Subversion Repositories SmartDukaan

Rev

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