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

?>

<div  align=left >
<?php


echo "<section class='view_toolbar'>";
    echo "<div class='view_toolbar_left' style='width:50%;'>";
		echo "<font size=5 ><span class='fa fa-bar-chart fa-1x'></span> <b>Stock Balance</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>";





$cell_width="50";


$this_url="mod/stock_balance_simple/index.php";




if($_REQUEST["filter_balance_category"]!="")
{
		$_SESSION["list_filter"]["filter_balance_category"] = $_REQUEST["filter_balance_category"];
}
if($_SESSION["list_filter"]["filter_balance_category"]=="")
{
    $_SESSION["list_filter"]["filter_balance_category"]="ALL";
}


if($_REQUEST["filter_balance_warehouse"]!="")
{
	$_SESSION["list_filter"]["filter_balance_warehouse"] = $_REQUEST["filter_balance_warehouse"];
		
}
if($_SESSION["list_filter"]["filter_balance_warehouse"]=="")
{
    $_SESSION["list_filter"]["filter_balance_warehouse"]="ALL";
}




if($_REQUEST["filter_balance_vendor"]!="")
{
    $_SESSION["list_filter"]["filter_balance_vendor"]=$_REQUEST["filter_balance_vendor"];
}

if($_SESSION["list_filter"]["filter_balance_vendor"]=="")
{
    $_SESSION["list_filter"]["filter_balance_vendor"]="ALL";
}



//-------------toggle filter button---------------------
if($_REQUEST["filter_balance_color"]!="")
{
	
	if($_SESSION["list_filter"]["filter_balance_color"]=="YES")
	{
	    $_SESSION["list_filter"]["filter_balance_color"]="";
	}
	else {
		$_SESSION["list_filter"]["filter_balance_color"]="YES";
	}
}



if($_REQUEST["filter_balance_size"]!="")
{
	
	if($_SESSION["list_filter"]["filter_balance_size"]=="YES")
	{
	    $_SESSION["list_filter"]["filter_balance_size"]="";
	}
	else {
		$_SESSION["list_filter"]["filter_balance_size"]="YES";
	}
}


if($_REQUEST["filter_balance_pattern"]!="")
{
	
	if($_SESSION["list_filter"]["filter_balance_pattern"]=="YES")
	{
	    $_SESSION["list_filter"]["filter_balance_pattern"]="";
	}
	else {
		$_SESSION["list_filter"]["filter_balance_pattern"]="YES";
	}
}


if($_REQUEST["filter_balance_featured"]!="")
{
	
	if($_SESSION["list_filter"]["filter_balance_featured"]=="YES")
	{
	    $_SESSION["list_filter"]["filter_balance_featured"]="";
	}
	else {
		$_SESSION["list_filter"]["filter_balance_featured"]="YES";
	}
}


if($_REQUEST["filter_balance_inventory"]!="")
{
	
	if($_SESSION["list_filter"]["filter_balance_inventory"]=="YES")
	{
	    $_SESSION["list_filter"]["filter_balance_inventory"]="";
	}
	else {
		$_SESSION["list_filter"]["filter_balance_inventory"]="YES";
	}
}


if($_REQUEST["filter_balance_discount"]!="")
{
	
	if($_SESSION["list_filter"]["filter_balance_discount"]=="YES")
	{
	    $_SESSION["list_filter"]["filter_balance_discount"]="";
	}
	else {
		$_SESSION["list_filter"]["filter_balance_discount"]="YES";
	}
}

if($_SESSION["list_filter"]["filter_balance_date"]=="")
{
	$_SESSION["list_filter"]["filter_balance_date"]=date("Y-m-d");	
}

if($_REQUEST["balance_date"]!="")
{
	$_SESSION["list_filter"]["filter_balance_date"] = $_REQUEST["balance_date"];
}







$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 "<form name='form_balance' >";



	

//----------------------filters 0-------------------------------------------------------------


