Subversion Repositories SmartDukaan

Rev

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

Rev 11095 Rev 12133
Line 69... Line 69...
69
import com.opensymphony.xwork2.ValidationAwareSupport;
69
import com.opensymphony.xwork2.ValidationAwareSupport;
70
 
70
 
71
@SuppressWarnings({"unused","deprecation"})
71
@SuppressWarnings({"unused","deprecation"})
72
 
72
 
73
@InterceptorRefs({
73
@InterceptorRefs({
74
	@InterceptorRef("defaultStack"),
74
    @InterceptorRef("defaultStack"),
75
	@InterceptorRef("login")
75
    @InterceptorRef("login")
76
})
76
})
77
 
77
 
78
public class SnapdealListController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
78
public class SnapdealListController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
79
	/**
79
    /**
80
	 * 
80
     * 
81
	 */
81
     */
82
	private static final long serialVersionUID = 1L;
82
    private static final long serialVersionUID = 1L;
83
 
83
 
84
 
84
 
85
	private static Logger logger = LoggerFactory.getLogger(SnapdealListController.class);
85
    private static Logger logger = LoggerFactory.getLogger(SnapdealListController.class);
86
 
86
 
87
 
87
 
88
	private HttpServletRequest request;
88
    private HttpServletRequest request;
89
	private HttpServletResponse response;
89
    private HttpServletResponse response;
90
	private HttpSession session;
90
    private HttpSession session;
91
	private ServletContext context;
91
    private ServletContext context;
92
	private String url;
92
    private String url;
93
	private String itemId;
93
    private String itemId;
94
	private String isSnapdealListed;
94
    private String isSnapdealListed;
95
	private String exceptionPrice;
95
    private String exceptionPrice;
96
	private String warehouseId;
96
    private String warehouseId;
97
	private File file;
97
    private File file;
98
	private String errMsg;
98
    private String errMsg;
99
	private String next;
99
    private String next;
100
	private String id;
100
    private String id;
101
	private String searchText;
101
    private String searchText;
102
	private List<SnapdealItemDetails> snapdealItems;
102
    private List<SnapdealItemDetails> snapdealItems;
103
	private long searchCount;
103
    private long searchCount;
104
	private long totalCount;
104
    private long totalCount;
105
	private String sellingPrice;
105
    private String sellingPrice;
106
	private String transferPrice;
106
    private String transferPrice;
107
	private String webisteMrp;
107
    private String webisteMrp;
108
	private String webisteSellingPrice;
108
    private String webisteSellingPrice;
109
	private String isListedOnSnapdeal;
109
    private String isListedOnSnapdeal;
110
	private String commission;
110
    private String commission;
111
	private String serviceTax;
111
    private String serviceTax;
112
	private String courierCost;
112
    private String courierCost;
113
	private JSONObject itemObj;
113
    private JSONObject itemObj;
114
	private String isSuppressInventoryFeed;
114
    private String isSuppressInventoryFeed;
115
	private String isSuppressPriceFeed;
115
    private String isSuppressPriceFeed;
116
	private String maxNlc;
116
    private String maxNlc;
117
	private String sdItemCode;
117
    private String sdItemCode;
118
	private String supc;
118
    private String supc;
119
	private String held;
119
    private String held;
120
	private String lastUpdatedInventoryTimestamp;
120
    private String lastUpdatedInventoryTimestamp;
121
	private String lastCheckedTimestamp;
121
    private String lastCheckedTimestamp;
122
	private String otherCost;
122
    private String otherCost;
123
	private String isAutoIncrement;
123
    private String isAutoIncrement;
124
	private String isAutoDecrement;
124
    private String isAutoDecrement;
125
	private String isManualFavourite;
125
    private String isManualFavourite;
126
	private String isAutoFavourite;
126
    private String isAutoFavourite;
127
	private String currentSp;
127
    private String currentSp;
128
	private String currentTp;
128
    private String currentTp;
129
	private String minPosSp;
129
    private String minPosSp;
130
	private String minPosTp;
130
    private String minPosTp;
131
	private String vat;
131
    private String vat;
132
	private String comparsionResult;
132
    private String comparsionResult;
133
	private String maxSp;
133
    private String maxSp;
134
	private String nDaySale;
134
    private String nDaySale;
135
	private static String live;
135
    private static String live;
136
    private List<MarketplaceHistory> compData;
136
    private List<MarketplaceHistory> compData;
137
    private String productName;
137
    private String productName;
138
    private String startDate;
138
    private String startDate;
139
    private String endDate;
139
    private String endDate;
140
    private String courierCostMarketplace;
140
    private String courierCostMarketplace;
-
 
141
    private String packagingCost;
-
 
142
 
141
 
143
 
142
    
-
 
143
    public String courierCostMarketplace() {
144
    public String courierCostMarketplace() {
144
        return courierCostMarketplace;
145
        return courierCostMarketplace;
145
    }
146
    }
146
 
147
 
147
    public void setCourierCostMarketplace(String courierCostMarketplace) {
148
    public void setCourierCostMarketplace(String courierCostMarketplace) {
148
        this.courierCostMarketplace = courierCostMarketplace;
149
        this.courierCostMarketplace = courierCostMarketplace;
149
    }
150
    }
150
    
151
 
151
    public String getnDaySale() {
152
    public String getnDaySale() {
152
		return nDaySale;
153
        return nDaySale;
153
	}
154
    }
154
 
155
 
155
	public void setnDaySale(String nDaySale) {
156
    public void setnDaySale(String nDaySale) {
156
		this.nDaySale = nDaySale;
157
        this.nDaySale = nDaySale;
157
	}
158
    }
158
 
159
 
159
	private String avgSale;
160
    private String avgSale;
160
 
161
 
161
	public String getAvgSale() {
162
    public String getAvgSale() {
162
		return avgSale;
163
        return avgSale;
163
	}
164
    }
164
 
165
 
165
	public void setAvgSale(String avgSale) {
166
    public void setAvgSale(String avgSale) {
166
		this.avgSale = avgSale;
167
        this.avgSale = avgSale;
167
	}
168
    }
168
 
169
 
169
	public String getMaxSp() {
170
    public String getMaxSp() {
170
		return maxSp;
171
        return maxSp;
171
	}
172
    }
172
 
173
 
173
	public void setMaxSp(String maxSp) {
174
    public void setMaxSp(String maxSp) {
174
		this.maxSp = maxSp;
175
        this.maxSp = maxSp;
175
	}
176
    }
176
 
177
 
177
	public String getComparsionResult() {
178
    public String getComparsionResult() {
178
		return comparsionResult;
179
        return comparsionResult;
179
	}
180
    }
180
 
181
 
181
	public void setComparsionResult(String comparsionResult) {
182
    public void setComparsionResult(String comparsionResult) {
182
		this.comparsionResult = comparsionResult;
183
        this.comparsionResult = comparsionResult;
183
	}
184
    }
184
 
185
 
185
	private Map<Integer, Long> holdInventoryMap;
186
    private Map<Integer, Long> holdInventoryMap;
186
 
187
 
187
	public String getVat() {
188
    public String getVat() {
188
		return vat;
189
        return vat;
189
	}
190
    }
190
 
191
 
191
	public void setStartDate(String startDate) {
192
    public void setStartDate(String startDate) {
192
		this.startDate = startDate;
193
        this.startDate = startDate;
193
	}
194
    }
194
	
195
 
195
	public String getStartDate() {
196
    public String getStartDate() {
196
        return startDate;
197
        return startDate;
197
    }
198
    }
198
	
199
 
199
	public void setEndDate(String endDate) {
200
    public void setEndDate(String endDate) {
200
        this.endDate = endDate;
201
        this.endDate = endDate;
201
    }
202
    }
202
    
203
 
203
    public String getEndDate() {
204
    public String getEndDate() {
204
        return endDate;
205
        return endDate;
205
    }
206
    }
206
 
207
 
207
    public void setVat(String vat) {
208
    public void setVat(String vat) {
208
        this.vat = vat;
209
        this.vat = vat;
209
    }
210
    }
210
 
211
 
211
	public String getOtherCost() {
212
    public String getOtherCost() {
212
		return otherCost;
213
        return otherCost;
213
	}
214
    }
214
 
215
 
215
	public void setOtherCost(String otherCost) {
216
    public void setOtherCost(String otherCost) {
216
		this.otherCost = otherCost;
217
        this.otherCost = otherCost;
217
	}
218
    }
218
 
219
 
219
 
220
 
220
	public String getCurrentSp() {
221
    public String getCurrentSp() {
221
		return currentSp;
222
        return currentSp;
222
	}
223
    }
223
 
224
 
224
	public void setCurrentSp(String currentSp) {
225
    public void setCurrentSp(String currentSp) {
225
		this.currentSp = currentSp;
226
        this.currentSp = currentSp;
226
	}
227
    }
227
 
228
 
228
	public String getCurrentTp() {
229
    public String getCurrentTp() {
229
		return currentTp;
230
        return currentTp;
230
	}
231
    }
231
 
232
 
232
	public void setCurrentTp(String currentTp) {
233
    public void setCurrentTp(String currentTp) {
233
		this.currentTp = currentTp;
234
        this.currentTp = currentTp;
234
	}
235
    }
235
 
236
 
236
 
237
 
237
	public String getLastCheckedTimestamp() {
238
    public String getLastCheckedTimestamp() {
238
		return lastCheckedTimestamp;
239
        return lastCheckedTimestamp;
239
	}
240
    }
240
 
241
 
241
	public String getLastUpdatedInventoryTimestamp() {
242
    public String getLastUpdatedInventoryTimestamp() {
242
		return lastUpdatedInventoryTimestamp;
243
        return lastUpdatedInventoryTimestamp;
243
	}
244
    }
244
 
245
 
245
	public void setLastUpdatedInventoryTimestamp(
246
    public void setLastUpdatedInventoryTimestamp(
246
			String lastUpdatedInventoryTimestamp) {
247
            String lastUpdatedInventoryTimestamp) {
247
		this.lastUpdatedInventoryTimestamp = lastUpdatedInventoryTimestamp;
248
        this.lastUpdatedInventoryTimestamp = lastUpdatedInventoryTimestamp;
248
	}
249
    }
249
 
250
 
250
	public void setLastCheckedTimestamp(
251
    public void setLastCheckedTimestamp(
251
			String lastCheckedTimestamp) {
252
            String lastCheckedTimestamp) {
252
		this.lastCheckedTimestamp = lastCheckedTimestamp;
253
        this.lastCheckedTimestamp = lastCheckedTimestamp;
253
	}
254
    }
254
 
255
 
255
	public String getIsAutoIncrement() {
256
    public String getIsAutoIncrement() {
256
		return isAutoIncrement;
257
        return isAutoIncrement;
257
	}
258
    }
258
 
259
 
259
	public void setIsAutoIncrement(String isAutoIncrement) {
260
    public void setIsAutoIncrement(String isAutoIncrement) {
260
		this.isAutoIncrement = isAutoIncrement;
261
        this.isAutoIncrement = isAutoIncrement;
261
	}
262
    }
262
 
263
 
263
	public String getIsAutoDecrement() {
264
    public String getIsAutoDecrement() {
264
		return isAutoDecrement;
265
        return isAutoDecrement;
265
	}
266
    }
266
 
267
 
267
	public void setIsAutoDecrement(String isAutoDecrement) {
268
    public void setIsAutoDecrement(String isAutoDecrement) {
268
		this.isAutoDecrement = isAutoDecrement;
269
        this.isAutoDecrement = isAutoDecrement;
269
	}
270
    }
270
 
271
 
271
	public String getIsManualFavourite() {
272
    public String getIsManualFavourite() {
272
		return isManualFavourite;
273
        return isManualFavourite;
273
	}
274
    }
274
 
275
 
275
	public void setIsManualFavourite(String isManualFavourite) {
276
    public void setIsManualFavourite(String isManualFavourite) {
276
		this.isManualFavourite = isManualFavourite;
277
        this.isManualFavourite = isManualFavourite;
277
	}
278
    }
278
 
279
 
279
	public String getIsAutoFavourite() {
280
    public String getIsAutoFavourite() {
280
		return isAutoFavourite;
281
        return isAutoFavourite;
281
	}
282
    }
282
 
283
 
283
	public void setIsAutoFavourite(String isAutoFavourite) {
284
    public void setIsAutoFavourite(String isAutoFavourite) {
284
		this.isAutoFavourite = isAutoFavourite;
285
        this.isAutoFavourite = isAutoFavourite;
285
	}
286
    }
286
 
287
 
287
	public String getMinPosSp() {
288
    public String getMinPosSp() {
288
		return minPosSp;
289
        return minPosSp;
289
	}
290
    }
290
 
291
 
291
	public void setMinPosSp(String minPosSp) {
292
    public void setMinPosSp(String minPosSp) {
292
		this.minPosSp = minPosSp;
293
        this.minPosSp = minPosSp;
293
	}
294
    }
294
 
295
 
295
	public String getMinPosTp() {
296
    public String getMinPosTp() {
296
		return minPosTp;
297
        return minPosTp;
297
	}
298
    }
298
 
299
 
299
	public void setMinPosTp(String minPosTp) {
300
    public void setMinPosTp(String minPosTp) {
300
		this.minPosTp = minPosTp;
301
        this.minPosTp = minPosTp;
301
	}
302
    }
302
 
303
 
303
	public String getHeld() {
304
    public String getHeld() {
304
		return held;
305
        return held;
305
	}
306
    }
306
 
307
 
307
	public void setHeld(String held) {
308
    public void setHeld(String held) {
308
		this.held = held;
309
        this.held = held;
309
	}
310
    }
310
 
311
 
311
	public String getSupc() {
312
    public String getSupc() {
312
		return supc;
313
        return supc;
313
	}
314
    }
314
 
315
 
315
	public void setSupc(String supc) {
316
    public void setSupc(String supc) {
316
		this.supc = supc;
317
        this.supc = supc;
317
	}
318
    }
318
 
319
 
319
	public String getSdItemCode() {
320
    public String getSdItemCode() {
320
		return sdItemCode;
321
        return sdItemCode;
321
	}
322
    }
322
 
323
 
323
	public void setSdItemCode(String sdItemCode) {
324
    public void setSdItemCode(String sdItemCode) {
324
		this.sdItemCode = sdItemCode;
325
        this.sdItemCode = sdItemCode;
325
	}
326
    }
326
	
327
 
327
	
328
 
328
	static{
329
    static{
329
		try {
330
        try {
330
			live = ConfigClient.getClient().get("sync_price_on_marketplace");
331
            live = ConfigClient.getClient().get("sync_price_on_marketplace");
331
		} catch (ConfigException e) {
332
        } catch (ConfigException e) {
332
		    logger.error("Unable to get parameter from the config service", e);
333
            logger.error("Unable to get parameter from the config service", e);
333
		    live = "false";
334
            live = "false";
334
		}
335
        }
335
	}
336
    }
336
 
337
 
