Ejemplo n.º 1
0
 public function actionAdmin()
 {
     $sukses = false;
     $gagal = false;
     $alreadySlip = false;
     $slipExists = false;
     $loadModelFirstname = $this->loadModelFirstname();
     if (isset($_POST['Listgaji'])) {
         Yii::import('ext.phpexcelreader.JPhpExcelReader');
         $model = new Listgaji();
         $model->attributes = $_POST['Listgaji'];
         $fileUpload = CUploadedFile::getInstance($model, 'filee');
         $path = Yii::getPathOfAlias('webroot') . '/FileExcel/' . $fileUpload;
         $fileUpload->saveAs($path);
         if (!file_exists($path)) {
             die('File could not be found at: ' . $path);
         }
         $data = new JPhpExcelReader($path);
         $baris = $data->rowcount($sheet_index = 0);
         $sukses = 0;
         $gagal = 0;
         $alreadySlip = 0;
         for ($i = 2; $i <= $baris; $i++) {
             for ($n = 1; $n <= 31; $n++) {
                 $rowData[$n] = str_replace(",", "", $data->val($i, $n));
                 if ($rowData[$n] == null or $rowData[$n] == '') {
                     $rowData[$n] = 0;
                 }
             }
             $command = Yii::app()->db->createCommand();
             if (Listgaji::model()->findByAttributes(array('noSlipGaji' => $rowData[1] . $rowData[2] . $rowData[3])) != null) {
                 $alreadySlip++;
                 $slipExists[$rowData[1] . $rowData[2] . $rowData[3]] = $rowData[1] . $rowData[2] . $rowData[3];
             } else {
                 try {
                     $command->insert('listgaji', array('noSlipGaji' => $rowData[1] . $rowData[2] . $rowData[3], 'year' => $rowData[1], 'month' => $rowData[2], 'nip' => $rowData[3], 'workdays' => $rowData[4], 'grossSalary' => $rowData[5], 'fixAllowance' => $rowData[6], 'meal' => $rowData[7], 'transport' => $rowData[8], 'pulse' => $rowData[9], 'medicalAllowance' => $rowData[10], 'overtime' => $rowData[11], 'bonus' => $rowData[12], 'thr' => $rowData[13], 'correctionPlus' => $rowData[14], 'incentive' => $rowData[15], 'jobAllowance' => $rowData[16], 'marriageAllowance' => $rowData[17], 'houseAllowance' => $rowData[18], 'taskForceAllowance' => $rowData[19], 'maternityAllowance' => $rowData[20], 'glassesAllowance' => $rowData[21], 'condolanceAllowance' => $rowData[22], 'separationPay' => $rowData[23], 'opex' => $rowData[24], 'coc' => $rowData[25], 'pph21' => $rowData[26], 'bpjs' => $rowData[27], 'jamsostek' => $rowData[28], 'benefitMin' => $rowData[29], 'copAllowanceMin' => $rowData[30], 'loan' => $rowData[31], 'state' => 'Y', 'createdTimeStamp' => date('Y-m-d H:i:s'), 'createdBy' => Yii::app()->user->Id));
                     $sukses++;
                 } catch (Exception $e) {
                     $gagal++;
                 }
             }
         }
         unlink($path);
     }
     $date = date('Y-m-d');
     $dateStamp = Yii::app()->db->createCommand()->select('count(id)')->from('listgaji')->where('substr(createdTimeStamp,1,10)=:date', array(':date' => $date))->queryRow();
     $model = new Listgaji('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['Listgaji'])) {
         $model->attributes = $_GET['Listgaji'];
     }
     $this->render('admin', array('model' => $model, 'loadModelFirstname' => $loadModelFirstname, 'sukses' => $sukses, 'gagal' => $gagal, 'alreadySlip' => $alreadySlip, 'slipExists' => $slipExists, 'dateStamp' => $dateStamp));
 }
Ejemplo n.º 2
0
 /**
  * Manages all models.
  */
 public function actionAdmin()
 {
     if (isset($_GET['updatePassword'])) {
         $updatePass = "******" . TbHtml::alert(TbHtml::ALERT_COLOR_SUCCESS, 'Well Done! You Successfully update password user!') . "</div>";
     } else {
         $updatePass = '';
     }
     $sukses = false;
     $gagal = false;
     $alreadyUser = false;
     $userExists = false;
     if (isset($_POST['User'])) {
         Yii::import('ext.phpexcelreader.JPhpExcelReader');
         $model = new User();
         $model->attributes = $_POST['User'];
         $fileUpload = CUploadedFile::getInstance($model, 'filee');
         $path = Yii::getPathOfAlias('webroot') . '/FileExcel/' . $fileUpload;
         if ($fileUpload == '') {
             die('Please Insert File Excel 2003 with format template! ');
         }
         if (substr($path, -3, 3) != 'xls') {
             die('Please Insert File Excel 2003! ');
         }
         $fileUpload->saveAs($path);
         if (!file_exists($path)) {
             die('File could not be found at: ' . $path);
         }
         $data = new JPhpExcelReader($path);
         $baris = $data->rowcount($sheet_index = 0);
         $sukses = 0;
         $gagal = 0;
         $alreadyUser = 0;
         for ($i = 2; $i <= $baris; $i++) {
             for ($n = 1; $n <= 14; $n++) {
                 $rowData[$n] = str_replace(",", "", $data->val($i, $n));
             }
             $command = Yii::app()->db->createCommand();
             if (User::model()->findByAttributes(array('username' => $rowData[1])) != null) {
                 $alreadyUser++;
                 $userExists[$rowData[1]] = $rowData[1];
             } else {
                 try {
                     $command->insert('users', array('username' => $rowData[1], 'password' => Yii::app()->controller->module->encrypting($rowData[14]), 'email' => $rowData[1] . '@morena.co.id', 'create_at' => date('Y-m-d H:i:s'), 'status' => 1));
                     $idUsersCreate = User::model()->findByAttributes(array('username' => $rowData[1]));
                     $command->insert('profiles', array('user_id' => $idUsersCreate->id, 'nip' => $rowData[1], 'firstname' => $rowData[2], 'lastname' => $rowData[3], 'birthdate' => $rowData[4], 'address' => $rowData[5], 'location' => $rowData[6], 'position' => $rowData[7], 'departement' => $rowData[8], 'class' => $rowData[9], 'joinDate' => $rowData[10], 'hireDate' => $rowData[11], 'state' => $rowData[12], 'marriageStatus' => $rowData[13]));
                     $command->insert('authassignment', array('itemname' => 'employee', 'userid' => $idUsersCreate['id']));
                     $sukses++;
                 } catch (Exception $e) {
                     $gagal++;
                 }
             }
         }
         unlink($path);
     }
     $model = new User('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['User'])) {
         $model->attributes = $_GET['User'];
     }
     $this->render('index', array('model' => $model, 'sukses' => $sukses, 'gagal' => $gagal, 'alreadyUser' => $alreadyUser, 'userExists' => $userExists, 'updatePass' => $updatePass));
     /*$dataProvider=new CActiveDataProvider('User', array(
     			'pagination'=>array(
     				'pageSize'=>Yii::app()->controller->module->user_page_size,
     			),
     		));
     
     		$this->render('index',array(
     			'dataProvider'=>$dataProvider,
     		));//*/
 }