Subversion Repositories SmartDukaan

Rev

Rev 32565 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32565 Rev 34329
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import com.spice.profitmandi.common.model.ProfitMandiConstants;
3
import com.spice.profitmandi.common.model.ProfitMandiConstants;
4
import com.spice.profitmandi.dao.entity.inventory.State;
4
import com.spice.profitmandi.dao.entity.inventory.State;
5
import com.spice.profitmandi.dao.entity.inventory.Vendor;
5
import com.spice.profitmandi.dao.entity.inventory.Vendor;
-
 
6
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
6
import com.spice.profitmandi.dao.entity.transaction.Seller;
7
import com.spice.profitmandi.dao.entity.transaction.Seller;
7
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
8
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
8
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMapping;
9
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMapping;
9
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMaster;
10
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMaster;
10
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
11
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
11
import com.spice.profitmandi.dao.enumuration.inventory.InventoryType;
12
import com.spice.profitmandi.dao.enumuration.inventory.InventoryType;
12
import com.spice.profitmandi.dao.enumuration.inventory.WarehouseType;
13
import com.spice.profitmandi.dao.enumuration.inventory.WarehouseType;
13
import com.spice.profitmandi.dao.hrms.CreateNewSupplier;
14
import com.spice.profitmandi.dao.hrms.CreateNewSupplier;
14
import com.spice.profitmandi.dao.hrms.WarehouseIdPrefixModel;
15
import com.spice.profitmandi.dao.hrms.WarehouseIdPrefixModel;
-
 
16
import com.spice.profitmandi.dao.model.hdfc.SupplierFormData;
15
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
17
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
16
import com.spice.profitmandi.dao.repository.inventory.VendorRepository;
18
import com.spice.profitmandi.dao.repository.inventory.VendorRepository;
-
 
19
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
17
import com.spice.profitmandi.dao.repository.transaction.SellerRepository;
20
import com.spice.profitmandi.dao.repository.transaction.SellerRepository;
18
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
21
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
19
import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMappingRepository;
22
import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMappingRepository;
20
import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMasterRepository;
23
import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMasterRepository;
21
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
24
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
Line 67... Line 70...
67
    @Autowired
70
    @Autowired
68
    private StateRepository stateRepository;
71
    private StateRepository stateRepository;
69
 
72
 
70
    private static final Logger LOGGER = LogManager.getLogger(SupplierController.class);
73
    private static final Logger LOGGER = LogManager.getLogger(SupplierController.class);
71
 
74
 
72
    @RequestMapping(value = "/getAllSupplier", method = RequestMethod.GET)
-
 
73
    public String getShowSupplier(HttpServletRequest request, Model model) throws Exception {
-
 
74
 
-
 
75
        List<Supplier> supplierAcvtives = supplierRepository.selectByStatus(true);
-
 
76
 
-
 
77
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
-
 
78
        List<Integer> sellerwarehouseIds = sellerWarehouses.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());
-
 
79
        LOGGER.info("sellerWarehouses" + sellerWarehouses);
-
 
80
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
-
 
81
 
-
 
82
        for (SellerWarehouse sw : sellerWarehouses) {
-
 
83
 
-
 
84
            WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sw.getWarehouseId());
-
 
85
            LOGGER.info("warehouseAddressMapping" + warehouseAddressMapping);
-
 
86
            if (warehouseAddressMapping != null) {
-
 
87
                WarehouseAddressMaster WarehouseAddressMaster = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());
-
 
88
                LOGGER.info("warehouseAddressMappingAddreesId" + warehouseAddressMapping.getAddressId());
-
 
89
                LOGGER.info("WarehouseAddressMaster" + WarehouseAddressMaster);
-
 
90
                State state = stateRepository.selectById(WarehouseAddressMaster.getStateId());
-
 
91
                WarehouseIdPrefixModel wp = new WarehouseIdPrefixModel();
-
 
92
                wp.setPrefix(sw.getPrefix());
-
 
93
                wp.setStateName(state.getName());
-
 
94
                warehouseIdAndState.put(sw.getWarehouseId(), wp);
-
 
95
                LOGGER.info("state" + state);
-
 
96
            }
75
    @Autowired
97
        }
-
 
98
        LOGGER.info("warehouseIdAndState" + warehouseIdAndState);
76
    WarehouseRepository warehouseRepository;
99
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
-
 
100
 
-
 
101
        List<State> state = stateRepository.selectAll();
-
 
102
 
-
 
103
        model.addAttribute("suppliers", supplierAcvtives);
-
 
104
        model.addAttribute("state", state);
-
 
105
 
-
 
106
        return "supplier";
-
 
107
 
-
 
108
    }
-
 
109
 
77
 
110
    @RequestMapping(value = "/getAllInActiveSupplier", method = RequestMethod.GET)
78
    @RequestMapping(value = "/getAllInActiveSupplier", method = RequestMethod.GET)
