4
4
import lombok .extern .slf4j .Slf4j ;
5
5
import lombok .val ;
6
6
import org .cardanofoundation .lob .app .accounting_reporting_core .domain .core .UserExtractionParameters ;
7
- import org .cardanofoundation .lob .app .accounting_reporting_core .domain .entity .BatchStatistics ;
8
- import org .cardanofoundation .lob .app .accounting_reporting_core .domain .entity .FilteringParameters ;
9
- import org .cardanofoundation .lob .app .accounting_reporting_core .domain .entity .TransactionBatchEntity ;
10
- import org .cardanofoundation .lob .app .accounting_reporting_core .domain .entity .TransactionEntity ;
7
+ import org .cardanofoundation .lob .app .accounting_reporting_core .domain .entity .*;
11
8
import org .cardanofoundation .lob .app .accounting_reporting_core .repository .TransactionBatchRepositoryGateway ;
12
9
import org .cardanofoundation .lob .app .accounting_reporting_core .repository .TransactionRepositoryGateway ;
13
10
import org .cardanofoundation .lob .app .accounting_reporting_core .resource .requests .BatchSearchRequest ;
18
15
import org .jmolecules .ddd .annotation .Service ;
19
16
import org .springframework .transaction .annotation .Transactional ;
20
17
18
+ import java .math .BigDecimal ;
21
19
import java .time .LocalDate ;
22
- import java .util .List ;
23
- import java .util .Optional ;
24
- import java .util .Set ;
20
+ import java .util .*;
25
21
import java .util .stream .Collectors ;
26
22
23
+ import static org .cardanofoundation .lob .app .accounting_reporting_core .domain .core .Source .ERP ;
24
+ import static org .cardanofoundation .lob .app .accounting_reporting_core .domain .core .Violation .Severity .ERROR ;
25
+ import static org .cardanofoundation .lob .app .accounting_reporting_core .domain .core .ViolationCode .AMOUNT_FCY_IS_ZERO ;
26
+
27
27
@ Service
28
28
@ org .springframework .stereotype .Service
29
29
@ Slf4j
@@ -152,20 +152,46 @@ private TransactionView getTransactionView(TransactionEntity transactionEntity)
152
152
transactionEntity .getAutomatedValidationStatus (),
153
153
transactionEntity .getTransactionApproved (),
154
154
transactionEntity .getLedgerDispatchApproved (),
155
+ getAmountLcy (transactionEntity ),
155
156
getTransactionItemView (transactionEntity ),
156
157
getViolation (transactionEntity ),
157
158
transactionEntity .getStatus ()
158
159
);
159
160
}
160
161
161
162
private Set <TransactionItemView > getTransactionItemView (TransactionEntity transaction ) {
162
- return transaction .getItems ().stream ().map (item -> new TransactionItemView (
163
- item .getId (),
164
- item .getAccountDebit (),
165
- item .getAccountCredit (),
166
- item .getAmountFcy (),
167
- item .getAmountLcy ()
168
- )).collect (Collectors .toSet ());
163
+ return transaction .getItems ().stream ().map (item -> {
164
+
165
+ return new TransactionItemView (
166
+ item .getId (),
167
+ item .getAccountDebit ().map (account -> account .getCode ()).orElse ("" ),
168
+ item .getAccountDebit ().flatMap (account -> account .getName ()).orElse ("" ),
169
+ item .getAccountDebit ().flatMap (account -> account .getRefCode ()).orElse ("" ),
170
+ item .getAccountCredit ().map (account -> account .getCode ()).orElse ("" ),
171
+ item .getAccountCredit ().flatMap (account -> account .getName ()).orElse ("" ),
172
+ item .getAccountCredit ().flatMap (account -> account .getRefCode ()).orElse ("" ),
173
+ item .getAmountFcy (),
174
+ item .getAmountLcy (),
175
+ item .getFxRate (),
176
+ item .getCostCenter ().map (CostCenter ::getCustomerCode ).orElse ("" ),
177
+ item .getCostCenter ().flatMap (CostCenter ::getExternalCustomerCode ).orElse ("" ),
178
+ item .getCostCenter ().flatMap (CostCenter ::getName ).orElse ("" ),
179
+ item .getProject ().map (Project ::getCustomerCode ).orElse ("" ),
180
+ item .getProject ().flatMap (Project ::getName ).orElse ("" ),
181
+ item .getProject ().flatMap (Project ::getExternalCustomerCode ).orElse ("" ),
182
+ item .getAccountEvent ().map (AccountEvent ::getCode ).orElse ("" ),
183
+ item .getAccountEvent ().map (AccountEvent ::getName ).orElse ("" ),
184
+ item .getDocument ().map (Document ::getNum ).orElse ("" ),
185
+ item .getDocument ().map (document -> document .getCurrency ().getCustomerCode ()).orElse ("" ),
186
+ item .getDocument ().flatMap (document -> document .getVat ().map (Vat ::getCustomerCode )).orElse ("" ),
187
+ item .getDocument ().flatMap (document -> document .getVat ().flatMap (Vat ::getRate )).orElse (BigDecimal .ZERO ),
188
+ item .getDocument ().flatMap (d -> d .getCounterparty ().map (Counterparty ::getCustomerCode )).orElse ("" ),
189
+ item .getDocument ().flatMap (d -> d .getCounterparty ().map (Counterparty ::getType )).orElse (org .cardanofoundation .lob .app .accounting_reporting_core .domain .core .Counterparty .Type .VENDOR ),
190
+ item .getDocument ().flatMap (document -> document .getCounterparty ().flatMap (Counterparty ::getName )).orElse ("" )
191
+
192
+
193
+ );
194
+ }).collect (Collectors .toSet ());
169
195
}
170
196
171
197
private Set <ViolationView > getViolation (TransactionEntity transaction ) {
@@ -179,4 +205,12 @@ private Set<ViolationView> getViolation(TransactionEntity transaction) {
179
205
)).collect (Collectors .toSet ());
180
206
}
181
207
208
+ private BigDecimal getAmountLcy (TransactionEntity tx ) {
209
+ BigDecimal total = BigDecimal .ZERO ;
210
+ for (val txItem : tx .getItems ()) {
211
+ total = total .add (txItem .getAmountLcy ());
212
+ }
213
+ return total ;
214
+ }
215
+
182
216
}
0 commit comments