Subversion Repositories SmartDukaan

Rev

Rev 33750 | Rev 34048 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33750 Rev 34047
Line 3... Line 3...
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.model.ItemDescriptionModel;
4
import com.spice.profitmandi.common.model.ItemDescriptionModel;
5
import com.spice.profitmandi.common.util.FileUtil;
5
import com.spice.profitmandi.common.util.FileUtil;
6
import com.spice.profitmandi.common.util.FormattingUtils;
6
import com.spice.profitmandi.common.util.FormattingUtils;
7
import com.spice.profitmandi.dao.entity.auth.AuthUser;
7
import com.spice.profitmandi.dao.entity.auth.AuthUser;
-
 
8
import com.spice.profitmandi.dao.entity.catalog.CategorisedCatalog;
8
import com.spice.profitmandi.dao.entity.catalog.Item;
9
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.Vendor;
10
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricing;
11
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricing;
11
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricingLog;
12
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricingLog;
12
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
13
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
13
import com.spice.profitmandi.dao.enumuration.inventory.VendorCatalogPricingStatus;
14
import com.spice.profitmandi.dao.enumuration.inventory.VendorCatalogPricingStatus;
14
import com.spice.profitmandi.dao.model.VendorCatalogPricingModel;
15
import com.spice.profitmandi.dao.model.VendorCatalogPricingModel;
15
import com.spice.profitmandi.dao.model.VendorPriceCircularModel;
16
import com.spice.profitmandi.dao.model.VendorPriceCircularModel;
16
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
17
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
-
 
18
import com.spice.profitmandi.dao.repository.catalog.CategorisedCatalogRepository;
17
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
19
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
18
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingLogRepository;
20
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingLogRepository;
19
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingRepository;
21
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingRepository;
20
import com.spice.profitmandi.dao.repository.inventory.VendorRepository;
22
import com.spice.profitmandi.dao.repository.inventory.VendorRepository;
21
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
23
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
Line 92... Line 94...
92
    private SupplierRepository supplierRepository;
94
    private SupplierRepository supplierRepository;
93
 
95
 
94
    @Autowired
96
    @Autowired
95
    private WarehouseService warehouseService;
97
    private WarehouseService warehouseService;
96
 
98
 
-
 
99
    @Autowired
-
 
100
    CategorisedCatalogRepository categorisedCatalogRepository;
-
 
101
 
97
    private static final Logger LOGGER = LogManager.getLogger(VendorController.class);
102
    private static final Logger LOGGER = LogManager.getLogger(VendorController.class);
98
 
103
 
99
 
104
 
100
    @RequestMapping(value = "/vendorCatalogPricing", method = RequestMethod.GET)
105
    @RequestMapping(value = "/vendorCatalogPricing", method = RequestMethod.GET)
101
    public String vendorCatalogPricing(HttpServletRequest request, Model model) throws Exception {
106
    public String vendorCatalogPricing() throws Exception {
102
 
-
 
103
        return "vendor-catalog-pricing";
107
        return "vendor-catalog-pricing";
104
    }
108
    }
105
 
109
 
106
 
110
 
107
    @RequestMapping(value = "/getVendorCatalogPricingByModel", method = RequestMethod.GET)
111
    @RequestMapping(value = "/getVendorCatalogPricingByModel", method = RequestMethod.GET)
108
    public String getVendorCatalogPricingByModel(HttpServletRequest request, @RequestParam int catalogId, Model model) throws Exception {
112
    public String getVendorCatalogPricingByModel(@RequestParam int catalogId, Model model) throws Exception {
109
 
113
 
110
        List<Integer> vendorIds = new ArrayList<>();
114
        List<Integer> vendorIds = new ArrayList<>();
111
        Map<Integer, VendorCatalogPricing> vendorCatalogPricingMap = new HashMap<>();
115
        Map<Integer, VendorCatalogPricing> vendorCatalogPricingMap = new HashMap<>();
112
        Map<Integer, VendorCatalogPricingLog> vendorCatalogPricingLogMap = new HashMap<>();
116
        Map<Integer, VendorCatalogPricingLog> vendorCatalogPricingLogMap = new HashMap<>();
113
        List<VendorCatalogPricing> vendorCatalogPricing = vendorCatalogPricingRepository.selectByCatalogId(catalogId);
117
        List<VendorCatalogPricing> vendorCatalogPricing = vendorCatalogPricingRepository.selectByCatalogId(catalogId);
Line 138... Line 142...
138
        return "vendor-catalog-pricing-view";
142
        return "vendor-catalog-pricing-view";
139
    }
143
    }
