| 28300 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 28493 |
tejbeer |
3 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
|
|
4 |
import com.spice.profitmandi.dao.entity.inventory.Vendor;
|
| 31238 |
amit.gupta |
5 |
import com.spice.profitmandi.dao.entity.transaction.Seller;
|
|
|
6 |
import com.spice.profitmandi.dao.entity.transaction.SellerWarehouse;
|
|
|
7 |
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMapping;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.transaction.WarehouseAddressMaster;
|
| 28300 |
tejbeer |
9 |
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
|
| 28493 |
tejbeer |
10 |
import com.spice.profitmandi.dao.enumuration.inventory.InventoryType;
|
|
|
11 |
import com.spice.profitmandi.dao.enumuration.inventory.WarehouseType;
|
|
|
12 |
import com.spice.profitmandi.dao.hrms.CreateNewSupplier;
|
|
|
13 |
import com.spice.profitmandi.dao.hrms.WarehouseIdPrefixModel;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
|
|
15 |
import com.spice.profitmandi.dao.repository.inventory.VendorRepository;
|
|
|
16 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.transaction.SellerRepository;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.transaction.SellerWarehouseRepository;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.transaction.WareHouseAddressMappingRepository;
|
| 31238 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.repository.transaction.WareHouseAddressMasterRepository;
|
| 28300 |
tejbeer |
21 |
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
|
| 28493 |
tejbeer |
22 |
import com.spice.profitmandi.service.warehouse.WarehouseService;
|
| 28300 |
tejbeer |
23 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 31238 |
amit.gupta |
24 |
import org.apache.logging.log4j.LogManager;
|
|
|
25 |
import org.apache.logging.log4j.Logger;
|
|
|
26 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
27 |
import org.springframework.stereotype.Controller;
|
|
|
28 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
29 |
import org.springframework.ui.Model;
|
|
|
30 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 28300 |
tejbeer |
34 |
|
| 31238 |
amit.gupta |
35 |
import javax.servlet.http.HttpServletRequest;
|
|
|
36 |
import java.util.HashMap;
|
|
|
37 |
import java.util.List;
|
|
|
38 |
import java.util.Map;
|
|
|
39 |
import java.util.stream.Collectors;
|
| 28493 |
tejbeer |
40 |
|
| 28300 |
tejbeer |
41 |
@Controller
|
|
|
42 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
43 |
public class SupplierController {
|
| 28493 |
tejbeer |
44 |
|
| 28300 |
tejbeer |
45 |
@Autowired
|
|
|
46 |
private SupplierRepository supplierRepository;
|
|
|
47 |
|
|
|
48 |
@Autowired
|
|
|
49 |
private MVCResponseSender mvcResponseSender;
|
| 28493 |
tejbeer |
50 |
@Autowired
|
|
|
51 |
private WarehouseRepository warehouseRepository;
|
| 28300 |
tejbeer |
52 |
|
| 28493 |
tejbeer |
53 |
@Autowired
|
|
|
54 |
private SellerRepository sellerRepository;
|
|
|
55 |
|
|
|
56 |
@Autowired
|
|
|
57 |
private WarehouseService warehouseService;
|
|
|
58 |
|
|
|
59 |
@Autowired
|
|
|
60 |
private SellerWarehouseRepository sellerWarehouseRepository;
|
|
|
61 |
|
|
|
62 |
@Autowired
|
|
|
63 |
private VendorRepository vendorRepository;
|
|
|
64 |
|
|
|
65 |
@Autowired
|
|
|
66 |
private WareHouseAddressMappingRepository wareHouseAddressMappingRepository;
|
|
|
67 |
|
|
|
68 |
@Autowired
|
|
|
69 |
private WareHouseAddressMasterRepository WareHouseAddressMasterRepository;
|
|
|
70 |
|
|
|
71 |
@Autowired
|
|
|
72 |
private StateRepository stateRepository;
|
|
|
73 |
|
|
|
74 |
private static final Logger LOGGER = LogManager.getLogger(SupplierController.class);
|
|
|
75 |
|
| 28300 |
tejbeer |
76 |
@RequestMapping(value = "/getAllSupplier", method = RequestMethod.GET)
|
| 28493 |
tejbeer |
77 |
public String getShowSupplier(HttpServletRequest request, Model model) throws Exception {
|
|
|
78 |
|
|
|
79 |
List<Supplier> supplierAcvtives = supplierRepository.selectByStatus(true);
|
|
|
80 |
|
|
|
81 |
List<SellerWarehouse> sellerWarehouses = supplierRepository.selectAll();
|
|
|
82 |
List<Integer> sellerwarehouseIds = sellerWarehouses.stream().map(x -> x.getWarehouseId())
|
|
|
83 |
.collect(Collectors.toList());
|
|
|
84 |
LOGGER.info("sellerWarehouses" + sellerWarehouses);
|
|
|
85 |
Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
|
|
|
86 |
|
|
|
87 |
for (SellerWarehouse sw : sellerWarehouses) {
|
|
|
88 |
|
|
|
89 |
WarehouseAddressMapping warehouseAddressMapping = wareHouseAddressMappingRepository
|
|
|
90 |
.selectByWarehouseId(sw.getWarehouseId());
|
|
|
91 |
LOGGER.info("warehouseAddressMapping" + warehouseAddressMapping);
|
|
|
92 |
if (warehouseAddressMapping != null) {
|
|
|
93 |
WarehouseAddressMaster WarehouseAddressMaster = WareHouseAddressMasterRepository
|
| 29511 |
amit.gupta |
94 |
.selectById(warehouseAddressMapping.getAddressId());
|
| 28493 |
tejbeer |
95 |
LOGGER.info("warehouseAddressMappingAddreesId" + warehouseAddressMapping.getAddressId());
|
|
|
96 |
LOGGER.info("WarehouseAddressMaster" + WarehouseAddressMaster);
|
|
|
97 |
State state = stateRepository.selectById(WarehouseAddressMaster.getStateId());
|
|
|
98 |
WarehouseIdPrefixModel wp = new WarehouseIdPrefixModel();
|
|
|
99 |
wp.setPrefix(sw.getPrefix());
|
|
|
100 |
wp.setStateName(state.getName());
|
|
|
101 |
warehouseIdAndState.put(sw.getWarehouseId(), wp);
|
|
|
102 |
LOGGER.info("state" + state);
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
LOGGER.info("warehouseIdAndState" + warehouseIdAndState);
|
|
|
106 |
model.addAttribute("warehouseIdAndState", warehouseIdAndState);
|
|
|
107 |
|
|
|
108 |
List<State> state = supplierRepository.selectByIdStateMaster();
|
|
|
109 |
|
| 28300 |
tejbeer |
110 |
model.addAttribute("suppliers", supplierAcvtives);
|
| 28493 |
tejbeer |
111 |
model.addAttribute("state", state);
|
|
|
112 |
|
| 28300 |
tejbeer |
113 |
return "supplier";
|
|
|
114 |
|
|
|
115 |
}
|
| 28493 |
tejbeer |
116 |
|
| 28300 |
tejbeer |
117 |
@RequestMapping(value = "/getAllInActiveSupplier", method = RequestMethod.GET)
|
| 28493 |
tejbeer |
118 |
public String getShowInActiveSupplier(HttpServletRequest request, Model model) throws Exception {
|
|
|
119 |
|
|
|
120 |
List<Supplier> supplierInactives = supplierRepository.selectByStatus(false);
|
|
|
121 |
|
| 28300 |
tejbeer |
122 |
model.addAttribute("supplierInactives", supplierInactives);
|
| 28493 |
tejbeer |
123 |
|
|
|
124 |
LOGGER.info("supplierInactives" + supplierInactives);
|
|
|
125 |
|
| 28300 |
tejbeer |
126 |
return "supplier-in-active";
|
|
|
127 |
|
|
|
128 |
}
|
|
|
129 |
|
| 28493 |
tejbeer |
130 |
@RequestMapping(value = "/getCreateNewSupplier", method = RequestMethod.GET)
|
|
|
131 |
public String getCreateNewSupplier(HttpServletRequest request, Model model) throws Exception {
|
|
|
132 |
|
|
|
133 |
List<SellerWarehouse> sellerWarehouses = supplierRepository.selectAll();
|
|
|
134 |
List<Integer> sellerwarehouseIds = sellerWarehouses.stream().map(x -> x.getWarehouseId())
|
|
|
135 |
.collect(Collectors.toList());
|
|
|
136 |
LOGGER.info("sellerWarehouses" + sellerWarehouses);
|
|
|
137 |
Map<Integer, WarehouseIdPrefixModel> warehouseIdAndState = new HashMap<>();
|
|
|
138 |
|
|
|
139 |
for (SellerWarehouse sw : sellerWarehouses) {
|
|
|
140 |
|
|
|
141 |
WarehouseAddressMapping warehouseAddressMapping = wareHouseAddressMappingRepository
|
|
|
142 |
.selectByWarehouseId(sw.getWarehouseId());
|
|
|
143 |
LOGGER.info("warehouseAddressMapping" + warehouseAddressMapping);
|
|
|
144 |
if (warehouseAddressMapping != null) {
|
|
|
145 |
WarehouseAddressMaster WarehouseAddressMaster = WareHouseAddressMasterRepository
|
| 29511 |
amit.gupta |
146 |
.selectById(warehouseAddressMapping.getAddressId());
|
| 28493 |
tejbeer |
147 |
LOGGER.info("warehouseAddressMappingAddreesId" + warehouseAddressMapping.getAddressId());
|
|
|
148 |
LOGGER.info("WarehouseAddressMaster" + WarehouseAddressMaster);
|
|
|
149 |
State state = stateRepository.selectById(WarehouseAddressMaster.getStateId());
|
|
|
150 |
WarehouseIdPrefixModel wp = new WarehouseIdPrefixModel();
|
|
|
151 |
wp.setPrefix(sw.getPrefix());
|
|
|
152 |
wp.setStateName(state.getName());
|
|
|
153 |
warehouseIdAndState.put(sw.getWarehouseId(), wp);
|
|
|
154 |
LOGGER.info("state" + state);
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
LOGGER.info("warehouseIdAndState" + warehouseIdAndState);
|
|
|
158 |
model.addAttribute("warehouseIdAndState", warehouseIdAndState);
|
|
|
159 |
|
|
|
160 |
List<State> state = supplierRepository.selectByIdStateMaster();
|
|
|
161 |
|
|
|
162 |
model.addAttribute("state", state);
|
|
|
163 |
|
|
|
164 |
return "new-supplier";
|
|
|
165 |
}
|
|
|
166 |
|
| 28300 |
tejbeer |
167 |
@RequestMapping(value = "/setStatusInActive", method = RequestMethod.POST)
|
|
|
168 |
public String setInActiveSupplier(HttpServletRequest request,
|
| 28493 |
tejbeer |
169 |
@RequestParam(name = "id", required = true, defaultValue = "0") int id, Model model) throws Exception {
|
|
|
170 |
|
|
|
171 |
Supplier supplier = supplierRepository.selectById(id);
|
|
|
172 |
|
| 28300 |
tejbeer |
173 |
supplier.setStatus(false);
|
| 28493 |
tejbeer |
174 |
|
| 31238 |
amit.gupta |
175 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 28493 |
tejbeer |
176 |
|
| 28300 |
tejbeer |
177 |
return "response";
|
|
|
178 |
}
|
| 28493 |
tejbeer |
179 |
|
|
|
180 |
@RequestMapping(value = "/setStatusActive", method = RequestMethod.POST)
|
|
|
181 |
public String setActiveSupplier(HttpServletRequest request,
|
|
|
182 |
@RequestParam(name = "id", required = true, defaultValue = "0") int id, Model model) throws Exception {
|
|
|
183 |
|
|
|
184 |
Supplier supplier = supplierRepository.selectById(id);
|
|
|
185 |
|
|
|
186 |
supplier.setStatus(true);
|
|
|
187 |
|
| 31238 |
amit.gupta |
188 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 28493 |
tejbeer |
189 |
|
|
|
190 |
return "response";
|
|
|
191 |
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
@RequestMapping(value = "/submitNewSupplier", method = RequestMethod.POST)
|
|
|
195 |
public String getCreateNewSupplier(HttpServletRequest request, @RequestBody CreateNewSupplier createNewSupplier,
|
|
|
196 |
Model model) throws Exception {
|
|
|
197 |
|
|
|
198 |
Supplier supplier = new Supplier();
|
|
|
199 |
|
|
|
200 |
supplier.setName(createNewSupplier.getName());
|
|
|
201 |
supplier.setCommunicationAddress(createNewSupplier.getCommunicationAddress());
|
|
|
202 |
supplier.setContactEmail(createNewSupplier.getContactEmail());
|
|
|
203 |
supplier.setContactFax(createNewSupplier.getContactFax());
|
|
|
204 |
supplier.setContactName(createNewSupplier.getContactPerson());
|
|
|
205 |
supplier.setGstin(createNewSupplier.getGst());
|
|
|
206 |
supplier.setHeadDesignation(createNewSupplier.getHeadDesign());
|
|
|
207 |
supplier.setHeadEmail(createNewSupplier.getHeadEmail());
|
|
|
208 |
supplier.setHeadName(createNewSupplier.getHeadName());
|
|
|
209 |
supplier.setPan(createNewSupplier.getPan());
|
|
|
210 |
supplier.setPhone(createNewSupplier.getPhone());
|
|
|
211 |
supplier.setPoValidityLimit(createNewSupplier.getpOValidityLimit());
|
|
|
212 |
supplier.setRegisteredAddress(createNewSupplier.getRegisteredAddress());
|
|
|
213 |
supplier.setStateId(createNewSupplier.getState());
|
|
|
214 |
supplierRepository.persist(supplier);
|
|
|
215 |
|
|
|
216 |
Vendor vendor = new Vendor();
|
|
|
217 |
vendor.setName(supplier.getName());
|
|
|
218 |
vendor.setId(supplier.getId());
|
|
|
219 |
vendorRepository.persist(vendor);
|
|
|
220 |
LOGGER.info("supplierId" + supplier.getId());
|
|
|
221 |
LOGGER.info("vendorId" + vendor.getId());
|
|
|
222 |
|
|
|
223 |
List<WarehouseAddressMapping> warehouseAddressMappings = wareHouseAddressMappingRepository
|
|
|
224 |
.selectAllByIds(createNewSupplier.getWarehouseId());
|
|
|
225 |
LOGGER.info("warehouseAddressMappings" + warehouseAddressMappings);
|
|
|
226 |
|
|
|
227 |
for (WarehouseAddressMapping wamp : warehouseAddressMappings) {
|
|
|
228 |
List<SellerWarehouse> sellerWarehouse = sellerWarehouseRepository
|
|
|
229 |
.selectBywarehouseId(wamp.getWarehouseId());
|
|
|
230 |
for (SellerWarehouse sw : sellerWarehouse) {
|
| 28989 |
amit.gupta |
231 |
Seller seller = sellerRepository.selectById(sw.getSellerId());
|
| 28493 |
tejbeer |
232 |
|
| 29511 |
amit.gupta |
233 |
WarehouseAddressMaster wam = WareHouseAddressMasterRepository.selectById(wamp.getAddressId());
|
| 28493 |
tejbeer |
234 |
|
|
|
235 |
// GOOD - WarehouseType.OURS, InventoryType.GOOD
|
|
|
236 |
warehouseService.createVendorWarehouse(WarehouseType.OURS, InventoryType.GOOD, seller.getLabel(),
|
|
|
237 |
wamp.getWarehouseId(), wam, vendor.getId());
|
|
|
238 |
|
|
|
239 |
// BAD - WarehouseType.OURS, InventoryType.BAD
|
|
|
240 |
warehouseService.createVendorWarehouse(WarehouseType.OURS, InventoryType.BAD, seller.getLabel(),
|
|
|
241 |
wamp.getWarehouseId(), wam, vendor.getId());
|
|
|
242 |
|
|
|
243 |
// VIRTUAL - WarehouseType.THIRD_PARTY, InventoryType.GOOD
|
|
|
244 |
warehouseService.createVendorWarehouse(WarehouseType.THIRD_PARTY, InventoryType.GOOD, seller.getLabel(),
|
|
|
245 |
wamp.getWarehouseId(), wam, 0);
|
|
|
246 |
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
return "new-supplier";
|
|
|
252 |
|
|
|
253 |
}
|
| 28300 |
tejbeer |
254 |
}
|