| 23724 |
amit.gupta |
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;
|
| 23724 |
amit.gupta |
6 |
import java.time.LocalDate;
|
|
|
7 |
import java.time.LocalDateTime;
|
| 24256 |
amit.gupta |
8 |
import java.time.LocalTime;
|
| 24653 |
govind |
9 |
import java.time.format.DateTimeFormatter;
|
| 23724 |
amit.gupta |
10 |
import java.time.temporal.ChronoUnit;
|
|
|
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Arrays;
|
| 24627 |
amit.gupta |
13 |
import java.util.Collections;
|
| 23723 |
amit.gupta |
14 |
import java.util.HashMap;
|
| 24241 |
amit.gupta |
15 |
import java.util.HashSet;
|
| 23724 |
amit.gupta |
16 |
import java.util.List;
|
| 23723 |
amit.gupta |
17 |
import java.util.Map;
|
| 24242 |
amit.gupta |
18 |
import java.util.Optional;
|
| 24542 |
amit.gupta |
19 |
import java.util.Set;
|
| 23724 |
amit.gupta |
20 |
import java.util.stream.Collectors;
|
| 23723 |
amit.gupta |
21 |
|
| 24121 |
govind |
22 |
import javax.mail.MessagingException;
|
|
|
23 |
import javax.mail.internet.InternetAddress;
|
|
|
24 |
import javax.mail.internet.MimeMessage;
|
|
|
25 |
|
| 23929 |
amit.gupta |
26 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 25598 |
amit.gupta |
27 |
import org.apache.commons.lang.StringUtils;
|
| 25300 |
tejbeer |
28 |
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
29 |
import org.apache.http.client.methods.HttpPost;
|
|
|
30 |
import org.apache.http.entity.StringEntity;
|
|
|
31 |
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
32 |
import org.apache.http.impl.client.HttpClients;
|
| 23755 |
amit.gupta |
33 |
import org.apache.logging.log4j.LogManager;
|
|
|
34 |
import org.apache.logging.log4j.Logger;
|
| 25300 |
tejbeer |
35 |
import org.json.JSONObject;
|
| 23723 |
amit.gupta |
36 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23933 |
amit.gupta |
37 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23724 |
amit.gupta |
38 |
import org.springframework.beans.factory.annotation.Value;
|
| 23929 |
amit.gupta |
39 |
import org.springframework.core.io.ByteArrayResource;
|
| 24692 |
amit.gupta |
40 |
import org.springframework.core.io.InputStreamSource;
|
| 23929 |
amit.gupta |
41 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24121 |
govind |
42 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23723 |
amit.gupta |
43 |
import org.springframework.stereotype.Component;
|
| 23724 |
amit.gupta |
44 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
45 |
|
| 24542 |
amit.gupta |
46 |
import com.google.common.collect.Lists;
|
| 25300 |
tejbeer |
47 |
import com.google.gson.Gson;
|
|
|
48 |
import com.google.gson.GsonBuilder;
|
| 25721 |
tejbeer |
49 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 23724 |
amit.gupta |
50 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24681 |
amit.gupta |
51 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 24121 |
govind |
52 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23929 |
amit.gupta |
53 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 25721 |
tejbeer |
54 |
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
|
| 24542 |
amit.gupta |
55 |
import com.spice.profitmandi.common.model.GstRate;
|
| 25590 |
amit.gupta |
56 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23724 |
amit.gupta |
57 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 25821 |
amit.gupta |
58 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 24681 |
amit.gupta |
59 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 24002 |
amit.gupta |
60 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
61 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
62 |
import com.spice.profitmandi.common.util.Utils;
|
| 24592 |
amit.gupta |
63 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| 25300 |
tejbeer |
64 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
|
|
65 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
| 25590 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 25800 |
tejbeer |
67 |
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
|
| 25609 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 24590 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 25590 |
amit.gupta |
70 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 26283 |
tejbeer |
71 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 23724 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
| 25300 |
tejbeer |
73 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
|
|
74 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
| 23724 |
amit.gupta |
75 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
76 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
|
|
77 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 26283 |
tejbeer |
78 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| 24542 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 24590 |
amit.gupta |
80 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 23724 |
amit.gupta |
81 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 24542 |
amit.gupta |
82 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 23929 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24249 |
amit.gupta |
84 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24277 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 23724 |
amit.gupta |
86 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24242 |
amit.gupta |
87 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 24241 |
amit.gupta |
88 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 25982 |
amit.gupta |
89 |
import com.spice.profitmandi.dao.entity.transaction.HdfcPayment;
|
| 24431 |
amit.gupta |
90 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 25609 |
amit.gupta |
91 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 24587 |
amit.gupta |
92 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 24580 |
amit.gupta |
93 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 24542 |
amit.gupta |
94 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 25300 |
tejbeer |
95 |
import com.spice.profitmandi.dao.entity.user.Device;
|
| 25927 |
amit.gupta |
96 |
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
|
| 25910 |
amit.gupta |
97 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
| 24250 |
amit.gupta |
98 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 25598 |
amit.gupta |
99 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 24242 |
amit.gupta |
100 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 25609 |
amit.gupta |
101 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 25982 |
amit.gupta |
102 |
import com.spice.profitmandi.dao.model.AddPaymentRequest;
|
|
|
103 |
import com.spice.profitmandi.dao.model.AddPaymentResponse;
|
| 25300 |
tejbeer |
104 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
|
|
105 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 25590 |
amit.gupta |
106 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 25300 |
tejbeer |
107 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 25721 |
tejbeer |
108 |
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
|
| 24249 |
amit.gupta |
109 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24241 |
amit.gupta |
110 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 25590 |
amit.gupta |
111 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
|
|
112 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 26283 |
tejbeer |
113 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
| 23724 |
amit.gupta |
114 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 23929 |
amit.gupta |
115 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 25927 |
amit.gupta |
116 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeActivityRepository;
|
|
|
117 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeVisitRepository;
|
| 25837 |
amit.gupta |
118 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 25910 |
amit.gupta |
119 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
| 24653 |
govind |
120 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 25300 |
tejbeer |
121 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
|
|
122 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
| 23724 |
amit.gupta |
123 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
|
|
124 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
125 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24542 |
amit.gupta |
126 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 24669 |
govind |
127 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 25721 |
tejbeer |
128 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
|
|
129 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24542 |
amit.gupta |
130 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 24590 |
amit.gupta |
131 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 24542 |
amit.gupta |
132 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 23724 |
amit.gupta |
133 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 24249 |
amit.gupta |
134 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24277 |
amit.gupta |
135 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24174 |
govind |
136 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 25503 |
amit.gupta |
137 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 23724 |
amit.gupta |
138 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24242 |
amit.gupta |
139 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 24241 |
amit.gupta |
140 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 25982 |
amit.gupta |
141 |
import com.spice.profitmandi.dao.repository.transaction.HdfcPaymentRepository;
|
| 23929 |
amit.gupta |
142 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 25609 |
amit.gupta |
143 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
| 24431 |
amit.gupta |
144 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 24580 |
amit.gupta |
145 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 24587 |
amit.gupta |
146 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 24542 |
amit.gupta |
147 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 25721 |
tejbeer |
148 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 26092 |
amit.gupta |
149 |
import com.spice.profitmandi.service.AuthService;
|
| 25854 |
amit.gupta |
150 |
import com.spice.profitmandi.service.NotificationService;
|
| 24337 |
amit.gupta |
151 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 25694 |
amit.gupta |
152 |
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
|
| 23929 |
amit.gupta |
153 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 25335 |
amit.gupta |
154 |
import com.spice.profitmandi.service.order.OrderService;
|
| 24431 |
amit.gupta |
155 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
156 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
157 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
158 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 24121 |
govind |
159 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23929 |
amit.gupta |
160 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
161 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
162 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23723 |
amit.gupta |
163 |
|
| 25721 |
tejbeer |
164 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 25982 |
amit.gupta |
165 |
import in.shop2020.model.v1.order.WalletReferenceType;;
|
| 23739 |
amit.gupta |
166 |
|
| 23723 |
amit.gupta |
167 |
@Component
|
| 23724 |
amit.gupta |
168 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
169 |
public class ScheduledTasks {
|
|
|
170 |
|
| 23724 |
amit.gupta |
171 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
172 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
173 |
|
| 23724 |
amit.gupta |
174 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
175 |
private String oxigenRechargeEnquiryUrl;
|
| 24533 |
govind |
176 |
|
| 24431 |
amit.gupta |
177 |
@Autowired
|
| 25503 |
amit.gupta |
178 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| 25598 |
amit.gupta |
179 |
|
| 25590 |
amit.gupta |
180 |
@Autowired
|
| 25910 |
amit.gupta |
181 |
private LeadRepository leadRepository;
|
| 25927 |
amit.gupta |
182 |
|
| 25910 |
amit.gupta |
183 |
@Autowired
|
| 25590 |
amit.gupta |
184 |
private AuthRepository authRepository;
|
| 25503 |
amit.gupta |
185 |
|
|
|
186 |
@Autowired
|
| 24431 |
amit.gupta |
187 |
private PriceDropService priceDropService;
|
| 26283 |
tejbeer |
188 |
|
| 25590 |
amit.gupta |
189 |
@Autowired
|
| 25927 |
amit.gupta |
190 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
|
|
191 |
|
|
|
192 |
@Autowired
|
|
|
193 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
|
|
194 |
|
|
|
195 |
@Autowired
|
| 25982 |
amit.gupta |
196 |
private HdfcPaymentRepository hdfcPaymentRepository;
|
|
|
197 |
|
|
|
198 |
@Autowired
|
| 25590 |
amit.gupta |
199 |
private CsService csService;
|
| 25846 |
amit.gupta |
200 |
|
| 25837 |
amit.gupta |
201 |
@Autowired
|
|
|
202 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23723 |
amit.gupta |
203 |
|
| 25694 |
amit.gupta |
204 |
@Autowired
|
|
|
205 |
private ToffeeService toffeeService;
|
|
|
206 |
|
| 23724 |
amit.gupta |
207 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
208 |
private String oxigenRechargeAuthKey;
|
|
|
209 |
|
|
|
210 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
211 |
private String oxigenRechargeValidationUrl;
|
|
|
212 |
|
|
|
213 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
214 |
private String oxigenRechargeValidationAuthKey;
|
|
|
215 |
|
|
|
216 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
217 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
218 |
|
|
|
219 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
220 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
221 |
|
|
|
222 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
223 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
224 |
|
|
|
225 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
226 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
227 |
|
|
|
228 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
229 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
230 |
|
|
|
231 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
232 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
233 |
|
|
|
234 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
235 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
236 |
|
| 23723 |
amit.gupta |
237 |
@Autowired
|
| 23724 |
amit.gupta |
238 |
private PurchaseRepository purchaseRepository;
|
|
|
239 |
|
|
|
240 |
@Autowired
|
| 25609 |
amit.gupta |
241 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
|
|
242 |
|
|
|
243 |
@Autowired
|
|
|
244 |
PriceDropRepository priceDropRepository;
|
|
|
245 |
|
|
|
246 |
@Autowired
|
| 23724 |
amit.gupta |
247 |
private SchemeService schemeService;
|
| 24683 |
amit.gupta |
248 |
|
| 25609 |
amit.gupta |
249 |
private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "amod.sen@smartdukaan.com",
|
|
|
250 |
"adeel.yazdani@smartdukaan.com", "manoj.singh@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
|
|
251 |
"mohinder.mutreja@smartdukaan.com", " ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 25821 |
amit.gupta |
252 |
"chaitnaya.vats@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "prakash.rai@smartdukaan.com" };
|
| 25609 |
amit.gupta |
253 |
|
|
|
254 |
private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
|
| 25821 |
amit.gupta |
255 |
"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com",
|
|
|
256 |
"kuldeep.kumar@smartdukaan.com" };
|
| 25609 |
amit.gupta |
257 |
|
| 25721 |
tejbeer |
258 |
private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
259 |
|
| 25927 |
amit.gupta |
260 |
private Object[] REPORT_HEADERS = { "Store Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager" };
|
|
|
261 |
|
| 24681 |
amit.gupta |
262 |
@Autowired
|
|
|
263 |
private ReporticoService reporticoService;
|
| 23724 |
amit.gupta |
264 |
|
|
|
265 |
@Autowired
|
| 24337 |
amit.gupta |
266 |
private PartnerInvestmentService partnerInvestmentService;
|
| 25598 |
amit.gupta |
267 |
|
| 25590 |
amit.gupta |
268 |
@Autowired
|
|
|
269 |
private PositionRepository positionRepository;
|
| 24337 |
amit.gupta |
270 |
|
|
|
271 |
@Autowired
|
| 24542 |
amit.gupta |
272 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 25865 |
amit.gupta |
273 |
|
| 25854 |
amit.gupta |
274 |
@Autowired
|
|
|
275 |
private NotificationService notificationService;
|
| 24542 |
amit.gupta |
276 |
|
|
|
277 |
@Autowired
|
| 24277 |
amit.gupta |
278 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
279 |
|
|
|
280 |
@Autowired
|
| 24241 |
amit.gupta |
281 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
282 |
|
|
|
283 |
@Autowired
|
| 23724 |
amit.gupta |
284 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
285 |
|
|
|
286 |
@Autowired
|
| 24542 |
amit.gupta |
287 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
288 |
|
|
|
289 |
@Autowired
|
| 23724 |
amit.gupta |
290 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
291 |
|
|
|
292 |
@Autowired
|
| 24590 |
amit.gupta |
293 |
private FofoLineItemRepository fofoLineItemRepository;
|
|
|
294 |
|
|
|
295 |
@Autowired
|
| 23724 |
amit.gupta |
296 |
private FofoOrderRepository fofoOrderRepository;
|
| 24587 |
amit.gupta |
297 |
|
| 24580 |
amit.gupta |
298 |
@Autowired
|
|
|
299 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 24250 |
amit.gupta |
300 |
|
| 24249 |
amit.gupta |
301 |
@Autowired
|
| 24587 |
amit.gupta |
302 |
private UserWalletRepository userWalletRepository;
|
|
|
303 |
|
|
|
304 |
@Autowired
|
| 24249 |
amit.gupta |
305 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
306 |
|
| 23739 |
amit.gupta |
307 |
@Autowired
|
|
|
308 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
309 |
|
|
|
310 |
@Autowired
|
|
|
311 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
312 |
|
|
|
313 |
@Autowired
|
|
|
314 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
315 |
|
|
|
316 |
@Autowired
|
|
|
317 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
318 |
|
|
|
319 |
@Autowired
|
| 24242 |
amit.gupta |
320 |
private ScanRecordRepository scanRecordRepository;
|
|
|
321 |
|
|
|
322 |
@Autowired
|
| 23724 |
amit.gupta |
323 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
324 |
|
| 23929 |
amit.gupta |
325 |
@Autowired
|
|
|
326 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
327 |
|
| 24121 |
govind |
328 |
@Autowired
|
|
|
329 |
private TargetSlabService targetService;
|
| 23929 |
amit.gupta |
330 |
|
| 23724 |
amit.gupta |
331 |
@Value("${prod}")
|
|
|
332 |
private boolean prod;
|
|
|
333 |
|
| 23929 |
amit.gupta |
334 |
@Autowired
|
|
|
335 |
private RetailerService retailerService;
|
|
|
336 |
|
|
|
337 |
@Autowired
|
|
|
338 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
339 |
|
| 24249 |
amit.gupta |
340 |
@Autowired
|
|
|
341 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
342 |
|
|
|
343 |
@Autowired
|
|
|
344 |
private OrderRepository orderRepository;
|
| 25351 |
tejbeer |
345 |
|
| 25335 |
amit.gupta |
346 |
@Autowired
|
|
|
347 |
private OrderService orderService;
|
| 23929 |
amit.gupta |
348 |
|
|
|
349 |
@Autowired
|
| 24241 |
amit.gupta |
350 |
private SchemeRepository schemeRepository;
|
|
|
351 |
|
|
|
352 |
@Autowired
|
| 23929 |
amit.gupta |
353 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
354 |
|
| 24174 |
govind |
355 |
@Autowired
|
|
|
356 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
357 |
|
|
|
358 |
@Autowired
|
|
|
359 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
360 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
361 |
|
|
|
362 |
@Autowired
|
|
|
363 |
private InventoryService inventoryService;
|
|
|
364 |
|
| 24533 |
govind |
365 |
@Autowired
|
| 24542 |
amit.gupta |
366 |
private AddressRepository addressRepository;
|
|
|
367 |
|
|
|
368 |
@Autowired
|
|
|
369 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
370 |
|
| 24653 |
govind |
371 |
@Autowired
|
|
|
372 |
private Mongo mongoClient;
|
| 24683 |
amit.gupta |
373 |
|
| 24669 |
govind |
374 |
@Autowired
|
| 25300 |
tejbeer |
375 |
private DeviceRepository deviceRepository;
|
|
|
376 |
|
|
|
377 |
@Autowired
|
|
|
378 |
private PushNotificationRepository pushNotificationRepository;
|
|
|
379 |
|
|
|
380 |
@Autowired
|
|
|
381 |
private NotificationCampaignRepository notificationCampaignRepository;
|
|
|
382 |
|
|
|
383 |
@Autowired
|
| 25721 |
tejbeer |
384 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
385 |
|
|
|
386 |
@Autowired
|
|
|
387 |
private FocusedModelRepository focusedModelRepository;
|
|
|
388 |
|
|
|
389 |
@Autowired
|
| 24669 |
govind |
390 |
private UserAccountRepository userAccountRepository;
|
| 24653 |
govind |
391 |
|
| 25721 |
tejbeer |
392 |
@Autowired
|
| 25927 |
amit.gupta |
393 |
private UserRepository userUserRepository;
|
| 25721 |
tejbeer |
394 |
|
|
|
395 |
@Autowired
|
| 25927 |
amit.gupta |
396 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
|
|
397 |
|
|
|
398 |
@Autowired
|
| 25721 |
tejbeer |
399 |
private UserCampaignRepository userCampaignRepository;
|
|
|
400 |
|
|
|
401 |
@Autowired
|
|
|
402 |
private Gson gson;
|
|
|
403 |
|
| 26283 |
tejbeer |
404 |
@Autowired
|
|
|
405 |
private TicketRepository ticketRepository;
|
|
|
406 |
|
| 23755 |
amit.gupta |
407 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
408 |
|
| 25300 |
tejbeer |
409 |
private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
|
|
|
410 |
private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
|
|
|
411 |
|
| 23724 |
amit.gupta |
412 |
public void generateDailyRecharge() {
|
|
|
413 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
414 |
.selectAll(0, 2000);
|
|
|
415 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
416 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
417 |
|
|
|
418 |
rechargeProviders.stream().forEach(x -> {
|
|
|
419 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
420 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
421 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
422 |
|
|
|
423 |
LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
|
|
|
424 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
425 |
float previousDayClosing = 0;
|
|
|
426 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
427 |
while (date.isBefore(endDate)) {
|
|
|
428 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
429 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
430 |
date.plusDays(1).atStartOfDay());
|
|
|
431 |
|
|
|
432 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
433 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
434 |
|
|
|
435 |
float dailyAmount = 0;
|
|
|
436 |
float totalCommission = 0;
|
|
|
437 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
438 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
439 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
440 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
441 |
}
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
445 |
float dailyWalletRecharge = 0;
|
|
|
446 |
if (rechargeHistoryList != null) {
|
|
|
447 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
448 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
449 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
450 |
}
|
|
|
451 |
}
|
|
|
452 |
}
|
|
|
453 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
454 |
DailyRecharge dailyRecharge = null;
|
|
|
455 |
try {
|
|
|
456 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
457 |
} catch (Exception e) {
|
|
|
458 |
LOGGER.info("Could not find Recharge entry");
|
|
|
459 |
}
|
|
|
460 |
if (dailyRecharge == null) {
|
|
|
461 |
dailyRecharge = new DailyRecharge();
|
|
|
462 |
dailyRecharge.setCreateDate(date);
|
|
|
463 |
}
|
|
|
464 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
465 |
dailyRecharge.setProviderId(x.getId());
|
|
|
466 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
467 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
468 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
469 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
470 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
471 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
472 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
473 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
474 |
}
|
|
|
475 |
date = date.plusDays(1);
|
|
|
476 |
}
|
|
|
477 |
rechargeProviderRepository.persist(x);
|
|
|
478 |
});
|
| 23761 |
amit.gupta |
479 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
480 |
}
|
|
|
481 |
|
| 23738 |
amit.gupta |
482 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
483 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
484 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
485 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
486 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
487 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
488 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
489 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
490 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
491 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
492 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
493 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
494 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
495 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
496 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
497 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
498 |
try {
|
|
|
499 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
500 |
if (providerId == 1) {
|
|
|
501 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
502 |
rechargeTransaction);
|
|
|
503 |
} else if (providerId == 2) {
|
|
|
504 |
thinkWalnutDigitalRechargeProviderService
|
|
|
505 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
506 |
}
|
|
|
507 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
508 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
509 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
510 |
rechargeTransaction.getStatus());
|
|
|
511 |
}
|
|
|
512 |
} catch (Exception e) {
|
|
|
513 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
514 |
}
|
|
|
515 |
}
|
| 23738 |
amit.gupta |
516 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
517 |
}
|
| 24240 |
amit.gupta |
518 |
|
|
|
519 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
520 |
public void migrateInvoice() {
|
|
|
521 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
522 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
523 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
524 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
525 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
526 |
int sequence = 0;
|
|
|
527 |
String prefix = "";
|
| 24241 |
amit.gupta |
528 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
529 |
.collect(Collectors.toList());
|
|
|
530 |
for (FofoOrder order : sortedList) {
|
|
|
531 |
|
| 24240 |
amit.gupta |
532 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
533 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
534 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
535 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
536 |
} else {
|
|
|
537 |
sequence += 1;
|
| 24241 |
amit.gupta |
538 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
539 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
540 |
fofoOrderRepository.persist(order);
|
|
|
541 |
}
|
|
|
542 |
}
|
| 24241 |
amit.gupta |
543 |
|
| 24237 |
amit.gupta |
544 |
}
|
|
|
545 |
}
|
| 23724 |
amit.gupta |
546 |
|
| 24241 |
amit.gupta |
547 |
// Temporary Method
|
| 24252 |
amit.gupta |
548 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 24244 |
amit.gupta |
549 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
550 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 24252 |
amit.gupta |
551 |
|
| 25837 |
amit.gupta |
552 |
List<List<?>> rows = new ArrayList<>();
|
| 24271 |
amit.gupta |
553 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
554 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 24241 |
amit.gupta |
555 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 24250 |
amit.gupta |
556 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
557 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
558 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
559 |
if (x.getActiveTimestamp() != null) {
|
|
|
560 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
561 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
562 |
endDateTime = x.getExpireTimestamp();
|
| 24249 |
amit.gupta |
563 |
}
|
| 24250 |
amit.gupta |
564 |
for (SchemeInOut sio : sioList) {
|
|
|
565 |
InventoryItem inventoryItem = null;
|
| 24266 |
amit.gupta |
566 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 24271 |
amit.gupta |
567 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
568 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 24250 |
amit.gupta |
569 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
570 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
571 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
572 |
if (record.isPresent()) {
|
|
|
573 |
int fofoId = record.get().getFofoId();
|
|
|
574 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
575 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
576 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
577 |
userAmountMap.put(fofoId, 0f);
|
|
|
578 |
}
|
|
|
579 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
580 |
try {
|
| 24252 |
amit.gupta |
581 |
rows.add(Arrays.asList(x.getDescription(),
|
| 24250 |
amit.gupta |
582 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 24252 |
amit.gupta |
583 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 24253 |
amit.gupta |
584 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
585 |
fofoOrder.getInvoiceNumber(),
|
|
|
586 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
587 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
588 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
589 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
590 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 24250 |
amit.gupta |
591 |
} catch (Exception e) {
|
|
|
592 |
e.printStackTrace();
|
|
|
593 |
}
|
| 24242 |
amit.gupta |
594 |
}
|
| 24241 |
amit.gupta |
595 |
}
|
|
|
596 |
}
|
|
|
597 |
}
|
|
|
598 |
}
|
|
|
599 |
});
|
| 24246 |
amit.gupta |
600 |
userAmountMap.entrySet().stream()
|
|
|
601 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
602 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 24241 |
amit.gupta |
603 |
|
| 24252 |
amit.gupta |
604 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
605 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
606 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
|
|
607 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 24252 |
amit.gupta |
608 |
|
| 24241 |
amit.gupta |
609 |
}
|
| 24271 |
amit.gupta |
610 |
|
| 25584 |
amit.gupta |
611 |
public void processScheme(int offset, boolean dryRun) throws Exception {
|
| 24462 |
amit.gupta |
612 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24259 |
amit.gupta |
613 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 25584 |
amit.gupta |
614 |
processScheme(startDate, endDate, dryRun);
|
| 24256 |
amit.gupta |
615 |
}
|
| 24533 |
govind |
616 |
|
| 25584 |
amit.gupta |
617 |
public void processScheme(int offset, int durationDays, boolean dryRun) throws Exception {
|
| 24462 |
amit.gupta |
618 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24461 |
amit.gupta |
619 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
| 25584 |
amit.gupta |
620 |
processScheme(startDate, endDate, dryRun);
|
| 24461 |
amit.gupta |
621 |
}
|
| 24271 |
amit.gupta |
622 |
|
| 25584 |
amit.gupta |
623 |
public void processScheme(boolean dryRun) throws Exception {
|
| 24256 |
amit.gupta |
624 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
| 25584 |
amit.gupta |
625 |
processScheme(fromDate, LocalDateTime.now(), dryRun);
|
| 24256 |
amit.gupta |
626 |
}
|
| 24271 |
amit.gupta |
627 |
|
| 25584 |
amit.gupta |
628 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate, boolean dryRun) throws Exception {
|
| 23724 |
amit.gupta |
629 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 25312 |
amit.gupta |
630 |
System.out.println(
|
|
|
631 |
"InventoryId\tSerialNumber\tItem Id\tScheme Id\tScheme Name\tScheme Type\tAmount Type\tDP\tTaxable\tScheme Amount\tAmount Paid");
|
| 24561 |
amit.gupta |
632 |
try {
|
| 24587 |
amit.gupta |
633 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
634 |
for (Purchase purchase : purchases) {
|
|
|
635 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
636 |
}
|
| 24271 |
amit.gupta |
637 |
|
| 24587 |
amit.gupta |
638 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
639 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
640 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
641 |
}
|
|
|
642 |
} catch (Exception e) {
|
| 24561 |
amit.gupta |
643 |
e.printStackTrace();
|
| 24565 |
amit.gupta |
644 |
throw e;
|
| 24561 |
amit.gupta |
645 |
}
|
| 25312 |
amit.gupta |
646 |
List<UserWalletHistory> uwhs = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
647 |
Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
| 25043 |
amit.gupta |
648 |
System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
|
| 25312 |
amit.gupta |
649 |
for (UserWalletHistory uwh : uwhs) {
|
|
|
650 |
System.out.println(String.format("%d\t%d\t%s\t%s\t%s", uwh.getAmount(), uwh.getReference(),
|
|
|
651 |
uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
|
| 25043 |
amit.gupta |
652 |
}
|
| 23724 |
amit.gupta |
653 |
LOGGER.info("Schemes process successfully.");
|
| 25598 |
amit.gupta |
654 |
if (dryRun) {
|
| 25584 |
amit.gupta |
655 |
throw new Exception();
|
|
|
656 |
}
|
| 23724 |
amit.gupta |
657 |
}
|
| 23929 |
amit.gupta |
658 |
|
| 23739 |
amit.gupta |
659 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
660 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
661 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
662 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
663 |
.getPendingCashBackRehargeTransactions();
|
|
|
664 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
665 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
666 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
667 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
668 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
669 |
if (Math.round(amount) > 0) {
|
|
|
670 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
|
|
671 |
"Recharge Cashback", Math.round(amount));
|
| 23762 |
amit.gupta |
672 |
}
|
| 23739 |
amit.gupta |
673 |
}
|
| 23929 |
amit.gupta |
674 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
675 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
676 |
rt.setCashbackReference(referenceId);
|
|
|
677 |
rechargeTransactionRepository.persist(rt);
|
|
|
678 |
}
|
| 23739 |
amit.gupta |
679 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
680 |
}
|
| 23724 |
amit.gupta |
681 |
|
| 25598 |
amit.gupta |
682 |
private class SaleRoles {
|
|
|
683 |
|
|
|
684 |
private List<String> l1;
|
|
|
685 |
private List<String> l2;
|
|
|
686 |
|
|
|
687 |
public SaleRoles() {
|
|
|
688 |
l1 = new ArrayList<>();
|
|
|
689 |
l2 = new ArrayList<>();
|
|
|
690 |
}
|
|
|
691 |
|
|
|
692 |
public List<String> getL1() {
|
|
|
693 |
return l1;
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
public List<String> getL2() {
|
|
|
697 |
return l2;
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
}
|
|
|
701 |
|
| 24271 |
amit.gupta |
702 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
703 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 25267 |
amit.gupta |
704 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 23929 |
amit.gupta |
705 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
706 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 25351 |
tejbeer |
707 |
|
| 25598 |
amit.gupta |
708 |
List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory/Team Lead",
|
| 26265 |
amit.gupta |
709 |
"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount", "Grn Pending Amount",
|
| 25598 |
amit.gupta |
710 |
"Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty");
|
| 25837 |
amit.gupta |
711 |
List<List<?>> rows = new ArrayList<>();
|
| 25895 |
amit.gupta |
712 |
Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
|
| 25598 |
amit.gupta |
713 |
|
| 25837 |
amit.gupta |
714 |
Map<Integer, List<Serializable>> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
|
| 25598 |
amit.gupta |
715 |
|
| 24002 |
amit.gupta |
716 |
for (FofoStore fofoStore : fofoStores) {
|
| 25598 |
amit.gupta |
717 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoStore.getId(),
|
|
|
718 |
1);
|
|
|
719 |
partnerDailyInvestment.setDate(yesterDay);
|
|
|
720 |
try {
|
|
|
721 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
|
|
722 |
} catch (Exception e) {
|
|
|
723 |
// ignore the exceptions during persist
|
|
|
724 |
}
|
|
|
725 |
|
| 24002 |
amit.gupta |
726 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 25837 |
amit.gupta |
727 |
if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
|
| 24002 |
amit.gupta |
728 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
729 |
continue;
|
|
|
730 |
}
|
| 25837 |
amit.gupta |
731 |
List<Serializable> row = partnerIdSalesHeaderMap.get(fofoStore.getId());
|
| 25927 |
amit.gupta |
732 |
row.addAll(
|
|
|
733 |
Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
|
| 26265 |
amit.gupta |
734 |
partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-":"("+partnerDailyInvestment.getActivatedStockAmount()+")",
|
| 25927 |
amit.gupta |
735 |
0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
|
|
736 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
|
|
737 |
partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty()));
|
| 25837 |
amit.gupta |
738 |
partnerRowsMap.put(fofoStore.getId(), row);
|
| 24002 |
amit.gupta |
739 |
rows.add(row);
|
|
|
740 |
|
| 23929 |
amit.gupta |
741 |
}
|
| 25312 |
amit.gupta |
742 |
|
| 24271 |
amit.gupta |
743 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 25598 |
amit.gupta |
744 |
|
| 25927 |
amit.gupta |
745 |
if (sendTo == null) {
|
| 25895 |
amit.gupta |
746 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
|
|
747 |
List<List<?>> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerRowsMap.get(x))
|
|
|
748 |
.filter(x -> x != null).collect(Collectors.toList());
|
|
|
749 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
|
|
750 |
String[] sendToArray = new String[] { storeGuyEntry.getKey() };
|
|
|
751 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
752 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
|
|
753 |
}
|
|
|
754 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
|
|
755 |
"prakash.rai@smartdukaan.com", "amit.gupta@shop2020.in", "amod.sen@smartdukaan.com");
|
| 25341 |
amit.gupta |
756 |
}
|
| 25312 |
amit.gupta |
757 |
|
| 25604 |
amit.gupta |
758 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
759 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
| 25609 |
amit.gupta |
760 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
761 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 24271 |
amit.gupta |
762 |
|
| 23929 |
amit.gupta |
763 |
}
|
| 24177 |
govind |
764 |
|
| 25837 |
amit.gupta |
765 |
private Map<Integer, List<Serializable>> getPartnerIdSalesHeaders() {
|
| 25598 |
amit.gupta |
766 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
|
|
767 |
|
|
|
768 |
List<Position> positions = positionRepository
|
|
|
769 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
770 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
|
|
|
771 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
772 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = csService.getPositionCustomRetailerMap(positions);
|
|
|
773 |
for (Position position : positions) {
|
|
|
774 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
| 25609 |
amit.gupta |
775 |
if (crList == null)
|
|
|
776 |
continue;
|
| 25598 |
amit.gupta |
777 |
for (CustomRetailer cr : crList) {
|
|
|
778 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
|
|
779 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
|
|
780 |
}
|
|
|
781 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
|
|
782 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
| 26059 |
amit.gupta |
783 |
if(authUser==null) {
|
|
|
784 |
continue;
|
|
|
785 |
}
|
| 25598 |
amit.gupta |
786 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
787 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
|
|
788 |
saleRoles.getL1().add(name);
|
|
|
789 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
|
|
790 |
saleRoles.getL2().add(name);
|
|
|
791 |
}
|
|
|
792 |
}
|
|
|
793 |
}
|
| 25837 |
amit.gupta |
794 |
|
|
|
795 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
|
|
796 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
|
|
797 |
allCrList.addAll(cr);
|
|
|
798 |
}
|
|
|
799 |
|
|
|
800 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
|
|
|
801 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
802 |
|
|
|
803 |
Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = new HashMap<>();
|
|
|
804 |
|
|
|
805 |
for (CustomRetailer cr : allCrList) {
|
|
|
806 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
| 25927 |
amit.gupta |
807 |
if (fofoStore == null) {
|
| 25870 |
amit.gupta |
808 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
|
|
809 |
continue;
|
|
|
810 |
}
|
| 25865 |
amit.gupta |
811 |
String code = fofoStore.getCode() + "";
|
| 25837 |
amit.gupta |
812 |
String storeName = "SmartDukaan-" + fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
|
|
813 |
String businessName = cr.getBusinessName();
|
|
|
814 |
try {
|
|
|
815 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
816 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
|
|
817 |
List<Serializable> row = new ArrayList<>(
|
|
|
818 |
Arrays.asList(code, businessName, storeName, stateManager, territoryManager));
|
|
|
819 |
partnerIdSalesHeadersMap.put(cr.getPartnerId(), row);
|
|
|
820 |
|
|
|
821 |
} catch (Exception e) {
|
|
|
822 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
|
|
823 |
}
|
|
|
824 |
}
|
|
|
825 |
return partnerIdSalesHeadersMap;
|
|
|
826 |
|
| 25598 |
amit.gupta |
827 |
}
|
|
|
828 |
|
| 24271 |
amit.gupta |
829 |
public void sendPartnerInvestmentDetails() throws Exception {
|
| 25565 |
amit.gupta |
830 |
this.sendPartnerInvestmentDetails(null);
|
| 24271 |
amit.gupta |
831 |
}
|
|
|
832 |
|
| 25312 |
amit.gupta |
833 |
public void sendTargetVsSalesReport(List<String> sendTo) throws Exception {
|
| 24177 |
govind |
834 |
|
| 25312 |
amit.gupta |
835 |
if (sendTo == null) {
|
| 25827 |
amit.gupta |
836 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
|
|
837 |
"amit.gupta@shop2020.in", "amod.sen@smartdukaan.com", "prakash.rai@smartdukaan.com");
|
| 25312 |
amit.gupta |
838 |
}
|
| 25837 |
amit.gupta |
839 |
Map<Integer, List<Serializable>> partnerSalesTargetRowsMap = targetService.getDailySaleReportVsTarget();
|
| 25315 |
amit.gupta |
840 |
|
| 25837 |
amit.gupta |
841 |
Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 24177 |
govind |
842 |
|
| 25837 |
amit.gupta |
843 |
List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager",
|
|
|
844 |
"Current Category", "Target Value", "Target Achieved", "Achived Percentage", "Remaining Target",
|
|
|
845 |
"Today's Target", "Today's achievement");
|
| 25609 |
amit.gupta |
846 |
|
| 25837 |
amit.gupta |
847 |
List<List<?>> rows = new ArrayList<>();
|
|
|
848 |
Map<Integer, List<? extends Serializable>> partnerRowMap = new HashMap<>();
|
|
|
849 |
for (Map.Entry<Integer, List<Serializable>> partnerSalesTargetRowEntry : partnerSalesTargetRowsMap.entrySet()) {
|
|
|
850 |
List<Serializable> row = partnerIdSalesHeadersMap.get(partnerSalesTargetRowEntry.getKey());
|
|
|
851 |
if (row == null) {
|
|
|
852 |
LOGGER.warn("Could not find headers for partner ID - {}", partnerSalesTargetRowEntry.getKey());
|
| 25315 |
amit.gupta |
853 |
}
|
| 25837 |
amit.gupta |
854 |
row.addAll(partnerSalesTargetRowEntry.getValue());
|
|
|
855 |
partnerRowMap.put(partnerSalesTargetRowEntry.getKey(), row);
|
|
|
856 |
rows.add(row);
|
| 24177 |
govind |
857 |
}
|
| 25503 |
amit.gupta |
858 |
|
| 25318 |
amit.gupta |
859 |
String fileName = "TargetVsSales-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 25894 |
amit.gupta |
860 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
|
|
861 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
| 25827 |
amit.gupta |
862 |
if (storeGuyEntry.getValue().size() == 0)
|
|
|
863 |
continue;
|
| 25927 |
amit.gupta |
864 |
List<List<?>> storeGuyRows = storeGuyEntry.getValue().stream().filter(x -> partnerRowMap.containsKey(x))
|
|
|
865 |
.map(x -> partnerRowMap.get(x)).collect(Collectors.toList());
|
| 25827 |
amit.gupta |
866 |
ByteArrayOutputStream authUserStream = FileUtil.getCSVByteStream(headers, storeGuyRows);
|
|
|
867 |
Attachment attache = new Attachment(fileName, new ByteArrayResource(authUserStream.toByteArray()));
|
|
|
868 |
System.out.println(storeGuyEntry.getValue());
|
|
|
869 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
|
|
|
870 |
"Franchise Stock Report", "PFA", attache);
|
|
|
871 |
}
|
| 24240 |
amit.gupta |
872 |
|
| 25312 |
amit.gupta |
873 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
874 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
|
|
875 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA", fileName,
|
|
|
876 |
new ByteArrayResource(baos.toByteArray()));
|
| 24174 |
govind |
877 |
}
|
| 24683 |
amit.gupta |
878 |
|
| 24697 |
amit.gupta |
879 |
public void sendAgeingReport(String... sendTo) throws Exception {
|
| 24692 |
amit.gupta |
880 |
|
|
|
881 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
|
|
|
882 |
"itemstockageing.xml");
|
| 24708 |
amit.gupta |
883 |
InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 24754 |
amit.gupta |
884 |
"ItemwiseOverallPendingIndent.xml");
|
| 24683 |
amit.gupta |
885 |
Attachment attachment = new Attachment(
|
| 25445 |
amit.gupta |
886 |
"ageing-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
|
| 24707 |
amit.gupta |
887 |
Attachment attachment1 = new Attachment(
|
| 25445 |
amit.gupta |
888 |
"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
|
| 25418 |
amit.gupta |
889 |
|
| 25609 |
amit.gupta |
890 |
Utils.sendMailWithAttachments(googleMailSender, STOCK_AGEING_MAIL_LIST, null, "Stock Ageing Report", "PFA",
|
|
|
891 |
attachment);
|
|
|
892 |
Utils.sendMailWithAttachments(googleMailSender, ITEMWISE_PENDING_INDENT_MAIL_LIST, null,
|
|
|
893 |
"Itemwise Pending indent", "PFA", attachment1);
|
|
|
894 |
|
| 25598 |
amit.gupta |
895 |
// Reports to be sent to mapped partners
|
| 25597 |
amit.gupta |
896 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
| 25503 |
amit.gupta |
897 |
|
|
|
898 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
| 25418 |
amit.gupta |
899 |
Map<String, String> params = new HashMap<>();
|
| 25503 |
amit.gupta |
900 |
if (storeGuyEntry.getValue().size() == 0)
|
|
|
901 |
continue;
|
| 25418 |
amit.gupta |
902 |
params.put("MANUAL_email", String.join(",", storeGuyEntry.getValue()));
|
|
|
903 |
InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
904 |
"focostockreport.xml", params);
|
|
|
905 |
Attachment attache = new Attachment(
|
| 25609 |
amit.gupta |
906 |
"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
|
| 25584 |
amit.gupta |
907 |
System.out.println(storeGuyEntry.getValue());
|
| 25609 |
amit.gupta |
908 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
|
|
|
909 |
"Franchise Stock Report", "PFA", attache);
|
| 25418 |
amit.gupta |
910 |
}
|
| 25503 |
amit.gupta |
911 |
|
| 24681 |
amit.gupta |
912 |
}
|
| 24533 |
govind |
913 |
|
| 24697 |
amit.gupta |
914 |
public void sendAgeingReport() throws Exception {
|
| 25807 |
amit.gupta |
915 |
sendAgeingReport("kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 25609 |
amit.gupta |
916 |
"chaitnaya.vats@smartdukaan.com");
|
| 24697 |
amit.gupta |
917 |
}
|
|
|
918 |
|
| 24533 |
govind |
919 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
920 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
921 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
922 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
923 |
}
|
|
|
924 |
}
|
| 23929 |
amit.gupta |
925 |
|
| 24542 |
amit.gupta |
926 |
public void walletmismatch() throws Exception {
|
|
|
927 |
LocalDate curDate = LocalDate.now();
|
| 24553 |
amit.gupta |
928 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 24552 |
amit.gupta |
929 |
System.out.println(pdis.size());
|
| 24542 |
amit.gupta |
930 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 24549 |
amit.gupta |
931 |
int fofoId = pdi.getFofoId();
|
| 24542 |
amit.gupta |
932 |
for (PartnerDailyInvestment investment : Lists
|
|
|
933 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 24552 |
amit.gupta |
934 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 24555 |
amit.gupta |
935 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 24552 |
amit.gupta |
936 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 24841 |
govind |
937 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
|
|
|
938 |
investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
|
| 24551 |
amit.gupta |
939 |
|
| 24542 |
amit.gupta |
940 |
}
|
| 24549 |
amit.gupta |
941 |
}
|
| 24542 |
amit.gupta |
942 |
|
|
|
943 |
}
|
|
|
944 |
|
|
|
945 |
public void gst() throws Exception {
|
| 24548 |
amit.gupta |
946 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2019, 1, 26).atStartOfDay(),
|
|
|
947 |
LocalDate.of(2019, 1, 27).atTime(LocalTime.MAX));
|
|
|
948 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
949 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
950 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 24542 |
amit.gupta |
951 |
|
|
|
952 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
953 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
954 |
Integer stateId = null;
|
|
|
955 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
956 |
try {
|
|
|
957 |
stateId = Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
|
|
|
958 |
} catch (Exception e) {
|
|
|
959 |
LOGGER.error("Unable to get state rates");
|
|
|
960 |
}
|
|
|
961 |
}
|
|
|
962 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
963 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 24548 |
amit.gupta |
964 |
|
|
|
965 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
966 |
Set<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 24542 |
amit.gupta |
967 |
if (stateId != null) {
|
|
|
968 |
itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemIds), stateId);
|
|
|
969 |
} else {
|
|
|
970 |
itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemIds));
|
|
|
971 |
}
|
|
|
972 |
|
| 24548 |
amit.gupta |
973 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 24542 |
amit.gupta |
974 |
if (stateId == null) {
|
|
|
975 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
|
|
976 |
} else {
|
|
|
977 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
|
|
978 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
|
|
979 |
}
|
|
|
980 |
fofoOrderItemRepository.persist(foi);
|
|
|
981 |
}
|
|
|
982 |
}
|
| 24548 |
amit.gupta |
983 |
|
| 24542 |
amit.gupta |
984 |
}
|
|
|
985 |
|
| 24580 |
amit.gupta |
986 |
public void schemewalletmismatch() {
|
|
|
987 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
| 24587 |
amit.gupta |
988 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
| 24580 |
amit.gupta |
989 |
reconcileSchemes(dateToReconcile);
|
| 24587 |
amit.gupta |
990 |
// reconcileOrders(dateTime);
|
|
|
991 |
// reconcileRecharges(dateTime);
|
| 24580 |
amit.gupta |
992 |
dateToReconcile = dateToReconcile.plusDays(1);
|
|
|
993 |
}
|
|
|
994 |
}
|
|
|
995 |
|
|
|
996 |
private void reconcileSchemes(LocalDate date) {
|
|
|
997 |
LocalDateTime startDate = date.atStartOfDay();
|
|
|
998 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
999 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
|
|
1000 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
| 24587 |
amit.gupta |
1001 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1002 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 24580 |
amit.gupta |
1003 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
| 24587 |
amit.gupta |
1004 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
|
|
1005 |
WalletReferenceType.SCHEME_OUT);
|
|
|
1006 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
1007 |
walletReferenceTypes);
|
|
|
1008 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1009 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
| 24580 |
amit.gupta |
1010 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
| 24587 |
amit.gupta |
1011 |
|
|
|
1012 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
|
|
1013 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1014 |
|
|
|
1015 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
|
|
1016 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1017 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
|
|
1018 |
|
|
|
1019 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
|
|
1020 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1021 |
|
|
|
1022 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
|
|
1023 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
|
|
1024 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1025 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
|
|
1026 |
|
|
|
1027 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
| 26092 |
amit.gupta |
1028 |
|
| 24587 |
amit.gupta |
1029 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
|
|
1030 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
|
|
1031 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
|
|
1032 |
} else {
|
|
|
1033 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
|
|
1034 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
|
|
1035 |
}
|
|
|
1036 |
}
|
| 24590 |
amit.gupta |
1037 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
|
|
1038 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
|
|
1039 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1040 |
|
| 24587 |
amit.gupta |
1041 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
|
|
1042 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
|
|
1043 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
|
|
1044 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
|
|
1045 |
if (diff > 5) {
|
|
|
1046 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
|
|
1047 |
}
|
|
|
1048 |
}
|
| 24580 |
amit.gupta |
1049 |
}
|
| 24587 |
amit.gupta |
1050 |
|
| 24580 |
amit.gupta |
1051 |
}
|
| 24590 |
amit.gupta |
1052 |
|
| 24592 |
amit.gupta |
1053 |
public void dryRunSchemeReco() throws Exception {
|
| 24635 |
amit.gupta |
1054 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1055 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1056 |
|
| 24592 |
amit.gupta |
1057 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1058 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24635 |
amit.gupta |
1059 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1060 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1061 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
|
|
1062 |
|
| 25096 |
amit.gupta |
1063 |
LocalDateTime startDate = LocalDate.of(2018, 3, 1).atStartOfDay();
|
| 24635 |
amit.gupta |
1064 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
|
|
1065 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
1066 |
|
| 24683 |
amit.gupta |
1067 |
Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
|
| 24635 |
amit.gupta |
1068 |
purchases.stream().forEach(purchase -> {
|
|
|
1069 |
float amountToRollback = 0;
|
|
|
1070 |
String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
|
|
|
1071 |
+ purchase.getPurchaseReference();
|
|
|
1072 |
Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
|
|
|
1073 |
.stream().filter(ii -> ii.getSerialNumber() != null)
|
|
|
1074 |
.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
|
|
|
1075 |
if (inventorySerialNumberMap.size() > 0) {
|
|
|
1076 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1077 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1078 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1079 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1080 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1081 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1082 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1083 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1084 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1085 |
.collect(Collectors.toList());
|
|
|
1086 |
Collections.reverse(sios);
|
|
|
1087 |
for (SchemeInOut sio : sios) {
|
|
|
1088 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1089 |
amountToRollback += sio.getAmount();
|
|
|
1090 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1091 |
sio.setSerialNumber(serialNumber);
|
|
|
1092 |
rolledbackSios.add(sio);
|
|
|
1093 |
}
|
|
|
1094 |
description = description.concat(" " + serialNumber + " ");
|
|
|
1095 |
} else {
|
|
|
1096 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1097 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1098 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1099 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1100 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1101 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1102 |
.collect(Collectors.toList());
|
|
|
1103 |
Collections.reverse(sios);
|
|
|
1104 |
for (SchemeInOut sio : sios) {
|
|
|
1105 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1106 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1107 |
continue;
|
|
|
1108 |
}
|
|
|
1109 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1110 |
amountToRollback += sio.getAmount();
|
|
|
1111 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1112 |
sio.setSerialNumber(serialNumber);
|
| 24681 |
amit.gupta |
1113 |
sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
|
|
1114 |
sio.setReference(purchase.getId());
|
| 24635 |
amit.gupta |
1115 |
rolledbackSios.add(sio);
|
|
|
1116 |
}
|
|
|
1117 |
}
|
|
|
1118 |
|
|
|
1119 |
}
|
|
|
1120 |
}
|
|
|
1121 |
if (amountToRollback > 0) {
|
| 24683 |
amit.gupta |
1122 |
// Address address =
|
|
|
1123 |
// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
|
| 24635 |
amit.gupta |
1124 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1125 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1126 |
uwh.setDescription(description);
|
|
|
1127 |
uwh.setTimestamp(LocalDateTime.now());
|
| 24681 |
amit.gupta |
1128 |
uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
|
| 24635 |
amit.gupta |
1129 |
uwh.setReference(purchase.getId());
|
|
|
1130 |
uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
|
|
|
1131 |
uwh.setFofoId(purchase.getFofoId());
|
| 24681 |
amit.gupta |
1132 |
uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
| 24635 |
amit.gupta |
1133 |
userWalletHistory.add(uwh);
|
|
|
1134 |
}
|
|
|
1135 |
});
|
|
|
1136 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1137 |
Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
|
|
1138 |
"Timestamp"),
|
|
|
1139 |
userWalletHistory.stream()
|
|
|
1140 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1141 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
|
|
1142 |
.collect(Collectors.toList()));
|
|
|
1143 |
|
|
|
1144 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 24683 |
amit.gupta |
1145 |
Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
|
|
|
1146 |
"Created", "Rolledback"),
|
| 24635 |
amit.gupta |
1147 |
rolledbackSios.stream()
|
| 24681 |
amit.gupta |
1148 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
|
| 24635 |
amit.gupta |
1149 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1150 |
.collect(Collectors.toList()));
|
|
|
1151 |
|
| 25043 |
amit.gupta |
1152 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24636 |
amit.gupta |
1153 |
"Partner Excess Amount Scheme In", "PFA",
|
| 24635 |
amit.gupta |
1154 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
| 24636 |
amit.gupta |
1155 |
new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24635 |
amit.gupta |
1156 |
|
| 25096 |
amit.gupta |
1157 |
throw new Exception();
|
| 24635 |
amit.gupta |
1158 |
|
|
|
1159 |
}
|
|
|
1160 |
|
|
|
1161 |
public void dryRunOutSchemeReco() throws Exception {
|
|
|
1162 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1163 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24606 |
amit.gupta |
1164 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1165 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 24590 |
amit.gupta |
1166 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1167 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 25028 |
amit.gupta |
1168 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
| 24632 |
amit.gupta |
1169 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
| 24631 |
amit.gupta |
1170 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
1171 |
// Collections.reverse(allOrders);
|
|
|
1172 |
// List<FofoOrder> allOrders =
|
| 24653 |
govind |
1173 |
// List<FofoOrder> allOrders =
|
| 24631 |
amit.gupta |
1174 |
// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
|
| 24625 |
amit.gupta |
1175 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
| 24590 |
amit.gupta |
1176 |
allOrders.stream().forEach(fofoOrder -> {
|
| 24592 |
amit.gupta |
1177 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 24598 |
amit.gupta |
1178 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
| 24592 |
amit.gupta |
1179 |
float amountToRollback = 0;
|
| 24590 |
amit.gupta |
1180 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1181 |
orderItems.forEach(x -> {
|
| 24606 |
amit.gupta |
1182 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
| 24598 |
amit.gupta |
1183 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
| 24590 |
amit.gupta |
1184 |
});
|
| 24606 |
amit.gupta |
1185 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24631 |
amit.gupta |
1186 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1187 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1188 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1189 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1190 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1191 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1192 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1193 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1194 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1195 |
.collect(Collectors.toList());
|
|
|
1196 |
Collections.reverse(sios);
|
|
|
1197 |
for (SchemeInOut sio : sios) {
|
|
|
1198 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1199 |
amountToRollback += sio.getAmount();
|
|
|
1200 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1201 |
sio.setSerialNumber(serialNumber);
|
|
|
1202 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 24681 |
amit.gupta |
1203 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1204 |
rolledbackSios.add(sio);
|
| 24623 |
amit.gupta |
1205 |
}
|
| 24635 |
amit.gupta |
1206 |
description = description.concat(" " + serialNumber + " ");
|
| 24631 |
amit.gupta |
1207 |
} else {
|
|
|
1208 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1209 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1210 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1211 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1212 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1213 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1214 |
.collect(Collectors.toList());
|
|
|
1215 |
Collections.reverse(sios);
|
|
|
1216 |
for (SchemeInOut sio : sios) {
|
|
|
1217 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1218 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1219 |
continue;
|
|
|
1220 |
}
|
|
|
1221 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1222 |
amountToRollback += sio.getAmount();
|
|
|
1223 |
// sio.setSchemeType(SchemeType.OUT);
|
| 24681 |
amit.gupta |
1224 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1225 |
sio.setSerialNumber(serialNumber);
|
|
|
1226 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1227 |
rolledbackSios.add(sio);
|
|
|
1228 |
}
|
| 24615 |
amit.gupta |
1229 |
}
|
| 24631 |
amit.gupta |
1230 |
|
| 24604 |
amit.gupta |
1231 |
}
|
| 24590 |
amit.gupta |
1232 |
}
|
| 24631 |
amit.gupta |
1233 |
if (amountToRollback > 0) {
|
|
|
1234 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1235 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1236 |
uwh.setDescription(description);
|
|
|
1237 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1238 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1239 |
uwh.setReference(fofoOrder.getId());
|
|
|
1240 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1241 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1242 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1243 |
userWalletHistory.add(uwh);
|
|
|
1244 |
}
|
| 24590 |
amit.gupta |
1245 |
});
|
| 24598 |
amit.gupta |
1246 |
|
| 24592 |
amit.gupta |
1247 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 24681 |
amit.gupta |
1248 |
Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
| 24615 |
amit.gupta |
1249 |
"Timestamp"),
|
|
|
1250 |
userWalletHistory.stream()
|
|
|
1251 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1252 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24592 |
amit.gupta |
1253 |
.collect(Collectors.toList()));
|
|
|
1254 |
|
|
|
1255 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1256 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1257 |
"Rolledback"),
|
|
|
1258 |
rolledbackSios.stream()
|
|
|
1259 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1260 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1261 |
.collect(Collectors.toList()));
|
|
|
1262 |
|
| 25043 |
amit.gupta |
1263 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24681 |
amit.gupta |
1264 |
"Partner Excess Amount Scheme Out", "PFA",
|
| 24598 |
amit.gupta |
1265 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1266 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1267 |
|
| 25267 |
amit.gupta |
1268 |
throw new Exception();
|
| 24590 |
amit.gupta |
1269 |
}
|
| 24615 |
amit.gupta |
1270 |
|
| 24611 |
amit.gupta |
1271 |
public void dryRunSchemeOutReco1() throws Exception {
|
| 24615 |
amit.gupta |
1272 |
List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
|
| 24611 |
amit.gupta |
1273 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1274 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
|
|
1275 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1276 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1277 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1278 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1279 |
references.stream().forEach(reference -> {
|
|
|
1280 |
FofoOrder fofoOrder = null;
|
|
|
1281 |
try {
|
|
|
1282 |
fofoOrder = fofoOrderRepository.selectByOrderId(reference);
|
| 24615 |
amit.gupta |
1283 |
} catch (Exception e) {
|
|
|
1284 |
|
| 24611 |
amit.gupta |
1285 |
}
|
|
|
1286 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
|
|
1287 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
|
|
1288 |
float amountToRollback = 0;
|
|
|
1289 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1290 |
orderItems.forEach(x -> {
|
|
|
1291 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
|
|
1292 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
|
|
1293 |
});
|
|
|
1294 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24615 |
amit.gupta |
1295 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1296 |
.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
|
|
|
1297 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24611 |
amit.gupta |
1298 |
.collect(Collectors.toList());
|
|
|
1299 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
|
|
1300 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 24615 |
amit.gupta |
1301 |
Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
|
|
|
1302 |
.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
|
| 24611 |
amit.gupta |
1303 |
for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
|
|
|
1304 |
List<SchemeInOut> outList = inventorySioEntry.getValue();
|
| 24615 |
amit.gupta |
1305 |
if (outList.size() > 1) {
|
|
|
1306 |
|
| 24611 |
amit.gupta |
1307 |
}
|
|
|
1308 |
}
|
|
|
1309 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1310 |
uwh.setDescription(description);
|
|
|
1311 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1312 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1313 |
uwh.setReference(fofoOrder.getId());
|
|
|
1314 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1315 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1316 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1317 |
userWalletHistory.add(uwh);
|
|
|
1318 |
}
|
|
|
1319 |
});
|
| 24615 |
amit.gupta |
1320 |
|
| 24611 |
amit.gupta |
1321 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1322 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
|
|
1323 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
|
|
1324 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24615 |
amit.gupta |
1325 |
.collect(Collectors.toList()));
|
|
|
1326 |
|
| 24611 |
amit.gupta |
1327 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1328 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1329 |
"Rolledback"),
|
|
|
1330 |
rolledbackSios.stream()
|
| 24615 |
amit.gupta |
1331 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1332 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1333 |
.collect(Collectors.toList()));
|
|
|
1334 |
|
| 24623 |
amit.gupta |
1335 |
Utils.sendMailWithAttachments(googleMailSender,
|
|
|
1336 |
new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
|
| 24611 |
amit.gupta |
1337 |
"Partner Excess Amount", "PFA",
|
|
|
1338 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1339 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1340 |
|
| 24628 |
amit.gupta |
1341 |
throw new Exception();
|
| 24615 |
amit.gupta |
1342 |
|
| 24611 |
amit.gupta |
1343 |
}
|
| 24615 |
amit.gupta |
1344 |
|
| 25837 |
amit.gupta |
1345 |
public void sendDailySalesNotificationToPartner(Integer fofoIdInt)
|
| 24653 |
govind |
1346 |
throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 25927 |
amit.gupta |
1347 |
|
| 24653 |
govind |
1348 |
LocalDateTime now = LocalDateTime.now();
|
| 25837 |
amit.gupta |
1349 |
LocalDateTime from = now.with(LocalTime.MIN);
|
| 25925 |
amit.gupta |
1350 |
String timeString = "Today %s";
|
| 25927 |
amit.gupta |
1351 |
// Send yesterday's report
|
|
|
1352 |
if (now.getHour() < 13) {
|
| 25925 |
amit.gupta |
1353 |
timeString = "Yesterday %s";
|
| 25910 |
amit.gupta |
1354 |
from = now.minusDays(1);
|
|
|
1355 |
now = from.with(LocalTime.MAX);
|
| 25927 |
amit.gupta |
1356 |
|
| 25910 |
amit.gupta |
1357 |
}
|
| 24855 |
amit.gupta |
1358 |
List<Integer> fofoIds = null;
|
| 25043 |
amit.gupta |
1359 |
if (fofoIdInt == null) {
|
|
|
1360 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
1361 |
.collect(Collectors.toList());
|
| 24856 |
amit.gupta |
1362 |
} else {
|
| 24855 |
amit.gupta |
1363 |
fofoIds = Arrays.asList(fofoIdInt);
|
|
|
1364 |
}
|
| 25912 |
amit.gupta |
1365 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
| 24683 |
amit.gupta |
1366 |
|
| 25865 |
amit.gupta |
1367 |
Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
|
|
|
1368 |
Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
|
|
|
1369 |
null);
|
|
|
1370 |
Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
|
|
|
1371 |
Map<Integer, Double> partnerOrderAmountMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
|
|
|
1372 |
0, true);
|
|
|
1373 |
Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
|
|
|
1374 |
Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
|
|
|
1375 |
for (int fofoId : fofoIds) {
|
|
|
1376 |
SaleTargetReportModel model = new SaleTargetReportModel();
|
| 25927 |
amit.gupta |
1377 |
model.setInsuranceSale(
|
|
|
1378 |
partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
|
| 25865 |
amit.gupta |
1379 |
model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
|
|
|
1380 |
model.setSmartphoneSale(partnerOrderAmountMap.containsKey(fofoId) ? partnerOrderAmountMap.get(fofoId) : 0);
|
|
|
1381 |
model.setSmartphoneQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
|
|
|
1382 |
model.setTotalSale(salesByFofoIdMap.containsKey(fofoId) ? salesByFofoIdMap.get(fofoId) : 0);
|
| 25880 |
amit.gupta |
1383 |
model.setFofoId(fofoId);
|
| 25865 |
amit.gupta |
1384 |
saleTargetReportModelMap.put(fofoId, model);
|
|
|
1385 |
}
|
| 25880 |
amit.gupta |
1386 |
|
| 25865 |
amit.gupta |
1387 |
Map<Integer, List<Serializable>> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 24653 |
govind |
1388 |
for (Integer fofoId : fofoIds) {
|
| 25865 |
amit.gupta |
1389 |
SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
|
| 25821 |
amit.gupta |
1390 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1391 |
sendNotificationModel.setCampaignName("Sales update alert");
|
| 25884 |
tejbeer |
1392 |
sendNotificationModel.setTitle("Sale Update");
|
| 25927 |
amit.gupta |
1393 |
sendNotificationModel
|
|
|
1394 |
.setMessage(String.format("Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
|
|
1395 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
|
|
1396 |
String.format(timeString, now.format(timeFormatter))));
|
| 25821 |
amit.gupta |
1397 |
sendNotificationModel.setType("url");
|
|
|
1398 |
sendNotificationModel.setUrl("http://app.profitmandi.com/pages/home/notifications");
|
|
|
1399 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
1400 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25872 |
tejbeer |
1401 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
|
|
1402 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 25854 |
amit.gupta |
1403 |
notificationService.sendNotification(sendNotificationModel);
|
| 24653 |
govind |
1404 |
}
|
| 25865 |
amit.gupta |
1405 |
String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap, saleTargetReportModelMap);
|
| 24653 |
govind |
1406 |
LOGGER.info(saleReport);
|
| 25837 |
amit.gupta |
1407 |
String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
|
| 25846 |
amit.gupta |
1408 |
"chaitnaya.vats@smartdukaan.com" };
|
| 25837 |
amit.gupta |
1409 |
|
| 25912 |
amit.gupta |
1410 |
String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
|
| 25821 |
amit.gupta |
1411 |
this.sendMailOfHtmlFomat("amit.gupta@shop2020.in", saleReport, cc, subject);
|
| 24653 |
govind |
1412 |
}
|
|
|
1413 |
|
| 25865 |
amit.gupta |
1414 |
public static class SaleTargetReportModel {
|
|
|
1415 |
private double totalSale;
|
| 25880 |
amit.gupta |
1416 |
private int fofoId;
|
|
|
1417 |
|
|
|
1418 |
public int getFofoId() {
|
|
|
1419 |
return fofoId;
|
|
|
1420 |
}
|
|
|
1421 |
|
|
|
1422 |
public void setFofoId(int fofoId) {
|
|
|
1423 |
this.fofoId = fofoId;
|
|
|
1424 |
}
|
|
|
1425 |
|
| 25865 |
amit.gupta |
1426 |
private double smartphoneSale;
|
|
|
1427 |
private long smartphoneQty;
|
|
|
1428 |
private double insuranceSale;
|
|
|
1429 |
private long insruanceQty;
|
|
|
1430 |
|
|
|
1431 |
@Override
|
|
|
1432 |
public int hashCode() {
|
|
|
1433 |
final int prime = 31;
|
|
|
1434 |
int result = 1;
|
| 25880 |
amit.gupta |
1435 |
result = prime * result + fofoId;
|
| 25865 |
amit.gupta |
1436 |
result = prime * result + (int) (insruanceQty ^ (insruanceQty >>> 32));
|
|
|
1437 |
long temp;
|
|
|
1438 |
temp = Double.doubleToLongBits(insuranceSale);
|
|
|
1439 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1440 |
result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
|
|
|
1441 |
temp = Double.doubleToLongBits(smartphoneSale);
|
|
|
1442 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1443 |
temp = Double.doubleToLongBits(totalSale);
|
|
|
1444 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1445 |
return result;
|
|
|
1446 |
}
|
|
|
1447 |
|
|
|
1448 |
@Override
|
|
|
1449 |
public boolean equals(Object obj) {
|
|
|
1450 |
if (this == obj)
|
|
|
1451 |
return true;
|
|
|
1452 |
if (obj == null)
|
|
|
1453 |
return false;
|
|
|
1454 |
if (getClass() != obj.getClass())
|
|
|
1455 |
return false;
|
|
|
1456 |
SaleTargetReportModel other = (SaleTargetReportModel) obj;
|
| 25880 |
amit.gupta |
1457 |
if (fofoId != other.fofoId)
|
|
|
1458 |
return false;
|
| 25865 |
amit.gupta |
1459 |
if (insruanceQty != other.insruanceQty)
|
|
|
1460 |
return false;
|
|
|
1461 |
if (Double.doubleToLongBits(insuranceSale) != Double.doubleToLongBits(other.insuranceSale))
|
|
|
1462 |
return false;
|
|
|
1463 |
if (smartphoneQty != other.smartphoneQty)
|
|
|
1464 |
return false;
|
|
|
1465 |
if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
|
|
|
1466 |
return false;
|
|
|
1467 |
if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
|
|
|
1468 |
return false;
|
|
|
1469 |
return true;
|
|
|
1470 |
}
|
|
|
1471 |
|
|
|
1472 |
public double getTotalSale() {
|
|
|
1473 |
return totalSale;
|
|
|
1474 |
}
|
|
|
1475 |
|
|
|
1476 |
public void setTotalSale(double totalSale) {
|
|
|
1477 |
this.totalSale = totalSale;
|
|
|
1478 |
}
|
|
|
1479 |
|
|
|
1480 |
public double getSmartphoneSale() {
|
|
|
1481 |
return smartphoneSale;
|
|
|
1482 |
}
|
|
|
1483 |
|
|
|
1484 |
public void setSmartphoneSale(double smartphoneSale) {
|
|
|
1485 |
this.smartphoneSale = smartphoneSale;
|
|
|
1486 |
}
|
|
|
1487 |
|
|
|
1488 |
public long getSmartphoneQty() {
|
|
|
1489 |
return smartphoneQty;
|
|
|
1490 |
}
|
|
|
1491 |
|
|
|
1492 |
public void setSmartphoneQty(long smartphoneQty) {
|
|
|
1493 |
this.smartphoneQty = smartphoneQty;
|
|
|
1494 |
}
|
|
|
1495 |
|
|
|
1496 |
public double getInsuranceSale() {
|
|
|
1497 |
return insuranceSale;
|
|
|
1498 |
}
|
|
|
1499 |
|
|
|
1500 |
public void setInsuranceSale(double insuranceSale) {
|
|
|
1501 |
this.insuranceSale = insuranceSale;
|
|
|
1502 |
}
|
|
|
1503 |
|
|
|
1504 |
public long getInsruanceQty() {
|
|
|
1505 |
return insruanceQty;
|
|
|
1506 |
}
|
|
|
1507 |
|
|
|
1508 |
public void setInsruanceQty(long insruanceQty) {
|
|
|
1509 |
this.insruanceQty = insruanceQty;
|
|
|
1510 |
}
|
|
|
1511 |
|
|
|
1512 |
@Override
|
|
|
1513 |
public String toString() {
|
| 25880 |
amit.gupta |
1514 |
return "SaleTargetReportModel [totalSale=" + totalSale + ", fofoId=" + fofoId + ", smartphoneSale="
|
|
|
1515 |
+ smartphoneSale + ", smartphoneQty=" + smartphoneQty + ", insuranceSale=" + insuranceSale
|
|
|
1516 |
+ ", insruanceQty=" + insruanceQty + "]";
|
| 25865 |
amit.gupta |
1517 |
}
|
|
|
1518 |
|
|
|
1519 |
}
|
|
|
1520 |
|
|
|
1521 |
private String getDailySalesReportHtml(Map<Integer, List<Serializable>> partnerSalesHeadersMap,
|
| 25872 |
tejbeer |
1522 |
Map<Integer, SaleTargetReportModel> saleReportTargetMap) throws ProfitMandiBusinessException {
|
| 24653 |
govind |
1523 |
StringBuilder sb = new StringBuilder();
|
| 25872 |
tejbeer |
1524 |
|
| 25832 |
amit.gupta |
1525 |
sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 24653 |
govind |
1526 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 25865 |
amit.gupta |
1527 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1528 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1529 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1530 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1531 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
| 24653 |
govind |
1532 |
+ " <th style='border:1px solid black;padding: 5px'>Sale</th>\n"
|
| 25865 |
amit.gupta |
1533 |
+ " <th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>\n"
|
|
|
1534 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>\n"
|
|
|
1535 |
+ " <th style='border:1px solid black;padding: 5px'>Insurance Sale</th>\n"
|
|
|
1536 |
+ " <th style='border:1px solid black;padding: 5px'>Insurance Qty</th>\n"
|
| 24653 |
govind |
1537 |
+ " </tr>");
|
| 25880 |
amit.gupta |
1538 |
List<Integer> sortedPartnerSalesHeaders = partnerSalesHeadersMap.entrySet().stream()
|
|
|
1539 |
.sorted((x, y) -> ((String) (x.getValue().get(3))).compareTo((String) (y.getValue().get(3))))
|
| 25927 |
amit.gupta |
1540 |
.map(x -> x.getKey()).collect(Collectors.toList());
|
|
|
1541 |
for (Integer fofoId : sortedPartnerSalesHeaders) {
|
| 25865 |
amit.gupta |
1542 |
sb.append("<tr>");
|
| 25880 |
amit.gupta |
1543 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(0)
|
|
|
1544 |
+ "</td>");
|
|
|
1545 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(1)
|
|
|
1546 |
+ "</td>");
|
|
|
1547 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(2)
|
|
|
1548 |
+ "</td>");
|
|
|
1549 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(3)
|
|
|
1550 |
+ "</td>");
|
|
|
1551 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(4)
|
|
|
1552 |
+ "</td>");
|
|
|
1553 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1554 |
+ saleReportTargetMap.get(fofoId).getTotalSale() + "</td>");
|
|
|
1555 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1556 |
+ saleReportTargetMap.get(fofoId).getSmartphoneSale() + "</td>");
|
|
|
1557 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1558 |
+ saleReportTargetMap.get(fofoId).getSmartphoneQty() + "</td>");
|
|
|
1559 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1560 |
+ saleReportTargetMap.get(fofoId).getInsuranceSale() + "</td>");
|
|
|
1561 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1562 |
+ saleReportTargetMap.get(fofoId).getInsruanceQty() + "</td>");
|
| 25865 |
amit.gupta |
1563 |
sb.append("</tr>");
|
| 24653 |
govind |
1564 |
|
|
|
1565 |
}
|
| 24683 |
amit.gupta |
1566 |
|
| 24653 |
govind |
1567 |
sb.append("</tbody></table></body></html>");
|
| 25865 |
amit.gupta |
1568 |
return String.format(sb.toString(), REPORT_HEADERS);
|
| 24653 |
govind |
1569 |
}
|
| 24841 |
govind |
1570 |
|
|
|
1571 |
private void sendMailOfHtmlFomat(String email, String body, String cc[], String subject)
|
|
|
1572 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
1573 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
1574 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
1575 |
helper.setSubject(subject);
|
|
|
1576 |
helper.setText(body, true);
|
|
|
1577 |
helper.setTo(email);
|
|
|
1578 |
if (cc != null) {
|
|
|
1579 |
helper.setCc(cc);
|
|
|
1580 |
}
|
|
|
1581 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
1582 |
helper.setFrom(senderAddress);
|
|
|
1583 |
mailSender.send(message);
|
|
|
1584 |
}
|
| 25300 |
tejbeer |
1585 |
|
| 25351 |
tejbeer |
1586 |
public void sendNotification() throws Exception {
|
| 25300 |
tejbeer |
1587 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
|
|
1588 |
if (!pushNotifications.isEmpty()) {
|
|
|
1589 |
for (PushNotifications pushNotification : pushNotifications) {
|
| 25351 |
tejbeer |
1590 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
| 25300 |
tejbeer |
1591 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
|
|
1592 |
.selectById(pushNotification.getNotificationCampaignid());
|
|
|
1593 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
|
|
1594 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
|
|
1595 |
|
|
|
1596 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
1597 |
SimpleCampaignParams.class);
|
|
|
1598 |
Campaign campaign = new SimpleCampaign(scp);
|
| 25351 |
tejbeer |
1599 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
| 25300 |
tejbeer |
1600 |
JSONObject json = new JSONObject();
|
| 25351 |
tejbeer |
1601 |
json.put("to", device.getFcmId());
|
| 25300 |
tejbeer |
1602 |
JSONObject jsonObj = new JSONObject();
|
|
|
1603 |
jsonObj.put("message", campaign.getMessage());
|
|
|
1604 |
jsonObj.put("title", campaign.getTitle());
|
|
|
1605 |
jsonObj.put("type", campaign.getType());
|
|
|
1606 |
jsonObj.put("url", result_url);
|
|
|
1607 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
|
|
1608 |
jsonObj.put("image", campaign.getImageUrl());
|
|
|
1609 |
jsonObj.put("largeIcon", "large_icon");
|
|
|
1610 |
jsonObj.put("smallIcon", "small_icon");
|
|
|
1611 |
jsonObj.put("vibrate", 1);
|
|
|
1612 |
jsonObj.put("pid", pushNotification.getId());
|
|
|
1613 |
jsonObj.put("sound", 1);
|
|
|
1614 |
jsonObj.put("priority", "high");
|
|
|
1615 |
json.put("data", jsonObj);
|
| 25351 |
tejbeer |
1616 |
try {
|
|
|
1617 |
CloseableHttpClient client = HttpClients.createDefault();
|
|
|
1618 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| 25300 |
tejbeer |
1619 |
|
| 25351 |
tejbeer |
1620 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
|
|
1621 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
|
|
1622 |
StringEntity entity = new StringEntity(json.toString());
|
|
|
1623 |
httpPost.setEntity(entity);
|
|
|
1624 |
CloseableHttpResponse response = client.execute(httpPost);
|
|
|
1625 |
LOGGER.info("response" + response);
|
| 25300 |
tejbeer |
1626 |
|
| 25351 |
tejbeer |
1627 |
if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
1628 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
|
|
1629 |
} else {
|
| 25356 |
tejbeer |
1630 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 25778 |
amit.gupta |
1631 |
LOGGER.info("message" + "not sent");
|
| 25351 |
tejbeer |
1632 |
}
|
| 25300 |
tejbeer |
1633 |
|
| 25351 |
tejbeer |
1634 |
} catch (Exception e) {
|
|
|
1635 |
e.printStackTrace();
|
| 25300 |
tejbeer |
1636 |
LOGGER.info("message" + "not sent");
|
|
|
1637 |
}
|
|
|
1638 |
}
|
|
|
1639 |
}
|
|
|
1640 |
}
|
|
|
1641 |
|
| 25553 |
amit.gupta |
1642 |
public void grouping() throws Exception {
|
| 25609 |
amit.gupta |
1643 |
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM-dd-yyyy hh:mm");
|
|
|
1644 |
List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByStatus(PriceDropImeiStatus.APPROVED);
|
|
|
1645 |
System.out.println(String.join("\t",
|
|
|
1646 |
Arrays.asList("IMEI", "ItemId", "Brand", "Model Name", "Model Number", "Franchise Id", "Franchise Name",
|
| 25694 |
amit.gupta |
1647 |
"Grn On", "Price Dropped On", "Approved On", "Returned On", "Price Drop Paid", "Is Doa")));
|
| 25609 |
amit.gupta |
1648 |
Map<Integer, CustomRetailer> retailersMap = retailerService.getFofoRetailers();
|
|
|
1649 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
| 25694 |
amit.gupta |
1650 |
if (priceDropIMEI.getPartnerId() == 0)
|
|
|
1651 |
continue;
|
| 25609 |
amit.gupta |
1652 |
HashSet<String> imeis = new HashSet<>();
|
|
|
1653 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropIMEI.getPriceDropId());
|
|
|
1654 |
imeis.add(priceDropIMEI.getImei());
|
|
|
1655 |
List<InventoryItem> inventoryItems = inventoryItemRepository
|
|
|
1656 |
.selectByFofoIdSerialNumbers(priceDropIMEI.getPartnerId(), imeis, false);
|
| 25694 |
amit.gupta |
1657 |
if (inventoryItems.size() == 0) {
|
|
|
1658 |
LOGGER.info("Need to investigate partnerId - {} imeis - {}", priceDropIMEI.getPartnerId(), imeis);
|
| 25613 |
amit.gupta |
1659 |
continue;
|
| 25612 |
amit.gupta |
1660 |
}
|
| 25609 |
amit.gupta |
1661 |
InventoryItem inventoryItem = inventoryItems.get(0);
|
|
|
1662 |
CustomRetailer customRetailer = retailersMap.get(inventoryItem.getFofoId());
|
|
|
1663 |
if (inventoryItem.getLastScanType().equals(ScanType.DOA_OUT)
|
|
|
1664 |
|| inventoryItem.getLastScanType().equals(ScanType.PURCHASE_RET)) {
|
|
|
1665 |
// check if pricedrop has been rolled out
|
|
|
1666 |
List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
|
|
|
1667 |
priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
|
|
|
1668 |
if (uwh.size() > 0) {
|
| 25615 |
amit.gupta |
1669 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 25609 |
amit.gupta |
1670 |
System.out.println(String.join("\t",
|
|
|
1671 |
Arrays.asList(priceDropIMEI.getImei(), inventoryItem.getItemId() + "", item.getBrand(),
|
|
|
1672 |
item.getModelName(), item.getModelNumber(), inventoryItem.getFofoId() + "",
|
|
|
1673 |
customRetailer.getBusinessName(), inventoryItem.getCreateTimestamp().format(dtf),
|
|
|
1674 |
priceDrop.getAffectedOn().format(dtf),
|
|
|
1675 |
priceDropIMEI.getUpdateTimestamp().format(dtf),
|
| 26344 |
amit.gupta |
1676 |
inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
|
| 25609 |
amit.gupta |
1677 |
inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
|
|
|
1678 |
}
|
|
|
1679 |
}
|
|
|
1680 |
}
|
| 25503 |
amit.gupta |
1681 |
}
|
| 25694 |
amit.gupta |
1682 |
|
|
|
1683 |
public void testToffee() throws Exception {
|
| 25846 |
amit.gupta |
1684 |
LOGGER.info("Insurance Sum Summary --- {}",
|
|
|
1685 |
insurancePolicyRepository.selectAmountSumGroupByRetailerId(LocalDateTime.MIN, LocalDateTime.MAX));
|
|
|
1686 |
LOGGER.info("Insurance Qty Summary --- {}",
|
|
|
1687 |
insurancePolicyRepository.selectQtyGroupByRetailerId(LocalDateTime.MIN, LocalDateTime.MAX));
|
| 25854 |
amit.gupta |
1688 |
LOGGER.info("SmartPhone Amount Summary --- {}",
|
| 25856 |
amit.gupta |
1689 |
fofoOrderItemRepository.selectSumAmountGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
|
| 25854 |
amit.gupta |
1690 |
LOGGER.info("Smartphone Qty Summary --- {}",
|
|
|
1691 |
fofoOrderItemRepository.selectQtyGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
|
| 25800 |
tejbeer |
1692 |
// LOGGER.info("{}", toffeeService.getAuthToken());
|
| 25846 |
amit.gupta |
1693 |
/*
|
|
|
1694 |
* LOGGER.info("{}", toffeeService.getProducts()); // LOGGER.info("{}",
|
|
|
1695 |
* toffeeService.getPincodes("36103000PR")); PremiumCalculationRequestModel pcrm
|
|
|
1696 |
* = new PremiumCalculationRequestModel(); pcrm.setProductDetails("36103000PR");
|
|
|
1697 |
* // pcrm.setProductDetails("36103000PR");
|
|
|
1698 |
* pcrm.setDurations(Arrays.asList("3 Months", "6 Months", "1 Year"));
|
|
|
1699 |
* pcrm.setSumInsured("15000");
|
|
|
1700 |
* System.out.println(toffeeService.getPremiumCalculation(pcrm));
|
|
|
1701 |
*/
|
| 25694 |
amit.gupta |
1702 |
}
|
|
|
1703 |
|
|
|
1704 |
public void schemeRollback(List<String> schemeIds) throws Exception {
|
|
|
1705 |
List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
|
| 25708 |
amit.gupta |
1706 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()
|
| 25694 |
amit.gupta |
1707 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1708 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIdsInt));
|
|
|
1709 |
for (SchemeInOut sio : schemeInOuts) {
|
|
|
1710 |
Scheme scheme = schemesMap.get(sio.getSchemeId());
|
|
|
1711 |
if (scheme.getType().equals(SchemeType.IN)) {
|
|
|
1712 |
|
|
|
1713 |
} else if (scheme.getType().equals(SchemeType.OUT)) {
|
|
|
1714 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
|
|
1715 |
List<ScanRecord> sr = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId());
|
|
|
1716 |
ScanRecord scanRecord = sr.stream().filter(x -> x.getType().equals(ScanType.SALE))
|
|
|
1717 |
.max((x1, x2) -> x1.getCreateTimestamp().compareTo(x2.getCreateTimestamp())).get();
|
|
|
1718 |
if (scanRecord.getCreateTimestamp().isAfter(scheme.getEndDateTime())
|
|
|
1719 |
|| scanRecord.getCreateTimestamp().isBefore(scheme.getStartDateTime())) {
|
|
|
1720 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1721 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
|
| 25709 |
amit.gupta |
1722 |
String rollbackReason = "Scheme reversed for "
|
|
|
1723 |
+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
|
| 25694 |
amit.gupta |
1724 |
+ fofoOrder.getInvoiceNumber();
|
|
|
1725 |
walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
|
|
|
1726 |
scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason);
|
|
|
1727 |
System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
|
|
|
1728 |
rollbackReason);
|
|
|
1729 |
}
|
|
|
1730 |
}
|
|
|
1731 |
}
|
| 25721 |
tejbeer |
1732 |
// throw new Exception();
|
| 25694 |
amit.gupta |
1733 |
}
|
| 25721 |
tejbeer |
1734 |
|
|
|
1735 |
public void checkfocusedModelInPartnerStock() throws Exception {
|
|
|
1736 |
|
|
|
1737 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
1738 |
.collect(Collectors.toList());
|
|
|
1739 |
Map<Integer, List<FocusedModelShortageModel>> focusedModelShortageReportMap = new HashMap<>();
|
|
|
1740 |
for (Integer fofoId : fofoIds) {
|
|
|
1741 |
if (!focusedModelShortageReportMap.containsKey(fofoId)) {
|
|
|
1742 |
focusedModelShortageReportMap.put(fofoId, new ArrayList<>());
|
|
|
1743 |
}
|
|
|
1744 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
1745 |
Map<Integer, Integer> processingOrderMap = null;
|
|
|
1746 |
Map<Integer, Integer> catalogIdAndQtyMap = null;
|
|
|
1747 |
Map<Integer, Integer> grnPendingOrdersMap = null;
|
|
|
1748 |
|
|
|
1749 |
Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
|
|
|
1750 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
1751 |
|
|
|
1752 |
if (!currentInventorySnapshot.isEmpty()) {
|
|
|
1753 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
|
|
1754 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1755 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
|
|
1756 |
|
|
|
1757 |
}
|
|
|
1758 |
|
|
|
1759 |
Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
|
|
1760 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1761 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1762 |
if (!grnPendingOrders.isEmpty()) {
|
|
|
1763 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
|
|
1764 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1765 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
|
|
1766 |
|
|
|
1767 |
}
|
|
|
1768 |
|
|
|
1769 |
Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
|
|
|
1770 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1771 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1772 |
if (!processingOrder.isEmpty()) {
|
|
|
1773 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
|
|
1774 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1775 |
Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
|
|
1776 |
|
|
|
1777 |
}
|
|
|
1778 |
|
| 25800 |
tejbeer |
1779 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
1780 |
.collect(Collectors.toList());
|
|
|
1781 |
|
|
|
1782 |
List<Integer> focusedModelCatalogId = focusedModelRepository.selectAll().stream().map(x -> x.getCatalogId())
|
|
|
1783 |
.collect(Collectors.toList());
|
|
|
1784 |
Map<String, Object> equalsMap = new HashMap<>();
|
|
|
1785 |
equalsMap.put("categoryId", 10006);
|
|
|
1786 |
equalsMap.put("brand", brands);
|
|
|
1787 |
|
|
|
1788 |
Map<String, List<?>> notEqualsMap = new HashMap<>();
|
|
|
1789 |
|
|
|
1790 |
Map<String, Object> equalsJoinMap = new HashMap<>();
|
|
|
1791 |
equalsJoinMap.put("catalogId", focusedModelCatalogId);
|
|
|
1792 |
|
|
|
1793 |
Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
|
|
|
1794 |
|
|
|
1795 |
List<Integer> catalogIds = itemRepository
|
|
|
1796 |
.selectItems(FocusedModel.class, "catalogItemId", "catalogId", equalsMap, notEqualsMap,
|
|
|
1797 |
equalsJoinMap, notEqualsJoinMap, "minimumQty")
|
|
|
1798 |
.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
|
|
|
1799 |
|
|
|
1800 |
Map<Integer, Integer> focusedCatalogIdAndQtyMap = focusedModelRepository.selectByCatalogIdsl(catalogIds)
|
|
|
1801 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getMinimumQty()));
|
|
|
1802 |
|
|
|
1803 |
/*
|
|
|
1804 |
* Map<Integer, Integer> focusedCatalogIdAndQtyMap =
|
|
|
1805 |
* focusedModelRepository.selectAll().stream() .collect(Collectors.toMap(x ->
|
|
|
1806 |
* x.getCatalogId(), x -> x.getMinimumQty()));
|
|
|
1807 |
*/
|
|
|
1808 |
|
| 25721 |
tejbeer |
1809 |
LOGGER.info("focusedCatalogIdAndQtyMap" + focusedCatalogIdAndQtyMap);
|
|
|
1810 |
|
|
|
1811 |
for (Map.Entry<Integer, Integer> entry : focusedCatalogIdAndQtyMap.entrySet()) {
|
|
|
1812 |
int inStockQty = 0;
|
|
|
1813 |
int processingQty = 0;
|
|
|
1814 |
int grnPendingQty = 0;
|
|
|
1815 |
if (processingOrderMap != null) {
|
|
|
1816 |
processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
|
|
|
1817 |
: processingOrderMap.get(entry.getKey());
|
|
|
1818 |
|
|
|
1819 |
}
|
|
|
1820 |
if (grnPendingOrdersMap != null) {
|
|
|
1821 |
grnPendingQty = (grnPendingOrdersMap.get(entry.getKey()) == null) ? 0
|
|
|
1822 |
: grnPendingOrdersMap.get(entry.getKey());
|
|
|
1823 |
|
|
|
1824 |
}
|
|
|
1825 |
if (catalogIdAndQtyMap != null) {
|
|
|
1826 |
inStockQty = (catalogIdAndQtyMap.get(entry.getKey()) == null) ? 0
|
|
|
1827 |
: catalogIdAndQtyMap.get(entry.getKey());
|
|
|
1828 |
|
|
|
1829 |
}
|
|
|
1830 |
int totalQty = processingQty + grnPendingQty + inStockQty;
|
|
|
1831 |
|
|
|
1832 |
if (totalQty < entry.getValue()) {
|
|
|
1833 |
|
|
|
1834 |
int shortageQty = entry.getValue() - totalQty;
|
|
|
1835 |
List<Item> item = itemRepository.selectAllByCatalogItemId(entry.getKey());
|
|
|
1836 |
|
|
|
1837 |
FocusedModelShortageModel fm = new FocusedModelShortageModel();
|
|
|
1838 |
fm.setFofoId(fofoId);
|
|
|
1839 |
fm.setStoreName(customRetailer.getBusinessName());
|
|
|
1840 |
|
|
|
1841 |
fm.setItemName(item.get(0).getBrand() + item.get(0).getModelNumber() + item.get(0).getModelName());
|
|
|
1842 |
fm.setShortageQty(shortageQty);
|
|
|
1843 |
|
|
|
1844 |
focusedModelShortageReportMap.get(fofoId).add(fm);
|
|
|
1845 |
}
|
|
|
1846 |
|
|
|
1847 |
}
|
|
|
1848 |
List<FocusedModelShortageModel> focusedModelShortageModel = focusedModelShortageReportMap.get(fofoId);
|
|
|
1849 |
|
|
|
1850 |
if (!focusedModelShortageModel.isEmpty()) {
|
|
|
1851 |
String subject = "Stock Alert";
|
|
|
1852 |
String messageText = this.getMessage(focusedModelShortageModel);
|
|
|
1853 |
|
| 25732 |
tejbeer |
1854 |
this.sendMailWithAttachments(subject, messageText, customRetailer.getEmail());
|
| 25721 |
tejbeer |
1855 |
String notificationMessage = this.getNotificationMessage(focusedModelShortageModel);
|
|
|
1856 |
|
|
|
1857 |
LOGGER.info("notificationMessage" + notificationMessage);
|
|
|
1858 |
|
| 25872 |
tejbeer |
1859 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1860 |
sendNotificationModel.setCampaignName("Stock Alert");
|
|
|
1861 |
sendNotificationModel.setTitle("Alert");
|
|
|
1862 |
sendNotificationModel.setMessage(notificationMessage);
|
|
|
1863 |
sendNotificationModel.setType("url");
|
|
|
1864 |
sendNotificationModel.setUrl("http://app.profitmandi.com/pages/home/notifications");
|
|
|
1865 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
1866 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25732 |
tejbeer |
1867 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| 25872 |
tejbeer |
1868 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
1869 |
notificationService.sendNotification(sendNotificationModel);
|
| 25721 |
tejbeer |
1870 |
|
|
|
1871 |
}
|
| 25732 |
tejbeer |
1872 |
|
| 25721 |
tejbeer |
1873 |
}
|
| 25800 |
tejbeer |
1874 |
if (!focusedModelShortageReportMap.isEmpty())
|
| 25721 |
tejbeer |
1875 |
|
| 25800 |
tejbeer |
1876 |
{
|
|
|
1877 |
String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
|
|
1878 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 25837 |
amit.gupta |
1879 |
Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
|
| 25721 |
tejbeer |
1880 |
|
| 25800 |
tejbeer |
1881 |
focusedModelShortageReportMap.entrySet().forEach(x -> {
|
|
|
1882 |
storeGuyMap.entrySet().forEach(y -> {
|
|
|
1883 |
|
|
|
1884 |
if (y.getValue().contains(x.getKey())) {
|
|
|
1885 |
if (!emailRowsMap.containsKey(y.getKey())) {
|
|
|
1886 |
emailRowsMap.put(y.getKey(), new ArrayList<>());
|
|
|
1887 |
}
|
|
|
1888 |
List<List<? extends Serializable>> fms = x.getValue().stream().map(r -> Arrays
|
|
|
1889 |
.asList(r.getFofoId(), r.getStoreName(), r.getItemName(), r.getShortageQty()))
|
|
|
1890 |
.collect(Collectors.toList());
|
|
|
1891 |
emailRowsMap.get(y.getKey()).addAll(fms);
|
|
|
1892 |
|
| 25721 |
tejbeer |
1893 |
}
|
|
|
1894 |
|
| 25800 |
tejbeer |
1895 |
});
|
| 25721 |
tejbeer |
1896 |
|
|
|
1897 |
});
|
|
|
1898 |
|
| 25800 |
tejbeer |
1899 |
List<String> headers = Arrays.asList("Partner Id", "Partner Name", "Model Name", "Shortage Qty");
|
| 25837 |
amit.gupta |
1900 |
emailRowsMap.entrySet().forEach(entry -> {
|
| 25721 |
tejbeer |
1901 |
|
| 25800 |
tejbeer |
1902 |
ByteArrayOutputStream baos = null;
|
|
|
1903 |
try {
|
| 25837 |
amit.gupta |
1904 |
baos = FileUtil.getCSVByteStream(headers, entry.getValue());
|
| 25800 |
tejbeer |
1905 |
} catch (Exception e2) {
|
|
|
1906 |
e2.printStackTrace();
|
|
|
1907 |
}
|
| 25837 |
amit.gupta |
1908 |
String[] sendToArray = new String[] { entry.getKey() };
|
| 25800 |
tejbeer |
1909 |
try {
|
|
|
1910 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
|
|
|
1911 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
1912 |
} catch (Exception e1) { // TODO Auto-generated catch block
|
|
|
1913 |
e1.printStackTrace();
|
|
|
1914 |
}
|
| 25721 |
tejbeer |
1915 |
|
| 25800 |
tejbeer |
1916 |
});
|
|
|
1917 |
}
|
| 25721 |
tejbeer |
1918 |
}
|
|
|
1919 |
|
|
|
1920 |
private String getNotificationMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
1921 |
StringBuilder sb = new StringBuilder();
|
|
|
1922 |
sb.append("Focused Model Shortage in Your Stock : \n");
|
|
|
1923 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
1924 |
|
|
|
1925 |
sb.append(entry.getItemName() + "-" + entry.getShortageQty());
|
|
|
1926 |
sb.append(String.format("%n", ""));
|
|
|
1927 |
}
|
|
|
1928 |
return sb.toString();
|
|
|
1929 |
}
|
|
|
1930 |
|
|
|
1931 |
private void sendMailWithAttachments(String subject, String messageText, String email) throws Exception {
|
|
|
1932 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
1933 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
1934 |
|
|
|
1935 |
helper.setSubject(subject);
|
|
|
1936 |
helper.setText(messageText, true);
|
|
|
1937 |
helper.setTo(email);
|
| 26032 |
amit.gupta |
1938 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smatdukaan Alerts");
|
| 25721 |
tejbeer |
1939 |
helper.setFrom(senderAddress);
|
|
|
1940 |
mailSender.send(message);
|
|
|
1941 |
|
|
|
1942 |
}
|
|
|
1943 |
|
|
|
1944 |
private String getMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
1945 |
StringBuilder sb = new StringBuilder();
|
|
|
1946 |
sb.append("<html><body><p>Alert</p><p>Focused Model Shortage in Your Stock:-</p>"
|
|
|
1947 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
1948 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
1949 |
+ " <th style='border:1px solid black;padding: 5px'>Item</th>\n"
|
|
|
1950 |
+ " <th style='border:1px solid black;padding: 5px'>Shortage Qty</th>\n"
|
|
|
1951 |
+ " </tr>");
|
|
|
1952 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
1953 |
|
|
|
1954 |
sb.append("<tr>");
|
|
|
1955 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getItemName() + "</td>");
|
|
|
1956 |
|
|
|
1957 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getShortageQty() + "</td>");
|
|
|
1958 |
|
|
|
1959 |
sb.append("</tr>");
|
|
|
1960 |
|
|
|
1961 |
}
|
|
|
1962 |
|
|
|
1963 |
sb.append("</tbody></table></body></html>");
|
|
|
1964 |
|
|
|
1965 |
return sb.toString();
|
|
|
1966 |
}
|
|
|
1967 |
|
| 25927 |
amit.gupta |
1968 |
public void notifyLead() throws Exception {
|
|
|
1969 |
List<Lead> leadsToNotify = leadRepository.selectLeadsScheduledBetweenDate(LocalDateTime.now().minusDays(15),
|
|
|
1970 |
LocalDateTime.now().plusHours(4));
|
|
|
1971 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
1972 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
| 25936 |
amit.gupta |
1973 |
System.out.printf("authUserEmailMap - %s", authUserEmailMap);
|
| 25927 |
amit.gupta |
1974 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
1975 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
1976 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
| 25936 |
amit.gupta |
1977 |
|
|
|
1978 |
System.out.printf("dtrEmailMap - %s", dtrEmailMap);
|
|
|
1979 |
|
| 25927 |
amit.gupta |
1980 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
|
|
1981 |
|
|
|
1982 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
1983 |
int authId = authUserEmail.getKey();
|
|
|
1984 |
String email = authUserEmail.getValue();
|
|
|
1985 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
1986 |
}
|
| 25929 |
amit.gupta |
1987 |
System.out.println(authUserKeyMap);
|
|
|
1988 |
System.out.println(leadsToNotify);
|
|
|
1989 |
|
| 25927 |
amit.gupta |
1990 |
String templateMessage = "Lead followup for %s %s, %s is due by %s";
|
|
|
1991 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
|
|
1992 |
for (Lead lead : leadsToNotify) {
|
|
|
1993 |
if (authUserKeyMap.get(lead.getAuthId()) == null) {
|
|
|
1994 |
continue;
|
|
|
1995 |
}
|
|
|
1996 |
String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
|
| 25941 |
amit.gupta |
1997 |
lead.getAddress(), timeFormatter.format(lead.getLeadActivity().getSchelduleTimestamp()));
|
| 25927 |
amit.gupta |
1998 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1999 |
sendNotificationModel.setCampaignName("Lead Reminder");
|
|
|
2000 |
sendNotificationModel.setTitle("Leads followup Reminder");
|
|
|
2001 |
sendNotificationModel.setMessage(notificationMessage);
|
|
|
2002 |
sendNotificationModel.setType("url");
|
| 26121 |
amit.gupta |
2003 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifications");
|
| 25927 |
amit.gupta |
2004 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2005 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
| 26320 |
tejbeer |
2006 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
|
| 25929 |
amit.gupta |
2007 |
System.out.println(sendNotificationModel);
|
| 25927 |
amit.gupta |
2008 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2009 |
}
|
|
|
2010 |
}
|
|
|
2011 |
public void notifyVisits() throws Exception {
|
|
|
2012 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15),
|
|
|
2013 |
LocalDateTime.now().plusHours(4));
|
|
|
2014 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
2015 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
|
|
2016 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
2017 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
2018 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
|
|
2019 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
| 25910 |
amit.gupta |
2020 |
|
| 25927 |
amit.gupta |
2021 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
2022 |
int authId = authUserEmail.getKey();
|
|
|
2023 |
String email = authUserEmail.getValue();
|
|
|
2024 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
2025 |
}
|
|
|
2026 |
String visitTemplate = "Planned visit to franchisee %s is due by %s";
|
|
|
2027 |
String followupTemplate = "Lead followup for franchisee %s is due by %s";
|
|
|
2028 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("MMM 7, EEEE h:m a");
|
|
|
2029 |
for (FranchiseeVisit visit : franchiseeVisits) {
|
|
|
2030 |
if (authUserKeyMap.containsKey(visit.getAuthId())) {
|
|
|
2031 |
continue;
|
|
|
2032 |
}
|
|
|
2033 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2034 |
String message = null;
|
|
|
2035 |
if(visit.getFranchiseActivityId()==0) {
|
|
|
2036 |
message = String.format(visitTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
|
|
|
2037 |
sendNotificationModel.setCampaignName("Franchisee visit Reminder");
|
|
|
2038 |
} else {
|
|
|
2039 |
message = String.format(followupTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
|
|
|
2040 |
sendNotificationModel.setCampaignName("Franchisee followup Reminder");
|
|
|
2041 |
}
|
|
|
2042 |
sendNotificationModel.setMessage(message);
|
|
|
2043 |
sendNotificationModel.setType("url");
|
| 26122 |
amit.gupta |
2044 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifications");
|
| 25927 |
amit.gupta |
2045 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2046 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
|
|
2047 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(visit.getAuthId())));
|
|
|
2048 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2049 |
}
|
| 25910 |
amit.gupta |
2050 |
}
|
| 25927 |
amit.gupta |
2051 |
|
| 25982 |
amit.gupta |
2052 |
public AddPaymentResponse addPayment(AddPaymentRequest addPaymentRequest) throws Exception {
|
|
|
2053 |
HdfcPayment hdfcPayment = hdfcPaymentRepository.selectByTransactionId(addPaymentRequest.getTransactionId());
|
|
|
2054 |
AddPaymentResponse response = new AddPaymentResponse();
|
|
|
2055 |
if (hdfcPayment == null) {
|
|
|
2056 |
hdfcPayment = new HdfcPayment();
|
|
|
2057 |
hdfcPayment.setAmount(addPaymentRequest.getAmount());
|
|
|
2058 |
hdfcPayment.setCreateTimestamp(LocalDateTime.now());
|
|
|
2059 |
hdfcPayment.setCreditTimestamp(addPaymentRequest.getCreditDateTime());
|
|
|
2060 |
hdfcPayment.setFromAccountNumber(addPaymentRequest.getFromAccountNumber());
|
|
|
2061 |
hdfcPayment.setFromBankName(addPaymentRequest.getFromBankName());
|
|
|
2062 |
hdfcPayment.setMmid(addPaymentRequest.getMmid());
|
|
|
2063 |
hdfcPayment.setRemitterName(addPaymentRequest.getRemitterName());
|
|
|
2064 |
hdfcPayment.setTransactionId(addPaymentRequest.getTransactionId());
|
|
|
2065 |
hdfcPayment.setTransferMode(addPaymentRequest.getTransferMode());
|
|
|
2066 |
hdfcPayment.setUtr(addPaymentRequest.getUtr());
|
|
|
2067 |
hdfcPayment.setVirtualAccount(hdfcPayment.getVirtualAccount());
|
|
|
2068 |
hdfcPaymentRepository.persist(hdfcPayment);
|
|
|
2069 |
String virtualAccount = hdfcPayment.getVirtualAccount();
|
|
|
2070 |
String retailerIdString = virtualAccount.substring(6);
|
|
|
2071 |
int retailerId = Integer.parseInt(retailerIdString);
|
|
|
2072 |
String description = String.format("Paid through %s, Utr# %s", hdfcPayment.getTransferMode(),
|
|
|
2073 |
hdfcPayment.getUtr());
|
|
|
2074 |
walletService.addAmountToWallet(retailerId, hdfcPayment.getId(), WalletReferenceType.ADVANCE_AMOUNT,
|
|
|
2075 |
description, (float) hdfcPayment.getAmount());
|
|
|
2076 |
response.setCode("100");
|
|
|
2077 |
response.setStatus("Success");
|
|
|
2078 |
} else {
|
|
|
2079 |
response.setCode("200");
|
|
|
2080 |
response.setStatus("Duplicate");
|
|
|
2081 |
}
|
|
|
2082 |
response.setTransactionId("");
|
|
|
2083 |
|
|
|
2084 |
return response;
|
|
|
2085 |
}
|
| 25927 |
amit.gupta |
2086 |
|
| 25982 |
amit.gupta |
2087 |
|
| 25910 |
amit.gupta |
2088 |
|
| 26283 |
tejbeer |
2089 |
public void ticketClosed() throws Exception {
|
|
|
2090 |
|
|
|
2091 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTicketsWithStatus(ActivityType.RESOLVED);
|
|
|
2092 |
for (Ticket ticket : tickets) {
|
|
|
2093 |
if (ticket.getUpdateTimestamp().toLocalDate().isBefore(LocalDate.now().minusDays(7))) {
|
|
|
2094 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
2095 |
ticket.setLastActivity(ActivityType.RESOLVED_ACCEPTED);
|
|
|
2096 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
2097 |
ticketRepository.persist(ticket);
|
|
|
2098 |
}
|
|
|
2099 |
}
|
|
|
2100 |
|
|
|
2101 |
}
|
|
|
2102 |
|
| 25721 |
tejbeer |
2103 |
}
|