<?php
$PageSecurity = 11;
include('includes/SQL_CommonFunctions.inc');
?>
<script language="javascript" type="text/javascript">

function get_itemsubgroup(str)
{
	if(str=="")
  {
  document.getElementById("sub_id").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("sub_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","item_subcategory.php?main="+str,true);
xmlhttp.send();
}

function chekuser()
{
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
	xmlhttp.open("GET","getmonthly.php?sub="+str,true);
xmlhttp.send();
}
}
function get_item(str)
{
if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?sub="+str,true);
xmlhttp.send();
}
<?php 
    	            $month1=array(
    "1" => "1","2" => "2","3" => "3","4" => "4","5" => "5","6" => "6","7" => "7","8" => "8","9" => "9","10" => "10","11" => "11","12" => "12",
);
    	            ?> 
</script>
<h2 align="center"><strong>Monthly Supply Chart</strong></h2>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top">
    	<table width="100%" border="0" cellspacing="1" cellpadding="0" style="border:1px solid #ccc; background-color:#FFF">
    	    <tr>
    	      <td>
    	      	<tr><td><form  action="" method="post"><table align="center"><tr><td align="center">
    	      	From:	<select name="month" width="94;">
    	      		<option value="000">---Select-----</option>
    	      		<option value="01" >Jan</option>	<option value="02">Feb</option><option value="03">Mar</option><option value="04">Apr</option>
    	      		<option value="05">May</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Aug</option>
    	      		<option value="09">Sep</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dec</option>	
    	      			
    	      		</select>&nbsp;To: <select name="month2" width="94;">
    	      		<option value="000">---Select-----</option>
    	      		<option value="01">Jan</option>	<option value="02">Feb</option><option value="03">Mar</option><option value="04">Apr</option>
    	      		<option value="05">May</option><option value="06">Jun</option><option value="07">Jul</option><option value="08">Aug</option>
    	      		<option value="09">Sep</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dec</option>	
    	      			
    	      		</select></td><td><input type="submit" name="Search" value="Search"></td></tr></table></form></td></tr>
    	      		<tr><td>
    	     	      	<table width="100%" border="0" cellspacing="1" cellpadding="0" class="lvt" bgcolor="#CCCCCC" style="border:1px solid #FFF;">
    	        <tr>
    	          <td width="15%" height="30" align="center" style="border-right:1px solid #FFF; text-align:center;" valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="3">
    	       <tr>
    	              <td height="40"><strong>Party Name</strong></td>
  	              </tr>
  	              <?php
  	                  
    	              $kk=0;
					  
					  $cliintsql="SELECT DISTINCT client_id FROM invoice where CompanyId='".$_SESSION['ACGCompanyId']."' order by client_id desc;";
				
					  $result=DB_query($cliintsql,$db);
					  while($myrow12=DB_fetch_array($result))
					  {
					  $sql5="select c_name from clientmaster where id='".$myrow12['client_id']."' ";
					  $result2=DB_query($sql5,$db);
					  while($myrow2=DB_fetch_array($result2))
					  {?>  

					<tr bgcolor="#FFFFFF">
    	              <td> <?php echo $myrow2['c_name']; ?></td>
  	          </tr><?php $kk++; } } ?>
					
    	            
                
  	            </table></td>
  	            <?php
  	            $num='';
  	            if(!isset($_POST['month2']))
				{
					$month22=$_REQUEST['month'];
				}
				else {
					if($_REQUEST['month']>$_REQUEST['month2'])
					{
				    $month22=$_REQUEST['month'];		
					}
					else {
				  $month22=$_REQUEST['month2'];
				  }
				}
				if(!isset($_POST['month']) && !isset($_POST['month2']))
				{
				 $end1 = date("Y-m-d",strtotime("+0 months"));
				$monthdate1=explode('-',$end1);
				 $num=(int)$monthdate1[1];
				}
  	            for($i=(int)$_REQUEST['month'];$i<=(int)$month22;$i++)
  	            {
  	             $monthname = array(
    "1" => "Jan","2" => "Feb","3" => "Mar","4" => "Apr","5" => "May","6" => "June","7" => "July","8" => "Aug","7" => "Sep","10" => "Oct","11" => "Nov","12" => "Dec",
);
  	             ?>
    	          <td width="11%" align="center" style="border-right:1px solid #FFF; text-align:center;" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    	            <tr>
    	              <td height="40"><table width="100%" border="0" cellspacing="1" cellpadding="0">
    	                <tr>
    	                  <td colspan="2" align="center"><strong><?php if(!isset($_POST['month']) && !isset($_POST['month2'])) {
    	                  	 echo $monthname[$num]; } else {  echo $monthname[$i];  } ?></strong></td>
    	                  </tr>
    	                  <tr bgcolor="#FFFFFF">
    	                  <td width="10%" height="20" align="center"><strong>Qty</strong></td>
    	                  <td width="30%" align="center"><strong>Amt.</strong></td>
  	                  </tr>
  	                  </table></td>
  	              </tr>
    	                 
    	                
    	            <tr bgcolor="#FFFFFF">
    	              <td valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="cccccc">
    	                <?php
    	                  if(isset($_POST['Search']))
						  {						  
						  $k=0;
						 $ss="SELECT DISTINCT client_id FROM invoice  where CompanyId='".$_SESSION['ACGCompanyId']."' order by client_id desc;";
						  $result11=DB_query($ss,$db);
						  while($clien=DB_fetch_array($result11))
						  {					  
						 $cliintsql="select invoice.*,invoice_details.*,sum(Quantity),sum(Amount) from invoice,invoice_details where MONTH(invoice.invoiceDate)='".$month1[$i]."' 
						 and invoice.invoice_id=invoice_details.invoiceid and invoice.client_id='".$clien['client_id']."'
						 order by  client_id desc";
					     $result=DB_query($cliintsql,$db);
						 
					      while($myrow3=DB_fetch_array($result))
					     {
					     	
					     if($kk!=$k)
							{
    	                   ?>
    	                <tr bgcolor="#FFFFFF">
    	                  <td align="center" width="10%"><?php if(empty($myrow3['sum(Quantity)'])) { ?> 0.00 <?php } else { echo $myrow3['sum(Quantity)']; } ?></td>
    	                  <td  width="20%"  align="center"><?php if(empty($myrow3['sum(Amount)'])) { ?> 0.00 <?php } else { echo $myrow3['sum(Amount)']; }?></td>
  	                  </tr><?php $k++; } }  }}else { 
  	                  	 $k=0;
						 $end = date("Y-m-d",strtotime("+0 months"));
						 $monthdate=explode('-',$end);
					     $cliintsql="SELECT DISTINCT client_id  FROM invoice where MONTH(invoiceDate)='".$monthdate[1]."' order by  client_id";
					     $result=DB_query($cliintsql,$db);
						 while($sql6=DB_fetch_array($result))
						 {						 								
						 $sql5="select invoice.*,invoice_details.*,sum(Quantity),sum(Amount) from invoice,invoice_details where MONTH(invoice.invoiceDate)='".$month1[$i]."' 
						 and invoice.invoice_id=invoice_details.invoiceid and invoiceid='".$sql6['invoice_id']."'  order by  client_id desc ";
					      $result3=DB_query($sql5,$db);
					      while($myrow3=DB_fetch_array($result3))
					     {
					     	
					     	if($kk!=$k)
							{
  	                  	
  	                  	?>
  	                  	<tr bgcolor="#FFFFFF">
    	                  <td align="center" width="10%"><?php if($myrow3['sum(Quantity)']==null) { ?> 0.00 <?php } else { echo $myrow3['sum(Quantity)']; } ?></td>
    	                  <td  width="20%"  align="center"><?php if(!$myrow3['sum(Amount)']) { ?> 0.00 <?php } else { echo $myrow3['sum(Amount)']; }?></td>
  	                  </tr>
  	                  	<?php $k++; }} } }?>
  	                  
    	               
  	                  </table></td>
  	              </tr>
  	            </table></td><?php } ?>
    	          
   	            </tr>
  	        </table></td>
   	      </tr>
    </table></td>
  </tr>
  
</table>