1 INSERT INTO `0_sys_prefs` VALUES('tax_algorithm','glsetup.customer', 'tinyint', 1, '1');
2 INSERT INTO `0_sys_prefs` VALUES('gl_closing_date','setup.closing_date', 'date', 8, '');
3 ALTER TABLE `0_audit_trail` CHANGE `fiscal_year` `fiscal_year` int(11) NOT NULL default 0;
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`);
12 DROP TABLE IF EXISTS `0_wo_costing`;
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',
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));
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`;
37 ALTER TABLE `0_sales_order_details` ADD KEY `stkcode` (`stk_code`);
38 ALTER TABLE `0_purch_order_details` ADD KEY `itemcode` (`item_code`);
39 ALTER TABLE `0_sys_prefs` CHANGE `value` `value` TEXT NOT NULL DEFAULT '';
40 ALTER TABLE `0_cust_branch` ADD COLUMN `bank_account` varchar(60) DEFAULT NULL AFTER `notes`;
42 ALTER TABLE `0_debtor_trans` ADD COLUMN `tax_included` tinyint(1) unsigned NOT NULL default '0' AFTER `payment_terms`;
43 UPDATE `0_debtor_trans` tr, `0_trans_tax_details` td SET tr.tax_included=td.included_in_price
44 WHERE tr.`type`=td.trans_type AND tr.trans_no=td.trans_no AND td.included_in_price;
46 ALTER TABLE `0_bank_accounts` ADD COLUMN `bank_charge_act` varchar(15) NOT NULL DEFAULT '' AFTER `id`;
47 UPDATE `0_bank_accounts` SET `bank_charge_act`=(SELECT `value` FROM 0_sys_prefs WHERE name='bank_charge_act');
49 ALTER TABLE `0_users` ADD `transaction_days` INT( 6 ) NOT NULL default '30' COMMENT 'Transaction days' AFTER `startup_tab`;
51 ALTER TABLE `0_purch_orders` ADD COLUMN `prep_amount` double NOT NULL DEFAULT 0 AFTER `total`;
52 ALTER TABLE `0_purch_orders` ADD COLUMN `alloc` double NOT NULL DEFAULT 0 AFTER `prep_amount`;
54 ALTER TABLE `0_sales_orders` ADD COLUMN `prep_amount` double NOT NULL DEFAULT 0 AFTER `total`;
55 ALTER TABLE `0_sales_orders` ADD COLUMN `alloc` double NOT NULL DEFAULT 0 AFTER `prep_amount`;
57 ALTER TABLE `0_cust_allocations` ADD UNIQUE KEY(`trans_type_from`,`trans_no_from`,`trans_type_to`,`trans_no_to`);
58 ALTER TABLE `0_supp_allocations` ADD UNIQUE KEY(`trans_type_from`,`trans_no_from`,`trans_type_to`,`trans_no_to`);
60 ALTER TABLE `0_sales_order_details` ADD COLUMN `invoiced` double NOT NULL DEFAULT 0 AFTER `quantity`;
62 # update sales_order_details.invoiced with sum of invoiced quantities on all related SI
63 UPDATE `0_sales_order_details` so
64 LEFT JOIN `0_debtor_trans_details` delivery ON delivery.`debtor_trans_type`=13 AND src_id=so.id
65 LEFT JOIN (SELECT src_id, sum(quantity) as qty FROM `0_debtor_trans_details` WHERE `debtor_trans_type`=10 GROUP BY src_id) inv
66 ON inv.src_id=delivery.id
67 SET `invoiced` = `invoiced`+inv.qty;
69 ALTER TABLE `0_debtor_trans` ADD COLUMN `prep_amount` double NOT NULL DEFAULT 0 AFTER `alloc`;
71 INSERT INTO `0_sys_prefs` VALUES ('deferred_income_act', 'glsetup.sales', 'varchar', '15', '');
73 # set others transactions edition for all roles for backward compatibility
74 UPDATE `0_security_roles` SET `sections`=CONCAT_WS(';', `sections`, '768'), `areas`='775'
75 WHERE NOT `sections` REGEXP '[^0-9]?768[^0-9]?';
77 UPDATE `0_security_roles` SET `areas`=CONCAT_WS(';', `areas`, '775')
78 WHERE NOT `areas` REGEXP '[^0-9]?775[^0-9]?';
80 ALTER TABLE `0_stock_master` ADD COLUMN `no_purchase` tinyint(1) NOT NULL default '0' AFTER `no_sale`;
81 ALTER TABLE `0_stock_category` ADD COLUMN `dflt_no_purchase` tinyint(1) NOT NULL default '0' AFTER `dflt_no_sale`;
83 # added exchange rate field in grn_batch
84 ALTER TABLE `0_grn_batch` ADD COLUMN `rate` double NULL default '1' AFTER `loc_code`;
85 ALTER TABLE `0_users` CHANGE `query_size` `query_size` TINYINT(1) UNSIGNED NOT NULL DEFAULT 10;
87 ALTER TABLE `0_users` ADD `save_report_selections` SMALLINT( 6 ) NOT NULL default '0' COMMENT 'Save Report Selection Days' AFTER `transaction_days`;
88 ALTER TABLE `0_users` ADD `use_date_picker` TINYINT(1) NOT NULL default '1' COMMENT 'Use Date Picker for all Date Values' AFTER `save_report_selections`;
89 ALTER TABLE `0_users` ADD `def_print_destination` TINYINT(1) NOT NULL default '0' COMMENT 'Default Report Destination' AFTER `use_date_picker`;
90 ALTER TABLE `0_users` ADD `def_print_orientation` TINYINT(1) NOT NULL default '0' COMMENT 'Default Report Orientation' AFTER `def_print_destination`;
92 INSERT INTO `0_sys_prefs` VALUES('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1');
93 INSERT INTO `0_sys_prefs` VALUES('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0');
94 INSERT INTO `0_sys_prefs` VALUES('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0');
95 INSERT INTO `0_sys_prefs` VALUES('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0');
96 INSERT INTO `0_sys_prefs` VALUES('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0');
97 INSERT INTO `0_sys_prefs` VALUES('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1');
98 INSERT INTO `0_sys_prefs` VALUES('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0');
99 INSERT INTO `0_sys_prefs` VALUES('default_receival_required', 'glsetup.purchase', 'smallint', 6, '10');
101 # switching all MyISAM tables to InnoDB
102 ALTER TABLE `0_areas` ENGINE=InnoDB;
103 ALTER TABLE `0_attachments` ENGINE=InnoDB;
104 ALTER TABLE `0_bank_accounts` ENGINE=InnoDB;
105 ALTER TABLE `0_bom` ENGINE=InnoDB;
106 ALTER TABLE `0_chart_class` ENGINE=InnoDB;
107 ALTER TABLE `0_chart_master` ENGINE=InnoDB;
108 ALTER TABLE `0_chart_types` ENGINE=InnoDB;
109 ALTER TABLE `0_credit_status` ENGINE=InnoDB;
110 ALTER TABLE `0_currencies` ENGINE=InnoDB;
111 ALTER TABLE `0_cust_branch` ENGINE=InnoDB;
112 ALTER TABLE `0_debtors_master` ENGINE=InnoDB;
113 ALTER TABLE `0_exchange_rates` ENGINE=InnoDB;
114 ALTER TABLE `0_groups` ENGINE=InnoDB;
115 ALTER TABLE `0_item_codes` ENGINE=InnoDB;
116 ALTER TABLE `0_item_units` ENGINE=InnoDB;
117 ALTER TABLE `0_locations` ENGINE=InnoDB;
118 ALTER TABLE `0_movement_types` ENGINE=InnoDB;
119 ALTER TABLE `0_payment_terms` ENGINE=InnoDB;
120 ALTER TABLE `0_prices` ENGINE=InnoDB;
121 ALTER TABLE `0_printers` ENGINE=InnoDB;
122 ALTER TABLE `0_print_profiles` ENGINE=InnoDB;
123 ALTER TABLE `0_purch_data` ENGINE=InnoDB;
124 ALTER TABLE `0_quick_entries` ENGINE=InnoDB;
125 ALTER TABLE `0_quick_entry_lines` ENGINE=InnoDB;
126 ALTER TABLE `0_salesman` ENGINE=InnoDB;
127 ALTER TABLE `0_sales_pos` ENGINE=InnoDB;
128 ALTER TABLE `0_sales_types` ENGINE=InnoDB;
129 ALTER TABLE `0_security_roles` ENGINE=InnoDB;
130 ALTER TABLE `0_shippers` ENGINE=InnoDB;
131 ALTER TABLE `0_sql_trail` ENGINE=InnoDB;
132 ALTER TABLE `0_stock_category` ENGINE=InnoDB;
133 ALTER TABLE `0_suppliers` ENGINE=InnoDB;
134 ALTER TABLE `0_sys_prefs` ENGINE=InnoDB;
135 ALTER TABLE `0_tags` ENGINE=InnoDB;
136 ALTER TABLE `0_tag_associations` ENGINE=InnoDB;
137 ALTER TABLE `0_useronline` ENGINE=InnoDB;
138 ALTER TABLE `0_users` ENGINE=InnoDB;
139 ALTER TABLE `0_workcentres` ENGINE=InnoDB;
141 ALTER TABLE `0_gl_trans` CHANGE `type_no` `type_no` int(11) NOT NULL default '0';
142 ALTER TABLE `0_loc_stock` CHANGE `reorder_level` `reorder_level` double NOT NULL default '0';
144 # added dimensions in supplier documents
145 ALTER TABLE `0_supp_invoice_items` ADD COLUMN `dimension_id` int(11) NOT NULL DEFAULT '0' AFTER `memo_`;
146 ALTER TABLE `0_supp_invoice_items` ADD COLUMN `dimension2_id` int(11) NOT NULL DEFAULT '0' AFTER `dimension_id`;
148 UPDATE `0_supp_invoice_items` si
149 LEFT JOIN `0_gl_trans` gl ON si.supp_trans_type=gl.`type` AND si.supp_trans_no=gl.type_no AND si.gl_code=gl.account
150 SET si.dimension_id=gl.dimension_id, si.dimension2_id=gl.dimension2_id
151 WHERE si.grn_item_id=-1 AND (gl.dimension_id OR gl.dimension2_id);
153 ALTER TABLE `0_quick_entries` ADD COLUMN `usage` varchar(120) NULL AFTER `description`;
154 ALTER TABLE `0_quick_entry_lines` ADD COLUMN `memo` tinytext NOT NULL AFTER `amount`;
156 # multiply allocations to single jiurnal transaction
157 ALTER TABLE `0_cust_allocations` ADD COLUMN `person_id` int(11) DEFAULT NULL AFTER `id`;
158 UPDATE `0_cust_allocations` alloc LEFT JOIN `0_debtor_trans` trans ON alloc.trans_no_to=trans.trans_no AND alloc.trans_type_to=trans.type
159 SET alloc.person_id = trans.debtor_no;
161 ALTER TABLE `0_supp_allocations` ADD COLUMN `person_id` int(11) DEFAULT NULL AFTER `id`;
162 UPDATE `0_supp_allocations` alloc LEFT JOIN `0_supp_trans` trans ON alloc.trans_no_to=trans.trans_no AND alloc.trans_type_to=trans.type
163 SET alloc.person_id = trans.supplier_id;
165 ALTER TABLE `0_cust_allocations` DROP KEY `trans_type_from`;
166 ALTER TABLE `0_cust_allocations` ADD UNIQUE KEY(`person_id`,`trans_type_from`,`trans_no_from`,`trans_type_to`,`trans_no_to`);
167 ALTER TABLE `0_supp_allocations` DROP KEY `trans_type_from`;
168 ALTER TABLE `0_supp_allocations` ADD UNIQUE KEY(`person_id`,`trans_type_from`,`trans_no_from`,`trans_type_to`,`trans_no_to`);
170 # full support for any journal transaction
171 DROP TABLE IF EXISTS `0_journal`;
172 CREATE TABLE `0_journal` (
173 `type` smallint(6) NOT NULL DEFAULT '0',
174 `trans_no` int(11) NOT NULL DEFAULT '0',
175 `tran_date` date DEFAULT '0000-00-00',
176 `reference` varchar(60) NOT NULL DEFAULT '',
177 `source_ref` varchar(60) NOT NULL DEFAULT '',
178 `event_date` date DEFAULT '0000-00-00',
179 `doc_date` date NOT NULL DEFAULT '0000-00-00',
180 `currency` char(3) NOT NULL DEFAULT '',
181 `amount` double NOT NULL DEFAULT '0',
182 `rate` double NOT NULL DEFAULT '1',
183 PRIMARY KEY `Type_and_Number` (`type`,`trans_no`),
184 KEY `tran_date` (`tran_date`)
185 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
187 INSERT INTO `0_journal` (`type`, `trans_no`, `tran_date`, `reference`, `event_date`,`doc_date`,`currency`,`amount`)
188 SELECT `gl`.`type`, `gl`.`type_no`, `gl`.`tran_date`, `ref`.`reference`, `gl`.`tran_date`,
189 `gl`.`tran_date`, `sys_curr`.`value`, SUM(IF(`gl`.`amount`>0,`gl`.`amount`,0))
190 FROM `0_gl_trans` gl LEFT JOIN `0_refs` ref ON gl.type = ref.type AND gl.type_no=ref.id
191 LEFT JOIN `0_sys_prefs` sys_curr ON `sys_curr`.`name`='curr_default'
192 WHERE `gl`.`type` IN(0, 35)
193 GROUP BY `type`,`type_no`;
195 # allow multiply customers.suppliers in single journal transaction
196 ALTER TABLE `0_debtor_trans` DROP PRIMARY KEY;
197 ALTER TABLE `0_debtor_trans` ADD PRIMARY KEY (`type`,`trans_no`, `debtor_no`);
198 ALTER TABLE `0_supp_trans` DROP PRIMARY KEY;
199 ALTER TABLE `0_supp_trans` ADD PRIMARY KEY (`type`,`trans_no`, `supplier_id`);
201 ALTER TABLE `0_trans_tax_details` ADD COLUMN `reg_type` tinyint(1) DEFAULT NULL AFTER `memo`;
203 UPDATE `0_trans_tax_details` reg
205 WHERE reg.trans_type IN(20, 21);
207 UPDATE `0_trans_tax_details` reg
209 WHERE reg.trans_type IN(10, 11);
211 INSERT IGNORE INTO `0_sys_prefs` VALUES
212 ('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0),
213 ('default_receival_required', 'glsetup.purchase', 'smallint', 6, '10'),
214 ('default_quote_valid_days', 'glsetup.sales', 'smallint', 6, 30),
215 ('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1'),
216 ('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0'),
217 ('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0'),
218 ('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0'),
219 ('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0'),
220 ('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1'),
221 ('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0'),
222 ('bcc_email', 'setup.company', 'varchar', 100, ''),
223 ('alternative_tax_include_on_docs', 'setup.company', 'tinyint', 1, '0'),
224 ('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0');
226 # stock_moves.visible field is obsolete
227 # removing obsolete moves for writeoffs
229 FROM `0_stock_moves` moves
230 INNER JOIN (SELECT * FROM `0_stock_moves` WHERE `type`=11 AND `qty`<0) writeoffs ON writeoffs.`trans_no`=moves.`trans_no` AND writeoffs.`type`=11
231 WHERE moves.`type`=11;
233 ALTER TABLE `0_stock_moves` DROP COLUMN `visible`;
234 # stock_moves.discount_percent field are obsolete
236 UPDATE `0_stock_moves` SET
237 price = price*(1-discount_percent);
238 ALTER TABLE `0_stock_moves` DROP COLUMN `discount_percent`;