<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
date_default_timezone_set("Asia/Kolkata");
$recrdid=$_REQUEST['recrdid'];
?>
<html>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui.min.js"></script>
<link type="text/css" href="../jquery/jquery-ui.min.css" rel="stylesheet" />	
<link rel="stylesheet" href="../css/form.css" type="text/css" /> 

<script type="text/javascript">
$(function(){
  $(".exphd").live("keydown.autocomplete",function(){
  $led = $(this);
  $row = $led.parent().parent();
  $(this).autocomplete({
    source: function( request, response ) {
    $.ajax({
      url: "../searchled_new.php",
      dataType: "json",
      data: "key="+$led.val(),
      success: function( data ) {
        response( $.map( data, function( item ) {
          return {
            label: '<span class="la-code">'+item.led+' </span><span class="la-name">'+  item.partname + '</span>',
            value: item.led,
            name:item.partname,
            }
        }));
      }
    });
  }
  ,
  minLength: 2,
  select: function( event, ui ) {
  $row.find('.led').val(ui.item.value);
  $row.find('.stok').val(ui.item.stock);
  $row.find('.qty').focus();
  /*log( ui.item ?
  "Selected: " + ui.item.label :
  "Nothing selected, input was " + this.value);
  */
   }

  }).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };
  });
});
</script>
<style>
    .la-code {
    display: inline-block;
    width: 200px;
}
</style>
<?
if(isset($_POST['save']))
{
   
    
    $recrdid=$_REQUEST['recrdid']; 
    $customer_name1=$_REQUEST['customer_name1']; 
    if($customer_name1>'')
    {
    
    $customer_name2=$_REQUEST['customer_name2']; 
    $customer_name3=$_REQUEST['customer_name3']; 
    $customer_name4=$_REQUEST['customer_name4']; 
    $customer_name5=$_REQUEST['customer_name5']; 
  
    $narration=$_REQUEST['customer_address']; 
    $banks=$_REQUEST['banks']; 
    $invre=mysqli_query($db,"select * from psnindia_gen4psnauto_psn_psndb.upentry where brcode='PSN236' and id='$recrdid'");
    $cr_row=mysqli_fetch_array($invre);
    $dt=$cr_row['date'];
    $mref=$cr_row['partic'];
    $res=mysqli_query($db,"select max(jvno) from journal2 where brcode='$brcode'");
    $row=mysqli_fetch_row($res);
    
    $resbp=mysqli_query($db,"select max(bpno) from bnkpay where brcode='$brcode'");
    $rowbp=mysqli_fetch_row($resbp);
    if($rowbp[0]<=0)
    {
        $bpno=1;
    }
    else
    {
        $bpno=($rowbp[0]+1);
    }
    
    $resbr=mysqli_query($db,"select max(brno) from bnkrec where brcode='$brcode'");
    $rowbr=mysqli_fetch_row($resbr);
    if($rowbr[0]<=0)
    {
        $brno=1;
    }
    else
    {
        $brno=($rowbr[0]+1);
    }
    if($row[0]<=0)
    {
        $jvno=1;
    }
    else
    {
        $jvno=($row[0]+1);
    }
    $resbp=mysqli_query($db,"select max(bpno) from psnindia_psndbdn.bnkpay where brcode='$brcode'");
    $rowbp=mysqli_fetch_row($resbp);
    if($rowbp[0]<=0)
    {
        $crnodn=1;
    }
    else
    {
        $crnodn=($rowbp[0]+1);
    }
   
    $rsdn=mysqli_query($db,"select max(brno) from psnindia_psndbdn.bnkrec where brcode='$brcode'");
$cr_rowdn=mysqli_fetch_row($rsdn);
if($cr_rowdn[0]<=0)
{
   $brnodn=1;
}
 else  
 {
   $brnodn=$cr_rowdn[0]+1;
 }
 
 
$resdn=mysqli_query($db,"select max(jvno) from psnindia_psndbdn.journal2 where brcode='$brcode'");

 $rowdn=mysqli_fetch_row($resdn);
 if($rowdn[0]<=0)
 {
    $jvnodn=1;
 }
 else
 {
    $jvnodn=($rowdn[0]+1);
 }

   
    
    $brqry=mysqli_query($db,"select brname from branch where brcode='$brcode'");
    $brqrow=mysqli_fetch_array($brqry);
    $brname=$brqrow[0];
    
    $cr_again='Bank Stmnt';
    
    $allocdate=date("Y-m-d");
    $entrytime=date("Y-m-d H:i:s");
    $customer_amt1=$_REQUEST['customer_amt1'];
    $customer_amt2=$_REQUEST['customer_amt2'];
    $customer_amt3=$_REQUEST['customer_amt3'];
    $customer_amt4=$_REQUEST['customer_amt4'];
    $customer_amt5=$_REQUEST['customer_amt5'];
   
    if($cr_row['dramt']>0)
    {
        $totcramt=$cr_row['dramt'];
        
        //$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Dr','PSN COCHIN HO','$totcramt','0','$narration','$brcode','CR','$cr_again[0]','$cr_agval[0]','$crno')";
        //mysqli_query($db,$sql) or die(mysqli_error($db));
        if($customer_amt1>0)
        {
            $ledqry1=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name1'");
            $lednum1=mysqli_num_rows($ledqry1);
            
            if($lednum1>0)
            {
                $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Dr','$customer_name1','$customer_amt1','0','$narration','$brcode','BP','$banks','$mref','$bpno')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                $sqldn="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Dr','$customer_name1','$customer_amt1','0','$narration','$brcode','BP','$banks','$mref','$crnodn')";
                mysqli_query($db,$sqldn) or die(mysqli_error());
                
                $sql="insert into bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvno','Dr','$customer_name1','$customer_amt1','0','$narration','$brcode','$bpno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                $sql="insert into psnindia_psndbdn.bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvnodn','Dr','$customer_name1','$customer_amt1','0','$narration','$brcode','$crnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name1')</script>";
            }
        }
        if($customer_amt2>0)
        {
            
            $ledqry2=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name2'");
            $lednum2=mysqli_num_rows($ledqry2);
            
            if($lednum2>0)
            {

            $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Dr','$customer_name2','$customer_amt2','0','$narration','$brcode','BP','$banks','$mref','$bpno')";
            //echo $sql;
            //echo "<br>";
            mysqli_query($db,$sql) or die(mysqli_error($db));
            $sql="insert into bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvno','Dr','$customer_name2','$customer_amt2','0','$narration','$brcode','$bpno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                $sqldn="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Dr','$customer_name2','$customer_amt2','0','$narration','$brcode','BP','$banks','$mref','$crnodn')";
                mysqli_query($db,$sqldn) or die(mysqli_error());
                $sql="insert into psnindia_psndbdn.bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvnodn','Dr','$customer_name2','$customer_amt2','0','$narration','$brcode','$crnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name2')</script>";
            }
        }
        if($customer_amt3>0)
        {
            $ledqry3=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name3'");
            $lednum3=mysqli_num_rows($ledqry3);
            
            if($lednum3>0)
            {

            $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Dr','$customer_name3','$customer_amt3','0','$narration','$brcode','BP','$banks','$mref','$bpno')";
            //echo $sql;
            //echo "<br>";
            mysqli_query($db,$sql) or die(mysqli_error($db));
            $sql="insert into bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvno','Dr','$customer_name3','$customer_amt3','0','$narration','$brcode','$bpno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                 $sqldn="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Dr','$customer_name3','$customer_amt3','0','$narration','$brcode','BP','$banks','$mref','$crnodn')";
                mysqli_query($db,$sqldn) or die(mysqli_error());
                $sql="insert into psnindia_psndbdn.bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvnodn','Dr','$customer_name3','$customer_amt3','0','$narration','$brcode','$crnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name3')</script>";
            }
        }
        if($customer_amt4>0)
        {
            $ledqry4=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name4'");
            $lednum4=mysqli_num_rows($ledqry4);
            
            if($lednum4>0)
            {

            $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Dr','$customer_name4','$customer_amt4','0','$narration','$brcode','BP','$banks','$mref','$bpno')";
            //echo $sql;
            //echo "<br>";
            mysqli_query($db,$sql) or die(mysqli_error($db));
            $sql="insert into bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvno','Dr','$customer_name4','$customer_amt4','0','$narration','$brcode','$bpno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                $sqldn="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Dr','$customer_name4','$customer_amt4','0','$narration','$brcode','BP','$banks','$mref','$crnodn')";
                mysqli_query($db,$sqldn) or die(mysqli_error());
                $sql="insert into psnindia_psndbdn.bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvnodn','Dr','$customer_name4','$customer_amt4','0','$narration','$brcode','$crnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name4')</script>";
            }
        }
        if($customer_amt5>0)
        {
            $ledqry5=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name5'");
            $lednum5=mysqli_num_rows($ledqry5);
            
            if($lednum5>0)
            {

            $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Dr','$customer_name5','$customer_amt5','0','$narration','$brcode','BP','$banks','$mref','$bpno')";
            //echo $sql;
            //echo "<br>";
            mysqli_query($db,$sql) or die(mysqli_error($db));
            $sql="insert into bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvno','Dr','$customer_name5','$customer_amt5','0','$narration','$brcode','$bpno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                
                $sqldn="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Dr','$customer_name5','$customer_amt5','0','$narration','$brcode','BP','$banks','$mref','$crnodn')";
                mysqli_query($db,$sqldn) or die(mysqli_error());
                $sql="insert into psnindia_psndbdn.bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvnodn','Dr','$customer_name5','$customer_amt5','0','$narration','$brcode','$crnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name5')</script>";
            }
        }
        $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Cr','$banks','0','$totcramt','$narration','$brcode','BP','$banks','$mref','$bpno')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
        $sql="insert into bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvno','Cr','$banks','0','$totcramt','$narration','$brcode','$bpno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                $sqldn="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Cr','$banks','0','$totcramt','$narration','$brcode','BP','$banks','$mref','$crnodn')";
                mysqli_query($db,$sqldn) or die(mysqli_error());
                $sql="insert into psnindia_psndbdn.bnkpay(date,j_type,type,partic,dramt,cramt,narr,brcode,bpno,against,no) values('$dt','$jvnodn','Cr','$banks','0','$totcramt','$narration','$brcode','$crnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
    }
    else
    {
    
        $totcramt=$cr_row['cramt'];
        $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Dr','$banks','$totcramt','0','$narration','$brcode','BR','$banks','$mref','$brno')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
        
        $sql="insert into bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvno','Dr','$banks','$totcramt','0','$narration','$brcode','$brno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
        
        
        
        
        $sqldn="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Dr','$banks','$totcramt','0','$narration','$brcode','BP','$banks','$mref','$brnodn')";
                mysqli_query($db,$sqldn) or die(mysqli_error());
                $sql="insert into psnindia_psndbdn.bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvnodn','Dr','$banks','$totcramt','0','$narration','$brcode','$brnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
        
        
        
        
        
        if($customer_amt1>0)
        {
            $ledqry1=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name1'");
            $lednum1=mysqli_num_rows($ledqry1);
            
            if($lednum1>0)
            {
        $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Cr','$customer_name1','0','$customer_amt1','$narration','$brcode','BR','$banks','$mref','$brno')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
         $sql="insert into bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvno','Cr','$customer_name1','0','$customer_amt1','$narration','$brcode','$brno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                
                $sql="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Cr','$customer_name1','0','$customer_amt1','$narration','$brcode','BR','$banks','$mref','$brnodn')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
         $sql="insert into psnindia_psndbdn.bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvnodn','Cr','$customer_name1','0','$customer_amt1','$narration','$brcode','$brnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name1')</script>";
            }
        }
        if($customer_amt2>0)
        {
            $ledqry2=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name2'");
            $lednum2=mysqli_num_rows($ledqry2);
            
            if($lednum2>0)
            {
                $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Cr','$customer_name2','0','$customer_amt2','$narration','$brcode','BR','$banks','$mref','$brno')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                 $sql="insert into bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvno','Cr','$customer_name2','0','$customer_amt2','$narration','$brcode','$brno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                $sql="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Cr','$customer_name2','0','$customer_amt2','$narration','$brcode','BR','$banks','$mref','$brnodn')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
         $sql="insert into psnindia_psndbdn.bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvnodn','Cr','$customer_name2','0','$customer_amt2','$narration','$brcode','$brnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name2')</script>";
            }
        }
            
        
        if($customer_amt3>0)
        {
            $ledqry3=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name3'");
            $lednum3=mysqli_num_rows($ledqry3);
            
            if($lednum3>0)
            {
        $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Cr','$customer_name3','0','$customer_amt3','$narration','$brcode','BR','$banks','$mref','$brno')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
         $sql="insert into bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvno','Cr','$customer_name3','0','$customer_amt3','$narration','$brcode','$brno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                
                $sql="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Cr','$customer_name3','0','$customer_amt3','$narration','$brcode','BR','$banks','$mref','$brnodn')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
         $sql="insert into psnindia_psndbdn.bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvnodn','Cr','$customer_name3','0','$customer_amt3','$narration','$brcode','$brnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name3')</script>";
            }
        }
        if($customer_amt4>0)
        {
            $ledqry4=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name4'");
            $lednum4=mysqli_num_rows($ledqry4);
            
            if($lednum4>0)
            {
                $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Cr','$customer_name4','0','$customer_amt4','$narration','$brcode','BR','$banks','$mref','$brno')";
        //echo $sql;
        //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                 $sql="insert into bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvno','Cr','$customer_name4','0','$customer_amt4','$narration','$brcode','$brno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                $sql="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Cr','$customer_name4','0','$customer_amt4','$narration','$brcode','BR','$banks','$mref','$brnodn')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
         $sql="insert into psnindia_psndbdn.bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvnodn','Cr','$customer_name4','0','$customer_amt4','$narration','$brcode','$brnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name4')</script>";
            }
        }
        if($customer_amt5>0)
        {
            $ledqry5=mysqli_query($db,"select led from ledger where brcode='$brcode' and led='$customer_name5'");
            $lednum5=mysqli_num_rows($ledqry5);
            
            if($lednum5>0)
            {
                $sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvno','Cr','$customer_name5','0','$customer_amt5','$narration','$brcode','BR','$banks','$mref','$brno')";
        //echo $sql;
        //echo "<br>";
              mysqli_query($db,$sql) or die(mysqli_error($db));
               $sql="insert into bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvno','Cr','$customer_name5','0','$customer_amt5','$narration','$brcode','$brno','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
                $sql="insert into psnindia_psndbdn.journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$dt','$jvnodn','Cr','$customer_name5','0','$customer_amt5','$narration','$brcode','BR','$banks','$mref','$brnodn')";
        //echo $sql;
        //echo "<br>";
        mysqli_query($db,$sql) or die(mysqli_error($db));
         $sql="insert into psnindia_psndbdn.bnkrec(date,j_type,type,partic,dramt,cramt,narr,brcode,brno,against,no) values('$dt','$jvnodn','Cr','$customer_name5','0','$customer_amt5','$narration','$brcode','$brnodn','$banks','$mref')";
                //echo $sql;
                //echo "<br>";
                mysqli_query($db,$sql) or die(mysqli_error($db));
                
                
                
                
            }
            else
            {
                print "<script>alert('Invalid customer $customer_name5')</script>";
            }
        }
    }
    mysqli_query($db,"update psnindia_gen4psnauto_psn_psndb.upentry set jvno='$jvno',allocat_user='$user',allocat_brcode='$brcode',allocat_date='$allocdate',allocat_branch='$brname',entrydate='$entrytime' where id='$recrdid'") or die(mysqli_error($db));
    $ip_details = $jvno.'|Bank Statement Entry|Add';
    log_entry($brcode,$user,$ip_details,"Bank Statement Entry JVNo: $jvno, ID No:$recrdid",$db);
    }
    else
    {
        print "<script>alert('Invalid customer Name')</script>";
    }
    print "<script>window.close()</script>";
    header("Refresh:0; url=bankstate.php");
}
$invres1=mysqli_query($db,"select * from psnindia_gen4psnauto_psn_psndb.upentry where brcode='PSN236' and id='$recrdid' and jvno=0");
$invrow=mysqli_fetch_array($invres1);
$narrationdat=$invrow['partic'];
$invnnum=mysqli_num_rows($invres1);
if($invnnum>0)
{
    if($invrow['dramt']>0)
    {
        $invvalue=$invrow['dramt'];
    }
    if($invrow['cramt']>0)
    {
        $invvalue=$invrow['cramt'];
    }
    ?>
    <style>
    body,td 
    {
        margin: 0 auto;
    	font-family: Arial, Verdana, Sans-Serif;
    	font-size: 0.8em;
    }
    th{font-family:verdana;font-size:11;color:white;background-color:#5b5858}
    body{background-color:ivory}
    </style>
    <center>
    <div class="w3-container w3-pale-red">
    <h4>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp DETAILS OF ACCOUNTS</h4> 
    <th colspan=12 ><h4></h4></th>
    </div>
    <table cellspacing=1 cellpadding=5 border=0 class="form">
    <form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
    </th>
    <input type='hidden' name='recrdid' id='recrdid' value='<? echo $recrdid ?>'>
    <input type='hidden' name='invamtval' id='invamtval' value='<? echo $invvalue ?>'>
    <?if($invrow['type']=='SBI'){?>
        <tr><td>Select SBI Account</td><td><select name="banks" id="banks">
        <option>SBI A/C NO -30728155988</option>
        </select>
    <?}else{?>
        <tr><td>Select FB Account</td><td><select name="banks" id="banks">
        <option>FEDERAL BANK O/D-13805600014689</option>
        </select>
    <?}?>
    <tr><td>Customer Name1</td><td>
    <input type=text name='customer_name1' id='customer_name1' class=exphd size='50'></td>
    <td>Amount1</td><td>
    <input type=text name='customer_amt1' id='customer_amt1' value='<? echo $invvalue ?>' size='20'></td>
    </tr>
    <tr><td>Customer Name2</td><td>
    <input type=text name='customer_name2' id='customer_name2' class=exphd size='50'></td>
    <td>Amount2</td>
    <td><input type=text name='customer_amt2' id='customer_amt2' size='20'></td>
    </tr>
    <tr><td>Customer Name3</td><td>
    <input type=text name='customer_name3' id='customer_name3' class=exphd size='50'></td>
    <td>Amount3</td>
    <td><input type=text name='customer_amt3' id='customer_amt3' size='20'></td>
    </tr>
    <tr><td>Customer Name4</td><td>
    <input type=text name='customer_name4' id='customer_name4' class=exphd size='50'></td>
    <td>Amount4</td>
    <td><input type=text name='customer_amt4' id='customer_amt4' size='20'></td>
    </tr>
    <tr><td>Customer Name5</td><td>
    <input type=text name='customer_name5' id='customer_name5' class=exphd size='50'></td>
    <td>Amount5</td>
    <td><input type=text name='customer_amt5' id='customer_amt5' size='20'></td>
    </tr>
    <tr><td>Narration</td><td> <input type=text name='customer_address' id='customer_address' size='50'> 
    </textarea></td>
    
    </tr>
    </table>
    <th colspan=2><input type=submit value='Submit' name='save'>
    </form>
    </div>
    <?
}
?>
</html>
<script type="text/javascript">
function valid()
{
    var custamt1;
    var custamt2;
    var custamt3;
    var custamt4;
    var custamt5;
    var totcustamt=0;
    if(document.getElementById("customer_amt1").value>0)
    {
        custamt1=document.getElementById("customer_amt1").value;
    }
    else
    {
        custamt1=0;
    }
    if(document.getElementById("customer_amt2").value>0)
    {
        custamt2=document.getElementById("customer_amt2").value;
    }
    else
    {
        custamt2=0;
    }
    if(document.getElementById("customer_amt3").value>0)
    {
        custamt3=document.getElementById("customer_amt3").value;
    }
    else
    {
        custamt3=0;
    }
    if(document.getElementById("customer_amt4").value>0)
    {
        custamt4=document.getElementById("customer_amt4").value;
    }
    else
    {
        custamt4=0;
    }
    if(document.getElementById("customer_amt5").value>0)
    {
        custamt5=document.getElementById("customer_amt5").value;
    }
    else
    {
        custamt5=0;
    }
    var totinvamt=document.getElementById("invamtval").value;
    totcustamt=parseFloat(custamt1)+parseFloat(custamt2)+parseFloat(custamt3)+parseFloat(custamt4)+parseFloat(custamt5);
    if(parseFloat(totcustamt)!=parseFloat(totinvamt))
    {
         alert('Amount mismatch');
         return false;
    }
    
}
</script>