Subversion Repositories SmartDukaan

Rev

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

Rev 30873 Rev 31238
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.ByteArrayInputStream;
-
 
4
import java.io.ByteArrayOutputStream;
-
 
5
import java.io.InputStream;
-
 
6
import java.text.MessageFormat;
-
 
7
import java.time.LocalDate;
-
 
8
import java.time.LocalDateTime;
-
 
9
import java.time.ZoneId;
-
 
10
import java.util.ArrayList;
-
 
11
import java.util.Arrays;
-
 
12
import java.util.Collections;
-
 
13
import java.util.Date;
-
 
14
import java.util.HashMap;
-
 
15
import java.util.List;
-
 
16
import java.util.Map;
-
 
17
import java.util.Set;
-
 
18
import java.util.stream.Collectors;
-
 
19
 
-
 
20
import javax.mail.internet.InternetAddress;
-
 
21
import javax.mail.internet.MimeMessage;
-
 
22
import javax.servlet.http.HttpServletRequest;
-
 
23
import javax.swing.SortOrder;
-
 
24
import javax.transaction.Transactional;
-
 
25
 
-
 
26
import org.apache.logging.log4j.LogManager;
-
 
27
import org.apache.logging.log4j.Logger;
-
 
28
import org.apache.poi.ss.usermodel.Cell;
-
 
29
import org.apache.poi.ss.usermodel.CellStyle;
-
 
30
import org.apache.poi.ss.usermodel.CreationHelper;
-
 
31
import org.apache.poi.ss.usermodel.Sheet;
-
 
32
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-
 
33
import org.json.JSONObject;
-
 
34
import org.springframework.beans.factory.annotation.Autowired;
-
 
35
import org.springframework.core.io.InputStreamResource;
-
 
36
import org.springframework.http.HttpHeaders;
-
 
37
import org.springframework.http.HttpStatus;
-
 
38
import org.springframework.http.ResponseEntity;
-
 
39
import org.springframework.mail.javamail.JavaMailSender;
-
 
40
import org.springframework.mail.javamail.MimeMessageHelper;
-
 
41
import org.springframework.stereotype.Controller;
-
 
42
import org.springframework.ui.Model;
-
 
43
import org.springframework.web.bind.annotation.PostMapping;
-
 
44
import org.springframework.web.bind.annotation.RequestBody;
-
 
45
import org.springframework.web.bind.annotation.RequestMapping;
-
 
46
import org.springframework.web.bind.annotation.RequestMethod;
-
 
47
import org.springframework.web.bind.annotation.RequestParam;
-
 
48
import org.springframework.web.bind.annotation.RequestPart;
-
 
49
import org.springframework.web.multipart.MultipartFile;
-
 
50
 
-
 
51
import com.spice.profitmandi.common.enumuration.MessageType;
3
import com.spice.profitmandi.common.enumuration.MessageType;
52
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
53
import com.spice.profitmandi.common.model.CustomRetailer;
5
import com.spice.profitmandi.common.model.CustomRetailer;
54
import com.spice.profitmandi.common.model.ProfitMandiConstants;
6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
55
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
7
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
56
import com.spice.profitmandi.common.util.ExcelUtils;
-
 
57
import com.spice.profitmandi.common.util.FileUtil;
8
import com.spice.profitmandi.common.util.*;
58
import com.spice.profitmandi.common.util.FormattingUtils;
-
 
59
import com.spice.profitmandi.common.util.StringUtils;
-
 
60
import com.spice.profitmandi.common.util.WalletHistoryModel;
-
 
61
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
9
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
62
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
10
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
63
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
-
 
64
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
-
 
65
import com.spice.profitmandi.dao.entity.transaction.UnsettledPayment;
-
 
66
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
11
import com.spice.profitmandi.dao.entity.transaction.*;
67
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
-
 
68
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
12
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
69
import com.spice.profitmandi.dao.enumuration.transaction.TransactionType;
13
import com.spice.profitmandi.dao.enumuration.transaction.TransactionType;
70
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
14
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
71
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
15
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
72
import com.spice.profitmandi.dao.repository.catalog.UnsettledPaymentsRepository;
16
import com.spice.profitmandi.dao.repository.catalog.UnsettledPaymentsRepository;
Line 83... Line 27...
83
import com.spice.profitmandi.service.user.RetailerService;
27
import com.spice.profitmandi.service.user.RetailerService;
84
import com.spice.profitmandi.service.wallet.WalletService;
28
import com.spice.profitmandi.service.wallet.WalletService;
85
import com.spice.profitmandi.web.model.LoginDetails;
29
import com.spice.profitmandi.web.model.LoginDetails;
86
import com.spice.profitmandi.web.util.CookiesProcessor;
30
import com.spice.profitmandi.web.util.CookiesProcessor;
87
import com.spice.profitmandi.web.util.MVCResponseSender;
31
import com.spice.profitmandi.web.util.MVCResponseSender;
88
 
