/**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $this->title = 'Rincian UP';
     //UP model detail view
     $model = $this->loadModel($id);
     $userId = Yii::app()->user->id;
     $user = User::model()->findByPk($userId);
     //UPDetail model Gridview
     $modelDetail = new UpDetail('searchDetail');
     $modelDetail->unsetAttributes();
     if (isset($_GET['UpDetail'])) {
         $modelDetail->attributes = $_GET['UpDetail'];
     }
     //Create new UPDetail
     $newDetail = new UpDetail();
     $this->performAjaxValidation($newDetail);
     if (isset($_POST['UpDetail'])) {
         if ($_POST['UpDetail']['limit'] == NULL && $_POST['UpDetail']['package_code'] == NULL) {
             Yii::app()->user->setFlash('error', 'Mohon isikan data pada form.');
         } else {
             $detailLimit = $_POST['UpDetail']['limit'];
             $packageCode = $_POST['UpDetail']['package_code'];
             $checkDetail = UpDetail::model()->findByAttributes(array('up_number_of_letter' => "{$model->number_of_letter}", 'package_code' => "{$packageCode}"));
             $package = Package::model()->findByAttributes(array('code' => $packageCode));
             $detailLists = UpDetail::model()->findAllByAttributes(array('up_number_of_letter' => $model->number_of_letter));
             $total = 0;
             if ($detailLists) {
                 foreach ($detailLists as $detailList) {
                     $total += $detailList->limit;
                 }
             }
             $totalNewLimit = $total + $detailLimit;
             if ($checkDetail) {
                 Yii::app()->user->setFlash('error', 'Paket sudah digunakan dalam UP');
             } elseif ($detailLimit > $package->limit) {
                 Yii::app()->user->setFlash('error', 'Pagu UP Detail tidak boleh melebihi pagu paket');
             } elseif ($totalNewLimit > $model->total_up) {
                 Yii::app()->user->setFlash('error', 'Pagu UP Detail tidak boleh melebihi pagu UP');
             } else {
                 $newDetail->attributes = $_POST['UpDetail'];
                 $newDetail->up_number_of_letter = $model->number_of_letter;
                 if ($newDetail->save()) {
                     //Update package account UP status from "LS" to "UP"
                     $packagesAccounts = PackageAccount::model()->findAllByAttributes(array('package_code' => $newDetail->package_code));
                     foreach ($packagesAccounts as $packagesAccount) {
                         $packagesAccount->up = "UP";
                         $packagesAccount->update();
                     }
                     Yii::app()->user->setFlash('success', 'Detail berhasil ditambahkan');
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             }
         }
     }
     $this->render('view', array('model' => $model, 'modelDetail' => $modelDetail, 'addDetail' => $newDetail, 'user' => $user));
 }
 /**
  * Updata package_account data after editable column successfully updated
  */
 public function actionChildUpdate()
 {
     $code = $_GET['code'];
     $provinceCode = $_GET['provinceCode'];
     $cityCode = $_GET['cityCode'];
     $ppkCode = $_GET['ppkCode'];
     $models = PackageAccount::model()->findAllByAttributes(array('package_code' => "{$code}"));
     if ($models) {
         foreach ($models as $model) {
             $model->province_code = $provinceCode;
             $model->city_code = $cityCode;
             $model->ppk_code = $ppkCode;
             $model->update();
         }
     }
 }
 public function actionTableReport()
 {
     $data = Satker::model()->findByAttributes(array('code' => '622280'));
     $ppk = array();
     $limit = array();
     $realization = array();
     $rate = array();
     $countData = array();
     $ratePpk = array();
     $limitPpk = array();
     $totalRealPpk = array();
     if ($data) {
         $packageAccount = PackageAccount::model()->findAllByAttributes(array('satker_code' => "{$data->code}"));
         $countData[$data->code] = 0;
         $limit[$data->code] = 0;
         $realization[$data->code] = 0;
         $rate[$data->code] = 0;
         if ($packageAccount) {
             $countData[$data->code] = count($packageAccount);
             foreach ($packageAccount as $pa) {
                 $limit[$data->code] += $pa->limit;
                 $realData = Realization::model()->findAllByAttributes(array('packageAccount_code' => "{$data->code}"));
                 $totalRealization = 0;
                 if ($realData) {
                     foreach ($realData as $r) {
                         $totalRealization += $r->total_spm;
                     }
                 }
                 $realization[$data->code] += $totalRealization;
             }
         }
         if ($limit[$data->code] != 0) {
             $rate[$data->code] = $realization[$data->code] / $limit[$data->code] * 100;
         }
         $ppks = Ppk::model()->findAll();
         if ($ppks) {
             foreach ($ppks as $ppk) {
                 $paPpk = PackageAccount::model()->findAllByAttributes(array('ppk_code' => "{$ppk->code}"));
                 $limitPpk[$ppk->code] = 0;
                 $ratePpk[$ppk->code] = 0;
                 $totalRealPpk[$ppk->code] = 0;
                 if ($paPpk) {
                     foreach ($paPpk as $p) {
                         $limitPpk[$ppk->code] += $p->limit;
                         $realPpk = Realization::model()->findAllByAttributes(array('packageAccount_code' => "{$p->code}"));
                         $realizationPpk = 0;
                         if ($realPpk) {
                             foreach ($realPpk as $dataReal) {
                                 $realizationPpk += $dataReal->total_spm;
                             }
                         }
                         $totalRealPpk[$ppk->code] += $realizationPpk;
                     }
                     if ($limitPpk != 0) {
                         $ratePpk[$ppk->code] = $totalRealPpk[$ppk->code] / $limitPpk[$ppk->code] * 100;
                     }
                 }
             }
         }
     }
     echo $data->name . "</br>";
     echo $limit[$data->code] . "</br>";
     echo $realization[$data->code] . "</br>";
     //        $this->title = 'Tabel Penggunaan Anggaran';
     //        $say = 'Ini adalah page report penggunaan anggaran';
     //        $this->render('tableReport', array(
     //            'say' => $say,
     //        ));
 }
