* @param workDialog Description of the Parameter
*/
private void UpgradeAccounts(WorkingDialog workDialog) {
//convert all the accounts IsAsset field to show more asset/debt/income/expense
try {
DataConnection dc = new DataConnection(null);
if (dc == null || !dc.bIsConnectionMade) {
return;
}
Statement st = dc.con.createStatement();
ResultSet rsAccounts = st.executeQuery(dc.filterSQL(
"SELECT APP.Account.Account FROM APP.Account WHERE " +
"(IsAsset=0 AND (APP.Account.Account<3000 OR APP.Account.Account>=10000)) " +
"OR (IsAsset=1 AND (APP.Account.Account<1000 OR APP.Account.Account>=3000)) "));
int numEuBasErrors = 0;
if (rsAccounts.next()) {
rsAccounts.last();
numEuBasErrors = rsAccounts.getRow();
}
st = dc.con.createStatement();
rsAccounts = st.executeQuery(dc.filterSQL(
"SELECT CompId,APP.Account.Account,AccDesc,IsAsset FROM APP.Account"));
int numRows = 0;
if (rsAccounts.next()) {
rsAccounts.last();
numRows = rsAccounts.getRow();
rsAccounts.beforeFirst();
}
if (numRows > 0) {
int ACCOUNT_TYPE_ASSET = 0;
int ACCOUNT_TYPE_DEBT = 1;
int ACCOUNT_TYPE_INCOME = 2;
int ACCOUNT_TYPE_EXPENSE = 3;
boolean isEuBasAccounting = true;
if ((numEuBasErrors * 100 / numRows) > 10) {
//more then 10% errors
isEuBasAccounting = false;
}
//attempt to see if this is a EU BAS 2000 account. system
rsAccounts.beforeFirst();
while (rsAccounts.next()) {
//sum up account
workDialog.SetProgress(100 * rsAccounts.getRow() / numRows);
int oldIsAsset = rsAccounts.getInt(4);
int defaultIsAsset = 0;
int AccountNum = rsAccounts.getInt(2);
if (isEuBasAccounting) {
//assume this is the EU bas 2000 accounting system
//these numbers are hard coded now because at this point, the AccountType
//table does not exist.
if (AccountNum < 2000) {
defaultIsAsset = ACCOUNT_TYPE_ASSET;
} else if (AccountNum >= 2000 && AccountNum < 3000) {
defaultIsAsset = ACCOUNT_TYPE_DEBT;
} else if ((AccountNum >= 3000 && AccountNum < 4000)
|| (AccountNum >= 8000 && AccountNum < 8400)
|| (AccountNum >= 8700 && AccountNum < 8750)
|| (AccountNum >= 8800 && AccountNum < 8900)
|| (AccountNum >= 8990 && AccountNum < 9000)) {
defaultIsAsset = ACCOUNT_TYPE_INCOME;
} else if ((AccountNum >= 4000 && AccountNum < 8000)
|| (AccountNum >= 8400 && AccountNum < 8700)
|| (AccountNum >= 8750 && AccountNum < 8800)
|| (AccountNum >= 8900 && AccountNum < 8990)) {
defaultIsAsset = ACCOUNT_TYPE_EXPENSE;
} else {
if (oldIsAsset == 0) {
defaultIsAsset = ACCOUNT_TYPE_INCOME;
} else {
defaultIsAsset = ACCOUNT_TYPE_ASSET;
}
}
} else {
Statement st2 = dc.con.createStatement();
ResultSet rsSumAccounts = st2.executeQuery(dc.filterSQL(
"SELECT Sum(Amount.Amount * ((2 * Amount.IsDebit) - 1) ) AS SumOfAmount1 " +
"FROM Amount WHERE CompId=" + rsAccounts.getInt(1)
+ " AND Amount.Account=" + AccountNum));
if (oldIsAsset == 0) {
defaultIsAsset = ACCOUNT_TYPE_INCOME;
} else {
defaultIsAsset = ACCOUNT_TYPE_ASSET;
}
if (rsSumAccounts.next()) {
double amount = rsSumAccounts.getDouble(1);
if (oldIsAsset == 0) {
if (amount >= 0) {
defaultIsAsset = ACCOUNT_TYPE_EXPENSE;
} else {
defaultIsAsset = ACCOUNT_TYPE_INCOME;
}
} else {
if (amount >= 0) {
defaultIsAsset = ACCOUNT_TYPE_ASSET;
} else {
defaultIsAsset = ACCOUNT_TYPE_DEBT;
}
}
}
}
Statement st3 = dc.con.createStatement();
st3.executeUpdate(dc.filterSQL(
"UPDATE APP.Account SET IsAsset=" + defaultIsAsset + " WHERE CompId="
+ rsAccounts.getInt(1) + " AND APP.Account.Account=" + AccountNum));
}
}
} catch (Exception eee) {