Parcourir la source

[Global] Prix dégressifs : affichage dynamique du prix en fonction du volume (dans facturation) #250

refactoring
Guillaume il y a 2 ans
Parent
révision
a3c96e1bb1
4 fichiers modifiés avec 65 ajouts et 42 suppressions
  1. +1
    -29
      backend/controllers/DistributionController.php
  2. +2
    -10
      backend/controllers/DocumentController.php
  3. +26
    -3
      backend/web/js/vuejs/document-form.js
  4. +36
    -0
      common/models/Product.php

+ 1
- 29
backend/controllers/DistributionController.php Voir le fichier

@@ -441,9 +441,6 @@ class DistributionController extends BackendController

$distribution = Distribution::findOne($idDistribution);
$user = User::findOne($idUser);
$userProducer = UserProducer::searchOne([
'id_user' => $idUser,
]);
$pointSale = PointSale::findOne($idPointSale);

$productsArray = Product::find()
@@ -459,32 +456,7 @@ class DistributionController extends BackendController

$productOrderArray = [];
foreach ($productsArray as $product) {
$priceArray = [];

// specific prices
$specificPriceArray = $product->getSpecificPricesFilterByPriorityMatch(
$product->productPrice,
$user,
$pointSale
);

foreach ($specificPriceArray as $specificPrice) {
$priceArray[] = [
'from_quantity' => $specificPrice->from_quantity ? $specificPrice->from_quantity : 0,
'price_with_tax' => $product->getPriceWithTax([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $pointSale,
'quantity' => $specificPrice->from_quantity
]),
];
}

// base price
$priceArray[] = [
'from_quantity' => 0,
'price_with_tax' => $product->getPriceWithTax(),
];
$priceArray = $product->getPriceArray($user, $pointSale);

$productOrderArray[$product['id']] = [
'quantity' => 0,

+ 2
- 10
backend/controllers/DocumentController.php Voir le fichier

@@ -363,16 +363,8 @@ class DocumentController extends BackendController
'id',
function ($product) use ($document, $userProducer, $pointSale) {
return array_merge($product->getAttributes(), [
'price_with_tax' => $product->getPriceWithTax([
'user' => $document->user,
'user_producer' => $userProducer,
'point_sale' => $pointSale,
]),
'price' => $product->getPrice([
'user' => $document->user,
'user_producer' => $userProducer,
'point_sale' => $pointSale,
]),
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($userProducer->user, $pointSale),
'wording_unit' => $product->wording_unit,
'tax_rate' => $product->taxRate->value
]);

+ 26
- 3
backend/web/js/vuejs/document-form.js Voir le fichier

@@ -141,10 +141,32 @@ var app = new Vue({
changeProductAdd: function(event) {
var idProduct = event.currentTarget.value ;
this.productAddId = idProduct ;
//this.productAddPrice = parseFloat(this.productsArray[idProduct].price).toFixed(2) ;
this.productAddPrice = parseFloat(this.productsArray[idProduct].price);
this.productAddPrice = this.getBestProductPrice(idProduct, this.getStepProductAdd());
this.productAddQuantity = this.getStepProductAdd() ;
},
},
getBestProductPrice: function(idProduct, theQuantity) {
var thePriceWithTax = 9999;
var pricesArray = this.productsArray[idProduct].prices;
var unitCoefficient = this.productsArray[idProduct].unit_coefficient;
if(theQuantity) {
theQuantity = theQuantity / unitCoefficient;
}

for(var i = 0; i < pricesArray.length ; i++) {
var priceWithTax = pricesArray[i].price_with_tax;
var fromQuantity = pricesArray[i].from_quantity;

if(priceWithTax < thePriceWithTax && fromQuantity <= theQuantity) {
thePriceWithTax = priceWithTax;
}
}
if(thePriceWithTax == 9999) {
return 0;
}
else {
return thePriceWithTax;
}
},
changeQuantityProductAdd: function(quantity) {
var step = this.getStepProductAdd() ;
quantity = quantity * step ;
@@ -152,6 +174,7 @@ var app = new Vue({
if(this.productAddQuantity < 1) {
this.productAddQuantity = step ;
}
this.productAddPrice = this.getBestProductPrice(app.productAddId, this.productAddQuantity);
},
submitProductAdd: function() {
var app = this ;

+ 36
- 0
common/models/Product.php Voir le fichier

@@ -388,6 +388,42 @@ class Product extends ActiveRecordCommon
return $strUnit;
}

public function getPriceArray($user, $pointSale)
{
$priceArray = [];

$userProducer = UserProducer::searchOne([
'id_user' => $user->id,
]);

// specific prices
$specificPriceArray = $this->getSpecificPricesFilterByPriorityMatch(
$this->productPrice,
$user,
$pointSale
);

foreach ($specificPriceArray as $specificPrice) {
$priceArray[] = [
'from_quantity' => $specificPrice->from_quantity ? $specificPrice->from_quantity : 0,
'price_with_tax' => $this->getPriceWithTax([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $pointSale,
'quantity' => $specificPrice->from_quantity
]),
];
}

// base price
$priceArray[] = [
'from_quantity' => 0,
'price_with_tax' => $this->getPriceWithTax(),
];

return $priceArray;
}

public function getSpecificPricesFilterByPriorityMatch($specificPrices, $user, $pointSale)
{
$priorityMatchSpecificPrice = ProductPrice::getPriorityMatchOfSpecificPriceArray($specificPrices, $user, $pointSale);

Chargement…
Annuler
Enregistrer