<?php extract($_POST);
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Sales Order');
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['Cancel']!='')
{
	unset($_SESSION['branch']);
	unset($_SESSION['orderDate']);
	unset($_SESSION['orderNo']);
	unset($_SESSION['orderType']);
	unset($_SESSION['voucherPrefix']);
	unset($_SESSION['voucherDigit']);
	unset($_SESSION['client']);
	unset($_SESSION['Transporter']);
	unset($_SESSION['salesMan']);
	unset($_SESSION['creditDays']);
	unset($_SESSION['expiry']);
	unset($_SESSION['voucherNo']);
	unset($_SESSION['FinalFGArray']);
	unset($_SESSION['lastPayDate']);
	unset($_SESSION['expiryDate']);
}
if($_REQUEST['item_popup']!='')
{
	$_SESSION['branch']=$_REQUEST['branch'];
	$_SESSION['orderDate']=$_REQUEST['orderDate'];
	$_SESSION['orderNo']=$_REQUEST['orderNo'];
	$_SESSION['voucherPrefix']=$_REQUEST['voucherPrefix'];
	$_SESSION['voucherDigit']=$_REQUEST['voucherDigit'];
	$_SESSION['orderType']=$_REQUEST['orderType'];
	$_SESSION['client']=$_REQUEST['client'];
	$_SESSION['Transporter']=$_REQUEST['Transporter'];
	$_SESSION['salesMan']=$_REQUEST['salesMan'];
	$_SESSION['creditDays']=$_REQUEST['creditDays'];
	$_SESSION['expiry']=$_REQUEST['expiry'];
	$_SESSION['lastPayDate']=$_REQUEST['lastPayDate'];
	$_SESSION['expiryDate']=$_REQUEST['expiryDate'];
}
if($_REQUEST['Save']!='')
{
	$sql1="Insert into salesorder set
					branch='".$_REQUEST['branch']."', 
					orderNo='".$_REQUEST['orderNo']."',
					voucherPrefix='".$_REQUEST['voucherPrefix']."',  
					voucherDigit='".$_REQUEST['voucherDigit']."',
					voucherNo ='".$_REQUEST['voucherPrefix']."-".$_REQUEST['voucherDigit']."', 
					client='".$_REQUEST['client']."',  
					salesMan='".$_REQUEST['salesMan']."',  
					orderDate='".FormatDateForSql($_REQUEST['orderDate'])."',  
					orderType='".$_REQUEST['orderType']."',  
					Transporter='".$_REQUEST['Transporter']."',  
					creditDays='".$_REQUEST['creditDays']."',  
					expiry='".$_REQUEST['expiry']."',  
					paymentTerms='".$_REQUEST['paymentTerms']."',  
					deliveryTerms='".$_REQUEST['deliveryTerms']."',  
					otherTerm1='".$_REQUEST['otherTerm1']."',  
					otherTerm2='".$_REQUEST['otherTerm2']."',  
					narration='".$_REQUEST['narration']."',  
					advance='".$_REQUEST['advance']."',  
					totalQuantity='".$_REQUEST['totalQuantity']."',  
					basicAmount='".$_REQUEST['basicAmount']."',  
					excisePerc='".$_REQUEST['excisePerc']."',  
					exciseValue='".$_REQUEST['exciseValue']."',  
					C_CessPerc='".$_REQUEST['C_CessPerc']."',  
					C_CessValue='".$_REQUEST['C_CessValue']."',  
					H_CessPerc='".$_REQUEST['H_CessPerc']."',  
					H_CessValue='".$_REQUEST['H_CessValue']."',  
					taxableAmount='".$_REQUEST['taxableAmount']."',  
					salesTax='".$_REQUEST['salesTax']."',  
					taxRate='".$_REQUEST['taxRate']."',  
					totalTaxAmount='".$_REQUEST['totalTaxAmount']."',  
					freight='".$_REQUEST['freight']."',  
					surchargePerc='".$_REQUEST['surchargePerc']."',  
					surchargeValue='".$_REQUEST['surchargeValue']."',  
					roundOff='".$_REQUEST['roundOff']."',  
					grandTotal='".$_REQUEST['grandTotal']."',  
					createdBy='".$_SESSION['UserID']."',  
					createdDate='".FormatDateForSql(date('d/m/Y'))."' ";
	$result1=DB_query($sql1,$db);
	//echo "<pre>";
	//print_r($sql1);exit;

	$masterId=DB_Last_Insert_ID($db,'salesorder','id');
	if(isset($masterId))
	{
		for($K=0;$K<$_REQUEST['countItems'];$K++)
		{
			$sql2="Insert into salesorder_details set 
							masterId='".$masterId."',  
							ItemSubGroup='".$_REQUEST['ItemSubGroup'][$K]."',    
							ItemCode='".$_REQUEST['ItemCode'][$K]."',   
							ItemDesc='".$_REQUEST['ItemDesc'][$K]."',    
							BillingDesc='".$_REQUEST['BillingDesc'][$K]."',    
							Quantity='".$_REQUEST['Quantity'][$K]."',      
							Rate='".$_REQUEST['Rate'][$K]."',  
							unit='".$_REQUEST['unit'][$K]."',    
 							Amount='".$_REQUEST['Amount'][$K]."' ";
			$result2=DB_query($sql2,$db);
			//echo "<pre>";
			//print_r($sql2);
		}
	}
echo "<script>location.href='index.php?route=SalesOrderList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
prnMsg( _('Sales Order inserted successfully'),'success');

	unset($_SESSION['branch']);
	unset($_SESSION['orderDate']);
	unset($_SESSION['orderNo']);
	unset($_SESSION['orderType']);
	unset($_SESSION['client']);
	unset($_SESSION['Transporter']);
	unset($_SESSION['salesMan']);
	unset($_SESSION['creditDays']);
	unset($_SESSION['expiry']);
	unset($_SESSION['FinalFGArray']);
	unset($_SESSION['voucherPrefix']);
	unset($_SESSION['voucherDigit']);
	unset($_SESSION['lastPayDate']);
	unset($_SESSION['expiryDate']);
}
?>
<script language="javascript" type="text/javascript">
function item_window()
{
	window.open("SelectSalesItems.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
	
}
function calculate_totAmount(k)
{
	var qty=document.getElementById("Quantity_"+k).value;
	var Rate=document.getElementById("Rate_"+k).value;
	var rateperthousand=Rate/1000;
	var total=parseFloat(qty)*parseFloat(rateperthousand);
	document.getElementById("Amount_"+k).value=total.toFixed(2);
}
function calculateTotalQty()
{
	var count=document.getElementById("countItems").value;
	var totqty=0;
	for(var str=0;str<count;str++)
	{
		var qty=document.getElementById("Quantity_"+str).value;
		totqty=parseInt(totqty)+parseInt(qty);
	}
	document.getElementById("totalQuantity").value=totqty;
}
function calculateBasicAmt()
{
	var count1=document.getElementById("countItems").value;
	var totamount=0;
	
	for(var st=0;st<count1;st++)
	{
		var amount=document.getElementById("Amount_"+st).value;
		totamount=parseInt(totamount)+parseInt(amount);
	}
	document.getElementById("basicAmount").value=totamount.toFixed(2);
}
function getOrderNo(str)
{
if (str.length==0)
  {
  document.getElementById("orderid").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("orderid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","SalesOrderNo.php?q="+str,true);
xmlhttp.send();
}
function getCreditDays(str)
{
	if (str.length==0)
  {
  document.getElementById("creditId").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("creditId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ClientCreditDays.php?q="+str,true);
xmlhttp.send();
}
function calculateExcise()
{
	var ordervalue=document.getElementById("basicAmount").value;
	var Epercent=document.getElementById("excisePerc").value;
	var value=ordervalue*(Epercent/100);
	document.getElementById("exciseValue").value=value.toFixed(2);
}

function calculateCCess()
{
	var excise=document.getElementById("exciseValue").value;
	var Cpercent=document.getElementById("C_CessPerc").value;
	var value=excise*(Cpercent/100);
	document.getElementById("C_CessValue").value=value.toFixed(2);
}

function calculateHCess()
{
	var excise=document.getElementById("exciseValue").value;
	var Hpercent=document.getElementById("H_CessPerc").value;
	var value=excise*(Hpercent/100);
	document.getElementById("H_CessValue").value=value.toFixed(2);
}
function calculateTaxable()
{
	var basic=document.getElementById("basicAmount").value;
	var excise=document.getElementById("exciseValue").value;
	var CCess=document.getElementById("C_CessValue").value;
	var HCess=document.getElementById("H_CessValue").value;
	var tottaxable=parseFloat(basic)+parseFloat(excise)+parseFloat(CCess)+parseFloat(HCess);
	document.getElementById("taxableAmount").value=tottaxable.toFixed(2);
}
function GetTaxValue(str)
{
	if (str.length==0)
  {
  document.getElementById("rateId").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("rateId").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_val.php?q="+str,true);
xmlhttp.send();
}
function calculateTotalTaxAmt()
{
	var taxRate=document.getElementById("taxRate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var tax=taxableAmount*(taxRate/100);
	document.getElementById("totalTaxAmount").value=tax.toFixed(2);
}
function calculateSurcharge()
{
	var surchargePerc=document.getElementById("surchargePerc").value;
	var totalTaxAmount=document.getElementById("totalTaxAmount").value;
	var surcharge=totalTaxAmount*(surchargePerc/100);
	document.getElementById("surchargeValue").value=surcharge.toFixed(2);
}
function calculateGrandTotal()
{
	var taxableAmount=document.getElementById("taxableAmount").value;
	var totalTaxAmount=document.getElementById("totalTaxAmount").value;
	var freight=document.getElementById("freight").value;
	var surchargeValue=document.getElementById("surchargeValue").value;
	var Grand=parseFloat(taxableAmount)+parseFloat(totalTaxAmount)+parseFloat(freight)+parseFloat(surchargeValue);
	document.getElementById("grandTotal").value=Grand.toFixed(2);
	
}
function calculatePaymentDate()
{
	var startdate=document.getElementById("orderDate").value;
	var days=document.getElementById("creditDays").value;
	
	$breakDate=startdate.split('/');
	
	var date=$breakDate[0];
	var month=$breakDate[1];
	var year=$breakDate[2];
	 startdate = month+"/"+date+"/"+year;
	
	var d=startdate.getDate();
	
}
</script>
<form action="" method="post">
<div id="TabbedPanels1" class="TabbedPanels">
  <ul class="TabbedPanelsTabGroup">
    <li class="TabbedPanelsTab" tabindex="0">Ledger Book</li>
    <li class="TabbedPanelsTab" tabindex="0">Day Book</li>
    <li class="TabbedPanelsTab" tabindex="0">Cash Receipt Book</li>
    <li class="TabbedPanelsTab" tabindex="0">Cash Payment Book</li>
    <li class="TabbedPanelsTab" tabindex="0">Bank Receipt Book</li>
    <li class="TabbedPanelsTab" tabindex="0">Bank Payment Book</li>
    <li class="TabbedPanelsTab" tabindex="0">Contra Book</li>
  </ul></div>
  <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
		  	<td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Ledger Book</strong></div></td>
    </tr>
	<tr>
		<td><div align="center">
			<table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
			  <tr>
				<th width="19%" align="left"><strong>Branch</strong></th>
				<td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
				  <option value="000">---Select---</option>
				  <?php 
		if($_SESSION['AssignedSites']!='0'){
		$site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
		else
		{$site_sql=DB_query("Select loccode,locationname from locations",$db);}
		while($site_row=DB_fetch_array($site_sql)){
				?>
				  <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
				  <?php } ?>
				</select>				</td>
				<th width="23%" align="left"><strong>Period</strong></th>
				<td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
			  </tr>
			  <tr>
			    <th align="left"><strong>Ledger Name</strong></th>
			    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
			      <option value="000">---Select---</option>
			      <?php 
		if($_SESSION['AssignedSites']!='0'){
		$site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
		else
		{$site_sql=DB_query("Select loccode,locationname from locations",$db);}
		while($site_row=DB_fetch_array($site_sql)){
				?>
			      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
			      <?php } ?>
		        </select></td>
				<th align="left">&nbsp;</th>
				<td>&nbsp;</td>
			  </tr>
		  </table>
	  </div>		</td>
	</tr>
    <tr>
    	<td>&nbsp;</td>
    </tr>
    <tr>
    	<td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
    </tr>
     <tr>
    	<td>&nbsp;</td>
    </tr>
	<tr>
    	<td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
    	  <tr>
    	    <th width="11%"><strong>Voucher Date</strong></th>
    	    <th width="12%"><strong>Voucher No.</strong></th>
    	    <th width="11%"><strong>Voucher Type</strong></th>
    	    <th width="22%"><strong>Ledger Name</strong></th>
    	    <th width="11%"><strong>Debit Amt.</strong></th>
    	    <th width="12%"><strong>Credit Amt.</strong></th>
    	    <th width="11%"><strong>Balance Amt.</strong></th>
    	    <th width="10%"><strong>Unit</strong></th>
   	      </tr>
    	  <?php 
  	$sql=DB_query("Select * from salesorder",$db);
	$i=1;
	while($myrow=DB_fetch_array($sql)){
  ?>
    	  <tr bgcolor="#FFFFFF">
    	    <td><strong><?php echo $i;?></strong></td>
    	    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
	echo $sitename;?></td>
    	    <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
    	    <td><?php echo $myrow['orderNo'];?></td>
    	    <td><?php echo $myrow['creditDays'];?></td>
    	    <td><?php echo $myrow['expiry'];?></td>
    	    <td><?php
	$username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
	echo $username;?></td>
    	    <td><?php
	$username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
	echo $username;?></td>
   	      </tr>
    	  <?php $i++;}?>
          <tr bgcolor="#FFFFFF">
    	    <td>&nbsp;</td>
    	    <td>&nbsp;</td>
    	    <td>&nbsp;</td>
    	    <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
    	    <td><?php echo $myrow['creditDays'];?></td>
    	    <td><?php echo $myrow['expiry'];?></td>
    	    <td><?php
	$username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
	echo $username;?></td>
    	    <td><?php
	$username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
	echo $username;?></td>
   	      </tr>
  	  </table></td>
    </tr>
</table></div>
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
		  	<td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
    </tr>
	<tr>
		<td><div align="center">
			<table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
			  <tr>
				<th width="19%" align="left"><strong>Branch</strong></th>
				<td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
				  <option value="000">---Select---</option>
				  <?php 
		if($_SESSION['AssignedSites']!='0'){
		$site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
		else
		{$site_sql=DB_query("Select loccode,locationname from locations",$db);}
		while($site_row=DB_fetch_array($site_sql)){
				?>
				  <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
				  <?php } ?>
				</select>				</td>
				<th width="23%" align="left"><strong>Period</strong></th>
				<td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
			  </tr>
			  
		  </table>
	  </div>		</td>
	</tr>
    <tr>
    	<td>&nbsp;</td>
    </tr>
    <tr>
    	<td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
    </tr>
     <tr>
    	<td>&nbsp;</td>
    </tr>
	<tr>
    	<td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
    	  <tr>
    	    <th width="11%"><strong>Date</strong></th>
    	    <th width="12%"><strong>Ledger Name</strong></th>
    	    <th width="11%"><strong>Voucher Type</strong></th>
    	    <th width="22%"><strong>Voucher No.</strong></th>
    	    <th width="11%"><strong>Debit Amt.</strong></th>
    	    <th width="12%"><strong>Credit Amt.</strong></th>
   	      </tr>
    	  <?php 
  	$sql=DB_query("Select * from salesorder",$db);
	$i=1;
	while($myrow=DB_fetch_array($sql)){
  ?>
    	  <tr bgcolor="#FFFFFF">
    	    <td><strong><?php echo $i;?></strong></td>
    	    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
	echo $sitename;?></td>
    	    <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
    	    <td><?php echo $myrow['orderNo'];?></td>
    	    <td><?php echo $myrow['creditDays'];?></td>
    	    <td><?php echo $myrow['expiry'];?></td>
   	      </tr>
    	  <?php $i++;}?>
          <tr bgcolor="#FFFFFF">
    	    <td>&nbsp;</td>
    	    <td>&nbsp;</td>
    	    <td>&nbsp;</td>
    	    <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
    	    <td><?php echo $myrow['creditDays'];?></td>
    	    <td><?php echo $myrow['expiry'];?></td>
   	      </tr>
  	  </table></td>
    </tr>
</table></div>
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
        </tr>
        <tr>
            <td><div align="center">
                <table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
                  <tr>
                    <th width="19%" align="left"><strong>Branch</strong></th>
                    <td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="23%" align="left"><strong>Period</strong></th>
                    <td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Ledger Name</strong></th>
                    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">&nbsp;</th>
                    <td>&nbsp;</td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
        </tr>
         <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
              <tr>
                <th width="11%"><strong>Voucher Date</strong></th>
                <th width="12%"><strong>Voucher No.</strong></th>
                <th width="11%"><strong>Voucher Type</strong></th>
                <th width="22%"><strong>Ledger Name</strong></th>
                <th width="11%"><strong>Debit Amt.</strong></th>
                <th width="12%"><strong>Credit Amt.</strong></th>
                <th width="11%"><strong>Balance Amt.</strong></th>
                <th width="10%"><strong>Unit</strong></th>
              </tr>
              <?php 
        $sql=DB_query("Select * from salesorder",$db);
        $i=1;
        while($myrow=DB_fetch_array($sql)){
      ?>
              <tr bgcolor="#FFFFFF">
                <td><strong><?php echo $i;?></strong></td>
                <td><?php 
        $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
        echo $sitename;?></td>
                <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
                <td><?php echo $myrow['orderNo'];?></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
              <?php $i++;}?>
              <tr bgcolor="#FFFFFF">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
          </table></td>
        </tr>
    </table></div>
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
        </tr>
        <tr>
            <td><div align="center">
                <table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
                  <tr>
                    <th width="19%" align="left"><strong>Branch</strong></th>
                    <td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="23%" align="left"><strong>Period</strong></th>
                    <td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Ledger Name</strong></th>
                    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">&nbsp;</th>
                    <td>&nbsp;</td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
        </tr>
         <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
              <tr>
                <th width="11%"><strong>Voucher Date</strong></th>
                <th width="12%"><strong>Voucher No.</strong></th>
                <th width="11%"><strong>Voucher Type</strong></th>
                <th width="22%"><strong>Ledger Name</strong></th>
                <th width="11%"><strong>Debit Amt.</strong></th>
                <th width="12%"><strong>Credit Amt.</strong></th>
                <th width="11%"><strong>Balance Amt.</strong></th>
                <th width="10%"><strong>Unit</strong></th>
              </tr>
              <?php 
        $sql=DB_query("Select * from salesorder",$db);
        $i=1;
        while($myrow=DB_fetch_array($sql)){
      ?>
              <tr bgcolor="#FFFFFF">
                <td><strong><?php echo $i;?></strong></td>
                <td><?php 
        $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
        echo $sitename;?></td>
                <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
                <td><?php echo $myrow['orderNo'];?></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
              <?php $i++;}?>
              <tr bgcolor="#FFFFFF">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
          </table></td>
        </tr>
    </table></div>
    </div>
    <div class="TabbedPanelsContent">
    	<form action="" method="post">
        <table width="100%" border="0" cellspacing="2" cellpadding="5">
         <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Bank Receipt Book</strong></div></td>
        </tr>
        <tr>
            <td><table width="60%" border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
              <tr>
                <th width="13%"><strong>SITE</strong></tH>
                <td width="31%">
                <select name="site" id="site">
                <option value="">---Select Site---</option>
                <?php 
                $site_sql = "Select loccode, locationname from locations";
                $site_result = DB_query($site_sql, $db);
                while($site_row	= DB_fetch_array($site_result))
                { 
                    $p='';
                    if($site_row['loccode']==$_POST['site'])
                    $p="selected";
                ?>
                <option value="<?php echo $site_row['loccode'];?>" <?php echo $p;?>><?php echo $site_row['locationname'];?></option>		
                <?php 
                }
                ?>
                </select>
                </td>
                <th width="25%"><strong>FROM</strong></th>
                <td width="31%" nowrap="nowrap"><input type="text" name="fromdate" value="<?php echo $_POST['fromdate']; ?>" id="fromdate" class="datepicker" size="12"> 
                To 
                <input type="text" name="todate" value="<?php echo $_POST['todate']; ?>" id="todate" class="datepicker" size="12" /></td>
              <tr>
                <th><strong>BANK</strong></th>
                <td><select name="bank" id="bank">
                  <option value="">---Select---</option>
                  <?php 
                echo $query = "SELECT A.GroupId,B.AccountName,B.AccountsID from accountgroupmaster A ,accountledger B where A.GroupId=19 and B.UnderGroup=A.GroupId and B.AccountName!='Cash In Hand' ";
                $result = DB_query($query,$db);
                while($row = DB_fetch_array($result))
                { 
                    $p='';
                    if($row['AccountsID']==$_POST['bank'])
                    $p="selected";
                ?>
                  <option value="<?php echo $row['AccountsID'];?>" <?php echo $p;?>><?php echo $row['AccountName'];?></option>
                  <?php } ?>
                </select></td>
                <th>&nbsp;</th>
                <td>&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td><p align="center">
              <input type="submit" name="add" value="Add In Schedule">
                              <input type="submit" name="view" value="View">
                              <input type="submit" name="print" value="Print">
            <input type="submit" name="cancel" value="Cancel"></p></td>
        </tr>
        </table>
        </form>
        <hr>
        <form action="" method="post">
          <table width="100%" border="0" cellspacing="2" cellpadding="2">
            <tr>
              <th scope="col"><strong>VOUCHER DATE </strong></th>
              <th scope="col"><strong>VOUCHER NO.</strong></th>
              <th scope="col"><strong>SUB LEDGER/PARTY </strong></th>
              <th scope="col"><strong>AMOUNT(INR)</strong></th>
              <th scope="col"><strong>CHEQUE NO. </strong></th>
              <th scope="col"><strong>BANK</strong></th>
              <th scope="col"><strong>NARRATION</strong></th>
            </tr>
             <?php if($_REQUEST['view']){
        $fordate = $_POST['fromdate'];
        $todate = $_POST['todate'];
        $fromdate = explode("/", $fordate);
        $daydate = $fromdate['0'];
        $Monthdate = $fromdate['1'];
        $yeardate = $fromdate['2'];
        $fdate = $yeardate."-".$Monthdate."-".$daydate;
                               
        $tredate   = explode("/", $todate);
        $dayda     = $tredate['0'];
        $Monthda   = $tredate['1'];
        $yearda    = $tredate['2'];
        $toyrdate  = $yearda."-".$Monthda."-".$dayda;
            
            $filter=array();
        $sql = "select * from cashbankvoucher_master A, cashbankvoucher B where A.voucherMasterId = B.TransId ";
        
            if($_GET['PrefixID'])
            $filter[]="A.PreFix='".$PrefixID."' ";
            if(isset($_POST['site']) && $_POST['site'] != '')
            $filter[]="A.BranchID='".$_POST['site']."'";
            if(isset($_POST['fromdate']) && $_POST['fromdate'] != '' && isset($_POST['todate']) && $_POST['todate'] != '')
            $filter[]="A.VDate between '".$fdate."' and '".$toyrdate."' ";
            if(isset($_REQUEST['bank']) && $_REQUEST['bank'] != '')
            $filter[]="A.CaseBankId = '".$_POST['bank']."'";
        
        if($filter!=''){
            $sql=$sql." and ".implode(" and ",$filter);
            }	
        echo $sql;
        //echo "<pre>";
        //print_r($_REQUEST);
        
        $res = DB_query($sql,$db);
        while($myrow = DB_fetch_array($res))
        { ?>
              <tr bgcolor="#FFFFFF">
              <td><?php echo ConvertSQLDate($myrow['VDate']);?></td>
              <td><?php echo $myrow['VoucherNo'];?></td>
              <td><?php 
                $ledger_sql = "select AccountName from accountledger where AccountsID='".$myrow['ledger_id']."'";
                $ledger_res = DB_query($ledger_sql,$db);
                $ledger_row = DB_fetch_array($ledger_res);
                $sub_sql = "select SubLedgerName from mastersubledger where LedgerId='".$myrow['sub_ledger_id']."' ";
                $sub_res = DB_query($sub_sql, $db);
                $sub_ledger = DB_fetch_array($sub_res);
                echo $ledger_row['AccountName']." - ".$sub_ledger['SubLedgerName'];
              ?></td>
              <td><?php echo $myrow['Amount'];?></td>
              <td><?php echo $myrow['cheque_no'];?></td>
              <td><?php 
              $bank_sql = "select AccountName from accountledger where AccountsID='".$myrow['CaseBankId']."'";
              $bank_result = DB_query($bank_sql,$db);
              $bank_row = DB_fetch_array($bank_result);
              echo $bank_row['AccountName'];
              ?></td>
              <td><?php echo $myrow['narration'];?></td>
              </tr>
        <?php }  }?>
          </table>
        </form>
	</div>
    
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
        </tr>
        <tr>
            <td><div align="center">
                <table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
                  <tr>
                    <th width="19%" align="left"><strong>Branch</strong></th>
                    <td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="23%" align="left"><strong>Period</strong></th>
                    <td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Ledger Name</strong></th>
                    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">&nbsp;</th>
                    <td>&nbsp;</td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
        </tr>
         <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
              <tr>
                <th width="11%"><strong>Voucher Date</strong></th>
                <th width="12%"><strong>Voucher No.</strong></th>
                <th width="11%"><strong>Voucher Type</strong></th>
                <th width="22%"><strong>Ledger Name</strong></th>
                <th width="11%"><strong>Debit Amt.</strong></th>
                <th width="12%"><strong>Credit Amt.</strong></th>
                <th width="11%"><strong>Balance Amt.</strong></th>
                <th width="10%"><strong>Unit</strong></th>
              </tr>
              <?php 
        $sql=DB_query("Select * from salesorder",$db);
        $i=1;
        while($myrow=DB_fetch_array($sql)){
      ?>
              <tr bgcolor="#FFFFFF">
                <td><strong><?php echo $i;?></strong></td>
                <td><?php 
        $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
        echo $sitename;?></td>
                <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
                <td><?php echo $myrow['orderNo'];?></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
              <?php $i++;}?>
              <tr bgcolor="#FFFFFF">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
          </table></td>
        </tr>
    </table></div>
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
        </tr>
        <tr>
            <td><div align="center">
                <table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
                  <tr>
                    <th width="19%" align="left"><strong>Branch</strong></th>
                    <td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="23%" align="left"><strong>Period</strong></th>
                    <td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Ledger Name</strong></th>
                    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">&nbsp;</th>
                    <td>&nbsp;</td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
        </tr>
         <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
              <tr>
                <th width="11%"><strong>Voucher Date</strong></th>
                <th width="12%"><strong>Voucher No.</strong></th>
                <th width="11%"><strong>Voucher Type</strong></th>
                <th width="22%"><strong>Ledger Name</strong></th>
                <th width="11%"><strong>Debit Amt.</strong></th>
                <th width="12%"><strong>Credit Amt.</strong></th>
                <th width="11%"><strong>Balance Amt.</strong></th>
                <th width="10%"><strong>Unit</strong></th>
              </tr>
              <?php 
        $sql=DB_query("Select * from salesorder",$db);
        $i=1;
        while($myrow=DB_fetch_array($sql)){
      ?>
              <tr bgcolor="#FFFFFF">
                <td><strong><?php echo $i;?></strong></td>
                <td><?php 
        $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
        echo $sitename;?></td>
                <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
                <td><?php echo $myrow['orderNo'];?></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
              <?php $i++;}?>
              <tr bgcolor="#FFFFFF">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
          </table></td>
        </tr>
    </table></div>
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
        </tr>
        <tr>
            <td><div align="center">
                <table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
                  <tr>
                    <th width="19%" align="left"><strong>Branch</strong></th>
                    <td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="23%" align="left"><strong>Period</strong></th>
                    <td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Ledger Name</strong></th>
                    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">&nbsp;</th>
                    <td>&nbsp;</td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
        </tr>
         <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
              <tr>
                <th width="11%"><strong>Voucher Date</strong></th>
                <th width="12%"><strong>Voucher No.</strong></th>
                <th width="11%"><strong>Voucher Type</strong></th>
                <th width="22%"><strong>Ledger Name</strong></th>
                <th width="11%"><strong>Debit Amt.</strong></th>
                <th width="12%"><strong>Credit Amt.</strong></th>
                <th width="11%"><strong>Balance Amt.</strong></th>
                <th width="10%"><strong>Unit</strong></th>
              </tr>
              <?php 
        $sql=DB_query("Select * from salesorder",$db);
        $i=1;
        while($myrow=DB_fetch_array($sql)){
      ?>
              <tr bgcolor="#FFFFFF">
                <td><strong><?php echo $i;?></strong></td>
                <td><?php 
        $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
        echo $sitename;?></td>
                <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
                <td><?php echo $myrow['orderNo'];?></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
              <?php $i++;}?>
              <tr bgcolor="#FFFFFF">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
          </table></td>
        </tr>
    </table></div>
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
        </tr>
        <tr>
            <td><div align="center">
                <table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
                  <tr>
                    <th width="19%" align="left"><strong>Branch</strong></th>
                    <td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="23%" align="left"><strong>Period</strong></th>
                    <td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Ledger Name</strong></th>
                    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">&nbsp;</th>
                    <td>&nbsp;</td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
        </tr>
         <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
              <tr>
                <th width="11%"><strong>Voucher Date</strong></th>
                <th width="12%"><strong>Voucher No.</strong></th>
                <th width="11%"><strong>Voucher Type</strong></th>
                <th width="22%"><strong>Ledger Name</strong></th>
                <th width="11%"><strong>Debit Amt.</strong></th>
                <th width="12%"><strong>Credit Amt.</strong></th>
                <th width="11%"><strong>Balance Amt.</strong></th>
                <th width="10%"><strong>Unit</strong></th>
              </tr>
              <?php 
        $sql=DB_query("Select * from salesorder",$db);
        $i=1;
        while($myrow=DB_fetch_array($sql)){
      ?>
              <tr bgcolor="#FFFFFF">
                <td><strong><?php echo $i;?></strong></td>
                <td><?php 
        $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
        echo $sitename;?></td>
                <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
                <td><?php echo $myrow['orderNo'];?></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
              <?php $i++;}?>
              <tr bgcolor="#FFFFFF">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
          </table></td>
        </tr>
    </table></div>
    <div class="TabbedPanelsContent"><table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
                <td align="center" height="40" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong>Day Book</strong></div></td>
        </tr>
        <tr>
            <td><div align="center">
                <table width="85%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
                  <tr>
                    <th width="19%" align="left"><strong>Branch</strong></th>
                    <td width="28%"><select name="branch" id="branch" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select>				</td>
                    <th width="23%" align="left"><strong>Period</strong></th>
                    <td width="30%"><input type="text" name="orderDate" id="orderDate" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker" style="width:40%"/> To  <input type="text" name="orderDate2" id="orderDate2" value="<?php if(isset($_SESSION['orderDate']))echo $_SESSION['orderDate']; else echo date('d/m/Y');?>" class="datepicker"  style="width:40%"/></td>
                  </tr>
                  <tr>
                    <th align="left"><strong>Ledger Name</strong></th>
                    <td><select name="branch2" id="branch2" style="width:98%" onchange="getOrderNo(this.value)">
                      <option value="000">---Select---</option>
                      <?php 
            if($_SESSION['AssignedSites']!='0'){
            $site_sql=DB_query("Select loccode,locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
            else
            {$site_sql=DB_query("Select loccode,locationname from locations",$db);}
            while($site_row=DB_fetch_array($site_sql)){
                    ?>
                      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_SESSION['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
                      <?php } ?>
                    </select></td>
                    <th align="left">&nbsp;</th>
                    <td>&nbsp;</td>
                  </tr>
              </table>
          </div>		</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td align="center" style="text-align:center;"><input type="button" name="" value="Proceed" /></td>
        </tr>
         <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
              <tr>
                <th width="11%"><strong>Voucher Date</strong></th>
                <th width="12%"><strong>Voucher No.</strong></th>
                <th width="11%"><strong>Voucher Type</strong></th>
                <th width="22%"><strong>Ledger Name</strong></th>
                <th width="11%"><strong>Debit Amt.</strong></th>
                <th width="12%"><strong>Credit Amt.</strong></th>
                <th width="11%"><strong>Balance Amt.</strong></th>
                <th width="10%"><strong>Unit</strong></th>
              </tr>
              <?php 
        $sql=DB_query("Select * from salesorder",$db);
        $i=1;
        while($myrow=DB_fetch_array($sql)){
      ?>
              <tr bgcolor="#FFFFFF">
                <td><strong><?php echo $i;?></strong></td>
                <td><?php 
        $sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
        echo $sitename;?></td>
                <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
                <td><?php echo $myrow['orderNo'];?></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
              <?php $i++;}?>
              <tr bgcolor="#FFFFFF">
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td height="30" align="right" style="text-align:right;"><strong>Total</strong></td>
                <td><?php echo $myrow['creditDays'];?></td>
                <td><?php echo $myrow['expiry'];?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
                <td><?php
        $username=$s->getField('www_users','id',$myrow['createdBy'],'realname');
        echo $username;?></td>
              </tr>
          </table></td>
        </tr>
    </table></div>
  </div>
  <div style="clear:both;"></div>
</div>

<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
//-->
</script>
<div style="clear:both;"></div>
</form>
<?php
include('includes/footer.inc');
?>