private function getIndex(Request $request)
 {
     $date = is_null($request->input('date')) ? $this->dr->now : carbonCheckorNow($request->input('date'));
     $data = $this->timelog->allByDate($date);
     //return dd($data);
     return $this->setViewWithDR(view('timesheet.index')->with('dr', $this->dr)->with('data', $data));
 }
 private function backupParseDate($filename)
 {
     $f = pathinfo($filename, PATHINFO_FILENAME);
     $m = substr($f, 2, 2);
     $d = substr($f, 4, 2);
     $y = '20' . substr($f, 6, 2);
     if (is_iso_date($y . '-' . $m . '-' . $d)) {
         return carbonCheckorNow($y . '-' . $m . '-' . $d);
     } else {
         return false;
     }
 }
 public function apiGetPurchase(Request $request)
 {
     //$categories
     $date = carbonCheckorNow($request->input('date'));
     $data = $this->getPurchaseByDate($date);
     $json = ['status' => 'success', 'code' => 200, 'data' => ['items' => ['date' => $date->format('Y-m-d'), 'data' => $data], 'stats' => ['categories' => $this->getFieldTotal($data, 'catname', 'tcost'), 'expenses' => $this->getExpenseTotal($data, 'tcost'), 'suppliers' => $this->getFieldTotal($data, 'supname', 'tcost')]]];
     if ($request->ajax()) {
         return response()->json($json);
         return response()->json(['status' => 'success', 'code' => 200, 'date' => $date->format('Y-m-d'), 'data' => $data]);
     } else {
         if (intval($request->input('download')) === 1) {
             return $this->export($data, $date);
         } else {
             return $data;
         }
     }
 }
Example #4
0
 public function apiGetPurchase(Request $request)
 {
     $branch = $this->branch->findByField('id', $request->input('branchid'))->first();
     $date = carbonCheckorNow($request->input('date'));
     if (is_null($branch)) {
         $status = 'warning';
         $msg = 'Branch not found!';
         $code = 300;
         $categories = [];
         $expenses = [];
         $suppliers = [];
         $data = [];
     } else {
         $status = 'success';
         $msg = 'success on fetching data';
         $code = 200;
         $data = $this->getPurchaseByDateBranch($branch->id, $date);
         $categories = $this->getFieldTotal($data, 'catname', 'tcost');
         $expenses = $this->getExpenseTotal($data, 'tcost');
         $suppliers = $this->getFieldTotal($data, 'supname', 'tcost');
     }
     //$categories
     $json = ['status' => $status, 'code' => $code, 'message' => $msg, 'data' => ['items' => ['date' => $date->format('Y-m-d'), 'data' => $data], 'stats' => ['categories' => $categories, 'expenses' => $expenses, 'suppliers' => $suppliers]]];
     if ($request->ajax()) {
         return response()->json($json);
     } else {
         if (intval($request->input('download')) === 1) {
             if (is_null($branch)) {
                 return $msg;
             }
             return $this->export($data, $date, $branch);
         } else {
             return $data;
         }
     }
 }
 public function getChecklist(Request $request)
 {
     $date = carbonCheckorNow($request->input('date'));
     $backups = $this->backup->monthlyLogs($date);
     return view('backups.checklist')->with('date', $date)->with('backups', $backups);
 }
 public function getDashboardCSV(Request $request)
 {
     $date = carbonCheckorNow($request->input('date'));
     //echo $date->month.' - '. $date->daysInMonth .'<br>';
     $bb = $this->bb->with('branch')->all();
     echo "Date";
     foreach ($bb as $b) {
         echo ',';
         echo $b->branch->code;
     }
     echo PHP_EOL;
     //echo '<br>';
     for ($i = 1; $i <= $date->daysInMonth; $i++) {
         $day = Carbon::parse($date->year . '-' . $date->month . '-' . $i);
         echo $day->format('Y-m-d') . ",";
         foreach ($bb as $b) {
             $ds = $this->repo->findWhere(['date' => $day->format('Y-m-d'), 'branchid' => $b->branchid])->first();
             echo is_null($ds) ? 0 : $ds->sales;
             echo $bb->last() == $b ? '' : ',';
             //echo ",";
         }
         echo PHP_EOL;
         //echo '<br>';
     }
     return;
     //$response = new Response;
     //$response->header('Content-Type', 'plain/text');
     //$response->header('Content-Disposition', 'attachment; filename="data.csv"');
     //return $response;
 }