111
    public String getShowInActiveSupplier(HttpServletRequest request, Model model) throws Exception {
79
    public String getShowInActiveSupplier(HttpServletRequest request, Model model) throws Exception {
112
 
80
 
113
        List<Supplier> supplierInactives = supplierRepository.selectByStatus(false);
81
        List<Supplier> supplierInactives = supplierRepository.selectByStatus(false);
Line 118... Line 86...
118
 
86
 
119
        return "supplier-in-active";
87
        return "supplier-in-active";
120
 
88
 
121
    }
89
    }
122
 
90
 
123
    /*@RequestMapping(value = "/supplier/edit/{supplierId}", method = RequestMethod.GET)
91
    @RequestMapping(value = "/getAllSupplier", method = RequestMethod.GET)
124
    public String getEditSupplier(HttpServletRequest request, Model model, @PathVariable int supplierId) throws Exception {
92
    public String getShowSupplier(HttpServletRequest request, Model model) throws Exception {
-
 
93
 
125
        Supplier supplier  = supplierRepository.selectById(supplierId);
94
        List<Supplier> supplierAcvtives = supplierRepository.selectByStatus(true);
-
 
95
 
126
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
96
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
127
        List<Integer> sellerwarehouseIds = sellerWarehouses.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());
97
        List<Integer> sellerwarehouseIds = sellerWarehouses.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());
128
        LOGGER.info("sellerWarehouses" + sellerWarehouses);
98
        LOGGER.info("sellerWarehouses" + sellerWarehouses);
129
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
99
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
130
 
100
 
Line 147... Line 117...
147
        LOGGER.info("warehouseIdAndState" + warehouseIdAndState);
117
        LOGGER.info("warehouseIdAndState" + warehouseIdAndState);
148
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
118
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
149
 
119
 
150
        List<State> state = stateRepository.selectAll();
120
        List<State> state = stateRepository.selectAll();
151
 
121
 
-
 
122
        model.addAttribute("suppliers", supplierAcvtives);
-
 
123
        model.addAttribute("response1", mvcResponseSender.createResponseString(supplierAcvtives));
152
        model.addAttribute("state", state);
124
        model.addAttribute("state", state);
153
        model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
-
 
154
        model.addAttribute("supplier", supplier);
-
 
-
 
125
 
155
        return "edit-supplier";
126
        return "supplier";
-
 
127
 
156
    }
128
    }
157
*/
129
 
158
 
130
 
159
    @RequestMapping(value = "/getCreateNewSupplier", method = RequestMethod.GET)
131
    @RequestMapping(value = "/getCreateNewSupplier", method = RequestMethod.GET)
160
    public String getCreateNewSupplier(HttpServletRequest request, Model model) throws Exception {
132
    public String getCreateNewSupplier(HttpServletRequest request, Model model) throws Exception {
161
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
133
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
162
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
134
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
Line 272... Line 244...
272
        //model.addAttribute("response1", mvcResponseSender.createResponseString(true));
244
        //model.addAttribute("response1", mvcResponseSender.createResponseString(true));
273
 
245
 
274
        return getShowInActiveSupplier(request, model);
246
        return getShowInActiveSupplier(request, model);
275
 
247
 
276
    }
248
    }
-
 
249
 
-
 
250
    @RequestMapping(value = "/supplier/edit/{supplierId}", method = RequestMethod.GET)
-
 
251
    public String getEditSupplier(HttpServletRequest request, Model model, @PathVariable int supplierId) throws Exception {
-
 
252
        Supplier supplier  = supplierRepository.selectById(supplierId);
-
 
253
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
-
 
254
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
-
 
255
 
-
 
256
        List<Warehouse> supplierWarehouses = warehouseRepository.selectVendorWarehouses(supplierId, WarehouseType.OURS, InventoryType.GOOD);
-
 
257
        List<Integer> supplierPhysicalWarehouseIds = supplierWarehouses.stream().map(x -> x.getShippingWarehouseId()).collect(Collectors.toList());
-
 
258
        LOGGER.info("supplierPhysicalWarehouseIds" + supplierPhysicalWarehouseIds);
-
 
259
        for (SellerWarehouse sw : sellerWarehouses) {
-
 
260
            WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sw.getWarehouseId());
-
 
261
            if (warehouseAddressMapping != null) {
-
 
262
                WarehouseAddressMaster WarehouseAddressMaster = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());
-
 
263
                State state = stateRepository.selectById(WarehouseAddressMaster.getStateId());
-
 
264
                WarehouseIdPrefixModel wp = new WarehouseIdPrefixModel();
-
 
265
                wp.setPrefix(sw.getPrefix());
-
 
266
                wp.setStateName(state.getName());
-
 
267
                warehouseIdAndState.put(sw.getWarehouseId(), wp);
-
 
268
            }
-
 
269
        }
-
 
270
        LOGGER.info("warehouseIdAndState" + warehouseIdAndState);
-
 
271
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
-
 
272
 
-
 
273
        List<State> state = stateRepository.selectAll();
-
 
274
 
-
 
275
        model.addAttribute("state", state);
-
 
276
        model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
-
 
277
        model.addAttribute("supplier", supplier);
