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