/**
  * 
  * @param \CashWithdrawals $model Model
  */
 public function posts($model)
 {
     if (isset($_POST['CashWithdrawals'])) {
         $model->attributes = $_POST['CashWithdrawals'];
         CashWithdrawals::model()->dateThis($model);
         $this->approvals($model);
         if ($model->save()) {
             if ($model->effected_by_treasurer == CashWithdrawals::YES && !empty($model->treasurer_date) && $model->approved_by_chairman == CashWithdrawals::YES && !empty($model->chairman_date) && $model->received_by_secretary == CashWithdrawals::YES && !empty($model->secretary_date)) {
                 Expenditures::model()->cashWithdrawalIsExpense($model);
                 Savings::model()->cashWithdrawaltoSavings($model);
             }
             Yii::app()->user->setFlash('saved', 'The alteration has been succcessfully saved');
         }
     }
 }
Example #2
0
</font></td>
                                    <td style="width: 50px; text-align: right"><font size="8"><?php 
                echo $income->amount;
                $netIncomes = $netIncomes + $income->amount;
                ?>
</font></td>
                                </tr>

                                <?php 
                if ($member != ContributionsByMembers::PAYMENT_BY_CASH && $member != ContributionsByMembers::PAYMENT_BY_BANK) {
                    ?>
                                    <?php 
                    if ($income->trans_channes == Incomes::INCOME_BY_CONTRIBUTION || $income->trans_channes == Incomes::INCOME_BY_CASH_SAVING) {
                        ?>
                                        <?php 
                        $savingValues = Savings::model()->profitEarnedOrToBeEarnedOnSavingBetweenAndIncludingTheseDates($income->trans_channes == Incomes::INCOME_BY_CONTRIBUTION ? ContributionsByMembers::model()->savingIdForContribution($income->associated_id) : $income->associated_id, '0000-00-00', $till);
                        ?>
                                        <?php 
                        if (!empty($savingValues[Savings::INTEREST])) {
                            ?>
                                            <tr>
                                                <td style="width: 50px"><font size="8"><?php 
                            if ($income->date != $prvsDate) {
                                echo $income->date;
                            }
                            ?>
</font></td>
                                                <td style="width: 150px"><font size="8">Interest</font></td>
                                                <td style="width: 50px; text-align: right"><font size="8"><?php 
                            echo $savingValues[Savings::INTEREST];
                            $netIncomes = $netIncomes + $savingValues[Savings::INTEREST];
Example #3
0
 /**
  * 
  * @param type $member
  * @param date $since yyyy-mm-dd
  * @param date $till yyyy-mm-dd
  * @return array total incomes
  */
 public function totalIncomeFromMemberFromStartToIncludingThisDate($member, $since, $till)
 {
     $total = 0;
     $pendingSavings = 0;
     foreach ($this->incomesFromMemberBetweenAndIncludingThisDates($member, '0000-00-00', $since) as $income) {
         $total = $total + $income->amount;
         if ($income->trans_channes == self::INCOME_BY_CONTRIBUTION || $income->trans_channes == self::INCOME_BY_CASH_SAVING) {
             $savingValues = Savings::model()->profitEarnedOrToBeEarnedOnSavingBetweenAndIncludingTheseDates($savingId = $income->trans_channes == self::INCOME_BY_CONTRIBUTION ? ContributionsByMembers::model()->savingIdForContribution($income->associated_id) : $income->associated_id, '0000-00-00', $since);
             if (!empty($savingValues[Savings::INTEREST])) {
                 $total = $total + $savingValues[Savings::INTEREST];
                 if ($savingValues[Savings::REDUCING_BALANCE] > 0) {
                     $newSavingValues = Savings::model()->profitEarnedOrToBeEarnedOnSavingBetweenAndIncludingTheseDates($savingId, '0000-00-00', $till);
                     $latestSavingHistory = Savings::model()->latestSavingHistoryBetweenAndIncludingTheseDates($savingId, LoanApplications::model()->dayAfter($since), $till);
                     $pendingSavings = $pendingSavings + $newSavingValues[Savings::INTEREST] - (empty($latestSavingHistory) ? $savingValues[Savings::INTEREST] : 0);
                 }
             }
         }
     }
     return array('total' => $total, 'pendingSaving' => $pendingSavings);
 }
Example #4
0
 /**
  * 
  * @param int $withdrawer Member.
  * @param date $asAtThisDay By end of this date.
  * @return double Savings less Withdrawals
  */
 public function availableSavingsAsAtThisDate($withdrawer, $asAtThisDay)
 {
     $savings = floor(Savings::model()->membersAvailableSavingsAsAtThisDate($withdrawer, empty($asAtThisDay) ? date('Y') . '-' . date('m') . '-' . date('d') : $asAtThisDay));
     if (empty($savings)) {
         return '0';
     }
     return $savings;
 }
Example #5
0
 /**
  * 
  * @param \CashWithdrawals $cashWithdrawal model
  */
 public function cashWithdrawaltoSavings($cashWithdrawal)
 {
     $amountToBeWithdrawn = $cashWithdrawal->amount;
     if (empty($newSaving)) {
         foreach ($this->membersSavingsAsAtThisDate($cashWithdrawal->member, $cashWithdrawal->date) as $saving) {
             if ($amountToBeWithdrawn > 0) {
                 if ($this->canBeWithdrawn($saving)) {
                     $accumulatedAmount = LoanRepayments::model()->amountDue($saving->principal, $saving->interest_rate_per_annum, $saving->date_of_investment, $cashWithdrawal->date, 0);
                     $saving->date_of_withdrawal = $cashWithdrawal->date;
                     $saving->accumulated_amount = $accumulatedAmount;
                     $saving->amount_withdrawn = $cashWithdrawal->primaryKey;
                     $reducingAmountToBeWithdrawn = $accumulatedAmount >= $amountToBeWithdrawn ? $amountToBeWithdrawn : $amountToBeWithdrawn - $saving->accumulated_amount;
                     $amountToBeWithdrawn = $amountToBeWithdrawn - $reducingAmountToBeWithdrawn;
                     $saving->balance = $saving->accumulated_amount - $reducingAmountToBeWithdrawn;
                     $saving->can_be_withdrawn = self::WITHDRAWABLE_NO;
                     $saving->save(false);
                     if ($saving->balance > 0) {
                         $newSaving = new Savings();
                         $newSaving->member = $saving->member;
                         $newSaving->savings_id = $saving->savings_id;
                         $newSaving->principal = $saving->balance;
                         $newSaving->interest_rate_per_annum = ContributionsByMembers::SAVINGS_INTEREST;
                         $newSaving->date_of_investment = $cashWithdrawal->date;
                         $newSaving->can_be_withdrawn = self::WITHDRAWABLE_YES;
                         $newSaving->earliest_withdrawal_date = $newSaving->date_of_investment;
                         $newSaving->save(false);
                     }
                 }
             }
         }
     }
 }
Example #6
0
<?php

$id = Yii::app()->user->id;
?>

<?php 
if (Savings::model()->memberCanWithraw($id)) {
    ?>
    <li class="<?php 
    echo isset($_REQUEST['active']) && $_REQUEST['active'] == 'towako' ? 'active' : '';
    ?>
">
        <a
        <?php 
    if (isset($_REQUEST['active']) && $_REQUEST['active'] == 'towako') {
        ?>

                <?php 
    } else {
        ?>
                href="<?php 
        echo Yii::app()->createUrl('/cashWithdrawals/create', array('active' => 'towako'));
        ?>
"
            <?php 
    }
    ?>
            >
            <i class="icon-suitcase"></i>
            <span class="menu-text"> <?php 
    echo Lang::t('Withdraw Savings');
 /**
  * Save a contribution conditionally
  * then record a loan repayment appropriately
  * and update subsequent loan repayments.
  * 
  * @param \ContributionsByMembers $model
  * @param boolean $rectifySubsequentRepayments TRUE = Rectify Subsequent Loan Repayments; FALSE = Not Rectify Subsequent Loan Repayments
  */
 public function modelSave($model, $rectifySubsequentRepayments)
 {
     if (($new = $model->isNewRecord) && empty($model->amount)) {
     } else {
         if ($model->save()) {
             if ($model->contribution_type == 4 && $rectifySubsequentRepayments == true) {
                 LoanRepayments::model()->updateRepayments($model);
             }
             if ($new && $model->contribution_type == 3) {
                 Savings::model()->contributionToSavings($model);
             }
             Incomes::model()->contributionIsIncome($model);
             NextReceiptNo::model()->updateNextReceiptNo($model->receiptno);
             Yii::app()->user->setFlash('saved', 'Your contribution has been succcessfully saved');
             return true;
         }
     }
     return false;
 }
 /**
  * 
  * @param \Savings $savingsModels models
  * @param \Savings $depositsAndReinvestments savings isolated into deposits or reinvestments
  * @param \Savings $notWithdrawns savings that have not been withdrawn to date
  * @param array $evaluationDates dates when amounts are required 
  * @return array
  */
 public function savingsTransactions($savingsModels, $depositsAndReinvestments, $notWithdrawns, $evaluationDates)
 {
     $transactions = array();
     foreach ($evaluationDates as $evaluationDate) {
         $notWithdrawnsByThisDate = $this->savingsNotWithdrawnbyThisDate($savingsModels, $evaluationDate);
         $depositsMadeOnThisDate = $this->depositsOnThisDate($depositsAndReinvestments[ContributionsByMembers::DEPOSIT], $evaluationDate);
         $withdrawalsOnThisDate = $this->withdrawalsOnThisDate($savingsModels, $evaluationDate);
         $balanceCarriedForward = Savings::model()->computeTotalForOpenInvestments($notWithdrawnsByThisDate, $evaluationDate);
         $totalPrincipals = Savings::model()->totalDeposits($notWithdrawnsByThisDate);
         $totalDeposits = Savings::model()->totalDeposits($depositsMadeOnThisDate);
         $totalToDeductFrom = $balanceCarriedForward + $totalDeposits;
         $interest = round(isset($previousBalanceCarriedForward) ? $balanceCarriedForward - $previousBalanceCarriedForward : $balanceCarriedForward - $totalPrincipals, 3);
         if (isset($previousDate) && substr($previousDate, 0, 4) != substr($evaluationDate, 0, 4)) {
             $transactions[$count = count($transactions)] = $this->buildRow(null, null, null, null, null, null, null, null);
             $style = true;
         }
         if ($balanceCarriedForward > 0) {
             $transactions[$count = count($transactions)] = $this->buildRow(null, null, $increasingAmount = $previousBalanceCarriedForward = $balanceCarriedForward, $interest, null, null, Savings::INSTEAD_OF_RECEIPT, $evaluationDate);
             if (isset($style)) {
                 $transactions[$count - 2][Savings::STYLE] = true;
                 unset($style);
             }
         }
         foreach ($depositsMadeOnThisDate as $depositMadeOnThisDate) {
             $contribution = ContributionsByMembers::model()->findByPk($depositMadeOnThisDate->savings_id);
             $transactions[$count = count($transactions)] = $this->buildRow($depositMadeOnThisDate->principal, $depositMadeOnThisDate->interest_rate_per_annum, $increasingAmount = isset($increasingAmount) ? $increasingAmount + $depositMadeOnThisDate->principal : $depositMadeOnThisDate->principal, null, null, null, $contribution->receiptno, $evaluationDate);
         }
         if (!empty($withdrawalsOnThisDate)) {
             foreach ($withdrawalsOnThisDate as $withdrawalOnThisDate) {
                 $cashWithdrawal = CashWithdrawals::model()->findByPk($withdrawalOnThisDate->amount_withdrawn);
                 $transactions[$count = count($transactions)] = $this->buildRow(null, null, null, null, $previousBalanceCarriedForward = $totalToDeductFrom = $totalToDeductFrom - ($amountWithdrawn = $withdrawalOnThisDate->accumulated_amount - $withdrawalOnThisDate->balance), $amountWithdrawn, $cashWithdrawal->cash_or_cheque, $evaluationDate);
             }
             $transactions[$count = count($transactions)] = $this->buildRow(null, null, $transactions[$count - 1][Loanrepayments::REDUCING_BALANCE], null, null, null, null, null);
         }
         $previousDate = $evaluationDate;
     }
     if (!empty($transactions)) {
         $transactions[$count][Savings::STYLE] = true;
     }
     return $transactions;
 }