<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$addpmtr = "?warehouseid=".$this->input->get("warehouseid")."=&fromdate=".$fromdate."&todate=".$todate;
//$previousstockdate = date('d-M-Y', strtotime('-1 day', strtotime($fromdate)));
?>
      <div class="main my-0">
        <div class="row mt-3 mx-0">
          <div class="col-md-9">
            <h3>Item Sale Report</h3>
          </div>
          <div class="col-md-3 text-right">
			
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="account/<?php echo $mgmtname;?>">
         <table class="webforms sttbl bg-light my-0 table-responsive-sm">
          <tr>
          <td class="pr-0" width="20%">
		<select name="productid" id="productid" class="js-example-basic-single" style="width:300px;" required>
		  <option value="">Select Item</option>
						<?php
						if(is_array($rsproducts) && count(array_filter($rsproducts))>0)
						{

							foreach($rsproducts as $row)
							{
								$selelement = "";
								if($this->input->get("productid")==$row->fld_id)
								{
									$selelement = ' selected="selected"';
								}				
									?>
											<option value="<?php echo $row->fld_id;?>" <?php echo $selelement;?>><?php echo $row->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>

          <td class="pr-0" width="20%">
		<select name="outletid" id="outletid" class="js-example-basic-single">
		  <option value="">ALL Outlets</option>
			<?php
			if(is_array($outletlist) && count(array_filter($outletlist))>0)
			{

				foreach($outletlist as $row)
				{
					$selelement="";
					if($this->input->get("outletid")==$row->fld_id)
					{
						$selelement = 'selected="selected"';
					}				
						?>
								<option value="<?php echo $row->fld_id;?>" <?php echo $selelement;?>><?php echo $row->fld_name;?></option>
						<?php
					
				}
			}
			?> 
		  </select>
		  </td>
           <td class="pr-0" width="8%"><input type="text" name="fromdate" id="fromdate" value="<?php echo $this->input->get("fromdate");?>"   placeholder="From Date" class="datepicker" style="width:150px;" /></td>
           <td class="pr-0" width="8%"><input type="text" name="todate" id="todate"  value="<?php echo $this->input->get("todate");?>" placeholder="To Date" class="datepicker" style="width:150px;" /></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%">Serial</th>                    	
                    	<th width="65%">Outlet</th>
                    	<th width="15%" class="text-right">Quantity (Bottles)</th>
                    	<th width="15%" class="text-right">Quantity (Cases)</th>
                    </tr>
                    </thead>
                    <tbody>
					<?php
					if(is_array($results) && count(array_filter($results))>0)
					{
						$rowindex = 0;
						$totalbottles = 0;
						$totalcases = 0;
						foreach($results as $row)
						{
							$rowindex++;
							if($row["outgoing"]>0)
							{
								$totalbottles += $row["outgoing"];
								$totalcases += $row["outgoingcases"];
					?>
                    <tr>
                    	<td class="text-center"><?php echo $rowindex;?>.</td>
                    	<td><?php echo $row['name'];?></td>
                    	<td class="text-right"><?php echo $row["outgoing"];?></td>
                    	<td class="text-right"><?php echo $row["outgoingcases"];?></td>
                    </tr>
                    <?php
							}
						}
					?>
                    <tr style="background-color:#dee2e6;">
                    	<td colspan="2"><strong>Total</strong></td>
                    	<td class="text-right"><strong><?php echo number_format($totalbottles);?></strong></td>
                    	<td class="text-right"><strong><?php echo number_format($totalcases, 2);?></strong></td>
                    </tr>
					<?php
					}
					else
					{
						$message2show = "Select item from the list above!";
						if($this->input->get("productid")!="") $message2show = "Data not found for this item!";
                    ?>
                    <tr><td colspan="4" style="text-align:center"><?php echo $message2show;?></td></tr>
                    <?php
					}
                    ?>
                    </tbody>
                </table>
                 
	         <div class="clearfix"></div>
          
        </div>
            
        </div>

