Beispiel #1
0
 public function post(Request $request)
 {
     //
     $this->validate($request, ['date' => 'required|date|max:10', 'weekno' => 'required']);
     // check weekno if exist
     $mansked = Mansked::whereWeekno($request->input('weekno'))->get();
     if (count($mansked) > 0) {
         return redirect('/branch/mansked/add')->withErrors(['message' => 'Week ' . $request->input('weekno') . ' already created!'])->withInput();
     }
     //$mansked = array_shift($mansked);
     $mansked = new Mansked();
     //return $mansked->getRefno();
     $mansked->refno = $mansked->getRefno();
     $mansked->date = $request->input('date');
     $mansked->weekno = $request->input('weekno');
     $mansked->branchid = $request->input('branchid');
     $mansked->managerid = $request->input('managerid');
     $mansked->mancost = $request->input('mancost');
     $mansked->notes = $request->input('notes');
     $mansked->id = $mansked->get_uid();
     $mandays = [];
     foreach ($mansked->getDaysByWeekNo($request->input('weekno')) as $key => $date) {
         $manday = new Manday();
         $manday->date = $date;
         $manday->id = $manday->get_uid();
         array_push($mandays, $manday);
     }
     \DB::beginTransaction();
     //Start transaction!
     try {
         $mansked->save();
         try {
             $mansked->manskeddays()->saveMany($mandays);
         } catch (\Exception $e) {
             \DB::rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         \DB::rollback();
         throw $e;
     }
     \DB::commit();
     //$mansked->id
     //return $id;
     //return dd($mansked);
     $mansked->load('manskeddays');
     foreach ($mansked->manskeddays as $manskedday) {
         foreach ($this->employees as $employee) {
             $mandtl = new Mandtl();
             $mandtl->employeeid = $employee->id;
             $mandtl->id = $mandtl->get_uid();
             $manskedday->manskeddtls()->save($mandtl);
         }
     }
     return $mansked;
 }
Beispiel #2
0
 public static function getManskedday($year, $weekno)
 {
     $mansked = Manskedhdr::with('manskeddays')->select('id')->where('weekno', $weekno)->where('branchid', Auth::user()->branchid)->get()->first();
     $days = isset($mansked) ? $mansked->manskeddays->keyBy('date')->toArray() : [];
     $arr_days = [];
     for ($day = 0; $day <= 7; $day++) {
         if (!$day == 0) {
             $currday = date('Y-m-d', strtotime($year . "W" . $weekno . $day));
             $arr_days[$day]['date'] = $currday;
             $arr_days[$day][0] = $currday;
             if (array_key_exists($currday, $days)) {
                 $arr_days[$day]['created'] = 'true';
                 $arr_days[$day][1] = 'true';
                 $x = 2;
                 foreach ($days[$currday] as $key => $value) {
                     if ($key == 'date') {
                         continue;
                     }
                     $arr_days[$day][$key] = $value;
                     $arr_days[$day][$x] = $value;
                     $x++;
                 }
             } else {
                 // no data from database
                 $arr_days[$day]['created'] = 'false';
                 $arr_days[$day][1] = 'false';
                 $arr_days[$day][2] = '-';
                 $arr_days[$day][3] = '-';
                 $arr_days[$day][4] = '-';
                 $arr_days[$day][5] = '-';
                 $arr_days[$day][6] = '-';
                 $arr_days[$day][7] = 'Create Header';
             }
             $arr_days[$day][7] = $arr_days[$day][1];
         } else {
             $arr_days[0]['created'] = '';
             $arr_days[0][0] = '<i class="fa fa-calendar"></i> Date';
             $arr_days[0][1] = 'created';
             $arr_days[0][2] = '';
             $arr_days[0][3] = '<span class="glyphicon glyphicon-user"></span> Customers';
             $arr_days[0][4] = '<i class="fa fa-line-chart"></i> Ave Spending';
             $arr_days[0][5] = '<i class="fa fa-users"></i> Crew on Duty';
             $arr_days[0][6] = '';
             $arr_days[0][7] = '';
         }
     }
     return $arr_days;
 }
 public function newWeek(Request $request)
 {
     $arr = [];
     $obj = Mansked::where('branchid', $request->user()->branchid)->orderBy('createdate', 'DESC')->get()->first();
     if (count($obj) <= 0) {
         $arr['weekno'] = date('W', strtotime('now'));
         $arr['year'] = date('Y', strtotime('now'));
         $arr['weekdays'] = $this->getDaysByWeekNo($arr['weekno']);
     } else {
         if (lastWeekOfYear() > $obj->weekno) {
             $arr['weekno'] = $obj->weekno + 1;
             $arr['year'] = $obj->year;
             $arr['weekdays'] = $this->getDaysByWeekNo($obj->weekno + 1);
             $arr['lmanskedid'] = $obj->id;
         } else {
             $arr['weekno'] = 1;
             $arr['year'] = Carbon::now()->addYear()->year;
             $arr['weekdays'] = $this->getDaysByWeekNo(1, $arr['year']);
             $arr['lmanskedid'] = $obj->id;
         }
     }
     return $arr;
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer('*', function ($view) {
         $id = empty(Auth::user()->id) ? '' : Auth::user()->id;
         if (strtolower($id) !== strtolower(session('user.id'))) {
             $emp = User::with(['branch' => function ($query) {
                 $query->select('code', 'descriptor', 'mancost', 'id');
             }])->where('id', Auth::user()->id)->get(['name', 'branchid', 'id'])->first();
             session(['user' => ['fullname' => $emp->name, 'id' => $emp->id, 'branchid' => $emp->branchid, 'branch' => $emp->branch->descriptor, 'branchcode' => $emp->branch->code, 'branchmancost' => $emp->branch->mancost]]);
         }
         $view->with('name', session('user.fullname'))->with('branch', session('user.branch'));
     });
     Mansked::created(function ($mansked) {
         Event::fire(new ManskedCreated($mansked));
     });
     Mansked::updated(function ($mansked) {
         event(new ManskedUpdated($mansked));
         // using the global event
     });
     Mansked::deleted(function ($mansked) {
         Event::fire(new ManskedDeleted($mansked));
     });
 }
 public function testWeeks(Request $request)
 {
     $weeks = Mansked::paginateWeeks($request, '2015');
     return view('branch.mansked.list')->with('weeks', $weeks);
 }
 public function copyMansked(Request $request)
 {
     $this->validate($request, ['lweekno' => 'required', 'nweekno' => 'required', 'year' => 'required', 'lmanskedid' => 'required']);
     $mansked1 = Mansked::whereWeekno($request->input('nweekno'))->where('year', $request->input('year'))->where('branchid', $request->user()->branchid)->get();
     if (count($mansked1) > 0) {
         return redirect('/task/mansked')->withErrors(['message' => 'Manpower Schedule Week ' . $request->input('nweekno') . ' already exist!'])->withInput();
     }
     $mansked = Mansked::find($request->input('lmanskedid'));
     if (count($mansked) <= 0) {
         return redirect('/task/mansked')->withErrors(['message' => 'Pointer Week ' . $request->input('lweekno') . ' not found!'])->withInput();
     }
     $mansked->load('manskeddays');
     $mandays = $mansked->manskeddays;
     foreach ($mandays as $manday) {
         $manday->load('manskeddtls');
     }
     $new_mansked = new Mansked();
     //return $mansked->getRefno();
     $new_mansked->refno = $new_mansked->getRefno();
     $new_mansked->date = $mansked->date->format('Y-m-d');
     $new_mansked->weekno = $request->input('nweekno');
     $new_mansked->year = $request->input('year');
     $new_mansked->branchid = $mansked->branchid;
     $new_mansked->managerid = $mansked->managerid;
     $new_mansked->mancost = $mansked->mancost;
     $new_mansked->notes = $mansked->notes;
     $new_mansked->id = $mansked->get_uid();
     \DB::beginTransaction();
     //Start transaction!
     $new_mandays = [];
     foreach ($new_mansked->getDaysByWeekNo($request->input('nweekno'), $request->input('year')) as $key => $date) {
         $new_manday = new Manday();
         $new_manday->date = $date->format('Y-m-d');
         $new_manday->custcount = $mandays[$key]->custcount;
         $new_manday->headspend = $mandays[$key]->headspend;
         $new_manday->empcount = $mandays[$key]->empcount;
         $new_manday->workhrs = $mandays[$key]->workhrs;
         $new_manday->breakhrs = $mandays[$key]->breakhrs;
         $new_manday->overload = $mandays[$key]->overload;
         $new_manday->underload = $mandays[$key]->underload;
         $new_manday->id = $new_manday->get_uid();
         $new_mandtls = [];
         foreach ($mandays[$key]->manskeddtls as $mandtl) {
             $new_mandtl = new Mandtl();
             $new_mandtl->employeeid = $mandtl->employeeid;
             $new_mandtl->daytype = $mandtl->daytype;
             $new_mandtl->timestart = $mandtl->timestart;
             $new_mandtl->breakstart = $mandtl->breakstart;
             $new_mandtl->breakend = $mandtl->breakend;
             $new_mandtl->timeend = $mandtl->timeend;
             $new_mandtl->workhrs = $mandtl->workhrs;
             $new_mandtl->breakhrs = $mandtl->breakhrs;
             $new_mandtl->loading = $mandtl->loading;
             $new_mandtl->id = $new_mandtl->get_uid();
             array_push($new_mandtls, $new_mandtl);
         }
         try {
             $new_manday->manskeddtls()->saveMany($new_mandtls);
         } catch (\Exception $e) {
             \DB::rollback();
             throw $e;
         }
         array_push($new_mandays, $new_manday);
     }
     try {
         $new_mansked->save();
         try {
             $new_mansked->manskeddays()->saveMany($new_mandays);
         } catch (\Exception $e) {
             \DB::rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         \DB::rollback();
         throw $e;
     }
     \DB::commit();
     return redirect('/task/mansked')->with(['new' => true])->with('alert-success', 'Week ' . $request->input('lweekno') . ' successfully copied!');
     $new_mansked->load('manskeddays');
     $new_mandays = $new_mansked->manskeddays;
     foreach ($new_mandays as $new_manday) {
         $new_manday->load('manskeddtls');
     }
     return $new_mansked;
 }