<?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>
          <?php
          if($this->whsubtype=="l1bf")
          {
          ?>
          <div class="col-md-3 text-right">
            <a href="warehouse/<?php echo $mgmtname;?>/manage" class="btn btn-success">Add Product</a>
          </div>
          <?php
		  }
          ?>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="warehouse/<?php echo $mgmtname;?>">
         <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,barcode" ></td>
          <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="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>

          <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>
           <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="10%">Type</th>
                    	<th width="15%">Barcode</th>
						<th width="15%">Name</th>
                    	<th width="15%">Category</th>
                    	<th width="15%">Brand</th>
                    	<th width="5%">Bottles <br>In Case</th>
                    	<!--<th width="5%">7 Days <br>Sale</th>
                    	<th width="5%">30 Days <br>Sale</th>//-->
                        <!--<th width="5%" class="text-center">Status</th>//-->
                        <?php
                        if($this->whsubtype=="l1bf")
                        {
                        ?>
                        <th width="5%" class="text-center">Action</th>
                        <?php
						}
                        ?>
                    </tr>
                    </thead>
                    <tbody>
					<?php
					if(is_array($results) && count(array_filter($results))>0)
					{
						$rowindex = 0;
						foreach($results as $row)
						{
							$rowindex++;
							$barcodes = $row['barcode'];
							if($row['barcode02']!="") { $barcodes .=" , ".$row['barcode02']; }
							if($row['barcode03']!="") { $barcodes .=" , ".$row['barcode03']; }
							if($row['barcode04']!="") { $barcodes .= " , ".$row['barcode04']; }

					?>
                    <tr>
                        <td><?php echo $rowindex;?>.</td> 
						<td><a href="warehouse/orders/producttype/<?php echo $row['type'];?>"><?php echo arrProductType()[$row['type']];?></a></td>
						<td><?php echo $barcodes;?></td>
						<td><a href="warehouse/orders/product/<?php echo encodeValue($row['id']);?>"><?php echo $row['name'];?></a></td>                    	                    	
						<td><a href="warehouse/orders/category/<?php echo encodeValue($row['catid']);?>"><?php echo $row['catname'];?></a></td>
						<td><a href="warehouse/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>//-->
                        <!--<td align="center">
							<?php
							if($row['status'] == "active")
							{
							?>
							<a id="chstatus_<?php echo $row['id'];?>" style="cursor:pointer" class="text-success" onclick="changestatus('<?php echo base_url() ?>','<?php echo $row['id']; ?>', '<?php echo $mgmtname;?>')"><i class="fa fa-check fa-lg" aria-hidden="true"></i></a>
							<input type="hidden" id="status_<?php echo $row['id'];?>" value="active" />
							<?php
							}
							else
							{
							?>
							<a id="chstatus_<?php echo $row['id'];?>" style="cursor:pointer" class="text-danger" onclick="changestatus('<?php echo base_url() ?>','<?php echo $row['id']; ?>', '<?php echo $mgmtname;?>')"><i class="fa fa-times fa-lg" aria-hidden="true"></i></a>
							<input type="hidden" id="status_<?php echo $row['id'];?>" value="inactive" />
							<?php
							}
							?>
                        </td>//-->
                        <?php
                        if($this->whsubtype=="l1bf")
                        {
                        ?>
                        <td align="center">
							<a href="warehouse/<?php echo $mgmtname;?>/manage/<?php echo encodeValue($row['id']);?>" class="text-success" title="Edit"><span class="fa fa-edit fa-lg"></span></a><span class="ml-2"></span></a>
							
							<!--<a href="warehouse/delcomm/<?php echo $mgmtname;?>/<?php echo encodeValue($row['id']);?>" onclick="if(!confirm('This will delete the info. permanently!\nAre you sure?')) return false;" class="text-danger" title="Delete"><span class="fa fa-trash-o fa-lg"></span></a>//-->
						</td>
						<?php
						}
						?>
                    </tr>
                    <?php
						}
							
					}
					else
					{
                    ?>
                    <tr><td colspan="9" 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>

