Subversion Repositories SmartDukaan

Rev

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

Rev 31852 Rev 31903
Line 9... Line 9...
9
import com.spice.profitmandi.common.util.FormattingUtils;
9
import com.spice.profitmandi.common.util.FormattingUtils;
10
import com.spice.profitmandi.common.util.Utils;
10
import com.spice.profitmandi.common.util.Utils;
11
import com.spice.profitmandi.dao.entity.catalog.Item;
11
import com.spice.profitmandi.dao.entity.catalog.Item;
12
import com.spice.profitmandi.dao.entity.catalog.TagListing;
12
import com.spice.profitmandi.dao.entity.catalog.TagListing;
13
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
13
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
14
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
-
 
15
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
14
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
16
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
15
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
17
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
16
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
18
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
17
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
-
 
18
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
19
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
19
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
-
 
20
import com.spice.profitmandi.dao.model.AmountModel;
20
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
21
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
21
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
22
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
22
import com.spice.profitmandi.dao.repository.cs.CsService;
23
import com.spice.profitmandi.dao.repository.cs.CsService;
23
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24
import com.spice.profitmandi.dao.repository.dtr.Mongo;
25
import com.spice.profitmandi.dao.repository.dtr.Mongo;
Line 30... Line 31...
30
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
31
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
31
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
32
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
32
import com.spice.profitmandi.service.NotificationService;
33
import com.spice.profitmandi.service.NotificationService;
33
import com.spice.profitmandi.service.authentication.RoleManager;
34
import com.spice.profitmandi.service.authentication.RoleManager;
34
import com.spice.profitmandi.service.inventory.InventoryService;
35
import com.spice.profitmandi.service.inventory.InventoryService;
35
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModel;
36
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModelNew;
36
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
37
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
37
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
38
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
38
import com.spice.profitmandi.service.pricing.PriceDropService;
39
import com.spice.profitmandi.service.pricing.PriceDropService;
39
import com.spice.profitmandi.service.scheme.SchemeService;
40
import com.spice.profitmandi.service.scheme.SchemeService;
40
import com.spice.profitmandi.service.transaction.TransactionService;
41
import com.spice.profitmandi.service.transaction.TransactionService;
Line 66... Line 67...
66
 
67
 
67
@Controller
68
@Controller
68
@Transactional(rollbackFor = Throwable.class)
69
@Transactional(rollbackFor = Throwable.class)
69
public class PriceDropController {
70
public class PriceDropController {
70
 
71
 
71
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
72
    private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
72
 
73
    private static final List<String> SELLINS = Arrays.asList("Base Payout", "Cash Discount", "Upfront Margin", "Modelwise");
73
	@Autowired
74
    private static final List<String> SELLOUTS = Arrays.asList("Tertiary Payout", "Hygiene Payout", "Investment Payout", "Category Payout", "Activation Margin", "Special Support");
74
	private CsService csService;
75
    private static final List<String> ALL_MARGINS = Arrays.asList(SELLINS, SELLOUTS).stream().flatMap(x -> x.stream()).collect(Collectors.toList());
75
 
76
    @Autowired
76
	@Autowired
77
    ReporticoService reporticoService;
77
	private UserRepository dtrUserRepository;
78
    @Autowired
78
 
79
    LineItemImeisRepository lineItemImeisRepository;
79
	@Autowired
80
    @Autowired
80
	private PriceDropRepository priceDropRepository;
81
    PriceCircularService priceCircularService;
81
 
82
    @Autowired
82
	@Autowired
83
    private CsService csService;
83
	private ObjectMapper objectMapper;
84
    @Autowired
84
 
85
    private UserRepository dtrUserRepository;
85
	@Autowired
86
    @Autowired
86
	private VendorItemPricingRepository vendorItemPricingRepository;
87
    private PriceDropRepository priceDropRepository;
87
 
88
    @Autowired
88
	@Autowired
89
    private ObjectMapper objectMapper;
89
	@Qualifier("fofoInventoryService")
90
    @Autowired
90
	private InventoryService inventoryService;
91
    private VendorItemPricingRepository vendorItemPricingRepository;
91
 
92
    @Autowired
92
	@Autowired
93
    @Qualifier("fofoInventoryService")
93
	private MVCResponseSender mvcResponseSender;
94
    private InventoryService inventoryService;
94
 
95
    @Autowired
95
	@Autowired
96
    private MVCResponseSender mvcResponseSender;
96
	private PriceDropService priceDropService;
97
    @Autowired
97
 
98
    private PriceDropService priceDropService;
98
	@Autowired
99
    @Autowired
99
	private ItemPricingHistoryRepository itemPricingHistoryRepository;
100
    private ItemPricingHistoryRepository itemPricingHistoryRepository;
100
 
101
    @Autowired
101
	@Autowired
102
    private WalletService walletService;
102
	private WalletService walletService;
103
    @Autowired
103
 
104
    private TagListingRepository tagListingRepository;
104
	@Autowired
105
    @Autowired
105
	private TagListingRepository tagListingRepository;
106
    private TransactionService transactionService;
106
 
107
    @Autowired
107
	@Autowired
108
    private PriceDropIMEIRepository priceDropIMEIRepository;
108
	private TransactionService transactionService;
109
    @Autowired
109
 
110
    private RoleManager roleManager;
110
	@Autowired
111
    @Autowired
111
	private PriceDropIMEIRepository priceDropIMEIRepository;
112
    @Qualifier("catalogItemRepository")
112
 
113
    private ItemRepository itemRepository;
113
	@Autowired
114
    @Autowired
114
	private RoleManager roleManager;
115
    private SchemeService schemeService;
115
 
116
    @Autowired
116
	@Autowired
117
    private Mongo mongoClient;
117
	@Qualifier("catalogItemRepository")
118
    @Autowired
118
	private ItemRepository itemRepository;
119
    private CookiesProcessor cookiesProcessor;
119
 
120
    @Autowired
120
	@Autowired
121
    private PartnerTypeChangeService partnerTypeChangeService;
121
	private SchemeService schemeService;
122
    @Autowired
122
 
123
    private RetailerService retailerService;
123
	@Autowired
124
    @Autowired
124
	ReporticoService reporticoService;
125
    private NotificationService notificationService;
125
 
126
    @Autowired
126
	@Autowired
127
    private FofoStoreRepository fofoStoreRepository;
127
	LineItemImeisRepository lineItemImeisRepository;
128
 
128
 
129
    @RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
129
	@Autowired
130
    public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
130
	private Mongo mongoClient;
131
        List<PriceDrop> priceDrops = priceDropRepository.selectAllIncomplete();
131
 
132
        Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
132
	@Autowired
133
 
133
	private CookiesProcessor cookiesProcessor;
134
        List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
134
 
135
        Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
135
	@Autowired
136
                x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
136
	private PartnerTypeChangeService partnerTypeChangeService;
137
        model.addAttribute("priceDrops", priceDrops);
137
 
138
        model.addAttribute("catalogDescription", catalogDescription);
138
	@Autowired
139
        return "price-drop";
139
	private RetailerService retailerService;
140
    }
140
 
141
 
141
	@Autowired
142
    @RequestMapping(value = "/getClosedPricedropItemDescription", method = RequestMethod.GET)
142
	private NotificationService notificationService;
143
    public String getClosedPricedropItemDescription(HttpServletRequest request, Model model) throws Throwable {
143
 
144
        List<PriceDrop> priceDrops = priceDropRepository.selectAllComplete();
144
	@Autowired
145
        int processOn = 1;
145
	private FofoStoreRepository fofoStoreRepository;
146
 
146
 
147
        List<PriceDrop> completePriceDrops = priceDrops.stream().filter(x -> x.getCompleteTimestamp() != null)
147
	private static final List<String> SELLINS = Arrays.asList("Base Payout", "Cash Discount", "Upfront Margin", "Modelwise");
148
                .collect(Collectors.toList());
148
	private static final List<String> SELLOUTS = Arrays.asList("Tertiary Payout", "Hygiene Payout", "Investment Payout", "Category Payout", "Activation Margin", "Special Support");
149
 
149
	private static final List<String> ALL_MARGINS = Arrays.asList(SELLINS, SELLOUTS).stream().flatMap(x -> x.stream()).collect(Collectors.toList());
150
        Set<Integer> catalogIds = completePriceDrops.stream().map(x -> x.getCatalogItemId())
150
 
151
                .collect(Collectors.toSet());
151
	@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
152
        List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
152
	public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
153
        LOGGER.info("catalogIds" + catalogIds);
153
		List<PriceDrop> priceDrops = priceDropRepository.selectAllIncomplete();
154
 
154
		Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
155
        Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
155
 
156
                x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
156
		List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
157
        model.addAttribute("priceDrops", completePriceDrops);
157
		Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
158
        model.addAttribute("processOn", processOn);
158
				x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
159
        model.addAttribute("catalogDescription", catalogDescription);
159
		model.addAttribute("priceDrops", priceDrops);
160
        return "price-drop";
160
		model.addAttribute("catalogDescription", catalogDescription);
161
    }
161
		return "price-drop";
162
 
162
	}
