0

How can I get invoice collection filter by status paid & payment method ?

I know how to filter order collection by payment method

$orders = Mage::getModel('sales/order')->getCollection();
$orders->getSelect()->join(
    array('payment' =>  $orders->getResource()->getTable('sales/order_payment')),
    'payment.parent_id = main_table.entity_id',
    array('*')
);
$orders->addFieldToFilter('method','ccsave');

But I can't make it work with

Mage::getModel("sales/order_invoice")->getCollection();

where invoice status is also paid

2 Answers 2

2

Try this:

$collection = Mage::getResourceModel('sales/order_invoice_collection');
$collection->addFieldToFilter('state', Mage_Sales_Model_Order_Invoice::STATE_PAID);
$collection->getSelect()->join(array('P' => $collection->getResource()->getTable('sales/order_payment')),"P.parent_id = main_table.order_id",array('method'=>'P.method'));
$collection->addFieldToFilter('method', 'checkmo');
echo '<pre>';
foreach($collection as $invoice) {
    print_r($invoice);
}
1

As stated in Magento User Guide: "Invoice is a record of the receipt of payment for an order" there is no need to apply paid filter to invoice collection. Please refer Magento Guide for further details.

However, if you want to get invoice collection by payment method you can use below code.

$orders = Mage::getModel("sales/order_invoice")->getCollection();
$orders->getSelect()->join(
    array('payment' =>  $orders->getResource()->getTable('sales/order_payment')),
    'payment.parent_id = main_table.order_id',
    array('*')
);
$orders->addFieldToFilter('method','ccsave');  // Set you payment method here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.