Subversion Repositories SmartDukaan

Rev

Rev 35098 | Rev 35252 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35098 Rev 35223
Line 21... Line 21...
21
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
21
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
22
import com.spice.profitmandi.dao.repository.cs.CsService;
22
import com.spice.profitmandi.dao.repository.cs.CsService;
23
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
23
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
24
import com.spice.profitmandi.dao.repository.dtr.*;
24
import com.spice.profitmandi.dao.repository.dtr.*;
25
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
25
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
-
 
26
import com.spice.profitmandi.dao.repository.fofo.RbmRatingRepository;
26
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
27
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
27
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
28
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
28
import com.spice.profitmandi.service.AuthService;
29
import com.spice.profitmandi.service.AuthService;
29
import com.spice.profitmandi.service.PartnerCollectionService;
30
import com.spice.profitmandi.service.PartnerCollectionService;
30
import com.spice.profitmandi.service.RbmTargetService;
31
import com.spice.profitmandi.service.RbmTargetService;
Line 53... Line 54...
53
import javax.servlet.http.HttpServletRequest;
54
import javax.servlet.http.HttpServletRequest;
54
import javax.servlet.http.HttpServletResponse;
55
import javax.servlet.http.HttpServletResponse;
55
import javax.transaction.Transactional;
56
import javax.transaction.Transactional;
56
import java.io.ByteArrayInputStream;
57
import java.io.ByteArrayInputStream;
57
import java.io.InputStream;
58
import java.io.InputStream;
-
 
59
import java.text.DecimalFormat;
58
import java.time.LocalDate;
60
import java.time.LocalDate;
59
import java.time.LocalDateTime;
61
import java.time.LocalDateTime;
60
import java.time.format.DateTimeFormatter;
62
import java.time.format.DateTimeFormatter;
61
import java.util.*;
63
import java.util.*;
62
import java.util.Map.Entry;
64
import java.util.Map.Entry;
Line 142... Line 144...
142
    @Autowired
144
    @Autowired
143
    private BrandsService brandsService;
145
    private BrandsService brandsService;
144
    @Autowired
146
    @Autowired
145
    OrderService orderService;
147
    OrderService orderService;
146
 
148
 
-
 
149
 
-
 
150
    @Autowired
-
 
151
    private RbmRatingRepository rbmRatingRepository;
-
 
152
 
147
    List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
153
    List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
148
 
154
 
149
    @RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
155
    @RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
150
    public String getOpenLead(HttpServletRequest request, @RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus, @RequestParam(name = "color", required = false, defaultValue = "All") List<String> color, @RequestParam(name = "leadDate", required = false, defaultValue = "") LocalDate leadDate, Model model) throws Exception {
156
    public String getOpenLead(HttpServletRequest request, @RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus, @RequestParam(name = "color", required = false, defaultValue = "All") List<String> color, @RequestParam(name = "leadDate", required = false, defaultValue = "") LocalDate leadDate, Model model) throws Exception {
151
 
157
 
Line 1120... Line 1126...
1120
    RbmTargetService rbmTargetService;
1126
    RbmTargetService rbmTargetService;
1121
 
1127
 
1122
    @RequestMapping(value = "/rbmTodayArr", method = RequestMethod.GET)
1128
    @RequestMapping(value = "/rbmTodayArr", method = RequestMethod.GET)
1123
    public String getRbmTodayArr(HttpServletRequest request, Model model, @RequestParam(value = "startDate", required = false) LocalDate startDate) throws Exception {
1129
    public String getRbmTodayArr(HttpServletRequest request, Model model, @RequestParam(value = "startDate", required = false) LocalDate startDate) throws Exception {
1124
        List<RbmArrViewModel> rbmArrViewModels;
1130
        List<RbmArrViewModel> rbmArrViewModels;
1125
 
-
 
-
 
1131
        DecimalFormat decimalFormat = new DecimalFormat("#"); // No decimal places
1126
        if (startDate != null) {
1132
        if (startDate != null) {
1127
            rbmArrViewModels = rbmTargetService.getRbmTodayArr(startDate);
1133
            rbmArrViewModels = rbmTargetService.getRbmTodayArr(startDate);
1128
        } else {
1134
        } else {
1129
            rbmArrViewModels = rbmTargetService.getRbmTodayArr();
1135
            rbmArrViewModels = rbmTargetService.getRbmTodayArr();
1130
        }
1136
        }
1131
 
1137
 
1132
        double totalAchieved = rbmArrViewModels.stream()
1138
        Set<AuthUser> authUsers = new HashSet<>();
1133
                .mapToDouble(RbmArrViewModel::getTotalAchievedTarget) // Replace with the actual getter method
1139
        Set<AuthUser> rbmAuthUsers = csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1).stream().filter(x -> x.isActive()).collect(Collectors.toSet());
1134
                .sum();
-
 
-
 
1140
        Set<AuthUser> salesAuthUsers = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_RBM, Arrays.asList(EscalationType.L1, EscalationType.L2)).stream().filter(x -> x.isActive()).collect(Collectors.toSet());
1135
 
1141
 
-
 
1142
        authUsers.addAll(rbmAuthUsers);
-
 
1143
        authUsers.addAll(salesAuthUsers);
-
 
1144
 
-
 
1145
        double totalAchieved = rbmArrViewModels.stream().mapToDouble(RbmArrViewModel::getTotalAchievedTarget).sum();
1136
        double totalTarget = rbmArrViewModels.stream()
1146
        double totalTargetSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayTarget).sum();
-
 
1147
 
1137
                .mapToDouble(RbmArrViewModel::getTodayTarget) // Replace with the actual getter method
1148
        double totalHidSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayHidTarget).sum();
