Subversion Repositories SmartDukaan

Rev

Rev 34701 | Rev 34703 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
34306 ranu 1
package com.smartdukaan.cron.scheduled;
2
 
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
34619 ranu 4
import com.spice.profitmandi.common.model.BrandStockPrice;
34606 ranu 5
import com.spice.profitmandi.common.model.CustomRetailer;
34321 ranu 6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
34619 ranu 7
import com.spice.profitmandi.common.util.FileUtil;
8
import com.spice.profitmandi.common.util.FormattingUtils;
9
import com.spice.profitmandi.common.util.Utils;
34321 ranu 10
import com.spice.profitmandi.dao.cart.CartService;
34450 ranu 11
import com.spice.profitmandi.dao.cart.SmartCartService;
34321 ranu 12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
34606 ranu 13
import com.spice.profitmandi.dao.entity.fofo.*;
14
import com.spice.profitmandi.dao.entity.logistics.AST;
15
import com.spice.profitmandi.dao.entity.logistics.ASTRepository;
16
import com.spice.profitmandi.dao.entity.logistics.AreaRepository;
34619 ranu 17
import com.spice.profitmandi.dao.entity.transaction.*;
34321 ranu 18
import com.spice.profitmandi.dao.entity.user.User;
19
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
34619 ranu 20
import com.spice.profitmandi.dao.enumuration.transaction.LoanReferenceType;
34641 ranu 21
import com.spice.profitmandi.dao.model.*;
34606 ranu 22
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
34321 ranu 23
import com.spice.profitmandi.dao.repository.cs.CsService;
24
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
34606 ranu 25
import com.spice.profitmandi.dao.repository.fofo.*;
26
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
34619 ranu 27
import com.spice.profitmandi.dao.repository.transaction.*;
34321 ranu 28
import com.spice.profitmandi.dao.repository.user.UserRepository;
34655 ranu 29
import com.spice.profitmandi.service.PartnerStatsService;
34641 ranu 30
import com.spice.profitmandi.service.RbmTargetService;
34619 ranu 31
import com.spice.profitmandi.service.inventory.InventoryService;
34308 ranu 32
import com.spice.profitmandi.service.transaction.SDCreditService;
34606 ranu 33
import com.spice.profitmandi.service.user.RetailerService;
34619 ranu 34
import com.spice.profitmandi.service.wallet.WalletService;
34606 ranu 35
import in.shop2020.model.v1.order.OrderStatus;
34619 ranu 36
import in.shop2020.model.v1.order.WalletReferenceType;
37
import org.apache.commons.io.output.ByteArrayOutputStream;
34306 ranu 38
import org.apache.logging.log4j.LogManager;
39
import org.apache.logging.log4j.Logger;
34641 ranu 40
import org.apache.poi.ss.usermodel.*;
41
import org.apache.poi.xssf.usermodel.XSSFColor;
34619 ranu 42
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
34306 ranu 43
import org.springframework.beans.factory.annotation.Autowired;
34619 ranu 44
import org.springframework.beans.factory.annotation.Qualifier;
34306 ranu 45
import org.springframework.beans.factory.annotation.Value;
34619 ranu 46
import org.springframework.core.io.ByteArrayResource;
34321 ranu 47
import org.springframework.mail.javamail.JavaMailSender;
48
import org.springframework.mail.javamail.MimeMessageHelper;
34306 ranu 49
import org.springframework.stereotype.Component;
50
import org.springframework.transaction.annotation.Transactional;
51
 
34321 ranu 52
import javax.mail.MessagingException;
53
import javax.mail.internet.InternetAddress;
54
import javax.mail.internet.MimeMessage;
34619 ranu 55
import java.io.*;
56
import java.math.BigDecimal;
34641 ranu 57
import java.time.*;
34306 ranu 58
import java.time.temporal.ChronoUnit;
59
import java.util.*;
34321 ranu 60
import java.util.stream.Collectors;
34619 ranu 61
import java.util.stream.Stream;
34306 ranu 62
 
