Search in sources :

Example 46 with MBPartner

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

the class MRP method getBPartner.

private MBPartner getBPartner(int C_BPartner_ID) {
    MBPartner partner = partner_cache.get(C_BPartner_ID);
    if (partner == null) {
        partner = MBPartner.get(getCtx(), C_BPartner_ID);
        partner_cache.put(C_BPartner_ID, partner);
    }
    return partner;
}
Also used : MBPartner(org.compiere.model.MBPartner)

Example 47 with MBPartner

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

the class MRPApproval method createDistributionOrder.

private MDDOrder createDistributionOrder(MPPMRP mrp) {
    MLocator locatorFrom = MLocator.get(mrp.getCtx(), getLocatorId());
    MLocator locatorTo = MLocator.get(mrp.getCtx(), getLocatorToId());
    int docTypeId = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder, locatorTo.getAD_Org_ID(), Env.getAD_User_ID(getCtx()), get_TrxName());
    MBPartner partner = MBPartner.get(mrp.getCtx(), getBusinessPartnerId());
    MDDOrder order = new MDDOrder(getCtx(), 0, get_TrxName());
    order.setAD_Org_ID(mrp.getAD_Org_ID());
    order.addDescription("Generated by MRP");
    order.setC_BPartner_ID(getBusinessPartnerId());
    order.setAD_User_ID(partner.getPrimaryAD_User_ID());
    order.setC_DocType_ID(docTypeId);
    order.setM_Warehouse_ID(getWarehouseinTransitId());
    if (getReferenceNo() != null)
        order.setPOReference(getReferenceNo());
    order.setDocStatus(MDDOrder.DOCSTATUS_Drafted);
    order.setDocAction(MDDOrder.DOCACTION_Complete);
    order.setDateOrdered(mrp.getDateFinishSchedule());
    order.setDatePromised(mrp.getDatePromised());
    order.setM_Shipper_ID(getShipperId());
    if (getPriority() != null)
        order.setPriorityRule(getPriority());
    order.setIsInDispute(false);
    order.setIsInTransit(false);
    order.setSalesRep_ID(mrp.getPlanner_ID());
    order.saveEx();
    MDDOrderLine orderLine = new MDDOrderLine(getCtx(), 0, get_TrxName());
    orderLine.setDD_Order_ID(order.getDD_Order_ID());
    orderLine.setAD_Org_ID(locatorTo.getAD_Org_ID());
    orderLine.setM_Locator_ID(locatorFrom.getM_Locator_ID());
    orderLine.setM_LocatorTo_ID(locatorTo.getM_Locator_ID());
    orderLine.setM_Product_ID(mrp.getM_Product_ID());
    orderLine.setDateOrdered(order.getDateOrdered());
    orderLine.setDatePromised(mrp.getDatePromised());
    orderLine.setQtyEntered(getSelectionAsBigDecimal(mrp.getPP_MRP_ID(), "MRP_" + MPPMRP.COLUMNNAME_Qty));
    orderLine.setQtyOrdered(getSelectionAsBigDecimal(mrp.getPP_MRP_ID(), "MRP_" + MPPMRP.COLUMNNAME_Qty));
    orderLine.setConfirmedQty(getSelectionAsBigDecimal(mrp.getPP_MRP_ID(), "DL_" + MDDOrderLine.COLUMNNAME_ConfirmedQty));
    orderLine.setTargetQty(MPPMRP.getQtyReserved(getCtx(), locatorTo.getM_Warehouse_ID(), mrp.getM_Product_ID(), mrp.getDateStartSchedule(), get_TrxName()));
    orderLine.setIsInvoiced(false);
    orderLine.saveEx();
    order.processIt(DocAction.ACTION_Prepare);
    order.saveEx();
    return order;
}
Also used : MDDOrderLine(org.eevolution.model.MDDOrderLine) MLocator(org.compiere.model.MLocator) MBPartner(org.compiere.model.MBPartner) MDDOrder(org.eevolution.model.MDDOrder)

Example 48 with MBPartner

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

the class VLookup method actionButton.

//	actionCombo
/**
	 *	Action - Button.
	 *	- Call Info
	 *	@param queryValue initial query value
	 */