163
    @RequestMapping(value = "/item-pricing/{itemId}", method = RequestMethod.GET)
163
 
164
    public String getItemPricing(HttpServletRequest request, Model model, @PathVariable int itemId) throws Throwable {
164
	@RequestMapping(value = "/getClosedPricedropItemDescription", method = RequestMethod.GET)
165
 
165
	public String getClosedPricedropItemDescription(HttpServletRequest request, Model model) throws Throwable {
166
        TagListing tagListing;
166
		List<PriceDrop> priceDrops = priceDropRepository.selectAllComplete();
167
        PriceDropModel pm = new PriceDropModel();
167
		int processOn = 1;
168
        try {
168
 
169
            tagListing = tagListingRepository.selectByItemId(itemId);
169
		List<PriceDrop> completePriceDrops = priceDrops.stream().filter(x -> x.getCompleteTimestamp() != null)
170
            if (tagListing != null) {
170
				.collect(Collectors.toList());
171
                pm.setMop(tagListing.getMop());
171
 
172
                pm.setDp(tagListing.getSellingPrice());
172
		Set<Integer> catalogIds = completePriceDrops.stream().map(x -> x.getCatalogItemId())
173
                pm.setMrp(tagListing.getMrp());
173
				.collect(Collectors.toSet());
174
                List<VendorItemPricing> vips = vendorItemPricingRepository.selectAll(itemId);
174
		List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
175
                if (vips.size() > 0) {
175
		LOGGER.info("catalogIds" + catalogIds);
176
                    VendorItemPricing vip = vips.get(0);
176
 
177
                    pm.setNlc(vip.getNlc());
177
		Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
178
                    pm.setTp(vip.getTp());
178
				x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
179
                } else {
179
		model.addAttribute("priceDrops", completePriceDrops);
180
                    throw new ProfitMandiBusinessException("Item Id", itemId, "Vendor item pricing does not exist");
180
		model.addAttribute("processOn", processOn);
181
                }
181
		model.addAttribute("catalogDescription", catalogDescription);
182
            }
182
		return "price-drop";
183
        } catch (Exception e) {
183
	}
184
            LOGGER.info("Chose item that doesn't exist");
184
 
185
        }
185
	@RequestMapping(value = "/item-pricing/{itemId}", method = RequestMethod.GET)
186
        model.addAttribute("response1", mvcResponseSender.createResponseString(pm));
186
	public String getItemPricing(HttpServletRequest request, Model model, @PathVariable int itemId) throws Throwable {
187
        return "response";
187
 
188
    }
188
		TagListing tagListing;
189
 
189
		PriceDropModel pm = new PriceDropModel();
190
    @RequestMapping(value = "/item", method = RequestMethod.GET)
190
		try {
191
    public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query,
191
			tagListing = tagListingRepository.selectByItemId(itemId);
192
                                 @RequestParam boolean anyColor) throws Throwable {
192
			if (tagListing != null) {
193
        String query1 = query.toLowerCase();
193
				pm.setMop(tagListing.getMop());
194
 
194
				pm.setDp(tagListing.getSellingPrice());
195
        List<ItemDescriptionModel> partnersItemDescription = inventoryService
195
				pm.setMrp(tagListing.getMrp());
196
                .getAllPartnerItemStringDescription(anyColor).parallelStream()
196
				List<VendorItemPricing> vips = vendorItemPricingRepository.selectAll(itemId);
197
                .filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
197
				if (vips.size() > 0) {
198
                .collect(Collectors.toList());
198
					VendorItemPricing vip = vips.get(0);
199
        LOGGER.info("partnersItemDescription" + partnersItemDescription);
199
					pm.setNlc(vip.getNlc());
200
 
200
					pm.setTp(vip.getTp());
201
        model.addAttribute("response1", mvcResponseSender.createResponseString(partnersItemDescription));
201
				} else {
202
        return "response";
202
					throw new ProfitMandiBusinessException("Item Id", itemId, "Vendor item pricing does not exist");
203
    }
203
				}
204
 
204
			}
205
    @RequestMapping(value = "/price-drop/imes/download")
205
		} catch (Exception e) {
206
    public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
206
			LOGGER.info("Chose item that doesn't exist");
207
                                                                    @RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
207
		}
208
        Item item = itemRepository.selectById(itemId);
208
		model.addAttribute("response1", mvcResponseSender.createResponseString(pm));
209
        ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null);
209
		return "response";
210
        final HttpHeaders headers = new HttpHeaders();
210
	}
211
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
211
 
212
        headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
212
	@RequestMapping(value = "/item", method = RequestMethod.GET)
213
        byte[] byteArray = baos.toByteArray();
213
	public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query,
214
        headers.setContentLength(byteArray.length);
214
								 @RequestParam boolean anyColor) throws Throwable {
215
        return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
215
		String query1 = query.toLowerCase();
216
    }
216
 
217
 
217
		List<ItemDescriptionModel> partnersItemDescription = inventoryService
218
    @RequestMapping(value = "/price-drop/addPayout", method = RequestMethod.POST)
218
				.getAllPartnerItemStringDescription(anyColor).parallelStream()
219
    public String updatePriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
219
				.filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
220
                                  Model model) throws Exception {
220
				.collect(Collectors.toList());
221
        boolean response = false;
221
		LOGGER.info("partnersItemDescription" + partnersItemDescription);
222
        PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
222
 
223
        if (priceDrop.getProcessTimestamp() == null) {
223
		model.addAttribute("response1", mvcResponseSender.createResponseString(partnersItemDescription));
224
            priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
224
		return "response";
225
            priceDrop.setPriceDropIn(priceDropProcessModel.getPriceDropIn());
225
	}
226
            // priceDrop.setProcessTimestamp(LocalDateTime.now());
226
 
227
            priceDropRepository.persist(priceDrop);
227
	@RequestMapping(value = "/price-drop/imes/download")
228
            response = true;
228
	public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
229
        }
229
																	@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
230
        model.addAttribute("response1", mvcResponseSender.createResponseString(response));
230
		Item item = itemRepository.selectById(itemId);
