<? 
session_start();
$brcode = $_SESSION['brcode'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");
$code=$_REQUEST['code'];
if(isset($_POST['sprint']))
{ 
    
    $cust=$_REQUEST['customer'];
    $addr=$_REQUEST['addr'];
    $fin=$_REQUEST['fin'];
    $mfyear=$_REQUEST['mfyear'];
    $invno=$_REQUEST['invno'];
    $chasis=$_REQUEST['da'];
    $mcode=$_REQUEST['mcode'];
    $config=$_REQUEST['config'];
    $engno=$_REQUEST['engno'];
    $color=$_REQUEST['color'];
    $gvw=$_REQUEST['gvw'];
    $wbase=$_REQUEST['wbase'];
    $tyrefr=$_REQUEST['tyrefr'];
    $tyrerr=$_REQUEST['tyrerr'];
    $cat=$_REQUEST['cat'];
    $clas=$_REQUEST['clas'];
    $mnam=$_REQUEST['mnam'];
    $hpower=$_REQUEST['hpower'];
    $fuel=$_REQUEST['fuel'];
    $cyl=$_REQUEST['cyl'];
    $capa=$_REQUEST['capa'];
    $uweight=$_REQUEST['uweight'];
    
    $axlefr=$_REQUEST['axlefr'];
    $axlerr=$_REQUEST['axlerr'];
    $axleoth=$_REQUEST['axleoth'];
    $axletan=$_REQUEST['axletan'];
    $cbody=$_REQUEST['cbody'];
    $tbody=$_REQUEST['tbody'];
    $invvalue=$_REQUEST['invvalue'];
    if(strlen($invvalue)<=0)$invvalue=0;
    $y=$_REQUEST['y'];
    $m=$_REQUEST['m'];
    $d=$_REQUEST['d'];
    $gcw=$_REQUEST['gcw'];
    $recordid=$_REQUEST['recordid'];
    
    $invdate=$y.'-'.$m.'-'.$d;
    $entrydt=$_REQUEST['entrydt'];
    $entrydt=implode('-', array_reverse(explode('-', $entrydt)));
    $sql="update scert set model='$mcode',class='$clas',manufacturer='$mnam',chasis='$chasis',engno='$engno',horse='$hpower',fuel='$fuel',cylinders='$cyl',seats='$capa',fronttyre='$tyrefr',reartyre='$tyrerr',frontaxle='$axlefr',rearaxle='$axlerr',otheraxle='$axleoth',tandemaxle='$axletan',color='$color',grosswgt='$gvw',bodytype='$tbody',wheelbase='$wbase',custname='$cust',custaddr='$addr',financer='$fin',yearofman='$mfyear',vehconfig='$config',uweight='$uweight',entrydt='$entrydt',gcw='$gcw',invvalue='$invvalue' where id='$recordid'";
   //echo $sql;
    mysqli_query($db,$sql) or die(mysqli_error());
   print "<script> alert('Data has been updated');</script>";
    print "<script> document.location='scert.php';</script>";
    /*
    if($taxtype=='CST')
        print "<script>window.open('scertreport.php?invno=$invno');</script>";
    else if($tp=='8')
        print "<script>window.open('scertreport.php?invno=$invno&da=$da');</script>";
    else
        print "<script>window.open('scertreport.php?invno=$invno&da=$da');</script>";
        */
} // end save
?>
<style>
select,input,body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>
<link type="text/css" href="../jquery/jquery-ui.min.css" rel="stylesheet" />	
<script type="text/javascript" src="../jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="../jquery/jquery.jqEasyCharCounter.min.js"></script>
    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
    <script type="text/javascript">
$(function() {


$( "#ref_date1" ).datepicker("destroy");
     
     $("#ref_date1").datepicker({ dateFormat: 'dd-mm-yy'});
});
</script>
<script>
$(function(){
$(".orderto").live("keydown.autocomplete",function(){

$orderto = $(this);

$row = $orderto.parent().parent();
$(this).autocomplete({
		source: function( request, response ) {

		$.ajax({
			url: "searchcust.php",
			dataType: "json",
			data: "key="+$orderto.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						label: item.orderto+' | '+  item.partname +' | '+  item.price  +' | '+  item.supqty  ,
						value: item.orderto,
						code:item.partname,
							adr:item.price,
							gst:item.supqty,
							marginpr:item.mrgnprc,
						    custstt:item.custstt,
						    shipdistvl:item.shidist,
						    shippinvl:item.shipin,
						    
						    

					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {

	$row.find('.orderto').val(ui.item.orderto);
	
	//$row.find('.msno').val(ui.item.partname);
	document.f1.addr.value=ui.item.code;
	
	
	
	//document.f1.msno.focus();
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});



$(".mcode").live("keydown.autocomplete",function(){

$service = $(this);
$row = $service.parent().parent();
$(this).autocomplete({
		source: function( request, response ) {

		$.ajax({
			url: "searchmcode.php",
			dataType: "json",
			data: "key="+$service.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						
						label: item.service+' | '+  item.servamt +' | '+  item.servdesc   ,
						value: item.service,
						servamt:item.servamt,
						servdesc:item.servdesc,	
						supqty:item.supqty,
						mrgnprc:item.mrgnprc,
						custstt:item.custstt,
						shipin:item.shipin,
						shidist:item.shidist,
						vehconf:item.vehconf,
						grswgt:item.grswgt,
						noseat:item.noseat,
						fronttyr:item.fronttyr,
						reartyr:item.reartyr,
						vehcat:item.vehcat,
						fraxle:item.fraxle,
						reaxle:item.reaxle,
						anyaxle:item.anyaxle,
						tanaxle:item.tanaxle,
						bdtyp:item.bdtyp,
						mkrnm:item.mkrnm,
						cylind:item.cylind,

					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {
		
	$row.find('.service').val(ui.item.value);
	document.f1.color.value=ui.item.shipin;
	document.f1.config.value=ui.item.vehconf;
	document.f1.gvw.value=ui.item.grswgt;
	document.f1.wbase.value=ui.item.shidist;
	document.f1.tyrefr.value=ui.item.fronttyr;
	document.f1.tyrerr.value=ui.item.reartyr;
	document.f1.cat.value=ui.item.vehcat;
	document.f1.clas.value=ui.item.servamt;
	document.f1.mnam.value=ui.item.mkrnm;
	document.f1.hpower.value=ui.item.servdesc;
	document.f1.fuel.value=ui.item.supqty;
	document.f1.cyl.value=ui.item.cylind;
	document.f1.capa.value=ui.item.noseat;
	
	document.f1.axlefr.value=ui.item.fraxle;
	document.f1.axlerr.value=ui.item.reaxle;
	document.f1.axleoth.value=ui.item.anyaxle;
	document.f1.axletan.value=ui.item.tanaxle;
	document.f1.tbody.value=ui.item.bdtyp;
	
	

	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});


});
var adr=[];
var ar1=[]; 
var config=[];
var config2=[];
var model=[];
var rep=[];
var area=[];
var color=[];
var engno=[];
var chasis=[];
var em_code=[];
var sconfig=[];

var gvw=[];
var wbase=[];
var tyrefr=[];
var tyrerr=[];
var cat=[];
var clas=[];
var mnam=[];
var hpower=[];
var fuel=[];
var cyl=[];
var capa=[];
var uweight=[];
var axlefr=[];
var axlerr=[];
var axleoth=[];
var axletan=[];
var cbody=[];
var tbody=[];

function fun1()
{
    var x=document.f1.da.selectedIndex;
    if(x<=0)
    {
        document.f1.mcode.value='';
        document.f1.config.value='';
    }
    else
    { 

        document.f1.mcode.value=ar1[document.f1.da.selectedIndex];
        document.f1.config.value=config[document.f1.da.selectedIndex];
        document.f1.color.value=color[document.f1.da.selectedIndex];
        document.f1.engno.value=engno[document.f1.da.selectedIndex];
        document.f1.chasis.value=chasis[document.f1.da.selectedIndex];
        //document.f1.emcode.value=em_code[document.f1.da.selectedIndex];
        document.f1.gvw.value=gvw[document.f1.da.selectedIndex];
    }
    /*if(document.f1.model.value != document.f1.mcode.value)
    {
        alert('Model code doesn\'t match with order form');
        document.f1.mcode.value='';
        document.f1.config.value='';
        document.f1.emcode.value= '';  
    }*/
}
function chmcode()
{ 
    document.f1.config.value=config2[document.f1.mcode.selectedIndex];
  document.f1.maker.value=sconfig[document.f1.mcode.selectedIndex];

if(document.f1.model.value != document.f1.mcode.value)
   {
       alert('Model code doesn\'t match with order form');
       document.f1.mcode.value='';
       document.f1.config.value='';
      document.f1.emcode.value= '';  
   }
}
function valid()
{
 submitOK="true";
 if(document.f1.invno.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Invoice No.');
 }
 if(document.f1.cust.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Customer');
 }

 if(document.f1.maker.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Descr.');
	return;
 }

 if(document.f1.mfyear.value.length<=0)
 {
   submitOK="false";
   alert('Invalid month/year');
 }

 if(document.f1.fin.selectedIndex<=0)
 {
   submitOK="false";
   alert('Invalid Financer');
 }

 if(document.f1.formno.seletedIndex<=0)
 {
   submitOK="false";
   alert('Invalid Formno');
 }
 if(document.f1.unit.value.length<=0)
 {
   submitOK="false";
   alert('Invalid unit price');
 }
 if(document.f1.segment.selectedIndex<=0)
 {
   submitOK="false";
   alert('Invalid Segment No.');

 }
if(submitOK=="true")
{
 x=confirm("Do you want to save?");
 if(x)
   submitOK="true";
 else
    submitOK="false";
}
  if(submitOK=="true")
   return true;
  else
   return false;
}

function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf(' ')>-1) 
  {
    alert('Space is not allowed');
    abc.value='';
  }
}

function setadr()
{
  var x= document.f1.cust.selectedIndex ; 
  if(x>0)
    document.f1.addr.value=adr[document.f1.cust.selectedIndex];
  else
    document.f1.addr.value='';
}
function setModel()
{
  var x= document.f1.formno.selectedIndex ; 
  if(x>0)
    {
     document.f1.model.value=model[document.f1.formno.selectedIndex];


   }
  else
    {
      document.f1.model.value='';
     document.f1.rep.value='';
     document.f1.area.value='';
   }

}
 
function setttype()
{
 if(document.f1.taxtype.selectedIndex==1)
  {
    document.f1.taxp.value=2;
    document.f1.cessp.value=0;
    document.f1.cessamt.value=0;

 }
 else
 {
  document.f1.cessp.value=1;
    document.f1.taxp.value=12.5;
 }

 calc();
}
</script>


<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
th{background-color:green;color:white}
.mnu{margin-left:5}
</style>

<?
$scertresult=mysqli_query($db,"select * from scert where brcode='$brcode' and id='$code'")or die(mysqli_error());
$scertrow=mysqli_fetch_array($scertresult);
?>
<body bgcolor='ivory'>

<form name='f1' action='<?print $PHP_SELF?>' method='POST' onSubmit="return valid()">
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td align=center bgcolor='GRAY'><FONT COLOR='IVORY'><B>CUSTOMER DETAILS</TD></TR>
<TR><td align=center bgcolor='ivory'>
<table>
<tr><td><font color=red>Customer</td><td colspan=1> <input type='text' name='customer' id='orderto' placeholder='Type Customer Name Here' class='orderto' value='<? echo $scertrow['custname'] ?>' size=50> </td></tr>
<tr>
<td>Address </td><td><textarea name='addr' cols=40><? echo $scertrow['custaddr'] ?></textarea></td>
<tr><td><font color=red>Financer</font> </td><td colspan=5> <select name='fin'> 
<option value='<? echo $scertrow['financer'] ?>'><? echo $scertrow['financer'] ?></option>
<?
$re=mysqli_query($db,"select code,finname from fin_master where branch='$brcode' order by finname");
while($row=mysqli_fetch_row($re))
{
    print "<option value='$row[1]'>$row[1]</option>";
}
?>
</select>
</td></tr>
</td><td>Month & Year Of Manufacture</td><td><input type=text  name='mfyear' value='<? echo $scertrow['yearofman'] ?>'></td></tr>



<br>
<CENTER>
<tr  bgColor='c1d7bb'><td align=center>
<tr bgColor='c1d7bb'><td colspan=7 align=center bgcolor='green'>
<font color='ivory'><STRONG>SALE CERTIFICATE No: <? echo $scertrow['invno'] ?>
<input type=hidden name='recordid' value='<?print $scertrow['id'] ?>'>

<input type=hidden name='pno' value='<?print $scertrow['invno'] ?>'>
</TD></TR>
<tr>

</tr>
<tr>
<td>Certificate No </td><td><input type=text  name='invno' value='<?print $scertrow['invno'] ?>' size=8 style={background-color:silver}></td>

</tr>
<tr><td>Chasis </td><td>
    <input type='text' name='da' id='da' value='<?print $scertrow['chasis'] ?>'>

</td></tr>
<tr></td><td>Engine No</td><td><input type=text  name='engno' value='<?print $scertrow['engno'] ?>'></td></tr>
<tr>
<td>Model Code </td><td>
    <input type='text' name='mcode' id='mcode' class='mcode' value='<?print $scertrow['model'] ?>'>
    

</tr>
<tr><td>config </td><td ><input type=text name='config' size=40 value='<?print $scertrow['vehconfig'] ?>'></td></tr>


<tr><td>Color</td> <td><input type=text name='color' value='<?print $scertrow['color'] ?>'></td></tr>

<tr><td>GVW</td><td><input type=text  name='gvw' value='<?print $scertrow['grosswgt'] ?>'></td></tr>
<tr><td>W Base </td><td><input type=text name='wbase' size=40 value='<?print $scertrow['wheelbase'] ?>'></td></tr>
<tr><td>Seating Capacity </td><td><input type=text name='capa' size=40 value='<?print $scertrow['seats'] ?>'></td></tr>
<tr><td>Tyre FR </td><td><input type=text name='tyrefr' size=40 value='<?print $scertrow['fronttyre'] ?>'></td></tr>
<tr><td>Tyre RR </td><td><input type=text name='tyrerr' size=40 value='<?print $scertrow['reartyre'] ?>'></td></tr>
<tr><td>Category </td><td><input type=text name='cat' size=40 value='<?print $scertrow['class'] ?>'></td></tr>
<tr><td>Class </td><td><input type=text name='clas' size=40 value='<?print $scertrow['class'] ?>'></td></tr>
<tr><td>Makers Name </td><td><input type=text name='mnam' size=40 value='<?print $scertrow['manufacturer'] ?>'></td></tr>
<tr><td>Horse Power </td><td><input type=text name='hpower' size=40 value='<?print $scertrow['horse'] ?>'></td></tr>
<tr><td>Fuel Used </td><td><input type=text name='fuel' size=40 value='<?print $scertrow['fuel'] ?>'></td></tr>
<tr><td>No.of Cylinders </td><td><input type=text name='cyl' size=40 value='<?print $scertrow['cylinders'] ?>'></td></tr>

<tr><td>Unladen Weight </td><td><input type=text name='uweight' value='<?print $scertrow['uweight'] ?>' size=40 ></td></tr>
<tr><td>Front axle </td><td><input type=text name='axlefr' size=40 value='<?print $scertrow['frontaxle'] ?>'></td></tr>
<tr><td>Rear axle </td><td><input type=text name='axlerr' size=40 value='<?print $scertrow['rearaxle'] ?>'></td></tr>
<tr><td>Any othe axle </td><td><input type=text name='axleoth' size=40 value='<?print $scertrow['otheraxle'] ?>'></td></tr>
<tr><td>Tandem axle</td><td><input type=text name='axletan' size=40 value='<?print $scertrow['tandemaxle'] ?>'></td></tr>
<tr><td>Gross Combination Weight </td><td><input type=text name='gcw' size=40 value='<?print $scertrow['gcw'] ?>'></td></tr>
<tr><td>Colour of Body </td><td><input type=text name='cbody' size=40 value='<?print $scertrow['color'] ?>'></td></tr>

<tr><td>Type of Body </td><td><input type=text name='tbody' size=40 value='<?print $scertrow['bodytype'] ?>'></td></tr>
<tr><td>Invoice Value </td><td><input type=text name='invvalue' size=40 value='<?print $scertrow['invvalue'] ?>'></td></tr>
<tr><td>Entry Date </td><td><input type=text name='entrydt' id="ref_date1" size=40 value='<?print implode('-', array_reverse(explode('-', $scertrow['entrydt']))) ?>' readonly></td></tr>

<tr><td colspan=6 align=center bgcolor='green'> 
<font color=white size=4>

</font>
<input type=submit  value='SAVE' name='sprint'>


<!--<input type=BUTTON value='  SAVE AND ADD ITEMS  ' name='svadd'> -->
<input type=button value='  CANCEL  ' onClick=history.back(1)></td></tr>
</table>
</form>
</td></tr>
</table>
</center>
<br>
<script>
function calc()
{
    var taxper=parseFloat(document.f1.taxp.value);
    document.f1.netamt.value=document.f1.unit.value-document.f1.disc.value;
    var cessper=parseFloat(document.f1.cessp.value).toFixed(0);
    net=parseFloat(document.f1.netamt.value);
    if(cessper==0 && taxper==2)
	{ amt=(net*100)/102; }
    else if(cessper==1)
	    amt=(net*100)/112.625; 
    else if(cessper==0)
	    amt=(net*100)/112.5; 
    document.f1.amt2.value=parseFloat(amt).toFixed(2);
    tax=parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value)/100;
    document.f1.tax.value=(tax).toFixed(2);
    var cessper=parseFloat(document.f1.cessp.value).toFixed(0);
    var ces_amt=parseFloat((document.f1.tax.value*cessper)/100);
    document.f1.cessamt.value=ces_amt.toFixed(2);
}
</script>