337
	public String index() {
338
    public String index() {
338
		if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
339
        if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE),request.getServletPath())) {
339
			return "authfail";
340
            return "authfail";
340
		}
341
        }
341
		return "index";
342
        return "index";
342
	}
343
    }
343
 
344
 
344
	public String edit() {
345
    public String edit() {
345
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
346
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
346
			return "authfail";
347
            return "authfail";
347
		}
348
        }
348
		return "edit";
349
        return "edit";
349
	}
350
    }
350
 
351
 
351
	public String fetchItems() throws TException {
352
    public String fetchItems() throws TException {
352
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
353
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
353
		if (searchText.length() == 0) {
354
        if (searchText.length() == 0) {
354
			snapdealItems = CatalogClient.getSnapdealItems(Long.valueOf(next), 10);
355
            snapdealItems = CatalogClient.getSnapdealItems(Long.valueOf(next), 10);
355
			totalCount = CatalogClient.getCountForSnapdealItems();
356
            totalCount = CatalogClient.getCountForSnapdealItems();
356
			setSearchCount(totalCount);
357
            setSearchCount(totalCount);
357
		} else {
358
        } else {
358
			List<String> subString = Arrays.asList(searchText.split(" "));
359
            List<String> subString = Arrays.asList(searchText.split(" "));
359
			snapdealItems = CatalogClient.searchSnapdealItems(subString,Long.valueOf(next), 10);
360
            snapdealItems = CatalogClient.searchSnapdealItems(subString,Long.valueOf(next), 10);
360
			totalCount = CatalogClient.getCountForSnapdealItems();
361
            totalCount = CatalogClient.getCountForSnapdealItems();
361
			searchCount = CatalogClient.getSnapdealSearchResultCount(subString);
362
            searchCount = CatalogClient.getSnapdealSearchResultCount(subString);
362
		}
363
        }
363
		return "snapdeal-item-table";
364
        return "snapdeal-item-table";
364
	}
365
    }
365
 
366
 
366
	public SnapdealItemDetails fetchItemDetail() throws NumberFormatException, TException {
367
    public SnapdealItemDetails fetchItemDetail() throws NumberFormatException, TException {
367
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
368
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
368
		SnapdealItemDetails sdItemDetails = CatalogClient.getSnapdealItemDetails(Long.valueOf(id));
369
        SnapdealItemDetails sdItemDetails = CatalogClient.getSnapdealItemDetails(Long.valueOf(id));
369
		lastUpdatedInventoryTimeStampForItem(sdItemDetails.getLastUpdatedInventoryTimestamp());
370
        lastUpdatedInventoryTimeStampForItem(sdItemDetails.getLastUpdatedInventoryTimestamp());
370
		return sdItemDetails;
371
        return sdItemDetails;
371
	}
372
    }
372
 
373
 
373
	public MarketplaceItems fetchMarketplaceDetail() throws NumberFormatException, TException {
374
    public MarketplaceItems fetchMarketplaceDetail() throws NumberFormatException, TException {
374
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
375
        Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
375
		MarketplaceItems mpItemDetails = CatalogClient.getMarketplacedetailsForItem(Long.valueOf(id), 7);
376
        MarketplaceItems mpItemDetails = CatalogClient.getMarketplacedetailsForItem(Long.valueOf(id), 7);
376
		lastCheckedTimeStampForItem(mpItemDetails.getLastCheckedTimestamp());
377
        lastCheckedTimeStampForItem(mpItemDetails.getLastCheckedTimestamp());
377
		return mpItemDetails;
378
        return mpItemDetails;
378
	}
379
    }
379
	
380
 
380
	public String getDate(long timestamp){
381
    public String getDate(long timestamp){
381
	    return new java.util.Date(timestamp).toLocaleString();
382
        return new java.util.Date(timestamp).toLocaleString();
382
	    
383
 
383
	}
384
    }
384
 
385
 
385
	public void lastUpdatedInventoryTimeStampForItem(long timestamp){
386
    public void lastUpdatedInventoryTimeStampForItem(long timestamp){
386
		setLastUpdatedInventoryTimestamp(new java.util.Date(timestamp).toLocaleString());
387
        setLastUpdatedInventoryTimestamp(new java.util.Date(timestamp).toLocaleString());
387
	}
388
    }
388
 
389
 
389
	public void lastCheckedTimeStampForItem(long timestamp){
390
    public void lastCheckedTimeStampForItem(long timestamp){
390
		setLastCheckedTimestamp(new java.util.Date(timestamp).toLocaleString());
391
        setLastCheckedTimestamp(new java.util.Date(timestamp).toLocaleString());
391
	}
392
    }
392
 
393
 
393
	public String uploadBulkSheet(){
394
    public String uploadBulkSheet(){
394
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
395
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
395
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
396
            logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
396
			return "authfail";
397
            return "authfail";
397
		}
398
        }
398
		return "snapdeal-bulk-upload";
399
        return "snapdeal-bulk-upload";
399
	}
400
    }
400
 
401
 
401
	public String update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException, JSONException{
402
    public String update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException, JSONException{
402
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
403
        Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
403
		//Client catalogClientProd = new CatalogClient().getClient();
404
        //Client catalogClientProd = new CatalogClient().getClient();
404
		Long timestamp = System.currentTimeMillis();
405
        Long timestamp = System.currentTimeMillis();
405
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
406
        SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
406
		boolean toUpdate = false;
407
        boolean toUpdate = false;
407
		if (snapdealItem.getSellingPrice()!=Double.valueOf(sellingPrice) || snapdealItem.isIsListedOnSnapdeal()!=Boolean.valueOf(isListedOnSnapdeal) || snapdealItem.isSuppressPriceFeed()!=Boolean.valueOf(isSuppressPriceFeed)){
408
        if (snapdealItem.getSellingPrice()!=Double.valueOf(sellingPrice) || snapdealItem.isIsListedOnSnapdeal()!=Boolean.valueOf(isListedOnSnapdeal) || snapdealItem.isSuppressPriceFeed()!=Boolean.valueOf(isSuppressPriceFeed)){
408
			toUpdate=true;
409
            toUpdate=true;
409
		}
410
        }
410
		Item item = catalogClient.getItem(Long.valueOf(itemId));
411
        Item item = catalogClient.getItem(Long.valueOf(itemId));
411
		MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
412
        MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
412
		if (mpCosting.getSource()==0){
413
        if (mpCosting.getSource()==0){
413
			throw new CatalogServiceException();
414
            throw new CatalogServiceException();
414
		}
415
        }
415
		MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
416
        MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
416
		mpItem.setEmiFee(mpCosting.getEmiFee());
417
        mpItem.setEmiFee(mpCosting.getEmiFee());
417
		mpItem.setReturnProvision(mpCosting.getReturnProvision());
418
        mpItem.setReturnProvision(mpCosting.getReturnProvision());
418
		mpItem.setClosingFee(mpCosting.getClosingFee());
419
        mpItem.setClosingFee(mpCosting.getClosingFee());
419
		mpItem.setServiceTax(mpCosting.getServiceTax());
420
        mpItem.setServiceTax(mpCosting.getServiceTax());
420
		mpItem.setCommission(mpCosting.getCommission());
421
        mpItem.setCommission(mpCosting.getCommission());
421
		mpItem.setPgFee(mpCosting.getPgFee());
422
        mpItem.setPgFee(mpCosting.getPgFee());
422
		InventoryClient inventoryServiceClient = new InventoryClient();
423
        InventoryClient inventoryServiceClient = new InventoryClient();
423
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
424
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
424
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
425
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
425
		/*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
426
        /*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
426
			throw new InventoryServiceException();
427
			throw new InventoryServiceException();
427
		}*/
428
		}*/
428
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
429
        snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
429
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
430
        snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
430
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
431
        snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
431
		snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
432
        snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
432
		snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
433
        snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
433
		snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
434
        snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
434
		snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
435
        snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
435
		snapdealItem.setCourierCost(Double.valueOf(courierCost));
436
        snapdealItem.setCourierCost(Double.valueOf(courierCost));
436
		snapdealItem.setCommission(Double.valueOf(commission));
437
        snapdealItem.setCommission(Double.valueOf(commission));
437
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
438
        snapdealItem.setServiceTax(Double.valueOf(serviceTax));
438
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
439
        snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
439
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
440
        snapdealItem.setSkuAtSnapdeal(sdItemCode);
440
		snapdealItem.setSupc(supc);
441
        snapdealItem.setSupc(supc);
441
		snapdealItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
442
        snapdealItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
442
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
443
        MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
443
		//double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
444
        //double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
444
		//t_mpItem.setVat(vat);
445
        //t_mpItem.setVat(vat);
445
		t_mpItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
446
        t_mpItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
446
		snapdealItem.setUpdatedBy(getUserName());
447
        snapdealItem.setUpdatedBy(getUserName());
447
		snapdealItem.setMarketplaceItems(t_mpItem);
448
        snapdealItem.setMarketplaceItems(t_mpItem);
448
 
449
 
449
		if(!compareParameters(t_mpItem,snapdealItem,warehouse,item.getWeight())){
450
        if(!compareParameters(t_mpItem,snapdealItem,warehouse,item.getWeight(),item.getCategory())){
450
			setComparsionResult("0");
451
            setComparsionResult("0");
451
			return "snapdeal-update-result";
452
            return "snapdeal-update-result";
452
		}
453
        }
453
		else{
454
        else{
454
			setComparsionResult("1");
455
            setComparsionResult("1");
455
		}
456
        }
456
 
457
 
457
		if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
458
        if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
458
			throw new CatalogServiceException();
459
            throw new CatalogServiceException();
459
		}
460
        }
460
 
461
 
461
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
462
        if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
462
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
463
            sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
463
		}
464
        }
464
		logger.info("\nUpdate Method Item Id "+itemId+"\nSelling Price "+sellingPrice+"\nWarehouse Id "+warehouseId+"\nMax Nlc "+maxNlc+"\nUpdated By: "+session.getAttribute(ReportsUtils.USER_NAME).toString());
465
        logger.info("\nUpdate Method Item Id "+itemId+"\nSelling Price "+sellingPrice+"\nWarehouse Id "+warehouseId+"\nMax Nlc "+maxNlc+"\nUpdated By: "+session.getAttribute(ReportsUtils.USER_NAME).toString());
465
		if(toUpdate && Boolean.valueOf(live) && (!snapdealItem.isSuppressPriceFeed()) && snapdealItem.isIsListedOnSnapdeal()){
466
        if(toUpdate && Boolean.valueOf(live) && (!snapdealItem.isSuppressPriceFeed()) && snapdealItem.isIsListedOnSnapdeal()){
466
			logger.info("Calling Method to update price at snapdeal");
467
            logger.info("Calling Method to update price at snapdeal");
467
			UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,timestamp);
468
            UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,timestamp);
468
			logger.info("Calling Thread to update price at snapdeal");
469
            logger.info("Calling Thread to update price at snapdeal");
469
			updatePriceOnSnapdeal.start();	
470
            updatePriceOnSnapdeal.start();	
470
		}
471
        }
471
		return "snapdeal-update-result";
472
        return "snapdeal-update-result";
472
	}
473
    }
473
	
474
 
474
	
475
 
475
	public void updateForAutoPricing() throws NumberFormatException, CatalogServiceException, TException{
476
    public void updateForAutoPricing() throws NumberFormatException, CatalogServiceException, TException{
476
		logger.info("Calling Method to update price at snapdeal for auto pricing");
477
        logger.info("Calling Method to update price at snapdeal for auto pricing");
477
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
478
        Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
478
		Item item = catalogClient.getItem(Long.valueOf(itemId));
479
        Item item = catalogClient.getItem(Long.valueOf(itemId));
479
		UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,System.currentTimeMillis());
480
        UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,System.currentTimeMillis());
480
		logger.info("Calling Thread to update price at snapdeal for auto pricing");
481
        logger.info("Calling Thread to update price at snapdeal for auto pricing");
481
		updatePriceOnSnapdeal.start();	
482
        updatePriceOnSnapdeal.start();	
482
	}
483
    }
483
 
484
 
484
 
485
 
485
	public boolean compareParameters(MarketplaceItems mpItem, SnapdealItem snapdealItem, Warehouse warehouse,double weight) throws TException, JSONException, CatalogServiceException{
486
    public boolean compareParameters(MarketplaceItems mpItem, SnapdealItem snapdealItem, Warehouse warehouse,double weight, Long categoryId) throws TException, JSONException, CatalogServiceException{
486
		double nlc =getNlcForWarehouse(snapdealItem.getWarehouseId(),snapdealItem.getItem_id());
487
        double nlc =getNlcForWarehouse(snapdealItem.getWarehouseId(),snapdealItem.getItem_id());
487
		double vat = (snapdealItem.getSellingPrice()/(1+(mpItem.getVat()/100))-(nlc/(1+(mpItem.getVat()/100))))*(mpItem.getVat()/100);
488
        double vat = (snapdealItem.getSellingPrice()/(1+(mpItem.getVat()/100))-(nlc/(1+(mpItem.getVat()/100))))*(mpItem.getVat()/100);
488
		double inHouseCost = 15+vat+(mpItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+mpItem.getOtherCost();
489
        double inHouseCost = mpItem.getPackagingCost()+vat+(mpItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+mpItem.getOtherCost();
489
		double lowest_possible_tp = nlc+inHouseCost;
490
        double lowest_possible_tp = nlc+inHouseCost;
490
		double our_tp =  snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*((mpItem.getCommission()/100)+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))-(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100))-(Math.max(20,(mpItem.getPgFee()/100)*snapdealItem.getSellingPrice())*(1+(mpItem.getServiceTax()/100)));
491
        double our_tp =  snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*((mpItem.getCommission()/100)+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))-(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100))-(Math.max(20,(mpItem.getPgFee()/100)*snapdealItem.getSellingPrice())*(1+(mpItem.getServiceTax()/100)));
491
		double commission=0.0;
492
        double commission=0.0;
492
		if ((mpItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
493
        if ((mpItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
493
			commission =  (((mpItem.getCommission()/100)+mpItem.getPgFee()/100)*snapdealItem.getSellingPrice());
494
            commission =  (((mpItem.getCommission()/100)+mpItem.getPgFee()/100)*snapdealItem.getSellingPrice());
494
		}
495
        }
495
		else{
496
        else{
496
			commission =  ((mpItem.getCommission()/100)*snapdealItem.getSellingPrice()+20);
497
            commission =  ((mpItem.getCommission()/100)*snapdealItem.getSellingPrice()+20);
497
		}
498
        }
498
		double service_tax = (mpItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCostMarketplace());
499
        double service_tax = (mpItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCostMarketplace());
499
		double lowest_possible_sp = 0.0;
500
        double lowest_possible_sp = 0.0;
500
		if ((mpItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
501
        if ((mpItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
501
			lowest_possible_sp = (nlc+(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat()/100))+(15+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-((mpItem.getCommission()/100)+mpItem.getEmiFee()/100+mpItem.getPgFee()/100)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat())/100)-(mpItem.getReturnProvision()/100)*(1+(mpItem.getVat())/100));
502
            lowest_possible_sp = (nlc+(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat()/100))+(mpItem.getPackagingCost()+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-((mpItem.getCommission()/100)+mpItem.getEmiFee()/100+mpItem.getPgFee()/100)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat())/100)-(mpItem.getReturnProvision()/100)*(1+(mpItem.getVat())/100));
502
		}
503
        }
