/**
  * Input multiple data to database
  */
 public function actionEntry()
 {
     $model = new Package();
     $lastDipa = Dipa::model()->find(array('order' => 'id DESC'));
     $lastDipaId = $lastDipa->id;
     if (isset($_POST['code'])) {
         if ($lastDipa) {
             $total = count($_POST['code']);
             for ($i = 0; $i < $total; $i++) {
                 if ($_POST['code'][$i] != NULL && $_POST['ppk_code'][$i] != NULL && $_POST['city_code'][$i] != NULL) {
                     $code = $_POST['code'][$i];
                     //Check existed record
                     $record = Package::model()->findByAttributes(array('code' => $code));
                     if ($record) {
                         $budgets = Budget::model()->findAllByAttributes(array('subcomponent_code' => "{$record->code}", 'dipa_id' => "{$lastDipaId}"));
                         $record->ppk_code = $_POST['ppk_code'][$i];
                         $record->city_code = $_POST['city_code'][$i];
                         $record->province_code = City::model()->findByAttributes(array('code' => "{$record->city_code}"))->province_code;
                         if ($budgets) {
                             foreach ($budgets as $budgetData) {
                                 $pAccount = PackageAccount::model()->findByAttributes(array('code' => "{$budgetData->code}"));
                                 if ($pAccount) {
                                     $pAccount->limit = $budgetData->total_budget_limit;
                                     $pAccount->ppk_code = $record->ppk_code;
                                     $pAccount->province_code = $record->province_code;
                                     $pAccount->city_code = $record->city_code;
                                     $pAccount->update();
                                 }
                             }
                         }
                         $record->update();
                     } else {
                         $data = new Package();
                         $data->code = $_POST['code'][$i];
                         $budget = Budget::model()->findByAttributes(array('subcomponent_code' => $_POST['code'][$i]), array('order' => 'dipa_id DESC'));
                         if ($budget) {
                             $data->satker_code = "{$budget->satker_code}";
                             $data->activity_code = "{$budget->activity_code}";
                             $data->output_code = "{$budget->output_code}";
                             $data->suboutput_code = "{$budget->suboutput_code}";
                             $data->name = $budget->subcomponentCode->name;
                             $data->component_code = "{$budget->component_code}";
                             $data->ppk_code = $_POST['ppk_code'][$i];
                             $data->city_code = $_POST['city_code'][$i];
                             $data->province_code = City::model()->findByAttributes(array('code' => "{$data->city_code}"))->province_code;
                             $budgets = Budget::model()->findAllByAttributes(array('subcomponent_code' => "{$data->code}", 'dipa_id' => "{$lastDipaId}"));
                             if ($budgets) {
                                 foreach ($budgets as $dataBudget) {
                                     $paModel = new PackageAccount();
                                     $paModel->code = "{$dataBudget->code}";
                                     $paModel->satker_code = "{$dataBudget->satker_code}";
                                     $paModel->activity_code = "{$dataBudget->activity_code}";
                                     $paModel->output_code = "{$dataBudget->output_code}";
                                     $paModel->suboutput_code = "{$dataBudget->suboutput_code}";
                                     $paModel->component_code = "{$dataBudget->component_code}";
                                     $paModel->package_code = "{$dataBudget->subcomponent_code}";
                                     $paModel->account_code = "{$dataBudget->account_code}";
                                     $paModel->ppk_code = "{$data->ppk_code}";
                                     $paModel->province_code = "{$data->province_code}";
                                     $paModel->city_code = "{$data->city_code}";
                                     $paModel->limit = "{$dataBudget->total_budget_limit}";
                                     $paModel->save();
                                 }
                             }
                             $data->save();
                         } else {
                             Yii::app()->user->setFlash('notice', 'Data DIPA belum diinput dengan lengkap. Beberapa data informasi tambahan gagal ditambahkan.');
                             $this->redirect(array('index'));
                         }
                     }
                 } else {
                     Yii::app()->user->setFlash('error', "Mohon isikan data secara lengkap.");
                     $this->redirect(array('entry'));
                 }
             }
         } else {
             Yii::app()->user->setFlash('error', 'Data DIPA/POK belum diinput.');
             $this->redirect(array('index'));
         }
         Yii::app()->user->setFlash('success', 'Data berhasil disimpan.');
         $this->redirect(array('index'));
     }
     $this->render('entry', array('model' => $model));
 }
Example #2
0
 public function getBudgetForDipaOptions()
 {
     $models = Budget::model()->findAll();
     $options = array();
     foreach ($models as $model) {
         $subcomponent = Subcomponent::model()->findByAttributes(array('code' => $model->subcomponent_code));
         if ($subcomponent) {
             $options[$model->code] = "[ {$model->code} ] | {$subcomponent->name}";
         } else {
             $options[$model->code] = "[ {$model->code} ]";
         }
     }
     return $options;
 }
Example #3
0
 public function getTotal($id)
 {
     $budgets = Budget::model()->findAllByAttributes(array('dipa_id' => $id));
     $total = 0;
     if ($budgets) {
         foreach ($budgets as $budget) {
             $total += $budget->total_budget_limit;
         }
     }
     return $total;
 }
Example #4
0
 /**
  * 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 Budget the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Budget::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Compare old budget with new budget temp structure
  * Part of check structure validation
  * @param type $code
  * @return boolean
  */
 public function addedRecords($code)
 {
     $added = TRUE;
     //Check Existing of Budget Record
     $dipa = Dipa::model()->find(array('order' => 'id DESC'));
     if ($dipa) {
         $dipaId = $dipa->id;
         $budget = Budget::model()->findByAttributes(array('code' => $code, 'dipa_id' => $dipaId));
         if ($budget) {
             $added = FALSE;
         }
     }
     return $added;
 }