Search in sources :

Example 16 with MAcctSchemaElement

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

the class AcctViewer method actionAcctSchema.

//  actionPerformed
/**
	 * 	New Acct Schema
	 */
private void actionAcctSchema() {
    KeyNamePair kp = (KeyNamePair) selAcctSchema.getSelectedItem();
    if (kp == null)
        return;
    m_data.C_AcctSchema_ID = kp.getKey();
    m_data.ASchema = MAcctSchema.get(Env.getCtx(), m_data.C_AcctSchema_ID);
    log.info(m_data.ASchema.toString());
    //
    //  Sort Options
    sortBy1.removeAllItems();
    sortBy2.removeAllItems();
    sortBy3.removeAllItems();
    sortBy4.removeAllItems();
    sortAddItem(new ValueNamePair("", ""));
    sortAddItem(new ValueNamePair("DateAcct", Msg.translate(Env.getCtx(), "DateAcct")));
    sortAddItem(new ValueNamePair("DateTrx", Msg.translate(Env.getCtx(), "DateTrx")));
    sortAddItem(new ValueNamePair("C_Period_ID", Msg.translate(Env.getCtx(), "C_Period_ID")));
    //
    CLabel[] labels = new CLabel[] { lsel1, lsel2, lsel3, lsel4, lsel5, lsel6, lsel7, lsel8 };
    CButton[] buttons = new CButton[] { sel1, sel2, sel3, sel4, sel5, sel6, sel7, sel8 };
    int selectionIndex = 0;
    MAcctSchemaElement[] elements = m_data.ASchema.getAcctSchemaElements();
    for (int i = 0; i < elements.length && selectionIndex < labels.length; i++) {
        MAcctSchemaElement acctSchemaElement = elements[i];
        String columnName = acctSchemaElement.getColumnName();
        String displayColumnName = acctSchemaElement.getDisplayColumnName();
        if (columnName.equals("User1_ID") || columnName.equals("User2_ID") || columnName.equals("User3_ID") || columnName.equals("User4_ID"))
            displayColumnName = acctSchemaElement.getName();
        else
            displayColumnName = acctSchemaElement.getDisplayColumnName();
        //  Add Sort Option
        sortAddItem(new ValueNamePair(columnName, Msg.translate(Env.getCtx(), displayColumnName)));
        //  Additional Elements
        if (!acctSchemaElement.isElementType(X_C_AcctSchema_Element.ELEMENTTYPE_Organization) && !acctSchemaElement.isElementType(X_C_AcctSchema_Element.ELEMENTTYPE_Account)) {
            labels[selectionIndex].setText(Msg.translate(Env.getCtx(), displayColumnName));
            labels[selectionIndex].setVisible(true);
            buttons[selectionIndex].setActionCommand(columnName);
            buttons[selectionIndex].addActionListener(this);
            buttons[selectionIndex].setIcon(m_iFind);
            buttons[selectionIndex].setText("");
            buttons[selectionIndex].setVisible(true);
            selectionIndex++;
        }
    }
    //	don't show remaining
    while (selectionIndex < labels.length) {
        labels[selectionIndex].setVisible(false);
        buttons[selectionIndex++].setVisible(false);
    }
}
Also used : CLabel(org.compiere.swing.CLabel) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair) CButton(org.compiere.swing.CButton) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 17 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)

Example 18 with MAcctSchemaElement

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

the class ImportBudget method doIt.

/**
     * Perform process.
     * @return Message
     * @throws Exception
     */
protected String doIt() throws Exception {
    // Validate Budget
    X_I_Budget importBudgetCurrent = new X_I_Budget(getCtx(), getRecord_ID(), null);
    int budgetId = importBudgetCurrent.getGL_Budget_ID();
    if (budgetId <= 0)
        budgetId = getId(X_GL_Budget.Table_Name, X_GL_Budget.COLUMNNAME_Name + "=?", get_TrxName(), importBudgetCurrent.getBudgetCode());
    if (budgetId <= 0)
        throw new AdempiereException("@GL_Budget_ID@ @NotFound@");
    else {
        importBudgetCurrent.setGL_Budget_ID(budgetId);
        importBudgetCurrent.saveEx();
    }
    MAcctSchema acctSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
    MAcctSchemaElement[] acctSchemaElements = MAcctSchemaElement.getAcctSchemaElements(acctSchema);
    MPeriod period = MPeriod.get(getCtx(), acctSchema.getC_Period_ID());
    int glCategoryId = DB.getSQLValue(get_TrxName(), "SELECT GL_Category_ID FROM GL_Category WHERE Name = 'Manual'  AND AD_Client_ID =? ", Env.getAD_Client_ID(getCtx()));
    int currencyId = acctSchema.getC_Currency_ID();
    int docTypeId = DB.getSQLValue(get_TrxName(), "SELECT C_DocType_ID FROM C_DocType WHERE Name = 'GL Journal' AND AD_Client_ID =?", Env.getAD_Client_ID(getCtx()));
    int conversionTypeId = DB.getSQLValue(get_TrxName(), "SELECT C_ConversionType_ID FROM C_ConversionType WHERE Value =? ", "S");
    String documentNo = importBudgetCurrent.getBatchDocumentNo();
    int calendarId = period.getC_Calendar_ID();
    if (isDeleteoldimportedrecords())
        Arrays.stream(getBudget(documentNo, true, true)).forEach(importBudgetId -> {
            X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, null);
            importBudget.deleteEx(true);
        });
    //Validation document
    int[] budgetLinesIds = getBudget(documentNo, false, false);
    validateBudget(budgetLinesIds);
    //AtomicInteger importedRecord = new AtomicInteger(0);
    //AtomicInteger withErrors = new AtomicInteger(0);
    Arrays.stream(budgetLinesIds).forEach(importBudgetId -> {
        Trx.run(trxName -> {
            X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, trxName);
            importBudget.setI_ErrorMsg(null);
            fillIdValues(importBudget, acctSchemaElements, trxName);
        });
    });
    // Validate  have not Error
    Arrays.stream(budgetLinesIds).forEach(importBudgetId -> {
        X_I_Budget importBudget = new X_I_Budget(getCtx(), importBudgetId, null);
        if (importBudget.getI_ErrorMsg() != null)
            throw new AdempiereException("@GL_BudgetID@ @ProcessFailed@");
    });
    Trx.run(trxName -> generateJournalBatch(trxName, documentNo, glCategoryId, docTypeId, currencyId, conversionTypeId, calendarId, importBudgetCurrent.getGL_Budget_ID()));
    return "@Ok@";
}
Also used : 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) MAcctSchema(org.compiere.model.MAcctSchema) AdempiereException(org.adempiere.exceptions.AdempiereException) MPeriod(org.compiere.model.MPeriod) X_I_Budget(org.compiere.model.X_I_Budget) 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