FR 2619262 - Adjusted coding style.
This commit is contained in:
parent
deb02c1053
commit
7f9931cd55
|
@ -32,6 +32,7 @@ import java.util.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
import org.compiere.model.*;
|
import org.compiere.model.*;
|
||||||
import org.compiere.process.*;
|
import org.compiere.process.*;
|
||||||
|
import org.compiere.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates expense type products from a given range of expense account
|
* Creates expense type products from a given range of expense account
|
||||||
|
@ -106,13 +107,10 @@ public class ExpenseTypesFromAccounts extends SvrProcess {
|
||||||
MProduct product;
|
MProduct product;
|
||||||
|
|
||||||
// Read all existing applicable products into memory for quick comparison.
|
// Read all existing applicable products into memory for quick comparison.
|
||||||
Query q1 = new Query(
|
List<MProduct> products = new Query(getCtx(), MProduct.Table_Name, "ProductType=?", get_TrxName())
|
||||||
getCtx(),
|
.setParameters(new Object[]{MProduct.PRODUCTTYPE_ExpenseType})
|
||||||
MProduct.Table_Name,
|
.list();
|
||||||
"ProductType=?",
|
|
||||||
get_TrxName());
|
|
||||||
q1.setParameters(new Object[]{MProduct.PRODUCTTYPE_ExpenseType});
|
|
||||||
List<MProduct> products = q1.list();
|
|
||||||
Map<String,MProduct> productMap = new TreeMap<String, MProduct>();
|
Map<String,MProduct> productMap = new TreeMap<String, MProduct>();
|
||||||
for (Iterator<MProduct> it = products.iterator(); it.hasNext();) {
|
for (Iterator<MProduct> it = products.iterator(); it.hasNext();) {
|
||||||
product = it.next();
|
product = it.next();
|
||||||
|
@ -121,9 +119,14 @@ public class ExpenseTypesFromAccounts extends SvrProcess {
|
||||||
|
|
||||||
// Read all existing valid combinations comparison
|
// Read all existing valid combinations comparison
|
||||||
MAccount validComb;
|
MAccount validComb;
|
||||||
q1 = new Query(getCtx(), MAccount.Table_Name, "C_AcctSchema_ID=? and AD_Client_ID=? and AD_Org_ID=0", get_TrxName());
|
List<MAccount> validCombs = new Query(
|
||||||
q1.setParameters(new Object[]{m_acctSchemaId, m_clientId});
|
getCtx(),
|
||||||
List<MAccount> validCombs = q1.list();
|
MAccount.Table_Name,
|
||||||
|
"C_AcctSchema_ID=? and AD_Client_ID=? and AD_Org_ID=0",
|
||||||
|
get_TrxName())
|
||||||
|
.setParameters(new Object[]{m_acctSchemaId, m_clientId})
|
||||||
|
.list();
|
||||||
|
|
||||||
Map<Integer, MAccount> validCombMap = new TreeMap<Integer, MAccount>();
|
Map<Integer, MAccount> validCombMap = new TreeMap<Integer, MAccount>();
|
||||||
for (Iterator<MAccount> it = validCombs.iterator(); it.hasNext();) {
|
for (Iterator<MAccount> it = validCombs.iterator(); it.hasNext();) {
|
||||||
validComb = it.next();
|
validComb = it.next();
|
||||||
|
@ -131,19 +134,19 @@ public class ExpenseTypesFromAccounts extends SvrProcess {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all accounttypes that fit the given criteria.
|
// Read all accounttypes that fit the given criteria.
|
||||||
Query q2 = new Query(
|
List<MElementValue> result = new Query(
|
||||||
getCtx(),
|
getCtx(),
|
||||||
MElementValue.Table_Name,
|
MElementValue.Table_Name,
|
||||||
"AccountType=? and isSummary='N' and Value>=? and Value<=? and AD_Client_ID=?",
|
"AccountType=? and isSummary='N' and Value>=? and Value<=? and AD_Client_ID=?",
|
||||||
get_TrxName());
|
get_TrxName())
|
||||||
q2.setParameters(new Object[]{MElementValue.ACCOUNTTYPE_Expense, m_startElement, m_endElement, m_clientId});
|
.setParameters(new Object[]{MElementValue.ACCOUNTTYPE_Expense, m_startElement, m_endElement, m_clientId})
|
||||||
List<MElementValue> result = q2.list();
|
.list();
|
||||||
|
|
||||||
MElementValue elem;
|
MElementValue elem;
|
||||||
MProductPrice priceRec;
|
MProductPrice priceRec;
|
||||||
X_M_Product_Acct productAcct;
|
X_M_Product_Acct productAcct;
|
||||||
String expenseItemValue;
|
String expenseItemValue;
|
||||||
BigDecimal zero = new BigDecimal("0");
|
BigDecimal zero = Env.ZERO;
|
||||||
int addCount = 0;
|
int addCount = 0;
|
||||||
int skipCount = 0;
|
int skipCount = 0;
|
||||||
|
|
||||||
|
@ -155,7 +158,7 @@ public class ExpenseTypesFromAccounts extends SvrProcess {
|
||||||
if (product==null) {
|
if (product==null) {
|
||||||
// Create a new product from the account element
|
// Create a new product from the account element
|
||||||
product = new MProduct(getCtx(), 0, get_TrxName());
|
product = new MProduct(getCtx(), 0, get_TrxName());
|
||||||
product.set_ValueOfColumn("AD_Client_ID", new Integer(m_clientId));
|
product.set_ValueOfColumn("AD_Client_ID", Integer.valueOf(m_clientId));
|
||||||
product.setValue(expenseItemValue);
|
product.setValue(expenseItemValue);
|
||||||
product.setName(elem.getName());
|
product.setName(elem.getName());
|
||||||
product.setDescription(elem.getDescription());
|
product.setDescription(elem.getDescription());
|
||||||
|
@ -168,13 +171,13 @@ public class ExpenseTypesFromAccounts extends SvrProcess {
|
||||||
product.setIsPurchased(true);
|
product.setIsPurchased(true);
|
||||||
product.setIsSold(false);
|
product.setIsSold(false);
|
||||||
// Save the product
|
// Save the product
|
||||||
product.save(get_TrxName());
|
product.saveEx(get_TrxName());
|
||||||
|
|
||||||
// Add a zero product price to the price list so it shows up in the price list
|
// Add a zero product price to the price list so it shows up in the price list
|
||||||
priceRec = new MProductPrice(getCtx(), pv.get_ID(), product.get_ID(), get_TrxName());
|
priceRec = new MProductPrice(getCtx(), pv.get_ID(), product.get_ID(), get_TrxName());
|
||||||
priceRec.set_ValueOfColumn("AD_Client_ID", new Integer(m_clientId));
|
priceRec.set_ValueOfColumn("AD_Client_ID", Integer.valueOf(m_clientId));
|
||||||
priceRec.setPrices(zero, zero, zero);
|
priceRec.setPrices(zero, zero, zero);
|
||||||
priceRec.save();
|
priceRec.saveEx(get_TrxName());
|
||||||
|
|
||||||
// Set the revenue and expense accounting of the product to the given account element
|
// Set the revenue and expense accounting of the product to the given account element
|
||||||
// Get the valid combination
|
// Get the valid combination
|
||||||
|
@ -182,20 +185,22 @@ public class ExpenseTypesFromAccounts extends SvrProcess {
|
||||||
if (validComb==null) {
|
if (validComb==null) {
|
||||||
// Create new valid combination
|
// Create new valid combination
|
||||||
validComb = new MAccount(getCtx(), 0, get_TrxName());
|
validComb = new MAccount(getCtx(), 0, get_TrxName());
|
||||||
validComb.set_ValueOfColumn("AD_Client_ID", new Integer(m_clientId));
|
validComb.set_ValueOfColumn("AD_Client_ID", Integer.valueOf(m_clientId));
|
||||||
validComb.setAD_Org_ID(0);
|
validComb.setAD_Org_ID(0);
|
||||||
validComb.setAlias(elem.getValue());
|
validComb.setAlias(elem.getValue());
|
||||||
validComb.setAccount_ID(elem.get_ID());
|
validComb.setAccount_ID(elem.get_ID());
|
||||||
validComb.setC_AcctSchema_ID(m_acctSchemaId);
|
validComb.setC_AcctSchema_ID(m_acctSchemaId);
|
||||||
validComb.save(get_TrxName());
|
validComb.saveEx(get_TrxName());
|
||||||
}
|
}
|
||||||
|
|
||||||
q1 = new Query(getCtx(), X_M_Product_Acct.Table_Name, "M_Product_ID=?", get_TrxName());
|
// TODO: It might be needed to make the accounting more specific, but the purpose
|
||||||
q1.setParameters(new Object[]{product.get_ID()});
|
// of the process now is to create general accounts so this is intentional.
|
||||||
productAcct = q1.first();
|
productAcct = new Query(getCtx(), X_M_Product_Acct.Table_Name, "M_Product_ID=?", get_TrxName())
|
||||||
|
.setParameters(new Object[]{product.get_ID()})
|
||||||
|
.first();
|
||||||
productAcct.setP_Expense_Acct(validComb.get_ID());
|
productAcct.setP_Expense_Acct(validComb.get_ID());
|
||||||
productAcct.setP_Revenue_Acct(validComb.get_ID());
|
productAcct.setP_Revenue_Acct(validComb.get_ID());
|
||||||
productAcct.save(get_TrxName());
|
productAcct.saveEx(get_TrxName());
|
||||||
|
|
||||||
addCount++;
|
addCount++;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue