Subversion Repositories SmartDukaan

Rev

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

Rev 34096 Rev 34236
Line 6... Line 6...
6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
7
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
7
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
8
import com.spice.profitmandi.common.services.ReporticoService;
8
import com.spice.profitmandi.common.services.ReporticoService;
9
import com.spice.profitmandi.common.util.FileUtil;
9
import com.spice.profitmandi.common.util.FileUtil;
10
import com.spice.profitmandi.common.util.FormattingUtils;
10
import com.spice.profitmandi.common.util.FormattingUtils;
-
 
11
import com.spice.profitmandi.common.util.Utils;
11
import com.spice.profitmandi.dao.entity.auth.AuthUser;
12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
12
import com.spice.profitmandi.dao.entity.cs.Position;
13
import com.spice.profitmandi.dao.entity.cs.Position;
13
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
14
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
14
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
15
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
-
 
16
import com.spice.profitmandi.dao.entity.transaction.CreditNote;
15
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
17
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
16
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
18
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
17
import com.spice.profitmandi.dao.model.*;
19
import com.spice.profitmandi.dao.model.*;
18
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
20
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
19
import com.spice.profitmandi.dao.repository.cs.CsService;
21
import com.spice.profitmandi.dao.repository.cs.CsService;
Line 24... Line 26...
24
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
26
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
25
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
27
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
26
import com.spice.profitmandi.dao.repository.transaction.*;
28
import com.spice.profitmandi.dao.repository.transaction.*;
27
import com.spice.profitmandi.service.authentication.RoleManager;
29
import com.spice.profitmandi.service.authentication.RoleManager;
28
import com.spice.profitmandi.service.order.OrderService;
30
import com.spice.profitmandi.service.order.OrderService;
-
 
31
import com.spice.profitmandi.service.transaction.CreditNoteService;
29
import com.spice.profitmandi.service.transaction.TransactionService;
32
import com.spice.profitmandi.service.transaction.TransactionService;
30
import com.spice.profitmandi.service.user.RetailerService;
33
import com.spice.profitmandi.service.user.RetailerService;
31
import com.spice.profitmandi.service.wallet.WalletService;
34
import com.spice.profitmandi.service.wallet.WalletService;
32
import com.spice.profitmandi.web.model.LoginDetails;
35
import com.spice.profitmandi.web.model.LoginDetails;
33
import com.spice.profitmandi.web.util.CookiesProcessor;
36
import com.spice.profitmandi.web.util.CookiesProcessor;
Line 37... Line 40...
37
import org.apache.logging.log4j.Logger;
40
import org.apache.logging.log4j.Logger;
38
import org.springframework.beans.factory.annotation.Autowired;
41
import org.springframework.beans.factory.annotation.Autowired;
39
import org.springframework.core.io.InputStreamResource;
42
import org.springframework.core.io.InputStreamResource;
40
import org.springframework.http.HttpHeaders;
43
import org.springframework.http.HttpHeaders;
41
import org.springframework.http.HttpStatus;
44
import org.springframework.http.HttpStatus;
-
 
45
import org.springframework.http.MediaType;
42
import org.springframework.http.ResponseEntity;
46
import org.springframework.http.ResponseEntity;
43
import org.springframework.stereotype.Controller;
47
import org.springframework.stereotype.Controller;
44
import org.springframework.transaction.annotation.Transactional;
48
import org.springframework.transaction.annotation.Transactional;
45
import org.springframework.ui.Model;
49
import org.springframework.ui.Model;
46
import org.springframework.web.bind.annotation.*;
50
import org.springframework.web.bind.annotation.*;
Line 48... Line 52...
48
import javax.servlet.http.HttpServletRequest;
52
import javax.servlet.http.HttpServletRequest;
49
import java.io.IOException;
53
import java.io.IOException;
50
import java.time.LocalDate;
54
import java.time.LocalDate;
51
import java.time.LocalDateTime;
55
import java.time.LocalDateTime;
52
import java.time.LocalTime;
56
import java.time.LocalTime;
-
 
57
import java.time.YearMonth;
53
import java.time.format.DateTimeFormatter;
58
import java.time.format.DateTimeFormatter;
54
import java.util.*;
59
import java.util.*;
55
import java.util.stream.Collectors;
60
import java.util.stream.Collectors;
56
 
61
 
57
@Controller
62
@Controller
Line 95... Line 100...
95
    private LoanStatementRepository loanStatementRepository;
100
    private LoanStatementRepository loanStatementRepository;
96
    @Autowired
101
    @Autowired
97
    PositionRepository positionRepository;
102
    PositionRepository positionRepository;
98
 
103
 
99
    @Autowired
104
    @Autowired
-
 
105
    CreditNoteRepository creditNoteRepository;
-
 
106
 
-
 
107
    @Autowired
-
 
108
    CreditNoteService creditNoteService;
