Search in sources :

Example 11 with MTable

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

the class AbstractDocumentSearch method getID.

/**
	 * search for id's that fit the searchString
	 *
	 * @param transactionCode
	 * @param searchString
	 */
private void getID(String transactionCode, String searchString) {
    ResultSet rsSO = null;
    ResultSet rsPO = null;
    PreparedStatement pstmtSO = null;
    PreparedStatement pstmtPO = null;
    String sqlSO = null;
    String sqlPO = null;
    final Properties ctx = Env.getCtx();
    final MRole role = MRole.get(ctx, Env.getAD_Role_ID(ctx), Env.getAD_User_ID(ctx), true);
    try {
        for (MSearchDefinition msd : MSearchDefinition.getForCode(transactionCode)) {
            MTable table = new MTable(Env.getCtx(), msd.getAD_Table_ID(), null);
            // SearchDefinition with a given table and column
            if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_TABLE)) {
                MColumn column = new MColumn(Env.getCtx(), msd.getAD_Column_ID(), null);
                sqlSO = "SELECT " + table.getTableName() + "_ID FROM " + table.getTableName() + " ";
                // search for an Integer
                if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) {
                    sqlSO += "WHERE " + column.getColumnName() + "=?";
                // search for a String
                } else {
                    sqlSO += "WHERE UPPER(" + column.getColumnName() + ") LIKE UPPER(?)";
                }
                if (msd.getPO_Window_ID() != 0) {
                    sqlPO = sqlSO + " AND IsSOTrx='N'";
                    sqlSO += " AND IsSOTrx='Y'";
                }
                pstmtSO = DB.prepareStatement(sqlSO, null);
                pstmtPO = DB.prepareStatement(sqlPO, null);
                // search for a Integer
                if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) {
                    pstmtSO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", "")));
                    if (msd.getPO_Window_ID() != 0) {
                        pstmtPO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", "")));
                    }
                // search for a String
                } else if (msd.getDataType().equals(MSearchDefinition.DATATYPE_STRING)) {
                    pstmtSO.setString(1, searchString);
                    if (msd.getPO_Window_ID() != 0) {
                        pstmtPO.setString(1, searchString);
                    }
                }
            // SearchDefinition with a special query
            } else if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_QUERY)) {
                sqlSO = msd.getQuery();
                pstmtSO = DB.prepareStatement(sqlSO, null);
                // count '?' in statement
                int count = 1;
                for (char c : sqlSO.toCharArray()) {
                    if (c == '?') {
                        count++;
                    }
                }
                for (int i = 1; i < count; i++) {
                    if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) {
                        pstmtSO.setInt(i, Integer.valueOf(searchString.replaceAll("\\D", "")));
                    } else if (msd.getDataType().equals(MSearchDefinition.DATATYPE_STRING)) {
                        pstmtSO.setString(i, searchString);
                    }
                }
            }
            if (pstmtSO != null) {
                log.fine("SQL Sales: " + sqlSO);
                rsSO = pstmtSO.executeQuery();
                Vector<Integer> idSO = new Vector<Integer>();
                while (rsSO.next()) {
                    idSO.add(new Integer(rsSO.getInt(1)));
                }
                if (role.getWindowAccess(msd.getAD_Window_ID()) != null) {
                    log.fine("Open Window: " + msd.getAD_Window_ID() + " / Table: " + table.getTableName() + " / Number of Results: " + idSO.size());
                    if (idSO.size() == 0 && (searchString == null || searchString.trim().length() == 0)) {
                        // No search string - open the window with new record
                        idSO.add(new Integer(0));
                    }
                    openWindow(idSO, table.getTableName(), msd.getAD_Window_ID());
                } else {
                    log.warning("Role is not allowed to view this window");
                }
            }
            if (pstmtPO != null) {
                log.fine("SQL Purchase: " + sqlPO);
                rsPO = pstmtPO.executeQuery();
                Vector<Integer> idPO = new Vector<Integer>();
                while (rsPO.next()) {
                    idPO.add(new Integer(rsPO.getInt(1)));
                }
                if (role.getWindowAccess(msd.getPO_Window_ID()) != null) {
                    log.fine("Open Window: " + msd.getPO_Window_ID() + " / Table: " + table.getTableName() + " / Number of Results: " + idPO.size());
                    openWindow(idPO, table.getTableName(), msd.getPO_Window_ID());
                } else {
                    log.warning("Role is not allowed to view this window");
                }
            }
            DB.close(rsSO, pstmtSO);
            DB.close(rsPO, pstmtPO);
            pstmtSO = null;
            pstmtPO = null;
            rsSO = null;
            rsPO = null;
        }
    } catch (Exception e) {
        log.severe(e.toString());
        e.printStackTrace();
    } finally {
        DB.close(rsSO, pstmtSO);
        DB.close(rsPO, pstmtPO);
        rsSO = null;
        rsPO = null;
        pstmtSO = null;
        pstmtPO = null;
    }
}
Also used : MColumn(org.compiere.model.MColumn) MTable(org.compiere.model.MTable) MSearchDefinition(org.compiere.model.MSearchDefinition) MRole(org.compiere.model.MRole) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) Vector(java.util.Vector) SQLException(java.sql.SQLException)

