public function afterSave() { $recap = AttendancePresencesRecap::model()->findByAttributes(array('date' => $this->date, 'employee_id' => $this->employee_id)); if (!isset($recap)) { $recap_new = new AttendancePresencesRecap(); $recap_new->employee_id = $this->employee_id; $recap_new->shift_id = $this->shift_id; $recap_new->date = $this->date; $recap_new->location_id = $this->location_id; $recap_new->type = 'CI'; if ($this->type == 'CI') { $recap_new->check_in = $this->presence_date; } if ($this->type == 'BO') { $recap_new->break_out = $this->presence_date; } if ($this->type == 'BI') { $recap_new->break_in = $this->presence_date; } if ($this->type == 'CO') { $recap_new->check_out = $this->presence_date; } $recap_new->save(); } else { if ($this->type == 'CI') { $recap->check_in = $this->presence_date; } if ($this->type == 'BO') { $recap->break_out = $this->presence_date; } if ($this->type == 'BI') { $recap->break_in = $this->presence_date; } if ($this->type == 'CO') { $recap->check_out = $this->presence_date; } $recap->save(); } }
<?php $attendances = AttendancePresencesRecap::model()->findAllByAttributes(array('employee_id' => getUser()->employee_id)); $mutation_requests = MutationsRequest::model()->findAllByAttributes(array('employee_id' => Yii::app()->user->id)); ?> <div class="row"> <div class="col-md-7"> <!-- START SALES BLOCK --> <div class="panel panel-default"> <div class="panel-heading"> <div class="panel-title-box"> <h3><?php echo at('Attendance Presences'); ?> </h3> </div> </div> <div class="panel-body panel-body-table"> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th width="10%"><?php echo at('Date'); ?> </th> <th width="10%"><?php echo at('Shift');
public function actionBeritaacara_approve($id) { $request = AttendancePresencesRequest::model()->findByPk($id); $request->approved_by = 'admin'; $request->status = 'approved'; $recap = AttendancePresencesRecap::model()->findByAttributes(array('employee_id' => $request->employee_id, 'date' => $request->date, 'location_id' => $request->location_id)); if (count($recap) != 0) { $recap->check_in = $request->check_in; $recap->check_out = $request->check_out; $recap->break_out = $request->break_out; $recap->break_in = $request->break_in; $recap->save(); } else { $recap = new AttendancePresencesRecap(); $recap->employee_id = $request->employee_id; $recap->shift_id = $request->shift_id; $recap->date = $request->date; $recap->type = $request->type; $recap->check_in = $request->check_in; $recap->check_out = $request->check_out; $recap->break_out = $request->break_out; $recap->break_in = $request->break_in; $recap->location_id = $request->location_id; $recap->type = 'CI'; $recap->save(); } $request->save(); $this->render('beritaacara_view', array('model' => $request)); }
public function actionBeritaacara() { $model = new AttendancePresencesRequest(); $locations = CHtml::listData(MastersLocation::model()->findAll(), 'id', 'name'); $request = 0; if (isset($_GET['id'])) { $attendance = $this->loadModel($_GET['id']); $request = AttendancePresencesRequest::model()->findByAttributes(array('attendance_id' => $_GET['id'])); if (isset($attendance)) { $attendances = AttendancePresencesRecap::model()->findAllByAttributes(array('employee_id' => $attendance->employee_id, 'date' => $attendance->date)); } else { $attendances = AttendancePresencesRecap::model()->findAllByAttributes(array('employee_id' => $request->employee_id, 'date' => $request->date)); } if (count($request) != 0) { if ($request->status == 'draft' and $request->created_by = 'rm') { $model = $request; } else { $this->redirect(array('beritaacara_view', 'id' => $request->id)); } } $locations = array(); foreach ($attendances as $value) { $locations[$value->location_id] = $value->location->name; } } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AttendancePresencesRequest'])) { if (isset($_POST['yt0']) or isset($_POST['yt1']) or isset($_POST['yt2'])) { $model->attributes = $_POST['AttendancePresencesRequest']; if (isset($_POST['yt1'])) { $model->status = 'saved'; } if (isset($_POST['yt0']) and $_POST['yt0'] == 'Save') { $model->status = 'saved'; } $model->attendance_id = $_POST['attendance_id']; $break_out = '00:00:00'; $break_in = '00:00:00'; if (isset($_POST['AttendancePresencesRequest']['break_out'])) { $break_out = $_POST['AttendancePresencesRequest']['break_out']; $break_in = $_POST['AttendancePresencesRequest']['break_in']; } $check_in = $_POST['AttendancePresencesRequest']['check_in']; $check_out = $_POST['AttendancePresencesRequest']['check_out']; $date = $_POST['AttendancePresencesRequest']['date']; $model->check_in = $date . ' ' . $check_in; $model->check_out = $date . ' ' . $check_out; $model->break_out = $date . ' ' . $break_out; $model->break_in = $date . ' ' . $break_in; $model->created_by = getUser()->role; if ($model->save()) { $this->redirect(array('beritaacara_view', 'id' => $model->id)); } else { print_r($model->errors); } } else { $attendance = AttendancePresencesRecap::model()->findByAttributes(array('employee_id' => $_POST['AttendancePresencesRequest']['employee_id'], 'date' => $_POST['AttendancePresencesRequest']['date'], 'location_id' => $_POST['AttendancePresencesRequest']['location_id'])); } } if (isset($attendance)) { if (count($request) == 0) { $model->attributes = $attendance->attributes; } if (isset($_GET['request'])) { $model = AttendancePresencesRequest::model()->findByPk($_GET['request']); } } $model->check_in = substr($model->check_in, 10); $model->break_out = substr($model->break_out, 10); $model->break_in = substr($model->break_in, 10); $model->check_out = substr($model->check_out, 10); if ($model->check_in == null) { $model->check_in = '00:00:00'; } if ($model->break_out == null) { $model->break_out = '00:00:00'; } if ($model->break_in == null) { $model->break_in = '00:00:00'; } if ($model->check_out == null) { $model->check_out = '00:00:00'; } $attendance_id = 0; if (isset($_GET['id'])) { $attendance_id = $_GET['id']; } $this->render('beritaacara', array('model' => $model, 'locations' => $locations, 'attendance_id' => $attendance_id)); }