Magento:发票总额的税收计算不正确

时间:2012-01-27 13:46:23

标签: php magento magento-1.5

我正在运行Magento 1.5.1.0并且曾经在发票总额上计算税收问题。虽然我的商店中的所有总计的计算都是正确的,但后端发票视图和pdf发票会显示不正确的总计。

在此图片中可以看到错误,显示值和正确值之间的差异: (简短版本:小计将包含运费税,但运费税已经包含在运费中) http://i731.photobucket.com/albums/ww318/vitamin6/orderview_fixed.jpg

所以我在freelancer.com上发布了这个问题,有人设法解决了这个问题。但是我后来发现,修复并未涵盖所有情况 - 如果订单有免费送货,则发票小计仍然不正确。以下是显示差异的屏幕截图: http://i731.photobucket.com/albums/ww318/vitamin6/orderview_freeship.jpg

自由职业者编辑了以下文件来修正错误的税收计算: 应用\代码\本地\法师\ SALES \模型\订单\发票\总\ Subtotal.php

在那里有以下代码:

    if ($invoice->isLast()) {
        $subtotal = $allowedSubtotal;
        $baseSubtotal = $baseAllowedSubtotal;
        $subtotalInclTax = $allowedSubtotalInclTax;
        $baseSubtotalInclTax  = $baseAllowedSubtotalInclTax;

被替换为这个:

    if ($invoice->isLast()) {
        $subtotal = $allowedSubtotal;
        $baseSubtotal = $baseAllowedSubtotal;
        //$subtotalInclTax = $allowedSubtotalInclTax;
        //$baseSubtotalInclTax  = $baseAllowedSubtotalInclTax;
        $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
        $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);

有人可以指出我正确的方向,我将如何进一步改变文件以使修复工作与免费送货订单? 如果需要,可以提供有关税收设置等的更多详细信息 - 提前谢谢!

2 个答案:

答案 0 :(得分:0)

总计的排序存在一个错误,可能会导致非常奇怪的问题。

你有添加总计的模块吗?

看一下这个:https://stackoverflow.com/a/11954867/288568

答案 1 :(得分:0)

这是很久以前的事了,对我来说这个问题已经解决了一个magento更新(我现在在1.8.1.0)。 我浏览了我的旧文件,我能找到的就是这个编辑:

应用\代码\核心\法师\ SALES \模型\订单\发票\总\ Subtotal.php (摘自1.7.0.2)

<?php /**  * Magento  *  * NOTICE OF LICENSE  *  * This source file is subject to the Open Software License (OSL 3.0)  * that is bundled with this package in the file LICENSE.txt.  * It is also available through the world-wide-web at this URL:  * http://opensource.org/licenses/osl-3.0.php  * If you did not receive a copy of the license and are unable to  * obtain it through the world-wide-web, please send an email  * to license@magentocommerce.com so we can send you a copy immediately.  *  * DISCLAIMER  *  * Do not edit or add to this file if you wish to upgrade Magento to newer  * versions in the future. If you wish to customize Magento for your  * needs please refer to http://www.magentocommerce.com for more information.  *  * @category    Mage  * @package     Mage_Sales  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL
3.0)  */


class Mage_Sales_Model_Order_Invoice_Total_Subtotal extends Mage_Sales_Model_Order_Invoice_Total_Abstract {
    /**
     * 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;
    } }