/**
  * Creates a new GlHeader model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($es = null)
 {
     $model = new GlHeader();
     if (!empty($es)) {
         $details = [];
         foreach (EntriSheetDtl::findAll(['id_esheet' => $es]) as $eDtl) {
             /* @var $eDtl EntriSheetDtl */
             $details[$eDtl->nm_esheet_dtl] = new GlDetail(['id_coa' => $eDtl->id_coa]);
         }
         $model->populateRelation('glDetails', $details);
         $post = Yii::$app->request->post();
         if ($model->load($post)) {
             try {
                 $transaction = Yii::$app->db->beginTransaction();
                 $success = $model->save();
                 $success = $model->saveRelated('glDetails', $post, $success);
                 if ($success) {
                     $error = false;
                     $balance = 0.0;
                     foreach ($model->glDetails as $detail) {
                         $balance += $detail->amount;
                     }
                     if ($balance != 0) {
                         $model->addError('', 'Details should be balance');
                         $error = true;
                     }
                     //
                     if ($error) {
                         $transaction->rollBack();
                     } else {
                         $transaction->commit();
                         return $this->redirect(['view', 'id' => $model->id_gl]);
                     }
                 } else {
                     $transaction->rollBack();
                 }
             } catch (\Exception $exc) {
                 $transaction->rollBack();
                 $model->addError('', $exc->getMessage());
             }
         }
     }
     return $this->render('create', ['model' => $model, 'es' => $es]);
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEntriSheetDtls()
 {
     return $this->hasMany(EntriSheetDtl::className(), ['cd_esheet' => 'cd_esheet']);
 }
Пример #3
0
        <div class="col-lg-7">
        </div>
    </div>
    <table class ="table table-striped" id="tbl-entryheader">
        <thead>
            <tr>
                <th>No</th>
                <th>NM Detail Entry</th>
                <th>Account</th>
                <th>
                    <a href="#" data-action="append"><span class="glyphicon glyphicon-plus"></span></a>
                </th>
            </tr>
        </thead>
        <?php 
echo TabularInput::widget(['id' => 'tbl-entrydetail', 'allModels' => $model->entriSheetDtls, 'modelClass' => EntriSheetDtl::className(), 'itemView' => '_detail', 'options' => ['tag' => 'tbody'], 'itemOptions' => ['tag' => 'tr'], 'clientOptions' => ['afterAddRow' => new yii\web\JsExpression('biz.config.entryAfterAddRow')]]);
?>
    </table>
    <div class="box-footer">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
</div>
<?php 
ActiveForm::end();
yii\jui\AutoCompleteAsset::register($this);
yii\jui\ThemeAsset::register($this);
biz\app\assets\BizAsset::register($this);
$jsFunc = <<<JS
function (\$row) {
 /**
  * Deletes an existing EntriSheet 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);
     try {
         $transaction = \Yii::$app->db->beginTransaction();
         EntriSheetDtl::deleteAll(['id_esheet' => $model->id_esheet]);
         $model->delete();
         $transaction->commit();
     } catch (\Exception $exc) {
         $transaction->rollBack();
         throw $exc;
     }
     return $this->redirect(['index']);
 }
Пример #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEntriSheetDtls()
 {
     return $this->hasMany(EntriSheetDtl::className(), ['id_coa' => 'id_coa']);
 }
Пример #6
0
    \$row.find('.nm_account').autocomplete({
        source: biz.master.coas,
        select: function (event, ui) {
            var \$row = \$(event.target).closest('tr');
            \$row.find('.id_account').val(ui.item.id);
            \$row.find('.cd_account').text(ui.item.cd_coa);
            \$row.find('.nm_account').val(ui.item.value);

            return false;
        }
    });
}
JS;
?>
            <?php 
echo TabularInput::widget(['id' => 'tbl-entrydetail', 'allModels' => $model->entriSheetDtls, 'modelClass' => EntriSheetDtl::className(), 'itemView' => '_detail', 'options' => ['tag' => 'tbody'], 'itemOptions' => ['tag' => 'tr'], 'clientOptions' => ['afterAddRow' => new yii\web\JsExpression($jsFunc), 'btnAddSelector' => '#append-row']]);
?>
        </table>
        <div class="panel-footer">
            <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
        </div>
    </div>
    <?php 
ActiveForm::end();
?>
</div>
<?php 
yii\jui\AutoCompleteAsset::register($this);
yii\jui\ThemeAsset::register($this);