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_old.php

<?php
//show page head
include "page_header.inc";
$db = $_REQUEST["db"];
$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'>Audit Report</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'></center><br>";
echo "<table width='100%'>";
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</th></tr>";

$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 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 = $qd1["description"];
  echo "<tr><td>$i</td><td>$cat_code - $desc</td>";

  //opening balance stock qty
  $sql2 = "select sum(stock_quantity) as oqty, sum(unit_price * stock_quantity) as oval from item_master where category_code=$cat_code and receive_date>'$pdate1' and receive_date<'$pdate2'";
  $rs2 = mysql_query($sql2, $link_id);
  if(!$rs2) echo sql_error();
  $qd2 = mysql_fetch_array($rs2);
  $oqty = $qd2["oqty"];
  if ($oqty == "") $oqty = 0;
  $oval = $qd2["oval"];
  if ($oval == "") $oval = 0.00;
  $toqty += $oqty;
  $toval += $oval;
  echo "<td align='right'>$oqty</td><td align='right'>$oval</td>";

//  $sql2 = "select count(pc.parts_code) from pc_configuration pc, parts_master pm, item_master im where pc.parts_code=pm.row_id and pm.item_code=im.row_id and pc.issue_date>'$date1' and pc.issue_date<'$date2' and im.receive_date<'$pdate1' and im.receive_date<'$pdate2' and im.category_code='$cat_code'";
//  $rs2 = mysql_query($sql2, $link_id);
//  if(!$rs2) echo sql_error();
//  $qd2 = mysql_fetch_array($rs2);
//  $iqty = $qd2["iqty"];
//  if ($iqty == "") $iqty = 0;
//  $oqty += $iqty;
//  echo "<td align='right'>$oqty</td><td></td>";
//  $toqty += $oqty;

  //purchase quantity
  $sql3 = "select sum(stock_quantity + issued_quantity) as pqty, sum(unit_price * (stock_quantity + issued_quantity)) as pval from item_master where category_code=$cat_code and receive_date>'$date1' and receive_date<'$date2'";
  $rs3 = mysql_query($sql3, $link_id);
  $qd3 = mysql_fetch_array($rs3);
  $pqty = $qd3["pqty"];
  if ($pqty == "") $pqty = 0;
  $pval = $qd3["pval"];
  if ($pval == "") $pval = 0.00;
  $tpqty += $pqty;
  $tpval += $pval;
  echo "<td align='right'>$pqty</td><td align='right'>$pval</td>";

  //consumption breakup
  $sql4 = "select im.category_code, count(pc.parts_code) as no, im.unit_price as , pc.used_for from item_master im, parts_master pm, pc_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 im.category_code, pc.used_for order by pc.used_for";
  $rs4 = mysql_query($sql4, $link_id);
  $j = 0; $tfno = 0; $trno = 0; $tuno = 0;
  while ($qd4 = mysql_fetch_array($rs4)){
    $j++;
    $no = $qd4["no"];
    $head = $qd4["used_for"];
    if ($no == "") $no = 0;
    switch ($head){
    case "fabrication": $tfno += $no;
    case "replacement": $trno += $no;
    default: $tuno += $no;
    }
    echo "<td align='right'>$no</td><td></td>";
  }
  if ($j == 0) echo "<td align='right'>0</td><td></td><td align='right'>0</td><td></td><td align='right'>0</td><td></td>";
  if ($j == 1) echo "<td align='right'>0</td><td></td><td align='right'>0</td><td></td>";
  if ($j == 2) echo "<td align='right'>0</td><td></td>";

  //issued separatly
  $sql5 = "select count(parts_code) as ino from parts_issued pi, parts_master pm, item_master im where pi.parts_code=pm.row_id and pm.item_code=im.row_id and im.category_code=$cat_code and im.receive_date>'$date1' and im.receive_date<'$date2'";
  $rs5 = mysql_query($sql5, $link_id);
  $qd5 = mysql_fetch_array($rs5);
  $ino = $qd5["ino"];
  if ($ino == "") $ino = 0;
  echo "<td align='right'>$ino</td><td></td>";
  $tino += $ino;

  //closing balance
  $sql6 = "select sum(stock_quantity) as cqty from item_master where category_code=$cat_code and receive_date>'$date1' and receive_date<'$date2'";
  $rs6 = mysql_query($sql6, $link_id);
  $qd6 = mysql_fetch_array($rs6);
  $cqty = $qd6["cqty"];
  if ($cqty == "") $cqty = 0;
  echo "<td align='right'>$cqty</td>";
  $tcqty += $cqty;


  //$sql3 = "select cm.sum(stock_quantity) as pqty, status from parts_master where item_code=$item_code group by status";
  //$rs3 = mysql_query($sql3, $link_id);
  //while ($qd3 = mysql_fetch_array($rs3)){
  //  $no = $qd3["no"];
  //  $status = $qd2["status"];
  //  echo "<td>$status</td><td>$no</td>";
  //}
  echo "</tr>";
}
echo "<tr><td></td><td align='right'><hr><b>Total</b></td><td align='right'><hr><b>$toqty</b></td><td align='right'><hr><b>Rs.$toval</b></td><td align='right'><hr><b>$tpqty</b></td><td align='right'><hr><b>Rs.$tpval</b></td><td align='right'><hr><b>$tfno</b></td><td align='right'><hr><b>Rs.</b></td><td align='right'><hr><b>$trno</b></td><td align='right'><hr><b>Rs.</b></td><td align='right'><hr><b>$tuno</b></td><td align='right'><hr><b>Rs.</b></td><td align='right'><hr><b>$tcqty</b></td><td align='right'><hr><b>Rs.</b></td><td align='right'><hr><b>$tino</b></td><td align='right'><hr><b>Rs.</b></td></tr>";
echo "</table>";
//show table data
//echo table_data($sql1, $link_id, $start_pos, $db);
include "page_footer.inc";
?>