Search in sources :

Example 16 with MBPartner

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

the class WebUser method save.

//	toString
/**************************************************************************
	 * 	Save BPartner Objects
	 * 	@return true if saved
	 */
public boolean save() {
    m_saveErrorMessage = null;
    log.info("BP.Value=" + m_bp.getValue() + ", Name=" + m_bp.getName());
    try {
        //	check if BPartner exists	***********************************
        if (m_bp.getC_BPartner_ID() == 0) {
            String sql = "SELECT * FROM C_BPartner WHERE AD_Client_ID=? AND Value=?";
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            try {
                pstmt = DB.prepareStatement(sql, null);
                pstmt.setInt(1, m_AD_Client_ID);
                pstmt.setString(2, m_bp.getValue());
                rs = pstmt.executeQuery();
                if (rs.next()) {
                    m_bp = new MBPartner(m_ctx, m_bpc.getC_BPartner_ID(), null);
                    log.fine("BP loaded =" + m_bp);
                }
            } catch (Exception e) {
                log.log(Level.SEVERE, "save-check", e);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
        }
        //	save BPartner			***************************************
        if (m_bp.getName() == null || m_bp.getName().length() == 0)
            m_bp.setName(m_bpc.getName());
        if (m_bp.getValue() == null || m_bp.getValue().length() == 0)
            m_bp.setValue(m_bpc.getEMail());
        log.fine("BP=" + m_bp);
        if (!m_bp.save()) {
            m_saveErrorMessage = "Could not save Business Partner";
            return false;
        }
        //	save Location			***************************************
        log.fine("LOC=" + m_loc);
        m_loc.save();
        //	save BP Location		***************************************
        if (m_bpl.getC_BPartner_ID() != m_bp.getC_BPartner_ID())
            m_bpl.setC_BPartner_ID(m_bp.getC_BPartner_ID());
        if (m_bpl.getC_Location_ID() != m_loc.getC_Location_ID())
            m_bpl.setC_Location_ID(m_loc.getC_Location_ID());
        log.fine("BPL=" + m_bpl);
        if (!m_bpl.save()) {
            m_saveErrorMessage = "Could not save Location";
            return false;
        }
        //	save Contact			***************************************
        if (m_bpc.getC_BPartner_ID() != m_bp.getC_BPartner_ID())
            m_bpc.setC_BPartner_ID(m_bp.getC_BPartner_ID());
        if (m_bpc.getC_BPartner_Location_ID() != m_bpl.getC_BPartner_Location_ID())
            m_bpc.setC_BPartner_Location_ID(m_bpl.getC_BPartner_Location_ID());
        log.fine("BPC=" + m_bpc);
        if (!m_bpc.save()) {
            m_saveErrorMessage = "Could not save Contact";
            return false;
        }
    } catch (Exception ex) {
        log.log(Level.SEVERE, "save", ex);
        m_saveErrorMessage = ex.toString();
        return false;
    }
    //
    return true;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MBPartner(org.compiere.model.MBPartner)

Example 17 with MBPartner

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

the class ReleaseInOutBound method createDistributionOrder.

/**
	 * get Out Bound Order Lines from Smart Browser
	 * @return
     */
/*private List <MWMInOutBoundLine> getOutBoundOrderLine()
	{
		StringBuilder whereClause = new StringBuilder();
		whereClause.append("EXISTS (SELECT 1 FROM WM_InOutBound o WHERE o.WM_InOutBound_ID=WM_InOutBoundLine.WM_InOutBound_ID AND o.Processed='N' AND o.DocAction NOT IN ('CO','CL','VO')) AND ");
		whereClause.append("EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE  T_Selection.AD_PInstance_ID=? AND T_Selection.T_Selection_ID=WM_InOutBoundLine.WM_InOutboundLine_ID)");
		return new Query(getCtx(), I_WM_InOutBoundLine.Table_Name, whereClause.toString(), get_TrxName())
				.setClient_ID()
				.setParameters(getAD_PInstance_ID())
				.list();
	}*/
/**
	 * create Distribution Order to performance a Pick List
	 * @param outBoundOrderLine Out bound Line
	 * @return Quantity that was not covert for inventory
	 */
protected BigDecimal createDistributionOrder(MWMInOutBoundLine outBoundOrderLine) {
    WMRuleEngine engineRule = WMRuleEngine.get();
    List<MStorage> storageList = engineRule.getStorage(outBoundOrderLine, getWarehouseAreaTypeId(), getWarehouseSectionTypeId());
    int shipperId = 0;
    BigDecimal qtySupply = BigDecimal.ZERO;
    if (storageList != null && storageList.size() > 0) {
        //get the warehouse in transit
        MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), outBoundLocator.getAD_Org_ID());
        if (wsts == null || wsts.length == 0)
            throw new AdempiereException("@M_Warehouse_ID@ @IsInTransit@ @NotFound@");
        //Org Must be linked to BPartner
        MOrg org = MOrg.get(getCtx(), outBoundLocator.getAD_Org_ID());
        int partnerId = org.getLinkedC_BPartner_ID(get_TrxName());
        if (partnerId == 0)
            throw new NoBPartnerLinkedforOrgException(org);
        MBPartner partner = MBPartner.get(getCtx(), partnerId);
        if (orderDistribution == null) {
            orderDistribution = new MDDOrder(getCtx(), 0, get_TrxName());
            orderDistribution.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
            orderDistribution.setC_BPartner_ID(partnerId);
            if (getDocumentTypeId() > 0) {
                orderDistribution.setC_DocType_ID(getDocumentTypeId());
            } else {
                orderDistribution.setC_DocType_ID(MDocType.getDocType(X_C_DocType.DOCBASETYPE_DistributionOrder));
            }
            orderDistribution.setM_Warehouse_ID(wsts[0].get_ID());
            if (getDocumentAction() != null)
                orderDistribution.setDocAction(getDocumentAction());
            else
                orderDistribution.setDocAction(X_DD_Order.DOCACTION_Prepare);
            MUser[] users = MUser.getOfBPartner(getCtx(), partner.getC_BPartner_ID(), get_TrxName());
            if (users == null || users.length == 0)
                throw new AdempiereException("@AD_User_ID@ @NotFound@ @Value@ - @C_BPartner_ID@ : " + partner.getValue() + " - " + partner.getName());
            orderDistribution.setAD_User_ID(users[0].getAD_User_ID());
            orderDistribution.setDateOrdered(getToday());
            orderDistribution.setDatePromised(getToday());
            orderDistribution.setM_Shipper_ID(shipperId);
            orderDistribution.setIsInDispute(false);
            orderDistribution.setIsInTransit(false);
            orderDistribution.setSalesRep_ID(getAD_User_ID());
            orderDistribution.saveEx();
        }
        storageList.stream().forEach(storage -> {
            MDDOrderLine orderLine = new MDDOrderLine(orderDistribution);
            orderLine.setM_Locator_ID(storage.getM_Locator_ID());
            orderLine.setM_LocatorTo_ID(outBoundLocator.getM_Locator_ID());
            orderLine.setC_UOM_ID(outBoundOrderLine.getC_UOM_ID());
            orderLine.setM_Product_ID(outBoundOrderLine.getM_Product_ID());
            orderLine.setDateOrdered(getToday());
            orderLine.setDatePromised(outBoundOrderLine.getPickDate());
            orderLine.setWM_InOutBoundLine_ID(outBoundOrderLine.getWM_InOutBoundLine_ID());
            orderLine.setIsInvoiced(false);
            orderLine.saveEx();
        });
    } else {
        qtySupply = outBoundOrderLine.getQtyToPick().subtract(qtySupply);
    }
    return qtySupply;
}
Also used : MBPartner(org.compiere.model.MBPartner) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MWarehouse(org.compiere.model.MWarehouse) MDDOrderLine(org.eevolution.model.MDDOrderLine) WMRuleEngine(org.eevolution.engine.warehouse.WMRuleEngine) MOrg(org.compiere.model.MOrg) AdempiereException(org.adempiere.exceptions.AdempiereException) NoBPartnerLinkedforOrgException(org.eevolution.exceptions.NoBPartnerLinkedforOrgException) MDDOrder(org.eevolution.model.MDDOrder) MUser(org.compiere.model.MUser)

