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