Subversion Repositories SmartDukaan

Rev

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

Rev 23996 Rev 24089
Line 16... Line 16...
16
import org.springframework.mail.javamail.JavaMailSender;
16
import org.springframework.mail.javamail.JavaMailSender;
17
import org.springframework.mail.javamail.MimeMessageHelper;
17
import org.springframework.mail.javamail.MimeMessageHelper;
18
import org.springframework.stereotype.Controller;
18
import org.springframework.stereotype.Controller;
19
import org.springframework.transaction.annotation.Transactional;
19
import org.springframework.transaction.annotation.Transactional;
20
import org.springframework.ui.Model;
20
import org.springframework.ui.Model;
-
 
21
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestMethod;
23
import org.springframework.web.bind.annotation.RequestMethod;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RequestParam;
24
 
25
 
25
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26
import com.spice.profitmandi.common.model.CustomRetailer;
27
import com.spice.profitmandi.common.model.CustomRetailer;
27
import com.spice.profitmandi.common.model.ProfitMandiConstants;
28
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
29
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
28
import com.spice.profitmandi.common.util.StringUtils;
30
import com.spice.profitmandi.common.util.StringUtils;
29
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
31
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
-
 
32
import com.spice.profitmandi.dao.entity.transaction.UnsettledPayment;
30
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
33
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
31
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
34
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
32
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
35
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
33
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
36
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
-
 
37
import com.spice.profitmandi.dao.repository.catalog.UnsettledPaymentsRepository;
34
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
38
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
35
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
39
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
36
import com.spice.profitmandi.service.user.RetailerService;
40
import com.spice.profitmandi.service.user.RetailerService;
37
import com.spice.profitmandi.service.wallet.WalletService;
41
import com.spice.profitmandi.service.wallet.WalletService;
38
import com.spice.profitmandi.web.model.LoginDetails;
42
import com.spice.profitmandi.web.model.LoginDetails;
Line 62... Line 66...
62
 
66
 
63
	@Autowired
67
	@Autowired
64
	JavaMailSender mailSender;
68
	JavaMailSender mailSender;
65
 
69
 
66
	@Autowired
70
	@Autowired
-
 
71
	private UnsettledPaymentsRepository unsettledPaymentsRepository;
-
 
72
 
-
 
73
	@Autowired
67
	private RetailerService retailerService;
74
	private RetailerService retailerService;
68
 
75
 
69
	@Autowired
76
	@Autowired
70
	AddWalletRequestRepository addWalletRequestRepository;
77
	AddWalletRequestRepository addWalletRequestRepository;
71
	private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
78
	private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
Line 318... Line 325...
318
		return "add-wallet-request-paginated";
325
		return "add-wallet-request-paginated";
319
	}
326
	}
320
 
327
 
321
	@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
328
	@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
322
	public String addAmountToWallet(HttpServletRequest request, @RequestParam(name = "id", defaultValue = "0") int id,
329
	public String addAmountToWallet(HttpServletRequest request, @RequestParam(name = "id", defaultValue = "0") int id,
-
 
330
			@RequestParam(name = "walletRequestid", defaultValue = "0") int walletRequestid, Model model)
323
			Model model) throws Exception {
331
			throws Exception {
324
 
332
 
325
		AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
333
		AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(walletRequestid);
326
		if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
334
		if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
327
			walletService.addAmountToWallet(addWalletRequest.getRetailerId(), id, WalletReferenceType.ADVANCE_AMOUNT,
335
			walletService.addAmountToWallet(addWalletRequest.getRetailerId(), walletRequestid,
328
					"ntfs/rgfs", addWalletRequest.getAmount());
336
					WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs", addWalletRequest.getAmount());
329
			addWalletRequest.setStatus(AddWalletRequestStatus.approved);
337
			addWalletRequest.setStatus(AddWalletRequestStatus.approved);
330
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
338
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
331
			addWalletRequestRepository.persist(addWalletRequest);
339
			addWalletRequestRepository.persist(addWalletRequest);
-
 
340
			unsettledPaymentsRepository.deleteById(id);
332
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
341
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
333
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
342
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
334
			String subject = "Request Approved for " + customRetailer.getBusinessName() + " of Rs."
343
			String subject = "Request Approved for " + customRetailer.getBusinessName() + " of Rs."
335
					+ addWalletRequest.getAmount();
344
					+ addWalletRequest.getAmount();
336
			String messageText = MessageFormat.format(
345
			String messageText = MessageFormat.format(
Line 375... Line 384...
375
	}
384
	}
376
 
385
 
377
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
386
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
378
		MimeMessage message = mailSender.createMimeMessage();
387
		MimeMessage message = mailSender.createMimeMessage();
379
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
388
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
380
		String[] email = { "neerajgupta2021@gmail.com","adeel.yazdani@smartdukaan.com", "kamini.sharma@smartdukaan.com", "care@smartdukaan.com",
389
		String[] email = { "neerajgupta2021@gmail.com", "adeel.yazdani@smartdukaan.com",
381
				"mohinder.mutreja@smartdukaan.com" };
390
				"kamini.sharma@smartdukaan.com", "care@smartdukaan.com", "mohinder.mutreja@smartdukaan.com" };
382
		helper.setSubject(subject);
391
		helper.setSubject(subject);
383
		helper.setText(messageText);
392
		helper.setText(messageText);
384
		helper.setTo(email);
393
		helper.setTo(email);
385
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
394
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
386
		helper.setFrom(senderAddress);
395
		helper.setFrom(senderAddress);
Line 394... Line 403...
394
			fofoIds.add(walletdetail.getRetailerId());
403
			fofoIds.add(walletdetail.getRetailerId());
395
		}
404
		}
396
		return fofoIds;
405
		return fofoIds;
397
	}
