| Line 45... |
Line 45... |
| 45 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
45 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 46 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
46 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| 47 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
47 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 48 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
48 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
| 49 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
49 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| - |
|
50 |
import com.spice.profitmandi.dao.model.ItemCriteriaPayout;
|
| 50 |
import com.spice.profitmandi.dao.model.OfferRowModel;
|
51 |
import com.spice.profitmandi.dao.model.OfferRowModel;
|
| 51 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
52 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
|
53 |
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
|
| 53 |
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
|
54 |
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
55 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
56 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 56 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
57 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 57 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
58 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| - |
|
59 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 58 |
import com.spice.profitmandi.service.offers.OfferService;
|
60 |
import com.spice.profitmandi.service.offers.OfferService;
|
| 59 |
import com.spice.profitmandi.service.user.RetailerService;
|
61 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 60 |
import com.spice.profitmandi.web.model.LoginDetails;
|
62 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 61 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
63 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 62 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
64 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| Line 154... |
Line 156... |
| 154 |
|
156 |
|
| 155 |
@RequestMapping(value = "/offerHistory", method = RequestMethod.GET)
|
157 |
@RequestMapping(value = "/offerHistory", method = RequestMethod.GET)
|
| 156 |
public String getPaginatedOffers(HttpServletRequest request, @RequestParam YearMonth yearMonth, Model model)
|
158 |
public String getPaginatedOffers(HttpServletRequest request, @RequestParam YearMonth yearMonth, Model model)
|
| 157 |
throws ProfitMandiBusinessException {
|
159 |
throws ProfitMandiBusinessException {
|
| 158 |
|
160 |
|
| 159 |
List<CreateOfferRequest> publishedOffers = offerService.getAllOffers(yearMonth)
|
161 |
List<CreateOfferRequest> publishedOffers = offerService.getAllOffers(yearMonth).values()
|
| 160 |
.stream().sorted(Comparator.comparing(CreateOfferRequest::getId).reversed()).collect(Collectors.toList());
|
162 |
.stream().sorted(Comparator.comparing(CreateOfferRequest::getId).reversed()).collect(Collectors.toList());
|
| 161 |
model.addAttribute("offers", publishedOffers);
|
163 |
model.addAttribute("offers", publishedOffers);
|
| 162 |
model.addAttribute("yearMonth", yearMonth);
|
164 |
model.addAttribute("yearMonth", yearMonth);
|
| 163 |
|
165 |
|
| 164 |
return "offer_history";
|
166 |
return "offer_history";
|
| Line 167... |
Line 169... |
| 167 |
@RequestMapping(value = "/offer-details", method = RequestMethod.GET)
|
169 |
@RequestMapping(value = "/offer-details", method = RequestMethod.GET)
|
| 168 |
public String schemeDetails(HttpServletRequest request, @RequestParam int offerId, Model model)
|
170 |
public String schemeDetails(HttpServletRequest request, @RequestParam int offerId, Model model)
|
| 169 |
throws ProfitMandiBusinessException {
|
171 |
throws ProfitMandiBusinessException {
|
| 170 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
172 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 171 |
|
173 |
|
| 172 |
CreateOfferRequest createOfferRequest = offerService.getOffer(offerId);
|
174 |
CreateOfferRequest createOfferRequest = offerService.getOffer(loginDetails.getFofoId(), offerId);
|
| 173 |
int fofoId = loginDetails.getFofoId();
|
- |
|
| 174 |
double amount = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId) == null ? 0
|
- |
|
| 175 |
: offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
- |
|
| 176 |
|
- |
|
| 177 |
com.spice.profitmandi.dao.model.TargetSlab currentSlab = createOfferRequest.getTargetSlabs().stream()
|
- |
|
| 178 |
.filter(x -> x.getOnwardsAmount() <= amount).max(Comparator.comparing(x -> x.getOnwardsAmount()))
|
- |
|
| 179 |
.orElse(null);
|
- |
|
| 180 |
|
- |
|
| 181 |
com.spice.profitmandi.dao.model.TargetSlab nextSlab = createOfferRequest.getTargetSlabs().stream()
|
- |
|
| 182 |
.filter(x -> x.getOnwardsAmount() > amount).min(Comparator.comparing(x -> x.getOnwardsAmount()))
|
- |
|
| 183 |
.orElse(null);
|
- |
|
| 184 |
createOfferRequest.setNextTargetSlab(nextSlab);
|
- |
|
| 185 |
createOfferRequest.setCurrentTargetSlab(currentSlab);
|
- |
|
| 186 |
createOfferRequest.setEligibleSale((int) amount);
|
- |
|
| 187 |
|
175 |
|
| 188 |
model.addAttribute("offer", createOfferRequest);
|
176 |
model.addAttribute("offer", createOfferRequest);
|
| 189 |
return "offer-details";
|
177 |
return "offer-details";
|
| 190 |
}
|
178 |
}
|
| 191 |
|
179 |
|
| Line 194... |
Line 182... |
| 194 |
throws Exception {
|
182 |
throws Exception {
|
| 195 |
List<List<?>> listOfRows = new ArrayList<>();
|
183 |
List<List<?>> listOfRows = new ArrayList<>();
|
| 196 |
final HttpHeaders headers = new HttpHeaders();
|
184 |
final HttpHeaders headers = new HttpHeaders();
|
| 197 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
185 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 198 |
headers.set("Content-disposition", "inline; filename=offer-" + offerId + ".csv");
|
186 |
headers.set("Content-disposition", "inline; filename=offer-" + offerId + ".csv");
|
| 199 |
CreateOfferRequest createOfferRequest = offerService.getOffer(offerId);
|
187 |
CreateOfferRequest createOfferRequest = offerService.getOffer(0, offerId);
|
| 200 |
Collection<OfferRowModel> offerRowModels = offerRepository.getOfferRows(createOfferRequest);
|
188 |
Collection<OfferRowModel> offerRowModels = offerRepository.getOfferRows(createOfferRequest);
|
| 201 |
|
189 |
|
| 202 |
for (OfferRowModel offerRowModel : offerRowModels) {
|
190 |
for (OfferRowModel offerRowModel : offerRowModels) {
|
| 203 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(offerRowModel.getFofoId());
|
191 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(offerRowModel.getFofoId());
|
| 204 |
listOfRows.add(Arrays.asList(createOfferRequest.getId(), createOfferRequest.getName(),
|
192 |
listOfRows.add(Arrays.asList(createOfferRequest.getId(), createOfferRequest.getName(),
|
| Line 243... |
Line 231... |
| 243 |
int fofoId = loginDetails.getFofoId();
|
231 |
int fofoId = loginDetails.getFofoId();
|
| 244 |
List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(fofoId, YearMonth.from(LocalDate.now()).minusMonths(yearMonth));
|
232 |
List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(fofoId, YearMonth.from(LocalDate.now()).minusMonths(yearMonth));
|
| 245 |
|
233 |
|
| 246 |
model.addAttribute("publishedOffers", createOffers);
|
234 |
model.addAttribute("publishedOffers", createOffers);
|
| 247 |
|
235 |
|
| - |
|
236 |
|
| - |
|
237 |
|
| 248 |
return "published-offers";
|
238 |
return "published-offers";
|
| 249 |
}
|
239 |
}
|
| 250 |
|
240 |
|
| 251 |
@PostMapping(value = "/offers/upload")
|
241 |
@PostMapping(value = "/offers/upload")
|
| 252 |
public String uploadOffers(HttpServletRequest request, @RequestPart("file") MultipartFile targetFile, Model model)
|
242 |
public String uploadOffers(HttpServletRequest request, @RequestPart("file") MultipartFile targetFile, Model model)
|
| 253 |
throws Exception {
|
243 |
throws Exception {
|
| 254 |
offerService.createOffers(targetFile.getInputStream());
|
244 |
offerService.createOffers(targetFile.getInputStream());
|
| 255 |
model.addAttribute("response", true);
|
245 |
model.addAttribute("response", true);
|
| 256 |
return "response";
|
246 |
return "response";
|
| 257 |
}
|
247 |
}
|
| - |
|
248 |
|
| - |
|
249 |
@Autowired
|
| - |
|
250 |
RoleManager roleManager;
|
| 258 |
|
251 |
|
| 259 |
@RequestMapping(value = "/getOfferMargins", method = RequestMethod.GET)
|
252 |
@RequestMapping(value = "/getOfferMargins", method = RequestMethod.GET)
|
| 260 |
public String getOfferMargins(HttpServletRequest request,
|
253 |
public String getOfferMargins(HttpServletRequest request,
|
| 261 |
@RequestParam(name = "offerId", defaultValue = "0") int offerId, Model model) throws Exception {
|
254 |
@RequestParam(name = "offerId", defaultValue = "0") int offerId, Model model) throws Exception {
|
| 262 |
Offer offer = offerRepository.selectById(offerId);
|
- |
|
| 263 |
|
- |
|
| 264 |
LOGGER.info("offerId" + offer.getId());
|
- |
|
| 265 |
|
- |
|
| 266 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
255 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 267 |
|
- |
|
| 268 |
CreateOfferRequest createOfferRequest = offerService.getOffer(offerId);
|
- |
|
| 269 |
int fofoId = loginDetails.getFofoId();
|
256 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 270 |
double amount = offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId) == null ? 0
|
257 |
CreateOfferRequest createOfferRequest = offerService.getOffer(isAdmin?0:loginDetails.getFofoId(), offerId);
|
| 271 |
: offerRepository.getPartnerWiseSalesSum(createOfferRequest).get(fofoId);
|
- |
|
| 272 |
|
- |
|
| 273 |
com.spice.profitmandi.dao.model.TargetSlab currentSlab = createOfferRequest.getTargetSlabs().stream()
|
- |
|
| 274 |
.filter(x -> x.getOnwardsAmount() <= amount).max(Comparator.comparing(x -> x.getOnwardsAmount()))
|
- |
|
| 275 |
.orElse(null);
|
- |
|
| 276 |
|
258 |
|
| 277 |
com.spice.profitmandi.dao.model.TargetSlab nextSlab = createOfferRequest.getTargetSlabs().stream()
|
- |
|
| 278 |
.filter(x -> x.getOnwardsAmount() > amount).min(Comparator.comparing(x -> x.getOnwardsAmount()))
|
- |
|
| 279 |
.orElse(null);
|
- |
|
| 280 |
createOfferRequest.setNextTargetSlab(nextSlab);
|
- |
|
| 281 |
createOfferRequest.setCurrentTargetSlab(currentSlab);
|
- |
|
| 282 |
createOfferRequest.setEligibleSale((int) amount);
|
- |
|
| 283 |
model.addAttribute("offer", createOfferRequest);
|
259 |
model.addAttribute("offer", createOfferRequest);
|
| 284 |
|
260 |
|
| 285 |
return "offer_margin_detail_partner";
|
261 |
return "offer_margin_detail_partner";
|
| 286 |
|
262 |
|
| 287 |
}
|
263 |
}
|