<?php extract($_POST);
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Sales Order');
include('includes/SQL_CommonFunctions.inc');
?>
<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>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
		  	<td align="center" height="30" colspan="6" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;"><div align="center"><strong><?php echo $title;?></strong></div></td>
    </tr>
	<tr>
		<td><div align="center">
			<form  action="" method="post">
			<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%">
				   <option value="0">---Select---</option>
				  <?php 		
		$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 ($_REQUEST['site']==$site_row['loccode']?'selected':'')?>"><?php echo $site_row['locationname'];?></option>
				  <?php } ?>
				</select>				</td>
				<th width="23%" align="left"><strong>Period Wise</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>Order No. Wise</strong></th>
			    <td><select name="orderno">
	<option value="000">Select</option>
	<?php 
	$name_sql=DB_query("Select distinct orderNo from salesorder",$db);
	while($name_row=DB_fetch_array($name_sql)) {
	?>
	<option value="<?php echo $name_row['orderNo'];?>"><?php echo $name_row['orderNo'];?></option>
	<?php } ?>
    </select>	</td>
				<th align="left"><strong>Order Type Wise</strong></th>
				<td><select name="orderType" id="orderType" style="width:98%">
                  <option value="000">---Select---</option>
                  <option value="OPEN" <?php echo($_SESSION['orderType']=='OPEN'?'selected':'')?>>OPEN</option>
				  <option value="CLOSE" <?php echo($_SESSION['orderType']=='CLOSE'?'selected':'')?>>CLOSE</option>
                </select></td>
			  </tr>
			  <tr>
			    <th align="left"><strong>Party Name Wise</strong></th>
			    <td><select name="client" id="client" style="width:98%" onchange="getCreditDays(this.value)">
			      <option value="000">---Select---</option>
			      <?php 
				$c_sql=DB_query("select id,client_code, c_name from clientmaster",$db);
				while($c_row=DB_fetch_array($c_sql)){
				?>
			      <option value="<?php echo $c_row['client_code'];?>"><?php echo $c_row['c_name'];?></option>
			      <?php } ?>
			      </select></td>
			    <th align="left"><strong>Item Wise</strong></th>
			    <td><select name="itemName"  id="itemName" style="width:98%">
	<option value="0">Select</option>
	<?php 
	$name_sql=DB_query("Select distinct item_name from item_master",$db);
	while($name_row=DB_fetch_array($name_sql)) {
	?>
	<option value="<?php echo $name_row['item_name'];?>"<?php echo ($_REQUEST['itemName']==$name_row['item_name']?'selected':'')?>><?php echo $name_row['item_name'];?></option>
	<?php } ?>
    </select></td>
			  </tr>
			  <tr>
    	<td>&nbsp;</td>
    </tr>
    <tr>
    	<td align="center" style="text-align:center;"><input type="Submit" name="Proceed" value="Proceed" /></td>
    </tr>
		  </table></form>
	  </div></td>
	</tr>    
     <tr>
    	<td>&nbsp;</td>
    </tr>
    <tr>
    	<td>&nbsp;</td>
    </tr>
	</table>

	<p align="right"><a href="exportdata1.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">Export</a></p>
		<br>
	<table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
    	  <tr>
    	    <th width="7%"><strong>S. No.</strong></th>
    	    <th width="13%"><strong>Branch</strong></th>
    	    <th width="7%"><strong>Date</strong></th>
    	    <th width="12%"><strong>Order No.</strong></th>
    	     <th width="12%"><strong>Party P.O.No.</strong></th>
    	    <th width="17%"><strong>Party Name</strong></th>
    	    <th width="8%"><strong>Qty</strong></th>
    	    <th width="13%"><strong>Pending Qty</strong></th>
    	    <th width="12%"><strong>Status</strong></th>
   	      </tr>
    	  <?php 
    	 if(isset($_POST['Proceed']))
		 {		  	
    	$filter=array();		
		$fromDate=$_REQUEST['fromDate'];
		$fromDateBrk=explode("/",$fromDate);
		$fromDate=$fromDateBrk[0];
		$fromMonth=$fromDateBrk[1];
		$fromYear=$fromDateBrk[2];
		$From=$fromYear."-".$fromMonth."-".$fromDate;		
		$toDate=$_REQUEST['toDate'];
		$toDateBrk=explode("/",$toDate);
		$toDate=$toDateBrk[0];
		$toMonth=$toDateBrk[1];
		$toYear=$toDateBrk[2];
		$To=$toYear."-".$toMonth."-".$toDate;
		if($_REQUEST['branch']!='0')
		$filter[]="A.branch='".$_REQUEST['branch']."'";
		if($_REQUEST['orderno']!='0')
		$filter[]="A.orderNo='".$_REQUEST['orderno']."'";		
		if($_REQUEST['client']!='0')
		$filter[]="A.client='".$_REQUEST['client']."'";		
		if($_REQUEST['fromDate']!='' && $_REQUEST['toDate']!='')
		$filter[]="A.orddate between '".$From."' and '".$To."'";
		if($filter!='')
		{
			if($_REQUEST['branch']!='0'){$filter2=implode(" and ",$filter)." group by B.masterid";}
			else
			$filter2=implode(" and ",$filter);
		}			
				
		if($_REQUEST['branch']!='0')
		{
	   $sql="Select A.*, B.* , sum(Quantity) from salesorder A, salesorder_details B where B.masterid=A.id and $filter2 ";
		}
		else{
		 $sql="Select A.*, B.* from salesorder A, salesorder_details B where B.masterid=A.id  "; }
		$_SESSION['data2']=$sql;
  	//$sql=DB_query("Select * from salesorder",$db);
  	$result=DB_query($sql,$db);
		$i=1;
		 $mmm=DB_num_rows($result);
		if(DB_num_rows($result)>0)
		{			
		while($myrow=DB_fetch_array($result))
			{				
          ?>
    	  <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['PORefNo'];?></td>
    	    <td><?php
    	    	$sitename1=$s->getField('clientmaster','client_code',$myrow['client'],'c_name');
	echo $sitename1;?>
    	    	 
	</td>   	    
    	    <td>
    	    	<?php if($_REQUEST['branch']!='0'){echo $myrow['sum(Quantity)'];}
else { echo $myrow['Quantity'];}
	?>
    	    </td><td>
    	    	<?php
	
	echo $myrow['pendingQty'];	?></td>
    	    <td><?php echo $myrow['status'];
	?></td>
   	       </tr>
    	  
  	  <?php $i++; }  }else
		{?>
		<tr><td colspan="9"><font color="#FF0000"><strong>No Record Found</strong></font></td></tr>
		<?php 	
		}
		}
	?></table>
	
<?php
include('includes/footer.inc');
?>