Subversion Repositories SmartDukaan

Rev

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