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


################## Delete Receive Invoice Start ####################################

if(isset($_GET['delsaleinvoice'])&&$_GET['delsaleinvoice']!='')
{
	try
	{
		$delSaleInvOb = new classStoreItemSaleInvoice;
		$delSaleInvOb->setSaleInvoiceID(base64_decode($_GET['delsaleinvoice']));
		$delSaleInvOb->deleteSaleInvoice();
		header("Location:mgmtrequisitions.php");
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}

unset($_SESSION['print']);

$retrieveInvoiceOb = new classStoreItemSaleInvoice;
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($_SESSION['print']['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();
}
else
{
	$date = date('Y-m-d',time());
	$invoice_array = $retrieveInvoiceOb->retrieveInvoiceByDate($date,$_SESSION['security']['location_id']);
	
}


$total_invoices = count($invoice_array);





/*echo '<pre>';
print_r($invoice_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"><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">
    <!--mini statistics start-->
      <!-- page start-->
      <div class="row">
        <div class="col-sm-12">
          <section class="panel">
          
            <header class="panel-heading">
              <h2>MANAGE REQUISITIONS</h2>
            </header>
<table width="100%" border="0" cellspacing="5" cellpadding="5">
              <tr>
              
                <td width="3%" align="right" valign="bottom"></td>
                
                <td width="10%" valign="bottom">
               
                 
                </td>
                
                <td width="20%" align="left" valign="bottom">
                <?php
				if(isset($_GET['view'])&&$_GET['view']=='all')
				{
					?>
                	<a href="printmgmtrequisitions.php">Today Sales</a>    
                    <?php
					
				}
				else
				{
					?>
                	<a href="printmgmtrequisitions.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 Requisitions: <div style="float:right;"><?php echo $total_invoices;?></div></span></br>
                     
                    </div>
                  </section>
                </div>
          		</div>
          		</td>
                
              </tr>
            </table>
            <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
				<table>
				<tr>
					<td><span class="message_red"><?php echo $error_message;?></span></td>
				</tr>
				</table>
				<?php
			}
			?>
            
           	<div class="panel-body">
              <div class="adv-table">
                 <table class="bottomBorder" id="dynamic-table" width="100%" cellpadding="0" cellspacing="0">
                  <thead>
                    <tr>
                      <th width="5%" align="center">ID</th>
                      <th width="10%" align="center">Date</th>
                      <th width="15%" align="left">Request by</th>
                      <th width="15%" align="left">Required for</th>
                      <th width="20%" align="left">Items</th>
                      <th width="10%" align="left">Qty</th>
                      <th width="10%">Status</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
				  if(isset($invoice_array[0]['saleinvoice_id'])&&$invoice_array[0]['saleinvoice_id']!='')
				  {
					  	for($inv=0;$inv<count($invoice_array);$inv++)
					  	{
							$retInvItems = new classStoreItemSaleInvoice;
							$retInvItems->setSaleInvoiceID($invoice_array[$inv]['saleinvoice_id']);
							$items_array = $retInvItems->retrieveInvoiceItemsAndQty();
								
						  	if($inv%2==0){ $class = 'gradeX';}else{$class = 'gradeC';}
							?>
                            <tr class="<?php echo $class;?>">
                            
                            
                            
                            <td align="center"><?php echo $invoice_array[$inv]['saleinvoice_id'];?></td>
                            
                            <td align="center"><?php echo date('d M Y',$invoice_array[$inv]['saleinvoice_date']);?></td>
                            
                            <td><?php echo ucwords($invoice_array[$inv]['staff_name']);?></td>
                            
                            <td><?php echo ucwords($invoice_array[$inv]['department_name']);?></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="center">
                            <?php
							if($invoice_array[$inv]['delivere_status']=='delivered')
							{
								?>
                                <span class="label label-success label-mini">Delivered</span>
                                <?php
							}
							else
							{
								?>
                         <p id="<?php echo $inv;?>"><span class="label label-danger label-mini">Delivere</span></p>
                                <?php
							}
							?>
                           	</td>
                            
                          
                            
                            </tr>
                            
                            </tbody><input type="hidden" name="saleinvoice_id" class="set_to_pop" id="saleinvoice_id_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['saleinvoice_id'];?>" />
                        	<?php
					  	}
				  }
				  else
				  {
					?>
					<tr>
                        <td colspan="11">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>

$(".delivere_sale_invoice").click(function() {
	
	var id = this.id;
	saleinvoice_id = $("#saleinvoice_id_"+id).val();
	$("#saleinvoice_id").val(saleinvoice_id);
});


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

</script>

