1 14 package org.compiere.acct; 15 16 import java.math.*; 17 import java.sql.*; 18 19 import org.compiere.util.*; 20 import org.compiere.model.*; 21 22 28 public class DocLine_Cash extends DocLine 29 { 30 36 public DocLine_Cash (String DocumentType, int TrxHeader_ID, int TrxLine_ID) 37 { 38 super (DocumentType, TrxHeader_ID, TrxLine_ID); 39 } 41 42 private String m_CashType = ""; 43 44 public static final String CASHTYPE_CHARGE = "C"; 46 public static final String CASHTYPE_DIFFERENCE = "D"; 47 public static final String CASHTYPE_EXPENSE = "E"; 48 public static final String CASHTYPE_INVOICE = "I"; 49 public static final String CASHTYPE_RECEIPT = "R"; 50 public static final String CASHTYPE_TRANSFER = "T"; 51 52 private int m_C_BankAccount_ID = 0; 54 private int m_C_Invoice_ID = 0; 55 private int m_C_BPartner_ID = 0; 56 private int m_C_Currency_ID = -1; 58 private int m_AD_Org_ID = -1; 59 60 private BigDecimal m_Amount = Env.ZERO; 62 private BigDecimal m_DiscountAmt = Env.ZERO; 63 private BigDecimal m_WriteOffAmt = Env.ZERO; 64 65 69 public void setCashType(String CashType) 70 { 71 if (CashType != null) 72 m_CashType = CashType; 73 } 75 79 public String getCashType() 80 { 81 return m_CashType; 82 } 84 89 public void setReference (int C_BankAccount_ID, int C_Invoice_ID) 90 { 91 m_C_BankAccount_ID = C_BankAccount_ID; 92 m_C_Invoice_ID = C_Invoice_ID; 93 setReferenceInfo(); 94 } 96 100 public int getC_BankAccount_ID() 101 { 102 return m_C_BankAccount_ID; 103 } 105 109 public int getC_Invoice_ID() 110 { 111 return m_C_Invoice_ID; 112 } 114 120 public void setAmount(BigDecimal Amount, BigDecimal DiscountAmt, BigDecimal WriteOffAmt) 121 { 122 if (Amount != null) 123 m_Amount = Amount; 124 if (DiscountAmt != null) 125 m_DiscountAmt = DiscountAmt; 126 if (WriteOffAmt != null) 127 m_WriteOffAmt = WriteOffAmt; 128 setAmount(Amount); 130 } 132 136 public BigDecimal getAmount() 137 { 138 return m_Amount; 139 } 140 144 public BigDecimal getDiscountAmt() 145 { 146 return m_DiscountAmt; 147 } 148 152 public BigDecimal getWriteOffAmt() 153 { 154 return m_WriteOffAmt; 155 } 156 157 161 public int getC_Currency_ID() 162 { 163 if (m_C_BankAccount_ID == 0 && m_C_Invoice_ID == 0) 164 return super.getC_Currency_ID(); 165 166 if (m_C_Currency_ID == -1) 167 setReferenceInfo(); 168 return m_C_Currency_ID; 169 } 171 175 public int getAD_Org_ID() 176 { 177 if (m_C_BankAccount_ID == 0 && m_C_Invoice_ID == 0) 178 return super.getAD_Org_ID(); 179 180 if (m_AD_Org_ID == -1) 181 setReferenceInfo(); 182 return m_AD_Org_ID; 183 } 185 189 public int getC_BPartner_ID() 190 { 191 if (m_C_Invoice_ID == 0) 192 return super.getC_BPartner_ID(); 193 194 if (m_C_BPartner_ID == -1) 195 setReferenceInfo(); 196 return m_C_BPartner_ID; 197 } 199 205 private void setReferenceInfo() 206 { 207 m_C_Currency_ID = 0; 208 m_AD_Org_ID = 0; 209 m_C_BPartner_ID = 0; 210 211 String sql = null; 212 int parameter = 0; 213 if (m_C_BankAccount_ID != 0) 215 { 216 sql = "SELECT AD_Org_ID, C_Currency_ID, 0 FROM C_BankAccount WHERE C_BankAccount_ID=?"; 217 parameter = m_C_BankAccount_ID; 218 } 219 else if (m_C_Invoice_ID != 0) 220 { 221 sql = "SELECT AD_Org_ID, C_Currency_ID, C_BPartner_ID FROM C_Invoice WHERE C_Invoice_ID=?"; 222 parameter = m_C_Invoice_ID; 223 } 224 else 225 return; 226 227 try 228 { 229 PreparedStatement pstmt = DB.prepareStatement(sql); 230 pstmt.setInt(1, parameter); 231 ResultSet rs = pstmt.executeQuery(); 232 if (rs.next()) 233 { 234 m_AD_Org_ID = rs.getInt(1); 235 m_C_Currency_ID = rs.getInt(2); 236 m_C_BPartner_ID = rs.getInt(3); 237 } 238 rs.close(); 239 pstmt.close(); 240 } 241 catch (SQLException e) 242 { 243 log.error("setReferenceInfo", e); 244 } 245 } 247 } | Popular Tags |