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

include("../opendb.php");


if($_POST[save])


{
 $dt=$y.'-'.$m.'-'.$d;
 if(strlen($amt)<=0 || strlen($no)<=0)
 {
  print "<script> alert('Invalid Entry'); history.back(1);</script>";
  return;
 }
if(strlen($chqno)<= 0 && $ptype=='Cheque')
 {
  print "<script> alert('Please select type as cheque'); history.back(1);</script>";
  return;
 }
/*
 $rr=mysqli_query($db,"select * from profrec where no='$no' and brcode='$brcode'");
 if(mysqli_num_rows($rr)>0)
 {
  print "<script> alert('Duplicate Receipt NO'); history.back(1);</script>";
  return;
 }

$rr=mysqli_query($db,"select * from profreceipt where profno='$no' ");
 if(mysqli_num_rows($rr)>0)
 {
  print "<script> alert('Duplicate Proforma NO'); </script>";
  return;
 }
*/
 $sql="update profinv set mmoney='$amt',ptype='$ptype' where invno='$no' and brcode='$brcode'";

 //$sql="insert into profrec values('$no','$dt','$amt','$cust','$brcode','$ptype')";
 mysqli_query($db,$sql) or die(mysqli_error());
 //print "<script> window.open('prnduprec.php?no=$no'); </script>";
 //print "<script> window.open('prnprofrec.php?invno=$no'+'&recno='+$recno_row[0]); </script>";

$recdate=$y.'-'.$m.'-'.$d;
$chqdate=$cy.'-'.$cm.'-'.$cd;

$sqlchk=mysqli_query($db,"select '$no' in (select invno from profinv)");
$chkval_row=mysqli_fetch_row($sqlchk);
$chkval=$chkval_row[0];
//print $chkval;
if ($chkval=='1')
{
$sqlrec= "insert into profreceipt (profno,recdt,recamt,rectype,chqno,chqdt,bank,order_no)values('$no','$recdate','$amt','$ptype','$chqno','$chqdate','$bank','$orderno')";

mysqli_query($db,$sqlrec) or die(mysqli_error());
$recno=mysqli_query($db,"select max(recno) from profreceipt");
$recno_row=mysqli_fetch_row($recno);

print "<script> window.open('prnprofrec.php?invno=$no'+'&recno='+$recno_row[0]); </script>";

}
else
{
print "<script> alert('Invalid proforma NO'); </script>";
}  


}

?>
<script>
 function valid()
 {
  if(document.f1.no.value.length<=0)
   {
     alert('Invalid receipt no');
     return false; 
   }
  if(document.f1.d.value.length<=0 || document.f1.m.value.length<=0|| document.f1.y.value.length<=0)
   {
     alert('Invalid Date');
     return false;
   }
  if(document.f1.amt.value.length<=0 || isNaN(document.f1.amt.value))
   {
     alert('Invalid Amount');
     return false;
   }
  if(document.f1.cust.value.length<=0)
   {
   
   }
}
</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<BODY BGCOLOR='IVORY'>
<input type=button value='Show Receipt' onClick=document.location='listreceipt.php'><br>
<CENTER>
<h3>PRINT PROFORMA RECEIPT</H3>
<form name='f1' action='<?print $_SERVER[PHP_SELF]?>' method='post' onSubmit="return valid()">

<table cellspacing=1 cellpadding=4 bgcolor=gray>
<input type=hidden name='recno'  value='<? print $recno_row[0]?>'>
<tr><td>Proforma No.</td><td> <input type=text name='no' style={text-align:right} size=5 >
&nbsp;&nbsp; Order Form No. <input type=text name='orderno' style={text-align:right} size=10> </td>
</tr>
<tr><td>Receipt Date</td><td>dd <input type=text name='d' size=2 maxlength=2>
			mm <input type=text name='m' size=2 maxlength=2>
			yy <input type=text name='y' size=4 maxlength=4 value='<?print date("Y")?>'> </td>
</tr>

<tr><td>Receipt Amount</td><td> <input type=text name='amt' style={text-align:right}> </td></tr>
<tr><td>Type</td><td> <select name='ptype' onchange=bankdetails()><option>Cash</option><option>Cheque</option><option>RTGS</option></select> </td></tr>
<tr><td>Cheque Details</td><td> No: <input type=text disabled name='chqno' size=8>     Date: dd <input type=text disabled name='cd' size=2 maxlength=2>
			mm <input type=text disabled name='cm' size=2 maxlength=2>
			yy <input type=text disabled name='cy' size=4 maxlength=4 value='<?print date("Y")?>'>  
<br>   <br>     Bank <input type=text disabled name='bank' size=25></td> </tr>

<!--
<tr><td>Customer <br>(with addr)</td><td> <input type=hidden name='cust' size=90></td></tr>
-->
<tr><td colspan=2 align=center><input type=submit value='Save & Print' name='save' value =></td></tr>
</table>
</form>

<script>
function bankdetails()
{
if (f1.ptype.value=="Cheque")
{
f1.chqno.disabled=false;
f1.cd.disabled=false;
f1.cm.disabled=false;
f1.cy.disabled=false;
f1.bank.disabled=false;
}
else
{
f1.chqno.disabled=true;
f1.cd.disabled=true;
f1.cm.disabled=true;
f1.cy.disabled=true;
f1.bank.disabled=true;
}
}
</script>