private void actionButton(String queryValue) {
    //  disable double click
    m_button.setEnabled(false);
    if (m_lookup == null)
        //	leave button disabled
        return;
    //  closes other editors
    m_text.requestFocus();
    Frame frame = Env.getFrame(this);
    /**
		 *  Three return options:
		 *  - Value Selected & OK pressed   => store result => result has value
		 *  - Cancel pressed                => store null   => result == null && cancelled
		 *  - Window closed                 -> ignore       => result == null && !cancelled
		 */
    Object[] result = null;
    boolean cancelled = false;
    boolean multipleSelection = false;
    int record_id = 0;
    //
    //	fully qualified name
    String col = m_lookup.getColumnName();
    if (col.indexOf('.') != -1)
        col = col.substring(col.indexOf('.') + 1);
    //  Zoom / Validation
    String whereClause = getWhereClause();
    //
    log.fine(col + ", Zoom=" + m_lookup.getZoom() + " (" + whereClause + ")");
    //  If the record has a value (ID) find the name.  The displayed text could be different.
    if (queryValue.length() == 0 && getValue() != null && !getValue().equals("")) {
        Object currentValue = getValue();
        try {
            record_id = ((Number) currentValue).intValue();
            queryValue = "";
        } catch (Exception e) {
        //  Can't cast the string "" to a number.
        }
    }
    //
    //	reset value so that is always treated as new entry
    boolean resetValue = false;
    String infoFactoryClass = m_lookup.getInfoFactoryClass();
    if (infoFactoryClass != null && infoFactoryClass.trim().length() > 0) {
        try {
            Class<InfoFactory> clazz = (Class<InfoFactory>) this.getClass().getClassLoader().loadClass(infoFactoryClass);
            InfoFactory factory = clazz.newInstance();
            //				}
            if (m_tableName == null) {
                //	sets table name & key column
                String rsql = getDirectAccessSQL("*");
                if (rsql == null || rsql.length() == 0) {
                    m_button.setEnabled(false);
                    return;
                }
            }
            // multipleSelection assumed false for custom info windows
            Info ig = factory.create(frame, true, m_lookup.getWindowNo(), m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, whereClause);
            ig.setVisible(true);
            cancelled = ig.isCancelled();
            result = ig.getSelectedKeys();
        } catch (Exception e) {
            log.log(Level.SEVERE, "Failed to load custom InfoFactory - " + e.getLocalizedMessage(), e);
        }
    } else if (col.equals("M_Product_ID")) {
        //	Reset
        resetTabInfo();
        //
        int M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), m_lookup.getWindowNo(), "M_Warehouse_ID");
        int M_PriceList_ID = Env.getContextAsInt(Env.getCtx(), m_lookup.getWindowNo(), "M_PriceList_ID");
        //
        if (m_mField != null) {
            int AD_Table_ID = MColumn.getTable_ID(Env.getCtx(), m_mField.getAD_Column_ID(), null);
            // TODO hard-coded - add to AD_Column?
            multipleSelection = (MOrderLine.Table_ID == AD_Table_ID) || (MInvoiceLine.Table_ID == AD_Table_ID) || (I_PP_Product_BOMLine.Table_ID == AD_Table_ID) || (MProductPrice.Table_ID == AD_Table_ID);
        }
        //	Show Info
        InfoProduct ip = new InfoProduct(frame, true, m_lookup.getWindowNo(), M_Warehouse_ID, M_PriceList_ID, record_id, queryValue, multipleSelection, true, whereClause);
        ip.setVisible(true);
        cancelled = ip.isCancelled();
        result = ip.getSelectedKeys();
        resetValue = true;
    } else if (col.equals("C_BPartner_ID")) {
        resetTabInfo();
        //
        setIsSOTrx(m_isSOTrxEnvOverride, false);
        //  If we have a record id, set isSOMatch
        if (record_id > 0) {
            String trxName = Trx.createTrxName();
            MBPartner bp = new MBPartner(Env.getCtx(), record_id, trxName);
            m_isSOMatch = (m_isSOTrx && bp.isCustomer()) || (!m_isSOTrx && bp.isVendor());
            Trx.get(trxName, false).close();
        }
        //
        InfoBPartner ip = new InfoBPartner(frame, true, m_lookup.getWindowNo(), record_id, queryValue, m_isSOTrx, m_isSOMatch, multipleSelection, true, whereClause);
        ip.setVisible(true);
        cancelled = ip.isCancelled();
        result = ip.getSelectedKeys();
    } else //	General Info
    {
        if (m_tableName == null) {
            //	sets table name & key column
            String rsql = getDirectAccessSQL("*");
            if (rsql == null || rsql.length() == 0) {
                m_button.setEnabled(false);
                return;
            }
        }
        //
        Info ig = Info.create(frame, true, m_lookup.getWindowNo(), m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, true, whereClause);
        ig.setVisible(true);
        cancelled = ig.isCancelled();
        result = ig.getSelectedKeys();
    }
    if (isReadWrite()) {
        //  Result
        if (result != null && result.length > 0) {
            log.config(m_columnName + " - Result = " + result.toString() + " (" + result.getClass().getName() + ")");
            //  make sure that value is in cache
            m_lookup.getDirect(result[0], false, true);
            if (resetValue)
                actionCombo(null);
            // juddm added logic for multi-select handling
            if (result.length > 1)
                //	data binding
                actionCombo(result);
            else
                actionCombo(result[0]);
        } else if (cancelled) {
            log.config(m_columnName + " - Result = null (cancelled)");
            actionCombo(null);
        } else {
            log.config(m_columnName + " - Result = null (not cancelled)");
            //  to re-display value
            setValue(m_value);
        }
        //
        m_text.requestFocus();
    } else
        log.config(m_columnName + " - Field not writable.  No change.");
    m_button.setEnabled(true);
}
Also used : Frame(java.awt.Frame) MBPartner(org.compiere.model.MBPartner) InfoBPartner(org.compiere.apps.search.InfoBPartner) InfoFactory(org.compiere.apps.search.InfoFactory) Info(org.compiere.apps.search.Info) RecordInfo(org.compiere.apps.RecordInfo) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) InfoProduct(org.compiere.apps.search.InfoProduct)