63
@Component
64
@Transactional(rollbackFor = {Throwable.class, ProfitMandiBusinessException.class})
65
public class ScheduledTasksTest {
66
 
67
    private static final Logger LOGGER = LogManager.getLogger(ScheduledTasksTest.class);
68
 
69
    @Autowired
70
    TransactionRepository transactionRepository;
71
 
72
    @Autowired
34619 ranu 73
    @Qualifier(value = "googleMailSender")
74
    private JavaMailSender googleMailSender;
75
 
76
    @Autowired
34306 ranu 77
    LoanRepository loanRepository;
78
 
34308 ranu 79
    @Autowired
80
    SDCreditService sdCreditService;
81
 
34321 ranu 82
    @Autowired
83
    UserRepository userRepository;
84
 
85
    @Autowired
86
    CsService csService;
87
 
88
    @Autowired
89
    RbmRatingRepository rbmRatingRepository;
90
 
91
    @Autowired
92
    private JavaMailSender mailSender;
93
 
94
    @Autowired
95
    SalesRatingRepository salesRatingRepository;
96
 
97
    @Autowired
98
    FofoStoreRepository fofoStoreRepository;
99
 
34450 ranu 100
    @Autowired
101
    SmartCartService smartCartService;
102
 
34606 ranu 103
    @Autowired
104
    RetailerService retailerService;
105
 
106
    @Autowired
107
    ASTRepository astRepository;
108
 
109
    @Autowired
110
    AuthRepository authRepository;
111
 
112
    @Autowired
113
    StateRepository stateRepository;
114
 
115
    @Autowired
116
    MonthlyTargetRepository monthlyTargetRepository;
117
 
118
    @Autowired
119
    PartnerTypeChangeService partnerTypeChangeService;
120
 
121
    @Autowired
122
    ReturnOrderInfoRepository returnOrderInfoRepository;
123
 
124
    @Autowired
125
    OrderRepository orderRepository;
126
 
34619 ranu 127
    @Autowired
128
    FofoOrderItemRepository fofoOrderItemRepository;
129
 
130
    @Autowired
131
    InventoryService inventoryService;
132
 
133
    @Autowired
134
    UserWalletRepository userWalletRepository;
135
 
136
    @Autowired
137
    LoanStatementRepository loanStatementRepository;
138
 
139
    @Autowired
34641 ranu 140
    ActivatedImeiRepository activatedImeiRepository;
141
 
142
    @Autowired
143
    PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
144
 
145
    @Autowired
34619 ranu 146
    WalletService walletService;
147
 
34641 ranu 148
    @Autowired
149
    RbmTargetService rbmTargetService;
150
 
34655 ranu 151
    @Autowired
152
    PartnerStatsService partnerStatsService;
153
 
34321 ranu 154
    public void test() throws Exception {
34366 ranu 155
        System.out.println("test start");
34699 ranu 156
        //partnerStatsService.getAllPartnerStats();
157
        this.generateBiReportExcel();
34366 ranu 158
        System.out.println("test end");
34306 ranu 159
 
160
    }
161
 
34648 ranu 162
    public void generateBiReport() throws Exception {
163
        LOGGER.info("bi report started {-----}");
164
        this.generateBiReportExcel();
165
        LOGGER.info("bi report ended {-----}");
166
    }
167
 
34308 ranu 168
    public void createLoanForBillingByTransactionIdAndInvoiceNumber(int transactionId, double invoiceAmount, String invoiceNumber) throws Exception {
169
        sdCreditService.createLoanForBilling(transactionId, invoiceAmount, invoiceNumber);
34306 ranu 170
 
34308 ranu 171
    }
34306 ranu 172
 
34619 ranu 173
    public void loanSettle() throws Exception {
174
        List<Integer> refrences = Arrays.asList(25807,36003,38938,39506,42219,45084);
175
        for(Integer ref : refrences){
176
            List<LoanStatement> loanStatements = loanStatementRepository.selectByLoanId(ref);
177
            double amountSum = loanStatements.stream().map(LoanStatement::getAmount).mapToDouble(BigDecimal::doubleValue).sum();
178
            if(amountSum > 0){
179
                walletService.addAmountToWallet(loanStatements.get(0).getFofoId(),ref, WalletReferenceType.CREDIT_LIMIT,"Amount reversal against credit limit deduction",(float) amountSum,LocalDateTime.now());
34308 ranu 180
 
34619 ranu 181
//                Loan statement entry
182
                    BigDecimal adjustAmount = BigDecimal.valueOf(amountSum).negate(); // or multiply by -1
183
                    LoanStatement loanStatement = new LoanStatement();
184
                    loanStatement.setAmount(adjustAmount);
185
                    loanStatement.setFofoId(loanStatements.get(0).getFofoId());
186
                    loanStatement.setLoanReferenceType(LoanReferenceType.PRINCIPAL);
187
                    loanStatement.setCreatedAt(LocalDateTime.now());
188
                    loanStatement.setDescription("Amount reversal due to access debit against limit");
189
                    loanStatement.setLoanId(ref);
190
                    loanStatement.setBusinessDate(LocalDateTime.now());
191
                    loanStatementRepository.persist(loanStatement);
192
 
193
                    Loan loan = loanRepository.selectByLoanId(ref);
194
                    loan.setPendingAmount(BigDecimal.valueOf(0));
195
                    loan.setSettledOn(LocalDateTime.now());
196
                }
197
 
198
 
199
        }
200
    }
201
 
202
 
203
 
34321 ranu 204
    private void sendMailHtmlFormat(String email[], String body, String cc[], String bcc[], String subject)
205
            throws MessagingException, ProfitMandiBusinessException, IOException {
206
        MimeMessage message = mailSender.createMimeMessage();
207
        MimeMessageHelper helper = new MimeMessageHelper(message);
208
        helper.setSubject(subject);
209
        helper.setText(body, true);
210
        helper.setTo(email);
211
        if (cc != null) {
212
            helper.setCc(cc);
213
        }
214
        if (bcc != null) {
215
            helper.setBcc(bcc);
34308 ranu 216
 
34321 ranu 217
        }
218
 
219
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
220
        helper.setFrom(senderAddress);
221
        mailSender.send(message);
222
    }
223
 
34307 ranu 224
    public Map<Integer,Integer> findLoanTransactionMapingAccordingLoan(List<Integer> loanIds) throws ProfitMandiBusinessException {
34306 ranu 225
 
226
        Map<Integer, Integer> transactionLoanMap = new HashMap<>();
227
 
228
        for(int loanId : loanIds){
229
            Transaction transaction = null;
230
            Loan loan = loanRepository.selectByLoanId(loanId);
231
            List<Transaction> transactions = transactionRepository.selectByRetailerId(loan.getFofoId());
232
 
233
            LocalDateTime nearestDateTime = transactions.stream().map(x -> x.getCreateTimestamp())
234
                    .min(Comparator.comparingLong(x -> Math.abs(ChronoUnit.MILLIS.between(x, loan.getCreatedOn()))))
235
                    .orElse(null);
236
 
237
            if (nearestDateTime != null && loan.getCreatedOn().plusMinutes(2).isAfter(nearestDateTime) &&
238
                    loan.getCreatedOn().minusMinutes(1).isBefore(nearestDateTime)) {
239
                // Here transaction is still null
240
                transaction = transactions.stream()
241
                        .filter(x -> x.getCreateTimestamp().equals(nearestDateTime))
242
                        .findFirst().get();
243
                transactionLoanMap.put(transaction.getId(), loanId);
244
            }
245
 
246
        }
247
        LOGGER.info("transactionLoanMap {}",transactionLoanMap);
248
        return transactionLoanMap;
249
    }
34321 ranu 250
 
251
 
252
 
253
    public void sendRbmFeedbackSummaryEmail() throws MessagingException, ProfitMandiBusinessException, IOException {
254
        LocalDateTime startOfMonth = LocalDate.now().withDayOfMonth(1).atStartOfDay();
255
        LocalDateTime endOfMonth = LocalDateTime.now();
34323 ranu 256
        String[] bcc = {"tarun.verma@smartdukaan.com"};
34321 ranu 257
 
258
        // Get all RBM users
259
        List<AuthUser> authUsers = csService.getAuthUserIds(
260
                ProfitMandiConstants.TICKET_CATEGORY_RBM,
261
                Arrays.asList(EscalationType.L1)
262
        );
263
 
264
        if (authUsers.isEmpty()) {
265
            LOGGER.info("No RBMs found.");
266
            return;
267
        }
268
 
269
        List<Integer> rbmIds = authUsers.stream().map(AuthUser::getId).collect(Collectors.toList());
270
 
271
        // Fetch ratings for all RBMs for current month
272
        List<RbmRating> feedbackList = rbmRatingRepository.selectByRbmIdsAndDateRange(rbmIds, startOfMonth, endOfMonth);
273
 
274
        if (feedbackList.isEmpty()) {
275
            LOGGER.info("No feedback entries found for RBMs.");
276
            return;
277
        }
278
 
279
        // Sort feedback by createTimeStamp DESC
280
        feedbackList.sort((a, b) -> b.getCreateTimeStamp().compareTo(a.getCreateTimeStamp()));
281
 
282
        // Fetch and map FOFO (partner) names
283
        Map<Integer, String> fofoNameMap = new HashMap<>();
284
        for (RbmRating rating : feedbackList) {
285
            int fofoId = rating.getFofoId();
286
            if (!fofoNameMap.containsKey(fofoId)) {
287
                User fofoUser = userRepository.selectById(fofoId);
288
                FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
289
 
290
                String partnerName = fofoUser != null ? fofoUser.getName() : "Unknown Partner";
291
                String storeCode = fofoStore != null ? fofoStore.getCode() : "Unknown Code";
292
 
293
                String displayName = partnerName + " (" + storeCode + ")";
294
                fofoNameMap.put(fofoId, displayName);
295
            }
296
        }
297
 
298
        // Map RBM ID to name for quick lookup
299
        Map<Integer, String> rbmNameMap = authUsers.stream()
300
                .collect(Collectors.toMap(AuthUser::getId, AuthUser::getFullName));
301
 
302
        // Generate HTML content
303
        StringBuilder emailContent = new StringBuilder();
304
        emailContent.append("<html><body>");
305
        emailContent.append("<p>Dear Team,</p>");
306
        emailContent.append("<p>Here is the <b>latest RBM Rating and Feedback Summary</b> for ")
307
                .append(LocalDate.now().getMonth()).append(":</p>");
308
 
309
        emailContent.append("<table border='1' cellspacing='0' cellpadding='5'>");
310
        emailContent.append("<tr>")
311
                .append("<th>RBM Name</th>")
312
                .append("<th>Partner Name</th>")
313
                .append("<th>Rating</th>")
314
                .append("<th>Comment</th>")
315
                .append("<th>Date</th>")
316
                .append("</tr>");
317
 
318
        for (RbmRating rating : feedbackList) {
319
            String rbmName = rbmNameMap.getOrDefault(rating.getRbmId(), "Unknown RBM");
320
            String partnerName = fofoNameMap.getOrDefault(rating.getFofoId(), "Unknown Partner");
321
            emailContent.append("<tr>")
322
                    .append("<td>").append(rbmName).append("</td>")
323
                    .append("<td>").append(partnerName).append("</td>")
324
                    .append("<td>").append(rating.getRating()).append("</td>")
325
                    .append("<td>").append(rating.getComment() != null ? rating.getComment() : "-").append("</td>")
326
                    .append("<td>").append(rating.getCreateTimeStamp().toLocalDate()).append("</td>")
327
                    .append("</tr>");
328
        }
329
 
330
        emailContent.append("</table>");
331
        emailContent.append("<br><p>Regards,<br>Smart Dukaan Team</p>");
332
        emailContent.append("</body></html>");
333
 
334
        String subject = "Monthly RBM Feedback Summary - " + LocalDate.now().getMonth();
335
 
336
        List<String> sendTo = new ArrayList<>();
34323 ranu 337
        sendTo.add("sm@smartdukaan.com"); //
338
        sendTo.add("chiranjib.sarkar@smartdukaan.com"); //
339
        sendTo.add("kamini.sharma@smartdukaan.com"); //
34321 ranu 340
 
341
        String[] emailRecipients = sendTo.toArray(new String[0]);
342
 
343
 
344
        this.sendMailHtmlFormat(emailRecipients, emailContent.toString(), null, bcc, subject);
345
 
346
        LOGGER.info("Consolidated RBM feedback summary email sent.");
347
    }
348
 
349
 
350
    public void sendSalesFeedbackSummaryEmail() throws MessagingException, ProfitMandiBusinessException, IOException {
351
        LocalDateTime startOfMonth = LocalDate.now().withDayOfMonth(1).atStartOfDay();
352
        LocalDateTime endOfMonth = LocalDateTime.now();
34323 ranu 353
        String[] bcc = {"tarun.verma@smartdukaan.com"};
34411 tejus.loha 354
//        String[] bcc = {"tejus.lohani@smartdukaan.com"};
34321 ranu 355
 
356
        // Get all RBM users
357
        List<AuthUser> authUsers = csService.getAuthUserIds(
358
                ProfitMandiConstants.TICKET_CATEGORY_SALES,
359
                Arrays.asList(EscalationType.L1)
360
        );
361
 
362
        if (authUsers.isEmpty()) {
363
            LOGGER.info("No sales person found.");
364
            return;
365
        }
366
 
367
        List<Integer> salesL1Ids = authUsers.stream().map(AuthUser::getId).collect(Collectors.toList());
368
 
369
        // Fetch ratings for all RBMs for current month
370
        List<SalesRating> feedbackList = salesRatingRepository.selectBySalesL1IdsAndDateRange(salesL1Ids, startOfMonth, endOfMonth);
371
 
372
        if (feedbackList.isEmpty()) {
373
            LOGGER.info("No feedback entries found for Sales.");
374
            return;
375
        }
376
 
377
        // Sort feedback by createTimeStamp DESC
378
        feedbackList.sort((a, b) -> b.getCreateTimeStamp().compareTo(a.getCreateTimeStamp()));
379
 
380
        // Fetch and map FOFO (partner) names
381
        Map<Integer, String> fofoNameMap = new HashMap<>();
382
        for (SalesRating rating : feedbackList) {
383
            int fofoId = rating.getFofoId();
384
            if (!fofoNameMap.containsKey(fofoId)) {
385
                User fofoUser = userRepository.selectById(fofoId);
386
                FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
387
 
388
                String partnerName = fofoUser != null ? fofoUser.getName() : "Unknown Partner";
389
                String storeCode = fofoStore != null ? fofoStore.getCode() : "Unknown Code";
390
 
391
                String displayName = partnerName + " (" + storeCode + ")";
392
                fofoNameMap.put(fofoId, displayName);
393
            }
394
        }
395
 
396
        // Map RBM ID to name for quick lookup
397
        Map<Integer, String> salesL1NameMap = authUsers.stream()
398
                .collect(Collectors.toMap(AuthUser::getId, AuthUser::getFullName));
399
 
400
        // Generate HTML content
401
        StringBuilder emailContent = new StringBuilder();
402
        emailContent.append("<html><body>");
403
        emailContent.append("<p>Dear Team,</p>");
404
        emailContent.append("<p>Here is the <b>latest Sales L1 Rating and Feedback Summary</b> for ")
405
                .append(LocalDate.now().getMonth()).append(":</p>");
406
 
407
        emailContent.append("<table border='1' cellspacing='0' cellpadding='5'>");
408
        emailContent.append("<tr>")
409
                .append("<th>Sales L1 Name</th>")
410
                .append("<th>Partner Name</th>")
34411 tejus.loha 411
                .append("<th>Partner Category</th>")
34321 ranu 412
                .append("<th>Rating</th>")
413
                .append("<th>Comment</th>")
414
                .append("<th>Date</th>")
415
                .append("</tr>");
416
 
417
        for (SalesRating rating : feedbackList) {
418
            String salesL1 = salesL1NameMap.getOrDefault(rating.getSalesL1Id(), "Unknown Sales Person");
419
            String partnerName = fofoNameMap.getOrDefault(rating.getFofoId(), "Unknown Partner");
34411 tejus.loha 420
            PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(rating.getFofoId(), LocalDate.now());
34321 ranu 421
            emailContent.append("<tr>")
422
                    .append("<td>").append(salesL1).append("</td>")
423
                    .append("<td>").append(partnerName).append("</td>")
34411 tejus.loha 424
                    .append("<td>").append(partnerType).append("</td>")
34321 ranu 425
                    .append("<td>").append(rating.getRating()).append("</td>")
426
                    .append("<td>").append(rating.getComment() != null ? rating.getComment() : "-").append("</td>")
427
                    .append("<td>").append(rating.getCreateTimeStamp().toLocalDate()).append("</td>")
428
                    .append("</tr>");
429
        }
430
 
431
        emailContent.append("</table>");
432
        emailContent.append("<br><p>Regards,<br>Smartdukaan Team</p>");
433
        emailContent.append("</body></html>");
434
 
34411 tejus.loha 435
        String subject = "Monthly Sales L1 Feedback Summary Test test - " + LocalDate.now().getMonth();
34321 ranu 436
 
437
        List<String> sendTo = new ArrayList<>();
34323 ranu 438
         sendTo.add("sm@smartdukaan.com"); //
439
         sendTo.add("chiranjib.sarkar@smartdukaan.com"); //
34606 ranu 440
         sendTo.add("kamini.sharma@smartdukaan.com"); //
34321 ranu 441
 
442
        String[] emailRecipients = sendTo.toArray(new String[0]);
443
 
444
 
445
        this.sendMailHtmlFormat(emailRecipients, emailContent.toString(), null, bcc, subject);
446
 
447
        LOGGER.info("Consolidated Sales L1 feedback summary email sent.");
448
    }
449
 
450
 
34606 ranu 451
    public void generateBiReportExcel() throws Exception {
34619 ranu 452
 
34606 ranu 453
        LocalDateTime startOfToday = LocalDate.now().atStartOfDay();
34321 ranu 454
 
34701 ranu 455
        /*Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
34321 ranu 456
 
34701 ranu 457
        List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());*/
34606 ranu 458
 
34701 ranu 459
        List<Integer> retailerIds = Arrays.asList(175139615,175139391,175135707);
460
        Map<Integer,CustomRetailer> customRetailers = retailerService.getFofoRetailers(retailerIds);
34648 ranu 461
 
34641 ranu 462
        //partner daily investment
463
        List<Loan> defaultLoans = sdCreditService.getDefaultLoan();
464
        Map<Integer,List<Loan>> defaultLoanMap = defaultLoans.stream().collect(Collectors.groupingBy(Loan::getFofoId));
34619 ranu 465
 
34641 ranu 466
        Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
467
        List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
468
                .selectAll(new ArrayList<>(retailerIds), LocalDate.now().minusDays(1));
469
        if (!partnerDailyInvestments.isEmpty()) {
470
            partnerDailyInvestmentMap = partnerDailyInvestments.stream()
471
                    .collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
472
        }
473
 
34648 ranu 474
    //  this month return data
34619 ranu 475
        YearMonth currentMonth = YearMonth.now();
476
        String currentMonthStringValue = String.valueOf(currentMonth);
34606 ranu 477
        LocalDateTime currentMonthStartDate = YearMonth.now().atDay(1).atStartOfDay();
34699 ranu 478
        LocalDateTime currentMonthEndDate = LocalDateTime.now().minusDays(1);
34606 ranu 479
 
480
        List<ReturnOrderInfoModel> currentMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(currentMonthStartDate, currentMonthEndDate);
481
        Map<Integer, Long> currentMonthPartnerReturnOrderInfoModelMap = currentMonthReturnOrderInfoModels.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getRefundAmount()))));
