Search in sources :

Example 41 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 42 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 43 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 44 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)

Example 45 with MBPartner

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

the class MRP method createDDOrder.

protected void createDDOrder(int AD_Org_ID, int PP_MRP_ID, MProduct product, BigDecimal QtyPlanned, Timestamp DemandDateStartSchedule, String trxName) throws AdempiereException, SQLException {
    //TODO vpj-cd I need to create logic for DRP-040 Shipment Due  Action Notice
    //Indicates that a shipment for a Order Distribution is due. 
    // Action should be taken at the source warehouse to ensure that the order is received on time.
    //TODO vpj-cd I need to create logic for DRP-050 Shipment Pas Due  Action Notice
    //Indicates that a shipment for a Order Distribution is past due. You should either delay the orders created the requirement for the product 
    //or expedite them when the product does arrive.
    //Setting DRP Change net Update out the model validator
    MPPMRP.setIsRequired(m_product_planning, MPPProductPlanning.COLUMNNAME_IsRequiredDRP, false, trxName);
    if (m_product_planning.getDD_NetworkDistribution_ID() == 0) {
        //Indicates that the Product Planning Data for this product does not specify a valid network distribution.
        createMRPNote("DRP-060", AD_Org_ID, PP_MRP_ID, product, (String) null, null, null, trxName);
    }
    //TODO: Create functionality for Valid form and Valid To for an Network Distribution
    MDDNetworkDistribution network = MDDNetworkDistribution.get(getCtx(), m_product_planning.getDD_NetworkDistribution_ID());
    MDDNetworkDistributionLine[] network_lines = network.getLines(m_product_planning.getM_Warehouse_ID());
    int M_Shipper_ID = 0;
    MDDOrder order = null;
    Integer DD_Order_ID = 0;
    for (MDDNetworkDistributionLine network_line : network_lines) {
        if (network_line.getM_Shipper_ID() == 0) {
            String comment = Msg.translate(getCtx(), MDDNetworkDistribution.COLUMNNAME_Name) + " : " + network.getName();
            createMRPNote("DRP-030", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get supply source warehouse and locator
        MWarehouse source = new MWarehouse(getCtx(), network_line.getM_WarehouseSource_ID(), trxName);
        MLocator locator = MLocator.getDefault(source);
        if (locator == null || locator.getM_Locator_ID() <= 0) {
            String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
            createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get supply target warehouse and locator
        MWarehouse target = new MWarehouse(getCtx(), network_line.getM_Warehouse_ID(), trxName);
        MLocator locator_to = MLocator.getDefault(target);
        if (locator_to == null || locator_to.getM_Locator_ID() <= 0) {
            String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
            createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get the transfer time
        BigDecimal transferTime = network_line.getTransferTime();
        if (transferTime.compareTo(Env.ZERO) <= 0) {
            transferTime = m_product_planning.getTransferTime();
        }
        if (locator == null || locator_to == null) {
            String comment = Msg.translate(getCtx(), MDDNetworkDistributionLine.COLUMNNAME_M_WarehouseSource_ID) + " : " + source.getName();
            createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        //get the warehouse in transit
        MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), source.getAD_Org_ID());
        if (wsts == null || wsts.length == 0) {
            String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
            createMRPNote("DRP-010", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
            continue;
        }
        if (M_Shipper_ID != network_line.getM_Shipper_ID()) {
            //Org Must be linked to BPartner
            MOrg org = MOrg.get(getCtx(), locator_to.getAD_Org_ID());
            int C_BPartner_ID = org.getLinkedC_BPartner_ID(trxName);
            if (C_BPartner_ID == 0) {
                String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
                createMRPNote("DRP-020", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
                continue;
            }
            MBPartner bp = getBPartner(C_BPartner_ID);
            // Try found some order with Shipper , Business Partner and Doc Status = Draft 
            // Consolidate the demand in a single order for each Shipper , Business Partner , DemandDateStartSchedule
            DD_Order_ID = getDDOrder_ID(AD_Org_ID, wsts[0].get_ID(), network_line.getM_Shipper_ID(), bp.getC_BPartner_ID(), TimeUtil.getDay(DemandDateStartSchedule.getTime()), trxName);
            if (DD_Order_ID <= 0) {
                order = new MDDOrder(getCtx(), 0, trxName);
                order.setAD_Org_ID(target.getAD_Org_ID());
                order.setC_BPartner_ID(C_BPartner_ID);
                order.setAD_User_ID(bp.getPrimaryAD_User_ID());
                order.setC_DocType_ID(docTypeDO_ID);
                order.setM_Warehouse_ID(wsts[0].get_ID());
                order.setDocAction(MDDOrder.DOCACTION_Complete);
                order.setDateOrdered(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(transferTime)).negate().intValueExact()));
                order.setDatePromised(DemandDateStartSchedule);
                order.setM_Shipper_ID(network_line.getM_Shipper_ID());
                order.setIsInDispute(false);
                order.setIsInTransit(false);
                order.setSalesRep_ID(m_product_planning.getPlanner_ID());
                order.setProcessed(false);
                order.setProcessing(false);
                order.saveEx();
                order.addDescription(Msg.parseTranslation(getCtx(), "@DD_Order_ID@ @DocumentNo@ " + order.getDocumentNo() + " @Generate@ @from@ " + getName()));
                order.saveEx();
                DD_Order_ID = order.get_ID();
                String key = order.getAD_Org_ID() + "#" + order.getM_Warehouse_ID() + "#" + network_line.getM_Shipper_ID() + "#" + C_BPartner_ID + "#" + TimeUtil.getDay(DemandDateStartSchedule.getTime()) + "DR";
                dd_order_id_cache.put(key, DD_Order_ID);
            } else {
                order = new MDDOrder(getCtx(), DD_Order_ID, trxName);
            }
            M_Shipper_ID = network_line.getM_Shipper_ID();
        }
        BigDecimal QtyOrdered = QtyPlanned.multiply(network_line.getPercent()).divide(Env.ONEHUNDRED);
        MDDOrderLine oline = new MDDOrderLine(getCtx(), 0, trxName);
        oline.setDD_Order_ID(order.getDD_Order_ID());
        oline.setAD_Org_ID(target.getAD_Org_ID());
        oline.setM_Locator_ID(locator.getM_Locator_ID());
        oline.setM_LocatorTo_ID(locator_to.getM_Locator_ID());
        oline.setM_Product_ID(m_product_planning.getM_Product_ID());
        oline.setDateOrdered(order.getDateOrdered());
        oline.setDatePromised(DemandDateStartSchedule);
        oline.setQtyEntered(QtyOrdered);
        oline.setQtyOrdered(QtyOrdered);
        oline.setTargetQty(MPPMRP.getQtyReserved(getCtx(), target.getM_Warehouse_ID(), m_product_planning.getM_Product_ID(), DemandDateStartSchedule, trxName));
        oline.setIsInvoiced(false);
        oline.saveEx();
        // Set Correct Dates for Plan
        final String whereClause = MPPMRP.COLUMNNAME_DD_OrderLine_ID + "=?";
        List<MPPMRP> mrpList = new Query(getCtx(), MPPMRP.Table_Name, whereClause, trxName).setParameters(new Object[] { oline.getDD_OrderLine_ID() }).list();
        for (MPPMRP mrp : mrpList) {
            mrp.setDateOrdered(getToday());
            mrp.setDateOrdered(mrp.getDD_Order().getDateOrdered());
            mrp.setDateStartSchedule(mrp.getDateOrdered());
            mrp.setDatePromised(DemandDateStartSchedule);
            mrp.setDateFinishSchedule(DemandDateStartSchedule);
            mrp.saveEx();
            if (MPPMRP.TYPEMRP_Supply.equals(mrp.getTypeMRP()))
                supplies.put(mrp.get_ID(), mrp.getQty());
        }
        count_DO += 1;
    }
}
Also used : MDDNetworkDistributionLine(org.eevolution.model.MDDNetworkDistributionLine) Query(org.compiere.model.Query) MBPartner(org.compiere.model.MBPartner) MPPMRP(org.eevolution.model.MPPMRP) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal) MDDNetworkDistribution(org.eevolution.model.MDDNetworkDistribution) MDDOrderLine(org.eevolution.model.MDDOrderLine) MOrg(org.compiere.model.MOrg) MLocator(org.compiere.model.MLocator) MDDOrder(org.eevolution.model.MDDOrder)

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