Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\modules\master\controllers;
- use Yii;
- use app\modules\master\models\EmployeeSalary;
- use app\modules\personnel\models\Employee;
- use app\modules\master\models\EmployeeSalarySearch;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- /**
- * EmployeeSalaryController implements the CRUD actions for EmployeeSalary model.
- */
- class EmployeeSalaryController extends Controller
- {
- /**
- * {@inheritdoc}
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
- /**
- * Lists all EmployeeSalary models.
- * @return mixed
- */
- public function actionIndex()
- {
- $searchModel = new EmployeeSalarySearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
- /**
- * Displays a single EmployeeSalary model.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- /**
- * Creates a new EmployeeSalary model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new EmployeeSalary();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- /**
- * Updates an existing EmployeeSalary model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- /**
- * Deletes an existing EmployeeSalary model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- public function actionImport(){
- $modelImport = new \yii\base\DynamicModel([
- 'fileImport'=>'File Import',
- ]);
- $modelImport->addRule(['fileImport'],'required');
- $modelImport->addRule(['fileImport'],'file',['extensions'=>'ods,xls,xlsx'],['maxSize'=>1024*1024]);
- if(Yii::$app->request->post()){
- $modelImport->fileImport = \yii\web\UploadedFile::getInstance($modelImport,'fileImport');
- if($modelImport->fileImport && $modelImport->validate()){
- $inputFileType = \PHPExcel_IOFactory::identify($modelImport->fileImport->tempName);
- $objReader = \PHPExcel_IOFactory::createReader($inputFileType);
- $objPHPExcel = $objReader->load($modelImport->fileImport->tempName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,true,true);
- $baseRow = 1;
- foreach ($sheetData as $value) {
- $employee_id = Employee::find()->select('id')->orWhere(['idcard1_number' => $value])->one()->id;
- // If set !empty, then empty row will be inserted
- if(!empty($value['A'])){
- $model = new EmployeeSalary();
- $model->employee_id = $employee_id;
- $model->nikppnpn = (string)$value['A'];
- $model->kode_bank = (string)$value['B'];
- $model->nama_bank = (string)$value['C'];
- $model->nama_rekening = (string)$value['D'];
- $model->save();
- $baseRow++;
- }
- }
- Yii::$app->getSession()->setFlash('success','Success');
- }else{
- Yii::$app->getSession()->setFlash('error','Error');
- }
- }
- return $this->render('import',[
- 'modelImport' => $modelImport,
- ]);
- }
- /**
- * Finds the EmployeeSalary model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return EmployeeSalary the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = EmployeeSalary::findOne($id)) !== null) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement