<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 return;
}
include("../opendb.php");
include("../test.php");
$code=str_replace('*',' ',$code);
$re=mysqli_query($db,"select * from asset where acode='$code'")or die(mysqli_error($db));
$row=mysqli_fetch_array($re);
if($save)
{
 if($pswd!='edit')
 {
   print "<script> alert('Invalid Password'); window.close(); </script>";
   return;
 }
 $purdate=$py.'-'.$pm.'-'.$pd;
 $vehtxduedt=$pdy.'-'.$pdm.'-'.$pdy;
 $vehfitduedt=$fityt.'-'.$fitmt.'-'.$fitdt;
 $vehpermdt=$peryt.'-'.$permt.'-'.$perdt;
 $polludt=$polyt.'-'.$polmt.'-'.$polmt;
 $advtdt=$advyt.'-'.$advmt.'-'.$advdt;
 $saledate=$saleyt.'-'.$salemt.'-'.$saledt;
 $insudt=$inyt.'-'.$inmt.'-'.$indt;
 $agrdate=$agryt.'-'.$agrmt.'-'.$agrdt;
 $premredt=$renyt.'-'.$renmt.'-'.$rendt;
 $ondate=date("Y-m-d");
 $sql="update asset set aname='$aname',agroup='$agroup',adesc='$adesc', pcost='$pcost', curval='$curval', supp='$supp',purdate='$purdate',location='$location', place='$place', inuse='$inuse', saledet='$saledet', insure='$insure', regno='$regno',vehmodel='$vehmodel', vehtxduedt='$vehtxduedt' ,vehfitduedt='$vehfitduedt', vehpermdt='$vehpermdt', polludt='$polludt',advtdt='$advtdt',orgrc='$orgrc', saledate='$saledate', cust='$cust', saleamt='$saleamt', insuco='$insuco', policyno='$policyno', insudt='$insudt', landlord='$landlord', builno='$builno', agrdate='$agrdate',rentdepo='$rentdepo', rent='$rent', agrper='$agrper', premredt='$premredt', ondate='$ondate',pbillno='$pbillno',remark='$remark' where acode='$acode' and brcode='$brcode'";
mysqli_query($db,$sql) or die(mysqli_error($db));
 print "<script> alert('Data has been updated');opener.document.location='amastrepo.php'; window.close(); </script>";
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
body,td{font-family:arial narrow;font-size:14}
th{background-color:silver}
</style>
<script>
 function valid()
 {
 if(document.f1.acode.value.length<=0)
 {
   alert('Invalid Asset Code');
   document.f1.acode.focus();
   return false;
 }
 if(document.f1.aname.value.length<=0)
 {
   alert('Invalid Asset Name');
   document.f1.aname.focus();
   return false;
 }

 if(document.f1.insure.value=='Yes')
 {
  
 if(document.f1.insuco.value.length<=0)
 {
   alert('Invalid Insurance Details');
   document.f1.insuco.focus();
   return false;
 }
 }

 }
</script>

<center>
<h3>EDIT ASSET MASTER</h3>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<table border=1 width=60%>
<tr><td>
<table cellspacing=1 cellpadding=2>
<tr><td bgcolor='yellow'>Password</td><td bgcolor='yellow'><input type=password name='pswd'></td></tr>
<tr><td>Asset Code</td><td><input type=text readonly name='acode' value='<?print $row[acode]?>'></td></tr>
<tr><td>Asset Name</td><td><input type=text name='aname' size=40 value='<?print $row[aname]?>'></td></tr>


<tr><td>Asset Group</td><td><select name='agroup'>
 <option> <?print $row[agroup]?></option>
<?
$ares=mysqli_query($db,"select * from astgroup where brcode='$brcode' order by agrp");
while($arow=mysqli_fetch_array($ares))
{
  print "<option>$arow[0]</option>";
}
?>		</select>
	</td>
</tr>
<tr><td>Description</td><td><textarea name='adesc' cols=38><?print $row[adesc]?></textarea></td></tr>
<tr><td>Purchase Cost</td><td><input type=text name='pcost' size=8 value='<?print $row[pcost]?>'> Current Value
<input type=text name='curval'  size=8 value='<?print $row[curval]?>'></td></tr>



<tr><td>Supplier</td><td><input type=text name='supp' size=40 value='<?print $row[supp]?>'></td></tr>
<tr><td>P Bill No</td><td><input type=text name='pbillno' size=40 value='<?print $row[pbillno]?>'></td></tr>
<?
$pd1=explode('-',$row[purdate]);
?>
<tr><td>Purchase Date</td><td>dd<input type=text name='pd' size=2 value='<?print $pd1[2]?>'> 
mm <input type=text name='pm' size=2 value='<?print $pd1[1]?>'> yy
<input type=text name='py' size=4 value='<?print $pd1[0]?>'> </td></tr>
<tr><td>Branch</td><td><select name='location'> 
<option><?print $row[location]?></option>
<?
$locre=mysqli_query($db,"select brname from br_master where brcode='$brcode' order by brname");
while($locrow=mysqli_fetch_array($locre))
{
 print "<option>$locrow[brname]</option>";
}
?>
</select>
</td></tr>
<tr><td>Place</td><td><input type=text name='place' size=40 value='<?print $row[place]?>'></td></tr>
<tr><td>In-Use</td><td><select name='inuse'>
<option><?print $row[inuse]?></option>
 <option>Yes</option><option>No</option></select></td></tr>
<tr><td>Sale / Not in use Details</td><td><textarea name='saledet' cols=38><?print $row[saledet]?></textarea></td></tr>
<tr><td>Insured</td><td><select name='insure'> 
<option value='<?print $row[insure]?>'><?print $row[insure]?></option>
<option value='Yes'>Yes</option>
<option value='No'>No</option></select></td></tr>
<tr><td>Remark</td><td><textarea name='remark' cols=38><?print $row[remark]?></textarea></td></tr>
</table>
</td></tr>
<table border=1 width=60%>
<tr><td bgcolor='e4ecc4'><center>VEHICLE DETAILS</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2 width=60%>
<tr><td>Reg No</td><td><input type=text name='regno' value='<?print $row[regno]?>'></td><td>Model</td><td><input type=text name='vehmodel' value='<?print $row[vehmodel]?>'></td></tr>
<?
 $ptdt=explode('-',$row[vehtxduedt]);
?>
<tr><td>Tax Due Date</td><td colspan=3>dd<input type=text name='pdt' size=2 value='<?print $ptdt[2]?>'> 
mm <input type=text name='pmt' size=2 value='<?print $ptdt[1]?>'> yy
<input type=text name='pyt' size=4 value='<?print $ptdt[0]?>'> </td></tr>
<?
 $fit=explode('-',$row[vehfitduedt]);
?>


<tr><td>Fit Certi Due Date</td><td colspan=3>dd<input type=text name='fitdt' size=2 value='<?print $fit[2]?>'> 
mm <input type=text name='fitmt' size=2  value='<?print $fit[1]?>'> yy
<input type=text name='fityt' size=4  value='<?print $fit[0]?>'> </td></tr>

<?
 $fit=explode('-',$row[vehpermdt]);
?>
<tr><td>Permit Due Date</td><td colspan=3>dd<input type=text name='perdt' size=2 value='<?print $fit[2]?>'> 
mm <input type=text name='permt' size=2  value='<?print $fit[1]?>'> yy
<input type=text name='peryt' size=4 value='<?print $fit[0]?>'> </td></tr>

<?
 $fit=explode('-',$row[polludt]);
?>
<tr><td>Pollution Certi. Due Date</td><td colspan=3>dd<input type=text name='poldt' size=2 value='<?print $fit[2]?>'> 
mm <input type=text name='polmt' size=2 value='<?print $fit[1]?>'> yy
<input type=text name='polyt' size=4 value='<?print $fit[0]?>'> </td></tr>
<?
 $fit=explode('-',$row[advtdt]);
?>

<tr><td>Advt License Due Date</td><td colspan=3>dd<input type=text name='advdt' size=2 value='<?print $fit[2]?>'> 
mm <input type=text name='advmt' size=2 value='<?print $fit[1]?>'> yy
<input type=text name='advyt' size=4 value='<?print $fit[0]?>'> </td></tr>

<tr><td>Original RC at</td><td colspan=3><input type=text name='orgrc' size=30 value='<?print $row[orgrc]?>'> </td></tr>

<?
 $fit=explode('-',$row[saledate]);
?>
<tr><td>Sale Date</td><td colspan=3>dd<input type=text name='saledt' size=2  value='<?print $fit[2]?>'> 
mm <input type=text name='salemt' size=2  value='<?print $fit[1]?>'> yy
<input type=text name='saleyt' size=4  value='<?print $fit[0]?>'> </td></tr>

<tr><td>Customer</td><td colspan=3><input type=text name='cust' size=30  value='<?print $row[cust]?>'> </td></tr>
<tr><td>Sale Amount</td><td colspan=3><input type=text name='saleamt' size=10  value='<?print $row[saleamt]?>'> </td></tr>
</table>
</td></tr>
<table border=1 width=60%>
<tr><td bgcolor='e4ecc4'><center>INSURANCE DETAILS</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2 width=60%>
<tr><td>Insurance Company</td><td colspan=3><input type=text name='insuco'  size=30  value='<?print $row[insuco]?>'> </td></tr>

<tr><td>Policy Number</td><td colspan=3><input type=text name='policyno'  size=30  value='<?print $row[policyno]?>'> </td></tr>
<?
 $fit=explode('-',$row[insudt]);
?>

<tr><td>Due Date</td><td colspan=3>dd<input type=text name='indt' size=2  value='<?print $fit[2]?>'> 
mm <input type=text name='inmt' size=2  value='<?print $fit[1]?>'> yy
<input type=text name='inyt' size=4  value='<?print $fit[0]?>'> </td></tr>
</TABLE>
</td></tr>
</table>
<table border=1 width=60%>
<tr><td bgcolor='e4ecc4'><center>LEASE HOLD PREMISES</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2 width=60%>
<tr><td>Land Lord</td><td colspan=3><input type=text name='landlord'  size=30  value='<?print $row[landlord]?>'> </td></tr>
<tr><td>Building No.</td><td colspan=3><input type=text name='builno'  size=30  value='<?print $row[builno]?>'> </td></tr>

<?
 $fit=explode('-',$row[agrdate]);
?>
<tr><td>Agrement Date</td><td colspan=3>dd<input type=text name='agrdt' size=2  value='<?print $fit[2]?>'> 
mm <input type=text name='agrmt' size=2 value='<?print $fit[1]?>'> yy
<input type=text name='agryt' size=4 value='<?print $fit[0]?>'> </td></tr>

<tr><td>Rent Deposit</td><td colspan=3><input type=text name='rentdepo'  size=30  value='<?print $row[rentdepo]?>'> </td></tr>
<tr><td>Rent</td><td colspan=3><input type=text name='rent'  size=30 value='<?print $row[rent]?>'> </td></tr>
<tr><td>Period of agreement</td><td colspan=3><input type=text name='agrper'  size=30 value='<?print $row[agrper]?>'> </td></tr>
<?
 $fit=explode('-',$row[premredt]);
?>

<tr><td>Renewal Date</td><td colspan=3>dd<input type=text name='rendt' size=2 value='<?print $fit[2]?>'> 
mm <input type=text name='renmt' size=2 value='<?print $fit[1]?>'> yy
<input type=text name='renyt' size=4 value='<?print $fit[0]?>'> </td></tr>
</table>

<tr><td colspan=4 align=center BGCOLOR='LIGHTSTEELBLUE'><INPUT TYPE=SUBMIT VALUE='SAVE' name='save'> <input type=button value='Cancel' onClick=window.close()></TD></TR>
</table>
</form>