Example 18 with MBPartner

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

the class WMRuleEngine method applyDefinition.

/**
	 * Apply Definition for Warehouse  Strategy
	 * @param inOutBoundLine Order Bound Line
	 * @param warehouseAreaTypeId Area Type Id
	 * @param warehouseSectionTypeId Section Type Id
	 * */
private MWMStrategy applyDefinition(MWMInOutBoundLine inOutBoundLine, int warehouseAreaTypeId, int warehouseSectionTypeId) {
    StringBuffer whereClause = new StringBuffer("(");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IS NULL");
    whereClause.append(")");
    whereClause.append(" AND EXISTS (SELECT 1 FROM " + MWMStrategy.Table_Name);
    whereClause.append(" WHERE ");
    whereClause.append(MWMStrategy.Table_Name + "." + MWMStrategy.COLUMNNAME_WM_Strategy_ID + "=");
    whereClause.append(MWMDefinition.Table_Name + "." + MWMDefinition.COLUMNNAME_WM_Strategy_ID);
    whereClause.append(" AND ");
    whereClause.append(MWMStrategy.COLUMNNAME_InOutBoundType + "=?");
    whereClause.append(")");
    MProduct product = inOutBoundLine.getMProduct();
    MBPartner partner = inOutBoundLine.getBPartner();
    MWMDefinition definition = new Query(inOutBoundLine.getCtx(), MWMDefinition.Table_Name, whereClause.toString(), inOutBoundLine.get_TrxName()).setClient_ID().setParameters(product.getM_Product_ID(), product.getM_Product_Category_ID(), product.getGroup1(), product.getGroup2(), product.getClassification(), partner.getC_BPartner_ID(), partner.getC_BP_Group_ID(), warehouseAreaTypeId, warehouseSectionTypeId, MWMStrategy.INOUTBOUNDTYPE_OutboundOperation).first();
    if (definition == null) {
        throw new AdempiereException("@WM_Definition_ID@ @NotFound@");
    }
    return definition.getWarehouseStrategy();
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) AdempiereException(org.adempiere.exceptions.AdempiereException) MWMDefinition(org.eevolution.model.MWMDefinition) MBPartner(org.compiere.model.MBPartner)

