Subversion Repositories SmartDukaan

Rev

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