예제 #1
0
 public function getLastestSales(Request $request, $day = 1)
 {
     $arr = [];
     $to = Carbon::now();
     //$to = Carbon::parse('2016-03-6');
     $fr = $to->copy()->subDay($day);
     $dss = DailySales::whereBetween('date', [$fr->format('Y-m-d'), $to->format('Y-m-d')])->where('branchid', $request->user()->branchid)->get();
     foreach ($this->dateInterval($fr, $to) as $key => $date) {
         $filtered = $dss->filter(function ($item) use($date) {
             return $item->date->format('Y-m-d') == $date->format('Y-m-d') ? $item : null;
         });
         $obj = new StdClass();
         $obj->date = $date;
         $obj->dailysale = $filtered->first();
         $arr[$key] = $obj;
     }
     return array_reverse($arr);
 }
예제 #2
0
 public function todayTopSales(Carbon $date, $limit = 10)
 {
     $arr = [];
     $ds_null = false;
     $current_day_zero_sales = false;
     $ds = DailySales::where('date', $date->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get();
     if (count($ds) == '0') {
         $ds = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get();
         $ds_null = true;
     } else {
         foreach ($ds as $d) {
             if ($d->sales == '0.00') {
                 $ds = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->orderBy('sales', 'DESC')->take($limit)->get();
                 $ds_null = true;
                 continue;
             }
         }
     }
     foreach ($ds as $d) {
         $branch = Branch::where('id', $d->branchid)->get(['code', 'descriptor', 'id'])->first();
         if ($ds_null) {
             $ds_today = new DailySales();
             $ds_yesteday = $d;
         } else {
             $ds_today = $d;
             $ds_yesteday = DailySales::where('date', $date->copy()->subDay()->format('Y-m-d'))->where('branchid', $d->branchid)->first();
         }
         $ds_otherday = DailySales::where('date', $date->copy()->subDay(2)->format('Y-m-d'))->where('branchid', $d->branchid)->first();
         $s = new StdClass();
         $c = new StdClass();
         $s->branch = $branch;
         $s->today = $ds_today;
         $s->yesterday = $ds_yesteday;
         $s->otherday = $ds_otherday;
         $c->sales = $ds_today->sales - $ds_yesteday->sales;
         $s->today->sign = $this->getSign($ds_today->sales - $ds_yesteday->sales);
         $c->sales1 = $ds_yesteday->sales - $ds_otherday->sales;
         $s->yesterday->sign = $this->getSign($ds_yesteday->sales - $ds_otherday->sales);
         $s->diff = $c;
         array_push($arr, $s);
     }
     return collect($arr);
 }