1 14 package org.compiere.acct; 15 16 import java.math.*; 17 import java.sql.*; 18 19 import org.apache.log4j.Logger; 20 21 import org.compiere.util.Env; 22 import org.compiere.util.DB; 23 import org.compiere.model.*; 24 25 31 public class DocLine 32 { 33 39 public DocLine(String DocumentType, int TrxHeader_ID, int TrxLine_ID) 40 { 41 if (DocumentType == null) 42 throw new IllegalArgumentException ("DocLine - DocumentType is null"); 43 p_DocumentType = DocumentType; 44 m_TrxHeader_ID = TrxHeader_ID; 45 m_TrxLine_ID = TrxLine_ID; 46 } 48 49 protected Logger log = Logger.getLogger(getClass()); 50 51 52 protected String p_DocumentType = null; 53 54 private int m_TrxHeader_ID = 0; 55 56 private int m_TrxLine_ID = 0; 57 58 private int m_Line = 0; 59 60 61 private int m_C_UOM_ID = 0; 62 63 private BigDecimal m_qty = null; 64 65 66 67 private int m_C_Currency_ID = 0; 68 69 71 private BigDecimal m_AmtSourceDr = Env.ZERO; 72 73 private BigDecimal m_AmtSourceCr = Env.ZERO; 74 75 76 private BigDecimal m_AmtAcctDr = null; 77 private BigDecimal m_AmtAcctCr = null; 78 private int m_C_AcctSchema_ID = 0; 79 80 protected ProductInfo p_productInfo = null; 81 82 83 private Account m_account = null; 84 85 private int m_AD_Org_ID = 0; 87 private int m_C_BPartner_ID = 0; 88 private int m_M_Product_ID = 0; 89 private int m_AD_OrgTrx_ID = 0; 90 private int m_C_SalesRegion_ID = 0; 91 private int m_C_Project_ID = 0; 92 private int m_C_Campaign_ID = 0; 93 private int m_C_Activity_ID = 0; 94 private int m_C_LocFrom_ID = 0; 95 private int m_C_LocTo_ID = 0; 96 private int m_User1_ID = 0; 97 private int m_User2_ID = 0; 98 private int m_C_Charge_ID = 0; 100 private BigDecimal m_ChargeAmt = Env.ZERO; 101 102 private String m_description = null; 103 104 private int m_C_Tax_ID = 0; 105 106 private Timestamp m_DateAcct = null; 107 private Timestamp m_DateDoc = null; 108 109 private int m_M_AttributSetInstance_ID = 0; 110 111 112 113 118 public void loadAttributes (ResultSet rs, DocVO vo) 119 { 120 try 122 { 123 ResultSetMetaData rsmd = rs.getMetaData(); 124 for (int i = 1; i <= rsmd.getColumnCount(); i++) 125 { 126 String col = rsmd.getColumnName(i); 127 if (col.equalsIgnoreCase("AD_Org_ID")) 128 m_AD_Org_ID = rs.getInt(i); 129 else if (col.equalsIgnoreCase("C_BPartner_ID")) 130 m_C_BPartner_ID = rs.getInt(i); 131 else if (col.equalsIgnoreCase("M_Product_ID")) 132 m_M_Product_ID = rs.getInt(i); 133 else if (col.equalsIgnoreCase("AD_OrgTrx_ID")) 134 m_AD_OrgTrx_ID = rs.getInt(i); 135 else if (col.equalsIgnoreCase("C_SalesRegion_ID")) 136 m_C_SalesRegion_ID = rs.getInt(i); 137 else if (col.equalsIgnoreCase("C_Project_ID")) 138 m_C_Project_ID = rs.getInt(i); 139 else if (col.equalsIgnoreCase("C_Campaign_ID")) 140 m_C_Campaign_ID = rs.getInt(i); 141 else if (col.equalsIgnoreCase("C_Activity_ID")) 142 m_C_Activity_ID = rs.getInt(i); 143 else if (col.equalsIgnoreCase("C_LocFrom_ID")) 144 m_C_LocFrom_ID = rs.getInt(i); 145 else if (col.equalsIgnoreCase("C_LocTo_ID")) 146 m_C_LocTo_ID = rs.getInt(i); 147 else if (col.equalsIgnoreCase("User1_ID")) 148 m_User1_ID = rs.getInt(i); 149 else if (col.equalsIgnoreCase("User2_ID")) 150 m_User2_ID = rs.getInt(i); 151 else if (col.equalsIgnoreCase("Line")) 153 m_Line = rs.getInt(i); 154 else if (col.equalsIgnoreCase("Description")) 155 m_description = rs.getString(i); 156 else if (col.equalsIgnoreCase("C_Currency_ID")) 157 m_C_Currency_ID = rs.getInt(i); 158 else if (col.equalsIgnoreCase("C_UOM_ID")) 160 m_C_UOM_ID = rs.getInt(i); 161 else if (col.equalsIgnoreCase("Qty")) 162 m_qty = rs.getBigDecimal(i); 163 else if (col.equalsIgnoreCase("C_Tax_ID")) 165 m_C_Tax_ID = rs.getInt(i); 166 else if (col.equalsIgnoreCase("C_Charge_ID")) 167 m_C_Charge_ID = rs.getInt(i); 168 else if (col.equalsIgnoreCase("ChargeAmt")) 169 m_ChargeAmt = rs.getBigDecimal(i); 170 else if (col.equalsIgnoreCase("DateAcct")) 172 m_DateAcct = rs.getTimestamp(i); 173 else if (col.equalsIgnoreCase("DateDoc")) 174 m_DateDoc = rs.getTimestamp(i); 175 else if (col.equalsIgnoreCase("M_AttributSetInstance_ID")) 177 m_M_AttributSetInstance_ID = rs.getInt(i); 178 } } 180 catch (SQLException e) 181 { 182 log.error ("loadAttributes", e); 183 } 184 p_productInfo = new ProductInfo(m_M_Product_ID); 186 187 if (m_AD_Org_ID == 0) 189 m_AD_Org_ID = vo.AD_Org_ID; 190 if (m_C_Currency_ID == 0) 191 m_C_Currency_ID = vo.C_Currency_ID; 192 } 194 195 196 197 201 public void setC_Currency_ID (int C_Currency_ID) 202 { 203 m_C_Currency_ID = C_Currency_ID; 204 } 206 210 public int getC_Currency_ID () 211 { 212 return m_C_Currency_ID; 213 } 215 219 public void setAmount (BigDecimal sourceAmt) 220 { 221 m_AmtSourceDr = sourceAmt == null ? Env.ZERO : sourceAmt; 222 m_AmtSourceCr = Env.ZERO; 223 } 225 230 public void setAmount (BigDecimal amtSourceDr, BigDecimal amtSourceCr) 231 { 232 m_AmtSourceDr = amtSourceDr == null ? Env.ZERO : amtSourceDr; 233 m_AmtSourceCr = amtSourceCr == null ? Env.ZERO : amtSourceCr; 234 } 236 242 public void setConvertedAmt (int C_AcctSchema_ID, BigDecimal amtAcctDr, BigDecimal amtAcctCr) 243 { 244 m_C_AcctSchema_ID = C_AcctSchema_ID; 245 m_AmtAcctDr = amtAcctDr; 246 m_AmtAcctCr = amtAcctCr; 247 } 249 253 public BigDecimal getAmount() 254 { 255 return m_AmtSourceDr.subtract(m_AmtSourceCr); 256 } 258 262 public BigDecimal getAmtSourceDr() 263 { 264 return m_AmtSourceDr; 265 } 267 271 public BigDecimal getAmtSourceCr() 272 { 273 return m_AmtSourceCr; 274 } 276 280 public BigDecimal getAmtAcctDr() 281 { 282 return m_AmtAcctDr; 283 } 285 289 public BigDecimal getAmtAcctCr() 290 { 291 return m_AmtAcctCr; 292 } 294 298 public void setChargeAmt (BigDecimal chargeAmt) 299 { 300 m_ChargeAmt = chargeAmt == null ? Env.ZERO : chargeAmt; 301 } 303 307 public BigDecimal getChargeAmt() 308 { 309 return m_ChargeAmt; 310 } 312 313 314 318 public void setDateAcct (Timestamp dateAcct) 319 { 320 m_DateAcct = dateAcct; 321 } 323 327 public Timestamp getDateAcct () 328 { 329 return m_DateAcct; 330 } 332 336 public void setDateDoc (Timestamp dateDoc) 337 { 338 m_DateDoc = dateDoc; 339 } 341 345 public Timestamp getDateDoc () 346 { 347 return m_DateDoc; 348 } 350 351 352 356 public void setAccount (Account acct) 357 { 358 m_account = acct; 359 } 361 365 public Account getAccount() 366 { 367 return m_account; 368 } 370 376 public Account getChargeAccount (AcctSchema as, BigDecimal amount) 377 { 378 if (m_C_Charge_ID == 0) 379 return null; 380 381 int acct_index = 1; if (amount != null && amount.signum() < 0) 383 acct_index = 2; String sql = "SELECT CH_Expense_Acct, CH_Revenue_Acct FROM C_Charge_Acct WHERE C_Charge_ID=? AND C_AcctSchema_ID=?"; 385 int Account_ID = 0; 386 try 387 { 388 PreparedStatement pstmt = DB.prepareStatement(sql); 389 pstmt.setInt (1, m_C_Charge_ID); 390 pstmt.setInt (2, as.getC_AcctSchema_ID()); 391 ResultSet rs = pstmt.executeQuery(); 392 if (rs.next()) 393 Account_ID = rs.getInt(acct_index); 394 rs.close(); 395 pstmt.close(); 396 } 397 catch (SQLException e) 398 { 399 log.error ("getChargeAccount", e); 400 return null; 401 } 402 if (Account_ID == 0) 404 { 405 log.error ("getChargeAccount - NO account for C_Charge_ID=" + m_C_Charge_ID); 406 return null; 407 } 408 409 Account acct = Account.getAccount (Account_ID); 411 return acct; 412 } 414 415 416 420 public int getC_AcctSchema_ID() 421 { 422 return m_C_AcctSchema_ID; 423 } 425 429 public int getM_Product_ID() 430 { 431 return m_M_Product_ID; 432 } 434 438 public int getC_LocFrom_ID() 439 { 440 return m_C_LocFrom_ID; 441 } 443 447 public int getC_LocTo_ID() 448 { 449 return m_C_LocTo_ID; 450 } 452 456 public boolean isProduct() 457 { 458 return p_productInfo.isProduct(); 459 } 461 465 public boolean isBOM() 466 { 467 return p_productInfo.isBOM(); 468 } 470 474 public boolean isService() 475 { 476 return !p_productInfo.isProduct(); 477 } 479 483 public String getProductCategory() 484 { 485 return p_productInfo.getProductCategory(); 486 } 488 492 public boolean isRevenueRecognition() 493 { 494 return p_productInfo.isRevenueRecognition(); 495 } 497 501 public int getC_RevenueRecognition_ID() 502 { 503 return p_productInfo.getC_RevenueRecognition_ID(); 504 } 506 510 public int getC_UOM_ID() 511 { 512 return m_C_UOM_ID; 513 } 515 519 public void setQty (BigDecimal qty) 520 { 521 m_qty = qty == null ? Env.ZERO : qty; 522 } 524 528 public BigDecimal getQty() 529 { 530 return m_qty; 531 } 533 537 public String getDescription() 538 { 539 return m_description; 540 } 541 542 546 public int getC_Tax_ID() 547 { 548 return m_C_Tax_ID; 549 } 550 551 555 public int getLine() 556 { 557 return m_Line; 558 } 560 564 public int getAD_Org_ID() 565 { 566 return m_AD_Org_ID; 567 } 569 574 protected void setAD_Org_ID(int AD_Org_ID) 575 { 576 m_AD_Org_ID = AD_Org_ID; 577 } 579 583 public int getC_BPartner_ID() 584 { 585 return m_C_BPartner_ID; 586 } 588 592 public int getAD_OrgTrx_ID() 593 { 594 return m_AD_OrgTrx_ID; 595 } 597 602 public int getC_SalesRegion_ID() 603 { 604 return m_C_SalesRegion_ID; 605 } 607 611 public int getC_Project_ID() 612 { 613 return m_C_Project_ID; 614 } 616 620 public int getC_Campaign_ID() 621 { 622 return m_C_Campaign_ID; 623 } 625 629 public int getC_Activity_ID() 630 { 631 return m_C_Activity_ID; 632 } 634 638 public int getUser1_ID() 639 { 640 return m_User1_ID; 641 } 643 647 public int getUser2_ID() 648 { 649 return m_User2_ID; 650 } 652 656 public int getTrxLine_ID() 657 { 658 return m_TrxLine_ID; 659 } 661 665 protected int getC_Charge_ID() 666 { 667 return m_C_Charge_ID; 668 } 670 674 protected void setC_Charge_ID(int C_Charge_ID) 675 { 676 m_C_Charge_ID = C_Charge_ID; 677 } 679 683 public String toString() 684 { 685 StringBuffer sb = new StringBuffer ("DocLine=["); 686 sb.append(m_TrxLine_ID); 687 sb.append(",").append(m_description); 688 sb.append(",Qty=").append(m_qty); 689 sb.append(",Amt=").append(getAmount()); 690 sb.append("]"); 691 return sb.toString(); 692 } 694 } | Popular Tags |