<?php
include('../config/config.php');
include('../classes/classProduct.php');
include('../classes/classProductClosingReconcilation.php');


if(isset($_GET['closingrepid'])&&$_GET['closingrepid']!='')
{
	$_SESSION['temp']['productclosing_id'] = (base64_decode($_GET['closingrepid']));
}

if(isset($_SESSION['temp']['productclosing_id'])&&$_SESSION['temp']['productclosing_id']!='')
{
	$productclosing_id = $_SESSION['temp']['productclosing_id'];
}
/*echo '<pre>';
print_r($_POST);
print_r($_SESSION);
echo '</pre>';
exit;*/
if(isset($_POST['search'])&&$_POST['search']!='')
{
	$search = $_POST['search'];
}
else
{
	$search = '';
}

if(isset($_GET['sortby'])&&$_GET['sortby']!='')
{
	$sortby = $_GET['sortby'];
}
else
{
	$sortby = '';
}

try
{
	$retrieveProdOb = new classProduct;
	$products_array = $retrieveProdOb->retrieveActiveProductsThroughFilter($search,$sortby,$_SESSION['security']['org_id']);
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../css/print.css" rel="stylesheet">
</head>

<body>
<div align="right">
 <SCRIPT LANGUAGE="JavaScript"> 
if (window.print) {
document.write('<form class="no-print"><input type=button name=print value="Print" onClick="window.print()"></form>');
}
</script></div>
<section class="wrapper">

      <!-- page start-->
      <div class="row">
        <div class="col-sm-12">
          <section class="panel">
           <header class="panel-heading">
              <h2>INVENTORY CLOSING</h2>
            </header>

            <div class="panel-body">
              <div class="adv-table">
                <table  class="bottomBorder" id="dynamic-table">
                  <thead>
                    <tr>

           			 <th width="5%" align="center">ID</th>
            		 <th width="15%" align="center">Product Name</th>
            		 <th width="10%" align="left">Product Type</th>
           		 	 <th width="15%" align="center">Actual/Physical Count</th>
           		 	 <th width="15%" align="center">Packing Type</th>
            		 <th width="12%" align="center">Unit Per Pack</th>
                     <th width="13%" align="center">Total<br> Unit in Stock</th>
                    </tr>
                  </thead>
                  <tbody>
					<?php
					if(isset($products_array[0]['product_id']))
					{
						for($p=0;$p<count($products_array);$p++)
						{
							$product_id = $products_array[$p]['product_id'];
							$product_name = $products_array[$p]['product_name'];
							$medicine_type = $products_array[$p]['medicine_type'];
							
							
							$retrieveItemClosingOb = new classProductClosingReconcilation;
							$retrieveItemClosingOb->setProductID($product_id);
							$retrieveItemClosingOb->setClosingReportID($productclosing_id);
							$closing_item_detail = $retrieveItemClosingOb->retrieveClosingItemByProductIDAndClosingReportID();
							
							if($closing_item_detail[0]['closing_packing']=='Unit/Tablets') 
							{
								$unitperbox = 1;
							} 
							elseif($closing_item_detail[0]['closing_packing']=='Leaf') 
							{
								$unitperbox = $products_array[$p]['unitperbox']/$products_array[$p]['leafperbox'];
							} 
							elseif($closing_item_detail[0]['closing_packing']=='Box/Pack') 
							{
								$unitperbox = $products_array[$p]['unitperbox'];
							}
							?>
							<tr class="gradeX">

								<td align="center"><?php echo $product_id;?></td>
								<td align="left"><?php echo $product_name;?></td>
								<td align="left"><?php echo $medicine_type;?></td>
                                
								<td align="center"><?php echo $closing_item_detail[0]['closingcount']; ?> </td>
                                <td align="center"><?php echo $closing_item_detail[0]['closing_packing']; ?> </td>
                                
								<td align="left"><?php echo $unitperbox;?></td>
								<td align="center" id="unit_phy_qtyinstock_<?php echo $p;?>"><?php if(isset($closing_item_detail[0]['unit_phy_qtyinstock'])&&$closing_item_detail[0]['unit_phy_qtyinstock']!=''){ echo $closing_item_detail[0]['unit_phy_qtyinstock'];}?></td>
							</tr>
                            
                           <input name="product_id[]" type="hidden" class="product_id" id="product_id_<?php echo $p;?>" size="5" value="<?php echo $product_id;?>" />
                           
                           
							<?php
						}
					}
					else
					{
						?>
                        
                        <?php
					}
                    ?>
                  </tbody>
                  <tfoot>
                  </tfoot>
                </table>
                
              </div>
            </div>
          </section>
        </div>
      </div>
      <!-- page end-->
    </section><br />
<div style="color:#999; text-align:center; position: absolute; bottom: 5px;">All Rights Reserved © copyrights Softusion Inc. 2013 Design by Softusion.</div> 
</body>
</html>