按客户分组发票



我正试图根据所有客户的增值税id对他们进行分组,并显示向他们开具的发票金额,所以我的结果应该是这样的

TAXVAT | Tax Sum
ATU321 | 365.50
ATU123 | 120.00

但我对groupBy函数magento很着迷,我试过这个:

$objInvoiceCollection = Mage::getModel('sales/order/invoice')->getCollection();
$objInvoiceCollection 
->addAttributeToSelect('customer_taxvat');
->addExpressionAttributeToSelect('tax_invoiced','SUM({{tax_invoiced}})','tax')
->addFieldToFilter('customer_taxvat', array('notnull'=>true))
->addFieldToFilter('tax_invoiced', array('notnull'=>true))
->groupByAttribute('customer_taxvat');

但是我得到了这个错误:

Call to undefined method Mage_Sales_Model_Resource_Order_Collection::addExpressionAttributeToSelect() ...

我认为每个基于eav的模型都提供addAttributeToSelect和groupByAttribute方法,但在我的情况下显然不是这样:(

Magento在几个版本前就停止使用EAV来存储销售。此外,customer_taxvat不是作为发票的一部分存储的,而是作为订单的一部分。你可以通过这种方式获得相同的结果:

<?php
// Set Up Collection
$objOrderCollection = Mage::getResourceModel('sales/order_collection')
  ->addFieldToSelect('customer_taxvat')
  ->addExpressionFieldToSelect('tax_invoiced','SUM(tax_invoiced)','tax')
  ->addFieldToFilter('customer_taxvat', array('notnull'=>true))
  ->addFieldToFilter('tax_invoiced', array('notnull'=>true));
// Add Group By
$objOrderCollection->getSelect()->group('customer_taxvat');
// Do your stuff!
foreach ( $objOrderCollection as $order ) { ... }
?>

相关内容

  • 没有找到相关文章

最新更新