482
 
483
        List<Order> currentMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(currentMonthStartDate, currentMonthEndDate, OrderStatus.RTO_REFUNDED);
484
        Map<Integer, Long> currentMonthRtoRefundOrderMap = currentMonthRtoRefundOrders.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
485
 
486
 
34619 ranu 487
//  last month return data
34606 ranu 488
        YearMonth lastMonth = YearMonth.now().minusMonths(1);
34619 ranu 489
        String lastMonthStringValue = String.valueOf(lastMonth);
34606 ranu 490
        LocalDateTime lastMontStartDate = lastMonth.atDay(1).atStartOfDay();
491
        LocalDateTime lastMonthEndDate = lastMonth.atEndOfMonth().atTime(23, 59, 59);
492
 
493
        List<ReturnOrderInfoModel> lastMonthReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(lastMontStartDate, lastMonthEndDate);
494
        Map<Integer, Long> lastMonthPartnerReturnOrderInfoModelMap = lastMonthReturnOrderInfoModels.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getRefundAmount()))));
495
 
496
        List<Order> lastMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(lastMontStartDate, lastMonthEndDate, OrderStatus.RTO_REFUNDED);
497
        Map<Integer, Long> lastMonthRtoRefundOrderMap = lastMonthRtoRefundOrders.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
498
 
499
 
34619 ranu 500
//  twoMonthsAgo return data
34606 ranu 501
        YearMonth twoMonthsAgo = YearMonth.now().minusMonths(2);
34619 ranu 502
        String twoMonthAgoStringValue = String.valueOf(twoMonthsAgo);
34606 ranu 503
        LocalDateTime twoMonthsAgoStartDate = twoMonthsAgo.atDay(1).atStartOfDay();
504
        LocalDateTime twoMonthsAgoEndDate = twoMonthsAgo.atEndOfMonth().atTime(23, 59, 59);
505
 
506
        List<ReturnOrderInfoModel> twoMonthAgoReturnOrderInfoModels = returnOrderInfoRepository.selectAllByBetweenDate(twoMonthsAgoStartDate, twoMonthsAgoEndDate);
507
        Map<Integer, Long> twoMonthAgoPartnerReturnOrderInfoModelMap = twoMonthAgoReturnOrderInfoModels.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getRefundAmount()))));
508
 
509
        List<Order> twoMonthRtoRefundOrders = orderRepository.selectAllOrderDatesBetweenByStatus(twoMonthsAgoStartDate, twoMonthsAgoEndDate, OrderStatus.RTO_REFUNDED);
