本文整理汇总了PHP中Mage_Sales_Model_Order_Creditmemo::getInvoice方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Order_Creditmemo::getInvoice方法的具体用法?PHP Mage_Sales_Model_Order_Creditmemo::getInvoice怎么用?PHP Mage_Sales_Model_Order_Creditmemo::getInvoice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Order_Creditmemo
的用法示例。
在下文中一共展示了Mage_Sales_Model_Order_Creditmemo::getInvoice方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect
public function collect(Mage_Sales_Model_Order_Creditmemo $cm)
{
$order = $cm->getOrder();
if ($order->getPayment()->getMethodInstance()->getCode() != 'cashondelivery') {
return $this;
}
$baseCmTotal = $cm->getBaseGrandTotal();
$cmTotal = $cm->getGrandTotal();
$baseCodFeeCredited = $order->getBaseCodFeeCredited();
$codFeeCredited = $order->getCodFeeCredited();
$baseCodFeeInvoiced = $order->getBaseCodFeeInvoiced();
$codFeeInvoiced = $order->getCodFeeInvoiced();
if ($cm->getInvoice()) {
$invoice = $cm->getInvoice();
$baseCodFeeToCredit = $invoice->getBaseCodFee();
$codFeeToCredit = $invoice->getCodFee();
} else {
$baseCodFeeToCredit = $baseCodFeeInvoiced;
$codFeeToCredit = $codFeeInvoiced;
}
if (!$baseCodFeeToCredit > 0) {
return $this;
}
// Subtracting invoiced COD fee from Credit memo total
//$cm->setBaseGrandTotal($baseCmTotal-$baseCodFeeToCredit);
//$cm->setGrandTotal($cmTotal-$codFeeToCredit);
//$cm->setBaseCodFee($baseCodFeeToCredit);
//$cm->setCodFee($codFeeToCredit);
//$order->setBaseCodFeeCredited($baseCodFeeCredited+$baseCodFeeToCredit);
//$order->setCodFeeCredited($codFeeCredited+$baseCodFeeToCredit);
return $this;
}
示例2: collect
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
if (!$creditmemo->getInvoice() || !$creditmemo->getInvoice()->getId()) {
return;
}
$order = $creditmemo->getOrder();
if ($order->getWebposCash() < 0.0001 || $order->getGrandTotal() < 0.0001) {
return;
}
$ratio = $creditmemo->getGrandTotal() / $order->getGrandTotal();
$cash = $order->getWebposCash() * $ratio;
$baseCash = $order->getWebposBaseCash() * $ratio;
$maxcash = $order->getWebposCash();
$maxbaseCash = $order->getWebposBaseCash();
foreach ($order->getCreditmemosCollection() as $existedCreditmemo) {
if ($maxcash > 0.0001) {
$maxcash -= $existedCreditmemo->getWebposCash();
$maxbaseCash -= $existedCreditmemo->getWebposBaseCash();
}
}
if ($cash > $maxcash) {
$cash = $maxcash;
$baseCash = $maxbaseCash;
}
if ($cash > 0.0001) {
$creditmemo->setWebposCash($cash)->setWebposBaseCash($baseCash);
if ($creditmemo->getGrandTotal() <= $cash) {
$creditmemo->setBaseGrandTotal(0.0)->setGrandTotal(0.0);
} else {
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $cash)->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseCash);
}
}
}
示例3: collect
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
if (!$creditmemo->getInvoice() || !$creditmemo->getInvoice()->getId()) {
return;
}
$order = $creditmemo->getOrder();
if ($order->getWebposChange() < 0.0001) {
return;
}
$creditmemo->setWebposChange($order->getWebposChange())->setWebposBaseChange($order->getWebposBaseChange());
}
示例4: collect
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$totalTax = 0;
$baseTotalTax = 0;
foreach ($creditmemo->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
$orderItemTax = $item->getOrderItem()->getTaxAmount();
$baseOrderItemTax = $item->getOrderItem()->getBaseTaxAmount();
$orderItemQty = $item->getOrderItem()->getQtyOrdered();
if ($orderItemTax && $orderItemQty) {
$tax = $orderItemTax * $item->getQty() / $orderItemQty;
$baseTax = $baseOrderItemTax * $item->getQty() / $orderItemQty;
$tax = $creditmemo->getStore()->roundPrice($tax);
$baseTax = $creditmemo->getStore()->roundPrice($baseTax);
$item->setTaxAmount($tax);
$item->setBaseTaxAmount($baseTax);
$totalTax += $tax;
$baseTotalTax += $baseTax;
}
}
if ($invoice = $creditmemo->getInvoice()) {
$totalTax += $invoice->getShippingTaxAmount();
$baseTotalTax += $invoice->getBaseShippingTaxAmount();
$creditmemo->setShippingTaxAmount($invoice->getShippingTaxAmount());
$creditmemo->setBaseShippingTaxAmount($invoice->getBaseShippingTaxAmount());
} else {
$shippingAmount = $creditmemo->getOrder()->getBaseShippingAmount();
$shippingRefundedAmount = $creditmemo->getOrder()->getBaseShippingRefunded();
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
if ($shippingAmount - $shippingRefundedAmount > $creditmemo->getShippingAmount()) {
$shippingTaxAmount = $creditmemo->getShippingAmount() * ($creditmemo->getOrder()->getShippingTaxAmount() / $shippingAmount);
$baseShippingTaxAmount = $creditmemo->getBaseShippingAmount() * ($creditmemo->getOrder()->getBaseShippingTaxAmount() / $shippingAmount);
$shippingTaxAmount = $creditmemo->getStore()->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->getStore()->roundPrice($baseShippingTaxAmount);
} elseif ($shippingAmount - $shippingRefundedAmount == $creditmemo->getShippingAmount()) {
$shippingTaxAmount = $creditmemo->getOrder()->getShippingTaxAmount() - $creditmemo->getOrder()->getShippingTaxRefunded();
$baseShippingTaxAmount = $creditmemo->getOrder()->getBaseShippingTaxAmount() - $creditmemo->getOrder()->getBaseShippingTaxRefunded();
}
$totalTax += $shippingTaxAmount;
$baseTotalTax += $baseShippingTaxAmount;
}
$tmpBaseTotalTax = $baseTotalTax - ($creditmemo->getOrder()->getBaseTaxRefunded() - $creditmemo->getOrder()->getBaseShippingTaxRefunded());
if ($tmpBaseTotalTax < 0) {
$baseTotalTax = 0;
$totalTax = 0;
}
$creditmemo->setTaxAmount($totalTax);
$creditmemo->setBaseTaxAmount($baseTotalTax);
$creditmemo->setShippingTaxAmount($shippingTaxAmount);
$creditmemo->setBaseShippingTaxAmount($baseShippingTaxAmount);
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
return $this;
}
示例5: collect
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
$creditmemo->setSveaPaymentFeeAmount(0);
$creditmemo->setBaseSveaPaymentFeeAmount(0);
$creditmemo->setSveaPaymentFeeTaxAmount(0);
$creditmemo->setBaseSveaPaymentFeeTaxAmount(0);
$creditmemo->setSveaPaymentFeeInclTax(0);
$creditmemo->setBaseSveaPaymentFeeInclTax(0);
$order = $creditmemo->getOrder();
if (!$order->getSveaPaymentFeeAmount()) {
return $this;
}
$paymentFeeAmount = 0;
$basePaymentFeeAmount = 0;
$paymentFeeTaxAmount = 0;
$basePaymentFeeTaxAmount = 0;
$paymentFeeTaxInclTax = 0;
$grandTotal = $creditmemo->getGrandTotal();
$baseGrandTotal = $creditmemo->getBaseGrandTotal();
$taxAmount = $creditmemo->getTaxAmount();
$baseTaxAmount = $creditmemo->getBaseTaxAmount();
if ($invoice = $creditmemo->getInvoice()) {
if ($invoice->getSveaPaymentFeeAmount()) {
// Refund specific invoice
$source = $invoice;
}
} else {
if (!$order->getSveaPaymentFeeRefunded()) {
// Refund from order values
$source = $order;
}
}
if (isset($source)) {
$paymentFeeAmount = $source->getSveaPaymentFeeAmount();
$basePaymentFeeAmount = $source->getBaseSveaPaymentFeeAmount();
$paymentFeeTaxAmount = $source->getSveaPaymentFeeTaxAmount();
$basePaymentFeeTaxAmount = $source->getBaseSveaPaymentFeeTaxAmount();
$paymentFeeTaxInclTax = $source->getSveaPaymentFeeInclTax();
$basePaymentFeeInclTax = $source->getBaseSveaPaymentFeeInclTax();
}
$taxAmount += $paymentFeeTaxAmount;
$baseTaxAmount += $basePaymentFeeTaxAmount;
$grandTotal += $paymentFeeTaxInclTax;
$baseGrandTotal += $basePaymentFeeInclTax;
$creditmemo->setSveaPaymentFeeAmount($paymentFeeAmount);
$creditmemo->setBaseSveaPaymentFeeAmount($basePaymentFeeAmount);
$creditmemo->setSveaPaymentFeeTaxAmount($paymentFeeTaxAmount);
$creditmemo->setBaseSveaPaymentFeeTaxAmount($basePaymentFeeTaxAmount);
$creditmemo->setSveaPaymentFeeInclTax($paymentFeeTaxInclTax);
$creditmemo->setBaseSveaPaymentFeeInclTax($basePaymentFeeInclTax);
$creditmemo->setTaxAmount($taxAmount);
$creditmemo->setBaseTaxAmount($baseTaxAmount);
$creditmemo->setGrandTotal($grandTotal);
$creditmemo->setBaseGrandTotal($baseGrandTotal);
return $this;
}
示例6: collect
public function collect(Mage_Sales_Model_Order_Creditmemo $cm)
{
$order = $cm->getOrder();
if (!preg_match('/capayable/', $order->getPayment()->getMethodInstance()->getCode())) {
return $this;
}
$baseCmTotal = $cm->getBaseGrandTotal();
$cmTotal = $cm->getGrandTotal();
$baseTaxAmount = $cm->getBaseTaxAmount();
$taxAmount = $cm->getTaxAmount();
$basePaymentFeeInvoiced = $order->getBaseCapayableFeeInvoiced();
$paymentFeeInvoiced = $order->getCapayableFeeInvoiced();
$basePaymentFeeTaxAmount = $order->getBaseCapayableFeeTaxAmount();
$paymentFeeTaxAmount = $order->getCapayableFeeTaxAmount();
if ($cm->getInvoice()) {
$invoice = $cm->getInvoice();
$basePaymentsFeeToCredit = $invoice->getBaseCapayableFee();
$paymentFeeToCredit = $invoice->getCapayableFee();
$basePaymentFeeTaxAmountToCredit = $invoice->getBaseCapayableFeeTaxAmount();
$paymentFeeTaxAmountToCredit = $invoice->getCapayableFeeTaxAmount();
} else {
$basePaymentsFeeToCredit = $basePaymentFeeInvoiced;
$paymentFeeToCredit = $paymentFeeInvoiced;
$basePaymentFeeTaxAmountToCredit = $basePaymentFeeTaxAmount;
$paymentFeeTaxAmountToCredit = $paymentFeeTaxAmount;
}
if (!$basePaymentsFeeToCredit > 0) {
return $this;
}
// Subtracting invoiced Payment fee from Credit memo total
$cm->setBaseGrandTotal($baseCmTotal + ($basePaymentsFeeToCredit + $basePaymentFeeTaxAmountToCredit));
$cm->setGrandTotal($cmTotal + ($paymentFeeToCredit + $paymentFeeTaxAmountToCredit));
$cm->setTaxAmount($taxAmount + $paymentFeeTaxAmountToCredit);
$cm->setBaseTaxAmount($baseTaxAmount + $basePaymentFeeTaxAmountToCredit);
$cm->setBaseCapayableFee($basePaymentsFeeToCredit);
$cm->setCapayableFee($paymentFeeToCredit);
$cm->setBaseCapayableFeeTaxAmount($basePaymentFeeTaxAmountToCredit);
$cm->setCapayableFeeTaxAmount($paymentFeeTaxAmountToCredit);
return $this;
}
示例7: collect
/**
* Collects the total tax for the credit memo
*
* @param Mage_Sales_Model_Order_Creditmemo $creditmemo
* @return Mage_Sales_Model_Order_Creditmemo_Total_Tax
*/
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$totalTax = 0;
$baseTotalTax = 0;
$totalHiddenTax = 0;
$baseTotalHiddenTax = 0;
$weeeTaxAmount = 0;
$baseWeeeTaxAmount = 0;
$order = $creditmemo->getOrder();
/** @var $item Mage_Sales_Model_Order_Creditmemo_Item */
foreach ($creditmemo->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$orderItemTax = $orderItem->getTaxInvoiced();
$baseOrderItemTax = $orderItem->getBaseTaxInvoiced();
$orderItemHiddenTax = $orderItem->getHiddenTaxInvoiced();
$baseOrderItemHiddenTax = $orderItem->getBaseHiddenTaxInvoiced();
$orderItemQty = $orderItem->getQtyInvoiced();
if (($orderItemTax || $orderItemHiddenTax) && $orderItemQty) {
/**
* Check item tax amount
*/
$tax = $orderItemTax - $orderItem->getTaxRefunded();
$baseTax = $baseOrderItemTax - $orderItem->getTaxRefunded();
$hiddenTax = $orderItemHiddenTax - $orderItem->getHiddenTaxRefunded();
$baseHiddenTax = $baseOrderItemHiddenTax - $orderItem->getBaseHiddenTaxRefunded();
if (!$item->isLast()) {
$availableQty = $orderItemQty - $orderItem->getQtyRefunded();
$tax = $creditmemo->roundPrice($tax / $availableQty * $item->getQty());
$baseTax = $creditmemo->roundPrice($baseTax / $availableQty * $item->getQty(), 'base');
$hiddenTax = $creditmemo->roundPrice($hiddenTax / $availableQty * $item->getQty());
$baseHiddenTax = $creditmemo->roundPrice($baseHiddenTax / $availableQty * $item->getQty(), 'base');
}
$item->setTaxAmount($tax);
$item->setBaseTaxAmount($baseTax);
$item->setHiddenTaxAmount($hiddenTax);
$item->setBaseHiddenTaxAmount($baseHiddenTax);
$totalTax += $tax;
$baseTotalTax += $baseTax;
$totalHiddenTax += $hiddenTax;
$baseTotalHiddenTax += $baseHiddenTax;
}
}
$invoice = $creditmemo->getInvoice();
if ($invoice) {
//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;
$totalHiddenTax += $invoice->getShippingHiddenTaxAmount() * $taxFactor;
$baseTotalHiddenTax += $invoice->getBaseShippingHiddenTaxAmount() * $taxFactor;
$shippingHiddenTaxAmount = $invoice->getShippingHiddenTaxAmount() * $taxFactor;
$baseShippingHiddenTaxAmount = $invoice->getBaseShippingHiddenTaxAmount() * $taxFactor;
$shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
$totalHiddenTax = $creditmemo->roundPrice($totalHiddenTax);
$baseTotalHiddenTax = $creditmemo->roundPrice($baseTotalHiddenTax, 'base');
$shippingHiddenTaxAmount = $creditmemo->roundPrice($shippingHiddenTaxAmount);
$baseShippingHiddenTaxAmount = $creditmemo->roundPrice($baseShippingHiddenTaxAmount, 'base');
$totalTax += $shippingTaxAmount;
$baseTotalTax += $baseShippingTaxAmount;
}
} else {
$orderShippingAmount = $order->getShippingAmount();
$baseOrderShippingAmount = $order->getBaseShippingAmount();
$orderShippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount();
$baseOrderShippingHiddenTaxAmount = $order->getBaseShippingHiddenTaxAmount();
$baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();
$baseOrderShippingHiddenTaxRefunded = $order->getBaseShippingHiddenTaxRefunded();
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$shippingHiddenTaxAmount = 0;
$baseShippingHiddenTaxAmount = 0;
$shippingDelta = $baseOrderShippingAmount - $baseOrderShippingRefundedAmount;
if ($shippingDelta > $creditmemo->getBaseShippingAmount()) {
$part = $creditmemo->getShippingAmount() / $orderShippingAmount;
$basePart = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
$shippingTaxAmount = $order->getShippingTaxAmount() * $part;
$baseShippingTaxAmount = $order->getBaseShippingTaxAmount() * $basePart;
$shippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount() * $part;
$baseShippingHiddenTaxAmount = $order->getBaseShippingHiddenTaxAmount() * $basePart;
$shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
$shippingHiddenTaxAmount = $creditmemo->roundPrice($shippingHiddenTaxAmount);
$baseShippingHiddenTaxAmount = $creditmemo->roundPrice($baseShippingHiddenTaxAmount, 'base');
} elseif ($shippingDelta == $creditmemo->getBaseShippingAmount()) {
$shippingTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
$baseShippingTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
$shippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount() - $order->getShippingHiddenTaxRefunded();
//.........这里部分代码省略.........
示例8: getInvoiceAppendixRefund
/**
* Returns the refund appendix and substitutes the placeholders, as far as possible
*
* @param Mage_Sales_Model_Order_Creditmemo $creditmemo
* @return string
*/
public function getInvoiceAppendixRefund(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
$order = $this->getOrder();
/** @var $customer Mage_Customer_Model_Customer */
$customer = $this->getFactory()->getModelCustomer();
$customer->load($order->getCustomerId());
/** @var $invoice Mage_Sales_Model_Order_Invoice */
$invoice = $creditmemo->getInvoice();
$substitutionArray = array('{{order_increment_id}}' => $order->getIncrementId(), '{{order_id}}' => $order->getId(), '{{creditmemo_increment_id}}' => $creditmemo->getIncrementId(), '{{invoice_increment_id}}' => $invoice->getIncrementId(), '{{invoice_id}}' => $invoice->getId(), '{{customer_increment_id}}' => $customer->getIncrementId(), '{{customer_id}}' => $order->getCustomerId());
$appendix = $this->getConfigParameterInvoice()->getInvoiceAppendixRefund();
$appendix = str_replace(array_keys($substitutionArray), array_values($substitutionArray), $appendix);
return $appendix;
}
示例9: collect
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$totalTax = 0;
$baseTotalTax = 0;
$totalHiddenTax = 0;
$baseTotalHiddenTax = 0;
$order = $creditmemo->getOrder();
foreach ($creditmemo->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
$orderItem = $item->getOrderItem();
$orderItemTax = $item->getOrderItem()->getTaxAmount();
$baseOrderItemTax = $item->getOrderItem()->getBaseTaxAmount();
$orderItemQty = $item->getOrderItem()->getQtyOrdered();
if ($orderItemTax && $orderItemQty) {
/**
* Check item tax amount
*/
if ($item->isLast()) {
$tax = $orderItemTax - $item->getOrderItem()->getTaxRefunded() - $item->getOrderItem()->getTaxCanceled();
$baseTax = $baseOrderItemTax - $item->getOrderItem()->getTaxRefunded() - $item->getOrderItem()->getTaxCanceled();
$hiddenTax = $orderItem->getHiddenTaxAmount() - $orderItem->getHiddenTaxRefunded() - $item->getOrderItem()->getHiddenTaxCanceled();
$baseHiddenTax = $orderItem->getBaseHiddenTaxAmount() - $orderItem->getBaseHiddenTaxRefunded() - $item->getOrderItem()->getHiddenTaxCanceled();
} else {
$tax = $orderItemTax * $item->getQty() / $orderItemQty;
$baseTax = $baseOrderItemTax * $item->getQty() / $orderItemQty;
$hiddenTax = $orderItem->getHiddenTaxAmount() * $item->getQty() / $orderItemQty;
$baseHiddenTax = $orderItem->getBaseHiddenTaxAmount() * $item->getQty() / $orderItemQty;
$tax = $creditmemo->getStore()->roundPrice($tax);
$baseTax = $creditmemo->getStore()->roundPrice($baseTax);
$hiddenTax = $creditmemo->getStore()->roundPrice($hiddenTax);
$baseHiddenTax = $creditmemo->getStore()->roundPrice($baseHiddenTax);
}
$item->setTaxAmount($tax);
$item->setBaseTaxAmount($baseTax);
$item->setHiddenTaxAmount($hiddenTax);
$item->setBaseHiddenTaxAmount($baseHiddenTax);
$totalTax += $tax;
$baseTotalTax += $baseTax;
$totalHiddenTax += $hiddenTax;
$baseTotalHiddenTax += $baseHiddenTax;
}
}
if ($invoice = $creditmemo->getInvoice()) {
$totalTax += $invoice->getShippingTaxAmount();
$baseTotalTax += $invoice->getBaseShippingTaxAmount();
$totalHiddenTax += $invoice->getShippingHiddenTaxAmount();
$baseTotalHiddenTax += $invoice->getBaseShippingHiddenTaxAmount();
$shippingTaxAmount = $invoice->getShippingTaxAmount();
$baseShippingTaxAmount = $invoice->getBaseShippingTaxAmount();
$shippingHiddenTaxAmount = $invoice->getShippingHiddenTaxAmount();
$baseShippingHiddenTaxAmount = $invoice->getBaseShippingHiddenTaxAmount();
} else {
$orderShippingAmount = $order->getShippingAmount();
$baseOrderShippingAmount = $order->getBaseShippingAmount();
$orderShippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount();
$baseOrderShippingHiddenTaxAmount = $order->getBaseShippingHiddenTaxAmount();
$baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();
$baseOrderShippingHiddenTaxRefunded = $order->getBaseShippingHiddenTaxRefunded();
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$shippingHiddenTaxAmount = 0;
$baseShippingHiddenTaxAmount = 0;
if ($baseOrderShippingAmount - $baseOrderShippingRefundedAmount > $creditmemo->getBaseShippingAmount()) {
$part = $creditmemo->getShippingAmount() / $orderShippingAmount;
$basePart = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
$shippingTaxAmount = $order->getShippingTaxAmount() * $part;
$baseShippingTaxAmount = $order->getBaseShippingTaxAmount() * $basePart;
$shippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount() * $part;
$baseShippingHiddenTaxAmount = $order->getBaseShippingHiddenTaxAmount() * $basePart;
$shippingTaxAmount = $creditmemo->getStore()->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->getStore()->roundPrice($baseShippingTaxAmount);
$shippingHiddenTaxAmount = $creditmemo->getStore()->roundPrice($shippingHiddenTaxAmount);
$baseShippingHiddenTaxAmount = $creditmemo->getStore()->roundPrice($baseShippingHiddenTaxAmount);
} elseif ($baseOrderShippingAmount - $baseOrderShippingRefundedAmount == $creditmemo->getBaseShippingAmount()) {
$shippingTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
$baseShippingTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
$shippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount() - $order->getShippingHiddenTaxRefunded();
$baseShippingHiddenTaxAmount = $order->getBaseShippingHiddenTaxAmount() - $order->getBaseShippingHiddenTaxRefunded();
}
$totalTax += $shippingTaxAmount;
$baseTotalTax += $baseShippingTaxAmount;
$totalHiddenTax += $shippingHiddenTaxAmount;
$baseTotalHiddenTax += $baseShippingHiddenTaxAmount;
}
$allowedTax = $order->getTaxAmount() - $order->getTaxRefunded();
$allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxRefunded();
$allowedHiddenTax = $order->getHiddenTaxAmount() + $order->getShippingHiddenTaxAmount() - $order->getHiddenTaxRefunded() - $order->getShippingHiddenTaxRefunded();
$allowedBaseHiddenTax = $order->getBaseHiddenTaxAmount() + $order->getBaseShippingHiddenTaxAmount() - $order->getBaseHiddenTaxRefunded() - $order->getBaseShippingHiddenTaxRefunded();
$totalTax = min($allowedTax, $totalTax);
$baseTotalTax = min($allowedBaseTax, $baseTotalTax);
$totalHiddenTax = min($allowedHiddenTax, $totalHiddenTax);
$baseTotalHiddenTax = min($allowedBaseHiddenTax, $baseTotalHiddenTax);
$creditmemo->setTaxAmount($totalTax);
$creditmemo->setBaseTaxAmount($baseTotalTax);
$creditmemo->setHiddenTaxAmount($totalHiddenTax);
$creditmemo->setBaseHiddenTaxAmount($baseTotalHiddenTax);
//.........这里部分代码省略.........
示例10: createTaxRequestFromCreditmemo
protected function createTaxRequestFromCreditmemo(Mage_Sales_Model_Order_Creditmemo $creditmemo, $commit = false)
{
$order = $creditmemo->getOrder();
$store = $creditmemo->getStore();
$invoice = $creditmemo->getInvoice();
/** @var Mage_Customer_Model_Customer $customer */
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
$hideDiscountAmount = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $store);
$request = array('Client' => 'Aoe_AvaTax', 'CompanyCode' => $this->limit($this->getHelper()->getConfig('company_code', $store), 25), 'DocType' => $commit ? 'ReturnInvoice' : 'ReturnOrder', 'DocCode' => $this->limit($this->getHelper()->getCreditmemoDocCode($creditmemo), 50), 'ReferenceCode' => $invoice ? $this->getHelper()->getInvoiceDocCode($invoice) : $this->getHelper()->getOrderDocCode($order), 'Commit' => $commit, 'DetailLevel' => 'Tax', 'DocDate' => $creditmemo->getCreatedAtDate()->toString('yyyy-MM-dd'), 'CustomerCode' => $this->getHelper()->getCustomerDocCode($customer) ?: $this->getHelper()->getOrderDocCode($order), 'CurrencyCode' => $this->limit($creditmemo->getBaseCurrencyCode(), 3), 'Discount' => $hideDiscountAmount ? 0.0 : -$store->roundPrice($creditmemo->getBaseDiscountAmount()), 'Addresses' => array(), 'Lines' => array());
if ($order->getCustomerTaxvat()) {
$request['BusinessIdentificationNo'] = $this->limit($order->getCustomerTaxvat(), 25);
}
$request['Addresses'][] = $this->getOriginAddress('ORIGIN', $store);
$request['Addresses'][] = $this->getAddress('DESTINATION', $order->getShippingAddress());
$itemPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $store);
foreach ($this->getHelper()->getActionableCreditmemoItems($creditmemo) as $k => $item) {
/** @var Mage_Sales_Model_Order_Creditmemo_Item $item */
$request['Lines'][] = array("LineNo" => $this->limit($k, 50), "ItemCode" => $this->limit($item->getSku(), 50), "Qty" => round(floatval($item->getQty()), 4), "Amount" => -($store->roundPrice($itemPriceIncludesTax ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal()) - $store->roundPrice($item->getBaseDiscountAmount())), "OriginCode" => "ORIGIN", "DestinationCode" => "DESTINATION", "Description" => $this->limit($item->getDescription(), 255), "TaxCode" => $this->limit($this->getHelper()->getProductTaxCode($item->getOrderItem()->getProduct()), 25), "Discounted" => $item->getBaseDiscountAmount() > 0.0, "TaxIncluded" => $itemPriceIncludesTax, "Ref1" => $this->limit($this->getHelper()->getCreditmemoItemRef1($item, $store), 250), "Ref2" => $this->limit($this->getHelper()->getCreditmemoItemRef2($item, $store), 250));
}
$shippingPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX, $store);
$request['Lines'][] = array("LineNo" => "SHIPPING", "ItemCode" => "SHIPPING", "Qty" => "1", "Amount" => -($store->roundPrice($shippingPriceIncludesTax ? $creditmemo->getBaseShippingInclTax() : $creditmemo->getBaseShippingAmount()) - $store->roundPrice($creditmemo->getBaseShippingDiscountAmount())), "OriginCode" => "ORIGIN", "DestinationCode" => "DESTINATION", "Description" => $this->limit("Shipping: " . $order->getShippingMethod(), 255), "TaxCode" => $this->limit($this->getHelper()->getShippingTaxCode($store), 25), "Discounted" => $creditmemo->getBaseShippingDiscountAmount() > 0.0, "TaxIncluded" => $shippingPriceIncludesTax, "Ref1" => $this->limit($order->getShippingMethod(), 250));
// TODO: Handle giftwrapping
return $request;
}