]; | ]; | ||||
} | } | ||||
public function actionAjaxUpdateProductOrder($idUser = false, $idPointSale = false) | |||||
{ | |||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||||
$productsArray = Product::find() | |||||
->where([ | |||||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||||
'product.active' => 1, | |||||
])->joinWith(['productPrice']) | |||||
->all(); | |||||
$productOrderArray = []; | |||||
foreach ($productsArray as $product) { | |||||
$productOrderArray[$product['id']] = [ | |||||
'quantity' => 0, | |||||
'unit' => $product->unit, | |||||
'price' => $product->getPriceWithTax(['id_user' => $idUser, 'id_point_sale' => $idPointSale]), | |||||
]; | |||||
} | |||||
return $productOrderArray ; | |||||
} | |||||
/** | /** | ||||
* Génére un PDF récapitulatif des des commandes d'un producteur pour une | * Génére un PDF récapitulatif des des commandes d'un producteur pour une | ||||
* date donnée (Méthode appelable via CRON) | * date donnée (Méthode appelable via CRON) |
:producer="producer" | :producer="producer" | ||||
@close="showModalFormOrderCreate = false" | @close="showModalFormOrderCreate = false" | ||||
@ordercreatedupdated="orderCreatedUpdated" | @ordercreatedupdated="orderCreatedUpdated" | ||||
@updateproductorderprices="updateProductOrderPrices" | |||||
></order-form> | ></order-form> | ||||
<div id="wrapper-nav-points-sale"> | <div id="wrapper-nav-points-sale"> | ||||
:producer="producer" | :producer="producer" | ||||
@close="showModalFormOrderUpdate = false" | @close="showModalFormOrderUpdate = false" | ||||
@ordercreatedupdated="orderCreatedUpdated" | @ordercreatedupdated="orderCreatedUpdated" | ||||
@updateproductorderprices="updateProductOrderPrices" | |||||
></order-form> | ></order-form> | ||||
<modal v-if="showModalPayment && idOrderPayment == order.id" class="modal-payment" @close="showModalPayment = false"> | <modal v-if="showModalPayment && idOrderPayment == order.id" class="modal-payment" @close="showModalPayment = false"> | ||||
<label class="control-label" for="select-id-user"> | <label class="control-label" for="select-id-user"> | ||||
Utilisateur | Utilisateur | ||||
</label> | </label> | ||||
<select class="form-control" v-model="order.id_user"> | |||||
<select class="form-control" v-model="order.id_user" @change="userChange"> | |||||
<option value="0">--</option> | <option value="0">--</option> | ||||
<option v-for="user in users" :value="user.id_user" @click="userChange"> | |||||
<option v-for="user in users" :value="user.id_user"> | |||||
<template v-if="user.name_legal_person && user.name_legal_person.length"> | <template v-if="user.name_legal_person && user.name_legal_person.length"> | ||||
Personne morale / {{ user.name_legal_person }} | Personne morale / {{ user.name_legal_person }} | ||||
</template> | </template> | ||||
</div> | </div> | ||||
<div class="form-group"> | <div class="form-group"> | ||||
<label class="control-label" for="select-id-point-sale">Point de vente</label> | <label class="control-label" for="select-id-point-sale">Point de vente</label> | ||||
<select class="form-control" id="select-id-point-sale" v-model="order.id_point_sale"> | |||||
<select class="form-control" id="select-id-point-sale" v-model="order.id_point_sale" @change="pointSaleChange"> | |||||
<option value="0">--</option> | <option value="0">--</option> | ||||
<option v-for="pointSale in pointsSale" v-if="pointSale.pointSaleDistribution[0].delivery == 1" :value="pointSale.id">{{ pointSale.name }}</option> | |||||
<option v-for="pointSale in pointsSale" v-if="pointSale.pointSaleDistribution[0].delivery == 1" :value="pointSale.id"">{{ pointSale.name }}</option> | |||||
</select> | </select> | ||||
</div> | </div> | ||||
<div class="form-group"> | <div class="form-group"> |
openModalFormOrderCreate: function() { | openModalFormOrderCreate: function() { | ||||
this.showModalFormOrderCreate = true ; | this.showModalFormOrderCreate = true ; | ||||
this.initModalFormOrder() ; | this.initModalFormOrder() ; | ||||
this.updateProductOrderPrices() ; | |||||
}, | }, | ||||
initModalFormOrder: function() { | initModalFormOrder: function() { | ||||
setTimeout(function() { | setTimeout(function() { | ||||
appAlerts.alertResponse(response) ; | appAlerts.alertResponse(response) ; | ||||
app.init(app.idActivePointSale) ; | app.init(app.idActivePointSale) ; | ||||
}) ; | }) ; | ||||
}, | |||||
updateProductOrderPrices: function() { | |||||
var app = this ; | |||||
var order = null ; | |||||
if(app.showModalFormOrderCreate) { | |||||
order = app.orderCreate ; | |||||
} | |||||
if(app.showModalFormOrderUpdate && app.idOrderUpdate) { | |||||
for (keyOrderUpdate in app.ordersUpdate) { | |||||
if (app.ordersUpdate[keyOrderUpdate].id == app.idOrderUpdate) { | |||||
order = app.ordersUpdate[keyOrderUpdate] ; | |||||
} | |||||
} | |||||
} | |||||
if(order) { | |||||
axios.get(UrlManager.getBaseUrlAbsolute() + "distribution/ajax-update-product-order", { | |||||
params: { | |||||
idUser: order.id_user, | |||||
idPointSale: order.id_point_sale | |||||
} | |||||
}) | |||||
.then(function (response) { | |||||
if (response.data) { | |||||
for (idProduct in response.data) { | |||||
if (app.showModalFormOrderCreate) { | |||||
Vue.set(app.orderCreate.productOrder[idProduct], 'price', response.data[idProduct].price); | |||||
} | |||||
if (app.showModalFormOrderUpdate && app.idOrderUpdate) { | |||||
for (keyOrderUpdate in app.ordersUpdate) { | |||||
if (order.id == app.idOrderUpdate) { | |||||
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'price', response.data[idProduct].price); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
}); | |||||
} | |||||
} | } | ||||
}, | }, | ||||
}); | }); | ||||
}}) | }}) | ||||
.then(function(response) { | .then(function(response) { | ||||
app.order.id_point_sale = response.data.id_favorite_point_sale ; | app.order.id_point_sale = response.data.id_favorite_point_sale ; | ||||
app.updateProductOrderPrices() ; | |||||
}) ; | }) ; | ||||
}, | |||||
pointSaleChange: function(event) { | |||||
this.updateProductOrderPrices() ; | |||||
}, | |||||
updateProductOrderPrices: function() { | |||||
this.$emit('updateproductorderprices') ; | |||||
} | } | ||||
} | } | ||||
}) ; | }) ; |
if($producer) { | if($producer) { | ||||
$this->populateRelation('taxRate', $producer->taxRate); | $this->populateRelation('taxRate', $producer->taxRate); | ||||
} | } | ||||
//$this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate); | |||||
} | } | ||||
$this->wording_unit = Product::strUnit($this->unit) ; | $this->wording_unit = Product::strUnit($this->unit) ; | ||||
$this->price_with_tax = $this->getpriceWithTax() ; | |||||
$this->price_with_tax = $this->getPriceWithTax() ; | |||||
parent::afterFind(); | parent::afterFind(); | ||||
} | } | ||||
public function getTaxRate() | public function getTaxRate() | ||||
{ | { | ||||
return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']); | return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']); | ||||
} | } | ||||
public function getProductPrice() | |||||
{ | |||||
return $this->hasMany(ProductPrice::className(), ['id_product' => 'id']); | |||||
} | |||||
/** | /** | ||||
* Retourne les options de base nécessaires à la fonction de recherche. | * Retourne les options de base nécessaires à la fonction de recherche. | ||||
* | * | ||||
return $strUnit; | return $strUnit; | ||||
} | } | ||||
public function getPrice() | |||||
public function getPrice($params = []) | |||||
{ | { | ||||
$specificPrices = $this->productPrice ; | |||||
if($specificPrices && (isset($params['id_user']) || isset($params['id_point_sale']))) { | |||||
$specificPricesArray = [ | |||||
'user' => false, | |||||
'pointsale' => false, | |||||
'user_pointsale' => false, | |||||
] ; | |||||
foreach($specificPrices as $specificPrice) { | |||||
if(isset($params['id_user']) && $params['id_user'] | |||||
&& $specificPrice->id_user && !$specificPrice->id_point_sale | |||||
&& $specificPrice->id_user == $params['id_user']) { | |||||
$specificPricesArray['user'] = $specificPrice->price ; | |||||
} | |||||
if(isset($params['id_point_sale']) && $params['id_point_sale'] | |||||
&& $specificPrice->id_point_sale && !$specificPrice->id_user | |||||
&& $specificPrice->id_point_sale == $params['id_point_sale']) { | |||||
$specificPricesArray['pointsale'] = $specificPrice->price ; | |||||
} | |||||
if(isset($params['id_point_sale']) && $params['id_point_sale'] && isset($params['id_user']) && $params['id_user'] | |||||
&& $specificPrice->id_point_sale && $specificPrice->id_user | |||||
&& $specificPrice->id_point_sale == $params['id_point_sale'] && $specificPrice->id_user == $params['id_user']) { | |||||
$specificPricesArray['user_pointsale'] = $specificPrice->price ; | |||||
} | |||||
} | |||||
if($specificPricesArray['user_pointsale']) { | |||||
return $specificPricesArray['user_pointsale'] ; | |||||
} | |||||
elseif($specificPricesArray['pointsale']) { | |||||
return $specificPricesArray['pointsale'] ; | |||||
} | |||||
elseif($specificPricesArray['user']) { | |||||
return $specificPricesArray['user'] ; | |||||
} | |||||
} | |||||
return $this->price ; | return $this->price ; | ||||
} | } | ||||
/** | /** | ||||
* Retourne le prix du produit avec taxe | * Retourne le prix du produit avec taxe | ||||
*/ | */ | ||||
public function getPriceWithTax() | |||||
public function getPriceWithTax($params = []) | |||||
{ | { | ||||
$taxRateValue = $this->taxRate ? $this->taxRate->value : 0 ; | $taxRateValue = $this->taxRate ? $this->taxRate->value : 0 ; | ||||
return Price::getPriceWithTax($this->price, $taxRateValue); | |||||
return Price::getPriceWithTax($this->getPrice($params), $taxRateValue); | |||||
} | } | ||||
public function getTheTaxRate() | public function getTheTaxRate() |
$productOrder->id_order = $order->id; | $productOrder->id_order = $order->id; | ||||
$productOrder->id_product = $productSubscription->product->id; | $productOrder->id_product = $productSubscription->product->id; | ||||
$productOrder->quantity = $productSubscription->quantity; | $productOrder->quantity = $productSubscription->quantity; | ||||
$productOrder->price = $productSubscription->product->price; | |||||
$productOrder->price = $productSubscription->product->getPrice([ | |||||
'id_user' => $this->id_user, | |||||
'id_point_sale' => $this->id_point_sale | |||||
]); | |||||
$productOrder->unit = $productSubscription->product->unit; | $productOrder->unit = $productSubscription->product->unit; | ||||
$productOrder->step = $productSubscription->product->step; | $productOrder->step = $productSubscription->product->step; | ||||
$productOrder->id_tax_rate = $productSubscription->product->taxRate->id; | $productOrder->id_tax_rate = $productSubscription->product->taxRate->id; |
return 0; | return 0; | ||||
} | } | ||||
public function actionAjaxInfos($date = '') | |||||
public function actionAjaxInfos($date = '', $pointSaleId = 0) | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
]); | ]); | ||||
// Produits | // Produits | ||||
/*if (Producer::getConfig('option_allow_user_gift')) { | |||||
$productsArray = Product::find() | |||||
->orWhere(['id_producer' => $this->getProducer()->id,]) | |||||
//->orWhere(['id_producer' => 0,]) // produit "Don"; | |||||
; | |||||
} else { | |||||
$productsArray = Product::find() | |||||
->where(['id_producer' => $this->getProducer()->id,]); | |||||
}*/ | |||||
$productsArray = Product::find() | $productsArray = Product::find() | ||||
->where([ | ->where([ | ||||
'id_producer' => $this->getProducer()->id, | 'id_producer' => $this->getProducer()->id, | ||||
$productsArray = $productsArray->joinWith(['productDistribution' => function ($query) use ($distribution) { | $productsArray = $productsArray->joinWith(['productDistribution' => function ($query) use ($distribution) { | ||||
$query->andOnCondition('product_distribution.id_distribution = ' . $distribution->id); | $query->andOnCondition('product_distribution.id_distribution = ' . $distribution->id); | ||||
}]) | |||||
}, 'productPrice']) | |||||
->orderBy('product_distribution.active DESC, order ASC') | ->orderBy('product_distribution.active DESC, order ASC') | ||||
->all(); | ->all(); | ||||
$product = array_merge( | $product = array_merge( | ||||
$product->getAttributes(), | $product->getAttributes(), | ||||
[ | [ | ||||
'price_with_tax' => $product->getPriceWithTax(), | |||||
'price_with_tax' => $product->getPriceWithTax([ | |||||
'id_user' => User::getCurrentId(), | |||||
'id_point_sale' => $pointSaleId | |||||
]), | |||||
'productDistribution' => $product['productDistribution'] | 'productDistribution' => $product['productDistribution'] | ||||
] | ] | ||||
); | ); | ||||
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient']; | $coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient']; | ||||
if (is_null($product['photo'])) { | if (is_null($product['photo'])) { |
init: function() { | init: function() { | ||||
var app = this ; | var app = this ; | ||||
this.loading = true ; | this.loading = true ; | ||||
axios.get("ajax-infos",{params: {date : this.getDate()}}) | |||||
axios.get("ajax-infos",{params: { | |||||
date : this.getDate(), | |||||
pointSaleId: this.pointSaleActive ? this.pointSaleActive.id : 0 | |||||
}}) | |||||
.then(function(response) { | .then(function(response) { | ||||
app.producer = response.data.producer ; | app.producer = response.data.producer ; | ||||
app.user = response.data.user ; | app.user = response.data.user ; |