Search in sources :

Example 11 with MAcctSchemaElement

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

the class WAcctViewer method actionQuery.

// sortAddItem
/**
	 *  Query
	 */
private void actionQuery() {
    //  Parameter Info
    StringBuffer para = new StringBuffer();
    //  Reset Selection Data
    m_data.C_AcctSchema_ID = 0;
    m_data.AD_Org_ID = 0;
    //  Save Selection Choices
    Listitem listitem = selAcctSchema.getSelectedItem();
    KeyNamePair kp = null;
    if (listitem != null)
        kp = (KeyNamePair) listitem.getValue();
    if (kp != null)
        m_data.C_AcctSchema_ID = kp.getKey();
    para.append("C_AcctSchema_ID=").append(m_data.C_AcctSchema_ID);
    listitem = selPostingType.getSelectedItem();
    ValueNamePair vp = null;
    if (listitem != null)
        vp = (ValueNamePair) listitem.getValue();
    else
        return;
    m_data.PostingType = vp.getValue();
    para.append(", PostingType=").append(m_data.PostingType);
    //  Document
    m_data.documentQuery = selDocument.isChecked();
    para.append(", DocumentQuery=").append(m_data.documentQuery);
    if (selDocument.isChecked()) {
        if (m_data.AD_Table_ID == 0 || m_data.Record_ID == 0)
            return;
        para.append(", AD_Table_ID=").append(m_data.AD_Table_ID).append(", Record_ID=").append(m_data.Record_ID);
    } else {
        m_data.DateFrom = selDateFrom.getValue() != null ? new Timestamp(selDateFrom.getValue().getTime()) : null;
        para.append(", DateFrom=").append(m_data.DateFrom);
        m_data.DateTo = selDateTo.getValue() != null ? new Timestamp(selDateTo.getValue().getTime()) : null;
        para.append(", DateTo=").append(m_data.DateTo);
        listitem = selOrg.getSelectedItem();
        if (listitem != null)
            kp = (KeyNamePair) listitem.getValue();
        else
            kp = null;
        if (kp != null)
            m_data.AD_Org_ID = kp.getKey();
        para.append(", AD_Org_ID=").append(m_data.AD_Org_ID);
        //
        Iterator<String> it = m_data.whereInfo.values().iterator();
        while (it.hasNext()) para.append(", ").append(it.next());
    }
    //  Save Display Choices
    m_data.displayQty = displayQty.isChecked();
    para.append(" - Display Qty=").append(m_data.displayQty);
    m_data.displaySourceAmt = displaySourceAmt.isChecked();
    para.append(", Source=").append(m_data.displaySourceAmt);
    m_data.displayDocumentInfo = displayDocumentInfo.isChecked();
    para.append(", Doc=").append(m_data.displayDocumentInfo);
    listitem = sortBy1.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy1 = vp.getValue();
            m_data.group1 = group1.isChecked();
            para.append(" - Sorting: ").append(m_data.sortBy1).append("/").append(m_data.group1);
        }
    }
    listitem = sortBy2.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy2 = vp.getValue();
            m_data.group2 = group2.isChecked();
            para.append(", ").append(m_data.sortBy2).append("/").append(m_data.group2);
        }
    }
    listitem = sortBy3.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy3 = vp.getValue();
            m_data.group3 = group3.isChecked();
            para.append(", ").append(m_data.sortBy3).append("/").append(m_data.group3);
        }
    }
    listitem = sortBy4.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy4 = vp.getValue();
            m_data.group4 = group4.isChecked();
            para.append(", ").append(m_data.sortBy4).append("/").append(m_data.group4);
        }
    }
    bQuery.setEnabled(false);
    statusLine.setValue(" " + Msg.getMsg(Env.getCtx(), "Processing"));
    log.config(para.toString());
    //  Switch to Result pane
    tabbedPane.setSelectedIndex(1);
    //  Set TableModel with Query
    RModel rmodel = m_data.query();
    m_queryData = rmodel.getRows();
    List<ArrayList<Object>> list = null;
    paging.setPageSize(PAGE_SIZE);
    if (m_queryData.size() > PAGE_SIZE) {
        list = m_queryData.subList(0, PAGE_SIZE);
        paging.setTotalSize(m_queryData.size());
        pagingPanel.setVisible(true);
    } else {
        list = m_queryData;
        paging.setTotalSize(m_queryData.size());
        pagingPanel.setVisible(false);
    }
    paging.setActivePage(0);
    ListModelTable listmodeltable = new ListModelTable(list);
    if (table.getListhead() == null) {
        Listhead listhead = new Listhead();
        listhead.setSizable(true);
        for (int i = 0; i < rmodel.getColumnCount(); i++) {
            // Replace user columns with the user selected names
            String displayColumnName = rmodel.getColumnName(i);
            ;
            String columnName;
            RColumn col = rmodel.getColumn(i);
            columnName = col.getColumnName();
            MAcctSchema as = MAcctSchema.get(Env.getCtx(), m_data.C_AcctSchema_ID);
            if (columnName.equals("User1_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList1);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            } else if (columnName.equals("User2_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList2);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            } else if (columnName.equals("User3_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList3);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            } else if (columnName.equals("User4_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList4);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            }
            Listheader listheader = new Listheader(displayColumnName);
            listheader.setTooltiptext(rmodel.getColumnName(i));
            listhead.appendChild(listheader);
        }
        table.appendChild(listhead);
    } else // Elaine 2008/07/28
    {
        Listhead listhead = table.getListhead();
        // remove existing column header
        listhead.getChildren().clear();
        // add in new column header
        for (int i = 0; i < rmodel.getColumnCount(); i++) {
            Listheader listheader = new Listheader(rmodel.getColumnName(i));
            listhead.appendChild(listheader);
        }
    }
    //
    table.getItems().clear();
    table.setItemRenderer(new WListItemRenderer());
    table.setModel(listmodeltable);
    resultPanel.invalidate();
    bQuery.setEnabled(true);
    statusLine.setValue(" " + Msg.getMsg(Env.getCtx(), "ViewerOptions"));
}
Also used : WListItemRenderer(org.adempiere.webui.component.WListItemRenderer) Listheader(org.zkoss.zul.Listheader) Listhead(org.zkoss.zul.Listhead) Listitem(org.zkoss.zul.Listitem) ArrayList(java.util.ArrayList) RModel(org.compiere.report.core.RModel) ListModelTable(org.adempiere.webui.component.ListModelTable) RColumn(org.compiere.report.core.RColumn) Timestamp(java.sql.Timestamp) MAcctSchema(org.compiere.model.MAcctSchema) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 12 with MAcctSchemaElement

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

