Current File : /home/inlingua/public_html/noida/icentex/admin_fd/ingl_invoice_main.form.php
<?php
//  Created on: 13-04-2013

// Include header
include "header_fd.php";
?>

<h3 class='pa-nor-navbar'>Add New Invoice</h3>

<?php
echo $succFailMesg; 

// Show result of a form submission?
if ($showResult == "Y")
{	echo "<br><a href='ingl_invoice_main.select.php'>Back</a><br>";
	// Include footer
	include "footer_fd.php";
	return; 
}

?>

<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/student.js"></script>

<script language="javascript">
<!--
function validate1() 
{	if (document.aForm.recNo.value=="")
	{	alert("recNo cannot be blank. Please enter it.");
		document.aForm.recNo.focus(); return false;
	}
	
	if (document.aForm.student_address.value=="")
	{	alert("Address cannot be blank. Please enter it.");
		document.aForm.student_address.focus(); return false;
	}
	
	
	if (document.aForm.student_name.value=="")
	{	alert("Name cannot be blank. Please enter it.");
		document.aForm.student_name.focus(); return false;
	}
	
	
	if (document.aForm.received_by.value=="")
	{	alert("Mode of Payment cannot be blank. Please enter it.");
		document.aForm.received_by.focus(); return false;
	}
	return true;
}
-->
</script>
<script>
function checkdup(ch)

	{

//alert(ch.value);

    var inputs = document.getElementsByClassName('nodupli');

 

for (var i = 0; i < inputs.length; ++i) {

 //alert(inputs[i].className);

  

  val=inputs[i].value;
  //id=inputs[i].id;
  
 if(ch.value==val && inputs[i]!=ch && val!="0")
 {
 alert("Please check it is duplicate entry");
 //ch.value="0";
 }

  //alert(val);

  }

  
  
  
  
}
</script>
<script language="javascript">

function subtot(ratesid,quanid,subtot,tax_s_id,tax_id)
{
rates=1*(document.getElementById(''+ratesid+'').value);
quan=1*(document.getElementById(''+quanid+'').value);
//alert(rates);
//alert(quan);
document.getElementById(''+subtot+'').value=rates*quan;
document.getElementById(''+tax_id+'').value=1*(document.getElementById(''+tax_s_id+'').value)*quan;
gtotal();
}

</script>

<script language="javascript">
$(function() {
		$('#datepicker3').datepicker({
			changeMonth: true,
			changeYear: true
		});
	});
	$(function() {
		$('#datepicker4').datepicker({
			changeMonth: true,
			changeYear: true
		});
	});
</script>

<form id='aForm' name="aForm" method='post' action='ingl_invoice_main.main.php' onsubmit="return validate1(this)">
<input type='hidden' name='recNo' class='required' value="<?php echo $dbObject->getDbField('recNo');?>">
<input type='hidden' name='kV' value="<?php echo $_REQUEST['kV'];?>">
<input type='hidden' name='centre'  value="<?php echo $dbObject->getDbField('centre');?>">
<table>
	<tr>
		<td>Student</td><td>
<?php			
	$customer= new dbHandler();
        $customer->connect();
        $query_customer="select  a.* from ingl_admission a left join timesheet_location b on a.center_no=b.recNo where b.location='".$_SESSION['branch']."'  order by recNo desc";
		
        $result_customer=$customer->select($query_customer);
	$customer_array=array();
		
		while($data_customer=$customer->SelectNext($result_customer))
              {
		$customer_array[''.$data_customer[recNo].'']="".$data_customer['ref_No']."";
	      }
			  
		$customer_selected=$dbObject->getDbField('student_id');
		$customer_extra='style="width:180px; height:25px;" onchange="invoice_customer(this.value)"';
			  
		echo select_drop($customer_array,'student_id','Select',0,$customer_selected,$customer_extra);
			  //print_r($customer_array);
			  
			  
?>
		</td>
		<td></td>
		<td rowspan="2" valign="top">Address</td><td rowspan="2"><textarea wrap='virtual' rows='3' cols='50' id="cus_address" name='student_address'><?php echo $dbObject->getDbField('student_address');?></textarea></td>
	</tr>
