This commit is contained in:
Adam 2026-06-06 17:18:04 +02:00
parent cab7d1c2aa
commit 1b60684f85
2 changed files with 22 additions and 19 deletions

View File

@ -6,37 +6,37 @@ using Nop.Web.Framework.Mvc.Filters;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
public partial class PreorderAdminController
public partial class PreOrderAdminController
{
[HttpPost, Route("Admin/Preorders/UpdateHeader/{id:int}")]
[HttpPost, Route("Admin/PreOrders/UpdateHeader/{id:int}")]
public async Task<IActionResult> UpdateHeader(int id, string deliveryDateTime, string? customerNote)
{
if (!await _permissionService.AuthorizeAsync(StandardPermission.Security.ACCESS_ADMIN_PANEL)) return Forbid();
var p = await _preorderDbContext.Preorders.GetByIdAsync(id);
if (p == null || p.Status == PreorderStatus.Cancelled) return Json(new { success = false });
var p = await _preorderDbContext.PreOrders.GetByIdAsync(id);
if (p == null || p.Status == PreOrderStatus.Cancelled) return Json(new { success = false });
if (!DateTime.TryParse(deliveryDateTime, out var d)) return Json(new { success = false, error = "Érvénytelen dátum" });
p.DateOfReceipt = d; p.CustomerNote = customerNote?.Trim(); p.UpdatedOnUtc = DateTime.UtcNow;
await _preorderDbContext.Preorders.UpdateAsync(p);
await _preorderDbContext.PreOrders.UpdateAsync(p);
return Json(new { success = true });
}
[HttpPost, Route("Admin/Preorders/UpdateItem/{id:int}")]
[HttpPost, Route("Admin/PreOrders/UpdateItem/{id:int}")]
public async Task<IActionResult> UpdateItem(int id, int quantity, decimal unitPrice)
{
if (!await _permissionService.AuthorizeAsync(StandardPermission.Security.ACCESS_ADMIN_PANEL)) return Forbid();
var item = await _preorderDbContext.PreorderItems.GetByIdAsync(id);
var item = await _preorderDbContext.PreOrderItems.GetByIdAsync(id);
if (item == null || item.FulfilledQuantity > 0) return Json(new { success = false, error = "Módosítás nem lehetséges" });
item.RequestedQuantity = Math.Max(1, quantity);
item.UnitPriceInclTax = Math.Max(0, unitPrice);
await _preorderDbContext.PreorderItems.UpdateAsync(item);
await _preorderDbContext.PreOrderItems.UpdateAsync(item);
return Json(new { success = true });
}
[HttpPost, Route("Admin/Preorders/ReplaceItemProduct/{id:int}")]
[HttpPost, Route("Admin/PreOrders/ReplaceItemProduct/{id:int}")]
public async Task<IActionResult> ReplaceItemProduct(int id, int newProductId)
{
if (!await _permissionService.AuthorizeAsync(StandardPermission.Security.ACCESS_ADMIN_PANEL)) return Forbid();
var item = await _preorderDbContext.PreorderItems.GetByIdAsync(id);
var item = await _preorderDbContext.PreOrderItems.GetByIdAsync(id);
if (item == null || item.FulfilledQuantity > 0) return Json(new { success = false, error = "Csere nem lehetséges" });
var product = await _dbContext.Products.GetByIdAsync(newProductId);
if (product == null || product.Deleted) return Json(new { success = false, error = "Termék nem található" });
@ -44,7 +44,7 @@ public partial class PreorderAdminController
item.ProductId = newProductId;
// Recalculate price for the preorder's customer using CustomPriceCalculationService
var preorder = await _preorderDbContext.Preorders.GetByIdAsync(item.PreorderId);
var preorder = await _preorderDbContext.PreOrders.GetByIdAsync(item.PreOrderId);
var customer = preorder != null ? await _customerService.GetCustomerByIdAsync(preorder.CustomerId) : null;
if (customer != null)
{
@ -53,23 +53,23 @@ public partial class PreorderAdminController
item.UnitPriceInclTax = calc.finalPrice;
}
await _preorderDbContext.PreorderItems.UpdateAsync(item);
await _preorderDbContext.PreOrderItems.UpdateAsync(item);
return Json(new { success = true, productName = product.Name, newPrice = item.UnitPriceInclTax });
}
[HttpPost, Route("Admin/Preorders/ConvertNow/{id:int}")]
[HttpPost, Route("Admin/PreOrders/ConvertNow/{id:int}")]
public async Task<IActionResult> ConvertNow(int id)
{
if (!await _permissionService.AuthorizeAsync(StandardPermission.Security.ACCESS_ADMIN_PANEL)) return Forbid();
var preorder = await _preorderDbContext.Preorders.GetByIdAsync(id);
if (preorder == null || preorder.Status == PreorderStatus.Cancelled)
var preorder = await _preorderDbContext.PreOrders.GetByIdAsync(id);
if (preorder == null || preorder.Status == PreOrderStatus.Cancelled)
return Json(new { success = false, error = "Konvertálás nem lehetséges" });
var pending = await _preorderDbContext.PreorderItems.GetAll()
.Where(i => i.PreorderId == id && i.FulfilledQuantity < i.RequestedQuantity).ToListAsync();
var pending = await _preorderDbContext.PreOrderItems.GetAll()
.Where(i => i.PreOrderId == id && i.FulfilledQuantity < i.RequestedQuantity).ToListAsync();
if (!pending.Any()) return Json(new { success = false, error = "Nincs teljesítetlen tétel" });
await _preorderConversionService.ConvertPreordersForProductsAsync(
await _preorderConversionService.ConvertPreOrdersForProductsAsync(
pending.Select(i => i.ProductId).Distinct().ToList(), 0);
var refreshed = await _preorderDbContext.Preorders.GetByIdAsync(id);
var refreshed = await _preorderDbContext.PreOrders.GetByIdAsync(id);
return Json(new { success = true, orderId = refreshed?.OrderId });
}
}

View File

@ -151,12 +151,15 @@
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Connections.Client">
<HintPath>..\..\..\..\FruitBankHybridApp\FruitBank.Common.Server\bin\$(Configuration)\net9.0\Microsoft.AspNetCore.Http.Connections.Client.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.SignalR.Client">
<HintPath>..\..\..\..\FruitBankHybridApp\FruitBank.Common.Server\bin\$(Configuration)\net9.0\Microsoft.AspNetCore.SignalR.Client.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.SignalR.Client.Core">
<HintPath>..\..\..\..\FruitBankHybridApp\FruitBank.Common.Server\bin\$(Configuration)\net9.0\Microsoft.AspNetCore.SignalR.Client.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson">
<HintPath>..\..\..\..\FruitBankHybridApp\FruitBank.Common.Server\bin\$(Configuration)\net9.0\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.dll</HintPath>