Example 12 with MTable

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

the class ImportBudget method fillIdValues.

/**
     * Fill Id Values
     * @param importBudget
     * @param acctSchemaElements
     * @param trxName
     */
private void fillIdValues(X_I_Budget importBudget, MAcctSchemaElement[] acctSchemaElements, String trxName) {
    StringBuffer stringError = new StringBuffer("");
    // Set Organization
    Integer orgId = 0;
    if (importBudget.getAD_Org_ID() > 0)
        orgId = importBudget.getAD_Org_ID();
    if (orgId <= 0 && importBudget.getOrgValue() != null)
        orgId = getId(MOrg.Table_Name, MOrg.COLUMNNAME_Value + "=?", trxName, importBudget.getOrgValue());
    if (orgId > 0 && importBudget.getAD_Org_ID() <= 0)
        importBudget.setAD_Org_ID(orgId);
    if (importBudget.getAD_Org_ID() <= 0 && importBudget.getOrgValue() != null)
        stringError.append("@AD_Org_ID@ @NotFound@ ");
    // Set Organization Trx
    Integer orgTrxId = 0;
    if (importBudget.getAD_OrgTrx_ID() > 0)
        orgTrxId = importBudget.getAD_OrgTrx_ID();
    if (orgTrxId <= 0 && importBudget.getOrgTrxValue() != null)
        orgTrxId = getId(MOrg.Table_Name, MOrg.COLUMNNAME_Value + "=?", trxName, importBudget.getOrgTrxValue());
    if (orgTrxId > 0 && importBudget.getAD_OrgTrx_ID() <= 0)
        importBudget.setAD_OrgTrx_ID(orgTrxId);
    if (importBudget.getAD_Org_ID() <= 0 && importBudget.getOrgTrxValue() != null)
        stringError.append("@AD_OrgTrx_ID@ @NotFound@ ");
    // Set Account Schema
    Integer accountSchemaId = 0;
    if (importBudget.getC_AcctSchema_ID() > 0)
        accountSchemaId = importBudget.getC_AcctSchema_ID();
    if (accountSchemaId <= 0 && importBudget.getAcctSchemaName() != null)
        accountSchemaId = getId(MAcctSchema.Table_Name, MAcctSchema.COLUMNNAME_Name + "=?", trxName, importBudget.getAcctSchemaName());
    if (accountSchemaId > 0 && importBudget.getC_AcctSchema_ID() <= 0)
        importBudget.setC_AcctSchema_ID(accountSchemaId);
    else {
        accountSchemaId = getAccountingSchemaId();
        importBudget.setC_AcctSchema_ID(accountSchemaId);
    }
    // Set Budget
    Integer budgetId = 0;
    if (importBudget.getGL_Budget_ID() > 0)
        budgetId = importBudget.getGL_Budget_ID();
    if (budgetId <= 0 && importBudget.getBudgetCode() != null)
        budgetId = getId(X_GL_Budget.Table_Name, X_GL_Budget.COLUMNNAME_Name + "=?", trxName, importBudget.getBudgetCode());
    if (budgetId > 0 && importBudget.getGL_Budget_ID() <= 0)
        importBudget.setGL_Budget_ID(budgetId);
    if (importBudget.getGL_Budget_ID() <= 0 && importBudget.getBudgetCode() != null)
        stringError.append("@GL_Budget_ID@ @NotFound@ ");
    // Set Asset
    Integer assetId = 0;
    if (importBudget.getA_Asset_ID() > 0)
        assetId = importBudget.getA_Asset_ID();
    if (assetId <= 0 && importBudget.getAssetValue() != null)
        assetId = getId(X_A_Asset.Table_Name, X_A_Asset.COLUMNNAME_Value + "=?", trxName, importBudget.getAssetValue());
    if (assetId > 0 && importBudget.getA_Asset_ID() <= 0)
        importBudget.setA_Asset_ID(assetId);
    if (importBudget.getA_Asset_ID() <= 0 && importBudget.getAssetValue() != null)
        stringError.append("@A_Asset_ID@ @NotFound@ ");
    // Set Account
    int accountId = 0;
    if (importBudget.getAccount_ID() > 0)
        accountId = importBudget.getAccount_ID();
    if (accountId <= 0 && importBudget.getAccountValue() != null)
        accountId = getId(MElementValue.Table_Name, MElementValue.COLUMNNAME_Value + "=?", trxName, importBudget.getAccountValue());
    if (accountId > 0 && importBudget.getAccount_ID() <= 0)
        importBudget.setAccount_ID(accountId);
    if (importBudget.getAccount_ID() <= 0 && importBudget.getAccountValue() != null)
        stringError.append("@Account_ID@ @NotFound@ ");
    int partnerId = 0;
    if (importBudget.getC_BPartner_ID() > 0)
        partnerId = importBudget.getC_BPartner_ID();
    if (partnerId <= 0 && importBudget.getBPartnerValue() != null) {
        MBPartner partner = MBPartner.get(getCtx(), importBudget.getBPartnerValue());
        if (partner != null)
            partnerId = partner.getC_BPartner_ID();
    }
    if (partnerId > 0 && importBudget.getC_BPartner_ID() <= 0)
        importBudget.setC_BPartner_ID(partnerId);
    if (importBudget.getC_BPartner_ID() <= 0 && importBudget.getBPartnerValue() != null)
        stringError.append("@C_BPartner_ID@ @NotFound@ ");
    // Set Product
    Integer productId = 0;
    if (importBudget.getM_Product_ID() > 0)
        productId = importBudget.getM_Product_ID();
    if (productId <= 0 && importBudget.getProductValue() != null)
        productId = getId(MProduct.Table_Name, MProduct.COLUMNNAME_Value + "=?", trxName, importBudget.getProductValue());
    if (productId > 0 && importBudget.getM_Product_ID() <= 0)
        importBudget.setM_Product_ID(productId);
    if (importBudget.getM_Product_ID() <= 0 && importBudget.getProductValue() != null)
        stringError.append("@M_Product_ID@ @NotFound@ ");
    // Set Project
    Integer projectId = 0;
    if (importBudget.getC_Project_ID() > 0)
        projectId = importBudget.getC_Project_ID();
    if (projectId <= 0 && importBudget.getProjectValue() != null)
        projectId = getId(MProject.Table_Name, MProject.COLUMNNAME_Value + "=?", trxName, importBudget.getProjectValue());
    if (projectId > 0 && importBudget.getC_Project_ID() <= 0)
        importBudget.setC_Project_ID(projectId);
    if (importBudget.getC_Project_ID() <= 0 && importBudget.getProjectValue() != null)
        stringError.append("@C_Project_ID@ @NotFound@ ");
    // Set Campaign
    Integer campaignId = 0;
    if (importBudget.getC_Campaign_ID() > 0)
        campaignId = importBudget.getC_Campaign_ID();
    if (campaignId <= 0 && importBudget.getCampaignValue() != null)
        campaignId = getId(MCampaign.Table_Name, MCampaign.COLUMNNAME_Value + "=?", trxName, importBudget.getCampaignValue());
    if (campaignId > 0 && importBudget.getC_Campaign_ID() <= 0)
        importBudget.setC_Campaign_ID(campaignId);
    if (importBudget.getC_Campaign_ID() <= 0 && importBudget.getCampaignValue() != null)
        stringError.append("@C_Campaign_ID@ @NotFound@ ");
    // Set Sales Region
    Integer salesRegionId = 0;
    if (importBudget.getC_SalesRegion_ID() > 0)
        salesRegionId = importBudget.getC_SalesRegion_ID();
    if (salesRegionId <= 0 && importBudget.getSalesRegionValue() != null)
        salesRegionId = getId(MSalesRegion.Table_Name, MSalesRegion.COLUMNNAME_Value + "=?", trxName, importBudget.getSalesRegionValue());
    if (salesRegionId > 0 && importBudget.getC_SalesRegion_ID() <= 0)
        importBudget.setC_SalesRegion_ID(salesRegionId);
    if (importBudget.getC_SalesRegion_ID() <= 0 && importBudget.getSalesRegionValue() != null)
        stringError.append("@C_SalesRegion_ID@ @NotFound@");
    // Set Activity Id
    Integer activityId = 0;
    if (importBudget.getC_Activity_ID() > 0)
        activityId = importBudget.getC_Activity_ID();
    if (activityId <= 0 && importBudget.getActivityValue() != null)
        activityId = getId(MActivity.Table_Name, MActivity.COLUMNNAME_Value + "=?", trxName, importBudget.getActivityValue());
    if (accountId > 0 && importBudget.getC_Activity_ID() <= 0)
        importBudget.setC_Activity_ID(activityId);
    if (importBudget.getC_Activity_ID() <= 0 && importBudget.getActivityValue() != null)
        stringError.append("@C_SalesRegion_ID@ @NotFound@ ");
    // Set Sub Acct Id
    Integer subAcctountId = 0;
    if (importBudget.getC_SubAcct_ID() > 0)
        subAcctountId = importBudget.getC_SubAcct_ID();
    if (subAcctountId <= 0 && importBudget.getSubAcctValue() != null)
        subAcctountId = getId(X_C_SubAcct.Table_Name, X_C_SubAcct.COLUMNNAME_Value + "=?", trxName, importBudget.getSubAcctValue());
    if (subAcctountId > 0 && importBudget.getC_SubAcct_ID() <= 0)
        importBudget.setC_SubAcct_ID(subAcctountId);
    if (importBudget.getC_SubAcct_ID() <= 0 && importBudget.getSubAcctValue() != null)
        stringError.append("@C_SubAcct_ID@ @NotFound@ ");
    // Set User 1
    Integer user1Id = 0;
    if (importBudget.getUser1_ID() > 0)
        user1Id = importBudget.getUser1_ID();
    if (user1Id <= 0 && importBudget.getUser1_ID() <= 0 && importBudget.getUserValue1() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList1.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser1_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue1()));
        });
    }
    if (importBudget.getUser1_ID() <= 0 && importBudget.getUserValue1() != null)
        stringError.append("@User1_ID@ @NotFound@ ");
    // User 2
    Integer user2Id = 0;
    if (importBudget.getUser2_ID() > 0)
        user2Id = importBudget.getUser2_ID();
    if (user2Id <= 0 && importBudget.getUser2_ID() <= 0 && importBudget.getUserValue2() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList2.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser2_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue2()));
        });
    }
    if (importBudget.getUser2_ID() <= 0 && importBudget.getUserValue2() != null)
        stringError.append("@User2_ID@ @NotFound@ ");
    Integer user3Id = 0;
    if (importBudget.getUser3_ID() > 0)
        user3Id = importBudget.getUser3_ID();
    if (user3Id <= 0 && importBudget.getUser3_ID() <= 0 && importBudget.getUserValue3() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList3.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser3_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue3()));
        });
    }
    if (importBudget.getUser3_ID() <= 0 && importBudget.getUserValue3() != null)
        stringError.append("@User3_ID@ @NotFound@ ");
    Integer user4Id = 0;
    if (importBudget.getUser4_ID() > 0)
        user4Id = importBudget.getUser4_ID();
    if (user4Id <= 0 && importBudget.getUser4_ID() <= 0 && importBudget.getUserValue4() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserList4.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            String where = MElementValue.COLUMNNAME_C_Element_ID + "=? AND " + MElementValue.COLUMNNAME_Value + "=?";
            importBudget.setUser4_ID(getId(MElementValue.Table_Name, where, trxName, acctSchemaElement.getC_Element_ID(), importBudget.getUserValue4()));
        });
    }
    if (importBudget.getUser4_ID() <= 0 && importBudget.getUserValue4() != null)
        stringError.append("@User4_ID@ @NotFound@ ");
    Integer userElement1Id = 0;
    if (importBudget.getUserElement1_ID() > 0)
        userElement1Id = importBudget.getUserElement1_ID();
    if (userElement1Id <= 0 && importBudget.getUserElement1_ID() <= 0 && importBudget.getUserElementValue1() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserElement1.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            I_AD_Column column = acctSchemaElement.getAD_Column();
            MTable table = (MTable) column.getAD_Table();
            MColumn columnName = table.getColumn("Value");
            if (columnName == null)
                columnName = table.getColumn("Name");
            if (columnName != null)
                importBudget.setUserElement1_ID(getId(table.getTableName(), columnName.getColumnName() + "=?", trxName, importBudget.getUserElementValue1()));
        });
    }
    if (importBudget.getUserElement1_ID() <= 0 && importBudget.getUserElementValue1() != null)
        stringError.append("@UserElement1_ID@ @NotFound@ ");
    Integer userElement2Id = 0;
    if (importBudget.getUserElement2_ID() > 0)
        userElement2Id = importBudget.getUserElement2_ID();
    if (userElement2Id <= 0 && importBudget.getUserElement2_ID() <= 0 && importBudget.getUserElementValue2() != null) {
        Arrays.stream(acctSchemaElements).filter(acctSchemaElement -> MAcctSchemaElement.ELEMENTTYPE_UserElement2.equals(acctSchemaElement.getElementType())).forEach(acctSchemaElement -> {
            I_AD_Column column = acctSchemaElement.getAD_Column();
            MTable table = (MTable) column.getAD_Table();
            MColumn columnName = table.getColumn("Value");
            if (columnName == null)
                columnName = table.getColumn("Name");
            if (columnName != null)
                importBudget.setUserElement2_ID(getId(table.getTableName(), columnName.getColumnName() + "=?", trxName, importBudget.getUserElementValue2()));
        });
    }
    if (importBudget.getUserElement2_ID() <= 0 && importBudget.getUserElementValue2() != null)
        stringError.append("@UserElement2_ID@ @NotFound@ ");
    if (accountSchemaId <= 0)
        stringError.append("@C_AcctSchema_ID@ @NotFound@ ");
    if (budgetId <= 0)
        stringError.append("@GL_Budget_ID@ @NotFound@ ");
    if (accountId <= 0)
        stringError.append("@Account_ID@ @NotFound@ ");
    if (!stringError.toString().isEmpty() && stringError.toString().length() > 0) {
        importBudget.setI_ErrorMsg(Msg.parseTranslation(getCtx(), stringError.toString()));
        importBudget.saveEx();
    }
    importBudget.saveEx();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) Arrays(java.util.Arrays) MProject(org.compiere.model.MProject) X_I_Budget(org.compiere.model.X_I_Budget) CLogger(org.compiere.util.CLogger) MJournalLine(org.compiere.model.MJournalLine) MJournalBatch(org.compiere.model.MJournalBatch) Env(org.compiere.util.Env) SimpleDateFormat(java.text.SimpleDateFormat) X_GL_Budget(org.compiere.model.X_GL_Budget) MCampaign(org.compiere.model.MCampaign) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) MActivity(org.compiere.model.MActivity) MSalesRegion(org.compiere.model.MSalesRegion) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) DB(org.compiere.util.DB) Calendar(java.util.Calendar) MBPartner(org.compiere.model.MBPartner) Msg(org.compiere.util.Msg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MElementValue(org.compiere.model.MElementValue) MPeriod(org.compiere.model.MPeriod) Trx(org.compiere.util.Trx) MJournal(org.compiere.model.MJournal) DateFormat(java.text.DateFormat) Timestamp(java.sql.Timestamp) X_C_SubAcct(org.compiere.model.X_C_SubAcct) Logger(java.util.logging.Logger) MColumn(org.compiere.model.MColumn) Date(java.sql.Date) I_AD_Column(org.compiere.model.I_AD_Column) List(java.util.List) MOrg(org.compiere.model.MOrg) AdempiereException(org.adempiere.exceptions.AdempiereException) X_A_Asset(org.compiere.model.X_A_Asset) MTable(org.compiere.model.MTable) MAccount(org.compiere.model.MAccount) MProduct(org.compiere.model.MProduct) I_I_Budget(org.compiere.model.I_I_Budget) MColumn(org.compiere.model.MColumn) MTable(org.compiere.model.MTable) I_AD_Column(org.compiere.model.I_AD_Column) MBPartner(org.compiere.model.MBPartner)

Example 13 with MTable

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

the class VDocAction method dynInit.

//	jbInit
/**
	 *	Dynamic Init - determine valid DocActions based on DocStatus for the different documents.
	 *  <pre>
	 *  DocStatus (131)
			??                         Unknown
			AP *                       Approved
			CH                         Changed
			CL *                       Closed
			CO *                       Completed
			DR                         Drafted
			IN                         Inactive
			NA                         Not Approved
			PE                         Posting Error
			PO *                       Posted
			PR *                       Printed
			RE                         Reversed
			TE                         Transfer Error
			TR *                       Transferred
			VO *                       Voided
			XX                         Being Processed
	 *
	 *   DocAction (135)
			--                         <None>
			AP *                       Approve
			CL *                       Close
			CO *                       Complete
			PO *                       Post
			PR *                       Print
			RA                         Reverse - Accrual
			RC                         Reverse - Correction
			RE                         RE-activate
			RJ                         Reject
			TR *                       Transfer
			VO *                       Void
			XL                         Unlock
	 *  </pre>
	 * 	@param Record_ID id
	 */
private void dynInit(int Record_ID) {
    String DocStatus = (String) m_mTab.getValue("DocStatus");
    String DocAction = (String) m_mTab.getValue("DocAction");
    //
    Object Processing = m_mTab.getValue("Processing");
    String OrderType = Env.getContext(Env.getCtx(), m_WindowNo, "OrderType");
    String IsSOTrx = Env.getContext(Env.getCtx(), m_WindowNo, "IsSOTrx");
    if (DocStatus == null) {
        message.setText("*** ERROR ***");
        return;
    }
    log.fine("DocStatus=" + DocStatus + ", DocAction=" + DocAction + ", OrderType=" + OrderType + ", IsSOTrx=" + IsSOTrx + ", Processing=" + Processing + ", AD_Table_ID=" + m_AD_Table_ID + ", Record_ID=" + Record_ID);
    //
    String[] options = new String[s_value.length];
    int index = 0;
    /**
		 * 	Check Existence of Workflow Activities
		 */
    String wfStatus = MWFActivity.getActiveInfo(Env.getCtx(), m_AD_Table_ID, Record_ID);
    if (wfStatus != null) {
        ADialog.error(m_WindowNo, this, "WFActiveForRecord", wfStatus);
        return;
    }
    //	Status Change
    if (!checkStatus(m_mTab.getTableName(), Record_ID, DocStatus)) {
        ADialog.error(m_WindowNo, this, "DocumentStatusChanged");
        return;
    }
    /*******************
		 *  General Actions
		 */
    String[] docActionHolder = new String[] { DocAction };
    index = DocumentEngine.getValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options);
    MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
    PO po = table.getPO(Record_ID, null);
    if (po instanceof DocOptions)
        index = ((DocOptions) po).customizeValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options, index);
    Integer doctypeId = (Integer) m_mTab.getValue("C_DocType_ID");
    if (doctypeId == null || doctypeId.intValue() == 0) {
        doctypeId = (Integer) m_mTab.getValue("C_DocTypeTarget_ID");
    }
    log.fine("get doctype: " + doctypeId);
    if (doctypeId != null) {
        index = DocumentEngine.checkActionAccess(Env.getAD_Client_ID(Env.getCtx()), Env.getAD_Role_ID(Env.getCtx()), doctypeId, options, index);
    }
    DocAction = docActionHolder[0];
    /**
		 *	Fill actionCombo
		 */
    for (int i = 0; i < index; i++) {
        //	Search for option and add it
        boolean added = false;
        for (int j = 0; j < s_value.length && !added; j++) if (options[i].equals(s_value[j])) {
            actionCombo.addItem(s_name[j]);
            added = true;
        }
    }
    //	setDefault
    if (//	If None, suggest closing
    DocAction.equals("--"))
        DocAction = DocumentEngine.ACTION_Close;
    String defaultV = "";
    for (int i = 0; i < s_value.length && defaultV.equals(""); i++) if (DocAction.equals(s_value[i]))
        defaultV = s_name[i];
    if (!defaultV.equals(""))
        actionCombo.setSelectedItem(defaultV);
}
Also used : MTable(org.compiere.model.MTable) DocOptions(org.compiere.process.DocOptions) PO(org.compiere.model.PO)

