Search in sources :

Example 26 with MClient

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

the class PayrollViaEMail method sendIndividualMail.

//	sendBPGroup
/**
	 * 	Send Individual Mail
	 *	@param bPartnerId user
	 *	@param unSubscribe unsubscribe message
	 *	@return true if mail has been sent
	 */
private Boolean sendIndividualMail(int bPartnerId, String unSubscribe) {
    try {
        MBPartner employee = new MBPartner(getCtx(), bPartnerId, null);
        String message = mailText.getMailText(true);
        if (unSubscribe != null)
            message += unSubscribe;
        StringBuffer whereClause = new StringBuffer();
        whereClause.append(MBPartnerLocation.COLUMNNAME_C_BPartner_ID).append(" = ? AND ").append(MBPartnerLocation.COLUMNNAME_ContactType).append("=?");
        MBPartnerLocation location = new Query(getCtx(), MBPartnerLocation.Table_Name, whereClause.toString(), get_TrxName()).setOnlyActiveRecords(true).setParameters(bPartnerId, MBPartnerLocation.CONTACTTYPE_Primary).first();
        if (location == null) {
            addLog(0, null, null, employee.getName() + " @Email@ @NotFound@");
            return false;
        }
        MClient client = MClient.get(getCtx());
        String eMailFrom = client.getRequestEMail();
        String emailFrom = location.get_ValueAsString("EMail");
        String userMailFrom = client.getRequestUser();
        String password = client.getRequestUserPW();
        //	FR [ 402 ]
        //	Add support to new send mail
        EMail email = new EMail(client, eMailFrom, emailFrom, mailText.getMailHeader(), message);
        if (mailText.isHtml())
            email.setMessageHTML(mailText.getMailHeader(), message);
        else {
            email.setSubject(mailText.getMailHeader());
            email.setMessageText(message);
        }
        email.addAttachment(CreatePDF(bPartnerId));
        if (!email.isValid() && !email.isValid(true)) {
            log.warning("NOT VALID - " + email);
            employee.setIsActive(false);
            employee.save();
            return Boolean.FALSE;
        }
        email.createAuthenticator(userMailFrom, password);
        boolean OK = EMail.SENT_OK.equals(email.send());
        if (OK) {
            addLog(0, null, null, employee.getName() + " @Email@ @OK@");
            log.fine(employee.getURL());
        } else
            log.warning("FAILURE - " + employee.getURL());
        addLog(0, null, null, (OK ? "@OK@" : "@ERROR@") + " - " + emailFrom);
        return OK;
    } catch (Exception e) {
        return Boolean.FALSE;
    }
}
Also used : Query(org.compiere.model.Query) MBPartner(org.compiere.model.MBPartner) EMail(org.compiere.util.EMail) MBPartnerLocation(org.compiere.model.MBPartnerLocation) MClient(org.compiere.model.MClient)

Example 27 with MClient

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

the class AdempiereMonitor method createLogMgtPage.

//	createSummaryPage
/**
	 * 	Add Log Management to page
	 *	@param bb body
	 */
