| 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;
|
| 23724 |
amit.gupta |
18 |
import java.util.stream.Collectors;
|
| 23723 |
amit.gupta |
19 |
|
| 24121 |
govind |
20 |
import javax.mail.MessagingException;
|
|
|
21 |
import javax.mail.internet.InternetAddress;
|
|
|
22 |
import javax.mail.internet.MimeMessage;
|
|
|
23 |
|
|
|
24 |
import org.apache.commons.codec.CharEncoding;
|
|
|
25 |
import org.apache.commons.io.IOUtils;
|
| 23929 |
amit.gupta |
26 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 23755 |
amit.gupta |
27 |
import org.apache.logging.log4j.LogManager;
|
|
|
28 |
import org.apache.logging.log4j.Logger;
|
| 24184 |
govind |
29 |
import org.apache.poi.EncryptedDocumentException;
|
|
|
30 |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
| 23723 |
amit.gupta |
31 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23933 |
amit.gupta |
32 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23724 |
amit.gupta |
33 |
import org.springframework.beans.factory.annotation.Value;
|
| 23929 |
amit.gupta |
34 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
35 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24121 |
govind |
36 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23723 |
amit.gupta |
37 |
import org.springframework.stereotype.Component;
|
| 23724 |
amit.gupta |
38 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
39 |
|
| 23724 |
amit.gupta |
40 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24121 |
govind |
41 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23929 |
amit.gupta |
42 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 23724 |
amit.gupta |
43 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 24002 |
amit.gupta |
44 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
45 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
46 |
import com.spice.profitmandi.common.util.Utils;
|
| 23724 |
amit.gupta |
47 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
|
|
48 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
49 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
|
|
50 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
|
|
51 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 23929 |
amit.gupta |
52 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24249 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24277 |
amit.gupta |
54 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 24174 |
govind |
55 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 23724 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24174 |
govind |
57 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
| 24242 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 24241 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 23929 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 24250 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 24242 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 24249 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24241 |
amit.gupta |
64 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 23724 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 23929 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23724 |
amit.gupta |
67 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
|
|
68 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
69 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
|
|
70 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 24249 |
amit.gupta |
71 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24277 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24174 |
govind |
73 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 23724 |
amit.gupta |
74 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24242 |
amit.gupta |
75 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 24241 |
amit.gupta |
76 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23929 |
amit.gupta |
77 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
78 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24271 |
amit.gupta |
79 |
import com.spice.profitmandi.service.order.OrderService;
|
| 23724 |
amit.gupta |
80 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
81 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
82 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 24121 |
govind |
83 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23929 |
amit.gupta |
84 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
85 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
86 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23723 |
amit.gupta |
87 |
|
| 24197 |
amit.gupta |
88 |
import in.shop2020.model.v1.order.WalletReferenceType;;
|
| 23739 |
amit.gupta |
89 |
|
| 23723 |
amit.gupta |
90 |
@Component
|
| 23724 |
amit.gupta |
91 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
92 |
public class ScheduledTasks {
|
|
|
93 |
|
| 23724 |
amit.gupta |
94 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
95 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
96 |
|
| 23724 |
amit.gupta |
97 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
98 |
private String oxigenRechargeEnquiryUrl;
|
| 23723 |
amit.gupta |
99 |
|
| 23724 |
amit.gupta |
100 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
101 |
private String oxigenRechargeAuthKey;
|
|
|
102 |
|
|
|
103 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
104 |
private String oxigenRechargeValidationUrl;
|
|
|
105 |
|
|
|
106 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
107 |
private String oxigenRechargeValidationAuthKey;
|
|
|
108 |
|
|
|
109 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
110 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
111 |
|
|
|
112 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
113 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
114 |
|
|
|
115 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
116 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
117 |
|
|
|
118 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
119 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
120 |
|
|
|
121 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
122 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
123 |
|
|
|
124 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
125 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
126 |
|
|
|
127 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
128 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
129 |
|
| 23723 |
amit.gupta |
130 |
@Autowired
|
| 23724 |
amit.gupta |
131 |
private PurchaseRepository purchaseRepository;
|
|
|
132 |
|
|
|
133 |
@Autowired
|
|
|
134 |
private SchemeService schemeService;
|
|
|
135 |
|
|
|
136 |
@Autowired
|
| 24271 |
amit.gupta |
137 |
private OrderService orderService;
|
|
|
138 |
|
|
|
139 |
@Autowired
|
| 24277 |
amit.gupta |
140 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
141 |
|
|
|
142 |
@Autowired
|
| 24241 |
amit.gupta |
143 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
144 |
|
|
|
145 |
@Autowired
|
| 23724 |
amit.gupta |
146 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
147 |
|
|
|
148 |
@Autowired
|
|
|
149 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
150 |
|
|
|
151 |
@Autowired
|
|
|
152 |
private FofoOrderRepository fofoOrderRepository;
|
| 24250 |
amit.gupta |
153 |
|
| 24249 |
amit.gupta |
154 |
@Autowired
|
|
|
155 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
156 |
|
| 23739 |
amit.gupta |
157 |
@Autowired
|
|
|
158 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
159 |
|
|
|
160 |
@Autowired
|
|
|
161 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
162 |
|
|
|
163 |
@Autowired
|
|
|
164 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
165 |
|
|
|
166 |
@Autowired
|
|
|
167 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
168 |
|
|
|
169 |
@Autowired
|
| 24242 |
amit.gupta |
170 |
private ScanRecordRepository scanRecordRepository;
|
|
|
171 |
|
|
|
172 |
@Autowired
|
| 23724 |
amit.gupta |
173 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
174 |
|
| 23929 |
amit.gupta |
175 |
@Autowired
|
|
|
176 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
177 |
|
| 24121 |
govind |
178 |
@Autowired
|
|
|
179 |
private TargetSlabService targetService;
|
| 23929 |
amit.gupta |
180 |
|
| 23724 |
amit.gupta |
181 |
@Value("${prod}")
|
|
|
182 |
private boolean prod;
|
|
|
183 |
|
| 23929 |
amit.gupta |
184 |
@Autowired
|
|
|
185 |
private RetailerService retailerService;
|
|
|
186 |
|
|
|
187 |
@Autowired
|
|
|
188 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
189 |
|
| 24249 |
amit.gupta |
190 |
@Autowired
|
|
|
191 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
192 |
|
|
|
193 |
@Autowired
|
|
|
194 |
private OrderRepository orderRepository;
|
|
|
195 |
|
|
|
196 |
@Autowired
|
| 24241 |
amit.gupta |
197 |
private SchemeRepository schemeRepository;
|
|
|
198 |
|
|
|
199 |
@Autowired
|
| 23929 |
amit.gupta |
200 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
201 |
|
| 24174 |
govind |
202 |
@Autowired
|
|
|
203 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
204 |
|
|
|
205 |
@Autowired
|
|
|
206 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
207 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
208 |
|
|
|
209 |
@Autowired
|
|
|
210 |
private InventoryService inventoryService;
|
|
|
211 |
|
| 23755 |
amit.gupta |
212 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
213 |
|
|
|
214 |
public void generateDailyRecharge() {
|
|
|
215 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
216 |
.selectAll(0, 2000);
|
|
|
217 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
218 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
219 |
|
|
|
220 |
rechargeProviders.stream().forEach(x -> {
|
|
|
221 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
222 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
223 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
224 |
|
|
|
225 |
LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
|
|
|
226 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
227 |
float previousDayClosing = 0;
|
|
|
228 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
229 |
while (date.isBefore(endDate)) {
|
|
|
230 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
231 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
232 |
date.plusDays(1).atStartOfDay());
|
|
|
233 |
|
|
|
234 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
235 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
236 |
|
|
|
237 |
float dailyAmount = 0;
|
|
|
238 |
float totalCommission = 0;
|
|
|
239 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
240 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
241 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
242 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
247 |
float dailyWalletRecharge = 0;
|
|
|
248 |
if (rechargeHistoryList != null) {
|
|
|
249 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
250 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
251 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
256 |
DailyRecharge dailyRecharge = null;
|
|
|
257 |
try {
|
|
|
258 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
259 |
} catch (Exception e) {
|
|
|
260 |
LOGGER.info("Could not find Recharge entry");
|
|
|
261 |
}
|
|
|
262 |
if (dailyRecharge == null) {
|
|
|
263 |
dailyRecharge = new DailyRecharge();
|
|
|
264 |
dailyRecharge.setCreateDate(date);
|
|
|
265 |
}
|
|
|
266 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
267 |
dailyRecharge.setProviderId(x.getId());
|
|
|
268 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
269 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
270 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
271 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
272 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
273 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
274 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
275 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
276 |
}
|
|
|
277 |
date = date.plusDays(1);
|
|
|
278 |
}
|
|
|
279 |
rechargeProviderRepository.persist(x);
|
|
|
280 |
});
|
| 23761 |
amit.gupta |
281 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
282 |
}
|
|
|
283 |
|
| 23738 |
amit.gupta |
284 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
285 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
286 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
287 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
288 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
289 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
290 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
291 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
292 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
293 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
294 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
295 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
296 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
297 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
298 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
299 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
300 |
try {
|
|
|
301 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
302 |
if (providerId == 1) {
|
|
|
303 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
304 |
rechargeTransaction);
|
|
|
305 |
} else if (providerId == 2) {
|
|
|
306 |
thinkWalnutDigitalRechargeProviderService
|
|
|
307 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
308 |
}
|
|
|
309 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
310 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
311 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
312 |
rechargeTransaction.getStatus());
|
|
|
313 |
}
|
|
|
314 |
} catch (Exception e) {
|
|
|
315 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
316 |
}
|
|
|
317 |
}
|
| 23738 |
amit.gupta |
318 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
319 |
}
|
| 24240 |
amit.gupta |
320 |
|
|
|
321 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
322 |
public void migrateInvoice() {
|
|
|
323 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
324 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
325 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
326 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
327 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
328 |
int sequence = 0;
|
|
|
329 |
String prefix = "";
|
| 24241 |
amit.gupta |
330 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
331 |
.collect(Collectors.toList());
|
|
|
332 |
for (FofoOrder order : sortedList) {
|
|
|
333 |
|
| 24240 |
amit.gupta |
334 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
335 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
336 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
337 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
338 |
} else {
|
|
|
339 |
sequence += 1;
|
| 24241 |
amit.gupta |
340 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
341 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
342 |
fofoOrderRepository.persist(order);
|
|
|
343 |
}
|
|
|
344 |
}
|
| 24241 |
amit.gupta |
345 |
|
| 24237 |
amit.gupta |
346 |
}
|
|
|
347 |
}
|
| 23724 |
amit.gupta |
348 |
|
| 24241 |
amit.gupta |
349 |
// Temporary Method
|
| 24252 |
amit.gupta |
350 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 24244 |
amit.gupta |
351 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
352 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 24252 |
amit.gupta |
353 |
|
|
|
354 |
List<List<Object>> rows = new ArrayList<>();
|
| 24271 |
amit.gupta |
355 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
356 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 24241 |
amit.gupta |
357 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 24250 |
amit.gupta |
358 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
359 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
360 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
361 |
if (x.getActiveTimestamp() != null) {
|
|
|
362 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
363 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
364 |
endDateTime = x.getExpireTimestamp();
|
| 24249 |
amit.gupta |
365 |
}
|
| 24250 |
amit.gupta |
366 |
for (SchemeInOut sio : sioList) {
|
|
|
367 |
InventoryItem inventoryItem = null;
|
| 24266 |
amit.gupta |
368 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 24271 |
amit.gupta |
369 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
370 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 24250 |
amit.gupta |
371 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
372 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
373 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
374 |
if (record.isPresent()) {
|
|
|
375 |
int fofoId = record.get().getFofoId();
|
|
|
376 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
377 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
378 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
379 |
userAmountMap.put(fofoId, 0f);
|
|
|
380 |
}
|
|
|
381 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
382 |
try {
|
| 24252 |
amit.gupta |
383 |
rows.add(Arrays.asList(x.getDescription(),
|
| 24250 |
amit.gupta |
384 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 24252 |
amit.gupta |
385 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 24253 |
amit.gupta |
386 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
387 |
fofoOrder.getInvoiceNumber(),
|
|
|
388 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
389 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
390 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
391 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
392 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 24250 |
amit.gupta |
393 |
} catch (Exception e) {
|
|
|
394 |
e.printStackTrace();
|
|
|
395 |
}
|
| 24242 |
amit.gupta |
396 |
}
|
| 24241 |
amit.gupta |
397 |
}
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
}
|
|
|
401 |
});
|
| 24246 |
amit.gupta |
402 |
userAmountMap.entrySet().stream()
|
|
|
403 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
404 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 24241 |
amit.gupta |
405 |
|
| 24252 |
amit.gupta |
406 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
407 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
408 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
|
|
409 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 24252 |
amit.gupta |
410 |
|
| 24241 |
amit.gupta |
411 |
}
|
| 24271 |
amit.gupta |
412 |
|
| 24256 |
amit.gupta |
413 |
public void processScheme(int offset) throws Exception {
|
| 24271 |
amit.gupta |
414 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(30 * offset);
|
| 24259 |
amit.gupta |
415 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 24258 |
amit.gupta |
416 |
processScheme(startDate, endDate);
|
| 24256 |
amit.gupta |
417 |
}
|
| 24271 |
amit.gupta |
418 |
|
| 23738 |
amit.gupta |
419 |
public void processScheme() throws Exception {
|
| 24256 |
amit.gupta |
420 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
|
|
421 |
processScheme(fromDate, LocalDateTime.now());
|
|
|
422 |
}
|
| 24271 |
amit.gupta |
423 |
|
| 24256 |
amit.gupta |
424 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
|
| 23724 |
amit.gupta |
425 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 24256 |
amit.gupta |
426 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
| 23724 |
amit.gupta |
427 |
for (Purchase purchase : purchases) {
|
|
|
428 |
try {
|
|
|
429 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
430 |
} catch (Exception e) {
|
|
|
431 |
LOGGER.error("Error while processing purchase {} for scheme In ", purchase.getId());
|
|
|
432 |
e.printStackTrace();
|
| 24271 |
amit.gupta |
433 |
|
| 23724 |
amit.gupta |
434 |
}
|
|
|
435 |
}
|
| 24256 |
amit.gupta |
436 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
| 23724 |
amit.gupta |
437 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
438 |
try {
|
|
|
439 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
440 |
} catch (Exception e) {
|
|
|
441 |
LOGGER.error("Error while processing sale order {} for scheme Out", fofoOrder.getId());
|
|
|
442 |
}
|
|
|
443 |
}
|
|
|
444 |
LOGGER.info("Schemes process successfully.");
|
|
|
445 |
}
|
| 23929 |
amit.gupta |
446 |
|
| 23739 |
amit.gupta |
447 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
448 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
449 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
450 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
451 |
.getPendingCashBackRehargeTransactions();
|
|
|
452 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
453 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
454 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
455 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
456 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
457 |
if (Math.round(amount) > 0) {
|
|
|
458 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
|
|
459 |
"Recharge Cashback", Math.round(amount));
|
| 23762 |
amit.gupta |
460 |
}
|
| 23739 |
amit.gupta |
461 |
}
|
| 23929 |
amit.gupta |
462 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
463 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
464 |
rt.setCashbackReference(referenceId);
|
|
|
465 |
rechargeTransactionRepository.persist(rt);
|
|
|
466 |
}
|
| 23739 |
amit.gupta |
467 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
468 |
}
|
| 23724 |
amit.gupta |
469 |
|
| 24271 |
amit.gupta |
470 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
471 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 23929 |
amit.gupta |
472 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
|
|
473 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
474 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
475 |
|
| 24271 |
amit.gupta |
476 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
|
|
477 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
|
|
478 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
| 24002 |
amit.gupta |
479 |
List<List<Object>> rows = new ArrayList<>();
|
|
|
480 |
for (FofoStore fofoStore : fofoStores) {
|
|
|
481 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
|
|
482 |
if (retailer == null) {
|
|
|
483 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
484 |
continue;
|
|
|
485 |
}
|
|
|
486 |
float walletAmount = walletService.getUserWallet(fofoStore.getId()).getAmount();
|
|
|
487 |
float inStockAmount = inventoryService.getTotalAmountInStock(fofoStore.getId());
|
| 24284 |
amit.gupta |
488 |
float salesAmount = orderService.getSales(fofoStore.getId(), LocalDateTime.now().minusDays(1).with(LocalTime.MIDNIGHT), LocalDateTime.now());
|
| 24314 |
amit.gupta |
489 |
float returnInTransitAmount = 0;
|
| 24002 |
amit.gupta |
490 |
float unbilledStockAmount = 0;
|
|
|
491 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(fofoStore.getId());
|
|
|
492 |
for (Order unBilledOrder : unbilledOrders) {
|
|
|
493 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
| 23929 |
amit.gupta |
494 |
}
|
|
|
495 |
|
| 24002 |
amit.gupta |
496 |
float grnPendingStockAmount = 0;
|
|
|
497 |
List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoStore.getId());
|
|
|
498 |
for (Order grnPendingOrder : grnPendingOrders) {
|
|
|
499 |
LOGGER.info("Grn pending for Order {} and partner {}", grnPendingOrder.getId(),
|
|
|
500 |
grnPendingOrder.getRetailerEmailId());
|
|
|
501 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
|
|
502 |
}
|
| 24284 |
amit.gupta |
503 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount + salesAmount;
|
| 24314 |
amit.gupta |
504 |
float shortValue = fofoStore.getMinimumInvestment() - totalInvestedAmount;
|
|
|
505 |
|
| 24002 |
amit.gupta |
506 |
List<Object> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(), retailer.getEmail(),
|
| 24286 |
amit.gupta |
507 |
retailer.getMobileNumber(), walletAmount, salesAmount, inStockAmount, 0, unbilledStockAmount,
|
| 24314 |
amit.gupta |
508 |
grnPendingStockAmount, fofoStore.getMinimumInvestment(), totalInvestedAmount, shortValue);
|
| 24277 |
amit.gupta |
509 |
try {
|
| 24314 |
amit.gupta |
510 |
PartnerDailyInvestment partnerDailyInvestment = new PartnerDailyInvestment();
|
|
|
511 |
partnerDailyInvestment.setDate(yesterDay);
|
|
|
512 |
partnerDailyInvestment.setFofoId(fofoStore.getId());
|
|
|
513 |
partnerDailyInvestment.setGrnPendingAmount(grnPendingStockAmount);
|
|
|
514 |
partnerDailyInvestment.setInStockAmount(inStockAmount);
|
|
|
515 |
partnerDailyInvestment.setSalesAmount(salesAmount);
|
|
|
516 |
partnerDailyInvestment.setReturnInTransitAmount(returnInTransitAmount);
|
|
|
517 |
partnerDailyInvestment.setUnbilledAmount(unbilledStockAmount);
|
|
|
518 |
partnerDailyInvestment.setWalletAmount(walletAmount);
|
|
|
519 |
partnerDailyInvestment.setMinInvestment(fofoStore.getMinimumInvestment());
|
|
|
520 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 24277 |
amit.gupta |
521 |
} catch(Exception e) {
|
|
|
522 |
e.printStackTrace();
|
|
|
523 |
}
|
| 24002 |
amit.gupta |
524 |
rows.add(row);
|
|
|
525 |
|
| 23929 |
amit.gupta |
526 |
}
|
| 24271 |
amit.gupta |
527 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 24002 |
amit.gupta |
528 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
529 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
|
|
530 |
|
|
|
531 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA", fileName,
|
|
|
532 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
533 |
|
| 23929 |
amit.gupta |
534 |
}
|
| 24177 |
govind |
535 |
|
| 24271 |
amit.gupta |
536 |
public void sendPartnerInvestmentDetails() throws Exception {
|
|
|
537 |
List<String> sendTo = Arrays.asList("adeel.yazdani@smartdukaan.com", "amandeep.singh@smartdukaan.com",
|
|
|
538 |
"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com",
|
|
|
539 |
"neeraj.gupta@smartdukaan.com");
|
|
|
540 |
this.sendPartnerInvestmentDetails(sendTo);
|
|
|
541 |
|
|
|
542 |
}
|
|
|
543 |
|
| 24177 |
govind |
544 |
private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
|
| 24187 |
govind |
545 |
Map<String, InputStream> inputStreams)
|
| 24177 |
govind |
546 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 24121 |
govind |
547 |
MimeMessage message = mailSender.createMimeMessage();
|
| 24177 |
govind |
548 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
549 |
helper.setSubject(subject);
|
|
|
550 |
helper.setText(body);
|
|
|
551 |
if (ccEmails != null) {
|
|
|
552 |
helper.setCc(ccEmails);
|
|
|
553 |
}
|
| 24240 |
amit.gupta |
554 |
for (String attachment : inputStreams.keySet()) {
|
|
|
555 |
helper.addAttachment(attachment + "_" + LocalDate.now() + ".xls",
|
|
|
556 |
new ByteArrayResource(IOUtils.toByteArray(inputStreams.get(attachment))));
|
| 24187 |
govind |
557 |
}
|
| 24177 |
govind |
558 |
helper.setTo(email);
|
| 24195 |
govind |
559 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24177 |
govind |
560 |
helper.setFrom(senderAddress);
|
|
|
561 |
mailSender.send(message);
|
| 24135 |
govind |
562 |
}
|
| 24240 |
amit.gupta |
563 |
|
|
|
564 |
private void sendMailWithAttachmentsForPartners(String email, String body, String subject, InputStream is)
|
| 24184 |
govind |
565 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
566 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
567 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
568 |
helper.setSubject(subject);
|
|
|
569 |
helper.setText(body);
|
| 24240 |
amit.gupta |
570 |
helper.addAttachment("DailySaleTargetReports_" + LocalDate.now() + ".xls",
|
|
|
571 |
new ByteArrayResource(IOUtils.toByteArray(is)));
|
| 24184 |
govind |
572 |
helper.setTo(email);
|
| 24195 |
govind |
573 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24184 |
govind |
574 |
helper.setFrom(senderAddress);
|
|
|
575 |
mailSender.send(message);
|
|
|
576 |
}
|
| 24177 |
govind |
577 |
|
|
|
578 |
public void sendMailToSalesHeadAboutTargetAndSales(SaleHeadDetails salesHeadDetail)
|
|
|
579 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
580 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
581 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
582 |
Map<String, InputStream> inputStreams = new HashMap<>();
|
|
|
583 |
for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
|
|
|
584 |
InputStream is = targetService.getDailySaleReportVsTargetForSaleHead(partnerTargetDetail,
|
|
|
585 |
salesHeadDetail.getName());
|
| 24240 |
amit.gupta |
586 |
|
| 24177 |
govind |
587 |
inputStreams.put(partnerTargetDetail.getTargetName(), is);
|
|
|
588 |
|
| 24174 |
govind |
589 |
}
|
| 24240 |
amit.gupta |
590 |
// String[] ccEmails = null;
|
| 24271 |
amit.gupta |
591 |
if (partnerTargetDetails.size() > 0) {
|
| 24254 |
govind |
592 |
String[] ccEmails = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
|
|
593 |
"chaitnaya.vats@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" };
|
|
|
594 |
String subject = "Daily Sales Report ";
|
|
|
595 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
|
|
596 |
LOGGER.info("message" + message);
|
|
|
597 |
if (salesHeadDetail.getName().equals("Kamal")) {
|
|
|
598 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
599 |
String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
|
| 24177 |
govind |
600 |
|
| 24271 |
amit.gupta |
601 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
| 24177 |
govind |
602 |
|
| 24271 |
amit.gupta |
603 |
} else {
|
|
|
604 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
605 |
String[] to = { salesHeadDetail.getEmail() };
|
|
|
606 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
|
|
607 |
}
|
| 24177 |
govind |
608 |
}
|
| 24121 |
govind |
609 |
}
|
| 24177 |
govind |
610 |
|
| 24240 |
amit.gupta |
611 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException,
|
|
|
612 |
IOException, EncryptedDocumentException, InvalidFormatException {
|
| 24177 |
govind |
613 |
List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
|
|
|
614 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService
|
|
|
615 |
.getFofoRetailers(new ArrayList<>(fofoIds));
|
| 24240 |
amit.gupta |
616 |
List<InputStream> input = new ArrayList<>();
|
| 24177 |
govind |
617 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
618 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
619 |
for (Integer fofoId : fofoIds) {
|
| 24240 |
amit.gupta |
620 |
InputStream is = targetService.getDailySaleReportVsTargetForPartner(fofoId, partnerTargetDetails);
|
|
|
621 |
LOGGER.info("is" + is);
|
|
|
622 |
if (is == null) {
|
| 24192 |
govind |
623 |
continue;
|
|
|
624 |
}
|
| 24240 |
amit.gupta |
625 |
LOGGER.info("fofoId" + fofoId);
|
|
|
626 |
|
| 24177 |
govind |
627 |
LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
|
| 24240 |
amit.gupta |
628 |
String subject = "Daily Sales Report";
|
|
|
629 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
| 24177 |
govind |
630 |
LOGGER.info(message);
|
| 24240 |
amit.gupta |
631 |
this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
|
|
|
632 |
is);
|
|
|
633 |
|
| 24174 |
govind |
634 |
}
|
|
|
635 |
}
|
| 23929 |
amit.gupta |
636 |
|
| 23724 |
amit.gupta |
637 |
}
|