@@ -380,6 +380,29 @@ class DistributionController extends BackendController | |||
]; | |||
} | |||
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 | |||
* date donnée (Méthode appelable via CRON) |
@@ -231,6 +231,7 @@ $this->setPageTitle('Distributions') ; | |||
:producer="producer" | |||
@close="showModalFormOrderCreate = false" | |||
@ordercreatedupdated="orderCreatedUpdated" | |||
@updateproductorderprices="updateProductOrderPrices" | |||
></order-form> | |||
<div id="wrapper-nav-points-sale"> | |||
@@ -390,6 +391,7 @@ $this->setPageTitle('Distributions') ; | |||
:producer="producer" | |||
@close="showModalFormOrderUpdate = false" | |||
@ordercreatedupdated="orderCreatedUpdated" | |||
@updateproductorderprices="updateProductOrderPrices" | |||
></order-form> | |||
<modal v-if="showModalPayment && idOrderPayment == order.id" class="modal-payment" @close="showModalPayment = false"> | |||
@@ -540,9 +542,9 @@ $this->setPageTitle('Distributions') ; | |||
<label class="control-label" for="select-id-user"> | |||
Utilisateur | |||
</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 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"> | |||
Personne morale / {{ user.name_legal_person }} | |||
</template> | |||
@@ -555,9 +557,9 @@ $this->setPageTitle('Distributions') ; | |||
</div> | |||
<div class="form-group"> | |||
<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 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> | |||
</div> | |||
<div class="form-group"> |
@@ -367,6 +367,7 @@ var app = new Vue({ | |||
openModalFormOrderCreate: function() { | |||
this.showModalFormOrderCreate = true ; | |||
this.initModalFormOrder() ; | |||
this.updateProductOrderPrices() ; | |||
}, | |||
initModalFormOrder: function() { | |||
setTimeout(function() { | |||
@@ -563,6 +564,49 @@ var app = new Vue({ | |||
appAlerts.alertResponse(response) ; | |||
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); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
} | |||
}, | |||
}); | |||
@@ -702,7 +746,14 @@ Vue.component('order-form',{ | |||
}}) | |||
.then(function(response) { | |||
app.order.id_point_sale = response.data.id_favorite_point_sale ; | |||
app.updateProductOrderPrices() ; | |||
}) ; | |||
}, | |||
pointSaleChange: function(event) { | |||
this.updateProductOrderPrices() ; | |||
}, | |||
updateProductOrderPrices: function() { | |||
this.$emit('updateproductorderprices') ; | |||
} | |||
} | |||
}) ; |
@@ -179,11 +179,10 @@ class Product extends ActiveRecordCommon | |||
if($producer) { | |||
$this->populateRelation('taxRate', $producer->taxRate); | |||
} | |||
//$this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate); | |||
} | |||
$this->wording_unit = Product::strUnit($this->unit) ; | |||
$this->price_with_tax = $this->getpriceWithTax() ; | |||
$this->price_with_tax = $this->getPriceWithTax() ; | |||
parent::afterFind(); | |||
} | |||
@@ -200,10 +199,14 @@ class Product extends ActiveRecordCommon | |||
public function getTaxRate() | |||
{ | |||
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. | |||
* | |||
@@ -331,18 +334,61 @@ class Product extends ActiveRecordCommon | |||
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 ; | |||
} | |||
/** | |||
* Retourne le prix du produit avec taxe | |||
*/ | |||
public function getPriceWithTax() | |||
public function getPriceWithTax($params = []) | |||
{ | |||
$taxRateValue = $this->taxRate ? $this->taxRate->value : 0 ; | |||
return Price::getPriceWithTax($this->price, $taxRateValue); | |||
return Price::getPriceWithTax($this->getPrice($params), $taxRateValue); | |||
} | |||
public function getTheTaxRate() |
@@ -245,7 +245,10 @@ class Subscription extends ActiveRecordCommon | |||
$productOrder->id_order = $order->id; | |||
$productOrder->id_product = $productSubscription->product->id; | |||
$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->step = $productSubscription->product->step; | |||
$productOrder->id_tax_rate = $productSubscription->product->taxRate->id; |
@@ -514,7 +514,7 @@ class OrderController extends ProducerBaseController | |||
return 0; | |||
} | |||
public function actionAjaxInfos($date = '') | |||
public function actionAjaxInfos($date = '', $pointSaleId = 0) | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
@@ -656,16 +656,6 @@ class OrderController extends ProducerBaseController | |||
]); | |||
// 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() | |||
->where([ | |||
'id_producer' => $this->getProducer()->id, | |||
@@ -674,7 +664,7 @@ class OrderController extends ProducerBaseController | |||
$productsArray = $productsArray->joinWith(['productDistribution' => function ($query) use ($distribution) { | |||
$query->andOnCondition('product_distribution.id_distribution = ' . $distribution->id); | |||
}]) | |||
}, 'productPrice']) | |||
->orderBy('product_distribution.active DESC, order ASC') | |||
->all(); | |||
@@ -684,12 +674,14 @@ class OrderController extends ProducerBaseController | |||
$product = array_merge( | |||
$product->getAttributes(), | |||
[ | |||
'price_with_tax' => $product->getPriceWithTax(), | |||
'price_with_tax' => $product->getPriceWithTax([ | |||
'id_user' => User::getCurrentId(), | |||
'id_point_sale' => $pointSaleId | |||
]), | |||
'productDistribution' => $product['productDistribution'] | |||
] | |||
); | |||
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient']; | |||
if (is_null($product['photo'])) { |
@@ -107,7 +107,10 @@ var app = new Vue({ | |||
init: function() { | |||
var app = this ; | |||
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) { | |||
app.producer = response.data.producer ; | |||
app.user = response.data.user ; |