From 4528afda32783ab1b4e5e88fe19e2136a3f060e1 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Mon, 29 Aug 2011 16:42:26 +0200 Subject: [PATCH] Display payments on view invoice like display allocation on view payments. Chaitanya. --- includes/ui/ui_view.inc | 21 ++++++++++++++++++-- purchasing/includes/db/suppalloc_db.inc | 23 ++++++++++++++++++++++ purchasing/view/view_supp_invoice.php | 8 +++++++- sales/includes/db/custalloc_db.inc | 26 +++++++++++++++++++++++++ sales/view/view_invoice.php | 7 ++++++- 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 97b932c8..5b6de2fb 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -474,14 +474,14 @@ function display_footer_exit() //-------------------------------------------------------------------------------------- -function display_allocations($alloc_result, $total) +function display_allocations($alloc_result, $total, $payments=false) { global $systypes_array; if (!$alloc_result || db_num_rows($alloc_result) == 0) return; - display_heading2(_("Allocations")); + display_heading2(($payments ? _("Payments") : _("Allocations"))); start_table(TABLESTYLE, "width=80%"); @@ -538,6 +538,23 @@ function display_allocations_from($person_type, $person_id, $type, $type_no, $to } } +//-------------------------------------------------------------------------------------- + +function display_allocations_to($person_type, $person_id, $type, $type_no, $total) +{ + switch ($person_type) + { + case PT_CUSTOMER : + $alloc_result = get_allocatable_from_cust_transactions($person_id, $type_no, $type); + display_allocations($alloc_result, $total, true); + return; + case PT_SUPPLIER : + $alloc_result = get_allocatable_from_supp_transactions($person_id, $type_no, $type); + display_allocations($alloc_result, $total, true); + return; + } +} + //-------------------------------------------------------------------------------------- // // Expands selected quick entry $id into GL posings and adds to cart. diff --git a/purchasing/includes/db/suppalloc_db.inc b/purchasing/includes/db/suppalloc_db.inc index 017feeea..4e634d10 100644 --- a/purchasing/includes/db/suppalloc_db.inc +++ b/purchasing/includes/db/suppalloc_db.inc @@ -172,6 +172,29 @@ function get_allocatable_to_supp_transactions($supplier_id, $trans_no=null, $typ return db_query($sql." ORDER BY due_date", "Cannot retreive alloc to transactions"); } +//------------------------------------------------------------------------------------------------------------- + +function get_allocatable_from_supp_transactions($supplier_id, $trans_no=null, $type=null) +{ + if ($trans_no != null && $type!= null) + { + $sql = get_alloc_supp_sql("amt, supp_reference", "trans.trans_no = alloc.trans_no_from + AND trans.type = alloc.trans_type_from + AND alloc.trans_no_to=".db_escape($trans_no)." + AND alloc.trans_type_to=".db_escape($type)." + AND trans.supplier_id=".db_escape($supplier_id), + TB_PREF."supp_allocations as alloc"); + } + else + { + $sql = get_alloc_supp_sql(null, "round(ABS(ov_amount+ov_gst+ov_discount)-alloc,6) > 0 + AND trans.type != ".ST_SUPPAYMENT." + AND trans.supplier_id=".db_escape($supplier_id)); + } + + return db_query($sql." ORDER BY due_date", "Cannot retreive alloc to transactions"); +} + function get_sql_for_supplier_allocation_inquiry() { $date_after = date2sql($_POST['TransAfterDate']); diff --git a/purchasing/view/view_supp_invoice.php b/purchasing/view/view_supp_invoice.php index b13ef416..025e6581 100644 --- a/purchasing/view/view_supp_invoice.php +++ b/purchasing/view/view_supp_invoice.php @@ -73,7 +73,13 @@ label_row(_("TOTAL INVOICE"), $display_total, "colspan=1 align=right", "nowrap a end_table(1); -is_voided_display(ST_SUPPINVOICE, $trans_no, _("This invoice has been voided.")); +$voided = is_voided_display(ST_SUPPINVOICE, $trans_no, _("This invoice has been voided.")); + +if (!$voided) +{ + display_allocations_to(PT_SUPPLIER, $supp_trans->supplier_id, ST_SUPPINVOICE, $trans_no, + ($supp_trans->ov_amount + $supp_trans->ov_gst)); +} end_page(true, false, false, ST_SUPPINVOICE, $trans_no); diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index 16f9227e..c80378c6 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -158,6 +158,32 @@ function get_allocatable_to_cust_transactions($customer_id, $trans_no=null, $typ return db_query($sql." ORDER BY trans_no", "Cannot retreive alloc to transactions"); } +//------------------------------------------------------------------------------------------------------------- + +function get_allocatable_from_cust_transactions($customer_id, $trans_no=null, $type=null) +{ + if ($trans_no != null and $type != null) + { + $sql = get_alloc_trans_sql("amt", "trans.trans_no = alloc.trans_no_from + AND trans.type = alloc.trans_type_from + AND alloc.trans_no_to=".db_escape($trans_no)." + AND alloc.trans_type_to=".db_escape($type)." + AND trans.debtor_no=".db_escape($customer_id), + "".TB_PREF."cust_allocations as alloc"); + } + else + { + $sql = get_alloc_trans_sql(null, "round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) > 0 + AND trans.type <> " . ST_CUSTPAYMENT . " + AND trans.type <> " . ST_BANKDEPOSIT . " + AND trans.type <> " . ST_CUSTCREDIT . " + AND trans.type <> " . ST_CUSTDELIVERY . " + AND trans.debtor_no=".db_escape($customer_id)); + } + + return db_query($sql." ORDER BY trans_no", "Cannot retreive alloc to transactions"); +} + function get_sql_for_customer_allocation_inquiry() { $data_after = date2sql($_POST['TransAfterDate']); diff --git a/sales/view/view_invoice.php b/sales/view/view_invoice.php index 61fc0b56..d6a6cb7a 100644 --- a/sales/view/view_invoice.php +++ b/sales/view/view_invoice.php @@ -165,7 +165,12 @@ label_row(_("TOTAL INVOICE"), $display_total, "colspan=6 align=right", "nowrap align=right"); end_table(1); -is_voided_display(ST_SALESINVOICE, $trans_id, _("This invoice has been voided.")); +$voided = is_voided_display(ST_SALESINVOICE, $trans_id, _("This invoice has been voided.")); + +if (!$voided) +{ + display_allocations_to(PT_CUSTOMER, $myrow['debtor_no'], ST_SALESINVOICE, $trans_id, $myrow['Total']); +} end_page(true, false, false, ST_SALESINVOICE, $trans_id); -- 2.30.2