1 14 package org.compiere.model; 15 16 import java.sql.*; 17 import java.math.*; 18 19 import org.compiere.util.*; 20 21 27 public class MProductPriceVO 28 { 29 37 public MProductPriceVO (int m_product_ID, int m_PriceList_Version_ID, 38 BigDecimal priceList, BigDecimal priceStd, BigDecimal priceLimit) 39 { 40 M_Product_ID = m_product_ID; 41 M_PriceList_Version_ID = m_PriceList_Version_ID; 42 PriceList = priceList; 43 if (PriceList == null) 44 PriceList = Env.ZERO; 45 PriceStd = priceStd; 46 if (PriceStd == null) 47 PriceStd = Env.ZERO; 48 PriceLimit = priceLimit; 49 if (PriceLimit == null) 50 PriceLimit = Env.ZERO; 51 } 53 54 public int M_Product_ID = 0; 55 56 public int M_PriceList_Version_ID = 0; 57 58 59 public BigDecimal PriceList; 60 61 public BigDecimal PriceStd; 62 63 public BigDecimal PriceLimit; 64 65 66 67 68 private Timestamp m_ValidFrom = null; 69 70 71 private int m_C_Currency_ID = 0; 72 73 private Boolean m_enforcePriceLimit = null; 74 75 private int m_M_PriceList_ID = 0; 76 77 78 private static Logger s_log = Logger.getCLogger(MProductPriceVO.class); 79 80 81 85 public Timestamp getValidFrom() 86 { 87 if (m_ValidFrom == null) 88 loadPLV(); 89 return m_ValidFrom; 90 } 92 95 private void loadPLV() 96 { 97 X_M_PriceList_Version plv = new X_M_PriceList_Version (Env.getCtx(), M_PriceList_Version_ID); 98 m_ValidFrom = plv.getValidFrom(); 99 m_M_PriceList_ID = plv.getM_PriceList_ID(); 100 } 102 106 public int getC_Currency_ID() 107 { 108 if (m_C_Currency_ID == 0) 109 loadPL(); 110 return m_C_Currency_ID; 111 } 113 117 public boolean isEnforcePriceLimit() 118 { 119 if (m_enforcePriceLimit == null) 120 loadPL(); 121 return m_enforcePriceLimit.booleanValue(); 122 } 124 127 private void loadPL() 128 { 129 if (m_M_PriceList_ID == 0) 130 loadPLV(); 131 X_M_PriceList pl = new X_M_PriceList (Env.getCtx(), m_M_PriceList_ID); 132 m_C_Currency_ID = pl.getC_Currency_ID(); 133 m_enforcePriceLimit = new Boolean (pl.isEnforcePriceLimit()); 134 } 136 137 138 145 public static MProductPriceVO getBOMPrices (int M_Product_ID, boolean SOPriceList, Timestamp docDate) 146 { 147 if (docDate == null) 148 docDate = new Timestamp (System.currentTimeMillis()); 149 MProductPriceVO retValue = null; 150 String sql = "SELECT pp.M_Product_ID,plv.M_PriceList_Version_ID, " + "BOM_PriceList(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceList," 152 + "BOM_PriceStd(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceStd," 153 + "BOM_PriceLimit(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceLimit," 154 + "plv.ValidFrom, pl.C_Currency_ID,pl.EnforcePriceLimit " + "FROM M_ProductPrice pp" 156 + " INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)" 157 + " INNER JOIN M_Pricelist pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID) " 158 + "WHERE pp.M_Product_ID=?" 159 + " AND pl.IsDefault='Y' AND pl.IsSOPriceList=" + (SOPriceList ? "'Y'" : "'N'") 160 + " AND plv.IsActive='Y' AND pl.IsActive='Y' " 161 + "ORDER BY pl.M_PriceList_ID, plv.ValidFrom DESC"; 162 try 163 { 164 PreparedStatement pstmt = DB.prepareStatement(sql); 165 pstmt.setInt(1, M_Product_ID); 166 ResultSet rs = pstmt.executeQuery(); 167 boolean noPrice = true; 168 while (noPrice && rs.next()) 169 { 170 Timestamp plvDate = rs.getTimestamp(6); 171 if (plvDate == null || !docDate.before(plvDate)) 174 { 175 noPrice = false; 176 retValue = new MProductPriceVO (rs.getInt(1), rs.getInt(2), 177 rs.getBigDecimal(3), rs.getBigDecimal(4), rs.getBigDecimal(5)); 178 retValue.m_ValidFrom = plvDate; 179 retValue.m_C_Currency_ID = rs.getInt(7); 180 retValue.m_enforcePriceLimit = new Boolean ("Y".equals(rs.getString(8))); 181 } 182 } 183 rs.close(); 184 pstmt.close(); 185 } 186 catch (Exception e) 187 { 188 s_log.error("getBOMPricesPL\n" + sql, e); 189 } 190 return retValue; 191 } 193 200 public static MProductPriceVO getBOMPricesPL (int M_Product_ID, int M_PriceList_ID, Timestamp docDate) 201 { 202 if (docDate == null) 203 docDate = new Timestamp (System.currentTimeMillis()); 204 MProductPriceVO retValue = null; 205 String sql = "SELECT pp.M_Product_ID,plv.M_PriceList_Version_ID, " + "BOM_PriceList(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceList," 207 + "BOM_PriceStd(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceStd," 208 + "BOM_PriceLimit(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceLimit," 209 + "plv.ValidFrom, pl.C_Currency_ID,pl.EnforcePriceLimit " + "FROM M_ProductPrice pp" 211 + " INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)" 212 + " INNER JOIN M_Pricelist pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID) " 213 + "WHERE pp.M_Product_ID=?" 214 + " AND pl.M_PriceList_ID=?" 215 + " AND plv.IsActive='Y' AND pl.IsActive='Y' " 216 + "ORDER BY plv.ValidFrom DESC"; 217 try 218 { 219 PreparedStatement pstmt = DB.prepareStatement(sql); 220 pstmt.setInt(1, M_Product_ID); 221 pstmt.setInt(2, M_PriceList_ID); 222 ResultSet rs = pstmt.executeQuery(); 223 boolean noPrice = true; 224 while (noPrice && rs.next()) 225 { 226 Timestamp plvDate = rs.getTimestamp(6); 227 if (plvDate == null || !docDate.before(plvDate)) 230 { 231 noPrice = false; 232 retValue = new MProductPriceVO (rs.getInt(1), rs.getInt(2), 233 rs.getBigDecimal(3), rs.getBigDecimal(4), rs.getBigDecimal(5)); 234 retValue.m_ValidFrom = plvDate; 235 retValue.m_C_Currency_ID = rs.getInt(7); 236 retValue.m_enforcePriceLimit = new Boolean ("Y".equals(rs.getString(8))); 237 } 238 } 239 rs.close(); 240 pstmt.close(); 241 } 242 catch (Exception e) 243 { 244 s_log.error("getBOMPricesPL", e); 245 } 246 return retValue; 247 } 249 255 public static MProductPriceVO getBOMPricesPLV (int M_Product_ID, int M_PriceList_Version_ID) 256 { 257 MProductPriceVO retValue = null; 258 String sql = "SELECT pp.M_Product_ID,plv.M_PriceList_Version_ID, " + "BOM_PriceList(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceList," 260 + "BOM_PriceStd(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceStd," 261 + "BOM_PriceLimit(pp.M_Product_ID,plv.M_PriceList_Version_ID) AS PriceLimit," 262 + "plv.ValidFrom, pl.C_Currency_ID,pl.EnforcePriceLimit " + "FROM M_ProductPrice pp" 264 + " INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)" 265 + " INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID) " 266 + "WHERE pp.M_Product_ID=?" 267 + " AND plv.M_PriceList_Version_ID=?" 268 + " AND plv.IsActive='Y' AND pl.IsActive='Y'"; 269 try 270 { 271 PreparedStatement pstmt = DB.prepareStatement(sql); 272 pstmt.setInt(1, M_Product_ID); 273 pstmt.setInt(2, M_PriceList_Version_ID); 274 ResultSet rs = pstmt.executeQuery(); 275 if (rs.next()) 276 { 277 retValue = new MProductPriceVO (rs.getInt(1), rs.getInt(2), 278 rs.getBigDecimal(3), rs.getBigDecimal(4), rs.getBigDecimal(5)); 279 retValue.m_ValidFrom = rs.getTimestamp(6); 280 retValue.m_C_Currency_ID = rs.getInt(7); 281 retValue.m_enforcePriceLimit = new Boolean ("Y".equals(rs.getString(8))); 282 } 283 rs.close(); 284 pstmt.close(); 285 } 286 catch (Exception e) 287 { 288 s_log.error("getBOMPricesPLV", e); 289 } 290 return retValue; 291 } 293 }
| Popular Tags
|