Subversion Repositories SmartDukaan

Rev

Rev 21875 | Rev 21877 | 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.setPhone(phone);
216
            supplier.setRegisteredAddress(registeredAddress);
21844 amit.gupta 217
            supplier.setGstin(gstin);
14088 manish.sha 218
            supplier.setStateId(supplier.getStateId());
14072 manish.sha 219
            supplier.setPoValidityLimit(poValidityLimit);
5591 mandeep.dh 220
            purchaseClient.updateSupplier(supplier);
21873 amit.gupta 221
            Utils.resetSuppliers();
5591 mandeep.dh 222
        } catch (Exception e) {
223
            errorMessage = "Error updating supplier: " + supplierName + ": " + e.getMessage();
224
            logger.error("Error updating supplier", e);
225
        }
226
 
227
        return index();
228
    }
229
 
230
    public String getName() {
231
        return name;
232
    }
233
    public void setName(String name) {
234
        this.name = name;
235
    }
236
    public String getPhone() {
237
        return phone;
238
    }
239
    public void setPhone(String phone) {
240
        this.phone = phone;
241
    }
242
    public String getFax() {
243
        return fax;
244
    }
245
    public void setFax(String fax) {
246
        this.fax = fax;
247
    }
248
    public String getPan() {
249
        return pan;
250
    }
251
    public void setPan(String pan) {
252
        this.pan = pan;
253
    }
254
    public String getHeadName() {
255
        return headName;
256
    }
257
    public void setHeadName(String headName) {
258
        this.headName = headName;
259
    }
260
    public String getHeadDesignation() {
261
        return headDesignation;
262
    }
263
    public void setHeadDesignation(String headDesignation) {
264
        this.headDesignation = headDesignation;
265
    }
266
    public String getHeadEmail() {
267
        return headEmail;
268
    }
269
    public void setHeadEmail(String headEmail) {
270
        this.headEmail = headEmail;
271
    }
272
    public String getContactName() {
273
        return contactName;
274
    }
275
    public void setContactName(String contactName) {
276
        this.contactName = contactName;
277
    }
278
    public String getContactPhone() {
279
        return contactPhone;
280
    }
281
    public void setContactPhone(String contactPhone) {
282
        this.contactPhone = contactPhone;
283
    }
284
    public String getContactFax() {
285
        return contactFax;
286
    }
287
    public void setContactFax(String contactFax) {
288
        this.contactFax = contactFax;
289
    }
290
    public String getContactEmail() {
291
        return contactEmail;
292
    }
293
    public void setContactEmail(String contactEmail) {
294
        this.contactEmail = contactEmail;
295
    }
296
    public String getRegisteredAddress() {
297
        return registeredAddress;
298
    }
299
    public void setRegisteredAddress(String registeredAddress) {
300
        this.registeredAddress = registeredAddress;
301
    }
302
    public String getCommunicationAddress() {
303
        return communicationAddress;
304
    }
305
    public void setCommunicationAddress(String communicationAddress) {
306
        this.communicationAddress = communicationAddress;
307
    }
308
 
309
    public String getId() {
310
        return id;
311
    }
312
 
313
    public void setId(String id) {
314
        this.id = id;
315
    }
316
 
317
    public List<Supplier> getSuppliers() {
21873 amit.gupta 318
        return Utils.getSuppliers();
5591 mandeep.dh 319
    }
320
 
321
    public void setSuppliers(List<Supplier> suppliers) {
322
        this.suppliers = suppliers;
323
    }
324
 
325
    public String getErrorMessage() {
326
        return errorMessage;
327
    }
328
 
329
    public void setErrorMessage(String errorMessage) {
330
        this.errorMessage = errorMessage;
331
    }
332
 
333
    public Supplier getSupplier() {
334
        return supplier;
335
    }
336
 
337
    public void setSupplier(Supplier supplier) {
338
        this.supplier = supplier;
339
    }
7410 amar.kumar 340
 
341
	public List<Long> getBillingWarehouseIds() {
342
		return billingWarehouseIds;
343
	}
344
 
345
	public void setBillingWarehouseIds(List<Long> billingWarehouseIds) {
346
		this.billingWarehouseIds = billingWarehouseIds;
347
	}
10295 amar.kumar 348
 
349
    public long getStateId() {
350
		return stateId;
351
	}
21873 amit.gupta 352
 
21876 amit.gupta 353
    public String getStateName(String stateId){
21873 amit.gupta 354
    	return Utils.getStateIdMap().get(stateId).getStateName();
355
    }
10295 amar.kumar 356
 
357
	public void setStateId(long stateId) {
358
		this.stateId = stateId;
359
	}
14072 manish.sha 360
 
361
	public long getPoValidityLimit() {
362
		return poValidityLimit;
363
	}
364
 
365
	public void setPoValidityLimit(long poValidityLimit) {
366
		this.poValidityLimit = poValidityLimit;
367
	}
14090 manish.sha 368
 
369
	public String getStateIdVal() {
370
		return stateIdVal;
371
	}
372
 
373
	public void setStateIdVal(String stateIdVal) {
374
		this.stateIdVal = stateIdVal;
375
	}
7410 amar.kumar 376
 
5591 mandeep.dh 377
}