| Current Path : /var/www/html/mmishra/iws8/html/mcell/report/ |
| Current File : /var/www/html/mmishra/iws8/html/mcell/report/report_audit.php.old |
<?php
//show page head
include "report_header.inc";
$item_type = $_REQUEST["item_type"];
$submit = $_POST["submit"];
$financial_year = $_REQUEST["financial_year"];
$fyear = (date("Y") - 1) . "-" . date("Y");
if ($financial_year == "") $financial_year = $fyear;
$date1 = substr($financial_year,0,4) . "-04-01";
$date2 = substr($financial_year,5,4) . "-03-31";
echo "<center><font color='red' size='+1'>Balance Sheet</font></center>";
echo "<div align='left'> Financial Year ";
echo "<select name='financial_year' onchange=\"javascript:document.location.href='" . $_SERVER["SCRIPT_NAME"] . "?item_type=$item_type&financial_year=' + this.value\">";
$rs = mysql_query("select financial_year from balance_sheet group by financial_year", $con);
while ($o = mysql_fetch_object($rs)){
$financial_year1 = $o->financial_year;
echo "<option value='$financial_year1'";
if ($financial_year1 == $financial_year) echo " selected";
echo ">$financial_year1</option>";
}
//echo "<option value='$fyear'>$fyear</option>";
//echo "<option value='2002-2003'>2002-2003</option>";
echo "</select>";
echo " ($date1 - $date2) </div>";
//delete old records
$rrs = mysql_query("delete from balance_sheet where financial_year='$financial_year'",$con);
echo "<table width='100%' border='1' cellspacing='0' cellpadding='1' bordercolordark='white' bordercolor='black' frame='box' id='id4'>";
echo "<tr><th rowspan='3'>Sr.</th><th rowspan='3'>Item</th><th rowspan='2' colspan='2'>Opening<br>Balance</th><th rowspan='2' colspan='2'>Total<br>Purchase</th><th colspan='8'>Consumption</th><th rowspan='2' colspan='2'>Closing<br>Balance</th></tr>";
echo "<tr><th colspan='2'>Fabrication</th><th colspan='2'>Replacement</th><th colspan='2'>Upgradation</th><th colspan='2'>Project</th></tr>";
echo "<tr><th>Qty</th><th>Value</th><th>Qty</th><th>Value</th><th>Qty</th><th>Value</th><th>Qty</th><th>Value</th><th>Qty</th><th>Value</th><th>Qty</th><th>Value</th><th>Qty</th><th>Value </th></tr>";
$toqty=0; $toval=0; $tpqty=0; $tpval=0; $tfqty=0; $tfval=0; $tuqty=0; $tuval=0; $trqty=0; $trval=0; $tjqty=0; $tjval=0; $tcqty=0; $tcval=0;
$brs = mysql_query("select * from balance_sheet where item_type='$item_type' and financial_year='$financial_year' order by item", $con);
if (!mysql_num_rows($brs)){
$sql1 = "select row_id,name from category_master where item_type='$item_type' order by name";
$rs1 = mysql_query($sql1, $con);
if(!$rs1) echo sql_error();
while ($qd1 = mysql_fetch_array($rs1)){
$cat_code = $qd1["row_id"];
$item = $qd1["name"];
//opening balance stock qty - stock on date1 means received before date1 and either in stock or issued after date2
$sql2 = "select pm.row_id as parts_code,im.unit_price,pm.status,im.receive_date from parts_master pm left join item_master im on pm.item_code=im.row_id where category_code=$cat_code and im.receive_date<='$date2'";
$rs2 = mysql_query($sql2, $con);
if(!$rs2) echo sql_error();
$oqty=0; $oval=0; $pqty=0; $pval=0; $fqty=0; $fval=0; $uqty=0; $uval=0; $rqty=0; $rval=0; $jqty=0; $jval=0; $cqty=0; $cval=0;
//iterate through the parts list
while ($qd2 = mysql_fetch_array($rs2)){
$parts_code = $qd2["parts_code"];
$status = $qd2["status"];
$uprice = $qd2["unit_price"];
$receive_date = $qd2["receive_date"];
if ($uprice == "") $uprice = 0;
//issued items
if ($status == "issued"){
$sql3 = "select * from parts_issued where parts_code=$parts_code";
$rs3 = mysql_query($sql3, $con);
if(!$rs3) echo sql_error();
//check issue date which must > date1
if (mysql_num_rows($rs3)){
$qd3 = mysql_fetch_array($rs3);
$issue_date = $qd3["issue_date"];
$used_for = $qd3["issue_for"];
$issued = "true";
}else{
$sql4 = "select * from pc_configuration where parts_code=$parts_code";
$rs4 = mysql_query($sql4, $con);
if(!$rs4) echo sql_error();
if (mysql_num_rows($rs4)){
$qd4 = mysql_fetch_array($rs4);
$issue_date = $qd4["issue_date"];
$used_for = $qd4["used_for"];
$issued = "true";
}
}
if ($issue_date>$date2){
$oqty++; $oval += $uprice;
$toqty += $oqty; $toval += $oval;
//closing balance for current financial year consumption in next year
$cqty++; $cval += $uprice;
$tcqty += $cqty; $tcval += $cval;
}else{
//items purchased between date1 and date2
if ($receive_date<='$date1' and $receive_date>='$date2'){
$pqty++; $pval += $uprice;
$tpqty += $pqty; $tpval += $pval;
}
$issued="false";
//opening balance items purchased before date1
if ($receive_date<$date1){
switch ($status){
case "issued":
if ($issue_date<$date1){
//previous financial year data
}else if ($issue_date>=$date1){
//purchased before date1 but used after date1
$oqty++; $oval += $uprice;
$toqty += $oqty; $toval += $oval;
$issued="true";
}
break;
case "old":
case "new":
case "reserved":
$oqty++; $oval += $uprice;
$toqty += $oqty; $toval += $oval;
//unused so closing balanace for this financial year
$cqty++; $cval += $uprice;
$tcqty += $cqty; $tcval += $cval;
break;
}
}else if ($receive_date<=$date2){//>date1
switch ($status){
case "issued":
if ($issue_date<$date2){
//current financial year consumption
$issued="true";
}else{//next financial year consumption
//purchased after date1 but before date2 and used after date2
$cqty++; $cval += $uprice;
$tcqty += $cqty; $tcval += $cval;
}
break;
case "old":
case "new":
case "reserved":
$cqty++; $cval += $uprice;
$tcqty += $cqty; $tcval += $cval;
break;
}
}
//consumption during date1 and date2
//check the issue date
if ($issued == "true"){
switch ($used_for){
case "fabrication":
$fqty++; $fval += $uprice;
$tfqty += $fqty; $tfval += $fval;
break;
case "upgradation":
$uqty++; $uval += $uprice;
$tuqty += $uqty; $tuval += $uval;
break;
case "replacement":
$rqty++; $rval += $uprice;
$trqty += $rqty; $trval += $rval;
break;
default:
$jqty++; $jval += $uprice;
$tjqty += $jqty; $tjval += $jval;
break;
}
}
}
}else{
//$oqty++; $oval += $uprice;
//$toqty += $oqty; $toval += $oval;
//$cqty++; $cval += $uprice;
//$tcqty += $cqty; $tcval += $cval;
}
}
$rrs = mysql_query("insert into balance_sheet (financial_year,item,item_type,opening_stock,opening_value,purchased_stock,purchased_value,fabricated_stock,fabricated_value,upgraded_stock,upgraded_value,replaced_stock,replaced_value,project_stock,project_value,closing_stock,closing_value) values('$financial_year','$item','$item_type',$oqty,$oval,$pqty,$pval,$fqty,$fval,$uqty,$uval,$rqty,$rval,$jqty,$jval,$cqty,$cval)",$con);
if (!$rrs) echo mysql_error();
}
}
$oqty=0; $oval=0; $pqty=0; $pval=0; $fqty=0; $fval=0; $uqty=0; $uval=0; $rqty=0; $rval=0; $jqty=0; $jval=0; $cqty=0; $cval=0;
$toqty=0; $toval=0; $tpqty=0; $tpval=0; $tfqty=0; $tfval=0; $tuqty=0; $tuval=0; $trqty=0; $trval=0; $tjqty=0; $tjval=0; $tcqty=0; $tcval=0;
$brs = mysql_query("select * from balance_sheet where financial_year='$financial_year' and item_type='$item_type' order by item", $con);
while ($o = mysql_fetch_object($brs)){
$item = $o->item;
$oqty = $o->opening_stock; $oval = $o->opening_value;
$toqty += $oqty; $toval += $oval;
$pqty = $o->purchased_stock; $pval = $o->purchased_value;
$tpqty += $pqty; $tpval += $pval;
$fqty = $o->fabricated_stock; $fval = $o->fabricated_value;
$tfqty += $fqty; $tfval += $fval;
$rqty = $o->replaced_stock; $rval = $o->replaced_value;
$trqty += $rqty; $trval += $rval;
$uqty = $o->upgraded_stock; $uval = $o->upgraded_value;
$tuqty += $uqty; $tuval += $uval;
$jqty = $o->project_stock; $jval = $o->project_value;
$tjqty += $jqty; $tjval += $jval;
$cqty = $o->closing_stock; $cval = $o->closing_value;
$tcqty += $cqty; $tcval += $cval;
$i++;
//show figures
echo "<tr><td>$i</td><td>$item</td>";
echo "<td align='right'>$oqty</td><td align='right'>$oval</td><td align='right'>$pqty</td><td align='right'>$pval</td>";
echo "<td align='right'>$fqty</td><td align='right'>$fval</td><td align='right'>$rqty</td><td align='right'>$rval</td><td align='right'>$uqty</td><td align='right'>$uval</td><td align='right'>$jqty</td><td align='right'>$jval</td>";
echo "<td align='right'>$cqty</td><td align='right'>$cval </td></tr>";
}
echo "<tr><td></td><td align='right'><b>Total</b></td><td align='right'>$toqty</td><td align='right'>Rs.$toval.00</td><td align='right'>$tpqty</td><td align='right'>Rs.$tpval.00</td><td align='right'>$tfqty</td><td align='right'>Rs.$tfval.00</td><td align='right'>$trqty</td><td align='right'>Rs.$trval.00</td><td align='right'>$tuqty</td><td align='right'>Rs.$tuval.00</td><td align='right'>$tjqty</td><td align='right'>Rs.$tjval.00</td><td align='right'>$tcqty</td><td align='right'>Rs.$tcval.00 </td></tr>";
echo "</table>";
echo '<p><p><input type="submit" name="submit" value="PRINT" onclick="window.print()">';
include "report_footer.inc";
?>