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



/*echo '<pre>';
print_r($_POST);
print_r($_SESSION);
echo '</pre>';
exit;
*/
################## Delete Receive Invoice Start ####################################

if(isset($_GET['delrecinvoice'])&&$_GET['delrecinvoice']!='')
{
	try
	{
		$delRecInvOb = new classStoreItemReceiveInvoice;
		$delRecInvOb->setReceiveInvoiceID(base64_decode($_GET['delrecinvoice']));
		$delRecInvOb->deleteReceiveInvoice();
		header("Location:mgmtreceiving.php");
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}

unset($_SESSION['print']);

try
{
	$retrieveInvoiceOb = new classStoreItemReceiveInvoice;
	
	if(isset($_POST['search_invoice_by_date'])&&$_POST['search_invoice_by_date']!='')
	{
		$_SESSION['print']['search_invoice_by_date'] = $_POST['search_invoice_by_date'];
		$invoice_array = $retrieveInvoiceOb->retrieveInvoiceByDate($_POST['search_invoice_by_date'],$_SESSION['security']['location_id']);
		$no_of_items = $retrieveInvoiceOb->countAllInvoicesItemsByDate($_POST['search_invoice_by_date'],$_SESSION['security']['location_id']);
	}
	elseif(isset($_GET['view'])&&$_GET['view']=='all')
	{
		$_SESSION['print']['view'] = $_GET['view'];
		$retrieveInvoiceOb->setLocationID($_SESSION['security']['location_id']);
		$invoice_array = $retrieveInvoiceOb->retrieveAllInvoices();	
		$no_of_items = $retrieveInvoiceOb->countAllInvoicesItems();
	}
	else
	{
		$date = date('Y-m-d',time());
		$invoice_array = $retrieveInvoiceOb->retrieveInvoiceByDate($date,$_SESSION['security']['location_id']);
		$no_of_items = $retrieveInvoiceOb->countAllInvoicesItemsByDate($date,$_SESSION['security']['location_id']);
	}
	
	$total_invoices = count($invoice_array);
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}
  




/*echo '<pre>';
print_r($product_supplier_relationship);
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"><head></head><!-- 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" --><!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <title>Med2TEC Hospital Management Information System</title>
  <section id="main-content">
    <section class="wrapper">

      <!-- page start-->
      <div class="row">
        <div class="col-sm-12">
          <section class="panel">
          
			<header class="panel-heading">
              <h2>RECEIVE ITEMS</h2>
            </header>
            
            <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
                <span class="message_red"><?php echo $error_message;?></span>
                
				<?php
			}
			?>
            
            <table width="100%" border="0" cellspacing="5" cellpadding="5">
              <tr>
              
                <td width="10%" align="right" valign="bottom">Search By Date:</td>
                
                <td width="20%" valign="bottom">
                <form action="" method="post" id="form_incoming">
                <input type="text" name="search_invoice_by_date" value="" id="datepicker" class="form-control" readonly="readonly" style="display:inline; width:90%;" />
                </form>
                 
                </td>
                
                <td width="20%" align="left" valign="bottom">
                <?php
				if(isset($_GET['view'])&&$_GET['view']=='all')
				{
					?>
                	<a href="printmgmtreceiving.php">Today Incoming</a>    
                    <?php
					
				}
				else
				{
					?>
                	<a href="printmgmtreceiving.php?view=all">View All</a>    
                    <?php
				}
				?>
                
                </td>
                
                <td width="70%" align="right">
                <div class="col-md-4" style="float: right; width:60%;">
                <div class="profile-nav alt">
                  <section class="panel">
                    <div class="user-heading alt clock-row terques-bg">
                      <h1><?php echo date('d F Y',time());?></h1>
                      <p class="text-left"><?php echo date('h:i A',time());?></p></br>
                      <p class="text-left"></p>
                      <span>Total Invoices: <div style="float:right;"><?php echo $total_invoices;?></div></span></br>
                      <span>No. of Equipments: <div style="float:right;"><?php echo $no_of_items;?></div></span></br>
                    </div>
                  </section>
                </div>
          		</div>
          		</td>
                
              </tr>
            </table><br /><br />  
                  
           <div class="panel-body" style="padding-top: 0px; margin-top: -34px;">
              <div class="adv-table">
               <table class="bottomBorder" cellpadding="0" cellspacing="0" width="100%" >
                  <thead>
                    <tr>
                      <th width="5%" align="center">ID</th>
                      <th width="15%" align="center">Date</th>
                      <th width="30%">Items</th>
                      <th width="15%">Qty Received</th>
                      <th width="10%" align="center">Status</th>
                      <th width="20%" align="right">Verified By</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
				  	if(isset($invoice_array[0]['recinvoice_id'])&&$invoice_array[0]['recinvoice_id']!='')
				  	{
						  for($inv=0;$inv<count($invoice_array);$inv++)
						  {
								if($inv%2==0){ $class = 'gradeX';}else{$class = 'gradeC';}
								
								$retInvItems = new classStoreItemReceiveInvoice;
								$retInvItems->setReceiveInvoiceID($invoice_array[$inv]['recinvoice_id']);
								$items_array = $retInvItems->retrieveInvoiceItemsAndQty();
								
								?>
								<tr class="<?php echo $class;?>">
								
									
								  
									<td align="center"><?php echo $invoice_array[$inv]['recinvoice_id'];?></td>
								  
									<td align="center"><?php echo date('d M Y',$invoice_array[$inv]['recinvoice_date']);?></td>
									
									<td align="left"><?php echo $items_array[0]['store_items_names'];?></td>
									
									<td align="left"><?php echo $items_array[0]['store_items_qty'];?></td>
									
									<td align="right">
                                    <?php
									if($invoice_array[$inv]['verified_status']=='verified')
									{
										?>
                                        <span class="label label-success label-mini">Verified</span>
                                        <?php
										
									}
									else
									{
										?>
										<span class="label label-danger label-mini">Verify</span>
										<?php
									}
									?>
                                    
                                    </td>
                                    
                                    <td  align="right"><?php echo ucwords($invoice_array[$inv]['verified_by_name']);?></td>
									
									
									
								</tr>
                                
                                 </tbody>
								<?php
						  }
				  	}
					else
					{
						?>
						<tr>
							<td colspan="7">No entries found!</td>
						</tr>
						<?php
					}
				  	?>
                    
                  
                
                </table>
              </div>
            </div>
            
          </section>
        </div>
      </div>
      <!-- page end-->
    </section>
  </section>
  
                    
					
  
    
<!-- 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>


 

<script>

$(".verify_rec_invoice").click(function() {
	
	var id = this.id;
	recinvoice_id = $("#recinvoice_id_"+id).val();
	$("#recinvoice_id").val(recinvoice_id);
});

$(function() {
	$("#datepicker").datepicker({
	showOn: "button",
	buttonImage: "../images/calendar.gif",
	buttonImageOnly: true,
	dateFormat: "yy-mm-dd",
	
	onClose: function(dateText, inst) {
	
    $("#form_incoming").submit();
} 
	/*minDate: '-1'*/
	});
});




</script>
