Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/mcell/report/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/mcell/report/report_inventory.php

<?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 "<hr><center><font color='red' size='+1'>Balance Sheet</font></center>
     <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)){
  $fyear1 = $o->financial_year;
  echo "<option value='$fyear1'";
  if ($fyear1 == $financial_year) echo " selected";
  echo ">$fyear1</option>";
}
echo "<option value='$fyear'>$fyear</option>
      <option value='2007-2008'>2007-2008</option>
      </select> ($date1 to $date2) </div>

      <table width='100%' border='1' cellspacing='0' cellpadding='1' 
      bordercolordark='white' bordercolor='black' frame='box' id='id4'>
      <tr><th rowspan='3'>Sr.</th><th rowspan='3'>Item</th>
      <th rowspan='2'>Opening<br>Balance</th>
      <th rowspan='2'>Total<br>Purchase</th>
      <th colspan='5'>Consumption</th>
      <th rowspan='2'>Closing<br>Balance</th></tr>
      <tr><th>Fabrication</th><th>Replacement</th>
      <th>Upgradation</th><th>Project</th><th>Scrap</th></tr>
      <tr><th>Qty</th><th>Qty</th><th>Qty</th><th>Qty</th>
      <th>Qty</th><th>Qty</th><th>Qty</th><th>Qty</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; $tsqty=0; $tsval=0;

$sql1 = "select row_id,name from parts_category where item_type='$item_type' order by name";
$rs1 = mysql_query($sql1, $con);
if(!$rs1) echo sql_error();
while ($o = mysql_fetch_object($rs1)){
  $cat_code = $o->row_id;
  $item = $o->name;

  //initialise the memory variables
  $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; $sqty=0; $sval=0;


  //opening balance at the start of financial year
  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im where pm.item_code=im.row_id and im.category_code=$cat_code and im.receive_date<'$date1' and pm.status<>'issued'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $oqty = $o->no;
  $oval = $o->cost;   

  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im,parts_issued pi where pm.item_code=im.row_id and pm.row_id=pi.parts_code and im.category_code=$cat_code and im.receive_date<'$date1' and pi.issue_date>='$date1'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $oqty += $o->no;
  $oval += $o->cost;

  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im,product_configuration pc where pm.item_code=im.row_id and pm.row_id=pc.parts_code and im.category_code=$cat_code and im.receive_date<'$date1' and pc.issue_date>='$date1'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $oqty += $o->no;
  $oval += $o->cost;

  //total purchase during the financial year  
  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm left join parts_receipt im on pm.item_code=im.row_id where im.category_code=$cat_code and im.receive_date>='$date1' and im.receive_date<='$date2'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $pqty = $o->no;
  $pval = $o->cost;

  //consumption in projects during the financial year
  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im,parts_issued pi where im.row_id=pm.item_code and pm.row_id=pi.parts_code and im.category_code=$cat_code and pi.issue_date>='$date1' and pi.issue_date<='$date2'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $jqty = $o->no;
  $jval = $o->cost;

  //consumption in pc assembling/maintenance during the financial year
  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost,pc.used_for from parts_master pm,parts_receipt im,product_configuration pc where im.row_id=pm.item_code and pm.row_id=pc.parts_code and im.category_code=$cat_code and pc.issue_date>='$date1' and pc.issue_date<='$date2' group by used_for";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  while ($o = mysql_fetch_object($rs2)){
    $used_for = $o->used_for;
    switch ($used_for){
    case "fabrication":
      $fqty = $o->no;
      $fval = $o->cost;
      break;
    case "upgradation":
      $uqty = $o->no;
      $uval = $o->cost;
      break;
    case "replacement":
      $rqty = $o->no;
      $rval = $o->cost;
      break;
    default:
      $jqty += $o->no;
      $jval += $o->cost;
      break;
    }
  } 
  //scrap balance at the end of financial year
  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im where im.row_id=pm.item_code and im.category_code=$cat_code and pm.status='scrap' and im.receive_date<='$date2'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $sqty = $o->no;
  $sval = $o->cost;

  //closing balance at the end of financial year
  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im where im.row_id=pm.item_code and im.category_code=$cat_code and pm.status<>'issued' and im.receive_date<='$date2'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $cqty = $o->no;
  $cval = $o->cost;     

  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im,parts_issued pi where im.row_id=pm.item_code and pm.row_id=pi.parts_code and im.category_code=$cat_code and im.receive_date<'$date2' and pi.issue_date>'$date2'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $cqty += $o->no;
  $cval += $o->cost;

  $sql2 = "select count(pm.row_id) no,sum(im.unit_price) cost from parts_master pm,parts_receipt im,product_configuration pc where im.row_id=pm.item_code and pm.row_id=pc.parts_code and im.category_code=$cat_code and im.receive_date<'$date2' and pc.issue_date>'$date2'";
  $rs2 = mysql_query($sql2, $con);
  if(!$rs2) echo sql_error();
  $o = mysql_fetch_object($rs2);
  $cqty += $o->no;
  $cval += $o->cost;

  $toqty += $oqty; $toval += $oval;
  $tpqty += $pqty; $tpval += $pval;
  $tfqty += $fqty; $tfval += $fval;
  $tuqty += $uqty; $tuval += $uval;
  $trqty += $rqty; $trval += $rval;
  $tjqty += $jqty; $tjval += $jval;
  $tsqty += $sqty; $tsval += $sval;
  $tcqty += $cqty; $tcval += $cval;
  if ($oval == '') $oval = 0;
  if ($pval == '') $pval = 0;
  if ($fval == '') $fval = 0;
  if ($uval == '') $uval = 0;
  if ($rval == '') $rval = 0;
  if ($jval == '') $jval = 0;
  if ($sval == '') $sval = 0;
  if ($cval == '') $cval = 0;
  $i++; 
  //show figures
  echo "<tr><td>$i</td><td>$item</td>
        <td align='right'>$oqty</td>
        <td align='right'>$pqty</td>
        <td align='right'>$fqty</td>
        <td align='right'>$rqty</td>
        <td align='right'>$uqty</td>
        <td align='right'>$jqty</td>
        <td align='right'>$sqty</td>
        <td align='right'>$cqty</td></tr>";
}
echo "<tr><td colspan='2' align='right'><b>Total</b></td>
      <td align='right'>$toqty</td>
      <td align='right'>$tpqty</td>
      <td align='right'>$tfqty</td>
      <td align='right'>$trqty</td>
      <td align='right'>$tuqty</td>
      <td align='right'>$tjqty</td>
      <td align='right'>$tsqty</td>
      <td align='right'>$tcqty</td></tr>";
echo '</table>
      <p><p><input type="submit" name="submit" value="PRINT" onclick="window.print()">';

include "report_footer.inc";
?>