| 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;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.inventory.Vendor;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricing;
|
|
|
11 |
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricingLog;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
|
|
|
13 |
import com.spice.profitmandi.dao.enumuration.inventory.VendorCatalogPricingStatus;
|
|
|
14 |
import com.spice.profitmandi.dao.model.VendorCatalogPricingModel;
|
| 32163 |
tejbeer |
15 |
import com.spice.profitmandi.dao.model.VendorPriceCircularModel;
|
| 32075 |
tejbeer |
16 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingLogRepository;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingRepository;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.inventory.VendorRepository;
|
| 33183 |
shampa |
21 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 32075 |
tejbeer |
22 |
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
|
| 33183 |
shampa |
23 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 32075 |
tejbeer |
24 |
import com.spice.profitmandi.service.inventory.VendorCatalogPricingService;
|
| 33183 |
shampa |
25 |
import com.spice.profitmandi.service.order.OrderService;
|
| 32194 |
tejbeer |
26 |
import com.spice.profitmandi.service.warehouse.WarehouseService;
|
| 32075 |
tejbeer |
27 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
28 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
29 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 32383 |
amit.gupta |
30 |
import org.apache.logging.log4j.LogManager;
|
|
|
31 |
import org.apache.logging.log4j.Logger;
|
|
|
32 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 33465 |
ranu |
33 |
import org.springframework.core.io.ClassPathResource;
|
|
|
34 |
import org.springframework.core.io.InputStreamResource;
|
|
|
35 |
import org.springframework.http.HttpHeaders;
|
|
|
36 |
import org.springframework.http.MediaType;
|
| 33183 |
shampa |
37 |
import org.springframework.http.ResponseEntity;
|
| 32383 |
amit.gupta |
38 |
import org.springframework.stereotype.Controller;
|
|
|
39 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
40 |
import org.springframework.ui.Model;
|
| 33465 |
ranu |
41 |
import org.springframework.web.bind.annotation.*;
|
|
|
42 |
import org.springframework.web.multipart.MultipartFile;
|
| 32075 |
tejbeer |
43 |
|
| 33465 |
ranu |
44 |
import javax.mail.MessagingException;
|
| 32383 |
amit.gupta |
45 |
import javax.servlet.http.HttpServletRequest;
|
| 33465 |
ranu |
46 |
import java.io.IOException;
|
| 32383 |
amit.gupta |
47 |
import java.time.LocalDate;
|
|
|
48 |
import java.time.LocalDateTime;
|
|
|
49 |
import java.util.*;
|
|
|
50 |
import java.util.stream.Collectors;
|
|
|
51 |
|
| 32075 |
tejbeer |
52 |
@Controller
|
|
|
53 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
54 |
public class VendorController {
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
VendorRepository vendorRepository;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
private CookiesProcessor cookiesProcessor;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
| 33183 |
shampa |
64 |
private RoleManager roleManager;
|
|
|
65 |
|
|
|
66 |
@Autowired
|
| 32075 |
tejbeer |
67 |
private AuthRepository authRepository;
|
|
|
68 |
|
|
|
69 |
@Autowired
|
| 33183 |
shampa |
70 |
private OrderRepository orderRepository;
|
|
|
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
private OrderService orderService;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
| 32075 |
tejbeer |
76 |
private VendorCatalogPricingService vendorCatalogPricingService;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private VendorCatalogPricingLogRepository vendorCatalogPricingLogRepository;
|
|
|
80 |
|
|
|
81 |
@Autowired
|
|
|
82 |
private VendorCatalogPricingRepository vendorCatalogPricingRepository;
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
@Autowired
|
|
|
86 |
private MVCResponseSender mvcResponseSender;
|
|
|
87 |
|
|
|
88 |
@Autowired
|
|
|
89 |
private ItemRepository itemRepository;
|
|
|
90 |
|
|
|
91 |
@Autowired
|
|
|
92 |
private SupplierRepository supplierRepository;
|
|
|
93 |
|
| 32194 |
tejbeer |
94 |
@Autowired
|
|
|
95 |
private WarehouseService warehouseService;
|
|
|
96 |
|
| 32075 |
tejbeer |
97 |
private static final Logger LOGGER = LogManager.getLogger(VendorController.class);
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
@RequestMapping(value = "/vendorCatalogPricing", method = RequestMethod.GET)
|
|
|
101 |
public String vendorCatalogPricing(HttpServletRequest request, Model model) throws Exception {
|
|
|
102 |
|
|
|
103 |
return "vendor-catalog-pricing";
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
@RequestMapping(value = "/getVendorCatalogPricingByModel", method = RequestMethod.GET)
|
|
|
108 |
public String getVendorCatalogPricingByModel(HttpServletRequest request, @RequestParam int catalogId, Model model) throws Exception {
|
|
|
109 |
|
|
|
110 |
List<Integer> vendorIds = new ArrayList<>();
|
|
|
111 |
Map<Integer, VendorCatalogPricing> vendorCatalogPricingMap = new HashMap<>();
|
|
|
112 |
Map<Integer, VendorCatalogPricingLog> vendorCatalogPricingLogMap = new HashMap<>();
|
|
|
113 |
List<VendorCatalogPricing> vendorCatalogPricing = vendorCatalogPricingRepository.selectByCatalogId(catalogId);
|
|
|
114 |
if (!vendorCatalogPricing.isEmpty()) {
|
|
|
115 |
vendorIds.addAll(vendorCatalogPricing.stream().distinct().map(x -> x.getVendorId()).collect(Collectors.toList()));
|
|
|
116 |
vendorCatalogPricingMap = vendorCatalogPricing.stream().collect(Collectors.toMap(x -> x.getVendorId(), x -> x));
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
List<VendorCatalogPricingLog> vendorCatalogPricingLog = vendorCatalogPricingLogRepository.selectByCatalogId(catalogId, VendorCatalogPricingStatus.PENDING);
|
|
|
120 |
if (!vendorCatalogPricingLog.isEmpty()) {
|
|
|
121 |
vendorIds.addAll(vendorCatalogPricingLog.stream().distinct().map(x -> x.getVendorId()).collect(Collectors.toList()));
|
|
|
122 |
vendorCatalogPricingLogMap = vendorCatalogPricingLog.stream().filter(x -> x.getStatus().equals(VendorCatalogPricingStatus.PENDING)).collect(Collectors.toMap(x -> x.getVendorId(), x -> x));
|
|
|
123 |
}
|
|
|
124 |
LOGGER.info("VendorIds {}", vendorIds);
|
|
|
125 |
List<Supplier> suppliers = new ArrayList<Supplier>();
|
|
|
126 |
if (!vendorIds.isEmpty()) {
|
|
|
127 |
suppliers.addAll(supplierRepository.selectBySupplierIds(vendorIds));
|
|
|
128 |
}
|
|
|
129 |
LOGGER.info("suppliers {}", suppliers);
|
|
|
130 |
|
|
|
131 |
model.addAttribute("suppliers", suppliers);
|
|
|
132 |
model.addAttribute("vendorCatalogPricingMap", vendorCatalogPricingMap);
|
|
|
133 |
model.addAttribute("vendorCatalogPricingLogMap", vendorCatalogPricingLogMap);
|
|
|
134 |
|
|
|
135 |
model.addAttribute("catalogId", catalogId);
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
return "vendor-catalog-pricing-view";
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
@RequestMapping(value = "/vendors", method = RequestMethod.GET)
|
|
|
143 |
public String getVendor(HttpServletRequest request, Model model, @RequestParam String query) throws Throwable {
|
| 32398 |
amit.gupta |
144 |
List<Supplier> vendors = supplierRepository.selectAll().stream().filter(x -> x.getName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?"))
|
|
|
145 |
.filter(x -> x.isStatus()).collect(Collectors.toList());
|
| 32075 |
tejbeer |
146 |
model.addAttribute("response1", mvcResponseSender.createResponseString(vendors));
|
|
|
147 |
return "response";
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
@RequestMapping(value = "/createVendorCatalogPricing", method = RequestMethod.POST)
|
|
|
152 |
public String createVendorCatalogPricing(HttpServletRequest request, @RequestBody VendorCatalogPricingModel vendorCatalogPricingModel, Model model) throws Exception {
|
|
|
153 |
|
|
|
154 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
155 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
156 |
vendorCatalogPricingModel.setAuthId(authUser.getId());
|
|
|
157 |
|
|
|
158 |
LOGGER.info("vendorCatalogPricingModel {}", vendorCatalogPricingModel);
|
|
|
159 |
|
|
|
160 |
vendorCatalogPricingService.createVendorCatalogPricingLog(vendorCatalogPricingModel);
|
|
|
161 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
162 |
return "response";
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
|
| 33465 |
ranu |
166 |
@RequestMapping(value = "/createBulkPricing")
|
|
|
167 |
public String createBulkPricing(HttpServletRequest request, Model model) throws ProfitMandiBusinessException, MessagingException, IOException {
|
|
|
168 |
return "bulk-vendor-pricing";
|
|
|
169 |
}
|
| 32075 |
tejbeer |
170 |
|
| 33465 |
ranu |
171 |
@PostMapping(value = "/bulkVendorCatalogPricing/upload")
|
|
|
172 |
public String uploadCatalog(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model)
|
|
|
173 |
throws Exception {
|
|
|
174 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
175 |
int authId = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId()).getId();
|
|
|
176 |
LOGGER.info("authId - {}", authId);
|
|
|
177 |
vendorCatalogPricingService.parseBulkVendorCatalogPricing(file, authId);
|
|
|
178 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
179 |
return "response";
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
@GetMapping("/bulkVendorCatalogPricing/downloadReferenceFile")
|
| 33467 |
ranu |
183 |
public ResponseEntity<?> downloadReferenceFile() throws IOException {
|
| 33465 |
ranu |
184 |
ClassPathResource dummyFile = new ClassPathResource("vendor-catalog-pricing-file.xlsx"); // Make sure the file is in the resources folder
|
|
|
185 |
return ResponseEntity.ok()
|
|
|
186 |
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=dummy-file.xlsx")
|
|
|
187 |
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
188 |
.body(new InputStreamResource(dummyFile.getInputStream()));
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
|
| 32075 |
tejbeer |
192 |
@RequestMapping(value = "/vendorCatalogPricingRequests", method = RequestMethod.GET)
|
|
|
193 |
public String vendorCatalogPricingRequests(HttpServletRequest request, Model model) throws Exception {
|
|
|
194 |
List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByStatus(VendorCatalogPricingStatus.PENDING);
|
|
|
195 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
196 |
model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
|
|
|
197 |
if (!vendorCatalogPricingRequests.isEmpty()) {
|
|
|
198 |
Set<Integer> catalogIds = vendorCatalogPricingRequests.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
199 |
List<Integer> vendorIds = vendorCatalogPricingRequests.stream().map(x -> x.getVendorId()).collect(Collectors.toList());
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
Map<Integer, List<Item>> itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
203 |
model.addAttribute("itemMap", itemMap);
|
|
|
204 |
}
|
|
|
205 |
Map<Integer, Vendor> vendorMap = vendorRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
206 |
model.addAttribute("authMap", authUserMap);
|
|
|
207 |
model.addAttribute("vendorMap", vendorMap);
|
|
|
208 |
model.addAttribute("vendorPricingStatus", VendorCatalogPricingStatus.values());
|
|
|
209 |
|
|
|
210 |
return "vendor-catalog-pricing-request";
|
|
|
211 |
}
|
|
|
212 |
|
| 33750 |
ranu |
213 |
@RequestMapping(value = "/vendorCatalogPricingPendingRequests", method = RequestMethod.GET)
|
|
|
214 |
public String vendorCatalogPricingPendingRequests(HttpServletRequest request, Model model) throws Exception {
|
|
|
215 |
return "vendor-catalog-pricing-pending-request";
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
@RequestMapping(value = "/datewiseVendorCatalogPricingPendingRequests", method = RequestMethod.GET)
|
|
|
219 |
public String datewiseVendorCatalogPricingPendingRequests(HttpServletRequest request, @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
|
|
|
220 |
List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByDate(startDate, endDate);
|
|
|
221 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
222 |
LOGGER.info("vendorCatalogPricingRequests {}", vendorCatalogPricingRequests);
|
|
|
223 |
model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
|
|
|
224 |
if (!vendorCatalogPricingRequests.isEmpty()) {
|
|
|
225 |
Set<Integer> catalogIds = vendorCatalogPricingRequests.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
226 |
Map<Integer, List<Item>> itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
227 |
model.addAttribute("itemMap", itemMap);
|
|
|
228 |
}
|
|
|
229 |
Map<Integer, Vendor> vendorMap = vendorRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
230 |
model.addAttribute("authMap", authUserMap);
|
|
|
231 |
model.addAttribute("vendorMap", vendorMap);
|
|
|
232 |
model.addAttribute("vendorPricingStatus", VendorCatalogPricingStatus.values());
|
|
|
233 |
|
|
|
234 |
return "vendor-catalog-pricing-pending-request-table";
|
|
|
235 |
}
|
|
|
236 |
|
| 32075 |
tejbeer |
237 |
@RequestMapping(value = "/verifyVendorCatalogPricingRequest", method = RequestMethod.POST)
|
|
|
238 |
public String verifyVendorCatalogPricingRequest(HttpServletRequest request, @RequestParam int id, @RequestParam VendorCatalogPricingStatus status, Model model) throws Exception {
|
| 32086 |
tejbeer |
239 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
240 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 32075 |
tejbeer |
241 |
|
|
|
242 |
VendorCatalogPricingLog vendorCatalogPricingLog = vendorCatalogPricingLogRepository.selectById(id);
|
| 32298 |
tejbeer |
243 |
|
|
|
244 |
if (status.equals(VendorCatalogPricingStatus.APPROVED)) {
|
| 32785 |
amit.gupta |
245 |
List<VendorCatalogPricingLog> vendorCatalogPricingLogsOnEffectedDate = vendorCatalogPricingLogRepository.selectByEffectedDateAndCatalogId(vendorCatalogPricingLog.getVendorId(), vendorCatalogPricingLog.getCatalogId(), vendorCatalogPricingLog.getEffectedOn());
|
| 32791 |
amit.gupta |
246 |
Optional<VendorCatalogPricingLog> optionalVendorCatalogPricingLog = vendorCatalogPricingLogsOnEffectedDate.stream().filter(x -> x.getStatus().equals(VendorCatalogPricingStatus.APPROVED)).findAny();
|
|
|
247 |
if (optionalVendorCatalogPricingLog.isPresent()) {
|
|
|
248 |
VendorCatalogPricingLog approvedPricingLog = optionalVendorCatalogPricingLog.get();
|
| 32786 |
amit.gupta |
249 |
approvedPricingLog.setStatus(VendorCatalogPricingStatus.REJECTED);
|
|
|
250 |
approvedPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
| 32298 |
tejbeer |
251 |
}
|
| 32785 |
amit.gupta |
252 |
|
| 32298 |
tejbeer |
253 |
}
|
| 32075 |
tejbeer |
254 |
vendorCatalogPricingLog.setStatus(status);
|
| 32086 |
tejbeer |
255 |
vendorCatalogPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
| 32075 |
tejbeer |
256 |
if (vendorCatalogPricingLog.getStatus().equals(VendorCatalogPricingStatus.APPROVED)) {
|
| 32086 |
tejbeer |
257 |
vendorCatalogPricingLog.setApprovedBy(authUser.getId());
|
|
|
258 |
vendorCatalogPricingLog.setApprovedTimestamp(LocalDateTime.now());
|
| 32075 |
tejbeer |
259 |
vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
263 |
return "response";
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
@RequestMapping(value = "/vendorPriceCircular", method = RequestMethod.GET)
|
|
|
268 |
public String vendorPriceCircular(HttpServletRequest request, Model model) throws Exception {
|
|
|
269 |
|
|
|
270 |
|
|
|
271 |
return "vendor-price-circular";
|
|
|
272 |
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
@RequestMapping(value = "/getVendorPriceCircular", method = RequestMethod.GET)
|
| 33183 |
shampa |
277 |
public String getVendorPriceCircular(HttpServletRequest request, @RequestParam(defaultValue = "0") int vendorId, @RequestParam LocalDate effectedDate, Model model) throws Exception {
|
| 32075 |
tejbeer |
278 |
|
| 32485 |
amit.gupta |
279 |
List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(vendorId, effectedDate);
|
| 33183 |
shampa |
280 |
Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 32075 |
tejbeer |
281 |
if (!vendorCatalogPricings.isEmpty()) {
|
|
|
282 |
Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
283 |
Map<Integer, List<Item>> itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
284 |
model.addAttribute("itemMap", itemMap);
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
model.addAttribute("vendorCatalogPricings", vendorCatalogPricings);
|
| 33183 |
shampa |
288 |
model.addAttribute("suppliers", supplierMap);
|
| 32075 |
tejbeer |
289 |
return "vendor-price-circular-view";
|
|
|
290 |
|
|
|
291 |
}
|
| 33183 |
shampa |
292 |
@RequestMapping(value = "/downloadPriceCircularReport", method = RequestMethod.GET)
|
|
|
293 |
public ResponseEntity<?> getSelectDownloadPriceCircularReport(HttpServletRequest request,
|
|
|
294 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
295 |
@RequestParam(name = "startDate") LocalDate startDate) throws Exception {
|
| 32145 |
tejbeer |
296 |
|
| 33183 |
shampa |
297 |
List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(0, startDate);
|
|
|
298 |
Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
299 |
Map<Integer, List<Item>> itemMap = new HashMap<>();
|
|
|
300 |
List<List<?>> rows = new ArrayList<>();
|
|
|
301 |
if (!vendorCatalogPricings.isEmpty()) {
|
|
|
302 |
Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
303 |
itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
for(VendorPriceCircularModel vcp: vendorCatalogPricings) {
|
|
|
308 |
|
|
|
309 |
rows.add(Arrays.asList(vcp.getCatalogId(),supplierMap.get(vcp.getVendorId()).getName(),itemMap.get(vcp.getCatalogId()).get(0).getItemDescriptionNoColor(),vcp.getTransferPrice(),vcp.getDealerPrice(),vcp.getMop(),
|
|
|
310 |
FormattingUtils.formatDate(vcp.getEffectedOn())));
|
|
|
311 |
|
|
|
312 |
}
|
|
|
313 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
314 |
.getCSVByteStream(Arrays.asList("Catalog Id","Vendor Name", "Model name", "TP", "DP", "MOP",
|
|
|
315 |
"Effected On"), rows);
|
|
|
316 |
|
|
|
317 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price circular report");
|
|
|
318 |
|
|
|
319 |
return responseEntity;
|
|
|
320 |
|
|
|
321 |
}
|
|
|
322 |
|
| 32145 |
tejbeer |
323 |
@RequestMapping(value = "/getPricing", method = RequestMethod.GET)
|
| 32488 |
amit.gupta |
324 |
public String getPricing(HttpServletRequest request, @RequestParam int vendorId, @RequestParam int itemId, @RequestParam LocalDate onDate, Model model) throws Exception {
|
| 32901 |
amit.gupta |
325 |
Item item = itemRepository.selectById(itemId);
|
| 32488 |
amit.gupta |
326 |
VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), onDate);
|
| 32145 |
tejbeer |
327 |
|
| 32488 |
amit.gupta |
328 |
LOGGER.info("vendorCatalogPricing {}", vendorPriceCircularModel);
|
| 32145 |
tejbeer |
329 |
|
| 32488 |
amit.gupta |
330 |
model.addAttribute("response1", mvcResponseSender.createResponseString(vendorPriceCircularModel));
|
| 32145 |
tejbeer |
331 |
|
|
|
332 |
return "response";
|
|
|
333 |
|
|
|
334 |
}
|
| 32194 |
tejbeer |
335 |
|
| 32903 |
amit.gupta |
336 |
private void addVendorPricingIfMissing(int itemId, int vendorId) throws ProfitMandiBusinessException {
|
| 32942 |
amit.gupta |
337 |
Supplier supplier = supplierRepository.selectById(vendorId);
|
| 32900 |
amit.gupta |
338 |
Item item = itemRepository.selectById(itemId);
|
| 32903 |
amit.gupta |
339 |
int vendorWithPricing = 0;
|
| 32970 |
amit.gupta |
340 |
if (supplier.isInternal() && (item.getBrand().equals("Samsung") || item.getCategoryId() != 10006)) {
|
| 32927 |
amit.gupta |
341 |
VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), LocalDate.now());
|
| 32903 |
amit.gupta |
342 |
LOGGER.info("VendorPriceCircularModel - {}", vendorPriceCircularModel);
|
|
|
343 |
if (vendorPriceCircularModel == null) {
|
| 32942 |
amit.gupta |
344 |
if (item.getBrand().equals("Samsung")) {
|
|
|
345 |
//BSB
|
|
|
346 |
vendorWithPricing = 334;
|
| 32970 |
amit.gupta |
347 |
} else if (item.getCategoryId() != 10006) {
|
|
|
348 |
vendorWithPricing = vendorCatalogPricingLogRepository.selectByCatalogId(item.getCatalogItemId(), VendorCatalogPricingStatus.APPROVED).stream().map(x -> x.getVendorId())
|
|
|
349 |
.findFirst().orElse(null);
|
| 32903 |
amit.gupta |
350 |
}
|
|
|
351 |
VendorPriceCircularModel existingPriceCircular = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorWithPricing, item.getCatalogItemId(), LocalDate.now());
|
|
|
352 |
LOGGER.info("Existing price circular - {}", existingPriceCircular);
|
|
|
353 |
if (existingPriceCircular == null) {
|
|
|
354 |
throw new ProfitMandiBusinessException("Pricing missing for vendor - " + vendorId, "Pricing missing for vendor - " + vendorId, "Pricing missing for vendor - " + vendorId);
|
|
|
355 |
}
|
|
|
356 |
VendorCatalogPricingModel vendorCatalogPricingModel = new VendorCatalogPricingModel();
|
|
|
357 |
vendorCatalogPricingModel.setAuthId(52);
|
|
|
358 |
vendorCatalogPricingModel.setVendorId(vendorId);
|
|
|
359 |
vendorCatalogPricingModel.setCatalogId(existingPriceCircular.getCatalogId());
|
|
|
360 |
vendorCatalogPricingModel.setDp(existingPriceCircular.getDealerPrice());
|
|
|
361 |
vendorCatalogPricingModel.setEffectedOn(existingPriceCircular.getEffectedOn());
|
|
|
362 |
vendorCatalogPricingModel.setMop(existingPriceCircular.getMop());
|
|
|
363 |
vendorCatalogPricingModel.setTp(existingPriceCircular.getTransferPrice());
|
|
|
364 |
vendorCatalogPricingModel.setCatalogId(item.getCatalogItemId());
|
|
|
365 |
|
|
|
366 |
VendorCatalogPricingLog vendorCatalogPricingLog = vendorCatalogPricingService.createVendorCatalogPricingLog(vendorCatalogPricingModel);
|
|
|
367 |
vendorCatalogPricingLog.setStatus(VendorCatalogPricingStatus.APPROVED);
|
|
|
368 |
vendorCatalogPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
369 |
//Deenanath Auth Id
|
|
|
370 |
vendorCatalogPricingLog.setApprovedBy(138);
|
|
|
371 |
vendorCatalogPricingLog.setApprovedTimestamp(LocalDateTime.now());
|
|
|
372 |
vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
|
|
|
373 |
|
| 32900 |
amit.gupta |
374 |
}
|
|
|
375 |
}
|
|
|
376 |
}
|
|
|
377 |
|
| 32194 |
tejbeer |
378 |
@RequestMapping(value = "/vendorItem", method = RequestMethod.GET)
|
| 32900 |
amit.gupta |
379 |
public String getItemPricing(HttpServletRequest request, Model model, @RequestParam int vendorId,
|
| 32924 |
amit.gupta |
380 |
@RequestParam String query) throws Exception {
|
| 32194 |
tejbeer |
381 |
String query1 = query.toLowerCase();
|
| 32900 |
amit.gupta |
382 |
int itemId = 0;
|
|
|
383 |
try {
|
|
|
384 |
itemId = Integer.parseInt(query1);
|
| 32903 |
amit.gupta |
385 |
addVendorPricingIfMissing(itemId, vendorId);
|
| 32924 |
amit.gupta |
386 |
} catch (NumberFormatException e) {
|
|
|
387 |
LOGGER.info("Ignore number format exception");
|
| 32942 |
amit.gupta |
388 |
// e.printStackTrace();
|
| 32898 |
amit.gupta |
389 |
}
|
| 32903 |
amit.gupta |
390 |
LOGGER.info("Vendor Id - {}", vendorId);
|
| 32194 |
tejbeer |
391 |
List<ItemDescriptionModel> partnersItemDescription = warehouseService.getAllPartnerItemStringDescription(vendorId).parallelStream().filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?")).collect(Collectors.toList());
|
|
|
392 |
LOGGER.info("partnersItemDescription" + partnersItemDescription);
|
|
|
393 |
|
|
|
394 |
model.addAttribute("response1", mvcResponseSender.createResponseString(partnersItemDescription));
|
|
|
395 |
return "response";
|
|
|
396 |
}
|
| 32075 |
tejbeer |
397 |
}
|