Subversion Repositories SmartDukaan

Rev

Rev 37564 | 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
 
23945 amit.gupta 3
import com.fasterxml.jackson.databind.ObjectMapper;
29926 amit.gupta 4
import com.spice.profitmandi.common.enumuration.MessageType;
23819 govind 5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
29926 amit.gupta 6
import com.spice.profitmandi.common.model.*;
23945 amit.gupta 7
import com.spice.profitmandi.common.services.ReporticoService;
23951 amit.gupta 8
import com.spice.profitmandi.common.util.FileUtil;
23945 amit.gupta 9
import com.spice.profitmandi.common.util.FormattingUtils;
28102 tejbeer 10
import com.spice.profitmandi.common.util.Utils;
23819 govind 11
import com.spice.profitmandi.dao.entity.catalog.Item;
23884 amit.gupta 12
import com.spice.profitmandi.dao.entity.catalog.TagListing;
32905 shampa 13
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
24822 amit.gupta 14
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
23884 amit.gupta 15
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
23819 govind 16
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
24083 amit.gupta 17
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
31903 amit.gupta 18
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
24083 amit.gupta 19
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
31903 amit.gupta 20
import com.spice.profitmandi.dao.model.AmountModel;
23819 govind 21
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23884 amit.gupta 22
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
35547 amit 23
import com.spice.profitmandi.dao.event.TagListingEventPublisher;
29926 amit.gupta 24
import com.spice.profitmandi.dao.repository.cs.CsService;
28136 tejbeer 25
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
28102 tejbeer 26
import com.spice.profitmandi.dao.repository.dtr.Mongo;
29926 amit.gupta 27
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
28102 tejbeer 28
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
24822 amit.gupta 29
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
23884 amit.gupta 30
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
23983 amit.gupta 31
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
24083 amit.gupta 32
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
23819 govind 33
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
29926 amit.gupta 34
import com.spice.profitmandi.service.NotificationService;
29951 amit.gupta 35
import com.spice.profitmandi.service.authentication.RoleManager;
32844 shampa 36
import com.spice.profitmandi.service.catalog.BrandsService;
23819 govind 37
import com.spice.profitmandi.service.inventory.InventoryService;
37623 amit 38
import com.spice.profitmandi.service.inventory.VendorCatalogPricingService;
39
import com.spice.profitmandi.dao.entity.auth.AuthUser;
40
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
34651 aman.kumar 41
import com.spice.profitmandi.service.order.OrderService;
31903 amit.gupta 42
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModelNew;
29788 amit.gupta 43
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
44
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
23983 amit.gupta 45
import com.spice.profitmandi.service.pricing.PriceDropService;
37000 amit 46
import com.spice.profitmandi.service.pricing.PriceHikeService;
23968 amit.gupta 47
import com.spice.profitmandi.service.scheme.SchemeService;
23884 amit.gupta 48
import com.spice.profitmandi.service.transaction.TransactionService;
28102 tejbeer 49
import com.spice.profitmandi.service.user.RetailerService;
23819 govind 50
import com.spice.profitmandi.service.wallet.WalletService;
28102 tejbeer 51
import com.spice.profitmandi.web.model.LoginDetails;
52
import com.spice.profitmandi.web.util.CookiesProcessor;
23819 govind 53
import com.spice.profitmandi.web.util.MVCResponseSender;
29926 amit.gupta 54
import org.apache.commons.io.output.ByteArrayOutputStream;
55
import org.apache.logging.log4j.LogManager;
56
import org.apache.logging.log4j.Logger;
57
import org.springframework.beans.factory.annotation.Autowired;
58
import org.springframework.beans.factory.annotation.Qualifier;
59
import org.springframework.core.io.ByteArrayResource;
60
import org.springframework.http.HttpHeaders;
61
import org.springframework.http.HttpStatus;
62
import org.springframework.http.ResponseEntity;
63
import org.springframework.stereotype.Controller;
64
import org.springframework.transaction.annotation.Transactional;
65
import org.springframework.ui.Model;
66
import org.springframework.web.bind.annotation.*;
23819 govind 67
 
29926 amit.gupta 68
import javax.servlet.http.HttpServletRequest;
69
import java.io.Serializable;
70
import java.time.LocalDate;
71
import java.time.LocalDateTime;
72
import java.util.*;
73
import java.util.stream.Collectors;
74
 