503
		else{
504
        else{
504
			lowest_possible_sp = (nlc+(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee()+20)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat()/100))+(15+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-((mpItem.getCommission()/100)+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat())/100)-(mpItem.getReturnProvision()/100)*(1+(mpItem.getVat())/100));
505
            lowest_possible_sp = (nlc+(snapdealItem.getCourierCostMarketplace()+mpItem.getClosingFee()+20)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat()/100))+(mpItem.getPackagingCost()+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-((mpItem.getCommission()/100)+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat())/100)-(mpItem.getReturnProvision()/100)*(1+(mpItem.getVat())/100));
505
		}
506
        }
506
		double vat_rate_prod = getVatRateForItem(warehouse,snapdealItem.getSellingPrice(),snapdealItem.getItem_id());
507
        double vat_rate_prod = getVatRateForItem(warehouse,snapdealItem.getSellingPrice(),snapdealItem.getItem_id());
507
		JSONObject x = new JSONObject();
508
        JSONObject x = new JSONObject();
508
		x.put("NLC", nlc);
509
        x.put("NLC", nlc);
509
		x.put("VAT", vat);
510
        x.put("VAT", vat);
510
		x.put("COURIER COST",getCourierCost(weight));
511
        x.put("COURIER COST",getCourierCost(weight));
511
		x.put("LOWEST POS TP", lowest_possible_tp);
512
        x.put("LOWEST POS TP", lowest_possible_tp);
512
		x.put("TP", our_tp);
513
        x.put("TP", our_tp);
513
		x.put("COMMISSION", commission);
514
        x.put("COMMISSION", commission);
514
		x.put("SERVICE TAX", service_tax);
515
        x.put("SERVICE TAX", service_tax);
515
		x.put("LOWEST POS SP", lowest_possible_sp);
516
        x.put("LOWEST POS SP", lowest_possible_sp);
516
		x.put("VAT RATE",vat_rate_prod);
517
        x.put("VAT RATE",vat_rate_prod);
517
		logger.info("Snapdeal Backend validation "+x.toString());
518
        logger.info("Snapdeal Backend validation "+x.toString());
518
		boolean compare_result=true;
519
        boolean compare_result=true;
519
 
520
 
520
		if(!(getCourierCost(weight)==snapdealItem.getCourierCost())){
521
        if(!(mpItem.getPackagingCost()==computePackagingCost(categoryId))){
521
			compare_result=false;
522
            compare_result=false;
522
		}
523
        }
523
 
524
 
524
		if(!(vat_rate_prod==mpItem.getVat())){
525
        if(!(getCourierCost(weight)==snapdealItem.getCourierCost())){
525
			compare_result=false;
526
            compare_result=false;
526
		}
527
        }
527
 
528
 
528
		if(!(nlc==snapdealItem.getMaxNlc())){
529
        if(!(vat_rate_prod==mpItem.getVat())){
529
			compare_result=false;
530
            compare_result=false;
530
		}
531
        }
531
		if(!(lowest_possible_tp-mpItem.getMinimumPossibleTp()>-1 && lowest_possible_tp-mpItem.getMinimumPossibleTp()<1)){
532
 
532
			compare_result=false;
533
        if(!(nlc==snapdealItem.getMaxNlc())){
533
		}
534
            compare_result=false;
534
		if(!(our_tp-snapdealItem.getTransferPrice()>-1 && our_tp-snapdealItem.getTransferPrice()<1)){
535
        }
535
			compare_result=false;
536
        if(!(lowest_possible_tp-mpItem.getMinimumPossibleTp()>-1 && lowest_possible_tp-mpItem.getMinimumPossibleTp()<1)){
536
		}
537
            compare_result=false;
537
		if(!(commission-snapdealItem.getCommission()>-1 && commission-snapdealItem.getCommission()<1)){
538
        }
538
			compare_result=false;
539
        if(!(our_tp-snapdealItem.getTransferPrice()>-1 && our_tp-snapdealItem.getTransferPrice()<1)){
539
		}
540
            compare_result=false;
540
		if(!(service_tax-snapdealItem.getServiceTax()>-1 && service_tax-snapdealItem.getServiceTax()<1)){
541
        }
541
			compare_result=false;
542
        if(!(commission-snapdealItem.getCommission()>-1 && commission-snapdealItem.getCommission()<1)){
542
		}
543
            compare_result=false;
543
		if(!(lowest_possible_sp-mpItem.getMinimumPossibleSp()>-1 && lowest_possible_sp-mpItem.getMinimumPossibleSp()<1)){
544
        }
544
			compare_result=false;
545
        if(!(service_tax-snapdealItem.getServiceTax()>-1 && service_tax-snapdealItem.getServiceTax()<1)){
545
		}
546
            compare_result=false;
546
		return compare_result;
547
        }
547
 
548
        if(!(lowest_possible_sp-mpItem.getMinimumPossibleSp()>-1 && lowest_possible_sp-mpItem.getMinimumPossibleSp()<1)){
548
	}
549
            compare_result=false;
549
 
550
        }
550
	public double getVatRateForItem(Warehouse warehouse, double sellingPrice,long itemId) throws CatalogServiceException, TException{
551
        return compare_result;
551
		Client catalogClientProd = new CatalogClient().getClient();
552
 
552
		return catalogClientProd.getVatPercentageForItem(itemId, warehouse.getStateId(), sellingPrice);
553
    }
553
	}
554
 
554
 
555
    private double computePackagingCost(Long categoryId) {
555
	public double getNlcForWarehouse(long warehouseId,long item_id) throws TException{
556
        double pc = 15.0;
556
		InventoryClient inventoryServiceClient = new InventoryClient();
557
        if (categoryId==10006 || categoryId==10010){
557
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
558
            pc =pc + 43.0;
558
		return inventoryClient.getNlcForWarehouse(warehouseId, item_id);
559
        }
559
	}
560
        return pc;
560
 
561
    }
561
	public double getCourierCost(double weight){
562
 
562
		double cCost = 45.0;
563
    public double getVatRateForItem(Warehouse warehouse, double sellingPrice,long itemId) throws CatalogServiceException, TException{
563
		int slabs = (int) ((weight+.05 - .001)/(.5));
564
        Client catalogClientProd = new CatalogClient().getClient();
564
		for(int i=0;i<slabs;i++){
565
        return catalogClientProd.getVatPercentageForItem(itemId, warehouse.getStateId(), sellingPrice);
565
			cCost = cCost + 35;
566
    }
566
		}
567
 
567
		return cCost;
568
    public double getNlcForWarehouse(long warehouseId,long item_id) throws TException{
568
	}
569
        InventoryClient inventoryServiceClient = new InventoryClient();
569
 
570
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
570
	public void getLastNDaySaleForItem(String itemId,String days) {
571
        return inventoryClient.getNlcForWarehouse(warehouseId, item_id);
571
		try{
572
    }
572
			InventoryClient inventoryServiceClient = new InventoryClient();
573
 
573
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
574
    public double getCourierCost(double weight){
574
			List<OOSStatus> oosStatuses = inventoryClient.getOosStatusesForXDaysForItem(Long.valueOf(itemId), 7, Integer.valueOf(days));
575
        double cCost = 45.0;
575
			String lastNdaySale="";
576
        int slabs = (int) ((weight+.05 - .001)/(.5));
576
			double avgSale = 0.0;
577
        for(int i=0;i<slabs;i++){
577
			long count = 0,sale = 0;
578
            cCost = cCost + 35;
578
			for(OOSStatus oosStatus : oosStatuses){
579
        }
579
				if(oosStatus.isIs_oos()){
580
        return cCost;
580
					lastNdaySale += "X-";
581
    }
581
				}else{
582
 
582
					lastNdaySale += oosStatus.getNum_orders() + "-";
583
    public void getLastNDaySaleForItem(String itemId,String days) {
583
					sale = sale + oosStatus.getNum_orders();
584
        try{
584
					count+=1;
585
            InventoryClient inventoryServiceClient = new InventoryClient();
585
				}
586
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
586
			}
587
            List<OOSStatus> oosStatuses = inventoryClient.getOosStatusesForXDaysForItem(Long.valueOf(itemId), 7, Integer.valueOf(days));
587
			lastNdaySale = lastNdaySale.substring(0, lastNdaySale.length()-1);
588
            String lastNdaySale="";
588
			lastNdaySale += "\n";
589
            double avgSale = 0.0;
589
			setnDaySale(lastNdaySale);
590
            long count = 0,sale = 0;
590
			if (count!=0){
591
            for(OOSStatus oosStatus : oosStatuses){
591
				setAvgSale(String.valueOf(roundTwoDecimals(sale/(double)count)));
592
                if(oosStatus.isIs_oos()){
592
			}
593
                    lastNdaySale += "X-";
593
			else{
594
                }else{
594
				setAvgSale("0");
595
                    lastNdaySale += oosStatus.getNum_orders() + "-";
595
			}
596
                    sale = sale + oosStatus.getNum_orders();
596
		}
597
                    count+=1;
597
		catch (Exception e){
598
                }
598
			setAvgSale("0");
599
            }
599
			setnDaySale("Unable to fetch");
600
            lastNdaySale = lastNdaySale.substring(0, lastNdaySale.length()-1);
600
			logger.error("Unable to get last n day sale",e);
601
            lastNdaySale += "\n";
601
		}
602
            setnDaySale(lastNdaySale);
602
 
603
            if (count!=0){
603
	}
604
                setAvgSale(String.valueOf(roundTwoDecimals(sale/(double)count)));
604
 
605
            }
605
 
606
            else{
606
	private MarketplaceItems updateMarketplaceItemDetails(MarketplaceItems mpItem){
607
                setAvgSale("0");
607
		mpItem.setItemId(Long.valueOf(itemId));
608
            }
608
		mpItem.setSource(7);
609
        }
609
		mpItem.setVat(Double.valueOf(vat));
610
        catch (Exception e){
610
		mpItem.setCourierCost(Double.valueOf(courierCost));
611
            setAvgSale("0");
611
		mpItem.setOtherCost(Double.valueOf(otherCost));
612
            setnDaySale("Unable to fetch");
612
		mpItem.setCurrentSp(Double.valueOf(sellingPrice));
613
            logger.error("Unable to get last n day sale",e);
613
		mpItem.setCurrentTp(Double.valueOf(transferPrice));
614
        }
614
		mpItem.setAutoDecrement(Boolean.valueOf(isAutoDecrement));
615
 
615
		mpItem.setAutoIncrement(Boolean.valueOf(isAutoIncrement));
616
    }
616
		mpItem.setManualFavourite(Boolean.valueOf(isManualFavourite));
617
 
617
		mpItem.setMinimumPossibleSp(Double.valueOf(minPosSp));
618
 
618
		mpItem.setMinimumPossibleTp(Double.valueOf(minPosTp));
619
    private MarketplaceItems updateMarketplaceItemDetails(MarketplaceItems mpItem){
619
		mpItem.setMaximumSellingPrice(Double.valueOf(maxSp));
620
        mpItem.setItemId(Long.valueOf(itemId));
620
		return mpItem;
621
        mpItem.setSource(7);
621
	}
622
        mpItem.setVat(Double.valueOf(vat));
622
 
623
        mpItem.setCourierCost(Double.valueOf(courierCost));
623
	private void sendAlert(long itemId,double sp,double minSp){
624
        mpItem.setOtherCost(Double.valueOf(otherCost));
624
		Item item;
625
        mpItem.setCurrentSp(Double.valueOf(sellingPrice));
625
		try{
626
        mpItem.setCurrentTp(Double.valueOf(transferPrice));
626
			Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
627
        mpItem.setAutoDecrement(Boolean.valueOf(isAutoDecrement));
627
			item= catalogClient.getItem(itemId);
628
        mpItem.setAutoIncrement(Boolean.valueOf(isAutoIncrement));
628
		}
629
        mpItem.setManualFavourite(Boolean.valueOf(isManualFavourite));
629
		catch(Exception e){
630
        mpItem.setMinimumPossibleSp(Double.valueOf(minPosSp));
630
			e.printStackTrace();
631
        mpItem.setMinimumPossibleTp(Double.valueOf(minPosTp));
631
			return;
632
        mpItem.setMaximumSellingPrice(Double.valueOf(maxSp));
632
		}
633
        return mpItem;
633
		String emailSubjectTxt="Snapdeal SP is set below Min Possible SP";
634
    }
634
		String[] sendTo=new String[]{ "kshitij.sood@saholic.com","rajneesh.arora@saholic.com","rajveer.singh@saholic.com","vikram.raghav@saholic.com"};
635
 
635
		String text = "Item Details-\nItem Id: "+itemId+"\nProduct Name: "+item.getBrand()+" "+item.getModelName()+" "+item.getModelNumber()+" "+item.getColor()+"\nSellingPrice: "+sp+"\nMinPossibleSp: "+minSp+"\nUpdated By: "+session.getAttribute(ReportsUtils.USER_NAME).toString();
636
    private void sendAlert(long itemId,double sp,double minSp){
636
		logger.info(text);
637
        Item item;
637
		String emailFromAddress = "build@shop2020.in";
638
        try{
638
		String password = "cafe@nes";
639
            Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
639
		GmailUtils mailer = new GmailUtils();
640
            item= catalogClient.getItem(itemId);
640
		try {
641
        }
641
			mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
642
        catch(Exception e){
642
		}
643
            e.printStackTrace();
643
		catch (Exception e) {
644
            return;
644
			logger.info(e.toString());
645
        }
645
		}
646
        String emailSubjectTxt="Snapdeal SP is set below Min Possible SP";
646
	}
647
        String[] sendTo=new String[]{ "kshitij.sood@saholic.com","rajneesh.arora@saholic.com","rajveer.singh@saholic.com","vikram.raghav@saholic.com"};
647
 
648
        String text = "Item Details-\nItem Id: "+itemId+"\nProduct Name: "+item.getBrand()+" "+item.getModelName()+" "+item.getModelNumber()+" "+item.getColor()+"\nSellingPrice: "+sp+"\nMinPossibleSp: "+minSp+"\nUpdated By: "+session.getAttribute(ReportsUtils.USER_NAME).toString();
648
	public String addNewItem() throws TException, NumberFormatException, InventoryServiceException, CatalogServiceException, JSONException{
649
        logger.info(text);
649
		InventoryClient inventoryServiceClient = new InventoryClient();
650
        String emailFromAddress = "build@shop2020.in";
650
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
651
        String password = "cafe@nes";
651
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
652
        GmailUtils mailer = new GmailUtils();
652
		Item item = catalogClient.getItem(Long.valueOf(itemId));
653
        try {
653
		//Client catalogClientProd = new CatalogClient().getClient();
654
            mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
654
		MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
655
        }
655
 
656
        catch (Exception e) {
656
		if (mpCosting.getSource()==0){
657
            logger.info(e.toString());
657
			throw new CatalogServiceException();
658
        }
658
		}
659
    }
659
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
660
 
660
		/*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
661
    public String addNewItem() throws TException, NumberFormatException, InventoryServiceException, CatalogServiceException, JSONException{
-
 
662
        InventoryClient inventoryServiceClient = new InventoryClient();
-
 
663
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
664
        Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
665
        Item item = catalogClient.getItem(Long.valueOf(itemId));
-
 
666
        //Client catalogClientProd = new CatalogClient().getClient();
-
 
667
        MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
-
 
668
 
-
 
669
        if (mpCosting.getSource()==0){
-
 
670
            throw new CatalogServiceException();
-
 
671
        }
-
 
672
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
-
 
673
        /*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
661
			throw new InventoryServiceException();
674
			throw new InventoryServiceException();
662
		}*/
675
		}*/
