From 1fad5af914284430197dbd4a223bc71efed6194b Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Mon, 5 Jan 2009 15:41:38 +0000 Subject: [PATCH] Forgot the immediate allocations. --- CHANGELOG.txt | 2 ++ purchasing/includes/db/invoice_db.inc | 30 ++++++++++++++++++++++++++- purchasing/supplier_credit.php | 5 ++++- purchasing/view/view_supp_credit.php | 3 +-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cdc9969a..39dd30b8 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -23,9 +23,11 @@ $ -> Affected files + Possibility to 'Credit This' in supplier transactions like in customer transaction. If there are many invoice items during a year, there would be many rows suggestions. $ /purchasing/includes/db/grn_db.inc + /purchasing/includes/db/invoice_db.inc /purchasing/includes/ui/invoice_ui.inc /purchasing/supplier_credit.php /purchasing/inquiry/supplier_inquiry.php + /purchasing/view/view_supp_credit.php 22-Dec-2008 Janusz Dobrowolski # Fixed item_code database update on item creation. diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 96fa45ce..49805297 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -107,7 +107,7 @@ function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amoun } //---------------------------------------------------------------------------------------- -function add_supp_invoice($supp_trans) // do not receive as ref because we change locally +function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref because we change locally { //$company_currency = get_company_currency(); /*Start an sql transaction */ @@ -271,6 +271,34 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang references::save_last($supp_trans->reference, $trans_type); + if ($invoice_no != 0) + { + $invoice_alloc_balance = get_supp_trans_allocation_balance(20, $invoice_no); + if ($invoice_alloc_balance > 0) + { //the invoice is not already fully allocated + + $trans = get_supp_trans($invoice_no, 20); + $total = $trans['Total']; + + $allocate_amount = ($invoice_alloc_balance > $total) ? $total : $invoice_alloc_balance; + /*Now insert the allocation record if > 0 */ + if ($allocate_amount != 0) + { + update_supp_trans_allocation(20, $invoice_no, $allocate_amount); + update_supp_trans_allocation(21, $invoice_id, $allocate_amount); // *** + add_supp_allocation($allocate_amount, 21, $invoice_id, 20, $invoice_no, + $date_); + // Exchange Variations Joe Hunt 2008-09-20 //////////////////////////////////////// + + exchange_variation(21, $invoice_id, 20, $invoice_no, $date_, + $allocate_amount, payment_person_types::supplier()); + + /////////////////////////////////////////////////////////////////////////// + } + } + } + + commit_transaction(); return $invoice_id; diff --git a/purchasing/supplier_credit.php b/purchasing/supplier_credit.php index 16c78c9c..e6c83e64 100644 --- a/purchasing/supplier_credit.php +++ b/purchasing/supplier_credit.php @@ -211,7 +211,10 @@ function handle_commit_credit_note() if (!check_data()) return; - $invoice_no = add_supp_invoice($_SESSION['supp_trans']); + if (isset($_POST['invoice_no'])) + $invoice_no = add_supp_invoice($_SESSION['supp_trans'], $_POST['invoice_no']); + else + $invoice_no = add_supp_invoice($_SESSION['supp_trans']); $_SESSION['supp_trans']->clear_items(); unset($_SESSION['supp_trans']); diff --git a/purchasing/view/view_supp_credit.php b/purchasing/view/view_supp_credit.php index 64ed9b8c..64efdbe5 100644 --- a/purchasing/view/view_supp_credit.php +++ b/purchasing/view/view_supp_credit.php @@ -63,8 +63,7 @@ $voided = is_voided_display(21, $trans_no, _("This credit note has been voided." if (!$voided) { - $tax_total = 0; // ?????? - display_allocations_from(payment_person_types::supplier(), $supp_trans->supplier_id, 21, $trans_no, -($supp_trans->ov_amount + $tax_total)); + display_allocations_from(payment_person_types::supplier(), $supp_trans->supplier_id, 21, $trans_no, -($supp_trans->ov_amount + $supp_trans->ov_gst)); } end_page(true); -- 2.30.2