Exemple #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function searchDtl($params)
 {
     $query = GlHeaderModel::find();
     //$query->select(['gl_header.*','gl_detail.*']);
     $query->with(['glDetails', 'glDetails.coa']);
     //$query->joinWith(['glDetails']);
     $query->orderBy(['number' => SORT_ASC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'date' => $this->date, 'periode_id' => $this->periode_id, 'branch_id' => $this->branch_id, 'reff_type' => $this->reff_type, 'reff_id' => $this->reff_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', 'number', $this->number])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemple #2
0
 public function beforeDelete()
 {
     parent::beforeDelete();
     $ada = GlHeader::find()->where('periode_id = :did', [':did' => $this->id])->exists();
     if ($ada) {
         $this->addError('id', $this->name . 'telah digunakan dalam journal');
         return false;
     } else {
         if ($this->status == self::STATUS_CLOSE) {
             $this->addError('id', $this->name . ' telah close, tidak dapat dihapus');
             return false;
         }
     }
     return true;
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getJournals()
 {
     return $this->hasMany(GlHeader::className(), ['reff_id' => 'id'])->where(['reff_type' => GlHeader::REFF_INVOICE])->andFilterWhere(['<>', 'status', GlHeader::STATUS_CANCELED]);
 }
 /**
  * Deletes an existing Sales model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if ($model->status == Sales::STATUS_DRAFT) {
         $model->delete();
         return $this->redirect(['index']);
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         // gl
         $gl = GlHeader::findOne(['reff_type' => GlHeader::REFF_SALES, 'reff_id' => $id]);
         // movement
         $movement = $gl != null ? GoodsMovement::findOne(['reff_type' => GoodsMovement::REFF_SALES, 'reff_id' => $id]) : null;
         // invoice from movement
         $invoice = $movement != null ? Invoice::findOne(['reff_type' => Invoice::REFF_GOODS_MOVEMENT, 'reff_id' => $movement->id]) : null;
         // payment invoive
         $payments = $invoice != null ? $invoice->payments : [];
         foreach ($payments as $payment) {
             if (!$payment->delete()) {
                 throw new UserException('Cannot delete payment');
             }
         }
         if (count($payments) > 0 && $invoice->delete() && $movement->delete() && $gl->reserve() && $model->delete()) {
             //do nothing
             $transaction->commit();
             return $this->redirect(['index']);
         } else {
             throw new UserException('Something error');
         }
     } catch (\Exception $exc) {
         $transaction->rollBack();
         throw $exc;
     }
 }
 /**
  * Finds the GlHeader model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return GlHeader the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GlHeader::find()->where('id=:did', [':did' => $id])->with(['glDetails', 'glDetails.coa'])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #6
0
 /**
  * 
  * @param GlHeader $model
  */
 public function createUpdateJournal($model = null)
 {
     if ($model === null) {
         $model = new GlHeader(['status' => GlHeader::STATUS_RELEASED, 'reff_type' => GlHeader::REFF_SALES, 'reff_id' => $this->id, 'date' => date('Y-m-d'), 'vendor_id' => $this->vendor_id, 'periode_id' => GlHeader::getActivePeriode(), 'branch_id' => $this->branch_id]);
     }
     $value = 0;
     foreach ($this->items as $item) {
         $value += $item->cogs * $item->qty * $item->productUom->isi;
     }
     $model->addFromTemplate(['ES006' => $value]);
     return $model;
 }
 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]);
 }
 /**
  *
  * @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;
 }
Exemple #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getHeader()
 {
     return $this->hasOne(GlHeader::className(), ['id' => 'header_id']);
 }