Subversion Repositories SmartDukaan

Rev

Rev 5616 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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