<body background="blater01.gif" topmargin=0>
<?php include ("../../include/dbconnect.php");



$selQuery = "Select custcode from billcustomer where custcode = '$bcode'";
$result = mysqli_query($conn,$selQuery);
$row= mysqli_fetch_row($result);

if (!is_array($row))
{
	$query = "truncate table billcustomer";
	mysqli_query($conn,$query) or die(mysqli_error());
	
	$query="insert into billcustomer (custcode,name,address1,address2,city,state,country,pin,phone,active,record,nominee,occupation,relationship) values('$bcode','$custname','$address1','$address2','$city','$state','India','$pin','$telno','Yes',NULL,'$nominee','$occupation','$relationship')";
	mysqli_query($conn,$query) or 	die(mysqli_error());
}
else
{
	$query = "update billcustomer set name='$custname',address1='$address1',address2='$address2',city='$city',state='$state',country='India',pin='$pin',phone='$telno',nominee='$nominee',occupation='$occupation',relationship='$relationship' where custcode='$bcode'";
	mysqli_query($conn,$query) or 	die(mysqli_error());
}

if($acctcheck == 'Yes')
{

$result = mysqli_query($conn,"select acctcode from acctgroup where groupname = 'SUNDRY DEBTORS'") or die(mysqli_error());
$row = mysqli_fetch_array($result);
$group = $row[0];

	$result = mysqli_query($conn,"select max(acctcode) from acctmast where substring(acctcode,1,6) = '$group' order by acctcode ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	 $newcode=$row[0];
	
	 
	 if(empty($newcode))
	   { 
		$newcode=$accthead.'0001'; 
		}
	 else
	 { 
		$newcode=$newcode+1; 
	 } 

	$query="insert into acctmast values ('$newcode','$custname','$group','000','$type','Yes','','$opening_balance','$db_cr',NULL)";
	mysqli_query($conn,$query) or die(mysqli_error());
	
	$query="insert into inpatient (mr_no,acctcode,ipno,date,active) values('$bcode','$newcode','$loanid',curdate(),'Yes')";
	mysqli_query($conn,$query) or 	die(mysqli_error());
}
else
{
	$newcode = $gl;
}



?>
 <meta http-equiv="refresh" content="0 url=input.php?IsOld=<? echo $IsOld; ?>&custcode=<?=$bcode?>&gcode=<?=$newcode?>&ipno=<?=$ipno?>"> 