140
 
144
 
141
 
145
 
142
    @RequestMapping(value = "/vendors", method = RequestMethod.GET)
146
    @RequestMapping(value = "/vendors", method = RequestMethod.GET)
143
    public String getVendor(HttpServletRequest request, Model model, @RequestParam String query) throws Throwable {
147
    public String getVendor(Model model, @RequestParam String query) throws Throwable {
144
        List<Supplier> vendors = supplierRepository.selectAll().stream().filter(x -> x.getName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?"))
148
        List<Supplier> vendors = supplierRepository.selectAll().stream().filter(x -> x.getName().toLowerCase().matches(".*?" + query.toLowerCase() + ".*?"))
145
                .filter(x -> x.isStatus()).collect(Collectors.toList());
149
                .filter(x -> x.isStatus()).collect(Collectors.toList());
146
        model.addAttribute("response1", mvcResponseSender.createResponseString(vendors));
150
        model.addAttribute("response1", mvcResponseSender.createResponseString(vendors));
147
        return "response";
151
        return "response";
148
    }
152
    }
Line 162... Line 166...
162
        return "response";
166
        return "response";
163
 
167
 
164
    }
168
    }
165
 
169
 
166
    @RequestMapping(value = "/createBulkPricing")
170
    @RequestMapping(value = "/createBulkPricing")
167
    public String createBulkPricing(HttpServletRequest request, Model model) throws ProfitMandiBusinessException, MessagingException, IOException {
171
    public String createBulkPricing() throws ProfitMandiBusinessException, MessagingException, IOException {
168
        return "bulk-vendor-pricing";
172
        return "bulk-vendor-pricing";
169
    }
173
    }
170
 
174
 
171
    @PostMapping(value = "/bulkVendorCatalogPricing/upload")
175
    @PostMapping(value = "/bulkVendorCatalogPricing/upload")
172
    public String uploadCatalog(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model)
176
    public String uploadCatalog(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model)
Line 188... Line 192...
188
                .body(new InputStreamResource(dummyFile.getInputStream()));
192
                .body(new InputStreamResource(dummyFile.getInputStream()));
189
    }
193
    }
190
 
194
 
191
 
195
 
192
    @RequestMapping(value = "/vendorCatalogPricingRequests", method = RequestMethod.GET)
196
    @RequestMapping(value = "/vendorCatalogPricingRequests", method = RequestMethod.GET)
