//--------------------------------------------------------------------------------------
-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%");
}
}
+//--------------------------------------------------------------------------------------
+
+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.
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']);
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);
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']);
"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);