Subversion Repositories SmartDukaan

Rev

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