Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/backup/mcell/master/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/backup/mcell/master/item_master_entry.php

<?php
include "../page_header.inc";
echo "<form method='post' action='/php/mcell/master/item_master_entry.php'>";

$status_array = array("new", "old");//"scrap", "issued", "reserved", 
$submit = $_REQUEST["submit"];
$supplier_code = strtoupper($_REQUEST["supplier_code"]);
$category_code = strtoupper($_REQUEST["category_code"]);
$item_code = strtoupper($_REQUEST["item_code"]);
$description = $_REQUEST["description"];
$model = $_REQUEST["model"];
if ($model == "") $model = "iiita";
$make = $_REQUEST["make"];
if ($make == "") $make = "iiita";
$unit_price = $_REQUEST["unit_price"];
if ($unit_price == "") $unit_price = 0;
$receive_date = date("Y-m-d");
$status = $_REQUEST["status"];
$received_from = $_REQUEST["received_from"];
if ($status == ""){
  if ($received_from == "user") $status="old";
  else $status="new";
}
$remark = $_REQUEST["remark"];
echo "<b>" . ucfirst($status)  . " Item Entry</b> (on " . date("d-m-Y") . ") Received from <b>$received_from</b><p>";
echo "<input type='hidden' name='received_from' value='$received_from'>";
echo "<table>";

switch ($submit){
case "SAVE":
  $sql = "insert into item_master(item_code, description, category_code, model, make, unit_price, status, receive_date, supplier_code, remark) values('$item_code', '$description', '$category_code', '$model', '$make', $unit_price, '$status', '$receive_date', '$supplier_code', '$remark')";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  //update stock_quantity & total_cost in category_master table, first get available stock status
  $sql = "select count(item_code) qty, sum(unit_price) tcost from item_master where category_code='$category_code' and status in('new', 'old', 'reserved')";
  $result = mysql_query($sql, $link_id);
  $query_data = mysql_fetch_array($result);
  $qty = $query_data["qty"];
  $tcost = $query_data["tcost"];
  if ($tcost == NULL) $tcost = 0;
  //get max acc no.
  $sql = "select item_code from category_master where category_code='$category_code'";
  $result = mysql_query($sql, $link_id);
  $query_data = mysql_fetch_array($result);
  $acc_no = $query_data["item_code"];
  $acc_no = $acc_no + 1;
  //update into item_master table
  $sql = "update category_master set stock_quantity=$qty, total_cost=$tcost, item_code=$acc_no where category_code='$category_code'";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  break;
case "UPDATE":
  $sql = "update item_master set category_code='$category_code', description='$description', model='$model', make='$make', unit_price=$unit_price, status='$status', supplier_code='$supplier_code', remark='$remark' where item_code='$item_code'";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  //update stock_quantity & total_cost in category_master table, first get available stock status
  $sql = "select count(item_code) qty, sum(unit_price) tcost from item_master where category_code='$category_code' and status in('new', 'old', 'reserved')";
  $result = mysql_query($sql, $link_id);
  if (!$result) echo mysql_error();
  $query_data = mysql_fetch_array($result);
  $qty = $query_data["qty"];
  $tcost = $query_data["tcost"];
  if ($tcost == "") $tcost = 0;
  //update into item_master table
  $sql = "update category_master set stock_quantity=$qty, total_cost=$tcost where category_code='$category_code'";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  break;
case "DELETE":
  $sql = "delete from item_master where item_code='$item_code'";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  //update stock_quantity & total_cost in category_master table, first get available stock status
  $sql = "select count(item_code) as qty, sum(unit_price) as tcost from item_master where category_code='$category_code' and status in('new', 'old', 'reserved')";
  $result = mysql_query($sql, $link_id);
  $query_data = mysql_fetch_array($result);
  $qty = $query_data["qty"];
  $tcost = $query_data["tcost"];
  //update into item_master table
  $sql = "update category_master set stock_quantity = $qty, total_cost = $tcost where category_code='$category_code'";
  $result = mysql_query($sql, $link_id);
  break;
default:
  break;
}
//echo "<tr><th colspan='5' nowrap>Select</th></tr>";
echo "<tr valign='top'><th nowrap>";
if ($received_from == "user"){
  echo "User Code</th><td><input type='text' name='supplier_code' value='$supplier_code' size='10'>";
  if ($supplier_code != ""){
    $sql = "select * from user_master where user_code='$supplier_code'";
    $result = mysql_query($sql, $link_id);
    if (!mysql_num_rows($result)){
      echo "Invalid user code";
      $flag="NO";
    }else{
      $flag = "YES";
      $query_data = mysql_fetch_array($result);
      $name=$query_data["name"]; 
      $email=$query_data["email"]; 
    }
  }
}else{
  echo "Supplier Code</th><td><select name='supplier_code'>";
  $sql = "select supplier_code, firm_name, email from supplier_master";
  $result = mysql_query($sql, $link_id);
  while ($query_data = mysql_fetch_array($result)){
    echo "<option value='" . strtoupper($query_data["supplier_code"]) . "'";
    if ($supplier_code == strtoupper($query_data["supplier_code"])){
      echo " selected";
      $name=$query_data["firm_name"]; 
      $email=$query_data["email"]; 
    }
    echo ">" . $query_data["supplier_code"] . "</option>";
  }
  echo "</select>";
  $flag = "YES";
}
echo "</td><td nowrap>Category Code</td><td><select name='category_code'>";
//onchange=\"javascript:document.location.href='/php/mcell/master/item_master_entry.php?received_from=$received_from&supplier_code=' + supplier_code.value + '&item_code=NEW&category_code=' + this.value\"
echo "<option value=''>Select</option>";
$sql = "select distinct category_code, item_code from category_master";
$result = mysql_query($sql, $link_id);
while ($query_data = mysql_fetch_array($result)){
  echo "<option value='" . strtoupper($query_data["category_code"]) . "'";
  if ($category_code == strtoupper($query_data["category_code"])) echo " selected";
  echo ">" . strtoupper($query_data["category_code"]) . "</option>";
}
echo "</select></td><td><input type='submit' name='submit' value='FIND'></td></tr>";
if ($supplier_code != "") echo "<tr><th colspan='2'>$name</th><td colspan='2'>($email)</th></tr>";
echo "</table>";

if ($flag == "YES" and $category_code != ""){
  $sql = "select * from item_master where item_code='$item_code'";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  if (mysql_num_rows($result)){
    $query_data = mysql_fetch_array($result);
    $description = $query_data["description"];
    $unit_price = $query_data["unit_price"];
    if ($unit_price == "") $unit_price = 0;
    $model = $query_data["model"];
    $make = $query_data["make"];
    $receive_date = $query_data["receive_date"];
    $status = $query_data["status"];
    $supplier_code = strtoupper($query_data["supplier_code"]);
    $remark = $query_data["remark"];
    //see whether it is configurable or not
    $sql = "select configuration from category_master where category_code='$category_code'";
    $result = mysql_query($sql, $link_id);
    $query_data = mysql_fetch_array($result);
    $configuration = $query_data["configuration"];
  }else{
    $flag = "TRUE";
    $sql = "select item_code, configuration from category_master where category_code='$category_code'";
    $result = mysql_query($sql, $link_id);
    $query_data = mysql_fetch_array($result);
    $acc_no = $query_data["item_code"];
    $configuration = $query_data["configuration"];
    $item_code = $category_code . "-" . $acc_no;
  }
  echo "<center><table><tr><td nowrap>Item Code</td><th>$item_code</th><td>Received On</td><td>$receive_date<input type='hidden' name='item_code' value='$item_code'></td>";
  echo "<td rowspan='6'><b>Item List</b><br><select name='acc_no' size='12' onchange=\"javascript:document.location.href='/php/mcell/master/item_master_entry.php?received_from=$received_from&category_code=' + category_code.value + '&item_code=' + this.value\">";
  echo "<option value='NEW'>Add New</option>";
  $sql2 = "select item_code from item_master where category_code='$category_code' and status in ('new', 'old', 'issued', 'reserved', 'scrap')";
  $result2 = mysql_query($sql2, $link_id);
  while ($query_data2 = mysql_fetch_array($result2)){
    echo "<option value='" . strtoupper($query_data2["item_code"]) . "'";
    if ($item_code == strtoupper($query_data2["item_code"])) echo " selected";
    echo ">" . strtoupper($query_data2["item_code"]) . "</option>";
  }
  echo "</select></td></tr>";
  echo "<tr valign='top'><td>Description</td><td colspan='3'><textarea name='description' rows='2' cols='30'>$description</textarea></td></tr>";  
  echo "<tr><td>Unit Price</td><td><input type='text' name='unit_price' value='$unit_price' size='5'> in Rs.</td><th>Status</th><th><input type='hidden' name='status' value='$status'>$status</th></tr>";
  echo "<tr><td>Model</td><td><input type='text' name='model' value='$model' size='30'></td></tr>";
  echo "<tr><td>Make</td><td><input type='text' name='make' value='$make' size='30'></td></tr>";
  echo "<tr valign='top'><td>Remark</td><td colspan='3'><textarea name='remark' rows='2' cols='30'>$remark</textarea></td></tr>";
  if ($configuration == "YES") echo "<tr><td><a href='/php/mcell/master/configuration_entry.php?category_code=$category_code&configuration_code=$item_code' target='center'>Configuration</a></td>";
  else echo "<tr><td></td>";
  if ($flag != "TRUE") echo "<td colspan='2' nowrap><input type='submit' name='submit' value='UPDATE'> <input type='submit' name='submit' value='DELETE'></td></tr>";
  else echo "<td colspan='2'><input type='submit' name='submit' value='SAVE'> <input type='reset' name='submit' value='RESET'></td></tr>";
  echo "<tr><td colspan='5'><b>Item Details</b><br><iframe src='/php/mcell/master/item_details_view.php?category_code=$category_code' name='center' width='100%' height='120'></iframe></td></tr>";
  echo "</table>";
}
?>
</form>
<?php
include "../page_footer.inc";
?>