-
 
1149
        double totalHidAchievedSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayAchievedHidTarget).sum();
-
 
1150
 
-
 
1151
        double totalFastSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayFastMovingTarget).sum();
-
 
1152
        double totalFastAchievedSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayAchievedFastMovingTarget).sum();
-
 
1153
 
1138
                .sum();
1154
        double totalSlowSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodaySlowMovingTarget).sum();
-
 
1155
        double totalSlowAchievedSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayAchievedSlowMovingTarget).sum();
-
 
1156
 
-
 
1157
        double totalRunningSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayRunningTarget).sum();
-
 
1158
        double totalRunningAchievedSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayAchievedRunningTarget).sum();
-
 
1159
 
-
 
1160
        double totalOtherSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayOtherMovingTarget).sum();
-
 
1161
        double totalOtherAchievedSum = rbmArrViewModels.stream().mapToLong(RbmArrViewModel::getTodayAchievedOtherMovingTarget).sum();
1139
 
1162
 
1140
        List<Sold15daysOldAgingModel> sold15daysOldAgingModels = rbmTargetService.getAgingSale(LocalDate.now(), LocalDate.now().plusDays(1));
1163
        List<Sold15daysOldAgingModel> sold15daysOldAgingModels = rbmTargetService.getAgingSale(LocalDate.now(), LocalDate.now().plusDays(1));
1141
        List<Our15DaysOldAgingStock> our15DaysOldAgingStocks = rbmTargetService.our15DaysAgingStock();
1164
        List<Our15DaysOldAgingStock> our15DaysOldAgingStocks = rbmTargetService.our15DaysAgingStock();
1142
 
1165
 
-
 
1166
        long totalSoldSlow = sold15daysOldAgingModels.stream().mapToLong(Sold15daysOldAgingModel::getSlowmovingBilled).sum();
-
 
1167
        long totalSoldRun = sold15daysOldAgingModels.stream().mapToLong(Sold15daysOldAgingModel::getRunningBilled).sum();
-
 
1168
        long totalSoldFast = sold15daysOldAgingModels.stream().mapToLong(Sold15daysOldAgingModel::getFastmovingBilled).sum();
-
 
1169
        long totalSoldHid = sold15daysOldAgingModels.stream().mapToLong(Sold15daysOldAgingModel::getHidBilled).sum();
-
 
1170
        long totalSoldOther = sold15daysOldAgingModels.stream().mapToLong(Sold15daysOldAgingModel::getOthersBilled).sum();
-
 
1171
        long totalSoldAging = sold15daysOldAgingModels.stream().mapToLong(Sold15daysOldAgingModel::getTotalBilled).sum();
-
 
1172
 
1143
 
1173
 
1144
//        first week count of rbm partner billing
1174
//        first week count of rbm partner billing
1145
        LocalDate firstOfCurrentMonth = LocalDate.now().withDayOfMonth(1);
1175
        LocalDate firstOfCurrentMonth = LocalDate.now().withDayOfMonth(1);
1146
        LocalDate seventhOfCurrentMonth = LocalDate.now().withDayOfMonth(7);
1176
        LocalDate seventhOfCurrentMonth = LocalDate.now().withDayOfMonth(7);
1147
 
1177
 
Line 1221... Line 1251...
1221
                        entry -> entry.getValue() - rbmBilledCountMapMtd.getOrDefault(entry.getKey(), 0L)
1251
                        entry -> entry.getValue() - rbmBilledCountMapMtd.getOrDefault(entry.getKey(), 0L)
1222
                ));
1252
                ));
1223
 
1253
 
1224
        long totalZeroBilledCount = zeroBilledCountMap.values().stream().mapToLong(Long::longValue).sum();
1254
        long totalZeroBilledCount = zeroBilledCountMap.values().stream().mapToLong(Long::longValue).sum();
