Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = EntriSheetModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  *
  * @param array $templates
  */
 public function addFromTemplate($templates = [], $description = false)
 {
     $items = $this->glDetails;
     foreach ($templates as $code => $amount) {
         /* @var $es EntriSheet */
         $es = EntriSheet::findOne(['code' => $code]);
         if ($description === true) {
             $this->description .= "\n" . $es->name;
         }
         $items[] = ['coa_id' => $es->d_coa_id, 'amount' => $amount];
         $items[] = ['coa_id' => $es->k_coa_id, 'amount' => -1 * $amount];
     }
     if (is_string($description)) {
         $this->description .= "\n{$description}";
     }
     $this->glDetails = $items;
 }
 public function actionJournalTemplates($term = '')
 {
     $response = Yii::$app->response;
     $response->format = 'json';
     $glTemplates = \backend\models\accounting\EntriSheet::find()->filterWhere(['like', 'lower([[name]])', strtolower($term)])->orderBy('name ASC')->limit(10);
     return $glTemplates->all();
 }
 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]);
 }
Esempio n. 5
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]);
 }
Esempio n. 6
0
 /**
  *
  * @return boolean
  */
 public function postGL($factor)
 {
     /*
      * Header Journal
      */
     $model_journal = new \backend\models\accounting\GlHeader();
     $model_journal->periode_id = $this->findActivePeriode();
     $model_journal->date = date('Y-m-d');
     $model_journal->status = \backend\models\accounting\GlHeader::STATUS_RELEASED;
     $model_journal->reff_type = \backend\models\accounting\GlHeader::REFF_GOODS_MOVEMENT;
     $model_journal->reff_id = $this->id;
     $model_journal->branch_id = isset(Yii::$app->profile->branch_id) ? Yii::$app->profile->branch_id : -1;
     $esheet = null;
     switch ($this->reff_type) {
         case self::REFF_TRANSFER:
             $esheet = $this->type == self::TYPE_ISSUE ? EntriSheet::find()->where('code=:dcode', [':dcode' => 'ES004'])->one() : EntriSheet::find()->where('code=:dcode', [':dcode' => 'ES005'])->one();
             break;
         default:
             $esheet = $factor == 1 ? EntriSheet::find()->where('code=:dcode', [':dcode' => 'ES001'])->one() : EntriSheet::find()->where('code=:dcode', [':dcode' => 'ES003'])->one();
     }
     $model_journal->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 = $this->totalValue;
     $newDtls[] = $ndtl;
     $ndtl1 = new \backend\models\accounting\GlDetail();
     $ndtl1->coa_id = $esheet->k_coa_id;
     $ndtl1->header_id = null;
     $ndtl1->amount = $this->totalValue * -1;
     $newDtls[] = $ndtl1;
     $model_journal->glDetails = $newDtls;
     if (!$model_journal->save()) {
         print_r($model_journal->getErrors());
         print_r($model_journal->getRelatedErrors());
         return false;
     }
     return true;
 }