663
		SnapdealItem snapdealItem = new SnapdealItem();
676
        SnapdealItem snapdealItem = new SnapdealItem();
664
		snapdealItem.setItem_id(Long.valueOf(itemId));
677
        snapdealItem.setItem_id(Long.valueOf(itemId));
665
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
678
        snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
666
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
679
        snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
667
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
680
        snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
668
		snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
681
        snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
669
		snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
682
        snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
670
		snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
683
        snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
671
		snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
684
        snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
672
		snapdealItem.setCourierCost(Double.valueOf(courierCost));
685
        snapdealItem.setCourierCost(Double.valueOf(courierCost));
673
		snapdealItem.setCommission(Double.valueOf(commission));
686
        snapdealItem.setCommission(Double.valueOf(commission));
674
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
687
        snapdealItem.setServiceTax(Double.valueOf(serviceTax));
675
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
688
        snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
676
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
689
        snapdealItem.setSkuAtSnapdeal(sdItemCode);
677
		snapdealItem.setSupc(supc);
690
        snapdealItem.setSupc(supc);
678
		snapdealItem.setUpdatedBy(getUserName());
691
        snapdealItem.setUpdatedBy(getUserName());
679
		snapdealItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
692
        snapdealItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
680
 
693
 
681
		MarketplaceItems mpItem = new MarketplaceItems();
694
        MarketplaceItems mpItem = new MarketplaceItems();
682
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
695
        MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
683
		/*double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
696
        /*double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
684
		t_mpItem.setVat(vat);*/
697
		t_mpItem.setVat(vat);*/
685
		t_mpItem.setCommission(mpCosting.getCommission());
698
        t_mpItem.setCommission(mpCosting.getCommission());
686
		t_mpItem.setServiceTax(mpCosting.getServiceTax());
699
        t_mpItem.setServiceTax(mpCosting.getServiceTax());
687
		t_mpItem.setReturnProvision(mpCosting.getReturnProvision());
700
        t_mpItem.setReturnProvision(mpCosting.getReturnProvision());
688
		t_mpItem.setEmiFee(mpCosting.getEmiFee());
701
        t_mpItem.setEmiFee(mpCosting.getEmiFee());
689
		t_mpItem.setClosingFee(mpCosting.getClosingFee());
702
        t_mpItem.setClosingFee(mpCosting.getClosingFee());
690
		t_mpItem.setPgFee(mpCosting.getPgFee());
703
        t_mpItem.setPgFee(mpCosting.getPgFee());
691
		t_mpItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
704
        t_mpItem.setCourierCostMarketplace(Double.valueOf(courierCostMarketplace));
-
 
705
        t_mpItem.setPackagingCost(Double.valueOf(packagingCost));
692
		if(!compareParameters(t_mpItem,snapdealItem,warehouse,item.getWeight())){
706
        if(!compareParameters(t_mpItem,snapdealItem,warehouse,item.getWeight(),item.getCategory())){
693
			setComparsionResult("0");
707
            setComparsionResult("0");
694
			return "snapdeal-update-result";
708
            return "snapdeal-update-result";
695
		}
709
        }
696
		else{
710
        else{
697
			setComparsionResult("1");
711
            setComparsionResult("1");
698
		}
712
        }
699
		snapdealItem.setMarketplaceItems(t_mpItem);
713
        snapdealItem.setMarketplaceItems(t_mpItem);
700
		Long timestamp = System.currentTimeMillis();
714
        Long timestamp = System.currentTimeMillis();
701
		boolean result = catalogClient.addOrUpdateSnapdealItem(snapdealItem);
715
        boolean result = catalogClient.addOrUpdateSnapdealItem(snapdealItem);
702
		if(!result){
716
        if(!result){
703
			throw new CatalogServiceException();
717
            throw new CatalogServiceException();
704
		}
718
        }
705
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
719
        if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
706
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
720
            sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
707
		}
721
        }
708
		if (Boolean.valueOf(live) && (!snapdealItem.isSuppressPriceFeed()) && snapdealItem.isIsListedOnSnapdeal()){
722
        if (Boolean.valueOf(live) && (!snapdealItem.isSuppressPriceFeed()) && snapdealItem.isIsListedOnSnapdeal()){
709
			logger.info("Calling Method to update new item price at snapdeal");
723
            logger.info("Calling Method to update new item price at snapdeal");
710
			UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,timestamp);
724
            UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(Float.valueOf(sellingPrice),supc,item,timestamp);
711
			logger.info("Calling Thread to update new item price at snapdeal");
725
            logger.info("Calling Thread to update new item price at snapdeal");
712
			updatePriceOnSnapdeal.start();
726
            updatePriceOnSnapdeal.start();
713
		}
727
        }
714
		return "snapdeal-update-result";
728
        return "snapdeal-update-result";
715
	}
729
    }
716
 
730
 
717
 
731
 
718
	public String getAddNewItemForm(){
732
    public String getAddNewItemForm(){
719
		return "snapdeal-add-item";
733
        return "snapdeal-add-item";
720
	}
734
    }
721
	
735
 
722
	/*public String getCompetitionAnalyis() throws NumberFormatException, TException{
736
    /*public String getCompetitionAnalyis() throws NumberFormatException, TException{
723
	    Client cc = new CatalogClient().getClient();
737
	    Client cc = new CatalogClient().getClient();
724
	    compData = cc.getMarketplaceHistory(7, 0, Long.valueOf(itemId));
738
	    compData = cc.getMarketplaceHistory(7, 0, Long.valueOf(itemId));
725
	    //Gson gson = new Gson();
739
	    //Gson gson = new Gson();
726
	    //competitionJson = gson.toJson(compData);
740
	    //competitionJson = gson.toJson(compData);
727
	    return "competition-details";
741
	    return "competition-details";
728
	    
742
 
729
	}*/
743
	}*/
730
 
744
 
731
	public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException, InventoryServiceException{
745
    public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException, InventoryServiceException{
732
		Client catalogClientProd = new CatalogClient().getClient();
746
        Client catalogClientProd = new CatalogClient().getClient();
733
		Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
747
        Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
734
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
748
        SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
735
		MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
749
        MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
736
		if (snapdealItem.getItem_id()!=0){
750
        if (snapdealItem.getItem_id()!=0){
737
			throw new CatalogServiceException();
751
            throw new CatalogServiceException();
738
		}
752
        }
739
		Item item = catalogClient.getItem(Long.valueOf(itemId));
753
        Item item = catalogClient.getItem(Long.valueOf(itemId));
740
		if (item.getId()==0){
754
        if (item.getId()==0){
741
			throw new CatalogServiceException();
755
            throw new CatalogServiceException();
742
		}
756
        }
743
		InventoryClient inventoryServiceClient = new InventoryClient();
757
        InventoryClient inventoryServiceClient = new InventoryClient();
744
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
758
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
745
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
759
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
746
		/*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
760
        /*if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
747
			throw new InventoryServiceException();
761
			throw new InventoryServiceException();
748
		}*/
762
		}*/
749
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
763
        double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
750
		double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
764
        double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
751
		if (maxNLC==0){
765
        if (maxNLC==0){
752
			throw new InventoryServiceException();
766
            throw new InventoryServiceException();
753
		}
767
        }
754
		itemObj = new JSONObject();
768
        itemObj = new JSONObject();
755
		itemObj.put("ItemId", item.getId());
769
        itemObj.put("ItemId", item.getId());
756
		itemObj.put("Brand", item.getBrand());
770
        itemObj.put("Brand", item.getBrand());
757
		itemObj.put("ModelName", item.getModelName());
771
        itemObj.put("ModelName", item.getModelName());
758
		itemObj.put("ModelNumber", item.getModelNumber());
772
        itemObj.put("ModelNumber", item.getModelNumber());
759
		itemObj.put("Color", item.getColor());
773
        itemObj.put("Color", item.getColor());
760
		itemObj.put("Weight", item.getWeight());
774
        itemObj.put("Weight", item.getWeight());
761
		itemObj.put("Risky", item.isRisky());
775
        itemObj.put("Risky", item.isRisky());
762
		itemObj.put("Status", item.getItemStatus());
776
        itemObj.put("Status", item.getItemStatus());
763
		itemObj.put("MRP", item.getMrp());
777
        itemObj.put("MRP", item.getMrp());
764
		itemObj.put("SellingPrice", item.getSellingPrice());
778
        itemObj.put("SellingPrice", item.getSellingPrice());
765
		itemObj.put("MaxNlc", maxNLC);
779
        itemObj.put("MaxNlc", maxNLC);
766
		itemObj.put("VatRate", vat);
780
        itemObj.put("VatRate", vat);
767
		itemObj.put("CommissionRate", mpCosting.getCommission());
781
        itemObj.put("CommissionRate", mpCosting.getCommission());
768
		itemObj.put("ServiceTaxRate", mpCosting.getServiceTax());
782
        itemObj.put("ServiceTaxRate", mpCosting.getServiceTax());
769
		itemObj.put("ReturnProvision", mpCosting.getReturnProvision());
783
        itemObj.put("ReturnProvision", mpCosting.getReturnProvision());
770
		itemObj.put("EmiFee", mpCosting.getEmiFee());
784
        itemObj.put("EmiFee", mpCosting.getEmiFee());
771
		itemObj.put("ClosingFee", mpCosting.getClosingFee());
785
        itemObj.put("ClosingFee", mpCosting.getClosingFee());
772
		itemObj.put("PgFee", mpCosting.getPgFee());
786
        itemObj.put("PgFee", mpCosting.getPgFee());
-
 
787
        itemObj.put("PackagingCost", computePackagingCost(item.getCategory()));
773
		return "item-details-json";
788
        return "item-details-json";
774
	}
789
    }
775
 
790
 
776
	public String ke$ha() throws NumberFormatException, TException, JSONException, InventoryServiceException, CatalogServiceException{
791
    public String ke$ha() throws NumberFormatException, TException, JSONException, InventoryServiceException, CatalogServiceException{
777
		Client catalogClientProd = new CatalogClient().getClient();
792
        Client catalogClientProd = new CatalogClient().getClient();
778
		InventoryClient inventoryServiceClient = new InventoryClient();
793
        InventoryClient inventoryServiceClient = new InventoryClient();
779
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
794
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
780
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
795
        Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
781
		//if (warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD){
796
        //if (warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD){
782
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
797
        double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
783
		double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
798
        double vat = catalogClientProd.getVatPercentageForItem(Long.valueOf(itemId), warehouse.getStateId(), Double.valueOf(sellingPrice));
784
		itemObj = new JSONObject();
799
        itemObj = new JSONObject();
785
		itemObj.put("ItemId", itemId);
800
        itemObj.put("ItemId", itemId);
786
		itemObj.put("WarehouseId", warehouseId);
801
        itemObj.put("WarehouseId", warehouseId);
787
		itemObj.put("MaxNlc", maxNLC);
802
        itemObj.put("MaxNlc", maxNLC);
788
		itemObj.put("VatRate", vat);
803
        itemObj.put("VatRate", vat);
789
		/*}
804
        /*}
790
		else{
805
		else{
791
			itemObj = new JSONObject();
806
			itemObj = new JSONObject();
792
			throw new InventoryServiceException();
807
			throw new InventoryServiceException();
793
		}*/
808
		}*/
794
		return "item-details-json";
809
        return "item-details-json";
795
	}
810
    }
796
 
811
 
797
	public ItemInventory getItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
812
    public ItemInventory getItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
798
		try{
813
        try{
799
			InventoryClient inventoryServiceClient = new InventoryClient();
814
            InventoryClient inventoryServiceClient = new InventoryClient();
800
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
815
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
801
			in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
816
            in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
802
			return thriftItemInventory;
817
            return thriftItemInventory;
803
		}
818
        }
804
		catch(Exception e){
819
        catch(Exception e){
805
			logger.error("Unable to get inventory info for item",e);
820
            logger.error("Unable to get inventory info for item",e);
806
			return null;
821
            return null;
807
		}
822
        }
808
	}
823
    }
809
 
824
 
810
 
825
 
811
 
826
 
812
	public Warehouse getWarehouse(String warehouseId,String itemId) throws NumberFormatException, TException, InventoryServiceException { 
827
    public Warehouse getWarehouse(String warehouseId,String itemId) throws NumberFormatException, TException, InventoryServiceException { 
813
		InventoryClient inventoryServiceClient = new InventoryClient();
828
        InventoryClient inventoryServiceClient = new InventoryClient();
814
		holdInventoryMap =inventoryServiceClient.getClient().getHeldInventoryMapForItem(Long.valueOf(itemId), Long.valueOf(warehouseId));
829
        holdInventoryMap =inventoryServiceClient.getClient().getHeldInventoryMapForItem(Long.valueOf(itemId), Long.valueOf(warehouseId));
815
		return inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
830
        return inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
816
	}
831
    }
817
 
832
 
818
	public Map<Integer, Long> getHoldInventoryMapForItem(){
833
    public Map<Integer, Long> getHoldInventoryMapForItem(){
819
		return holdInventoryMap;
834
        return holdInventoryMap;
820
	}
835
    }
821
 
836
 
822
	public void changeHeldForSource() throws NumberFormatException, TException, InventoryServiceException{
837
    public void changeHeldForSource() throws NumberFormatException, TException, InventoryServiceException{
823
		InventoryClient inventoryServiceClient = new InventoryClient();
838
        InventoryClient inventoryServiceClient = new InventoryClient();
824
		Warehouse warehouse = inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
839
        Warehouse warehouse = inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
825
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
840
        if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
826
			throw new InventoryServiceException();
841
            throw new InventoryServiceException();
827
		}
842
        }
828
		inventoryServiceClient.getClient().addUpdateHoldInventory(Long.valueOf(itemId),Long.valueOf(warehouseId),Long.valueOf(held),7);
843
        inventoryServiceClient.getClient().addUpdateHoldInventory(Long.valueOf(itemId),Long.valueOf(warehouseId),Long.valueOf(held),7);