Example 49 with MBPartner

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

the class WPOSDocumentPanel method findBPartner.

/**
	 * 	Find/Set BPartner
	 */
private void findBPartner() {
    String query = bPartnerName.getText();
    //	
    if (query == null || query.length() == 0)
        return;
    // unchanged
    if (posPanel.hasBPartner() && posPanel.compareBPName(query))
        return;
    query = query.toUpperCase();
    //	Test Number
    boolean allNumber = true;
    boolean noNumber = true;
    char[] qq = query.toCharArray();
    for (int i = 0; i < qq.length; i++) {
        if (Character.isDigit(qq[i])) {
            noNumber = false;
            break;
        }
    }
    try {
        Integer.parseInt(query);
    } catch (Exception e) {
        allNumber = false;
    }
    String value = query;
    String taxId = query;
    String name = (allNumber ? null : query);
    String name2 = (allNumber ? null : query);
    String contact = (allNumber ? null : query);
    String eMail = (query.indexOf('@') != -1 ? query : null);
    String phone = (noNumber ? null : query);
    String city = null;
    //
    MBPartnerInfo[] results = MBPartnerInfo.find(ctx, value, taxId, contact, name, name2, eMail, phone, city);
    //	Set Result
    if (results.length == 1) {
        MBPartner bp = MBPartner.get(ctx, results[0].getC_BPartner_ID());
        posPanel.configureBPartner(bp.getC_BPartner_ID());
        bPartnerName.setText(bp.getName() + "");
    } else {
        //	more than one
        changeBusinessPartner(results);
    }
    //	Default return
    posPanel.refreshPanel();
    return;
}
Also used : MBPartnerInfo(org.compiere.model.MBPartnerInfo) MBPartner(org.compiere.model.MBPartner)

Example 50 with MBPartner

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

the class WPOSBPartner method loadBPartner.

//	createLine
/**
	 *	Load BPartner
	 *  @param C_BPartner_ID - existing BPartner or 0 for new
	 * 	@return true if loaded
	 */
public boolean loadBPartner(int C_BPartner_ID) {
    log.config("C_BPartner_ID=" + C_BPartner_ID);
    //  New bpartner
    if (C_BPartner_ID == 0) {
        partner = null;
        m_pLocation = null;
        m_user = null;
        return true;
    }
    partner = new MBPartner(Env.getCtx(), C_BPartner_ID, null);
    if (partner.get_ID() == 0) {
        FDialog.error(m_WindowNo, this, "BPartnerNotFound");
        return false;
    }
    //	BPartner - Load values
    fValue.setText(partner.getValue());
    fName.setText(partner.getName());
    fName2.setText(partner.getName2());
    //	Contact - Load values
    m_pLocation = partner.getLocation(Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_BPartner_Location_ID"));
    if (m_pLocation != null) {
        int location = m_pLocation.getC_Location_ID();
        fAddress.setValue(new Integer(location));
        fPhone.setText(m_pLocation.getPhone());
        fPhone2.setText(m_pLocation.getPhone2());
    }
    //	User - Load values
    m_user = partner.getContact(Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_User_ID"));
    if (m_user != null) {
        fContact.setText(m_user.getName());
        fEMail.setText(m_user.getEMail());
        fPhone.setText(m_user.getPhone());
        fPhone2.setText(m_user.getPhone2());
    }
    return true;
}
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