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