按客户分组发票

发布于 2024-12-29 18:14:05 字数 851 浏览 0 评论 0原文

我试图按他们的增值税 ID 对所有客户进行分组,并显示向他们开具了多少税款,所以我的结果应该如下所示,

TAXVAT | Tax Sum
ATU321 | 365.50
ATU123 | 120.00

但我对 magento 的 groupBy 功能很困惑,我尝试了这个:

$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 - 但显然在我的情况下这不是真的:(

I'm trying to group all customers by their tax-vat id and show how much tax was invoiced to them, so my result should look like this

TAXVAT | Tax Sum
ATU321 | 365.50
ATU123 | 120.00

but I'm pretty stuck with the groupBy function of magento, i tried this:

$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');

but i get this error:

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

I thought every eav-based model provides the methods addAttributeToSelect and groupByAttribute - but obviously thats not true in my case :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九厘米的零° 2025-01-05 18:14:05

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 ) { ... }
?>

Magento stopped using EAV for storing sales several versions ago. Also, the customer_taxvat is not stored as part of the invoice, but as part of the order.
You can get the same results this way:

<?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 ) { ... }
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文