use of org.compiere.model.MLocation in project adempiere by adempiere.
the class ConvertLead method doIt.
@Override
protected String doIt() throws Exception {
if (p_AD_User_ID <= 0)
throw new FillMandatoryException("AD_User_ID");
MUser lead = new MUser(getCtx(), p_AD_User_ID, get_TrxName());
if (!lead.isSalesLead() || lead.getC_BPartner_ID() != 0)
throw new AdempiereUserError("Lead already converted");
MBPartner bp = MBPartner.getTemplate(getCtx(), getAD_Client_ID());
bp.set_TrxName(get_TrxName());
if (!Util.isEmpty(lead.getBPName()))
bp.setName(lead.getBPName());
else
bp.setName(lead.getName());
bp.saveEx();
addLog("Business Partner created.");
lead.setC_BPartner_ID(bp.getC_BPartner_ID());
if (lead.getC_Location_ID() != 0) {
MLocation leadAddress = (MLocation) lead.getC_Location();
MBPartnerLocation loc = new MBPartnerLocation(bp);
MLocation address = new MLocation(getCtx(), 0, get_TrxName());
PO.copyValues(leadAddress, address);
address.saveEx();
loc.setC_Location_ID(address.getC_Location_ID());
loc.setPhone(lead.getPhone());
loc.setPhone2(lead.getPhone2());
loc.setFax(lead.getFax());
loc.saveEx();
lead.setC_BPartner_Location_ID(loc.getC_BPartner_Location_ID());
addLog("Contact Location added.");
}
// company address
if (lead.getBP_Location_ID() != 0) {
MLocation leadAddress = (MLocation) lead.getBP_Location();
MBPartnerLocation loc = new MBPartnerLocation(bp);
MLocation address = new MLocation(getCtx(), 0, get_TrxName());
PO.copyValues(leadAddress, address);
address.saveEx();
loc.setC_Location_ID(address.getC_Location_ID());
loc.saveEx();
addLog("BP Address added.");
}
if (p_createOpportunity) {
MOpportunity op = new MOpportunity(getCtx(), 0, get_TrxName());
op.setAD_User_ID(lead.getAD_User_ID());
op.setC_BPartner_ID(bp.getC_BPartner_ID());
op.setExpectedCloseDate(p_expectedCloseDate != null ? p_expectedCloseDate : new Timestamp(System.currentTimeMillis()));
op.setOpportunityAmt(p_opportunityAmt != null ? p_opportunityAmt : Env.ZERO);
if (p_C_SalesStage_ID > 0)
op.setC_SalesStage_ID(p_C_SalesStage_ID);
String sql = "SELECT Probability FROM C_SalesStage WHERE C_SalesStage_ID = ?";
BigDecimal probability = DB.getSQLValueBD(get_TrxName(), sql, p_C_SalesStage_ID);
op.setProbability(probability != null ? probability : Env.ZERO);
op.setDescription(p_Description);
if (p_C_Currency_ID > 0)
op.setC_Currency_ID(p_C_Currency_ID);
else
op.setC_Currency_ID(Env.getContextAsInt(getCtx(), "$C_Currency_ID"));
if (p_SalesRep_ID > 0)
op.setSalesRep_ID(p_SalesRep_ID);
else if (lead.getSalesRep_ID() > 0)
op.setSalesRep_ID(lead.getSalesRep_ID());
else
op.setSalesRep_ID(Env.getContextAsInt(getCtx(), "#SalesRep_ID"));
op.setC_Campaign_ID(lead.getC_Campaign_ID());
op.saveEx();
addLog("Opportunity created.");
}
lead.setIsSalesLead(false);
lead.setLeadStatus(MUser.LEADSTATUS_Converted);
lead.saveEx();
addLog("Lead converted.");
return "@OK@";
}
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();
String whereClause = MBPartner.COLUMNNAME_Value + "=?";
MBPartner bp = new Query(ctx, MBPartner.Table_Name, whereClause, null).setParameters(new Object[] { 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 LocationTag method doStartTag.
/**
* Start Tag
* @return SKIP_BODY
* @throws JspException
*/
public int doStartTag() throws JspException {
Properties ctx = JSPEnv.getCtx((HttpServletRequest) pageContext.getRequest());
MLocation loc = new MLocation(ctx, 0, null);
HtmlCode html = new HtmlCode();
int C_Country_ID = getCountryID(loc);
int C_Region_ID = getRegionID(loc);
option[] countries = getCountries(loc, C_Country_ID);
// if (m_country != null) m_country.DisplaySequence;
String name = null;
label lbl = null;
input field = null;
select sel = null;
// City ***********************************************************
name = "City";
String city = (String) ExpressionUtil.evalNotNull("location", "city", m_city_el, String.class, this, pageContext);
lbl = new label();
lbl.setFor(name);
lbl.setID("LBL_" + name);
lbl.addElement(Msg.translate(ctx, name));
html.addElement(lbl);
field = new input(input.TYPE_TEXT, name, city);
field.setSize(40).setMaxlength(60).setID("ID_" + name);
field.setClass(C_MANDATORY);
html.addElement(field);
html.addElement(new br());
// Postal ***********************************************************
name = "Postal";
String postal = (String) ExpressionUtil.evalNotNull("location", "postal", m_postal_el, String.class, this, pageContext);
lbl = new label();
lbl.setFor(name);
lbl.setID("LBL_" + name);
lbl.addElement(Msg.translate(ctx, name));
html.addElement(lbl);
field = new input(input.TYPE_TEXT, name, postal);
field.setSize(10).setMaxlength(10).setID("ID_" + name);
field.setClass(C_MANDATORY);
html.addElement(field);
html.addElement(new br());
// Region *******************************************************
name = "C_Region_ID";
lbl = new label();
lbl.setFor(name);
lbl.setID("LBL_" + name);
String regionName = (String) ExpressionUtil.evalNotNull("location", "regionName", m_regionName_el, String.class, this, pageContext);
field = new input(input.TYPE_TEXT, "RegionName", regionName);
field.setSize(40).setMaxlength(60).setID("ID_RegionName");
if (m_country != null && m_country.isHasRegion()) {
sel = new select(name, getRegions(loc, C_Country_ID, C_Region_ID));
sel.setID("ID_" + name);
lbl.addElement(m_country.getRegionName());
html.addElement(lbl);
html.addElement(sel);
html.addElement(new span(" - "));
html.addElement(field);
} else {
lbl.addElement(Msg.translate(ctx, name));
html.addElement(lbl);
html.addElement(field);
}
html.addElement(new br());
// Country *******************************************************
name = "C_Country_ID";
lbl = new label();
lbl.setFor(name);
lbl.setID("LBL_" + name);
lbl.addElement(Msg.translate(ctx, name));
html.addElement(lbl);
sel = new select(name, countries);
sel.setID("ID_" + name);
sel.setClass(C_MANDATORY);
sel.setOnChange("changeCountry('ID_" + name + "');");
html.addElement(sel);
html.addElement(new br());
log.fine("C_Country_ID=" + C_Country_ID + ", C_Region_ID=" + C_Region_ID + ", RegionName=" + regionName + ", City=" + city + ", Postal=" + postal);
JspWriter out = pageContext.getOut();
html.output(out);
//
return (SKIP_BODY);
}
use of org.compiere.model.MLocation in project adempiere by adempiere.
the class InvoiceGenerate method createLine.
// createLine
/**
* Create Invoice Line from Shipment
* @param order order
* @param ship shipment header
* @param sLine shipment line
*/
private void createLine(MOrder order, MInOut ship, MInOutLine sLine) {
if (m_invoice == null) {
m_invoice = new MInvoice(order, 0, p_DateInvoiced);
if (!m_invoice.save())
throw new IllegalStateException("Could not create Invoice (s)");
}
// Create Shipment Comment Line
if (m_ship == null || m_ship.getM_InOut_ID() != ship.getM_InOut_ID()) {
MDocType dt = MDocType.get(getCtx(), ship.getC_DocType_ID());
if (m_bp == null || m_bp.getC_BPartner_ID() != ship.getC_BPartner_ID())
m_bp = new MBPartner(getCtx(), ship.getC_BPartner_ID(), get_TrxName());
// Reference: Delivery: 12345 - 12.12.12
MClient client = MClient.get(getCtx(), order.getAD_Client_ID());
String AD_Language = client.getAD_Language();
if (client.isMultiLingualDocument() && m_bp.getAD_Language() != null)
AD_Language = m_bp.getAD_Language();
if (AD_Language == null)
AD_Language = Language.getBaseAD_Language();
java.text.SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.Date, Language.getLanguage(AD_Language));
String reference = dt.getPrintName(m_bp.getAD_Language()) + ": " + ship.getDocumentNo() + " - " + format.format(ship.getMovementDate());
m_ship = ship;
//
MInvoiceLine line = new MInvoiceLine(m_invoice);
line.setIsDescription(true);
line.setDescription(reference);
line.setLine(m_line + sLine.getLine() - 2);
if (!line.save())
throw new IllegalStateException("Could not create Invoice Comment Line (sh)");
// Optional Ship Address if not Bill Address
if (order.getBill_Location_ID() != ship.getC_BPartner_Location_ID()) {
MLocation addr = MLocation.getBPLocation(getCtx(), ship.getC_BPartner_Location_ID(), null);
line = new MInvoiceLine(m_invoice);
line.setIsDescription(true);
line.setDescription(addr.toString());
line.setLine(m_line + sLine.getLine() - 1);
if (!line.save())
throw new IllegalStateException("Could not create Invoice Comment Line 2 (sh)");
}
}
//
MInvoiceLine line = new MInvoiceLine(m_invoice);
line.setShipLine(sLine);
if (sLine.sameOrderLineUOM())
line.setQtyEntered(sLine.getQtyEntered());
else
line.setQtyEntered(sLine.getMovementQty());
line.setQtyInvoiced(sLine.getMovementQty());
line.setLine(m_line + sLine.getLine());
//@Trifon - special handling when ShipLine.ToBeInvoiced='N'
String toBeInvoiced = sLine.get_ValueAsString("ToBeInvoiced");
if ("N".equals(toBeInvoiced)) {
line.setPriceEntered(Env.ZERO);
line.setPriceActual(Env.ZERO);
line.setPriceLimit(Env.ZERO);
line.setPriceList(Env.ZERO);
//setC_Tax_ID(oLine.getC_Tax_ID());
line.setLineNetAmt(Env.ZERO);
line.setIsDescription(true);
}
if (!line.save())
throw new IllegalStateException("Could not create Invoice Line (s)");
// Link
sLine.setIsInvoiced(true);
if (!sLine.save())
throw new IllegalStateException("Could not update Shipment Line");
log.fine(line.toString());
}
use of org.compiere.model.MLocation in project adempiere by adempiere.
the class WLocation method doGet.
/**
* Process the HTTP Get request - initial Start
* Needs to have parameters FormName and ColumnName
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.fine("");
HttpSession sess = request.getSession();
WWindowStatus ws = WWindowStatus.get(request);
if (ws == null) {
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
// Get Mandatory Parameters
String columnName = WebUtil.getParameter(request, "ColumnName");
log.info("ColumnName=" + columnName + " - " + ws.toString());
//
GridField mField = ws.curTab.getField(columnName);
log.config("ColumnName=" + columnName + ", MField=" + mField);
if (mField == null || columnName == null || columnName.equals("")) {
WebUtil.createErrorPage(request, response, this, Msg.getMsg(ws.ctx, "ParameterMissing"));
return;
}
MLocation location = null;
Object value = mField.getValue();
if (value != null && value instanceof Integer)
location = new MLocation(ws.ctx, ((Integer) value).intValue(), null);
else
location = new MLocation(ws.ctx, 0, null);
//String targetBase = "parent.WWindow." + WWindow.FORM_NAME + "." + columnName;
String targetBase = "opener.WWindow." + WWindow.FORM_NAME + "." + columnName;
String action = request.getRequestURI();
// Create Document
WebDoc doc = WebDoc.createPopup(mField.getHeader());
doc.addPopupClose(ws.ctx);
boolean hasDependents = ws.curTab.hasDependants(columnName);
boolean hasCallout = mField.getCallout().length() > 0;
// Reset
button reset = new button();
// translate
reset.addElement("Reset");
String script = targetBase + "D.value='';" + targetBase + "F.value='';closePopup();";
if (hasDependents || hasCallout)
script += "startUpdate(" + targetBase + "F);";
reset.setOnClick(script);
//
doc.getTable().addElement(new tr().addElement(fillForm(ws, action, location, targetBase, hasDependents || hasCallout)).addElement(reset));
//
doc.addPopupClose(ws.ctx);
// log.trace(log.l6_Database, doc.toString());
WebUtil.createResponse(request, response, this, null, doc, true);
}
Aggregations