Search in sources :

Example 11 with MLocation

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) {
        MobileUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    //  Get Mandatory Parameters
    String columnName = MobileUtil.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("")) {
        MobileUtil.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
    MobileDoc doc = MobileDoc.createPopup(mField.getHeader());
    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);
    //
    div div = new div();
    div.setClass("toolbar");
    h1 header = new h1();
    header.setID("pageTitle");
    div.addElement(header);
    a anchor = new a();
    anchor.setID("backButton");
    anchor.setClass("button");
    div.addElement(anchor);
    doc.getBody().addElement(fillForm(ws, action, location, targetBase, hasDependents || hasCallout)).addElement(reset).addElement(div);
    //
    //	log.trace(log.l6_Database, doc.toString());
    MobileUtil.createResponse(request, response, this, null, doc, true);
}
Also used : org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) HttpSession(javax.servlet.http.HttpSession) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.button(org.apache.ecs.xhtml.button) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) MLocation(org.compiere.model.MLocation)

Example 12 with MLocation

use of org.compiere.model.MLocation in project adempiere by adempiere.

the class InvoiceGenerateFromShipment method createInvoiceLineFromShipmentLine.

/**
	 * 	Create Invoice Line from Shipment Line
	 *	@param order order
	 *	@param inOut shipment header
	 *	@param inOutLine shipment line
	 */
private MInvoice createInvoiceLineFromShipmentLine(MInvoice invoice, MOrder order, MInOut inOut, MInOutLine inOutLine) {
    if (invoice == null) {
        invoice = new MInvoice(inOut, p_DateInvoiced);
        if (!invoice.save())
            throw new IllegalStateException("Could not create Invoice (s)");
    }
    //	Create Shipment Comment Line
    if (m_ship == null || m_ship.getM_InOut_ID() != inOut.getM_InOut_ID()) {
        MDocType dt = MDocType.get(getCtx(), inOut.getC_DocType_ID());
        if (m_bp == null || m_bp.getC_BPartner_ID() != inOut.getC_BPartner_ID())
            m_bp = new MBPartner(getCtx(), inOut.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 referenceDescr = dt.getPrintName(m_bp.getAD_Language()) + ": " + inOut.getDocumentNo() + " - " + format.format(inOut.getMovementDate());
        m_ship = inOut;
        //
        MInvoiceLine descInvLine = new MInvoiceLine(invoice);
        descInvLine.setIsDescription(true);
        descInvLine.setDescription(referenceDescr);
        descInvLine.setLine(m_line + inOutLine.getLine() - 2);
        if (!descInvLine.save())
            throw new IllegalStateException("Could not create Invoice Comment Line (sh)");
        //	Optional Ship Address if not Bill Address
        if (order.getBill_Location_ID() != inOut.getC_BPartner_Location_ID()) {
            MLocation addr = MLocation.getBPLocation(getCtx(), inOut.getC_BPartner_Location_ID(), null);
            descInvLine = new MInvoiceLine(invoice);
            descInvLine.setIsDescription(true);
            descInvLine.setDescription(addr.toString());
            descInvLine.setLine(m_line + inOutLine.getLine() - 1);
            if (!descInvLine.save())
                throw new IllegalStateException("Could not create Invoice Comment Line 2 (sh)");
        }
    }
    //	
    MInvoiceLine invLine = new MInvoiceLine(invoice);
    invLine.setShipLine(inOutLine);
    if (inOutLine.sameOrderLineUOM())
        invLine.setQtyEntered(inOutLine.getQtyEntered());
    else
        invLine.setQtyEntered(inOutLine.getMovementQty());
    invLine.setQtyInvoiced(inOutLine.getMovementQty());
    invLine.setLine(m_line + inOutLine.getLine());
    //@Trifon - special handling when ShipLine.ToBeInvoiced='N'
    String toBeInvoiced = inOutLine.get_ValueAsString("ToBeInvoiced");
    if ("N".equals(toBeInvoiced) || "false".equals(toBeInvoiced)) {
        invLine.setPriceEntered(Env.ZERO);
        invLine.setPriceActual(Env.ZERO);
        invLine.setPriceList(Env.ZERO);
        invLine.setPriceLimit(Env.ZERO);
        //setC_Tax_ID(oLine.getC_Tax_ID());
        invLine.setLineNetAmt(Env.ZERO);
        invLine.setIsDescription(true);
    }
    if (!invLine.save())
        throw new IllegalStateException("Could not create Invoice Line (s)");
    //	Link
    inOutLine.setIsInvoiced(true);
    if (!inOutLine.save())
        throw new IllegalStateException("Could not update Shipment Line");
    log.fine(invLine.toString());
    return invoice;
}
Also used : MDocType(org.compiere.model.MDocType) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) MLocation(org.compiere.model.MLocation) MClient(org.compiere.model.MClient)

