1 14 package org.compiere.model; 15 16 import java.sql.*; 17 import java.util.*; 18 import java.math.*; 19 20 import org.compiere.util.*; 21 import java.io.*; 22 23 29 public final class MAllocation implements Serializable 30 { 31 37 public MAllocation (int type, int Record_ID) 38 { 39 String sql = "SELECT * FROM C_Allocation WHERE "; 40 if (type == TYPE_Invoice) 41 sql += "C_Invoice_ID=?"; 42 else if (type == TYPE_Order) 43 sql += "C_Order_ID=?"; 44 else if (type == TYPE_Payment) 45 sql += "C_Payment_ID=?"; 46 else if (type == TYPE_CashLine) 47 sql += "C_CashLine_ID=?"; 48 else 49 return; 50 51 try 53 { 54 PreparedStatement pstmt = DB.prepareStatement(sql.toString()); 55 pstmt.setInt(1, Record_ID); 56 ResultSet rs = pstmt.executeQuery(); 57 while (rs.next()) 58 { 59 int C_Invoice_ID = rs.getInt("C_Invoice_ID"); 60 if (!rs.wasNull()) 61 m_listInvoices.add(new Integer (C_Invoice_ID)); 62 int C_Order_ID = rs.getInt("C_Order_ID"); 64 if (!rs.wasNull()) 65 m_listOrders.add(new Integer (C_Order_ID)); 66 int C_Payment_ID = rs.getInt("C_Payment_ID"); 68 if (!rs.wasNull()) 69 m_listPayments.add(new Integer (C_Payment_ID)); 70 int C_CashLine_ID = rs.getInt("C_CashLine_ID"); 72 if (!rs.wasNull()) 73 m_listCashLines.add(new Integer (C_CashLine_ID)); 74 BigDecimal temp = rs.getBigDecimal("Amount"); 76 if (temp != null) 77 m_Amount = m_Amount.add(temp); 78 temp = rs.getBigDecimal("DiscountAmt"); 79 if (temp != null) 80 m_DiscountAmt = m_DiscountAmt.add(temp); 81 temp = rs.getBigDecimal("WriteOffAmt"); 82 if (temp != null) 83 m_WriteOffAmt = m_WriteOffAmt.add(temp); 84 } 85 rs.close(); 86 pstmt.close(); 87 } 88 catch (SQLException e) 89 { 90 Log.error ("MAllocation.Constructor", e); 91 } 92 } 94 95 private ArrayList m_listInvoices = new ArrayList(); 96 97 private ArrayList m_listOrders = new ArrayList(); 98 99 private ArrayList m_listPayments = new ArrayList(); 100 101 private ArrayList m_listCashLines = new ArrayList(); 102 103 BigDecimal m_Amount = new BigDecimal(0.0); 104 BigDecimal m_DiscountAmt = new BigDecimal(0.0); 105 BigDecimal m_WriteOffAmt = new BigDecimal(0.0); 106 107 108 public final static int TYPE_Invoice = 1; 109 public final static int TYPE_Order = 2; 110 public final static int TYPE_Payment = 3; 111 public final static int TYPE_CashLine = 4; 112 113 116 public void dispose() 117 { 118 if (m_listInvoices != null) 119 m_listInvoices.clear(); 120 m_listInvoices = null; 121 if (m_listOrders != null) 122 m_listOrders.clear(); 123 m_listOrders = null; 124 if (m_listPayments != null) 125 m_listPayments.clear(); 126 m_listPayments = null; 127 if (m_listCashLines != null) 128 m_listCashLines.clear(); 129 m_listCashLines = null; 130 } 132 136 public ArrayList getInvoiceIDs() 137 { 138 return m_listInvoices; 139 } 141 145 public ArrayList getOrderIDs() 146 { 147 return m_listOrders; 148 } 150 154 public ArrayList getPaymentIDs() 155 { 156 return m_listPayments; 157 } 159 163 public ArrayList getCashLineIDs() 164 { 165 return m_listCashLines; 166 } 168 172 public BigDecimal getAmount() 173 { 174 return m_Amount; 175 } 177 181 public BigDecimal getDiscountAmt() 182 { 183 return m_DiscountAmt; 184 } 186 190 public BigDecimal getWriteOffAmt() 191 { 192 return m_WriteOffAmt; 193 } 195 196 197 218 public static int createAllocation (Properties ctx, int WindowNo, 219 int AD_Client_ID, int AD_Org_ID, 220 int C_BPartner_ID, int C_Order_ID, int C_Invoice_ID, int C_Payment_ID, int C_CashLine_ID, 221 int AllocationNo, int C_Currency_ID, Timestamp DateTrx, boolean IsManual, 222 BigDecimal Amount, BigDecimal DiscountAmt, BigDecimal WriteOffAmt) 223 { 224 StringBuffer sql = new StringBuffer ("INSERT INTO C_Allocation " 225 + "(C_Allocation_ID,AD_Client_ID,AD_Org_ID, " 226 + "IsActive,Created,CreatedBy,Updated,UpdatedBy, " 227 + "AllocationNo,C_Currency_ID,DateTrx,IsManual, " 228 + "C_BPartner_ID,C_Invoice_ID,C_Order_ID,C_Payment_ID,C_CashLine_ID, " 229 + "Amount,DiscountAmt,WriteOffAmt, " 230 + "Processed,Posted) VALUES ("); 231 Env.setContext(ctx, WindowNo, "AD_Client_ID", AD_Client_ID); int C_Allocation_ID = DB.getKeyNextNo(ctx, WindowNo, "C_Allocation"); 234 int user = Env.getContextAsInt(ctx, "#AD_User_ID"); 235 sql.append(C_Allocation_ID).append(","); 237 sql.append(AD_Client_ID).append(",").append(AD_Org_ID); 238 sql.append(",'Y',SysDate,").append(user).append(",SysDate,").append(user).append(","); 239 sql.append(AllocationNo).append(","); 241 sql.append(C_Currency_ID).append(","); 242 sql.append(DB.TO_DATE(DateTrx, true)).append(","); 243 sql.append(IsManual ? "'Y'," : "'N',"); 244 if (C_BPartner_ID == 0) 246 sql.append("NULL,"); 247 else 248 sql.append(C_BPartner_ID).append(","); 249 if (C_Invoice_ID == 0) 250 sql.append("NULL,"); 251 else 252 sql.append(C_Invoice_ID).append(","); 253 if (C_Order_ID == 0) 254 sql.append("NULL,"); 255 else 256 sql.append(C_Order_ID).append(","); 257 if (C_Payment_ID == 0) 258 sql.append("NULL,"); 259 else 260 sql.append(C_Payment_ID).append(","); 261 if (C_CashLine_ID == 0) 262 sql.append("NULL,"); 263 else 264 sql.append(C_CashLine_ID).append(","); 265 if (Amount == null) 267 sql.append("0,"); 268 else 269 sql.append(Amount).append(","); 270 if (DiscountAmt == null) 271 sql.append("0,"); 272 else 273 sql.append(DiscountAmt).append(","); 274 if (WriteOffAmt == null) 275 sql.append("0,"); 276 else 277 sql.append(WriteOffAmt).append(","); 278 sql.append("'Y','N')"); 280 int no = DB.executeUpdate(sql.toString()); 282 if (no == 1) 284 Log.trace(Log.l3_Util, "MAllocation.createAllocation - " + C_Allocation_ID); 285 else 286 { 287 Log.error("MAllocation.createAllocation - Not Inserted - " + C_Allocation_ID); 288 C_Allocation_ID = 0; 289 } 290 return C_Allocation_ID; 291 } 293 } | Popular Tags |