23819 govind 75
@Controller
27071 amit.gupta 76
@Transactional(rollbackFor = Throwable.class)
23819 govind 77
public class PriceDropController {
78
 
31903 amit.gupta 79
    private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
34317 amit.gupta 80
    /*private static final List<String> SELLINS = Arrays.asList("Base Payout", "Cash Discount", "Upfront Margin", "Modelwise");
31910 amit.gupta 81
    private static final List<String> SELLOUTS = Arrays.asList("Tertiary Payout", "Hygiene Payout", "Investment Payout", "Category Payout", "Activation Margin", "Special Support", "Sellout Support");
34317 amit.gupta 82
    private static final List<String> ALL_MARGINS = Arrays.asList(SELLINS, SELLOUTS).stream().flatMap(x -> x.stream()).collect(Collectors.toList());*/
31903 amit.gupta 83
    @Autowired
84
    ReporticoService reporticoService;
85
    @Autowired
86
    LineItemImeisRepository lineItemImeisRepository;
87
    @Autowired
88
    PriceCircularService priceCircularService;
89
    @Autowired
90
    private CsService csService;
91
    @Autowired
92
    private UserRepository dtrUserRepository;
93
    @Autowired
94
    private PriceDropRepository priceDropRepository;
95
    @Autowired
96
    private ObjectMapper objectMapper;
97
    @Autowired
98
    private VendorItemPricingRepository vendorItemPricingRepository;
99
    @Autowired
37623 amit 100
    private VendorCatalogPricingService vendorCatalogPricingService;
101
    @Autowired
102
    private AuthRepository authRepository;
103
    @Autowired
31903 amit.gupta 104
    @Qualifier("fofoInventoryService")
105
    private InventoryService inventoryService;
106
    @Autowired
107
    private MVCResponseSender mvcResponseSender;
108
    @Autowired
109
    private PriceDropService priceDropService;
110
    @Autowired
37000 amit 111
    private PriceHikeService priceHikeService;
112
    @Autowired
31903 amit.gupta 113
    private ItemPricingHistoryRepository itemPricingHistoryRepository;
114
    @Autowired
115
    private WalletService walletService;
116
    @Autowired
117
    private TagListingRepository tagListingRepository;
118
    @Autowired
119
    private TransactionService transactionService;
120
    @Autowired
121
    private PriceDropIMEIRepository priceDropIMEIRepository;
122
    @Autowired
123
    private RoleManager roleManager;
124
    @Autowired
125
    @Qualifier("catalogItemRepository")
126
    private ItemRepository itemRepository;
127
    @Autowired
128
    private SchemeService schemeService;
129
    @Autowired
130
    private Mongo mongoClient;
131
    @Autowired
132
    private CookiesProcessor cookiesProcessor;
133
    @Autowired
134
    private PartnerTypeChangeService partnerTypeChangeService;
135
    @Autowired
136
    private RetailerService retailerService;
137
    @Autowired
138
    private NotificationService notificationService;
139
    @Autowired
140
    private FofoStoreRepository fofoStoreRepository;
23819 govind 141
 
34651 aman.kumar 142
    @Autowired
143
    OrderService orderService;
144
 
35547 amit 145
    @Autowired
146
    private TagListingEventPublisher tagListingEventPublisher;
147
 
31903 amit.gupta 148
    @RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
149
    public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
150
        List<PriceDrop> priceDrops = priceDropRepository.selectAllIncomplete();
151
        Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
29926 amit.gupta 152
 
31903 amit.gupta 153
        List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
154
        Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
155
                x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
156
        model.addAttribute("priceDrops", priceDrops);
157
        model.addAttribute("catalogDescription", catalogDescription);
158
        return "price-drop";
159
    }
29926 amit.gupta 160
 
34651 aman.kumar 161
    @RequestMapping(value = "/getPricedropByDate", method = RequestMethod.GET)
162
    public String getItemDescriptionByDate(
163
            HttpServletRequest request,
164
            @RequestParam LocalDateTime startDate,
165
            @RequestParam LocalDateTime endDate,
166
            Model model) throws Throwable {
34657 aman.kumar 167
        if (endDate.isAfter(LocalDateTime.now().plusDays(1)) || startDate.isAfter(LocalDateTime.now().plusDays(1))) {
34651 aman.kumar 168
            throw new ProfitMandiBusinessException("startData and end data must if before the today date ", "", "");
169
        }
170
        try {
171
            List<PriceDrop> priceDrops = priceDropRepository.selectAllByDatesBetweenSortByDate(startDate, endDate);
172
 
173
            Set<Integer> catalogIds = priceDrops.stream()
174
                    .map(PriceDrop::getCatalogItemId)
175
                    .collect(Collectors.toSet());
176
 
177
            List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
178
            Map<Integer, String> catalogDescription = items.stream()
179
                    .collect(Collectors.toMap(
180
                            Item::getCatalogItemId,
181
                            Item::getItemDescriptionNoColor,
182
                            (description1, description2) -> description1));
183
 
184
            model.addAttribute("priceDrops", priceDrops);
185
            model.addAttribute("catalogDescription", catalogDescription);
186
 
187
            return "price-drop-table";
188
 
189
        } catch (Exception e) {
190
            e.printStackTrace();
191
            return "price-drop";
192
        }
193
    }
194
    @RequestMapping(value = "/pricedropByDate/download", method = RequestMethod.GET)
195
    public ResponseEntity<?> dowloadItems(HttpServletRequest request, @PathVariable(name = "tagId") @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate)
196
            throws Throwable {
197
        List<PriceDrop> priceDrops = priceDropRepository.selectAllByDatesBetweenSortByDate(startDate, endDate);
198
        Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
199
        List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
200
        Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
201
                x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
202
 
203
        List<List<?>> rows = new ArrayList<>();
204
        for (PriceDrop priceDrop : priceDrops) {
34720 aman.kumar 205
            rows.add(Arrays.asList(priceDrop.getId(), priceDrop.getCatalogItemId(), catalogDescription.get(priceDrop.getCatalogItemId()), priceDrop.getTp(), priceDrop.getOldDp(), priceDrop.getMop(),
34657 aman.kumar 206
                    priceDrop.getAmount(), priceDrop.getNewDp(), FormattingUtils.formatDate(priceDrop.getAffectedOn()), FormattingUtils.formatDate(priceDrop.getCreatedOn())
34651 aman.kumar 207
            ));
208
 
209
        }
210
        org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
34720 aman.kumar 211
                Arrays.asList("Drop Id", "Catalog Id", "Item Name", "TP", "DP", "Mop", "Price Drop",
34651 aman.kumar 212
                        "New DP", "Affected On", "Created On"),
213
                rows);
214
        ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Price Drop ");
215
        return responseEntity;
216
    }
217
 
31903 amit.gupta 218
    @RequestMapping(value = "/getClosedPricedropItemDescription", method = RequestMethod.GET)
219
    public String getClosedPricedropItemDescription(HttpServletRequest request, Model model) throws Throwable {
220
        List<PriceDrop> priceDrops = priceDropRepository.selectAllComplete();
221
        int processOn = 1;
23819 govind 222
 
31903 amit.gupta 223
        List<PriceDrop> completePriceDrops = priceDrops.stream().filter(x -> x.getCompleteTimestamp() != null)
224
                .collect(Collectors.toList());
23945 amit.gupta 225
 
31903 amit.gupta 226
        Set<Integer> catalogIds = completePriceDrops.stream().map(x -> x.getCatalogItemId())
227
                .collect(Collectors.toSet());
228
        List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
229
        LOGGER.info("catalogIds" + catalogIds);
23819 govind 230
 
31903 amit.gupta 231
        Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
232
                x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
233
        model.addAttribute("priceDrops", completePriceDrops);
234
        model.addAttribute("processOn", processOn);
235
        model.addAttribute("catalogDescription", catalogDescription);
236
        return "price-drop";
237
    }
23945 amit.gupta 238
 
31903 amit.gupta 239
    @RequestMapping(value = "/item-pricing/{itemId}", method = RequestMethod.GET)
240
    public String getItemPricing(HttpServletRequest request, Model model, @PathVariable int itemId) throws Throwable {
23819 govind 241
 
31903 amit.gupta 242
        TagListing tagListing;
243
        PriceDropModel pm = new PriceDropModel();
244
        try {
245
            tagListing = tagListingRepository.selectByItemId(itemId);
246
            if (tagListing != null) {
247
                pm.setMop(tagListing.getMop());
248
                pm.setDp(tagListing.getSellingPrice());
249
                pm.setMrp(tagListing.getMrp());
250
                List<VendorItemPricing> vips = vendorItemPricingRepository.selectAll(itemId);
251
                if (vips.size() > 0) {
252
                    VendorItemPricing vip = vips.get(0);
253
                    pm.setNlc(vip.getNlc());
254
                    pm.setTp(vip.getTp());
255
                } else {
256
                    throw new ProfitMandiBusinessException("Item Id", itemId, "Vendor item pricing does not exist");
257
                }
258
            }
259
        } catch (Exception e) {
260
            LOGGER.info("Chose item that doesn't exist");
261
        }
262
        model.addAttribute("response1", mvcResponseSender.createResponseString(pm));
263
        return "response";
264
    }
27071 amit.gupta 265
 
37564 amit 266
    /**
267
     * Shared partner item typeahead. Feeds price drop, warehouse purchase (PO),
268
     * catalog-item, combo and prebooking.
269
     *
270
     * <p>{@code activeOnly} selects the basis: false (default) is the historical
271
     * whole-catalogue list, kept for screens that inspect or edit existing
272
     * records; true restricts to items with a live tag_listing, which is what
273
     * creation screens send so a delisted SKU cannot be picked.
274
     */
31903 amit.gupta 275
    @RequestMapping(value = "/item", method = RequestMethod.GET)
276
    public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query,
37564 amit 277
                                 @RequestParam boolean anyColor,
278
                                 @RequestParam(required = false, defaultValue = "false") boolean activeOnly)
279
            throws Throwable {
31903 amit.gupta 280
        String query1 = query.toLowerCase();
24083 amit.gupta 281
 
31903 amit.gupta 282
        List<ItemDescriptionModel> partnersItemDescription = inventoryService
37564 amit 283
                .getAllPartnerItemStringDescription(anyColor, activeOnly).parallelStream()
31903 amit.gupta 284
                .filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
285
                .collect(Collectors.toList());
286
        LOGGER.info("partnersItemDescription" + partnersItemDescription);
23819 govind 287
 
31903 amit.gupta 288
        model.addAttribute("response1", mvcResponseSender.createResponseString(partnersItemDescription));
289
        return "response";
290
    }
23945 amit.gupta 291
 
31903 amit.gupta 292
    @RequestMapping(value = "/price-drop/imes/download")
293
    public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
294
                                                                    @RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
295
        Item item = itemRepository.selectById(itemId);
33198 amit.gupta 296
        ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null, Optional.empty());
31903 amit.gupta 297
        final HttpHeaders headers = new HttpHeaders();
298
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
299
        headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
300
        byte[] byteArray = baos.toByteArray();
301
        headers.setContentLength(byteArray.length);
302
        return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
303
    }
23819 govind 304
 
31903 amit.gupta 305
    @RequestMapping(value = "/price-drop/addPayout", method = RequestMethod.POST)
306
    public String updatePriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