-
 
109
 
-
 
110
    @Autowired
100
    UserWalletRepository userWalletRepository;
111
    UserWalletRepository userWalletRepository;
101
    @PostMapping(value = "/reports/{projectName}/{fileName}")
112
    @PostMapping(value = "/reports/{projectName}/{fileName}")
102
    public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
113
    public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
103
                                         @PathVariable ReporticoProject projectName, @RequestBody Map<String, String> paramsMap)
114
                                         @PathVariable ReporticoProject projectName, @RequestBody Map<String, String> paramsMap)
104
            throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
115
            throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
Line 1578... Line 1589...
1578
        ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Partner Loan Summary Report");
1589
        ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Partner Loan Summary Report");
1579
 
1590
 
1580
        return responseEntity;
1591
        return responseEntity;
1581
 
1592
 
1582
    }
1593
    }
-
 
1594
 
-
 
1595
    @RequestMapping(value = "/report/credit-note", method = RequestMethod.GET)
-
 
1596
    public String creditNote(HttpServletRequest request, Model model)
-
 
1597
            throws Exception {
-
 
1598
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1599
        boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
1600
        boolean isRBM = false;
-
 
1601
        if (isAdmin) {
-
 
1602
            AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
-
 
1603
            List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
-
 
1604
            isRBM = positions.stream()
-
 
1605
                    .anyMatch(position ->
-
 
1606
                            ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
-
 
1607
            Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
-
 
1608
            if (isRBM && pp.containsKey(authUser.getId())) {
-
 
1609
                List<Integer> fofoIds = pp.get(authUser.getId());
-
 
1610
                Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(fofoId -> {
-
 
1611
                    try {
-
 
1612
                        return retailerService.getFofoRetailers(true).get(fofoId);
-
 
1613
                    } catch (ProfitMandiBusinessException e) {
-
 
1614
                        // TODO Auto-generated catch block
-
 
1615
                        return null;
-
 
1616
                    }
-
 
1617
                }).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
-
 
1618
                model.addAttribute("customRetailersMap", customRetailersMap);
-
 
1619
            }
-
 
1620
        }
-
 
1621
        model.addAttribute("isRBM", isRBM);
-
 
1622
        model.addAttribute("isAdmin", isAdmin);
-
 
1623
 
-
 
1624
        return "credit-note";
-
 
1625
 
-
 
1626
    }
-
 
1627
 
-
 
1628
 
-
 
1629
    @RequestMapping(value = "/credit/credit-note-report", method = RequestMethod.GET)
-
 
1630
    public String creditNoteReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
-
 
1631
                                   @RequestParam(required = false) YearMonth yearMonth)
-
 
1632
            throws Exception {
-
 
1633
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1634
        boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
1635
        int partnerId = 0;
-
 
1636
 
-
 
1637
        if (fofoId > 0) {
-
 
1638
            partnerId = fofoId;
-
 
1639
        } else {
-
 
1640
            partnerId = loginDetails.getFofoId();
-
 
1641
        }
-
 
1642
 
-
 
1643
        LOGGER.info("partnerId: " + partnerId + " yearMonth: " + yearMonth);
-
 
1644
 
-
 
1645
        List<CreditNote> creditNotes = creditNoteRepository.selectAll(partnerId, yearMonth);
-
 
1646
 
-
 
1647
        model.addAttribute("isAdmin", isAdmin);
-
 
1648
        model.addAttribute("creditNotes", creditNotes);
-
 
1649
 
-
 
1650
        return "credit-note-list";
-
 
1651
 
-
 
1652
    }
-
 
1653
 
-
 
1654
    @RequestMapping(value = "/credit-note/download", method = RequestMethod.GET)
-
 
1655
    public ResponseEntity<?> downloadCreditNote(@RequestParam("cnNumber") String cnNumber) {
-
 
1656
        try {
-
 
1657
            CreditNote creditNote = creditNoteRepository.selectByCreditNoteNumber(cnNumber);
-
 
1658
 
-
 
1659
            YearMonth yearMonth = YearMonth.from(creditNote.getCnDate());
-
 
1660
            int fofoId = creditNote.getFofoId();
-
 
1661
 
-
 
1662
            Utils.Attachment attachment = creditNoteService.downloadCN(creditNote, yearMonth, fofoId);
-
 
1663
 
-
 
1664
            return ResponseEntity.ok()
-
 
1665
                    .contentType(MediaType.APPLICATION_PDF)
-
 
1666
                    .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + attachment.getFileName() + "\"")
-
 
1667
                    .body(attachment.getInputStreamSource());
-
 
1668
        } catch (Exception e) {
-
 
1669
            e.printStackTrace();
-
 
1670
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error generating PDF: " + e.getMessage());
-
 
1671
        }
-
 
1672
    }
-
 
1673
 
1583
}
1674
}