d944173746f9c8100c03c49e3a4559c91b95534c
[fa-stable.git] / sql / alter2.4.sql
1 ALTER TABLE `0_suppliers` ADD COLUMN  `tax_algorithm` tinyint(1) NOT NULL default '1' AFTER `tax_included`;
2 ALTER TABLE `0_supp_trans` ADD COLUMN `tax_algorithm` tinyint(1) NULL default '1' AFTER `tax_included`;
3 INSERT INTO `0_sys_prefs` VALUES('tax_algorithm','glsetup.customer', 'tinyint', 1, '1');
4 INSERT INTO `0_sys_prefs` VALUES('gl_closing_date','setup.closing_date', 'date', 8, '');
5 # Fix eventual invalid date/year in audit records
6 UPDATE `0_audit_trail` audit 
7                 LEFT JOIN `0_gl_trans` gl ON  gl.`type`=audit.`type` AND gl.type_no=audit.trans_no
8                 LEFT JOIN `0_fiscal_year` year ON year.begin<=gl.tran_date AND year.end>=gl.tran_date
9                 SET audit.gl_date=gl.tran_date, audit.fiscal_year=year.id
10                 WHERE NOT ISNULL(gl.`type`);
11
12 DROP TABLE IF EXISTS `0_wo_costing`;
13
14 CREATE TABLE `0_wo_costing` (
15   `id` int(11) NOT NULL auto_increment,
16   `workorder_id` int(11) NOT NULL default '0',
17   `cost_type`   tinyint(1) NOT NULL default '0',
18   `trans_type` int(11) NOT NULL default '0',
19   `trans_no` int(11) NOT NULL default '0',
20   `factor` double NOT NULL default '1',
21   PRIMARY KEY  (`id`)
22 ) TYPE=InnoDB;
23
24 UPDATE `0_gl_trans` gl
25                 LEFT JOIN `0_cust_branch` br ON br.receivables_account=gl.account AND br.debtor_no=gl.person_id AND gl.person_type_id=2
26                 LEFT JOIN `0_suppliers` sup ON sup.payable_account=gl.account AND sup.supplier_id=gl.person_id AND gl.person_type_id=3
27  SET `person_id` = IF(br.receivables_account, br.debtor_no, IF(sup.payable_account, sup.supplier_id, NULL)), 
28         `person_type_id` = IF(br.receivables_account, 2, IF(sup.payable_account, 3, NULL));
29
30 ALTER TABLE `0_tax_group_items` ADD COLUMN `tax_shipping` tinyint(1) NOT NULL default '0' AFTER `rate`;
31 UPDATE `0_tax_group_items` tgi
32         SET tgi.tax_shipping=1
33         WHERE tgi.rate=(SELECT 0_tax_types.rate FROM 0_tax_types, 0_tax_groups 
34                 WHERE tax_shipping=1 AND tgi.tax_group_id=0_tax_groups.id AND tgi.tax_type_id=0_tax_types.id);
35 ALTER TABLE `0_tax_groups` DROP COLUMN `tax_shipping`;