Thursday, September 22, 2011

Total For Final Salary sheet of Project

One thing which I forgot was total of each field  i.e gross, hra, cal salary, total wages, pf, esi etc. What I did, I declared an array named total in class finalsheet of page salarysheet.php

So Code Snippet got modified as below:-
<?php class finalsheet{
private $query= array();
private $result= array();
private $total= array();
private $calsal;
private $ded;
private $totwages;
private $netpay;
private $month;
public function seedata(){
$this->total[1]=0;
$this->total[2]=0;
$this->total[3]=0;
$this->total[4]=0;
$this->total[5]=0;
$this->total[6]=0;
$this->total[7]=0;
$this->total[8]=0;
$this->total[9]=0;
$this->total[10]=0;
$this->total[11]=0;
$this->month= date('n')-1;
$this->query[0]=mysql_query("Select id from worker_varys where month='$this->month'");
$count= mysql_num_rows($this->query[0]);
if($count==0){
echo "<script>var check= confirm('No data for updation');
if(check==true){
window.location='newsheet.php';}
else{
window.location='adminhome.php';}
</script>";
}
else{
$this->query[1]= mysql_query("Select workers.id as id, worker_fname, worker_lname, gross, hra, rate, workdays, pf, esi, advance from workers, worker_fixeds, worker_varys where workers.id=worker_fixeds.worker_id and workers.id=worker_varys.id and month='$this->month'");
if(!$this->query[1]){
header('location:qerror.php?op=uperror');
}
$this->i=1;
while($this->result[2]=mysql_fetch_array($this->query[1])){
if(($this->i)%2==0){
echo "<tr>";
}
else{
echo "<tr>";
}
echo "<input type='hidden' name=id[] value=".$this->result[2]['id']." />";
echo "<td>".$this->i."</td>";
echo "<td style='width:120px;'>".$this->result[2]['worker_fname'].' '.$this->result[2]['worker_lname']."</td>";
echo "<td>".$this->result[2]['gross']."</td>";
echo "<td>".$this->result[2]['rate']."</td>";
echo "<td>".$this->result[2]['workdays']."</td>";
$this->calsal= sprintf('%.2f',($this->result[2]['rate'])*($this->result[2]['workdays']));
echo "<td>".$this->calsal."</td>";
if($this->result[2]['workdays']<20){
echo "<td>0</td>";
$this->total[5]= sprintf('%.2f', ($this->total[5]) + 0);
$this->totwages=sprintf('%.2f',($this->calsal)+0);
echo "<td>".$this->totwages."</td>";
}
else{
echo "<td>".$this->result[2]['hra']."</td>";
$this->total[5]= sprintf('%.2f', ($this->total[5]) + ($this->result[2]['hra']));
$this->totwages=sprintf('%.2f',($this->calsal)+$this->result[2]['hra']);
echo "<td>".$this->totwages."</td>";
}
echo "<td>".$this->result[2]['pf']."</td>";
echo "<td>".$this->result[2]['esi']."</td>";
echo "<td>".$this->result[2]['advance']."</td>";
$this->ded=($this->result[2]['pf']+$this->result[2]['esi']+$this->result[2]['advance']);
echo "<td>".$this->ded."</td>";
$this->netpay= sprintf('%.2f',($this->totwages)-($this->ded));
echo "<td>".$this->netpay."</td>";
$this->total[1]= $this->total[1] + $this->result[2]['gross'];
$this->total[2]= sprintf('%.2f', ($this->total[2]) + ($this->result[2]['rate']));
$this->total[3]= sprintf('%.2f', ($this->total[3]) + ($this->result[2]['workdays']));
$this->total[4]= sprintf('%.2f', ($this->total[4]) + ($this->calsal));
$this->total[6]= sprintf('%.2f', ($this->total[6]) + ($this->totwages));
$this->total[7]= sprintf('%.2f', ($this->total[7]) + ($this->result[2]['pf']));
$this->total[8]= sprintf('%.2f', ($this->total[8]) + ($this->result[2]['esi']));
$this->total[9]= sprintf('%.2f', ($this->total[9]) + ($this->result[2]['advance']));
$this->total[10]= sprintf('%.2f', ($this->total[10]) + ($this->ded));
$this->total[11]= sprintf('%.2f', ($this->total[11]) + ($this->netpay));
echo "</tr>";
$this->i=$this->i+1;
}
echo '<tr><td colspan="2" align="right" style="font-size:medium;">Total
</td>';
echo '<td>'.$this->total[1].'</td>';
echo '<td>'.$this->total[2].'</td>';
echo '<td>'.$this->total[3].'</td>';
echo '<td>'.$this->total[4].'</td>';
echo '<td>'.$this->total[5].'</td>';
echo '<td>'.$this->total[6].'</td>';
echo '<td>'.$this->total[7].'</td>';
echo '<td>'.$this->total[8].'</td>';
echo '<td>'.$this->total[9].'</td>';
echo '<td>'.$this->total[10].'</td>';
echo '<td>'.$this->total[11].'</td></tr>';
}
}
}
$sh= new finalsheet();
$sh->seedata();
?>
And Below is the screen shot of fields that get total. It is clearly visible total being performed at last row.

[caption id="attachment_41" align="aligncenter" width="1024" caption="Total of Every Field of Salary sheet"][/caption]

No comments:

Post a Comment