Skip to content

Commit b7306f1

Browse files
Jose Alberto Hernandezadamsaghy
authored andcommitted
FINERACT-2425: Tax component and Tax Group refactoring
1 parent cbf8a4f commit b7306f1

33 files changed

+525
-295
lines changed

fineract-core/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccountType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public String toString() {
119119
return name();
120120
}
121121

122+
public EnumOptionData toEnumOptionData() {
123+
return new EnumOptionData((long) value, code, code);
124+
}
125+
122126
public boolean isAssetType() {
123127
return this.value.equals(GLAccountType.ASSET.getValue());
124128
}

fineract-core/src/main/java/org/apache/fineract/accounting/glaccount/domain/GLAccountUsage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.HashMap;
2222
import java.util.Map;
23+
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
2324

2425
public enum GLAccountUsage {
2526

@@ -81,4 +82,8 @@ public String toString() {
8182
return name().toString();
8283
}
8384

85+
public EnumOptionData toEnumOptionData() {
86+
return new EnumOptionData((long) value, code, code);
87+
}
88+
8489
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.accounting.glaccount.mapper;
20+
21+
import java.util.List;
22+
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
23+
import org.apache.fineract.accounting.glaccount.domain.GLAccount;
24+
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
25+
import org.apache.fineract.accounting.glaccount.domain.GLAccountUsage;
26+
import org.apache.fineract.infrastructure.codes.mapper.CodeValueMapper;
27+
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
28+
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
29+
import org.mapstruct.Mapper;
30+
import org.mapstruct.Mapping;
31+
import org.mapstruct.Named;
32+
33+
@Mapper(config = MapstructMapperConfig.class, uses = { CodeValueMapper.class })
34+
public interface GlAccountMapper {
35+
36+
@Mapping(target = "usage", source = "glAccount.usage", qualifiedByName = "glAccountUsage")
37+
@Mapping(target = "type", source = "glAccount.type", qualifiedByName = "glAccountType")
38+
@Mapping(target = "name", source = "glAccount.name")
39+
@Mapping(target = "nameDecorated", source = "glAccount.name")
40+
@Mapping(target = "parentId", source = "glAccount.parent.id")
41+
@Mapping(target = "tagId", source = "glAccount.tagId")
42+
@Mapping(target = "accountTypeOptions", ignore = true)
43+
@Mapping(target = "usageOptions", ignore = true)
44+
@Mapping(target = "assetHeaderAccountOptions", ignore = true)
45+
@Mapping(target = "liabilityHeaderAccountOptions", ignore = true)
46+
@Mapping(target = "equityHeaderAccountOptions", ignore = true)
47+
@Mapping(target = "incomeHeaderAccountOptions", ignore = true)
48+
@Mapping(target = "expenseHeaderAccountOptions", ignore = true)
49+
@Mapping(target = "allowedAssetsTagOptions", ignore = true)
50+
@Mapping(target = "allowedLiabilitiesTagOptions", ignore = true)
51+
@Mapping(target = "allowedEquityTagOptions", ignore = true)
52+
@Mapping(target = "allowedIncomeTagOptions", ignore = true)
53+
@Mapping(target = "allowedExpensesTagOptions", ignore = true)
54+
@Mapping(target = "organizationRunningBalance", ignore = true)
55+
@Mapping(target = "rowIndex", ignore = true)
56+
GLAccountData map(GLAccount glAccount);
57+
58+
List<GLAccountData> map(List<GLAccount> glAccounts);
59+
60+
@Named("glAccountType")
61+
default EnumOptionData glAccountType(Integer typeId) {
62+
return GLAccountType.fromInt(typeId).toEnumOptionData();
63+
}
64+
65+
@Named("glAccountUsage")
66+
default EnumOptionData glAccountUsage(Integer usageId) {
67+
return GLAccountUsage.fromInt(usageId).toEnumOptionData();
68+
}
69+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.accounting.glaccount.mapper;
20+
21+
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
22+
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
23+
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
24+
import org.mapstruct.Mapper;
25+
import org.mapstruct.Mapping;
26+
27+
@Mapper(config = MapstructMapperConfig.class)
28+
public interface GlAccountTypeMapper {
29+
30+
@Mapping(target = "id", expression = "java((long) glAccountType.getValue())")
31+
@Mapping(target = "code", source = "glAccountType.code")
32+
@Mapping(target = "description", source = "glAccountType.code")
33+
EnumOptionData map(GLAccountType glAccountType);
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.accounting.glaccount.mapper;
20+
21+
import org.apache.fineract.accounting.glaccount.domain.GLAccountUsage;
22+
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
23+
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
24+
import org.mapstruct.Mapper;
25+
import org.mapstruct.Mapping;
26+
27+
@Mapper(config = MapstructMapperConfig.class)
28+
public interface GlAccountUsageMapper {
29+
30+
@Mapping(target = "id", expression = "java((long) glAccountUsage.getValue())")
31+
@Mapping(target = "code", source = "glAccountUsage.code")
32+
@Mapping(target = "description", source = "glAccountUsage.code")
33+
EnumOptionData map(GLAccountUsage glAccountUsage);
34+
35+
}

fineract-core/src/main/java/org/apache/fineract/portfolio/tax/data/TaxComponentData.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ public final class TaxComponentData implements Serializable {
4949
private final Collection<EnumOptionData> glAccountTypeOptions;
5050

5151
public static TaxComponentData instance(final Long id, final String name, final BigDecimal percentage,
52-
final EnumOptionData debitAccountType, final GLAccountData debitAcount, final EnumOptionData creditAccountType,
53-
final GLAccountData creditAcount, final LocalDate startDate, final Collection<TaxComponentHistoryData> taxComponentHistories) {
52+
final EnumOptionData debitAccountType, final GLAccountData debitAccount, final EnumOptionData creditAccountType,
53+
final GLAccountData creditAccount, final LocalDate startDate, final Collection<TaxComponentHistoryData> taxComponentHistories) {
5454
final Map<String, List<GLAccountData>> glAccountOptions = null;
5555
final Collection<EnumOptionData> glAccountTypeOptions = null;
56-
return new TaxComponentData(id, name, percentage, debitAccountType, debitAcount, creditAccountType, creditAcount, startDate,
56+
return new TaxComponentData(id, name, percentage, debitAccountType, debitAccount, creditAccountType, creditAccount, startDate,
5757
taxComponentHistories, glAccountOptions, glAccountTypeOptions);
5858
}
5959

6060
public static TaxComponentData lookup(final Long id, final String name) {
6161
final BigDecimal percentage = null;
6262
final EnumOptionData debitAccountType = null;
63-
final GLAccountData debitAcount = null;
63+
final GLAccountData debitAccount = null;
6464
final EnumOptionData creditAccountType = null;
65-
final GLAccountData creditAcount = null;
65+
final GLAccountData creditAccount = null;
6666
final LocalDate startDate = null;
6767
final Collection<TaxComponentHistoryData> taxComponentHistories = null;
6868
final Map<String, List<GLAccountData>> glAccountOptions = null;
6969
final Collection<EnumOptionData> glAccountTypeOptions = null;
70-
return new TaxComponentData(id, name, percentage, debitAccountType, debitAcount, creditAccountType, creditAcount, startDate,
70+
return new TaxComponentData(id, name, percentage, debitAccountType, debitAccount, creditAccountType, creditAccount, startDate,
7171
taxComponentHistories, glAccountOptions, glAccountTypeOptions);
7272
}
7373

@@ -77,24 +77,24 @@ public static TaxComponentData template(final Map<String, List<GLAccountData>> g
7777
final String name = null;
7878
final BigDecimal percentage = null;
7979
final EnumOptionData debitAccountType = null;
80-
final GLAccountData debitAcount = null;
80+
final GLAccountData debitAccount = null;
8181
final EnumOptionData creditAccountType = null;
82-
final GLAccountData creditAcount = null;
82+
final GLAccountData creditAccount = null;
8383
final LocalDate startDate = null;
8484
final Collection<TaxComponentHistoryData> taxComponentHistories = null;
85-
return new TaxComponentData(id, name, percentage, debitAccountType, debitAcount, creditAccountType, creditAcount, startDate,
85+
return new TaxComponentData(id, name, percentage, debitAccountType, debitAccount, creditAccountType, creditAccount, startDate,
8686
taxComponentHistories, glAccountOptions, glAccountTypeOptions);
8787
}
8888

89-
private TaxComponentData(final Long id, final BigDecimal percentage, final GLAccountData debitAcount,
90-
final GLAccountData creditAcount) {
89+
private TaxComponentData(final Long id, final BigDecimal percentage, final GLAccountData debitAccount,
90+
final GLAccountData creditAccount) {
9191
this.id = id;
9292
this.percentage = percentage;
9393
this.name = null;
9494
this.debitAccountType = null;
95-
this.debitAccount = debitAcount;
95+
this.debitAccount = debitAccount;
9696
this.creditAccountType = null;
97-
this.creditAccount = creditAcount;
97+
this.creditAccount = creditAccount;
9898
this.startDate = null;
9999
this.taxComponentHistories = null;
100100
this.glAccountOptions = null;

fineract-core/src/main/java/org/apache/fineract/portfolio/tax/request/TaxComponentRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class TaxComponentRequest implements Serializable {
4040
private Integer debitAccountType;
4141
private Long debitAccountId;
4242
private Integer creditAccountType;
43-
private Long creditAcountId;
43+
private Long creditAccountId;
4444
private String startDate;
4545
private String dateFormat;
4646
private String locale;

fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxAssembler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public TaxComponent assembleTaxComponentFrom(final JsonCommand command) {
6161
final BigDecimal percentage = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(TaxApiConstants.percentageParamName, element);
6262
final Integer debitAccountType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(TaxApiConstants.debitAccountTypeParamName,
6363
element);
64-
final Long debitAccountId = this.fromApiJsonHelper.extractLongNamed(TaxApiConstants.debitAcountIdParamName, element);
64+
final Long debitAccountId = this.fromApiJsonHelper.extractLongNamed(TaxApiConstants.debitAccountIdParamName, element);
6565
GLAccountType debitGlAccountType = null;
6666
if (debitAccountType != null) {
6767
debitGlAccountType = GLAccountType.fromInt(debitAccountType);
@@ -70,7 +70,7 @@ public TaxComponent assembleTaxComponentFrom(final JsonCommand command) {
7070
if (debitAccountId != null) {
7171
debitGlAccount = this.glAccountRepositoryWrapper.findOneWithNotFoundDetection(debitAccountId);
7272
if (!debitGlAccount.getType().equals(debitAccountType) || debitGlAccount.isHeaderAccount()) {
73-
baseDataValidator.parameter(TaxApiConstants.debitAcountIdParamName).value(debitAccountId)
73+
baseDataValidator.parameter(TaxApiConstants.debitAccountIdParamName).value(debitAccountId)
7474
.failWithCode("not.a.valid.account");
7575
}
7676
}
@@ -81,12 +81,12 @@ public TaxComponent assembleTaxComponentFrom(final JsonCommand command) {
8181
if (creditAccountType != null) {
8282
creditGlAccountType = GLAccountType.fromInt(creditAccountType);
8383
}
84-
final Long creditAccountId = this.fromApiJsonHelper.extractLongNamed(TaxApiConstants.creditAcountIdParamName, element);
84+
final Long creditAccountId = this.fromApiJsonHelper.extractLongNamed(TaxApiConstants.creditAccountIdParamName, element);
8585
GLAccount creditGlAccount = null;
8686
if (creditAccountId != null) {
8787
creditGlAccount = this.glAccountRepositoryWrapper.findOneWithNotFoundDetection(creditAccountId);
8888
if (!creditGlAccount.getType().equals(creditAccountType) || creditGlAccount.isHeaderAccount()) {
89-
baseDataValidator.parameter(TaxApiConstants.creditAcountIdParamName).value(creditAccountId)
89+
baseDataValidator.parameter(TaxApiConstants.creditAccountIdParamName).value(creditAccountId)
9090
.failWithCode("not.a.valid.account");
9191
}
9292
}

0 commit comments

Comments
 (0)