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


/*echo '<pre>';
print_r($_POST);
print_r($_SESSION);
echo '</pre>';
exit;*/

################### create report ############################

if(isset($_POST['create_closing_report'])&&$_POST['create_closing_report']=='Start New Report')
{
	try
	{
		$createClosingOb = new classProductClosingReconcilation;
		$createClosingOb->setClosingReportClosingDate($_POST['closing_date']);
		$createClosingOb->setClosingReportCreatedBy($_SESSION['security']['user_id']);
		$createClosingOb->setLocationID($_SESSION['security']['location_id']);
		$createClosingOb->setClosingReportStatus('in_progress');
		$createClosingOb->createClosingReport();
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}	
	
}
################### close report ############################

if(isset($_GET['status'])&&isset($_GET['close_rec']))
{
	$report_id = base64_decode($_GET['close_rec']);
	try
	{
		$closeReportOb = new classProductClosingReconcilation;
		$closeReportOb->setClosingReportStatus('closed');
		$closeReportOb->setClosingReportEndTime(time());
		$closeReportOb->setClosingReportID($report_id);
		$closeReportOb->setClosingReportClosedBy($_SESSION['security']['user_id']);
		$closeReportOb->updateStatusAndClosingEndOfReport();
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}

################### Re Open report ############################

if(isset($_GET['openreport'])&&$_GET['openreport']!='')
{
	$report_id = base64_decode($_GET['openreport']);
	try
	{
		$openReportOb = new classProductClosingReconcilation;
		$openReportOb->setClosingReportStatus('in_progress');
		$openReportOb->setClosingReportEndTime("0");
		$openReportOb->setClosingReportID($report_id);
		$openReportOb->setClosingReportClosedBy("0");
		$openReportOb->updateStatusAndClosingEndOfReport();
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}


################### Delete reports ############################

if(isset($_GET['closingdel'])&&$_GET['closingdel']!='')
{
	$report_id = base64_decode($_GET['closingdel']);
	try
	{
		$delReportOb = new classProductClosingReconcilation;
		$delReportOb->setClosingReportID($report_id);
		$delReportOb->deleteClosingReport();
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}

################### Retrieve reports ############################

try
{
	$retrieveClosingOb = new classProductClosingReconcilation;
	$retrieveClosingOb->setLocationID($_SESSION['security']['location_id']);
	$closing_reports_array = $retrieveClosingOb->retrieveClosingReports();
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

/*echo '<pre>';
//print_r($_POST);
print_r($closing_reports_array);
echo '</pre>';
exit;*/

?>
<!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"><!-- InstanceBegin template="/Templates/print.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <link rel="shortcut icon" href="../images/favicon.png">
    <title>Med2TEC Hospital Management Information System</title> 
    <link href="../css/print.css" rel="stylesheet">
    <link href="../datepicker/jquery-ui.css" rel="stylesheet" >  
    <script type="text/javascript" src="../datepicker/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="../datepicker/jquery-ui.js"></script> 
</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">
<div style="background:#FFF; padding:0px 0px 0; height:auto;">
  <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
    <tbody>
      <tr>
        <td align="left" style="background:#fff;"><img alt="" src="../images/org_print_logos/<?php echo $_SESSION['security']['org_id']?>.png" style="width:100%;"></td>
      </tr>
    </tbody>
  </table>
  
</br>

</div>

<div class="row">
          <section class="panel">
            <header class="panel-heading">
              <h2><!-- InstanceBeginEditable name="title" -->INVENTORY CLOSING REPORTS<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->
  
            
            <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
                <span class="message_red"><?php echo $error_message;?></span>  
				<?php
			}
			?>


                <table  class="bottomBorder" cellpadding="0" cellspacing="0" width="100%">
                  <thead>
                    <tr>
           			 <th width="5%" align="center">ID</th>
            		 <th width="15%" align="center">Closing Date</th>
            		 <th width="18%" align="left">Report From</th>
           		 	 <th width="18%" align="left">End at</th>
            		 <th width="10%" align="center">Status</th>
            		 <th width="10%" align="center">Closing By</th>
                    </tr>
                  </thead>
                  <tbody>
					<?php
                    if(isset($closing_reports_array[0]['productclosing_id']))
                    {
						for($c=0;$c<count($closing_reports_array);$c++)
						{
							$productclosing_id = $closing_reports_array[$c]['productclosing_id'];
							$status = $closing_reports_array[$c]['status'];
							?>
							<tr class="gradeX">
                            
							
                            
                            <td align="center"><?php echo $productclosing_id;?></td>
                            
							<td align="center"><?php echo date('d M Y',$closing_reports_array[$c]['closing_date']);?></td>
                            
							<td align="center"><?php echo date('d M Y h:i:s A',$closing_reports_array[$c]['closing_start']);?></td>
                            
							<td align="center"><?php if ($closing_reports_array[$c]['closing_end']!=''){echo date('d M Y h:i:s A',$closing_reports_array[$c]['closing_end']);}?></td>
                            
							<td align="center"><?php echo $status;?></td>
                            
							<td align="center" ><?php echo $closing_reports_array[$c]['created_by'];?></td>
                            
                           	
							</tr>
							<?php
						}
                    }
                    ?>
                  </tbody>
                  <tfoot>
                  </tfoot>
                </table>
  <!-- page end-->
  
<!-- InstanceEndEditable -->
</section>
</div>

<!--<p align="center" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; margin-top:260px;"><strong><!--317 A-1, Nursery Stop, Township, Lahore. 
Ph: 042-35151666</strong><br />
For Appointment call at 042-35151666 (bring your Patient ID Card) </p>-->

   <div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color: rgb(0, 0, 0); text-align: right; font-size: 10px; margin-top: 4px; position: absolute; right: 180px;">© Software by Softusion Inc. 0322 6155 219</div>   
    </div>
</div>

<!--<div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color:#000; text-align:right; font-size:9px;">© Software designed by Softusion Inc. Contact us at 0322 6155 219</div>   
    </div>
</div>-->


          
</body>
<!-- InstanceEnd --></html>