Subversion Repositories SmartDukaan

Rev

Rev 5945 | Rev 10121 | 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;
32
    private String tin;
33
    private String pan;
34
    private String headName;
35
    private String headDesignation;
36
    private String headEmail;
37
    private String contactName;
38
    private String contactPhone;
39
    private String contactFax;
40
    private String contactEmail;
41
    private String registeredAddress;
42
    private String communicationAddress;
7410 amar.kumar 43
    private List<Long> billingWarehouseIds;
5591 mandeep.dh 44
 
45
    private String id;
46
    private List<Supplier> suppliers;
47
    private String errorMessage = "";
48
    private Supplier supplier;
49
 
50
    public String index() {
51
        try {
52
            Client purchaseClient = new PurchaseClient().getClient();
53
            suppliers = purchaseClient.getSuppliers();
54
        } catch (Exception e) {
55
            logger.error("Error loading suppliers", e);
56
        }
57
 
58
        return INDEX;
59
    }
60
 
61
    /* (non-Javadoc)
62
     * @see in.shop2020.inventory.controllers.BaseController#edit()
63
     */
64
    @Override
65
    public String edit() {
66
        try {
67
            Client purchaseClient = new PurchaseClient().getClient();
68
            supplier = purchaseClient.getSupplier(Long.valueOf(id));
69
        } catch (Exception e) {
70
            errorMessage = "Error finding supplier: " + id + ": " + e.getMessage();
71
            logger.error("Could not find supplier: " + id, e);
72
        }
73
 
74
        return super.edit();
75
    }
76
 
77
    public String create() {
78
        try {
79
            Supplier supplier = new Supplier();
80
            supplier.setName(name);
81
            supplier.setCommunicationAddress(communicationAddress);
82
            supplier.setContactEmail(contactEmail);
83
            supplier.setContactFax(contactFax);
84
            supplier.setContactName(contactName);
85
            supplier.setContactPhone(contactPhone);
86
            supplier.setFax(fax);
87
            supplier.setHeadDesignation(headDesignation);
88
            supplier.setHeadEmail(headEmail);
89
            supplier.setHeadName(headName);
90
            supplier.setPan(pan);
91
            supplier.setPhone(phone);
92
            supplier.setRegisteredAddress(registeredAddress);
93
            supplier.setTin(tin);
94
            Client purchaseClient = new PurchaseClient().getClient();
95
            supplier = purchaseClient.addSupplier(supplier);
96
 
5945 mandeep.dh 97
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient(ConfigClientKeys.inventory_service_server_host.toString(),
98
                    ConfigClientKeys.inventory_service_server_port.toString()).getClient();
5591 mandeep.dh 99
            Vendor vendor = new Vendor();
100
            vendor.setId(supplier.getId());
101
            vendor.setName(name);
5945 mandeep.dh 102
            inventoryClient.addVendor(vendor);
7410 amar.kumar 103
            for(Long billingWarehouseId : billingWarehouseIds) {
104
	            Warehouse billingWarehouse = inventoryClient.getWarehouse(billingWarehouseId);
105
	            Warehouse warehouse = new Warehouse();
106
	            warehouse.setVendor(vendor);
107
	            warehouse.setStateId(billingWarehouse.getStateId());
108
	            warehouse.setBillingType(BillingType.OURS);
109
	            warehouse.setBillingWarehouseId(billingWarehouse.getId());
110
	            warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "G"}, '/'));
111
	            warehouse.setInventoryType(InventoryType.GOOD);
112
	            warehouse.setIsAvailabilityMonitored(false);
113
	            warehouse.setLocation(billingWarehouse.getLocation());
114
	            warehouse.setPincode(billingWarehouse.getPincode());
115
	            warehouse.setLogisticsLocation(billingWarehouse.getLogisticsLocation());
116
	            warehouse.setShippingWarehouseId(billingWarehouse.getId());
117
	            warehouse.setTinNumber(tin);
118
	            warehouse.setTransferDelayInHours(0);
119
	            warehouse.setWarehouseType(WarehouseType.OURS);
120
	            inventoryClient.addWarehouse(warehouse);
121
 
122
	            warehouse.setDisplayName(StringUtils.join(new String[]{billingWarehouse.getDisplayName(), name, "B"}, '/'));
123
	            warehouse.setInventoryType(InventoryType.BAD);
124
	            inventoryClient.addWarehouse(warehouse);
125
 
126
	            warehouse.setWarehouseType(WarehouseType.THIRD_PARTY);
127
	            warehouse.setDisplayName(StringUtils.join(new String[]{name, "G"}, '/'));
128
	            warehouse.setInventoryType(InventoryType.GOOD);
129
	            warehouse.setTransferDelayInHours(24);
130
	            warehouse.setBillingType(null);
131
	            warehouse.setBillingWarehouseId(0);
132
	            warehouse.setShippingWarehouseId(0);
133
	            inventoryClient.addWarehouse(warehouse);
134
            }
