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_GLJournal extends Doc 33 { 34 38 protected Doc_GLJournal(int AD_Client_ID) 39 { 40 super(AD_Client_ID); 41 } 42 43 private String m_PostingType = Fact.POST_Actual; 44 45 49 public String getTableName() 50 { 51 return "GL_Journal"; 52 } 54 58 public int getAD_Table_ID() 59 { 60 return 224; 61 } 63 68 protected boolean loadDocumentDetails (ResultSet rs) 69 { 70 loadDocumentType(); try 72 { 73 m_PostingType = rs.getString ("PostingType"); 74 } 75 catch (SQLException ex) 76 { 77 log.error("loadDocumentDetails - load PostingType", ex); 78 } 79 p_lines = loadLines(); 81 log.debug("Lines=" + p_lines.length); 82 return true; 83 } 85 86 90 private DocLine[] loadLines() 91 { 92 ArrayList list = new ArrayList(); 93 String sql = "SELECT jl.GL_JournalLine_ID,jl.AD_Client_ID,jl.AD_Org_ID," + " jl.Line,jl.Description," + " jl.C_Currency_ID,jl.AmtSourceDr,jl.AmtSourceCr," + " jl.CurrencyRateType,jl.CurrencyRate," + " jl.DateAcct,jl.AmtAcctDr,jl.AmtAcctCr," + " jl.C_UOM_ID,jl.Qty," + " vc.C_AcctSchema_ID,vc.C_ValidCombination_ID," + " vc.Account_ID,vc.M_Product_ID,vc.C_BPartner_ID," + " vc.AD_OrgTrx_ID,vc.C_LocFrom_ID,vc.C_LocTo_ID," 102 + " vc.C_SalesRegion_ID,vc.C_Project_ID,vc.C_Campaign_ID," 103 + " vc.C_Activity_ID,vc.User1_ID,vc.User2_ID " 104 + "FROM C_ValidCombination vc, GL_JournalLine jl " 106 + "WHERE vc.C_ValidCombination_ID=jl.C_ValidCombination_ID" 107 + " AND jl.GL_Journal_ID=?" 108 + " AND jl.IsActive='Y' AND vc.IsFullyQualified='Y' " 109 + "ORDER BY jl.Line"; 110 try 111 { 112 PreparedStatement pstmt = DB.prepareStatement(sql); 113 pstmt.setInt(1, p_vo.Record_ID); 114 ResultSet rs = pstmt.executeQuery(); 115 while (rs.next()) 117 { 118 int Line_ID = rs.getInt(1); 119 DocLine docLine = new DocLine (p_vo.DocumentType, p_vo.Record_ID, Line_ID); 120 docLine.loadAttributes (rs, p_vo); 121 BigDecimal AmtSourceDr = rs.getBigDecimal(7); 123 BigDecimal AmtSourceCr = rs.getBigDecimal(8); 124 docLine.setAmount (AmtSourceDr, AmtSourceCr); 125 int C_AcctSchema_ID = rs.getInt(16); 127 BigDecimal AmtAcctDr = rs.getBigDecimal(12); 128 BigDecimal AmtAcctCr = rs.getBigDecimal(13); 129 docLine.setConvertedAmt (C_AcctSchema_ID, AmtAcctDr, AmtAcctCr); 130 int C_ValidCombination_ID = rs.getInt(17); 132 Account acct = new Account(C_ValidCombination_ID); 133 docLine.setAccount (acct); 134 docLine.setAD_Org_ID (acct.getAD_Org_ID()); 136 list.add(docLine); 138 } 139 rs.close(); 141 pstmt.close(); 142 } 143 catch (SQLException e) 144 { 145 log.error ("loadLines - SQL=" + sql, e); 146 } 147 148 int size = list.size(); 150 DocLine[] dl = new DocLine[size]; 151 list.toArray(dl); 152 return dl; 153 } 155 156 157 161 public BigDecimal getBalance() 162 { 163 BigDecimal retValue = Env.ZERO; 164 StringBuffer sb = new StringBuffer (" ["); 165 for (int i = 0; i < p_lines.length; i++) 167 { 168 retValue = retValue.add(p_lines[i].getAmount()); 169 sb.append("+").append(p_lines[i].getAmount()); 170 } 171 sb.append("]"); 172 log.debug(toString() + " Balance=" + retValue + sb.toString()); 174 return retValue; 175 } 177 187 public Fact createFact (AcctSchema as) 188 { 189 Fact fact = new Fact (this, as, m_PostingType); 191 192 if (p_vo.DocumentType.equals(DocVO.DOCTYPE_GLJournal)) 194 { 195 for (int i = 0; i < p_lines.length; i++) 197 { 198 if (p_lines[i].getC_AcctSchema_ID () == as.getC_AcctSchema_ID ()) 199 { 200 FactLine line = fact.createLine (p_lines[i], 201 p_lines[i].getAccount (), 202 p_vo.C_Currency_ID, 203 p_lines[i].getAmtSourceDr (), 204 p_lines[i].getAmtSourceCr ()); 205 } 206 } } 208 else 209 { 210 p_vo.Error = "DocumentType unknown: " + p_vo.DocumentType; 211 log.error("createFact - " + p_vo.Error); 212 fact = null; 213 } 214 return fact; 215 } 217 } | Popular Tags |