added client name to billing report
parent
3ffa03f765
commit
d46852cd9a
@ -1,24 +1,27 @@
|
|||||||
DROP TABLE IF EXISTS billing_report;
|
DROP TABLE IF EXISTS billing_report;
|
||||||
|
|
||||||
CREATE TABLE billing_report AS
|
CREATE TABLE billing_report AS
|
||||||
SELECT pkey,
|
SELECT billing.pkey,
|
||||||
refNumber,
|
refNumber,
|
||||||
(SELECT all_projects.proj_type from all_projects where all_projects.refnum = refNumber) AS division,
|
(SELECT all_projects.proj_type from all_projects where all_projects.refnum = refNumber) AS division,
|
||||||
line_created,
|
line_created,
|
||||||
accepted_date,
|
accepted_date,
|
||||||
(qty * default_price) AS fee,
|
(qty * default_price) AS fee,
|
||||||
invoice_accepted,
|
invoice_accepted,
|
||||||
(SELECT clients.name FROM clients where clients.pkey = (SELECT contacts.cl_fkey from contacts where pkey = (SELECT all_projects.contact_fkey where all_projects.refnum = refNumber))) as 'Client'
|
clients.name as Client
|
||||||
FROM billing
|
FROM billing
|
||||||
|
INNER JOIN all_projects on billing.refNumber = all_projects.refnum
|
||||||
|
INNER JOIN contacts on all_projects.contact_fkey = contacts.pkey
|
||||||
|
INNER JOIN clients on contacts.cl_fkey = clients.pkey
|
||||||
where invoice_accepted = 1;
|
where invoice_accepted = 1;
|
||||||
|
|
||||||
CREATE INDEX ref_num ON billing_report (refNumber);
|
CREATE INDEX ref_num ON billing_report (refNumber);
|
||||||
CREATE INDEX div_idx ON billing_report (division);
|
CREATE INDEX div_idx ON billing_report (division);
|
||||||
|
|
||||||
|
|
||||||
UPDATE billing_report
|
UPDATE billing_report
|
||||||
SET division = IF(
|
SET division = IF(
|
||||||
division = 'Warranty',
|
division = 'Warranty',
|
||||||
CONCAT(SUBSTRING(refNumber, 1, 3), ' - ', 'Structural'),
|
CONCAT(SUBSTRING(refNumber, 1, 3), ' - ', 'Structural'),
|
||||||
CONCAT(SUBSTRING(refNumber, 1, 3), ' - ', division)
|
CONCAT(SUBSTRING(refNumber, 1, 3), ' - ', division)
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue