Rev 32539 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.dao.entity.inventory.State;import com.spice.profitmandi.dao.entity.inventory.Vendor;import com.spice.profitmandi.dao.entity.transaction.Seller;import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMapping;import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMaster;import com.spice.profitmandi.dao.entity.warehouse.Supplier;import com.spice.profitmandi.dao.enumuration.inventory.InventoryType;import com.spice.profitmandi.dao.enumuration.inventory.WarehouseType;import com.spice.profitmandi.dao.hrms.CreateNewSupplier;import com.spice.profitmandi.dao.hrms.WarehouseIdPrefixModel;import com.spice.profitmandi.dao.repository.inventory.StateRepository;import com.spice.profitmandi.dao.repository.inventory.VendorRepository;import com.spice.profitmandi.dao.repository.transaction.SellerRepository;import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMappingRepository;import com.spice.profitmandi.dao.repository.transaction.WarehouseAddressMasterRepository;import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;import com.spice.profitmandi.service.warehouse.WarehouseService;import com.spice.profitmandi.web.util.MVCResponseSender;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.transaction.annotation.Transactional;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.*;import javax.servlet.http.HttpServletRequest;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.stream.Collectors;@Controller@Transactional(rollbackFor = Throwable.class)public class SupplierController {@Autowiredprivate SupplierRepository supplierRepository;@Autowiredprivate MVCResponseSender mvcResponseSender;@Autowiredprivate SellerRepository sellerRepository;@Autowiredprivate WarehouseService warehouseService;@Autowiredprivate SellerWarehouseRepository sellerWarehouseRepository;@Autowiredprivate VendorRepository vendorRepository;@Autowiredprivate WarehouseAddressMappingRepository warehouseAddressMappingRepository;@Autowiredprivate WarehouseAddressMasterRepository warehouseAddressMasterRepository;@Autowiredprivate StateRepository stateRepository;private static final Logger LOGGER = LogManager.getLogger(SupplierController.class);@RequestMapping(value = "/getAllSupplier", method = RequestMethod.GET)public String getShowSupplier(HttpServletRequest request, Model model) throws Exception {List<Supplier> supplierAcvtives = supplierRepository.selectByStatus(true);List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();List<Integer> sellerwarehouseIds = sellerWarehouses.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());LOGGER.info("sellerWarehouses" + sellerWarehouses);Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();for (SellerWarehouse sw : sellerWarehouses) {WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sw.getWarehouseId());LOGGER.info("warehouseAddressMapping" + warehouseAddressMapping);if (warehouseAddressMapping != null) {WarehouseAddressMaster WarehouseAddressMaster = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());LOGGER.info("warehouseAddressMappingAddreesId" + warehouseAddressMapping.getAddressId());LOGGER.info("WarehouseAddressMaster" + WarehouseAddressMaster);State state = stateRepository.selectById(WarehouseAddressMaster.getStateId());WarehouseIdPrefixModel wp = new WarehouseIdPrefixModel();wp.setPrefix(sw.getPrefix());wp.setStateName(state.getName());warehouseIdAndState.put(sw.getWarehouseId(), wp);LOGGER.info("state" + state);}}LOGGER.info("warehouseIdAndState" + warehouseIdAndState);model.addAttribute("warehouseIdAndState", warehouseIdAndState);List<State> state = stateRepository.selectAll();model.addAttribute("suppliers", supplierAcvtives);model.addAttribute("state", state);return "supplier";}@RequestMapping(value = "/getAllInActiveSupplier", method = RequestMethod.GET)public String getShowInActiveSupplier(HttpServletRequest request, Model model) throws Exception {List<Supplier> supplierInactives = supplierRepository.selectByStatus(false);model.addAttribute("supplierInactives", supplierInactives);LOGGER.info("supplierInactives" + supplierInactives);return "supplier-in-active";}/*@RequestMapping(value = "/supplier/edit/{supplierId}", method = RequestMethod.GET)public String getEditSupplier(HttpServletRequest request, Model model, @PathVariable int supplierId) throws Exception {Supplier supplier = supplierRepository.selectById(supplierId);List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();List<Integer> sellerwarehouseIds = sellerWarehouses.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());LOGGER.info("sellerWarehouses" + sellerWarehouses);Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();for (SellerWarehouse sw : sellerWarehouses) {WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sw.getWarehouseId());LOGGER.info("warehouseAddressMapping" + warehouseAddressMapping);if (warehouseAddressMapping != null) {WarehouseAddressMaster WarehouseAddressMaster = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());LOGGER.info("warehouseAddressMappingAddreesId" + warehouseAddressMapping.getAddressId());LOGGER.info("WarehouseAddressMaster" + WarehouseAddressMaster);State state = stateRepository.selectById(WarehouseAddressMaster.getStateId());WarehouseIdPrefixModel wp = new WarehouseIdPrefixModel();wp.setPrefix(sw.getPrefix());wp.setStateName(state.getName());warehouseIdAndState.put(sw.getWarehouseId(), wp);LOGGER.info("state" + state);}}LOGGER.info("warehouseIdAndState" + warehouseIdAndState);model.addAttribute("warehouseIdAndState", warehouseIdAndState);List<State> state = stateRepository.selectAll();model.addAttribute("state", state);model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);model.addAttribute("supplier", supplier);return "edit-supplier";}*/@RequestMapping(value = "/getCreateNewSupplier", method = RequestMethod.GET)public String getCreateNewSupplier(HttpServletRequest request, Model model) throws Exception {List<SellerWarehouse> sellerWarehouses = sellerWarehouseRepository.selectAll();Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;sellerWarehouses = sellerWarehouses.stream().filter(x -> warehouseMap.containsKey(x.getWarehouseId())).collect(Collectors.toList());Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();for (SellerWarehouse sw : sellerWarehouses) {WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sw.getWarehouseId());LOGGER.info("warehouseAddressMapping" + warehouseAddressMapping);if (warehouseAddressMapping != null) {WarehouseAddressMaster WarehouseAddressMaster = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());LOGGER.info("warehouseAddressMappingAddreesId" + warehouseAddressMapping.getAddressId());LOGGER.info("WarehouseAddressMaster" + WarehouseAddressMaster);State state = stateRepository.selectById(WarehouseAddressMaster.getStateId());WarehouseIdPrefixModel wp = new WarehouseIdPrefixModel();wp.setPrefix(sw.getPrefix());wp.setStateName(state.getName());warehouseIdAndState.put(sw.getWarehouseId(), wp);LOGGER.info("state" + state);}}LOGGER.info("warehouseIdAndState" + warehouseIdAndState);model.addAttribute("warehouseIdAndState", warehouseIdAndState);List<State> state = stateRepository.selectAll();model.addAttribute("state", state);model.addAttribute("warehouseMap", ProfitMandiConstants.WAREHOUSE_MAP);return "new-supplier";}@RequestMapping(value = "/setStatusInActive", method = RequestMethod.POST)public String setInActiveSupplier(HttpServletRequest request, @RequestParam(name = "id", required = true, defaultValue = "0") int id, Model model) throws Exception {Supplier supplier = supplierRepository.selectById(id);supplier.setStatus(false);model.addAttribute("response1", mvcResponseSender.createResponseString(true));return "response";}@RequestMapping(value = "/setStatusActive", method = RequestMethod.POST)public String setActiveSupplier(HttpServletRequest request, @RequestParam(name = "id", required = true, defaultValue = "0") int id, Model model) throws Exception {Supplier supplier = supplierRepository.selectById(id);supplier.setStatus(true);model.addAttribute("response1", mvcResponseSender.createResponseString(true));return "response";}@RequestMapping(value = "/submitNewSupplier", method = RequestMethod.POST)public String getCreateNewSupplier(HttpServletRequest request, @RequestBody CreateNewSupplier createNewSupplier, Model model) throws Exception {Supplier supplier = new Supplier();supplier.setName(createNewSupplier.getName());supplier.setCommunicationAddress(createNewSupplier.getCommunicationAddress());supplier.setContactEmail(createNewSupplier.getContactEmail());supplier.setContactFax(createNewSupplier.getContactFax());supplier.setContactName(createNewSupplier.getContactPerson());supplier.setContactPhone(createNewSupplier.getContactPhone());supplier.setGstin(createNewSupplier.getGst());supplier.setHeadDesignation(createNewSupplier.getHeadDesign());supplier.setHeadEmail(createNewSupplier.getHeadEmail());supplier.setHeadName(createNewSupplier.getHeadName());supplier.setPan(createNewSupplier.getPan());supplier.setPhone(createNewSupplier.getPhone());supplier.setPoValidityLimit(createNewSupplier.getpOValidityLimit());supplier.setRegisteredAddress(createNewSupplier.getRegisteredAddress());supplier.setStateId(createNewSupplier.getState());supplier.setInternalWarehouseId(createNewSupplier.getInternalWarehouseId());supplierRepository.persist(supplier);Vendor vendor = new Vendor();vendor.setName(supplier.getName());vendor.setId(supplier.getId());vendorRepository.persist(vendor);LOGGER.info("supplierId" + supplier.getId());LOGGER.info("vendorId" + vendor.getId());List<WarehouseAddressMapping> warehouseAddressMappings = warehouseAddressMappingRepository.selectAllByIds(createNewSupplier.getWarehouseId());LOGGER.info("warehouseAddressMappings" + warehouseAddressMappings);for (WarehouseAddressMapping wamp : warehouseAddressMappings) {List<SellerWarehouse> sellerWarehouse = sellerWarehouseRepository.selectBywarehouseId(wamp.getWarehouseId());for (SellerWarehouse sw : sellerWarehouse) {Seller seller = sellerRepository.selectById(sw.getSellerId());WarehouseAddressMaster wam = warehouseAddressMasterRepository.selectById(wamp.getAddressId());// GOOD - WarehouseType.OURS, InventoryType.GOODwarehouseService.createVendorWarehouse(WarehouseType.OURS, InventoryType.GOOD, seller.getLabel(), wamp.getWarehouseId(), wam, vendor.getId());// BAD - WarehouseType.OURS, InventoryType.BADwarehouseService.createVendorWarehouse(WarehouseType.OURS, InventoryType.BAD, seller.getLabel(), wamp.getWarehouseId(), wam, vendor.getId());// VIRTUAL - WarehouseType.THIRD_PARTY, InventoryType.GOODwarehouseService.createVendorWarehouse(WarehouseType.THIRD_PARTY, InventoryType.GOOD, seller.getLabel(), wamp.getWarehouseId(), wam, vendor.getId());}}//model.addAttribute("response1", mvcResponseSender.createResponseString(true));return getShowInActiveSupplier(request, model);}}