| 5591 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.inventory.controllers;
|
|
|
5 |
|
| 21873 |
amit.gupta |
6 |
import in.shop2020.inventory.utils.Utils;
|
| 5945 |
mandeep.dh |
7 |
import in.shop2020.model.v1.inventory.BillingType;
|
|
|
8 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
9 |
import in.shop2020.model.v1.inventory.Vendor;
|
|
|
10 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
11 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
| 5591 |
mandeep.dh |
12 |
import in.shop2020.purchase.PurchaseService.Client;
|
|
|
13 |
import in.shop2020.purchase.Supplier;
|
| 5945 |
mandeep.dh |
14 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 5591 |
mandeep.dh |
15 |
import in.shop2020.thrift.clients.PurchaseClient;
|
|
|
16 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
17 |
|
|
|
18 |
import java.util.List;
|
|
|
19 |
|
|
|
20 |
import org.apache.commons.lang.StringUtils;
|
|
|
21 |
import org.apache.commons.logging.Log;
|
|
|
22 |
import org.apache.commons.logging.LogFactory;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* @author mandeep
|
|
|
26 |
*
|
|
|
27 |
*/
|
|
|
28 |
public class SupplierController extends BaseController {
|
|
|
29 |
private static Log logger = LogFactory.getLog(SupplierController.class);
|
|
|
30 |
private String name;
|
|
|
31 |
private String phone;
|
|
|
32 |
private String fax;
|
| 21844 |
amit.gupta |
33 |
private String gstin;
|
|
|
34 |
public String getGstin() {
|
|
|
35 |
return gstin;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public void setGstin(String gstin) {
|
|
|
39 |
this.gstin = gstin;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
private String pan;
|
| 5591 |
mandeep.dh |
43 |
private String headName;
|
|
|
44 |
private String headDesignation;
|
|
|
45 |
private String headEmail;
|
|
|
46 |
private String contactName;
|
|
|
47 |
private String contactPhone;
|
|
|
48 |
private String contactFax;
|
|
|
49 |
private String contactEmail;
|
|
|
50 |
private String registeredAddress;
|
| 10295 |
amar.kumar |
51 |
private long stateId;
|
| 14090 |
manish.sha |
52 |
private String stateIdVal;
|
| 14072 |
manish.sha |
53 |
private long poValidityLimit;
|
| 5591 |
mandeep.dh |
54 |
private String communicationAddress;
|
| 7410 |
amar.kumar |
55 |
private List<Long> billingWarehouseIds;
|
| 23081 |
amit.gupta |
56 |
private String tnc;
|
| 5591 |
mandeep.dh |
57 |
|
|
|
58 |
private String id;
|
|
|
59 |
private List<Supplier> suppliers;
|
|
|
60 |
private String errorMessage = "";
|
|
|
61 |
private Supplier supplier;
|
|
|
62 |
|
|
|
63 |
public String index() {
|
|
|
64 |
return INDEX;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/* (non-Javadoc)
|
|
|
68 |
* @see in.shop2020.inventory.controllers.BaseController#edit()
|
|
|
69 |
*/
|
|
|
70 |
@Override
|
|
|
71 |
public String edit() {
|
|
|
72 |
try {
|
|
|
73 |
Client purchaseClient = new PurchaseClient().getClient();
|
|
|
74 |
supplier = purchaseClient.getSupplier(Long.valueOf(id));
|
|
|
75 |
} catch (Exception e) {
|
|
|
76 |
errorMessage = "Error finding supplier: " + id + ": " + e.getMessage();
|
|
|
77 |
logger.error("Could not find supplier: " + id, e);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
return super.edit();
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
public String create() {
|
|
|
84 |
try {
|
| 10121 |
manish.sha |
85 |
if(name==null || ("").equalsIgnoreCase(name)){
|
|
|
86 |
throw new Exception("Supplier Name is Mandatory.");
|
|
|
87 |
}
|
|
|
88 |
if((phone==null || ("").equalsIgnoreCase(phone)) && !StringUtils.isNumeric(phone)){
|
|
|
89 |
throw new Exception("Supplier Phone is Mandatory and Should be in digits only");
|
|
|
90 |
}
|
|
|
91 |
if(fax==null || ("").equalsIgnoreCase(fax)){
|
|
|
92 |
throw new Exception("Supplier Fax is Mandatory.");
|
|
|
93 |
}
|
| 21844 |
amit.gupta |
94 |
if(gstin==null || ("").equalsIgnoreCase(gstin)){
|
|
|
95 |
throw new Exception("Supplier GSTIN is Mandatory.");
|
| 10121 |
manish.sha |
96 |
}
|
|
|
97 |
if(pan==null || ("").equalsIgnoreCase(pan)){
|
|
|
98 |
throw new Exception("Supplier PAN is Mandatory.");
|
|
|
99 |
}
|
|
|
100 |
if(headName==null || ("").equalsIgnoreCase(headName)){
|
|
|
101 |
throw new Exception("Supplier Head Name is Mandatory.");
|
|
|
102 |
}
|
|
|
103 |
if(headEmail==null || ("").equalsIgnoreCase(headEmail)){
|
|
|
104 |
throw new Exception("Supplier Head Email is Mandatory.");
|
|
|
105 |
}
|
|
|
106 |
if(contactName==null || ("").equalsIgnoreCase(contactName)){
|
|
|
107 |
throw new Exception("Supplier Contact Name is Mandatory.");
|
|
|
108 |
}
|
|
|
109 |
if(contactFax==null || ("").equalsIgnoreCase(contactFax)){
|
|
|
110 |
throw new Exception("Supplier Name is Mandatory.");
|
|
|
111 |
}
|
|
|
112 |
if(contactPhone==null || ("").equalsIgnoreCase(contactPhone)){
|
|
|
113 |
throw new Exception("Supplier Contact Phone is Mandatory.");
|
|
|
114 |
}
|
|
|
115 |
if(registeredAddress==null || ("").equalsIgnoreCase(registeredAddress)){
|
|
|
116 |
throw new Exception("Supplier Registered Address is Mandatory.");
|
|
|
117 |
}
|
|
|
118 |
if(communicationAddress==null || ("").equalsIgnoreCase(communicationAddress)){
|
|
|
119 |
throw new Exception("Supplier Communication Address is Mandatory.");
|
|
|
120 |
}
|
|
|
121 |
if(billingWarehouseIds==null || billingWarehouseIds.size()==0){
|
|
|
122 |
throw new Exception("Atleast One Billing Warehouse is Mandatory.");
|
|
|
123 |
}
|
| 23081 |
amit.gupta |
124 |
if(billingWarehouseIds==null || billingWarehouseIds.size()==0){
|
|
|
125 |
throw new Exception("Atleast One Billing Warehouse is Mandatory.");
|
|
|
126 |
}
|
| 12361 |
manish.sha |
127 |
if(stateId == -1){
|
|
|
128 |
throw new Exception("State is Mandatory. Please select state");
|
|
|
129 |
}
|
| 14072 |
manish.sha |
130 |
if(poValidityLimit < 1){
|
|
|
131 |
throw new Exception("PO Validity Limit Must be greater than equal to 1.");
|
|
|
132 |
}
|
| 5591 |
mandeep.dh |
133 |
Supplier supplier = new Supplier();
|
| 12629 |
amit.gupta |
134 |
name = name.trim();
|
| 5591 |
mandeep.dh |
135 |
supplier.setName(name);
|
|
|
136 |
supplier.setCommunicationAddress(communicationAddress);
|
|
|
137 |
supplier.setContactEmail(contactEmail);
|
|
|
138 |
supplier.setContactFax(contactFax);
|
|
|
139 |
supplier.setContactName(contactName);
|
|
|
140 |
supplier.setContactPhone(contactPhone);
|
|
|
141 |
supplier.setFax(fax);
|
|
|
142 |
supplier.setHeadDesignation(headDesignation);
|
|
|
143 |
supplier.setHeadEmail(headEmail);
|
|
|
144 |
supplier.setHeadName(headName);
|
|
|
145 |
supplier.setPan(pan);
|
|
|
146 |
supplier.setPhone(phone);
|
|
|
147 |
supplier.setRegisteredAddress(registeredAddress);
|
| 21844 |
amit.gupta |
148 |
//supplier.setTin(tin);
|
|
|
149 |
supplier.setGstin(gstin);
|
| 10295 |
amar.kumar |
150 |
supplier.setStateId(stateId);
|
| 14072 |
manish.sha |
151 |
supplier.setPoValidityLimit(poValidityLimit);
|
| 23081 |
amit.gupta |
152 |
supplier.setTnc(tnc);
|
| 5591 |
mandeep.dh |
153 |
Client purchaseClient = new PurchaseClient().getClient();
|
|
|
154 |
supplier = purchaseClient.addSupplier(supplier);
|
|
|
155 |
|
| 5945 |
mandeep.dh |
156 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient(ConfigClientKeys.inventory_service_server_host.toString(),
|
|
|
157 |
ConfigClientKeys.inventory_service_server_port.toString()).getClient();
|
| 5591 |
mandeep.dh |
158 |
Vendor vendor = new Vendor();
|
|
|
159 |
vendor.setId(supplier.getId());
|
|
|
160 |
vendor.setName(name);
|
| 5945 |
mandeep.dh |
161 |
inventoryClient.addVendor(vendor);
|
| 7410 |
amar.kumar |
162 |
for(Long billingWarehouseId : billingWarehouseIds) {
|
|
|
163 |
Warehouse billingWarehouse = inventoryClient.getWarehouse(billingWarehouseId);
|
|
|
164 |
Warehouse warehouse = new Warehouse();
|
|
|
165 |
warehouse.setVendor(vendor);
|
|
|
166 |
warehouse.setStateId(billingWarehouse.getStateId());
|
|
|
167 |
warehouse.setBillingType(BillingType.OURS);
|
|
|
168 |
warehouse.setBillingWarehouseId(billingWarehouse.getId());
|
|
|
169 |
warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "G"}, '/'));
|
|
|
170 |
warehouse.setInventoryType(InventoryType.GOOD);
|
|
|
171 |
warehouse.setIsAvailabilityMonitored(false);
|
|
|
172 |
warehouse.setLocation(billingWarehouse.getLocation());
|
|
|
173 |
warehouse.setPincode(billingWarehouse.getPincode());
|
|
|
174 |
warehouse.setLogisticsLocation(billingWarehouse.getLogisticsLocation());
|
|
|
175 |
warehouse.setShippingWarehouseId(billingWarehouse.getId());
|
| 21844 |
amit.gupta |
176 |
warehouse.setGstin(gstin);
|
| 7410 |
amar.kumar |
177 |
warehouse.setTransferDelayInHours(0);
|
|
|
178 |
warehouse.setWarehouseType(WarehouseType.OURS);
|
|
|
179 |
inventoryClient.addWarehouse(warehouse);
|
|
|
180 |
|
|
|
181 |
warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "B"}, '/'));
|
|
|
182 |
warehouse.setInventoryType(InventoryType.BAD);
|
|
|
183 |
inventoryClient.addWarehouse(warehouse);
|
|
|
184 |
|
|
|
185 |
warehouse.setWarehouseType(WarehouseType.THIRD_PARTY);
|
|
|
186 |
warehouse.setDisplayName(StringUtils.join(new String[]{name, "G"}, '/'));
|
|
|
187 |
warehouse.setInventoryType(InventoryType.GOOD);
|
|
|
188 |
warehouse.setTransferDelayInHours(24);
|
|
|
189 |
warehouse.setBillingType(null);
|
|
|
190 |
warehouse.setBillingWarehouseId(0);
|
|
|
191 |
warehouse.setShippingWarehouseId(0);
|
|
|
192 |
inventoryClient.addWarehouse(warehouse);
|
| 21873 |
amit.gupta |
193 |
Utils.resetSuppliers();
|
| 7410 |
amar.kumar |
194 |
}
|
| 5591 |
mandeep.dh |
195 |
} catch (Exception e) {
|
|
|
196 |
errorMessage = "Error creating supplier: " + e.getMessage();
|
|
|
197 |
logger.error("Error creating supplier", e);
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
return index();
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public String update() {
|
|
|
204 |
String supplierName = id;
|
|
|
205 |
try {
|
|
|
206 |
Client purchaseClient = new PurchaseClient().getClient();
|
|
|
207 |
Supplier supplier = purchaseClient.getSupplier(Long.valueOf(id));
|
|
|
208 |
supplierName = supplier.getName();
|
|
|
209 |
supplier.setName(name);
|
|
|
210 |
supplier.setCommunicationAddress(communicationAddress);
|
|
|
211 |
supplier.setContactEmail(contactEmail);
|
|
|
212 |
supplier.setContactFax(contactFax);
|
|
|
213 |
supplier.setContactName(contactName);
|
|
|
214 |
supplier.setContactPhone(contactPhone);
|
|
|
215 |
supplier.setFax(fax);
|
|
|
216 |
supplier.setHeadDesignation(headDesignation);
|
|
|
217 |
supplier.setHeadEmail(headEmail);
|
|
|
218 |
supplier.setHeadName(headName);
|
|
|
219 |
supplier.setPan(pan);
|
|
|
220 |
supplier.setRegisteredAddress(registeredAddress);
|
| 21844 |
amit.gupta |
221 |
supplier.setGstin(gstin);
|
| 23081 |
amit.gupta |
222 |
supplier.setTnc(tnc);
|
| 14088 |
manish.sha |
223 |
supplier.setStateId(supplier.getStateId());
|
| 14072 |
manish.sha |
224 |
supplier.setPoValidityLimit(poValidityLimit);
|
| 5591 |
mandeep.dh |
225 |
purchaseClient.updateSupplier(supplier);
|
| 21873 |
amit.gupta |
226 |
Utils.resetSuppliers();
|
| 5591 |
mandeep.dh |
227 |
} catch (Exception e) {
|
|
|
228 |
errorMessage = "Error updating supplier: " + supplierName + ": " + e.getMessage();
|
|
|
229 |
logger.error("Error updating supplier", e);
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
return index();
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
public String getName() {
|
|
|
236 |
return name;
|
|
|
237 |
}
|
|
|
238 |
public void setName(String name) {
|
|
|
239 |
this.name = name;
|
|
|
240 |
}
|
|
|
241 |
public String getPhone() {
|
|
|
242 |
return phone;
|
|
|
243 |
}
|
|
|
244 |
public void setPhone(String phone) {
|
|
|
245 |
this.phone = phone;
|
|
|
246 |
}
|
|
|
247 |
public String getFax() {
|
|
|
248 |
return fax;
|
|
|
249 |
}
|
|
|
250 |
public void setFax(String fax) {
|
|
|
251 |
this.fax = fax;
|
|
|
252 |
}
|
|
|
253 |
public String getPan() {
|
|
|
254 |
return pan;
|
|
|
255 |
}
|
|
|
256 |
public void setPan(String pan) {
|
|
|
257 |
this.pan = pan;
|
|
|
258 |
}
|
|
|
259 |
public String getHeadName() {
|
|
|
260 |
return headName;
|
|
|
261 |
}
|
|
|
262 |
public void setHeadName(String headName) {
|
|
|
263 |
this.headName = headName;
|
|
|
264 |
}
|
|
|
265 |
public String getHeadDesignation() {
|
|
|
266 |
return headDesignation;
|
|
|
267 |
}
|
|
|
268 |
public void setHeadDesignation(String headDesignation) {
|
|
|
269 |
this.headDesignation = headDesignation;
|
|
|
270 |
}
|
|
|
271 |
public String getHeadEmail() {
|
|
|
272 |
return headEmail;
|
|
|
273 |
}
|
|
|
274 |
public void setHeadEmail(String headEmail) {
|
|
|
275 |
this.headEmail = headEmail;
|
|
|
276 |
}
|
|
|
277 |
public String getContactName() {
|
|
|
278 |
return contactName;
|
|
|
279 |
}
|
|
|
280 |
public void setContactName(String contactName) {
|
|
|
281 |
this.contactName = contactName;
|
|
|
282 |
}
|
|
|
283 |
public String getContactPhone() {
|
|
|
284 |
return contactPhone;
|
|
|
285 |
}
|
|
|
286 |
public void setContactPhone(String contactPhone) {
|
|
|
287 |
this.contactPhone = contactPhone;
|
|
|
288 |
}
|
|
|
289 |
public String getContactFax() {
|
|
|
290 |
return contactFax;
|
|
|
291 |
}
|
|
|
292 |
public void setContactFax(String contactFax) {
|
|
|
293 |
this.contactFax = contactFax;
|
|
|
294 |
}
|
|
|
295 |
public String getContactEmail() {
|
|
|
296 |
return contactEmail;
|
|
|
297 |
}
|
|
|
298 |
public void setContactEmail(String contactEmail) {
|
|
|
299 |
this.contactEmail = contactEmail;
|
|
|
300 |
}
|
|
|
301 |
public String getRegisteredAddress() {
|
|
|
302 |
return registeredAddress;
|
|
|
303 |
}
|
|
|
304 |
public void setRegisteredAddress(String registeredAddress) {
|
|
|
305 |
this.registeredAddress = registeredAddress;
|
|
|
306 |
}
|
|
|
307 |
public String getCommunicationAddress() {
|
|
|
308 |
return communicationAddress;
|
|
|
309 |
}
|
|
|
310 |
public void setCommunicationAddress(String communicationAddress) {
|
|
|
311 |
this.communicationAddress = communicationAddress;
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
public String getId() {
|
|
|
315 |
return id;
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
public void setId(String id) {
|
|
|
319 |
this.id = id;
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
public List<Supplier> getSuppliers() {
|
| 21873 |
amit.gupta |
323 |
return Utils.getSuppliers();
|
| 5591 |
mandeep.dh |
324 |
}
|
|
|
325 |
|
|
|
326 |
public void setSuppliers(List<Supplier> suppliers) {
|
|
|
327 |
this.suppliers = suppliers;
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
public String getErrorMessage() {
|
|
|
331 |
return errorMessage;
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
public void setErrorMessage(String errorMessage) {
|
|
|
335 |
this.errorMessage = errorMessage;
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
public Supplier getSupplier() {
|
|
|
339 |
return supplier;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
public void setSupplier(Supplier supplier) {
|
|
|
343 |
this.supplier = supplier;
|
|
|
344 |
}
|
| 7410 |
amar.kumar |
345 |
|
|
|
346 |
public List<Long> getBillingWarehouseIds() {
|
|
|
347 |
return billingWarehouseIds;
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
public void setBillingWarehouseIds(List<Long> billingWarehouseIds) {
|
|
|
351 |
this.billingWarehouseIds = billingWarehouseIds;
|
|
|
352 |
}
|
| 10295 |
amar.kumar |
353 |
|
|
|
354 |
public long getStateId() {
|
|
|
355 |
return stateId;
|
|
|
356 |
}
|
| 21873 |
amit.gupta |
357 |
|
| 21878 |
amit.gupta |
358 |
public String getStateName(long stateId){
|
| 21873 |
amit.gupta |
359 |
return Utils.getStateIdMap().get(stateId).getStateName();
|
|
|
360 |
}
|
| 10295 |
amar.kumar |
361 |
|
|
|
362 |
public void setStateId(long stateId) {
|
|
|
363 |
this.stateId = stateId;
|
|
|
364 |
}
|
| 14072 |
manish.sha |
365 |
|
|
|
366 |
public long getPoValidityLimit() {
|
|
|
367 |
return poValidityLimit;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
public void setPoValidityLimit(long poValidityLimit) {
|
|
|
371 |
this.poValidityLimit = poValidityLimit;
|
|
|
372 |
}
|
| 14090 |
manish.sha |
373 |
|
|
|
374 |
public String getStateIdVal() {
|
|
|
375 |
return stateIdVal;
|
|
|
376 |
}
|
|
|
377 |
|
|
|
378 |
public void setStateIdVal(String stateIdVal) {
|
|
|
379 |
this.stateIdVal = stateIdVal;
|
|
|
380 |
}
|
| 23081 |
amit.gupta |
381 |
|
|
|
382 |
public void setTnc(String tnc) {
|
|
|
383 |
this.tnc = tnc;
|
|
|
384 |
}
|
|
|
385 |
|
|
|
386 |
public String getTnc() {
|
|
|
387 |
return tnc;
|
|
|
388 |
}
|
| 7410 |
amar.kumar |
389 |
|
| 5591 |
mandeep.dh |
390 |
}
|