/
EmployeesController.php
355 lines (292 loc) · 8.63 KB
/
EmployeesController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
class EmployeesController extends BackEndController
{
public $icon_class = 'glyphicon glyphicon-user';
public function init() {
parent::init();
// Check Access
checkAccessThrowException('op_masters_employees_view');
// Add Breadcrumb
$this->addBreadCrumb(at('Employees'));
$this->title[] = at('Employees');
}
public function actionTes()
{
$employees = MastersEmployees::model()->findAll();
foreach ($employees as $key => $value) {
$value->code = '0'.$value->code;
$value->save();
}
}
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new MastersEmployees;
$modelPhoto = new ImportForm;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['MastersEmployees']))
{
$model->attributes=$_POST['MastersEmployees'];
if($model->save())
{
if(isset($_POST['ImportForm'])){
$modelPhoto->attributes=$_POST['ImportForm'];
$imgFile = CUploadedFile::getInstance($modelPhoto, 'file');
//$imgFile->saveAs(profilePaths.$model->code.'.jpg');
}
$this->redirect(array('update','id'=>$model->id));
}
} else {
$model->type_id = 2; //Probation 1
}
$this->render('create',array(
'model' => $model,
'modelPhoto' => $modelPhoto,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$modelPhoto = new ImportForm;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['MastersEmployees']))
{
$model->attributes = $_POST['MastersEmployees'];
if($model->save())
{
if(isset($_POST['ImportForm'])){
$modelPhoto->attributes=$_POST['ImportForm'];
$imgFile = CUploadedFile::getInstance($modelPhoto, 'file');
if(isset($imgFile)) $imgFile->saveAs(profilePaths().$model->code.'.jpg');
}
$this->redirect(array('update','id'=>$model->id));
}
}
if(isset($_GET['tab']))$select_tab = $_GET['tab'];
else $select_tab = 0;
$this->render('update',array(
'model' => $model,
'modelPhoto' => $modelPhoto,
'select_tab' => $select_tab,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
/**
* Manages all models.
*/
public function actionIndex()
{
$model=new MastersEmployees('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['MastersEmployees']))
$model->attributes=$_GET['MastersEmployees'];
$this->render('index',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return MastersEmployees the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = MastersEmployees::model()->findByPk($id);
if($model===null) throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX validation.
* @param MastersEmployees $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='masters-employees-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
public function actionDynamicStatuses($id)
{
$c = new CDbCriteria();
$c->compare('family_group_id', $id);
$model = ReferenceFamilyStatuses::model()->findAll($c);
echo CHtml::tag('option', array('value'=>''), '', true);
foreach($model as $status)
{
echo CHtml::tag('option', array('value'=>$status->id), CHtml::encode($status->name), true);
}
}
public function actionChooseList()
{
$model=new MastersEmployees('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['MastersEmployees']))
$model->attributes=$_GET['MastersEmployees'];
$this->renderPartial('chooselist',array(
'model'=>$model,
),false,true);
Yii::app()->end();
}
public function actionSelect($id)
{
$model = MastersEmployees::model()->findByPk($id);
echo CJSON::encode(array
(
'id' => $model->primaryKey,
'name' => $model->getFullName(),
'dept_id' => $model->department_id,
));
Yii::app()->end();
}
public function actionPromotion($id)
{
$model = MastersEmployees::model()->findByPk($id);
if(isset($_POST['duallistbox_outlets']))
{
print_r($_POST['duallistbox_outlets']);
}
$this->render('promotion',array(
'model'=>$model,
));
}
public function actionChooseaa()
{
$model = MastersEmployees::model()->findByPk(1);
echo $model->getFullName();
}
public function actionSelectlist()
{
$model=new MastersEmployees('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['MastersEmployees']))
$model->attributes=$_GET['MastersEmployees'];
$this->renderPartial('selectlist',array(
'model'=>$model,
), false, true);
}
public function actionMutation($id)
{
$model = MutationsRequest::model()->find(array(
'condition' => 'employee_id = '.$id.' and status <> "rejected" and active_date > Now()'
));
if(!isset($model)) $model = new MutationsRequest;
else $this->redirect(array('mutation_view','id'=>$model->id));
$model->fill($id);
if(isset($_POST['MutationsRequest']))
{
// echo $_POST['MutationsRequest']['action']; die();
$model->attributes = $_POST['MutationsRequest'];
$model->status = 'approved';
if($_POST['action']=='draft')
{
$model->status = 'draft';
}
else
{
$model->approved_by = getUser()->role;
$model->approved_at = date('Y-m-d h:i:s');
}
if($model->save()) $this->redirect(array('mutation_view','id'=>$model->id));
}
$this->render('mutation',array(
'model'=>$model,
));
}
public function actionMutation_view($id)
{
$model = MutationsRequest::model()->findByPk($id);
$this->render('mutation_view',array(
'model'=>$model,
));
}
public function actionMutation_approve($id)
{
$model = MutationsRequest::model()->findByPk($id);
$model->status = 'approved';
$model->approved_by = getUser()->role;
$model->approved_at = date('Y-m-d h:i:s');
$model->save();
$this->redirect(array('mutation_view','id'=>$id));
}
public function actionMutation_cancel($id)
{
$model = MutationsRequest::model()->findByPk($id);
$model->status = 'rejected';
$model->canceled_by = getUser()->role;
$model->canceled_at = date('Y-m-d h:i:s');
$model->save();
$this->redirect(array('mutation_view','id'=>$id));
}
public function actionMutation_update($id)
{
$model = MutationsRequest::model()->findByPk($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['MutationsRequest']))
{
$model->attributes = $_POST['MutationsRequest'];
$model->status = 'approved';
$model->approved_by = getUser()->role;
$model->approved_at = date('Y-m-d h:i:s');
if($model->save())
$this->redirect(array('mutation_view','id'=>$id));
}
$this->render('mutation_update',array(
'model'=>$model,
));
}
public function actionRotation($id)
{
$model = MutationsRequest::model()->findByAttributes(array('employee_id'=>$id,'status'=>'request'));
if(!isset($model)) $model = new MutationsRequest;
else $this->redirect(array('mutation_view','id'=>$model->id));
$model->fill($id);
$model->is_rotation();
if(isset($_POST['MutationsRequest']))
{
$model->attributes = $_POST['MutationsRequest'];
$model->status = 'approved';
$model->approved_by = getUser()->role;
$model->approved_at = date('Y-m-d h:i:s');
if($model->save()) $this->redirect(array('mutation_view','id'=>$model->id));
}
$this->render('mutation',array(
'model'=>$model,
));
}
}