Subversion Repositories SmartDukaan

Rev

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

Rev 37770 Rev 37823
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.exception.ProfitMandiBusinessException;
3
import com.spice.profitmandi.common.model.ProfitMandiConstants;
4
import com.spice.profitmandi.common.model.ProfitMandiConstants;
4
import com.spice.profitmandi.dao.entity.inventory.State;
5
import com.spice.profitmandi.dao.entity.inventory.State;
5
import com.spice.profitmandi.dao.entity.inventory.Vendor;
6
import com.spice.profitmandi.dao.entity.inventory.Vendor;
6
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
7
import com.spice.profitmandi.dao.entity.inventory.Warehouse;
7
import com.spice.profitmandi.dao.entity.transaction.Seller;
8
import com.spice.profitmandi.dao.entity.transaction.Seller;
Line 35... Line 36...
35
 
36
 
36
import javax.servlet.http.HttpServletRequest;
37
import javax.servlet.http.HttpServletRequest;
37
import java.util.HashMap;
38
import java.util.HashMap;
38
import java.util.List;
39
import java.util.List;
39
import java.util.Map;
40
import java.util.Map;
-
 
41
import java.util.TreeMap;
40
import java.util.stream.Collectors;
42
import java.util.stream.Collectors;
41
 
43
 
42
@Controller
44
@Controller
43
@Transactional(rollbackFor = Throwable.class)
45
@Transactional(rollbackFor = Throwable.class)
44
public class SupplierController {
46
public class SupplierController {
Line 77... Line 79...
77
    private static final Logger LOGGER = LogManager.getLogger(SupplierController.class);
79
    private static final Logger LOGGER = LogManager.getLogger(SupplierController.class);
78
 
80
 
79
    @Autowired
81
    @Autowired
80
    WarehouseRepository warehouseRepository;
82
    WarehouseRepository warehouseRepository;
81
 
83
 
-
 
84
    // Physical warehouses are the ones with an active seller registration (transaction.sellerwarehouse);
-
 
85
    // inventory.warehouse only supplies the name.
-
 
86
    private Map<Integer, String> activePhysicalWarehouses() {
-
 
87
        Map<Integer, String> activeWarehouses = new TreeMap<>();
-
 
88
        for (SellerWarehouse sellerWarehouse : sellerWarehouseRepository.selectAll()) {
-
 
89
            if (!sellerWarehouse.isActive() || activeWarehouses.containsKey(sellerWarehouse.getWarehouseId())) {
-
 
90
                continue;
-
 
91
            }
-
 
92
            Warehouse warehouse = warehouseRepository.selectById(sellerWarehouse.getWarehouseId());
-
 
93
            activeWarehouses.put(sellerWarehouse.getWarehouseId(), sellerWarehouse.getPrefix() + " - "
-
 
94
                    + (warehouse == null ? String.valueOf(sellerWarehouse.getWarehouseId()) : warehouse.getDisplayName()));
-
 
95
        }
-
 
96
        return activeWarehouses;
-
 
97
    }
-
 
98
 
-
 
99
    // 0 means not internal. A supplier marked internal stands for that physical warehouse in stock movements, so it
-
 
100
    // must be an active one.
-
 
101
    private void applyInternalWarehouse(Supplier supplier, Integer internalWarehouseId) throws ProfitMandiBusinessException {
-
 
102
        int warehouseId = internalWarehouseId == null ? 0 : internalWarehouseId;
-
 
103
        if (warehouseId > 0 && !this.activePhysicalWarehouses().containsKey(warehouseId)) {
-
 
104
            throw new ProfitMandiBusinessException("internalWarehouseId", warehouseId,
-
 
105
                    "Warehouse " + warehouseId + " is not an active physical warehouse");
-
 
106
        }
-
 
107
        supplier.setInternal(warehouseId > 0);
-
 
108
        supplier.setInternalWarehouseId(warehouseId);
-
 
109
    }
-
 
110
 
82
    @RequestMapping(value = "/getAllInActiveSupplier", method = RequestMethod.GET)
111
    @RequestMapping(value = "/getAllInActiveSupplier", method = RequestMethod.GET)
83
    public String getShowInActiveSupplier(HttpServletRequest request, Model model) throws Exception {
112
    public String getShowInActiveSupplier(HttpServletRequest request, Model model) throws Exception {
84
 
113
 
85
        List<Supplier> supplierInactives = supplierRepository.selectByStatus(false);
114
        List<Supplier> supplierInactives = supplierRepository.selectByStatus(false);
86
 
115
 
Line 132... Line 161...
132
    }
161
    }
133
 
162
 
134
 
163
 
135
    @RequestMapping(value = "/getCreateNewSupplier", method = RequestMethod.GET)
164
    @RequestMapping(value = "/getCreateNewSupplier", method = RequestMethod.GET)
136
    public String getCreateNewSupplier(HttpServletRequest request, Model model) throws Exception {
165
    public String getCreateNewSupplier(HttpServletRequest request, Model model) throws Exception {
137
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
166
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll().stream()
138
        Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
-
 
139
        sellerWarehouses = sellerWarehouses.stream().filter(x -> warehouseMap.containsKey(x.getWarehouseId())).collect(Collectors.toList());
167
                .filter(SellerWarehouse::isActive).collect(Collectors.toList());
140
 
168
 
141
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
169
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
142
 
170
 
143
        for (SellerWarehouse sw : sellerWarehouses) {
171
        for (SellerWarehouse sw : sellerWarehouses) {
144
            WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sw.getWarehouseId());
172
            WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sw.getWarehouseId());
Line 159... Line 187...
159
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
187
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
160
 
188
 
161
        List<State> state = stateRepository.selectAll();
189
        List<State> state = stateRepository.selectAll();
162
 
190
 
163
        model.addAttribute("state", state);
191
        model.addAttribute("state", state);
164
        model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
192
        model.addAttribute("warehouseMap", this.activePhysicalWarehouses());
165
 
193
 
166
        return "new-supplier";
194
        return "new-supplier";
167
    }
195
    }
168
 
196
 
169
    @RequestMapping(value = "/setStatusInActive", method = RequestMethod.POST)
197
    @RequestMapping(value = "/setStatusInActive", method = RequestMethod.POST)
Line 209... Line 237...
209
        supplier.setPan(createNewSupplier.getPan());
237
        supplier.setPan(createNewSupplier.getPan());
210
        supplier.setPhone(createNewSupplier.getPhone());
238
        supplier.setPhone(createNewSupplier.getPhone());
211
        supplier.setPoValidityLimit(createNewSupplier.getpOValidityLimit());
239
        supplier.setPoValidityLimit(createNewSupplier.getpOValidityLimit());
212
        supplier.setRegisteredAddress(createNewSupplier.getRegisteredAddress());
240
        supplier.setRegisteredAddress(createNewSupplier.getRegisteredAddress());
213
        supplierStateResolver.applyGstinAndState(supplier, createNewSupplier.getGst(), createNewSupplier.getState());
241
        supplierStateResolver.applyGstinAndState(supplier, createNewSupplier.getGst(), createNewSupplier.getState());
214
        supplier.setInternalWarehouseId(createNewSupplier.getInternalWarehouseId());
242
        this.applyInternalWarehouse(supplier, createNewSupplier.getInternalWarehouseId());
215
        supplierRepository.persist(supplier);
243
        supplierRepository.persist(supplier);
216
 
244
 
217
        Vendor vendor = new Vendor();
245
        Vendor vendor = new Vendor();
218
        vendor.setName(supplier.getName());
246
        vendor.setName(supplier.getName());
219
        vendor.setId(supplier.getId());
247
        vendor.setId(supplier.getId());
Line 251... Line 279...
251
    }
279
    }
252
 
280
 
253
    @RequestMapping(value = "/supplier/edit/{supplierId}", method = RequestMethod.GET)
281
    @RequestMapping(value = "/supplier/edit/{supplierId}", method = RequestMethod.GET)
254
    public String getEditSupplier(HttpServletRequest request, Model model, @PathVariable int supplierId) throws Exception {
282
    public String getEditSupplier(HttpServletRequest request, Model model, @PathVariable int supplierId) throws Exception {
255
        Supplier supplier  = supplierRepository.selectById(supplierId);
283
        Supplier supplier  = supplierRepository.selectById(supplierId);
256
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();
284
        List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll().stream()
-
 
285
                .filter(SellerWarehouse::isActive).collect(Collectors.toList());
257
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
286
        Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
258
 
287
 
259
        List<Warehouse> supplierWarehouses = warehouseRepository.selectVendorWarehouses(supplierId, WarehouseType.OURS, InventoryType.GOOD);
288
        List<Warehouse> supplierWarehouses = warehouseRepository.selectVendorWarehouses(supplierId, WarehouseType.OURS, InventoryType.GOOD);
260
        List<Integer> supplierPhysicalWarehouseIds = supplierWarehouses.stream().map(x -> x.getShippingWarehouseId()).collect(Collectors.toList());
289
        List<Integer> supplierPhysicalWarehouseIds = supplierWarehouses.stream().map(x -> x.getShippingWarehouseId()).collect(Collectors.toList());
261
        LOGGER.info("supplierPhysicalWarehouseIds" + supplierPhysicalWarehouseIds);
290
        LOGGER.info("supplierPhysicalWarehouseIds" + supplierPhysicalWarehouseIds);
Line 274... Line 303...
274
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
303
        model.addAttribute("warehouseIdAndState", warehouseIdAndState);
275
 
304
 
276
        List<State> state = stateRepository.selectAll();
305
        List<State> state = stateRepository.selectAll();
277
 
306
 
278
        model.addAttribute("state", state);
307
        model.addAttribute("state", state);
279
        model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);
308
        model.addAttribute("warehouseMap", this.activePhysicalWarehouses());
280
        model.addAttribute("supplier", supplier);
309
        model.addAttribute("supplier", supplier);
281
        model.addAttribute("supplierPhysicalWarehouseIds", supplierPhysicalWarehouseIds);
310
        model.addAttribute("supplierPhysicalWarehouseIds", supplierPhysicalWarehouseIds);
282
        return "edit-supplier";
311
        return "edit-supplier";
283
    }
