1 14 package org.compiere.acct; 15 16 import java.math.*; 17 import java.util.*; 18 import java.sql.*; 19 20 import org.compiere.util.*; 21 import org.compiere.model.*; 22 23 32 public class Doc_Bank extends Doc 33 { 34 38 protected Doc_Bank(int AD_Client_ID) 39 { 40 super(AD_Client_ID); 41 } 42 43 47 public String getTableName() 48 { 49 return "C_BankStatement"; 50 } 52 56 public int getAD_Table_ID() 57 { 58 return 392; 59 } 61 66 protected boolean loadDocumentDetails (ResultSet rs) 67 { 68 p_vo.DocumentType = DocVO.DOCTYPE_BankStatement; 69 try 70 { 71 p_vo.DateDoc = rs.getTimestamp("StatementDate"); 72 p_vo.Amounts[Doc.AMTTYPE_Gross] = rs.getBigDecimal("StatementDifference"); 74 if (p_vo.Amounts[Doc.AMTTYPE_Gross] == null) 75 p_vo.Amounts[Doc.AMTTYPE_Gross] = Env.ZERO; 76 } 77 catch (SQLException e) 78 { 79 log.error("loadDocumentDetails", e); 80 } 81 82 setBankAccountInfo(); 84 loadDocumentType(); 86 p_lines = loadLines(); 88 log.debug("Lines=" + p_lines.length); 89 return true; 90 } 92 95 private void setBankAccountInfo() 96 { 97 String sql = "SELECT C_Currency_ID FROM C_BankAccount WHERE C_BankAccount_ID=?"; 98 try 99 { 100 PreparedStatement pstmt = DB.prepareStatement(sql); 101 pstmt.setInt(1, p_vo.C_BankAccount_ID); 102 ResultSet rs = pstmt.executeQuery(); 103 if (rs.next()) 104 p_vo.C_Currency_ID = rs.getInt(1); 105 rs.close(); 106 pstmt.close(); 107 } 108 catch (SQLException e) 109 { 110 log.error("setBankAccountInfo", e); 111 } 112 } 114 123 private DocLine[] loadLines() 124 { 125 ArrayList list = new ArrayList(); 126 String sql = "SELECT * FROM C_BankStatementLine WHERE C_BankStatement_ID=? ORDER BY Line"; 127 try 128 { 129 PreparedStatement pstmt = DB.prepareStatement(sql); 130 pstmt.setInt(1, p_vo.Record_ID); 131 ResultSet rs = pstmt.executeQuery(); 132 while (rs.next()) 134 { 135 int Line_ID = rs.getInt("C_BankStatementLine_ID"); 136 DocLine_Bank docLine = new DocLine_Bank (p_vo.DocumentType, p_vo.Record_ID, Line_ID); 137 docLine.loadAttributes(rs, p_vo); 138 docLine.setDateDoc(rs.getTimestamp("ValutaDate")); 139 docLine.setC_Payment_ID(rs.getInt("C_Payment_ID")); 140 docLine.setIsReversal(rs.getString("IsReversal")); 141 docLine.setAmount(rs.getBigDecimal("StmtAmt"), rs.getBigDecimal("InterestAmt"), rs.getBigDecimal("TrxAmt")); 142 list.add(docLine); 143 } 144 rs.close(); 146 pstmt.close(); 147 } 148 catch (SQLException e) 149 { 150 log.error ("loadLines", e); 151 } 152 153 DocLine[] dl = new DocLine[list.size()]; 155 list.toArray(dl); 156 return dl; 157 } 159 160 161 165 public BigDecimal getBalance() 166 { 167 BigDecimal retValue = Env.ZERO; 168 StringBuffer sb = new StringBuffer (" ["); 169 retValue = retValue.add(getAmount(Doc.AMTTYPE_Gross)); 171 sb.append(getAmount(Doc.AMTTYPE_Gross)); 172 for (int i = 0; i < p_lines.length; i++) 174 { 175 BigDecimal lineBalance = ((DocLine_Bank)p_lines[i]).getStmtAmt(); 176 retValue = retValue.subtract(lineBalance); 177 sb.append("-").append(lineBalance); 178 } 179 sb.append("]"); 180 log.debug(toString() + " Balance=" + retValue + sb.toString()); 182 return retValue; 183 } 185 197 public Fact createFact (AcctSchema as) 198 { 199 Fact fact = new Fact(this, as, Fact.POST_Actual); 201 202 204 for (int i = 0; i < p_lines.length; i++) 206 { 207 DocLine_Bank line = (DocLine_Bank)p_lines[i]; 208 fact.createLine(line, 210 getAccount(Doc.ACCTTYPE_BankAsset, as), 211 line.getC_Currency_ID(), line.getStmtAmt()); 212 fact.createLine(line, 214 getAccount(Doc.ACCTTYPE_BankInTransit, as), 215 line.getC_Currency_ID(), line.getTrxAmt().negate()); 216 fact.createLine(line, 218 line.getChargeAccount(as, line.getChargeAmt().negate()), 219 line.getC_Currency_ID(), line.getChargeAmt().negate(), null); 220 if (line.getInterestAmt().signum() < 0) 222 fact.createLine(line, 223 getAccount(Doc.ACCTTYPE_InterestExp, as), getAccount(Doc.ACCTTYPE_InterestExp, as), 224 line.getC_Currency_ID(), line.getInterestAmt().negate()); 225 else 226 fact.createLine(line, 227 getAccount(Doc.ACCTTYPE_InterestExp, as), getAccount(Doc.ACCTTYPE_InterestRev, as), 228 line.getC_Currency_ID(), line.getInterestAmt().negate()); 229 fact.createTaxCorrection(); 231 } 232 return fact; 233 } 235 } | Popular Tags |