Current File : //home/obabain/ms_obaba_in/editRecVoucherDA.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>
<%
try
{
	String vid=request.getParameter("vid");
	String payno=request.getParameter("payno");
	String acc=request.getParameter("account");
	String vdate=request.getParameter("paydate");
	String parti=request.getParameter("country");
	String cramt=request.getParameter("total2");
	String narr=request.getParameter("narr");
	String cashchq=null;
	String chqno=request.getParameter("chqno");
	String chqdate=request.getParameter("chqdate");
	String total=request.getParameter("gtotal");
	
	 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;
	  	
	  	a=request.getParameterValues("invid[]");
	  	b=request.getParameterValues("billamt[]");
	  	c=request.getParameterValues("typ[]");
	  	
	  	if(!payno.equals(""))
		 {
	  		int i=st.executeUpdate("update account_voucher_main set account='"+acc+"',voucher_date='"+vdate+"',particular='"+parti+"',credit_amt='"+cramt+"',narration='"+narr+"',createdby="+loginid+",cash_cheque='"+cashchq+"' where voucher_id="+vid+"");
	  		 if(!chqno.equals(""))
	  		 {
	  			 Statement stchq=con.createStatement();
	  			 ResultSet rq=stchq.executeQuery("select * from cheque_voucher where voucher_no="+vid+"");
	  			 if(rq.next())
	  			 {
	  				 Statement si=con.createStatement();
	  				 int q=si.executeUpdate("update cheque_voucher set chq_no='"+chqno+"',chq_date='"+chqdate+"' where voucher_no="+vid+"");
	  			 }
	  			 else
	  			 {
	  				 int l=st.executeUpdate("insert into cheque_voucher(chq_no,chq_date,created_date,voucher_no,voucher_type) values('"+chqno+"','"+chqdate+"',NOW(),'"+vid+"','Rec')");
	  			 }
	  		 }
	  		 else{
	  			 Statement stchq=con.createStatement();
	  			 ResultSet rq=stchq.executeQuery("select * from cheque_voucher where voucher_no="+vid+"");
	  			 if(rq.next())
	  			 {
	  				 Statement si=con.createStatement();
	  				 int qd=si.executeUpdate("delete from cheque_voucher where voucher_no="+vid+"");
	  			 }
	  			 
	  		 }
	  		 Statement st2=con.createStatement();
	  		 ResultSet rs1=st2.executeQuery("SELECT * FROM account_voucher_sub where voucher_id="+vid+" and type='B'");
	  		 while(rs1.next())
	  		 {
	  			 String damt=rs1.getString("debit_amt");
	  			 String invoiceId=rs1.getString("bill_no");
	  			 Statement stmt=con.createStatement();
	  			 ResultSet result=stmt.executeQuery("select * from account_ledger where l_id="+rs1.getString("particular")+"");
	  			 while(result.next())
	  			 {
	  				 String type=result.getString("type");
	  				 if(type.equals("3"))
	  				 {
	  					 Statement stinv=con.createStatement();
	  					 int inv=stinv.executeUpdate("update ip_sales_invoice set received_amt=received_amt-"+damt+" where sinvoice_id="+invoiceId+""); 
	  				 }
	  				 else if(type.equals("1"))
	  				 {
	  					 Statement stj=con.createStatement();
	  					 int inv=stj.executeUpdate("update journalentry set paid_amt=paid_amt-"+damt+" where journal_id="+invoiceId+""); 
	  				 }
	  			 }
	  		 }
	  		 Statement st1=con.createStatement();
	  		 int k=st1.executeUpdate("delete from account_voucher_sub where voucher_id="+vid+"");
	  		for(int j=2;j<=c.length-1;j++)
	  		{
			 
			 
			 if(c[j].equals("B"))
	  			{
				 
	  				if(a[j].equals(""))
	  				{
	  					System.out.print("wb");
	  					int x=st.executeUpdate("insert into account_voucher_sub(voucher_id,particular,voucher_date,bill_no,debit_amt,crdr_type,voucher_type,type) values("+vid+",'"+parti+"','"+vdate+"',0,"+total+",'Dr','receipt','WB')");
	  					
	  				}
	  				else
	  				{
	  					
	  			int y=st.executeUpdate("insert into account_voucher_sub(voucher_id,particular,voucher_date,bill_no,debit_amt,crdr_type,voucher_type,type) values("+vid+",'"+parti+"','"+vdate+"','"+a[j]+"',"+b[j]+",'Dr','receipt','"+c[j]+"')");
	  		
	  			}
	  		}
			 else
			 {
				 int z=st.executeUpdate("insert into account_voucher_sub(voucher_id,particular,voucher_date,bill_no,debit_amt,crdr_type,voucher_type,type) values("+vid+",'"+acc+"','"+vdate+"','"+a[j]+"',"+b[j]+",'Dr','receipt','"+c[j]+"')");
		  			
			 }
			 
			 if(c[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("3")) 		 			
	  		 		{
	  		 			
	  		 			ResultSet ra=st.executeQuery("select * from ip_sales_invoice where sinvoice_id="+a[j]+" and supplier_id="+supplid+"");
	  		 			
	  		 			while(ra.next())
	  		 			{
	  		 				paid_amt=Double.parseDouble(ra.getString("received_amt"));
	  		 			}
	  		 			 amt=paid_amt+Double.parseDouble(b[j]);
	  		 			
	  		 			int u=st.executeUpdate("update ip_sales_invoice set received_amt="+amt+" where sinvoice_id="+a[j]+" and supplier_id="+supplid+"");
	  		 		}
	  				else if(particular.equals("1"))
	  		 		{
	  		 			ResultSet ra=st.executeQuery("select * from journalentry where journal_id="+a[j]+"");
	  		 			while(ra.next())
	  		 			{
	  		 				paid_amt=Double.parseDouble(ra.getString("paid_amt"));
	  		 			}
	  		 			 amt=paid_amt+Double.parseDouble(b[j]);
	  		 			int u=st.executeUpdate("update journalentry set paid_amt="+amt+" where journal_id="+a[j]+"");
	  		 			
	  		 		}
	  			}
			 
	  		}
	  		
		 }
response.sendRedirect("editRecVoucher.jsp?Id="+vid+"");	
}
	  	catch(Exception el){out.print(el);}
	  	%>
</body>
</html>