<?php
include_once('database_connection.php');
if(isset($_GET['submit']))
{
$txt=$_GET['keyfield'];
echo $sql="select * from invoicemaster where keyfield like '%$txt%' and symreceived is null ";
$result=odbc_exec($connection,$sql);
	while($row=odbc_fetch_array($result))
	{
		$ReferenceInvoiceID=$row['InvoiceID'];
		$CreditCard=$row['CreditCard'];
		$NetAmount=$row['NetAmount'];
		echo $sql="update invoicemaster set Supplierid=96,paid=$NetAmount where InvoiceID=$ReferenceInvoiceID";
	//odbc_exec($connection,$sql);

		
	$sql="update VoucherDetails set LedgerID=96 where ReferenceInvoiceID=$ReferenceInvoiceID and Debit>0";
	//odbc_exec($connection,$sql);
	if($CreditCard>0)
	{
		echo	$sql="update VoucherDetails set LedgerID=98,CreditLedgerID=96,Debit=(select Debit from VoucherDetails where ReferenceInvoiceID=$ReferenceInvoiceID and Debit>0),Credit=(select Debit from VoucherDetails where ReferenceInvoiceID=$ReferenceInvoiceID and Debit>0) where ID=(select ID from VoucherDetails where ReferenceInvoiceID=$ReferenceInvoiceID and Debit=0)";
	//odbc_exec($connection,$sql);

	}
	else
	{
	echo $sql="update VoucherDetails set LedgerID=90,CreditLedgerID=96,Debit=(select Debit from VoucherDetails where ReferenceInvoiceID=$ReferenceInvoiceID and Debit>0),Credit=(select Debit from VoucherDetails where ReferenceInvoiceID=$ReferenceInvoiceID and Debit>0) where ID=(select ID from VoucherDetails where ReferenceInvoiceID=$ReferenceInvoiceID and Debit=0)";
	//odbc_exec($connection,$sql);
	}

	}
}
?>


<form>
	<p>Enter Keyfield </p>
	<input type="text" name="keyfield" value="">
	<input type="submit" name="submit" value="submit">
</form>