34619 ranu 510
        Map<Integer, Long> twoMonthAgoRtoRefundOrderMap = twoMonthRtoRefundOrders.stream().collect(Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingLong(x -> Math.round(x.getTotalAmount()))));
34606 ranu 511
 
34648 ranu 512
        Map<Integer , String> assessmentMap = new HashMap<>();
513
        Map<Integer , String> zeroBillingMap = new HashMap<>();
514
        Map<Integer , Float> billingNeededMap = new HashMap<>();
515
        Map<Integer , Integer> countAMap = new HashMap<>();
34606 ranu 516
 
34619 ranu 517
        Map<Integer , BIRetailerModel> biRetailerModelMap = new HashMap<>();
34606 ranu 518
 
34641 ranu 519
        Map<Integer , FofoInvestmentModel> biInvestmentModelMap = new HashMap<>();
520
 
34619 ranu 521
        Map<Integer, Map<YearMonth, BiSecondaryModel>> allRetailerMonthlyData = new HashMap<>();
34606 ranu 522
 
34619 ranu 523
        Map<Integer,Double> fofoTotalStockPriceMap = new HashMap<>();
524
 
525
        Map<Integer,Map<String, BrandStockPrice>> fofoBrandStockPriceMap = new HashMap<>();
526
 
34641 ranu 527
        Map<Integer,Long> fofoTotalMtdSecondaryMap = new HashMap<>();
34619 ranu 528
 
529
 
34641 ranu 530
        Map<Integer,Map<String, Long>> fofoBrandWiseMtdSecondaryMap = new HashMap<>();
34619 ranu 531
 
34641 ranu 532
        Map<Integer,Double> fofoTotalMtdTertiaryMap = new HashMap<>();
533
 
534
        Map<Integer,Map<String, Double>> fofoBrandMtdTertiaryMap = new HashMap<>();
535
 
34606 ranu 536
        for(Integer fofoId: retailerIds){
34619 ranu 537
            String rbmName = "";
34606 ranu 538
            int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM,EscalationType.L1,fofoId);
34619 ranu 539
            if(rbmL1 != 0){
540
                 rbmName = authRepository.selectById(rbmL1).getFullName();
34677 ranu 541
            }else {
542
                int rbmL2 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L2, fofoId);
543
                if(rbmL2 != 0){
544
                    rbmName = authRepository.selectById(rbmL2).getFullName();
545
                }
34619 ranu 546
            }
547
            String bmName ="";
34606 ranu 548
            int bmId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES,EscalationType.L2,fofoId);
34619 ranu 549
            if(bmId !=0){
550
                bmName = authRepository.selectById(bmId).getFullName();
551
            }
34606 ranu 552
 
553
            int managerId = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES,EscalationType.L1,fofoId);
554
            String managerName = " ";
555
            if(managerId != 0){
556
                 managerName = authRepository.selectById(managerId).getFullName();
557
            }else {
558
                managerName = bmName;
559
            }
560
 
561
            AST ast = astRepository.selectById(customRetailers.get(fofoId).getAstId());
562
 
563
            PartnerType partnerTypeThisMonth = partnerTypeChangeService.getTypeOnMonth(fofoId, YearMonth.now());
564
 
565
//            generate retaile detail
566
 
567
            BIRetailerModel biRetailerModel = new BIRetailerModel();
568
            biRetailerModel.setBmName(bmName);
569
            biRetailerModel.setCode(customRetailers.get(fofoId).getCode());
34619 ranu 570
            if(ast != null){
571
                biRetailerModel.setArea(ast.getArea());
572
            }else {
573
                biRetailerModel.setArea("-");
574
            }
34606 ranu 575
            biRetailerModel.setCity(customRetailers.get(fofoId).getAddress().getCity());
576
            biRetailerModel.setStoreName(customRetailers.get(fofoId).getBusinessName());
34619 ranu 577
            biRetailerModel.setStatus(String.valueOf(customRetailers.get(fofoId).getActivationType()));
34606 ranu 578
            biRetailerModel.setCategory(String.valueOf(partnerTypeThisMonth));
579
            biRetailerModel.setSalesManager(managerName);
580
            biRetailerModel.setRbm(rbmName);
581
 
34619 ranu 582
            biRetailerModelMap.put(fofoId,biRetailerModel);
583
 
34641 ranu 584
 
34606 ranu 585
//            generate secondary data
586
 
34641 ranu 587
            List<PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledMonthlyTotals = activatedImeiRepository.getTotalMonthlyActivatedNotBilled(fofoId,twoMonthsAgoStartDate);
588
            Map<YearMonth , PartnerWiseActivatedNotBilledTotal> partnerWiseActivatedNotBilledTotalMap = partnerWiseActivatedNotBilledMonthlyTotals.stream().collect(Collectors.toMap(x-> YearMonth.parse(x.getYearMonth()),x->x));
589
 
34606 ranu 590
//            this month secondary target
591
 
34619 ranu 592
            double currentSecondaryTarget =  monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId) != null ? monthlyTargetRepository.selectByDateAndFofoId(YearMonth.now(), fofoId).getPurchaseTarget() : 0;
34606 ranu 593
 
34619 ranu 594
 
595
            long currentMonthReturn = currentMonthPartnerReturnOrderInfoModelMap.getOrDefault(fofoId, 0L) + currentMonthRtoRefundOrderMap.getOrDefault(fofoId, 0L);
596
 
597
 
34606 ranu 598
            Map<Integer, Double> secondaryMtd = orderRepository.selectOrderValueBetweenDatesGroupByFofoId(Arrays.asList(fofoId),
34701 ranu 599
                    Arrays.asList(OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.DELIVERY_SUCCESS),
34699 ranu 600
                    startOfToday.withDayOfMonth(1), startOfToday.with(LocalTime.MAX).minusDays(1)).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
34606 ranu 601
 
602
            double secondaryAchievedMtd = secondaryMtd.getOrDefault(fofoId, 0.0);
603
 
34619 ranu 604
            double currentMonthNetSecondary = secondaryAchievedMtd - currentMonthReturn;
34606 ranu 605
 
34701 ranu 606
            double currentMonthSecondaryPercent = currentSecondaryTarget == 0 ? 0.0 : Math.round(Math.abs((secondaryAchievedMtd / currentSecondaryTarget) * 100));
34619 ranu 607
 
34641 ranu 608
            double currentMonthUnbilled = partnerWiseActivatedNotBilledTotalMap.get(currentMonth) != null ? partnerWiseActivatedNotBilledTotalMap.get(currentMonth).getTotalUnbilledAmount() : 0d;
34619 ranu 609
 
610
//          this month tertiary----------
611
 
612
            LocalDateTime now = LocalDateTime.now();
613
            double todaySale = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday, now, fofoId, false).get(fofoId);
614
            double mtdSaleTillYesterDay = fofoOrderItemRepository.selectSumMopGroupByRetailer(startOfToday.withDayOfMonth(1), startOfToday, fofoId, false).get(fofoId);
615
            double mtdSale = mtdSaleTillYesterDay + todaySale;
616
 
617
 
34606 ranu 618
//            last month secondary target
619
 
34619 ranu 620
            double lastMonthSecondaryTarget = monthlyTargetRepository.selectByDateAndFofoId(lastMonth, fofoId) != null ?  monthlyTargetRepository.selectByDateAndFofoId(lastMonth, fofoId).getPurchaseTarget() : 0;
34606 ranu 621
 
34619 ranu 622
            long lastMonthReturn = (lastMonthPartnerReturnOrderInfoModelMap.getOrDefault(fofoId,0L) + lastMonthRtoRefundOrderMap.getOrDefault(fofoId,0L));
623
 
34606 ranu 624
            Map<Integer, Double> lastMonthSecondary = orderRepository.selectOrderValueBetweenDatesGroupByFofoId(Arrays.asList(fofoId),
625
                    Arrays.asList(OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.DELIVERY_SUCCESS, OrderStatus.ACCEPTED, OrderStatus.SUBMITTED_FOR_PROCESSING),
626
                    lastMontStartDate, lastMonthEndDate).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
627
 
628
            double lastMonthSecondaryAchieved = lastMonthSecondary.getOrDefault(fofoId, 0.0);
629
 
34619 ranu 630
            double lastMonthNetSecondary = lastMonthSecondaryAchieved - lastMonthReturn;
34606 ranu 631
 
34701 ranu 632
            double lastMonthSecondaryPercent = lastMonthSecondaryTarget == 0 ? 0.0 : Math.round(Math.abs((lastMonthSecondaryAchieved / lastMonthSecondaryTarget) * 100));
34606 ranu 633
 
34641 ranu 634
            double lastMonthUnbilled = partnerWiseActivatedNotBilledTotalMap.get(lastMonth) != null ? partnerWiseActivatedNotBilledTotalMap.get(lastMonth).getTotalUnbilledAmount() : 0d;