echo "<section class='view_toolbar' >";
	echo "<div class='view_toolbar_search_field'>";
		echo "<span class='fa fa-filter fa-lg'></span> Filter Product with Settings";
	echo "</div>";
	echo "<div class='view_toolbar_filter' style='border:0px solid #ff0000;'>";
		
		echo "<div   class='view_toolbar_filter_box'>";			
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer; ' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&filter_balance_color=YES&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
				if($_SESSION["list_filter"]["filter_balance_color"]=="YES")
				{
					$this_button_color="color_green";
				}
				else {
					$this_button_color="color_grey";
				}
				echo '<i class="fa fa-square fa-stack-2x '.$this_button_color.'"  ></i><i class="fa fa-tint fa-stack-1x color_white" ></i>';
			echo "</div> Color ";
		echo "</div>";
			
		echo "<div   class='view_toolbar_filter_box'>";				
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer; ' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&filter_balance_size=YES&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
			if($_SESSION["list_filter"]["filter_balance_size"]=="YES")
			{
				$this_button_color="color_green";
			}
			else {
				$this_button_color="color_grey";
			}
				echo '<i class="fa fa-square fa-stack-2x '.$this_button_color.'"  ></i><i class="fa fa-arrows-h fa-stack-1x color_white" ></i>';
			echo "</div> Size ";
		echo "</div>";	
			
		echo "<div class='view_toolbar_filter_box'>";			
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer; ' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&filter_balance_pattern=YES&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
			if($_SESSION["list_filter"]["filter_balance_pattern"]=="YES")
			{
				$this_button_color="color_green";
			}
			else {
				$this_button_color="color_grey";
			}
				echo '<i class="fa fa-square fa-stack-2x '.$this_button_color.'"  ></i><i class="fa fa-puzzle-piece fa-stack-1x color_white" ></i>';
			echo "</div> Pattern";
		echo "</div>";
		
		echo "<div   class='view_toolbar_filter_box'>";			
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&filter_balance_featured=YES&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
			if($_SESSION["list_filter"]["filter_balance_featured"]=="YES")
			{
				$this_button_color="color_green";
			}
			else {
				$this_button_color="color_grey";
			}	
				echo '<i class="fa fa-square fa-stack-2x '.$this_button_color.'"  ></i><i class="fa fa-lightbulb-o fa-stack-1x color_white" ></i>';
			echo "</div> Featured ";
		echo "</div>";
		
		echo "<div   class='view_toolbar_filter_box'>";			
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&filter_balance_inventory=YES&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
			if($_SESSION["list_filter"]["filter_balance_inventory"]=="YES")
			{
				$this_button_color="color_green";
			}
			else {
				$this_button_color="color_grey";
			}	
				echo '<i class="fa fa-square fa-stack-2x '.$this_button_color.'"  ></i><i class="fa fa-cubes fa-stack-1x color_white" ></i>';
			echo "</div> Inventory ";
		echo "</div>";
			
		echo "<div   class='view_toolbar_filter_box'>";			
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer;' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&filter_balance_discount=YES&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
			if($_SESSION["list_filter"]["filter_balance_discount"]=="YES")
			{
				$this_button_color="color_green";
			}
			else {
				$this_button_color="color_grey";
			}
				echo '<i class="fa fa-square fa-stack-2x '.$this_button_color.'"  ></i><i class="fa fa-cut fa-stack-1x color_white" ></i>';
			echo "</div> Discount ";
		echo "</div>";
			
	echo "</div>";
	
echo "</section>";




