Two smaller bugs [0000023],[0000026]
[fa-stable.git] / sales / includes / db / sales_invoice_db.inc
index 8270ea6eaf3f92c2d9d7f9cc72f4556fece6dfd5..4bf6ee48bde98b1e2aa3638aa6bc7c75732d0e19 100644 (file)
@@ -163,18 +163,18 @@ function void_sales_invoice($type, $type_no)
        void_bank_trans($type, $type_no, true);
        void_gl_trans($type, $type_no, true);
 
-       // for invoices and credits related to invoices,
-       // reverse all the changes in the sales order
+       // reverse all the changes in parent document(s)
        $items_result = get_customer_trans_details($type, $type_no);
 
-       $delivery = get_customer_trans_link($type, $type_no);
+       $deliveries = get_parent_trans($type, $type_no);
 
-       if ($delivery) {
+       if (count($deliveries)) {
+               $srcdetails = get_customer_trans_details(get_parent_type($type), $deliveries);
                while ($row = db_fetch($items_result)) {
-                       update_parent_line(10, $row['id'], -$row['quantity']);
+                       $src_line = db_fetch($srcdetails);
+                       update_parent_line(10, $src_line['id'], -$row['quantity']);
                }
        }
-
        // clear details after they've been reversed in the sales order
        void_customer_trans_details($type, $type_no);