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();
     }
 }
 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));
 }
Example #3
0
<?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()
 {
     $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));
 }
 public function afterSave()
 {
     if ($this->status == 'approved') {
         $recap = new AttendancePresencesRecap();
         $recap->employee_id = $this->employee_id;
         $recap->shift_id = $this->shift_id;
         $recap->date = $this->date;
         $recap->location_id = $this->location_id;
         $recap->type = 'OFF';
         if (!$recap->save()) {
             print_r($recap->errors);
             die;
         }
         $this->sendMail('template_attendance_off_approve');
     } elseif ($this->status == 'saved') {
         $this->sendMail('template_attendance_off_request');
     } elseif ($this->status == 'rejected') {
         $this->sendMail('template_attendance_off_reject');
     }
 }
 public function savePresence()
 {
     $long_date = strtotime($this->end_date) - strtotime($this->start_date);
     $count_day = $long_date / 86400;
     for ($i = 0; $i <= $count_day; $i++) {
         $date = strtotime($this->start_date) + 86400 * $i;
         $presence = new AttendancePresencesRecap();
         $presence->employee_id = $this->employee_id;
         $presence->date = date('Y-m-d', $date) . "<br>";
         if ($this->type == 'Normal') {
             $presence->type = 'P';
             $presence->permit = date('Y-m-d');
         } elseif ($this->type == 'Sick') {
             if ($this->doctor_note == 1) {
                 $presence->type = 'S';
                 $presence->sick = date('Y-m-d');
             } elseif ($this->doctor_note == 0) {
                 $presence->type = 'SN';
                 $presence->sickwithoutmail = date('Y-m-d');
             }
         }
         $presence->save();
     }
 }