410 lines
16 KiB
Plaintext
410 lines
16 KiB
Plaintext
@using Nop.Plugin.Misc.FruitBankPlugin.Models.Orders
|
|
@model OrderAttributesModel
|
|
|
|
<!-- InnVoice Management Section -->
|
|
<div class="card card-default mb-3">
|
|
<div class="card-header">
|
|
<i class="fas fa-file-invoice"></i>
|
|
InnVoice Management
|
|
</div>
|
|
<div class="card-body">
|
|
<!-- Order Subsection -->
|
|
<div class="form-group row">
|
|
<div class="col-12 col-md-3">
|
|
<h5><i class="fas fa-shopping-cart"></i> Order</h5>
|
|
<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> View Order PDF
|
|
</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-12 col-md-3 text-right">
|
|
<button type="button" id="createOrderBtn" class="btn btn-success">
|
|
<i class="fas fa-shopping-cart"></i> Create Order in InnVoice
|
|
</button>
|
|
<button type="button" id="checkOrderBtn" class="btn btn-secondary" style="display: none;">
|
|
<i class="fas fa-sync"></i> Refresh Order
|
|
</button>
|
|
</div>
|
|
|
|
<div class="col-12 col-md-3">
|
|
<h5><i class="fas fa-file-invoice-dollar"></i> Invoice</h5>
|
|
<div id="invoiceStatus" class="alert alert-info" style="display: none;">
|
|
<i class="fas fa-info-circle"></i> <span id="invoiceStatusMessage"></span>
|
|
</div>
|
|
<div id="invoiceDetails" style="display: none;">
|
|
<p><strong>Invoice Number:</strong> <span id="invoiceNumber"></span></p>
|
|
<p><strong>Table ID:</strong> <span id="invoiceTableId"></span></p>
|
|
<p>
|
|
<a id="invoicePdfLink" href="#" target="_blank" class="btn btn-sm btn-info">
|
|
<i class="fas fa-file-pdf"></i> View Invoice PDF
|
|
</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-12 col-md-3 text-right">
|
|
<button type="button" id="createInvoiceBtn" class="btn btn-success">
|
|
<i class="fas fa-file-invoice-dollar"></i> Create Invoice
|
|
</button>
|
|
<button type="button" id="checkInvoiceBtn" class="btn btn-secondary" style="display: none;">
|
|
<i class="fas fa-sync"></i> Refresh Invoice
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Attributes Section (NO FORM TAG - just a div) -->
|
|
<div id="orderAttributesSection">
|
|
<div class="form-group row">
|
|
<div class="col-12">
|
|
<div class="form-group row">
|
|
<div class="col-md-3">
|
|
<nop-label asp-for="IsMeasurable" />
|
|
</div>
|
|
<div class="col-md-9">
|
|
<nop-editor asp-for="IsMeasurable" asp-template="" />
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<div class="col-md-3">
|
|
<nop-label asp-for="DateOfReceipt" />
|
|
</div>
|
|
<div class="col-md-9">
|
|
<nop-editor asp-for="DateOfReceipt" asp-template="" />
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<div class="col-md-12 text-right">
|
|
<button type="button" id="saveAttributesBtn" class="btn btn-primary">
|
|
<i class="fa fa-save"></i> Save Attributes
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</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;
|
|
});
|
|
|
|
// ========== 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();
|
|
}
|
|
});
|
|
});
|
|
</script> |