Subversion Repositories SmartDukaan

Rev

Rev 11219 | Rev 12629 | 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
        	}
12361 manish.sha 119
        	if(stateId == -1){
120
        		throw new Exception("State is Mandatory. Please select state");
121
        	}
5591 mandeep.dh 122
            Supplier supplier = new Supplier();
123
            supplier.setName(name);
124
            supplier.setCommunicationAddress(communicationAddress);
125
            supplier.setContactEmail(contactEmail);
126
            supplier.setContactFax(contactFax);
127
            supplier.setContactName(contactName);
128
            supplier.setContactPhone(contactPhone);
129
            supplier.setFax(fax);
130
            supplier.setHeadDesignation(headDesignation);
131
            supplier.setHeadEmail(headEmail);
132
            supplier.setHeadName(headName);
133
            supplier.setPan(pan);
134
            supplier.setPhone(phone);
135
            supplier.setRegisteredAddress(registeredAddress);
136
            supplier.setTin(tin);
10295 amar.kumar 137
            supplier.setStateId(stateId);
5591 mandeep.dh 138
            Client purchaseClient = new PurchaseClient().getClient();
139
            supplier = purchaseClient.addSupplier(supplier);
140
 
5945 mandeep.dh 141
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient(ConfigClientKeys.inventory_service_server_host.toString(),
142
                    ConfigClientKeys.inventory_service_server_port.toString()).getClient();
5591 mandeep.dh 143
            Vendor vendor = new Vendor();
144
            vendor.setId(supplier.getId());
145
            vendor.setName(name);
5945 mandeep.dh 146
            inventoryClient.addVendor(vendor);
7410 amar.kumar 147
            for(Long billingWarehouseId : billingWarehouseIds) {
148
	            Warehouse billingWarehouse = inventoryClient.getWarehouse(billingWarehouseId);
149
	            Warehouse warehouse = new Warehouse();
150
	            warehouse.setVendor(vendor);
151
	            warehouse.setStateId(billingWarehouse.getStateId());
152
	            warehouse.setBillingType(BillingType.OURS);
153
	            warehouse.setBillingWarehouseId(billingWarehouse.getId());
154
	            warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "G"}, '/'));
155
	            warehouse.setInventoryType(InventoryType.GOOD);
156
	            warehouse.setIsAvailabilityMonitored(false);
157
	            warehouse.setLocation(billingWarehouse.getLocation());
158
	            warehouse.setPincode(billingWarehouse.getPincode());
159
	            warehouse.setLogisticsLocation(billingWarehouse.getLogisticsLocation());
160
	            warehouse.setShippingWarehouseId(billingWarehouse.getId());
161
	            warehouse.setTinNumber(tin);
162
	            warehouse.setTransferDelayInHours(0);
163
	            warehouse.setWarehouseType(WarehouseType.OURS);
164
	            inventoryClient.addWarehouse(warehouse);
165
 
166
	            warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "B"}, '/'));
167
	            warehouse.setInventoryType(InventoryType.BAD);
168
	            inventoryClient.addWarehouse(warehouse);
169
 
170
	            warehouse.setWarehouseType(WarehouseType.THIRD_PARTY);
171
	            warehouse.setDisplayName(StringUtils.join(new String[]{name, "G"}, '/'));
172
	            warehouse.setInventoryType(InventoryType.GOOD);
173
	            warehouse.setTransferDelayInHours(24);
174
	            warehouse.setBillingType(null);
175
	            warehouse.setBillingWarehouseId(0);
176
	            warehouse.setShippingWarehouseId(0);
177
	            inventoryClient.addWarehouse(warehouse);
178
            }
5591 mandeep.dh 179
        } catch (Exception e) {
180
            errorMessage = "Error creating supplier: " + e.getMessage();
181
            logger.error("Error creating supplier", e);
182
        }
183
 
184
        return index();
185
    }
186
 