34606 ranu 635
 
34619 ranu 636
//           last month tertiary
637
            Double lastMonthSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
638
                    lastMontStartDate, lastMonthEndDate, fofoId, false).get(fofoId);
639
 
640
 
641
//            two month ago secondary target
642
 
643
            double twoMonthAgoSecondaryTarget = monthlyTargetRepository.selectByDateAndFofoId(lastMonth, fofoId) != null ? monthlyTargetRepository.selectByDateAndFofoId(lastMonth, fofoId).getPurchaseTarget() : 0;
644
 
645
            long twoMonthAgoReturn = (twoMonthAgoPartnerReturnOrderInfoModelMap.getOrDefault(fofoId,0L) + twoMonthAgoRtoRefundOrderMap.getOrDefault(fofoId,0L));
646
 
34606 ranu 647
            Map<Integer, Double> twoMonthAgoSecondary = orderRepository.selectOrderValueBetweenDatesGroupByFofoId(Arrays.asList(fofoId),
648
                    Arrays.asList(OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.DELIVERY_SUCCESS, OrderStatus.ACCEPTED, OrderStatus.SUBMITTED_FOR_PROCESSING),
649
                    twoMonthsAgoStartDate, twoMonthsAgoEndDate).stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getAmount()));
650
 
651
            double twoMonthAgoSecondaryAchieved = twoMonthAgoSecondary.getOrDefault(fofoId, 0.0);
652
 
34619 ranu 653
            double twoMonthAgoNetSecondary = twoMonthAgoSecondaryAchieved - twoMonthAgoReturn;
34606 ranu 654
 
34701 ranu 655
            double twoMonthAgoSecondaryPercent = twoMonthAgoSecondaryTarget == 0 ? 0.0 : Math.round(Math.abs((twoMonthAgoSecondaryAchieved / twoMonthAgoSecondaryTarget) * 100));
34619 ranu 656
 
34641 ranu 657
            double twoMonthAgoUnbilled = partnerWiseActivatedNotBilledTotalMap.get(twoMonthsAgo) != null ? partnerWiseActivatedNotBilledTotalMap.get(twoMonthsAgo).getTotalUnbilledAmount() : 0d;
34619 ranu 658
 
659
//          second Month Tertiary
660
            double twoMonthAgoSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
661
                    twoMonthsAgoStartDate, twoMonthsAgoEndDate, fofoId, false).get(fofoId);
662
 
663
 
664
            Map<YearMonth, BiSecondaryModel> monthlySecondaryModels = new HashMap<>();
665
 
666
            BiSecondaryModel currentMonthSecondaryModel = new BiSecondaryModel(
667
                    currentSecondaryTarget,
668
                    secondaryAchievedMtd,
669
                    currentMonthReturn,
670
                    currentMonthNetSecondary,
671
                    currentMonthSecondaryPercent,
672
                    mtdSale,
673
                    currentMonthUnbilled // for now, unbilled tertiary value
674
            );
675
 
676
            BiSecondaryModel lastMonthSecondaryModel = new BiSecondaryModel(
677
                    lastMonthSecondaryTarget,
678
                    lastMonthSecondaryAchieved,
679
                    lastMonthReturn,
680
                    lastMonthNetSecondary,
681
                    lastMonthSecondaryPercent,
682
                    lastMonthSale,
683
                    lastMonthUnbilled // for now, unbilled tertiary value
684
            );
685
 
686
            BiSecondaryModel twoMonthAgoSecondaryModel = new BiSecondaryModel(
687
                    twoMonthAgoSecondaryTarget,
688
                    twoMonthAgoSecondaryAchieved,
689
                    twoMonthAgoReturn,
690
                    twoMonthAgoNetSecondary,
691
                    twoMonthAgoSecondaryPercent,
692
                    twoMonthAgoSale,
693
                    twoMonthAgoUnbilled // for now, unbilled tertiary value
694
            );
695
 
696
            monthlySecondaryModels.put(currentMonth, currentMonthSecondaryModel);
697
            monthlySecondaryModels.put(lastMonth, lastMonthSecondaryModel);
698
            monthlySecondaryModels.put(twoMonthsAgo, twoMonthAgoSecondaryModel);
699
 
700
            allRetailerMonthlyData.put(fofoId, monthlySecondaryModels);
701
 
702
//            brandwiseStock value price
703
 
704
            Map<String, BrandStockPrice> brandStockPriceMap = inventoryService.getBrandWiseStockValue(fofoId);
705
 
706
            fofoBrandStockPriceMap.put(fofoId,brandStockPriceMap);
707
 
708
            double totalStockPrice = brandStockPriceMap.values().stream().mapToDouble(x->x.getTotalValue()).sum();
709
 
710
            fofoTotalStockPriceMap.put(fofoId,totalStockPrice);
711
 
712
            Map<String, Double> brandMtdTertiaryAmount = fofoOrderItemRepository.selectSumAmountGroupByBrand(
713
                    currentMonthStartDate, currentMonthEndDate, fofoId);
714
 
34641 ranu 715
            fofoBrandMtdTertiaryMap.put(fofoId,brandMtdTertiaryAmount);
34619 ranu 716
 
717
            double totalMtdTertiaryAmount = brandMtdTertiaryAmount.values().stream().mapToDouble(Double::doubleValue).sum();
718
 
34641 ranu 719
            fofoTotalMtdTertiaryMap.put(fofoId,totalMtdTertiaryAmount);
34619 ranu 720
 
34641 ranu 721
            List<BrandWiseModel> brandWiseMtdSecondary = orderRepository.selectAllBilledOrderGroupByBrandFofoId(fofoId, currentMonthStartDate);
722
            Map<String,Long> brandWiseMtdSecondaryMap = brandWiseMtdSecondary.stream().collect(Collectors.toMap(BrandWiseModel::getBrand,BrandWiseModel::getAmount));
723
            fofoBrandWiseMtdSecondaryMap.put(fofoId,brandWiseMtdSecondaryMap);
34619 ranu 724
 
34641 ranu 725
            long mtdTotalSecondary = brandWiseMtdSecondary.stream().mapToLong(x -> x.getAmount() != 0 ? x.getAmount() : 0L).sum();
34619 ranu 726
 
34641 ranu 727
            fofoTotalMtdSecondaryMap.put(fofoId,mtdTotalSecondary);
728
 
729
            //            generate investment info
730
            FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
731
            float shortInvestment = partnerDailyInvestmentMap.get(fofoId) != null ? partnerDailyInvestmentMap.get(fofoId).getShortInvestment() : 0f;
732
            float agreedInvestment = partnerDailyInvestmentMap.get(fofoId) != null ? partnerDailyInvestmentMap.get(fofoId).getMinInvestment() : 0f;
34677 ranu 733
            float investmentLevel = partnerDailyInvestmentMap.get(fofoId) != null
734
                    ? Math.abs(((shortInvestment - agreedInvestment) / agreedInvestment) * 100)
735
                    : 0f;
34641 ranu 736
 
34677 ranu 737
 
34641 ranu 738
            List<Loan> fofoDefaultLoans = new ArrayList<>();
739
            if(defaultLoanMap != null){
740
                 fofoDefaultLoans  =  defaultLoanMap.get(fofoId);
741
                LOGGER.info("fofoDefaultLoans {}",fofoDefaultLoans);
742
            }
743
 
744
            float defaultLoanAmount = 0f;
745
            if(fofoDefaultLoans != null ){
746
                if (!fofoDefaultLoans.isEmpty()) {
747
                    defaultLoanAmount =  fofoDefaultLoans.stream().map(Loan::getPendingAmount).reduce(BigDecimal.ZERO, BigDecimal::add).floatValue(); // or .floatValue() directly
748
                }
749
            }
750
 
751
            float activeLoan = loanRepository.selectActiveLoan(fofoId).stream().map(Loan::getPendingAmount).reduce(BigDecimal.ZERO,BigDecimal::add).floatValue();
752
 
753
 
754
            float poValue = partnerDailyInvestmentMap.get(fofoId) != null ?  partnerDailyInvestmentMap.get(fofoId).getUnbilledAmount() : 0f;
755
 
34677 ranu 756
            List<Order> billedAndPoOrder = orderRepository.selectOrders(Arrays.asList(fofoId),Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.ACCEPTED, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH, OrderStatus.DELIVERY_SUCCESS),currentMonthStartDate,startOfToday.plusDays(1));
34641 ranu 757
            float poAndBilledValue = (float) billedAndPoOrder.stream().map(Order::getTotalAmount).reduce(0f,Float::sum);
758
 
759
            double purchaseMtd = secondaryMtd.getOrDefault(fofoId, 0.0);
760
 
761
            double todayRequiredDrr = rbmTargetService.calculateFofoIdTodayTarget(fofoId, purchaseMtd,LocalDate.now());
