Created
March 2, 2017 07:08
-
-
Save esmeromichael/dd7b73bc50d5c2cdfc1e200ab4662e89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select id, total_amt, applied_amount, bill_type, balance, bill_headers.partner_id, gross from | |
( | |
(SELECT (sum(sd_headers.vatable_sales) + sum(sd_headers.vat_exempt) + sum(sd_headers.zero_rated) + sum(sd_headers.none) ) as gross, | |
sum(sd_headers.vat_amount) as so_vat_amount, sd_headers.partner_id as partner_id | |
from bill_sub_details LEFT OUTER JOIN sd_headers on bill_sub_details.dr_id = sd_headers.id) | |
UNION ALL | |
(SELECT (sum(project_headers.vatable_sales) + sum(project_headers.vat_exempt) + sum(project_headers.zero_rated) + sum(project_headers.none) ) as gross, | |
sum(project_headers.vat_amount) as proj_vat_amount, project_headers.partner_id as partner_id | |
from bill_details LEFT OUTER JOIN project_headers on bill_details.ref_no = project_headers.id) | |
) as sales | |
right JOIN bill_headers on bill_headers.partner_id = sales.partner_id | |
where bill_headers.partner_id = 5 and balance > 0 and status in ('Approved','Printed') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment