Search in sources :

Example 71 with MBPartner

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

the class WSearchEditor method actionButton.

//	actionBPartner
private void actionButton(String queryValue) {
    if (m_lookup == null)
        //	leave button disabled
        return;
    // If an infoPanel is already open, close it.
    if (infoPanel != null) {
        infoPanel.detach();
        infoPanel = null;
    }
    /**
		 *  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
		 */
    // We're changing something - ignore other events;
    m_settingValue = true;
    //
    Object[] result = null;
    boolean cancelled = false;
    boolean multipleSelection = false;
    boolean modal = true;
    boolean saveResults = true;
    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.
        }
    }
    //
    String infoPanelFactoryClass = m_lookup.getInfoPanelFactoryClass();
    if (infoPanelFactoryClass != null && infoPanelFactoryClass.trim().length() > 0) {
        try {
            @SuppressWarnings("unchecked") Class<InfoPanelFactory> clazz = (Class<InfoPanelFactory>) this.getClass().getClassLoader().loadClass(infoPanelFactoryClass);
            InfoPanelFactory factory = clazz.newInstance();
            if (//	sets table name & key column
            m_tableName == null) {
                if (!hasSearchableColumns()) {
                    // Search should have been disabled for this field.
                    log.severe("Search enabled on field " + m_columnName + ". Associated table has no standard/identifier columns.");
                    return;
                }
            }
            // multipleSelection assumed false for custom info windows
            infoPanel = factory.create(m_lookup.getWindowNo(), modal, m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, saveResults, whereClause);
        //
        } 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
        infoPanel = new InfoProductPanel(m_lookup.getWindowNo(), modal, M_Warehouse_ID, M_PriceList_ID, record_id, queryValue, multipleSelection, saveResults, whereClause);
    } 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();
        }
        //
        infoPanel = new InfoBPartnerPanel(m_lookup.getWindowNo(), modal, record_id, queryValue, m_isSOTrx, m_isSOMatch, multipleSelection, saveResults, whereClause);
    } else //	General Info
    {
        if (//	sets table name & key column
        m_tableName == null)
            getDirectAccessSQL("*");
        //
        infoPanel = InfoPanel.create(m_lookup.getWindowNo(), modal, m_tableName, m_keyColumnName, record_id, queryValue, multipleSelection, saveResults, whereClause);
    }
    //
    if (infoPanel != null) {
        infoPanel.addValueChangeListener(this);
        AEnv.showWindow(infoPanel);
        //
        cancelled = infoPanel.isCancelled();
        result = infoPanel.getSelectedKeys();
        //
        infoPanel = null;
    }
    //  Result
    if (isReadWrite()) {
        if (result != null && result.length > 0) {
            //ensure data binding happen
            if (result.length > 1)
                actionCombo(result);
            else
                actionCombo(result[0]);
        } else if (cancelled) {
            log.config(getColumnName() + " - Result = null (cancelled)");
            actionCombo(null);
        } else {
            log.config(getColumnName() + " - Result = null (not cancelled)");
            //Reset the combo box to the current value
            actionCombo(getValue());
        }
    } else
        m_settingValue = false;
}
Also used : InfoBPartnerPanel(org.adempiere.webui.panel.InfoBPartnerPanel) MBPartner(org.compiere.model.MBPartner) SQLException(java.sql.SQLException) InfoProductPanel(org.adempiere.webui.panel.InfoProductPanel) InfoPanelFactory(org.adempiere.webui.panel.InfoPanelFactory)

Example 72 with MBPartner

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

the class InvoiceCalculateTax method recalculateTax.

public static void recalculateTax(MInvoice invoice) {
    //
    // Delete accounting /UnPost
    MPeriod.testPeriodOpen(invoice.getCtx(), invoice.getDateAcct(), invoice.getC_DocType_ID(), invoice.getAD_Org_ID());
    MFactAcct.deleteEx(MInvoice.Table_ID, invoice.get_ID(), invoice.get_TrxName());
    //
    // Update Invoice
    invoice.calculateTaxTotal();
    invoice.setPosted(false);
    invoice.saveEx();
    //
    // Update balance
    MBPartner bp = new MBPartner(invoice.getCtx(), invoice.getC_BPartner_ID(), invoice.get_TrxName());
    bp.setTotalOpenBalance();
    bp.setSOCreditStatus();
    bp.saveEx();
}
Also used : MBPartner(org.compiere.model.MBPartner)

Example 73 with MBPartner

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

the class VBPartner method loadBPartner.

//	getGreeting
/**
	 *	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) {
        m_partner = null;
        m_pLocation = null;
        m_user = null;
        return true;
    }
    m_partner = new MBPartner(Env.getCtx(), C_BPartner_ID, null);
    if (m_partner.get_ID() == 0) {
        ADialog.error(m_WindowNo, this, "BPartnerNotFound");
        return false;
    }
    //	BPartner - Load values
    fValue.setText(m_partner.getValue());
    fGreetingBP.setSelectedItem(getGreeting(m_partner.getC_Greeting_ID()));
    fName.setText(m_partner.getName());
    fName2.setText(m_partner.getName2());
    fTaxId.setText(m_partner.getTaxID());
    //	Contact - Load values
    m_pLocation = m_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());
        fFax.setText(m_pLocation.getFax());
    }
    //	User - Load values
    m_user = m_partner.getContact(Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_User_ID"));
    if (m_user != null) {
        fGreetingC.setSelectedItem(getGreeting(m_user.getC_Greeting_ID()));
        fContact.setText(m_user.getName());
        fTitle.setText(m_user.getTitle());
        fEMail.setText(m_user.getEMail());
        //
        fPhone.setText(m_user.getPhone());
        fPhone2.setText(m_user.getPhone2());
        fFax.setText(m_user.getFax());
    }
    return true;
}
Also used : MBPartner(org.compiere.model.MBPartner)

Example 74 with MBPartner

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

the class VPOSBPartner 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;
        partnerLocation = null;
        contact = null;
        return true;
    }
    partner = new MBPartner(Env.getCtx(), C_BPartner_ID, null);
    if (partner.get_ID() == 0) {
        ADialog.error(windowNo, this, "BPartnerNotFound");
        return false;
    }
    //	BPartner - Load values
    fValue.setText(partner.getValue());
    fName.setText(partner.getName());
    fName2.setText(partner.getName2());
    //	Contact - Load values
    partnerLocation = partner.getLocation(Env.getContextAsInt(Env.getCtx(), windowNo, "C_BPartner_Location_ID"));
    if (partnerLocation != null) {
        int location = partnerLocation.getC_Location_ID();
        fAddress.setValue(new Integer(location));
        //
        fPhone.setText(partnerLocation.getPhone());
        fPhone2.setText(partnerLocation.getPhone2());
    }
    //	User - Load values
    contact = partner.getContact(Env.getContextAsInt(Env.getCtx(), windowNo, "AD_User_ID"));
    if (contact != null) {
        fContact.setText(contact.getName());
        fEMail.setText(contact.getEMail());
        //
        fPhone.setText(contact.getPhone());
        fPhone2.setText(contact.getPhone2());
    }
    return true;
}
Also used : MBPartner(org.compiere.model.MBPartner)

Example 75 with MBPartner

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

the class POSDocumentPanel method findBPartner.

/**
	 * 	Find/Set BPartner
	 */
private void findBPartner() {
    String query = fieldPartnerName.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, name, name2, contact, 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());
        fieldPartnerName.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)

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