| 31436 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
5 |
import com.spice.profitmandi.common.util.Utils;
|
|
|
6 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
|
|
7 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
8 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
|
|
9 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
10 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
import org.springframework.ui.Model;
|
|
|
15 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
18 |
|
|
|
19 |
import javax.servlet.http.HttpServletRequest;
|
|
|
20 |
import java.time.LocalDateTime;
|
|
|
21 |
import java.time.LocalTime;
|
|
|
22 |
import java.time.YearMonth;
|
|
|
23 |
import java.util.ArrayList;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
import java.util.Map;
|
|
|
26 |
import java.util.stream.Collectors;
|
|
|
27 |
|
|
|
28 |
@Controller
|
| 35458 |
amit |
29 |
@Transactional(rollbackFor = Throwable.class)
|
| 31436 |
amit.gupta |
30 |
public class InvoiceController {
|
|
|
31 |
@Autowired
|
|
|
32 |
OrderRepository orderRepository;
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
CookiesProcessor cookiesProcessor;
|
|
|
36 |
|
|
|
37 |
@Autowired
|
|
|
38 |
RoleManager roleManager;
|
|
|
39 |
|
|
|
40 |
@RequestMapping(value = {"invoice-summary", "/invoice-summary/{yearMonth}" })
|
|
|
41 |
public String addAddress(HttpServletRequest request, @PathVariable(required = false) YearMonth yearMonth, Model model, @RequestParam(defaultValue = "0") int fofoId) throws ProfitMandiBusinessException {
|
|
|
42 |
if (yearMonth == null) {
|
|
|
43 |
yearMonth = YearMonth.now();
|
|
|
44 |
}
|
|
|
45 |
LocalDateTime startDate = yearMonth.atDay(1).atStartOfDay();
|
|
|
46 |
LocalDateTime endDate = yearMonth.atEndOfMonth().atTime(LocalTime.MAX);
|
|
|
47 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
48 |
boolean isAdmin = false;
|
|
|
49 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
50 |
isAdmin = true;
|
|
|
51 |
} else {
|
|
|
52 |
fofoId = loginDetails.getFofoId();
|
|
|
53 |
}
|
|
|
54 |
List<Order> orders;
|
|
|
55 |
if (fofoId == 0) {
|
|
|
56 |
orders = new ArrayList<>();
|
|
|
57 |
} else {
|
|
|
58 |
orders = orderRepository.selectAllByBillingDatesBetween(fofoId, startDate,
|
|
|
59 |
endDate);
|
|
|
60 |
}
|
|
|
61 |
Map<String, LocalDateTime> invoiceBillingDateMap = orders.stream().filter(Utils.distinctByKey(x -> x.getInvoiceNumber())).collect(Collectors.toMap(x -> x.getInvoiceNumber(), x -> x.getBillingTimestamp()));
|
|
|
62 |
String yearMonthString = FormattingUtils.formatYearMonth(startDate);
|
|
|
63 |
model.addAttribute("yearMonth", yearMonth);
|
|
|
64 |
model.addAttribute("invoiceMap", invoiceBillingDateMap);
|
|
|
65 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
66 |
|
|
|
67 |
return "invoice-summary";
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
}
|