Example 19 with MBPartner

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

the class PaySelectionCreateCheck method createCheck.

//	doIt
/**
	 * 	Create Check from line
	 *	@param line
	 *	@throws Exception for invalid bank accounts
	 */
private void createCheck(MPaySelectionLine line) throws Exception {
    //	Try to find one
    for (int i = 0; i < paySelectionChecks.size(); i++) {
        MPaySelectionCheck check = (MPaySelectionCheck) paySelectionChecks.get(i);
        //	Add to existing
        if (check.getC_BPartner_ID() == line.getInvoice().getC_BPartner_ID()) {
            check.addLine(line);
            if (!check.save())
                throw new IllegalStateException("Cannot save MPaySelectionCheck");
            line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
            line.setProcessed(true);
            if (!line.save())
                throw new IllegalStateException("Cannot save MPaySelectionLine");
            return;
        }
    }
    //	Create new
    String PaymentRule = line.getPaymentRule();
    if (p_PaymentRule != null) {
        if (!X_C_Order.PAYMENTRULE_DirectDebit.equals(PaymentRule))
            PaymentRule = p_PaymentRule;
    }
    MPaySelectionCheck check = new MPaySelectionCheck(line, PaymentRule);
    if (!check.isValid()) {
        int C_BPartner_ID = check.getC_BPartner_ID();
        MBPartner bp = MBPartner.get(getCtx(), C_BPartner_ID);
        String msg = "@NotFound@ @C_BP_BankAccount@: " + bp.getName();
        throw new AdempiereUserError(msg);
    }
    if (!check.save())
        throw new IllegalStateException("Cannot save MPaySelectionCheck");
    line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
    line.setProcessed(true);
    if (!line.save())
        throw new IllegalStateException("Cannot save MPaySelectionLine");
    paySelectionChecks.add(check);
}
Also used : MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner)