231
        return "response";
231
		ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null);
232
    }
232
		final HttpHeaders headers = new HttpHeaders();
233
 
233
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
234
    @RequestMapping(value = "/priceDropImeis/{priceDropId}", method = RequestMethod.GET)
234
		headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
235
    public String priceDropStatus(HttpServletRequest request, @PathVariable int priceDropId, Model model)
235
		byte[] byteArray = baos.toByteArray();
236
            throws Exception {
236
		headers.setContentLength(byteArray.length);
237
 
237
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
238
        PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
238
	}
239
 
239
 
240
        // This call is used to persit imeis to pricedrop imeis in case its not there.
240
	@RequestMapping(value = "/price-drop/addPayout", method = RequestMethod.POST)
241
        // This should be called while creating price drop.
241
	public String updatePriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
242
        // priceDropService.priceDropStatus(priceDropId);
242
								  Model model) throws Exception {
243
 
243
		boolean response = false;
244
        List<String> pendingImeis = new ArrayList<>();
244
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
245
        List<String> approvedImeis = new ArrayList<>();
245
		if (priceDrop.getProcessTimestamp() == null) {
246
        List<String> rejectedImeis = new ArrayList<>();
246
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
247
        List<String> holdImeis = new ArrayList<>();
247
			priceDrop.setPriceDropIn(priceDropProcessModel.getPriceDropIn());
248
        List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
248
			// priceDrop.setProcessTimestamp(LocalDateTime.now());
249
        for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
249
			priceDropRepository.persist(priceDrop);
250
            if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.PENDING)) {
250
			response = true;
251
                pendingImeis.add(priceDropIMEI.getImei());
251
		}
252
            } else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)) {
252
		model.addAttribute("response1", mvcResponseSender.createResponseString(response));
253
                approvedImeis.add(priceDropIMEI.getImei());
253
		return "response";
254
            }
254
	}
255
            if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.REJECTED)) {
255
 
256
                rejectedImeis.add(priceDropIMEI.getImei());
256
	@RequestMapping(value = "/priceDropImeis/{priceDropId}", method = RequestMethod.GET)
257
            } else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.HOLD)) {
257
	public String priceDropStatus(HttpServletRequest request, @PathVariable int priceDropId, Model model)
258
                holdImeis.add(priceDropIMEI.getImei());
258
			throws Exception {
259
 
259
 
260
            }
260
		PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
261
        }
261
 
262
        LOGGER.info("pendingImeis" + pendingImeis);
262
		// This call is used to persit imeis to pricedrop imeis in case its not there.
263
        LOGGER.info("approvedImeis" + approvedImeis);
263
		// This should be called while creating price drop.
264
        LOGGER.info("rejectedImeis" + rejectedImeis);
264
		// priceDropService.priceDropStatus(priceDropId);
265
        LOGGER.info("priceDropImeis" + priceDropImeis);
265
 
266
 
266
		List<String> pendingImeis = new ArrayList<>();
267
        priceDropImeisModel.setPendingImeis(pendingImeis);
267
		List<String> approvedImeis = new ArrayList<>();
268
        priceDropImeisModel.setPriceDropId(priceDropId);
268
		List<String> rejectedImeis = new ArrayList<>();
269
        priceDropImeisModel.setApprovedImeis(approvedImeis);
269
		List<String> holdImeis = new ArrayList<>();
270
        priceDropImeisModel.setHoldImeis(holdImeis);
270
		List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
271
        priceDropImeisModel.setRejectedImeis(rejectedImeis);
271
		for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
272
        model.addAttribute("response1", mvcResponseSender.createResponseString(priceDropImeisModel));
272
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.PENDING)) {
273
        return "response";
273
				pendingImeis.add(priceDropIMEI.getImei());
274
    }
274
			} else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)) {
275
 
275
				approvedImeis.add(priceDropIMEI.getImei());
276
    @RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
276
			}
277
    public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
277
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.REJECTED)) {
278
                                   Model model) throws Exception {
278
				rejectedImeis.add(priceDropIMEI.getImei());
279
        PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
279
			} else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.HOLD)) {
280
        boolean response = false;
280
				holdImeis.add(priceDropIMEI.getImei());
281
        if (priceDrop.getPartnerPayout() == 0) {
281
 
282
            priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
282
			}
283
        }
283
		}
284
        priceDrop.setProcessTimestamp(LocalDateTime.now());
284
		LOGGER.info("pendingImeis" + pendingImeis);
285
        priceDropRepository.persist(priceDrop);
285
		LOGGER.info("approvedImeis" + approvedImeis);
286
        priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
286
		LOGGER.info("rejectedImeis" + rejectedImeis);
287
        response = true;
287
		LOGGER.info("priceDropImeis" + priceDropImeis);
288
        model.addAttribute("response1", mvcResponseSender.createResponseString(response));
288
 
289
        return "response";
289
		priceDropImeisModel.setPendingImeis(pendingImeis);
290
    }
290
		priceDropImeisModel.setPriceDropId(priceDropId);
291
 
291
		priceDropImeisModel.setApprovedImeis(approvedImeis);
292
    @RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
292
		priceDropImeisModel.setHoldImeis(holdImeis);
293
    public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
293
		priceDropImeisModel.setRejectedImeis(rejectedImeis);
294
            throws Exception {
294
		model.addAttribute("response1", mvcResponseSender.createResponseString(priceDropImeisModel));
295
        boolean response = false;
295
		return "response";
296
        priceDropModel.setAllColors(true);
296
	}
