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


//------------------data display----------------------
echo "<div class='data_display_content'>";	
	
	$query_pdt = "select * from t_".$key_table_prefix."_product ";
	$result_pdt = mysqli_query($dbconn,$query_pdt);
	while($line_pdt = mysqli_fetch_array($result_pdt,MYSQLI_ASSOC))
	{
		$pdt_data[$line_pdt["pdt_code"]]=$line_pdt;
	}
	

echo "<table  width=100% cellspacing=10 cellpadding=10 >";
	echo "<tr>";
		
		
		
		echo "<td valign=top width=30% >";
			echo "<span class='fa fa-map-marker fa-lg'></span> <b>Storage Location:</b> ";
			echo "".$_REQUEST["loc_code"];
			
			
			$query_storage_location="select * from t_".$key_table_prefix."_storage_location 
						where loc_code = '".$_REQUEST["loc_code"]."' ";
			$result_storage_location = mysqli_query($dbconn, $query_storage_location);
			if($line_storage_location = mysqli_fetch_array($result_storage_location,MYSQLI_ASSOC))
			{
				
				echo " ".$line_storage_location["loc_name"];
			}
			
			
			echo "<br>";
			
			echo "<br><div style='border:1px solid #ECF0F1;'>";
			
			
			
			
			
			
			$this_url="mod/floor_plan_display/display.php";


			//----------------------------------year-----------------------------------
			if($_REQUEST["cal_year"]!="")
			{
			  $_SESSION["cal_year"]=$_REQUEST["cal_year"];
			}
			if($_SESSION["cal_year"]=="")
			{
			 $_SESSION["cal_year"]=date("Y");
			}



			//----------------------------------month-----------------------------------
			if($_REQUEST["cal_month"]!="")
			{
			  $_SESSION["cal_month"]=$_REQUEST["cal_month"];
			  
			  
			}
			if($_SESSION["cal_month"]=="")
			{
			 $_SESSION["cal_month"]=date("m");
			}

			//----------------------------------date-----------------------------------
			if($_REQUEST["cal_date"]!="")
			{
				 $_SESSION["cal_date"] =$_REQUEST["cal_date"];
			}
			if($_SESSION["cal_date"]=="")
			{
				 $_SESSION["cal_date"] =date("Y-m-d");
			}
			    
			    
			    
			    $month_text[1]="JAN";
			    $month_text[2]="FEB";
			    $month_text[3]="MAR";
			    $month_text[4]="APR";
			    $month_text[5]="MAY";
			    $month_text[6]="JUN";
			    $month_text[7]="JUL";
			    $month_text[8]="AUG";
			    $month_text[9]="SEP";
			    $month_text[10]="OCT";
			    $month_text[11]="NOV";
			    $month_text[12]="DEC";
			    
			    
			    $month_text2[1]="January";
			    $month_text2[2]="February";
			    $month_text2[3]="March";
			    $month_text2[4]="April";
			    $month_text2[5]="May";
			    $month_text2[6]="June";
			    $month_text2[7]="July";
			    $month_text2[8]="August";
			    $month_text2[9]="September";
			    $month_text2[10]="October";
			    $month_text2[11]="November";
			    $month_text2[12]="December";
			    
			   
			   
			   
			   
			    
			    function build_calendar($month,$year) {
			    
			              	global $this_cus_id;
				       	global $this_folder;
				       	global $key_table_prefix,$CurrentUserID, $attendance_count,$CurrentUserDiscipline;
				    
				       	global $CurrentUserLevel,$mon_keyword_list,$CurrentUserDiscipline_LIST;
				    
				       	global $cus_name;
			    
			              	global $this_url;
			              	global $t;
			              	global $tab_extra_url;
			              	global $tab_key_id;
			    
			    			global $dbconn;
			    
			    
			    
			    
			    
			    
			    
			       // Create array containing abbreviations of days of week.
			       $daysOfWeek = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
			       //$daysOfWeek = array('S','M','T','W','T','F','S');
			    
			        // What is the first day of the month in question?
			        $firstDayOfMonth = mktime(0,0,0,$month,1,$year);
			    
			        // How many days does this month contain?
			        $numberDays = date('t',$firstDayOfMonth);
			    
			        // Retrieve some information about the first day of the
			        // month in question.
			        $dateComponents = getdate($firstDayOfMonth);
			    
			        // What is the name of the month in question?
			        $monthName = $dateComponents['month'];
			    
			        // What is the index value (0-6) of the first day of the
			        // month in question.
			        $dayOfWeek = $dateComponents['wday'];
			    
			    
			    
			        // Create the table tag opener and day headers
			        $calendar = "<table border=0 width=100% align=center><tr><td>";
			        $calendar .= "<table  border=0  width=100%  align=center cellspacing=2 cellpadding=5 >";
			        //$calendar .= "<caption><FONT SIZE =2 color=#ffffff><B>$monthName, $year</a></B></FONT></caption>";
			        $calendar .= "<tr>";
			    
			        // Create the calendar headers
			    
			        foreach($daysOfWeek as $day) {
			              $calendar .= "<td  width=14% style='background:#DADFE1;' align=right ><font size=2 color=#000> $day </font></td>";
			        }
			    
			        // Create the rest of the calendar
			        // Initiate the day counter, starting with the 1st.
			        $currentDay = 1;
			    
			        $calendar .= "</tr><tr>";
			    
			        // The variable $dayOfWeek is used to
			        // ensure that the calendar
			        // display consists of exactly 7 columns.
			        if ($dayOfWeek > 0) {
			              $calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>";
			        }
			    
			                while ($currentDay <= $numberDays)
			                {
			    
			                    if ($dayOfWeek == 7)
			                    {
			                        $dayOfWeek = 0;
			                        $calendar .= "</tr><tr>";
			                    }
			    
			    
			                        $todayDay = date("j");
			                        $todayMonth = date("m");
			                        $todayYear = date("Y");
			    
			                        $date_p = "$year-$month-".substr(($currentDay+100),-2);
			    
			                        $currentDay2=substr(($currentDay+100),-2);
			                        $month2=substr(($month+100),-2);
			    
			                        $page_date=$year."-".$month2."-".$currentDay2;
			    
			    
			                        if ($currentDay==$todayDay AND $month==$todayMonth AND $year==$todayYear)
			                        {
			                            $border_color="#3498DB";
			    
			                        }
			                        else
			                        {
			                            $border_color="#ECF0F1";
			    
			                        }
			    
			    
			                        if ($_SESSION["cal_date"]==$page_date)
			                        {
			    
			                              $background_color="#BDC3C7";
			                        }
			                        else {
			                         	$background_color="#ECF0F1";
			                        }
			    
			    
			    					$this_link ="mon_send_get('mod/floor_plan_display/display.php','?loc_code=".$_REQUEST["loc_code"]."&cal_date=".$page_date."','div_display')";
			    
			    
			    
			                        $calendar .= "<td style='cursor:pointer;background:".$background_color.";min-height:200px;height:70px;border:1px solid ".$border_color.";' align=left valign=top
			                                        onclick=\"".$this_link."\"        >";
			    
			    
			                              $calendar .= "<font size=2 style='float:right;'>".$currentDay."</font><br>";
			                             	$calendar .= "<div id='cal_".$page_date."'>";
									
									
									
										//------------------------sales------------------------------------------
				                             	$query_check = "select count(iit_id) as total, 		
													iit_type
										 			from t_".$key_table_prefix."_internal_inventory_transaction
													where iit_location_code = '".$_REQUEST["loc_code"]."' 
				                                             and iit_date = '".$page_date."'
													group by iit_type
													
				                                               ";	  
													  
													  
											  			  //echo $query_check."<br>";
														  
				                              $result_check = mysqli_query($dbconn,$query_check);
				                              while($line_check = mysqli_fetch_array($result_check,MYSQLI_ASSOC))
				                              {
											
											if(($line_check["iit_type"]=="CHECK_IN"))
											{
												$calendar .= "<div class='fa-stack fa-lg'  style='cursor:pointer;' >";
												$calendar .= '<i class="fa fa-square fa-stack-2x " style="color:#16A085;"  ></i><i class="fa fa-sign-in fa-stack-1x color_white" ></i>';
												$calendar .= "</div>";
												$calendar .= "<span style='margin-left:-8px;position:absolute;border-radius:50px;padding:3px;background:#CF000F;'><font size=1 color=#fff>".$line_check["total"]."</font></span>";
											
											}
											
											if(($line_check["iit_type"]=="CHECK_OUT"))
											{
												$calendar .= "<div class='fa-stack fa-lg'  style='cursor:pointer;' >";
								                    $calendar .= '<i class="fa fa-square fa-stack-2x " style="color:#16A085;"  ></i><i class="fa fa-sign-out fa-stack-1x color_white" ></i>';
								                    $calendar .= "</div>";
												$calendar .= "<span style='margin-left:-8px;position:absolute;border-radius:50px;padding:3px;background:#CF000F;'><font size=1 color=#fff>".$line_check["total"]."</font></span>";
												
											}
											
											
											if(($line_check["iit_type"]=="INTERNAL_USE"))
											{
												$calendar .= "<div class='fa-stack fa-lg'  style='cursor:pointer;' >";
												$calendar .= '<i class="fa fa-square fa-stack-2x " style="color:#F39C12;"  ></i><i class="fa fa-bolt fa-stack-1x color_white" ></i>';
												$calendar .= "</div>";
												$calendar .= "<span style='margin-left:-8px;position:absolute;border-radius:50px;padding:3px;background:#CF000F;'><font size=1 color=#fff>".$line_check["total"]."</font></span>";
											
											}
											
				                              }
										
										$calendar .="<br>";
									
									
										
			                              $calendar .= "</div>";
			    
			    
			    
			                         $calendar .= "</td>";
			    
			    
			    
			    
			    
			    
			                        $currentDay++;
			                        $dayOfWeek++;
			    
			                }
			              // Complete the row of the last week in month, if necessary
			    
			          if ($dayOfWeek != 7) {
			                    $remainingDays = 7 - $dayOfWeek;
			                    $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";
			          }
			    
			    
			          $calendar .= "</table>";
			          $calendar .= "</td></tr></table>";
			    
			          return $calendar;
			    }
			    
			    
			    
			    
			    echo "<table  width=98%  cellpadding=5 align=center >";
			            echo "<tr>";
			               
						
			                echo "<td valign=top>";
			    
			    
			    
			    
			    
			                                   echo "<table width=100% >";
			                                   echo "<tr>";
			                                   echo "<td colspan=3 >";
			                                             echo "<table bgcolor=ffffff cellpadding=5 cellspacing=1 width=100% ><tr>";
			                                             for($y=2015;$y<=date("Y");$y++)
			                                             {
			                                                        if($_SESSION["cal_year"]==$y)
			                                                        {
			                                                                 echo "<td bgcolor=#CF000F align=center >";
			                                                                 //onclick=\"mon_send_get('$this_url','?time=".date("H:m:s")."&tab=".$t."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."','div_main')\"
			                                                                 echo "<a href=\"javascript:mon_send_get('$this_url','?time=".date("H:m:s")."&tab=".$t."&loc_code=".$_REQUEST["loc_code"]."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_year=".$y."','div_display')\">";
			                                                                 echo "<font color=#FFFFFF >".$y."</font>";
			                                                                 echo "</a>";
			                                                                 echo "</td>";
			                                                        }
			                                                        else
			                                                        {
			                                                                 echo "<td bgcolor=#ECF0F1 align=center >";
			                                                                 echo "<a href=\"javascript:mon_send_get('$this_url','?time=".date("H:m:s")."&tab=".$t."&loc_code=".$_REQUEST["loc_code"]."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_year=".$y."','div_display')\">";
			                                                                 echo "<font color=#95A5A6>".$y."</font>";
			                                                                 echo "</a>";
			                                                                 echo "</td>";
			                                                        }
			    
			                                             }
			                                             echo "</tr></table>";
			    
			                                             echo "<table bgcolor=ffffff cellpadding=5 cellspacing=1 align=left width=100% ><tr>";
			                                             for($m=1;$m<=12;$m++)
			                                             {
			    
			    
			                                                       if($_SESSION["cal_month"]==$m)
			                                                       {
			                                                                echo "<td bgcolor=#CF000F align=center >";
			                                                                //onclick=\"mon_send_get('$this_url','?time=".date("H:m:s")."&tab=".$t."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."','div_main')\"
			                                                                echo "<a href=\"javascript:mon_send_get('$this_url','?time=".date("H:m:s")."&tab=".$t."&loc_code=".$_REQUEST["loc_code"]."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_month=".$m."','div_display')\">";
			                                                                echo "<font color=#FFFFFF>".$month_text2[$m]."</font>";
			                                                                echo "</a>";
			                                                                echo "</td>";
			                                                       }
			                                                       else
			                                                       {
			                                                                echo "<td bgcolor=#ECF0F1 align=center >";
			                                                                echo "<a href=\"javascript:mon_send_get('$this_url','?time=".date("H:m:s")."&tab=".$t."&loc_code=".$_REQUEST["loc_code"]."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_month=".$m."','div_display')\">";
			                                                                echo "<font color=#95A5A6>".$month_text2[$m]."</font>";
			                                                                echo "</a>";
			                                                                echo "</td>";
			                                                       }
			    
			    
			    
			                                             }
			                                             echo "</tr></table>";
			    
			    
			                                   echo "</td>";
			                                   echo "</tr>";
			                                   echo "</table>";
			    
			    
			    
			    
			    
			    
			                        //echo "<font size=1 color=#BDC3C7 >".$month_text2[$_SESSION["cal_month"]]."  ".$_SESSION["cal_year"]."</font>";
			    
			                                  echo "<br><br>";
			    
							    		    	echo "<table width=100% >";
											echo "<tr>";
												echo "<td valign=top width=50%>";
													 echo build_calendar($_SESSION["cal_month"],$_SESSION["cal_year"]);
											
													
												echo "</td>";
												
											echo "</tr>";
										echo "</table>";
							    
							    
							                    
							    
			    
			    
			    
			                echo "</td>";
			            echo "</tr>";
			        echo "</table>";
			    
			    
			    
			        //echo "<br><br>";
			    

			
			
			
			
			
			
			
			
			echo "</div>";
			
		
		echo "</td>";
		
		
		echo "<td valign=top >";
			
			
			echo "<span class='fa fa-cubes fa-lg'></span>  ";
			
			echo "Product Item at this location (Check In/Check Out)";
			echo "<br><br>";
			
			echo "<div style='border-radius:15px 15px;height:200px;overflow:auto;border:0px solid #BDC3C7;background:#ECF0F1;;'>";
			
				$query_get_item = "select 
							sum(iit_quantity) as total,
							iit_type ,
							iit_product_code
							
							from t_".$key_table_prefix."_internal_inventory_transaction
							where iit_location_code = '".$_REQUEST["loc_code"]."' 
							and iit_date <= '".$_SESSION["cal_date"]."'
							and (iit_type= 'CHECK_IN' or iit_type= 'CHECK_OUT')
							group by iit_type ,iit_product_code
							";
				$result_get_item = mysqli_query($dbconn, $query_get_item);
				while($line_get_item = mysqli_fetch_array($result_get_item,MYSQLI_ASSOC))
				{
					if($line_get_item["iit_type"]=="CHECK_IN")
					{
						$in_this_location[$line_get_item["iit_product_code"]]["QTY"] = $in_this_location[$line_get_item["iit_product_code"]]["QTY"] + 	$line_get_item["total"];
					}
					
					if($line_get_item["iit_type"]=="CHECK_OUT")
					{
						$in_this_location[$line_get_item["iit_product_code"]]["QTY"] = $in_this_location[$line_get_item["iit_product_code"]]["QTY"] - 	$line_get_item["total"];
					}

				}
				
				
				
				foreach($in_this_location as $pdt_code => $value_data)
				{
					echo "<div style='text-align:center;float:left;border-radius:10px 10px;background:#16A085;color:#fff;;padding:10px;margin:3px;width:80px;height:?px;'>";
						echo "<span class='fa fa-cube fa-2x'></span><br><br>";
						echo $pdt_code;
						echo "<br>";
						echo $pdt_data[$pdt_code]["pdt_name"];
						echo "<br><br>";
						echo "<font size=3>".$value_data["QTY"]."</font>";
					echo "</div>";
					
					
				}
			
			
			echo "</div>";
			
			echo "<br><br>";
			//=======================================================================================
			
			
			echo "<span class='fa fa-bolt fa-lg'></span>  ";
			
			echo "Quantity of Product Used at this location (Internal Usage Posting)";
			echo "<br><br>";
			
			echo "<div style='border-radius:15px 15px;height:200px;overflow:auto;border:0px solid #BDC3C7;background:#ECF0F1;;'>";
			
				$query_get_item = "select 
							sum(iit_quantity) as total,
							iit_type ,
							iit_product_code
							
							from t_".$key_table_prefix."_internal_inventory_transaction
							where iit_location_code = '".$_REQUEST["loc_code"]."' 
							and iit_date <= '".$_SESSION["cal_date"]."'
							and (iit_type= 'INTERNAL_USE' )
							group by iit_type ,iit_product_code
							";
				$result_get_item = mysqli_query($dbconn, $query_get_item);
				while($line_get_item = mysqli_fetch_array($result_get_item,MYSQLI_ASSOC))
				{
					
						$used_at_this_location[$line_get_item["iit_product_code"]]["QTY"] = $used_at_this_location[$line_get_item["iit_product_code"]]["QTY"] + 	$line_get_item["total"];
					
					
				}
				
				
				
				foreach($used_at_this_location as $pdt_code => $value_data)
				{
					echo "<div style='text-align:center;float:left;border-radius:10px 10px;background:#F39C12;color:#fff;;padding:10px;margin:3px;width:80px;height:?px;'>";
						echo "<span class='fa fa-cube fa-2x'></span><br><br>";
						echo $pdt_code;
						echo "<br>";
						echo $pdt_data[$pdt_code]["pdt_name"];
						echo "<br><br>";
						echo "<font size=3>".$value_data["QTY"]."</font>";
					echo "</div>";
					
					
				}
			
			
			echo "</div>";
			
			echo "<br><br>";
			//=======================================================================================
			
			
			
			
			echo "<span class='fa fa-list-ol fa-lg'></span>  ";
			
			echo "Showing Transaction for ".$_SESSION["cal_date"];
			echo "<br><br>";
			
			echo "<div style='height:200px;overflow:auto;border:0px solid #BDC3C7;'>";
			
			echo "<table cellspacing=1 cellpadding=5 bgcolor=#DADFE1 width=100% >";
			
			
				echo "<tr>";
					echo "<td bgcolor=#ECF0F1 >";
						echo "<b>Device ID</b>";
					echo "</td>";
					
					
					echo "<td bgcolor=#ECF0F1 >";
						echo "<b>Tran#</b>";
					echo "</td>";
					
					
					echo "<td bgcolor=#ECF0F1 >";
						echo "<b>User</b>";
					echo "</td>";
					
					echo "<td bgcolor=#ECF0F1 >";
						echo "<b>Type</b>";
					echo "</td>";
					
					
					echo "<td bgcolor=#ECF0F1 >";
						echo "<b>Product Code</b>";
					echo "</td>";
					
				
					echo "<td bgcolor=#ECF0F1 >";
						echo "<b>Quantity</b>";
					echo "</td>";
					
				
				echo "</tr>";
			
			
				$query_internal_inventory_transaction = "select * from t_".$key_table_prefix."_internal_inventory_transaction
							where iit_location_code = '".$_REQUEST["loc_code"]."' 
							and iit_date = '".$_SESSION["cal_date"]."'
							
							";
				$result_internal_inventory_transaction = mysqli_query($dbconn, $query_internal_inventory_transaction);
				while($line_intern_inventory_transaction = mysqli_fetch_array($result_internal_inventory_transaction,MYSQLI_ASSOC))
				{
					
					echo "<tr>";
						echo "<td bgcolor=#fff >";
							echo $line_intern_inventory_transaction["device_id"];
						echo "</td>";
		
						
						echo "<td bgcolor=#fff >";
							echo $line_intern_inventory_transaction["iit_device_iit_id"];
						echo "</td>";
						
						
						echo "<td bgcolor=#fff >";
							echo $line_intern_inventory_transaction["iit_user"];
						echo "</td>";
						
						echo "<td bgcolor=#fff >";
							if($line_intern_inventory_transaction["iit_type"]=="INTERNAL_USE")
							{
								echo "<font style='color:#F39C12;' >".$line_intern_inventory_transaction["iit_type"]."</font>";
							}
							
							if($line_intern_inventory_transaction["iit_type"]=="CHECK_IN")
							{
								echo "<font style='color:#16A085;' >".$line_intern_inventory_transaction["iit_type"]."</font>";
							}
							
							if($line_intern_inventory_transaction["iit_type"]=="CHECK_OUT")
							{
								echo "<font style='color:#16A085;' >".$line_intern_inventory_transaction["iit_type"]."</font>";
							}
							
						echo "</td>";
						
						
						echo "<td bgcolor=#fff >";
							echo $line_intern_inventory_transaction["iit_product_code"];
						echo "</td>";
						
					
						echo "<td bgcolor=#fff >";
							echo $line_intern_inventory_transaction["iit_quantity"];
						echo "</td>";
						
					
					echo "</tr>";
					
					
					
				}
		
		
			echo "</table>";
			
			echo "</div>";
		
		
			
		echo "</td>";



echo "</table>";

echo "</div>";
			

?>
<?php include "../../includes/end_ajax.php";?>