<?php
require_once("../config/config.php");
$_SESSION['retailBill']="";
?>
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title><?=siteTitle?></title>
 <script src="../js/jquery.min.js"></script>
 <link href="../css/font-awesome.min.css" rel="stylesheet">
 <link href="../css/abc.css" rel="stylesheet">
 <script src="../js/bootstrap.min.js"></script>
 <link href="../css/abc2.css" rel="stylesheet">
 <link rel="stylesheet" href="../css/bootstrap.min.css">
 <link rel="stylesheet" href="../css/jquery.dataTables.min.css">
 <script type="text/javascript" src="../js/jquery.dataTables.min.js"></script>
 <script>
$(document).ready(function(){
    $('#myTable').dataTable();
});
</script>
</head>
<body>
<div class="container-fluid">
  <div class="row content">
	<?php 
    include("../includes/leftnav2.php");
    ?>
    <div class="col-sm-9 tab-pane fade in active table-responsive" id="home">
      <h2 align="center"><i class="fa fa-user"></i> Retail Billing List</h2>
      <?php if(isset($_REQUEST['msg'])){?>
        <div class="alert alert-<?php echo $_REQUEST['chkflag'];?> alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            <strong><?php echo $_REQUEST['chkmsg'];?>!</strong>&nbsp;&nbsp;<?=$_REQUEST['msg']?>.
        </div>
      <?php }?>
      <form class="form-horizontal" role="form">
        <div style="display:inline-block;float:right">
        <button title="Direct Billing" type="button" class="btn btn-primary" style="float:right;" onClick="window.location.href='directBilling.php?<?=$pagenav?>'"><span>Add Retail Billing To Location</span></button>&nbsp;&nbsp;&nbsp;&nbsp;</div>
        <button title="Add New Opening" type="button" class="btn btn-primary" style="float:right;" onClick="window.location.href='customerbilling_withscheme.php?rb=add<?=$pagenav?>'"><span>Add Retail Billing To Customer</span></button>&nbsp;&nbsp;&nbsp;
        <div style="display:inline-block;float:right">
        <button title="Free Billing" type="button" class="btn btn-primary" style="float:right;margin-right: 16px;" onClick="window.location.href='FreeBilling.php?<?=$pagenav?>'"><span>Add Free Retail Billing To Location</span></button>&nbsp;&nbsp;&nbsp;&nbsp;</div>
      <div class="form-group"  id="page-wrap" style="margin-left:10px;"><br/><br/>
       <table  width="98%" id="myTable" class="table-striped table-bordered table-hover" align="center">
          <thead>
            <tr>
              <th width="5%" data-class="expand"><a href="#" name="entity_id" title="asc" ></a>S.No</th>
              <th width="17%"><a href="#" name="name" title="asc" ></a>Billing From</th>
              <th width="17%" data-hide="phone"><a href="#" name="name" title="asc" class="not-sort"></a>Billing To</th>
              <th width="15%" data-hide="phone,tablet"><a href="#" name="name" title="asc" class="not-sort"></a>Invoice No.</th>
              <th width="10%" data-hide="phone,tablet"><a href="#" name="date" title="asc" class="not-sort"></a>Invoice Date</th>
              <th width="8%" data-hide="phone,tablet"><a href="#" name="name" title="asc" class="not-sort"></a>Status</th>
              <th width="8%" data-hide="phone,tablet"><a href="#" name="name" title="asc" class="not-sort"></a>Print</th>
              <th width="6%" data-hide="phone,tablet"><a href="#" name="name" title="asc" class="not-sort"></a>IMEI Attached</th>
              <th width="6%" data-hide="phone,tablet"><a href="#" name="name" title="asc" class="not-sort"></a>View</th>
              <th width="6%" data-hide="phone,tablet">Cancel</th>
            </tr>
          </thead>
          <tbody>
            <?php
			$sno=0;
			///// get access location ///
			$accesslocation=getAccessLocation($_SESSION['userid'],$link1);
			$sql=mysqli_query($link1,"Select * from billing_master where from_location in (".$accesslocation.") and type='RETAIL' order by id desc");
			while($row=mysqli_fetch_assoc($sql)){
				  $sno=$sno+1;
				  /// bill to party
				  $billto=getLocationDetails($row['to_location'],"name,city,state",$link1);
				  $explodeval=explode("~",$billto);
				  if($explodeval[0]){ $toparty=$billto; }else{ $toparty=getCustomerDetails($row['to_location'],"customername,city,state",$link1);}
				  $cancel_right=mysqli_num_rows(mysqli_query($link1,"select id from access_cancel_rights where  uid='$_SESSION[userid]' and status='Y' and cancel_type='9'"));
			?>
            <tr class="even pointer">
              <td><?php echo $sno;?></td>
              <td><?php echo str_replace("~",",",getLocationDetails($row['from_location'],"name,city,state",$link1));?></td>
              <td><?php echo str_replace("~",",",$toparty);?></td>
              <td><?php echo $row['challan_no'];?></td>
              <td><?php echo $row['sale_date'];?></td>
              <td <?php if($row['status']=="Pending"){ echo "class='red_small'";}?>><?php echo $row['status'];?></td>
              <td align="center"><a href='../print/print_invoice.php?rb=view&id=<?php echo base64_encode($row['challan_no']);?><?=$pagenav?>' target="_blank"  title='Print Invoice'><i class="fa fa-print fa-lg" title="Print Invoice"></i></a><?php if($row['imei_attach']){ ?>  &nbsp;&nbsp;<a href='../print/print_imei.php?rb=view&id=<?php echo base64_encode($row['challan_no']);?><?=$pagenav?>' target="_blank"  title='Print IMEI'><i class="fa fa-print fa-lg" title="Print IMEI"></i></a><?php }?></td>
              
              <td align="center"><?php if($row['status']!="Cancelled"){if($row['imei_attach']==""){ ?><a href='imeiUpload.php?id=<?php echo base64_encode($row['challan_no']);?><?=$pagenav?>'  title='IMEI Attach'><i class="fa fa-upload fa-lg"></i></a>    <a href='imei_scan.php?id=<?php echo base64_encode($row['challan_no']);?>&invdate=<?php echo base64_encode($row['sale_date']);?>&invloc=<?php echo base64_encode($row['from_location']);?>&invto=<?php echo base64_encode($row['to_location']);?><?=$pagenav?>'  title='IMEI Attach'><i class="fa fa-cloud-upload fa-lg"></i></a><?php }else{ echo "YES";}}?></td>
              
              <td align="center"><a href='retailbillingdetails.php?rb=view&id=<?php echo base64_encode($row['challan_no']);?><?=$pagenav?>'  title='view'><i class="fa fa-eye fa-lg" title="view details"></i></a></td>
              <td align="center"><?php if($cancel_right > 0){if($row['status']=="Dispatched" || $row['status']=="Pending"){?><a href='cancelRetailInvoice.php?id=<?php echo base64_encode($row['challan_no']);?><?=$pagenav?>'  title='Cancel Invoice'><i class="fa fa-trash fa-lg" title="Cancel Invoice"></i></a><?php }}?></td>
            <?php }?>
          </tbody>
          </table>
      </div>
      </form>
    </div>
    
  </div>
</div>
<?php
include("../includes/footer.php");
include("../includes/connection_close.php");
?>
</body>
</html>