-
 
89
import in.shop2020.model.v1.order.WalletReferenceType;
32
import in.shop2020.model.v1.order.WalletReferenceType;
-
 
33
import org.apache.logging.log4j.LogManager;
-
 
34
import org.apache.logging.log4j.Logger;
-
 
35
import org.apache.poi.ss.usermodel.Cell;
-
 
36
import org.apache.poi.ss.usermodel.CellStyle;
-
 
37
import org.apache.poi.ss.usermodel.CreationHelper;
-
 
38
import org.apache.poi.ss.usermodel.Sheet;
-
 
39
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-
 
40
import org.json.JSONObject;
-
 
41
import org.springframework.beans.factory.annotation.Autowired;
-
 
42
import org.springframework.core.io.InputStreamResource;
-
 
43
import org.springframework.http.HttpHeaders;
-
 
44
import org.springframework.http.HttpStatus;
-
 
45
import org.springframework.http.ResponseEntity;
-
 
46
import org.springframework.mail.javamail.JavaMailSender;
-
 
47
import org.springframework.mail.javamail.MimeMessageHelper;
-
 
48
import org.springframework.stereotype.Controller;
-
 
49
import org.springframework.ui.Model;
-
 
50
import org.springframework.web.bind.annotation.*;
-
 
51
import org.springframework.web.multipart.MultipartFile;
-
 
52
 
-
 
53
import javax.mail.internet.InternetAddress;
-
 
54
import javax.mail.internet.MimeMessage;
-
 
55
import javax.servlet.http.HttpServletRequest;
-
 
56
import javax.swing.*;
-
 
57
import javax.transaction.Transactional;
-
 
58
import java.io.ByteArrayInputStream;
-
 
59
import java.io.ByteArrayOutputStream;
-
 
60
import java.io.InputStream;
-
 
61
import java.text.MessageFormat;
-
 
62
import java.time.LocalDate;
-
 
63
import java.time.LocalDateTime;
-
 
64
import java.time.ZoneId;
-
 
65
import java.util.*;
-
 
66
import java.util.stream.Collectors;
90
 
67
 
91
@Controller
68
@Controller
92
@Transactional(rollbackOn = Throwable.class)
69
@Transactional(rollbackOn = Throwable.class)
93
public class WalletController {
70
public class WalletController {
94
 
71
 
Line 205... Line 182...
205
						walletHistoryModel.getWalletReferenceType(), walletHistoryModel.getDescription(),
182
						walletHistoryModel.getWalletReferenceType(), walletHistoryModel.getDescription(),
206
						(float) walletHistoryModel.getAmount(), walletHistoryModel.getBusinessDate());
183
						(float) walletHistoryModel.getAmount(), walletHistoryModel.getBusinessDate());
207
			}
184
			}
208
		}
185
		}
209
 
186
 
210
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
187
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
211
		return "response";
188
		return "response";
212
	}
189
	}
213
 
190
 
214
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
191
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
215
	public String dashboard(HttpServletRequest request,
192
	public String dashboard(HttpServletRequest request,
Line 494... Line 471...
494
					addWalletRequest.getCreateTimestamp());
471
					addWalletRequest.getCreateTimestamp());
495
			addWalletRequest.setStatus(AddWalletRequestStatus.approved);
472
			addWalletRequest.setStatus(AddWalletRequestStatus.approved);
496
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
473
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
497
			addWalletRequestRepository.persist(addWalletRequest);
474
			addWalletRequestRepository.persist(addWalletRequest);
498
			unsettledPaymentsRepository.deleteById(id);
475
			unsettledPaymentsRepository.deleteById(id);
499
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
476
			model.addAttribute("response1", mvcResponseSender.createResponseString(true));
500
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
477
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
501
			String subject = "Request Approved for " + customRetailer.getBusinessName() + " of Rs."
478
			String subject = "Request Approved for " + customRetailer.getBusinessName() + " of Rs."
502
					+ addWalletRequest.getAmount();
479
					+ addWalletRequest.getAmount();