762
 
763
            double monthDay1Drr = rbmTargetService.calculateFofoIdTodayTarget(fofoId,0d,YearMonth.now().atDay(1));
764
 
765
 
766
            double gotDrrPercent = (todayRequiredDrr / monthDay1Drr) * 100;
767
 
34701 ranu 768
            long drrPercentDisplay = Math.round(Math.abs(gotDrrPercent));
769
 
770
 
34641 ranu 771
            int orderId = orderRepository.getLastOrderByFofoId(fofoId);
772
 
34644 ranu 773
            // Determine alert level
774
            String alertLevel = "-";
775
            int lastPurchaseDays = 0;
34641 ranu 776
            if (orderId != 0) {
777
                Order order = orderRepository.selectById(orderId);
778
 
779
                // Calculate the number of days since the last purchase (billing)
34644 ranu 780
                lastPurchaseDays = (int) Duration.between(order.getCreateTimestamp().plusDays(1), LocalDateTime.now()).toDays();
34641 ranu 781
 
782
                if (lastPurchaseDays >= 11) {
783
                    alertLevel = "Alert for Management";
34676 ranu 784
                } else if (lastPurchaseDays >= 10) {
34641 ranu 785
                    alertLevel = " Alert for RSM/SH";
34676 ranu 786
                } else if (lastPurchaseDays >= 7) {
34641 ranu 787
                    alertLevel = "Must be Billed";
788
                } else if (lastPurchaseDays >= 3) {
789
                    alertLevel = "OK";
790
                } else {
34676 ranu 791
                    alertLevel = "OK";
34641 ranu 792
                }
34644 ranu 793
            }
34641 ranu 794
 
34644 ranu 795
            //investment modal set all related value
796
            FofoInvestmentModel fofoInvestmentModel = new FofoInvestmentModel();
34641 ranu 797
 
34644 ranu 798
            fofoInvestmentModel.setCounterPotential(fofoStore.getCounterPotential());
799
            fofoInvestmentModel.setShortInvestment(shortInvestment);
800
            fofoInvestmentModel.setDefaultLoan(defaultLoanAmount);
801
            fofoInvestmentModel.setInvestmentLevel(investmentLevel);
802
            fofoInvestmentModel.setActiveLoan(activeLoan);
803
            fofoInvestmentModel.setPoValue(poValue);
804
            fofoInvestmentModel.setPoAndBilled(poAndBilledValue);
805
            fofoInvestmentModel.setAgreedInvestment(agreedInvestment);
806
            fofoInvestmentModel.setWallet(partnerDailyInvestmentMap.get(fofoId) != null ? partnerDailyInvestmentMap.get(fofoId).getWalletAmount() : 0);
807
            fofoInvestmentModel.setMonthBeginingDrr(monthDay1Drr);
808
            fofoInvestmentModel.setRequiredDrr(todayRequiredDrr);
34701 ranu 809
            fofoInvestmentModel.setDrrPercent(drrPercentDisplay);
34644 ranu 810
            fofoInvestmentModel.setLastBillingDone(lastPurchaseDays);
811
            fofoInvestmentModel.setSlab(alertLevel);
34641 ranu 812
 
34644 ranu 813
            biInvestmentModelMap.put(fofoId, fofoInvestmentModel);
34641 ranu 814
                String assessment = "";
815
                if(defaultLoanAmount > 0 ){
816
                    assessment = "Loan Default";
817
                }else if(investmentLevel <= 75 && defaultLoanAmount < 1){
818
                    assessment = "Low Invest";
819
                }else {
820
                    assessment = "-";
821
                }
822
                assessmentMap.put(fofoId,assessment);
823
 
824
                String zeroBilling = "";
825
                if(currentMonthNetSecondary <= 100000 ){
826
                    zeroBilling = "Zero Billing";
827
                }else {
828
                    zeroBilling = "-";
829
                }
830
                zeroBillingMap.put(fofoId,zeroBilling);
831
 
832
                float billingNeeded = 0f;
34701 ranu 833
                if(drrPercentDisplay >= 110 ){
34641 ranu 834
                    billingNeeded = (float) todayRequiredDrr;
835
                }else {
836
                    billingNeeded = 0f;
837
                }
838
                billingNeededMap.put(fofoId,billingNeeded);
839
 
840
                int counta = 0;
34701 ranu 841
                if(defaultLoanAmount > 0 || investmentLevel <= 75 || currentMonthNetSecondary <= 100000 || drrPercentDisplay >= 110 ){
34641 ranu 842
                    counta = 1;
843
                }else {
844
                    counta = 0;
845
                }
846
                countAMap.put(fofoId,counta);
847
 
34606 ranu 848
        }
849
 
34619 ranu 850
        LOGGER.info("Total BI Retailers processed: {}", biRetailerModelMap.size());
34606 ranu 851
 
34619 ranu 852
        //generate excel and sent to mail
853
        List<List<String>> headerGroup = new ArrayList<>();
34606 ranu 854
 
34619 ranu 855
        List<String> headers1 = Arrays.asList(
34641 ranu 856
                "","","","",
34699 ranu 857
                "Retailer Detail", "","", "", "", "", "", "", "", "","",
34677 ranu 858
 
859
                twoMonthAgoStringValue, "", "", "", "", "", "",
860
                lastMonthStringValue, "", "", "", "", "", "",
34619 ranu 861
                currentMonthStringValue, "", "", "", "", "", "",
34641 ranu 862
 
863
                "","", "", "", "", "", "", "", "", "", "", "", "", "",
864
 
865
                "", "", "", "", "", "", "", "", "", "", "", "", "",
866
                "", "", "", "", "", "", "", "", "", "", "", "", ""
867
 
34619 ranu 868
        );
34606 ranu 869
 
34619 ranu 870
        List<String> headers2 = Arrays.asList(
34641 ranu 871
                "Assessment","Zero billing","Billing needed","Counta",
34699 ranu 872
                "BM","Partner Id","Link","Code","Area",  "City", "Store Name", "Status","Category","Sales Manager", "RBM",
34619 ranu 873
                "Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
874
                "Tertiary Sale", "Unbilled",
875
                "Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
876
                "Tertiary Sale", "Unbilled",
877
                "Secondary Target", "Secondary Achieved", "Returns", "Net Secondary", "Secondary %",
878
                "Tertiary Sale", "Unbilled",
34641 ranu 879
                "Counter Potential", "Short investment", "Default", "INVESTMENT LEVEL", "Loan", "PO value", "Agreed investment",
880
                "Wallet", "po+bill", "MONTH BEGINNING DRR", "REQ DRR", "Drr %", "Last billing Done", "Slab",
34606 ranu 881
 
34641 ranu 882
              "Total Stock",  "Apple","Xiaomi", "Vivo", "Tecno", "Samsung", "Realme", "Oppo", "OnePlus", "Poco", "Lava", "Itel", "Almost New",
883
              "Total Secondary", "Apple", "Xiaomi", "Vivo", "Tecno", "Samsung", "Realme", "Oppo", "OnePlus", "Poco", "Lava", "Itel", "Almost New",
884
              "Total Tertiary",  "Apple", "Xiaomi", "Vivo", "Tecno", "Samsung", "Realme", "Oppo", "OnePlus", "Poco", "Lava", "Itel", "Almost New"
34619 ranu 885
        );
886
 
887
        headerGroup.add(headers1);
888
        headerGroup.add(headers2);
889
 
890
 
891
        List<List<?>> rows = new ArrayList<>();
