Search in sources :

Example 1 with IzlyPayForm

use of org.esupportail.papercut.domain.IzlyPayForm in project esup-papercut by EsupPortail.

the class UserController method userView.

@GetMapping(produces = "text/html")
public String userView(HttpServletRequest request, Model uiModel) {
    EsupPapercutContext context = config.getContext(ContextHelper.getCurrentContext());
    if (context == null) {
        return "redirect:/";
    }
    double papercutSheetCost = context.getPapercutSheetCost();
    double papercutColorSheetCost = context.getPapercutColorSheetCost();
    String uid = getUid();
    String userMail = getUserMail();
    // check if the user can make a transaction
    int transactionNbMax = context.getTransactionNbMax();
    int transactionMontantMax = context.getTransactionMontantMax();
    boolean canMakeTransaction = true;
    // constraints via transactionNbMax
    if (transactionNbMax > -1) {
        long nbTransactionsNotArchived = papercutDaoService.countByUidAndArchived(uid, false);
        if (transactionNbMax <= nbTransactionsNotArchived) {
            canMakeTransaction = false;
        }
    }
    Integer montantMin = context.getMontantMin();
    Integer montantMax = context.getMontantMax();
    Integer montantStep = context.getMontantStep();
    // constraints via transactionMontantMax
    if (canMakeTransaction && transactionMontantMax > -1) {
        Page<PayPapercutTransactionLog> transactionsNotArchived = papercutDaoService.findPayPapercutTransactionLogsByUidAndArchived(uid, false, PageRequest.of(0, Integer.MAX_VALUE));
        Integer montantTotalTransactionsNotArchived = 0;
        for (PayPapercutTransactionLog txLog : transactionsNotArchived.getContent()) {
            montantTotalTransactionsNotArchived = montantTotalTransactionsNotArchived + txLog.getMontant();
        }
        transactionMontantMax = transactionMontantMax - montantTotalTransactionsNotArchived;
        if (transactionMontantMax < montantMax) {
            montantMax = transactionMontantMax;
            if (montantMax.compareTo(montantMin) == -1) {
                canMakeTransaction = false;
            }
            uiModel.addAttribute("payboxMontantMax", montantMax.doubleValue());
        }
    }
    // generation de l'ensemble des payboxForm :  payboxMontantMin -> payboxMontantMax par pas de payboxMontantStep
    String contextPath = request.getContextPath();
    if (esupPaperCutService.getPayModes(context).contains(PayMode.PAYBOX)) {
        Map<Integer, PayBoxForm> payboxForms = new TreeMap<Integer, PayBoxForm>();
        for (Integer montant = montantMin; montant.compareTo(montantMax) <= 0; montant = montant + montantStep) {
            PayBoxForm payBoxForm = esupPaperCutService.getPayBoxForm(context, uid, userMail, montant, contextPath);
            payBoxForm.setToolTip(getToolTipMessage(payBoxForm.getMontant(), montant, papercutSheetCost, papercutColorSheetCost));
            payboxForms.put(montant, payBoxForm);
        }
        uiModel.addAttribute("payboxLegend", context.getPaybox().getLegend());
        uiModel.addAttribute("payboxForms", payboxForms);
    }
    if (esupPaperCutService.getPayModes(context).contains(PayMode.IZLYPAY)) {
        Map<Integer, IzlyPayForm> izlypayForms = new TreeMap<Integer, IzlyPayForm>();
        for (Integer montant = montantMin; montant.compareTo(montantMax) <= 0; montant = montant + montantStep) {
            IzlyPayForm izlypayForm = new IzlyPayForm();
            izlypayForm.setMontant(new Double(new Double(montant) / 100.0).toString());
            izlypayForm.setToolTip(getToolTipMessage(izlypayForm.getMontant(), montant, papercutSheetCost, papercutColorSheetCost));
            izlypayForms.put(montant, izlypayForm);
        }
        uiModel.addAttribute("izlypayLegend", context.getIzlypay().getLegend());
        uiModel.addAttribute("izlypayForms", izlypayForms);
    }
    if (esupPaperCutService.getPayModes(context).contains(PayMode.PAYBOX) || esupPaperCutService.getPayModes(context).contains(PayMode.IZLYPAY)) {
        uiModel.addAttribute("tipMessage4MontantMin", getToolTipMessage(new Double(new Double(montantMin) / 100.0).toString(), montantMin, papercutSheetCost, papercutColorSheetCost));
    }
    uiModel.addAttribute("canMakeTransaction", canMakeTransaction);
    UserPapercutInfos userPapercutInfos = esupPaperCutService.getUserPapercutInfos(context, uid);
    uiModel.addAttribute("userPapercutInfos", userPapercutInfos);
    uiModel.addAttribute("isAdmin", WebUtils.isAdmin());
    uiModel.addAttribute("isManager", WebUtils.isManager());
    uiModel.addAttribute("active", "home");
    uiModel.addAttribute("papercutContext", context);
    return "index";
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) IzlyPayForm(org.esupportail.papercut.domain.IzlyPayForm) TreeMap(java.util.TreeMap) PayBoxForm(org.esupportail.papercut.domain.PayBoxForm) UserPapercutInfos(org.esupportail.papercut.domain.UserPapercutInfos) EsupPapercutContext(org.esupportail.papercut.config.EsupPapercutContext) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

TreeMap (java.util.TreeMap)1 EsupPapercutContext (org.esupportail.papercut.config.EsupPapercutContext)1 IzlyPayForm (org.esupportail.papercut.domain.IzlyPayForm)1 PayBoxForm (org.esupportail.papercut.domain.PayBoxForm)1 PayPapercutTransactionLog (org.esupportail.papercut.domain.PayPapercutTransactionLog)1 UserPapercutInfos (org.esupportail.papercut.domain.UserPapercutInfos)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1