<?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-6">
            <h3>Manage <?php echo ucfirst($mgmtname);?></h3>
          </div>
          <div class="col-md-6 text-right">
			<a href="account/admtransfers" class="btn btn-success">Transfers</a>
            <a href="billtest" target="_blank" class="btn btn-success">Bills</a>			  
            <a href="billtest/itemwise" target="_blank" class="btn btn-success">Bills - Items Wise</a>			  
            <a href="account/products/admmerge" class="btn btn-success">Merged Items</a>			  
            <a href="account/admhistory" class="btn btn-success">History</a>			  
            <a href="account/outlets/showall" class="btn btn-success">Outlets</a>			  
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="account/products/listings">
         <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 && $this->input->get("type")!="")
								{
									$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%">ID</th>
						<th width="20%">Name</th>
                    	<th width="10%">Type</th>
                    	<th width="15%">Category</th>
                    	<th width="12%">Brand</th>
                    	<th width="5%">Bottles <br>In Case</th>
                    	<th width="13%">Barcode</th>
                        <!--<th width="5%" class="text-center">Status</th>//-->
                        <th width="5%" class="text-center">Deleted</th>
                        <!--<th width="5%" class="text-center">Action</th>//-->
                    </tr>
                    </thead>
                    <tbody>
					<?php
					if(is_array($results) && count(array_filter($results))>0)
					{
						foreach($results as $row)
						{
							$barcodes = $row->fld_barcode;
							if($row->fld_barcode02!="") { $barcodes .=" , ".$row->fld_barcode02; }
							if($row->fld_barcode03!="") { $barcodes .=" , ".$row->fld_barcode03; }
							if($row->fld_barcode04!="") { $barcodes .= " , ".$row->fld_barcode04; }
							$deleted = "";
							if($row->fld_del==1) $deleted = "Yes";

					?>
                    <tr>
                        <td><?php echo $row->fld_id;?></td> 
						<td><a href="account/orders/product/<?php echo encodeValue($row->fld_id);?>"><?php echo $row->fld_name;?></a></td>                    	                    	
						<td><a href="account/orders/producttype/<?php echo $row->fld_type;?>"><?php echo $row->fld_type;?></a></td>
						<td><a href="account/orders/category/<?php echo encodeValue($row->fld_catid);?>"><?php echo $row->categoryname;?></a></td>
						<td><a href="account/orders/brand/<?php echo encodeValue($row->fld_brandid);?>"><?php echo $row->brandname;?></a></td>
                    	<td class="text-center"><?php echo $row->fld_noofbottlesincase;?></td>
						<td><?php echo $barcodes;?></td>
                        <!--<td align="center">
							<?php
							if($row->fld_status == "active")
							{
							?>
							<a id="chstatus_<?php echo $row->fld_id;?>" style="cursor:pointer" class="text-success" onclick="changestatus('<?php echo base_url() ?>','<?php echo $row->fld_id; ?>', '<?php echo $mgmtname;?>')"><i class="fa fa-check fa-lg" aria-hidden="true"></i></a>
							<input type="hidden" id="status_<?php echo $row->fld_id;?>" value="active" />
							<?php
							}
							else
							{
							?>
							<a id="chstatus_<?php echo $row->fld_id;?>" style="cursor:pointer" class="text-danger" onclick="changestatus('<?php echo base_url() ?>','<?php echo $row->fld_id; ?>', '<?php echo $mgmtname;?>')"><i class="fa fa-times fa-lg" aria-hidden="true"></i></a>
							<input type="hidden" id="status_<?php echo $row->fld_id;?>" value="inactive" />
							<?php
							}
							?>
                        </td>//'-->
                        <td align="center"><?php echo $deleted;?></td>
                        <!--<td align="center">
							<a href="account/<?php echo $mgmtname;?>/manage/<?php echo encodeValue($row->fld_id);?>" class="text-success" title="Update"><span class="fa fa-edit fa-lg"></span></a><span class="ml-2"></span></a>
							
						</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>

