Subversion Repositories SmartDukaan

Rev

Rev 10295 | Rev 12361 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
10295 amar.kumar 42
    private long stateId;
5591 mandeep.dh 43
    private String communicationAddress;
7410 amar.kumar 44
    private List<Long> billingWarehouseIds;
5591 mandeep.dh 45
 
46
    private String id;
47
    private List<Supplier> suppliers;
48
    private String errorMessage = "";
49
    private Supplier supplier;
50
 
51
    public String index() {
52
        try {
53
            Client purchaseClient = new PurchaseClient().getClient();
54
            suppliers = purchaseClient.getSuppliers();
55
        } catch (Exception e) {
56
            logger.error("Error loading suppliers", e);
57
        }
58
 
59
        return INDEX;
60
    }
61
 
62
    /* (non-Javadoc)
63
     * @see in.shop2020.inventory.controllers.BaseController#edit()
64
     */
65
    @Override
66
    public String edit() {
67
        try {
68
            Client purchaseClient = new PurchaseClient().getClient();
69
            supplier = purchaseClient.getSupplier(Long.valueOf(id));
70
        } catch (Exception e) {
71
            errorMessage = "Error finding supplier: " + id + ": " + e.getMessage();
72
            logger.error("Could not find supplier: " + id, e);
73
        }
74
 
75
        return super.edit();
76
    }
77
 
78
    public String create() {
79
        try {
10121 manish.sha 80
        	if(name==null || ("").equalsIgnoreCase(name)){
81
        		throw new Exception("Supplier Name is Mandatory.");
82
        	}
83
        	if((phone==null || ("").equalsIgnoreCase(phone)) && !StringUtils.isNumeric(phone)){
84
        		throw new Exception("Supplier Phone is Mandatory and Should be in digits only");
85
        	}
86
        	if(fax==null || ("").equalsIgnoreCase(fax)){
87
        		throw new Exception("Supplier Fax is Mandatory.");
88
        	}
89
        	if(tin==null || ("").equalsIgnoreCase(tin)){
90
        		throw new Exception("Supplier Name is Mandatory.");
91
        	}
92
        	if(pan==null || ("").equalsIgnoreCase(pan)){
93
        		throw new Exception("Supplier PAN is Mandatory.");
94
        	}
95
        	if(headName==null || ("").equalsIgnoreCase(headName)){
96
        		throw new Exception("Supplier Head Name is Mandatory.");
97
        	}
98
        	if(headEmail==null || ("").equalsIgnoreCase(headEmail)){
99
        		throw new Exception("Supplier Head Email is Mandatory.");
100
        	}
101
        	if(contactName==null || ("").equalsIgnoreCase(contactName)){
102
        		throw new Exception("Supplier Contact Name is Mandatory.");
103
        	}
104
        	if(contactFax==null || ("").equalsIgnoreCase(contactFax)){
105
        		throw new Exception("Supplier Name is Mandatory.");
106
        	}
107
        	if(contactPhone==null || ("").equalsIgnoreCase(contactPhone)){
108
        		throw new Exception("Supplier Contact Phone is Mandatory.");
109
        	}
110
        	if(registeredAddress==null || ("").equalsIgnoreCase(registeredAddress)){
111
        		throw new Exception("Supplier Registered Address is Mandatory.");
112
        	}
113
        	if(communicationAddress==null || ("").equalsIgnoreCase(communicationAddress)){
114
        		throw new Exception("Supplier Communication Address is Mandatory.");
115
        	}
116
        	if(billingWarehouseIds==null || billingWarehouseIds.size()==0){
117
        		throw new Exception("Atleast One Billing Warehouse is Mandatory.");
118
        	}
5591 mandeep.dh 119
            Supplier supplier = new Supplier();
120
            supplier.setName(name);
121
            supplier.setCommunicationAddress(communicationAddress);
122
            supplier.setContactEmail(contactEmail);
123
            supplier.setContactFax(contactFax);
124
            supplier.setContactName(contactName);
125
            supplier.setContactPhone(contactPhone);
126
            supplier.setFax(fax);
127
            supplier.setHeadDesignation(headDesignation);
128
            supplier.setHeadEmail(headEmail);
129
            supplier.setHeadName(headName);
130
            supplier.setPan(pan);
131
            supplier.setPhone(phone);
132
            supplier.setRegisteredAddress(registeredAddress);
133
            supplier.setTin(tin);
10295 amar.kumar 134
            supplier.setStateId(stateId);
5591 mandeep.dh 135
            Client purchaseClient = new PurchaseClient().getClient();
136
            supplier = purchaseClient.addSupplier(supplier);
137
 
5945 mandeep.dh 138
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient(ConfigClientKeys.inventory_service_server_host.toString(),
139
                    ConfigClientKeys.inventory_service_server_port.toString()).getClient();
5591 mandeep.dh 140
            Vendor vendor = new Vendor();
141
            vendor.setId(supplier.getId());
142
            vendor.setName(name);
5945 mandeep.dh 143
            inventoryClient.addVendor(vendor);
7410 amar.kumar 144
            for(Long billingWarehouseId : billingWarehouseIds) {
145
	            Warehouse billingWarehouse = inventoryClient.getWarehouse(billingWarehouseId);
146
	            Warehouse warehouse = new Warehouse();
147
	            warehouse.setVendor(vendor);
148
	            warehouse.setStateId(billingWarehouse.getStateId());
149
	            warehouse.setBillingType(BillingType.OURS);
150
	            warehouse.setBillingWarehouseId(billingWarehouse.getId());
151
	            warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "G"}, '/'));
