<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$level=$_SESSION['level'];
$acname=$_REQUEST['acname'];
$code=$_REQUEST['code'];
if(strlen($user)<=0)
{
 print "<script> alert('You are not logged in') </script>";
 include("logout.php");
 return;
}
include("opendb.php");

$sql="select * from customer where code='$code'and acname='$acname'";
$re=mysqli_query($db,$sql)or die(mysqli_error($db));
$row=mysqli_fetch_array($re);
$dt1=explode('-',$row['crdate']);
$dt2=explode('-',$row['dob']);
?>
<link rel="stylesheet" href="css/form.css" type="text/css" />
<html>
<body>
    <br>
<h1>CUSTOMERS LIST</h1>
<center>
<form method='post' action='updcustomer.php' onSubmit="return valid()">
<input type=hidden name='code' value='<?print $code?>'>
<table cellspacing=1 cellpadding=2 bgcolor='aliceblue' width=40%>
<tr height=21><td colspan=2 align=center bgcolor='steelblue'><FONT COLOR=IVORY><B>EDIT CUSTOMER DETAILS</td></tr>
<TR><TD>Creation Date </TD><TD><?print  $dt1[2].'-'.$dt1[1].'-'.$dt1[0]?></td></tr>
<tr><td>Customer Name</td><td><input type=text name='cname' size=40 value='<?print $row['cname']?>'></td></tr>
<tr><td>Corporate </td><td><select name='corp'><option><?print $row['corp']?></option>
<?
$re=mysqli_query($db,"select * from corp_master where branch='$brcode'  order by corpname");
while($row1=mysqli_fetch_row($re))
{
 print "<option>$row1[1]</option>";
}
?>
</select>
</td></tr>

<tr bgColor='c1d7bb'><td><font color=red>Display Name<br><font color=blue>(A/c Head) 
</td><td><input type=text name='acname' readonly size=40  value='<?print $row['acname']?>' style="background-color:ivory"></td></tr>

<tr><td colspan=2 align=center bgcolor='lightsteelblue'>PERMANANT</td></tr>
<tr><td>Address</td><td><input type=text name='addr1' size=40 value='<?print $row['addr1']?>'></td></tr>
<tr><td>District</td><td><input type=text name='dist1' size=40 value='<?print $row['dist1']?>'></td></tr>
<tr><td>State</td><td>
    <select name='state1'><option>Select State</option>
    <option value="Kerala"<? if($row['state1']=='Kerala') echo 'selected="selected"';?>>Kerala</option>
    <option value="Tamil Nadu"<? if($row['state1']=='Tamil Nadu') echo 'selected="selected"';?>>Tamil Nadu</option>
    <option value="Karnataka"<? if($row['state1']=='Karnataka') echo 'selected="selected"';?>>Karnataka</option>
<option>Andhra Pradesh</option>
<option>Arunachal Pradesh</option><option>Assam</option><option>Bihar</option><option>Chhattisgarh</option>
<option>Dadra and Nagar Haveli</option><option>Daman and Diu</option><option>Delhi</option><option>Goa</option>
<option>Gujarat</option><option>Haryana</option><option>Himachal Pradesh</option><option>Jammu and Kashmir</option>
<option>Jharkhand</option><option>Madhya Pradesh</option><option>Maharashtra</option><option>Manipur</option>
<option>Meghalaya</option><option>Mizoram</option><option>Nagaland</option><option>Orissa</option>
<option>Puducherry</option><option>Punjab</option><option>Rajasthan</option><option>Sikkim</option><option>Telangana</option>
<option>Tripura</option><option>Uttar Pradesh</option><option>Uttarakhand</option><option>West Bengal</option>
    </select>
</td></tr>
<tr><td>pin</td><td><input type=text name='pin1' size=6 value='<?print $row['pin1']?>'></td></tr>
<tr><td>Phone</td><td><input type=text name='phone1' size=40 value='<?print $row['phone1']?>'></td></tr>

<tr><td colspan=2 align=center bgcolor='lightsteelblue'>PRESENT</td></tr>
<tr><td>Address</td><td><input type=text name='addr2' size=40 value='<?print $row['addr2']?>'></td></tr>
<tr><td>District</td><td><input type=text name='dist2' size=40 value='<?print $row['dist2']?>'></td></tr>
<tr><td>State</td><td>
<select name='state2'><option>Select State</option>
<option value="Kerala"<? if($row['state2']=='Kerala') echo 'selected="selected"';?>>Kerala</option>
    <option value="Tamil Nadu"<? if($row['state2']=='Tamil Nadu') echo 'selected="selected"';?>>Tamil Nadu</option>
    <option value="Karnataka"<? if($row['state2']=='Karnataka') echo 'selected="selected"';?>>Karnataka</option>
