| Line 2597... |
Line 2597... |
| 2597 |
LocalDate startOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
|
2597 |
LocalDate startOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
|
| 2598 |
LocalDate endOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
|
2598 |
LocalDate endOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
|
| 2599 |
LocalDateTime startOfMonthDateTime = startOfMonth.atStartOfDay();
|
2599 |
LocalDateTime startOfMonthDateTime = startOfMonth.atStartOfDay();
|
| 2600 |
LocalDateTime endOfMonthDateTime = endOfMonth.atTime(23, 59, 59);
|
2600 |
LocalDateTime endOfMonthDateTime = endOfMonth.atTime(23, 59, 59);
|
| 2601 |
|
2601 |
|
| - |
|
2602 |
// JSON error body so Angular's HttpClient (produces = APPLICATION_JSON)
|
| - |
|
2603 |
// doesn't add a "parse error" alongside the 400. Was returning a plain
|
| - |
|
2604 |
// string which caused the "Http failure response … 400 Bad Request
|
| - |
|
2605 |
// (2 errors)" toast for partners who tried to re-submit a rating in
|
| - |
|
2606 |
// the same month.
|
| 2602 |
List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfMonthDateTime, endOfMonthDateTime);
|
2607 |
List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfMonthDateTime, endOfMonthDateTime);
|
| 2603 |
if (!existingRbmRatings.isEmpty()) {
|
2608 |
if (!existingRbmRatings.isEmpty()) {
|
| - |
|
2609 |
Map<String, Object> body = new HashMap<>();
|
| - |
|
2610 |
body.put("code", "RATING_ALREADY_EXISTS");
|
| - |
|
2611 |
body.put("message", "Rating for this month already exists.");
|
| 2604 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this month already exists.");
|
2612 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(body);
|
| 2605 |
}
|
2613 |
}
|
| 2606 |
|
2614 |
|
| 2607 |
List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfMonthDateTime, endOfMonthDateTime);
|
2615 |
List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfMonthDateTime, endOfMonthDateTime);
|
| 2608 |
if (!existingSalesRatings.isEmpty()) {
|
2616 |
if (!existingSalesRatings.isEmpty()) {
|
| - |
|
2617 |
Map<String, Object> body = new HashMap<>();
|
| - |
|
2618 |
body.put("code", "RATING_ALREADY_EXISTS");
|
| - |
|
2619 |
body.put("message", "Rating for this month already exists.");
|
| 2609 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this month already exists.");
|
2620 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(body);
|
| 2610 |
}
|
2621 |
}
|
| 2611 |
|
2622 |
|
| 2612 |
// Save RBM rating
|
2623 |
// Save RBM rating
|
| 2613 |
RbmRating rbmRating = new RbmRating();
|
2624 |
RbmRating rbmRating = new RbmRating();
|
| 2614 |
rbmRating.setComment(rbmSalesRatingRequest.getRbmComment());
|
2625 |
rbmRating.setComment(rbmSalesRatingRequest.getRbmComment());
|
| Line 2625... |
Line 2636... |
| 2625 |
salesRating.setFofoId(fofoId);
|
2636 |
salesRating.setFofoId(fofoId);
|
| 2626 |
salesRating.setSalesL1Id(salesL1Id);
|
2637 |
salesRating.setSalesL1Id(salesL1Id);
|
| 2627 |
salesRating.setCreateTimeStamp(LocalDateTime.now());
|
2638 |
salesRating.setCreateTimeStamp(LocalDateTime.now());
|
| 2628 |
salesRatingRepository.persist(salesRating);
|
2639 |
salesRatingRepository.persist(salesRating);
|
| 2629 |
|
2640 |
|
| - |
|
2641 |
Map<String, Object> ok = new HashMap<>();
|
| - |
|
2642 |
ok.put("code", "OK");
|
| 2630 |
return responseSender.ok("Rating submitted successfully.");
|
2643 |
ok.put("message", "Rating submitted successfully.");
|
| - |
|
2644 |
return responseSender.ok(ok);
|
| - |
|
2645 |
}
|
| - |
|
2646 |
|
| - |
|
2647 |
/**
|
| - |
|
2648 |
* GET /rbmRating/exists-this-month — quick precheck so the client can
|
| - |
|
2649 |
* hide/disable the rating popup when a rating for the current month
|
| - |
|
2650 |
* already exists. Returns per-side booleans so the UI can distinguish
|
| - |
|
2651 |
* "only RBM done" vs "only Sales done" vs "both done" if it wants.
|
| - |
|
2652 |
*
|
| - |
|
2653 |
* Response:
|
| - |
|
2654 |
* {
|
| - |
|
2655 |
* "rbmRated": true|false,
|
| - |
|
2656 |
* "salesRated": true|false,
|
| - |
|
2657 |
* "canSubmit": true|false, // true only when NEITHER rating exists
|
| - |
|
2658 |
* "monthStart": "yyyy-MM-dd",
|
| - |
|
2659 |
* "monthEnd": "yyyy-MM-dd"
|
| - |
|
2660 |
* }
|
| - |
|
2661 |
*/
|
| - |
|
2662 |
@RequestMapping(value = "/rbmRating/exists-this-month", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
2663 |
public ResponseEntity<?> rbmRatingExistsThisMonth(HttpServletRequest request) throws Exception {
|
| - |
|
2664 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| - |
|
2665 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| - |
|
2666 |
int fofoId = uc.getUserId();
|
| - |
|
2667 |
|
| - |
|
2668 |
int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
| - |
|
2669 |
int salesL1Id = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, fofoId);
|
| - |
|
2670 |
|
| - |
|
2671 |
LocalDate today = LocalDate.now();
|
| - |
|
2672 |
LocalDate startOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
|
| - |
|
2673 |
LocalDate endOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
|
| - |
|
2674 |
LocalDateTime startOfMonthDateTime = startOfMonth.atStartOfDay();
|
| - |
|
2675 |
LocalDateTime endOfMonthDateTime = endOfMonth.atTime(23, 59, 59);
|
| - |
|
2676 |
|
| - |
|
2677 |
boolean rbmRated = !rbmRatingRepository
|
| - |
|
2678 |
.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfMonthDateTime, endOfMonthDateTime)
|
| - |
|
2679 |
.isEmpty();
|
| - |
|
2680 |
boolean salesRated = !salesRatingRepository
|
| - |
|
2681 |
.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfMonthDateTime, endOfMonthDateTime)
|
| - |
|
2682 |
.isEmpty();
|
| - |
|
2683 |
|
| - |
|
2684 |
Map<String, Object> body = new HashMap<>();
|
| - |
|
2685 |
body.put("rbmRated", rbmRated);
|
| - |
|
2686 |
body.put("salesRated", salesRated);
|
| - |
|
2687 |
// POST /rbmRating rejects when EITHER side already exists, so canSubmit
|
| - |
|
2688 |
// mirrors that gate rather than a per-side flag.
|
| - |
|
2689 |
body.put("canSubmit", !rbmRated && !salesRated);
|
| - |
|
2690 |
body.put("monthStart", startOfMonth.toString());
|
| - |
|
2691 |
body.put("monthEnd", endOfMonth.toString());
|
| - |
|
2692 |
return responseSender.ok(body);
|
| 2631 |
}
|
2693 |
}
|
| 2632 |
|
2694 |
|
| 2633 |
@RequestMapping(value = "/rbmRating/weekly-status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
2695 |
@RequestMapping(value = "/rbmRating/weekly-status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 2634 |
public ResponseEntity<?> rbmRatingWeeklyStatus(HttpServletRequest request) throws Exception {
|
2696 |
public ResponseEntity<?> rbmRatingWeeklyStatus(HttpServletRequest request) throws Exception {
|
| 2635 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
2697 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|