[0000297] Added balance limit check on payments made from cash type accounts.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 27 Dec 2010 13:09:58 +0000 (13:09 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 27 Dec 2010 13:09:58 +0000 (13:09 +0000)
CHANGELOG.txt
gl/gl_bank.php
gl/includes/db/gl_db_bank_accounts.inc
purchasing/supplier_payment.php

index bc044689e0c42171ecdb8c970c2ded5c4936e4fb..029cd4630818c0fad0c293dabe3a4e6e8f1b29a8 100644 (file)
@@ -19,7 +19,7 @@ Legend:
 ! -> Note
 $ -> Affected files
 
-2-Dec-2010 Janusz Dobrowolski
+27-Dec-2010 Janusz Dobrowolski
 + Option for allowing negative prices for dummy/service items [0000343]
 $ /config.default.php
   /sales/sales_order_entry.php
@@ -27,6 +27,10 @@ $ /config.default.php
 $ /admin/db/transactions_db.inc
 # [0000380] Database error during direct invoice processing in mysql strict mode.
 $ /sales/includes/db/cust_trans_db.inc
+! Added balance limit for payments made from cash accounts
+$ /gl/gl_bank.php
+  /gl/includes/db/gl_db_bank_accounts.inc
+  /purchasing/supplier_payment.php
 
 19-Dec-2010 Janusz Dobrowolski
 # Supressed strict warnings in reporting 
index 5ed202e7c2c43814556ce38e039e3ec051300633..8dd950f1d703722641f2b50ce14ce4e130299603 100644 (file)
@@ -224,6 +224,15 @@ if (isset($_POST['Process']))
                $input_error = 1;
        }
 
+       $limit = get_bank_account_limit($_POST['bank_account'], $_POST['date_']);
+
+       if ($limit != null && ($limit < $_SESSION['pay_items']->gl_items_total()))
+       {
+               display_error(sprintf(_("The total bank amount exceeds allowed limit (%s)."), price_format($limit)));
+               set_focus('code_id');
+               $input_error = 1;
+       }
+
        if (!$Refs->is_valid($_POST['ref']))
        {
                display_error( _("You must enter a reference."));
@@ -247,7 +256,7 @@ if (isset($_POST['Process']))
                display_error(_("The entered date is not in fiscal year."));
                set_focus('date_');
                $input_error = 1;
-       }
+       } 
 
        if (get_post('PayType')==PT_CUSTOMER && (!get_post('person_id') || !get_post('PersonDetailID'))) {
                display_error(_("You have to select customer and customer branch."));
index 7f46f624470bff6580f6cb1913f055693ecfb8f8..3e886763c6029f090381a95c0b44b694d0fa02a4 100644 (file)
@@ -315,4 +315,19 @@ function get_default_bank_account($curr)
 
        return db_fetch($result);
 }
+//---------------------------------------------------------------------------------------------
+//
+//     This function returns current allowed bank payment limit, or null if limit is not set.
+//     As of FA 2.3 check is done only on cash account, for which limit is bank amount as of the date selected.
+//
+function get_bank_account_limit($account, $date, $user=null)
+{
+//     $user = current_user();
+
+       $bankacc = get_bank_account($account);
+       if ($bankacc['account_type'] != BT_CASH)
+               return null;
+       return get_balance_before_for_bank_account($account, $date);
+}
+
 ?>
\ No newline at end of file
index 0d094ba346b5e49d0512ed05b905e1d33be4bf38..5421ee401d426db3ce60862252aa81999c6a94df 100644 (file)
@@ -186,6 +186,16 @@ function check_inputs()
                set_focus('DatePaid');
                return false;
        }
+
+       $limit = get_bank_account_limit($_POST['bank_account'], $_POST['DatePaid']);
+
+       if ($limit != null && ($limit < input_num('amount')))
+       {
+               display_error(sprintf(_("The total bank amount exceeds allowed limit (%s)."), price_format($limit)));
+               set_focus('amount');
+               return false;
+       }
+
     if (!$Refs->is_valid($_POST['ref'])) 
     {
                display_error(_("You must enter a reference."));