use common\models\DeliveryNote; | use common\models\DeliveryNote; | ||||
use common\models\Distribution; | use common\models\Distribution; | ||||
use common\models\Document; | use common\models\Document; | ||||
use common\models\PointSale; | |||||
use common\models\Product; | use common\models\Product; | ||||
use common\models\Producer; | use common\models\Producer; | ||||
use common\models\Order; | use common\models\Order; | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$user = User::findOne($idUser) ; | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => $idUser, | |||||
]) ; | |||||
$pointSale = PointSale::findOne($idPointSale) ; | |||||
$productsArray = Product::find() | $productsArray = Product::find() | ||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
$productOrderArray[$product['id']] = [ | $productOrderArray[$product['id']] = [ | ||||
'quantity' => 0, | 'quantity' => 0, | ||||
'unit' => $product->unit, | 'unit' => $product->unit, | ||||
'price' => $product->getPriceWithTax(['id_user' => $idUser, 'id_point_sale' => $idPointSale]), | |||||
'price' => $product->getPriceWithTax([ | |||||
'user' => $user, | |||||
'user_producer' => $userProducer, | |||||
'point_sale' => $pointSale | |||||
]), | |||||
]; | ]; | ||||
} | } | ||||
$model->id_product = $idProduct; | $model->id_product = $idProduct; | ||||
$modelProduct = $this->findModel($idProduct) ; | $modelProduct = $this->findModel($idProduct) ; | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
Yii::$app->getSession()->setFlash('success', 'Le prix a bien été ajouté.'); | |||||
return $this->redirect(['product/prices-list', 'id' => $idProduct]); | |||||
if ($model->load(Yii::$app->request->post())) { | |||||
$conditionsProductPriceExist = [ | |||||
'id_product' => $idProduct, | |||||
'id_user' => $model->id_user ? $model->id_user : null, | |||||
'id_point_sale' => $model->id_point_sale ? $model->id_point_sale : null, | |||||
] ; | |||||
$productPriceExist = ProductPrice::findOne($conditionsProductPriceExist) ; | |||||
if($productPriceExist) { | |||||
$productPriceExist->delete() ; | |||||
Yii::$app->getSession()->setFlash('warning', 'Un prix existait déjà pour cet utilisateur / point de vente, il a été supprimé.'); | |||||
} | |||||
if($model->save()) { | |||||
Yii::$app->getSession()->setFlash('success', 'Le prix a bien été ajouté.'); | |||||
return $this->redirect(['product/prices-list', 'id' => $idProduct]); | |||||
} | |||||
} | } | ||||
return $this->render('update/prices/create', [ | return $this->render('update/prices/create', [ |
<div class="alert alert-info"> | |||||
Prix de base : <strong><?= Price::format($model->getPrice()); ?> HT</strong> / <strong><?= Price::format($model->getPriceWithTax()); ?> TTC</strong><br /> | |||||
</div> |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\User ; | use common\models\User ; | ||||
?> | ?> | ||||
<div class="product-form"> | <div class="product-form"> | ||||
<?= | |||||
$this->render('_base_price', [ | |||||
'model' => $modelProduct, | |||||
]) ; | |||||
?> | |||||
<?php $form = ActiveForm::begin([ | <?php $form = ActiveForm::begin([ | ||||
'enableClientValidation' => false, | 'enableClientValidation' => false, | ||||
'options' => ['enctype' => 'multipart/form-data'] | 'options' => ['enctype' => 'multipart/form-data'] | ||||
<?= $form->field($model, 'id_user')->dropDownList(User::populateDropdownList()); ?> | <?= $form->field($model, 'id_user')->dropDownList(User::populateDropdownList()); ?> | ||||
<?= $form->field($model, 'id_point_sale')->dropDownList(PointSale::populateDropdownList()) ?> | <?= $form->field($model, 'id_point_sale')->dropDownList(PointSale::populateDropdownList()) ?> | ||||
<?= $form->field($model, 'price') ?> | |||||
<?php | |||||
$producer = GlobalParam::getCurrentProducer(); | |||||
$taxRateValue = $producer->taxRate->value; | |||||
if($modelProduct->taxRate) { | |||||
$taxRateValue = $modelProduct->taxRate->value ; | |||||
} | |||||
?> | |||||
<?= $form->field($model, 'price', [ | |||||
'template' => ' | |||||
<div class="row"> | |||||
<div class="col-xs-6"> | |||||
<label for="product-price" class="control-label without-tax">Prix ('.Product::strUnit($modelProduct->unit, 'wording_unit').') HT</label> | |||||
<div class="input-group"> | |||||
{input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> | |||||
</div> | |||||
</div> | |||||
<div class="col-xs-6"> | |||||
<label for="productprice-price-with-tax" class="control-label with-tax">Prix ('.Product::strUnit($modelProduct->unit, 'wording_unit').') TTC</label> | |||||
<div class="input-group"> | |||||
<input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'"> | |||||
<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> | |||||
</div> | |||||
</div> | |||||
</div>', | |||||
]) ?> | |||||
<div class="form-group"> | <div class="form-group"> | ||||
<?= Html::a('Annuler', ['prices-list', 'id' => $model->id_product], ['class' => 'btn btn-default']) ?> | <?= Html::a('Annuler', ['prices-list', 'id' => $model->id_product], ['class' => 'btn btn-default']) ?> |
<div class="product-prices-create"> | <div class="product-prices-create"> | ||||
<?= $this->render('_form', [ | <?= $this->render('_form', [ | ||||
'model' => $model, | 'model' => $model, | ||||
'modelProduct' => $modelProduct | |||||
]) ?> | ]) ?> | ||||
</div> | </div> |
<?php | <?php | ||||
use common\helpers\Price ; | |||||
/** | /** | ||||
* Copyright distrib (2018) | * Copyright distrib (2018) | ||||
* | * | ||||
]) ; | ]) ; | ||||
?> | ?> | ||||
<?= | |||||
$this->render('_base_price', [ | |||||
'model' => $model, | |||||
]) ; | |||||
?> | |||||
<?php | <?php | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'columns' => [ | 'columns' => [ | ||||
[ | [ | ||||
'attribute' => 'id_user', | |||||
'attribute' => 'id_point_sale', | |||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
if($model->user) { | |||||
return $model->user->getUsername() ; | |||||
if($model->pointSale) { | |||||
return $model->pointSale->name ; | |||||
} | } | ||||
return '' ; | return '' ; | ||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'id_point_sale', | |||||
'attribute' => 'id_user', | |||||
'value' => function ($model) { | 'value' => function ($model) { | ||||
if($model->pointSale) { | |||||
return $model->pointSale->name ; | |||||
if($model->user) { | |||||
return $model->user->getUsername() ; | |||||
} | } | ||||
return '' ; | return '' ; | ||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'price', | 'attribute' => 'price', | ||||
'value' => function ($model) { | |||||
return number_format($model->price, 2).' €' ; | |||||
'value' => function ($productPrice) { | |||||
return Price::numberTwoDecimals($productPrice->price).' €' ; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'price', | |||||
'header' => 'Prix (TTC)', | |||||
'value' => function ($productPrice) use ($model) { | |||||
return Price::numberTwoDecimals(Price::getPriceWithTax($productPrice->price, $model->taxRate->value)).' €' ; | |||||
} | } | ||||
], | ], | ||||
[ | [ |
<div class="product-prices-update"> | <div class="product-prices-update"> | ||||
<?= $this->render('_form', [ | <?= $this->render('_form', [ | ||||
'model' => $model, | 'model' => $model, | ||||
'modelProduct' => $modelProduct | |||||
]) ?> | ]) ?> | ||||
</div> | </div> |
opendistrib_tooltip() ; | opendistrib_tooltip() ; | ||||
opendistrib_ordre_produits() ; | opendistrib_ordre_produits() ; | ||||
opendistrib_products() ; | opendistrib_products() ; | ||||
opendistrib_product_prices() ; | |||||
opendistrib_confirm_delete() ; | opendistrib_confirm_delete() ; | ||||
}) ; | }) ; | ||||
opendistrib_products_event_unit(true) ; | opendistrib_products_event_unit(true) ; | ||||
}) ; | }) ; | ||||
opendistrib_products_event_price_with_tax() ; | opendistrib_products_event_price_with_tax() ; | ||||
$('#product-price').change(opendistrib_products_event_price_with_tax); | $('#product-price').change(opendistrib_products_event_price_with_tax); | ||||
if(typeof taxRateSelected == 'undefined') { | if(typeof taxRateSelected == 'undefined') { | ||||
taxRateSelected = 0 ; | taxRateSelected = 0 ; | ||||
} | } | ||||
$('#product-price-with-tax').val(getPriceWithTax($('#product-price').val(), taxRateSelected)); | |||||
//formattage des prix | |||||
$('#product-price').val(parseFloat($('#product-price').val()).toFixed(3)); | |||||
var price = $('#product-price').val() ; | |||||
if(price) { | |||||
$('#product-price-with-tax').val(getPriceWithTax(price, taxRateSelected)); | |||||
// formattage | |||||
$('#product-price').val(parseFloat(price).toFixed(3)); | |||||
} | |||||
} | } | ||||
function opendistrib_products_event_price(){ | function opendistrib_products_event_price(){ | ||||
taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value'); | taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value'); | ||||
$('#product-price').val(getPrice($('#product-price-with-tax').val(), taxRateSelected)); | |||||
//formattage des prix | |||||
$('#product-price-with-tax').val(parseFloat($('#product-price-with-tax').val()).toFixed(2)); | |||||
var priceWithTax = $('#product-price-with-tax').val() ; | |||||
if(priceWithTax) { | |||||
$('#product-price').val(getPrice(priceWithTax, taxRateSelected)); | |||||
// formattage | |||||
$('#product-price-with-tax').val(parseFloat(priceWithTax).toFixed(2)); | |||||
} | |||||
} | } | ||||
} | } | ||||
function opendistrib_product_prices() { | |||||
if($('.product-prices-create').size() || $('.product-prices-update').size()) { | |||||
opendistrib_product_prices_event_price_with_tax() ; | |||||
$('#productprice-price').change(opendistrib_product_prices_event_price_with_tax); | |||||
$('#productprice-price-with-tax').change(opendistrib_product_prices_event_price); | |||||
} | |||||
} | |||||
function opendistrib_product_prices_event_price_with_tax() { | |||||
var taxRateValue = $('#productprice-price-with-tax').data('tax-rate-value'); | |||||
var price = $('#productprice-price').val() ; | |||||
if(price) { | |||||
$('#productprice-price-with-tax').val(getPriceWithTax(price, taxRateValue)); | |||||
// formattage | |||||
$('#productprice-price').val(parseFloat(price).toFixed(3)); | |||||
} | |||||
} | |||||
function opendistrib_product_prices_event_price() { | |||||
var taxRateValue = $('#productprice-price-with-tax').data('tax-rate-value'); | |||||
var priceWithTax = $('#productprice-price-with-tax').val() ; | |||||
if(priceWithTax) { | |||||
$('#productprice-price').val(getPrice(priceWithTax, taxRateValue)); | |||||
// formattage | |||||
$('#productprice-price-with-tax').val(parseFloat(priceWithTax).toFixed(2)); | |||||
} | |||||
} | |||||
function opendistrib_tooltip() { | function opendistrib_tooltip() { | ||||
$('[data-toggle="tooltip"]').tooltip({container:'body'}); | $('[data-toggle="tooltip"]').tooltip({container:'body'}); | ||||
} | } |
{ | { | ||||
$specificPrices = $this->productPrice ; | $specificPrices = $this->productPrice ; | ||||
if($specificPrices && (isset($params['id_user']) || isset($params['id_point_sale']))) { | |||||
$user = isset($params['user']) ? $params['user'] : false ; | |||||
$userProducer = isset($params['user_producer']) ? $params['user_producer'] : false ; | |||||
$pointSale = isset($params['point_sale']) ? $params['point_sale'] : false ; | |||||
if($specificPrices && ($user || $pointSale)) { | |||||
$specificPricesArray = [ | $specificPricesArray = [ | ||||
'user' => false, | 'user' => false, | ||||
] ; | ] ; | ||||
foreach($specificPrices as $specificPrice) { | foreach($specificPrices as $specificPrice) { | ||||
if(isset($params['id_user']) && $params['id_user'] | |||||
if($user | |||||
&& $specificPrice->id_user && !$specificPrice->id_point_sale | && $specificPrice->id_user && !$specificPrice->id_point_sale | ||||
&& $specificPrice->id_user == $params['id_user']) { | |||||
&& $specificPrice->id_user == $user->id) { | |||||
$specificPricesArray['user'] = $specificPrice->price ; | $specificPricesArray['user'] = $specificPrice->price ; | ||||
} | } | ||||
if(isset($params['id_point_sale']) && $params['id_point_sale'] | |||||
if($pointSale | |||||
&& $specificPrice->id_point_sale && !$specificPrice->id_user | && $specificPrice->id_point_sale && !$specificPrice->id_user | ||||
&& $specificPrice->id_point_sale == $params['id_point_sale']) { | |||||
&& $specificPrice->id_point_sale == $pointSale->id) { | |||||
$specificPricesArray['pointsale'] = $specificPrice->price ; | $specificPricesArray['pointsale'] = $specificPrice->price ; | ||||
} | } | ||||
if(isset($params['id_point_sale']) && $params['id_point_sale'] && isset($params['id_user']) && $params['id_user'] | |||||
if($pointSale && $user | |||||
&& $specificPrice->id_point_sale && $specificPrice->id_user | && $specificPrice->id_point_sale && $specificPrice->id_user | ||||
&& $specificPrice->id_point_sale == $params['id_point_sale'] && $specificPrice->id_user == $params['id_user']) { | |||||
&& $specificPrice->id_point_sale == $pointSale->id && $specificPrice->id_user == $user->id) { | |||||
$specificPricesArray['user_pointsale'] = $specificPrice->price ; | $specificPricesArray['user_pointsale'] = $specificPrice->price ; | ||||
} | } | ||||
if($specificPricesArray['user_pointsale']) { | if($specificPricesArray['user_pointsale']) { | ||||
return $specificPricesArray['user_pointsale'] ; | return $specificPricesArray['user_pointsale'] ; | ||||
} | } | ||||
elseif($specificPricesArray['pointsale']) { | |||||
return $specificPricesArray['pointsale'] ; | |||||
} | |||||
elseif($specificPricesArray['user']) { | elseif($specificPricesArray['user']) { | ||||
return $specificPricesArray['user'] ; | return $specificPricesArray['user'] ; | ||||
} | } | ||||
elseif($specificPricesArray['pointsale']) { | |||||
return $specificPricesArray['pointsale'] ; | |||||
} | |||||
} | |||||
if($userProducer && $userProducer->product_price_percent) { | |||||
return $this->price * (1 + $userProducer->product_price_percent / 100) ; | |||||
} | |||||
if($pointSale && $pointSale->product_price_percent) { | |||||
return $this->price * (1 + $pointSale->product_price_percent / 100) ; | |||||
} | } | ||||
return $this->price ; | return $this->price ; |
$format = 'Y-m-d'; | $format = 'Y-m-d'; | ||||
$dateObject = DateTime::createFromFormat($format, $date); | $dateObject = DateTime::createFromFormat($format, $date); | ||||
// PointSale current | |||||
$pointSaleCurrent = PointSale::findOne($pointSaleId) ; | |||||
// Producteur | // Producteur | ||||
$producer = Producer::searchOne([ | $producer = Producer::searchOne([ | ||||
'id' => $this->getProducer()->id | 'id' => $this->getProducer()->id | ||||
$product->getAttributes(), | $product->getAttributes(), | ||||
[ | [ | ||||
'price_with_tax' => $product->getPriceWithTax([ | 'price_with_tax' => $product->getPriceWithTax([ | ||||
'id_user' => User::getCurrentId(), | |||||
'id_point_sale' => $pointSaleId | |||||
'user' => User::getCurrent(), | |||||
'user_producer' => $userProducer, | |||||
'point_sale' => $pointSaleCurrent | |||||
]), | ]), | ||||
'productDistribution' => $product['productDistribution'] | 'productDistribution' => $product['productDistribution'] | ||||
] | ] |
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$params = []; | $params = []; | ||||
$user = User::getCurrent() ; | |||||
$userProducer = UserProducer::searchOne([ | |||||
'id_user' => User::getCurrentId() | |||||
]) ; | |||||
$pointSale = false ; | |||||
if ($idSubscription > 0) { | if ($idSubscription > 0) { | ||||
$arrayProductsSubscription = ProductSubscription::searchAll([ | $arrayProductsSubscription = ProductSubscription::searchAll([ | ||||
'id_subscription' => $idSubscription | 'id_subscription' => $idSubscription | ||||
]); | ]); | ||||
$subscription = Subscription::findOne($idSubscription) ; | |||||
if($subscription) { | |||||
if($subscription->id_point_sale) { | |||||
$pointSale = PointSale::findOne($subscription->id_point_sale) ; | |||||
} | |||||
} | |||||
} | } | ||||
// Produits | // Produits | ||||
'coefficient_unit' => $coefficientUnit, | 'coefficient_unit' => $coefficientUnit, | ||||
'wording_unit' => Product::strUnit($product->unit, 'wording_unit', true), | 'wording_unit' => Product::strUnit($product->unit, 'wording_unit', true), | ||||
'wording_short' => Product::strUnit($product->unit, 'wording_short'), | 'wording_short' => Product::strUnit($product->unit, 'wording_short'), | ||||
'price_with_tax' => $product->getPriceWithTax(), | |||||
'price_with_tax' => $product->getPriceWithTax([ | |||||
'user' => $user, | |||||
'user_producer' => $userProducer, | |||||
'point_sale' => $pointSale | |||||
]), | |||||
] | ] | ||||
); | ); | ||||
} | } |