Search in sources :

Example 6 with MAcctSchemaElement

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

the class WAcctViewerData method createKeyColumns.

// createRModel
/**
	 *  Create the key columns in sequence
	 *  @return List of Key Columns
	 */
private ArrayList<String> createKeyColumns() {
    ArrayList<String> columns = new ArrayList<String>();
    m_leadingColumns = 0;
    //  Sorting Fields
    //  may add ""
    columns.add(sortBy1);
    if (!columns.contains(sortBy2))
        columns.add(sortBy2);
    if (!columns.contains(sortBy3))
        columns.add(sortBy3);
    if (!columns.contains(sortBy4))
        columns.add(sortBy4);
    //  Add Account Segments
    MAcctSchemaElement[] elements = ASchema.getAcctSchemaElements();
    for (int i = 0; i < elements.length; i++) {
        if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID"))
            m_leadingColumns = columns.size();
        MAcctSchemaElement ase = elements[i];
        String columnName = ase.getColumnName();
        if (columnName.startsWith("UserElement")) {
            if (columnName.indexOf('1') != -1)
                m_ref1 = ase.getDisplayColumnName();
            else
                m_ref2 = ase.getDisplayColumnName();
        }
        if (!columns.contains(columnName))
            columns.add(columnName);
    }
    if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID"))
        m_leadingColumns = columns.size();
    return columns;
}
Also used : ArrayList(java.util.ArrayList) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 7 with MAcctSchemaElement

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

the class WAcctViewer method actionButton.

// actionTable
/**
	 *  Action Button
	 *
	 *  @param button pressed button
	 *  @return ID
	 * @throws Exception
	 */
private int actionButton(Button button) throws Exception {
    String keyColumn = button.getName();
    log.info(keyColumn);
    // String whereClause = ""; // Elaine 2008/07/28
    String whereClause = "(IsSummary='N' OR IsSummary IS NULL)";
    String lookupColumn = keyColumn;
    int record_id = m_data.getButtonRecordID(keyColumn);
    if ("Account_ID".equals(keyColumn)) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_Account);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if ("User1_ID".equals(keyColumn)) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList1);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if ("User2_ID".equals(keyColumn)) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList2);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if ("User3_ID".equals(keyColumn)) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList3);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if ("User4_ID".equals(keyColumn)) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList4);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if ("UserElement1_ID".equals(keyColumn)) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X1' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    } else if ("UserElement2_ID".equals(keyColumn)) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X2' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    } else if (keyColumn.equals("M_Product_ID")) {
        whereClause = "";
    } else if (selDocument.isChecked())
        whereClause = "";
    if (//  Record_ID
    button == selRecord)
        record_id = m_data.Record_ID;
    else
        record_id = m_data.getButtonRecordID(keyColumn);
    String tableName = lookupColumn.substring(0, lookupColumn.length() - 3);
    //whereClause = tableName + ".IsSummary='N'" + whereClause; // Elaine 2008/07/28
    //  Open modal
    InfoPanel info = InfoPanel.create(m_data.WindowNo, tableName, lookupColumn, record_id, "", false, whereClause);
    if (!info.loadedOK()) {
        info.dispose();
        info = null;
        button.setLabel("");
        m_data.whereInfo.put(keyColumn, "");
        m_data.buttonRecordID.put(keyColumn, null);
        return 0;
    }
    info.setVisible(true);
    AEnv.showWindow(info);
    boolean isCancelled = info.isCancelled();
    boolean isOK = info.isOk();
    Integer key = 0;
    if (// Delete the saved info
    isCancelled && !isOK) {
        key = 0;
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  no query
            m_data.whereInfo.put(keyColumn, "");
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        button.setLabel("");
    } else if (!isCancelled && isOK) {
        //  Save for query
        //  C_Project_ID=100 or ""
        String selectSQL = info.getSelectedSQL();
        key = (Integer) info.getSelectedKey();
        log.config(keyColumn + " - " + key);
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  Add to query
            m_data.whereInfo.put(keyColumn, keyColumn + "=" + key.intValue());
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        //  Display Selection and resize
        button.setLabel(m_data.getButtonText(tableName, lookupColumn, selectSQL));
    } else if (// xor: window closed or error - no change
    !(isCancelled ^ isOK)) {
        // m_data not changed
        if (//  Record_ID
        button == selRecord)
            key = m_data.Record_ID = key.intValue();
        else
            key = m_data.getButtonRecordID(keyColumn);
    }
    info = null;
    return key.intValue();
}
Also used : Query(org.compiere.model.Query) InfoPanel(org.adempiere.webui.panel.InfoPanel) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 8 with MAcctSchemaElement

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

