From: Joe Hunt Date: Mon, 26 Apr 2010 15:11:07 +0000 (+0000) Subject: Changed voiding of Direct Invoice to automatically void 'auto' delivery and set SO... X-Git-Tag: v2.4.2~19^2~904 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=dc99a4af783003bbabddd59e87db18a8af4476cb;p=fa-stable.git 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. --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4fdd7734..6976cde6 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/admin/db/voiding_db.inc b/admin/db/voiding_db.inc index 553240c2..55a7308f 100644 --- a/admin/db/voiding_db.inc +++ b/admin/db/voiding_db.inc @@ -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; } } diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 995a0609..efb743cd 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -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)); } diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 334badaa..db34deda 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -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 diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 1629b55f..bd191780 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -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); diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index e9d7a95e..3638ae0f 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -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