Пример #1
0
 public function actionCreate()
 {
     // master value
     $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null);
     $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null);
     JarPayment::$_PHP_FM_SHORTDATE = $fmShortDatePhp;
     $arrAccount = ModelUtils::getArrData(JarAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'status' => MasterValueUtils::MV_JAR_ACCOUNT_STATUS_ON])->orderBy('account_type, order_num'), 'account_id', 'account_name');
     $arrEntryLog = MasterValueUtils::getArrData('jar_payment_status');
     // submit data
     $postData = Yii::$app->request->post();
     $submitMode = isset($postData[MasterValueUtils::SM_MODE_NAME]) ? $postData[MasterValueUtils::SM_MODE_NAME] : false;
     // populate model attributes with user inputs
     $model = new JarPayment();
     $model->load($postData);
     if (Yii::$app->request->getIsGet()) {
         $model->entry_date = DateTimeUtils::formatNow($fmShortDatePhp);
         $model->entry_status = MasterValueUtils::MV_JAR_ENTRY_TYPE_SIMPLE;
     }
     // init value
     $model->scenario = MasterValueUtils::SCENARIO_CREATE;
     // render GUI
     $renderView = 'create';
     $renderData = ['model' => $model, 'fmShortDatePhp' => $fmShortDatePhp, 'fmShortDateJui' => $fmShortDateJui, 'arrAccount' => $arrAccount, 'arrEntryLog' => $arrEntryLog];
     switch ($submitMode) {
         case MasterValueUtils::SM_MODE_INPUT:
             $isValid = $model->validate();
             if ($isValid) {
                 $renderView = 'confirm';
                 $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_CREATE];
             }
             break;
         case MasterValueUtils::SM_MODE_CONFIRM:
             $isValid = $model->validate();
             if ($isValid) {
                 $result = $this->createPayment($model, $fmShortDatePhp);
                 if ($result === true) {
                     Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('jar.models', 'Payment')]));
                     return Yii::$app->getResponse()->redirect(Url::to(['index']));
                 } else {
                     // restore Data for View
                     $model->entry_date = DateTimeUtils::parse($model->entry_date, DateTimeUtils::FM_DB_DATE, $fmShortDatePhp);
                     // render View
                     Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result);
                     $renderView = 'confirm';
                     $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_CREATE];
                 }
             }
             break;
         case MasterValueUtils::SM_MODE_BACK:
             break;
         default:
             break;
     }
     // render GUI
     return $this->render($renderView, $renderData);
 }
Пример #2
0
<?php

use app\components\DateTimeUtils;
use app\components\NumberUtils;
$this->title = Yii::t('fin.account', 'Personal Accounts List');
// for render
$rowindex = 0;
$viewToday = DateTimeUtils::formatNow(DateTimeUtils::FM_VIEW_DATE);
?>
<div class="row">
	<div class="col-md-12"><div class="box">
		<div class="box-header with-border">
			<h3 class="box-title"><?php 
echo Yii::t('fin.account', 'Time Deposits');
?>
</h3>
		</div>
		<div class="box-body"><div id="timeDepositsBoxgroup" class="box-group">
			<div class="panel box box-primary">
				<div class="box-header with-border">
					<h4 class="box-title">
						<a href="#timeDepositsOpening" data-parent="#timeDepositsBoxgroup" data-toggle="collapse">
							<?php 
echo Yii::t('fin.grid', 'Opening Deposit');
?>
						</a>
					</h4>
				</div>
				<div class="panel-collapse collapse in" id="timeDepositsOpening">
					<div class="box-body"><div class="table-responsive"><table class="table table-bordered no-margin">
						<tr>