Esempio n. 4
0
 public function getTotal($code)
 {
     $totalRealization = 0;
     $totalRestMoney = 0;
     $usingRate = 0;
     //        Calculate total realization for each package
     $models = Realization::model()->findAllByAttributes(array('package_code' => "{$code}"));
     if ($models) {
         foreach ($models as $model) {
             $totalRealization += $model->total_spm;
         }
     }
     //        Calculate total realization for each package
     //Get Package Limit
     $packageAccounts = PackageAccount::model()->findAllByAttributes(array('package_code' => "{$code}"));
     $limit = 0;
     if ($packageAccounts) {
         foreach ($packageAccounts as $data) {
             $limit += $data->limit;
         }
     }
     //Get Package Limit
     $totalRestMoney = $limit - $totalRealization;
     $rate = $totalRealization / $limit;
     $usingRate = round($rate, 4);
     return array('limit' => $limit, 'realization' => $totalRealization, 'restMoney' => $totalRestMoney, 'rate' => $usingRate);
 }
 public function exportExcel($objPHPExcel, $models)
 {
     $sheet = $objPHPExcel->getActiveSheet();
     $sheet->setCellValueExplicit('A2', "Tanggal:  " . date('j F Y'), PHPExcel_Cell_DataType::TYPE_STRING);
     $row = 3;
     if ($models) {
         foreach ($models as $model) {
             $sheet->setCellValueExplicit('A' . ++$row, isset($model->code) ? $model->code : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValueExplicit('B' . $row, isset($model->satker_code) ? $model->satker_code : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValueExplicit('C' . $row, isset($model->activity_code) ? str_replace($model->satker_code . '.', '', $model->activity_code) : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValueExplicit('D' . $row, isset($model->output_code) ? str_replace($model->activity_code . '.', '', $model->output_code) : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValueExplicit('E' . $row, isset($model->suboutput_code) ? str_replace($model->output_code . '.', '', $model->suboutput_code) : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValueExplicit('F' . $row, isset($model->component_code) ? str_replace($model->suboutput_code . '.', '', $model->component_code) : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValueExplicit('G' . $row, isset($model->package_code) ? str_replace($model->component_code . '.', '', $model->package_code) : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValueExplicit('H' . $row, isset($model->account_code) ? $model->account_code : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
             $sheet->setCellValue('I' . $row, isset($model->limit) ? $model->limit : NULL);
             $realization = PackageAccount::model()->getTotal($model->code)['realization'];
             $sheet->setCellValue('J' . $row, $realization);
             $sheet->setCellValueExplicit('K' . $row, isset($model->ppk_code) ? $model->ppk->official_name : NULL, PHPExcel_Cell_DataType::TYPE_STRING);
         }
     }
     $objPHPExcel->getActiveSheet()->setTitle('Laporan');
 }
 /**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = PackageAccount::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Clear all DIPA, Budget, Package, Account Package, and Realization data from database record
  */
 public function actionClear()
 {
     //Check record data on database
     $realization = Realization::model()->exists();
     $packageAccount = PackageAccount::model()->exists();
     $package = Package::model()->exists();
     $budget = Budget::model()->exists();
     $dipa = Dipa::model()->exists();
     //Clear data
     if ($realization) {
         //Truncate realization table on anggaran database
         Yii::app()->db->createCommand()->truncateTable(Realization::model()->tableName());
     }
     if ($packageAccount) {
         //Truncate package_account table on anggaran database
         Yii::app()->db->createCommand()->truncateTable(PackageAccount::model()->tableName());
     }
     if ($package) {
         //Truncate package table on anggaran database
         Yii::app()->db->createCommand()->truncateTable(Package::model()->tableName());
     }
     if ($budget) {
         //Truncate budget table on anggaran database
         Yii::app()->db->createCommand()->truncateTable(Budget::model()->tableName());
     }
     if ($dipa) {
         //Truncate dipa table on anggaran database
         Yii::app()->db->createCommand()->truncateTable(Dipa::model()->tableName());
     }
     //Redirect to DIPA index page
     Yii::app()->user->setFlash('success', 'Data berhasil dibersihkan. </br> Anda dapat memasukkan anggaran baru.');
     $this->redirect(array('index'));
 }
 public function actionGetPackageAccountOptionsCodeName()
 {
     echo json_encode(PackageAccount::model()->getOptionsCodeName());
 }
 public function getOptionsCodeName()
 {
     $models = PackageAccount::model()->findAll();
     $options = array();
     foreach ($models as $model) {
         $name = $model->package->name;
         $options[$model->code] = "[{$model->code}] | {$name}" . ' - ' . $model->account->name;
     }
     return $options;
 }
    <thead>
        <tr>
            <th>Kode Akun Paket </th>
            <th>Total SPM</th>
            <th>Nomor SPM</th>
            <th>Tanggal SPM</th>
            <th>UP/LS</th>
        </tr>
    </thead>
    <tbody>
        <?php 
if ($model->packageAccount_code == null) {
    ?>
            <tr>
                <td><?php 
    echo CHtml::dropDownList('packageAccount_code[]', "string", PackageAccount::model()->getOptionsCodeName(), array('prompt' => 'Pilih', 'type' => 'selc', 'onfocus' => 'removeDuplicate()'));
    ?>
 </td>
                <td><?php 
    echo CHtml::textField('total_spm[]');
    ?>
 </td>
                <td><?php 
    echo CHtml::textField('spm_number[]');
    ?>
 </td>
                <!--date picker belum nemu naroh chtml nya-->
                <td><?php 
    echo CHtml::textField('spm_date[]', '', array('placeholder' => "format:yyyy-mm-dd, ex:2015-08-30"));
    ?>
 </td>