当前位置: 首页>>代码示例>>PHP>>正文


PHP Creditmemo::setShippingTaxAmount方法代码示例

本文整理汇总了PHP中Magento\Sales\Model\Order\Creditmemo::setShippingTaxAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Creditmemo::setShippingTaxAmount方法的具体用法?PHP Creditmemo::setShippingTaxAmount怎么用?PHP Creditmemo::setShippingTaxAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Sales\Model\Order\Creditmemo的用法示例。


在下文中一共展示了Creditmemo::setShippingTaxAmount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: collect


//.........这里部分代码省略.........
             $baseDiscountTaxCompensation = $orderItem->getBaseDiscountTaxCompensationInvoiced() - $orderItem->getBaseDiscountTaxCompensationRefunded();
             if (!$item->isLast()) {
                 $availableQty = $orderItemQty - $orderItem->getQtyRefunded();
                 $tax = $creditmemo->roundPrice($tax / $availableQty * $item->getQty());
                 $baseTax = $creditmemo->roundPrice($baseTax / $availableQty * $item->getQty(), 'base');
                 $discountTaxCompensation = $creditmemo->roundPrice($discountTaxCompensation / $availableQty * $item->getQty());
                 $baseDiscountTaxCompensation = $creditmemo->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;
         }
     }
     $isPartialShippingRefunded = false;
     if ($invoice = $creditmemo->getInvoice()) {
         //recalculate tax amounts in case if refund shipping value was changed
         if ($order->getBaseShippingAmount() && $creditmemo->getBaseShippingAmount()) {
             $taxFactor = $creditmemo->getBaseShippingAmount() / $order->getBaseShippingAmount();
             $shippingTaxAmount = $invoice->getShippingTaxAmount() * $taxFactor;
             $baseShippingTaxAmount = $invoice->getBaseShippingTaxAmount() * $taxFactor;
             $totalDiscountTaxCompensation += $invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
             $baseTotalDiscountTaxCompensation += $invoice->getBaseShippingDiscountTaxCompensationAmnt() * $taxFactor;
             $shippingDiscountTaxCompensationAmount = $invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
             $baseShippingDiscountTaxCompensationAmount = $invoice->getBaseShippingDiscountTaxCompensationAmnt() * $taxFactor;
             $shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
             $baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
             $totalDiscountTaxCompensation = $creditmemo->roundPrice($totalDiscountTaxCompensation);
             $baseTotalDiscountTaxCompensation = $creditmemo->roundPrice($baseTotalDiscountTaxCompensation, 'base');
             $shippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($shippingDiscountTaxCompensationAmount);
             $baseShippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($baseShippingDiscountTaxCompensationAmount, 'base');
             if ($taxFactor < 1 && $invoice->getShippingTaxAmount() > 0) {
                 $isPartialShippingRefunded = true;
             }
             $totalTax += $shippingTaxAmount;
             $baseTotalTax += $baseShippingTaxAmount;
         }
     } else {
         $orderShippingAmount = $order->getShippingAmount();
         $baseOrderShippingAmount = $order->getBaseShippingAmount();
         $baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();
         $shippingTaxAmount = 0;
         $baseShippingTaxAmount = 0;
         $shippingDiscountTaxCompensationAmount = 0;
         $baseShippingDiscountTaxCompensationAmount = 0;
         $shippingDelta = $baseOrderShippingAmount - $baseOrderShippingRefundedAmount;
         if ($shippingDelta > $creditmemo->getBaseShippingAmount()) {
             $part = $creditmemo->getShippingAmount() / $orderShippingAmount;
             $basePart = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
             $shippingTaxAmount = $order->getShippingTaxAmount() * $part;
             $baseShippingTaxAmount = $order->getBaseShippingTaxAmount() * $basePart;
             $shippingDiscountTaxCompensationAmount = $order->getShippingDiscountTaxCompensationAmount() * $part;
             $baseShippingDiscountTaxCompensationAmount = $order->getBaseShippingDiscountTaxCompensationAmnt() * $basePart;
             $shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
             $baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
             $shippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($shippingDiscountTaxCompensationAmount);
             $baseShippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($baseShippingDiscountTaxCompensationAmount, 'base');
             if ($part < 1 && $order->getShippingTaxAmount() > 0) {
                 $isPartialShippingRefunded = true;
             }
         } elseif ($shippingDelta == $creditmemo->getBaseShippingAmount()) {
             $shippingTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
             $baseShippingTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
             $shippingDiscountTaxCompensationAmount = $order->getShippingDiscountTaxCompensationAmount() - $order->getShippingDiscountTaxCompensationRefunded();
             $baseShippingDiscountTaxCompensationAmount = $order->getBaseShippingDiscountTaxCompensationAmnt() - $order->getBaseShippingDiscountTaxCompensationRefunded();
         }
         $totalTax += $shippingTaxAmount;
         $baseTotalTax += $baseShippingTaxAmount;
         $totalDiscountTaxCompensation += $shippingDiscountTaxCompensationAmount;
         $baseTotalDiscountTaxCompensation += $baseShippingDiscountTaxCompensationAmount;
     }
     $allowedTax = $order->getTaxInvoiced() - $order->getTaxRefunded() - $creditmemo->getTaxAmount();
     $allowedBaseTax = $order->getBaseTaxInvoiced() - $order->getBaseTaxRefunded() - $creditmemo->getBaseTaxAmount();
     $allowedDiscountTaxCompensation = $order->getDiscountTaxCompensationInvoiced() + $order->getShippingDiscountTaxCompensationAmount() - $order->getDiscountTaxCompensationRefunded() - $order->getShippingDiscountTaxCompensationRefunded() - $creditmemo->getDiscountTaxCompensationAmount() - $creditmemo->getShippingDiscountTaxCompensationAmount();
     $allowedBaseDiscountTaxCompensation = $order->getBaseDiscountTaxCompensationInvoiced() + $order->getBaseShippingDiscountTaxCompensationAmnt() - $order->getBaseDiscountTaxCompensationRefunded() - $order->getBaseShippingDiscountTaxCompensationRefunded() - $creditmemo->getBaseShippingDiscountTaxCompensationAmnt() - $creditmemo->getBaseDiscountTaxCompensationAmount();
     if ($creditmemo->isLast() && !$isPartialShippingRefunded) {
         $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);
     }
     $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $totalTax);
     $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTotalTax);
     $creditmemo->setDiscountTaxCompensationAmount($totalDiscountTaxCompensation);
     $creditmemo->setBaseDiscountTaxCompensationAmount($baseTotalDiscountTaxCompensation);
     $creditmemo->setShippingTaxAmount($shippingTaxAmount);
     $creditmemo->setBaseShippingTaxAmount($baseShippingTaxAmount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax + $totalDiscountTaxCompensation);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax + $baseTotalDiscountTaxCompensation);
     return $this;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:101,代码来源:Tax.php


注:本文中的Magento\Sales\Model\Order\Creditmemo::setShippingTaxAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。