Example #7
0
 public function getComparativeJSON(Request $request)
 {
     $this->dr->fr = carbonCheckorNow($request->input('fr'));
     $this->dr->to = carbonCheckorNow($request->input('to'));
     $arr = [];
     $branches = $this->repository->findWhereIn('id', $request->input('branches'), ['code', 'descriptor', 'mancost', 'id']);
     $dss = $this->ds->skipCache()->with(['branch' => function ($query) {
         $query->select(['code', 'descriptor', 'mancost', 'id']);
     }])->scopeQuery(function ($query) use($request) {
         return $query->whereBetween('date', [$this->dr->fr->format('Y-m-d'), $this->dr->to->format('Y-m-d')])->whereIn('branchid', $request->input('branches'))->orderBy('date', 'ASC');
     })->all();
     foreach ($branches as $b) {
         $arr[$b->code] = [];
         foreach ($this->dr->dateInterval() as $date) {
             $filtered = $dss->filter(function ($item) use($b, $date) {
                 return $item->branchid == $b->id && $item->date->format('Y-m-d') == $date->format('Y-m-d') ? $item : null;
             })->first();
             $ds = $filtered;
             $data['date'] = $date->format('Y-m-d');
             $data['timestamp'] = $date->timestamp;
             if (is_null($ds)) {
                 $data['sales'] = 0;
                 $data['mancost'] = 0;
                 $data['mancostpct'] = 0;
                 $data['tips'] = 0;
                 $data['tipspct'] = 0;
                 $data['salesemp'] = 0;
                 $data['purchcost'] = 0;
             } else {
                 $data['sales'] = (double) $ds->sales;
                 $data['mancost'] = (double) number_format($ds->empcount * $b->mancost, 2, '.', '');
                 $data['mancostpct'] = (double) $ds->mancostpct;
                 $data['tips'] = (double) $ds->tips;
                 $data['tipspct'] = (double) $ds->tipspct;
                 $data['salesemp'] = $ds->empcount == '0' ? (double) '0.00' : (double) number_format($ds->sales / $ds->empcount, 2, '.', '');
                 $data['purchcost'] = (double) $ds->purchcost;
             }
             array_push($arr[$b->code], $data);
         }
     }
     //return response()->json($arr);
     return response($arr)->header('Content-Type', 'text/json')->withCookie(cookie('to', $this->dr->to->format('Y-m-d'), 120))->withCookie(cookie('fr', $this->dr->fr->format('Y-m-d'), 120));
 }
 private function setDateRangeMode(Request $request, $mode = 'day')
 {
     $y = false;
     switch ($mode) {
         case 'month':
             $to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->endOfMonth();
             $fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $to->copy()->subMonths(5)->startOfMonth();
             if ($to->lt($fr)) {
                 $to = Carbon::now()->endOfMonth();
                 $fr = $to->copy()->subMonths(5)->startOfMonth();
                 //$to->copy()->startOfMonth();
             } else {
                 $to = $to->endOfMonth();
                 $fr = $fr->startOfMonth();
             }
             break;
         case 'daily':
             $to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->endOfMonth();
             $fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $to->copy()->startOfMonth();
             if ($to->lt($fr)) {
                 $to = Carbon::now();
                 $fr = $to->copy()->startOfMonth();
             }
             break;
         case 'weekly':
             $to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->endOfWeek();
             $fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $to->copy()->subWeeks(5)->startOfWeek();
             if ($to->lt($fr)) {
                 $to = Carbon::now()->endOfWeek();
                 $fr = $to->copy()->subWeeks(5)->startOfWeek();
                 //$to->copy()->startOfWeek();
             } else {
                 $to = $to->endOfWeek();
                 $fr = $fr->startOfWeek();
             }
             break;
         case 'quarterly':
             $to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->lastOfQuarter();
             $fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $to->copy()->subMonths(11)->firstOfQuarter();
             if ($to->lt($fr)) {
                 $to = Carbon::now()->lastOfQuarter();
                 $fr = $to->copy()->subMonths(12)->firstOfQuarter();
                 //$to->copy()->startOfWeek();
             } else {
                 $to = $to->lastOfQuarter();
                 $fr = $fr->firstOfQuarter();
             }
             break;
         case 'yearly':
             $y = true;
             $to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->lastOfYear();
             $fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $to->copy()->subYear()->firstOfYear();
             if ($to->lt($fr)) {
                 $to = Carbon::now()->lastOfYear();
                 $fr = $to->copy()->subYear()->firstOfYear();
                 //$to->copy()->startOfWeek();
             } else {
                 $to = $to->lastOfYear();
                 $fr = $fr->firstOfYear();
             }
             break;
         default:
             $to = Carbon::now()->endOfMonth();
             $fr = $to->copy()->startOfMonth();
             break;
     }
     if (!$y) {
         // if more than a year
         if ($fr->diffInDays($to, false) >= 731) {
             // 730 = 2yrs
             $this->dr->fr = $to->copy()->subDays(730)->startOfMonth();
             $this->dr->to = $to;
             $this->dr->date = $to;
             return false;
         }
     }
     $this->dr->fr = $fr;
     $this->dr->to = $to;
     $this->dr->date = $to;
     return true;
 }
