MT#7843 copy vat data from billing_profiles to contracts

vat_rate -> vat_rate
vat_included -> add_vat
trying to use the active billing_profile for each contract

also provide a rudimentary down-script (this is lossy though)
gjungwirth/voicemail_numbers
Gerhard Jungwirth 11 years ago
parent e446761901
commit dc597912e8

@ -0,0 +1,30 @@
USE billing;
SET FOREIGN_KEY_CHECKS = 0;
-- note that the vat information is lost, when this script is executed
BEGIN WORK;
ALTER TABLE billing_profiles
ADD COLUMN vat_rate TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
ADD COLUMN vat_included TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE contracts
DROP COLUMN vat_rate,
DROP COLUMN add_vat;
alter table contacts
DROP column bank_name,
DROP column gpp0,
DROP column gpp1,
DROP column gpp2,
DROP column gpp3,
DROP column gpp4,
DROP column gpp5,
DROP column gpp6,
DROP column gpp7,
DROP column gpp8,
DROP column gpp9;
COMMIT;

@ -2,14 +2,27 @@ USE billing;
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE billing_profiles
DROP COLUMN vat_rate,
DROP COLUMN vat_included;
BEGIN WORK;
ALTER TABLE contracts
ADD COLUMN vat_rate TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
ADD COLUMN add_vat TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;
-- preserve the vat information by copying it from billing_profiles to contracts
UPDATE contracts c
JOIN billing_mappings m ON c.id = m.contract_id AND
m.id = (
SELECT mi.id FROM billing_mappings mi WHERE mi.contract_id = c.id
ORDER BY start_date DESC LIMIT 1)
JOIN billing_profiles p ON m.billing_profile_id = p.id
SET
c.vat_rate = p.vat_rate,
c.add_vat = p.vat_included;
ALTER TABLE billing_profiles
DROP COLUMN vat_rate,
DROP COLUMN vat_included;
DROP TABLE IF EXISTS invoice_templates;
CREATE TABLE `invoice_templates` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
@ -54,3 +67,5 @@ alter table contacts
add column gpp7 varchar(255) default null,
add column gpp8 varchar(255) default null,
add column gpp9 varchar(255) default null;
COMMIT;

Loading…
Cancel
Save