//----------------------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='filter_balance_warehouse' onchange=\"mon_send_get('mod/stock_balance_simple/index.php','?filter_balance_warehouse='+this.value+'&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
			
			
			
			echo "<option value='ALL'>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($_SESSION["list_filter"]["filter_balance_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='filter_balance_category' onchange=\"mon_send_get('mod/stock_balance_simple/index.php','?filter_balance_category='+this.value+'&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
		
		
		if($_SESSION["list_filter"]["filter_balance_category"]=="ALL")
		{
			echo "<option value='ALL' selected >All Categories</option>";
		}
		else {
			echo "<option value='ALL' >All Categories</option>";	
		}
		
		
		if($_SESSION["list_filter"]["filter_balance_category"]=="UNSPECIFIED")
		{
			echo "<option value='UNSPECIFIED' selected >Unspecified</option>";
		}
		else {
			echo "<option value='UNSPECIFIED' >Unspecified</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($_SESSION["list_filter"]["filter_balance_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='filter_balance_vendor' onchange=\"mon_send_get('mod/stock_balance_simple/index.php','?filter_balance_vendor='+this.value+'&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\" >";
			
			$query_filter="select * from t_".$key_table_prefix."_vendor order by vdr_code ";
			echo "<option value='ALL'>All</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($_SESSION["list_filter"]["filter_balance_vendor"]==$line_filter["vdr_code"])
				{
					echo "<option value='".$line_filter["vdr_code"]."' selected >".$line_filter["vdr_code"]." - ".$line_filter["vdr_name"]."</option>";
				}
				else {
					echo "<option value='".$line_filter["vdr_code"]."'>".$line_filter["vdr_code"]." - ".$line_filter["vdr_name"]."</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-search fa-lg'></span> Balance as at: ";
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		
		
		echo "<input type=text class='textbox textbox-s' name='filter_balance_date' value='".$_SESSION["list_filter"]["filter_balance_date"]."' id='filter_balance_date' onfocus=blur() >";
		echo "<a href=\"javascript:void(0)\" onclick=\"if(self.gfPop)gfPop.fPopCalendar(document.form_balance.filter_balance_date);"."return false;\" HIDEFOCUS>";
		//echo "<img class=\"PopcalTrigger\" align=\"absmiddle\" "."src=".$addon_path.$theme_path."icon/calendar.gif border=0>";
		echo " <span class='fa fa-calendar fa-lg'></font>";
		echo "</a>"; 
		
		echo " <input type=button class='button button-blue' name='set_date_button'  value='Set As At Date' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&balance_date='+document.getElementById('filter_balance_date').value,'div_main')\">";
		
	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-search fa-lg'></span> Search";
	echo "</div>";
	echo "<div class='view_toolbar_search_button'>";
		echo "<input type=text class='textbox textbox-l' name='search_word' id='balance_product_search_word' value='".$_REQUEST["search_word"]."'>";
		echo "<br><br> <input type=button class='button button-blue' name='search_button'  value='Search' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&search_word='+document.getElementById('balance_product_search_word').value,'div_main')\">";
		echo " <input type=button class='button button-grey' name='clear_button'  value='Clear' onclick=\"mon_send_get('$this_url','?offset=0".$extraurl."&search_word=','div_main')\">";
		echo "<br><br>";
		
	echo "</div>";
	echo "<div class='view_toolbar_action_button'>";
			echo "<br>";
	echo "</div>";
		
echo "</section>";





	
	$data_found=false;

	$query_pdt="select * from t_".$key_table_prefix."_product 
			where pdt_id> 0 
			";
			//where pdt_code = '".$_SESSION["BALANCE_PDT_CODE"]."'
	if($_SESSION["list_filter"]["filter_balance_category"]!="ALL")
	{
		if($_SESSION["list_filter"]["filter_balance_category"]=="UNSPECIFIED")
		{
			$query_pdt=$query_pdt." and (pdt_category_code = '' or pdt_category_code = '0'  ) ";
		}
		else {
			$query_pdt=$query_pdt." and pdt_category_code = '".$_SESSION["list_filter"]["filter_balance_category"]."' ";
		}
		
		
	}
	
	
				 
	if($_SESSION["list_filter"]["filter_balance_vendor"]!="ALL")
	{
		$query_pdt=$query_pdt." and pdt_vendor_code = '".$_SESSION["list_filter"]["filter_balance_vendor"]."' ";
		
	}
	if($_REQUEST["search_word"]!="")
	{
		$query_pdt=$query_pdt." and  ( pdt_code like '%".$_REQUEST["search_word"]."%' ";
		$query_pdt=$query_pdt." or pdt_barcode like '%".$_REQUEST["search_word"]."%' ";
		$query_pdt=$query_pdt." or pdt_name like '%".$_REQUEST["search_word"]."%' ";
		$query_pdt=$query_pdt." ) ";
	}
	
	if($_SESSION["list_filter"]["filter_balance_color"]=="YES")
    	{
    	    $query_pdt=$query_pdt." and pdt_select_color = 'YES' ";   
    	}
	
	if($_SESSION["list_filter"]["filter_balance_size"]=="YES")
    	{
    	    $query_pdt=$query_pdt." and pdt_select_size = 'YES' ";   
    	}
	
	if($_SESSION["list_filter"]["filter_balance_pattern"]=="YES")
    	{
    	    $query_pdt=$query_pdt." and pdt_select_pattern = 'YES' ";   
    	}
	
	if($_SESSION["list_filter"]["filter_balance_featured"]=="YES")
    	{
    	    $query_pdt=$query_pdt." and pdt_featured = 'YES' ";   
    	}
	
	if($_SESSION["list_filter"]["filter_balance_featured"]=="YES")
     {
 	   $query_pdt=$query_pdt." and pdt_featured = 'YES' ";   
     }
	
	if($_SESSION["list_filter"]["filter_balance_inventory"]=="YES")
     {
 	   $query_pdt=$query_pdt." and pdt_inventory_tracking = 'YES' ";   
     }
	
	
	if($_SESSION["list_filter"]["filter_balance_discount"]=="YES")
     {
 	   $query_pdt=$query_pdt." and pdt_discount_allow = 'YES' ";   
     }
	
	
	
	
	$result_pdt =mysqli_query($dbconn,$query_pdt);
	while($line_pdt = mysqli_fetch_array($result_pdt,MYSQLI_ASSOC))
	{
		$data_found=true;
		$pdt_data[$line_pdt["pdt_code"]]=$line_pdt["pdt_name"];
		
		$lib_barcode[$line_pdt["pdt_code"]]=$line_pdt["pdt_barcode"];
	}
	
	
	
	
	
	
	
	
	
	
	$query_whs = "select * from t_".$key_table_prefix."_warehouse 
			 ";
	if($_SESSION["list_filter"]["filter_balance_warehouse"]!="ALL")		 
	{
		$query_whs = $query_whs." where whs_code = '".$_SESSION["list_filter"]["filter_balance_warehouse"]."' ";
	}
	
	$result_whs = mysqli_query($dbconn,$query_whs);
	while($line_whs = mysqli_fetch_array($result_whs,MYSQLI_ASSOC))
	{
		$whs_data[$line_whs["whs_code"]]=$line_whs["whs_name"];
	}
	
	


	unset($bal_data);
	
	$query_balance="select * from t_".$key_table_prefix."_balance
				";
	if($_SESSION["list_filter"]["filter_balance_warehouse"]!="ALL")		 
	{
		$query_balance = $query_balance." where bal_warehouse_code = '".$_SESSION["list_filter"]["filter_balance_warehouse"]."' ";
	}
	$result_balance=mysqli_query($dbconn,$query_balance);
	while($line_balance=mysqli_fetch_array($result_balance,MYSQLI_ASSOC))
	{
		$bal_data[$line_balance["bal_product_code"]][$line_balance["bal_warehouse_code"]] = $bal_data[$line_balance["bal_product_code"]][$line_balance["bal_warehouse_code"]] +  $line_balance["bal_quantity"];	
		$bal_data[$line_balance["bal_product_code"]]["ALL"] = $bal_data[$line_balance["bal_product_code"]]["ALL"] +  $line_balance["bal_quantity"];	
		
	}
	
	
	//=======================stock card to calculate back until START date=============================
	$query_transaction_start="select sum(stc_base_quantity) as total_quantity,
					stc_stock_code,
					stc_warehouse_code ,
					stc_type
					from t_".$key_table_prefix."_stock_card
					where stc_date > '".$_SESSION["list_filter"]["filter_balance_date"]."'  
					";
	if($_SESSION["list_filter"]["filter_balance_warehouse"]!="ALL")		 
	{
		$query_transaction_start = $query_transaction_start." and stc_warehouse_code = '".$_SESSION["list_filter"]["filter_balance_warehouse"]."' ";
	}
	
	$query_transaction_start = $query_transaction_start." group by  stc_stock_code , stc_warehouse_code ,stc_type ";
	$result_transaction_start = mysqli_query($dbconn,$query_transaction_start) or die("error");
	while($line_transaction_start = mysqli_fetch_array($result_transaction_start,MYSQLI_ASSOC))
	{
		if($line_transaction_start["stc_type"]=="PLUS")
		{
			
			
			
			$bal_data[$line_transaction_start["stc_stock_code"]][$line_transaction_start["stc_warehouse_code"]] = $bal_data[$line_transaction_start["stc_stock_code"]][$line_transaction_start["stc_warehouse_code"]] - abs($line_transaction_start["total_quantity"]);
			$bal_data[$line_transaction_start["stc_stock_code"]]["ALL"] = $bal_data[$line_transaction_start["stc_stock_code"]]["ALL"] - abs($line_transaction_start["total_quantity"]);
			
			
			
		}
		
		if($line_transaction_start["stc_type"]=="MINUS")
		{
			$bal_data[$line_transaction_start["stc_stock_code"]][$line_transaction_start["stc_warehouse_code"]] = $bal_data[$line_transaction_start["stc_stock_code"]][$line_transaction_start["stc_warehouse_code"]] + abs($line_transaction_start["total_quantity"]);
			$bal_data[$line_transaction_start["stc_stock_code"]]["ALL"] = $bal_data[$line_transaction_start["stc_stock_code"]]["ALL"] + abs($line_transaction_start["total_quantity"]);
		}
		
	}	
		
		
		
		
		
		
		
		
		
		
		
		
		echo "<div class='data_display_content'>";	
		
		
			echo "<table cellpadding=8 cellspacing=1  bgcolor=#BDC3C7 style='margin:10px;'>";
				
				echo "<tr>";
					echo "<td bgcolor=#ECF0F1 ><b>Code</b></td>";
					echo "<td bgcolor=#ECF0F1 ><b>Barcode</b></td>";
					echo "<td bgcolor=#ECF0F1 ><b>Name</b></td>";
					foreach($whs_data as $whs_code => $whs_name)
					{
						echo "<td bgcolor=#ECF0F1 >";
							echo "<b>".$whs_code."</b><br>";
							echo "<font size=1>".$whs_name."</font>";						
						echo "</td>";	
					}
					echo "<td bgcolor=#ECF0F1 ><b>Total</b></td>";
					
				echo "</tr>";
			
			
					
			if(!$data_found)		
			{
				echo "<tr>";
				
				
					echo "<td  bgcolor=#ECF0F1 colspan=".(4+count($whs_data))." align=center >";	
						echo "<br><br><font color=#BDC3C7 >No Product Found</font><br><br><br>";
					echo "</td>";
			
				echo "</tr>";
				
				
			}
			else {
				foreach($pdt_data as $pdt_code => $pdt_name)
				{
				
					echo "<tr>";

						echo "<td bgcolor=#fff >";
								echo "<font color=#000>".$pdt_code."</font> ";	
						echo "</td>";
						
						echo "<td bgcolor=#fff >";
								echo "<font color=#000>".$lib_barcode[$pdt_code]."</font> ";
						echo "</td>";		
					
						echo "<td bgcolor=#fff >";
								echo "<font color=#000>".$pdt_name."</font>";
						echo "</td>";
						
						
				
						foreach($whs_data as $whs_code => $whs_name)
						{
							echo "<td bgcolor=#fff align=right >";
								
									echo $bal_data[$pdt_code][$whs_code];
							echo "</td>";
							$total_bal_data[$whs_code] = $total_bal_data[$whs_code] + $bal_data[$pdt_code][$whs_code];
						}
						
						
						echo "<td bgcolor=#fff align=right >";
							echo "<b>".$bal_data[$pdt_code]["ALL"]."</b>";
						echo "</td>";
						
						
						$total_bal_data["ALL"] = $total_bal_data["ALL"] + $bal_data[$pdt_code]["ALL"];
							
						
					echo "</tr>";
					
				}
			
			
			
			
				//total:
				
				echo "<tr>";

					echo "<td bgcolor=#ECF0F1 colspan=3 align=right >";
							echo "<font color=#000><b>Total</b></font> ";	
					echo "</td>";
					
			
					foreach($whs_data as $whs_code => $whs_name)
					{
						echo "<td  bgcolor=#ECF0F1 align=right >";
								echo "<b>".$total_bal_data[$whs_code]."</b>";		
						echo "</td>";
					}
					
					echo "<td  bgcolor=#ECF0F1 align=right >";
						echo "<b>".$total_bal_data["ALL"]."</b>";
					echo "</td>";
					
					
				echo "</tr>";
				
			}	
			
		echo "</table>";			
echo "</div>";

		
		



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

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

?>
