Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23819 govind 1
package com.spice.profitmandi.web.controller;
2
 
24822 amit.gupta 3
import java.io.Serializable;
23819 govind 4
import java.time.LocalDateTime;
5
import java.util.ArrayList;
23884 amit.gupta 6
import java.util.Arrays;
23819 govind 7
import java.util.List;
8
import java.util.Map;
24063 amit.gupta 9
import java.util.Set;
23819 govind 10
import java.util.stream.Collectors;
11
 
12
import javax.servlet.http.HttpServletRequest;
13
 
23951 amit.gupta 14
import org.apache.commons.io.output.ByteArrayOutputStream;
23819 govind 15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.beans.factory.annotation.Qualifier;
23951 amit.gupta 19
import org.springframework.core.io.ByteArrayResource;
20
import org.springframework.http.HttpHeaders;
23819 govind 21
import org.springframework.http.HttpStatus;
22
import org.springframework.http.ResponseEntity;
23
import org.springframework.stereotype.Controller;
25161 amit.gupta 24
import org.springframework.transaction.annotation.Transactional;
23819 govind 25
import org.springframework.ui.Model;
26
import org.springframework.web.bind.annotation.PathVariable;
23884 amit.gupta 27
import org.springframework.web.bind.annotation.RequestBody;
23819 govind 28
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RequestMethod;
23951 amit.gupta 30
import org.springframework.web.bind.annotation.RequestParam;
23819 govind 31
 
23945 amit.gupta 32
import com.fasterxml.jackson.databind.ObjectMapper;
23819 govind 33
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23951 amit.gupta 34
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
23884 amit.gupta 35
import com.spice.profitmandi.common.model.ItemDescriptionModel;
24083 amit.gupta 36
import com.spice.profitmandi.common.model.PriceDropImeisModel;
23884 amit.gupta 37
import com.spice.profitmandi.common.model.PriceDropModel;
23968 amit.gupta 38
import com.spice.profitmandi.common.model.PriceDropProcessModel;
23945 amit.gupta 39
import com.spice.profitmandi.common.services.ReporticoService;
23951 amit.gupta 40
import com.spice.profitmandi.common.util.FileUtil;
23945 amit.gupta 41
import com.spice.profitmandi.common.util.FormattingUtils;
23819 govind 42
import com.spice.profitmandi.dao.entity.catalog.Item;
23884 amit.gupta 43
import com.spice.profitmandi.dao.entity.catalog.TagListing;
24822 amit.gupta 44
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
23884 amit.gupta 45
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
23819 govind 46
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
24083 amit.gupta 47
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
48
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
23819 govind 49
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23884 amit.gupta 50
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
24822 amit.gupta 51
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
23884 amit.gupta 52
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
23983 amit.gupta 53
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
24083 amit.gupta 54
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
23819 govind 55
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
56
import com.spice.profitmandi.service.inventory.InventoryService;
23983 amit.gupta 57
import com.spice.profitmandi.service.pricing.PriceDropService;
23968 amit.gupta 58
import com.spice.profitmandi.service.scheme.SchemeService;
23884 amit.gupta 59
import com.spice.profitmandi.service.transaction.TransactionService;
23819 govind 60
import com.spice.profitmandi.service.wallet.WalletService;
61
import com.spice.profitmandi.web.util.MVCResponseSender;
62
 