152
	            warehouse.setInventoryType(InventoryType.GOOD);
153
	            warehouse.setIsAvailabilityMonitored(false);
154
	            warehouse.setLocation(billingWarehouse.getLocation());
155
	            warehouse.setPincode(billingWarehouse.getPincode());
156
	            warehouse.setLogisticsLocation(billingWarehouse.getLogisticsLocation());
157
	            warehouse.setShippingWarehouseId(billingWarehouse.getId());
158
	            warehouse.setTinNumber(tin);
159
	            warehouse.setTransferDelayInHours(0);
160
	            warehouse.setWarehouseType(WarehouseType.OURS);
161
	            inventoryClient.addWarehouse(warehouse);
162
 
163
	            warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "B"}, '/'));
164
	            warehouse.setInventoryType(InventoryType.BAD);
165
	            inventoryClient.addWarehouse(warehouse);
166
 
167
	            warehouse.setWarehouseType(WarehouseType.THIRD_PARTY);
168
	            warehouse.setDisplayName(StringUtils.join(new String[]{name, "G"}, '/'));
169
	            warehouse.setInventoryType(InventoryType.GOOD);
170
	            warehouse.setTransferDelayInHours(24);
171
	            warehouse.setBillingType(null);
172
	            warehouse.setBillingWarehouseId(0);
173
	            warehouse.setShippingWarehouseId(0);
174
	            inventoryClient.addWarehouse(warehouse);
175
            }
5591 mandeep.dh 176
        } catch (Exception e) {
177
            errorMessage = "Error creating supplier: " + e.getMessage();
178
            logger.error("Error creating supplier", e);
179
        }
180
 
181
        return index();
182
    }
183
 
184
    public String update() {
185
        String supplierName = id;
186
        try {
187
            Client purchaseClient = new PurchaseClient().getClient();
188
            Supplier supplier = purchaseClient.getSupplier(Long.valueOf(id));
189
            supplierName = supplier.getName();
190
            supplier.setName(name);
191
            supplier.setCommunicationAddress(communicationAddress);
192
            supplier.setContactEmail(contactEmail);
193
            supplier.setContactFax(contactFax);
194
            supplier.setContactName(contactName);
195
            supplier.setContactPhone(contactPhone);
196
            supplier.setFax(fax);
197
            supplier.setHeadDesignation(headDesignation);
198
            supplier.setHeadEmail(headEmail);
199
            supplier.setHeadName(headName);
200
            supplier.setPan(pan);
201
            supplier.setPhone(phone);
202
            supplier.setRegisteredAddress(registeredAddress);
203
            supplier.setTin(tin);
11219 manish.sha 204
            supplier.setStateId(stateId);
5591 mandeep.dh 205
            purchaseClient.updateSupplier(supplier);
206
        } catch (Exception e) {
207
            errorMessage = "Error updating supplier: " + supplierName + ": " + e.getMessage();
208
            logger.error("Error updating supplier", e);
209
        }
210
 
211
        return index();
212
    }