Пример #3
0
 public function actionCreate()
 {
     // master value
     $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null);
     $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null);
     $arrNetCustomer = ModelUtils::getArrData(NetCustomer::find()->select(['id', 'name'])->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'status' => MasterValueUtils::MV_NET_CUSTOMER_STATUS_ON])->orderBy('order_num'), 'id', 'name');
     NetBill::$_PHP_FM_SHORTDATE = $fmShortDatePhp;
     NetBillDetail::$_PHP_FM_SHORTDATE = $fmShortDatePhp;
     $billDetail = new NetBillDetail();
     // submit data
     $postData = Yii::$app->request->post();
     $submitMode = isset($postData[MasterValueUtils::SM_MODE_NAME]) ? $postData[MasterValueUtils::SM_MODE_NAME] : false;
     // populate model attributes with user inputs
     $model = $this->loadBill(null, $postData, $fmShortDatePhp);
     $billDetail->load($postData);
     $arrBillDetail = $this->loadBillDetails(null, $postData, $fmShortDatePhp);
     if (Yii::$app->request->getIsGet()) {
         $model->bill_date = DateTimeUtils::formatNow($fmShortDatePhp);
         $model->arr_member_list = array_keys($arrNetCustomer);
     }
     // init value
     $model->scenario = MasterValueUtils::SCENARIO_CREATE;
     // render GUI
     $renderView = 'create';
     $renderData = ['model' => $model, 'billDetail' => $billDetail, 'fmShortDatePhp' => $fmShortDatePhp, 'arrBillDetail' => $arrBillDetail, 'fmShortDateJui' => $fmShortDateJui, 'arrNetCustomer' => $arrNetCustomer];
     switch ($submitMode) {
         case MasterValueUtils::SM_MODE_ADD_ITEM:
             $itemNo = empty($billDetail->item_no) ? count($arrBillDetail) + 1 : $billDetail->item_no;
             $billDetail->item_no = $itemNo;
             $arrBillDetail[$itemNo] = $billDetail;
             $isValid = $this->validate($model, $arrBillDetail, false);
             if ($isValid !== true) {
                 $renderData['isValid'] = $isValid;
             }
             $renderData['model'] = $model;
             $renderData['arrBillDetail'] = $arrBillDetail;
             break;
         case MasterValueUtils::SM_MODE_DEL_ITEM:
             $arrBillDetail[$billDetail->item_no]->delete_flag = MasterValueUtils::MV_FIN_FLG_DELETE_TRUE;
             $renderData['arrBillDetail'] = $arrBillDetail;
             break;
         case MasterValueUtils::SM_MODE_INPUT:
             $isValid = $this->validate($model, $arrBillDetail);
             if ($isValid === true) {
                 $renderView = 'confirm';
                 $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_CREATE];
             } else {
                 $renderData['isValid'] = $isValid;
             }
             $renderData['model'] = $model;
             $renderData['arrBillDetail'] = $arrBillDetail;
             break;
         case MasterValueUtils::SM_MODE_CONFIRM:
             $isValid = $this->validate($model, $arrBillDetail);
             if ($isValid === true) {
                 $result = $this->createBill($model, $arrBillDetail, $fmShortDatePhp);
                 if ($result === true) {
                     Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('fin.models', 'Bill')]));
                     return Yii::$app->getResponse()->redirect(Url::to(['index']));
                 } else {
                     // restore Data for View
                     $this->restoreData4View($model, $arrBillDetail, $fmShortDatePhp);
                     // render View
                     Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result);
                     $renderView = 'confirm';
                     $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_CREATE];
                 }
             } else {
                 $renderData['isValid'] = $isValid;
                 $renderData['model'] = $model;
                 $renderData['arrBillDetail'] = $arrBillDetail;
             }
             break;
         case MasterValueUtils::SM_MODE_BACK:
             break;
         default:
             break;
     }
     return $this->render($renderView, $renderData);
 }
