Subversion Repositories SmartDukaan

Rev

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

Rev 25853 Rev 26082
Line 211... Line 211...
211
	 */
211
	 */
212
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
212
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
213
	public String saveOpenIndent(HttpServletRequest request, Model model, @RequestParam int catalogId,
213
	public String saveOpenIndent(HttpServletRequest request, Model model, @RequestParam int catalogId,
214
			@RequestParam int itemQty) throws Exception {
214
			@RequestParam int itemQty) throws Exception {
215
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
215
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
216
		LocalDate currentMonthdate = LocalDate.now().withDayOfMonth(1);
216
		LocalDate currentMonthDate = LocalDate.now();
217
		LOGGER.info("currentMonthdate" + currentMonthdate);
-
 
218
		LOGGER.info("catalogId" + catalogId);
217
		MonthlyPlanned monthlyPlanned = null;
219
		LOGGER.info("itemQty" + itemQty);
-
 
220
 
218
 
-
 
219
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(25))
-
 
220
				&& LocalDate.now().isBefore(LocalDate.now().plusMonths(1).withDayOfMonth(8))) {
-
 
221
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
221
		MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
222
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
-
 
223
					currentMonthDate);
-
 
224
 
-
 
225
			saveMonthlyPlanned(monthlyPlanned, loginDetails.getFofoId(), currentMonthDate, catalogId, itemQty);
-
 
226
		} else if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(8))
-
 
227
				&& (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(26)))) {
-
 
228
			// freezed code;
-
 
229
		} else if (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(8))) {
-
 
230
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
-
 
231
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
222
				currentMonthdate);
232
					currentMonthDate);
223
 
233
 
-
 
234
			saveMonthlyPlanned(monthlyPlanned, loginDetails.getFofoId(), currentMonthDate, catalogId, itemQty);
-
 
235
		}
-
 
236
 
-
 
237
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
238
 
-
 
239
		model.addAttribute("response", mvcResponseSender.createResponseString(false));
-
 
240
 
-
 
241
		return "response";
-
 
242
	}
-
 
243
 
-
 
244
	private void saveMonthlyPlanned(MonthlyPlanned monthlyPlanned, int fofoId, LocalDate currentMonthDate,
-
 
245
			int catalogId, int itemQty) {
224
		if (monthlyPlanned == null) {
246
		if (monthlyPlanned == null) {
225
			monthlyPlanned = new MonthlyPlanned();
247
			monthlyPlanned = new MonthlyPlanned();
226
			monthlyPlanned.setFofoId(loginDetails.getFofoId());
248
			monthlyPlanned.setFofoId(fofoId);
227
			monthlyPlanned.setYearMonth(currentMonthdate);
249
			monthlyPlanned.setYearMonth(currentMonthDate);
228
			monthlyPlannedRepository.persist(monthlyPlanned);
250
			monthlyPlannedRepository.persist(monthlyPlanned);
229
			PlannedDetail pd = new PlannedDetail();
251
			PlannedDetail pd = new PlannedDetail();
230
			pd.setCatalogId(catalogId);
252
			pd.setCatalogId(catalogId);
231
			pd.setPlannedId(monthlyPlanned.getId());
253
			pd.setPlannedId(monthlyPlanned.getId());
232
			pd.setQuantity(itemQty);
254
			pd.setQuantity(itemQty);
Line 252... Line 274...
252
				plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
274
				plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
253
			}
275
			}
254
 
276
 
255
		}
277
		}
256
 
278
 
257
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
258
 
-
 
259
		return "response";
-
 
260
	}
279
	}
261
 
280
 
262
	@RequestMapping(value = "/open-indent/confirm", method = RequestMethod.POST)
281
	@RequestMapping(value = "/open-indent/confirm", method = RequestMethod.POST)
263
	public String confirmOpenIndent(HttpServletRequest request, Model model) throws Exception {
282
	public String confirmOpenIndent(HttpServletRequest request, Model model) throws Exception {
264
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
283
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
265
		int fofoId = loginDetails.getFofoId();
284
		int fofoId = loginDetails.getFofoId();
266
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
285
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
-
 
286
		LocalDate currentMonthDate = LocalDate.now();
-
 
287
		MonthlyPlanned monthlyPlanned = null;
-
 
288
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(25))
-
 
289
				&& LocalDate.now().isBefore(LocalDate.now().plusMonths(1).withDayOfMonth(8))) {
-
 
290
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
267
		MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoId(fofoId);
291
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
-
 
292
 
-
 
293
			confirmMonthlyPlanned(monthlyPlanned, customRetailer, fofoId);
-
 
294
		} else if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(8))
-
 
295
				&& (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(26)))) {
-
 
296
			// freezed code;
-
 
297
		} else if (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(8))) {
-
 
298
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
-
 
299
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
268
 
300
 
269
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
301
			confirmMonthlyPlanned(monthlyPlanned, customRetailer, fofoId);
-
 
302
		}
-
 
303
 
-
 
304
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
305
 
-
 
306
		return "response";
-
 
307
	}
-
 
308
 
-
 
309
	private void confirmMonthlyPlanned(MonthlyPlanned monthlyPlanned, CustomRetailer customRetailer, int fofoId)
-
 
310
			throws Exception {
270
		List<PlannedDetail> plannedDetails = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId());
311
		List<PlannedDetail> plannedDetails = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId());
271
 
312
 
272
		List<PlannedModel> plannedModel = new ArrayList<>();
313
		List<PlannedModel> plannedModel = new ArrayList<>();
273
		for (PlannedDetail plannedDetail : plannedDetails) {
314
		for (PlannedDetail plannedDetail : plannedDetails) {
274
 
315
 
Line 276... Line 317...
276
			String itemDesription = items.get(0).getItemDescriptionNoColor();
317
			String itemDesription = items.get(0).getItemDescriptionNoColor();
277
			PlannedModel pm = new PlannedModel();
318
			PlannedModel pm = new PlannedModel();
278
			pm.setItemDescription(itemDesription);
319
			pm.setItemDescription(itemDesription);
279
			pm.setStoreName(customRetailer.getBusinessName());
320
			pm.setStoreName(customRetailer.getBusinessName());
280
			pm.setQty(plannedDetail.getQuantity());
321
			pm.setQty(plannedDetail.getQuantity());
281
			pm.setFofoId(loginDetails.getFofoId());
322
			pm.setFofoId(fofoId);
282
			plannedModel.add(pm);
323
			plannedModel.add(pm);
283
			LOGGER.info("plannedModel" + plannedModel);
324
			LOGGER.info("plannedModel" + plannedModel);
284
 
325
 
285
		}
326
		}
286
		List<String> emails = csService.getAuthUserByPartnerId(fofoId);
327
		List<String> emails = csService.getAuthUserByPartnerId(fofoId);
287
		emails.add(customRetailer.getEmail());
328
		emails.add(customRetailer.getEmail());
288
 
329
 
289
		/*
-
 
290
		 * List<String> emails = new ArrayList<>(); emails.add("tejbeer1710@gmail.com");
-
 
291
		 */
-
 
292
		LOGGER.info("emails" + emails);
330
		LOGGER.info("emails" + emails);
-
 
331
 
293
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
332
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
294
				Arrays.asList("Partner Id", "Partner Name", "Model Name", "Qty"),
333
				Arrays.asList("Partner Id", "Partner Name", "Model Name", "Qty"),
295
				plannedModel.stream()
334
				plannedModel.stream()
296
						.map(x -> Arrays.asList(x.getFofoId(), x.getStoreName(), x.getItemDescription(), x.getQty()))
335
						.map(x -> Arrays.asList(x.getFofoId(), x.getStoreName(), x.getItemDescription(), x.getQty()))
297
						.collect(Collectors.toList()));
336
						.collect(Collectors.toList()));
298
		LOGGER.info("baos" + baos);
337
		LOGGER.info("baos" + baos);
299
		Utils.sendMailWithAttachments(googleMailSender, emails.toArray(new String[emails.size()]), null,
338
		Utils.sendMailWithAttachments(googleMailSender, emails.toArray(new String[emails.size()]), null,
300
				"Planned Indent", "PFA",
339
				"Planned Indent", "PFA",
301
				new Attachment[] { new Attachment("PlannedIndent.csv", new ByteArrayResource(baos.toByteArray())), });
340
				new Attachment[] { new Attachment("PlannedIndent.csv", new ByteArrayResource(baos.toByteArray())), });
302
 
341
 
303
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
304
		return "response";
-
 
305
	}
342
	}
306
 
343
 
307
	@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
344
	@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
308
	public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
345
	public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
309
			@RequestParam(required = false, defaultValue = "0") int fofoId,
346
			@RequestParam(required = false, defaultValue = "0") int fofoId,
Line 518... Line 555...
518
		Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
555
		Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
519
 
556
 
520
		Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
557
		Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
521
				.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
558
				.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
522
 
559
 
-
 
560
		LocalDate currentMonthDate = LocalDate.now();
-
 
561
		MonthlyPlanned monthlyPlanned = null;
-
 
562
		LOGGER.info("localDate" + LocalDate.now());
-
 
563
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(25))
-
 
564
				&& LocalDate.now().isBefore(LocalDate.now().plusMonths(1).withDayOfMonth(8))) {
-
 
565
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
523
		MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoId(loginDetails.getFofoId());
566
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
-
 
567
			LOGGER.info("monthlyPlanned2" + monthlyPlanned);
-
 
568
 
-
 
569
			model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
-
 
570
		} else if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(8))
-
 
571
				&& (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(26)))) {
-
 
572
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
-
 
573
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
-
 
574
			LOGGER.info("monthlyPlanned1" + monthlyPlanned);
-
 
575
		} else if (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(8))) {
-
 
576
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
-
 
577
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
524
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
578
			LOGGER.info("monthlyPlanned3" + monthlyPlanned);
-
 
579
			model.addAttribute("planningMonth", LocalDate.now().getMonth());
-
 
580
		}
-
 
581
 
525
		Map<Integer, Integer> plannedDetailMap = null;
582
		Map<Integer, Integer> plannedDetailMap = null;
526
		if (monthlyPlanned != null) {
583
		if (monthlyPlanned != null) {
527
			plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
584
			plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
528
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
585
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
529
 
586