}
JournalHeaderWithVatVO jhVO = (JournalHeaderWithVatVO)newPersistentObject;
jhVO.getJournalRows().clear();
JournalRowVO jrVO = null;
JournalRowWithVatVO rowVatVO = null;
VatRowVO vatVO = null;
BigDecimal vatValue = null;
BigDecimal totalValue = new BigDecimal(0);
for(int i=0;i<gridModel.getRowCount();i++) {
// create 3 rows for each vat row value object...
rowVatVO = (JournalRowWithVatVO)gridModel.getObjectForRow(i);
// 1. add taxable income to the accounting item...
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
jrVO.setAccountCodeAcc02ACC06(rowVatVO.getAccountCodeAcc02ACC06());
jrVO.setAccountCodeACC06(rowVatVO.getAccountCodeACC06());
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_ACCOUNT);
if (jhVO.getAccountCodeTypeACC06().equals(ApplicationConsts.ACCOUNT_TYPE_CUSTOMER))
jrVO.setCreditAmountACC06(rowVatVO.getTaxableIncome().setScale(detailFrame.getCurrencyDecimals(),BigDecimal.ROUND_HALF_UP));
else
jrVO.setDebitAmountACC06(rowVatVO.getTaxableIncome().setScale(detailFrame.getCurrencyDecimals(),BigDecimal.ROUND_HALF_UP));
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jrVO.setDescriptionACC06(rowVatVO.getDescriptionACC06());
jhVO.addJournalRow(jrVO);
totalValue = totalValue.add(rowVatVO.getTaxableIncome().setScale(detailFrame.getCurrencyDecimals(),BigDecimal.ROUND_HALF_UP));
// 2. prepare vat row for the specified register...
vatVO = new VatRowVO();
vatVO.setCompanyCodeSys01ACC07(jhVO.getCompanyCodeSys01ACC05());
vatVO.setRegisterCodeAcc04ACC07(jhVO.getRegisterCodeACC04());
vatVO.setTaxableIncomeACC07(rowVatVO.getTaxableIncome().setScale(detailFrame.getCurrencyDecimals(),BigDecimal.ROUND_HALF_UP));
vatVO.setVatCodeACC07(rowVatVO.getVatCodeREG01());
vatVO.setVatDateACC07(new java.sql.Date(System.currentTimeMillis()));
vatVO.setVatDescriptionACC07(rowVatVO.getVatDescriptionREG01());
vatValue = rowVatVO.getTaxableIncome().multiply( new BigDecimal(rowVatVO.getValueREG01().doubleValue()/100d*(100d-rowVatVO.getDeductibleREG01().doubleValue())/100d) ).setScale(detailFrame.getCurrencyDecimals(),BigDecimal.ROUND_HALF_UP);
vatVO.setVatValueACC07(vatValue);
vatVO.setVatYearACC07(new BigDecimal(Calendar.getInstance().get(Calendar.YEAR)));
jhVO.addVat(vatVO);
totalValue = totalValue.add(vatValue);
// 3. add total vat value to the accounting item...
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
jrVO.setAccountCodeAcc02ACC06(jhVO.getAccountCodeAcc02ACC04());
jrVO.setAccountCodeACC06(jhVO.getAccountCodeAcc02ACC04());
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_ACCOUNT);
if (jhVO.getAccountCodeTypeACC06().equals(ApplicationConsts.ACCOUNT_TYPE_CUSTOMER))
jrVO.setCreditAmountACC06(vatValue);
else
jrVO.setDebitAmountACC06(vatValue);
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jhVO.addJournalRow(jrVO);
// 4. add total credit/debit value to the accounting item...
jrVO = new JournalRowVO();
jrVO.setCompanyCodeSys01ACC06(jhVO.getCompanyCodeSys01ACC05());
if (jhVO.getAccountCodeTypeACC06().equals(ApplicationConsts.ACCOUNT_TYPE_CUSTOMER)) {
jrVO.setAccountCodeAcc02ACC06(jhVO.getCreditAccountCodeAcc02SAL07());
jrVO.setAccountCodeACC06(jhVO.getCustomerCodeSAL07());
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_CUSTOMER);
jrVO.setDebitAmountACC06(rowVatVO.getTaxableIncome().add(vatValue).setScale(detailFrame.getCurrencyDecimals(),BigDecimal.ROUND_HALF_UP));
}
else {
jrVO.setAccountCodeAcc02ACC06(jhVO.getDebitAccountCodeAcc02PUR01());
jrVO.setAccountCodeACC06(jhVO.getSupplierCodePUR01());
jrVO.setAccountCodeTypeACC06(ApplicationConsts.ACCOUNT_TYPE_SUPPLIER);
jrVO.setCreditAmountACC06(rowVatVO.getTaxableIncome().add(vatValue).setScale(detailFrame.getCurrencyDecimals(),BigDecimal.ROUND_HALF_UP));
}
jrVO.setDescriptionACC06("");
jrVO.setItemYearAcc05ACC06(jhVO.getItemYearACC05());
jhVO.addJournalRow(jrVO);
}