Changed voiding of Direct Invoice to automatically void 'auto' delivery and set SO...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 26 Apr 2010 15:11:07 +0000 (15:11 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 26 Apr 2010 15:11:07 +0000 (15:11 +0000)
And a few small bug fixes.

CHANGELOG.txt
admin/db/voiding_db.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 4fdd7734314bb37680fb6239824baf15e2db8c82..6976cde68384cd824d283436b91f29d10ca725be 100644 (file)
@@ -19,6 +19,16 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+26-Apr-2010 Joe Hunt
+! Changed voiding of Direct Invoice to automatically void 'auto' delivery
+  and set SO quantity and qty_sent to 0.
+  And a few small bug fixes.  
+$ /admin/db/voiding_db.inc
+  /sales/includes/sales_db.inc
+  /sales/includes/db/sales_credit_db.inc
+  /sales/includes/db/sales_invoice_db.inc
+  /sales/includes/db/sales_delivery_db.inc
+  
 21-Apr-2010 Joe Hunt
 # Bug in systypes selector (no type update)
 $ /admin/attachments.php
index 553240c2b016c1d2220d930529d0dd244b21afe6..55a7308f8565640c387d806af670ba5ea30cea40 100644 (file)
@@ -42,12 +42,12 @@ function void_transaction($type, $type_no, $date_, $memo_)
                case ST_CUSTDELIVERY : // it's a customer dispatch
                        if (!exists_customer_trans($type, $type_no))
                                return false;
-                       if ($type == 13)        // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
+                       if ($type == ST_CUSTDELIVERY)   // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
                        {
                                $delivery = get_customer_trans($type_no, $type);
                                if ($delivery['trans_link'] != 0)
                                {
-                                       if (get_voided_entry(10, $delivery['trans_link']) === false)
+                                       if (get_voided_entry(ST_SALESINVOICE, $delivery['trans_link']) === false)
                                                return false;
                                }
                        }       
index 995a060983d80187fa3f86229d323a5d1d555f15..efb743cd073824bdb48c606149f5d74230ef51e6 100644 (file)
@@ -115,7 +115,7 @@ 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->src_id,($credit_line->qty_dispatched
+                       update_parent_line(ST_CUSTCREDIT, $credit_line->src_id,($credit_line->qty_dispatched
                                        -$credit_line->qty_old));
                }
 
index 334badaa6e4cce2cfd7ee19997d82f485e0f49bb..db34dedabfe9b309bb0cd6d2e4d36837aadab5f8 100644 (file)
@@ -147,9 +147,10 @@ function write_sales_delivery(&$delivery,$bo_policy)
 
 //--------------------------------------------------------------------------------------------------
 
-function void_sales_delivery($type, $type_no)
+function void_sales_delivery($type, $type_no, $transactions=true)
 {
-       begin_transaction();
+       if ($transactions)
+               begin_transaction();
 
        void_gl_trans($type, $type_no, true);
 
@@ -159,10 +160,11 @@ function void_sales_delivery($type, $type_no)
        $order = get_customer_trans_order($type, $type_no);
 
        if ($order) {
+               $auto = (get_reference(ST_SALESORDER, $order) == "auto");
                $order_items = get_sales_order_details($order, ST_SALESORDER);
                while ($row = db_fetch($items_result)) {
                        $order_line = db_fetch($order_items);
-                       update_parent_line(ST_CUSTDELIVERY, $order_line['id'], -$row['quantity']);
+                       update_parent_line(ST_CUSTDELIVERY, $order_line['id'], -$row['quantity'], $auto);
                }
        }
 
@@ -177,6 +179,7 @@ function void_sales_delivery($type, $type_no)
        // DO NOT MOVE THIS ABOVE VOIDING or we can end up with trans with alloc < 0
        void_customer_trans($type, $type_no);
 
-       commit_transaction();
+       if ($transactions)
+               commit_transaction();
 }
 ?>
\ No newline at end of file
index 1629b55f24ac1c99c2e45a962eabe0d3db9ad45e..bd191780dbbaef403f4e1c0f78fee16b7175811f 100644 (file)
@@ -207,11 +207,22 @@ function void_sales_invoice($type, $type_no)
        $deliveries = get_parent_trans($type, $type_no);
 
        if ($deliveries !== 0) {
-               $srcdetails = get_customer_trans_details(get_parent_type($type), $deliveries);
-               while ($row = db_fetch($items_result)) {
-                       $src_line = db_fetch($srcdetails);
-                       update_parent_line($type, $src_line['id'], -$row['quantity']);
-               }
+               if (count($deliveries) == 1 && get_reference(ST_CUSTDELIVERY, $deliveries[0]) == "auto")
+               {
+                       void_sales_delivery(ST_CUSTDELIVERY, $deliveries[0], false);
+                       $date_ = Today();
+                       add_audit_trail(ST_CUSTDELIVERY, $deliveries[0], $date_, _("Voided."));
+                       add_voided_entry(ST_CUSTDELIVERY, $deliveries[0], $date_, "");
+               }       
+               else    
+               {
+                       
+                       $srcdetails = get_customer_trans_details(get_parent_type($type), $deliveries);
+                       while ($row = db_fetch($items_result)) {
+                               $src_line = db_fetch($srcdetails);
+                               update_parent_line($type, $src_line['id'], -$row['quantity']);
+                       }
+               }       
        }
        // clear details after they've been reversed in the sales order
        void_customer_trans_details($type, $type_no);
index e9d7a95ef9b6372f1a4f4ba150ddba87bcf89726..3638ae0f4a0a560fe8292480e726e50fab78932a 100644 (file)
@@ -246,7 +246,7 @@ function get_parent_type($type)
 }
 
 //--------------------------------------------------------------------------------------------------
-function update_parent_line($doc_type, $line_id, $qty_dispatched)
+function update_parent_line($doc_type, $line_id, $qty_dispatched, $auto=false)
 {
        $doc_type = get_parent_type($doc_type);
 
@@ -255,9 +255,13 @@ function update_parent_line($doc_type, $line_id, $qty_dispatched)
                return false;
        else {
                if ($doc_type==ST_SALESORDER)
+               {
                        $sql = "UPDATE ".TB_PREF."sales_order_details
-                               SET qty_sent = qty_sent + $qty_dispatched
-                               WHERE id=".db_escape($line_id);
+                               SET qty_sent = qty_sent + $qty_dispatched";
+                       if ($auto)
+                               $sql .= ", quantity = quantity + $qty_dispatched";
+                       $sql .= " WHERE id=".db_escape($line_id);
+               }               
                else
                        $sql = "UPDATE ".TB_PREF."debtor_trans_details
                                SET qty_done = qty_done + $qty_dispatched