}
// add taxable income rows to the accounting item...
java.util.List taxableIncomes = ((VOListResponse)res).getRows();
TaxableIncomeVO tVO = null;
JournalRowVO jrVO = null;
BigDecimal totalVat = new BigDecimal(0);
Hashtable vats = new Hashtable(); // collections of: vat code,VatRowVO
VatRowVO vatVO = null;
for(int i=0;i<taxableIncomes.size();i++) {
tVO = (TaxableIncomeVO)taxableIncomes.get(i);
totalVat = totalVat.add(tVO.getVatValue());
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
if (tVO.getRowType()==tVO.ITEM_ROW_TYPE) {
jrVO.setAccountCodeAcc02ACC06(itemsAccountCodeAcc02);
jrVO.setAccountCodeACC06(itemsAccountCodeAcc02);
}
else if (tVO.getRowType()==tVO.ACTIVITY_ROW_TYPE) {
jrVO.setAccountCodeAcc02ACC06(actAccountCodeAcc02);
jrVO.setAccountCodeACC06(actAccountCodeAcc02);
}
else if (tVO.getRowType()==tVO.CHARGE_ROW_TYPE) {
jrVO.setAccountCodeAcc02ACC06(chargesAccountCodeAcc02);
jrVO.setAccountCodeACC06(chargesAccountCodeAcc02);
}
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_ACCOUNT);
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
jrVO.setCreditAmountACC06(tVO.getTaxableIncome().negate());
else
jrVO.setCreditAmountACC06(tVO.getTaxableIncome());
jrVO.setCreditAmountACC06(CurrencyConversionUtils.convertCurrencyToCurrency(jrVO.getCreditAmountACC06(),conv));
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setProgressiveAcc05ACC06(jhVO.getProgressiveACC05());
jhVO.addJournalRow(jrVO);
// prepare vat row for sale vat register...
vatVO = (VatRowVO)vats.get(tVO.getVatCode());
if (vatVO==null) {
vatVO = new VatRowVO();
vatVO.setCompanyCodeSys01ACC07(docVO.getCompanyCodeSys01DOC01());
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_DESK_DOC_TYPE))
vatVO.setRegisterCodeAcc04ACC07(ApplicationConsts.VAT_REGISTER_RETAIL);
else
vatVO.setRegisterCodeAcc04ACC07(ApplicationConsts.VAT_REGISTER_SELLING);
vatVO.setTaxableIncomeACC07(tVO.getTaxableIncome());
vatVO.setTaxableIncomeACC07(CurrencyConversionUtils.convertCurrencyToCurrency(vatVO.getTaxableIncomeACC07(),conv));
vatVO.setVatCodeACC07(tVO.getVatCode());
vatVO.setVatDateACC07(new java.sql.Date(System.currentTimeMillis()));
vatVO.setVatDescriptionACC07(tVO.getVatDescription());
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
vatVO.setVatValueACC07(tVO.getVatValue().negate());
else
vatVO.setVatValueACC07(tVO.getVatValue());
vatVO.setVatValueACC07(CurrencyConversionUtils.convertCurrencyToCurrency(vatVO.getVatValueACC07(),conv));
vatVO.setVatYearACC07(new BigDecimal(Calendar.getInstance().get(Calendar.YEAR)));
}
else {
vatVO.setTaxableIncomeACC07(vatVO.getTaxableIncomeACC07().add(tVO.getTaxableIncome()));
vatVO.setTaxableIncomeACC07(CurrencyConversionUtils.convertCurrencyToCurrency(vatVO.getTaxableIncomeACC07(),conv));
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
vatVO.setVatValueACC07(vatVO.getVatValueACC07().add(tVO.getVatValue()).negate());
else
vatVO.setVatValueACC07(vatVO.getVatValueACC07().add(tVO.getVatValue()));
vatVO.setVatValueACC07(CurrencyConversionUtils.convertCurrencyToCurrency(vatVO.getVatValueACC07(),conv));
}
vats.put(tVO.getVatCode(),vatVO);
}
// add total vat value to the accounting item...
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
jrVO.setAccountCodeAcc02ACC06(vatAccountCodeAcc02);
jrVO.setAccountCodeACC06(vatAccountCodeAcc02);
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_ACCOUNT);
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
jrVO.setCreditAmountACC06(totalVat.negate());
else
jrVO.setCreditAmountACC06(totalVat);
jrVO.setCreditAmountACC06(CurrencyConversionUtils.convertCurrencyToCurrency(jrVO.getCreditAmountACC06(),conv));
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setProgressiveAcc05ACC06(jhVO.getProgressiveACC05());
jhVO.addJournalRow(jrVO);
// add total credit value to the accounting item...
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
jrVO.setAccountCodeAcc02ACC06(creditAccountCodeAcc02);
jrVO.setAccountCodeACC06(docVO.getCustomerCodeSAL07());
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_CUSTOMER);
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
jrVO.setDebitAmountACC06(docVO.getTotalDOC01().negate());
else
jrVO.setDebitAmountACC06(docVO.getTotalDOC01());
jrVO.setDebitAmountACC06(CurrencyConversionUtils.convertCurrencyToCurrency(jrVO.getDebitAmountACC06(),conv));
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setProgressiveAcc05ACC06(jhVO.getProgressiveACC05());
jhVO.addJournalRow(jrVO);
res = insJornalItemAction.insertJournalItem(jhVO,serverLanguageId,username);
if (res.isError()) {
throw new Exception(res.getErrorMessage());
}
// insert vat rows in sale vat register...
ArrayList vatRows = new ArrayList();
Enumeration en = vats.keys();
while(en.hasMoreElements())
vatRows.add(vats.get(en.nextElement()));
res = vatRegisterAction.insertVatRows(vatRows,serverLanguageId,username);
if (res.isError()) {
throw new Exception(res.getErrorMessage());
}
/*
// create an item registration for proceeds, according to expiration settings (e.g. retail selling):
// there must be only one instalment and this instalment has 0 instalment days
if (paymentInstallments.size()==1 && ((PaymentInstalmentVO)paymentInstallments.get(0)).getInstalmentDaysREG17().intValue()==0) {
*/
if (pk.getDocTypeDOC01().equals(ApplicationConsts.SALE_DESK_DOC_TYPE)) {
map = new HashMap();
map.put(ApplicationConsts.COMPANY_CODE_SYS01,docVO.getCompanyCodeSys01DOC01());
map.put(ApplicationConsts.PARAM_CODE,ApplicationConsts.CASE_ACCOUNT);
res = parsBean.loadUserParam(map,serverLanguageId,username);
if (res.isError()) {
throw new Exception(res.getErrorMessage());
}
String caseAccountCode = ((VOResponse)res).getVo().toString();
jhVO = new JournalHeaderVO();
jhVO.setCompanyCodeSys01ACC05(docVO.getCompanyCodeSys01DOC01());
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_DESK_DOC_TYPE)) {
jhVO.setDescriptionACC05(
t3+" "+docVO.getDocSequenceDOC01()+"/"+docVO.getDocYearDOC01()
);
jhVO.setAccountingMotiveCodeAcc03ACC05(ApplicationConsts.MOTIVE_SALE_RETAIL_PROCEEDS);
}
else if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE)) {
jhVO.setAccountingMotiveCodeAcc03ACC05(ApplicationConsts.MOTIVE_INVOICE_PROCEEDS);
jhVO.setDescriptionACC05(
t4+" "+docVO.getDocSequenceDOC01()+"/"+docVO.getDocYearDOC01()+" - "+
t5+" "+docVO.getName_1REG04()+" "+(docVO.getName_2REG04()==null?"":docVO.getName_2REG04())
);
}
else {
jhVO.setAccountingMotiveCodeAcc03ACC05(ApplicationConsts.MOTIVE_INVOICE_PROCEEDS);
jhVO.setDescriptionACC05(
t6+" "+docVO.getDocSequenceDOC01()+"/"+docVO.getDocYearDOC01()+" - "+
t5+" "+docVO.getName_1REG04()+" "+(docVO.getName_2REG04()==null?"":docVO.getName_2REG04())
);
}
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(creditAccountCodeAcc02);
jrVO.setAccountCodeACC06(docVO.getCustomerCodeSAL07());
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_CUSTOMER);
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
jrVO.setCreditAmountACC06(docVO.getTotalDOC01().negate());
else
jrVO.setCreditAmountACC06(docVO.getTotalDOC01());
jrVO.setCreditAmountACC06(CurrencyConversionUtils.convertCurrencyToCurrency(jrVO.getCreditAmountACC06(),conv));
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setProgressiveAcc05ACC06(jhVO.getProgressiveACC05());
jhVO.addJournalRow(jrVO);
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
jrVO.setAccountCodeAcc02ACC06(caseAccountCode);
jrVO.setAccountCodeACC06(caseAccountCode);
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_ACCOUNT);
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
jrVO.setDebitAmountACC06(docVO.getTotalDOC01().negate());
else
jrVO.setDebitAmountACC06(docVO.getTotalDOC01());
jrVO.setDebitAmountACC06(CurrencyConversionUtils.convertCurrencyToCurrency(jrVO.getDebitAmountACC06(),conv));
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setProgressiveAcc05ACC06(jhVO.getProgressiveACC05());
jhVO.addJournalRow(jrVO);
res = insJornalItemAction.insertJournalItem(jhVO,serverLanguageId,username);
if (res.isError()) {
throw new Exception(res.getErrorMessage());