| Line 841... |
Line 841... |
| 841 |
}
|
841 |
}
|
| 842 |
|
842 |
|
| 843 |
@Autowired
|
843 |
@Autowired
|
| 844 |
CreditNoteService creditNoteService;
|
844 |
CreditNoteService creditNoteService;
|
| 845 |
|
845 |
|
| - |
|
846 |
@Autowired
|
| - |
|
847 |
com.spice.profitmandi.dao.repository.transaction.CreditNoteRepository creditNoteRepository;
|
| - |
|
848 |
|
| 846 |
public void sendCreditNote(YearMonth yearMonth) throws Exception {
|
849 |
public void sendCreditNote(YearMonth yearMonth) throws Exception {
|
| 847 |
LOGGER.info("Running SendCreditNote for {}", yearMonth.toString());
|
850 |
LOGGER.info("Running SendCreditNote for {}", yearMonth.toString());
|
| 848 |
creditNoteService.issueMonthlyMarginsCN(yearMonth);
|
851 |
creditNoteService.issueMonthlyMarginsCN(yearMonth);
|
| 849 |
}
|
852 |
}
|
| 850 |
|
853 |
|
| Line 861... |
Line 864... |
| 861 |
public void genDNs(YearMonth yearMonth) throws Exception {
|
864 |
public void genDNs(YearMonth yearMonth) throws Exception {
|
| 862 |
LOGGER.info("Running genDNs for {}", yearMonth.toString());
|
865 |
LOGGER.info("Running genDNs for {}", yearMonth.toString());
|
| 863 |
creditNoteService.generateDebitNotesForCancelled(yearMonth);
|
866 |
creditNoteService.generateDebitNotesForCancelled(yearMonth);
|
| 864 |
}
|
867 |
}
|
| 865 |
|
868 |
|
| - |
|
869 |
public void testReissueOneCN() throws Exception {
|
| - |
|
870 |
YearMonth marginMonth = YearMonth.of(2026, 3);
|
| - |
|
871 |
java.time.LocalDate bookDate = java.time.LocalDate.of(2026, 3, 31);
|
| - |
|
872 |
String suffix = "/A";
|
| - |
|
873 |
|
| - |
|
874 |
java.util.List<com.spice.profitmandi.dao.entity.transaction.CreditNote> allCNs =
|
| - |
|
875 |
creditNoteRepository.selectAllMarginsTypeByMonth(marginMonth);
|
| - |
|
876 |
LOGGER.info("testReissueOneCN: found {} non-cancelled MARGINS CNs for {}", allCNs.size(), marginMonth);
|
| - |
|
877 |
|
| - |
|
878 |
// Pick first non-Delhi CN for testing
|
| - |
|
879 |
com.spice.profitmandi.dao.entity.transaction.CreditNote testCN = null;
|
| - |
|
880 |
for (com.spice.profitmandi.dao.entity.transaction.CreditNote cn : allCNs) {
|
| - |
|
881 |
String prefix = cn.getCreditNoteNumber().substring(3).replaceAll("\\d", "");
|
| - |
|
882 |
if (!prefix.startsWith("NSDL")) {
|
| - |
|
883 |
testCN = cn;
|
| - |
|
884 |
break;
|
| - |
|
885 |
}
|
| - |
|
886 |
}
|
| - |
|
887 |
if (testCN == null) {
|
| - |
|
888 |
throw new RuntimeException("No non-Delhi CN found for testing");
|
| - |
|
889 |
}
|
| - |
|
890 |
LOGGER.info("testReissueOneCN: testing with CN={} fofoId={}", testCN.getCreditNoteNumber(), testCN.getFofoId());
|
| - |
|
891 |
|
| - |
|
892 |
// Override partner email to send to sdtech for testing
|
| - |
|
893 |
creditNoteService.reissueMarginsCN(marginMonth, bookDate, suffix, testCN.getId(), "sdtech@smartdukaan.com");
|
| - |
|
894 |
}
|
| - |
|
895 |
|
| - |
|
896 |
public void reissueMarginsCN() throws Exception {
|
| - |
|
897 |
YearMonth marginMonth = YearMonth.of(2026, 3);
|
| - |
|
898 |
java.time.LocalDate bookDate = java.time.LocalDate.of(2026, 3, 31);
|
| - |
|
899 |
String suffix = "/A";
|
| - |
|
900 |
|
| - |
|
901 |
java.util.List<com.spice.profitmandi.dao.entity.transaction.CreditNote> existing =
|
| - |
|
902 |
creditNoteRepository.selectAllMarginsTypeByMonth(marginMonth);
|
| - |
|
903 |
LOGGER.info("reissueMarginsCN: found {} non-cancelled MARGINS CNs for {}", existing.size(), marginMonth);
|
| - |
|
904 |
|
| - |
|
905 |
creditNoteService.reissueMarginsCN(marginMonth, bookDate, suffix);
|
| - |
|
906 |
}
|
| - |
|
907 |
|
| 866 |
@Autowired
|
908 |
@Autowired
|
| 867 |
BrandAgeingLimitRepository brandAgeingLimitRepository;
|
909 |
BrandAgeingLimitRepository brandAgeingLimitRepository;
|
| 868 |
|
910 |
|
| 869 |
@Autowired
|
911 |
@Autowired
|
| 870 |
AgeingService ageingService;
|
912 |
AgeingService ageingService;
|
| Line 1260... |
Line 1302... |
| 1260 |
|
1302 |
|
| 1261 |
//System.out.println(trialFormRepository.selectByEmailOrMobile("9990381568"));
|
1303 |
//System.out.println(trialFormRepository.selectByEmailOrMobile("9990381568"));
|
| 1262 |
/*CreditBlockedExceptionPartner creditBlockedExceptionPartner = creditBlockedExceptionPartnersRepository.select(175139430);
|
1304 |
/*CreditBlockedExceptionPartner creditBlockedExceptionPartner = creditBlockedExceptionPartnersRepository.select(175139430);
|
| 1263 |
System.out.println(creditBlockedExceptionPartner);*/
|
1305 |
System.out.println(creditBlockedExceptionPartner);*/
|
| 1264 |
//this.updatePartnerLimit(175139595);
|
1306 |
//this.updatePartnerLimit(175139595);
|
| - |
|
1307 |
this.fixStuckLimitBlocks(9999);
|
| 1265 |
this.regenerateDCInvoices();
|
1308 |
//this.regenerateDCInvoices();
|
| 1266 |
//this.releaseBlockedLimit();
|
1309 |
//this.releaseBlockedLimit();
|
| 1267 |
//sdCreditService.resetHardLimit();
|
1310 |
//sdCreditService.resetHardLimit();
|
| 1268 |
//migrations.migrateSerialInvoiceMap();
|
1311 |
//migrations.migrateSerialInvoiceMap();
|
| 1269 |
//runOnceTasks.checkRewardsEligibility();
|
1312 |
//runOnceTasks.checkRewardsEligibility();
|
| 1270 |
//hybridEncryptor.getJwt();
|
1313 |
//hybridEncryptor.getJwt();
|
| Line 1363... |
Line 1406... |
| 1363 |
|
1406 |
|
| 1364 |
|
1407 |
|
| 1365 |
}
|
1408 |
}
|
| 1366 |
}
|
1409 |
}
|
| 1367 |
|
1410 |
|
| - |
|
1411 |
private void fixStuckLimitBlocks(int maxFixes) {
|
| - |
|
1412 |
LocalDate fromDate = LocalDate.of(2026, 4, 27);
|
| - |
|
1413 |
LocalDate toDate = LocalDate.of(2026, 4, 29);
|
| - |
|
1414 |
|
| - |
|
1415 |
List<Loan> allBlockedLoans = loanRepository.selectAllBlockedLoans();
|
| - |
|
1416 |
List<Loan> stuckLoans = allBlockedLoans.stream()
|
| - |
|
1417 |
.filter(l -> {
|
| - |
|
1418 |
LocalDate created = l.getCreatedOn().toLocalDate();
|
| - |
|
1419 |
return !created.isBefore(fromDate) && !created.isAfter(toDate);
|
| - |
|
1420 |
})
|
| - |
|
1421 |
.collect(toList());
|
| - |
|
1422 |
|
| - |
|
1423 |
System.out.println("Found " + stuckLoans.size() + " stuck limit blocks between " + fromDate + " and " + toDate);
|
| - |
|
1424 |
System.out.println("Max fixes this run: " + maxFixes);
|
| - |
|
1425 |
|
| - |
|
1426 |
int fixed = 0, skipped = 0, failed = 0;
|
| - |
|
1427 |
for (Loan blockedLoan : stuckLoans) {
|
| - |
|
1428 |
if (fixed >= maxFixes) {
|
| - |
|
1429 |
System.out.println("Reached max fixes limit (" + maxFixes + "), stopping.");
|
| - |
|
1430 |
break;
|
| - |
|
1431 |
}
|
| - |
|
1432 |
|
| - |
|
1433 |
try {
|
| - |
|
1434 |
LoanTransaction loanTransaction = loanTransactionRepository.selectByLoanId(blockedLoan.getId());
|
| - |
|
1435 |
if (loanTransaction == null) {
|
| - |
|
1436 |
System.out.println("SKIP loan " + blockedLoan.getId() + " - no LoanTransaction found");
|
| - |
|
1437 |
skipped++;
|
| - |
|
1438 |
continue;
|
| - |
|
1439 |
}
|
| - |
|
1440 |
int transactionId = loanTransaction.getTransactionId();
|
| - |
|
1441 |
List<Order> billedOrders = orderRepository.selectAllByTransactionId(transactionId).stream()
|
| - |
|
1442 |
.filter(o -> o.getBillingTimestamp() != null && o.getRefundTimestamp() == null)
|
| - |
|
1443 |
.collect(toList());
|
| - |
|
1444 |
|
| - |
|
1445 |
if (billedOrders.isEmpty()) {
|
| - |
|
1446 |
System.out.println("SKIP loan " + blockedLoan.getId() + " txn " + transactionId + " - no billed orders");
|
| - |
|
1447 |
skipped++;
|
| - |
|
1448 |
continue;
|
| - |
|
1449 |
}
|
| - |
|
1450 |
|
| - |
|
1451 |
Map<String, List<Order>> byInvoice = billedOrders.stream()
|
| - |
|
1452 |
.filter(o -> o.getInvoiceNumber() != null)
|
| - |
|
1453 |
.collect(Collectors.groupingBy(Order::getInvoiceNumber));
|
| - |
|
1454 |
|
| - |
|
1455 |
for (Map.Entry<String, List<Order>> entry : byInvoice.entrySet()) {
|
| - |
|
1456 |
String invoiceNumber = entry.getKey();
|
| - |
|
1457 |
double invoiceAmount = entry.getValue().stream().mapToDouble(Order::getWalletAmount).sum();
|
| - |
|
1458 |
|
| - |
|
1459 |
Loan existingLoan = loanRepository.selectLoanByInvoice(invoiceNumber);
|
| - |
|
1460 |
if (existingLoan != null) {
|
| - |
|
1461 |
System.out.println("SKIP loan " + blockedLoan.getId() + " invoice " + invoiceNumber + " - loan already exists (id=" + existingLoan.getId() + ")");
|
| - |
|
1462 |
continue;
|
| - |
|
1463 |
}
|
| - |
|
1464 |
|
| - |
|
1465 |
System.out.println("FIX loan " + blockedLoan.getId() + " fofo " + blockedLoan.getFofoId() + " txn " + transactionId + " invoice " + invoiceNumber + " invoiceAmt " + invoiceAmount + " pending " + blockedLoan.getPendingAmount());
|
| - |
|
1466 |
sdCreditService.createLoanForBilling(transactionId, invoiceAmount, invoiceNumber);
|
| - |
|
1467 |
fixed++;
|
| - |
|
1468 |
}
|
| - |
|
1469 |
} catch (Exception e) {
|
| - |
|
1470 |
System.out.println("FAIL loan " + blockedLoan.getId() + " fofo " + blockedLoan.getFofoId() + " - " + e.getMessage());
|
| - |
|
1471 |
e.printStackTrace();
|
| - |
|
1472 |
failed++;
|
| - |
|
1473 |
}
|
| - |
|
1474 |
}
|
| - |
|
1475 |
System.out.println("Done. fixed=" + fixed + " skipped=" + skipped + " failed=" + failed);
|
| - |
|
1476 |
}
|
| - |
|
1477 |
|
| - |
|
1478 |
private void compensateAlreadyFixedLoans() {
|
| - |
|
1479 |
int[] alreadyFixedLoanIds = {106138, 106139, 106140, 106141, 106142, 106143, 106144, 106145, 106146, 106147};
|
| - |
|
1480 |
System.out.println("Compensating " + alreadyFixedLoanIds.length + " already-fixed loans");
|
| - |
|
1481 |
|
| - |
|
1482 |
int done = 0, failed = 0;
|
| - |
|
1483 |
for (int loanId : alreadyFixedLoanIds) {
|
| - |
|
1484 |
try {
|
| - |
|
1485 |
Loan loan = loanRepository.selectByLoanId(loanId);
|
| - |
|
1486 |
if (loan == null) {
|
| - |
|
1487 |
System.out.println("SKIP compensate loan " + loanId + " - not found");
|
| - |
|
1488 |
continue;
|
| - |
|
1489 |
}
|
| - |
|
1490 |
double compensateAmount = loan.getIntialAmount().doubleValue();
|
| - |
|
1491 |
String compensateDesc = "Compensating double credit - forced loan " + loan.getId() + " against invoice " + loan.getInvoiceNumber();
|
| - |
|
1492 |
walletService.consumeAmountFromWallet(loan.getFofoId(), loan.getId(),
|
| - |
|
1493 |
WalletReferenceType.CREDIT_UTILIZED, compensateDesc, (float) compensateAmount, LocalDateTime.now());
|
| - |
|
1494 |
System.out.println("COMPENSATE fofo " + loan.getFofoId() + " loan " + loan.getId() + " amount -" + compensateAmount);
|
| - |
|
1495 |
|
| - |
|
1496 |
String forcedLoanReason = "Forced loan against invoice " + loan.getInvoiceNumber() + " (limit fix)";
|
| - |
|
1497 |
Loan forcedLoan = sdCreditService.createLoan(loan.getFofoId(), compensateAmount, loan.getFreeDays(), forcedLoanReason);
|
| - |
|
1498 |
System.out.println("FORCED LOAN fofo " + loan.getFofoId() + " loan " + forcedLoan.getId() + " amount " + compensateAmount + " freeDays " + loan.getFreeDays());
|
| - |
|
1499 |
done++;
|
| - |
|
1500 |
} catch (Exception e) {
|
| - |
|
1501 |
System.out.println("FAIL compensate loan " + loanId + " - " + e.getMessage());
|
| - |
|
1502 |
e.printStackTrace();
|
| - |
|
1503 |
failed++;
|
| - |
|
1504 |
}
|
| - |
|
1505 |
}
|
| - |
|
1506 |
System.out.println("Compensate done. done=" + done + " failed=" + failed);
|
| - |
|
1507 |
}
|
| - |
|
1508 |
|
| 1368 |
public static byte[] toByteArray(InputStream input) throws IOException {
|
1509 |
public static byte[] toByteArray(InputStream input) throws IOException {
|
| 1369 |
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
1510 |
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
| 1370 |
int nRead;
|
1511 |
int nRead;
|
| 1371 |
byte[] data = new byte[16384];
|
1512 |
byte[] data = new byte[16384];
|
| 1372 |
while ((nRead = input.read(data, 0, data.length)) != -1) {
|
1513 |
while ((nRead = input.read(data, 0, data.length)) != -1) {
|