1225
 
1255
 
-
 
1256
        //        rbmRating by franchisee visits
-
 
1257
 
-
 
1258
        Map<Integer, String> rbmIdToNameMap = authUsers.stream()
-
 
1259
                .collect(Collectors.toMap(AuthUser::getId, AuthUser::getFullName));
-
 
1260
 
-
 
1261
        Map<String, RbMRatingModel> rbmNameToRatingMap = rbmRatingRepository
-
 
1262
                .findAverageRatingByRbmId(new ArrayList<>(rbmIdToNameMap.keySet())).stream().collect(Collectors.toMap(
-
 
1263
                        x -> rbmIdToNameMap.get(x.getRbmId()),
-
 
1264
                        x -> x
-
 
1265
                ));
-
 
1266
 
-
 
1267
 
1226
        LOGGER.info("rbmArrViewModels {}", rbmArrViewModels);
1268
        LOGGER.info("rbmArrViewModels {}", rbmArrViewModels);
1227
        model.addAttribute("rbmArrViewModels", rbmArrViewModels);
1269
        model.addAttribute("rbmArrViewModels", rbmArrViewModels);
-
 
1270
        model.addAttribute("rbmNameToRatingMap", rbmNameToRatingMap);
-
 
1271
 
1228
        model.addAttribute("totalTarget", totalTarget);
1272
        model.addAttribute("totalTargetSum", decimalFormat.format(totalTargetSum));
1229
        model.addAttribute("totalAchieved", totalAchieved);
1273
        model.addAttribute("totalAchieved", decimalFormat.format(totalAchieved));
-
 
1274
 
1230
        model.addAttribute("sold15daysOldAgingModels", sold15daysOldAgingModels);
1275
        model.addAttribute("totalHidSum", decimalFormat.format(totalHidSum));
-
 
1276
        model.addAttribute("totalHidAchievedSum", decimalFormat.format(totalHidAchievedSum));
-
 
1277
 
-
 
1278
        model.addAttribute("totalFastSum", decimalFormat.format(totalFastSum));
-
 
1279
        model.addAttribute("totalFastAchievedSum", decimalFormat.format(totalFastAchievedSum));
-
 
1280
 
-
 
1281
        model.addAttribute("totalSlowSum", decimalFormat.format(totalSlowSum));
-
 
1282
        model.addAttribute("totalSlowAchievedSum", decimalFormat.format(totalSlowAchievedSum));
-
 
1283
 
-
 
1284
        model.addAttribute("totalRunningSum", decimalFormat.format(totalRunningSum));
-
 
1285
        model.addAttribute("totalRunningAchievedSum", decimalFormat.format(totalRunningAchievedSum));
-
 
1286
 
-
 
1287
        model.addAttribute("totalOtherSum", decimalFormat.format(totalOtherSum));
-
 
1288
        model.addAttribute("totalOtherAchievedSum", decimalFormat.format(totalOtherAchievedSum));
-
 
1289
 
1231
        model.addAttribute("our15DaysOldAgingStocks", our15DaysOldAgingStocks);
1290
        model.addAttribute("our15DaysOldAgingStocks", our15DaysOldAgingStocks);
-
 
1291
        model.addAttribute("sold15daysOldAgingModels", sold15daysOldAgingModels);
-
 
1292
        model.addAttribute("totalSoldSlow", totalSoldSlow);
-
 
1293
        model.addAttribute("totalSoldRun", totalSoldRun);
-
 
1294
        model.addAttribute("totalSoldFast", totalSoldFast);
-
 
1295
        model.addAttribute("totalSoldHid", totalSoldHid);
-
 
1296
        model.addAttribute("totalSoldOther", totalSoldOther);
-
 
1297
        model.addAttribute("totalSoldAging", totalSoldAging);
1232
 
1298
 
1233
        model.addAttribute("rbmTargetedFofoIdCountMap", rbmTargetedFofoIdCountMap);
1299
        model.addAttribute("rbmTargetedFofoIdCountMap", rbmTargetedFofoIdCountMap);
1234
        model.addAttribute("rbmBilledCountMapFirstWeek", rbmBilledCountMapFirstWeek);
1300
        model.addAttribute("rbmBilledCountMapFirstWeek", rbmBilledCountMapFirstWeek);
1235
        model.addAttribute("rbmBilledCountMapSecondWeek", rbmBilledCountMapSecondWeek);
1301
        model.addAttribute("rbmBilledCountMapSecondWeek", rbmBilledCountMapSecondWeek);
1236
        model.addAttribute("rbmBilledCountMapThirdWeek", rbmBilledCountMapThirdWeek);
1302
        model.addAttribute("rbmBilledCountMapThirdWeek", rbmBilledCountMapThirdWeek);