mardi 1 août 2017

How to take sum of column of different date in laravel and mongo?

I have a statistics page. In this page I need to integrate line graph using chartjs. For plotting graph I need to take sum (amount) and sum (total_amount) of different booking date. I have tried some code but getting null. Please check my code, expecting result and booking table structure given below.

My db is mongodb. Project is developing using laravel

I am following this repo for eloquent with mongodb "http://ift.tt/1qxFWF0"

booking

_id amount total_amount bookingdate (date)

57ea5a3bf8f888c40900002a 25 50 2016-09-30 17:06:18.000

57ea5a3bf8f888c40888883a 20 55 2016-09-30 11:07:19.000

57ea5a3bf8f888c40999998a 15 30 2017-02-15 17:06:18.000

57ea5a3bf8f888c40444445a 35 55 2017-02-15 09:06:18.000

57ea5a3bf8f888c40966667a 39 67 2017-05-11 10:06:18.000

57ea5a3bf8f888c40967806a 43 49 2017-05-11 11:06:18.000

Expecting result

amount total_amount bookingdate (date)

45 105 2016-09-30

50 85 2017-02-15

82 116 2017-05-11

Code

if(!empty($request->cabin) && !empty($request->daterange))
        {
            $cabinName              = $request->cabin;
            $daterange              = explode("-", $request->daterange);
            $dateBegin              = new \MongoDB\BSON\UTCDateTime(strtotime($daterange[0])*1000);
            $dateEnd                = new \MongoDB\BSON\UTCDateTime(strtotime($daterange[1])*1000);
            $bookings               = Booking::select('total_amount', 'amount', 'bookingdate')
                ->where('is_delete', 0)
                ->where('cabinname', $cabinName)
                ->whereBetween('bookingdate', [$dateBegin, $dateEnd])
                ->groupBy('checkin_from')
                ->sum('bookingdate');
            return response()->json(['incomingCount' => $bookings]);
        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire