1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.math.*; 19 import java.io.Serializable ; 20 21 import org.compiere.util.*; 22 23 29 public class MBPartner extends X_C_BPartner 30 { 31 37 public static MBPartner getTemplate (Properties ctx, int AD_Client_ID) 38 { 39 if (s_template != null) 40 return s_template; 41 String sql = "SELECT * FROM C_BPartner " 43 + "WHERE C_BPartner_ID=(SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo WHERE AD_Client_ID=?)"; 44 PreparedStatement pstmt = null; 45 try 46 { 47 pstmt = DB.prepareStatement(sql); 48 pstmt.setInt(1, AD_Client_ID); 49 ResultSet rs = pstmt.executeQuery(); 50 if (rs.next()) 51 s_template = new MBPartner (ctx, rs); 52 else 53 s_log.error("getTemplate - No Template BP for AD_Client_ID=" + AD_Client_ID); 54 rs.close(); 55 pstmt.close(); 56 pstmt = null; 57 } 58 catch (Exception e) 59 { 60 s_log.error("getTemplate", e); 61 } 62 finally 63 { 64 try 65 { 66 if (pstmt != null) 67 pstmt.close (); 68 } 69 catch (Exception e) 70 {} 71 pstmt = null; 72 } 73 if (s_template != null) 75 { 76 s_template.setValueNoCheck ("C_BPartner_ID", null); 77 s_template.setValueNoCheck ("Value", ""); 78 s_template.setValueNoCheck ("Name", ""); 79 s_template.setValueNoCheck ("Name2", ""); 80 s_template.setSO_CreditLimit (Env.ZERO); 81 s_template.setSO_CreditUsed (Env.ZERO); 82 } 83 return s_template; 84 } 86 87 private static Logger s_log = Logger.getCLogger (PO.class); 88 89 private static MBPartner s_template; 90 91 92 93 97 public MBPartner (Properties ctx) 98 { 99 this (ctx, -1); 100 } 101 102 107 public MBPartner (Properties ctx, ResultSet rs) 108 { 109 super (ctx, rs); 110 } 112 117 public MBPartner (Properties ctx, int C_BPartner_ID) 118 { 119 super (ctx, C_BPartner_ID); 120 if (C_BPartner_ID == -1) 122 { 123 getTemplate (Env.getContextAsInt(ctx, "AD_Client_ID")); 124 C_BPartner_ID = 0; 125 } 126 if (C_BPartner_ID == 0) 127 { 128 setValueNoCheck ("Value", ""); 129 setValueNoCheck ("Name", ""); 130 setName2(""); 131 setDUNS(""); 132 setFirstSale(null); 133 setIsCustomer (true); 135 setIsProspect (true); 136 setSendEMail (false); 138 setIsOneTime (false); 139 setIsVendor (false); 140 setIsSummary (false); 141 setIsEmployee (false); 142 setIsSalesRep (false); 143 setSO_CreditLimit (Env.ZERO); 145 setSO_CreditUsed (Env.ZERO); 146 } 147 log.debug(toString()); 148 } 150 private MUser[] m_contacts = null; 151 private MBPartner_Location[] m_locations = null; 152 private MBP_BankAccount[] m_accounts = null; 153 154 158 private void getTemplate (int AD_Client_ID) 159 { 160 if (AD_Client_ID == 0) 161 throw new IllegalArgumentException ("MBPartner new - Client_ID=0"); 162 163 String sql = "SELECT * FROM C_BPartner " 164 + "WHERE C_BPartner_ID=(SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo WHERE AD_Client_ID=?)"; 165 PreparedStatement pstmt = null; 166 try 167 { 168 pstmt = DB.prepareStatement(sql); 169 pstmt.setInt(1, AD_Client_ID); 170 ResultSet rs = pstmt.executeQuery(); 171 if (rs.next()) 172 load (rs); 173 else 174 { 175 load(0); 176 log.error ("getTemplate - None found"); 177 } 178 rs.close(); 179 pstmt.close(); 180 pstmt = null; 181 } 182 catch (Exception e) 183 { 184 log.error("getTemplate", e); 185 } 186 finally 187 { 188 try 189 { 190 if (pstmt != null) 191 pstmt.close (); 192 } 193 catch (Exception e) 194 {} 195 pstmt = null; 196 } 197 setStandardDefaults(); 198 setValueNoCheck("C_BPartner_ID", new Integer (0)); 199 setValueNoCheck("Value", null); 200 setValueNoCheck("Name", null); 201 setName2(null); 202 } 204 205 209 public MUser[] getContacts() 210 { 211 if (m_contacts == null || m_contacts.length == 0) 212 ; 213 else 214 return m_contacts; 215 ArrayList list = new ArrayList(); 217 String sql = "SELECT * FROM AD_User WHERE C_BPartner_ID=?"; 218 PreparedStatement pstmt = null; 219 try 220 { 221 pstmt = DB.prepareStatement(sql); 222 pstmt.setInt(1, getC_BPartner_ID()); 223 ResultSet rs = pstmt.executeQuery(); 224 while (rs.next()) 225 list.add(new MUser (getCtx(), rs)); 226 rs.close(); 227 pstmt.close(); 228 pstmt = null; 229 } 230 catch (Exception e) 231 { 232 log.error("getContacts", e); 233 } 234 finally 235 { 236 try 237 { 238 if (pstmt != null) 239 pstmt.close (); 240 } 241 catch (Exception e) 242 {} 243 pstmt = null; 244 } 245 246 m_contacts = new MUser[list.size()]; 247 list.toArray(m_contacts); 248 return m_contacts; 249 } 251 255 public MBPartner_Location[] getLocations() 256 { 257 if (m_locations == null || m_locations.length == 0) 258 ; 259 else 260 return m_locations; 261 ArrayList list = new ArrayList(); 263 String sql = "SELECT * FROM C_BPartner_Location WHERE C_BPartner_ID=?"; 264 PreparedStatement pstmt = null; 265 try 266 { 267 pstmt = DB.prepareStatement(sql); 268 pstmt.setInt(1, getC_BPartner_ID()); 269 ResultSet rs = pstmt.executeQuery(); 270 while (rs.next()) 271 list.add(new MBPartner_Location (getCtx(), rs)); 272 rs.close(); 273 pstmt.close(); 274 pstmt = null; 275 } 276 catch (Exception e) 277 { 278 log.error("getLocations", e); 279 } 280 finally 281 { 282 try 283 { 284 if (pstmt != null) 285 pstmt.close (); 286 } 287 catch (Exception e) 288 {} 289 pstmt = null; 290 } 291 292 m_locations = new MBPartner_Location[list.size()]; 293 list.toArray(m_locations); 294 return m_locations; 295 } 297 301 public MBP_BankAccount[] getBankAccounts() 302 { 303 if (m_accounts == null || m_accounts.length == 0) ; 305 else 306 return m_accounts; 307 ArrayList list = new ArrayList(); 309 String sql = "SELECT * FROM C_BP_BankAccount WHERE C_BPartner_ID=?"; 310 PreparedStatement pstmt = null; 311 try 312 { 313 pstmt = DB.prepareStatement(sql); 314 pstmt.setInt(1, getC_BPartner_ID()); 315 ResultSet rs = pstmt.executeQuery(); 316 while (rs.next()) 317 list.add(new MBP_BankAccount (getCtx(), rs)); 318 rs.close(); 319 pstmt.close(); 320 pstmt = null; 321 } 322 catch (Exception e) 323 { 324 log.error("getBankAccounts", e); 325 } 326 finally 327 { 328 try 329 { 330 if (pstmt != null) 331 pstmt.close (); 332 } 333 catch (Exception e) 334 {} 335 pstmt = null; 336 } 337 338 m_accounts = new MBP_BankAccount[list.size()]; 339 list.toArray(m_accounts); 340 return m_accounts; 341 } 343 344 345 349 public String toString () 350 { 351 StringBuffer sb = new StringBuffer ("MBPartner[ID=") 352 .append(getID()) 353 .append(",Value=").append(getValue()) 354 .append(",Name=").append(getName()) 355 .append ("]"); 356 return sb.toString (); 357 } 359 364 public void setClientOrg (int AD_Client_ID, int AD_Org_ID) 365 { 366 setAD_Client_ID(AD_Client_ID); 367 setAD_Org_ID(AD_Org_ID); 368 } 370 } | Popular Tags |