the class AcctSchemaCopyAcct method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("SourceAcctSchema_ID=" + p_SourceAcctSchema_ID + ", TargetAcctSchema_ID=" + p_TargetAcctSchema_ID);
    if (p_SourceAcctSchema_ID == 0 || p_TargetAcctSchema_ID == 0)
        throw new AdempiereSystemError("ID=0");
    if (p_SourceAcctSchema_ID == p_TargetAcctSchema_ID)
        throw new AdempiereUserError("Must be different");
    MAcctSchema source = MAcctSchema.get(getCtx(), p_SourceAcctSchema_ID, null);
    if (source.get_ID() == 0)
        throw new AdempiereSystemError("NotFound Source C_AcctSchema_ID=" + p_SourceAcctSchema_ID);
    MAcctSchema target = new MAcctSchema(getCtx(), p_TargetAcctSchema_ID, get_TrxName());
    if (target.get_ID() == 0)
        throw new AdempiereSystemError("NotFound Target C_AcctSchema_ID=" + p_TargetAcctSchema_ID);
    //
    MAcctSchemaElement[] targetElements = target.getAcctSchemaElements();
    if (targetElements.length == 0)
        throw new AdempiereUserError("NotFound Target C_AcctSchema_Element");
    //	Accounting Element must be the same
    MAcctSchemaElement sourceAcctElement = source.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account);
    if (sourceAcctElement == null)
        throw new AdempiereUserError("NotFound Source AC C_AcctSchema_Element");
    MAcctSchemaElement targetAcctElement = target.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account);
    if (targetAcctElement == null)
        throw new AdempiereUserError("NotFound Target AC C_AcctSchema_Element");
    if (sourceAcctElement.getC_Element_ID() != targetAcctElement.getC_Element_ID())
        throw new AdempiereUserError("@C_Element_ID@ different");
    if (MAcctSchemaGL.get(getCtx(), p_TargetAcctSchema_ID) == null)
        copyGL(target);
    if (MAcctSchemaDefault.get(getCtx(), p_TargetAcctSchema_ID) == null)
        copyDefault(target);
    return "@OK@";
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) AdempiereUserError(org.compiere.util.AdempiereUserError) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 13 with MAcctSchemaElement

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

