<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:11}
.mnu{margin-left:5}
th{font-size:14}
</style>
<CENTER>
<H2>INCENTIVE ENTRY</H2>
<?
 if(!$df)
{
   $df1=$y.'-'.$m.'-'.$d;
   $dt1=$y1.'-'.$m1.'-'.$d1;
}
 

if($save)
{
 $re=mysqli_query($db,"select * from incentive where da='$da' and brcode='$brcode'");
 if(mysqli_num_rows($re)>0)
  {
    $sql="update incentive set eiinc='$eiinc', inc='$inc',com='$com',pval='$pval', body='$body',jack='$jack', oth='$oth',rem='$rem',cd='$cd' where da='$da' and invno='$invno' and brcode='$brcode'";
  mysqli_query($db,$sql) or die(mysqli_error());
  }
 else
{
    $sql="insert into incentive values('$invno','$da','$inc','$com','$brcode','$pval','$body','$jack','$oth','$rem','$eiinc','$cd')";
  mysqli_query($db,$sql) or die(mysqli_error());
}
 show($df,$dt,$brcode);
}
else
show($df1,$dt1,$brcode);
function show($df,$dt,$brcode)
{
include("../opendb.php");
 $sq="select * from veh_invoice where brcode='$brcode' and invdate<='$dt' and invdate>='$df' and type!='sale-ret' order by invno";

 $invre=mysqli_query($db,$sq)or die(mysqli_error());
print "<br><table cellspacing=1 cellpadding=2 bgcolor='c1d7bb'>";
print "<th>No<th>Inv No.<th>Customer<th>DA<th>Amount <th>Cr Note";
print "<th>P Value<th>E-Incentive<th>Body <th>Jacky <th>Other <th>Rem";
print "<th>Incentive <th>Comm.<th>C.D<th>Action";
$i=1;
 while($row=mysqli_fetch_array($invre))
 {
   print "\n<tr bgcolor=white><form action='$PHP_SELF'>";
   print "<input type=hidden name='invno' value='$row[invno]'>";

   print "<input type=hidden name='df' value='$df'>";
   print "<input type=hidden name='dt' value='$dt'>";


 print "<input type=hidden name='da' value='$row[da]'>";
 print "<td>".$i++."</td><td>$row[invno]</td><td>".getCust($row[cust])."</td>";
 print "<td>$row[da]</td><td align=right>$row[netamt]</td>";
 $crres=mysqli_query($db,"select netamt from crnote where da='$row[da]' and brcode='$brcode'");
 $crrow=mysqli_fetch_array($crres);
 print "<td align=right>$crrow[0]</td>";
 $incen=mysqli_query($db,"select * from incentive where da='$row[da]' and brcode='$brcode'");
 $incenrow=mysqli_fetch_array($incen);
  print "<td><input type=text name='pval' size=6 value='$incenrow[pval]'></td>";
  print "<td><input type=text name='eiinc' size=6 value='$incenrow[eiinc]'></td>";

  print "<td><input type=text name='body' size=6 value='$incenrow[body]'></td>";
  print "<td><input type=text name='jack' size=6 value='$incenrow[jack]'></td>";
  print "<td><input type=text name='oth' size=6 value='$incenrow[oth]'></td>";
  print "<td><textarea name='rem'>$incenrow[rem]</textarea></td>";

  print "<td><input type=text name='inc' size=6 value='$incenrow[inc]'></td>";
  print "<td><input type=text name='com' size=6 value='$incenrow[com]'></td>";
  print "<td><input type=text name='cd' size=6 value='$incenrow[cd]'></td>";

  print "<td><input type=submit value='save' name='save'></td></form></tr>";
 } // end while invre
 print "</table>";
}// end function;



//************************************************
function getCust($c)
{
$c2=$c;
if(strlen($c<=6))
{
$cres=mysqli_query($db,"select acname from cust_master where code='$c'")or die(mysqli_error());
     $cusrow=mysqli_fetch_row($cres);
if(mysqli_num_rows($cres)>0)
 return $cusrow[0];
else 
 return "<font color=red>".$c;
}
}
?>
