Subversion Repositories SmartDukaan

Rev

Rev 36008 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36008 Rev 36024
Line 1866... Line 1866...
1866
        bulkOrderService.parseBulkOrders(file, authId);
1866
        bulkOrderService.parseBulkOrders(file, authId);
1867
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
1867
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
1868
        return "response";
1868
        return "response";
1869
    }
1869
    }
1870
 
1870
 
-
 
1871
    private static final String PRICE_APPROVAL_EMAIL = "deena.nath@smartdukaan.com";
-
 
1872
 
-
 
1873
    /**
-
 
1874
     * Returns the highest Sales escalation level for this user, or null if not in Sales.
-
 
1875
     */
-
 
1876
    private EscalationType getSalesEscalationLevel(int authUserId) {
-
 
1877
        EscalationType highest = null;
-
 
1878
        List<Position> positions = positionRepository.selectPositionByAuthId(authUserId);
-
 
1879
        for (Position position : positions) {
-
 
1880
            if (position.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES) {
-
 
1881
                if (highest == null || position.getEscalationType().isGreaterThanEqualTo(highest)) {
-
 
1882
                    highest = position.getEscalationType();
-
 
1883
                }
-
 
1884
            }
-
 
1885
        }
-
 
1886
        return highest;
-
 
1887
    }
-
 
1888
 
1871
    // This method is use for sending all pending transaction to Transation Approval menu
1889
    // This method is use for sending all pending transaction to Transation Approval menu
1872
    @RequestMapping(value = "/transaction/pendingApprovals", method = RequestMethod.GET)
1890
    @RequestMapping(value = "/transaction/pendingApprovals", method = RequestMethod.GET)
1873
    public String getTransactionApproval(HttpServletRequest request, Model model) throws Exception {
1891
    public String getTransactionApproval(HttpServletRequest request, Model model) throws Exception {
-
 
1892
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1893
        String email = loginDetails.getEmailId();
-
 
1894
        AuthUser authUser = authRepository.selectByEmailOrMobile(email);
-
 
1895
 
-
 
1896
        boolean canSeeAll = false;
-
 
1897
        boolean canSeeFirstPo = false;
-
 
1898
        boolean canSeePriceApproval = false;
-
 
1899
 
-
 
1900
        if (authUser != null) {
-
 
1901
            EscalationType salesLevel = getSalesEscalationLevel(authUser.getId());
-
 
1902
            if (salesLevel != null) {
-
 
1903
                if (salesLevel.isGreaterThanEqualTo(EscalationType.L4)) {
-
 
1904
                    canSeeAll = true;
-
 
1905
                } else if (salesLevel.isGreaterThanEqualTo(EscalationType.L3)) {
-
 
1906
                    canSeeFirstPo = true;
-
 
1907
                }
-
 
1908
            }
-
 
1909
        }
-
 
1910
 
-
 
1911
        if (PRICE_APPROVAL_EMAIL.equalsIgnoreCase(email)) {
-
 
1912
            canSeePriceApproval = true;
-
 
1913
        }
-
 
1914
 
1874
        List<TransactionApproval> transactionApprovals = transactionApprovalRepository.selectAllPending();
1915
        List<TransactionApprovalModel> approvalModelList;
-
 
1916
        if (canSeeAll || (canSeeFirstPo && canSeePriceApproval)) {
1875
        LOGGER.info("list of Approval transaction Id: {}", transactionApprovals);
1917
            approvalModelList = bulkOrderService.getAllPendingTransactionApproval();
-
 
1918
        } else if (canSeeFirstPo || canSeePriceApproval) {
1876
        List<TransactionApprovalModel> approvalModelList = bulkOrderService.getAllPendingTransactionApproval();
1919
            List<TransactionApprovalModel> allApprovals = bulkOrderService.getAllPendingTransactionApproval();
-
 
1920
            final boolean filterFirstPo = canSeeFirstPo;
-
 
1921
            approvalModelList = allApprovals.stream()
-
 
1922
                    .filter(a -> filterFirstPo ? a.isFirstPo() : !a.isFirstPo())
-
 
1923
                    .collect(Collectors.toList());
-
 
1924
        } else {
-
 
1925
            approvalModelList = Collections.emptyList();
-
 
1926
        }
-
 
1927
 
-
 
1928
        LOGGER.info("pendingApprovals user={} canSeeAll={} canSeeFirstPo={} canSeePriceApproval={} showing={}",
-
 
1929
                email, canSeeAll, canSeeFirstPo, canSeePriceApproval, approvalModelList.size());
1877
        model.addAttribute("approvalModelList", approvalModelList);
1930
        model.addAttribute("approvalModelList", approvalModelList);
1878
        return "transaction/transaction-approvals";
1931
        return "transaction/transaction-approvals";
1879
    }
1932
    }