Пример #4
0
 public function actionCopy($id)
 {
     // master value
     $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null);
     FinTotalInterestUnit::$_PHP_FM_SHORTDATE = $fmShortDatePhp;
     $this->objectId = $id;
     $model = FinTotalInterestUnit::findOne(['id' => $id]);
     $renderView = 'copy';
     if (is_null($model)) {
         $model = false;
         $renderData = ['model' => $model];
         Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, Yii::t('common', 'The requested {record} does not exist.', ['record' => Yii::t('fin.models', 'Interest Unit')]));
     } else {
         // master value
         $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null);
         // modify data for View
         if (empty($model->end_date)) {
             $model->start_date = DateTimeUtils::formatNow($fmShortDatePhp);
         } else {
             $startDate = DateTimeUtils::parse($model->end_date, DateTimeUtils::FM_DB_DATE);
             $model->start_date = DateTimeUtils::addDateTime($startDate, 'P1D', $fmShortDatePhp);
             $model->end_date = null;
             $model->interest_unit = null;
         }
         // submit data
         $postData = Yii::$app->request->post();
         $submitMode = isset($postData[MasterValueUtils::SM_MODE_NAME]) ? $postData[MasterValueUtils::SM_MODE_NAME] : false;
         // populate model attributes with user inputs
         $model->load($postData);
         // init value
         $model->scenario = MasterValueUtils::SCENARIO_COPY;
         $renderData = ['model' => $model, 'fmShortDatePhp' => $fmShortDatePhp, 'fmShortDateJui' => $fmShortDateJui];
         switch ($submitMode) {
             case MasterValueUtils::SM_MODE_INPUT:
                 $isValid = $model->validate();
                 if ($isValid) {
                     $renderView = 'confirm';
                     $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_EDIT];
                 }
                 break;
             case MasterValueUtils::SM_MODE_CONFIRM:
                 $isValid = $model->validate();
                 if ($isValid) {
                     $result = $this->copyInterestUnit($model, $fmShortDatePhp);
                     if ($result === true) {
                         Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('fin.models', 'Interest Unit')]));
                         return Yii::$app->getResponse()->redirect(Url::to(['index']));
                     } else {
                         // modify data for View
                         $model->start_date = DateTimeUtils::parse($model->start_date, DateTimeUtils::FM_DB_DATE, $fmShortDatePhp);
                         if (!empty($model->end_date)) {
                             $model->end_date = DateTimeUtils::parse($model->end_date, DateTimeUtils::FM_DB_DATE, $fmShortDatePhp);
                         }
                         // render View
                         Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result);
                         $renderView = 'confirm';
                         $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_EDIT];
                     }
                 }
                 break;
             case MasterValueUtils::SM_MODE_BACK:
                 break;
             default:
                 break;
         }
     }
     // render GUI
     return $this->render($renderView, $renderData);
 }
Пример #5
0
 public function actionCreate()
 {
     // master value
     $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null);
     $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null);
     JarShare::$_PHP_FM_SHORTDATE = $fmShortDatePhp;
     // submit data
     $postData = Yii::$app->request->post();
     $submitMode = isset($postData[MasterValueUtils::SM_MODE_NAME]) ? $postData[MasterValueUtils::SM_MODE_NAME] : false;
     // populate model attributes with user inputs
     $model = new JarShare();
     $model->load($postData);
     if (Yii::$app->request->getIsGet()) {
         $model->share_date = DateTimeUtils::formatNow($fmShortDatePhp);
     }
     // init value
     $model->scenario = MasterValueUtils::SCENARIO_CREATE;
     // render GUI
     $renderView = 'create';
     $renderData = ['model' => $model, 'fmShortDatePhp' => $fmShortDatePhp, 'fmShortDateJui' => $fmShortDateJui];
     switch ($submitMode) {
         case MasterValueUtils::SM_MODE_INPUT:
             $isValid = $model->validate();
             if ($isValid) {
                 $renderView = 'confirm';
                 $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_CREATE];
                 $renderData['arrShareDetail'] = $this->initShareDetail($model);
             }
             break;
         case MasterValueUtils::SM_MODE_CONFIRM:
             $isValid = $model->validate();
             if ($isValid) {
                 $arrShareDetail = $this->initShareDetail($model);
                 $result = $this->createDistribute($model, $arrShareDetail, $fmShortDatePhp);
                 if ($result === true) {
                     Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('jar.models', 'Distribute')]));
                     return Yii::$app->getResponse()->redirect(Url::to(['index']));
                 } else {
                     // restore Data for View
                     $model->share_date = DateTimeUtils::parse($model->share_date, DateTimeUtils::FM_DB_DATE, $fmShortDatePhp);
                     // render View
                     Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result);
                     $renderView = 'confirm';
                     $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_CREATE];
                     $renderData['arrShareDetail'] = $arrShareDetail;
                 }
             }
             break;
         case MasterValueUtils::SM_MODE_BACK:
             break;
         default:
             break;
     }
     // render GUI
     return $this->render($renderView, $renderData);
 }
