743 lines
30 KiB
Plaintext
743 lines
30 KiB
Plaintext
@using Nop.Plugin.Misc.FruitBankPlugin.Models.Orders
|
|
@model OrderAttributesModel
|
|
|
|
|
|
@*
|
|
<div class="form-group row">
|
|
|
|
</div> *@
|
|
|
|
<div class="form-group row">
|
|
|
|
<div class="col-12 col-md-7">
|
|
<div class="card card-default mb-2">
|
|
<div class="card-header">
|
|
<i class="fas fa-file-invoice"></i>
|
|
Megrendelés beállítások
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="form-group row">
|
|
|
|
<div class="col-md-12">
|
|
<strong>@(Model.IsMeasurable ? "Mérendő termék!" : "Nem mérendő termék")</strong>
|
|
</div>
|
|
</div>
|
|
<hr />
|
|
<div class="form-group row">
|
|
<div class="col-md-3">
|
|
<nop-label asp-for="DateOfReceipt" />
|
|
</div>
|
|
<div class="col-md-6">
|
|
<nop-editor asp-for="DateOfReceipt" asp-template="" />
|
|
</div>
|
|
<div class="col-md-3 text-right">
|
|
<button type="button" id="saveAttributesBtn" class="btn btn-primary">
|
|
<i class="fa fa-save"></i> Mentés
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<hr />
|
|
<div class="form-group row">
|
|
<div class="col-md-4">
|
|
<button type="button" class="btn btn-warning btn-block" data-toggle="modal" data-target="#allowRevisionModal">
|
|
<i class="fa fa-redo"></i> Újramérés engedélyezése
|
|
</button>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#sendMessageModal">
|
|
<i class="fas fa-paper-plane"></i> Üzenet küldése
|
|
</button>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<button type="button" class="btn btn-info btn-block" data-toggle="modal" data-target="#addOrderNoteModal">
|
|
<i class="fas fa-sticky-note"></i> Jegyzet hozzáadása
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-md-5">
|
|
<div class="card card-default mb-3">
|
|
<div class="card-header">
|
|
<i class="fas fa-file-invoice"></i>
|
|
Megrendelés beküldése Innvoice-ba
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="col-12">
|
|
|
|
<div id="orderStatus" class="alert alert-info" style="display: none;">
|
|
<i class="fas fa-info-circle"></i> <span id="orderStatusMessage"></span>
|
|
</div>
|
|
<div id="orderDetails" style="display: none;">
|
|
<p><strong>Order Table ID:</strong> <span id="orderTableId"></span></p>
|
|
<p><strong>Order Tech ID:</strong> <span id="orderTechId"></span></p>
|
|
<p>
|
|
<a id="orderPdfLink" href="#" target="_blank" class="btn btn-sm btn-info">
|
|
<i class="fas fa-file-pdf"></i> PDF megtekintése
|
|
</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-12 text-right float-end">
|
|
<button type="button" id="createOrderBtn" class="btn btn-success">
|
|
<i class="fas fa-shopping-cart"></i> Megrendelés beküldése
|
|
</button>
|
|
<button type="button" id="checkOrderBtn" class="btn btn-secondary" style="display: none;">
|
|
<i class="fas fa-sync"></i> Invoice adat ellenőrzése
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- Allow Revision Modal -->
|
|
<div class="modal fade" id="allowRevisionModal" tabindex="-1" role="dialog" aria-labelledby="allowRevisionModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="allowRevisionModalLabel">
|
|
<i class="fa fa-redo"></i> Újramérés engedélyezése
|
|
</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="form-group">
|
|
<label for="revisionSubject"><strong>Válassza ki az újramérendő terméket:</strong></label>
|
|
<select id="revisionSubject" class="form-control">
|
|
<option value="" disabled selected>Újramérendő termék</option>
|
|
@foreach (var orderItem in Model.OrderDto.OrderItemDtos)
|
|
{
|
|
<option value="@orderItem.Id">@orderItem.ProductName - @orderItem.Quantity @orderItem.IsAudited</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
<div id="revisionStatus" class="alert" style="display: none; margin-top: 15px;">
|
|
<i class="fas fa-info-circle"></i> <span id="revisionStatusMessage"></span>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">
|
|
<i class="fa fa-times"></i> Mégse
|
|
</button>
|
|
<button type="button" id="allowRevisionBtn" class="btn btn-primary">
|
|
<i class="fa fa-save"></i> Újramérés engedélyezése
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Send Message Modal -->
|
|
<div class="modal fade" id="sendMessageModal" tabindex="-1" role="dialog" aria-labelledby="sendMessageModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="sendMessageModalLabel">
|
|
<i class="fas fa-paper-plane"></i> Üzenet küldése
|
|
</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="form-group">
|
|
<label for="notificationMessage"><strong>Üzenet szövege:</strong></label>
|
|
<textarea id="notificationMessage" class="form-control" rows="4" placeholder="Írja be az üzenetet..."></textarea>
|
|
</div>
|
|
<div id="notificationStatus" class="alert" style="display: none; margin-top: 15px;">
|
|
<i class="fas fa-info-circle"></i> <span id="notificationStatusMessage"></span>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">
|
|
<i class="fa fa-times"></i> Mégse
|
|
</button>
|
|
<button type="button" id="sendNotificationBtn" class="btn btn-primary">
|
|
<i class="fas fa-paper-plane"></i> Üzenet küldése
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Order Note Modal -->
|
|
<div class="modal fade" id="addOrderNoteModal" tabindex="-1" role="dialog" aria-labelledby="addOrderNoteModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addOrderNoteModalLabel">
|
|
<i class="fas fa-sticky-note"></i> Jegyzet hozzáadása
|
|
</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="form-group">
|
|
<label for="orderNoteText"><strong>Jegyzet szövege:</strong></label>
|
|
<textarea id="orderNoteText" class="form-control" rows="4" placeholder="Írja be a jegyzetet a kollégák számára..."></textarea>
|
|
<small class="form-text text-muted">Ez a jegyzet megjelenik az external alkalmazásban a kollégák számára.</small>
|
|
</div>
|
|
<div id="orderNoteStatus" class="alert" style="display: none; margin-top: 15px;">
|
|
<i class="fas fa-info-circle"></i> <span id="orderNoteStatusMessage"></span>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">
|
|
<i class="fa fa-times"></i> Mégse
|
|
</button>
|
|
<button type="button" id="addOrderNoteBtn" class="btn btn-primary">
|
|
<i class="fas fa-save"></i> Jegyzet mentése
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
var createOrderUrl = '/Admin/InnVoiceOrder/CreateOrder';
|
|
var getOrderStatusUrl = '/Admin/InnVoiceOrder/GetOrderStatus';
|
|
var createInvoiceUrl = '/Admin/Invoice/CreateInvoice';
|
|
var getInvoiceStatusUrl = '/Admin/Invoice/GetInvoiceStatus';
|
|
|
|
|
|
var orderExists = false;
|
|
var invoiceExists = false;
|
|
|
|
// Remove validation from these specific fields
|
|
$('#@Html.IdFor(m => m.IsMeasurable)').rules('remove');
|
|
$('#@Html.IdFor(m => m.DateOfReceipt)').rules('remove');
|
|
|
|
// Also set data-val to false
|
|
$('#@Html.IdFor(m => m.IsMeasurable)').attr('data-val', 'false');
|
|
$('#@Html.IdFor(m => m.DateOfReceipt)').attr('data-val', 'false');
|
|
|
|
// Save Order Attributes
|
|
$("#saveAttributesBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "@Url.Action("SaveOrderAttributes", "CustomOrder")",
|
|
data: {
|
|
orderId: "@Model.OrderId",
|
|
isMeasurable: $("#@Html.IdFor(m => m.IsMeasurable)").is(":checked"),
|
|
dateOfReceipt: $("#@Html.IdFor(m => m.DateOfReceipt)").val(),
|
|
__RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val()
|
|
},
|
|
success: function () {
|
|
alert("Attributes saved successfully");
|
|
},
|
|
error: function () {
|
|
alert("Error saving attributes");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
// Allow Revision Button (in modal)
|
|
$("#allowRevisionBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var selectedOrderItemId = $("#revisionSubject").val();
|
|
|
|
if (!selectedOrderItemId) {
|
|
showRevisionStatus("Kérjük, válasszon ki egy terméket!", "warning");
|
|
return false;
|
|
}
|
|
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Mentés...');
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "@Url.Action("AllowRevision", "CustomOrder")",
|
|
data: {
|
|
orderId: "@Model.OrderId",
|
|
orderItemId: selectedOrderItemId,
|
|
__RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val()
|
|
},
|
|
success: function () {
|
|
btn.prop("disabled", false).html('<i class="fa fa-save"></i> Újramérés engedélyezése');
|
|
showRevisionStatus("Újramérés sikeresen engedélyezve!", "success");
|
|
|
|
// Close modal after 1.5 seconds
|
|
setTimeout(function() {
|
|
$('#allowRevisionModal').modal('hide');
|
|
$("#revisionSubject").val(""); // Reset select
|
|
}, 1500);
|
|
},
|
|
error: function () {
|
|
btn.prop("disabled", false).html('<i class="fa fa-save"></i> Újramérés engedélyezése');
|
|
showRevisionStatus("Hiba történt a művelet során!", "danger");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
function showRevisionStatus(message, type) {
|
|
var statusDiv = $("#revisionStatus");
|
|
statusDiv.removeClass("alert-info alert-success alert-warning alert-danger")
|
|
.addClass("alert-" + type);
|
|
$("#revisionStatusMessage").text(message);
|
|
statusDiv.show();
|
|
}
|
|
|
|
// Clear revision status when modal is closed
|
|
$('#allowRevisionModal').on('hidden.bs.modal', function () {
|
|
$("#revisionStatus").hide();
|
|
$("#revisionSubject").val("");
|
|
});
|
|
|
|
// ========== ORDER MANAGEMENT ==========
|
|
|
|
// Create Order
|
|
$("#createOrderBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Creating Order...');
|
|
|
|
showOrderStatus("Creating order in InnVoice, please wait...", "info");
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: createOrderUrl,
|
|
data: { orderId: @Model.OrderId },
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
console.log("Order Response:", response);
|
|
btn.prop("disabled", false).html('<i class="fas fa-shopping-cart"></i> Create Order in InnVoice');
|
|
|
|
if (response.success) {
|
|
showOrderStatus("Order created successfully in InnVoice!", "success");
|
|
displayOrderDetails(response.data);
|
|
orderExists = true;
|
|
updateOrderButtons();
|
|
} else {
|
|
showOrderStatus("Error: " + (response.message || "Unknown error"), "danger");
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error("Order AJAX Error:", xhr, status, error);
|
|
btn.prop("disabled", false).html('<i class="fas fa-shopping-cart"></i> Create Order in InnVoice');
|
|
|
|
var errorMessage = "Error creating order";
|
|
if (xhr.responseJSON && xhr.responseJSON.message) {
|
|
errorMessage = xhr.responseJSON.message;
|
|
} else if (xhr.responseText) {
|
|
try {
|
|
var errorObj = JSON.parse(xhr.responseText);
|
|
errorMessage = errorObj.message || errorMessage;
|
|
} catch (e) {
|
|
errorMessage = "Error: " + xhr.status + " - " + xhr.statusText;
|
|
}
|
|
}
|
|
showOrderStatus(errorMessage, "danger");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
// Check Order Status
|
|
$("#checkOrderBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Checking...');
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: getOrderStatusUrl,
|
|
data: { orderId: @Model.OrderId },
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
btn.prop("disabled", false).html('<i class="fas fa-sync"></i> Refresh Order');
|
|
|
|
if (response.success && response.data) {
|
|
displayOrderDetails(response.data);
|
|
showOrderStatus("Order details refreshed", "success");
|
|
} else {
|
|
showOrderStatus("No order found in InnVoice for this order", "warning");
|
|
}
|
|
},
|
|
error: function () {
|
|
btn.prop("disabled", false).html('<i class="fas fa-sync"></i> Refresh Order');
|
|
showOrderStatus("Error checking order status", "danger");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
function showOrderStatus(message, type) {
|
|
var statusDiv = $("#orderStatus");
|
|
statusDiv.removeClass("alert-info alert-success alert-warning alert-danger")
|
|
.addClass("alert-" + type);
|
|
$("#orderStatusMessage").text(message);
|
|
statusDiv.show();
|
|
}
|
|
|
|
function displayOrderDetails(data) {
|
|
$("#orderTableId").text(data.tableId || "N/A");
|
|
$("#orderTechId").text(data.techId || "N/A");
|
|
|
|
if (data.printUrl) {
|
|
$("#orderPdfLink").attr("href", data.printUrl).show();
|
|
} else {
|
|
$("#orderPdfLink").hide();
|
|
}
|
|
|
|
$("#orderDetails").show();
|
|
}
|
|
|
|
function updateOrderButtons() {
|
|
if (orderExists) {
|
|
$("#createOrderBtn").hide();
|
|
$("#checkOrderBtn").show();
|
|
} else {
|
|
$("#createOrderBtn").show();
|
|
$("#checkOrderBtn").hide();
|
|
}
|
|
}
|
|
|
|
// Check if order exists on page load
|
|
$.ajax({
|
|
type: "GET",
|
|
url: getOrderStatusUrl,
|
|
data: { orderId: @Model.OrderId },
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
if (response.success && response.data) {
|
|
displayOrderDetails(response.data);
|
|
orderExists = true;
|
|
updateOrderButtons();
|
|
}
|
|
},
|
|
error: function() {
|
|
// Silently fail on page load
|
|
orderExists = false;
|
|
updateOrderButtons();
|
|
}
|
|
});
|
|
|
|
// ========== INVOICE MANAGEMENT ==========
|
|
|
|
// Create Invoice
|
|
$("#createInvoiceBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Creating Invoice...');
|
|
|
|
showInvoiceStatus("Creating invoice, please wait...", "info");
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: createInvoiceUrl,
|
|
data: { orderId: @Model.OrderId },
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
console.log("Invoice Response:", response);
|
|
btn.prop("disabled", false).html('<i class="fas fa-file-invoice-dollar"></i> Create Invoice');
|
|
|
|
if (response.success) {
|
|
showInvoiceStatus("Invoice created successfully!", "success");
|
|
displayInvoiceDetails(response.data);
|
|
invoiceExists = true;
|
|
updateInvoiceButtons();
|
|
} else {
|
|
showInvoiceStatus("Error: " + (response.message || "Unknown error"), "danger");
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error("Invoice AJAX Error:", xhr, status, error);
|
|
btn.prop("disabled", false).html('<i class="fas fa-file-invoice-dollar"></i> Create Invoice');
|
|
|
|
var errorMessage = "Error creating invoice";
|
|
if (xhr.responseJSON && xhr.responseJSON.message) {
|
|
errorMessage = xhr.responseJSON.message;
|
|
} else if (xhr.responseText) {
|
|
try {
|
|
var errorObj = JSON.parse(xhr.responseText);
|
|
errorMessage = errorObj.message || errorMessage;
|
|
} catch (e) {
|
|
errorMessage = "Error: " + xhr.status + " - " + xhr.statusText;
|
|
}
|
|
}
|
|
showInvoiceStatus(errorMessage, "danger");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
// Check Invoice Status
|
|
$("#checkInvoiceBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Checking...');
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: getInvoiceStatusUrl,
|
|
data: { orderId: @Model.OrderId },
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
btn.prop("disabled", false).html('<i class="fas fa-sync"></i> Refresh Invoice');
|
|
|
|
if (response.success && response.data) {
|
|
displayInvoiceDetails(response.data);
|
|
showInvoiceStatus("Invoice details refreshed", "success");
|
|
} else {
|
|
showInvoiceStatus("No invoice found for this order", "warning");
|
|
}
|
|
},
|
|
error: function () {
|
|
btn.prop("disabled", false).html('<i class="fas fa-sync"></i> Refresh Invoice');
|
|
showInvoiceStatus("Error checking invoice status", "danger");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
function showInvoiceStatus(message, type) {
|
|
var statusDiv = $("#invoiceStatus");
|
|
statusDiv.removeClass("alert-info alert-success alert-warning alert-danger")
|
|
.addClass("alert-" + type);
|
|
$("#invoiceStatusMessage").text(message);
|
|
statusDiv.show();
|
|
}
|
|
|
|
function displayInvoiceDetails(data) {
|
|
$("#invoiceNumber").text(data.invoiceNumber || data.sorszam || "N/A");
|
|
$("#invoiceTableId").text(data.tableId || "N/A");
|
|
|
|
if (data.printUrl) {
|
|
$("#invoicePdfLink").attr("href", data.printUrl).show();
|
|
} else {
|
|
$("#invoicePdfLink").hide();
|
|
}
|
|
|
|
$("#invoiceDetails").show();
|
|
}
|
|
|
|
function updateInvoiceButtons() {
|
|
if (invoiceExists) {
|
|
$("#createInvoiceBtn").hide();
|
|
$("#checkInvoiceBtn").show();
|
|
} else {
|
|
$("#createInvoiceBtn").show();
|
|
$("#checkInvoiceBtn").hide();
|
|
}
|
|
}
|
|
|
|
// Check if invoice exists on page load
|
|
$.ajax({
|
|
type: "GET",
|
|
url: getInvoiceStatusUrl,
|
|
data: { orderId: @Model.OrderId },
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
if (response.success && response.data) {
|
|
displayInvoiceDetails(response.data);
|
|
invoiceExists = true;
|
|
updateInvoiceButtons();
|
|
}
|
|
},
|
|
error: function() {
|
|
// Silently fail on page load
|
|
invoiceExists = false;
|
|
updateInvoiceButtons();
|
|
}
|
|
});
|
|
|
|
// ========== NOTIFICATION MANAGEMENT ==========
|
|
|
|
var sendNotificationUrl = '/Admin/CustomOrder/SendOrderNotification';
|
|
|
|
// Send Notification (in modal)
|
|
$("#sendNotificationBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var message = $("#notificationMessage").val().trim();
|
|
|
|
if (!message) {
|
|
showNotificationStatus("Kérjük, adjon meg egy üzenetet!", "warning");
|
|
return false;
|
|
}
|
|
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Küldés...');
|
|
|
|
showNotificationStatus("Üzenet küldése folyamatban...", "info");
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: sendNotificationUrl,
|
|
data: {
|
|
orderId: @Model.OrderId,
|
|
message: message,
|
|
__RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val()
|
|
},
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
console.log("Notification Response:", response);
|
|
btn.prop("disabled", false).html('<i class="fas fa-paper-plane"></i> Üzenet küldése');
|
|
|
|
if (response.success) {
|
|
showNotificationStatus("Üzenet sikeresen elküldve!", "success");
|
|
|
|
// Close modal after 1.5 seconds
|
|
setTimeout(function() {
|
|
$('#sendMessageModal').modal('hide');
|
|
$("#notificationMessage").val(""); // Clear the textbox
|
|
}, 1500);
|
|
} else {
|
|
showNotificationStatus("Hiba: " + (response.message || "Ismeretlen hiba"), "danger");
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error("Notification AJAX Error:", xhr, status, error);
|
|
btn.prop("disabled", false).html('<i class="fas fa-paper-plane"></i> Üzenet küldése');
|
|
|
|
var errorMessage = "Hiba az üzenet küldése közben";
|
|
if (xhr.responseJSON && xhr.responseJSON.message) {
|
|
errorMessage = xhr.responseJSON.message;
|
|
} else if (xhr.responseText) {
|
|
try {
|
|
var errorObj = JSON.parse(xhr.responseText);
|
|
errorMessage = errorObj.message || errorMessage;
|
|
} catch (e) {
|
|
errorMessage = "Hiba: " + xhr.status + " - " + xhr.statusText;
|
|
}
|
|
}
|
|
showNotificationStatus(errorMessage, "danger");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
function showNotificationStatus(message, type) {
|
|
var statusDiv = $("#notificationStatus");
|
|
statusDiv.removeClass("alert-info alert-success alert-warning alert-danger")
|
|
.addClass("alert-" + type);
|
|
$("#notificationStatusMessage").text(message);
|
|
statusDiv.show();
|
|
}
|
|
|
|
// Clear notification status when modal is closed
|
|
$('#sendMessageModal').on('hidden.bs.modal', function () {
|
|
$("#notificationStatus").hide();
|
|
$("#notificationMessage").val("");
|
|
});
|
|
|
|
// ========== ORDER NOTE MANAGEMENT ==========
|
|
|
|
var addOrderNoteUrl = '@Url.Action("AddOrderNote", "CustomOrder")';
|
|
|
|
// Add Order Note (in modal)
|
|
$("#addOrderNoteBtn").click(function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var noteText = $("#orderNoteText").val().trim();
|
|
|
|
if (!noteText) {
|
|
showOrderNoteStatus("Kérjük, adjon meg egy jegyzetet!", "warning");
|
|
return false;
|
|
}
|
|
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Mentés...');
|
|
|
|
showOrderNoteStatus("Jegyzet mentése folyamatban...", "info");
|
|
|
|
// Add asterisk (*) at the beginning of the message
|
|
var noteWithAsterisk = "* " + noteText;
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: addOrderNoteUrl,
|
|
data: {
|
|
orderId: @Model.OrderId,
|
|
note: noteWithAsterisk,
|
|
__RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val()
|
|
},
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
console.log("Order Note Response:", response);
|
|
btn.prop("disabled", false).html('<i class="fas fa-save"></i> Jegyzet mentése');
|
|
|
|
if (response.success) {
|
|
showOrderNoteStatus("Jegyzet sikeresen mentve!", "success");
|
|
|
|
// Close modal after 1.5 seconds
|
|
setTimeout(function() {
|
|
$('#addOrderNoteModal').modal('hide');
|
|
$("#orderNoteText").val(""); // Clear the textbox
|
|
}, 1500);
|
|
} else {
|
|
showOrderNoteStatus("Hiba: " + (response.message || "Ismeretlen hiba"), "danger");
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error("Order Note AJAX Error:", xhr, status, error);
|
|
btn.prop("disabled", false).html('<i class="fas fa-save"></i> Jegyzet mentése');
|
|
|
|
var errorMessage = "Hiba a jegyzet mentése közben";
|
|
if (xhr.responseJSON && xhr.responseJSON.message) {
|
|
errorMessage = xhr.responseJSON.message;
|
|
} else if (xhr.responseText) {
|
|
try {
|
|
var errorObj = JSON.parse(xhr.responseText);
|
|
errorMessage = errorObj.message || errorMessage;
|
|
} catch (e) {
|
|
errorMessage = "Hiba: " + xhr.status + " - " + xhr.statusText;
|
|
}
|
|
}
|
|
showOrderNoteStatus(errorMessage, "danger");
|
|
}
|
|
});
|
|
|
|
return false;
|
|
});
|
|
|
|
function showOrderNoteStatus(message, type) {
|
|
var statusDiv = $("#orderNoteStatus");
|
|
statusDiv.removeClass("alert-info alert-success alert-warning alert-danger")
|
|
.addClass("alert-" + type);
|
|
$("#orderNoteStatusMessage").text(message);
|
|
statusDiv.show();
|
|
}
|
|
|
|
// Clear order note status when modal is closed
|
|
$('#addOrderNoteModal').on('hidden.bs.modal', function () {
|
|
$("#orderNoteStatus").hide();
|
|
$("#orderNoteText").val("");
|
|
});
|
|
|
|
});
|
|
</script>
|