198 lines
7.7 KiB
Plaintext
198 lines
7.7 KiB
Plaintext
@using Nop.Plugin.Misc.FruitBankPlugin.Models.Orders
|
|
@model OrderAttributesModel
|
|
|
|
<!-- InnVoice Invoice Section -->
|
|
<div class="card card-default mb-3">
|
|
<div class="card-header">
|
|
<i class="fas fa-file-invoice"></i>
|
|
InnVoice Invoice Management
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="form-group row">
|
|
<div class="col-md-12">
|
|
<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 PDF
|
|
</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<div class="col-md-12 text-right">
|
|
<button type="button" id="createInvoiceBtn" class="btn btn-success">
|
|
<i class="fas fa-file-invoice-dollar"></i> Create & Upload Invoice
|
|
</button>
|
|
<button type="button" id="checkInvoiceBtn" class="btn btn-secondary" style="display: none;">
|
|
<i class="fas fa-sync"></i> Check Invoice Status
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Custom Order Attributes Section -->
|
|
<div class="card card-default">
|
|
<div class="card-header">
|
|
<i class="fas fa-tags"></i>
|
|
Custom Order Attributes
|
|
</div>
|
|
<div class="card-body">
|
|
<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" />
|
|
<span asp-validation-for="IsMeasurable"></span>
|
|
</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" />
|
|
<span asp-validation-for="DateOfReceipt"></span>
|
|
</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>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
// Save Order Attributes
|
|
$("#saveAttributesBtn").click(function () {
|
|
$.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");
|
|
}
|
|
});
|
|
});
|
|
|
|
// Create Invoice
|
|
$("#createInvoiceBtn").click(function () {
|
|
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: "@Url.Action("CreateInvoice", "InnVoice")",
|
|
data: {
|
|
orderId: "@Model.OrderId",
|
|
__RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val()
|
|
},
|
|
success: function (response) {
|
|
btn.prop("disabled", false).html('<i class="fas fa-file-invoice-dollar"></i> Create & Upload Invoice');
|
|
|
|
if (response.success) {
|
|
showInvoiceStatus("Invoice created successfully!", "success");
|
|
displayInvoiceDetails(response.data);
|
|
$("#checkInvoiceBtn").show();
|
|
} else {
|
|
showInvoiceStatus("Error: " + response.message, "danger");
|
|
}
|
|
},
|
|
error: function (xhr) {
|
|
btn.prop("disabled", false).html('<i class="fas fa-file-invoice-dollar"></i> Create & Upload Invoice');
|
|
|
|
var errorMessage = "Error creating invoice";
|
|
if (xhr.responseJSON && xhr.responseJSON.message) {
|
|
errorMessage = xhr.responseJSON.message;
|
|
}
|
|
showInvoiceStatus(errorMessage, "danger");
|
|
}
|
|
});
|
|
});
|
|
|
|
// Check Invoice Status
|
|
$("#checkInvoiceBtn").click(function () {
|
|
var btn = $(this);
|
|
btn.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> Checking...');
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "@Url.Action("GetInvoiceStatus", "InnVoice")",
|
|
data: {
|
|
orderId: "@Model.OrderId"
|
|
},
|
|
success: function (response) {
|
|
btn.prop("disabled", false).html('<i class="fas fa-sync"></i> Check Invoice Status');
|
|
|
|
if (response.success && response.data) {
|
|
displayInvoiceDetails(response.data);
|
|
showInvoiceStatus("Invoice details loaded", "success");
|
|
} else {
|
|
showInvoiceStatus("No invoice found for this order", "warning");
|
|
}
|
|
},
|
|
error: function () {
|
|
btn.prop("disabled", false).html('<i class="fas fa-sync"></i> Check Invoice Status');
|
|
showInvoiceStatus("Error checking invoice status", "danger");
|
|
}
|
|
});
|
|
});
|
|
|
|
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();
|
|
}
|
|
|
|
// Check if invoice exists on page load
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "@Url.Action("GetInvoiceStatus", "InnVoice")",
|
|
data: {
|
|
orderId: "@Model.OrderId"
|
|
},
|
|
success: function (response) {
|
|
if (response.success && response.data) {
|
|
displayInvoiceDetails(response.data);
|
|
$("#checkInvoiceBtn").show();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
</script> |