| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
3 |
import java.io.ByteArrayInputStream;
|
| 4 |
import java.io.ByteArrayOutputStream;
|
4 |
import java.io.ByteArrayOutputStream;
|
| 5 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| 6 |
import java.text.MessageFormat;
|
6 |
import java.text.MessageFormat;
|
| - |
|
7 |
import java.time.LocalDate;
|
| 7 |
import java.time.LocalDateTime;
|
8 |
import java.time.LocalDateTime;
|
| 8 |
import java.time.ZoneId;
|
9 |
import java.time.ZoneId;
|
| 9 |
import java.util.ArrayList;
|
10 |
import java.util.ArrayList;
|
| - |
|
11 |
import java.util.Arrays;
|
| 10 |
import java.util.Collections;
|
12 |
import java.util.Collections;
|
| 11 |
import java.util.Date;
|
13 |
import java.util.Date;
|
| 12 |
import java.util.HashMap;
|
14 |
import java.util.HashMap;
|
| 13 |
import java.util.List;
|
15 |
import java.util.List;
|
| 14 |
import java.util.Map;
|
16 |
import java.util.Map;
|
| - |
|
17 |
import java.util.Set;
|
| 15 |
import java.util.stream.Collectors;
|
18 |
import java.util.stream.Collectors;
|
| 16 |
|
19 |
|
| 17 |
import javax.mail.internet.InternetAddress;
|
20 |
import javax.mail.internet.InternetAddress;
|
| 18 |
import javax.mail.internet.MimeMessage;
|
21 |
import javax.mail.internet.MimeMessage;
|
| 19 |
import javax.servlet.http.HttpServletRequest;
|
22 |
import javax.servlet.http.HttpServletRequest;
|
| Line 48... |
Line 51... |
| 48 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
51 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 49 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
52 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 50 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
53 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 51 |
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
|
54 |
import com.spice.profitmandi.common.model.UnsettledPaymentModel;
|
| 52 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
55 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| - |
|
56 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 53 |
import com.spice.profitmandi.common.util.StringUtils;
|
57 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 54 |
import com.spice.profitmandi.common.util.WalletHistoryModel;
|
58 |
import com.spice.profitmandi.common.util.WalletHistoryModel;
|
| 55 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
59 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
| 56 |
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
|
60 |
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
|
| 57 |
import com.spice.profitmandi.dao.entity.transaction.UnsettledPayment;
|
61 |
import com.spice.profitmandi.dao.entity.transaction.UnsettledPayment;
|
| 58 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
62 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 59 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
63 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 60 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
64 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
| 61 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionType;
|
65 |
import com.spice.profitmandi.dao.enumuration.transaction.TransactionType;
|
| 62 |
import com.spice.profitmandi.dao.model.AccountStatementModel;
|
- |
|
| 63 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
66 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 64 |
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
|
67 |
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
|
| 65 |
import com.spice.profitmandi.dao.repository.catalog.UnsettledPaymentsRepository;
|
68 |
import com.spice.profitmandi.dao.repository.catalog.UnsettledPaymentsRepository;
|
| 66 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
69 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 67 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
70 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| Line 641... |
Line 644... |
| 641 |
model.addAttribute("startDate", startDate);
|
644 |
model.addAttribute("startDate", startDate);
|
| 642 |
model.addAttribute("endDate", endDate);
|
645 |
model.addAttribute("endDate", endDate);
|
| 643 |
return "walletStatement";
|
646 |
return "walletStatement";
|
| 644 |
}
|
647 |
}
|
| 645 |
|
648 |
|
| - |
|
649 |
@RequestMapping(value = "/account/closing-statements", method = RequestMethod.GET)
|
| - |
|
650 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDate closingDate,
|
| - |
|
651 |
Model model) throws Exception {
|
| - |
|
652 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
| - |
|
653 |
if (!isAdmin) {
|
| - |
|
654 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
| - |
|
655 |
}
|
| - |
|
656 |
LocalDateTime closingDateTime = closingDate.atStartOfDay().plusDays(1);
|
| - |
|
657 |
|
| - |
|
658 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| - |
|
659 |
Set<Integer> retailersSet = customRetailerMap.keySet();
|
| - |
|
660 |
|
| - |
|
661 |
Map<Integer, Float> closingPurchaseMap = orderRepository.selectOpeningAmount(closingDateTime, retailersSet);
|
| - |
|
662 |
|
| - |
|
663 |
|
| - |
|
664 |
Map<Integer, UserWallet> retailerWalletMap = walletService.getRetailerIdUserWalletMap(retailersSet);
|
| - |
|
665 |
Map<Integer, Integer> walletRetailerMap = retailerWalletMap.entrySet().stream().collect(Collectors.toMap(x->x.getValue().getId(), x->x.getKey()));
|
| - |
|
666 |
|
| - |
|
667 |
Set<Integer> walletSet = walletRetailerMap.keySet();
|
| - |
|
668 |
Map<Integer, Float> closingBalanceMap = userWalletHistoryRepository.getSumTillDateExcludingPurchase(closingDateTime, walletSet);
|
| - |
|
669 |
|
| - |
|
670 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
671 |
for (Map.Entry<Integer, Float> closingWalletBalance : closingBalanceMap.entrySet()) {
|
| - |
|
672 |
int walletId = closingWalletBalance.getKey();
|
| - |
|
673 |
int retailerId = walletRetailerMap.get(walletId);
|
| - |
|
674 |
if (!closingPurchaseMap.containsKey(retailerId)) {
|
| - |
|
675 |
closingPurchaseMap.put(retailerId, closingWalletBalance.getValue());
|
| - |
|
676 |
} else {
|
| - |
|
677 |
closingPurchaseMap.put(retailerId,
|
| - |
|
678 |
closingWalletBalance.getValue() - closingPurchaseMap.get(retailerId));
|
| - |
|
679 |
}
|
| - |
|
680 |
float closingValue = closingPurchaseMap.get(retailerId);
|
| - |
|
681 |
CustomRetailer cr = customRetailerMap.get(retailerId);
|
| - |
|
682 |
|
| - |
|
683 |
rows.add(Arrays.asList(retailerId, cr.getBusinessName(), cr.getAddress().getCity(),
|
| - |
|
684 |
cr.getAddress().getState(), closingValue));
|
| - |
|
685 |
}
|
| - |
|
686 |
|
| - |
|
687 |
org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = FileUtil
|
| - |
|
688 |
.getCSVByteStream(Arrays.asList("Id", "Partner Name", "City", "State", "Closing Balance"), rows);
|
| - |
|
689 |
final HttpHeaders headers = new HttpHeaders();
|
| - |
|
690 |
headers.set("Content-Type", "text/csv");
|
| - |
|
691 |
headers.set("Content-disposition",
|
| - |
|
692 |
"inline; filename=account-statement-closing-." + StringUtils.toHyphenatedString(closingDate) + ".csv");
|
| - |
|
693 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
| - |
|
694 |
|
| - |
|
695 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
| - |
|
696 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| - |
|
697 |
|
| - |
|
698 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| - |
|
699 |
|
| - |
|
700 |
}
|
| - |
|
701 |
|
| 646 |
@RequestMapping(value = "/account/statement", method = RequestMethod.GET)
|
702 |
@RequestMapping(value = "/account/statement", method = RequestMethod.GET)
|
| 647 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate,
|
703 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate,
|
| 648 |
@RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId)
|
704 |
@RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId)
|
| 649 |
throws Exception {
|
705 |
throws Exception {
|
| 650 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
706 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
| Line 656... |
Line 712... |
| 656 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
712 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
| 657 |
}
|
713 |
}
|
| 658 |
float openingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, startDate);
|
714 |
float openingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, startDate);
|
| 659 |
float closingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, endDate);
|
715 |
float closingBalance = walletService.getOpeningTillExcludingPurchase(fofoId, endDate);
|
| 660 |
UserWallet uw = walletService.getUserWallet(fofoId);
|
716 |
UserWallet uw = walletService.getUserWallet(fofoId);
|
| 661 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectPaginatedByWalletId(uw.getId(), startDate, endDate, 0, 0);
|
717 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectPaginatedByWalletId(uw.getId(), startDate,
|
| - |
|
718 |
endDate, 0, 0);
|
| 662 |
history = history.stream().filter(x -> !x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
719 |
history = history.stream().filter(x -> !x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
| 663 |
.collect(Collectors.toList());
|
720 |
.collect(Collectors.toList());
|
| 664 |
InputStream is = getClass().getClassLoader().getResourceAsStream("account-statement.xlsx");
|
721 |
InputStream is = getClass().getClassLoader().getResourceAsStream("account-statement.xlsx");
|
| 665 |
String partnerName = retailerService.getAllFofoRetailerIdNameMap().get(fofoId);
|
722 |
String partnerName = retailerService.getAllFofoRetailerIdNameMap().get(fofoId);
|
| 666 |
List<StatementDetailModel> details = orderRepository.selectDetailsBetween(fofoId, startDate, endDate);
|
723 |
List<StatementDetailModel> details = orderRepository.selectDetailsBetween(fofoId, startDate, endDate);
|
| Line 683... |
Line 740... |
| 683 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
740 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 684 |
|
741 |
|
| 685 |
}
|
742 |
}
|
| 686 |
|
743 |
|
| 687 |
private ByteArrayOutputStream populateData(InputStream is, float openingBalance, float closingBalance,
|
744 |
private ByteArrayOutputStream populateData(InputStream is, float openingBalance, float closingBalance,
|
| 688 |
String partnerName, List<UserWalletHistory> history, LocalDateTime startDate,
|
745 |
String partnerName, List<UserWalletHistory> history, LocalDateTime startDate, LocalDateTime endDate,
|
| 689 |
LocalDateTime endDate, List<StatementDetailModel> invoiceDetails) throws Exception {
|
746 |
List<StatementDetailModel> invoiceDetails) throws Exception {
|
| 690 |
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
747 |
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
| 691 |
CreationHelper creationHelper = workbook.getCreationHelper();
|
748 |
CreationHelper creationHelper = workbook.getCreationHelper();
|
| 692 |
CellStyle style2 = workbook.createCellStyle();
|
749 |
CellStyle style2 = workbook.createCellStyle();
|
| 693 |
style2.setDataFormat(creationHelper.createDataFormat().getFormat(
|
750 |
style2.setDataFormat(creationHelper.createDataFormat().getFormat("mm/dd/yyyy hh:mm:ss"));
|
| 694 |
"mm/dd/yyyy hh:mm:ss"));
|
- |
|
| 695 |
|
751 |
|
| 696 |
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
752 |
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
| 697 |
Sheet sheet = workbook.getSheetAt(0);
|
753 |
Sheet sheet = workbook.getSheetAt(0);
|
| 698 |
sheet.getRow(0).getCell(0).setCellValue(partnerName);
|
754 |
sheet.getRow(0).getCell(0).setCellValue(partnerName);
|
| 699 |
sheet.getRow(1).getCell(1)
|
755 |
sheet.getRow(1).getCell(1)
|
| 700 |
.setCellValue(new Date(startDate.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
|
756 |
.setCellValue(new Date(startDate.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
|
| Line 704... |
Line 760... |
| 704 |
long grandTotalDebit = 0l;
|
760 |
long grandTotalDebit = 0l;
|
| 705 |
long grandTotalCredit = 0l;
|
761 |
long grandTotalCredit = 0l;
|
| 706 |
int row = 4;
|
762 |
int row = 4;
|
| 707 |
for (UserWalletHistory walletEntry : history) {
|
763 |
for (UserWalletHistory walletEntry : history) {
|
| 708 |
Cell dateCell = sheet.createRow(row).createCell(0);
|
764 |
Cell dateCell = sheet.createRow(row).createCell(0);
|
| - |
|
765 |
dateCell.setCellValue(
|
| 709 |
dateCell.setCellValue(new Date(walletEntry.getTimestamp().atZone( ZoneId.systemDefault()).toInstant().toEpochMilli()));
|
766 |
new Date(walletEntry.getTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
|
| 710 |
dateCell.setCellStyle(style2);
|
767 |
dateCell.setCellStyle(style2);
|
| 711 |
sheet.getRow(row).createCell(1).setCellValue(walletEntry.getReferenceType().toString());
|
768 |
sheet.getRow(row).createCell(1).setCellValue(walletEntry.getReferenceType().toString());
|
| 712 |
if(walletEntry.getAmount() > 0) {
|
769 |
if (walletEntry.getAmount() > 0) {
|
| 713 |
sheet.getRow(row).createCell(2).setCellValue(0);
|
770 |
sheet.getRow(row).createCell(2).setCellValue(0);
|
| 714 |
sheet.getRow(row).createCell(3).setCellValue(walletEntry.getAmount());
|
771 |
sheet.getRow(row).createCell(3).setCellValue(walletEntry.getAmount());
|
| 715 |
grandTotalCredit += walletEntry.getAmount();
|
772 |
grandTotalCredit += walletEntry.getAmount();
|
| 716 |
} else {
|
773 |
} else {
|
| 717 |
sheet.getRow(row).createCell(2).setCellValue(walletEntry.getAmount());
|
774 |
sheet.getRow(row).createCell(2).setCellValue(walletEntry.getAmount());
|
| Line 728... |
Line 785... |
| 728 |
dateCell.setCellStyle(style2);
|
785 |
dateCell.setCellStyle(style2);
|
| 729 |
sheet.getRow(row).createCell(1).setCellValue("BILLING");
|
786 |
sheet.getRow(row).createCell(1).setCellValue("BILLING");
|
| 730 |
if (statementDetailModel.getAmount() > 0) {
|
787 |
if (statementDetailModel.getAmount() > 0) {
|
| 731 |
sheet.getRow(row).createCell(2).setCellValue(statementDetailModel.getAmount());
|
788 |
sheet.getRow(row).createCell(2).setCellValue(statementDetailModel.getAmount());
|
| 732 |
sheet.getRow(row).createCell(3).setCellValue(0);
|
789 |
sheet.getRow(row).createCell(3).setCellValue(0);
|
| 733 |
grandTotalDebit += statementDetailModel.getAmount();
|
790 |
grandTotalDebit += statementDetailModel.getAmount();
|
| 734 |
} else {
|
791 |
} else {
|
| 735 |
sheet.getRow(row).createCell(2).setCellValue(0);
|
792 |
sheet.getRow(row).createCell(2).setCellValue(0);
|
| 736 |
sheet.getRow(row).createCell(3).setCellValue(-statementDetailModel.getAmount());
|
793 |
sheet.getRow(row).createCell(3).setCellValue(-statementDetailModel.getAmount());
|
| 737 |
grandTotalCredit += -statementDetailModel.getAmount();
|
794 |
grandTotalCredit += -statementDetailModel.getAmount();
|
| 738 |
}
|
795 |
}
|
| 739 |
|
796 |
|
| 740 |
sheet.getRow(row).createCell(4).setCellValue(statementDetailModel.getReferenceType());
|
797 |
sheet.getRow(row).createCell(4).setCellValue(statementDetailModel.getReferenceType());
|
| 741 |
sheet.getRow(row).createCell(5).setCellValue(statementDetailModel.getInvoiceNumber());
|
798 |
sheet.getRow(row).createCell(5).setCellValue(statementDetailModel.getInvoiceNumber());
|
| 742 |
|
- |
|
| 743 |
|
799 |
|
| 744 |
row += 1;
|
800 |
row += 1;
|
| 745 |
}
|
801 |
}
|
| 746 |
sheet.createRow(row).createCell(0).setCellValue("Grand Total");
|
802 |
sheet.createRow(row).createCell(0).setCellValue("Grand Total");
|
| 747 |
sheet.getRow(row).createCell(1).setCellValue(grandTotalDebit);
|
803 |
sheet.getRow(row).createCell(1).setCellValue(grandTotalDebit);
|