9b254e83c04add2c19929daa578193829dec3154
[fa-stable.git] / admin / db / v_banktrans.inc
1 <?php
2
3 include_once($path_to_root . "/gl/includes/gl_db.inc");
4
5 function validate_bank_trans()
6 {
7         dump_msg("<b>Checking bank transactions.........</b>");
8
9         // check that the account in the trans is actually a P/L account
10         $sql = "SELECT * FROM ".TB_PREF."bank_trans,".TB_PREF."chart_master, ".TB_PREF."chart_types
11                 WHERE ".TB_PREF."bank_trans.bank_act=".TB_PREF."chart_master.account_code
12                 AND  ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
13                 AND (".TB_PREF."chart_types.class_id = 1 OR ".TB_PREF."chart_types.class_id = 2)";
14
15         $result = db_query($sql);
16         if (db_num_rows($result) > 0) 
17         {
18                 dump_msg("There are bank transactions with accounts that are not Profit&Loss");
19         }
20
21         $sql = "SELECT * FROM ".TB_PREF."bank_trans";
22         $result = db_query($sql);
23         while ($banktrans = db_fetch($result)) 
24         {
25                 // make sure bank_act is valid
26                 $get = get_gl_account($banktrans["bank_act"]);
27                 if ($get == null)
28                         dump_msg("Invalid Bank Account for bank trans " . $banktrans["id"]);
29
30                 // make sure the type is valid
31                 $get = get_bank_trans_type($banktrans["bank_trans_type_id"]);
32                 if ($get == null)
33                         dump_msg("Invalid bank_trans_type_id (" . $banktrans["bank_trans_type_id"] . ") for bank_trans " . $banktrans["id"]);
34
35                 if ($banktrans["type"] != 1 && $banktrans["type"] != 2 && $banktrans["type"] != 4
36                         && $banktrans["type"] != 22 && $banktrans["type"] != 12)
37                         dump_msg("Invalid type for bank_trans " . $banktrans["id"]);
38         }
39 }
40
41
42 ?>