<tr>
<td>Name</td><td><input type='text' name='student_name' value="<?php echo $dbObject->getDbField('student_name');?>" id="cus_name" size='20' maxlength='250' style="width:180px;"></td><td></td>	
<tr valign='top'><td>Date</td><td><input type='text' name='createDate' id="datepicker3" value="<?php echo $dbObject->getDbField('createDate');?>" size='20' maxlength='10' style="width:180px;"></td><td></td></tr>

</tr>
</table>
<table id='myDiv' style="width:100%">

<tr style=" width:100%; background:#CCCCCC">
                <td></td>
                <td>&nbsp;<b>Category</b>
                </td>
                <td>&nbsp;<b>Product</b></td>
				
			    <td>&nbsp;<b>Rate</b></td>
			    <td>&nbsp;<b>Tax</b></td>
			    <td>&nbsp;<b>Quantity</b></td>
			    <td>&nbsp;<b>Amount</b></td>
			    <td>&nbsp;<b>Remarks</b></td>
				
			   <td>&nbsp;</td>
                
              

                </tr>

<?php
$i=1;
if($_REQUEST['aC']=="sM")
{
$queryP="select * from ingl_invoice_detail where main_id='".$_REQUEST['kV']."'";
$resultP=mysql_query($queryP);

while($numP=mysql_fetch_array($resultP))
{
$t2="".$i."";
?>
<tr>
<input type="hidden" name="recNo_1[]" value="<?php echo $numP['recNo']; ?>" />
 <td><br>
                </td>
                <td>&nbsp;
				  <?php
		$prodcat= new dbHandler();
                $prodcat->connect();
                $query_prodcat="select recNo,bill_category from ingl_billing_cat order by bill_category";
		
                $result_prodcat=$prodcat->select($query_prodcat);
		$prodcat_array=array();
		
		while($data_prodcat=$prodcat->SelectNext($result_prodcat)){
			  $prodcat_array[''.$data_prodcat[recNo].'']=$data_prodcat['bill_category'];
			}
			  
			$prodcat_selected=$numP['category_id'];
			$prodcat_extra='id="target" style="width:130px;" onchange="displaymain(this.value,\'prodcat'.$i.'\');"';
			  
			echo select_drop($prodcat_array,'category[]','--  Select Category  --',0,$prodcat_selected,$prodcat_extra);
			  //print_r($customer_array);
			  
			  
?>

                </td>
                <td id="prodcat<?php echo $i; ?>">
				<?php
				if($currentMode=="Add")
				{
				$subprodcat_array=array();
				$subprodcat_selected="";
				$subprodcat_extra='id="target" style="width:130px;"';
				}
				else
				{
				$subprodcat_array=array();
				$subprodcat= new dbHandler();
                $subprodcat->connect();
                $query_subprodcat="select recNo,bill_details from ingl_billing_main where bill_category='".$numP['category_id']."' order by bill_details";
	            $result_subprodcat=$subprodcat->select($query_subprodcat);
				
				while($data_subprodcat=$subprodcat->SelectNext($result_subprodcat))
              {
			  $subprodcat_array[''.$data_subprodcat[recNo].'']=$data_subprodcat['bill_details'];
			  
			  }
				
				$subprodcat_selected=$numP['product_id'];
				$subprodcat_extra='style="width:130px; class="nodupli" onchange="checkdup(this);ajax_spec(this.value,\''.$t2.'\');"';
				
				
				}
				
				echo select_drop($subprodcat_array,'product[]','--  Select Product  --',0,$subprodcat_selected,$subprodcat_extra);
				?>
				
				</td>
				
				<td id="rates<?php echo $i; ?>" >&nbsp;
				
				<input type="text" name="rates[]" value="<?php echo $numP['rates']; ?>" style="width:70px;" id="rat<?php echo $i; ?>"  onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();" /></td>
			        <td><input type="text" name="tax_s[]" value="<?php echo $numP['tax_rates']; ?>" style="width:70px;" id="tax_s<?php echo $i; ?>" onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();"/>
				</td>
				<td>&nbsp;<input type="text" name="quan[]" id="quan<?php echo $i; ?>"   value="<?php echo $numP['quantity'] ?>" style="width:90px;" onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();" />&nbsp;<span id='unit<?php echo $i; ?>'></span></td>
				<td>&nbsp;<input type="text" name="total[]"  value="<?php echo $numP['amount'] ?>" id="tot<?php echo $i; ?>" style="width:70px;" class="net_tot" onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();"/>
				<input type="hidden" name="tax[]" value="<?php echo $numP['tax_amount']; ?>" style="width:70px;" class="tax" id="tax<?php echo $i; ?>" />
				</td>
				
				<td>&nbsp;<textarea name="description[]" cols="14" rows="1"><?php echo $numP['remarks']; ?></textarea></td>
				
				<td>&nbsp;</td>
                
              

                </tr>





<?php
$i++;
}

}
//else{
	for($i=$i;$i<=5;$i++)
{
?>
<tr>
<input type="hidden" name="recNo_1[]" value="0" />
 <td><br>
                </td>
                <td>&nbsp;
				  <?php
		$prodcat= new dbHandler();
                $prodcat->connect();
                $query_prodcat="select recNo,bill_category from ingl_billing_cat order by bill_category";
		
                $result_prodcat=$prodcat->select($query_prodcat);
		$prodcat_array=array();
		
		while($data_prodcat=$prodcat->SelectNext($result_prodcat)){
			  $prodcat_array[''.$data_prodcat[recNo].'']=$data_prodcat['bill_category'];
			}
			  
			$prodcat_selected=$dbObject->getDbField('category');
			$prodcat_extra='id="target" style="width:130px;" onchange="displaymain(this.value,\'prodcat'.$i.'\');"';
			  
			echo select_drop($prodcat_array,'category[]','--  Select Category  --',0,$prodcat_selected,$prodcat_extra);
			  //print_r($customer_array);
			  
			  
?>

                </td>
                <td id="prodcat<?php echo $i; ?>">
				<?php
				if($currentMode=="Add")
				{
				$subprodcat_array=array();
				$subprodcat_selected="";
				$subprodcat_extra='id="target" style="width:130px;"';
				}
				else
				{
				
				$subprodcat_array=array();
				$subprodcat_selected="";
				$subprodcat_extra="";
				
				}
				
				echo select_drop($subprodcat_array,'product[]','--  Select Product  --',0,$subprodcat_selected,$subprodcat_extra);
				?>
				
				</td>
				
				<td id="rates<?php echo $i; ?>" >&nbsp;
				
				
				<input type="text" name="rates[]" value="<?php echo $numP['rates']; ?>" style="width:70px;" id="rat<?php echo $i; ?>"  onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();" /></td>
			        <td><input type="text" name="tax_s[]" value="<?php echo $numP['tax_s']; ?>" style="width:70px;" id="tax_s<?php echo $i; ?>" onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();" />
				</td>
				<td>&nbsp;<input type="text" name="quan[]" id="quan<?php echo $i; ?>"   value="1" style="width:90px;" onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();" />&nbsp;<span id='unit<?php echo $i; ?>'></span></td>
				<td>&nbsp;<input type="text" name="total[]"  value="0" id="tot<?php echo $i; ?>" style="width:70px;" class="net_tot" onkeyup="javascript:subtot('rat<?php echo $i; ?>','quan<?php echo $i; ?>','tot<?php echo $i; ?>','tax_s<?php echo $i; ?>','tax<?php echo $i; ?>');gtotal();"/>
				<input type="hidden" name="tax[]" value="<?php echo $numP['tax']; ?>" style="width:70px;" class="tax" id="tax<?php echo $i; ?>" />
				</td>
				
				<td>&nbsp;<textarea name="description[]" cols="14" rows="1"></textarea></td>
				
				<td>&nbsp;</td>
                
              

                </tr>

<?php
}
//}
?>
<tr><td colspan="5"  align="right">Sub-Total</td><td><input type='text' id="sub_total" name='amount' onkeyup="gtotal();" value="<?php echo $dbObject->getDbField('amount');?>" size='10' maxlength='10'></td><td>&nbsp;</td></tr>
<tr><td colspan="5"   align="right">Tax</td><td><input type='text' name='tax_value' id="tax_value" value="<?php echo $dbObject->getDbField('tax_value');?>" size='10' maxlength='10'></td><td>&nbsp;</td></tr>
<tr><td colspan="5"  align="right">Discount<input type='text' name='discount_per' onkeyup="gtotal();" id="discount_per" value="<?php echo $dbObject->getDbField('discount_per');?>" size='5' maxlength='10'>%</td>
	<td><input type='text' name='discount_value' id="discount_value"  onkeyup="gtotal();" value="<?php echo $dbObject->getDbField('discount_value');?>" size='10' maxlength='10'></td>
<td></td></tr>
<tr><td colspan="5"  align="right">Total</td><td>
	
	<input type='text' name='final_amount' id="grand_total" value="<?php echo $dbObject->getDbField('final_amount');?>" size='10' maxlength='10'>
</td><td>&nbsp;</td></tr>
</table>
<?php
if($currentMode=="Add")
{
?>
<table width="100%">
<tr><td>Mode of Payment</td><td>
	<select name="rcpt_payment_mode">
	<option value="Cash">Cash</option>
	<option value="Cheque">Cheque</option>
	<option value="Card">Card</option>
	<option value="Net Banking">Net Banking</option>
	</select>
</td><td>&nbsp;</td><td>Amount Received</td><td><input type="text" name="rcpt_amount" value="0.00" style="width:50px;"></td>
<td>&nbsp;</td><td>Cheque No.</td><td><input type="text" name="rcpt_cheque_no" value="" style="width:100%"></td>

</tr>    
<tr>
	<td colspan="2">Cheque Drawn in favour of </td><td colspan="6"><input type="text" name="rcpt_favour_of" value="" style="width:100%"></td>
</tr>
</table>
<?php
}
?>

<table border='0' class='pa-nor'>
<tr><td colspan='3'><input type='submit' name='aC' value='<?php echo $currentMode;?>'></td></tr>
</table>
</form>




