I was trying to make monthly report what i wanted to show in chart. I need to find the monthly report (i.e. everyday collection).
$monthly_report_chart = DB::table("invoices")
->select(DB::raw("DATE_FORMAT(updated_at, '%d/%m/%Y ') as today"),
// DB::raw("SUM(collected_today) as sum") [problem of finding everyday collection] )
->groupBy(DB::raw('Date(updated_at)'))
->whereMonth('updated_at','=',date('m'))
->get();
But the problem is finding the total collection of each day. How to find total collection of each day with above query? Here is the method of finding total of each invoice:
static function totalPrice($id)
{
$itemsPrice = 0;
$prices = DB::table('invoices')
->join('carts','carts.invoice_id','invoices.id')
->select('purchase_price','quantity')
->where('carts.invoice_id','=',$id)
->get();
$invoice_price = DB::table('invoices')
->select('vat','discount')
->where('invoices.id','=',$id)
->first();
foreach ($prices as $price)
{
$itemsPrice = $itemsPrice+ $price->purchase_price*$price->quantity;
}
$itemsPrice = $itemsPrice - $invoice_price->discount + (($itemsPrice*$invoice_price->vat)/100);
return $itemsPrice;
}
Carts Table structure:
id , invoice_id, product_id, quantity , purchase_price, created_at, updated_at
Invoices Table structure:
id, customer_id, discount, vat, created_at, updated_at
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2N0K4ut
via IFTTT
Aucun commentaire:
Enregistrer un commentaire