private void createLogMgtPage(body bb) {
    bb.addElement(new hr());
    //	Ini Parameters
    table table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //
    Properties ctx = new Properties();
    MSystem system = MSystem.get(ctx);
    tr line = new tr();
    line.addElement(new th().addElement(system.getDBAddress()));
    line.addElement(new td().addElement(Ini.getAdempiereHome()));
    table.addElement(line);
    //	OS + Name
    line = new tr();
    String info = System.getProperty("os.name") + " " + System.getProperty("os.version");
    String s = System.getProperty("sun.os.patch.level");
    if (s != null && s.length() > 0)
        info += " (" + s + ")";
    line.addElement(new th().addElement(info));
    info = system.getName();
    if (system.getCustomPrefix() != null)
        info += " (" + system.getCustomPrefix() + ")";
    line.addElement(new td().addElement(info));
    table.addElement(line);
    //	Java + email
    line = new tr();
    info = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(system.getUserName()));
    table.addElement(line);
    //	DB + Instance
    line = new tr();
    CConnection cc = CConnection.get();
    AdempiereDatabase db = cc.getDatabase();
    info = db.getDescription();
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(cc.getConnectionURL()));
    //		line.addElement(new td().addElement(system.getDBInstance()));
    table.addElement(line);
    //	Processors/Support
    line = new tr();
    line.addElement(new th().addElement("Processor/Support"));
    line.addElement(new td().addElement(system.getNoProcessors() + "/" + system.getSupportUnits()));
    table.addElement(line);
    //	Memory
    line = new tr();
    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
    line.addElement(new th().addElement("VM Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getNonHeapMemoryUsage()).toString()));
    table.addElement(line);
    line = new tr();
    line.addElement(new th().addElement("Heap Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getHeapMemoryUsage()).toString()));
    table.addElement(line);
    //	Runtime
    line = new tr();
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    line.addElement(new th().addElement("Runtime " + rt.getName()));
    line.addElement(new td().addElement(TimeUtil.formatElapsed(rt.getUptime())));
    table.addElement(line);
    //	Threads
    line = new tr();
    ThreadMXBean th = ManagementFactory.getThreadMXBean();
    line.addElement(new th().addElement("Threads " + th.getThreadCount()));
    line.addElement(new td().addElement("Peak=" + th.getPeakThreadCount() + ", Demons=" + th.getDaemonThreadCount() + ", Total=" + th.getTotalStartedThreadCount()));
    table.addElement(line);
    //Transactions
    Trx[] trxs = Trx.getActiveTransactions();
    for (Trx trx : trxs) {
        if (trx != null && trx.isActive()) {
            line = new tr();
            line.addElement(new th().addElement("Active Transaction "));
            line.addElement(new td().addElement("Name=" + trx.getTrxName() + ", StartTime=" + trx.getStartTime()));
            table.addElement(line);
        }
    }
    //	Cache Reset
    line = new tr();
    line.addElement(new th().addElement(CacheMgt.get().toStringX()));
    line.addElement(new td().addElement(new a("adempiereMonitor?CacheReset=Yes", "Reset Cache")));
    table.addElement(line);
    //	Trace Level
    line = new tr();
    line.addElement(new th().addElement(new label("TraceLevel").addElement("Trace Log Level")));
    form myForm = new form("adempiereMonitor", form.METHOD_POST, form.ENC_DEFAULT);
    //	LogLevel Selection
    option[] options = new option[CLogMgt.LEVELS.length];
    for (int i = 0; i < options.length; i++) {
        options[i] = new option(CLogMgt.LEVELS[i].getName());
        options[i].addElement(CLogMgt.LEVELS[i].getName());
        if (CLogMgt.LEVELS[i] == CLogMgt.getLevel())
            options[i].setSelected(true);
    }
    select sel = new select("TraceLevel", options);
    myForm.addElement(sel);
    myForm.addElement(new input(input.TYPE_SUBMIT, "Set", "Set"));
    line.addElement(new td().addElement(myForm));
    table.addElement(line);
    //
    line = new tr();
    CLogFile fileHandler = CLogFile.get(true, null, false);
    line.addElement(new th().addElement("Trace File"));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=" + fileHandler.getFileName(), "Current")));
    table.addElement(line);
    //
    line = new tr();
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=ROTATE", "Rotate Trace Log")));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=DELETE", "Delete all Trace Logs")));
    table.addElement(line);
    //
    bb.addElement(table);
    //	List Log Files
    p p = new p();
    p.addElement(new b("All Log Files: "));
    //	All in dir
    File logDir = fileHandler.getLogDirectory();
    if (logDir != null && logDir.isDirectory()) {
        File[] logs = logDir.listFiles();
        for (int i = 0; i < logs.length; i++) {
            // Skip if is not a file - teo_sarca [ 1726066 ]
            if (!logs[i].isFile())
                continue;
            if (i != 0)
                p.addElement(" - ");
            String fileName = logs[i].getAbsolutePath();
            a link = new a("adempiereMonitor?Trace=" + fileName, fileName);
            p.addElement(link);
            int size = (int) (logs[i].length() / 1024);
            if (size < 1024)
                p.addElement(" (" + size + "k)");
            else
                p.addElement(" (" + size / 1024 + "M)");
        }
    }
    bb.addElement(p);
    //	Clients and Web Stores
    table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //	
    line = new tr();
    MClient[] clients = MClient.getAll(ctx);
    line.addElement(new th().addElement("Client #" + clients.length + " - EMail Test:"));
    p = new p();
    for (int i = 0; i < clients.length; i++) {
        MClient client = clients[i];
        if (i > 0)
            p.addElement(" - ");
        p.addElement(new a("adempiereMonitor?EMail=" + client.getAD_Client_ID(), client.getName()));
    }
    if (clients.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //	
    line = new tr();
    MStore[] wstores = MStore.getActive();
    line.addElement(new th().addElement("Active Web Stores #" + wstores.length));
    p = new p();
    for (int i = 0; i < wstores.length; i++) {
        MStore store = wstores[i];
        if (i > 0)
            p.addElement(" - ");
        a a = new a(store.getWebContext(), store.getName());
        a.setTarget("t" + i);
        p.addElement(a);
    }
    if (wstores.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //
    bb.addElement(table);
}
Also used : org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) org.apache.ecs.xhtml.hr(org.apache.ecs.xhtml.hr) Properties(java.util.Properties) MClient(org.compiere.model.MClient) MemoryMXBean(java.lang.management.MemoryMXBean) Trx(org.compiere.util.Trx) MSystem(org.compiere.model.MSystem) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) ThreadMXBean(java.lang.management.ThreadMXBean) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) CLogFile(org.compiere.util.CLogFile) org.apache.ecs.xhtml.b(org.apache.ecs.xhtml.b) RuntimeMXBean(java.lang.management.RuntimeMXBean) org.apache.ecs.xhtml.label(org.apache.ecs.xhtml.label) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) CConnection(org.compiere.db.CConnection) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) AdempiereDatabase(org.compiere.db.AdempiereDatabase) org.apache.ecs.xhtml.th(org.apache.ecs.xhtml.th) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) CMemoryUsage(org.compiere.util.CMemoryUsage) MStore(org.compiere.model.MStore) CLogFile(org.compiere.util.CLogFile) File(java.io.File) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 28 with MClient

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