307
                                  Model model) throws Exception {
308
        boolean response = false;
309
        PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
310
        if (priceDrop.getProcessTimestamp() == null) {
311
            priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
312
            priceDrop.setPriceDropIn(priceDropProcessModel.getPriceDropIn());
313
            // priceDrop.setProcessTimestamp(LocalDateTime.now());
314
            priceDropRepository.persist(priceDrop);
315
            response = true;
316
        }
317
        model.addAttribute("response1", mvcResponseSender.createResponseString(response));
318
        return "response";
319
    }
24083 amit.gupta 320
 
31903 amit.gupta 321
    @RequestMapping(value = "/priceDropImeis/{priceDropId}", method = RequestMethod.GET)
322
    public String priceDropStatus(HttpServletRequest request, @PathVariable int priceDropId, Model model)
323
            throws Exception {
29951 amit.gupta 324
 
31903 amit.gupta 325
        PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
23819 govind 326
 
31903 amit.gupta 327
        // This call is used to persit imeis to pricedrop imeis in case its not there.
328
        // This should be called while creating price drop.
329
        // priceDropService.priceDropStatus(priceDropId);
24083 amit.gupta 330
 
31903 amit.gupta 331
        List<String> pendingImeis = new ArrayList<>();
332
        List<String> approvedImeis = new ArrayList<>();
333
        List<String> rejectedImeis = new ArrayList<>();
334
        List<String> holdImeis = new ArrayList<>();
335
        List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
336
        for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
337
            if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.PENDING)) {
338
                pendingImeis.add(priceDropIMEI.getImei());
339
            } else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)) {
340
                approvedImeis.add(priceDropIMEI.getImei());
341
            }
342
            if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.REJECTED)) {
343
                rejectedImeis.add(priceDropIMEI.getImei());
344
            } else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.HOLD)) {
345
                holdImeis.add(priceDropIMEI.getImei());
24083 amit.gupta 346
 
31903 amit.gupta 347
            }
348
        }
349
        LOGGER.info("pendingImeis" + pendingImeis);
350
        LOGGER.info("approvedImeis" + approvedImeis);
351
        LOGGER.info("rejectedImeis" + rejectedImeis);
352
        LOGGER.info("priceDropImeis" + priceDropImeis);
23945 amit.gupta 353
 
31903 amit.gupta 354
        priceDropImeisModel.setPendingImeis(pendingImeis);
355
        priceDropImeisModel.setPriceDropId(priceDropId);
356
        priceDropImeisModel.setApprovedImeis(approvedImeis);
357
        priceDropImeisModel.setHoldImeis(holdImeis);
358
        priceDropImeisModel.setRejectedImeis(rejectedImeis);
359
        model.addAttribute("response1", mvcResponseSender.createResponseString(priceDropImeisModel));
360
        return "response";
361
    }
28102 tejbeer 362
 
31903 amit.gupta 363
    @RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
364
    public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
365
                                   Model model) throws Exception {
366
        PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
367
        boolean response = false;
368
        if (priceDrop.getPartnerPayout() == 0) {
369
            priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
370
        }
371
        priceDrop.setProcessTimestamp(LocalDateTime.now());
372
        priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
373
        response = true;
374
        model.addAttribute("response1", mvcResponseSender.createResponseString(response));
375
        return "response";
376
    }
28102 tejbeer 377
 
37000 amit 378
    // On-demand price-hike deduction for a whole hike: figures out billed partners/IMEIs, then
379
    // debits each partner in the background (one transaction per retailer). Idempotent — re-calling
380
    // skips units already recovered (incl. those already handled by the GRN hook).
381
    @RequestMapping(value = "/priceHike/process/{priceDropId}", method = RequestMethod.GET)
382
    public String processPriceHike(HttpServletRequest request, @PathVariable int priceDropId, Model model)
36983 amit 383
            throws Exception {
37000 amit 384
        priceHikeService.triggerHikeDeduction(priceDropId);
385
        model.addAttribute("response1",
386
                mvcResponseSender.createResponseString("Price hike deduction started for priceDropId " + priceDropId));
36983 amit 387
        return "response";
388
    }
389
 
31903 amit.gupta 390
    @RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
391
    public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
