Added links to payments for invoices in customer/supplier allocation inquiry
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Tue, 20 Sep 2011 08:57:27 +0000 (10:57 +0200)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Tue, 20 Sep 2011 08:57:27 +0000 (10:57 +0200)
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/suppalloc_db.inc
purchasing/inquiry/supplier_allocation_inquiry.php
purchasing/supplier_payment.php
sales/customer_payments.php
sales/includes/db/custalloc_db.inc
sales/inquiry/customer_allocation_inquiry.php
sales/manage/customers.php

index 1482ebcc8804434c1c51fe1a46171e6a46563b0c..17af1e037d6e82761ed6ed7c082a3f6fb246696c 100644 (file)
@@ -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"];
index 4e634d107dcca97ab54853a6eb31cd1b9494451a..535e66c5a0208a3b79a44cc50e0447da8e51c1c3 100644 (file)
@@ -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
index eb7cedc169c5da130b6f71a83dc3a06cc3207640..17bf983bf87247d39273b2a18d651e14f5bcf202 100644 (file)
@@ -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)
index 477c30b41a7a83c526ec0c36d83589f54860d986..ed8f5a089a9c50302c9e7614358e2e68b31fe496 100644 (file)
@@ -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();
        }
index b4551702a4c0ec8e347582e59a27513c73e6c166..2627cdd6349be1dfa568cdc1824728aa4445b56a 100644 (file)
@@ -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();
                }
index c80378c6737ad710dce7ac8ff85ba03d794b7b2c..896649090fedf2658b5dd85ac8b4b4d1a4d4d289 100644 (file)
@@ -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
index f32bd6cbb2c4212b1ef41d81aa7db91bd05fb84f..e7b0ca27c5a5ec1ecf3cc7cd8147c5ce825e75fa 100644 (file)
@@ -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)
index f3ac068af0338206c76e2e19cc3de5a7ca8c941e..36d2f3825dbacccab7eb1492a80a25c1175097ea 100644 (file)
@@ -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."));