<? ob_start();
session_start();
 include("../../include/dbconnect.php");



// Get all _POST VALUES HERE..

foreach($_POST as $q=>$r)
{
	$_POST[$q] = trim($r);
}

$myCompany = $_POST['Company'];

foreach($_POST as $h=>$i)
{
	$_POST[$h] = trim($i);
}
$myDate = $_POST['Date'];

$aresult = mysqli_query($conn,"select distinct account_year,name from company") or die(mysqli_error());
$arow = mysqli_fetch_row($aresult);
$account_year = $arow[0];
?>
<title>Trading Invoice Printing</title>
<body background="../wilson/prgent/reports/blater01.gif" topmargin="0">  
<center> 
<table cellpadding=0 cellspacing=4 width=590>
  <tr> 
    <td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font face="Verdana, Arial, Helvetica, sans-serif"><b>Trading Invoice   
      Printing</b></font></td>
  </tr>
  <tr valign="top"> 
  <td colspan=2> <font >&nbsp;</font> </td>
  </tr>
</table>
<table border=0 cellpadding=3 cellspacing=4 width="590">
  <?

// Pull all the data from Area master & populate it

$result= mysqli_query($conn," select distinct compcode,name from company  order by name")or die( mysqli_error() );


?>
  <form name='myForm01' method='POST' action='<?=$_SERVER['PHP_SELF']?>'>
    <tr > 
      <td width="207" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Company 
        &nbsp;</b></font></td>
      <td> <select name='Company' onChange="javascript:submit();">
          <?php 
	 echo "<option selected value=\" 0\"> Select Company";	  
      while ( $row1= mysqli_fetch_row($result))
      {
	  	if(isset($myCompany) && preg_match("/" . preg_quote($myCompany", '/') . "/", $row1[0]))
		{
			echo "<option selected value=\"$row1[0]\">$row1[0]";
	  	}
	  	else
	  	{
			echo "<option value=\"$row1[0]\">$row1[0]";
	  	}
	}
?>
        </select> </td>
    </tr>
    <?
$result2= mysqli_query($conn," select distinct date from ledger where compcode = '$myCompany'  and account_year ='$account_year'   order by date desc")or die( mysqli_error() );
?>
    <tr > 
      <td width="207" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Date 
        &nbsp;</b></font></td>
      <td> <select name='Date' onChange="javascript:submit();">
          <?php 
	 echo "<option selected value=\" 0\"> Select Date";	  
      while ( $row2= mysqli_fetch_row($result2))
      {
	  	$temp = british($row2[0]);
	  	if(isset($myDate) && preg_match("/" . preg_quote($myDate", '/') . "/", $row2[0]))
		{
			echo "<option selected value=\"$row2[0]\">$temp";
	  	}
	  	else
	  	{
			echo "<option value=\"$row2[0]\">$temp";
	  	}
	}
?>
        </select> </td>
    </tr>
  </form>
  <script language="JavaScript" src="../wilson/../../include/CalendarPopup.js"></script>
  <script language="JavaScript">
var cal = new CalendarPopup();
</script>
  <form  method="POST" name="inv_slct" action="invoice.php"  target="_blank">
          <input type="hidden" name="compcode" value="<?echo($myCompany);?>">  
          <input type="hidden" name="account_year" value="<?echo($account_year);?>">  		  
		  
    <title>Print Trading Invoice & Statement</title>
  

    <tr > 
      <td width="207" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Trading Invoice 
        Nos &nbsp;</b></font></td>
      <td width="359"> 
        <?

// Pull all Customers from Customer  based on Selected Area id and populate it.


$sBuyQuery = mysqli_query($conn,"SELECT distinct pur_invno,buy.name FROM ledger,buy WHERE (date ='$myDate') and ledger.bcode = buy.bcode and buyertype != 'Customer' and compcode = '$myCompany'  order by compcode,invno ") or die(mysqli_error());


// This form contain a hidden field AreaID which can be later used in next  page..
?>


          <select name=invnos[] multiple size="5"  >
            <?
while($row1 = mysqli_fetch_row($sBuyQuery))
{
	$temp = $row1[0].'&nbsp;&nbsp;'.$row1[1];
	$ino= $row1[0];
	echo "<option value=\"$ino\">$temp";
}

?>
          </select>
        </td>
    </tr>

  <tr> 
    <td align="right" width="354" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Print Statement of Account </b></font></td>

  <tr> 
    <td width="354" ></td>

    <td width="437" > <input type="radio" name="upd" value = "No" checked> <font class="sbd"><b>Not to Print </b></font>&nbsp;</td>
  </tr>
  <tr> 
    <td width="354" ></td>

    <td width="437" > <input type="radio" name="upd" value = "Yes"> <font class="sbd"><b>Print</b></font>&nbsp;</td>
  </tr>
  </table>


<table border=0 cellpadding=3 cellspacing=4 width="590">



            <tr class="small_site_font_black">
              <td width="25%" align="center" valign="top"><span id="lbl_from_date">From Date </span></td>
              <td width="26%">
                        <?
						 // echo $from_date;
						  if(empty($from_date))
						  {
						   $from_date=strftime ("%d/%m/%Y", mktime (0,0,0,date("m"),date("d"),date("Y"))); 
						  }
						?>
						  <INPUT NAME="from_date" TYPE="text" class="text_box_button" VALUE="<?=$from_date?>" SIZE="15"   >
                          <A HREF="#" onClick="cal.select(document.inv_slct.from_date,'anchor1','dd/MM/yyyy'); return false;"NAME="anchor1" ID="anchor1"><img  src="../..//images/cal.gif" border="0"></A> 
			  </td>
              <td width="22%" valign="top"><span id="lbl_to_date">To Date </span></td>
              <td width="27%">
                         <? 
						//    echo $to_date;
						   if(empty($to_date))
						    {
						      $to_date =strftime ("%d/%m/%Y", mktime (0,0,0,date("m"),date("d")+6,date("Y"))); 
						    }
						 ?> 
						  <INPUT NAME="to_date" TYPE="text" class="text_box_button" VALUE="<?=$to_date;?>" SIZE="15" onBlur="return diff(document.inv_slct.from_date.value,this.value);" >
                          <A HREF="#" onClick="cal.select(document.inv_slct.to_date,'anchor2','dd/MM/yyyy'); return false;"NAME="anchor2" ID="anchor2"><img src="../../images/cal.gif" border="0"></A> 
			  </td>
              </tr></table>





<table cellpading=0 cellspacing=10 width= 591>
<tr>
<td width="117" align="center">
 <blockquote>  <input type =submit name=submit value = "Submit"></blockquote>
</table>



                                                                             
</body>
</form>
