| Line 60... |
Line 60... |
| 60 |
import org.springframework.web.bind.annotation.*;
|
60 |
import org.springframework.web.bind.annotation.*;
|
| 61 |
import org.springframework.web.multipart.MultipartFile;
|
61 |
import org.springframework.web.multipart.MultipartFile;
|
| 62 |
|
62 |
|
| 63 |
import javax.servlet.http.HttpServletRequest;
|
63 |
import javax.servlet.http.HttpServletRequest;
|
| 64 |
import java.io.IOException;
|
64 |
import java.io.IOException;
|
| - |
|
65 |
import java.time.DayOfWeek;
|
| 65 |
import java.time.LocalDate;
|
66 |
import java.time.LocalDate;
|
| 66 |
import java.time.LocalDateTime;
|
67 |
import java.time.LocalDateTime;
|
| 67 |
import java.time.YearMonth;
|
68 |
import java.time.YearMonth;
|
| 68 |
import java.time.format.DateTimeFormatter;
|
69 |
import java.time.format.DateTimeFormatter;
|
| - |
|
70 |
import java.time.temporal.TemporalAdjusters;
|
| 69 |
import java.util.*;
|
71 |
import java.util.*;
|
| 70 |
import java.util.HashSet;
|
72 |
import java.util.HashSet;
|
| 71 |
import java.util.Map.Entry;
|
73 |
import java.util.Map.Entry;
|
| 72 |
import java.util.stream.Collectors;
|
74 |
import java.util.stream.Collectors;
|
| 73 |
|
75 |
|
| Line 2185... |
Line 2187... |
| 2185 |
int fofoId = uc.getUserId();
|
2187 |
int fofoId = uc.getUserId();
|
| 2186 |
|
2188 |
|
| 2187 |
int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
2189 |
int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
| 2188 |
int salesL1Id = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, fofoId);
|
2190 |
int salesL1Id = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, fofoId);
|
| 2189 |
|
2191 |
|
| - |
|
2192 |
// Calculate current week boundaries (Monday to Sunday)
|
| 2190 |
YearMonth currentMonth = YearMonth.now();
|
2193 |
LocalDate today = LocalDate.now();
|
| - |
|
2194 |
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
| - |
|
2195 |
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
| 2191 |
LocalDateTime startOfMonth = currentMonth.atDay(1).atStartOfDay();
|
2196 |
LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay();
|
| 2192 |
LocalDateTime endOfMonth = currentMonth.atEndOfMonth().atTime(23, 59, 59);
|
2197 |
LocalDateTime endOfWeekDateTime = endOfWeek.atTime(23, 59, 59);
|
| 2193 |
|
2198 |
|
| 2194 |
// Check if RBM rating already exists
|
2199 |
// Check if RBM rating already exists for this week
|
| 2195 |
List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfMonth, endOfMonth);
|
2200 |
List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfWeekDateTime, endOfWeekDateTime);
|
| 2196 |
if (!existingRbmRatings.isEmpty()) {
|
2201 |
if (!existingRbmRatings.isEmpty()) {
|
| 2197 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this month already exists.");
|
2202 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this week already exists.");
|
| 2198 |
}
|
2203 |
}
|
| 2199 |
|
2204 |
|
| 2200 |
// Check if Sales Person rating exists (optional check)
|
2205 |
// Check if Sales Person rating already exists for this week
|
| 2201 |
List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfMonth, endOfMonth);
|
2206 |
List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfWeekDateTime, endOfWeekDateTime);
|
| 2202 |
if (!existingSalesRatings.isEmpty()) {
|
2207 |
if (!existingSalesRatings.isEmpty()) {
|
| 2203 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this month already exists.");
|
2208 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this week already exists.");
|
| 2204 |
}
|
2209 |
}
|
| 2205 |
|
2210 |
|
| 2206 |
// Save RBM rating
|
2211 |
// Save RBM rating
|
| 2207 |
RbmRating rbmRating = new RbmRating();
|
2212 |
RbmRating rbmRating = new RbmRating();
|
| 2208 |
rbmRating.setComment(rbmSalesRatingRequest.getRbmComment());
|
2213 |
rbmRating.setComment(rbmSalesRatingRequest.getRbmComment());
|