예제 #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;
 }
 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();
 }
예제 #3
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]);
 }
예제 #4
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;
 }