//Disponibilité par unité de référence | //Disponibilité par unité de référence | ||||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | $oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | ||||
$newAvailability = $oldAvailability - ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()); | |||||
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient())); | |||||
$orderProduct->getProduct()->getProductFamily()->setAvailableQuantity($newAvailability); | $orderProduct->getProduct()->getProductFamily()->setAvailableQuantity($newAvailability); | ||||
$this->em->persist($orderProduct->getProduct()->getProductFamily()); | $this->em->persist($orderProduct->getProduct()->getProductFamily()); |
$orderProduct, | $orderProduct, | ||||
$this->getPrice($orderProduct), | $this->getPrice($orderProduct), | ||||
$this->getPriceWithTax($orderProduct), | $this->getPriceWithTax($orderProduct), | ||||
1, | |||||
null, | null, | ||||
false | false | ||||
); | ); | ||||
$orderProduct, | $orderProduct, | ||||
$this->getTotal($orderProduct), | $this->getTotal($orderProduct), | ||||
$this->getTotalWithTax($orderProduct), | $this->getTotalWithTax($orderProduct), | ||||
$orderProduct->getQuantityOrder(), | |||||
null, | null, | ||||
false | false | ||||
); | ); | ||||
return $this->applyReductionCatalog( | return $this->applyReductionCatalog( | ||||
$orderProduct, | $orderProduct, | ||||
$this->getTotal($orderProduct), | $this->getTotal($orderProduct), | ||||
$this->getTotalWithTax($orderProduct) | |||||
$this->getTotalWithTax($orderProduct), | |||||
$orderProduct->getQuantityOrder() | |||||
); | ); | ||||
} | } | ||||
return round((($price * $percent)) / 100, 2); | return round((($price * $percent)) / 100, 2); | ||||
} | } | ||||
public function applyReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null, $withTax = true): ?float | |||||
public function applyReductionCatalog($entity, $price, $priceWithTax, $quantity = 1, $reductionCatalog = null, $withTax = true): ?float | |||||
{ | { | ||||
if ($reductionCatalog) { | if ($reductionCatalog) { | ||||
$reductionCatalogValue = $reductionCatalog->getValue(); | $reductionCatalogValue = $reductionCatalog->getValue(); | ||||
$reductionCatalogUnit = $reductionCatalog->getUnit(); | $reductionCatalogUnit = $reductionCatalog->getUnit(); | ||||
$priceWithTax = $this->applyTax( | $priceWithTax = $this->applyTax( | ||||
$this->applyReductionAmount( | $this->applyReductionAmount( | ||||
$price, | $price, | ||||
$reductionCatalogValue | |||||
$reductionCatalogValue * $quantity | |||||
), | ), | ||||
$entity->getTaxRateInherited()->getValue() | $entity->getTaxRateInherited()->getValue() | ||||
); | ); | ||||
} elseif ($reductionCatalogBehaviorTaxRate == 'tax-included') { | } elseif ($reductionCatalogBehaviorTaxRate == 'tax-included') { | ||||
$priceWithTax = $this->applyReductionAmount( | $priceWithTax = $this->applyReductionAmount( | ||||
$priceWithTax, | $priceWithTax, | ||||
$reductionCatalogValue | |||||
$reductionCatalogValue * $quantity | |||||
); | ); | ||||
} | } | ||||
} | } |