INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_estimate_item_unit_type', 'unit', 1);
INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_invoice_item_unit_type', 'unit', 1);
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_estimate_item_unit_type', 'unit', 1 FROM tbltenants;
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_invoice_item_unit_type', 'unit', 1 FROM tbltenants;

INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_estimate_tax_type', 'for_item', 1);
INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_detail_estimate_tax_type', 'for_item', 1);
INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_invoice_tax_type', 'for_item', 1);
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_estimate_tax_type', 'for_item', 1 FROM tbltenants;
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_detail_estimate_tax_type', 'for_item', 1 FROM tbltenants;
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_invoice_tax_type', 'for_item', 1 FROM tbltenants;

INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_estimate_discount_type', 'after_tax', 1);
INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_detail_estimate_discount_type', 'after_tax', 1);
INSERT INTO tbloptions_static(name, value, autoload) VALUES ('default_invoice_discount_type', 'after_tax', 1);
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_estimate_discount_type', 'after_tax', 1 FROM tbltenants;
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_detail_estimate_discount_type', 'after_tax', 1 FROM tbltenants;
INSERT INTO tbloptions(tenant_id, name, value, autoload) SELECT id, 'default_invoice_discount_type', 'after_tax', 1 FROM tbltenants;

UPDATE tblestimates SET discount_type = 'after_tax' WHERE tax_type = 'for_item';
UPDATE tblestimates SET discount_type = 'before_tax' WHERE tax_type = 'global';
UPDATE tblinvoices SET discount_type = 'after_tax' WHERE tax_type = 'for_item';
UPDATE tblinvoices SET discount_type = 'before_tax' WHERE tax_type = 'global';

ALTER TABLE `tblmodule_taxes` CHANGE `taxrate` `taxrate` FLOAT(10,2) NOT NULL;
ALTER TABLE `tblmodule_taxes` CHANGE `amount` `amount` FLOAT(10,2) NOT NULL;

ALTER TABLE `tblestimates` ADD `global_tax_for` ENUM('on_supply','on_labour','on_both') NULL DEFAULT NULL COMMENT 'If tax_type is global than use this flag' AFTER `tax_type`;

ALTER TABLE `tblmodule_taxes` CHANGE `rel_type` `rel_type` ENUM('estimate','invoice','detail_estimate') CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL;