1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.math.*; 19 20 import org.compiere.util.*; 21 22 28 public class MJournal extends X_GL_Journal 29 { 30 public MJournal (Properties ctx, int GL_Journal_ID) 31 { 32 super (ctx, GL_Journal_ID); 33 if (GL_Journal_ID == 0) 34 { 35 setCurrencyRate (Env.ONE); 42 setCurrencyRateType (CURRENCYRATETYPE_Spot); 43 setDateAcct (new Timestamp(System.currentTimeMillis())); 44 setDateDoc (new Timestamp(System.currentTimeMillis())); 45 setDocAction (DOCACTION_Process); 47 setDocStatus (DOCSTATUS_Drafted); 48 setPostingType (POSTINGTYPE_Actual); 51 setTotalCr (Env.ZERO); 52 setTotalDr (Env.ZERO); 53 setIsApproved (false); 54 setIsPrinted (false); 55 setPosted (false); 56 setProcessed(false); 57 } 58 } 60 public MJournal (Properties ctx, ResultSet rs) 61 { 62 super (ctx, rs); 63 } 65 70 public void setClientOrg (int AD_Client_ID, int AD_Org_ID) 71 { 72 super.setClientOrg(AD_Client_ID, AD_Org_ID); 73 } 75 80 public void setDateAcct (Timestamp DateAcct) 81 { 82 super.setDateAcct(DateAcct); 83 if (DateAcct == null) 84 return; 85 if (getC_Period_ID() != 0) 86 return; 87 int C_Period_ID = MPeriod.getC_Period_ID(getCtx(), DateAcct); 88 if (C_Period_ID == 0) 89 log.warn("setDateAcct - Period not found"); 90 else 91 setC_Period_ID(C_Period_ID); 92 } 94 98 public void setDocumentNo (String DocumentNo) 99 { 100 if (DocumentNo == null || DocumentNo.length() == 0) 101 return; 102 super.setDocumentNo(DocumentNo); 103 } 105 public void setGL_JournalBatch_ID (int GL_JournalBatch_ID) 106 { 107 super.setGL_JournalBatch_ID(GL_JournalBatch_ID); 108 } 109 public void setC_AcctSchema_ID (int C_AcctSchema_ID) 110 { 111 super.setC_AcctSchema_ID (C_AcctSchema_ID); 112 } 113 114 120 public void setCurrency (int C_Currency_ID, String CurrencyRateType, BigDecimal CurrencyRate) 121 { 122 if (C_Currency_ID != 0) 123 setC_Currency_ID(C_Currency_ID); 124 if (CurrencyRateType != null && CurrencyRateType.length() != 0) 125 setCurrencyRateType(CurrencyRateType); 126 if (CurrencyRate != null && CurrencyRate.compareTo(Env.ZERO) == 0) 127 setCurrencyRate(CurrencyRate); 128 } 130 131 135 public boolean save() 136 { 137 if (getDocumentNo() == null) 138 { 139 String DocumentNo = DB.getDocumentNo (getAD_Client_ID (), getC_DocType_ID ()); 140 setDocumentNo (DocumentNo); 141 } 142 return super.save(); 143 } 145 146 147 151 public MJournalLine[] getLines() 152 { 153 ArrayList list = new ArrayList(); 154 String sql = "SELECT * FROM GL_JournalLine WHERE GL_Journal_ID=? ORDER BY Line"; 155 PreparedStatement pstmt = null; 156 try 157 { 158 pstmt = DB.prepareStatement(sql); 159 pstmt.setInt(1, getGL_Journal_ID()); 160 ResultSet rs = pstmt.executeQuery(); 161 while (rs.next()) 162 list.add(new MJournalLine (getCtx(), rs)); 163 rs.close(); 164 pstmt.close(); 165 pstmt = null; 166 } 167 catch (SQLException ex) 168 { 169 log.error("getLines", ex); 170 } 171 try 172 { 173 if (pstmt != null) 174 pstmt.close(); 175 } 176 catch (SQLException ex1) 177 { 178 } 179 pstmt = null; 180 MJournalLine[] retValue = new MJournalLine[list.size()]; 182 list.toArray(retValue); 183 return retValue; 184 } 186 191 public int copyLinesFrom (MJournal fromJournal) 192 { 193 if (isProcessed() || fromJournal == null) 194 return 0; 195 int count = 0; 196 MJournalLine[] fromLines = fromJournal.getLines(); 197 for (int i = 0; i < fromLines.length; i++) 198 { 199 MJournalLine toLine = new MJournalLine (getCtx(), 0); 200 PO.copyValues(fromLines[i], toLine, getAD_Client_ID(), getAD_Org_ID()); 201 toLine.setGL_Journal_ID(getGL_Journal_ID()); 202 toLine.setDateAcct(getDateAcct()); 203 toLine.setIsGenerated(true); 204 if (toLine.save()) 205 count++; 206 } 207 if (fromLines.length != count) 208 log.error("copyLinesFrom - Line difference - JournalLines=" + fromLines.length + " <> Saved=" + count); 209 210 return count; 211 } 213 } | Popular Tags |