Subversion Repositories SmartDukaan

Rev

Rev 5946 | Rev 6241 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5946 Rev 6165
Line 5... Line 5...
5
import in.shop2020.config.ConfigException;
5
import in.shop2020.config.ConfigException;
6
import in.shop2020.model.v1.catalog.CatalogService;
6
import in.shop2020.model.v1.catalog.CatalogService;
7
import in.shop2020.model.v1.catalog.ItemType;
7
import in.shop2020.model.v1.catalog.ItemType;
8
import in.shop2020.model.v1.catalog.status;
8
import in.shop2020.model.v1.catalog.status;
9
import in.shop2020.model.v1.inventory.InventoryService.Client;
9
import in.shop2020.model.v1.inventory.InventoryService.Client;
-
 
10
import in.shop2020.model.v1.inventory.Vendor;
10
import in.shop2020.thrift.clients.CatalogClient;
11
import in.shop2020.thrift.clients.CatalogClient;
11
import in.shop2020.thrift.clients.InventoryClient;
12
import in.shop2020.thrift.clients.InventoryClient;
12
import in.shop2020.thrift.clients.config.ConfigClient;
13
import in.shop2020.thrift.clients.config.ConfigClient;
13
import in.shop2020.utils.CategoryManager;
14
import in.shop2020.utils.CategoryManager;
14
import in.shop2020.utils.ConfigClientKeys;
15
import in.shop2020.utils.ConfigClientKeys;
Line 16... Line 17...
16
import java.io.ByteArrayOutputStream;
17
import java.io.ByteArrayOutputStream;
17
import java.io.IOException;
18
import java.io.IOException;
18
import java.text.DecimalFormat;
19
import java.text.DecimalFormat;
19
import java.util.ArrayList;
20
import java.util.ArrayList;
20
import java.util.HashMap;
21
import java.util.HashMap;
-
 
22
import java.util.Hashtable;
21
import java.util.List;
23
import java.util.List;
22
import java.util.Map;
24
import java.util.Map;
23
 
25
 
24
import org.apache.log4j.Logger;
26
import org.apache.log4j.Logger;
25
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
27
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
Line 65... Line 67...
65
                    ConfigClientKeys.catalog_service_server_port.toString());
67
                    ConfigClientKeys.catalog_service_server_port.toString());
66
            CatalogService.Client catalogClient = catalogServiceClient.getClient();
68
            CatalogService.Client catalogClient = catalogServiceClient.getClient();
67
            
69
            
68
            InventoryClient inventoryServiceClient = new InventoryClient();
70
            InventoryClient inventoryServiceClient = new InventoryClient();
69
            Client inventoryClient = inventoryServiceClient.getClient();
71
            Client inventoryClient = inventoryServiceClient.getClient();
-
 
72
            List<Vendor> vendors = inventoryClient.getAllVendors();
-
 
73
            Map<Long, String> vendorIdNameMap = new Hashtable<Long, String>();
-
 
74
            for(Vendor vendor : vendors){
-
 
75
            	vendorIdNameMap.put(vendor.getId(), vendor.getName());
70
            
76
            }
71
            thriftItemListInactive.addAll(catalogClient.getAllItemsByStatus(status.PAUSED));
77
            thriftItemListInactive.addAll(catalogClient.getAllItemsByStatus(status.PAUSED));
72
            if(TYPE_INACTIVE != type){
78
            if(TYPE_INACTIVE != type){
73
            	catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
79
            	catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
74
                        ConfigClientKeys.catalog_service_server_port.toString());
80
                        ConfigClientKeys.catalog_service_server_port.toString());
75
            	catalogClient = catalogServiceClient.getClient();
81
            	catalogClient = catalogServiceClient.getClient();
Line 92... Line 98...
92
	            headerRow.getCell(2).setCellStyle(styleBold);
98
	            headerRow.getCell(2).setCellStyle(styleBold);
93
	            headerRow.createCell(3).setCellValue("Model Number");
99
	            headerRow.createCell(3).setCellValue("Model Number");
94
	            headerRow.getCell(3).setCellStyle(styleBold);
100
	            headerRow.getCell(3).setCellStyle(styleBold);
95
	            headerRow.createCell(4).setCellValue("Color");
101
	            headerRow.createCell(4).setCellValue("Color");
96
	            headerRow.getCell(4).setCellStyle(styleBold);
