supp.tax_group_id, tax_group.name AS tax_group_name,
supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1)
* (ov_amount + ov_gst + ov_discount),0)) as cur_credit
- FROM ".TB_PREF."suppliers supp LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id, ".TB_PREF."payment_terms terms, ".TB_PREF."tax_groups tax_group
+ FROM ".TB_PREF."suppliers supp
+ LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id, "
+ .TB_PREF."payment_terms terms, ".TB_PREF."tax_groups tax_group
WHERE supp.tax_group_id = tax_group.id
AND supp.payment_terms=terms.terms_indicator
AND supp.supplier_id = ".db_escape($supplier_id)." GROUP BY supp.supp_name";
$supp_trans->supplier_name = $trans_row["supp_name"];
$supp_trans->tran_date = sql2date($trans_row["tran_date"]);
$supp_trans->due_date = sql2date($trans_row["due_date"]);
- //$supp_trans->Comments = $trans_row["TransText"];
$supp_trans->Comments = get_comments_string($trans_type, $trans_no);
$supp_trans->reference = $trans_row["reference"];
$supp_trans->supp_reference = $trans_row["supp_reference"];
supplier.curr_code,
(trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount,
trans.alloc AS Allocated,
- ((trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_SUPPCREDIT.") AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue
+ ((trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_SUPPCREDIT.") AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
+ trans.supplier_id
FROM "
.TB_PREF."supp_trans as trans, "
.TB_PREF."suppliers as supplier
function alloc_link($row)
{
- $link =
- pager_link(_("Allocations"),
- "/purchasing/allocations/supplier_allocate.php?trans_no=" .
- $row["trans_no"]. "&trans_type=" . $row["type"], ICON_MONEY );
-
- return (($row["type"] == ST_BANKPAYMENT || $row["type"] == ST_SUPPCREDIT || $row["type"] == ST_SUPPAYMENT)
+ if (($row["type"] == ST_BANKPAYMENT || $row["type"] == ST_SUPPCREDIT || $row["type"] == ST_SUPPAYMENT)
&& (-$row["TotalAmount"] - $row["Allocated"]) > 0)
- ? $link : '';
+ return pager_link(_("Allocations"), "/purchasing/allocations/supplier_allocate.php?trans_no=" .
+ $row["trans_no"]. "&trans_type=" . $row["type"], ICON_MONEY );
+ elseif ($row["type"] == ST_SUPPINVOICE && ($row["TotalAmount"] - $row["Allocated"]) > 0)
+ return pager_link(_("Pay"), "/purchasing/supplier_payment.php?supplier_id=".$row["supplier_id"]
+ ."&PInvoice=".$row["trans_no"], ICON_MONEY );
+ else
+ return '';
}
function fmt_debit($row)
}
if (list_updated('supplier_id') || list_updated('bank_account')) {
+ $_SESSION['alloc']->read();
+ $_POST['memo_'] = $_POST['amount'] = '';
$Ajax->activate('alloc_tbl');
}
//----------------------------------------------------------------------------------------
$_POST['memo_'] = $inv['supp_reference'];
foreach($_SESSION['alloc']->allocs as $line => $trans) {
if ($trans->type == ST_SUPPINVOICE && $trans->type_no == $_GET['PInvoice']) {
- $_POST['amount'] =
+ $_POST['amount'] =
$_SESSION['alloc']->amount = price_format($_SESSION['alloc']->allocs[$line]->amount);
$_SESSION['alloc']->allocs[$line]->current_allocated =
$_SESSION['alloc']->allocs[$line]->amount;
unset($inv);
} else
display_error(_("Invalid purchase invoice number."));
-
}
}
if (isset($_GET['AddedID'])) {
if ($bank_currency == $supplier_currency) {
div_start('alloc_tbl');
- $_SESSION['alloc']->read();
show_allocatable(false);
div_end();
}
check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
//----------------------------------------------------------------------------------------
+if (isset($_GET['customer_id']))
+{
+ $_POST['customer_id'] = $_GET['customer_id'];
+}
+
+if (!isset($_POST['bank_account']))
+{ // first page call
+ $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,0);
+
+ if (isset($_GET['SInvoice'])) {
+ // get date and supplier
+ $inv = get_customer_trans($_GET['SInvoice'], ST_SALESINVOICE);
+ if($inv) {
+ $_POST['customer_id'] = $inv['debtor_no'];
+ $_POST['DateBanked'] = sql2date($inv['tran_date']);
+ foreach($_SESSION['alloc']->allocs as $line => $trans) {
+ if ($trans->type == ST_SALESINVOICE && $trans->type_no == $_GET['SInvoice']) {
+ $_POST['amount'] =
+ $_SESSION['alloc']->amount = price_format($_SESSION['alloc']->allocs[$line]->amount);
+ $_SESSION['alloc']->allocs[$line]->current_allocated =
+ $_SESSION['alloc']->allocs[$line]->amount;
+ break;
+ }
+ }
+ unset($inv);
+ } else
+ display_error(_("Invalid sales invoice number."));
+ }
+}
if (list_updated('BranchID')) {
// when branch is selected via external editor also customer can change
}
}
+
if (isset($_GET['AddedID'])) {
$payment_no = $_GET['AddedID'];
$Ajax->activate('_ex_rate');
}
if (list_updated('customer_id') || list_updated('bank_account')) {
+ $_SESSION['alloc']->read();
+ $_POST['memo_'] = $_POST['amount'] = '';
$Ajax->activate('alloc_tbl');
}
//----------------------------------------------------------------------------------------------
table_section(1);
customer_list_row(_("From Customer:"), 'customer_id', null, false, true);
- if (!isset($_POST['bank_account'])) // first page call
- $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT,0);
if (db_customer_has_branches($_POST['customer_id'])) {
customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'BranchID', null, false, true, true);
if ($cust_currency == $bank_currency) {
div_start('alloc_tbl');
- $_SESSION['alloc']->read();
show_allocatable(false);
div_end();
}
+ trans.ov_freight_tax + trans.ov_discount) AS TotalAmount,
trans.alloc AS Allocated,
((trans.type = ".ST_SALESINVOICE.")
- AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue
+ AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
+ trans.debtor_no
FROM "
.TB_PREF."debtor_trans as trans, "
.TB_PREF."debtors_master as debtor
{
/*its a negative receipt */
return '';
- }
+ } elseif ($row["type"] == ST_SALESINVOICE && ($row['TotalAmount'] - $row['Allocated']) > 0)
+ return pager_link(_("Payment"),
+ "/sales/customer_payments.php?customer_id=".$row["debtor_no"]."&SInvoice=" . $row["trans_no"], ICON_MONEY);
+
}
function fmt_debit($row)
// PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
- if (key_in_foreign_table($selected_id, 'debtor_trans', 'debtor_no', true))
+ if (key_in_foreign_table($selected_id, 'debtor_trans', 'debtor_no'))
{
$cancel_delete = 1;
display_error(_("This customer cannot be deleted because there are transactions that refer to it."));
}
else
{
- if (key_in_foreign_table($selected_id, 'sales_orders', 'debtor_no', true))
+ if (key_in_foreign_table($selected_id, 'sales_orders', 'debtor_no'))
{
$cancel_delete = 1;
display_error(_("Cannot delete the customer record because orders have been created against it."));
}
else
{
- if (key_in_foreign_table($selected_id, 'cust_branch', 'debtor_no', true))
+ if (key_in_foreign_table($selected_id, 'cust_branch', 'debtor_no'))
{
$cancel_delete = 1;
display_error(_("Cannot delete this customer because there are branch records set up against it."));