| Line 8... |
Line 8... |
| 8 |
import com.spice.profitmandi.common.util.FileUtil;
|
8 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 9 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
9 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 10 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
10 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 11 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
11 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 12 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
|
12 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
|
| - |
|
13 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| - |
|
14 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 13 |
import com.spice.profitmandi.dao.model.*;
|
15 |
import com.spice.profitmandi.dao.model.*;
|
| 14 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
16 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 15 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
17 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 16 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
18 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 17 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
19 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 18 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
20 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 19 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
21 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
| 20 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
|
22 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
|
| 21 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
23 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| - |
|
24 |
import com.spice.profitmandi.dao.repository.transaction.StatementDetailModel;
|
| - |
|
25 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 22 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
26 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23 |
import com.spice.profitmandi.service.order.OrderService;
|
27 |
import com.spice.profitmandi.service.order.OrderService;
|
| - |
|
28 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 24 |
import com.spice.profitmandi.service.user.RetailerService;
|
29 |
import com.spice.profitmandi.service.user.RetailerService;
|
| - |
|
30 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 25 |
import com.spice.profitmandi.web.model.LoginDetails;
|
31 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 26 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
32 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| - |
|
33 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 27 |
import org.apache.http.HttpResponse;
|
34 |
import org.apache.http.HttpResponse;
|
| 28 |
import org.apache.logging.log4j.LogManager;
|
35 |
import org.apache.logging.log4j.LogManager;
|
| 29 |
import org.apache.logging.log4j.Logger;
|
36 |
import org.apache.logging.log4j.Logger;
|
| 30 |
import org.springframework.beans.factory.annotation.Autowired;
|
37 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 31 |
import org.springframework.core.io.InputStreamResource;
|
38 |
import org.springframework.core.io.InputStreamResource;
|
| Line 75... |
Line 82... |
| 75 |
private OrderService orderService;
|
82 |
private OrderService orderService;
|
| 76 |
@Autowired
|
83 |
@Autowired
|
| 77 |
private CsService csService;
|
84 |
private CsService csService;
|
| 78 |
@Autowired
|
85 |
@Autowired
|
| 79 |
private AuthRepository authRepository;
|
86 |
private AuthRepository authRepository;
|
| - |
|
87 |
@Autowired
|
| - |
|
88 |
private WalletService walletService;
|
| - |
|
89 |
@Autowired
|
| - |
|
90 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| - |
|
91 |
@Autowired
|
| - |
|
92 |
private TransactionService transactionService;
|
| 80 |
|
93 |
|
| 81 |
@PostMapping(value = "/reports/{projectName}/{fileName}")
|
94 |
@PostMapping(value = "/reports/{projectName}/{fileName}")
|
| 82 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
95 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 83 |
@PathVariable ReporticoProject projectName, @RequestBody Map<String, String> paramsMap)
|
96 |
@PathVariable ReporticoProject projectName, @RequestBody Map<String, String> paramsMap)
|
| 84 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
97 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| Line 1040... |
Line 1053... |
| 1040 |
returnMap = returnMap1;
|
1053 |
returnMap = returnMap1;
|
| 1041 |
}*/
|
1054 |
}*/
|
| 1042 |
model.addAttribute("reporticoProjectMap", returnMap);
|
1055 |
model.addAttribute("reporticoProjectMap", returnMap);
|
| 1043 |
return "reports";
|
1056 |
return "reports";
|
| 1044 |
}
|
1057 |
}
|
| - |
|
1058 |
|
| - |
|
1059 |
@RequestMapping(value = "/account-statement", method = RequestMethod.GET)
|
| - |
|
1060 |
public String accountStatement(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
|
| - |
|
1061 |
@RequestParam(required = false) LocalDate startDate,
|
| - |
|
1062 |
@RequestParam(required = false) LocalDate endDate)
|
| - |
|
1063 |
throws Exception {
|
| - |
|
1064 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
1065 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| - |
|
1066 |
|
| - |
|
1067 |
model.addAttribute("isAdmin", isAdmin);
|
| - |
|
1068 |
|
| - |
|
1069 |
return "partner-account-statement";
|
| - |
|
1070 |
|
| - |
|
1071 |
}
|
| - |
|
1072 |
|
| - |
|
1073 |
@RequestMapping(value = "/account-statement-report", method = RequestMethod.GET)
|
| - |
|
1074 |
public String getPartnerAccountStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId) throws Exception {
|
| - |
|
1075 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
| - |
|
1076 |
if (fofoId > 0) {
|
| - |
|
1077 |
if (!isAdmin) {
|
| - |
|
1078 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
| - |
|
1079 |
}
|
| - |
|
1080 |
} else {
|
| - |
|
1081 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
| - |
|
1082 |
}
|
| - |
|
1083 |
float openingBalance = walletService.getOpeningTill(fofoId, startDate);
|
| - |
|
1084 |
float closingBalance = walletService.getOpeningTill(fofoId, endDate);
|
| - |
|
1085 |
UserWallet uw = walletService.getUserWallet(fofoId);
|
| - |
|
1086 |
LOGGER.info("Start date - {}, end Date - {}", startDate, endDate);
|
| - |
|
1087 |
|
| - |
|
1088 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectPaginatedByWalletId(uw.getId(), startDate, endDate, 0, 0);
|
| - |
|
1089 |
|
| - |
|
1090 |
history = history.stream().filter(x -> !x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
| - |
|
1091 |
.filter(x -> !WalletService.CN_WALLET_REFERENCES.contains(x.getReferenceType())).sorted(Comparator.comparing(UserWalletHistory::getId)).collect(Collectors.toList());
|
| - |
|
1092 |
Map<LocalDate, List<UserWalletHistory>> dateWalletMap = history.stream().collect(Collectors.groupingBy(x -> x.getTimestamp().toLocalDate()));
|
| - |
|
1093 |
CustomRetailer customRetailer = retailerService.getAllFofoRetailers().get(fofoId);
|
| - |
|
1094 |
List<StatementDetailModel> billedStatementDetails = orderRepository.selectDetailsBetween(fofoId, startDate, endDate);
|
| - |
|
1095 |
Map<Integer, Float> openingAmountMap = transactionService.getPendingIndentValueMap(startDate, Optional.of(fofoId));
|
| - |
|
1096 |
Map<Integer, Float> closingAmountMap = transactionService.getPendingIndentValueMap(endDate, Optional.of(fofoId));
|
| - |
|
1097 |
|
| - |
|
1098 |
float openingPendingAmount = openingAmountMap.get(fofoId) == null ? 0 : openingAmountMap.get(fofoId);
|
| - |
|
1099 |
float closingPendingAmount = closingAmountMap.get(fofoId) == null ? 0 : closingAmountMap.get(fofoId);
|
| - |
|
1100 |
LOGGER.info("Opening - {}, Closing - {}", openingPendingAmount, closingPendingAmount);
|
| - |
|
1101 |
|
| - |
|
1102 |
double grandTotalDebit = 0;
|
| - |
|
1103 |
double grandTotalCredit = 0;
|
| - |
|
1104 |
|
| - |
|
1105 |
for (UserWalletHistory walletEntry : history) {
|
| - |
|
1106 |
if (walletEntry.getAmount() < 0) {
|
| - |
|
1107 |
grandTotalDebit += Math.abs(walletEntry.getAmount());
|
| - |
|
1108 |
} else {
|
| - |
|
1109 |
grandTotalCredit += walletEntry.getAmount();
|
| - |
|
1110 |
}
|
| - |
|
1111 |
}
|
| - |
|
1112 |
|
| - |
|
1113 |
for (StatementDetailModel statement : billedStatementDetails) {
|
| - |
|
1114 |
if (statement.getAmount() < 0) {
|
| - |
|
1115 |
grandTotalCredit += Math.abs(statement.getAmount());
|
| - |
|
1116 |
} else {
|
| - |
|
1117 |
grandTotalDebit += statement.getAmount();
|
| - |
|
1118 |
}
|
| - |
|
1119 |
}
|
| - |
|
1120 |
|
| - |
|
1121 |
model.addAttribute("billedStatementDetails", billedStatementDetails);
|
| - |
|
1122 |
model.addAttribute("customRetailer", customRetailer);
|
| - |
|
1123 |
model.addAttribute("wallethistory", history);
|
| - |
|
1124 |
model.addAttribute("startDate", startDate);
|
| - |
|
1125 |
model.addAttribute("endDate", endDate);
|
| - |
|
1126 |
model.addAttribute("dateWalletMap", dateWalletMap);
|
| - |
|
1127 |
model.addAttribute("openingBalance", (openingBalance + openingPendingAmount));
|
| - |
|
1128 |
model.addAttribute("closingBalance", (closingBalance + closingPendingAmount));
|
| - |
|
1129 |
model.addAttribute("grandTotalDebit", grandTotalDebit);
|
| - |
|
1130 |
model.addAttribute("grandTotalCredit", grandTotalCredit);
|
| - |
|
1131 |
|
| - |
|
1132 |
return "account-statement-list";
|
| - |
|
1133 |
}
|
| 1045 |
}
|
1134 |
}
|