Facturas agrupadas por cliente

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();

->addFieldToFilter('customer_taxvat', array('notnull'=>true))
->addFieldToFilter('tax_invoiced', array('notnull'=>true))

pero me sale este 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 :(

preguntado el 30 de enero de 12 a las 19:01

Some versions of Magento have removed addExpressionAttributeToSelect. What version are you using? -

Thank you for this info, i'm using Version of the community edition. -

1 Respuestas

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:

// Set Up Collection
$objOrderCollection = Mage::getResourceModel('sales/order_collection')
  ->addFieldToFilter('customer_taxvat', array('notnull'=>true))
  ->addFieldToFilter('tax_invoiced', array('notnull'=>true));
// Add Group By

// Do your stuff!
foreach ( $objOrderCollection as $order ) { ... }

Respondido el 31 de enero de 12 a las 20:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.