1 14 package org.compiere.model; 15 16 import java.sql.*; 17 import java.util.*; 18 19 import org.compiere.util.*; 20 import java.io.*; 21 22 28 public final class Account implements Serializable 29 { 30 33 public Account() 34 { 35 } 37 41 public Account (int C_ValidCombination_ID) 42 { 43 if (C_ValidCombination_ID == 0) 44 return; 45 load(C_ValidCombination_ID); 46 } 48 49 50 private int C_ValidCombination_ID = 0; 51 52 private int C_AcctSchema_ID = 0; 53 55 private int AD_Client_ID = 0; 56 57 private int AD_Org_ID = 0; 58 59 private int Account_ID = 0; 60 61 private int M_Product_ID = 0; 62 63 private int C_BPartner_ID = 0; 64 65 private int AD_OrgTrx_ID = 0; 66 67 private int C_LocFrom_ID = 0; 68 69 private int C_LocTo_ID = 0; 70 71 private int C_SalesRegion_ID = 0; 72 73 private int C_Project_ID = 0; 74 75 private int C_Channel_ID = 0; 76 77 private int C_Campaign_ID = 0; 78 79 private int C_Activity_ID = 0; 80 81 private int User1_ID = 0; 82 83 private int User2_ID = 0; 84 private String alias = ""; 86 private String combination = ""; 87 private String description = ""; 88 private boolean active = true; 89 private int updatedBy = 0; 90 private boolean fullyQualified = false; 91 92 93 94 private char m_AcctType = ' '; 95 96 private Boolean m_IsValid = null; 97 98 private int m_OldAccount_ID = 0; 99 100 101 private boolean m_changed = true; 102 103 104 108 public void load (int C_ValidCombination_ID) 109 { 110 String sql = "SELECT AD_CLIENT_ID,AD_ORG_ID, ISACTIVE, UPDATED,UPDATEDBY," + "ALIAS, COMBINATION, DESCRIPTION, ISFULLYQUALIFIED," + "C_ACCTSCHEMA_ID, ACCOUNT_ID, M_PRODUCT_ID, C_BPARTNER_ID," + "AD_ORGTRX_ID, C_LOCFROM_ID, C_LOCTO_ID, C_SALESREGION_ID," + "C_PROJECT_ID, C_CAMPAIGN_ID, C_ACTIVITY_ID, USER1_ID,USER2_ID " + "FROM C_ValidCombination " 116 + "WHERE C_ValidCombination_ID=?"; 117 try 118 { 119 PreparedStatement pstmt = DB.prepareStatement(sql); 120 pstmt.setInt(1, C_ValidCombination_ID); 121 ResultSet rs = pstmt.executeQuery(); 122 if (rs.next()) 123 { 124 setAD_Client_ID(rs.getInt(1)); 126 setAD_Org_ID(rs.getInt(2)); 127 setActive(rs.getString(3).equals("Y")); 128 setUpdatedBy(rs.getInt(5)); 130 setAlias(rs.getString(6)); 132 setCombination(rs.getString(7)); 133 setDescription(rs.getString(8)); 134 setFullyQualified(rs.getString(9).equals("Y")); 135 setC_AcctSchema_ID(rs.getInt(10)); 137 setAccount_ID(rs.getInt(11)); 138 setM_Product_ID(rs.getInt(12)); 139 setC_BPartner_ID(rs.getInt(13)); 140 setAD_OrgTrx_ID(rs.getInt(14)); 142 setC_LocFrom_ID(rs.getInt(15)); 143 setC_LocTo_ID(rs.getInt(16)); 144 setC_SalesRegion_ID(rs.getInt(17)); 145 setC_Project_ID(rs.getInt(18)); 147 setC_Campaign_ID(rs.getInt(19)); 148 setC_Activity_ID(rs.getInt(20)); 149 setUser1_ID(rs.getInt(21)); 150 setUser2_ID(rs.getInt(22)); 151 setC_ValidCombination_ID(C_ValidCombination_ID); 153 m_changed = false; 154 } 155 else 156 Log.error("Account.getAccount - " + C_ValidCombination_ID + " not found"); 157 rs.close(); 158 pstmt.close(); 159 } 160 catch (SQLException e) 161 { 162 C_ValidCombination_ID = 0; 163 Log.error ("Account.load", e); 164 } 165 } 167 173 public static Account getDefault (int C_AcctSchema_ID, boolean optionalNull) 174 { 175 AcctSchema acctSchema = new AcctSchema(C_AcctSchema_ID); 176 return getDefault(acctSchema, optionalNull); 177 } 179 185 public static Account getDefault (AcctSchema acctSchema, boolean optionalNull) 186 { 187 Account vc = new Account(); 188 vc.setC_AcctSchema_ID(acctSchema.getC_AcctSchema_ID()); 189 ArrayList list = acctSchema.getAcctSchemaElementList(); 191 for (int i = 0; i < list.size(); i++) 192 { 193 AcctSchemaElement ase = (AcctSchemaElement)list.get(i); 194 String segmentType = ase.getSegmentType(); 195 int defaultValue = ase.getDefaultValue(); 196 boolean setValue = ase.isMandatory() || (!ase.isMandatory() && !optionalNull); 197 if (segmentType.equals(AcctSchemaElement.SEGMENT_Org)) 199 vc.setAD_Org_ID(defaultValue); 200 else if (segmentType.equals(AcctSchemaElement.SEGMENT_Account)) 201 vc.setAccount_ID(defaultValue); 202 else if (segmentType.equals(AcctSchemaElement.SEGMENT_BPartner) && setValue) 203 vc.setC_BPartner_ID(defaultValue); 204 else if (segmentType.equals(AcctSchemaElement.SEGMENT_Product) && setValue) 205 vc.setM_Product_ID(defaultValue); 206 else if (segmentType.equals(AcctSchemaElement.SEGMENT_Activity) && setValue) 207 vc.setC_Activity_ID(defaultValue); 208 else if (segmentType.equals(AcctSchemaElement.SEGMENT_LocationFrom) && setValue) 209 vc.setC_LocFrom_ID(defaultValue); 210 else if (segmentType.equals(AcctSchemaElement.SEGMENT_LocationTo) && setValue) 211 vc.setC_LocTo_ID(defaultValue); 212 else if (segmentType.equals(AcctSchemaElement.SEGMENT_Campaign) && setValue) 213 vc.setC_Campaign_ID(defaultValue); 214 else if (segmentType.equals(AcctSchemaElement.SEGMENT_OrgTrx) && setValue) 215 vc.setAD_OrgTrx_ID(defaultValue); 216 else if (segmentType.equals(AcctSchemaElement.SEGMENT_Project) && setValue) 217 vc.setC_Project_ID(defaultValue); 218 else if (segmentType.equals(AcctSchemaElement.SEGMENT_SalesRegion) && setValue) 219 vc.setC_SalesRegion_ID(defaultValue); 220 else if (segmentType.equals(AcctSchemaElement.SEGMENT_User1) && setValue) 221 vc.setUser1_ID(defaultValue); 222 else if (segmentType.equals(AcctSchemaElement.SEGMENT_User2) && setValue) 223 vc.setUser2_ID(defaultValue); 224 } 225 Log.trace(Log.l3_Util, "Account.getDefault - Client_ID=" 226 + vc.getAD_Client_ID() + ", Org_ID=" + vc.getAD_Org_ID(), 227 "AcctSchema_ID=" + vc.getC_AcctSchema_ID() + ", Account_ID=" + vc.getAccount_ID()); 228 return vc; 229 } 231 236 public static Account getAccount (int C_ValidCombination_ID) 237 { 238 return new Account(C_ValidCombination_ID); 239 } 241 247 public boolean save (int AD_Client_ID, int UpdatedBy) 248 { 249 setAD_Client_ID(AD_Client_ID); 250 setUpdatedBy(UpdatedBy); 251 return save(); 252 } 254 258 public boolean save() 259 { 260 Log.trace(Log.l4_Data, "Account.save - Client_ID=" 261 + AD_Client_ID + ", Org_ID=" + AD_Org_ID, 262 "AcctSchema_ID=" + C_AcctSchema_ID + ", Account_ID=" + Account_ID); 263 264 int C_ValidCombination_ID = 0; 265 boolean saved = false; 266 try 267 { 268 String SQL = "{CALL C_ValidCombination_Get(?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?)}"; 269 CallableStatement cstmt = DB.prepareCall(SQL); 270 cstmt.registerOutParameter(1, Types.NUMERIC); 272 273 cstmt.setInt(2, AD_Client_ID); 276 cstmt.setInt(3, AD_Org_ID); 278 cstmt.setInt(4, C_AcctSchema_ID); 280 cstmt.setInt(5, Account_ID); 282 283 cstmt.setNull(6, Types.NUMERIC); 286 cstmt.setString(7, "Y"); 288 if (alias != null && alias.length() > 0) 290 cstmt.setString(8, alias); 291 else 292 cstmt.setNull(8, Types.VARCHAR); 293 cstmt.setInt(9, getUpdatedBy()); 295 296 if (M_Product_ID != 0) 299 cstmt.setInt(10, M_Product_ID); 300 else 301 cstmt.setNull(10, Types.NUMERIC); 302 if (C_BPartner_ID != 0) 304 cstmt.setInt(11, C_BPartner_ID); 305 else 306 cstmt.setNull(11, Types.NUMERIC); 307 if (AD_OrgTrx_ID != 0) 309 cstmt.setInt(12, AD_OrgTrx_ID); 310 else 311 cstmt.setNull(12, Types.NUMERIC); 312 if (C_LocFrom_ID != 0) 314 cstmt.setInt(13, C_LocFrom_ID); 315 else 316 cstmt.setNull(13, Types.NUMERIC); 317 if (C_LocTo_ID != 0) 319 cstmt.setInt(14, C_LocTo_ID); 320 else 321 cstmt.setNull(14, Types.NUMERIC); 322 if (C_SalesRegion_ID != 0) 324 cstmt.setInt(15, C_SalesRegion_ID); 325 else 326 cstmt.setNull(15, Types.NUMERIC); 327 if (C_Project_ID != 0) 329 cstmt.setInt(16, C_Project_ID); 330 else 331 cstmt.setNull(16, Types.NUMERIC); 332 if (C_Campaign_ID != 0) 334 cstmt.setInt(17, C_Campaign_ID); 335 else 336 cstmt.setNull(17, Types.NUMERIC); 337 if (C_Activity_ID != 0) 339 cstmt.setInt(18, C_Activity_ID); 340 else 341 cstmt.setNull(18, Types.NUMERIC); 342 if (User1_ID != 0) 344 cstmt.setInt(19, User1_ID); 345 else 346 cstmt.setNull(19, Types.NUMERIC); 347 if (User2_ID != 0) 349 cstmt.setInt(20, User2_ID); 350 else 351 cstmt.setNull(20, Types.NUMERIC); 352 353 cstmt.executeUpdate(); 355 C_ValidCombination_ID = cstmt.getInt(1); cstmt.close(); 357 m_changed = true; 358 saved = true; 359 } 360 catch(SQLException e) 361 { 362 Log.error("Account.save", e); 363 m_changed = false; 364 } 365 366 load(C_ValidCombination_ID); 368 return saved; 369 } 371 372 373 377 public String toString() 378 { 379 StringBuffer sb = new StringBuffer ("Account=["); 380 sb.append(C_ValidCombination_ID) 381 .append(",Client=").append(AD_Client_ID) 382 .append(",Org=").append(AD_Org_ID) 383 .append(",Acct=").append(Account_ID); 384 sb.append("]"); 386 return sb.toString(); 387 } 389 393 public boolean isBalanceSheet() 394 { 395 return (m_AcctType == 'A' || m_AcctType == 'L' || m_AcctType == 'O'); 396 } 398 402 public boolean isActiva() 403 { 404 return m_AcctType == 'A'; 405 } 407 411 public boolean isPassiva() 412 { 413 return m_AcctType == 'L' || m_AcctType == 'O'; 414 } 416 417 418 419 428 public boolean isValid() 429 { 430 if (m_OldAccount_ID == Account_ID && m_IsValid != null) 431 return m_IsValid.booleanValue(); 432 m_OldAccount_ID = Account_ID; 433 434 String sql = "SELECT AccountType,PostActual,PostBudget,PostEncumbrance,PostStatistical,IsForeignCurrency,C_Currency_ID " 435 + "FROM C_ElementValue " 436 + "WHERE C_ElementValue_ID=? AND IsActive='Y' AND IsSummary='N'"; 437 String str = null; 438 try 439 { 440 PreparedStatement pstmt = DB.prepareStatement(sql); 441 pstmt.setInt(1, Account_ID); 442 ResultSet rs = pstmt.executeQuery(); 443 if (rs.next()) 444 str = rs.getString(1); 445 rs.close(); 446 pstmt.close(); 447 } 448 catch (SQLException e) 449 { 450 Log.error ("Account.getAccountType", e); 451 } 452 catch (Exception e2) 453 { 454 Log.error("Account.getAccountType", e2); 455 } 456 if (str == null || str.length() == 0) 457 { 458 Log.error("Account.getAccountType - Type not found"); 459 m_IsValid = new Boolean (false); 460 m_AcctType = '?'; 461 } 462 else 463 { 464 m_IsValid = new Boolean (true); 465 m_AcctType = str.charAt(0); 466 } 467 return m_IsValid.booleanValue(); 468 } 470 471 472 476 public void setC_ValidCombination_ID(int newC_ValidCombination_ID) 477 { 478 C_ValidCombination_ID = newC_ValidCombination_ID; 479 m_changed = true; 480 } 481 public int getC_ValidCombination_ID() 482 { 483 return C_ValidCombination_ID; 484 } 485 public void setAD_Client_ID(int newAD_Client_ID) 486 { 487 AD_Client_ID = newAD_Client_ID; 488 m_changed = true; 489 } 490 public int getAD_Client_ID() 491 { 492 return AD_Client_ID; 493 } 494 public void setAD_Org_ID(int newAD_Org_ID) 495 { 496 AD_Org_ID = newAD_Org_ID; 497 m_changed = true; 498 } 499 public int getAD_Org_ID() 500 { 501 return AD_Org_ID; 502 } 503 public void setActive(boolean newActive) 504 { 505 active = newActive; 506 m_changed = true; 507 } 508 public boolean isActive() 509 { 510 return active; 511 } 512 public void setUpdatedBy(int newUpdatedBy) 513 { 514 updatedBy = newUpdatedBy; 515 m_changed = true; 516 } 517 public int getUpdatedBy() 518 { 519 return updatedBy; 520 } 521 public void setAlias(String newAlias) 522 { 523 alias = newAlias; 524 m_changed = true; 525 } 526 public String getAlias() 527 { 528 return alias; 529 } 530 public void setCombination(String newCombination) 531 { 532 combination = newCombination; 533 m_changed = true; 534 } 535 public String getCombination() 536 { 537 return combination; 538 } 539 public void setDescription(String newDescription) 540 { 541 description = newDescription; 542 m_changed = true; 543 } 544 public String getDescription() 545 { 546 return description; 547 } 548 public void setFullyQualified(boolean newFullyQualified) 549 { 550 fullyQualified = newFullyQualified; 551 m_changed = true; 552 } 553 public boolean isFullyQualified() 554 { 555 return fullyQualified; 556 } 557 public void setC_AcctSchema_ID(int newC_AcctSchema_ID) 558 { 559 C_AcctSchema_ID = newC_AcctSchema_ID; 560 m_changed = true; 561 } 562 public int getC_AcctSchema_ID() 563 { 564 return C_AcctSchema_ID; 565 } 566 public void setAccount_ID(int newAccount_ID) 567 { 568 Account_ID = newAccount_ID; 569 m_changed = true; 570 } 571 public int getAccount_ID() 572 { 573 return Account_ID; 574 } 575 public void setM_Product_ID(int newM_Product_ID) 576 { 577 M_Product_ID = newM_Product_ID; 578 m_changed = true; 579 } 580 public int getM_Product_ID() 581 { 582 return M_Product_ID; 583 } 584 public void setC_BPartner_ID(int newC_BPartner_ID) 585 { 586 C_BPartner_ID = newC_BPartner_ID; 587 m_changed = true; 588 } 589 public int getC_BPartner_ID() 590 { 591 return C_BPartner_ID; 592 } 593 public void setAD_OrgTrx_ID(int newAD_OrgTrx_ID) 594 { 595 AD_OrgTrx_ID = newAD_OrgTrx_ID; 596 m_changed = true; 597 } 598 public int getAD_OrgTrx_ID() 599 { 600 return AD_OrgTrx_ID; 601 } 602 public void setC_LocFrom_ID(int newC_LocFrom_ID) 603 { 604 C_LocFrom_ID = newC_LocFrom_ID; 605 m_changed = true; 606 } 607 public int getC_LocFrom_ID() 608 { 609 return C_LocFrom_ID; 610 } 611 public void setC_LocTo_ID(int newC_LocTo_ID) 612 { 613 C_LocTo_ID = newC_LocTo_ID; 614 m_changed = true; 615 } 616 public int getC_LocTo_ID() 617 { 618 return C_LocTo_ID; 619 } 620 public void setC_SalesRegion_ID(int newC_SalesRegion_ID) 621 { 622 C_SalesRegion_ID = newC_SalesRegion_ID; 623 m_changed = true; 624 } 625 public int getC_SalesRegion_ID() 626 { 627 return C_SalesRegion_ID; 628 } 629 public void setC_Project_ID(int newC_Project_ID) 630 { 631 C_Project_ID = newC_Project_ID; 632 m_changed = true; 633 } 634 public int getC_Project_ID() 635 { 636 return C_Project_ID; 637 } 638 public void setC_Campaign_ID(int newC_Campaign_ID) 639 { 640 C_Campaign_ID = newC_Campaign_ID; 641 m_changed = true; 642 } 643 public int getC_Campaign_ID() 644 { 645 return C_Campaign_ID; 646 } 647 public void setC_Activity_ID(int newC_Activity_ID) 648 { 649 C_Activity_ID = newC_Activity_ID; 650 m_changed = true; 651 } 652 public int getC_Activity_ID() 653 { 654 return C_Activity_ID; 655 } 656 public void setUser1_ID(int newUser1_ID) 657 { 658 User1_ID = newUser1_ID; 659 m_changed = true; 660 } 661 public int getUser1_ID() 662 { 663 return User1_ID; 664 } 665 public void setUser2_ID(int newUser2_ID) 666 { 667 User2_ID = newUser2_ID; 668 m_changed = true; 669 } 670 public int getUser2_ID() 671 { 672 return User2_ID; 673 } 674 public boolean isChanged() 675 { 676 return m_changed; 677 } 678 private void writeObject(ObjectOutputStream oos) throws IOException 679 { 680 oos.defaultWriteObject(); 681 } 682 private void readObject(ObjectInputStream ois) throws ClassNotFoundException , IOException 683 { 684 ois.defaultReadObject(); 685 } 686 } 688 | Popular Tags |