| Line 3... |
Line 3... |
| 3 |
import com.google.common.collect.Lists;
|
3 |
import com.google.common.collect.Lists;
|
| 4 |
import com.google.gson.Gson;
|
4 |
import com.google.gson.Gson;
|
| 5 |
import com.razorpay.Payment;
|
5 |
import com.razorpay.Payment;
|
| 6 |
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
|
6 |
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
|
| 7 |
import com.smartdukaan.cron.itelImeiActivation.TecnoImeiActivation;
|
7 |
import com.smartdukaan.cron.itelImeiActivation.TecnoImeiActivation;
|
| - |
|
8 |
import com.spice.profitmandi.common.enumuration.ActivationType;
|
| 8 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
9 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 9 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
10 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 10 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
11 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 11 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
12 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 12 |
import com.spice.profitmandi.common.model.*;
|
13 |
import com.spice.profitmandi.common.model.*;
|
| Line 50... |
Line 51... |
| 50 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
51 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
| 51 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
52 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
| 52 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
53 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 53 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
54 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
55 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.catalog.CustomerOfferItemRepository;
|
- |
|
| 56 |
import com.spice.profitmandi.dao.repository.catalog.CustomerOfferRepository;
|
- |
|
| 57 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
- |
|
| 58 |
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
|
- |
|
| 59 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
56 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
| 60 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
- |
|
| 61 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
- |
|
| 62 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
- |
|
| 63 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
57 |
import com.spice.profitmandi.dao.repository.cs.*;
|
| 64 |
import com.spice.profitmandi.dao.repository.cs.PartnerRegionRepository;
|
- |
|
| 65 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
- |
|
| 66 |
import com.spice.profitmandi.dao.repository.cs.RegionRepository;
|
- |
|
| 67 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
- |
|
| 68 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
- |
|
| 69 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
- |
|
| 70 |
import com.spice.profitmandi.dao.repository.dtr.EmployeeAttendanceRepository;
|
- |
|
| 71 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
- |
|
| 72 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeActivityRepository;
|
- |
|
| 73 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeVisitRepository;
|
- |
|
| 74 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
- |
|
| 75 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
- |
|
| 76 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
58 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 77 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
- |
|
| 78 |
import com.spice.profitmandi.dao.repository.dtr.PartnerProblemRepository;
|
- |
|
| 79 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
- |
|
| 80 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
- |
|
| 81 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
- |
|
| 82 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
- |
|
| 83 |
import com.spice.profitmandi.dao.repository.dtr.RefferalRepository;
|
- |
|
| 84 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
- |
|
| 85 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
- |
|
| 86 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
- |
|
| 87 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
- |
|
| 88 |
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
|
- |
|
| 89 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
- |
|
| 90 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
- |
|
| 91 |
import com.spice.profitmandi.dao.repository.fofo.CurrentPartnerDailyInvestmentRepository;
|
- |
|
| 92 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
- |
|
| 93 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
- |
|
| 94 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
- |
|
| 95 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
- |
|
| 96 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
- |
|
| 97 |
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
|
- |
|
| 98 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
- |
|
| 99 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
- |
|
| 100 |
import com.spice.profitmandi.dao.repository.fofo.MonthlyTargetRepository;
|
- |
|
| 101 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
- |
|
| 102 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
- |
|
| 103 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeRepository;
|
- |
|
| 104 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
- |
|
| 105 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
- |
|
| 106 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
|
- |
|
| 107 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
|
- |
|
| 108 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
- |
|
| 109 |
import com.spice.profitmandi.dao.repository.fofo.RazorPayRepository;
|
59 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 110 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
- |
|
| 111 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
- |
|
| 112 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
- |
|
| 113 |
import com.spice.profitmandi.dao.repository.fofo.ServiceConfigRepository;
|
- |
|
| 114 |
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
|
60 |
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
|
| 115 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
61 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 116 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
62 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
| 117 |
import com.spice.profitmandi.dao.repository.transaction.HdfcPaymentRepository;
|
- |
|
| 118 |
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
|
- |
|
| 119 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
63 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| 120 |
import com.spice.profitmandi.dao.repository.transaction.LoanStatementRepository;
|
- |
|
| 121 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
- |
|
| 122 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
- |
|
| 123 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
- |
|
| 124 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
- |
|
| 125 |
import com.spice.profitmandi.dao.repository.transaction.SanctionRequestRepository;
|
- |
|
| 126 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
- |
|
| 127 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
- |
|
| 128 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
- |
|
| 129 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
64 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 130 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
65 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 131 |
import com.spice.profitmandi.dao.repository.warehouse.BilledImeiModel;
|
66 |
import com.spice.profitmandi.dao.repository.warehouse.BilledImeiModel;
|
| 132 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
|
67 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
|
| 133 |
import com.spice.profitmandi.dao.service.solr.FofoSolr;
|
68 |
import com.spice.profitmandi.dao.service.solr.FofoSolr;
|
| Line 149... |
Line 84... |
| 149 |
import com.spice.profitmandi.service.transaction.CreditNoteService;
|
84 |
import com.spice.profitmandi.service.transaction.CreditNoteService;
|
| 150 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
85 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
| 151 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
86 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 152 |
import com.spice.profitmandi.service.user.RetailerService;
|
87 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 153 |
import com.spice.profitmandi.service.wallet.WalletService;
|
88 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 154 |
|
- |
|
| 155 |
import in.shop2020.model.v1.order.OrderStatus;
|
89 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 156 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
90 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 157 |
import okhttp3.OkHttpClient;
|
91 |
import okhttp3.OkHttpClient;
|
| 158 |
import okhttp3.Request;
|
92 |
import okhttp3.Request;
|
| 159 |
import okhttp3.Response;
|
93 |
import okhttp3.Response;
|
| 160 |
|
- |
|
| 161 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
94 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 162 |
import org.apache.commons.lang.StringUtils;
|
95 |
import org.apache.commons.lang.StringUtils;
|
| 163 |
import org.apache.http.client.methods.CloseableHttpResponse;
|
96 |
import org.apache.http.client.methods.CloseableHttpResponse;
|
| 164 |
import org.apache.http.client.methods.HttpPost;
|
97 |
import org.apache.http.client.methods.HttpPost;
|
| 165 |
import org.apache.http.conn.HttpHostConnectException;
|
98 |
import org.apache.http.conn.HttpHostConnectException;
|
| Line 203... |
Line 136... |
| 203 |
|
136 |
|
| 204 |
@Component
|
137 |
@Component
|
| 205 |
@Transactional(rollbackFor = Throwable.class)
|
138 |
@Transactional(rollbackFor = Throwable.class)
|
| 206 |
public class ScheduledTasks {
|
139 |
public class ScheduledTasks {
|
| 207 |
|
140 |
|
| 208 |
@Value("${oxigen.recharge.transaction.url}")
|
141 |
@Value("${oxigen.recharge.transaction.url}")
|
| 209 |
private String oxigenRechargeTransactionUrl;
|
142 |
private String oxigenRechargeTransactionUrl;
|
| 210 |
|
143 |
|
| 211 |
@Value("${oxigen.recharge.enquiry.url}")
|
144 |
@Value("${oxigen.recharge.enquiry.url}")
|
| 212 |
private String oxigenRechargeEnquiryUrl;
|
145 |
private String oxigenRechargeEnquiryUrl;
|
| 213 |
|
146 |
|
| 214 |
@Autowired
|
147 |
@Autowired
|
| 215 |
private RegionRepository regionRepository;
|
148 |
private RegionRepository regionRepository;
|
| 216 |
|
149 |
|
| 217 |
@Autowired
|
150 |
@Autowired
|
| 218 |
private ServiceConfigService serviceConfigService;
|
151 |
private ServiceConfigService serviceConfigService;
|
| 219 |
|
152 |
|
| 220 |
@Autowired
|
153 |
@Autowired
|
| 221 |
private TecnoImeiActivation tecnoImeiActivation;
|
154 |
private TecnoImeiActivation tecnoImeiActivation;
|
| 222 |
|
155 |
|
| 223 |
private static final DateTimeFormatter leadTimeFormatter = DateTimeFormatter.ofPattern("d LLL, hh:mm a");
|
156 |
private static final DateTimeFormatter leadTimeFormatter = DateTimeFormatter.ofPattern("d LLL, hh:mm a");
|
| 224 |
|
157 |
|
| 225 |
@Autowired
|
158 |
@Autowired
|
| 226 |
private PartnerRegionRepository partnerRegionRepository;
|
159 |
private PartnerRegionRepository partnerRegionRepository;
|
| 227 |
|
160 |
|
| 228 |
@Autowired
|
161 |
@Autowired
|
| 229 |
private EmployeeAttendanceRepository employeeAttendanceRepository;
|
162 |
private EmployeeAttendanceRepository employeeAttendanceRepository;
|
| 230 |
|
163 |
|
| 231 |
@Autowired
|
164 |
@Autowired
|
| 232 |
VivoImeiActivationService vivoImeiActivationService;
|
165 |
VivoImeiActivationService vivoImeiActivationService;
|
| 233 |
|
166 |
|
| 234 |
@Autowired
|
167 |
@Autowired
|
| 235 |
ItelImeiActivationService itelImeiActivationService;
|
168 |
ItelImeiActivationService itelImeiActivationService;
|
| 236 |
|
169 |
|
| 237 |
@Autowired
|
170 |
@Autowired
|
| 238 |
private PartnerTypeChangeService partnerTypeChangeService;
|
171 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| 239 |
|
172 |
|
| 240 |
@Autowired
|
173 |
@Autowired
|
| 241 |
private ActivatedImeiRepository activatedImeiRepository;
|
174 |
private ActivatedImeiRepository activatedImeiRepository;
|
| 242 |
|
175 |
|
| 243 |
@Autowired
|
176 |
@Autowired
|
| 244 |
private LineItemRepository lineItemRepository;
|
177 |
private LineItemRepository lineItemRepository;
|
| 245 |
|
178 |
|
| 246 |
@Autowired
|
179 |
@Autowired
|
| 247 |
private LeadRepository leadRepository;
|
180 |
private LeadRepository leadRepository;
|
| 248 |
|
181 |
|
| 249 |
@Autowired
|
182 |
@Autowired
|
| 250 |
private AuthRepository authRepository;
|
183 |
private AuthRepository authRepository;
|
| 251 |
|
184 |
|
| 252 |
@Autowired
|
185 |
@Autowired
|
| 253 |
private PriceDropService priceDropService;
|
186 |
private PriceDropService priceDropService;
|
| 254 |
|
187 |
|
| 255 |
@Autowired
|
188 |
@Autowired
|
| 256 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
189 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
| 257 |
|
190 |
|
| 258 |
@Autowired
|
191 |
@Autowired
|
| 259 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
192 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
| 260 |
|
193 |
|
| 261 |
@Autowired
|
194 |
@Autowired
|
| 262 |
private HdfcPaymentRepository hdfcPaymentRepository;
|
195 |
private HdfcPaymentRepository hdfcPaymentRepository;
|
| 263 |
|
196 |
|
| 264 |
@Autowired
|
197 |
@Autowired
|
| 265 |
private CsService csService;
|
198 |
private CsService csService;
|
| 266 |
|
199 |
|
| 267 |
@Autowired
|
200 |
@Autowired
|
| 268 |
private SaholicInventoryService saholicInventoryService;
|
201 |
private SaholicInventoryService saholicInventoryService;
|
| 269 |
|
202 |
|
| 270 |
@Autowired
|
203 |
@Autowired
|
| 271 |
private InsurancePolicyRepository insurancePolicyRepository;
|
204 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 272 |
|
205 |
|
| 273 |
@Autowired
|
206 |
@Autowired
|
| 274 |
private ToffeeService toffeeService;
|
207 |
private ToffeeService toffeeService;
|
| 275 |
|
208 |
|
| 276 |
@Value("${oxigen.recharge.auth.key}")
|
209 |
@Value("${oxigen.recharge.auth.key}")
|
| 277 |
private String oxigenRechargeAuthKey;
|
210 |
private String oxigenRechargeAuthKey;
|
| 278 |
|
211 |
|
| 279 |
@Value("${oxigen.recharge.validation.url}")
|
212 |
@Value("${oxigen.recharge.validation.url}")
|
| 280 |
private String oxigenRechargeValidationUrl;
|
213 |
private String oxigenRechargeValidationUrl;
|
| 281 |
|
214 |
|
| 282 |
@Value("${oxigen.recharge.validation.auth.key}")
|
215 |
@Value("${oxigen.recharge.validation.auth.key}")
|
| 283 |
private String oxigenRechargeValidationAuthKey;
|
216 |
private String oxigenRechargeValidationAuthKey;
|
| 284 |
|
217 |
|
| 285 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
218 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
| 286 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
219 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
| 287 |
|
220 |
|
| 288 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
221 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
| 289 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
222 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
| 290 |
|
223 |
|
| 291 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
224 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
| 292 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
225 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
| 293 |
|
226 |
|
| 294 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
227 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
| 295 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
228 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
| 296 |
|
229 |
|
| 297 |
@Value("${think.walnut.digital.recharge.username}")
|
230 |
@Value("${think.walnut.digital.recharge.username}")
|
| 298 |
private String thinkWalnutDigitalRechargeUserName;
|
231 |
private String thinkWalnutDigitalRechargeUserName;
|
| 299 |
|
232 |
|
| 300 |
@Value("${think.walnut.digital.recharge.password}")
|
233 |
@Value("${think.walnut.digital.recharge.password}")
|
| 301 |
private String thinkWalnutDigitalRechargePassword;
|
234 |
private String thinkWalnutDigitalRechargePassword;
|
| 302 |
|
235 |
|
| 303 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
236 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
| 304 |
private String thinkWalnutDigitalRechargeAuthKey;
|
237 |
private String thinkWalnutDigitalRechargeAuthKey;
|
| 305 |
|
238 |
|
| 306 |
@Autowired
|
239 |
@Autowired
|
| 307 |
private PurchaseRepository purchaseRepository;
|
240 |
private PurchaseRepository purchaseRepository;
|
| 308 |
|
241 |
|
| 309 |
@Autowired
|
242 |
@Autowired
|
| 310 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
243 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
| 311 |
|
244 |
|
| 312 |
@Autowired
|
245 |
@Autowired
|
| 313 |
PriceDropRepository priceDropRepository;
|
246 |
PriceDropRepository priceDropRepository;
|
| 314 |
|
247 |
|
| 315 |
@Autowired
|
248 |
@Autowired
|
| 316 |
private PartnerTypeChangeRepository partnerTypeChangeRepository;
|
249 |
private PartnerTypeChangeRepository partnerTypeChangeRepository;
|
| 317 |
|
250 |
|
| 318 |
@Autowired
|
251 |
@Autowired
|
| 319 |
private SchemeService schemeService;
|
252 |
private SchemeService schemeService;
|
| 320 |
|
253 |
|
| 321 |
@Autowired
|
254 |
@Autowired
|
| 322 |
private ServiceConfigRepository serviceConfigRepository;
|
255 |
private ServiceConfigRepository serviceConfigRepository;
|
| 323 |
|
256 |
|
| 324 |
@Value("${delhivery.tracking.token}")
|
257 |
@Value("${delhivery.tracking.token}")
|
| 325 |
private String token;
|
258 |
private String token;
|
| 326 |
|
259 |
|
| 327 |
private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "uday.singh@smartudkaan.com",
|
260 |
private static final String[] STOCK_AGEING_MAIL_LIST = new String[]{"uday.singh@smartudkaan.com",
|
| 328 |
"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
261 |
"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 329 |
"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com" };
|
262 |
"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com"};
|
| 330 |
|
263 |
|
| 331 |
private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
|
264 |
private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[]{"kamini.sharma@smartdukaan.com",
|
| 332 |
"tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com",
|
265 |
"tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com",
|
| 333 |
"niranjan.kala@smartdukaan.com" };
|
266 |
"niranjan.kala@smartdukaan.com"};
|
| 334 |
|
267 |
|
| 335 |
private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[] { "uday.singh@smartdukaan.com",
|
268 |
private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[]{"uday.singh@smartdukaan.com",
|
| 336 |
"kuldeep.kumar@smartdukaan.com" };
|
269 |
"kuldeep.kumar@smartdukaan.com"};
|
| 337 |
|
270 |
|
| 338 |
private static final String[] EMPLOYEE_ATTENDANCE_MAIL_LIST = new String[] { "sm@smartdukaan.com",
|
271 |
private static final String[] EMPLOYEE_ATTENDANCE_MAIL_LIST = new String[]{"sm@smartdukaan.com",
|
| 339 |
"sm@smartdukaan.com" };
|
272 |
"sm@smartdukaan.com"};
|
| 340 |
|
273 |
|
| 341 |
private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
274 |
private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 342 |
|
275 |
|
| 343 |
@Autowired
|
276 |
@Autowired
|
| 344 |
private ReporticoService reporticoService;
|
277 |
private ReporticoService reporticoService;
|
| 345 |
|
278 |
|
| 346 |
@Autowired
|
279 |
@Autowired
|
| 347 |
private PartnerInvestmentService partnerInvestmentService;
|
280 |
private PartnerInvestmentService partnerInvestmentService;
|
| 348 |
|
281 |
|
| 349 |
@Autowired
|
282 |
@Autowired
|
| 350 |
private PositionRepository positionRepository;
|
283 |
private PositionRepository positionRepository;
|
| 351 |
|
284 |
|
| 352 |
@Autowired
|
285 |
@Autowired
|
| 353 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
286 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 354 |
|
287 |
|
| 355 |
@Autowired
|
288 |
@Autowired
|
| 356 |
private NotificationService notificationService;
|
289 |
private NotificationService notificationService;
|
| 357 |
|
290 |
|
| 358 |
@Autowired
|
291 |
@Autowired
|
| 359 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
292 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 360 |
|
293 |
|
| 361 |
@Autowired
|
294 |
@Autowired
|
| 362 |
private SchemeInOutRepository schemeInOutRepository;
|
295 |
private SchemeInOutRepository schemeInOutRepository;
|
| 363 |
|
296 |
|
| 364 |
@Autowired
|
297 |
@Autowired
|
| 365 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
298 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
| 366 |
|
299 |
|
| 367 |
@Autowired
|
300 |
@Autowired
|
| 368 |
private CustomerAddressRepository customerAddressRepository;
|
301 |
private CustomerAddressRepository customerAddressRepository;
|
| 369 |
|
302 |
|
| 370 |
@Autowired
|
303 |
@Autowired
|
| 371 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
304 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
| 372 |
|
305 |
|
| 373 |
@Autowired
|
306 |
@Autowired
|
| 374 |
private FofoLineItemRepository fofoLineItemRepository;
|
307 |
private FofoLineItemRepository fofoLineItemRepository;
|
| 375 |
|
308 |
|
| 376 |
@Autowired
|
309 |
@Autowired
|
| 377 |
private FofoOrderRepository fofoOrderRepository;
|
310 |
private FofoOrderRepository fofoOrderRepository;
|
| 378 |
|
311 |
|
| 379 |
@Autowired
|
312 |
@Autowired
|
| 380 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
313 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 381 |
|
314 |
|
| 382 |
@Autowired
|
315 |
@Autowired
|
| 383 |
private UserWalletRepository userWalletRepository;
|
316 |
private UserWalletRepository userWalletRepository;
|
| 384 |
|
317 |
|
| 385 |
@Autowired
|
318 |
@Autowired
|
| 386 |
private InventoryItemRepository inventoryItemRepository;
|
319 |
private InventoryItemRepository inventoryItemRepository;
|
| 387 |
|
320 |
|
| 388 |
@Autowired
|
321 |
@Autowired
|
| 389 |
private WalletService walletService;
|
322 |
private WalletService walletService;
|
| 390 |
|
323 |
|
| 391 |
@Autowired
|
324 |
@Autowired
|
| 392 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
325 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
| 393 |
|
326 |
|
| 394 |
@Autowired
|
327 |
@Autowired
|
| 395 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
328 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
| 396 |
|
329 |
|
| 397 |
@Autowired
|
330 |
@Autowired
|
| 398 |
private RechargeProviderRepository rechargeProviderRepository;
|
331 |
private RechargeProviderRepository rechargeProviderRepository;
|
| 399 |
|
332 |
|
| 400 |
@Autowired
|
333 |
@Autowired
|
| 401 |
private ScanRecordRepository scanRecordRepository;
|
334 |
private ScanRecordRepository scanRecordRepository;
|
| 402 |
|
335 |
|
| 403 |
@Autowired
|
336 |
@Autowired
|
| 404 |
private DailyRechargeRepository dailyRechargeRepository;
|
337 |
private DailyRechargeRepository dailyRechargeRepository;
|
| 405 |
|
338 |
|
| 406 |
@Autowired
|
339 |
@Autowired
|
| 407 |
private FofoStoreRepository fofoStoreRepository;
|
340 |
private FofoStoreRepository fofoStoreRepository;
|
| 408 |
|
341 |
|
| 409 |
@Value("${prod}")
|
342 |
@Value("${prod}")
|
| 410 |
private boolean prod;
|
343 |
private boolean prod;
|
| 411 |
|
344 |
|
| 412 |
@Autowired
|
345 |
@Autowired
|
| 413 |
private StateGstRateRepository stateGstRateRepository;
|
346 |
private StateGstRateRepository stateGstRateRepository;
|
| 414 |
|
347 |
|
| 415 |
@Autowired
|
348 |
@Autowired
|
| 416 |
private RetailerService retailerService;
|
349 |
private RetailerService retailerService;
|
| 417 |
|
350 |
|
| 418 |
@Autowired
|
351 |
@Autowired
|
| 419 |
private TransactionService transactionService;
|
352 |
private TransactionService transactionService;
|
| 420 |
|
353 |
|
| 421 |
@Autowired
|
354 |
@Autowired
|
| 422 |
private ItemRepository itemRepository;
|
355 |
private ItemRepository itemRepository;
|
| 423 |
|
356 |
|
| 424 |
@Autowired
|
357 |
@Autowired
|
| 425 |
private OrderRepository orderRepository;
|
358 |
private OrderRepository orderRepository;
|
| 426 |
|
359 |
|
| 427 |
@Autowired
|
360 |
@Autowired
|
| 428 |
private OrderService orderService;
|
361 |
private OrderService orderService;
|
| 429 |
|
362 |
|
| 430 |
@Autowired
|
363 |
@Autowired
|
| 431 |
private SchemeRepository schemeRepository;
|
364 |
private SchemeRepository schemeRepository;
|
| 432 |
|
365 |
|
| 433 |
@Autowired
|
366 |
@Autowired
|
| 434 |
private SchemeItemRepository schemeItemRepository;
|
367 |
private SchemeItemRepository schemeItemRepository;
|
| 435 |
|
368 |
|
| 436 |
@Autowired
|
369 |
@Autowired
|
| 437 |
private JavaMailSender mailSender;
|
370 |
private JavaMailSender mailSender;
|
| 438 |
|
371 |
|
| 439 |
@Autowired
|
372 |
@Autowired
|
| 440 |
private PartnerTargetRepository partnerTargetRepository;
|
373 |
private PartnerTargetRepository partnerTargetRepository;
|
| 441 |
|
374 |
|
| 442 |
@Autowired
|
375 |
@Autowired
|
| 443 |
@Qualifier(value = "googleMailSender")
|
376 |
@Qualifier(value = "googleMailSender")
|
| 444 |
private JavaMailSender googleMailSender;
|
377 |
private JavaMailSender googleMailSender;
|
| 445 |
|
378 |
|
| 446 |
@Autowired
|
379 |
@Autowired
|
| 447 |
private InventoryService inventoryService;
|
380 |
private InventoryService inventoryService;
|
| 448 |
|
381 |
|
| 449 |
@Autowired
|
382 |
@Autowired
|
| 450 |
private AddressRepository addressRepository;
|
383 |
private AddressRepository addressRepository;
|
| 451 |
|
384 |
|
| 452 |
@Autowired
|
385 |
@Autowired
|
| 453 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
386 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 454 |
|
387 |
|
| 455 |
@Autowired
|
388 |
@Autowired
|
| 456 |
private Mongo mongoClient;
|
389 |
private Mongo mongoClient;
|
| 457 |
|
390 |
|
| 458 |
@Autowired
|
391 |
@Autowired
|
| 459 |
private DeviceRepository deviceRepository;
|
392 |
private DeviceRepository deviceRepository;
|
| 460 |
|
393 |
|
| 461 |
@Autowired
|
394 |
@Autowired
|
| 462 |
private PushNotificationRepository pushNotificationRepository;
|
395 |
private PushNotificationRepository pushNotificationRepository;
|
| 463 |
|
396 |
|
| 464 |
@Autowired
|
397 |
@Autowired
|
| 465 |
private NotificationCampaignRepository notificationCampaignRepository;
|
398 |
private NotificationCampaignRepository notificationCampaignRepository;
|
| 466 |
|
399 |
|
| 467 |
@Autowired
|
400 |
@Autowired
|
| 468 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
401 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 469 |
|
402 |
|
| 470 |
@Autowired
|
403 |
@Autowired
|
| 471 |
private FocusedModelRepository focusedModelRepository;
|
404 |
private FocusedModelRepository focusedModelRepository;
|
| 472 |
|
405 |
|
| 473 |
@Autowired
|
406 |
@Autowired
|
| 474 |
private UserAccountRepository userAccountRepository;
|
407 |
private UserAccountRepository userAccountRepository;
|
| 475 |
|
408 |
|
| 476 |
@Autowired
|
409 |
@Autowired
|
| 477 |
private UserRepository userUserRepository;
|
410 |
private UserRepository userUserRepository;
|
| 478 |
|
411 |
|
| 479 |
@Autowired
|
412 |
@Autowired
|
| 480 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
413 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
| 481 |
|
414 |
|
| 482 |
@Autowired
|
415 |
@Autowired
|
| 483 |
private UserCampaignRepository userCampaignRepository;
|
416 |
private UserCampaignRepository userCampaignRepository;
|
| 484 |
|
417 |
|
| 485 |
@Autowired
|
418 |
@Autowired
|
| 486 |
private Gson gson;
|
419 |
private Gson gson;
|
| 487 |
|
420 |
|
| 488 |
@Autowired
|
421 |
@Autowired
|
| 489 |
private TicketRepository ticketRepository;
|
422 |
private TicketRepository ticketRepository;
|
| 490 |
|
423 |
|
| 491 |
@Autowired
|
424 |
@Autowired
|
| 492 |
private RefferalRepository refferalRepository;
|
425 |
private RefferalRepository refferalRepository;
|
| 493 |
|
426 |
|
| 494 |
@Autowired
|
427 |
@Autowired
|
| 495 |
private PartnerProblemRepository partnerProblemRepository;
|
428 |
private PartnerProblemRepository partnerProblemRepository;
|
| 496 |
|
429 |
|
| 497 |
@Autowired
|
430 |
@Autowired
|
| 498 |
private PendingOrderRepository pendingOrderRepository;
|
431 |
private PendingOrderRepository pendingOrderRepository;
|
| 499 |
|
432 |
|
| 500 |
@Autowired
|
433 |
@Autowired
|
| 501 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
434 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
| 502 |
|
435 |
|
| 503 |
@Value("${razorpay.account.keyId}")
|
436 |
@Value("${razorpay.account.keyId}")
|
| 504 |
private String keyId;
|
437 |
private String keyId;
|
| 505 |
|
438 |
|
| 506 |
@Value("${razorpay.account.keySecret}")
|
439 |
@Value("${razorpay.account.keySecret}")
|
| 507 |
private String keySecret;
|
440 |
private String keySecret;
|
| 508 |
|
441 |
|
| 509 |
@Autowired
|
442 |
@Autowired
|
| 510 |
private RazorpayPaymentService razorPaymentService;
|
443 |
private RazorpayPaymentService razorPaymentService;
|
| 511 |
|
444 |
|
| 512 |
@Autowired
|
445 |
@Autowired
|
| 513 |
private RazorPayRepository razorPayRepository;
|
446 |
private RazorPayRepository razorPayRepository;
|
| 514 |
|
447 |
|
| 515 |
@Autowired
|
448 |
@Autowired
|
| 516 |
private PendingOrderService pendingOrderService;
|
449 |
private PendingOrderService pendingOrderService;
|
| 517 |
|
450 |
|
| 518 |
@Autowired
|
451 |
@Autowired
|
| 519 |
private CustomerRepository customerRepository;
|
452 |
private CustomerRepository customerRepository;
|
| 520 |
|
453 |
|
| 521 |
@Autowired
|
454 |
@Autowired
|
| 522 |
private RestClient restClient;
|
455 |
private RestClient restClient;
|
| 523 |
|
456 |
|
| 524 |
@Autowired
|
457 |
@Autowired
|
| 525 |
private MandiiService mandiiService;
|
458 |
private MandiiService mandiiService;
|
| 526 |
|
459 |
|
| 527 |
@Autowired
|
460 |
@Autowired
|
| 528 |
CreditAccountRepository creditAccountRepository;
|
461 |
CreditAccountRepository creditAccountRepository;
|
| 529 |
|
462 |
|
| 530 |
@Autowired
|
463 |
@Autowired
|
| 531 |
CustomerOfferRepository customerOfferRepository;
|
464 |
CustomerOfferRepository customerOfferRepository;
|
| 532 |
|
465 |
|
| 533 |
@Autowired
|
466 |
@Autowired
|
| 534 |
CustomerOfferItemRepository customerOfferItemRepository;
|
467 |
CustomerOfferItemRepository customerOfferItemRepository;
|
| 535 |
@Autowired
|
468 |
@Autowired
|
| 536 |
private FofoSolr fofoSolr;
|
469 |
private FofoSolr fofoSolr;
|
| 537 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
470 |
|
| 538 |
|
471 |
|
| 539 |
private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
|
472 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 540 |
private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
|
473 |
|
| 541 |
|
474 |
private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
|
| 542 |
@Autowired
|
475 |
private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
|
| 543 |
private TagListingRepository tagListingRepository;
|
476 |
|
| 544 |
|
477 |
@Autowired
|
| 545 |
public void generateDailyRecharge() {
|
478 |
private TagListingRepository tagListingRepository;
|
| 546 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
479 |
|
| 547 |
.selectAll(0, 2000);
|
480 |
public void generateDailyRecharge() {
|
| 548 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
481 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
| 549 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
482 |
.selectAll(0, 2000);
|
| 550 |
|
483 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
| 551 |
rechargeProviders.stream().forEach(x -> {
|
484 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
| 552 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
485 |
|
| 553 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
486 |
rechargeProviders.stream().forEach(x -> {
|
| 554 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
487 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
| 555 |
|
488 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
| 556 |
LOGGER.info("dateWiseProviderCreditsMap -{}", dateWiseProviderCreditsMap);
|
489 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
| 557 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
490 |
|
| 558 |
float previousDayClosing = 0;
|
491 |
LOGGER.info("dateWiseProviderCreditsMap -{}", dateWiseProviderCreditsMap);
|
| 559 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
492 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
| 560 |
while (date.isBefore(endDate)) {
|
493 |
float previousDayClosing = 0;
|
| 561 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
494 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
| 562 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
495 |
while (date.isBefore(endDate)) {
|
| 563 |
date.plusDays(1).atStartOfDay());
|
496 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
| 564 |
|
497 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
| 565 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
498 |
date.plusDays(1).atStartOfDay());
|
| 566 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
499 |
|
| 567 |
|
500 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
| 568 |
float dailyAmount = 0;
|
501 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
| 569 |
float totalCommission = 0;
|
502 |
|
| 570 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
503 |
float dailyAmount = 0;
|
| 571 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
504 |
float totalCommission = 0;
|
| 572 |
dailyAmount += rechargeTransaction.getAmount();
|
505 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
| 573 |
totalCommission += rechargeTransaction.getCommission();
|
506 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
| 574 |
}
|
507 |
dailyAmount += rechargeTransaction.getAmount();
|
| 575 |
}
|
508 |
totalCommission += rechargeTransaction.getCommission();
|
| 576 |
|
509 |
}
|
| 577 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
510 |
}
|
| 578 |
float dailyWalletRecharge = 0;
|
511 |
|
| 579 |
if (rechargeHistoryList != null) {
|
512 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
| 580 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
513 |
float dailyWalletRecharge = 0;
|
| 581 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
514 |
if (rechargeHistoryList != null) {
|
| 582 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
515 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
| 583 |
}
|
516 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
| 584 |
}
|
517 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
| 585 |
}
|
518 |
}
|
| 586 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
519 |
}
|
| 587 |
DailyRecharge dailyRecharge = null;
|
520 |
}
|
| 588 |
try {
|
521 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
| 589 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
522 |
DailyRecharge dailyRecharge = null;
|
| 590 |
} catch (Exception e) {
|
523 |
try {
|
| 591 |
LOGGER.info("Could not find Recharge entry");
|
524 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
| 592 |
}
|
525 |
} catch (Exception e) {
|
| 593 |
if (dailyRecharge == null) {
|
526 |
LOGGER.info("Could not find Recharge entry");
|
| 594 |
dailyRecharge = new DailyRecharge();
|
527 |
}
|
| 595 |
dailyRecharge.setCreateDate(date);
|
528 |
if (dailyRecharge == null) {
|
| 596 |
}
|
529 |
dailyRecharge = new DailyRecharge();
|
| 597 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
530 |
dailyRecharge.setCreateDate(date);
|
| 598 |
dailyRecharge.setProviderId(x.getId());
|
531 |
}
|
| 599 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
532 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
| 600 |
dailyRecharge.setTotalAmount(dailyAmount);
|
533 |
dailyRecharge.setProviderId(x.getId());
|
| 601 |
dailyRecharge.setTotalCommission(totalCommission);
|
534 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
| 602 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
535 |
dailyRecharge.setTotalAmount(dailyAmount);
|
| 603 |
dailyRecharge.setClosingBalance(closingBalance);
|
536 |
dailyRecharge.setTotalCommission(totalCommission);
|
| 604 |
dailyRechargeRepository.persist(dailyRecharge);
|
537 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
| 605 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
538 |
dailyRecharge.setClosingBalance(closingBalance);
|
| 606 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
539 |
dailyRechargeRepository.persist(dailyRecharge);
|
| 607 |
}
|
540 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
| 608 |
date = date.plusDays(1);
|
541 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
| 609 |
}
|
542 |
}
|
| 610 |
rechargeProviderRepository.persist(x);
|
543 |
date = date.plusDays(1);
|
| 611 |
});
|
544 |
}
|
| 612 |
LOGGER.info("finished generating daily recharge");
|
545 |
rechargeProviderRepository.persist(x);
|
| 613 |
}
|
546 |
});
|
| 614 |
|
547 |
LOGGER.info("finished generating daily recharge");
|
| 615 |
public void reconcileRecharge() throws Exception {
|
548 |
}
|
| 616 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
549 |
|
| 617 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
550 |
public void reconcileRecharge() throws Exception {
|
| 618 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
551 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
| 619 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
552 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
| 620 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
553 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
| 621 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
554 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
| 622 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
555 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
| 623 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
556 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
| 624 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
557 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
| 625 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
558 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
| 626 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
559 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
| 627 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
560 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
| 628 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
561 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
| 629 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
562 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
| 630 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
563 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
| 631 |
try {
|
564 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
| 632 |
int providerId = rechargeTransaction.getProviderId();
|
565 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
| 633 |
if (providerId == 1) {
|
566 |
try {
|
| 634 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
567 |
int providerId = rechargeTransaction.getProviderId();
|
| 635 |
rechargeTransaction);
|
568 |
if (providerId == 1) {
|
| 636 |
} else if (providerId == 2) {
|
569 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
| 637 |
thinkWalnutDigitalRechargeProviderService
|
570 |
rechargeTransaction);
|
| 638 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
571 |
} else if (providerId == 2) {
|
| 639 |
}
|
572 |
thinkWalnutDigitalRechargeProviderService
|
| 640 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
573 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
| 641 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
574 |
}
|
| 642 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
575 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
| 643 |
rechargeTransaction.getStatus());
|
576 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
| 644 |
}
|
577 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
| 645 |
} catch (Exception e) {
|
578 |
rechargeTransaction.getStatus());
|
| 646 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
579 |
}
|
| 647 |
}
|
580 |
} catch (Exception e) {
|
| 648 |
}
|
581 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
| 649 |
LOGGER.info("Reconcile recharge ran successfully");
|
582 |
}
|
| 650 |
}
|
583 |
}
|
| 651 |
|
584 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 652 |
public void processActivation() throws Exception {
|
585 |
}
|
| 653 |
schemeService.processActivation();
|
586 |
|
| 654 |
}
|
587 |
public void processActivation() throws Exception {
|
| 655 |
|
588 |
schemeService.processActivation();
|
| 656 |
// TemporaryMethod
|
589 |
}
|
| 657 |
public void migrateInvoice() {
|
590 |
|
| 658 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
591 |
// TemporaryMethod
|
| 659 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
592 |
public void migrateInvoice() {
|
| 660 |
partnerOrdersMap = fofoOrders.stream()
|
593 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
| 661 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
594 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 662 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
595 |
partnerOrdersMap = fofoOrders.stream()
|
| 663 |
int sequence = 0;
|
596 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 664 |
String prefix = "";
|
597 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 665 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
598 |
int sequence = 0;
|
| 666 |
.collect(Collectors.toList());
|
599 |
String prefix = "";
|
| 667 |
for (FofoOrder order : sortedList) {
|
600 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
| 668 |
|
601 |
.collect(Collectors.toList());
|
| 669 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
602 |
for (FofoOrder order : sortedList) {
|
| 670 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
603 |
|
| 671 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
604 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 672 |
prefix = order.getInvoiceNumber().split("/")[0];
|
605 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 673 |
} else {
|
606 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
| 674 |
sequence += 1;
|
607 |
prefix = order.getInvoiceNumber().split("/")[0];
|
| 675 |
String invoiceNumber = prefix + "/" + sequence;
|
608 |
} else {
|
| 676 |
order.setInvoiceNumber(invoiceNumber);
|
609 |
sequence += 1;
|
| 677 |
fofoOrderRepository.persist(order);
|
610 |
String invoiceNumber = prefix + "/" + sequence;
|
| 678 |
}
|
611 |
order.setInvoiceNumber(invoiceNumber);
|
| 679 |
}
|
612 |
fofoOrderRepository.persist(order);
|
| 680 |
|
613 |
}
|
| 681 |
}
|
614 |
}
|
| 682 |
}
|
615 |
|
| 683 |
|
616 |
}
|
| 684 |
@Autowired
|
617 |
}
|
| 685 |
private ReporticoCacheTableRepository reporticoCacheTableRepository;
|
618 |
|
| 686 |
|
619 |
@Autowired
|
| 687 |
public void processScheme(int offset, boolean dryRun) throws Exception {
|
620 |
private ReporticoCacheTableRepository reporticoCacheTableRepository;
|
| 688 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
621 |
|
| 689 |
LocalDateTime endDate = startDate.plusDays(30);
|
622 |
public void processScheme(int offset, boolean dryRun) throws Exception {
|
| 690 |
processScheme(startDate, endDate, dryRun);
|
623 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 691 |
}
|
624 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 692 |
|
625 |
processScheme(startDate, endDate, dryRun);
|
| 693 |
public void processSchemeOut(List<String> invoiceNumbers) throws Exception {
|
626 |
}
|
| 694 |
for (String invoiceNumber : invoiceNumbers) {
|
627 |
|
| 695 |
System.out.println("Invoice Number - " + invoiceNumber);
|
628 |
public void processSchemeOut(List<String> invoiceNumbers) throws Exception {
|
| 696 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
629 |
for (String invoiceNumber : invoiceNumbers) {
|
| 697 |
orderService.reverseScheme(fofoOrder);
|
630 |
System.out.println("Invoice Number - " + invoiceNumber);
|
| 698 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
631 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 699 |
}
|
632 |
orderService.reverseScheme(fofoOrder);
|
| 700 |
}
|
633 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
| 701 |
|
634 |
}
|
| 702 |
public void processSchemeIn(List<String> invoiceNumbers) throws Exception {
|
635 |
}
|
| 703 |
for (String invoiceNumber : invoiceNumbers) {
|
636 |
|
| 704 |
System.out.println("Invoice Number - " + invoiceNumber);
|
637 |
public void processSchemeIn(List<String> invoiceNumbers) throws Exception {
|
| 705 |
Purchase purchase = purchaseRepository.selectByPurchaseReference(invoiceNumber);
|
638 |
for (String invoiceNumber : invoiceNumbers) {
|
| 706 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
639 |
System.out.println("Invoice Number - " + invoiceNumber);
|
| 707 |
}
|
640 |
Purchase purchase = purchaseRepository.selectByPurchaseReference(invoiceNumber);
|
| 708 |
}
|
641 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
| 709 |
|
642 |
}
|
| 710 |
public void processScheme(int offset, int durationDays, boolean dryRun) throws Exception {
|
643 |
}
|
| 711 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
644 |
|
| 712 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
645 |
public void processScheme(int offset, int durationDays, boolean dryRun) throws Exception {
|
| 713 |
processScheme(startDate, endDate, dryRun);
|
646 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 714 |
}
|
647 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
| 715 |
|
648 |
processScheme(startDate, endDate, dryRun);
|
| 716 |
public void processScheme(boolean dryRun) throws Exception {
|
649 |
}
|
| 717 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
650 |
|
| 718 |
processScheme(fromDate, LocalDateTime.now(), dryRun);
|
651 |
public void processScheme(boolean dryRun) throws Exception {
|
| 719 |
}
|
652 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
| 720 |
|
653 |
processScheme(fromDate, LocalDateTime.now(), dryRun);
|
| 721 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate, boolean dryRun) throws Exception {
|
654 |
}
|
| 722 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
655 |
|
| 723 |
System.out.println(
|
656 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate, boolean dryRun) throws Exception {
|
| 724 |
"InventoryId\tSerialNumber\tItem Id\tScheme Id\tScheme Name\tScheme Type\tAmount Type\tDP\tTaxable\tScheme Amount\tAmount Paid");
|
657 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 725 |
try {
|
658 |
System.out.println(
|
| 726 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
659 |
"InventoryId\tSerialNumber\tItem Id\tScheme Id\tScheme Name\tScheme Type\tAmount Type\tDP\tTaxable\tScheme Amount\tAmount Paid");
|
| 727 |
for (Purchase purchase : purchases) {
|
660 |
try {
|
| 728 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
661 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
| 729 |
}
|
662 |
for (Purchase purchase : purchases) {
|
| 730 |
|
663 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
| 731 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
664 |
}
|
| 732 |
for (FofoOrder fofoOrder : fofoOrders) {
|
665 |
|
| 733 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
666 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
| 734 |
}
|
667 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 735 |
} catch (Exception e) {
|
668 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
| 736 |
e.printStackTrace();
|
669 |
}
|
| 737 |
throw e;
|
670 |
} catch (Exception e) {
|
| 738 |
}
|
671 |
e.printStackTrace();
|
| 739 |
List<UserWalletHistory> uwhs = userWalletHistoryRepository.selectAllByDateType(LocalDate.now().atStartOfDay(),
|
672 |
throw e;
|
| 740 |
endDate, Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
673 |
}
|
| 741 |
System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
|
674 |
List<UserWalletHistory> uwhs = userWalletHistoryRepository.selectAllByDateType(LocalDate.now().atStartOfDay(),
|
| 742 |
for (UserWalletHistory uwh : uwhs) {
|
675 |
endDate, Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
| 743 |
System.out.println(String.format("%d\t%d\t%s\t%s\t%s", uwh.getAmount(), uwh.getReference(),
|
676 |
System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
|
| 744 |
uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
|
677 |
for (UserWalletHistory uwh : uwhs) {
|
| 745 |
}
|
678 |
System.out.println(String.format("%d\t%d\t%s\t%s\t%s", uwh.getAmount(), uwh.getReference(),
|
| 746 |
LOGGER.info("Schemes processed successfully.");
|
679 |
uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
|
| 747 |
if (dryRun) {
|
680 |
}
|
| 748 |
throw new Exception();
|
681 |
LOGGER.info("Schemes processed successfully.");
|
| 749 |
}
|
682 |
if (dryRun) {
|
| 750 |
}
|
683 |
throw new Exception();
|
| 751 |
|
684 |
}
|
| 752 |
public void processRechargeCashback() throws Throwable {
|
685 |
}
|
| 753 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
686 |
|
| 754 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
687 |
public void processRechargeCashback() throws Throwable {
|
| 755 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
688 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 756 |
.getPendingCashBackRehargeTransactions();
|
689 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
| 757 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
690 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
| 758 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
691 |
.getPendingCashBackRehargeTransactions();
|
| 759 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
692 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
| 760 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
693 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
| 761 |
float amount = totalRetailerCashback.getValue().floatValue();
|
694 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
| 762 |
if (Math.round(amount) > 0) {
|
695 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 763 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
696 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 764 |
"Recharge Cashback", Math.round(amount), LocalDateTime.now());
|
697 |
if (Math.round(amount) > 0) {
|
| 765 |
}
|
698 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
| 766 |
}
|
699 |
"Recharge Cashback", Math.round(amount), LocalDateTime.now());
|
| 767 |
for (RechargeTransaction rt : pendingTransactions) {
|
700 |
}
|
| 768 |
rt.setCashbackTimestamp(cashbackTime);
|
701 |
}
|
| 769 |
rt.setCashbackReference(referenceId);
|
702 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 770 |
rechargeTransactionRepository.persist(rt);
|
703 |
rt.setCashbackTimestamp(cashbackTime);
|
| 771 |
}
|
704 |
rt.setCashbackReference(referenceId);
|
| 772 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
705 |
rechargeTransactionRepository.persist(rt);
|
| 773 |
}
|
706 |
}
|
| 774 |
|
707 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
| 775 |
public void rollOutUpgardedMarginsNextMonth() throws Exception {
|
708 |
}
|
| 776 |
LocalDate startOfPreviousMonth = LocalDate.now().with(ChronoField.DAY_OF_MONTH, 1).minusMonths(1);
|
709 |
|
| 777 |
|
710 |
public void rollOutUpgardedMarginsNextMonth() throws Exception {
|
| 778 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
711 |
LocalDate startOfPreviousMonth = LocalDate.now().with(ChronoField.DAY_OF_MONTH, 1).minusMonths(1);
|
| 779 |
for (FofoStore store : stores) {
|
712 |
|
| 780 |
int fofoId = store.getId();
|
713 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
| 781 |
|
714 |
for (FofoStore store : stores) {
|
| 782 |
PartnerType startOfPreviousMonthPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId,
|
715 |
int fofoId = store.getId();
|
| 783 |
startOfPreviousMonth);
|
716 |
|
| 784 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnMonth(fofoId,
|
717 |
PartnerType startOfPreviousMonthPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId,
|
| 785 |
YearMonth.from(startOfPreviousMonth.atStartOfDay()));
|
718 |
startOfPreviousMonth);
|
| 786 |
if (!startOfPreviousMonthPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
719 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnMonth(fofoId,
|
| 787 |
continue;
|
720 |
YearMonth.from(startOfPreviousMonth.atStartOfDay()));
|
| 788 |
}
|
721 |
if (!startOfPreviousMonthPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
| 789 |
if (!startOfPreviousMonthPartnerType.equals(todayPartnerType)) {
|
722 |
continue;
|
| 790 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
723 |
}
|
| 791 |
startOfPreviousMonthPartnerType, todayPartnerType);
|
724 |
if (!startOfPreviousMonthPartnerType.equals(todayPartnerType)) {
|
| 792 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
725 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
| 793 |
startOfPreviousMonth.atStartOfDay(), startOfPreviousMonth.plusMonths(1).atStartOfDay(), 0, 0);
|
726 |
startOfPreviousMonthPartnerType, todayPartnerType);
|
| 794 |
for (FofoOrder fofoOrder : fofoOrders) {
|
727 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
| 795 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
728 |
startOfPreviousMonth.atStartOfDay(), startOfPreviousMonth.plusMonths(1).atStartOfDay(), 0, 0);
|
| 796 |
}
|
729 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 797 |
|
730 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 798 |
}
|
731 |
}
|
| 799 |
}
|
732 |
|
| 800 |
}
|
733 |
}
|
| 801 |
|
734 |
}
|
| 802 |
public void rollOutUpgardedMargins() throws Exception {
|
735 |
}
|
| 803 |
LocalDate today = LocalDate.now();
|
736 |
|
| 804 |
LocalDate yesterday = today.minusDays(1);
|
737 |
public void rollOutUpgardedMargins() throws Exception {
|
| 805 |
int upgradedCount = 0;
|
738 |
LocalDate today = LocalDate.now();
|
| 806 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
739 |
LocalDate yesterday = today.minusDays(1);
|
| 807 |
StringBuilder sb = new StringBuilder();
|
740 |
int upgradedCount = 0;
|
| 808 |
for (FofoStore store : stores) {
|
741 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
| 809 |
int fofoId = store.getId();
|
742 |
StringBuilder sb = new StringBuilder();
|
| 810 |
|
743 |
for (FofoStore store : stores) {
|
| 811 |
PartnerType yesterdayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, yesterday);
|
744 |
int fofoId = store.getId();
|
| 812 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, today);
|
745 |
|
| 813 |
if (!yesterdayPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
746 |
PartnerType yesterdayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, yesterday);
|
| 814 |
continue;
|
747 |
PartnerType todayPartnerType = partnerTypeChangeService.getTypeOnDate(fofoId, today);
|
| 815 |
}
|
748 |
if (!yesterdayPartnerType.nextPartnerTypes().contains(todayPartnerType)) {
|
| 816 |
if (!yesterdayPartnerType.equals(todayPartnerType)) {
|
749 |
continue;
|
| 817 |
upgradedCount++;
|
750 |
}
|
| 818 |
sb.append(String.format("Partner Type has been changed for code %s from %s to %s", store.getCode(),
|
751 |
if (!yesterdayPartnerType.equals(todayPartnerType)) {
|
| 819 |
yesterdayPartnerType.toString(), todayPartnerType.toString()));
|
752 |
upgradedCount++;
|
| 820 |
sb.append("<br>");
|
753 |
sb.append(String.format("Partner Type has been changed for code %s from %s to %s", store.getCode(),
|
| 821 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
754 |
yesterdayPartnerType.toString(), todayPartnerType.toString()));
|
| 822 |
yesterdayPartnerType, todayPartnerType);
|
755 |
sb.append("<br>");
|
| 823 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
756 |
LOGGER.info("Partner Type has been changed for code {} from {} to {}", store.getCode(),
|
| 824 |
yesterday.withDayOfMonth(1).atStartOfDay(), yesterday.atStartOfDay(), 0, 0);
|
757 |
yesterdayPartnerType, todayPartnerType);
|
| 825 |
for (FofoOrder fofoOrder : fofoOrders) {
|
758 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectByFofoId(fofoId,
|
| 826 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
759 |
yesterday.withDayOfMonth(1).atStartOfDay(), yesterday.atStartOfDay(), 0, 0);
|
| 827 |
}
|
760 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 828 |
|
761 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 829 |
}
|
762 |
}
|
| 830 |
}
|
763 |
|
| 831 |
if (upgradedCount > 0) {
|
764 |
}
|
| 832 |
sendMailHtmlFormat(
|
765 |
}
|
| 833 |
new String[] { "amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
766 |
if (upgradedCount > 0) {
|
| 834 |
"neeraj.gupta@smartdukaan.com" },
|
767 |
sendMailHtmlFormat(
|
| 835 |
sb.toString(), null, "Few Partners Category have been Upgraded");
|
768 |
new String[]{"amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 836 |
} else {
|
769 |
"neeraj.gupta@smartdukaan.com"},
|
| 837 |
sendMailHtmlFormat(
|
770 |
sb.toString(), null, "Few Partners Category have been Upgraded");
|
| 838 |
new String[] { "amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
771 |
} else {
|
| 839 |
"neeraj.gupta@smartdukaan.com" },
|
772 |
sendMailHtmlFormat(
|
| 840 |
sb.toString(), null, "No partners Category have been upgraded today");
|
773 |
new String[]{"amit.gupta@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 841 |
}
|
774 |
"neeraj.gupta@smartdukaan.com"},
|
| 842 |
}
|
775 |
sb.toString(), null, "No partners Category have been upgraded today");
|
| 843 |
|
776 |
}
|
| 844 |
@Autowired
|
777 |
}
|
| 845 |
private PartnerStatsService partnerStatsService;
|
778 |
|
| 846 |
|
779 |
@Autowired
|
| 847 |
// Temporary Method
|
780 |
private PartnerStatsService partnerStatsService;
|
| 848 |
public void evaluateExcessSchemeOut() throws Exception {
|
781 |
|
| 849 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
782 |
// Temporary Method
|
| 850 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
783 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 851 |
|
784 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
| 852 |
List<List<?>> rows = new ArrayList<>();
|
785 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 853 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
786 |
|
| 854 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
787 |
List<List<?>> rows = new ArrayList<>();
|
| 855 |
schemeRepository.selectAll().stream().forEach(x -> {
|
788 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
| 856 |
if (x.getType().equals(SchemeType.OUT)) {
|
789 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 857 |
List<SchemeInOut> sioList = schemeInOutRepository
|
790 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 858 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
791 |
if (x.getType().equals(SchemeType.OUT)) {
|
| 859 |
if (x.getActiveTimestamp() != null) {
|
792 |
List<SchemeInOut> sioList = schemeInOutRepository
|
| 860 |
LocalDateTime endDateTime = x.getEndDateTime();
|
793 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
| 861 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
794 |
if (x.getActiveTimestamp() != null) {
|
| 862 |
endDateTime = x.getExpireTimestamp();
|
795 |
LocalDateTime endDateTime = x.getEndDateTime();
|
| 863 |
}
|
796 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
| 864 |
for (SchemeInOut sio : sioList) {
|
797 |
endDateTime = x.getExpireTimestamp();
|
| 865 |
InventoryItem inventoryItem = null;
|
798 |
}
|
| 866 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
799 |
for (SchemeInOut sio : sioList) {
|
| 867 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
800 |
InventoryItem inventoryItem = null;
|
| 868 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
801 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 869 |
Optional<ScanRecord> record = scanRecordRepository
|
802 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
| 870 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
803 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 871 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
804 |
Optional<ScanRecord> record = scanRecordRepository
|
| 872 |
if (record.isPresent()) {
|
805 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
| 873 |
int fofoId = record.get().getFofoId();
|
806 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
| 874 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
807 |
if (record.isPresent()) {
|
| 875 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
808 |
int fofoId = record.get().getFofoId();
|
| 876 |
if (!userAmountMap.containsKey(fofoId)) {
|
809 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
| 877 |
userAmountMap.put(fofoId, 0f);
|
810 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
| 878 |
}
|
811 |
if (!userAmountMap.containsKey(fofoId)) {
|
| 879 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
812 |
userAmountMap.put(fofoId, 0f);
|
| 880 |
try {
|
813 |
}
|
| 881 |
rows.add(Arrays.asList(x.getDescription(),
|
814 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
| 882 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
815 |
try {
|
| 883 |
userNameMap.get(fofoId), sio.getAmount(),
|
816 |
rows.add(Arrays.asList(x.getDescription(),
|
| 884 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
817 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 885 |
fofoOrder.getInvoiceNumber(),
|
818 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 886 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
819 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
| 887 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
820 |
fofoOrder.getInvoiceNumber(),
|
| 888 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
821 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
| 889 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
822 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
| 890 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
823 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
| 891 |
} catch (Exception e) {
|
824 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
| 892 |
e.printStackTrace();
|
825 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 893 |
}
|
826 |
} catch (Exception e) {
|
| 894 |
}
|
827 |
e.printStackTrace();
|
| 895 |
}
|
828 |
}
|
| 896 |
}
|
829 |
}
|
| 897 |
}
|
830 |
}
|
| 898 |
}
|
831 |
}
|
| 899 |
});
|
832 |
}
|
| 900 |
userAmountMap.entrySet().stream()
|
833 |
}
|
| 901 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
834 |
});
|
| 902 |
x.getValue(), userNameMap.get(x.getKey())));
|
835 |
userAmountMap.entrySet().stream()
|
| 903 |
|
836 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
| 904 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
837 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 905 |
Utils.sendMailWithAttachment(googleMailSender,
|
838 |
|
| 906 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
839 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 907 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
840 |
Utils.sendMailWithAttachment(googleMailSender,
|
| 908 |
|
841 |
new String[]{"amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com"}, null,
|
| 909 |
}
|
842 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 910 |
|
843 |
|
| 911 |
public void fetchParnterStats() throws Exception {
|
844 |
}
|
| 912 |
Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
|
845 |
|
| 913 |
ObjectOutputStream oos = null;
|
846 |
public void fetchParnterStats() throws Exception {
|
| 914 |
FileOutputStream fout = null;
|
847 |
Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
|
| 915 |
try {
|
848 |
ObjectOutputStream oos = null;
|
| 916 |
fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
|
849 |
FileOutputStream fout = null;
|
| 917 |
oos = new ObjectOutputStream(fout);
|
850 |
try {
|
| 918 |
oos.writeObject(partnerStats);
|
851 |
fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
|
| 919 |
|
852 |
oos = new ObjectOutputStream(fout);
|
| 920 |
} catch (Exception ex) {
|
853 |
oos.writeObject(partnerStats);
|
| 921 |
ex.printStackTrace();
|
854 |
|
| 922 |
} finally {
|
855 |
} catch (Exception ex) {
|
| 923 |
if (oos != null) {
|
856 |
ex.printStackTrace();
|
| 924 |
oos.close();
|
857 |
} finally {
|
| 925 |
}
|
858 |
if (oos != null) {
|
| 926 |
}
|
859 |
oos.close();
|
| 927 |
ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
|
860 |
}
|
| 928 |
if (rct == null) {
|
861 |
}
|
| 929 |
rct = new ReporticoCacheTable();
|
862 |
ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
|
| 930 |
rct.setTableName("partnerStat");
|
863 |
if (rct == null) {
|
| 931 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
864 |
rct = new ReporticoCacheTable();
|
| 932 |
reporticoCacheTableRepository.persist(rct);
|
865 |
rct.setTableName("partnerStat");
|
| 933 |
} else {
|
866 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
| 934 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
867 |
reporticoCacheTableRepository.persist(rct);
|
| 935 |
}
|
868 |
} else {
|
| 936 |
}
|
869 |
rct.setLastCreatedTimestamp(LocalDateTime.now());
|
| 937 |
|
870 |
}
|
| 938 |
public void processPriceDrop() throws Exception {
|
871 |
}
|
| 939 |
List<PriceDrop> priceDrops = priceDropRepository.selectAllByDatesBetween(LocalDateTime.now(),
|
872 |
|
| 940 |
LocalDateTime.now().minusYears(1));
|
873 |
public void processPriceDrop() throws Exception {
|
| 941 |
for (PriceDrop priceDrop : priceDrops) {
|
874 |
List<PriceDrop> priceDrops = priceDropRepository.selectAllByDatesBetween(LocalDateTime.now(),
|
| 942 |
if (priceDrop.getDropAmount() > 0) {
|
875 |
LocalDateTime.now().minusYears(1));
|
| 943 |
priceDropService.processPriceDrop(priceDrop.getId(), true);
|
876 |
for (PriceDrop priceDrop : priceDrops) {
|
| 944 |
}
|
877 |
if (priceDrop.getDropAmount() > 0) {
|
| 945 |
}
|
878 |
priceDropService.processPriceDrop(priceDrop.getId(), true);
|
| 946 |
}
|
879 |
}
|
| 947 |
|
880 |
}
|
| 948 |
@Autowired
|
881 |
}
|
| 949 |
CreditNoteService creditNoteService;
|
882 |
|
| 950 |
|
883 |
@Autowired
|
| 951 |
public void sendCreditNote(YearMonth yearMonth) throws Exception {
|
884 |
CreditNoteService creditNoteService;
|
| 952 |
creditNoteService.issueMonthlyMarginsCN(yearMonth);
|
885 |
|
| 953 |
}
|
886 |
public void sendCreditNote(YearMonth yearMonth) throws Exception {
|
| 954 |
|
887 |
creditNoteService.issueMonthlyMarginsCN(yearMonth);
|
| 955 |
private class SaleRoles {
|
888 |
}
|
| 956 |
|
889 |
|
| 957 |
private List<String> l1;
|
890 |
private class SaleRoles {
|
| 958 |
private List<String> l2;
|
891 |
|
| 959 |
|
892 |
private List<String> l1;
|
| 960 |
public SaleRoles() {
|
893 |
private List<String> l2;
|
| 961 |
l1 = new ArrayList<>();
|
894 |
|
| 962 |
l2 = new ArrayList<>();
|
895 |
public SaleRoles() {
|
| 963 |
}
|
896 |
l1 = new ArrayList<>();
|
| 964 |
|
897 |
l2 = new ArrayList<>();
|
| 965 |
public List<String> getL1() {
|
898 |
}
|
| 966 |
return l1;
|
899 |
|
| 967 |
}
|
900 |
public List<String> getL1() {
|
| 968 |
|
901 |
return l1;
|
| 969 |
public List<String> getL2() {
|
902 |
}
|
| 970 |
return l2;
|
903 |
|
| 971 |
}
|
904 |
public List<String> getL2() {
|
| 972 |
|
905 |
return l2;
|
| 973 |
}
|
906 |
}
|
| 974 |
|
907 |
|
| 975 |
private class FofoReportingModel {
|
908 |
}
|
| 976 |
private String code;
|
909 |
|
| 977 |
private int fofoId;
|
910 |
private class FofoReportingModel {
|
| 978 |
private String businessName;
|
911 |
private String code;
|
| 979 |
private String territoryManager;
|
912 |
private int fofoId;
|
| 980 |
private String regionalManager;
|
913 |
private String businessName;
|
| 981 |
|
914 |
private String territoryManager;
|
| 982 |
@Override
|
915 |
private String regionalManager;
|
| 983 |
public String toString() {
|
916 |
private String businessManager;
|
| 984 |
return "FofoReportingModel [code=" + code + ", fofoId=" + fofoId + ", businessName=" + businessName
|
917 |
|
| 985 |
+ ", territoryManager=" + territoryManager + ", regionalManager=" + regionalManager + "]";
|
918 |
public String getCode() {
|
| 986 |
}
|
919 |
return code;
|
| 987 |
|
920 |
}
|
| 988 |
public String getCode() {
|
921 |
|
| 989 |
return code;
|
922 |
public void setCode(String code) {
|
| 990 |
}
|
923 |
this.code = code;
|
| 991 |
|
924 |
}
|
| 992 |
public void setCode(String code) {
|
925 |
|
| 993 |
this.code = code;
|
926 |
public String getBusinessName() {
|
| 994 |
}
|
927 |
return businessName;
|
| 995 |
|
928 |
}
|
| 996 |
public String getBusinessName() {
|
929 |
|
| 997 |
return businessName;
|
930 |
public void setBusinessName(String businessName) {
|
| 998 |
}
|
931 |
this.businessName = businessName;
|
| 999 |
|
932 |
}
|
| 1000 |
public void setBusinessName(String businessName) {
|
933 |
|
| 1001 |
this.businessName = businessName;
|
934 |
public String getTerritoryManager() {
|
| 1002 |
}
|
935 |
return territoryManager;
|
| 1003 |
|
936 |
}
|
| 1004 |
public String getTerritoryManager() {
|
937 |
|
| 1005 |
return territoryManager;
|
938 |
public void setTerritoryManager(String territoryManager) {
|
| 1006 |
}
|
939 |
this.territoryManager = territoryManager;
|
| 1007 |
|
940 |
}
|
| 1008 |
public void setTerritoryManager(String territoryManager) {
|
941 |
|
| 1009 |
this.territoryManager = territoryManager;
|
942 |
public String getRegionalManager() {
|
| 1010 |
}
|
943 |
return regionalManager;
|
| 1011 |
|
944 |
}
|
| 1012 |
public String getRegionalManager() {
|
945 |
|
| 1013 |
return regionalManager;
|
946 |
public void setRegionalManager(String regionalManager) {
|
| 1014 |
}
|
947 |
this.regionalManager = regionalManager;
|
| 1015 |
|
948 |
}
|
| 1016 |
public void setRegionalManager(String regionalManager) {
|
949 |
|
| 1017 |
this.regionalManager = regionalManager;
|
950 |
private ScheduledTasks getOuterType() {
|
| 1018 |
}
|
951 |
return ScheduledTasks.this;
|
| 1019 |
|
952 |
}
|
| 1020 |
private ScheduledTasks getOuterType() {
|
953 |
|
| 1021 |
return ScheduledTasks.this;
|
954 |
@Override
|
| 1022 |
}
|
955 |
public String toString() {
|
| 1023 |
|
956 |
return "FofoReportingModel{" +
|
| 1024 |
@Override
|
957 |
"code='" + code + '\'' +
|
| 1025 |
public int hashCode() {
|
958 |
", fofoId=" + fofoId +
|
| 1026 |
final int prime = 31;
|
959 |
", businessName='" + businessName + '\'' +
|
| 1027 |
int result = 1;
|
960 |
", territoryManager='" + territoryManager + '\'' +
|
| 1028 |
result = prime * result + getOuterType().hashCode();
|
961 |
", regionalManager='" + regionalManager + '\'' +
|
| 1029 |
result = prime * result + ((businessName == null) ? 0 : businessName.hashCode());
|
962 |
", businessManager='" + businessManager + '\'' +
|
| 1030 |
result = prime * result + ((code == null) ? 0 : code.hashCode());
|
963 |
'}';
|
| 1031 |
result = prime * result + fofoId;
|
964 |
}
|
| 1032 |
result = prime * result + ((regionalManager == null) ? 0 : regionalManager.hashCode());
|
965 |
|
| 1033 |
result = prime * result + ((territoryManager == null) ? 0 : territoryManager.hashCode());
|
966 |
@Override
|
| 1034 |
return result;
|
967 |
public boolean equals(Object o) {
|
| 1035 |
}
|
968 |
if (this == o) return true;
|
| 1036 |
|
969 |
if (o == null || getClass() != o.getClass()) return false;
|
| 1037 |
@Override
|
970 |
FofoReportingModel that = (FofoReportingModel) o;
|
| 1038 |
public boolean equals(Object obj) {
|
971 |
return fofoId == that.fofoId && Objects.equals(code, that.code) && Objects.equals(businessName, that.businessName) && Objects.equals(territoryManager, that.territoryManager) && Objects.equals(regionalManager, that.regionalManager) && Objects.equals(businessManager, that.businessManager);
|
| 1039 |
if (this == obj)
|
972 |
}
|
| 1040 |
return true;
|
973 |
|
| 1041 |
if (obj == null)
|
974 |
@Override
|
| 1042 |
return false;
|
975 |
public int hashCode() {
|
| 1043 |
if (getClass() != obj.getClass())
|
976 |
return Objects.hash(code, fofoId, businessName, territoryManager, regionalManager, businessManager);
|
| 1044 |
return false;
|
977 |
}
|
| 1045 |
FofoReportingModel other = (FofoReportingModel) obj;
|
978 |
|
| 1046 |
if (!getOuterType().equals(other.getOuterType()))
|
979 |
public String getBusinessManager() {
|
| 1047 |
return false;
|
980 |
return businessManager;
|
| 1048 |
if (businessName == null) {
|
981 |
}
|
| 1049 |
if (other.businessName != null)
|
982 |
|
| 1050 |
return false;
|
983 |
public void setBusinessManager(String businessManager) {
|
| 1051 |
} else if (!businessName.equals(other.businessName))
|
984 |
this.businessManager = businessManager;
|
| 1052 |
return false;
|
985 |
}
|
| 1053 |
if (code == null) {
|
986 |
|
| 1054 |
if (other.code != null)
|
987 |
public int getFofoId() {
|
| 1055 |
return false;
|
988 |
return fofoId;
|
| 1056 |
} else if (!code.equals(other.code))
|
989 |
}
|
| 1057 |
return false;
|
990 |
|
| 1058 |
if (fofoId != other.fofoId)
|
991 |
public void setFofoId(int fofoId) {
|
| 1059 |
return false;
|
992 |
this.fofoId = fofoId;
|
| 1060 |
if (regionalManager == null) {
|
993 |
}
|
| 1061 |
if (other.regionalManager != null)
|
994 |
|
| 1062 |
return false;
|
995 |
}
|
| 1063 |
} else if (!regionalManager.equals(other.regionalManager))
|
996 |
|
| 1064 |
return false;
|
997 |
@Autowired
|
| 1065 |
if (territoryManager == null) {
|
998 |
WarehouseInventoryItemRepository warehouseInventoryItemRepository;
|
| 1066 |
if (other.territoryManager != null)
|
999 |
|
| 1067 |
return false;
|
1000 |
public void test() throws Exception {
|
| 1068 |
} else if (!territoryManager.equals(other.territoryManager))
|
1001 |
//this.sendMailForSamsungRebilling();
|
| 1069 |
return false;
|
1002 |
priceDropService.getAllSerialNumbersByAffectedDate(LocalDateTime.now(), 1023170);
|
| 1070 |
return true;
|
1003 |
}
|
| 1071 |
}
|
1004 |
|
| 1072 |
|
1005 |
public void sendMailForSamsungRebilling() throws Exception {
|
| 1073 |
public int getFofoId() {
|
1006 |
List<BilledImeiModel> samsungModels = warehouseInventoryItemRepository.findByBillingDateBrand(LocalDate.now(), "Samsung");
|
| 1074 |
return fofoId;
|
1007 |
LOGGER.info("SamsungModels {}", samsungModels);
|
| 1075 |
}
|
1008 |
samsungModels = samsungModels.stream().sorted(Comparator.comparing(x -> x.getPcmDate() == null ? -1 : 1)).collect(Collectors.toList());
|
| 1076 |
|
1009 |
if (samsungModels.size() > 0) {
|
| 1077 |
public void setFofoId(int fofoId) {
|
1010 |
List<String> headers = Arrays.asList("Partner Id", "Code", "Name", "City", "Brand", "Model Name", "Model Number", "Color", "Serial Number", "Remarks");
|
| 1078 |
this.fofoId = fofoId;
|
1011 |
List<List<?>> rows = new ArrayList<>();
|
| 1079 |
}
|
1012 |
for (BilledImeiModel billedImeiModel : samsungModels) {
|
| 1080 |
|
1013 |
List<Serializable> row = Arrays.asList(billedImeiModel.getFofoId(), billedImeiModel.getStoreCode(), billedImeiModel.getStoreName(),
|
| 1081 |
}
|
1014 |
billedImeiModel.getStoreCity(), billedImeiModel.getBrand(), billedImeiModel.getModelName(), billedImeiModel.getModelNumber(),
|
| 1082 |
|
1015 |
billedImeiModel.getColor(), billedImeiModel.getSerialNumber(), billedImeiModel.getPcmDate() == null ? "PCM date Missing" : "Rebill Imeis");
|
| 1083 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
1016 |
rows.add(row);
|
| 1084 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
1017 |
}
|
| 1085 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
1018 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 1086 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
1019 |
String[] sendToArray = new String[]{"kamini.sharma@smartdukaan.com", "praveen.sharma@smartdukaan.com"};
|
| 1087 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
1020 |
String fileName = "Imeis need Rebilling -" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 1088 |
|
1021 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{"tarun.verma@smartdukaan.com"}, "Samsung Rebilling IMEI Summary", "PFA",
|
| 1089 |
List<String> headers = Arrays.asList("Code", "Outlet name", "State Manager", "Teritory/Team Lead",
|
1022 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 1090 |
"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount",
|
1023 |
}
|
| 1091 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty",
|
1024 |
}
|
| 1092 |
"Short Days");
|
1025 |
|
| 1093 |
List<List<?>> rows = new ArrayList<>();
|
1026 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 1094 |
Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
|
1027 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 1095 |
|
1028 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 1096 |
Map<Integer, FofoReportingModel> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
|
1029 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
| 1097 |
|
1030 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 1098 |
Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository
|
1031 |
|
| 1099 |
.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now()).stream().collect(Collectors.groupingBy(
|
1032 |
List<String> headers = Arrays.asList("Code", "Outlet name", "State Manager", "Teritory/Team Lead",
|
| 1100 |
x -> x.getFofoId(), Collectors.summingInt(x -> x.getShortPercentage() > 10 ? 1 : 0)));
|
1033 |
"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount",
|
| 1101 |
|
1034 |
"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty",
|
| 1102 |
for (FofoStore fofoStore : fofoStores) {
|
1035 |
"Short Days");
|
| 1103 |
LOGGER.info("Fofo Store {}, {}", fofoStore.getId(), fofoStore.getCode());
|
1036 |
List<List<?>> rows = new ArrayList<>();
|
| 1104 |
int fofoId = fofoStore.getId();
|
1037 |
Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
|
| 1105 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 1);
|
1038 |
|
| 1106 |
partnerDailyInvestment.setDate(yesterDay);
|
1039 |
Map<Integer, FofoReportingModel> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
|
| 1107 |
|
1040 |
|
| 1108 |
try {
|
1041 |
Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository
|
| 1109 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
1042 |
.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now()).stream().collect(Collectors.groupingBy(
|
| 1110 |
shortDaysMap.put(fofoId,
|
1043 |
x -> x.getFofoId(), Collectors.summingInt(x -> x.getShortPercentage() > 10 ? 1 : 0)));
|
| 1111 |
shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
|
1044 |
|
| 1112 |
} catch (Exception e) {
|
1045 |
for (FofoStore fofoStore : fofoStores) {
|
| 1113 |
// ignore the exceptions during persist
|
1046 |
LOGGER.info("Fofo Store {}, {}", fofoStore.getId(), fofoStore.getCode());
|
| 1114 |
}
|
1047 |
int fofoId = fofoStore.getId();
|
| 1115 |
|
1048 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 1);
|
| 1116 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
1049 |
partnerDailyInvestment.setDate(yesterDay);
|
| 1117 |
if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
|
1050 |
|
| 1118 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
1051 |
try {
|
| 1119 |
continue;
|
1052 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 1120 |
}
|
1053 |
shortDaysMap.put(fofoId,
|
| 1121 |
FofoReportingModel reportingModel = partnerIdSalesHeaderMap.get(fofoStore.getId());
|
1054 |
shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
|
| 1122 |
List<Serializable> row = new ArrayList<>();
|
1055 |
} catch (Exception e) {
|
| 1123 |
row.addAll(Arrays.asList(reportingModel.getCode(), reportingModel.getBusinessName(),
|
1056 |
// ignore the exceptions during persist
|
| 1124 |
reportingModel.getRegionalManager(), reportingModel.getTerritoryManager()));
|
1057 |
}
|
| 1125 |
row.addAll(
|
1058 |
|
| 1126 |
Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
|
1059 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 1127 |
partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-"
|
1060 |
if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
|
| 1128 |
: "(" + partnerDailyInvestment.getActivatedStockAmount() + ")",
|
1061 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
| 1129 |
0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
1062 |
continue;
|
| 1130 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
1063 |
}
|
| 1131 |
partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),
|
1064 |
FofoReportingModel reportingModel = partnerIdSalesHeaderMap.get(fofoStore.getId());
|
| 1132 |
shortDaysMap.get(fofoId)));
|
1065 |
List<Serializable> row = new ArrayList<>();
|
| 1133 |
partnerRowsMap.put(fofoStore.getId(), row);
|
1066 |
row.addAll(Arrays.asList(reportingModel.getCode(), reportingModel.getBusinessName(),
|
| 1134 |
rows.add(row);
|
1067 |
reportingModel.getRegionalManager(), reportingModel.getTerritoryManager()));
|
| 1135 |
|
1068 |
row.addAll(
|
| 1136 |
}
|
1069 |
Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
|
| 1137 |
|
1070 |
partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-"
|
| 1138 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
1071 |
: "(" + partnerDailyInvestment.getActivatedStockAmount() + ")",
|
| 1139 |
|
1072 |
0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
| 1140 |
if (sendTo == null) {
|
1073 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
| 1141 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
1074 |
partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),
|
| 1142 |
List<List<?>> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerRowsMap.get(x))
|
1075 |
shortDaysMap.get(fofoId)));
|
| 1143 |
.filter(x -> x != null).collect(Collectors.toList());
|
1076 |
partnerRowsMap.put(fofoStore.getId(), row);
|
| 1144 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
1077 |
rows.add(row);
|
| 1145 |
String[] sendToArray = new String[] { storeGuyEntry.getKey() };
|
1078 |
|
| 1146 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
1079 |
}
|
| 1147 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
1080 |
|
| 1148 |
}
|
1081 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 1149 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
1082 |
|
| 1150 |
"neeraj.gupta@smartdukaan.com", "amit.gupta@shop2020.in", "manish.gupta@smartdukaan.com",
|
1083 |
if (sendTo == null) {
|
| 1151 |
"niranjan.kala@smartdukaan.com");
|
1084 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
| 1152 |
}
|
1085 |
List<List<?>> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerRowsMap.get(x))
|
| 1153 |
|
1086 |
.filter(x -> x != null).collect(Collectors.toList());
|
| 1154 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
1087 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
| 1155 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
1088 |
String[] sendToArray = new String[]{storeGuyEntry.getKey()};
|
| 1156 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
1089 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
| 1157 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
1090 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 1158 |
|
1091 |
}
|
| 1159 |
}
|
1092 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
| 1160 |
|
1093 |
"neeraj.gupta@smartdukaan.com", "amit.gupta@shop2020.in", "manish.gupta@smartdukaan.com",
|
| 1161 |
private Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
|
1094 |
"niranjan.kala@smartdukaan.com");
|
| 1162 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
1095 |
}
|
| 1163 |
|
1096 |
|
| 1164 |
List<Position> positions = positionRepository
|
1097 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 1165 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
1098 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
| 1166 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
|
1099 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
| 1167 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
1100 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 1168 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = csService.getPositionCustomRetailerMap(positions);
|
1101 |
|
| 1169 |
for (Position position : positions) {
|
1102 |
}
|
| 1170 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
1103 |
|
| 1171 |
if (crList == null)
|
1104 |
private Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
|
| 1172 |
continue;
|
1105 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
| 1173 |
for (CustomRetailer cr : crList) {
|
1106 |
Map<String, SaleRoles> partnerEmailRBMMap = new HashMap<>();
|
| 1174 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
1107 |
|
| 1175 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
1108 |
List<Position> positions = positionRepository
|
| 1176 |
}
|
1109 |
.selectPositionByCategoryIds(Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_RBM));
|
| 1177 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
1110 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
|
| 1178 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
1111 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 1179 |
if (authUser == null) {
|
1112 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = csService.getPositionCustomRetailerMap(positions);
|
| 1180 |
continue;
|
1113 |
for (Position position : positions) {
|
| 1181 |
}
|
1114 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
| 1182 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
1115 |
if (crList == null)
|
| 1183 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
1116 |
continue;
|
| 1184 |
saleRoles.getL1().add(name);
|
1117 |
if (position.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES) {
|
| 1185 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
1118 |
for (CustomRetailer cr : crList) {
|
| 1186 |
saleRoles.getL2().add(name);
|
1119 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
| 1187 |
}
|
1120 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
| 1188 |
}
|
1121 |
}
|
| 1189 |
}
|
1122 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
| 1190 |
|
1123 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
| 1191 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
1124 |
if (authUser == null) {
|
| 1192 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
1125 |
continue;
|
| 1193 |
allCrList.addAll(cr);
|
1126 |
}
|
| 1194 |
}
|
1127 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
| 1195 |
|
1128 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
| 1196 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
|
1129 |
saleRoles.getL1().add(name);
|
| 1197 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
1130 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
| 1198 |
|
1131 |
saleRoles.getL2().add(name);
|
| 1199 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
|
1132 |
}
|
| 1200 |
|
1133 |
}
|
| 1201 |
for (CustomRetailer cr : allCrList) {
|
1134 |
}
|
| 1202 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
1135 |
if (position.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM) {
|
| 1203 |
if (fofoStore == null) {
|
1136 |
for (CustomRetailer cr : crList) {
|
| 1204 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
1137 |
if (!partnerEmailRBMMap.containsKey(cr.getEmail())) {
|
| 1205 |
continue;
|
1138 |
partnerEmailRBMMap.put(cr.getEmail(), new SaleRoles());
|
| 1206 |
}
|
1139 |
}
|
| 1207 |
String code = fofoStore.getCode();
|
1140 |
SaleRoles saleRoles = partnerEmailRBMMap.get(cr.getEmail());
|
| 1208 |
// String storeName = "SmartDukaan-" +
|
1141 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
| 1209 |
// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
1142 |
if (authUser == null) {
|
| 1210 |
String businessName = cr.getBusinessName();
|
1143 |
continue;
|
| 1211 |
try {
|
1144 |
}
|
| 1212 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
1145 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
| 1213 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
1146 |
if (position.getEscalationType().equals(EscalationType.L1) || position.getEscalationType().equals(EscalationType.L1)) {
|
| 1214 |
FofoReportingModel reportingModel = new FofoReportingModel();
|
1147 |
saleRoles.getL1().add(name);
|
| 1215 |
reportingModel.setBusinessName(businessName);
|
1148 |
}
|
| 1216 |
reportingModel.setCode(code);
|
1149 |
/*else if (position.getEscalationType().equals(EscalationType.L2)) {
|
| 1217 |
reportingModel.setFofoId(fofoStore.getId());
|
1150 |
saleRoles.getL2().add(name);
|
| 1218 |
reportingModel.setRegionalManager(stateManager);
|
1151 |
}*/
|
| 1219 |
reportingModel.setTerritoryManager(territoryManager);
|
1152 |
}
|
| 1220 |
partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
|
1153 |
}
|
| 1221 |
} catch (Exception e) {
|
1154 |
|
| 1222 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
1155 |
}
|
| 1223 |
}
|
1156 |
|
| 1224 |
}
|
1157 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
| 1225 |
return partnerIdSalesHeadersMap;
|
1158 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
| 1226 |
|
1159 |
allCrList.addAll(cr);
|
| 1227 |
}
|
1160 |
}
|
| 1228 |
|
1161 |
|
| 1229 |
public void sendPartnerInvestmentDetails() throws Exception {
|
1162 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
|
| 1230 |
this.sendPartnerInvestmentDetails(null);
|
1163 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 1231 |
}
|
1164 |
|
| 1232 |
|
1165 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
|
| 1233 |
public void sendAgeingReport(String... sendTo) throws Exception {
|
1166 |
|
| 1234 |
|
1167 |
for (CustomRetailer cr : allCrList) {
|
| 1235 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
|
1168 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
| 1236 |
"itemstockageing.xml");
|
1169 |
if (fofoStore == null) {
|
| 1237 |
InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
1170 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
| 1238 |
"ItemwiseOverallPendingIndent.xml");
|
1171 |
continue;
|
| 1239 |
Attachment attachment = new Attachment(
|
1172 |
}
|
| 1240 |
"ageing-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
|
1173 |
String code = fofoStore.getCode();
|
| 1241 |
Attachment attachment1 = new Attachment(
|
1174 |
// String storeName = "SmartDukaan-" +
|
| 1242 |
"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
|
1175 |
// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
| 1243 |
|
1176 |
String businessName = cr.getBusinessName();
|
| 1244 |
Utils.sendMailWithAttachments(googleMailSender, STOCK_AGEING_MAIL_LIST, null, "Stock Ageing Report", "PFA",
|
1177 |
try {
|
| 1245 |
attachment);
|
1178 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
| 1246 |
Utils.sendMailWithAttachments(googleMailSender, ITEMWISE_PENDING_INDENT_MAIL_LIST, null,
|
1179 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
| 1247 |
"Itemwise Pending indent", "PFA", attachment1);
|
1180 |
String bdm = StringUtils.join(partnerEmailRBMMap.get(cr.getEmail()).getL1(), ", ");
|
| 1248 |
|
1181 |
FofoReportingModel reportingModel = new FofoReportingModel();
|
| 1249 |
// Reports to be sent to mapped partners
|
1182 |
reportingModel.setBusinessName(businessName);
|
| 1250 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
1183 |
reportingModel.setCode(code);
|
| 1251 |
|
1184 |
reportingModel.setFofoId(fofoStore.getId());
|
| 1252 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
1185 |
reportingModel.setRegionalManager(stateManager);
|
| 1253 |
Map<String, String> params = new HashMap<>();
|
1186 |
reportingModel.setTerritoryManager(territoryManager);
|
| 1254 |
if (storeGuyEntry.getValue().size() == 0)
|
1187 |
reportingModel.setBusinessManager(bdm);
|
| 1255 |
continue;
|
1188 |
partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
|
| 1256 |
params.put("MANUAL_email", String.join(",", storeGuyEntry.getValue()));
|
1189 |
} catch (Exception e) {
|
| 1257 |
InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
1190 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
| 1258 |
"focostockreport.xml", params);
|
1191 |
}
|
| 1259 |
Attachment attache = new Attachment(
|
1192 |
}
|
| 1260 |
"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
|
1193 |
return partnerIdSalesHeadersMap;
|
| 1261 |
System.out.println(storeGuyEntry.getValue());
|
1194 |
|
| 1262 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
|
1195 |
}
|
| 1263 |
"Franchise Stock Report", "PFA", attache);
|
1196 |
|
| 1264 |
}
|
1197 |
public void sendPartnerInvestmentDetails() throws Exception {
|
| 1265 |
|
1198 |
this.sendPartnerInvestmentDetails(null);
|
| 1266 |
}
|
1199 |
}
|
| 1267 |
|
1200 |
|
| 1268 |
public void sendIndentTertiary() throws Exception {
|
1201 |
public void sendAgeingReport(String... sendTo) throws Exception {
|
| 1269 |
|
1202 |
|
| 1270 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
1203 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
|
| 1271 |
"indentandtertiary.xml");
|
1204 |
"itemstockageing.xml");
|
| 1272 |
Attachment attachment = new Attachment(
|
1205 |
InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 1273 |
"indentandtertiary-report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr);
|
1206 |
"ItemwiseOverallPendingIndent.xml");
|
| 1274 |
Utils.sendMailWithAttachments(googleMailSender, INDENT_TERTIARY_MAIL_LIST, null, "Indent Tertiary Report",
|
1207 |
Attachment attachment = new Attachment(
|
| 1275 |
"PFA", attachment);
|
1208 |
"ageing-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
|
| 1276 |
|
1209 |
Attachment attachment1 = new Attachment(
|
| 1277 |
}
|
1210 |
"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
|
| 1278 |
|
1211 |
|
| 1279 |
public void sendAttendanceMorningAlert() throws Exception {
|
1212 |
Utils.sendMailWithAttachments(googleMailSender, STOCK_AGEING_MAIL_LIST, null, "Stock Ageing Report", "PFA",
|
| 1280 |
LocalDateTime moriningTime = LocalDate.now().atTime(10, 31);
|
1213 |
attachment);
|
| 1281 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
1214 |
Utils.sendMailWithAttachments(googleMailSender, ITEMWISE_PENDING_INDENT_MAIL_LIST, null,
|
| 1282 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
1215 |
"Itemwise Pending indent", "PFA", attachment1);
|
| 1283 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
1216 |
|
| 1284 |
|
1217 |
// Reports to be sent to mapped partners
|
| 1285 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
1218 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
| 1286 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
1219 |
|
| 1287 |
|
1220 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
| 1288 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository
|
1221 |
Map<String, String> params = new HashMap<>();
|
| 1289 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now());
|
1222 |
if (storeGuyEntry.getValue().size() == 0)
|
| 1290 |
|
1223 |
continue;
|
| 1291 |
Map<Integer, Optional<EmployeeAttendance>> employeeMorningAttendance = employeeAttendances.stream()
|
1224 |
params.put("MANUAL_email", String.join(",", storeGuyEntry.getValue()));
|
| 1292 |
.collect(Collectors.groupingBy(EmployeeAttendance::getUserId,
|
1225 |
InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 1293 |
Collectors.minBy(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))));
|
1226 |
"focostockreport.xml", params);
|
| 1294 |
for (AuthUser authUser : authUsers) {
|
1227 |
Attachment attache = new Attachment(
|
| 1295 |
User user = userMap.get(authUser.getEmailId());
|
1228 |
"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
|
| 1296 |
Optional<EmployeeAttendance> employeeAttendanceOptional = employeeMorningAttendance.get(user.getId());
|
1229 |
System.out.println(storeGuyEntry.getValue());
|
| 1297 |
LOGGER.info("AuthUser - {}, employeeAttendanceOptional {}", authUser.getName(), employeeAttendanceOptional);
|
1230 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{storeGuyEntry.getKey()}, null,
|
| 1298 |
if (employeeAttendanceOptional != null) {
|
1231 |
"Franchise Stock Report", "PFA", attache);
|
| 1299 |
LOGGER.info("employeeAttendanceOptional.orElse {}", employeeAttendanceOptional.orElse(null));
|
1232 |
}
|
| 1300 |
if (employeeAttendanceOptional.orElse(null) != null) {
|
1233 |
|
| 1301 |
LOGGER.info("employeeAttendanceOptional.get().getCreateTimestamp() {}",
|
1234 |
}
|
| 1302 |
employeeAttendanceOptional.get().getCreateTimestamp());
|
1235 |
|
| 1303 |
}
|
1236 |
public void sendIndentTertiary() throws Exception {
|
| 1304 |
}
|
1237 |
|
| 1305 |
if (employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null
|
1238 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 1306 |
|| employeeAttendanceOptional.get().getCreateTimestamp().isAfter(moriningTime)) {
|
1239 |
"indentandtertiary.xml");
|
| 1307 |
LOGGER.info("Will Send Email to {}", authUser.getFullName());
|
1240 |
Attachment attachment = new Attachment(
|
| 1308 |
String body = String.format(
|
1241 |
"indentandtertiary-report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr);
|
| 1309 |
"Dear %s,\n Pls note that you haven't punched your attendance by 10:30am%s. You have been marked absent for half the day.\n\nRegards\nHR Team",
|
1242 |
Utils.sendMailWithAttachments(googleMailSender, INDENT_TERTIARY_MAIL_LIST, null, "Indent Tertiary Report",
|
| 1310 |
authUser.getFullName(),
|
1243 |
"PFA", attachment);
|
| 1311 |
(employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null) ? ""
|
1244 |
|
| 1312 |
: "(Punched at "
|
1245 |
}
|
| 1313 |
+ FormattingUtils.format(employeeAttendanceOptional.get().getCreateTimestamp())
|
1246 |
|
| 1314 |
+ ")");
|
1247 |
public void sendAttendanceMorningAlert() throws Exception {
|
| 1315 |
|
1248 |
LocalDateTime moriningTime = LocalDate.now().atTime(10, 31);
|
| 1316 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() },
|
1249 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 1317 |
new String[] { "kangan.monga@smartdukaan.com" }, "Attendance Alert", body);
|
1250 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
| 1318 |
|
1251 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
| 1319 |
}
|
1252 |
|
| 1320 |
}
|
1253 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
| 1321 |
|
1254 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
| 1322 |
}
|
1255 |
|
| 1323 |
|
1256 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository
|
| 1324 |
public void sendAttendanceEveningAlert() throws Exception {
|
1257 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now());
|
| 1325 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
1258 |
|
| 1326 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
1259 |
Map<Integer, Optional<EmployeeAttendance>> employeeMorningAttendance = employeeAttendances.stream()
|
| 1327 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
1260 |
.collect(Collectors.groupingBy(EmployeeAttendance::getUserId,
|
| 1328 |
|
1261 |
Collectors.minBy(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))));
|
| 1329 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
1262 |
for (AuthUser authUser : authUsers) {
|
| 1330 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
1263 |
User user = userMap.get(authUser.getEmailId());
|
| 1331 |
|
1264 |
Optional<EmployeeAttendance> employeeAttendanceOptional = employeeMorningAttendance.get(user.getId());
|
| 1332 |
Map<Integer, List<EmployeeAttendance>> employeeAttendancesMap = employeeAttendanceRepository
|
1265 |
LOGGER.info("AuthUser - {}, employeeAttendanceOptional {}", authUser.getName(), employeeAttendanceOptional);
|
| 1333 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now()).stream()
|
1266 |
if (employeeAttendanceOptional != null) {
|
| 1334 |
.collect(Collectors.groupingBy(x -> x.getUserId()));
|
1267 |
LOGGER.info("employeeAttendanceOptional.orElse {}", employeeAttendanceOptional.orElse(null));
|
| 1335 |
|
1268 |
if (employeeAttendanceOptional.orElse(null) != null) {
|
| 1336 |
for (AuthUser authUser : authUsers) {
|
1269 |
LOGGER.info("employeeAttendanceOptional.get().getCreateTimestamp() {}",
|
| 1337 |
User user = userMap.get(authUser.getEmailId());
|
1270 |
employeeAttendanceOptional.get().getCreateTimestamp());
|
| 1338 |
String body = null;
|
1271 |
}
|
| 1339 |
List<EmployeeAttendance> employeeAttendances = employeeAttendancesMap.get(user.getId());
|
1272 |
}
|
| 1340 |
if (employeeAttendances == null) {
|
1273 |
if (employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null
|
| 1341 |
body = String.format(
|
1274 |
|| employeeAttendanceOptional.get().getCreateTimestamp().isAfter(moriningTime)) {
|
| 1342 |
"Dear %s,\n No attendance has been registered by you today. You have been marked absent for the day.\n\nRegards\nHR Team",
|
1275 |
LOGGER.info("Will Send Email to {}", authUser.getFullName());
|
| 1343 |
authUser.getFullName());
|
1276 |
String body = String.format(
|
| 1344 |
} else {
|
1277 |
"Dear %s,\n Pls note that you haven't punched your attendance by 10:30am%s. You have been marked absent for half the day.\n\nRegards\nHR Team",
|
| 1345 |
List<LocalDateTime> punchTimes = employeeAttendances.stream()
|
1278 |
authUser.getFullName(),
|
| 1346 |
.sorted(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))
|
1279 |
(employeeAttendanceOptional == null || employeeAttendanceOptional.orElse(null) == null) ? ""
|
| 1347 |
.map(x -> x.getCreateTimestamp()).collect(Collectors.toList());
|
1280 |
: "(Punched at "
|
| 1348 |
if (punchTimes.size() == 1) {
|
1281 |
+ FormattingUtils.format(employeeAttendanceOptional.get().getCreateTimestamp())
|
| 1349 |
// body = String.format("Dear %s,\n Pls note that you haven't punched out yet.
|
1282 |
+ ")");
|
| 1350 |
// You have been marked absent for half the day. You may contact your manager
|
1283 |
|
| 1351 |
// and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
1284 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{authUser.getEmailId()},
|
| 1352 |
} else {
|
1285 |
new String[]{"kangan.monga@smartdukaan.com"}, "Attendance Alert", body);
|
| 1353 |
LocalDateTime firstPunch = punchTimes.get(0);
|
1286 |
|
| 1354 |
LocalDateTime lastPunch = punchTimes.get(punchTimes.size() - 1);
|
1287 |
}
|
| 1355 |
Duration duration = Duration.between(firstPunch, lastPunch);
|
1288 |
}
|
| 1356 |
boolean hoursCompleted = lastPunch.isAfter(firstPunch.plusHours(8).plusMinutes(30));
|
1289 |
|
| 1357 |
if (!hoursCompleted) {
|
1290 |
}
|
| 1358 |
body = String.format(
|
1291 |
|
| 1359 |
"Dear %s,\n Pls note that you haven't completed 8.30 Hrs (%d.%d Hrs). You have been marked absent for half the day.\n\nRegards\nHR Team",
|
1292 |
public void sendAttendanceEveningAlert() throws Exception {
|
| 1360 |
authUser.getFullName(), duration.toHours(),
|
1293 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 1361 |
duration.toMinutes() - duration.toHours() * 60);
|
1294 |
Map<String, AuthUser> authUserEmailMap = authUsers.stream().filter(x -> x.isActive())
|
| 1362 |
}
|
1295 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
| 1363 |
}
|
1296 |
|
| 1364 |
|
1297 |
List<User> users = dtrUserRepository.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.keySet()));
|
| 1365 |
}
|
1298 |
Map<String, User> userMap = users.stream().collect(Collectors.toMap(x -> x.getEmailId(), x -> x));
|
| 1366 |
if (body != null) {
|
1299 |
|
| 1367 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { authUser.getEmailId() },
|
1300 |
Map<Integer, List<EmployeeAttendance>> employeeAttendancesMap = employeeAttendanceRepository
|
| 1368 |
new String[] { "kangan.monga@smartdukaan.com" }, "Attendance Alert", body);
|
1301 |
.selectAllByDatesBetween(LocalDate.now().atStartOfDay(), LocalDateTime.now()).stream()
|
| 1369 |
}
|
1302 |
.collect(Collectors.groupingBy(x -> x.getUserId()));
|
| 1370 |
}
|
1303 |
|
| 1371 |
|
1304 |
for (AuthUser authUser : authUsers) {
|
| 1372 |
this.sendMailToHR();
|
1305 |
User user = userMap.get(authUser.getEmailId());
|
| 1373 |
|
1306 |
String body = null;
|
| 1374 |
}
|
1307 |
List<EmployeeAttendance> employeeAttendances = employeeAttendancesMap.get(user.getId());
|
| 1375 |
|
1308 |
if (employeeAttendances == null) {
|
| 1376 |
private void sendMailToHR() throws Exception {
|
1309 |
body = String.format(
|
| 1377 |
Map<String, String> map = new HashMap<>();
|
1310 |
"Dear %s,\n No attendance has been registered by you today. You have been marked absent for the day.\n\nRegards\nHR Team",
|
| 1378 |
String reporticoDate = FormattingUtils.formatReporitcoDate(LocalDateTime.now());
|
1311 |
authUser.getFullName());
|
| 1379 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
1312 |
} else {
|
| 1380 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
1313 |
List<LocalDateTime> punchTimes = employeeAttendances.stream()
|
| 1381 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
1314 |
.sorted(Comparator.comparing(EmployeeAttendance::getCreateTimestamp))
|
| 1382 |
"employeeattendance.xml");
|
1315 |
.map(x -> x.getCreateTimestamp()).collect(Collectors.toList());
|
| 1383 |
Attachment attachment = new Attachment("attendance-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv",
|
1316 |
if (punchTimes.size() == 1) {
|
| 1384 |
isr);
|
1317 |
// body = String.format("Dear %s,\n Pls note that you haven't punched out yet.
|
| 1385 |
Utils.sendMailWithAttachments(googleMailSender, EMPLOYEE_ATTENDANCE_MAIL_LIST, null,
|
1318 |
// You have been marked absent for half the day. You may contact your manager
|
| 1386 |
"Attendance - " + FormattingUtils.formatDate(LocalDateTime.now()), "PFA Attendance", attachment);
|
1319 |
// and get it regularise.\n\nRegards\nHR Team", authUser.getFullName());
|
| 1387 |
}
|
1320 |
} else {
|
| 1388 |
|
1321 |
LocalDateTime firstPunch = punchTimes.get(0);
|
| 1389 |
public void checkPartnerActiveStore() throws Exception {
|
1322 |
LocalDateTime lastPunch = punchTimes.get(punchTimes.size() - 1);
|
| 1390 |
|
1323 |
Duration duration = Duration.between(firstPunch, lastPunch);
|
| 1391 |
List<FofoStore> fofoStores = fofoStoreRepository.selectByStatus(true);
|
1324 |
boolean hoursCompleted = lastPunch.isAfter(firstPunch.plusHours(8).plusMinutes(30));
|
| 1392 |
|
1325 |
if (!hoursCompleted) {
|
| 1393 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
1326 |
body = String.format(
|
| 1394 |
if (!fofoStores.isEmpty()) {
|
1327 |
"Dear %s,\n Pls note that you haven't completed 8.30 Hrs (%d.%d Hrs). You have been marked absent for half the day.\n\nRegards\nHR Team",
|
| 1395 |
for (FofoStore fofoStore : fofoStores) {
|
1328 |
authUser.getFullName(), duration.toHours(),
|
| 1396 |
|
1329 |
duration.toMinutes() - duration.toHours() * 60);
|
| 1397 |
if (currentDate.isBefore(fofoStore.getActiveTimeStamp())) {
|
1330 |
}
|
| 1398 |
|
1331 |
}
|
| 1399 |
fofoStore.setActive(true);
|
1332 |
|
| 1400 |
fofoStoreRepository.persist(fofoStore);
|
1333 |
}
|
| 1401 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
1334 |
if (body != null) {
|
| 1402 |
|
1335 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{authUser.getEmailId()},
|
| 1403 |
} else {
|
1336 |
new String[]{"kangan.monga@smartdukaan.com"}, "Attendance Alert", body);
|
| 1404 |
fofoStore.setActive(false);
|
1337 |
}
|
| 1405 |
fofoStore.setActiveTimeStamp(null);
|
1338 |
}
|
| 1406 |
fofoStoreRepository.persist(fofoStore);
|
1339 |
|
| 1407 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
1340 |
this.sendMailToHR();
|
| 1408 |
}
|
1341 |
|
| 1409 |
|
1342 |
}
|
| 1410 |
}
|
1343 |
|
| 1411 |
}
|
1344 |
private void sendMailToHR() throws Exception {
|
| 1412 |
|
1345 |
Map<String, String> map = new HashMap<>();
|
| 1413 |
}
|
1346 |
String reporticoDate = FormattingUtils.formatReporitcoDate(LocalDateTime.now());
|
| 1414 |
|
1347 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
| 1415 |
public void sendAgeingReport() throws Exception {
|
1348 |
map.put("MANUAL_datesBetween_FROMDATE", reporticoDate);
|
| 1416 |
sendAgeingReport("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
1349 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 1417 |
"niranjan.kala@smartdukaan.com", "manish.gupta@smartdukaan.com", "kuldeep.kumar@smartdukaan.com");
|
1350 |
"employeeattendance.xml");
|
| 1418 |
}
|
1351 |
Attachment attachment = new Attachment("attendance-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv",
|
| 1419 |
|
1352 |
isr);
|
| 1420 |
public void moveImeisToPriceDropImeis() throws Exception {
|
1353 |
Utils.sendMailWithAttachments(googleMailSender, EMPLOYEE_ATTENDANCE_MAIL_LIST, null,
|
| 1421 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
1354 |
"Attendance - " + FormattingUtils.formatDate(LocalDateTime.now()), "PFA Attendance", attachment);
|
| 1422 |
for (PriceDrop priceDrop : priceDrops) {
|
1355 |
}
|
| 1423 |
priceDropService.priceDropStatus(priceDrop.getId());
|
1356 |
|
| 1424 |
}
|
1357 |
public void checkPartnerActiveStore() throws Exception {
|
| 1425 |
}
|
1358 |
|
| 1426 |
|
1359 |
List<FofoStore> fofoStores = fofoStoreRepository.selectByStatus(true);
|
| 1427 |
public void walletmismatch() throws Exception {
|
1360 |
|
| 1428 |
LocalDate curDate = LocalDate.now();
|
1361 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
| 1429 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
1362 |
if (!fofoStores.isEmpty()) {
|
| 1430 |
System.out.println(pdis.size());
|
1363 |
for (FofoStore fofoStore : fofoStores) {
|
| 1431 |
for (PartnerDailyInvestment pdi : pdis) {
|
1364 |
|
| 1432 |
int fofoId = pdi.getFofoId();
|
1365 |
if (currentDate.isBefore(fofoStore.getActiveTimeStamp())) {
|
| 1433 |
for (PartnerDailyInvestment investment : Lists
|
1366 |
|
| 1434 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
1367 |
fofoStore.setActive(true);
|
| 1435 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
1368 |
fofoStoreRepository.persist(fofoStore);
|
| 1436 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
1369 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
| 1437 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
1370 |
|
| 1438 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
|
1371 |
} else {
|
| 1439 |
investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
|
1372 |
fofoStore.setActive(false);
|
| 1440 |
|
1373 |
fofoStore.setActiveTimeStamp(null);
|
| 1441 |
}
|
1374 |
fofoStoreRepository.persist(fofoStore);
|
| 1442 |
}
|
1375 |
LOGGER.info("inserted into InActiveFofoStore successfully");
|
| 1443 |
|
1376 |
}
|
| 1444 |
}
|
1377 |
|
| 1445 |
|
1378 |
}
|
| 1446 |
@Autowired
|
1379 |
}
|
| 1447 |
StateRepository stateRepository;
|
1380 |
|
| 1448 |
|
1381 |
}
|
| 1449 |
public void gst() throws Exception {
|
1382 |
|
| 1450 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2021, 8, 16).atStartOfDay(),
|
1383 |
public void sendAgeingReport() throws Exception {
|
| 1451 |
LocalDateTime.now());
|
1384 |
sendAgeingReport("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 1452 |
for (FofoOrder fofoOrder : fofoOrders) {
|
1385 |
"niranjan.kala@smartdukaan.com", "manish.gupta@smartdukaan.com", "kuldeep.kumar@smartdukaan.com");
|
| 1453 |
int retailerAddressId = retailerRegisteredAddressRepository
|
1386 |
}
|
| 1454 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
1387 |
|
| 1455 |
|
1388 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 1456 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
1389 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 1457 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
1390 |
for (PriceDrop priceDrop : priceDrops) {
|
| 1458 |
Integer stateId = null;
|
1391 |
priceDropService.priceDropStatus(priceDrop.getId());
|
| 1459 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
1392 |
}
|
| 1460 |
try {
|
1393 |
}
|
| 1461 |
stateId = stateRepository.selectByName(customerAddress.getState()).getId();
|
1394 |
|
| 1462 |
} catch (Exception e) {
|
1395 |
public void walletmismatch() throws Exception {
|
| 1463 |
LOGGER.error("Cannot found state named {}", customerAddress.getState());
|
1396 |
LocalDate curDate = LocalDate.now();
|
| 1464 |
continue;
|
1397 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 1465 |
}
|
1398 |
System.out.println(pdis.size());
|
| 1466 |
}
|
1399 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 1467 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
1400 |
int fofoId = pdi.getFofoId();
|
| 1468 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
1401 |
for (PartnerDailyInvestment investment : Lists
|
| 1469 |
|
1402 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 1470 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
1403 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 1471 |
List<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
1404 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 1472 |
if (stateId != null) {
|
1405 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 1473 |
itemIdStateTaxRateMap = stateGstRateRepository.getStateTaxRate(itemIds, stateId);
|
1406 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
|
| 1474 |
} else {
|
1407 |
investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
|
| 1475 |
itemIdIgstTaxRateMap = stateGstRateRepository.getIgstTaxRate(itemIds);
|
1408 |
|
| 1476 |
}
|
1409 |
}
|
| 1477 |
|
1410 |
}
|
| 1478 |
for (FofoOrderItem foi : fofoOrderItems) {
|
1411 |
|
| 1479 |
float sgstRate = foi.getSgstRate();
|
1412 |
}
|
| 1480 |
float cgstRate = foi.getCgstRate();
|
1413 |
|
| 1481 |
float igstRate = foi.getIgstRate();
|
1414 |
@Autowired
|
| 1482 |
if (stateId == null && igstRate == 0) {
|
1415 |
StateRepository stateRepository;
|
| 1483 |
|
1416 |
|
| 1484 |
foi.setSgstRate(0);
|
1417 |
public void gst() throws Exception {
|
| 1485 |
foi.setCgstRate(0);
|
1418 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2021, 8, 16).atStartOfDay(),
|
| 1486 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
1419 |
LocalDateTime.now());
|
| 1487 |
|
1420 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 1488 |
LOGGER.info("Invoice {}, Date {}", fofoOrder.getInvoiceNumber(), fofoOrder.getCreateTimestamp());
|
1421 |
int retailerAddressId = retailerRegisteredAddressRepository
|
| 1489 |
LOGGER.info("customerAddress.getState() {}, retailerAddress.getState() {}",
|
1422 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 1490 |
customerAddress.getState(), retailerAddress.getState());
|
1423 |
|
| 1491 |
LOGGER.info("Rates getIgstRate() {}", itemIdIgstTaxRateMap.get(foi.getItemId()));
|
1424 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 1492 |
|
1425 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 1493 |
} else if (stateId != null && sgstRate == 0 && cgstRate == 0) {
|
1426 |
Integer stateId = null;
|
| 1494 |
|
1427 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
| 1495 |
foi.setIgstRate(0);
|
1428 |
try {
|
| 1496 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
1429 |
stateId = stateRepository.selectByName(customerAddress.getState()).getId();
|
| 1497 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
1430 |
} catch (Exception e) {
|
| 1498 |
|
1431 |
LOGGER.error("Cannot found state named {}", customerAddress.getState());
|
| 1499 |
LOGGER.info("Invoice {}, Date {}", fofoOrder.getInvoiceNumber(), fofoOrder.getCreateTimestamp());
|
1432 |
continue;
|
| 1500 |
LOGGER.info("customerAddress.getState() {}, retailerAddress.getState() {}",
|
1433 |
}
|
| 1501 |
customerAddress.getState(), retailerAddress.getState());
|
1434 |
}
|
| 1502 |
LOGGER.info("Rates getCgstRate() {}, getSgstRate() {}",
|
1435 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
| 1503 |
itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate(),
|
1436 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 1504 |
itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
1437 |
|
| 1505 |
}
|
1438 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 1506 |
}
|
1439 |
List<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
| 1507 |
}
|
1440 |
if (stateId != null) {
|
| 1508 |
|
1441 |
itemIdStateTaxRateMap = stateGstRateRepository.getStateTaxRate(itemIds, stateId);
|
| 1509 |
}
|
1442 |
} else {
|
| 1510 |
|
1443 |
itemIdIgstTaxRateMap = stateGstRateRepository.getIgstTaxRate(itemIds);
|
| 1511 |
public void schemewalletmismatch() {
|
1444 |
}
|
| 1512 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
1445 |
|
| 1513 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
1446 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 1514 |
reconcileSchemes(dateToReconcile);
|
1447 |
float sgstRate = foi.getSgstRate();
|
| 1515 |
// reconcileOrders(dateTime);
|
1448 |
float cgstRate = foi.getCgstRate();
|
| 1516 |
// reconcileRecharges(dateTime);
|
1449 |
float igstRate = foi.getIgstRate();
|
| 1517 |
dateToReconcile = dateToReconcile.plusDays(1);
|
1450 |
if (stateId == null && igstRate == 0) {
|
| 1518 |
}
|
1451 |
|
| 1519 |
}
|
1452 |
foi.setSgstRate(0);
|
| 1520 |
|
1453 |
foi.setCgstRate(0);
|
| 1521 |
private void reconcileSchemes(LocalDate date) {
|
1454 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
| 1522 |
LocalDateTime startDate = date.atStartOfDay();
|
1455 |
|
| 1523 |
LocalDateTime endDate = startDate.plusDays(1);
|
1456 |
LOGGER.info("Invoice {}, Date {}", fofoOrder.getInvoiceNumber(), fofoOrder.getCreateTimestamp());
|
| 1524 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
1457 |
LOGGER.info("customerAddress.getState() {}, retailerAddress.getState() {}",
|
| 1525 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
1458 |
customerAddress.getState(), retailerAddress.getState());
|
| 1526 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
1459 |
LOGGER.info("Rates getIgstRate() {}", itemIdIgstTaxRateMap.get(foi.getItemId()));
|
| 1527 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
1460 |
|
| 1528 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
1461 |
} else if (stateId != null && sgstRate == 0 && cgstRate == 0) {
|
| 1529 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
1462 |
|
| 1530 |
WalletReferenceType.SCHEME_OUT);
|
1463 |
foi.setIgstRate(0);
|
| 1531 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
1464 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
| 1532 |
walletReferenceTypes);
|
1465 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
| 1533 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
1466 |
|
| 1534 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
1467 |
LOGGER.info("Invoice {}, Date {}", fofoOrder.getInvoiceNumber(), fofoOrder.getCreateTimestamp());
|
| 1535 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
1468 |
LOGGER.info("customerAddress.getState() {}, retailerAddress.getState() {}",
|
| 1536 |
|
1469 |
customerAddress.getState(), retailerAddress.getState());
|
| 1537 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
1470 |
LOGGER.info("Rates getCgstRate() {}, getSgstRate() {}",
|
| 1538 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
1471 |
itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate(),
|
| 1539 |
|
1472 |
itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
| 1540 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
1473 |
}
|
| 1541 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
1474 |
}
|
| 1542 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
1475 |
}
|
| 1543 |
|
1476 |
|
| 1544 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
1477 |
}
|
| 1545 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
1478 |
|
| 1546 |
|
1479 |
public void schemewalletmismatch() {
|
| 1547 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
1480 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
| 1548 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
1481 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
| 1549 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
1482 |
reconcileSchemes(dateToReconcile);
|
| 1550 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
1483 |
// reconcileOrders(dateTime);
|
| 1551 |
|
1484 |
// reconcileRecharges(dateTime);
|
| 1552 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
1485 |
dateToReconcile = dateToReconcile.plusDays(1);
|
| 1553 |
|
1486 |
}
|
| 1554 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
1487 |
}
|
| 1555 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
1488 |
|
| 1556 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
1489 |
private void reconcileSchemes(LocalDate date) {
|
| 1557 |
} else {
|
1490 |
LocalDateTime startDate = date.atStartOfDay();
|
| 1558 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
1491 |
LocalDateTime endDate = startDate.plusDays(1);
|
| 1559 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
1492 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
| 1560 |
}
|
1493 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
| 1561 |
}
|
1494 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 1562 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
1495 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 1563 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
1496 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
| 1564 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
1497 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
| 1565 |
|
1498 |
WalletReferenceType.SCHEME_OUT);
|
| 1566 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
1499 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
| 1567 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
1500 |
walletReferenceTypes);
|
| 1568 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
1501 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 1569 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
1502 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
| 1570 |
if (diff > 5) {
|
1503 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
| 1571 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
1504 |
|
| 1572 |
}
|
1505 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
| 1573 |
}
|
1506 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
| 1574 |
}
|
1507 |
|
| 1575 |
|
1508 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
| 1576 |
}
|
1509 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
| 1577 |
|
1510 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
| 1578 |
public void dryRunSchemeReco() throws Exception {
|
1511 |
|
| 1579 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
1512 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
| 1580 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
1513 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
| 1581 |
|
1514 |
|
| 1582 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
1515 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
| 1583 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
1516 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
| 1584 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
1517 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
| 1585 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
1518 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
| 1586 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
1519 |
|
| 1587 |
|
1520 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
| 1588 |
LocalDateTime startDate = LocalDate.of(2018, 3, 1).atStartOfDay();
|
1521 |
|
| 1589 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
1522 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
| 1590 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
1523 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
| 1591 |
|
1524 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
| 1592 |
Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
|
1525 |
} else {
|
| 1593 |
purchases.stream().forEach(purchase -> {
|
1526 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
| 1594 |
float amountToRollback = 0;
|
1527 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
| 1595 |
String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
|
1528 |
}
|
| 1596 |
+ purchase.getPurchaseReference();
|
1529 |
}
|
| 1597 |
Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
|
1530 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
| 1598 |
.stream().filter(ii -> ii.getSerialNumber() != null)
|
1531 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
| 1599 |
.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
|
1532 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 1600 |
if (inventorySerialNumberMap.size() > 0) {
|
1533 |
|
| 1601 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
1534 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
| 1602 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
1535 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
| 1603 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
1536 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
| 1604 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
1537 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
| 1605 |
// This will rollback scheme for differenct orders for same serial
|
1538 |
if (diff > 5) {
|
| 1606 |
List<SchemeInOut> sios = schemeInOutRepository
|
1539 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
| 1607 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
1540 |
}
|
| 1608 |
.filter(x -> x.getRolledBackTimestamp() == null
|
1541 |
}
|
| 1609 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
1542 |
}
|
| 1610 |
.collect(Collectors.toList());
|
1543 |
|
| 1611 |
Collections.reverse(sios);
|
1544 |
}
|
| 1612 |
for (SchemeInOut sio : sios) {
|
1545 |
|
| 1613 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
1546 |
public void dryRunSchemeReco() throws Exception {
|
| 1614 |
amountToRollback += sio.getAmount();
|
1547 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
| 1615 |
// sio.setSchemeType(SchemeType.OUT);
|
1548 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 1616 |
sio.setSerialNumber(serialNumber);
|
1549 |
|
| 1617 |
rolledbackSios.add(sio);
|
1550 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
| 1618 |
}
|
1551 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 1619 |
description = description.concat(" " + serialNumber + " ");
|
1552 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
| 1620 |
} else {
|
1553 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 1621 |
serialNumbersConsidered.add(serialNumber);
|
1554 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
| 1622 |
List<Integer> schemesConsidered = new ArrayList<>();
|
1555 |
|
| 1623 |
List<SchemeInOut> sios = schemeInOutRepository
|
1556 |
LocalDateTime startDate = LocalDate.of(2018, 3, 1).atStartOfDay();
|
| 1624 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
1557 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
| 1625 |
.filter(x -> x.getRolledBackTimestamp() == null
|
1558 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
| 1626 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
1559 |
|
| 1627 |
.collect(Collectors.toList());
|
1560 |
Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
|
| 1628 |
Collections.reverse(sios);
|
1561 |
purchases.stream().forEach(purchase -> {
|
| 1629 |
for (SchemeInOut sio : sios) {
|
1562 |
float amountToRollback = 0;
|
| 1630 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
1563 |
String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
|
| 1631 |
schemesConsidered.add(sio.getSchemeId());
|
1564 |
+ purchase.getPurchaseReference();
|
| 1632 |
continue;
|
1565 |
Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
|
| 1633 |
}
|
1566 |
.stream().filter(ii -> ii.getSerialNumber() != null)
|
| 1634 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
1567 |
.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
|
| 1635 |
amountToRollback += sio.getAmount();
|
1568 |
if (inventorySerialNumberMap.size() > 0) {
|
| 1636 |
// sio.setSchemeType(SchemeType.OUT);
|
1569 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
| 1637 |
sio.setSerialNumber(serialNumber);
|
1570 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
| 1638 |
sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
1571 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
| 1639 |
sio.setReference(purchase.getId());
|
1572 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
| 1640 |
rolledbackSios.add(sio);
|
1573 |
// This will rollback scheme for differenct orders for same serial
|
| 1641 |
}
|
1574 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 1642 |
}
|
1575 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 1643 |
|
1576 |
.filter(x -> x.getRolledBackTimestamp() == null
|
| 1644 |
}
|
1577 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
| 1645 |
}
|
1578 |
.collect(Collectors.toList());
|
| 1646 |
if (amountToRollback > 0) {
|
1579 |
Collections.reverse(sios);
|
| 1647 |
// Address address =
|
1580 |
for (SchemeInOut sio : sios) {
|
| 1648 |
// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
|
1581 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 1649 |
UserWalletHistory uwh = new UserWalletHistory();
|
1582 |
amountToRollback += sio.getAmount();
|
| 1650 |
uwh.setAmount(Math.round(amountToRollback));
|
1583 |
// sio.setSchemeType(SchemeType.OUT);
|
| 1651 |
uwh.setDescription(description);
|
1584 |
sio.setSerialNumber(serialNumber);
|
| 1652 |
uwh.setTimestamp(LocalDateTime.now());
|
1585 |
rolledbackSios.add(sio);
|
| 1653 |
uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
|
1586 |
}
|
| 1654 |
uwh.setReference(purchase.getId());
|
1587 |
description = description.concat(" " + serialNumber + " ");
|
| 1655 |
uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
|
1588 |
} else {
|
| 1656 |
uwh.setFofoId(purchase.getFofoId());
|
1589 |
serialNumbersConsidered.add(serialNumber);
|
| 1657 |
uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
1590 |
List<Integer> schemesConsidered = new ArrayList<>();
|
| 1658 |
userWalletHistory.add(uwh);
|
1591 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 1659 |
}
|
1592 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 1660 |
});
|
1593 |
.filter(x -> x.getRolledBackTimestamp() == null
|
| 1661 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
1594 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
| 1662 |
Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
1595 |
.collect(Collectors.toList());
|
| 1663 |
"Timestamp"),
|
1596 |
Collections.reverse(sios);
|
| 1664 |
userWalletHistory.stream()
|
1597 |
for (SchemeInOut sio : sios) {
|
| 1665 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
1598 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
| 1666 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
1599 |
schemesConsidered.add(sio.getSchemeId());
|
| 1667 |
.collect(Collectors.toList()));
|
1600 |
continue;
|
| 1668 |
|
1601 |
}
|
| 1669 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
1602 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 1670 |
Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
|
1603 |
amountToRollback += sio.getAmount();
|
| 1671 |
"Created", "Rolledback"),
|
1604 |
// sio.setSchemeType(SchemeType.OUT);
|
| 1672 |
rolledbackSios.stream()
|
1605 |
sio.setSerialNumber(serialNumber);
|
| 1673 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
|
1606 |
sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
| 1674 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
1607 |
sio.setReference(purchase.getId());
|
| 1675 |
.collect(Collectors.toList()));
|
1608 |
rolledbackSios.add(sio);
|
| 1676 |
|
1609 |
}
|
| 1677 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
1610 |
}
|
| 1678 |
"Partner Excess Amount Scheme In", "PFA",
|
1611 |
|
| 1679 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
1612 |
}
|
| 1680 |
new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
1613 |
}
|
| 1681 |
|
1614 |
if (amountToRollback > 0) {
|
| 1682 |
throw new Exception();
|
1615 |
// Address address =
|
| 1683 |
|
1616 |
// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
|
| 1684 |
}
|
1617 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 1685 |
|
1618 |
uwh.setAmount(Math.round(amountToRollback));
|
| 1686 |
public void dryRunOutSchemeReco() throws Exception {
|
1619 |
uwh.setDescription(description);
|
| 1687 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
1620 |
uwh.setTimestamp(LocalDateTime.now());
|
| 1688 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
1621 |
uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
|
| 1689 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
1622 |
uwh.setReference(purchase.getId());
|
| 1690 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
1623 |
uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
|
| 1691 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
1624 |
uwh.setFofoId(purchase.getFofoId());
|
| 1692 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
1625 |
uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
| 1693 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
1626 |
userWalletHistory.add(uwh);
|
| 1694 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
1627 |
}
|
| 1695 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
1628 |
});
|
| 1696 |
// Collections.reverse(allOrders);
|
1629 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 1697 |
// List<FofoOrder> allOrders =
|
1630 |
Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
| 1698 |
// List<FofoOrder> allOrders =
|
1631 |
"Timestamp"),
|
| 1699 |
// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
|
1632 |
userWalletHistory.stream()
|
| 1700 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
1633 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
| 1701 |
allOrders.stream().forEach(fofoOrder -> {
|
1634 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 1702 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
1635 |
.collect(Collectors.toList()));
|
| 1703 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
1636 |
|
| 1704 |
float amountToRollback = 0;
|
1637 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 1705 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
1638 |
Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
|
| 1706 |
orderItems.forEach(x -> {
|
1639 |
"Created", "Rolledback"),
|
| 1707 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
1640 |
rolledbackSios.stream()
|
| 1708 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
1641 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
|
| 1709 |
});
|
1642 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
| 1710 |
if (inventorySerialNumberMap.size() > 0) {
|
1643 |
.collect(Collectors.toList()));
|
| 1711 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
1644 |
|
| 1712 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
1645 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@shop2020.in"}, null,
|
| 1713 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
1646 |
"Partner Excess Amount Scheme In", "PFA",
|
| 1714 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
1647 |
new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
| 1715 |
// This will rollback scheme for differenct orders for same serial
|
1648 |
new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
|
| 1716 |
List<SchemeInOut> sios = schemeInOutRepository
|
1649 |
|
| 1717 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
1650 |
throw new Exception();
|
| 1718 |
.filter(x -> x.getRolledBackTimestamp() == null
|
1651 |
|
| 1719 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
1652 |
}
|
| 1720 |
.collect(Collectors.toList());
|
1653 |
|
| 1721 |
Collections.reverse(sios);
|
1654 |
public void dryRunOutSchemeReco() throws Exception {
|
| 1722 |
for (SchemeInOut sio : sios) {
|
1655 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
| 1723 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
1656 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 1724 |
amountToRollback += sio.getAmount();
|
1657 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
| 1725 |
// sio.setSchemeType(SchemeType.OUT);
|
1658 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 1726 |
sio.setSerialNumber(serialNumber);
|
1659 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
| 1727 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
1660 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 1728 |
sio.setReference(fofoOrder.getId());
|
1661 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
| 1729 |
rolledbackSios.add(sio);
|
1662 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
| 1730 |
}
|
1663 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
| 1731 |
description = description.concat(" " + serialNumber + " ");
|
1664 |
// Collections.reverse(allOrders);
|
| 1732 |
} else {
|
1665 |
// List<FofoOrder> allOrders =
|
| 1733 |
serialNumbersConsidered.add(serialNumber);
|
1666 |
// List<FofoOrder> allOrders =
|
| 1734 |
List<Integer> schemesConsidered = new ArrayList<>();
|
1667 |
// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
|
| 1735 |
List<SchemeInOut> sios = schemeInOutRepository
|
1668 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
| 1736 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
1669 |
allOrders.stream().forEach(fofoOrder -> {
|
| 1737 |
.filter(x -> x.getRolledBackTimestamp() == null
|
1670 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 1738 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
1671 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
| 1739 |
.collect(Collectors.toList());
|
1672 |
float amountToRollback = 0;
|
| 1740 |
Collections.reverse(sios);
|
1673 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 1741 |
for (SchemeInOut sio : sios) {
|
1674 |
orderItems.forEach(x -> {
|
| 1742 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
1675 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
| 1743 |
schemesConsidered.add(sio.getSchemeId());
|
1676 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
| 1744 |
continue;
|
1677 |
});
|
| 1745 |
}
|
1678 |
if (inventorySerialNumberMap.size() > 0) {
|
| 1746 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
1679 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
| 1747 |
amountToRollback += sio.getAmount();
|
1680 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
| 1748 |
// sio.setSchemeType(SchemeType.OUT);
|
1681 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
| 1749 |
sio.setReference(fofoOrder.getId());
|
1682 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
| 1750 |
sio.setSerialNumber(serialNumber);
|
1683 |
// This will rollback scheme for differenct orders for same serial
|
| 1751 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
1684 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 1752 |
rolledbackSios.add(sio);
|
1685 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 1753 |
}
|
1686 |
.filter(x -> x.getRolledBackTimestamp() == null
|
| 1754 |
}
|
1687 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 1755 |
|
1688 |
.collect(Collectors.toList());
|
| 1756 |
}
|
1689 |
Collections.reverse(sios);
|
| 1757 |
}
|
1690 |
for (SchemeInOut sio : sios) {
|
| 1758 |
if (amountToRollback > 0) {
|
1691 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 1759 |
UserWalletHistory uwh = new UserWalletHistory();
|
1692 |
amountToRollback += sio.getAmount();
|
| 1760 |
uwh.setAmount(Math.round(amountToRollback));
|
1693 |
// sio.setSchemeType(SchemeType.OUT);
|
| 1761 |
uwh.setDescription(description);
|
1694 |
sio.setSerialNumber(serialNumber);
|
| 1762 |
uwh.setTimestamp(LocalDateTime.now());
|
1695 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 1763 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
1696 |
sio.setReference(fofoOrder.getId());
|
| 1764 |
uwh.setReference(fofoOrder.getId());
|
1697 |
rolledbackSios.add(sio);
|
| 1765 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
1698 |
}
|
| 1766 |
uwh.setFofoId(fofoOrder.getFofoId());
|
1699 |
description = description.concat(" " + serialNumber + " ");
|
| 1767 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
1700 |
} else {
|
| 1768 |
userWalletHistory.add(uwh);
|
1701 |
serialNumbersConsidered.add(serialNumber);
|
| 1769 |
}
|
1702 |
List<Integer> schemesConsidered = new ArrayList<>();
|
| 1770 |
});
|
1703 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 1771 |
|
1704 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 1772 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
1705 |
.filter(x -> x.getRolledBackTimestamp() == null
|
| 1773 |
Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
1706 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 1774 |
"Timestamp"),
|
1707 |
.collect(Collectors.toList());
|
| 1775 |
userWalletHistory.stream()
|
1708 |
Collections.reverse(sios);
|
| 1776 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
1709 |
for (SchemeInOut sio : sios) {
|
| 1777 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
1710 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
| 1778 |
.collect(Collectors.toList()));
|
1711 |
schemesConsidered.add(sio.getSchemeId());
|
| 1779 |
|
1712 |
continue;
|
| 1780 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
1713 |
}
|
| 1781 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
1714 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 1782 |
"Rolledback"),
|
1715 |
amountToRollback += sio.getAmount();
|
| 1783 |
rolledbackSios.stream()
|
1716 |
// sio.setSchemeType(SchemeType.OUT);
|
| 1784 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
1717 |
sio.setReference(fofoOrder.getId());
|
| 1785 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
1718 |
sio.setSerialNumber(serialNumber);
|
| 1786 |
.collect(Collectors.toList()));
|
1719 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 1787 |
|
1720 |
rolledbackSios.add(sio);
|
| 1788 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
1721 |
}
|
| 1789 |
"Partner Excess Amount Scheme Out", "PFA",
|
1722 |
}
|
| 1790 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
1723 |
|
| 1791 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
1724 |
}
|
| 1792 |
|
1725 |
}
|
| 1793 |
throw new Exception();
|
1726 |
if (amountToRollback > 0) {
|
| 1794 |
}
|
1727 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 1795 |
|
1728 |
uwh.setAmount(Math.round(amountToRollback));
|
| 1796 |
public void dryRunSchemeOutReco1() throws Exception {
|
1729 |
uwh.setDescription(description);
|
| 1797 |
List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
|
1730 |
uwh.setTimestamp(LocalDateTime.now());
|
| 1798 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
1731 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
| 1799 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
1732 |
uwh.setReference(fofoOrder.getId());
|
| 1800 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
1733 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
| 1801 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
1734 |
uwh.setFofoId(fofoOrder.getFofoId());
|
| 1802 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
1735 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 1803 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
1736 |
userWalletHistory.add(uwh);
|
| 1804 |
references.stream().forEach(reference -> {
|
1737 |
}
|
| 1805 |
FofoOrder fofoOrder = null;
|
1738 |
});
|
| 1806 |
try {
|
1739 |
|
| 1807 |
fofoOrder = fofoOrderRepository.selectByOrderId(reference);
|
1740 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 1808 |
} catch (Exception e) {
|
1741 |
Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
| 1809 |
|
1742 |
"Timestamp"),
|
| 1810 |
}
|
1743 |
userWalletHistory.stream()
|
| 1811 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
1744 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
| 1812 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
1745 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 1813 |
float amountToRollback = 0;
|
1746 |
.collect(Collectors.toList()));
|
| 1814 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
1747 |
|
| 1815 |
orderItems.forEach(x -> {
|
1748 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 1816 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
1749 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
| 1817 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
1750 |
"Rolledback"),
|
| 1818 |
});
|
1751 |
rolledbackSios.stream()
|
| 1819 |
if (inventorySerialNumberMap.size() > 0) {
|
1752 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
| 1820 |
List<SchemeInOut> sios = schemeInOutRepository
|
1753 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
| 1821 |
.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
|
1754 |
.collect(Collectors.toList()));
|
| 1822 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
1755 |
|
| 1823 |
.collect(Collectors.toList());
|
1756 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{"amit.gupta@shop2020.in"}, null,
|
| 1824 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
1757 |
"Partner Excess Amount Scheme Out", "PFA",
|
| 1825 |
UserWalletHistory uwh = new UserWalletHistory();
|
1758 |
new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
| 1826 |
Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
|
1759 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
|
| 1827 |
.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
|
1760 |
|
| 1828 |
for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
|
1761 |
throw new Exception();
|
| 1829 |
List<SchemeInOut> outList = inventorySioEntry.getValue();
|
1762 |
}
|
| 1830 |
if (outList.size() > 1) {
|
1763 |
|
| 1831 |
|
1764 |
public void dryRunSchemeOutReco1() throws Exception {
|
| 1832 |
}
|
1765 |
List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
|
| 1833 |
}
|
1766 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
| 1834 |
uwh.setAmount(Math.round(amountToRollback));
|
1767 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 1835 |
uwh.setDescription(description);
|
1768 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
| 1836 |
uwh.setTimestamp(LocalDateTime.now());
|
1769 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 1837 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
1770 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
| 1838 |
uwh.setReference(fofoOrder.getId());
|
1771 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 1839 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
1772 |
references.stream().forEach(reference -> {
|
| 1840 |
uwh.setFofoId(fofoOrder.getFofoId());
|
1773 |
FofoOrder fofoOrder = null;
|
| 1841 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
1774 |
try {
|
| 1842 |
userWalletHistory.add(uwh);
|
1775 |
fofoOrder = fofoOrderRepository.selectByOrderId(reference);
|
| 1843 |
}
|
1776 |
} catch (Exception e) {
|
| 1844 |
});
|
1777 |
|
| 1845 |
|
1778 |
}
|
| 1846 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
1779 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 1847 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
1780 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
| 1848 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
1781 |
float amountToRollback = 0;
|
| 1849 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
1782 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 1850 |
.collect(Collectors.toList()));
|
1783 |
orderItems.forEach(x -> {
|
| 1851 |
|
1784 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
| 1852 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
1785 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
| 1853 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
1786 |
});
|
| 1854 |
"Rolledback"),
|
1787 |
if (inventorySerialNumberMap.size() > 0) {
|
| 1855 |
rolledbackSios.stream()
|
1788 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 1856 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
1789 |
.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
|
| 1857 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
1790 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 1858 |
.collect(Collectors.toList()));
|
1791 |
.collect(Collectors.toList());
|
| 1859 |
|
1792 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
| 1860 |
Utils.sendMailWithAttachments(googleMailSender,
|
1793 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 1861 |
new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
|
1794 |
Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
|
| 1862 |
"Partner Excess Amount", "PFA",
|
1795 |
.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
|
| 1863 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
1796 |
for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
|
| 1864 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
1797 |
List<SchemeInOut> outList = inventorySioEntry.getValue();
|
| 1865 |
|
1798 |
if (outList.size() > 1) {
|
| 1866 |
throw new Exception();
|
1799 |
|
| 1867 |
|
1800 |
}
|
| 1868 |
}
|
1801 |
}
|
| 1869 |
|
1802 |
uwh.setAmount(Math.round(amountToRollback));
|
| 1870 |
public void sendDailySalesNotificationToPartner(Integer fofoIdInt) throws Exception {
|
1803 |
uwh.setDescription(description);
|
| 1871 |
|
1804 |
uwh.setTimestamp(LocalDateTime.now());
|
| 1872 |
LocalDateTime now = LocalDateTime.now();
|
1805 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
| 1873 |
LocalDateTime from = now.with(LocalTime.MIN);
|
1806 |
uwh.setReference(fofoOrder.getId());
|
| 1874 |
String timeString = "Today %s";
|
1807 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
| 1875 |
// Send yesterday's report
|
1808 |
uwh.setFofoId(fofoOrder.getFofoId());
|
| 1876 |
/*
|
1809 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 1877 |
* if (now.getHour() < 13) { timeString = "Yesterday %s"; from =
|
1810 |
userWalletHistory.add(uwh);
|
| 1878 |
* now.minusDays(1).; now = from.with(LocalTime.MAX);
|
1811 |
}
|
| 1879 |
*
|
1812 |
});
|
| 1880 |
* }
|
1813 |
|
| 1881 |
*/
|
1814 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 1882 |
List<Integer> fofoIds = null;
|
1815 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
| 1883 |
if (fofoIdInt == null) {
|
1816 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
| 1884 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
1817 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 1885 |
.collect(Collectors.toList());
|
1818 |
.collect(Collectors.toList()));
|
| 1886 |
} else {
|
1819 |
|
| 1887 |
fofoIds = Arrays.asList(fofoIdInt);
|
1820 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 1888 |
}
|
1821 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
| 1889 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
1822 |
"Rolledback"),
|
| 1890 |
|
1823 |
rolledbackSios.stream()
|
| 1891 |
Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
|
1824 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
| 1892 |
null);
|
1825 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
| 1893 |
Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
|
1826 |
.collect(Collectors.toList()));
|
| 1894 |
|
1827 |
|
| 1895 |
Map<Integer, Double> spPartnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
1828 |
Utils.sendMailWithAttachments(googleMailSender,
|
| 1896 |
true);
|
1829 |
new String[]{"amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com"}, null,
|
| 1897 |
|
1830 |
"Partner Excess Amount", "PFA",
|
| 1898 |
Map<Integer, Double> spPartner3DaysOrderValMap = fofoOrderItemRepository
|
1831 |
new Attachment[]{new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
| 1899 |
.selectSumAmountGroupByRetailer(from.minusDays(3), now, 0, true);
|
1832 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray()))});
|
| 1900 |
Map<Integer, Long> spPartnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
|
1833 |
|
| 1901 |
|
1834 |
throw new Exception();
|
| 1902 |
Map<Integer, Double> partnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
1835 |
|
| 1903 |
false);
|
1836 |
}
|
| 1904 |
Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, false);
|
1837 |
|
| 1905 |
|
1838 |
public void sendDailySalesNotificationToPartner(Integer fofoIdInt) throws Exception {
|
| 1906 |
Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
|
1839 |
|
| 1907 |
for (int fofoId : fofoIds) {
|
1840 |
LocalDateTime now = LocalDateTime.now();
|
| 1908 |
SaleTargetReportModel model = new SaleTargetReportModel();
|
1841 |
LocalDateTime from = now.with(LocalTime.MIN);
|
| 1909 |
model.setInsuranceSale(
|
1842 |
String timeString = "Today %s";
|
| 1910 |
partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
|
1843 |
// Send yesterday's report
|
| 1911 |
model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
|
1844 |
/*
|
| 1912 |
model.setSmartphoneSale(spPartnerOrderValMap.containsKey(fofoId) ? spPartnerOrderValMap.get(fofoId) : 0);
|
1845 |
* if (now.getHour() < 13) { timeString = "Yesterday %s"; from =
|
| 1913 |
model.setSmartphoneQty(spPartnerOrderQtyMap.containsKey(fofoId) ? spPartnerOrderQtyMap.get(fofoId) : 0);
|
1846 |
* now.minusDays(1).; now = from.with(LocalTime.MAX);
|
| 1914 |
model.setTotalSale(partnerOrderValMap.containsKey(fofoId) ? partnerOrderValMap.get(fofoId) : 0);
|
1847 |
*
|
| 1915 |
model.setTotalQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
|
1848 |
* }
|
| 1916 |
model.setPast3daysSale(
|
1849 |
*/
|
| 1917 |
spPartner3DaysOrderValMap.containsKey(fofoId) ? spPartner3DaysOrderValMap.get(fofoId) : 0);
|
1850 |
|
| 1918 |
model.setFofoId(fofoId);
|
1851 |
List<Integer> fofoIds = null;
|
| 1919 |
saleTargetReportModelMap.put(fofoId, model);
|
1852 |
Map<Integer, FofoStore> fofoStoreMap = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
|
| 1920 |
}
|
1853 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 1921 |
|
1854 |
|
| 1922 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
1855 |
|
| 1923 |
for (Integer fofoId : fofoIds) {
|
1856 |
if (fofoIdInt == null) {
|
| 1924 |
SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
|
1857 |
fofoIds = new ArrayList<>(fofoStoreMap.keySet());
|
| 1925 |
|
1858 |
} else {
|
| 1926 |
// com.spice.profitmandi.dao.entity.user.User user =
|
1859 |
fofoIds = Arrays.asList(fofoIdInt);
|
| 1927 |
// userUserRepository.selectById(fofoId);
|
1860 |
}
|
| 1928 |
|
1861 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
| 1929 |
// Address address = addressRepository.selectById(user.getAddressId());
|
1862 |
|
| 1930 |
|
1863 |
Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
|
| 1931 |
String title = "Sale Update";
|
1864 |
null);
|
| 1932 |
String messageTemplate = String.format("Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
1865 |
Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
|
| 1933 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
1866 |
|
| 1934 |
String.format(timeString, now.format(timeFormatter)));
|
1867 |
Map<Integer, Double> spPartnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
| 1935 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
1868 |
true);
|
| 1936 |
sendNotificationModel.setCampaignName("Sales update alert");
|
1869 |
|
| 1937 |
sendNotificationModel.setTitle(title);
|
1870 |
Map<Integer, Double> spPartner3DaysOrderValMap = fofoOrderItemRepository
|
| 1938 |
sendNotificationModel.setMessage(messageTemplate);
|
1871 |
.selectSumAmountGroupByRetailer(from.minusDays(3), now, 0, true);
|
| 1939 |
sendNotificationModel.setType("url");
|
1872 |
Map<Integer, Long> spPartnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
|
| 1940 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
1873 |
|
| 1941 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
1874 |
Map<Integer, Double> partnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
|
| 1942 |
sendNotificationModel.setMessageType(MessageType.notification);
|
1875 |
false);
|
| 1943 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
1876 |
Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, false);
|
| 1944 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
1877 |
|
| 1945 |
notificationService.sendNotification(sendNotificationModel);
|
1878 |
//4 days + current day running
|
| 1946 |
String whatsappMessageTemplate = String.format(
|
1879 |
Map<Integer, Double> partnerBilledValueMap = orderRepository.selectBillingDatesBetweenSumGroupByRetailerId(from.minusDays(4), now);
|
| 1947 |
"Dear Partner, Your sale update is Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
1880 |
|
| 1948 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
1881 |
Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
|
| 1949 |
String.format(timeString, now.format(timeFormatter)));
|
1882 |
for (int fofoId : fofoIds) {
|
| 1950 |
// notificationService.sendWhatsappMessage(whatsappMessageTemplate, title,
|
1883 |
SaleTargetReportModel model = new SaleTargetReportModel();
|
| 1951 |
// address.getPhoneNumber());
|
1884 |
model.setInsuranceSale(
|
| 1952 |
|
1885 |
partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
|
| 1953 |
}
|
1886 |
model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
|
| 1954 |
// String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap,
|
1887 |
model.setSecondary(partnerBilledValueMap.containsKey(fofoId) ? partnerBilledValueMap.get(fofoId) : 0);
|
| 1955 |
// saleTargetReportModelMap);
|
1888 |
model.setSmartphoneSale(spPartnerOrderValMap.containsKey(fofoId) ? spPartnerOrderValMap.get(fofoId) : 0);
|
| 1956 |
this.getStateWiseSales(saleTargetReportModelMap, partnerSalesHeadersMap);
|
1889 |
model.setSmartphoneQty(spPartnerOrderQtyMap.containsKey(fofoId) ? spPartnerOrderQtyMap.get(fofoId) : 0);
|
| 1957 |
/*
|
1890 |
model.setTotalSale(partnerOrderValMap.containsKey(fofoId) ? partnerOrderValMap.get(fofoId) : 0);
|
| 1958 |
* String cc[] = { "tarun.verma@smartdukaan.com",
|
1891 |
model.setTotalQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
|
| 1959 |
* "kamini.sharma@smartdukaan.com", "niranjan.kala@smartdukaan.com",
|
1892 |
model.setPast3daysSale(
|
| 1960 |
* "sm@smartdukaan.com" };
|
1893 |
spPartner3DaysOrderValMap.containsKey(fofoId) ? spPartner3DaysOrderValMap.get(fofoId) : 0);
|
| 1961 |
*
|
1894 |
model.setFofoId(fofoId);
|
| 1962 |
* String subject = String.format("Sale till %s", String.format(timeString,
|
1895 |
model.setCode(fofoStoreMap.get(fofoId).getCode());
|
| 1963 |
* now.format(timeFormatter))); //
|
1896 |
saleTargetReportModelMap.put(fofoId, model);
|
| 1964 |
* this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc, //
|
1897 |
}
|
| 1965 |
* subject); this.sendMailOfHtmlFormat("amit.gupta@smartdukaan.com",
|
1898 |
|
| 1966 |
* statewiseSaleReport, cc, "Statewise" + subject);
|
1899 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 1967 |
*/
|
1900 |
for (Integer fofoId : fofoIds) {
|
| 1968 |
}
|
1901 |
SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
|
| 1969 |
|
1902 |
|
| 1970 |
public void checkRazorPayPaymentStatus() throws Exception {
|
1903 |
// com.spice.profitmandi.dao.entity.user.User user =
|
| 1971 |
List<PendingOrder> pendingOrder = pendingOrderRepository
|
1904 |
// userUserRepository.selectById(fofoId);
|
| 1972 |
.selectAllByStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PENDING);
|
1905 |
|
| 1973 |
|
1906 |
// Address address = addressRepository.selectById(user.getAddressId());
|
| 1974 |
for (PendingOrder po : pendingOrder) {
|
1907 |
|
| 1975 |
RazorPay razorPay = razorPayRepository.selectByOrdeId(po.getId());
|
1908 |
String title = "Sale Update";
|
| 1976 |
List<PendingOrderItem> poItems = pendingOrderItemRepository.selectByOrderId(po.getId());
|
1909 |
String messageTemplate = String.format("Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
| 1977 |
|
1910 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
| 1978 |
LOGGER.info("razorPay" + razorPay);
|
1911 |
String.format(timeString, now.format(timeFormatter)));
|
| 1979 |
if (razorPay != null) {
|
1912 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 1980 |
List<Payment> payments = razorPaymentService.fetchOrderForPayment(razorPay.getRazorOrderId());
|
1913 |
sendNotificationModel.setCampaignName("Sales update alert");
|
| 1981 |
|
1914 |
sendNotificationModel.setTitle(title);
|
| 1982 |
if (!payments.isEmpty()) {
|
1915 |
sendNotificationModel.setMessage(messageTemplate);
|
| 1983 |
List<String> statusList = new ArrayList<>();
|
1916 |
sendNotificationModel.setType("url");
|
| 1984 |
for (Payment payment : payments) {
|
1917 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 1985 |
|
1918 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| 1986 |
JSONObject jsonObj = new JSONObject(payment.toString());
|
1919 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 1987 |
|
1920 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| 1988 |
String status = jsonObj.getString("status");
|
1921 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 1989 |
|
1922 |
notificationService.sendNotification(sendNotificationModel);
|
| 1990 |
statusList.add(status);
|
1923 |
String whatsappMessageTemplate = String.format(
|
| 1991 |
|
1924 |
"Dear Partner, Your sale update is Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
| 1992 |
}
|
1925 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
| 1993 |
LOGGER.info("statusList" + statusList);
|
1926 |
String.format(timeString, now.format(timeFormatter)));
|
| 1994 |
|
1927 |
// notificationService.sendWhatsappMessage(whatsappMessageTemplate, title,
|
| 1995 |
if (statusList.contains("authorized") || statusList.contains("captured")) {
|
1928 |
// address.getPhoneNumber());
|
| 1996 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
1929 |
|
| 1997 |
po.setPaidAmount(po.getTotalAmount());
|
1930 |
}
|
| 1998 |
for (PendingOrderItem poi : poItems) {
|
1931 |
// String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap,
|
| 1999 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
1932 |
// saleTargetReportModelMap);
|
| 2000 |
}
|
1933 |
this.getStateWiseSales(saleTargetReportModelMap, partnerSalesHeadersMap);
|
| 2001 |
Map<String, Object> emailModel = pendingOrderService.sendCreateOrderMail(po);
|
1934 |
}
|
| 2002 |
|
1935 |
|
| 2003 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(po.getFofoId());
|
1936 |
public void checkRazorPayPaymentStatus() throws Exception {
|
| 2004 |
Customer customer = customerRepository.selectById(po.getCustomerId());
|
1937 |
List<PendingOrder> pendingOrder = pendingOrderRepository
|
| 2005 |
String[] customerEmail = null;
|
1938 |
.selectAllByStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PENDING);
|
| 2006 |
if (customer.getEmailId() != null) {
|
1939 |
|
| 2007 |
customerEmail = new String[] { customer.getEmailId() };
|
1940 |
for (PendingOrder po : pendingOrder) {
|
| 2008 |
}
|
1941 |
RazorPay razorPay = razorPayRepository.selectByOrdeId(po.getId());
|
| 2009 |
List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com",
|
1942 |
List<PendingOrderItem> poItems = pendingOrderItemRepository.selectByOrderId(po.getId());
|
| 2010 |
"tarun.verma@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
|
1943 |
|
| 2011 |
"tejbeer.kaur@shop2020.in", customRetailer.getEmail());
|
1944 |
LOGGER.info("razorPay" + razorPay);
|
| 2012 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
1945 |
if (razorPay != null) {
|
| 2013 |
if (authUserEmails != null) {
|
1946 |
List<Payment> payments = razorPaymentService.fetchOrderForPayment(razorPay.getRazorOrderId());
|
| 2014 |
authUserEmails = new ArrayList<>();
|
1947 |
|
| 2015 |
}
|
1948 |
if (!payments.isEmpty()) {
|
| 2016 |
authUserEmails.addAll(bccTo);
|
1949 |
List<String> statusList = new ArrayList<>();
|
| 2017 |
|
1950 |
for (Payment payment : payments) {
|
| 2018 |
// emailService.sendMailWithAttachments("Order Created with SmartDukaan",
|
1951 |
|
| 2019 |
// "order-confirm.vm",
|
1952 |
JSONObject jsonObj = new JSONObject(payment.toString());
|
| 2020 |
// emailModel, customerEmail, null, authUserEmails.toArray(new String[0]));
|
1953 |
|
| 2021 |
|
1954 |
String status = jsonObj.getString("status");
|
| 2022 |
} else if (statusList.contains("refunded") || statusList.contains("failed")) {
|
1955 |
|
| 2023 |
for (PendingOrderItem poi : poItems) {
|
1956 |
statusList.add(status);
|
| 2024 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
1957 |
|
| 2025 |
}
|
1958 |
}
|
| 2026 |
|
1959 |
LOGGER.info("statusList" + statusList);
|
| 2027 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
1960 |
|
| 2028 |
}
|
1961 |
if (statusList.contains("authorized") || statusList.contains("captured")) {
|
| 2029 |
|
1962 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
| 2030 |
}
|
1963 |
po.setPaidAmount(po.getTotalAmount());
|
| 2031 |
// LOGGER.info("payment" + payments);
|
1964 |
for (PendingOrderItem poi : poItems) {
|
| 2032 |
|
1965 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.PROCESSING);
|
| 2033 |
}
|
1966 |
}
|
| 2034 |
}
|
1967 |
Map<String, Object> emailModel = pendingOrderService.sendCreateOrderMail(po);
|
| 2035 |
}
|
1968 |
|
| 2036 |
|
1969 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(po.getFofoId());
|
| 2037 |
public static class SaleTargetReportModel {
|
1970 |
Customer customer = customerRepository.selectById(po.getCustomerId());
|
| 2038 |
private double totalSale;
|
1971 |
String[] customerEmail = null;
|
| 2039 |
private long totalQty;
|
1972 |
if (customer.getEmailId() != null) {
|
| 2040 |
private double past3daysSale;
|
1973 |
customerEmail = new String[]{customer.getEmailId()};
|
| 2041 |
private int fofoId;
|
1974 |
}
|
| 2042 |
|
1975 |
List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com",
|
| 2043 |
public int getFofoId() {
|
1976 |
"tarun.verma@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
|
| 2044 |
return fofoId;
|
1977 |
"tejbeer.kaur@shop2020.in", customRetailer.getEmail());
|
| 2045 |
}
|
1978 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
| 2046 |
|
1979 |
if (authUserEmails != null) {
|
| 2047 |
public void setFofoId(int fofoId) {
|
1980 |
authUserEmails = new ArrayList<>();
|
| 2048 |
this.fofoId = fofoId;
|
1981 |
}
|
| 2049 |
}
|
1982 |
authUserEmails.addAll(bccTo);
|
| 2050 |
|
1983 |
|
| 2051 |
private double smartphoneSale;
|
1984 |
// emailService.sendMailWithAttachments("Order Created with SmartDukaan",
|
| 2052 |
private long smartphoneQty;
|
1985 |
// "order-confirm.vm",
|
| 2053 |
private double insuranceSale;
|
1986 |
// emailModel, customerEmail, null, authUserEmails.toArray(new String[0]));
|
| 2054 |
private long insruanceQty;
|
1987 |
|
| 2055 |
|
1988 |
} else if (statusList.contains("refunded") || statusList.contains("failed")) {
|
| 2056 |
public long getTotalQty() {
|
1989 |
for (PendingOrderItem poi : poItems) {
|
| 2057 |
return totalQty;
|
1990 |
poi.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
| 2058 |
}
|
1991 |
}
|
| 2059 |
|
1992 |
|
| 2060 |
public void setTotalQty(long totalQty) {
|
1993 |
po.setStatus(com.spice.profitmandi.dao.enumuration.transaction.OrderStatus.FAILED);
|
| 2061 |
this.totalQty = totalQty;
|
1994 |
}
|
| 2062 |
}
|
1995 |
|
| 2063 |
|
1996 |
}
|
| 2064 |
public double getPast3daysSale() {
|
1997 |
// LOGGER.info("payment" + payments);
|
| 2065 |
return past3daysSale;
|
1998 |
|
| 2066 |
}
|
1999 |
}
|
| 2067 |
|
2000 |
}
|
| 2068 |
public void setPast3daysSale(double past3daysSale) {
|
2001 |
}
|
| 2069 |
this.past3daysSale = past3daysSale;
|
2002 |
|
| 2070 |
}
|
2003 |
public static class SaleTargetReportModel {
|
| 2071 |
|
2004 |
private double totalSale;
|
| 2072 |
@Override
|
2005 |
private long totalQty;
|
| 2073 |
public int hashCode() {
|
2006 |
private double past3daysSale;
|
| 2074 |
final int prime = 31;
|
2007 |
private int fofoId;
|
| 2075 |
int result = 1;
|
2008 |
private String code;
|
| 2076 |
result = prime * result + fofoId;
|
2009 |
|
| 2077 |
result = prime * result + (int) (insruanceQty ^ (insruanceQty >>> 32));
|
2010 |
public double getSecondary() {
|
| 2078 |
long temp;
|
2011 |
return secondary;
|
| 2079 |
temp = Double.doubleToLongBits(insuranceSale);
|
2012 |
}
|
| 2080 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
2013 |
|
| 2081 |
result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
|
2014 |
public void setSecondary(double secondary) {
|
| 2082 |
temp = Double.doubleToLongBits(smartphoneSale);
|
2015 |
this.secondary = secondary;
|
| 2083 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
2016 |
}
|
| 2084 |
result = prime * result + (int) (totalQty ^ (totalQty >>> 32));
|
2017 |
|
| 2085 |
temp = Double.doubleToLongBits(totalSale);
|
2018 |
private double secondary;
|
| 2086 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
2019 |
|
| 2087 |
return result;
|
2020 |
public int getFofoId() {
|
| 2088 |
}
|
2021 |
return fofoId;
|
| 2089 |
|
2022 |
}
|
| 2090 |
@Override
|
2023 |
|
| 2091 |
public boolean equals(Object obj) {
|
2024 |
@Override
|
| 2092 |
if (this == obj)
|
2025 |
public String toString() {
|
| 2093 |
return true;
|
2026 |
return "SaleTargetReportModel{" +
|
| 2094 |
if (obj == null)
|
2027 |
"totalSale=" + totalSale +
|
| 2095 |
return false;
|
2028 |
", totalQty=" + totalQty +
|
| 2096 |
if (getClass() != obj.getClass())
|
2029 |
", past3daysSale=" + past3daysSale +
|
| 2097 |
return false;
|
2030 |
", fofoId=" + fofoId +
|
| 2098 |
SaleTargetReportModel other = (SaleTargetReportModel) obj;
|
2031 |
", code='" + code + '\'' +
|
| 2099 |
if (fofoId != other.fofoId)
|
2032 |
", secondary=" + secondary +
|
| 2100 |
return false;
|
2033 |
", smartphoneSale=" + smartphoneSale +
|
| 2101 |
if (insruanceQty != other.insruanceQty)
|
2034 |
", smartphoneQty=" + smartphoneQty +
|
| 2102 |
return false;
|
2035 |
", insuranceSale=" + insuranceSale +
|
| 2103 |
if (Double.doubleToLongBits(insuranceSale) != Double.doubleToLongBits(other.insuranceSale))
|
2036 |
", insruanceQty=" + insruanceQty +
|
| 2104 |
return false;
|
2037 |
'}';
|
| 2105 |
if (smartphoneQty != other.smartphoneQty)
|
2038 |
}
|
| 2106 |
return false;
|
2039 |
|
| 2107 |
if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
|
2040 |
@Override
|
| 2108 |
return false;
|
2041 |
public boolean equals(Object o) {
|
| 2109 |
if (totalQty != other.totalQty)
|
2042 |
if (this == o) return true;
|
| 2110 |
return false;
|
2043 |
if (o == null || getClass() != o.getClass()) return false;
|
| 2111 |
if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
|
2044 |
SaleTargetReportModel that = (SaleTargetReportModel) o;
|
| 2112 |
return false;
|
2045 |
return Double.compare(that.totalSale, totalSale) == 0 && totalQty == that.totalQty && Double.compare(that.past3daysSale, past3daysSale) == 0 && fofoId == that.fofoId && Double.compare(that.secondary, secondary) == 0 && Double.compare(that.smartphoneSale, smartphoneSale) == 0 && smartphoneQty == that.smartphoneQty && Double.compare(that.insuranceSale, insuranceSale) == 0 && insruanceQty == that.insruanceQty && Objects.equals(code, that.code);
|
| 2113 |
return true;
|
2046 |
}
|
| 2114 |
}
|
2047 |
|
| 2115 |
|
2048 |
@Override
|
| 2116 |
public double getTotalSale() {
|
2049 |
public int hashCode() {
|
| 2117 |
return totalSale;
|
2050 |
return Objects.hash(totalSale, totalQty, past3daysSale, fofoId, code, secondary, smartphoneSale, smartphoneQty, insuranceSale, insruanceQty);
|
| 2118 |
}
|
2051 |
}
|
| 2119 |
|
2052 |
|
| 2120 |
public void setTotalSale(double totalSale) {
|
2053 |
public String getCode() {
|
| 2121 |
this.totalSale = totalSale;
|
2054 |
return code;
|
| 2122 |
}
|
2055 |
}
|
| 2123 |
|
2056 |
|
| 2124 |
public double getSmartphoneSale() {
|
2057 |
public void setCode(String code) {
|
| 2125 |
return smartphoneSale;
|
2058 |
this.code = code;
|
| 2126 |
}
|
2059 |
}
|
| 2127 |
|
2060 |
|
| 2128 |
public void setSmartphoneSale(double smartphoneSale) {
|
2061 |
public void setFofoId(int fofoId) {
|
| 2129 |
this.smartphoneSale = smartphoneSale;
|
2062 |
this.fofoId = fofoId;
|
| 2130 |
}
|
2063 |
}
|
| 2131 |
|
2064 |
|
| 2132 |
public long getSmartphoneQty() {
|
2065 |
private double smartphoneSale;
|
| 2133 |
return smartphoneQty;
|
2066 |
private long smartphoneQty;
|
| 2134 |
}
|
2067 |
private double insuranceSale;
|
| 2135 |
|
2068 |
private long insruanceQty;
|
| 2136 |
public void setSmartphoneQty(long smartphoneQty) {
|
2069 |
|
| 2137 |
this.smartphoneQty = smartphoneQty;
|
2070 |
public long getTotalQty() {
|
| 2138 |
}
|
2071 |
return totalQty;
|
| 2139 |
|
2072 |
}
|
| 2140 |
public double getInsuranceSale() {
|
2073 |
|
| 2141 |
return insuranceSale;
|
2074 |
public void setTotalQty(long totalQty) {
|
| 2142 |
}
|
2075 |
this.totalQty = totalQty;
|
| 2143 |
|
2076 |
}
|
| 2144 |
public void setInsuranceSale(double insuranceSale) {
|
2077 |
|
| 2145 |
this.insuranceSale = insuranceSale;
|
2078 |
public double getPast3daysSale() {
|
| 2146 |
}
|
2079 |
return past3daysSale;
|
| 2147 |
|
2080 |
}
|
| 2148 |
public long getInsruanceQty() {
|
2081 |
|
| 2149 |
return insruanceQty;
|
2082 |
public void setPast3daysSale(double past3daysSale) {
|
| 2150 |
}
|
2083 |
this.past3daysSale = past3daysSale;
|
| 2151 |
|
2084 |
}
|
| 2152 |
public void setInsruanceQty(long insruanceQty) {
|
2085 |
|
| 2153 |
this.insruanceQty = insruanceQty;
|
2086 |
public double getTotalSale() {
|
| 2154 |
}
|
2087 |
return totalSale;
|
| 2155 |
|
2088 |
}
|
| 2156 |
@Override
|
2089 |
|
| 2157 |
public String toString() {
|
2090 |
public void setTotalSale(double totalSale) {
|
| 2158 |
return "SaleTargetReportModel [totalSale=" + totalSale + ", totalQty=" + totalQty + ", past3daysSale="
|
2091 |
this.totalSale = totalSale;
|
| 2159 |
+ past3daysSale + ", fofoId=" + fofoId + ", smartphoneSale=" + smartphoneSale + ", smartphoneQty="
|
2092 |
}
|
| 2160 |
+ smartphoneQty + ", insuranceSale=" + insuranceSale + ", insruanceQty=" + insruanceQty + "]";
|
2093 |
|
| 2161 |
}
|
2094 |
public double getSmartphoneSale() {
|
| 2162 |
|
2095 |
return smartphoneSale;
|
| 2163 |
}
|
2096 |
}
|
| 2164 |
|
2097 |
|
| 2165 |
private void getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap,
|
2098 |
public void setSmartphoneSale(double smartphoneSale) {
|
| 2166 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap) throws Exception {
|
2099 |
this.smartphoneSale = smartphoneSale;
|
| 2167 |
String timeString = "Today %s";
|
2100 |
}
|
| 2168 |
LocalDateTime now = LocalDateTime.now();
|
2101 |
|
| 2169 |
|
2102 |
public long getSmartphoneQty() {
|
| 2170 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
2103 |
return smartphoneQty;
|
| 2171 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_LOGISTICS,
|
2104 |
}
|
| 2172 |
ProfitMandiConstants.TICKET_CATEGORY_FINANCIAL_SERVICES, ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
2105 |
|
| 2173 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
2106 |
public void setSmartphoneQty(long smartphoneQty) {
|
| 2174 |
ProfitMandiConstants.TICKET_CATEGORY_MARKETING, ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
2107 |
this.smartphoneQty = smartphoneQty;
|
| 2175 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT,
|
2108 |
}
|
| 2176 |
ProfitMandiConstants.TICKET_CATEGORY_TECHNOLOGY);
|
2109 |
|
| - |
|
2110 |
public double getInsuranceSale() {
|
| - |
|
2111 |
return insuranceSale;
|
| - |
|
2112 |
}
|
| - |
|
2113 |
|
| - |
|
2114 |
public void setInsuranceSale(double insuranceSale) {
|
| - |
|
2115 |
this.insuranceSale = insuranceSale;
|
| - |
|
2116 |
}
|
| - |
|
2117 |
|
| - |
|
2118 |
public long getInsruanceQty() {
|
| - |
|
2119 |
return insruanceQty;
|
| - |
|
2120 |
}
|
| - |
|
2121 |
|
| - |
|
2122 |
public void setInsruanceQty(long insruanceQty) {
|
| - |
|
2123 |
this.insruanceQty = insruanceQty;
|
| - |
|
2124 |
}
|
| - |
|
2125 |
|
| - |
|
2126 |
}
|
| - |
|
2127 |
|
| - |
|
2128 |
private void getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap,
|
| - |
|
2129 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap) throws Exception {
|
| - |
|
2130 |
String timeString = "Today %s";
|
| - |
|
2131 |
LocalDateTime now = LocalDateTime.now();
|
| - |
|
2132 |
|
| - |
|
2133 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
| - |
|
2134 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_LOGISTICS,
|
| - |
|
2135 |
ProfitMandiConstants.TICKET_CATEGORY_FINANCIAL_SERVICES, ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
| - |
|
2136 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
| - |
|
2137 |
ProfitMandiConstants.TICKET_CATEGORY_MARKETING, ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
| - |
|
2138 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT,
|
| - |
|
2139 |
ProfitMandiConstants.TICKET_CATEGORY_TECHNOLOGY);
|
| 2177 |
|
2140 |
|
| 2178 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false);
|
2141 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false);
|
| 2179 |
|
2142 |
|
| 2180 |
for (Entry<String, Set<Integer>> storeGuyEntry : storeGuyMap.entrySet()) {
|
2143 |
for (Entry<String, Set<Integer>> storeGuyEntry : storeGuyMap.entrySet()) {
|
| 2181 |
String email = storeGuyEntry.getKey();
|
2144 |
String email = storeGuyEntry.getKey();
|
| 2182 |
Set<Integer> fofoIds = storeGuyEntry.getValue();
|
2145 |
Set<Integer> fofoIds = storeGuyEntry.getValue();
|
| 2183 |
LOGGER.info("fofoIds {}", fofoIds);
|
2146 |
LOGGER.info("fofoIds {}", fofoIds);
|
| 2184 |
|
2147 |
|
| 2185 |
if (!fofoIds.isEmpty()) {
|
2148 |
if (!fofoIds.isEmpty()) {
|
| 2186 |
List<FofoStore> stores = fofoStoreRepository
|
2149 |
List<FofoStore> stores = fofoStoreRepository
|
| 2187 |
.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds));
|
2150 |
.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds));
|
| 2188 |
|
2151 |
|
| 2189 |
Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors.groupingBy(
|
2152 |
Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors.groupingBy(
|
| 2190 |
x -> x.getCode().substring(0, 2), Collectors.mapping(x -> x.getId(), Collectors.toList())));
|
2153 |
x -> x.getCode().substring(0, 2), Collectors.mapping(x -> x.getId(), Collectors.toList())));
|
| 2191 |
List<List<Serializable>> stateWiseSales = new ArrayList<>();
|
2154 |
List<List<Serializable>> stateWiseSales = new ArrayList<>();
|
| 2192 |
for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
|
2155 |
for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
|
| 2193 |
long totalQty = stateMapEntry.getValue().stream()
|
2156 |
long totalQty = stateMapEntry.getValue().stream()
|
| 2194 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getTotalQty()));
|
2157 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getTotalQty()));
|
| 2195 |
double totalSale = stateMapEntry.getValue().stream()
|
2158 |
double totalSale = stateMapEntry.getValue().stream()
|
| 2196 |
.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getTotalSale()));
|
2159 |
.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getTotalSale()));
|
| 2197 |
long smartPhoneQty = stateMapEntry.getValue().stream()
|
2160 |
long smartPhoneQty = stateMapEntry.getValue().stream()
|
| 2198 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getSmartphoneQty()));
|
2161 |
.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getSmartphoneQty()));
|
| 2199 |
double smartPhoneSale = stateMapEntry.getValue().stream().collect(
|
2162 |
double smartPhoneSale = stateMapEntry.getValue().stream().collect(
|
| 2200 |
Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getSmartphoneSale()));
|
2163 |
Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getSmartphoneSale()));
|
| 2201 |
stateWiseSales.add(
|
2164 |
stateWiseSales.add(
|
| 2202 |
Arrays.asList(stateMapEntry.getKey(), smartPhoneQty, smartPhoneSale, totalQty, totalSale));
|
2165 |
Arrays.asList(stateMapEntry.getKey(), smartPhoneQty, smartPhoneSale, totalQty, totalSale));
|
| 2203 |
}
|
2166 |
}
|
| 2204 |
StringBuilder sb = new StringBuilder();
|
2167 |
StringBuilder sb = new StringBuilder();
|
| 2205 |
sb.append("<html><body>");
|
2168 |
sb.append("<html><body>");
|
| 2206 |
sb.append("<p>Statewise Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
2169 |
sb.append("<p>Statewise Sale Report:</p><br/><table style=\"border-collapse: collapse;\">");
|
| 2207 |
sb.append("<tbody>\n" + " <tr>"
|
2170 |
sb.append("<tbody>\n" + " <tr>"
|
| 2208 |
+ " <th style='border:1px solid black;padding: 5px'>State</th>"
|
2171 |
+ " <th style='border:1px solid black;padding: 5px'>State</th>"
|
| 2209 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
2172 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
| 2210 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Value</th>"
|
2173 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Value</th>"
|
| 2211 |
+ " <th style='border:1px solid black;padding: 5px'>Total Qty</th>"
|
2174 |
+ " <th style='border:1px solid black;padding: 5px'>Total Qty</th>"
|
| 2212 |
+ " <th style='border:1px solid black;padding: 5px'>Total Value</th>"
|
2175 |
+ " <th style='border:1px solid black;padding: 5px'>Total Value</th>"
|
| 2213 |
+ " </tr>");
|
2176 |
+ " </tr>");
|
| 2214 |
for (List<Serializable> stateSale : stateWiseSales) {
|
2177 |
for (List<Serializable> stateSale : stateWiseSales) {
|
| 2215 |
sb.append("<tr>");
|
2178 |
sb.append("<tr>");
|
| 2216 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(0) + "</td>");
|
2179 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(0) + "</td>");
|
| 2217 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(1) + "</td>");
|
2180 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(1) + "</td>");
|
| 2218 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
|
2181 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
|
| 2219 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(3) + "</td>");
|
2182 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(3) + "</td>");
|
| 2220 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(4) + "</td>");
|
2183 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(4) + "</td>");
|
| 2221 |
sb.append("</tr>");
|
2184 |
sb.append("</tr>");
|
| 2222 |
}
|
2185 |
}
|
| 2223 |
sb.append("</tbody></table><br><br>");
|
2186 |
sb.append("</tbody></table><br><br>");
|
| 2224 |
|
2187 |
|
| 2225 |
sb.append("<p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
2188 |
sb.append("<p>Partnerwise Report:</p><br/><table style=\"border-collapse: collapse;\">");
|
| 2226 |
sb.append("<tbody>\n" + " <tr>\n"
|
2189 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 2227 |
+ " <th style='border:1px solid black;padding: 5px'>Code</th>"
|
2190 |
+ " <th style='border:1px solid black;padding: 5px'>Code</th>"
|
| 2228 |
+ " <th style='border:1px solid black;padding: 5px'>Business Name</th>"
|
2191 |
+ " <th style='border:1px solid black;padding: 5px'>Business Name</th>"
|
| 2229 |
+ " <th style='border:1px solid black;padding: 5px'>Regional Manager</th>"
|
2192 |
+ " <th style='border:1px solid black;padding: 5px'>BDM Name</th>"
|
| 2230 |
+ " <th style='border:1px solid black;padding: 5px'>Territory Manager</th>"
|
2193 |
+ " <th style='border:1px solid black;padding: 5px'>Regional Manager</th>"
|
| 2231 |
+ " <th style='border:1px solid black;padding: 5px'>Sale</th>"
|
2194 |
+ " <th style='border:1px solid black;padding: 5px'>Territory Manager</th>"
|
| 2232 |
+ " <th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>"
|
2195 |
+ " <th style='border:1px solid black;padding: 5px'>Billed(4 days)</th>"
|
| 2233 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
2196 |
+ " <th style='border:1px solid black;padding: 5px'>Sale</th>"
|
| 2234 |
+ " </tr>");
|
2197 |
+ " <th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>"
|
| 2235 |
|
2198 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
|
| 2236 |
/*
|
2199 |
+ " </tr>");
|
| 2237 |
* List<Integer> sortedPartnerSalesHeaders =
|
2200 |
|
| 2238 |
* partnerSalesHeadersMap.values().stream()
|
2201 |
|
| 2239 |
* .sorted(Comparator.comparing(FofoReportingModel::getCode)
|
2202 |
List<Integer> sortedSaleTargetReport = saleTargetReportModelMap.values().stream()
|
| 2240 |
* .thenComparing(FofoReportingModel::getRegionalManager)
|
2203 |
.filter(x -> fofoIds.contains(x.getFofoId()))
|
| 2241 |
* .thenComparing(FofoReportingModel::getTerritoryManager))
|
2204 |
.sorted(Comparator.comparing(SaleTargetReportModel::getCode).thenComparing(SaleTargetReportModel::getSecondary))
|
| 2242 |
* .map(FofoReportingModel::getFofoId).collect(Collectors.toList());
|
2205 |
.map(SaleTargetReportModel::getFofoId).collect(Collectors.toList());
|
| 2243 |
*/
|
2206 |
|
| 2244 |
|
2207 |
String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
|
| 2245 |
List<Integer> sortedSaleTargetReport = saleTargetReportModelMap.values().stream()
|
2208 |
|
| 2246 |
.filter(x -> fofoIds.contains(x.getFofoId()))
|
2209 |
List<String> headers = Arrays.asList("Store Id", "Store Code", "Store Name", "BDM Name", "Regional Manager", "Territory Manager",
|
| 2247 |
.sorted(Comparator.comparing(SaleTargetReportModel::getTotalSale))
|
2210 |
"Secondary(4 days)", "Sale", "Smartphone Value", "Smartphone Qty");
|
| 2248 |
.map(SaleTargetReportModel::getFofoId).collect(Collectors.toList());
|
2211 |
List<List<?>> rows = new ArrayList<>();
|
| 2249 |
for (Integer fofoId : sortedSaleTargetReport) {
|
2212 |
for (Integer fofoId : sortedSaleTargetReport) {
|
| 2250 |
if (saleTargetReportModelMap.get(fofoId).getPast3daysSale() == 0) {
|
2213 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 2251 |
sb.append("<tr style='background-color:red'>");
|
2214 |
FofoReportingModel fofoReportingModel = partnerSalesHeadersMap.get(fofoId);
|
| 2252 |
} else {
|
2215 |
rows.add(Arrays.asList(fofoId, fofoReportingModel.getCode(), fofoReportingModel.getBusinessName(),
|
| 2253 |
sb.append("<tr>");
|
2216 |
fofoReportingModel.getBusinessManager(), fofoReportingModel.getRegionalManager(), fofoReportingModel.getTerritoryManager(),
|
| 2254 |
}
|
2217 |
saleTargetReportModelMap.get(fofoId).getSecondary(), saleTargetReportModelMap.get(fofoId).getTotalSale(),
|
| 2255 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2218 |
saleTargetReportModelMap.get(fofoId).getSmartphoneSale(), saleTargetReportModelMap.get(fofoId).getSmartphoneQty()
|
| 2256 |
+ partnerSalesHeadersMap.get(fofoId).getCode() + "</td>");
|
2219 |
));
|
| 2257 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2220 |
|
| 2258 |
+ partnerSalesHeadersMap.get(fofoId).getBusinessName() + "</td>");
|
2221 |
|
| 2259 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2222 |
if (!fofoStore.getActivationType().equals(ActivationType.ACTIVE)) {
|
| 2260 |
+ partnerSalesHeadersMap.get(fofoId).getRegionalManager() + "</td>");
|
2223 |
continue;
|
| 2261 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2224 |
}
|
| 2262 |
+ partnerSalesHeadersMap.get(fofoId).getTerritoryManager() + "</td>");
|
2225 |
if (saleTargetReportModelMap.get(fofoId).getSecondary() == 0) {
|
| 2263 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2226 |
sb.append("<tr style='background-color:#D21F3C;color:white'>");
|
| 2264 |
+ saleTargetReportModelMap.get(fofoId).getTotalSale() + "</td>");
|
2227 |
} else {
|
| 2265 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2228 |
sb.append("<tr>");
|
| 2266 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneSale() + "</td>");
|
2229 |
}
|
| 2267 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2230 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2268 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneQty() + "</td>");
|
2231 |
+ partnerSalesHeadersMap.get(fofoId).getCode() + "</td>");
|
| 2269 |
sb.append("</tr>");
|
2232 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2270 |
}
|
2233 |
+ partnerSalesHeadersMap.get(fofoId).getBusinessName() + "</td>");
|
| 2271 |
|
2234 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2272 |
sb.append("</tr>");
|
2235 |
+ partnerSalesHeadersMap.get(fofoId).getBusinessManager() + "</td>");
|
| 2273 |
|
2236 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2274 |
sb.append("</body></html>");
|
2237 |
+ partnerSalesHeadersMap.get(fofoId).getRegionalManager() + "</td>");
|
| 2275 |
|
2238 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2276 |
String statewiseSaleReport = sb.toString();
|
2239 |
+ partnerSalesHeadersMap.get(fofoId).getTerritoryManager() + "</td>");
|
| 2277 |
|
2240 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2278 |
String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
|
2241 |
+ saleTargetReportModelMap.get(fofoId).getSecondary() + "</td>");
|
| 2279 |
// this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc,
|
2242 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2280 |
// subject);
|
2243 |
+ saleTargetReportModelMap.get(fofoId).getTotalSale() + "</td>");
|
| 2281 |
this.sendMailOfHtmlFormat(email, statewiseSaleReport, null, "Statewise" + subject);
|
2244 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2282 |
}
|
2245 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneSale() + "</td>");
|
| 2283 |
}
|
2246 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2284 |
}
|
2247 |
+ saleTargetReportModelMap.get(fofoId).getSmartphoneQty() + "</td>");
|
| 2285 |
|
2248 |
sb.append("</tr>");
|
| 2286 |
private void sendMailOfHtmlFormat(String email, String body, String cc[], String subject)
|
2249 |
|
| 2287 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
2250 |
|
| 2288 |
MimeMessage message = mailSender.createMimeMessage();
|
2251 |
}
|
| 2289 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
2252 |
sb.append("</tr>");
|
| 2290 |
helper.setSubject(subject);
|
2253 |
sb.append("</body></html>");
|
| 2291 |
helper.setText(body, true);
|
2254 |
String statewiseSaleReport = sb.toString();
|
| 2292 |
helper.setTo(email);
|
2255 |
|
| 2293 |
if (cc != null) {
|
2256 |
|
| 2294 |
helper.setCc(cc);
|
2257 |
ByteArrayOutputStream baos = null;
|
| 2295 |
}
|
2258 |
try {
|
| 2296 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
2259 |
baos = FileUtil.getCSVByteStream(headers, rows);
|
| 2297 |
helper.setFrom(senderAddress);
|
2260 |
} catch (Exception e2) {
|
| 2298 |
mailSender.send(message);
|
2261 |
e2.printStackTrace();
|
| 2299 |
}
|
2262 |
}
|
| 2300 |
|
2263 |
Attachment attachment = new Attachment("PartnerSalePerformance.csv", new ByteArrayResource(baos.toByteArray()));
|
| 2301 |
public void sendNotification() throws Exception {
|
2264 |
|
| 2302 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
2265 |
|
| 2303 |
if (!pushNotifications.isEmpty()) {
|
2266 |
Utils.sendHtmlMailWithAttachments(googleMailSender, new String[]{email}, null, "Statewise " + subject, statewiseSaleReport, attachment);
|
| 2304 |
for (PushNotifications pushNotification : pushNotifications) {
|
2267 |
return;
|
| 2305 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
2268 |
}
|
| 2306 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
2269 |
}
|
| 2307 |
.selectById(pushNotification.getNotificationCampaignid());
|
2270 |
}
|
| 2308 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
2271 |
|
| 2309 |
SimpleCampaignParams.class);
|
2272 |
private void sendMailOfHtmlFormat(String email, String body, String cc[], String subject)
|
| 2310 |
Campaign campaign = new SimpleCampaign(scp);
|
2273 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 2311 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
2274 |
MimeMessage message = mailSender.createMimeMessage();
|
| 2312 |
JSONObject json = new JSONObject();
|
2275 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
| 2313 |
json.put("to", device.getFcmId());
|
2276 |
helper.setSubject(subject);
|
| 2314 |
JSONObject jsonObj = new JSONObject();
|
2277 |
helper.setText(body, true);
|
| 2315 |
jsonObj.put("message", campaign.getMessage());
|
2278 |
helper.setTo(email);
|
| 2316 |
jsonObj.put("title", campaign.getTitle());
|
2279 |
if (cc != null) {
|
| 2317 |
jsonObj.put("type", campaign.getType());
|
2280 |
helper.setCc(cc);
|
| 2318 |
jsonObj.put("url", result_url);
|
2281 |
}
|
| 2319 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
2282 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 2320 |
jsonObj.put("image", campaign.getImageUrl());
|
2283 |
helper.setFrom(senderAddress);
|
| 2321 |
jsonObj.put("largeIcon", "large_icon");
|
2284 |
mailSender.send(message);
|
| 2322 |
jsonObj.put("smallIcon", "small_icon");
|
2285 |
}
|
| 2323 |
jsonObj.put("vibrate", 1);
|
2286 |
|
| 2324 |
jsonObj.put("pid", pushNotification.getId());
|
2287 |
public void sendNotification() throws Exception {
|
| 2325 |
jsonObj.put("sound", 1);
|
2288 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
| 2326 |
jsonObj.put("priority", "high");
|
2289 |
if (!pushNotifications.isEmpty()) {
|
| 2327 |
json.put("data", jsonObj);
|
2290 |
for (PushNotifications pushNotification : pushNotifications) {
|
| 2328 |
try {
|
2291 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
| 2329 |
CloseableHttpClient client = HttpClients.createDefault();
|
2292 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
| 2330 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
2293 |
.selectById(pushNotification.getNotificationCampaignid());
|
| 2331 |
|
2294 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
| 2332 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
2295 |
SimpleCampaignParams.class);
|
| 2333 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
2296 |
Campaign campaign = new SimpleCampaign(scp);
|
| 2334 |
StringEntity entity = new StringEntity(json.toString());
|
2297 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
| 2335 |
httpPost.setEntity(entity);
|
2298 |
JSONObject json = new JSONObject();
|
| 2336 |
CloseableHttpResponse response = client.execute(httpPost);
|
2299 |
json.put("to", device.getFcmId());
|
| 2337 |
|
2300 |
JSONObject jsonObj = new JSONObject();
|
| 2338 |
if (response.getStatusLine().getStatusCode() == 200) {
|
2301 |
jsonObj.put("message", campaign.getMessage());
|
| 2339 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
2302 |
jsonObj.put("title", campaign.getTitle());
|
| 2340 |
} else {
|
2303 |
jsonObj.put("type", campaign.getType());
|
| 2341 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
2304 |
jsonObj.put("url", result_url);
|
| 2342 |
LOGGER.info("message" + "not sent");
|
2305 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
| 2343 |
response.toString();
|
2306 |
jsonObj.put("image", campaign.getImageUrl());
|
| 2344 |
}
|
2307 |
jsonObj.put("largeIcon", "large_icon");
|
| 2345 |
|
2308 |
jsonObj.put("smallIcon", "small_icon");
|
| 2346 |
} catch (Exception e) {
|
2309 |
jsonObj.put("vibrate", 1);
|
| 2347 |
e.printStackTrace();
|
2310 |
jsonObj.put("pid", pushNotification.getId());
|
| 2348 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
2311 |
jsonObj.put("sound", 1);
|
| 2349 |
LOGGER.info("message " + "not sent " + e.getMessage());
|
2312 |
jsonObj.put("priority", "high");
|
| 2350 |
}
|
2313 |
json.put("data", jsonObj);
|
| 2351 |
}
|
2314 |
try {
|
| 2352 |
}
|
2315 |
CloseableHttpClient client = HttpClients.createDefault();
|
| 2353 |
}
|
2316 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| 2354 |
|
2317 |
|
| 2355 |
public void grouping() throws Exception {
|
2318 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
| 2356 |
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM-dd-yyyy hh:mm");
|
2319 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
| 2357 |
List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByStatus(PriceDropImeiStatus.APPROVED);
|
2320 |
StringEntity entity = new StringEntity(json.toString());
|
| 2358 |
System.out.println(String.join("\t",
|
2321 |
httpPost.setEntity(entity);
|
| 2359 |
Arrays.asList("IMEI", "ItemId", "Brand", "Model Name", "Model Number", "Franchise Id", "Franchise Name",
|
2322 |
CloseableHttpResponse response = client.execute(httpPost);
|
| 2360 |
"Grn On", "Price Dropped On", "Approved On", "Returned On", "Price Drop Paid", "Is Doa")));
|
2323 |
|
| 2361 |
Map<Integer, CustomRetailer> retailersMap = retailerService.getFofoRetailers(false);
|
2324 |
if (response.getStatusLine().getStatusCode() == 200) {
|
| 2362 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
2325 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
| 2363 |
if (priceDropIMEI.getPartnerId() == 0)
|
2326 |
} else {
|
| 2364 |
continue;
|
2327 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 2365 |
HashSet<String> imeis = new HashSet<>();
|
2328 |
LOGGER.info("message" + "not sent");
|
| 2366 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropIMEI.getPriceDropId());
|
2329 |
response.toString();
|
| 2367 |
imeis.add(priceDropIMEI.getImei());
|
2330 |
}
|
| 2368 |
List<InventoryItem> inventoryItems = inventoryItemRepository
|
2331 |
|
| 2369 |
.selectByFofoIdSerialNumbers(priceDropIMEI.getPartnerId(), imeis, false);
|
2332 |
} catch (Exception e) {
|
| 2370 |
if (inventoryItems.size() == 0) {
|
2333 |
e.printStackTrace();
|
| 2371 |
LOGGER.info("Need to investigate partnerId - {} imeis - {}", priceDropIMEI.getPartnerId(), imeis);
|
2334 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 2372 |
continue;
|
2335 |
LOGGER.info("message " + "not sent " + e.getMessage());
|
| 2373 |
}
|
2336 |
}
|
| 2374 |
InventoryItem inventoryItem = inventoryItems.get(0);
|
2337 |
}
|
| 2375 |
CustomRetailer customRetailer = retailersMap.get(inventoryItem.getFofoId());
|
2338 |
}
|
| 2376 |
if (inventoryItem.getLastScanType().equals(ScanType.DOA_OUT)
|
2339 |
}
|
| 2377 |
|| inventoryItem.getLastScanType().equals(ScanType.PURCHASE_RET)) {
|
2340 |
|
| 2378 |
// check if pricedrop has been rolled out
|
2341 |
public void grouping() throws Exception {
|
| 2379 |
List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
|
2342 |
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM-dd-yyyy hh:mm");
|
| 2380 |
priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
|
2343 |
List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByStatus(PriceDropImeiStatus.APPROVED);
|
| 2381 |
if (uwh.size() > 0) {
|
2344 |
System.out.println(String.join("\t",
|
| 2382 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
2345 |
Arrays.asList("IMEI", "ItemId", "Brand", "Model Name", "Model Number", "Franchise Id", "Franchise Name",
|
| 2383 |
System.out.println(String.join("\t",
|
2346 |
"Grn On", "Price Dropped On", "Approved On", "Returned On", "Price Drop Paid", "Is Doa")));
|
| 2384 |
Arrays.asList(priceDropIMEI.getImei(), inventoryItem.getItemId() + "", item.getBrand(),
|
2347 |
Map<Integer, CustomRetailer> retailersMap = retailerService.getFofoRetailers(false);
|
| 2385 |
item.getModelName(), item.getModelNumber(), inventoryItem.getFofoId() + "",
|
2348 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
| 2386 |
customRetailer.getBusinessName(), inventoryItem.getCreateTimestamp().format(dtf),
|
2349 |
if (priceDropIMEI.getPartnerId() == 0)
|
| 2387 |
priceDrop.getAffectedOn().format(dtf),
|
2350 |
continue;
|
| 2388 |
priceDropIMEI.getUpdateTimestamp().format(dtf),
|
2351 |
HashSet<String> imeis = new HashSet<>();
|
| 2389 |
inventoryItem.getUpdateTimestamp().format(dtf),
|
2352 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropIMEI.getPriceDropId());
|
| 2390 |
priceDrop.getAutoPartnerPayout(inventoryItem.getUpdateTimestamp()) + "",
|
2353 |
imeis.add(priceDropIMEI.getImei());
|
| 2391 |
inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
|
2354 |
List<InventoryItem> inventoryItems = inventoryItemRepository
|
| 2392 |
}
|
2355 |
.selectByFofoIdSerialNumbers(priceDropIMEI.getPartnerId(), imeis, false);
|
| 2393 |
}
|
2356 |
if (inventoryItems.size() == 0) {
|
| 2394 |
}
|
2357 |
LOGGER.info("Need to investigate partnerId - {} imeis - {}", priceDropIMEI.getPartnerId(), imeis);
|
| 2395 |
}
|
2358 |
continue;
|
| 2396 |
|
2359 |
}
|
| 2397 |
public void toffeeRollback() throws Exception {
|
2360 |
InventoryItem inventoryItem = inventoryItems.get(0);
|
| 2398 |
toffeeService.cancelPolicyCopy("110143521986");
|
2361 |
CustomRetailer customRetailer = retailersMap.get(inventoryItem.getFofoId());
|
| 2399 |
toffeeService.getOrderId("110143521986");
|
2362 |
if (inventoryItem.getLastScanType().equals(ScanType.DOA_OUT)
|
| 2400 |
}
|
2363 |
|| inventoryItem.getLastScanType().equals(ScanType.PURCHASE_RET)) {
|
| 2401 |
|
2364 |
// check if pricedrop has been rolled out
|
| 2402 |
public void attachToffeeInvoices() throws Exception {
|
2365 |
List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
|
| 2403 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(3,
|
2366 |
priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
|
| 2404 |
Optional.of(false));
|
2367 |
if (uwh.size() > 0) {
|
| 2405 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
2368 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 2406 |
String invoiceNumber = insurancePolicy.getInvoiceNumber();
|
2369 |
System.out.println(String.join("\t",
|
| 2407 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
2370 |
Arrays.asList(priceDropIMEI.getImei(), inventoryItem.getItemId() + "", item.getBrand(),
|
| 2408 |
InvoicePdfModel pdfModel = orderService.getInvoicePdfModel(fofoOrder.getId());
|
2371 |
item.getModelName(), item.getModelNumber(), inventoryItem.getFofoId() + "",
|
| 2409 |
java.io.ByteArrayOutputStream byteArrayOutputStream = new java.io.ByteArrayOutputStream();
|
2372 |
customRetailer.getBusinessName(), inventoryItem.getCreateTimestamp().format(dtf),
|
| 2410 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
2373 |
priceDrop.getAffectedOn().format(dtf),
|
| 2411 |
String pdfInvoiceString = "data:application/pdf;base64,"
|
2374 |
priceDropIMEI.getUpdateTimestamp().format(dtf),
|
| 2412 |
+ Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray());
|
2375 |
inventoryItem.getUpdateTimestamp().format(dtf),
|
| 2413 |
boolean attached = toffeeService.attachInvoice(insurancePolicy.getPolicyNumber().split("#")[1],
|
2376 |
priceDrop.getAutoPartnerPayout(inventoryItem.getUpdateTimestamp()) + "",
|
| 2414 |
pdfInvoiceString);
|
2377 |
inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
|
| 2415 |
if (attached) {
|
2378 |
}
|
| 2416 |
insurancePolicy.setPosted(true);
|
2379 |
}
|
| 2417 |
}
|
2380 |
}
|
| 2418 |
}
|
2381 |
}
|
| 2419 |
}
|
2382 |
|
| 2420 |
|
2383 |
public void toffeeRollback() throws Exception {
|
| 2421 |
public void sendBAGPendingPolicies() throws Exception {
|
2384 |
toffeeService.cancelPolicyCopy("110143521986");
|
| 2422 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(4,
|
2385 |
toffeeService.getOrderId("110143521986");
|
| 2423 |
Optional.of(false));
|
2386 |
}
|
| 2424 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
2387 |
|
| 2425 |
String invoiceNumber = insurancePolicy.getInvoiceNumber();
|
2388 |
public void attachToffeeInvoices() throws Exception {
|
| 2426 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
2389 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(3,
|
| 2427 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId()).get(0);
|
2390 |
Optional.of(false));
|
| 2428 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
2391 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 2429 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
2392 |
String invoiceNumber = insurancePolicy.getInvoiceNumber();
|
| 2430 |
BAGInsuranceModel bagInsuranceModel = new BAGInsuranceModel();
|
2393 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 2431 |
// bagInsuranceModel.setModelId();
|
2394 |
InvoicePdfModel pdfModel = orderService.getInvoicePdfModel(fofoOrder.getId());
|
| 2432 |
bagInsuranceModel.setAddressLine1(customerAddress.getLine1());
|
2395 |
java.io.ByteArrayOutputStream byteArrayOutputStream = new java.io.ByteArrayOutputStream();
|
| 2433 |
bagInsuranceModel.setAddressLine2(customerAddress.getLine2());
|
2396 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
| 2434 |
bagInsuranceModel.setCity(customerAddress.getCity());
|
2397 |
String pdfInvoiceString = "data:application/pdf;base64,"
|
| 2435 |
bagInsuranceModel.setBrandWarranty("1 Year");
|
2398 |
+ Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray());
|
| 2436 |
Item item = itemRepository.selectById(fofoOrderItem.getId());
|
2399 |
boolean attached = toffeeService.attachInvoice(insurancePolicy.getPolicyNumber().split("#")[1],
|
| 2437 |
bagInsuranceModel.setModelName(item.getItemDescription());
|
2400 |
pdfInvoiceString);
|
| 2438 |
bagInsuranceModel.setDateOfPurchase(fofoOrder.getFormattedDate());
|
2401 |
if (attached) {
|
| 2439 |
bagInsuranceModel.setEmail(customer.getEmailId());
|
2402 |
insurancePolicy.setPosted(true);
|
| 2440 |
bagInsuranceModel.setImei1(insurancePolicy.getSerialNumber());
|
2403 |
}
|
| 2441 |
bagInsuranceModel.setFirstName(customer.getFirstName());
|
2404 |
}
|
| 2442 |
bagInsuranceModel.setLastName(customer.getLastName());
|
2405 |
}
|
| 2443 |
bagInsuranceModel.setMobileNumber(customer.getMobileNumber());
|
2406 |
|
| 2444 |
bagInsuranceModel.setPlanId("");
|
2407 |
public void sendBAGPendingPolicies() throws Exception {
|
| 2445 |
insurancePolicy.setPosted(true);
|
2408 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectAllByProviderId(4,
|
| 2446 |
}
|
2409 |
Optional.of(false));
|
| 2447 |
}
|
2410 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 2448 |
|
2411 |
String invoiceNumber = insurancePolicy.getInvoiceNumber();
|
| 2449 |
public void schemeRollback(List<String> schemeIds) throws Exception {
|
2412 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 2450 |
List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
|
2413 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId()).get(0);
|
| 2451 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()
|
2414 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 2452 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
2415 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 2453 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIdsInt));
|
2416 |
BAGInsuranceModel bagInsuranceModel = new BAGInsuranceModel();
|
| 2454 |
for (SchemeInOut sio : schemeInOuts) {
|
2417 |
// bagInsuranceModel.setModelId();
|
| 2455 |
Scheme scheme = schemesMap.get(sio.getSchemeId());
|
2418 |
bagInsuranceModel.setAddressLine1(customerAddress.getLine1());
|
| 2456 |
if (scheme.getType().equals(SchemeType.IN)) {
|
2419 |
bagInsuranceModel.setAddressLine2(customerAddress.getLine2());
|
| 2457 |
|
2420 |
bagInsuranceModel.setCity(customerAddress.getCity());
|
| 2458 |
} else if (scheme.getType().equals(SchemeType.OUT)) {
|
2421 |
bagInsuranceModel.setBrandWarranty("1 Year");
|
| 2459 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
2422 |
Item item = itemRepository.selectById(fofoOrderItem.getId());
|
| 2460 |
List<ScanRecord> sr = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId());
|
2423 |
bagInsuranceModel.setModelName(item.getItemDescription());
|
| 2461 |
ScanRecord scanRecord = sr.stream().filter(x -> x.getType().equals(ScanType.SALE))
|
2424 |
bagInsuranceModel.setDateOfPurchase(fofoOrder.getFormattedDate());
|
| 2462 |
.max((x1, x2) -> x1.getCreateTimestamp().compareTo(x2.getCreateTimestamp())).get();
|
2425 |
bagInsuranceModel.setEmail(customer.getEmailId());
|
| 2463 |
if (scanRecord.getCreateTimestamp().isAfter(scheme.getEndDateTime())
|
2426 |
bagInsuranceModel.setImei1(insurancePolicy.getSerialNumber());
|
| 2464 |
|| scanRecord.getCreateTimestamp().isBefore(scheme.getStartDateTime())) {
|
2427 |
bagInsuranceModel.setFirstName(customer.getFirstName());
|
| 2465 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
2428 |
bagInsuranceModel.setLastName(customer.getLastName());
|
| 2466 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
|
2429 |
bagInsuranceModel.setMobileNumber(customer.getMobileNumber());
|
| 2467 |
String rollbackReason = "Scheme reversed for "
|
2430 |
bagInsuranceModel.setPlanId("");
|
| 2468 |
+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
|
2431 |
insurancePolicy.setPosted(true);
|
| 2469 |
+ fofoOrder.getInvoiceNumber();
|
2432 |
}
|
| 2470 |
walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
|
2433 |
}
|
| 2471 |
scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason,
|
2434 |
|
| 2472 |
LocalDateTime.now());
|
2435 |
public void schemeRollback(List<String> schemeIds) throws Exception {
|
| 2473 |
System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
|
2436 |
List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
|
| 2474 |
rollbackReason);
|
2437 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()
|
| 2475 |
}
|
2438 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 2476 |
}
|
2439 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIdsInt));
|
| 2477 |
}
|
2440 |
for (SchemeInOut sio : schemeInOuts) {
|
| 2478 |
// throw new Exception();
|
2441 |
Scheme scheme = schemesMap.get(sio.getSchemeId());
|
| 2479 |
}
|
2442 |
if (scheme.getType().equals(SchemeType.IN)) {
|
| 2480 |
|
2443 |
|
| 2481 |
public void checkfocusedModelInPartnerStock() throws Exception {
|
2444 |
} else if (scheme.getType().equals(SchemeType.OUT)) {
|
| 2482 |
|
2445 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 2483 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
2446 |
List<ScanRecord> sr = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId());
|
| 2484 |
.collect(Collectors.toList());
|
2447 |
ScanRecord scanRecord = sr.stream().filter(x -> x.getType().equals(ScanType.SALE))
|
| 2485 |
Map<Integer, Map<Integer, List<SaholicCIS>>> warehouseItemAvailabilityMap = saholicInventoryService
|
2448 |
.max((x1, x2) -> x1.getCreateTimestamp().compareTo(x2.getCreateTimestamp())).get();
|
| 2486 |
.getSaholicStock();
|
2449 |
if (scanRecord.getCreateTimestamp().isAfter(scheme.getEndDateTime())
|
| 2487 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
2450 |
|| scanRecord.getCreateTimestamp().isBefore(scheme.getStartDateTime())) {
|
| 2488 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
2451 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 2489 |
|
2452 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
|
| 2490 |
Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap = saholicInventoryService
|
2453 |
String rollbackReason = "Scheme reversed for "
|
| 2491 |
.getSaholicPOItems();
|
2454 |
+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
|
| 2492 |
Map<Integer, List<FocusedModelShortageModel>> focusedModelShortageReportMap = new HashMap<>();
|
2455 |
+ fofoOrder.getInvoiceNumber();
|
| 2493 |
for (Integer fofoId : fofoIds) {
|
2456 |
walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
|
| 2494 |
List<FocusedModelShortageModel> focusedModelShortageList = new ArrayList<>();
|
2457 |
scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason,
|
| 2495 |
focusedModelShortageReportMap.put(fofoId, focusedModelShortageList);
|
2458 |
LocalDateTime.now());
|
| 2496 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
2459 |
System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
|
| 2497 |
Map<Integer, Integer> processingOrderMap = null;
|
2460 |
rollbackReason);
|
| 2498 |
Map<Integer, Integer> catalogIdAndQtyMap = null;
|
2461 |
}
|
| 2499 |
Map<Integer, Integer> grnPendingOrdersMap = null;
|
2462 |
}
|
| 2500 |
|
2463 |
}
|
| 2501 |
Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
|
2464 |
// throw new Exception();
|
| 2502 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
2465 |
}
|
| 2503 |
|
2466 |
|
| 2504 |
if (!currentInventorySnapshot.isEmpty()) {
|
2467 |
public void checkfocusedModelInPartnerStock() throws Exception {
|
| 2505 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
2468 |
|
| 2506 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
2469 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
| 2507 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
2470 |
.collect(Collectors.toList());
|
| 2508 |
|
2471 |
Map<Integer, Map<Integer, List<SaholicCIS>>> warehouseItemAvailabilityMap = saholicInventoryService
|
| 2509 |
}
|
2472 |
.getSaholicStock();
|
| 2510 |
|
2473 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
| 2511 |
Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
2474 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 2512 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
2475 |
|
| 2513 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
2476 |
Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap = saholicInventoryService
|
| 2514 |
if (!grnPendingOrders.isEmpty()) {
|
2477 |
.getSaholicPOItems();
|
| 2515 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
2478 |
Map<Integer, List<FocusedModelShortageModel>> focusedModelShortageReportMap = new HashMap<>();
|
| 2516 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
2479 |
for (Integer fofoId : fofoIds) {
|
| 2517 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
2480 |
List<FocusedModelShortageModel> focusedModelShortageList = new ArrayList<>();
|
| 2518 |
|
2481 |
focusedModelShortageReportMap.put(fofoId, focusedModelShortageList);
|
| 2519 |
}
|
2482 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
| 2520 |
|
2483 |
Map<Integer, Integer> processingOrderMap = null;
|
| 2521 |
Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
|
2484 |
Map<Integer, Integer> catalogIdAndQtyMap = null;
|
| 2522 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
2485 |
Map<Integer, Integer> grnPendingOrdersMap = null;
|
| 2523 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
2486 |
|
| 2524 |
if (!processingOrder.isEmpty()) {
|
2487 |
Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
|
| 2525 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
2488 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
| 2526 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
2489 |
|
| 2527 |
Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
2490 |
if (!currentInventorySnapshot.isEmpty()) {
|
| 2528 |
|
2491 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
| 2529 |
}
|
2492 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
| 2530 |
|
2493 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
| 2531 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
2494 |
|
| 2532 |
.collect(Collectors.toList());
|
2495 |
}
|
| 2533 |
|
2496 |
|
| 2534 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
2497 |
Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
| 2535 |
.collect(Collectors.toList());
|
2498 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
| 2536 |
LOGGER.info("regionIds" + regionIds);
|
2499 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
| 2537 |
if (regionIds.size() == 0) {
|
2500 |
if (!grnPendingOrders.isEmpty()) {
|
| 2538 |
LOGGER.info("No region found for partner {}", fofoId);
|
2501 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
| 2539 |
continue;
|
2502 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
| 2540 |
}
|
2503 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
| 2541 |
Map<Integer, Optional<Integer>> focusedCatalogIdAndQtyMap = focusedModelRepository
|
2504 |
|
| 2542 |
.selectAllByRegionIds(regionIds).stream().collect(Collectors.groupingBy(FocusedModel::getCatalogId,
|
2505 |
}
|
| 2543 |
Collectors.mapping(FocusedModel::getObsMinimumQty, Collectors.maxBy(Integer::compareTo))));
|
2506 |
|
| 2544 |
|
2507 |
Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
|
| 2545 |
LOGGER.info("focusedCatalogIdAndQtyMap" + focusedCatalogIdAndQtyMap);
|
2508 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
| 2546 |
|
2509 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
| 2547 |
for (Map.Entry<Integer, Optional<Integer>> entry : focusedCatalogIdAndQtyMap.entrySet()) {
|
2510 |
if (!processingOrder.isEmpty()) {
|
| 2548 |
int minQty = entry.getValue().get();
|
2511 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
| 2549 |
int inStockQty = 0;
|
2512 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
| 2550 |
int processingQty = 0;
|
2513 |
Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
| 2551 |
int grnPendingQty = 0;
|
2514 |
|
| 2552 |
int allColorNetAvailability = 0;
|
2515 |
}
|
| 2553 |
int allColorPoAvailability = 0;
|
2516 |
|
| 2554 |
if (processingOrderMap != null) {
|
2517 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
| 2555 |
processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
|
2518 |
.collect(Collectors.toList());
|
| 2556 |
: processingOrderMap.get(entry.getKey());
|
2519 |
|
| 2557 |
|
2520 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
| 2558 |
}
|
2521 |
.collect(Collectors.toList());
|
| 2559 |
if (grnPendingOrdersMap != null) {
|
2522 |
LOGGER.info("regionIds" + regionIds);
|
| 2560 |
grnPendingQty = (grnPendingOrdersMap.get(entry.getKey()) == null) ? 0
|
2523 |
if (regionIds.size() == 0) {
|
| 2561 |
: grnPendingOrdersMap.get(entry.getKey());
|
2524 |
LOGGER.info("No region found for partner {}", fofoId);
|
| 2562 |
|
2525 |
continue;
|
| 2563 |
}
|
2526 |
}
|
| 2564 |
if (catalogIdAndQtyMap != null) {
|
2527 |
Map<Integer, Optional<Integer>> focusedCatalogIdAndQtyMap = focusedModelRepository
|
| 2565 |
inStockQty = (catalogIdAndQtyMap.get(entry.getKey()) == null) ? 0
|
2528 |
.selectAllByRegionIds(regionIds).stream().collect(Collectors.groupingBy(FocusedModel::getCatalogId,
|
| 2566 |
: catalogIdAndQtyMap.get(entry.getKey());
|
2529 |
Collectors.mapping(FocusedModel::getObsMinimumQty, Collectors.maxBy(Integer::compareTo))));
|
| 2567 |
|
2530 |
|
| 2568 |
}
|
2531 |
LOGGER.info("focusedCatalogIdAndQtyMap" + focusedCatalogIdAndQtyMap);
|
| 2569 |
|
2532 |
|
| 2570 |
int grnStockQty = grnPendingQty + inStockQty;
|
2533 |
for (Map.Entry<Integer, Optional<Integer>> entry : focusedCatalogIdAndQtyMap.entrySet()) {
|
| 2571 |
int totalQty = processingQty + grnPendingQty + inStockQty;
|
2534 |
int minQty = entry.getValue().get();
|
| 2572 |
|
2535 |
int inStockQty = 0;
|
| 2573 |
int shortageQty = minQty - totalQty;
|
2536 |
int processingQty = 0;
|
| 2574 |
List<Item> items = itemRepository.selectAllByCatalogItemId(entry.getKey());
|
2537 |
int grnPendingQty = 0;
|
| 2575 |
|
2538 |
int allColorNetAvailability = 0;
|
| 2576 |
TagListing tagListing = tagListingRepository.selectByCatalogId(entry.getKey());
|
2539 |
int allColorPoAvailability = 0;
|
| 2577 |
|
2540 |
if (processingOrderMap != null) {
|
| 2578 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
2541 |
processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
|
| 2579 |
|
2542 |
: processingOrderMap.get(entry.getKey());
|
| 2580 |
Map<Integer, List<SaholicCIS>> itemAvailabilityMap = warehouseItemAvailabilityMap
|
2543 |
|
| 2581 |
.get(fofoStore.getWarehouseId());
|
2544 |
}
|
| 2582 |
|
2545 |
if (grnPendingOrdersMap != null) {
|
| 2583 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = warehousePoItemAvailabilityMap
|
2546 |
grnPendingQty = (grnPendingOrdersMap.get(entry.getKey()) == null) ? 0
|
| 2584 |
.get(fofoStore.getWarehouseId());
|
2547 |
: grnPendingOrdersMap.get(entry.getKey());
|
| 2585 |
|
2548 |
|
| 2586 |
for (Item item : items) {
|
2549 |
}
|
| 2587 |
List<SaholicCIS> currentAvailability = null;
|
2550 |
if (catalogIdAndQtyMap != null) {
|
| 2588 |
List<SaholicPOItem> poItemAvailability = null;
|
2551 |
inStockQty = (catalogIdAndQtyMap.get(entry.getKey()) == null) ? 0
|
| 2589 |
if (itemAvailabilityMap != null) {
|
2552 |
: catalogIdAndQtyMap.get(entry.getKey());
|
| 2590 |
currentAvailability = itemAvailabilityMap.get(item.getId());
|
2553 |
|
| 2591 |
}
|
2554 |
}
|
| 2592 |
|
2555 |
|
| 2593 |
if (poItemAvailabilityMap != null) {
|
2556 |
int grnStockQty = grnPendingQty + inStockQty;
|
| 2594 |
poItemAvailability = poItemAvailabilityMap.get(item.getId());
|
2557 |
int totalQty = processingQty + grnPendingQty + inStockQty;
|
| 2595 |
}
|
2558 |
|
| 2596 |
if (currentAvailability != null) {
|
2559 |
int shortageQty = minQty - totalQty;
|
| 2597 |
allColorNetAvailability += currentAvailability.stream()
|
2560 |
List<Item> items = itemRepository.selectAllByCatalogItemId(entry.getKey());
|
| 2598 |
.collect(Collectors.summingInt(SaholicCIS::getNetavailability));
|
2561 |
|
| 2599 |
}
|
2562 |
TagListing tagListing = tagListingRepository.selectByCatalogId(entry.getKey());
|
| 2600 |
|
2563 |
|
| 2601 |
if (poItemAvailability != null) {
|
2564 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 2602 |
allColorPoAvailability += poItemAvailability.stream()
|
2565 |
|
| 2603 |
.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
|
2566 |
Map<Integer, List<SaholicCIS>> itemAvailabilityMap = warehouseItemAvailabilityMap
|
| 2604 |
}
|
2567 |
.get(fofoStore.getWarehouseId());
|
| 2605 |
|
2568 |
|
| 2606 |
}
|
2569 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = warehousePoItemAvailabilityMap
|
| 2607 |
|
2570 |
.get(fofoStore.getWarehouseId());
|
| 2608 |
FocusedModelShortageModel fm = new FocusedModelShortageModel();
|
2571 |
|
| 2609 |
fm.setFofoId(fofoId);
|
2572 |
for (Item item : items) {
|
| 2610 |
fm.setStoreCode(fofoStore.getCode());
|
2573 |
List<SaholicCIS> currentAvailability = null;
|
| 2611 |
fm.setStoreName(customRetailer.getBusinessName());
|
2574 |
List<SaholicPOItem> poItemAvailability = null;
|
| 2612 |
fm.setBrandName(items.get(0).getBrand());
|
2575 |
if (itemAvailabilityMap != null) {
|
| 2613 |
fm.setModelName(items.get(0).getModelName());
|
2576 |
currentAvailability = itemAvailabilityMap.get(item.getId());
|
| 2614 |
fm.setModelNumber(items.get(0).getModelNumber());
|
2577 |
}
|
| 2615 |
fm.setGrnStockQty(grnStockQty);
|
2578 |
|
| 2616 |
fm.setPendingIndentQty(processingQty);
|
2579 |
if (poItemAvailabilityMap != null) {
|
| 2617 |
fm.setShortageQty(shortageQty);
|
2580 |
poItemAvailability = poItemAvailabilityMap.get(item.getId());
|
| 2618 |
fm.setPoAvailability(allColorPoAvailability);
|
2581 |
}
|
| 2619 |
fm.setDp(tagListing.getSellingPrice());
|
2582 |
if (currentAvailability != null) {
|
| 2620 |
fm.setWarehouseName(warehouseMap.get(customRetailer.getWarehouseId()));
|
2583 |
allColorNetAvailability += currentAvailability.stream()
|
| 2621 |
fm.setStateManager(partnerIdSalesHeadersMap.get(fofoId).getRegionalManager());
|
2584 |
.collect(Collectors.summingInt(SaholicCIS::getNetavailability));
|
| 2622 |
fm.setTerritoryManager(partnerIdSalesHeadersMap.get(fofoId).getTerritoryManager());
|
2585 |
}
|
| 2623 |
fm.setItemName(items.get(0).getBrand() + items.get(0).getModelNumber() + items.get(0).getModelName());
|
2586 |
|
| 2624 |
fm.setAvailability(allColorNetAvailability);
|
2587 |
if (poItemAvailability != null) {
|
| 2625 |
|
2588 |
allColorPoAvailability += poItemAvailability.stream()
|
| 2626 |
focusedModelShortageList.add(fm);
|
2589 |
.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
|
| 2627 |
}
|
2590 |
}
|
| 2628 |
|
2591 |
|
| 2629 |
}
|
2592 |
}
|
| 2630 |
if (!focusedModelShortageReportMap.isEmpty()) {
|
2593 |
|
| 2631 |
String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
2594 |
FocusedModelShortageModel fm = new FocusedModelShortageModel();
|
| 2632 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
2595 |
fm.setFofoId(fofoId);
|
| 2633 |
Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
|
2596 |
fm.setStoreCode(fofoStore.getCode());
|
| 2634 |
|
2597 |
fm.setStoreName(customRetailer.getBusinessName());
|
| 2635 |
focusedModelShortageReportMap.entrySet().forEach(x -> {
|
2598 |
fm.setBrandName(items.get(0).getBrand());
|
| 2636 |
storeGuyMap.entrySet().forEach(y -> {
|
2599 |
fm.setModelName(items.get(0).getModelName());
|
| 2637 |
|
2600 |
fm.setModelNumber(items.get(0).getModelNumber());
|
| 2638 |
if (y.getValue().contains(x.getKey())) {
|
2601 |
fm.setGrnStockQty(grnStockQty);
|
| 2639 |
if (!emailRowsMap.containsKey(y.getKey())) {
|
2602 |
fm.setPendingIndentQty(processingQty);
|
| 2640 |
emailRowsMap.put(y.getKey(), new ArrayList<>());
|
2603 |
fm.setShortageQty(shortageQty);
|
| 2641 |
}
|
2604 |
fm.setPoAvailability(allColorPoAvailability);
|
| 2642 |
List<List<? extends Serializable>> fms = x.getValue().stream()
|
2605 |
fm.setDp(tagListing.getSellingPrice());
|
| 2643 |
.map(r -> Arrays.asList(r.getStoreCode(), r.getStoreName(), r.getBrandName(),
|
2606 |
fm.setWarehouseName(warehouseMap.get(customRetailer.getWarehouseId()));
|
| 2644 |
r.getModelName(), r.getModelNumber(), r.getDp(), r.getWarehouseName(),
|
2607 |
fm.setStateManager(partnerIdSalesHeadersMap.get(fofoId).getRegionalManager());
|
| 2645 |
r.getStateManager(), r.getTerritoryManager(), r.getPendingIndentQty(),
|
2608 |
fm.setTerritoryManager(partnerIdSalesHeadersMap.get(fofoId).getTerritoryManager());
|
| 2646 |
r.getGrnStockQty(), r.getShortageQty(), r.getAvailability()))
|
2609 |
fm.setItemName(items.get(0).getBrand() + items.get(0).getModelNumber() + items.get(0).getModelName());
|
| 2647 |
.collect(Collectors.toList());
|
2610 |
fm.setAvailability(allColorNetAvailability);
|
| 2648 |
emailRowsMap.get(y.getKey()).addAll(fms);
|
2611 |
|
| 2649 |
|
2612 |
focusedModelShortageList.add(fm);
|
| 2650 |
}
|
2613 |
}
|
| 2651 |
|
2614 |
|
| 2652 |
});
|
2615 |
}
|
| 2653 |
|
2616 |
if (!focusedModelShortageReportMap.isEmpty()) {
|
| 2654 |
});
|
2617 |
String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 2655 |
|
2618 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 2656 |
List<String> headers = Arrays.asList("Store Code", "Store Name", "Brand", "Model Name", "Model Number",
|
2619 |
Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
|
| 2657 |
"DP", "Warehouse Name", "State Manager", "Territory Manager", "Pending Indent", "InStock",
|
2620 |
|
| 2658 |
"Shortage Qty", "Availability");
|
2621 |
focusedModelShortageReportMap.entrySet().forEach(x -> {
|
| 2659 |
emailRowsMap.entrySet().forEach(entry -> {
|
2622 |
storeGuyMap.entrySet().forEach(y -> {
|
| 2660 |
|
2623 |
|
| 2661 |
ByteArrayOutputStream baos = null;
|
2624 |
if (y.getValue().contains(x.getKey())) {
|
| 2662 |
try {
|
2625 |
if (!emailRowsMap.containsKey(y.getKey())) {
|
| 2663 |
baos = FileUtil.getCSVByteStream(headers, entry.getValue());
|
2626 |
emailRowsMap.put(y.getKey(), new ArrayList<>());
|
| 2664 |
} catch (Exception e2) {
|
2627 |
}
|
| 2665 |
e2.printStackTrace();
|
2628 |
List<List<? extends Serializable>> fms = x.getValue().stream()
|
| 2666 |
}
|
2629 |
.map(r -> Arrays.asList(r.getStoreCode(), r.getStoreName(), r.getBrandName(),
|
| 2667 |
String[] sendToArray = new String[] {
|
2630 |
r.getModelName(), r.getModelNumber(), r.getDp(), r.getWarehouseName(),
|
| 2668 |
|
2631 |
r.getStateManager(), r.getTerritoryManager(), r.getPendingIndentQty(),
|
| 2669 |
entry.getKey()
|
2632 |
r.getGrnStockQty(), r.getShortageQty(), r.getAvailability()))
|
| 2670 |
|
2633 |
.collect(Collectors.toList());
|
| 2671 |
};
|
2634 |
emailRowsMap.get(y.getKey()).addAll(fms);
|
| 2672 |
|
2635 |
|
| 2673 |
try {
|
2636 |
}
|
| 2674 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
|
2637 |
|
| 2675 |
new ByteArrayResource(baos.toByteArray()));
|
2638 |
});
|
| 2676 |
} catch (Exception e1) { // TODO Auto-generated catch block
|
2639 |
|
| 2677 |
e1.printStackTrace();
|
2640 |
});
|
| 2678 |
}
|
2641 |
|
| 2679 |
|
2642 |
List<String> headers = Arrays.asList("Store Code", "Store Name", "Brand", "Model Name", "Model Number",
|
| 2680 |
});
|
2643 |
"DP", "Warehouse Name", "State Manager", "Territory Manager", "Pending Indent", "InStock",
|
| 2681 |
}
|
2644 |
"Shortage Qty", "Availability");
|
| 2682 |
}
|
2645 |
emailRowsMap.entrySet().forEach(entry -> {
|
| 2683 |
|
2646 |
|
| 2684 |
private String getNotificationMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
2647 |
ByteArrayOutputStream baos = null;
|
| 2685 |
StringBuilder sb = new StringBuilder();
|
2648 |
try {
|
| 2686 |
sb.append("Focused Model Shortage in Your Stock : \n");
|
2649 |
baos = FileUtil.getCSVByteStream(headers, entry.getValue());
|
| 2687 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
2650 |
} catch (Exception e2) {
|
| 2688 |
|
2651 |
e2.printStackTrace();
|
| 2689 |
sb.append(entry.getItemName() + "-" + entry.getShortageQty());
|
2652 |
}
|
| 2690 |
sb.append(String.format("%n", ""));
|
2653 |
String[] sendToArray = new String[]{
|
| 2691 |
}
|
2654 |
|
| 2692 |
return sb.toString();
|
2655 |
entry.getKey()
|
| 2693 |
}
|
2656 |
|
| 2694 |
|
2657 |
};
|
| 2695 |
private void sendMailWithAttachments(String subject, String messageText, String email) throws Exception {
|
2658 |
|
| 2696 |
MimeMessage message = mailSender.createMimeMessage();
|
2659 |
try {
|
| 2697 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
2660 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
|
| 2698 |
|
2661 |
new ByteArrayResource(baos.toByteArray()));
|
| 2699 |
helper.setSubject(subject);
|
2662 |
} catch (Exception e1) { // TODO Auto-generated catch block
|
| 2700 |
helper.setText(messageText, true);
|
2663 |
e1.printStackTrace();
|
| 2701 |
helper.setTo(email);
|
2664 |
}
|
| 2702 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
2665 |
|
| 2703 |
helper.setFrom(senderAddress);
|
2666 |
});
|
| 2704 |
mailSender.send(message);
|
2667 |
}
|
| 2705 |
|
2668 |
}
|
| 2706 |
}
|
2669 |
|
| 2707 |
|
2670 |
private String getNotificationMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
| 2708 |
private String getMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
2671 |
StringBuilder sb = new StringBuilder();
|
| 2709 |
StringBuilder sb = new StringBuilder();
|
2672 |
sb.append("Focused Model Shortage in Your Stock : \n");
|
| 2710 |
sb.append("<html><body><p>Alert</p><p>Focused Model Shortage in Your Stock:-</p>"
|
2673 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
| 2711 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
2674 |
|
| 2712 |
sb.append("<tbody>\n" + " <tr>\n"
|
2675 |
sb.append(entry.getItemName() + "-" + entry.getShortageQty());
|
| 2713 |
+ " <th style='border:1px solid black;padding: 5px'>Item</th>\n"
|
2676 |
sb.append(String.format("%n", ""));
|
| 2714 |
+ " <th style='border:1px solid black;padding: 5px'>Shortage Qty</th>\n"
|
2677 |
}
|
| 2715 |
+ " </tr>");
|
2678 |
return sb.toString();
|
| 2716 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
2679 |
}
|
| 2717 |
|
2680 |
|
| 2718 |
sb.append("<tr>");
|
2681 |
private void sendMailWithAttachments(String subject, String messageText, String email) throws Exception {
|
| 2719 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getItemName() + "</td>");
|
2682 |
MimeMessage message = mailSender.createMimeMessage();
|
| 2720 |
|
2683 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 2721 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getShortageQty() + "</td>");
|
2684 |
|
| 2722 |
|
2685 |
helper.setSubject(subject);
|
| 2723 |
sb.append("</tr>");
|
2686 |
helper.setText(messageText, true);
|
| 2724 |
|
2687 |
helper.setTo(email);
|
| 2725 |
}
|
2688 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
| 2726 |
|
2689 |
helper.setFrom(senderAddress);
|
| 2727 |
sb.append("</tbody></table></body></html>");
|
2690 |
mailSender.send(message);
|
| 2728 |
|
2691 |
|
| 2729 |
return sb.toString();
|
2692 |
}
|
| 2730 |
}
|
2693 |
|
| 2731 |
|
2694 |
private String getMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
| 2732 |
public void notifyLead() throws Exception {
|
2695 |
StringBuilder sb = new StringBuilder();
|
| 2733 |
List<Lead> leadsToNotify = leadRepository.selectLeadsScheduledBetweenDate(null,
|
2696 |
sb.append("<html><body><p>Alert</p><p>Focused Model Shortage in Your Stock:-</p>"
|
| 2734 |
LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
2697 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
| 2735 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
2698 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 2736 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
2699 |
+ " <th style='border:1px solid black;padding: 5px'>Item</th>\n"
|
| 2737 |
LOGGER.info("authUserEmailMap {}", authUserEmailMap);
|
2700 |
+ " <th style='border:1px solid black;padding: 5px'>Shortage Qty</th>\n"
|
| 2738 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
2701 |
+ " </tr>");
|
| 2739 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
2702 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
| 2740 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
2703 |
|
| 2741 |
|
2704 |
sb.append("<tr>");
|
| 2742 |
LOGGER.info("dtrEmailMap {}", dtrEmailMap);
|
2705 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getItemName() + "</td>");
|
| 2743 |
|
2706 |
|
| 2744 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
2707 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getShortageQty() + "</td>");
|
| 2745 |
|
2708 |
|
| 2746 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
2709 |
sb.append("</tr>");
|
| 2747 |
int authId = authUserEmail.getKey();
|
2710 |
|
| 2748 |
String email = authUserEmail.getValue();
|
2711 |
}
|
| 2749 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
2712 |
|
| 2750 |
}
|
2713 |
sb.append("</tbody></table></body></html>");
|
| 2751 |
LOGGER.info("authUserKeyMap", authUserKeyMap);
|
2714 |
|
| 2752 |
LOGGER.info("leadsToNotify {}", leadsToNotify);
|
2715 |
return sb.toString();
|
| 2753 |
|
2716 |
}
|
| 2754 |
String templateMessage = "Lead followup for %s %s, %s, %s is due by %s";
|
2717 |
|
| 2755 |
for (Lead lead : leadsToNotify) {
|
2718 |
public void notifyLead() throws Exception {
|
| 2756 |
if (authUserKeyMap.get(lead.getAssignTo()) == null) {
|
2719 |
List<Lead> leadsToNotify = leadRepository.selectLeadsScheduledBetweenDate(null,
|
| 2757 |
LOGGER.info("Assignee no longer part of system {}", lead.getAssignTo());
|
2720 |
LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
| 2758 |
continue;
|
2721 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
| 2759 |
}
|
2722 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
| 2760 |
String title = "Leads followup Reminder";
|
2723 |
LOGGER.info("authUserEmailMap {}", authUserEmailMap);
|
| 2761 |
String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
|
2724 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
| 2762 |
lead.getAddress(), lead.getLeadMobile(), leadTimeFormatter.format(lead.getScheduledTimestamp()));
|
2725 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
| 2763 |
String url = "https://app.smartdukaan.com/pages/home/leadUpdate?leadId=" + lead.getId();
|
2726 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
| 2764 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
2727 |
|
| 2765 |
sendNotificationModel.setCampaignName("Lead Reminder");
|
2728 |
LOGGER.info("dtrEmailMap {}", dtrEmailMap);
|
| 2766 |
sendNotificationModel.setTitle(title);
|
2729 |
|
| 2767 |
sendNotificationModel.setMessage(notificationMessage);
|
2730 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
| 2768 |
sendNotificationModel.setType("url");
|
2731 |
|
| 2769 |
sendNotificationModel.setUrl(url);
|
2732 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
| 2770 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
2733 |
int authId = authUserEmail.getKey();
|
| 2771 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
2734 |
String email = authUserEmail.getValue();
|
| 2772 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
|
2735 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
| 2773 |
System.out.println(sendNotificationModel);
|
2736 |
}
|
| 2774 |
notificationService.sendNotification(sendNotificationModel);
|
2737 |
LOGGER.info("authUserKeyMap", authUserKeyMap);
|
| 2775 |
AuthUser authUser = authRepository.selectById(lead.getAssignTo());
|
2738 |
LOGGER.info("leadsToNotify {}", leadsToNotify);
|
| 2776 |
// notificationService.sendWhatsappMessage(notificationMessage, title,
|
2739 |
|
| 2777 |
// authUser.getMobileNumber());
|
2740 |
String templateMessage = "Lead followup for %s %s, %s, %s is due by %s";
|
| 2778 |
}
|
2741 |
for (Lead lead : leadsToNotify) {
|
| 2779 |
}
|
2742 |
if (authUserKeyMap.get(lead.getAssignTo()) == null) {
|
| 2780 |
|
2743 |
LOGGER.info("Assignee no longer part of system {}", lead.getAssignTo());
|
| 2781 |
public void notifyVisits() throws Exception {
|
2744 |
continue;
|
| 2782 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository
|
2745 |
}
|
| 2783 |
.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
2746 |
String title = "Leads followup Reminder";
|
| 2784 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
2747 |
String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
|
| 2785 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
2748 |
lead.getAddress(), lead.getLeadMobile(), leadTimeFormatter.format(lead.getScheduledTimestamp()));
|
| 2786 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
2749 |
String url = "https://app.smartdukaan.com/pages/home/leadUpdate?leadId=" + lead.getId();
|
| 2787 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
2750 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 2788 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
2751 |
sendNotificationModel.setCampaignName("Lead Reminder");
|
| 2789 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
2752 |
sendNotificationModel.setTitle(title);
|
| 2790 |
|
2753 |
sendNotificationModel.setMessage(notificationMessage);
|
| 2791 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
2754 |
sendNotificationModel.setType("url");
|
| 2792 |
int authId = authUserEmail.getKey();
|
2755 |
sendNotificationModel.setUrl(url);
|
| 2793 |
String email = authUserEmail.getValue();
|
2756 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
| 2794 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
2757 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
| 2795 |
}
|
2758 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
|
| 2796 |
String visitTemplate = "Planned visit to franchisee %s is due by %s";
|
2759 |
System.out.println(sendNotificationModel);
|
| 2797 |
String followupTemplate = "Lead followup for franchisee %s is due by %s";
|
2760 |
notificationService.sendNotification(sendNotificationModel);
|
| 2798 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("MMM 7, EEEE h:m a");
|
2761 |
AuthUser authUser = authRepository.selectById(lead.getAssignTo());
|
| 2799 |
for (FranchiseeVisit visit : franchiseeVisits) {
|
2762 |
// notificationService.sendWhatsappMessage(notificationMessage, title,
|
| 2800 |
if (authUserKeyMap.containsKey(visit.getAuthId())) {
|
2763 |
// authUser.getMobileNumber());
|
| 2801 |
continue;
|
2764 |
}
|
| 2802 |
}
|
2765 |
}
|
| 2803 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
2766 |
|
| 2804 |
String message = null;
|
2767 |
public void notifyVisits() throws Exception {
|
| 2805 |
if (visit.getFranchiseActivityId() == 0) {
|
2768 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository
|
| 2806 |
message = String.format(visitTemplate, visit.getPartnerName(),
|
2769 |
.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
|
| 2807 |
timeFormatter.format(visit.getScheduleTimestamp()));
|
2770 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
| 2808 |
sendNotificationModel.setCampaignName("Franchisee visit Reminder");
|
2771 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
| 2809 |
} else {
|
2772 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
| 2810 |
message = String.format(followupTemplate, visit.getPartnerName(),
|
2773 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
| 2811 |
timeFormatter.format(visit.getScheduleTimestamp()));
|
2774 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
| 2812 |
sendNotificationModel.setCampaignName("Franchisee followup Reminder");
|
2775 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
| 2813 |
}
|
2776 |
|
| 2814 |
sendNotificationModel.setMessage(message);
|
2777 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
| 2815 |
sendNotificationModel.setType("url");
|
2778 |
int authId = authUserEmail.getKey();
|
| 2816 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
2779 |
String email = authUserEmail.getValue();
|
| 2817 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
2780 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
| 2818 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
2781 |
}
|
| 2819 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(visit.getAuthId())));
|
2782 |
String visitTemplate = "Planned visit to franchisee %s is due by %s";
|
| 2820 |
// notificationService.sendNotification(sendNotificationModel);
|
2783 |
String followupTemplate = "Lead followup for franchisee %s is due by %s";
|
| 2821 |
}
|
2784 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("MMM 7, EEEE h:m a");
|
| 2822 |
}
|
2785 |
for (FranchiseeVisit visit : franchiseeVisits) {
|
| 2823 |
|
2786 |
if (authUserKeyMap.containsKey(visit.getAuthId())) {
|
| 2824 |
public void ticketClosed() throws Exception {
|
2787 |
continue;
|
| 2825 |
|
2788 |
}
|
| 2826 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTicketsWithStatus(ActivityType.RESOLVED);
|
2789 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 2827 |
for (Ticket ticket : tickets) {
|
2790 |
String message = null;
|
| 2828 |
if (ticket.getUpdateTimestamp().toLocalDate().isBefore(LocalDate.now().minusDays(7))) {
|
2791 |
if (visit.getFranchiseActivityId() == 0) {
|
| 2829 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
2792 |
message = String.format(visitTemplate, visit.getPartnerName(),
|
| 2830 |
ticket.setLastActivity(ActivityType.RESOLVED_ACCEPTED);
|
2793 |
timeFormatter.format(visit.getScheduleTimestamp()));
|
| 2831 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
2794 |
sendNotificationModel.setCampaignName("Franchisee visit Reminder");
|
| 2832 |
ticketRepository.persist(ticket);
|
2795 |
} else {
|
| 2833 |
}
|
2796 |
message = String.format(followupTemplate, visit.getPartnerName(),
|
| 2834 |
}
|
2797 |
timeFormatter.format(visit.getScheduleTimestamp()));
|
| 2835 |
|
2798 |
sendNotificationModel.setCampaignName("Franchisee followup Reminder");
|
| 2836 |
}
|
2799 |
}
|
| 2837 |
|
2800 |
sendNotificationModel.setMessage(message);
|
| 2838 |
public void checkValidateReferral() throws Exception {
|
2801 |
sendNotificationModel.setType("url");
|
| 2839 |
|
2802 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 2840 |
List<Refferal> referrals = refferalRepository.selectByStatus(RefferalStatus.pending);
|
2803 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
| 2841 |
LOGGER.info("referrals" + referrals);
|
2804 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
| 2842 |
if (!referrals.isEmpty()) {
|
2805 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(visit.getAuthId())));
|
| 2843 |
String subject = "Referral Request";
|
2806 |
// notificationService.sendNotification(sendNotificationModel);
|
| 2844 |
String messageText = this.getMessageForReferral(referrals);
|
2807 |
}
|
| 2845 |
|
2808 |
}
|
| 2846 |
MimeMessage message = mailSender.createMimeMessage();
|
2809 |
|
| 2847 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
2810 |
public void ticketClosed() throws Exception {
|
| 2848 |
String[] email = { "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com" };
|
2811 |
|
| 2849 |
helper.setSubject(subject);
|
2812 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTicketsWithStatus(ActivityType.RESOLVED);
|
| 2850 |
helper.setText(messageText, true);
|
2813 |
for (Ticket ticket : tickets) {
|
| 2851 |
helper.setTo(email);
|
2814 |
if (ticket.getUpdateTimestamp().toLocalDate().isBefore(LocalDate.now().minusDays(7))) {
|
| 2852 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
2815 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
| 2853 |
helper.setFrom(senderAddress);
|
2816 |
ticket.setLastActivity(ActivityType.RESOLVED_ACCEPTED);
|
| 2854 |
mailSender.send(message);
|
2817 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| 2855 |
|
2818 |
ticketRepository.persist(ticket);
|
| 2856 |
}
|
2819 |
}
|
| 2857 |
}
|
2820 |
}
|
| 2858 |
|
2821 |
|
| 2859 |
private String getMessageForReferral(List<Refferal> referrals) {
|
2822 |
}
|
| 2860 |
StringBuilder sb = new StringBuilder();
|
2823 |
|
| 2861 |
sb.append("<html><body><p>Alert</p><p>Pending Referrals:-</p>"
|
2824 |
public void checkValidateReferral() throws Exception {
|
| 2862 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
2825 |
|
| 2863 |
sb.append("<tbody>\n" + " <tr>\n"
|
2826 |
List<Refferal> referrals = refferalRepository.selectByStatus(RefferalStatus.pending);
|
| 2864 |
+ " <th style='border:1px solid black;padding: 5px'>RefereeName</th>\n"
|
2827 |
LOGGER.info("referrals" + referrals);
|
| 2865 |
+ " <th style='border:1px solid black;padding: 5px'>Referee Email</th>\n"
|
2828 |
if (!referrals.isEmpty()) {
|
| 2866 |
+ " <th style='border:1px solid black;padding: 5px'>Referral Name</th>\n"
|
2829 |
String subject = "Referral Request";
|
| 2867 |
+ " <th style='border:1px solid black;padding: 5px'>Refferal Mobile</th>\n"
|
2830 |
String messageText = this.getMessageForReferral(referrals);
|
| 2868 |
+ " <th style='border:1px solid black;padding: 5px'>city</th>\n"
|
2831 |
|
| 2869 |
+ " <th style='border:1px solid black;padding: 5px'>state</th>\n"
|
2832 |
MimeMessage message = mailSender.createMimeMessage();
|
| 2870 |
+ " </tr>");
|
2833 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 2871 |
for (Refferal entry : referrals) {
|
2834 |
String[] email = {"kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com"};
|
| 2872 |
|
2835 |
helper.setSubject(subject);
|
| 2873 |
sb.append("<tr>");
|
2836 |
helper.setText(messageText, true);
|
| 2874 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeName() + "</td>");
|
2837 |
helper.setTo(email);
|
| 2875 |
|
2838 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
| 2876 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeEmail() + "</td>");
|
2839 |
helper.setFrom(senderAddress);
|
| 2877 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getFirstName() + "</td>");
|
2840 |
mailSender.send(message);
|
| 2878 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getMobile() + "</td>");
|
2841 |
|
| 2879 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCity() + "</td>");
|
2842 |
}
|
| 2880 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getState() + "</td>");
|
2843 |
}
|
| 2881 |
|
2844 |
|
| 2882 |
sb.append("</tr>");
|
2845 |
private String getMessageForReferral(List<Refferal> referrals) {
|
| 2883 |
|
2846 |
StringBuilder sb = new StringBuilder();
|
| 2884 |
}
|
2847 |
sb.append("<html><body><p>Alert</p><p>Pending Referrals:-</p>"
|
| 2885 |
|
2848 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
| 2886 |
sb.append("</tbody></table></body></html>");
|
2849 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 2887 |
|
2850 |
+ " <th style='border:1px solid black;padding: 5px'>RefereeName</th>\n"
|
| 2888 |
return sb.toString();
|
2851 |
+ " <th style='border:1px solid black;padding: 5px'>Referee Email</th>\n"
|
| 2889 |
}
|
2852 |
+ " <th style='border:1px solid black;padding: 5px'>Referral Name</th>\n"
|
| 2890 |
|
2853 |
+ " <th style='border:1px solid black;padding: 5px'>Refferal Mobile</th>\n"
|
| 2891 |
private String getMessageForUncontacblePartner(List<PartnerCollectionRemark> pcrs)
|
2854 |
+ " <th style='border:1px solid black;padding: 5px'>city</th>\n"
|
| 2892 |
throws ProfitMandiBusinessException {
|
2855 |
+ " <th style='border:1px solid black;padding: 5px'>state</th>\n"
|
| 2893 |
StringBuilder sb = new StringBuilder();
|
2856 |
+ " </tr>");
|
| 2894 |
sb.append("<html><body><p>Alert</p><p>Not Responding Partner:-</p>"
|
2857 |
for (Refferal entry : referrals) {
|
| 2895 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
2858 |
|
| 2896 |
sb.append("<tbody>\n" + " <tr>\n"
|
2859 |
sb.append("<tr>");
|
| 2897 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
2860 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeName() + "</td>");
|
| 2898 |
+ " <th style='border:1px solid black;padding: 5px'>from</th>\n"
|
2861 |
|
| 2899 |
|
2862 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getRefereeEmail() + "</td>");
|
| 2900 |
+ " </tr>");
|
2863 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getFirstName() + "</td>");
|
| 2901 |
for (PartnerCollectionRemark entry : pcrs) {
|
2864 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getMobile() + "</td>");
|
| 2902 |
|
2865 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCity() + "</td>");
|
| 2903 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
2866 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getState() + "</td>");
|
| 2904 |
|
2867 |
|
| 2905 |
sb.append("<tr>");
|
2868 |
sb.append("</tr>");
|
| 2906 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
2869 |
|
| 2907 |
+ customRetailer.getCode() + ")" + "</td>");
|
2870 |
}
|
| 2908 |
|
2871 |
|
| 2909 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
2872 |
sb.append("</tbody></table></body></html>");
|
| 2910 |
+ entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
2873 |
|
| 2911 |
|
2874 |
return sb.toString();
|
| 2912 |
sb.append("</tr>");
|
2875 |
}
|
| 2913 |
|
2876 |
|
| 2914 |
}
|
2877 |
private String getMessageForUncontacblePartner(List<PartnerCollectionRemark> pcrs)
|
| 2915 |
|
2878 |
throws ProfitMandiBusinessException {
|
| 2916 |
sb.append("</tbody></table></body></html>");
|
2879 |
StringBuilder sb = new StringBuilder();
|
| 2917 |
|
2880 |
sb.append("<html><body><p>Alert</p><p>Not Responding Partner:-</p>"
|
| 2918 |
return sb.toString();
|
2881 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
| 2919 |
}
|
2882 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 2920 |
|
2883 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
| 2921 |
public void reverseWallet() throws Exception {
|
2884 |
+ " <th style='border:1px solid black;padding: 5px'>from</th>\n"
|
| 2922 |
LocalDate localDate = LocalDate.of(2020, 10, 28);
|
2885 |
|
| 2923 |
List<UserWalletHistory> uwhList = userWalletHistoryRepository.selectAllByDateType(localDate.atStartOfDay(),
|
2886 |
+ " </tr>");
|
| 2924 |
localDate.plusDays(1).atStartOfDay(),
|
2887 |
for (PartnerCollectionRemark entry : pcrs) {
|
| 2925 |
Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
2888 |
|
| 2926 |
for (UserWalletHistory uwh : uwhList) {
|
2889 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
| 2927 |
if (uwh.getBusinessTimestamp().getMonth().equals(Month.SEPTEMBER)) {
|
2890 |
|
| 2928 |
UserWallet uw = userWalletRepository.selectById(uwh.getWalletId());
|
2891 |
sb.append("<tr>");
|
| 2929 |
// LOGGER.info("UWH - {}", uwh);
|
2892 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
| 2930 |
// amount += uwh.getAmount();
|
2893 |
+ customRetailer.getCode() + ")" + "</td>");
|
| 2931 |
// System.out.println("Amount is - " + amount);
|
2894 |
|
| 2932 |
// walletService.rollbackAmountFromWallet(uw.getUserId(), uwh.getAmount(),
|
2895 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 2933 |
// uwh.getReference(), uwh.getReferenceType(), "Margin reversal for error prone
|
2896 |
+ entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
| 2934 |
// run", uwh.getBusinessTimestamp());
|
2897 |
|
| 2935 |
int orderId = uwh.getReference();
|
2898 |
sb.append("</tr>");
|
| 2936 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
2899 |
|
| 2937 |
int inventoryItemId = 0;
|
2900 |
}
|
| 2938 |
// fofoOrderRepository.delete(fofoOrder);
|
2901 |
|
| 2939 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
2902 |
sb.append("</tbody></table></body></html>");
|
| 2940 |
/*
|
2903 |
|
| 2941 |
* List<PaymentOptionTransaction> paymentOptionTransactions =
|
2904 |
return sb.toString();
|
| 2942 |
* paymentOptionTransactionRepository.selectByReferenceIdAndType(fofoOrder.getId
|
2905 |
}
|
| 2943 |
* (), PaymentOptionReferenceType.ORDER); for(PaymentOptionTransaction
|
2906 |
|
| 2944 |
* paymentOptionTransaction : paymentOptionTransactions) {
|
2907 |
public void reverseWallet() throws Exception {
|
| 2945 |
* //paymentOptionTransactionRepository.delete(paymentOptionTransaction); }
|
2908 |
LocalDate localDate = LocalDate.of(2020, 10, 28);
|
| 2946 |
*/
|
2909 |
List<UserWalletHistory> uwhList = userWalletHistoryRepository.selectAllByDateType(localDate.atStartOfDay(),
|
| 2947 |
for (FofoOrderItem foi : fofoOrderItems) {
|
2910 |
localDate.plusDays(1).atStartOfDay(),
|
| 2948 |
// fofoOrderItemRepository.delete(foi);
|
2911 |
Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
| 2949 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(foi.getId());
|
2912 |
for (UserWalletHistory uwh : uwhList) {
|
| 2950 |
for (FofoLineItem fli : flis) {
|
2913 |
if (uwh.getBusinessTimestamp().getMonth().equals(Month.SEPTEMBER)) {
|
| 2951 |
// fofoLineItemRepository.delete(fli);
|
2914 |
UserWallet uw = userWalletRepository.selectById(uwh.getWalletId());
|
| 2952 |
inventoryItemId = fli.getInventoryItemId();
|
2915 |
// LOGGER.info("UWH - {}", uwh);
|
| 2953 |
}
|
2916 |
// amount += uwh.getAmount();
|
| 2954 |
}
|
2917 |
// System.out.println("Amount is - " + amount);
|
| 2955 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(
|
2918 |
// walletService.rollbackAmountFromWallet(uw.getUserId(), uwh.getAmount(),
|
| 2956 |
java.util.stream.Stream.of(inventoryItemId).collect(Collectors.toSet()));
|
2919 |
// uwh.getReference(), uwh.getReferenceType(), "Margin reversal for error prone
|
| 2957 |
for (SchemeInOut sio : schemeInOuts) {
|
2920 |
// run", uwh.getBusinessTimestamp());
|
| 2958 |
if (sio.getCreateTimestamp().toLocalDate().equals(localDate)) {
|
2921 |
int orderId = uwh.getReference();
|
| 2959 |
LOGGER.info("SIO - {}", sio);
|
2922 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
| 2960 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
2923 |
int inventoryItemId = 0;
|
| 2961 |
}
|
2924 |
// fofoOrderRepository.delete(fofoOrder);
|
| 2962 |
}
|
2925 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 2963 |
|
2926 |
/*
|
| 2964 |
}
|
2927 |
* List<PaymentOptionTransaction> paymentOptionTransactions =
|
| 2965 |
}
|
2928 |
* paymentOptionTransactionRepository.selectByReferenceIdAndType(fofoOrder.getId
|
| 2966 |
|
2929 |
* (), PaymentOptionReferenceType.ORDER); for(PaymentOptionTransaction
|
| 2967 |
}
|
2930 |
* paymentOptionTransaction : paymentOptionTransactions) {
|
| 2968 |
|
2931 |
* //paymentOptionTransactionRepository.delete(paymentOptionTransaction); }
|
| 2969 |
public void partnerProblemAlert() throws Exception {
|
2932 |
*/
|
| 2970 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
2933 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 2971 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
2934 |
// fofoOrderItemRepository.delete(foi);
|
| 2972 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
2935 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(foi.getId());
|
| 2973 |
Map<Integer, Double> mtdSales = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1),
|
2936 |
for (FofoLineItem fli : flis) {
|
| 2974 |
curDate.with(LocalTime.MAX), 0, false);
|
2937 |
// fofoLineItemRepository.delete(fli);
|
| 2975 |
Map<Integer, PartnerDailyInvestment> pdi = partnerDailyInvestmentRepository.selectAll(LocalDate.now()).stream()
|
2938 |
inventoryItemId = fli.getInventoryItemId();
|
| 2976 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
2939 |
}
|
| 2977 |
|
2940 |
}
|
| 2978 |
for (Entry<Integer, Double> ls : lmtdSale.entrySet()) {
|
2941 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(
|
| 2979 |
|
2942 |
java.util.stream.Stream.of(inventoryItemId).collect(Collectors.toSet()));
|
| 2980 |
double lmtdTwentyPercentSale = ls.getValue() * 0.2;
|
2943 |
for (SchemeInOut sio : schemeInOuts) {
|
| 2981 |
|
2944 |
if (sio.getCreateTimestamp().toLocalDate().equals(localDate)) {
|
| 2982 |
LOGGER.info("lmtdTwentyPercentSale" + lmtdTwentyPercentSale);
|
2945 |
LOGGER.info("SIO - {}", sio);
|
| 2983 |
|
2946 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| 2984 |
double mtdSale = mtdSales.get(ls.getKey()) == null ? 0 : mtdSales.get(ls.getKey());
|
2947 |
}
|
| 2985 |
|
2948 |
}
|
| 2986 |
LOGGER.info("mtdSale" + mtdSale);
|
2949 |
|
| 2987 |
|
2950 |
}
|
| 2988 |
double totalSixtyPercentInvestment = pdi.get(ls.getKey()) == null ? 0
|
2951 |
}
|
| 2989 |
: pdi.get(ls.getKey()).getTotalInvestment() * 0.6;
|
2952 |
|
| 2990 |
|
2953 |
}
|
| 2991 |
LOGGER.info("totalSixtyPercentInvestment" + totalSixtyPercentInvestment);
|
2954 |
|
| 2992 |
|
2955 |
public void partnerProblemAlert() throws Exception {
|
| 2993 |
double stockInvestment = pdi.get(ls.getKey()) == null ? 0 : pdi.get(ls.getKey()).getInStockAmount();
|
2956 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 2994 |
|
2957 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 2995 |
LOGGER.info("stockInvestment" + stockInvestment);
|
2958 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
| 2996 |
|
2959 |
Map<Integer, Double> mtdSales = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1),
|
| 2997 |
boolean Investmentvalue = partnerInvestmentService.isInvestmentBelow(ls.getKey(), 25);
|
2960 |
curDate.with(LocalTime.MAX), 0, false);
|
| 2998 |
|
2961 |
Map<Integer, PartnerDailyInvestment> pdi = partnerDailyInvestmentRepository.selectAll(LocalDate.now()).stream()
|
| 2999 |
PartnerProblem partnerProblem = partnerProblemRepository.selectByFofoId(ls.getKey());
|
2962 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 3000 |
|
2963 |
|
| 3001 |
if (partnerProblem == null) {
|
2964 |
for (Entry<Integer, Double> ls : lmtdSale.entrySet()) {
|
| 3002 |
partnerProblem = new PartnerProblem();
|
2965 |
|
| 3003 |
partnerProblem.setFofoId(ls.getKey());
|
2966 |
double lmtdTwentyPercentSale = ls.getValue() * 0.2;
|
| 3004 |
if (mtdSale < lmtdTwentyPercentSale) {
|
2967 |
|
| 3005 |
partnerProblem.setMtd(1);
|
2968 |
LOGGER.info("lmtdTwentyPercentSale" + lmtdTwentyPercentSale);
|
| 3006 |
}
|
2969 |
|
| 3007 |
if (Investmentvalue) {
|
2970 |
double mtdSale = mtdSales.get(ls.getKey()) == null ? 0 : mtdSales.get(ls.getKey());
|
| 3008 |
partnerProblem.setInvestment(1);
|
2971 |
|
| 3009 |
}
|
2972 |
LOGGER.info("mtdSale" + mtdSale);
|
| 3010 |
|
2973 |
|
| 3011 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
2974 |
double totalSixtyPercentInvestment = pdi.get(ls.getKey()) == null ? 0
|
| 3012 |
partnerProblem.setInvestment(1);
|
2975 |
: pdi.get(ls.getKey()).getTotalInvestment() * 0.6;
|
| 3013 |
}
|
2976 |
|
| 3014 |
|
2977 |
LOGGER.info("totalSixtyPercentInvestment" + totalSixtyPercentInvestment);
|
| 3015 |
partnerProblemRepository.persist(partnerProblem);
|
2978 |
|
| 3016 |
} else {
|
2979 |
double stockInvestment = pdi.get(ls.getKey()) == null ? 0 : pdi.get(ls.getKey()).getInStockAmount();
|
| 3017 |
if (mtdSale < lmtdTwentyPercentSale) {
|
2980 |
|
| 3018 |
partnerProblem.setMtd(partnerProblem.getMtd() + 1);
|
2981 |
LOGGER.info("stockInvestment" + stockInvestment);
|
| 3019 |
|
2982 |
|
| 3020 |
} else {
|
2983 |
boolean Investmentvalue = partnerInvestmentService.isInvestmentBelow(ls.getKey(), 25);
|
| 3021 |
partnerProblem.setMtd(0);
|
2984 |
|
| 3022 |
|
2985 |
PartnerProblem partnerProblem = partnerProblemRepository.selectByFofoId(ls.getKey());
|
| 3023 |
}
|
2986 |
|
| 3024 |
if (Investmentvalue) {
|
2987 |
if (partnerProblem == null) {
|
| 3025 |
partnerProblem.setInvestment(partnerProblem.getInvestment() + 1);
|
2988 |
partnerProblem = new PartnerProblem();
|
| 3026 |
} else {
|
2989 |
partnerProblem.setFofoId(ls.getKey());
|
| 3027 |
partnerProblem.setInvestment(0);
|
2990 |
if (mtdSale < lmtdTwentyPercentSale) {
|
| 3028 |
|
2991 |
partnerProblem.setMtd(1);
|
| 3029 |
}
|
2992 |
}
|
| 3030 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
2993 |
if (Investmentvalue) {
|
| 3031 |
partnerProblem.setStockInvestment(partnerProblem.getStockInvestment() + 1);
|
2994 |
partnerProblem.setInvestment(1);
|
| 3032 |
} else {
|
2995 |
}
|
| 3033 |
partnerProblem.setStockInvestment(0);
|
2996 |
|
| 3034 |
}
|
2997 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
| 3035 |
|
2998 |
partnerProblem.setInvestment(1);
|
| 3036 |
}
|
2999 |
}
|
| 3037 |
|
3000 |
|
| 3038 |
}
|
3001 |
partnerProblemRepository.persist(partnerProblem);
|
| 3039 |
|
3002 |
} else {
|
| 3040 |
List<PartnerProblem> partnerProblems = partnerProblemRepository.selectAll().stream()
|
3003 |
if (mtdSale < lmtdTwentyPercentSale) {
|
| 3041 |
.filter(x -> x.getMtd() + x.getInvestment() + x.getStockInvestment() > 0).collect(Collectors.toList());
|
3004 |
partnerProblem.setMtd(partnerProblem.getMtd() + 1);
|
| 3042 |
|
3005 |
|
| 3043 |
partnerProblems = partnerProblems.stream().sorted((x1, x2) -> {
|
3006 |
} else {
|
| 3044 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
3007 |
partnerProblem.setMtd(0);
|
| 3045 |
+ x2.getStockInvestment() ? 1 : -1;
|
3008 |
|
| 3046 |
}).collect(Collectors.toList());
|
3009 |
}
|
| 3047 |
|
3010 |
if (Investmentvalue) {
|
| 3048 |
Map<Integer, PartnerProblem> partnerProblemMap = partnerProblems.stream().sorted((x1, x2) -> {
|
3011 |
partnerProblem.setInvestment(partnerProblem.getInvestment() + 1);
|
| 3049 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
3012 |
} else {
|
| 3050 |
+ x2.getStockInvestment() ? 1 : -1;
|
3013 |
partnerProblem.setInvestment(0);
|
| 3051 |
}).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
3014 |
|
| 3052 |
|
3015 |
}
|
| 3053 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailers();
|
3016 |
if (stockInvestment < totalSixtyPercentInvestment) {
|
| 3054 |
|
3017 |
partnerProblem.setStockInvestment(partnerProblem.getStockInvestment() + 1);
|
| 3055 |
List<Integer> assignTo = Arrays.asList(15, 9, 54, 53);
|
3018 |
} else {
|
| 3056 |
|
3019 |
partnerProblem.setStockInvestment(0);
|
| 3057 |
Map<Integer, AuthUser> assignAuthUserMap = authRepository.selectAllAuthUserByIds(assignTo).stream()
|
3020 |
}
|
| 3058 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
3021 |
|
| 3059 |
|
3022 |
}
|
| 3060 |
List<String> sendTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
3023 |
|
| 3061 |
"sm@smartdukaan.com");
|
3024 |
}
|
| 3062 |
LOGGER.info("partnerProblem" + partnerProblems);
|
3025 |
|
| 3063 |
StringBuilder sb = new StringBuilder();
|
3026 |
List<PartnerProblem> partnerProblems = partnerProblemRepository.selectAll().stream()
|
| 3064 |
sb.append("<htl><body>");
|
3027 |
.filter(x -> x.getMtd() + x.getInvestment() + x.getStockInvestment() > 0).collect(Collectors.toList());
|
| 3065 |
sb.append(
|
3028 |
|
| 3066 |
"<p>Number against MTD or Investment are the count of days the MTD is low VS LMTD OR Investment is below 75%.</p><br/><p>These partners needs immediate attention.</p><br/><table style='border:1px solid black';cellspacing=0>");
|
3029 |
partnerProblems = partnerProblems.stream().sorted((x1, x2) -> {
|
| 3067 |
sb.append("<tbody>\n" + " <tr>"
|
3030 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
| 3068 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
3031 |
+ x2.getStockInvestment() ? 1 : -1;
|
| 3069 |
+ " <th style='border:1px solid black;padding: 5px'>Assign TO</th>"
|
3032 |
}).collect(Collectors.toList());
|
| 3070 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
3033 |
|
| 3071 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
3034 |
Map<Integer, PartnerProblem> partnerProblemMap = partnerProblems.stream().sorted((x1, x2) -> {
|
| 3072 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
3035 |
return x1.getMtd() + x1.getInvestment() + x1.getStockInvestment() < x2.getMtd() + x2.getInvestment()
|
| 3073 |
+ " <th style='border:1px solid black;padding: 5px'>Manager</th>"
|
3036 |
+ x2.getStockInvestment() ? 1 : -1;
|
| 3074 |
|
3037 |
}).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 3075 |
+ " </tr>");
|
3038 |
|
| 3076 |
|
3039 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailers();
|
| 3077 |
for (PartnerProblem pp : partnerProblems) {
|
3040 |
|
| 3078 |
int value = pp.getFofoId() % 4;
|
3041 |
List<Integer> assignTo = Arrays.asList(15, 9, 54, 53);
|
| 3079 |
|
3042 |
|
| 3080 |
Map<EscalationType, AuthUser> authUserMap = csService.getAuthUserAndEsclationByPartnerId(pp.getFofoId());
|
3043 |
Map<Integer, AuthUser> assignAuthUserMap = authRepository.selectAllAuthUserByIds(assignTo).stream()
|
| 3081 |
LOGGER.info("authUserMap" + authUserMap);
|
3044 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 3082 |
sb.append("<tr>");
|
3045 |
|
| 3083 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
3046 |
List<String> sendTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 3084 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
3047 |
"sm@smartdukaan.com");
|
| 3085 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
3048 |
LOGGER.info("partnerProblem" + partnerProblems);
|
| 3086 |
+ assignAuthUserMap.get(assignTo.get(value)).getName() + "</td>");
|
3049 |
StringBuilder sb = new StringBuilder();
|
| 3087 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
3050 |
sb.append("<htl><body>");
|
| 3088 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
3051 |
sb.append(
|
| 3089 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getStockInvestment() + "</td>");
|
3052 |
"<p>Number against MTD or Investment are the count of days the MTD is low VS LMTD OR Investment is below 75%.</p><br/><p>These partners needs immediate attention.</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 3090 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
3053 |
sb.append("<tbody>\n" + " <tr>"
|
| 3091 |
+ (authUserMap.get(EscalationType.L1) == null ? "N/A"
|
3054 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
| 3092 |
: authUserMap.get(EscalationType.L1).getFirstName())
|
3055 |
+ " <th style='border:1px solid black;padding: 5px'>Assign TO</th>"
|
| 3093 |
+ " ," + (authUserMap.get(EscalationType.L2) == null ? "N/A"
|
3056 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
| 3094 |
: authUserMap.get(EscalationType.L2).getFirstName())
|
3057 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
| 3095 |
+ "</td>");
|
3058 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
| 3096 |
|
3059 |
+ " <th style='border:1px solid black;padding: 5px'>Manager</th>"
|
| 3097 |
sb.append("</tr>");
|
3060 |
|
| 3098 |
}
|
3061 |
+ " </tr>");
|
| 3099 |
sb.append("</tbody></table><br><br>");
|
3062 |
|
| 3100 |
String subject = "Partner Problem Alert!";
|
3063 |
for (PartnerProblem pp : partnerProblems) {
|
| 3101 |
String[] email = sendTo.toArray(new String[sendTo.size()]);
|
3064 |
int value = pp.getFofoId() % 4;
|
| 3102 |
|
3065 |
|
| 3103 |
this.sendMailHtmlFormat(email, sb.toString(), null, subject);
|
3066 |
Map<EscalationType, AuthUser> authUserMap = csService.getAuthUserAndEsclationByPartnerId(pp.getFofoId());
|
| 3104 |
|
3067 |
LOGGER.info("authUserMap" + authUserMap);
|
| 3105 |
Map<Integer, List<Integer>> authUserPartnerMapping = csService.getAuthUserIdPartnerIdMapping();
|
3068 |
sb.append("<tr>");
|
| 3106 |
|
3069 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 3107 |
for (Entry<Integer, List<Integer>> authUserPartner : authUserPartnerMapping.entrySet()) {
|
3070 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
| 3108 |
AuthUser authUser = authRepository.selectById(authUserPartner.getKey());
|
3071 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 3109 |
for (Integer patnerId : authUserPartner.getValue()) {
|
3072 |
+ assignAuthUserMap.get(assignTo.get(value)).getName() + "</td>");
|
| 3110 |
if (partnerProblemMap.get(patnerId) != null) {
|
3073 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
| 3111 |
|
3074 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
| 3112 |
StringBuilder sbbuilder = new StringBuilder();
|
3075 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + pp.getStockInvestment() + "</td>");
|
| 3113 |
sbbuilder.append("<hml><body>");
|
3076 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 3114 |
sb.append(
|
3077 |
+ (authUserMap.get(EscalationType.L1) == null ? "N/A"
|
| 3115 |
"<p>Number against MTD or Investment are the count of days the MTD is low VS LMTD OR Investment is below 75%.</p><br/><p>These partners needs immediate attention.</p><br/><table style='border:1px solid black';cellspacing=0>");
|
3078 |
: authUserMap.get(EscalationType.L1).getFirstName())
|
| 3116 |
sbbuilder.append("<tbody>\n" + " <tr>"
|
3079 |
+ " ," + (authUserMap.get(EscalationType.L2) == null ? "N/A"
|
| 3117 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
3080 |
: authUserMap.get(EscalationType.L2).getFirstName())
|
| 3118 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
3081 |
+ "</td>");
|
| 3119 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
3082 |
|
| 3120 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
3083 |
sb.append("</tr>");
|
| 3121 |
|
3084 |
}
|
| 3122 |
+ " </tr>");
|
3085 |
sb.append("</tbody></table><br><br>");
|
| 3123 |
|
3086 |
String subject = "Partner Problem Alert!";
|
| 3124 |
for (Integer partnerId : authUserPartner.getValue()) {
|
3087 |
String[] email = sendTo.toArray(new String[sendTo.size()]);
|
| 3125 |
if (partnerProblemMap.get(partnerId) != null) {
|
3088 |
|
| 3126 |
PartnerProblem pp = partnerProblemMap.get(partnerId);
|
3089 |
this.sendMailHtmlFormat(email, sb.toString(), null, subject);
|
| 3127 |
sbbuilder.append("<tr>");
|
3090 |
|
| 3128 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
3091 |
Map<Integer, List<Integer>> authUserPartnerMapping = csService.getAuthUserIdPartnerIdMapping();
|
| 3129 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
3092 |
|
| 3130 |
sbbuilder
|
3093 |
for (Entry<Integer, List<Integer>> authUserPartner : authUserPartnerMapping.entrySet()) {
|
| 3131 |
.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
3094 |
AuthUser authUser = authRepository.selectById(authUserPartner.getKey());
|
| 3132 |
sbbuilder.append(
|
3095 |
for (Integer patnerId : authUserPartner.getValue()) {
|
| 3133 |
"<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
3096 |
if (partnerProblemMap.get(patnerId) != null) {
|
| 3134 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
3097 |
|
| 3135 |
+ pp.getStockInvestment() + "</td>");
|
3098 |
StringBuilder sbbuilder = new StringBuilder();
|
| 3136 |
|
3099 |
sbbuilder.append("<hml><body>");
|
| 3137 |
sbbuilder.append("</tr>");
|
3100 |
sb.append(
|
| 3138 |
}
|
3101 |
"<p>Number against MTD or Investment are the count of days the MTD is low VS LMTD OR Investment is below 75%.</p><br/><p>These partners needs immediate attention.</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 3139 |
|
3102 |
sbbuilder.append("<tbody>\n" + " <tr>"
|
| 3140 |
}
|
3103 |
+ " <th style='border:1px solid black;padding: 5px'>Partner Name</th>"
|
| 3141 |
sbbuilder.append("</tbody></table><br><br>");
|
3104 |
+ " <th style='border:1px solid black;padding: 5px'>Mtd</th>"
|
| 3142 |
|
3105 |
+ " <th style='border:1px solid black;padding: 5px'>Investment</th>"
|
| 3143 |
this.sendMailOfHtmlFormat(authUser.getEmailId(), sbbuilder.toString(), null, subject);
|
3106 |
+ " <th style='border:1px solid black;padding: 5px'>Stock</th>"
|
| 3144 |
break;
|
3107 |
|
| 3145 |
}
|
3108 |
+ " </tr>");
|
| 3146 |
|
3109 |
|
| 3147 |
}
|
3110 |
for (Integer partnerId : authUserPartner.getValue()) {
|
| 3148 |
}
|
3111 |
if (partnerProblemMap.get(partnerId) != null) {
|
| 3149 |
}
|
3112 |
PartnerProblem pp = partnerProblemMap.get(partnerId);
|
| 3150 |
|
3113 |
sbbuilder.append("<tr>");
|
| 3151 |
private void sendMailHtmlFormat(String email[], String body, String cc[], String subject)
|
3114 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
| 3152 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
3115 |
+ customRetailers.get(pp.getFofoId()).getBusinessName() + "</td>");
|
| 3153 |
MimeMessage message = mailSender.createMimeMessage();
|
3116 |
sbbuilder
|
| 3154 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
3117 |
.append("<td style='border:1px solid black;padding: 5px'>" + pp.getMtd() + "</td>");
|
| 3155 |
helper.setSubject(subject);
|
3118 |
sbbuilder.append(
|
| 3156 |
helper.setText(body, true);
|
3119 |
"<td style='border:1px solid black;padding: 5px'>" + pp.getInvestment() + "</td>");
|
| 3157 |
helper.setTo(email);
|
3120 |
sbbuilder.append("<td style='border:1px solid black;padding: 5px'>"
|
| 3158 |
if (cc != null) {
|
3121 |
+ pp.getStockInvestment() + "</td>");
|
| 3159 |
helper.setCc(cc);
|
3122 |
|
| 3160 |
}
|
3123 |
sbbuilder.append("</tr>");
|
| 3161 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
3124 |
}
|
| 3162 |
helper.setFrom(senderAddress);
|
3125 |
|
| 3163 |
mailSender.send(message);
|
3126 |
}
|
| 3164 |
}
|
3127 |
sbbuilder.append("</tbody></table><br><br>");
|
| 3165 |
|
3128 |
|
| 3166 |
@Autowired
|
3129 |
this.sendMailOfHtmlFormat(authUser.getEmailId(), sbbuilder.toString(), null, subject);
|
| 3167 |
WarehouseRepository warehouseRepository;
|
3130 |
break;
|
| 3168 |
|
3131 |
}
|
| 3169 |
public void getVendorWarehouses(int warehouseId) {
|
3132 |
|
| 3170 |
LOGGER.info("Warehouses - {}", warehouseRepository.getVendorWarehouses().get(warehouseId));
|
3133 |
}
|
| 3171 |
|
3134 |
}
|
| 3172 |
}
|
3135 |
}
|
| 3173 |
|
3136 |
|
| 3174 |
public void checkImeiActivation() {
|
3137 |
private void sendMailHtmlFormat(String email[], String body, String cc[], String subject)
|
| 3175 |
|
3138 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 3176 |
try {
|
3139 |
MimeMessage message = mailSender.createMimeMessage();
|
| 3177 |
vivoImeiActivationService.checkImeiActivation();
|
3140 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
| 3178 |
} catch (ProfitMandiBusinessException e) {
|
3141 |
helper.setSubject(subject);
|
| 3179 |
// TODO Auto-generated catch block
|
3142 |
helper.setText(body, true);
|
| 3180 |
e.printStackTrace();
|
3143 |
helper.setTo(email);
|
| 3181 |
} catch (IOException e) {
|
3144 |
if (cc != null) {
|
| 3182 |
// TODO Auto-generated catch block
|
3145 |
helper.setCc(cc);
|
| 3183 |
e.printStackTrace();
|
3146 |
}
|
| 3184 |
} catch (Exception e) {
|
3147 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| 3185 |
// TODO Auto-generated catch block
|
3148 |
helper.setFrom(senderAddress);
|
| 3186 |
e.printStackTrace();
|
3149 |
mailSender.send(message);
|
| 3187 |
}
|
3150 |
}
|
| 3188 |
|
3151 |
|
| 3189 |
}
|
3152 |
@Autowired
|
| 3190 |
|
3153 |
WarehouseRepository warehouseRepository;
|
| 3191 |
public void checkItelImeiActivation(LocalDate date, Integer day) {
|
3154 |
|
| 3192 |
LOGGER.info("Hello - {}", "hhh");
|
3155 |
public void getVendorWarehouses(int warehouseId) {
|
| 3193 |
|
3156 |
LOGGER.info("Warehouses - {}", warehouseRepository.getVendorWarehouses().get(warehouseId));
|
| 3194 |
try {
|
3157 |
|
| 3195 |
itelImeiActivationService.checkItelImeiActivation(date, day);
|
3158 |
}
|
| 3196 |
} catch (ProfitMandiBusinessException e) {
|
3159 |
|
| 3197 |
// TODO Auto-generated catch block
|
3160 |
public void checkImeiActivation() {
|
| 3198 |
e.printStackTrace();
|
3161 |
|
| 3199 |
} catch (IOException e) {
|
3162 |
try {
|
| 3200 |
// TODO Auto-generated catch block
|
3163 |
vivoImeiActivationService.checkImeiActivation();
|
| 3201 |
e.printStackTrace();
|
3164 |
} catch (ProfitMandiBusinessException e) {
|
| 3202 |
} catch (Exception e) {
|
3165 |
// TODO Auto-generated catch block
|
| 3203 |
// TODO Auto-generated catch block
|
3166 |
e.printStackTrace();
|
| 3204 |
e.printStackTrace();
|
3167 |
} catch (IOException e) {
|
| 3205 |
}
|
3168 |
// TODO Auto-generated catch block
|
| 3206 |
|
3169 |
e.printStackTrace();
|
| 3207 |
}
|
3170 |
} catch (Exception e) {
|
| 3208 |
|
3171 |
// TODO Auto-generated catch block
|
| 3209 |
public void selectFinServiceFollowUpDateByCurrDate(LocalDate currentDate)
|
3172 |
e.printStackTrace();
|
| 3210 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
3173 |
}
|
| 3211 |
LOGGER.info("selectfinServiceFollow - {}", "selectfinServiceFollowUpDateByCurrDate");
|
3174 |
|
| 3212 |
|
3175 |
}
|
| 3213 |
serviceConfigService.selectFinServicePartnerfollowUpDateByCurrentDate(currentDate);
|
3176 |
|
| 3214 |
|
3177 |
public void checkItelImeiActivation(LocalDate date, Integer day) {
|
| 3215 |
}
|
3178 |
LOGGER.info("Hello - {}", "hhh");
|
| 3216 |
|
3179 |
|
| 3217 |
public void checkTecnoImeiActivation(LocalDate date, Integer day) {
|
3180 |
try {
|
| 3218 |
LOGGER.info("Hello - {}", "hhh");
|
3181 |
itelImeiActivationService.checkItelImeiActivation(date, day);
|
| 3219 |
|
3182 |
} catch (ProfitMandiBusinessException e) {
|
| 3220 |
try {
|
3183 |
// TODO Auto-generated catch block
|
| 3221 |
tecnoImeiActivation.checkTecnoImeiActivation(date, day);
|
3184 |
e.printStackTrace();
|
| 3222 |
} catch (ProfitMandiBusinessException e) {
|
3185 |
} catch (IOException e) {
|
| 3223 |
// TODO Auto-generated catch block
|
3186 |
// TODO Auto-generated catch block
|
| 3224 |
e.printStackTrace();
|
3187 |
e.printStackTrace();
|
| 3225 |
} catch (IOException e) {
|
3188 |
} catch (Exception e) {
|
| 3226 |
// TODO Auto-generated catch block
|
3189 |
// TODO Auto-generated catch block
|
| 3227 |
e.printStackTrace();
|
3190 |
e.printStackTrace();
|
| 3228 |
} catch (Exception e) {
|
3191 |
}
|
| 3229 |
// TODO Auto-generated catch block
|
3192 |
|
| 3230 |
e.printStackTrace();
|
3193 |
}
|
| 3231 |
}
|
3194 |
|
| 3232 |
|
3195 |
public void selectFinServiceFollowUpDateByCurrDate(LocalDate currentDate)
|
| 3233 |
}
|
3196 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 3234 |
|
3197 |
LOGGER.info("selectfinServiceFollow - {}", "selectfinServiceFollowUpDateByCurrDate");
|
| 3235 |
public void checkCancellationMargin() throws Exception {
|
3198 |
|
| 3236 |
LocalDateTime startDate = LocalDate.of(2021, 4, 1).atStartOfDay();
|
3199 |
serviceConfigService.selectFinServicePartnerfollowUpDateByCurrentDate(currentDate);
|
| 3237 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectCancelledBetweenSaleDate(startDate, LocalDateTime.now());
|
3200 |
|
| 3238 |
LOGGER.info("Total Orders = {}", fofoOrders.size());
|
3201 |
}
|
| 3239 |
for (FofoOrder fofoOrder : fofoOrders) {
|
3202 |
|
| 3240 |
List<UserWalletHistory> history = userWalletHistoryRepository
|
3203 |
public void checkTecnoImeiActivation(LocalDate date, Integer day) {
|
| 3241 |
.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
|
3204 |
LOGGER.info("Hello - {}", "hhh");
|
| 3242 |
history.addAll(userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrder.getId(),
|
3205 |
|
| 3243 |
WalletReferenceType.ACTIVATION_SCHEME));
|
3206 |
try {
|
| 3244 |
int walletSum = history.stream().mapToInt(x -> x.getAmount()).sum();
|
3207 |
tecnoImeiActivation.checkTecnoImeiActivation(date, day);
|
| 3245 |
if (Math.abs(walletSum) > 1) {
|
3208 |
} catch (ProfitMandiBusinessException e) {
|
| 3246 |
// LOGGER.info("Cancelled invoice {}, Order Id = {}, = havent rolledback, Value
|
3209 |
// TODO Auto-generated catch block
|
| 3247 |
// = {}", fofoOrder.getInvoiceNumber(), fofoOrder.getId(), walletSum);
|
3210 |
e.printStackTrace();
|
| 3248 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
3211 |
} catch (IOException e) {
|
| 3249 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(fofoOrderItems.get(0).getId());
|
3212 |
// TODO Auto-generated catch block
|
| 3250 |
FofoLineItem fli = flis.get(0);
|
3213 |
e.printStackTrace();
|
| 3251 |
if (StringUtils.isEmpty(fli.getSerialNumber()))
|
3214 |
} catch (Exception e) {
|
| 3252 |
continue;
|
3215 |
// TODO Auto-generated catch block
|
| 3253 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository
|
3216 |
e.printStackTrace();
|
| 3254 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(fli.getInventoryItemId())));
|
3217 |
}
|
| 3255 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(fli.getInventoryItemId());
|
3218 |
|
| 3256 |
double schemeSum = schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null)
|
3219 |
}
|
| 3257 |
.mapToDouble(x -> x.getAmount()).sum();
|
3220 |
|
| 3258 |
/*
|
3221 |
public void checkCancellationMargin() throws Exception {
|
| 3259 |
* if(inventoryItem.getGoodQuantity()==1) {
|
3222 |
LocalDateTime startDate = LocalDate.of(2021, 4, 1).atStartOfDay();
|
| 3260 |
* LOGGER.info("GoodQty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
3223 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectCancelledBetweenSaleDate(startDate, LocalDateTime.now());
|
| 3261 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
3224 |
LOGGER.info("Total Orders = {}", fofoOrders.size());
|
| 3262 |
* inventoryItem.getUpdateTimestamp()); } else
|
3225 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 3263 |
* if(inventoryItem.getBadQuantity()==1){
|
3226 |
List<UserWalletHistory> history = userWalletHistoryRepository
|
| 3264 |
* LOGGER.info("Bad Qty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
3227 |
.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
|
| 3265 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
3228 |
history.addAll(userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrder.getId(),
|
| 3266 |
* inventoryItem.getUpdateTimestamp()); } else if
|
3229 |
WalletReferenceType.ACTIVATION_SCHEME));
|
| 3267 |
* (inventoryItem.getLastScanType().equals(ScanType.SALE)) { LOGGER.
|
3230 |
int walletSum = history.stream().mapToInt(x -> x.getAmount()).sum();
|
| 3268 |
* info("Problem Sold, Serial Number {}, InventoryItem = {}, Billed on {}",
|
3231 |
if (Math.abs(walletSum) > 1) {
|
| 3269 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
3232 |
// LOGGER.info("Cancelled invoice {}, Order Id = {}, = havent rolledback, Value
|
| 3270 |
* inventoryItem.getUpdateTimestamp()); }
|
3233 |
// = {}", fofoOrder.getInvoiceNumber(), fofoOrder.getId(), walletSum);
|
| 3271 |
*/
|
3234 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 3272 |
if (inventoryItem.getLastScanType().equals(ScanType.SALE)
|
3235 |
List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(fofoOrderItems.get(0).getId());
|
| 3273 |
|| inventoryItem.getLastScanType().equals(ScanType.SALE_RET)) {
|
3236 |
FofoLineItem fli = flis.get(0);
|
| 3274 |
Map<String, Double> map = schemeInOuts.stream()
|
3237 |
if (StringUtils.isEmpty(fli.getSerialNumber()))
|
| 3275 |
.collect(
|
3238 |
continue;
|
| 3276 |
Collectors.groupingBy(
|
3239 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository
|
| 3277 |
x -> DateTimeFormatter.ofPattern("yyyyMMddHH")
|
3240 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(fli.getInventoryItemId())));
|
| 3278 |
.format(x.getCreateTimestamp()) + "- " + x.getSchemeId(),
|
3241 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(fli.getInventoryItemId());
|
| 3279 |
Collectors.summingDouble(x -> x.getAmount())));
|
3242 |
double schemeSum = schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null)
|
| 3280 |
for (Map.Entry<String, Double> entry : map.entrySet()) {
|
3243 |
.mapToDouble(x -> x.getAmount()).sum();
|
| 3281 |
LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
|
3244 |
/*
|
| 3282 |
}
|
3245 |
* if(inventoryItem.getGoodQuantity()==1) {
|
| 3283 |
LOGGER.info("id- {}, imei- {}, lastScan = {}, Scheme sum - {}", inventoryItem.getId(),
|
3246 |
* LOGGER.info("GoodQty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
| 3284 |
inventoryItem.getSerialNumber(), inventoryItem.getLastScanType(), schemeSum);
|
3247 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
| 3285 |
}
|
3248 |
* inventoryItem.getUpdateTimestamp()); } else
|
| 3286 |
}
|
3249 |
* if(inventoryItem.getBadQuantity()==1){
|
| 3287 |
}
|
3250 |
* LOGGER.info("Bad Qty, Serial Number {}, InventoryItem = {}, Billed on {}",
|
| 3288 |
|
3251 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
| 3289 |
}
|
3252 |
* inventoryItem.getUpdateTimestamp()); } else if
|
| 3290 |
|
3253 |
* (inventoryItem.getLastScanType().equals(ScanType.SALE)) { LOGGER.
|
| 3291 |
public static String readFileAsString(String file) throws Exception {
|
3254 |
* info("Problem Sold, Serial Number {}, InventoryItem = {}, Billed on {}",
|
| 3292 |
String data = "";
|
3255 |
* inventoryItem.getSerialNumber(), inventoryItem.getId(),
|
| 3293 |
data = new String(Files.readAllBytes(Paths.get(file)));
|
3256 |
* inventoryItem.getUpdateTimestamp()); }
|
| 3294 |
return data;
|
3257 |
*/
|
| 3295 |
}
|
3258 |
if (inventoryItem.getLastScanType().equals(ScanType.SALE)
|
| 3296 |
|
3259 |
|| inventoryItem.getLastScanType().equals(ScanType.SALE_RET)) {
|
| 3297 |
public void markDelhiveryOrderDelivered() throws ProfitMandiBusinessException, IOException {
|
3260 |
Map<String, Double> map = schemeInOuts.stream()
|
| 3298 |
List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.DELHIVERY_PROVIDERID,
|
3261 |
.collect(
|
| 3299 |
OrderStatus.SHIPPED_FROM_WH);
|
3262 |
Collectors.groupingBy(
|
| 3300 |
|
3263 |
x -> DateTimeFormatter.ofPattern("yyyyMMddHH")
|
| 3301 |
if (!orders.isEmpty()) {
|
3264 |
.format(x.getCreateTimestamp()) + "- " + x.getSchemeId(),
|
| 3302 |
Set<String> airwayBill = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
|
3265 |
Collectors.summingDouble(x -> x.getAmount())));
|
| 3303 |
|
3266 |
for (Map.Entry<String, Double> entry : map.entrySet()) {
|
| 3304 |
int arraylength = airwayBill.size();
|
3267 |
LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
|
| 3305 |
|
3268 |
}
|
| 3306 |
if (arraylength >= 75) {
|
3269 |
LOGGER.info("id- {}, imei- {}, lastScan = {}, Scheme sum - {}", inventoryItem.getId(),
|
| 3307 |
|
3270 |
inventoryItem.getSerialNumber(), inventoryItem.getLastScanType(), schemeSum);
|
| 3308 |
airwayBill = airwayBill.stream().limit(74).collect(Collectors.toSet());
|
3271 |
}
|
| 3309 |
}
|
3272 |
}
|
| 3310 |
LOGGER.info("airwayBill" + airwayBill);
|
3273 |
}
|
| 3311 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
3274 |
|
| 3312 |
|
3275 |
}
|
| 3313 |
OkHttpClient client = new OkHttpClient();
|
3276 |
|
| 3314 |
|
3277 |
public static String readFileAsString(String file) throws Exception {
|
| 3315 |
Request request1 = new Request.Builder()
|
3278 |
String data = "";
|
| 3316 |
.url(url + "?waybill=" + String.join(",", airwayBill) + "&token=" + token).get().build();
|
3279 |
data = new String(Files.readAllBytes(Paths.get(file)));
|
| 3317 |
|
3280 |
return data;
|
| 3318 |
LOGGER.info("request1" + request1);
|
3281 |
}
|
| 3319 |
|
3282 |
|
| 3320 |
Response response = client.newCall(request1).execute();
|
3283 |
public void markDelhiveryOrderDelivered() throws ProfitMandiBusinessException, IOException {
|
| 3321 |
|
3284 |
List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.DELHIVERY_PROVIDERID,
|
| 3322 |
LOGGER.info("jsonbj" + response.body());
|
3285 |
OrderStatus.SHIPPED_FROM_WH);
|
| 3323 |
|
3286 |
|
| 3324 |
JSONObject jsonObj = new JSONObject(response.body().string());
|
3287 |
if (!orders.isEmpty()) {
|
| 3325 |
|
3288 |
Set<String> airwayBill = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
|
| 3326 |
LOGGER.info("jsonObj" + jsonObj);
|
3289 |
|
| 3327 |
|
3290 |
int arraylength = airwayBill.size();
|
| 3328 |
JSONArray shipmentData = jsonObj.getJSONArray("ShipmentData");
|
3291 |
|
| 3329 |
Set<String> airwaybillStatus = new HashSet<>();
|
3292 |
if (arraylength >= 75) {
|
| 3330 |
for (int i = 0; i < shipmentData.length(); i++) {
|
3293 |
|
| 3331 |
JSONObject jsonObject = shipmentData.getJSONObject(i);
|
3294 |
airwayBill = airwayBill.stream().limit(74).collect(Collectors.toSet());
|
| 3332 |
JSONObject shipment = jsonObject.getJSONObject("Shipment");
|
3295 |
}
|
| 3333 |
|
3296 |
LOGGER.info("airwayBill" + airwayBill);
|
| 3334 |
LOGGER.info("shipment" + shipment);
|
3297 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
| 3335 |
JSONObject statusDescription = shipment.getJSONObject("Status");
|
3298 |
|
| 3336 |
String awb = shipment.getString("AWB");
|
3299 |
OkHttpClient client = new OkHttpClient();
|
| 3337 |
|
3300 |
|
| 3338 |
String status = statusDescription.getString("Status");
|
3301 |
Request request1 = new Request.Builder()
|
| 3339 |
LOGGER.info("status" + status);
|
3302 |
.url(url + "?waybill=" + String.join(",", airwayBill) + "&token=" + token).get().build();
|
| 3340 |
|
3303 |
|
| 3341 |
LOGGER.info("awb" + awb);
|
3304 |
LOGGER.info("request1" + request1);
|
| 3342 |
if (status.equals("Delivered")) {
|
3305 |
|
| 3343 |
airwaybillStatus.add(awb);
|
3306 |
Response response = client.newCall(request1).execute();
|
| 3344 |
}
|
3307 |
|
| 3345 |
|
3308 |
LOGGER.info("jsonbj" + response.body());
|
| 3346 |
}
|
3309 |
|
| 3347 |
markOrderDelivered(airwaybillStatus);
|
3310 |
JSONObject jsonObj = new JSONObject(response.body().string());
|
| 3348 |
}
|
3311 |
|
| 3349 |
}
|
3312 |
LOGGER.info("jsonObj" + jsonObj);
|
| 3350 |
|
3313 |
|
| 3351 |
public void markBlueDartOrderDelivered() throws ProfitMandiBusinessException, IOException {
|
3314 |
JSONArray shipmentData = jsonObj.getJSONArray("ShipmentData");
|
| 3352 |
|
3315 |
Set<String> airwaybillStatus = new HashSet<>();
|
| 3353 |
String loginId = "DEL81122";
|
3316 |
for (int i = 0; i < shipmentData.length(); i++) {
|
| 3354 |
|
3317 |
JSONObject jsonObject = shipmentData.getJSONObject(i);
|
| 3355 |
String licencekey = "uhfhlg2jpmnqfhfrlsgzfr1nhu1qfvel";
|
3318 |
JSONObject shipment = jsonObject.getJSONObject("Shipment");
|
| 3356 |
|
3319 |
|
| 3357 |
List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.BLUEDART_PROVIDERID,
|
3320 |
LOGGER.info("shipment" + shipment);
|
| 3358 |
OrderStatus.SHIPPED_FROM_WH);
|
3321 |
JSONObject statusDescription = shipment.getJSONObject("Status");
|
| 3359 |
|
3322 |
String awb = shipment.getString("AWB");
|
| 3360 |
if (!orders.isEmpty()) {
|
3323 |
|
| 3361 |
|
3324 |
String status = statusDescription.getString("Status");
|
| 3362 |
Set<String> airwayBillNo = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
|
3325 |
LOGGER.info("status" + status);
|
| 3363 |
|
3326 |
|
| 3364 |
LOGGER.info("airwayBill" + airwayBillNo);
|
3327 |
LOGGER.info("awb" + awb);
|
| 3365 |
String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
|
3328 |
if (status.equals("Delivered")) {
|
| 3366 |
|
3329 |
airwaybillStatus.add(awb);
|
| 3367 |
String response = restClient.get(url + "&loginid=" + loginId + "&awb=awb&numbers="
|
3330 |
}
|
| 3368 |
+ String.join(",", airwayBillNo) + "&format=xml&lickey=" + licencekey + "&verno=1.3&scan=1", null,
|
3331 |
|
| 3369 |
null);
|
3332 |
}
|
| 3370 |
|
3333 |
markOrderDelivered(airwaybillStatus);
|
| 3371 |
JSONObject updateJson = XML.toJSONObject(response);
|
3334 |
}
|
| 3372 |
|
3335 |
}
|
| 3373 |
JSONObject shipmentData = updateJson.getJSONObject("ShipmentData");
|
3336 |
|
| 3374 |
Object shipmentObject = shipmentData.get("Shipment");
|
3337 |
public void markBlueDartOrderDelivered() throws ProfitMandiBusinessException, IOException {
|
| 3375 |
|
3338 |
|
| 3376 |
Set<String> airwaybillStatus = new HashSet<>();
|
3339 |
String loginId = "DEL81122";
|
| 3377 |
|
3340 |
|
| 3378 |
if (shipmentObject instanceof JSONArray) {
|
3341 |
String licencekey = "uhfhlg2jpmnqfhfrlsgzfr1nhu1qfvel";
|
| 3379 |
JSONArray shipments = (JSONArray) shipmentObject;
|
3342 |
|
| 3380 |
for (int i = 0; i < shipments.length(); i++) {
|
3343 |
List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.BLUEDART_PROVIDERID,
|
| 3381 |
JSONObject jsonObject = shipments.getJSONObject(i);
|
3344 |
OrderStatus.SHIPPED_FROM_WH);
|
| 3382 |
|
3345 |
|
| 3383 |
Number awb = jsonObject.getNumber("WaybillNo");
|
3346 |
if (!orders.isEmpty()) {
|
| 3384 |
String status = jsonObject.getString("Status");
|
3347 |
|
| 3385 |
|
3348 |
Set<String> airwayBillNo = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
|
| 3386 |
if (status.equals("SHIPMENT DELIVERED")) {
|
3349 |
|
| 3387 |
airwaybillStatus.add(awb.toString());
|
3350 |
LOGGER.info("airwayBill" + airwayBillNo);
|
| 3388 |
}
|
3351 |
String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
|
| 3389 |
|
3352 |
|
| 3390 |
}
|
3353 |
String response = restClient.get(url + "&loginid=" + loginId + "&awb=awb&numbers="
|
| 3391 |
} else {
|
3354 |
+ String.join(",", airwayBillNo) + "&format=xml&lickey=" + licencekey + "&verno=1.3&scan=1", null,
|
| 3392 |
JSONObject jsonObject = (JSONObject) shipmentObject;
|
3355 |
null);
|
| 3393 |
Number awb = jsonObject.getNumber("WaybillNo");
|
3356 |
|
| 3394 |
String status = jsonObject.getString("Status");
|
3357 |
JSONObject updateJson = XML.toJSONObject(response);
|
| 3395 |
|
3358 |
|
| 3396 |
if (status.equals("SHIPMENT DELIVERED")) {
|
3359 |
JSONObject shipmentData = updateJson.getJSONObject("ShipmentData");
|
| 3397 |
airwaybillStatus.add(awb.toString());
|
3360 |
Object shipmentObject = shipmentData.get("Shipment");
|
| 3398 |
}
|
3361 |
|
| 3399 |
|
3362 |
Set<String> airwaybillStatus = new HashSet<>();
|
| 3400 |
}
|
3363 |
|
| 3401 |
|
3364 |
if (shipmentObject instanceof JSONArray) {
|
| 3402 |
LOGGER.info("airwaybillStatus" + airwaybillStatus);
|
3365 |
JSONArray shipments = (JSONArray) shipmentObject;
|
| 3403 |
|
3366 |
for (int i = 0; i < shipments.length(); i++) {
|
| 3404 |
markOrderDelivered(airwaybillStatus);
|
3367 |
JSONObject jsonObject = shipments.getJSONObject(i);
|
| 3405 |
}
|
3368 |
|
| 3406 |
|
3369 |
Number awb = jsonObject.getNumber("WaybillNo");
|
| 3407 |
}
|
3370 |
String status = jsonObject.getString("Status");
|
| 3408 |
|
3371 |
|
| 3409 |
private void markOrderDelivered(Set<String> airwaybillStatus)
|
3372 |
if (status.equals("SHIPMENT DELIVERED")) {
|
| 3410 |
throws ProfitMandiBusinessException, HttpHostConnectException {
|
3373 |
airwaybillStatus.add(awb.toString());
|
| 3411 |
if (!airwaybillStatus.isEmpty()) {
|
3374 |
}
|
| 3412 |
for (String aws : airwaybillStatus) {
|
3375 |
|
| 3413 |
|
3376 |
}
|
| 3414 |
List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
|
3377 |
} else {
|
| 3415 |
|
3378 |
JSONObject jsonObject = (JSONObject) shipmentObject;
|
| 3416 |
int fofoId = deliverdOrders.get(0).getRetailerId();
|
3379 |
Number awb = jsonObject.getNumber("WaybillNo");
|
| 3417 |
for (Order dlo : deliverdOrders) {
|
3380 |
String status = jsonObject.getString("Status");
|
| 3418 |
dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
3381 |
|
| 3419 |
dlo.setStatusDescription("Order Delivered");
|
3382 |
if (status.equals("SHIPMENT DELIVERED")) {
|
| 3420 |
dlo.setDeliveryTimestamp(LocalDateTime.now());
|
3383 |
airwaybillStatus.add(awb.toString());
|
| 3421 |
}
|
3384 |
}
|
| 3422 |
|
3385 |
|
| 3423 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
|
3386 |
}
|
| 3424 |
|
3387 |
|
| 3425 |
Address address = addressRepository.selectById(user.getAddressId());
|
3388 |
LOGGER.info("airwaybillStatus" + airwaybillStatus);
|
| 3426 |
|
3389 |
|
| 3427 |
String title = "Order Delivered";
|
3390 |
markOrderDelivered(airwaybillStatus);
|
| 3428 |
|
3391 |
}
|
| 3429 |
String message = String.format("Dear partner, Your SmartDukaan Order " + aws
|
3392 |
|
| 3430 |
+ " has been delivered to you in a safe sealed bag.");
|
3393 |
}
|
| 3431 |
|
3394 |
|
| 3432 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
3395 |
private void markOrderDelivered(Set<String> airwaybillStatus)
|
| 3433 |
sendNotificationModel.setCampaignName("Order Delivered");
|
3396 |
throws ProfitMandiBusinessException, HttpHostConnectException {
|
| 3434 |
sendNotificationModel.setTitle(title);
|
3397 |
if (!airwaybillStatus.isEmpty()) {
|
| 3435 |
sendNotificationModel.setMessage(message);
|
3398 |
for (String aws : airwaybillStatus) {
|
| 3436 |
sendNotificationModel.setType("url");
|
3399 |
|
| 3437 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
3400 |
List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
|
| 3438 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
3401 |
|
| 3439 |
sendNotificationModel.setMessageType(MessageType.notification);
|
3402 |
int fofoId = deliverdOrders.get(0).getRetailerId();
|
| 3440 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
3403 |
for (Order dlo : deliverdOrders) {
|
| 3441 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
3404 |
dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
| 3442 |
notificationService.sendNotification(sendNotificationModel);
|
3405 |
dlo.setStatusDescription("Order Delivered");
|
| 3443 |
|
3406 |
dlo.setDeliveryTimestamp(LocalDateTime.now());
|
| 3444 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
3407 |
}
|
| 3445 |
|
3408 |
|
| 3446 |
}
|
3409 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
|
| 3447 |
}
|
3410 |
|
| 3448 |
}
|
3411 |
Address address = addressRepository.selectById(user.getAddressId());
|
| 3449 |
|
3412 |
|
| 3450 |
public void partnerWiseCreditAccount() throws Exception {
|
3413 |
String title = "Order Delivered";
|
| 3451 |
|
3414 |
|
| 3452 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
3415 |
String message = String.format("Dear partner, Your SmartDukaan Order " + aws
|
| 3453 |
|
3416 |
+ " has been delivered to you in a safe sealed bag.");
|
| 3454 |
for (FofoStore fs : fofoStores) {
|
3417 |
|
| 3455 |
|
3418 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 3456 |
if (fs.getPan() != null) {
|
3419 |
sendNotificationModel.setCampaignName("Order Delivered");
|
| 3457 |
AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
|
3420 |
sendNotificationModel.setTitle(title);
|
| 3458 |
|
3421 |
sendNotificationModel.setMessage(message);
|
| 3459 |
LOGGER.info("accountStatusResponseOut" + accountStatusResponseOut);
|
3422 |
sendNotificationModel.setType("url");
|
| 3460 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(fs.getId(),
|
3423 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 3461 |
Gateway.MANDII);
|
3424 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| 3462 |
|
3425 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 3463 |
if (creditAccount == null) {
|
3426 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| 3464 |
|
3427 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 3465 |
creditAccount = new CreditAccount();
|
3428 |
notificationService.sendNotification(sendNotificationModel);
|
| 3466 |
|
3429 |
|
| 3467 |
creditAccount.setFofoId(fs.getId());
|
3430 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
| 3468 |
creditAccount.setGateway(Gateway.MANDII);
|
3431 |
|
| 3469 |
|
3432 |
}
|
| 3470 |
}
|
3433 |
}
|
| 3471 |
|
3434 |
}
|
| 3472 |
if (accountStatusResponseOut == null) {
|
3435 |
|
| 3473 |
creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
|
3436 |
public void partnerWiseCreditAccount() throws Exception {
|
| 3474 |
creditAccount.setDescription("User company not found");
|
3437 |
|
| 3475 |
|
3438 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 3476 |
} else {
|
3439 |
|
| 3477 |
if (accountStatusResponseOut.getSanctionLimit() != null) {
|
3440 |
for (FofoStore fs : fofoStores) {
|
| 3478 |
creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
|
3441 |
|
| 3479 |
} else {
|
3442 |
if (fs.getPan() != null) {
|
| 3480 |
creditAccount.setSanctionedAmount(0);
|
3443 |
AccountStatusResponseOut accountStatusResponseOut = mandiiService.getStatus(fs.getPan());
|
| 3481 |
}
|
3444 |
|
| 3482 |
|
3445 |
LOGGER.info("accountStatusResponseOut" + accountStatusResponseOut);
|
| 3483 |
creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
|
3446 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(fs.getId(),
|
| 3484 |
if (accountStatusResponseOut.getBalanceAmount() != null) {
|
3447 |
Gateway.MANDII);
|
| 3485 |
creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
|
3448 |
|
| 3486 |
} else {
|
3449 |
if (creditAccount == null) {
|
| 3487 |
creditAccount.setAvailableAmount(0);
|
3450 |
|
| 3488 |
}
|
3451 |
creditAccount = new CreditAccount();
|
| 3489 |
|
3452 |
|
| 3490 |
if (accountStatusResponseOut.getCurrentStage() != null) {
|
3453 |
creditAccount.setFofoId(fs.getId());
|
| 3491 |
creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
|
3454 |
creditAccount.setGateway(Gateway.MANDII);
|
| 3492 |
}
|
3455 |
|
| 3493 |
if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
|
3456 |
}
|
| 3494 |
creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
|
3457 |
|
| 3495 |
} else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
|
3458 |
if (accountStatusResponseOut == null) {
|
| 3496 |
creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
|
3459 |
creditAccount.setCreditStatus(CreditStatus.UNKNOWN);
|
| 3497 |
} else {
|
3460 |
creditAccount.setDescription("User company not found");
|
| 3498 |
|
3461 |
|
| 3499 |
creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
|
3462 |
} else {
|
| 3500 |
}
|
3463 |
if (accountStatusResponseOut.getSanctionLimit() != null) {
|
| 3501 |
}
|
3464 |
creditAccount.setSanctionedAmount(accountStatusResponseOut.getSanctionLimit().floatValue());
|
| 3502 |
|
3465 |
} else {
|
| 3503 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
3466 |
creditAccount.setSanctionedAmount(0);
|
| 3504 |
creditAccountRepository.persist(creditAccount);
|
3467 |
}
|
| 3505 |
}
|
3468 |
|
| 3506 |
}
|
3469 |
creditAccount.setInterestRate(accountStatusResponseOut.getRateOfInterest());
|
| 3507 |
}
|
3470 |
if (accountStatusResponseOut.getBalanceAmount() != null) {
|
| 3508 |
|
3471 |
creditAccount.setAvailableAmount(accountStatusResponseOut.getBalanceAmount().floatValue());
|
| 3509 |
@Autowired
|
3472 |
} else {
|
| 3510 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
3473 |
creditAccount.setAvailableAmount(0);
|
| 3511 |
|
3474 |
}
|
| 3512 |
public void reviewUncontactablePartner()
|
3475 |
|
| 3513 |
throws ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
|
3476 |
if (accountStatusResponseOut.getCurrentStage() != null) {
|
| 3514 |
|
3477 |
creditAccount.setDescription(accountStatusResponseOut.getCurrentStage().toString());
|
| 3515 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
3478 |
}
|
| 3516 |
|
3479 |
if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.SANCTION_AVAILABLE)) {
|
| 3517 |
List<Integer> pcrms = partnerCollectionRemarkRepository
|
3480 |
creditAccount.setCreditStatus(CreditStatus.SANCTIONED);
|
| 3518 |
.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
|
3481 |
} else if (accountStatusResponseOut.getStatus().equals(EligibilityStatusEnum.IN_ELIGIBLE)) {
|
| 3519 |
|
3482 |
creditAccount.setCreditStatus(CreditStatus.INELIGIBLE);
|
| 3520 |
if (!pcrms.isEmpty()) {
|
3483 |
} else {
|
| 3521 |
Map<Integer, PartnerCollectionRemark> partnerCollectionRemarksMap = partnerCollectionRemarkRepository
|
3484 |
|
| 3522 |
.selectByIds(pcrms).stream().filter(x -> x.getRemark().equals(CollectionRemark.NOT_RESPONDING))
|
3485 |
creditAccount.setCreditStatus(CreditStatus.TO_BE_EVALUATED);
|
| 3523 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
3486 |
}
|
| 3524 |
|
3487 |
}
|
| 3525 |
if (!partnerCollectionRemarksMap.isEmpty()) {
|
3488 |
|
| 3526 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping()
|
3489 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
| 3527 |
.entrySet()) {
|
3490 |
creditAccountRepository.persist(creditAccount);
|
| 3528 |
List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
|
3491 |
}
|
| 3529 |
.map(x -> partnerCollectionRemarksMap.get(x)).filter(x -> x != null)
|
3492 |
}
|
| 3530 |
.collect(Collectors.toList());
|
3493 |
}
|
| 3531 |
String subject = "UNCONTACTABLE PARTNERS";
|
3494 |
|
| 3532 |
String messageText = this.getMessageForUncontacblePartner(filteredRows);
|
3495 |
@Autowired
|
| 3533 |
|
3496 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
| 3534 |
MimeMessage message = mailSender.createMimeMessage();
|
3497 |
|
| 3535 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
3498 |
public void reviewUncontactablePartner()
|
| 3536 |
String[] email = new String[] { storeGuyEntry.getKey() };
|
3499 |
throws ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
|
| 3537 |
|
3500 |
|
| 3538 |
helper.setSubject(subject);
|
3501 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
| 3539 |
helper.setText(messageText, true);
|
3502 |
|
| 3540 |
helper.setTo(email);
|
3503 |
List<Integer> pcrms = partnerCollectionRemarkRepository
|
| 3541 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com",
|
3504 |
.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
|
| 3542 |
"Smartdukaan Alerts");
|
3505 |
|
| 3543 |
helper.setFrom(senderAddress);
|
3506 |
if (!pcrms.isEmpty()) {
|
| 3544 |
mailSender.send(message);
|
3507 |
Map<Integer, PartnerCollectionRemark> partnerCollectionRemarksMap = partnerCollectionRemarkRepository
|
| 3545 |
|
3508 |
.selectByIds(pcrms).stream().filter(x -> x.getRemark().equals(CollectionRemark.NOT_RESPONDING))
|
| 3546 |
LOGGER.info("filteredRows {}", filteredRows);
|
3509 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 3547 |
|
3510 |
|
| 3548 |
}
|
3511 |
if (!partnerCollectionRemarksMap.isEmpty()) {
|
| 3549 |
}
|
3512 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping()
|
| 3550 |
|
3513 |
.entrySet()) {
|
| 3551 |
}
|
3514 |
List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
|
| 3552 |
}
|
3515 |
.map(x -> partnerCollectionRemarksMap.get(x)).filter(x -> x != null)
|
| 3553 |
|
3516 |
.collect(Collectors.toList());
|
| 3554 |
@Autowired
|
3517 |
String subject = "UNCONTACTABLE PARTNERS";
|
| 3555 |
private LoanRepository loanRepository;
|
3518 |
String messageText = this.getMessageForUncontacblePartner(filteredRows);
|
| 3556 |
|
3519 |
|
| 3557 |
@Autowired
|
3520 |
MimeMessage message = mailSender.createMimeMessage();
|
| 3558 |
private LoanStatementRepository loanStatementRepository;
|
3521 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 3559 |
|
3522 |
String[] email = new String[]{storeGuyEntry.getKey()};
|
| 3560 |
@Autowired
|
3523 |
|
| 3561 |
private SDCreditService sdCreditService;
|
3524 |
helper.setSubject(subject);
|
| 3562 |
|
3525 |
helper.setText(messageText, true);
|
| 3563 |
@Autowired
|
3526 |
helper.setTo(email);
|
| 3564 |
private SDCreditRequirementRepository sdCreditRequirementRepository;
|
3527 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com",
|
| 3565 |
|
3528 |
"Smartdukaan Alerts");
|
| 3566 |
@Autowired
|
3529 |
helper.setFrom(senderAddress);
|
| 3567 |
private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
|
3530 |
mailSender.send(message);
|
| 3568 |
|
3531 |
|
| 3569 |
@Autowired
|
3532 |
LOGGER.info("filteredRows {}", filteredRows);
|
| 3570 |
private TransactionRepository transactionRepository;
|
3533 |
|
| 3571 |
|
3534 |
}
|
| 3572 |
@Autowired
|
3535 |
}
|
| 3573 |
private SanctionRequestRepository sanctionRequestRepository;
|
3536 |
|
| 3574 |
|
3537 |
}
|
| 3575 |
public void calculateInterestAccured() throws ProfitMandiBusinessException {
|
3538 |
}
|
| 3576 |
|
3539 |
|
| 3577 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
3540 |
@Autowired
|
| 3578 |
|
3541 |
private LoanRepository loanRepository;
|
| 3579 |
if (!loans.isEmpty()) {
|
3542 |
|
| 3580 |
|
3543 |
@Autowired
|
| 3581 |
for (Loan loan : loans) {
|
3544 |
private LoanStatementRepository loanStatementRepository;
|
| 3582 |
|
3545 |
|
| 3583 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
3546 |
@Autowired
|
| 3584 |
|
3547 |
private SDCreditService sdCreditService;
|
| 3585 |
Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream().collect(Collectors.groupingBy(
|
3548 |
|
| 3586 |
x -> x.getLoanReferenceType(), Collectors.summingDouble(x -> x.getAmount().doubleValue())));
|
3549 |
@Autowired
|
| 3587 |
|
3550 |
private SDCreditRequirementRepository sdCreditRequirementRepository;
|
| 3588 |
if (loan.getFreeDays() > 0) {
|
3551 |
|
| 3589 |
LocalDateTime freeDaysLimitDate = loan.getCreatedOn().plusDays(loan.getFreeDays() - 1);
|
3552 |
@Autowired
|
| 3590 |
|
3553 |
private CurrentPartnerDailyInvestmentRepository currentPartnerDailyInvestmentRepository;
|
| 3591 |
LOGGER.info("freeDaysLimitDate {}", freeDaysLimitDate);
|
3554 |
|
| 3592 |
if (LocalDateTime.now().isAfter(freeDaysLimitDate)) {
|
3555 |
@Autowired
|
| 3593 |
int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
|
3556 |
private TransactionRepository transactionRepository;
|
| 3594 |
loan.getId());
|
3557 |
|
| 3595 |
LOGGER.info("loanStatementId {}", loanStatementId);
|
3558 |
@Autowired
|
| 3596 |
|
3559 |
private SanctionRequestRepository sanctionRequestRepository;
|
| 3597 |
if (loanStatementId != 0) {
|
3560 |
|
| 3598 |
|
3561 |
public void calculateInterestAccured() throws ProfitMandiBusinessException {
|
| 3599 |
this.calculateInterest(loan, loanStatusAmount, loanStatementId);
|
3562 |
|
| 3600 |
|
3563 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
| 3601 |
} else {
|
3564 |
|
| 3602 |
sdCreditService.addInterest(freeDaysLimitDate.toLocalDate(), LocalDate.now(), loan,
|
3565 |
if (!loans.isEmpty()) {
|
| 3603 |
loanStatusAmount);
|
3566 |
|
| 3604 |
}
|
3567 |
for (Loan loan : loans) {
|
| 3605 |
|
3568 |
|
| 3606 |
}
|
3569 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
| 3607 |
} else {
|
3570 |
|
| 3608 |
|
3571 |
Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream().collect(Collectors.groupingBy(
|
| 3609 |
int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
|
3572 |
x -> x.getLoanReferenceType(), Collectors.summingDouble(x -> x.getAmount().doubleValue())));
|
| 3610 |
loan.getId());
|
3573 |
|
| 3611 |
LOGGER.info("loanStatementId2 {}", loanStatementId);
|
3574 |
if (loan.getFreeDays() > 0) {
|
| 3612 |
|
3575 |
LocalDateTime freeDaysLimitDate = loan.getCreatedOn().plusDays(loan.getFreeDays() - 1);
|
| 3613 |
this.calculateInterest(loan, loanStatusAmount, loanStatementId);
|
3576 |
|
| 3614 |
|
3577 |
LOGGER.info("freeDaysLimitDate {}", freeDaysLimitDate);
|
| 3615 |
}
|
3578 |
if (LocalDateTime.now().isAfter(freeDaysLimitDate)) {
|
| 3616 |
|
3579 |
int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
|
| 3617 |
}
|
3580 |
loan.getId());
|
| 3618 |
}
|
3581 |
LOGGER.info("loanStatementId {}", loanStatementId);
|
| 3619 |
|
3582 |
|
| 3620 |
}
|
3583 |
if (loanStatementId != 0) {
|
| 3621 |
|
3584 |
|
| 3622 |
@Autowired
|
3585 |
this.calculateInterest(loan, loanStatusAmount, loanStatementId);
|
| 3623 |
FofoPaymentRepository fofoPaymentRepository;
|
3586 |
|
| 3624 |
|
3587 |
} else {
|
| 3625 |
@Autowired
|
3588 |
sdCreditService.addInterest(freeDaysLimitDate.toLocalDate(), LocalDate.now(), loan,
|
| 3626 |
CCAvenuePaymentService ccAvenuePaymentService;
|
3589 |
loanStatusAmount);
|
| 3627 |
|
3590 |
}
|
| 3628 |
public void settleCCAvePayments() throws Exception {
|
3591 |
|
| 3629 |
List<FofoPayment> fofoPayments = fofoPaymentRepository
|
3592 |
}
|
| 3630 |
.selectAllByGatewayStatus(Gateway.CCAVENUE, PaymentStatus.INIT).stream()
|
3593 |
} else {
|
| 3631 |
.filter(x -> x.getCreateTimestamp().isBefore(LocalDateTime.now().minusMinutes(30l)))
|
3594 |
|
| 3632 |
.collect(Collectors.toList());
|
3595 |
int loanStatementId = loanStatementRepository.selectLatestLoanSatement(loan.getFofoId(),
|
| 3633 |
for (FofoPayment fofoPayment : fofoPayments) {
|
3596 |
loan.getId());
|
| 3634 |
ccAvenuePaymentService.updatePayment(fofoPayment);
|
3597 |
LOGGER.info("loanStatementId2 {}", loanStatementId);
|
| 3635 |
}
|
3598 |
|
| 3636 |
}
|
3599 |
this.calculateInterest(loan, loanStatusAmount, loanStatementId);
|
| 3637 |
|
3600 |
|
| 3638 |
/*
|
3601 |
}
|
| 3639 |
* public void getCCAvenuePendingOrderStatus(int pendingOrderId) { PendingOrder
|
3602 |
|
| 3640 |
* pendingOrder = pendingOrderRepository.selectById(pendingOrderId);
|
3603 |
}
|
| 3641 |
* ccAvenuePaymentService.getPaymentStatusMap(pendingOrder); }
|
3604 |
}
|
| 3642 |
*/
|
3605 |
|
| 3643 |
|
3606 |
}
|
| 3644 |
private void calculateInterest(Loan loan, Map<LoanReferenceType, Double> loanStatusAmount, int loanStatementId)
|
3607 |
|
| 3645 |
throws ProfitMandiBusinessException {
|
3608 |
@Autowired
|
| 3646 |
LoanStatement loanStatement = loanStatementRepository.selectById(loanStatementId);
|
3609 |
FofoPaymentRepository fofoPaymentRepository;
|
| 3647 |
|
3610 |
|
| 3648 |
if (loanStatement.getLoanId() == loan.getId()) {
|
3611 |
@Autowired
|
| 3649 |
|
3612 |
CCAvenuePaymentService ccAvenuePaymentService;
|
| 3650 |
sdCreditService.addInterest(loanStatement.getCreatedAt().toLocalDate(), LocalDate.now(), loan,
|
3613 |
|
| 3651 |
loanStatusAmount);
|
3614 |
public void settleCCAvePayments() throws Exception {
|
| 3652 |
|
3615 |
List<FofoPayment> fofoPayments = fofoPaymentRepository
|
| 3653 |
} else {
|
3616 |
.selectAllByGatewayStatus(Gateway.CCAVENUE, PaymentStatus.INIT).stream()
|
| 3654 |
throw new ProfitMandiBusinessException("loanstament", loanStatement.getLoanId(), "Invalid LoanId");
|
3617 |
.filter(x -> x.getCreateTimestamp().isBefore(LocalDateTime.now().minusMinutes(30l)))
|
| 3655 |
}
|
3618 |
.collect(Collectors.toList());
|
| 3656 |
}
|
3619 |
for (FofoPayment fofoPayment : fofoPayments) {
|
| 3657 |
|
3620 |
ccAvenuePaymentService.updatePayment(fofoPayment);
|
| 3658 |
public void loanSettlement() throws Exception {
|
3621 |
}
|
| 3659 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
3622 |
}
|
| 3660 |
|
3623 |
|
| 3661 |
if (!loans.isEmpty()) {
|
3624 |
/*
|
| 3662 |
|
3625 |
* public void getCCAvenuePendingOrderStatus(int pendingOrderId) { PendingOrder
|
| 3663 |
for (Loan loan : loans) {
|
3626 |
* pendingOrder = pendingOrderRepository.selectById(pendingOrderId);
|
| 3664 |
|
3627 |
* ccAvenuePaymentService.getPaymentStatusMap(pendingOrder); }
|
| 3665 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(loan.getFofoId());
|
3628 |
*/
|
| 3666 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository
|
3629 |
|
| 3667 |
.selectByFofoId(loan.getFofoId());
|
3630 |
private void calculateInterest(Loan loan, Map<LoanReferenceType, Double> loanStatusAmount, int loanStatementId)
|
| 3668 |
|
3631 |
throws ProfitMandiBusinessException {
|
| 3669 |
if (userWallet.getAmount() >= 100) {
|
3632 |
LoanStatement loanStatement = loanStatementRepository.selectById(loanStatementId);
|
| 3670 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
3633 |
|
| 3671 |
|
3634 |
if (loanStatement.getLoanId() == loan.getId()) {
|
| 3672 |
LOGGER.info("loanStatements {}", loanStatements);
|
3635 |
|
| 3673 |
|
3636 |
sdCreditService.addInterest(loanStatement.getCreatedAt().toLocalDate(), LocalDate.now(), loan,
|
| 3674 |
Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream()
|
3637 |
loanStatusAmount);
|
| 3675 |
.collect(Collectors.groupingBy(x -> x.getLoanReferenceType(),
|
3638 |
|
| 3676 |
Collectors.summingDouble(x -> FormattingUtils.serialize(x.getAmount()))));
|
3639 |
} else {
|
| 3677 |
|
3640 |
throw new ProfitMandiBusinessException("loanstament", loanStatement.getLoanId(), "Invalid LoanId");
|
| 3678 |
LOGGER.info("loanStatusAmount {}", loanStatusAmount);
|
3641 |
}
|
| 3679 |
Double interestAmount = loanStatusAmount.get(LoanReferenceType.INTEREST);
|
3642 |
}
|
| 3680 |
|
3643 |
|
| 3681 |
if (interestAmount == null) {
|
3644 |
public void loanSettlement() throws Exception {
|
| 3682 |
interestAmount = (double) 0;
|
3645 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
| 3683 |
}
|
3646 |
|
| 3684 |
|
3647 |
if (!loans.isEmpty()) {
|
| 3685 |
double principalAmount = loanStatusAmount.get(LoanReferenceType.PRINCIPAL);
|
3648 |
|
| 3686 |
double paidAmount = 0;
|
3649 |
for (Loan loan : loans) {
|
| 3687 |
if (userWallet.getAmount() > Math.abs(interestAmount)) {
|
3650 |
|
| 3688 |
|
3651 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(loan.getFofoId());
|
| 3689 |
LOGGER.info("interestAmount b {}", interestAmount);
|
3652 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository
|
| 3690 |
|
3653 |
.selectByFofoId(loan.getFofoId());
|
| 3691 |
if (interestAmount < 0) {
|
3654 |
|
| 3692 |
LOGGER.info("interestAmount a {}", interestAmount);
|
3655 |
if (userWallet.getAmount() >= 100) {
|
| 3693 |
|
3656 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
| 3694 |
settledLoanStatement(LoanReferenceType.INTEREST, BigDecimal.valueOf(interestAmount),
|
3657 |
|
| 3695 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
3658 |
LOGGER.info("loanStatements {}", loanStatements);
|
| 3696 |
LocalDateTime.now());
|
3659 |
|
| 3697 |
loan.setInterestPaid(loan.getInterestPaid().add(BigDecimal.valueOf(interestAmount).abs()));
|
3660 |
Map<LoanReferenceType, Double> loanStatusAmount = loanStatements.stream()
|
| 3698 |
|
3661 |
.collect(Collectors.groupingBy(x -> x.getLoanReferenceType(),
|
| 3699 |
paidAmount += Math.abs(interestAmount);
|
3662 |
Collectors.summingDouble(x -> FormattingUtils.serialize(x.getAmount()))));
|
| 3700 |
}
|
3663 |
|
| 3701 |
|
3664 |
LOGGER.info("loanStatusAmount {}", loanStatusAmount);
|
| 3702 |
double userWalletAmount = userWallet.getAmount() - Math.abs(interestAmount);
|
3665 |
Double interestAmount = loanStatusAmount.get(LoanReferenceType.INTEREST);
|
| 3703 |
|
3666 |
|
| 3704 |
if (userWalletAmount > Math.abs(principalAmount) && principalAmount < 0) {
|
3667 |
if (interestAmount == null) {
|
| 3705 |
|
3668 |
interestAmount = (double) 0;
|
| 3706 |
settledLoanStatement(LoanReferenceType.PRINCIPAL, BigDecimal.valueOf(principalAmount),
|
3669 |
}
|
| 3707 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
3670 |
|
| 3708 |
LocalDateTime.now());
|
3671 |
double principalAmount = loanStatusAmount.get(LoanReferenceType.PRINCIPAL);
|
| 3709 |
double amount = userWalletAmount - Math.abs(principalAmount);
|
3672 |
double paidAmount = 0;
|
| 3710 |
|
3673 |
if (userWallet.getAmount() > Math.abs(interestAmount)) {
|
| 3711 |
paidAmount += Math.abs(principalAmount);
|
3674 |
|
| 3712 |
|
3675 |
LOGGER.info("interestAmount b {}", interestAmount);
|
| 3713 |
userWallet.setAmount((int) amount);
|
3676 |
|
| 3714 |
|
3677 |
if (interestAmount < 0) {
|
| 3715 |
BigDecimal utilizationAmount = sdCreditRequirement.getUtilizedAmount()
|
3678 |
LOGGER.info("interestAmount a {}", interestAmount);
|
| 3716 |
.subtract(BigDecimal.valueOf(principalAmount).abs());
|
3679 |
|
| 3717 |
|
3680 |
settledLoanStatement(LoanReferenceType.INTEREST, BigDecimal.valueOf(interestAmount),
|
| 3718 |
sdCreditRequirement.setUtilizedAmount(utilizationAmount);
|
3681 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
| 3719 |
|
3682 |
LocalDateTime.now());
|
| 3720 |
CreditAccount creditAccount = creditAccountRepository
|
3683 |
loan.setInterestPaid(loan.getInterestPaid().add(BigDecimal.valueOf(interestAmount).abs()));
|
| 3721 |
.selectByFofoIdAndGateway(loan.getFofoId(), Gateway.SDDIRECT);
|
3684 |
|
| 3722 |
|
3685 |
paidAmount += Math.abs(interestAmount);
|
| 3723 |
creditAccount.setAvailableAmount(sdCreditRequirement.getAvailableLimit().floatValue());
|
3686 |
}
|
| 3724 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
3687 |
|
| 3725 |
|
3688 |
double userWalletAmount = userWallet.getAmount() - Math.abs(interestAmount);
|
| 3726 |
loan.setPendingAmount(BigDecimal.ZERO);
|
3689 |
|
| 3727 |
|
3690 |
if (userWalletAmount > Math.abs(principalAmount) && principalAmount < 0) {
|
| 3728 |
} else if (principalAmount < 0) {
|
3691 |
|
| 3729 |
|
3692 |
settledLoanStatement(LoanReferenceType.PRINCIPAL, BigDecimal.valueOf(principalAmount),
|
| 3730 |
settledLoanStatement(LoanReferenceType.PRINCIPAL, BigDecimal.valueOf(userWalletAmount),
|
3693 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
| 3731 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
3694 |
LocalDateTime.now());
|
| 3732 |
LocalDateTime.now());
|
3695 |
double amount = userWalletAmount - Math.abs(principalAmount);
|
| 3733 |
|
3696 |
|
| 3734 |
paidAmount += Math.abs(userWalletAmount);
|
3697 |
paidAmount += Math.abs(principalAmount);
|
| 3735 |
|
3698 |
|
| 3736 |
BigDecimal availableLimit = sdCreditRequirement.getAvailableLimit()
|
3699 |
userWallet.setAmount((int) amount);
|
| 3737 |
.add(BigDecimal.valueOf(userWalletAmount)).abs();
|
3700 |
|
| 3738 |
|
3701 |
BigDecimal utilizationAmount = sdCreditRequirement.getUtilizedAmount()
|
| 3739 |
BigDecimal utilizationAmount = sdCreditRequirement.getUtilizedAmount()
|
3702 |
.subtract(BigDecimal.valueOf(principalAmount).abs());
|
| 3740 |
.subtract(BigDecimal.valueOf(userWalletAmount)).abs();
|
3703 |
|
| 3741 |
|
3704 |
sdCreditRequirement.setUtilizedAmount(utilizationAmount);
|
| 3742 |
sdCreditRequirement.setUtilizedAmount(utilizationAmount);
|
3705 |
|
| 3743 |
|
3706 |
CreditAccount creditAccount = creditAccountRepository
|
| 3744 |
CreditAccount creditAccount = creditAccountRepository
|
3707 |
.selectByFofoIdAndGateway(loan.getFofoId(), Gateway.SDDIRECT);
|
| 3745 |
.selectByFofoIdAndGateway(loan.getFofoId(), Gateway.SDDIRECT);
|
3708 |
|
| 3746 |
|
3709 |
creditAccount.setAvailableAmount(sdCreditRequirement.getAvailableLimit().floatValue());
|
| 3747 |
creditAccount.setAvailableAmount(sdCreditRequirement.getAvailableLimit().floatValue());
|
3710 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
| 3748 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
3711 |
|
| 3749 |
userWallet.setAmount(0);
|
3712 |
loan.setPendingAmount(BigDecimal.ZERO);
|
| 3750 |
|
3713 |
|
| 3751 |
loan.setPendingAmount(
|
3714 |
} else if (principalAmount < 0) {
|
| 3752 |
loan.getPendingAmount().subtract(BigDecimal.valueOf(userWalletAmount)));
|
3715 |
|
| 3753 |
|
3716 |
settledLoanStatement(LoanReferenceType.PRINCIPAL, BigDecimal.valueOf(userWalletAmount),
|
| 3754 |
}
|
3717 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan",
|
| 3755 |
|
3718 |
LocalDateTime.now());
|
| 3756 |
createUserWalletHistory(userWallet.getId(), userWallet.getUserId(),
|
3719 |
|
| 3757 |
WalletReferenceType.LOAN_REPAYMENT, loan.getId(), Math.abs(paidAmount));
|
3720 |
paidAmount += Math.abs(userWalletAmount);
|
| 3758 |
|
3721 |
|
| 3759 |
} else {
|
3722 |
BigDecimal availableLimit = sdCreditRequirement.getAvailableLimit()
|
| 3760 |
|
3723 |
.add(BigDecimal.valueOf(userWalletAmount)).abs();
|
| 3761 |
settledLoanStatement(LoanReferenceType.INTEREST, BigDecimal.valueOf(userWallet.getAmount()),
|
3724 |
|
| 3762 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan", LocalDateTime.now());
|
3725 |
BigDecimal utilizationAmount = sdCreditRequirement.getUtilizedAmount()
|
| 3763 |
|
3726 |
.subtract(BigDecimal.valueOf(userWalletAmount)).abs();
|
| 3764 |
paidAmount += Math.abs(userWallet.getAmount());
|
3727 |
|
| 3765 |
|
3728 |
sdCreditRequirement.setUtilizedAmount(utilizationAmount);
|
| 3766 |
createUserWalletHistory(userWallet.getId(), userWallet.getUserId(),
|
3729 |
|
| 3767 |
WalletReferenceType.LOAN_REPAYMENT, loan.getId(), Math.abs(paidAmount));
|
3730 |
CreditAccount creditAccount = creditAccountRepository
|
| 3768 |
|
3731 |
.selectByFofoIdAndGateway(loan.getFofoId(), Gateway.SDDIRECT);
|
| 3769 |
loan.setInterestPaid(
|
3732 |
|
| 3770 |
loan.getInterestPaid().add(BigDecimal.valueOf(userWallet.getAmount()).abs()));
|
3733 |
creditAccount.setAvailableAmount(sdCreditRequirement.getAvailableLimit().floatValue());
|
| 3771 |
|
3734 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
| 3772 |
userWallet.setAmount(0);
|
3735 |
userWallet.setAmount(0);
|
| 3773 |
}
|
3736 |
|
| 3774 |
|
3737 |
loan.setPendingAmount(
|
| 3775 |
}
|
3738 |
loan.getPendingAmount().subtract(BigDecimal.valueOf(userWalletAmount)));
|
| 3776 |
}
|
3739 |
|
| 3777 |
|
3740 |
}
|
| 3778 |
List<Order> allOrders = orderRepository.selectHoldOrder();
|
3741 |
|
| 3779 |
|
3742 |
createUserWalletHistory(userWallet.getId(), userWallet.getUserId(),
|
| 3780 |
LOGGER.info("allOrders {}", allOrders);
|
3743 |
WalletReferenceType.LOAN_REPAYMENT, loan.getId(), Math.abs(paidAmount));
|
| 3781 |
|
3744 |
|
| 3782 |
if (!allOrders.isEmpty()) {
|
3745 |
} else {
|
| 3783 |
Map<Integer, List<Order>> transactionOrdersMap = allOrders.stream()
|
3746 |
|
| 3784 |
.collect(Collectors.groupingBy(Order::getTransactionId, Collectors.toList()));
|
3747 |
settledLoanStatement(LoanReferenceType.INTEREST, BigDecimal.valueOf(userWallet.getAmount()),
|
| 3785 |
LinkedHashMap<Integer, List<Order>> sortedTransactionOrdersMap = new LinkedHashMap<>();
|
3748 |
loan.getFofoId(), loan.getId(), "Amount adjusted against loan", LocalDateTime.now());
|
| 3786 |
transactionOrdersMap.entrySet().stream().sorted(Map.Entry.comparingByKey())
|
3749 |
|
| 3787 |
.forEachOrdered(x -> sortedTransactionOrdersMap.put(x.getKey(), x.getValue()));
|
3750 |
paidAmount += Math.abs(userWallet.getAmount());
|
| 3788 |
LOGGER.info("sortedTransactionOrdersMap {}", sortedTransactionOrdersMap);
|
3751 |
|
| 3789 |
|
3752 |
createUserWalletHistory(userWallet.getId(), userWallet.getUserId(),
|
| 3790 |
for (Entry<Integer, List<Order>> transactionOrdersEntry : sortedTransactionOrdersMap.entrySet()) {
|
3753 |
WalletReferenceType.LOAN_REPAYMENT, loan.getId(), Math.abs(paidAmount));
|
| 3791 |
|
3754 |
|
| 3792 |
List<Order> orders = transactionOrdersEntry.getValue();
|
3755 |
loan.setInterestPaid(
|
| 3793 |
|
3756 |
loan.getInterestPaid().add(BigDecimal.valueOf(userWallet.getAmount()).abs()));
|
| 3794 |
double totalAmount = orders.stream().collect(Collectors.summingDouble(x -> x.getTotalAmount()));
|
3757 |
|
| 3795 |
|
3758 |
userWallet.setAmount(0);
|
| 3796 |
LocalDateTime createDate = orders.get(0).getCreateTimestamp();
|
3759 |
}
|
| 3797 |
|
3760 |
|
| 3798 |
int fofoId = orders.get(0).getRetailerId();
|
3761 |
}
|
| 3799 |
|
3762 |
}
|
| 3800 |
int transactionId = transactionOrdersEntry.getKey();
|
3763 |
|
| 3801 |
|
3764 |
List<Order> allOrders = orderRepository.selectHoldOrder();
|
| 3802 |
SanctionRequest sanctionRequest = sanctionRequestRepository.selectByTransactionId(transactionId);
|
3765 |
|
| 3803 |
|
3766 |
LOGGER.info("allOrders {}", allOrders);
|
| 3804 |
double loanSettleAmount = loanStatementRepository.selectByDateAndFofoId(createDate, fofoId).stream()
|
3767 |
|
| 3805 |
.filter(x -> x.getAmount().doubleValue() > 0)
|
3768 |
if (!allOrders.isEmpty()) {
|
| 3806 |
.collect(Collectors.summingDouble(x -> x.getAmount().doubleValue()));
|
3769 |
Map<Integer, List<Order>> transactionOrdersMap = allOrders.stream()
|
| 3807 |
|
3770 |
.collect(Collectors.groupingBy(Order::getTransactionId, Collectors.toList()));
|
| 3808 |
LOGGER.info("loanSettleAmount {}", loanSettleAmount);
|
3771 |
LinkedHashMap<Integer, List<Order>> sortedTransactionOrdersMap = new LinkedHashMap<>();
|
| 3809 |
|
3772 |
transactionOrdersMap.entrySet().stream().sorted(Map.Entry.comparingByKey())
|
| 3810 |
LOGGER.info("totalAmount {}", totalAmount);
|
3773 |
.forEachOrdered(x -> sortedTransactionOrdersMap.put(x.getKey(), x.getValue()));
|
| 3811 |
if (loanSettleAmount >= sanctionRequest.getUtilizationAmount().doubleValue()) {
|
3774 |
LOGGER.info("sortedTransactionOrdersMap {}", sortedTransactionOrdersMap);
|
| 3812 |
|
3775 |
|
| 3813 |
LOGGER.info("totalAmount {}", totalAmount);
|
3776 |
for (Entry<Integer, List<Order>> transactionOrdersEntry : sortedTransactionOrdersMap.entrySet()) {
|
| 3814 |
|
3777 |
|
| 3815 |
orders.forEach(x -> x.setShipmentHold(false));
|
3778 |
List<Order> orders = transactionOrdersEntry.getValue();
|
| 3816 |
|
3779 |
|
| 3817 |
List<String> authUserEmail = csService.getAuthUserIdByPartnerId(orders.get(0).getRetailerId())
|
3780 |
double totalAmount = orders.stream().collect(Collectors.summingDouble(x -> x.getTotalAmount()));
|
| 3818 |
.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
3781 |
|
| 3819 |
authUserEmail.add("vinay.p@smartdukaan.com");
|
3782 |
LocalDateTime createDate = orders.get(0).getCreateTimestamp();
|
| 3820 |
authUserEmail.add("shivam.gupta@smartdukaan.com");
|
3783 |
|
| 3821 |
|
3784 |
int fofoId = orders.get(0).getRetailerId();
|
| 3822 |
String[] emailTo = authUserEmail.toArray(new String[authUserEmail.size()]);
|
3785 |
|
| 3823 |
|
3786 |
int transactionId = transactionOrdersEntry.getKey();
|
| 3824 |
String[] ccTo = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com" };
|
3787 |
|
| 3825 |
|
3788 |
SanctionRequest sanctionRequest = sanctionRequestRepository.selectByTransactionId(transactionId);
|
| 3826 |
String subject = "Dispatched " + (orders.get(0).getRetailerName());
|
3789 |
|
| 3827 |
String message = String.format("Dear Team, \n" + "kindly note the material for the "
|
3790 |
double loanSettleAmount = loanStatementRepository.selectByDateAndFofoId(createDate, fofoId).stream()
|
| 3828 |
+ orders.get(0).getRetailerName() + "of Rs." + totalAmount + "is dispatched.");
|
3791 |
.filter(x -> x.getAmount().doubleValue() > 0)
|
| 3829 |
|
3792 |
.collect(Collectors.summingDouble(x -> x.getAmount().doubleValue()));
|
| 3830 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
3793 |
|
| 3831 |
|
3794 |
LOGGER.info("loanSettleAmount {}", loanSettleAmount);
|
| 3832 |
}
|
3795 |
|
| 3833 |
|
3796 |
LOGGER.info("totalAmount {}", totalAmount);
|
| 3834 |
}
|
3797 |
if (loanSettleAmount >= sanctionRequest.getUtilizationAmount().doubleValue()) {
|
| 3835 |
}
|
3798 |
|
| 3836 |
|
3799 |
LOGGER.info("totalAmount {}", totalAmount);
|
| 3837 |
}
|
3800 |
|
| 3838 |
|
3801 |
orders.forEach(x -> x.setShipmentHold(false));
|
| 3839 |
}
|
3802 |
|
| 3840 |
|
3803 |
List<String> authUserEmail = csService.getAuthUserIdByPartnerId(orders.get(0).getRetailerId())
|
| 3841 |
private void settledLoanStatement(LoanReferenceType loanReferneceType, BigDecimal amount, int fofoId, int loanId,
|
3804 |
.stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
| 3842 |
String description, LocalDateTime now) {
|
3805 |
authUserEmail.add("vinay.p@smartdukaan.com");
|
| 3843 |
|
3806 |
authUserEmail.add("shivam.gupta@smartdukaan.com");
|
| 3844 |
sdCreditService.createLoanStatement(loanReferneceType, amount.abs(), fofoId, loanId, description,
|
3807 |
|
| 3845 |
LocalDateTime.now());
|
3808 |
String[] emailTo = authUserEmail.toArray(new String[authUserEmail.size()]);
|
| 3846 |
|
3809 |
|
| 3847 |
}
|
3810 |
String[] ccTo = {"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com"};
|
| 3848 |
|
3811 |
|
| 3849 |
private void createUserWalletHistory(int walletId, int userId, WalletReferenceType referenceType, int loanId,
|
3812 |
String subject = "Dispatched " + (orders.get(0).getRetailerName());
|
| 3850 |
double interestAmount) {
|
3813 |
String message = String.format("Dear Team, \n" + "kindly note the material for the "
|
| 3851 |
UserWalletHistory uwh = new UserWalletHistory();
|
3814 |
+ orders.get(0).getRetailerName() + "of Rs." + totalAmount + "is dispatched.");
|
| 3852 |
uwh.setWalletId(walletId);
|
3815 |
|
| 3853 |
uwh.setFofoId(userId);
|
3816 |
Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
|
| 3854 |
uwh.setBusinessTimestamp(LocalDateTime.now());
|
3817 |
|
| 3855 |
uwh.setReferenceType(referenceType);
|
3818 |
}
|
| 3856 |
uwh.setReference(loanId);
|
3819 |
|
| 3857 |
uwh.setTimestamp(LocalDateTime.now());
|
3820 |
}
|
| 3858 |
uwh.setAmount((int) -(interestAmount));
|
3821 |
}
|
| 3859 |
uwh.setDescription("Amount adjusted against loan");
|
3822 |
|
| 3860 |
userWalletHistoryRepository.persist(uwh);
|
3823 |
}
|
| 3861 |
|
3824 |
|
| 3862 |
}
|
3825 |
}
|
| 3863 |
|
3826 |
|
| 3864 |
public void dailyLoanAlert()
|
3827 |
private void settledLoanStatement(LoanReferenceType loanReferneceType, BigDecimal amount, int fofoId, int loanId,
|
| 3865 |
throws ProfitMandiBusinessException, HttpHostConnectException, UnsupportedEncodingException {
|
3828 |
String description, LocalDateTime now) {
|
| 3866 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
3829 |
|
| 3867 |
|
3830 |
sdCreditService.createLoanStatement(loanReferneceType, amount.abs(), fofoId, loanId, description,
|
| 3868 |
Map<Integer, Double> partnerLoanAmount = new HashMap<>();
|
3831 |
LocalDateTime.now());
|
| 3869 |
|
3832 |
|
| 3870 |
if (!loans.isEmpty()) {
|
3833 |
}
|
| 3871 |
|
3834 |
|
| 3872 |
for (Loan loan : loans) {
|
3835 |
private void createUserWalletHistory(int walletId, int userId, WalletReferenceType referenceType, int loanId,
|
| 3873 |
|
3836 |
double interestAmount) {
|
| 3874 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
3837 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 3875 |
|
3838 |
uwh.setWalletId(walletId);
|
| 3876 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
3839 |
uwh.setFofoId(userId);
|
| 3877 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
3840 |
uwh.setBusinessTimestamp(LocalDateTime.now());
|
| 3878 |
if (partnerLoanAmount.get(loan.getFofoId()) != null) {
|
3841 |
uwh.setReferenceType(referenceType);
|
| 3879 |
amount += partnerLoanAmount.get(loan.getFofoId());
|
3842 |
uwh.setReference(loanId);
|
| 3880 |
partnerLoanAmount.put(loan.getFofoId(), amount);
|
3843 |
uwh.setTimestamp(LocalDateTime.now());
|
| 3881 |
} else {
|
3844 |
uwh.setAmount((int) -(interestAmount));
|
| 3882 |
partnerLoanAmount.put(loan.getFofoId(), amount);
|
3845 |
uwh.setDescription("Amount adjusted against loan");
|
| 3883 |
}
|
3846 |
userWalletHistoryRepository.persist(uwh);
|
| 3884 |
|
3847 |
|
| 3885 |
}
|
3848 |
}
|
| 3886 |
|
3849 |
|
| 3887 |
}
|
3850 |
public void dailyLoanAlert()
|
| 3888 |
|
3851 |
throws ProfitMandiBusinessException, HttpHostConnectException, UnsupportedEncodingException {
|
| 3889 |
if (!partnerLoanAmount.isEmpty()) {
|
3852 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
| 3890 |
|
3853 |
|
| 3891 |
for (Entry<Integer, Double> partnerLoanAmountEnrty : partnerLoanAmount.entrySet()) {
|
3854 |
Map<Integer, Double> partnerLoanAmount = new HashMap<>();
|
| 3892 |
|
3855 |
|
| 3893 |
int fofoId = partnerLoanAmountEnrty.getKey();
|
3856 |
if (!loans.isEmpty()) {
|
| 3894 |
|
3857 |
|
| 3895 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
|
3858 |
for (Loan loan : loans) {
|
| 3896 |
|
3859 |
|
| 3897 |
Address address = addressRepository.selectById(user.getAddressId());
|
3860 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
| 3898 |
|
3861 |
|
| 3899 |
String title = "Alert Credit Outstanding!";
|
3862 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
| 3900 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
3863 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
| 3901 |
String message = "Your total pending Loan amount is Rs."
|
3864 |
if (partnerLoanAmount.get(loan.getFofoId()) != null) {
|
| 3902 |
+ FormattingUtils.formatDecimal(Math.abs(partnerLoanAmountEnrty.getValue())) + ".";
|
3865 |
amount += partnerLoanAmount.get(loan.getFofoId());
|
| 3903 |
notificationService.sendNotification(fofoId, title, MessageType.notification, title, message, url);
|
3866 |
partnerLoanAmount.put(loan.getFofoId(), amount);
|
| 3904 |
|
3867 |
} else {
|
| 3905 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
3868 |
partnerLoanAmount.put(loan.getFofoId(), amount);
|
| 3906 |
|
3869 |
}
|
| 3907 |
}
|
3870 |
|
| 3908 |
|
3871 |
}
|
| 3909 |
}
|
3872 |
|
| 3910 |
|
3873 |
}
|
| 3911 |
}
|
3874 |
|
| 3912 |
|
3875 |
if (!partnerLoanAmount.isEmpty()) {
|
| 3913 |
public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
|
3876 |
|
| 3914 |
schemeService.processActivatedImeisForSchemes();
|
3877 |
for (Entry<Integer, Double> partnerLoanAmountEnrty : partnerLoanAmount.entrySet()) {
|
| 3915 |
}
|
3878 |
|
| 3916 |
|
3879 |
int fofoId = partnerLoanAmountEnrty.getKey();
|
| 3917 |
public void updatePartnerLimit() throws ProfitMandiBusinessException {
|
3880 |
|
| 3918 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
3881 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
|
| 3919 |
|
3882 |
|
| 3920 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
|
3883 |
Address address = addressRepository.selectById(user.getAddressId());
|
| 3921 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
3884 |
|
| 3922 |
Map<Integer, CurrentPartnerDailyInvestment> currentPartnerDailyInvestmentMap = currentPartnerDailyInvestmentRepository
|
3885 |
String title = "Alert Credit Outstanding!";
|
| 3923 |
.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
3886 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
| 3924 |
double limitValue = 100000;
|
3887 |
String message = "Your total pending Loan amount is Rs."
|
| 3925 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailerMap.entrySet()) {
|
3888 |
+ FormattingUtils.formatDecimal(Math.abs(partnerLoanAmountEnrty.getValue())) + ".";
|
| 3926 |
int fofoId = customRetailerEntry.getKey();
|
3889 |
notificationService.sendNotification(fofoId, title, MessageType.notification, title, message, url);
|
| 3927 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementMap.get(customRetailerEntry.getKey());
|
3890 |
|
| 3928 |
LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
|
3891 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
| 3929 |
CurrentPartnerDailyInvestment currentPartnerDailyInvestment = currentPartnerDailyInvestmentMap.get(fofoId);
|
3892 |
|
| 3930 |
BigDecimal suggestedAmount = BigDecimal.ZERO;
|
3893 |
}
|
| 3931 |
if (currentPartnerDailyInvestment != null) {
|
3894 |
|
| 3932 |
suggestedAmount = BigDecimal.valueOf(currentPartnerDailyInvestment.getTotalInvestment() * 0.1);
|
3895 |
}
|
| 3933 |
}
|
3896 |
|
| 3934 |
|
3897 |
}
|
| 3935 |
if (suggestedAmount.doubleValue() > limitValue) {
|
3898 |
|
| 3936 |
|
3899 |
public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
|
| 3937 |
suggestedAmount = BigDecimal.valueOf(limitValue);
|
3900 |
schemeService.processActivatedImeisForSchemes();
|
| 3938 |
|
3901 |
}
|
| 3939 |
}
|
3902 |
|
| 3940 |
|
3903 |
public void updatePartnerLimit() throws ProfitMandiBusinessException {
|
| 3941 |
if (suggestedAmount.doubleValue() < 0) {
|
3904 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
|
| 3942 |
suggestedAmount = BigDecimal.ZERO;
|
3905 |
|
| 3943 |
}
|
3906 |
Map<Integer, SDCreditRequirement> sdCreditRequirementMap = sdCreditRequirementRepository.selectAll().stream()
|
| 3944 |
|
3907 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 3945 |
LOGGER.info("suggestedAmount {} ", suggestedAmount);
|
3908 |
Map<Integer, CurrentPartnerDailyInvestment> currentPartnerDailyInvestmentMap = currentPartnerDailyInvestmentRepository
|
| 3946 |
|
3909 |
.selectAll().stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 3947 |
if (sdCreditRequirement == null) {
|
3910 |
double limitValue = 100000;
|
| 3948 |
sdCreditRequirement = new SDCreditRequirement();
|
3911 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailerMap.entrySet()) {
|
| 3949 |
sdCreditRequirement.setFofoId(fofoId);
|
3912 |
int fofoId = customRetailerEntry.getKey();
|
| 3950 |
sdCreditRequirement.setCreditDays(15);
|
3913 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementMap.get(customRetailerEntry.getKey());
|
| 3951 |
sdCreditRequirement.setInterestRate(BigDecimal.valueOf(0.05));
|
3914 |
LocalDateTime firstBillingDate = transactionRepository.getFirstBillingDate(fofoId);
|
| 3952 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
3915 |
CurrentPartnerDailyInvestment currentPartnerDailyInvestment = currentPartnerDailyInvestmentMap.get(fofoId);
|
| 3953 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
3916 |
BigDecimal suggestedAmount = BigDecimal.ZERO;
|
| 3954 |
sdCreditRequirement.setLimit(suggestedAmount);
|
3917 |
if (currentPartnerDailyInvestment != null) {
|
| 3955 |
sdCreditRequirement.setUtilizedAmount(BigDecimal.ZERO);
|
3918 |
suggestedAmount = BigDecimal.valueOf(currentPartnerDailyInvestment.getTotalInvestment() * 0.1);
|
| 3956 |
sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
|
3919 |
}
|
| 3957 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
3920 |
|
| 3958 |
sdCreditRequirementRepository.persist(sdCreditRequirement);
|
3921 |
if (suggestedAmount.doubleValue() > limitValue) {
|
| 3959 |
}
|
3922 |
|
| 3960 |
|
3923 |
suggestedAmount = BigDecimal.valueOf(limitValue);
|
| 3961 |
CreditRisk creditRisk = sdCreditService.getCurrentRisk(sdCreditRequirement, firstBillingDate);
|
3924 |
|
| 3962 |
|
3925 |
}
|
| 3963 |
sdCreditRequirement.setRisk(creditRisk);
|
3926 |
|
| 3964 |
|
3927 |
if (suggestedAmount.doubleValue() < 0) {
|
| 3965 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
3928 |
suggestedAmount = BigDecimal.ZERO;
|
| 3966 |
sdCreditRequirement.setLimit(suggestedAmount);
|
3929 |
}
|
| 3967 |
BigDecimal utilizedLimit = new BigDecimal(sdCreditService.getUtilizationAmount(fofoId));
|
3930 |
|
| 3968 |
|
3931 |
LOGGER.info("suggestedAmount {} ", suggestedAmount);
|
| 3969 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizedLimit);
|
3932 |
|
| 3970 |
|
3933 |
if (sdCreditRequirement == null) {
|
| 3971 |
LOGGER.info("utilizedLimit {} ", utilizedLimit);
|
3934 |
sdCreditRequirement = new SDCreditRequirement();
|
| 3972 |
|
3935 |
sdCreditRequirement.setFofoId(fofoId);
|
| 3973 |
LOGGER.info("availableLimit {} ", availableLimit);
|
3936 |
sdCreditRequirement.setCreditDays(15);
|
| 3974 |
|
3937 |
sdCreditRequirement.setInterestRate(BigDecimal.valueOf(0.05));
|
| 3975 |
sdCreditRequirement.setUtilizedAmount(utilizedLimit);
|
3938 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
| 3976 |
|
3939 |
sdCreditRequirement.setRisk(CreditRisk.HIGH_RISK);
|
| 3977 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
3940 |
sdCreditRequirement.setLimit(suggestedAmount);
|
| 3978 |
|
3941 |
sdCreditRequirement.setUtilizedAmount(BigDecimal.ZERO);
|
| 3979 |
CreditAccount creditAccount = creditAccountRepository
|
3942 |
sdCreditRequirement.setCreateTimestamp(LocalDateTime.now());
|
| 3980 |
.selectByFofoIdAndGateway(sdCreditRequirement.getFofoId(), Gateway.SDDIRECT);
|
3943 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
| 3981 |
if (creditAccount != null) {
|
3944 |
sdCreditRequirementRepository.persist(sdCreditRequirement);
|
| 3982 |
|
3945 |
}
|
| 3983 |
creditAccount.setInterestRate(sdCreditRequirement.getInterestRate().floatValue());
|
3946 |
|
| 3984 |
creditAccount.setSanctionedAmount(sdCreditRequirement.getLimit().floatValue());
|
3947 |
CreditRisk creditRisk = sdCreditService.getCurrentRisk(sdCreditRequirement, firstBillingDate);
|
| 3985 |
creditAccount.setAvailableAmount(availableLimit.floatValue());
|
3948 |
|
| 3986 |
creditAccount.setFreeDays(sdCreditRequirement.getFreeDays());
|
3949 |
sdCreditRequirement.setRisk(creditRisk);
|
| 3987 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
3950 |
|
| 3988 |
}
|
3951 |
sdCreditRequirement.setSuggestedLimit(suggestedAmount);
|
| 3989 |
|
3952 |
sdCreditRequirement.setLimit(suggestedAmount);
|
| 3990 |
}
|
3953 |
BigDecimal utilizedLimit = new BigDecimal(sdCreditService.getUtilizationAmount(fofoId));
|
| 3991 |
|
3954 |
|
| 3992 |
}
|
3955 |
BigDecimal availableLimit = sdCreditRequirement.getLimit().subtract(utilizedLimit);
|
| 3993 |
|
3956 |
|
| 3994 |
public void notifyDefaultLoans() throws ProfitMandiBusinessException, MessagingException, IOException {
|
3957 |
LOGGER.info("utilizedLimit {} ", utilizedLimit);
|
| 3995 |
|
3958 |
|
| 3996 |
sdCreditService.updateRisk();
|
3959 |
LOGGER.info("availableLimit {} ", availableLimit);
|
| 3997 |
List<Loan> defaultLoans = sdCreditService.getDefaultLoan();
|
3960 |
|
| 3998 |
if (!defaultLoans.isEmpty()) {
|
3961 |
sdCreditRequirement.setUtilizedAmount(utilizedLimit);
|
| 3999 |
this.sendDefaultLoanAlert(defaultLoans);
|
3962 |
|
| 4000 |
}
|
3963 |
sdCreditRequirement.setUpdateTimestamp(LocalDateTime.now());
|
| 4001 |
|
3964 |
|
| 4002 |
}
|
3965 |
CreditAccount creditAccount = creditAccountRepository
|
| 4003 |
|
3966 |
.selectByFofoIdAndGateway(sdCreditRequirement.getFofoId(), Gateway.SDDIRECT);
|
| 4004 |
public void sendDefaultLoanAlert(List<Loan> defaultLoans)
|
3967 |
if (creditAccount != null) {
|
| 4005 |
throws ProfitMandiBusinessException, MessagingException, IOException {
|
3968 |
|
| 4006 |
String subject = "Default Partners";
|
3969 |
creditAccount.setInterestRate(sdCreditRequirement.getInterestRate().floatValue());
|
| 4007 |
|
3970 |
creditAccount.setSanctionedAmount(sdCreditRequirement.getLimit().floatValue());
|
| 4008 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
3971 |
creditAccount.setAvailableAmount(availableLimit.floatValue());
|
| 4009 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
3972 |
creditAccount.setFreeDays(sdCreditRequirement.getFreeDays());
|
| 4010 |
ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
3973 |
creditAccount.setUpdatedOn(LocalDateTime.now());
|
| 4011 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
3974 |
}
|
| 4012 |
|
3975 |
|
| 4013 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService
|
3976 |
}
|
| 4014 |
.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false).entrySet()) {
|
3977 |
|
| 4015 |
List<Loan> filteredRows = new ArrayList<>();
|
3978 |
}
|
| 4016 |
for (Loan loan : defaultLoans) {
|
3979 |
|
| 4017 |
|
3980 |
public void notifyDefaultLoans() throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4018 |
if (storeGuyEntry.getValue().contains(loan.getFofoId())) {
|
3981 |
|
| 4019 |
|
3982 |
sdCreditService.updateRisk();
|
| 4020 |
filteredRows.add(loan);
|
3983 |
List<Loan> defaultLoans = sdCreditService.getDefaultLoan();
|
| 4021 |
}
|
3984 |
if (!defaultLoans.isEmpty()) {
|
| 4022 |
}
|
3985 |
this.sendDefaultLoanAlert(defaultLoans);
|
| 4023 |
if (!filteredRows.isEmpty()) {
|
3986 |
}
|
| 4024 |
String messageText = this.getMessageForDueDateExtend(filteredRows);
|
3987 |
|
| 4025 |
String[] email = new String[] { storeGuyEntry.getKey() };
|
3988 |
}
|
| 4026 |
|
3989 |
|
| 4027 |
this.sendMailHtmlFormat(email, messageText, null, subject);
|
3990 |
public void sendDefaultLoanAlert(List<Loan> defaultLoans)
|
| 4028 |
|
3991 |
throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4029 |
}
|
3992 |
String subject = "Default Partners";
|
| 4030 |
|
3993 |
|
| 4031 |
}
|
3994 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
| 4032 |
|
3995 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
| 4033 |
for (Loan defaultLoan : defaultLoans) {
|
3996 |
ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
| 4034 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(defaultLoan.getId());
|
3997 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
| 4035 |
|
3998 |
|
| 4036 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
3999 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService
|
| 4037 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
4000 |
.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false).entrySet()) {
|
| 4038 |
|
4001 |
List<Loan> filteredRows = new ArrayList<>();
|
| 4039 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(defaultLoan.getFofoId());
|
4002 |
for (Loan loan : defaultLoans) {
|
| 4040 |
|
4003 |
|
| 4041 |
Address address = addressRepository.selectById(user.getAddressId());
|
4004 |
if (storeGuyEntry.getValue().contains(loan.getFofoId())) {
|
| 4042 |
|
4005 |
|
| 4043 |
String title = "Loan Amount Overdue!";
|
4006 |
filteredRows.add(loan);
|
| 4044 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
4007 |
}
|
| 4045 |
String message = "Your loan due date "
|
4008 |
}
|
| 4046 |
+ defaultLoan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
|
4009 |
if (!filteredRows.isEmpty()) {
|
| 4047 |
+ " has been exceeded. Additional penal interest of "
|
4010 |
String messageText = this.getMessageForDueDateExtend(filteredRows);
|
| 4048 |
+ defaultLoan.getInterestRate().setScale(2, RoundingMode.HALF_UP)
|
4011 |
String[] email = new String[]{storeGuyEntry.getKey()};
|
| 4049 |
+ "% and Rs.100 shall be levied on daily basis." + " Your total pending Loan amount is Rs."
|
4012 |
|
| 4050 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
|
4013 |
this.sendMailHtmlFormat(email, messageText, null, subject);
|
| 4051 |
notificationService.sendNotification(defaultLoan.getFofoId(), title, MessageType.notification, title,
|
4014 |
|
| 4052 |
message, url);
|
4015 |
}
|
| 4053 |
|
4016 |
|
| 4054 |
// notificationService.sendWhatsappMessage(message, title,
|
4017 |
}
|
| 4055 |
// address.getPhoneNumber());
|
4018 |
|
| 4056 |
|
4019 |
for (Loan defaultLoan : defaultLoans) {
|
| 4057 |
}
|
4020 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(defaultLoan.getId());
|
| 4058 |
}
|
4021 |
|
| 4059 |
|
4022 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
| 4060 |
private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
|
4023 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
| 4061 |
StringBuilder sb = new StringBuilder();
|
4024 |
|
| 4062 |
sb.append(
|
4025 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(defaultLoan.getFofoId());
|
| 4063 |
"<html><body><p>Alert</p><p>Default Partners :-</p>" + "<br/><p>EveryDay Rs.100 charged as Penalty</p>"
|
4026 |
|
| 4064 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
4027 |
Address address = addressRepository.selectById(user.getAddressId());
|
| 4065 |
sb.append("<tbody>\n" + " <tr>\n"
|
4028 |
|
| 4066 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
4029 |
String title = "Loan Amount Overdue!";
|
| 4067 |
+ " <th style='border:1px solid black;padding: 5px'>due date</th>\n"
|
4030 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
| 4068 |
+ " <th style='border:1px solid black;padding: 5px'>Days</th>\n"
|
4031 |
String message = "Your loan due date "
|
| 4069 |
+ " <th style='border:1px solid black;padding: 5px'>Pending Amount</th>\n"
|
4032 |
+ defaultLoan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
|
| 4070 |
|
4033 |
+ " has been exceeded. Additional penal interest of "
|
| 4071 |
+ " </tr>");
|
4034 |
+ defaultLoan.getInterestRate().setScale(2, RoundingMode.HALF_UP)
|
| 4072 |
for (Loan entry : loans) {
|
4035 |
+ "% and Rs.100 shall be levied on daily basis." + " Your total pending Loan amount is Rs."
|
| 4073 |
|
4036 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
|
| 4074 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(entry.getId());
|
4037 |
notificationService.sendNotification(defaultLoan.getFofoId(), title, MessageType.notification, title,
|
| 4075 |
|
4038 |
message, url);
|
| 4076 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
4039 |
|
| 4077 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
4040 |
// notificationService.sendWhatsappMessage(message, title,
|
| 4078 |
|
4041 |
// address.getPhoneNumber());
|
| 4079 |
long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
|
4042 |
|
| 4080 |
|
4043 |
}
|
| 4081 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
4044 |
}
|
| 4082 |
|
4045 |
|
| 4083 |
sb.append("<tr>");
|
4046 |
private String getMessageForDueDateExtend(List<Loan> loans) throws ProfitMandiBusinessException {
|
| 4084 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
4047 |
StringBuilder sb = new StringBuilder();
|
| 4085 |
+ customRetailer.getCode() + ")" + "</td>");
|
4048 |
sb.append(
|
| 4086 |
|
4049 |
"<html><body><p>Alert</p><p>Default Partners :-</p>" + "<br/><p>EveryDay Rs.100 charged as Penalty</p>"
|
| 4087 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
4050 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
| 4088 |
+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
4051 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 4089 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
|
4052 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
| 4090 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
4053 |
+ " <th style='border:1px solid black;padding: 5px'>due date</th>\n"
|
| 4091 |
+ new DecimalFormat("#.##").format(Math.abs(amount)) + "</td>");
|
4054 |
+ " <th style='border:1px solid black;padding: 5px'>Days</th>\n"
|
| 4092 |
|
4055 |
+ " <th style='border:1px solid black;padding: 5px'>Pending Amount</th>\n"
|
| 4093 |
sb.append("</tr>");
|
4056 |
|
| 4094 |
|
4057 |
+ " </tr>");
|
| 4095 |
}
|
4058 |
for (Loan entry : loans) {
|
| 4096 |
|
4059 |
|
| 4097 |
sb.append("</tbody></table></body></html>");
|
4060 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(entry.getId());
|
| 4098 |
|
4061 |
|
| 4099 |
return sb.toString();
|
4062 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
| 4100 |
}
|
4063 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
| 4101 |
|
4064 |
|
| 4102 |
private String getMessageForDueDateCross(List<Loan> loans) throws ProfitMandiBusinessException {
|
4065 |
long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
|
| 4103 |
StringBuilder sb = new StringBuilder();
|
4066 |
|
| 4104 |
sb.append("<html><body><p>Alert</p><p>Due Date Cross Partners :-</p>"
|
4067 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
| 4105 |
+ "<br/><p>Additional penal interest of shall be levied on daily basis.</p>"
|
4068 |
|
| 4106 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
4069 |
sb.append("<tr>");
|
| 4107 |
sb.append("<tbody>\n" + " <tr>\n"
|
4070 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
| 4108 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
4071 |
+ customRetailer.getCode() + ")" + "</td>");
|
| 4109 |
+ " <th style='border:1px solid black;padding: 5px'>due date</th>\n"
|
4072 |
|
| 4110 |
+ " <th style='border:1px solid black;padding: 5px'>Days</th>\n"
|
4073 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 4111 |
+ " <th style='border:1px solid black;padding: 5px'>Pending Amount</th>\n"
|
4074 |
+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
| 4112 |
|
4075 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
|
| 4113 |
+ " </tr>");
|
4076 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 4114 |
for (Loan entry : loans) {
|
4077 |
+ new DecimalFormat("#.##").format(Math.abs(amount)) + "</td>");
|
| 4115 |
|
4078 |
|
| 4116 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(entry.getId());
|
4079 |
sb.append("</tr>");
|
| 4117 |
|
4080 |
|
| 4118 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
4081 |
}
|
| 4119 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
4082 |
|
| 4120 |
|
4083 |
sb.append("</tbody></table></body></html>");
|
| 4121 |
long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
|
4084 |
|
| 4122 |
|
4085 |
return sb.toString();
|
| 4123 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
4086 |
}
|
| 4124 |
|
4087 |
|
| 4125 |
sb.append("<tr>");
|
4088 |
private String getMessageForDueDateCross(List<Loan> loans) throws ProfitMandiBusinessException {
|
| 4126 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
4089 |
StringBuilder sb = new StringBuilder();
|
| 4127 |
+ customRetailer.getCode() + ")" + "</td>");
|
4090 |
sb.append("<html><body><p>Alert</p><p>Due Date Cross Partners :-</p>"
|
| 4128 |
|
4091 |
+ "<br/><p>Additional penal interest of shall be levied on daily basis.</p>"
|
| 4129 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
4092 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
| 4130 |
+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
4093 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 4131 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
|
4094 |
+ " <th style='border:1px solid black;padding: 5px'>PartnerName</th>\n"
|
| 4132 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
4095 |
+ " <th style='border:1px solid black;padding: 5px'>due date</th>\n"
|
| 4133 |
+ new DecimalFormat("#.##").format(Math.abs(amount)) + "</td>");
|
4096 |
+ " <th style='border:1px solid black;padding: 5px'>Days</th>\n"
|
| 4134 |
|
4097 |
+ " <th style='border:1px solid black;padding: 5px'>Pending Amount</th>\n"
|
| 4135 |
sb.append("</tr>");
|
4098 |
|
| 4136 |
|
4099 |
+ " </tr>");
|
| 4137 |
}
|
4100 |
for (Loan entry : loans) {
|
| 4138 |
|
4101 |
|
| 4139 |
sb.append("</tbody></table></body></html>");
|
4102 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(entry.getId());
|
| 4140 |
|
4103 |
|
| 4141 |
return sb.toString();
|
4104 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
| 4142 |
}
|
4105 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
| 4143 |
|
4106 |
|
| 4144 |
public void notifyLoanDueDateCross() throws ProfitMandiBusinessException, MessagingException, IOException {
|
4107 |
long noOfdaysBetween = ChronoUnit.DAYS.between(entry.getDueDate().toLocalDate(), LocalDateTime.now());
|
| 4145 |
|
4108 |
|
| 4146 |
List<Loan> dueDateCrossLoans = sdCreditService.getDueDateCrossLoan();
|
4109 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
|
| 4147 |
if (!dueDateCrossLoans.isEmpty()) {
|
4110 |
|
| 4148 |
this.sendDueDateCrossLoanAlert(dueDateCrossLoans);
|
4111 |
sb.append("<tr>");
|
| 4149 |
}
|
4112 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "("
|
| 4150 |
|
4113 |
+ customRetailer.getCode() + ")" + "</td>");
|
| 4151 |
}
|
4114 |
|
| 4152 |
|
4115 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 4153 |
private void sendDueDateCrossLoanAlert(List<Loan> dueDateCrossLoans)
|
4116 |
+ entry.getDueDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
|
| 4154 |
throws ProfitMandiBusinessException, MessagingException, IOException {
|
4117 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + noOfdaysBetween + "</td>");
|
| 4155 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
4118 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 4156 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
4119 |
+ new DecimalFormat("#.##").format(Math.abs(amount)) + "</td>");
|
| 4157 |
ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
4120 |
|
| 4158 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
4121 |
sb.append("</tr>");
|
| 4159 |
|
4122 |
|
| 4160 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService
|
4123 |
}
|
| 4161 |
.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false).entrySet()) {
|
4124 |
|
| 4162 |
List<Loan> filteredRows = new ArrayList<>();
|
4125 |
sb.append("</tbody></table></body></html>");
|
| 4163 |
for (Loan loan : dueDateCrossLoans) {
|
4126 |
|
| 4164 |
|
4127 |
return sb.toString();
|
| 4165 |
if (storeGuyEntry.getValue().contains(loan.getFofoId())) {
|
4128 |
}
|
| 4166 |
|
4129 |
|
| 4167 |
filteredRows.add(loan);
|
4130 |
public void notifyLoanDueDateCross() throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4168 |
}
|
4131 |
|
| 4169 |
}
|
4132 |
List<Loan> dueDateCrossLoans = sdCreditService.getDueDateCrossLoan();
|
| 4170 |
if (!filteredRows.isEmpty()) {
|
4133 |
if (!dueDateCrossLoans.isEmpty()) {
|
| 4171 |
String messageText = this.getMessageForDueDateCross(filteredRows);
|
4134 |
this.sendDueDateCrossLoanAlert(dueDateCrossLoans);
|
| 4172 |
String[] email = new String[] { storeGuyEntry.getKey() };
|
4135 |
}
|
| 4173 |
|
4136 |
|
| 4174 |
this.sendMailHtmlFormat(email, messageText, null, "Due Date Cross");
|
4137 |
}
|
| 4175 |
|
4138 |
|
| 4176 |
}
|
4139 |
private void sendDueDateCrossLoanAlert(List<Loan> dueDateCrossLoans)
|
| 4177 |
|
4140 |
throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4178 |
}
|
4141 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
| 4179 |
if (!dueDateCrossLoans.isEmpty()) {
|
4142 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
| 4180 |
for (Loan loan : dueDateCrossLoans) {
|
4143 |
ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
| 4181 |
|
4144 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
| 4182 |
long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDate.now());
|
4145 |
|
| 4183 |
|
4146 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService
|
| 4184 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(loan.getFofoId());
|
4147 |
.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false).entrySet()) {
|
| 4185 |
|
4148 |
List<Loan> filteredRows = new ArrayList<>();
|
| 4186 |
Address address = addressRepository.selectById(user.getAddressId());
|
4149 |
for (Loan loan : dueDateCrossLoans) {
|
| 4187 |
|
4150 |
|
| 4188 |
LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
|
4151 |
if (storeGuyEntry.getValue().contains(loan.getFofoId())) {
|
| 4189 |
|
4152 |
|
| 4190 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
4153 |
filteredRows.add(loan);
|
| 4191 |
|
4154 |
}
|
| 4192 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
4155 |
}
|
| 4193 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
4156 |
if (!filteredRows.isEmpty()) {
|
| 4194 |
|
4157 |
String messageText = this.getMessageForDueDateCross(filteredRows);
|
| 4195 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
4158 |
String[] email = new String[]{storeGuyEntry.getKey()};
|
| 4196 |
|
4159 |
|
| 4197 |
String title = "Alert!";
|
4160 |
this.sendMailHtmlFormat(email, messageText, null, "Due Date Cross");
|
| 4198 |
String message = "Your loan due date "
|
4161 |
|
| 4199 |
+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
|
4162 |
}
|
| 4200 |
+ " has been exceeded. Additional penal interest of "
|
4163 |
|
| 4201 |
+ loan.getInterestRate().setScale(2, RoundingMode.HALF_UP)
|
4164 |
}
|
| 4202 |
+ "% shall be levied on daily basis. Your total pending loan amount is Rs."
|
4165 |
if (!dueDateCrossLoans.isEmpty()) {
|
| 4203 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
|
4166 |
for (Loan loan : dueDateCrossLoans) {
|
| 4204 |
|
4167 |
|
| 4205 |
notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title, message,
|
4168 |
long noOfdaysBetween = ChronoUnit.DAYS.between(loan.getDueDate().toLocalDate(), LocalDate.now());
|
| 4206 |
url);
|
4169 |
|
| 4207 |
|
4170 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(loan.getFofoId());
|
| 4208 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
4171 |
|
| 4209 |
|
4172 |
Address address = addressRepository.selectById(user.getAddressId());
|
| 4210 |
}
|
4173 |
|
| 4211 |
}
|
4174 |
LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
|
| 4212 |
|
4175 |
|
| 4213 |
}
|
4176 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
| 4214 |
|
4177 |
|
| 4215 |
public void alertForDueDate() throws ProfitMandiBusinessException, MessagingException, IOException {
|
4178 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
| 4216 |
|
4179 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
| 4217 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
4180 |
|
| 4218 |
|
4181 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
| 4219 |
if (!loans.isEmpty()) {
|
4182 |
|
| 4220 |
for (Loan loan : loans) {
|
4183 |
String title = "Alert!";
|
| 4221 |
|
4184 |
String message = "Your loan due date "
|
| 4222 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(loan.getFofoId());
|
4185 |
+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
|
| 4223 |
|
4186 |
+ " has been exceeded. Additional penal interest of "
|
| 4224 |
Address address = addressRepository.selectById(user.getAddressId());
|
4187 |
+ loan.getInterestRate().setScale(2, RoundingMode.HALF_UP)
|
| 4225 |
|
4188 |
+ "% shall be levied on daily basis. Your total pending loan amount is Rs."
|
| 4226 |
long noOfdaysBetween = ChronoUnit.DAYS.between(LocalDate.now(), loan.getDueDate().toLocalDate());
|
4189 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + ". !!Pay Now!!";
|
| 4227 |
|
4190 |
|
| 4228 |
LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
|
4191 |
notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title, message,
|
| 4229 |
|
4192 |
url);
|
| 4230 |
if (noOfdaysBetween <= 4 && noOfdaysBetween >= 0) {
|
4193 |
|
| 4231 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
4194 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
| 4232 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
4195 |
|
| 4233 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
4196 |
}
|
| 4234 |
|
4197 |
}
|
| 4235 |
String title = "Alert!";
|
4198 |
|
| 4236 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
4199 |
}
|
| 4237 |
String message = null;
|
4200 |
|
| 4238 |
if (noOfdaysBetween == 0) {
|
4201 |
public void alertForDueDate() throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4239 |
|
4202 |
|
| 4240 |
message = "Your total pending Loan amount is Rs."
|
4203 |
List<Loan> loans = loanRepository.selectAllActiveLoan();
|
| 4241 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + " is due for Today, Pay Now!!";
|
4204 |
|
| 4242 |
|
4205 |
if (!loans.isEmpty()) {
|
| 4243 |
} else {
|
4206 |
for (Loan loan : loans) {
|
| 4244 |
|
4207 |
|
| 4245 |
message = "Your total pending Loan amount is Rs."
|
4208 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(loan.getFofoId());
|
| 4246 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + " is due by "
|
4209 |
|
| 4247 |
+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
|
4210 |
Address address = addressRepository.selectById(user.getAddressId());
|
| 4248 |
+ " , Pay Now!!";
|
4211 |
|
| 4249 |
|
4212 |
long noOfdaysBetween = ChronoUnit.DAYS.between(LocalDate.now(), loan.getDueDate().toLocalDate());
|
| 4250 |
}
|
4213 |
|
| 4251 |
notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title,
|
4214 |
LOGGER.info("noOfdaysBetween {} ", noOfdaysBetween);
|
| 4252 |
message, url);
|
4215 |
|
| 4253 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
4216 |
if (noOfdaysBetween <= 4 && noOfdaysBetween >= 0) {
|
| 4254 |
|
4217 |
List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(loan.getId());
|
| 4255 |
}
|
4218 |
double amount = loanStatements.stream().map(x -> x.getAmount())
|
| 4256 |
}
|
4219 |
.collect(Collectors.summingDouble(x -> x.doubleValue()));
|
| 4257 |
}
|
4220 |
|
| 4258 |
|
4221 |
String title = "Alert!";
|
| 4259 |
}
|
4222 |
String url = "http://app.smartdukaan.com/pages/home/credit";
|
| 4260 |
|
4223 |
String message = null;
|
| 4261 |
public void userMobileNumberOptIn() throws HttpHostConnectException, ProfitMandiBusinessException {
|
4224 |
if (noOfdaysBetween == 0) {
|
| 4262 |
|
4225 |
|
| 4263 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
4226 |
message = "Your total pending Loan amount is Rs."
|
| 4264 |
|
4227 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + " is due for Today, Pay Now!!";
|
| 4265 |
List<com.spice.profitmandi.dao.entity.user.User> users = userUserRepository
|
4228 |
|
| 4266 |
.selectByIds(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
4229 |
} else {
|
| 4267 |
|
4230 |
|
| 4268 |
List<Address> addresses = addressRepository
|
4231 |
message = "Your total pending Loan amount is Rs."
|
| 4269 |
.selectByIds(users.stream().map(x -> x.getAddressId()).collect(Collectors.toList()));
|
4232 |
+ FormattingUtils.formatDecimal(Math.abs(amount)) + " is due by "
|
| 4270 |
|
4233 |
+ loan.getDueDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))
|
| 4271 |
LOGGER.info("addresses" + addresses);
|
4234 |
+ " , Pay Now!!";
|
| 4272 |
|
4235 |
|
| 4273 |
for (Address address : addresses) {
|
4236 |
}
|
| 4274 |
Map<String, String> requestheaders = new HashMap<>();
|
4237 |
notificationService.sendNotification(loan.getFofoId(), title, MessageType.notification, title,
|
| 4275 |
requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
|
4238 |
message, url);
|
| 4276 |
Map<String, String> requestParams = new HashMap<>();
|
4239 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
| 4277 |
requestParams.put("userid", String.valueOf(2000215976));
|
4240 |
|
| 4278 |
requestParams.put("password", "MFRd!BBL");
|
4241 |
}
|
| 4279 |
requestParams.put("phone_number", address.getPhoneNumber());
|
4242 |
}
|
| 4280 |
requestParams.put("auth_scheme", "plain");
|
4243 |
}
|
| 4281 |
requestParams.put("v", "1.1");
|
4244 |
|
| 4282 |
requestParams.put("format", "json");
|
4245 |
}
|
| 4283 |
|
4246 |
|
| 4284 |
requestParams.put("method", "OPT_IN");
|
4247 |
public void userMobileNumberOptIn() throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 4285 |
|
4248 |
|
| 4286 |
requestParams.put("channel", "WHATSAPP");
|
4249 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 4287 |
String response = restClient.get("https://media.smsgupshup.com/GatewayAPI/rest", requestParams,
|
4250 |
|
| 4288 |
requestheaders);
|
4251 |
List<com.spice.profitmandi.dao.entity.user.User> users = userUserRepository
|
| 4289 |
LOGGER.info("response" + response);
|
4252 |
.selectByIds(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 4290 |
}
|
4253 |
|
| 4291 |
|
4254 |
List<Address> addresses = addressRepository
|
| 4292 |
}
|
4255 |
.selectByIds(users.stream().map(x -> x.getAddressId()).collect(Collectors.toList()));
|
| 4293 |
|
4256 |
|
| 4294 |
public void authUserMobileNumberOptIn() throws HttpHostConnectException, ProfitMandiBusinessException {
|
4257 |
LOGGER.info("addresses" + addresses);
|
| 4295 |
|
4258 |
|
| 4296 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
4259 |
for (Address address : addresses) {
|
| 4297 |
LOGGER.info("authUsers" + authUsers);
|
4260 |
Map<String, String> requestheaders = new HashMap<>();
|
| 4298 |
|
4261 |
requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
|
| 4299 |
for (AuthUser authUser : authUsers) {
|
4262 |
Map<String, String> requestParams = new HashMap<>();
|
| 4300 |
Map<String, String> requestheaders = new HashMap<>();
|
4263 |
requestParams.put("userid", String.valueOf(2000215976));
|
| 4301 |
requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
|
4264 |
requestParams.put("password", "MFRd!BBL");
|
| 4302 |
Map<String, String> requestParams = new HashMap<>();
|
4265 |
requestParams.put("phone_number", address.getPhoneNumber());
|
| 4303 |
requestParams.put("userid", String.valueOf(2000215976));
|
4266 |
requestParams.put("auth_scheme", "plain");
|
| 4304 |
requestParams.put("password", "MFRd!BBL");
|
4267 |
requestParams.put("v", "1.1");
|
| 4305 |
requestParams.put("phone_number", authUser.getMobileNumber());
|
4268 |
requestParams.put("format", "json");
|
| 4306 |
requestParams.put("auth_scheme", "plain");
|
4269 |
|
| 4307 |
requestParams.put("v", "1.1");
|
4270 |
requestParams.put("method", "OPT_IN");
|
| 4308 |
requestParams.put("format", "json");
|
4271 |
|
| 4309 |
|
4272 |
requestParams.put("channel", "WHATSAPP");
|
| 4310 |
requestParams.put("method", "OPT_IN");
|
4273 |
String response = restClient.get("https://media.smsgupshup.com/GatewayAPI/rest", requestParams,
|
| 4311 |
|
4274 |
requestheaders);
|
| 4312 |
requestParams.put("channel", "WHATSAPP");
|
4275 |
LOGGER.info("response" + response);
|
| 4313 |
String response = restClient.get("https://media.smsgupshup.com/GatewayAPI/rest", requestParams,
|
4276 |
}
|
| 4314 |
requestheaders);
|
4277 |
|
| 4315 |
LOGGER.info("response" + response);
|
4278 |
}
|
| 4316 |
}
|
4279 |
|
| 4317 |
|
4280 |
public void authUserMobileNumberOptIn() throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 4318 |
}
|
4281 |
|
| 4319 |
|
4282 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 4320 |
@Autowired
|
4283 |
LOGGER.info("authUsers" + authUsers);
|
| 4321 |
private HygieneDataRepository hygieneDataRepository;
|
4284 |
|
| 4322 |
|
4285 |
for (AuthUser authUser : authUsers) {
|
| 4323 |
public void hygineAlertForPartner() throws ProfitMandiBusinessException, MessagingException, IOException {
|
4286 |
Map<String, String> requestheaders = new HashMap<>();
|
| 4324 |
|
4287 |
requestheaders.put("Content-Type", "application/x-www-form-urlencoded");
|
| 4325 |
List<String> remarks = new ArrayList<>();
|
4288 |
Map<String, String> requestParams = new HashMap<>();
|
| 4326 |
remarks.add("Out of Service");
|
4289 |
requestParams.put("userid", String.valueOf(2000215976));
|
| 4327 |
remarks.add("Duplicate number");
|
4290 |
requestParams.put("password", "MFRd!BBL");
|
| 4328 |
remarks.add("Partner number");
|
4291 |
requestParams.put("phone_number", authUser.getMobileNumber());
|
| 4329 |
List<HygieneData> hygieneData = hygieneDataRepository.selectAllByDisposedDateAndRemark(LocalDate.now(),
|
4292 |
requestParams.put("auth_scheme", "plain");
|
| 4330 |
remarks);
|
4293 |
requestParams.put("v", "1.1");
|
| 4331 |
|
4294 |
requestParams.put("format", "json");
|
| 4332 |
if (!hygieneData.isEmpty()) {
|
4295 |
|
| 4333 |
|
4296 |
requestParams.put("method", "OPT_IN");
|
| 4334 |
Map<Integer, List<HygieneData>> partnerHygieneDataMap = hygieneData.stream()
|
4297 |
|
| 4335 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
4298 |
requestParams.put("channel", "WHATSAPP");
|
| 4336 |
|
4299 |
String response = restClient.get("https://media.smsgupshup.com/GatewayAPI/rest", requestParams,
|
| 4337 |
for (Entry<Integer, List<HygieneData>> partnerHygieneDataMapEntry : partnerHygieneDataMap.entrySet()) {
|
4300 |
requestheaders);
|
| 4338 |
|
4301 |
LOGGER.info("response" + response);
|
| 4339 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(partnerHygieneDataMapEntry.getKey());
|
4302 |
}
|
| 4340 |
|
4303 |
|
| 4341 |
StringBuilder sb = new StringBuilder();
|
4304 |
}
|
| 4342 |
sb.append("<html><body><p>Dear Partner,"
|
4305 |
|
| 4343 |
+ "</p><br/><p>It has been observed in our calls to the respective customers that the contact no is either not correct or does not have incoming calls.\n"
|
4306 |
@Autowired
|
| 4344 |
|
4307 |
private HygieneDataRepository hygieneDataRepository;
|
| 4345 |
+ " </p>"
|
4308 |
|
| 4346 |
+ "<p>We would like to inform you that this will hinder all our marketing initiatives to bring this customer back to our smartdukaan or cross sell any product from your inventory."
|
4309 |
public void hygineAlertForPartner() throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4347 |
+ "</p><p>Kindly ensure going forward that the details are correct so to avoid 1% margin loss.\n"
|
4310 |
|
| 4348 |
+ "</p><p>In case the data is found to be incorrect there is a loss of 1% margin on this sales under SmartDukaan hygiene guidelines.\n"
|
4311 |
List<String> remarks = new ArrayList<>();
|
| 4349 |
+ " " + "</p>"
|
4312 |
remarks.add("Out of Service");
|
| 4350 |
|
4313 |
remarks.add("Duplicate number");
|
| 4351 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
4314 |
remarks.add("Partner number");
|
| 4352 |
sb.append("<tbody>\n" + " " + " " + "<tr>\n");
|
4315 |
List<HygieneData> hygieneData = hygieneDataRepository.selectAllByDisposedDateAndRemark(LocalDate.now(),
|
| 4353 |
sb.append("<th style='border:1px solid black;padding: 5px'>Invoice Number</th>\n");
|
4316 |
remarks);
|
| 4354 |
sb.append("<th style='border:1px solid black;padding: 5px'>Customer Name</th>\n");
|
4317 |
|
| 4355 |
sb.append("<th style='border:1px solid black;padding: 5px'>Customer Number</th>\n");
|
4318 |
if (!hygieneData.isEmpty()) {
|
| 4356 |
sb.append("</tr>\n");
|
4319 |
|
| 4357 |
|
4320 |
Map<Integer, List<HygieneData>> partnerHygieneDataMap = hygieneData.stream()
|
| 4358 |
List<HygieneData> hygienes = partnerHygieneDataMapEntry.getValue();
|
4321 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 4359 |
|
4322 |
|
| 4360 |
List<Integer> orderIds = hygienes.stream().map(x -> x.getOrderId()).collect(Collectors.toList());
|
4323 |
for (Entry<Integer, List<HygieneData>> partnerHygieneDataMapEntry : partnerHygieneDataMap.entrySet()) {
|
| 4361 |
|
4324 |
|
| 4362 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectAllByOrderIds(orderIds);
|
4325 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(partnerHygieneDataMapEntry.getKey());
|
| 4363 |
|
4326 |
|
| 4364 |
for (FofoOrder fofoOrder : fofoOrders) {
|
4327 |
StringBuilder sb = new StringBuilder();
|
| 4365 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
4328 |
sb.append("<html><body><p>Dear Partner,"
|
| 4366 |
sb.append("<tr>");
|
4329 |
+ "</p><br/><p>It has been observed in our calls to the respective customers that the contact no is either not correct or does not have incoming calls.\n"
|
| 4367 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + fofoOrder.getInvoiceNumber()
|
4330 |
|
| 4368 |
+ "</td>\n");
|
4331 |
+ " </p>"
|
| 4369 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customer.getFirstName() + ""
|
4332 |
+ "<p>We would like to inform you that this will hinder all our marketing initiatives to bring this customer back to our smartdukaan or cross sell any product from your inventory."
|
| 4370 |
+ customer.getLastName() + "</td>\n");
|
4333 |
+ "</p><p>Kindly ensure going forward that the details are correct so to avoid 1% margin loss.\n"
|
| 4371 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customer.getMobileNumber()
|
4334 |
+ "</p><p>In case the data is found to be incorrect there is a loss of 1% margin on this sales under SmartDukaan hygiene guidelines.\n"
|
| 4372 |
+ "</td>\n");
|
4335 |
+ " " + "</p>"
|
| 4373 |
|
4336 |
|
| 4374 |
sb.append("</tr>\n");
|
4337 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
| 4375 |
}
|
4338 |
sb.append("<tbody>\n" + " " + " " + "<tr>\n");
|
| 4376 |
|
4339 |
sb.append("<th style='border:1px solid black;padding: 5px'>Invoice Number</th>\n");
|
| 4377 |
sb.append("</tbody></table></body></html>");
|
4340 |
sb.append("<th style='border:1px solid black;padding: 5px'>Customer Name</th>\n");
|
| 4378 |
String subject = "Customer Info - Hygiene Alert";
|
4341 |
sb.append("<th style='border:1px solid black;padding: 5px'>Customer Number</th>\n");
|
| 4379 |
|
4342 |
sb.append("</tr>\n");
|
| 4380 |
this.sendMailOfHtmlFormat(customRetailer.getEmail(), sb.toString(), null, subject);
|
4343 |
|
| 4381 |
|
4344 |
List<HygieneData> hygienes = partnerHygieneDataMapEntry.getValue();
|
| 4382 |
}
|
4345 |
|
| 4383 |
|
4346 |
List<Integer> orderIds = hygienes.stream().map(x -> x.getOrderId()).collect(Collectors.toList());
|
| 4384 |
}
|
4347 |
|
| 4385 |
|
4348 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectAllByOrderIds(orderIds);
|
| 4386 |
}
|
4349 |
|
| 4387 |
|
4350 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 4388 |
public void hygineAlertForInternalTeam() throws ProfitMandiBusinessException, MessagingException, IOException {
|
4351 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 4389 |
|
4352 |
sb.append("<tr>");
|
| 4390 |
List<String> remarks = new ArrayList<>();
|
4353 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + fofoOrder.getInvoiceNumber()
|
| 4391 |
remarks.add("Out of Service");
|
4354 |
+ "</td>\n");
|
| 4392 |
remarks.add("Duplicate number");
|
4355 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customer.getFirstName() + ""
|
| 4393 |
remarks.add("Partner number");
|
4356 |
+ customer.getLastName() + "</td>\n");
|
| 4394 |
List<HygieneData> hygieneDataLastThreeMonth = hygieneDataRepository
|
4357 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + customer.getMobileNumber()
|
| 4395 |
.selectDisposedDateAndRemarks(
|
4358 |
+ "</td>\n");
|
| 4396 |
LocalDate.now().withDayOfMonth(1).minusMonths(3).atStartOfDay(), LocalDate.now().minusMonths(1)
|
4359 |
|
| 4397 |
.withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth()).atTime(LocalTime.MAX),
|
4360 |
sb.append("</tr>\n");
|
| 4398 |
remarks);
|
4361 |
}
|
| 4399 |
|
4362 |
|
| 4400 |
List<HygieneData> hygieneDataRecentMonth = hygieneDataRepository
|
4363 |
sb.append("</tbody></table></body></html>");
|
| 4401 |
.selectDisposedDateAndRemarks(LocalDate.now().withDayOfMonth(1), remarks);
|
4364 |
String subject = "Customer Info - Hygiene Alert";
|
| 4402 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
4365 |
|
| 4403 |
Map<Integer, List<HygieneData>> partnerHygieneLastThreeMonthMap = null;
|
4366 |
this.sendMailOfHtmlFormat(customRetailer.getEmail(), sb.toString(), null, subject);
|
| 4404 |
|
4367 |
|
| 4405 |
Map<Integer, List<HygieneData>> partnerHygieneDataRecentMonth = null;
|
4368 |
}
|
| 4406 |
|
4369 |
|
| 4407 |
if (!hygieneDataLastThreeMonth.isEmpty()) {
|
4370 |
}
|
| 4408 |
partnerHygieneLastThreeMonthMap = hygieneDataLastThreeMonth.stream()
|
4371 |
|
| 4409 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
4372 |
}
|
| 4410 |
|
4373 |
|
| 4411 |
}
|
4374 |
public void hygineAlertForInternalTeam() throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 4412 |
|
4375 |
|
| 4413 |
if (!hygieneDataRecentMonth.isEmpty()) {
|
4376 |
List<String> remarks = new ArrayList<>();
|
| 4414 |
partnerHygieneDataRecentMonth = hygieneDataRecentMonth.stream()
|
4377 |
remarks.add("Out of Service");
|
| 4415 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
4378 |
remarks.add("Duplicate number");
|
| 4416 |
}
|
4379 |
remarks.add("Partner number");
|
| 4417 |
|
4380 |
List<HygieneData> hygieneDataLastThreeMonth = hygieneDataRepository
|
| 4418 |
for (Entry<String, Set<Integer>> storeGuyEntry : storeGuyMap.entrySet()) {
|
4381 |
.selectDisposedDateAndRemarks(
|
| 4419 |
|
4382 |
LocalDate.now().withDayOfMonth(1).minusMonths(3).atStartOfDay(), LocalDate.now().minusMonths(1)
|
| 4420 |
String email = storeGuyEntry.getKey();
|
4383 |
.withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth()).atTime(LocalTime.MAX),
|
| 4421 |
|
4384 |
remarks);
|
| 4422 |
List<Integer> fofoIds = new ArrayList<>(storeGuyEntry.getValue());
|
4385 |
|
| 4423 |
|
4386 |
List<HygieneData> hygieneDataRecentMonth = hygieneDataRepository
|
| 4424 |
Map<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthData = new HashMap<>();
|
4387 |
.selectDisposedDateAndRemarks(LocalDate.now().withDayOfMonth(1), remarks);
|
| 4425 |
Map<Integer, Map<LocalDate, List<HygieneData>>> partnerDateWiseData = new HashMap<>();
|
4388 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 4426 |
for (Integer fofoId : fofoIds) {
|
4389 |
Map<Integer, List<HygieneData>> partnerHygieneLastThreeMonthMap = null;
|
| 4427 |
|
4390 |
|
| 4428 |
partnerYearMonthData.put(fofoId, null);
|
4391 |
Map<Integer, List<HygieneData>> partnerHygieneDataRecentMonth = null;
|
| 4429 |
partnerDateWiseData.put(fofoId, null);
|
4392 |
|
| 4430 |
if (!partnerHygieneLastThreeMonthMap.isEmpty()) {
|
4393 |
if (!hygieneDataLastThreeMonth.isEmpty()) {
|
| 4431 |
List<HygieneData> hygienes = partnerHygieneLastThreeMonthMap.get(fofoId);
|
4394 |
partnerHygieneLastThreeMonthMap = hygieneDataLastThreeMonth.stream()
|
| 4432 |
|
4395 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 4433 |
if (hygienes != null) {
|
4396 |
|
| 4434 |
Map<YearMonth, List<HygieneData>> yearMonthData = hygienes.stream()
|
4397 |
}
|
| 4435 |
.collect(Collectors.groupingBy(x -> YearMonth.from(x.getDisposedTimestamp())));
|
4398 |
|
| 4436 |
|
4399 |
if (!hygieneDataRecentMonth.isEmpty()) {
|
| 4437 |
partnerYearMonthData.put(fofoId, yearMonthData);
|
4400 |
partnerHygieneDataRecentMonth = hygieneDataRecentMonth.stream()
|
| 4438 |
|
4401 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 4439 |
}
|
4402 |
}
|
| 4440 |
List<HygieneData> dateWiseHygienes = partnerHygieneDataRecentMonth.get(fofoId);
|
4403 |
|
| 4441 |
|
4404 |
for (Entry<String, Set<Integer>> storeGuyEntry : storeGuyMap.entrySet()) {
|
| 4442 |
if (dateWiseHygienes != null) {
|
4405 |
|
| 4443 |
|
4406 |
String email = storeGuyEntry.getKey();
|
| 4444 |
Map<LocalDate, List<HygieneData>> dateWiseData = hygienes.stream()
|
4407 |
|
| 4445 |
.collect(Collectors.groupingBy(x -> (x.getDisposedTimestamp()).toLocalDate()));
|
4408 |
List<Integer> fofoIds = new ArrayList<>(storeGuyEntry.getValue());
|
| 4446 |
|
4409 |
|
| 4447 |
partnerDateWiseData.put(fofoId, dateWiseData);
|
4410 |
Map<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthData = new HashMap<>();
|
| 4448 |
|
4411 |
Map<Integer, Map<LocalDate, List<HygieneData>>> partnerDateWiseData = new HashMap<>();
|
| 4449 |
}
|
4412 |
for (Integer fofoId : fofoIds) {
|
| 4450 |
|
4413 |
|
| 4451 |
}
|
4414 |
partnerYearMonthData.put(fofoId, null);
|
| 4452 |
|
4415 |
partnerDateWiseData.put(fofoId, null);
|
| 4453 |
}
|
4416 |
if (!partnerHygieneLastThreeMonthMap.isEmpty()) {
|
| 4454 |
|
4417 |
List<HygieneData> hygienes = partnerHygieneLastThreeMonthMap.get(fofoId);
|
| 4455 |
String subject = "Customer Info - Hygiene Alert";
|
4418 |
|
| 4456 |
|
4419 |
if (hygienes != null) {
|
| 4457 |
LOGGER.info("hygieneData {}", partnerDateWiseData.values());
|
4420 |
Map<YearMonth, List<HygieneData>> yearMonthData = hygienes.stream()
|
| 4458 |
|
4421 |
.collect(Collectors.groupingBy(x -> YearMonth.from(x.getDisposedTimestamp())));
|
| 4459 |
boolean partnerDateWise = partnerDateWiseData.values().stream().allMatch(Objects::isNull);
|
4422 |
|
| 4460 |
|
4423 |
partnerYearMonthData.put(fofoId, yearMonthData);
|
| 4461 |
boolean partnerYearMonth = partnerYearMonthData.values().stream().allMatch(Objects::isNull);
|
4424 |
|
| 4462 |
|
4425 |
}
|
| 4463 |
if (!partnerDateWise && !partnerYearMonth) {
|
4426 |
List<HygieneData> dateWiseHygienes = partnerHygieneDataRecentMonth.get(fofoId);
|
| 4464 |
String sb = this.getMessageHygieneAlertForPartner(partnerYearMonthData, partnerDateWiseData);
|
4427 |
|
| 4465 |
this.sendMailOfHtmlFormat(email, sb, null, subject);
|
4428 |
if (dateWiseHygienes != null) {
|
| 4466 |
}
|
4429 |
|
| 4467 |
|
4430 |
Map<LocalDate, List<HygieneData>> dateWiseData = hygienes.stream()
|
| 4468 |
}
|
4431 |
.collect(Collectors.groupingBy(x -> (x.getDisposedTimestamp()).toLocalDate()));
|
| 4469 |
|
4432 |
|
| 4470 |
}
|
4433 |
partnerDateWiseData.put(fofoId, dateWiseData);
|
| 4471 |
|
4434 |
|
| 4472 |
private String getMessageHygieneAlertForPartner(
|
4435 |
}
|
| 4473 |
Map<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthData,
|
4436 |
|
| 4474 |
Map<Integer, Map<LocalDate, List<HygieneData>>> partnerDateWiseData) {
|
4437 |
}
|
| 4475 |
|
4438 |
|
| 4476 |
Map<Integer, CustomRetailer> customeRetailerMap = retailerService.getAllFofoRetailers();
|
4439 |
}
|
| 4477 |
|
4440 |
|
| 4478 |
LocalDateTime startDate = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
4441 |
String subject = "Customer Info - Hygiene Alert";
|
| 4479 |
LocalDateTime endDate = LocalDateTime.now();
|
4442 |
|
| 4480 |
|
4443 |
LOGGER.info("hygieneData {}", partnerDateWiseData.values());
|
| 4481 |
LocalDateTime startYearMonth = LocalDate.now().withDayOfMonth(1).minusMonths(3).atStartOfDay();
|
4444 |
|
| 4482 |
LocalDateTime endYearMonth = LocalDate.now().minusMonths(1)
|
4445 |
boolean partnerDateWise = partnerDateWiseData.values().stream().allMatch(Objects::isNull);
|
| 4483 |
.withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth()).atTime(LocalTime.MAX);
|
4446 |
|
| 4484 |
|
4447 |
boolean partnerYearMonth = partnerYearMonthData.values().stream().allMatch(Objects::isNull);
|
| 4485 |
DateTimeFormatter dateYearMonthFormatter = DateTimeFormatter.ofPattern("MMM''uu");
|
4448 |
|
| 4486 |
|
4449 |
if (!partnerDateWise && !partnerYearMonth) {
|
| 4487 |
List<YearMonth> yearMonthRange = new ArrayList<>();
|
4450 |
String sb = this.getMessageHygieneAlertForPartner(partnerYearMonthData, partnerDateWiseData);
|
| 4488 |
yearMonthRange.add(YearMonth.from(startYearMonth));
|
4451 |
this.sendMailOfHtmlFormat(email, sb, null, subject);
|
| 4489 |
|
4452 |
}
|
| 4490 |
yearMonthRange.add(YearMonth.from(startYearMonth.plusMonths(1)));
|
4453 |
|
| 4491 |
|
4454 |
}
|
| 4492 |
yearMonthRange.add(YearMonth.from(endYearMonth));
|
4455 |
|
| 4493 |
|
4456 |
}
|
| 4494 |
long noOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate.plusDays(1));
|
4457 |
|
| 4495 |
|
4458 |
private String getMessageHygieneAlertForPartner(
|
| 4496 |
List<LocalDate> dateRange = Stream.iterate(startDate.toLocalDate(), date -> date.plusDays(1))
|
4459 |
Map<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthData,
|
| 4497 |
.limit(noOfDaysBetween).collect(Collectors.toList());
|
4460 |
Map<Integer, Map<LocalDate, List<HygieneData>>> partnerDateWiseData) {
|
| 4498 |
|
4461 |
|
| 4499 |
StringBuilder sb = new StringBuilder();
|
4462 |
Map<Integer, CustomRetailer> customeRetailerMap = retailerService.getAllFofoRetailers();
|
| 4500 |
sb.append("<html><body><p>Hi,"
|
4463 |
|
| 4501 |
+ "</p><br/><p>Kindly advise below mentioned partner to input correct details in the system else this will hinder all our marketing initiatives to bring this customer back to our smartdukaan or cross sell any product from partner's inventory.\n"
|
4464 |
LocalDateTime startDate = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
| 4502 |
+ " </p>" + "<p>Kindly ensure going forward that the details are correct so to avoid 1% margin loss.\n"
|
4465 |
LocalDateTime endDate = LocalDateTime.now();
|
| 4503 |
+ "</p><p>In case the data is found to be incorrect there is a loss of 1% margin on this sales under SmartDukaan hygiene guidelines.\n</p>"
|
4466 |
|
| 4504 |
|
4467 |
LocalDateTime startYearMonth = LocalDate.now().withDayOfMonth(1).minusMonths(3).atStartOfDay();
|
| 4505 |
+ "<table style='border:1px solid black ;padding: 5px';>");
|
4468 |
LocalDateTime endYearMonth = LocalDate.now().minusMonths(1)
|
| 4506 |
sb.append("<tbody>\n" + " " + " " + "<tr>\n");
|
4469 |
.withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth()).atTime(LocalTime.MAX);
|
| 4507 |
sb.append("<th style='border:1px solid black;padding: 5px'>Partner Name</th>\n");
|
4470 |
|
| 4508 |
|
4471 |
DateTimeFormatter dateYearMonthFormatter = DateTimeFormatter.ofPattern("MMM''uu");
|
| 4509 |
for (YearMonth yearMonth : yearMonthRange) {
|
4472 |
|
| 4510 |
sb.append("<th style='border:1px solid black;padding: 5px'>" + yearMonth.format(dateYearMonthFormatter)
|
4473 |
List<YearMonth> yearMonthRange = new ArrayList<>();
|
| 4511 |
+ "</th>\n");
|
4474 |
yearMonthRange.add(YearMonth.from(startYearMonth));
|
| 4512 |
}
|
4475 |
|
| 4513 |
|
4476 |
yearMonthRange.add(YearMonth.from(startYearMonth.plusMonths(1)));
|
| 4514 |
for (LocalDate localDate : dateRange) {
|
4477 |
|
| 4515 |
sb.append("<th style='border:1px solid black;padding: 5px'>" + localDate + "</th>\n");
|
4478 |
yearMonthRange.add(YearMonth.from(endYearMonth));
|
| 4516 |
}
|
4479 |
|
| 4517 |
|
4480 |
long noOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate.plusDays(1));
|
| 4518 |
sb.append("</tr>\n");
|
4481 |
|
| 4519 |
|
4482 |
List<LocalDate> dateRange = Stream.iterate(startDate.toLocalDate(), date -> date.plusDays(1))
|
| 4520 |
for (Entry<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthEntry : partnerYearMonthData
|
4483 |
.limit(noOfDaysBetween).collect(Collectors.toList());
|
| 4521 |
.entrySet()) {
|
4484 |
|
| 4522 |
|
4485 |
StringBuilder sb = new StringBuilder();
|
| 4523 |
int fofoId = partnerYearMonthEntry.getKey();
|
4486 |
sb.append("<html><body><p>Hi,"
|
| 4524 |
|
4487 |
+ "</p><br/><p>Kindly advise below mentioned partner to input correct details in the system else this will hinder all our marketing initiatives to bring this customer back to our smartdukaan or cross sell any product from partner's inventory.\n"
|
| 4525 |
Map<YearMonth, List<HygieneData>> yearMonthData = partnerYearMonthEntry.getValue();
|
4488 |
+ " </p>" + "<p>Kindly ensure going forward that the details are correct so to avoid 1% margin loss.\n"
|
| 4526 |
|
4489 |
+ "</p><p>In case the data is found to be incorrect there is a loss of 1% margin on this sales under SmartDukaan hygiene guidelines.\n</p>"
|
| 4527 |
Map<LocalDate, List<HygieneData>> dateWiseData = partnerDateWiseData.get(fofoId);
|
4490 |
|
| 4528 |
|
4491 |
+ "<table style='border:1px solid black ;padding: 5px';>");
|
| 4529 |
if (yearMonthData == null && dateWiseData == null) {
|
4492 |
sb.append("<tbody>\n" + " " + " " + "<tr>\n");
|
| 4530 |
continue;
|
4493 |
sb.append("<th style='border:1px solid black;padding: 5px'>Partner Name</th>\n");
|
| 4531 |
}
|
4494 |
|
| 4532 |
|
4495 |
for (YearMonth yearMonth : yearMonthRange) {
|
| 4533 |
sb.append("<tr>");
|
4496 |
sb.append("<th style='border:1px solid black;padding: 5px'>" + yearMonth.format(dateYearMonthFormatter)
|
| 4534 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
4497 |
+ "</th>\n");
|
| 4535 |
+ customeRetailerMap.get(fofoId).getBusinessName() + "</td>\n");
|
4498 |
}
|
| 4536 |
for (YearMonth yearMonth : yearMonthRange) {
|
4499 |
|
| 4537 |
|
4500 |
for (LocalDate localDate : dateRange) {
|
| 4538 |
if (yearMonthData == null) {
|
4501 |
sb.append("<th style='border:1px solid black;padding: 5px'>" + localDate + "</th>\n");
|
| 4539 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
4502 |
}
|
| 4540 |
|
4503 |
|
| 4541 |
} else {
|
4504 |
sb.append("</tr>\n");
|
| 4542 |
List<HygieneData> hygieneList = yearMonthData.get(yearMonth);
|
4505 |
|
| 4543 |
|
4506 |
for (Entry<Integer, Map<YearMonth, List<HygieneData>>> partnerYearMonthEntry : partnerYearMonthData
|
| 4544 |
if (hygieneList != null) {
|
4507 |
.entrySet()) {
|
| 4545 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + hygieneList.size() + "</td>\n");
|
4508 |
|
| 4546 |
|
4509 |
int fofoId = partnerYearMonthEntry.getKey();
|
| 4547 |
} else {
|
4510 |
|
| 4548 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
4511 |
Map<YearMonth, List<HygieneData>> yearMonthData = partnerYearMonthEntry.getValue();
|
| 4549 |
|
4512 |
|
| 4550 |
}
|
4513 |
Map<LocalDate, List<HygieneData>> dateWiseData = partnerDateWiseData.get(fofoId);
|
| 4551 |
}
|
4514 |
|
| 4552 |
}
|
4515 |
if (yearMonthData == null && dateWiseData == null) {
|
| 4553 |
|
4516 |
continue;
|
| 4554 |
for (LocalDate localDate : dateRange) {
|
4517 |
}
|
| 4555 |
|
4518 |
|
| 4556 |
if (dateWiseData == null) {
|
4519 |
sb.append("<tr>");
|
| 4557 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
4520 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 4558 |
|
4521 |
+ customeRetailerMap.get(fofoId).getBusinessName() + "</td>\n");
|
| 4559 |
} else {
|
4522 |
for (YearMonth yearMonth : yearMonthRange) {
|
| 4560 |
List<HygieneData> hygieneList = dateWiseData.get(localDate);
|
4523 |
|
| 4561 |
|
4524 |
if (yearMonthData == null) {
|
| 4562 |
if (hygieneList != null) {
|
4525 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
| 4563 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + hygieneList.size() + "</td>\n");
|
4526 |
|
| 4564 |
|
4527 |
} else {
|
| 4565 |
} else {
|
4528 |
List<HygieneData> hygieneList = yearMonthData.get(yearMonth);
|
| 4566 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
4529 |
|
| 4567 |
|
4530 |
if (hygieneList != null) {
|
| 4568 |
}
|
4531 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + hygieneList.size() + "</td>\n");
|
| 4569 |
}
|
4532 |
|
| 4570 |
}
|
4533 |
} else {
|
| 4571 |
sb.append("</tr>");
|
4534 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
| 4572 |
|
4535 |
|
| 4573 |
}
|
4536 |
}
|
| 4574 |
|
4537 |
}
|
| 4575 |
sb.append("</tbody></table></body></html>");
|
4538 |
}
|
| 4576 |
|
4539 |
|
| 4577 |
return sb.toString();
|
4540 |
for (LocalDate localDate : dateRange) {
|
| 4578 |
}
|
4541 |
|
| 4579 |
|
4542 |
if (dateWiseData == null) {
|
| 4580 |
@Autowired
|
4543 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
| 4581 |
private MonthlyTargetRepository monthlyTargetRepository;
|
4544 |
|
| 4582 |
|
4545 |
} else {
|
| 4583 |
public void monthlyTargetForPartner() throws MessagingException, ProfitMandiBusinessException, IOException {
|
4546 |
List<HygieneData> hygieneList = dateWiseData.get(localDate);
|
| 4584 |
|
4547 |
|
| 4585 |
LocalDateTime curDate = LocalDateTime.now();
|
4548 |
if (hygieneList != null) {
|
| 4586 |
List<MonthlyTarget> monthlyTargets = monthlyTargetRepository.selectByDate(YearMonth.now());
|
4549 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + hygieneList.size() + "</td>\n");
|
| 4587 |
|
4550 |
|
| 4588 |
Map<Integer, MonthlyTarget> partnersMonthlyTarget = monthlyTargets.stream()
|
4551 |
} else {
|
| 4589 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
4552 |
sb.append("<td style='border:1px solid black;padding: 5px'>-</td>\n");
|
| 4590 |
|
4553 |
|
| 4591 |
Map<Integer, Double> secondaryMtd = orderRepository
|
4554 |
}
|
| 4592 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
4555 |
}
|
| 4593 |
Map<Integer, Double> todaytertiary = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate,
|
4556 |
}
|
| 4594 |
curDate.with(LocalTime.MAX), 0, false);
|
4557 |
sb.append("</tr>");
|
| 4595 |
|
4558 |
|
| 4596 |
String subject = "Monthly Target Vs Achievement";
|
4559 |
}
|
| 4597 |
|
4560 |
|
| 4598 |
for (Entry<Integer, MonthlyTarget> partnerMonthlyTargetEntry : partnersMonthlyTarget.entrySet()) {
|
4561 |
sb.append("</tbody></table></body></html>");
|
| 4599 |
|
4562 |
|
| 4600 |
int fofoId = partnerMonthlyTargetEntry.getKey();
|
4563 |
return sb.toString();
|
| 4601 |
|
4564 |
}
|
| 4602 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
4565 |
|
| 4603 |
|
4566 |
@Autowired
|
| 4604 |
Double purchaseTarget = partnerMonthlyTargetEntry.getValue().getPurchaseTarget();
|
4567 |
private MonthlyTargetRepository monthlyTargetRepository;
|
| 4605 |
|
4568 |
|
| 4606 |
Double saleTarget = partnerMonthlyTargetEntry.getValue().getSaleTarget();
|
4569 |
public void monthlyTargetForPartner() throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 4607 |
|
4570 |
|
| 4608 |
if (purchaseTarget > 0) {
|
4571 |
LocalDateTime curDate = LocalDateTime.now();
|
| 4609 |
Double purchase = secondaryMtd.get(fofoId);
|
4572 |
List<MonthlyTarget> monthlyTargets = monthlyTargetRepository.selectByDate(YearMonth.now());
|
| 4610 |
|
4573 |
|
| 4611 |
if (purchase == null) {
|
4574 |
Map<Integer, MonthlyTarget> partnersMonthlyTarget = monthlyTargets.stream()
|
| 4612 |
purchase = 0.0;
|
4575 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 4613 |
}
|
4576 |
|
| 4614 |
|
4577 |
Map<Integer, Double> secondaryMtd = orderRepository
|
| 4615 |
Double balanceTarget = purchaseTarget - purchase;
|
4578 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
| 4616 |
|
4579 |
Map<Integer, Double> todaytertiary = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate,
|
| 4617 |
if (balanceTarget <= 0) {
|
4580 |
curDate.with(LocalTime.MAX), 0, false);
|
| 4618 |
balanceTarget = 0.0;
|
4581 |
|
| 4619 |
}
|
4582 |
String subject = "Monthly Target Vs Achievement";
|
| 4620 |
|
4583 |
|
| 4621 |
StringBuilder sb = new StringBuilder();
|
4584 |
for (Entry<Integer, MonthlyTarget> partnerMonthlyTargetEntry : partnersMonthlyTarget.entrySet()) {
|
| 4622 |
sb.append("<html><body><p>Dear Partner,\n");
|
4585 |
|
| 4623 |
sb.append("<p>Pls note your agreed monthly target is Rs." + purchaseTarget
|
4586 |
int fofoId = partnerMonthlyTargetEntry.getKey();
|
| 4624 |
+ " and your achievement till date is Rs." + purchase + "</p>");
|
4587 |
|
| 4625 |
sb.append("<p>Pls note that your balance target is Rs." + balanceTarget + "</p>\n");
|
4588 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
| 4626 |
sb.append(
|
4589 |
|
| 4627 |
"<p>We wish you all the best and we are confident that this focussed approach towards our outlet sales will help us take our outlet to the best SmartDukaan in your city.\n"
|
4590 |
Double purchaseTarget = partnerMonthlyTargetEntry.getValue().getPurchaseTarget();
|
| 4628 |
+ "</p>\n");
|
4591 |
|
| 4629 |
|
4592 |
Double saleTarget = partnerMonthlyTargetEntry.getValue().getSaleTarget();
|
| 4630 |
this.sendMailOfHtmlFormat(customRetailer.getEmail(), sb.toString(), null, subject);
|
4593 |
|
| 4631 |
|
4594 |
if (purchaseTarget > 0) {
|
| 4632 |
// this.sendMailOfHtmlFormat("tejbeer.kaur@smartdukaan.com", sb.toString(),
|
4595 |
Double purchase = secondaryMtd.get(fofoId);
|
| 4633 |
// null, subject);
|
4596 |
|
| 4634 |
|
4597 |
if (purchase == null) {
|
| 4635 |
}
|
4598 |
purchase = 0.0;
|
| 4636 |
|
4599 |
}
|
| 4637 |
}
|
4600 |
|
| 4638 |
|
4601 |
Double balanceTarget = purchaseTarget - purchase;
|
| 4639 |
}
|
4602 |
|
| 4640 |
|
4603 |
if (balanceTarget <= 0) {
|
| 4641 |
@Autowired
|
4604 |
balanceTarget = 0.0;
|
| 4642 |
WarehouseInventoryItemRepository warehouseInventoryItemRepository;
|
4605 |
}
|
| 4643 |
|
4606 |
|
| 4644 |
public void test() throws Exception {
|
4607 |
StringBuilder sb = new StringBuilder();
|
| 4645 |
this.sendMailForSamsungRebilling();
|
4608 |
sb.append("<html><body><p>Dear Partner,\n");
|
| 4646 |
}
|
4609 |
sb.append("<p>Pls note your agreed monthly target is Rs." + purchaseTarget
|
| 4647 |
|
4610 |
+ " and your achievement till date is Rs." + purchase + "</p>");
|
| 4648 |
public void sendMailForSamsungRebilling() throws Exception {
|
4611 |
sb.append("<p>Pls note that your balance target is Rs." + balanceTarget + "</p>\n");
|
| 4649 |
List<BilledImeiModel> samsungModels = warehouseInventoryItemRepository.findByBillingDateBrand(LocalDate.now(),
|
4612 |
sb.append(
|
| 4650 |
"Samsung");
|
4613 |
"<p>We wish you all the best and we are confident that this focussed approach towards our outlet sales will help us take our outlet to the best SmartDukaan in your city.\n"
|
| 4651 |
LOGGER.info("SamsungModels {}", samsungModels);
|
4614 |
+ "</p>\n");
|
| 4652 |
samsungModels = samsungModels.stream().sorted(Comparator.comparing(x -> x.getPcmDate() == null ? -1 : 1))
|
4615 |
|
| 4653 |
.collect(Collectors.toList());
|
4616 |
this.sendMailOfHtmlFormat(customRetailer.getEmail(), sb.toString(), null, subject);
|
| 4654 |
if (samsungModels.size() > 0) {
|
4617 |
|
| 4655 |
List<String> headers = Arrays.asList("Partner Id", "Code", "Name", "City", "Brand", "Model Name",
|
4618 |
// this.sendMailOfHtmlFormat("tejbeer.kaur@smartdukaan.com", sb.toString(),
|
| 4656 |
"Model Number", "Color", "Serial Number", "Remarks");
|
4619 |
// null, subject);
|
| 4657 |
List<List<?>> rows = new ArrayList<>();
|
4620 |
|
| 4658 |
for (BilledImeiModel billedImeiModel : samsungModels) {
|
4621 |
}
|
| 4659 |
List<Serializable> row = Arrays.asList(billedImeiModel.getFofoId(), billedImeiModel.getStoreCode(),
|
4622 |
|
| 4660 |
billedImeiModel.getStoreName(), billedImeiModel.getStoreCity(), billedImeiModel.getBrand(),
|
4623 |
}
|
| 4661 |
billedImeiModel.getModelName(), billedImeiModel.getModelNumber(), billedImeiModel.getColor(),
|
4624 |
|
| 4662 |
billedImeiModel.getSerialNumber(),
|
4625 |
}
|
| 4663 |
billedImeiModel.getPcmDate() == null ? "PCM date Missing" : "Rebill Imeis");
|
4626 |
|
| 4664 |
rows.add(row);
|
4627 |
public void monthlyTargetForInternalTeam() throws MessagingException, ProfitMandiBusinessException, IOException {
|
| 4665 |
}
|
4628 |
|
| 4666 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
4629 |
LocalDateTime curDate = LocalDateTime.now();
|
| 4667 |
String[] sendToArray = new String[] { "kamini.sharma@smartdukaan.com", "praveen.sharma@smartdukaan.com" };
|
4630 |
|
| 4668 |
String fileName = "Imeis need Rebilling -" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
4631 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
| 4669 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[] { "tarun.verma@smartdukaan.com" },
|
4632 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
| 4670 |
"Samsung Rebilling IMEI Summary", "PFA", fileName, new ByteArrayResource(baos.toByteArray()));
|
4633 |
ProfitMandiConstants.TICKET_CATEGORY_MARKETING, ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
| 4671 |
}
|
4634 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
| 4672 |
}
|
4635 |
|
| 4673 |
|
4636 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false);
|
| 4674 |
public void monthlyTargetForInternalTeam() throws MessagingException, ProfitMandiBusinessException, IOException {
|
4637 |
|
| 4675 |
|
4638 |
List<MonthlyTarget> monthlyTargets = monthlyTargetRepository.selectByDate(YearMonth.now());
|
| 4676 |
LocalDateTime curDate = LocalDateTime.now();
|
4639 |
|
| 4677 |
|
4640 |
Map<Integer, CustomRetailer> customeRetailerMap = retailerService.getAllFofoRetailers();
|
| 4678 |
List<Integer> categoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
4641 |
|
| 4679 |
ProfitMandiConstants.TICKET_CATEGORY_RBM, ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
4642 |
Map<Integer, MonthlyTarget> partnersMonthlyTarget = monthlyTargets.stream()
|
| 4680 |
ProfitMandiConstants.TICKET_CATEGORY_MARKETING, ProfitMandiConstants.TICKET_CATEGORY_ACCOUNTS,
|
4643 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 4681 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
4644 |
|
| 4682 |
|
4645 |
Map<Integer, Double> secondaryMtd = orderRepository
|
| 4683 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMappingByCategoryIds(categoryIds, false);
|
4646 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
| 4684 |
|
4647 |
Map<Integer, Double> todaytertiary = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate,
|
| 4685 |
List<MonthlyTarget> monthlyTargets = monthlyTargetRepository.selectByDate(YearMonth.now());
|
4648 |
curDate.with(LocalTime.MAX), 0, false);
|
| 4686 |
|
4649 |
|
| 4687 |
Map<Integer, CustomRetailer> customeRetailerMap = retailerService.getAllFofoRetailers();
|
4650 |
String subject = "Monthly Target Vs Achievement";
|
| 4688 |
|
4651 |
|
| 4689 |
Map<Integer, MonthlyTarget> partnersMonthlyTarget = monthlyTargets.stream()
|
4652 |
for (Entry<String, Set<Integer>> storeGuyEntry : storeGuyMap.entrySet()) {
|
| 4690 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
4653 |
|
| 4691 |
|
4654 |
String email = storeGuyEntry.getKey();
|
| 4692 |
Map<Integer, Double> secondaryMtd = orderRepository
|
4655 |
|
| 4693 |
.selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
4656 |
List<Integer> fofoIds = new ArrayList<>(storeGuyEntry.getValue());
|
| 4694 |
Map<Integer, Double> todaytertiary = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate,
|
4657 |
Map<Integer, MonthlyTarget> monthlyTargetAchievement = new HashMap<>();
|
| 4695 |
curDate.with(LocalTime.MAX), 0, false);
|
4658 |
for (Integer fofoId : fofoIds) {
|
| 4696 |
|
4659 |
|
| 4697 |
String subject = "Monthly Target Vs Achievement";
|
4660 |
MonthlyTarget monthlyTarget = partnersMonthlyTarget.get(fofoId);
|
| 4698 |
|
4661 |
if (monthlyTarget != null) {
|
| 4699 |
for (Entry<String, Set<Integer>> storeGuyEntry : storeGuyMap.entrySet()) {
|
4662 |
Double purchaseTarget = monthlyTarget.getPurchaseTarget();
|
| 4700 |
|
4663 |
|
| 4701 |
String email = storeGuyEntry.getKey();
|
4664 |
Double saleTarget = monthlyTarget.getSaleTarget();
|
| 4702 |
|
4665 |
|
| 4703 |
List<Integer> fofoIds = new ArrayList<>(storeGuyEntry.getValue());
|
4666 |
if (purchaseTarget != null && purchaseTarget > 0) {
|
| 4704 |
Map<Integer, MonthlyTarget> monthlyTargetAchievement = new HashMap<>();
|
4667 |
Double purchase = secondaryMtd.get(fofoId);
|
| 4705 |
for (Integer fofoId : fofoIds) {
|
4668 |
if (purchase == null) {
|
| 4706 |
|
4669 |
purchase = 0.0;
|
| 4707 |
MonthlyTarget monthlyTarget = partnersMonthlyTarget.get(fofoId);
|
4670 |
}
|
| 4708 |
if (monthlyTarget != null) {
|
4671 |
monthlyTarget.setPurchaseAchievement(purchase);
|
| 4709 |
Double purchaseTarget = monthlyTarget.getPurchaseTarget();
|
4672 |
monthlyTargetAchievement.put(fofoId, monthlyTarget);
|
| 4710 |
|
4673 |
|
| 4711 |
Double saleTarget = monthlyTarget.getSaleTarget();
|
4674 |
}
|
| 4712 |
|
4675 |
}
|
| 4713 |
if (purchaseTarget != null && purchaseTarget > 0) {
|
4676 |
}
|
| 4714 |
Double purchase = secondaryMtd.get(fofoId);
|
4677 |
|
| 4715 |
if (purchase == null) {
|
4678 |
if (!monthlyTargetAchievement.isEmpty()) {
|
| 4716 |
purchase = 0.0;
|
4679 |
|
| 4717 |
}
|
4680 |
StringBuilder sb = new StringBuilder();
|
| 4718 |
monthlyTarget.setPurchaseAchievement(purchase);
|
4681 |
|
| 4719 |
monthlyTargetAchievement.put(fofoId, monthlyTarget);
|
4682 |
sb.append("<html><body><p>Hi,\n");
|
| 4720 |
|
4683 |
sb.append("<p>Pls note your Partners agreed monthly target foolowing are :</p>\n"
|
| 4721 |
}
|
4684 |
+ " <table style='border:1px solid black ;padding: 5px';>");
|
| 4722 |
}
|
4685 |
sb.append("<tbody>\n" + " " + " " + "<tr>\n");
|
| 4723 |
}
|
4686 |
sb.append("<th style='border:1px solid black;padding: 5px'>Partner Name</th>\n");
|
| 4724 |
|
4687 |
|
| 4725 |
if (!monthlyTargetAchievement.isEmpty()) {
|
4688 |
sb.append("<th style='border:1px solid black;padding: 5px'>Purchase Target</th>\n");
|
| 4726 |
|
4689 |
|
| 4727 |
StringBuilder sb = new StringBuilder();
|
4690 |
sb.append("<th style='border:1px solid black;padding: 5px'>Purchase Achievement</th>\n");
|
| 4728 |
|
4691 |
sb.append("</tr>\n");
|
| 4729 |
sb.append("<html><body><p>Hi,\n");
|
4692 |
|
| 4730 |
sb.append("<p>Pls note your Partners agreed monthly target foolowing are :</p>\n"
|
4693 |
for (Entry<Integer, MonthlyTarget> monthlyTargetAchievementEntry : monthlyTargetAchievement
|
| 4731 |
+ " <table style='border:1px solid black ;padding: 5px';>");
|
4694 |
.entrySet()) {
|
| 4732 |
sb.append("<tbody>\n" + " " + " " + "<tr>\n");
|
4695 |
sb.append("<tr>");
|
| 4733 |
sb.append("<th style='border:1px solid black;padding: 5px'>Partner Name</th>\n");
|
4696 |
int fofoId = monthlyTargetAchievementEntry.getKey();
|
| 4734 |
|
4697 |
|
| 4735 |
sb.append("<th style='border:1px solid black;padding: 5px'>Purchase Target</th>\n");
|
4698 |
MonthlyTarget monthlyTarget = monthlyTargetAchievementEntry.getValue();
|
| 4736 |
|
4699 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 4737 |
sb.append("<th style='border:1px solid black;padding: 5px'>Purchase Achievement</th>\n");
|
4700 |
+ customeRetailerMap.get(fofoId).getBusinessName() + "</td>\n");
|
| 4738 |
sb.append("</tr>\n");
|
4701 |
|
| 4739 |
|
4702 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + monthlyTarget.getPurchaseTarget()
|
| 4740 |
for (Entry<Integer, MonthlyTarget> monthlyTargetAchievementEntry : monthlyTargetAchievement
|
4703 |
+ "</td>\n");
|
| 4741 |
.entrySet()) {
|
4704 |
|
| 4742 |
sb.append("<tr>");
|
4705 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
| 4743 |
int fofoId = monthlyTargetAchievementEntry.getKey();
|
4706 |
+ monthlyTarget.getPurchaseAchievement() + "</td>\n");
|
| 4744 |
|
4707 |
|
| 4745 |
MonthlyTarget monthlyTarget = monthlyTargetAchievementEntry.getValue();
|
4708 |
sb.append("</tr>\n");
|
| 4746 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
4709 |
|
| 4747 |
+ customeRetailerMap.get(fofoId).getBusinessName() + "</td>\n");
|
4710 |
}
|
| 4748 |
|
4711 |
|
| 4749 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + monthlyTarget.getPurchaseTarget()
|
4712 |
this.sendMailOfHtmlFormat(email, sb.toString(), null, subject);
|
| 4750 |
+ "</td>\n");
|
4713 |
// this.sendMailOfHtmlFormat("tejbeer.kaur@smartdukaan.com", sb.toString(),
|
| 4751 |
|
4714 |
// null, subject);
|
| 4752 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
4715 |
|
| 4753 |
+ monthlyTarget.getPurchaseAchievement() + "</td>\n");
|
4716 |
}
|
| 4754 |
|
4717 |
|
| 4755 |
sb.append("</tr>\n");
|
4718 |
}
|
| 4756 |
|
4719 |
|
| 4757 |
}
|
4720 |
}
|
| 4758 |
|
4721 |
|
| 4759 |
this.sendMailOfHtmlFormat(email, sb.toString(), null, subject);
|
4722 |
@Autowired
|
| 4760 |
// this.sendMailOfHtmlFormat("tejbeer.kaur@smartdukaan.com", sb.toString(),
|
4723 |
private WebListingRepository webListingRepository;
|
| 4761 |
// null, subject);
|
4724 |
|
| 4762 |
|
4725 |
@Autowired
|
| 4763 |
}
|
4726 |
private WebProductListingRepository webProductListingRepository;
|
| 4764 |
|
4727 |
|
| 4765 |
}
|
4728 |
public void pushDataToSolr() throws Exception {
|
| 4766 |
|
4729 |
fofoSolr.pushData();
|
| 4767 |
}
|
4730 |
}
|
| 4768 |
|
4731 |
|
| 4769 |
@Autowired
|
4732 |
public void getBestSeller() throws ProfitMandiBusinessException {
|
| 4770 |
private WebListingRepository webListingRepository;
|
4733 |
WebListing webListing = webListingRepository.selectByUrl("partner-best-sellers");
|
| 4771 |
|
4734 |
|
| 4772 |
@Autowired
|
4735 |
List<WebProductListing> webProductListings = webProductListingRepository
|
| 4773 |
private WebProductListingRepository webProductListingRepository;
|
4736 |
.selectAllByWebListingId(webListing.getId());
|
| 4774 |
|
4737 |
|
| 4775 |
public void pushDataToSolr() throws Exception {
|
4738 |
List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30),
|
| 4776 |
fofoSolr.pushData();
|
4739 |
LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);
|
| 4777 |
}
|
4740 |
|
| 4778 |
|
4741 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| 4779 |
public void getBestSeller() throws ProfitMandiBusinessException {
|
4742 |
if (!catalogItemIds.isEmpty()) {
|
| 4780 |
WebListing webListing = webListingRepository.selectByUrl("partner-best-sellers");
|
4743 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 4781 |
|
4744 |
int count = 0;
|
| 4782 |
List<Integer> catalogItemIds = orderRepository.selectAllOrderWeight(LocalDateTime.now().minusDays(30),
|
4745 |
for (Integer catalogItemId : catalogItemIds) {
|
| 4783 |
LocalDateTime.now(), OrderStatus.DELIVERY_SUCCESS);
|
4746 |
|
| 4784 |
Map<Integer, List<Item>> catalogItemsMap = itemRepository.selectAllByCatalogIds(new HashSet<>(catalogItemIds))
|
4747 |
WebProductListing webProductListing = new WebProductListing();
|
| 4785 |
.stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
4748 |
webProductListing.setEntityId(catalogItemId);
|
| 4786 |
|
4749 |
webProductListing.setWebListingId(webListing.getId());
|
| 4787 |
Map<String, Integer> brandCount = new HashMap<>();
|
4750 |
count = count + 1;
|
| 4788 |
|
4751 |
|
| 4789 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
4752 |
webProductListing.setRank(count + 1);
|
| 4790 |
if (!catalogItemIds.isEmpty()) {
|
4753 |
webProductListingRepository.persist(webProductListing);
|
| 4791 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
4754 |
|
| 4792 |
int count = 0;
|
4755 |
}
|
| 4793 |
for (Integer catalogItemId : catalogItemIds) {
|
4756 |
|
| 4794 |
|
4757 |
}
|
| 4795 |
List<Item> items = catalogItemsMap.get(catalogItemId);
|
4758 |
}
|
| 4796 |
|
4759 |
|
| 4797 |
String brand = items.get(0).getBrand();
|
4760 |
public void getPriceDrop() throws ProfitMandiBusinessException {
|
| 4798 |
int brandItemCount = 0;
|
4761 |
WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");
|
| 4799 |
|
4762 |
|
| 4800 |
if (brandCount.containsKey(items.get(0).getBrand())) {
|
4763 |
List<WebProductListing> webProductListings = webProductListingRepository
|
| 4801 |
brandItemCount = brandCount.get(brand);
|
4764 |
.selectAllByWebListingId(webListing.getId());
|
| 4802 |
|
4765 |
|
| 4803 |
}
|
4766 |
Set<Integer> catalogItemIds = priceDropRepository
|
| 4804 |
|
4767 |
.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream()
|
| 4805 |
brandCount.put(brand, brandItemCount + 1);
|
4768 |
.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 4806 |
|
4769 |
|
| 4807 |
if (brandCount.get(brand) > 3) {
|
4770 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| 4808 |
continue;
|
4771 |
if (!catalogItemIds.isEmpty()) {
|
| 4809 |
}
|
4772 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 4810 |
|
4773 |
int count = 0;
|
| 4811 |
WebProductListing webProductListing = new WebProductListing();
|
4774 |
for (Integer catalogItemId : catalogItemIds) {
|
| 4812 |
webProductListing.setEntityId(catalogItemId);
|
4775 |
|
| 4813 |
webProductListing.setWebListingId(webListing.getId());
|
4776 |
WebProductListing webProductListing = new WebProductListing();
|
| 4814 |
count = count + 1;
|
4777 |
webProductListing.setEntityId(catalogItemId);
|
| 4815 |
|
4778 |
webProductListing.setWebListingId(webListing.getId());
|
| 4816 |
webProductListing.setRank(count + 1);
|
4779 |
count = count + 1;
|
| 4817 |
webProductListingRepository.persist(webProductListing);
|
4780 |
webProductListing.setRank(count);
|
| 4818 |
|
4781 |
webProductListingRepository.persist(webProductListing);
|
| 4819 |
if (count == 12) {
|
4782 |
|
| 4820 |
break;
|
4783 |
}
|
| 4821 |
}
|
4784 |
|
| 4822 |
|
4785 |
}
|
| 4823 |
}
|
4786 |
}
|
| 4824 |
|
4787 |
|
| 4825 |
}
|
4788 |
public void getNewLaunches() throws ProfitMandiBusinessException {
|
| 4826 |
}
|
4789 |
WebListing webListing = webListingRepository.selectByUrl("new-launches");
|
| 4827 |
|
4790 |
|
| 4828 |
public void getPriceDrop() throws ProfitMandiBusinessException {
|
4791 |
Set<Integer> itemIds = tagListingRepository
|
| 4829 |
WebListing webListing = webListingRepository.selectByUrl("partner-price-drop");
|
4792 |
.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now()).stream()
|
| 4830 |
|
4793 |
.map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 4831 |
List<Integer> catalogItemIds = priceDropRepository
|
4794 |
|
| 4832 |
.selectAllByDatesBetweenSortByDate(LocalDateTime.now().minusDays(30), LocalDateTime.now().plusDays(1))
|
4795 |
Set<Integer> catalogItemIds = itemRepository.selectByIds(itemIds).stream().map(x -> x.getCatalogItemId())
|
| 4833 |
.stream().map(x -> x.getCatalogItemId()).distinct().collect(Collectors.toList());
|
4796 |
.collect(Collectors.toSet());
|
| 4834 |
|
4797 |
|
| 4835 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
4798 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| 4836 |
if (!catalogItemIds.isEmpty()) {
|
4799 |
if (!catalogItemIds.isEmpty()) {
|
| 4837 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
4800 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 4838 |
int count = 0;
|
4801 |
int count = 0;
|
| 4839 |
for (Integer catalogItemId : catalogItemIds) {
|
4802 |
for (Integer catalogItemId : catalogItemIds) {
|
| 4840 |
|
4803 |
|
| 4841 |
WebProductListing webProductListing = new WebProductListing();
|
4804 |
WebProductListing webProductListing = new WebProductListing();
|
| 4842 |
webProductListing.setEntityId(catalogItemId);
|
4805 |
webProductListing.setEntityId(catalogItemId);
|
| 4843 |
webProductListing.setWebListingId(webListing.getId());
|
4806 |
webProductListing.setWebListingId(webListing.getId());
|
| 4844 |
count = count + 1;
|
4807 |
count = count + 1;
|
| 4845 |
webProductListing.setRank(count);
|
4808 |
webProductListing.setRank(count);
|
| 4846 |
webProductListingRepository.persist(webProductListing);
|
4809 |
webProductListingRepository.persist(webProductListing);
|
| 4847 |
|
4810 |
|
| 4848 |
}
|
4811 |
}
|
| 4849 |
|
4812 |
|
| 4850 |
}
|
4813 |
}
|
| 4851 |
}
|
4814 |
}
|
| 4852 |
|
4815 |
|
| 4853 |
public void getNewLaunches() throws ProfitMandiBusinessException {
|
4816 |
public void getSpecialSupport() throws ProfitMandiBusinessException {
|
| 4854 |
WebListing webListing = webListingRepository.selectByUrl("new-launches");
|
4817 |
WebListing webListing = webListingRepository.selectByUrl("special-support");
|
| 4855 |
|
4818 |
|
| 4856 |
List<Integer> catalogItemIds = tagListingRepository.getRecentLanuch(LocalDate.now().minusDays(30),
|
4819 |
List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT,
|
| 4857 |
LocalDate.now().plusDays(1));
|
4820 |
LocalDate.now().plusDays(1));
|
| 4858 |
|
4821 |
|
| 4859 |
if (!catalogItemIds.isEmpty()) {
|
4822 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| 4860 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
4823 |
if (!catalogItemIds.isEmpty()) {
|
| 4861 |
int count = 0;
|
4824 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 4862 |
for (Integer catalogItemId : catalogItemIds) {
|
4825 |
int count = 0;
|
| 4863 |
|
4826 |
for (Integer catalogItemId : catalogItemIds) {
|
| 4864 |
WebProductListing webProductListing = new WebProductListing();
|
4827 |
|
| 4865 |
webProductListing.setEntityId(catalogItemId);
|
4828 |
WebProductListing webProductListing = new WebProductListing();
|
| 4866 |
webProductListing.setWebListingId(webListing.getId());
|
4829 |
webProductListing.setEntityId(catalogItemId);
|
| 4867 |
count = count + 1;
|
4830 |
webProductListing.setWebListingId(webListing.getId());
|
| 4868 |
webProductListing.setRank(count);
|
4831 |
count = count + 1;
|
| 4869 |
webProductListingRepository.persist(webProductListing);
|
4832 |
webProductListing.setRank(count);
|
| 4870 |
|
4833 |
webProductListingRepository.persist(webProductListing);
|
| 4871 |
}
|
4834 |
|
| 4872 |
|
4835 |
}
|
| 4873 |
}
|
4836 |
|
| 4874 |
}
|
4837 |
}
|
| 4875 |
|
4838 |
}
|
| 4876 |
public void getSpecialSupport() throws ProfitMandiBusinessException {
|
4839 |
|
| 4877 |
WebListing webListing = webListingRepository.selectByUrl("special-support");
|
4840 |
public void getUpgradeOffer() throws ProfitMandiBusinessException {
|
| 4878 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
4841 |
WebListing webListing = webListingRepository.selectByUrl("upgrade-offer");
|
| 4879 |
|
4842 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
| 4880 |
List<Integer> catalogItemIds = schemeRepository.getActiveScheme(SchemeType.SPECIAL_SUPPORT,
|
4843 |
|
| 4881 |
LocalDate.now().plusDays(1));
|
4844 |
List<Integer> customerOfferIds = customerOfferRepository.selectOffers(LocalDate.now()).stream()
|
| 4882 |
|
4845 |
.map(x -> x.getId()).collect(Collectors.toList());
|
| 4883 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
4846 |
|
| 4884 |
if (!catalogItemIds.isEmpty()) {
|
4847 |
List<Integer> catalogItemIds = customerOfferItemRepository
|
| 4885 |
int count = 0;
|
4848 |
.selectByOfferIdsRange(customerOfferIds, LocalDate.now()).stream().map(x -> x.getCatalogId()).distinct()
|
| 4886 |
for (Integer catalogItemId : catalogItemIds) {
|
4849 |
.collect(Collectors.toList());
|
| 4887 |
|
4850 |
|
| 4888 |
WebProductListing webProductListing = new WebProductListing();
|
4851 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
| 4889 |
webProductListing.setEntityId(catalogItemId);
|
4852 |
if (!catalogItemIds.isEmpty()) {
|
| 4890 |
webProductListing.setWebListingId(webListing.getId());
|
4853 |
int count = 0;
|
| 4891 |
count = count + 1;
|
4854 |
for (Integer catalogItemId : catalogItemIds) {
|
| 4892 |
webProductListing.setRank(count);
|
4855 |
|
| 4893 |
webProductListingRepository.persist(webProductListing);
|
4856 |
WebProductListing webProductListing = new WebProductListing();
|
| 4894 |
|
4857 |
webProductListing.setEntityId(catalogItemId);
|
| 4895 |
}
|
4858 |
webProductListing.setWebListingId(webListing.getId());
|
| 4896 |
|
4859 |
count = count + 1;
|
| 4897 |
}
|
4860 |
webProductListing.setRank(count);
|
| 4898 |
}
|
4861 |
webProductListingRepository.persist(webProductListing);
|
| 4899 |
|
- |
|
| 4900 |
public void getUpgradeOffer() throws ProfitMandiBusinessException {
|
- |
|
| 4901 |
WebListing webListing = webListingRepository.selectByUrl("upgrade-offer");
|
- |
|
| 4902 |
webProductListingRepository.deleteByEqual(webListing.getId());
|
- |
|
| 4903 |
|
- |
|
| 4904 |
List<Integer> customerOfferIds = customerOfferRepository.selectOffers(LocalDate.now()).stream()
|
- |
|
| 4905 |
.map(x -> x.getId()).collect(Collectors.toList());
|
- |
|
| 4906 |
|
- |
|
| 4907 |
List<Integer> catalogItemIds = customerOfferItemRepository
|
- |
|
| 4908 |
.selectByOfferIdsRange(customerOfferIds, LocalDate.now()).stream().map(x -> x.getCatalogId()).distinct()
|
- |
|
| 4909 |
.collect(Collectors.toList());
|
- |
|
| 4910 |
|
- |
|
| 4911 |
LOGGER.info("catalogItemIds {}", catalogItemIds);
|
- |
|
| 4912 |
if (!catalogItemIds.isEmpty()) {
|
- |
|
| 4913 |
int count = 0;
|
- |
|
| 4914 |
for (Integer catalogItemId : catalogItemIds) {
|
- |
|
| 4915 |
|
- |
|
| 4916 |
WebProductListing webProductListing = new WebProductListing();
|
- |
|
| 4917 |
webProductListing.setEntityId(catalogItemId);
|
- |
|
| 4918 |
webProductListing.setWebListingId(webListing.getId());
|
- |
|
| 4919 |
count = count + 1;
|
- |
|
| 4920 |
webProductListing.setRank(count);
|
- |
|
| 4921 |
webProductListingRepository.persist(webProductListing);
|
- |
|
| 4922 |
|
4862 |
|
| 4923 |
}
|
4863 |
}
|
| 4924 |
|
4864 |
|
| 4925 |
}
|
4865 |
}
|
| 4926 |
}
|
4866 |
}
|
| 4927 |
|
4867 |
|
| 4928 |
}
|
4868 |
}
|
| 4929 |
// 2284'
|
4869 |
// 2284'
|
| 4930 |
|
4870 |
|