Subversion Repositories SmartDukaan

Rev

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

Rev 34301 Rev 34322
Line 14... Line 14...
14
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
14
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
15
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
15
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
16
import com.spice.profitmandi.dao.entity.cs.Position;
16
import com.spice.profitmandi.dao.entity.cs.Position;
17
import com.spice.profitmandi.dao.entity.dtr.User;
17
import com.spice.profitmandi.dao.entity.dtr.User;
18
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
18
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
19
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
20
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
-
 
21
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
-
 
22
import com.spice.profitmandi.dao.entity.fofo.RbmRating;
19
import com.spice.profitmandi.dao.entity.fofo.*;
23
import com.spice.profitmandi.dao.entity.user.*;
20
import com.spice.profitmandi.dao.entity.user.*;
24
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
21
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
25
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
22
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
26
import com.spice.profitmandi.dao.enumuration.dtr.*;
23
import com.spice.profitmandi.dao.enumuration.dtr.*;
27
import com.spice.profitmandi.dao.model.*;
24
import com.spice.profitmandi.dao.model.*;
28
import com.spice.profitmandi.dao.repository.auth.*;
25
import com.spice.profitmandi.dao.repository.auth.*;
29
import com.spice.profitmandi.dao.repository.cs.*;
26
import com.spice.profitmandi.dao.repository.cs.*;
30
import com.spice.profitmandi.dao.repository.dtr.*;
27
import com.spice.profitmandi.dao.repository.dtr.*;
31
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
28
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
32
import com.spice.profitmandi.dao.repository.fofo.RbmRatingRepository;
29
import com.spice.profitmandi.dao.repository.fofo.RbmRatingRepository;
-
 
30
import com.spice.profitmandi.dao.repository.fofo.SalesRatingRepository;
33
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
31
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
34
import com.spice.profitmandi.dao.repository.user.AddressRepository;
32
import com.spice.profitmandi.dao.repository.user.AddressRepository;
35
import com.spice.profitmandi.service.AuthService;
33
import com.spice.profitmandi.service.AuthService;
36
import com.spice.profitmandi.service.NotificationService;
34
import com.spice.profitmandi.service.NotificationService;
37
import com.spice.profitmandi.service.PartnerCollectionService;
35
import com.spice.profitmandi.service.PartnerCollectionService;
38
import com.spice.profitmandi.service.user.RetailerService;
36
import com.spice.profitmandi.service.user.RetailerService;
39
import com.spice.profitmandi.service.user.StoreTimelineTatService;
37
import com.spice.profitmandi.service.user.StoreTimelineTatService;
40
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
38
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
41
import com.spice.profitmandi.web.req.RbmRatingRequest;
39
import com.spice.profitmandi.web.req.RbmSalesRatingRequest;
42
import com.spice.profitmandi.web.res.Partner;
40
import com.spice.profitmandi.web.res.Partner;
43
import io.swagger.annotations.ApiImplicitParam;
41
import io.swagger.annotations.ApiImplicitParam;
44
import io.swagger.annotations.ApiImplicitParams;
42
import io.swagger.annotations.ApiImplicitParams;
45
import org.apache.commons.csv.CSVRecord;
43
import org.apache.commons.csv.CSVRecord;
46
import org.apache.commons.io.output.ByteArrayOutputStream;
44
import org.apache.commons.io.output.ByteArrayOutputStream;
Line 1592... Line 1590...
1592
    }
1590
    }
1593
 
1591
 
1594
    @Autowired
1592
    @Autowired
1595
    RbmRatingRepository rbmRatingRepository;
1593
    RbmRatingRepository rbmRatingRepository;
1596
 
1594
 
-
 
1595
    @Autowired
-
 
1596
    SalesRatingRepository salesRatingRepository;
-
 
1597
 