63
@Controller
25161 amit.gupta 64
@Transactional(rollbackFor=Throwable.class)
23819 govind 65
public class PriceDropController {
66
 
67
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
68
 
69
	@Autowired
70
	private PriceDropRepository priceDropRepository;
71
 
23951 amit.gupta 72
	@Autowired
73
	private ObjectMapper objectMapper;
23945 amit.gupta 74
 
23819 govind 75
	@Autowired
23884 amit.gupta 76
	private VendorItemPricingRepository vendorItemPricingRepository;
23819 govind 77
 
78
	@Autowired
23884 amit.gupta 79
	@Qualifier("fofoInventoryService")
80
	private InventoryService inventoryService;
23945 amit.gupta 81
 
23884 amit.gupta 82
	@Autowired
23819 govind 83
	private MVCResponseSender mvcResponseSender;
84
 
85
	@Autowired
23983 amit.gupta 86
	private PriceDropService priceDropService;
24822 amit.gupta 87
 
88
	@Autowired
89
	private ItemPricingHistoryRepository itemPricingHistoryRepository;
24083 amit.gupta 90
 
23983 amit.gupta 91
	@Autowired
23819 govind 92
	private WalletService walletService;
93
 
94
	@Autowired
23884 amit.gupta 95
	private TagListingRepository tagListingRepository;
23945 amit.gupta 96
 
23884 amit.gupta 97
	@Autowired
98
	private TransactionService transactionService;
23819 govind 99
 
100
	@Autowired
24083 amit.gupta 101
	private PriceDropIMEIRepository priceDropIMEIRepository;
102
 
103
	@Autowired
23819 govind 104
	@Qualifier("catalogItemRepository")
105
	private ItemRepository itemRepository;
106
 
23945 amit.gupta 107
	@Autowired
23968 amit.gupta 108
	private SchemeService schemeService;
24083 amit.gupta 109
 
23986 amit.gupta 110
	@Autowired
23945 amit.gupta 111
	ReporticoService reporticoService;
24083 amit.gupta 112
 
23983 amit.gupta 113
	@Autowired
114
	LineItemImeisRepository lineItemImeisRepository;
23945 amit.gupta 115
 
23819 govind 116
	@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
23945 amit.gupta 117
	public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
23819 govind 118
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
24191 amit.gupta 119
		Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
24180 amit.gupta 120
		List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
24191 amit.gupta 121
		Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
122
				x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
23819 govind 123
		model.addAttribute("priceDrops", priceDrops);
23968 amit.gupta 124
		model.addAttribute("catalogDescription", catalogDescription);
23819 govind 125
		return "price-drop";
126
	}
24083 amit.gupta 127
 
24049 amit.gupta 128
	@RequestMapping(value = "/item-pricing/{itemId}", method = RequestMethod.GET)
129
	public String getItemPricing(HttpServletRequest request, Model model, @PathVariable int itemId) throws Throwable {
24083 amit.gupta 130
 
24063 amit.gupta 131
		TagListing tagListing;
24049 amit.gupta 132
		PriceDropModel pm = new PriceDropModel();
24063 amit.gupta 133
		try {
134
			tagListing = tagListingRepository.selectByItemId(itemId);
24083 amit.gupta 135
			if (tagListing != null) {
24063 amit.gupta 136
				pm.setMop(tagListing.getMop());
137
				pm.setDp(tagListing.getSellingPrice());
138
				pm.setMrp(tagListing.getMrp());
139
				List<VendorItemPricing> vips = vendorItemPricingRepository.selectAll(itemId);
24083 amit.gupta 140
				if (vips.size() > 0) {
24063 amit.gupta 141
					VendorItemPricing vip = vips.get(0);
142
					pm.setNlc(vip.getNlc());
143
					pm.setTp(vip.getTp());
144
				} else {
145
					throw new ProfitMandiBusinessException("Item Id", itemId, "Vendor item pricing does not exist");
146
				}
147
			}
24083 amit.gupta 148
		} catch (Exception e) {
24063 amit.gupta 149
			LOGGER.info("Chose item that doesn't exist");
24049 amit.gupta 150
		}
151
		model.addAttribute("response", mvcResponseSender.createResponseString(pm));
152
		return "response";
153
	}
24083 amit.gupta 154
 
24168 amit.gupta 155
	@RequestMapping(value = "/item", method = RequestMethod.GET)
156
	public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query) throws Throwable {
24383 amit.gupta 157
		String query1 = query.toLowerCase();
26299 amit.gupta 158
		List<ItemDescriptionModel> partnersItemDescription = inventoryService.getAllPartnerItemStringDescription().parallelStream()
24564 amit.gupta 159
				.filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
160
				.collect(Collectors.toList());
24168 amit.gupta 161
 
24191 amit.gupta 162
		model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
24168 amit.gupta 163
		return "response";
164
	}
165
 
23951 amit.gupta 166
	@RequestMapping(value = "/price-drop/imes/download")
167
	public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
168
			@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
169
		Item item = itemRepository.selectById(itemId);
