| 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")
|
|
|
183 |
public ResponseEntity<?> downloadDummyFile() throws IOException {
|
|
|
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 |
|
|
|
213 |
@RequestMapping(value = "/verifyVendorCatalogPricingRequest", method = RequestMethod.POST)
|
|
|
214 |
public String verifyVendorCatalogPricingRequest(HttpServletRequest request, @RequestParam int id, @RequestParam VendorCatalogPricingStatus status, Model model) throws Exception {
|
| 32086 |
tejbeer |
215 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
216 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 32075 |
tejbeer |
217 |
|
|
|
218 |
VendorCatalogPricingLog vendorCatalogPricingLog = vendorCatalogPricingLogRepository.selectById(id);
|
| 32298 |
tejbeer |
219 |
|
|
|
220 |
if (status.equals(VendorCatalogPricingStatus.APPROVED)) {
|
| 32785 |
amit.gupta |
221 |
List<VendorCatalogPricingLog> vendorCatalogPricingLogsOnEffectedDate = vendorCatalogPricingLogRepository.selectByEffectedDateAndCatalogId(vendorCatalogPricingLog.getVendorId(), vendorCatalogPricingLog.getCatalogId(), vendorCatalogPricingLog.getEffectedOn());
|
| 32791 |
amit.gupta |
222 |
Optional<VendorCatalogPricingLog> optionalVendorCatalogPricingLog = vendorCatalogPricingLogsOnEffectedDate.stream().filter(x -> x.getStatus().equals(VendorCatalogPricingStatus.APPROVED)).findAny();
|
|
|
223 |
if (optionalVendorCatalogPricingLog.isPresent()) {
|
|
|
224 |
VendorCatalogPricingLog approvedPricingLog = optionalVendorCatalogPricingLog.get();
|
| 32786 |
amit.gupta |
225 |
approvedPricingLog.setStatus(VendorCatalogPricingStatus.REJECTED);
|
|
|
226 |
approvedPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
| 32298 |
tejbeer |
227 |
}
|
| 32785 |
amit.gupta |
228 |
|
| 32298 |
tejbeer |
229 |
}
|
| 32075 |
tejbeer |
230 |
vendorCatalogPricingLog.setStatus(status);
|
| 32086 |
tejbeer |
231 |
vendorCatalogPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
| 32075 |
tejbeer |
232 |
if (vendorCatalogPricingLog.getStatus().equals(VendorCatalogPricingStatus.APPROVED)) {
|
| 32086 |
tejbeer |
233 |
vendorCatalogPricingLog.setApprovedBy(authUser.getId());
|
|
|
234 |
vendorCatalogPricingLog.setApprovedTimestamp(LocalDateTime.now());
|
| 32075 |
tejbeer |
235 |
vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
239 |
return "response";
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
@RequestMapping(value = "/vendorPriceCircular", method = RequestMethod.GET)
|
|
|
244 |
public String vendorPriceCircular(HttpServletRequest request, Model model) throws Exception {
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
return "vendor-price-circular";
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
@RequestMapping(value = "/getVendorPriceCircular", method = RequestMethod.GET)
|
| 33183 |
shampa |
253 |
public String getVendorPriceCircular(HttpServletRequest request, @RequestParam(defaultValue = "0") int vendorId, @RequestParam LocalDate effectedDate, Model model) throws Exception {
|
| 32075 |
tejbeer |
254 |
|
| 32485 |
amit.gupta |
255 |
List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(vendorId, effectedDate);
|
| 33183 |
shampa |
256 |
Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 32075 |
tejbeer |
257 |
if (!vendorCatalogPricings.isEmpty()) {
|
|
|
258 |
Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
259 |
Map<Integer, List<Item>> itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
260 |
model.addAttribute("itemMap", itemMap);
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
model.addAttribute("vendorCatalogPricings", vendorCatalogPricings);
|
| 33183 |
shampa |
264 |
model.addAttribute("suppliers", supplierMap);
|
| 32075 |
tejbeer |
265 |
return "vendor-price-circular-view";
|
|
|
266 |
|
|
|
267 |
}
|
| 33183 |
shampa |
268 |
@RequestMapping(value = "/downloadPriceCircularReport", method = RequestMethod.GET)
|
|
|
269 |
public ResponseEntity<?> getSelectDownloadPriceCircularReport(HttpServletRequest request,
|
|
|
270 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
271 |
@RequestParam(name = "startDate") LocalDate startDate) throws Exception {
|
| 32145 |
tejbeer |
272 |
|
| 33183 |
shampa |
273 |
List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(0, startDate);
|
|
|
274 |
Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
275 |
Map<Integer, List<Item>> itemMap = new HashMap<>();
|
|
|
276 |
List<List<?>> rows = new ArrayList<>();
|
|
|
277 |
if (!vendorCatalogPricings.isEmpty()) {
|
|
|
278 |
Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
|
|
279 |
itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
for(VendorPriceCircularModel vcp: vendorCatalogPricings) {
|
|
|
284 |
|
|
|
285 |
rows.add(Arrays.asList(vcp.getCatalogId(),supplierMap.get(vcp.getVendorId()).getName(),itemMap.get(vcp.getCatalogId()).get(0).getItemDescriptionNoColor(),vcp.getTransferPrice(),vcp.getDealerPrice(),vcp.getMop(),
|
|
|
286 |
FormattingUtils.formatDate(vcp.getEffectedOn())));
|
|
|
287 |
|
|
|
288 |
}
|
|
|
289 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
290 |
.getCSVByteStream(Arrays.asList("Catalog Id","Vendor Name", "Model name", "TP", "DP", "MOP",
|
|
|
291 |
"Effected On"), rows);
|
|
|
292 |
|
|
|
293 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price circular report");
|
|
|
294 |
|
|
|
295 |
return responseEntity;
|
|
|
296 |
|
|
|
297 |
}
|
|
|
298 |
|
| 32145 |
tejbeer |
299 |
@RequestMapping(value = "/getPricing", method = RequestMethod.GET)
|
| 32488 |
amit.gupta |
300 |
public String getPricing(HttpServletRequest request, @RequestParam int vendorId, @RequestParam int itemId, @RequestParam LocalDate onDate, Model model) throws Exception {
|
| 32901 |
amit.gupta |
301 |
Item item = itemRepository.selectById(itemId);
|
| 32488 |
amit.gupta |
302 |
VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), onDate);
|
| 32145 |
tejbeer |
303 |
|
| 32488 |
amit.gupta |
304 |
LOGGER.info("vendorCatalogPricing {}", vendorPriceCircularModel);
|
| 32145 |
tejbeer |
305 |
|
| 32488 |
amit.gupta |
306 |
model.addAttribute("response1", mvcResponseSender.createResponseString(vendorPriceCircularModel));
|
| 32145 |
tejbeer |
307 |
|
|
|
308 |
return "response";
|
|
|
309 |
|
|
|
310 |
}
|
| 32194 |
tejbeer |
311 |
|
| 32903 |
amit.gupta |
312 |
private void addVendorPricingIfMissing(int itemId, int vendorId) throws ProfitMandiBusinessException {
|
| 32942 |
amit.gupta |
313 |
Supplier supplier = supplierRepository.selectById(vendorId);
|
| 32900 |
amit.gupta |
314 |
Item item = itemRepository.selectById(itemId);
|
| 32903 |
amit.gupta |
315 |
int vendorWithPricing = 0;
|
| 32970 |
amit.gupta |
316 |
if (supplier.isInternal() && (item.getBrand().equals("Samsung") || item.getCategoryId() != 10006)) {
|
| 32927 |
amit.gupta |
317 |
VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), LocalDate.now());
|
| 32903 |
amit.gupta |
318 |
LOGGER.info("VendorPriceCircularModel - {}", vendorPriceCircularModel);
|
|
|
319 |
if (vendorPriceCircularModel == null) {
|
| 32942 |
amit.gupta |
320 |
if (item.getBrand().equals("Samsung")) {
|
|
|
321 |
//BSB
|
|
|
322 |
vendorWithPricing = 334;
|
| 32970 |
amit.gupta |
323 |
} else if (item.getCategoryId() != 10006) {
|
|
|
324 |
vendorWithPricing = vendorCatalogPricingLogRepository.selectByCatalogId(item.getCatalogItemId(), VendorCatalogPricingStatus.APPROVED).stream().map(x -> x.getVendorId())
|
|
|
325 |
.findFirst().orElse(null);
|
| 32903 |
amit.gupta |
326 |
}
|
|
|
327 |
VendorPriceCircularModel existingPriceCircular = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorWithPricing, item.getCatalogItemId(), LocalDate.now());
|
|
|
328 |
LOGGER.info("Existing price circular - {}", existingPriceCircular);
|
|
|
329 |
if (existingPriceCircular == null) {
|
|
|
330 |
throw new ProfitMandiBusinessException("Pricing missing for vendor - " + vendorId, "Pricing missing for vendor - " + vendorId, "Pricing missing for vendor - " + vendorId);
|
|
|
331 |
}
|
|
|
332 |
VendorCatalogPricingModel vendorCatalogPricingModel = new VendorCatalogPricingModel();
|
|
|
333 |
vendorCatalogPricingModel.setAuthId(52);
|
|
|
334 |
vendorCatalogPricingModel.setVendorId(vendorId);
|
|
|
335 |
vendorCatalogPricingModel.setCatalogId(existingPriceCircular.getCatalogId());
|
|
|
336 |
vendorCatalogPricingModel.setDp(existingPriceCircular.getDealerPrice());
|
|
|
337 |
vendorCatalogPricingModel.setEffectedOn(existingPriceCircular.getEffectedOn());
|
|
|
338 |
vendorCatalogPricingModel.setMop(existingPriceCircular.getMop());
|
|
|
339 |
vendorCatalogPricingModel.setTp(existingPriceCircular.getTransferPrice());
|
|
|
340 |
vendorCatalogPricingModel.setCatalogId(item.getCatalogItemId());
|
|
|
341 |
|
|
|
342 |
VendorCatalogPricingLog vendorCatalogPricingLog = vendorCatalogPricingService.createVendorCatalogPricingLog(vendorCatalogPricingModel);
|
|
|
343 |
vendorCatalogPricingLog.setStatus(VendorCatalogPricingStatus.APPROVED);
|
|
|
344 |
vendorCatalogPricingLog.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
345 |
//Deenanath Auth Id
|
|
|
346 |
vendorCatalogPricingLog.setApprovedBy(138);
|
|
|
347 |
vendorCatalogPricingLog.setApprovedTimestamp(LocalDateTime.now());
|
|
|
348 |
vendorCatalogPricingService.createVendorCatalogPricing(vendorCatalogPricingLog);
|
|
|
349 |
|
| 32900 |
amit.gupta |
350 |
}
|
|
|
351 |
}
|
|
|
352 |
}
|
|
|
353 |
|
| 32194 |
tejbeer |
354 |
@RequestMapping(value = "/vendorItem", method = RequestMethod.GET)
|
| 32900 |
amit.gupta |
355 |
public String getItemPricing(HttpServletRequest request, Model model, @RequestParam int vendorId,
|
| 32924 |
amit.gupta |
356 |
@RequestParam String query) throws Exception {
|
| 32194 |
tejbeer |
357 |
String query1 = query.toLowerCase();
|
| 32900 |
amit.gupta |
358 |
int itemId = 0;
|
|
|
359 |
try {
|
|
|
360 |
itemId = Integer.parseInt(query1);
|
| 32903 |
amit.gupta |
361 |
addVendorPricingIfMissing(itemId, vendorId);
|
| 32924 |
amit.gupta |
362 |
} catch (NumberFormatException e) {
|
|
|
363 |
LOGGER.info("Ignore number format exception");
|
| 32942 |
amit.gupta |
364 |
// e.printStackTrace();
|
| 32898 |
amit.gupta |
365 |
}
|
| 32903 |
amit.gupta |
366 |
LOGGER.info("Vendor Id - {}", vendorId);
|
| 32194 |
tejbeer |
367 |
List<ItemDescriptionModel> partnersItemDescription = warehouseService.getAllPartnerItemStringDescription(vendorId).parallelStream().filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?")).collect(Collectors.toList());
|
|
|
368 |
LOGGER.info("partnersItemDescription" + partnersItemDescription);
|
|
|
369 |
|
|
|
370 |
model.addAttribute("response1", mvcResponseSender.createResponseString(partnersItemDescription));
|
|
|
371 |
return "response";
|
|
|
372 |
}
|
| 32075 |
tejbeer |
373 |
}
|