Пример #6
0
 public function actionDeposit()
 {
     $model = new FinTotalInterestMonth();
     $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null);
     $startDateJui = DateTimeUtils::parse('20151001', 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 = FinTotalInterestMonth::findOne(['year' => $year, 'month' => $month, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]);
                 if (is_null($reportModel)) {
                     $reportModel = new FinTotalInterestMonth();
                     $reportModel->year = $year;
                     $reportModel->month = $month;
                 }
                 $reportMonthStr = $year . str_pad($month, 2, '0', STR_PAD_LEFT);
                 $reportMonth = DateTimeUtils::parse($reportMonthStr . '01', DateTimeUtils::FM_DEV_DATE);
                 $fromDate = $reportMonth->format(DateTimeUtils::FM_DB_DATE);
                 DateTimeUtils::addDateTime($reportMonth, 'P1M', null, false);
                 $toDate = DateTimeUtils::subDateTime($reportMonth, 'P1D', DateTimeUtils::FM_DB_DATE);
                 $interestUnitQuery = (new Query())->select(['start_date', 'end_date', 'interest_unit']);
                 $interestUnitQuery->from('fin_total_interest_unit')->where(['<=', 'start_date', $toDate]);
                 $interestUnitQuery->andWhere(['OR', ['>=', 'end_date', $fromDate], ['is', 'end_date', null]]);
                 $totalInterestMonth = 0;
                 $arrInterestUnit = $interestUnitQuery->createCommand()->queryAll();
                 foreach ($arrInterestUnit as $interestUnit) {
                     $unit = $interestUnit['interest_unit'];
                     $currentDateObj = DateTimeUtils::getDateFromDB($interestUnit['start_date']);
                     $startDate = $currentDateObj->format(DateTimeUtils::FM_DEV_DATE);
                     $endDate = empty($interestUnit['end_date']) ? DateTimeUtils::formatNow(DateTimeUtils::FM_DEV_DATE) : DateTimeUtils::formatDateFromDB($interestUnit['end_date'], DateTimeUtils::FM_DEV_DATE);
                     while ($startDate <= $endDate) {
                         $currentMonthStr = $currentDateObj->format(DateTimeUtils::FM_DEV_YM);
                         if ($currentMonthStr == $reportMonthStr) {
                             $totalInterestMonth += $unit;
                         }
                         DateTimeUtils::addDateTime($currentDateObj, 'P1D', null, false);
                         $startDate = $currentDateObj->format(DateTimeUtils::FM_DEV_DATE);
                     }
                 }
                 $reportModel->term_interest = intval($totalInterestMonth);
                 $reportModel->save();
                 Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', 'Monthly Interest Report of {month} has been saved successfully.', ['month' => $model->fmonth]));
                 return Yii::$app->getResponse()->redirect(Url::to(['deposit']));
                 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 = FinTotalInterestMonth::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere(['>=', 'year', $fYear])->andWhere(['OR', ['>', 'year', $fYear], ['>=', 'month', $fMonth]])->andWhere(['<=', 'year', $tYear])->andWhere(['OR', ['<', 'year', $tYear], ['<=', 'month', $tMonth]])->orderBy('year, 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) {
             $arrDataChartTemp[$sMonth] = ['noterm' => 0, 'term' => 0, 'total' => 0];
             DateTimeUtils::addDateTime($currentMonthObj, 'P1M', null, false);
             $sMonth = $currentMonthObj->format(DateTimeUtils::FM_DEV_DATE);
         }
         $firstResult = $resultModel[0];
         $prevNoterm = $firstResult->noterm_interest;
         $prevTerm = $firstResult->term_interest;
         $prevTotal = $prevNoterm + $prevTerm;
         $gridData = [];
         foreach ($resultModel as $rm) {
             $key = $rm->year . str_pad($rm->month, 2, '0', STR_PAD_LEFT) . '01';
             $total = $rm->noterm_interest + $rm->term_interest;
             $compareNoterm = $rm->noterm_interest - $prevNoterm;
             $compareTerm = $rm->term_interest - $prevTerm;
             $compareTotal = $total - $prevTotal;
             $prevNoterm = $rm->noterm_interest;
             $prevTerm = $rm->term_interest;
             $prevTotal = $prevNoterm + $prevTerm;
             $girdRow = ['month' => DateTimeUtils::parse($key, DateTimeUtils::FM_DEV_DATE), 'noterm' => $prevNoterm, 'term' => $prevTerm, 'total' => $prevTotal, 'compareNoterm' => $compareNoterm, 'compareTerm' => $compareTerm, 'compareTotal' => $compareTotal];
             $gridData[$key] = $girdRow;
             // data for chart
             if (isset($arrDataChartTemp[$key])) {
                 $arrDataChartTemp[$key]['noterm'] = $prevNoterm;
                 $arrDataChartTemp[$key]['term'] = $prevTerm;
                 $arrDataChartTemp[$key]['total'] = $prevTotal;
             }
         }
         // Total & Average
         $sumGridData = (new Query())->select(['SUM(noterm_interest) AS sum_noterm', 'AVG(noterm_interest) AS avg_noterm', 'SUM(term_interest) AS sum_term', 'AVG(term_interest) AS avg_term'])->from('fin_total_interest_month')->where(['=', 'delete_flag', MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere(['>=', 'year', $fYear])->andWhere(['OR', ['>', 'year', $fYear], ['>=', 'month', $fMonth]])->andWhere(['<=', 'year', $tYear])->andWhere(['OR', ['<', 'year', $tYear], ['<=', 'month', $tMonth]])->createCommand()->queryOne();
         $renderData['sumGridData'] = $sumGridData;
         // data for chart
         $arrLabelChart = [];
         $arrNotermDataChart = [];
         $arrTermDataChart = [];
         $arrTotalDataChart = [];
         $arrNotermAliasDataChart = [];
         $arrTermAliasDataChart = [];
         $arrTotalAliasDataChart = [];
         foreach ($arrDataChartTemp as $labelChart => $dataChartTemp) {
             $arrLabelChart[] = DateTimeUtils::parse($labelChart, DateTimeUtils::FM_DEV_DATE, $fmKeyPhp);
             $arrNotermDataChart[] = $dataChartTemp['noterm'];
             $arrTermDataChart[] = $dataChartTemp['term'];
             $arrTotalDataChart[] = $dataChartTemp['total'];
             $arrNotermAliasDataChart[] = NumberUtils::format($dataChartTemp['noterm']);
             $arrTermAliasDataChart[] = NumberUtils::format($dataChartTemp['term']);
             $arrTotalAliasDataChart[] = NumberUtils::format($dataChartTemp['total']);
         }
         $renderData['chartData'] = json_encode(['label' => $arrLabelChart, 'noterm' => $arrNotermDataChart, 'notermAlias' => $arrNotermAliasDataChart, 'term' => $arrTermDataChart, 'termAlias' => $arrTermAliasDataChart, 'total' => $arrTotalDataChart, 'totalAlias' => $arrTotalAliasDataChart], JSON_NUMERIC_CHECK);
     }
     $renderData['gridData'] = $gridData;
     // sum Term Interest 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);
     $currentInterestUnitQuery = (new Query())->select(['start_date', 'end_date', 'interest_unit']);
     $currentInterestUnitQuery->from('fin_total_interest_unit')->where(['<=', 'start_date', $endCurrentMonth->format(DateTimeUtils::FM_DB_DATE)]);
     $currentInterestUnitQuery->andWhere(['OR', ['>=', 'end_date', $beginCurrentMonth->format(DateTimeUtils::FM_DB_DATE)], ['is', 'end_date', null]]);
     $currentTermInterestMonth = 0;
     $arrCurrentInterestUnit = $currentInterestUnitQuery->createCommand()->queryAll();
     $requireCurrentMonthStr = $beginCurrentMonth->format(DateTimeUtils::FM_DEV_YM);
     foreach ($arrCurrentInterestUnit as $currentInterestUnit) {
         $currentUnit = $currentInterestUnit['interest_unit'];
         $currentDateObj = DateTimeUtils::getDateFromDB($currentInterestUnit['start_date']);
         $currentStartDate = $currentDateObj->format(DateTimeUtils::FM_DEV_DATE);
         $currentEndDate = empty($currentInterestUnit['end_date']) ? DateTimeUtils::formatNow(DateTimeUtils::FM_DEV_DATE) : DateTimeUtils::formatDateFromDB($currentInterestUnit['end_date'], DateTimeUtils::FM_DEV_DATE);
         while ($currentStartDate <= $currentEndDate) {
             $currentMonthStr = $currentDateObj->format(DateTimeUtils::FM_DEV_YM);
             if ($currentMonthStr == $requireCurrentMonthStr) {
                 $currentTermInterestMonth += $currentUnit;
             }
             DateTimeUtils::addDateTime($currentDateObj, 'P1D', null, false);
             $currentStartDate = $currentDateObj->format(DateTimeUtils::FM_DEV_DATE);
         }
     }
     // sum No Term Interest current month
     $currentNotermInterestMonth = 0;
     $arrFinAccount = FinAccount::find()->where(['delete_flag' => 0, 'account_type' => MasterValueUtils::MV_FIN_ACCOUNT_TYPE_CURRENT])->all();
     foreach ($arrFinAccount as $finAccount) {
         $instance = $finAccount->instance();
         $instance->initialize();
         $currentNotermInterestMonth += $instance->capital + $instance->now_interest;
     }
     $renderData['sumCurrentInterestData'] = ['term' => $currentTermInterestMonth, 'noterm' => $currentNotermInterestMonth];
     return $this->render('deposit', $renderData);
 }
Пример #7
0
 public function actionCopy($id)
 {
     $this->objectId = $id;
     $model = FinAccountEntry::findOne(['entry_id' => $id, 'entry_status' => MasterValueUtils::MV_FIN_ENTRY_TYPE_SIMPLE, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]);
     $renderView = 'copy';
     if (is_null($model)) {
         $model = false;
         $renderData = ['model' => $model];
         Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, Yii::t('common', 'The requested {record} does not exist.', ['record' => Yii::t('fin.models', 'Payment')]));
     } else {
         // master value
         $phpFmShortDate = DateTimeUtils::getPhpDateFormat();
         $arrFinAccount = ModelUtils::getArrData(FinAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => 0, 'account_type' => [1, 2, 3, 5, 6, 7]])->orderBy('account_type, order_num'), 'account_id', 'account_name');
         $arrEntryLog = MasterValueUtils::getArrData('fin_entry_log');
         // reset value
         $model->entry_date = DateTimeUtils::formatNow($phpFmShortDate);
         // submit data
         $postData = Yii::$app->request->post();
         $submitMode = isset($postData[MasterValueUtils::SM_MODE_NAME]) ? $postData[MasterValueUtils::SM_MODE_NAME] : false;
         // populate model attributes with user inputs
         $model->load($postData);
         if (is_null($model->arr_entry_log)) {
             $model->arr_entry_log = StringUtils::unserializeArr($model->description);
         }
         // init value
         FinAccountEntry::$_PHP_FM_SHORTDATE = $phpFmShortDate;
         $model->scenario = MasterValueUtils::SCENARIO_COPY;
         $renderData = ['model' => $model, 'phpFmShortDate' => $phpFmShortDate, 'arrFinAccount' => $arrFinAccount, 'arrEntryLog' => $arrEntryLog];
         switch ($submitMode) {
             case MasterValueUtils::SM_MODE_INPUT:
                 $isValid = $model->validate();
                 if ($isValid) {
                     $renderView = 'confirm';
                     $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_COPY];
                 }
                 break;
             case MasterValueUtils::SM_MODE_CONFIRM:
                 $isValid = $model->validate();
                 if ($isValid) {
                     $result = $this->copyPayment($model);
                     if ($result === true) {
                         Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('fin.models', 'Payment')]));
                         return Yii::$app->getResponse()->redirect(Url::to(['index']));
                     } else {
                         Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result);
                         $renderView = 'confirm';
                         $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_COPY];
                     }
                 }
                 break;
             case MasterValueUtils::SM_MODE_BACK:
                 break;
             default:
                 break;
         }
     }
     // render GUI
     return $this->render($renderView, $renderData);
 }