<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
      <div class="main my-0">
        <div class="row mt-3 mx-0">
          <div class="col-md-9">
            <h3>Manage Cancellation Requests</h3>
          </div>
          <div class="col-md-3 text-right">
            &nbsp;
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="account/<?php echo $mgmtname;?>/cnclrqts">
         <table class="webforms sttbl bg-light my-0 table-responsive-sm">
          <tr>
           <td class="pr-0" width="20%"><input type="text" name="search" size="20" value="<?php echo $this->input->get("search");?>" placeholder="search "></td>
			<td class="pr-0" width="20%">
		<select name="outletid" id="outletid" onchange="getoutletbiller('<?php echo base_url();?>',this.value)">
		  <option value="">Select Outlet</option>
						<?php
						if(is_array($outletlist) && count(array_filter($outletlist))>0)
						{

							foreach($outletlist as $outletrow)
							{
								$sel_outlet="";
								if(decodeValue($this->input->get("outletid"))==$outletrow->fld_id)
								{
									$sel_outlet = 'selected="selected"';
								}				
									?>
											<option value="<?php echo encodeValue($outletrow->fld_id);?>" <?php echo $sel_outlet;?>><?php echo $outletrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td> 
		<td class="pr-0" width="20%">
		<select name="billerid" id="billerid" >
		  <option value="">Select Biller</option>						
		  </select>
		  </td>		  
           <td>
           	<button class="btn btn-dark pt-0 pb-1 px-2">Go</button>
           </td>
          </tr>
         </table>
       </form>
         <?php
			if($this->session->flashdata("message")!="" && $this->session->flashdata("alerttype")!="")
			{
         ?>
         <div class="text-center my-4">
			 <span class="alert <?php echo $this->session->flashdata("alerttype");?>"><?php echo $this->session->flashdata("message");?></span>
         </div>
         <?php
			}
         ?>
         
         <table class="table mt-2 table-responsive-sm">
		 
                <thead>
                	<tr>
                    	<th width="5%">SRNo.</th>
                    	<th width="20%">Outlet</th>
                    	<th width="10%">Invoice NO.</th>
                    	<th width="10%">Invoice Date</th>
                    	<th width="10%">Customer</th>
						<th width="10%">Discount</th>
						<th width="10%">Gifts</th>
						<th width="10%">Amount</th>
                    	<th width="10%">Posted On</th>
                        <th width="5%" class="text-center">Status</th>
                        <th width="10%" class="text-center">Action</th>
                    </tr>
                    </thead>
                    <tbody>
					<?php
					if(is_array($results) && count(array_filter($results))>0)
					{
						$rowindex = 0;
						foreach($results as $row)
						{
							$rowindex++;
							$discount ="";
							$pdiscount ="";
							$hightlightcls ="";
							$giftinfo="";
							if($row['fld_discount']>0)
							{
								$discount = $row['fld_discount'];	
								$amount = $row['fld_netamount']+$discount;
								$pdiscount  = ceil(($amount-$row['fld_netamount'])/$amount*100);
								$discount  = round($discount,2) ." (" .$pdiscount. "%)";							
								$hightlightcls = 'class="text-'.arrOSColor()['specialdiscount'].'"';
							}
							else if($row['fld_gqty']>0)
							{
								$giftinfo = $row['fld_giftname'];
								$hightlightcls = 'class="text-'.arrOSColor()['gift'].'"';
							}

						
					?>
					
                    <tr <?php if($hightlightcls!="") { echo $hightlightcls; } ?> >
                    	<td class="text-center"><?php echo $rowindex;?>.</td>                    	
						 <td><?php echo $row['outletname'];?></td>              
						 <td><?php echo $row['fld_billno'];?></td>              
                    	<td><?php if($row['fld_billdate']!="") { echo date("d-M-Y", strtotime($row['fld_billdate'])); }?></td>
                    	<td><?php echo $row['fld_mobile'];?><br><?php echo $row['fld_name'];?></td>              
                    	            
                    	          
                            
						<td><?php echo $discount;?></td>  
						<td><?php echo $giftinfo;?></td>
						<td><?php echo $row['fld_netamount'];?></td>
                    	<td><?php echo date("d-M-Y", strtotime($row['fld_datetime']));?></td>
                        <td align="center">
							<span class="text-<?php echo arrOSColor()[$row['fld_status']];?>"><strong><?php echo arrOrderStatus()[$row['fld_status']];?></strong></span>
						</td>
						<td align="center">
						
					
						<!--<a href="account/<?php echo $mgmtname;?>/printbill/<?php echo encodeValue($row['fld_id']);?>" class="text-success" title="Print Bill" target="_blank"><span class="fa fa-print fa-lg"></span></a><span class="ml-2"></span></a>//-->

						<a href="account/<?php echo $mgmtname;?>/view/<?php echo encodeValue($row['fld_id']);?>" class="fancybox fancybox.iframe" aria-label="View" title="View"><span class="fa fa-eye fa-lg"></span></a><span class="ml-2"></span></a> <br>
						
						<?php
						if($row['fld_status']=='pending')
						{
						?>
							<a href="account/<?php echo $mgmtname;?>/cnclrqtsprocess/<?php echo encodeValue($row['fld_id']);?>" class="btn btn-success fancybox2-reloadparent" title="Process" >Process</a>
						<?php
						}
						
						?>						

						</td> 
                    </tr>
                    <?php
						}
							
					}
					else
					{
                    ?>
                    <tr><td colspan="11" style="text-align:center">Record not found!</td></tr>
                    <?php
					}
                    ?>
                    
                    
                    </tbody>
                </table>
                 
	         <div class="clearfix"></div>
          
        </div>
        <div id="paginate" class="row">
			<?php echo $this->ajax_pagination->create_links(); ?>
        </div>
            
        </div>

<?php
if($this->input->get("outletid")!="")
{
	$outletid  = $this->input->get("outletid");
	$billerval  = $this->input->get("billerid");
?>
<script>

	getoutletbiller('<?php echo base_url();?>','<?php echo $outletid;?>','<?php echo $billerval;?>');

</script>
<?php
}