5591 mandeep.dh 135
        } catch (Exception e) {
136
            errorMessage = "Error creating supplier: " + e.getMessage();
137
            logger.error("Error creating supplier", e);
138
        }
139
 
140
        return index();
141
    }
142
 
143
    public String update() {
144
        String supplierName = id;
145
        try {
146
            Client purchaseClient = new PurchaseClient().getClient();
147
            Supplier supplier = purchaseClient.getSupplier(Long.valueOf(id));
148
            supplierName = supplier.getName();
149
            supplier.setName(name);
150
            supplier.setCommunicationAddress(communicationAddress);
151
            supplier.setContactEmail(contactEmail);
152
            supplier.setContactFax(contactFax);
153
            supplier.setContactName(contactName);
154
            supplier.setContactPhone(contactPhone);
155
            supplier.setFax(fax);
156
            supplier.setHeadDesignation(headDesignation);
157
            supplier.setHeadEmail(headEmail);
158
            supplier.setHeadName(headName);
159
            supplier.setPan(pan);
160
            supplier.setPhone(phone);
161
            supplier.setRegisteredAddress(registeredAddress);
162
            supplier.setTin(tin);
163
            purchaseClient.updateSupplier(supplier);
164
        } catch (Exception e) {
165
            errorMessage = "Error updating supplier: " + supplierName + ": " + e.getMessage();
166
            logger.error("Error updating supplier", e);
167
        }
168
 
169
        return index();
170
    }
171
 
172
    public String getName() {
173
        return name;
174
    }
175
    public void setName(String name) {
176
        this.name = name;
177
    }
178
    public String getPhone() {
179
        return phone;
180
    }
181
    public void setPhone(String phone) {
182
        this.phone = phone;
183
    }
184
    public String getFax() {
185
        return fax;
186
    }
187
    public void setFax(String fax) {
188
        this.fax = fax;
189
    }
190
    public String getTin() {
191
        return tin;
192
    }
193
    public void setTin(String tin) {
194
        this.tin = tin;
195
    }
196
    public String getPan() {
197
        return pan;
198
    }
199
    public void setPan(String pan) {
200
        this.pan = pan;
201
    }
202
    public String getHeadName() {
203
        return headName;
204
    }
205
    public void setHeadName(String headName) {
206
        this.headName = headName;
207
    }
208
    public String getHeadDesignation() {
209
        return headDesignation;
210
    }
211
    public void setHeadDesignation(String headDesignation) {
212
        this.headDesignation = headDesignation;
213
    }
214
    public String getHeadEmail() {
215
        return headEmail;
216
    }
217
    public void setHeadEmail(String headEmail) {
218
        this.headEmail = headEmail;
219
    }
220
    public String getContactName() {
221
        return contactName;
222
    }
223
    public void setContactName(String contactName) {
224
        this.contactName = contactName;
225
    }
226
    public String getContactPhone() {
227
        return contactPhone;
228
    }
229
    public void setContactPhone(String contactPhone) {
230
        this.contactPhone = contactPhone;
231
    }
232
    public String getContactFax() {
233
        return contactFax;
234
    }
235
    public void setContactFax(String contactFax) {
236
        this.contactFax = contactFax;
237
    }
238
    public String getContactEmail() {
239
        return contactEmail;
240
    }
241
    public void setContactEmail(String contactEmail) {
242
        this.contactEmail = contactEmail;
243
    }
244
    public String getRegisteredAddress() {
245
        return registeredAddress;
246
    }
247
    public void setRegisteredAddress(String registeredAddress) {
248
        this.registeredAddress = registeredAddress;
249
    }
250
    public String getCommunicationAddress() {
251
        return communicationAddress;
252
    }
253
    public void setCommunicationAddress(String communicationAddress) {
254
        this.communicationAddress = communicationAddress;
255
    }
256
 
257
    public String getId() {
258
        return id;
259
    }
260
 
261
    public void setId(String id) {
262
        this.id = id;
263
    }
264
 
265
    public List<Supplier> getSuppliers() {
266
        return suppliers;
267
    }
268
 
269
    public void setSuppliers(List<Supplier> suppliers) {
270
        this.suppliers = suppliers;
271
    }
272
 
273
    public String getErrorMessage() {
274
        return errorMessage;
275
    }
276
 
277
    public void setErrorMessage(String errorMessage) {
278
        this.errorMessage = errorMessage;
279
    }
280
 
281
    public Supplier getSupplier() {
282
        return supplier;
283
    }
284
 
285
    public void setSupplier(Supplier supplier) {
286
        this.supplier = supplier;
287
    }
7410 amar.kumar 288
 
289
	public List<Long> getBillingWarehouseIds() {
290
		return billingWarehouseIds;
291
	}
292
 
293
	public void setBillingWarehouseIds(List<Long> billingWarehouseIds) {
294
		this.billingWarehouseIds = billingWarehouseIds;
295
	}
296
 
5591 mandeep.dh 297
}