
<?php include("../../include/dbconnect.php"); 
?>
<title>Customer Select page</title>
<link href="../../commonStyle.css">
<script language="javascript">
function funSubmit()
{
	document.formEntry.method = "post";
	document.formEntry.action = "<?=$_SERVER['PHP_SELF']?>?rec=Old"; 
	document.formEntry.submit();
}

function SearchCustomer()
{
	document.formEntry.method = "post";
	document.formEntry.action = "getcustomer.php?filename=parsys.php"; 
	document.formEntry.submit();	
}

function funChangeStatus()
{
	formEntry.loanidchanged.value = "Yes";
	//funSubmit();
}

function funValidate()
{
	if(formEntry.bcode.value=="")
	{
		alert("Please Enter MR No");
		formEntry.bcode.focus();
		return false;
	}

	else if(formEntry.custname.value=="")
	{
		alert("Please Enter Customer Name");
		formEntry.custname.focus();
		return false;
	}

	else
	{
		document.formEntry.method = "post";
		document.formEntry.action = "cust_temptable_entry.php?gcode=<?=$glcode?>"; 
		document.formEntry.submit();
	}
}

function isNumeric(str)
{
	if(!((event.keyCode >= 48) && (event.keyCode <= 57)))
	{
		return false;
	}
}
</script>
<style type="text/css">
body{
font-family:Verdana, Arial, Helvetica, sans-serif;
}
</style>
<link rel="stylesheet" href="../../include/style.css">
<?php


if ($rec == "") 
{
	$IsOld = "NO";
	//$bcode = NewCustmerCode();
	$bcode = "";
	$name = "";
	$address1 = "";
	$address2 = "";
	$city = "";
	$state = "";
	$country = "";
	$pin = "";
	$telno = "";
	$buyertype = "";

}

if($selbcode>0)
{
	$bcode = $selbcode;
}
$result = mysqli_query($conn,"select incentive,bcode from buy where bcode = '$bcode' and active = 'Yes' ") or die(mysqli_error());
$row = mysqli_fetch_array($result);
if(is_array($row))
{
	$loanid = $row['ipno'];
	$acctcode = $row['acctcode'];
}
else
{
	$loanid = 'AA';
}


if ($rec == "Old")
{

	foreach($_POST as $q=>$r)
	{
		$_POST[$q] = trim($r);
	}

	if ($isSrch == "Yes")
	{
		$bcode = $selbcode;
	}
	else
	{
		$bcode = $_POST['bcode'];
		
	}
	$IsOld = "YES";

	$query = "select buy.bcode as bcode,name,address1,address2,city,state,country,pin,telno,active,buyertype from buy where buy.bcode = '$bcode' and active = 'Yes'" ;
	
	$result= mysqli_query($conn,$query) or
		  die (mysqli_error() );
	$row = mysqli_fetch_array($result);
		  
	if(is_array($row))
	{
	  $bcode = $row['bcode'];
	  $name = $row['name'];
	  $address1 = $row['address1'];
	  $address2 = $row['address2'];
	  $city = $row['city'];
	  $state = $row['state'];
	  $country = $row['country'];
	  $pin = $row['pin'];
	  $telno = $row['telno'];

	  $buyertype = $row['buyertype'];


	}
	else
	{

	  //$bcode = NewCustmerCode();
      $bcode=0;
	//  $loanid = GenerateNewAcCode($accthead);
	  $IsOld = "NO";
	  $bcode = $bcode;
	  $name = "";
	  $address1 = "";
	  $address2 = "";
	  $city = "";
	  $state = "";
	  $country = "";
	  $pin = "";
	  $telno = "";

	  $buyertype = "";
  
	}
	

}

?> 

<body bgcolor="#CCCCFF" leftmargin="10px" oncontextmenu = "javascript:return false;" ondragdrop= "javascript:return false;" onselectstart="javascript:return false;">
<table cellpadding=0 cellspacing=4 width="100%" class="tdhead">
<tr>
<td style="padding:3px;" colspan=2 align="center"><b>Buyer/Customer Details</b></td>
</tr>
</table>
 <br><br><br>
