Search in sources :

Example 26 with MBPartner

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

the class PayrollViaEMail method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message
	 *  @throws Exception
	 */
protected String doIt() throws Exception {
    log.info("R_MailText_ID=" + mailTextId);
    //	Mail Test
    mailText = new MMailText(getCtx(), mailTextId, get_TrxName());
    if (mailText.getR_MailText_ID() == 0)
        throw new Exception("@R_MailText_ID@=" + mailTextId + " @NotFound@ ");
    //	Client Info
    client = MClient.get(getCtx());
    if (client.getAD_Client_ID() == 0)
        throw new Exception(" @AD_Client_ID@  @NotFound@ ");
    if (client.getSMTPHost() == null || client.getSMTPHost().length() == 0)
        throw new Exception("@SMTPHost@  @NotFound@ ");
    //
    long start = System.currentTimeMillis();
    if (bPartnerId > 0) {
        employee = new MBPartner(getCtx(), bPartnerId, get_TrxName());
        if (employee == null)
            throw new Exception("@C_BPartner_ID@=" + bPartnerId + " @NotFound@");
        sendIndividualMail(bPartnerId, null);
    } else
        sendBPGroup();
    log.fine("From " + employee);
    return "@Created@=" + m_counter + ", @Errors@=" + m_errors + " - " + (System.currentTimeMillis() - start) + "ms";
}
Also used : MMailText(org.compiere.model.MMailText) MBPartner(org.compiere.model.MBPartner)

Example 27 with MBPartner

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

the class HRCreateInvoice method doIt.

//	prepare
/**
     * Process
     * @return message
     * @throws Exception
     */
protected String doIt() throws Exception {
    MHRProcess process = new MHRProcess(getCtx(), getPayrollProcessId(), get_TrxName());
    final Timestamp dateInvoice = getDateInvoiced() != null ? getDateInvoiced() : process.getHR_Period_ID() > 0 ? process.getHR_Period().getStartDate() : process.getDateAcct();
    Arrays.stream(getEmployeeIds(process)).filter(partnerId -> partnerId > 0).forEach(partnerId -> {
        Trx.run(trxName -> {
            int lastPartnerId = 0;
            MHREmployee employee = null;
            MInvoice invoice = null;
            for (MHRMovement movement : getPayrollMovement(getPayrollProcessId(), partnerId, trxName)) {
                MBPartner partner = new MBPartner(getCtx(), partnerId, trxName);
                MHRAttribute attribute = MHRAttribute.getByConceptIdAndPartnerId(movement.getCtx(), movement.getHR_Concept_ID(), movement.getC_BPartner_ID(), movement.getValidFrom(), trxName);
                if (attribute != null && attribute.getC_DocType_ID() == 0) {
                    log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
                    addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
                    continue;
                }
                if (attribute != null && attribute.getC_Charge_ID() == 0) {
                    log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
                    addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + "  @HR_Concept_ID@  " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
                    continue;
                }
                if (movement.getC_BPartner_ID() != lastPartnerId) {
                    lastPartnerId = movement.getC_BPartner_ID();
                    employee = MHREmployee.getActiveEmployee(getCtx(), partner.getC_BPartner_ID(), trxName);
                    invoice = createInvoice(process, partner, employee, attribute.getC_DocType_ID(), dateInvoice);
                    if (invoice == null)
                        continue;
                }
                if (invoice != null)
                    createInvoiceLine(invoice, employee, movement, attribute.getC_Charge_ID());
            }
        });
    });
    return "@OK@";
}
Also used : Arrays(java.util.Arrays) MHREmployee(org.eevolution.model.MHREmployee) MHRAttribute(org.eevolution.model.MHRAttribute) Timestamp(java.sql.Timestamp) Env(org.compiere.util.Env) MPaymentTerm(org.compiere.model.MPaymentTerm) MBPartnerLocation(org.compiere.model.MBPartnerLocation) Level(java.util.logging.Level) MInvoice(org.compiere.model.MInvoice) MHRProcess(org.eevolution.model.MHRProcess) BigDecimal(java.math.BigDecimal) List(java.util.List) Query(org.compiere.model.Query) MHRMovement(org.eevolution.model.MHRMovement) MBPartner(org.compiere.model.MBPartner) MInvoiceLine(org.compiere.model.MInvoiceLine) Msg(org.compiere.util.Msg) Trx(org.compiere.util.Trx) DocAction(org.compiere.process.DocAction) I_C_BPartner(org.compiere.model.I_C_BPartner) I_C_BPartner_Location(org.compiere.model.I_C_BPartner_Location) MHRProcess(org.eevolution.model.MHRProcess) MHRAttribute(org.eevolution.model.MHRAttribute) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) Timestamp(java.sql.Timestamp) MHREmployee(org.eevolution.model.MHREmployee) MHRMovement(org.eevolution.model.MHRMovement)

