/**
  * 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;
 }
Beispiel #2
0
 /**
  * this loan over repayment is probably deducted from a previous receipt
  * rather than this current one
  * 
  * @param \ContributionsByMembers $contribution model
  */
 public function probablyPreviousMonthlyContribution($contribution)
 {
     if ($contribution->amount > 0) {
         $theJustPrecedingContribution = $contribution->theJustPrecedingContribution($contribution->member, 2, $contribution->date, $contribution->receiptno);
         if (empty($theJustPrecedingContribution)) {
             //very unlikely to occur couz an over repayment occurs when there have been a previous payment
             $theJustPrecedingContribution = new ContributionsByMembers();
             $theJustPrecedingContribution->attributes = $contribution->attributes;
             $theJustPrecedingContribution->contribution_type = 2;
             $theJustPrecedingContribution->date = date('Y') . '-' . date('m') . '-' . date('d');
             $theJustPrecedingContribution->amount = 0;
             $theJustPrecedingContribution->receiptno = ContributionsByMembers::FALSE_RECEIPT;
             $theJustPrecedingContribution->receiptno_again = $theJustPrecedingContribution->receiptno;
         }
         $theJustPrecedingContribution->amount = $theJustPrecedingContribution->amount + $contribution->amount;
         $theJustPrecedingContribution->save(false);
     }
 }