Example 20 with MBPartner

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

the class ProjectGenPO method createPO.

//	doIt
/**
	 * 	Create PO from Planned Amt/Qty
	 * 	@param projectLine project line
	 */
private void createPO(MProject project, MProjectLine projectLine) {
    if (projectLine.getM_Product_ID() == 0) {
        addLog(projectLine.getLine(), null, null, "Line has no Product");
        return;
    }
    if (projectLine.getC_OrderPO_ID() != 0) {
        addLog(projectLine.getLine(), null, null, "Line was ordered previously");
        return;
    }
    //	PO Record
    MProductPO[] pos = MProductPO.getOfProduct(getCtx(), projectLine.getM_Product_ID(), get_TrxName());
    if (pos == null || pos.length == 0) {
        addLog(projectLine.getLine(), null, null, "Product has no PO record");
        return;
    }
    //	Create to Order
    MOrder order = null;
    //	try to find PO to C_BPartner
    for (int i = 0; i < m_pos.size(); i++) {
        MOrder test = (MOrder) m_pos.get(i);
        if (test.getC_BPartner_ID() == pos[0].getC_BPartner_ID()) {
            order = test;
            break;
        }
    }
    if (//	create new Order
    order == null) {
        //	Vendor
        MBPartner bp = new MBPartner(getCtx(), pos[0].getC_BPartner_ID(), get_TrxName());
        //	New Order
        order = new MOrder(project, false, null);
        int AD_Org_ID = projectLine.getAD_Org_ID();
        if (AD_Org_ID == 0) {
            log.warning("createPOfromProjectLine - AD_Org_ID=0");
            AD_Org_ID = Env.getAD_Org_ID(getCtx());
            if (AD_Org_ID != 0)
                projectLine.setAD_Org_ID(AD_Org_ID);
        }
        order.setClientOrg(projectLine.getAD_Client_ID(), AD_Org_ID);
        order.setBPartner(bp);
        order.save();
        //	optionally save for consolidation
        if (m_ConsolidateDocument)
            m_pos.add(order);
    }
    //	Create Line
    MOrderLine orderLine = new MOrderLine(order);
    orderLine.setM_Product_ID(projectLine.getM_Product_ID(), true);
    orderLine.setQty(projectLine.getPlannedQty());
    orderLine.setDescription(projectLine.getDescription());
    //	(Vendor) PriceList Price
    orderLine.setPrice();
    if (orderLine.getPriceActual().signum() == 0) {
        //	Try to find purchase price
        BigDecimal poPrice = pos[0].getPricePO();
        int C_Currency_ID = pos[0].getC_Currency_ID();
        //
        if (poPrice == null || poPrice.signum() == 0)
            poPrice = pos[0].getPriceLastPO();
        if (poPrice == null || poPrice.signum() == 0)
            poPrice = pos[0].getPriceList();
        //	We have a price
        if (poPrice != null && poPrice.signum() != 0) {
            if (order.getC_Currency_ID() != C_Currency_ID)
                poPrice = MConversionRate.convert(getCtx(), poPrice, C_Currency_ID, order.getC_Currency_ID(), order.getDateAcct(), order.getC_ConversionType_ID(), order.getAD_Client_ID(), order.getAD_Org_ID());
            orderLine.setPrice(poPrice);
        }
    }
    orderLine.setTax();
    orderLine.saveEx();
    //	update ProjectLine
    projectLine.setC_OrderPO_ID(order.getC_Order_ID());
    projectLine.saveEx();
    addLog(projectLine.getLine(), null, projectLine.getPlannedQty(), order.getDocumentNo());
}
Also used : MOrder(org.compiere.model.MOrder) MProductPO(org.compiere.model.MProductPO) MBPartner(org.compiere.model.MBPartner) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

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