// retrieve vat endorse account code...
HashMap params = new HashMap();
params.put(ApplicationConsts.COMPANY_CODE_SYS01,companyCode);
params.put(ApplicationConsts.PARAM_CODE,ApplicationConsts.VAT_ENDORSE_ACCOUNT);
Response res = userParamAction.loadUserParam(params,serverLanguageId,username);
if (res.isError()) {
throw new Exception(res.getErrorMessage());
}
String vatEndorseAccountCode = ((VOResponse)res).getVo().toString();
SimpleDateFormat sdf = new SimpleDateFormat(t1);
// for each vat register: create an accounting item to endorse vat amount from the register to th tresury...
Enumeration en = lastRecordNumbers.keys();
sql =
"select VAT_VALUE,RECORD_NUMBER from ACC07_VAT_ROWS where COMPANY_CODE_SYS01=? and REGISTER_CODE_ACC04=? and "+
"RECORD_NUMBER>? and VAT_DATE<=?";
pstmt = conn.prepareStatement(sql);
BigDecimal amount = null;
BigDecimal newLastRN = null;
JournalHeaderVO jhVO = null;
JournalRowVO jrVO = null;
String accountCode = null;
sql = "update ACC04_VAT_REGISTERS set LAST_RECORD_NUMBER=?,LAST_VAT_DATE=?,LAST_UPDATE_USER=?,LAST_UPDATE_DATE=? where COMPANY_CODE_SYS01=? and REGISTER_CODE=? and (LAST_RECORD_NUMBER=? || LAST_RECORD_NUMBER is null)";
pstmt2 = conn.prepareStatement(sql);
while(en.hasMoreElements()) {
// retrieve total vat amount for the specified vat register...
amount = new BigDecimal(0);
regCode = en.nextElement().toString();
lastRN = (BigDecimal)lastRecordNumbers.get(regCode);
lastVD = (java.sql.Date)lastVatDates.get(regCode);
accountCode = (String)accountCodes.get(regCode);
pstmt.setString(1,companyCode);
pstmt.setString(2,regCode);
pstmt.setBigDecimal(3,lastRN);
pstmt.setDate(4,new java.sql.Date(toDate.getTime()));
rset = pstmt.executeQuery();
while(rset.next()) {
amount = amount.add(rset.getBigDecimal(1));
newLastRN = rset.getBigDecimal(2);
}
rset.close();
if (amount.doubleValue()!=0) {
lastVD.setTime(lastVD.getTime()+86400*1000);
// create the accounting item...
jhVO = new JournalHeaderVO();
jhVO.setCompanyCodeSys01ACC05(companyCode);
jhVO.setAccountingMotiveCodeAcc03ACC05(ApplicationConsts.MOTIVE_VAT_ENDORSING);
jhVO.setDescriptionACC05(
t2+" "+
regCode+" "+
t3+" "+sdf.format(lastVD)+" - "+sdf.format(toDate)
);
jhVO.setItemDateACC05(new java.sql.Date(System.currentTimeMillis()));
jhVO.setItemYearACC05(new BigDecimal(Calendar.getInstance().get(Calendar.YEAR)));
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
jrVO.setAccountCodeAcc02ACC06(accountCode);
jrVO.setAccountCodeACC06(accountCode);
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_ACCOUNT);
jrVO.setDebitAmountACC06(amount);
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setProgressiveAcc05ACC06(jhVO.getProgressiveACC05());
jhVO.addJournalRow(jrVO);
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
jrVO.setAccountCodeAcc02ACC06(vatEndorseAccountCode);
jrVO.setAccountCodeACC06(vatEndorseAccountCode);
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_ACCOUNT);
jrVO.setCreditAmountACC06(amount);
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setProgressiveAcc05ACC06(jhVO.getProgressiveACC05());
jhVO.addJournalRow(jrVO);
res = bean.insertJournalItem(jhVO,serverLanguageId,username);
if (res.isError()) {
throw new Exception(res.getErrorMessage());
}
// update last record number in the current vat register...
pstmt2.setBigDecimal(1,newLastRN);
pstmt2.setDate(2,new java.sql.Date(toDate.getTime()));
pstmt2.setString(3,username);
pstmt2.setTimestamp(4,new java.sql.Timestamp(System.currentTimeMillis()));
pstmt2.setString(5,companyCode);
pstmt2.setString(6,regCode);
pstmt2.setBigDecimal(7,lastRN);
int upd = pstmt2.executeUpdate();
if (upd==0) {
return new VOResponse("Updating not performed: the record was previously updated.");
}
}
}
Response answer = new VOResponse(Boolean.TRUE);
if (answer.isError()) throw new Exception(answer.getErrorMessage()); else return (VOResponse)answer;
}
catch (Throwable ex) {
Logger.error(username,this.getClass().getName(),"executeCommand","Error while endorsing vat",ex);
try {
if (this.conn==null && conn!=null)