<Am currently developing a school management system, in the school fees module I what to achieve the following objective
-
Once the student pay fee, the accountant enter the amount in the amount collect text field
-
The amount entered is assign to each raw by a loop that compared the amount of the item and the remaining amount is assign to the next item i.e $item Amount= school_fees_paid – item_amount
-
If $item Amount=0 THEN the item raw is assign zero
-
The whole grid view and the textfield on the form is submitted to the database
I have manage to do that in plain php like this.
<?php
$sum=0;
$ad=6; //i assumed this to be the amount entered by the accountanty
$a = array(1, 2, 3, 4, 5); //this are assumed to be the item that a student is supposed to pay
foreach ($a as $
{
?>
<?php
//echo $b."<br>";?><?php
$sum=$ad-$b; //minus the item amount from the school fees payed
//print "<br>".$b . " <br>";
if ($sum<=0){ //if the result if less or equal to zero the raw cell is automaticaly initialized by zero
echo ($sum=0)."<br>";
}
else{echo $b."<br>";}
$ad=$sum; //the next loop is assign with the result of the curre
//echo $ad;
}
?>
This is displaying correctly but when I use the following function the raws do not display correctly
The function I use is:
<?php
Yii::import(‘zii.widgets.grid.CDataColumn’);
Class SumColumn Extends CDataColumn {
public $name = 'amount';
public $sum = 0;
public function getHasFooter() {
return True;
}
public function renderDataCellContent($row, $data) {
$fee=1000;
$amount = $data->{$this->name};
//------------------minus the fee ammount from the amount assing-------------////////
foreach(array($amount) as $val){
$sum=$fee-$val;//minus the item amount from the school fees payed
$fee=$sum; //the new fee amount
}
//echo $sum;
$this->sum = $this->sum +(float)$amount;
echo $amount;
}
public function renderFooterCellContent() {
echo (float)$this->sum.'.'.'00';
}
}?>
figure 1
Problem
How can display accurate amount calculated on the amount column
How to save the data in the database>