Ejemplo n.º 1
0
 public function getTotal($code)
 {
     $totalRealization = 0;
     $totalRestMoney = 0;
     $usingRate = 0;
     $models = Realization::model()->findAllByAttributes(array('package_code' => "{$code}", 'use_up' => 'UP'));
     foreach ($models as $model) {
         $totalRealization += $model->total_spm;
     }
     $detail = UpDetail::model()->findByAttributes(array('package_name' => "{$code}"), array('order' => 'id DESC'));
     $limit = $detail->limit;
     $totalRestMoney = $limit - $totalRealization;
     $rate = $totalRealization / $limit;
     $usingRate = round($rate, 4);
     return array('realization' => $totalRealization, 'restUp' => $totalRestMoney, 'rateUpUsing' => $usingRate);
 }
 /**
  * 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 = UpDetail::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 3
0
 public function actionUpdateDetail($id)
 {
     $this->title = 'Update Detail UP';
     $model = UpDetail::model()->findByPk($id);
     $currentUp = UpDetail::model()->findAllByAttributes(array('up_number_of_letter' => $model->up_number_of_letter));
     $currentTotal = 0;
     if ($currentUp) {
         foreach ($currentUp as $currentUpDetail) {
             $currentTotal += $currentUpDetail->limit;
         }
     }
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['UpDetail'])) {
         $currentLimit = $model->limit;
         $limit = $_POST['UpDetail']['limit'];
         $tempTotal = $currentTotal - $currentLimit + $limit;
         $latestUP = Up::model()->find(array('order' => 'id DESC'));
         $upLimit = $latestUP->total_up;
         $up = Up::model()->findByAttributes(array('number_of_letter' => $model->up_number_of_letter));
         if ($model->up_number_of_letter != $latestUP->number_of_letter) {
             Yii::app()->user->setFlash('error', 'Sudah ada UP baru. Tidak dapat mengedit detail UP lama.');
             $this->redirect(array('view', 'id' => $up->id));
         } else {
             $realization = $model->getTotalDetail($model->package_code, $model->up_number_of_letter)["realization"];
             if ($limit < $realization) {
                 Yii::app()->user->setFlash('error', 'Pagu Detail tidak boleh lebih kecil dari Pagu detail yang sudah direalisasikan.');
                 $this->redirect(array('view', 'id' => $up->id));
             }
         }
         if ($tempTotal > $upLimit) {
             Yii::app()->user->setFlash('error', 'Update Pagu Detail UP tidak boleh melebihi total Pagu UP.');
         } else {
             $model->attributes = $_POST['UpDetail'];
             if ($model->update()) {
                 Yii::app()->user->setFlash('success', 'Data berhasil diupdate');
                 //$this->redirect(array('view','id'=>$model->id));
                 $this->redirect(array('view', 'id' => $up->id));
             }
         }
     }
     $this->render('updateDetail', array('model' => $model));
 }