Browse Source

Prix

feature/export_comptable
Guillaume 4 years ago
parent
commit
7735728fed
3 changed files with 34 additions and 17 deletions
  1. +2
    -2
      ShopBundle/Services/Order/OrderUtils.php
  2. +22
    -15
      ShopBundle/Services/Price/OrderShopPriceUtils.php
  3. +10
    -0
      ShopBundle/Services/Price/PriceUtils.php

+ 2
- 2
ShopBundle/Services/Order/OrderUtils.php View File



if ($order) { if ($order) {
$data['count'] = $this->countQuantities($order); $data['count'] = $this->countQuantities($order);
$data['total_with_tax'] = $this->priceUtils->getTotalWithTaxAndReduction($order);
$data['total_with_tax'] = $this->priceUtils->getTotalWithTax($order);
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order); $data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order);
} }
return $data; return $data;


public function isOrderPaid($order) public function isOrderPaid($order)
{ {
if ($this->getTotalOrderPayments($order) >= $this->priceUtils->getTotalWithTaxAndReduction($order)) {
if ($this->getTotalOrderPayments($order) >= $this->priceUtils->getTotalWithTax($order)) {
return true; return true;
} else { } else {
$order->editError[] = 'field.error.orderStatus.noPayment'; $order->editError[] = 'field.error.orderStatus.noPayment';

+ 22
- 15
ShopBundle/Services/Price/OrderShopPriceUtils.php View File

} }




public function getTotalOrderProductsTaxes(OrderShopInterface $orderShop):float {
public function getTotalOrderProductsTaxes(OrderShopInterface $orderShop):float
{
return 0 ;
} }


public function getOrderProductsTaxesAsArray(OrderShopInterface $orderShop):array public function getOrderProductsTaxesAsArray(OrderShopInterface $orderShop):array
return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop); return $this->getTotalOrderProducts($orderShop) / $this->getTotalOrderProductsWithReductions($orderShop);
} }


private function getTaxRateAverage(OrderShopInterface $order):float
private function getTaxRateAverage(OrderShopInterface $orderShop):float
{ {
return $this->getTotalOrderProductsWithTax() / $this->getTotalOrderProducts();
return $this->getTotalOrderProductsWithTax($orderShop) / $this->getTotalOrderProducts($orderShop);
} }


public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop) public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop)
if ($orderReductionCart->getBehaviorTaxRate() == 'tax-excluded') { if ($orderReductionCart->getBehaviorTaxRate() == 'tax-excluded') {
$price = $orderReductionCart->getValue(); $price = $orderReductionCart->getValue();
} else if ($orderReductionCart->getBehaviorTaxRate() == 'tax-included') { } else if ($orderReductionCart->getBehaviorTaxRate() == 'tax-included') {
$price = $orderReductionCart->getValue() / $this->getTaxRateAverage();
$price = $orderReductionCart->getValue() / $this->getTaxRateAverage($order);
} }


} }


public function getOrderProductsReductionCartAmountWithTax(OrderShopInterface $order, $orderReductionCart) public function getOrderProductsReductionCartAmountWithTax(OrderShopInterface $order, $orderReductionCart)
{ {
$amount = 0;


$amount =0;
if($orderReductionCart->getAppliedTo() === ReductionCart::APPLIED_TO_ORDER_PRODUCTS) { if($orderReductionCart->getAppliedTo() === ReductionCart::APPLIED_TO_ORDER_PRODUCTS) {
if ($orderReductionCart->getUnit() == 'percent') { if ($orderReductionCart->getUnit() == 'percent') {

$amount = $this->amountReductionByPercentValue( $amount = $this->amountReductionByPercentValue(
$this->getTotalOrderProductsWithTax($order), $this->getTotalOrderProductsWithTax($order),
$orderReductionCart->getValue() $orderReductionCart->getValue()
); );
} else if ($orderReductionCart->getUnit() == 'amount') {
}
elseif ($orderReductionCart->getUnit() == 'amount') {
if ($orderReductionCart->getBehaviorTaxRate() == 'tax-excluded') { if ($orderReductionCart->getBehaviorTaxRate() == 'tax-excluded') {
$amount = $orderReductionCart->getValue() * $this->getTaxRateAverage();
} else if ($orderReductionCart->getBehaviorTaxRate() == 'tax-included') {
$amount = $orderReductionCart->getValue() * $this->getTaxRateAverage($order);
}
elseif ($orderReductionCart->getBehaviorTaxRate() == 'tax-included') {
$amount = $orderReductionCart->getValue() ; $amount = $orderReductionCart->getValue() ;
} }


} }
} }

return $amount ; return $amount ;
} }


public function getOrderProductsReductionCreditAmountWithoutTax(OrderShopInterface $order, OrderReductionCreditInterface $orderReductionCredit) public function getOrderProductsReductionCreditAmountWithoutTax(OrderShopInterface $order, OrderReductionCreditInterface $orderReductionCredit)
{ {
$amount =0;
$amount = 0;
if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-excluded') { if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-excluded') {
$amount = $orderReductionCredit->getValue(); $amount = $orderReductionCredit->getValue();
} else if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-included') {
$amount = $orderReductionCredit->getValue() / $this->getTaxRateAverage();
}
else if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-included') {
$amount = $orderReductionCredit->getValue() / $this->getTaxRateAverage($order);
} }


return $amount; return $amount;


public function getOrderProductsReductionCreditAmountWithTax(OrderShopInterface $order, OrderReductionCreditInterface $orderReductionCredit) public function getOrderProductsReductionCreditAmountWithTax(OrderShopInterface $order, OrderReductionCreditInterface $orderReductionCredit)
{ {
$amount =0;
$amountWithTax = 0;
if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-excluded') { if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-excluded') {
$amountWithTax = $orderReductionCredit->getValue() * $this->getTaxRateAverage();
} else if ($orderReductionCredit->getBehaviorTaxRate() == 'tax-included') {
$amountWithTax = $orderReductionCredit->getValue() * $this->getTaxRateAverage($order);
}
elseif ($orderReductionCredit->getBehaviorTaxRate() == 'tax-included') {
$amountWithTax = $orderReductionCredit->getValue(); $amountWithTax = $orderReductionCredit->getValue();
} }

return $amountWithTax; return $amountWithTax;
} }
} }

+ 10
- 0
ShopBundle/Services/Price/PriceUtils.php View File

return $this->$service->$name($entity) ; return $this->$service->$name($entity) ;
} }
} }
else {
if(!strlen($service)) {
throw new \ErrorException("PriceUtils : le type d'entité n'est pas géré.") ;
}
else {
if(!method_exists($this->$service, $name)) {
throw new \ErrorException("PriceUtils : la méthode ".$name." du service ".$service." n'existe pas.") ;
}
}
}


return false ; return false ;
} }

Loading…
Cancel
Save