503
			String messageText = MessageFormat.format(
480
			String messageText = MessageFormat.format(
504
					"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
481
					"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
Line 507... Line 484...
507
					addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
484
					addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
508
 
485
 
509
			this.sendMailWithAttachments(subject, messageText);
486
			this.sendMailWithAttachments(subject, messageText);
510
			return "response";
487
			return "response";
511
		} else {
488
		} else {
512
			model.addAttribute("response", mvcResponseSender.createResponseString(false));
489
			model.addAttribute("response1", mvcResponseSender.createResponseString(false));
513
			return "response";
490
			return "response";
514
		}
491
		}
515
	}
492
	}
516
 
493
 
517
	@RequestMapping(value = "/addAmountToWalletRequestRejected", method = RequestMethod.PUT)
494
	@RequestMapping(value = "/addAmountToWalletRequestRejected", method = RequestMethod.PUT)
Line 521... Line 498...
521
		AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
498
		AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
522
		if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
499
		if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
523
			addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
500
			addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
524
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
501
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
525
			addWalletRequestRepository.persist(addWalletRequest);
502
			addWalletRequestRepository.persist(addWalletRequest);
526
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
503
			model.addAttribute("response1", mvcResponseSender.createResponseString(true));
527
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
504
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
528
			String subject = "Request Rejected for " + customRetailer.getBusinessName() + " of Rs."
505
			String subject = "Request Rejected for " + customRetailer.getBusinessName() + " of Rs."
529
					+ addWalletRequest.getAmount();
506
					+ addWalletRequest.getAmount();
530
			String messageText = MessageFormat.format(
507
			String messageText = MessageFormat.format(
531
					"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
508
					"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
Line 534... Line 511...
534
					addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
511
					addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
535
 
512
 
536
			this.sendMailWithAttachments(subject, messageText);
513
			this.sendMailWithAttachments(subject, messageText);
537
			return "response";
514
			return "response";
538
		} else {
515
		} else {
539
			model.addAttribute("response", mvcResponseSender.createResponseString(false));
516
			model.addAttribute("response1", mvcResponseSender.createResponseString(false));
540
			return "response";
517
			return "response";
541
		}
518
		}
542
	}
519
	}
543
 
520
 
544
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
521
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
Line 629... Line 606...
629
		up.setAmount(unsettledPaymentModel.getAmount());
606
		up.setAmount(unsettledPaymentModel.getAmount());
630
		up.setDescription(unsettledPaymentModel.getDescription());
607
		up.setDescription(unsettledPaymentModel.getDescription());
631
		up.setReference_date(unsettledPaymentModel.getReferenceDate());
608
		up.setReference_date(unsettledPaymentModel.getReferenceDate());
632
		LOGGER.info("uppaynments" + up);
609
		LOGGER.info("uppaynments" + up);
633
		unsettledPaymentsRepository.persist(up);
610
		unsettledPaymentsRepository.persist(up);
634
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
611
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
635
		return "response";
612
		return "response";
636
	}
613
	}
637
 
614
 
638
	@RequestMapping(value = "/removeUnsettledPaymentsEntries", method = RequestMethod.DELETE)
615
	@RequestMapping(value = "/removeUnsettledPaymentsEntries", method = RequestMethod.DELETE)
639
	public String removeUnsettledPaymentsEntries(HttpServletRequest request,
616
	public String removeUnsettledPaymentsEntries(HttpServletRequest request,
640
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
617
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
641
 
618
 
642
		unsettledPaymentsRepository.deleteById(id);
619
		unsettledPaymentsRepository.deleteById(id);
643
 
620
 
644
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
621
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
645
		return "response";
622
		return "response";
646
	}
623
	}
647
 
624
 
648
	@RequestMapping(value = "/wallet/statement", method = RequestMethod.GET)
625
	@RequestMapping(value = "/wallet/statement", method = RequestMethod.GET)
649
	public String getWalletStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate,
626
	public String getWalletStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate,
Line 944... Line 921...
944
		model.addAttribute("userWallet", userWallet);
921
		model.addAttribute("userWallet", userWallet);
945
		model.addAttribute("customretailer", customretailer);
922
		model.addAttribute("customretailer", customretailer);
946
 
923
 
947
		model.addAttribute("wallethistory", userWalletHistory);
924
		model.addAttribute("wallethistory", userWalletHistory);
948
 
925
 
949
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
926
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
950
		return "wallet-history";
927
		return "wallet-history";
951
 
928
 
952
	}
929
	}
953
 
930
 
954
	@RequestMapping(value = "/getWalletHistoryByPartner", method = RequestMethod.GET)