Example 28 with MBPartner

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

the class RfQCreateSO method doIt.

//	prepare
/**
	 * 	Process.
	 * 	A Sales Order is created for the entered Business Partner.  
	 * 	A sales order line is created for each RfQ line quantity, 
	 * 	where "Offer Quantity" is selected.  
	 * 	If on the RfQ Line Quantity, an offer amount is entered (not 0), 
	 * 	that price is used. 
	 *	If a magin is entered on RfQ Line Quantity, it overwrites the 
	 *	general margin.  The margin is the percentage added to the 
	 *	Best Response Amount.
	 *	@return message
	 */
protected String doIt() throws Exception {
    MRfQ rfq = new MRfQ(getCtx(), p_C_RfQ_ID, get_TrxName());
    if (rfq.get_ID() == 0)
        throw new IllegalArgumentException("No RfQ found");
    log.info("doIt - " + rfq);
    if (rfq.getC_BPartner_ID() == 0 || rfq.getC_BPartner_Location_ID() == 0)
        throw new Exception("No Business Partner/Location");
    MBPartner bp = new MBPartner(getCtx(), rfq.getC_BPartner_ID(), get_TrxName());
    MOrder order = new MOrder(getCtx(), 0, get_TrxName());
    order.setIsSOTrx(true);
    if (p_C_DocType_ID != 0)
        order.setC_DocTypeTarget_ID(p_C_DocType_ID);
    else
        order.setC_DocTypeTarget_ID();
    order.setBPartner(bp);
    order.setC_BPartner_Location_ID(rfq.getC_BPartner_Location_ID());
    order.setSalesRep_ID(rfq.getSalesRep_ID());
    if (rfq.getDateWorkComplete() != null)
        order.setDatePromised(rfq.getDateWorkComplete());
    order.saveEx();
    MRfQLine[] lines = rfq.getLines();
    for (int i = 0; i < lines.length; i++) {
        MRfQLine line = lines[i];
        MRfQLineQty[] qtys = line.getQtys();
        for (int j = 0; j < qtys.length; j++) {
            MRfQLineQty qty = qtys[j];
            if (qty.isActive() && qty.isOfferQty()) {
                MOrderLine ol = new MOrderLine(order);
                ol.setM_Product_ID(line.getM_Product_ID(), qty.getC_UOM_ID());
                ol.setDescription(line.getDescription());
                ol.setQty(qty.getQty());
                //
                BigDecimal price = qty.getOfferAmt();
                if (price == null || price.signum() == 0) {
                    price = qty.getBestResponseAmt();
                    if (price == null || price.signum() == 0) {
                        price = Env.ZERO;
                        log.warning(" - BestResponse=0 - " + qty);
                    } else {
                        BigDecimal margin = qty.getMargin();
                        if (margin == null || margin.signum() == 0)
                            margin = rfq.getMargin();
                        if (margin != null && margin.signum() != 0) {
                            margin = margin.add(ONEHUNDRED);
                            price = price.multiply(margin).divide(ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }
                //	price
                ol.setPrice(price);
                ol.saveEx();
            }
        //	Offer Qty
        }
    //	All Qtys
    }
    //	All Lines
    //
    rfq.setC_Order_ID(order.getC_Order_ID());
    rfq.saveEx();
    return order.getDocumentNo();
}
Also used : MOrder(org.compiere.model.MOrder) MRfQ(org.compiere.model.MRfQ) MRfQLine(org.compiere.model.MRfQLine) MRfQLineQty(org.compiere.model.MRfQLineQty) MBPartner(org.compiere.model.MBPartner) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 29 with MBPartner

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

the class MUserTest method testCreateMBPartner.

public void testCreateMBPartner() {
    try {
        m_partner = new MBPartner(getCtx(), 0, getTrxName());
        m_partner.setValue("");
        m_partner.setName("Test MBPartner with contact");
        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);
        MBPGroup 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.setBPGroup(m_group);
        // Reset Created, Updated to current system time ( teo_sarca )
        if (m_partner.save()) {
            m_contact = new MUser(getCtx(), 0, getTrxName());
            m_contact.setName("Test Contact Name");
            m_contact.setIsActive(true);
            m_contact.setC_BPartner_ID(m_partner.get_ID());
            m_contact.saveEx();
        }
        commit();
    } catch (Exception e) {
        fail(e.getLocalizedMessage());
    }
}
Also used : MBPGroup(org.compiere.model.MBPGroup) MBPartner(org.compiere.model.MBPartner) MUser(org.compiere.model.MUser) SQLException(java.sql.SQLException)

Example 30 with MBPartner

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

the class POTest method testAD_OrgBP_ID_Issue.

/**
	 * BF [ 2859125 ] Can't set AD_OrgBP_ID
	 * https://sourceforge.net/tracker/index.php?func=detail&aid=2859125&group_id=176962&atid=879332#
	 */
public void testAD_OrgBP_ID_Issue() throws Exception {
    // Store Central
    MBPartner bp = new MBPartner(getCtx(), 50004, getTrxName());
    //
    // Try to change AD_OrgBP_ID field value to a new value
    final int old_org_id = bp.getAD_OrgBP_ID_Int();
    // Store East Org
    int new_org_id = 50005;
    if (old_org_id == new_org_id) {
        // Store Central
        new_org_id = 12;
    }
    bp.setAD_OrgBP_ID(new_org_id);
    //
    // Following line throws:
    // java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    // at org.compiere.model.X_C_BPartner.getAD_OrgBP_ID(X_C_BPartner.java:165)
    // at org.compiere.model.MBPartner.getAD_OrgBP_ID_Int(MBPartner.java:602)
    // at test.functional.POTest.testAD_OrgBP_ID_Issue(POTest.java:192)
    bp.getAD_OrgBP_ID_Int();
    //
    // Test save:
    bp.saveEx();
}
Also used : MBPartner(org.compiere.model.MBPartner)

Aggregations

MBPartner (org.compiere.model.MBPartner)78 BigDecimal (java.math.BigDecimal)21 ResultSet (java.sql.ResultSet)14 MBPartnerLocation (org.compiere.model.MBPartnerLocation)14 AdempiereException (org.adempiere.exceptions.AdempiereException)13 MLocation (org.compiere.model.MLocation)13 MOrder (org.compiere.model.MOrder)13 PreparedStatement (java.sql.PreparedStatement)11 MOrderLine (org.compiere.model.MOrderLine)11 MUser (org.compiere.model.MUser)11 MInvoice (org.compiere.model.MInvoice)10 MOrg (org.compiere.model.MOrg)9 Query (org.compiere.model.Query)9 MWarehouse (org.compiere.model.MWarehouse)8 SQLException (java.sql.SQLException)7 MClient (org.compiere.model.MClient)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereUserError (org.compiere.util.AdempiereUserError)7 Timestamp (java.sql.Timestamp)6 MDDOrder (org.eevolution.model.MDDOrder)6