the class AcctSchemaCopyAcct method createAccount.

//	copyDefault
/**
	 * 	Create Account
	 *	@param targetAS target AS
	 *	@param sourceAcct source account
	 *	@return target account
	 */
private MAccount createAccount(MAcctSchema targetAS, MAccount sourceAcct) {
    int AD_Client_ID = targetAS.getAD_Client_ID();
    int C_AcctSchema_ID = targetAS.getC_AcctSchema_ID();
    //
    int AD_Org_ID = 0;
    int Account_ID = 0;
    int C_SubAcct_ID = 0;
    int M_Product_ID = 0;
    int C_BPartner_ID = 0;
    int AD_OrgTrx_ID = 0;
    int C_LocFrom_ID = 0;
    int C_LocTo_ID = 0;
    int C_SalesRegion_ID = 0;
    int C_Project_ID = 0;
    int C_Campaign_ID = 0;
    int C_Activity_ID = 0;
    int User1_ID = 0;
    int User2_ID = 0;
    int User3_ID = 0;
    int User4_ID = 0;
    int UserElement1_ID = 0;
    int UserElement2_ID = 0;
    //
    //  Active Elements
    MAcctSchemaElement[] elements = targetAS.getAcctSchemaElements();
    for (int i = 0; i < elements.length; i++) {
        MAcctSchemaElement ase = elements[i];
        String elementType = ase.getElementType();
        //
        if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Organization))
            AD_Org_ID = sourceAcct.getAD_Org_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Account))
            Account_ID = sourceAcct.getAccount_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount))
            C_SubAcct_ID = sourceAcct.getC_SubAcct_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner))
            C_BPartner_ID = sourceAcct.getC_BPartner_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Product))
            M_Product_ID = sourceAcct.getM_Product_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Activity))
            C_Activity_ID = sourceAcct.getC_Activity_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom))
            C_LocFrom_ID = sourceAcct.getC_LocFrom_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo))
            C_LocTo_ID = sourceAcct.getC_LocTo_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign))
            C_Campaign_ID = sourceAcct.getC_Campaign_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx))
            AD_OrgTrx_ID = sourceAcct.getAD_OrgTrx_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_Project))
            C_Project_ID = sourceAcct.getC_Project_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion))
            C_SalesRegion_ID = sourceAcct.getC_SalesRegion_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1))
            User1_ID = sourceAcct.getUser1_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2))
            User2_ID = sourceAcct.getUser2_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3))
            User3_ID = sourceAcct.getUser3_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4))
            User3_ID = sourceAcct.getUser4_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserElement1))
            UserElement1_ID = sourceAcct.getUserElement1_ID();
        else if (elementType.equals(MAcctSchemaElement.ELEMENTTYPE_UserElement2))
            UserElement2_ID = sourceAcct.getUserElement2_ID();
    //	No UserElement
    }
    //
    return MAccount.get(getCtx(), AD_Client_ID, AD_Org_ID, C_AcctSchema_ID, Account_ID, C_SubAcct_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SalesRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, User3_ID, User4_ID, UserElement1_ID, UserElement2_ID, null);
}
Also used : MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 14 with MAcctSchemaElement

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

the class WebEditorFactory method getEditor.

