Esempio 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));
 }
Esempio n. 2
0
 public function actionImportExcel()
 {
     error_reporting(E_ALL ^ E_NOTICE);
     $model = new Nilai();
     if (isset($_POST['Nilai'])) {
         $bulan = date('m');
         if ($bulan < 7) {
             $smt2 = 2;
             //jika th 2(1-6) maka tahun-1/tahun-2 2012/2013
             $th_ajar2 = date('Y') - 1 . '/' . date('Y');
         } elseif ($bulan < 13 && $bulan > 6) {
             $smt2 = 1;
             //jika th 1(7-12) maka tahun/tahun+1 2012/2013
             $th_ajar2 = date('Y') . '/' . (date('Y') + 1);
         }
         Yii::import('ext.ocim.excelread.JPhpExcelReader');
         $model->attributes = $_POST['Nilai'];
         if (strlen(trim(CUploadedFile::getInstance($model, 'filee'))) > 0) {
             //Proses upload dan rename file menjadi Karyawan.xls
             $unggah = CUploadedFile::getInstance($model, 'filee');
             $path = Yii::app()->getBasePath() . '/extensions/ocim/excelread/nilai.xls';
             $unggah->saveAs($path);
             //$data = new Spreadsheet_Excel_Reader($path);
             $data = new JPhpExcelReader($path);
             $nis = array();
             $kode_mapel = array();
             $kode_guru = array();
             $kelas = array();
             $lokal = array();
             $na = array();
             $un = array();
             $uas = array();
             $kurikulum = array();
             $th_ajar = array();
             $semester = array();
             $kodemapel = array();
             $setkurikulum = array();
             //Pembacaan coloumb ex: A, B, C (Horizontal)
             for ($j = 1; $j <= $data->sheets[0]['numRows']; $j++) {
                 //nama sheet(dimulai dari 0,1,dst) | array (jumlah row yang dibaca. Vertikal) | coloumb ke.. (Horizontal)
                 $nis[$j] = $data->sheets[0]['cells'][$j][2];
                 //Ini 2
                 $kelas[$j] = $data->sheets[0]['cells'][$j][4];
                 //Ini 4
                 $lokal[$j] = $data->sheets[0]['cells'][$j][5];
                 //Ini 5
                 $kode_mapel[$j] = $data->sheets[0]['cells'][$j][6];
                 //ini 6
                 $na[$j] = $data->sheets[0]['cells'][$j][7];
                 //Ini 7
                 $un[$j] = $data->sheets[0]['cells'][$j][8];
                 //Ini 8
                 $uas[$j] = $data->sheets[0]['cells'][$j][9];
                 //Ini 9
                 $th_ajar[$j] = $th_ajar2;
                 $semester[$j] = $smt2;
                 $kodemapel[$j] = Yii::app()->user->id;
                 $setkurikulum[$j] = Yii::app()->db->createCommand("select kurikulum from jadwal where kode_guru='" . Yii::app()->user->id . "' limit 1;")->queryScalar();
             }
             $aku = $data->rowcount(0);
             $rowExist = array();
             //try {
             //if($aku){
             //mengambil data dari row ke A2 ke bawah sampai data file habis karena di baca oleh variabel aku dengan sintaks "rowcount" (menghitung jumlah row yang ada isinya)
             for ($i = 2; $i <= $aku; $i++) {
                 $isExist = Nilai::model()->exists(array('condition' => 'nis = :nis AND kode_mapel = :kode_mapel AND th_ajar = :th_ajar AND semester = :semester', 'params' => array(':nis' => (string) $nis[$i], ':kode_mapel' => $kode_mapel[$i], ':th_ajar' => $th_ajar[$i], ':semester' => (string) $semester[$i])));
                 if ($isExist) {
                     $rowExist[] = array('nis' => $nis[$i], 'kode_mapel' => $kode_mapel[$i], 'th_ajar' => $th_ajar[$i], 'semester' => $semester[$i]);
                     $a = 0;
                 } else {
                     $model = new Nilai();
                     $model->nis = $nis[$i];
                     //2
                     $model->kelas = $kelas[$i];
                     //4
                     $model->lokal = $lokal[$i];
                     //5
                     $model->kode_mapel = $kode_mapel[$i];
                     //6
                     $model->na = $na[$i];
                     //7
                     $model->un = $un[$i];
                     //8
                     $model->uas = $uas[$i];
                     //9
                     $model->th_ajar = $th_ajar[$i];
                     $model->semester = $semester[$i];
                     //Deklarasi default
                     $model->kode_guru = $kodemapel[$i];
                     $model->kurikulum = $setkurikulum[$i];
                     /*echo "<pre>";
                     		print_r($model->getAttributes());
                     		echo "</pre>";
                     		die();*/
                     $model->save();
                 }
             }
             if ($a == 0) {
                 Yii::app()->user->setFlash('error', '<strong>Beberapa data sudah ada dalam database.</strong> Silahkan periksa kembali.');
                 //$this->redirect(array('admin'));
             } else {
                 Yii::app()->user->setFlash('success', 'Data <strong>berhasil</strong> di unggah. Terima kasih');
             }
             unlink($path);
             //}
             /*}
             		catch(CDbException $e) {
             			Yii::app()->user->setFlash('warning', '<strong>Data sudah ada dalam database.</strong> Silahkan periksa kembali.');
             			$model->addError(null, "Data sudah ada dalam database. Silahkan periksa kembali");
             		}*/
         } else {
             Yii::app()->user->setFlash('error', 'Data <strong>gagal</strong> di unggah. Silahkan periksa file anda.');
         }
     }
     $this->render('ImportExcel', array('model' => $model, 'rowExist' => $rowExist));
 }
Esempio n. 3
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,
     		));//*/
 }