892
        for (Map.Entry<Integer, BIRetailerModel> entry : biRetailerModelMap.entrySet()) {
893
            Integer fofoId = entry.getKey();
894
            BIRetailerModel retailer = entry.getValue();
34641 ranu 895
 
34619 ranu 896
            Map<YearMonth, BiSecondaryModel> monthlyData = allRetailerMonthlyData.get(fofoId);
897
 
898
            BiSecondaryModel current = monthlyData.getOrDefault(YearMonth.now(), new BiSecondaryModel(0,0,0,0,0,0,0));
899
            BiSecondaryModel last = monthlyData.getOrDefault(YearMonth.now().minusMonths(1), new BiSecondaryModel(0,0,0,0,0,0,0));
900
            BiSecondaryModel twoAgo = monthlyData.getOrDefault(YearMonth.now().minusMonths(2), new BiSecondaryModel(0,0,0,0,0,0,0));
901
 
902
            List<Object> row = new ArrayList<>();
903
            row.addAll(Arrays.asList(
34641 ranu 904
                    assessmentMap.get(fofoId),zeroBillingMap.get(fofoId),billingNeededMap.get(fofoId),countAMap.get(fofoId),
34699 ranu 905
                    retailer.getBmName(),fofoId ,"https://partners.smartdukaan.com/partnerPerformance?fofoId="+fofoId, retailer.getCode(), retailer.getArea(), retailer.getCity(),  retailer.getStoreName(), retailer.getStatus(),
34677 ranu 906
                    retailer.getCategory(),  retailer.getSalesManager(), retailer.getRbm()
907
 
34619 ranu 908
            ));
909
 
34677 ranu 910
 
911
            // Two Months Ago
34619 ranu 912
            row.addAll(Arrays.asList(
34677 ranu 913
                    twoAgo.getSecondaryTarget(),
914
                    twoAgo.getSecondaryAchieved(),
915
                    twoAgo.getSecondaryReturn(),
916
                    twoAgo.getNetSecondary(),
917
                    twoAgo.getSecondaryAchievedPercent(),
918
                    twoAgo.getTertiary(),
919
                    twoAgo.getTertiaryUnBilled()
34619 ranu 920
            ));
921
 
922
            // Last Month
923
            row.addAll(Arrays.asList(
924
                    last.getSecondaryTarget(),
925
                    last.getSecondaryAchieved(),
926
                    last.getSecondaryReturn(),
927
                    last.getNetSecondary(),
928
                    last.getSecondaryAchievedPercent(),
929
                    last.getTertiary(),
930
                    last.getTertiaryUnBilled()
931
            ));
932
 
34677 ranu 933
            // Current Month
34619 ranu 934
            row.addAll(Arrays.asList(
34677 ranu 935
                    current.getSecondaryTarget(),
936
                    current.getSecondaryAchieved(),
937
                    current.getSecondaryReturn(),
938
                    current.getNetSecondary(),
939
                    current.getSecondaryAchievedPercent(),
940
                    current.getTertiary(),
941
                    current.getTertiaryUnBilled()
34619 ranu 942
            ));
34677 ranu 943
 
944
 
945
 
34641 ranu 946
            FofoInvestmentModel fofoInvestmentModelValue = biInvestmentModelMap.get(fofoId);
947
            if(fofoInvestmentModelValue != null){
948
                row.addAll(Arrays.asList(
949
                        fofoInvestmentModelValue.getCounterPotential(),
950
                        fofoInvestmentModelValue.getShortInvestment(),
951
                        fofoInvestmentModelValue.getDefaultLoan(),
952
                        fofoInvestmentModelValue.getInvestmentLevel(),
953
                        fofoInvestmentModelValue.getActiveLoan(),
954
                        fofoInvestmentModelValue.getPoValue(),
955
                        fofoInvestmentModelValue.getAgreedInvestment(),
956
                        fofoInvestmentModelValue.getWallet(),
957
                        fofoInvestmentModelValue.getPoAndBilled(),
958
                        fofoInvestmentModelValue.getMonthBeginingDrr(),
959
                        fofoInvestmentModelValue.getRequiredDrr(),
960
                        fofoInvestmentModelValue.getDrrPercent(),
961
                        fofoInvestmentModelValue.getLastBillingDone(),
962
                        fofoInvestmentModelValue.getSlab()
963
                ));
964
            }else {
965
                row.addAll(Arrays.asList(
966
                        "-","-","-","-","-","-","-","-","-","-","-",""
967
                ));
968
            }
969
 
970
            Map<String, BrandStockPrice> brandStockMap = fofoBrandStockPriceMap.get(fofoId);
34619 ranu 971
            row.addAll(Arrays.asList(
972
                    fofoTotalStockPriceMap.getOrDefault(fofoId, 0.0),
34641 ranu 973
                    brandStockMap.get("Apple") != null ? brandStockMap.get("Apple").getTotalValue() : 0.0,
974
                    brandStockMap.get("Xiaomi") != null ? brandStockMap.get("Xiaomi").getTotalValue() : 0.0,
975
                    brandStockMap.get("Vivo") != null ? brandStockMap.get("Vivo").getTotalValue() : 0.0,
976
                    brandStockMap.get("Tecno") != null ? brandStockMap.get("Tecno").getTotalValue() : 0.0,
977
                    brandStockMap.get("Samsung") != null ? brandStockMap.get("Samsung").getTotalValue() : 0.0,
978
                    brandStockMap.get("Realme") != null ? brandStockMap.get("Realme").getTotalValue() : 0.0,
979
                    brandStockMap.get("Oppo") != null ? brandStockMap.get("Oppo").getTotalValue() : 0.0,
980
                    brandStockMap.get("OnePlus") != null ? brandStockMap.get("OnePlus").getTotalValue() : 0.0,
981
                    brandStockMap.get("Poco") != null ? brandStockMap.get("Poco").getTotalValue() : 0.0,
982
                    brandStockMap.get("Lava") != null ? brandStockMap.get("Lava").getTotalValue() : 0.0,
983
                    brandStockMap.get("Itel") != null ? brandStockMap.get("Itel").getTotalValue() : 0.0,
984
                    brandStockMap.get("Almost New") != null ? brandStockMap.get("Almost New").getTotalValue() : 0.0
34619 ranu 985
            ));
986
 
34641 ranu 987
            Map<String, Long> brandSecondaryMap = fofoBrandWiseMtdSecondaryMap.get(fofoId);
988
            row.addAll(Arrays.asList(
34648 ranu 989
                    fofoTotalMtdSecondaryMap.get(fofoId),
34641 ranu 990
                    brandSecondaryMap.getOrDefault("Apple", 0L),
991
                    brandSecondaryMap.getOrDefault("Xiaomi", 0L),
992
                    brandSecondaryMap.getOrDefault("Vivo", 0L),
993
                    brandSecondaryMap.getOrDefault("Tecno", 0L),
994
                    brandSecondaryMap.getOrDefault("Samsung", 0L),
995
                    brandSecondaryMap.getOrDefault("Realme", 0L),
996
                    brandSecondaryMap.getOrDefault("Oppo", 0L),
997
                    brandSecondaryMap.getOrDefault("OnePlus", 0L),
998
                    brandSecondaryMap.getOrDefault("Poco", 0L),
999
                    brandSecondaryMap.getOrDefault("Lava", 0L),
1000
                    brandSecondaryMap.getOrDefault("Itel", 0L),
1001
                    brandSecondaryMap.getOrDefault("Almost New", 0L)
1002
            ));
1003
 
1004
            Map<String, Double> brandTertiaryMap = fofoBrandMtdTertiaryMap.get(fofoId);
1005
            row.addAll(Arrays.asList(
34648 ranu 1006
                    fofoTotalMtdTertiaryMap.get(fofoId),
34641 ranu 1007
                    brandTertiaryMap.getOrDefault("Apple", 0d),
1008
                    brandTertiaryMap.getOrDefault("Xiaomi", 0d),
1009
                    brandTertiaryMap.getOrDefault("Vivo", 0d),
1010
                    brandTertiaryMap.getOrDefault("Tecno", 0d),
1011
                    brandTertiaryMap.getOrDefault("Samsung", 0d),
1012
                    brandTertiaryMap.getOrDefault("Realme", 0d),
1013
                    brandTertiaryMap.getOrDefault("Oppo", 0d),
1014
                    brandTertiaryMap.getOrDefault("OnePlus", 0d),
1015
                    brandTertiaryMap.getOrDefault("Poco", 0d),
1016
                    brandTertiaryMap.getOrDefault("Lava", 0d),
1017
                    brandTertiaryMap.getOrDefault("Itel", 0d),
1018
                    brandTertiaryMap.getOrDefault("Almost New", 0d)
1019
            ));
1020
            rows.add(row);
34619 ranu 1021
        }
1022
 
1023
 
34641 ranu 1024
        // Send to email
1025
//        ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
1026
        ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
1027
        String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
34702 ranu 1028
        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com","ashutosh.verma@smartdukaan.com","sm@smartdukaan.com","raj.singh@smartdukaan.com"};
1029
//        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com"};
34619 ranu 1030
 
1031
        Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{}, "BI Retailer Monthly Report", "Please find attached the BI retailer secondary/tertiary monthly report.", fileName, new ByteArrayResource(csvStream.toByteArray()));
1032
 
1033
 
34606 ranu 1034
    }
1035
 
