Aronaman
4 months ago
674
6
Laravel

DB query grouping sum each

Posted 4 months ago by Aronaman

i want to achieve

*OrgName #1
        - PayPal
            - 2020-01-01 
                    [ 
                    array_booking
                    ]
                - Count Total (LBP)
                - Total Sum(LBC) commison
            - 2020-01-02
                    [ 
                    array_booking
                    ]
                - Count Total (LBP)
                - Total Sum(LBC) commison
            - 2020-01-04
                .
                .

        - credit Card
            - 2020-01-02
                    [ 
                    array_booking
                    ]
                - Count Total (SBP)
                - Total Sum(SBC) commison


    *OrgName #2

bookings table

id |org_id | local_id| check_in| Checkout| commision| Pay| Payment_gateway| create_at| update_at|

my query i just try

$bookedStatus_id=BookStatus::where('name','Booked')->first()->id;
 $booking=Booking::with('bookable')->where('book_status_id',$bookedStatus_id)
    				->where('pay','>',0)
    				->selectRaw("DATE_FORMAT(Update_date, '%Y %m %e') date")
    				->get()
    				->groupBy(['organization_id','payment_gateway','date'])
    				->toArray();

// db query also try 
$booking=DB::table('bookings')->where('book_status_id',$bookedStatus_id)
    			->where('pay','>',0)
    			 ->selectRaw("DATE_FORMAT(check_in, '%Y %m %e') date")
    			->selectRaw("*,SUM(commison) as sum")					  
    			->get()
    			 ->groupBy(['organization_id','payment_gateway','date'])
    									  
    			 ->toArray();

not working for me any help, please

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