Grouping by 15 days( 1 ~ 15 ) / ( 16 ~ end of month ).

Posted 1 month ago by SangminKim

Hi everyone,

I have a query that groups billing information by month. However, I'd like to tweak it so that the query retrieves billing information by 15 days - i.e. ( 1 ~ 15 ) / ( 16 ~ end of month ).

$billings = Billing::select(\DB::raw("YEAR(billing_date) as year,
                                            MONTH(billing_date) as month,
                                            SUM(subtotal + extra_fee) as subtotal,
                                            SUM(gst) as gst, SUM(pst) as pst,
                                            SUM(subtotal) as total"))
                            ->groupBy(\DB::raw("YEAR(billing_date)"))
                            ->groupBy(\DB::raw("MONTH(billing_date)"))
                            ->orderBy('year', 'desc')
                            ->orderBy('month', 'desc')
                            ->get();

What would be the best way to do it with eloquent?

Thanks.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.