소스 검색

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

refactoring
Guillaume 2 년 전
부모
커밋
a3c96e1bb1
4개의 변경된 파일65개의 추가작업 그리고 42개의 파일을 삭제
  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 파일 보기



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


$productsArray = Product::find() $productsArray = Product::find()


$productOrderArray = []; $productOrderArray = [];
foreach ($productsArray as $product) { 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']] = [ $productOrderArray[$product['id']] = [
'quantity' => 0, 'quantity' => 0,

+ 2
- 10
backend/controllers/DocumentController.php 파일 보기

'id', 'id',
function ($product) use ($document, $userProducer, $pointSale) { function ($product) use ($document, $userProducer, $pointSale) {
return array_merge($product->getAttributes(), [ 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, 'wording_unit' => $product->wording_unit,
'tax_rate' => $product->taxRate->value 'tax_rate' => $product->taxRate->value
]); ]);

+ 26
- 3
backend/web/js/vuejs/document-form.js 파일 보기

changeProductAdd: function(event) { changeProductAdd: function(event) {
var idProduct = event.currentTarget.value ; var idProduct = event.currentTarget.value ;
this.productAddId = idProduct ; 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() ; 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) { changeQuantityProductAdd: function(quantity) {
var step = this.getStepProductAdd() ; var step = this.getStepProductAdd() ;
quantity = quantity * step ; quantity = quantity * step ;
if(this.productAddQuantity < 1) { if(this.productAddQuantity < 1) {
this.productAddQuantity = step ; this.productAddQuantity = step ;
} }
this.productAddPrice = this.getBestProductPrice(app.productAddId, this.productAddQuantity);
}, },
submitProductAdd: function() { submitProductAdd: function() {
var app = this ; var app = this ;

+ 36
- 0
common/models/Product.php 파일 보기

return $strUnit; 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) public function getSpecificPricesFilterByPriorityMatch($specificPrices, $user, $pointSale)
{ {
$priorityMatchSpecificPrice = ProductPrice::getPriorityMatchOfSpecificPriceArray($specificPrices, $user, $pointSale); $priorityMatchSpecificPrice = ProductPrice::getPriorityMatchOfSpecificPriceArray($specificPrices, $user, $pointSale);

Loading…
취소
저장