297
        if (this.validatePriceDrop(priceDropModel)) {
297
 
298
            TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
298
	@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
299
            float oldDp = tagListing.getSellingPrice();
299
	public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
300
            float oldMop = tagListing.getMop();
300
								   Model model) throws Exception {
301
            float oldTp = 0;
301
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
302
            float newDp = priceDropModel.getDp();
302
		boolean response = false;
303
 
303
		if (priceDrop.getPartnerPayout() == 0) {
304
            if (newDp != oldDp) {
304
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
305
                List<Item> allItems = null;
305
		}
306
                Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
306
		priceDrop.setProcessTimestamp(LocalDateTime.now());
307
                if (priceDropModel.isAllColors()) {
307
		priceDropRepository.persist(priceDrop);
308
                    allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
308
		priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
309
 
309
		response = true;
310
                } else {
310
		model.addAttribute("response1", mvcResponseSender.createResponseString(response));
311
                    allItems = Arrays.asList(currentItem);
311
		return "response";
312
                }
312
	}
313
                for (Item item : allItems) {
313
 
314
                    TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
314
	@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
315
                    if (itemTagListing == null)
315
	public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
316
                        continue;
316
			throws Exception {
317
                    itemTagListing.setSellingPrice(newDp);
317
		boolean response = false;
318
                    itemTagListing.setMop(priceDropModel.getMop());
318
		priceDropModel.setAllColors(true);
319
                    List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
319
		if (this.validatePriceDrop(priceDropModel)) {
320
                    for (VendorItemPricing vip : vipList) {
320
			TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
321
                        oldTp = vip.getNlc();
321
			float oldDp = tagListing.getSellingPrice();
322
                        vip.setDp(newDp);
322
			float oldMop = tagListing.getMop();
323
                        vip.setMop(priceDropModel.getMop());
323
			float oldTp = 0;
324
                        //Lets not update NLC/TP as it has to be managed by Category Tea,
324
			float newDp = priceDropModel.getDp();
325
                        //vip.setNlc(priceDropModel.getTp());
325
 
326
                        //vip.setTp(priceDropModel.getTp());
326
			if (newDp != oldDp) {
327
                        vendorItemPricingRepository.persist(vip);
327
				List<Item> allItems = null;
328
                    }
328
				Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
329
                    transactionService.updatePriceDrop(item.getId(), newDp);
329
				if (priceDropModel.isAllColors()) {
330
                }
330
					allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
331
 
331
 
332
                // Add to itemPricing history
332
				} else {
333
                ItemPricingHistory iph = new ItemPricingHistory();
333
					allItems = Arrays.asList(currentItem);
334
                iph.setCatalogId(currentItem.getCatalogItemId());
334
				}
335
                iph.setTp(priceDropModel.getTp());
335
				for (Item item : allItems) {
336
                iph.setDp(priceDropModel.getDp());
336
					TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
337
                iph.setMop(priceDropModel.getMop());
337
					if (itemTagListing == null)
338
                // TODO: changedBy
338
						continue;
339
                iph.setChangedBy("me");
339
					itemTagListing.setSellingPrice(newDp);
340
                iph.setCreateTimestamp(LocalDateTime.now());
340
					itemTagListing.setMop(priceDropModel.getMop());
341
                itemPricingHistoryRepository.persist(iph);
341
					List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
342
 
342
					for (VendorItemPricing vip : vipList) {
343
                PriceDrop priceDrop = new PriceDrop();
343
						oldTp = vip.getNlc();
344
                priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
344
						vip.setDp(newDp);
345
                priceDrop.setTp(oldTp);
345
						vip.setMop(priceDropModel.getMop());
346
                priceDrop.setNlc(oldTp);
346
						//Lets not update NLC/TP as it has to be managed by Category Tea,
347
                priceDrop.setMop(oldMop);
347
						//vip.setNlc(priceDropModel.getTp());
348
                priceDrop.setOldDp(oldDp);
348
						//vip.setTp(priceDropModel.getTp());
349
                priceDrop.setAmount(oldDp - newDp);
349
						vendorItemPricingRepository.persist(vip);
350
                priceDrop.setNewDp(newDp);
350
					}
351
                priceDrop.setCreatedOn(LocalDateTime.now());
351
					transactionService.updatePriceDrop(item.getId(), newDp);
352
                priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
352
				}
353
                priceDropRepository.persist(priceDrop);
353
 
354
                priceDropService.priceDropStatus(priceDrop.getId());
354
				// Add to itemPricing history
355
                response = true;
355
				ItemPricingHistory iph = new ItemPricingHistory();
356
 
356
				iph.setCatalogId(currentItem.getCatalogItemId());
357
                this.sendPriceChangeNotification(priceDrop);
357
				iph.setTp(priceDropModel.getTp());
358
            } else {
358
				iph.setDp(priceDropModel.getDp());
359
                throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
359
				iph.setMop(priceDropModel.getMop());
360
                        "Price Drop Should be greater than 0");
360
				// TODO: changedBy
361
            }
361
				iph.setChangedBy("me");
362
        }
362
				iph.setCreateTimestamp(LocalDateTime.now());
363
        model.addAttribute("response1", mvcResponseSender.createResponseString(response));
363
				itemPricingHistoryRepository.persist(iph);
364
        return "response";
364
 
365
    }
365
				PriceDrop priceDrop = new PriceDrop();
366
 
366
				priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
367
    private void sendPriceChangeNotification(PriceDrop priceDrop) throws ProfitMandiBusinessException {
367
				priceDrop.setTp(oldTp);
368
        List<Item> items = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId());
368
				priceDrop.setNlc(oldTp);
369
        String title = "Price has been %s for %s";
369
				priceDrop.setMop(oldMop);
370
 
370
				priceDrop.setOldDp(oldDp);
371
 
371
				priceDrop.setAmount(oldDp - newDp);
372
        SendNotificationModel sendNotificationModel = new SendNotificationModel();
372
				priceDrop.setNewDp(newDp);
373
        sendNotificationModel.setCampaignName("pricechange");
373
				priceDrop.setCreatedOn(LocalDateTime.now());
374
        sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
374
				priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
375
        sendNotificationModel.setTitle("");
375
				priceDropRepository.persist(priceDrop);
376
        StringBuffer sb = new StringBuffer();
376
				priceDropService.priceDropStatus(priceDrop.getId());
377
        String message = null;
377
				response = true;
378
        if (priceDrop.getDropAmount() > 0) {
378
 
379
            title = String.format(title, "dropped", items.get(0).getItemDescriptionNoColor());
379
				this.sendPriceChangeNotification(priceDrop);
380
            message = String.format("Price has been dropped from Rs.%s. Old DP - Rs.%s, New DP - Rs.%s", FormattingUtils.formatDecimal(priceDrop.getDropAmount()),
380
			} else {
381
                    FormattingUtils.formatDecimal(priceDrop.getOldDp()), FormattingUtils.formatDecimal(priceDrop.getNewDp()));
381
				throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
382
        } else {
382
						"Price Drop Should be greater than 0");
383
            title = String.format(title, "increased", items.get(0).getItemDescriptionNoColor());
383
			}
384
            message = String.format("Price has been increased from Rs.%s. Old DP - Rs.%s, New DP - Rs.%s", FormattingUtils.formatDecimal(-priceDrop.getDropAmount()),
384
		}
385
                    FormattingUtils.formatDecimal(priceDrop.getOldDp()), FormattingUtils.formatDecimal(priceDrop.getNewDp()));
385
		model.addAttribute("response1", mvcResponseSender.createResponseString(response));
386
        }
386
		return "response";
387
        sendNotificationModel.setTitle(title);
387
	}
388
        sendNotificationModel.setMessage(message);
388
 
389
        sendNotificationModel.setMessageType(MessageType.pricechange);
389
	private void sendPriceChangeNotification(PriceDrop priceDrop) throws ProfitMandiBusinessException {
390
        notificationService.sendNotificationToAll(sendNotificationModel);
390
		List<Item> items = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId());
391
    }
391
		String title = "Price has been %s for %s";
392
 
392
 
393
    @RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
393
 
394
    public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
394
		SendNotificationModel sendNotificationModel = new SendNotificationModel();
395
                                                        Model model) throws ProfitMandiBusinessException, Exception {
395
		sendNotificationModel.setCampaignName("pricechange");
396
 
396
		sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
397
        PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
397
		sendNotificationModel.setTitle("");
398
        Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
398
		StringBuffer sb = new StringBuffer();
399
                .collect(Collectors.toMap(x -> x.getImei(), x -> x));
399
		String message = null;
400
        LOGGER.info("PriceDropImeis {}, priceDropId {}", priceDropIMEIsMap, priceDropId);
400
		if (priceDrop.getDropAmount() > 0) {
401
        Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
401
			title = String.format(title, "dropped", items.get(0).getItemDescriptionNoColor());
402
        final HttpHeaders headers = new HttpHeaders();
402
			message = String.format("Price has been dropped from Rs.%s. Old DP - Rs.%s, New DP - Rs.%s", FormattingUtils.formatDecimal(priceDrop.getDropAmount()),
403
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
403
					FormattingUtils.formatDecimal(priceDrop.getOldDp()), FormattingUtils.formatDecimal(priceDrop.getNewDp()));
404
        headers.set("Content-disposition",
404
		} else {
405
                "inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
405
			title = String.format(title, "increased", items.get(0).getItemDescriptionNoColor());
406
                        + FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
406
			message = String.format("Price has been increased from Rs.%s. Old DP - Rs.%s, New DP - Rs.%s", FormattingUtils.formatDecimal(-priceDrop.getDropAmount()),
407
        ByteArrayOutputStream baos = null;
407
					FormattingUtils.formatDecimal(priceDrop.getOldDp()), FormattingUtils.formatDecimal(priceDrop.getNewDp()));
408
        if (priceDropIMEIsMap.size() == 0) {
408
		}
409
            priceDropService.priceDropStatus(priceDrop.getId());
409
		sendNotificationModel.setTitle(title);
410
            baos = FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
410
		sendNotificationModel.setMessage(message);
411
                    "Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
411
		sendNotificationModel.setMessageType(MessageType.pricechange);
412
                    "Grn On", "Activation Timestamp", "Activation Added On"), new ArrayList<>());
412
		notificationService.sendNotificationToAll(sendNotificationModel);
413
        } else {
413
	}