392
            throws Exception {
393
        boolean response = false;
394
        priceDropModel.setAllColors(true);
395
        if (this.validatePriceDrop(priceDropModel)) {
396
            TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
397
            float oldDp = tagListing.getSellingPrice();
398
            float oldMop = tagListing.getMop();
399
            float oldTp = 0;
400
            float newDp = priceDropModel.getDp();
28102 tejbeer 401
 
31903 amit.gupta 402
            if (newDp != oldDp) {
403
                List<Item> allItems = null;
404
                Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
405
                if (priceDropModel.isAllColors()) {
406
                    allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
28102 tejbeer 407
 
31903 amit.gupta 408
                } else {
409
                    allItems = Arrays.asList(currentItem);
410
                }
411
                for (Item item : allItems) {
412
                    TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
413
                    if (itemTagListing == null)
414
                        continue;
415
                    itemTagListing.setSellingPrice(newDp);
416
                    itemTagListing.setMop(priceDropModel.getMop());
417
                    List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
418
                    for (VendorItemPricing vip : vipList) {
419
                        oldTp = vip.getNlc();
420
                        vip.setDp(newDp);
421
                        vip.setMop(priceDropModel.getMop());
422
                        //Lets not update NLC/TP as it has to be managed by Category Tea,
423
                        //vip.setNlc(priceDropModel.getTp());
424
                        //vip.setTp(priceDropModel.getTp());
425
                        vendorItemPricingRepository.persist(vip);
426
                    }
427
                    transactionService.updatePriceDrop(item.getId(), newDp);
428
                }
29926 amit.gupta 429
 
31903 amit.gupta 430
                // Add to itemPricing history
431
                ItemPricingHistory iph = new ItemPricingHistory();
432
                iph.setCatalogId(currentItem.getCatalogItemId());
433
                iph.setTp(priceDropModel.getTp());
434
                iph.setDp(priceDropModel.getDp());
435
                iph.setMop(priceDropModel.getMop());
436
                // TODO: changedBy
437
                iph.setChangedBy("me");
438
                iph.setCreateTimestamp(LocalDateTime.now());
439
                itemPricingHistoryRepository.persist(iph);
28136 tejbeer 440
 
37623 amit 441
                LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
442
                AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
443
                LocalDate effectedOn = priceDropModel.getAffectedDate() == null ? LocalDate.now() : priceDropModel.getAffectedDate().toLocalDate();
444
                vendorCatalogPricingService.applyPriceDrop(currentItem.getCatalogItemId(), newDp, priceDropModel.getMop(), effectedOn, authUser.getId());
445
 
31903 amit.gupta 446
                PriceDrop priceDrop = new PriceDrop();
447
                priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
448
                priceDrop.setTp(oldTp);
449
                priceDrop.setNlc(oldTp);
450
                priceDrop.setMop(oldMop);
451
                priceDrop.setOldDp(oldDp);
452
                priceDrop.setAmount(oldDp - newDp);
453
                priceDrop.setNewDp(newDp);
454
                priceDrop.setCreatedOn(LocalDateTime.now());
455
                priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
456
                priceDropRepository.persist(priceDrop);
457
                priceDropService.priceDropStatus(priceDrop.getId());
458
                response = true;
30471 amit.gupta 459
 
31903 amit.gupta 460
                this.sendPriceChangeNotification(priceDrop);
35547 amit 461
 
462
                // Publish event for real-time Solr update
463
                try {
464
                    tagListingEventPublisher.publishPriceChange(0, currentItem.getCatalogItemId());
465
                } catch (Exception e) {
466
                    LOGGER.error("Failed to publish price change event for catalogId: {}", currentItem.getCatalogItemId(), e);
467
                }
31903 amit.gupta 468
            } else {
469
                throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
470
                        "Price Drop Should be greater than 0");
471
            }
472
        }
473
        model.addAttribute("response1", mvcResponseSender.createResponseString(response));
474
        return "response";
475
    }
29654 tejbeer 476
 
31903 amit.gupta 477
    private void sendPriceChangeNotification(PriceDrop priceDrop) throws ProfitMandiBusinessException {
478
        List<Item> items = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId());
479
        String title = "Price has been %s for %s";
24083 amit.gupta 480
 
28568 amit.gupta 481
 
31903 amit.gupta 482
        SendNotificationModel sendNotificationModel = new SendNotificationModel();
483
        sendNotificationModel.setCampaignName("pricechange");
484
        sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
485
        sendNotificationModel.setTitle("");
486
        StringBuffer sb = new StringBuffer();
487
        String message = null;
488
        if (priceDrop.getDropAmount() > 0) {
489
            title = String.format(title, "dropped", items.get(0).getItemDescriptionNoColor());
490
            message = String.format("Price has been dropped from Rs.%s. Old DP - Rs.%s, New DP - Rs.%s", FormattingUtils.formatDecimal(priceDrop.getDropAmount()),
491
                    FormattingUtils.formatDecimal(priceDrop.getOldDp()), FormattingUtils.formatDecimal(priceDrop.getNewDp()));
492
        } else {
493
            title = String.format(title, "increased", items.get(0).getItemDescriptionNoColor());
494
            message = String.format("Price has been increased from Rs.%s. Old DP - Rs.%s, New DP - Rs.%s", FormattingUtils.formatDecimal(-priceDrop.getDropAmount()),
495
                    FormattingUtils.formatDecimal(priceDrop.getOldDp()), FormattingUtils.formatDecimal(priceDrop.getNewDp()));
496
        }
497
        sendNotificationModel.setTitle(title);
498
        sendNotificationModel.setMessage(message);
499
        sendNotificationModel.setMessageType(MessageType.pricechange);
500
        notificationService.sendNotificationToAll(sendNotificationModel);
501
    }
28568 amit.gupta 502
 
31903 amit.gupta 503
    @RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
504
    public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
505
                                                        Model model) throws ProfitMandiBusinessException, Exception {
28568 amit.gupta 506
 
31903 amit.gupta 507
        PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
508
        Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
509
                .collect(Collectors.toMap(x -> x.getImei(), x -> x));
510
        LOGGER.info("PriceDropImeis {}, priceDropId {}", priceDropIMEIsMap, priceDropId);
511
        Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
512
        final HttpHeaders headers = new HttpHeaders();
513
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
514
        headers.set("Content-disposition",
515
                "inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
516
                        + FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
517
        ByteArrayOutputStream baos = null;
518
        if (priceDropIMEIsMap.size() == 0) {
519
            priceDropService.priceDropStatus(priceDrop.getId());
520
            baos = FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
521
                    "Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
522
                    "Grn On", "Activation Timestamp", "Activation Added On"), new ArrayList<>());
523
        } else {
28568 amit.gupta 524
 
31903 amit.gupta 525
            LOGGER.info("In else block");
33198 amit.gupta 526
            baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(), priceDropIMEIsMap, Optional.of(priceDrop.getCreatedOn()));
