Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create partial invoice?

From a specific order I want to create an invoice for some selected items from that order.

I have successfully created an invoice for the whole order programmatically, but I want to create a partial invoice of that order.

like image 964
Nikhil_K_R Avatar asked Dec 27 '13 11:12

Nikhil_K_R


People also ask

What is partial invoicing?

What is a partial invoice? A partial invoice is issued when you want to invoice a service that has already been completely performed. For example, if three out of ten production machines have already been delivered for an order, a partial invoice can be issued for the goods already delivered.

How do I create a partial invoice in SAP?

Once you click on Process Open Items → Go to Partial Payment tab and select the invoice for which partial payment is done and the amount. Click the Save button to post the document.

Can you do a partial invoice in Quickbooks?

Select the Sales tab. In the Progress Invoicing section, select Edit ✎. Turn on the switch to Create multiple partial invoices from a single estimate. Select Save and then Done.


2 Answers

Atlast I got it .
Had to dig magento to get this .

$orderid // order id
$order = Mage::getModel('sales/order')->load($orderid);

or for order increment id 
$orderincrmentid // order increment id

$order = Mage::getModel('sales/order')->loadByIncrementId($orderincrmentid);


if($order->canInvoice()) {          
    $invoiceId = Mage::getModel('sales/order_invoice_api')
            ->create($order->getIncrementId(), $itemsarray ,'your_comment' ,1,1);
}
echo $invoiceId; // Gives increment Invoice id

@parameters for above create function :

1st parameter : order increment id

2nd parameter : array

// array format . [Main point]

   foreach($order->getAllItems() as $item) {
$item_id = $item->getItemId(); //order_item_id
$qty = $item->getQtyOrdered();   //qty ordered for that item
}

array('56'=>'3','57'=>'1','58'=>'0');

array([order_item_id] => [qty]); // general array format

So here you will add order item id as key and its qty as its value .
If one do not want to create invoice id a particular item then simply pass value of its quantity as 0 // zero .

3rd parameter : comment

4th parameter : to send mail ----> 1 not send mail ----> 0

5th parameter : include comment in mail ----> 1 not include comment in mail ----> 0

It returns invoice increment id .

Hope it helps someone .

like image 102
Nikhil_K_R Avatar answered Oct 20 '22 01:10

Nikhil_K_R


Try this one...

<?php
$orderID = "145000010"; //order increment id
$orderDetails = Mage::getModel('sales/order')->loadByIncrementId($orderID);

if($orderDetails->canInvoice() and $orderDetails->getIncrementId())
{
    //$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
    $orderItems = $orderDetails->getAllItems();
    $invoiceItems = array();

    foreach ($orderItems as $_eachItem) {
    $opid = $_eachItem->getId();
    $opdtId = $_eachItem->getProductId();
    $itemss = Mage::getModel('catalog/product')->load($opdtId);
    $psku = $itemss->getSku(); // get product attribute which is used your condition
    if($psku=='Test product1'){
        $qty = $_eachItem->getQtyOrdered();
    } else {
        $qty = 0;
    }

    $itemsarray[$opid] = $qty;
    }

    if($orderDetails->canInvoice()) { 
    echo $invoiceId = Mage::getModel('sales/order_invoice_api')
    ->create($orderDetails->getIncrementId(), $itemsarray ,'Partially create Invoice programatically' ,0,0);
    }
}
?>

For more info

like image 34
Hardik Avatar answered Oct 20 '22 00:10

Hardik