the class AcctViewer method actionButton.

//  actionTable
/**
	 *  Action Button
	 *
	 *  @param button pressed button
	 *  @return ID
	 */
private int actionButton(CButton button) {
    String keyColumn = button.getActionCommand();
    log.info(keyColumn);
    String whereClause = "(IsSummary='N' OR IsSummary IS NULL)";
    String lookupColumn = keyColumn;
    int record_id = m_data.getButtonRecordID(keyColumn);
    if (keyColumn.equals("Account_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_Account);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User1_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList1);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User2_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList2);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User3_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList3);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("User4_ID")) {
        lookupColumn = "C_ElementValue_ID";
        MAcctSchemaElement ase = m_data.ASchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserList4);
        if (ase != null)
            whereClause += " AND C_Element_ID=" + ase.getC_Element_ID();
    } else if (keyColumn.equals("M_Product_ID")) {
        whereClause = "";
    }
    if (lookupColumn.equals("UserElement1_ID")) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X1' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    }
    if (lookupColumn.equals("UserElement2_ID")) {
        MAcctSchemaElement et = new Query(Env.getCtx(), MAcctSchemaElement.Table_Name, "elementtype = 'X2' ", null).setClient_ID().firstOnly();
        String tableName = et.getAD_Column().getAD_Table().getTableName();
        String lookupcolumnname = tableName + "_ID";
        lookupColumn = lookupcolumnname;
        whereClause = "";
    } else if (selDocument.isSelected())
        whereClause = "";
    if (//  Record_ID
    button == selRecord)
        record_id = m_data.Record_ID;
    else
        record_id = m_data.getButtonRecordID(keyColumn);
    String tableName = lookupColumn.substring(0, lookupColumn.length() - 3);
    Info info = Info.create(this, true, m_data.WindowNo, tableName, lookupColumn, record_id, "", false, true, whereClause);
    if (!info.loadedOK()) {
        info.dispose();
        info = null;
        button.setText("");
        m_data.whereInfo.put(keyColumn, "");
        m_data.buttonRecordID.put(keyColumn, null);
        return 0;
    }
    info.setVisible(true);
    boolean isCancelled = info.isCancelled();
    boolean isOK = info.isOk();
    Integer key = 0;
    if (// Delete the saved info
    isCancelled && !isOK) {
        key = 0;
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  no query
            m_data.whereInfo.put(keyColumn, "");
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        button.setText("");
    } else if (!isCancelled && isOK) {
        //  Save for query
        //  C_Project_ID=100 or ""
        String selectSQL = info.getSelectedSQL();
        key = (Integer) info.getSelectedKey();
        log.config(keyColumn + " - " + key);
        if (//  Record_ID
        button == selRecord)
            m_data.Record_ID = key.intValue();
        else {
            //  Add to query
            m_data.whereInfo.put(keyColumn, keyColumn + "=" + key.intValue());
            m_data.buttonRecordID.put(keyColumn, key.intValue());
        }
        //  Display Selection and resize
        button.setText(m_data.getButtonText(tableName, lookupColumn, selectSQL));
        pack();
    } else if (// xor: window closed or error - no change
    !(isCancelled ^ isOK)) {
        // m_data not changed
        if (//  Record_ID
        button == selRecord)
            key = m_data.Record_ID = key.intValue();
        else
            key = m_data.getButtonRecordID(keyColumn);
    }
    info = null;
    return key.intValue();
}
Also used : Query(org.compiere.model.Query) Info(org.compiere.apps.search.Info) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 9 with MAcctSchemaElement

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

the class Doc_AllocationTax method isInterOrg.

//  createFact
/** Verify if the posting involves two or more organizations
	@return true if there are more than one org involved on the posting
	 */
