Exemplo n.º 1
0
 public function actionDashboard()
 {
     $parms = Yii::$app->request->queryParams;
     $mperiode = \backend\models\accounting\AccPeriode::find()->active()->one();
     if ($mperiode == null) {
         throw new NotFoundHttpException('There is no active accounting periode.');
     }
     $searchModel = new SalesSearch();
     $dataProvider = $searchModel->searchByBranch($parms);
     $searchHutang = new \backend\models\accounting\search\Invoice();
     $searchHutang->type = \backend\models\accounting\Invoice::TYPE_INCOMING;
     $hutangPro = $searchHutang->search(Yii::$app->request->queryParams);
     $searchTransfer = new \backend\models\inventory\search\Transfer();
     $transfPro = $searchTransfer->search(Yii::$app->request->queryParams);
     $datavar = ['dataProvider' => $dataProvider, 'mperiode' => $mperiode->name, 'hutangPro' => $hutangPro, 'transfPro' => $transfPro];
     return $this->render('dashboard', $datavar);
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AccPeriodeModel::find();
     $query->orderBy('id ASC');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     if (isset($this->date_from)) {
         $query->andFilterWhere(['>=', 'date_from', $this->date_from]);
     }
     if (isset($this->date_to)) {
         $query->andFilterWhere(['<=', 'date_to', $this->date_to]);
     }
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * @return integer
  */
 public static function getActivePeriode()
 {
     if (($model = AccPeriode::find()->active()->one()) !== null) {
         return $model->id;
     } else {
         throw new \yii\web\NotFoundHttpException('Active Periode not exist.');
     }
 }
Exemplo n.º 4
0
 /**
  * Finds the AccPeriode model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AccPeriode the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AccPeriode::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 5
0
 protected function findPeriode()
 {
     if (($model = \backend\models\accounting\AccPeriode::find()->active()->one()) !== null) {
         return $model->id;
     } else {
         throw new NotFoundHttpException('Active Periode not exist.');
     }
 }
 public function actionTestEntriJournal()
 {
     $model = new EntriSheet();
     $dPost = Yii::$app->request->post();
     if (!empty($dPost)) {
         $model = EntriSheet::findOne($dPost['EntriSheet']['id']);
         $model->amount = $dPost['EntriSheet']['amount'];
         $newGl = new GlHeader();
         $newGl->reff_type = 0;
         $newGl->reff_id = null;
         $newGl->date = date('Y-m-d');
         $newDtls = [];
         foreach ($model->entriSheetDtls as $ddtl) {
             $ndtl = new \backend\models\accounting\GlDetail();
             $ndtl->coa_id = $ddtl->coa_id;
             $ndtl->header_id = null;
             $ndtl->amount = $ddtl->dk == $ddtl::DK_CREDIT ? -1 * $model->amount : $model->amount;
             $newDtls[] = $ndtl;
         }
         $newGl->status = $newGl::STATUS_RELEASED;
         $activePeriode = \backend\models\accounting\AccPeriode::find()->active()->one();
         $newGl->periode_id = $activePeriode->id;
         $newGl->branch_id = 1;
         $newGl->description = $model->name;
         $newGl->glDetails = $newDtls;
         if (!$newGl->save()) {
             //                print_r($newGl->getErrors());
             //                print_r($newGl->getRelatedErrors());
             return $this->redirect(['/accounting/general-ledger/view', 'id' => $model->id]);
         }
     }
     return $this->render('test', ['model' => $model]);
 }
Exemplo n.º 7
0
 /**
  * Deletes an existing GoodsMovement model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionPost($id)
 {
     $model = $this->findModel($id);
     $model->status = Invoice::STATUS_RELEASED;
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if ($model->save()) {
             //post journal first
             $gl = new \backend\models\accounting\GlHeader();
             $gl->branch_id = 1;
             $aPeriode = \backend\models\accounting\AccPeriode::find()->active()->one();
             if ($aPeriode == null) {
                 throw new NotFoundHttpException('No active periode exist for now.');
             }
             $gl->periode_id = $aPeriode->id;
             $gl->reff_type = $gl::REFF_INVOICE;
             $gl->reff_id = $model->id;
             $gl->status = $gl::STATUS_RELEASED;
             $gl->date = date('Y-m-d');
             $esheet = \backend\models\accounting\EntriSheet::find()->where('code=:dcode', [':dcode' => 'ES002'])->one();
             $gl->description = $esheet->name;
             /*
              * Detail Journal
              */
             $newDtls = [];
             $ndtl = new \backend\models\accounting\GlDetail();
             $ndtl->coa_id = $esheet->d_coa_id;
             $ndtl->header_id = null;
             $ndtl->amount = $model->value;
             $newDtls[] = $ndtl;
             $ndtl1 = new \backend\models\accounting\GlDetail();
             $ndtl1->coa_id = $esheet->k_coa_id;
             $ndtl1->header_id = null;
             $ndtl1->amount = $model->value * -1;
             $newDtls[] = $ndtl1;
             $gl->glDetails = $newDtls;
             if ($gl->save()) {
                 $transaction->commit();
             } else {
                 foreach ($gl->getErrors() as $dkey => $vald) {
                     if ($vald[0] == 'Related error') {
                         foreach ($gl->getRelatedErrors() as $dkey => $valr) {
                             foreach ($valr as $tkey => $valt) {
                                 \Yii::$app->getSession()->setFlash('error', $valt);
                             }
                             break;
                         }
                     } else {
                         \Yii::$app->getSession()->setFlash('error', $vald[0]);
                         break;
                     }
                 }
                 $transaction->rollback();
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             print_r($model->getErrors());
         }
     } catch (\Exception $exc) {
         $transaction->rollBack();
         echo $exc->getMessage();
     }
     return $this->render('view', ['model' => $model]);
 }
Exemplo n.º 8
0
 protected function findActivePeriode()
 {
     $dPeriode = \backend\models\accounting\AccPeriode::find()->active()->one();
     if ($dPeriode != null) {
         return $dPeriode->id;
     }
     throw new NotFoundHttpException('There is no active periode..');
 }