<?
session_start();
$brcode = $_SESSION['brcode'];
include ("includes/top.php");
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 return;
}
include("../opendb.php");
include("../test.php");
if($_REQUEST['save'])
{
    $acode = $_REQUEST['acode'];
    $aname = $_REQUEST['aname'];
    $agroup= $_REQUEST['agroup'];
    $adesc= $_REQUEST['adesc'];
    $pcost= $_REQUEST['pcost'];
    $curval= $_REQUEST['curval'];
    $supp= $_REQUEST['supp'];
    $pbillno= $_REQUEST['pbillno'];
    $pd= $_REQUEST['pd'];
    $pm= $_REQUEST['pm'];
    $py= $_REQUEST['py'];
    $partcode= $_REQUEST['partcode'];
    $qty= $_REQUEST['qty'];
    $purdate=$py.$pm.$pd;
    $regno = $_REQUEST['regno'];
    $place = $_REQUEST['place'];
    $inuse = $_REQUEST['inuser'];
    $saledet = $_REQUEST['saledet'];
    $insure = $_REQUEST['insure'];
    $user = $_REQUEST['user'];
    $insure = $_REQUEST['insure'];
    $serialno = $_REQUEST['serialno'];
    $remark = $_REQUEST['remark'];
    $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;
    }
    if(strlen($purdate)<4)$purdate='NULL';
    if(strlen($vehtxduedt)<4)$vehtxduedt='NULL';
    if(strlen($vehfitduedt)<4)$vehfitduedt='NULL';
    if(strlen($vehpermdt)<4)$vehpermdt='NULL';
    if(strlen($polludt)<4)$polludt='NULL';
    if(strlen($advtdt)<4)$advtdt='NULL';
    if(strlen($saledate)<4)$saledate='NULL';
    if(strlen($insudt)<4)$insudt='NULL';
    if(strlen($agrdate)<4)$agrdate='NULL';
    if(strlen($premredt)<4)$premredt='NULL';
    //$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($db));
    if(strlen($saleamt)<=0)$saleamt=0;
    if(strlen($rentdepo)<=0)$rentdepo=0;
    if(strlen($rent)<=0)$rent=0;
    $sql="insert into asset (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,serialno) 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','$serialno')";
    
    mysqli_query($db,$sql) or die(mysqli_error($db));
    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>Part Code </td><td><input type=text name='partcode' size=20>Qty <input type=text name='qty' size=8></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>Used by</td><td><input type=text name='user' size=40></td></tr>
<tr><td>Serial Number</td><td><input type=text name='serialno' size=40></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>
<table>
<tr><th>Sl No.</th><th>Asset Code</th><th>Name</th><th>Group</th><th>Pur.Value</th><th>Current Value</th><th>Supplier</th><th>Pur.Date</th><th>Location</th><th>Date Entered</th><th>User</th><th>Pur.Invoice</th><th>Remarks</th><th>Serial No.</th></tr>
<?$res=mysqli_query($db,"select acode,aname,agroup,pcost,curval,supp,purdate,location,ondate,user,pbillno,remark,serialno from asset where brcode = '$brcode' order by ondate");
$i=1;
while($row=mysqli_fetch_array($res))
{
    print "<tr><td>".$i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>$row[7]</td><td>$row[8]</td><td>$row[9]</td><td>$row[10]</td><td>$row[11]</td><td>$row[12]</td><td><input type=button value='Del' name='del' onClick='delfun($row[id])'></td></form></tr>";
}?>
</table>
</form>