829
	}
844
    }
830
 
845
 
831
	public void downloadSnapdealListings() throws IOException, TException{
846
    public void downloadSnapdealListings() throws IOException, TException{
832
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
847
        File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
833
		HSSFWorkbook hwb=new HSSFWorkbook();
848
        HSSFWorkbook hwb=new HSSFWorkbook();
834
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
849
        HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
835
		HSSFRow rowhead=   sheet.createRow((short)0);
850
        HSSFRow rowhead=   sheet.createRow((short)0);
836
		rowhead.createCell((short) 0).setCellValue("ITEM-ID");
851
        rowhead.createCell((short) 0).setCellValue("ITEM-ID");
837
		rowhead.createCell((short) 1).setCellValue("PRODUCT");
852
        rowhead.createCell((short) 1).setCellValue("PRODUCT");
838
		rowhead.createCell((short) 2).setCellValue("WAREHOUSE-ID");
853
        rowhead.createCell((short) 2).setCellValue("WAREHOUSE-ID");
839
		rowhead.createCell((short) 3).setCellValue("EXCEPTIONAL-PRICE");
854
        rowhead.createCell((short) 3).setCellValue("EXCEPTIONAL-PRICE");
840
		rowhead.createCell((short) 4).setCellValue("SNAPDEAL-LISTED");
855
        rowhead.createCell((short) 4).setCellValue("SNAPDEAL-LISTED");
841
		rowhead.createCell((short) 5).setCellValue("TRANSFER-PRICE");
856
        rowhead.createCell((short) 5).setCellValue("TRANSFER-PRICE");
842
		rowhead.createCell((short) 6).setCellValue("SELLING-PRICE");
857
        rowhead.createCell((short) 6).setCellValue("SELLING-PRICE");
843
		rowhead.createCell((short) 7).setCellValue("LOWEST POSSIBLE SP");
858
        rowhead.createCell((short) 7).setCellValue("LOWEST POSSIBLE SP");
844
		rowhead.createCell((short) 8).setCellValue("LOWEST POSSIBLE TP");
859
        rowhead.createCell((short) 8).setCellValue("LOWEST POSSIBLE TP");
845
		rowhead.createCell((short) 9).setCellValue("OTHER COST");
860
        rowhead.createCell((short) 9).setCellValue("OTHER COST");
846
		rowhead.createCell((short) 10).setCellValue("COURIER-COST");
861
        rowhead.createCell((short) 10).setCellValue("COURIER-COST");
847
		rowhead.createCell((short) 11).setCellValue("COURIER-COST-Snapdeal");
862
        rowhead.createCell((short) 11).setCellValue("COURIER-COST-Snapdeal");
848
		rowhead.createCell((short) 12).setCellValue("COMMISION");
863
        rowhead.createCell((short) 12).setCellValue("COMMISION");
849
		rowhead.createCell((short) 13).setCellValue("SERVICE-TAX");
864
        rowhead.createCell((short) 13).setCellValue("SERVICE-TAX");
850
		rowhead.createCell((short) 14).setCellValue("Suppress Inventory Feed");
865
        rowhead.createCell((short) 14).setCellValue("Suppress Inventory Feed");
851
		rowhead.createCell((short) 15).setCellValue("Suppress Price Feed");
866
        rowhead.createCell((short) 15).setCellValue("Suppress Price Feed");
852
		rowhead.createCell((short) 16).setCellValue("AUTO FAVOURITE");
867
        rowhead.createCell((short) 16).setCellValue("AUTO FAVOURITE");
853
		rowhead.createCell((short) 17).setCellValue("MANUAL FAVOURITE");
868
        rowhead.createCell((short) 17).setCellValue("MANUAL FAVOURITE");
854
		rowhead.createCell((short) 18).setCellValue("AUTO INCREMENT");
869
        rowhead.createCell((short) 18).setCellValue("AUTO INCREMENT");
855
		rowhead.createCell((short) 19).setCellValue("AUTO DECREMENT");
870
        rowhead.createCell((short) 19).setCellValue("AUTO DECREMENT");
856
		rowhead.createCell((short) 20).setCellValue("Max NLC");
871
        rowhead.createCell((short) 20).setCellValue("Max NLC");
857
		rowhead.createCell((short) 21).setCellValue("SKU @ Snapdeal");
872
        rowhead.createCell((short) 21).setCellValue("SKU @ Snapdeal");
858
		rowhead.createCell((short) 22).setCellValue("SUPC");
873
        rowhead.createCell((short) 22).setCellValue("SUPC");
859
		Client catalogClient = null;
874
        Client catalogClient = null;
860
		List<SnapdealItemDetails> snapdealItems = null;
875
        List<SnapdealItem> snapdealItems = null;
861
		try {
876
        try {
862
			catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
877
            catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
863
			snapdealItems = catalogClient.getAllSnapdealItems();
878
            snapdealItems = catalogClient.getAllSnapdealMarketplaceItem();
864
		} catch (Exception e) {
879
        } catch (Exception e) {
865
			e.printStackTrace();
880
            e.printStackTrace();
866
		}
881
        }
867
		int iterator=1;
882
        int iterator=1;
868
		Item item;
883
        Item item;
869
		MarketplaceItems marketplaceItem;
884
        MarketplaceItems marketplaceItem;
870
		for(SnapdealItemDetails snapdealItem:snapdealItems){
885
        for(SnapdealItem snapdealItem:snapdealItems){
871
			marketplaceItem = catalogClient.getMarketplacedetailsForItem(snapdealItem.getItem_id(), 7);
886
            marketplaceItem = snapdealItem.getMarketplaceItems();
872
			try {
887
            item = snapdealItem.getItem();
873
				item = catalogClient.getItem(snapdealItem.getItem_id());
888
            HSSFRow row = sheet.createRow((short)iterator);
874
			} catch (CatalogServiceException e) {
889
            row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
875
				e.printStackTrace();
890
            row.createCell((short) 1).setCellValue(getVaildName(item.getBrand())+" "+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor()));
876
				continue;
891
            row.createCell((short) 2).setCellValue(snapdealItem.getWarehouseId());
877
			}
892
            row.createCell((short) 3).setCellValue(roundTwoDecimals(snapdealItem.getExceptionPrice()));
878
			HSSFRow row = sheet.createRow((short)iterator);
893
            if(snapdealItem.isIsListedOnSnapdeal()){
879
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
894
                row.createCell((short) 4).setCellValue(1);
880
			row.createCell((short) 1).setCellValue(getVaildName(item.getBrand())+" "+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor()));
895
            }
881
			row.createCell((short) 2).setCellValue(snapdealItem.getWarehouseId());
896
            else{
882
			row.createCell((short) 3).setCellValue(roundTwoDecimals(snapdealItem.getExceptionPrice()));
897
                row.createCell((short) 4).setCellValue(0);
883
			if(snapdealItem.isIsListedOnSnapdeal()){
898
            }
884
				row.createCell((short) 4).setCellValue(1);
899
            row.createCell((short) 5).setCellValue(roundTwoDecimals(snapdealItem.getTransferPrice()));
885
			}
900
            row.createCell((short) 6).setCellValue(roundTwoDecimals(snapdealItem.getSellingPrice()));
886
			else{
901
            row.createCell((short) 7).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleSp()));
887
				row.createCell((short) 4).setCellValue(0);
902
            row.createCell((short) 8).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleTp()));
888
			}
903
            row.createCell((short) 9).setCellValue(roundTwoDecimals(marketplaceItem.getOtherCost()));
889
			row.createCell((short) 5).setCellValue(roundTwoDecimals(snapdealItem.getTransferPrice()));
904
            row.createCell((short) 10).setCellValue(snapdealItem.getCourierCost());
890
			row.createCell((short) 6).setCellValue(roundTwoDecimals(snapdealItem.getSellingPrice()));
905
            row.createCell((short) 11).setCellValue(snapdealItem.getCourierCostMarketplace());
891
			row.createCell((short) 7).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleSp()));
906
            row.createCell((short) 12).setCellValue(roundTwoDecimals(snapdealItem.getCommission()));
892
			row.createCell((short) 8).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleTp()));
907
            row.createCell((short) 13).setCellValue(roundTwoDecimals(snapdealItem.getServiceTax()));
893
			row.createCell((short) 9).setCellValue(roundTwoDecimals(marketplaceItem.getOtherCost()));
908
            if(snapdealItem.isSuppressInventoryFeed()){
894
			row.createCell((short) 10).setCellValue(snapdealItem.getCourierCost());
909
                row.createCell((short) 14).setCellValue(1);
895
			row.createCell((short) 11).setCellValue(snapdealItem.getCourierCostMarketplace());
910
            }
896
			row.createCell((short) 12).setCellValue(roundTwoDecimals(snapdealItem.getCommission()));
911
            else{
897
			row.createCell((short) 13).setCellValue(roundTwoDecimals(snapdealItem.getServiceTax()));
912
                row.createCell((short) 14).setCellValue(0);
898
			if(snapdealItem.isSuppressInventoryFeed()){
913
            }
899
				row.createCell((short) 14).setCellValue(1);
914
            if(snapdealItem.isSuppressPriceFeed()){
900
			}
915
                row.createCell((short) 15).setCellValue(1);
901
			else{
916
            }
902
				row.createCell((short) 14).setCellValue(0);
917
            else{
903
			}
918
                row.createCell((short) 15).setCellValue(0);
904
			if(snapdealItem.isSuppressPriceFeed()){
919
            }
905
				row.createCell((short) 15).setCellValue(1);
920
            if(marketplaceItem.isAutoFavourite()){
906
			}
921
                row.createCell((short) 16).setCellValue(1);
907
			else{
922
            }
908
				row.createCell((short) 15).setCellValue(0);
923
            else{
909
			}
924
                row.createCell((short) 16).setCellValue(0);
910
			if(marketplaceItem.isAutoFavourite()){
925
            }
911
				row.createCell((short) 16).setCellValue(1);
926
            if(marketplaceItem.isManualFavourite()){
912
			}
927
                row.createCell((short) 17).setCellValue(1);
913
			else{
928
            }
914
				row.createCell((short) 16).setCellValue(0);
929
            else{
915
			}
930
                row.createCell((short) 17).setCellValue(0);
916
			if(marketplaceItem.isManualFavourite()){
931
            }
917
				row.createCell((short) 17).setCellValue(1);
932
            if(marketplaceItem.isAutoIncrement()){
918
			}
933
                row.createCell((short) 18).setCellValue(1);
919
			else{
934
            }
920
				row.createCell((short) 17).setCellValue(0);
935
            else{
921
			}
936
                row.createCell((short) 18).setCellValue(0);
922
			if(marketplaceItem.isAutoIncrement()){
937
            }
923
				row.createCell((short) 18).setCellValue(1);
938
            if(marketplaceItem.isAutoDecrement()){
924
			}
939
                row.createCell((short) 19).setCellValue(1);
925
			else{
940
            }
926
				row.createCell((short) 18).setCellValue(0);
941
            else{
927
			}
942
                row.createCell((short) 19).setCellValue(0);
928
			if(marketplaceItem.isAutoDecrement()){
943
            }
929
				row.createCell((short) 19).setCellValue(1);
944
            row.createCell((short) 20).setCellValue(snapdealItem.getMaxNlc());
930
			}
945
            row.createCell((short) 21).setCellValue(snapdealItem.getSkuAtSnapdeal());
931
			else{
946
            row.createCell((short) 22).setCellValue(snapdealItem.getSupc());
932
				row.createCell((short) 19).setCellValue(0);
947
            iterator++;
933
			}
948
        }
934
			row.createCell((short) 20).setCellValue(snapdealItem.getMaxNlc());
949
 
935
			row.createCell((short) 21).setCellValue(snapdealItem.getSkuAtSnapdeal());
950
        FileOutputStream fileOut = null;
936
			row.createCell((short) 22).setCellValue(snapdealItem.getSupc());
951
        try {
937
			iterator++;
952
            fileOut = new FileOutputStream(file);
938
		}
953
        } catch (FileNotFoundException e) {
939
 
954
            // TODO Auto-generated catch block
940
		FileOutputStream fileOut = null;
955
            e.printStackTrace();
941
		try {
956
        }
942
			fileOut = new FileOutputStream(file);
957
        try {
943
		} catch (FileNotFoundException e) {
958
            hwb.write(fileOut);
944
			// TODO Auto-generated catch block
959
        } catch (IOException e) {
945
			e.printStackTrace();
960
            // TODO Auto-generated catch block
946
		}
961
            e.printStackTrace();
947
		try {
962
        }
948
			hwb.write(fileOut);
963
        try {
949
		} catch (IOException e) {
964
            fileOut.close();
950
			// TODO Auto-generated catch block
965
        } catch (IOException e) {
951
			e.printStackTrace();
966
            // TODO Auto-generated catch block
952
		}
967
            e.printStackTrace();
953
		try {
968
        }
954
			fileOut.close();
969
        byte[] buffer = new byte[(int)file.length()];
955
		} catch (IOException e) {
970
        InputStream input = null;
956
			// TODO Auto-generated catch block
971
        try {
957
			e.printStackTrace();
972
            int totalBytesRead = 0;
958
		}
973
            input = new BufferedInputStream(new FileInputStream(file));
959
		byte[] buffer = new byte[(int)file.length()];
974
            while(totalBytesRead < buffer.length){
960
		InputStream input = null;
975
                int bytesRemaining = buffer.length - totalBytesRead;
961
		try {
976
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
962
			int totalBytesRead = 0;
977
                if (bytesRead > 0){
963
			input = new BufferedInputStream(new FileInputStream(file));
978
                    totalBytesRead = totalBytesRead + bytesRead;
964
			while(totalBytesRead < buffer.length){
979
                }
965
				int bytesRemaining = buffer.length - totalBytesRead;
980
            }
966
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
981
        }
967
				if (bytesRead > 0){
982
        finally {
968
					totalBytesRead = totalBytesRead + bytesRead;
983
            input.close();
969
				}
984
            file.delete();
970
			}
985
        }
971
		}
986
 
972
		finally {
987
        response.setHeader("Content-Disposition", "attachment; filename=\"Snapdeal-Bulk-Listings.xls\"");
973
			input.close();
988
        response.setContentType("application/octet-stream");
974
			file.delete();
989
        ServletOutputStream sos;
975
		}
990
        try {
976
 
991
            sos = response.getOutputStream();
977
		response.setHeader("Content-Disposition", "attachment; filename=\"Snapdeal-Bulk-Listings.xls\"");
992
            sos.write(buffer);
978
		response.setContentType("application/octet-stream");
993
            sos.flush();
979
		ServletOutputStream sos;
994
        } catch (IOException e) {
980
		try {
995
            System.out.println("Unable to stream the manifest file");
981
			sos = response.getOutputStream();
996
        }   
982
			sos.write(buffer);
997
    }
983
			sos.flush();
998
 
