<?php require_once('header.php');?>
<?php if($allPermissions['reports']['read_delivered']=="1"){ ?>
<script>
            function total_reports()
            {
                var from_date=  $('#from').val();     
                var client_id=  $('#client_id').val();     
                var to_date=  $('#to').val();   
                var set_status=  $('#set_status').val();   
                var role=  $('#client_type').val();   
                var courier_id=  $('#courier_id').val();
                var ctype=  $('#ctype').val();
                console.log(from_date,to_date,set_status,role,client_id,courier_id,ctype);
				var dataTable = $('#total_report-grid').DataTable( {
					"processing": true,
					"serverSide": true,
					"bDestroy": true,
					"ajax":{
						url :"data-tables/report-data-tables/total-reports-data-table.php", // json datasource
						data:{from:from_date,to:to_date,status:set_status,role:role,client_id:client_id,courier_id:courier_id,ctype:ctype},
						type: "post",  // method  , by default get
						error: function(){  // error handling
							$(".total_report-grid-error").html("");
							$("#total_report-grid").append('<tbody class="total_report-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
							$("#total_report-grid_processing").css("display","none");
							
						}
					}
				} );
            }
            
            function redirectTo()
            {
                var from_date=  $('#from').val();     
                var client_id=  $('#client_id').val();     
                var to_date=  $('#to').val();   
                var set_status=  $('#set_status').val();   
                var role=  $('#client_type').val();   
                var courier_id=  $('#courier_id').val();
                var ctype=  $('#ctype').val();
                window.location.href="excel/excel-total-report.php?from="+from_date+"&to="+to_date+"&status="+set_status+"&client_id="+client_id+"&client_type="+ctype;
            }
            
	$(document).ready(function(){
	console.log("---------");    
    total_reports();
    $('#get_report').on('click', function(){
        total_reports();
        
    });
    
    $('#export_total_report').on('click', function(){
        
        var from_date=  $('#from').val();     
        var client_id=  $('#client_id').val();     
        var to_date=  $('#to').val();   
        var set_status=  $('#set_status').val();   
        var role=  $('#client_type').val();   
        var courier_id=  $('#courier_id').val();
        var ctype=  $('#ctype').val();
        console.log(from_date,client_id,to_date,set_status,role,courier_id,ctype);
        if(client_id!=''){
            $.ajax({
                type:'POST',
                url:'excel-total-report.php',
                data:{from:from_date,to:to_date,status:set_status,client_id:client_id,client_type:client_type},
                 
            }); 
        }
        else
        {
            alert('Select a Client !!');
        }
    });

});
</script>



<section class="content-header">
	<div class="content-header-left">
		<h1>Delivery Report</h1>
	</div>
	<div class="row " >
	    <div class="col-md-12 ">
	 <div class='col-md-2 '>
         <label for="from">From:</label>
         <input type="date" id="from" name="from" class="form-control " >
    </div>
    <div class='col-md-2'>
         <label for="to">To:</label>
         <input type="date" id="to" name="to" class="form-control" >
         <input type="hidden" id="ctype" name="ctype" value="<?=$clientType?>">
         <input type="hidden" id="courier_id" name="courier_id" value="">
    </div>
      <?php if($clientType=="Admin"){ ?>
    <div class='col-md-2'>
        <label for="to">Client:</label>
        <select class="form-control" name="client_id" id="client_id">
							        <option value="all">Over All </option>
							        <?php
									//$statement = $pdo->prepare("SELECT * FROM tbl_user WHERE role='Modicare' ORDER BY id ASC");
									
									 if($clientType=="Admin"){ 
									$statement = $pdo->prepare("SELECT * FROM tbl_user WHERE role='client' or role='Modicare' ORDER BY id ASC");
							      }
							      else
							      {
							          $statement = $pdo->prepare("SELECT * FROM tbl_user WHERE (role='client' or role='Modicare') and id=$clientId ORDER BY id ASC");
							      }
									
									$statement->execute();
									$result = $statement->fetchAll(PDO::FETCH_ASSOC);	
									foreach ($result as $row) {
										?>
										<option value="<?php echo $row['id']; ?>"><?php echo $row['full_name']; ?></option>
										<?php
									}
									?>
							    </select>
        </div>
    <?php }else{ ?>
    <input type='hidden' name="client_id" id="client_id" value="<?php echo $clientId; ?>">
    
    <?php } ?>
    <input type="hidden" id="set_status" name="set_status" value="7">
    <div class='col-md-2' style="margin-top: 2%;">
         <button id="get_report" class="btn btn-md btn-info"><span id='sub_txt'>Submit</span>&ensp;<span id="sub_spin"></span></button>
    </div>
	</div>
	</div>
	<div class="row" >
    <div class="btn-group pull-right" style=" padding: 10px;">
 <input type="hidden" id="client_type" name="client_type" value="<?php echo $clientType; ?>">
	      <button type="submit" onclick="redirectTo();" class="btn btn-md btn-primary" >Export As Excel</button>

		</div>
	</div>
</section>

<section class="content">
	<div class="row">
		<div class="col-md-12">
			<div class="box box-info">
				<div class="box-body table-responsive">
				<table id="total_report-grid"  class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="30">SL</th>
								<?php  if($clientType=="Admin")	 { ?>	<th>Client</th><?php } ?>
								<th>CSCS AWB</th>
								<?php  if($clientType=="Admin")	 { ?>	<th>3PL AWB</th><th>3PL Name</th><?php } ?>
								<th>Status</th>
								<th>Ref No</th>
								<th>Order Type</th>
								<th>Shipper Name</th>
								<th>Shipper Address</th>
								<th>Shipper City</th>
								<th>Shipper State</th>
								<th>Shipper Phone</th>
								<th>Shipper Pincode</th>
								<th>Consignee Name</th>
								<th>Consignee Address</th>
								<th>Consignee City</th>
								<th>Consignee State</th>
								<th>Consignee Phone</th>
								<th>Consignee Pincode</th>
								<th>Volumetric Weight</th>
								<th>Volumetric Length</th>
								<th>Volumetric Breadth</th>
								<th>Volumetric Height</th>
								<th>Collectable Amount</th>
								<th>Product Description</th>
								<th>Quantity</th>
								<th>Boxes</th>
								<th>Invoice Value</th>
								<th>Taxable Value</th>
								<th>Hsn Code</th>
								<th>Discount</th>
								<th>Gst Amount</th>
								<th>MRP</th>
								<th>Ewaybill</th>
								<th>Actual Weight</th>
								<th>Charged Weight</th>
								<th>Gst Type</th>
								<th>Buyer Gst</th>
								<th>Seller Gst</th>
								<th>RTO Name</th>
								<th>RTO Address</th>
								<th>RTO City</th>
								<th>RTO State</th>
								<th>RTO Phone</th>
								<th>RTO Pincode</th>
								<th>Date Added</th>
							</tr>
						</thead>
						
					</table>
				</div>
			</div>
		</div>
	</div>
</section>



<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Delete Confirmation</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure want to delete this item?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a class="btn btn-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>

<?php }else{ ?>
<center><h4 style="color:red;">You don't have permission to view this page </h4></center>
<?php } ?>
<?php require_once('footer.php'); ?>