Ver código fonte

Prix spécifiques : prix HT / TTC + gestion pourcentages utilisateur / points de vente

dev
Guillaume 3 anos atrás
pai
commit
64a0b0e6b9
11 arquivos alterados com 182 adições e 34 exclusões
  1. +12
    -1
      backend/controllers/DistributionController.php
  2. +19
    -3
      backend/controllers/ProductController.php
  3. +3
    -0
      backend/views/product/update/prices/_base_price.php
  4. +35
    -1
      backend/views/product/update/prices/_form.php
  5. +1
    -0
      backend/views/product/update/prices/create.php
  6. +23
    -8
      backend/views/product/update/prices/list.php
  7. +1
    -0
      backend/views/product/update/prices/update.php
  8. +42
    -8
      backend/web/js/backend.js
  9. +22
    -10
      common/models/Product.php
  10. +6
    -2
      producer/controllers/OrderController.php
  11. +18
    -1
      producer/controllers/SubscriptionController.php

+ 12
- 1
backend/controllers/DistributionController.php Ver arquivo

@@ -43,6 +43,7 @@ use common\helpers\GlobalParam;
use common\models\DeliveryNote;
use common\models\Distribution;
use common\models\Document;
use common\models\PointSale;
use common\models\Product;
use common\models\Producer;
use common\models\Order;
@@ -384,6 +385,12 @@ class DistributionController extends BackendController
{
\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()
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
@@ -396,7 +403,11 @@ class DistributionController extends BackendController
$productOrderArray[$product['id']] = [
'quantity' => 0,
'unit' => $product->unit,
'price' => $product->getPriceWithTax(['id_user' => $idUser, 'id_point_sale' => $idPointSale]),
'price' => $product->getPriceWithTax([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $pointSale
]),
];
}


+ 19
- 3
backend/controllers/ProductController.php Ver arquivo

@@ -200,9 +200,25 @@ class ProductController extends BackendController
$model->id_product = $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', [

+ 3
- 0
backend/views/product/update/prices/_base_price.php Ver arquivo

@@ -0,0 +1,3 @@
<div class="alert alert-info">
Prix de base : <strong><?= Price::format($model->getPrice()); ?> HT</strong> / <strong><?= Price::format($model->getPriceWithTax()); ?> TTC</strong><br />
</div>

+ 35
- 1
backend/views/product/update/prices/_form.php Ver arquivo

@@ -9,10 +9,19 @@ use common\models\Producer;
use common\helpers\GlobalParam;
use common\models\User ;


?>

<div class="product-form">

<?=

$this->render('_base_price', [
'model' => $modelProduct,
]) ;

?>

