<?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 ";
/*$sql="select * from InvoiceMaster where InvoiceID IN
(41717,
41717,
41725,
41725,
41689,
41689,
41701,
41701,
41718,
41718,
41784,
41784,
41765,
41765,
41852,
41852,
41754,
41754,
41749,
41749,
41857,
41857,
41874,
41874,
41916,
41916,
41921,
41921,
41927,
41927,
41941,
41941,
41957,
41957) and SymReceived is null and InvoiceStatus=4 and active=1";*/
/*$sql="select * from InvoiceMaster where invoiceid in (41971,
41977,41977,42011,42011,42023,42023,42042,42042)";*/
/*$sql="select * from InvoiceMaster where invoiceid in (42098,
42098,
42115,
42115,
42126,
42126,
42128,
42128)";
*/
echo $sql="select * from InvoiceMaster where InvoiceID in (19009,
19271,
21422,
22979,
23387,
23459,
28510,
28688,
42574,
42641,
44041,
44688,
44707,
44810,
44906,
45003,
45801,
45804,
45862,
45868,
45900,
45904,
46183,
46973,
47602,
47612,
47852,
57274,
57277,
57280,
84871,
84894,
98590) and SupplierID not in (96,0)";
$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,SymReceived=null  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);

	$sql="update invoicemaster set CreditCard=$NetAmount where InvoiceID=$ReferenceInvoiceID";
	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);
	$sql="update invoicemaster set TotalCurrencyAmount=$NetAmount where InvoiceID=$ReferenceInvoiceID";
	odbc_exec($connection,$sql);

	$sql="update Vouchermaster set cash=$NetAmount where vouchertypeid=8 and ReferenceInvoiceID=$ReferenceInvoiceID and active=1";
	odbc_exec($connection,$sql);	
	}

	}
}
?>


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