414
 
414
 
415
            LOGGER.info("In else block");
415
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
416
            baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
416
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
417
                    priceDropIMEIsMap);
417
														Model model) throws ProfitMandiBusinessException, Exception {
418
        }
418
 
419
        byte[] byteArray = baos.toByteArray();
419
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
420
        headers.setContentLength(byteArray.length);
420
		Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
421
        return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
421
				.collect(Collectors.toMap(x -> x.getImei(), x -> x));
422
 
422
		LOGGER.info("PriceDropImeis {}, priceDropId {}", priceDropIMEIsMap, priceDropId);
423
    }
423
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
424
 
424
		final HttpHeaders headers = new HttpHeaders();
425
    @RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
425
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
426
    public String updatePriceDropImeis(HttpServletRequest request, @RequestBody PriceDropImeisModel priceDropImeisModel,
426
		headers.set("Content-disposition",
427
                                       Model model) throws ProfitMandiBusinessException, Exception {
427
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
428
        PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
428
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
429
 
429
		ByteArrayOutputStream baos = null;
430
        switch (priceDropImeisModel.getUpdatedStatus()) {
430
		if (priceDropIMEIsMap.size() == 0) {
431
            case "approved": {
431
			priceDropService.priceDropStatus(priceDrop.getId());
432
                status = PriceDropImeiStatus.APPROVED;
432
			baos = FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
433
                break;
433
					"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
434
            }
434
					"Grn On", "Activation Timestamp", "Activation Added On"), new ArrayList<>());
435
            case "hold": {
435
		} else {
436
                status = PriceDropImeiStatus.HOLD;
436
 
437
                break;
437
			LOGGER.info("In else block");
438
            }
438
			baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
439
            case "rejected": {
439
					priceDropIMEIsMap);
440
                status = PriceDropImeiStatus.REJECTED;
440
		}
441
                break;
441
		byte[] byteArray = baos.toByteArray();
442
            }
442
		headers.setContentLength(byteArray.length);
443
        }
443
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
444
        PriceDropImeiStatus finalStatus = status;
444
 
445
 
445
	}
446
        if (PriceDropImeiStatus.PENDING.equals(status)) {
446
 
447
 
447
	@RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
448
            List<PriceDropIMEI> priceDropIMEIsToHolds = new ArrayList<>();
448
	public String updatePriceDropImeis(HttpServletRequest request, @RequestBody PriceDropImeisModel priceDropImeisModel,
449
            List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository.selectByIdAndStatus(PriceDropImeiStatus.HOLD,
449
									   Model model) throws ProfitMandiBusinessException, Exception {
450
                    priceDropImeisModel.getPriceDropId());
450
		PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
451
            LOGGER.info("hello" + priceDropIMEIs);
451
 
452
            for (PriceDropIMEI priceDropHoldIMEI : priceDropIMEIs) {
452
		switch (priceDropImeisModel.getUpdatedStatus()) {
453
                if (priceDropHoldIMEI.getStatus().equals(PriceDropImeiStatus.HOLD)) {
453
			case "approved": {
454
                    if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropHoldIMEI.getImei())
454
				status = PriceDropImeiStatus.APPROVED;
455
                            || priceDropHoldIMEI.getStatus().equals(status)) {
455
				break;
456
                        continue;
456
			}
457
                    }
457
			case "hold": {
458
                    priceDropIMEIsToHolds.add(priceDropHoldIMEI);
458
				status = PriceDropImeiStatus.HOLD;
459
                    priceDropHoldIMEI.setStatus(PriceDropImeiStatus.PENDING);
459
				break;
460
                    //priceDropHoldIMEI.setUpdateTimestamp(LocalDateTime.now());
460
			}
461
                } else {
461
			case "rejected": {
462
                    throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING",
462
				status = PriceDropImeiStatus.REJECTED;
463
                            "Pending Status is allowed  only for Hold IMIEs");
463
				break;
464
                }
464
			}
465
            }
465
		}
466
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
466
		PriceDropImeiStatus finalStatus = status;
467
            return "response";
467
 
468
        }
468
		if (PriceDropImeiStatus.PENDING.equals(status)) {
469
 
469
 
470
        // TODO:PD
470
			List<PriceDropIMEI> priceDropIMEIsToHolds = new ArrayList<>();
471
        List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
471
			List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository.selectByIdAndStatus(PriceDropImeiStatus.HOLD,
472
                .selectByPriceDropId(priceDropImeisModel.getPriceDropId());
472
					priceDropImeisModel.getPriceDropId());
473
 
473
			LOGGER.info("hello" + priceDropIMEIs);
474
        List<PriceDropIMEI> priceDropIMEIsToProcess = priceDropIMEIs.stream()
474
			for (PriceDropIMEI priceDropHoldIMEI : priceDropIMEIs) {
475
                .filter(x -> priceDropImeisModel.getUpdatedImeis().contains(x.getImei()))
475
				if (priceDropHoldIMEI.getStatus().equals(PriceDropImeiStatus.HOLD)) {
476
                .filter(x -> !x.getStatus().equals(finalStatus)).collect(Collectors.toList());
476
					if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropHoldIMEI.getImei())
-
 
477
							|| priceDropHoldIMEI.getStatus().equals(status)) {
-
 
478
						continue;
-
 
479
					}
-
 
480
					priceDropIMEIsToHolds.add(priceDropHoldIMEI);
-
 
481
					priceDropHoldIMEI.setStatus(PriceDropImeiStatus.PENDING);
-
 
482
					//priceDropHoldIMEI.setUpdateTimestamp(LocalDateTime.now());
-
 
483
				} else {
-
 
484
					throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING",
-
 
485
							"Pending Status is allowed  only for Hold IMIEs");
-
 
486
				}
-
 
487
			}
-
 
488
			model.addAttribute("response1", mvcResponseSender.createResponseString(true));
-
 
489
			return "response";
-
 
490
		}
-
 
491
 
-
 
492
		// TODO:PD
-
 
493
		List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
-
 
494
				.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
-
 
495
 
-
 
496
		List<PriceDropIMEI> priceDropIMEIsToProcess = priceDropIMEIs.stream()
-
 
497
				.filter(x -> priceDropImeisModel.getUpdatedImeis().contains(x.getImei()))
-
 
498
				.filter(x -> !x.getStatus().equals(finalStatus)).collect(Collectors.toList());
-
 
499
 
477
 
500
        /*for (PriceDropIMEI priceDropIMEI : priceDropIMEIsToProcess) {
478
        /*for (PriceDropIMEI priceDropIMEI : priceDropIMEIsToProcess) {
501
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
479
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
502
		}*/
480
		}*/
503
 
481
 
