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