<?php




$this_url="mod/picking_list/index.php";
$this_url_edit="mod/picking_list/edit.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="#1ABC9C";
                        }
                        else {
                         	$background_color="#ECF0F1";
                        }
    
    
    					$this_link ="mon_send_get('mod/picking_list/index.php','?picking_mode=".$_SESSION["picking_mode"]."&cal_date=".$page_date."','div_main')";
    
    
    
                        $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(ivh_id) as total	,
										sum(if(ifnull(ivh_delivery_status,'')='DELIVERED',0,1)) as total_pending
							 			from t_".$key_table_prefix."_invoice_header
	                                               where ivh_date='".$page_date."'

	                                               ";	  
								  			
	                              $result_check = mysqli_query($dbconn,$query_check);
						
	                              if($line_check = mysqli_fetch_array($result_check,MYSQLI_ASSOC))
	                              {
								if($line_check["total"]>0)
								{
									$calendar .= "<div class='fa-stack fa-lg'  style='cursor:pointer;' >";
					                    $calendar .= '<i class="fa fa-square fa-stack-2x " style="color:#3498DB;"  ></i><i class="fa fa-truck fa-stack-1x color_white" ></i>';
					                    $calendar .= "</div>";
									if($line_check["total_pending"]>0)
									{
										$calendar .= "<span style='margin-left:-8px;position:absolute;border-radius:50px;padding:3px;background:#CF000F;'><font size=1 color=#fff>".$line_check["total_pending"]."</font></span>";
									}
									
									
								}
	                              }
							
							$calendar .="<br>";
							//------------------------sales return------------------------------------------
	                             	$query_check = "select count(rth_id) as total ,		
										if(ifnull(rth_delivery_status,'') = '',count(rth_id), 0) as total_pending
							 			from t_".$key_table_prefix."_return_header
	                                               where rth_date='".$page_date."'
										  
	                                               ";	  
								  			  
	                              $result_check = mysqli_query($dbconn,$query_check);
	                              if($line_check = mysqli_fetch_array($result_check,MYSQLI_ASSOC))
	                              {
								if($line_check["total"]>0)
								{
									$calendar .= "<div class='fa-stack fa-lg'  style='cursor:pointer; ' >";
					                    $calendar .= '<i class="fa fa-square fa-stack-2x " style="color:#E67E22;"  ></i><i class="fa fa-truck fa-stack-1x color_white" ></i>';
					                    $calendar .= "</div>";
									
									if($line_check["total_pending"]>0)
									{
										$calendar .= "<span style='margin-left:-8px;position:absolute;border-radius:50px;padding:3px;background:#CF000F;'><font size=1 color=#fff>".$line_check["total_pending"]."</font></span>";
									}
									
									
								}
	                              }
							
							
                              $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=2010;$y<=2030;$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."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_year=".$y."','div_main')\">";
                                                                 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."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_year=".$y."','div_main')\">";
                                                                 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."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_month=".$m."','div_main')\">";
                                                                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."".$tab_extra_url."&".$tab_key_id."=".$_REQUEST[$tab_key_id]."&cal_month=".$m."','div_main')\">";
                                                                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 "<td valign=top >";
					
					
					
						//----------------------------------------------------------------------------------------------
						
						echo  "<div class='fa-stack fa-lg'  style='cursor:pointer;float:left;' >";
						echo '<i class="fa fa-square fa-stack-2x " style="color:#3498DB;"  ></i><i class="fa fa-truck fa-stack-1x color_white" ></i>';
						echo "</div>";
						
						echo "<font size=3 style='line-height:28px;'> Sales Transaction</font>";
						
						
							echo "<table cellspacing=0 cellpadding=8 width=100% >";
						
							echo "<tr>";
								echo "<td valign=top style='border-bottom:1px solid #000000;'>";
									echo "<b>Doc No.</b>";
								echo "</td>";
								
								
								echo "<td valign=top style='border-bottom:1px solid #000000;'>";
									echo "<b>Customer</b>";
								echo "</td>";
								
								
								echo "<td valign=top align=right style='border-bottom:1px solid #000000;'>";
									echo "<b>Total Amount</b>";
								echo "</td>";
								
								
								echo "<td valign=top style='border-bottom:1px solid #000000;'>";
									echo "";
								echo "</td>";
							echo "</tr>";
							
							
							
							$query_sales="select * from t_".$key_table_prefix."_invoice_header 
										where ivh_date = '".$_SESSION["cal_date"]."' 
										
										";
										//and ifnull(ivh_delivery_status,'') = '' 
							$result_sales = mysqli_query($dbconn,$query_sales);
							while($line_sales = mysqli_fetch_array($result_sales,MYSQLI_ASSOC))
							{
								
								
								echo "<tr>";
									echo "<td valign=top >";
										echo $line_sales["ivh_doc_no"];
									echo "</td>";
									
									
									echo "<td valign=top >";
										
										echo $line_sales["ivh_customer_name"]."<br>";
										echo "<font color=#BDC3C7 ><i>".$line_sales["ivh_customer_code"]."</i></font>";
									echo "</td>";
									
									
									echo "<td valign=top align=right >";
										echo $line_sales["ivh_total_amount_rounded"];
										
										
										
										//count picking status:
										if($line_sales["ivh_picking_status"]=="PICKED")
										{
											echo "<br> <font  style='color:#049372;' >".$line_sales["ivh_picking_status"]."</font>";	
											
											//checking:
											$picking_match=true;
											$query_sales_item="select * from t_".$key_table_prefix."_invoice_item
														where ivi_header_id = '".$line_sales["ivh_id"]."' 
														
														";
											$result_sales_item = mysqli_query($dbconn,$query_sales_item);
											while($line_sales_item = mysqli_fetch_array($result_sales_item,MYSQLI_ASSOC))
											{
												
												if($line_sales_item["ivi_picking_quantity"]==$line_sales_item["ivi_before_picking_quantity"])
												{
													
												}
												else {
													
													$picking_match=false;
												}
												
											}
											
											if($picking_match)
											{
												echo "<br><span class='fa fa-check fa-lg' style='color:#049372;' ></span> <font  style='color:#049372;' >Qty Matched</font>";	
											}
											else {
												
												echo "<br><span class='fa fa-check fa-lg' style='color:#cf000f;' ></span> <font  style='color:#cf000f;' >Qty not matched</font>";	
											}
											
											
											
										}
										
										
										
										
									echo "</td>";
									
									
									echo "<td valign=top >";
										
										
										echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"mon_send_get('mod/transaction/display.php','?ivh_id=".$line_sales["ivh_id"]."','div_display');\" >";
											echo "<i class='fa fa-square fa-stack-2x' style='color:#F39C12;' ></i>";
											echo "<i class='fa fa-eye fa-stack-1x'  style='color:#ffffff;'></i>";
										echo "</span>";
										
										echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"print_page('print/picking_list/index.php?ivh_id=".$line_sales["ivh_id"]."')\" >";
											echo "<i class='fa fa-square fa-stack-2x' style='color:#3498DB;' ></i>";
											echo "<i class='fa fa-print fa-stack-1x'  style='color:#ffffff;'></i>";
										echo "</span>";
										
										
										echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"mon_send_get('mod/picking_list/generate_po.php','?ivh_id=".$line_sales["ivh_id"]."','div_display');\" >";
											echo "<i class='fa fa-square fa-stack-2x' style='color:#9B59B6;' ></i>";
											echo "<i class='fa fa-shopping-cart fa-stack-1x'  style='color:#ffffff;'></i>";
										echo "</span>";
										
										
										
										if($line_sales["ivh_delivery_status"]=="")
										{
											echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"if(confirm('Delivery Completed?')){mon_send_get('".$this_url."','?delivery=YES&ivh_id=".$line_sales["ivh_id"]."','div_main')}\" >";
												echo "<i class='fa fa-square fa-stack-2x' style='color:#1ABC9C;' ></i>";
												echo "<i class='fa fa-truck fa-stack-1x'  style='color:#ffffff;'></i>";
											echo "</span>";
										}
										
										
										
										
										
										$query_item="select count(ivi_id) as total 
										 			from t_".$key_table_prefix."_invoice_item
													where ivi_header_id = '".$line_sales["ivh_id"]."' 
													and not ifnull(ivi_inventory_posting,'') = 'POSTED'
													";
										$result_item = mysqli_query($dbconn,$query_item);
										if($line_item = mysqli_fetch_array($result_item,MYSQLI_ASSOC))
										{
											
												
											
											if($line_item["total"]>0)
											{
												
												echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"mon_send_get('".$this_url_edit."','?ivh_id=".$line_sales["ivh_id"]."','div_display')\" >";
													echo "<i class='fa fa-square fa-stack-2x' style='color:#1ABC9C;' ></i>";
													echo "<i class='fa fa-pencil fa-stack-1x'  style='color:#ffffff;'></i>";
												echo "</span>";
												
												
												
												
												echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"if(confirm('Post to Inventory?')){mon_send_get('".$this_url."','?inventory_posting=YES&ivh_id=".$line_sales["ivh_id"]."','div_main')}\" >";
													echo "<i class='fa fa-square fa-stack-2x' style='color:#1ABC9C;' ></i>";
													echo "<i class='fa fa-cubes fa-stack-1x'  style='color:#ffffff;'></i>";
												echo "</span>";
												
												echo "<span style='margin-left:-8px;position:absolute;border-radius:50px;padding:3px;background:#CF000F;'><font size=1 color=#fff>".$line_item["total"]."</font></span>";
													
											}
											
											
											
										}
										
										
										
										
									echo "</td>";
								echo "</tr>";
								
							}
							
							echo "</table>";
							
						
						
					
					//----------------------------------------------------------------------------------------------
					
					
						echo "<br><br>";
					
						
						echo  "<div class='fa-stack fa-lg'  style='cursor:pointer;float:left;' >";
						echo '<i class="fa fa-square fa-stack-2x " style="color:#E67E22;"  ></i><i class="fa fa-truck fa-stack-1x color_white" ></i>';
						echo "</div>";
						
						echo "<font size=3 style='line-height:28px;'> Return Transaction</font>";
						
						
							echo "<table cellspacing=0 cellpadding=8 width=100% >";
						
							echo "<tr>";
								echo "<td valign=top style='border-bottom:1px solid #000000;'>";
									echo "<b>Doc No.</b>";
								echo "</td>";
								
								
								echo "<td valign=top style='border-bottom:1px solid #000000;'>";
									echo "<b>Customer</b>";
								echo "</td>";
								
								
								echo "<td valign=top align=right style='border-bottom:1px solid #000000;'>";
									echo "<b>Total Amount</b>";
								echo "</td>";
								
								
								echo "<td valign=top style='border-bottom:1px solid #000000;'>";
									echo "";
								echo "</td>";
							echo "</tr>";
							
							
							
							$query_sales="select * from t_".$key_table_prefix."_return_header 
										where rth_date = '".$_SESSION["cal_date"]."' 
										";
										//and ifnull(rth_delivery_status,'') = '' 
							$result_sales = mysqli_query($dbconn,$query_sales);
							while($line_sales = mysqli_fetch_array($result_sales,MYSQLI_ASSOC))
							{
								
								
								echo "<tr>";
									echo "<td valign=top >";
										echo $line_sales["rth_doc_no"];
									echo "</td>";
									
									
									echo "<td valign=top >";
										
										echo $line_sales["rth_customer_name"]."<br>";
										echo "<font color=#BDC3C7 ><i>".$line_sales["rth_customer_code"]."</i></font>";
									echo "</td>";
									
									
									echo "<td valign=top align=right >";
										echo $line_sales["rth_total_amount_rounded"];
									echo "</td>";
									
									
									echo "<td valign=top >";
										
										
										echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"mon_send_get('mod/transaction_return/display.php','?rth_id=".$line_sales["rth_id"]."','div_display');\" >";
											echo "<i class='fa fa-square fa-stack-2x' style='color:#F39C12;' ></i>";
											echo "<i class='fa fa-eye fa-stack-1x'  style='color:#ffffff;'></i>";
										echo "</span>";
										
										echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"print_page('print/collection_notes/index.php?rth_id=".$line_sales["rth_id"]."')\" >";
											echo "<i class='fa fa-square fa-stack-2x' style='color:#3498DB;' ></i>";
											echo "<i class='fa fa-print fa-stack-1x'  style='color:#ffffff;'></i>";
										echo "</span>";
										
										
										
									
										
										
										
										if($line_sales["rth_delivery_status"]=="")
										{
											
											
											
											echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"if(confirm('Delivery Completed?')){mon_send_get('".$this_url."','?delivery=YES&rth_id=".$line_sales["rth_id"]."','div_main')}\" >";
												echo "<i class='fa fa-square fa-stack-2x' style='color:#1ABC9C;' ></i>";
												echo "<i class='fa fa-truck fa-stack-1x'  style='color:#ffffff;'></i>";
											echo "</span>";	
										}
										
										
										
										
										
										$query_item="select count(rti_id) as total 
										 			from t_".$key_table_prefix."_return_item
													where rti_header_id = '".$line_sales["rth_id"]."' 
													and not ifnull(rti_inventory_posting,'') = 'POSTED'
													";
										$result_item = mysqli_query($dbconn,$query_item);
										if($line_item = mysqli_fetch_array($result_item,MYSQLI_ASSOC))
										{
												
											
											if($line_item["total"]>0)
											{
												
												
												
												
												
												echo "<span class='fa-stack fa-lg' style='cursor:pointer;' onclick=\"if(confirm('Post to Inventory?')){mon_send_get('".$this_url."','?inventory_posting=YES&rth_id=".$line_sales["rth_id"]."','div_main')}\" >";
													echo "<i class='fa fa-square fa-stack-2x' style='color:#1ABC9C;' ></i>";
													echo "<i class='fa fa-cubes fa-stack-1x'  style='color:#ffffff;'></i>";
												echo "</span>";
												
												echo "<span style='margin-left:-8px;position:absolute;border-radius:50px;padding:3px;background:#CF000F;'><font size=1 color=#fff>".$line_item["total"]."</font></span>";
													
											}
											
											
											
										}
										
										
										
										
									echo "</td>";
								echo "</tr>";
								
							}
							
							echo "</table>";
							
						
						
						
						
						
						
					echo "</td>";
					
				echo "</tr>";
			echo "</table>";
    
    
                    
    
    
    
    
                echo "</td>";
            echo "</tr>";
        echo "</table>";
    
    
    
        echo "<br><br>";
    



?>