<option>Andhra Pradesh</option>
<option>Arunachal Pradesh</option><option>Assam</option><option>Bihar</option><option>Chhattisgarh</option>
<option>Dadra and Nagar Haveli</option><option>Daman and Diu</option><option>Delhi</option><option>Goa</option>
<option>Gujarat</option><option>Haryana</option><option>Himachal Pradesh</option><option>Jammu and Kashmir</option>
<option>Jharkhand</option><option>Madhya Pradesh</option><option>Maharashtra</option><option>Manipur</option>
<option>Meghalaya</option><option>Mizoram</option><option>Nagaland</option><option>Orissa</option>
<option>Puducherry</option><option>Punjab</option><option>Rajasthan</option><option>Sikkim</option><option>Telangana</option>
<option>Tripura</option><option>Uttar Pradesh</option><option>Uttarakhand</option><option>West Bengal</option>
    </select>
</td></tr>
<tr><td>pin</td><td><input type=text name='pin2' size=6 value='<?print $row['pin2']?>'></td></tr>
<tr><td>Phone</td><td><input type=text name='phone2' size=40 value='<?print $row['phone2']?>'></td></tr>

<tr><td colspan=2 align=center bgcolor='lightsteelblue'>OTHER</td></tr>
<tr><td>Mobile</td><td><input type=text name='mob' size=40 value='<?print $row['mob']?>'></td></tr>

<tr><td>FR Name</td><td><input type=text name='relation' value='<?print $row['relation']?>' size=40></td>
<tr><td></td><td><input type=text name='father' size=40 value='<?print $row['father']?>'></td></tr>
<tr><td>Date of Birth</td>
<td>
 dd  <input type=text name='d1' size=2 value='<?print $dt2[2]?>'>
mm  <input type=text name='m1' size=2 value='<?print $dt2[1]?>'>
yy  <input type=text name='y1' size=4 value='<?print $dt2[0]?>'>
</td></tr>
<tr><td>Email_id </td><td><input type=text name='email' size=40 value='<?print $row['email']?>'></td></tr>
<tr><td>TCS Applicable</td><td><select id='tcsapply' name='tcsapply'>
    <option value='<?print $row['web']?>'><?print $row['web']?></option>
    <option value='NO'>NO</option><option value='YES'>YES</option></select></td>
</tr>


<tr><td>GST Registred</td><td><select id='gstsel' name='gstsel' onchange='gstreg()'><option value='Y'>YES</option><option value='N'>NO</option></select></td></tr>
<tr bgColor='c1d7bb' id='gsttr'><td>GST No </td><td><input type=text name='gst' id='gst' value='<?print $row['gst']?>' size=40 onchange='gstnochk()'></td></tr>

<?if($level>=5)
{
?>
<tr><td colspan=2>Credit Amt <input type=text name='cramt' size=10 value='0'>
Credit Days <input type=text name='crdays' size=10 value='0'></td></tr>
<?
}
?>
<?if($level<=4)
{
?>
<tr><td colspan=2>Credit Amt <input type=text readonly name='cramt' size=10 value='0'>
Credit Days <input type=text readonly name='crdays' size=10 value='0'></td></tr>
<?
}
?>

<tr><td colspan=2 align=center bgcolor='lightsteelblue'>
<input type=submit value='Save' name='upd'> 
<input type=button value='Cancel' onClick=history.go(-1)>
</td></tr>
</table>
</form>
</body>
</html>
<script>
function valid()
{ 
    
     var gstno=document.getElementById("gst").value;
     var sdr=document.getElementById("gstsel").value;
    if(sdr=='N')
    {
       return true;
    }
    else
    {
        if(gstno.length<15||gstno.length==''||gstno.length>15)
        {
        alert("Enter 15 Digit GST Number...!!!");
        document.getElementById("gst").value='';
        document.getElementById("gst").focus();
        return false;
        } 
    }
    
    
    
     
     
     
    
    
 subOK="false";
 x=confirm("Do you want to save?");
 if(x)
  subOK="true";
   if(subOK=="true")
     return true;
   else
     return false;
} 

</script>

<script>

function gstnochk(){
    var gstno=document.getElementById("gst").value;
    if(gstno.length<15||gstno.length==''||gstno.length>15)
    {
        alert("Enter 15 Digit GST Number...!!!");
        document.getElementById("gst").value='';
        document.getElementById("gst").focus();
    }
 }//function closed.
 
function gstreg(){
var sdr=document.getElementById("gstsel").value;
 if(sdr=='N')
 {
   document.getElementById("gsttr").style.visibility = "hidden";
   document.getElementById("gst").value="NOT REGISTERD";
 }
 else
 {
   document.getElementById("gsttr").style.visibility = "visible";
   document.getElementById("gst").value='';
 }
 }//function closed.
</script>