<?php $form = ActiveForm::begin([
'enableClientValidation' => false,
'options' => ['enctype' => 'multipart/form-data']
@@ -20,7 +29,32 @@ use common\models\User ;

<?= $form->field($model, 'id_user')->dropDownList(User::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">
<?= Html::a('Annuler', ['prices-list', 'id' => $model->id_product], ['class' => 'btn btn-default']) ?>

+ 1
- 0
backend/views/product/update/prices/create.php Ver arquivo

@@ -56,5 +56,6 @@ $this->addBreadcrumb('Ajouter un prix') ;
<div class="product-prices-create">
<?= $this->render('_form', [
'model' => $model,
'modelProduct' => $modelProduct
]) ?>
</div>

+ 23
- 8
backend/views/product/update/prices/list.php Ver arquivo

@@ -1,5 +1,7 @@
<?php

use common\helpers\Price ;

/**
* Copyright distrib (2018)
*
@@ -51,6 +53,12 @@ $this->addButton(['label' => 'Nouveau prix <span class="glyphicon glyphicon-plus
]) ;
?>

<?=
$this->render('_base_price', [
'model' => $model,
]) ;
?>

<?php


@@ -59,27 +67,34 @@ echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'id_user',
'attribute' => 'id_point_sale',
'value' => function ($model) {
if($model->user) {
return $model->user->getUsername() ;
if($model->pointSale) {
return $model->pointSale->name ;
}
return '' ;
}
],
[
'attribute' => 'id_point_sale',
'attribute' => 'id_user',
'value' => function ($model) {
if($model->pointSale) {
return $model->pointSale->name ;
if($model->user) {
return $model->user->getUsername() ;
}
return '' ;
}
],
[
'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)).' €' ;
}
],
[

+ 1
- 0
backend/views/product/update/prices/update.php Ver arquivo

@@ -56,5 +56,6 @@ $this->addBreadcrumb('Modifier un prix') ;
<div class="product-prices-update">
<?= $this->render('_form', [
'model' => $model,
'modelProduct' => $modelProduct
]) ?>
</div>

+ 42
- 8
backend/web/js/backend.js Ver arquivo

@@ -42,6 +42,7 @@ $(document).ready(function() {
opendistrib_tooltip() ;
opendistrib_ordre_produits() ;
opendistrib_products() ;
opendistrib_product_prices() ;
opendistrib_confirm_delete() ;
}) ;

@@ -72,7 +73,6 @@ function opendistrib_products() {
opendistrib_products_event_unit(true) ;
}) ;


opendistrib_products_event_price_with_tax() ;

$('#product-price').change(opendistrib_products_event_price_with_tax);
@@ -87,16 +87,22 @@ function opendistrib_products_event_price_with_tax() {
if(typeof taxRateSelected == 'undefined') {
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(){
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));
}
}


@@ -145,6 +151,34 @@ function opendistrib_products_event_unit(change) {
}

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() {
$('[data-toggle="tooltip"]').tooltip({container:'body'});
}

+ 22
- 10
common/models/Product.php Ver arquivo

@@ -338,7 +338,11 @@ class Product extends ActiveRecordCommon
{
$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 = [
'user' => false,
@@ -347,22 +351,22 @@ class Product extends ActiveRecordCommon
] ;

foreach($specificPrices as $specificPrice) {
if(isset($params['id_user']) && $params['id_user']
if($user
&& $specificPrice->id_user && !$specificPrice->id_point_sale
&& $specificPrice->id_user == $params['id_user']) {
&& $specificPrice->id_user == $user->id) {

$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 == $params['id_point_sale']) {
&& $specificPrice->id_point_sale == $pointSale->id) {

$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 == $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 ;
}
@@ -371,12 +375,20 @@ class Product extends ActiveRecordCommon
if($specificPricesArray['user_pointsale']) {
return $specificPricesArray['user_pointsale'] ;
}
elseif($specificPricesArray['pointsale']) {
return $specificPricesArray['pointsale'] ;
}
elseif($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 ;

+ 6
- 2
producer/controllers/OrderController.php Ver arquivo

@@ -523,6 +523,9 @@ class OrderController extends ProducerBaseController
$format = 'Y-m-d';
$dateObject = DateTime::createFromFormat($format, $date);

// PointSale current
$pointSaleCurrent = PointSale::findOne($pointSaleId) ;

// Producteur
$producer = Producer::searchOne([
'id' => $this->getProducer()->id
@@ -675,8 +678,9 @@ class OrderController extends ProducerBaseController
$product->getAttributes(),
[
'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']
]

+ 18
- 1
producer/controllers/SubscriptionController.php Ver arquivo

@@ -219,11 +219,24 @@ class SubscriptionController extends ProducerBaseController
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$params = [];

$user = User::getCurrent() ;
$userProducer = UserProducer::searchOne([
'id_user' => User::getCurrentId()
]) ;
$pointSale = false ;

if ($idSubscription > 0) {
$arrayProductsSubscription = ProductSubscription::searchAll([
'id_subscription' => $idSubscription
]);

$subscription = Subscription::findOne($idSubscription) ;

if($subscription) {
if($subscription->id_point_sale) {
$pointSale = PointSale::findOne($subscription->id_point_sale) ;
}
}
}

// Produits
@@ -250,7 +263,11 @@ class SubscriptionController extends ProducerBaseController
'coefficient_unit' => $coefficientUnit,
'wording_unit' => Product::strUnit($product->unit, 'wording_unit', true),
'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
]),
]
);
}

Carregando…
Cancelar
Salvar