984
		} catch (IOException e) {
999
 
985
			System.out.println("Unable to stream the manifest file");
1000
    public void uploadsnapdealBulkSheet() throws IOException, TException, NumberFormatException, InventoryServiceException, CatalogServiceException{
986
		}   
1001
        File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
987
	}
1002
        FileUtils.copyFile(this.file, fileToCreate);
988
 
1003
        FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
989
 
1004
        HSSFWorkbook workbook = new HSSFWorkbook(iFile);
990
	public void uploadsnapdealBulkSheet() throws IOException, TException, NumberFormatException, InventoryServiceException, CatalogServiceException{
1005
        HSSFSheet sheet = workbook.getSheetAt(0);
991
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
1006
        String updatedBy = getUserName();
992
		FileUtils.copyFile(this.file, fileToCreate);
1007
        Client catalogClient=null;
993
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
1008
        Client catalogClientProd=null;
994
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
1009
        StringBuilder sb = new StringBuilder();
995
		HSSFSheet sheet = workbook.getSheetAt(0);
1010
        try {
996
		String updatedBy = getUserName();
1011
            catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
997
		Client catalogClient=null;
1012
            catalogClientProd = new CatalogClient().getClient();
998
		Client catalogClientProd=null;
1013
        } catch (TTransportException e) {
999
		StringBuilder sb = new StringBuilder();
1014
            e.printStackTrace();
1000
		try {
1015
        }
1001
			catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1016
        InventoryClient inventoryServiceClient = new InventoryClient();
1002
			catalogClientProd = new CatalogClient().getClient();
1017
        in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1003
		} catch (TTransportException e) {
1018
 
1004
			e.printStackTrace();
1019
        for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
1005
		}
1020
            if (sheet.getLastRowNum()-1>100){
1006
		InventoryClient inventoryServiceClient = new InventoryClient();
1021
                sb.append("Number of items to update can't be greater than 100");
1007
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1022
                break;
1008
 
1023
            }
1009
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
1024
            SnapdealItem snapdealItem = null;
1010
			if (sheet.getLastRowNum()-1>100){
1025
            MarketplaceItems marketplaceItem = null;
1011
				sb.append("Number of items to update can't be greater than 100");
1026
            MarketplacePercentage mpCosting = null;
1012
				break;
1027
            Warehouse warehouse = null;
1013
			}
1028
            Item item = null;
1014
			SnapdealItem snapdealItem = null;
1029
            Long sku;
1015
			MarketplaceItems marketplaceItem = null;
1030
            boolean new_item = false;
1016
			MarketplacePercentage mpCosting = null;
1031
            if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
1017
			Warehouse warehouse = null;
1032
                continue;
1018
			Item item = null;
1033
            }
1019
			Long sku;
1034
            else {
1020
			boolean new_item = false;
1035
                sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
1021
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
1036
                snapdealItem = catalogClient.getSnapdealItem(sku);
1022
				continue;
1037
                mpCosting = catalogClient.getCostingForMarketplace(7, sku);
1023
			}
1038
                marketplaceItem  = catalogClient.getMarketplacedetailsForItem(sku, 7);
1024
			else {
1039
                marketplaceItem.setItemId(sku);
1025
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
1040
                marketplaceItem.setSource(7);
1026
				snapdealItem = catalogClient.getSnapdealItem(sku);
1041
                marketplaceItem.setCommission(mpCosting.getCommission());
1027
				mpCosting = catalogClient.getCostingForMarketplace(7, sku);
1042
                marketplaceItem.setServiceTax(mpCosting.getServiceTax());
1028
				marketplaceItem  = catalogClient.getMarketplacedetailsForItem(sku, 7);
1043
                marketplaceItem.setReturnProvision(mpCosting.getReturnProvision());
1029
				marketplaceItem.setItemId(sku);
1044
                marketplaceItem.setEmiFee(mpCosting.getEmiFee());
1030
				marketplaceItem.setSource(7);
1045
                marketplaceItem.setClosingFee(mpCosting.getClosingFee());
1031
				marketplaceItem.setCommission(mpCosting.getCommission());
1046
                marketplaceItem.setPgFee(mpCosting.getPgFee());
1032
				marketplaceItem.setServiceTax(mpCosting.getServiceTax());
1047
 
1033
				marketplaceItem.setReturnProvision(mpCosting.getReturnProvision());
1048
                try {
1034
				marketplaceItem.setEmiFee(mpCosting.getEmiFee());
1049
                    item = catalogClient.getItem(sku);
1035
				marketplaceItem.setClosingFee(mpCosting.getClosingFee());
1050
                    marketplaceItem.setPackagingCost(computePackagingCost(item.getCategory()));
1036
				marketplaceItem.setPgFee(mpCosting.getPgFee());
1051
                    if (item.getId()==0){
1037
 
1052
                        sb.append(sku + " Item not valid"+"\n");
1038
				try {
1053
                        continue;
1039
					item = catalogClient.getItem(sku);
1054
                    }
1040
					if (item.getId()==0){
1055
                } catch (CatalogServiceException e) {
1041
						sb.append(sku + " Item not valid"+"\n");
1056
                    sb.append(sku + " Item not valid"+"\n");
1042
						continue;
1057
                    continue;
1043
					}
1058
                }
1044
				} catch (CatalogServiceException e) {
1059
                if(snapdealItem.getItem_id()==0){
1045
					sb.append(sku + " Item not valid"+"\n");
1060
                    new_item = true;
1046
					continue;
1061
                    snapdealItem = new SnapdealItem();
1047
				}
1062
                    snapdealItem.setItem_id(sku); 
1048
				if(snapdealItem.getItem_id()==0){
1063
                }
1049
					new_item = true;
1064
            }
1050
					snapdealItem = new SnapdealItem();
1065
 
1051
					snapdealItem.setItem_id(sku); 
1066
            if (checkEmptyString(sheet.getRow(iterator).getCell(1)) && new_item){
1052
				}
1067
                sb.append(sku + " New Listing - Warehouse Id not Present"+"\n");
1053
			}
1068
                continue;
1054
 
1069
            }
1055
			if (checkEmptyString(sheet.getRow(iterator).getCell(1)) && new_item){
-
 
1056
				sb.append(sku + " New Listing - Warehouse Id not Present"+"\n");
-
 
1057
				continue;
-
 
1058
			}
-
 
1059
 
1070
 
1060
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
1071
            if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
1061
				/*Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
1072
                /*Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
1062
				if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
1073
				if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
1063
					sb.append(sku + "Not acceptable warehouse"+"\n");
1074
					sb.append(sku + "Not acceptable warehouse"+"\n");
1064
					continue;
1075
					continue;
1065
				}*/
1076
				}*/
1066
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
1077
                long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
1067
				double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
1078
                double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
1068
				if (maxNLC==0){
1079
                if (maxNLC==0){
1069
					sb.append(sku + "Max Nlc can't be 0"+"\n");
1080
                    sb.append(sku + "Max Nlc can't be 0"+"\n");
1070
					continue;
1081
                    continue;
1071
				}
1082
                }
1072
				snapdealItem.setWarehouseId(warehouseId);
1083
                snapdealItem.setWarehouseId(warehouseId);
1073
				snapdealItem.setMaxNlc(maxNLC);
1084
                snapdealItem.setMaxNlc(maxNLC);
1074
			}
1085
            }
1075
 
1086
 
1076
			if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
1087
            if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
1077
				double exceptionPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
1088
                double exceptionPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
1078
				snapdealItem.setExceptionPrice(exceptionPrice);
1089
                snapdealItem.setExceptionPrice(exceptionPrice);
1079
			}
1090
            }
1080
 
1091
 
1081
			if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
1092
            if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
1082
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==1){
1093
                if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==1){
1083
					snapdealItem.setIsListedOnSnapdeal(true);
1094
                    snapdealItem.setIsListedOnSnapdeal(true);
1084
				}
1095
                }
1085
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
1096
                if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
1086
					snapdealItem.setIsListedOnSnapdeal(false);
1097
                    snapdealItem.setIsListedOnSnapdeal(false);
1087
				}
1098
                }
1088
			}
1099
            }
1089
 
1100
 
1090
			double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax,otherCost;
1101
            double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax,otherCost;
1091
			if (checkEmptyString(sheet.getRow(iterator).getCell(4))&& new_item){
1102
            if (checkEmptyString(sheet.getRow(iterator).getCell(4))&& new_item){
1092
				sb.append(sku + "New Item -  Selling Price cannot be empty"+"\n");
1103
                sb.append(sku + "New Item -  Selling Price cannot be empty"+"\n");
1093
				continue;
1104
                continue;
1094
			}
1105
            }
1095
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
1106
            if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
1096
				sellingPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
1107
                sellingPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
1097
				if(sellingPrice==0){
1108
                if(sellingPrice==0){
1098
					sb.append(sku + " Selling Price cannot be zero"+"\n");
1109
                    sb.append(sku + " Selling Price cannot be zero"+"\n");
1099
					continue;
1110
                    continue;
1100
				}
1111
                }
1101
				snapdealItem.setSellingPrice(sellingPrice);
1112
                snapdealItem.setSellingPrice(sellingPrice);
1102
				marketplaceItem.setCurrentSp(sellingPrice);
1113
                marketplaceItem.setCurrentSp(sellingPrice);
1103
			}
1114
            }
1104
 
1115
 
1105
			if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
1116
            if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
1106
				otherCost = sheet.getRow(iterator).getCell(5).getNumericCellValue();
1117
                otherCost = sheet.getRow(iterator).getCell(5).getNumericCellValue();
1107
				marketplaceItem.setOtherCost(otherCost);
1118
                marketplaceItem.setOtherCost(otherCost);
1108
			}
1119
            }
1109
 
1120
 
1110
 
1121
 
1111
			if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
1122
            if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
1112
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
1123
                if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
1113
					snapdealItem.setSuppressPriceFeed(true);
1124
                    snapdealItem.setSuppressPriceFeed(true);
1114
				}
1125
                }
1115
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
1126
                if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
1116
					snapdealItem.setSuppressPriceFeed(false);
1127
                    snapdealItem.setSuppressPriceFeed(false);
1117
				}
1128
                }
1118
			}
1129
            }
1119
 
1130
 
1120
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
1131
            if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
1121
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==1){
1132
                if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==1){
1122
					snapdealItem.setSuppressInventoryFeed(true);
1133
                    snapdealItem.setSuppressInventoryFeed(true);
1123
				}
1134
                }
1124
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==0){
1135
                if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==0){
1125
					snapdealItem.setSuppressInventoryFeed(false);
1136
                    snapdealItem.setSuppressInventoryFeed(false);
1126
				}
1137
                }
1127
			}
1138
            }
1128
 
1139
 
1129
			if (checkEmptyString(sheet.getRow(iterator).getCell(8)) && new_item){
1140
            if (checkEmptyString(sheet.getRow(iterator).getCell(8)) && new_item){
1130
				sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
1141
                sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
1131
				continue;
1142
                continue;
1132
			}
1143
            }
1133
 
1144
 
1134
			if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
1145
            if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
1135
				sheet.getRow(iterator).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
1146
                sheet.getRow(iterator).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
1136
				String snapdealItemCode = sheet.getRow(iterator).getCell(8).getStringCellValue();
1147
                String snapdealItemCode = sheet.getRow(iterator).getCell(8).getStringCellValue();
1137
				if (snapdealItemCode.length()==0 && new_item){
1148
                if (snapdealItemCode.length()==0 && new_item){
1138
					sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
1149
                    sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
1139
					continue;
1150
                    continue;
1140
				}
1151
                }
1141
				snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
1152
                snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
1142
			}
1153
            }
1143
 
1154
 
1144
			if (checkEmptyString(sheet.getRow(iterator).getCell(9)) && new_item){
1155
            if (checkEmptyString(sheet.getRow(iterator).getCell(9)) && new_item){
1145
				sb.append(sku + " New Item -  SUPC code cannot be empty"+"\n");
1156
                sb.append(sku + " New Item -  SUPC code cannot be empty"+"\n");
1146
				continue;
1157
                continue;
1147
			}
1158
            }
1148
 
1159
 
1149
			if (!checkEmptyString(sheet.getRow(iterator).getCell(9))){
1160
            if (!checkEmptyString(sheet.getRow(iterator).getCell(9))){
1150
				sheet.getRow(iterator).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
1161
                sheet.getRow(iterator).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
1151
				String supc = sheet.getRow(iterator).getCell(9).getStringCellValue();
1162
                String supc = sheet.getRow(iterator).getCell(9).getStringCellValue();
1152
				if (supc.length()==0 && new_item){
1163
                if (supc.length()==0 && new_item){
1153
					sb.append(sku + "  New Item -  SUPC code cannot be empty"+"\n");
1164
                    sb.append(sku + "  New Item -  SUPC code cannot be empty"+"\n");
1154
					continue;
1165
                    continue;
1155
				}
1166
                }
1156
				snapdealItem.setSupc(supc);
1167
                snapdealItem.setSupc(supc);
1157
			}
1168
            }
1158
			double weight = item.getWeight();
1169
            double weight = item.getWeight();
1159
 
1170
 
1160
 
1171
 
1161
			if(weight==0){
1172
            if(weight==0){
1162
				sb.append(sku + " Please add weight"+"\n");
1173
                sb.append(sku + " Please add weight"+"\n");
1163
				continue;
1174
                continue;
1164
			}
1175
            }
1165
			if (weight!=0){
1176
            if (weight!=0){
1166
				weight = weight+.05;
1177
                weight = weight+.05;
1167
				int slabs = (int) ((weight - .001)/(.5));
1178
                int slabs = (int) ((weight - .001)/(.5));
1168
 
1179
 
1169
				for(int i=0;i<slabs;i++){
1180
                for(int i=0;i<slabs;i++){
1170
					courierCost = courierCost + 35;
1181
                    courierCost = courierCost + 35;
1171
				}
1182
                }
1172
			}
1183
            }
1173
 
1184
 
1174
			warehouse = inventoryClient.getWarehouse(snapdealItem.getWarehouseId());
1185
            warehouse = inventoryClient.getWarehouse(snapdealItem.getWarehouseId());
1175
			snapdealItem.setCourierCost(courierCost);
1186
            snapdealItem.setCourierCost(courierCost);
1176
			marketplaceItem.setCourierCost(courierCost);
1187
            marketplaceItem.setCourierCost(courierCost);
1177
			if (new_item){
1188
            if (new_item){
1178
			    snapdealItem.setCourierCostMarketplace(courierCost);
1189
                snapdealItem.setCourierCostMarketplace(courierCost);
1179
			    marketplaceItem.setCourierCostMarketplace(courierCost);
1190
                marketplaceItem.setCourierCostMarketplace(courierCost);
1180
			}
1191
            }
1181
			transferPrice = roundTwoDecimals(snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))-(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee())*(1+(marketplaceItem.getServiceTax()/100))-(Math.max(20,(marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice())*(1+(marketplaceItem.getServiceTax()/100))));
1192
            transferPrice = roundTwoDecimals(snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))-(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee())*(1+(marketplaceItem.getServiceTax()/100))-(Math.max(20,(marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice())*(1+(marketplaceItem.getServiceTax()/100))));
