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/update_stock.php

<?php
include "page_header.inc";

$sql2 = "update item_master set stock_quantity=0, issued_quantity=0, scrap_quantity=0";
$rs2 = mysql_query($sql2, $link_id);

//get stock quantity from stock master
$sql1 = "select item_code, count(row_id) qty from parts_master where status in('new', 'old') group by item_code";
$rs1 = mysql_query($sql1, $link_id);
while ($qd1 = mysql_fetch_array($rs1)){
  $item_code = $qd1["item_code"];
  $qty1 = $qd1["qty"];
  if ($qty1 == "") $qty1 = 0;
  //set stock quantity in item master
  $sql2 = "update item_master set stock_quantity=$qty1 where row_id=$item_code";
  $rs2 = mysql_query($sql2, $link_id);
}

//get issued quantity from stock master
$sql1 = "select item_code, count(row_id) qty from parts_master where status='issued' group by item_code";
$rs1 = mysql_query($sql1, $link_id);
while ($qd1 = mysql_fetch_array($rs1)){
  $item_code = $qd1["item_code"];
  $qty2 = $qd1["qty"];
  if ($qty2 == "") $qty2 = 0;
  //set issued quantity in item master
  $sql2 = "update item_master set issued_quantity=$qty2 where row_id=$item_code";
  $rs2 = mysql_query($sql2, $link_id);
}

//get scrap quantity from stock master
$sql1 = "select item_code, count(row_id) qty from parts_master where status='scrap' group by item_code";
$rs1 = mysql_query($sql1, $link_id);
while ($qd1 = mysql_fetch_array($rs1)){
  $item_code = $qd1["item_code"];
  $qty3 = $qd1["qty"];
  if ($qty3 == "") $qty3 = 0;
  //set scrap quantity in item master
  $sql2 = "update item_master set scrap_quantity=$qty3 where row_id=$item_code";
  $rs2 = mysql_query($sql2, $link_id);
}

$sql2 = "update category_master set stock_quantity=0, issued_quantity=0, scrap_quantity=0, total_cost=0";
$rs2 = mysql_query($sql2, $link_id);


//get stock quantity from item master
$sql1 = "select category_code, sum(stock_quantity) qty1, sum(issued_quantity) qty2, sum(scrap_quantity) qty3 from item_master group by category_code";
$rs1 = mysql_query($sql1, $link_id);
while ($qd1 = mysql_fetch_array($rs1)){
  $category_code = $qd1["category_code"];
  $qty1 = $qd1["qty1"];
  $qty2 = $qd1["qty2"];
  $qty3 = $qd1["qty3"];
  if ($qty1 == "") $qty1 = 0;
  if ($qty2 == "") $qty2 = 0;
  if ($qty3 == "") $qty3 = 0;
  //set quantities in category master
  $sql2 = "update category_master set stock_quantity=$qty1, issued_quantity=$qty2, scrap_quantity=$qty3 where row_id=$category_code";
  $rs2 = mysql_query($sql2, $link_id);
}

$sql1 = "select category_code, sum(unit_price * (stock_quantity + issued_quantity + scrap_quantity)) as cost from item_master group by category_code";
$rs1 = mysql_query($sql1, $link_id);
while ($qd1 = mysql_fetch_array($rs1)){
  $category_code = $qd1["category_code"];
  $cost = $qd1["cost"];
  if ($cost == "") $cost = 0;
  //set quantities in category master
  $sql2 = "update category_master set total_cost=$cost where row_id=$category_code";
  $rs2 = mysql_query($sql2, $link_id);
}


/*
$sql1 = "select row_id, user_code as code from user_master";
$rs1 = mysql_query($sql1, $link_id);
while ($qd1 = mysql_fetch_array($rs1)){
  $i++;
  $row_id = $qd1["row_id"];
  $code = $qd1["code"];
  echo $i . "---" . $code . "---" . $row_id . "<br>";
  $sql2 = "update pc_issued set user_code=$row_id where user_code1='$code'";
  $rs2 = mysql_query($sql2, $link_id);
  if (!$rs) echo mysql_error();
}
*/


echo "<b>Status</b><p>";
echo "<div id='orange_box'>!!! Stock updated successfully !!!</div>";
include "../page_footer.inc";
?>