<?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 <?php echo ucfirst($mgmtname);?></h3>
          </div>
          <div class="col-md-3 text-right">
           &nbsp;
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
<?php
 if($tasktype=='price')
 {
 ?>
		<form name="frmsearch" method="get" action="outlet/<?php echo $mgmtname;?>/price">
<?php
 }
 else
 {
?>
		<form name="frmsearch" method="get" action="outlet/<?php echo $mgmtname;?>">
<?php
 }
?>
         <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 by name" ></td>
			<td class="pr-0" width="20%">
			<select name="catid" id="catid" class="js-example-basic-single" >
			  <option value="">All Category</option>
							<?php
							if(is_array($catlist) && count(array_filter($catlist))>0)
							{

								foreach($catlist as $mcatrow)
								{
									$sel_mcat ="";
									if(decodeValue($this->input->get("catid"))==$mcatrow->fld_id)
									{
										$sel_mcat = 'selected="selected"';
									}				
										?>
												<option value="<?php echo encodeValue($mcatrow->fld_id);?>" <?php echo $sel_mcat;?>><?php echo $mcatrow->fld_name;?></option>
										<?php
									
								}
							}
							?> 
			  </select>
		  </td>
<?php
 if($tasktype=='price')
 {
 ?>
           <td class="pr-0" width="20%"><input type="number" name="fromprice" id="fromprice" value="<?php echo $this->input->get("fromprice");?>"   placeholder="From Price"  /></td>
           <td class="pr-0" width="20%"><input type="number" name="toprice" id="toprice"  value="<?php echo $this->input->get("toprice");?>" placeholder="To Price"/></td>			  
           
		   <?php
 }
 else
 {
?>
          <td width="20%">
		  <select name="type" id="type" class="js-example-basic-single">
		  <option value="">All Type</option>
						<?php
							
							foreach(arrProductType() as $ptkey => $ptval)
							{
								$sel_pt ="";
								if($this->input->get("type")==$ptkey)
								{
									$sel_pt = 'selected="selected"';
								}				
									?>
											<option value="<?php echo $ptkey;?>" <?php echo $sel_pt;?>><?php echo $ptval;?></option>
									<?php
								
							}
						
						?> 
		  </select>
		  </td>


          <td class="pr-0" width="20%">
		<select name="brandid" id="brandid" class="js-example-basic-single" >
		  <option value="">All Brand</option>
						<?php
						if(is_array($brandlist) && count(array_filter($brandlist))>0)
						{
							foreach($brandlist as $brandrow)
							{
								$sel_brand ="";
								if(decodeValue($this->input->get("brandid"))==$brandrow->fld_id)
								{
									$sel_brand = 'selected="selected"';
								}				
									?>
											<option value="<?php echo encodeValue($brandrow->fld_id);?>" <?php echo $sel_brand;?>><?php echo $brandrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>
<?php
 }
?>
           <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">
		<form name="frmlisting" id="frmlisting" action="<?php echo base_url()."outlet/".$mgmtname;?>" method="post" onsubmit=" return checkboxvalidate();">
                <thead>
                	<tr>
                        <th width="3%">SRNo.</th>
						<th width="5%" class="text-center">Min. Qty</th>
                    	<th width="3%">Type</th>
                    	<th width="8%">Barcode</th>
						<th width="15%">Name</th>
						<th width="8%">Category</th>
						 <?php
						 if($tasktype=='price')
						 {
							 $colspan = 11;
						 ?>
                    	<th width="8%">Price<br> 1<br>Bottle</th>
                    	<th width="8%">Price<br> 3<br>Bottle</th>
                    	<th width="8%">Price<br> 6<br> Bottle</th>
                    	<th width="8%">Price<br> 9<br> Bottle</th>
                    	<th width="8%">Price<br> 12<br> Bottle</th>
                    	<th width="8%">Price<br> 24<br> Bottle</th>
						 <?php
						 }
						 else
						 {
							 $colspan = 11;
						?>
							
							<th width="13%">Brand</th>
							<th width="9%" class="text-center">Bottles <br>In Case</th>
							<th width="13%">7 Days <br>Sale</th>
							<th width="13%">30 Days <br>Sale</th>
						<?php
						}
						?>
                    	<th width="10%" class="text-right">InStock</th>
                       
                        
                    </tr>
                    </thead>
                    <tbody>
					<?php
					//predata($results);
					if(is_array($results) && count(array_filter($results))>0)
					{
						$rowindex = 0;
						if($startlist!="" && $startlist!=0)
						{
							$rowindex = $startlist;
						}
						foreach($results as $row)
						{
							
							$barcodes = $row['barcode'];
							if($row['barcode02']!="") { $barcodes .=" , ".$row['barcode02']; }
							if($row['barcode03']!="") { $barcodes .=" , ".$row['barcode03']; }
							if($row['barcode04']!="") { $barcodes .= " , ".$row['barcode04']; }
							$minstockvalue = minstockStatus($row['minstockvalue'],$row['instock']);
					?>
                    <tr>
                        <td><?php echo $rowindex;?>.</td> 
                    	<td class="text-center"><input type="text" name="minqty[]" id="minqty<?php echo $row['minqtyid'];?>" value="<?php echo $row['minqty'];?>" style="width:50px;" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode==46'> <input type="hidden" name="minqtyid[]"  value="<?php echo $row['minqtyid'];?>"> <input type="hidden" name="prodid[]"  value="<?php echo $row['id'];?>"> </td>
						<td><a href="outlet/orders/producttype/<?php echo $row['type'];?>"><?php echo arrProductType()[$row['type']];?></a></td>
						<td><?php echo $barcodes;?></td>
						<td>
						<!--<a href="outlet/orders/product/<?php echo encodeValue($row['id']);?>"><?php echo $row['name'];?></a>//-->
						<a href="outlet/stockstatus/?pid=<?php echo encodeValue($row['id']);?>"><?php echo $row['name'];?></a>

						</td>    <td><a href="outlet/orders/category/<?php echo encodeValue($row['catid']);?>"><?php echo $row['catname'];?></a></td>                	                    	
          	
  						 <?php
						 if($tasktype=='price')
						 {
						 ?>

	                   	<td><a href="outlet/orders/product/<?php echo encodeValue($row['id']);?>?price=<?php echo $row['price1'];?>"><?php echo $row['price1'];?></a></td>
	                   	<td><a href="outlet/orders/product/<?php echo encodeValue($row['id']);?>?price=<?php echo $row['price3'];?>"><?php echo $row['price3'];?></a></td>
	                   	<td><a href="outlet/orders/product/<?php echo encodeValue($row['id']);?>?price=<?php echo $row['price6'];?>"><?php echo $row['price6'];?></a></td>
	                   	<td><a href="outlet/orders/product/<?php echo encodeValue($row['id']);?>?price=<?php echo $row['price9'];?>"><?php echo $row['price9'];?></a></td>
	                   	<td><a href="outlet/orders/product/<?php echo encodeValue($row['id']);?>?price=<?php echo $row['price12'];?>"><?php echo $row['price12'];?></a></td>
	                   	<td><a href="outlet/orders/product/<?php echo encodeValue($row['id']);?>?price=<?php echo $row['price24'];?>"><?php echo $row['price24'];?></a></td>
	                   
						 <?php
						 }
						 else
						 {
						?>
						
						<td><a href="outlet/orders/brand/<?php echo encodeValue($row['brandid']);?>"><?php echo $row['brandname'];?></a></td> 
                    	<td class="text-center"><?php echo $row['noofbottlesincase'];?></td>
                    	<td class="text-center"><?php echo $row['7dayssale'];?></td>
                    	<td class="text-center"><?php echo $row['30dayssale'];?></td>
						<?php
						}
						?>  
                    	<td class="text-right "> <span class="btn btn-<?php echo arrOSColor()[$minstockvalue];?> "><strong><?php echo $row['instock'];?></strong></span> </td>
                    </tr>
                    <?php
							$rowindex++;
						}
						?>
					<tr>
						<td>&nbsp;</td>						
						<td class="text-center"><button class="btn btn-success" type="submit"><i class="fa fa-cogs" aria-hidden="true"></i> Update Index</button></td>						
						<td colspan="<?php echo ($colspan-2);?>" >	&nbsp;</td>		
							
											
									
					</tr>
					</form>
					<?php
					}
					else
					{
                    ?>
                    <tr><td colspan="<?php echo $colspan;?>" 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>

