| 32075 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 32900 |
amit.gupta |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 32194 |
tejbeer |
4 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
| 33183 |
shampa |
5 |
import com.spice.profitmandi.common.util.FileUtil;
|
|
|
6 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 32075 |
tejbeer |
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 34047 |
tejus.loha |
8 |
import com.spice.profitmandi.dao.entity.catalog.CategorisedCatalog;
|
| 32075 |
tejbeer |
9 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.inventory.Vendor;
|
|
|
11 |
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricing;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricingLog;
|
|
|
13 |
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
|
|
|
14 |
import com.spice.profitmandi.dao.enumuration.inventory.VendorCatalogPricingStatus;
|
|
|
15 |
import com.spice.profitmandi.dao.model.VendorCatalogPricingModel;
|
| 32163 |
tejbeer |
16 |
import com.spice.profitmandi.dao.model.VendorPriceCircularModel;
|
| 32075 |
tejbeer |
17 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 34047 |
tejus.loha |
18 |
import com.spice.profitmandi.dao.repository.catalog.CategorisedCatalogRepository;
|
| 32075 |
tejbeer |
19 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingLogRepository;
|
|
|
21 |
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingRepository;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.inventory.VendorRepository;
|
| 33183 |
shampa |
23 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 32075 |
tejbeer |
24 |
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
|
| 33183 |
shampa |
25 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 32075 |
tejbeer |
26 |
import com.spice.profitmandi.service.inventory.VendorCatalogPricingService;
|
| 33183 |
shampa |
27 |
import com.spice.profitmandi.service.order.OrderService;
|
| 32194 |
tejbeer |
28 |
import com.spice.profitmandi.service.warehouse.WarehouseService;
|
| 32075 |
tejbeer |
29 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
30 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
31 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 32383 |
amit.gupta |
32 |
import org.apache.logging.log4j.LogManager;
|
|
|
33 |
import org.apache.logging.log4j.Logger;
|
|
|
34 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 33465 |
ranu |
35 |
import org.springframework.core.io.ClassPathResource;
|
|
|
36 |
import org.springframework.core.io.InputStreamResource;
|
|
|
37 |
import org.springframework.http.HttpHeaders;
|
|
|
38 |
import org.springframework.http.MediaType;
|
| 33183 |
shampa |
39 |
import org.springframework.http.ResponseEntity;
|
| 32383 |
amit.gupta |
40 |
import org.springframework.stereotype.Controller;
|
|
|
41 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
42 |
import org.springframework.ui.Model;
|
| 33465 |
ranu |
43 |
import org.springframework.web.bind.annotation.*;
|
|
|
44 |
import org.springframework.web.multipart.MultipartFile;
|
| 32075 |
tejbeer |
45 |
|
| 36464 |
amit |
46 |
import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
47 |
import org.apache.poi.ss.usermodel.Font;
|
|
|
48 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
49 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
50 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
51 |
|
| 33465 |
ranu |
52 |
import javax.mail.MessagingException;
|
| 32383 |
amit.gupta |
53 |
import javax.servlet.http.HttpServletRequest;
|
| 36464 |
amit |
54 |
import java.io.ByteArrayInputStream;
|
|
|
55 |
import java.io.ByteArrayOutputStream;
|
| 33465 |
ranu |
56 |
import java.io.IOException;
|
| 32383 |
amit.gupta |
57 |
import java.time.LocalDate;
|
|
|
58 |
import java.time.LocalDateTime;
|
|
|
59 |
import java.util.*;
|
|
|
60 |
import java.util.stream.Collectors;
|
|
|
61 |
|
| 32075 |
tejbeer |
62 |
@Controller
|
|
|
63 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
64 |
public class VendorController {
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
@Autowired
|
|
|
68 |
VendorRepository vendorRepository;
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private CookiesProcessor cookiesProcessor;
|
|
|
72 |
|
|
|
73 |
@Autowired
|
| 33183 |
shampa |
74 |
private RoleManager roleManager;
|
|
|
75 |
|
|
|
76 |
@Autowired
|
| 32075 |
tejbeer |
77 |
private AuthRepository authRepository;
|
|
|
78 |
|
|
|
79 |
@Autowired
|
| 33183 |
shampa |
80 |
private OrderRepository orderRepository;
|
|
|
81 |
|
|
|
82 |
@Autowired
|
|
|
83 |
private OrderService orderService;
|
|
|
84 |
|
|
|
85 |
@Autowired
|
| 32075 |
tejbeer |
86 |
private VendorCatalogPricingService vendorCatalogPricingService;
|
|
|
87 |
|
|
|
88 |
@Autowired
|
|
|
89 |
private VendorCatalogPricingLogRepository vendorCatalogPricingLogRepository;
|
|
|
90 |
|
|
|
91 |
@Autowired
|
|
|
92 |
private VendorCatalogPricingRepository vendorCatalogPricingRepository;
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
@Autowired
|
|
|
96 |
private MVCResponseSender mvcResponseSender;
|
|
|
97 |
|
|
|
98 |
@Autowired
|
|
|
99 |
private ItemRepository itemRepository;
|
|
|
100 |
|
|
|
101 |
@Autowired
|
|
|
102 |
private SupplierRepository supplierRepository;
|
|
|
103 |
|
| 32194 |
tejbeer |
104 |
@Autowired
|
|
|
105 |
private WarehouseService warehouseService;
|
|
|
106 |
|
| 34047 |
tejus.loha |
107 |
@Autowired
|
|
|
108 |
CategorisedCatalogRepository categorisedCatalogRepository;
|
|
|
109 |
|
| 32075 |
tejbeer |
110 |
private static final Logger LOGGER = LogManager.getLogger(VendorController.class);
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
@RequestMapping(value = "/vendorCatalogPricing", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
114 |
public String vendorCatalogPricing() throws Exception {
|
| 32075 |
tejbeer |
115 |
return "vendor-catalog-pricing";
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
@RequestMapping(value = "/getVendorCatalogPricingByModel", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
120 |
public String getVendorCatalogPricingByModel(@RequestParam int catalogId, Model model) throws Exception {
|
| 32075 |
tejbeer |
121 |
|
|
|
122 |
List<Integer> vendorIds = new ArrayList<>();
|
|
|
123 |
Map<Integer, VendorCatalogPricing> vendorCatalogPricingMap = new HashMap<>();
|
|
|
124 |
Map<Integer, VendorCatalogPricingLog> vendorCatalogPricingLogMap = new HashMap<>();
|
|
|
125 |
List<VendorCatalogPricing> vendorCatalogPricing = vendorCatalogPricingRepository.selectByCatalogId(catalogId);
|
|
|
126 |
if (!vendorCatalogPricing.isEmpty()) {
|
|
|
127 |
vendorIds.addAll(vendorCatalogPricing.stream().distinct().map(x -> x.getVendorId()).collect(Collectors.toList()));
|
|
|
128 |
vendorCatalogPricingMap = vendorCatalogPricing.stream().collect(Collectors.toMap(x -> x.getVendorId(), x -> x));
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
List<VendorCatalogPricingLog> vendorCatalogPricingLog = vendorCatalogPricingLogRepository.selectByCatalogId(catalogId, VendorCatalogPricingStatus.PENDING);
|
|
|
132 |
if (!vendorCatalogPricingLog.isEmpty()) {
|
|
|
133 |
vendorIds.addAll(vendorCatalogPricingLog.stream().distinct().map(x -> x.getVendorId()).collect(Collectors.toList()));
|
|
|
134 |
vendorCatalogPricingLogMap = vendorCatalogPricingLog.stream().filter(x -> x.getStatus().equals(VendorCatalogPricingStatus.PENDING)).collect(Collectors.toMap(x -> x.getVendorId(), x -> x));
|
|
|
135 |
}
|
|
|
136 |
LOGGER.info("VendorIds {}", vendorIds);
|
|
|
137 |
List<Supplier> suppliers = new ArrayList<Supplier>();
|
|
|
138 |
if (!vendorIds.isEmpty()) {
|
|
|
139 |
suppliers.addAll(supplierRepository.selectBySupplierIds(vendorIds));
|
|
|
140 |
}
|
|
|
141 |
LOGGER.info("suppliers {}", suppliers);
|
|
|
142 |
|
|
|
143 |
model.addAttribute("suppliers", suppliers);
|
|
|
144 |
model.addAttribute("vendorCatalogPricingMap", vendorCatalogPricingMap);
|
|
|
145 |
model.addAttribute("vendorCatalogPricingLogMap", vendorCatalogPricingLogMap);
|
|
|
146 |
|
|
|
147 |
model.addAttribute("catalogId", catalogId);
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
return "vendor-catalog-pricing-view";
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
@RequestMapping(value = "/vendors", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
155 |
public String getVendor(Model model, @RequestParam String query) throws Throwable {
|
| 32398 |
amit.gupta |
156 |
List<Supplier> vendors = supplierRepository.selectAll().stream().filter(x -> x.getName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?"))
|
|
|
157 |
.filter(x -> x.isStatus()).collect(Collectors.toList());
|
| 32075 |
tejbeer |
158 |
model.addAttribute("response1", mvcResponseSender.createResponseString(vendors));
|
|
|
159 |
return "response";
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
@RequestMapping(value = "/createVendorCatalogPricing", method = RequestMethod.POST)
|
|
|
164 |
public String createVendorCatalogPricing(HttpServletRequest request, @RequestBody VendorCatalogPricingModel vendorCatalogPricingModel, Model model) throws Exception {
|
|
|
165 |
|
|
|
166 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
167 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
168 |
vendorCatalogPricingModel.setAuthId(authUser.getId());
|
|
|
169 |
|
|
|
170 |
LOGGER.info("vendorCatalogPricingModel {}", vendorCatalogPricingModel);
|
|
|
171 |
|
|
|
172 |
vendorCatalogPricingService.createVendorCatalogPricingLog(vendorCatalogPricingModel);
|
|
|
173 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
174 |
return "response";
|
|
|
175 |
|
|
|
176 |
}
|
|
|
177 |
|
| 33465 |
ranu |
178 |
@RequestMapping(value = "/createBulkPricing")
|
| 34047 |
tejus.loha |
179 |
public String createBulkPricing() throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 33465 |
ranu |
180 |
return "bulk-vendor-pricing";
|
|
|
181 |
}
|
| 32075 |
tejbeer |
182 |
|
| 33465 |
ranu |
183 |
@PostMapping(value = "/bulkVendorCatalogPricing/upload")
|
|
|
184 |
public String uploadCatalog(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model)
|
|
|
185 |
throws Exception {
|
|
|
186 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
187 |
int authId = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId()).getId();
|
|
|
188 |
LOGGER.info("authId - {}", authId);
|
|
|
189 |
vendorCatalogPricingService.parseBulkVendorCatalogPricing(file, authId);
|
|
|
190 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
191 |
return "response";
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
@GetMapping("/bulkVendorCatalogPricing/downloadReferenceFile")
|
| 33467 |
ranu |
195 |
public ResponseEntity<?> downloadReferenceFile() throws IOException {
|
| 33465 |
ranu |
196 |
ClassPathResource dummyFile = new ClassPathResource("vendor-catalog-pricing-file.xlsx"); // Make sure the file is in the resources folder
|
|
|
197 |
return ResponseEntity.ok()
|
|
|
198 |
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=dummy-file.xlsx")
|
|
|
199 |
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
200 |
.body(new InputStreamResource(dummyFile.getInputStream()));
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
|
| 32075 |
tejbeer |
204 |
@RequestMapping(value = "/vendorCatalogPricingRequests", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
205 |
public String vendorCatalogPricingRequests(Model model) throws Exception {
|
| 32075 |
tejbeer |
206 |
List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByStatus(VendorCatalogPricingStatus.PENDING);
|
|
|
207 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
208 |
model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
|
|
|
209 |
if (!vendorCatalogPricingRequests.isEmpty()) {
|
|
|
210 |
Set<Integer> catalogIds = vendorCatalogPricingRequests.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
211 |
List<Integer> vendorIds = vendorCatalogPricingRequests.stream().map(x -> x.getVendorId()).collect(Collectors.toList());
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
Map<Integer, List<Item>> itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
215 |
model.addAttribute("itemMap", itemMap);
|
|
|
216 |
}
|
|
|
217 |
Map<Integer, Vendor> vendorMap = vendorRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
218 |
model.addAttribute("authMap", authUserMap);
|
|
|
219 |
model.addAttribute("vendorMap", vendorMap);
|
|
|
220 |
model.addAttribute("vendorPricingStatus", VendorCatalogPricingStatus.values());
|
|
|
221 |
|
|
|
222 |
return "vendor-catalog-pricing-request";
|
|
|
223 |
}
|
|
|
224 |
|
| 33750 |
ranu |
225 |
@RequestMapping(value = "/vendorCatalogPricingPendingRequests", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
226 |
public String vendorCatalogPricingPendingRequests() throws Exception {
|
| 33750 |
ranu |
227 |
return "vendor-catalog-pricing-pending-request";
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
@RequestMapping(value = "/datewiseVendorCatalogPricingPendingRequests", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
231 |
public String datewiseVendorCatalogPricingPendingRequests(@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
|
| 33750 |
ranu |
232 |
List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByDate(startDate, endDate);
|
|
|
233 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
234 |
LOGGER.info("vendorCatalogPricingRequests {}", vendorCatalogPricingRequests);
|
|
|
235 |
model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
|
|
|
236 |
if (!vendorCatalogPricingRequests.isEmpty()) {
|
|
|
237 |
Set<Integer> catalogIds = vendorCatalogPricingRequests.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
238 |
Map<Integer, List<Item>> itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
239 |
model.addAttribute("itemMap", itemMap);
|
|
|
240 |
}
|
|
|
241 |
Map<Integer, Vendor> vendorMap = vendorRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
242 |
model.addAttribute("authMap", authUserMap);
|
|
|
243 |
model.addAttribute("vendorMap", vendorMap);
|
|
|
244 |
model.addAttribute("vendorPricingStatus", VendorCatalogPricingStatus.values());
|
|
|
245 |
|
|
|
246 |
return "vendor-catalog-pricing-pending-request-table";
|
|
|
247 |
}
|
|
|
248 |
|
| 32075 |
tejbeer |
249 |
@RequestMapping(value = "/verifyVendorCatalogPricingRequest", method = RequestMethod.POST)
|
|
|
250 |
public String verifyVendorCatalogPricingRequest(HttpServletRequest request, @RequestParam int id, @RequestParam VendorCatalogPricingStatus status, Model model) throws Exception {
|
| 32086 |
tejbeer |
251 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
252 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 32075 |
tejbeer |
253 |
|
|
|
254 |
VendorCatalogPricingLog vendorCatalogPricingLog = vendorCatalogPricingLogRepository.selectById(id);
|
| 32298 |
tejbeer |
255 |
|
|
|
256 |
if (status.equals(VendorCatalogPricingStatus.APPROVED)) {
|
| 32785 |
amit.gupta |
257 |
List<VendorCatalogPricingLog> vendorCatalogPricingLogsOnEffectedDate = vendorCatalogPricingLogRepository.selectByEffectedDateAndCatalogId(vendorCatalogPricingLog.getVendorId(), vendorCatalogPricingLog.getCatalogId(), vendorCatalogPricingLog.getEffectedOn());
|
| 32791 |
amit.gupta |
258 |
Optional<VendorCatalogPricingLog> optionalVendorCatalogPricingLog = vendorCatalogPricingLogsOnEffectedDate.stream().filter(x -> x.getStatus().equals(VendorCatalogPricingStatus.APPROVED)).findAny();
|
|
|
259 |
if (optionalVendorCatalogPricingLog.isPresent()) {
|
|
|
260 |
VendorCatalogPricingLog approvedPricingLog = optionalVendorCatalogPricingLog.get();
|
| 32786 |
amit.gupta |
261 |
approvedPricingLog.setStatus(VendorCatalogPricingStatus.REJECTED);
|
|
|
262 |
approvedPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
| 32298 |
tejbeer |
263 |
}
|
| 32785 |
amit.gupta |
264 |
|
| 32298 |
tejbeer |
265 |
}
|
| 32075 |
tejbeer |
266 |
vendorCatalogPricingLog.setStatus(status);
|
| 32086 |
tejbeer |
267 |
vendorCatalogPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
| 32075 |
tejbeer |
268 |
if (vendorCatalogPricingLog.getStatus().equals(VendorCatalogPricingStatus.APPROVED)) {
|
| 32086 |
tejbeer |
269 |
vendorCatalogPricingLog.setApprovedBy(authUser.getId());
|
|
|
270 |
vendorCatalogPricingLog.setApprovedTimestamp(LocalDateTime.now());
|
| 32075 |
tejbeer |
271 |
vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
275 |
return "response";
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
@RequestMapping(value = "/vendorPriceCircular", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
280 |
public String vendorPriceCircular() throws Exception {
|
| 32075 |
tejbeer |
281 |
return "vendor-price-circular";
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
@RequestMapping(value = "/getVendorPriceCircular", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
286 |
public String getVendorPriceCircular(@RequestParam(defaultValue = "0") int vendorId, @RequestParam LocalDate effectedDate, Model model) throws Exception {
|
| 32075 |
tejbeer |
287 |
|
| 32485 |
amit.gupta |
288 |
List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(vendorId, effectedDate);
|
| 33183 |
shampa |
289 |
Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 32075 |
tejbeer |
290 |
if (!vendorCatalogPricings.isEmpty()) {
|
|
|
291 |
Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
292 |
Map<Integer, List<Item>> itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
293 |
model.addAttribute("itemMap", itemMap);
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
model.addAttribute("vendorCatalogPricings", vendorCatalogPricings);
|
| 33183 |
shampa |
297 |
model.addAttribute("suppliers", supplierMap);
|
| 32075 |
tejbeer |
298 |
return "vendor-price-circular-view";
|
|
|
299 |
|
|
|
300 |
}
|
| 34047 |
tejus.loha |
301 |
|
| 33183 |
shampa |
302 |
@RequestMapping(value = "/downloadPriceCircularReport", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
303 |
public ResponseEntity<?> getSelectDownloadPriceCircularReport(@RequestParam(name = "startDate") LocalDate startDate) throws Exception {
|
| 32145 |
tejbeer |
304 |
|
| 33183 |
shampa |
305 |
List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(0, startDate);
|
|
|
306 |
Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
307 |
Map<Integer, List<Item>> itemMap = new HashMap<>();
|
|
|
308 |
List<List<?>> rows = new ArrayList<>();
|
|
|
309 |
if (!vendorCatalogPricings.isEmpty()) {
|
|
|
310 |
Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
311 |
itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
312 |
}
|
|
|
313 |
|
| 34047 |
tejus.loha |
314 |
for (VendorPriceCircularModel vcp : vendorCatalogPricings) {
|
| 36468 |
amit |
315 |
Supplier supplier = supplierMap.get(vcp.getVendorId());
|
|
|
316 |
List<Item> items = itemMap.get(vcp.getCatalogId());
|
|
|
317 |
if (supplier == null || supplier.isInternal() || items == null || items.isEmpty()) {
|
|
|
318 |
continue;
|
|
|
319 |
}
|
|
|
320 |
rows.add(Arrays.asList(vcp.getCatalogId(), supplier.getName(), items.get(0).getItemDescriptionNoColor(), vcp.getTransferPrice(), vcp.getDealerPrice(), vcp.getMop(),
|
| 33183 |
shampa |
321 |
FormattingUtils.formatDate(vcp.getEffectedOn())));
|
|
|
322 |
}
|
|
|
323 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
| 34047 |
tejus.loha |
324 |
.getCSVByteStream(Arrays.asList("Catalog Id", "Vendor Name", "Model name", "TP", "DP", "MOP",
|
| 33183 |
shampa |
325 |
"Effected On"), rows);
|
|
|
326 |
|
|
|
327 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price circular report");
|
|
|
328 |
|
|
|
329 |
return responseEntity;
|
|
|
330 |
|
|
|
331 |
}
|
|
|
332 |
|
| 34047 |
tejus.loha |
333 |
|
| 32145 |
tejbeer |
334 |
@RequestMapping(value = "/getPricing", method = RequestMethod.GET)
|
| 32488 |
amit.gupta |
335 |
public String getPricing(HttpServletRequest request, @RequestParam int vendorId, @RequestParam int itemId, @RequestParam LocalDate onDate, Model model) throws Exception {
|
| 34057 |
tejus.loha |
336 |
List<Integer> checkRequiredCategoryId = Arrays.asList(10006);
|
|
|
337 |
List<String> checkRequiredCategoryGroup = Arrays.asList("Handset");
|
| 32901 |
amit.gupta |
338 |
Item item = itemRepository.selectById(itemId);
|
| 34050 |
tejus.loha |
339 |
List<String> brandsIgnoreToCheckCategory = Arrays.asList("Dummy", "Live Demo");
|
|
|
340 |
if (!brandsIgnoreToCheckCategory.contains(item.getBrand())) {
|
|
|
341 |
if (checkRequiredCategoryId.contains(item.getCategoryId()) || checkRequiredCategoryGroup.contains(item.getProductGroup())) {
|
|
|
342 |
CategorisedCatalog categorisedCatalog = categorisedCatalogRepository.getCurrentCatalogMovement(item.getCatalogItemId());
|
|
|
343 |
if (categorisedCatalog == null || categorisedCatalog.getStatus().getValue().isEmpty()) {
|
|
|
344 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
|
|
345 |
return "response";
|
|
|
346 |
}
|
| 34047 |
tejus.loha |
347 |
}
|
|
|
348 |
}
|
| 32488 |
amit.gupta |
349 |
VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), onDate);
|
|
|
350 |
LOGGER.info("vendorCatalogPricing {}", vendorPriceCircularModel);
|
|
|
351 |
model.addAttribute("response1", mvcResponseSender.createResponseString(vendorPriceCircularModel));
|
| 32145 |
tejbeer |
352 |
return "response";
|
|
|
353 |
}
|
| 32194 |
tejbeer |
354 |
|
| 32903 |
amit.gupta |
355 |
private void addVendorPricingIfMissing(int itemId, int vendorId) throws ProfitMandiBusinessException {
|
| 32942 |
amit.gupta |
356 |
Supplier supplier = supplierRepository.selectById(vendorId);
|
| 32900 |
amit.gupta |
357 |
Item item = itemRepository.selectById(itemId);
|
| 32903 |
amit.gupta |
358 |
int vendorWithPricing = 0;
|
| 32970 |
amit.gupta |
359 |
if (supplier.isInternal() && (item.getBrand().equals("Samsung") || item.getCategoryId() != 10006)) {
|
| 32927 |
amit.gupta |
360 |
VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), LocalDate.now());
|
| 32903 |
amit.gupta |
361 |
LOGGER.info("VendorPriceCircularModel - {}", vendorPriceCircularModel);
|
|
|
362 |
if (vendorPriceCircularModel == null) {
|
| 32942 |
amit.gupta |
363 |
if (item.getBrand().equals("Samsung")) {
|
|
|
364 |
//BSB
|
|
|
365 |
vendorWithPricing = 334;
|
| 32970 |
amit.gupta |
366 |
} else if (item.getCategoryId() != 10006) {
|
|
|
367 |
vendorWithPricing = vendorCatalogPricingLogRepository.selectByCatalogId(item.getCatalogItemId(), VendorCatalogPricingStatus.APPROVED).stream().map(x -> x.getVendorId())
|
|
|
368 |
.findFirst().orElse(null);
|
| 32903 |
amit.gupta |
369 |
}
|
|
|
370 |
VendorPriceCircularModel existingPriceCircular = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorWithPricing, item.getCatalogItemId(), LocalDate.now());
|
|
|
371 |
LOGGER.info("Existing price circular - {}", existingPriceCircular);
|
|
|
372 |
if (existingPriceCircular == null) {
|
|
|
373 |
throw new ProfitMandiBusinessException("Pricing missing for vendor - " + vendorId, "Pricing missing for vendor - " + vendorId, "Pricing missing for vendor - " + vendorId);
|
|
|
374 |
}
|
|
|
375 |
VendorCatalogPricingModel vendorCatalogPricingModel = new VendorCatalogPricingModel();
|
|
|
376 |
vendorCatalogPricingModel.setAuthId(52);
|
|
|
377 |
vendorCatalogPricingModel.setVendorId(vendorId);
|
|
|
378 |
vendorCatalogPricingModel.setCatalogId(existingPriceCircular.getCatalogId());
|
|
|
379 |
vendorCatalogPricingModel.setDp(existingPriceCircular.getDealerPrice());
|
|
|
380 |
vendorCatalogPricingModel.setEffectedOn(existingPriceCircular.getEffectedOn());
|
|
|
381 |
vendorCatalogPricingModel.setMop(existingPriceCircular.getMop());
|
|
|
382 |
vendorCatalogPricingModel.setTp(existingPriceCircular.getTransferPrice());
|
|
|
383 |
vendorCatalogPricingModel.setCatalogId(item.getCatalogItemId());
|
|
|
384 |
|
|
|
385 |
VendorCatalogPricingLog vendorCatalogPricingLog = vendorCatalogPricingService.createVendorCatalogPricingLog(vendorCatalogPricingModel);
|
|
|
386 |
vendorCatalogPricingLog.setStatus(VendorCatalogPricingStatus.APPROVED);
|
|
|
387 |
vendorCatalogPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
388 |
//Deenanath Auth Id
|
|
|
389 |
vendorCatalogPricingLog.setApprovedBy(138);
|
|
|
390 |
vendorCatalogPricingLog.setApprovedTimestamp(LocalDateTime.now());
|
|
|
391 |
vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
|
|
|
392 |
|
| 32900 |
amit.gupta |
393 |
}
|
|
|
394 |
}
|
|
|
395 |
}
|
|
|
396 |
|
| 32194 |
tejbeer |
397 |
@RequestMapping(value = "/vendorItem", method = RequestMethod.GET)
|
| 34047 |
tejus.loha |
398 |
public String getItemPricing(Model model, @RequestParam int vendorId, @RequestParam String query) throws Exception {
|
| 32194 |
tejbeer |
399 |
String query1 = query.toLowerCase();
|
| 32900 |
amit.gupta |
400 |
int itemId = 0;
|
|
|
401 |
try {
|
|
|
402 |
itemId = Integer.parseInt(query1);
|
| 32903 |
amit.gupta |
403 |
addVendorPricingIfMissing(itemId, vendorId);
|
| 32924 |
amit.gupta |
404 |
} catch (NumberFormatException e) {
|
|
|
405 |
LOGGER.info("Ignore number format exception");
|
| 32942 |
amit.gupta |
406 |
// e.printStackTrace();
|
| 32898 |
amit.gupta |
407 |
}
|
| 32903 |
amit.gupta |
408 |
LOGGER.info("Vendor Id - {}", vendorId);
|
| 32194 |
tejbeer |
409 |
List<ItemDescriptionModel> partnersItemDescription = warehouseService.getAllPartnerItemStringDescription(vendorId).parallelStream().filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?")).collect(Collectors.toList());
|
|
|
410 |
LOGGER.info("partnersItemDescription" + partnersItemDescription);
|
|
|
411 |
|
|
|
412 |
model.addAttribute("response1", mvcResponseSender.createResponseString(partnersItemDescription));
|
|
|
413 |
return "response";
|
|
|
414 |
}
|
| 36464 |
amit |
415 |
|
|
|
416 |
@RequestMapping(value = "/downloadVendorPricingChangesReport", method = RequestMethod.GET)
|
|
|
417 |
public ResponseEntity<?> downloadVendorPricingChangesReport(
|
|
|
418 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
419 |
@RequestParam(name = "endDate") LocalDate endDate) throws Exception {
|
|
|
420 |
|
|
|
421 |
Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream()
|
|
|
422 |
.filter(s -> s.isStatus() && !s.isInternal())
|
|
|
423 |
.collect(Collectors.toMap(Supplier::getId, s -> s));
|
|
|
424 |
|
|
|
425 |
List<VendorPriceCircularModel> allBaseline = vendorCatalogPricingLogRepository.getVendorPricesOnDate(0, startDate);
|
|
|
426 |
Map<Integer, List<VendorPriceCircularModel>> baselineByVendor = allBaseline.stream()
|
|
|
427 |
.filter(p -> supplierMap.containsKey(p.getVendorId()))
|
|
|
428 |
.collect(Collectors.groupingBy(VendorPriceCircularModel::getVendorId));
|
|
|
429 |
|
|
|
430 |
List<VendorPriceCircularModel> allChanges = vendorCatalogPricingLogRepository.selectApprovedInDateRange(startDate, endDate);
|
|
|
431 |
Map<Integer, List<VendorPriceCircularModel>> changesByVendor = allChanges.stream()
|
|
|
432 |
.collect(Collectors.groupingBy(VendorPriceCircularModel::getVendorId));
|
|
|
433 |
|
|
|
434 |
Set<Integer> allCatalogIds = new HashSet<>();
|
|
|
435 |
allBaseline.stream().filter(p -> supplierMap.containsKey(p.getVendorId())).forEach(p -> allCatalogIds.add(p.getCatalogId()));
|
|
|
436 |
allChanges.forEach(p -> allCatalogIds.add(p.getCatalogId()));
|
|
|
437 |
|
|
|
438 |
Map<Integer, List<Item>> itemMap = new HashMap<>();
|
|
|
439 |
if (!allCatalogIds.isEmpty()) {
|
|
|
440 |
itemMap = itemRepository.selectAllByCatalogIds(allCatalogIds).stream()
|
|
|
441 |
.collect(Collectors.groupingBy(Item::getCatalogItemId));
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
ByteArrayOutputStream bos = buildVendorPricingChangesExcel(supplierMap, baselineByVendor, changesByVendor, itemMap);
|
|
|
445 |
|
|
|
446 |
HttpHeaders headers = new HttpHeaders();
|
|
|
447 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
448 |
headers.set("Content-disposition", "attachment; filename=vendor-pricing-changes-" + startDate + "-to-" + endDate + ".xlsx");
|
|
|
449 |
headers.setContentLength(bos.toByteArray().length);
|
|
|
450 |
|
|
|
451 |
InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(bos.toByteArray()));
|
|
|
452 |
return new ResponseEntity<>(resource, headers, org.springframework.http.HttpStatus.OK);
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
private ByteArrayOutputStream buildVendorPricingChangesExcel(
|
|
|
456 |
Map<Integer, Supplier> supplierMap,
|
|
|
457 |
Map<Integer, List<VendorPriceCircularModel>> baselineByVendor,
|
|
|
458 |
Map<Integer, List<VendorPriceCircularModel>> changesByVendor,
|
|
|
459 |
Map<Integer, List<Item>> itemMap) throws Exception {
|
|
|
460 |
|
|
|
461 |
XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
462 |
XSSFSheet sheet = workbook.createSheet("Pricing Changes");
|
|
|
463 |
|
|
|
464 |
CellStyle headerStyle = workbook.createCellStyle();
|
|
|
465 |
Font boldFont = workbook.createFont();
|
|
|
466 |
boldFont.setBold(true);
|
|
|
467 |
headerStyle.setFont(boldFont);
|
|
|
468 |
|
|
|
469 |
int rowNum = 0;
|
|
|
470 |
|
|
|
471 |
XSSFRow colRow = sheet.createRow(rowNum++);
|
|
|
472 |
String[] columns = {"Vendor", "Effective Date", "Model", "Catalog Id", "TP", "DP", "MOP"};
|
|
|
473 |
for (int i = 0; i < columns.length; i++) {
|
|
|
474 |
colRow.createCell(i).setCellValue(columns[i]);
|
|
|
475 |
colRow.getCell(i).setCellStyle(headerStyle);
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
List<Map.Entry<Integer, Supplier>> sortedVendors = supplierMap.entrySet().stream()
|
|
|
479 |
.sorted(Comparator.comparing(e -> e.getValue().getName()))
|
|
|
480 |
.collect(Collectors.toList());
|
|
|
481 |
|
|
|
482 |
for (Map.Entry<Integer, Supplier> vendorEntry : sortedVendors) {
|
|
|
483 |
int vendorId = vendorEntry.getKey();
|
|
|
484 |
String vendorName = vendorEntry.getValue().getName();
|
|
|
485 |
|
|
|
486 |
List<VendorPriceCircularModel> baseline = baselineByVendor.getOrDefault(vendorId, Collections.emptyList());
|
|
|
487 |
List<VendorPriceCircularModel> changes = changesByVendor.getOrDefault(vendorId, Collections.emptyList());
|
|
|
488 |
|
|
|
489 |
if (baseline.isEmpty() && changes.isEmpty()) {
|
|
|
490 |
continue;
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
Map<Integer, Float> tpTracker = new HashMap<>();
|
|
|
494 |
|
|
|
495 |
for (VendorPriceCircularModel bp : baseline) {
|
|
|
496 |
XSSFRow dataRow = sheet.createRow(rowNum++);
|
|
|
497 |
dataRow.createCell(0).setCellValue(vendorName);
|
|
|
498 |
dataRow.createCell(1).setCellValue(FormattingUtils.formatDate(bp.getEffectedOn()));
|
|
|
499 |
dataRow.createCell(2).setCellValue(getModelName(itemMap, bp.getCatalogId()));
|
|
|
500 |
dataRow.createCell(3).setCellValue(bp.getCatalogId());
|
|
|
501 |
dataRow.createCell(4).setCellValue(bp.getTransferPrice());
|
|
|
502 |
dataRow.createCell(5).setCellValue(bp.getDealerPrice());
|
|
|
503 |
dataRow.createCell(6).setCellValue(bp.getMop());
|
|
|
504 |
tpTracker.put(bp.getCatalogId(), bp.getTransferPrice());
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
for (VendorPriceCircularModel cp : changes) {
|
|
|
508 |
Float lastTp = tpTracker.get(cp.getCatalogId());
|
|
|
509 |
if (lastTp == null || Float.compare(lastTp, cp.getTransferPrice()) != 0) {
|
|
|
510 |
XSSFRow dataRow = sheet.createRow(rowNum++);
|
|
|
511 |
dataRow.createCell(0).setCellValue(vendorName);
|
|
|
512 |
dataRow.createCell(1).setCellValue(FormattingUtils.formatDate(cp.getEffectedOn()));
|
|
|
513 |
dataRow.createCell(2).setCellValue(getModelName(itemMap, cp.getCatalogId()));
|
|
|
514 |
dataRow.createCell(3).setCellValue(cp.getCatalogId());
|
|
|
515 |
dataRow.createCell(4).setCellValue(cp.getTransferPrice());
|
|
|
516 |
dataRow.createCell(5).setCellValue(cp.getDealerPrice());
|
|
|
517 |
dataRow.createCell(6).setCellValue(cp.getMop());
|
|
|
518 |
tpTracker.put(cp.getCatalogId(), cp.getTransferPrice());
|
|
|
519 |
}
|
|
|
520 |
}
|
|
|
521 |
}
|
|
|
522 |
|
|
|
523 |
for (int i = 0; i < 7; i++) {
|
|
|
524 |
sheet.autoSizeColumn(i);
|
|
|
525 |
}
|
|
|
526 |
|
|
|
527 |
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
528 |
workbook.write(bos);
|
|
|
529 |
workbook.close();
|
|
|
530 |
return bos;
|
|
|
531 |
}
|
|
|
532 |
|
|
|
533 |
private String getModelName(Map<Integer, List<Item>> itemMap, int catalogId) {
|
|
|
534 |
List<Item> items = itemMap.get(catalogId);
|
|
|
535 |
if (items != null && !items.isEmpty()) {
|
|
|
536 |
return items.get(0).getItemDescriptionNoColor();
|
|
|
537 |
}
|
|
|
538 |
return "Unknown (" + catalogId + ")";
|
|
|
539 |
}
|
| 32075 |
tejbeer |
540 |
}
|