26368 amit.gupta 170
		ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null);
23951 amit.gupta 171
		final HttpHeaders headers = new HttpHeaders();
172
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
25408 amit.gupta 173
		headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
23951 amit.gupta 174
		byte[] byteArray = baos.toByteArray();
175
		headers.setContentLength(byteArray.length);
176
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
177
	}
178
 
24083 amit.gupta 179
	@RequestMapping(value = "/price-drop/addPayout", method = RequestMethod.POST)
180
	public String updatePriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
181
			Model model) throws Exception {
182
		boolean response = false;
183
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
184
		if (priceDrop.getProcessTimestamp() == null) {
185
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
186
			priceDrop.setPriceDropIn(priceDropProcessModel.getPriceDropIn());
187
			// priceDrop.setProcessTimestamp(LocalDateTime.now());
188
			priceDropRepository.persist(priceDrop);
189
			response = true;
190
		}
191
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
192
		return "response";
193
	}
194
 
195
	@RequestMapping(value = "/priceDropImeis/{priceDropId}", method = RequestMethod.GET)
196
	public String priceDropStatus(HttpServletRequest request, @PathVariable int priceDropId, Model model)
197
			throws Exception {
198
 
199
		PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
24564 amit.gupta 200
 
201
		// This call is used to persit imeis to pricedrop imeis in case its not there.
26116 amit.gupta 202
		//This should be called while creating price drop.
203
		//priceDropService.priceDropStatus(priceDropId);
24564 amit.gupta 204
 
24083 amit.gupta 205
		List<String> pendingImeis = new ArrayList<>();
206
		List<String> approvedImeis = new ArrayList<>();
207
		List<String> rejectedImeis = new ArrayList<>();
208
		List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
209
		for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
210
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.PENDING)) {
211
				pendingImeis.add(priceDropIMEI.getImei());
212
			} else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)) {
213
				approvedImeis.add(priceDropIMEI.getImei());
214
			}
215
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.REJECTED)) {
216
				rejectedImeis.add(priceDropIMEI.getImei());
217
			}
218
		}
219
		priceDropImeisModel.setPendingImeis(pendingImeis);
220
		priceDropImeisModel.setPriceDropId(priceDropId);
221
		priceDropImeisModel.setApprovedImeis(approvedImeis);
222
		priceDropImeisModel.setRejectedImeis(rejectedImeis);
223
		model.addAttribute("response", mvcResponseSender.createResponseString(priceDropImeisModel));
224
		return "response";
225
	}
226
 
23968 amit.gupta 227
	@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
228
	public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcess,
229
			Model model) throws Exception {
230
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcess.getPriceDropId());
231
		boolean response = false;
232
		if (priceDrop.getProcessTimestamp() == null) {
26402 amit.gupta 233
			priceDropService.processPriceDrop(priceDrop.getId());
23968 amit.gupta 234
			priceDrop.setProcessTimestamp(LocalDateTime.now());
235
			priceDropRepository.persist(priceDrop);
236
			response = true;
23819 govind 237
		}
23968 amit.gupta 238
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
239
		return "response";
23819 govind 240
	}
24083 amit.gupta 241
 
23884 amit.gupta 242
	@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
23945 amit.gupta 243
	public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
