mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-02-28 05:39:13 +00:00
corregidos varios problemas
This commit is contained in:
@ -22,7 +22,6 @@ import com.imprimelibros.erp.direcciones.DireccionService;
|
|||||||
import com.imprimelibros.erp.cart.Cart;
|
import com.imprimelibros.erp.cart.Cart;
|
||||||
import com.imprimelibros.erp.cart.CartService;
|
import com.imprimelibros.erp.cart.CartService;
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/checkout")
|
@RequestMapping("/checkout")
|
||||||
public class CheckoutController {
|
public class CheckoutController {
|
||||||
@ -63,21 +62,24 @@ public class CheckoutController {
|
|||||||
return "imprimelibros/checkout/checkout"; // crea esta vista si quieres (tabla simple)
|
return "imprimelibros/checkout/checkout"; // crea esta vista si quieres (tabla simple)
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping({"/get-summary", "/get-summary/{direccionId}"})
|
@GetMapping({ "/get-summary", "/get-summary/{direccionId}/{method}" })
|
||||||
public String getCheckoutSummary(@PathVariable(required = false) Long direccionId, Principal principal, Model model, Locale locale) {
|
public String getCheckoutSummary(@PathVariable(required = false) Long direccionId,
|
||||||
|
@PathVariable(required = false) String method, Principal principal, Model model, Locale locale) {
|
||||||
Long userId = Utils.currentUserId(principal);
|
Long userId = Utils.currentUserId(principal);
|
||||||
Cart cart = cartService.getOrCreateActiveCart(userId);
|
Cart cart = cartService.getOrCreateActiveCart(userId);
|
||||||
Boolean hasTaxes = true;
|
Boolean hasTaxes = true;
|
||||||
if(direccionId != null) {
|
if (direccionId != null) {
|
||||||
hasTaxes = direccionService.hasTaxes(direccionId);
|
hasTaxes = direccionService.hasTaxes(direccionId);
|
||||||
}
|
}
|
||||||
Map<String, Object> summary = cartService.getCartSummary(cart, locale, hasTaxes);
|
Map<String, Object> summary = cartService.getCartSummary(cart, locale, hasTaxes);
|
||||||
model.addAttribute("summary", summary);
|
model.addAttribute("summary", summary);
|
||||||
|
if (method != null) {
|
||||||
|
model.addAttribute("method", method);
|
||||||
|
}
|
||||||
|
|
||||||
return "imprimelibros/checkout/_summary :: checkoutSummary(summary=${summary})";
|
return "imprimelibros/checkout/_summary :: checkoutSummary(summary=${summary})";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/get-address/{id}")
|
@GetMapping("/get-address/{id}")
|
||||||
public String getDireccionCard(@PathVariable Long id, Model model, Locale locale) {
|
public String getDireccionCard(@PathVariable Long id, Model model, Locale locale) {
|
||||||
Direccion dir = direccionService.findById(id)
|
Direccion dir = direccionService.findById(id)
|
||||||
|
|||||||
@ -184,11 +184,14 @@ public class PaymentController {
|
|||||||
|
|
||||||
// Campos ordenables
|
// Campos ordenables
|
||||||
List<String> orderable = List.of(
|
List<String> orderable = List.of(
|
||||||
"transferId",
|
"client",
|
||||||
|
"transfer_id",
|
||||||
"status",
|
"status",
|
||||||
"amountCents",
|
"amountCents",
|
||||||
"payment.amountRefundedCents",
|
"amountCentsRefund",
|
||||||
"createdAt", "updatedAt");
|
"payment.orderId",
|
||||||
|
"createdAt",
|
||||||
|
"processedAt");
|
||||||
|
|
||||||
Specification<PaymentTransaction> base = (root, query, cb) -> cb.or(
|
Specification<PaymentTransaction> base = (root, query, cb) -> cb.or(
|
||||||
cb.equal(root.get("status"), PaymentTransactionStatus.pending),
|
cb.equal(root.get("status"), PaymentTransactionStatus.pending),
|
||||||
@ -215,6 +218,26 @@ public class PaymentController {
|
|||||||
return DataTable
|
return DataTable
|
||||||
.of(repoPaymentTransaction, PaymentTransaction.class, dt, searchable)
|
.of(repoPaymentTransaction, PaymentTransaction.class, dt, searchable)
|
||||||
.orderable(orderable)
|
.orderable(orderable)
|
||||||
|
.orderable("client", (root, query, cb) -> {
|
||||||
|
var sq = query.subquery(String.class);
|
||||||
|
var u = sq.from(User.class);
|
||||||
|
sq.select(u.get("fullName"));
|
||||||
|
sq.where(cb.equal(u.get("id"), root.join("payment").get("userId")));
|
||||||
|
return sq;
|
||||||
|
})
|
||||||
|
.orderable("transfer_id", (root, query, cb) -> {
|
||||||
|
var orderId = root.join("payment").get("orderId").as(Long.class);
|
||||||
|
return cb.<Long>selectCase()
|
||||||
|
.when(cb.isNull(orderId), Long.MAX_VALUE)
|
||||||
|
.otherwise(orderId);
|
||||||
|
})
|
||||||
|
.orderable("payment.orderId", (root, query, cb) -> {
|
||||||
|
var orderId = root.join("payment").get("orderId").as(Long.class);
|
||||||
|
return cb.<Long>selectCase()
|
||||||
|
.when(cb.isNull(orderId), Long.MAX_VALUE)
|
||||||
|
.otherwise(orderId);
|
||||||
|
})
|
||||||
|
.orderable("amountCentsRefund", (root, query, cb) -> root.join("payment").get("amountRefundedCents"))
|
||||||
.add("created_at", pago -> Utils.formatDateTime(pago.getCreatedAt(), locale))
|
.add("created_at", pago -> Utils.formatDateTime(pago.getCreatedAt(), locale))
|
||||||
.add("processed_at", pago -> Utils.formatDateTime(pago.getProcessedAt(), locale))
|
.add("processed_at", pago -> Utils.formatDateTime(pago.getProcessedAt(), locale))
|
||||||
.add("client", pago -> {
|
.add("client", pago -> {
|
||||||
@ -237,14 +260,14 @@ public class PaymentController {
|
|||||||
return "";
|
return "";
|
||||||
})
|
})
|
||||||
.add("order_id", pago -> {
|
.add("order_id", pago -> {
|
||||||
if (pago.getStatus() != PaymentTransactionStatus.pending) {
|
//if (pago.getStatus() != PaymentTransactionStatus.pending) {
|
||||||
if (pago.getPayment() != null && pago.getPayment().getOrderId() != null) {
|
if (pago.getPayment() != null && pago.getPayment().getOrderId() != null) {
|
||||||
return pago.getPayment().getOrderId().toString();
|
return pago.getPayment().getOrderId().toString();
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
return messageSource.getMessage("pagos.transferencia.no-pedido", null, "Pendiente", locale);
|
//return messageSource.getMessage("pagos.transferencia.no-pedido", null, "Pendiente", locale);
|
||||||
|
|
||||||
}).add("amount_cents", pago -> Utils.formatCurrency(pago.getAmountCents() / 100.0, locale))
|
}).add("amount_cents", pago -> Utils.formatCurrency(pago.getAmountCents() / 100.0, locale))
|
||||||
.add("amount_cents_refund", pago ->
|
.add("amount_cents_refund", pago ->
|
||||||
|
|||||||
@ -151,7 +151,7 @@ $(() => {
|
|||||||
|
|
||||||
if (direccionId) {
|
if (direccionId) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: `/checkout/get-summary/${direccionId}`,
|
url: `/checkout/get-summary/${direccionId}/${$('input[name="method"]').val()}`,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
const parent = $('.cart-summary-container').parent();
|
const parent = $('.cart-summary-container').parent();
|
||||||
|
|||||||
@ -48,7 +48,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<form th:action="@{/pagos/redsys/crear}" method="post">
|
<form th:action="@{/pagos/redsys/crear}" method="post">
|
||||||
<input type="hidden" name="amountCents" th:value="${summary.amountCents}" />
|
<input type="hidden" name="amountCents" th:value="${summary.amountCents}" />
|
||||||
<input type="hidden" name="method" value="card" />
|
<input type="hidden" name="method" th:value="${method} ?: 'card'" />
|
||||||
<input type="hidden" name="cartId" th:value="${summary.cartId}" />
|
<input type="hidden" name="cartId" th:value="${summary.cartId}" />
|
||||||
<input type="hidden" id="dirFactId" name="dirFactId" value="" />
|
<input type="hidden" id="dirFactId" name="dirFactId" value="" />
|
||||||
<button id="btn-checkout" type="submit" class="btn btn-secondary w-100 mt-2"
|
<button id="btn-checkout" type="submit" class="btn btn-secondary w-100 mt-2"
|
||||||
|
|||||||
Reference in New Issue
Block a user