We need to have contacts with just a name: we need to assign freelancer’s quote as expense linked the government, but of course we do not have a phone or email for that “contact”, much less a VATIN or other tax details. It is also interesting for other expenses-only contacts to not have to input all tax details, as we may not need to invoice then, thus are useless for us, but sometimes it might be interesting to have them, “just in case”. Of course, i did not want to make nullable any of the tax details required to generate an invoice, otherwise we could allow illegal invoices. Therefore, that data had to go in a different relation, and invoice’s foreign key update to point to that relation, not just customer, or we would again be able to create invalid invoices. We replaced the contact’s trade name with just name, because we do not need _three_ names for a contact, but we _do_ need two: the one we use to refer to them and the business name for tax purposes. The new contact_phone, contact_web, and contact_email relations could be simply a nullable field, but i did not see the point, since there are not that many instances where i need any of this data. Now company.taxDetailsForm is no longer “the same as contactForm with some extra fields”, because i have to add a check whether the user needs to invoice the contact, to check that the required values are there. I have an additional problem with the contact form when not using JavaScript: i must set the required field to all tax details fields to avoid the “(optional)” suffix, and because they _are_ required when that checkbox is enabled, but i can not set them optional when the check is unchecked. My solution for now is to ignore the form validation, and later i will add some JavaScript that adds the validation again, so it will work in all cases.
52 lines
1.2 KiB
PL/PgSQL
52 lines
1.2 KiB
PL/PgSQL
-- Revert numerus:contact_tax_details from pg
|
|
|
|
begin;
|
|
|
|
set search_path to numerus, public;
|
|
|
|
alter table contact
|
|
drop constraint name_not_empty
|
|
, add column country_code country_code
|
|
, add column postal_code text
|
|
, add column province text
|
|
, add column city text
|
|
, add column address text
|
|
, add column vatin vatin
|
|
, add column business_name text constraint business_name_not_empty check(length(trim(business_name)) > 1)
|
|
;
|
|
|
|
alter table contact
|
|
rename column name to trade_name
|
|
;
|
|
|
|
update contact
|
|
set business_name = tax.business_name
|
|
, vatin = tax.vatin
|
|
, address = tax.address
|
|
, city = tax.city
|
|
, province = tax.province
|
|
, postal_code = tax.postal_code
|
|
, country_code = tax.country_code
|
|
from contact_tax_details as tax
|
|
where tax.contact_id = contact.contact_id
|
|
;
|
|
|
|
alter table contact
|
|
alter column business_name set not null
|
|
, alter column vatin set not null
|
|
, alter column address set not null
|
|
, alter column city set not null
|
|
, alter column province set not null
|
|
, alter column postal_code set not null
|
|
, alter column country_code set not null
|
|
;
|
|
|
|
update contact
|
|
set trade_name = ''
|
|
where trade_name = business_name
|
|
;
|
|
|
|
drop table if exists contact_tax_details;
|
|
|
|
commit;
|