31903 amit.gupta 527
        }
528
        byte[] byteArray = baos.toByteArray();
529
        headers.setContentLength(byteArray.length);
530
        return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
24083 amit.gupta 531
 
31903 amit.gupta 532
    }
24083 amit.gupta 533
 
31903 amit.gupta 534
    @RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
33470 amit.gupta 535
    public String updatePriceDropImeis(@RequestBody PriceDropImeisModel priceDropImeisModel,
536
                                       Model model) throws Exception {
32012 amit.gupta 537
        final PriceDropImeiStatus status;
28102 tejbeer 538
 
31903 amit.gupta 539
        switch (priceDropImeisModel.getUpdatedStatus()) {
540
            case "approved": {
541
                status = PriceDropImeiStatus.APPROVED;
542
                break;
543
            }
32012 amit.gupta 544
            case "pending": {
545
                status = PriceDropImeiStatus.PENDING;
31903 amit.gupta 546
                break;
547
            }
548
            case "rejected": {
549
                status = PriceDropImeiStatus.REJECTED;
550
                break;
551
            }
32012 amit.gupta 552
            case "hold": {
553
                status = PriceDropImeiStatus.HOLD;
554
                break;
555
            }
556
            default:
557
                throw new IllegalStateException("Unexpected value: " + priceDropImeisModel.getUpdatedStatus());
31903 amit.gupta 558
        }
24168 amit.gupta 559
 
31903 amit.gupta 560
        if (PriceDropImeiStatus.PENDING.equals(status)) {
32012 amit.gupta 561
            List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository.selectByStatuses(Arrays.asList(PriceDropImeiStatus.REJECTED, PriceDropImeiStatus.HOLD),
31903 amit.gupta 562
                    priceDropImeisModel.getPriceDropId());
563
            LOGGER.info("hello" + priceDropIMEIs);
32012 amit.gupta 564
            for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
565
                if (priceDropIMEI.getStatus().equals(status) || !priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())) {
566
                    continue;
31903 amit.gupta 567
                }
32012 amit.gupta 568
                priceDropIMEI.setStatus(PriceDropImeiStatus.PENDING);
31903 amit.gupta 569
            }
570
            model.addAttribute("response1", mvcResponseSender.createResponseString(true));
571
            return "response";
572
        }
23951 amit.gupta 573
 
32012 amit.gupta 574
        if (status.equals(PriceDropImeiStatus.APPROVED)) {
575
            priceDropService.processPriceDrop(priceDropImeisModel.getPriceDropId(),
576
                    priceDropImeisModel.getUpdatedImeis());
577
        }
578
 
31903 amit.gupta 579
        List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
580
                .selectByPriceDropId(priceDropImeisModel.getPriceDropId());
581
        List<PriceDropIMEI> priceDropIMEIsToProcess = priceDropIMEIs.stream()
582
                .filter(x -> priceDropImeisModel.getUpdatedImeis().contains(x.getImei()))
32012 amit.gupta 583
                .filter(x -> !x.getStatus().equals(status)).collect(Collectors.toList());
31903 amit.gupta 584
        for (PriceDropIMEI priceDropImei : priceDropIMEIsToProcess) {
585
            if (status.equals(PriceDropImeiStatus.REJECTED)
586
                    && priceDropImei.getStatus().equals(PriceDropImeiStatus.PENDING)) {
587
                priceDropImei.setStatus(PriceDropImeiStatus.REJECTED);
588
                priceDropImei.setRejectionReason(priceDropImeisModel.getRejectionReason());
589
                priceDropImei.setRejectTimestamp(LocalDateTime.now());
590
            } else if (status.equals(PriceDropImeiStatus.HOLD)) {
591
                if (priceDropImei.getStatus().equals(PriceDropImeiStatus.PENDING)) {
592
                    priceDropImei.setStatus(PriceDropImeiStatus.HOLD);
593
                } else {
594
                    throw new ProfitMandiBusinessException("INVALID STATUS", status, "only  allowed For PENDING IMEIs");
595
                }
28568 amit.gupta 596
 
31903 amit.gupta 597
            }
28568 amit.gupta 598
 
31903 amit.gupta 599
        }
28568 amit.gupta 600
 
31903 amit.gupta 601
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
602
        return "response";
24083 amit.gupta 603
 
31903 amit.gupta 604
    }
24083 amit.gupta 605
 
31903 amit.gupta 606
    private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
33198 amit.gupta 607
                                                           Map<String, PriceDropIMEI> priceDropImeis, Optional<LocalDateTime> createdOn) throws Exception {
608
 
31903 amit.gupta 609
        List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
33198 amit.gupta 610
                .getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId, createdOn);
31903 amit.gupta 611
        List<List<?>> rows = new ArrayList<>();
612
        for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
613
            if (priceDropImeis == null) {
614
                rows.add(this.getRow(imeiDropSummaryModel, null));
615
            } else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
616
                rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
617
            }
618
        }
619
        return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
620
                "Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
621
                "Grn On", "Activation Timestamp", "Activation Added On"), rows);