504
		if (status.equals(PriceDropImeiStatus.APPROVED)) {
482
        if (status.equals(PriceDropImeiStatus.APPROVED)) {
505
			priceDropService.processPriceDrop(priceDropImeisModel.getPriceDropId(),
483
            priceDropService.processPriceDrop(priceDropImeisModel.getPriceDropId(),
506
					priceDropImeisModel.getUpdatedImeis());
484
                    priceDropImeisModel.getUpdatedImeis());
507
		}
485
        }
508
		for (PriceDropIMEI priceDropImei : priceDropIMEIsToProcess) {
486
        for (PriceDropIMEI priceDropImei : priceDropIMEIsToProcess) {
509
			if (status.equals(PriceDropImeiStatus.REJECTED)
487
            if (status.equals(PriceDropImeiStatus.REJECTED)
510
					&& priceDropImei.getStatus().equals(PriceDropImeiStatus.PENDING)) {
488
                    && priceDropImei.getStatus().equals(PriceDropImeiStatus.PENDING)) {
511
				priceDropImei.setStatus(PriceDropImeiStatus.REJECTED);
489
                priceDropImei.setStatus(PriceDropImeiStatus.REJECTED);
512
				priceDropImei.setRejectionReason(priceDropImeisModel.getRejectionReason());
490
                priceDropImei.setRejectionReason(priceDropImeisModel.getRejectionReason());
513
				priceDropImei.setRejectTimestamp(LocalDateTime.now());
491
                priceDropImei.setRejectTimestamp(LocalDateTime.now());
514
			} else if (status.equals(PriceDropImeiStatus.HOLD)) {
492
            } else if (status.equals(PriceDropImeiStatus.HOLD)) {
515
				if (priceDropImei.getStatus().equals(PriceDropImeiStatus.PENDING)) {
493
                if (priceDropImei.getStatus().equals(PriceDropImeiStatus.PENDING)) {
516
					priceDropImei.setStatus(PriceDropImeiStatus.HOLD);
494
                    priceDropImei.setStatus(PriceDropImeiStatus.HOLD);
517
				} else {
495
                } else {
518
					throw new ProfitMandiBusinessException("INVALID STATUS", status, "only  allowed For PENDING IMEIs");
496
                    throw new ProfitMandiBusinessException("INVALID STATUS", status, "only  allowed For PENDING IMEIs");
519
				}
497
                }
520
 
498
 
521
			}
499
            }
522
 
500
 
523
		}
501
        }
524
 
502
 
525
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
503
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
526
		return "response";
504
        return "response";
527
 
505
 
528
	}
506
    }
529
 
507
 
530
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
508
    private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
531
														   Map<String, PriceDropIMEI> priceDropImeis) throws Exception {
509
                                                           Map<String, PriceDropIMEI> priceDropImeis) throws Exception {
532
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
510
        List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
533
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
511
                .getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
534
		List<List<?>> rows = new ArrayList<>();
512
        List<List<?>> rows = new ArrayList<>();
535
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
513
        for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
536
			if (priceDropImeis == null) {
514
            if (priceDropImeis == null) {
537
				rows.add(this.getRow(imeiDropSummaryModel, null));
515
                rows.add(this.getRow(imeiDropSummaryModel, null));
538
			} else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
516
            } else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
539
				rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
517
                rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
540
			}
518
            }
541
		}
519
        }
542
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
520
        return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
543
				"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
521
                "Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
544
				"Grn On", "Activation Timestamp", "Activation Added On"), rows);
522
                "Grn On", "Activation Timestamp", "Activation Added On"), rows);
545
	}
523
    }
546
 
524
 
547
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel,
525
    private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel,
548
												PriceDropIMEI priceDropIMEI) {
526
                                                PriceDropIMEI priceDropIMEI) {
549
		List<Serializable> row = new ArrayList<>();
527
        List<Serializable> row = new ArrayList<>();
550
		row.add(imeiDropSummaryModel.getSerialNumber());
528
        row.add(imeiDropSummaryModel.getSerialNumber());
551
		row.add(imeiDropSummaryModel.getStoreName());
529
        row.add(imeiDropSummaryModel.getStoreName());
552
		row.add(imeiDropSummaryModel.getPartnerCode());
530
        row.add(imeiDropSummaryModel.getPartnerCode());
553
		row.add(imeiDropSummaryModel.getItemId());
531
        row.add(imeiDropSummaryModel.getItemId());
554
		row.add(imeiDropSummaryModel.getBrand());
532
        row.add(imeiDropSummaryModel.getBrand());
555
		row.add(imeiDropSummaryModel.getModelName());
533
        row.add(imeiDropSummaryModel.getModelName());
556
		row.add(imeiDropSummaryModel.getModelNumber());
534
        row.add(imeiDropSummaryModel.getModelNumber());
557
		row.add(imeiDropSummaryModel.getColor());
535
        row.add(imeiDropSummaryModel.getColor());
558
		if (priceDropIMEI != null) {
536
        if (priceDropIMEI != null) {
559
			row.add(priceDropIMEI.getStatus());
537
            row.add(priceDropIMEI.getStatus());
560
			row.add(priceDropIMEI.getRejectionReason());
538
            row.add(priceDropIMEI.getRejectionReason());
561
		} else {
539
        } else {
562
			row.add(PriceDropImeiStatus.PENDING);
540
            row.add(PriceDropImeiStatus.PENDING);
563
			row.add("");
541
            row.add("");
564
		}
542
        }
565
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
543
        row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
566
		row.add(imeiDropSummaryModel.getVendorName());
544
        row.add(imeiDropSummaryModel.getVendorName());
567
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getGrnOn()));
545
        row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getGrnOn()));
568
		row.add(imeiDropSummaryModel.getActivationTimestamp());
546
        row.add(imeiDropSummaryModel.getActivationTimestamp());
569
		row.add(imeiDropSummaryModel.getActivationAddedOn());
547
        row.add(imeiDropSummaryModel.getActivationAddedOn());
570
		return row;
548
        return row;
571
	}
549
    }
572
 
550
 
573
	private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
551
    private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
574
		if (priceDropModel.getMop() > 0 && priceDropModel.getDp() > 0 && priceDropModel.getTp() > 0) {
552
        if (priceDropModel.getMop() > 0 && priceDropModel.getDp() > 0 && priceDropModel.getTp() > 0) {
575
			return true;
553
            return true;
576
		}
554
        }
577
		return false;
555
        return false;
578
	}
556
    }
579
 
557
 
580
	@RequestMapping(value = "/priceCircular")
558
    @RequestMapping(value = "/priceCircular")
581
	public String priceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
559
    public String priceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
582
		int fofoId = Utils.SYSTEM_PARTNER_ID;
560
        int fofoId = Utils.SYSTEM_PARTNER_ID;
583
		Set<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
561
        Set<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
584
				.collect(Collectors.toSet());
562
                .collect(Collectors.toSet());
585
		brands.addAll(mongoClient.getMongoBrands(fofoId, null, 6).stream().map(x -> (String) x.get("name"))
563
        brands.addAll(mongoClient.getMongoBrands(fofoId, null, 6).stream().map(x -> (String) x.get("name"))
586
				.collect(Collectors.toSet()));
564
                .collect(Collectors.toSet()));
587
 
565
 
588
		model.addAttribute("brands", brands);
566
        model.addAttribute("brands", brands);
589
		model.addAttribute("isAdmin", true);
567
        model.addAttribute("isAdmin", true);
590
		model.addAttribute("date", FormattingUtils.format(LocalDateTime.now()));
568
        model.addAttribute("date", FormattingUtils.format(LocalDateTime.now()));
591
 
569
 
592
		return "partner-price-circular";
570
        return "partner-price-circular";
