/** * Calculate the row total for an item * * @param QuoteDetailsItem $item * @return float */ protected function calcRowTotal(QuoteDetailsItem $item) { $qty = $this->getTotalQuantity($item); // Round unit price before multiplying to prevent losing 1 cent on subtotal $total = $this->calculator->round($item->getUnitPrice()) * $qty; return $this->calculator->round($total); }
/** * Given a store price that includes tax at the store rate, this function will back out the store's tax, and add in * the customer's tax. Returns this new price which is the customer's price including tax. * * @param float $storePriceInclTax * @param float $storeRate * @param float $customerRate * @return float */ protected function calculatePriceInclTax($storePriceInclTax, $storeRate, $customerRate) { $storeTax = $this->calculationTool->calcTaxAmount($storePriceInclTax, $storeRate, true, false); $priceExclTax = $storePriceInclTax - $storeTax; $customerTax = $this->calculationTool->calcTaxAmount($priceExclTax, $customerRate, false, false); $customerPriceInclTax = $this->calculationTool->round($priceExclTax + $customerTax); return $customerPriceInclTax; }
/** * Calculate row information for item based on children calculation * * @param TaxDetailsItemInterface[] $children * @param int $quantity * @return TaxDetailsItemInterface */ protected function calculateParent($children, $quantity) { $rowTotal = 0.0; $rowTotalInclTax = 0.0; $rowTax = 0.0; $taxableAmount = 0.0; foreach ($children as $child) { $rowTotal += $child->getRowTotal(); $rowTotalInclTax += $child->getRowTotalInclTax(); $rowTax += $child->getRowTax(); $taxableAmount += $child->getTaxableAmount(); } $price = $this->calculationTool->round($rowTotal / $quantity); $priceInclTax = $this->calculationTool->round($rowTotalInclTax / $quantity); $taxDetailsItemDataObject = $this->taxDetailsItemDataObjectFactory->create()->setPrice($price)->setPriceInclTax($priceInclTax)->setRowTotal($rowTotal)->setRowTotalInclTax($rowTotalInclTax)->setRowTax($rowTax); return $taxDetailsItemDataObject; }