Update invoice query to allow for missing invoice_item_taxes records, discount is now removed from price base before calculating item_total
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 35s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s

This commit is contained in:
Deon George 2024-07-06 22:17:41 +10:00
parent 3c7e2bbbc9
commit 61fe84498a

View File

@ -290,16 +290,16 @@ class Account extends Model implements IDs
->select([
'invoice_id',
DB::raw('ROUND(CAST(SUM(quantity*price_base) AS NUMERIC),2) AS item'),
DB::raw('ROUND(CAST(SUM(amount) AS NUMERIC),2) AS tax'),
DB::raw('ROUND(CAST(SUM(COALESCE(amount,0)) AS NUMERIC),2) AS tax'),
DB::raw('ROUND(CAST(SUM(COALESCE(invoice_items.discount_amt,0)) AS NUMERIC),2) AS discount'),
DB::raw('ROUND(CAST(SUM(ROUND(CAST(quantity*price_base AS NUMERIC),2))+SUM(ROUND(CAST(amount AS NUMERIC),2))-SUM(ROUND(CAST(COALESCE(invoice_items.discount_amt,0) AS NUMERIC),2)) AS NUMERIC),2) AS item_total'),
DB::raw('ROUND(CAST(SUM(ROUND(CAST(quantity*(price_base-COALESCE(invoice_items.discount_amt,0)) AS NUMERIC),2))+SUM(ROUND(CAST(COALESCE(amount,0) AS NUMERIC),2)) AS NUMERIC),2) AS item_total'),
DB::raw('0 as payments'),
DB::raw('0 as payment_fees'),
])
->leftjoin('invoice_item_taxes',['invoice_item_taxes.invoice_item_id'=>'invoice_items.id'])
->rightjoin('invoices',['invoices.id'=>'invoice_items.invoice_id'])
->where('invoice_items.active',TRUE)
->where('invoice_item_taxes.active',TRUE)
->where(fn($query)=>$query->where('invoice_item_taxes.active',TRUE)->orWhereNull('invoice_item_taxes.active'))
->where('invoices.active',TRUE)
->groupBy(['invoice_items.invoice_id']),
),'p')