593
	}
571
    }
594
 
572
 
595
	@RequestMapping(value = "/partnerPriceCircular")
573
    @RequestMapping(value = "/partnerPriceCircular")
596
	public String partnerPriceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
574
    public String partnerPriceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
597
		int fofoId = Utils.SYSTEM_PARTNER_ID;
575
        int fofoId = Utils.SYSTEM_PARTNER_ID;
598
		Set<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
576
        Set<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
599
				.collect(Collectors.toSet());
577
                .collect(Collectors.toSet());
600
		brands.addAll(mongoClient.getMongoBrands(fofoId, null, 6).stream().map(x -> (String) x.get("name"))
578
        brands.addAll(mongoClient.getMongoBrands(fofoId, null, 6).stream().map(x -> (String) x.get("name"))
601
				.collect(Collectors.toSet()));
579
                .collect(Collectors.toSet()));
602
		model.addAttribute("brands", brands);
580
        model.addAttribute("brands", brands);
603
		model.addAttribute("isAdmin", false);
581
        model.addAttribute("isAdmin", false);
604
 
582
 
605
		return "partner-price-circular";
583
        return "partner-price-circular";
606
	}
584
    }
607
 
585
 
608
	@Autowired
586
    @RequestMapping(value = "/priceCircularByBrand")
609
	PriceCircularService priceCircularService;
587
    public String priceCircularByBrand(HttpServletRequest request, @RequestParam String brand, Model model, @RequestParam(defaultValue = "0", required = false) int fofoId)
610
 
588
            throws ProfitMandiBusinessException {
611
	@RequestMapping(value = "/priceCircularByBrand")
589
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
612
	public String priceCircularByBrand(HttpServletRequest request, @RequestParam String brand, Model model, @RequestParam(defaultValue = "0", required = false) int fofoId)
590
        if (fofoId > 0 && roleManager.isAdmin(loginDetails.getRoleIds())) {
613
			throws ProfitMandiBusinessException {
591
        } else {
614
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
592
            fofoId = loginDetails.getFofoId();
615
		if (fofoId > 0 && roleManager.isAdmin(loginDetails.getRoleIds())) {
593
        }
616
		} else {
594
        //.minusDays(2)
617
			fofoId = loginDetails.getFofoId();
595
        PriceCircularModel priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, brand, LocalDate.now());
618
		}
596
        //List<Integer> catalogIds = priceCircular.getPriceCircularItemModelNews().stream().limit(100).map(x->x.getCatalogId()).collect(Collectors.toList());
619
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
597
        //priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
620
		List<PartnerType> partnerTypes = new ArrayList<>();
598
        List<String> schemeHeaders = new ArrayList<>(this.getSchemeHeaders(priceCircular));
621
		partnerTypes.add(partnerType);
599
        List<String> allMargins = ALL_MARGINS.stream().filter(x -> schemeHeaders.contains(x)).collect(Collectors.toList());
622
		partnerTypes.add(PartnerType.ALL);
600
        List<String> sellins = SELLINS.stream().filter(x -> allMargins.contains(x)).collect(Collectors.toList());
623
		PriceCircularModel priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, brand);
601
        List<String> sellouts = SELLOUTS.stream().filter(x -> allMargins.contains(x)).collect(Collectors.toList());
624
		PriceCircularItemModel summaryModel = this.getSummaryModel(priceCircular);
602
        LOGGER.info("Scheme Headers = {}", schemeHeaders);
625
		List<String> allMargins = ALL_MARGINS.stream().filter(payoutType -> summaryModel.getByPayoutType(payoutType) > 0).collect(Collectors.toList());
603
        LOGGER.info("allMargins {}", allMargins);
626
		List<String> sellins = SELLINS.stream().filter(x -> allMargins.contains(x)).collect(Collectors.toList());
604
        LOGGER.info("Sellins - {}", sellins);
627
		List<String> sellouts = SELLOUTS.stream().filter(x -> allMargins.contains(x)).collect(Collectors.toList());
605
        LOGGER.info("Sellouts - {}", sellouts);
628
		LOGGER.info("All margins - {}", allMargins);
606
        FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
629
		LOGGER.info("Sellins - {}", sellins);
607
        model.addAttribute("priceCircularItemModels", priceCircular.getPriceCircularItemModelNews());
630
		LOGGER.info("Sellouts - {}", sellouts);
608
        model.addAttribute("allMargins", allMargins);
631
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
609
        model.addAttribute("sellins", sellins);
632
		model.addAttribute("priceCircular", priceCircular.getPriceCircularItemModels());
610
        model.addAttribute("sellouts", sellouts);
633
		model.addAttribute("allMargins", allMargins);
611
        model.addAttribute("offers", priceCircular.getOffers());
634
		model.addAttribute("sellins", sellins);
612
        model.addAttribute("upgradeOffer", priceCircular.isUpgradeOffer());
635
		model.addAttribute("sellouts", sellouts);
613
        model.addAttribute("partnerCode", fs.getCode());
636
		model.addAttribute("offers", priceCircular.getOffers());
614
        model.addAttribute("mvcResponseSender", mvcResponseSender);
637
		model.addAttribute("upgradeOffer", priceCircular.isUpgradeOffer());
615
        return "price-circular-detail";
638
		model.addAttribute("partnerCode", fs.getCode());
616
    }
639
		return "price-circular-detail";
617
 
640
	}