the class AdempiereMonitor method processEMailParameter.

//	processTraceParameter
/**
	 * 	Process EMail Parameter
	 *	@param request request
	 *	@param response response
	 *	@return true if it was a email request with output
	 *	@throws ServletException
	 *	@throws IOException
	 */
private boolean processEMailParameter(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String email = WebUtil.getParameter(request, "EMail");
    if (email == null || email.length() == 0)
        return false;
    int AD_Client_ID = -1;
    try {
        AD_Client_ID = Integer.parseInt(email);
    } catch (Exception e) {
        log.warning("Parsing: " + email + " - " + e.toString());
    }
    if (AD_Client_ID < 0) {
        m_message = new p();
        m_message.addElement("No EMail: " + email);
        return false;
    }
    //	log.info ("Test EMail: " + AD_Client_ID);
    MClient client = MClient.get(new Properties(), AD_Client_ID);
    log.info("Test: " + client);
    m_message = new p();
    m_message.addElement(client.getName() + ": " + client.testEMail());
    return false;
}
Also used : org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) MClient(org.compiere.model.MClient)

Example 29 with MClient

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

the class SequenceCheck method checkClientSequences.

//	checkTableID
/**
	 *	Check/Initialize DocumentNo/Value Sequences for all Clients 	
	 *	@param ctx context
	 *	@param sp server process or null
	 */
private static void checkClientSequences(Properties ctx, SvrProcess sp) {
    String trxName = null;
    if (sp != null)
        trxName = sp.get_TrxName();
    // CarlosRuiz - globalqss - [ 1887608 ] SequenceCheck deadlock 
    // Commit previous work on AD_Sequence
    // previously could update a sequence record needed now that is going to create new ones
    Trx trx = Trx.get(trxName, false);
    trx.commit();
    //	Sequence for DocumentNo/Value
    MClient[] clients = MClient.getAll(ctx);
    for (int i = 0; i < clients.length; i++) {
        MClient client = clients[i];
        if (!client.isActive())
            continue;
        MSequence.checkClientSequences(ctx, client.getAD_Client_ID(), trxName);
    }
//	for all clients
}
Also used : Trx(org.compiere.util.Trx) MClient(org.compiere.model.MClient)

Example 30 with MClient

use of org.compiere.model.MClient 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)

Aggregations

MClient (org.compiere.model.MClient)50 SQLException (java.sql.SQLException)11 ResultSet (java.sql.ResultSet)9 Timestamp (java.sql.Timestamp)9 Properties (java.util.Properties)9 PreparedStatement (java.sql.PreparedStatement)8 File (java.io.File)7 MBPartner (org.compiere.model.MBPartner)7 MUser (org.compiere.model.MUser)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MWarehouse (org.compiere.model.MWarehouse)5 AdempiereUserError (org.compiere.util.AdempiereUserError)5 Enumeration (java.util.Enumeration)4 MInvoice (org.compiere.model.MInvoice)4 MMailText (org.compiere.model.MMailText)4 PO (org.compiere.model.PO)4 Query (org.compiere.model.Query)4 ReportEngine (org.compiere.print.ReportEngine)4 Element (org.w3c.dom.Element)4 BigDecimal (java.math.BigDecimal)3