| 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;
|
| 24807 |
amit.gupta |
5 |
import java.io.Serializable;
|
| 23739 |
amit.gupta |
6 |
import java.sql.Timestamp;
|
| 24174 |
govind |
7 |
import java.text.MessageFormat;
|
| 23724 |
amit.gupta |
8 |
import java.time.LocalDate;
|
|
|
9 |
import java.time.LocalDateTime;
|
| 24256 |
amit.gupta |
10 |
import java.time.LocalTime;
|
| 24653 |
govind |
11 |
import java.time.ZoneOffset;
|
|
|
12 |
import java.time.format.DateTimeFormatter;
|
| 23724 |
amit.gupta |
13 |
import java.time.temporal.ChronoUnit;
|
|
|
14 |
import java.util.ArrayList;
|
|
|
15 |
import java.util.Arrays;
|
| 24627 |
amit.gupta |
16 |
import java.util.Collections;
|
| 23723 |
amit.gupta |
17 |
import java.util.HashMap;
|
| 24241 |
amit.gupta |
18 |
import java.util.HashSet;
|
| 23724 |
amit.gupta |
19 |
import java.util.List;
|
| 23723 |
amit.gupta |
20 |
import java.util.Map;
|
| 24242 |
amit.gupta |
21 |
import java.util.Optional;
|
| 24542 |
amit.gupta |
22 |
import java.util.Set;
|
| 23724 |
amit.gupta |
23 |
import java.util.stream.Collectors;
|
| 23723 |
amit.gupta |
24 |
|
| 24121 |
govind |
25 |
import javax.mail.MessagingException;
|
|
|
26 |
import javax.mail.internet.InternetAddress;
|
|
|
27 |
import javax.mail.internet.MimeMessage;
|
|
|
28 |
|
|
|
29 |
import org.apache.commons.codec.CharEncoding;
|
|
|
30 |
import org.apache.commons.io.IOUtils;
|
| 23929 |
amit.gupta |
31 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 23755 |
amit.gupta |
32 |
import org.apache.logging.log4j.LogManager;
|
|
|
33 |
import org.apache.logging.log4j.Logger;
|
| 24184 |
govind |
34 |
import org.apache.poi.EncryptedDocumentException;
|
|
|
35 |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
| 23723 |
amit.gupta |
36 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23933 |
amit.gupta |
37 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23724 |
amit.gupta |
38 |
import org.springframework.beans.factory.annotation.Value;
|
| 23929 |
amit.gupta |
39 |
import org.springframework.core.io.ByteArrayResource;
|
| 24692 |
amit.gupta |
40 |
import org.springframework.core.io.InputStreamSource;
|
| 23929 |
amit.gupta |
41 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24121 |
govind |
42 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23723 |
amit.gupta |
43 |
import org.springframework.stereotype.Component;
|
| 23724 |
amit.gupta |
44 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
45 |
|
| 24542 |
amit.gupta |
46 |
import com.google.common.collect.Lists;
|
| 23724 |
amit.gupta |
47 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24681 |
amit.gupta |
48 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 24121 |
govind |
49 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23929 |
amit.gupta |
50 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24542 |
amit.gupta |
51 |
import com.spice.profitmandi.common.model.GstRate;
|
| 23724 |
amit.gupta |
52 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 24681 |
amit.gupta |
53 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 24002 |
amit.gupta |
54 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
55 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
56 |
import com.spice.profitmandi.common.util.Utils;
|
| 24592 |
amit.gupta |
57 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| 24590 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 23724 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
| 24653 |
govind |
60 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
| 23724 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
62 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
|
|
63 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 24542 |
amit.gupta |
64 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 24590 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 23724 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 24542 |
amit.gupta |
67 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 23929 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24249 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24277 |
amit.gupta |
70 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 24174 |
govind |
71 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 23724 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24174 |
govind |
73 |
import com.spice.profitmandi.dao.entity.fofo.SaleHeadDetails;
|
| 24242 |
amit.gupta |
74 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 24241 |
amit.gupta |
75 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 24431 |
amit.gupta |
76 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 24587 |
amit.gupta |
77 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 24580 |
amit.gupta |
78 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 24542 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 24250 |
amit.gupta |
80 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 24242 |
amit.gupta |
81 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 24249 |
amit.gupta |
82 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24241 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 23724 |
amit.gupta |
84 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 23929 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24653 |
govind |
86 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 23724 |
amit.gupta |
87 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
|
|
88 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
89 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24542 |
amit.gupta |
90 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 24669 |
govind |
91 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 24542 |
amit.gupta |
92 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 24590 |
amit.gupta |
93 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 24542 |
amit.gupta |
94 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 23724 |
amit.gupta |
95 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 24249 |
amit.gupta |
96 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24277 |
amit.gupta |
97 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24174 |
govind |
98 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 23724 |
amit.gupta |
99 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24242 |
amit.gupta |
100 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 24241 |
amit.gupta |
101 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23929 |
amit.gupta |
102 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 24431 |
amit.gupta |
103 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 24580 |
amit.gupta |
104 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 24587 |
amit.gupta |
105 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 24542 |
amit.gupta |
106 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 24337 |
amit.gupta |
107 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23929 |
amit.gupta |
108 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24431 |
amit.gupta |
109 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
110 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
111 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
112 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 24121 |
govind |
113 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23929 |
amit.gupta |
114 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
115 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
116 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23723 |
amit.gupta |
117 |
|
| 24197 |
amit.gupta |
118 |
import in.shop2020.model.v1.order.WalletReferenceType;;
|
| 23739 |
amit.gupta |
119 |
|
| 23723 |
amit.gupta |
120 |
@Component
|
| 23724 |
amit.gupta |
121 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
122 |
public class ScheduledTasks {
|
|
|
123 |
|
| 23724 |
amit.gupta |
124 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
125 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
126 |
|
| 23724 |
amit.gupta |
127 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
128 |
private String oxigenRechargeEnquiryUrl;
|
| 24533 |
govind |
129 |
|
| 24431 |
amit.gupta |
130 |
@Autowired
|
|
|
131 |
private PriceDropService priceDropService;
|
| 23723 |
amit.gupta |
132 |
|
| 23724 |
amit.gupta |
133 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
134 |
private String oxigenRechargeAuthKey;
|
|
|
135 |
|
|
|
136 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
137 |
private String oxigenRechargeValidationUrl;
|
|
|
138 |
|
|
|
139 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
140 |
private String oxigenRechargeValidationAuthKey;
|
|
|
141 |
|
|
|
142 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
143 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
144 |
|
|
|
145 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
146 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
147 |
|
|
|
148 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
149 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
150 |
|
|
|
151 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
152 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
153 |
|
|
|
154 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
155 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
156 |
|
|
|
157 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
158 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
159 |
|
|
|
160 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
161 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
162 |
|
| 23723 |
amit.gupta |
163 |
@Autowired
|
| 23724 |
amit.gupta |
164 |
private PurchaseRepository purchaseRepository;
|
|
|
165 |
|
|
|
166 |
@Autowired
|
|
|
167 |
private SchemeService schemeService;
|
| 24683 |
amit.gupta |
168 |
|
| 24681 |
amit.gupta |
169 |
@Autowired
|
|
|
170 |
private ReporticoService reporticoService;
|
| 23724 |
amit.gupta |
171 |
|
|
|
172 |
@Autowired
|
| 24337 |
amit.gupta |
173 |
private PartnerInvestmentService partnerInvestmentService;
|
|
|
174 |
|
|
|
175 |
@Autowired
|
| 24542 |
amit.gupta |
176 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
177 |
|
|
|
178 |
@Autowired
|
| 24277 |
amit.gupta |
179 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
180 |
|
|
|
181 |
@Autowired
|
| 24241 |
amit.gupta |
182 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
183 |
|
|
|
184 |
@Autowired
|
| 23724 |
amit.gupta |
185 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
186 |
|
|
|
187 |
@Autowired
|
| 24542 |
amit.gupta |
188 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
189 |
|
|
|
190 |
@Autowired
|
| 23724 |
amit.gupta |
191 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
192 |
|
|
|
193 |
@Autowired
|
| 24590 |
amit.gupta |
194 |
private FofoLineItemRepository fofoLineItemRepository;
|
|
|
195 |
|
|
|
196 |
@Autowired
|
| 23724 |
amit.gupta |
197 |
private FofoOrderRepository fofoOrderRepository;
|
| 24587 |
amit.gupta |
198 |
|
| 24580 |
amit.gupta |
199 |
@Autowired
|
|
|
200 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 24250 |
amit.gupta |
201 |
|
| 24249 |
amit.gupta |
202 |
@Autowired
|
| 24587 |
amit.gupta |
203 |
private UserWalletRepository userWalletRepository;
|
|
|
204 |
|
|
|
205 |
@Autowired
|
| 24249 |
amit.gupta |
206 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
207 |
|
| 23739 |
amit.gupta |
208 |
@Autowired
|
|
|
209 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
210 |
|
|
|
211 |
@Autowired
|
|
|
212 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
213 |
|
|
|
214 |
@Autowired
|
|
|
215 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
216 |
|
|
|
217 |
@Autowired
|
|
|
218 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
219 |
|
|
|
220 |
@Autowired
|
| 24242 |
amit.gupta |
221 |
private ScanRecordRepository scanRecordRepository;
|
|
|
222 |
|
|
|
223 |
@Autowired
|
| 23724 |
amit.gupta |
224 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
225 |
|
| 23929 |
amit.gupta |
226 |
@Autowired
|
|
|
227 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
228 |
|
| 24121 |
govind |
229 |
@Autowired
|
|
|
230 |
private TargetSlabService targetService;
|
| 23929 |
amit.gupta |
231 |
|
| 23724 |
amit.gupta |
232 |
@Value("${prod}")
|
|
|
233 |
private boolean prod;
|
|
|
234 |
|
| 23929 |
amit.gupta |
235 |
@Autowired
|
|
|
236 |
private RetailerService retailerService;
|
|
|
237 |
|
|
|
238 |
@Autowired
|
|
|
239 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
240 |
|
| 24249 |
amit.gupta |
241 |
@Autowired
|
|
|
242 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
243 |
|
|
|
244 |
@Autowired
|
|
|
245 |
private OrderRepository orderRepository;
|
|
|
246 |
|
|
|
247 |
@Autowired
|
| 24241 |
amit.gupta |
248 |
private SchemeRepository schemeRepository;
|
|
|
249 |
|
|
|
250 |
@Autowired
|
| 23929 |
amit.gupta |
251 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
252 |
|
| 24174 |
govind |
253 |
@Autowired
|
| 24431 |
amit.gupta |
254 |
private PriceDropRepository priceDropRepository;
|
|
|
255 |
|
|
|
256 |
@Autowired
|
| 24174 |
govind |
257 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
258 |
|
|
|
259 |
@Autowired
|
|
|
260 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
261 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
262 |
|
|
|
263 |
@Autowired
|
|
|
264 |
private InventoryService inventoryService;
|
|
|
265 |
|
| 24533 |
govind |
266 |
@Autowired
|
| 24542 |
amit.gupta |
267 |
private AddressRepository addressRepository;
|
|
|
268 |
|
|
|
269 |
@Autowired
|
|
|
270 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
271 |
|
| 24653 |
govind |
272 |
@Autowired
|
|
|
273 |
private Mongo mongoClient;
|
| 24683 |
amit.gupta |
274 |
|
| 24669 |
govind |
275 |
@Autowired
|
|
|
276 |
private UserAccountRepository userAccountRepository;
|
| 24653 |
govind |
277 |
|
| 23755 |
amit.gupta |
278 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
279 |
|
|
|
280 |
public void generateDailyRecharge() {
|
|
|
281 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
282 |
.selectAll(0, 2000);
|
|
|
283 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
284 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
285 |
|
|
|
286 |
rechargeProviders.stream().forEach(x -> {
|
|
|
287 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
288 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
289 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
290 |
|
|
|
291 |
LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
|
|
|
292 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
293 |
float previousDayClosing = 0;
|
|
|
294 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
295 |
while (date.isBefore(endDate)) {
|
|
|
296 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
297 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
298 |
date.plusDays(1).atStartOfDay());
|
|
|
299 |
|
|
|
300 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
301 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
302 |
|
|
|
303 |
float dailyAmount = 0;
|
|
|
304 |
float totalCommission = 0;
|
|
|
305 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
306 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
307 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
308 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
309 |
}
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
313 |
float dailyWalletRecharge = 0;
|
|
|
314 |
if (rechargeHistoryList != null) {
|
|
|
315 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
316 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
317 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
322 |
DailyRecharge dailyRecharge = null;
|
|
|
323 |
try {
|
|
|
324 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
325 |
} catch (Exception e) {
|
|
|
326 |
LOGGER.info("Could not find Recharge entry");
|
|
|
327 |
}
|
|
|
328 |
if (dailyRecharge == null) {
|
|
|
329 |
dailyRecharge = new DailyRecharge();
|
|
|
330 |
dailyRecharge.setCreateDate(date);
|
|
|
331 |
}
|
|
|
332 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
333 |
dailyRecharge.setProviderId(x.getId());
|
|
|
334 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
335 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
336 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
337 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
338 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
339 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
340 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
341 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
342 |
}
|
|
|
343 |
date = date.plusDays(1);
|
|
|
344 |
}
|
|
|
345 |
rechargeProviderRepository.persist(x);
|
|
|
346 |
});
|
| 23761 |
amit.gupta |
347 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
348 |
}
|
|
|
349 |
|
| 23738 |
amit.gupta |
350 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
351 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
352 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
353 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
354 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
355 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
356 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
357 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
358 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
359 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
360 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
361 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
362 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
363 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
364 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
365 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
366 |
try {
|
|
|
367 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
368 |
if (providerId == 1) {
|
|
|
369 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
370 |
rechargeTransaction);
|
|
|
371 |
} else if (providerId == 2) {
|
|
|
372 |
thinkWalnutDigitalRechargeProviderService
|
|
|
373 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
374 |
}
|
|
|
375 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
376 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
377 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
378 |
rechargeTransaction.getStatus());
|
|
|
379 |
}
|
|
|
380 |
} catch (Exception e) {
|
|
|
381 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
382 |
}
|
|
|
383 |
}
|
| 23738 |
amit.gupta |
384 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
385 |
}
|
| 24240 |
amit.gupta |
386 |
|
|
|
387 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
388 |
public void migrateInvoice() {
|
|
|
389 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
390 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
391 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
392 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
393 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
394 |
int sequence = 0;
|
|
|
395 |
String prefix = "";
|
| 24241 |
amit.gupta |
396 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
397 |
.collect(Collectors.toList());
|
|
|
398 |
for (FofoOrder order : sortedList) {
|
|
|
399 |
|
| 24240 |
amit.gupta |
400 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
401 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
402 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
403 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
404 |
} else {
|
|
|
405 |
sequence += 1;
|
| 24241 |
amit.gupta |
406 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
407 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
408 |
fofoOrderRepository.persist(order);
|
|
|
409 |
}
|
|
|
410 |
}
|
| 24241 |
amit.gupta |
411 |
|
| 24237 |
amit.gupta |
412 |
}
|
|
|
413 |
}
|
| 23724 |
amit.gupta |
414 |
|
| 24241 |
amit.gupta |
415 |
// Temporary Method
|
| 24252 |
amit.gupta |
416 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 24244 |
amit.gupta |
417 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
418 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 24252 |
amit.gupta |
419 |
|
| 24807 |
amit.gupta |
420 |
List<List<? extends Serializable>> rows = new ArrayList<>();
|
| 24271 |
amit.gupta |
421 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
422 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 24241 |
amit.gupta |
423 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 24250 |
amit.gupta |
424 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
425 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
426 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
427 |
if (x.getActiveTimestamp() != null) {
|
|
|
428 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
429 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
430 |
endDateTime = x.getExpireTimestamp();
|
| 24249 |
amit.gupta |
431 |
}
|
| 24250 |
amit.gupta |
432 |
for (SchemeInOut sio : sioList) {
|
|
|
433 |
InventoryItem inventoryItem = null;
|
| 24266 |
amit.gupta |
434 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 24271 |
amit.gupta |
435 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
436 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 24250 |
amit.gupta |
437 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
438 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
439 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
440 |
if (record.isPresent()) {
|
|
|
441 |
int fofoId = record.get().getFofoId();
|
|
|
442 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
443 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
444 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
445 |
userAmountMap.put(fofoId, 0f);
|
|
|
446 |
}
|
|
|
447 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
448 |
try {
|
| 24252 |
amit.gupta |
449 |
rows.add(Arrays.asList(x.getDescription(),
|
| 24250 |
amit.gupta |
450 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 24252 |
amit.gupta |
451 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 24253 |
amit.gupta |
452 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
453 |
fofoOrder.getInvoiceNumber(),
|
|
|
454 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
455 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
456 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
457 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
458 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 24250 |
amit.gupta |
459 |
} catch (Exception e) {
|
|
|
460 |
e.printStackTrace();
|
|
|
461 |
}
|
| 24242 |
amit.gupta |
462 |
}
|
| 24241 |
amit.gupta |
463 |
}
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
}
|
|
|
467 |
});
|
| 24246 |
amit.gupta |
468 |
userAmountMap.entrySet().stream()
|
|
|
469 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
470 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 24241 |
amit.gupta |
471 |
|
| 24252 |
amit.gupta |
472 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
473 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
474 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
|
|
475 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 24252 |
amit.gupta |
476 |
|
| 24241 |
amit.gupta |
477 |
}
|
| 24271 |
amit.gupta |
478 |
|
| 24256 |
amit.gupta |
479 |
public void processScheme(int offset) throws Exception {
|
| 24462 |
amit.gupta |
480 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24259 |
amit.gupta |
481 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 24258 |
amit.gupta |
482 |
processScheme(startDate, endDate);
|
| 24256 |
amit.gupta |
483 |
}
|
| 24533 |
govind |
484 |
|
| 24461 |
amit.gupta |
485 |
public void processScheme(int offset, int durationDays) throws Exception {
|
| 24462 |
amit.gupta |
486 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24461 |
amit.gupta |
487 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
|
|
488 |
processScheme(startDate, endDate);
|
|
|
489 |
}
|
| 24271 |
amit.gupta |
490 |
|
| 23738 |
amit.gupta |
491 |
public void processScheme() throws Exception {
|
| 24256 |
amit.gupta |
492 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
|
|
493 |
processScheme(fromDate, LocalDateTime.now());
|
|
|
494 |
}
|
| 24271 |
amit.gupta |
495 |
|
| 24256 |
amit.gupta |
496 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate) throws Exception {
|
| 23724 |
amit.gupta |
497 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 24561 |
amit.gupta |
498 |
try {
|
| 24587 |
amit.gupta |
499 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
500 |
for (Purchase purchase : purchases) {
|
|
|
501 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
502 |
}
|
| 24271 |
amit.gupta |
503 |
|
| 24587 |
amit.gupta |
504 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
505 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
506 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
507 |
}
|
|
|
508 |
} catch (Exception e) {
|
| 24561 |
amit.gupta |
509 |
e.printStackTrace();
|
| 24565 |
amit.gupta |
510 |
throw e;
|
| 24561 |
amit.gupta |
511 |
}
|
| 25043 |
amit.gupta |
512 |
List<UserWalletHistory> uwhs =userWalletHistoryRepository.selectAllByDateType(startDate, endDate, Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
|
|
513 |
System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
|
|
|
514 |
for(UserWalletHistory uwh : uwhs) {
|
|
|
515 |
System.out.println(String.format("%d\t%d\t%s\t%d\t%s", uwh.getAmount(), uwh.getReference(), uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
|
|
|
516 |
}
|
| 23724 |
amit.gupta |
517 |
LOGGER.info("Schemes process successfully.");
|
| 25043 |
amit.gupta |
518 |
throw new Exception();
|
| 23724 |
amit.gupta |
519 |
}
|
| 23929 |
amit.gupta |
520 |
|
| 23739 |
amit.gupta |
521 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
522 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
523 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
524 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
525 |
.getPendingCashBackRehargeTransactions();
|
|
|
526 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
527 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
528 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
529 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
530 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
531 |
if (Math.round(amount) > 0) {
|
|
|
532 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
|
|
533 |
"Recharge Cashback", Math.round(amount));
|
| 23762 |
amit.gupta |
534 |
}
|
| 23739 |
amit.gupta |
535 |
}
|
| 23929 |
amit.gupta |
536 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
537 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
538 |
rt.setCashbackReference(referenceId);
|
|
|
539 |
rechargeTransactionRepository.persist(rt);
|
|
|
540 |
}
|
| 23739 |
amit.gupta |
541 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
542 |
}
|
| 23724 |
amit.gupta |
543 |
|
| 24271 |
amit.gupta |
544 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
545 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 23929 |
amit.gupta |
546 |
List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
|
|
|
547 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
548 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
549 |
|
| 24271 |
amit.gupta |
550 |
List<String> headers = Arrays.asList("Code", "StoreName", "Email", "Mobile", "Wallet Amount",
|
|
|
551 |
"Yesterday's Sale", "In Stock Amount", "Return In Transit Stock", "Unbilled Amount",
|
|
|
552 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short");
|
| 24807 |
amit.gupta |
553 |
List<List<? extends Serializable>> rows = new ArrayList<>();
|
| 24002 |
amit.gupta |
554 |
for (FofoStore fofoStore : fofoStores) {
|
|
|
555 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
|
|
556 |
if (retailer == null) {
|
|
|
557 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
558 |
continue;
|
|
|
559 |
}
|
| 24533 |
govind |
560 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
|
|
|
561 |
1);
|
| 24337 |
amit.gupta |
562 |
partnerDailyInvestment.setDate(yesterDay);
|
|
|
563 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 24533 |
govind |
564 |
|
| 24841 |
govind |
565 |
List<? extends Serializable> row = Arrays.asList(fofoStore.getCode(), retailer.getBusinessName(),
|
|
|
566 |
retailer.getEmail(), retailer.getMobileNumber(), partnerDailyInvestment.getWalletAmount(),
|
| 24337 |
amit.gupta |
567 |
partnerDailyInvestment.getSalesAmount(), partnerDailyInvestment.getInStockAmount(), 0,
|
| 24415 |
amit.gupta |
568 |
partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
| 24533 |
govind |
569 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
|
|
570 |
partnerDailyInvestment.getShortInvestment());
|
| 24002 |
amit.gupta |
571 |
rows.add(row);
|
|
|
572 |
|
| 23929 |
amit.gupta |
573 |
}
|
| 24271 |
amit.gupta |
574 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 24002 |
amit.gupta |
575 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
576 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
|
|
577 |
|
|
|
578 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Partner Investment Summary", "PFA", fileName,
|
|
|
579 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
580 |
|
| 23929 |
amit.gupta |
581 |
}
|
| 24177 |
govind |
582 |
|
| 24271 |
amit.gupta |
583 |
public void sendPartnerInvestmentDetails() throws Exception {
|
|
|
584 |
List<String> sendTo = Arrays.asList("adeel.yazdani@smartdukaan.com", "amandeep.singh@smartdukaan.com",
|
|
|
585 |
"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "dhruv.kathpal@smartdukaan.com",
|
|
|
586 |
"neeraj.gupta@smartdukaan.com");
|
|
|
587 |
this.sendPartnerInvestmentDetails(sendTo);
|
|
|
588 |
|
|
|
589 |
}
|
|
|
590 |
|
| 24177 |
govind |
591 |
private void sendMailWithAttachments(String[] email, String[] ccEmails, String body, String subject,
|
| 24187 |
govind |
592 |
Map<String, InputStream> inputStreams)
|
| 24177 |
govind |
593 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 24121 |
govind |
594 |
MimeMessage message = mailSender.createMimeMessage();
|
| 24177 |
govind |
595 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
596 |
helper.setSubject(subject);
|
|
|
597 |
helper.setText(body);
|
|
|
598 |
if (ccEmails != null) {
|
|
|
599 |
helper.setCc(ccEmails);
|
|
|
600 |
}
|
| 24240 |
amit.gupta |
601 |
for (String attachment : inputStreams.keySet()) {
|
|
|
602 |
helper.addAttachment(attachment + "_" + LocalDate.now() + ".xls",
|
|
|
603 |
new ByteArrayResource(IOUtils.toByteArray(inputStreams.get(attachment))));
|
| 24187 |
govind |
604 |
}
|
| 24177 |
govind |
605 |
helper.setTo(email);
|
| 24195 |
govind |
606 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24177 |
govind |
607 |
helper.setFrom(senderAddress);
|
|
|
608 |
mailSender.send(message);
|
| 24135 |
govind |
609 |
}
|
| 24240 |
amit.gupta |
610 |
|
|
|
611 |
private void sendMailWithAttachmentsForPartners(String email, String body, String subject, InputStream is)
|
| 24184 |
govind |
612 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
613 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
614 |
MimeMessageHelper helper = new MimeMessageHelper(message, true, CharEncoding.UTF_8);
|
|
|
615 |
helper.setSubject(subject);
|
|
|
616 |
helper.setText(body);
|
| 24240 |
amit.gupta |
617 |
helper.addAttachment("DailySaleTargetReports_" + LocalDate.now() + ".xls",
|
|
|
618 |
new ByteArrayResource(IOUtils.toByteArray(is)));
|
| 24184 |
govind |
619 |
helper.setTo(email);
|
| 24195 |
govind |
620 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 24184 |
govind |
621 |
helper.setFrom(senderAddress);
|
|
|
622 |
mailSender.send(message);
|
|
|
623 |
}
|
| 24177 |
govind |
624 |
|
|
|
625 |
public void sendMailToSalesHeadAboutTargetAndSales(SaleHeadDetails salesHeadDetail)
|
|
|
626 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
627 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
628 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
629 |
Map<String, InputStream> inputStreams = new HashMap<>();
|
|
|
630 |
for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
|
|
|
631 |
InputStream is = targetService.getDailySaleReportVsTargetForSaleHead(partnerTargetDetail,
|
|
|
632 |
salesHeadDetail.getName());
|
| 24240 |
amit.gupta |
633 |
|
| 24177 |
govind |
634 |
inputStreams.put(partnerTargetDetail.getTargetName(), is);
|
|
|
635 |
|
| 24174 |
govind |
636 |
}
|
| 24240 |
amit.gupta |
637 |
// String[] ccEmails = null;
|
| 24271 |
amit.gupta |
638 |
if (partnerTargetDetails.size() > 0) {
|
| 24254 |
govind |
639 |
String[] ccEmails = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
|
|
640 |
"chaitnaya.vats@smartdukaan.com", "dhruv.kathpal@smartdukaan.com" };
|
|
|
641 |
String subject = "Daily Sales Report ";
|
|
|
642 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
|
|
643 |
LOGGER.info("message" + message);
|
|
|
644 |
if (salesHeadDetail.getName().equals("Kamal")) {
|
|
|
645 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
646 |
String[] to = { salesHeadDetail.getEmail(), "mohinder.mutreja@smartdukaan.com" };
|
| 24177 |
govind |
647 |
|
| 24271 |
amit.gupta |
648 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
| 24177 |
govind |
649 |
|
| 24271 |
amit.gupta |
650 |
} else {
|
|
|
651 |
LOGGER.info("salesHeadDetail.getName()" + salesHeadDetail.getName());
|
|
|
652 |
String[] to = { salesHeadDetail.getEmail() };
|
|
|
653 |
this.sendMailWithAttachments(to, ccEmails, message, subject, inputStreams);
|
|
|
654 |
}
|
| 24177 |
govind |
655 |
}
|
| 24121 |
govind |
656 |
}
|
| 24177 |
govind |
657 |
|
| 24240 |
amit.gupta |
658 |
public void sendMailToPartnerAboutTargetAndSales() throws ProfitMandiBusinessException, MessagingException,
|
|
|
659 |
IOException, EncryptedDocumentException, InvalidFormatException {
|
| 24177 |
govind |
660 |
List<Integer> fofoIds = targetService.getfofoIdsFromfofoStore();
|
|
|
661 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService
|
|
|
662 |
.getFofoRetailers(new ArrayList<>(fofoIds));
|
|
|
663 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
664 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
|
|
665 |
for (Integer fofoId : fofoIds) {
|
| 24240 |
amit.gupta |
666 |
InputStream is = targetService.getDailySaleReportVsTargetForPartner(fofoId, partnerTargetDetails);
|
|
|
667 |
LOGGER.info("is" + is);
|
|
|
668 |
if (is == null) {
|
| 24192 |
govind |
669 |
continue;
|
|
|
670 |
}
|
| 24240 |
amit.gupta |
671 |
LOGGER.info("fofoId" + fofoId);
|
|
|
672 |
|
| 24177 |
govind |
673 |
LOGGER.info(fofoIdsAndCustomRetailer.get(fofoId).getEmail());
|
| 24240 |
amit.gupta |
674 |
String subject = "Daily Sales Report";
|
|
|
675 |
String message = MessageFormat.format("Sale Target summary for {0}", LocalDate.now());
|
| 24177 |
govind |
676 |
LOGGER.info(message);
|
| 24240 |
amit.gupta |
677 |
this.sendMailWithAttachmentsForPartners(fofoIdsAndCustomRetailer.get(fofoId).getEmail(), message, subject,
|
|
|
678 |
is);
|
|
|
679 |
|
| 24174 |
govind |
680 |
}
|
|
|
681 |
}
|
| 24683 |
amit.gupta |
682 |
|
| 24697 |
amit.gupta |
683 |
public void sendAgeingReport(String... sendTo) throws Exception {
|
| 24692 |
amit.gupta |
684 |
|
|
|
685 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
|
|
|
686 |
"itemstockageing.xml");
|
| 24708 |
amit.gupta |
687 |
InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 24754 |
amit.gupta |
688 |
"ItemwiseOverallPendingIndent.xml");
|
| 24683 |
amit.gupta |
689 |
Attachment attachment = new Attachment(
|
| 24692 |
amit.gupta |
690 |
"aeging-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
|
| 24707 |
amit.gupta |
691 |
Attachment attachment1 = new Attachment(
|
|
|
692 |
"aeging-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
|
| 24841 |
govind |
693 |
Utils.sendMailWithAttachments(googleMailSender, sendTo, null, "Stock Aeging Report", "PFA", attachment,
|
|
|
694 |
attachment1);
|
| 24681 |
amit.gupta |
695 |
}
|
| 24533 |
govind |
696 |
|
| 24697 |
amit.gupta |
697 |
public void sendAgeingReport() throws Exception {
|
|
|
698 |
sendAgeingReport("amod.sen@smartdukaan.com", "adeel.yazdani@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
|
|
699 |
"tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com", "mohinder.mutreja@smartdukaan.com");
|
|
|
700 |
}
|
|
|
701 |
|
| 24533 |
govind |
702 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
703 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
704 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
705 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
706 |
}
|
|
|
707 |
}
|
| 23929 |
amit.gupta |
708 |
|
| 24542 |
amit.gupta |
709 |
public void walletmismatch() throws Exception {
|
|
|
710 |
LocalDate curDate = LocalDate.now();
|
| 24553 |
amit.gupta |
711 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 24552 |
amit.gupta |
712 |
System.out.println(pdis.size());
|
| 24542 |
amit.gupta |
713 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 24549 |
amit.gupta |
714 |
int fofoId = pdi.getFofoId();
|
| 24542 |
amit.gupta |
715 |
for (PartnerDailyInvestment investment : Lists
|
|
|
716 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 24552 |
amit.gupta |
717 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 24555 |
amit.gupta |
718 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 24552 |
amit.gupta |
719 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 24841 |
govind |
720 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
|
|
|
721 |
investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
|
| 24551 |
amit.gupta |
722 |
|
| 24542 |
amit.gupta |
723 |
}
|
| 24549 |
amit.gupta |
724 |
}
|
| 24542 |
amit.gupta |
725 |
|
|
|
726 |
}
|
|
|
727 |
|
|
|
728 |
public void gst() throws Exception {
|
| 24548 |
amit.gupta |
729 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2019, 1, 26).atStartOfDay(),
|
|
|
730 |
LocalDate.of(2019, 1, 27).atTime(LocalTime.MAX));
|
|
|
731 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
732 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
733 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 24542 |
amit.gupta |
734 |
|
|
|
735 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
736 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
737 |
Integer stateId = null;
|
|
|
738 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
739 |
try {
|
|
|
740 |
stateId = Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
|
|
|
741 |
} catch (Exception e) {
|
|
|
742 |
LOGGER.error("Unable to get state rates");
|
|
|
743 |
}
|
|
|
744 |
}
|
|
|
745 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
746 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 24548 |
amit.gupta |
747 |
|
|
|
748 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
749 |
Set<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 24542 |
amit.gupta |
750 |
if (stateId != null) {
|
|
|
751 |
itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemIds), stateId);
|
|
|
752 |
} else {
|
|
|
753 |
itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemIds));
|
|
|
754 |
}
|
|
|
755 |
|
| 24548 |
amit.gupta |
756 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 24542 |
amit.gupta |
757 |
if (stateId == null) {
|
|
|
758 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
|
|
759 |
} else {
|
|
|
760 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
|
|
761 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
|
|
762 |
}
|
|
|
763 |
fofoOrderItemRepository.persist(foi);
|
|
|
764 |
}
|
|
|
765 |
}
|
| 24548 |
amit.gupta |
766 |
|
| 24542 |
amit.gupta |
767 |
}
|
|
|
768 |
|
| 24580 |
amit.gupta |
769 |
public void schemewalletmismatch() {
|
|
|
770 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
| 24587 |
amit.gupta |
771 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
| 24580 |
amit.gupta |
772 |
reconcileSchemes(dateToReconcile);
|
| 24587 |
amit.gupta |
773 |
// reconcileOrders(dateTime);
|
|
|
774 |
// reconcileRecharges(dateTime);
|
| 24580 |
amit.gupta |
775 |
dateToReconcile = dateToReconcile.plusDays(1);
|
|
|
776 |
}
|
|
|
777 |
}
|
|
|
778 |
|
|
|
779 |
private void reconcileSchemes(LocalDate date) {
|
|
|
780 |
LocalDateTime startDate = date.atStartOfDay();
|
|
|
781 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
782 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
|
|
783 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
| 24587 |
amit.gupta |
784 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
785 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 24580 |
amit.gupta |
786 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
| 24587 |
amit.gupta |
787 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
|
|
788 |
WalletReferenceType.SCHEME_OUT);
|
|
|
789 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
790 |
walletReferenceTypes);
|
|
|
791 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
792 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
| 24580 |
amit.gupta |
793 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
| 24587 |
amit.gupta |
794 |
|
|
|
795 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
|
|
796 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
797 |
|
|
|
798 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
|
|
799 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
800 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
|
|
801 |
|
|
|
802 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
|
|
803 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
804 |
|
|
|
805 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
|
|
806 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
|
|
807 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
808 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
|
|
809 |
|
|
|
810 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
|
|
811 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeMap.entrySet()) {
|
|
|
812 |
}
|
|
|
813 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
|
|
814 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
|
|
815 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
|
|
816 |
} else {
|
|
|
817 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
|
|
818 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
|
|
819 |
}
|
|
|
820 |
}
|
| 24590 |
amit.gupta |
821 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
|
|
822 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
|
|
823 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
824 |
|
| 24587 |
amit.gupta |
825 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
|
|
826 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
|
|
827 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
|
|
828 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
|
|
829 |
if (diff > 5) {
|
|
|
830 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
|
|
831 |
}
|
|
|
832 |
}
|
| 24580 |
amit.gupta |
833 |
}
|
| 24587 |
amit.gupta |
834 |
|
| 24580 |
amit.gupta |
835 |
}
|
| 24590 |
amit.gupta |
836 |
|
| 24592 |
amit.gupta |
837 |
public void dryRunSchemeReco() throws Exception {
|
| 24635 |
amit.gupta |
838 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
839 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
840 |
|
| 24592 |
amit.gupta |
841 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
842 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24635 |
amit.gupta |
843 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
844 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
845 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
|
|
846 |
|
| 25032 |
amit.gupta |
847 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
| 24635 |
amit.gupta |
848 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
|
|
849 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
850 |
|
| 24683 |
amit.gupta |
851 |
Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
|
| 24635 |
amit.gupta |
852 |
purchases.stream().forEach(purchase -> {
|
|
|
853 |
float amountToRollback = 0;
|
|
|
854 |
String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
|
|
|
855 |
+ purchase.getPurchaseReference();
|
|
|
856 |
Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
|
|
|
857 |
.stream().filter(ii -> ii.getSerialNumber() != null)
|
|
|
858 |
.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
|
|
|
859 |
if (inventorySerialNumberMap.size() > 0) {
|
|
|
860 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
861 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
862 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
863 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
864 |
// This will rollback scheme for differenct orders for same serial
|
|
|
865 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
866 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
867 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
868 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
869 |
.collect(Collectors.toList());
|
|
|
870 |
Collections.reverse(sios);
|
|
|
871 |
for (SchemeInOut sio : sios) {
|
|
|
872 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
873 |
amountToRollback += sio.getAmount();
|
|
|
874 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
875 |
sio.setSerialNumber(serialNumber);
|
|
|
876 |
rolledbackSios.add(sio);
|
|
|
877 |
}
|
|
|
878 |
description = description.concat(" " + serialNumber + " ");
|
|
|
879 |
} else {
|
|
|
880 |
serialNumbersConsidered.add(serialNumber);
|
|
|
881 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
882 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
883 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
884 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
885 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
886 |
.collect(Collectors.toList());
|
|
|
887 |
Collections.reverse(sios);
|
|
|
888 |
for (SchemeInOut sio : sios) {
|
|
|
889 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
890 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
891 |
continue;
|
|
|
892 |
}
|
|
|
893 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
894 |
amountToRollback += sio.getAmount();
|
|
|
895 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
896 |
sio.setSerialNumber(serialNumber);
|
| 24681 |
amit.gupta |
897 |
sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
|
|
898 |
sio.setReference(purchase.getId());
|
| 24635 |
amit.gupta |
899 |
rolledbackSios.add(sio);
|
|
|
900 |
}
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
}
|
|
|
904 |
}
|
|
|
905 |
if (amountToRollback > 0) {
|
| 24683 |
amit.gupta |
906 |
// Address address =
|
|
|
907 |
// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
|
| 24635 |
amit.gupta |
908 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
909 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
910 |
uwh.setDescription(description);
|
|
|
911 |
uwh.setTimestamp(LocalDateTime.now());
|
| 24681 |
amit.gupta |
912 |
uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
|
| 24635 |
amit.gupta |
913 |
uwh.setReference(purchase.getId());
|
|
|
914 |
uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
|
|
|
915 |
uwh.setFofoId(purchase.getFofoId());
|
| 24681 |
amit.gupta |
916 |
uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
| 24635 |
amit.gupta |
917 |
userWalletHistory.add(uwh);
|
|
|
918 |
}
|
|
|
919 |
});
|
|
|
920 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
921 |
Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
|
|
922 |
"Timestamp"),
|
|
|
923 |
userWalletHistory.stream()
|
|
|
924 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
925 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
|
|
926 |
.collect(Collectors.toList()));
|
|
|
927 |
|
|
|
928 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 24683 |
amit.gupta |
929 |
Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
|
|
|
930 |
"Created", "Rolledback"),
|
| 24635 |
amit.gupta |
931 |
rolledbackSios.stream()
|
| 24681 |
amit.gupta |
932 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
|
| 24635 |
amit.gupta |
933 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
934 |
.collect(Collectors.toList()));
|
|
|
935 |
|
| 25043 |
amit.gupta |
936 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24636 |
amit.gupta |
937 |
"Partner Excess Amount Scheme In", "PFA",
|
| 24635 |
amit.gupta |
938 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
| 24636 |
amit.gupta |
939 |
new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24635 |
amit.gupta |
940 |
|
| 25043 |
amit.gupta |
941 |
// throw new Exception();
|
| 24635 |
amit.gupta |
942 |
|
|
|
943 |
}
|
|
|
944 |
|
|
|
945 |
public void dryRunOutSchemeReco() throws Exception {
|
|
|
946 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
947 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24606 |
amit.gupta |
948 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
949 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 24590 |
amit.gupta |
950 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
951 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 25028 |
amit.gupta |
952 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
| 24632 |
amit.gupta |
953 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
| 24631 |
amit.gupta |
954 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
955 |
// Collections.reverse(allOrders);
|
|
|
956 |
// List<FofoOrder> allOrders =
|
| 24653 |
govind |
957 |
// List<FofoOrder> allOrders =
|
| 24631 |
amit.gupta |
958 |
// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
|
| 24625 |
amit.gupta |
959 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
| 24590 |
amit.gupta |
960 |
allOrders.stream().forEach(fofoOrder -> {
|
| 24592 |
amit.gupta |
961 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 24598 |
amit.gupta |
962 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
| 24592 |
amit.gupta |
963 |
float amountToRollback = 0;
|
| 24590 |
amit.gupta |
964 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
965 |
orderItems.forEach(x -> {
|
| 24606 |
amit.gupta |
966 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
| 24598 |
amit.gupta |
967 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
| 24590 |
amit.gupta |
968 |
});
|
| 24606 |
amit.gupta |
969 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24631 |
amit.gupta |
970 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
971 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
972 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
973 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
974 |
// This will rollback scheme for differenct orders for same serial
|
|
|
975 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
976 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
977 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
978 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
979 |
.collect(Collectors.toList());
|
|
|
980 |
Collections.reverse(sios);
|
|
|
981 |
for (SchemeInOut sio : sios) {
|
|
|
982 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
983 |
amountToRollback += sio.getAmount();
|
|
|
984 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
985 |
sio.setSerialNumber(serialNumber);
|
|
|
986 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 24681 |
amit.gupta |
987 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
988 |
rolledbackSios.add(sio);
|
| 24623 |
amit.gupta |
989 |
}
|
| 24635 |
amit.gupta |
990 |
description = description.concat(" " + serialNumber + " ");
|
| 24631 |
amit.gupta |
991 |
} else {
|
|
|
992 |
serialNumbersConsidered.add(serialNumber);
|
|
|
993 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
994 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
995 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
996 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
997 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
998 |
.collect(Collectors.toList());
|
|
|
999 |
Collections.reverse(sios);
|
|
|
1000 |
for (SchemeInOut sio : sios) {
|
|
|
1001 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1002 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1003 |
continue;
|
|
|
1004 |
}
|
|
|
1005 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1006 |
amountToRollback += sio.getAmount();
|
|
|
1007 |
// sio.setSchemeType(SchemeType.OUT);
|
| 24681 |
amit.gupta |
1008 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1009 |
sio.setSerialNumber(serialNumber);
|
|
|
1010 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1011 |
rolledbackSios.add(sio);
|
|
|
1012 |
}
|
| 24615 |
amit.gupta |
1013 |
}
|
| 24631 |
amit.gupta |
1014 |
|
| 24604 |
amit.gupta |
1015 |
}
|
| 24590 |
amit.gupta |
1016 |
}
|
| 24631 |
amit.gupta |
1017 |
if (amountToRollback > 0) {
|
|
|
1018 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1019 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1020 |
uwh.setDescription(description);
|
|
|
1021 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1022 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1023 |
uwh.setReference(fofoOrder.getId());
|
|
|
1024 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1025 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1026 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1027 |
userWalletHistory.add(uwh);
|
|
|
1028 |
}
|
| 24590 |
amit.gupta |
1029 |
});
|
| 24598 |
amit.gupta |
1030 |
|
| 24592 |
amit.gupta |
1031 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 24681 |
amit.gupta |
1032 |
Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
| 24615 |
amit.gupta |
1033 |
"Timestamp"),
|
|
|
1034 |
userWalletHistory.stream()
|
|
|
1035 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1036 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24592 |
amit.gupta |
1037 |
.collect(Collectors.toList()));
|
|
|
1038 |
|
|
|
1039 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1040 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1041 |
"Rolledback"),
|
|
|
1042 |
rolledbackSios.stream()
|
|
|
1043 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1044 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1045 |
.collect(Collectors.toList()));
|
|
|
1046 |
|
| 25043 |
amit.gupta |
1047 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24681 |
amit.gupta |
1048 |
"Partner Excess Amount Scheme Out", "PFA",
|
| 24598 |
amit.gupta |
1049 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1050 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1051 |
|
| 25043 |
amit.gupta |
1052 |
// throw new Exception();
|
| 24590 |
amit.gupta |
1053 |
}
|
| 24615 |
amit.gupta |
1054 |
|
| 24611 |
amit.gupta |
1055 |
public void dryRunSchemeOutReco1() throws Exception {
|
| 24615 |
amit.gupta |
1056 |
List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
|
| 24611 |
amit.gupta |
1057 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1058 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
|
|
1059 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1060 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1061 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1062 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1063 |
references.stream().forEach(reference -> {
|
|
|
1064 |
FofoOrder fofoOrder = null;
|
|
|
1065 |
try {
|
|
|
1066 |
fofoOrder = fofoOrderRepository.selectByOrderId(reference);
|
| 24615 |
amit.gupta |
1067 |
} catch (Exception e) {
|
|
|
1068 |
|
| 24611 |
amit.gupta |
1069 |
}
|
|
|
1070 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
|
|
1071 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
|
|
1072 |
float amountToRollback = 0;
|
|
|
1073 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1074 |
orderItems.forEach(x -> {
|
|
|
1075 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
|
|
1076 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
|
|
1077 |
});
|
|
|
1078 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24615 |
amit.gupta |
1079 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1080 |
.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
|
|
|
1081 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24611 |
amit.gupta |
1082 |
.collect(Collectors.toList());
|
|
|
1083 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
|
|
1084 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 24615 |
amit.gupta |
1085 |
Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
|
|
|
1086 |
.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
|
| 24611 |
amit.gupta |
1087 |
for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
|
|
|
1088 |
List<SchemeInOut> outList = inventorySioEntry.getValue();
|
| 24615 |
amit.gupta |
1089 |
if (outList.size() > 1) {
|
|
|
1090 |
|
| 24611 |
amit.gupta |
1091 |
}
|
|
|
1092 |
}
|
|
|
1093 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1094 |
uwh.setDescription(description);
|
|
|
1095 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1096 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1097 |
uwh.setReference(fofoOrder.getId());
|
|
|
1098 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1099 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1100 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1101 |
userWalletHistory.add(uwh);
|
|
|
1102 |
}
|
|
|
1103 |
});
|
| 24615 |
amit.gupta |
1104 |
|
| 24611 |
amit.gupta |
1105 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1106 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
|
|
1107 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
|
|
1108 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24615 |
amit.gupta |
1109 |
.collect(Collectors.toList()));
|
|
|
1110 |
|
| 24611 |
amit.gupta |
1111 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1112 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1113 |
"Rolledback"),
|
|
|
1114 |
rolledbackSios.stream()
|
| 24615 |
amit.gupta |
1115 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1116 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1117 |
.collect(Collectors.toList()));
|
|
|
1118 |
|
| 24623 |
amit.gupta |
1119 |
Utils.sendMailWithAttachments(googleMailSender,
|
|
|
1120 |
new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
|
| 24611 |
amit.gupta |
1121 |
"Partner Excess Amount", "PFA",
|
|
|
1122 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1123 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1124 |
|
| 24628 |
amit.gupta |
1125 |
throw new Exception();
|
| 24615 |
amit.gupta |
1126 |
|
| 24611 |
amit.gupta |
1127 |
}
|
| 24615 |
amit.gupta |
1128 |
|
| 24855 |
amit.gupta |
1129 |
public void sendDailySalesReportNotificationToPartner(Integer fofoIdInt)
|
| 24653 |
govind |
1130 |
throws ProfitMandiBusinessException, MessagingException, IOException {
|
|
|
1131 |
LocalDateTime now = LocalDateTime.now();
|
|
|
1132 |
LocalDateTime from = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 00, 00);
|
|
|
1133 |
Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
|
| 24855 |
amit.gupta |
1134 |
List<Integer> fofoIds = null;
|
| 25043 |
amit.gupta |
1135 |
if (fofoIdInt == null) {
|
|
|
1136 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
1137 |
.collect(Collectors.toList());
|
| 24856 |
amit.gupta |
1138 |
} else {
|
| 24855 |
amit.gupta |
1139 |
fofoIds = Arrays.asList(fofoIdInt);
|
|
|
1140 |
}
|
| 24653 |
govind |
1141 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
1142 |
.selectAllGeEqAndLeEqStartDateAndEndDate(now);
|
| 24683 |
amit.gupta |
1143 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h a");
|
|
|
1144 |
|
|
|
1145 |
Map<Integer, Float> dailyTarget = new HashMap<>();
|
| 24653 |
govind |
1146 |
for (Integer fofoId : fofoIds) {
|
| 24683 |
amit.gupta |
1147 |
Map<Integer, Float> dailyAverageSale = null;
|
| 24653 |
govind |
1148 |
double sale = fofoOrderRepository.selectTotalSaleSumByFofoIdBrtweenDate(fofoId, from, now);
|
|
|
1149 |
for (PartnerTargetDetails partnerTargetDetail : partnerTargetDetails) {
|
|
|
1150 |
Map<Integer, Float> targetValues = targetService.getTargetValueByFofoIdAndTargetId(fofoId,
|
|
|
1151 |
partnerTargetDetail.getId());
|
|
|
1152 |
if (targetValues.size() == 0) {
|
|
|
1153 |
continue;
|
|
|
1154 |
} else {
|
|
|
1155 |
List<Integer> partnerIds = new ArrayList<>();
|
|
|
1156 |
partnerIds.add(fofoId);
|
|
|
1157 |
dailyAverageSale = targetService.getDailyAverageSaleForCurrentForSingleFofoIdAndBrand(partnerIds,
|
|
|
1158 |
targetValues, partnerTargetDetail.getStartDate(), partnerTargetDetail.getEndDate(),
|
|
|
1159 |
partnerTargetDetail.getBrandName());
|
|
|
1160 |
dailyTarget.put(fofoId, dailyAverageSale.get(fofoId));
|
|
|
1161 |
break;
|
|
|
1162 |
}
|
|
|
1163 |
}
|
|
|
1164 |
NotificationCampaigns notification = new NotificationCampaigns();
|
| 24847 |
amit.gupta |
1165 |
notification.setName("Daily Sales");
|
|
|
1166 |
notification.setTitle("Daily Sale Update");
|
| 24683 |
amit.gupta |
1167 |
if (dailyAverageSale != null && dailyAverageSale.get(fofoId) != null) {
|
| 24864 |
amit.gupta |
1168 |
notification.setMessage(String.format("Rs.%.0f till %s. Today's Target is Rs.%.0f", sale,
|
| 24847 |
amit.gupta |
1169 |
now.format(timeFormatter), dailyAverageSale.get(fofoId)));
|
| 24683 |
amit.gupta |
1170 |
} else {
|
| 25043 |
amit.gupta |
1171 |
notification.setMessage(String.format("Rs.%.0f till %s", sale, now.format(timeFormatter)));
|
| 24653 |
govind |
1172 |
}
|
| 24683 |
amit.gupta |
1173 |
// notification.setMessage("Your sale is "+salesbyfofoId.get(fofoId));
|
| 24989 |
tejbeer |
1174 |
notification.setType("url");
|
| 24863 |
govind |
1175 |
notification.setUrl("http://app.profitmandi.com/pages/home/notifications");
|
| 24683 |
amit.gupta |
1176 |
LOGGER.info("UserID" + userAccountRepository.selectUserIdByRetailerId(fofoId));
|
|
|
1177 |
notification.setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
|
|
|
1178 |
+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
|
|
|
1179 |
+ " where d2.id is null and d1.user_id = "
|
|
|
1180 |
+ userAccountRepository.selectUserIdByRetailerId(fofoId));
|
| 24676 |
govind |
1181 |
LOGGER.info("SELECT distinct d1.user_id from devices d1 left join devices d2 on"
|
| 24683 |
amit.gupta |
1182 |
+ "(d1.imeinumber = d2.imeinumber and d1.created < d2.created) "
|
|
|
1183 |
+ " where d2.id is null and d1.user_id = "
|
|
|
1184 |
+ userAccountRepository.selectUserIdByRetailerId(fofoId));
|
| 24667 |
govind |
1185 |
notification.setExpiresat(LocalDateTime.now().plusDays(1).toEpochSecond(ZoneOffset.UTC) * 1000);
|
| 24653 |
govind |
1186 |
notification.setStatus("active");
|
|
|
1187 |
notification.setSmsprocessed(0);
|
|
|
1188 |
notification.setNotification_processed(0);
|
|
|
1189 |
notification.setNotification_type("GENERAL_NOTIFICATION");
|
| 24657 |
govind |
1190 |
mongoClient.persistNotificationCmpInfo(notification);
|
| 24653 |
govind |
1191 |
salesByFofoIdMap.put(fofoId, sale);
|
|
|
1192 |
LOGGER.info(sale);
|
|
|
1193 |
}
|
| 24683 |
amit.gupta |
1194 |
String saleReport = this.getDailySalesReportByPartnerId(salesByFofoIdMap, dailyTarget);
|
| 24653 |
govind |
1195 |
LOGGER.info(saleReport);
|
|
|
1196 |
String cc[] = { "Tarun.verma@smartdukaan.com", "Kamini.sharma@smartdukaan.com",
|
| 24697 |
amit.gupta |
1197 |
"chaitnaya.vats@smartdukaan.com", "adeel.yazdani@smartdukaan.com", "mohinder.mutreja@smartdukaan.com" };
|
| 24653 |
govind |
1198 |
String subject = "sale report till" + " " + now.format(timeFormatter);
|
| 24677 |
govind |
1199 |
this.sendMailOfHtmlFomat("amod.sen@smartdukaan.com", saleReport, cc, subject);
|
| 24653 |
govind |
1200 |
}
|
|
|
1201 |
|
| 24683 |
amit.gupta |
1202 |
public String getDailySalesReportByPartnerId(Map<Integer, Double> salesByFofoIdMap, Map<Integer, Float> dailyTarget)
|
| 24653 |
govind |
1203 |
throws ProfitMandiBusinessException {
|
|
|
1204 |
StringBuilder sb = new StringBuilder();
|
|
|
1205 |
sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
1206 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
1207 |
+ " <th style='border:1px solid black;padding: 5px'>Partner</th>\n"
|
|
|
1208 |
+ " <th style='border:1px solid black;padding: 5px'>Daily Target</th>\n"
|
|
|
1209 |
+ " <th style='border:1px solid black;padding: 5px'>Sale</th>\n"
|
|
|
1210 |
+ " </tr>");
|
|
|
1211 |
for (Integer fofoId : salesByFofoIdMap.keySet()) {
|
| 25043 |
amit.gupta |
1212 |
try {
|
|
|
1213 |
String PartnerName = retailerService.getFofoRetailer(fofoId).getBusinessName();
|
|
|
1214 |
sb.append("<tr>");
|
|
|
1215 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + PartnerName + "</td>");
|
|
|
1216 |
if (dailyTarget != null && dailyTarget.get(fofoId) != null) {
|
|
|
1217 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + dailyTarget.get(fofoId) + "</td>");
|
|
|
1218 |
} else {
|
|
|
1219 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + 0.0 + "</td>");
|
|
|
1220 |
}
|
|
|
1221 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + salesByFofoIdMap.get(fofoId) + "</td>");
|
| 24653 |
govind |
1222 |
|
| 25043 |
amit.gupta |
1223 |
sb.append("</tr>");
|
|
|
1224 |
} catch (Exception e) {
|
| 24842 |
govind |
1225 |
e.printStackTrace();
|
|
|
1226 |
}
|
| 25043 |
amit.gupta |
1227 |
|
| 24653 |
govind |
1228 |
}
|
| 24683 |
amit.gupta |
1229 |
|
| 24653 |
govind |
1230 |
sb.append("</tbody></table></body></html>");
|
|
|
1231 |
return sb.toString();
|
|
|
1232 |
}
|
| 24841 |
govind |
1233 |
|
|
|
1234 |
private void sendMailOfHtmlFomat(String email, String body, String cc[], String subject)
|
|
|
1235 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
1236 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
1237 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
1238 |
helper.setSubject(subject);
|
|
|
1239 |
helper.setText(body, true);
|
|
|
1240 |
helper.setTo(email);
|
|
|
1241 |
if (cc != null) {
|
|
|
1242 |
helper.setCc(cc);
|
|
|
1243 |
}
|
|
|
1244 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
1245 |
helper.setFrom(senderAddress);
|
|
|
1246 |
mailSender.send(message);
|
|
|
1247 |
}
|
| 24587 |
amit.gupta |
1248 |
}
|