187
    public String update() {
188
        String supplierName = id;
189
        try {
190
            Client purchaseClient = new PurchaseClient().getClient();
191
            Supplier supplier = purchaseClient.getSupplier(Long.valueOf(id));
192
            supplierName = supplier.getName();
193
            supplier.setName(name);
194
            supplier.setCommunicationAddress(communicationAddress);
195
            supplier.setContactEmail(contactEmail);
196
            supplier.setContactFax(contactFax);
197
            supplier.setContactName(contactName);
198
            supplier.setContactPhone(contactPhone);
199
            supplier.setFax(fax);
200
            supplier.setHeadDesignation(headDesignation);
201
            supplier.setHeadEmail(headEmail);
202
            supplier.setHeadName(headName);
203
            supplier.setPan(pan);
204
            supplier.setPhone(phone);
205
            supplier.setRegisteredAddress(registeredAddress);
206
            supplier.setTin(tin);
11219 manish.sha 207
            supplier.setStateId(stateId);
5591 mandeep.dh 208
            purchaseClient.updateSupplier(supplier);
209
        } catch (Exception e) {
210
            errorMessage = "Error updating supplier: " + supplierName + ": " + e.getMessage();
211
            logger.error("Error updating supplier", e);
212
        }
213
 
214
        return index();
215
    }
216
 
217
    public String getName() {
218
        return name;
219
    }
220
    public void setName(String name) {
221
        this.name = name;
222
    }
223
    public String getPhone() {
224
        return phone;
225
    }
226
    public void setPhone(String phone) {
227
        this.phone = phone;
228
    }
229
    public String getFax() {
230
        return fax;
231
    }
232
    public void setFax(String fax) {
233
        this.fax = fax;
234
    }
235
    public String getTin() {
236
        return tin;
237
    }
238
    public void setTin(String tin) {
239
        this.tin = tin;
240
    }
241
    public String getPan() {
242
        return pan;
243
    }
244
    public void setPan(String pan) {
245
        this.pan = pan;
246
    }
247
    public String getHeadName() {
248
        return headName;
249
    }
250
    public void setHeadName(String headName) {
251
        this.headName = headName;
252
    }
253
    public String getHeadDesignation() {
254
        return headDesignation;
255
    }
256
    public void setHeadDesignation(String headDesignation) {
257
        this.headDesignation = headDesignation;
258
    }
259
    public String getHeadEmail() {
260
        return headEmail;
261
    }
262
    public void setHeadEmail(String headEmail) {
263
        this.headEmail = headEmail;
264
    }
265
    public String getContactName() {
266
        return contactName;
267
    }
268
    public void setContactName(String contactName) {
269
        this.contactName = contactName;
270
    }
271
    public String getContactPhone() {
272
        return contactPhone;
273
    }
274
    public void setContactPhone(String contactPhone) {
275
        this.contactPhone = contactPhone;
276
    }
277
    public String getContactFax() {
278
        return contactFax;
279
    }
280
    public void setContactFax(String contactFax) {
281
        this.contactFax = contactFax;
282
    }
283
    public String getContactEmail() {
284
        return contactEmail;
285
    }
286
    public void setContactEmail(String contactEmail) {
287
        this.contactEmail = contactEmail;
288
    }
289
    public String getRegisteredAddress() {
290
        return registeredAddress;
291
    }
292
    public void setRegisteredAddress(String registeredAddress) {
293
        this.registeredAddress = registeredAddress;
294
    }
295
    public String getCommunicationAddress() {
296
        return communicationAddress;
297
    }
298
    public void setCommunicationAddress(String communicationAddress) {
299
        this.communicationAddress = communicationAddress;
300
    }
301
 
302
    public String getId() {
303
        return id;
304
    }
305
 
306
    public void setId(String id) {
307
        this.id = id;
308
    }
309
 
310
    public List<Supplier> getSuppliers() {
311
        return suppliers;
312
    }
313
 
314
    public void setSuppliers(List<Supplier> suppliers) {
315
        this.suppliers = suppliers;
316
    }
317
 
318
    public String getErrorMessage() {
319
        return errorMessage;
320
    }
321
 
322
    public void setErrorMessage(String errorMessage) {
323
        this.errorMessage = errorMessage;
324
    }
325
 
326
    public Supplier getSupplier() {
327
        return supplier;
328
    }
329
 
330
    public void setSupplier(Supplier supplier) {
331
        this.supplier = supplier;
332
    }
7410 amar.kumar 333
 
334
	public List<Long> getBillingWarehouseIds() {
335
		return billingWarehouseIds;
336
	}
337
 
338
	public void setBillingWarehouseIds(List<Long> billingWarehouseIds) {
339
		this.billingWarehouseIds = billingWarehouseIds;
340
	}
10295 amar.kumar 341
 
342
    public long getStateId() {
343
		return stateId;
344
	}
345
 
346
	public void setStateId(long stateId) {
347
		this.stateId = stateId;
348
	}
7410 amar.kumar 349
 
5591 mandeep.dh 350
}