public static WEditor getEditor(GridTab gridTab, GridField gridField, boolean tableEditor) {
    if (gridField == null) {
        return null;
    }
    WEditor editor = null;
    int displayType = gridField.getDisplayType();
    /** Not a Field */
    if (gridField.isHeading()) {
        return null;
    }
    /** String (clear/password) */
    if (displayType == DisplayType.String || displayType == DisplayType.PrinterName || (tableEditor && (displayType == DisplayType.Text || displayType == DisplayType.TextLong))) {
        if (gridField.isEncryptedField()) {
            editor = new WPasswordEditor(gridField);
        } else {
            editor = new WStringEditor(gridField, tableEditor);
        }
    } else /** File */
    if (displayType == DisplayType.FileName) {
        editor = new WFilenameEditor(gridField);
    } else /** File Path */
    if (displayType == DisplayType.FilePath) {
        editor = new WFileDirectoryEditor(gridField);
    } else /** File Path or Name */
    if (displayType == DisplayType.FilePathOrName) {
        editor = new WFilenameEditor(gridField);
    } else /** Number */
    if (DisplayType.isNumeric(displayType)) {
        editor = new WNumberEditor(gridField);
    } else /** YesNo */
    if (displayType == DisplayType.YesNo) {
        editor = new WYesNoEditor(gridField);
        if (tableEditor)
            ((WYesNoEditor) editor).getComponent().setLabel("");
    } else /** Text */
    if (displayType == DisplayType.Text || displayType == DisplayType.Memo || displayType == DisplayType.TextLong) {
        editor = new WStringEditor(gridField);
    } else /** Date */
    if (DisplayType.isDate(displayType)) {
        if (displayType == DisplayType.Time)
            editor = new WTimeEditor(gridField);
        else if (displayType == DisplayType.DateTime)
            editor = new WDatetimeEditor(gridField);
        else
            editor = new WDateEditor(gridField);
    } else /**  Button */
    if (displayType == DisplayType.Button) {
        editor = new WButtonEditor(gridField);
    } else /** Table Direct */
    if (displayType == DisplayType.TableDir || displayType == DisplayType.Table || displayType == DisplayType.List || displayType == DisplayType.ID) {
        editor = new WTableDirEditor(gridField);
    } else if (displayType == DisplayType.URL) {
        editor = new WUrlEditor(gridField);
    } else if (displayType == DisplayType.Search) {
        editor = new WSearchEditor(gridField);
    } else if (displayType == DisplayType.Location) {
        editor = new WLocationEditor(gridField);
    } else if (displayType == DisplayType.Locator) {
        editor = new WLocatorEditor(gridField);
    } else if (displayType == DisplayType.Account) {
        editor = new WAccountEditor(gridField);
    } else if (displayType == DisplayType.Image) {
        editor = new WImageEditor(gridField);
    } else if (displayType == DisplayType.Binary) {
        editor = new WBinaryEditor(gridField);
    } else if (displayType == DisplayType.PAttribute) {
        editor = new WPAttributeEditor(gridTab, gridField);
    } else if (displayType == DisplayType.Assignment) {
        editor = new WAssignmentEditor(gridField);
    } else if (displayType == DisplayType.Chart) {
        editor = new WChartEditor(gridField, gridTab.getWindowNo());
    } else {
        editor = new WUnknownEditor(gridField);
    }
    // Change the label from the column to a user defined value for specific fields.
    if (gridField.getColumnName() != null && gridField.getColumnName().equals("User1_ID") || gridField.getColumnName() != null && gridField.getColumnName().equals("User2_ID") || gridField.getColumnName() != null && gridField.getColumnName().equals("User3_ID") || gridField.getColumnName() != null && gridField.getColumnName().equals("User4_ID")) {
        int accountSchemaId = Env.getContextAsInt(Env.getCtx(), "$C_AcctSchema_ID");
        if (accountSchemaId > 0) {
            MAcctSchema accountSchema = MAcctSchema.get(Env.getCtx(), accountSchemaId);
            if (accountSchema != null) {
                MAcctSchemaElement accountSchemaElement = null;
                if (gridField.getColumnName().equals("User1_ID"))
                    accountSchemaElement = accountSchema.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList1);
                else if (gridField.getColumnName().equals("User2_ID"))
                    accountSchemaElement = accountSchema.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList2);
                else if (gridField.getColumnName().equals("User3_ID"))
                    accountSchemaElement = accountSchema.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList3);
                else if (gridField.getColumnName().equals("User4_ID"))
                    accountSchemaElement = accountSchema.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList4);
                if (accountSchemaElement != null)
                    editor.setLabel(accountSchemaElement.getName());
            }
        }
    }
    return editor;
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 15 with MAcctSchemaElement

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

the class AcctViewerData 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)

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