<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 return;
}
include("../opendb.php");
include("../test.php");
if($save)
{
 $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");
 $acres=mysqli_query($db,"select * from asset where acode='$acode' and brcode='$brcode'");
 if(mysqli_num_rows($acres)>0)
 {
  print "<script> alert('Duplicate Asset Code'); history.back(1); </script>";
  return;
 }
 $sql="create table asset (acode varchar(100), aname varchar(100),agroup varchar(100),adesc varchar(250), pcost double(14,2), curval double(14,2), supp varchar(250), purdate date, location varchar(200),place varchar(200), inuse varchar(10),saledet varchar(250), insure varchar(20), regno varchar(100), vehmodel varchar(200),vehtxduedt date, vehfitduedt date, vehpermdt date, polludt date, advtdt date, orgrc varchar(200),saledate date,cust varchar(200), saleamt double(14,2), insuco varchar(250), policyno varchar(100),insudt date, landlord varchar(200),builno varchar(100), agrdate date,rentdepo double(14,2), rent double(14,2),agrper varchar(100),premredt date, ondate date,brcode varchar(100),user varchar(100),pbillno varchar(100),remark varchar(250))";
mysqli_query($db,$sql);// or die(mysqli_error());

 $sql="insert into asset values('$acode', '$aname','$agroup','$adesc','$pcost','$curval','$supp', '$purdate','$location','$place','$inuse','$saledet','$insure','$regno','$vehmodel','$vehtxduedt' , '$vehfitduedt','$vehpermdt','$polludt','$advtdt','$orgrc','$saledate','$cust', '$saleamt', '$insuco', '$policyno','$insudt', '$landlord', '$builno', '$agrdate','$rentdepo', '$rent', '$agrper', '$premredt', '$ondate', '$brcode','$user','$pbillno','$remark')";
mysqli_query($db,$sql) or die(mysqli_error());
 print "<script> alert('Data has been saved'); </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.agroup.selectedIndex<=0)
 {
   alert('Invalid Asset Group');
   document.f1.agroup.focus();
   return false;
 }
 if(document.f1.insure.selectedIndex==0)
 {
  
 if(document.f1.insuco.value.length<=0)
 {
   alert('Invalid Insurance Details');
   document.f1.insuco.focus();
   return false;
 }
 }

 }
</script>

<center>
<h3>ASSET MASTER</h3>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<table border=1 width=80%>
<tr><td>
<table cellspacing=1 cellpadding=2 width=85%>
<tr><td>Asset Code</td><td><input type=text name='acode'></td></tr>
<tr><td>Asset Name</td><td><input type=text name='aname' size=40></td></tr>


<tr><td>Asset Group</td><td><select name='agroup'>
<option></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></textarea></td></tr>
<tr><td>Purchase Cost</td><td><input type=text name='pcost' size=8> Current Value
<input type=text name='curval'  size=8></td></tr>



<tr><td>Supplier</td><td><input type=text name='supp' size=40></td></tr>
<tr><td>P Bill No</td><td><input type=text name='pbillno' size=40></td></tr>

<tr><td>Purchase Date</td><td>dd<input type=text name='pd' size=2> 
mm <input type=text name='pm' size=2> yy
<input type=text name='py' size=4> </td></tr>
<tr><td>Branch</td><td><select name='location'> 
<?
$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></td></tr>
<tr><td>In-Use</td><td><select name='inuse'> <option>Yes</option><option>No</option></select></td></tr>
<tr><td>Sale / Not in use Details</td><td><textarea name='saledet' cols=38></textarea></td></tr>
<tr><td>Insured</td><td><select name='insure'> <option>Yes</option><option>No</option></select></td></tr>
<tr><td>Remark</td><td><textarea name='remark' cols=38></textarea></td></tr>
</table>
</td></tr>
<table border=1  width=80%>
<tr><td bgcolor='e4ecc4'><center>VEHICLE DETAILS</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2>
<tr><td>Reg No</td><td><input type=text name='regno'></td><td>Model</td><td><input type=text name='vehmodel'></td></tr>

<tr><td>Tax Due Date</td><td colspan=3>dd<input type=text name='pdt' size=2> 
mm <input type=text name='pmt' size=2> yy
<input type=text name='pyt' size=4> </td></tr>


<tr><td>Fit Certi Due Date</td><td colspan=3>dd<input type=text name='fitdt' size=2> 
mm <input type=text name='fitmt' size=2> yy
<input type=text name='fityt' size=4> </td></tr>

<tr><td>Permit Due Date</td><td colspan=3>dd<input type=text name='perdt' size=2> 
mm <input type=text name='permt' size=2> yy
<input type=text name='peryt' size=4> </td></tr>

<tr><td>Pollution Certi. Due Date</td><td colspan=3>dd<input type=text name='poldt' size=2> 
mm <input type=text name='polmt' size=2> yy
<input type=text name='polyt' size=4> </td></tr>

<tr><td>Advt License Due Date</td><td colspan=3>dd<input type=text name='advdt' size=2> 
mm <input type=text name='advmt' size=2> yy
<input type=text name='advyt' size=4> </td></tr>

<tr><td>Original RC at</td><td colspan=3><input type=text name='orgrc' size=30> </td></tr>


<tr><td>Sale Date</td><td colspan=3>dd<input type=text name='saledt' size=2> 
mm <input type=text name='salemt' size=2> yy
<input type=text name='saleyt' size=4> </td></tr>

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

<tr><td>Policy Number</td><td colspan=3><input type=text name='policyno'  size=30> </td></tr>

<tr><td>Due Date</td><td colspan=3>dd<input type=text name='indt' size=2> 
mm <input type=text name='inmt' size=2> yy
<input type=text name='inyt' size=4> </td></tr>
</TABLE>
</td></tr>
</table>
<table border=1  width=80%>
<tr><td bgcolor='e4ecc4'><center>LEASE HOLD PREMISES</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2>
<tr><td>Land Lord</td><td colspan=3><input type=text name='landlord'  size=30> </td></tr>
<tr><td>Building No.</td><td colspan=3><input type=text name='builno'  size=30> </td></tr>
<tr><td>Agrement Date</td><td colspan=3>dd<input type=text name='agrdt' size=2> 
mm <input type=text name='agrmt' size=2> yy
<input type=text name='agryt' size=4> </td></tr>

<tr><td>Rent Deposit</td><td colspan=3><input type=text name='rentdepo'  size=30> </td></tr>
<tr><td>Rent</td><td colspan=3><input type=text name='rent'  size=30> </td></tr>
<tr><td>Period of agreement</td><td colspan=3><input type=text name='agrper'  size=30> </td></tr>
<tr><td>Renewal Date</td><td colspan=3>dd<input type=text name='rendt' size=2> 
mm <input type=text name='renmt' size=2> yy
<input type=text name='renyt' size=4> </td></tr>
</table>

<tr><td colspan=4 align=center BGCOLOR='LIGHTSTEELBLUE'><INPUT TYPE=SUBMIT VALUE='SAVE' name='save'></TD></TR>
</table>
</form>

