Subversion Repositories SmartDukaan

Rev

Rev 10121 | Rev 11219 | 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);
204
            purchaseClient.updateSupplier(supplier);
205
        } catch (Exception e) {
206
            errorMessage = "Error updating supplier: " + supplierName + ": " + e.getMessage();
207
            logger.error("Error updating supplier", e);
208
        }
209
 
210
        return index();
211
    }
212
 
213
    public String getName() {
214
        return name;
215
    }
216
    public void setName(String name) {
217
        this.name = name;
218
    }
219
    public String getPhone() {
220
        return phone;
221
    }
222
    public void setPhone(String phone) {
223
        this.phone = phone;
224
    }
225
    public String getFax() {
226
        return fax;
227
    }
228
    public void setFax(String fax) {
229
        this.fax = fax;
230
    }
231
    public String getTin() {
232
        return tin;
233
    }
234
    public void setTin(String tin) {
235
        this.tin = tin;
236
    }
237
    public String getPan() {
238
        return pan;
239
    }
240
    public void setPan(String pan) {
241
        this.pan = pan;
242
    }
243
    public String getHeadName() {
244
        return headName;
245
    }
246
    public void setHeadName(String headName) {
247
        this.headName = headName;
248
    }
249
    public String getHeadDesignation() {
250
        return headDesignation;
251
    }
252
    public void setHeadDesignation(String headDesignation) {
253
        this.headDesignation = headDesignation;
254
    }
255
    public String getHeadEmail() {
256
        return headEmail;
257
    }
258
    public void setHeadEmail(String headEmail) {
259
        this.headEmail = headEmail;
260
    }
261
    public String getContactName() {
262
        return contactName;
263
    }
264
    public void setContactName(String contactName) {
265
        this.contactName = contactName;
266
    }
267
    public String getContactPhone() {
268
        return contactPhone;
269
    }
270
    public void setContactPhone(String contactPhone) {
271
        this.contactPhone = contactPhone;
272
    }
273
    public String getContactFax() {
274
        return contactFax;
275
    }
276
    public void setContactFax(String contactFax) {
277
        this.contactFax = contactFax;
278
    }
279
    public String getContactEmail() {
280
        return contactEmail;
281
    }
282
    public void setContactEmail(String contactEmail) {
283
        this.contactEmail = contactEmail;
284
    }
285
    public String getRegisteredAddress() {
286
        return registeredAddress;
287
    }
288
    public void setRegisteredAddress(String registeredAddress) {
289
        this.registeredAddress = registeredAddress;
290
    }
291
    public String getCommunicationAddress() {
292
        return communicationAddress;
293
    }
294
    public void setCommunicationAddress(String communicationAddress) {
295
        this.communicationAddress = communicationAddress;
296
    }
297
 
298
    public String getId() {
299
        return id;
300
    }
301
 
302
    public void setId(String id) {
303
        this.id = id;
304
    }
305
 
306
    public List<Supplier> getSuppliers() {
307
        return suppliers;
308
    }
309
 
310
    public void setSuppliers(List<Supplier> suppliers) {
311
        this.suppliers = suppliers;
312
    }
313
 
314
    public String getErrorMessage() {
315
        return errorMessage;
316
    }
317
 
318
    public void setErrorMessage(String errorMessage) {
319
        this.errorMessage = errorMessage;
320
    }
321
 
322
    public Supplier getSupplier() {
323
        return supplier;
324
    }
325
 
326
    public void setSupplier(Supplier supplier) {
327
        this.supplier = supplier;
328
    }
7410 amar.kumar 329
 
330
	public List<Long> getBillingWarehouseIds() {
331
		return billingWarehouseIds;
332
	}
333
 
334
	public void setBillingWarehouseIds(List<Long> billingWarehouseIds) {
335
		this.billingWarehouseIds = billingWarehouseIds;
336
	}
10295 amar.kumar 337
 
338
    public long getStateId() {
339
		return stateId;
340
	}
341
 
342
	public void setStateId(long stateId) {
343
		this.stateId = stateId;
344
	}
7410 amar.kumar 345
 
5591 mandeep.dh 346
}