コード例 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request)
 {
     $leave = DB::table('extra')->select('leave_h', 'extra_h')->where('user_id', Auth::User()->id)->orderBy('extra_date', 'desc')->first();
     $leave_time = $leave->leave_h;
     $attend = $leave->extra_h;
     $attendSplit = explode(':', $attend);
     $extraH = $attendSplit[0];
     $extraM = $attendSplit[1];
     $todayDate = date('d-m-Y');
     $leave_h = date('H:i');
     $end = $request->extraEnd;
     $calcH = date('H') - $extraH;
     $Mcalc = $extraM;
     if (date('i') > $Mcalc) {
         $calcM = date('i') - $Mcalc;
     } else {
         if ($Mcalc > 60) {
             $calcM = $Mcalc - 60 - date('i');
             $calcH--;
         } else {
             $calcM = $Mcalc - date('i');
         }
     }
     if ($calcH < 10) {
         $calcH = '0' . $calcH;
     } else {
         $calcH = $calcH;
     }
     if ($calcM < 10) {
         $calcM = '0' . $calcM;
     } else {
         $calcM = $calcM;
     }
     if ($end === 'extraEnd' && $leave_time === '00:00') {
         $update = DB::table('extra')->where('user_id', Auth::User()->id)->where('extra_date', $todayDate)->update(['leave_h' => $leave_h, 'calc_hour' => $calcH, 'calc_min' => $calcM]);
         $doneMsg = 'Ended Extra Time Successfully';
         $success = 'alert-success';
         return homeController::index($doneMsg, $success);
     } else {
         $doneMsg = 'you already done that';
         $success = 'alert-danger';
         return homeController::index($doneMsg, $success);
     }
 }
コード例 #2
0
 public function BreakTime(Request $request)
 {
     $break = DB::table('attend')->select('break_h', 'calc_hour', 'calc_min', 'leave_h')->where('user_id', Auth::User()->id)->orderBy('attend_date', 'desc')->first();
     if ($break) {
         $breakH = $request->breakH;
         $breakM = $request->breakM;
         $calcHour = $break->calc_hour;
         $calcMin = $break->calc_min;
         $breakHour = $break->break_h;
         $todayDate = date('Y-m-d');
         $LeaveHour = $break->leave_h;
         $calcH = $calcHour - $breakH;
         if ($calcMin >= $breakM) {
             $calcM = $calcMin - $breakM;
         } else {
             $calcM = 60 - $breakM + $calcMin;
             $calcH--;
         }
         if ($calcH < 10) {
             $calcH = '0' . $calcH;
         } else {
             $calcH = $calcH;
         }
         if ($calcM < 10) {
             $calcM = '0' . $calcM;
         } else {
             $calcM = $calcM;
         }
         if ($breakH === '0') {
             $breakH = '01';
             $BreakLeave = $LeaveHour;
         } elseif ($breakH === '1') {
             $breakH = '02';
             $breakLeave = $LeaveHour + 1;
             $calcH++;
         }
         if ($breakHour === '1:00') {
             $update = DB::table('attend')->where('user_id', Auth::User()->id)->where('attend_date', $todayDate)->update(['break_h' => $breakH . ':' . $breakM, 'calc_hour' => $calcH, 'calc_min' => $calcM, 'leave_h' => $breakLeave]);
             $doneMsg = 'Done Successfully';
             $success = 'alert-success';
             return homeController::index($doneMsg, $success);
         } else {
             $doneMsg = 'you already done that';
             $success = 'alert-danger';
             return homeController::index($doneMsg, $success);
         }
     } else {
         $doneMsg = 'No data avalible';
         $success = 'alert-danger';
         return homeController::index($doneMsg, $success);
     }
 }