-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathReconsilationController.java
More file actions
538 lines (491 loc) · 25.1 KB
/
ReconsilationController.java
File metadata and controls
538 lines (491 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
package com.simpleaccounts.rest.reconsilationcontroller;
import static com.simpleaccounts.constant.ErrorConstant.ERROR;
import com.simpleaccounts.aop.LogRequest;
import com.simpleaccounts.bank.model.DeleteModel;
import com.simpleaccounts.constant.ChartOfAccountCategoryIdEnumConstant;
import com.simpleaccounts.constant.ReconsileCategoriesEnumConstant;
import com.simpleaccounts.constant.TransactionExplinationStatusEnum;
import com.simpleaccounts.constant.dbfilter.TransactionFilterEnum;
import com.simpleaccounts.entity.ChartOfAccountCategory;
import com.simpleaccounts.entity.Contact;
import com.simpleaccounts.entity.Invoice;
import com.simpleaccounts.entity.bankaccount.BankAccount;
import com.simpleaccounts.entity.bankaccount.ReconcileStatus;
import com.simpleaccounts.entity.bankaccount.TransactionCategory;
import com.simpleaccounts.repository.TransactionExpensesRepository;
import com.simpleaccounts.rest.DropdownModel;
import com.simpleaccounts.rest.InviceSingleLevelDropdownModel;
import com.simpleaccounts.rest.PaginationResponseModel;
import com.simpleaccounts.rest.SingleLevelDropDownModel;
import com.simpleaccounts.rest.transactioncategorycontroller.TranscationCategoryHelper;
import com.simpleaccounts.service.*;
import com.simpleaccounts.service.bankaccount.ReconcileStatusService;
import com.simpleaccounts.service.bankaccount.TransactionService;
import com.simpleaccounts.service.impl.TransactionCategoryClosingBalanceServiceImpl;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/rest/reconsile")
@SuppressWarnings("java:S131")
@RequiredArgsConstructor
public class ReconsilationController {
private final Logger logger = LoggerFactory.getLogger(ReconsilationController.class);
private final ReconcileStatusService reconcileStatusService;
private final BankAccountService bankAccountService;
private final TransactionCategoryService transactionCategoryService;
private final ReconsilationRestHelper reconsilationRestHelper;
private final InvoiceService invoiceService;
private final TranscationCategoryHelper transcationCategoryHelper;
private final ChartOfAccountCategoryService chartOfAccountCategoryService;
private final VatCategoryService vatCategoryService;
private final ContactService contactService;
private final UserService userServiceNew;
private final TransactionService transactionService;
private final TransactionCategoryClosingBalanceServiceImpl transactionCategoryClosingBalanceService;
private final TransactionExpensesRepository transactionExpensesRepository;
@LogRequest
@GetMapping(value = "/getByReconcilationCatCode")
public ResponseEntity<List<ReconsilationListModel>> getByReconcilationCatCode(
@RequestParam int reconcilationCatCode) {
try {
return new ResponseEntity<>(
reconsilationRestHelper.getList(ReconsileCategoriesEnumConstant.get(reconcilationCatCode)),
HttpStatus.OK);
} catch (Exception e) {
logger.error(ERROR, e);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
@LogRequest
@Transactional(readOnly = true)
@GetMapping(value = "/getTransactionCat")
public ResponseEntity<Object> getTransactionCategory(ReconcilationRequestModel filterModel ) {
try {
Integer chartOfAccountCategoryId = filterModel.getChartOfAccountCategoryId();
if (chartOfAccountCategoryId == null) {
logger.warn("getTransactionCategory called with null chartOfAccountCategoryId");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
ChartOfAccountCategory category = chartOfAccountCategoryService.findByPK(chartOfAccountCategoryId);
if (category == null) {
logger.warn("getTransactionCategory: ChartOfAccountCategory with ID {} not found. Returning empty structure instead of 404.", chartOfAccountCategoryId);
// Return empty structure instead of 404 to prevent UI errors
return new ResponseEntity<>(
new ReconsilationCatDataModel(null, new ArrayList<>()),
HttpStatus.OK);
}
Map<String, Object> param = null;
List<TransactionCategory> transactionCatList = null;
List<Object> list = new ArrayList<>();
// Handle null, empty, or invalid bankId gracefully
// bankId is optional for many transaction types, so we continue even if it's null or invalid
BankAccount bankAccount = null;
Integer bankId = filterModel.getBankId();
if (bankId != null && bankId != 0) {
try {
bankAccount = bankAccountService.findByPK(bankId);
if (bankAccount == null) {
logger.debug("getTransactionCategory: Bank account with ID {} not found, continuing without bank account context", bankId);
}
} catch (Exception e) {
logger.warn("getTransactionCategory: Error fetching bank account with ID {}: {}. Continuing without bank account context.", bankId, e.getMessage());
// Continue without bankAccount - it's optional for some transaction types
}
} else {
logger.debug("getTransactionCategory: No valid bankId provided (bankId={}), continuing without bank account context", bankId);
}
List<Contact> customerContactList = new ArrayList<>();
if (bankAccount != null && bankAccount.getBankAccountCurrency() != null) {
customerContactList = contactService.getCustomerContacts(bankAccount.getBankAccountCurrency());
}
List<DropdownModel> dropdownModelList = new ArrayList<>();
for (Contact contact:customerContactList){
DropdownModel dropdownModel =new DropdownModel();
dropdownModel.setValue(contact.getContactId());
if(contact.getOrganization() != null && !contact.getOrganization().isEmpty()){
dropdownModel.setLabel(contact.getOrganization());
}else {
dropdownModel.setLabel(contact.getFirstName()+" "+contact.getMiddleName()+" "+contact.getLastName());
}
dropdownModelList.add(dropdownModel);
}
ChartOfAccountCategoryIdEnumConstant categoryEnum = ChartOfAccountCategoryIdEnumConstant.get(category.getChartOfAccountCategoryId());
if (categoryEnum == null) {
logger.warn("getTransactionCategory: Unknown ChartOfAccountCategoryIdEnumConstant for category ID {}", category.getChartOfAccountCategoryId());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
switch (categoryEnum) {
case SALES:
param = new HashMap<>();
param.put("deleteFlag", false);
param.put("type", 2);
List<Invoice> invList = invoiceService.findByAttributes(param);
List<InviceSingleLevelDropdownModel> invModelList = new ArrayList<>();
for (Invoice invice : invList) {
if (invice.getId()!=null && invice.getReferenceNumber()!=null && invice.getTotalAmount()!=null && invice.getCurrency()!=null){
invModelList.add(new InviceSingleLevelDropdownModel(invice.getId(), invice.getReferenceNumber()
+ " (" + invice.getTotalAmount() + " " + invice.getCurrency().getCurrencyName()+")",
invice.getTotalAmount()));
}
}
list.add(new SingleLevelDropDownModel("Customer",dropdownModelList));
param = new HashMap<>();
param.put("label", "Sales Invoice");
param.put("options", invModelList);
list.add(param);
transactionCatList = transactionCategoryService
.getTransactionCatByChartOfAccountCategoryId(category.getChartOfAccountCategoryId());
return new ResponseEntity<>(
new ReconsilationCatDataModel(list,
transcationCategoryHelper.getSinleLevelDropDownModelList(transactionCatList)),
HttpStatus.OK);
case EXPENSE:
transactionCatList = transactionCategoryService
.getTransactionCatByChartOfAccountCategoryId(category.getChartOfAccountCategoryId());
list.add(new SingleLevelDropDownModel("Vat Included", vatCategoryService.getVatCategoryForDropDown()));
list.add(new SingleLevelDropDownModel("Customer", dropdownModelList));
// Re-fetch bankAccount if needed, with null check
if (bankAccount == null && filterModel.getBankId() != null && filterModel.getBankId() != 0) {
bankAccount = bankAccountService.findByPK(filterModel.getBankId());
}
List<Contact> supplierContactList = new ArrayList<>();
if (bankAccount != null && bankAccount.getBankAccountCurrency() != null) {
supplierContactList = contactService.getSupplierContacts(bankAccount.getBankAccountCurrency());
}
dropdownModelList = new ArrayList<>();
for (Contact contact:supplierContactList){
DropdownModel dropdownModel =new DropdownModel();
dropdownModel.setValue(contact.getContactId());
dropdownModel.setLabel(contact.getFirstName()+""+contact.getLastName());
dropdownModelList.add(dropdownModel);
}
list.add(new SingleLevelDropDownModel("Vendor", dropdownModelList));
return new ResponseEntity<>(
new ReconsilationCatDataModel(list,
transcationCategoryHelper.getSinleLevelDropDownModelList(transactionCatList)),
HttpStatus.OK);
case MONEY_PAID_TO_USER:
case MONEY_RECEIVED_FROM_USER:
transactionCatList = transactionCategoryService
.getTransactionCatByChartOfAccountCategoryId(category.getChartOfAccountCategoryId());
return new ResponseEntity<>(
new ReconsilationCatDataModel(
Arrays.asList(new SingleLevelDropDownModel("User",
userServiceNew.getUserForDropdown()/*
employeeService.getEmployeesForDropdown()*/)),
transcationCategoryHelper.getSinleLevelDropDownModelList(transactionCatList)),
HttpStatus.OK);
case TRANSFERD_TO:
case TRANSFER_FROM:
transactionCatList = transactionCategoryService
.getTransactionCatByChartOfAccountCategoryId(category.getChartOfAccountCategoryId());
if (transactionCatList != null && !transactionCatList.isEmpty())
{
if(filterModel.getBankId() != null && filterModel.getBankId() != 0)
{
List<TransactionCategory> tempTransactionCatogaryList = new ArrayList<>();
BankAccount transferBankAccount = bankAccountService.getBankAccountById(filterModel.getBankId());
if (transferBankAccount != null && transferBankAccount.getTransactionCategory() != null) {
TransactionCategory bankTransactionCategory = transferBankAccount.getTransactionCategory();
Integer bankTransactionCategoryId = bankTransactionCategory.getTransactionCategoryId();
for(TransactionCategory transactionCategory : transactionCatList)
{
Integer transactionCategoryId = transactionCategory.getTransactionCategoryId();
if(Objects.equals(transactionCategoryId, bankTransactionCategoryId))
{
// Skip the bank's own transaction category
}
else
{
tempTransactionCatogaryList.add(transactionCategory);
}
}
transactionCatList = tempTransactionCatogaryList;
}
}
return new ResponseEntity<>(
new ReconsilationCatDataModel(null,
transcationCategoryHelper.getSinleLevelDropDownModelList(transactionCatList)),
HttpStatus.OK);
}
// Return empty structure if no categories found
return new ResponseEntity<>(
new ReconsilationCatDataModel(null, new ArrayList<>()),
HttpStatus.OK);
case MONEY_SPENT_OTHERS:
case MONEY_SPENT:
case PURCHASE_OF_CAPITAL_ASSET:
case REFUND_RECEIVED:
case INTEREST_RECEVIED:
case MONEY_RECEIVED_OTHERS:
case DISPOSAL_OF_CAPITAL_ASSET:
case MONEY_RECEIVED:
transactionCatList = transactionCategoryService
.getTransactionCatByChartOfAccountCategoryId(category.getChartOfAccountCategoryId());
if (transactionCatList != null && !transactionCatList.isEmpty())
return new ResponseEntity<>(
new ReconsilationCatDataModel(null,
transcationCategoryHelper.getSinleLevelDropDownModelList(transactionCatList)),
HttpStatus.OK);
// Return empty structure if no categories found
return new ResponseEntity<>(
new ReconsilationCatDataModel(null, new ArrayList<>()),
HttpStatus.OK);
case VAT_PAYMENT:
case VAT_CLAIM:
case CORPORATE_TAX_PAYMENT:
// These categories don't need transaction categories, return empty structure
transactionCatList = transactionCategoryService
.getTransactionCatByChartOfAccountCategoryId(category.getChartOfAccountCategoryId());
return new ResponseEntity<>(
new ReconsilationCatDataModel(null,
transcationCategoryHelper.getSinleLevelDropDownModelList(transactionCatList != null ? transactionCatList : new ArrayList<>())),
HttpStatus.OK);
case DEFAULT:
default:
logger.warn("getTransactionCategory: Unhandled category enum: {}", categoryEnum);
// For unhandled cases, return empty data structure instead of error
transactionCatList = transactionCategoryService
.getTransactionCatByChartOfAccountCategoryId(category.getChartOfAccountCategoryId());
if (transactionCatList != null && !transactionCatList.isEmpty()) {
return new ResponseEntity<>(
new ReconsilationCatDataModel(null,
transcationCategoryHelper.getSinleLevelDropDownModelList(transactionCatList)),
HttpStatus.OK);
}
// Return empty structure for unhandled cases
return new ResponseEntity<>(
new ReconsilationCatDataModel(null, new ArrayList<>()),
HttpStatus.OK);
}
} catch (Exception e) {
logger.error("Error in getTransactionCategory for categoryId={}, bankId={}: ",
filterModel.getChartOfAccountCategoryId(), filterModel.getBankId(), e);
return new ResponseEntity<>("Error: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@LogRequest
@Transactional(readOnly = true)
@GetMapping(value = "/list")
public ResponseEntity<PaginationResponseModel> getAllReconcileStatus(ReconcileStatusRequestModel filterModel) {
Map<TransactionFilterEnum, Object> dataMap = new EnumMap<>(TransactionFilterEnum.class);
if (filterModel.getBankId() != null) {
dataMap.put(TransactionFilterEnum.BANK_ID, bankAccountService.findByPK(filterModel.getBankId()));
}
dataMap.put(TransactionFilterEnum.DELETE_FLAG, false);
PaginationResponseModel response = reconcileStatusService.getAllReconcileStatusList(dataMap, filterModel);
if (response == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
response.setData(reconsilationRestHelper.getModelList(response.getData()));
return new ResponseEntity<>(response, HttpStatus.OK);
}
@LogRequest
@Transactional(rollbackFor = Exception.class)
@PostMapping(value = "/save")
public ResponseEntity<String> save(@RequestParam Integer bankAccountId, @RequestParam BigDecimal closingBalance) {
try {
ReconcileStatus reconcileStatus = new ReconcileStatus();
reconcileStatus.setBankAccount(bankAccountService.getBankAccountById(bankAccountId));
reconcileStatus.setClosingBalance(closingBalance);
reconcileStatus.setReconciledDuration("1 Month");
Date date = new Date();
reconcileStatus.setReconciledDate(Instant.ofEpochMilli(date.getTime())
.atZone(ZoneId.systemDefault()).toLocalDateTime());
reconcileStatusService.persist(reconcileStatus);
return new ResponseEntity<>("Saved Successfully", HttpStatus.OK);
} catch (Exception e) {
logger.error(ERROR, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@LogRequest
@Transactional(rollbackFor = Exception.class)
@PostMapping(value = "/reconcilenow")
public ResponseEntity<ReconcilationResponseModel> reconcileNow(@ModelAttribute ReconcilationPersistModel reconcilationPersistModel,
HttpServletRequest request) {
// #region agent log
try {
Integer bid = reconcilationPersistModel != null ? reconcilationPersistModel.getBankId() : null;
String dt = reconcilationPersistModel != null && reconcilationPersistModel.getDate() != null ? reconcilationPersistModel.getDate().replace("\"", "\\\"") : null;
BigDecimal cb = reconcilationPersistModel != null ? reconcilationPersistModel.getClosingBalance() : null;
String line = "{\"location\":\"ReconsilationController.java:reconcileNow:entry\",\"message\":\"reconcileNow entry\",\"data\":{\"bankId\":" + bid + ",\"date\":\"" + (dt != null ? dt : "null") + "\",\"closingBalance\":" + (cb != null ? cb.toString() : "null") + "},\"timestamp\":" + System.currentTimeMillis() + ",\"hypothesisId\":\"H1,H2\"}\n";
Files.write(Path.of("/Users/zecs/workspaces/SimpleAccounts-UAE/.cursor/debug.log"), line.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
} catch (Exception ignored) { }
// #endregion
try {
ReconcilationResponseModel responseModel = new ReconcilationResponseModel();
if (reconcilationPersistModel.getBankId() == null) {
responseModel.setStatus(0);
responseModel.setMessage("Bank account is required.");
return new ResponseEntity<>(responseModel, HttpStatus.BAD_REQUEST);
}
LocalDateTime reconcileDate = reconsilationRestHelper.getDateFromRequest(reconcilationPersistModel);
// #region agent log
try {
String line2 = "{\"location\":\"ReconsilationController.java:afterGetDateFromRequest\",\"message\":\"reconcileDate\",\"data\":{\"reconcileDate\":" + (reconcileDate == null ? "null" : "\"" + reconcileDate.toString() + "\"") + "},\"timestamp\":" + System.currentTimeMillis() + ",\"hypothesisId\":\"H3\"}\n";
Files.write(Path.of("/Users/zecs/workspaces/SimpleAccounts-UAE/.cursor/debug.log"), line2.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
} catch (Exception ignored) { }
// #endregion
if (reconcileDate == null) {
responseModel.setStatus(0);
responseModel.setMessage("Invalid or missing date. Use format DD-MM-YYYY.");
return new ResponseEntity<>(responseModel, HttpStatus.BAD_REQUEST);
}
if (reconcilationPersistModel.getClosingBalance() == null) {
responseModel.setStatus(0);
responseModel.setMessage("Closing balance is required.");
return new ResponseEntity<>(responseModel, HttpStatus.BAD_REQUEST);
}
ReconcileStatus status = reconsilationRestHelper.getReconcileStatus(reconcilationPersistModel);
LocalDateTime startDate = null;
if (status == null) {
startDate = transactionService.getTransactionStartDateToReconcile(reconcileDate.plusHours(23).plusMinutes(59), reconcilationPersistModel.getBankId());
if(startDate == null) {
responseModel.setStatus(3);
responseModel.setMessage(" The Reconcile date should be after the last transaction date or same as the transaction date.");
return new ResponseEntity<>(responseModel, HttpStatus.OK);
}
} else {
startDate = status.getReconciledDate();
if (startDate == null) {
responseModel.setStatus(0);
responseModel.setMessage("Invalid reconcile status: missing start date.");
return new ResponseEntity<>(responseModel, HttpStatus.BAD_REQUEST);
}
}
Integer unexplainedTransaction = 1;
if (startDate.isEqual(reconcileDate) && status !=null)
unexplainedTransaction = -1;
else
unexplainedTransaction = transactionService.isTransactionsReadyForReconcile(startDate, reconcileDate.plusHours(23).plusMinutes(59), reconcilationPersistModel.getBankId());
if (unexplainedTransaction == 0) {
//1 check if this matches with closing balance
BigDecimal closingBalance = reconcilationPersistModel.getClosingBalance();
var bankAccount = bankAccountService.getBankAccountById(reconcilationPersistModel.getBankId());
if (bankAccount == null || bankAccount.getTransactionCategory() == null) {
responseModel.setStatus(0);
responseModel.setMessage("Bank account or transaction category not found.");
return new ResponseEntity<>(responseModel, HttpStatus.BAD_REQUEST);
}
BigDecimal dbClosingBalance = transactionCategoryClosingBalanceService.matchClosingBalanceForReconcile(reconcileDate,
bankAccount.getTransactionCategory());
if(dbClosingBalance != null && dbClosingBalance.longValue()<0)
dbClosingBalance = dbClosingBalance.negate();
if (dbClosingBalance == null) {
responseModel.setStatus(0);
responseModel.setMessage("Could not compute closing balance.");
return new ResponseEntity<>(responseModel, HttpStatus.BAD_REQUEST);
}
boolean isClosingBalanceMatches = dbClosingBalance.compareTo(closingBalance)==0;
if (isClosingBalanceMatches) {
transactionService.updateTransactionStatusReconcile(startDate, reconcileDate.plusHours(23).plusMinutes(59), reconcilationPersistModel.getBankId(),
TransactionExplinationStatusEnum.RECONCILED);
ReconcileStatus reconcileStatus = new ReconcileStatus();
reconcileStatus.setReconciledDate(reconcileDate);
reconcileStatus.setReconciledStartDate(startDate);
reconcileStatus.setBankAccount(bankAccountService.findByPK(reconcilationPersistModel.getBankId()));
reconcileStatus.setClosingBalance(closingBalance);
reconcileStatusService.persist(reconcileStatus);
responseModel.setStatus(1);
responseModel.setMessage("Reconciled Successfully..");
return new ResponseEntity<>(responseModel, HttpStatus.OK);
} else {
responseModel.setStatus(2);
responseModel.setMessage("Failed Reconciling. Closing Balance in System " + dbClosingBalance + " does not matches with the given Closing Balance");
return new ResponseEntity<>(responseModel, HttpStatus.OK);
}
} else if (unexplainedTransaction == -1) {
responseModel.setStatus(3);
responseModel.setMessage("The Transactions in Bank Account are already reconciled for the given date");
return new ResponseEntity<>(responseModel, HttpStatus.OK);
} else { /*
* Send unexplainedTransaction still pending to be explained.
*/
responseModel.setStatus(4);
responseModel.setMessage("Failed Reconciling. Please update the remaining " + unexplainedTransaction + " unexplained transactions before reconciling");
return new ResponseEntity<>(responseModel, HttpStatus.OK);
}
} catch (Exception e) {
// #region agent log
try {
String msg = e.getMessage() != null ? e.getMessage().replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", " ") : "";
String line3 = "{\"location\":\"ReconsilationController.java:catch\",\"message\":\"reconcileNow exception\",\"data\":{\"exceptionClass\":\"" + e.getClass().getName() + "\",\"message\":\"" + msg + "\"},\"timestamp\":" + System.currentTimeMillis() + ",\"hypothesisId\":\"H2,H4\"}\n";
Files.write(Path.of("/Users/zecs/workspaces/SimpleAccounts-UAE/.cursor/debug.log"), line3.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
} catch (Exception ignored) { }
// #endregion
logger.error(ERROR, e);
ReconcilationResponseModel errModel = new ReconcilationResponseModel();
errModel.setStatus(0);
errModel.setMessage(e.getMessage() != null ? e.getMessage() : "Reconciliation failed. Please try again.");
return new ResponseEntity<>(errModel, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@LogRequest
@Transactional(rollbackFor = Exception.class)
@DeleteMapping(value = "/deletes")
public ResponseEntity<String> deleteTransactions(@RequestBody DeleteModel ids) {
try {
reconcileStatusService.deleteByIds(ids.getIds());
return new ResponseEntity<>("Deleted reconcile status rows successfully", HttpStatus.OK);
} catch (Exception e) {
logger.error(ERROR, e);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
@LogRequest
@GetMapping(value = "/getChildrenTransactionCategoryList")
public ResponseEntity<List<SingleLevelDropDownModel>> getlistEmployeeTransactionCategory(
@RequestParam(value = "id", required = false) Integer id) {
try {
if (id == null) {
logger.warn("getChildrenTransactionCategoryList: id is null");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
List<DropdownModel> response;
TransactionCategory parentCategory = transactionCategoryService.findByPK(id);
if (parentCategory == null) {
logger.warn("getChildrenTransactionCategoryList: parent category not found for id {}", id);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
Map<String, Object> param = new HashMap<>();
param.put("parentTransactionCategory", parentCategory);
List<TransactionCategory> transactionCategoryList =
transactionCategoryService.findByAttributes(param);
response = transcationCategoryHelper.getEmployeeTransactionCategory(transactionCategoryList);
return new ResponseEntity(response, HttpStatus.OK);
} catch (Exception e) {
logger.error(ERROR, e);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
@LogRequest
@GetMapping(value = "/getCOACList")
public ResponseEntity<List<SingleLevelDropDownModel>> getCOACList(){
try {
List<DropdownModel> response;
List<ChartOfAccountCategory> chartOfAccountCategory = chartOfAccountCategoryService.findAll();
response = transcationCategoryHelper.getCOACList(chartOfAccountCategory);
return new ResponseEntity(response, HttpStatus.OK);
}
catch (Exception e) {
logger.error(ERROR, e);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}