Improved notification in revaluation of currencies and fixed a summation bug.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 10 May 2011 08:09:59 +0000 (10:09 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 10 May 2011 08:09:59 +0000 (10:09 +0200)
gl/includes/db/gl_db_banking.inc
gl/manage/revaluate_currencies.php

index e4343a3b9f1eccecd8f5a81a5ce387715c73baa2..6c4395d582abc8e813d813f056e19a0369d86d30 100644 (file)
@@ -91,12 +91,8 @@ function get_cust_account_home_balance($debtor_no, $rec_account, $to_date)
        $to = date2sql($to_date);
 
     $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans t  
-       LEFT JOIN ".TB_PREF."debtors_master d ON t.person_id = d.debtor_no
-       LEFT JOIN ".TB_PREF."debtor_trans dt ON (t.type=dt.type AND t.type_no=dt.trans_no) 
-       LEFT JOIN ".TB_PREF."cust_branch br ON dt.branch_code = br.branch_code
-                       WHERE br.debtor_no=".db_escape($debtor_no)." AND t.account=br.receivables_account AND t.account='$rec_account' 
-                       AND person_id=br.debtor_no AND person_type_id=".PT_CUSTOMER." 
-                       AND t.tran_date <= '$to'";
+                       WHERE t.person_id=".db_escape($debtor_no)." AND t.account='$rec_account' 
+                       AND person_type_id=".PT_CUSTOMER." AND t.tran_date <= '$to'";
        $result = db_query($sql, "The AR balance for customer $debtor_no could not be calculated");
        $row = db_fetch_row($result);
        return $row[0];
@@ -159,8 +155,9 @@ function add_exchange_variation_all($date=null, $ref="", $memo)
        //------------- BEGIN inserted for revaluation of customer/supplier currencies 2011-05-08 Joe Hunt.
        if ($date == null)
                $date = Today();
-       // debtors
        $exchange_act = get_company_pref('exchange_diff_act');
+       $je = 0;
+       // debtors
        $res = get_cust_account_curr_balances($date);
        
        while($row = db_fetch($res)) 
@@ -173,6 +170,7 @@ function add_exchange_variation_all($date=null, $ref="", $memo)
                        $amount = $foreign - $home;     
                        add_cust_supp_revaluation($row['receivables_account'], $exchange_act, $date, $amount, PT_CUSTOMER, 
                                $row['debtor_no'], $memo);
+                       $je++;  
                }
        }
        // creditors
@@ -188,12 +186,13 @@ function add_exchange_variation_all($date=null, $ref="", $memo)
                        $amount = $foreign - $home;     
                        add_cust_supp_revaluation($row['payable_account'], $exchange_act, $date, $amount, PT_SUPPLIER, 
                                $row['supplier_id'], $memo);
+                       $je++;  
                }
        }
        //------------- END
        
        commit_transaction();
-       return ($exchanged ? $trans_no : 0);
+       return array(($exchanged ? $trans_no : 0), $je);
 }
 //----------------------------------------------------------------------------------
 //     Add bank tranfer to database.
index 78c5cbbbf8a65653adc0625dc718a94b960969c9..a35c4a91e177a99db8964bdedb32085354d01509 100644 (file)
@@ -25,6 +25,7 @@ page(_($help_context = "Revaluation of Currency Accounts"), false, false, "", $j
 if (isset($_GET['AddedID'])) 
 {
        $trans_no = $_GET['AddedID'];
+       $JE = $_GET['JE'];
        $trans_type = ST_JOURNAL;
 
        if ($trans_no == 0)
@@ -35,6 +36,8 @@ if (isset($_GET['AddedID']))
 
                display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Journal Entries for this Transfer")));
        }
+       if ($JE > 0)
+               display_notification_centered(sprintf(_("%d Journal Entries for AR/AP accounts have been added"), $JE));
 
        //display_footer_exit();
 }
@@ -81,9 +84,9 @@ function handle_submit()
        if (!check_data())
                return;
 
-       $trans_no = add_exchange_variation_all($_POST['date'], $_POST['ref'], $_POST['memo_']);
+       $trans = add_exchange_variation_all($_POST['date'], $_POST['ref'], $_POST['memo_']);
 
-       meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
+       meta_forward($_SERVER['PHP_SELF'], "AddedID=".$trans[0]."&JE=".$trans[1]);
        //clear_data();
 }