622
    }
24083 amit.gupta 623
 
31903 amit.gupta 624
    private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel,
625
                                                PriceDropIMEI priceDropIMEI) {
626
        List<Serializable> row = new ArrayList<>();
627
        row.add(imeiDropSummaryModel.getSerialNumber());
628
        row.add(imeiDropSummaryModel.getStoreName());
629
        row.add(imeiDropSummaryModel.getPartnerCode());
630
        row.add(imeiDropSummaryModel.getItemId());
631
        row.add(imeiDropSummaryModel.getBrand());
632
        row.add(imeiDropSummaryModel.getModelName());
633
        row.add(imeiDropSummaryModel.getModelNumber());
634
        row.add(imeiDropSummaryModel.getColor());
635
        if (priceDropIMEI != null) {
636
            row.add(priceDropIMEI.getStatus());
637
            row.add(priceDropIMEI.getRejectionReason());
638
        } else {
639
            row.add(PriceDropImeiStatus.PENDING);
640
            row.add("");
641
        }
642
        row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
643
        row.add(imeiDropSummaryModel.getVendorName());
644
        row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getGrnOn()));
645
        row.add(imeiDropSummaryModel.getActivationTimestamp());
646
        row.add(imeiDropSummaryModel.getActivationAddedOn());
647
        return row;
648
    }
23819 govind 649
 
31903 amit.gupta 650
    private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
651
        if (priceDropModel.getMop() > 0 && priceDropModel.getDp() > 0 && priceDropModel.getTp() > 0) {
652
            return true;
653
        }
654
        return false;
655
    }
23945 amit.gupta 656
 
32844 shampa 657
    @Autowired
658
    BrandsService brandsService;
33470 amit.gupta 659
 
31903 amit.gupta 660
    @RequestMapping(value = "/priceCircular")
661
    public String priceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
662
        int fofoId = Utils.SYSTEM_PARTNER_ID;
32844 shampa 663
        List<String> brands = brandsService.getBrandsToDisplay(3).stream().map(x -> x.getName()).collect(Collectors.toList());
31903 amit.gupta 664
        model.addAttribute("brands", brands);
665
        model.addAttribute("isAdmin", true);
666
        model.addAttribute("date", FormattingUtils.format(LocalDateTime.now()));
28102 tejbeer 667
 
31903 amit.gupta 668
        return "partner-price-circular";
669
    }
28102 tejbeer 670
 
31903 amit.gupta 671
    @RequestMapping(value = "/partnerPriceCircular")
672
    public String partnerPriceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
673
        int fofoId = Utils.SYSTEM_PARTNER_ID;
32844 shampa 674
        Set<String> brands = brandsService.getBrandsToDisplay(3).stream().map(x -> x.getName()).collect(Collectors.toSet());
675
        brands.addAll(brandsService.getBrandsToDisplay(6).stream().map(x -> (String) x.getName())
31903 amit.gupta 676
                .collect(Collectors.toSet()));
677
        model.addAttribute("brands", brands);
678
        model.addAttribute("isAdmin", false);
28102 tejbeer 679
 
31903 amit.gupta 680
        return "partner-price-circular";
681
    }
28102 tejbeer 682
 
31903 amit.gupta 683
    @RequestMapping(value = "/priceCircularByBrand")
684
    public String priceCircularByBrand(HttpServletRequest request, @RequestParam String brand, Model model, @RequestParam(defaultValue = "0", required = false) int fofoId)
685
            throws ProfitMandiBusinessException {
686
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
687
        if (fofoId > 0 && roleManager.isAdmin(loginDetails.getRoleIds())) {
688
        } else {
689
            fofoId = loginDetails.getFofoId();
690
        }
32905 shampa 691
        FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
692
 
31903 amit.gupta 693
        //.minusDays(2)
34317 amit.gupta 694
        PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, brand, LocalDate.now());
35395 amit 695
        //Get slowmong/missign category for that brand
696
        //get stock with us missing as well as with partner missing
697
        //filter that stock
34317 amit.gupta 698
        return this.getPriceCircularView(priceCircularModel, model, fs.getCode());
32331 amit.gupta 699
    }
700
 
34317 amit.gupta 701
    public String getPriceCircularView(PriceCircularModel priceCircularModel, Model model, String partnerCode) {
702
        List<String> allMarginsSet = new ArrayList<>(this.getSchemeHeaders(priceCircularModel));
703
        List<String> sellins = SchemeType.IN_TYPES.stream().map(x -> x.getValue()).filter(x -> allMarginsSet.contains(x)).collect(Collectors.toList());
704
        List<String> sellouts = SchemeType.OUT_TYPES.stream().map(x -> x.getValue()).filter(x -> allMarginsSet.contains(x)).collect(Collectors.toList());
705
        List<String> allMargins = new ArrayList<>();
706
        allMargins.addAll(sellins);
707
        allMargins.addAll(sellouts);
31903 amit.gupta 708
        LOGGER.info("Sellins - {}", sellins);
709
        LOGGER.info("Sellouts - {}", sellouts);
34317 amit.gupta 710
        model.addAttribute("priceCircularItemModels", priceCircularModel.getPriceCircularItemModelNews());
31903 amit.gupta 711
        model.addAttribute("allMargins", allMargins);
712
        model.addAttribute("sellins", sellins);
713
        model.addAttribute("sellouts", sellouts);
34317 amit.gupta 714
        model.addAttribute("offers", priceCircularModel.getOffers());
715
        model.addAttribute("upgradeOffer", priceCircularModel.isUpgradeOffer());
31903 amit.gupta 716
        model.addAttribute("mvcResponseSender", mvcResponseSender);
32905 shampa 717
        model.addAttribute("partnerCode", partnerCode);
32331 amit.gupta 718
        return "price-circular-table";
31903 amit.gupta 719
    }