312
    }
284
 
313
 
Line 300... Line 329...
300
        supplier.setContactEmail(supplierFormData.getInputContactEmail());
329
        supplier.setContactEmail(supplierFormData.getInputContactEmail());
301
        supplier.setFax((supplierFormData.getInputFax()));
330
        supplier.setFax((supplierFormData.getInputFax()));
302
        supplier.setRegisteredAddress(supplierFormData.getInputRegisteredAddress());
331
        supplier.setRegisteredAddress(supplierFormData.getInputRegisteredAddress());
303
        supplier.setCommunicationAddress(supplierFormData.getInputCommunicationAddress());
332
        supplier.setCommunicationAddress(supplierFormData.getInputCommunicationAddress());
304
        supplier.setTnc(supplierFormData.getInputTermConditions());
333
        supplier.setTnc(supplierFormData.getInputTermConditions());
305
        supplier.setInternalWarehouseId(supplierFormData.getInternalWarehouseId());
334
        this.applyInternalWarehouse(supplier, supplierFormData.getInternalWarehouseId());
306
        if (supplierFormData.getInternalWarehouseId() != null && supplierFormData.getInternalWarehouseId() > 0) {
-
 
307
            supplier.setInternal(true);
-
 
308
        } else {
-
 
309
            supplier.setInternal(false);
-
 
310
            supplier.setInternalWarehouseId(null);
-
 
311
        }
-
 
312
        supplierStateResolver.applyGstinAndState(supplier, supplierFormData.getInputGst(), supplierFormData.getStateId());
335
        supplierStateResolver.applyGstinAndState(supplier, supplierFormData.getInputGst(), supplierFormData.getStateId());
313
        supplier.setPoValidityLimit(supplierFormData.getInputPOValidityLimit());
336
        supplier.setPoValidityLimit(supplierFormData.getInputPOValidityLimit());
314
 
337
 
315
        List<Integer> newWarehouseIds = supplierFormData.getInputWarehouseLocation();
338
        List<Integer> newWarehouseIds = supplierFormData.getInputWarehouseLocation();
316
 
339