193
    public String vendorCatalogPricingRequests(HttpServletRequest request, Model model) throws Exception {
197
    public String vendorCatalogPricingRequests(Model model) throws Exception {
194
        List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByStatus(VendorCatalogPricingStatus.PENDING);
198
        List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByStatus(VendorCatalogPricingStatus.PENDING);
195
        Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
199
        Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
196
        model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
200
        model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
197
        if (!vendorCatalogPricingRequests.isEmpty()) {
201
        if (!vendorCatalogPricingRequests.isEmpty()) {
198
            Set<Integer> catalogIds = vendorCatalogPricingRequests.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
202
            Set<Integer> catalogIds = vendorCatalogPricingRequests.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
Line 209... Line 213...
209
 
213
 
210
        return "vendor-catalog-pricing-request";
214
        return "vendor-catalog-pricing-request";
211
    }
215
    }
212
 
216
 
213
    @RequestMapping(value = "/vendorCatalogPricingPendingRequests", method = RequestMethod.GET)
217
    @RequestMapping(value = "/vendorCatalogPricingPendingRequests", method = RequestMethod.GET)
214
    public String vendorCatalogPricingPendingRequests(HttpServletRequest request, Model model) throws Exception {
218
    public String vendorCatalogPricingPendingRequests() throws Exception {
215
        return "vendor-catalog-pricing-pending-request";
219
        return "vendor-catalog-pricing-pending-request";
216
    }
220
    }
217
 
221
 
218
    @RequestMapping(value = "/datewiseVendorCatalogPricingPendingRequests", method = RequestMethod.GET)
222
    @RequestMapping(value = "/datewiseVendorCatalogPricingPendingRequests", method = RequestMethod.GET)
219
    public String datewiseVendorCatalogPricingPendingRequests(HttpServletRequest request, @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
223
    public String datewiseVendorCatalogPricingPendingRequests(@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
220
        List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByDate(startDate, endDate);
224
        List<VendorCatalogPricingLog> vendorCatalogPricingRequests = vendorCatalogPricingLogRepository.selectByDate(startDate, endDate);
221
        Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
225
        Map<Integer, AuthUser> authUserMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
222
        LOGGER.info("vendorCatalogPricingRequests {}", vendorCatalogPricingRequests);
226
        LOGGER.info("vendorCatalogPricingRequests {}", vendorCatalogPricingRequests);
223
        model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
227
        model.addAttribute("vendorCatalogPricingRequests", vendorCatalogPricingRequests);
224
        if (!vendorCatalogPricingRequests.isEmpty()) {
228
        if (!vendorCatalogPricingRequests.isEmpty()) {
Line 263... Line 267...
263
        return "response";
267
        return "response";
264
    }
268
    }
265
 
269
 
266
 
270
 
267
    @RequestMapping(value = "/vendorPriceCircular", method = RequestMethod.GET)
271
    @RequestMapping(value = "/vendorPriceCircular", method = RequestMethod.GET)
268
    public String vendorPriceCircular(HttpServletRequest request, Model model) throws Exception {
272
    public String vendorPriceCircular() throws Exception {
269
 
-
 
270
 
-
 
271
        return "vendor-price-circular";
273
        return "vendor-price-circular";
272
 
-
 
273
    }
274
    }
274
 
275
 
275
 
276
 
276
    @RequestMapping(value = "/getVendorPriceCircular", method = RequestMethod.GET)
277
    @RequestMapping(value = "/getVendorPriceCircular", method = RequestMethod.GET)
277
    public String getVendorPriceCircular(HttpServletRequest request, @RequestParam(defaultValue = "0") int vendorId, @RequestParam LocalDate effectedDate, Model model) throws Exception {
278
    public String getVendorPriceCircular(@RequestParam(defaultValue = "0") int vendorId, @RequestParam LocalDate effectedDate, Model model) throws Exception {
278
 
279
 
279
        List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(vendorId, effectedDate);
280
        List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(vendorId, effectedDate);
280
        Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
281
        Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
281
        if (!vendorCatalogPricings.isEmpty()) {
282
        if (!vendorCatalogPricings.isEmpty()) {
282
            Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
283
            Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
Line 287... Line 288...
287
        model.addAttribute("vendorCatalogPricings", vendorCatalogPricings);
288
        model.addAttribute("vendorCatalogPricings", vendorCatalogPricings);
288
        model.addAttribute("suppliers", supplierMap);
289
        model.addAttribute("suppliers", supplierMap);
289
        return "vendor-price-circular-view";
290
        return "vendor-price-circular-view";
290
 
291
 
291
    }
292
    }
-
 
293
 
292
    @RequestMapping(value = "/downloadPriceCircularReport", method = RequestMethod.GET)
294
    @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 {
295
    public ResponseEntity<?> getSelectDownloadPriceCircularReport(@RequestParam(name = "startDate") LocalDate startDate) throws Exception {
296
 
296
 
297
        List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(0, startDate);
297
        List<VendorPriceCircularModel> vendorCatalogPricings = vendorCatalogPricingLogRepository.getVendorPricesOnDate(0, startDate);
298
        Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
298
        Map<Integer, Supplier> supplierMap = supplierRepository.selectAll().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
299
        Map<Integer, List<Item>> itemMap = new HashMap<>();
299
        Map<Integer, List<Item>> itemMap = new HashMap<>();
300
        List<List<?>> rows = new ArrayList<>();
300
        List<List<?>> rows = new ArrayList<>();
301
        if (!vendorCatalogPricings.isEmpty()) {
301
        if (!vendorCatalogPricings.isEmpty()) {
302
            Set<Integer> catalogIds = vendorCatalogPricings.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
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()));
303
            itemMap = itemRepository.selectAllByCatalogIds(catalogIds).stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
304
        }
304
        }
305
 
305
 
-
 
306
        for (VendorPriceCircularModel vcp : vendorCatalogPricings) {
306
 
307
 
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(),
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(),
310
                    FormattingUtils.formatDate(vcp.getEffectedOn())));
309
                    FormattingUtils.formatDate(vcp.getEffectedOn())));
311
 
310
 
312
        }
311
        }
313
        org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
312
        org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
314
                .getCSVByteStream(Arrays.asList("Catalog Id","Vendor Name", "Model name", "TP", "DP", "MOP",
313
                .getCSVByteStream(Arrays.asList("Catalog Id", "Vendor Name", "Model name", "TP", "DP", "MOP",
315
                        "Effected On"), rows);
314
                        "Effected On"), rows);
316
 
315
 
317
        ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price circular report");
316
        ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price circular report");
318
 
317
 
319
        return responseEntity;
318
        return responseEntity;
320
 
319
 
321
    }
