| 23724 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled;
|
| 23723 |
amit.gupta |
2 |
|
| 24121 |
govind |
3 |
import java.io.IOException;
|
|
|
4 |
import java.io.InputStream;
|
| 23739 |
amit.gupta |
5 |
import java.sql.Timestamp;
|
| 24174 |
govind |
6 |
import java.text.MessageFormat;
|
| 23724 |
amit.gupta |
7 |
import java.time.LocalDate;
|
|
|
8 |
import java.time.LocalDateTime;
|
| 24256 |
amit.gupta |
9 |
import java.time.LocalTime;
|
| 23724 |
amit.gupta |
10 |
import java.time.temporal.ChronoUnit;
|
|
|
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Arrays;
|
| 23723 |
amit.gupta |
13 |
import java.util.HashMap;
|
| 24241 |
amit.gupta |
14 |
import java.util.HashSet;
|
| 23724 |
amit.gupta |
15 |
import java.util.List;
|
| 23723 |
amit.gupta |
16 |
import java.util.Map;
|
| 24242 |
amit.gupta |
17 |
import java.util.Optional;
|
| 24542 |
amit.gupta |
18 |
import java.util.Set;
|
| 23724 |
amit.gupta |
19 |
import java.util.stream.Collectors;
|
| 23723 |
amit.gupta |
20 |
|
| 24121 |
govind |
21 |
import javax.mail.MessagingException;
|
|
|
22 |
import javax.mail.internet.InternetAddress;
|
|
|
23 |
import javax.mail.internet.MimeMessage;
|
|
|
24 |
|
|
|
25 |
import org.apache.commons.codec.CharEncoding;
|
|
|
26 |
import org.apache.commons.io.IOUtils;
|
| 23929 |
amit.gupta |
27 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 23755 |
amit.gupta |
28 |
import org.apache.logging.log4j.LogManager;
|
|
|
29 |
import org.apache.logging.log4j.Logger;
|
| 24184 |
govind |
30 |
import org.apache.poi.EncryptedDocumentException;
|
|
|
31 |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
| 23723 |
amit.gupta |
32 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23933 |
amit.gupta |
33 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23724 |
amit.gupta |
34 |
import org.springframework.beans.factory.annotation.Value;
|
| 23929 |
amit.gupta |
35 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
36 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24121 |
govind |
37 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23723 |
amit.gupta |
38 |
import org.springframework.stereotype.Component;
|
| 23724 |
amit.gupta |
39 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
40 |
|
| 24542 |
amit.gupta |
41 |
import com.google.common.collect.Lists;
|
| 23724 |
amit.gupta |
42 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24121 |
govind |
43 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23929 |
amit.gupta |
44 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24542 |
amit.gupta |
45 |
import com.spice.profitmandi.common.model.GstRate;
|
| 23724 |
amit.gupta |
46 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 24002 |
amit.gupta |
47 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
48 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
49 |
import com.spice.profitmandi.common.util.Utils;
|
| 24533 |
govind |
50 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
|
|
51 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| 23724 |
amit.gupta |
52 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
|
|
53 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
54 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
|
|
55 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 24542 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 23724 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 24542 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 23929 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24249 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24277 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 24174 |
govind |
62 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 23724 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24174 |
govind |
64 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
| 24242 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 24241 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 24431 |
amit.gupta |
67 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 24580 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 24542 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 24250 |
amit.gupta |
70 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 24242 |
amit.gupta |
71 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 24533 |
govind |
72 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 24249 |
amit.gupta |
73 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24241 |
amit.gupta |
74 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 24533 |
govind |
75 |
import com.spice.profitmandi.dao.repository.cs.TicketAssignedRepository;
|
|
|
76 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
| 23724 |
amit.gupta |
77 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 23929 |
amit.gupta |
78 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23724 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
|
|
80 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
81 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24542 |
amit.gupta |
82 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
|
|
83 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
|
|
84 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 23724 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 24249 |
amit.gupta |
86 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24277 |
amit.gupta |
87 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24174 |
govind |
88 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 23724 |
amit.gupta |
89 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24242 |
amit.gupta |
90 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 24241 |
amit.gupta |
91 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23929 |
amit.gupta |
92 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 24431 |
amit.gupta |
93 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 24580 |
amit.gupta |
94 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 24542 |
amit.gupta |
95 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 24337 |
amit.gupta |
96 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23929 |
amit.gupta |
97 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24271 |
amit.gupta |
98 |
import com.spice.profitmandi.service.order.OrderService;
|
| 24431 |
amit.gupta |
99 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
100 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
101 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
102 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 24121 |
govind |
103 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23929 |
amit.gupta |
104 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
105 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
106 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23723 |
amit.gupta |
107 |
|
| 24197 |
amit.gupta |
108 |
import in.shop2020.model.v1.order.WalletReferenceType;;
|
| 23739 |
amit.gupta |
109 |
|
| 23723 |
amit.gupta |
110 |
@Component
|
| 23724 |
amit.gupta |
111 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
112 |
public class ScheduledTasks {
|
|
|
113 |
|
| 24533 |
govind |
114 |
private static final String Escalate_TICKET = "Dear {0},Your Ticket created by {1} is escalated and assigned to {2}. Regards \nSmartdukaan";
|
|
|
115 |
|
| 23724 |
amit.gupta |
116 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
117 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
118 |
|
| 23724 |
amit.gupta |
119 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
120 |
private String oxigenRechargeEnquiryUrl;
|
| 24533 |
govind |
121 |
|
| 24431 |
amit.gupta |
122 |
@Autowired
|
|
|
123 |
private PriceDropService priceDropService;
|
| 23723 |
amit.gupta |
124 |
|
| 23724 |
amit.gupta |
125 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
126 |
private String oxigenRechargeAuthKey;
|
|
|
127 |
|
|
|
128 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
129 |
private String oxigenRechargeValidationUrl;
|
|
|
130 |
|
|
|
131 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
132 |
private String oxigenRechargeValidationAuthKey;
|
|
|
133 |
|
|
|
134 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
135 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
136 |
|
|
|
137 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
138 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
139 |
|
|
|
140 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
141 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
142 |
|
|
|
143 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
144 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
145 |
|
|
|
146 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
147 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
148 |
|
|
|
149 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
150 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
151 |
|
|
|
152 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
153 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
154 |
|
| 23723 |
amit.gupta |
155 |
@Autowired
|
| 23724 |
amit.gupta |
156 |
private PurchaseRepository purchaseRepository;
|
|
|
157 |
|
|
|
158 |
@Autowired
|
|
|
159 |
private SchemeService schemeService;
|
|
|
160 |
|
|
|
161 |
@Autowired
|
| 24271 |
amit.gupta |
162 |
private OrderService orderService;
|
|
|
163 |
|
|
|
164 |
@Autowired
|
| 24337 |
amit.gupta |
165 |
private PartnerInvestmentService partnerInvestmentService;
|
|
|
166 |
|
|
|
167 |
@Autowired
|
| 24542 |
amit.gupta |
168 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
169 |
|
|
|
170 |
@Autowired
|
| 24277 |
amit.gupta |
171 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
172 |
|
|
|
173 |
@Autowired
|
| 24241 |
amit.gupta |
174 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
175 |
|
|
|
176 |
@Autowired
|
| 23724 |
amit.gupta |
177 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
178 |
|
|
|
179 |
@Autowired
|
| 24542 |
amit.gupta |
180 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
181 |
|
|
|
182 |
@Autowired
|
| 23724 |
amit.gupta |
183 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
184 |
|
|
|
185 |
@Autowired
|
|
|
186 |
private FofoOrderRepository fofoOrderRepository;
|
| 24580 |
amit.gupta |
187 |
|
|
|
188 |
@Autowired
|
|
|
189 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 24250 |
amit.gupta |
190 |
|
| 24249 |
amit.gupta |
191 |
@Autowired
|
|
|
192 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
193 |
|
| 23739 |
amit.gupta |
194 |
@Autowired
|
|
|
195 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
196 |
|
|
|
197 |
@Autowired
|
|
|
198 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
199 |
|
|
|
200 |
@Autowired
|
|
|
201 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
202 |
|
|
|
203 |
@Autowired
|
|
|
204 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
205 |
|
|
|
206 |
@Autowired
|
| 24242 |
amit.gupta |
207 |
private ScanRecordRepository scanRecordRepository;
|
|
|
208 |
|
|
|
209 |
@Autowired
|
| 23724 |
amit.gupta |
210 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
211 |
|
| 23929 |
amit.gupta |
212 |
@Autowired
|
|
|
213 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
214 |
|
| 24121 |
govind |
215 |
@Autowired
|
|
|
216 |
private TargetSlabService targetService;
|
| 23929 |
amit.gupta |
217 |
|
| 23724 |
amit.gupta |
218 |
@Value("${prod}")
|
|
|
219 |
private boolean prod;
|
|
|
220 |
|
| 23929 |
amit.gupta |
221 |
@Autowired
|
|
|
222 |
private RetailerService retailerService;
|
|
|
223 |
|
|
|
224 |
@Autowired
|
|
|
225 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
226 |
|
| 24249 |
amit.gupta |
227 |
@Autowired
|
|
|
228 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
229 |
|
|
|
230 |
@Autowired
|
|
|
231 |
private OrderRepository orderRepository;
|
|
|
232 |
|
|
|
233 |
@Autowired
|
| 24241 |
amit.gupta |
234 |
private SchemeRepository schemeRepository;
|
|
|
235 |
|
|
|
236 |
@Autowired
|
| 23929 |
amit.gupta |
237 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
238 |
|
| 24174 |
govind |
239 |
@Autowired
|
| 24431 |
amit.gupta |
240 |
private PriceDropRepository priceDropRepository;
|
|
|
241 |
|
|
|
242 |
@Autowired
|
| 24174 |
govind |
243 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
244 |
|
|
|
245 |
@Autowired
|
|
|
246 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
247 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
248 |
|
|
|
249 |
@Autowired
|
|
|
250 |
private InventoryService inventoryService;
|
|
|
251 |
|
| 24533 |
govind |
252 |
@Autowired
|
|
|
253 |
private TicketRepository ticketRepository;
|
|
|
254 |
|
|
|
255 |
@Autowired
|
|
|
256 |
private TicketAssignedRepository ticketAssignedRepository;
|
|
|
257 |
|
|
|
258 |
@Autowired
|
|
|
259 |
private AuthRepository authRepository;
|
|
|
260 |
|
| 24542 |
amit.gupta |
261 |
@Autowired
|
|
|
262 |
private AddressRepository addressRepository;
|
|
|
263 |
|
|
|
264 |
@Autowired
|
|
|
265 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
266 |
|
| 23755 |
amit.gupta |
267 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
268 |
|
|
|
269 |
public void generateDailyRecharge() {
|
|
|
270 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
271 |
.selectAll(0, 2000);
|
|
|
272 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
273 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
274 |
|
|
|
275 |
rechargeProviders.stream().forEach(x -> {
|
|
|
276 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
277 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
278 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
279 |
|
|
|
280 |
LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
|
|
|
281 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
282 |
float previousDayClosing = 0;
|
|
|
283 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
284 |
while (date.isBefore(endDate)) {
|
|
|
285 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
286 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
287 |
date.plusDays(1).atStartOfDay());
|
|
|
288 |
|
|
|
289 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
290 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
291 |
|
|
|
292 |
float dailyAmount = 0;
|
|
|
293 |
float totalCommission = 0;
|
|
|
294 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
295 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
296 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
297 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
298 |
}
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
302 |
float dailyWalletRecharge = 0;
|
|
|
303 |
if (rechargeHistoryList != null) {
|
|
|
304 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
305 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
306 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
307 |
}
|
|
|
308 |
}
|
|
|
309 |
}
|
|
|
310 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
311 |
DailyRecharge dailyRecharge = null;
|
|
|
312 |
try {
|
|
|
313 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
314 |
} catch (Exception e) {
|
|
|
315 |
LOGGER.info("Could not find Recharge entry");
|
|
|
316 |
}
|
|
|
317 |
if (dailyRecharge == null) {
|
|
|
318 |
dailyRecharge = new DailyRecharge();
|
|
|
319 |
dailyRecharge.setCreateDate(date);
|
|
|
320 |
}
|
|
|
321 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
322 |
dailyRecharge.setProviderId(x.getId());
|
|
|
323 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
324 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
325 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
326 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
327 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
328 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
329 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
330 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
331 |
}
|
|
|
332 |
date = date.plusDays(1);
|
|
|
333 |
}
|
|
|
334 |
rechargeProviderRepository.persist(x);
|
|
|
335 |
});
|
| 23761 |
amit.gupta |
336 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
337 |
}
|
|
|
338 |
|
| 23738 |
amit.gupta |
339 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
340 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
341 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
342 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
343 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
344 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
345 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
346 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
347 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
348 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
349 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
350 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
351 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
352 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
353 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
354 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
355 |
try {
|
|
|
356 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
357 |
if (providerId == 1) {
|
|
|
358 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
359 |
rechargeTransaction);
|
|
|
360 |
} else if (providerId == 2) {
|
|
|
361 |
thinkWalnutDigitalRechargeProviderService
|
|
|
362 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
363 |
}
|
|
|
364 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
365 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
366 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
367 |
rechargeTransaction.getStatus());
|
|
|
368 |
}
|
|
|
369 |
} catch (Exception e) {
|
|
|
370 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
371 |
}
|
|
|
372 |
}
|
| 23738 |
amit.gupta |
373 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
374 |
}
|
| 24240 |
amit.gupta |
375 |
|
|
|
376 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
377 |
public void migrateInvoice() {
|
|
|
378 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
379 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
380 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
381 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
382 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
383 |
int sequence = 0;
|
|
|
384 |
String prefix = "";
|
| 24241 |
amit.gupta |
385 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
386 |
.collect(Collectors.toList());
|
|
|
387 |
for (FofoOrder order : sortedList) {
|
|
|
388 |
|
| 24240 |
amit.gupta |
389 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
390 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
391 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
392 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
393 |
} else {
|
|
|
394 |
sequence += 1;
|
| 24241 |
amit.gupta |
395 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
396 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
397 |
fofoOrderRepository.persist(order);
|
|
|
398 |
}
|
|
|
399 |
}
|
| 24241 |
amit.gupta |
400 |
|
| 24237 |
amit.gupta |
401 |
}
|
|
|
402 |
}
|
| 23724 |
amit.gupta |
403 |
|
| 24241 |
amit.gupta |
404 |
// Temporary Method
|
| 24252 |
amit.gupta |
405 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 24244 |
amit.gupta |
406 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
407 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 24252 |
amit.gupta |
408 |
|
|
|
409 |
List<List<Object>> rows = new ArrayList<>();
|
| 24271 |
amit.gupta |
410 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
411 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 24241 |
amit.gupta |
412 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 24250 |
amit.gupta |
413 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
414 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
415 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
416 |
if (x.getActiveTimestamp() != null) {
|
|
|
417 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
418 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
419 |
endDateTime = x.getExpireTimestamp();
|
| 24249 |
amit.gupta |
420 |
}
|
| 24250 |
amit.gupta |
421 |
for (SchemeInOut sio : sioList) {
|
|
|
422 |
InventoryItem inventoryItem = null;
|
| 24266 |
amit.gupta |
423 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 24271 |
amit.gupta |
424 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
425 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 24250 |
amit.gupta |
426 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
427 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
428 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
429 |
if (record.isPresent()) {
|
|
|
430 |
int fofoId = record.get().getFofoId();
|
|
|
431 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
432 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
433 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
434 |
userAmountMap.put(fofoId, 0f);
|
|
|
435 |
}
|
|
|
436 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
437 |
try {
|
| 24252 |
amit.gupta |
438 |
rows.add(Arrays.asList(x.getDescription(),
|
| 24250 |
amit.gupta |
439 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 24252 |
amit.gupta |
440 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 24253 |
amit.gupta |
441 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
442 |
fofoOrder.getInvoiceNumber(),
|
|
|
443 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
444 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
445 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
446 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
447 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 24250 |
amit.gupta |
448 |
} catch (Exception e) {
|
|
|
449 |
e.printStackTrace();
|
|
|
450 |
}
|
| 24242 |
amit.gupta |
451 |
}
|
| 24241 |
amit.gupta |
452 |
}
|
|
|
453 |
}
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
});
|
| 24246 |
amit.gupta |
457 |
userAmountMap.entrySet().stream()
|
|
|
458 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
459 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 24241 |
amit.gupta |
460 |
|
| 24252 |
amit.gupta |
461 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
462 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
463 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
|
|
464 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 24252 |
amit.gupta |
465 |
|
| 24241 |
amit.gupta |
466 |
}
|
| 24271 |
amit.gupta |
467 |
|
| 24256 |
amit.gupta |
468 |
public void processScheme(int offset) throws Exception {
|
| 24462 |
amit.gupta |
469 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24259 |
amit.gupta |
470 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 24258 |
amit.gupta |
471 |
processScheme(startDate, endDate);
|
| 24256 |
amit.gupta |
472 |
}
|
| 24533 |
govind |
473 |
|
| 24461 |
amit.gupta |
474 |
public void processScheme(int offset, int durationDays) throws Exception {
|
| 24462 |
amit.gupta |
475 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24461 |
amit.gupta |
476 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
|
|
477 |
processScheme(startDate, endDate);
|
|
|
478 |
}
|
| 24271 |
amit.gupta |
479 |
|
| 23738 |
amit.gupta |
480 |
public void processScheme() throws Exception {
|
| 24256 |
amit.gupta |
481 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
|
|
482 |
processScheme(fromDate, LocalDateTime.now());
|
|
|
483 |
}
|
| 24271 |
amit.gupta |
484 |
|
| 24256 |
amit.gupta |
485 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
|
| 23724 |
amit.gupta |
486 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 24561 |
amit.gupta |
487 |
try {
|
| 24256 |
amit.gupta |
488 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
| 23724 |
amit.gupta |
489 |
for (Purchase purchase : purchases) {
|
| 24561 |
amit.gupta |
490 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
491 |
}
|
| 24271 |
amit.gupta |
492 |
|
| 24256 |
amit.gupta |
493 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
| 23724 |
amit.gupta |
494 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 24561 |
amit.gupta |
495 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
| 23724 |
amit.gupta |
496 |
}
|
| 24561 |
amit.gupta |
497 |
}catch(Exception e) {
|
|
|
498 |
e.printStackTrace();
|
| 24565 |
amit.gupta |
499 |
throw e;
|
| 24561 |
amit.gupta |
500 |
}
|
| 23724 |
amit.gupta |
501 |
LOGGER.info("Schemes process successfully.");
|
|
|
502 |
}
|
| 23929 |
amit.gupta |
503 |
|
| 23739 |
amit.gupta |
504 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
505 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
506 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
507 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
508 |
.getPendingCashBackRehargeTransactions();
|
|
|
509 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
510 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
511 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
512 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
513 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
514 |
if (Math.round(amount) > 0) {
|
|
|
515 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
|
|
516 |
"Recharge Cashback", Math.round(amount));
|
| 23762 |
amit.gupta |
517 |
}
|
| 23739 |
amit.gupta |
518 |
}
|
| 23929 |
amit.gupta |
519 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
520 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
521 |
rt.setCashbackReference(referenceId);
|
|
|
522 |
rechargeTransactionRepository.persist(rt);
|
|
|
523 |
}
|
| 23739 |
amit.gupta |
524 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
525 |
}
|
| 23724 |
amit.gupta |
526 |
|
| 24271 |
amit.gupta |
527 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
528 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 23929 |
amit.gupta |
529 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
|
|
530 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
531 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
532 |
|
| 24271 |
amit.gupta |
533 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
|
|
534 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
|
|
535 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
| 24002 |
amit.gupta |
536 |
List<List<Object>> rows = new ArrayList<>();
|
|
|
537 |
for (FofoStore fofoStore : fofoStores) {
|
|
|
538 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
|
|
539 |
if (retailer == null) {
|
|
|
540 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
541 |
continue;
|
|
|
542 |
}
|
| 24533 |
govind |
543 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
|
|
|
544 |
1);
|
| 24337 |
amit.gupta |
545 |
partnerDailyInvestment.setDate(yesterDay);
|
|
|
546 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 24533 |
govind |
547 |
|
| 24002 |
amit.gupta |
548 |
List<Object> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(), retailer.getEmail(),
|
| 24337 |
amit.gupta |
549 |
retailer.getMobileNumber(), partnerDailyInvestment.getWalletAmount(),
|
|
|
550 |
partnerDailyInvestment.getSalesAmount(), partnerDailyInvestment.getInStockAmount(), 0,
|
| 24415 |
amit.gupta |
551 |
partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
| 24533 |
govind |
552 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
|
|
553 |
partnerDailyInvestment.getShortInvestment());
|
| 24002 |
amit.gupta |
554 |
rows.add(row);
|
|
|
555 |
|
| 23929 |
amit.gupta |
556 |
}
|
| 24271 |
amit.gupta |
557 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 24002 |
amit.gupta |
558 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
559 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
|
|
560 |
|
|
|
561 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA", fileName,
|
|
|
562 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
563 |
|
| 23929 |
amit.gupta |
564 |
}
|
| 24177 |
govind |
565 |
|
| 24271 |
amit.gupta |
566 |
public void sendPartnerInvestmentDetails() throws Exception {
|
|
|
567 |
List<String> sendTo = Arrays.asList("adeel.yazdani@smartdukaan.com", "amandeep.singh@smartdukaan.com",
|
|
|
568 |
"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com",
|
|
|
569 |
"neeraj.gupta@smartdukaan.com");
|
|
|
570 |
this.sendPartnerInvestmentDetails(sendTo);
|
|
|
571 |
|
|
|
572 |
}
|
|
|
573 |
|
| 24177 |
govind |
574 |
private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
|
| 24187 |
govind |
575 |
Map<String, InputStream> inputStreams)
|
| 24177 |
govind |
576 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 24121 |
govind |
577 |
MimeMessage message = mailSender.createMimeMessage();
|
| 24177 |
govind |
578 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
579 |
helper.setSubject(subject);
|
|
|
580 |
helper.setText(body);
|
|
|
581 |
if (ccEmails != null) {
|
|
|
582 |
helper.setCc(ccEmails);
|
|
|
583 |
}
|
| 24240 |
amit.gupta |
584 |
for (String attachment : inputStreams.keySet()) {
|
|
|
585 |
helper.addAttachment(attachment + "_" + LocalDate.now() + ".xls",
|
|
|
586 |
new ByteArrayResource(IOUtils.toByteArray(inputStreams.get(attachment))));
|
| 24187 |
govind |
587 |
}
|
| 24177 |
govind |
588 |
helper.setTo(email);
|
| 24195 |
govind |
589 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24177 |
govind |
590 |
helper.setFrom(senderAddress);
|
|
|
591 |
mailSender.send(message);
|
| 24135 |
govind |
592 |
}
|
| 24240 |
amit.gupta |
593 |
|
|
|
594 |
private void sendMailWithAttachmentsForPartners(String email, String body, String subject, InputStream is)
|
| 24184 |
govind |
595 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
596 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
597 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
598 |
helper.setSubject(subject);
|
|
|
599 |
helper.setText(body);
|
| 24240 |
amit.gupta |
600 |
helper.addAttachment("DailySaleTargetReports_" + LocalDate.now() + ".xls",
|
|
|
601 |
new ByteArrayResource(IOUtils.toByteArray(is)));
|
| 24184 |
govind |
602 |
helper.setTo(email);
|
| 24195 |
govind |
603 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24184 |
govind |
604 |
helper.setFrom(senderAddress);
|
|
|
605 |
mailSender.send(message);
|
|
|
606 |
}
|
| 24177 |
govind |
607 |
|
|
|
608 |
public void sendMailToSalesHeadAboutTargetAndSales(SaleHeadDetails salesHeadDetail)
|
|
|
609 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
610 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
611 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
612 |
Map<String, InputStream> inputStreams = new HashMap<>();
|
|
|
613 |
for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
|
|
|
614 |
InputStream is = targetService.getDailySaleReportVsTargetForSaleHead(partnerTargetDetail,
|
|
|
615 |
salesHeadDetail.getName());
|
| 24240 |
amit.gupta |
616 |
|
| 24177 |
govind |
617 |
inputStreams.put(partnerTargetDetail.getTargetName(), is);
|
|
|
618 |
|
| 24174 |
govind |
619 |
}
|
| 24240 |
amit.gupta |
620 |
// String[] ccEmails = null;
|
| 24271 |
amit.gupta |
621 |
if (partnerTargetDetails.size() > 0) {
|
| 24254 |
govind |
622 |
String[] ccEmails = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
|
|
623 |
"chaitnaya.vats@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" };
|
|
|
624 |
String subject = "Daily Sales Report ";
|
|
|
625 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
|
|
626 |
LOGGER.info("message" + message);
|
|
|
627 |
if (salesHeadDetail.getName().equals("Kamal")) {
|
|
|
628 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
629 |
String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
|
| 24177 |
govind |
630 |
|
| 24271 |
amit.gupta |
631 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
| 24177 |
govind |
632 |
|
| 24271 |
amit.gupta |
633 |
} else {
|
|
|
634 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
635 |
String[] to = { salesHeadDetail.getEmail() };
|
|
|
636 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
|
|
637 |
}
|
| 24177 |
govind |
638 |
}
|
| 24121 |
govind |
639 |
}
|
| 24177 |
govind |
640 |
|
| 24240 |
amit.gupta |
641 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException,
|
|
|
642 |
IOException, EncryptedDocumentException, InvalidFormatException {
|
| 24177 |
govind |
643 |
List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
|
|
|
644 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService
|
|
|
645 |
.getFofoRetailers(new ArrayList<>(fofoIds));
|
| 24240 |
amit.gupta |
646 |
List<InputStream> input = new ArrayList<>();
|
| 24177 |
govind |
647 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
648 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
649 |
for (Integer fofoId : fofoIds) {
|
| 24240 |
amit.gupta |
650 |
InputStream is = targetService.getDailySaleReportVsTargetForPartner(fofoId, partnerTargetDetails);
|
|
|
651 |
LOGGER.info("is" + is);
|
|
|
652 |
if (is == null) {
|
| 24192 |
govind |
653 |
continue;
|
|
|
654 |
}
|
| 24240 |
amit.gupta |
655 |
LOGGER.info("fofoId" + fofoId);
|
|
|
656 |
|
| 24177 |
govind |
657 |
LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
|
| 24240 |
amit.gupta |
658 |
String subject = "Daily Sales Report";
|
|
|
659 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
| 24177 |
govind |
660 |
LOGGER.info(message);
|
| 24240 |
amit.gupta |
661 |
this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
|
|
|
662 |
is);
|
|
|
663 |
|
| 24174 |
govind |
664 |
}
|
|
|
665 |
}
|
| 24533 |
govind |
666 |
|
|
|
667 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
668 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
669 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
670 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
671 |
}
|
|
|
672 |
}
|
| 23929 |
amit.gupta |
673 |
|
| 24542 |
amit.gupta |
674 |
public void walletmismatch() throws Exception {
|
|
|
675 |
LocalDate curDate = LocalDate.now();
|
| 24553 |
amit.gupta |
676 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 24552 |
amit.gupta |
677 |
System.out.println(pdis.size());
|
| 24542 |
amit.gupta |
678 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 24549 |
amit.gupta |
679 |
int fofoId = pdi.getFofoId();
|
| 24542 |
amit.gupta |
680 |
for (PartnerDailyInvestment investment : Lists
|
|
|
681 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 24552 |
amit.gupta |
682 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 24555 |
amit.gupta |
683 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 24552 |
amit.gupta |
684 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 24561 |
amit.gupta |
685 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), investment.getDate().toString(),
|
|
|
686 |
investment.getWalletAmount(), statementAmount);
|
| 24551 |
amit.gupta |
687 |
|
| 24542 |
amit.gupta |
688 |
}
|
| 24549 |
amit.gupta |
689 |
}
|
| 24542 |
amit.gupta |
690 |
|
|
|
691 |
}
|
|
|
692 |
|
| 24533 |
govind |
693 |
public void escalateTicket() throws ProfitMandiBusinessException {
|
|
|
694 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTickets();
|
| 24571 |
amit.gupta |
695 |
LocalDateTime now = LocalDateTime.now();
|
| 24533 |
govind |
696 |
for (Ticket ticket : tickets) {
|
| 24571 |
amit.gupta |
697 |
if (ticket.getL2EscalationTimestamp().isBefore(now) && ticket.getL3EscalationTimestamp().isAfter(now)) {
|
| 24533 |
govind |
698 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
699 |
.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(), ticket.getId());
|
|
|
700 |
if (ticketAssigned == null) {
|
|
|
701 |
ticketAssigned = new TicketAssigned();
|
|
|
702 |
ticketAssigned.setAssineeId(ticket.getL2AuthUser());
|
|
|
703 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
704 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
705 |
String subject = "Escalated Ticket";
|
|
|
706 |
LOGGER.info(subject);
|
|
|
707 |
|
|
|
708 |
String message = MessageFormat.format(Escalate_TICKET,
|
|
|
709 |
authRepository.selectById(ticket.getL1AuthUser()).getFirstName(),
|
|
|
710 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(),
|
|
|
711 |
authRepository.selectById(ticket.getL2AuthUser()).getFirstName());
|
|
|
712 |
LOGGER.info(message);
|
|
|
713 |
|
|
|
714 |
String[] cc = { authRepository.selectById(ticket.getL2AuthUser()).getEmailId() };
|
|
|
715 |
LOGGER.info(cc[0]);
|
|
|
716 |
|
|
|
717 |
String to = authRepository.selectById(ticket.getL1AuthUser()).getEmailId();
|
|
|
718 |
LOGGER.info(to);
|
|
|
719 |
|
|
|
720 |
this.sendEscaltedTicketMail(to, subject, message, cc);
|
|
|
721 |
LOGGER.info(subject + " " + message + " " + to + " " + cc[0]);
|
|
|
722 |
}
|
| 24571 |
amit.gupta |
723 |
} else if (ticket.getL3EscalationTimestamp().isBefore(now)
|
|
|
724 |
&& ticket.getLastEscalationTimestamp().isAfter(now)) {
|
| 24533 |
govind |
725 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
726 |
.selectByAssigneeIdAndTicketId(ticket.getL3AuthUser(), ticket.getId());
|
|
|
727 |
if (ticketAssigned == null) {
|
|
|
728 |
ticketAssigned = new TicketAssigned();
|
|
|
729 |
ticketAssigned.setAssineeId(ticket.getL3AuthUser());
|
|
|
730 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
731 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
732 |
String subject = "Escalated Ticket";
|
|
|
733 |
String message = MessageFormat.format(Escalate_TICKET,
|
|
|
734 |
authRepository.selectById(ticket.getL2AuthUser()).getFirstName(),
|
|
|
735 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(),
|
|
|
736 |
authRepository.selectById(ticket.getL3AuthUser()).getFirstName());
|
|
|
737 |
LOGGER.info(subject);
|
|
|
738 |
LOGGER.info(message);
|
|
|
739 |
String[] cc = { authRepository.selectById(ticket.getL3AuthUser()).getEmailId() };
|
|
|
740 |
LOGGER.info(cc[0]);
|
|
|
741 |
|
|
|
742 |
String to = authRepository.selectById(ticket.getL2AuthUser()).getEmailId();
|
|
|
743 |
LOGGER.info(to);
|
|
|
744 |
this.sendEscaltedTicketMail(to, subject, message, cc);
|
|
|
745 |
LOGGER.info(subject);
|
|
|
746 |
}
|
|
|
747 |
}
|
|
|
748 |
}
|
|
|
749 |
}
|
|
|
750 |
|
|
|
751 |
private void sendEscaltedTicketMail(String to, String subject, String message, String[] cc)
|
|
|
752 |
throws ProfitMandiBusinessException {
|
|
|
753 |
try {
|
|
|
754 |
Utils.sendMailWithAttachments(mailSender, to, cc, subject, message, null);
|
|
|
755 |
LOGGER.info("mail send successfully");
|
|
|
756 |
} catch (Exception e) {
|
|
|
757 |
throw new ProfitMandiBusinessException("Escalated Ticket", to, "Could not send Escalated ticket mail");
|
|
|
758 |
}
|
|
|
759 |
}
|
|
|
760 |
|
| 24542 |
amit.gupta |
761 |
public void gst() throws Exception {
|
| 24548 |
amit.gupta |
762 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2019, 1, 26).atStartOfDay(),
|
|
|
763 |
LocalDate.of(2019, 1, 27).atTime(LocalTime.MAX));
|
|
|
764 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
765 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
766 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 24542 |
amit.gupta |
767 |
|
|
|
768 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
769 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
770 |
Integer stateId = null;
|
|
|
771 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
772 |
try {
|
|
|
773 |
stateId = Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
|
|
|
774 |
} catch (Exception e) {
|
|
|
775 |
LOGGER.error("Unable to get state rates");
|
|
|
776 |
}
|
|
|
777 |
}
|
|
|
778 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
779 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 24548 |
amit.gupta |
780 |
|
|
|
781 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
782 |
Set<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 24542 |
amit.gupta |
783 |
if (stateId != null) {
|
|
|
784 |
itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemIds), stateId);
|
|
|
785 |
} else {
|
|
|
786 |
itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemIds));
|
|
|
787 |
}
|
|
|
788 |
|
| 24548 |
amit.gupta |
789 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 24542 |
amit.gupta |
790 |
if (stateId == null) {
|
|
|
791 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
|
|
792 |
} else {
|
|
|
793 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
|
|
794 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
|
|
795 |
}
|
|
|
796 |
fofoOrderItemRepository.persist(foi);
|
|
|
797 |
}
|
|
|
798 |
}
|
| 24548 |
amit.gupta |
799 |
|
| 24542 |
amit.gupta |
800 |
}
|
|
|
801 |
|
| 24580 |
amit.gupta |
802 |
public void schemewalletmismatch() {
|
|
|
803 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
|
|
804 |
while(dateToReconcile.isBefore(LocalDate.now())) {
|
|
|
805 |
reconcileSchemes(dateToReconcile);
|
|
|
806 |
//reconcileOrders(dateTime);
|
|
|
807 |
//reconcileRecharges(dateTime);
|
|
|
808 |
dateToReconcile = dateToReconcile.plusDays(1);
|
|
|
809 |
}
|
|
|
810 |
}
|
|
|
811 |
|
|
|
812 |
private void reconcileSchemes(LocalDate date) {
|
|
|
813 |
LocalDateTime startDate = date.atStartOfDay();
|
|
|
814 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
815 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
|
|
816 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
|
|
817 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x->x.getAmount()).sum();
|
|
|
818 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x->x.getAmount()).sum();
|
|
|
819 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
|
|
820 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT);
|
|
|
821 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate, walletReferenceTypes);
|
|
|
822 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x->x.getAmount()).sum();
|
|
|
823 |
if(Math.abs(netSchemeDisbursed-schemeAmountWalletTotal) > 10d) {
|
|
|
824 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
|
|
825 |
}
|
|
|
826 |
|
|
|
827 |
|
|
|
828 |
}
|
|
|
829 |
|
| 24561 |
amit.gupta |
830 |
/*
|
|
|
831 |
* public void processSchemeForModel(String string) { pricingService
|
|
|
832 |
*
|
|
|
833 |
* }
|
|
|
834 |
*/
|
|
|
835 |
|
| 23724 |
amit.gupta |
836 |
}
|