| 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;
|
| 30913 |
tejbeer |
45 |
import com.spice.profitmandi.dao.enumuration.transaction.CreditRisk;
|
| 30859 |
tejbeer |
46 |
import com.spice.profitmandi.dao.enumuration.transaction.LoanReferenceType;
|
| 25609 |
amit.gupta |
47 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 30390 |
amit.gupta |
48 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
| 25300 |
tejbeer |
49 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
|
|
50 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 25590 |
amit.gupta |
51 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 30421 |
tejbeer |
52 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 30119 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
|
|
54 |
import com.spice.profitmandi.dao.repository.cs.*;
|
|
|
55 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
|
|
56 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 30390 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
|
| 28990 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 28775 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
| 30119 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| 24542 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 25721 |
tejbeer |
62 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 25854 |
amit.gupta |
63 |
import com.spice.profitmandi.service.NotificationService;
|
| 24337 |
amit.gupta |
64 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 30390 |
amit.gupta |
65 |
import com.spice.profitmandi.service.PartnerStatsService;
|
| 28368 |
tejbeer |
66 |
import com.spice.profitmandi.service.integrations.RazorpayPaymentService;
|
| 30858 |
amit.gupta |
67 |
import com.spice.profitmandi.service.integrations.bharti.model.BAGInsuranceModel;
|
| 25694 |
amit.gupta |
68 |
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
|
| 23929 |
amit.gupta |
69 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 27208 |
tejbeer |
70 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 25335 |
amit.gupta |
71 |
import com.spice.profitmandi.service.order.OrderService;
|
| 24431 |
amit.gupta |
72 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
73 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
74 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
75 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 29668 |
tejbeer |
76 |
import com.spice.profitmandi.service.serviceConfig.ServiceConfigService;
|
| 30859 |
tejbeer |
77 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
| 23929 |
amit.gupta |
78 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
79 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
80 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 25721 |
tejbeer |
81 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 29308 |
tejbeer |
82 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
83 |
import okhttp3.OkHttpClient;
|
|
|
84 |
import okhttp3.Request;
|
| 30119 |
amit.gupta |
85 |
import okhttp3.Response;
|
|
|
86 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
87 |
import org.apache.commons.lang.StringUtils;
|
|
|
88 |
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
89 |
import org.apache.http.client.methods.HttpPost;
|
|
|
90 |
import org.apache.http.entity.StringEntity;
|
|
|
91 |
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
92 |
import org.apache.http.impl.client.HttpClients;
|
|
|
93 |
import org.apache.logging.log4j.LogManager;
|
|
|
94 |
import org.apache.logging.log4j.Logger;
|
|
|
95 |
import org.json.JSONArray;
|
|
|
96 |
import org.json.JSONObject;
|
|
|
97 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
98 |
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
99 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
100 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
101 |
import org.springframework.core.io.InputStreamSource;
|
|
|
102 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
103 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
104 |
import org.springframework.stereotype.Component;
|
|
|
105 |
import org.springframework.transaction.annotation.Transactional;
|
| 23739 |
amit.gupta |
106 |
|
| 30119 |
amit.gupta |
107 |
import javax.mail.MessagingException;
|
|
|
108 |
import javax.mail.internet.InternetAddress;
|
|
|
109 |
import javax.mail.internet.MimeMessage;
|
| 30574 |
amit.gupta |
110 |
import java.io.*;
|
| 30859 |
tejbeer |
111 |
import java.math.BigDecimal;
|
| 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 |
|
| 30752 |
tejbeer |
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",
|
| 30752 |
tejbeer |
248 |
"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com" };
|
| 25609 |
amit.gupta |
249 |
|
| 30752 |
tejbeer |
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",
|
| 30752 |
tejbeer |
252 |
"niranjan.kala@smartdukaan.com" };
|
| 25609 |
amit.gupta |
253 |
|
| 30752 |
tejbeer |
254 |
private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[] { "uday.singh@smartdukaan.com",
|
|
|
255 |
"kuldeep.kumar@smartdukaan.com" };
|
| 28709 |
amit.gupta |
256 |
|
| 30752 |
tejbeer |
257 |
private static final String[] EMPLOYEE_ATTENDANCE_MAIL_LIST = new String[] { "sm@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 |
}
|
| 30644 |
amit.gupta |
650 |
LOGGER.info("Schemes processed 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 |
|
| 30752 |
tejbeer |
686 |
PartnerType startOfPreviousMonthPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId,
|
|
|
687 |
startOfPreviousMonth);
|
| 29160 |
amit.gupta |
688 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnMonth(fofoId,
|
|
|
689 |
YearMonth.from(startOfPreviousMonth.atStartOfDay()));
|
| 30119 |
amit.gupta |
690 |
if (!startOfPreviousMonthPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
| 29160 |
amit.gupta |
691 |
continue;
|
|
|
692 |
}
|
| 30119 |
amit.gupta |
693 |
if (!startOfPreviousMonthPartnerType.equals(todayPartnerType)) {
|
| 29160 |
amit.gupta |
694 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
| 30119 |
amit.gupta |
695 |
startOfPreviousMonthPartnerType, todayPartnerType);
|
| 29160 |
amit.gupta |
696 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
|
|
697 |
startOfPreviousMonth.atStartOfDay(), startOfPreviousMonth.plusMonths(1).atStartOfDay(), 0, 0);
|
|
|
698 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
699 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 28974 |
amit.gupta |
700 |
}
|
| 29160 |
amit.gupta |
701 |
|
|
|
702 |
}
|
| 28971 |
amit.gupta |
703 |
}
|
|
|
704 |
}
|
| 29252 |
amit.gupta |
705 |
|
| 29160 |
amit.gupta |
706 |
public void rollOutUpgardedMargins() throws Exception {
|
|
|
707 |
LocalDate today = LocalDate.now();
|
|
|
708 |
LocalDate yesterday = today.minusDays(1);
|
|
|
709 |
int upgradedCount = 0;
|
|
|
710 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
|
|
711 |
StringBuilder sb = new StringBuilder();
|
|
|
712 |
for (FofoStore store : stores) {
|
|
|
713 |
int fofoId = store.getId();
|
| 29252 |
amit.gupta |
714 |
|
| 30215 |
amit.gupta |
715 |
PartnerType yesterdayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, yesterday);
|
|
|
716 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, today);
|
| 29160 |
amit.gupta |
717 |
if (!yesterdayPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
|
|
718 |
continue;
|
|
|
719 |
}
|
|
|
720 |
if (!yesterdayPartnerType.equals(todayPartnerType)) {
|
|
|
721 |
upgradedCount++;
|
| 29252 |
amit.gupta |
722 |
sb.append(String.format("Partner Type has been changed for code %s from %s to %s", store.getCode(),
|
|
|
723 |
yesterdayPartnerType.toString(), todayPartnerType.toString()));
|
| 29160 |
amit.gupta |
724 |
sb.append("<br>");
|
|
|
725 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
|
|
726 |
yesterdayPartnerType, todayPartnerType);
|
|
|
727 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
|
|
728 |
yesterday.withDayOfMonth(1).atStartOfDay(), yesterday.atStartOfDay(), 0, 0);
|
|
|
729 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
730 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
|
|
731 |
}
|
| 29252 |
amit.gupta |
732 |
|
| 29160 |
amit.gupta |
733 |
}
|
|
|
734 |
}
|
| 29252 |
amit.gupta |
735 |
if (upgradedCount > 0) {
|
|
|
736 |
sendMailHtmlFormat(
|
| 30752 |
tejbeer |
737 |
new String[] { "amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
|
|
738 |
"neeraj.gupta@smartdukaan.com" },
|
| 29252 |
amit.gupta |
739 |
sb.toString(), null, "Few Partners Category have been Upgraded");
|
| 29160 |
amit.gupta |
740 |
} else {
|
| 29252 |
amit.gupta |
741 |
sendMailHtmlFormat(
|
| 30752 |
tejbeer |
742 |
new String[] { "amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
|
|
743 |
"neeraj.gupta@smartdukaan.com" },
|
| 29252 |
amit.gupta |
744 |
sb.toString(), null, "No partners Category have been upgraded today");
|
| 29160 |
amit.gupta |
745 |
}
|
|
|
746 |
}
|
| 23724 |
amit.gupta |
747 |
|
| 30390 |
amit.gupta |
748 |
@Autowired
|
|
|
749 |
private PartnerStatsService partnerStatsService;
|
|
|
750 |
|
| 30393 |
amit.gupta |
751 |
// Temporary Method
|
|
|
752 |
public void evaluateExcessSchemeOut() throws Exception {
|
|
|
753 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
754 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
|
|
755 |
|
|
|
756 |
List<List<?>> rows = new ArrayList<>();
|
|
|
757 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
758 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
|
|
759 |
schemeRepository.selectAll().stream().forEach(x -> {
|
|
|
760 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
761 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
762 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
763 |
if (x.getActiveTimestamp() != null) {
|
|
|
764 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
765 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
766 |
endDateTime = x.getExpireTimestamp();
|
|
|
767 |
}
|
|
|
768 |
for (SchemeInOut sio : sioList) {
|
|
|
769 |
InventoryItem inventoryItem = null;
|
|
|
770 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
|
|
771 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
772 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
|
|
773 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
774 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
775 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
776 |
if (record.isPresent()) {
|
|
|
777 |
int fofoId = record.get().getFofoId();
|
|
|
778 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
779 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
780 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
781 |
userAmountMap.put(fofoId, 0f);
|
|
|
782 |
}
|
|
|
783 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
784 |
try {
|
|
|
785 |
rows.add(Arrays.asList(x.getDescription(),
|
|
|
786 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
|
|
787 |
userNameMap.get(fofoId), sio.getAmount(),
|
|
|
788 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
789 |
fofoOrder.getInvoiceNumber(),
|
|
|
790 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
791 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
792 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
793 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
794 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
|
|
795 |
} catch (Exception e) {
|
|
|
796 |
e.printStackTrace();
|
|
|
797 |
}
|
|
|
798 |
}
|
|
|
799 |
}
|
|
|
800 |
}
|
|
|
801 |
}
|
|
|
802 |
}
|
|
|
803 |
});
|
|
|
804 |
userAmountMap.entrySet().stream()
|
|
|
805 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
806 |
x.getValue(), userNameMap.get(x.getKey())));
|
|
|
807 |
|
|
|
808 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
809 |
Utils.sendMailWithAttachment(googleMailSender,
|
| 30752 |
tejbeer |
810 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
| 30393 |
amit.gupta |
811 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
|
|
812 |
|
|
|
813 |
}
|
|
|
814 |
|
| 30390 |
amit.gupta |
815 |
public void fetchParnterStats() throws Exception {
|
|
|
816 |
Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
|
|
|
817 |
ObjectOutputStream oos = null;
|
|
|
818 |
FileOutputStream fout = null;
|
|
|
819 |
try {
|
|
|
820 |
fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
|
|
|
821 |
oos = new ObjectOutputStream(fout);
|
|
|
822 |
oos.writeObject(partnerStats);
|
|
|
823 |
|
|
|
824 |
} catch (Exception ex) {
|
|
|
825 |
ex.printStackTrace();
|
|
|
826 |
} finally {
|
|
|
827 |
if (oos != null) {
|
|
|
828 |
oos.close();
|
|
|
829 |
}
|
|
|
830 |
}
|
|
|
831 |
ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
|
|
|
832 |
if (rct == null) {
|
|
|
833 |
rct = new ReporticoCacheTable();
|
|
|
834 |
rct.setTableName("partnerStat");
|
| 30393 |
amit.gupta |
835 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
|
|
836 |
reporticoCacheTableRepository.persist(rct);
|
|
|
837 |
} else {
|
|
|
838 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
| 30390 |
amit.gupta |
839 |
}
|
|
|
840 |
}
|
|
|
841 |
|
| 30637 |
amit.gupta |
842 |
public void processPriceDrop() throws Exception {
|
| 30752 |
tejbeer |
843 |
List<PriceDrop> priceDrops = priceDropRepository.selectAllByDatesBetween(LocalDateTime.now(),
|
|
|
844 |
LocalDateTime.now().minusYears(1));
|
| 30637 |
amit.gupta |
845 |
for (PriceDrop priceDrop : priceDrops) {
|
|
|
846 |
if (priceDrop.getDropAmount() > 0) {
|
|
|
847 |
priceDropService.processPriceDrop(priceDrop.getId(), true);
|
|
|
848 |
}
|
|
|
849 |
}
|
|
|
850 |
}
|
|
|
851 |
|
| 25598 |
amit.gupta |
852 |
private class SaleRoles {
|
|
|
853 |
|
|
|
854 |
private List<String> l1;
|
|
|
855 |
private List<String> l2;
|
|
|
856 |
|
|
|
857 |
public SaleRoles() {
|
|
|
858 |
l1 = new ArrayList<>();
|
|
|
859 |
l2 = new ArrayList<>();
|
|
|
860 |
}
|
|
|
861 |
|
|
|
862 |
public List<String> getL1() {
|
|
|
863 |
return l1;
|
|
|
864 |
}
|
|
|
865 |
|
|
|
866 |
public List<String> getL2() {
|
|
|
867 |
return l2;
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
}
|
|
|
871 |
|
| 26945 |
amit.gupta |
872 |
private class FofoReportingModel {
|
|
|
873 |
private String code;
|
|
|
874 |
private int fofoId;
|
|
|
875 |
private String businessName;
|
|
|
876 |
private String territoryManager;
|
|
|
877 |
private String regionalManager;
|
|
|
878 |
|
|
|
879 |
@Override
|
|
|
880 |
public String toString() {
|
|
|
881 |
return "FofoReportingModel [code=" + code + ", fofoId=" + fofoId + ", businessName=" + businessName
|
|
|
882 |
+ ", territoryManager=" + territoryManager + ", regionalManager=" + regionalManager + "]";
|
|
|
883 |
}
|
|
|
884 |
|
|
|
885 |
public String getCode() {
|
|
|
886 |
return code;
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
public void setCode(String code) {
|
|
|
890 |
this.code = code;
|
|
|
891 |
}
|
|
|
892 |
|
|
|
893 |
public String getBusinessName() {
|
|
|
894 |
return businessName;
|
|
|
895 |
}
|
|
|
896 |
|
|
|
897 |
public void setBusinessName(String businessName) {
|
|
|
898 |
this.businessName = businessName;
|
|
|
899 |
}
|
|
|
900 |
|
|
|
901 |
public String getTerritoryManager() {
|
|
|
902 |
return territoryManager;
|
|
|
903 |
}
|
|
|
904 |
|
|
|
905 |
public void setTerritoryManager(String territoryManager) {
|
|
|
906 |
this.territoryManager = territoryManager;
|
|
|
907 |
}
|
|
|
908 |
|
|
|
909 |
public String getRegionalManager() {
|
|
|
910 |
return regionalManager;
|
|
|
911 |
}
|
|
|
912 |
|
|
|
913 |
public void setRegionalManager(String regionalManager) {
|
|
|
914 |
this.regionalManager = regionalManager;
|
|
|
915 |
}
|
|
|
916 |
|
|
|
917 |
private ScheduledTasks getOuterType() {
|
|
|
918 |
return ScheduledTasks.this;
|
|
|
919 |
}
|
|
|
920 |
|
|
|
921 |
@Override
|
|
|
922 |
public int hashCode() {
|
|
|
923 |
final int prime = 31;
|
|
|
924 |
int result = 1;
|
|
|
925 |
result = prime * result + getOuterType().hashCode();
|
|
|
926 |
result = prime * result + ((businessName == null) ? 0 : businessName.hashCode());
|
|
|
927 |
result = prime * result + ((code == null) ? 0 : code.hashCode());
|
|
|
928 |
result = prime * result + fofoId;
|
|
|
929 |
result = prime * result + ((regionalManager == null) ? 0 : regionalManager.hashCode());
|
|
|
930 |
result = prime * result + ((territoryManager == null) ? 0 : territoryManager.hashCode());
|
|
|
931 |
return result;
|
|
|
932 |
}
|
|
|
933 |
|
|
|
934 |
@Override
|
|
|
935 |
public boolean equals(Object obj) {
|
|
|
936 |
if (this == obj)
|
|
|
937 |
return true;
|
|
|
938 |
if (obj == null)
|
|
|
939 |
return false;
|
|
|
940 |
if (getClass() != obj.getClass())
|
|
|
941 |
return false;
|
|
|
942 |
FofoReportingModel other = (FofoReportingModel) obj;
|
|
|
943 |
if (!getOuterType().equals(other.getOuterType()))
|
|
|
944 |
return false;
|
|
|
945 |
if (businessName == null) {
|
|
|
946 |
if (other.businessName != null)
|
|
|
947 |
return false;
|
|
|
948 |
} else if (!businessName.equals(other.businessName))
|
|
|
949 |
return false;
|
|
|
950 |
if (code == null) {
|
|
|
951 |
if (other.code != null)
|
|
|
952 |
return false;
|
|
|
953 |
} else if (!code.equals(other.code))
|
|
|
954 |
return false;
|
|
|
955 |
if (fofoId != other.fofoId)
|
|
|
956 |
return false;
|
|
|
957 |
if (regionalManager == null) {
|
|
|
958 |
if (other.regionalManager != null)
|
|
|
959 |
return false;
|
|
|
960 |
} else if (!regionalManager.equals(other.regionalManager))
|
|
|
961 |
return false;
|
|
|
962 |
if (territoryManager == null) {
|
|
|
963 |
if (other.territoryManager != null)
|
|
|
964 |
return false;
|
|
|
965 |
} else if (!territoryManager.equals(other.territoryManager))
|
|
|
966 |
return false;
|
|
|
967 |
return true;
|
|
|
968 |
}
|
|
|
969 |
|
|
|
970 |
public int getFofoId() {
|
|
|
971 |
return fofoId;
|
|
|
972 |
}
|
|
|
973 |
|
|
|
974 |
public void setFofoId(int fofoId) {
|
|
|
975 |
this.fofoId = fofoId;
|
|
|
976 |
}
|
|
|
977 |
|
|
|
978 |
}
|
|
|
979 |
|
| 24271 |
amit.gupta |
980 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
981 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 25267 |
amit.gupta |
982 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 23929 |
amit.gupta |
983 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
984 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 25351 |
tejbeer |
985 |
|
| 26957 |
amit.gupta |
986 |
List<String> headers = Arrays.asList("Code", "Outlet name", "State Manager", "Teritory/Team Lead",
|
| 26945 |
amit.gupta |
987 |
"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount",
|
|
|
988 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty",
|
|
|
989 |
"Short Days");
|
| 25837 |
amit.gupta |
990 |
List<List<?>> rows = new ArrayList<>();
|
| 25895 |
amit.gupta |
991 |
Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
|
| 25598 |
amit.gupta |
992 |
|
| 26945 |
amit.gupta |
993 |
Map<Integer, FofoReportingModel> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
|
| 25598 |
amit.gupta |
994 |
|
| 26945 |
amit.gupta |
995 |
Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository
|
|
|
996 |
.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now()).stream().collect(Collectors.groupingBy(
|
|
|
997 |
x -> x.getFofoId(), Collectors.summingInt(x -> x.getShortPercentage() > 10 ? 1 : 0)));
|
|
|
998 |
|
| 24002 |
amit.gupta |
999 |
for (FofoStore fofoStore : fofoStores) {
|
| 27750 |
amit.gupta |
1000 |
LOGGER.info("Fofo Store {}, {}", fofoStore.getId(), fofoStore.getCode());
|
| 26376 |
amit.gupta |
1001 |
int fofoId = fofoStore.getId();
|
| 26945 |
amit.gupta |
1002 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 1);
|
| 25598 |
amit.gupta |
1003 |
partnerDailyInvestment.setDate(yesterDay);
|
| 26945 |
amit.gupta |
1004 |
|
| 25598 |
amit.gupta |
1005 |
try {
|
|
|
1006 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 26945 |
amit.gupta |
1007 |
shortDaysMap.put(fofoId,
|
|
|
1008 |
shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
|
| 25598 |
amit.gupta |
1009 |
} catch (Exception e) {
|
|
|
1010 |
// ignore the exceptions during persist
|
|
|
1011 |
}
|
|
|
1012 |
|
| 24002 |
amit.gupta |
1013 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 25837 |
amit.gupta |
1014 |
if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
|
| 24002 |
amit.gupta |
1015 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
1016 |
continue;
|
|
|
1017 |
}
|
| 26945 |
amit.gupta |
1018 |
FofoReportingModel reportingModel = partnerIdSalesHeaderMap.get(fofoStore.getId());
|
|
|
1019 |
List<Serializable> row = new ArrayList<>();
|
|
|
1020 |
row.addAll(Arrays.asList(reportingModel.getCode(), reportingModel.getBusinessName(),
|
|
|
1021 |
reportingModel.getRegionalManager(), reportingModel.getTerritoryManager()));
|
| 25927 |
amit.gupta |
1022 |
row.addAll(
|
|
|
1023 |
Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
|
| 26945 |
amit.gupta |
1024 |
partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-"
|
|
|
1025 |
: "(" + partnerDailyInvestment.getActivatedStockAmount() + ")",
|
| 25927 |
amit.gupta |
1026 |
0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
|
|
1027 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
| 26945 |
amit.gupta |
1028 |
partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),
|
|
|
1029 |
shortDaysMap.get(fofoId)));
|
| 25837 |
amit.gupta |
1030 |
partnerRowsMap.put(fofoStore.getId(), row);
|
| 24002 |
amit.gupta |
1031 |
rows.add(row);
|
|
|
1032 |
|
| 23929 |
amit.gupta |
1033 |
}
|
| 25312 |
amit.gupta |
1034 |
|
| 24271 |
amit.gupta |
1035 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 25598 |
amit.gupta |
1036 |
|
| 25927 |
amit.gupta |
1037 |
if (sendTo == null) {
|
| 30215 |
amit.gupta |
1038 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
| 25895 |
amit.gupta |
1039 |
List<List<?>> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerRowsMap.get(x))
|
|
|
1040 |
.filter(x -> x != null).collect(Collectors.toList());
|
|
|
1041 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
| 30752 |
tejbeer |
1042 |
String[] sendToArray = new String[] { storeGuyEntry.getKey() };
|
| 25895 |
amit.gupta |
1043 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
1044 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
|
|
1045 |
}
|
| 27210 |
tejbeer |
1046 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
| 28467 |
tejbeer |
1047 |
"neeraj.gupta@smartdukaan.com", "amit.gupta@shop2020.in", "manish.gupta@smartdukaan.com",
|
|
|
1048 |
"niranjan.kala@smartdukaan.com");
|
| 25341 |
amit.gupta |
1049 |
}
|
| 25312 |
amit.gupta |
1050 |
|
| 25604 |
amit.gupta |
1051 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
1052 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
| 25609 |
amit.gupta |
1053 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
1054 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 24271 |
amit.gupta |
1055 |
|
| 23929 |
amit.gupta |
1056 |
}
|
| 24177 |
govind |
1057 |
|
| 26945 |
amit.gupta |
1058 |
private Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
|
| 25598 |
amit.gupta |
1059 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
|
|
1060 |
|
|
|
1061 |
List<Position> positions = positionRepository
|
|
|
1062 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
1063 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
|
|
|
1064 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1065 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = csService.getPositionCustomRetailerMap(positions);
|
|
|
1066 |
for (Position position : positions) {
|
|
|
1067 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
| 25609 |
amit.gupta |
1068 |
if (crList == null)
|
|
|
1069 |
continue;
|
| 25598 |
amit.gupta |
1070 |
for (CustomRetailer cr : crList) {
|
|
|
1071 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
|
|
1072 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
|
|
1073 |
}
|
|
|
1074 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
|
|
1075 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
| 26945 |
amit.gupta |
1076 |
if (authUser == null) {
|
| 26059 |
amit.gupta |
1077 |
continue;
|
|
|
1078 |
}
|
| 25598 |
amit.gupta |
1079 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
1080 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
|
|
1081 |
saleRoles.getL1().add(name);
|
|
|
1082 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
|
|
1083 |
saleRoles.getL2().add(name);
|
|
|
1084 |
}
|
|
|
1085 |
}
|
|
|
1086 |
}
|
| 25837 |
amit.gupta |
1087 |
|
|
|
1088 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
|
|
1089 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
|
|
1090 |
allCrList.addAll(cr);
|
|
|
1091 |
}
|
|
|
1092 |
|
|
|
1093 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
|
|
|
1094 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1095 |
|
| 26945 |
amit.gupta |
1096 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
|
| 25837 |
amit.gupta |
1097 |
|
|
|
1098 |
for (CustomRetailer cr : allCrList) {
|
|
|
1099 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
| 25927 |
amit.gupta |
1100 |
if (fofoStore == null) {
|
| 25870 |
amit.gupta |
1101 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
|
|
1102 |
continue;
|
|
|
1103 |
}
|
| 26945 |
amit.gupta |
1104 |
String code = fofoStore.getCode();
|
|
|
1105 |
// String storeName = "SmartDukaan-" +
|
|
|
1106 |
// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
| 25837 |
amit.gupta |
1107 |
String businessName = cr.getBusinessName();
|
|
|
1108 |
try {
|
|
|
1109 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
1110 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
| 26945 |
amit.gupta |
1111 |
FofoReportingModel reportingModel = new FofoReportingModel();
|
|
|
1112 |
reportingModel.setBusinessName(businessName);
|
|
|
1113 |
reportingModel.setCode(code);
|
|
|
1114 |
reportingModel.setFofoId(fofoStore.getId());
|
|
|
1115 |
reportingModel.setRegionalManager(stateManager);
|
|
|
1116 |
reportingModel.setTerritoryManager(territoryManager);
|
|
|
1117 |
partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
|
| 25837 |
amit.gupta |
1118 |
} catch (Exception e) {
|
|
|
1119 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
|
|
1120 |
}
|
|
|
1121 |
}
|
|
|
1122 |
return partnerIdSalesHeadersMap;
|
|
|
1123 |
|
| 25598 |
amit.gupta |
1124 |
}
|
|
|
1125 |
|
| 24271 |
amit.gupta |
1126 |
public void sendPartnerInvestmentDetails() throws Exception {
|
| 25565 |
amit.gupta |
1127 |
this.sendPartnerInvestmentDetails(null);
|
| 24271 |
amit.gupta |
1128 |
}
|
|
|
1129 |
|
| 24697 |
amit.gupta |
1130 |
public void sendAgeingReport(String... sendTo) throws Exception {
|
| 24692 |
amit.gupta |
1131 |
|
|
|
1132 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
|
|
|
1133 |
"itemstockageing.xml");
|
| 24708 |
amit.gupta |
1134 |
InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 24754 |
amit.gupta |
1135 |
"ItemwiseOverallPendingIndent.xml");
|
| 24683 |
amit.gupta |
1136 |
Attachment attachment = new Attachment(
|
| 25445 |
amit.gupta |
1137 |
"ageing-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
|
| 24707 |
amit.gupta |
1138 |
Attachment attachment1 = new Attachment(
|
| 25445 |
amit.gupta |
1139 |
"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
|
| 25418 |
amit.gupta |
1140 |
|
| 25609 |
amit.gupta |
1141 |
Utils.sendMailWithAttachments(googleMailSender, STOCK_AGEING_MAIL_LIST, null, "Stock Ageing Report", "PFA",
|
|
|
1142 |
attachment);
|
|
|
1143 |
Utils.sendMailWithAttachments(googleMailSender, ITEMWISE_PENDING_INDENT_MAIL_LIST, null,
|
|
|
1144 |
"Itemwise Pending indent", "PFA", attachment1);
|
|
|
1145 |
|
| 25598 |
amit.gupta |
1146 |
// Reports to be sent to mapped partners
|
| 25597 |
amit.gupta |
1147 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
| 25503 |
amit.gupta |
1148 |
|
|
|
1149 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
| 25418 |
amit.gupta |
1150 |
Map<String, String> params = new HashMap<>();
|
| 25503 |
amit.gupta |
1151 |
if (storeGuyEntry.getValue().size() == 0)
|
|
|
1152 |
continue;
|
| 25418 |
amit.gupta |
1153 |
params.put("MANUAL_email", String.join(",", storeGuyEntry.getValue()));
|
|
|
1154 |
InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
1155 |
"focostockreport.xml", params);
|
|
|
1156 |
Attachment attache = new Attachment(
|
| 25609 |
amit.gupta |
1157 |
"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
|
| 25584 |
amit.gupta |
1158 |
System.out.println(storeGuyEntry.getValue());
|
| 30752 |
tejbeer |
1159 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
|
| 25609 |
amit.gupta |
1160 |
"Franchise Stock Report", "PFA", attache);
|
| 25418 |
amit.gupta |
1161 |
}
|
| 25503 |
amit.gupta |
1162 |
|
| 24681 |
amit.gupta |
1163 |
}
|
| 24533 |
govind |
1164 |
|
| 28632 |
amit.gupta |
1165 |
public void sendIndentTertiary() throws Exception {
|
| 28709 |
amit.gupta |
1166 |
|
| 28632 |
amit.gupta |
1167 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
1168 |
"indentandtertiary.xml");
|
|
|
1169 |
Attachment attachment = new Attachment(
|
| 28839 |
tejbeer |
1170 |
"indentandtertiary-report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr);
|
| 28709 |
amit.gupta |
1171 |
Utils.sendMailWithAttachments(googleMailSender, INDENT_TERTIARY_MAIL_LIST, null, "Indent Tertiary Report",
|
|
|
1172 |
"PFA", attachment);
|
|
|
1173 |
|
| 28632 |
amit.gupta |
1174 |
}
|
| 28790 |
amit.gupta |
1175 |
|
| 28769 |
amit.gupta |
1176 |
public void sendAttendanceMorningAlert() throws Exception {
|
| 28793 |
amit.gupta |
1177 |
LocalDateTime moriningTime = LocalDate.now().atTime(10, 31);
|
| 28775 |
amit.gupta |
1178 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 28790 |
amit.gupta |
1179 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
|
|
1180 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
|
|
1181 |
|
| 28769 |
amit.gupta |
1182 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
| 28790 |
amit.gupta |
1183 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
|
|
1184 |
|
|
|
1185 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository
|
|
|
1186 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now());
|
|
|
1187 |
|
|
|
1188 |
Map<Integer, Optional<EmployeeAttendance>> employeeMorningAttendance = employeeAttendances.stream()
|
|
|
1189 |
.collect(Collectors.groupingBy(EmployeeAttendance::getUserId,
|
|
|
1190 |
Collectors.minBy(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))));
|
|
|
1191 |
for (AuthUser authUser : authUsers) {
|
| 28769 |
amit.gupta |
1192 |
User user = userMap.get(authUser.getEmailId());
|
|
|
1193 |
Optional<EmployeeAttendance> employeeAttendanceOptional = employeeMorningAttendance.get(user.getId());
|
| 28817 |
amit.gupta |
1194 |
LOGGER.info("AuthUser - {}, employeeAttendanceOptional {}", authUser.getName(), employeeAttendanceOptional);
|
| 28839 |
tejbeer |
1195 |
if (employeeAttendanceOptional != null) {
|
| 28818 |
amit.gupta |
1196 |
LOGGER.info("employeeAttendanceOptional.orElse {}", employeeAttendanceOptional.orElse(null));
|
| 28839 |
tejbeer |
1197 |
if (employeeAttendanceOptional.orElse(null) != null) {
|
|
|
1198 |
LOGGER.info("employeeAttendanceOptional.get().getCreateTimestamp() {}",
|
|
|
1199 |
employeeAttendanceOptional.get().getCreateTimestamp());
|
| 28818 |
amit.gupta |
1200 |
}
|
|
|
1201 |
}
|
| 28790 |
amit.gupta |
1202 |
if (employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null
|
| 28769 |
amit.gupta |
1203 |
|| employeeAttendanceOptional.get().getCreateTimestamp().isAfter(moriningTime)) {
|
| 28819 |
amit.gupta |
1204 |
LOGGER.info("Will Send Email to {}", authUser.getFullName());
|
| 28790 |
amit.gupta |
1205 |
String body = String.format(
|
| 28806 |
amit.gupta |
1206 |
"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 |
1207 |
authUser.getFullName(),
|
|
|
1208 |
(employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null) ? ""
|
|
|
1209 |
: "(Punched at "
|
| 30752 |
tejbeer |
1210 |
+ FormattingUtils.format(employeeAttendanceOptional.get().getCreateTimestamp())
|
|
|
1211 |
+ ")");
|
| 28839 |
tejbeer |
1212 |
|
| 30752 |
tejbeer |
1213 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() },
|
|
|
1214 |
new String[] { "sm@smartdukaan.com" }, "Attendance Alert", body);
|
| 28839 |
tejbeer |
1215 |
|
| 28769 |
amit.gupta |
1216 |
}
|
|
|
1217 |
}
|
| 28790 |
amit.gupta |
1218 |
|
| 28769 |
amit.gupta |
1219 |
}
|
| 28790 |
amit.gupta |
1220 |
|
| 28775 |
amit.gupta |
1221 |
public void sendAttendanceEveningAlert() throws Exception {
|
|
|
1222 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 28790 |
amit.gupta |
1223 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
|
|
1224 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
|
|
1225 |
|
| 28775 |
amit.gupta |
1226 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
| 28790 |
amit.gupta |
1227 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
| 28775 |
amit.gupta |
1228 |
|
| 28790 |
amit.gupta |
1229 |
Map<Integer, List<EmployeeAttendance>> employeeAttendancesMap = employeeAttendanceRepository
|
|
|
1230 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now()).stream()
|
|
|
1231 |
.collect(Collectors.groupingBy(x -> x.getUserId()));
|
|
|
1232 |
|
|
|
1233 |
for (AuthUser authUser : authUsers) {
|
| 28775 |
amit.gupta |
1234 |
User user = userMap.get(authUser.getEmailId());
|
| 28784 |
amit.gupta |
1235 |
String body = null;
|
|
|
1236 |
List<EmployeeAttendance> employeeAttendances = employeeAttendancesMap.get(user.getId());
|
| 28790 |
amit.gupta |
1237 |
if (employeeAttendances == null) {
|
|
|
1238 |
body = String.format(
|
| 28806 |
amit.gupta |
1239 |
"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 |
1240 |
authUser.getFullName());
|
| 28784 |
amit.gupta |
1241 |
} else {
|
| 28790 |
amit.gupta |
1242 |
List<LocalDateTime> punchTimes = employeeAttendances.stream()
|
|
|
1243 |
.sorted(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))
|
|
|
1244 |
.map(x -> x.getCreateTimestamp()).collect(Collectors.toList());
|
|
|
1245 |
if (punchTimes.size() == 1) {
|
|
|
1246 |
// body = String.format("Dear %s,\n Pls note that you haven't punched out yet.
|
|
|
1247 |
// You have been marked absent for half the day. You may contact your manager
|
|
|
1248 |
// and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
| 28784 |
amit.gupta |
1249 |
} else {
|
|
|
1250 |
LocalDateTime firstPunch = punchTimes.get(0);
|
| 28790 |
amit.gupta |
1251 |
LocalDateTime lastPunch = punchTimes.get(punchTimes.size() - 1);
|
| 28805 |
amit.gupta |
1252 |
Duration duration = Duration.between(firstPunch, lastPunch);
|
| 28784 |
amit.gupta |
1253 |
boolean hoursCompleted = lastPunch.isAfter(firstPunch.plusHours(8).plusMinutes(30));
|
| 28790 |
amit.gupta |
1254 |
if (!hoursCompleted) {
|
|
|
1255 |
body = String.format(
|
| 28806 |
amit.gupta |
1256 |
"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 |
1257 |
authUser.getFullName(), duration.toHours(),
|
|
|
1258 |
duration.toMinutes() - duration.toHours() * 60);
|
| 28784 |
amit.gupta |
1259 |
}
|
|
|
1260 |
}
|
|
|
1261 |
|
|
|
1262 |
}
|
| 28790 |
amit.gupta |
1263 |
if (body != null) {
|
| 30752 |
tejbeer |
1264 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() },
|
|
|
1265 |
new String[] { "sm@smartdukaan.com" }, "Attendance Alert", body);
|
| 28775 |
amit.gupta |
1266 |
}
|
|
|
1267 |
}
|
| 28790 |
amit.gupta |
1268 |
|
|
|
1269 |
this.sendMailToHR();
|
|
|
1270 |
|
| 28775 |
amit.gupta |
1271 |
}
|
| 28790 |
amit.gupta |
1272 |
|
|
|
1273 |
private void sendMailToHR() throws Exception {
|
|
|
1274 |
Map<String, String> map = new HashMap<>();
|
|
|
1275 |
String reporticoDate = FormattingUtils.formatReporitcoDate(LocalDateTime.now());
|
|
|
1276 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
|
|
1277 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
|
|
1278 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
1279 |
"employeeattendance.xml");
|
|
|
1280 |
Attachment attachment = new Attachment("attendance-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv",
|
|
|
1281 |
isr);
|
|
|
1282 |
Utils.sendMailWithAttachments(googleMailSender, EMPLOYEE_ATTENDANCE_MAIL_LIST, null,
|
|
|
1283 |
"Attendance - " + FormattingUtils.formatDate(LocalDateTime.now()), "PFA Attendance", attachment);
|
|
|
1284 |
}
|
|
|
1285 |
|
| 28709 |
amit.gupta |
1286 |
public void checkPartnerActiveStore() throws Exception {
|
|
|
1287 |
|
|
|
1288 |
List<FofoStore> fofoStores = fofoStoreRepository.selectByStatus(true);
|
|
|
1289 |
|
|
|
1290 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
| 28712 |
amit.gupta |
1291 |
if (!fofoStores.isEmpty()) {
|
|
|
1292 |
for (FofoStore fofoStore : fofoStores) {
|
| 28709 |
amit.gupta |
1293 |
|
| 28712 |
amit.gupta |
1294 |
if (currentDate.isBefore(fofoStore.getActiveTimeStamp())) {
|
| 28709 |
amit.gupta |
1295 |
|
| 28712 |
amit.gupta |
1296 |
fofoStore.setActive(true);
|
|
|
1297 |
fofoStoreRepository.persist(fofoStore);
|
|
|
1298 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
| 28709 |
amit.gupta |
1299 |
|
| 30393 |
amit.gupta |
1300 |
} else {
|
| 28712 |
amit.gupta |
1301 |
fofoStore.setActive(false);
|
|
|
1302 |
fofoStore.setActiveTimeStamp(null);
|
|
|
1303 |
fofoStoreRepository.persist(fofoStore);
|
|
|
1304 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
|
|
1305 |
}
|
| 28709 |
amit.gupta |
1306 |
|
|
|
1307 |
}
|
|
|
1308 |
}
|
|
|
1309 |
|
|
|
1310 |
}
|
|
|
1311 |
|
| 24697 |
amit.gupta |
1312 |
public void sendAgeingReport() throws Exception {
|
| 30593 |
amit.gupta |
1313 |
sendAgeingReport("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 28467 |
tejbeer |
1314 |
"niranjan.kala@smartdukaan.com", "manish.gupta@smartdukaan.com", "kuldeep.kumar@smartdukaan.com");
|
| 24697 |
amit.gupta |
1315 |
}
|
|
|
1316 |
|
| 24533 |
govind |
1317 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
1318 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
1319 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
1320 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
1321 |
}
|
|
|
1322 |
}
|
| 23929 |
amit.gupta |
1323 |
|
| 24542 |
amit.gupta |
1324 |
public void walletmismatch() throws Exception {
|
|
|
1325 |
LocalDate curDate = LocalDate.now();
|
| 24553 |
amit.gupta |
1326 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 24552 |
amit.gupta |
1327 |
System.out.println(pdis.size());
|
| 24542 |
amit.gupta |
1328 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 24549 |
amit.gupta |
1329 |
int fofoId = pdi.getFofoId();
|
| 24542 |
amit.gupta |
1330 |
for (PartnerDailyInvestment investment : Lists
|
|
|
1331 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 24552 |
amit.gupta |
1332 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 24555 |
amit.gupta |
1333 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 24552 |
amit.gupta |
1334 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 24841 |
govind |
1335 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
|
|
|
1336 |
investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
|
| 24551 |
amit.gupta |
1337 |
|
| 24542 |
amit.gupta |
1338 |
}
|
| 24549 |
amit.gupta |
1339 |
}
|
| 24542 |
amit.gupta |
1340 |
|
|
|
1341 |
}
|
| 29160 |
amit.gupta |
1342 |
|
| 28990 |
amit.gupta |
1343 |
@Autowired
|
|
|
1344 |
StateRepository stateRepository;
|
| 24542 |
amit.gupta |
1345 |
|
|
|
1346 |
public void gst() throws Exception {
|
| 28995 |
amit.gupta |
1347 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2021, 8, 16).atStartOfDay(),
|
| 28990 |
amit.gupta |
1348 |
LocalDateTime.now());
|
| 24548 |
amit.gupta |
1349 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
1350 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
1351 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 24542 |
amit.gupta |
1352 |
|
|
|
1353 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
1354 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
1355 |
Integer stateId = null;
|
|
|
1356 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
1357 |
try {
|
| 28990 |
amit.gupta |
1358 |
stateId = stateRepository.selectByName(customerAddress.getState()).getId();
|
| 24542 |
amit.gupta |
1359 |
} catch (Exception e) {
|
| 28990 |
amit.gupta |
1360 |
LOGGER.error("Cannot found state named {}", customerAddress.getState());
|
|
|
1361 |
continue;
|
| 24542 |
amit.gupta |
1362 |
}
|
|
|
1363 |
}
|
|
|
1364 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
1365 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 24548 |
amit.gupta |
1366 |
|
|
|
1367 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 26929 |
amit.gupta |
1368 |
List<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
| 24542 |
amit.gupta |
1369 |
if (stateId != null) {
|
| 26929 |
amit.gupta |
1370 |
itemIdStateTaxRateMap = stateGstRateRepository.getStateTaxRate(itemIds, stateId);
|
| 24542 |
amit.gupta |
1371 |
} else {
|
| 26929 |
amit.gupta |
1372 |
itemIdIgstTaxRateMap = stateGstRateRepository.getIgstTaxRate(itemIds);
|
| 24542 |
amit.gupta |
1373 |
}
|
|
|
1374 |
|
| 24548 |
amit.gupta |
1375 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 28990 |
amit.gupta |
1376 |
float sgstRate = foi.getSgstRate();
|
|
|
1377 |
float cgstRate = foi.getCgstRate();
|
|
|
1378 |
float igstRate = foi.getIgstRate();
|
| 29160 |
amit.gupta |
1379 |
if (stateId == null && igstRate == 0) {
|
|
|
1380 |
|
|
|
1381 |
foi.setSgstRate(0);
|
|
|
1382 |
foi.setCgstRate(0);
|
|
|
1383 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
|
|
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());
|
| 28990 |
amit.gupta |
1388 |
LOGGER.info("Rates getIgstRate() {}", itemIdIgstTaxRateMap.get(foi.getItemId()));
|
| 29160 |
amit.gupta |
1389 |
|
|
|
1390 |
} else if (stateId != null && sgstRate == 0 && cgstRate == 0) {
|
|
|
1391 |
|
|
|
1392 |
foi.setIgstRate(0);
|
|
|
1393 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
|
|
1394 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
|
|
1395 |
|
| 28993 |
amit.gupta |
1396 |
LOGGER.info("Invoice {}, Date {}", fofoOrder.getInvoiceNumber(), fofoOrder.getCreateTimestamp());
|
| 29160 |
amit.gupta |
1397 |
LOGGER.info("customerAddress.getState() {}, retailerAddress.getState() {}",
|
|
|
1398 |
customerAddress.getState(), retailerAddress.getState());
|
|
|
1399 |
LOGGER.info("Rates getCgstRate() {}, getSgstRate() {}",
|
|
|
1400 |
itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate(),
|
|
|
1401 |
itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
| 24542 |
amit.gupta |
1402 |
}
|
|
|
1403 |
}
|
|
|
1404 |
}
|
| 24548 |
amit.gupta |
1405 |
|
| 24542 |
amit.gupta |
1406 |
}
|
|
|
1407 |
|
| 24580 |
amit.gupta |
1408 |
public void schemewalletmismatch() {
|
|
|
1409 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
| 24587 |
amit.gupta |
1410 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
| 24580 |
amit.gupta |
1411 |
reconcileSchemes(dateToReconcile);
|
| 24587 |
amit.gupta |
1412 |
// reconcileOrders(dateTime);
|
|
|
1413 |
// reconcileRecharges(dateTime);
|
| 24580 |
amit.gupta |
1414 |
dateToReconcile = dateToReconcile.plusDays(1);
|
|
|
1415 |
}
|
|
|
1416 |
}
|
|
|
1417 |
|
|
|
1418 |
private void reconcileSchemes(LocalDate date) {
|
|
|
1419 |
LocalDateTime startDate = date.atStartOfDay();
|
|
|
1420 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
1421 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
|
|
1422 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
| 24587 |
amit.gupta |
1423 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1424 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 24580 |
amit.gupta |
1425 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
| 24587 |
amit.gupta |
1426 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
|
|
1427 |
WalletReferenceType.SCHEME_OUT);
|
|
|
1428 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
1429 |
walletReferenceTypes);
|
|
|
1430 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1431 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
| 24580 |
amit.gupta |
1432 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
| 24587 |
amit.gupta |
1433 |
|
|
|
1434 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
|
|
1435 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1436 |
|
|
|
1437 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
|
|
1438 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1439 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
|
|
1440 |
|
|
|
1441 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
|
|
1442 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1443 |
|
|
|
1444 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
|
|
1445 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
|
|
1446 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1447 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
|
|
1448 |
|
|
|
1449 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
| 26092 |
amit.gupta |
1450 |
|
| 24587 |
amit.gupta |
1451 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
|
|
1452 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
|
|
1453 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
|
|
1454 |
} else {
|
|
|
1455 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
|
|
1456 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
|
|
1457 |
}
|
|
|
1458 |
}
|
| 24590 |
amit.gupta |
1459 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
|
|
1460 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
|
|
1461 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1462 |
|
| 24587 |
amit.gupta |
1463 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
|
|
1464 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
|
|
1465 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
|
|
1466 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
|
|
1467 |
if (diff > 5) {
|
|
|
1468 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
|
|
1469 |
}
|
|
|
1470 |
}
|
| 24580 |
amit.gupta |
1471 |
}
|
| 24587 |
amit.gupta |
1472 |
|
| 24580 |
amit.gupta |
1473 |
}
|
| 24590 |
amit.gupta |
1474 |
|
| 24592 |
amit.gupta |
1475 |
public void dryRunSchemeReco() throws Exception {
|
| 24635 |
amit.gupta |
1476 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1477 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1478 |
|
| 24592 |
amit.gupta |
1479 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1480 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24635 |
amit.gupta |
1481 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1482 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1483 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
|
|
1484 |
|
| 25096 |
amit.gupta |
1485 |
LocalDateTime startDate = LocalDate.of(2018, 3, 1).atStartOfDay();
|
| 24635 |
amit.gupta |
1486 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
|
|
1487 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
1488 |
|
| 24683 |
amit.gupta |
1489 |
Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
|
| 24635 |
amit.gupta |
1490 |
purchases.stream().forEach(purchase -> {
|
|
|
1491 |
float amountToRollback = 0;
|
|
|
1492 |
String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
|
|
|
1493 |
+ purchase.getPurchaseReference();
|
|
|
1494 |
Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
|
|
|
1495 |
.stream().filter(ii -> ii.getSerialNumber() != null)
|
|
|
1496 |
.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
|
|
|
1497 |
if (inventorySerialNumberMap.size() > 0) {
|
|
|
1498 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1499 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1500 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1501 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1502 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1503 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1504 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1505 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1506 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1507 |
.collect(Collectors.toList());
|
|
|
1508 |
Collections.reverse(sios);
|
|
|
1509 |
for (SchemeInOut sio : sios) {
|
|
|
1510 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1511 |
amountToRollback += sio.getAmount();
|
|
|
1512 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1513 |
sio.setSerialNumber(serialNumber);
|
|
|
1514 |
rolledbackSios.add(sio);
|
|
|
1515 |
}
|
|
|
1516 |
description = description.concat(" " + serialNumber + " ");
|
|
|
1517 |
} else {
|
|
|
1518 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1519 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1520 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1521 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1522 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1523 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1524 |
.collect(Collectors.toList());
|
|
|
1525 |
Collections.reverse(sios);
|
|
|
1526 |
for (SchemeInOut sio : sios) {
|
|
|
1527 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1528 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1529 |
continue;
|
|
|
1530 |
}
|
|
|
1531 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1532 |
amountToRollback += sio.getAmount();
|
|
|
1533 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1534 |
sio.setSerialNumber(serialNumber);
|
| 24681 |
amit.gupta |
1535 |
sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
|
|
1536 |
sio.setReference(purchase.getId());
|
| 24635 |
amit.gupta |
1537 |
rolledbackSios.add(sio);
|
|
|
1538 |
}
|
|
|
1539 |
}
|
|
|
1540 |
|
|
|
1541 |
}
|
|
|
1542 |
}
|
|
|
1543 |
if (amountToRollback > 0) {
|
| 24683 |
amit.gupta |
1544 |
// Address address =
|
|
|
1545 |
// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
|
| 24635 |
amit.gupta |
1546 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1547 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1548 |
uwh.setDescription(description);
|
|
|
1549 |
uwh.setTimestamp(LocalDateTime.now());
|
| 24681 |
amit.gupta |
1550 |
uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
|
| 24635 |
amit.gupta |
1551 |
uwh.setReference(purchase.getId());
|
|
|
1552 |
uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
|
|
|
1553 |
uwh.setFofoId(purchase.getFofoId());
|
| 24681 |
amit.gupta |
1554 |
uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
| 24635 |
amit.gupta |
1555 |
userWalletHistory.add(uwh);
|
|
|
1556 |
}
|
|
|
1557 |
});
|
|
|
1558 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1559 |
Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
|
|
1560 |
"Timestamp"),
|
|
|
1561 |
userWalletHistory.stream()
|
|
|
1562 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1563 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
|
|
1564 |
.collect(Collectors.toList()));
|
|
|
1565 |
|
|
|
1566 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 24683 |
amit.gupta |
1567 |
Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
|
|
|
1568 |
"Created", "Rolledback"),
|
| 24635 |
amit.gupta |
1569 |
rolledbackSios.stream()
|
| 24681 |
amit.gupta |
1570 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
|
| 24635 |
amit.gupta |
1571 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1572 |
.collect(Collectors.toList()));
|
|
|
1573 |
|
| 30752 |
tejbeer |
1574 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24636 |
amit.gupta |
1575 |
"Partner Excess Amount Scheme In", "PFA",
|
| 30752 |
tejbeer |
1576 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1577 |
new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24635 |
amit.gupta |
1578 |
|
| 25096 |
amit.gupta |
1579 |
throw new Exception();
|
| 24635 |
amit.gupta |
1580 |
|
|
|
1581 |
}
|
|
|
1582 |
|
|
|
1583 |
public void dryRunOutSchemeReco() throws Exception {
|
|
|
1584 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1585 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24606 |
amit.gupta |
1586 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1587 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 24590 |
amit.gupta |
1588 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1589 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 25028 |
amit.gupta |
1590 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
| 24632 |
amit.gupta |
1591 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
| 24631 |
amit.gupta |
1592 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
1593 |
// Collections.reverse(allOrders);
|
|
|
1594 |
// List<FofoOrder> allOrders =
|
| 24653 |
govind |
1595 |
// List<FofoOrder> allOrders =
|
| 24631 |
amit.gupta |
1596 |
// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
|
| 24625 |
amit.gupta |
1597 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
| 24590 |
amit.gupta |
1598 |
allOrders.stream().forEach(fofoOrder -> {
|
| 24592 |
amit.gupta |
1599 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 24598 |
amit.gupta |
1600 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
| 24592 |
amit.gupta |
1601 |
float amountToRollback = 0;
|
| 24590 |
amit.gupta |
1602 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1603 |
orderItems.forEach(x -> {
|
| 24606 |
amit.gupta |
1604 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
| 24598 |
amit.gupta |
1605 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
| 24590 |
amit.gupta |
1606 |
});
|
| 24606 |
amit.gupta |
1607 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24631 |
amit.gupta |
1608 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1609 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1610 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1611 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1612 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1613 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1614 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1615 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1616 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1617 |
.collect(Collectors.toList());
|
|
|
1618 |
Collections.reverse(sios);
|
|
|
1619 |
for (SchemeInOut sio : sios) {
|
|
|
1620 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1621 |
amountToRollback += sio.getAmount();
|
|
|
1622 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1623 |
sio.setSerialNumber(serialNumber);
|
|
|
1624 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 24681 |
amit.gupta |
1625 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1626 |
rolledbackSios.add(sio);
|
| 24623 |
amit.gupta |
1627 |
}
|
| 24635 |
amit.gupta |
1628 |
description = description.concat(" " + serialNumber + " ");
|
| 24631 |
amit.gupta |
1629 |
} else {
|
|
|
1630 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1631 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1632 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1633 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1634 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1635 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1636 |
.collect(Collectors.toList());
|
|
|
1637 |
Collections.reverse(sios);
|
|
|
1638 |
for (SchemeInOut sio : sios) {
|
|
|
1639 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1640 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1641 |
continue;
|
|
|
1642 |
}
|
|
|
1643 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1644 |
amountToRollback += sio.getAmount();
|
|
|
1645 |
// sio.setSchemeType(SchemeType.OUT);
|
| 24681 |
amit.gupta |
1646 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1647 |
sio.setSerialNumber(serialNumber);
|
|
|
1648 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1649 |
rolledbackSios.add(sio);
|
|
|
1650 |
}
|
| 24615 |
amit.gupta |
1651 |
}
|
| 24631 |
amit.gupta |
1652 |
|
| 24604 |
amit.gupta |
1653 |
}
|
| 24590 |
amit.gupta |
1654 |
}
|
| 24631 |
amit.gupta |
1655 |
if (amountToRollback > 0) {
|
|
|
1656 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1657 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1658 |
uwh.setDescription(description);
|
|
|
1659 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1660 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1661 |
uwh.setReference(fofoOrder.getId());
|
|
|
1662 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1663 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1664 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1665 |
userWalletHistory.add(uwh);
|
|
|
1666 |
}
|
| 24590 |
amit.gupta |
1667 |
});
|
| 24598 |
amit.gupta |
1668 |
|
| 24592 |
amit.gupta |
1669 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 24681 |
amit.gupta |
1670 |
Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
| 24615 |
amit.gupta |
1671 |
"Timestamp"),
|
|
|
1672 |
userWalletHistory.stream()
|
|
|
1673 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1674 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24592 |
amit.gupta |
1675 |
.collect(Collectors.toList()));
|
|
|
1676 |
|
|
|
1677 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1678 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1679 |
"Rolledback"),
|
|
|
1680 |
rolledbackSios.stream()
|
|
|
1681 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1682 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1683 |
.collect(Collectors.toList()));
|
|
|
1684 |
|
| 30752 |
tejbeer |
1685 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24681 |
amit.gupta |
1686 |
"Partner Excess Amount Scheme Out", "PFA",
|
| 30752 |
tejbeer |
1687 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1688 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1689 |
|
| 25267 |
amit.gupta |
1690 |
throw new Exception();
|
| 24590 |
amit.gupta |
1691 |
}
|
| 24615 |
amit.gupta |
1692 |
|
| 24611 |
amit.gupta |
1693 |
public void dryRunSchemeOutReco1() throws Exception {
|
| 24615 |
amit.gupta |
1694 |
List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
|
| 24611 |
amit.gupta |
1695 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1696 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
|
|
1697 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1698 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1699 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1700 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1701 |
references.stream().forEach(reference -> {
|
|
|
1702 |
FofoOrder fofoOrder = null;
|
|
|
1703 |
try {
|
|
|
1704 |
fofoOrder = fofoOrderRepository.selectByOrderId(reference);
|
| 24615 |
amit.gupta |
1705 |
} catch (Exception e) {
|
|
|
1706 |
|
| 24611 |
amit.gupta |
1707 |
}
|
|
|
1708 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
|
|
1709 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
|
|
1710 |
float amountToRollback = 0;
|
|
|
1711 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1712 |
orderItems.forEach(x -> {
|
|
|
1713 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
|
|
1714 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
|
|
1715 |
});
|
|
|
1716 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24615 |
amit.gupta |
1717 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1718 |
.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
|
|
|
1719 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24611 |
amit.gupta |
1720 |
.collect(Collectors.toList());
|
|
|
1721 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
|
|
1722 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 24615 |
amit.gupta |
1723 |
Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
|
|
|
1724 |
.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
|
| 24611 |
amit.gupta |
1725 |
for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
|
|
|
1726 |
List<SchemeInOut> outList = inventorySioEntry.getValue();
|
| 24615 |
amit.gupta |
1727 |
if (outList.size() > 1) {
|
|
|
1728 |
|
| 24611 |
amit.gupta |
1729 |
}
|
|
|
1730 |
}
|
|
|
1731 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1732 |
uwh.setDescription(description);
|
|
|
1733 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1734 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1735 |
uwh.setReference(fofoOrder.getId());
|
|
|
1736 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1737 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1738 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1739 |
userWalletHistory.add(uwh);
|
|
|
1740 |
}
|
|
|
1741 |
});
|
| 24615 |
amit.gupta |
1742 |
|
| 24611 |
amit.gupta |
1743 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1744 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
|
|
1745 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
| 30752 |
tejbeer |
1746 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24615 |
amit.gupta |
1747 |
.collect(Collectors.toList()));
|
|
|
1748 |
|
| 24611 |
amit.gupta |
1749 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1750 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1751 |
"Rolledback"),
|
|
|
1752 |
rolledbackSios.stream()
|
| 24615 |
amit.gupta |
1753 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1754 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1755 |
.collect(Collectors.toList()));
|
|
|
1756 |
|
| 24623 |
amit.gupta |
1757 |
Utils.sendMailWithAttachments(googleMailSender,
|
| 30752 |
tejbeer |
1758 |
new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
|
| 24611 |
amit.gupta |
1759 |
"Partner Excess Amount", "PFA",
|
| 30752 |
tejbeer |
1760 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1761 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1762 |
|
| 24628 |
amit.gupta |
1763 |
throw new Exception();
|
| 24615 |
amit.gupta |
1764 |
|
| 24611 |
amit.gupta |
1765 |
}
|
| 24615 |
amit.gupta |
1766 |
|
| 26945 |
amit.gupta |
1767 |
public void sendDailySalesNotificationToPartner(Integer fofoIdInt) throws Exception {
|
| 25927 |
amit.gupta |
1768 |
|
| 24653 |
govind |
1769 |
LocalDateTime now = LocalDateTime.now();
|
| 25837 |
amit.gupta |
1770 |
LocalDateTime from = now.with(LocalTime.MIN);
|
| 25925 |
amit.gupta |
1771 |
String timeString = "Today %s";
|
| 25927 |
amit.gupta |
1772 |
// Send yesterday's report
|
| 27007 |
amit.gupta |
1773 |
/*
|
|
|
1774 |
* if (now.getHour() < 13) { timeString = "Yesterday %s"; from =
|
|
|
1775 |
* now.minusDays(1).; now = from.with(LocalTime.MAX);
|
| 30393 |
amit.gupta |
1776 |
*
|
| 27007 |
amit.gupta |
1777 |
* }
|
|
|
1778 |
*/
|
| 24855 |
amit.gupta |
1779 |
List<Integer> fofoIds = null;
|
| 25043 |
amit.gupta |
1780 |
if (fofoIdInt == null) {
|
|
|
1781 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
1782 |
.collect(Collectors.toList());
|
| 24856 |
amit.gupta |
1783 |
} else {
|
| 24855 |
amit.gupta |
1784 |
fofoIds = Arrays.asList(fofoIdInt);
|
|
|
1785 |
}
|
| 25912 |
amit.gupta |
1786 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
| 24683 |
amit.gupta |
1787 |
|
| 25865 |
amit.gupta |
1788 |
Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
|
|
|
1789 |
null);
|
|
|
1790 |
Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
|
| 26945 |
amit.gupta |
1791 |
|
|
|
1792 |
Map<Integer, Double> spPartnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
|
|
1793 |
true);
|
|
|
1794 |
|
|
|
1795 |
Map<Integer, Double> spPartner3DaysOrderValMap = fofoOrderItemRepository
|
|
|
1796 |
.selectSumAmountGroupByRetailer(from.minusDays(3), now, 0, true);
|
| 26941 |
amit.gupta |
1797 |
Map<Integer, Long> spPartnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
|
|
|
1798 |
|
| 26945 |
amit.gupta |
1799 |
Map<Integer, Double> partnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
|
|
1800 |
false);
|
| 26941 |
amit.gupta |
1801 |
Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, false);
|
| 26945 |
amit.gupta |
1802 |
|
| 25865 |
amit.gupta |
1803 |
Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
|
|
|
1804 |
for (int fofoId : fofoIds) {
|
|
|
1805 |
SaleTargetReportModel model = new SaleTargetReportModel();
|
| 25927 |
amit.gupta |
1806 |
model.setInsuranceSale(
|
|
|
1807 |
partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
|
| 25865 |
amit.gupta |
1808 |
model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
|
| 26941 |
amit.gupta |
1809 |
model.setSmartphoneSale(spPartnerOrderValMap.containsKey(fofoId) ? spPartnerOrderValMap.get(fofoId) : 0);
|
|
|
1810 |
model.setSmartphoneQty(spPartnerOrderQtyMap.containsKey(fofoId) ? spPartnerOrderQtyMap.get(fofoId) : 0);
|
|
|
1811 |
model.setTotalSale(partnerOrderValMap.containsKey(fofoId) ? partnerOrderValMap.get(fofoId) : 0);
|
|
|
1812 |
model.setTotalQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
|
| 26945 |
amit.gupta |
1813 |
model.setPast3daysSale(
|
|
|
1814 |
spPartner3DaysOrderValMap.containsKey(fofoId) ? spPartner3DaysOrderValMap.get(fofoId) : 0);
|
| 25880 |
amit.gupta |
1815 |
model.setFofoId(fofoId);
|
| 25865 |
amit.gupta |
1816 |
saleTargetReportModelMap.put(fofoId, model);
|
|
|
1817 |
}
|
| 25880 |
amit.gupta |
1818 |
|
| 26945 |
amit.gupta |
1819 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 24653 |
govind |
1820 |
for (Integer fofoId : fofoIds) {
|
| 25865 |
amit.gupta |
1821 |
SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
|
| 25821 |
amit.gupta |
1822 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1823 |
sendNotificationModel.setCampaignName("Sales update alert");
|
| 25884 |
tejbeer |
1824 |
sendNotificationModel.setTitle("Sale Update");
|
| 25927 |
amit.gupta |
1825 |
sendNotificationModel
|
|
|
1826 |
.setMessage(String.format("Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
|
|
1827 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
|
|
1828 |
String.format(timeString, now.format(timeFormatter))));
|
| 25821 |
amit.gupta |
1829 |
sendNotificationModel.setType("url");
|
| 27206 |
tejbeer |
1830 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 25821 |
amit.gupta |
1831 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
1832 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25872 |
tejbeer |
1833 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
|
|
1834 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 25854 |
amit.gupta |
1835 |
notificationService.sendNotification(sendNotificationModel);
|
| 24653 |
govind |
1836 |
}
|
| 26945 |
amit.gupta |
1837 |
// String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap,
|
|
|
1838 |
// saleTargetReportModelMap);
|
|
|
1839 |
String statewiseSaleReport = this.getStateWiseSales(saleTargetReportModelMap, partnerSalesHeadersMap);
|
| 30752 |
tejbeer |
1840 |
String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "niranjan.kala@smartdukaan.com",
|
|
|
1841 |
"sm@smartdukaan.com" };
|
| 25837 |
amit.gupta |
1842 |
|
| 25912 |
amit.gupta |
1843 |
String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
|
| 26945 |
amit.gupta |
1844 |
// this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc,
|
|
|
1845 |
// subject);
|
|
|
1846 |
this.sendMailOfHtmlFormat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
|
| 24653 |
govind |
1847 |
}
|
|
|
1848 |
|
| 28377 |
tejbeer |
1849 |
public void checkRazorPayPaymentStatus() throws Exception {
|
| 28368 |
tejbeer |
1850 |
List<PendingOrder> pendingOrder = pendingOrderRepository
|
|
|
1851 |
.selectAllByStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PENDING);
|
|
|
1852 |
|
|
|
1853 |
for (PendingOrder po : pendingOrder) {
|
|
|
1854 |
RazorPay razorPay = razorPayRepository.selectByOrdeId(po.getId());
|
| 28377 |
tejbeer |
1855 |
List<PendingOrderItem> poItems = pendingOrderItemRepository.selectByOrderId(po.getId());
|
| 28368 |
tejbeer |
1856 |
|
| 28369 |
tejbeer |
1857 |
LOGGER.info("razorPay" + razorPay);
|
|
|
1858 |
if (razorPay != null) {
|
|
|
1859 |
List<Payment> payments = razorPaymentService.fetchOrderForPayment(razorPay.getRazorOrderId());
|
| 28377 |
tejbeer |
1860 |
|
| 28369 |
tejbeer |
1861 |
if (!payments.isEmpty()) {
|
| 28377 |
tejbeer |
1862 |
List<String> statusList = new ArrayList<>();
|
| 28369 |
tejbeer |
1863 |
for (Payment payment : payments) {
|
| 28368 |
tejbeer |
1864 |
|
| 28377 |
tejbeer |
1865 |
JSONObject jsonObj = new JSONObject(payment.toString());
|
|
|
1866 |
|
|
|
1867 |
String status = jsonObj.getString("status");
|
|
|
1868 |
|
|
|
1869 |
statusList.add(status);
|
|
|
1870 |
|
| 28369 |
tejbeer |
1871 |
}
|
| 28377 |
tejbeer |
1872 |
LOGGER.info("statusList" + statusList);
|
| 28368 |
tejbeer |
1873 |
|
| 28377 |
tejbeer |
1874 |
if (statusList.contains("authorized") || statusList.contains("captured")) {
|
|
|
1875 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
|
|
1876 |
po.setPaidAmount(po.getTotalAmount());
|
|
|
1877 |
for (PendingOrderItem poi : poItems) {
|
|
|
1878 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
|
|
1879 |
}
|
|
|
1880 |
Map<String, Object> emailModel = pendingOrderService.sendCreateOrderMail(po);
|
|
|
1881 |
|
|
|
1882 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(po.getFofoId());
|
|
|
1883 |
Customer customer = customerRepository.selectById(po.getCustomerId());
|
|
|
1884 |
String[] customerEmail = null;
|
|
|
1885 |
if (customer.getEmailId() != null) {
|
| 30752 |
tejbeer |
1886 |
customerEmail = new String[] { customer.getEmailId() };
|
| 28377 |
tejbeer |
1887 |
}
|
|
|
1888 |
List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com",
|
| 28467 |
tejbeer |
1889 |
"tarun.verma@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
|
|
|
1890 |
"tejbeer.kaur@shop2020.in", customRetailer.getEmail());
|
| 28377 |
tejbeer |
1891 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
|
|
1892 |
if (authUserEmails != null) {
|
|
|
1893 |
authUserEmails = new ArrayList<>();
|
|
|
1894 |
}
|
|
|
1895 |
authUserEmails.addAll(bccTo);
|
|
|
1896 |
|
| 28382 |
tejbeer |
1897 |
// emailService.sendMailWithAttachments("Order Created with SmartDukaan",
|
|
|
1898 |
// "order-confirm.vm",
|
|
|
1899 |
// emailModel, customerEmail, null, authUserEmails.toArray(new String[0]));
|
| 28377 |
tejbeer |
1900 |
|
|
|
1901 |
} else if (statusList.contains("refunded") || statusList.contains("failed")) {
|
|
|
1902 |
for (PendingOrderItem poi : poItems) {
|
|
|
1903 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
|
|
1904 |
}
|
|
|
1905 |
|
|
|
1906 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
|
|
1907 |
}
|
|
|
1908 |
|
| 28369 |
tejbeer |
1909 |
}
|
| 28377 |
tejbeer |
1910 |
// LOGGER.info("payment" + payments);
|
| 28369 |
tejbeer |
1911 |
|
|
|
1912 |
}
|
| 28368 |
tejbeer |
1913 |
}
|
|
|
1914 |
}
|
|
|
1915 |
|
| 25865 |
amit.gupta |
1916 |
public static class SaleTargetReportModel {
|
|
|
1917 |
private double totalSale;
|
| 26941 |
amit.gupta |
1918 |
private long totalQty;
|
| 26945 |
amit.gupta |
1919 |
private double past3daysSale;
|
| 25880 |
amit.gupta |
1920 |
private int fofoId;
|
|
|
1921 |
|
|
|
1922 |
public int getFofoId() {
|
|
|
1923 |
return fofoId;
|
|
|
1924 |
}
|
|
|
1925 |
|
|
|
1926 |
public void setFofoId(int fofoId) {
|
|
|
1927 |
this.fofoId = fofoId;
|
|
|
1928 |
}
|
|
|
1929 |
|
| 25865 |
amit.gupta |
1930 |
private double smartphoneSale;
|
|
|
1931 |
private long smartphoneQty;
|
|
|
1932 |
private double insuranceSale;
|
|
|
1933 |
private long insruanceQty;
|
|
|
1934 |
|
| 26941 |
amit.gupta |
1935 |
public long getTotalQty() {
|
|
|
1936 |
return totalQty;
|
|
|
1937 |
}
|
|
|
1938 |
|
|
|
1939 |
public void setTotalQty(long totalQty) {
|
|
|
1940 |
this.totalQty = totalQty;
|
|
|
1941 |
}
|
|
|
1942 |
|
| 26945 |
amit.gupta |
1943 |
public double getPast3daysSale() {
|
|
|
1944 |
return past3daysSale;
|
|
|
1945 |
}
|
|
|
1946 |
|
|
|
1947 |
public void setPast3daysSale(double past3daysSale) {
|
|
|
1948 |
this.past3daysSale = past3daysSale;
|
|
|
1949 |
}
|
|
|
1950 |
|
| 25865 |
amit.gupta |
1951 |
@Override
|
|
|
1952 |
public int hashCode() {
|
|
|
1953 |
final int prime = 31;
|
|
|
1954 |
int result = 1;
|
| 25880 |
amit.gupta |
1955 |
result = prime * result + fofoId;
|
| 25865 |
amit.gupta |
1956 |
result = prime * result + (int) (insruanceQty ^ (insruanceQty >>> 32));
|
|
|
1957 |
long temp;
|
|
|
1958 |
temp = Double.doubleToLongBits(insuranceSale);
|
|
|
1959 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1960 |
result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
|
|
|
1961 |
temp = Double.doubleToLongBits(smartphoneSale);
|
|
|
1962 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
| 26941 |
amit.gupta |
1963 |
result = prime * result + (int) (totalQty ^ (totalQty >>> 32));
|
| 25865 |
amit.gupta |
1964 |
temp = Double.doubleToLongBits(totalSale);
|
|
|
1965 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1966 |
return result;
|
|
|
1967 |
}
|
|
|
1968 |
|
|
|
1969 |
@Override
|
|
|
1970 |
public boolean equals(Object obj) {
|
|
|
1971 |
if (this == obj)
|
|
|
1972 |
return true;
|
|
|
1973 |
if (obj == null)
|
|
|
1974 |
return false;
|
|
|
1975 |
if (getClass() != obj.getClass())
|
|
|
1976 |
return false;
|
|
|
1977 |
SaleTargetReportModel other = (SaleTargetReportModel) obj;
|
| 25880 |
amit.gupta |
1978 |
if (fofoId != other.fofoId)
|
|
|
1979 |
return false;
|
| 25865 |
amit.gupta |
1980 |
if (insruanceQty != other.insruanceQty)
|
|
|
1981 |
return false;
|
|
|
1982 |
if (Double.doubleToLongBits(insuranceSale) != Double.doubleToLongBits(other.insuranceSale))
|
|
|
1983 |
return false;
|
|
|
1984 |
if (smartphoneQty != other.smartphoneQty)
|
|
|
1985 |
return false;
|
|
|
1986 |
if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
|
|
|
1987 |
return false;
|
| 26941 |
amit.gupta |
1988 |
if (totalQty != other.totalQty)
|
|
|
1989 |
return false;
|
| 25865 |
amit.gupta |
1990 |
if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
|
|
|
1991 |
return false;
|
|
|
1992 |
return true;
|
|
|
1993 |
}
|
|
|
1994 |
|
|
|
1995 |
public double getTotalSale() {
|
|
|
1996 |
return totalSale;
|
|
|
1997 |
}
|
|
|
1998 |
|
|
|
1999 |
public void setTotalSale(double totalSale) {
|
|
|
2000 |
this.totalSale = totalSale;
|
|
|
2001 |
}
|
|
|
2002 |
|
|
|
2003 |
public double getSmartphoneSale() {
|
|
|
2004 |
return smartphoneSale;
|
|
|
2005 |
}
|
|
|
2006 |
|
|
|
2007 |
public void setSmartphoneSale(double smartphoneSale) {
|
|
|
2008 |
this.smartphoneSale = smartphoneSale;
|
|
|
2009 |
}
|
|
|
2010 |
|
|
|
2011 |
public long getSmartphoneQty() {
|
|
|
2012 |
return smartphoneQty;
|
|
|
2013 |
}
|
|
|
2014 |
|
|
|
2015 |
public void setSmartphoneQty(long smartphoneQty) {
|
|
|
2016 |
this.smartphoneQty = smartphoneQty;
|
|
|
2017 |
}
|
|
|
2018 |
|
|
|
2019 |
public double getInsuranceSale() {
|
|
|
2020 |
return insuranceSale;
|
|
|
2021 |
}
|
|
|
2022 |
|
|
|
2023 |
public void setInsuranceSale(double insuranceSale) {
|
|
|
2024 |
this.insuranceSale = insuranceSale;
|
|
|
2025 |
}
|
|
|
2026 |
|
|
|
2027 |
public long getInsruanceQty() {
|
|
|
2028 |
return insruanceQty;
|
|
|
2029 |
}
|
|
|
2030 |
|
|
|
2031 |
public void setInsruanceQty(long insruanceQty) {
|
|
|
2032 |
this.insruanceQty = insruanceQty;
|
|
|
2033 |
}
|
|
|
2034 |
|
|
|
2035 |
@Override
|
|
|
2036 |
public String toString() {
|
| 26945 |
amit.gupta |
2037 |
return "SaleTargetReportModel [totalSale=" + totalSale + ", totalQty=" + totalQty + ", past3daysSale="
|
|
|
2038 |
+ past3daysSale + ", fofoId=" + fofoId + ", smartphoneSale=" + smartphoneSale + ", smartphoneQty="
|
|
|
2039 |
+ smartphoneQty + ", insuranceSale=" + insuranceSale + ", insruanceQty=" + insruanceQty + "]";
|
| 25865 |
amit.gupta |
2040 |
}
|
|
|
2041 |
|
|
|
2042 |
}
|
|
|
2043 |
|
| 26945 |
amit.gupta |
2044 |
private String getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap,
|
| 30752 |
tejbeer |
2045 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap) throws Exception {
|
| 26940 |
amit.gupta |
2046 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
| 26945 |
amit.gupta |
2047 |
Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors
|
|
|
2048 |
.groupingBy(x -> x.getCode().substring(0, 2), Collectors.mapping(x -> x.getId(), Collectors.toList())));
|
| 26940 |
amit.gupta |
2049 |
List<List<Serializable>> stateWiseSales = new ArrayList<>();
|
|
|
2050 |
for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
|
| 26945 |
amit.gupta |
2051 |
long totalQty = stateMapEntry.getValue().stream()
|
|
|
2052 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getTotalQty()));
|
|
|
2053 |
double totalSale = stateMapEntry.getValue().stream()
|
|
|
2054 |
.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getTotalSale()));
|
|
|
2055 |
long smartPhoneQty = stateMapEntry.getValue().stream()
|
|
|
2056 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getSmartphoneQty()));
|
|
|
2057 |
double smartPhoneSale = stateMapEntry.getValue().stream()
|
|
|
2058 |
.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getSmartphoneSale()));
|
|
|
2059 |
stateWiseSales
|
|
|
2060 |
.add(Arrays.asList(stateMapEntry.getKey(), smartPhoneQty, smartPhoneSale, totalQty, totalSale));
|
| 26940 |
amit.gupta |
2061 |
}
|
|
|
2062 |
StringBuilder sb = new StringBuilder();
|
| 26945 |
amit.gupta |
2063 |
sb.append("<html><body>");
|
|
|
2064 |
sb.append("<p>Statewise Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 26940 |
amit.gupta |
2065 |
sb.append("<tbody>\n" + " <tr>"
|
|
|
2066 |
+ " <th style='border:1px solid black;padding: 5px'>State</th>"
|
| 26941 |
amit.gupta |
2067 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
|
|
2068 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Value</th>"
|
|
|
2069 |
+ " <th style='border:1px solid black;padding: 5px'>Total Qty</th>"
|
|
|
2070 |
+ " <th style='border:1px solid black;padding: 5px'>Total Value</th>"
|
| 26940 |
amit.gupta |
2071 |
+ " </tr>");
|
|
|
2072 |
for (List<Serializable> stateSale : stateWiseSales) {
|
|
|
2073 |
sb.append("<tr>");
|
|
|
2074 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(0) + "</td>");
|
|
|
2075 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(1) + "</td>");
|
|
|
2076 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
|
| 26941 |
amit.gupta |
2077 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(3) + "</td>");
|
|
|
2078 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(4) + "</td>");
|
| 26940 |
amit.gupta |
2079 |
sb.append("</tr>");
|
|
|
2080 |
}
|
| 26945 |
amit.gupta |
2081 |
sb.append("</tbody></table><br><br>");
|
| 25872 |
tejbeer |
2082 |
|
| 26945 |
amit.gupta |
2083 |
sb.append("<p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 24653 |
govind |
2084 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 26945 |
amit.gupta |
2085 |
+ " <th style='border:1px solid black;padding: 5px'>Code</th>"
|
|
|
2086 |
+ " <th style='border:1px solid black;padding: 5px'>Business Name</th>"
|
|
|
2087 |
+ " <th style='border:1px solid black;padding: 5px'>Regional Manager</th>"
|
|
|
2088 |
+ " <th style='border:1px solid black;padding: 5px'>Territory Manager</th>"
|
|
|
2089 |
+ " <th style='border:1px solid black;padding: 5px'>Sale</th>"
|
|
|
2090 |
+ " <th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>"
|
|
|
2091 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
| 24653 |
govind |
2092 |
+ " </tr>");
|
| 26945 |
amit.gupta |
2093 |
|
| 30765 |
tejbeer |
2094 |
/*
|
|
|
2095 |
* List<Integer> sortedPartnerSalesHeaders =
|
|
|
2096 |
* partnerSalesHeadersMap.values().stream()
|
|
|
2097 |
* .sorted(Comparator.comparing(FofoReportingModel::getCode)
|
|
|
2098 |
* .thenComparing(FofoReportingModel::getRegionalManager)
|
|
|
2099 |
* .thenComparing(FofoReportingModel::getTerritoryManager))
|
|
|
2100 |
* .map(FofoReportingModel::getFofoId).collect(Collectors.toList());
|
|
|
2101 |
*/
|
|
|
2102 |
|
|
|
2103 |
List<Integer> sortedSaleTargetReport = saleTargetReportModelMap.values().stream()
|
|
|
2104 |
.sorted(Comparator.comparing(SaleTargetReportModel::getTotalSale)).map(SaleTargetReportModel::getFofoId)
|
|
|
2105 |
.collect(Collectors.toList());
|
|
|
2106 |
for (Integer fofoId : sortedSaleTargetReport) {
|
| 27007 |
amit.gupta |
2107 |
if (saleTargetReportModelMap.get(fofoId).getPast3daysSale() == 0) {
|
| 26947 |
amit.gupta |
2108 |
sb.append("<tr style='background-color:red'>");
|
|
|
2109 |
} else {
|
| 26945 |
amit.gupta |
2110 |
sb.append("<tr>");
|
|
|
2111 |
}
|
|
|
2112 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).getCode()
|
| 25880 |
amit.gupta |
2113 |
+ "</td>");
|
|
|
2114 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 27007 |
amit.gupta |
2115 |
+ partnerSalesHeadersMap.get(fofoId).getBusinessName() + "</td>");
|
|
|
2116 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2117 |
+ partnerSalesHeadersMap.get(fofoId).getRegionalManager() + "</td>");
|
|
|
2118 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2119 |
+ partnerSalesHeadersMap.get(fofoId).getTerritoryManager() + "</td>");
|
|
|
2120 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 26945 |
amit.gupta |
2121 |
+ saleTargetReportModelMap.get(fofoId).getTotalSale() + "</td>");
|
| 25880 |
amit.gupta |
2122 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 26945 |
amit.gupta |
2123 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneSale() + "</td>");
|
| 25880 |
amit.gupta |
2124 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 26945 |
amit.gupta |
2125 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneQty() + "</td>");
|
| 25865 |
amit.gupta |
2126 |
sb.append("</tr>");
|
| 24653 |
govind |
2127 |
}
|
| 24683 |
amit.gupta |
2128 |
|
| 26945 |
amit.gupta |
2129 |
sb.append("</tr>");
|
|
|
2130 |
|
|
|
2131 |
sb.append("</body></html>");
|
|
|
2132 |
|
|
|
2133 |
return sb.toString();
|
| 24653 |
govind |
2134 |
}
|
| 24841 |
govind |
2135 |
|
| 26945 |
amit.gupta |
2136 |
private void sendMailOfHtmlFormat(String email, String body, String cc[], String subject)
|
| 24841 |
govind |
2137 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
2138 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
2139 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
2140 |
helper.setSubject(subject);
|
|
|
2141 |
helper.setText(body, true);
|
|
|
2142 |
helper.setTo(email);
|
|
|
2143 |
if (cc != null) {
|
|
|
2144 |
helper.setCc(cc);
|
|
|
2145 |
}
|
|
|
2146 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
2147 |
helper.setFrom(senderAddress);
|
|
|
2148 |
mailSender.send(message);
|
|
|
2149 |
}
|
| 25300 |
tejbeer |
2150 |
|
| 25351 |
tejbeer |
2151 |
public void sendNotification() throws Exception {
|
| 25300 |
tejbeer |
2152 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
|
|
2153 |
if (!pushNotifications.isEmpty()) {
|
|
|
2154 |
for (PushNotifications pushNotification : pushNotifications) {
|
| 25351 |
tejbeer |
2155 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
| 25300 |
tejbeer |
2156 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
|
|
2157 |
.selectById(pushNotification.getNotificationCampaignid());
|
|
|
2158 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
2159 |
SimpleCampaignParams.class);
|
|
|
2160 |
Campaign campaign = new SimpleCampaign(scp);
|
| 25351 |
tejbeer |
2161 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
| 25300 |
tejbeer |
2162 |
JSONObject json = new JSONObject();
|
| 25351 |
tejbeer |
2163 |
json.put("to", device.getFcmId());
|
| 25300 |
tejbeer |
2164 |
JSONObject jsonObj = new JSONObject();
|
|
|
2165 |
jsonObj.put("message", campaign.getMessage());
|
|
|
2166 |
jsonObj.put("title", campaign.getTitle());
|
|
|
2167 |
jsonObj.put("type", campaign.getType());
|
|
|
2168 |
jsonObj.put("url", result_url);
|
|
|
2169 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
|
|
2170 |
jsonObj.put("image", campaign.getImageUrl());
|
|
|
2171 |
jsonObj.put("largeIcon", "large_icon");
|
|
|
2172 |
jsonObj.put("smallIcon", "small_icon");
|
|
|
2173 |
jsonObj.put("vibrate", 1);
|
|
|
2174 |
jsonObj.put("pid", pushNotification.getId());
|
|
|
2175 |
jsonObj.put("sound", 1);
|
|
|
2176 |
jsonObj.put("priority", "high");
|
|
|
2177 |
json.put("data", jsonObj);
|
| 25351 |
tejbeer |
2178 |
try {
|
|
|
2179 |
CloseableHttpClient client = HttpClients.createDefault();
|
|
|
2180 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| 25300 |
tejbeer |
2181 |
|
| 25351 |
tejbeer |
2182 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
|
|
2183 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
|
|
2184 |
StringEntity entity = new StringEntity(json.toString());
|
|
|
2185 |
httpPost.setEntity(entity);
|
|
|
2186 |
CloseableHttpResponse response = client.execute(httpPost);
|
| 25300 |
tejbeer |
2187 |
|
| 25351 |
tejbeer |
2188 |
if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
2189 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
|
|
2190 |
} else {
|
| 25356 |
tejbeer |
2191 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 25778 |
amit.gupta |
2192 |
LOGGER.info("message" + "not sent");
|
| 26945 |
amit.gupta |
2193 |
response.toString();
|
| 25351 |
tejbeer |
2194 |
}
|
| 25300 |
tejbeer |
2195 |
|
| 25351 |
tejbeer |
2196 |
} catch (Exception e) {
|
|
|
2197 |
e.printStackTrace();
|
| 26443 |
amit.gupta |
2198 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 26436 |
amit.gupta |
2199 |
LOGGER.info("message " + "not sent " + e.getMessage());
|
| 25300 |
tejbeer |
2200 |
}
|
|
|
2201 |
}
|
|
|
2202 |
}
|
|
|
2203 |
}
|
|
|
2204 |
|
| 25553 |
amit.gupta |
2205 |
public void grouping() throws Exception {
|
| 25609 |
amit.gupta |
2206 |
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM-dd-yyyy hh:mm");
|
|
|
2207 |
List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByStatus(PriceDropImeiStatus.APPROVED);
|
|
|
2208 |
System.out.println(String.join("\t",
|
|
|
2209 |
Arrays.asList("IMEI", "ItemId", "Brand", "Model Name", "Model Number", "Franchise Id", "Franchise Name",
|
| 25694 |
amit.gupta |
2210 |
"Grn On", "Price Dropped On", "Approved On", "Returned On", "Price Drop Paid", "Is Doa")));
|
| 26963 |
amit.gupta |
2211 |
Map<Integer, CustomRetailer> retailersMap = retailerService.getFofoRetailers(false);
|
| 25609 |
amit.gupta |
2212 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
| 25694 |
amit.gupta |
2213 |
if (priceDropIMEI.getPartnerId() == 0)
|
|
|
2214 |
continue;
|
| 25609 |
amit.gupta |
2215 |
HashSet<String> imeis = new HashSet<>();
|
|
|
2216 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropIMEI.getPriceDropId());
|
|
|
2217 |
imeis.add(priceDropIMEI.getImei());
|
|
|
2218 |
List<InventoryItem> inventoryItems = inventoryItemRepository
|
|
|
2219 |
.selectByFofoIdSerialNumbers(priceDropIMEI.getPartnerId(), imeis, false);
|
| 25694 |
amit.gupta |
2220 |
if (inventoryItems.size() == 0) {
|
|
|
2221 |
LOGGER.info("Need to investigate partnerId - {} imeis - {}", priceDropIMEI.getPartnerId(), imeis);
|
| 25613 |
amit.gupta |
2222 |
continue;
|
| 25612 |
amit.gupta |
2223 |
}
|
| 25609 |
amit.gupta |
2224 |
InventoryItem inventoryItem = inventoryItems.get(0);
|
|
|
2225 |
CustomRetailer customRetailer = retailersMap.get(inventoryItem.getFofoId());
|
|
|
2226 |
if (inventoryItem.getLastScanType().equals(ScanType.DOA_OUT)
|
|
|
2227 |
|| inventoryItem.getLastScanType().equals(ScanType.PURCHASE_RET)) {
|
|
|
2228 |
// check if pricedrop has been rolled out
|
|
|
2229 |
List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
|
|
|
2230 |
priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
|
|
|
2231 |
if (uwh.size() > 0) {
|
| 25615 |
amit.gupta |
2232 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 26945 |
amit.gupta |
2233 |
System.out.println(String.join("\t", Arrays.asList(priceDropIMEI.getImei(),
|
|
|
2234 |
inventoryItem.getItemId() + "", item.getBrand(), item.getModelName(), item.getModelNumber(),
|
|
|
2235 |
inventoryItem.getFofoId() + "", customRetailer.getBusinessName(),
|
|
|
2236 |
inventoryItem.getCreateTimestamp().format(dtf), priceDrop.getAffectedOn().format(dtf),
|
|
|
2237 |
priceDropIMEI.getUpdateTimestamp().format(dtf),
|
|
|
2238 |
inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
|
|
|
2239 |
inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
|
| 25609 |
amit.gupta |
2240 |
}
|
|
|
2241 |
}
|
|
|
2242 |
}
|
| 25503 |
amit.gupta |
2243 |
}
|
| 29668 |
tejbeer |
2244 |
|
| 29566 |
amit.gupta |
2245 |
public void toffeeRollback() throws Exception {
|
|
|
2246 |
toffeeService.cancelPolicyCopy("110143521986");
|
|
|
2247 |
toffeeService.getOrderId("110143521986");
|
|
|
2248 |
}
|
| 25694 |
amit.gupta |
2249 |
|
| 27686 |
amit.gupta |
2250 |
public void attachToffeeInvoices() throws Exception {
|
| 28205 |
tejbeer |
2251 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(3,
|
|
|
2252 |
Optional.of(false));
|
|
|
2253 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 27678 |
amit.gupta |
2254 |
String invoiceNumber = insurancePolicy.getInvoiceNumber();
|
|
|
2255 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 30321 |
amit.gupta |
2256 |
InvoicePdfModel pdfModel = orderService.getInvoicePdfModel(fofoOrder.getId());
|
| 27678 |
amit.gupta |
2257 |
java.io.ByteArrayOutputStream byteArrayOutputStream = new java.io.ByteArrayOutputStream();
|
|
|
2258 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
| 28205 |
tejbeer |
2259 |
String pdfInvoiceString = "data:application/pdf;base64,"
|
|
|
2260 |
+ Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray());
|
|
|
2261 |
boolean attached = toffeeService.attachInvoice(insurancePolicy.getPolicyNumber().split("#")[1],
|
|
|
2262 |
pdfInvoiceString);
|
|
|
2263 |
if (attached) {
|
| 27678 |
amit.gupta |
2264 |
insurancePolicy.setPosted(true);
|
|
|
2265 |
}
|
|
|
2266 |
}
|
| 25694 |
amit.gupta |
2267 |
}
|
|
|
2268 |
|
| 30858 |
amit.gupta |
2269 |
public void sendBAGPendingPolicies() throws Exception {
|
|
|
2270 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(4,
|
|
|
2271 |
Optional.of(false));
|
|
|
2272 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
|
|
2273 |
String invoiceNumber = insurancePolicy.getInvoiceNumber();
|
|
|
2274 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
|
|
2275 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId()).get(0);
|
|
|
2276 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
2277 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
2278 |
BAGInsuranceModel bagInsuranceModel = new BAGInsuranceModel();
|
| 30913 |
tejbeer |
2279 |
// bagInsuranceModel.setModelId();
|
| 30858 |
amit.gupta |
2280 |
bagInsuranceModel.setAddressLine1(customerAddress.getLine1());
|
|
|
2281 |
bagInsuranceModel.setAddressLine2(customerAddress.getLine2());
|
|
|
2282 |
bagInsuranceModel.setCity(customerAddress.getCity());
|
|
|
2283 |
bagInsuranceModel.setBrandWarranty("1 Year");
|
|
|
2284 |
Item item = itemRepository.selectById(fofoOrderItem.getId());
|
|
|
2285 |
bagInsuranceModel.setModelName(item.getItemDescription());
|
|
|
2286 |
bagInsuranceModel.setDateOfPurchase(fofoOrder.getFormattedDate());
|
|
|
2287 |
bagInsuranceModel.setEmail(customer.getEmailId());
|
|
|
2288 |
bagInsuranceModel.setImei1(insurancePolicy.getSerialNumber());
|
|
|
2289 |
bagInsuranceModel.setFirstName(customer.getFirstName());
|
|
|
2290 |
bagInsuranceModel.setLastName(customer.getLastName());
|
|
|
2291 |
bagInsuranceModel.setMobileNumber(customer.getMobileNumber());
|
|
|
2292 |
bagInsuranceModel.setPlanId("");
|
|
|
2293 |
insurancePolicy.setPosted(true);
|
|
|
2294 |
}
|
|
|
2295 |
}
|
|
|
2296 |
|
| 25694 |
amit.gupta |
2297 |
public void schemeRollback(List<String> schemeIds) throws Exception {
|
|
|
2298 |
List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
|
| 25708 |
amit.gupta |
2299 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()
|
| 25694 |
amit.gupta |
2300 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
2301 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIdsInt));
|
|
|
2302 |
for (SchemeInOut sio : schemeInOuts) {
|
|
|
2303 |
Scheme scheme = schemesMap.get(sio.getSchemeId());
|
|
|
2304 |
if (scheme.getType().equals(SchemeType.IN)) {
|
|
|
2305 |
|
|
|
2306 |
} else if (scheme.getType().equals(SchemeType.OUT)) {
|
|
|
2307 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
|
|
2308 |
List<ScanRecord> sr = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId());
|
|
|
2309 |
ScanRecord scanRecord = sr.stream().filter(x -> x.getType().equals(ScanType.SALE))
|
|
|
2310 |
.max((x1, x2) -> x1.getCreateTimestamp().compareTo(x2.getCreateTimestamp())).get();
|
|
|
2311 |
if (scanRecord.getCreateTimestamp().isAfter(scheme.getEndDateTime())
|
|
|
2312 |
|| scanRecord.getCreateTimestamp().isBefore(scheme.getStartDateTime())) {
|
|
|
2313 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
2314 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
|
| 25709 |
amit.gupta |
2315 |
String rollbackReason = "Scheme reversed for "
|
|
|
2316 |
+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
|
| 25694 |
amit.gupta |
2317 |
+ fofoOrder.getInvoiceNumber();
|
|
|
2318 |
walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
|
| 26945 |
amit.gupta |
2319 |
scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason,
|
|
|
2320 |
LocalDateTime.now());
|
| 25694 |
amit.gupta |
2321 |
System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
|
|
|
2322 |
rollbackReason);
|
|
|
2323 |
}
|
|
|
2324 |
}
|
|
|
2325 |
}
|
| 25721 |
tejbeer |
2326 |
// throw new Exception();
|
| 25694 |
amit.gupta |
2327 |
}
|
| 25721 |
tejbeer |
2328 |
|
|
|
2329 |
public void checkfocusedModelInPartnerStock() throws Exception {
|
|
|
2330 |
|
|
|
2331 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
2332 |
.collect(Collectors.toList());
|
| 27212 |
tejbeer |
2333 |
Map<Integer, Map<Integer, List<SaholicCIS>>> warehouseItemAvailabilityMap = saholicInventoryService
|
|
|
2334 |
.getSaholicStock();
|
| 27213 |
tejbeer |
2335 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
|
|
2336 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 27212 |
tejbeer |
2337 |
|
|
|
2338 |
Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap = saholicInventoryService
|
|
|
2339 |
.getSaholicPOItems();
|
| 25721 |
tejbeer |
2340 |
Map<Integer, List<FocusedModelShortageModel>> focusedModelShortageReportMap = new HashMap<>();
|
|
|
2341 |
for (Integer fofoId : fofoIds) {
|
| 27102 |
amit.gupta |
2342 |
List<FocusedModelShortageModel> focusedModelShortageList = new ArrayList<>();
|
|
|
2343 |
focusedModelShortageReportMap.put(fofoId, focusedModelShortageList);
|
| 25721 |
tejbeer |
2344 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
2345 |
Map<Integer, Integer> processingOrderMap = null;
|
|
|
2346 |
Map<Integer, Integer> catalogIdAndQtyMap = null;
|
|
|
2347 |
Map<Integer, Integer> grnPendingOrdersMap = null;
|
|
|
2348 |
|
|
|
2349 |
Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
|
|
|
2350 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
2351 |
|
|
|
2352 |
if (!currentInventorySnapshot.isEmpty()) {
|
|
|
2353 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
|
|
2354 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
2355 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
|
|
2356 |
|
|
|
2357 |
}
|
|
|
2358 |
|
|
|
2359 |
Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
|
|
2360 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
2361 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
2362 |
if (!grnPendingOrders.isEmpty()) {
|
|
|
2363 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
|
|
2364 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
2365 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
|
|
2366 |
|
|
|
2367 |
}
|
|
|
2368 |
|
|
|
2369 |
Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
|
|
|
2370 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
2371 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
2372 |
if (!processingOrder.isEmpty()) {
|
|
|
2373 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
|
|
2374 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
2375 |
Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
|
|
2376 |
|
|
|
2377 |
}
|
|
|
2378 |
|
| 25800 |
tejbeer |
2379 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
2380 |
.collect(Collectors.toList());
|
|
|
2381 |
|
| 27088 |
tejbeer |
2382 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
|
|
2383 |
.collect(Collectors.toList());
|
| 27095 |
tejbeer |
2384 |
LOGGER.info("regionIds" + regionIds);
|
| 27102 |
amit.gupta |
2385 |
if (regionIds.size() == 0) {
|
|
|
2386 |
LOGGER.info("No region found for partner {}", fofoId);
|
|
|
2387 |
continue;
|
|
|
2388 |
}
|
| 27100 |
amit.gupta |
2389 |
Map<Integer, Optional<Integer>> focusedCatalogIdAndQtyMap = focusedModelRepository
|
| 27102 |
amit.gupta |
2390 |
.selectAllByRegionIds(regionIds).stream().collect(Collectors.groupingBy(FocusedModel::getCatalogId,
|
| 29668 |
tejbeer |
2391 |
Collectors.mapping(FocusedModel::getObsMinimumQty, Collectors.maxBy(Integer::compareTo))));
|
| 25800 |
tejbeer |
2392 |
|
| 25721 |
tejbeer |
2393 |
LOGGER.info("focusedCatalogIdAndQtyMap" + focusedCatalogIdAndQtyMap);
|
|
|
2394 |
|
| 27100 |
amit.gupta |
2395 |
for (Map.Entry<Integer, Optional<Integer>> entry : focusedCatalogIdAndQtyMap.entrySet()) {
|
|
|
2396 |
int minQty = entry.getValue().get();
|
| 25721 |
tejbeer |
2397 |
int inStockQty = 0;
|
|
|
2398 |
int processingQty = 0;
|
|
|
2399 |
int grnPendingQty = 0;
|
| 27208 |
tejbeer |
2400 |
int allColorNetAvailability = 0;
|
| 27253 |
tejbeer |
2401 |
int allColorPoAvailability = 0;
|
| 25721 |
tejbeer |
2402 |
if (processingOrderMap != null) {
|
|
|
2403 |
processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
|
|
|
2404 |
: processingOrderMap.get(entry.getKey());
|
|
|
2405 |
|
|
|
2406 |
}
|
|
|
2407 |
if (grnPendingOrdersMap != null) {
|
|
|
2408 |
grnPendingQty = (grnPendingOrdersMap.get(entry.getKey()) == null) ? 0
|
|
|
2409 |
: grnPendingOrdersMap.get(entry.getKey());
|
|
|
2410 |
|
|
|
2411 |
}
|
|
|
2412 |
if (catalogIdAndQtyMap != null) {
|
|
|
2413 |
inStockQty = (catalogIdAndQtyMap.get(entry.getKey()) == null) ? 0
|
|
|
2414 |
: catalogIdAndQtyMap.get(entry.getKey());
|
|
|
2415 |
|
|
|
2416 |
}
|
| 28526 |
tejbeer |
2417 |
|
|
|
2418 |
int grnStockQty = grnPendingQty + inStockQty;
|
| 25721 |
tejbeer |
2419 |
int totalQty = processingQty + grnPendingQty + inStockQty;
|
|
|
2420 |
|
| 29801 |
manish |
2421 |
int shortageQty = minQty - totalQty;
|
|
|
2422 |
List<Item> item = itemRepository.selectAllByCatalogItemId(entry.getKey());
|
|
|
2423 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 25721 |
tejbeer |
2424 |
|
| 29801 |
manish |
2425 |
Map<Integer, List<SaholicCIS>> itemAvailabilityMap = warehouseItemAvailabilityMap
|
|
|
2426 |
.get(fofoStore.getWarehouseId());
|
| 27213 |
tejbeer |
2427 |
|
| 29801 |
manish |
2428 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = warehousePoItemAvailabilityMap
|
|
|
2429 |
.get(fofoStore.getWarehouseId());
|
| 25721 |
tejbeer |
2430 |
|
| 29801 |
manish |
2431 |
for (Item it : item) {
|
|
|
2432 |
List<SaholicCIS> currentAvailability = null;
|
|
|
2433 |
List<SaholicPOItem> poItemAvailability = null;
|
|
|
2434 |
if (itemAvailabilityMap != null) {
|
|
|
2435 |
currentAvailability = itemAvailabilityMap.get(it.getId());
|
|
|
2436 |
}
|
| 27208 |
tejbeer |
2437 |
|
| 29801 |
manish |
2438 |
if (poItemAvailabilityMap != null) {
|
|
|
2439 |
poItemAvailability = poItemAvailabilityMap.get(it.getId());
|
|
|
2440 |
}
|
|
|
2441 |
if (currentAvailability != null) {
|
|
|
2442 |
allColorNetAvailability += currentAvailability.stream()
|
|
|
2443 |
.collect(Collectors.summingInt(SaholicCIS::getNetavailability));
|
|
|
2444 |
}
|
| 28528 |
tejbeer |
2445 |
|
| 29801 |
manish |
2446 |
if (poItemAvailability != null) {
|
|
|
2447 |
allColorPoAvailability += poItemAvailability.stream()
|
|
|
2448 |
.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
|
| 27208 |
tejbeer |
2449 |
}
|
|
|
2450 |
|
| 25721 |
tejbeer |
2451 |
}
|
|
|
2452 |
|
| 29801 |
manish |
2453 |
FocusedModelShortageModel fm = new FocusedModelShortageModel();
|
|
|
2454 |
fm.setFofoId(fofoId);
|
|
|
2455 |
fm.setStoreCode(fofoStore.getCode());
|
|
|
2456 |
fm.setStoreName(customRetailer.getBusinessName());
|
|
|
2457 |
fm.setBrandName(item.get(0).getBrand());
|
|
|
2458 |
fm.setModelName(item.get(0).getModelName());
|
|
|
2459 |
fm.setModelNumber(item.get(0).getModelNumber());
|
|
|
2460 |
fm.setGrnStockQty(grnStockQty);
|
|
|
2461 |
fm.setPendingIndentQty(processingQty);
|
|
|
2462 |
fm.setShortageQty(shortageQty);
|
|
|
2463 |
fm.setPoAvailabitiy(allColorPoAvailability);
|
|
|
2464 |
fm.setWarehouseName(warehouseMap.get(customRetailer.getWarehouseId()));
|
|
|
2465 |
fm.setStateManager(partnerIdSalesHeadersMap.get(fofoId).getRegionalManager());
|
|
|
2466 |
fm.setTerritoryManager(partnerIdSalesHeadersMap.get(fofoId).getTerritoryManager());
|
|
|
2467 |
fm.setItemName(item.get(0).getBrand() + item.get(0).getModelNumber() + item.get(0).getModelName());
|
|
|
2468 |
fm.setAvailabitiy(allColorNetAvailability);
|
| 27233 |
tejbeer |
2469 |
|
| 29801 |
manish |
2470 |
focusedModelShortageList.add(fm);
|
|
|
2471 |
}
|
|
|
2472 |
|
| 29668 |
tejbeer |
2473 |
/*
|
|
|
2474 |
* if (!focusedModelShortageList.isEmpty()) { String subject = "Stock Alert";
|
|
|
2475 |
* String messageText = this.getMessage(focusedModelShortageList);
|
| 30393 |
amit.gupta |
2476 |
*
|
| 29668 |
tejbeer |
2477 |
* this.sendMailWithAttachments(subject, messageText,
|
|
|
2478 |
* customRetailer.getEmail()); String notificationMessage =
|
|
|
2479 |
* this.getNotificationMessage(focusedModelShortageList);
|
| 30393 |
amit.gupta |
2480 |
*
|
| 29668 |
tejbeer |
2481 |
* LOGGER.info("notificationMessage" + notificationMessage);
|
| 30393 |
amit.gupta |
2482 |
*
|
| 29668 |
tejbeer |
2483 |
* SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2484 |
* sendNotificationModel.setCampaignName("Stock Alert");
|
|
|
2485 |
* sendNotificationModel.setTitle("Alert");
|
|
|
2486 |
* sendNotificationModel.setMessage(notificationMessage);
|
|
|
2487 |
* sendNotificationModel.setType("url"); sendNotificationModel.setUrl(
|
|
|
2488 |
* "https://app.smartdukaan.com/pages/home/notifications");
|
|
|
2489 |
* sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2490 |
* sendNotificationModel.setMessageType(MessageType.notification); int userId =
|
|
|
2491 |
* userAccountRepository.selectUserIdByRetailerId(fofoId);
|
|
|
2492 |
* sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
2493 |
* notificationService.sendNotification(sendNotificationModel);
|
| 30393 |
amit.gupta |
2494 |
*
|
| 29668 |
tejbeer |
2495 |
* }
|
|
|
2496 |
*/
|
| 27233 |
tejbeer |
2497 |
|
| 25721 |
tejbeer |
2498 |
}
|
| 27102 |
amit.gupta |
2499 |
if (!focusedModelShortageReportMap.isEmpty()) {
|
| 25800 |
tejbeer |
2500 |
String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 30215 |
amit.gupta |
2501 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 25837 |
amit.gupta |
2502 |
Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
|
| 25721 |
tejbeer |
2503 |
|
| 25800 |
tejbeer |
2504 |
focusedModelShortageReportMap.entrySet().forEach(x -> {
|
|
|
2505 |
storeGuyMap.entrySet().forEach(y -> {
|
|
|
2506 |
|
|
|
2507 |
if (y.getValue().contains(x.getKey())) {
|
|
|
2508 |
if (!emailRowsMap.containsKey(y.getKey())) {
|
|
|
2509 |
emailRowsMap.put(y.getKey(), new ArrayList<>());
|
|
|
2510 |
}
|
| 27208 |
tejbeer |
2511 |
List<List<? extends Serializable>> fms = x.getValue().stream()
|
|
|
2512 |
.map(r -> Arrays.asList(r.getStoreCode(), r.getStoreName(), r.getBrandName(),
|
| 27213 |
tejbeer |
2513 |
r.getModelName(), r.getModelNumber(), r.getWarehouseName(), r.getStateManager(),
|
| 28526 |
tejbeer |
2514 |
r.getTerritoryManager(), r.getPendingIndentQty(), r.getGrnStockQty(),
|
|
|
2515 |
r.getShortageQty(), r.getAvailabitiy()))
|
| 25800 |
tejbeer |
2516 |
.collect(Collectors.toList());
|
|
|
2517 |
emailRowsMap.get(y.getKey()).addAll(fms);
|
|
|
2518 |
|
| 25721 |
tejbeer |
2519 |
}
|
|
|
2520 |
|
| 25800 |
tejbeer |
2521 |
});
|
| 25721 |
tejbeer |
2522 |
|
|
|
2523 |
});
|
|
|
2524 |
|
| 27212 |
tejbeer |
2525 |
List<String> headers = Arrays.asList("Store Code", "Store Name", "Brand", "Model Name", "Model Number",
|
| 28526 |
tejbeer |
2526 |
"Warehouse Name", "State Manager", "Territory Manager", "Pending Indent", "InStock", "Shortage Qty",
|
|
|
2527 |
"Availability");
|
| 25837 |
amit.gupta |
2528 |
emailRowsMap.entrySet().forEach(entry -> {
|
| 25721 |
tejbeer |
2529 |
|
| 25800 |
tejbeer |
2530 |
ByteArrayOutputStream baos = null;
|
|
|
2531 |
try {
|
| 25837 |
amit.gupta |
2532 |
baos = FileUtil.getCSVByteStream(headers, entry.getValue());
|
| 25800 |
tejbeer |
2533 |
} catch (Exception e2) {
|
|
|
2534 |
e2.printStackTrace();
|
|
|
2535 |
}
|
| 30752 |
tejbeer |
2536 |
String[] sendToArray = new String[] {
|
| 28526 |
tejbeer |
2537 |
|
| 29996 |
tejbeer |
2538 |
entry.getKey()
|
| 29995 |
tejbeer |
2539 |
|
|
|
2540 |
};
|
|
|
2541 |
|
| 25800 |
tejbeer |
2542 |
try {
|
|
|
2543 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
|
|
|
2544 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
2545 |
} catch (Exception e1) { // TODO Auto-generated catch block
|
|
|
2546 |
e1.printStackTrace();
|
|
|
2547 |
}
|
| 25721 |
tejbeer |
2548 |
|
| 25800 |
tejbeer |
2549 |
});
|
|
|
2550 |
}
|
| 25721 |
tejbeer |
2551 |
}
|
|
|
2552 |
|
|
|
2553 |
private String getNotificationMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
2554 |
StringBuilder sb = new StringBuilder();
|
|
|
2555 |
sb.append("Focused Model Shortage in Your Stock : \n");
|
|
|
2556 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
2557 |
|
|
|
2558 |
sb.append(entry.getItemName() + "-" + entry.getShortageQty());
|
|
|
2559 |
sb.append(String.format("%n", ""));
|
|
|
2560 |
}
|
|
|
2561 |
return sb.toString();
|
|
|
2562 |
}
|
|
|
2563 |
|
|
|
2564 |
private void sendMailWithAttachments(String subject, String messageText, String email) throws Exception {
|
|
|
2565 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
2566 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
2567 |
|
|
|
2568 |
helper.setSubject(subject);
|
|
|
2569 |
helper.setText(messageText, true);
|
|
|
2570 |
helper.setTo(email);
|
| 27116 |
amit.gupta |
2571 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
| 25721 |
tejbeer |
2572 |
helper.setFrom(senderAddress);
|
|
|
2573 |
mailSender.send(message);
|
|
|
2574 |
|
|
|
2575 |
}
|
|
|
2576 |
|
|
|
2577 |
private String getMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
2578 |
StringBuilder sb = new StringBuilder();
|
|
|
2579 |
sb.append("<html><body><p>Alert</p><p>Focused Model Shortage in Your Stock:-</p>"
|
|
|
2580 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
2581 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
2582 |
+ " <th style='border:1px solid black;padding: 5px'>Item</th>\n"
|
|
|
2583 |
+ " <th style='border:1px solid black;padding: 5px'>Shortage Qty</th>\n"
|
|
|
2584 |
+ " </tr>");
|
|
|
2585 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
2586 |
|
|
|
2587 |
sb.append("<tr>");
|
|
|
2588 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getItemName() + "</td>");
|
|
|
2589 |
|
|
|
2590 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getShortageQty() + "</td>");
|
|
|
2591 |
|
|
|
2592 |
sb.append("</tr>");
|
|
|
2593 |
|
|
|
2594 |
}
|
|
|
2595 |
|
|
|
2596 |
sb.append("</tbody></table></body></html>");
|
|
|
2597 |
|
|
|
2598 |
return sb.toString();
|
|
|
2599 |
}
|
|
|
2600 |
|
| 25927 |
amit.gupta |
2601 |
public void notifyLead() throws Exception {
|
| 29488 |
manish |
2602 |
List<Lead> leadsToNotify = leadRepository.selectLeadsScheduledBetweenDate(null,
|
|
|
2603 |
LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
| 25927 |
amit.gupta |
2604 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
2605 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
| 27477 |
amit.gupta |
2606 |
LOGGER.info("authUserEmailMap {}", authUserEmailMap);
|
| 25927 |
amit.gupta |
2607 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
2608 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
2609 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
| 25936 |
amit.gupta |
2610 |
|
| 27477 |
amit.gupta |
2611 |
LOGGER.info("dtrEmailMap {}", dtrEmailMap);
|
| 26790 |
tejbeer |
2612 |
|
| 25927 |
amit.gupta |
2613 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
|
|
2614 |
|
|
|
2615 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
2616 |
int authId = authUserEmail.getKey();
|
|
|
2617 |
String email = authUserEmail.getValue();
|
|
|
2618 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
2619 |
}
|
| 27477 |
amit.gupta |
2620 |
LOGGER.info("authUserKeyMap", authUserKeyMap);
|
|
|
2621 |
LOGGER.info("leadsToNotify {}", leadsToNotify);
|
| 26790 |
tejbeer |
2622 |
|
| 29308 |
tejbeer |
2623 |
String templateMessage = "Lead followup for %s %s, %s, %s is due by %s";
|
| 25927 |
amit.gupta |
2624 |
for (Lead lead : leadsToNotify) {
|
| 27217 |
amit.gupta |
2625 |
if (authUserKeyMap.get(lead.getAssignTo()) == null) {
|
|
|
2626 |
LOGGER.info("Assignee no longer part of system {}", lead.getAssignTo());
|
| 25927 |
amit.gupta |
2627 |
continue;
|
|
|
2628 |
}
|
|
|
2629 |
String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
|
| 29308 |
tejbeer |
2630 |
lead.getAddress(), lead.getLeadMobile(), leadTimeFormatter.format(lead.getScheduledTimestamp()));
|
| 25927 |
amit.gupta |
2631 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2632 |
sendNotificationModel.setCampaignName("Lead Reminder");
|
|
|
2633 |
sendNotificationModel.setTitle("Leads followup Reminder");
|
|
|
2634 |
sendNotificationModel.setMessage(notificationMessage);
|
|
|
2635 |
sendNotificationModel.setType("url");
|
| 29317 |
tejbeer |
2636 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/leadUpdate?leadId=" + lead.getId());
|
| 25927 |
amit.gupta |
2637 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2638 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
| 26320 |
tejbeer |
2639 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
|
| 25929 |
amit.gupta |
2640 |
System.out.println(sendNotificationModel);
|
| 25927 |
amit.gupta |
2641 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2642 |
}
|
|
|
2643 |
}
|
| 26945 |
amit.gupta |
2644 |
|
| 25927 |
amit.gupta |
2645 |
public void notifyVisits() throws Exception {
|
| 26945 |
amit.gupta |
2646 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository
|
|
|
2647 |
.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
| 25927 |
amit.gupta |
2648 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
2649 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
|
|
2650 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
2651 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
2652 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
|
|
2653 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
| 26945 |
amit.gupta |
2654 |
|
| 25927 |
amit.gupta |
2655 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
2656 |
int authId = authUserEmail.getKey();
|
|
|
2657 |
String email = authUserEmail.getValue();
|
|
|
2658 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
2659 |
}
|
|
|
2660 |
String visitTemplate = "Planned visit to franchisee %s is due by %s";
|
|
|
2661 |
String followupTemplate = "Lead followup for franchisee %s is due by %s";
|
|
|
2662 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("MMM 7, EEEE h:m a");
|
|
|
2663 |
for (FranchiseeVisit visit : franchiseeVisits) {
|
|
|
2664 |
if (authUserKeyMap.containsKey(visit.getAuthId())) {
|
|
|
2665 |
continue;
|
|
|
2666 |
}
|
|
|
2667 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2668 |
String message = null;
|
| 26945 |
amit.gupta |
2669 |
if (visit.getFranchiseActivityId() == 0) {
|
|
|
2670 |
message = String.format(visitTemplate, visit.getPartnerName(),
|
| 30574 |
amit.gupta |
2671 |
timeFormatter.format(visit.getScheduleTimestamp()));
|
| 26945 |
amit.gupta |
2672 |
sendNotificationModel.setCampaignName("Franchisee visit Reminder");
|
| 25927 |
amit.gupta |
2673 |
} else {
|
| 26945 |
amit.gupta |
2674 |
message = String.format(followupTemplate, visit.getPartnerName(),
|
| 30574 |
amit.gupta |
2675 |
timeFormatter.format(visit.getScheduleTimestamp()));
|
| 25927 |
amit.gupta |
2676 |
sendNotificationModel.setCampaignName("Franchisee followup Reminder");
|
|
|
2677 |
}
|
|
|
2678 |
sendNotificationModel.setMessage(message);
|
|
|
2679 |
sendNotificationModel.setType("url");
|
| 26482 |
tejbeer |
2680 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 25927 |
amit.gupta |
2681 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2682 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
|
|
2683 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(visit.getAuthId())));
|
|
|
2684 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2685 |
}
|
| 25910 |
amit.gupta |
2686 |
}
|
| 25982 |
amit.gupta |
2687 |
|
| 26283 |
tejbeer |
2688 |
public void ticketClosed() throws Exception {
|
|
|
2689 |
|
|
|
2690 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTicketsWithStatus(ActivityType.RESOLVED);
|
|
|
2691 |
for (Ticket ticket : tickets) {
|
|
|
2692 |
if (ticket.getUpdateTimestamp().toLocalDate().isBefore(LocalDate.now().minusDays(7))) {
|
|
|
2693 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
2694 |
ticket.setLastActivity(ActivityType.RESOLVED_ACCEPTED);
|
|
|
2695 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
2696 |
ticketRepository.persist(ticket);
|
|
|
2697 |
}
|
|
|
2698 |
}
|
|
|
2699 |
|
|
|
2700 |
}
|
|
|
2701 |
|
| 26790 |
tejbeer |
2702 |
public void checkValidateReferral() throws Exception {
|
|
|
2703 |
|
|
|
2704 |
List<Refferal> referrals = refferalRepository.selectByStatus(RefferalStatus.pending);
|
| 26791 |
tejbeer |
2705 |
LOGGER.info("referrals" + referrals);
|
| 26790 |
tejbeer |
2706 |
if (!referrals.isEmpty()) {
|
|
|
2707 |
String subject = "Referral Request";
|
|
|
2708 |
String messageText = this.getMessageForReferral(referrals);
|
|
|
2709 |
|
| 26792 |
tejbeer |
2710 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
2711 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 30752 |
tejbeer |
2712 |
String[] email = { "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com" };
|
| 26792 |
tejbeer |
2713 |
helper.setSubject(subject);
|
|
|
2714 |
helper.setText(messageText, true);
|
|
|
2715 |
helper.setTo(email);
|
|
|
2716 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
|
|
2717 |
helper.setFrom(senderAddress);
|
|
|
2718 |
mailSender.send(message);
|
|
|
2719 |
|
| 26790 |
tejbeer |
2720 |
}
|
|
|
2721 |
}
|
|
|
2722 |
|
|
|
2723 |
private String getMessageForReferral(List<Refferal> referrals) {
|
|
|
2724 |
StringBuilder sb = new StringBuilder();
|
|
|
2725 |
sb.append("<html><body><p>Alert</p><p>Pending Referrals:-</p>"
|
|
|
2726 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
2727 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
2728 |
+ " <th style='border:1px solid black;padding: 5px'>RefereeName</th>\n"
|
|
|
2729 |
+ " <th style='border:1px solid black;padding: 5px'>Referee Email</th>\n"
|
|
|
2730 |
+ " <th style='border:1px solid black;padding: 5px'>Referral Name</th>\n"
|
|
|
2731 |
+ " <th style='border:1px solid black;padding: 5px'>Refferal Mobile</th>\n"
|
|
|
2732 |
+ " <th style='border:1px solid black;padding: 5px'>city</th>\n"
|
|
|
2733 |
+ " <th style='border:1px solid black;padding: 5px'>state</th>\n"
|
|
|
2734 |
+ " </tr>");
|
|
|
2735 |
for (Refferal entry : referrals) {
|
|
|
2736 |
|
|
|
2737 |
sb.append("<tr>");
|
|
|
2738 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeName() + "</td>");
|
|
|
2739 |
|
|
|
2740 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeEmail() + "</td>");
|
|
|
2741 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getFirstName() + "</td>");
|
|
|
2742 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getMobile() + "</td>");
|
|
|
2743 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCity() + "</td>");
|
|
|
2744 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getState() + "</td>");
|
|
|
2745 |
|
|
|
2746 |
sb.append("</tr>");
|
|
|
2747 |
|
|
|
2748 |
}
|
|
|
2749 |
|
|
|
2750 |
sb.append("</tbody></table></body></html>");
|
|
|
2751 |
|
|
|
2752 |
return sb.toString();
|
|
|
2753 |
}
|
|
|
2754 |
|
| 30421 |
tejbeer |
2755 |
private String getMessageForUncontacblePartner(List<PartnerCollectionRemark> pcrs)
|
|
|
2756 |
throws ProfitMandiBusinessException {
|
|
|
2757 |
StringBuilder sb = new StringBuilder();
|
|
|
2758 |
sb.append("<html><body><p>Alert</p><p>Not Responding Partner:-</p>"
|
|
|
2759 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
2760 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
2761 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
|
|
2762 |
+ " <th style='border:1px solid black;padding: 5px'>from</th>\n"
|
|
|
2763 |
|
|
|
2764 |
+ " </tr>");
|
|
|
2765 |
for (PartnerCollectionRemark entry : pcrs) {
|
|
|
2766 |
|
|
|
2767 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
|
|
2768 |
|
|
|
2769 |
sb.append("<tr>");
|
|
|
2770 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
|
|
2771 |
+ customRetailer.getCode() + ")" + "</td>");
|
|
|
2772 |
|
|
|
2773 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2774 |
+ entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
|
|
2775 |
|
|
|
2776 |
sb.append("</tr>");
|
|
|
2777 |
|
|
|
2778 |
}
|
|
|
2779 |
|
|
|
2780 |
sb.append("</tbody></table></body></html>");
|
|
|
2781 |
|
|
|
2782 |
return sb.toString();
|
|
|
2783 |
}
|
|
|
2784 |
|
| 27271 |
amit.gupta |
2785 |
public void reverseWallet() throws Exception {
|
|
|
2786 |
LocalDate localDate = LocalDate.of(2020, 10, 28);
|
| 28205 |
tejbeer |
2787 |
List<UserWalletHistory> uwhList = userWalletHistoryRepository.selectAllByDateType(localDate.atStartOfDay(),
|
|
|
2788 |
localDate.plusDays(1).atStartOfDay(),
|
| 27271 |
amit.gupta |
2789 |
Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
|
|
2790 |
for (UserWalletHistory uwh : uwhList) {
|
| 28205 |
tejbeer |
2791 |
if (uwh.getBusinessTimestamp().getMonth().equals(Month.SEPTEMBER)) {
|
| 27275 |
amit.gupta |
2792 |
UserWallet uw = userWalletRepository.selectById(uwh.getWalletId());
|
| 28205 |
tejbeer |
2793 |
// LOGGER.info("UWH - {}", uwh);
|
|
|
2794 |
// amount += uwh.getAmount();
|
|
|
2795 |
// System.out.println("Amount is - " + amount);
|
|
|
2796 |
// walletService.rollbackAmountFromWallet(uw.getUserId(), uwh.getAmount(),
|
|
|
2797 |
// uwh.getReference(), uwh.getReferenceType(), "Margin reversal for error prone
|
|
|
2798 |
// run", uwh.getBusinessTimestamp());
|
| 27313 |
amit.gupta |
2799 |
int orderId = uwh.getReference();
|
|
|
2800 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
|
|
2801 |
int inventoryItemId = 0;
|
| 28205 |
tejbeer |
2802 |
// fofoOrderRepository.delete(fofoOrder);
|
| 27313 |
amit.gupta |
2803 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 28205 |
tejbeer |
2804 |
/*
|
|
|
2805 |
* List<PaymentOptionTransaction> paymentOptionTransactions =
|
|
|
2806 |
* paymentOptionTransactionRepository.selectByReferenceIdAndType(fofoOrder.getId
|
|
|
2807 |
* (), PaymentOptionReferenceType.ORDER); for(PaymentOptionTransaction
|
|
|
2808 |
* paymentOptionTransaction : paymentOptionTransactions) {
|
|
|
2809 |
* //paymentOptionTransactionRepository.delete(paymentOptionTransaction); }
|
|
|
2810 |
*/
|
|
|
2811 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
2812 |
// fofoOrderItemRepository.delete(foi);
|
| 27313 |
amit.gupta |
2813 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(foi.getId());
|
| 28205 |
tejbeer |
2814 |
for (FofoLineItem fli : flis) {
|
|
|
2815 |
// fofoLineItemRepository.delete(fli);
|
| 27313 |
amit.gupta |
2816 |
inventoryItemId = fli.getInventoryItemId();
|
|
|
2817 |
}
|
|
|
2818 |
}
|
| 28205 |
tejbeer |
2819 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(
|
|
|
2820 |
java.util.stream.Stream.of(inventoryItemId).collect(Collectors.toSet()));
|
|
|
2821 |
for (SchemeInOut sio : schemeInOuts) {
|
|
|
2822 |
if (sio.getCreateTimestamp().toLocalDate().equals(localDate)) {
|
| 27314 |
amit.gupta |
2823 |
LOGGER.info("SIO - {}", sio);
|
| 27315 |
amit.gupta |
2824 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 27313 |
amit.gupta |
2825 |
}
|
|
|
2826 |
}
|
| 28205 |
tejbeer |
2827 |
|
| 27271 |
amit.gupta |
2828 |
}
|
|
|
2829 |
}
|
| 28205 |
tejbeer |
2830 |
|
| 27271 |
amit.gupta |
2831 |
}
|
| 28205 |
tejbeer |
2832 |
|
|
|
2833 |
public void partnerProblemAlert() throws Exception {
|
|
|
2834 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
2835 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
|
|
2836 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
|
|
2837 |
Map<Integer, Double> mtdSales = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1),
|
|
|
2838 |
curDate.with(LocalTime.MAX), 0, false);
|
|
|
2839 |
Map<Integer, PartnerDailyInvestment> pdi = partnerDailyInvestmentRepository.selectAll(LocalDate.now()).stream()
|
|
|
2840 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
2841 |
|
|
|
2842 |
for (Entry<Integer, Double> ls : lmtdSale.entrySet()) {
|
|
|
2843 |
|
|
|
2844 |
double lmtdTwentyPercentSale = ls.getValue() * 0.2;
|
| 28208 |
tejbeer |
2845 |
|
|
|
2846 |
LOGGER.info("lmtdTwentyPercentSale" + lmtdTwentyPercentSale);
|
|
|
2847 |
|
| 28211 |
tejbeer |
2848 |
double mtdSale = mtdSales.get(ls.getKey()) == null ? 0 : mtdSales.get(ls.getKey());
|
| 28208 |
tejbeer |
2849 |
|
|
|
2850 |
LOGGER.info("mtdSale" + mtdSale);
|
|
|
2851 |
|
| 28209 |
tejbeer |
2852 |
double totalSixtyPercentInvestment = pdi.get(ls.getKey()) == null ? 0
|
|
|
2853 |
: pdi.get(ls.getKey()).getTotalInvestment() * 0.6;
|
| 28205 |
tejbeer |
2854 |
|
| 28208 |
tejbeer |
2855 |
LOGGER.info("totalSixtyPercentInvestment" + totalSixtyPercentInvestment);
|
|
|
2856 |
|
| 28209 |
tejbeer |
2857 |
double stockInvestment = pdi.get(ls.getKey()) == null ? 0 : pdi.get(ls.getKey()).getInStockAmount();
|
| 28208 |
tejbeer |
2858 |
|
|
|
2859 |
LOGGER.info("stockInvestment" + stockInvestment);
|
|
|
2860 |
|
| 28205 |
tejbeer |
2861 |
boolean Investmentvalue = partnerInvestmentService.isInvestmentBelow(ls.getKey(), 25);
|
|
|
2862 |
|
|
|
2863 |
PartnerProblem partnerProblem = partnerProblemRepository.selectByFofoId(ls.getKey());
|
|
|
2864 |
|
| 28210 |
tejbeer |
2865 |
if (partnerProblem == null) {
|
| 28205 |
tejbeer |
2866 |
partnerProblem = new PartnerProblem();
|
|
|
2867 |
partnerProblem.setFofoId(ls.getKey());
|
|
|
2868 |
if (mtdSale < lmtdTwentyPercentSale) {
|
|
|
2869 |
partnerProblem.setMtd(1);
|
|
|
2870 |
}
|
|
|
2871 |
if (Investmentvalue) {
|
|
|
2872 |
partnerProblem.setInvestment(1);
|
|
|
2873 |
}
|
|
|
2874 |
|
|
|
2875 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
|
|
2876 |
partnerProblem.setInvestment(1);
|
|
|
2877 |
}
|
|
|
2878 |
|
|
|
2879 |
partnerProblemRepository.persist(partnerProblem);
|
|
|
2880 |
} else {
|
|
|
2881 |
if (mtdSale < lmtdTwentyPercentSale) {
|
|
|
2882 |
partnerProblem.setMtd(partnerProblem.getMtd() + 1);
|
|
|
2883 |
|
|
|
2884 |
} else {
|
|
|
2885 |
partnerProblem.setMtd(0);
|
|
|
2886 |
|
|
|
2887 |
}
|
|
|
2888 |
if (Investmentvalue) {
|
|
|
2889 |
partnerProblem.setInvestment(partnerProblem.getInvestment() + 1);
|
|
|
2890 |
} else {
|
|
|
2891 |
partnerProblem.setInvestment(0);
|
|
|
2892 |
|
|
|
2893 |
}
|
|
|
2894 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
|
|
2895 |
partnerProblem.setStockInvestment(partnerProblem.getStockInvestment() + 1);
|
|
|
2896 |
} else {
|
|
|
2897 |
partnerProblem.setStockInvestment(0);
|
|
|
2898 |
}
|
|
|
2899 |
|
|
|
2900 |
}
|
|
|
2901 |
|
|
|
2902 |
}
|
|
|
2903 |
|
| 28213 |
tejbeer |
2904 |
List<PartnerProblem> partnerProblems = partnerProblemRepository.selectAll().stream()
|
|
|
2905 |
.filter(x -> x.getMtd() + x.getInvestment() + x.getStockInvestment() > 0).collect(Collectors.toList());
|
|
|
2906 |
|
| 28223 |
tejbeer |
2907 |
partnerProblems = partnerProblems.stream().sorted((x1, x2) -> {
|
| 28224 |
tejbeer |
2908 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
| 28223 |
tejbeer |
2909 |
+ x2.getStockInvestment() ? 1 : -1;
|
|
|
2910 |
}).collect(Collectors.toList());
|
| 28227 |
tejbeer |
2911 |
|
|
|
2912 |
Map<Integer, PartnerProblem> partnerProblemMap = partnerProblems.stream().sorted((x1, x2) -> {
|
|
|
2913 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
|
|
2914 |
+ x2.getStockInvestment() ? 1 : -1;
|
|
|
2915 |
}).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
2916 |
|
| 28212 |
tejbeer |
2917 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailers();
|
| 28213 |
tejbeer |
2918 |
|
| 28467 |
tejbeer |
2919 |
List<Integer> assignTo = Arrays.asList(15, 9, 54, 53);
|
| 28213 |
tejbeer |
2920 |
|
|
|
2921 |
Map<Integer, AuthUser> assignAuthUserMap = authRepository.selectAllAuthUserByIds(assignTo).stream()
|
|
|
2922 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
2923 |
|
| 28286 |
tejbeer |
2924 |
List<String> sendTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 30765 |
tejbeer |
2925 |
"niranjan.kala@smartdukaan.com", "sm@smartdukaan.com");
|
| 28208 |
tejbeer |
2926 |
LOGGER.info("partnerProblem" + partnerProblems);
|
| 28205 |
tejbeer |
2927 |
StringBuilder sb = new StringBuilder();
|
| 28218 |
tejbeer |
2928 |
sb.append("<htl><body>");
|
| 28222 |
tejbeer |
2929 |
sb.append(
|
|
|
2930 |
"<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 |
2931 |
sb.append("<tbody>\n" + " <tr>"
|
|
|
2932 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
|
|
2933 |
+ " <th style='border:1px solid black;padding: 5px'>Assign TO</th>"
|
|
|
2934 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
|
|
2935 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
|
|
2936 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
|
|
2937 |
+ " <th style='border:1px solid black;padding: 5px'>Manager</th>"
|
|
|
2938 |
|
|
|
2939 |
+ " </tr>");
|
|
|
2940 |
|
|
|
2941 |
for (PartnerProblem pp : partnerProblems) {
|
| 28467 |
tejbeer |
2942 |
int value = pp.getFofoId() % 4;
|
| 28205 |
tejbeer |
2943 |
|
|
|
2944 |
Map<EscalationType, AuthUser> authUserMap = csService.getAuthUserAndEsclationByPartnerId(pp.getFofoId());
|
| 28217 |
tejbeer |
2945 |
LOGGER.info("authUserMap" + authUserMap);
|
| 28205 |
tejbeer |
2946 |
sb.append("<tr>");
|
|
|
2947 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2948 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
| 28213 |
tejbeer |
2949 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2950 |
+ assignAuthUserMap.get(assignTo.get(value)).getName() + "</td>");
|
| 28205 |
tejbeer |
2951 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
|
|
2952 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
|
|
2953 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getStockInvestment() + "</td>");
|
| 28216 |
tejbeer |
2954 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 28224 |
tejbeer |
2955 |
+ (authUserMap.get(EscalationType.L1) == null ? "N/A"
|
| 30752 |
tejbeer |
2956 |
: authUserMap.get(EscalationType.L1).getFirstName())
|
| 28224 |
tejbeer |
2957 |
+ " ," + (authUserMap.get(EscalationType.L2) == null ? "N/A"
|
| 30752 |
tejbeer |
2958 |
: authUserMap.get(EscalationType.L2).getFirstName())
|
| 28216 |
tejbeer |
2959 |
+ "</td>");
|
| 28205 |
tejbeer |
2960 |
|
|
|
2961 |
sb.append("</tr>");
|
|
|
2962 |
}
|
|
|
2963 |
sb.append("</tbody></table><br><br>");
|
|
|
2964 |
String subject = "Partner Problem Alert!";
|
|
|
2965 |
String[] email = sendTo.toArray(new String[sendTo.size()]);
|
|
|
2966 |
|
| 28222 |
tejbeer |
2967 |
this.sendMailHtmlFormat(email, sb.toString(), null, subject);
|
|
|
2968 |
|
| 28218 |
tejbeer |
2969 |
Map<Integer, List<Integer>> authUserPartnerMapping = csService.getAuthUserIdPartnerIdMapping();
|
|
|
2970 |
|
|
|
2971 |
for (Entry<Integer, List<Integer>> authUserPartner : authUserPartnerMapping.entrySet()) {
|
| 28222 |
tejbeer |
2972 |
AuthUser authUser = authRepository.selectById(authUserPartner.getKey());
|
| 28227 |
tejbeer |
2973 |
for (Integer patnerId : authUserPartner.getValue()) {
|
|
|
2974 |
if (partnerProblemMap.get(patnerId) != null) {
|
| 28218 |
tejbeer |
2975 |
|
| 28227 |
tejbeer |
2976 |
StringBuilder sbbuilder = new StringBuilder();
|
|
|
2977 |
sbbuilder.append("<hml><body>");
|
|
|
2978 |
sb.append(
|
|
|
2979 |
"<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>");
|
|
|
2980 |
sbbuilder.append("<tbody>\n" + " <tr>"
|
|
|
2981 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
|
|
2982 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
|
|
2983 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
|
|
2984 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
| 28218 |
tejbeer |
2985 |
|
| 28227 |
tejbeer |
2986 |
+ " </tr>");
|
| 28218 |
tejbeer |
2987 |
|
| 28227 |
tejbeer |
2988 |
for (Integer partnerId : authUserPartner.getValue()) {
|
|
|
2989 |
if (partnerProblemMap.get(partnerId) != null) {
|
|
|
2990 |
PartnerProblem pp = partnerProblemMap.get(partnerId);
|
|
|
2991 |
sbbuilder.append("<tr>");
|
|
|
2992 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2993 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
|
|
2994 |
sbbuilder
|
|
|
2995 |
.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
|
|
2996 |
sbbuilder.append(
|
|
|
2997 |
"<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
|
|
2998 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
2999 |
+ pp.getStockInvestment() + "</td>");
|
|
|
3000 |
|
|
|
3001 |
sbbuilder.append("</tr>");
|
|
|
3002 |
}
|
|
|
3003 |
|
| 28224 |
tejbeer |
3004 |
}
|
| 28227 |
tejbeer |
3005 |
sbbuilder.append("</tbody></table><br><br>");
|
| 28224 |
tejbeer |
3006 |
|
| 28286 |
tejbeer |
3007 |
this.sendMailOfHtmlFormat(authUser.getEmailId(), sbbuilder.toString(), null, subject);
|
| 28230 |
tejbeer |
3008 |
break;
|
| 28218 |
tejbeer |
3009 |
}
|
| 28230 |
tejbeer |
3010 |
|
| 28223 |
tejbeer |
3011 |
}
|
| 28222 |
tejbeer |
3012 |
}
|
|
|
3013 |
}
|
| 28218 |
tejbeer |
3014 |
|
| 28222 |
tejbeer |
3015 |
private void sendMailHtmlFormat(String email[], String body, String cc[], String subject)
|
|
|
3016 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
3017 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
3018 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
3019 |
helper.setSubject(subject);
|
|
|
3020 |
helper.setText(body, true);
|
|
|
3021 |
helper.setTo(email);
|
|
|
3022 |
if (cc != null) {
|
|
|
3023 |
helper.setCc(cc);
|
| 28218 |
tejbeer |
3024 |
}
|
| 28222 |
tejbeer |
3025 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
3026 |
helper.setFrom(senderAddress);
|
|
|
3027 |
mailSender.send(message);
|
| 28205 |
tejbeer |
3028 |
}
|
|
|
3029 |
|
| 28775 |
amit.gupta |
3030 |
@Autowired
|
|
|
3031 |
WarehouseRepository warehouseRepository;
|
| 28790 |
amit.gupta |
3032 |
|
| 28775 |
amit.gupta |
3033 |
public void getVendorWarehouses(int warehouseId) {
|
| 28778 |
amit.gupta |
3034 |
LOGGER.info("Warehouses - {}", warehouseRepository.getVendorWarehouses().get(warehouseId));
|
| 28790 |
amit.gupta |
3035 |
|
| 28775 |
amit.gupta |
3036 |
}
|
| 29488 |
manish |
3037 |
|
| 29451 |
manish |
3038 |
public void checkImeiActivation() {
|
| 29488 |
manish |
3039 |
|
| 29451 |
manish |
3040 |
try {
|
|
|
3041 |
vivoImeiActivationService.checkImeiActivation();
|
|
|
3042 |
} catch (ProfitMandiBusinessException e) {
|
|
|
3043 |
// TODO Auto-generated catch block
|
|
|
3044 |
e.printStackTrace();
|
|
|
3045 |
} catch (IOException e) {
|
|
|
3046 |
// TODO Auto-generated catch block
|
|
|
3047 |
e.printStackTrace();
|
|
|
3048 |
} catch (Exception e) {
|
|
|
3049 |
// TODO Auto-generated catch block
|
|
|
3050 |
e.printStackTrace();
|
|
|
3051 |
}
|
| 28775 |
amit.gupta |
3052 |
|
| 29451 |
manish |
3053 |
}
|
|
|
3054 |
|
| 29668 |
tejbeer |
3055 |
public void checkItelImeiActivation(LocalDate date, Integer day) {
|
| 29488 |
manish |
3056 |
LOGGER.info("Hello - {}", "hhh");
|
|
|
3057 |
|
|
|
3058 |
try {
|
| 29668 |
tejbeer |
3059 |
itelImeiActivationService.checkItelImeiActivation(date, day);
|
| 29488 |
manish |
3060 |
} catch (ProfitMandiBusinessException e) {
|
|
|
3061 |
// TODO Auto-generated catch block
|
|
|
3062 |
e.printStackTrace();
|
|
|
3063 |
} catch (IOException e) {
|
|
|
3064 |
// TODO Auto-generated catch block
|
|
|
3065 |
e.printStackTrace();
|
|
|
3066 |
} catch (Exception e) {
|
|
|
3067 |
// TODO Auto-generated catch block
|
|
|
3068 |
e.printStackTrace();
|
|
|
3069 |
}
|
|
|
3070 |
|
|
|
3071 |
}
|
|
|
3072 |
|
| 29807 |
manish |
3073 |
public void selectFinServiceFollowUpDateByCurrDate(LocalDate currentDate)
|
|
|
3074 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 29801 |
manish |
3075 |
LOGGER.info("selectfinServiceFollow - {}", "selectfinServiceFollowUpDateByCurrDate");
|
|
|
3076 |
|
| 29807 |
manish |
3077 |
serviceConfigService.selectFinServicePartnerfollowUpDateByCurrentDate(currentDate);
|
|
|
3078 |
|
| 29801 |
manish |
3079 |
}
|
|
|
3080 |
|
| 29668 |
tejbeer |
3081 |
public void checkTecnoImeiActivation(LocalDate date, Integer day) {
|
| 29488 |
manish |
3082 |
LOGGER.info("Hello - {}", "hhh");
|
|
|
3083 |
|
|
|
3084 |
try {
|
| 29668 |
tejbeer |
3085 |
tecnoImeiActivation.checkTecnoImeiActivation(date, day);
|
| 29488 |
manish |
3086 |
} catch (ProfitMandiBusinessException e) {
|
|
|
3087 |
// TODO Auto-generated catch block
|
|
|
3088 |
e.printStackTrace();
|
|
|
3089 |
} catch (IOException e) {
|
|
|
3090 |
// TODO Auto-generated catch block
|
|
|
3091 |
e.printStackTrace();
|
|
|
3092 |
} catch (Exception e) {
|
|
|
3093 |
// TODO Auto-generated catch block
|
|
|
3094 |
e.printStackTrace();
|
|
|
3095 |
}
|
|
|
3096 |
|
|
|
3097 |
}
|
|
|
3098 |
|
| 29252 |
amit.gupta |
3099 |
public void checkCancellationMargin() throws Exception {
|
|
|
3100 |
LocalDateTime startDate = LocalDate.of(2021, 4, 1).atStartOfDay();
|
|
|
3101 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectCancelledBetweenSaleDate(startDate, LocalDateTime.now());
|
|
|
3102 |
LOGGER.info("Total Orders = {}", fofoOrders.size());
|
| 29308 |
tejbeer |
3103 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
3104 |
List<UserWalletHistory> history = userWalletHistoryRepository
|
|
|
3105 |
.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
|
|
|
3106 |
history.addAll(userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrder.getId(),
|
|
|
3107 |
WalletReferenceType.ACTIVATION_SCHEME));
|
|
|
3108 |
int walletSum = history.stream().mapToInt(x -> x.getAmount()).sum();
|
|
|
3109 |
if (Math.abs(walletSum) > 1) {
|
|
|
3110 |
// LOGGER.info("Cancelled invoice {}, Order Id = {}, = havent rolledback, Value
|
|
|
3111 |
// = {}", fofoOrder.getInvoiceNumber(), fofoOrder.getId(), walletSum);
|
| 29252 |
amit.gupta |
3112 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
3113 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(fofoOrderItems.get(0).getId());
|
|
|
3114 |
FofoLineItem fli = flis.get(0);
|
| 29308 |
tejbeer |
3115 |
if (StringUtils.isEmpty(fli.getSerialNumber()))
|
|
|
3116 |
continue;
|
|
|
3117 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository
|
|
|
3118 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(fli.getInventoryItemId())));
|
| 29252 |
amit.gupta |
3119 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(fli.getInventoryItemId());
|
| 29308 |
tejbeer |
3120 |
double schemeSum = schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null)
|
|
|
3121 |
.mapToDouble(x -> x.getAmount()).sum();
|
|
|
3122 |
/*
|
|
|
3123 |
* if(inventoryItem.getGoodQuantity()==1) {
|
|
|
3124 |
* LOGGER.info("GoodQty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
|
|
3125 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
|
|
3126 |
* inventoryItem.getUpdateTimestamp()); } else
|
|
|
3127 |
* if(inventoryItem.getBadQuantity()==1){
|
|
|
3128 |
* LOGGER.info("Bad Qty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
|
|
3129 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
|
|
3130 |
* inventoryItem.getUpdateTimestamp()); } else if
|
|
|
3131 |
* (inventoryItem.getLastScanType().equals(ScanType.SALE)) { LOGGER.
|
|
|
3132 |
* info("Problem Sold, Serial Number {}, InventoryItem = {}, Billed on {}",
|
|
|
3133 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
|
|
3134 |
* inventoryItem.getUpdateTimestamp()); }
|
|
|
3135 |
*/
|
|
|
3136 |
if (inventoryItem.getLastScanType().equals(ScanType.SALE)
|
|
|
3137 |
|| inventoryItem.getLastScanType().equals(ScanType.SALE_RET)) {
|
|
|
3138 |
Map<String, Double> map = schemeInOuts.stream()
|
|
|
3139 |
.collect(
|
|
|
3140 |
Collectors.groupingBy(
|
|
|
3141 |
x -> DateTimeFormatter.ofPattern("yyyyMMddHH")
|
|
|
3142 |
.format(x.getCreateTimestamp()) + "- " + x.getSchemeId(),
|
|
|
3143 |
Collectors.summingDouble(x -> x.getAmount())));
|
|
|
3144 |
for (Map.Entry<String, Double> entry : map.entrySet()) {
|
|
|
3145 |
LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
|
| 29252 |
amit.gupta |
3146 |
}
|
| 29308 |
tejbeer |
3147 |
LOGGER.info("id- {}, imei- {}, lastScan = {}, Scheme sum - {}", inventoryItem.getId(),
|
|
|
3148 |
inventoryItem.getSerialNumber(), inventoryItem.getLastScanType(), schemeSum);
|
| 29252 |
amit.gupta |
3149 |
}
|
|
|
3150 |
}
|
|
|
3151 |
}
|
| 29308 |
tejbeer |
3152 |
|
| 29252 |
amit.gupta |
3153 |
}
|
|
|
3154 |
|
| 29488 |
manish |
3155 |
public static String readFileAsString(String file) throws Exception {
|
|
|
3156 |
String data = "";
|
|
|
3157 |
data = new String(Files.readAllBytes(Paths.get(file)));
|
|
|
3158 |
return data;
|
|
|
3159 |
}
|
| 29451 |
manish |
3160 |
|
| 29308 |
tejbeer |
3161 |
public void markDelhiveryOrderDelivered() throws ProfitMandiBusinessException, IOException {
|
|
|
3162 |
List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.DELHIVERY_PROVIDERID,
|
|
|
3163 |
OrderStatus.SHIPPED_FROM_WH);
|
|
|
3164 |
|
|
|
3165 |
if (!orders.isEmpty()) {
|
| 29441 |
tejbeer |
3166 |
Set<String> airwayBill = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
|
| 29308 |
tejbeer |
3167 |
|
| 29441 |
tejbeer |
3168 |
int arraylength = airwayBill.size();
|
|
|
3169 |
|
|
|
3170 |
if (arraylength >= 75) {
|
|
|
3171 |
|
|
|
3172 |
airwayBill = airwayBill.stream().limit(74).collect(Collectors.toSet());
|
|
|
3173 |
}
|
| 29308 |
tejbeer |
3174 |
LOGGER.info("airwayBill" + airwayBill);
|
|
|
3175 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
|
|
3176 |
|
|
|
3177 |
OkHttpClient client = new OkHttpClient();
|
|
|
3178 |
|
|
|
3179 |
Request request1 = new Request.Builder()
|
|
|
3180 |
.url(url + "?waybill=" + String.join(",", airwayBill) + "&token=" + token).get().build();
|
|
|
3181 |
|
|
|
3182 |
LOGGER.info("request1" + request1);
|
|
|
3183 |
|
|
|
3184 |
Response response = client.newCall(request1).execute();
|
|
|
3185 |
|
|
|
3186 |
LOGGER.info("jsonbj" + response.body());
|
|
|
3187 |
|
|
|
3188 |
JSONObject jsonObj = new JSONObject(response.body().string());
|
|
|
3189 |
|
|
|
3190 |
LOGGER.info("jsonObj" + jsonObj);
|
|
|
3191 |
|
| 29403 |
tejbeer |
3192 |
JSONArray shipmentData = jsonObj.getJSONArray("ShipmentData");
|
| 29308 |
tejbeer |
3193 |
Set<String> airwaybillStatus = new HashSet<>();
|
| 29403 |
tejbeer |
3194 |
for (int i = 0; i < shipmentData.length(); i++) {
|
|
|
3195 |
JSONObject jsonObject = shipmentData.getJSONObject(i);
|
| 29308 |
tejbeer |
3196 |
JSONObject shipment = jsonObject.getJSONObject("Shipment");
|
|
|
3197 |
|
|
|
3198 |
LOGGER.info("shipment" + shipment);
|
|
|
3199 |
JSONObject statusDescription = shipment.getJSONObject("Status");
|
|
|
3200 |
String awb = shipment.getString("AWB");
|
|
|
3201 |
|
|
|
3202 |
String status = statusDescription.getString("Status");
|
|
|
3203 |
LOGGER.info("status" + status);
|
|
|
3204 |
|
|
|
3205 |
LOGGER.info("awb" + awb);
|
|
|
3206 |
if (status.equals("Delivered")) {
|
|
|
3207 |
airwaybillStatus.add(awb);
|
|
|
3208 |
}
|
|
|
3209 |
|
|
|
3210 |
}
|
|
|
3211 |
if (!airwaybillStatus.isEmpty()) {
|
|
|
3212 |
for (String aws : airwaybillStatus) {
|
|
|
3213 |
|
|
|
3214 |
List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
|
|
|
3215 |
for (Order dlo : deliverdOrders) {
|
|
|
3216 |
dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
| 29403 |
tejbeer |
3217 |
dlo.setStatusDescription("Order Delivered");
|
| 29308 |
tejbeer |
3218 |
dlo.setDeliveryTimestamp(LocalDateTime.now());
|
|
|
3219 |
}
|
|
|
3220 |
|
|
|
3221 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
3222 |
sendNotificationModel.setCampaignName("Order Delivered");
|
|
|
3223 |
sendNotificationModel.setTitle("Order Delivered");
|
|
|
3224 |
sendNotificationModel.setMessage(String.format("Dear partner, your SmartDukaan ORDER " + aws
|
| 29336 |
tejbeer |
3225 |
+ "has been delivered to you in a safe sealed bag" + "."));
|
| 29308 |
tejbeer |
3226 |
sendNotificationModel.setType("url");
|
|
|
3227 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
3228 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
3229 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
3230 |
int userId = userAccountRepository.selectUserIdByRetailerId(orders.get(0).getRetailerId());
|
|
|
3231 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
3232 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
3233 |
|
|
|
3234 |
}
|
|
|
3235 |
}
|
|
|
3236 |
|
|
|
3237 |
}
|
|
|
3238 |
}
|
|
|
3239 |
|
| 29814 |
tejbeer |
3240 |
public void partnerWiseCreditAccount() throws Exception {
|
|
|
3241 |
|
|
|
3242 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
|
|
3243 |
|
|
|
3244 |
for (FofoStore fs : fofoStores) {
|
|
|
3245 |
|
|
|
3246 |
if (fs.getPan() != null) {
|
|
|
3247 |
AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
|
| 29815 |
tejbeer |
3248 |
|
|
|
3249 |
LOGGER.info("accountStatusResponseOut" + accountStatusResponseOut);
|
| 29814 |
tejbeer |
3250 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(fs.getId(),
|
|
|
3251 |
Gateway.MANDII);
|
|
|
3252 |
|
|
|
3253 |
if (creditAccount == null) {
|
|
|
3254 |
|
|
|
3255 |
creditAccount = new CreditAccount();
|
|
|
3256 |
|
|
|
3257 |
creditAccount.setFofoId(fs.getId());
|
|
|
3258 |
creditAccount.setGateway(Gateway.MANDII);
|
|
|
3259 |
|
|
|
3260 |
}
|
| 29835 |
tejbeer |
3261 |
|
|
|
3262 |
if (accountStatusResponseOut == null) {
|
|
|
3263 |
creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
|
|
|
3264 |
creditAccount.setDescription("User company not found");
|
|
|
3265 |
|
| 29817 |
tejbeer |
3266 |
} else {
|
| 29835 |
tejbeer |
3267 |
if (accountStatusResponseOut.getSanctionLimit() != null) {
|
|
|
3268 |
creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
|
|
|
3269 |
} else {
|
|
|
3270 |
creditAccount.setSanctionedAmount(0);
|
|
|
3271 |
}
|
| 29817 |
tejbeer |
3272 |
|
| 29835 |
tejbeer |
3273 |
creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
|
|
|
3274 |
if (accountStatusResponseOut.getBalanceAmount() != null) {
|
|
|
3275 |
creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
|
|
|
3276 |
} else {
|
|
|
3277 |
creditAccount.setAvailableAmount(0);
|
|
|
3278 |
}
|
|
|
3279 |
|
|
|
3280 |
if (accountStatusResponseOut.getCurrentStage() != null) {
|
|
|
3281 |
creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
|
|
|
3282 |
}
|
|
|
3283 |
if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
|
|
|
3284 |
creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
|
|
|
3285 |
} else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
|
|
|
3286 |
creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
|
|
|
3287 |
} else {
|
|
|
3288 |
|
|
|
3289 |
creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
|
|
|
3290 |
}
|
| 29817 |
tejbeer |
3291 |
}
|
|
|
3292 |
|
| 29814 |
tejbeer |
3293 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
|
|
3294 |
creditAccountRepository.persist(creditAccount);
|
|
|
3295 |
}
|
|
|
3296 |
}
|
|
|
3297 |
}
|
|
|
3298 |
|
| 30421 |
tejbeer |
3299 |
@Autowired
|
|
|
3300 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
|
|
3301 |
|
|
|
3302 |
public void reviewUncontactablePartner()
|
|
|
3303 |
throws ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
|
|
|
3304 |
|
|
|
3305 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
|
|
3306 |
|
|
|
3307 |
List<Integer> pcrms = partnerCollectionRemarkRepository
|
|
|
3308 |
.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
|
|
|
3309 |
|
|
|
3310 |
if (!pcrms.isEmpty()) {
|
|
|
3311 |
Map<Integer, PartnerCollectionRemark> partnerCollectionRemarksMap = partnerCollectionRemarkRepository
|
|
|
3312 |
.selectByIds(pcrms).stream().filter(x -> x.getRemark().equals(CollectionRemark.NOT_RESPONDING))
|
|
|
3313 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
3314 |
|
|
|
3315 |
if (!partnerCollectionRemarksMap.isEmpty()) {
|
|
|
3316 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping()
|
|
|
3317 |
.entrySet()) {
|
|
|
3318 |
List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
|
|
|
3319 |
.map(x -> partnerCollectionRemarksMap.get(x)).filter(x -> x != null)
|
|
|
3320 |
.collect(Collectors.toList());
|
| 30752 |
tejbeer |
3321 |
String subject = "UNCONTACTABLE PARTNERS";
|
| 30421 |
tejbeer |
3322 |
String messageText = this.getMessageForUncontacblePartner(filteredRows);
|
|
|
3323 |
|
|
|
3324 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
3325 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 30752 |
tejbeer |
3326 |
String[] email = new String[] { storeGuyEntry.getKey() };
|
| 30421 |
tejbeer |
3327 |
|
|
|
3328 |
helper.setSubject(subject);
|
|
|
3329 |
helper.setText(messageText, true);
|
|
|
3330 |
helper.setTo(email);
|
|
|
3331 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com",
|
|
|
3332 |
"Smartdukaan Alerts");
|
|
|
3333 |
helper.setFrom(senderAddress);
|
|
|
3334 |
mailSender.send(message);
|
|
|
3335 |
|
|
|
3336 |
LOGGER.info("filteredRows {}", filteredRows);
|
|
|
3337 |
|
|
|
3338 |
}
|
|
|
3339 |
}
|
| 30859 |
tejbeer |
3340 |
|
| 30421 |
tejbeer |
3341 |
}
|
|
|
3342 |
}
|
|
|
3343 |
|
| 30859 |
tejbeer |
3344 |
@Autowired
|
|
|
3345 |
private LoanRepository loanRepository;
|
|
|
3346 |
|
|
|
3347 |
@Autowired
|
|
|
3348 |
private LoanStatementRepository loanStatementRepository;
|
|
|
3349 |
|
|
|
3350 |
@Autowired
|
|
|
3351 |
private SDCreditService sdCreditService;
|
|
|
3352 |
|
|
|
3353 |
@Autowired
|
|
|
3354 |
private SDCreditRequirementRepository sdCreditRequirementRepository;
|
|
|
3355 |
|
|
|
3356 |
public void calculateInterestAccured() throws ProfitMandiBusinessException {
|
|
|
3357 |
|
|
|
3358 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
|
|
3359 |
|
|
|
3360 |
if (!loans.isEmpty()) {
|
|
|
3361 |
|
|
|
3362 |
for (Loan loan : loans) {
|
|
|
3363 |
|
|
|
3364 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
|
|
3365 |
|
|
|
3366 |
Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream().collect(Collectors.groupingBy(
|
|
|
3367 |
x -> x.getLoanReferenceType(), Collectors.summingDouble(x -> x.getAmount().doubleValue())));
|
|
|
3368 |
|
|
|
3369 |
if (loan.getFreeDays() > 0) {
|
|
|
3370 |
LocalDateTime freeDaysLimitDate = loan.getCreatedOn().plusDays(loan.getFreeDays() - 1);
|
|
|
3371 |
if (LocalDateTime.now().isAfter(freeDaysLimitDate)) {
|
|
|
3372 |
sdCreditService.calculateInterest(freeDaysLimitDate.toLocalDate(), LocalDate.now(), loan,
|
|
|
3373 |
loanStatusAmount);
|
|
|
3374 |
|
|
|
3375 |
}
|
|
|
3376 |
} else {
|
|
|
3377 |
|
|
|
3378 |
int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
|
|
|
3379 |
loan.getId());
|
|
|
3380 |
LOGGER.info("loanStatementId {}", loanStatementId);
|
|
|
3381 |
LoanStatement loanStatement = loanStatementRepository.selectById(loanStatementId);
|
|
|
3382 |
if (loanStatement.getLoanId() == loan.getId()) {
|
|
|
3383 |
|
|
|
3384 |
sdCreditService.calculateInterest(loanStatement.getCreatedAt().toLocalDate(), LocalDate.now(),
|
|
|
3385 |
loan, loanStatusAmount);
|
|
|
3386 |
|
|
|
3387 |
} else {
|
|
|
3388 |
throw new ProfitMandiBusinessException("loanstament", loanStatement.getLoanId(),
|
|
|
3389 |
"Invalid LoanId");
|
|
|
3390 |
}
|
|
|
3391 |
|
|
|
3392 |
}
|
|
|
3393 |
|
|
|
3394 |
}
|
|
|
3395 |
}
|
|
|
3396 |
|
|
|
3397 |
}
|
|
|
3398 |
|
|
|
3399 |
public void loanSettlement() throws ProfitMandiBusinessException {
|
|
|
3400 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
|
|
3401 |
|
|
|
3402 |
if (!loans.isEmpty()) {
|
|
|
3403 |
|
|
|
3404 |
for (Loan loan : loans) {
|
|
|
3405 |
|
|
|
3406 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(loan.getFofoId());
|
|
|
3407 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository
|
|
|
3408 |
.selectByFofoId(loan.getFofoId());
|
|
|
3409 |
|
|
|
3410 |
if (userWallet.getAmount() >= 100) {
|
|
|
3411 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
|
|
3412 |
|
|
|
3413 |
Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream()
|
|
|
3414 |
.collect(Collectors.groupingBy(x -> x.getLoanReferenceType(),
|
|
|
3415 |
Collectors.summingDouble(x -> x.getAmount().doubleValue())));
|
|
|
3416 |
|
|
|
3417 |
LOGGER.info("loanStatusAmount {}", loanStatusAmount);
|
|
|
3418 |
double interestAmount = loanStatusAmount.get(LoanReferenceType.INTEREST);
|
|
|
3419 |
|
|
|
3420 |
double principalAmount = loanStatusAmount.get(LoanReferenceType.PRINCIPAL);
|
|
|
3421 |
double paidAmount = 0;
|
|
|
3422 |
if (userWallet.getAmount() > Math.abs(interestAmount)) {
|
|
|
3423 |
|
|
|
3424 |
if (interestAmount != 0) {
|
|
|
3425 |
|
|
|
3426 |
settledLoanStatement(LoanReferenceType.INTEREST, BigDecimal.valueOf(interestAmount),
|
|
|
3427 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
|
|
3428 |
LocalDateTime.now());
|
|
|
3429 |
loan.setInterestPaid(loan.getInterestPaid().add(BigDecimal.valueOf(interestAmount).abs()));
|
|
|
3430 |
|
|
|
3431 |
paidAmount += Math.abs(interestAmount);
|
|
|
3432 |
}
|
|
|
3433 |
|
|
|
3434 |
double userWalletAmount = userWallet.getAmount() - Math.abs(interestAmount);
|
|
|
3435 |
|
|
|
3436 |
if (userWalletAmount > Math.abs(principalAmount) && principalAmount != 0) {
|
|
|
3437 |
|
|
|
3438 |
settledLoanStatement(LoanReferenceType.PRINCIPAL, BigDecimal.valueOf(principalAmount),
|
|
|
3439 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
|
|
3440 |
LocalDateTime.now());
|
|
|
3441 |
double amount = userWalletAmount - Math.abs(principalAmount);
|
|
|
3442 |
|
|
|
3443 |
paidAmount += Math.abs(principalAmount);
|
|
|
3444 |
|
|
|
3445 |
userWallet.setAmount((int) amount);
|
|
|
3446 |
|
|
|
3447 |
sdCreditRequirement.setAvailableLimit(sdCreditRequirement.getAvailableLimit()
|
|
|
3448 |
.add(BigDecimal.valueOf(principalAmount).abs()));
|
|
|
3449 |
sdCreditRequirement.setUtilizedAmount(sdCreditRequirement.getUtilizedAmount()
|
|
|
3450 |
.subtract(BigDecimal.valueOf(principalAmount).abs()));
|
|
|
3451 |
|
|
|
3452 |
loan.setPendingAmount(BigDecimal.ZERO);
|
|
|
3453 |
|
|
|
3454 |
} else if (principalAmount != 0) {
|
|
|
3455 |
|
|
|
3456 |
settledLoanStatement(LoanReferenceType.PRINCIPAL, BigDecimal.valueOf(userWalletAmount),
|
|
|
3457 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
|
|
3458 |
LocalDateTime.now());
|
|
|
3459 |
|
|
|
3460 |
paidAmount += Math.abs(userWalletAmount);
|
|
|
3461 |
|
|
|
3462 |
sdCreditRequirement.setAvailableLimit(sdCreditRequirement.getAvailableLimit()
|
|
|
3463 |
.add(BigDecimal.valueOf(userWalletAmount)).abs());
|
|
|
3464 |
sdCreditRequirement.setUtilizedAmount(sdCreditRequirement.getUtilizedAmount()
|
|
|
3465 |
.subtract(BigDecimal.valueOf(userWalletAmount)).abs());
|
|
|
3466 |
userWallet.setAmount(0);
|
|
|
3467 |
|
|
|
3468 |
loan.setPendingAmount(
|
|
|
3469 |
loan.getPendingAmount().subtract(BigDecimal.valueOf(userWalletAmount)));
|
|
|
3470 |
|
|
|
3471 |
}
|
|
|
3472 |
|
|
|
3473 |
createUserWalletHistory(userWallet.getId(), userWallet.getUserId(),
|
|
|
3474 |
WalletReferenceType.LOAN_REPAYMENT, loan.getId(), Math.abs(paidAmount));
|
|
|
3475 |
|
|
|
3476 |
} else {
|
|
|
3477 |
|
|
|
3478 |
settledLoanStatement(LoanReferenceType.INTEREST, BigDecimal.valueOf(userWallet.getAmount()),
|
|
|
3479 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan", LocalDateTime.now());
|
|
|
3480 |
|
|
|
3481 |
paidAmount += Math.abs(userWallet.getAmount());
|
|
|
3482 |
|
|
|
3483 |
createUserWalletHistory(userWallet.getId(), userWallet.getUserId(),
|
|
|
3484 |
WalletReferenceType.LOAN_REPAYMENT, loan.getId(), Math.abs(paidAmount));
|
|
|
3485 |
|
|
|
3486 |
loan.setInterestPaid(
|
|
|
3487 |
loan.getInterestPaid().add(BigDecimal.valueOf(userWallet.getAmount()).abs()));
|
|
|
3488 |
|
|
|
3489 |
userWallet.setAmount(0);
|
|
|
3490 |
}
|
|
|
3491 |
|
|
|
3492 |
}
|
|
|
3493 |
}
|
|
|
3494 |
}
|
|
|
3495 |
|
|
|
3496 |
}
|
|
|
3497 |
|
|
|
3498 |
private void settledLoanStatement(LoanReferenceType loanReferneceType, BigDecimal amount, int fofoId, int loanId,
|
|
|
3499 |
String description, LocalDateTime now) {
|
|
|
3500 |
|
|
|
3501 |
sdCreditService.createLoanStatement(loanReferneceType, amount.abs(), fofoId, loanId, description,
|
|
|
3502 |
LocalDateTime.now());
|
|
|
3503 |
|
|
|
3504 |
}
|
|
|
3505 |
|
|
|
3506 |
private void createUserWalletHistory(int walletId, int userId, WalletReferenceType referenceType, int loanId,
|
|
|
3507 |
double interestAmount) {
|
|
|
3508 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
3509 |
uwh.setWalletId(walletId);
|
|
|
3510 |
uwh.setFofoId(userId);
|
|
|
3511 |
uwh.setBusinessTimestamp(LocalDateTime.now());
|
|
|
3512 |
uwh.setReferenceType(referenceType);
|
|
|
3513 |
uwh.setReference(loanId);
|
|
|
3514 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
3515 |
uwh.setAmount((int) -(interestAmount));
|
| 30908 |
tejbeer |
3516 |
uwh.setDescription("Amount adjusted against loan");
|
| 30859 |
tejbeer |
3517 |
userWalletHistoryRepository.persist(uwh);
|
|
|
3518 |
|
|
|
3519 |
}
|
|
|
3520 |
|
|
|
3521 |
public void dailyLoanAlert() throws ProfitMandiBusinessException {
|
|
|
3522 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
|
|
3523 |
|
|
|
3524 |
Map<Integer, Double> partnerLoanAmount = new HashMap<>();
|
|
|
3525 |
|
|
|
3526 |
if (!loans.isEmpty()) {
|
|
|
3527 |
|
|
|
3528 |
for (Loan loan : loans) {
|
|
|
3529 |
|
|
|
3530 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
|
|
3531 |
|
|
|
3532 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
|
|
3533 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
|
|
3534 |
if (partnerLoanAmount.get(loan.getFofoId()) != null) {
|
|
|
3535 |
amount += partnerLoanAmount.get(loan.getFofoId());
|
|
|
3536 |
partnerLoanAmount.put(loan.getFofoId(), amount);
|
|
|
3537 |
} else {
|
|
|
3538 |
partnerLoanAmount.put(loan.getFofoId(), amount);
|
|
|
3539 |
}
|
|
|
3540 |
|
|
|
3541 |
}
|
|
|
3542 |
|
|
|
3543 |
}
|
|
|
3544 |
|
|
|
3545 |
if (!partnerLoanAmount.isEmpty()) {
|
|
|
3546 |
|
|
|
3547 |
for (Entry<Integer, Double> partnerLoanAmountEnrty : partnerLoanAmount.entrySet()) {
|
|
|
3548 |
|
|
|
3549 |
int fofoId = partnerLoanAmountEnrty.getKey();
|
|
|
3550 |
|
|
|
3551 |
String title = "Alert! Credit o/s";
|
|
|
3552 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
|
|
3553 |
String message = "Your total pending Loan amount is Rs."
|
|
|
3554 |
+ FormattingUtils.formatDecimal(Math.abs(partnerLoanAmountEnrty.getValue()));
|
|
|
3555 |
notificationService.sendNotification(fofoId, title, MessageType.notification, title, message, url);
|
|
|
3556 |
|
|
|
3557 |
}
|
|
|
3558 |
|
|
|
3559 |
}
|
|
|
3560 |
|
|
|
3561 |
}
|
|
|
3562 |
|
| 30896 |
amit.gupta |
3563 |
public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
|
|
|
3564 |
schemeService.processActivatedImeisForSchemes();
|
|
|
3565 |
}
|
|
|
3566 |
|
| 30913 |
tejbeer |
3567 |
@Autowired
|
|
|
3568 |
private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
|
|
|
3569 |
|
| 30917 |
tejbeer |
3570 |
@Autowired
|
|
|
3571 |
private TransactionRepository transactionRepository;
|
|
|
3572 |
|
| 30929 |
tejbeer |
3573 |
@Autowired
|
|
|
3574 |
private CreditAccountRepository crediRepository;
|
|
|
3575 |
|
| 30913 |
tejbeer |
3576 |
public void updatePartnerLimit() throws ProfitMandiBusinessException {
|
|
|
3577 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
|
|
3578 |
|
|
|
3579 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
|
|
|
3580 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
3581 |
Map<Integer, CurrentPartnerDailyInvestment> currentPartnerDailyInvestmentMap = currentPartnerDailyInvestmentRepository
|
|
|
3582 |
.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 30933 |
tejbeer |
3583 |
double limitValue = 100000;
|
| 30913 |
tejbeer |
3584 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailerMap.entrySet()) {
|
|
|
3585 |
int fofoId = customRetailerEntry.getKey();
|
|
|
3586 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementMap.get(customRetailerEntry.getKey());
|
| 30929 |
tejbeer |
3587 |
LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
|
| 30913 |
tejbeer |
3588 |
CurrentPartnerDailyInvestment currentPartnerDailyInvestment = currentPartnerDailyInvestmentMap.get(fofoId);
|
|
|
3589 |
BigDecimal suggestedAmount = BigDecimal.ZERO;
|
|
|
3590 |
if (currentPartnerDailyInvestment != null) {
|
|
|
3591 |
suggestedAmount = BigDecimal.valueOf(currentPartnerDailyInvestment.getTotalInvestment() * 0.1);
|
|
|
3592 |
}
|
|
|
3593 |
|
| 30933 |
tejbeer |
3594 |
if (suggestedAmount.doubleValue() > limitValue) {
|
| 30917 |
tejbeer |
3595 |
|
| 30933 |
tejbeer |
3596 |
suggestedAmount = BigDecimal.valueOf(limitValue);
|
| 30917 |
tejbeer |
3597 |
|
|
|
3598 |
}
|
| 30920 |
tejbeer |
3599 |
|
|
|
3600 |
if (suggestedAmount.doubleValue() < 0) {
|
|
|
3601 |
suggestedAmount = BigDecimal.ZERO;
|
|
|
3602 |
}
|
|
|
3603 |
|
| 30913 |
tejbeer |
3604 |
LOGGER.info("suggestedAmount {} ", suggestedAmount);
|
|
|
3605 |
|
|
|
3606 |
if (sdCreditRequirement == null) {
|
|
|
3607 |
sdCreditRequirement = new SDCreditRequirement();
|
|
|
3608 |
sdCreditRequirement.setFofoId(fofoId);
|
|
|
3609 |
sdCreditRequirement.setCreditDays(15);
|
|
|
3610 |
sdCreditRequirement.setInterestRate(BigDecimal.valueOf(0.05));
|
|
|
3611 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
| 30929 |
tejbeer |
3612 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
| 30913 |
tejbeer |
3613 |
sdCreditRequirement.setLimit(suggestedAmount);
|
|
|
3614 |
sdCreditRequirement.setUtilizedAmount(BigDecimal.ZERO);
|
|
|
3615 |
sdCreditRequirement.setAvailableLimit(suggestedAmount);
|
|
|
3616 |
sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
|
|
|
3617 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
|
|
3618 |
sdCreditRequirementRepository.persist(sdCreditRequirement);
|
|
|
3619 |
}
|
| 30929 |
tejbeer |
3620 |
|
|
|
3621 |
CreditRisk creditRisk = getCurrentRisk(sdCreditRequirement, firstBillingDate);
|
|
|
3622 |
|
|
|
3623 |
sdCreditRequirement.setRisk(creditRisk);
|
|
|
3624 |
|
| 30913 |
tejbeer |
3625 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
|
|
3626 |
sdCreditRequirement.setLimit(suggestedAmount);
|
|
|
3627 |
BigDecimal utilizedLimit = new BigDecimal(sdCreditService.getUtilizationAmount(fofoId));
|
|
|
3628 |
|
|
|
3629 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizedLimit);
|
|
|
3630 |
|
|
|
3631 |
LOGGER.info("utilizedLimit {} ", utilizedLimit);
|
|
|
3632 |
|
|
|
3633 |
LOGGER.info("availableLimit {} ", availableLimit);
|
|
|
3634 |
|
|
|
3635 |
sdCreditRequirement.setUtilizedAmount(utilizedLimit);
|
|
|
3636 |
|
|
|
3637 |
sdCreditRequirement.setAvailableLimit(availableLimit);
|
|
|
3638 |
|
|
|
3639 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
|
|
3640 |
|
|
|
3641 |
}
|
|
|
3642 |
|
|
|
3643 |
}
|
|
|
3644 |
|
| 30929 |
tejbeer |
3645 |
private static final List<CreditRisk> ORDERED_RISKS = Arrays.asList(CreditRisk.HIGH_RISK, CreditRisk.LOW_RISK,
|
|
|
3646 |
CreditRisk.NO_RISK);
|
|
|
3647 |
|
|
|
3648 |
private CreditRisk getCurrentRisk(SDCreditRequirement sdCreditRequirement, LocalDateTime firstBillingDate) {
|
|
|
3649 |
CreditRisk currentRisk = sdCreditRequirement.getRisk();
|
|
|
3650 |
long noOfDaysBetween = 0;
|
|
|
3651 |
LocalDateTime riskDate = sdCreditRequirement.getRiskTimestamp() == null ? firstBillingDate
|
|
|
3652 |
: sdCreditRequirement.getRiskTimestamp();
|
|
|
3653 |
if (riskDate == null) {
|
|
|
3654 |
return CreditRisk.HIGH_RISK;
|
|
|
3655 |
} else {
|
|
|
3656 |
noOfDaysBetween = ChronoUnit.DAYS.between(riskDate, LocalDateTime.now());
|
|
|
3657 |
if (noOfDaysBetween < 90) {
|
|
|
3658 |
return currentRisk;
|
|
|
3659 |
} else if (noOfDaysBetween >= 90 && noOfDaysBetween < 180) {
|
|
|
3660 |
return currentRisk.decrease();
|
|
|
3661 |
} else {
|
|
|
3662 |
return currentRisk.decrease();
|
|
|
3663 |
}
|
|
|
3664 |
|
|
|
3665 |
}
|
|
|
3666 |
|
|
|
3667 |
}
|
|
|
3668 |
|
|
|
3669 |
public void setDefaultPartnersRisk()
|
|
|
3670 |
throws ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
|
|
|
3671 |
|
|
|
3672 |
List<Loan> loans = loanRepository.selectAllActiveLoan().stream()
|
|
|
3673 |
.filter(x -> x.getDueDate().isBefore(LocalDateTime.now())).collect(Collectors.toList());
|
|
|
3674 |
|
|
|
3675 |
List<Loan> defaulterLoan = new ArrayList<>();
|
|
|
3676 |
|
|
|
3677 |
if (!loans.isEmpty()) {
|
|
|
3678 |
for (Loan loan : loans) {
|
|
|
3679 |
|
|
|
3680 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository
|
|
|
3681 |
.selectByFofoId(loan.getFofoId());
|
|
|
3682 |
long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDateTime.now());
|
|
|
3683 |
|
|
|
3684 |
LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
|
|
|
3685 |
|
|
|
3686 |
if (noOfdaysBetween > 30) {
|
|
|
3687 |
CreditAccount creditAccount = crediRepository.selectByFofoIdAndGateway(loan.getFofoId(),
|
|
|
3688 |
Gateway.SDDIRECT);
|
|
|
3689 |
creditAccount.setActive(false);
|
|
|
3690 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
|
|
3691 |
sdCreditRequirement.setRiskTimestamp(LocalDateTime.now());
|
|
|
3692 |
|
|
|
3693 |
defaulterLoan.add(loan);
|
|
|
3694 |
|
|
|
3695 |
} else {
|
|
|
3696 |
|
|
|
3697 |
sdCreditRequirement.setRisk(sdCreditRequirement.getRisk().increase());
|
|
|
3698 |
|
|
|
3699 |
sdCreditRequirement.setRiskTimestamp(LocalDateTime.now());
|
|
|
3700 |
|
|
|
3701 |
}
|
|
|
3702 |
}
|
|
|
3703 |
}
|
|
|
3704 |
|
|
|
3705 |
if (!defaulterLoan.isEmpty()) {
|
|
|
3706 |
|
| 30931 |
tejbeer |
3707 |
List<AuthUser> authUsers = csService
|
|
|
3708 |
.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_FINANCIAL_SERVICES);
|
|
|
3709 |
List<String> allEmails = new ArrayList<>();
|
|
|
3710 |
if (!authUsers.isEmpty()) {
|
|
|
3711 |
List<String> financeEmails = authUsers.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
|
|
3712 |
allEmails.addAll(financeEmails);
|
|
|
3713 |
}
|
|
|
3714 |
|
| 30929 |
tejbeer |
3715 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
| 30931 |
tejbeer |
3716 |
allEmails.add(storeGuyEntry.getKey());
|
|
|
3717 |
String subject = "Time Limit Cross";
|
| 30929 |
tejbeer |
3718 |
String messageText = this.getMessageForDueDateExtend(defaulterLoan);
|
|
|
3719 |
|
|
|
3720 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
3721 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 30931 |
tejbeer |
3722 |
String[] email = allEmails.toArray(new String[allEmails.size()]);
|
| 30929 |
tejbeer |
3723 |
|
|
|
3724 |
helper.setSubject(subject);
|
|
|
3725 |
helper.setText(messageText, true);
|
|
|
3726 |
helper.setTo(email);
|
|
|
3727 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
|
|
3728 |
helper.setFrom(senderAddress);
|
|
|
3729 |
mailSender.send(message);
|
|
|
3730 |
|
|
|
3731 |
}
|
|
|
3732 |
}
|
|
|
3733 |
|
|
|
3734 |
}
|
|
|
3735 |
|
|
|
3736 |
private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
|
|
|
3737 |
StringBuilder sb = new StringBuilder();
|
|
|
3738 |
sb.append("<html><body><p>Alert</p><p>Time Limit Cross :-</p>"
|
|
|
3739 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
3740 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
3741 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
|
|
3742 |
+ " <th style='border:1px solid black;padding: 5px'>due date</th>\n"
|
|
|
3743 |
+ " <th style='border:1px solid black;padding: 5px'>Days</th>\n"
|
|
|
3744 |
|
|
|
3745 |
+ " </tr>");
|
|
|
3746 |
for (Loan entry : loans) {
|
|
|
3747 |
long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
|
|
|
3748 |
|
|
|
3749 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
|
|
3750 |
|
|
|
3751 |
sb.append("<tr>");
|
|
|
3752 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
|
|
3753 |
+ customRetailer.getCode() + ")" + "</td>");
|
|
|
3754 |
|
|
|
3755 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
3756 |
+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
|
|
3757 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
|
|
|
3758 |
|
|
|
3759 |
sb.append("</tr>");
|
|
|
3760 |
|
|
|
3761 |
}
|
|
|
3762 |
|
|
|
3763 |
sb.append("</tbody></table></body></html>");
|
|
|
3764 |
|
|
|
3765 |
return sb.toString();
|
|
|
3766 |
}
|
|
|
3767 |
|
| 26418 |
tejbeer |
3768 |
}
|
| 29814 |
tejbeer |
3769 |
|
| 27438 |
amit.gupta |
3770 |
//2284
|