Disposed Item Report


Disposal Report shows all items disposed in a given date range. Applying the report filter, you can generate report for all items (item wise report) or select an item and get the report for that item in date wise.

Source Code of disposal_reports.php File:

<?php include("inc/page_header.php"); ?>
<?php
 if(check('Add Stocks') != 'Valid'){
  header("Location: sys_home.php?pre=error");
  ob_end_flush();
 }
?>
<script type="text/javascript" src="ajax/show_items_js.js"></script>
 <div class="wrapper">

  <div class="s60">
  <div class="boxtitle">Disposals</div>
   <p>Pleaseselect a an option from the filters in the right side.</p>
   <table width="98%">
    <?php
     if(isset($_POST['submit_1'])){
      $item_name = $_POST['item_name'];
      echo "<tr><td colspan='5'>{$item_name}</td></tr>";
      //validation
      if($item_name == ''){
       $error = 'Please select an item from the list!';
      }else{
       // get the item code
       $q = mysql_query("SELECT Item_Code FROM items WHERE Item_Name = '$item_name'");
       $r = mysql_fetch_assoc($q);
       $item_code = $r['Item_Code'];
       // create the sql filter
       $q = mysql_query("SELECT * FROM returns, items WHERE Return_Item = Item_Code AND Return_Action = 'dispose' ORDER BY Return_Date DESC");
    ?>
      <tr id="headrow"><td>&nbsp;Date</td><td>&nbsp;Qty</td><td>&nbsp;Purchase Rs.</td><td>&nbsp;Reason</td></tr>
    <?php
       $total_qty = 0;
       $total_value = 0;
       while($r = mysql_fetch_assoc($q)){
        echo "<tr id='sh2'><td>&nbsp;{$r['Return_Date']}</td><td>&nbsp;{$r['Return_Qty']}</td><td><div align='right'>".number_format(($r['Return_Value']*$r['Return_Qty']),2,'.','')."</div></td><td>{$r['Return_Reason']}</td></tr>";
        $total_qty += $r['Return_Qty'];
        $total_value += $r['Return_Value']*$r['Return_Qty'];
       }
      }
     }
     if(isset($_POST['submit_2'])){
      $date_from = $_POST['date_from'];
      $date_to = $_POST['date_to'];
      echo "<tr><td colspan='5'>From {$date_from} To {$date_to}</td></tr>";
      // validation
      if($date_from == '' || $date_to == ''){
       $error = 'Please enter a valid date range!';
      }else{
       $q = mysql_query("SELECT Item_Code, Item_Part_No, Item_Name, SUM(Return_Qty), SUM(Return_Value), AVG(Return_Value) FROM returns, items WHERE Return_Item = Item_Code AND Return_Action = 'dispose' AND Return_Date BETWEEN '$date_from' AND '$date_to' GROUP BY Return_Item ORDER BY Item_Name");
    ?>
       <tr id="headrow"><td>&nbsp;Item Code</td><td>&nbsp;Item Name</td><td>&nbsp;Qty</td><td>&nbsp;Value Rs.</td></tr>
    <?php
       $total_qty = 0;
       $total_value = 0;
       while($r = mysql_fetch_assoc($q)){
        echo "<tr id='sh2'><td>&nbsp;{$r['Item_Part_No']}</td><td>&nbsp;{$r['Item_Name']}</td><td><div align='right'>{$r['SUM(Return_Qty)']}</div></td><td><div align='right'>{$r['SUM(Return_Value)']}</div></td></tr>";
        $total_qty += $r['SUM(Return_Qty)'];
        $total_value += $r['AVG(Return_Value)']*$r['SUM(Return_Qty)'];
       }
      }
     }
    ?>
   </table>
  </div>
  <div class="s40">
   <?php
    if(isset($error)){ echo "<div class='errordiv'>{$error}</div>"; }
    if(isset($noerror)){ echo "<div class='noerrordiv'>{$noerror}</div>"; }
   ?>
   <div style="border:2px solid #6484F0; width:90%; margin:10px auto 10px auto; padding:5px; ">
    <p><strong>View report by items<br>
    </strong>Please select an item you want to see in the report.</p>
    <form action="disposal_reports.php" method="post">
     <input id="item_name" type="text" size="37" name="item_name" onKeyUp="showItems(this.value)" onFocus="showItemList()" onBlur="hideItemList()" /> <input id="submit_1" type="submit" name="submit_1" class="btn" value="&raquo;" /><br />
     <div id="item_list" style="position:absolute; z-index:2; width:246px; background-color:#FFFFCC; border:1px solid #999999; overflow:scroll; min-height:1px; visibility:hidden; "></div>
    </form>
   </div>
   <div style="border:2px solid #6484F0; width:90%; margin:10px auto 10px auto; padding:5px; ">
    <p><strong>View report by period<br>
    </strong>Please provide the time period you want to generate the report.</p>
    <form action="disposal_reports.php" method="post">
     From: <input id="date_from" type="text" size="8" name="date_from" /> <img src="images/calendar.gif" onClick="fPopCalendar('date_from')"> 
     &nbsp; To: <input id="date_to" type="text" size="8" name="date_to" /> <img src="images/calendar.gif" onClick="fPopCalendar('date_to')"> 
     &nbsp; &nbsp;<input id="submit_2" type="submit" name="submit_2" class="btn" value="&raquo;" />
    </form>
   </div>
   <p>&nbsp;</p>
   <?php if(isset($total_value)){ ?>
   <p style="text-align:center; font-size:16px; font-weight:bold; color:#990000;"><?php echo $total_qty; ?> Items<br />Value of Rs. <?php echo number_format($total_value,2,'.',''); ?></p>
   <?php } ?>
  </div>
  
 </div>
 
<?php include("inc/page_footer.php"); ?>

Comments