本文整理汇总了PHP中Magento\Sales\Model\Order\Invoice::roundPrice方法的典型用法代码示例。如果您正苦于以下问题:PHP Invoice::roundPrice方法的具体用法?PHP Invoice::roundPrice怎么用?PHP Invoice::roundPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order\Invoice
的用法示例。
在下文中一共展示了Invoice::roundPrice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect
/**
* @param \Magento\Sales\Model\Order\Invoice $invoice
* @return $this
*/
public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
{
$invoice->setDiscountAmount(0);
$invoice->setBaseDiscountAmount(0);
$totalDiscountAmount = 0;
$baseTotalDiscountAmount = 0;
/**
* Checking if shipping discount was added in previous invoices.
* So basically if we have invoice with positive discount and it
* was not canceled we don't add shipping discount to this one.
*/
$addShippingDiscount = true;
foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
if ($previousInvoice->getDiscountAmount()) {
$addShippingDiscount = false;
}
}
if ($addShippingDiscount) {
$totalDiscountAmount = $totalDiscountAmount + $invoice->getOrder()->getShippingDiscountAmount();
$baseTotalDiscountAmount = $baseTotalDiscountAmount + $invoice->getOrder()->getBaseShippingDiscountAmount();
}
/** @var $item \Magento\Sales\Model\Order\Invoice\Item */
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$orderItemDiscount = (double) $orderItem->getDiscountAmount();
$baseOrderItemDiscount = (double) $orderItem->getBaseDiscountAmount();
$orderItemQty = $orderItem->getQtyOrdered();
if ($orderItemDiscount && $orderItemQty) {
/**
* Resolve rounding problems
*/
$discount = $orderItemDiscount - $orderItem->getDiscountInvoiced();
$baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced();
if (!$item->isLast()) {
$activeQty = $orderItemQty - $orderItem->getQtyInvoiced();
$discount = $invoice->roundPrice($discount / $activeQty * $item->getQty(), 'regular', true);
$baseDiscount = $invoice->roundPrice($baseDiscount / $activeQty * $item->getQty(), 'base', true);
}
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
$totalDiscountAmount += $discount;
$baseTotalDiscountAmount += $baseDiscount;
}
}
$invoice->setDiscountAmount(-$totalDiscountAmount);
$invoice->setBaseDiscountAmount(-$baseTotalDiscountAmount);
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount);
return $this;
}
示例2: collect
/**
* Collect Weee amounts for the invoice
*
* @param \Magento\Sales\Model\Order\Invoice $invoice
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
{
$store = $invoice->getStore();
$order = $invoice->getOrder();
$totalWeeeAmount = 0;
$baseTotalWeeeAmount = 0;
$totalWeeeAmountInclTax = 0;
$baseTotalWeeeAmountInclTax = 0;
$totalWeeeTaxAmount = 0;
$baseTotalWeeeTaxAmount = 0;
/** @var \Magento\Sales\Model\Order\Invoice\Item $item */
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
$orderItemQty = $orderItem->getQtyOrdered();
if (!$orderItemQty || $orderItem->isDummy() || $item->getQty() <= 0) {
continue;
}
$ratio = $item->getQty() / $orderItemQty;
$orderItemWeeeAmount = $orderItem->getWeeeTaxAppliedRowAmount();
$orderItemBaseWeeeAmount = $orderItem->getBaseWeeeTaxAppliedRowAmnt();
$weeeAmount = $invoice->roundPrice($orderItemWeeeAmount * $ratio);
$baseWeeeAmount = $invoice->roundPrice($orderItemBaseWeeeAmount * $ratio, 'base');
$orderItemWeeeInclTax = $this->_weeeData->getRowWeeeTaxInclTax($orderItem);
$orderItemBaseWeeeInclTax = $this->_weeeData->getBaseRowWeeeTaxInclTax($orderItem);
$weeeAmountInclTax = $invoice->roundPrice($orderItemWeeeInclTax * $ratio);
$baseWeeeAmountInclTax = $invoice->roundPrice($orderItemBaseWeeeInclTax * $ratio, 'base');
$orderItemWeeeTax = $orderItemWeeeInclTax - $orderItemWeeeAmount;
$itemWeeeTax = $weeeAmountInclTax - $weeeAmount;
$itemBaseWeeeTax = $baseWeeeAmountInclTax - $baseWeeeAmount;
if ($item->isLast()) {
$weeeAmount = $orderItemWeeeAmount - $this->_weeeData->getWeeeAmountInvoiced($orderItem);
$baseWeeeAmount = $orderItemBaseWeeeAmount - $this->_weeeData->getBaseWeeeAmountInvoiced($orderItem);
$itemWeeeTax = $orderItemWeeeTax - $this->_weeeData->getWeeeTaxAmountInvoiced($orderItem);
$itemBaseWeeeTax = $orderItemWeeeTax - $this->_weeeData->getBaseWeeeTaxAmountInvoiced($orderItem);
}
$totalWeeeTaxAmount += $itemWeeeTax;
$baseTotalWeeeTaxAmount += $itemBaseWeeeTax;
//Set the ratio of the tax amount in invoice item compared to tax amount in order item
//This information is needed to calculate tax per tax rate later
if ($orderItemWeeeTax != 0) {
$taxRatio = [];
if ($item->getTaxRatio()) {
$taxRatio = unserialize($item->getTaxRatio());
}
$taxRatio[\Magento\Weee\Model\Total\Quote\Weee::ITEM_TYPE] = $itemWeeeTax / $orderItemWeeeTax;
$item->setTaxRatio(serialize($taxRatio));
}
$item->setWeeeTaxAppliedRowAmount($weeeAmount);
$item->setBaseWeeeTaxAppliedRowAmount($baseWeeeAmount);
$newApplied = [];
$applied = $this->_weeeData->getApplied($orderItem);
foreach ($applied as $one) {
$title = (string) $one['title'];
$one['base_row_amount'] = $invoice->roundPrice($one['base_row_amount'] * $ratio, $title . '_base');
$one['row_amount'] = $invoice->roundPrice($one['row_amount'] * $ratio, $title);
$one['base_row_amount_incl_tax'] = $invoice->roundPrice($one['base_row_amount_incl_tax'] * $ratio, $title . '_base');
$one['row_amount_incl_tax'] = $invoice->roundPrice($one['row_amount_incl_tax'] * $ratio, $title);
$newApplied[] = $one;
}
$this->_weeeData->setApplied($item, $newApplied);
//Update order item
$newApplied = [];
$applied = $this->_weeeData->getApplied($orderItem);
foreach ($applied as $one) {
if (isset($one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED])) {
$one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] + $baseWeeeAmount;
} else {
$one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] = $baseWeeeAmount;
}
if (isset($one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED])) {
$one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] + $weeeAmount;
} else {
$one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] = $weeeAmount;
}
if (isset($one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED])) {
$one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] + $itemWeeeTax;
} else {
$one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] = $itemWeeeTax;
}
if (isset($one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED])) {
$one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] + $itemBaseWeeeTax;
} else {
$one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] = $itemBaseWeeeTax;
}
$newApplied[] = $one;
}
$this->_weeeData->setApplied($orderItem, $newApplied);
$item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
$item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
$totalWeeeAmount += $weeeAmount;
$baseTotalWeeeAmount += $baseWeeeAmount;
//.........这里部分代码省略.........
示例3: collect
/**
* Collect invoice tax amount
*
* @param \Magento\Sales\Model\Order\Invoice $invoice
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
{
$totalTax = 0;
$baseTotalTax = 0;
$totalDiscountTaxCompensation = 0;
$baseTotalDiscountTaxCompensation = 0;
$order = $invoice->getOrder();
/** @var $item \Magento\Sales\Model\Order\Invoice\Item */
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
$orderItemQty = $orderItem->getQtyOrdered();
if (($orderItem->getTaxAmount() || $orderItem->getDiscountTaxCompensationAmount()) && $orderItemQty) {
if ($item->getOrderItem()->isDummy() || $item->getQty() <= 0) {
continue;
}
/**
* Resolve rounding problems
*/
$tax = $orderItem->getTaxAmount() - $orderItem->getTaxInvoiced();
$baseTax = $orderItem->getBaseTaxAmount() - $orderItem->getBaseTaxInvoiced();
$discountTaxCompensation = $orderItem->getDiscountTaxCompensationAmount() - $orderItem->getDiscountTaxCompensationInvoiced();
$baseDiscountTaxCompensation = $orderItem->getBaseDiscountTaxCompensationAmount() - $orderItem->getBaseDiscountTaxCompensationInvoiced();
if (!$item->isLast()) {
$availableQty = $orderItemQty - $orderItem->getQtyInvoiced();
$tax = $invoice->roundPrice($tax / $availableQty * $item->getQty());
$baseTax = $invoice->roundPrice($baseTax / $availableQty * $item->getQty(), 'base');
$discountTaxCompensation = $invoice->roundPrice($discountTaxCompensation / $availableQty * $item->getQty());
$baseDiscountTaxCompensation = $invoice->roundPrice($baseDiscountTaxCompensation / $availableQty * $item->getQty(), 'base');
}
$item->setTaxAmount($tax);
$item->setBaseTaxAmount($baseTax);
$item->setDiscountTaxCompensationAmount($discountTaxCompensation);
$item->setBaseDiscountTaxCompensationAmount($baseDiscountTaxCompensation);
$totalTax += $tax;
$baseTotalTax += $baseTax;
$totalDiscountTaxCompensation += $discountTaxCompensation;
$baseTotalDiscountTaxCompensation += $baseDiscountTaxCompensation;
}
}
if ($this->_canIncludeShipping($invoice)) {
$totalTax += $order->getShippingTaxAmount();
$baseTotalTax += $order->getBaseShippingTaxAmount();
$totalDiscountTaxCompensation += $order->getShippingDiscountTaxCompensationAmount();
$baseTotalDiscountTaxCompensation += $order->getBaseShippingDiscountTaxCompensationAmnt();
$invoice->setShippingTaxAmount($order->getShippingTaxAmount());
$invoice->setBaseShippingTaxAmount($order->getBaseShippingTaxAmount());
$invoice->setShippingDiscountTaxCompensationAmount($order->getShippingDiscountTaxCompensationAmount());
$invoice->setBaseShippingDiscountTaxCompensationAmnt($order->getBaseShippingDiscountTaxCompensationAmnt());
}
$allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced();
$allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced();
$allowedDiscountTaxCompensation = $order->getDiscountTaxCompensationAmount() + $order->getShippingDiscountTaxCompensationAmount() - $order->getDiscountTaxCompensationInvoiced() - $order->getShippingDiscountTaxCompensationInvoiced();
$allowedBaseDiscountTaxCompensation = $order->getBaseDiscountTaxCompensationAmount() + $order->getBaseShippingDiscountTaxCompensationAmnt() - $order->getBaseDiscountTaxCompensationInvoiced() - $order->getBaseShippingDiscountTaxCompensationInvoiced();
if ($invoice->isLast()) {
$totalTax = $allowedTax;
$baseTotalTax = $allowedBaseTax;
$totalDiscountTaxCompensation = $allowedDiscountTaxCompensation;
$baseTotalDiscountTaxCompensation = $allowedBaseDiscountTaxCompensation;
} else {
$totalTax = min($allowedTax, $totalTax);
$baseTotalTax = min($allowedBaseTax, $baseTotalTax);
$totalDiscountTaxCompensation = min($allowedDiscountTaxCompensation, $totalDiscountTaxCompensation);
$baseTotalDiscountTaxCompensation = min($allowedBaseDiscountTaxCompensation, $baseTotalDiscountTaxCompensation);
}
$invoice->setTaxAmount($totalTax);
$invoice->setBaseTaxAmount($baseTotalTax);
$invoice->setDiscountTaxCompensationAmount($totalDiscountTaxCompensation);
$invoice->setBaseDiscountTaxCompensationAmount($baseTotalDiscountTaxCompensation);
$invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax + $totalDiscountTaxCompensation);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax + $baseTotalDiscountTaxCompensation);
return $this;
}