102
	            headerRow.getCell(4).setCellStyle(styleBold);
97
	            headerRow.createCell(5).setCellValue("Selling Price");
103
	            headerRow.createCell(5).setCellValue("Transfer Price");
98
	            headerRow.getCell(5).setCellStyle(styleBold);
104
	            headerRow.getCell(5).setCellStyle(styleBold);
99
	            headerRow.createCell(6).setCellValue("Break Even Price");
105
	            headerRow.createCell(6).setCellValue("Vendor");
100
	            headerRow.getCell(6).setCellStyle(styleBold);
106
	            headerRow.getCell(6).setCellStyle(styleBold);
101
	            headerRow.createCell(7).setCellValue("Current Status");
107
	            headerRow.createCell(7).setCellValue("Selling Price");
102
	            headerRow.getCell(7).setCellStyle(styleBold);
108
	            headerRow.getCell(7).setCellStyle(styleBold);
103
	            headerRow.createCell(8).setCellValue("Reason");
109
	            headerRow.createCell(8).setCellValue("Break Even Price");
104
	            headerRow.getCell(8).setCellStyle(styleBold);
110
	            headerRow.getCell(8).setCellStyle(styleBold);
-
 
111
	            headerRow.createCell(9).setCellValue("Current Status");
-
 
112
	            headerRow.getCell(9).setCellStyle(styleBold);
-
 
113
	            headerRow.createCell(10).setCellValue("Reason");
-
 
114
	            headerRow.getCell(10).setCellStyle(styleBold);
105
	            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItemList) {
115
	            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItemList) {
106
	            	List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
116
	            	List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
107
	            	Item item = getItemFromThriftItem(thriftItem, vip);
117
	            	Item item = getItemFromThriftItem(thriftItem, vip);
108
	            	List<Object> breakeven = isBreakeven(item);
118
	            	List<Object> breakeven = isBreakeven(item);
109
	            	if(!(Boolean)breakeven.get(0)){
119
	            	if(!(Boolean)breakeven.get(0)){
Line 113... Line 123...
113
	            		itemRow.createCell(1).setCellValue(item.getBrand());
123
	            		itemRow.createCell(1).setCellValue(item.getBrand());
114
	            		itemRow.createCell(2).setCellValue(item.getModelName());
124
	            		itemRow.createCell(2).setCellValue(item.getModelName());
115
	            		itemRow.createCell(3).setCellValue(item.getModelNumber());
125
	            		itemRow.createCell(3).setCellValue(item.getModelNumber());
116
	            		itemRow.createCell(4).setCellValue(item.getColor());
126
	            		itemRow.createCell(4).setCellValue(item.getColor());
117
	            		
127
	            		
-
 
128
	            		try{
-
 
129
	            			itemRow.createCell(5).setCellValue(numberFormat.format((Double)breakeven.get(2)));
-
 
130
	            		} catch (Exception e){
-
 
131
	            			itemRow.createCell(5).setCellValue("Empty");
-
 
132
	            		}
-
 
133
	            		
-
 
134
	            		try{
-
 
135
	            			itemRow.createCell(6).setCellValue(vendorIdNameMap.get(breakeven.get(3)));
-
 
136
	            		} catch (Exception e){
-
 
137
	            			itemRow.createCell(6).setCellValue("Empty");
-
 
138
	            		}
-
 
139
	            		
118
	            		Double sellingPrice = item.getSellingPrice();
140
	            		Double sellingPrice = item.getSellingPrice();
119
	            		if(sellingPrice != null){
141
	            		if(sellingPrice != null){
120
	            			itemRow.createCell(5).setCellValue(numberFormat.format(sellingPrice));
142
	            			itemRow.createCell(7).setCellValue(numberFormat.format(sellingPrice));
121
	            		} else {
143
	            		} else {
122
	            			itemRow.createCell(5).setCellValue("NULL");
144
	            			itemRow.createCell(7).setCellValue("NULL");
123
	            		}
145
	            		}
124
	            		
146
	            		
125
	            		try{
147
	            		try{
126
	            			itemRow.createCell(6).setCellValue(numberFormat.format((Double)breakeven.get(1)));
148
	            			itemRow.createCell(8).setCellValue(numberFormat.format((Double)breakeven.get(1)));
127
	            		} catch (Exception e){
149
	            		} catch (Exception e){
128
	            			itemRow.createCell(6).setCellValue("Empty");
150
	            			itemRow.createCell(8).setCellValue("Empty");
129
	            		}
151
	            		}
130
	            		itemRow.createCell(7).setCellValue(thriftItem.getItemStatus().toString());
152
	            		itemRow.createCell(9).setCellValue(thriftItem.getItemStatus().toString());
131
	            		try { 
153
	            		try { 
132
	            			itemRow.createCell(8).setCellValue((String)breakeven.get(1));
154
	            			itemRow.createCell(10).setCellValue((String)breakeven.get(1));
133
	            		}catch (Exception e) {
155
	            		}catch (Exception e) {
134
	            			itemRow.createCell(8).setCellValue("");							
156
	            			itemRow.createCell(10).setCellValue("");							
135
						}
157
						}
136
	            		}catch (Exception e) {
158
	            		}catch (Exception e) {
137
							logger.info("Error occurred for item : " + item.getId());
159
							logger.info("Error occurred for item : " + item.getId());
138
							System.out.println("Item id failed for breakeven report: " + item.getId());
160
							System.out.println("Item id failed for breakeven report: " + item.getId());
139
						}
161
						}
Line 210... Line 232...
210
	}
