You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.0 KiB
SQL

DROP TABLE IF EXISTS billing_report;
CREATE TABLE billing_report AS
SELECT billing.pkey,
refNumber,
(SELECT projects.proj_type from projects where projects.refnum = refNumber) AS division,
line_created,
accepted_date,
(qty * default_price) AS fee,
invoice_accepted,
clients.name as Client
FROM billing
INNER JOIN projects on billing.refNumber = projects.refnum
INNER JOIN contacts on projects.contact_fkey = contacts.pkey
INNER JOIN clients on contacts.cl_fkey = clients.pkey
where invoice_accepted = 1;
CREATE INDEX ref_num ON billing_report (refNumber);
CREATE INDEX div_idx ON billing_report (division);
UPDATE billing_report
SET division = IF(
division = 'Warranty',
CONCAT(SUBSTRING(refNumber, 1, 3), ' - ', 'Structural'),
CONCAT(SUBSTRING(refNumber, 1, 3), ' - ', division)
);