<table class="tablecolor" border=0 bordercolor="#9966CC" rules="none" frame="box" cellpadding=5 cellspacing=0 width="780px"> <form name = "formEntry">

  <tr class="tdindent"> 
    <td><b>Customer No.</b></td>
    <td>  
	<input type="hidden" name="IsOld" value = "<? echo $IsOld; ?>"  >
	<input type="hidden" name="gcode" value = "<? echo 	$gcode; ?>"  >
	<? if ($rec == "Back") {?>
      <input type="text" size="15" name="bcode" value="<? echo $bcode; ?>" readonly>
	  <?  }
	   else 
	   { ?>
	   <input type="text" size="15" name="bcode" value="<? echo $bcode; ?>" onChange="javascript:funSubmit();" >
	   <input type="button" name="btnSrch" value="Search" onClick="javascript:SearchCustomer();">
		<? } ?>
      </td>
		<?
		if($loanid =='0' and $acctcode >0)
		{
				
				?>
				<td><font color="#CC0000">Vender Code </font></b></td>
				<td>  
				<input  type="text" name="gl" value="<?=$acctcode?>" readonly>
				</td>
				<?

		}
	   
		?>
       
  </tr>  
  
  <tr>
  	<td colspan="4" class="tdhead">Customer Details</td>
  </tr>
  <tr class="tdindent"> 
    <td><b>Customer Name</b></td>
    <td>   
      <input type="text" size="35" name="custname" value="<? echo $name; ?>" >
      </td>
    <td><b>Type</b></td>
    <td>  
      <input type="text" size="35" name="buyertype" value="<? echo $buyertype; ?>">
      </td>
  </tr>  
  <tr class="tdindent"> 
    <td ><b>Address</b></td>
    <td colspan="3">  
      <input type="text" size="50" name="address1" value="<? echo $address1; ?>">
      </td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
    <td colspan="3">  
      <input type="text" size="50" name="address2" value="<? echo $address2; ?>">
      </td>
  </tr>
  <tr class="tdindent">  
    <td><b>City</b></td>
    <td>  
      <input type="text" size="35" name="city" value="<? echo $city; ?>">
      </td>

    <td><b>State</b></td>
    <td>  
      <input type="text" size="35" name="state" value="<? echo $state; ?>">
      </td>
  </tr>
  <tr class="tdindent"> 
    <td><b>Pin Code</b></td>
    <td>  
      <input type="text" size="10" name="pin" value="<? echo $pin; ?>">
      </td>

    <td><b>Tel No(s)</b></td>
    <td>  
      <input type="text" size="35" name="telno" value="<? echo $telno; ?>">
      </td>
  </tr>
  


  <tr> 
	  <td colspan="4">
	  <table align="center" cellpading=0 cellspacing=10 width= 50>
		<tr> <blockquote>
		  <td> <input type ="button" name="Next" value = "Next" onClick="javascript:funValidate();"></td>
		  <td><input type="reset" name="reset" value="Clear"></blockquote>
		  </td>
		</tr>
	  </table>
	  </td>
  </tr>
</table>
<br><br><font size=1><center><a href= "javascript:window.close();">Close Window</a></center></font>
</body>
</form>
<?
function NewCustmerCode()
{
	$result = mysqli_query($conn,"select max(bcode) as bcode from buy") or die(mysqli_error());
	$row = mysqli_fetch_array($result);
	$bcode=$row['bcode'];
	if(empty($bcode))
	{ 
		$bcode='10001'; 
	}
	else
	{ 
		$bcode=$bcode+1; 
	}
	
	return $bcode;
}

function GenerateNewAcCode($accthead)
{
	$result = mysqli_query($conn,"select max(acctcode) from acctmast where acctgroup = '$accthead' order by acctcode ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	 $loanid=$row[0];
	 
	if(empty($loanid))
	{ 
		$loanid=$accthead.'000001'; 
	}
	else
	{ 
		$loanid=$loanid+1; 
	} 
	
	return $loanid;
}
?>
