| Line 69... |
Line 69... |
| 69 |
private OrderRepository orderRepository;
|
69 |
private OrderRepository orderRepository;
|
| 70 |
@Autowired
|
70 |
@Autowired
|
| 71 |
private JavaMailSender mailSender;
|
71 |
private JavaMailSender mailSender;
|
| 72 |
|
72 |
|
| 73 |
public void dailyReconciliation() throws Exception {
|
73 |
public void dailyReconciliation() throws Exception {
|
| - |
|
74 |
LocalDate date = LocalDate.now().minusDays(1);
|
| - |
|
75 |
dailyReconciliation(date);
|
| - |
|
76 |
}
|
| - |
|
77 |
|
| - |
|
78 |
/*public void partnerDailyReconciliation(int fofoId) throws Exception {
|
| - |
|
79 |
LocalDate startDate = LocalDate.of(2018, Month.JANUARY, 1);
|
| - |
|
80 |
while(startDate.isBefore(LocalDate.now())) {
|
| - |
|
81 |
dailyReconciliation();
|
| - |
|
82 |
startDate.plusDays(1);
|
| - |
|
83 |
}
|
| - |
|
84 |
}*/
|
| - |
|
85 |
|
| - |
|
86 |
private void dailyReconciliation(LocalDate localDate) throws Exception {
|
| 74 |
Map<SchemeType, Set<Integer>> schemeTypeMap = schemeRepository.selectAll().stream()
|
87 |
Map<SchemeType, Set<Integer>> schemeTypeMap = schemeRepository.selectAll().stream()
|
| 75 |
.collect(Collectors.groupingBy(Scheme::getType, Collectors.mapping(Scheme::getId, Collectors.toSet())));
|
88 |
.collect(Collectors.groupingBy(Scheme::getType, Collectors.mapping(Scheme::getId, Collectors.toSet())));
|
| 76 |
boolean reconciled = true;
|
89 |
boolean reconciled = true;
|
| 77 |
Map<Integer, String> stores = fofoStoreRepository.getStoresMap();
|
90 |
Map<Integer, String> stores = fofoStoreRepository.getStoresMap();
|
| 78 |
List<List<? extends Serializable>> rows = new ArrayList<>();
|
91 |
List<List<? extends Serializable>> rows = new ArrayList<>();
|
| Line 92... |
Line 105... |
| 92 |
}
|
105 |
}
|
| 93 |
});
|
106 |
});
|
| 94 |
|
107 |
|
| 95 |
List<Serializable> reconciliation = new ArrayList<>();
|
108 |
List<Serializable> reconciliation = new ArrayList<>();
|
| 96 |
LocalDate dateToReconcile = yesterday;
|
109 |
LocalDate dateToReconcile = yesterday;
|
| - |
|
110 |
//"PartnerId", "Partner Name", "Reconciliation Date"
|
| 97 |
reconciliation.addAll(Arrays.asList(partnerId, retailerNameMap.get(partnerId), dateToReconcile));
|
111 |
reconciliation.addAll(Arrays.asList(partnerId, retailerNameMap.get(partnerId), dateToReconcile));
|
| 98 |
|
112 |
|
| 99 |
for (Map.Entry<WalletReferenceType, List<UserWalletHistory>> entry : referenceWiseWalletHistory
|
113 |
for (Map.Entry<WalletReferenceType, List<UserWalletHistory>> entry : referenceWiseWalletHistory
|
| 100 |
.entrySet()) {
|
114 |
.entrySet()) {
|
| 101 |
List<UserWalletHistory> history = entry.getValue();
|
115 |
List<UserWalletHistory> history = entry.getValue();
|
| 102 |
Map<Integer, Integer> referenceWalletMap = entry.getValue().stream().collect(
|
116 |
Map<Integer, Integer> referenceWalletMap = entry.getValue().stream().collect(
|
| 103 |
Collectors.groupingBy(x -> x.getReference(), Collectors.summingInt(x -> x.getAmount())));
|
117 |
Collectors.groupingBy(x -> x.getReference(), Collectors.summingInt(x -> x.getAmount())));
|
| 104 |
switch (entry.getKey()) {
|
118 |
switch (entry.getKey()) {
|
| 105 |
case PURCHASE:
|
119 |
case PURCHASE:
|
| 106 |
reconciliation.addAll(
|
120 |
reconciliation.addAll(
|
| 107 |
reconcileOrdersAndWallet(uw.getUserId(), dateToReconcile, referenceWalletMap, history));
|
121 |
reconcileOrdersAndWallet(dateToReconcile, referenceWalletMap, history));
|
| 108 |
break;
|
122 |
break;
|
| 109 |
case SCHEME_IN:
|
123 |
case SCHEME_IN:
|
| 110 |
reconciliation.addAll(reconcileSchemeInAndWallet(uw.getUserId(), dateToReconcile,
|
124 |
reconciliation.addAll(reconcileSchemeInAndWallet(dateToReconcile,
|
| 111 |
referenceWalletMap, history, schemeTypeMap.get(SchemeType.IN)));
|
125 |
referenceWalletMap, history, schemeTypeMap.get(SchemeType.IN)));
|
| 112 |
break;
|
126 |
break;
|
| 113 |
case SCHEME_OUT:
|
127 |
case SCHEME_OUT:
|
| 114 |
reconciliation.addAll(reconcileSchemeOutAndWallet(uw.getUserId(), dateToReconcile,
|
128 |
reconciliation.addAll(reconcileSchemeOutAndWallet(dateToReconcile,
|
| 115 |
referenceWalletMap, history, schemeTypeMap.get(SchemeType.OUT)));
|
129 |
referenceWalletMap, history, schemeTypeMap.get(SchemeType.OUT)));
|
| 116 |
break;
|
130 |
break;
|
| 117 |
default:
|
131 |
default:
|
| 118 |
break;
|
132 |
break;
|
| 119 |
|
133 |
|
| 120 |
}
|
134 |
}
|
| 121 |
}
|
135 |
}
|
| 122 |
reconciled = reconciled || Boolean.TRUE.equals(reconciliation.get(0));
|
136 |
reconciled = reconciled || Boolean.TRUE.equals(reconciliation.get(0));
|
| 123 |
rows.add(reconciliation);
|
137 |
rows.add(reconciliation);
|
| 124 |
}
|
138 |
}
|
| 125 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("PartnerId", "Store Name",
|
139 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| - |
|
140 |
Arrays.asList("PartnerId", "Partner Name", "Reconciliation Date",
|
| 126 |
"Reconciliation Date", "Purchase Reconciled", "Wallet amount consumed", "Ordered Total",
|
141 |
"Purchase Reconciled", "Wallet amount consumed", "Ordered Total", "Cancelled Total", "Refunded Total",
|
| 127 |
"Cancelled Total", "Refunded Total", "", "Scheme In to Wallet", "Scheme In disbursed",
|
142 |
"Scheme In Reconciled", "Scheme In to Wallet", "Scheme In disbursed", "Scheme In rolledback",
|
| 128 |
"Scheme In rolledback", "Scheme Out to Wallet", "Scheme Out Disbursed", "Scheme Out Rolledback"), rows);
|
143 |
"SchemeOut Reconciled", "Scheme Out to Wallet", "Scheme Out Disbursed", "Scheme Out Rolledback"), rows);
|
| 129 |
|
144 |
|
| 130 |
Utils.sendMailWithAttachment(mailSender, new String[] { "amit.gupta@shop2020.in" }, new String[] {},
|
145 |
Utils.sendMailWithAttachment(mailSender, new String[] { "amit.gupta@shop2020.in" }, new String[] {},
|
| 131 |
reconciled ? "Reconciled Successfully" : "Reconciliation failed", "Report attached",
|
146 |
reconciled ? "Reconciled Successfully" : "Reconciliation failed", "Report attached",
|
| 132 |
String.format("reconciliation-%s.csv", FormattingUtils.formatDate(yesterday.atStartOfDay())),
|
147 |
String.format("reconciliation-%s.csv", FormattingUtils.formatDate(yesterday.atStartOfDay())),
|
| 133 |
new ByteArrayResource(baos.toByteArray()));
|
148 |
new ByteArrayResource(baos.toByteArray()));
|
| 134 |
}
|
149 |
}
|
| 135 |
|
150 |
|
| 136 |
private List<? extends Serializable> reconcileOrdersAndWallet(int fofoId, LocalDate localDate,
|
151 |
private List<? extends Serializable> reconcileOrdersAndWallet(LocalDate localDate,
|
| 137 |
Map<Integer, Integer> transactionsOnThatDate, List<UserWalletHistory> history) throws Exception {
|
152 |
Map<Integer, Integer> transactionsOnThatDate, List<UserWalletHistory> history) throws Exception {
|
| 138 |
|
153 |
|
| 139 |
int totalWalletConsumed = 0;
|
154 |
int totalWalletConsumed = 0;
|
| 140 |
float cancelledAmount = 0;
|
155 |
float cancelledAmount = 0;
|
| 141 |
float returnedAmount = 0;
|
156 |
float returnedAmount = 0;
|
| Line 175... |
Line 190... |
| 175 |
|
190 |
|
| 176 |
return Arrays.asList(reconciled, totalWalletConsumed, totalDeductedAmount, cancelledAmount, returnedAmount, "");
|
191 |
return Arrays.asList(reconciled, totalWalletConsumed, totalDeductedAmount, cancelledAmount, returnedAmount, "");
|
| 177 |
|
192 |
|
| 178 |
}
|
193 |
}
|
| 179 |
|
194 |
|
| 180 |
private List<? extends Serializable> reconcileSchemeInAndWallet(int fofoId, LocalDate localDate,
|
195 |
private List<? extends Serializable> reconcileSchemeInAndWallet(LocalDate localDate,
|
| 181 |
Map<Integer, Integer> transactionsOnThatDate, List<UserWalletHistory> history, Set<Integer> schemeIds) {
|
196 |
Map<Integer, Integer> transactionsOnThatDate, List<UserWalletHistory> history, Set<Integer> schemeIds) {
|
| 182 |
|
197 |
|
| 183 |
int totalSchemeInWalletCredited = 0;
|
198 |
int totalSchemeInWalletCredited = 0;
|
| 184 |
float schemeInAmountAdded = 0;
|
199 |
float schemeInAmountAdded = 0;
|
| 185 |
float schemeInAmountRolledBack = 0;
|
200 |
float schemeInAmountRolledBack = 0;
|
| Line 207... |
Line 222... |
| 207 |
return Arrays.asList(reconciled, totalSchemeInWalletCredited, schemeInAmountAdded, schemeInAmountRolledBack,
|
222 |
return Arrays.asList(reconciled, totalSchemeInWalletCredited, schemeInAmountAdded, schemeInAmountRolledBack,
|
| 208 |
"");
|
223 |
"");
|
| 209 |
|
224 |
|
| 210 |
}
|
225 |
}
|
| 211 |
|
226 |
|
| 212 |
private List<? extends Serializable> reconcileSchemeOutAndWallet(int fofoId, LocalDate localDate,
|
227 |
private List<? extends Serializable> reconcileSchemeOutAndWallet(LocalDate localDate,
|
| 213 |
Map<Integer, Integer> transactionsOnThatDate, List<UserWalletHistory> history, Set<Integer> schemeIds) {
|
228 |
Map<Integer, Integer> transactionsOnThatDate, List<UserWalletHistory> history, Set<Integer> schemeIds) {
|
| 214 |
int totalSchemeOutWalletCredited = 0;
|
229 |
int totalSchemeOutWalletCredited = 0;
|
| 215 |
float schemeOutAmountAdded = 0;
|
230 |
float schemeOutAmountAdded = 0;
|
| 216 |
float schemeOutAmountRolledBack = 0;
|
231 |
float schemeOutAmountRolledBack = 0;
|
| 217 |
for (int fofoOrderId : transactionsOnThatDate.keySet()) {
|
232 |
for (int fofoOrderId : transactionsOnThatDate.keySet()) {
|