Created
February 3, 2014 17:42
-
-
Save hodaddy/8788587 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
$query = DB::table('invoice AS i') | |
->join('client AS c', 'c.id', '=', 'i.client_id') | |
->join('users AS u', 'u.id', '=', 'i.mod_user_id') | |
->join('invoice_payment AS p', 'p.invoice_id', '=', 'i.id') | |
->join('payment_type AS pt', 'pt.id', '=', 'p.payment_method_id') | |
->join('invoice_ticket AS it', 'it.invoice_id', '=', 'i.id') | |
->join('ticket AS t', 't.id', '=', 'it.ticket_id') | |
->join('invoice_delivery AS d', 'd.invoice_id', '=', 'i.id') | |
->select(array( | |
'i.id', 'i.client_id', 'i.mod_user_id', 'i.invoice_type_id', | |
'c.id', 'c.first_name', 'c.last_name', 'c.company', | |
'u.id', 'u.username', | |
'pt.name as payment_type', | |
DB::raw('(SUM(p.amount) - SUM(p.fee)) as p_total, | |
SUM(t.list) as t_list, | |
((SUM(t.list) + (SUM(d.fee) + SUM(d.additional_cost))) - (SUM(p.amount) - SUM(p.fee))) as balance') | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment