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

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

<b>Issue Item</b> (on <?php echo date("d-m-Y") ?>)<p>

<?php
$submit=$_REQUEST["submit"];
$user_code=strtoupper($_REQUEST["user_code"]);
$category_code=strtoupper($_REQUEST["category_code"]);
$item_code=strtoupper($_REQUEST["item_code"]);
$issue_date=date("Y-m-d");
$destination=$_REQUEST["destination"];
if ($destination == "") $destination="lab";
$due_date=$_REQUEST["due_date"];
if ($due_date == "") $due_date = date("Y-m-d");
$return_date=date("Y-m-d");
$status=$_REQUEST["status"];
if ($status == "") $status="working";
$remark=$_REQUEST["remark"];
$action = $_REQUEST["action"];

switch ($submit){
case "ISSUE":
  //issue & reduce stock status
  $sql="insert into consumption_master(item_code, user_code, issue_date, destination, due_date, status, remark) values('$item_code', '$user_code', '$issue_date', '$destination', '$due_date', '$status', '$remark')";
  $result=mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  //change status in item master
  $sql="update item_master set status='issued' where item_code='$item_code'";
  $result=mysql_query($sql, $link_id);
  //get balance stock
  $sql="select count(item_code) qty1 from item_master where category_code='$category_code' and status in ('new', 'old')";
  $result=mysql_query($sql, $link_id);
  $query_data=mysql_fetch_array($result);
  $qty1=$query_data["qty1"];
  $sql="select count(item_code) qty2 from item_master where category_code='$category_code' and status in ('issued')";
  $result=mysql_query($sql, $link_id);
  $query_data=mysql_fetch_array($result);
  $qty2=$query_data["qty2"];
  //maintain stock status
  $sql="update category_master set stock_quantity=$qty1, issued_quantity=$qty2 where category_code='$category_code'";
  $result=mysql_query($sql, $link_id);
  break;
case "RETURN":
  $sql="update consumption_master set return_date='$return_date', status='$status' where item_code='$item_code'";
  $result=mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  //change status to old/used in item master
  if ($status == "working") $status="old";
  $sql="update item_master set status='$status' where item_code='$item_code'";
  $result=mysql_query($sql, $link_id);
  //get balance stock
  $sql="select count(item_code) qty1 from item_master where category_code='$category_code' and status in ('new', 'old')";
  $result=mysql_query($sql, $link_id);
  $query_data=mysql_fetch_array($result);
  $qty1=$query_data["qty1"];
  $sql="select count(item_code) qty2 from item_master where category_code='$category_code' and status in ('issued')";
  $result=mysql_query($sql, $link_id);
  $query_data=mysql_fetch_array($result);
  $qty2=$query_data["qty2"];
  //maintain stock status
  $sql="update category_master set stock_quantity=$qty1, issued_quantity=$qty2 where category_code='$category_code'";
  $result=mysql_query($sql, $link_id);
  break;
case "FIND":
  $sql="select * from user_master where user_code='$user_code'";
  $result=mysql_query($sql, $link_id);
  if (!mysql_num_rows($result)) $flag="FALSE";      //echo "Wrong user code";
default:
  break;
}

echo "<table width='50%'><tr><th nowrap>User Code</th><td nowrap><input type='text' name='user_code' value='$user_code' size='20'>";
$sql="select category_code, stock_quantity from category_master where stock_quantity > 0 order by category_code asc";
$result=mysql_query($sql, $link_id);
if (mysql_num_rows($result)){
  echo "<th nowrap>Category Code</th><td><select name='category_code'>";
  while ($query_data=mysql_fetch_array($result)){
    echo "<option value='" . $query_data["category_code"] . "'";
    if ($category_code == $query_data["category_code"]) echo " selected";
    echo ">" . $query_data["category_code"] . " (" . $query_data["stock_quantity"] . ")</option>";
  }
  echo "</select></td>";
}else{
  echo "<th nowrap>Nothing to issue</th>";
  $flag="FALSE";
}
echo "<td><input type='submit' name='submit' value='FIND'></td></tr></table>";
echo "<table border='0' width='80%'>";
echo "<center><tr valign='top'>";
if ($flag != "FALSE" and $category_code != ""){
  $sql="select * from item_master where category_code='$category_code' and status in ('new','old') order by category_code asc";
  $result=mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  echo "<td WIDTH='20%' align='center'><b>Issue New Item</b><table width='100%'><tr><td nowrap>Item Code</td><td><select name='item_code'>";
  while ($query_data=mysql_fetch_array($result)){
    echo "<option value='" . $query_data["item_code"] . "'";
    if ($item_code == $query_data["item_code"]) echo " selected";
    echo ">" . $query_data["item_code"] . "</option>";
  }
  echo "</select></td></tr>";
  echo "<tr><td>Destination</td><td><input type='text' name='destination' value='$destination' size='20'></td></tr>";
  echo "<tr><td>Due Date</td><td><input type='text' name='due_date' value='$due_date' size='10'></td></tr>";
  echo "<tr valign='top'><td>Remark</td><td><textarea name='remark' rows='3' cols='20'>$remark</textarea></td></tr>";
  echo "<tr><th>New</th><td><input type='submit' name='submit' value='ISSUE'></td></tr>";
  echo "<tr><td colspan='2'><i>To return an item click on Item Code</i></td></tr></table></td>";
}
//show user account
if ($user_code != ""){
  echo "<td width='80%' align='center'><b>User Account Details</b>";
  $sql="select * from user_master where user_code='$user_code'";
  $result=mysql_query($sql, $link_id);
  if(!mysql_num_rows($result)) echo "<br>Invalid user code";
  else{
    echo "<table width='100%' border='0'>";
    echo "<th nowrap>ITEM<br>CODE</th><th>STATUS</th><th nowrap>ISSUE<br>DATE</th><th nowrap>DUE<br>DATE</th><th nowrap>RETURN<br>DATE</th><th>DESTINATION</th><th>REMARK</th></tr>";
    $sql="select * from consumption_master where user_code='$user_code' order by issue_date asc";
    $result=mysql_query($sql, $link_id);
    if(!$result) echo sql_error();
    if (mysql_num_rows($result)){
      while($query_data=mysql_fetch_array($result)){
        $i++;
        $user_code=$query_data["user_code"];
        $category_code=strtoupper(substr($query_data["item_code"], 0, strpos($query_data["item_code"],"-")));
        $issue_date=$query_data["issue_date"];
        $destination=$query_data["destination"];
        $due_date=$query_data["due_date"];
        $return_date=$query_data["return_date"];
        $status=$query_data["status"];
        if ($status == "") $status="working";
        $remark=$query_data["remark"];
        echo "<tr id='";
        if ($i % 2) echo "row1'>";
        else echo "row2'>";
        if ($item_code == strtoupper($query_data["item_code"])){
          echo "<td bgcolor='#CDAE95' nowrap>$item_code</td><td><select name='status'><option value='working'>working</option><option value='scrap'>scrap</option></select></td>";
          echo "<td>$issue_date</td>";
          echo "<td>$due_date</td>";
          echo "<td>$return_date</td>";
          echo "<td>$destination</td>";
          echo "<td>$remark</td><td bgcolor='#CDAE95'><input type='submit' name='submit' value='RETURN'></td></tr>";
        }else{
          echo "<td bgcolor='#CDAE95' nowrap><a href='/php/mcell/master/consumption_master_entry.php?submit=RETURNING&user_code=$user_code&category_code=$category_code&item_code=" . strtoupper($query_data["item_code"]) . "'>" . strtoupper($query_data["item_code"]) . "</a></td><td>$status</td>";
          echo "<td>$issue_date</td>";
          echo "<td>$due_date</td>";
          echo "<td>$return_date</td>";
          echo "<td>$destination</td>";
          echo "<td>$remark</td></tr>";
        }
      }
    }else echo "<tr><td colspan='6'>Nothing to show here...</td></tr>";
    echo "</table>";
  }
  $sql = "select email from user_master where user_code='$user_code'";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  if ($query_data = mysql_fetch_array($result)){
    $email_address = $query_data["email"];
  }

  $sql = "select * from consumption_master where user_code='$user_code' and due_date < curdate()";
  $result = mysql_query($sql, $link_id);
  if(!$result) echo sql_error();
  if ($query_data = mysql_fetch_array($result)){
    $mail_body .= $query_data["item_code"] . "---" . $query_data["issue_date"] . "---" . $query_data["due_date"] . "---" . $query_data["remark"] . "\n";
    $overdue = "YES";
  }
  if ($action == "mail"){
    $mail_body .= "item_code---issue_date---due_date---remark\n";
    require("../class.phpmailer.php");
    $mail = new PHPMailer();
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host = "mail.local"; // SMTP server
    $mail->From = "mmishra@iiita.ac.in";
    $mail->AddAddress("$email_address");
    $mail->Subject = "Item Overdue Reminder from Maintenance Cell";
    $mail->Body = "$mail_body\n\nThese items are pending to you. kindly return them.";
    $mail->WordWrap = 50;
    if(!$mail->Send()){
      echo "Message was not sent";
      echo "Mailer Error: " . $mail->ErrorInfo;
    }else echo "Message has been sent";
  }else{
    if ($overdue == "YES") echo "<a href='/php/mcell/master/consumption_master_entry.php?user_code=$user_code&category_code=$category_code&action=mail'>Send overdue reminder</a>";
  }
}
echo "</td></tr></table>";
?>
</form>
<?php
include "../page_footer.inc";
?>