1182
			snapdealItem.setTransferPrice(transferPrice);
1193
            snapdealItem.setTransferPrice(transferPrice);
1183
			marketplaceItem.setCurrentTp(transferPrice);
1194
            marketplaceItem.setCurrentTp(transferPrice);
1184
			if ((marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
1195
            if ((marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
1185
				commission =  (((marketplaceItem.getCommission()/100)+marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice());
1196
                commission =  (((marketplaceItem.getCommission()/100)+marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice());
1186
			}
1197
            }
1187
			else{
1198
            else{
1188
				commission =  ((marketplaceItem.getCommission()/100)*snapdealItem.getSellingPrice()+20);
1199
                commission =  ((marketplaceItem.getCommission()/100)*snapdealItem.getSellingPrice()+20);
1189
			}
1200
            }
1190
			commission = roundTwoDecimals(commission);
1201
            commission = roundTwoDecimals(commission);
1191
			snapdealItem.setCommission(commission);
1202
            snapdealItem.setCommission(commission);
1192
			serviceTax = roundTwoDecimals((marketplaceItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCostMarketplace())); 
1203
            serviceTax = roundTwoDecimals((marketplaceItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCostMarketplace())); 
1193
			snapdealItem.setServiceTax(serviceTax);
1204
            snapdealItem.setServiceTax(serviceTax);
1194
			double vatRate = catalogClientProd.getVatPercentageForItem(snapdealItem.getItem_id(),warehouse.getStateId(),snapdealItem.getSellingPrice());
1205
            double vatRate = catalogClientProd.getVatPercentageForItem(snapdealItem.getItem_id(),warehouse.getStateId(),snapdealItem.getSellingPrice());
1195
			marketplaceItem.setVat(vatRate);
1206
            marketplaceItem.setVat(vatRate);
1196
			double vat = roundTwoDecimals((snapdealItem.getSellingPrice()/(1+(marketplaceItem.getVat()/100))-(snapdealItem.getMaxNlc()/(1+(marketplaceItem.getVat()/100))))*(marketplaceItem.getVat()/100));
1207
            double vat = roundTwoDecimals((snapdealItem.getSellingPrice()/(1+(marketplaceItem.getVat()/100))-(snapdealItem.getMaxNlc()/(1+(marketplaceItem.getVat()/100))))*(marketplaceItem.getVat()/100));
1197
			double inHouseCost = roundTwoDecimals(15+vat+(marketplaceItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+marketplaceItem.getOtherCost());
1208
            double inHouseCost = roundTwoDecimals(marketplaceItem.getPackagingCost()+vat+(marketplaceItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+marketplaceItem.getOtherCost());
1198
			double lowest_possible_tp = roundTwoDecimals(snapdealItem.getMaxNlc()+inHouseCost);
1209
            double lowest_possible_tp = roundTwoDecimals(snapdealItem.getMaxNlc()+inHouseCost);
1199
			marketplaceItem.setMinimumPossibleTp(lowest_possible_tp);
1210
            marketplaceItem.setMinimumPossibleTp(lowest_possible_tp);
1200
			double lowest_possible_sp=0.0;
1211
            double lowest_possible_sp=0.0;
1201
			if ((marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
1212
            if ((marketplaceItem.getPgFee()/100)*snapdealItem.getSellingPrice()>=20){
1202
				lowest_possible_sp = roundTwoDecimals((snapdealItem.getMaxNlc()+(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee())*(1+marketplaceItem.getServiceTax()/100)*(1+(marketplaceItem.getVat()/100))+(15+marketplaceItem.getOtherCost())*(1+(marketplaceItem.getVat())/100))/(1-((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100+marketplaceItem.getPgFee()/100)*(1+(marketplaceItem.getServiceTax()/100))*(1+(marketplaceItem.getVat())/100)-(marketplaceItem.getReturnProvision()/100)*(1+(marketplaceItem.getVat())/100)));
1213
                lowest_possible_sp = roundTwoDecimals((snapdealItem.getMaxNlc()+(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee())*(1+marketplaceItem.getServiceTax()/100)*(1+(marketplaceItem.getVat()/100))+(marketplaceItem.getPackagingCost()+marketplaceItem.getOtherCost())*(1+(marketplaceItem.getVat())/100))/(1-((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100+marketplaceItem.getPgFee()/100)*(1+(marketplaceItem.getServiceTax()/100))*(1+(marketplaceItem.getVat())/100)-(marketplaceItem.getReturnProvision()/100)*(1+(marketplaceItem.getVat())/100)));
1203
			}
1214
            }
1204
			else{
1215
            else{
1205
				lowest_possible_sp = roundTwoDecimals((snapdealItem.getMaxNlc()+(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee()+20)*(1+marketplaceItem.getServiceTax()/100)*(1+(marketplaceItem.getVat()/100))+(15+marketplaceItem.getOtherCost())*(1+(marketplaceItem.getVat())/100))/(1-((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))*(1+(marketplaceItem.getVat())/100)-(marketplaceItem.getReturnProvision()/100)*(1+(marketplaceItem.getVat())/100)));
1216
                lowest_possible_sp = roundTwoDecimals((snapdealItem.getMaxNlc()+(snapdealItem.getCourierCostMarketplace()+marketplaceItem.getClosingFee()+20)*(1+marketplaceItem.getServiceTax()/100)*(1+(marketplaceItem.getVat()/100))+(marketplaceItem.getPackagingCost()+marketplaceItem.getOtherCost())*(1+(marketplaceItem.getVat())/100))/(1-((marketplaceItem.getCommission()/100)+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))*(1+(marketplaceItem.getVat())/100)-(marketplaceItem.getReturnProvision()/100)*(1+(marketplaceItem.getVat())/100)));
1206
			}
1217
            }
1207
			marketplaceItem.setMinimumPossibleSp(lowest_possible_sp);
1218
            marketplaceItem.setMinimumPossibleSp(lowest_possible_sp);
1208
			snapdealItem.setUpdatedBy(updatedBy);
1219
            snapdealItem.setUpdatedBy(updatedBy);
1209
			snapdealItem.setMarketplaceItems(marketplaceItem);
1220
            snapdealItem.setMarketplaceItems(marketplaceItem);
1210
			//logger.info(snapdealItem.toString());
1221
            //logger.info(snapdealItem.toString());
1211
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
1222
            if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
1212
				sb.append(sku + " Service Error\n");
1223
                sb.append(sku + " Service Error\n");
1213
			}	
1224
            }	
1214
		}
1225
        }
1215
		File file = new File("/tmp/snapdealbulk");
1226
        File file = new File("/tmp/snapdealbulk");
1216
		FileWriter writer = new FileWriter(file);
1227
        FileWriter writer = new FileWriter(file);
1217
		writer.append(sb.toString());
1228
        writer.append(sb.toString());
1218
		writer.close();
1229
        writer.close();
1219
		byte[] buffer = new byte[(int)file.length()];
1230
        byte[] buffer = new byte[(int)file.length()];
1220
		InputStream input = null;
1231
        InputStream input = null;
1221
		try {
1232
        try {
1222
			int totalBytesRead = 0;
1233
            int totalBytesRead = 0;
1223
			input = new BufferedInputStream(new FileInputStream(file));
1234
            input = new BufferedInputStream(new FileInputStream(file));
1224
			while(totalBytesRead < buffer.length){
1235
            while(totalBytesRead < buffer.length){
1225
				int bytesRemaining = buffer.length - totalBytesRead;
1236
                int bytesRemaining = buffer.length - totalBytesRead;
1226
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
1237
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
1227
				if (bytesRead > 0){
1238
                if (bytesRead > 0){
1228
					totalBytesRead = totalBytesRead + bytesRead;
1239
                    totalBytesRead = totalBytesRead + bytesRead;
1229
				}
1240
                }
1230
			}
1241
            }
1231
		}
1242
        }
1232
		finally {
1243
        finally {
1233
			input.close();
1244
            input.close();
1234
			file.delete();
1245
            file.delete();
1235
		}
1246
        }
1236
 
1247
 
1237
		response.setHeader("Content-Type", "text/javascript");
1248
        response.setHeader("Content-Type", "text/javascript");
1238
 
1249
 
1239
		ServletOutputStream sos;
1250
        ServletOutputStream sos;
1240
		try {
1251
        try {
1241
			sos = response.getOutputStream();
1252
            sos = response.getOutputStream();
1242
			sos.write(buffer);
1253
            sos.write(buffer);
1243
			sos.flush();
1254
            sos.flush();
1244
		} catch (IOException e) {
1255
        } catch (IOException e) {
1245
			System.out.println("Unable to stream the manifest file");
1256
            System.out.println("Unable to stream the manifest file");
1246
		}   
1257
        }   
1247
	}
1258
    }
1248
 
-
 
1249
	public boolean checkEmptyString(Cell cell){
-
 
1250
		if (cell==null || cell.getCellType() == Cell.CELL_TYPE_BLANK){
-
 
1251
			return true;
-
 
1252
		}
-
 
1253
		return false;
-
 
1254
	}
-
 
1255
 
-
 
1256
	double roundTwoDecimals(double d) {
-
 
1257
		DecimalFormat twoPlaces = new DecimalFormat("#.##");
-
 
1258
		return Double.valueOf(twoPlaces.format(d));
-
 
1259
	}
-
 
1260
 
1259
 
-
 
1260
    public boolean checkEmptyString(Cell cell){
-
 
1261
        if (cell==null || cell.getCellType() == Cell.CELL_TYPE_BLANK){
-
 
1262
            return true;
-
 
1263
        }
-
 
1264
        return false;
-
 
1265
    }
-
 
1266
 
-
 
1267
    double roundTwoDecimals(double d) {
-
 
1268
        DecimalFormat twoPlaces = new DecimalFormat("#.##");
-
 
1269
        return Double.valueOf(twoPlaces.format(d));
-
 
1270
    }
-
 
1271
 
1261
	/*String getLocation(String location){
1272
    /*String getLocation(String location){
1262
		logger.info("Inside trim"+location);
1273
		logger.info("Inside trim"+location);
1263
		int loc = location.lastIndexOf(',');
1274
		int loc = location.lastIndexOf(',');
1264
		logger.info("end result "+location.substring(loc+1));
1275
		logger.info("end result "+location.substring(loc+1));
1265
		return location.substring(loc+1);
1276
		return location.substring(loc+1);
1266
	}*/
1277
	}*/
1267
 
1278
 
1268
 
1279
 
1269
	public String show() {
1280
    public String show() {
1270
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
1281
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
1271
			return "authfail";
1282
            return "authfail";
1272
		}
1283
        }
1273
 
1284
 
1274
		if (StringUtils.equals(id, "snapdeal-options")){
1285
        if (StringUtils.equals(id, "snapdeal-options")){
1275
			return "snapdeal-options";
1286
            return "snapdeal-options";
1276
		}
1287
        }
1277
		
1288
 
1278
		if (StringUtils.equals(id, "competition-analysis")){
1289
        if (StringUtils.equals(id, "competition-analysis")){
1279
		    //setAnalysisData(Long.valueOf(itemId));
1290
            //setAnalysisData(Long.valueOf(itemId));
1280
		    
1291
 
1281
            return "competition-details";
1292
            return "competition-details";
1282
        }
1293
        }
1283
		
1294
 
1284
		if (StringUtils.equals(id, "item-table")){
1295
        if (StringUtils.equals(id, "item-table")){
1285
			return "snapdeal-item-table";
1296
            return "snapdeal-item-table";
1286
		}
1297
        }
1287
 
1298
 
1288
		return "id";
1299
        return "id";
1289
	}
1300
    }
1290
	
1301
 
1291
//	public void setAnalysisData(long itemId){
1302
    //	public void setAnalysisData(long itemId){
1292
//        try {
1303
    //        try {
1293
//            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1304
    //            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1294
//            compData = cc.getMarketplaceHistory(7, 0, itemId);
1305
    //            compData = cc.getMarketplaceHistory(7, 0, itemId);
1295
//        } catch (Exception e) {
1306
    //        } catch (Exception e) {
1296
//            // TODO Auto-generated catch block
1307
    //            // TODO Auto-generated catch block
1297
//            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1308
    //            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1298
//        }
1309
    //        }
1299
//        //Gson gson = new Gson();
1310
    //        //Gson gson = new Gson();
1300
//        //competitionJson = gson.toJson(compData);
1311
    //        //competitionJson = gson.toJson(compData);
1301
//        
1312
    //        
1302
//	}
1313
    //	}
1303
	
1314
 
1304
	public String getCountForCompetitionData(String itemId) throws TException, NumberFormatException, CatalogServiceException{
1315
    public String getCountForCompetitionData(String itemId) throws TException, NumberFormatException, CatalogServiceException{
1305
	    Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1316
        Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1306
	    Item item = cc.getItem(Long.valueOf(itemId));
1317
        Item item = cc.getItem(Long.valueOf(itemId));
1307
	    setProductName(getVaildName(item.getBrand())+" "+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor()));
1318
        setProductName(getVaildName(item.getBrand())+" "+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor()));
1308
	    return String.valueOf(cc.getCountForMarketplaceHistory(7, Long.valueOf(itemId)));
1319
        return String.valueOf(cc.getCountForMarketplaceHistory(7, Long.valueOf(itemId)));
1309
	}
1320
    }
1310
	
1321
 
1311
	public void setProductName(String productName){
1322
    public void setProductName(String productName){
1312
	    this.productName = productName;
1323
        this.productName = productName;
1313
	}
1324
    }
1314
	
1325
 
1315
	public String getProductName(){
1326
    public String getProductName(){
1316
	    return productName;
1327
        return productName;
1317
	}
1328
    }
1318
	
1329
 
1319
	
1330
 
1320
	public String fetchCompetitionData(){
1331
    public String fetchCompetitionData(){
1321
	    try {
1332
        try {
1322
            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1333
            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1323
            compData = cc.getMarketplaceHistory(7, Long.valueOf(next), Long.valueOf(itemId));
1334
            compData = cc.getMarketplaceHistory(7, Long.valueOf(next), Long.valueOf(itemId));
1324
        } catch (Exception e) {
1335
        } catch (Exception e) {
1325
            // TODO Auto-generated catch block
1336
            // TODO Auto-generated catch block
1326
            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1337
            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1327
        }
1338
        }
1328
        return "snapdeal-competition-table";
1339
        return "snapdeal-competition-table";
1329
	    
1340
 
1330
	}
1341
    }
1331
	
1342
 
