| 28217 |
tejbeer |
1 |
package com.smartdukaan.cron.scheduled;
|
| 23723 |
amit.gupta |
2 |
|
| 24542 |
amit.gupta |
3 |
import com.google.common.collect.Lists;
|
| 25300 |
tejbeer |
4 |
import com.google.gson.Gson;
|
| 29488 |
manish |
5 |
import com.razorpay.Payment;
|
|
|
6 |
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
|
|
|
7 |
import com.smartdukaan.cron.itelImeiActivation.TecnoImeiActivation;
|
| 25721 |
tejbeer |
8 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 23724 |
amit.gupta |
9 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24681 |
amit.gupta |
10 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 24121 |
govind |
11 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30119 |
amit.gupta |
12 |
import com.spice.profitmandi.common.model.*;
|
| 24681 |
amit.gupta |
13 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 29814 |
tejbeer |
14 |
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
|
|
|
15 |
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
|
|
|
16 |
import com.spice.profitmandi.common.services.mandii.MandiiService;
|
| 24002 |
amit.gupta |
17 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
18 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 27678 |
amit.gupta |
19 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 23929 |
amit.gupta |
20 |
import com.spice.profitmandi.common.util.Utils;
|
| 24592 |
amit.gupta |
21 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| 29308 |
tejbeer |
22 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 25300 |
tejbeer |
23 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
| 25590 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30421 |
tejbeer |
25 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
| 25800 |
tejbeer |
26 |
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
|
| 25609 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 24590 |
amit.gupta |
28 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 25590 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 26283 |
tejbeer |
30 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 28769 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 30119 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 30390 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
|
| 27208 |
tejbeer |
35 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
|
|
|
36 |
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
|
| 30119 |
amit.gupta |
37 |
import com.spice.profitmandi.dao.entity.transaction.*;
|
|
|
38 |
import com.spice.profitmandi.dao.entity.user.*;
|
| 30421 |
tejbeer |
39 |
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
|
| 24250 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 25598 |
amit.gupta |
41 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 26790 |
tejbeer |
42 |
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
|
| 29814 |
tejbeer |
43 |
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
|
| 24242 |
amit.gupta |
44 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 25609 |
amit.gupta |
45 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 30390 |
amit.gupta |
46 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
| 30421 |
tejbeer |
47 |
import com.spice.profitmandi.dao.model.PartnerCollectionRemarkModel;
|
| 25300 |
tejbeer |
48 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
|
|
49 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 25590 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 30421 |
tejbeer |
51 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 30119 |
amit.gupta |
52 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
|
|
53 |
import com.spice.profitmandi.dao.repository.cs.*;
|
|
|
54 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
|
|
55 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 30390 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
|
| 28990 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 28775 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
| 30119 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| 24542 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 25721 |
tejbeer |
61 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 25854 |
amit.gupta |
62 |
import com.spice.profitmandi.service.NotificationService;
|
| 24337 |
amit.gupta |
63 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 30390 |
amit.gupta |
64 |
import com.spice.profitmandi.service.PartnerStatsService;
|
| 28368 |
tejbeer |
65 |
import com.spice.profitmandi.service.integrations.RazorpayPaymentService;
|
| 25694 |
amit.gupta |
66 |
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
|
| 23929 |
amit.gupta |
67 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 27208 |
tejbeer |
68 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 25335 |
amit.gupta |
69 |
import com.spice.profitmandi.service.order.OrderService;
|
| 24431 |
amit.gupta |
70 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
71 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
72 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
73 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 29668 |
tejbeer |
74 |
import com.spice.profitmandi.service.serviceConfig.ServiceConfigService;
|
| 23929 |
amit.gupta |
75 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
76 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
77 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 25721 |
tejbeer |
78 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 29308 |
tejbeer |
79 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
80 |
import okhttp3.OkHttpClient;
|
|
|
81 |
import okhttp3.Request;
|
| 30119 |
amit.gupta |
82 |
import okhttp3.Response;
|
|
|
83 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
84 |
import org.apache.commons.lang.StringUtils;
|
|
|
85 |
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
86 |
import org.apache.http.client.methods.HttpPost;
|
|
|
87 |
import org.apache.http.entity.StringEntity;
|
|
|
88 |
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
89 |
import org.apache.http.impl.client.HttpClients;
|
|
|
90 |
import org.apache.logging.log4j.LogManager;
|
|
|
91 |
import org.apache.logging.log4j.Logger;
|
|
|
92 |
import org.json.JSONArray;
|
|
|
93 |
import org.json.JSONObject;
|
|
|
94 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
95 |
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
96 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
97 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
98 |
import org.springframework.core.io.InputStreamSource;
|
|
|
99 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
100 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
101 |
import org.springframework.stereotype.Component;
|
|
|
102 |
import org.springframework.transaction.annotation.Transactional;
|
| 23739 |
amit.gupta |
103 |
|
| 30119 |
amit.gupta |
104 |
import javax.mail.MessagingException;
|
|
|
105 |
import javax.mail.internet.InternetAddress;
|
|
|
106 |
import javax.mail.internet.MimeMessage;
|
| 30390 |
amit.gupta |
107 |
import java.io.FileOutputStream;
|
| 30119 |
amit.gupta |
108 |
import java.io.IOException;
|
| 30390 |
amit.gupta |
109 |
import java.io.ObjectOutputStream;
|
| 30119 |
amit.gupta |
110 |
import java.io.Serializable;
|
| 30422 |
tejbeer |
111 |
import java.io.UnsupportedEncodingException;
|
| 30119 |
amit.gupta |
112 |
import java.nio.file.Files;
|
|
|
113 |
import java.nio.file.Paths;
|
|
|
114 |
import java.sql.Timestamp;
|
|
|
115 |
import java.time.*;
|
|
|
116 |
import java.time.format.DateTimeFormatter;
|
|
|
117 |
import java.time.temporal.ChronoField;
|
|
|
118 |
import java.time.temporal.ChronoUnit;
|
|
|
119 |
import java.util.*;
|
|
|
120 |
import java.util.Map.Entry;
|
|
|
121 |
import java.util.stream.Collectors;
|
|
|
122 |
|
| 23723 |
amit.gupta |
123 |
@Component
|
| 23724 |
amit.gupta |
124 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
125 |
public class ScheduledTasks {
|
|
|
126 |
|
| 23724 |
amit.gupta |
127 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
128 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
129 |
|
| 23724 |
amit.gupta |
130 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
131 |
private String oxigenRechargeEnquiryUrl;
|
| 24533 |
govind |
132 |
|
| 24431 |
amit.gupta |
133 |
@Autowired
|
| 27088 |
tejbeer |
134 |
private RegionRepository regionRepository;
|
| 29668 |
tejbeer |
135 |
|
| 29488 |
manish |
136 |
@Autowired
|
| 29801 |
manish |
137 |
private ServiceConfigService serviceConfigService;
|
|
|
138 |
|
|
|
139 |
@Autowired
|
| 29488 |
manish |
140 |
private TecnoImeiActivation tecnoImeiActivation;
|
| 28205 |
tejbeer |
141 |
|
| 27795 |
amit.gupta |
142 |
private static final DateTimeFormatter leadTimeFormatter = DateTimeFormatter.ofPattern("d LLL, hh:mm a");
|
| 27088 |
tejbeer |
143 |
|
|
|
144 |
@Autowired
|
|
|
145 |
private PartnerRegionRepository partnerRegionRepository;
|
| 28790 |
amit.gupta |
146 |
|
| 28769 |
amit.gupta |
147 |
@Autowired
|
|
|
148 |
private EmployeeAttendanceRepository employeeAttendanceRepository;
|
| 27088 |
tejbeer |
149 |
|
|
|
150 |
@Autowired
|
| 29451 |
manish |
151 |
VivoImeiActivationService vivoImeiActivationService;
|
| 29488 |
manish |
152 |
|
| 29451 |
manish |
153 |
@Autowired
|
| 29488 |
manish |
154 |
ItelImeiActivationService itelImeiActivationService;
|
|
|
155 |
|
|
|
156 |
@Autowired
|
| 25503 |
amit.gupta |
157 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| 25598 |
amit.gupta |
158 |
|
| 25590 |
amit.gupta |
159 |
@Autowired
|
| 26408 |
amit.gupta |
160 |
private ActivatedImeiRepository activatedImeiRepository;
|
|
|
161 |
|
|
|
162 |
@Autowired
|
| 29451 |
manish |
163 |
private LineItemRepository lineItemRepository;
|
|
|
164 |
|
|
|
165 |
@Autowired
|
| 25910 |
amit.gupta |
166 |
private LeadRepository leadRepository;
|
| 25927 |
amit.gupta |
167 |
|
| 25910 |
amit.gupta |
168 |
@Autowired
|
| 25590 |
amit.gupta |
169 |
private AuthRepository authRepository;
|
| 25503 |
amit.gupta |
170 |
|
|
|
171 |
@Autowired
|
| 24431 |
amit.gupta |
172 |
private PriceDropService priceDropService;
|
| 26283 |
tejbeer |
173 |
|
| 25590 |
amit.gupta |
174 |
@Autowired
|
| 25927 |
amit.gupta |
175 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
| 26790 |
tejbeer |
176 |
|
| 25927 |
amit.gupta |
177 |
@Autowired
|
|
|
178 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
| 26790 |
tejbeer |
179 |
|
| 25927 |
amit.gupta |
180 |
@Autowired
|
| 25982 |
amit.gupta |
181 |
private HdfcPaymentRepository hdfcPaymentRepository;
|
| 26790 |
tejbeer |
182 |
|
| 25982 |
amit.gupta |
183 |
@Autowired
|
| 25590 |
amit.gupta |
184 |
private CsService csService;
|
| 25846 |
amit.gupta |
185 |
|
| 25837 |
amit.gupta |
186 |
@Autowired
|
| 27208 |
tejbeer |
187 |
private SaholicInventoryService saholicInventoryService;
|
|
|
188 |
|
|
|
189 |
@Autowired
|
| 25837 |
amit.gupta |
190 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23723 |
amit.gupta |
191 |
|
| 25694 |
amit.gupta |
192 |
@Autowired
|
|
|
193 |
private ToffeeService toffeeService;
|
|
|
194 |
|
| 23724 |
amit.gupta |
195 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
196 |
private String oxigenRechargeAuthKey;
|
|
|
197 |
|
|
|
198 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
199 |
private String oxigenRechargeValidationUrl;
|
|
|
200 |
|
|
|
201 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
202 |
private String oxigenRechargeValidationAuthKey;
|
|
|
203 |
|
|
|
204 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
205 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
206 |
|
|
|
207 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
208 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
209 |
|
|
|
210 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
211 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
212 |
|
|
|
213 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
214 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
215 |
|
|
|
216 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
217 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
218 |
|
|
|
219 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
220 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
221 |
|
|
|
222 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
223 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
224 |
|
| 23723 |
amit.gupta |
225 |
@Autowired
|
| 23724 |
amit.gupta |
226 |
private PurchaseRepository purchaseRepository;
|
|
|
227 |
|
|
|
228 |
@Autowired
|
| 25609 |
amit.gupta |
229 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
|
|
230 |
|
|
|
231 |
@Autowired
|
|
|
232 |
PriceDropRepository priceDropRepository;
|
|
|
233 |
|
|
|
234 |
@Autowired
|
| 27086 |
tejbeer |
235 |
private PartnerTypeChangeRepository partnerTypeChangeRepository;
|
| 28368 |
tejbeer |
236 |
|
| 27086 |
tejbeer |
237 |
@Autowired
|
| 23724 |
amit.gupta |
238 |
private SchemeService schemeService;
|
| 24683 |
amit.gupta |
239 |
|
| 29668 |
tejbeer |
240 |
@Autowired
|
|
|
241 |
private ServiceConfigRepository serviceConfigRepository;
|
|
|
242 |
|
| 29308 |
tejbeer |
243 |
@Value("${delhivery.tracking.token}")
|
|
|
244 |
private String token;
|
|
|
245 |
|
| 30393 |
amit.gupta |
246 |
private static final String[] STOCK_AGEING_MAIL_LIST = new String[]{"uday.singh@smartudkaan.com",
|
| 29160 |
amit.gupta |
247 |
"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 30393 |
amit.gupta |
248 |
"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com"};
|
| 25609 |
amit.gupta |
249 |
|
| 30393 |
amit.gupta |
250 |
private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[]{"kamini.sharma@smartdukaan.com",
|
| 28205 |
tejbeer |
251 |
"tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com",
|
| 30393 |
amit.gupta |
252 |
"niranjan.kala@smartdukaan.com"};
|
| 25609 |
amit.gupta |
253 |
|
| 30393 |
amit.gupta |
254 |
private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[]{"uday.singh@smartdukaan.com",
|
|
|
255 |
"kuldeep.kumar@smartdukaan.com"};
|
| 28709 |
amit.gupta |
256 |
|
| 30393 |
amit.gupta |
257 |
private static final String[] EMPLOYEE_ATTENDANCE_MAIL_LIST = new String[]{"jyoti.rawat@smartdukaan.com",
|
|
|
258 |
"sm@smartdukaan.com"};
|
| 28790 |
amit.gupta |
259 |
|
| 25721 |
tejbeer |
260 |
private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
261 |
|
| 24681 |
amit.gupta |
262 |
@Autowired
|
|
|
263 |
private ReporticoService reporticoService;
|
| 23724 |
amit.gupta |
264 |
|
|
|
265 |
@Autowired
|
| 24337 |
amit.gupta |
266 |
private PartnerInvestmentService partnerInvestmentService;
|
| 25598 |
amit.gupta |
267 |
|
| 25590 |
amit.gupta |
268 |
@Autowired
|
|
|
269 |
private PositionRepository positionRepository;
|
| 24337 |
amit.gupta |
270 |
|
|
|
271 |
@Autowired
|
| 24542 |
amit.gupta |
272 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 25865 |
amit.gupta |
273 |
|
| 25854 |
amit.gupta |
274 |
@Autowired
|
|
|
275 |
private NotificationService notificationService;
|
| 24542 |
amit.gupta |
276 |
|
|
|
277 |
@Autowired
|
| 24277 |
amit.gupta |
278 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
279 |
|
|
|
280 |
@Autowired
|
| 24241 |
amit.gupta |
281 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
282 |
|
|
|
283 |
@Autowired
|
| 23724 |
amit.gupta |
284 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
285 |
|
|
|
286 |
@Autowired
|
| 24542 |
amit.gupta |
287 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
288 |
|
|
|
289 |
@Autowired
|
| 23724 |
amit.gupta |
290 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
291 |
|
|
|
292 |
@Autowired
|
| 24590 |
amit.gupta |
293 |
private FofoLineItemRepository fofoLineItemRepository;
|
|
|
294 |
|
|
|
295 |
@Autowired
|
| 23724 |
amit.gupta |
296 |
private FofoOrderRepository fofoOrderRepository;
|
| 24587 |
amit.gupta |
297 |
|
| 24580 |
amit.gupta |
298 |
@Autowired
|
|
|
299 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 24250 |
amit.gupta |
300 |
|
| 24249 |
amit.gupta |
301 |
@Autowired
|
| 24587 |
amit.gupta |
302 |
private UserWalletRepository userWalletRepository;
|
|
|
303 |
|
|
|
304 |
@Autowired
|
| 24249 |
amit.gupta |
305 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
306 |
|
| 23739 |
amit.gupta |
307 |
@Autowired
|
|
|
308 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
309 |
|
|
|
310 |
@Autowired
|
|
|
311 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
312 |
|
|
|
313 |
@Autowired
|
|
|
314 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
315 |
|
|
|
316 |
@Autowired
|
|
|
317 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
318 |
|
|
|
319 |
@Autowired
|
| 24242 |
amit.gupta |
320 |
private ScanRecordRepository scanRecordRepository;
|
|
|
321 |
|
|
|
322 |
@Autowired
|
| 23724 |
amit.gupta |
323 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
324 |
|
| 23929 |
amit.gupta |
325 |
@Autowired
|
|
|
326 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
327 |
|
| 23724 |
amit.gupta |
328 |
@Value("${prod}")
|
|
|
329 |
private boolean prod;
|
| 26945 |
amit.gupta |
330 |
|
| 26929 |
amit.gupta |
331 |
@Autowired
|
|
|
332 |
private StateGstRateRepository stateGstRateRepository;
|
| 23724 |
amit.gupta |
333 |
|
| 23929 |
amit.gupta |
334 |
@Autowired
|
|
|
335 |
private RetailerService retailerService;
|
|
|
336 |
|
|
|
337 |
@Autowired
|
|
|
338 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
339 |
|
| 24249 |
amit.gupta |
340 |
@Autowired
|
|
|
341 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
342 |
|
|
|
343 |
@Autowired
|
|
|
344 |
private OrderRepository orderRepository;
|
| 25351 |
tejbeer |
345 |
|
| 25335 |
amit.gupta |
346 |
@Autowired
|
|
|
347 |
private OrderService orderService;
|
| 23929 |
amit.gupta |
348 |
|
|
|
349 |
@Autowired
|
| 24241 |
amit.gupta |
350 |
private SchemeRepository schemeRepository;
|
|
|
351 |
|
|
|
352 |
@Autowired
|
| 23929 |
amit.gupta |
353 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
354 |
|
| 24174 |
govind |
355 |
@Autowired
|
|
|
356 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
357 |
|
|
|
358 |
@Autowired
|
|
|
359 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
360 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
361 |
|
|
|
362 |
@Autowired
|
|
|
363 |
private InventoryService inventoryService;
|
|
|
364 |
|
| 24533 |
govind |
365 |
@Autowired
|
| 24542 |
amit.gupta |
366 |
private AddressRepository addressRepository;
|
|
|
367 |
|
|
|
368 |
@Autowired
|
|
|
369 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
370 |
|
| 24653 |
govind |
371 |
@Autowired
|
|
|
372 |
private Mongo mongoClient;
|
| 24683 |
amit.gupta |
373 |
|
| 24669 |
govind |
374 |
@Autowired
|
| 25300 |
tejbeer |
375 |
private DeviceRepository deviceRepository;
|
|
|
376 |
|
|
|
377 |
@Autowired
|
|
|
378 |
private PushNotificationRepository pushNotificationRepository;
|
|
|
379 |
|
|
|
380 |
@Autowired
|
|
|
381 |
private NotificationCampaignRepository notificationCampaignRepository;
|
|
|
382 |
|
|
|
383 |
@Autowired
|
| 25721 |
tejbeer |
384 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
385 |
|
|
|
386 |
@Autowired
|
|
|
387 |
private FocusedModelRepository focusedModelRepository;
|
|
|
388 |
|
|
|
389 |
@Autowired
|
| 24669 |
govind |
390 |
private UserAccountRepository userAccountRepository;
|
| 24653 |
govind |
391 |
|
| 25721 |
tejbeer |
392 |
@Autowired
|
| 25927 |
amit.gupta |
393 |
private UserRepository userUserRepository;
|
| 25721 |
tejbeer |
394 |
|
|
|
395 |
@Autowired
|
| 25927 |
amit.gupta |
396 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
|
|
397 |
|
|
|
398 |
@Autowired
|
| 25721 |
tejbeer |
399 |
private UserCampaignRepository userCampaignRepository;
|
|
|
400 |
|
|
|
401 |
@Autowired
|
|
|
402 |
private Gson gson;
|
|
|
403 |
|
| 26283 |
tejbeer |
404 |
@Autowired
|
|
|
405 |
private TicketRepository ticketRepository;
|
|
|
406 |
|
| 26790 |
tejbeer |
407 |
@Autowired
|
|
|
408 |
private RefferalRepository refferalRepository;
|
|
|
409 |
|
| 28205 |
tejbeer |
410 |
@Autowired
|
|
|
411 |
private PartnerProblemRepository partnerProblemRepository;
|
|
|
412 |
|
| 28368 |
tejbeer |
413 |
@Autowired
|
|
|
414 |
private PendingOrderRepository pendingOrderRepository;
|
|
|
415 |
|
|
|
416 |
@Autowired
|
|
|
417 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
|
|
418 |
|
|
|
419 |
@Value("${razorpay.account.keyId}")
|
|
|
420 |
private String keyId;
|
|
|
421 |
|
|
|
422 |
@Value("${razorpay.account.keySecret}")
|
|
|
423 |
private String keySecret;
|
|
|
424 |
|
| 28369 |
tejbeer |
425 |
@Autowired
|
|
|
426 |
private RazorpayPaymentService razorPaymentService;
|
|
|
427 |
|
|
|
428 |
@Autowired
|
|
|
429 |
private RazorPayRepository razorPayRepository;
|
|
|
430 |
|
| 28377 |
tejbeer |
431 |
@Autowired
|
|
|
432 |
private PendingOrderService pendingOrderService;
|
|
|
433 |
|
|
|
434 |
@Autowired
|
|
|
435 |
private CustomerRepository customerRepository;
|
|
|
436 |
|
| 29308 |
tejbeer |
437 |
@Autowired
|
|
|
438 |
private RestClient restClient;
|
|
|
439 |
|
| 29814 |
tejbeer |
440 |
@Autowired
|
|
|
441 |
private MandiiService mandiiService;
|
|
|
442 |
|
|
|
443 |
@Autowired
|
|
|
444 |
CreditAccountRepository creditAccountRepository;
|
| 23755 |
amit.gupta |
445 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
446 |
|
| 25300 |
tejbeer |
447 |
private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
|
|
|
448 |
private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
|
|
|
449 |
|
| 23724 |
amit.gupta |
450 |
public void generateDailyRecharge() {
|
|
|
451 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
452 |
.selectAll(0, 2000);
|
|
|
453 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
454 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
455 |
|
|
|
456 |
rechargeProviders.stream().forEach(x -> {
|
|
|
457 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
458 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
459 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
460 |
|
| 29252 |
amit.gupta |
461 |
LOGGER.info("dateWiseProviderCreditsMap -{}", dateWiseProviderCreditsMap);
|
| 23724 |
amit.gupta |
462 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
463 |
float previousDayClosing = 0;
|
|
|
464 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
465 |
while (date.isBefore(endDate)) {
|
|
|
466 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
467 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
468 |
date.plusDays(1).atStartOfDay());
|
|
|
469 |
|
|
|
470 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
471 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
472 |
|
|
|
473 |
float dailyAmount = 0;
|
|
|
474 |
float totalCommission = 0;
|
|
|
475 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
476 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
477 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
478 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
479 |
}
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
483 |
float dailyWalletRecharge = 0;
|
|
|
484 |
if (rechargeHistoryList != null) {
|
|
|
485 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
486 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
487 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
488 |
}
|
|
|
489 |
}
|
|
|
490 |
}
|
|
|
491 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
492 |
DailyRecharge dailyRecharge = null;
|
|
|
493 |
try {
|
|
|
494 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
495 |
} catch (Exception e) {
|
|
|
496 |
LOGGER.info("Could not find Recharge entry");
|
|
|
497 |
}
|
|
|
498 |
if (dailyRecharge == null) {
|
|
|
499 |
dailyRecharge = new DailyRecharge();
|
|
|
500 |
dailyRecharge.setCreateDate(date);
|
|
|
501 |
}
|
|
|
502 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
503 |
dailyRecharge.setProviderId(x.getId());
|
|
|
504 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
505 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
506 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
507 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
508 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
509 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
510 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
511 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
512 |
}
|
|
|
513 |
date = date.plusDays(1);
|
|
|
514 |
}
|
|
|
515 |
rechargeProviderRepository.persist(x);
|
|
|
516 |
});
|
| 23761 |
amit.gupta |
517 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
518 |
}
|
|
|
519 |
|
| 23738 |
amit.gupta |
520 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
521 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
522 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
523 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
524 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
525 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
526 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
527 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
528 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
529 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
530 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
531 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
532 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
533 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
534 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
535 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
536 |
try {
|
|
|
537 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
538 |
if (providerId == 1) {
|
|
|
539 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
540 |
rechargeTransaction);
|
|
|
541 |
} else if (providerId == 2) {
|
|
|
542 |
thinkWalnutDigitalRechargeProviderService
|
|
|
543 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
544 |
}
|
|
|
545 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
546 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
547 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
548 |
rechargeTransaction.getStatus());
|
|
|
549 |
}
|
|
|
550 |
} catch (Exception e) {
|
|
|
551 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
552 |
}
|
|
|
553 |
}
|
| 23738 |
amit.gupta |
554 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
555 |
}
|
| 28205 |
tejbeer |
556 |
|
| 27438 |
amit.gupta |
557 |
public void processActivation() throws Exception {
|
|
|
558 |
schemeService.processActivation();
|
|
|
559 |
}
|
| 24240 |
amit.gupta |
560 |
|
|
|
561 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
562 |
public void migrateInvoice() {
|
|
|
563 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
564 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
565 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
566 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
567 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
568 |
int sequence = 0;
|
|
|
569 |
String prefix = "";
|
| 24241 |
amit.gupta |
570 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
571 |
.collect(Collectors.toList());
|
|
|
572 |
for (FofoOrder order : sortedList) {
|
|
|
573 |
|
| 24240 |
amit.gupta |
574 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
575 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
576 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
577 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
578 |
} else {
|
|
|
579 |
sequence += 1;
|
| 24241 |
amit.gupta |
580 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
581 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
582 |
fofoOrderRepository.persist(order);
|
|
|
583 |
}
|
|
|
584 |
}
|
| 24241 |
amit.gupta |
585 |
|
| 24237 |
amit.gupta |
586 |
}
|
|
|
587 |
}
|
| 23724 |
amit.gupta |
588 |
|
| 30393 |
amit.gupta |
589 |
@Autowired
|
|
|
590 |
private ReporticoCacheTableRepository reporticoCacheTableRepository;
|
| 24252 |
amit.gupta |
591 |
|
| 25584 |
amit.gupta |
592 |
public void processScheme(int offset, boolean dryRun) throws Exception {
|
| 24462 |
amit.gupta |
593 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24259 |
amit.gupta |
594 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 25584 |
amit.gupta |
595 |
processScheme(startDate, endDate, dryRun);
|
| 24256 |
amit.gupta |
596 |
}
|
| 28205 |
tejbeer |
597 |
|
| 27892 |
amit.gupta |
598 |
public void processSchemeOut(List<String> invoiceNumbers) throws Exception {
|
| 28205 |
tejbeer |
599 |
for (String invoiceNumber : invoiceNumbers) {
|
|
|
600 |
System.out.println("Invoice Number - " + invoiceNumber);
|
| 27892 |
amit.gupta |
601 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
|
|
602 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
603 |
}
|
|
|
604 |
}
|
| 28205 |
tejbeer |
605 |
|
| 27987 |
amit.gupta |
606 |
public void processSchemeIn(List<String> invoiceNumbers) throws Exception {
|
| 28205 |
tejbeer |
607 |
for (String invoiceNumber : invoiceNumbers) {
|
|
|
608 |
System.out.println("Invoice Number - " + invoiceNumber);
|
| 27987 |
amit.gupta |
609 |
Purchase purchase = purchaseRepository.selectByPurchaseReference(invoiceNumber);
|
|
|
610 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
611 |
}
|
|
|
612 |
}
|
| 24533 |
govind |
613 |
|
| 25584 |
amit.gupta |
614 |
public void processScheme(int offset, int durationDays, boolean dryRun) throws Exception {
|
| 24462 |
amit.gupta |
615 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24461 |
amit.gupta |
616 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
| 25584 |
amit.gupta |
617 |
processScheme(startDate, endDate, dryRun);
|
| 24461 |
amit.gupta |
618 |
}
|
| 24271 |
amit.gupta |
619 |
|
| 25584 |
amit.gupta |
620 |
public void processScheme(boolean dryRun) throws Exception {
|
| 24256 |
amit.gupta |
621 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
| 25584 |
amit.gupta |
622 |
processScheme(fromDate, LocalDateTime.now(), dryRun);
|
| 24256 |
amit.gupta |
623 |
}
|
| 24271 |
amit.gupta |
624 |
|
| 25584 |
amit.gupta |
625 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate, boolean dryRun) throws Exception {
|
| 23724 |
amit.gupta |
626 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 25312 |
amit.gupta |
627 |
System.out.println(
|
|
|
628 |
"InventoryId\tSerialNumber\tItem Id\tScheme Id\tScheme Name\tScheme Type\tAmount Type\tDP\tTaxable\tScheme Amount\tAmount Paid");
|
| 24561 |
amit.gupta |
629 |
try {
|
| 24587 |
amit.gupta |
630 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
631 |
for (Purchase purchase : purchases) {
|
|
|
632 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
633 |
}
|
| 24271 |
amit.gupta |
634 |
|
| 24587 |
amit.gupta |
635 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
636 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
637 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
638 |
}
|
|
|
639 |
} catch (Exception e) {
|
| 24561 |
amit.gupta |
640 |
e.printStackTrace();
|
| 24565 |
amit.gupta |
641 |
throw e;
|
| 24561 |
amit.gupta |
642 |
}
|
| 28205 |
tejbeer |
643 |
List<UserWalletHistory> uwhs = userWalletHistoryRepository.selectAllByDateType(LocalDate.now().atStartOfDay(),
|
|
|
644 |
endDate, Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
| 25043 |
amit.gupta |
645 |
System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
|
| 25312 |
amit.gupta |
646 |
for (UserWalletHistory uwh : uwhs) {
|
|
|
647 |
System.out.println(String.format("%d\t%d\t%s\t%s\t%s", uwh.getAmount(), uwh.getReference(),
|
|
|
648 |
uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
|
| 25043 |
amit.gupta |
649 |
}
|
| 23724 |
amit.gupta |
650 |
LOGGER.info("Schemes process successfully.");
|
| 25598 |
amit.gupta |
651 |
if (dryRun) {
|
| 25584 |
amit.gupta |
652 |
throw new Exception();
|
|
|
653 |
}
|
| 23724 |
amit.gupta |
654 |
}
|
| 23929 |
amit.gupta |
655 |
|
| 23739 |
amit.gupta |
656 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
657 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
658 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
659 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
660 |
.getPendingCashBackRehargeTransactions();
|
|
|
661 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
662 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
663 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
664 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
665 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
666 |
if (Math.round(amount) > 0) {
|
|
|
667 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
| 26565 |
amit.gupta |
668 |
"Recharge Cashback", Math.round(amount), LocalDateTime.now());
|
| 23762 |
amit.gupta |
669 |
}
|
| 23739 |
amit.gupta |
670 |
}
|
| 23929 |
amit.gupta |
671 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
672 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
673 |
rt.setCashbackReference(referenceId);
|
|
|
674 |
rechargeTransactionRepository.persist(rt);
|
|
|
675 |
}
|
| 23739 |
amit.gupta |
676 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
677 |
}
|
| 29160 |
amit.gupta |
678 |
|
|
|
679 |
public void rollOutUpgardedMarginsNextMonth() throws Exception {
|
| 29107 |
amit.gupta |
680 |
LocalDate startOfPreviousMonth = LocalDate.now().with(ChronoField.DAY_OF_MONTH, 1).minusMonths(1);
|
| 29160 |
amit.gupta |
681 |
|
| 28971 |
amit.gupta |
682 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
| 29160 |
amit.gupta |
683 |
for (FofoStore store : stores) {
|
|
|
684 |
int fofoId = store.getId();
|
|
|
685 |
|
| 30215 |
amit.gupta |
686 |
PartnerType startOfPreviousMonthPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, startOfPreviousMonth);
|
| 29160 |
amit.gupta |
687 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnMonth(fofoId,
|
|
|
688 |
YearMonth.from(startOfPreviousMonth.atStartOfDay()));
|
| 30119 |
amit.gupta |
689 |
if (!startOfPreviousMonthPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
| 29160 |
amit.gupta |
690 |
continue;
|
|
|
691 |
}
|
| 30119 |
amit.gupta |
692 |
if (!startOfPreviousMonthPartnerType.equals(todayPartnerType)) {
|
| 29160 |
amit.gupta |
693 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
| 30119 |
amit.gupta |
694 |
startOfPreviousMonthPartnerType, todayPartnerType);
|
| 29160 |
amit.gupta |
695 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
|
|
696 |
startOfPreviousMonth.atStartOfDay(), startOfPreviousMonth.plusMonths(1).atStartOfDay(), 0, 0);
|
|
|
697 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
698 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 28974 |
amit.gupta |
699 |
}
|
| 29160 |
amit.gupta |
700 |
|
|
|
701 |
}
|
| 28971 |
amit.gupta |
702 |
}
|
|
|
703 |
}
|
| 29252 |
amit.gupta |
704 |
|
| 29160 |
amit.gupta |
705 |
public void rollOutUpgardedMargins() throws Exception {
|
|
|
706 |
LocalDate today = LocalDate.now();
|
|
|
707 |
LocalDate yesterday = today.minusDays(1);
|
|
|
708 |
int upgradedCount = 0;
|
|
|
709 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
|
|
710 |
StringBuilder sb = new StringBuilder();
|
|
|
711 |
for (FofoStore store : stores) {
|
|
|
712 |
int fofoId = store.getId();
|
| 29252 |
amit.gupta |
713 |
|
| 30215 |
amit.gupta |
714 |
PartnerType yesterdayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, yesterday);
|
|
|
715 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, today);
|
| 29160 |
amit.gupta |
716 |
if (!yesterdayPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
|
|
717 |
continue;
|
|
|
718 |
}
|
|
|
719 |
if (!yesterdayPartnerType.equals(todayPartnerType)) {
|
|
|
720 |
upgradedCount++;
|
| 29252 |
amit.gupta |
721 |
sb.append(String.format("Partner Type has been changed for code %s from %s to %s", store.getCode(),
|
|
|
722 |
yesterdayPartnerType.toString(), todayPartnerType.toString()));
|
| 29160 |
amit.gupta |
723 |
sb.append("<br>");
|
|
|
724 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
|
|
725 |
yesterdayPartnerType, todayPartnerType);
|
|
|
726 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
|
|
727 |
yesterday.withDayOfMonth(1).atStartOfDay(), yesterday.atStartOfDay(), 0, 0);
|
|
|
728 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
729 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
|
|
730 |
}
|
| 29252 |
amit.gupta |
731 |
|
| 29160 |
amit.gupta |
732 |
}
|
|
|
733 |
}
|
| 29252 |
amit.gupta |
734 |
if (upgradedCount > 0) {
|
|
|
735 |
sendMailHtmlFormat(
|
| 30390 |
amit.gupta |
736 |
new String[]{"amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
|
|
737 |
"neeraj.gupta@smartdukaan.com"},
|
| 29252 |
amit.gupta |
738 |
sb.toString(), null, "Few Partners Category have been Upgraded");
|
| 29160 |
amit.gupta |
739 |
} else {
|
| 29252 |
amit.gupta |
740 |
sendMailHtmlFormat(
|
| 30390 |
amit.gupta |
741 |
new String[]{"amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
|
|
742 |
"neeraj.gupta@smartdukaan.com"},
|
| 29252 |
amit.gupta |
743 |
sb.toString(), null, "No partners Category have been upgraded today");
|
| 29160 |
amit.gupta |
744 |
}
|
|
|
745 |
}
|
| 23724 |
amit.gupta |
746 |
|
| 30390 |
amit.gupta |
747 |
@Autowired
|
|
|
748 |
private PartnerStatsService partnerStatsService;
|
|
|
749 |
|
| 30393 |
amit.gupta |
750 |
// Temporary Method
|
|
|
751 |
public void evaluateExcessSchemeOut() throws Exception {
|
|
|
752 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
753 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
|
|
754 |
|
|
|
755 |
List<List<?>> rows = new ArrayList<>();
|
|
|
756 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
757 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
|
|
758 |
schemeRepository.selectAll().stream().forEach(x -> {
|
|
|
759 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
760 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
761 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
762 |
if (x.getActiveTimestamp() != null) {
|
|
|
763 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
764 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
765 |
endDateTime = x.getExpireTimestamp();
|
|
|
766 |
}
|
|
|
767 |
for (SchemeInOut sio : sioList) {
|
|
|
768 |
InventoryItem inventoryItem = null;
|
|
|
769 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
|
|
770 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
771 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
|
|
772 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
773 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
774 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
775 |
if (record.isPresent()) {
|
|
|
776 |
int fofoId = record.get().getFofoId();
|
|
|
777 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
778 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
779 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
780 |
userAmountMap.put(fofoId, 0f);
|
|
|
781 |
}
|
|
|
782 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
783 |
try {
|
|
|
784 |
rows.add(Arrays.asList(x.getDescription(),
|
|
|
785 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
|
|
786 |
userNameMap.get(fofoId), sio.getAmount(),
|
|
|
787 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
788 |
fofoOrder.getInvoiceNumber(),
|
|
|
789 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
790 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
791 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
792 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
793 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
|
|
794 |
} catch (Exception e) {
|
|
|
795 |
e.printStackTrace();
|
|
|
796 |
}
|
|
|
797 |
}
|
|
|
798 |
}
|
|
|
799 |
}
|
|
|
800 |
}
|
|
|
801 |
}
|
|
|
802 |
});
|
|
|
803 |
userAmountMap.entrySet().stream()
|
|
|
804 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
805 |
x.getValue(), userNameMap.get(x.getKey())));
|
|
|
806 |
|
|
|
807 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
808 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
809 |
new String[]{"amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com"}, null,
|
|
|
810 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
|
|
811 |
|
|
|
812 |
}
|
|
|
813 |
|
| 30390 |
amit.gupta |
814 |
public void fetchParnterStats() throws Exception {
|
|
|
815 |
Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
|
|
|
816 |
ObjectOutputStream oos = null;
|
|
|
817 |
FileOutputStream fout = null;
|
|
|
818 |
try {
|
|
|
819 |
fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
|
|
|
820 |
oos = new ObjectOutputStream(fout);
|
|
|
821 |
oos.writeObject(partnerStats);
|
|
|
822 |
|
|
|
823 |
} catch (Exception ex) {
|
|
|
824 |
ex.printStackTrace();
|
|
|
825 |
} finally {
|
|
|
826 |
if (oos != null) {
|
|
|
827 |
oos.close();
|
|
|
828 |
}
|
|
|
829 |
}
|
|
|
830 |
ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
|
|
|
831 |
if (rct == null) {
|
|
|
832 |
rct = new ReporticoCacheTable();
|
|
|
833 |
rct.setTableName("partnerStat");
|
| 30393 |
amit.gupta |
834 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
|
|
835 |
reporticoCacheTableRepository.persist(rct);
|
|
|
836 |
} else {
|
|
|
837 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
| 30390 |
amit.gupta |
838 |
}
|
|
|
839 |
}
|
|
|
840 |
|
| 25598 |
amit.gupta |
841 |
private class SaleRoles {
|
|
|
842 |
|
|
|
843 |
private List<String> l1;
|
|
|
844 |
private List<String> l2;
|
|
|
845 |
|
|
|
846 |
public SaleRoles() {
|
|
|
847 |
l1 = new ArrayList<>();
|
|
|
848 |
l2 = new ArrayList<>();
|
|
|
849 |
}
|
|
|
850 |
|
|
|
851 |
public List<String> getL1() {
|
|
|
852 |
return l1;
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
public List<String> getL2() {
|
|
|
856 |
return l2;
|
|
|
857 |
}
|
|
|
858 |
|
|
|
859 |
}
|
|
|
860 |
|
| 26945 |
amit.gupta |
861 |
private class FofoReportingModel {
|
|
|
862 |
private String code;
|
|
|
863 |
private int fofoId;
|
|
|
864 |
private String businessName;
|
|
|
865 |
private String territoryManager;
|
|
|
866 |
private String regionalManager;
|
|
|
867 |
|
|
|
868 |
@Override
|
|
|
869 |
public String toString() {
|
|
|
870 |
return "FofoReportingModel [code=" + code + ", fofoId=" + fofoId + ", businessName=" + businessName
|
|
|
871 |
+ ", territoryManager=" + territoryManager + ", regionalManager=" + regionalManager + "]";
|
|
|
872 |
}
|
|
|
873 |
|
|
|
874 |
public String getCode() {
|
|
|
875 |
return code;
|
|
|
876 |
}
|
|
|
877 |
|
|
|
878 |
public void setCode(String code) {
|
|
|
879 |
this.code = code;
|
|
|
880 |
}
|
|
|
881 |
|
|
|
882 |
public String getBusinessName() {
|
|
|
883 |
return businessName;
|
|
|
884 |
}
|
|
|
885 |
|
|
|
886 |
public void setBusinessName(String businessName) {
|
|
|
887 |
this.businessName = businessName;
|
|
|
888 |
}
|
|
|
889 |
|
|
|
890 |
public String getTerritoryManager() {
|
|
|
891 |
return territoryManager;
|
|
|
892 |
}
|
|
|
893 |
|
|
|
894 |
public void setTerritoryManager(String territoryManager) {
|
|
|
895 |
this.territoryManager = territoryManager;
|
|
|
896 |
}
|
|
|
897 |
|
|
|
898 |
public String getRegionalManager() {
|
|
|
899 |
return regionalManager;
|
|
|
900 |
}
|
|
|
901 |
|
|
|
902 |
public void setRegionalManager(String regionalManager) {
|
|
|
903 |
this.regionalManager = regionalManager;
|
|
|
904 |
}
|
|
|
905 |
|
|
|
906 |
private ScheduledTasks getOuterType() {
|
|
|
907 |
return ScheduledTasks.this;
|
|
|
908 |
}
|
|
|
909 |
|
|
|
910 |
@Override
|
|
|
911 |
public int hashCode() {
|
|
|
912 |
final int prime = 31;
|
|
|
913 |
int result = 1;
|
|
|
914 |
result = prime * result + getOuterType().hashCode();
|
|
|
915 |
result = prime * result + ((businessName == null) ? 0 : businessName.hashCode());
|
|
|
916 |
result = prime * result + ((code == null) ? 0 : code.hashCode());
|
|
|
917 |
result = prime * result + fofoId;
|
|
|
918 |
result = prime * result + ((regionalManager == null) ? 0 : regionalManager.hashCode());
|
|
|
919 |
result = prime * result + ((territoryManager == null) ? 0 : territoryManager.hashCode());
|
|
|
920 |
return result;
|
|
|
921 |
}
|
|
|
922 |
|
|
|
923 |
@Override
|
|
|
924 |
public boolean equals(Object obj) {
|
|
|
925 |
if (this == obj)
|
|
|
926 |
return true;
|
|
|
927 |
if (obj == null)
|
|
|
928 |
return false;
|
|
|
929 |
if (getClass() != obj.getClass())
|
|
|
930 |
return false;
|
|
|
931 |
FofoReportingModel other = (FofoReportingModel) obj;
|
|
|
932 |
if (!getOuterType().equals(other.getOuterType()))
|
|
|
933 |
return false;
|
|
|
934 |
if (businessName == null) {
|
|
|
935 |
if (other.businessName != null)
|
|
|
936 |
return false;
|
|
|
937 |
} else if (!businessName.equals(other.businessName))
|
|
|
938 |
return false;
|
|
|
939 |
if (code == null) {
|
|
|
940 |
if (other.code != null)
|
|
|
941 |
return false;
|
|
|
942 |
} else if (!code.equals(other.code))
|
|
|
943 |
return false;
|
|
|
944 |
if (fofoId != other.fofoId)
|
|
|
945 |
return false;
|
|
|
946 |
if (regionalManager == null) {
|
|
|
947 |
if (other.regionalManager != null)
|
|
|
948 |
return false;
|
|
|
949 |
} else if (!regionalManager.equals(other.regionalManager))
|
|
|
950 |
return false;
|
|
|
951 |
if (territoryManager == null) {
|
|
|
952 |
if (other.territoryManager != null)
|
|
|
953 |
return false;
|
|
|
954 |
} else if (!territoryManager.equals(other.territoryManager))
|
|
|
955 |
return false;
|
|
|
956 |
return true;
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
public int getFofoId() {
|
|
|
960 |
return fofoId;
|
|
|
961 |
}
|
|
|
962 |
|
|
|
963 |
public void setFofoId(int fofoId) {
|
|
|
964 |
this.fofoId = fofoId;
|
|
|
965 |
}
|
|
|
966 |
|
|
|
967 |
}
|
|
|
968 |
|
| 24271 |
amit.gupta |
969 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
970 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 25267 |
amit.gupta |
971 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 23929 |
amit.gupta |
972 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
973 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 25351 |
tejbeer |
974 |
|
| 26957 |
amit.gupta |
975 |
List<String> headers = Arrays.asList("Code", "Outlet name", "State Manager", "Teritory/Team Lead",
|
| 26945 |
amit.gupta |
976 |
"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount",
|
|
|
977 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty",
|
|
|
978 |
"Short Days");
|
| 25837 |
amit.gupta |
979 |
List<List<?>> rows = new ArrayList<>();
|
| 25895 |
amit.gupta |
980 |
Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
|
| 25598 |
amit.gupta |
981 |
|
| 26945 |
amit.gupta |
982 |
Map<Integer, FofoReportingModel> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
|
| 25598 |
amit.gupta |
983 |
|
| 26945 |
amit.gupta |
984 |
Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository
|
|
|
985 |
.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now()).stream().collect(Collectors.groupingBy(
|
|
|
986 |
x -> x.getFofoId(), Collectors.summingInt(x -> x.getShortPercentage() > 10 ? 1 : 0)));
|
|
|
987 |
|
| 24002 |
amit.gupta |
988 |
for (FofoStore fofoStore : fofoStores) {
|
| 27750 |
amit.gupta |
989 |
LOGGER.info("Fofo Store {}, {}", fofoStore.getId(), fofoStore.getCode());
|
| 26376 |
amit.gupta |
990 |
int fofoId = fofoStore.getId();
|
| 26945 |
amit.gupta |
991 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 1);
|
| 25598 |
amit.gupta |
992 |
partnerDailyInvestment.setDate(yesterDay);
|
| 26945 |
amit.gupta |
993 |
|
| 25598 |
amit.gupta |
994 |
try {
|
|
|
995 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 26945 |
amit.gupta |
996 |
shortDaysMap.put(fofoId,
|
|
|
997 |
shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
|
| 25598 |
amit.gupta |
998 |
} catch (Exception e) {
|
|
|
999 |
// ignore the exceptions during persist
|
|
|
1000 |
}
|
|
|
1001 |
|
| 24002 |
amit.gupta |
1002 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 25837 |
amit.gupta |
1003 |
if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
|
| 24002 |
amit.gupta |
1004 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
1005 |
continue;
|
|
|
1006 |
}
|
| 26945 |
amit.gupta |
1007 |
FofoReportingModel reportingModel = partnerIdSalesHeaderMap.get(fofoStore.getId());
|
|
|
1008 |
List<Serializable> row = new ArrayList<>();
|
|
|
1009 |
row.addAll(Arrays.asList(reportingModel.getCode(), reportingModel.getBusinessName(),
|
|
|
1010 |
reportingModel.getRegionalManager(), reportingModel.getTerritoryManager()));
|
| 25927 |
amit.gupta |
1011 |
row.addAll(
|
|
|
1012 |
Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
|
| 26945 |
amit.gupta |
1013 |
partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-"
|
|
|
1014 |
: "(" + partnerDailyInvestment.getActivatedStockAmount() + ")",
|
| 25927 |
amit.gupta |
1015 |
0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
|
|
1016 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
| 26945 |
amit.gupta |
1017 |
partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),
|
|
|
1018 |
shortDaysMap.get(fofoId)));
|
| 25837 |
amit.gupta |
1019 |
partnerRowsMap.put(fofoStore.getId(), row);
|
| 24002 |
amit.gupta |
1020 |
rows.add(row);
|
|
|
1021 |
|
| 23929 |
amit.gupta |
1022 |
}
|
| 25312 |
amit.gupta |
1023 |
|
| 24271 |
amit.gupta |
1024 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 25598 |
amit.gupta |
1025 |
|
| 25927 |
amit.gupta |
1026 |
if (sendTo == null) {
|
| 30215 |
amit.gupta |
1027 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
| 25895 |
amit.gupta |
1028 |
List<List<?>> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerRowsMap.get(x))
|
|
|
1029 |
.filter(x -> x != null).collect(Collectors.toList());
|
|
|
1030 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
| 30209 |
amit.gupta |
1031 |
String[] sendToArray = new String[]{storeGuyEntry.getKey()};
|
| 25895 |
amit.gupta |
1032 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
1033 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
|
|
1034 |
}
|
| 27210 |
tejbeer |
1035 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
| 28467 |
tejbeer |
1036 |
"neeraj.gupta@smartdukaan.com", "amit.gupta@shop2020.in", "manish.gupta@smartdukaan.com",
|
|
|
1037 |
"niranjan.kala@smartdukaan.com");
|
| 25341 |
amit.gupta |
1038 |
}
|
| 25312 |
amit.gupta |
1039 |
|
| 25604 |
amit.gupta |
1040 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
1041 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
| 25609 |
amit.gupta |
1042 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
1043 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 24271 |
amit.gupta |
1044 |
|
| 23929 |
amit.gupta |
1045 |
}
|
| 24177 |
govind |
1046 |
|
| 26945 |
amit.gupta |
1047 |
private Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
|
| 25598 |
amit.gupta |
1048 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
|
|
1049 |
|
|
|
1050 |
List<Position> positions = positionRepository
|
|
|
1051 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
1052 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
|
|
|
1053 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1054 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = csService.getPositionCustomRetailerMap(positions);
|
|
|
1055 |
for (Position position : positions) {
|
|
|
1056 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
| 25609 |
amit.gupta |
1057 |
if (crList == null)
|
|
|
1058 |
continue;
|
| 25598 |
amit.gupta |
1059 |
for (CustomRetailer cr : crList) {
|
|
|
1060 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
|
|
1061 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
|
|
1062 |
}
|
|
|
1063 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
|
|
1064 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
| 26945 |
amit.gupta |
1065 |
if (authUser == null) {
|
| 26059 |
amit.gupta |
1066 |
continue;
|
|
|
1067 |
}
|
| 25598 |
amit.gupta |
1068 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
1069 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
|
|
1070 |
saleRoles.getL1().add(name);
|
|
|
1071 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
|
|
1072 |
saleRoles.getL2().add(name);
|
|
|
1073 |
}
|
|
|
1074 |
}
|
|
|
1075 |
}
|
| 25837 |
amit.gupta |
1076 |
|
|
|
1077 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
|
|
1078 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
|
|
1079 |
allCrList.addAll(cr);
|
|
|
1080 |
}
|
|
|
1081 |
|
|
|
1082 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
|
|
|
1083 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1084 |
|
| 26945 |
amit.gupta |
1085 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
|
| 25837 |
amit.gupta |
1086 |
|
|
|
1087 |
for (CustomRetailer cr : allCrList) {
|
|
|
1088 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
| 25927 |
amit.gupta |
1089 |
if (fofoStore == null) {
|
| 25870 |
amit.gupta |
1090 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
|
|
1091 |
continue;
|
|
|
1092 |
}
|
| 26945 |
amit.gupta |
1093 |
String code = fofoStore.getCode();
|
|
|
1094 |
// String storeName = "SmartDukaan-" +
|
|
|
1095 |
// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
| 25837 |
amit.gupta |
1096 |
String businessName = cr.getBusinessName();
|
|
|
1097 |
try {
|
|
|
1098 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
1099 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
| 26945 |
amit.gupta |
1100 |
FofoReportingModel reportingModel = new FofoReportingModel();
|
|
|
1101 |
reportingModel.setBusinessName(businessName);
|
|
|
1102 |
reportingModel.setCode(code);
|
|
|
1103 |
reportingModel.setFofoId(fofoStore.getId());
|
|
|
1104 |
reportingModel.setRegionalManager(stateManager);
|
|
|
1105 |
reportingModel.setTerritoryManager(territoryManager);
|
|
|
1106 |
partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
|
| 25837 |
amit.gupta |
1107 |
} catch (Exception e) {
|
|
|
1108 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
|
|
1109 |
}
|
|
|
1110 |
}
|
|
|
1111 |
return partnerIdSalesHeadersMap;
|
|
|
1112 |
|
| 25598 |
amit.gupta |
1113 |
}
|
|
|
1114 |
|
| 24271 |
amit.gupta |
1115 |
public void sendPartnerInvestmentDetails() throws Exception {
|
| 25565 |
amit.gupta |
1116 |
this.sendPartnerInvestmentDetails(null);
|
| 24271 |
amit.gupta |
1117 |
}
|
|
|
1118 |
|
| 24697 |
amit.gupta |
1119 |
public void sendAgeingReport(String... sendTo) throws Exception {
|
| 24692 |
amit.gupta |
1120 |
|
|
|
1121 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
|
|
|
1122 |
"itemstockageing.xml");
|
| 24708 |
amit.gupta |
1123 |
InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 24754 |
amit.gupta |
1124 |
"ItemwiseOverallPendingIndent.xml");
|
| 24683 |
amit.gupta |
1125 |
Attachment attachment = new Attachment(
|
| 25445 |
amit.gupta |
1126 |
"ageing-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
|
| 24707 |
amit.gupta |
1127 |
Attachment attachment1 = new Attachment(
|
| 25445 |
amit.gupta |
1128 |
"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
|
| 25418 |
amit.gupta |
1129 |
|
| 25609 |
amit.gupta |
1130 |
Utils.sendMailWithAttachments(googleMailSender, STOCK_AGEING_MAIL_LIST, null, "Stock Ageing Report", "PFA",
|
|
|
1131 |
attachment);
|
|
|
1132 |
Utils.sendMailWithAttachments(googleMailSender, ITEMWISE_PENDING_INDENT_MAIL_LIST, null,
|
|
|
1133 |
"Itemwise Pending indent", "PFA", attachment1);
|
|
|
1134 |
|
| 25598 |
amit.gupta |
1135 |
// Reports to be sent to mapped partners
|
| 25597 |
amit.gupta |
1136 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
| 25503 |
amit.gupta |
1137 |
|
|
|
1138 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
| 25418 |
amit.gupta |
1139 |
Map<String, String> params = new HashMap<>();
|
| 25503 |
amit.gupta |
1140 |
if (storeGuyEntry.getValue().size() == 0)
|
|
|
1141 |
continue;
|
| 25418 |
amit.gupta |
1142 |
params.put("MANUAL_email", String.join(",", storeGuyEntry.getValue()));
|
|
|
1143 |
InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
1144 |
"focostockreport.xml", params);
|
|
|
1145 |
Attachment attache = new Attachment(
|
| 25609 |
amit.gupta |
1146 |
"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
|
| 25584 |
amit.gupta |
1147 |
System.out.println(storeGuyEntry.getValue());
|
| 30393 |
amit.gupta |
1148 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{storeGuyEntry.getKey()}, null,
|
| 25609 |
amit.gupta |
1149 |
"Franchise Stock Report", "PFA", attache);
|
| 25418 |
amit.gupta |
1150 |
}
|
| 25503 |
amit.gupta |
1151 |
|
| 24681 |
amit.gupta |
1152 |
}
|
| 24533 |
govind |
1153 |
|
| 28632 |
amit.gupta |
1154 |
public void sendIndentTertiary() throws Exception {
|
| 28709 |
amit.gupta |
1155 |
|
| 28632 |
amit.gupta |
1156 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
1157 |
"indentandtertiary.xml");
|
|
|
1158 |
Attachment attachment = new Attachment(
|
| 28839 |
tejbeer |
1159 |
"indentandtertiary-report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr);
|
| 28709 |
amit.gupta |
1160 |
Utils.sendMailWithAttachments(googleMailSender, INDENT_TERTIARY_MAIL_LIST, null, "Indent Tertiary Report",
|
|
|
1161 |
"PFA", attachment);
|
|
|
1162 |
|
| 28632 |
amit.gupta |
1163 |
}
|
| 28790 |
amit.gupta |
1164 |
|
| 28769 |
amit.gupta |
1165 |
public void sendAttendanceMorningAlert() throws Exception {
|
| 28793 |
amit.gupta |
1166 |
LocalDateTime moriningTime = LocalDate.now().atTime(10, 31);
|
| 28775 |
amit.gupta |
1167 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 28790 |
amit.gupta |
1168 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
|
|
1169 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
|
|
1170 |
|
| 28769 |
amit.gupta |
1171 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
| 28790 |
amit.gupta |
1172 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
|
|
1173 |
|
|
|
1174 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository
|
|
|
1175 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now());
|
|
|
1176 |
|
|
|
1177 |
Map<Integer, Optional<EmployeeAttendance>> employeeMorningAttendance = employeeAttendances.stream()
|
|
|
1178 |
.collect(Collectors.groupingBy(EmployeeAttendance::getUserId,
|
|
|
1179 |
Collectors.minBy(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))));
|
|
|
1180 |
for (AuthUser authUser : authUsers) {
|
| 28769 |
amit.gupta |
1181 |
User user = userMap.get(authUser.getEmailId());
|
|
|
1182 |
Optional<EmployeeAttendance> employeeAttendanceOptional = employeeMorningAttendance.get(user.getId());
|
| 28817 |
amit.gupta |
1183 |
LOGGER.info("AuthUser - {}, employeeAttendanceOptional {}", authUser.getName(), employeeAttendanceOptional);
|
| 28839 |
tejbeer |
1184 |
if (employeeAttendanceOptional != null) {
|
| 28818 |
amit.gupta |
1185 |
LOGGER.info("employeeAttendanceOptional.orElse {}", employeeAttendanceOptional.orElse(null));
|
| 28839 |
tejbeer |
1186 |
if (employeeAttendanceOptional.orElse(null) != null) {
|
|
|
1187 |
LOGGER.info("employeeAttendanceOptional.get().getCreateTimestamp() {}",
|
|
|
1188 |
employeeAttendanceOptional.get().getCreateTimestamp());
|
| 28818 |
amit.gupta |
1189 |
}
|
|
|
1190 |
}
|
| 28790 |
amit.gupta |
1191 |
if (employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null
|
| 28769 |
amit.gupta |
1192 |
|| employeeAttendanceOptional.get().getCreateTimestamp().isAfter(moriningTime)) {
|
| 28819 |
amit.gupta |
1193 |
LOGGER.info("Will Send Email to {}", authUser.getFullName());
|
| 28790 |
amit.gupta |
1194 |
String body = String.format(
|
| 28806 |
amit.gupta |
1195 |
"Dear %s,\n Pls note that you haven't punched your attendance by 10:30am%s. You have been marked absent for half the day.\n\nRegards\nHR Team",
|
| 28839 |
tejbeer |
1196 |
authUser.getFullName(),
|
|
|
1197 |
(employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null) ? ""
|
|
|
1198 |
: "(Punched at "
|
| 30393 |
amit.gupta |
1199 |
+ FormattingUtils.format(employeeAttendanceOptional.get().getCreateTimestamp())
|
|
|
1200 |
+ ")");
|
| 28839 |
tejbeer |
1201 |
|
| 30393 |
amit.gupta |
1202 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{authUser.getEmailId()},
|
|
|
1203 |
new String[]{"jyoti.rawat@smartdukaan.com"}, "Attendance Alert", body);
|
| 28839 |
tejbeer |
1204 |
|
| 28769 |
amit.gupta |
1205 |
}
|
|
|
1206 |
}
|
| 28790 |
amit.gupta |
1207 |
|
| 28769 |
amit.gupta |
1208 |
}
|
| 28790 |
amit.gupta |
1209 |
|
| 28775 |
amit.gupta |
1210 |
public void sendAttendanceEveningAlert() throws Exception {
|
|
|
1211 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 28790 |
amit.gupta |
1212 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
|
|
1213 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
|
|
1214 |
|
| 28775 |
amit.gupta |
1215 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
| 28790 |
amit.gupta |
1216 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
| 28775 |
amit.gupta |
1217 |
|
| 28790 |
amit.gupta |
1218 |
Map<Integer, List<EmployeeAttendance>> employeeAttendancesMap = employeeAttendanceRepository
|
|
|
1219 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now()).stream()
|
|
|
1220 |
.collect(Collectors.groupingBy(x -> x.getUserId()));
|
|
|
1221 |
|
|
|
1222 |
for (AuthUser authUser : authUsers) {
|
| 28775 |
amit.gupta |
1223 |
User user = userMap.get(authUser.getEmailId());
|
| 28784 |
amit.gupta |
1224 |
String body = null;
|
|
|
1225 |
List<EmployeeAttendance> employeeAttendances = employeeAttendancesMap.get(user.getId());
|
| 28790 |
amit.gupta |
1226 |
if (employeeAttendances == null) {
|
|
|
1227 |
body = String.format(
|
| 28806 |
amit.gupta |
1228 |
"Dear %s,\n No attendance has been registered by you today. You have been marked absent for the day.\n\nRegards\nHR Team",
|
| 28790 |
amit.gupta |
1229 |
authUser.getFullName());
|
| 28784 |
amit.gupta |
1230 |
} else {
|
| 28790 |
amit.gupta |
1231 |
List<LocalDateTime> punchTimes = employeeAttendances.stream()
|
|
|
1232 |
.sorted(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))
|
|
|
1233 |
.map(x -> x.getCreateTimestamp()).collect(Collectors.toList());
|
|
|
1234 |
if (punchTimes.size() == 1) {
|
|
|
1235 |
// body = String.format("Dear %s,\n Pls note that you haven't punched out yet.
|
|
|
1236 |
// You have been marked absent for half the day. You may contact your manager
|
|
|
1237 |
// and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
| 28784 |
amit.gupta |
1238 |
} else {
|
|
|
1239 |
LocalDateTime firstPunch = punchTimes.get(0);
|
| 28790 |
amit.gupta |
1240 |
LocalDateTime lastPunch = punchTimes.get(punchTimes.size() - 1);
|
| 28805 |
amit.gupta |
1241 |
Duration duration = Duration.between(firstPunch, lastPunch);
|
| 28784 |
amit.gupta |
1242 |
boolean hoursCompleted = lastPunch.isAfter(firstPunch.plusHours(8).plusMinutes(30));
|
| 28790 |
amit.gupta |
1243 |
if (!hoursCompleted) {
|
|
|
1244 |
body = String.format(
|
| 28806 |
amit.gupta |
1245 |
"Dear %s,\n Pls note that you haven't completed 8.30 Hrs (%d.%d Hrs). You have been marked absent for half the day.\n\nRegards\nHR Team",
|
| 28839 |
tejbeer |
1246 |
authUser.getFullName(), duration.toHours(),
|
|
|
1247 |
duration.toMinutes() - duration.toHours() * 60);
|
| 28784 |
amit.gupta |
1248 |
}
|
|
|
1249 |
}
|
|
|
1250 |
|
|
|
1251 |
}
|
| 28790 |
amit.gupta |
1252 |
if (body != null) {
|
| 30393 |
amit.gupta |
1253 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{authUser.getEmailId()},
|
|
|
1254 |
new String[]{"jyoti.rawat@smartdukaan.com"}, "Attendance Alert", body);
|
| 28775 |
amit.gupta |
1255 |
}
|
|
|
1256 |
}
|
| 28790 |
amit.gupta |
1257 |
|
|
|
1258 |
this.sendMailToHR();
|
|
|
1259 |
|
| 28775 |
amit.gupta |
1260 |
}
|
| 28790 |
amit.gupta |
1261 |
|
|
|
1262 |
private void sendMailToHR() throws Exception {
|
|
|
1263 |
Map<String, String> map = new HashMap<>();
|
|
|
1264 |
String reporticoDate = FormattingUtils.formatReporitcoDate(LocalDateTime.now());
|
|
|
1265 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
|
|
1266 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
|
|
1267 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
1268 |
"employeeattendance.xml");
|
|
|
1269 |
Attachment attachment = new Attachment("attendance-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv",
|
|
|
1270 |
isr);
|
|
|
1271 |
Utils.sendMailWithAttachments(googleMailSender, EMPLOYEE_ATTENDANCE_MAIL_LIST, null,
|
|
|
1272 |
"Attendance - " + FormattingUtils.formatDate(LocalDateTime.now()), "PFA Attendance", attachment);
|
|
|
1273 |
}
|
|
|
1274 |
|
| 28709 |
amit.gupta |
1275 |
public void checkPartnerActiveStore() throws Exception {
|
|
|
1276 |
|
|
|
1277 |
List<FofoStore> fofoStores = fofoStoreRepository.selectByStatus(true);
|
|
|
1278 |
|
|
|
1279 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
| 28712 |
amit.gupta |
1280 |
if (!fofoStores.isEmpty()) {
|
|
|
1281 |
for (FofoStore fofoStore : fofoStores) {
|
| 28709 |
amit.gupta |
1282 |
|
| 28712 |
amit.gupta |
1283 |
if (currentDate.isBefore(fofoStore.getActiveTimeStamp())) {
|
| 28709 |
amit.gupta |
1284 |
|
| 28712 |
amit.gupta |
1285 |
fofoStore.setActive(true);
|
|
|
1286 |
fofoStoreRepository.persist(fofoStore);
|
|
|
1287 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
| 28709 |
amit.gupta |
1288 |
|
| 30393 |
amit.gupta |
1289 |
} else {
|
| 28712 |
amit.gupta |
1290 |
fofoStore.setActive(false);
|
|
|
1291 |
fofoStore.setActiveTimeStamp(null);
|
|
|
1292 |
fofoStoreRepository.persist(fofoStore);
|
|
|
1293 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
|
|
1294 |
}
|
| 28709 |
amit.gupta |
1295 |
|
|
|
1296 |
}
|
|
|
1297 |
}
|
|
|
1298 |
|
|
|
1299 |
}
|
|
|
1300 |
|
| 24697 |
amit.gupta |
1301 |
public void sendAgeingReport() throws Exception {
|
| 27210 |
tejbeer |
1302 |
sendAgeingReport("kamini.sharma@smartdukaan.com", "amit.babu@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 28467 |
tejbeer |
1303 |
"niranjan.kala@smartdukaan.com", "manish.gupta@smartdukaan.com", "kuldeep.kumar@smartdukaan.com");
|
| 24697 |
amit.gupta |
1304 |
}
|
|
|
1305 |
|
| 24533 |
govind |
1306 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
1307 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
1308 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
1309 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
1310 |
}
|
|
|
1311 |
}
|
| 23929 |
amit.gupta |
1312 |
|
| 24542 |
amit.gupta |
1313 |
public void walletmismatch() throws Exception {
|
|
|
1314 |
LocalDate curDate = LocalDate.now();
|
| 24553 |
amit.gupta |
1315 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 24552 |
amit.gupta |
1316 |
System.out.println(pdis.size());
|
| 24542 |
amit.gupta |
1317 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 24549 |
amit.gupta |
1318 |
int fofoId = pdi.getFofoId();
|
| 24542 |
amit.gupta |
1319 |
for (PartnerDailyInvestment investment : Lists
|
|
|
1320 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 24552 |
amit.gupta |
1321 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 24555 |
amit.gupta |
1322 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 24552 |
amit.gupta |
1323 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 24841 |
govind |
1324 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
|
|
|
1325 |
investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
|
| 24551 |
amit.gupta |
1326 |
|
| 24542 |
amit.gupta |
1327 |
}
|
| 24549 |
amit.gupta |
1328 |
}
|
| 24542 |
amit.gupta |
1329 |
|
|
|
1330 |
}
|
| 29160 |
amit.gupta |
1331 |
|
| 28990 |
amit.gupta |
1332 |
@Autowired
|
|
|
1333 |
StateRepository stateRepository;
|
| 24542 |
amit.gupta |
1334 |
|
|
|
1335 |
public void gst() throws Exception {
|
| 28995 |
amit.gupta |
1336 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2021, 8, 16).atStartOfDay(),
|
| 28990 |
amit.gupta |
1337 |
LocalDateTime.now());
|
| 24548 |
amit.gupta |
1338 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
1339 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
1340 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 24542 |
amit.gupta |
1341 |
|
|
|
1342 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
1343 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
1344 |
Integer stateId = null;
|
|
|
1345 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
1346 |
try {
|
| 28990 |
amit.gupta |
1347 |
stateId = stateRepository.selectByName(customerAddress.getState()).getId();
|
| 24542 |
amit.gupta |
1348 |
} catch (Exception e) {
|
| 28990 |
amit.gupta |
1349 |
LOGGER.error("Cannot found state named {}", customerAddress.getState());
|
|
|
1350 |
continue;
|
| 24542 |
amit.gupta |
1351 |
}
|
|
|
1352 |
}
|
|
|
1353 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
1354 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 24548 |
amit.gupta |
1355 |
|
|
|
1356 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 26929 |
amit.gupta |
1357 |
List<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
| 24542 |
amit.gupta |
1358 |
if (stateId != null) {
|
| 26929 |
amit.gupta |
1359 |
itemIdStateTaxRateMap = stateGstRateRepository.getStateTaxRate(itemIds, stateId);
|
| 24542 |
amit.gupta |
1360 |
} else {
|
| 26929 |
amit.gupta |
1361 |
itemIdIgstTaxRateMap = stateGstRateRepository.getIgstTaxRate(itemIds);
|
| 24542 |
amit.gupta |
1362 |
}
|
|
|
1363 |
|
| 24548 |
amit.gupta |
1364 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 28990 |
amit.gupta |
1365 |
float sgstRate = foi.getSgstRate();
|
|
|
1366 |
float cgstRate = foi.getCgstRate();
|
|
|
1367 |
float igstRate = foi.getIgstRate();
|
| 29160 |
amit.gupta |
1368 |
if (stateId == null && igstRate == 0) {
|
|
|
1369 |
|
|
|
1370 |
foi.setSgstRate(0);
|
|
|
1371 |
foi.setCgstRate(0);
|
|
|
1372 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
|
|
1373 |
|
| 28993 |
amit.gupta |
1374 |
LOGGER.info("Invoice {}, Date {}", fofoOrder.getInvoiceNumber(), fofoOrder.getCreateTimestamp());
|
| 29160 |
amit.gupta |
1375 |
LOGGER.info("customerAddress.getState() {}, retailerAddress.getState() {}",
|
|
|
1376 |
customerAddress.getState(), retailerAddress.getState());
|
| 28990 |
amit.gupta |
1377 |
LOGGER.info("Rates getIgstRate() {}", itemIdIgstTaxRateMap.get(foi.getItemId()));
|
| 29160 |
amit.gupta |
1378 |
|
|
|
1379 |
} else if (stateId != null && sgstRate == 0 && cgstRate == 0) {
|
|
|
1380 |
|
|
|
1381 |
foi.setIgstRate(0);
|
|
|
1382 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
|
|
1383 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
|
|
1384 |
|
| 28993 |
amit.gupta |
1385 |
LOGGER.info("Invoice {}, Date {}", fofoOrder.getInvoiceNumber(), fofoOrder.getCreateTimestamp());
|
| 29160 |
amit.gupta |
1386 |
LOGGER.info("customerAddress.getState() {}, retailerAddress.getState() {}",
|
|
|
1387 |
customerAddress.getState(), retailerAddress.getState());
|
|
|
1388 |
LOGGER.info("Rates getCgstRate() {}, getSgstRate() {}",
|
|
|
1389 |
itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate(),
|
|
|
1390 |
itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
| 24542 |
amit.gupta |
1391 |
}
|
|
|
1392 |
}
|
|
|
1393 |
}
|
| 24548 |
amit.gupta |
1394 |
|
| 24542 |
amit.gupta |
1395 |
}
|
|
|
1396 |
|
| 24580 |
amit.gupta |
1397 |
public void schemewalletmismatch() {
|
|
|
1398 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
| 24587 |
amit.gupta |
1399 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
| 24580 |
amit.gupta |
1400 |
reconcileSchemes(dateToReconcile);
|
| 24587 |
amit.gupta |
1401 |
// reconcileOrders(dateTime);
|
|
|
1402 |
// reconcileRecharges(dateTime);
|
| 24580 |
amit.gupta |
1403 |
dateToReconcile = dateToReconcile.plusDays(1);
|
|
|
1404 |
}
|
|
|
1405 |
}
|
|
|
1406 |
|
|
|
1407 |
private void reconcileSchemes(LocalDate date) {
|
|
|
1408 |
LocalDateTime startDate = date.atStartOfDay();
|
|
|
1409 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
1410 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
|
|
1411 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
| 24587 |
amit.gupta |
1412 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1413 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 24580 |
amit.gupta |
1414 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
| 24587 |
amit.gupta |
1415 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
|
|
1416 |
WalletReferenceType.SCHEME_OUT);
|
|
|
1417 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
1418 |
walletReferenceTypes);
|
|
|
1419 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1420 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
| 24580 |
amit.gupta |
1421 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
| 24587 |
amit.gupta |
1422 |
|
|
|
1423 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
|
|
1424 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1425 |
|
|
|
1426 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
|
|
1427 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1428 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
|
|
1429 |
|
|
|
1430 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
|
|
1431 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1432 |
|
|
|
1433 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
|
|
1434 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
|
|
1435 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1436 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
|
|
1437 |
|
|
|
1438 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
| 26092 |
amit.gupta |
1439 |
|
| 24587 |
amit.gupta |
1440 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
|
|
1441 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
|
|
1442 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
|
|
1443 |
} else {
|
|
|
1444 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
|
|
1445 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
|
|
1446 |
}
|
|
|
1447 |
}
|
| 24590 |
amit.gupta |
1448 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
|
|
1449 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
|
|
1450 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1451 |
|
| 24587 |
amit.gupta |
1452 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
|
|
1453 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
|
|
1454 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
|
|
1455 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
|
|
1456 |
if (diff > 5) {
|
|
|
1457 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
|
|
1458 |
}
|
|
|
1459 |
}
|
| 24580 |
amit.gupta |
1460 |
}
|
| 24587 |
amit.gupta |
1461 |
|
| 24580 |
amit.gupta |
1462 |
}
|
| 24590 |
amit.gupta |
1463 |
|
| 24592 |
amit.gupta |
1464 |
public void dryRunSchemeReco() throws Exception {
|
| 24635 |
amit.gupta |
1465 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1466 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1467 |
|
| 24592 |
amit.gupta |
1468 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1469 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24635 |
amit.gupta |
1470 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1471 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1472 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
|
|
1473 |
|
| 25096 |
amit.gupta |
1474 |
LocalDateTime startDate = LocalDate.of(2018, 3, 1).atStartOfDay();
|
| 24635 |
amit.gupta |
1475 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
|
|
1476 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
1477 |
|
| 24683 |
amit.gupta |
1478 |
Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
|
| 24635 |
amit.gupta |
1479 |
purchases.stream().forEach(purchase -> {
|
|
|
1480 |
float amountToRollback = 0;
|
|
|
1481 |
String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
|
|
|
1482 |
+ purchase.getPurchaseReference();
|
|
|
1483 |
Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
|
|
|
1484 |
.stream().filter(ii -> ii.getSerialNumber() != null)
|
|
|
1485 |
.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
|
|
|
1486 |
if (inventorySerialNumberMap.size() > 0) {
|
|
|
1487 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1488 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1489 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1490 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1491 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1492 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1493 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1494 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1495 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1496 |
.collect(Collectors.toList());
|
|
|
1497 |
Collections.reverse(sios);
|
|
|
1498 |
for (SchemeInOut sio : sios) {
|
|
|
1499 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1500 |
amountToRollback += sio.getAmount();
|
|
|
1501 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1502 |
sio.setSerialNumber(serialNumber);
|
|
|
1503 |
rolledbackSios.add(sio);
|
|
|
1504 |
}
|
|
|
1505 |
description = description.concat(" " + serialNumber + " ");
|
|
|
1506 |
} else {
|
|
|
1507 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1508 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1509 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1510 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1511 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1512 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1513 |
.collect(Collectors.toList());
|
|
|
1514 |
Collections.reverse(sios);
|
|
|
1515 |
for (SchemeInOut sio : sios) {
|
|
|
1516 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1517 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1518 |
continue;
|
|
|
1519 |
}
|
|
|
1520 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1521 |
amountToRollback += sio.getAmount();
|
|
|
1522 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1523 |
sio.setSerialNumber(serialNumber);
|
| 24681 |
amit.gupta |
1524 |
sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
|
|
1525 |
sio.setReference(purchase.getId());
|
| 24635 |
amit.gupta |
1526 |
rolledbackSios.add(sio);
|
|
|
1527 |
}
|
|
|
1528 |
}
|
|
|
1529 |
|
|
|
1530 |
}
|
|
|
1531 |
}
|
|
|
1532 |
if (amountToRollback > 0) {
|
| 24683 |
amit.gupta |
1533 |
// Address address =
|
|
|
1534 |
// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
|
| 24635 |
amit.gupta |
1535 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1536 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1537 |
uwh.setDescription(description);
|
|
|
1538 |
uwh.setTimestamp(LocalDateTime.now());
|
| 24681 |
amit.gupta |
1539 |
uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
|
| 24635 |
amit.gupta |
1540 |
uwh.setReference(purchase.getId());
|
|
|
1541 |
uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
|
|
|
1542 |
uwh.setFofoId(purchase.getFofoId());
|
| 24681 |
amit.gupta |
1543 |
uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
| 24635 |
amit.gupta |
1544 |
userWalletHistory.add(uwh);
|
|
|
1545 |
}
|
|
|
1546 |
});
|
|
|
1547 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1548 |
Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
|
|
1549 |
"Timestamp"),
|
|
|
1550 |
userWalletHistory.stream()
|
|
|
1551 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1552 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
|
|
1553 |
.collect(Collectors.toList()));
|
|
|
1554 |
|
|
|
1555 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 24683 |
amit.gupta |
1556 |
Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
|
|
|
1557 |
"Created", "Rolledback"),
|
| 24635 |
amit.gupta |
1558 |
rolledbackSios.stream()
|
| 24681 |
amit.gupta |
1559 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
|
| 24635 |
amit.gupta |
1560 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1561 |
.collect(Collectors.toList()));
|
|
|
1562 |
|
| 30393 |
amit.gupta |
1563 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@shop2020.in"}, null,
|
| 24636 |
amit.gupta |
1564 |
"Partner Excess Amount Scheme In", "PFA",
|
| 30393 |
amit.gupta |
1565 |
new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1566 |
new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
|
| 24635 |
amit.gupta |
1567 |
|
| 25096 |
amit.gupta |
1568 |
throw new Exception();
|
| 24635 |
amit.gupta |
1569 |
|
|
|
1570 |
}
|
|
|
1571 |
|
|
|
1572 |
public void dryRunOutSchemeReco() throws Exception {
|
|
|
1573 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1574 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24606 |
amit.gupta |
1575 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1576 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 24590 |
amit.gupta |
1577 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1578 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 25028 |
amit.gupta |
1579 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
| 24632 |
amit.gupta |
1580 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
| 24631 |
amit.gupta |
1581 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
1582 |
// Collections.reverse(allOrders);
|
|
|
1583 |
// List<FofoOrder> allOrders =
|
| 24653 |
govind |
1584 |
// List<FofoOrder> allOrders =
|
| 24631 |
amit.gupta |
1585 |
// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
|
| 24625 |
amit.gupta |
1586 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
| 24590 |
amit.gupta |
1587 |
allOrders.stream().forEach(fofoOrder -> {
|
| 24592 |
amit.gupta |
1588 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 24598 |
amit.gupta |
1589 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
| 24592 |
amit.gupta |
1590 |
float amountToRollback = 0;
|
| 24590 |
amit.gupta |
1591 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1592 |
orderItems.forEach(x -> {
|
| 24606 |
amit.gupta |
1593 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
| 24598 |
amit.gupta |
1594 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
| 24590 |
amit.gupta |
1595 |
});
|
| 24606 |
amit.gupta |
1596 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24631 |
amit.gupta |
1597 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1598 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1599 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1600 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1601 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1602 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1603 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1604 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1605 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1606 |
.collect(Collectors.toList());
|
|
|
1607 |
Collections.reverse(sios);
|
|
|
1608 |
for (SchemeInOut sio : sios) {
|
|
|
1609 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1610 |
amountToRollback += sio.getAmount();
|
|
|
1611 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1612 |
sio.setSerialNumber(serialNumber);
|
|
|
1613 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 24681 |
amit.gupta |
1614 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1615 |
rolledbackSios.add(sio);
|
| 24623 |
amit.gupta |
1616 |
}
|
| 24635 |
amit.gupta |
1617 |
description = description.concat(" " + serialNumber + " ");
|
| 24631 |
amit.gupta |
1618 |
} else {
|
|
|
1619 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1620 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1621 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1622 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1623 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1624 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1625 |
.collect(Collectors.toList());
|
|
|
1626 |
Collections.reverse(sios);
|
|
|
1627 |
for (SchemeInOut sio : sios) {
|
|
|
1628 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1629 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1630 |
continue;
|
|
|
1631 |
}
|
|
|
1632 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1633 |
amountToRollback += sio.getAmount();
|
|
|
1634 |
// sio.setSchemeType(SchemeType.OUT);
|
| 24681 |
amit.gupta |
1635 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1636 |
sio.setSerialNumber(serialNumber);
|
|
|
1637 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1638 |
rolledbackSios.add(sio);
|
|
|
1639 |
}
|
| 24615 |
amit.gupta |
1640 |
}
|
| 24631 |
amit.gupta |
1641 |
|
| 24604 |
amit.gupta |
1642 |
}
|
| 24590 |
amit.gupta |
1643 |
}
|
| 24631 |
amit.gupta |
1644 |
if (amountToRollback > 0) {
|
|
|
1645 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1646 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1647 |
uwh.setDescription(description);
|
|
|
1648 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1649 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1650 |
uwh.setReference(fofoOrder.getId());
|
|
|
1651 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1652 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1653 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1654 |
userWalletHistory.add(uwh);
|
|
|
1655 |
}
|
| 24590 |
amit.gupta |
1656 |
});
|
| 24598 |
amit.gupta |
1657 |
|
| 24592 |
amit.gupta |
1658 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 24681 |
amit.gupta |
1659 |
Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
| 24615 |
amit.gupta |
1660 |
"Timestamp"),
|
|
|
1661 |
userWalletHistory.stream()
|
|
|
1662 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1663 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24592 |
amit.gupta |
1664 |
.collect(Collectors.toList()));
|
|
|
1665 |
|
|
|
1666 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1667 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1668 |
"Rolledback"),
|
|
|
1669 |
rolledbackSios.stream()
|
|
|
1670 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1671 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1672 |
.collect(Collectors.toList()));
|
|
|
1673 |
|
| 30393 |
amit.gupta |
1674 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@shop2020.in"}, null,
|
| 24681 |
amit.gupta |
1675 |
"Partner Excess Amount Scheme Out", "PFA",
|
| 30393 |
amit.gupta |
1676 |
new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1677 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
|
| 24631 |
amit.gupta |
1678 |
|
| 25267 |
amit.gupta |
1679 |
throw new Exception();
|
| 24590 |
amit.gupta |
1680 |
}
|
| 24615 |
amit.gupta |
1681 |
|
| 24611 |
amit.gupta |
1682 |
public void dryRunSchemeOutReco1() throws Exception {
|
| 24615 |
amit.gupta |
1683 |
List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
|
| 24611 |
amit.gupta |
1684 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1685 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
|
|
1686 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1687 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1688 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1689 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1690 |
references.stream().forEach(reference -> {
|
|
|
1691 |
FofoOrder fofoOrder = null;
|
|
|
1692 |
try {
|
|
|
1693 |
fofoOrder = fofoOrderRepository.selectByOrderId(reference);
|
| 24615 |
amit.gupta |
1694 |
} catch (Exception e) {
|
|
|
1695 |
|
| 24611 |
amit.gupta |
1696 |
}
|
|
|
1697 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
|
|
1698 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
|
|
1699 |
float amountToRollback = 0;
|
|
|
1700 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1701 |
orderItems.forEach(x -> {
|
|
|
1702 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
|
|
1703 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
|
|
1704 |
});
|
|
|
1705 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24615 |
amit.gupta |
1706 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1707 |
.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
|
|
|
1708 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24611 |
amit.gupta |
1709 |
.collect(Collectors.toList());
|
|
|
1710 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
|
|
1711 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 24615 |
amit.gupta |
1712 |
Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
|
|
|
1713 |
.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
|
| 24611 |
amit.gupta |
1714 |
for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
|
|
|
1715 |
List<SchemeInOut> outList = inventorySioEntry.getValue();
|
| 24615 |
amit.gupta |
1716 |
if (outList.size() > 1) {
|
|
|
1717 |
|
| 24611 |
amit.gupta |
1718 |
}
|
|
|
1719 |
}
|
|
|
1720 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1721 |
uwh.setDescription(description);
|
|
|
1722 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1723 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1724 |
uwh.setReference(fofoOrder.getId());
|
|
|
1725 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1726 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1727 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1728 |
userWalletHistory.add(uwh);
|
|
|
1729 |
}
|
|
|
1730 |
});
|
| 24615 |
amit.gupta |
1731 |
|
| 24611 |
amit.gupta |
1732 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1733 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
|
|
1734 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
| 30393 |
amit.gupta |
1735 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24615 |
amit.gupta |
1736 |
.collect(Collectors.toList()));
|
|
|
1737 |
|
| 24611 |
amit.gupta |
1738 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1739 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1740 |
"Rolledback"),
|
|
|
1741 |
rolledbackSios.stream()
|
| 24615 |
amit.gupta |
1742 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1743 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1744 |
.collect(Collectors.toList()));
|
|
|
1745 |
|
| 24623 |
amit.gupta |
1746 |
Utils.sendMailWithAttachments(googleMailSender,
|
| 30393 |
amit.gupta |
1747 |
new String[]{"amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com"}, null,
|
| 24611 |
amit.gupta |
1748 |
"Partner Excess Amount", "PFA",
|
| 30393 |
amit.gupta |
1749 |
new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1750 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
|
| 24631 |
amit.gupta |
1751 |
|
| 24628 |
amit.gupta |
1752 |
throw new Exception();
|
| 24615 |
amit.gupta |
1753 |
|
| 24611 |
amit.gupta |
1754 |
}
|
| 24615 |
amit.gupta |
1755 |
|
| 26945 |
amit.gupta |
1756 |
public void sendDailySalesNotificationToPartner(Integer fofoIdInt) throws Exception {
|
| 25927 |
amit.gupta |
1757 |
|
| 24653 |
govind |
1758 |
LocalDateTime now = LocalDateTime.now();
|
| 25837 |
amit.gupta |
1759 |
LocalDateTime from = now.with(LocalTime.MIN);
|
| 25925 |
amit.gupta |
1760 |
String timeString = "Today %s";
|
| 25927 |
amit.gupta |
1761 |
// Send yesterday's report
|
| 27007 |
amit.gupta |
1762 |
/*
|
|
|
1763 |
* if (now.getHour() < 13) { timeString = "Yesterday %s"; from =
|
|
|
1764 |
* now.minusDays(1).; now = from.with(LocalTime.MAX);
|
| 30393 |
amit.gupta |
1765 |
*
|
| 27007 |
amit.gupta |
1766 |
* }
|
|
|
1767 |
*/
|
| 24855 |
amit.gupta |
1768 |
List<Integer> fofoIds = null;
|
| 25043 |
amit.gupta |
1769 |
if (fofoIdInt == null) {
|
|
|
1770 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
1771 |
.collect(Collectors.toList());
|
| 24856 |
amit.gupta |
1772 |
} else {
|
| 24855 |
amit.gupta |
1773 |
fofoIds = Arrays.asList(fofoIdInt);
|
|
|
1774 |
}
|
| 25912 |
amit.gupta |
1775 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
| 24683 |
amit.gupta |
1776 |
|
| 25865 |
amit.gupta |
1777 |
Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
|
|
|
1778 |
null);
|
|
|
1779 |
Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
|
| 26945 |
amit.gupta |
1780 |
|
|
|
1781 |
Map<Integer, Double> spPartnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
|
|
1782 |
true);
|
|
|
1783 |
|
|
|
1784 |
Map<Integer, Double> spPartner3DaysOrderValMap = fofoOrderItemRepository
|
|
|
1785 |
.selectSumAmountGroupByRetailer(from.minusDays(3), now, 0, true);
|
| 26941 |
amit.gupta |
1786 |
Map<Integer, Long> spPartnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
|
|
|
1787 |
|
| 26945 |
amit.gupta |
1788 |
Map<Integer, Double> partnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
|
|
1789 |
false);
|
| 26941 |
amit.gupta |
1790 |
Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, false);
|
| 26945 |
amit.gupta |
1791 |
|
| 25865 |
amit.gupta |
1792 |
Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
|
|
|
1793 |
for (int fofoId : fofoIds) {
|
|
|
1794 |
SaleTargetReportModel model = new SaleTargetReportModel();
|
| 25927 |
amit.gupta |
1795 |
model.setInsuranceSale(
|
|
|
1796 |
partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
|
| 25865 |
amit.gupta |
1797 |
model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
|
| 26941 |
amit.gupta |
1798 |
model.setSmartphoneSale(spPartnerOrderValMap.containsKey(fofoId) ? spPartnerOrderValMap.get(fofoId) : 0);
|
|
|
1799 |
model.setSmartphoneQty(spPartnerOrderQtyMap.containsKey(fofoId) ? spPartnerOrderQtyMap.get(fofoId) : 0);
|
|
|
1800 |
model.setTotalSale(partnerOrderValMap.containsKey(fofoId) ? partnerOrderValMap.get(fofoId) : 0);
|
|
|
1801 |
model.setTotalQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
|
| 26945 |
amit.gupta |
1802 |
model.setPast3daysSale(
|
|
|
1803 |
spPartner3DaysOrderValMap.containsKey(fofoId) ? spPartner3DaysOrderValMap.get(fofoId) : 0);
|
| 25880 |
amit.gupta |
1804 |
model.setFofoId(fofoId);
|
| 25865 |
amit.gupta |
1805 |
saleTargetReportModelMap.put(fofoId, model);
|
|
|
1806 |
}
|
| 25880 |
amit.gupta |
1807 |
|
| 26945 |
amit.gupta |
1808 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 24653 |
govind |
1809 |
for (Integer fofoId : fofoIds) {
|
| 25865 |
amit.gupta |
1810 |
SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
|
| 25821 |
amit.gupta |
1811 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1812 |
sendNotificationModel.setCampaignName("Sales update alert");
|
| 25884 |
tejbeer |
1813 |
sendNotificationModel.setTitle("Sale Update");
|
| 25927 |
amit.gupta |
1814 |
sendNotificationModel
|
|
|
1815 |
.setMessage(String.format("Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
|
|
1816 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
|
|
1817 |
String.format(timeString, now.format(timeFormatter))));
|
| 25821 |
amit.gupta |
1818 |
sendNotificationModel.setType("url");
|
| 27206 |
tejbeer |
1819 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 25821 |
amit.gupta |
1820 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
1821 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25872 |
tejbeer |
1822 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
|
|
1823 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 25854 |
amit.gupta |
1824 |
notificationService.sendNotification(sendNotificationModel);
|
| 24653 |
govind |
1825 |
}
|
| 26945 |
amit.gupta |
1826 |
// String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap,
|
|
|
1827 |
// saleTargetReportModelMap);
|
|
|
1828 |
String statewiseSaleReport = this.getStateWiseSales(saleTargetReportModelMap, partnerSalesHeadersMap);
|
| 30393 |
amit.gupta |
1829 |
String cc[] = {"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "amit.babu@smartdukaan.com",
|
|
|
1830 |
"niranjan.kala@smartdukaan.com", "up.singh@smartdukaan.com", "sm@smartdukaan.com"};
|
| 25837 |
amit.gupta |
1831 |
|
| 25912 |
amit.gupta |
1832 |
String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
|
| 26945 |
amit.gupta |
1833 |
// this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc,
|
|
|
1834 |
// subject);
|
|
|
1835 |
this.sendMailOfHtmlFormat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
|
| 24653 |
govind |
1836 |
}
|
|
|
1837 |
|
| 28377 |
tejbeer |
1838 |
public void checkRazorPayPaymentStatus() throws Exception {
|
| 28368 |
tejbeer |
1839 |
List<PendingOrder> pendingOrder = pendingOrderRepository
|
|
|
1840 |
.selectAllByStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PENDING);
|
|
|
1841 |
|
|
|
1842 |
for (PendingOrder po : pendingOrder) {
|
|
|
1843 |
RazorPay razorPay = razorPayRepository.selectByOrdeId(po.getId());
|
| 28377 |
tejbeer |
1844 |
List<PendingOrderItem> poItems = pendingOrderItemRepository.selectByOrderId(po.getId());
|
| 28368 |
tejbeer |
1845 |
|
| 28369 |
tejbeer |
1846 |
LOGGER.info("razorPay" + razorPay);
|
|
|
1847 |
if (razorPay != null) {
|
|
|
1848 |
List<Payment> payments = razorPaymentService.fetchOrderForPayment(razorPay.getRazorOrderId());
|
| 28377 |
tejbeer |
1849 |
|
| 28369 |
tejbeer |
1850 |
if (!payments.isEmpty()) {
|
| 28377 |
tejbeer |
1851 |
List<String> statusList = new ArrayList<>();
|
| 28369 |
tejbeer |
1852 |
for (Payment payment : payments) {
|
| 28368 |
tejbeer |
1853 |
|
| 28377 |
tejbeer |
1854 |
JSONObject jsonObj = new JSONObject(payment.toString());
|
|
|
1855 |
|
|
|
1856 |
String status = jsonObj.getString("status");
|
|
|
1857 |
|
|
|
1858 |
statusList.add(status);
|
|
|
1859 |
|
| 28369 |
tejbeer |
1860 |
}
|
| 28377 |
tejbeer |
1861 |
LOGGER.info("statusList" + statusList);
|
| 28368 |
tejbeer |
1862 |
|
| 28377 |
tejbeer |
1863 |
if (statusList.contains("authorized") || statusList.contains("captured")) {
|
|
|
1864 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
|
|
1865 |
po.setPaidAmount(po.getTotalAmount());
|
|
|
1866 |
for (PendingOrderItem poi : poItems) {
|
|
|
1867 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
|
|
1868 |
}
|
|
|
1869 |
Map<String, Object> emailModel = pendingOrderService.sendCreateOrderMail(po);
|
|
|
1870 |
|
|
|
1871 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(po.getFofoId());
|
|
|
1872 |
Customer customer = customerRepository.selectById(po.getCustomerId());
|
|
|
1873 |
String[] customerEmail = null;
|
|
|
1874 |
if (customer.getEmailId() != null) {
|
| 30393 |
amit.gupta |
1875 |
customerEmail = new String[]{customer.getEmailId()};
|
| 28377 |
tejbeer |
1876 |
}
|
|
|
1877 |
List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com",
|
| 28467 |
tejbeer |
1878 |
"tarun.verma@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
|
|
|
1879 |
"tejbeer.kaur@shop2020.in", customRetailer.getEmail());
|
| 28377 |
tejbeer |
1880 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
|
|
1881 |
if (authUserEmails != null) {
|
|
|
1882 |
authUserEmails = new ArrayList<>();
|
|
|
1883 |
}
|
|
|
1884 |
authUserEmails.addAll(bccTo);
|
|
|
1885 |
|
| 28382 |
tejbeer |
1886 |
// emailService.sendMailWithAttachments("Order Created with SmartDukaan",
|
|
|
1887 |
// "order-confirm.vm",
|
|
|
1888 |
// emailModel, customerEmail, null, authUserEmails.toArray(new String[0]));
|
| 28377 |
tejbeer |
1889 |
|
|
|
1890 |
} else if (statusList.contains("refunded") || statusList.contains("failed")) {
|
|
|
1891 |
for (PendingOrderItem poi : poItems) {
|
|
|
1892 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
|
|
1893 |
}
|
|
|
1894 |
|
|
|
1895 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
|
|
1896 |
}
|
|
|
1897 |
|
| 28369 |
tejbeer |
1898 |
}
|
| 28377 |
tejbeer |
1899 |
// LOGGER.info("payment" + payments);
|
| 28369 |
tejbeer |
1900 |
|
|
|
1901 |
}
|
| 28368 |
tejbeer |
1902 |
}
|
|
|
1903 |
}
|
|
|
1904 |
|
| 25865 |
amit.gupta |
1905 |
public static class SaleTargetReportModel {
|
|
|
1906 |
private double totalSale;
|
| 26941 |
amit.gupta |
1907 |
private long totalQty;
|
| 26945 |
amit.gupta |
1908 |
private double past3daysSale;
|
| 25880 |
amit.gupta |
1909 |
private int fofoId;
|
|
|
1910 |
|
|
|
1911 |
public int getFofoId() {
|
|
|
1912 |
return fofoId;
|
|
|
1913 |
}
|
|
|
1914 |
|
|
|
1915 |
public void setFofoId(int fofoId) {
|
|
|
1916 |
this.fofoId = fofoId;
|
|
|
1917 |
}
|
|
|
1918 |
|
| 25865 |
amit.gupta |
1919 |
private double smartphoneSale;
|
|
|
1920 |
private long smartphoneQty;
|
|
|
1921 |
private double insuranceSale;
|
|
|
1922 |
private long insruanceQty;
|
|
|
1923 |
|
| 26941 |
amit.gupta |
1924 |
public long getTotalQty() {
|
|
|
1925 |
return totalQty;
|
|
|
1926 |
}
|
|
|
1927 |
|
|
|
1928 |
public void setTotalQty(long totalQty) {
|
|
|
1929 |
this.totalQty = totalQty;
|
|
|
1930 |
}
|
|
|
1931 |
|
| 26945 |
amit.gupta |
1932 |
public double getPast3daysSale() {
|
|
|
1933 |
return past3daysSale;
|
|
|
1934 |
}
|
|
|
1935 |
|
|
|
1936 |
public void setPast3daysSale(double past3daysSale) {
|
|
|
1937 |
this.past3daysSale = past3daysSale;
|
|
|
1938 |
}
|
|
|
1939 |
|
| 25865 |
amit.gupta |
1940 |
@Override
|
|
|
1941 |
public int hashCode() {
|
|
|
1942 |
final int prime = 31;
|
|
|
1943 |
int result = 1;
|
| 25880 |
amit.gupta |
1944 |
result = prime * result + fofoId;
|
| 25865 |
amit.gupta |
1945 |
result = prime * result + (int) (insruanceQty ^ (insruanceQty >>> 32));
|
|
|
1946 |
long temp;
|
|
|
1947 |
temp = Double.doubleToLongBits(insuranceSale);
|
|
|
1948 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1949 |
result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
|
|
|
1950 |
temp = Double.doubleToLongBits(smartphoneSale);
|
|
|
1951 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
| 26941 |
amit.gupta |
1952 |
result = prime * result + (int) (totalQty ^ (totalQty >>> 32));
|
| 25865 |
amit.gupta |
1953 |
temp = Double.doubleToLongBits(totalSale);
|
|
|
1954 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1955 |
return result;
|
|
|
1956 |
}
|
|
|
1957 |
|
|
|
1958 |
@Override
|
|
|
1959 |
public boolean equals(Object obj) {
|
|
|
1960 |
if (this == obj)
|
|
|
1961 |
return true;
|
|
|
1962 |
if (obj == null)
|
|
|
1963 |
return false;
|
|
|
1964 |
if (getClass() != obj.getClass())
|
|
|
1965 |
return false;
|
|
|
1966 |
SaleTargetReportModel other = (SaleTargetReportModel) obj;
|
| 25880 |
amit.gupta |
1967 |
if (fofoId != other.fofoId)
|
|
|
1968 |
return false;
|
| 25865 |
amit.gupta |
1969 |
if (insruanceQty != other.insruanceQty)
|
|
|
1970 |
return false;
|
|
|
1971 |
if (Double.doubleToLongBits(insuranceSale) != Double.doubleToLongBits(other.insuranceSale))
|
|
|
1972 |
return false;
|
|
|
1973 |
if (smartphoneQty != other.smartphoneQty)
|
|
|
1974 |
return false;
|
|
|
1975 |
if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
|
|
|
1976 |
return false;
|
| 26941 |
amit.gupta |
1977 |
if (totalQty != other.totalQty)
|
|
|
1978 |
return false;
|
| 25865 |
amit.gupta |
1979 |
if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
|
|
|
1980 |
return false;
|
|
|
1981 |
return true;
|
|
|
1982 |
}
|
|
|
1983 |
|
|
|
1984 |
public double getTotalSale() {
|
|
|
1985 |
return totalSale;
|
|
|
1986 |
}
|
|
|
1987 |
|
|
|
1988 |
public void setTotalSale(double totalSale) {
|
|
|
1989 |
this.totalSale = totalSale;
|
|
|
1990 |
}
|
|
|
1991 |
|
|
|
1992 |
public double getSmartphoneSale() {
|
|
|
1993 |
return smartphoneSale;
|
|
|
1994 |
}
|
|
|
1995 |
|
|
|
1996 |
public void setSmartphoneSale(double smartphoneSale) {
|
|
|
1997 |
this.smartphoneSale = smartphoneSale;
|
|
|
1998 |
}
|
|
|
1999 |
|
|
|
2000 |
public long getSmartphoneQty() {
|
|
|
2001 |
return smartphoneQty;
|
|
|
2002 |
}
|
|
|
2003 |
|
|
|
2004 |
public void setSmartphoneQty(long smartphoneQty) {
|
|
|
2005 |
this.smartphoneQty = smartphoneQty;
|
|
|
2006 |
}
|
|
|
2007 |
|
|
|
2008 |
public double getInsuranceSale() {
|
|
|
2009 |
return insuranceSale;
|
|
|
2010 |
}
|
|
|
2011 |
|
|
|
2012 |
public void setInsuranceSale(double insuranceSale) {
|
|
|
2013 |
this.insuranceSale = insuranceSale;
|
|
|
2014 |
}
|
|
|
2015 |
|
|
|
2016 |
public long getInsruanceQty() {
|
|
|
2017 |
return insruanceQty;
|
|
|
2018 |
}
|
|
|
2019 |
|
|
|
2020 |
public void setInsruanceQty(long insruanceQty) {
|
|
|
2021 |
this.insruanceQty = insruanceQty;
|
|
|
2022 |
}
|
|
|
2023 |
|
|
|
2024 |
@Override
|
|
|
2025 |
public String toString() {
|
| 26945 |
amit.gupta |
2026 |
return "SaleTargetReportModel [totalSale=" + totalSale + ", totalQty=" + totalQty + ", past3daysSale="
|
|
|
2027 |
+ past3daysSale + ", fofoId=" + fofoId + ", smartphoneSale=" + smartphoneSale + ", smartphoneQty="
|
|
|
2028 |
+ smartphoneQty + ", insuranceSale=" + insuranceSale + ", insruanceQty=" + insruanceQty + "]";
|
| 25865 |
amit.gupta |
2029 |
}
|
|
|
2030 |
|
|
|
2031 |
}
|
|
|
2032 |
|
| 26945 |
amit.gupta |
2033 |
private String getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap,
|
| 30393 |
amit.gupta |
2034 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap) throws Exception {
|
| 26940 |
amit.gupta |
2035 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
| 26945 |
amit.gupta |
2036 |
Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors
|
|
|
2037 |
.groupingBy(x -> x.getCode().substring(0, 2), Collectors.mapping(x -> x.getId(), Collectors.toList())));
|
| 26940 |
amit.gupta |
2038 |
List<List<Serializable>> stateWiseSales = new ArrayList<>();
|
|
|
2039 |
for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
|
| 26945 |
amit.gupta |
2040 |
long totalQty = stateMapEntry.getValue().stream()
|
|
|
2041 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getTotalQty()));
|
|
|
2042 |
double totalSale = stateMapEntry.getValue().stream()
|
|
|
2043 |
.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getTotalSale()));
|
|
|
2044 |
long smartPhoneQty = stateMapEntry.getValue().stream()
|
|
|
2045 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getSmartphoneQty()));
|
|
|
2046 |
double smartPhoneSale = stateMapEntry.getValue().stream()
|
|
|
2047 |
.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getSmartphoneSale()));
|
|
|
2048 |
stateWiseSales
|
|
|
2049 |
.add(Arrays.asList(stateMapEntry.getKey(), smartPhoneQty, smartPhoneSale, totalQty, totalSale));
|
| 26940 |
amit.gupta |
2050 |
}
|
|
|
2051 |
StringBuilder sb = new StringBuilder();
|
| 26945 |
amit.gupta |
2052 |
sb.append("<html><body>");
|
|
|
2053 |
sb.append("<p>Statewise Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 26940 |
amit.gupta |
2054 |
sb.append("<tbody>\n" + " <tr>"
|
|
|
2055 |
+ " <th style='border:1px solid black;padding: 5px'>State</th>"
|
| 26941 |
amit.gupta |
2056 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
|
|
2057 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Value</th>"
|
|
|
2058 |
+ " <th style='border:1px solid black;padding: 5px'>Total Qty</th>"
|
|
|
2059 |
+ " <th style='border:1px solid black;padding: 5px'>Total Value</th>"
|
| 26940 |
amit.gupta |
2060 |
+ " </tr>");
|
|
|
2061 |
for (List<Serializable> stateSale : stateWiseSales) {
|
|
|
2062 |
sb.append("<tr>");
|
|
|
2063 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(0) + "</td>");
|
|
|
2064 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(1) + "</td>");
|
|
|
2065 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
|
| 26941 |
amit.gupta |
2066 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(3) + "</td>");
|
|
|
2067 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(4) + "</td>");
|
| 26940 |
amit.gupta |
2068 |
sb.append("</tr>");
|
|
|
2069 |
}
|
| 26945 |
amit.gupta |
2070 |
sb.append("</tbody></table><br><br>");
|
| 25872 |
tejbeer |
2071 |
|
| 26945 |
amit.gupta |
2072 |
sb.append("<p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 24653 |
govind |
2073 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 26945 |
amit.gupta |
2074 |
+ " <th style='border:1px solid black;padding: 5px'>Code</th>"
|
|
|
2075 |
+ " <th style='border:1px solid black;padding: 5px'>Business Name</th>"
|
|
|
2076 |
+ " <th style='border:1px solid black;padding: 5px'>Regional Manager</th>"
|
|
|
2077 |
+ " <th style='border:1px solid black;padding: 5px'>Territory Manager</th>"
|
|
|
2078 |
+ " <th style='border:1px solid black;padding: 5px'>Sale</th>"
|
|
|
2079 |
+ " <th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>"
|
|
|
2080 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
| 24653 |
govind |
2081 |
+ " </tr>");
|
| 26945 |
amit.gupta |
2082 |
|
|
|
2083 |
List<Integer> sortedPartnerSalesHeaders = partnerSalesHeadersMap.values().stream()
|
| 26947 |
amit.gupta |
2084 |
.sorted(Comparator.comparing(FofoReportingModel::getCode)
|
|
|
2085 |
.thenComparing(FofoReportingModel::getRegionalManager)
|
| 26948 |
amit.gupta |
2086 |
.thenComparing(FofoReportingModel::getTerritoryManager))
|
| 26945 |
amit.gupta |
2087 |
.map(FofoReportingModel::getFofoId).collect(Collectors.toList());
|
| 25927 |
amit.gupta |
2088 |
for (Integer fofoId : sortedPartnerSalesHeaders) {
|
| 27007 |
amit.gupta |
2089 |
if (saleTargetReportModelMap.get(fofoId).getPast3daysSale() == 0) {
|
| 26947 |
amit.gupta |
2090 |
sb.append("<tr style='background-color:red'>");
|
|
|
2091 |
} else {
|
| 26945 |
amit.gupta |
2092 |
sb.append("<tr>");
|
|
|
2093 |
}
|
|
|
2094 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).getCode()
|
| 25880 |
amit.gupta |
2095 |
+ "</td>");
|
|
|
2096 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 27007 |
amit.gupta |
2097 |
+ partnerSalesHeadersMap.get(fofoId).getBusinessName() + "</td>");
|
|
|
2098 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2099 |
+ partnerSalesHeadersMap.get(fofoId).getRegionalManager() + "</td>");
|
|
|
2100 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2101 |
+ partnerSalesHeadersMap.get(fofoId).getTerritoryManager() + "</td>");
|
|
|
2102 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 26945 |
amit.gupta |
2103 |
+ saleTargetReportModelMap.get(fofoId).getTotalSale() + "</td>");
|
| 25880 |
amit.gupta |
2104 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 26945 |
amit.gupta |
2105 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneSale() + "</td>");
|
| 25880 |
amit.gupta |
2106 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 26945 |
amit.gupta |
2107 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneQty() + "</td>");
|
| 25865 |
amit.gupta |
2108 |
sb.append("</tr>");
|
| 24653 |
govind |
2109 |
}
|
| 24683 |
amit.gupta |
2110 |
|
| 26945 |
amit.gupta |
2111 |
sb.append("</tr>");
|
|
|
2112 |
|
|
|
2113 |
sb.append("</body></html>");
|
|
|
2114 |
|
|
|
2115 |
return sb.toString();
|
| 24653 |
govind |
2116 |
}
|
| 24841 |
govind |
2117 |
|
| 26945 |
amit.gupta |
2118 |
private void sendMailOfHtmlFormat(String email, String body, String cc[], String subject)
|
| 24841 |
govind |
2119 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
2120 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
2121 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
2122 |
helper.setSubject(subject);
|
|
|
2123 |
helper.setText(body, true);
|
|
|
2124 |
helper.setTo(email);
|
|
|
2125 |
if (cc != null) {
|
|
|
2126 |
helper.setCc(cc);
|
|
|
2127 |
}
|
|
|
2128 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
2129 |
helper.setFrom(senderAddress);
|
|
|
2130 |
mailSender.send(message);
|
|
|
2131 |
}
|
| 25300 |
tejbeer |
2132 |
|
| 25351 |
tejbeer |
2133 |
public void sendNotification() throws Exception {
|
| 25300 |
tejbeer |
2134 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
|
|
2135 |
if (!pushNotifications.isEmpty()) {
|
|
|
2136 |
for (PushNotifications pushNotification : pushNotifications) {
|
| 25351 |
tejbeer |
2137 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
| 25300 |
tejbeer |
2138 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
|
|
2139 |
.selectById(pushNotification.getNotificationCampaignid());
|
|
|
2140 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
2141 |
SimpleCampaignParams.class);
|
|
|
2142 |
Campaign campaign = new SimpleCampaign(scp);
|
| 25351 |
tejbeer |
2143 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
| 25300 |
tejbeer |
2144 |
JSONObject json = new JSONObject();
|
| 25351 |
tejbeer |
2145 |
json.put("to", device.getFcmId());
|
| 25300 |
tejbeer |
2146 |
JSONObject jsonObj = new JSONObject();
|
|
|
2147 |
jsonObj.put("message", campaign.getMessage());
|
|
|
2148 |
jsonObj.put("title", campaign.getTitle());
|
|
|
2149 |
jsonObj.put("type", campaign.getType());
|
|
|
2150 |
jsonObj.put("url", result_url);
|
|
|
2151 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
|
|
2152 |
jsonObj.put("image", campaign.getImageUrl());
|
|
|
2153 |
jsonObj.put("largeIcon", "large_icon");
|
|
|
2154 |
jsonObj.put("smallIcon", "small_icon");
|
|
|
2155 |
jsonObj.put("vibrate", 1);
|
|
|
2156 |
jsonObj.put("pid", pushNotification.getId());
|
|
|
2157 |
jsonObj.put("sound", 1);
|
|
|
2158 |
jsonObj.put("priority", "high");
|
|
|
2159 |
json.put("data", jsonObj);
|
| 25351 |
tejbeer |
2160 |
try {
|
|
|
2161 |
CloseableHttpClient client = HttpClients.createDefault();
|
|
|
2162 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| 25300 |
tejbeer |
2163 |
|
| 25351 |
tejbeer |
2164 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
|
|
2165 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
|
|
2166 |
StringEntity entity = new StringEntity(json.toString());
|
|
|
2167 |
httpPost.setEntity(entity);
|
|
|
2168 |
CloseableHttpResponse response = client.execute(httpPost);
|
| 25300 |
tejbeer |
2169 |
|
| 25351 |
tejbeer |
2170 |
if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
2171 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
|
|
2172 |
} else {
|
| 25356 |
tejbeer |
2173 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 25778 |
amit.gupta |
2174 |
LOGGER.info("message" + "not sent");
|
| 26945 |
amit.gupta |
2175 |
response.toString();
|
| 25351 |
tejbeer |
2176 |
}
|
| 25300 |
tejbeer |
2177 |
|
| 25351 |
tejbeer |
2178 |
} catch (Exception e) {
|
|
|
2179 |
e.printStackTrace();
|
| 26443 |
amit.gupta |
2180 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 26436 |
amit.gupta |
2181 |
LOGGER.info("message " + "not sent " + e.getMessage());
|
| 25300 |
tejbeer |
2182 |
}
|
|
|
2183 |
}
|
|
|
2184 |
}
|
|
|
2185 |
}
|
|
|
2186 |
|
| 25553 |
amit.gupta |
2187 |
public void grouping() throws Exception {
|
| 25609 |
amit.gupta |
2188 |
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM-dd-yyyy hh:mm");
|
|
|
2189 |
List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByStatus(PriceDropImeiStatus.APPROVED);
|
|
|
2190 |
System.out.println(String.join("\t",
|
|
|
2191 |
Arrays.asList("IMEI", "ItemId", "Brand", "Model Name", "Model Number", "Franchise Id", "Franchise Name",
|
| 25694 |
amit.gupta |
2192 |
"Grn On", "Price Dropped On", "Approved On", "Returned On", "Price Drop Paid", "Is Doa")));
|
| 26963 |
amit.gupta |
2193 |
Map<Integer, CustomRetailer> retailersMap = retailerService.getFofoRetailers(false);
|
| 25609 |
amit.gupta |
2194 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
| 25694 |
amit.gupta |
2195 |
if (priceDropIMEI.getPartnerId() == 0)
|
|
|
2196 |
continue;
|
| 25609 |
amit.gupta |
2197 |
HashSet<String> imeis = new HashSet<>();
|
|
|
2198 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropIMEI.getPriceDropId());
|
|
|
2199 |
imeis.add(priceDropIMEI.getImei());
|
|
|
2200 |
List<InventoryItem> inventoryItems = inventoryItemRepository
|
|
|
2201 |
.selectByFofoIdSerialNumbers(priceDropIMEI.getPartnerId(), imeis, false);
|
| 25694 |
amit.gupta |
2202 |
if (inventoryItems.size() == 0) {
|
|
|
2203 |
LOGGER.info("Need to investigate partnerId - {} imeis - {}", priceDropIMEI.getPartnerId(), imeis);
|
| 25613 |
amit.gupta |
2204 |
continue;
|
| 25612 |
amit.gupta |
2205 |
}
|
| 25609 |
amit.gupta |
2206 |
InventoryItem inventoryItem = inventoryItems.get(0);
|
|
|
2207 |
CustomRetailer customRetailer = retailersMap.get(inventoryItem.getFofoId());
|
|
|
2208 |
if (inventoryItem.getLastScanType().equals(ScanType.DOA_OUT)
|
|
|
2209 |
|| inventoryItem.getLastScanType().equals(ScanType.PURCHASE_RET)) {
|
|
|
2210 |
// check if pricedrop has been rolled out
|
|
|
2211 |
List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
|
|
|
2212 |
priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
|
|
|
2213 |
if (uwh.size() > 0) {
|
| 25615 |
amit.gupta |
2214 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 26945 |
amit.gupta |
2215 |
System.out.println(String.join("\t", Arrays.asList(priceDropIMEI.getImei(),
|
|
|
2216 |
inventoryItem.getItemId() + "", item.getBrand(), item.getModelName(), item.getModelNumber(),
|
|
|
2217 |
inventoryItem.getFofoId() + "", customRetailer.getBusinessName(),
|
|
|
2218 |
inventoryItem.getCreateTimestamp().format(dtf), priceDrop.getAffectedOn().format(dtf),
|
|
|
2219 |
priceDropIMEI.getUpdateTimestamp().format(dtf),
|
|
|
2220 |
inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
|
|
|
2221 |
inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
|
| 25609 |
amit.gupta |
2222 |
}
|
|
|
2223 |
}
|
|
|
2224 |
}
|
| 25503 |
amit.gupta |
2225 |
}
|
| 29668 |
tejbeer |
2226 |
|
| 29566 |
amit.gupta |
2227 |
public void toffeeRollback() throws Exception {
|
|
|
2228 |
toffeeService.cancelPolicyCopy("110143521986");
|
|
|
2229 |
toffeeService.getOrderId("110143521986");
|
|
|
2230 |
}
|
| 25694 |
amit.gupta |
2231 |
|
| 27686 |
amit.gupta |
2232 |
public void attachToffeeInvoices() throws Exception {
|
| 28205 |
tejbeer |
2233 |
/*
|
|
|
2234 |
* LOGGER.info("Insurance Sum Summary --- {}",
|
|
|
2235 |
* insurancePolicyRepository.selectAmountSumGroupByRetailerId(LocalDateTime.MIN,
|
|
|
2236 |
* LocalDateTime.MAX)); LOGGER.info("Insurance Qty Summary --- {}",
|
|
|
2237 |
* insurancePolicyRepository.selectQtyGroupByRetailerId(LocalDateTime.MIN,
|
|
|
2238 |
* LocalDateTime.MAX)); LOGGER.info("SmartPhone Amount Summary --- {}",
|
|
|
2239 |
* fofoOrderItemRepository.selectSumAmountGroupByRetailer(LocalDateTime.MIN,
|
|
|
2240 |
* LocalDateTime.MAX, 0, true)); LOGGER.info("Smartphone Qty Summary --- {}",
|
|
|
2241 |
* fofoOrderItemRepository.selectQtyGroupByRetailer(LocalDateTime.MIN,
|
|
|
2242 |
* LocalDateTime.MAX, 0, true));
|
|
|
2243 |
*/
|
|
|
2244 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(3,
|
|
|
2245 |
Optional.of(false));
|
|
|
2246 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 27678 |
amit.gupta |
2247 |
String invoiceNumber = insurancePolicy.getInvoiceNumber();
|
|
|
2248 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 30321 |
amit.gupta |
2249 |
InvoicePdfModel pdfModel = orderService.getInvoicePdfModel(fofoOrder.getId());
|
| 27678 |
amit.gupta |
2250 |
java.io.ByteArrayOutputStream byteArrayOutputStream = new java.io.ByteArrayOutputStream();
|
|
|
2251 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
| 28205 |
tejbeer |
2252 |
String pdfInvoiceString = "data:application/pdf;base64,"
|
|
|
2253 |
+ Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray());
|
|
|
2254 |
boolean attached = toffeeService.attachInvoice(insurancePolicy.getPolicyNumber().split("#")[1],
|
|
|
2255 |
pdfInvoiceString);
|
|
|
2256 |
if (attached) {
|
| 27678 |
amit.gupta |
2257 |
insurancePolicy.setPosted(true);
|
|
|
2258 |
}
|
|
|
2259 |
}
|
| 25694 |
amit.gupta |
2260 |
}
|
|
|
2261 |
|
|
|
2262 |
public void schemeRollback(List<String> schemeIds) throws Exception {
|
|
|
2263 |
List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
|
| 25708 |
amit.gupta |
2264 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()
|
| 25694 |
amit.gupta |
2265 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
2266 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIdsInt));
|
|
|
2267 |
for (SchemeInOut sio : schemeInOuts) {
|
|
|
2268 |
Scheme scheme = schemesMap.get(sio.getSchemeId());
|
|
|
2269 |
if (scheme.getType().equals(SchemeType.IN)) {
|
|
|
2270 |
|
|
|
2271 |
} else if (scheme.getType().equals(SchemeType.OUT)) {
|
|
|
2272 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
|
|
2273 |
List<ScanRecord> sr = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId());
|
|
|
2274 |
ScanRecord scanRecord = sr.stream().filter(x -> x.getType().equals(ScanType.SALE))
|
|
|
2275 |
.max((x1, x2) -> x1.getCreateTimestamp().compareTo(x2.getCreateTimestamp())).get();
|
|
|
2276 |
if (scanRecord.getCreateTimestamp().isAfter(scheme.getEndDateTime())
|
|
|
2277 |
|| scanRecord.getCreateTimestamp().isBefore(scheme.getStartDateTime())) {
|
|
|
2278 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
2279 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
|
| 25709 |
amit.gupta |
2280 |
String rollbackReason = "Scheme reversed for "
|
|
|
2281 |
+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
|
| 25694 |
amit.gupta |
2282 |
+ fofoOrder.getInvoiceNumber();
|
|
|
2283 |
walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
|
| 26945 |
amit.gupta |
2284 |
scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason,
|
|
|
2285 |
LocalDateTime.now());
|
| 25694 |
amit.gupta |
2286 |
System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
|
|
|
2287 |
rollbackReason);
|
|
|
2288 |
}
|
|
|
2289 |
}
|
|
|
2290 |
}
|
| 25721 |
tejbeer |
2291 |
// throw new Exception();
|
| 25694 |
amit.gupta |
2292 |
}
|
| 25721 |
tejbeer |
2293 |
|
|
|
2294 |
public void checkfocusedModelInPartnerStock() throws Exception {
|
|
|
2295 |
|
|
|
2296 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
2297 |
.collect(Collectors.toList());
|
| 27212 |
tejbeer |
2298 |
Map<Integer, Map<Integer, List<SaholicCIS>>> warehouseItemAvailabilityMap = saholicInventoryService
|
|
|
2299 |
.getSaholicStock();
|
| 27213 |
tejbeer |
2300 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
|
|
2301 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 27212 |
tejbeer |
2302 |
|
|
|
2303 |
Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap = saholicInventoryService
|
|
|
2304 |
.getSaholicPOItems();
|
| 25721 |
tejbeer |
2305 |
Map<Integer, List<FocusedModelShortageModel>> focusedModelShortageReportMap = new HashMap<>();
|
|
|
2306 |
for (Integer fofoId : fofoIds) {
|
| 27102 |
amit.gupta |
2307 |
List<FocusedModelShortageModel> focusedModelShortageList = new ArrayList<>();
|
|
|
2308 |
focusedModelShortageReportMap.put(fofoId, focusedModelShortageList);
|
| 25721 |
tejbeer |
2309 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
2310 |
Map<Integer, Integer> processingOrderMap = null;
|
|
|
2311 |
Map<Integer, Integer> catalogIdAndQtyMap = null;
|
|
|
2312 |
Map<Integer, Integer> grnPendingOrdersMap = null;
|
|
|
2313 |
|
|
|
2314 |
Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
|
|
|
2315 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
2316 |
|
|
|
2317 |
if (!currentInventorySnapshot.isEmpty()) {
|
|
|
2318 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
|
|
2319 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
2320 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
|
|
2321 |
|
|
|
2322 |
}
|
|
|
2323 |
|
|
|
2324 |
Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
|
|
2325 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
2326 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
2327 |
if (!grnPendingOrders.isEmpty()) {
|
|
|
2328 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
|
|
2329 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
2330 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
|
|
2331 |
|
|
|
2332 |
}
|
|
|
2333 |
|
|
|
2334 |
Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
|
|
|
2335 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
2336 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
2337 |
if (!processingOrder.isEmpty()) {
|
|
|
2338 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
|
|
2339 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
2340 |
Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
|
|
2341 |
|
|
|
2342 |
}
|
|
|
2343 |
|
| 25800 |
tejbeer |
2344 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
2345 |
.collect(Collectors.toList());
|
|
|
2346 |
|
| 27088 |
tejbeer |
2347 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
|
|
2348 |
.collect(Collectors.toList());
|
| 27095 |
tejbeer |
2349 |
LOGGER.info("regionIds" + regionIds);
|
| 27102 |
amit.gupta |
2350 |
if (regionIds.size() == 0) {
|
|
|
2351 |
LOGGER.info("No region found for partner {}", fofoId);
|
|
|
2352 |
continue;
|
|
|
2353 |
}
|
| 27100 |
amit.gupta |
2354 |
Map<Integer, Optional<Integer>> focusedCatalogIdAndQtyMap = focusedModelRepository
|
| 27102 |
amit.gupta |
2355 |
.selectAllByRegionIds(regionIds).stream().collect(Collectors.groupingBy(FocusedModel::getCatalogId,
|
| 29668 |
tejbeer |
2356 |
Collectors.mapping(FocusedModel::getObsMinimumQty, Collectors.maxBy(Integer::compareTo))));
|
| 25800 |
tejbeer |
2357 |
|
| 25721 |
tejbeer |
2358 |
LOGGER.info("focusedCatalogIdAndQtyMap" + focusedCatalogIdAndQtyMap);
|
|
|
2359 |
|
| 27100 |
amit.gupta |
2360 |
for (Map.Entry<Integer, Optional<Integer>> entry : focusedCatalogIdAndQtyMap.entrySet()) {
|
|
|
2361 |
int minQty = entry.getValue().get();
|
| 25721 |
tejbeer |
2362 |
int inStockQty = 0;
|
|
|
2363 |
int processingQty = 0;
|
|
|
2364 |
int grnPendingQty = 0;
|
| 27208 |
tejbeer |
2365 |
int allColorNetAvailability = 0;
|
| 27253 |
tejbeer |
2366 |
int allColorPoAvailability = 0;
|
| 25721 |
tejbeer |
2367 |
if (processingOrderMap != null) {
|
|
|
2368 |
processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
|
|
|
2369 |
: processingOrderMap.get(entry.getKey());
|
|
|
2370 |
|
|
|
2371 |
}
|
|
|
2372 |
if (grnPendingOrdersMap != null) {
|
|
|
2373 |
grnPendingQty = (grnPendingOrdersMap.get(entry.getKey()) == null) ? 0
|
|
|
2374 |
: grnPendingOrdersMap.get(entry.getKey());
|
|
|
2375 |
|
|
|
2376 |
}
|
|
|
2377 |
if (catalogIdAndQtyMap != null) {
|
|
|
2378 |
inStockQty = (catalogIdAndQtyMap.get(entry.getKey()) == null) ? 0
|
|
|
2379 |
: catalogIdAndQtyMap.get(entry.getKey());
|
|
|
2380 |
|
|
|
2381 |
}
|
| 28526 |
tejbeer |
2382 |
|
|
|
2383 |
int grnStockQty = grnPendingQty + inStockQty;
|
| 25721 |
tejbeer |
2384 |
int totalQty = processingQty + grnPendingQty + inStockQty;
|
|
|
2385 |
|
| 29801 |
manish |
2386 |
int shortageQty = minQty - totalQty;
|
|
|
2387 |
List<Item> item = itemRepository.selectAllByCatalogItemId(entry.getKey());
|
|
|
2388 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 25721 |
tejbeer |
2389 |
|
| 29801 |
manish |
2390 |
Map<Integer, List<SaholicCIS>> itemAvailabilityMap = warehouseItemAvailabilityMap
|
|
|
2391 |
.get(fofoStore.getWarehouseId());
|
| 27213 |
tejbeer |
2392 |
|
| 29801 |
manish |
2393 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = warehousePoItemAvailabilityMap
|
|
|
2394 |
.get(fofoStore.getWarehouseId());
|
| 25721 |
tejbeer |
2395 |
|
| 29801 |
manish |
2396 |
for (Item it : item) {
|
|
|
2397 |
List<SaholicCIS> currentAvailability = null;
|
|
|
2398 |
List<SaholicPOItem> poItemAvailability = null;
|
|
|
2399 |
if (itemAvailabilityMap != null) {
|
|
|
2400 |
currentAvailability = itemAvailabilityMap.get(it.getId());
|
|
|
2401 |
}
|
| 27208 |
tejbeer |
2402 |
|
| 29801 |
manish |
2403 |
if (poItemAvailabilityMap != null) {
|
|
|
2404 |
poItemAvailability = poItemAvailabilityMap.get(it.getId());
|
|
|
2405 |
}
|
|
|
2406 |
if (currentAvailability != null) {
|
|
|
2407 |
allColorNetAvailability += currentAvailability.stream()
|
|
|
2408 |
.collect(Collectors.summingInt(SaholicCIS::getNetavailability));
|
|
|
2409 |
}
|
| 28528 |
tejbeer |
2410 |
|
| 29801 |
manish |
2411 |
if (poItemAvailability != null) {
|
|
|
2412 |
allColorPoAvailability += poItemAvailability.stream()
|
|
|
2413 |
.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
|
| 27208 |
tejbeer |
2414 |
}
|
|
|
2415 |
|
| 25721 |
tejbeer |
2416 |
}
|
|
|
2417 |
|
| 29801 |
manish |
2418 |
FocusedModelShortageModel fm = new FocusedModelShortageModel();
|
|
|
2419 |
fm.setFofoId(fofoId);
|
|
|
2420 |
fm.setStoreCode(fofoStore.getCode());
|
|
|
2421 |
fm.setStoreName(customRetailer.getBusinessName());
|
|
|
2422 |
fm.setBrandName(item.get(0).getBrand());
|
|
|
2423 |
fm.setModelName(item.get(0).getModelName());
|
|
|
2424 |
fm.setModelNumber(item.get(0).getModelNumber());
|
|
|
2425 |
fm.setGrnStockQty(grnStockQty);
|
|
|
2426 |
fm.setPendingIndentQty(processingQty);
|
|
|
2427 |
fm.setShortageQty(shortageQty);
|
|
|
2428 |
fm.setPoAvailabitiy(allColorPoAvailability);
|
|
|
2429 |
fm.setWarehouseName(warehouseMap.get(customRetailer.getWarehouseId()));
|
|
|
2430 |
fm.setStateManager(partnerIdSalesHeadersMap.get(fofoId).getRegionalManager());
|
|
|
2431 |
fm.setTerritoryManager(partnerIdSalesHeadersMap.get(fofoId).getTerritoryManager());
|
|
|
2432 |
fm.setItemName(item.get(0).getBrand() + item.get(0).getModelNumber() + item.get(0).getModelName());
|
|
|
2433 |
fm.setAvailabitiy(allColorNetAvailability);
|
| 27233 |
tejbeer |
2434 |
|
| 29801 |
manish |
2435 |
focusedModelShortageList.add(fm);
|
|
|
2436 |
}
|
|
|
2437 |
|
| 29668 |
tejbeer |
2438 |
/*
|
|
|
2439 |
* if (!focusedModelShortageList.isEmpty()) { String subject = "Stock Alert";
|
|
|
2440 |
* String messageText = this.getMessage(focusedModelShortageList);
|
| 30393 |
amit.gupta |
2441 |
*
|
| 29668 |
tejbeer |
2442 |
* this.sendMailWithAttachments(subject, messageText,
|
|
|
2443 |
* customRetailer.getEmail()); String notificationMessage =
|
|
|
2444 |
* this.getNotificationMessage(focusedModelShortageList);
|
| 30393 |
amit.gupta |
2445 |
*
|
| 29668 |
tejbeer |
2446 |
* LOGGER.info("notificationMessage" + notificationMessage);
|
| 30393 |
amit.gupta |
2447 |
*
|
| 29668 |
tejbeer |
2448 |
* SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2449 |
* sendNotificationModel.setCampaignName("Stock Alert");
|
|
|
2450 |
* sendNotificationModel.setTitle("Alert");
|
|
|
2451 |
* sendNotificationModel.setMessage(notificationMessage);
|
|
|
2452 |
* sendNotificationModel.setType("url"); sendNotificationModel.setUrl(
|
|
|
2453 |
* "https://app.smartdukaan.com/pages/home/notifications");
|
|
|
2454 |
* sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2455 |
* sendNotificationModel.setMessageType(MessageType.notification); int userId =
|
|
|
2456 |
* userAccountRepository.selectUserIdByRetailerId(fofoId);
|
|
|
2457 |
* sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
2458 |
* notificationService.sendNotification(sendNotificationModel);
|
| 30393 |
amit.gupta |
2459 |
*
|
| 29668 |
tejbeer |
2460 |
* }
|
|
|
2461 |
*/
|
| 27233 |
tejbeer |
2462 |
|
| 25721 |
tejbeer |
2463 |
}
|
| 27102 |
amit.gupta |
2464 |
if (!focusedModelShortageReportMap.isEmpty()) {
|
| 25800 |
tejbeer |
2465 |
String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 30215 |
amit.gupta |
2466 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 25837 |
amit.gupta |
2467 |
Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
|
| 25721 |
tejbeer |
2468 |
|
| 25800 |
tejbeer |
2469 |
focusedModelShortageReportMap.entrySet().forEach(x -> {
|
|
|
2470 |
storeGuyMap.entrySet().forEach(y -> {
|
|
|
2471 |
|
|
|
2472 |
if (y.getValue().contains(x.getKey())) {
|
|
|
2473 |
if (!emailRowsMap.containsKey(y.getKey())) {
|
|
|
2474 |
emailRowsMap.put(y.getKey(), new ArrayList<>());
|
|
|
2475 |
}
|
| 27208 |
tejbeer |
2476 |
List<List<? extends Serializable>> fms = x.getValue().stream()
|
|
|
2477 |
.map(r -> Arrays.asList(r.getStoreCode(), r.getStoreName(), r.getBrandName(),
|
| 27213 |
tejbeer |
2478 |
r.getModelName(), r.getModelNumber(), r.getWarehouseName(), r.getStateManager(),
|
| 28526 |
tejbeer |
2479 |
r.getTerritoryManager(), r.getPendingIndentQty(), r.getGrnStockQty(),
|
|
|
2480 |
r.getShortageQty(), r.getAvailabitiy()))
|
| 25800 |
tejbeer |
2481 |
.collect(Collectors.toList());
|
|
|
2482 |
emailRowsMap.get(y.getKey()).addAll(fms);
|
|
|
2483 |
|
| 25721 |
tejbeer |
2484 |
}
|
|
|
2485 |
|
| 25800 |
tejbeer |
2486 |
});
|
| 25721 |
tejbeer |
2487 |
|
|
|
2488 |
});
|
|
|
2489 |
|
| 27212 |
tejbeer |
2490 |
List<String> headers = Arrays.asList("Store Code", "Store Name", "Brand", "Model Name", "Model Number",
|
| 28526 |
tejbeer |
2491 |
"Warehouse Name", "State Manager", "Territory Manager", "Pending Indent", "InStock", "Shortage Qty",
|
|
|
2492 |
"Availability");
|
| 25837 |
amit.gupta |
2493 |
emailRowsMap.entrySet().forEach(entry -> {
|
| 25721 |
tejbeer |
2494 |
|
| 25800 |
tejbeer |
2495 |
ByteArrayOutputStream baos = null;
|
|
|
2496 |
try {
|
| 25837 |
amit.gupta |
2497 |
baos = FileUtil.getCSVByteStream(headers, entry.getValue());
|
| 25800 |
tejbeer |
2498 |
} catch (Exception e2) {
|
|
|
2499 |
e2.printStackTrace();
|
|
|
2500 |
}
|
| 30393 |
amit.gupta |
2501 |
String[] sendToArray = new String[]{
|
| 28526 |
tejbeer |
2502 |
|
| 29996 |
tejbeer |
2503 |
entry.getKey()
|
| 29995 |
tejbeer |
2504 |
|
|
|
2505 |
};
|
|
|
2506 |
|
| 25800 |
tejbeer |
2507 |
try {
|
|
|
2508 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
|
|
|
2509 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
2510 |
} catch (Exception e1) { // TODO Auto-generated catch block
|
|
|
2511 |
e1.printStackTrace();
|
|
|
2512 |
}
|
| 25721 |
tejbeer |
2513 |
|
| 25800 |
tejbeer |
2514 |
});
|
|
|
2515 |
}
|
| 25721 |
tejbeer |
2516 |
}
|
|
|
2517 |
|
|
|
2518 |
private String getNotificationMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
2519 |
StringBuilder sb = new StringBuilder();
|
|
|
2520 |
sb.append("Focused Model Shortage in Your Stock : \n");
|
|
|
2521 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
2522 |
|
|
|
2523 |
sb.append(entry.getItemName() + "-" + entry.getShortageQty());
|
|
|
2524 |
sb.append(String.format("%n", ""));
|
|
|
2525 |
}
|
|
|
2526 |
return sb.toString();
|
|
|
2527 |
}
|
|
|
2528 |
|
|
|
2529 |
private void sendMailWithAttachments(String subject, String messageText, String email) throws Exception {
|
|
|
2530 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
2531 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
2532 |
|
|
|
2533 |
helper.setSubject(subject);
|
|
|
2534 |
helper.setText(messageText, true);
|
|
|
2535 |
helper.setTo(email);
|
| 27116 |
amit.gupta |
2536 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
| 25721 |
tejbeer |
2537 |
helper.setFrom(senderAddress);
|
|
|
2538 |
mailSender.send(message);
|
|
|
2539 |
|
|
|
2540 |
}
|
|
|
2541 |
|
|
|
2542 |
private String getMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
2543 |
StringBuilder sb = new StringBuilder();
|
|
|
2544 |
sb.append("<html><body><p>Alert</p><p>Focused Model Shortage in Your Stock:-</p>"
|
|
|
2545 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
2546 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
2547 |
+ " <th style='border:1px solid black;padding: 5px'>Item</th>\n"
|
|
|
2548 |
+ " <th style='border:1px solid black;padding: 5px'>Shortage Qty</th>\n"
|
|
|
2549 |
+ " </tr>");
|
|
|
2550 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
2551 |
|
|
|
2552 |
sb.append("<tr>");
|
|
|
2553 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getItemName() + "</td>");
|
|
|
2554 |
|
|
|
2555 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getShortageQty() + "</td>");
|
|
|
2556 |
|
|
|
2557 |
sb.append("</tr>");
|
|
|
2558 |
|
|
|
2559 |
}
|
|
|
2560 |
|
|
|
2561 |
sb.append("</tbody></table></body></html>");
|
|
|
2562 |
|
|
|
2563 |
return sb.toString();
|
|
|
2564 |
}
|
|
|
2565 |
|
| 25927 |
amit.gupta |
2566 |
public void notifyLead() throws Exception {
|
| 29488 |
manish |
2567 |
List<Lead> leadsToNotify = leadRepository.selectLeadsScheduledBetweenDate(null,
|
|
|
2568 |
LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
| 25927 |
amit.gupta |
2569 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
2570 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
| 27477 |
amit.gupta |
2571 |
LOGGER.info("authUserEmailMap {}", authUserEmailMap);
|
| 25927 |
amit.gupta |
2572 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
2573 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
2574 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
| 25936 |
amit.gupta |
2575 |
|
| 27477 |
amit.gupta |
2576 |
LOGGER.info("dtrEmailMap {}", dtrEmailMap);
|
| 26790 |
tejbeer |
2577 |
|
| 25927 |
amit.gupta |
2578 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
|
|
2579 |
|
|
|
2580 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
2581 |
int authId = authUserEmail.getKey();
|
|
|
2582 |
String email = authUserEmail.getValue();
|
|
|
2583 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
2584 |
}
|
| 27477 |
amit.gupta |
2585 |
LOGGER.info("authUserKeyMap", authUserKeyMap);
|
|
|
2586 |
LOGGER.info("leadsToNotify {}", leadsToNotify);
|
| 26790 |
tejbeer |
2587 |
|
| 29308 |
tejbeer |
2588 |
String templateMessage = "Lead followup for %s %s, %s, %s is due by %s";
|
| 25927 |
amit.gupta |
2589 |
for (Lead lead : leadsToNotify) {
|
| 27217 |
amit.gupta |
2590 |
if (authUserKeyMap.get(lead.getAssignTo()) == null) {
|
|
|
2591 |
LOGGER.info("Assignee no longer part of system {}", lead.getAssignTo());
|
| 25927 |
amit.gupta |
2592 |
continue;
|
|
|
2593 |
}
|
|
|
2594 |
String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
|
| 29308 |
tejbeer |
2595 |
lead.getAddress(), lead.getLeadMobile(), leadTimeFormatter.format(lead.getScheduledTimestamp()));
|
| 25927 |
amit.gupta |
2596 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2597 |
sendNotificationModel.setCampaignName("Lead Reminder");
|
|
|
2598 |
sendNotificationModel.setTitle("Leads followup Reminder");
|
|
|
2599 |
sendNotificationModel.setMessage(notificationMessage);
|
|
|
2600 |
sendNotificationModel.setType("url");
|
| 29317 |
tejbeer |
2601 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/leadUpdate?leadId=" + lead.getId());
|
| 25927 |
amit.gupta |
2602 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2603 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
| 26320 |
tejbeer |
2604 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
|
| 25929 |
amit.gupta |
2605 |
System.out.println(sendNotificationModel);
|
| 25927 |
amit.gupta |
2606 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2607 |
}
|
|
|
2608 |
}
|
| 26945 |
amit.gupta |
2609 |
|
| 25927 |
amit.gupta |
2610 |
public void notifyVisits() throws Exception {
|
| 26945 |
amit.gupta |
2611 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository
|
|
|
2612 |
.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
| 25927 |
amit.gupta |
2613 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
2614 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
|
|
2615 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
2616 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
2617 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
|
|
2618 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
| 26945 |
amit.gupta |
2619 |
|
| 25927 |
amit.gupta |
2620 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
2621 |
int authId = authUserEmail.getKey();
|
|
|
2622 |
String email = authUserEmail.getValue();
|
|
|
2623 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
2624 |
}
|
|
|
2625 |
String visitTemplate = "Planned visit to franchisee %s is due by %s";
|
|
|
2626 |
String followupTemplate = "Lead followup for franchisee %s is due by %s";
|
|
|
2627 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("MMM 7, EEEE h:m a");
|
|
|
2628 |
for (FranchiseeVisit visit : franchiseeVisits) {
|
|
|
2629 |
if (authUserKeyMap.containsKey(visit.getAuthId())) {
|
|
|
2630 |
continue;
|
|
|
2631 |
}
|
|
|
2632 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2633 |
String message = null;
|
| 26945 |
amit.gupta |
2634 |
if (visit.getFranchiseActivityId() == 0) {
|
|
|
2635 |
message = String.format(visitTemplate, visit.getPartnerName(),
|
|
|
2636 |
timeFormatter.format(visit.getSchelduleTimestamp()));
|
|
|
2637 |
sendNotificationModel.setCampaignName("Franchisee visit Reminder");
|
| 25927 |
amit.gupta |
2638 |
} else {
|
| 26945 |
amit.gupta |
2639 |
message = String.format(followupTemplate, visit.getPartnerName(),
|
|
|
2640 |
timeFormatter.format(visit.getSchelduleTimestamp()));
|
| 25927 |
amit.gupta |
2641 |
sendNotificationModel.setCampaignName("Franchisee followup Reminder");
|
|
|
2642 |
}
|
|
|
2643 |
sendNotificationModel.setMessage(message);
|
|
|
2644 |
sendNotificationModel.setType("url");
|
| 26482 |
tejbeer |
2645 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 25927 |
amit.gupta |
2646 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2647 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
|
|
2648 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(visit.getAuthId())));
|
|
|
2649 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2650 |
}
|
| 25910 |
amit.gupta |
2651 |
}
|
| 25982 |
amit.gupta |
2652 |
|
| 26283 |
tejbeer |
2653 |
public void ticketClosed() throws Exception {
|
|
|
2654 |
|
|
|
2655 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTicketsWithStatus(ActivityType.RESOLVED);
|
|
|
2656 |
for (Ticket ticket : tickets) {
|
|
|
2657 |
if (ticket.getUpdateTimestamp().toLocalDate().isBefore(LocalDate.now().minusDays(7))) {
|
|
|
2658 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
2659 |
ticket.setLastActivity(ActivityType.RESOLVED_ACCEPTED);
|
|
|
2660 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
2661 |
ticketRepository.persist(ticket);
|
|
|
2662 |
}
|
|
|
2663 |
}
|
|
|
2664 |
|
|
|
2665 |
}
|
|
|
2666 |
|
| 26790 |
tejbeer |
2667 |
public void checkValidateReferral() throws Exception {
|
|
|
2668 |
|
|
|
2669 |
List<Refferal> referrals = refferalRepository.selectByStatus(RefferalStatus.pending);
|
| 26791 |
tejbeer |
2670 |
LOGGER.info("referrals" + referrals);
|
| 26790 |
tejbeer |
2671 |
if (!referrals.isEmpty()) {
|
|
|
2672 |
String subject = "Referral Request";
|
|
|
2673 |
String messageText = this.getMessageForReferral(referrals);
|
|
|
2674 |
|
| 26792 |
tejbeer |
2675 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
2676 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 30393 |
amit.gupta |
2677 |
String[] email = {"kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com"};
|
| 26792 |
tejbeer |
2678 |
helper.setSubject(subject);
|
|
|
2679 |
helper.setText(messageText, true);
|
|
|
2680 |
helper.setTo(email);
|
|
|
2681 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
|
|
2682 |
helper.setFrom(senderAddress);
|
|
|
2683 |
mailSender.send(message);
|
|
|
2684 |
|
| 26790 |
tejbeer |
2685 |
}
|
|
|
2686 |
}
|
|
|
2687 |
|
|
|
2688 |
private String getMessageForReferral(List<Refferal> referrals) {
|
|
|
2689 |
StringBuilder sb = new StringBuilder();
|
|
|
2690 |
sb.append("<html><body><p>Alert</p><p>Pending Referrals:-</p>"
|
|
|
2691 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
2692 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
2693 |
+ " <th style='border:1px solid black;padding: 5px'>RefereeName</th>\n"
|
|
|
2694 |
+ " <th style='border:1px solid black;padding: 5px'>Referee Email</th>\n"
|
|
|
2695 |
+ " <th style='border:1px solid black;padding: 5px'>Referral Name</th>\n"
|
|
|
2696 |
+ " <th style='border:1px solid black;padding: 5px'>Refferal Mobile</th>\n"
|
|
|
2697 |
+ " <th style='border:1px solid black;padding: 5px'>city</th>\n"
|
|
|
2698 |
+ " <th style='border:1px solid black;padding: 5px'>state</th>\n"
|
|
|
2699 |
+ " </tr>");
|
|
|
2700 |
for (Refferal entry : referrals) {
|
|
|
2701 |
|
|
|
2702 |
sb.append("<tr>");
|
|
|
2703 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeName() + "</td>");
|
|
|
2704 |
|
|
|
2705 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeEmail() + "</td>");
|
|
|
2706 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getFirstName() + "</td>");
|
|
|
2707 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getMobile() + "</td>");
|
|
|
2708 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCity() + "</td>");
|
|
|
2709 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getState() + "</td>");
|
|
|
2710 |
|
|
|
2711 |
sb.append("</tr>");
|
|
|
2712 |
|
|
|
2713 |
}
|
|
|
2714 |
|
|
|
2715 |
sb.append("</tbody></table></body></html>");
|
|
|
2716 |
|
|
|
2717 |
return sb.toString();
|
|
|
2718 |
}
|
|
|
2719 |
|
| 30421 |
tejbeer |
2720 |
private String getMessageForUncontacblePartner(List<PartnerCollectionRemark> pcrs)
|
|
|
2721 |
throws ProfitMandiBusinessException {
|
|
|
2722 |
StringBuilder sb = new StringBuilder();
|
|
|
2723 |
sb.append("<html><body><p>Alert</p><p>Not Responding Partner:-</p>"
|
|
|
2724 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
2725 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
2726 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
|
|
2727 |
+ " <th style='border:1px solid black;padding: 5px'>from</th>\n"
|
|
|
2728 |
|
|
|
2729 |
+ " </tr>");
|
|
|
2730 |
for (PartnerCollectionRemark entry : pcrs) {
|
|
|
2731 |
|
|
|
2732 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
|
|
2733 |
|
|
|
2734 |
sb.append("<tr>");
|
|
|
2735 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
|
|
2736 |
+ customRetailer.getCode() + ")" + "</td>");
|
|
|
2737 |
|
|
|
2738 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2739 |
+ entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
|
|
2740 |
|
|
|
2741 |
sb.append("</tr>");
|
|
|
2742 |
|
|
|
2743 |
}
|
|
|
2744 |
|
|
|
2745 |
sb.append("</tbody></table></body></html>");
|
|
|
2746 |
|
|
|
2747 |
return sb.toString();
|
|
|
2748 |
}
|
|
|
2749 |
|
| 27271 |
amit.gupta |
2750 |
public void reverseWallet() throws Exception {
|
|
|
2751 |
LocalDate localDate = LocalDate.of(2020, 10, 28);
|
| 28205 |
tejbeer |
2752 |
List<UserWalletHistory> uwhList = userWalletHistoryRepository.selectAllByDateType(localDate.atStartOfDay(),
|
|
|
2753 |
localDate.plusDays(1).atStartOfDay(),
|
| 27271 |
amit.gupta |
2754 |
Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
|
|
2755 |
for (UserWalletHistory uwh : uwhList) {
|
| 28205 |
tejbeer |
2756 |
if (uwh.getBusinessTimestamp().getMonth().equals(Month.SEPTEMBER)) {
|
| 27275 |
amit.gupta |
2757 |
UserWallet uw = userWalletRepository.selectById(uwh.getWalletId());
|
| 28205 |
tejbeer |
2758 |
// LOGGER.info("UWH - {}", uwh);
|
|
|
2759 |
// amount += uwh.getAmount();
|
|
|
2760 |
// System.out.println("Amount is - " + amount);
|
|
|
2761 |
// walletService.rollbackAmountFromWallet(uw.getUserId(), uwh.getAmount(),
|
|
|
2762 |
// uwh.getReference(), uwh.getReferenceType(), "Margin reversal for error prone
|
|
|
2763 |
// run", uwh.getBusinessTimestamp());
|
| 27313 |
amit.gupta |
2764 |
int orderId = uwh.getReference();
|
|
|
2765 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
|
|
2766 |
int inventoryItemId = 0;
|
| 28205 |
tejbeer |
2767 |
// fofoOrderRepository.delete(fofoOrder);
|
| 27313 |
amit.gupta |
2768 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 28205 |
tejbeer |
2769 |
/*
|
|
|
2770 |
* List<PaymentOptionTransaction> paymentOptionTransactions =
|
|
|
2771 |
* paymentOptionTransactionRepository.selectByReferenceIdAndType(fofoOrder.getId
|
|
|
2772 |
* (), PaymentOptionReferenceType.ORDER); for(PaymentOptionTransaction
|
|
|
2773 |
* paymentOptionTransaction : paymentOptionTransactions) {
|
|
|
2774 |
* //paymentOptionTransactionRepository.delete(paymentOptionTransaction); }
|
|
|
2775 |
*/
|
|
|
2776 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
2777 |
// fofoOrderItemRepository.delete(foi);
|
| 27313 |
amit.gupta |
2778 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(foi.getId());
|
| 28205 |
tejbeer |
2779 |
for (FofoLineItem fli : flis) {
|
|
|
2780 |
// fofoLineItemRepository.delete(fli);
|
| 27313 |
amit.gupta |
2781 |
inventoryItemId = fli.getInventoryItemId();
|
|
|
2782 |
}
|
|
|
2783 |
}
|
| 28205 |
tejbeer |
2784 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(
|
|
|
2785 |
java.util.stream.Stream.of(inventoryItemId).collect(Collectors.toSet()));
|
|
|
2786 |
for (SchemeInOut sio : schemeInOuts) {
|
|
|
2787 |
if (sio.getCreateTimestamp().toLocalDate().equals(localDate)) {
|
| 27314 |
amit.gupta |
2788 |
LOGGER.info("SIO - {}", sio);
|
| 27315 |
amit.gupta |
2789 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 27313 |
amit.gupta |
2790 |
}
|
|
|
2791 |
}
|
| 28205 |
tejbeer |
2792 |
|
| 27271 |
amit.gupta |
2793 |
}
|
|
|
2794 |
}
|
| 28205 |
tejbeer |
2795 |
|
| 27271 |
amit.gupta |
2796 |
}
|
| 28205 |
tejbeer |
2797 |
|
|
|
2798 |
public void partnerProblemAlert() throws Exception {
|
|
|
2799 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
2800 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
|
|
2801 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
|
|
2802 |
Map<Integer, Double> mtdSales = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1),
|
|
|
2803 |
curDate.with(LocalTime.MAX), 0, false);
|
|
|
2804 |
Map<Integer, PartnerDailyInvestment> pdi = partnerDailyInvestmentRepository.selectAll(LocalDate.now()).stream()
|
|
|
2805 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
2806 |
|
|
|
2807 |
for (Entry<Integer, Double> ls : lmtdSale.entrySet()) {
|
|
|
2808 |
|
|
|
2809 |
double lmtdTwentyPercentSale = ls.getValue() * 0.2;
|
| 28208 |
tejbeer |
2810 |
|
|
|
2811 |
LOGGER.info("lmtdTwentyPercentSale" + lmtdTwentyPercentSale);
|
|
|
2812 |
|
| 28211 |
tejbeer |
2813 |
double mtdSale = mtdSales.get(ls.getKey()) == null ? 0 : mtdSales.get(ls.getKey());
|
| 28208 |
tejbeer |
2814 |
|
|
|
2815 |
LOGGER.info("mtdSale" + mtdSale);
|
|
|
2816 |
|
| 28209 |
tejbeer |
2817 |
double totalSixtyPercentInvestment = pdi.get(ls.getKey()) == null ? 0
|
|
|
2818 |
: pdi.get(ls.getKey()).getTotalInvestment() * 0.6;
|
| 28205 |
tejbeer |
2819 |
|
| 28208 |
tejbeer |
2820 |
LOGGER.info("totalSixtyPercentInvestment" + totalSixtyPercentInvestment);
|
|
|
2821 |
|
| 28209 |
tejbeer |
2822 |
double stockInvestment = pdi.get(ls.getKey()) == null ? 0 : pdi.get(ls.getKey()).getInStockAmount();
|
| 28208 |
tejbeer |
2823 |
|
|
|
2824 |
LOGGER.info("stockInvestment" + stockInvestment);
|
|
|
2825 |
|
| 28205 |
tejbeer |
2826 |
boolean Investmentvalue = partnerInvestmentService.isInvestmentBelow(ls.getKey(), 25);
|
|
|
2827 |
|
|
|
2828 |
PartnerProblem partnerProblem = partnerProblemRepository.selectByFofoId(ls.getKey());
|
|
|
2829 |
|
| 28210 |
tejbeer |
2830 |
if (partnerProblem == null) {
|
| 28205 |
tejbeer |
2831 |
partnerProblem = new PartnerProblem();
|
|
|
2832 |
partnerProblem.setFofoId(ls.getKey());
|
|
|
2833 |
if (mtdSale < lmtdTwentyPercentSale) {
|
|
|
2834 |
partnerProblem.setMtd(1);
|
|
|
2835 |
}
|
|
|
2836 |
if (Investmentvalue) {
|
|
|
2837 |
partnerProblem.setInvestment(1);
|
|
|
2838 |
}
|
|
|
2839 |
|
|
|
2840 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
|
|
2841 |
partnerProblem.setInvestment(1);
|
|
|
2842 |
}
|
|
|
2843 |
|
|
|
2844 |
partnerProblemRepository.persist(partnerProblem);
|
|
|
2845 |
} else {
|
|
|
2846 |
if (mtdSale < lmtdTwentyPercentSale) {
|
|
|
2847 |
partnerProblem.setMtd(partnerProblem.getMtd() + 1);
|
|
|
2848 |
|
|
|
2849 |
} else {
|
|
|
2850 |
partnerProblem.setMtd(0);
|
|
|
2851 |
|
|
|
2852 |
}
|
|
|
2853 |
if (Investmentvalue) {
|
|
|
2854 |
partnerProblem.setInvestment(partnerProblem.getInvestment() + 1);
|
|
|
2855 |
} else {
|
|
|
2856 |
partnerProblem.setInvestment(0);
|
|
|
2857 |
|
|
|
2858 |
}
|
|
|
2859 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
|
|
2860 |
partnerProblem.setStockInvestment(partnerProblem.getStockInvestment() + 1);
|
|
|
2861 |
} else {
|
|
|
2862 |
partnerProblem.setStockInvestment(0);
|
|
|
2863 |
}
|
|
|
2864 |
|
|
|
2865 |
}
|
|
|
2866 |
|
|
|
2867 |
}
|
|
|
2868 |
|
| 28213 |
tejbeer |
2869 |
List<PartnerProblem> partnerProblems = partnerProblemRepository.selectAll().stream()
|
|
|
2870 |
.filter(x -> x.getMtd() + x.getInvestment() + x.getStockInvestment() > 0).collect(Collectors.toList());
|
|
|
2871 |
|
| 28223 |
tejbeer |
2872 |
partnerProblems = partnerProblems.stream().sorted((x1, x2) -> {
|
| 28224 |
tejbeer |
2873 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
| 28223 |
tejbeer |
2874 |
+ x2.getStockInvestment() ? 1 : -1;
|
|
|
2875 |
}).collect(Collectors.toList());
|
| 28227 |
tejbeer |
2876 |
|
|
|
2877 |
Map<Integer, PartnerProblem> partnerProblemMap = partnerProblems.stream().sorted((x1, x2) -> {
|
|
|
2878 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
|
|
2879 |
+ x2.getStockInvestment() ? 1 : -1;
|
|
|
2880 |
}).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
2881 |
|
| 28212 |
tejbeer |
2882 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailers();
|
| 28213 |
tejbeer |
2883 |
|
| 28467 |
tejbeer |
2884 |
List<Integer> assignTo = Arrays.asList(15, 9, 54, 53);
|
| 28213 |
tejbeer |
2885 |
|
|
|
2886 |
Map<Integer, AuthUser> assignAuthUserMap = authRepository.selectAllAuthUserByIds(assignTo).stream()
|
|
|
2887 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
2888 |
|
| 28286 |
tejbeer |
2889 |
List<String> sendTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 28467 |
tejbeer |
2890 |
"niranjan.kala@smartdukaan.com", "sm@smartdukaan.com", "tejbeer.kaur@shop2020.in");
|
| 28208 |
tejbeer |
2891 |
LOGGER.info("partnerProblem" + partnerProblems);
|
| 28205 |
tejbeer |
2892 |
StringBuilder sb = new StringBuilder();
|
| 28218 |
tejbeer |
2893 |
sb.append("<htl><body>");
|
| 28222 |
tejbeer |
2894 |
sb.append(
|
|
|
2895 |
"<p>Number against MTD or Investment are the count of days the MTD is low VS LMTD OR Investment is below 75%.</p><br/><p>These partners needs immediate attention.</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 28205 |
tejbeer |
2896 |
sb.append("<tbody>\n" + " <tr>"
|
|
|
2897 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
|
|
2898 |
+ " <th style='border:1px solid black;padding: 5px'>Assign TO</th>"
|
|
|
2899 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
|
|
2900 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
|
|
2901 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
|
|
2902 |
+ " <th style='border:1px solid black;padding: 5px'>Manager</th>"
|
|
|
2903 |
|
|
|
2904 |
+ " </tr>");
|
|
|
2905 |
|
|
|
2906 |
for (PartnerProblem pp : partnerProblems) {
|
| 28467 |
tejbeer |
2907 |
int value = pp.getFofoId() % 4;
|
| 28205 |
tejbeer |
2908 |
|
|
|
2909 |
Map<EscalationType, AuthUser> authUserMap = csService.getAuthUserAndEsclationByPartnerId(pp.getFofoId());
|
| 28217 |
tejbeer |
2910 |
LOGGER.info("authUserMap" + authUserMap);
|
| 28205 |
tejbeer |
2911 |
sb.append("<tr>");
|
|
|
2912 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2913 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
| 28213 |
tejbeer |
2914 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2915 |
+ assignAuthUserMap.get(assignTo.get(value)).getName() + "</td>");
|
| 28205 |
tejbeer |
2916 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
|
|
2917 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
|
|
2918 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getStockInvestment() + "</td>");
|
| 28216 |
tejbeer |
2919 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 28224 |
tejbeer |
2920 |
+ (authUserMap.get(EscalationType.L1) == null ? "N/A"
|
| 30393 |
amit.gupta |
2921 |
: authUserMap.get(EscalationType.L1).getFirstName())
|
| 28224 |
tejbeer |
2922 |
+ " ," + (authUserMap.get(EscalationType.L2) == null ? "N/A"
|
| 30393 |
amit.gupta |
2923 |
: authUserMap.get(EscalationType.L2).getFirstName())
|
| 28216 |
tejbeer |
2924 |
+ "</td>");
|
| 28205 |
tejbeer |
2925 |
|
|
|
2926 |
sb.append("</tr>");
|
|
|
2927 |
}
|
|
|
2928 |
sb.append("</tbody></table><br><br>");
|
|
|
2929 |
String subject = "Partner Problem Alert!";
|
|
|
2930 |
String[] email = sendTo.toArray(new String[sendTo.size()]);
|
|
|
2931 |
|
| 28222 |
tejbeer |
2932 |
this.sendMailHtmlFormat(email, sb.toString(), null, subject);
|
|
|
2933 |
|
| 28218 |
tejbeer |
2934 |
Map<Integer, List<Integer>> authUserPartnerMapping = csService.getAuthUserIdPartnerIdMapping();
|
|
|
2935 |
|
|
|
2936 |
for (Entry<Integer, List<Integer>> authUserPartner : authUserPartnerMapping.entrySet()) {
|
| 28222 |
tejbeer |
2937 |
AuthUser authUser = authRepository.selectById(authUserPartner.getKey());
|
| 28227 |
tejbeer |
2938 |
for (Integer patnerId : authUserPartner.getValue()) {
|
|
|
2939 |
if (partnerProblemMap.get(patnerId) != null) {
|
| 28218 |
tejbeer |
2940 |
|
| 28227 |
tejbeer |
2941 |
StringBuilder sbbuilder = new StringBuilder();
|
|
|
2942 |
sbbuilder.append("<hml><body>");
|
|
|
2943 |
sb.append(
|
|
|
2944 |
"<p>Number against MTD or Investment are the count of days the MTD is low VS LMTD OR Investment is below 75%.</p><br/><p>These partners needs immediate attention.</p><br/><table style='border:1px solid black';cellspacing=0>");
|
|
|
2945 |
sbbuilder.append("<tbody>\n" + " <tr>"
|
|
|
2946 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
|
|
2947 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
|
|
2948 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
|
|
2949 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
| 28218 |
tejbeer |
2950 |
|
| 28227 |
tejbeer |
2951 |
+ " </tr>");
|
| 28218 |
tejbeer |
2952 |
|
| 28227 |
tejbeer |
2953 |
for (Integer partnerId : authUserPartner.getValue()) {
|
|
|
2954 |
if (partnerProblemMap.get(partnerId) != null) {
|
|
|
2955 |
PartnerProblem pp = partnerProblemMap.get(partnerId);
|
|
|
2956 |
sbbuilder.append("<tr>");
|
|
|
2957 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2958 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
|
|
2959 |
sbbuilder
|
|
|
2960 |
.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
|
|
2961 |
sbbuilder.append(
|
|
|
2962 |
"<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
|
|
2963 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2964 |
+ pp.getStockInvestment() + "</td>");
|
|
|
2965 |
|
|
|
2966 |
sbbuilder.append("</tr>");
|
|
|
2967 |
}
|
|
|
2968 |
|
| 28224 |
tejbeer |
2969 |
}
|
| 28227 |
tejbeer |
2970 |
sbbuilder.append("</tbody></table><br><br>");
|
| 28224 |
tejbeer |
2971 |
|
| 28286 |
tejbeer |
2972 |
this.sendMailOfHtmlFormat(authUser.getEmailId(), sbbuilder.toString(), null, subject);
|
| 28230 |
tejbeer |
2973 |
break;
|
| 28218 |
tejbeer |
2974 |
}
|
| 28230 |
tejbeer |
2975 |
|
| 28223 |
tejbeer |
2976 |
}
|
| 28222 |
tejbeer |
2977 |
}
|
|
|
2978 |
}
|
| 28218 |
tejbeer |
2979 |
|
| 28222 |
tejbeer |
2980 |
private void sendMailHtmlFormat(String email[], String body, String cc[], String subject)
|
|
|
2981 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
2982 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
2983 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
2984 |
helper.setSubject(subject);
|
|
|
2985 |
helper.setText(body, true);
|
|
|
2986 |
helper.setTo(email);
|
|
|
2987 |
if (cc != null) {
|
|
|
2988 |
helper.setCc(cc);
|
| 28218 |
tejbeer |
2989 |
}
|
| 28222 |
tejbeer |
2990 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
2991 |
helper.setFrom(senderAddress);
|
|
|
2992 |
mailSender.send(message);
|
| 28205 |
tejbeer |
2993 |
}
|
|
|
2994 |
|
| 28775 |
amit.gupta |
2995 |
@Autowired
|
|
|
2996 |
WarehouseRepository warehouseRepository;
|
| 28790 |
amit.gupta |
2997 |
|
| 28775 |
amit.gupta |
2998 |
public void getVendorWarehouses(int warehouseId) {
|
| 28778 |
amit.gupta |
2999 |
LOGGER.info("Warehouses - {}", warehouseRepository.getVendorWarehouses().get(warehouseId));
|
| 28790 |
amit.gupta |
3000 |
|
| 28775 |
amit.gupta |
3001 |
}
|
| 29488 |
manish |
3002 |
|
| 29451 |
manish |
3003 |
public void checkImeiActivation() {
|
| 29488 |
manish |
3004 |
|
| 29451 |
manish |
3005 |
try {
|
|
|
3006 |
vivoImeiActivationService.checkImeiActivation();
|
|
|
3007 |
} catch (ProfitMandiBusinessException e) {
|
|
|
3008 |
// TODO Auto-generated catch block
|
|
|
3009 |
e.printStackTrace();
|
|
|
3010 |
} catch (IOException e) {
|
|
|
3011 |
// TODO Auto-generated catch block
|
|
|
3012 |
e.printStackTrace();
|
|
|
3013 |
} catch (Exception e) {
|
|
|
3014 |
// TODO Auto-generated catch block
|
|
|
3015 |
e.printStackTrace();
|
|
|
3016 |
}
|
| 28775 |
amit.gupta |
3017 |
|
| 29451 |
manish |
3018 |
}
|
|
|
3019 |
|
| 29668 |
tejbeer |
3020 |
public void checkItelImeiActivation(LocalDate date, Integer day) {
|
| 29488 |
manish |
3021 |
LOGGER.info("Hello - {}", "hhh");
|
|
|
3022 |
|
|
|
3023 |
try {
|
| 29668 |
tejbeer |
3024 |
itelImeiActivationService.checkItelImeiActivation(date, day);
|
| 29488 |
manish |
3025 |
} catch (ProfitMandiBusinessException e) {
|
|
|
3026 |
// TODO Auto-generated catch block
|
|
|
3027 |
e.printStackTrace();
|
|
|
3028 |
} catch (IOException e) {
|
|
|
3029 |
// TODO Auto-generated catch block
|
|
|
3030 |
e.printStackTrace();
|
|
|
3031 |
} catch (Exception e) {
|
|
|
3032 |
// TODO Auto-generated catch block
|
|
|
3033 |
e.printStackTrace();
|
|
|
3034 |
}
|
|
|
3035 |
|
|
|
3036 |
}
|
|
|
3037 |
|
| 29807 |
manish |
3038 |
public void selectFinServiceFollowUpDateByCurrDate(LocalDate currentDate)
|
|
|
3039 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 29801 |
manish |
3040 |
LOGGER.info("selectfinServiceFollow - {}", "selectfinServiceFollowUpDateByCurrDate");
|
|
|
3041 |
|
| 29807 |
manish |
3042 |
serviceConfigService.selectFinServicePartnerfollowUpDateByCurrentDate(currentDate);
|
|
|
3043 |
|
| 29801 |
manish |
3044 |
}
|
|
|
3045 |
|
| 29668 |
tejbeer |
3046 |
public void checkTecnoImeiActivation(LocalDate date, Integer day) {
|
| 29488 |
manish |
3047 |
LOGGER.info("Hello - {}", "hhh");
|
|
|
3048 |
|
|
|
3049 |
try {
|
| 29668 |
tejbeer |
3050 |
tecnoImeiActivation.checkTecnoImeiActivation(date, day);
|
| 29488 |
manish |
3051 |
} catch (ProfitMandiBusinessException e) {
|
|
|
3052 |
// TODO Auto-generated catch block
|
|
|
3053 |
e.printStackTrace();
|
|
|
3054 |
} catch (IOException e) {
|
|
|
3055 |
// TODO Auto-generated catch block
|
|
|
3056 |
e.printStackTrace();
|
|
|
3057 |
} catch (Exception e) {
|
|
|
3058 |
// TODO Auto-generated catch block
|
|
|
3059 |
e.printStackTrace();
|
|
|
3060 |
}
|
|
|
3061 |
|
|
|
3062 |
}
|
|
|
3063 |
|
| 29252 |
amit.gupta |
3064 |
public void checkCancellationMargin() throws Exception {
|
|
|
3065 |
LocalDateTime startDate = LocalDate.of(2021, 4, 1).atStartOfDay();
|
|
|
3066 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectCancelledBetweenSaleDate(startDate, LocalDateTime.now());
|
|
|
3067 |
LOGGER.info("Total Orders = {}", fofoOrders.size());
|
| 29308 |
tejbeer |
3068 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
3069 |
List<UserWalletHistory> history = userWalletHistoryRepository
|
|
|
3070 |
.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
|
|
|
3071 |
history.addAll(userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrder.getId(),
|
|
|
3072 |
WalletReferenceType.ACTIVATION_SCHEME));
|
|
|
3073 |
int walletSum = history.stream().mapToInt(x -> x.getAmount()).sum();
|
|
|
3074 |
if (Math.abs(walletSum) > 1) {
|
|
|
3075 |
// LOGGER.info("Cancelled invoice {}, Order Id = {}, = havent rolledback, Value
|
|
|
3076 |
// = {}", fofoOrder.getInvoiceNumber(), fofoOrder.getId(), walletSum);
|
| 29252 |
amit.gupta |
3077 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
3078 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(fofoOrderItems.get(0).getId());
|
|
|
3079 |
FofoLineItem fli = flis.get(0);
|
| 29308 |
tejbeer |
3080 |
if (StringUtils.isEmpty(fli.getSerialNumber()))
|
|
|
3081 |
continue;
|
|
|
3082 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository
|
|
|
3083 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(fli.getInventoryItemId())));
|
| 29252 |
amit.gupta |
3084 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(fli.getInventoryItemId());
|
| 29308 |
tejbeer |
3085 |
double schemeSum = schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null)
|
|
|
3086 |
.mapToDouble(x -> x.getAmount()).sum();
|
|
|
3087 |
/*
|
|
|
3088 |
* if(inventoryItem.getGoodQuantity()==1) {
|
|
|
3089 |
* LOGGER.info("GoodQty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
|
|
3090 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
|
|
3091 |
* inventoryItem.getUpdateTimestamp()); } else
|
|
|
3092 |
* if(inventoryItem.getBadQuantity()==1){
|
|
|
3093 |
* LOGGER.info("Bad Qty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
|
|
3094 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
|
|
3095 |
* inventoryItem.getUpdateTimestamp()); } else if
|
|
|
3096 |
* (inventoryItem.getLastScanType().equals(ScanType.SALE)) { LOGGER.
|
|
|
3097 |
* info("Problem Sold, Serial Number {}, InventoryItem = {}, Billed on {}",
|
|
|
3098 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
|
|
3099 |
* inventoryItem.getUpdateTimestamp()); }
|
|
|
3100 |
*/
|
|
|
3101 |
if (inventoryItem.getLastScanType().equals(ScanType.SALE)
|
|
|
3102 |
|| inventoryItem.getLastScanType().equals(ScanType.SALE_RET)) {
|
|
|
3103 |
Map<String, Double> map = schemeInOuts.stream()
|
|
|
3104 |
.collect(
|
|
|
3105 |
Collectors.groupingBy(
|
|
|
3106 |
x -> DateTimeFormatter.ofPattern("yyyyMMddHH")
|
|
|
3107 |
.format(x.getCreateTimestamp()) + "- " + x.getSchemeId(),
|
|
|
3108 |
Collectors.summingDouble(x -> x.getAmount())));
|
|
|
3109 |
for (Map.Entry<String, Double> entry : map.entrySet()) {
|
|
|
3110 |
LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
|
| 29252 |
amit.gupta |
3111 |
}
|
| 29308 |
tejbeer |
3112 |
LOGGER.info("id- {}, imei- {}, lastScan = {}, Scheme sum - {}", inventoryItem.getId(),
|
|
|
3113 |
inventoryItem.getSerialNumber(), inventoryItem.getLastScanType(), schemeSum);
|
| 29252 |
amit.gupta |
3114 |
}
|
|
|
3115 |
}
|
|
|
3116 |
}
|
| 29308 |
tejbeer |
3117 |
|
| 29252 |
amit.gupta |
3118 |
}
|
|
|
3119 |
|
| 29488 |
manish |
3120 |
public static String readFileAsString(String file) throws Exception {
|
|
|
3121 |
String data = "";
|
|
|
3122 |
data = new String(Files.readAllBytes(Paths.get(file)));
|
|
|
3123 |
return data;
|
|
|
3124 |
}
|
| 29451 |
manish |
3125 |
|
| 29308 |
tejbeer |
3126 |
public void markDelhiveryOrderDelivered() throws ProfitMandiBusinessException, IOException {
|
|
|
3127 |
List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.DELHIVERY_PROVIDERID,
|
|
|
3128 |
OrderStatus.SHIPPED_FROM_WH);
|
|
|
3129 |
|
|
|
3130 |
if (!orders.isEmpty()) {
|
| 29441 |
tejbeer |
3131 |
Set<String> airwayBill = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
|
| 29308 |
tejbeer |
3132 |
|
| 29441 |
tejbeer |
3133 |
int arraylength = airwayBill.size();
|
|
|
3134 |
|
|
|
3135 |
if (arraylength >= 75) {
|
|
|
3136 |
|
|
|
3137 |
airwayBill = airwayBill.stream().limit(74).collect(Collectors.toSet());
|
|
|
3138 |
}
|
| 29308 |
tejbeer |
3139 |
LOGGER.info("airwayBill" + airwayBill);
|
|
|
3140 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
|
|
3141 |
|
|
|
3142 |
OkHttpClient client = new OkHttpClient();
|
|
|
3143 |
|
|
|
3144 |
Request request1 = new Request.Builder()
|
|
|
3145 |
.url(url + "?waybill=" + String.join(",", airwayBill) + "&token=" + token).get().build();
|
|
|
3146 |
|
|
|
3147 |
LOGGER.info("request1" + request1);
|
|
|
3148 |
|
|
|
3149 |
Response response = client.newCall(request1).execute();
|
|
|
3150 |
|
|
|
3151 |
LOGGER.info("jsonbj" + response.body());
|
|
|
3152 |
|
|
|
3153 |
JSONObject jsonObj = new JSONObject(response.body().string());
|
|
|
3154 |
|
|
|
3155 |
LOGGER.info("jsonObj" + jsonObj);
|
|
|
3156 |
|
| 29403 |
tejbeer |
3157 |
JSONArray shipmentData = jsonObj.getJSONArray("ShipmentData");
|
| 29308 |
tejbeer |
3158 |
Set<String> airwaybillStatus = new HashSet<>();
|
| 29403 |
tejbeer |
3159 |
for (int i = 0; i < shipmentData.length(); i++) {
|
|
|
3160 |
JSONObject jsonObject = shipmentData.getJSONObject(i);
|
| 29308 |
tejbeer |
3161 |
JSONObject shipment = jsonObject.getJSONObject("Shipment");
|
|
|
3162 |
|
|
|
3163 |
LOGGER.info("shipment" + shipment);
|
|
|
3164 |
JSONObject statusDescription = shipment.getJSONObject("Status");
|
|
|
3165 |
String awb = shipment.getString("AWB");
|
|
|
3166 |
|
|
|
3167 |
String status = statusDescription.getString("Status");
|
|
|
3168 |
LOGGER.info("status" + status);
|
|
|
3169 |
|
|
|
3170 |
LOGGER.info("awb" + awb);
|
|
|
3171 |
if (status.equals("Delivered")) {
|
|
|
3172 |
airwaybillStatus.add(awb);
|
|
|
3173 |
}
|
|
|
3174 |
|
|
|
3175 |
}
|
|
|
3176 |
if (!airwaybillStatus.isEmpty()) {
|
|
|
3177 |
for (String aws : airwaybillStatus) {
|
|
|
3178 |
|
|
|
3179 |
List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
|
|
|
3180 |
for (Order dlo : deliverdOrders) {
|
|
|
3181 |
dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
| 29403 |
tejbeer |
3182 |
dlo.setStatusDescription("Order Delivered");
|
| 29308 |
tejbeer |
3183 |
dlo.setDeliveryTimestamp(LocalDateTime.now());
|
|
|
3184 |
}
|
|
|
3185 |
|
|
|
3186 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
3187 |
sendNotificationModel.setCampaignName("Order Delivered");
|
|
|
3188 |
sendNotificationModel.setTitle("Order Delivered");
|
|
|
3189 |
sendNotificationModel.setMessage(String.format("Dear partner, your SmartDukaan ORDER " + aws
|
| 29336 |
tejbeer |
3190 |
+ "has been delivered to you in a safe sealed bag" + "."));
|
| 29308 |
tejbeer |
3191 |
sendNotificationModel.setType("url");
|
|
|
3192 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
3193 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
3194 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
3195 |
int userId = userAccountRepository.selectUserIdByRetailerId(orders.get(0).getRetailerId());
|
|
|
3196 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
3197 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
3198 |
|
|
|
3199 |
}
|
|
|
3200 |
}
|
|
|
3201 |
|
|
|
3202 |
}
|
|
|
3203 |
}
|
|
|
3204 |
|
| 29814 |
tejbeer |
3205 |
public void partnerWiseCreditAccount() throws Exception {
|
|
|
3206 |
|
|
|
3207 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
|
|
3208 |
|
|
|
3209 |
for (FofoStore fs : fofoStores) {
|
|
|
3210 |
|
|
|
3211 |
if (fs.getPan() != null) {
|
|
|
3212 |
AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
|
| 29815 |
tejbeer |
3213 |
|
|
|
3214 |
LOGGER.info("accountStatusResponseOut" + accountStatusResponseOut);
|
| 29814 |
tejbeer |
3215 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(fs.getId(),
|
|
|
3216 |
Gateway.MANDII);
|
|
|
3217 |
|
|
|
3218 |
if (creditAccount == null) {
|
|
|
3219 |
|
|
|
3220 |
creditAccount = new CreditAccount();
|
|
|
3221 |
|
|
|
3222 |
creditAccount.setFofoId(fs.getId());
|
|
|
3223 |
creditAccount.setGateway(Gateway.MANDII);
|
|
|
3224 |
|
|
|
3225 |
}
|
| 29835 |
tejbeer |
3226 |
|
|
|
3227 |
if (accountStatusResponseOut == null) {
|
|
|
3228 |
creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
|
|
|
3229 |
creditAccount.setDescription("User company not found");
|
|
|
3230 |
|
| 29817 |
tejbeer |
3231 |
} else {
|
| 29835 |
tejbeer |
3232 |
if (accountStatusResponseOut.getSanctionLimit() != null) {
|
|
|
3233 |
creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
|
|
|
3234 |
} else {
|
|
|
3235 |
creditAccount.setSanctionedAmount(0);
|
|
|
3236 |
}
|
| 29817 |
tejbeer |
3237 |
|
| 29835 |
tejbeer |
3238 |
creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
|
|
|
3239 |
if (accountStatusResponseOut.getBalanceAmount() != null) {
|
|
|
3240 |
creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
|
|
|
3241 |
} else {
|
|
|
3242 |
creditAccount.setAvailableAmount(0);
|
|
|
3243 |
}
|
|
|
3244 |
|
|
|
3245 |
if (accountStatusResponseOut.getCurrentStage() != null) {
|
|
|
3246 |
creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
|
|
|
3247 |
}
|
|
|
3248 |
if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
|
|
|
3249 |
creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
|
|
|
3250 |
} else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
|
|
|
3251 |
creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
|
|
|
3252 |
} else {
|
|
|
3253 |
|
|
|
3254 |
creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
|
|
|
3255 |
}
|
| 29817 |
tejbeer |
3256 |
}
|
|
|
3257 |
|
| 29814 |
tejbeer |
3258 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
|
|
3259 |
creditAccountRepository.persist(creditAccount);
|
|
|
3260 |
}
|
|
|
3261 |
}
|
|
|
3262 |
}
|
|
|
3263 |
|
| 30421 |
tejbeer |
3264 |
@Autowired
|
|
|
3265 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
|
|
3266 |
|
|
|
3267 |
public void reviewUncontactablePartner()
|
|
|
3268 |
throws ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
|
|
|
3269 |
|
|
|
3270 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
|
|
3271 |
|
|
|
3272 |
List<Integer> pcrms = partnerCollectionRemarkRepository
|
|
|
3273 |
.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
|
|
|
3274 |
|
|
|
3275 |
if (!pcrms.isEmpty()) {
|
|
|
3276 |
Map<Integer, PartnerCollectionRemark> partnerCollectionRemarksMap = partnerCollectionRemarkRepository
|
|
|
3277 |
.selectByIds(pcrms).stream().filter(x -> x.getRemark().equals(CollectionRemark.NOT_RESPONDING))
|
|
|
3278 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
3279 |
|
|
|
3280 |
if (!partnerCollectionRemarksMap.isEmpty()) {
|
|
|
3281 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping()
|
|
|
3282 |
.entrySet()) {
|
|
|
3283 |
List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
|
|
|
3284 |
.map(x -> partnerCollectionRemarksMap.get(x)).filter(x -> x != null)
|
|
|
3285 |
.collect(Collectors.toList());
|
|
|
3286 |
String subject = "Uncontacble Partner";
|
|
|
3287 |
String messageText = this.getMessageForUncontacblePartner(filteredRows);
|
|
|
3288 |
|
|
|
3289 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
3290 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
3291 |
String[] email = new String[] { storeGuyEntry.getKey() };
|
|
|
3292 |
|
|
|
3293 |
helper.setSubject(subject);
|
|
|
3294 |
helper.setText(messageText, true);
|
|
|
3295 |
helper.setTo(email);
|
|
|
3296 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com",
|
|
|
3297 |
"Smartdukaan Alerts");
|
|
|
3298 |
helper.setFrom(senderAddress);
|
|
|
3299 |
mailSender.send(message);
|
|
|
3300 |
|
|
|
3301 |
LOGGER.info("filteredRows {}", filteredRows);
|
|
|
3302 |
|
|
|
3303 |
}
|
|
|
3304 |
}
|
|
|
3305 |
}
|
|
|
3306 |
}
|
|
|
3307 |
|
| 26418 |
tejbeer |
3308 |
}
|
| 29814 |
tejbeer |
3309 |
|
| 27438 |
amit.gupta |
3310 |
//2284
|