本文整理汇总了PHP中Mage_Sales_Model_Order_Invoice::getOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Order_Invoice::getOrder方法的具体用法?PHP Mage_Sales_Model_Order_Invoice::getOrder怎么用?PHP Mage_Sales_Model_Order_Invoice::getOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Order_Invoice
的用法示例。
在下文中一共展示了Mage_Sales_Model_Order_Invoice::getOrder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setPaymentCharge(0);
$invoice->setBasePaymentCharge(0);
/*$hasInvoices = $invoice->getOrder()->hasInvoices();
$paymentMethod = $invoice->getOrder()->getPayment()->getMethod();
if ($paymentMethod) { //&& !$hasInvoices
$chargeType = Mage::getStoreConfig('payment/'.strval($paymentMethod).'/charge_type');
$chargeValue = Mage::getStoreConfig('payment/'.strval($paymentMethod).'/charge_value');
if ($chargeValue) {
if ($chargeType=="percentage") {
$subTotal = $invoice->getSubtotal();
$amount = $subTotal * intval($chargeValue) / 100;
}
else {
$amount = intval($chargeValue);
}
$invoice->setPaymentCharge($amount);
$invoice->setBasePaymentCharge($amount);
}
}
$invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
*/
$amount = $invoice->getOrder()->getPaymentCharge();
$invoice->setPaymentCharge($amount);
$amount = $invoice->getOrder()->getBasePaymentCharge();
$invoice->setBasePaymentCharge($amount);
$invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
return $this;
}
示例2: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
if ($order->getPayment()->getMethodInstance()->getCode() != 'cashondelivery') {
return $this;
}
if (!$order->getCodFee()) {
return $this;
}
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getCodAmount() && !$previusInvoice->isCanceled()) {
$includeCodTax = false;
}
}
$baseCodFee = $order->getBaseCodFee();
$baseCodFeeInvoiced = $order->getBaseCodFeeInvoiced();
$baseInvoiceTotal = $invoice->getBaseGrandTotal();
$codFee = $order->getCodFee();
$codFeeInvoiced = $order->getCodFeeInvoiced();
$invoiceTotal = $invoice->getGrandTotal();
if (!$baseCodFee || $baseCodFeeInvoiced == $baseCodFee) {
return $this;
}
$baseCodFeeToInvoice = $baseCodFee - $baseCodFeeInvoiced;
$codFeeToInvoice = $codFee - $codFeeInvoiced;
$baseInvoiceTotal = $baseInvoiceTotal + $baseCodFeeToInvoice;
$invoiceTotal = $invoiceTotal + $codFeeToInvoice;
$invoice->setBaseGrandTotal($baseInvoiceTotal);
$invoice->setGrandTotal($invoiceTotal);
$invoice->setBaseCodFee($baseCodFeeToInvoice);
$invoice->setCodFee($codFeeToInvoice);
$order->setBaseCodFeeInvoiced($baseCodFeeInvoiced + $baseCodFeeToInvoice);
$order->setCodFeeInvoiced($codFeeInvoiced + $codFeeToInvoice);
return $this;
}
示例3: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
if (!preg_match('/^capayable/', $order->getPayment()->getMethodInstance()->getCode())) {
return $this;
}
if (!$order->getCapayableFee()) {
return $this;
}
foreach ($invoice->getOrder()->getInvoiceCollection() as $prevInvoice) {
if ($prevInvoice->getCapayableFeeAmount() && !$prevInvoice->isCanceled()) {
$includeFeeTax = FALSE;
}
}
$basePaymentFee = $order->getBaseCapayableFee();
$basePaymentFeeInvoiced = $order->getBaseCapayableFeeInvoiced();
$baseInvoiceTotal = $invoice->getBaseGrandTotal();
$paymentFee = $order->getCapayableFee();
$paymentFeeInvoiced = $order->getCapayableFeeInvoiced();
$invoiceTotal = $invoice->getGrandTotal();
if (!$basePaymentFee || $basePaymentFeeInvoiced == $basePaymentFee) {
return $this;
}
$basePaymentFeeToInvoice = $basePaymentFee - $basePaymentFeeInvoiced;
$paymentFeeToInvoice = $paymentFee - $paymentFeeInvoiced;
$baseInvoiceTotal = $baseInvoiceTotal + $basePaymentFeeToInvoice;
$invoiceTotal = $invoiceTotal + $paymentFeeToInvoice;
$invoice->setBaseGrandTotal($baseInvoiceTotal);
$invoice->setGrandTotal($invoiceTotal);
$invoice->setBaseCapayableFee($basePaymentFeeToInvoice);
$invoice->setCapayableFee($paymentFeeToInvoice);
$order->setBaseCapayableFeeInvoiced($basePaymentFeeInvoiced + $basePaymentFeeToInvoice);
$order->setCapayableFeeInvoiced($paymentFeeInvoiced + $paymentFeeToInvoice);
return $this;
}
示例4: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setPaymentCharge(0);
$invoice->setBasePaymentCharge(0);
$paymentCharge = $invoice->getOrder()->getPaymentCharge();
$basePaymentCharge = $invoice->getOrder()->getBasePaymentCharge();
// we moeten de btw meenemen in de berekening
$paymentMethod = $invoice->getOrder()->getPayment()->getMethod();
$taxClass = Mage::helper('pay_payment')->getPaymentChargeTaxClass($paymentMethod);
$storeId = Mage::app()->getStore()->getId();
$taxCalculationModel = Mage::getSingleton('tax/calculation');
$request = $taxCalculationModel->getRateRequest($invoice->getOrder()->getShippingAddress(), $invoice->getOrder()->getBillingAddress(), null, $storeId);
$request->setStore(Mage::app()->getStore());
$rate = $taxCalculationModel->getRate($request->setProductClassId($taxClass));
if ($rate > 0) {
$baseChargeTax = round($invoice->getBasePaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
$chargeTax = round($invoice->getPaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
} else {
$baseChargeTax = 0;
$chargeTax = 0;
}
$invoice->setPaymentCharge($paymentCharge);
$invoice->setBasePaymentCharge($basePaymentCharge);
$invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseChargeTax);
$invoice->setTaxAmount($invoice->getTaxAmount() + $chargeTax);
$invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
return $this;
}
示例5: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setShippingAmount(0);
$invoice->setBaseShippingAmount(0);
$orderShippingAmount = $invoice->getOrder()->getShippingAmount();
$baseOrderShippingAmount = $invoice->getOrder()->getBaseShippingAmount();
$shippingInclTax = $invoice->getOrder()->getShippingInclTax();
$baseShippingInclTax = $invoice->getOrder()->getBaseShippingInclTax();
if ($orderShippingAmount) {
/**
* Check shipping amount in previus invoices
*/
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getShippingAmount() && !$previusInvoice->isCanceled()) {
return $this;
}
}
$invoice->setShippingAmount($orderShippingAmount);
$invoice->setBaseShippingAmount($baseOrderShippingAmount);
$invoice->setShippingInclTax($shippingInclTax);
$invoice->setBaseShippingInclTax($baseShippingInclTax);
$invoice->setGrandTotal($invoice->getGrandTotal() + $orderShippingAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseOrderShippingAmount);
}
return $this;
}
示例6: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$initAmount = $invoice->getOrder()->getSubscriptionInitAmount();
$baseInitAmount = $invoice->getOrder()->getBaseSubscriptionInitAmount();
$invoice->setGrandTotal($invoice->getGrandTotal() + $initAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseInitAmount);
return $this;
}
示例7: collect
public function collect(Mage_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.
*/
$addShippingDicount = true;
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getDiscountAmount()) {
$addShippingDicount = false;
}
}
if ($addShippingDicount) {
$totalDiscountAmount = $totalDiscountAmount + $invoice->getOrder()->getShippingDiscountAmount();
$baseTotalDiscountAmount = $baseTotalDiscountAmount + $invoice->getOrder()->getBaseShippingDiscountAmount();
}
/** @var $item Mage_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
*
* We dont want to include the weee discount amount as the right amount
* is added when calculating the taxes.
*
* Also the subtotal is without weee
*/
$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;
}
示例8: collect
/**
* Collect invoice subtotal
*
* @param Mage_Sales_Model_Order_Invoice $invoice
* @return Mage_Sales_Model_Order_Invoice_Total_Subtotal
*/
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$subtotal = 0;
$baseSubtotal = 0;
$subtotalInclTax = 0;
$baseSubtotalInclTax = 0;
$order = $invoice->getOrder();
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
$item->calcRowTotal();
$subtotal += $item->getRowTotal();
$baseSubtotal += $item->getBaseRowTotal();
$subtotalInclTax += $item->getRowTotalInclTax();
$baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
}
$allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
$baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
$allowedSubtotalInclTax = $allowedSubtotal + $order->getHiddenTaxAmount() + $order->getTaxAmount() - $order->getTaxInvoiced() - $order->getHiddenTaxInvoiced();
$baseAllowedSubtotalInclTax = $baseAllowedSubtotal + $order->getBaseHiddenTaxAmount() + $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $order->getBaseHiddenTaxInvoiced();
/**
* Check if shipping tax calculation is included to current invoice.
*/
$includeShippingTax = true;
foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
$includeShippingTax = false;
break;
}
}
if ($includeShippingTax) {
$allowedSubtotalInclTax -= $order->getShippingTaxAmount();
$baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
} else {
$allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount();
$baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
}
if ($invoice->isLast()) {
$subtotal = $allowedSubtotal;
$baseSubtotal = $baseAllowedSubtotal;
$subtotalInclTax = $allowedSubtotalInclTax;
$baseSubtotalInclTax = $baseAllowedSubtotalInclTax;
} else {
$subtotal = min($allowedSubtotal, $subtotal);
$baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
$subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
$baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
}
$invoice->setSubtotal($subtotal);
$invoice->setBaseSubtotal($baseSubtotal);
$invoice->setSubtotalInclTax($subtotalInclTax);
$invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
$invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
return $this;
}
示例9: collect
public function collect(Mage_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.
*/
$addShippingDicount = true;
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getDiscountAmount()) {
$addShippingDicount = false;
}
}
if ($addShippingDicount) {
$totalDiscountAmount = $totalDiscountAmount + $invoice->getOrder()->getShippingDiscountAmount();
$baseTotalDiscountAmount = $baseTotalDiscountAmount + $invoice->getOrder()->getBaseShippingDiscountAmount();
}
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
$orderItem = $item->getOrderItem();
$orderItemDiscount = (double) $orderItem->getDiscountAmount();
$baseOrderItemDiscount = (double) $orderItem->getBaseDiscountAmount();
$orderItemQty = $orderItem->getQtyOrdered();
if ($orderItemDiscount && $orderItemQty) {
/**
* Resolve rounding problems
*/
if ($item->isLast()) {
$discount = $orderItemDiscount - $orderItem->getDiscountInvoiced();
$baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced();
} else {
$discount = $orderItemDiscount * $item->getQty() / $orderItemQty;
$baseDiscount = $baseOrderItemDiscount * $item->getQty() / $orderItemQty;
$discount = $invoice->getStore()->roundPrice($discount);
$baseDiscount = $invoice->getStore()->roundPrice($baseDiscount);
}
$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;
}
示例10: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setWebposGiftwrapAmount(0);
$orderGiftwrapAmount = $invoice->getOrder()->getWebposGiftwrapAmount();
$baseOrderShippingAmount = $invoice->getOrder()->getWebposGiftwrapAmount();
if ($orderGiftwrapAmount) {
$invoice->setWebposGiftwrapAmount($orderGiftwrapAmount);
$invoice->setGrandTotal($invoice->getGrandTotal() + $orderGiftwrapAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $orderGiftwrapAmount);
}
return $this;
}
示例11: collect
public function collect(Mage_Sales_Model_Order_Invoice $creditmemo)
{
$creditmemo->setOnestepcheckoutGiftwrapAmount(0);
$orderGiftwrapAmount = $creditmemo->getOrder()->getOnestepcheckoutGiftwrapAmount();
$baseOrderShippingAmount = $creditmemo->getOrder()->getOnestepcheckoutGiftwrapAmount();
if ($orderGiftwrapAmount) {
$creditmemo->setOnestepcheckoutGiftwrapAmount($orderGiftwrapAmount);
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $orderGiftwrapAmount);
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $orderGiftwrapAmount);
}
return $this;
}
示例12: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$totalTax = 0;
$baseTotalTax = 0;
foreach ($invoice->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
$orderItemTax = $orderItem->getTaxAmount();
$baseOrderItemTax = $orderItem->getBaseTaxAmount();
$orderItemQty = $orderItem->getQtyOrdered();
if ($orderItemTax && $orderItemQty) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
/**
* Resolve rounding problems
*/
if ($item->isLast()) {
$tax = $orderItemTax - $orderItem->getTaxInvoiced();
$baseTax = $baseOrderItemTax - $orderItem->getBaseTaxInvoiced();
} else {
$tax = $orderItemTax * $item->getQty() / $orderItemQty;
$baseTax = $baseOrderItemTax * $item->getQty() / $orderItemQty;
$tax = $invoice->getStore()->roundPrice($tax);
$baseTax = $invoice->getStore()->roundPrice($baseTax);
}
$item->setTaxAmount($tax);
$item->setBaseTaxAmount($baseTax);
$totalTax += $tax;
$baseTotalTax += $baseTax;
}
}
$includeShippingTax = true;
/**
* Check shipping amount in previus invoices
*/
foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
if ($previusInvoice->getShippingAmount() && !$previusInvoice->isCanceled()) {
$includeShippingTax = false;
}
}
if ($includeShippingTax) {
$totalTax += $invoice->getOrder()->getShippingTaxAmount();
$baseTotalTax += $invoice->getOrder()->getBaseShippingTaxAmount();
$invoice->setShippingTaxAmount($invoice->getOrder()->getShippingTaxAmount());
$invoice->setBaseShippingTaxAmount($invoice->getOrder()->getBaseShippingTaxAmount());
}
$invoice->setTaxAmount($totalTax);
$invoice->setBaseTaxAmount($baseTotalTax);
$invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
return $this;
}
示例13: collect
/**
* Collect shipping amount to be invoiced based on already invoiced amount
*
* @param Mage_Sales_Model_Order_Invoice $invoice
* @return $this
*/
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$previousInvoices = $invoice->getOrder()->getInvoiceCollection();
if ($invoice->getShippingAmount() > 0) {
return $this;
}
$order = $invoice->getOrder();
$shippingAmount = $order->getShippingAmount() - $order->getShippingInvoiced() - $order->getShippingRefunded();
$baseShippingAmount = $order->getBaseShippingAmount() - $order->getBaseShippingInvoiced() - $order->getBaseShippingRefunded();
$invoice->setShippingAmount($shippingAmount);
$invoice->setBaseShippingAmount($baseShippingAmount);
$invoice->setGrandTotal($invoice->getGrandTotal() + $shippingAmount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseShippingAmount);
return $this;
}
示例14: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
$store = $order->getStore();
$invoiceTaxClass = Mage::getHelper('billmateinvoice')->getInvoiceTaxClass($store);
$custTaxClassId = $order->getQuote()->getCustomerTaxClassId();
$address = $order->getBillingAddress();
$taxCalculationModel = Mage::getSingleton('tax/calculation');
/* @var $taxCalculationModel Mage_Tax_Model_Calculation */
$request = $taxCalculationModel->getRateRequest($invoice, $order->getQuote()->getBillingAddress(), $custTaxClassId, $store);
if ($invoiceTaxClass) {
if ($rate = $taxCalculationModel->getRate($request->setProductClassId($invoiceTaxClass))) {
if (!Mage::helper('billmateinvoice')->InvoicePriceIncludesTax()) {
$InvoiceTax = $invoice->getFeeAmount() * $rate / 100;
$InvoiceBaseTax = $invoice->getBaseFeeAmount() * $rate / 100;
} else {
$InvoiceTax = $invoice->getPaymentTaxAmount();
$InvoiceBaseTax = $invoice->getBasePaymentTaxAmount();
}
$InvoiceTax = $store->roundPrice($InvoiceTax);
$InvoiceBaseTax = $store->roundPrice($InvoiceBaseTax);
$invoice->setTaxAmount($invoice->getTaxAmount() + $InvoiceTax);
$invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $InvoiceBaseTax);
$this->_saveAppliedTaxes($invoice, $taxCalculationModel->getAppliedRates($request), $InvoiceTax, $InvoiceBaseTax, $rate);
}
}
if (!Mage::helper('billmateinvoice')->InvoicePriceIncludesTax()) {
$invoice->setInvoiceTaxAmount($InvoiceTax);
$invoice->setBaseInvoiceTaxAmount($InvoiceBaseTax);
}
$invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentTaxAmount());
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentTaxAmount());
return $this;
}
示例15: collect
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$invoice->setData('zitec_dpd_cashondelivery_surcharge', 0);
$invoice->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
$invoice->setData('zitec_dpd_cashondelivery_surcharge_tax', 0);
$invoice->setData('base_zitec_dpd_cashondelivery_surcharge_tax', 0);
$order = $invoice->getOrder();
$amount = $order->getData('zitec_dpd_cashondelivery_surcharge');
if ($amount) {
// We look at the bills to see if it has already claimed the COD surcharge.
foreach ($order->getInvoiceCollection() as $previousInvoice) {
/* @var $previousInvoice Mage_Sales_Model_Order_Invoice */
if (!$previousInvoice->isCanceled() && $previousInvoice->getData('base_zitec_dpd_cashondelivery_surcharge')) {
return $this;
}
}
$invoice->setData('zitec_dpd_cashondelivery_surcharge', $amount);
$baseAmount = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
$invoice->setData('base_zitec_dpd_cashondelivery_surcharge', $baseAmount);
$invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $amount);
// NB. We do not add taxes grand total here.
// Are added Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax.
}
return $this;
}