/**
  * update a Purchase
  * @param $purchase OefPurchase
  * @param $fmShortDatePhp
  * @throws Exception
  * @return string|true
  */
 private function updatePurchase($purchase, $fmShortDatePhp)
 {
     // modify data for DB
     $purchase->purchase_date = DateTimeUtils::parse($purchase->purchase_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE);
     if (!empty($purchase->sip_date)) {
         $purchase->sip_date = DateTimeUtils::parse($purchase->sip_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE);
     }
     $transaction = Yii::$app->db->beginTransaction();
     $save = true;
     $message = null;
     // begin transaction
     try {
         // save OefPurchase
         $save = $purchase->save();
         // FinAccountEntry
         $finPayment = FinAccountEntry::findOne($purchase->fin_entry_id);
         if ($save !== false && !is_null($finPayment)) {
             $finPayment->entry_date = $purchase->purchase_date;
             $finPayment->entry_value = $purchase->investment;
             $save = $finPayment->save();
             // save FinAccount (Debit)
             if ($save !== false) {
                 $debitFinAccount = FinAccount::findOne($finPayment->account_source);
                 $debitFinAccount->opening_balance = $debitFinAccount->opening_balance - $purchase->investment + $purchase->investment_old;
                 $save = $debitFinAccount->save();
             }
             // save FinAccount (Credit)
             if ($save !== false) {
                 $creditFinAccount = FinAccount::findOne($finPayment->account_target);
                 $creditFinAccount->opening_balance = $creditFinAccount->opening_balance + $purchase->investment - $purchase->investment_old;
                 $creditFinAccount->capital = $creditFinAccount->capital + $purchase->investment - $purchase->investment_old;
                 $save = $creditFinAccount->save();
             }
         }
         // save JarPayment
         $jarPayment = JarPayment::findOne($purchase->jar_payment_id);
         if ($save !== false && !is_null($jarPayment)) {
             $jarPayment->entry_date = $purchase->purchase_date;
             $jarPayment->entry_value = $purchase->investment;
             $save = $jarPayment->save();
             // save JarAccount (Debit)
             if ($save !== false) {
                 $debitJarAccount = JarAccount::findOne($jarPayment->account_source);
                 $debitJarAccount->useable_balance = $debitJarAccount->useable_balance - $purchase->investment + $purchase->investment_old;
                 $save = $debitJarAccount->save();
             }
             // save JarAccount (Credit)
             if ($save !== false) {
                 $creditJarAccount = JarAccount::findOne($jarPayment->account_target);
                 $creditJarAccount->useable_balance = $creditJarAccount->useable_balance + $purchase->investment - $purchase->investment_old;
                 $save = $creditJarAccount->save();
             }
         }
     } catch (Exception $e) {
         $save = false;
         $message = Yii::t('common', 'Unable to save {record}.', ['record' => Yii::t('oef.models', 'Purchase')]);
     }
     // end transaction
     try {
         if ($save === false) {
             $transaction->rollback();
             return $message;
         } else {
             $transaction->commit();
         }
     } catch (Exception $e) {
         throw Exception(Yii::t('common', 'Unable to excute Transaction.'));
     }
     return true;
 }
 /**
  * copy a Fixed Deposit
  * @param type $fixedDepositModel
  * @throws Exception
  * @return string|true
  */
 private function copyFixedDeposit($fixedDepositModel)
 {
     $fixedDepositModel->setIsNewRecord(true);
     $transaction = Yii::$app->db->beginTransaction();
     $save = true;
     $message = null;
     // begin transaction
     try {
         // saving account
         $savingAccount = FinAccount::findOne($fixedDepositModel->saving_account);
         $savingAccount->opening_date = $fixedDepositModel->opening_date . ' 00:00:00';
         $savingAccount->closing_date = $fixedDepositModel->closing_date . ' 00:00:00';
         $savingAccount->term_interest_rate = $fixedDepositModel->interest_rate;
         // TM or ATM
         $currentAssets = FinAccount::findOne($fixedDepositModel->current_assets);
         // history entry (interest)
         $interestEntry = new FinAccountEntry();
         $interestEntry->entry_date = $fixedDepositModel->opening_date;
         $interestEntry->entry_value = $fixedDepositModel->interest_add;
         $interestEntry->entry_status = MasterValueUtils::MV_FIN_ENTRY_TYPE_INTEREST_DEPOSIT;
         $interestEntry->description = serialize([MasterValueUtils::MV_FIN_ENTRY_LOG_INTEREST]);
         $interestEntry->account_source = 0;
         $interestEntry->account_target = $fixedDepositModel->saving_account;
         // history entry (capital)
         $capitalEntry = new FinAccountEntry();
         $capitalEntry->entry_date = $fixedDepositModel->opening_date;
         $capitalEntry->entry_value = $fixedDepositModel->entry_value;
         $capitalEntry->entry_status = MasterValueUtils::MV_FIN_ENTRY_TYPE_DEPOSIT;
         $capitalEntry->description = serialize([MasterValueUtils::MV_FIN_ENTRY_LOG_SAVING]);
         if ($fixedDepositModel->add_flag == MasterValueUtils::MV_FIN_TIMEDP_TRANTYPE_ADDING) {
             $savingAccount->opening_balance += $fixedDepositModel->interest_add + $fixedDepositModel->entry_value;
             $savingAccount->capital += $fixedDepositModel->entry_value;
             $currentAssets->opening_balance -= $fixedDepositModel->entry_value;
             $capitalEntry->account_source = $fixedDepositModel->current_assets;
             $capitalEntry->account_target = $fixedDepositModel->saving_account;
         } else {
             $savingAccount->opening_balance += $fixedDepositModel->interest_add - $fixedDepositModel->entry_value;
             $savingAccount->capital -= $fixedDepositModel->entry_value;
             $currentAssets->opening_balance += $fixedDepositModel->entry_value;
             $capitalEntry->account_source = $fixedDepositModel->saving_account;
             $capitalEntry->account_target = $fixedDepositModel->current_assets;
         }
         // interest unit
         $instance = $savingAccount->instance();
         $instance->initialize();
         $fixedDepositModel->interest_unit = $instance->closing_interest_unit;
         $save = $savingAccount->save();
         if ($save !== false) {
             $save = $currentAssets->save();
         }
         if ($save !== false) {
             $save = $interestEntry->save();
         }
         if ($save !== false) {
             $save = $capitalEntry->save();
         }
         if ($save !== false) {
             $save = $fixedDepositModel->save();
         }
     } catch (Exception $e) {
         $save = false;
         $message = Yii::t('common', 'Unable to save {record}.', ['record' => Yii::t('fin.models', 'Fixed Deposit')]);
     }
     // end transaction
     try {
         if ($save === false) {
             $transaction->rollback();
             return $message;
         } else {
             $transaction->commit();
         }
     } catch (Exception $e) {
         throw Exception(Yii::t('common', 'Unable to excute Transaction.'));
     }
     return true;
 }
 public function actionAssets()
 {
     $model = new FinTotalAssetsMonth();
     $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null);
     $startDateJui = DateTimeUtils::parse('20151101', DateTimeUtils::FM_DEV_DATE, $fmShortDatePhp);
     $fmKeyPhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null, DateTimeUtils::FM_KEY_FMONTH);
     $fmKeyJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null, DateTimeUtils::FM_KEY_FMONTH);
     $td = DateTimeUtils::getNow();
     // is get page than reset value
     if (Yii::$app->request->getIsGet()) {
         $tdTimestamp = $td->getTimestamp();
         $tdInfo = getdate($tdTimestamp);
         $thismonth = $td->format($fmKeyPhp);
         // for report Model
         $model->fmonth = $thismonth;
         // for search Model
         $model->fmonth_to = $thismonth;
         $model->fmonth_from = DateTimeUtils::parse($tdInfo[DateTimeUtils::FN_KEY_GETDATE_YEAR] - 1 . '0101', DateTimeUtils::FM_DEV_DATE, $fmKeyPhp);
     } else {
         // submit data
         $postData = Yii::$app->request->post();
         $model->load($postData);
         $submitMode = isset($postData[MasterValueUtils::SM_MODE_NAME]) ? $postData[MasterValueUtils::SM_MODE_NAME] : false;
         switch ($submitMode) {
             case MasterValueUtils::SM_MODE_INPUT:
                 $reportMonthStr = DateTimeUtils::parse($model->fmonth, $fmKeyPhp, DateTimeUtils::FM_DEV_YM) . '01';
                 $reportMonthObj = DateTimeUtils::parse($reportMonthStr, DateTimeUtils::FM_DEV_DATE);
                 $reportMonthInfo = getdate($reportMonthObj->getTimestamp());
                 $year = $reportMonthInfo[DateTimeUtils::FN_KEY_GETDATE_YEAR];
                 $month = $reportMonthInfo[DateTimeUtils::FN_KEY_GETDATE_MONTH_INT];
                 $reportModel = FinTotalAssetsMonth::findOne(['year' => $year, 'month' => $month, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]);
                 if (is_null($reportModel)) {
                     $reportModel = new FinTotalAssetsMonth();
                     $reportModel->year = $year;
                     $reportModel->month = $month;
                 }
                 $prevReportMonthObj = DateTimeUtils::subDateTime($reportMonthObj, 'P1M');
                 $prevReportMonthInfo = getdate($prevReportMonthObj->getTimestamp());
                 $prevYear = $prevReportMonthInfo[DateTimeUtils::FN_KEY_GETDATE_YEAR];
                 $prevMonth = $prevReportMonthInfo[DateTimeUtils::FN_KEY_GETDATE_MONTH_INT];
                 $prevReportModel = FinTotalAssetsMonth::findOne(['year' => $prevYear, 'month' => $prevMonth, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]);
                 $prevAssetsValue = is_null($prevReportModel) ? 0 : $prevReportModel->assets_value;
                 $totalEntryMonth = FinTotalEntryMonth::findOne(['year' => $year, 'month' => $month, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]);
                 $sumdebit = 0;
                 $sumcredit = 0;
                 if (!is_null($totalEntryMonth)) {
                     $sumdebit = is_null($totalEntryMonth->value_out) ? 0 : $totalEntryMonth->value_out;
                     $sumcredit = is_null($totalEntryMonth->value_in) ? 0 : $totalEntryMonth->value_in;
                 }
                 $reportModel->assets_value = $prevAssetsValue + $sumcredit - $sumdebit;
                 $reportModel->save();
                 Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', 'Monthly Assets Report of {month} has been saved successfully.', ['month' => $model->fmonth]));
                 return Yii::$app->getResponse()->redirect(Url::to(['assets']));
                 break;
             default:
                 break;
         }
     }
     $renderData = ['fmKeyJui' => $fmKeyJui, 'fmKeyPhp' => $fmKeyPhp, 'model' => $model, 'startDateJui' => $startDateJui];
     $fMonthInfo = getdate(DateTimeUtils::parse($model->fmonth_from, $fmKeyPhp)->getTimestamp());
     $tMonthInfo = getdate(DateTimeUtils::parse($model->fmonth_to, $fmKeyPhp)->getTimestamp());
     $fYear = $fMonthInfo[DateTimeUtils::FN_KEY_GETDATE_YEAR];
     $fMonth = $fMonthInfo[DateTimeUtils::FN_KEY_GETDATE_MONTH_INT];
     $fMonthMM = str_pad($fMonth, 2, '0', STR_PAD_LEFT);
     $tYear = $tMonthInfo[DateTimeUtils::FN_KEY_GETDATE_YEAR];
     $tMonth = $tMonthInfo[DateTimeUtils::FN_KEY_GETDATE_MONTH_INT];
     $tMonthMM = str_pad($tMonth, 2, '0', STR_PAD_LEFT);
     $gridData = null;
     $resultModel = FinTotalAssetsMonth::find()->select('t1.*, t2.value_in AS credit, t2.value_out AS debit')->from('fin_total_assets_month t1')->leftJoin('fin_total_entry_month t2', '(t1.year = t2.year AND t1.month = t2.month)')->where(['t1.delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere(['>=', 't1.year', $fYear])->andWhere(['OR', ['>', 't1.year', $fYear], ['>=', 't1.month', $fMonth]])->andWhere(['<=', 't1.year', $tYear])->andWhere(['OR', ['<', 't1.year', $tYear], ['<=', 't1.month', $tMonth]])->orderBy('t1.year, t1.month')->all();
     if (count($resultModel) > 0) {
         // Init data for chart
         $sMonth = $fYear . $fMonthMM . '01';
         $eMonth = $tYear . $tMonthMM . '01';
         $currentMonthObj = DateTimeUtils::parse($sMonth, DateTimeUtils::FM_DEV_DATE);
         $arrDataChartTemp = [];
         while ($sMonth < $eMonth) {
             $sMonth = $currentMonthObj->format(DateTimeUtils::FM_DEV_DATE);
             $arrDataChartTemp[$sMonth] = ['credit' => 0, 'debit' => 0, 'assets' => 0];
             DateTimeUtils::addDateTime($currentMonthObj, 'P1M', null, false);
         }
         $firstResult = $resultModel[0];
         $prevCredit = is_null($firstResult->credit) ? 0 : $firstResult->credit;
         $prevDebit = is_null($firstResult->debit) ? 0 : $firstResult->debit;
         $prevAssets = is_null($firstResult->assets_value) ? 0 : $firstResult->assets_value;
         $gridData = [];
         foreach ($resultModel as $rm) {
             $key = $rm->year . str_pad($rm->month, 2, '0', STR_PAD_LEFT) . '01';
             $tempCredit = is_null($rm->credit) ? 0 : $rm->credit;
             $tempDebit = is_null($rm->debit) ? 0 : $rm->debit;
             $tempAssets = is_null($rm->assets_value) ? 0 : $rm->assets_value;
             $compareCredit = $tempCredit - $prevCredit;
             $compareDebit = $tempDebit - $prevDebit;
             $compareAssets = $tempAssets - $prevAssets;
             $prevCredit = $tempCredit;
             $prevDebit = $tempDebit;
             $prevAssets = $tempAssets;
             $girdRow = ['month' => DateTimeUtils::parse($key, DateTimeUtils::FM_DEV_DATE), 'credit' => $prevCredit, 'debit' => $prevDebit, 'assets' => $prevAssets, 'compareCredit' => $compareCredit, 'compareDebit' => $compareDebit, 'compareAssets' => $compareAssets];
             $gridData[$key] = $girdRow;
             // data for chart
             if (isset($arrDataChartTemp[$key])) {
                 $arrDataChartTemp[$key]['credit'] = $prevCredit;
                 $arrDataChartTemp[$key]['debit'] = $prevDebit;
                 $arrDataChartTemp[$key]['assets'] = $prevAssets;
             }
         }
         // data for chart
         $arrLabelChart = [];
         $arrCreditDataChart = [];
         $arrDebitDataChart = [];
         $arrAssetsDataChart = [];
         $arrCreditAliasDataChart = [];
         $arrDebitAliasDataChart = [];
         $arrAssetsAliasDataChart = [];
         foreach ($arrDataChartTemp as $labelChart => $dataChartTemp) {
             $arrLabelChart[] = DateTimeUtils::parse($labelChart, DateTimeUtils::FM_DEV_DATE, $fmKeyPhp);
             $arrCreditDataChart[] = $dataChartTemp['credit'];
             $arrDebitDataChart[] = $dataChartTemp['debit'];
             $arrAssetsDataChart[] = $dataChartTemp['assets'];
             $arrCreditAliasDataChart[] = NumberUtils::format($dataChartTemp['credit']);
             $arrDebitAliasDataChart[] = NumberUtils::format($dataChartTemp['debit']);
             $arrAssetsAliasDataChart[] = NumberUtils::format($dataChartTemp['assets']);
         }
         $renderData['chartData'] = json_encode(['label' => $arrLabelChart, 'credit' => $arrCreditDataChart, 'creditAlias' => $arrCreditAliasDataChart, 'debit' => $arrDebitDataChart, 'debitAlias' => $arrDebitAliasDataChart, 'assets' => $arrAssetsDataChart, 'assetsAlias' => $arrAssetsAliasDataChart], JSON_NUMERIC_CHECK);
     }
     $renderData['gridData'] = $gridData;
     // sum payment current month
     $beginCurrentMonth = DateTimeUtils::parse($td->format(DateTimeUtils::FM_DEV_YM) . '01', DateTimeUtils::FM_DEV_DATE);
     $endCurrentMonth = DateTimeUtils::addDateTime($beginCurrentMonth, 'P1M');
     DateTimeUtils::subDateTime($endCurrentMonth, 'P1D', null, false);
     $sumCurrentMonthQuery = (new Query())->select(['SUM(IF(account_source > 0, entry_value, 0)) AS debit', 'SUM(IF(account_target > 0, entry_value, 0)) AS credit']);
     $sumCurrentMonthQuery->from('fin_account_entry')->where(['=', 'delete_flag', MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]);
     $sumCurrentMonthQuery->andWhere(['OR', ['=', 'account_source', MasterValueUtils::MV_FIN_ACCOUNT_NONE], ['=', 'account_target', MasterValueUtils::MV_FIN_ACCOUNT_NONE]]);
     $sumCurrentMonthQuery->andWhere(['>=', 'entry_date', $beginCurrentMonth->format(DateTimeUtils::FM_DB_DATE)]);
     $sumCurrentMonthQuery->andWhere(['<=', 'entry_date', $endCurrentMonth->format(DateTimeUtils::FM_DB_DATE)]);
     $sumCurrentAssetsData = $sumCurrentMonthQuery->createCommand()->queryOne();
     // sum Assets current month
     $sumCurrentAssets = 0;
     $arrFinAccount = FinAccount::find()->where(['delete_flag' => 0])->all();
     foreach ($arrFinAccount as $finAccount) {
         $instance = $finAccount->instance();
         $instance->initialize();
         $sumCurrentAssets += $instance->opening_balance;
     }
     $sumCurrentAssetsData['assets'] = $sumCurrentAssets;
     $renderData['sumCurrentAssetsData'] = $sumCurrentAssetsData;
     return $this->render('assets', $renderData);
 }
 public function actionIndex()
 {
     $arrDeposits = [];
     $sumDeposits = ['opening_balance' => 0, 'closing_interest_unit' => 0, 'closing_interest' => 0, 'closing_balance' => 0, 'now_interest_unit' => 0, 'now_interest' => 0, 'capital' => 0, 'result_interest' => 0];
     $minClosingTimestamp = null;
     $arrTmAtm = [];
     $arrCredit = [];
     $arrLunchFound = [];
     $arrOtherFound = [];
     $sumTmAtm = ['opening_balance' => 0, 'closing_balance' => 0, 'now_balance' => 0];
     $sumTmAtmDeposit = ['opening_balance' => 0, 'closing_balance' => 0, 'now_balance' => 0];
     $sumTotal = ['opening_balance' => 0, 'closing_balance' => 0, 'now_balance' => 0];
     $arrFinAccount = FinAccount::find()->where(['delete_flag' => 0])->orderBy('order_num')->all();
     foreach ($arrFinAccount as $finAccount) {
         $instance = $finAccount->instance();
         $instance->initialize();
         if ($instance instanceof FinAccount01I00 || $instance instanceof FinAccount02I00) {
             // add instance TM or ATM
             $arrTmAtm[] = $instance;
             // sum TM - ATM
             $sumTmAtm['opening_balance'] += $instance->opening_balance;
             $sumTmAtm['closing_balance'] += $instance->closing_balance;
             $sumTmAtm['now_balance'] += $instance->now_balance;
             // sum TM - ATM - Deposits
             $sumTmAtmDeposit['opening_balance'] += $instance->opening_balance;
             $sumTmAtmDeposit['closing_balance'] += $instance->closing_balance;
             $sumTmAtmDeposit['now_balance'] += $instance->now_balance;
             // sum Total
             $sumTotal['opening_balance'] += $instance->opening_balance;
             $sumTotal['closing_balance'] += $instance->closing_balance;
             $sumTotal['now_balance'] += $instance->now_balance;
         } elseif ($instance instanceof FinAccount03I00) {
             // add instance CREDIT
             $arrCredit[] = $instance;
             // sum Total
             $sumTotal['opening_balance'] += $instance->opening_balance;
             $sumTotal['closing_balance'] += $instance->closing_balance;
             $sumTotal['now_balance'] += $instance->now_balance;
         } elseif ($instance instanceof FinAccount04I00) {
             // add instance Deposits
             $arrDeposits[] = $instance;
             // sum deposits
             $sumDeposits['opening_balance'] += $instance->opening_balance;
             $sumDeposits['closing_interest_unit'] += $instance->closing_interest_unit;
             $sumDeposits['closing_interest'] += $instance->closing_interest;
             $sumDeposits['closing_balance'] += $instance->closing_balance;
             $sumDeposits['now_interest_unit'] += $instance->now_interest_unit;
             $sumDeposits['now_interest'] += $instance->now_interest;
             $sumDeposits['capital'] += $instance->capital;
             $sumDeposits['result_interest'] += $instance->result_interest;
             // sum TM - ATM - Deposits
             $nowbalance = $instance->opening_balance + $instance->now_interest;
             $sumTmAtmDeposit['opening_balance'] += $instance->opening_balance;
             $sumTmAtmDeposit['closing_balance'] += $instance->closing_balance;
             $sumTmAtmDeposit['now_balance'] += $nowbalance;
             // sum Total
             $sumTotal['opening_balance'] += $instance->opening_balance;
             $sumTotal['closing_balance'] += $instance->closing_balance;
             $sumTotal['now_balance'] += $nowbalance;
             // next closing
             $timestamp = DateTimeUtils::getDateTimeFromDB($instance->closing_date)->getTimestamp();
             if (is_null($minClosingTimestamp) || $minClosingTimestamp > $timestamp) {
                 $minClosingTimestamp = $timestamp;
             }
         } elseif ($instance instanceof FinAccount05I00) {
             // add instance LUNCH FOUND
             $arrLunchFound[] = $instance;
             // sum Total
             $sumTotal['opening_balance'] += $instance->opening_balance;
             $sumTotal['closing_balance'] += $instance->closing_balance;
             $sumTotal['now_balance'] += $instance->now_balance;
         } elseif ($instance instanceof FinAccount06I00 || $instance instanceof FinAccount07I00) {
             // add instance OTHER FOUND
             $arrOtherFound[] = $instance;
             // sum Total
             $sumTotal['opening_balance'] += $instance->opening_balance;
             $sumTotal['closing_balance'] += $instance->closing_balance;
             $sumTotal['now_balance'] += $instance->now_balance;
         }
     }
     return $this->render('index', ['arrDeposits' => $arrDeposits, 'sumDeposits' => $sumDeposits, 'minClosingTimestamp' => $minClosingTimestamp, 'arrTmAtm' => $arrTmAtm, 'sumTmAtm' => $sumTmAtm, 'sumTmAtmDeposit' => $sumTmAtmDeposit, 'arrCredit' => $arrCredit, 'arrLunchFound' => $arrLunchFound, 'arrOtherFound' => $arrOtherFound, 'sumTotal' => $sumTotal]);
 }
 /**
  * copy a payment
  * @param type $paymentModel
  * @throws Exception
  * @return string|true
  */
 private function copyPayment($paymentModel)
 {
     $paymentModel->setIsNewRecord(true);
     $transaction = Yii::$app->db->beginTransaction();
     $save = true;
     $message = null;
     // begin transaction
     try {
         $paymentModel->description = serialize($paymentModel->arr_entry_log);
         $accountSource = FinAccount::findOne($paymentModel->account_source);
         $accountTarget = FinAccount::findOne($paymentModel->account_target);
         // save source
         if (!is_null($accountSource) && $save !== false) {
             $accountSource->opening_balance -= $paymentModel->entry_value;
             $save = $accountSource->save();
         }
         // save Target
         if (!is_null($accountTarget) && $save !== false) {
             $accountTarget->opening_balance += $paymentModel->entry_value;
             $save = $accountTarget->save();
         }
         // save payment
         if ($save !== false) {
             $save = $paymentModel->save();
         }
     } catch (Exception $e) {
         $save = false;
         $message = Yii::t('common', 'Unable to save {record}.', ['record' => Yii::t('fin.models', 'Payment')]);
     }
     // end transaction
     try {
         if ($save === false) {
             $transaction->rollback();
             return $message;
         } else {
             $transaction->commit();
         }
     } catch (Exception $e) {
         throw Exception(Yii::t('common', 'Unable to excute Transaction.'));
     }
     return true;
 }