Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/irp/irp/pcstore/
Upload File :
Current File : /var/www/html/mmishra/irp/irp/pcstore/audit_report.php

<?php
//show page head
include "page_header.inc";
//$db = $_REQUEST["db"];
$consumable = $_REQUEST["consumable"];
$submit = $_POST["submit"];
$date1 = $_REQUEST["date1"];
$date2 = $_REQUEST["date2"];
if ($date1 == "") $date1 = (date("Y") - 1) . "-04-01";
if ($date2 == "") $date2 = date("Y") . "-03-31";

echo "<center><font color='red' size='+1'>Balance Sheet</font><p>";
echo "From <input type='text' name='date1' value='$date1' size='10'> ";
echo "To <input type='text' name='date2' value='$date2' size='10'> ";
echo "<input type='submit' name='submit' value='OK'><input type='hidden' name='consumable' value='$consumable'><br>";
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<br>Description</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&nbsp;</th></tr>";

//previous financial year dates
$pdate1 = (substr($date1,0,4) - 1) . substr($date1,4);
$pdate2 = (substr($date2,0,4) - 1) . substr($date2,4);

$sql1 = "select row_id, description from category_master where consumable='$consumable' order by description";
$rs1 = mysql_query($sql1, $link_id);
if(!$rs1) echo sql_error();
while ($qd1 = mysql_fetch_array($rs1)){
  $i++;
  $cat_code = $qd1["row_id"];
  $desc = $cat_code . "-" . $qd1["description"];
  echo "<tr><td>$i</td><td>$desc</td>";

  //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<='$date1'";
  $rs2 = mysql_query($sql2, $link_id);
  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;

    //items purchased between date1 and date2
    if ($receive_date>=$date1 and $receive_date<=$date2){
      $pqty++;
      $pval += $uprice;
    }

    //opening balance items purchased before date1
    if ($receive_date<$date1){ 
      switch ($status){
        case "issued":
	  //check the issue date
          $sql3 = "select * from parts_issued where parts_code=$parts_code";
          $rs3 = mysql_query($sql3, $link_id);
          if(!$rs3) echo sql_error();
          $sql4 = "select * from pc_configuration where parts_code=$parts_code";
          $rs4 = mysql_query($sql4, $link_id);
          if(!$rs4) 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 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>=$date1){
            //purchased before date1 and used after date1
            $oqty++; $oval += $uprice;
          }
          break;
	case "old":
	case "new":
        case "reserved":
	  $oqty++; $oval += $uprice;
          break;
      }
    }else if ($receive_date<=$date2){
      switch ($status){
        case "issued":
          //check the issue date
          $sql3 = "select * from parts_issued where parts_code=$parts_code";
          $rs3 = mysql_query($sql3, $link_id);
          if(!$rs3) echo sql_error();
          $sql4 = "select * from pc_configuration where parts_code=$parts_code";
          $rs4 = mysql_query($sql4, $link_id);
          if(!$rs4) 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 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){
            //purchased after date1 before date2 and used after date2
            $cqty++; $cval += $uprice;
          }
          break;
        case "old":
        case "new":
        case "reserved":
          $cqty++; $cval += $uprice;
          break;
      }
   } 
    //consumption during date1 and date2
    //check the issue date
    $issued="false";
    $sql3 = "select * from parts_issued where parts_code=$parts_code";
    $rs3 = mysql_query($sql3, $link_id);
    if(!$rs3) echo sql_error();
    $sql4 = "select * from pc_configuration where parts_code=$parts_code";
    $rs4 = mysql_query($sql4, $link_id);
    if(!$rs4) echo sql_error();
    //check issue date which must > date1
    if (mysql_num_rows($rs3) != 0){
      $qd3 = mysql_fetch_array($rs3);
      $issue_date = $qd3["issue_date"];
      $used_for = $qd3["issue_for"];
      $issued = "true";
    }else if (mysql_num_rows($rs4) != 0){
      $qd4 = mysql_fetch_array($rs4);
      $issue_date = $qd4["issue_date"];
      $used_for = $qd4["used_for"];
      $issued = "true";
    }
    if ($issued=="true"){
      if ($issue_date>=$date1 and $issue_date<=$date2){
        switch ($used_for){
          case "fabrication":
            $fqty++; $fval += $uprice;
            break;
          case "upgradation":
            $uqty++; $uval += $uprice;
            break;
          case "replacement":
            $rqty++; $rval += $uprice;
            break;
          default:
            $jqty++; $jval += $uprice;
            break;
        }
      }	
    }
  }
  $toqty += $oqty; $toval += $oval;
  $tpqty += $pqty; $tpval += $pval;
  $tfqty += $fqty; $tfval += $fval;
  $tuqty += $uqty; $tuval += $uval;
  $trqty += $rqty; $trval += $rval;
  $tjqty += $jqty; $tjval += $jval;
  $tcqty += $cqty; $tcval += $cval;
  //closing balance
  //$sql6 = "select 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 im.category_code=$cat_code and im.receive_date<='$date2'";
  //$rs6 = mysql_query($sql6, $link_id);
  //if(!$rs6) echo sql_error();
  //while ($qd6 = mysql_fetch_array($rs6)){
  //  $receive_date = $qd6["receive_date"];
  //  $uprice = $qd6["unit_price"];
  //  $status = $qd6["status"];
  //  if ($uprice == "") $uprice = 0;
  //  if ($status=="new" or $status=="old" or $status=="reserved"){
  //    $cqty++; $cval += $uprice;
  //  }else if ($status=="issued"){
  //    $rs7 = mysql_query("select * from parts_issued where parts_code=$parts_code and issue_date>'$date2'", $link_id);
  //    //check issue date which must > date2
  //    if (mysql_num_rows($rs7)==0) $rs7 = mysql_query("select * from pc_configuration where parts_code=$parts_code and issue_date>'$date2'", $link_id);
  //    if (mysql_num_rows($rs7)>0){
  //      $cqty++; $cval += $uprice;
  //    }
  //  }
  //}
  //$tcqty += $cqty;
  //$tcval += $cval;

  //show figures
  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&nbsp;</td></tr>";
  $oqty=0; $oval=0; $fqty=0; $fval=0; $uqty=0; $uval=0; $rqty=0; $rval=0; $jqty=0; $jval=0; $cqty=0; $cval=0;

}
echo "<tr><td></td><td align='right'><b>Total</b></td><td align='right'><b>$toqty</b></td><td align='right'><b>Rs.$toval</b></td><td align='right'><b>$tpqty</b></td><td align='right'><b>Rs.$tpval</b></td><td align='right'><b>$tfqty</b></td><td align='right'><b>Rs.$tfval</b></td><td align='right'><b>$trqty</b></td><td align='right'><b>Rs.$trval</b></td><td align='right'><b>$tuqty</b></td><td align='right'><b>Rs.$tuval</b></td><td align='right'><b>$tjqty</b></td><td align='right'><b>Rs.$tjval</b></td><td align='right'><b>$tcqty</b></td><td align='right'><b>Rs.$tcval&nbsp;</b></td></tr>";
echo "</table>";


include "page_footer.inc";
?>