Search in sources :

Example 1 with PayPapercutTransactionLog

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

the class PapercutDaoService method remove.

@Transactional
public void remove(PayPapercutTransactionLog txLog) {
    if (entityManager.contains(txLog)) {
        entityManager.remove(txLog);
    } else {
        PayPapercutTransactionLog attached = txRepository.findById(txLog.getId()).get();
        entityManager.remove(attached);
    }
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PayPapercutTransactionLog

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

the class PapercutDaoService method merge.

@Transactional
public PayPapercutTransactionLog merge(PayPapercutTransactionLog txLog) {
    PayPapercutTransactionLog merged = entityManager.merge(txLog);
    entityManager.flush();
    return merged;
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PayPapercutTransactionLog

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

the class EsupPaperCutService method izlypayCallback.

public boolean izlypayCallback(EsupPapercutContext context, IzlyPayCallBack izlyPayCallBack) {
    String reference = izlyPayCallBack.getOperationSMoney().getClientOrderId();
    String idtrans = reference;
    Integer montant = izlyPayCallBack.getOperationSMoney().getAmountAsInteger();
    List<PayPapercutTransactionLog> txLogs = papercutDaoService.findPayPapercutTransactionLogsByIdtransAndPayMode(idtrans, PayMode.IZLYPAY, PageRequest.of(0, Integer.MAX_VALUE)).getContent();
    if (txLogs.size() > 0) {
        log.info("This transaction + " + idtrans + " is already OK");
        return true;
    }
    PayPapercutTransactionLog txLog = new PayPapercutTransactionLog();
    txLog.setPayMode(PayMode.IZLYPAY);
    txLog.setMontant(montant);
    txLog.setReference(reference);
    txLog.setIdtrans(idtrans);
    txLog.setTransactionDate(new Date());
    String uid = reference.split("@")[0];
    uid = uid.substring(context.getNumCommandePrefix().length(), uid.length());
    txLog.setUid(uid);
    String papercutContext = reference.split("@")[1];
    txLog.setPapercutContext(papercutContext);
    String papercutOldSolde = papercutService.getUserPapercutInfos(context, uid).getBalance();
    txLog.setPapercutOldSolde(papercutOldSolde);
    try {
        log.info("Transaction : " + reference + " pour un montant de " + montant + " OK !");
        double montantEuros = new Double(montant) / 100.0;
        papercutService.creditUserBalance(context, uid, montantEuros, idtrans, PayMode.IZLYPAY);
        String papercutNewSolde = papercutService.getUserPapercutInfos(context, uid).getBalance();
        txLog.setPapercutNewSolde(papercutNewSolde);
        papercutDaoService.persist(txLog);
    } catch (Exception ex) {
        log.error("Exception during creditUserBalance on papercut ?", ex);
    }
    return true;
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) Date(java.util.Date)

Example 4 with PayPapercutTransactionLog

use of org.esupportail.papercut.domain.PayPapercutTransactionLog 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)

Example 5 with PayPapercutTransactionLog

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

the class AdminController method getCsv.

@RequestMapping("/csv")
@Transactional
public void getCsv(HttpServletResponse response) throws IOException {
    StopWatch stopWatch = new StopWatch("Stream - build CSV and send it");
    stopWatch.start();
    response.setContentType("text/csv");
    response.setCharacterEncoding("utf-8");
    response.setHeader("Content-Disposition", "attachment; filename=\"pay_papercut_transaction_log.csv\"");
    Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF8");
    String csv = "Date transaction,uid,montant,ID transaction,context,payMode";
    writer.write(csv);
    Page<PayPapercutTransactionLog> txLogsPage = papercutDaoService.findAllPayPapercutTransactionLogs(PageRequest.of(0, 1000, Sort.by("transactionDate").ascending()));
    int nbLine = 0;
    while (true) {
        for (PayPapercutTransactionLog txLog : txLogsPage.getContent()) {
            csv = "";
            csv = csv + "\r\n";
            csv = csv + txLog.getTransactionDate() + ",";
            csv = csv + txLog.getUid() + ",";
            csv = csv + txLog.getMontant() + ",";
            csv = csv + txLog.getIdtrans() + ",";
            csv = csv + txLog.getPapercutContext() + ",";
            csv = csv + txLog.getPayMode();
            writer.write(csv);
            nbLine++;
        }
        if (txLogsPage.hasNext()) {
            Pageable pageable = txLogsPage.nextPageable();
            txLogsPage = papercutDaoService.findAllPayPapercutTransactionLogs(pageable);
        } else {
            break;
        }
    }
    stopWatch.stop();
    log.info("CSV of " + nbLine + " lines sent in " + stopWatch.getTotalTimeSeconds() + " sec.");
    writer.close();
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) Pageable(org.springframework.data.domain.Pageable) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) StopWatch(org.springframework.util.StopWatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PayPapercutTransactionLog (org.esupportail.papercut.domain.PayPapercutTransactionLog)11 Transactional (org.springframework.transaction.annotation.Transactional)6 Date (java.util.Date)2 EsupPapercutContext (org.esupportail.papercut.config.EsupPapercutContext)2 Pageable (org.springframework.data.domain.Pageable)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 TreeMap (java.util.TreeMap)1 IzlyPayForm (org.esupportail.papercut.domain.IzlyPayForm)1 PayBoxForm (org.esupportail.papercut.domain.PayBoxForm)1 UserPapercutInfos (org.esupportail.papercut.domain.UserPapercutInfos)1 StopWatch (org.springframework.util.StopWatch)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1