-
 
278
        model.addAttribute("supplierPhysicalWarehouseIds", supplierPhysicalWarehouseIds);
-
 
279
        return "edit-supplier";
-
 
280
    }
-
 
281
 
-
 
282
    @RequestMapping(value = "/supplier/update/{supplierId}", method = RequestMethod.POST)
-
 
283
    public String updateSupplier(@PathVariable("supplierId") int supplierId,
-
 
284
                                 @RequestBody SupplierFormData supplierFormData,
-
 
285
                                 Model model) throws Exception {
-
 
286
        LOGGER.info("supplierFormDataaaa - " + supplierFormData);
-
 
287
 
-
 
288
        Supplier supplier = supplierRepository.selectById(supplierId);
-
 
289
        supplier.setContactPhone(supplierFormData.getInputPhone());
-
 
290
        supplier.setGstin(supplierFormData.getInputGst());
-
 
291
        supplier.setPan(supplierFormData.getInputPan());
-
 
292
        supplier.setFax(supplierFormData.getInputFax());
-
 
293
        supplier.setHeadName(supplierFormData.getInputHeadName());
-
 
294
        supplier.setHeadDesignation(supplierFormData.getInputHeadDesign());
-
 
295
        supplier.setHeadEmail(supplierFormData.getInputHeadEmail());
-
 
296
        supplier.setContactName(supplierFormData.getInputContactPerson());
-
 
297
        supplier.setContactPhone(supplierFormData.getInputContactPhone());
-
 
298
        supplier.setContactEmail(supplierFormData.getInputContactEmail());
-
 
299
        supplier.setFax((supplierFormData.getInputFax()));
-
 
300
        supplier.setRegisteredAddress(supplierFormData.getInputRegisteredAddress());
-
 
301
        supplier.setCommunicationAddress(supplierFormData.getInputCommunicationAddress());
-
 
302
        supplier.setTnc(supplierFormData.getInputTermConditions());
-
 
303
        supplier.setInternalWarehouseId(supplierFormData.getInternalWarehouseId());
-
 
304
        supplier.setStateId(supplierFormData.getStateId());
-
 
305
        supplier.setPoValidityLimit(supplierFormData.getInputPOValidityLimit());
-
 
306
 
-
 
307
        List<Integer> newWarehouseIds = supplierFormData.getInputWarehouseLocation();
-
 
308
 
-
 
309
        // Only run the warehouse update logic if new warehouse IDs are provided
-
 
310
        if (newWarehouseIds != null && !newWarehouseIds.isEmpty()) {
-
 
311
            List<Warehouse> existingWarehouses = warehouseRepository.selectVendorWarehouses(supplierId, WarehouseType.OURS, InventoryType.GOOD);
-
 
312
            List<Integer> existingWarehouseIds = existingWarehouses.stream().map(Warehouse::getShippingWarehouseId).collect(Collectors.toList());
-
 
313
 
-
 
314
            // Filter out any IDs that are already present
-
 
315
            List<Integer> warehousesToAdd = newWarehouseIds.stream()
-
 
316
                    .filter(id -> !existingWarehouseIds.contains(id))
-
 
317
                    .collect(Collectors.toList());
-
 
318
 
-
 
319
            if (!warehousesToAdd.isEmpty()) {
-
 
320
                for (Integer warehouseId : warehousesToAdd) {
-
 
321
                    WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(warehouseId);
-
 
322
                    if (warehouseAddressMapping != null) {
-
 
323
                        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectBywarehouseId(warehouseAddressMapping.getWarehouseId());
-
 
324
                        for (SellerWarehouse sellerWarehouse : sellerWarehouses) {
-
 
325
                            Seller seller = sellerRepository.selectById(sellerWarehouse.getSellerId());
-
 
326
                            WarehouseAddressMaster wam = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());
-
 
327
 
-
 
328
                            // GOOD - WarehouseType.OURS, InventoryType.GOOD
-
 
329
                            warehouseService.createVendorWarehouse(WarehouseType.OURS, InventoryType.GOOD, seller.getLabel(), warehouseId, wam, supplierId);
-
 
330
 
-
 
331
                            // BAD - WarehouseType.OURS, InventoryType.BAD
-
 
332
                            warehouseService.createVendorWarehouse(WarehouseType.OURS, InventoryType.BAD, seller.getLabel(), warehouseId, wam, supplierId);
-
 
333
 
-
 
334
                            // VIRTUAL - WarehouseType.THIRD_PARTY, InventoryType.GOOD
-
 
335
                            warehouseService.createVendorWarehouse(WarehouseType.THIRD_PARTY, InventoryType.GOOD, seller.getLabel(), warehouseId, wam, supplierId);
-
 
336
                        }
-
 
337
                    }
-
 
338
                }
-
 
339
            }
-
 
340
        }
-
 
341
 
-
 
342
        return "edit-supplier";
-
 
343
    }
-
 
344
 
-
 
345
 
-
 
346
 
-
 
347
 
-
 
348
 
277
}
349
}