private boolean isInterOrg(MAcctSchema as) {
    MAcctSchemaElement elementorg = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Organization);
    if (elementorg == null || !elementorg.isBalanced()) {
        // no org element or not need to be balanced
        return false;
    }
    if (p_lines.length <= 0) {
        // no lines
        return false;
    }
    int startorg = p_lines[0].getAD_Org_ID();
    // validate if the allocation involves more than one org
    for (int i = 0; i < p_lines.length; i++) {
        DocLine_Allocation line = (DocLine_Allocation) p_lines[i];
        int orgpayment = startorg;
        MPayment payment = null;
        if (line.getC_Payment_ID() != 0) {
            payment = new MPayment(getCtx(), line.getC_Payment_ID(), getTrxName());
            orgpayment = payment.getAD_Org_ID();
        }
        int orginvoice = startorg;
        MInvoice invoice = null;
        if (line.getC_Invoice_ID() != 0) {
            invoice = new MInvoice(getCtx(), line.getC_Invoice_ID(), getTrxName());
            orginvoice = invoice.getAD_Org_ID();
        }
        int orgcashline = startorg;
        MCashLine cashline = null;
        if (line.getC_CashLine_ID() != 0) {
            cashline = new MCashLine(getCtx(), line.getC_CashLine_ID(), getTrxName());
            orgcashline = cashline.getAD_Org_ID();
        }
        int orgorder = startorg;
        MOrder order = null;
        if (line.getC_Order_ID() != 0) {
            order = new MOrder(getCtx(), line.getC_Order_ID(), getTrxName());
            orgorder = order.getAD_Org_ID();
        }
        if (line.getAD_Org_ID() != startorg || orgpayment != startorg || orginvoice != startorg || orgcashline != startorg || orgorder != startorg)
            return true;
    }
    return false;
}
Also used : MOrder(org.compiere.model.MOrder) MPayment(org.compiere.model.MPayment) MInvoice(org.compiere.model.MInvoice) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) MCashLine(org.compiere.model.MCashLine)

Example 10 with MAcctSchemaElement

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

the class FactLine method setAccount.

//	reverse
/**
	 *  Set Account Info
	 *  @param acctSchema account schema
	 *  @param acct account
	 */
public void setAccount(MAcctSchema acctSchema, MAccount acct) {
    m_acctSchema = acctSchema;
    setC_AcctSchema_ID(acctSchema.getC_AcctSchema_ID());
    //
    m_acct = acct;
    if (getAD_Client_ID() == 0)
        setAD_Client_ID(m_acct.getAD_Client_ID());
    setAccount_ID(m_acct.getAccount_ID());
    setC_SubAcct_ID(m_acct.getC_SubAcct_ID());
    //	User Defined References
    MAcctSchemaElement ud1 = m_acctSchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserElement1);
    if (ud1 != null) {
        String ColumnName1 = ud1.getDisplayColumnName();
        if (ColumnName1 != null) {
            int ID1 = 0;
            if (m_docLine != null)
                ID1 = m_docLine.getValue(ColumnName1);
            if (ID1 == 0) {
                if (m_doc == null)
                    throw new IllegalArgumentException("Document not set yet");
                ID1 = m_doc.getValue(ColumnName1);
            }
            if (ID1 != 0)
                setUserElement1_ID(ID1);
        }
    }
    MAcctSchemaElement ud2 = m_acctSchema.getAcctSchemaElement(X_C_AcctSchema_Element.ELEMENTTYPE_UserElement2);
    if (ud2 != null) {
        String ColumnName2 = ud2.getDisplayColumnName();
        if (ColumnName2 != null) {
            int ID2 = 0;
            if (m_docLine != null)
                ID2 = m_docLine.getValue(ColumnName2);
            if (ID2 == 0) {
                if (m_doc == null)
                    throw new IllegalArgumentException("Document not set yet");
                ID2 = m_doc.getValue(ColumnName2);
            }
            if (ID2 != 0)
                setUserElement2_ID(ID2);
        }
    }
}
Also used : MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Aggregations

MAcctSchemaElement (org.compiere.model.MAcctSchemaElement)18 MAcctSchema (org.compiere.model.MAcctSchema)7 ArrayList (java.util.ArrayList)5 MAccount (org.compiere.model.MAccount)4 Timestamp (java.sql.Timestamp)3 Query (org.compiere.model.Query)3 KeyNamePair (org.compiere.util.KeyNamePair)3 ValueNamePair (org.compiere.util.ValueNamePair)3 BigDecimal (java.math.BigDecimal)2 Date (java.sql.Date)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Arrays (java.util.Arrays)2 Calendar (java.util.Calendar)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2