Example 14 with MTable

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

the class Generator method generateExternalTables.

private void generateExternalTables(Properties ctx, HttpServletRequest httpRequest) {
    HttpSession thisSession = httpRequest.getSession(false);
    WebInfo wi = null;
    if (thisSession != null)
        if (thisSession.getAttribute(WebInfo.NAME) != null)
            wi = (WebInfo) thisSession.getAttribute(WebInfo.NAME);
    int[] tableKeys = X_CM_TemplateTable.getAllIDs("CM_TemplateTable", "CM_Template_ID=" + thisRequest.getCM_Container().getCM_Template_ID(), "WebCM");
    if (tableKeys.length > 0) {
        xmlCode.append("<externalTables>\n");
        for (int i = 0; i < tableKeys.length; i++) {
            X_CM_TemplateTable thisTemplateTable = new X_CM_TemplateTable(ctx, tableKeys[i], "WebCM");
            try {
                StringBuffer tempXML = new StringBuffer();
                tempXML.append("<" + thisTemplateTable.getName() + ">\n");
                MTable table = MTable.get(ctx, thisTemplateTable.getAD_Table_ID());
                String trxName = null;
                int[] ids = PO.getAllIDs(table.getTableName(), replaceSessionElements(wi, thisTemplateTable.getWhereClause()), trxName);
                if (ids != null && ids.length > 0) {
                    for (int j = 0; j < ids.length; j++) {
                        PO po = null;
                        po = table.getPO(ids[j], null);
                        if (po != null) {
                            tempXML = po.get_xmlString(tempXML);
                        }
                    }
                }
                tempXML.append("\n</" + thisTemplateTable.getName() + ">\n");
                xmlCode.append(tempXML);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        xmlCode.append("\n</externalTables>\n");
    }
}
Also used : MTable(org.compiere.model.MTable) HttpSession(javax.servlet.http.HttpSession) WebInfo(org.compiere.util.WebInfo) SQLException(java.sql.SQLException) X_CM_TemplateTable(org.compiere.model.X_CM_TemplateTable) PO(org.compiere.model.PO)

Example 15 with MTable

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

the class CalloutParameter method element.

/**
	 * Set the default values from Element
	 * 
	 * @param ctx
	 * @param WindowNo
	 * @param mTab
	 * @param mField
	 * @param value
	 * @return
	 */
public String element(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    Integer AD_Element_ID = (Integer) value;
    if (AD_Element_ID == null || AD_Element_ID <= 0)
        return "";
    I_AD_Process_Para para = GridTabWrapper.create(mTab, I_AD_Process_Para.class);
    MTable table = MTable.get(ctx, para.Table_ID);
    MProcess process = MProcess.get(ctx, para.getAD_Process_ID());
    para.setEntityType(process.getEntityType());
    M_Element element = new M_Element(ctx, AD_Element_ID, null);
    if (element.getAD_Reference_ID() == DisplayType.ID) {
        String columnName = table.get_TableName() + "_ID";
        if (!columnName.equals(element.getColumnName())) {
            para.setAD_Reference_ID(DisplayType.TableDir);
        }
    }
    if (para.getColumnName() == null || para.getColumnName().length() <= 0)
        para.setColumnName(element.getColumnName());
    if (para.getFieldLength() <= 0)
        para.setFieldLength(element.getFieldLength());
    if (para.getAD_Reference_ID() <= 0)
        para.setAD_Reference_ID(element.getAD_Reference_ID());
    if (para.getAD_Reference_Value_ID() <= 0)
        para.setAD_Reference_Value_ID(element.getAD_Reference_Value_ID());
    if (para.getName() == null || para.getName().length() <= 0)
        para.setName(element.getName());
    if (para.getDescription() == null || para.getDescription().length() <= 0)
        para.setDescription(element.getDescription());
    if (para.getHelp() == null || para.getHelp().length() <= 0)
        para.setHelp(element.getHelp());
    return "";
}
Also used : MProcess(org.compiere.model.MProcess) MTable(org.compiere.model.MTable) I_AD_Process_Para(org.compiere.model.I_AD_Process_Para) M_Element(org.compiere.model.M_Element)

Aggregations

MTable (org.compiere.model.MTable)67 PO (org.compiere.model.PO)18 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 PreparedStatement (java.sql.PreparedStatement)15 MColumn (org.compiere.model.MColumn)15 Query (org.compiere.model.Query)13 ArrayList (java.util.ArrayList)10 Properties (java.util.Properties)9 AdempiereException (org.adempiere.exceptions.AdempiereException)7 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)7 XFireFault (org.codehaus.xfire.fault.XFireFault)5 POInfo (org.compiere.model.POInfo)5 Trx (org.compiere.util.Trx)5 DataField (pl.x3E.adInterface.DataField)5 DataRow (pl.x3E.adInterface.DataRow)5 ModelCRUD (pl.x3E.adInterface.ModelCRUD)5 List (java.util.List)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)4