1880
 
1933
 
1881
    @RequestMapping(value = "transaction/approval", method = RequestMethod.PUT)
1934
    @RequestMapping(value = "transaction/approval", method = RequestMethod.PUT)
Line 1883... Line 1936...
1883
                                      @RequestParam int transactionId,
1936
                                      @RequestParam int transactionId,
1884
                                      @RequestParam String remark,
1937
                                      @RequestParam String remark,
1885
                                      @RequestParam TransactionApprovalStatus transactionApprovalStatus
1938
                                      @RequestParam TransactionApprovalStatus transactionApprovalStatus
1886
    ) throws Exception {
1939
    ) throws Exception {
1887
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1940
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1941
        String email = loginDetails.getEmailId();
1888
        AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
1942
        AuthUser authUser = authRepository.selectByEmailOrMobile(email);
-
 
1943
        if (authUser == null) {
-
 
1944
            throw new ProfitMandiBusinessException("UNAUTHORIZED", "User not found", "User not found");
-
 
1945
        }
-
 
1946
 
-
 
1947
        EscalationType salesLevel = getSalesEscalationLevel(authUser.getId());
-
 
1948
        boolean isSuperApprover = salesLevel != null && salesLevel.isGreaterThanEqualTo(EscalationType.L4);
-
 
1949
 
-
 
1950
        if (!isSuperApprover) {
-
 
1951
            // Verify the user has permission to approve this specific transaction type
-
 
1952
            TransactionApproval ta = transactionApprovalRepository.selectById(transactionId);
-
 
1953
            if (ta.isFirstPo()) {
-
 
1954
                if (salesLevel == null || !salesLevel.isGreaterThanEqualTo(EscalationType.L3)) {
-
 
1955
                    throw new ProfitMandiBusinessException("UNAUTHORIZED",
-
 
1956
                            "Only Sales L3+ can approve First PO", "Only Sales L3+ can approve First PO");
-
 
1957
                }
-
 
1958
            } else {
-
 
1959
                if (!PRICE_APPROVAL_EMAIL.equalsIgnoreCase(email)) {
-
 
1960
                    throw new ProfitMandiBusinessException("UNAUTHORIZED",
-
 
1961
                            "Not authorized to approve price difference", "Not authorized to approve price difference");
-
 
1962
                }
-
 
1963
            }
-
 
1964
        }
-
 
1965
 
1889
        int approvalId = authUser.getId();
1966
        int approvalId = authUser.getId();
1890
        String approvedBy = authUser.getFullName();
1967
        String approvedBy = authUser.getFullName();
1891
        LocalDateTime approvedOn = LocalDateTime.now();
1968
        LocalDateTime approvedOn = LocalDateTime.now();
1892
        this.updateApprovalStatus(transactionId, approvalId, approvedBy, approvedOn, remark, transactionApprovalStatus);
1969
        this.updateApprovalStatus(transactionId, approvalId, approvedBy, approvedOn, remark, transactionApprovalStatus);
1893
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
1970
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));