320
    }
322
 
321
 
-
 
322
 
323
    @RequestMapping(value = "/getPricing", method = RequestMethod.GET)
323
    @RequestMapping(value = "/getPricing", method = RequestMethod.GET)
324
    public String getPricing(HttpServletRequest request, @RequestParam int vendorId, @RequestParam int itemId, @RequestParam LocalDate onDate, Model model) throws Exception {
324
    public String getPricing(HttpServletRequest request, @RequestParam int vendorId, @RequestParam int itemId, @RequestParam LocalDate onDate, Model model) throws Exception {
-
 
325
        List<Integer> checkRequiredCategoryId = Arrays.asList(10006, 10010);
-
 
326
        List<String> checkRequiredCategoryGroup = Arrays.asList("Handset", "Tablets");
325
        Item item = itemRepository.selectById(itemId);
327
        Item item = itemRepository.selectById(itemId);
-
 
328
        if (checkRequiredCategoryId.contains(item.getCategoryId()) || checkRequiredCategoryGroup.contains(item.getProductGroup())) {
-
 
329
            CategorisedCatalog categorisedCatalog = categorisedCatalogRepository.selectByCatalogId(item.getCatalogItemId());
-
 
330
            if (categorisedCatalog == null || categorisedCatalog.getStatus().getValue().isEmpty()) {
-
 
331
                model.addAttribute("response1", mvcResponseSender.createResponseString(false));
-
 
332
                return "response";
-
 
333
            }
-
 
334
        }
326
        VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), onDate);
335
        VendorPriceCircularModel vendorPriceCircularModel = vendorCatalogPricingLogRepository.getVendorPriceOnDate(vendorId, item.getCatalogItemId(), onDate);
327
 
-
 
328
        LOGGER.info("vendorCatalogPricing {}", vendorPriceCircularModel);
336
        LOGGER.info("vendorCatalogPricing {}", vendorPriceCircularModel);
329
 
-
 
330
        model.addAttribute("response1", mvcResponseSender.createResponseString(vendorPriceCircularModel));
337
        model.addAttribute("response1", mvcResponseSender.createResponseString(vendorPriceCircularModel));
331
 
-
 
332
        return "response";
338
        return "response";
333
 
-
 
334
    }
339
    }
335
 
340
 
336
    private void addVendorPricingIfMissing(int itemId, int vendorId) throws ProfitMandiBusinessException {
341
    private void addVendorPricingIfMissing(int itemId, int vendorId) throws ProfitMandiBusinessException {
337
        Supplier supplier = supplierRepository.selectById(vendorId);
342
        Supplier supplier = supplierRepository.selectById(vendorId);
338
        Item item = itemRepository.selectById(itemId);
343
        Item item = itemRepository.selectById(itemId);
Line 374... Line 379...
374
            }
379
            }
375
        }
380
        }
376
    }
381
    }
377
 
382
 
378
    @RequestMapping(value = "/vendorItem", method = RequestMethod.GET)
383
    @RequestMapping(value = "/vendorItem", method = RequestMethod.GET)
379
    public String getItemPricing(HttpServletRequest request, Model model, @RequestParam int vendorId,
384
    public String getItemPricing(Model model, @RequestParam int vendorId, @RequestParam String query) throws Exception {
380
                                 @RequestParam String query) throws Exception {
-
 
381
        String query1 = query.toLowerCase();
385
        String query1 = query.toLowerCase();
382
        int itemId = 0;
386
        int itemId = 0;
383
        try {
387
        try {
384
            itemId = Integer.parseInt(query1);
388
            itemId = Integer.parseInt(query1);
385
            addVendorPricingIfMissing(itemId, vendorId);
389
            addVendorPricingIfMissing(itemId, vendorId);