Exemplo n.º 1
0
 public function actionIndex()
 {
     $arrAccount = JarAccount::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'account_type' => MasterValueUtils::MV_JAR_ACCOUNT_TYPE_JAR])->orderBy('status, order_num')->all();
     $tempAccount = JarAccount::findOne(9);
     $sumAccountQuery = (new Query())->select(['SUM(useable_balance) AS useable_balance, SUM(real_balance) AS real_balance, SUM(share_unit) AS share'])->from('jar_account')->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'status' => MasterValueUtils::MV_JAR_ACCOUNT_STATUS_ON, 'account_type' => MasterValueUtils::MV_JAR_ACCOUNT_TYPE_JAR]);
     $sumAccountValue = $sumAccountQuery->createCommand()->queryOne();
     // render GUI
     $renderData = ['arrAccount' => $arrAccount, 'tempAccount' => $tempAccount, 'sumAccountValue' => $sumAccountValue];
     return $this->render('index', $renderData);
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
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;
 }