244
			throws Exception {
23884 amit.gupta 245
		boolean response = false;
23968 amit.gupta 246
		priceDropModel.setAllColors(true);
23945 amit.gupta 247
		if (this.validatePriceDrop(priceDropModel)) {
23884 amit.gupta 248
			TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
24409 amit.gupta 249
			float oldDp = tagListing.getSellingPrice();
24410 amit.gupta 250
			float oldMop = tagListing.getMop();
251
			float oldTp = 0;
24409 amit.gupta 252
			float newDp = priceDropModel.getDp();
24564 amit.gupta 253
 
24410 amit.gupta 254
			if (newDp != oldDp) {
23884 amit.gupta 255
				List<Item> allItems = null;
256
				Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
23945 amit.gupta 257
				if (priceDropModel.isAllColors()) {
23884 amit.gupta 258
					allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
23945 amit.gupta 259
 
23884 amit.gupta 260
				} else {
23945 amit.gupta 261
					allItems = Arrays.asList(currentItem);
23884 amit.gupta 262
				}
23945 amit.gupta 263
				for (Item item : allItems) {
23884 amit.gupta 264
					TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
23945 amit.gupta 265
					if (itemTagListing == null)
266
						continue;
23884 amit.gupta 267
					itemTagListing.setSellingPrice(newDp);
268
					itemTagListing.setMop(priceDropModel.getMop());
269
					tagListingRepository.persist(tagListing);
270
					List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
23945 amit.gupta 271
					for (VendorItemPricing vip : vipList) {
24410 amit.gupta 272
						oldTp = vip.getNlc();
23884 amit.gupta 273
						vip.setDp(newDp);
274
						vip.setMop(priceDropModel.getMop());
24409 amit.gupta 275
						vip.setNlc(priceDropModel.getTp());
23884 amit.gupta 276
						vip.setTp(priceDropModel.getTp());
277
						vendorItemPricingRepository.persist(vip);
278
					}
279
					transactionService.updatePriceDrop(item.getId(), newDp);
280
				}
24822 amit.gupta 281
 
282
				//Add to itemPricing history
283
				ItemPricingHistory iph = new ItemPricingHistory();
284
				iph.setCatalogId(currentItem.getCatalogItemId());
285
				iph.setTp(priceDropModel.getTp());
286
				iph.setDp(priceDropModel.getDp());
287
				iph.setMop(priceDropModel.getMop());
288
				//TODO: changedBy
289
				iph.setChangedBy("me");
290
				iph.setCreateTimestamp(LocalDateTime.now());
291
				itemPricingHistoryRepository.persist(iph);
292
 
293
 
23951 amit.gupta 294
				PriceDrop priceDrop = new PriceDrop();
295
				priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
24410 amit.gupta 296
				priceDrop.setTp(oldTp);
297
				priceDrop.setNlc(oldTp);
298
				priceDrop.setMop(oldMop);
24409 amit.gupta 299
				priceDrop.setOldDp(oldDp);
300
				priceDrop.setAmount(oldDp - newDp);
23968 amit.gupta 301
				priceDrop.setNewDp(newDp);
23951 amit.gupta 302
				priceDrop.setCreatedOn(LocalDateTime.now());
303
				priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
304
				priceDropRepository.persist(priceDrop);
26116 amit.gupta 305
				priceDropService.priceDropStatus(priceDrop.getId());
23884 amit.gupta 306
				response = true;
307
			} else {
23945 amit.gupta 308
				throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
24409 amit.gupta 309
						"Price Drop Should be greater than 0");
23884 amit.gupta 310
			}
311
		}
312
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
313
		return "response";
314
	}
23945 amit.gupta 315
 
23819 govind 316
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
317
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
23945 amit.gupta 318
			Model model) throws ProfitMandiBusinessException, Exception {
23819 govind 319
 
320
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
26368 amit.gupta 321
		Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).
322
				stream().collect(Collectors.toMap(x->x.getImei(), x->x));
323
 
26372 amit.gupta 324
		if(priceDropIMEIsMap.size()==0 && priceDrop.getProcessTimestamp()==null) {
325
			priceDrop.setProcessTimestamp(LocalDateTime.now());
326
		} else {
327
			priceDropService.priceDropStatus(priceDrop.getId());
328
		}
329
 
23968 amit.gupta 330
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
26368 amit.gupta 331
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(), priceDropIMEIsMap);
23968 amit.gupta 332
		final HttpHeaders headers = new HttpHeaders();
333
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
23983 amit.gupta 334
		headers.set("Content-disposition",
335
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
336
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
23968 amit.gupta 337
		byte[] byteArray = baos.toByteArray();
338
		headers.setContentLength(byteArray.length);
339
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
23951 amit.gupta 340
 
341
	}
342
 
26400 amit.gupta 343
	@RequestMapping(value = "/updatePriceDropImeis-DNC", method = RequestMethod.POST)
24822 amit.gupta 344
	public String updatePriceDropImeis(HttpServletRequest request,
24083 amit.gupta 345
			@RequestBody PriceDropImeisModel priceDropImeisModel, Model model)