406
	}
398
 
407
 
-
 
408
	@RequestMapping(value = "/getcreateUnsettledPayments", method = RequestMethod.GET)
-
 
409
	public String getcreateUnsettledPayment(HttpServletRequest request,
-
 
410
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
411
			@RequestParam(name = "limit", defaultValue = "15") int limit, Model model) throws Exception {
-
 
412
		List<UnsettledPayment> up = null;
-
 
413
 
-
 
414
		long size = 0;
-
 
415
		up = unsettledPaymentsRepository.selectAllById(offset, limit);
-
 
416
 
-
 
417
		size = unsettledPaymentsRepository.selectAllCount();
-
 
418
		if (!up.isEmpty()) {
-
 
419
			model.addAttribute("unsettledPayment", up);
-
 
420
			model.addAttribute("start", offset + 1);
-
 
421
			model.addAttribute("size", size);
-
 
422
			model.addAttribute("url", "/getPaginatedUnsettledPayments");
-
 
423
 
-
 
424
			if (up.size() < limit) {
-
 
425
				model.addAttribute("end", offset + up.size());
-
 
426
			} else {
-
 
427
				model.addAttribute("end", offset + limit);
-
 
428
			}
-
 
429
		} else {
-
 
430
			model.addAttribute("unsettledPayment", up);
-
 
431
			model.addAttribute("size", size);
-
 
432
		}
-
 
433
 
-
 
434
		LOGGER.info("unsettledPaymentList" + up);
-
 
435
		return "unsettled-payments";
-
 
436
	}
-
 
437
 
-
 
438
 
-
 
439
	@RequestMapping(value = "/getUnsettledPaymentsByAmount", method = RequestMethod.GET)
-
 
440
	public String getUnsettledPaymentByAmount(HttpServletRequest request,
-
 
441
			@RequestParam(name = "amount", defaultValue = "0") float amount,
-
 
442
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
443
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
-
 
444
		List<UnsettledPayment> up = null;
-
 
445
 
-
 
446
		long size = 0;
-
 
447
		up = unsettledPaymentsRepository.selectAllByAmount(amount, offset, limit);
-
 
448
 
-
 
449
		size = unsettledPaymentsRepository.selectAllCount();
-
 
450
		if (!up.isEmpty()) {
-
 
451
			model.addAttribute("unsettledPayment", up);
-
 
452
			model.addAttribute("start", offset + 1);
-
 
453
			model.addAttribute("size", size);
-
 
454
			model.addAttribute("url", "/getPaginatedUnsettledPayments");
-
 
455
 
-
 
456
			if (up.size() < limit) {
-
 
457
				model.addAttribute("end", offset + up.size());
-
 
458
			} else {
-
 
459
				model.addAttribute("end", offset + limit);
-
 
460
			}
-
 
461
			return "unsettle-payment-modal";
-
 
462
		} else {
-
 
463
			model.addAttribute("unsettledPayment", up);
-
 
464
			model.addAttribute("size", size);
-
 
465
		}
-
 
466
 
-
 
467
		
-
 
468
		return "unsettle-payment-modal";
-
 
469
	}
-
 
470
 
-
 
471
	@RequestMapping(value = "/createUnsettledPaymentsEntries", method = RequestMethod.POST)
-
 
472
	public String createUnsettledPaymentsEntries(HttpServletRequest request,
-
 
473
			@RequestBody UnsettledPaymentModel unsettledPaymentModel, Model model) throws Exception {
-
 
474
 
-
 
475
		UnsettledPayment up = new UnsettledPayment();
-
 
476
		up.setTransaction_reference(unsettledPaymentModel.getTransactionReference());
-
 
477
		up.setAmount(unsettledPaymentModel.getAmount());
-
 
478
		up.setDescription(unsettledPaymentModel.getDescription());
-
 
479
		up.setReference_date(unsettledPaymentModel.getReferenceDate());
-
 
480
		LOGGER.info("uppaynments" + up);
-
 
481
		unsettledPaymentsRepository.persist(up);
-
 
482
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
483
		return "response";
-
 
484
	}
-
 
485
 
-
 
486
	@RequestMapping(value = "/removeUnsettledPaymentsEntries", method = RequestMethod.DELETE)
-
 
487
	public String removeUnsettledPaymentsEntries(HttpServletRequest request,
-
 
488
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
-
 
489
 
-
 
490
		unsettledPaymentsRepository.deleteById(id);
-
 
491
 
-
 
492
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
493
		return "response";
-
 
494
	}
-
 
495
 
399
}
496
}