213
 
214
    public String getName() {
215
        return name;
216
    }
217
    public void setName(String name) {
218
        this.name = name;
219
    }
220
    public String getPhone() {
221
        return phone;
222
    }
223
    public void setPhone(String phone) {
224
        this.phone = phone;
225
    }
226
    public String getFax() {
227
        return fax;
228
    }
229
    public void setFax(String fax) {
230
        this.fax = fax;
231
    }
232
    public String getTin() {
233
        return tin;
234
    }
235
    public void setTin(String tin) {
236
        this.tin = tin;
237
    }
238
    public String getPan() {
239
        return pan;
240
    }
241
    public void setPan(String pan) {
242
        this.pan = pan;
243
    }
244
    public String getHeadName() {
245
        return headName;
246
    }
247
    public void setHeadName(String headName) {
248
        this.headName = headName;
249
    }
250
    public String getHeadDesignation() {
251
        return headDesignation;
252
    }
253
    public void setHeadDesignation(String headDesignation) {
254
        this.headDesignation = headDesignation;
255
    }
256
    public String getHeadEmail() {
257
        return headEmail;
258
    }
259
    public void setHeadEmail(String headEmail) {
260
        this.headEmail = headEmail;
261
    }
262
    public String getContactName() {
263
        return contactName;
264
    }
265
    public void setContactName(String contactName) {
266
        this.contactName = contactName;
267
    }
268
    public String getContactPhone() {
269
        return contactPhone;
270
    }
271
    public void setContactPhone(String contactPhone) {
272
        this.contactPhone = contactPhone;
273
    }
274
    public String getContactFax() {
275
        return contactFax;
276
    }
277
    public void setContactFax(String contactFax) {
278
        this.contactFax = contactFax;
279
    }
280
    public String getContactEmail() {
281
        return contactEmail;
282
    }
283
    public void setContactEmail(String contactEmail) {
284
        this.contactEmail = contactEmail;
285
    }
286
    public String getRegisteredAddress() {
287
        return registeredAddress;
288
    }
289
    public void setRegisteredAddress(String registeredAddress) {
290
        this.registeredAddress = registeredAddress;
291
    }
292
    public String getCommunicationAddress() {
293
        return communicationAddress;
294
    }
295
    public void setCommunicationAddress(String communicationAddress) {
296
        this.communicationAddress = communicationAddress;
297
    }
298
 
299
    public String getId() {
300
        return id;
301
    }
302
 
303
    public void setId(String id) {
304
        this.id = id;
305
    }
306
 
307
    public List<Supplier> getSuppliers() {
308
        return suppliers;
309
    }
310
 
311
    public void setSuppliers(List<Supplier> suppliers) {
312
        this.suppliers = suppliers;
313
    }
314
 
315
    public String getErrorMessage() {
316
        return errorMessage;
317
    }
318
 
319
    public void setErrorMessage(String errorMessage) {
320
        this.errorMessage = errorMessage;
321
    }
322
 
323
    public Supplier getSupplier() {
324
        return supplier;
325
    }
326
 
327
    public void setSupplier(Supplier supplier) {
328
        this.supplier = supplier;
329
    }
7410 amar.kumar 330
 
331
	public List<Long> getBillingWarehouseIds() {
332
		return billingWarehouseIds;
333
	}
334
 
335
	public void setBillingWarehouseIds(List<Long> billingWarehouseIds) {
336
		this.billingWarehouseIds = billingWarehouseIds;
337
	}
10295 amar.kumar 338
 
339
    public long getStateId() {
340
		return stateId;
341
	}
342
 
343
	public void setStateId(long stateId) {
344
		this.stateId = stateId;
345
	}
7410 amar.kumar 346
 
5591 mandeep.dh 347
}