| Line 73... |
Line 73... |
| 73 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
73 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 74 |
import com.spice.profitmandi.dao.repository.transaction.StatementDetailModel;
|
74 |
import com.spice.profitmandi.dao.repository.transaction.StatementDetailModel;
|
| 75 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
75 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 76 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
76 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 77 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
77 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| - |
|
78 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 78 |
import com.spice.profitmandi.service.user.RetailerService;
|
79 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 79 |
import com.spice.profitmandi.service.wallet.WalletService;
|
80 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 80 |
import com.spice.profitmandi.web.model.LoginDetails;
|
81 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 81 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
82 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 82 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
83 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| Line 644... |
Line 645... |
| 644 |
model.addAttribute("startDate", startDate);
|
645 |
model.addAttribute("startDate", startDate);
|
| 645 |
model.addAttribute("endDate", endDate);
|
646 |
model.addAttribute("endDate", endDate);
|
| 646 |
return "walletStatement";
|
647 |
return "walletStatement";
|
| 647 |
}
|
648 |
}
|
| 648 |
|
649 |
|
| - |
|
650 |
@Autowired
|
| - |
|
651 |
TransactionService transactionService;
|
| - |
|
652 |
|
| - |
|
653 |
@RequestMapping(value = "/account/reco", method = RequestMethod.GET)
|
| - |
|
654 |
public ResponseEntity<?> accountReco(HttpServletRequest request, @RequestParam LocalDate closingDate,
|
| - |
|
655 |
Model model) throws Exception {
|
| - |
|
656 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
| - |
|
657 |
if (!isAdmin) {
|
| - |
|
658 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
| - |
|
659 |
}
|
| - |
|
660 |
LocalDateTime closingDateTime = LocalDate.now().atStartOfDay().plusDays(1);
|
| - |
|
661 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| - |
|
662 |
Set<Integer> retailersSet = customRetailerMap.keySet();
|
| - |
|
663 |
|
| - |
|
664 |
Map<Integer, Float> closingPurchaseMap = orderRepository.selectOpeningAmount(closingDateTime, retailersSet);
|
| - |
|
665 |
|
| - |
|
666 |
|
| - |
|
667 |
Map<Integer, UserWallet> retailerWalletMap = walletService.getRetailerIdUserWalletMap(retailersSet);
|
| - |
|
668 |
Map<Integer, Integer> walletRetailerMap = retailerWalletMap.entrySet().stream().collect(Collectors.toMap(x->x.getValue().getId(), x->x.getKey()));
|
| - |
|
669 |
|
| - |
|
670 |
Set<Integer> walletSet = walletRetailerMap.keySet();
|
| - |
|
671 |
Map<Integer, Float> closingBalanceMap = userWalletHistoryRepository.getSumTillDateExcludingPurchase(closingDateTime, walletSet);
|
| - |
|
672 |
Map<Integer, Float> closingWalletMap = userWalletHistoryRepository.getSumTillDate(closingDateTime, walletSet);
|
| - |
|
673 |
Map<Integer, Float> inTransitStock = transactionService.getIntransitStockValue();
|
| - |
|
674 |
|
| - |
|
675 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
676 |
for (Map.Entry<Integer, Float> closingBalance : closingBalanceMap.entrySet()) {
|
| - |
|
677 |
int walletId = closingBalance.getKey();
|
| - |
|
678 |
int retailerId = walletRetailerMap.get(walletId);
|
| - |
|
679 |
|
| - |
|
680 |
float accountClosing = 0f;
|
| - |
|
681 |
if (!closingPurchaseMap.containsKey(retailerId)) {
|
| - |
|
682 |
accountClosing = closingBalance.getValue();
|
| - |
|
683 |
} else {
|
| - |
|
684 |
accountClosing = closingBalance.getValue() - closingPurchaseMap.get(retailerId);
|
| - |
|
685 |
}
|
| - |
|
686 |
|
| - |
|
687 |
CustomRetailer cr = customRetailerMap.get(retailerId);
|
| - |
|
688 |
|
| - |
|
689 |
rows.add(Arrays.asList(retailerId, cr.getBusinessName(), cr.getAddress().getCity(),
|
| - |
|
690 |
cr.getAddress().getState(), accountClosing, closingWalletMap.get(retailerId), inTransitStock.get(retailerId)));
|
| - |
|
691 |
}
|
| - |
|
692 |
|
| - |
|
693 |
|
| - |
|
694 |
org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = FileUtil
|
| - |
|
695 |
.getCSVByteStream(Arrays.asList("Id", "Partner Name", "City", "State", "Closing Balance", "Closing Wallet", "In Transit"), rows);
|
| - |
|
696 |
final HttpHeaders headers = new HttpHeaders();
|
| - |
|
697 |
headers.set("Content-Type", "text/csv");
|
| - |
|
698 |
headers.set("Content-disposition",
|
| - |
|
699 |
"inline; filename=account-statement-closing-." + StringUtils.toHyphenatedString(closingDate) + ".csv");
|
| - |
|
700 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
| - |
|
701 |
|
| - |
|
702 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
| - |
|
703 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| - |
|
704 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| - |
|
705 |
}
|
| - |
|
706 |
|
| - |
|
707 |
|
| 649 |
@RequestMapping(value = "/account/closing-statements", method = RequestMethod.GET)
|
708 |
@RequestMapping(value = "/account/closing-statements", method = RequestMethod.GET)
|
| 650 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDate closingDate,
|
709 |
public ResponseEntity<?> getAccountStatement(HttpServletRequest request, @RequestParam LocalDate closingDate,
|
| 651 |
Model model) throws Exception {
|
710 |
Model model) throws Exception {
|
| 652 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
711 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
| 653 |
if (!isAdmin) {
|
712 |
if (!isAdmin) {
|