232
	}
211
 
233
 
212
	private List<Object> isBreakeven(Item newItem) {
234
	private List<Object> isBreakeven(Item newItem) {
213
		List<Object> list = new ArrayList<Object>();
235
		List<Object> list = new ArrayList<Object>();
214
		boolean message = true;
236
		boolean message = true;
-
 
237
		Long vendor = 0L;
215
 
238
 
216
		if (newItem.getSellingPrice() == null || newItem.getSellingPrice().compareTo(0d) <= 0) {
239
		if (newItem.getSellingPrice() == null || newItem.getSellingPrice().compareTo(0d) <= 0) {
217
			message=false;
240
			message=false;
218
			list.add(message);
241
			list.add(message);
219
			list.add("Selling price is empty or 0");
242
			list.add("Selling price is empty or 0");
Line 227... Line 250...
227
			for (VendorPricings vendorDetail : newItem.getVendorPricesMap()
250
			for (VendorPricings vendorDetail : newItem.getVendorPricesMap()
228
					.values()) {
251
					.values()) {
229
				if (transferPrice > vendorDetail.getTransferPrice()
252
				if (transferPrice > vendorDetail.getTransferPrice()
230
						|| transferPrice == -1) {
253
						|| transferPrice == -1) {
231
					transferPrice = vendorDetail.getTransferPrice();
254
					transferPrice = vendorDetail.getTransferPrice();
-
 
255
					vendor = vendorDetail.getVendorId();
232
				}
256
				}
233
			}
257
			}
234
		} else if (!newItem.getVendorPricesMap().isEmpty()
258
		} else if (!newItem.getVendorPricesMap().isEmpty()
235
				&& newItem.getVendorPricesMap().containsKey(
259
				&& newItem.getVendorPricesMap().containsKey(
236
						newItem.getPreferredVendor())) {
260
						newItem.getPreferredVendor())) {
237
			transferPrice = newItem.getVendorPricesMap()
261
			transferPrice = newItem.getVendorPricesMap()
238
					.get(newItem.getPreferredVendor()).getTransferPrice();
262
					.get(newItem.getPreferredVendor()).getTransferPrice();
-
 
263
			vendor = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getVendorId();
239
		} else {
264
		} else {
240
			message = false;
265
			message = false;
241
			list.add(message);
266
			list.add(message);
242
			list.add("Preferred vendor is not in Vendor Item Mapping.");
267
			list.add("Preferred vendor is not in Vendor Item Mapping.");
243
			return list;
268
			return list;
Line 270... Line 295...
270
 
295
 
271
		if (Double.compare(breakeven, newItem.getSellingPrice())>=0) {
296
		if (Double.compare(breakeven, newItem.getSellingPrice())>=0) {
272
			message=false;
297
			message=false;
273
			list.add(message);
298
			list.add(message);
274
			list.add(breakeven);
299
			list.add(breakeven);
-
 
300
			list.add(transferPrice);
-
 
301
			list.add(vendor);
275
			return list;
302
			return list;
276
		}
303
		}
277
		list.add(message);
304
		list.add(message);
278
		return list;
305
		return list;
279
	}
306
	}