<?php include "../../includes/start_ajax.php";

?>

<div  align=left >
<?php


if ($_SERVER[REQUEST_METHOD] == 'POST') {
	
	
	
	
	if($_REQUEST["product"]!="")
	{
		$_SESSION["stock_replenishment_product_picker"][$_REQUEST["product"]]="YES";
		
		
	}
	
	
}



if($_REQUEST["remove"]!="")
{
	unset($_SESSION["stock_replenishment_product_picker"][$_REQUEST["remove"]]);
	
	
}


$cell_width="100";


$this_url="report/stock_replenishment/index.php";


$query_pdt_count="select count(pdt_id) as total,
			pdt_category_code
			from t_".$key_table_prefix."_product 
			group by pdt_category_code ; ";
$result_pdt_count =mysqli_query($dbconn,$query_pdt_count);
while($line_pdt_count = mysqli_fetch_array($result_pdt_count,MYSQLI_ASSOC))
{
	$category_product_count[$line_pdt_count["pdt_category_code"]]=$line_pdt_count["total"];
}




echo "<section class='view_toolbar'>";
    echo "<div class='view_toolbar_left' style='width:80%;'>";
		echo "<font size=5 ><span class='fa fa-cart-plus fa-1x'></span> <b>Stock Replenishment Report</b></font>";

		echo "<br>";
	    
    echo "</div>";
    echo "<div class='view_toolbar_right'>";
    
		    echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:right;'  onclick=\"mon_refresh_tab(mon_current_selected_tab);\" >";
			    echo "<i class='fa fa-square fa-stack-2x color_red'   ></i><i class='fa fa-refresh fa-stack-1x color_white' ></i>";
		    echo "</div>";
   
    echo "</div>";
echo "</section>";




echo "<form name='form_replenishment_report' >";






//----------------------filters 1-------------------------------------------------------------


echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		echo "<span class='fa fa-filter fa-lg'></span> Warehouse";
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		
		echo "<select class='dropdown dropdown-auto' name='warehouse' >";
			
			
			
			echo "<option value=''>All Warehouses</option>";
			
			
			
			$query_whs="select * from t_".$key_table_prefix."_warehouse order by whs_code ; ";
			$result_whs =mysqli_query($dbconn,$query_whs);
			
			while($line_whs = mysqli_fetch_array($result_whs,MYSQLI_ASSOC))
			{
				
				
				
				if($_REQUEST["warehouse"]==$line_whs["whs_code"])
				{
					echo "<option value='".$line_whs["whs_code"]."' selected >";		
				}
				else {
					echo "<option value='".$line_whs["whs_code"]."' >";
						
				}
					echo $line_whs["whs_code"];
					echo " - ";
					echo $line_whs["whs_name"];
				echo "</option>";
				
			}


		
			echo "</select>";
	
	
	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
		echo "<br>";
	echo "</div>";
		
echo "</section>";




echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		echo "<span class='fa fa-filter fa-lg'></span> Product Category";
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		
	echo "<select class='dropdown dropdown-auto' name='category' >";
		echo "<option value='' >All Categories</option>";	
		
		$query_cat="select * from t_".$key_table_prefix."_category order by cat_code ; ";
		$result_cat =mysqli_query($dbconn,$query_cat);
		while($line_cat = mysqli_fetch_array($result_cat,MYSQLI_ASSOC))
		{
			
			if($_REQUEST["category"]==$line_cat["cat_code"])
			{
				echo "<option value='".$line_cat["cat_code"]."' selected >";
			}
			else {
				echo "<option value='".$line_cat["cat_code"]."' >";
					
			}
			
				echo $line_cat["cat_code"];
				echo " - ";
				echo $line_cat["cat_name"];
				
				echo " (".($category_product_count[$line_cat["cat_code"]]+0).")";
				
			echo "</option>";
			
		}
	echo "</select>";
	
	
	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
		echo "<br>";
	echo "</div>";
		
echo "</section>";





//----------------------filters 2-------------------------------------------------------------


echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		echo "<span class='fa fa-filter fa-lg'></span> Vendor";
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		echo "<select class='dropdown dropdown-l' name='vendor' >";
			
			$query_filter="select * from t_".$key_table_prefix."_vendor order by vdr_code ";
			echo "<option value=''>All Vendor</option>";
			$result_filter = mysqli_query($dbconn,$query_filter) or die("Listing failed- Err msg  ". mysqli_error($dbconn));
			while($line_filter=mysqli_fetch_array($result_filter,MYSQLI_ASSOC))
			{
				
				
				if($_REQUEST["vendor"]==$line_filter["vdr_code"])
				{
					echo "<option value='".$line_filter["vdr_code"]."' selected >";
				}
				else {
					echo "<option value='".$line_filter["vdr_code"]."'>";
						
				}
				
				
				
				echo "".$line_filter["vdr_code"]." - ".$line_filter["vdr_name"]."";
				echo "</option>";	
				
			}
		echo "</select>";
	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
			echo "<br>";
	echo "</div>";
		
echo "</section>";




//----------------------filters 2-------------------------------------------------------------


/*
echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		echo "<span class='fa fa-filter fa-lg'></span> Show Zero Balance Product";
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		echo "<select class='dropdown dropdown-auto' name='zero' >";
			
			foreach($mon_keyword_list["key_yes_no"] as $key=>$value)
			{
				echo "<option value='".$key."'>";
					echo $value;	
				echo "</option>";	
				
			}
		echo "</select>";
	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
			echo "<br>";
	echo "</div>";
		
echo "</section>";

*/


//----------------------product picker-------------------------------------------------------------

echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		echo "<span class='fa fa-cubes fa-lg'></span> Product(s)";
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		
		echo "<input type=text class='textbox textbox-l' name='product' 
			    onkeyup=\"if(this.value=='')
					    {
						    document.getElementById('autofill_stock_replenish').style.visibility='hidden';
					    }else{
						    document.getElementById('autofill_stock_replenish').style.visibility='visible';
						    mon_send_get_lookup('report/stock_replenishment/lookup_product.php','?search='+this.value,'autofill_stock_replenish');
					    }
						    \"
				
						    >";
		
	    echo "<div id='autofill_stock_replenish' style='padding:2px;min-height:10px;height:?px;overflow:auto;background:#ffffff;position:absolute;border:1px solid #ECF0F1;visibility:hidden;-moz-box-shadow: 1px 1px 10px #888;-webkit-box-shadow: 1px 1px 10px #888;box-shadow: 1px 1px 10px #888;' >";
	    echo "</div>";

	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
			echo "<br>";
	echo "</div>";
		
echo "</section>";




//----------------------product picker listing-------------------------------------------------------------

echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		
	
	    		
			foreach($_SESSION["stock_replenishment_product_picker"] as $pdt_code => $pdt_value)
			{
				echo "<div style='float:left;margin:2px;border-radius:8px;padding:8px;background:#ECF0F1;color:#000;width:?px;min-width:10px;'>";
				echo "".$pdt_code."";
				echo " <span class='fa fa-times fa-1x' style='color:#95A5A6;' onclick=\"mon_send_get('report/stock_replenishment/index.php','?remove=".$pdt_code."','div_main')\"> </span>";
				echo "</div>";
				
			}
	
	
	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
			echo "<br>";
	echo "</div>";
		
echo "</section>";









echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
	
	
		echo "  <input type=button class='button button-blue' name='generate_report'  value='Generate Report' onclick=\"print_page('print/stock_replenishment_report/index.php?warehouse='+encodeURIComponent(document.form_replenishment_report.warehouse.value.replace(/&/g, '%26'))+'&category='+document.form_replenishment_report.category.value+'&vendor='+document.form_replenishment_report.vendor.value)\">";
	
	
		
	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
			echo "<br>";
	echo "</div>";
		
echo "</section>";




echo "<div style='float:left;height:200px;'></div>";

echo "</form>";
?>
</div>
<?php include "../../includes/end_ajax.php";

?>
