| 5591 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.inventory.controllers;
|
|
|
5 |
|
| 5945 |
mandeep.dh |
6 |
import in.shop2020.model.v1.inventory.BillingType;
|
|
|
7 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
8 |
import in.shop2020.model.v1.inventory.Vendor;
|
|
|
9 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
10 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
| 5591 |
mandeep.dh |
11 |
import in.shop2020.purchase.PurchaseService.Client;
|
|
|
12 |
import in.shop2020.purchase.Supplier;
|
| 5945 |
mandeep.dh |
13 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 5591 |
mandeep.dh |
14 |
import in.shop2020.thrift.clients.PurchaseClient;
|
|
|
15 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
16 |
|
|
|
17 |
import java.util.List;
|
|
|
18 |
|
|
|
19 |
import org.apache.commons.lang.StringUtils;
|
|
|
20 |
import org.apache.commons.logging.Log;
|
|
|
21 |
import org.apache.commons.logging.LogFactory;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* @author mandeep
|
|
|
25 |
*
|
|
|
26 |
*/
|
|
|
27 |
public class SupplierController extends BaseController {
|
|
|
28 |
private static Log logger = LogFactory.getLog(SupplierController.class);
|
|
|
29 |
private String name;
|
|
|
30 |
private String phone;
|
|
|
31 |
private String fax;
|
|
|
32 |
private String tin;
|
|
|
33 |
private String pan;
|
|
|
34 |
private String headName;
|
|
|
35 |
private String headDesignation;
|
|
|
36 |
private String headEmail;
|
|
|
37 |
private String contactName;
|
|
|
38 |
private String contactPhone;
|
|
|
39 |
private String contactFax;
|
|
|
40 |
private String contactEmail;
|
|
|
41 |
private String registeredAddress;
|
|
|
42 |
private String communicationAddress;
|
|
|
43 |
|
|
|
44 |
private String id;
|
|
|
45 |
private List<Supplier> suppliers;
|
|
|
46 |
private String errorMessage = "";
|
|
|
47 |
private Supplier supplier;
|
|
|
48 |
|
|
|
49 |
public String index() {
|
|
|
50 |
try {
|
|
|
51 |
Client purchaseClient = new PurchaseClient().getClient();
|
|
|
52 |
suppliers = purchaseClient.getSuppliers();
|
|
|
53 |
} catch (Exception e) {
|
|
|
54 |
logger.error("Error loading suppliers", e);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
return INDEX;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/* (non-Javadoc)
|
|
|
61 |
* @see in.shop2020.inventory.controllers.BaseController#edit()
|
|
|
62 |
*/
|
|
|
63 |
@Override
|
|
|
64 |
public String edit() {
|
|
|
65 |
try {
|
|
|
66 |
Client purchaseClient = new PurchaseClient().getClient();
|
|
|
67 |
supplier = purchaseClient.getSupplier(Long.valueOf(id));
|
|
|
68 |
} catch (Exception e) {
|
|
|
69 |
errorMessage = "Error finding supplier: " + id + ": " + e.getMessage();
|
|
|
70 |
logger.error("Could not find supplier: " + id, e);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
return super.edit();
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public String create() {
|
|
|
77 |
try {
|
|
|
78 |
Supplier supplier = new Supplier();
|
|
|
79 |
supplier.setName(name);
|
|
|
80 |
supplier.setCommunicationAddress(communicationAddress);
|
|
|
81 |
supplier.setContactEmail(contactEmail);
|
|
|
82 |
supplier.setContactFax(contactFax);
|
|
|
83 |
supplier.setContactName(contactName);
|
|
|
84 |
supplier.setContactPhone(contactPhone);
|
|
|
85 |
supplier.setFax(fax);
|
|
|
86 |
supplier.setHeadDesignation(headDesignation);
|
|
|
87 |
supplier.setHeadEmail(headEmail);
|
|
|
88 |
supplier.setHeadName(headName);
|
|
|
89 |
supplier.setPan(pan);
|
|
|
90 |
supplier.setPhone(phone);
|
|
|
91 |
supplier.setRegisteredAddress(registeredAddress);
|
|
|
92 |
supplier.setTin(tin);
|
|
|
93 |
Client purchaseClient = new PurchaseClient().getClient();
|
|
|
94 |
supplier = purchaseClient.addSupplier(supplier);
|
|
|
95 |
|
| 5945 |
mandeep.dh |
96 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient(ConfigClientKeys.inventory_service_server_host.toString(),
|
|
|
97 |
ConfigClientKeys.inventory_service_server_port.toString()).getClient();
|
| 5591 |
mandeep.dh |
98 |
Vendor vendor = new Vendor();
|
|
|
99 |
vendor.setId(supplier.getId());
|
|
|
100 |
vendor.setName(name);
|
| 5945 |
mandeep.dh |
101 |
inventoryClient.addVendor(vendor);
|
|
|
102 |
Warehouse billingWarehouse = inventoryClient.getWarehouse(PurchaseOrderController.WAREHOUSE_ID);
|
| 5591 |
mandeep.dh |
103 |
Warehouse warehouse = new Warehouse();
|
|
|
104 |
warehouse.setVendor(vendor);
|
|
|
105 |
warehouse.setBillingType(BillingType.OURS);
|
|
|
106 |
warehouse.setBillingWarehouseId(billingWarehouse.getId());
|
|
|
107 |
warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "G"}, '/'));
|
|
|
108 |
warehouse.setInventoryType(InventoryType.GOOD);
|
|
|
109 |
warehouse.setIsAvailabilityMonitored(false);
|
|
|
110 |
warehouse.setLocation(billingWarehouse.getLocation());
|
|
|
111 |
warehouse.setPincode(billingWarehouse.getPincode());
|
|
|
112 |
warehouse.setLogisticsLocation(billingWarehouse.getLogisticsLocation());
|
|
|
113 |
warehouse.setShippingWarehouseId(billingWarehouse.getId());
|
|
|
114 |
warehouse.setTinNumber(tin);
|
|
|
115 |
warehouse.setTransferDelayInHours(0);
|
|
|
116 |
warehouse.setWarehouseType(WarehouseType.OURS);
|
| 5945 |
mandeep.dh |
117 |
inventoryClient.addWarehouse(warehouse);
|
| 5591 |
mandeep.dh |
118 |
|
|
|
119 |
warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "B"}, '/'));
|
|
|
120 |
warehouse.setInventoryType(InventoryType.BAD);
|
| 5945 |
mandeep.dh |
121 |
inventoryClient.addWarehouse(warehouse);
|
| 5591 |
mandeep.dh |
122 |
|
|
|
123 |
warehouse.setWarehouseType(WarehouseType.THIRD_PARTY);
|
|
|
124 |
warehouse.setDisplayName(StringUtils.join(new String[]{name, "G"}, '/'));
|
|
|
125 |
warehouse.setInventoryType(InventoryType.GOOD);
|
|
|
126 |
warehouse.setTransferDelayInHours(24);
|
|
|
127 |
warehouse.setBillingType(null);
|
|
|
128 |
warehouse.setBillingWarehouseId(0);
|
|
|
129 |
warehouse.setShippingWarehouseId(0);
|
| 5945 |
mandeep.dh |
130 |
inventoryClient.addWarehouse(warehouse);
|
| 5591 |
mandeep.dh |
131 |
} catch (Exception e) {
|
|
|
132 |
errorMessage = "Error creating supplier: " + e.getMessage();
|
|
|
133 |
logger.error("Error creating supplier", e);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
return index();
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public String update() {
|
|
|
140 |
String supplierName = id;
|
|
|
141 |
try {
|
|
|
142 |
Client purchaseClient = new PurchaseClient().getClient();
|
|
|
143 |
Supplier supplier = purchaseClient.getSupplier(Long.valueOf(id));
|
|
|
144 |
supplierName = supplier.getName();
|
|
|
145 |
supplier.setName(name);
|
|
|
146 |
supplier.setCommunicationAddress(communicationAddress);
|
|
|
147 |
supplier.setContactEmail(contactEmail);
|
|
|
148 |
supplier.setContactFax(contactFax);
|
|
|
149 |
supplier.setContactName(contactName);
|
|
|
150 |
supplier.setContactPhone(contactPhone);
|
|
|
151 |
supplier.setFax(fax);
|
|
|
152 |
supplier.setHeadDesignation(headDesignation);
|
|
|
153 |
supplier.setHeadEmail(headEmail);
|
|
|
154 |
supplier.setHeadName(headName);
|
|
|
155 |
supplier.setPan(pan);
|
|
|
156 |
supplier.setPhone(phone);
|
|
|
157 |
supplier.setRegisteredAddress(registeredAddress);
|
|
|
158 |
supplier.setTin(tin);
|
|
|
159 |
purchaseClient.updateSupplier(supplier);
|
|
|
160 |
} catch (Exception e) {
|
|
|
161 |
errorMessage = "Error updating supplier: " + supplierName + ": " + e.getMessage();
|
|
|
162 |
logger.error("Error updating supplier", e);
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
return index();
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
public String getName() {
|
|
|
169 |
return name;
|
|
|
170 |
}
|
|
|
171 |
public void setName(String name) {
|
|
|
172 |
this.name = name;
|
|
|
173 |
}
|
|
|
174 |
public String getPhone() {
|
|
|
175 |
return phone;
|
|
|
176 |
}
|
|
|
177 |
public void setPhone(String phone) {
|
|
|
178 |
this.phone = phone;
|
|
|
179 |
}
|
|
|
180 |
public String getFax() {
|
|
|
181 |
return fax;
|
|
|
182 |
}
|
|
|
183 |
public void setFax(String fax) {
|
|
|
184 |
this.fax = fax;
|
|
|
185 |
}
|
|
|
186 |
public String getTin() {
|
|
|
187 |
return tin;
|
|
|
188 |
}
|
|
|
189 |
public void setTin(String tin) {
|
|
|
190 |
this.tin = tin;
|
|
|
191 |
}
|
|
|
192 |
public String getPan() {
|
|
|
193 |
return pan;
|
|
|
194 |
}
|
|
|
195 |
public void setPan(String pan) {
|
|
|
196 |
this.pan = pan;
|
|
|
197 |
}
|
|
|
198 |
public String getHeadName() {
|
|
|
199 |
return headName;
|
|
|
200 |
}
|
|
|
201 |
public void setHeadName(String headName) {
|
|
|
202 |
this.headName = headName;
|
|
|
203 |
}
|
|
|
204 |
public String getHeadDesignation() {
|
|
|
205 |
return headDesignation;
|
|
|
206 |
}
|
|
|
207 |
public void setHeadDesignation(String headDesignation) {
|
|
|
208 |
this.headDesignation = headDesignation;
|
|
|
209 |
}
|
|
|
210 |
public String getHeadEmail() {
|
|
|
211 |
return headEmail;
|
|
|
212 |
}
|
|
|
213 |
public void setHeadEmail(String headEmail) {
|
|
|
214 |
this.headEmail = headEmail;
|
|
|
215 |
}
|
|
|
216 |
public String getContactName() {
|
|
|
217 |
return contactName;
|
|
|
218 |
}
|
|
|
219 |
public void setContactName(String contactName) {
|
|
|
220 |
this.contactName = contactName;
|
|
|
221 |
}
|
|
|
222 |
public String getContactPhone() {
|
|
|
223 |
return contactPhone;
|
|
|
224 |
}
|
|
|
225 |
public void setContactPhone(String contactPhone) {
|
|
|
226 |
this.contactPhone = contactPhone;
|
|
|
227 |
}
|
|
|
228 |
public String getContactFax() {
|
|
|
229 |
return contactFax;
|
|
|
230 |
}
|
|
|
231 |
public void setContactFax(String contactFax) {
|
|
|
232 |
this.contactFax = contactFax;
|
|
|
233 |
}
|
|
|
234 |
public String getContactEmail() {
|
|
|
235 |
return contactEmail;
|
|
|
236 |
}
|
|
|
237 |
public void setContactEmail(String contactEmail) {
|
|
|
238 |
this.contactEmail = contactEmail;
|
|
|
239 |
}
|
|
|
240 |
public String getRegisteredAddress() {
|
|
|
241 |
return registeredAddress;
|
|
|
242 |
}
|
|
|
243 |
public void setRegisteredAddress(String registeredAddress) {
|
|
|
244 |
this.registeredAddress = registeredAddress;
|
|
|
245 |
}
|
|
|
246 |
public String getCommunicationAddress() {
|
|
|
247 |
return communicationAddress;
|
|
|
248 |
}
|
|
|
249 |
public void setCommunicationAddress(String communicationAddress) {
|
|
|
250 |
this.communicationAddress = communicationAddress;
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
public String getId() {
|
|
|
254 |
return id;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
public void setId(String id) {
|
|
|
258 |
this.id = id;
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
public List<Supplier> getSuppliers() {
|
|
|
262 |
return suppliers;
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
public void setSuppliers(List<Supplier> suppliers) {
|
|
|
266 |
this.suppliers = suppliers;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
public String getErrorMessage() {
|
|
|
270 |
return errorMessage;
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
public void setErrorMessage(String errorMessage) {
|
|
|
274 |
this.errorMessage = errorMessage;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
public Supplier getSupplier() {
|
|
|
278 |
return supplier;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
public void setSupplier(Supplier supplier) {
|
|
|
282 |
this.supplier = supplier;
|
|
|
283 |
}
|
|
|
284 |
}
|