Hi,
in my fees module, i ve used beforesave() in my feestransaction model file.
but its not working.
i want that if course fees=15000 then when i am collecting fees, and if paidfees > 15000 then it will not save fess and give message for that…
for that i ve used beforesave()
here is my code…
public function beforeSave()
{
$fees_trans=FeesPaymentTransaction::findAll('fees_payment_student_id='.$_REQUEST['id']);
$query= new \yii\db\Query();
$query -> select(['batch_fees'])
-> from('batch as b')
-> join('join',
'course as c',
'b.course_id=c.course_id')
->where('b.batch_id='.StudentTransaction::findOne($_REQUEST['id'])->student_transaction_batch_id);
$command=$query->createCommand();
$total_payable=$command->queryOne();
$total=0;
foreach($fees_trans as $fee){
$total=$total+$fee->fees_payment_amount;
}
if($this->isNewRecord){
$total = $total+$this->fees_payment_amount;
}
else{
$oldfee = $fees_trans=FeesPaymentTransaction::findOne($_REQUEST['fees_id'])->fees_payment_amount;
$total = ($total-$oldfee)+$this->fees_payment_amount;
}
if($total > $total_payable['batch_fees'] ){
$this->addError('fees_payment_amount','<b style="color:red">You can not take an advance fees for student.</b>');
return false;
}
else
return true;
}
can u please suggest solution.
thanks.