618
    private Set<String> getSchemeHeaders(PriceCircularModel priceCircular) {
641
 
619
        Set<String> schemeHeaders = new HashSet<>();
642
	//private static final List<String> SELLINS = Arrays.asList("Base Payout", "Cash Discount", "Upfront Margin");
620
        priceCircular.getPriceCircularItemModelNews().stream().forEach(priceCircularItemModelNew -> {
643
	//private static final List<String> SELLOUTS = Arrays.asList("Tertiary Payout", "Hygiene Payout", "Investment Payout", "Category Payout", "Activation Margin", "Special Support");
621
            Map<String, AmountModel> headerMap = new HashMap<>();
644
	private PriceCircularItemModel getSummaryModel(PriceCircularModel priceCircular) {
622
            priceCircularItemModelNew.setHeaderSchemeModelsMap(headerMap);
645
 
623
            priceCircularItemModelNew.getSchemeSummaryModels().stream().forEach(schemeSummaryModel -> {
646
		PriceCircularItemModel summaryModel = new PriceCircularItemModel();
624
                if (schemeSummaryModel == null) return;
647
		priceCircular.getPriceCircularItemModels().stream().forEach(x -> {
625
                if (schemeSummaryModel.getSchemeType().equals(SchemeType.SPECIAL_SUPPORT) || schemeSummaryModel.getSchemeType().equals(SchemeType.ACTIVATION)) {
648
			if (summaryModel.getBasePayout() == 0 && x.getBasePayout() > 0) {
626
                    schemeSummaryModel.setHeader("Special Support");
649
				summaryModel.setBasePayout(1);
627
                } else if (schemeSummaryModel.getDescription().equalsIgnoreCase("modelwise") && schemeSummaryModel.getSchemeType().equals(SchemeType.IN)) {
650
			}
628
                    schemeSummaryModel.setHeader("Modelwise");
651
			if (summaryModel.getCashDiscount() == 0 && x.getCashDiscount() > 0) {
629
                } else {
652
				summaryModel.setCashDiscount(1);
630
                    schemeSummaryModel.setHeader(schemeSummaryModel.getDescription());
653
			}
631
                }
654
			if (summaryModel.getSpecialSupport() == 0 && x.getSpecialSupport() > 0) {
632
                if (!headerMap.containsKey(schemeSummaryModel.getHeader())) {
655
				summaryModel.setSpecialSupport(1);
633
                    headerMap.put(schemeSummaryModel.getHeader(), new AmountModel(schemeSummaryModel.getAmount(), schemeSummaryModel.getAmountType()));
656
			}
634
                } else {
657
			if (summaryModel.getCategoryPayout() == 0 && x.getCategoryPayout() > 0) {
635
                    AmountModel model = headerMap.get(schemeSummaryModel.getHeader());
658
				summaryModel.setCategoryPayout(1);
636
                    model.setAmount(model.getAmount() + schemeSummaryModel.getAmount());
659
			}
637
                }
660
			if (summaryModel.getTertiaryPayout() == 0 && x.getTertiaryPayout() > 0) {
638
                schemeHeaders.add(schemeSummaryModel.getHeader());
661
				summaryModel.setTertiaryPayout(1);
639
            });
662
			}
640
        });
663
			if (summaryModel.getModelSpecfic() == 0 && x.getModelSpecfic() > 0) {
641
 
664
				summaryModel.setModelSpecfic(1);
642
        LOGGER.info("Scheme headers - {}", schemeHeaders);
665
			}
643
        return schemeHeaders;
666
			if (summaryModel.getUpfrontMargin() == 0 && x.getUpfrontMargin() > 0) {
644
    }
667
				summaryModel.setUpfrontMargin(1);
645
 
668
			}
646
    //private static final List<String> SELLINS = Arrays.asList("Base Payout", "Cash Discount", "Upfront Margin");
669
			if (summaryModel.getHygienePayout() == 0 && x.getHygienePayout() > 0) {
647
    //private static final List<String> SELLOUTS = Arrays.asList("Tertiary Payout", "Hygiene Payout", "Investment Payout", "Category Payout", "Activation Margin", "Special Support");
670
				summaryModel.setHygienePayout(1);
648
 
671
			}
649
 
672
			if (summaryModel.getInvestmentPayout() == 0 && x.getInvestmentPayout() > 0) {
650
    @RequestMapping(value = "/downloadNlcByBrand")
673
				summaryModel.setInvestmentPayout(1);
651
    public ResponseEntity<ByteArrayResource> downloadNlcByBrand(HttpServletRequest request,
674
			}
652
                                                                @RequestParam String brand, Model model, @RequestParam(defaultValue = "0", required = false) int fofoId) throws Exception {
675
			if (summaryModel.getModelWise() == 0 && x.getModelWise() > 0) {
653
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
676
				summaryModel.setModelWise(1);
654
        if (fofoId > 0 && roleManager.isAdmin(loginDetails.getRoleIds())) {
677
			}
655
        } else {
678
		});
656
            fofoId = loginDetails.getFofoId();
679
 
657
        }
680
		LOGGER.info("Summary Model {}", summaryModel);
658
        PriceCircularModel priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, brand, LocalDate.now());
681
 
659
        /*List<Integer> catalogIds = priceCircular.getPriceCircularItemModelNews().stream().limit(10).map(x->x.getCatalogId()).collect(Collectors.toList());
682
		return summaryModel;
660
        priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());*/
683
	}
661
        ByteArrayOutputStream baos = getNlcBaos(brand, priceCircular);
684
 
662
        final HttpHeaders headers = new HttpHeaders();
685
 
663
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
686
	@RequestMapping(value = "/downloadNlcByBrand")
664
        headers.set("Content-disposition", "inline; filename=\"" + brand + ".csv\"");
687
	public ResponseEntity<ByteArrayResource> downloadNlcByBrand(HttpServletRequest request,
665
        byte[] byteArray = baos.toByteArray();
688
																@RequestParam String brand, Model model, @RequestParam(defaultValue = "0", required = false) int fofoId) throws Exception {
666
        headers.setContentLength(byteArray.length);
689
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
667
        return new ResponseEntity<>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
690
		if (fofoId > 0 && roleManager.isAdmin(loginDetails.getRoleIds())) {
668
    }
691
		} else {
669
 
692
			fofoId = loginDetails.getFofoId();
670
    private ByteArrayOutputStream getNlcBaos(String brand, PriceCircularModel priceCircular) throws Exception {
693
		}
671
        List<List<?>> rows = new ArrayList<>();
694
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
672
        for (PriceCircularItemModelNew priceCircularItemModel : priceCircular.getPriceCircularItemModelNews()) {
695
		List<PartnerType> partnerTypes = new ArrayList<>();
673
            List<Serializable> row = new ArrayList<>();
696
		partnerTypes.add(partnerType);
674
            row.add(priceCircularItemModel.getCatalogId());
697
		partnerTypes.add(PartnerType.ALL);
675
            row.add(brand);
698
		PriceCircularModel priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, brand);
676
            row.add(priceCircularItemModel.getCatalogSummaryModel().getModelName());
699
		ByteArrayOutputStream baos = getNlcBaos(brand, priceCircular);
677
            row.add(priceCircularItemModel.getCatalogSummaryModel().getModelNumber());
700
		final HttpHeaders headers = new HttpHeaders();
678
            //TODO: fix nlc
701
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
679
            //row.add(priceCircularItemModel.getNetPrice());
702
		headers.set("Content-disposition", "inline; filename=\"" + brand + ".csv\"");
680
            rows.add(row);
703
		byte[] byteArray = baos.toByteArray();
681
        }
704
		headers.setContentLength(byteArray.length);
682
        return FileUtil.getCSVByteStream(Arrays.asList("Model Id", "Brand", "Model Name", "Model Number", "Partner Landing"), rows);
705
		return new ResponseEntity<>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
683
    }
706
	}
684
 
707
 
685
    @RequestMapping(value = "/selectPriceDropStatus", method = RequestMethod.GET)
708
	private ByteArrayOutputStream getNlcBaos(String brand, PriceCircularModel priceCircular) throws Exception {
686
    public String selectPriceDropStatus(HttpServletRequest request,
709
		List<List<?>> rows = new ArrayList<>();
687
                                        @RequestParam(name = "selectedStatus", required = true, defaultValue = "") String selectedStatus,
710
		for (PriceCircularItemModel priceCircularItemModel : priceCircular.getPriceCircularItemModels()) {
688
                                        Model model) throws Exception {
711
			List<Serializable> row = new ArrayList<>();
689
 
712
			row.add(priceCircularItemModel.getCatalogId());
690
        model.addAttribute("selectedStatus", selectedStatus);
713
			row.add(brand);
691
        return "pricedrop-status-change";
714
			row.add(priceCircularItemModel.getModelName());
692
    }
715
			row.add(priceCircularItemModel.getModelNumber());
-
 
716
			row.add(priceCircularItemModel.getNetPrice());
-
 
717
			rows.add(row);
-
 
718
		}
-
 
719
		return FileUtil.getCSVByteStream(Arrays.asList("Model Id", "Brand", "Model Name", "Model Number", "Partner Landing"), rows);
-
 
720
	}
-
 
721
 
-
 
722
	@RequestMapping(value = "/selectPriceDropStatus", method = RequestMethod.GET)
-
 
723
	public String selectPriceDropStatus(HttpServletRequest request,
-
 
724
										@RequestParam(name = "selectedStatus", required = true, defaultValue = "") String selectedStatus,
-
 
725
										Model model) throws Exception {
-
 
726
 
-
 
727
		model.addAttribute("selectedStatus", selectedStatus);
-
 
728
		return "pricedrop-status-change";
-
 
729
	}
-
 
730
 
693
 
731
}
694
}