Example #9
0
 public function setDateRangeMode($arg = null, $arg2 = null)
 {
     if (is_null($arg) && is_null($arg)) {
         $request = $this->request;
         $mode = 'daily';
     } elseif (in_array($arg, $this->modes) && $arg2 == null) {
         $request = $this->request;
         $mode = $arg;
     } elseif ($arg instanceof Request && in_array($arg2, $this->modes)) {
         $request = $arg;
         $mode = $arg2;
     }
     //$this->setDateRangeFromRequest($request);
     $this->mode = $mode;
     $y = false;
     switch ($mode) {
         case 'monthly':
             $this->to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->endOfMonth();
             $this->fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $this->to->copy()->subMonths(5)->startOfMonth();
             if ($this->to->lt($this->fr)) {
                 $this->to = Carbon::now()->endOfMonth();
                 $this->fr = $this->to->copy()->subMonths(5)->startOfMonth();
                 //$this->to->copy()->startOfMonth();
             } else {
                 $this->to = $this->to->endOfMonth();
                 $this->fr = $this->fr->startOfMonth();
             }
             break;
         case 'daily':
             $this->to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->endOfMonth();
             $this->fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $this->to->copy()->startOfMonth();
             if ($this->to->lt($this->fr)) {
                 $this->to = Carbon::now();
                 $this->fr = $this->to->copy()->startOfMonth();
             }
             break;
         case 'weekly':
             $this->to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->endOfWeek();
             $this->fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $this->to->copy()->subWeeks(5)->startOfWeek();
             if ($this->to->lt($this->fr)) {
                 $this->to = Carbon::now()->endOfWeek();
                 $this->fr = $this->to->copy()->subWeeks(5)->startOfWeek();
                 //$this->to->copy()->startOfWeek();
             } else {
                 $this->to = $this->to->endOfWeek();
                 $this->fr = $this->fr->startOfWeek();
             }
             break;
         case 'quarterly':
             $this->to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->lastOfQuarter();
             $this->fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $this->to->copy()->subMonths(11)->firstOfQuarter();
             if ($this->to->lt($this->fr)) {
                 $this->to = Carbon::now()->lastOfQuarter();
                 $this->fr = $this->to->copy()->subMonths(12)->firstOfQuarter();
                 //$this->to->copy()->startOfWeek();
             } else {
                 $this->to = $this->to->lastOfQuarter();
                 $this->fr = $this->fr->firstOfQuarter();
             }
             break;
         case 'yearly':
             $y = true;
             $this->to = !is_null($request->input('to')) ? carbonCheckorNow($request->input('to')) : Carbon::now()->lastOfYear();
             $this->fr = !is_null($request->input('fr')) ? carbonCheckorNow($request->input('fr')) : $this->to->copy()->subYear()->firstOfYear();
             if ($this->to->lt($this->fr)) {
                 $this->to = Carbon::now()->lastOfYear();
                 $this->fr = $this->to->copy()->subYear()->firstOfYear();
                 //$this->to->copy()->startOfWeek();
             } else {
                 $this->to = $this->to->lastOfYear();
                 $this->fr = $this->fr->firstOfYear();
             }
             break;
         default:
             $this->to = Carbon::now()->endOfDay();
             $this->fr = $this->to->copy()->startOfMonth();
             break;
     }
     if (!$y) {
         // if more than a year
         if ($this->fr->diffInDays($this->to, false) >= 731) {
             // 730 = 2yrs
             $this->fr = $this->to->copy()->subDays(730)->startOfMonth();
             $this->to = $this->to;
             $this->date = $this->to;
             return false;
         }
     }
     return true;
 }
 private function getPrintIndex(Request $request)
 {
     $date = is_null($request->input('date')) ? $this->dr->date : carbonCheckorNow($request->input('date'));
     $data = $this->timelog->allByDate($date);
     return view('timesheet.index-print')->with('dr', $this->dr)->with('data', $data);
 }
Example #11
0
 public function getChecklist(Request $request)
 {
     $bb = $this->branch->orderBy('code')->getByCriteria(new ActiveBranch())->all(['code', 'descriptor', 'id']);
     $date = carbonCheckorNow($request->input('date'));
     if (!$request->has('branchid') && !isset($_GET['branchid'])) {
         return view('backup.checklist')->with('date', $date)->with('branches', $bb)->with('branch', null)->with('backups', null);
     }
     if (!is_uuid($request->input('branchid')) || !in_array(strtoupper($request->input('branchid')), $this->branch->all()->pluck('id')->all())) {
         return redirect('/backup/checklist')->with('alert-warning', 'Please select a branch.');
     }
     try {
         $branch = $this->branch->find(strtolower($request->input('branchid')));
     } catch (Exception $e) {
         return redirect('/backup/checklist')->with('alert-warning', 'Please select a branch.');
     }
     $backups = $this->repository->monthlyLogs($date, $branch);
     return view('backup.checklist')->with('date', $date)->with('branches', $bb)->with('branch', $branch)->with('backups', $backups);
 }