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);
}
}
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;
}
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;
}
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";
}
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();
}
Aggregations