// retrieve all charges rows...
rowsResponse = rowsBean.loadSaleDocCharges(pars,serverLanguageId,username);
if (rowsResponse.isError())
throw new Exception(rowsResponse.getErrorMessage());
java.util.List chargesRows = ((VOListResponse)rowsResponse).getRows();
SaleDocChargeVO chargeVO = null;
for(int i=0;i<chargesRows.size();i++) {
chargeVO = (SaleDocChargeVO)chargesRows.get(i);
if (chargeVO.getValueDOC03()!=null) {
chargeVO.setTaxableIncomeDOC03(
chargeVO.getValueDOC03().setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
);
// apply taxable income to total taxable income...
totalTaxableIncome = totalTaxableIncome.add(chargeVO.getTaxableIncomeDOC03());
}
}
// fill in coeff...
Hashtable coeff = new Hashtable(); // collection of <item/act/valuecharge,taxableincome/totaltaxableincome>
for(int i=0;i<detailItemRows.size();i++) {
detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
coeff.put(detailItemVO,detailItemVO.getTaxableIncomeDOC02().divide(totalTaxableIncome,BigDecimal.ROUND_HALF_UP));
}
for(int i=0;i<actsRows.size();i++) {
actVO = (SaleDocActivityVO)actsRows.get(i);
coeff.put(actVO,actVO.getTaxableIncomeDOC13().divide(totalTaxableIncome,BigDecimal.ROUND_HALF_UP));
}
for(int i=0;i<chargesRows.size();i++) {
chargeVO = (SaleDocChargeVO)chargesRows.get(i);
if (chargeVO.getValueDOC03()!=null) {
coeff.put(chargeVO,chargeVO.getTaxableIncomeDOC03().divide(totalTaxableIncome,BigDecimal.ROUND_HALF_UP));
}
}
// apply % charges to all taxable incomes...
SaleDocChargeVO percVO = null;
for(int k=0;k<chargesRows.size();k++) {
percVO = (SaleDocChargeVO)chargesRows.get(k);
if (percVO.getPercDOC03()!=null) {
for(int i=0;i<detailItemRows.size();i++) {
detailItemVO = (DetailSaleDocRowVO)detailItemRows.get(i);
detailItemVO.setTaxableIncomeDOC02(
detailItemVO.getTaxableIncomeDOC02().add(detailItemVO.getTaxableIncomeDOC02().multiply(percVO.getPercDOC03().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
);
}
for(int i=0;i<actsRows.size();i++) {
actVO = (SaleDocActivityVO)actsRows.get(i);
actVO.setTaxableIncomeDOC13(
actVO.getTaxableIncomeDOC13().add(actVO.getTaxableIncomeDOC13().multiply(percVO.getPercDOC03().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
);
}
for(int i=0;i<chargesRows.size();i++) {
chargeVO = (SaleDocChargeVO)chargesRows.get(i);
if (chargeVO.getValueDOC03()!=null) {
chargeVO.setTaxableIncomeDOC03(
chargeVO.getTaxableIncomeDOC03().add(chargeVO.getTaxableIncomeDOC03().multiply(percVO.getPercDOC03().divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP))).
setScale(vo.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP)
);
}
}