<script>
$(function() {
	$('#aForm').validate({
		errorPlacement: function(error, element) 
		{   error.appendTo( element.parent("td").next("td") );
		} 
	});
});
</script>

<?php
// Include footer
include "footer_fd.php";
?>

<script language="javascript">
function gtotal()

	{



 var inputs = document.getElementsByTagName('input');

 totalamount=0;

for (var i = 0; i < inputs.length; ++i) {

 //alert(inputs[i].className);

  if(inputs[i].className=="net_tot")

  {

  val=inputs[i].value;

  totalamount=totalamount+(1*val);

  //alert(val);

  }

  }
  
  document.getElementById('sub_total').value=roundNumber(totalamount,2);
  

 taxamount=0;

for (var i = 0; i < inputs.length; ++i) {

 //alert(inputs[i].className);

  if(inputs[i].className=="tax")

  {

  val=inputs[i].value;

  taxamount=taxamount+(1*val);

  //alert(val);

  }

  }
  
  document.getElementById('tax_value').value=taxamount;
  
  tax1=document.getElementById('tax_value').value;
  
  if(document.getElementById('discount_per').value!="" && 1*document.getElementById('discount_per').value>0)
  {
	per=((1*document.getElementById('discount_per').value)*((1*document.getElementById('sub_total').value)+(1*tax1)))/100;
        document.getElementById('discount_value').value=roundNumber(per,2);
  }
  
  discount1=document.getElementById('discount_value').value;

  /*tax2=document.getElementById('tax2').value;
  tax3=document.getElementById('tax3').value;
  tax4=document.getElementById('tax4').value;
  tax5=document.getElementById('tax5').value;
  tax6=document.getElementById('tax6').value;
  tax7=document.getElementById('tax7').value;
  */
  
  document.getElementById('grand_total').value=(1*document.getElementById('sub_total').value)+(1*tax1)-(1*discount1);
  
  
}

function roundNumber(num, dec) {

	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);

	return result;

		 }
</script>