Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public function calculate()
 {
     $this->purchase_fee_rate = ParamUtils::getPurchaseFeeRate($this->purchase);
     $this->discount_rate = ParamUtils::getPurchaseFeeDiscountRate($this->purchase_type);
     $this->total_fee_rate = $this->purchase_fee_rate * (100 - $this->discount_rate) / 100;
     $this->purchase_fee_rule = ParamUtils::getPurchaseFeeRule();
     $this->purchase_fee = NumberUtils::rounds($this->purchase * $this->total_fee_rate / 100, $this->purchase_fee_rule);
     $this->real_purchase = $this->purchase - $this->purchase_fee;
     $this->found_stock_rule = ParamUtils::getFoundStockRule();
     $this->found_stock = NumberUtils::rounds(100 * ($this->real_purchase / $this->nav), $this->found_stock_rule) / 100;
     $this->investment = $this->purchase + $this->transfer_fee + $this->other_fee;
     if ($this->purchase_type == MasterValueUtils::MV_OEF_PERCHASE_TYPE_DIVIDEND) {
         $this->fin_entry_id = 0;
         $this->jar_payment_id = 0;
     }
 }
Exemplo n.º 3
0
            </a></li>
            <li><a href="javascript:void(0);">
                <?php 
    echo $model->getAttributeLabel('total');
    ?>
                <span class="pull-right badge bg-red"><?php 
    echo NumberUtils::format($model->total);
    ?>
</span>
            </a></li>
            <li><a href="javascript:void(0);">
                <?php 
    echo Yii::t('common', 'Price Per Member');
    ?>
                <span class="pull-right badge bg-red"><?php 
    echo NumberUtils::format(NumberUtils::rounds($model->total / $model->member_num, NumberUtils::NUM_CEIL));
    ?>
</span>
            </a></li>
        </ul>
    </div>
    <div class="widget-detail-header bg-maroon"><h3 class="widget-detail-title"><?php 
    echo Yii::t('fin.form', 'Customers List');
    ?>
</h3></div>
    <div class="box-footer"><div class="row"><div id="w0"><div id="w1" class="grid-view col-xs-12"><div class="table-responsive">
        <?php 
    $rowindex = 0;
    ?>
        <table class="table table-bordered">
            <thead><tr class="warning">
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * get list of JarShareDetail
  * @param $share JarShare
  * @param $backup boolean
  * @return array JarShareDetail
  */
 private function initShareDetail($share, $backup = false)
 {
     $results = null;
     if (is_null($share->share_id)) {
         $results = [];
         $arrAccount = JarAccount::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'account_type' => MasterValueUtils::MV_JAR_ACCOUNT_TYPE_JAR, 'status' => MasterValueUtils::MV_JAR_ACCOUNT_STATUS_ON])->orderBy('order_num')->all();
         $per = 1.0 * $share->share_value / 100;
         foreach ($arrAccount as $account) {
             $item = new JarShareDetail();
             $item->account_id = $account->account_id;
             $item->account_name = $account->account_name;
             $item->share_unit = $account->share_unit;
             $item->share_value = NumberUtils::rounds($per * $account->share_unit);
             $results[] = $item;
         }
     } else {
         $results = JarShareDetail::find()->select('d.*, a.account_name, p.entry_value AS share_value')->from('jar_share_detail d, jar_account a, jar_payment p')->where(['d.share_id' => $share->share_id, 'd.delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere('d.account_id = a.account_id AND d.share_id = p.share_id AND a.account_id = p.account_target')->orderBy('a.order_num')->all();
         if ($backup) {
             $per = 1.0 * $share->share_value / 100;
             foreach ($results as $result) {
                 $result->share_value_old = $result->share_value;
                 $result->share_value = NumberUtils::rounds($per * $result->share_unit);
             }
         }
     }
     return $results;
 }
Exemplo n.º 6
0
use yii\bootstrap\Alert;
use yii\helpers\Html;
use app\components\DateTimeUtils;
use app\components\MasterValueUtils;
use app\components\NumberUtils;
use app\components\StringUtils;
$formModeValue = $formMode[MasterValueUtils::PG_MODE_NAME];
$this->title = Yii::t('net.bill', 'Create Bill');
if ($formModeValue === MasterValueUtils::PG_MODE_EDIT) {
    $this->title = Yii::t('net.bill', 'Edit Bill');
} elseif ($formModeValue === MasterValueUtils::PG_MODE_COPY) {
    $this->title = Yii::t('net.bill', 'Copy Bill');
}
$rowindex = 0;
$memberCount = count($model->arr_member_list);
$pricePerMember = NumberUtils::rounds($model->total / $memberCount, NumberUtils::NUM_CEIL);
?>

<div class="box box-default"><?php 
$form = ActiveForm::begin(['requiredCssClass' => 'form-group-required']);
?>
    <div class="box-header with-border"><h3 class="box-title"><?php 
echo Yii::t('fin.form', 'Basic Info');
?>
</h3></div>
    <div id="netBillConfirmForm" class="box-body"><div class="row"><div class="col-md-12">
        <table class="table table-bordered">
            <tr>
                <th class="warning" style="width: 200px;"><?php 
echo $model->getAttributeLabel('bill_date');
?>