34641 ranu 1036
    public static ByteArrayOutputStream getExcelStreamWithMultiHeaders(List<List<String>> headerGroup, List<List<?>> rows) {
1037
        Workbook workbook = new XSSFWorkbook();
1038
        Sheet sheet = workbook.createSheet("BI Report");
1039
        int rowIndex = 0;
34606 ranu 1040
 
34641 ranu 1041
        CellStyle centeredStyle = workbook.createCellStyle();
1042
        centeredStyle.setAlignment(HorizontalAlignment.CENTER); // Center horizontally
1043
        centeredStyle.setVerticalAlignment(VerticalAlignment.CENTER); // Center vertically
34606 ranu 1044
 
34641 ranu 1045
    // Optional: bold font
1046
        Font font1 = workbook.createFont();
1047
        font1.setBold(true);
1048
        centeredStyle.setFont(font1);
34606 ranu 1049
 
34619 ranu 1050
 
34641 ranu 1051
 
1052
        // Create styles
1053
        Map<String, CellStyle> headerStyles = new HashMap<>();
1054
 
1055
        // fontPurpleStyle
1056
        CellStyle purpleStyle = workbook.createCellStyle();
1057
        purpleStyle.setFillForegroundColor(IndexedColors.ROSE.getIndex());
1058
        purpleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
1059
        purpleStyle.setFont(font1);
1060
        headerStyles.put("Assessment", purpleStyle);
1061
        headerStyles.put("Zero billing", purpleStyle);
1062
        headerStyles.put("Billing needed", purpleStyle);
1063
        headerStyles.put("Counta", purpleStyle);
1064
        headerStyles.put("MONTH BEGINNING DRR", purpleStyle);
1065
        headerStyles.put("REQ DRR", purpleStyle);
1066
        headerStyles.put("Drr %", purpleStyle);
1067
 
1068
        // Light Blue
1069
        CellStyle blueStyle = workbook.createCellStyle();
1070
        blueStyle.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
1071
        blueStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
1072
        blueStyle.setFont(font1);
1073
        headerStyles.put("Code", blueStyle);
1074
        headerStyles.put("Store Name", blueStyle);
1075
        headerStyles.put("City", blueStyle);
1076
        headerStyles.put("Area", blueStyle);
1077
        headerStyles.put("BM", blueStyle);
1078
        headerStyles.put("RBM", blueStyle);
1079
        headerStyles.put("Sales Manager", blueStyle);
1080
        headerStyles.put("Status", blueStyle);
1081
        headerStyles.put("Category", blueStyle);
1082
 
1083
        // Light Yellow
1084
        CellStyle yellowStyle = workbook.createCellStyle();
1085
        yellowStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
1086
        yellowStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
1087
        yellowStyle.setFont(font1);
1088
        headerStyles.put("Last billing Done", yellowStyle);
1089
        headerStyles.put("Total Stock", yellowStyle);
1090
 
1091
        // Light Orange
1092
        CellStyle orangeStyle = workbook.createCellStyle();
1093
        orangeStyle.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
1094
        orangeStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
1095
        orangeStyle.setFont(font1);
1096
        headerStyles.put("Total Tertiary", orangeStyle);
1097
        headerStyles.put("Total Secondary", orangeStyle);
1098
        headerStyles.put("Default", orangeStyle);
1099
 
1100
 
1101
        // Light green
1102
        CellStyle lightGreenStyle = workbook.createCellStyle();
1103
        lightGreenStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
1104
        lightGreenStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
1105
        lightGreenStyle.setFont(font1);
1106
        headerStyles.put("Short investment", lightGreenStyle);
1107
        headerStyles.put("INVESTMENT LEVEL", lightGreenStyle);
1108
        headerStyles.put("Loan", lightGreenStyle);
1109
        headerStyles.put("PO value", lightGreenStyle);
1110
        headerStyles.put("Agreed investment", lightGreenStyle);
1111
        headerStyles.put("Wallet", lightGreenStyle);
1112
        headerStyles.put("po+bill", lightGreenStyle);
1113
 
1114
        // Light Green
1115
        CellStyle secondary1 = createStyle(workbook, IndexedColors.LIGHT_GREEN);
1116
        CellStyle secondary2 = createStyle(workbook, IndexedColors.LIGHT_YELLOW);
1117
        CellStyle secondary3 = createStyle(workbook, IndexedColors.LIGHT_ORANGE);
1118
 
1119
        Map<String, CellStyle> brandStyles = new HashMap<>();
1120
        brandStyles.put("Apple", createStyle(workbook, IndexedColors.GREY_25_PERCENT));
1121
        brandStyles.put("Xiaomi", createStyle(workbook, IndexedColors.ORANGE));
1122
        brandStyles.put("Vivo", createStyle(workbook, IndexedColors.SKY_BLUE));
1123
        brandStyles.put("Tecno", createStyle(workbook, IndexedColors.LIGHT_BLUE));
1124
        brandStyles.put("Samsung", createStyle(workbook, IndexedColors.ROYAL_BLUE));
1125
        brandStyles.put("Realme", createStyle(workbook, IndexedColors.YELLOW));
1126
        brandStyles.put("Oppo", createStyle(workbook, IndexedColors.LIGHT_GREEN));
1127
        brandStyles.put("OnePlus", createStyle(workbook, IndexedColors.RED));
1128
        brandStyles.put("Poco", createStyle(workbook, IndexedColors.ORANGE));
1129
        brandStyles.put("Lava", createStyle(workbook, IndexedColors.LIGHT_YELLOW));
1130
        brandStyles.put("Itel", createStyle(workbook, IndexedColors.LIGHT_YELLOW));
1131
        brandStyles.put("Almost New", createStyle(workbook, IndexedColors.WHITE));
1132
 
1133
 
1134
        CellStyle defaultHeaderStyle = workbook.createCellStyle();
1135
        defaultHeaderStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
1136
        defaultHeaderStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
1137
        defaultHeaderStyle.setFont(font1);
1138
 
1139
 
1140
        Map<String, Integer> headerCount = new HashMap<>();
1141
 
1142
        for (int headerRowIndex = 0; headerRowIndex < headerGroup.size(); headerRowIndex++) {
1143
            List<String> headerRow = headerGroup.get(headerRowIndex);
1144
            Row row = sheet.createRow(rowIndex++);
1145
 
1146
            for (int i = 0; i < headerRow.size(); i++) {
1147
                String headerText = headerRow.get(i);
1148
                sheet.setColumnWidth(i, 25 * 256);
1149
                row.setHeightInPoints(20); // 25-point height
1150
                Cell cell = row.createCell(i);
1151
                cell.setCellValue(headerText);
1152
                cell.setCellStyle(centeredStyle);
1153
                // Count how many times this header has appeared
1154
                int count = headerCount.getOrDefault(headerText, 0) + 1;
1155
                headerCount.put(headerText, count);
1156
                // Apply special style for repeated headers
1157
                if (headerText.equals("Secondary Target") || headerText.equals("Secondary Achieved") || headerText.equals("Returns") || headerText.equals("Net Secondary") || headerText.equals("Secondary %") || headerText.equals("Tertiary Sale") || headerText.equals("Unbilled")) {
1158
                    if (count == 1) {
1159
                        cell.setCellStyle(secondary1);
1160
                    } else if (count == 2) {
1161
                        cell.setCellStyle(secondary2);
1162
                    } else if (count == 3) {
1163
                        cell.setCellStyle(secondary3);
1164
                    }
1165
                }
1166
                // Brand header styling (apply only for the 2nd row of headers)
1167
                else if (headerRowIndex == 1 && brandStyles.containsKey(headerText)) {
1168
                    cell.setCellStyle(brandStyles.get(headerText));
1169
                }else if (headerStyles.containsKey(headerText)) {
1170
                    cell.setCellStyle(headerStyles.get(headerText));
1171
                } else {
1172
                    cell.setCellStyle(defaultHeaderStyle); // default style for others
1173
                }
1174
            }
1175
        }
1176
 
1177
        // Write data rows
1178
        for (List<?> dataRow : rows) {
1179
            Row row = sheet.createRow(rowIndex++);
1180
            for (int i = 0; i < dataRow.size(); i++) {
1181
                Cell cell = row.createCell(i);
1182
                Object value = dataRow.get(i);
1183
                if (value instanceof Number) {
1184
                    cell.setCellValue(((Number) value).doubleValue());
1185
                } else {
1186
                    cell.setCellValue(value != null ? value.toString() : "");
1187
                }
1188
            }
1189
        }
1190
 
1191
        // Auto-size columns
1192
        if (!rows.isEmpty()) {
1193
            for (int i = 0; i < rows.get(0).size(); i++) {
1194
                sheet.autoSizeColumn(i);
1195
            }
1196
        }
1197
 
1198
        // Output as ByteArray
1199
        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
1200
            workbook.write(outputStream);
1201
            workbook.close();
1202
            return outputStream;
1203
        } catch (IOException e) {
1204
            throw new RuntimeException("Failed to generate Excel file", e);
1205
        }
1206
    }
1207
 
1208
 
1209
    private static CellStyle createStyle(Workbook workbook, IndexedColors color) {
1210
        CellStyle style = workbook.createCellStyle();
1211
        style.setFillForegroundColor(color.getIndex());
1212
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
1213
        Font font = workbook.createFont();
1214
        font.setBold(true);
1215
        style.setFont(font);
1216
        return style;
1217
    }
1218
 
1219
 
1220
 
1221
 
34306 ranu 1222
}