931
	@RequestMapping(value = "/getWalletHistoryByPartner", method = RequestMethod.GET)
Line 966... Line 943...
966
 
943
 
967
		model.addAttribute("userWallet", userWallet);
944
		model.addAttribute("userWallet", userWallet);
968
		model.addAttribute("customretailer", customretailer);
945
		model.addAttribute("customretailer", customretailer);
969
		model.addAttribute("wallethistory", userWalletHistory);
946
		model.addAttribute("wallethistory", userWalletHistory);
970
 
947
 
971
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
948
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
972
		return "wallet-history";
949
		return "wallet-history";
973
 
950
 
974
	}
951
	}
975
 
952
 
976
	@RequestMapping(value = "/getPartnerName", method = RequestMethod.GET)
953
	@RequestMapping(value = "/getPartnerName", method = RequestMethod.GET)
Line 985... Line 962...
985
		}
962
		}
986
		UserWallet userWallet = userWalletRepository.selectById(userWalletHistory.get(0).getWalletId());
963
		UserWallet userWallet = userWalletRepository.selectById(userWalletHistory.get(0).getWalletId());
987
 
964
 
988
		CustomRetailer retailer = retailerService.getFofoRetailer(userWallet.getUserId());
965
		CustomRetailer retailer = retailerService.getFofoRetailer(userWallet.getUserId());
989
 
966
 
990
		model.addAttribute("response", mvcResponseSender.createResponseString(retailer));
967
		model.addAttribute("response1", mvcResponseSender.createResponseString(retailer));
991
 
968
 
992
		return "response";
969
		return "response";
993
 
970
 
994
	}
971
	}
995
 
972
 
996
	@RequestMapping(value = "/reset-wallet/9990381", method = RequestMethod.GET)
973
	@RequestMapping(value = "/reset-wallet/9990381", method = RequestMethod.GET)
997
	public String walletUpdate(Model model) throws Exception {
974
	public String walletUpdate(Model model) throws Exception {
998
		walletService.resetWallet();
975
		walletService.resetWallet();
999
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
976
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
1000
		return "response";
977
		return "response";
1001
	}
978
	}
1002
 
979
 
1003
	@RequestMapping(value = "/walletUpdate", method = RequestMethod.POST)
980
	@RequestMapping(value = "/walletUpdate", method = RequestMethod.POST)
1004
	public String walletUpdate(HttpServletRequest request,
981
	public String walletUpdate(HttpServletRequest request,
Line 1052... Line 1029...
1052
		newUserWalletHistory.setWalletId(userWallet.getId());
1029
		newUserWalletHistory.setWalletId(userWallet.getId());
1053
		newUserWalletHistory.setReferenceType(referenceType);
1030
		newUserWalletHistory.setReferenceType(referenceType);
1054
		newUserWalletHistory.setTimestamp(LocalDateTime.now());
1031
		newUserWalletHistory.setTimestamp(LocalDateTime.now());
1055
		userWalletHistoryRepository.persist(newUserWalletHistory);
1032
		userWalletHistoryRepository.persist(newUserWalletHistory);
1056
 
1033
 
1057
		model.addAttribute("response", mvcResponseSender.createResponseString(reference));
1034
		model.addAttribute("response1", mvcResponseSender.createResponseString(reference));
1058
		return "response";
1035
		return "response";
1059
 
1036
 
1060
	}
1037
	}
1061
 
1038
 
1062
	@RequestMapping(value = "/addMoney", method = RequestMethod.POST)
1039
	@RequestMapping(value = "/addMoney", method = RequestMethod.POST)
Line 1074... Line 1051...
1074
		addWalletRequest.setStatus(AddWalletRequestStatus.pending);
1051
		addWalletRequest.setStatus(AddWalletRequestStatus.pending);
1075
 
1052
 
1076
		LOGGER.info("info" + addWalletRequest);
1053
		LOGGER.info("info" + addWalletRequest);
1077
 
1054
 
1078
		addWalletRequestRepository.persist(addWalletRequest);
1055
		addWalletRequestRepository.persist(addWalletRequest);
1079
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1056
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
1080
		return "response";
1057
		return "response";
1081
	}
1058
	}
1082
 
1059
 
1083
	@RequestMapping(value = "/getCreditDetail", method = RequestMethod.GET)
1060
	@RequestMapping(value = "/getCreditDetail", method = RequestMethod.GET)
1084
	public String getCreditDetail(HttpServletRequest request, Model model) throws Exception {
1061
	public String getCreditDetail(HttpServletRequest request, Model model) throws Exception {