0001488: Modifying Sales Invoice (with allocations) causes negative allocations
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 4 Apr 2012 07:25:04 +0000 (09:25 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 4 Apr 2012 07:25:04 +0000 (09:25 +0200)
sales/includes/db/sales_invoice_db.inc

index 558b2159aba0159fd9a1bad9c8e0a000ad275cfd..8ffd22e48f7ce0ec45b4ff87efefcf80c0b1a946 100644 (file)
@@ -59,22 +59,23 @@ function write_sales_invoice(&$invoice)
        if (is_array($sales_order))
                        $sales_order = $sales_order[0]; // assume all crucial SO data are same for every delivery
 
-       $invoice_no = write_customer_trans(ST_SALESINVOICE, $trans_no, $invoice->customer_id,
-               $invoice->Branch, $date_, $invoice->reference, $items_total, 0,
-               $items_added_tax, $invoice->freight_cost, $freight_added_tax,
-               $invoice->sales_type, $sales_order, $invoice->ship_via, 
-               $invoice->due_date, 0, 0, $invoice->dimension_id, 
-               $invoice->dimension2_id, $invoice->payment); 
-               // 2008-06-14 extra $alloc, 2008-11-12 added dimension_id Joe Hunt
+       if ($trans_no != 0) {
+         delete_comments(ST_SALESINVOICE, $trans_no);
+         void_gl_trans(ST_SALESINVOICE, $trans_no, true);
+         void_cust_allocations(ST_SALESINVOICE, $trans_no); // ?
+         void_trans_tax_details(ST_SALESINVOICE, $trans_no);
+    } 
+    $invoice_no = write_customer_trans(ST_SALESINVOICE, $trans_no, $invoice->customer_id,
+       $invoice->Branch, $date_, $invoice->reference, $items_total, 0,
+       $items_added_tax, $invoice->freight_cost, $freight_added_tax,
+       $invoice->sales_type, $sales_order, $invoice->ship_via, 
+       $invoice->due_date, 0, 0, $invoice->dimension_id, 
+       $invoice->dimension2_id, $invoice->payment); 
+       // 2008-06-14 extra $alloc, 2008-11-12 added dimension_id Joe Hunt
 
        if ($trans_no == 0) {
                $invoice->trans_no = array($invoice_no=>0);
-       } else {
-               delete_comments(ST_SALESINVOICE, $invoice_no);
-               void_gl_trans(ST_SALESINVOICE, $invoice_no, true);
-               void_cust_allocations(ST_SALESINVOICE, $invoice_no); // ?
-               void_trans_tax_details(ST_SALESINVOICE, $invoice_no);
-       }
+
        $total = 0;
        foreach ($invoice->line_items as $line_no => $invoice_line) {
                $qty = $invoice_line->qty_dispatched;