1597
    @RequestMapping(value = "/rbmRating", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
1598
    @RequestMapping(value = "/rbmRating", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
1598
    public ResponseEntity<?> rbmRating(HttpServletRequest request, @RequestBody RbmRatingRequest rbmRatingRequest, Model model) throws Exception {
1599
    public ResponseEntity<?> rbmRating(HttpServletRequest request, @RequestBody RbmSalesRatingRequest rbmSalesRatingRequest, Model model) throws Exception {
1599
        int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
1600
        int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
1600
        UserCart uc = userAccountRepository.getUserCart(userId);
1601
        UserCart uc = userAccountRepository.getUserCart(userId);
1601
        int fofoId = uc.getUserId();
1602
        int fofoId = uc.getUserId();
-
 
1603
 
1602
        int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
1604
        int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
-
 
1605
        int salesL1Id = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, fofoId);
1603
 
1606
 
1604
        YearMonth currentMonth = YearMonth.now();
1607
        YearMonth currentMonth = YearMonth.now();
1605
        LocalDateTime startOfMonth = currentMonth.atDay(1).atStartOfDay();
1608
        LocalDateTime startOfMonth = currentMonth.atDay(1).atStartOfDay();
1606
        LocalDateTime endOfMonth = currentMonth.atEndOfMonth().atTime(23, 59, 59);
1609
        LocalDateTime endOfMonth = currentMonth.atEndOfMonth().atTime(23, 59, 59);
1607
 
1610
 
-
 
1611
        // Check if RBM rating already exists
1608
        List<RbmRating> existingRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfMonth, endOfMonth);
1612
        List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfMonth, endOfMonth);
1609
        if (!existingRatings.isEmpty()) {
1613
        if (!existingRbmRatings.isEmpty()) {
1610
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this month already exists.");
1614
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this month already exists.");
1611
        }
1615
        }
1612
 
1616
 
-
 
1617
        // Check if Sales Person rating exists (optional check)
-
 
1618
        List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfMonth, endOfMonth);
1613
        LOGGER.info("existingRatings {}", existingRatings);
1619
        if (!existingSalesRatings.isEmpty()) {
-
 
1620
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this month already exists.");
-
 
1621
        }
1614
 
1622
 
1615
        // Save the new rating
1623
        // Save RBM rating
1616
        RbmRating rbmRating = new RbmRating();
1624
        RbmRating rbmRating = new RbmRating();
1617
        rbmRating.setComment(rbmRatingRequest.getComment());
1625
        rbmRating.setComment(rbmSalesRatingRequest.getRbmComment());
1618
        rbmRating.setRating(rbmRatingRequest.getRating());
1626
        rbmRating.setRating(rbmSalesRatingRequest.getRbmRating());
1619
        rbmRating.setFofoId(fofoId);
1627
        rbmRating.setFofoId(fofoId);
1620
        rbmRating.setRbmId(rbmL1);
1628
        rbmRating.setRbmId(rbmL1);
1621
        rbmRating.setCreateTimeStamp(LocalDateTime.now());
1629
        rbmRating.setCreateTimeStamp(LocalDateTime.now());
1622
        rbmRatingRepository.persist(rbmRating);
1630
        rbmRatingRepository.persist(rbmRating);
1623
 
1631
 
-
 
1632
        // Save Sales Person rating
-
 
1633
        SalesRating salesRating = new SalesRating();
-
 
1634
        salesRating.setComment(rbmSalesRatingRequest.getSalesComment());
-
 
1635
        salesRating.setRating(rbmSalesRatingRequest.getSalesRating());
-
 
1636
        salesRating.setFofoId(fofoId);
-
 
1637
        salesRating.setSalesL1Id(salesL1Id);
-
 
1638
        salesRating.setCreateTimeStamp(LocalDateTime.now());
-
 
1639
        salesRatingRepository.persist(salesRating);
-
 
1640
 
1624
        return responseSender.ok(true);
1641
        return responseSender.ok("Rating submitted successfully.");
1625
    }
1642
    }
1626
 
1643
 
1627
 
1644
 
-
 
1645
 
1628
}
1646
}
1629
1647