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