2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
11 ***********************************************************************/
13 var $version = '2.1'; // version installed
14 var $description = 'Version 2.1';
15 var $sql = 'alter2.1.sql';
17 // Install procedure. All additional changes
18 // not included in sql file should go here.
20 function install($pref, $force)
24 Statement below is allowed only for MySQL >=4.0.4:
25 UPDATE `0_bank_trans`, `0_bank_accounts`
26 SET 0_bank_trans.bank_act=0_bank_accounts.id
27 WHERE 0_bank_trans.bank_act=0_bank_accounts.account_code;
29 $sql = "SELECT id, account_code FROM ".$pref."bank_accounts";
30 if(!($res = db_query($sql))) {
31 display_error(_("Cannot retrieve bank accounts codes")
32 .':<br>'. db_error_msg($db));
35 while ($acc = db_fetch($res)) {
36 $sql = "UPDATE ".$pref."bank_trans SET bank_act='"
37 .$acc['id']."' WHERE bank_act=".$acc['account_code'];
38 if (db_query($sql)==false) {
39 display_error(_("Cannot update bank transactions")
40 .':<br>'. db_error_msg($db));
44 // copy all item codes from stock_master into item_codes
45 $sql = "SELECT `stock_id`,`description`,`category_id` FROM ".$pref."stock_master";
46 $result = db_query($sql);
48 display_error(_("Cannot select stock identificators")
49 .':<br>'. db_error_msg($db));
52 while ($row = db_fetch_assoc($result)) {
53 $sql = "INSERT IGNORE "
54 .$pref."item_codes (`item_code`,`stock_id`,`description`,`category_id`)
55 VALUES('".$row['stock_id']."','".$row['stock_id']."','"
56 .$row['description']."','".$row['category_id']."')";
57 $res2 = db_query($sql);
59 display_error(_("Cannot insert stock id into item_codes")
60 .':<br>'. db_error_msg($db));
65 // remove obsolete bank_trans_types table
66 // (DROP queries are skipped during non-forced upgrade)
67 $sql = "DROP TABLE IF EXISTS `0_bank_trans_types`";
73 // Checking before install
75 function pre_check($pref)
77 return true; // true when ok, fail otherwise
80 // Test if patch was applied before.
82 function installed($pref) {
83 if (check_table($pref, 'item_codes')) return false;
84 if (check_table($pref, 'company', 'foreign_codes')) return false;
85 if (check_table($pref, 'supplier', 'credit_limit') return false;