Subversion Repositories SmartDukaan

Rev

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