/**
  * Creates a new Attendance model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Attendance();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Get the post register / login redirect path.
  *
  * @return string
  */
 public function redirectPath()
 {
     switch (\Auth::user()->role_id) {
         case '4':
             return '/admin';
             break;
         case '3':
             return '/promoter';
             break;
         case '2':
             //aqui agregamos una entrada a la asistencia
             $dateToday = new Carbon();
             $dateToday = $dateToday->toDateString();
             $dateTimeToday = new Carbon();
             $id = Auth::user()->id;
             $Attendance = Attendance::where('datetime', $dateToday)->where('salesman_id', $id)->get();
             if ($Attendance->count() == 0) {
                 // si no lo encuentro creo la fecha
                 $assitance = new Attendance();
                 $assitance->datetime = $dateToday;
                 $assitance->salesman_id = $id;
                 $assitance->datetimestart = $dateTimeToday;
                 $assitance->save();
                 // sleep(0.1);
             } else {
                 // si lo encuentro actualizo la fecha de finalizacion de sesion a null
                 $assitance = Attendance::find($Attendance[0]->id);
                 $assitance->datetimeend = NULL;
                 $assitance->save();
             }
             ////////////////////////////////////////////////////////////////////////////////////////////////////////
             //ahora creo el detalle de la asistencia. esto es si o si
             ////////////////////////////////////////////////////////////////////////////////////////////////////////
             $assitancedetail = new AttendanceDetail();
             $assitancedetail->datetime = $dateTimeToday;
             $assitancedetail->tipo = Config::get('constants.in');
             // ya que se trata de un ingreso
             $id = Auth::user()->id;
             $Attendance = Attendance::where('datetime', $dateToday)->where('salesman_id', $id)->get();
             $assitancedetail->attendance_id = $Attendance[0]->id;
             $assitancedetail->save();
             //tambien agregamos una salida
             $assitancedetail = new AttendanceDetail();
             $assitancedetail->tipo = 2;
             // ya que se trata de un ingreso
             $id = Auth::user()->id;
             $Attendance = Attendance::where('datetime', $dateToday)->where('salesman_id', $id)->get();
             $assitancedetail->attendance_id = $Attendance[0]->id;
             $assitancedetail->datetime = NULL;
             $assitancedetail->save();
             return '/salesman';
             break;
         case '1':
             return '/client/home';
             break;
         default:
             return '/';
             break;
     }
 }
Exemplo n.º 3
0
 public function actionCompare()
 {
     $model = new Attendance();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         // this renders title "Compare Attendance"
         return $this->render('compare', ['model' => $model]);
     }
 }