Subversion Repositories SmartDukaan

Rev

Rev 10228 | Rev 10278 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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