Subversion Repositories SmartDukaan

Rev

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