Current File : /home/obabain/anms_obaba_in/paymentVouchDA.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
     <%@ include file="Connection.jsp" %>
      <%
Statement st=con.createStatement();
ResultSet rs = null;
String loginid=(String)session.getAttribute("logid");
String name=(String)session.getAttribute("uname");
String firstname=(String)session.getAttribute("firstname");
%>
<%!
String particular=null;
Double paid_amt=0.00;
double amt=0.00;
String newid=null;
String ttotal=null;
String supplid=null;
String cashchq=null;
String partic=null;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form>
  <%
      try{
      String payno=request.getParameter("payno");
      String pdate=request.getParameter("paydate");
      String narr=request.getParameter("narr");
      String total=request.getParameter("gtotal");
      String acc=request.getParameter("account");
      String parti=request.getParameter("country");
      String chqno=request.getParameter("chqno");
      String chqdate=request.getParameter("chqdate");
      String chrg=request.getParameter("chrg");
      String bank=request.getParameter("bank");
      String total2=request.getParameter("total2");
     
      
      
      if(chqno.equals(""))
      {
    	  cashchq="cash";
      }
      else
      {
    	  cashchq="chq";
      }
      
  	String[] a=null;
  	String[] b=null;
  	String[] c=null;
  	String[] g=null;
  	String[] co=null;
  	String[] billtyp=null;
  	
  	billtyp=request.getParameterValues("typ[]");
  	b=request.getParameterValues("state[]");
  	c=request.getParameterValues("billamt[]");
  	co=request.getParameterValues("comm[]");
  	
  	if(payno.contentEquals(""))
  	{
  		response.sendRedirect("PaymentVoucherNew.jsp");
  	}
  	else if(payno!= null || payno.length() > 0 || payno!="")
  	{
  		int i=st.executeUpdate("insert into account_voucher_main(voucher_no,account,voucher_date,particular,credit_amt,voucher_type,narration,crdr_type,createdby,cash_cheque) values('"+payno+"','"+acc+"','"+pdate+"','"+parti+"',"+total2+",'payment','"+narr+"','Cr',"+loginid+",'"+cashchq+"')");
  		rs=st.executeQuery("select max(voucher_id)nid from account_voucher_main");
  		while(rs.next())
		{
			newid=rs.getString("nid");
		}
  		if(chqno.length()> 0)
  	  	{
  	  		int l=st.executeUpdate("insert into cheque_voucher(chq_no,chq_date,created_date,voucher_no,voucher_type) values('"+chqno+"','"+chqdate+"',NOW(),'"+payno+"','Pay')");
  	  	}
  		
  		for(int j=1;j<=co.length-1;j++)
  		{
  			if(billtyp[j].equals("B"))
  			{
  				if(b[j].equals("-1"))
  				{
  					int k=st.executeUpdate("insert into account_voucher_sub(voucher_id,particular,voucher_date,bill_no,debit_amt,crdr_type,voucher_type,type) values("+newid+",'"+parti+"','"+pdate+"',0,"+total+",'Dr','payment','WB')");
  					
  				}
  				else
  				{
  		
  			int k=st.executeUpdate("insert into account_voucher_sub(voucher_id,particular,voucher_date,bill_no,debit_amt,crdr_type,voucher_type,type) values("+newid+",'"+parti+"','"+pdate+"','"+b[j]+"',"+c[j]+",'Dr','payment','"+billtyp[j]+"')");
  			}}
  			else
  			{
  				int k=st.executeUpdate("insert into account_voucher_sub(voucher_id,particular,voucher_date,bill_no,debit_amt,crdr_type,voucher_type,type) values("+newid+",'"+b[j]+"','"+pdate+"','"+b[j]+"',"+c[j]+",'Dr','payment','"+billtyp[j]+"')");
  			}
  			if(billtyp[j].equals("B"))
  			{
  				
  				ResultSet rr=st.executeQuery("select * from account_ledger where l_id="+parti+"");
  				while(rr.next())
  		  		{
  		  			particular=rr.getString("type");
  		  			
  		  			supplid=rr.getString("ref_id");
  		  			
  		  		}
  		 		if(particular.equals("2"))
  		 			
  		 		{
  		 			
  		 			ResultSet ra=st.executeQuery("select * from ip_puchase_invoice2 where pinvoice_id="+b[j]+" and supplier_id="+supplid+"");
  		 			
  		 			while(ra.next())
  		 			{
  		 				paid_amt=Double.parseDouble(ra.getString("paid_amt"));
  		 			}
  		 			 amt=paid_amt+Double.parseDouble(c[j]);
  		 			System.out.print(amt);
  		 			int u=st.executeUpdate("update ip_puchase_invoice2 set paid_amt="+amt+" where pinvoice_id="+b[j]+" and supplier_id="+supplid+"");
  		 		}
  		 		else if(particular.equals("1"))
  		 		{
  		 			ResultSet ra=st.executeQuery("select * from journalentry where journal_id="+b[j]+"");
  		 			while(ra.next())
  		 			{
  		 				paid_amt=Double.parseDouble(ra.getString("paid_amt"));
  		 			}
  		 			 amt=paid_amt+Double.parseDouble(c[j]);
  		 			int u=st.executeUpdate("update journalentry set paid_amt="+amt+" where journal_id="+b[j]+"");
  		 			
  		 		}
  			}
  		}
  		response.sendRedirect("ViewPaymentVouchers.jsp");
  	}
  	
      }
  catch(Exception el){out.print(el);}
  	%>
  	</form>
</body>
</html>