29951 amit.gupta 720
 
31903 amit.gupta 721
    private Set<String> getSchemeHeaders(PriceCircularModel priceCircular) {
722
        Set<String> schemeHeaders = new HashSet<>();
723
        priceCircular.getPriceCircularItemModelNews().stream().forEach(priceCircularItemModelNew -> {
724
            Map<String, AmountModel> headerMap = new HashMap<>();
725
            priceCircularItemModelNew.setHeaderSchemeModelsMap(headerMap);
726
            priceCircularItemModelNew.getSchemeSummaryModels().stream().forEach(schemeSummaryModel -> {
727
                if (schemeSummaryModel == null) return;
34317 amit.gupta 728
                schemeSummaryModel.setHeader(schemeSummaryModel.getSchemeType().getValue());
31903 amit.gupta 729
                if (!headerMap.containsKey(schemeSummaryModel.getHeader())) {
730
                    headerMap.put(schemeSummaryModel.getHeader(), new AmountModel(schemeSummaryModel.getAmount(), schemeSummaryModel.getAmountType()));
731
                } else {
732
                    AmountModel model = headerMap.get(schemeSummaryModel.getHeader());
733
                    model.setAmount(model.getAmount() + schemeSummaryModel.getAmount());
734
                }
735
                schemeHeaders.add(schemeSummaryModel.getHeader());
736
            });
737
        });
28102 tejbeer 738
 
31903 amit.gupta 739
        LOGGER.info("Scheme headers - {}", schemeHeaders);
740
        return schemeHeaders;
741
    }
30250 amit.gupta 742
 
31903 amit.gupta 743
    //private static final List<String> SELLINS = Arrays.asList("Base Payout", "Cash Discount", "Upfront Margin");
744
    //private static final List<String> SELLOUTS = Arrays.asList("Tertiary Payout", "Hygiene Payout", "Investment Payout", "Category Payout", "Activation Margin", "Special Support");
30471 amit.gupta 745
 
30562 amit.gupta 746
 
31903 amit.gupta 747
    @RequestMapping(value = "/downloadNlcByBrand")
748
    public ResponseEntity<ByteArrayResource> downloadNlcByBrand(HttpServletRequest request,
749
                                                                @RequestParam String brand, Model model, @RequestParam(defaultValue = "0", required = false) int fofoId) throws Exception {
750
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
751
        if (fofoId > 0 && roleManager.isAdmin(loginDetails.getRoleIds())) {
752
        } else {
753
            fofoId = loginDetails.getFofoId();
754
        }
755
        PriceCircularModel priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, brand, LocalDate.now());
756
        /*List<Integer> catalogIds = priceCircular.getPriceCircularItemModelNews().stream().limit(10).map(x->x.getCatalogId()).collect(Collectors.toList());
757
        priceCircular = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());*/
758
        ByteArrayOutputStream baos = getNlcBaos(brand, priceCircular);
759
        final HttpHeaders headers = new HttpHeaders();
760
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
761
        headers.set("Content-disposition", "inline; filename=\"" + brand + ".csv\"");
762
        byte[] byteArray = baos.toByteArray();
763
        headers.setContentLength(byteArray.length);
764
        return new ResponseEntity<>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
765
    }
30471 amit.gupta 766
 
31903 amit.gupta 767
    private ByteArrayOutputStream getNlcBaos(String brand, PriceCircularModel priceCircular) throws Exception {
768
        List<List<?>> rows = new ArrayList<>();
769
        for (PriceCircularItemModelNew priceCircularItemModel : priceCircular.getPriceCircularItemModelNews()) {
770
            List<Serializable> row = new ArrayList<>();
771
            row.add(priceCircularItemModel.getCatalogId());
772
            row.add(brand);
773
            row.add(priceCircularItemModel.getCatalogSummaryModel().getModelName());
774
            row.add(priceCircularItemModel.getCatalogSummaryModel().getModelNumber());
775
            //TODO: fix nlc
776
            //row.add(priceCircularItemModel.getNetPrice());
777
            rows.add(row);
778
        }
779
        return FileUtil.getCSVByteStream(Arrays.asList("Model Id", "Brand", "Model Name", "Model Number", "Partner Landing"), rows);
780
    }
30471 amit.gupta 781
 
31903 amit.gupta 782
    @RequestMapping(value = "/selectPriceDropStatus", method = RequestMethod.GET)
783
    public String selectPriceDropStatus(HttpServletRequest request,
784
                                        @RequestParam(name = "selectedStatus", required = true, defaultValue = "") String selectedStatus,
785
                                        Model model) throws Exception {
30250 amit.gupta 786
 
31903 amit.gupta 787
        model.addAttribute("selectedStatus", selectedStatus);
788
        return "pricedrop-status-change";
789
    }
30250 amit.gupta 790
 
23819 govind 791
}