public function initialize() { $thisMonth = DateTimeUtils::getNow(DateTimeUtils::FM_DEV_YM . '01 000000', DateTimeUtils::FM_DEV_DATETIME); DateTimeUtils::addDateTime($thisMonth, 'P1M', null, false); DateTimeUtils::subDateTime($thisMonth, 'P1D', null, false); $this->closing_date = $thisMonth->format(DateTimeUtils::FM_DB_DATETIME); $oTime = DateTimeUtils::getDateTimeFromDB($this->opening_date); $cTime = DateTimeUtils::getDateTimeFromDB($this->closing_date); $now = new \DateTime(); $this->closing_diff = $cTime->diff($oTime)->days; $this->now_diff = $now->diff($oTime)->days; // calculate Closing Interest $this->closing_interest_unit = NumberUtils::getInterest($this->opening_balance, $this->term_interest_rate); $this->closing_interest = NumberUtils::rounds($this->closing_interest_unit * $this->closing_diff, NumberUtils::NUM_ROUND); $this->closing_balance = $this->opening_balance + $this->capital + $this->closing_interest; // calculate Interest of current date $this->now_interest_unit = NumberUtils::getInterest($this->opening_balance, $this->noterm_interest_rate); $delta = $this->now_diff - $this->closing_diff; if ($delta < 0) { $this->now_interest = NumberUtils::rounds($this->now_interest_unit * $this->now_diff, NumberUtils::NUM_ROUND); } else { $this->now_interest = $this->closing_interest + NumberUtils::getInterest($this->closing_balance, $this->noterm_interest_rate, NumberUtils::NUM_ROUND, $delta); } $this->now_balance = $this->opening_balance + $this->capital + $this->now_interest; }
/** * @param OefPurchase $purchase * @param OefFundCertificate $condition */ public function initialize($purchase, $condition) { $this->purchase_id = $purchase->id; $this->purchase_date = DateTimeUtils::getDateFromDB($purchase->purchase_date); $this->purchase_type = $purchase->purchase_type; $this->sellable_certificate = $purchase->found_stock - $purchase->found_stock_sold; $this->sell_date = $condition->sell_date_obj; $sellCertificate = $condition->sell_certificate - $condition->sum_sell_certificate; $this->sell_certificate = $sellCertificate < $this->sellable_certificate ? $sellCertificate : $this->sellable_certificate; $this->investment = $this->sell_certificate * ($purchase->purchase + $purchase->transfer_fee + $purchase->other_fee) / $purchase->found_stock; $this->revenue = $this->sell_certificate * $condition->nav; $this->kept_months = DateTimeUtils::diffMonths($this->purchase_date, $this->sell_date); $this->income_tax_rate = $condition->income_tax_rate; $this->calculate(); }
return ['style' => 'vertical-align: middle; text-align: right', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) { return NumberUtils::format($model->interest_unit, 2); }], ['label' => Yii::t('fin.grid', 'Days'), 'headerOptions' => ['style' => 'text-align: center'], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: center', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) { $startDate = DateTimeUtils::parse($model->start_date, DateTimeUtils::FM_DB_DATE); $endDate = is_null($model->end_date) ? DateTimeUtils::getNow() : DateTimeUtils::parse($model->end_date, DateTimeUtils::FM_DB_DATE); $interval = $endDate->diff($startDate); $days = ($interval->invert === 1 ? 1 : -1) * $interval->days + 1; return $days; }], ['label' => Yii::t('fin.grid', 'Interest'), 'headerOptions' => ['style' => 'text-align: center'], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: right', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) { $startDate = DateTimeUtils::parse($model->start_date, DateTimeUtils::FM_DB_DATE); $endDate = is_null($model->end_date) ? DateTimeUtils::getNow() : DateTimeUtils::parse($model->end_date, DateTimeUtils::FM_DB_DATE); $interval = $endDate->diff($startDate); $days = ($interval->invert === 1 ? 1 : -1) * $interval->days + 1; return NumberUtils::format($model->interest_unit * $days, 2); }], ['label' => Yii::t('fin.grid', 'Action'), 'headerOptions' => ['style' => 'text-align: center; width: 100px;'], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: center', 'class' => MasterValueUtils::getColorRow($index)]; }, 'format' => 'raw', 'value' => function ($model, $key, $index) { $btnClass = MasterValueUtils::getColorRow($index); $lblView = Yii::t('button', 'View'); $lblEdit = Yii::t('button', 'Edit'); $lblCopy = Yii::t('button', 'Copy'); $arrBtns = []; $entryId = $model->id; $urlEdit = BaseUrl::toRoute(['interest/update', 'id' => $entryId]); $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlEdit, $lblEdit]); $urlView = BaseUrl::toRoute(['interest/view', 'id' => $entryId]);
</div> </div></div> <?php ActiveForm::end(); ?> </div> <div class="box-body-notool"> <div class="row"><?php Pjax::begin(); echo GridView::widget(['layout' => '{summary}<div class="table-responsive">{items}</div>{pager}', 'options' => ['class' => 'grid-view col-xs-12'], 'tableOptions' => ['class' => 'table table-bordered'], 'pager' => ['options' => ['class' => 'pagination pagination-bottom'], 'maxButtonCount' => 6], 'dataProvider' => new ActiveDataProvider(['query' => $dataQuery, 'pagination' => ['pagesize' => 20]]), 'columns' => [['label' => Yii::t('fin.grid', 'Ref'), 'headerOptions' => ['style' => 'text-align: center'], 'contentOptions' => ['style' => 'vertical-align: middle; text-align: center'], 'format' => 'raw', 'value' => function ($model, $key, $index, $column) { $pagination = $column->grid->dataProvider->pagination; $html = $pagination->page * $pagination->pageSize + $index + 1; $html .= '<br/>' . str_pad($model->nav_id, 6, '0', STR_PAD_LEFT); return $html; }], ['label' => Yii::t('fin.grid', 'Trade'), 'headerOptions' => ['style' => 'text-align: center'], 'contentOptions' => ['style' => 'vertical-align: middle; text-align: center'], 'format' => 'raw', 'value' => function ($model) { $html = DateTimeUtils::htmlDateFormatFromDB($model->trade_date, DateTimeUtils::FM_VIEW_DATE, true); $lblView = Yii::t('button', 'View'); $lblEdit = Yii::t('button', 'Edit'); $urlEdit = null; $arrBtns = []; $entryId = $model->nav_id; $urlEdit = BaseUrl::toRoute(['nav/update', 'id' => $entryId]); $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlEdit, $lblEdit]); $urlView = BaseUrl::toRoute(['nav/view', 'id' => $entryId]); $arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlView, $lblView]); $html .= '<br/><div class="btn-group">'; $html .= Html::a($lblEdit, [$urlEdit], ['class' => 'btn btn-xs btn-info']); $html .= '<button type="button" class="btn btn-xs btn-info dropdown-toggle" data-toggle="dropdown">'; $html .= '<span class="caret"></span><span class="sr-only">Toggle Dropdown</span>'; $html .= '</button>'; $html .= '<ul class="dropdown-menu" role="menu">';
</div> <div class="row"><?php Pjax::begin(); echo GridView::widget(['options' => ['class' => 'grid-view col-xs-12 table-responsive'], 'tableOptions' => ['class' => 'table table-bordered'], 'showFooter' => true, 'headerRowOptions' => ['class' => 'warning'], 'footerRowOptions' => ['class' => 'warning', 'style' => 'font-weight:bold'], 'dataProvider' => new ActiveDataProvider(['query' => $dataQuery, 'pagination' => ['pagesize' => 20]]), 'columns' => [['label' => Yii::t('fin.grid', 'No.'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right', 'colspan' => 2], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: center', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model, $key, $index, $column) { $pagination = $column->grid->dataProvider->pagination; return $pagination->page * $pagination->pageSize + $index + 1; }, 'footer' => Yii::t('fin.grid', 'Total')], ['class' => DataColumn::className(), 'label' => Yii::t('fin.grid', 'Reference'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['colspan' => 0], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: center', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) { return str_pad($model->entry_id, 6, '0', STR_PAD_LEFT); }], ['attribute' => 'entry_date', 'label' => Yii::t('fin.grid', 'Transaction Date'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right'], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: center', 'class' => MasterValueUtils::getColorRow($index)]; }, 'format' => 'raw', 'value' => function ($model) use($phpFmShortDate) { return DateTimeUtils::htmlDateFormatFromDB($model->entry_date, DateTimeUtils::FM_VIEW_DATE, true); }, 'footer' => $htmlFooterCreditBalance], ['label' => Yii::t('fin.grid', 'Debit Account'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right', 'colspan' => 2], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: left', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) use($arrFinAccount) { return isset($arrFinAccount[$model->account_source]) ? $arrFinAccount[$model->account_source] : ''; }, 'footer' => $htmlFooterDebit], ['class' => DataColumn::className(), 'label' => Yii::t('fin.grid', 'Debit Amount'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['colspan' => 0], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: right', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) { $amount = $model->account_source == 0 ? '' : NumberUtils::format($model->entry_value); return $amount; }], ['label' => Yii::t('fin.grid', 'Credit Account'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right', 'colspan' => 2], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: left', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) use($arrFinAccount) { return isset($arrFinAccount[$model->account_target]) ? $arrFinAccount[$model->account_target] : ''; }, 'footer' => $htmlFooterCredit], ['class' => DataColumn::className(), 'label' => Yii::t('fin.grid', 'Credit Amount'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['colspan' => 0], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: right', 'class' => MasterValueUtils::getColorRow($index)];
<th class="warning" style="width: 200px;"><?php echo $model->getAttributeLabel('customer_id'); ?> </th> <td class="info"><?php echo isset($arrNetCustomer[$model->customer_id]) ? $arrNetCustomer[$model->customer_id] : ''; ?> </td> </tr> <tr> <th class="warning"><?php echo $model->getAttributeLabel('entry_date'); ?> </th> <td class="info"><?php echo DateTimeUtils::htmlDateFormat($model->entry_date, DateTimeUtils::FM_VIEW_DATE_WD, $fmShortDatePhp, true); ?> </td> </tr> <tr> <th class="warning"><?php echo $model->getAttributeLabel('credit'); ?> </th> <td class="info"><?php echo NumberUtils::format($model->credit); ?> </td> </tr> </table> <div style="display: none">
?> "> <td style="vertical-align: middle; text-align: center"><?php echo $item->item_no; ?> </td> <td style="vertical-align: middle; text-align: left"><?php echo $item->item_name; ?> </td> <td style="vertical-align: middle; text-align: right"><?php echo NumberUtils::format($item->price); ?> </td> <td style="vertical-align: middle; text-align: left"><?php echo DateTimeUtils::htmlDateFormat($item->pay_date, DateTimeUtils::FM_VIEW_DATE, DateTimeUtils::FM_DB_DATE, true); ?> </td> <td style="vertical-align: middle; text-align: left"><?php echo $item->description; ?> </td> </tr> <?php } ?> </tbody> </table> </div></div></div></div></div> </div></div></div><?php }
/** * 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; }
echo Yii::t('fin.grid', 'Cost'); ?> </th> </tr> <?php foreach ($arrModel as $model) { ?> <?php $rowClass = MasterValueUtils::getColorRow($rowindex); $rowindex++; $startDateStr = ''; $diffDays = ''; $diffFull = ''; if (!is_null($model->start_date)) { $startDate = DateTimeUtils::parse($model->start_date, DateTimeUtils::FM_DB_DATETIME); $startDateStr = DateTimeUtils::htmlDateTimeFormatFromDB($model->start_date, DateTimeUtils::FM_VIEW_DATE, true); $interval = $currentDate->diff($startDate); $diffDays = $interval->days; $diffFull = $interval->format('%Y-%M-%D %H:%I:%S'); } $costAll = ''; $costDay = ''; if (!is_null($model->costs)) { $costAll = NumberUtils::format($model->costs); if ($diffDays > 0) { $costDay = NumberUtils::format($model->costs / $diffDays, 2); } } ?> <tr class="<?php echo $rowClass;
/** * update a Payment * @param $paymentModel * @param $fmDateTimePhp * @throws Exception * @return string|true */ private function updatePayment($paymentModel, $fmDateTimePhp) { // modify data for DB $paymentModel->entry_date = DateTimeUtils::parse($paymentModel->entry_date, $fmDateTimePhp, DateTimeUtils::FM_DB_DATE); $transaction = Yii::$app->db->beginTransaction(); $save = true; $message = null; // begin transaction try { // save Customer $customer = NetCustomer::findOne(['id' => $paymentModel->customer_id]); if ($save !== false && !is_null($customer)) { $customer->balance = $customer->balance + $paymentModel->credit - $paymentModel->credit_old; $save = $customer->save(); } // save Payment if ($paymentModel->entry_date == $paymentModel->entry_date_old) { $paymentModel->secret_key = EnDescrypt::encryptSha1($paymentModel->customer_id . $paymentModel->entry_date); $save = $paymentModel->save(false); } else { if ($paymentModel->debit > 0) { // save new Payment $newSecretKey = EnDescrypt::encryptSha1($paymentModel->customer_id . $paymentModel->entry_date); $newPaymentModel = new NetPayment(); $newPaymentModel->customer_id = $paymentModel->customer_id; $newPaymentModel->entry_date = $paymentModel->entry_date; $newPaymentModel->credit = $paymentModel->credit; $newPaymentModel->debit = 0; $newPaymentModel->order_id = 0; $newPaymentModel->secret_key = $newSecretKey; $save = $newPaymentModel->save(false); // save old Payment if ($save !== false) { $paymentModel->entry_date = $paymentModel->entry_date_old; $paymentModel->credit = 0; $paymentModel->secret_key = EnDescrypt::encryptSha1($paymentModel->customer_id . $paymentModel->entry_date_old); $save = $paymentModel->save(false); $paymentModel->secret_key = $newSecretKey; } } else { $paymentModel->secret_key = EnDescrypt::encryptSha1($paymentModel->customer_id . $paymentModel->entry_date); $save = $paymentModel->save(false); } } } 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; }
$arrBtns[] = StringUtils::format('<li><a href="{0}">{1}</a></li>', [$urlView, $lblView]); $html .= '<br/><div class="btn-group">'; $html .= Html::a($lblEdit, [$urlEdit], ['class' => 'btn btn-xs btn-info']); $html .= '<button type="button" class="btn btn-xs btn-info dropdown-toggle" data-toggle="dropdown">'; $html .= '<span class="caret"></span><span class="sr-only">Toggle Dropdown</span>'; $html .= '</button>'; $html .= '<ul class="dropdown-menu" role="menu">'; $html .= implode('', $arrBtns); $html .= '</ul></div>'; return $html; }, 'footer' => $htmlFooterCredit], ['label' => Yii::t('fin.grid', 'Credit / Debit'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right'], 'contentOptions' => ['style' => 'vertical-align: middle; text-align: left'], 'format' => 'raw', 'value' => function ($model) { $htmls = []; if ($model->credit > 0) { $htmls[] = '<span class="label label-info pull-right">' . NumberUtils::format($model->credit) . '</span>'; } if ($model->debit > 0) { $htmls[] = '<span class="label label-danger pull-right">' . NumberUtils::format($model->debit) . '</span>'; } return implode('<br/>', $htmls); }, 'footer' => $htmlFooterDebit], ['label' => Yii::t('fin.grid', 'Bill Date'), 'headerOptions' => ['style' => 'text-align: center'], 'contentOptions' => ['style' => 'vertical-align: middle; text-align: center'], 'format' => 'raw', 'value' => function ($model) { if ($model->order_id > 0 && !is_null($model->bill_date)) { $urlEdit = BaseUrl::toRoute(['bill/update', 'id' => $model->order_id]); return StringUtils::format('<a href="{0}">{1}</a>', [$urlEdit, DateTimeUtils::htmlDateFormatFromDB($model->bill_date, DateTimeUtils::FM_VIEW_DATE, true)]); } return ''; }]]]); Pjax::end(); ?> </div></div> </div></div></div>
<th class="warning" style="width: 200px;"><?php echo $model->getAttributeLabel('share_id'); ?> </th> <td class="info"><?php echo $model->share_id; ?> </td> </tr> <tr> <th class="warning"><?php echo $model->getAttributeLabel('share_date'); ?> </th> <td class="info"><?php echo DateTimeUtils::htmlDateFormat($model->share_date, DateTimeUtils::FM_VIEW_DATE_WD, DateTimeUtils::FM_DB_DATE, true); ?> </td> </tr> <tr> <th class="warning"><?php echo $model->getAttributeLabel('share_value'); ?> </th> <td class="info"><?php echo NumberUtils::format($model->share_value); ?> </td> </tr> <tr> <th class="warning"><?php
public function actionCopy($id) { $this->objectId = $id; $model = FinTimeDepositTran::findOne(['transactions_id' => $id, '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', 'Fixed Deposit')])); } else { // master value $phpFmShortDate = DateTimeUtils::getPhpDateFormat(); $arrTimedepositTrantype = MasterValueUtils::getArrData('fin_timedeposit_trantype'); $arrSavingAccount = ModelUtils::getArrData(FinAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => 0, 'account_type' => 4])->orderBy('account_type, order_num'), 'account_id', 'account_name'); $arrCurrentAssets = ModelUtils::getArrData(FinAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => 0, 'account_type' => [1, 2]])->orderBy('account_type, order_num'), 'account_id', 'account_name'); // 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); // reset value if (Yii::$app->request->getIsGet()) { $openingDate = DateTimeUtils::getDateFromDB($model->opening_date); $closingDate = DateTimeUtils::getDateFromDB($model->closing_date); $dateDiff = $closingDate->diff($openingDate); $interval = 'P' . $dateDiff->m . 'M'; DateTimeUtils::addDateTime($closingDate, $interval, null, false); $model->opening_date = $model->closing_date; $model->closing_date = $closingDate->format(DateTimeUtils::FM_DB_DATE); $model->interest_add = 0; $model->add_flag = MasterValueUtils::MV_FIN_TIMEDP_TRANTYPE_ADDING; } // init value FinTimeDepositTran::$_PHP_FM_SHORTDATE = $phpFmShortDate; FinTimeDepositTran::$_ARR_SAVING_ACOUNT = $arrSavingAccount; $model->scenario = MasterValueUtils::SCENARIO_COPY; $renderData = ['model' => $model, 'phpFmShortDate' => $phpFmShortDate, 'arrTimedepositTrantype' => $arrTimedepositTrantype, 'arrSavingAccount' => $arrSavingAccount, 'arrCurrentAssets' => $arrCurrentAssets]; 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->copyFixedDeposit($model); if ($result === true) { Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('fin.models', 'Fixed Deposit')])); 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); }
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]); }
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); }
/** * update Payment * @param $payment JarPayment * @param $fmShortDatePhp * @throws Exception * @return string|true */ private function updatePayment($payment, $fmShortDatePhp) { // modify data for DB $payment->entry_date = DateTimeUtils::parse($payment->entry_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); $transaction = Yii::$app->db->beginTransaction(); $save = true; $message = null; // begin transaction try { $accountSource = JarAccount::findOne($payment->account_source); $accountTarget = JarAccount::findOne($payment->account_target); if ($payment->account_source == 0 || $payment->account_target == 0) { // save source if (!is_null($accountSource) && $save !== false) { $accountSource->real_balance = $accountSource->real_balance - $payment->entry_adjust; $accountSource->useable_balance = $accountSource->useable_balance - $payment->entry_adjust; $save = $accountSource->save(); } // save target if (!is_null($accountTarget) && $save !== false) { $accountTarget->real_balance = $accountTarget->real_balance + $payment->entry_adjust; $accountTarget->useable_balance = $accountTarget->useable_balance + $payment->entry_adjust; $save = $accountTarget->save(); } } else { // save source if ($save !== false) { $accountSource->useable_balance = $accountSource->useable_balance - $payment->entry_adjust; $save = $accountSource->save(); } // save target if ($save !== false) { $accountTarget->useable_balance = $accountTarget->useable_balance + $payment->entry_adjust; $save = $accountTarget->save(); } } // save payment if ($save !== false) { $payment->entry_value = $payment->entry_value + $payment->entry_adjust; $save = $payment->save(); } } catch (Exception $e) { $save = false; $message = Yii::t('common', 'Unable to save {record}.', ['record' => Yii::t('jar.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; }
/** * @param OefPurchase $purchase * @param OefFundCertificate $condition */ public function initialize($purchase, $condition) { $this->sip_date = DateTimeUtils::getDateFromDB($purchase->sip_date); $this->sip_months = DateTimeUtils::diffMonths($this->sip_date, $condition->sell_date_obj); parent::initialize($purchase, $condition); }
/** * update Distribute * @param $share JarShare * @param $arrShareDetail JarShareDetail * @param $fmShortDatePhp * @throws Exception * @return string|true */ private function updateDistribute($share, $arrShareDetail, $fmShortDatePhp) { // modify data for DB $share->share_date = DateTimeUtils::parse($share->share_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); $transaction = Yii::$app->db->beginTransaction(); $save = true; $message = null; // begin transaction try { // save JarShare $save = $share->save(); if ($save !== false) { foreach ($arrShareDetail as $shareDetail) { // save JarAccount $account = JarAccount::findOne($shareDetail->account_id); $account->real_balance = $account->real_balance - $shareDetail->share_value_old + $shareDetail->share_value; $account->useable_balance = $account->useable_balance - $shareDetail->share_value_old + $shareDetail->share_value; $save = $account->save(); if ($save === false) { break; } // save JarPayment $payment = JarPayment::findOne(['account_target' => $shareDetail->account_id, 'share_id' => $share->share_id]); $payment->entry_date = $share->share_date; $payment->entry_value = $shareDetail->share_value; $payment->description = $share->description; $save = $payment->save(); if ($save === false) { break; } } } } catch (Exception $e) { $save = false; $message = Yii::t('common', 'Unable to save {record}.', ['record' => Yii::t('jar.models', 'Distribute')]); } // 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; }
/** * save Nav * @param $nav OefNav * @param $fmShortDatePhp * @throws Exception * @return string|true */ private function saveNav($nav, $fmShortDatePhp) { // modify data for DB $nav->trade_date = DateTimeUtils::parse($nav->trade_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); $nav->decide_date = DateTimeUtils::parse($nav->decide_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); $transaction = Yii::$app->db->beginTransaction(); $save = true; $message = null; // begin transaction try { // save Nav $save = $nav->save(); } catch (Exception $e) { $save = false; $message = Yii::t('common', 'Unable to save {record}.', ['record' => Yii::t('oef.models', 'Nav')]); } // 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; }
$htmlAction = '<div class="btn-group">'; $htmlAction .= StringUtils::format("<a href='javascript:void(0)' onclick='editBillItem(this);' data-maps='{0}' class='btn btn-{1}'>{2}</a>", [$datasetUpdateStr, $btnClass, $lblEdit]); $htmlAction .= '<button type="button" class="btn btn-' . $btnClass . ' dropdown-toggle" data-toggle="dropdown">'; $htmlAction .= '<span class="caret"></span><span class="sr-only">Toggle Dropdown</span>'; $htmlAction .= '</button>'; $htmlAction .= '<ul class="dropdown-menu" role="menu">'; $htmlAction .= implode('', $arrBtns); $htmlAction .= '</ul></div>'; // show error columns $colItemNameStyle = ''; $colPriceStyle = ''; $colPayDateStyle = ''; $colDescriptionStyle = ''; $htmlItemName = $item->item_name; $htmlPrice = is_numeric($item->price) ? NumberUtils::format($item->price) : $item->price; $htmlPayDate = empty($item->pay_date) ? '' : DateTimeUtils::htmlDateFormat($item->pay_date, DateTimeUtils::FM_VIEW_DATE_WD, $fmShortDatePhp, true); $htmlDescription = $item->description; if (!$item->is_valid) { $errorItemName = $item->getErrors('item_name'); if (count($errorItemName) > 0) { $colItemNameStyle = ' class="danger"'; $htmlItemName = '<i class="fa fa-question-circle" data-toggle="tooltip" data-placement="top" title="' . $errorItemName[0] . '"></i> ' . $htmlItemName; } $errorPrice = $item->getErrors('price'); if (count($errorPrice) > 0) { $colPriceStyle = ' class="danger"'; $htmlPrice = '<i class="fa fa-question-circle" data-toggle="tooltip" data-placement="top" title="' . $errorPrice[0] . '"></i> ' . $htmlPrice; } $errorPayDate = $item->getErrors('pay_date'); if (count($errorPayDate) > 0) { $colPayDateStyle = ' class="danger"';
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); }
<th class="warning"><?php echo $model->getAttributeLabel('opening_date'); ?> </th> <td class="info"><?php echo DateTimeUtils::htmlDateFormatFromDB($model->opening_date, DateTimeUtils::FM_VIEW_DATE_WD, true); ?> </td> </tr> <tr> <th class="warning"><?php echo $model->getAttributeLabel('closing_date'); ?> </th> <td class="info"><?php echo DateTimeUtils::htmlDateFormatFromDB($model->closing_date, DateTimeUtils::FM_VIEW_DATE_WD, true); ?> </td> </tr> <tr> <th class="warning"><?php echo $model->getAttributeLabel('interest_days'); ?> </th> <td class="info"><?php echo $dateDiff->days; ?> </td> </tr> <tr> <th class="warning"><?php
/** * @param OefFundCertificate $condition * @param String $fmShortDatePhp * @return array */ private function getFundCertificate4Sell($condition, $fmShortDatePhp) { $condition->sum_sell_certificate = 0; $condition->investment = 0; $condition->sellable_certificate = 0; $condition->revenue = 0; $condition->sell_fee = 0; $condition->profit_before_taxes = 0; $condition->income_tax = 0; $condition->profit_after_taxes = 0; $condition->investment_result = 0; $sqlLimit = 3; $sqlOffset = 0; $results = []; $condition->sell_date_obj = DateTimeUtils::parse($condition->sell_date, $fmShortDatePhp); $running = true; while ($running) { $arrOefPurchase = OefPurchase::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere('found_stock > found_stock_sold')->addOrderBy(['purchase_date' => SORT_ASC])->offset($sqlOffset)->limit($sqlLimit)->all(); $running = count($arrOefPurchase) > 0; if ($running) { foreach ($arrOefPurchase as $oefPurchase) { $result = null; switch ($oefPurchase->purchase_type) { case MasterValueUtils::MV_OEF_PERCHASE_TYPE_NORMAL: $result = new OefFundCertificateNormal(); break; case MasterValueUtils::MV_OEF_PERCHASE_TYPE_SIP: $result = new OefFundCertificateSip(); break; case MasterValueUtils::MV_OEF_PERCHASE_TYPE_DIVIDEND: $result = new OefFundCertificateDividend(); break; case MasterValueUtils::MV_OEF_PERCHASE_TYPE_IPO: $result = new OefFundCertificateIpo(); break; } if (!is_null($result)) { $result->initialize($oefPurchase, $condition); $results[] = $result; $condition->investment += $result->investment; $condition->sellable_certificate += $result->sellable_certificate; $condition->sum_sell_certificate += $result->sell_certificate; $condition->revenue += $result->revenue; $condition->sell_fee += $result->sell_fee; $condition->profit_before_taxes += $result->profit_before_taxes; $condition->income_tax += $result->income_tax; $condition->profit_after_taxes += $result->profit_after_taxes; $condition->investment_result += $result->investment_result; $running = $condition->sum_sell_certificate < $condition->sell_certificate; if (!$running) { break; } } } $sqlOffset += $sqlLimit; } } return $results; }
?> <br/> <?php echo $deposits->account_name; ?> </td> <td style="text-align: right; vertical-align: middle;"> <?php echo $deposits->closing_diff; ?> <?php echo Yii::t('fin.grid', '(days)'); ?> <br/> <?php echo DateTimeUtils::formatDateTimeFromDB($deposits->closing_date, DateTimeUtils::FM_VIEW_DATE); ?> </td> <td style="text-align: right; vertical-align: middle;"> <?php echo NumberUtils::format($deposits->closing_interest); ?> <br/> <?php echo NumberUtils::format($deposits->closing_balance); ?> </td> </tr> <?php } ?>
}, 'value' => function ($model, $key, $index, $column) { $pagination = $column->grid->dataProvider->pagination; return $pagination->page * $pagination->pageSize + $index + 1; }, 'footer' => Yii::t('fin.grid', 'Total')], ['class' => DataColumn::className(), 'label' => Yii::t('fin.grid', 'Reference'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['colspan' => 0], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: center', 'class' => MasterValueUtils::getColorRow($index)]; }, 'value' => function ($model) { return str_pad($model->id, 6, '0', STR_PAD_LEFT); }], ['class' => DataColumn::className(), 'label' => Yii::t('fin.grid', 'Transaction'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['colspan' => 0], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: center', 'class' => MasterValueUtils::getColorRow($index)]; }, 'format' => 'raw', 'value' => function ($model) { return DateTimeUtils::htmlDateFormatFromDB($model->purchase_date, DateTimeUtils::FM_VIEW_DATE, true); }], ['label' => Yii::t('fin.grid', 'Type'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right'], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: right', 'class' => MasterValueUtils::getColorRow($index)]; }, 'format' => 'raw', 'value' => function ($model) use($arrPurchaseType) { $html = $arrPurchaseType[$model->purchase_type]; $html .= is_null($model->sip_date) ? '' : ' ' . DateTimeUtils::htmlDateFormatFromDB($model->sip_date, DateTimeUtils::FM_VIEW_DATE, true); $html .= '<br/>' . NumberUtils::format($model->purchase); return $html; }, 'footer' => $htmlFooterRequest], ['label' => Yii::t('fin.grid', 'Fee Rate'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right'], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: right', 'class' => MasterValueUtils::getColorRow($index)]; }, 'format' => 'raw', 'value' => function ($model) { $totalFeeRate = $model->purchase_fee_rate * (100 - $model->discount_rate) / 100; $html = NumberUtils::format($totalFeeRate, 2); $html .= ' %<br/>' . NumberUtils::format($model->purchase_fee); return $html; }, 'footer' => $htmlFooterPurchaseFee], ['label' => Yii::t('fin.grid', 'NAV / Real'), 'headerOptions' => ['style' => 'text-align: center'], 'footerOptions' => ['style' => 'text-align: right'], 'contentOptions' => function ($model, $key, $index) { return ['style' => 'vertical-align: middle; text-align: right', 'class' => MasterValueUtils::getColorRow($index)]; }, 'format' => 'raw', 'value' => function ($model) { $html = NumberUtils::format($model->nav, 2); $html .= '<br/>' . NumberUtils::format($model->purchase - $model->purchase_fee); return $html;
<?php echo $model->getAttributeLabel('id'); ?> <span class="pull-right"><?php echo $model->id; ?> </span> </a></li><?php } ?> <li><a href="javascript:void(0);"> <?php echo $model->getAttributeLabel('entry_date'); ?> <?php echo DateTimeUtils::htmlDateFormat($model->entry_date, DateTimeUtils::FM_VIEW_DATE_WD, $fmShortDatePhp, ['class' => 'pull-right']); ?> </a></li> <li><a href="javascript:void(0);"> <?php echo $model->getAttributeLabel('account_source'); ?> <span class="pull-right"><?php echo isset($arrAccount[$model->account_source]) ? $arrAccount[$model->account_source] : ''; ?> </span> </a></li> <li><a href="javascript:void(0);"> <?php echo $model->getAttributeLabel('account_target'); ?>
/** * update a Bill * @param $model * @param $arrBillDetail * @param $fmShortDatePhp * @throws Exception * @return string|true */ private function updateBill($model, $arrBillDetail, $fmShortDatePhp) { // modify data for DB $model->bill_date = DateTimeUtils::parse($model->bill_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); $model->member_num = count($model->arr_member_list); $model->member_list = serialize($model->arr_member_list); $pricePerMember = NumberUtils::rounds($model->total / $model->member_num, NumberUtils::NUM_CEIL); $pricePerMemberOld = NumberUtils::rounds($model->total_old / $model->member_num_old, NumberUtils::NUM_CEIL); foreach ($arrBillDetail as $billDetail) { if (!$billDetail->delete_flag) { $billDetail->pay_date = DateTimeUtils::parse($billDetail->pay_date, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); } } $transaction = Yii::$app->db->beginTransaction(); $save = true; $message = null; // begin transaction try { // save Bill $save = $model->save(false); // save Bill Detail if ($save !== false) { // delete all Bill Detail NetBillDetail::deleteAll(['bill_id' => $model->id]); $itemNo = 1; foreach ($arrBillDetail as $billDetail) { if (!$billDetail->delete_flag) { $billDetail->setIsNewRecord(true); $billDetail->bill_id = $model->id; $billDetail->item_no = $itemNo; $itemNo++; $save = $billDetail->save(false); if ($save === false) { break; } } } } // save Customer & Payment if ($save !== false) { foreach ($model->arr_member_list_old as $oldCustomerId) { // save old Customer $oldCustomer = NetCustomer::findOne($oldCustomerId); $oldCustomer->balance = $oldCustomer->balance + $pricePerMemberOld; $save = $oldCustomer->save(false); if ($save === false) { break; } // save old Payment $oldPayment = NetPayment::findOne(['customer_id' => $oldCustomerId, 'order_id' => $model->id]); if (!is_null($oldPayment)) { if ($oldPayment->credit > 0) { $oldPayment->debit = 0; $oldPayment->order_id = 0; $save = $oldPayment->save(false); } else { $save = $oldPayment->delete(); } if ($save === false) { break; } } } if ($save !== false) { foreach ($model->arr_member_list as $customerId) { // save new Customer $customer = NetCustomer::findOne($customerId); $customer->balance = $customer->balance - $pricePerMember; $save = $customer->save(false); if ($save === false) { break; } // save new Payment $payment = NetPayment::findOne(['customer_id' => $customerId, 'entry_date' => $model->bill_date]); if (is_null($payment)) { $payment = new NetPayment(); $payment->customer_id = $customerId; $payment->entry_date = $model->bill_date; } $payment->debit = $pricePerMember; $payment->order_id = $model->id; $payment->secret_key = EnDescrypt::encryptSha1($payment->customer_id . $payment->entry_date); $save = $payment->save(false); if ($save === false) { break; } } } } } catch (Exception $e) { $save = false; $message = Yii::t('common', 'Unable to save {record}.', ['record' => Yii::t('fin.models', 'Bill')]); } // 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; }
</span> </a></li> <li><a href="javascript:void(0);"> <?php echo $model->getAttributeLabel('trade_date'); ?> <?php echo DateTimeUtils::htmlDateFormatFromDB($model->trade_date, DateTimeUtils::FM_VIEW_DATE_WD, ['class' => 'pull-right']); ?> </a></li> <li><a href="javascript:void(0);"> <?php echo $model->getAttributeLabel('decide_date'); ?> <?php echo DateTimeUtils::htmlDateFormatFromDB($model->decide_date, DateTimeUtils::FM_VIEW_DATE_WD, ['class' => 'pull-right']); ?> </a></li> <li><a href="javascript:void(0);"> <?php echo $model->getAttributeLabel('nav_value'); ?> <span class="pull-right badge bg-red"><?php echo NumberUtils::format($model->nav_value, 2); ?> </span> </a></li> <li><a href="javascript:void(0);"> <?php echo $model->getAttributeLabel('nav_value_prev'); ?>
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); }