1 14 package org.compiere.wstore; 15 16 import javax.servlet.*; 17 import javax.servlet.http.*; 18 import java.io.*; 19 import java.util.*; 20 import java.sql.*; 21 22 import org.apache.log4j.Logger; 23 24 import org.compiere.model.*; 25 import org.compiere.util.*; 26 27 28 35 public class Info 36 { 37 41 public static Info getGeneral() 42 { 43 if (m_general == null) 44 m_general = new Info (new Properties(), -1, -1); 45 return m_general; 46 } 48 49 private static Info m_general = null; 50 51 57 public Info (Properties ctx, int C_BPartner_ID, int AD_User_ID) 58 { 59 m_ctx = ctx; 60 m_C_BPartner_ID = C_BPartner_ID; 61 m_AD_User_ID = AD_User_ID; 62 log.debug("C_BPartner_ID=" + C_BPartner_ID + ", AD_User_ID=" + AD_User_ID); 63 } 65 66 static public final String NAME = "info"; 67 68 69 private Logger log = Logger.getLogger(getClass()); 70 71 private Properties m_ctx = null; 72 73 private int m_C_BPartner_ID = 0; 74 private int m_AD_User_ID = 0; 75 76 private String m_infoMessage = null; 77 78 private int m_id = 0; 79 80 84 public String toString() 85 { 86 StringBuffer sb = new StringBuffer ("Info["); 87 sb.append(m_C_BPartner_ID); 88 sb.append("]"); 89 return sb.toString(); 90 } 92 96 public String getMessage() 97 { 98 String retValue = m_infoMessage; 99 m_infoMessage = null; 100 return retValue; 101 } 103 107 public String getInfo() 108 { 109 return m_infoMessage; 110 } 112 116 public void setMessage (String msg) 117 { 118 m_infoMessage = msg; 119 } 121 125 public int getId() 126 { 127 return m_id; 128 } 130 134 public void setId (String id) 135 { 136 try 137 { 138 setId (Integer.parseInt (id)); 139 } 140 catch (NumberFormatException ex) 141 { 142 log.error("setId - " + id + " - " + ex.toString()); 143 } 144 } 146 150 public void setId (int id) 151 { 152 log.info("setID = " + id); 153 m_id = id; 154 } 156 160 public int getC_BPartner_ID() 161 { 162 return m_C_BPartner_ID; 163 } 165 169 public int getAD_User_ID() 170 { 171 return m_AD_User_ID; 172 } 174 178 public int getUser_ID() 179 { 180 return m_AD_User_ID; 181 } 183 184 185 189 public ArrayList getOrders() 190 { 191 m_infoMessage = null; 192 ArrayList list = new ArrayList(); 193 String sql = "SELECT * FROM C_Order WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC"; 194 PreparedStatement pstmt = null; 195 try 196 { 197 pstmt = DB.prepareStatement(sql); 198 pstmt.setInt(1, m_C_BPartner_ID); 199 ResultSet rs = pstmt.executeQuery(); 200 while (rs.next()) 201 list.add(new MOrder (m_ctx, rs)); 202 rs.close(); 203 pstmt.close(); 204 pstmt = null; 205 } 206 catch (Exception e) 207 { 208 log.error("getOrders", e); 209 } 210 finally 211 { 212 try 213 { 214 if (pstmt != null) 215 pstmt.close (); 216 } 217 catch (Exception e) 218 {} 219 pstmt = null; 220 } 221 log.debug ("getOrders #" + list.size()); 222 return list; 223 } 225 230 public MOrder getOrder() 231 { 232 MOrder retValue = null; 233 String sql = "SELECT * FROM C_Order WHERE C_BPartner_ID=? AND C_Order_ID=?"; 234 PreparedStatement pstmt = null; 235 try 236 { 237 pstmt = DB.prepareStatement(sql); 238 pstmt.setInt(1, m_C_BPartner_ID); 239 pstmt.setInt(2, m_id); 240 ResultSet rs = pstmt.executeQuery(); 241 if (rs.next()) 242 retValue = new MOrder (m_ctx, rs); 243 rs.close(); 244 pstmt.close(); 245 pstmt = null; 246 } 247 catch (Exception e) 248 { 249 log.error("getOrder ID=" + m_id, e); 250 } 251 finally 252 { 253 try 254 { 255 if (pstmt != null) 256 pstmt.close (); 257 } 258 catch (Exception e) 259 {} 260 pstmt = null; 261 } 262 log.debug ("getOrder ID=" + m_id + " - " + retValue); 263 return retValue; 264 } 266 267 271 public ArrayList getShipments() 272 { 273 m_infoMessage = null; 274 ArrayList list = new ArrayList(); 275 String sql = "SELECT * FROM M_InOut WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC"; 276 PreparedStatement pstmt = null; 277 try 278 { 279 pstmt = DB.prepareStatement(sql); 280 pstmt.setInt(1, m_C_BPartner_ID); 281 ResultSet rs = pstmt.executeQuery(); 282 while (rs.next()) 283 list.add(new MInOut (m_ctx, rs)); 284 rs.close(); 285 pstmt.close(); 286 pstmt = null; 287 } 288 catch (Exception e) 289 { 290 log.error("getShipments", e); 291 } 292 finally 293 { 294 try 295 { 296 if (pstmt != null) 297 pstmt.close (); 298 } 299 catch (Exception e) 300 {} 301 pstmt = null; 302 } 303 log.debug ("getShipments #" + list.size()); 304 return list; 305 } 307 311 public ArrayList getRequestsOwn () 312 { 313 return getRequests(true); 314 } 316 320 public ArrayList getRequestsAssigned () 321 { 322 return getRequests(false); 323 } 325 330 public ArrayList getRequests (boolean own) 331 { 332 m_infoMessage = null; 333 ArrayList list = new ArrayList(); 334 String sql = own ? "SELECT * FROM R_Request WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC" 335 : "SELECT * FROM R_Request WHERE SalesRep_ID IN (SELECT AD_User_ID FROM AD_User WHERE C_BPartner_ID=?) " 336 + "ORDER BY DocumentNo DESC"; 337 PreparedStatement pstmt = null; 338 try 339 { 340 pstmt = DB.prepareStatement(sql); 341 pstmt.setInt(1, m_C_BPartner_ID); 342 ResultSet rs = pstmt.executeQuery(); 343 while (rs.next()) 344 list.add (new MRequest (m_ctx, rs)); 345 rs.close(); 346 pstmt.close(); 347 pstmt = null; 348 } 349 catch (Exception e) 350 { 351 log.error("getRequests Own=" + own, e); 352 } 353 finally 354 { 355 try 356 { 357 if (pstmt != null) 358 pstmt.close (); 359 } 360 catch (Exception e) 361 {} 362 pstmt = null; 363 } 364 log.debug ("getRequests Own=" + own +" #" + list.size()); 365 return list; 366 } 368 372 public ArrayList getInvoices() 373 { 374 ArrayList list = new ArrayList(); 375 String sql = "SELECT * FROM C_Invoice WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC"; 376 PreparedStatement pstmt = null; 377 try 378 { 379 pstmt = DB.prepareStatement(sql); 380 pstmt.setInt(1, m_C_BPartner_ID); 381 ResultSet rs = pstmt.executeQuery(); 382 while (rs.next()) 383 list.add(new MInvoice (m_ctx, rs)); 384 rs.close(); 385 pstmt.close(); 386 pstmt = null; 387 } 388 catch (Exception e) 389 { 390 log.error("getInvoices", e); 391 } 392 finally 393 { 394 try 395 { 396 if (pstmt != null) 397 pstmt.close (); 398 } 399 catch (Exception e) 400 {} 401 pstmt = null; 402 } 403 log.debug ("getInvoices #" + list.size()); 404 return list; 405 } 407 412 public MInvoice getInvoice() 413 { 414 MInvoice retValue = null; 415 String sql = "SELECT * FROM C_Invoice WHERE C_BPartner_ID=? AND C_Invoice_ID=?"; 416 PreparedStatement pstmt = null; 417 try 418 { 419 pstmt = DB.prepareStatement(sql); 420 pstmt.setInt(1, m_C_BPartner_ID); 421 pstmt.setInt(2, m_id); 422 ResultSet rs = pstmt.executeQuery(); 423 if (rs.next()) 424 retValue = new MInvoice (m_ctx, rs); 425 rs.close(); 426 pstmt.close(); 427 pstmt = null; 428 } 429 catch (Exception e) 430 { 431 log.error("getInvoice ID=" + m_id, e); 432 } 433 finally 434 { 435 try 436 { 437 if (pstmt != null) 438 pstmt.close (); 439 } 440 catch (Exception e) 441 {} 442 pstmt = null; 443 } 444 log.debug ("getInvoice ID=" + m_id + " - " + retValue); 445 return retValue; 446 } 448 452 public ArrayList getPayments() 453 { 454 ArrayList list = new ArrayList(); 455 String sql = "SELECT * FROM C_Payment WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC"; 456 PreparedStatement pstmt = null; 457 try 458 { 459 pstmt = DB.prepareStatement(sql); 460 pstmt.setInt(1, m_C_BPartner_ID); 461 ResultSet rs = pstmt.executeQuery(); 462 while (rs.next()) 463 list.add(new MPayment (m_ctx, rs)); 464 rs.close(); 465 pstmt.close(); 466 pstmt = null; 467 } 468 catch (Exception e) 469 { 470 log.error("getPayments", e); 471 } 472 finally 473 { 474 try 475 { 476 if (pstmt != null) 477 pstmt.close (); 478 } 479 catch (Exception e) 480 {} 481 pstmt = null; 482 } 483 log.debug ("getPayments #" + list.size()); 484 return list; 485 } 487 491 public ArrayList getAssets() 492 { 493 ArrayList list = new ArrayList(); 494 String sql = "SELECT * FROM A_Asset WHERE C_BPartner_ID=? AND IsActive='Y' ORDER BY Name"; 495 PreparedStatement pstmt = null; 496 try 497 { 498 pstmt = DB.prepareStatement(sql); 499 pstmt.setInt(1, m_C_BPartner_ID); 500 ResultSet rs = pstmt.executeQuery(); 501 while (rs.next()) 502 list.add(new MAsset (m_ctx, rs)); 503 rs.close(); 504 pstmt.close(); 505 pstmt = null; 506 } 507 catch (Exception e) 508 { 509 log.error("getAssets", e); 510 } 511 finally 512 { 513 try 514 { 515 if (pstmt != null) 516 pstmt.close (); 517 } 518 catch (Exception e) 519 {} 520 pstmt = null; 521 } 522 log.debug ("getAssets #" + list.size()); 523 return list; 524 } 526 530 public ArrayList getInterests() 531 { 532 int AD_Client_ID = Env.getContextAsInt(m_ctx, "#AD_Client_ID"); 533 ArrayList list = new ArrayList(); 535 String sql = "SELECT ia.R_InterestArea_ID, ia.AD_Client_ID,ia.AD_Org_ID,ia.IsActive," 536 + " ia.Created,ia.CreatedBy,ia.Updated,ia.UpdatedBy," 537 + " ia.Name,ia.Description,ia.IsSelfService," 538 + " ci.AD_User_ID, ci.SubscribeDate,ci.OptOutDate " 539 + "FROM R_InterestArea ia" 540 + " LEFT OUTER JOIN R_ContactInterest ci ON (ia.R_InterestArea_ID=ci.R_InterestArea_ID AND ci.AD_User_ID=?) " 541 + "WHERE ia.IsActive='Y' AND ia.IsSelfService='Y'" 542 + " AND ia.AD_Client_ID=? " 543 + "ORDER BY ia.Name"; 544 PreparedStatement pstmt = null; 545 try 546 { 547 pstmt = DB.prepareStatement(sql); 548 pstmt.setInt(1, m_AD_User_ID); 549 pstmt.setInt(2, AD_Client_ID); 550 ResultSet rs = pstmt.executeQuery(); 551 while (rs.next()) 552 { 553 MInterestArea ia = new MInterestArea (m_ctx, rs); 554 int contact = rs.getInt("AD_User_ID"); 555 if (contact != 0) 556 ia.setSubscription(contact, rs.getTimestamp("SubscribeDate"), rs.getTimestamp("OptOutDate")); 557 list.add (ia); 558 } 559 rs.close(); 560 pstmt.close(); 561 pstmt = null; 562 } 563 catch (Exception e) 564 { 565 log.error("getInterests", e); 566 } 567 finally 568 { 569 try 570 { 571 if (pstmt != null) 572 pstmt.close (); 573 } 574 catch (Exception e) 575 {} 576 pstmt = null; 577 } 578 log.debug ("getInterests #" + list.size()); 579 return list; 580 } 582 586 public ArrayList getAdvertisements() 587 { 588 m_infoMessage = null; 589 ArrayList list = new ArrayList(); 590 String sql = "SELECT * FROM W_Advertisement WHERE C_BPartner_ID=? ORDER BY ValidFrom DESC"; 591 PreparedStatement pstmt = null; 592 try 593 { 594 pstmt = DB.prepareStatement(sql); 595 pstmt.setInt(1, m_C_BPartner_ID); 596 ResultSet rs = pstmt.executeQuery(); 597 while (rs.next()) 598 list.add(new MAdvertisement (m_ctx, rs)); 599 rs.close(); 600 pstmt.close(); 601 pstmt = null; 602 } 603 catch (Exception e) 604 { 605 log.error("getAdvertisement", e); 606 } 607 finally 608 { 609 try 610 { 611 if (pstmt != null) 612 pstmt.close (); 613 } 614 catch (Exception e) 615 {} 616 pstmt = null; 617 } 618 log.debug ("getAdvertisement #" + list.size()); 619 return list; 620 } 622 626 public ArrayList getAllAds() 627 { 628 m_infoMessage = null; 629 ArrayList list = new ArrayList(); 630 String sql = "SELECT * FROM W_Advertisement ORDER BY Description"; 631 PreparedStatement pstmt = null; 632 try 633 { 634 pstmt = DB.prepareStatement(sql); 635 ResultSet rs = pstmt.executeQuery(); 636 while (rs.next()) 637 list.add(new MAdvertisement (m_ctx, rs)); 638 rs.close(); 639 pstmt.close(); 640 pstmt = null; 641 } 642 catch (Exception e) 643 { 644 log.error("getAllAds", e); 645 } 646 finally 647 { 648 try 649 { 650 if (pstmt != null) 651 pstmt.close (); 652 } 653 catch (Exception e) 654 {} 655 pstmt = null; 656 } 657 log.debug ("getAllAds #" + list.size()); 658 return list; 659 } 661 } | Popular Tags |