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);
}
}
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);
}
}
}
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@";
}
Aggregations