Subversion Repositories SmartDukaan

Rev

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