Subversion Repositories SmartDukaan

Rev

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