use of org.compiere.model.MLocation in project adempiere by adempiere.
the class WebUser method load.
/**
* Load Contact
* @param email email
* @param password optional password
*/
private void load(String email, String password) {
log.info(email + " - AD_Client_ID=" + m_AD_Client_ID);
String sql = "SELECT * " + "FROM AD_User " + "WHERE AD_Client_ID=?" + " AND TRIM(EMail)=?";
if (email == null)
email = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_AD_Client_ID);
pstmt.setString(2, email.trim());
rs = pstmt.executeQuery();
if (rs.next()) {
m_bpc = new MUser(m_ctx, rs, null);
log.fine("Found BPC=" + m_bpc);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Check Password
m_passwordOK = false;
// We have a password
if (m_bpc != null && password != null && authenticateHash(password))
m_passwordOK = true;
if (m_passwordOK || m_bpc == null)
m_passwordMessage = null;
else
setPasswordOK(false, password);
// Load BPartner
if (m_bpc != null) {
m_bp = new MBPartner(m_ctx, m_bpc.getC_BPartner_ID(), null);
log.fine("Found BP=" + m_bp);
} else
m_bp = null;
// Load Loacation
if (m_bpc != null) {
if (m_bpc.getC_BPartner_Location_ID() != 0) {
m_bpl = new MBPartnerLocation(m_ctx, m_bpc.getC_BPartner_Location_ID(), null);
log.fine("Found BPL=" + m_bpl);
} else {
MBPartnerLocation[] bpls = m_bp.getLocations(false);
if (bpls != null && bpls.length > 0) {
m_bpl = bpls[0];
log.fine("Found BPL=" + m_bpl);
}
}
if (m_bpl != null) {
m_loc = MLocation.get(m_ctx, m_bpl.getC_Location_ID(), null);
log.fine("Found LOC=" + m_loc);
} else
m_loc = null;
} else {
m_bpl = null;
m_loc = null;
}
// Make sure that all entities exist
if (m_bpc == null) {
m_bpc = new MUser(m_ctx, 0, null);
m_bpc.setEMail(email);
m_bpc.setPassword(password);
}
if (m_bp == null) {
// template
m_bp = new MBPartner(m_ctx);
m_bp.setIsCustomer(true);
}
if (m_bpl == null)
m_bpl = new MBPartnerLocation(m_bp);
if (m_loc == null)
m_loc = new MLocation(m_ctx, 0, null);
//
log.config(m_bp + " - " + m_bpc);
}
use of org.compiere.model.MLocation in project adempiere by adempiere.
the class WebUser method load.
// load
/**
* Load Contact
* @param AD_User_ID BP Contact
*/
private void load(int AD_User_ID) {
log.info("ID=" + AD_User_ID + ", AD_Client_ID=" + m_AD_Client_ID);
String sql = "SELECT * " + "FROM AD_User " + "WHERE AD_Client_ID=?" + " AND AD_User_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_AD_Client_ID);
pstmt.setInt(2, AD_User_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
m_bpc = new MUser(m_ctx, rs, null);
log.fine("= found BPC=" + m_bpc);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Password not entered
m_passwordOK = false;
m_loggedIn = false;
// Load BPartner
if (m_bpc != null) {
m_bp = new MBPartner(m_ctx, m_bpc.getC_BPartner_ID(), null);
log.fine("= Found BP=" + m_bp);
} else
m_bp = null;
// Load Loacation
if (m_bpc != null) {
if (m_bpc.getC_BPartner_Location_ID() != 0) {
m_bpl = new MBPartnerLocation(m_ctx, m_bpc.getC_BPartner_Location_ID(), null);
log.fine("= Found BPL=" + m_bpl);
} else {
MBPartnerLocation[] bpls = m_bp.getLocations(false);
if (bpls != null && bpls.length > 0) {
m_bpl = bpls[0];
log.fine("= Found BPL=" + m_bpl);
}
}
if (m_bpl != null) {
m_loc = MLocation.get(m_ctx, m_bpl.getC_Location_ID(), null);
log.fine("= Found LOC=" + m_loc);
} else
m_loc = null;
} else {
m_bpl = null;
m_loc = null;
}
// Make sure that all entities exist
if (m_bpc == null) {
m_bpc = new MUser(m_ctx, 0, null);
m_bpc.setEMail("?");
m_bpc.setPassword("?");
}
if (m_bp == null) {
// template
m_bp = new MBPartner(m_ctx);
m_bp.setIsCustomer(true);
}
if (m_bpl == null)
m_bpl = new MBPartnerLocation(m_bp);
if (m_loc == null)
m_loc = new MLocation(m_ctx, 0, null);
//
log.info("= " + m_bp + " - " + m_bpc);
}
use of org.compiere.model.MLocation in project adempiere by adempiere.
the class InventoryUtil method getCreatePartner.
public static MBPartner getCreatePartner(String value) {
Properties ctx = Env.getCtx();
final String whereClause = MBPartner.COLUMNNAME_Value + "=?";
MBPartner bp = new Query(ctx, I_C_BPartner.Table_Name, whereClause, null).setParameters(value).setClient_ID().firstOnly();
if (bp == null) {
bp = new MBPartner(ctx, 0, null);
}
bp.setValue(value);
bp.setName(value);
setGeneratedTag(bp);
bp.setIsCustomer(true);
bp.setIsVendor(true);
bp.setC_BP_Group_ID(MBPGroup.getDefault(ctx).get_ID());
bp.saveEx();
//
if (bp.getLocations(false).length == 0) {
MLocation loc = new MLocation(ctx, 0, null);
loc.saveEx();
//
MBPartnerLocation bpl = new MBPartnerLocation(bp);
bpl.setC_Location_ID(loc.get_ID());
bpl.saveEx();
}
return bp;
}
use of org.compiere.model.MLocation in project adempiere by adempiere.
the class FreightRule method getFreightRate.
/**
* get Freight Rate
* @param ctx
* @param shipperId
* @param freightCategoryId
* @param currencyId
* @param date
* @param trxName
* @return
*/
public BigDecimal getFreightRate(Properties ctx, int shipperId, int freightCategoryId, int currencyId, int locationFromId, int locationToId, Timestamp date, String trxName) {
MLocation locationFrom = MLocation.get(ctx, locationFromId, trxName);
MLocation locationTo = MLocation.get(ctx, locationToId, trxName);
Optional<Integer> countryFromOptionalId;
Optional<Integer> regionFromOptionalId;
if (locationFrom != null && locationFrom.get_ID() > 0) {
countryFromOptionalId = Optional.ofNullable(locationFrom.getC_Country_ID());
regionFromOptionalId = Optional.ofNullable(locationFrom.getC_Region_ID());
} else {
countryFromOptionalId = Optional.empty();
regionFromOptionalId = Optional.empty();
}
Optional<Integer> countryToOptionalId;
Optional<Integer> regionToOptionalId;
if (locationTo != null && locationTo.get_ID() > 0) {
countryToOptionalId = Optional.ofNullable(locationTo.getC_Country_ID());
regionToOptionalId = Optional.ofNullable(locationTo.getC_Region_ID());
} else {
countryToOptionalId = Optional.empty();
regionToOptionalId = Optional.empty();
}
FreightServiceInterface freightService = new FreightService();
Optional<MFreight> freightOptioonal = freightService.getFreightValid(ctx, shipperId, freightCategoryId, currencyId, date, trxName).stream().filter(freight -> {
if (freight.getC_Country_ID() == 0 && freight.getTo_Country_ID() == 0)
return true;
else if (freight.getC_Country_ID() == 0 && (countryToOptionalId.isPresent() && countryToOptionalId.get() == freight.getTo_Country_ID()))
return true;
else if ((countryFromOptionalId.isPresent() && countryFromOptionalId.get() == freight.getC_Country_ID()) && (countryToOptionalId.isPresent() && countryToOptionalId.get() == freight.getTo_Country_ID()))
return true;
else
return false;
}).filter(freight -> {
if (freight.getC_Region_ID() == 0 && freight.getTo_Region_ID() == 0)
return true;
else if (freight.getC_Region_ID() == 0 && (regionToOptionalId.isPresent() && regionToOptionalId.get() == freight.getTo_Region_ID()))
return true;
else if ((regionFromOptionalId.isPresent() && regionFromOptionalId.get() == freight.getC_Region_ID()) && (regionToOptionalId.isPresent() && regionToOptionalId.get() == freight.getTo_Region_ID()))
return true;
else
return false;
}).findFirst();
if (freightOptioonal.isPresent()) {
return freightOptioonal.get().getFreightAmt();
} else {
return BigDecimal.ZERO;
}
}
use of org.compiere.model.MLocation in project adempiere by adempiere.
the class LocationServlet method doPost.
// doGet
/**
* Process the HTTP Post request.
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
HttpSession session = request.getSession(true);
Properties ctx = JSPEnv.getCtx(request);
MLocation loc = new MLocation(ctx, 0, null);
response.setHeader("Cache-Control", "no-cache");
response.setContentType("text/xml; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String cmd = request.getParameter("cmd");
cmd = Util.maskHTML(cmd, true);
if (cmd == null) {
out.println("<error>Unknown Request: NULL</error>");
} else {
String selected = request.getParameter("selected");
int selectedID = 0;
try {
selectedID = Integer.parseInt(selected);
} catch (Exception e) {
selectedID = 0;
}
if (// should probably put these in enum
cmd.equalsIgnoreCase("countries")) {
out.println("<countries>");
MCountry[] countries = MCountry.getCountries(loc.getCtx());
for (MCountry country : countries) {
int id = country.getC_Country_ID();
out.print("<country id='" + id + "'");
if (id == selectedID)
out.print(" selected='true'");
out.println(">" + country.getName() + "</country>");
}
out.println("</countries>");
} else if (cmd.equalsIgnoreCase("regions")) {
String country = Util.maskHTML(request.getParameter("country"), true);
try {
int countryId = Integer.parseInt(country);
out.println("<regions country='" + countryId + "'>");
MRegion[] regions = MRegion.getRegions(loc.getCtx(), countryId);
if ((regions.length > 0) && (selectedID == 0))
selectedID = regions[0].getC_Region_ID();
for (MRegion region : regions) {
int id = region.getC_Region_ID();
out.print("<region id='" + id + "'");
if (id == selectedID)
out.print(" selected='true'");
out.println(">" + region.getName() + "</region>");
}
out.println("</regions>");
} catch (Exception e) {
out.println("<error>Unknown Country: " + country + "</error>");
}
} else {
out.println("<error>Unknown Request: " + cmd + "</error>");
}
}
out.flush();
out.close();
}
Aggregations