public function actionCreate() { $model = new fJournal(); //$this->performAjaxValidation($model); //default value $_myDebit = 0; $_myCredit = 0; $model->balance = "NOT OK"; if (isset($_POST['account_no_id'])) { $model->attributes = $_POST['fJournal']; $model->account_no_id = $_POST['account_no_id']; $model->debit = $_POST['debit']; $model->credit = $_POST['credit']; $model->user_remark = $_POST['user_remark']; foreach ($model->debit as $_debit) { $_myDebit = $_myDebit + $_debit; } foreach ($model->credit as $_credit) { $_myCredit = $_myCredit + $_credit; } if ($_myDebit == $_myCredit && $_myDebit != 0 && $_myCredit != 0) { $model->balance = "OK"; } else { $model->balance = "NOT OK"; } if ($model->validate()) { $modelHeader = new uJournal(); $modelHeader->input_date = $_POST['fJournal']['input_date']; $modelHeader->yearmonth_periode = Yii::app()->settings->get("System", "cCurrentPeriod"); $modelHeader->remark = $_POST['fJournal']['remark']; $modelHeader->entity_id = 1; $modelHeader->module_id = 1; //GL $modelHeader->state_id = 1; $modelHeader->journal_type_id = 1; $modelHeader->save(); for ($i = 0; $i < sizeof($model->account_no_id); ++$i) { $modelDetail = new uJournalDetail(); $modelDetail->parent_id = $modelHeader->id; $modelDetail->account_no_id = $model->account_no_id[$i]; if ($model->debit[$i] != null) { $modelDetail->debit = $model->debit[$i]; } else { $modelDetail->debit = 0; } if ($model->credit[$i] != null) { $modelDetail->credit = $model->credit[$i]; } else { $modelDetail->credit = 0; } $modelDetail->user_remark = $model->user_remark[$i]; $modelDetail->sub_account_id = 0; $modelDetail->save(); } //Create System_ref $_ref = "GL-" . $modelHeader->yearmonth_periode . "-" . str_pad($modelHeader->id, 5, "0", STR_PAD_LEFT); $modelHeader->updateByPk((int) $modelHeader->id, array('system_ref' => $_ref)); Yii::app()->user->setFlash("success", "<strong>Great!</strong> Journal created succesfully..."); $this->redirect(array('/m2/uJournal')); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new fJournal('cashbank'); //$this->performAjaxValidation($model); $_myDebit = 0; $_myCredit = 0; $_myBalance = 0; $model->balance = "NOT OK"; if (isset($_POST['account_no_id'])) { $model->attributes = $_POST['fJournal']; $model->validate(); if (isset($_POST['fJournal']['cb_receiver'])) { //Expense $model->account_no_id = $_POST['account_no_id']; $model->debit = $_POST['debit']; $model->credit = $_POST['credit']; $model->user_remark = $_POST['user_remark']; foreach ($model->debit as $_debit) { $_myDebit = $_myDebit + $_debit; } foreach ($model->credit as $_credit) { $_myCredit = $_myCredit + $_credit; } $_myBalance = $_myDebit - $_myCredit; $model->balance = "OK"; if ($model->validate()) { $modelHeader = new uJournal(); $modelHeader->input_date = $_POST['fJournal']['input_date']; $modelHeader->yearmonth_periode = Yii::app()->settings->get("System", "cCurrentPeriod"); $modelHeader->remark = $_POST['fJournal']['remark']; $modelHeader->user_ref = $_POST['fJournal']['cb_receiver']; $modelHeader->entity_id = sUser::model()->getGroup(); //default Group $modelHeader->module_id = 2; //CB $modelHeader->state_id = 1; $modelHeader->journal_type_id = 2; //CB-expense $modelHeader->save(); $_tdebet = 0; $_tcredit = 0; for ($i = 0; $i < sizeof($model->account_no_id); ++$i) { $modelDetail = new uJournalDetail(); $modelDetail->parent_id = $modelHeader->id; $modelDetail->account_no_id = $model->account_no_id[$i]; if ($model->debit[$i] != null) { $modelDetail->debit = $model->debit[$i]; } else { $modelDetail->debit = 0; } if ($model->credit[$i] != null) { $modelDetail->credit = $model->credit[$i]; } else { $modelDetail->credit = 0; } $modelDetail->user_remark = $model->user_remark[$i]; $modelDetail->save(); } $modelDetail = new uJournalDetail(); $modelDetail->parent_id = $modelHeader->id; $modelDetail->account_no_id = $_POST['fJournal']['var_account']; $modelDetail->debit = 0; $modelDetail->credit = $_myBalance; $modelDetail->system_remark = "Automated by System"; $modelDetail->user_remark = $model->user_remark[0]; $modelDetail->save(); //Create System_ref $_ref = "CB-" . $modelDetail->account->cashbank->mtext . "-" . $modelHeader->yearmonth_periode . "-EXP-" . str_pad($modelHeader->id, 5, "0", STR_PAD_LEFT); $modelHeader->updateByPk((int) $modelHeader->id, array('system_ref' => $_ref)); Yii::app()->user->setFlash("success", "Journal created succesfully..."); $this->redirect(array('/mCashbank')); } $this->render('create', array('model' => $model)); Yii::app()->end(); } else { //Income $model->account_no_id = $_POST['account_no_id']; $model->debit = $_POST['debit']; $model->credit = $_POST['credit']; $model->user_remark = $_POST['user_remark']; foreach ($model->debit as $_debit) { $_myDebit = $_myDebit + $_debit; } foreach ($model->credit as $_credit) { $_myCredit = $_myCredit + $_credit; } $_myBalance = $_myCredit - $_myDebit; $model->balance = "OK"; if ($model->validate()) { $modelHeader = new uJournal(); $modelHeader->input_date = $_POST['fJournal']['input_date']; $modelHeader->yearmonth_periode = Yii::app()->settings->get("System", "cCurrentPeriod"); $modelHeader->remark = $_POST['fJournal']['remark']; $modelHeader->user_ref = $_POST['fJournal']['cb_received_from']; $modelHeader->entity_id = sUser::model()->getGroup(); //default Group $modelHeader->module_id = 2; //CB $modelHeader->state_id = 1; $modelHeader->journal_type_id = 1; //CB-Income $modelHeader->save(); $modelDetail = new uJournalDetail(); $modelDetail->parent_id = $modelHeader->id; $modelDetail->account_no_id = $_POST['fJournal']['var_account']; $modelDetail->debit = $_myBalance; $modelDetail->credit = 0; $modelDetail->system_remark = "Automated by System"; $modelDetail->user_remark = $model->user_remark[0]; $modelDetail->save(); //Create System_ref $_ref = "CB-" . $modelDetail->account->cashbank->mtext . "-" . $modelHeader->yearmonth_periode . "-INC-" . str_pad($modelHeader->id, 5, "0", STR_PAD_LEFT); $modelHeader->updateByPk((int) $modelHeader->id, array('system_ref' => $_ref)); $_tdebet = 0; $_tcredit = 0; for ($i = 0; $i < sizeof($model->account_no_id); ++$i) { $modelDetail = new uJournalDetail(); $modelDetail->parent_id = $modelHeader->id; $modelDetail->account_no_id = $model->account_no_id[$i]; if ($model->debit[$i] != null) { $modelDetail->debit = $model->debit[$i]; } else { $modelDetail->debit = 0; } if ($model->credit[$i] != null) { $modelDetail->credit = $model->credit[$i]; } else { $modelDetail->credit = 0; } $modelDetail->user_remark = $model->user_remark[$i]; $modelDetail->save(); } Yii::app()->user->setFlash("success", "Journal created succesfully... View Jurnal: " . CHtml::link($modelHeader->system_ref, Yii::app()->createUrl("/mCashbank/view", array("id" => $modelHeader->id)))); $this->redirect(array('/mCashbank')); } $this->render('create', array('model' => $model)); Yii::app()->end(); } } $this->render('create', array('model' => $model)); }