346
			throws ProfitMandiBusinessException, Exception {
24168 amit.gupta 347
		PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
24083 amit.gupta 348
 
349
		switch (priceDropImeisModel.getUpdatedStatus()) {
26332 amit.gupta 350
			case "approved": {
26400 amit.gupta 351
				status = PriceDropImeiStatus.APPROVED_OURS;
26332 amit.gupta 352
				break;
353
			}
354
			case "rejected": {
355
				status = PriceDropImeiStatus.REJECTED;
356
				break;
357
			}
24083 amit.gupta 358
		}
26332 amit.gupta 359
 
360
		if(PriceDropImeiStatus.PENDING.equals(status)) {
361
			throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING", "only approved and rejected is allowed");
24083 amit.gupta 362
		}
26332 amit.gupta 363
 
364
		//TODO:PD 
24083 amit.gupta 365
		List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
366
				.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
367
 
368
		List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
369
		for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
370
			if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
371
					|| priceDropIMEI.getStatus().equals(status)) {
372
				continue;
373
			}
26368 amit.gupta 374
			priceDropIMEIsToProcess.add(priceDropIMEI);
375
			if(status.equals(PriceDropImeiStatus.REJECTED)) {
376
				priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
377
			}
378
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
24083 amit.gupta 379
		}
26401 amit.gupta 380
		/*if (priceDropIMEIsToProcess.size() > 0) {
26332 amit.gupta 381
			priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(), priceDropIMEIsToProcess, status);
26401 amit.gupta 382
		}*/
24168 amit.gupta 383
 
24083 amit.gupta 384
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
385
		return "response";
386
 
387
	}
388
 
26368 amit.gupta 389
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId, Map<String, PriceDropIMEI> priceDropImeis)
23983 amit.gupta 390
			throws Exception {
24564 amit.gupta 391
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
392
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
25852 amit.gupta 393
		List<List<?>> rows = new ArrayList<>();
23983 amit.gupta 394
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
26368 amit.gupta 395
			if(priceDropImeis == null) {
396
				rows.add(this.getRow(imeiDropSummaryModel, null));
397
			} else if(priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
398
				rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
399
			}
23951 amit.gupta 400
		}
26368 amit.gupta 401
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand", 
26420 amit.gupta 402
				"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name", "Grn On", "Activation Timestamp", "Activation Added On"), rows);
23819 govind 403
	}
24083 amit.gupta 404
 
26368 amit.gupta 405
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel, PriceDropIMEI priceDropIMEI) {
24822 amit.gupta 406
		List<Serializable> row = new ArrayList<>();
23986 amit.gupta 407
		row.add(imeiDropSummaryModel.getSerialNumber());
408
		row.add(imeiDropSummaryModel.getStoreName());
409
		row.add(imeiDropSummaryModel.getPartnerCode());
410
		row.add(imeiDropSummaryModel.getItemId());
411
		row.add(imeiDropSummaryModel.getBrand());
412
		row.add(imeiDropSummaryModel.getModelName());
413
		row.add(imeiDropSummaryModel.getModelNumber());
414
		row.add(imeiDropSummaryModel.getColor());
26368 amit.gupta 415
		if(priceDropIMEI != null) {
416
			row.add(priceDropIMEI.getStatus());
417
			row.add(priceDropIMEI.getRejectionReason());
418
		} else {
419
			row.add(PriceDropImeiStatus.PENDING);
420
			row.add("");
421
		}
26373 amit.gupta 422
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
423
		row.add(imeiDropSummaryModel.getVendorName());
26420 amit.gupta 424
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getGrnOn()));
26368 amit.gupta 425
		row.add(imeiDropSummaryModel.getActivationTimestamp());
426
		row.add(imeiDropSummaryModel.getActivationAddedOn());
23986 amit.gupta 427
		return row;
428
	}
23819 govind 429
 
23884 amit.gupta 430
	private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
24564 amit.gupta 431
		if (priceDropModel.getMop() > 0 && priceDropModel.getDp() > 0 && priceDropModel.getTp() > 0) {
23884 amit.gupta 432
			return true;
433
		}
434
		return false;
435
	}
23945 amit.gupta 436
 
23819 govind 437
}