Example 13 with MLocation

use of org.compiere.model.MLocation in project adempiere by adempiere.

the class SB_InvoiceGenerateFromOrderLine 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());
}
Also used : MDocType(org.compiere.model.MDocType) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) MLocation(org.compiere.model.MLocation) MClient(org.compiere.model.MClient)

Example 14 with MLocation

use of org.compiere.model.MLocation in project adempiere by adempiere.

the class RegisterSystem method doIt.

//	prepare
/**
	 * 	DoIt
	 *	@return Message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    int AD_Registration_ID = getRecord_ID();
    log.info("doIt - AD_Registration_ID=" + AD_Registration_ID);
    //	Check Ststem
    MSystem sys = MSystem.get(getCtx());
    if (sys.getName().equals("?") || sys.getName().length() < 2)
        throw new AdempiereUserError("Set System Name in System Record");
    if (sys.getUserName().equals("?") || sys.getUserName().length() < 2)
        throw new AdempiereUserError("Set User Name (as in Web Store) in System Record");
    if (sys.getPassword().equals("?") || sys.getPassword().length() < 2)
        throw new AdempiereUserError("Set Password (as in Web Store) in System Record");
    //	Registration
    M_Registration reg = new M_Registration(getCtx(), AD_Registration_ID, get_TrxName());
    //	Location
    MLocation loc = null;
    if (reg.getC_Location_ID() > 0) {
        loc = new MLocation(getCtx(), reg.getC_Location_ID(), get_TrxName());
        if (loc.getCity() == null || loc.getCity().length() < 2)
            throw new AdempiereUserError("No City in Address");
    }
    if (loc == null)
        throw new AdempiereUserError("Please enter Address with City");
    //	Create Query String
    String enc = WebEnv.ENCODING;
    //	Send GET Request
    StringBuffer urlString = new StringBuffer("http://www.adempiere.net").append("/wstore/registrationServlet?");
    //	System Info
    urlString.append("Name=").append(URLEncoder.encode(sys.getName(), enc)).append("&UserName=").append(URLEncoder.encode(sys.getUserName(), enc)).append("&Password=").append(URLEncoder.encode(sys.getPassword(), enc));
    //	Registration Info
    if (reg.getDescription() != null && reg.getDescription().length() > 0)
        urlString.append("&Description=").append(URLEncoder.encode(reg.getDescription(), enc));
    urlString.append("&IsInProduction=").append(reg.isInProduction() ? "Y" : "N");
    if (reg.getStartProductionDate() != null)
        urlString.append("&StartProductionDate=").append(URLEncoder.encode(String.valueOf(reg.getStartProductionDate()), enc));
    urlString.append("&IsAllowPublish=").append(reg.isAllowPublish() ? "Y" : "N").append("&NumberEmployees=").append(URLEncoder.encode(String.valueOf(reg.getNumberEmployees()), enc)).append("&C_Currency_ID=").append(URLEncoder.encode(String.valueOf(reg.getC_Currency_ID()), enc)).append("&SalesVolume=").append(URLEncoder.encode(String.valueOf(reg.getSalesVolume()), enc));
    if (reg.getIndustryInfo() != null && reg.getIndustryInfo().length() > 0)
        urlString.append("&IndustryInfo=").append(URLEncoder.encode(reg.getIndustryInfo(), enc));
    if (reg.getPlatformInfo() != null && reg.getPlatformInfo().length() > 0)
        urlString.append("&PlatformInfo=").append(URLEncoder.encode(reg.getPlatformInfo(), enc));
    urlString.append("&IsRegistered=").append(reg.isRegistered() ? "Y" : "N").append("&Record_ID=").append(URLEncoder.encode(String.valueOf(reg.getRecord_ID()), enc));
    //	Address
    urlString.append("&City=").append(URLEncoder.encode(loc.getCity(), enc)).append("&C_Country_ID=").append(URLEncoder.encode(String.valueOf(loc.getC_Country_ID()), enc));
    //	Statistics
    if (reg.isAllowStatistics()) {
        urlString.append("&NumClient=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_Client")), enc)).append("&NumOrg=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_Org")), enc)).append("&NumBPartner=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM C_BPartner")), enc)).append("&NumUser=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_User")), enc)).append("&NumProduct=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM M_Product")), enc)).append("&NumInvoice=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM C_Invoice")), enc));
    }
    log.fine(urlString.toString());
    //	Send it
    URL url = new URL(urlString.toString());
    StringBuffer sb = new StringBuffer();
    try {
        URLConnection uc = url.openConnection();
        InputStreamReader in = new InputStreamReader(uc.getInputStream());
        int c;
        while ((c = in.read()) != -1) sb.append((char) c);
        in.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, "Connect - " + e.toString());
        throw new IllegalStateException("Cannot connect to Server - Please try later");
    }
    //
    String info = sb.toString();
    log.info("Response=" + info);
    //	Record at the end
    int index = sb.indexOf("Record_ID=");
    if (index != -1) {
        try {
            int Record_ID = Integer.parseInt(sb.substring(index + 10));
            reg.setRecord_ID(Record_ID);
            reg.setIsRegistered(true);
            reg.saveEx();
            //
            info = info.substring(0, index);
        } catch (Exception e) {
            log.log(Level.SEVERE, "Record - ", e);
        }
    }
    return info;
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) InputStreamReader(java.io.InputStreamReader) MSystem(org.compiere.model.MSystem) MLocation(org.compiere.model.MLocation) URL(java.net.URL) URLConnection(java.net.URLConnection) M_Registration(org.compiere.model.M_Registration)

Example 15 with MLocation

use of org.compiere.model.MLocation in project adempiere by adempiere.

the class MBPartnerLocationTest method testCreatePartnerLocation.

public void testCreatePartnerLocation() {
    try {
        location = new MLocation(getCtx(), 0, getTrxName());
        location.setC_Country_ID(getC_Country_ID("United States"));
        location.setC_Region_ID(getC_Region_ID("CA"));
        location.setCity("Windsor");
        location.setAddress1("Happy Lane");
        location.setAddress2("Happy Lane 2");
        String zipcode = ("95492");
        location.setPostal(zipcode);
        location.setPostal_Add(zipcode);
        location.setAD_Org_ID(0);
        location.saveEx();
        m_group = new MBPGroup(getCtx(), 0, getTrxName());
        // N
        m_group.setName("Test Group Name");
        // N
        m_group.setIsConfidentialInfo(false);
        m_group.setIsDefault(false);
        m_group.setPriorityBase(MBPGroup.PRIORITYBASE_Same);
        m_group.saveEx();
        m_partner = new MBPartner(getCtx(), 0, getTrxName());
        m_partner.setValue("");
        m_partner.setName("Test Business Partner Location");
        m_partner.setName2(null);
        m_partner.setDUNS("");
        m_partner.setFirstSale(null);
        //
        m_partner.setSO_CreditLimit(Env.ZERO);
        m_partner.setSO_CreditUsed(Env.ZERO);
        m_partner.setTotalOpenBalance(Env.ZERO);
        //      s_m_partner.setRating(null);
        //
        m_partner.setActualLifeTimeValue(Env.ZERO);
        m_partner.setPotentialLifeTimeValue(Env.ZERO);
        m_partner.setAcqusitionCost(Env.ZERO);
        m_partner.setShareOfCustomer(0);
        m_partner.setSalesVolume(0);
        m_partner.setBPGroup(m_group);
        // Reset Created, Updated to current system time ( teo_sarca )
        if (m_partner.save()) {
            bpl = new MBPartnerLocation(getCtx(), 0, getTrxName());
            bpl.setIsActive(true);
            bpl.setName("Test Business Partner Location");
            bpl.setC_BPartner_ID(m_partner.get_ID());
            bpl.setC_Location_ID(location.get_ID());
            bpl.saveEx();
        }
        commit();
    } catch (Exception e) {
        fail(e.getLocalizedMessage());
    }
}
Also used : MBPGroup(org.compiere.model.MBPGroup) MBPartner(org.compiere.model.MBPartner) MLocation(org.compiere.model.MLocation) SQLException(java.sql.SQLException) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Aggregations

MLocation (org.compiere.model.MLocation)28 MBPartner (org.compiere.model.MBPartner)13 MBPartnerLocation (org.compiere.model.MBPartnerLocation)10 Properties (java.util.Properties)8 MUser (org.compiere.model.MUser)7 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 HttpSession (javax.servlet.http.HttpSession)6 BigDecimal (java.math.BigDecimal)5 SQLException (java.sql.SQLException)5 Query (org.compiere.model.Query)5 org.apache.ecs.xhtml.button (org.apache.ecs.xhtml.button)4 MInvoice (org.compiere.model.MInvoice)4 MInvoiceLine (org.compiere.model.MInvoiceLine)4 MClient (org.compiere.model.MClient)3 MDocType (org.compiere.model.MDocType)3 Timestamp (java.sql.Timestamp)2 org.apache.ecs.xhtml.b (org.apache.ecs.xhtml.b)2 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)2 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)2