Display payments on view invoice like display allocation on view payments. Chaitanya.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 29 Aug 2011 14:42:26 +0000 (16:42 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 29 Aug 2011 14:42:26 +0000 (16:42 +0200)
includes/ui/ui_view.inc
purchasing/includes/db/suppalloc_db.inc
purchasing/view/view_supp_invoice.php
sales/includes/db/custalloc_db.inc
sales/view/view_invoice.php

index 97b932c819f45e23f2399ed342a25d5c4f73ae92..5b6de2fb7c6010334951272a30886e756ceb4243 100644 (file)
@@ -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.
index 017feeea90ac956f4135716a198b3187437bc26d..4e634d107dcca97ab54853a6eb31cd1b9494451a 100644 (file)
@@ -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']);
index b13ef4160dca923e95bb2d263f7dbf47a8a8f9f5..025e6581ef0631b454e268e92def09729802873d 100644 (file)
@@ -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);
 
index 16f9227e95f7f961ab5cf163e76c54e3cf1d2a6c..c80378c6737ad710dce7ac8ff85ba03d794b7b2c 100644 (file)
@@ -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']);
index 61fc0b56fb88f0974ba980dd1bf2d0f7d67413ac..d6a6cb7aba96ed7b5874430f4309d74b1299fb37 100644 (file)
@@ -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);