1332
	public String fetchCompetitionDataTest(){
1343
    public String fetchCompetitionDataTest(){
1333
        try {
1344
        try {
1334
            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1345
            Client cc = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
1335
            compData = cc.getMarketplaceHistoryByDate(7, Long.valueOf(startDate), Long.valueOf(endDate),999999L,999999L,Long.valueOf(itemId));
1346
            compData = cc.getMarketplaceHistoryByDate(7, Long.valueOf(startDate), Long.valueOf(endDate),999999L,999999L,Long.valueOf(itemId));
1336
        } catch (Exception e) {
1347
        } catch (Exception e) {
1337
            // TODO Auto-generated catch block
1348
            // TODO Auto-generated catch block
1338
            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1349
            logger.error("Unable to set analysis data for itemId "+itemId +" "+e);
1339
        }
1350
        }
1340
        return "snapdeal-duplicate-records";
1351
        return "snapdeal-duplicate-records";
1341
        
1352
 
1342
    }
1353
    }
1343
	
1354
 
1344
	
1355
 
1345
	public List<MarketplaceHistory> getAnalysisData() {
1356
    public List<MarketplaceHistory> getAnalysisData() {
1346
        return compData;
1357
        return compData;
1347
    }
1358
    }
1348
 
1359
 
1349
	public void setId(String id) {
1360
    public void setId(String id) {
1350
		this.id = id;
1361
        this.id = id;
1351
	}
1362
    }
1352
 
1363
 
1353
	public String getUserName(){
1364
    public String getUserName(){
1354
		return session.getAttribute(ReportsUtils.USER_NAME).toString();
1365
        return session.getAttribute(ReportsUtils.USER_NAME).toString();
1355
	}
1366
    }
1356
 
1367
 
1357
	public HttpServletRequest getRequest() {
1368
    public HttpServletRequest getRequest() {
1358
		logger.info("set request"+request.toString());
1369
        logger.info("set request"+request.toString());
1359
		return request;
1370
        return request;
1360
	}
1371
    }
1361
 
1372
 
1362
	public void setRequest(HttpServletRequest request) {
1373
    public void setRequest(HttpServletRequest request) {
1363
		this.request = request;
1374
        this.request = request;
1364
	}
1375
    }
1365
 
1376
 
1366
	public HttpServletResponse getResponse() {
1377
    public HttpServletResponse getResponse() {
1367
		return response;
1378
        return response;
1368
	}
1379
    }
1369
 
1380
 
1370
	public void setResponse(HttpServletResponse response) {
1381
    public void setResponse(HttpServletResponse response) {
1371
		this.response = response;
1382
        this.response = response;
1372
	}
1383
    }
1373
 
1384
 
1374
	public HttpSession getSession() {
1385
    public HttpSession getSession() {
1375
		return session;
1386
        return session;
1376
	}
1387
    }
1377
 
1388
 
1378
	public void setSession(HttpSession session) {
1389
    public void setSession(HttpSession session) {
1379
		this.session = session;
1390
        this.session = session;
1380
	}
1391
    }
1381
 
1392
 
1382
	public ServletContext getContext() {
1393
    public ServletContext getContext() {
1383
		return context;
1394
        return context;
1384
	}
1395
    }
1385
 
1396
 
1386
	public void setContext(ServletContext context) {
1397
    public void setContext(ServletContext context) {
1387
		this.context = context;
1398
        this.context = context;
1388
	}
1399
    }
1389
 
1400
 
1390
	public String getUrl() {
1401
    public String getUrl() {
1391
		return url;
1402
        return url;
1392
	}
1403
    }
1393
 
1404
 
1394
	public void setUrl(String url) {
1405
    public void setUrl(String url) {
1395
		this.url = url;
1406
        this.url = url;
1396
	}
1407
    }
1397
 
1408
 
1398
	public String getItemId() {
1409
    public String getItemId() {
1399
		return itemId;
1410
        return itemId;
1400
	}
1411
    }
1401
 
1412
 
1402
	public void setItemId(String itemId) {
1413
    public void setItemId(String itemId) {
1403
		this.itemId = itemId;
1414
        this.itemId = itemId;
1404
	}
1415
    }
1405
 
1416
 
1406
	public String getIsSnapdealListed() {
1417
    public String getIsSnapdealListed() {
1407
		return isSnapdealListed;
1418
        return isSnapdealListed;
1408
	}
1419
    }
1409
 
1420
 
1410
	public void setIsSnapdealListed(String isSnapdealListed) {
1421
    public void setIsSnapdealListed(String isSnapdealListed) {
1411
		this.isSnapdealListed = isSnapdealListed;
1422
        this.isSnapdealListed = isSnapdealListed;
1412
	}
1423
    }
1413
 
1424
 
1414
	public String getExceptionPrice() {
1425
    public String getExceptionPrice() {
1415
		return exceptionPrice;
1426
        return exceptionPrice;
1416
	}
1427
    }
1417
 
1428
 
1418
	public void setExceptionPrice(String exceptionPrice) {
1429
    public void setExceptionPrice(String exceptionPrice) {
1419
		this.exceptionPrice = exceptionPrice;
1430
        this.exceptionPrice = exceptionPrice;
1420
	}
1431
    }
1421
 
1432
 
1422
	public String getWarehouseId() {
1433
    public String getWarehouseId() {
1423
		return warehouseId;
1434
        return warehouseId;
1424
	}
1435
    }
1425
 
1436
 
1426
	public void setWarehouseId(String warehouseId) {
1437
    public void setWarehouseId(String warehouseId) {
1427
		this.warehouseId = warehouseId;
1438
        this.warehouseId = warehouseId;
1428
	}
1439
    }
1429
 
1440
 
1430
	public File getFile() {
1441
    public File getFile() {
1431
		return file;
1442
        return file;
1432
	}
1443
    }
1433
 
1444
 
1434
	public void setFile(File file) {
1445
    public void setFile(File file) {
1435
		this.file = file;
1446
        this.file = file;
1436
	}
1447
    }
1437
 
1448
 
1438
	public String getErrMsg() {
1449
    public String getErrMsg() {
1439
		return errMsg;
1450
        return errMsg;
1440
	}
1451
    }
1441
 
1452
 
1442
	public void setErrMsg(String errMsg) {
1453
    public void setErrMsg(String errMsg) {
1443
		this.errMsg = errMsg;
1454
        this.errMsg = errMsg;
1444
	}
1455
    }
1445
 
1456
 
1446
	public String getNext() {
1457
    public String getNext() {
1447
		return next;
1458
        return next;
1448
	}
1459
    }
1449
 
1460
 
1450
	public void setNext(String next) {
1461
    public void setNext(String next) {
1451
		this.next = next;
1462
        this.next = next;
1452
	}
1463
    }
1453
 
1464
 
1454
	public String getId() {
1465
    public String getId() {
1455
		return id;
1466
        return id;
1456
	}
1467
    }
1457
 
1468
 
1458
	public void setServletRequest(HttpServletRequest req) {
1469
    public void setServletRequest(HttpServletRequest req) {
1459
		this.request = req;
1470
        this.request = req;
1460
		this.session = req.getSession();        
1471
        this.session = req.getSession();        
1461
	}
1472
    }
1462
 
1473
 
1463
	public void setServletContext(ServletContext arg0) {
1474
    public void setServletContext(ServletContext arg0) {
1464
		// TODO Auto-generated method stub
1475
        // TODO Auto-generated method stub
1465
 
1476
 
1466
	}
1477
    }
1467
 
1478
 
1468
	public void setServletResponse(HttpServletResponse response) {
1479
    public void setServletResponse(HttpServletResponse response) {
1469
		this.response = response;
1480
        this.response = response;
1470
	}
1481
    }
1471
 
1482
 
1472
	public void setSearchText(String searchText) {
1483
    public void setSearchText(String searchText) {
1473
		this.searchText = searchText;
1484
        this.searchText = searchText;
1474
	}
1485
    }
1475
 
1486
 
1476
	public String getSearchText() {
1487
    public String getSearchText() {
1477
		return searchText;
1488
        return searchText;
1478
	}
1489
    }
1479
 
1490
 
1480
	public long getSearchCount() {
1491
    public long getSearchCount() {
1481
		return searchCount;
1492
        return searchCount;
1482
	}
1493
    }
1483
 
1494
 
1484
	public long getTotalCount() {
1495
    public long getTotalCount() {
1485
		return totalCount;
1496
        return totalCount;
1486
	}
1497
    }
1487
 
1498
 
1488
	public void setSearchCount(long count) {
1499
    public void setSearchCount(long count) {
1489
		this.searchCount = count;
1500
        this.searchCount = count;
1490
	}
1501
    }
1491
 
1502
 
1492
	public List<SnapdealItemDetails> getSnapdealItems(){
1503
    public List<SnapdealItemDetails> getSnapdealItems(){
1493
		return snapdealItems;
1504
        return snapdealItems;
1494
	}
1505
    }
1495
 
1506
 
1496
	public void setSellingPrice(String sellingPrice) {
1507
    public void setSellingPrice(String sellingPrice) {
1497
		this.sellingPrice = sellingPrice;
1508
        this.sellingPrice = sellingPrice;
1498
	}
1509
    }
1499
 
1510
 
1500
	public String getSellingPrice() {
1511
    public String getSellingPrice() {
1501
		return sellingPrice;
1512
        return sellingPrice;
1502
	}
1513
    }
1503
 
1514
 
1504
	public void setTransferPrice(String transferPrice) {
1515
    public void setTransferPrice(String transferPrice) {
1505
		this.transferPrice = transferPrice;
1516
        this.transferPrice = transferPrice;
1506
	}
1517
    }
1507
 
1518
 
1508
	public String getTransferPrice() {
1519
    public String getTransferPrice() {
1509
		return transferPrice;
1520
        return transferPrice;
1510
	}
1521
    }
1511
 
1522
 
1512
	public void setWebisteMrp(String webisteMrp) {
1523
    public void setWebisteMrp(String webisteMrp) {
1513
		this.webisteMrp = webisteMrp;
1524
        this.webisteMrp = webisteMrp;
1514
	}
1525
    }
1515
 
1526
 
1516
	public String getWebisteMrp() {
1527
    public String getWebisteMrp() {
1517
		return webisteMrp;
1528
        return webisteMrp;
1518
	}
1529
    }
1519
 
1530
 
1520
	public void setWebisteSellingPrice(String webisteSellingPrice) {
1531
    public void setWebisteSellingPrice(String webisteSellingPrice) {
1521
		this.webisteSellingPrice = webisteSellingPrice;
1532
        this.webisteSellingPrice = webisteSellingPrice;
1522
	}
1533
    }
1523
 
1534
 
1524
	public String getWebisteSellingPrice() {
1535
    public String getWebisteSellingPrice() {
1525
		return webisteSellingPrice;
1536
        return webisteSellingPrice;
1526
	}
1537
    }
1527
 
1538
 
1528
	public void setIsListedOnSnapdeal(String isListedOnSnapdeal) {
1539
    public void setIsListedOnSnapdeal(String isListedOnSnapdeal) {
1529
		this.isListedOnSnapdeal = isListedOnSnapdeal;
1540
        this.isListedOnSnapdeal = isListedOnSnapdeal;
1530
	}
1541
    }
1531
 
1542
 
1532
	public String getIsSuppressInventoryFeed() {
1543
    public String getIsSuppressInventoryFeed() {
1533
		return isSuppressInventoryFeed;
1544
        return isSuppressInventoryFeed;
1534
	}
1545
    }
1535
 
1546
 
1536
	public void setIsSuppressInventoryFeed(String isSuppressInventoryFeed) {
1547
    public void setIsSuppressInventoryFeed(String isSuppressInventoryFeed) {
1537
		this.isSuppressInventoryFeed = isSuppressInventoryFeed;
1548
        this.isSuppressInventoryFeed = isSuppressInventoryFeed;
1538
	}
1549
    }
1539
 
1550
 
1540
	public String getIsSuppressPriceFeed() {
1551
    public String getIsSuppressPriceFeed() {
1541
		return isSuppressPriceFeed;
1552
        return isSuppressPriceFeed;
1542
	}
1553
    }
1543
 
1554
 
1544
	public void setIsSuppressPriceFeed(String isSuppressPriceFeed) {
1555
    public void setIsSuppressPriceFeed(String isSuppressPriceFeed) {
1545
		this.isSuppressPriceFeed = isSuppressPriceFeed;
1556
        this.isSuppressPriceFeed = isSuppressPriceFeed;
1546
	}
1557
    }
1547
 
1558
 
1548
	public String getIsListedOnSnapdeal() {
1559
    public String getIsListedOnSnapdeal() {
1549
		return isListedOnSnapdeal;
1560
        return isListedOnSnapdeal;
1550
	}
1561
    }
1551
 
1562
 
1552
	public void setCommission(String commission) {
1563
    public void setCommission(String commission) {
1553
		this.commission = commission;
1564
        this.commission = commission;
1554
	}
1565
    }
1555
 
1566
 
1556
	public String getCommission() {
1567
    public String getCommission() {
1557
		return commission;
1568
        return commission;
1558
	}
1569
    }
1559
 
1570
 
1560
	public void setServiceTax(String serviceTax) {
1571
    public void setServiceTax(String serviceTax) {
1561
		this.serviceTax = serviceTax;
1572
        this.serviceTax = serviceTax;
1562
	}
1573
    }
1563
 
1574
 
1564
	public String getServiceTax() {
1575
    public String getServiceTax() {
1565
		return serviceTax;
1576
        return serviceTax;
1566
	}
1577
    }
1567
 
1578
 
1568
	public void setCourierCost(String courierCost) {
1579
    public void setCourierCost(String courierCost) {
1569
		this.courierCost = courierCost;
1580
        this.courierCost = courierCost;
1570
	}
1581
    }
1571
 
1582
 
1572
	public String getCourierCost() {
1583
    public String getCourierCost() {
1573
		return courierCost;
1584
        return courierCost;
1574
	}
1585
    }
1575
 
1586
 
1576
	public void setMaxNlc(String maxNlc) {
1587
    public void setMaxNlc(String maxNlc) {
1577
		this.maxNlc = maxNlc;
1588
        this.maxNlc = maxNlc;
1578
	}
1589
    }
1579
 
1590
 
1580
	public String getMaxNlc() {
1591
    public String getMaxNlc() {
1581
		return maxNlc;
1592
        return maxNlc;
1582
	}
1593
    }
1583
 
1594
 
1584
	public String getItemDetails(){
1595
    public String getItemDetails(){
1585
		return itemObj.toString();
1596
        return itemObj.toString();
1586
	}
1597
    }
1587
 
1598
 
1588
	public double getRoundOfValue(String val){
1599
    public double getRoundOfValue(String val){
1589
		return roundTwoDecimals(Double.valueOf(val));
1600
        return roundTwoDecimals(Double.valueOf(val));
1590
	}
1601
    }
1591
 
1602
 
1592
	public String getVaildName(String name){
1603
    public String getVaildName(String name){
1593
		return name!=null?name:"";
1604
        return name!=null?name:"";
1594
	}
1605
    }
-
 
1606
 
-
 
1607
    public String getPackagingCost() {
-
 
1608
        return packagingCost;
-
 
1609
    }
-
 
1610
 
-
 
1611
    public void setPackagingCost(String packagingCost) {
-
 
1612
        this.packagingCost = packagingCost;
-
 
1613
    }
1595
 
1614
 
1596
}
1615
}