From: Janusz Dobrowolski Date: Tue, 20 Sep 2011 08:57:27 +0000 (+0200) Subject: Added links to payments for invoices in customer/supplier allocation inquiry X-Git-Tag: 2.3-final~569 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=2bbf52478cf6cbf4fb89395f18390f1a6af93f40;p=fa-stable.git Added links to payments for invoices in customer/supplier allocation inquiry --- diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 1482ebcc..17af1e03 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -20,7 +20,9 @@ function read_supplier_details_to_trans(&$supp_trans, $supplier_id) 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"; @@ -456,7 +458,6 @@ function read_supp_invoice($trans_no, $trans_type, &$supp_trans) $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"]; diff --git a/purchasing/includes/db/suppalloc_db.inc b/purchasing/includes/db/suppalloc_db.inc index 4e634d10..535e66c5 100644 --- a/purchasing/includes/db/suppalloc_db.inc +++ b/purchasing/includes/db/suppalloc_db.inc @@ -211,7 +211,8 @@ function get_sql_for_supplier_allocation_inquiry() 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 diff --git a/purchasing/inquiry/supplier_allocation_inquiry.php b/purchasing/inquiry/supplier_allocation_inquiry.php index eb7cedc1..17bf983b 100644 --- a/purchasing/inquiry/supplier_allocation_inquiry.php +++ b/purchasing/inquiry/supplier_allocation_inquiry.php @@ -95,14 +95,15 @@ function fmt_balance($row) 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) diff --git a/purchasing/supplier_payment.php b/purchasing/supplier_payment.php index 477c30b4..ed8f5a08 100644 --- a/purchasing/supplier_payment.php +++ b/purchasing/supplier_payment.php @@ -58,6 +58,8 @@ if (isset($_POST['_DatePaid_changed'])) { } if (list_updated('supplier_id') || list_updated('bank_account')) { + $_SESSION['alloc']->read(); + $_POST['memo_'] = $_POST['amount'] = ''; $Ajax->activate('alloc_tbl'); } //---------------------------------------------------------------------------------------- @@ -76,7 +78,7 @@ if (!isset($_POST['bank_account'])) { // first page call $_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; @@ -86,7 +88,6 @@ if (!isset($_POST['bank_account'])) { // first page call unset($inv); } else display_error(_("Invalid purchase invoice number.")); - } } if (isset($_GET['AddedID'])) { @@ -302,7 +303,6 @@ start_form(); if ($bank_currency == $supplier_currency) { div_start('alloc_tbl'); - $_SESSION['alloc']->read(); show_allocatable(false); div_end(); } diff --git a/sales/customer_payments.php b/sales/customer_payments.php index b4551702..2627cdd6 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -39,6 +39,35 @@ check_db_has_customers(_("There are no customers defined in the system.")); 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 @@ -56,6 +85,7 @@ if (!isset($_POST['DateBanked'])) { } } + if (isset($_GET['AddedID'])) { $payment_no = $_GET['AddedID']; @@ -184,6 +214,8 @@ if (isset($_POST['_DateBanked_changed'])) { $Ajax->activate('_ex_rate'); } if (list_updated('customer_id') || list_updated('bank_account')) { + $_SESSION['alloc']->read(); + $_POST['memo_'] = $_POST['amount'] = ''; $Ajax->activate('alloc_tbl'); } //---------------------------------------------------------------------------------------------- @@ -231,8 +263,6 @@ start_form(); 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); @@ -277,7 +307,6 @@ start_form(); if ($cust_currency == $bank_currency) { div_start('alloc_tbl'); - $_SESSION['alloc']->read(); show_allocatable(false); div_end(); } diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index c80378c6..89664909 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -202,7 +202,8 @@ function get_sql_for_customer_allocation_inquiry() + 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 diff --git a/sales/inquiry/customer_allocation_inquiry.php b/sales/inquiry/customer_allocation_inquiry.php index f32bd6cb..e7b0ca27 100644 --- a/sales/inquiry/customer_allocation_inquiry.php +++ b/sales/inquiry/customer_allocation_inquiry.php @@ -112,7 +112,10 @@ function alloc_link($row) { /*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) diff --git a/sales/manage/customers.php b/sales/manage/customers.php index f3ac068a..36d2f382 100644 --- a/sales/manage/customers.php +++ b/sales/manage/customers.php @@ -121,21 +121,21 @@ if (isset($_POST['delete'])) // 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."));