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