Bugfix [0000063] Bad update of parent document lines after edition of sales document.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 5 Oct 2008 17:14:14 +0000 (17:14 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 5 Oct 2008 17:14:14 +0000 (17:14 +0000)
sales/includes/cart_class.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_delivery_db.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/sales_db.inc

index 83c9e28f9d25896e9fdf33188dd28fa225f13ab8..78cf46a88f0712d84a72e3c55588980a94ad98a8 100644 (file)
@@ -75,17 +75,17 @@ class cart
        function read($type, $trans_no = 0, $view=false ) {
 
                if (!is_array($trans_no)) $trans_no = array($trans_no);
-
                if ($trans_no[0]) {
                        if ($type == 30) { // sales order
                                read_sales_order($trans_no[0], $this);
                                if ($view) {    // prepare for DN/IV entry
                                        for($line_no = 0; $line_no < count($this->line_items); $line_no++) {
                                                $line = &$this->line_items[$line_no];
+                                               $line->src_id = $line->id; // save src line ids for update
                                                $line->qty_dispatched = $line->quantity - $line->qty_done;
                                        }
                                }
-                               } else {        // derivative transaction
+                       } else {        // derivative transaction
                                        read_sales_trans($type, $trans_no, $this);
                                        if ($this->order_no) { // free hand credit notes have no order_no
                                                $sodata = get_sales_order_header($this->order_no);
@@ -111,12 +111,14 @@ class cart
                                                        $sign = 1; // $type==13 ?  1 : -1; // this is strange debtor_trans atavism
                                                        $line = &$this->line_items[$line_no];
 
+                                                       $line->src_id = $srcline['id']; // save src line ids for update
                                                        $line->qty_old = $line->qty_dispatched = $line->quantity;
                                                        $line->quantity += $sign * ($srcline['quantity'] - $srcline['qty_done']); // add free qty on src doc
                                                }
                                        } else {
                                                for($line_no = 0; $line_no < count($this->line_items); $line_no++) {
                                                        $line = &$this->line_items[$line_no];
+                                                       $line->src_id = $line->id; // save src line ids for update
                                                        $line->qty_dispatched = $line->quantity;
                                                }
                                        }
@@ -403,6 +405,7 @@ class line_details
        var $tax_type;
        var $tax_type_name;
        var $src_no;    // number of src doc for this line
+       var $src_id;
        var $quantity;
        var $price;
        var $discount_percent;
index c49a07f40e34c04b16ec24ef7eaacf29c1997b2c..2f56e9012d03548015ab02a7fffdb17aa5da7351 100644 (file)
@@ -6,8 +6,8 @@
 //
 function write_credit_note($credit_note, $write_off_acc)
 {
-       // Changed 2008-09-26 Joe Hunt -------
-       $credit_invoice = count(array_keys($credit_note->src_docs)) ? reset(array_keys($credit_note->src_docs)) : 0;
+       $credit_invoice =       is_array($credit_note->src_docs) ?
+                reset(array_keys($credit_note->src_docs)) : $credit_note->src_docs;
 
        $credit_date = $credit_note->document_date;
        $tax_group_id = $credit_note->tax_group_id;
@@ -73,11 +73,10 @@ function write_credit_note($credit_note, $write_off_acc)
                void_stock_move(11, $credit_no);
                void_customer_trans_tax_details(11, $credit_no);
        }
-
        if ($credit_invoice) {
                $invoice_alloc_balance = get_DebtorTrans_allocation_balance(10, $credit_invoice);
                update_customer_trans_version(get_parent_type(11), $credit_note->src_docs );
-               if ($invoice_alloc_balance > 0) {       /*the invoice is not already fully allocated */
+               if ($invoice_alloc_balance > 0) {       //the invoice is not already fully allocated 
                        $total = $credit_note_total + $credit_note->freight_cost +
                            $items_added_tax + $freight_added_tax;
 
@@ -98,10 +97,11 @@ function write_credit_note($credit_note, $write_off_acc)
                }
        }
 
+
        foreach ($credit_note->line_items as $credit_line) {
 
                if ($credit_invoice && $credit_line->qty_dispatched!=$credit_line->qty_old ) {
-                       update_parent_line(11, $credit_line->id,($credit_line->qty_dispatched
+                       update_parent_line(11, $credit_line->src_id,($credit_line->qty_dispatched
                                        -$credit_line->qty_old));
                }
 
@@ -151,7 +151,6 @@ function write_credit_note($credit_note, $write_off_acc)
                                "A tax GL posting for this credit note could not be inserted");
                }
        }
-
        add_comments(11, $credit_no, $credit_date, $credit_note->Comments);
 
        if ($trans_no == 0) {
index 6b0cc5e6ad7d32a9c6bd5ae3b6268b7a3e9b3d43..11aa2f665c0cc57525320e3f8b87824c3d3a39b3 100644 (file)
@@ -63,7 +63,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
 
        // Now update sales_order_details for the quantity delivered
                if ($delivery_line->qty_old != $delivery_line->qty_dispatched)
-                       update_parent_line(13, $delivery_line->id,
+                       update_parent_line(13, $delivery_line->src_id,
                                $delivery_line->qty_dispatched-$delivery_line->qty_old);
 
                if ($delivery_line->qty_dispatched != 0) {
index b3dfd743d7ebe5fb82f45fff89deab003b8f0623..c4303fc60561f2b14ae2b3bba9d1217c8a1d859f 100644 (file)
@@ -91,7 +91,7 @@ function write_sales_invoice(&$invoice)
 
                // Update delivery items for the quantity invoiced
                if ($invoice_line->qty_old != $invoice_line->qty_dispatched)
-                       update_parent_line(10, $invoice_line->id, ($invoice_line->qty_dispatched-$invoice_line->qty_old));
+                       update_parent_line(10, $invoice_line->src_id, ($invoice_line->qty_dispatched-$invoice_line->qty_old));
 
                if ($invoice_line->qty_dispatched != 0) {
                        $stock_gl_code = get_stock_gl_code($invoice_line->stock_id);
index ffefcd20ac128216028ef1b8dd691857c7c01cd6..5c4fffdb763b9d907731d531521448f609101c1e 100644 (file)
@@ -125,7 +125,7 @@ function set_document_parent($cart)
        if (count($cart->src_docs) == 1) {
 
        // if this child document has only one parent - update child link
-       $del_no = reset($cart->src_docs);
+       $del_no = reset(array_keys($cart->src_docs));
 
        $sql = 'UPDATE '.TB_PREF.'debtor_trans SET trans_link = ' . $del_no .
                ' WHERE type='.$cart->trans_type.' AND trans_no='. $inv_no ;