<?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>Purchase Report - Item Wise</h3>
          </div>
        </div>
        
        <div class="container_fluid mt-2 px-3">
		<form name="frmsearch" method="get" action="warehouse/<?php echo $mgmtname;?>/itemreport">
         <table class="webforms sttbl bg-light my-0 table-responsive-sm">
          <tr>
           <td class="pr-0" width="35%"><input type="text" name="search" size="20" value="<?php echo $this->input->get("search");?>" placeholder="search by ref. no or item name"></td>
          <td class="pr-0" width="20%">
		<select name="vendorid" id="vendorid" class="js-example-basic-single nxtinput">
		  <option value="">All Vendors</option>
						<?php
						if(is_array($vendorlist) && count(array_filter($vendorlist))>0)
						{

							foreach($vendorlist as $vendorrow)
							{
								$sel_vendor ="";
								if(decodeValue($this->input->get("vendorid"))==$vendorrow->fld_id)
								{
									$sel_vendor = 'selected="selected"';
								}				
									?>
											<option value="<?php echo encodeValue($vendorrow->fld_id);?>" <?php echo $sel_vendor;?>><?php echo $vendorrow->fld_name;?></option>
									<?php
								
							}
						}
						?> 
		  </select>
		  </td>
          
           <td class="pr-0" width="10%"><input type="text" name="fromdate" id="fromdate" value="<?php echo $fromdate;?>"   placeholder="From Date" class="datepicker" style="width:120px;"/></td>
           <td class="pr-0" width="10%"><input type="text" name="todate" id="todate"  value="<?php echo $todate;?>" placeholder="To Date" class="datepicker" style="width:120px;"/></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">
		 <form name="frmlisting" id="frmlisting" action="<?php echo base_url()."warehouse/".$mgmtname;?>" method="post" onsubmit=" return checkboxvalidate();">
                <thead>
                	<tr>
                    	<th width="5%">Serial</th>
                    	<th width="15%">Vendor</th>                    	
                    	<th width="5%">Ref. #</th>                    	
                    	<th width="8%">Date</th>                    	
                    	<th width="15%">Product</th>
                    	<th width="10%" class="text-right">Qty. Case</th>
                    	<th width="10%" class="text-right">Qty. Bottle</th>
                    	<th width="10%" class="text-right">Price Case</th>
                    	<th width="10%" class="text-right">Price Bottle</th>
                    	<th width="10%" class="text-right">Amount (<?php echo CURRENCY;?>)</th>
                    </tr>
                    </thead>
                    <tbody>
					<?php
					
					if(is_array($results) && count(array_filter($results))>0)
					{
						$totalamount = 0;
						$rowindex = 0;
						$caseqty = 0;
						$bottleqty = 0;
						
						foreach($results as $row)
						{
							$rowindex++;
							$totalamount += $row->fld_subtotal;
							$caseqty += $row->fld_qty_case;
							$bottleqty += $row->fld_qty_bottle;


					?>
                    <tr>
                    	<td class="text-center"><?php echo $rowindex;?>.</td>                    	
       
                    	<td><?php echo $row->vendorname;?></td>              
                    	              
                    	<td class="text-center"><?php echo $row->fld_refno;?></td>              
                    	<td nowrap><?php echo date("d-M-Y", strtotime($row->fld_refdate));?></td>           
                         <td><?php echo $row->productname;?></td> 
                         <td class="text-right"><?php echo $row->fld_qty_case;?></td> 
                         <td class="text-right"><?php echo $row->fld_qty_bottle;?></td> 
                         <td class="text-right"><?php echo $row->fld_price_case;?></td> 
                         <td class="text-right"><?php echo $row->fld_price_bottle;?></td> 
                         <td class="text-right"><?php echo number_format($row->fld_subtotal,2);?></td> 
                    </tr>
                    <?php
						}
					?>
					<tr>
						<th colspan="5">Total:</th>
						<th class="text-right"><?php echo $caseqty;?></th>
						<th class="text-right"><?php echo $bottleqty;?></th>
						<th></th>
						<th></th>
						<th class="text-right"><?php echo number_format($totalamount, 2);?></th>
					</tr>
					<?php
					}
					else
					{
                    ?>
                    <tr><td colspan="10" style="text-align:center">Record not found!</td></tr>
                    <?php
					}
                    ?>
                    
                    
                    </tbody>
                </table>
                 
	         <div class="clearfix"></div>
          
        </div>
            
        </div>

