feat(invoice): add print functionality for order invoices and enhance order details
- Implemented a print button in OrderDetailsDialog and UserOrderDetailsDialog for generating invoices. - Updated DiscountOrdersMainPage to populate order details from the list. - Enhanced DiscountOrderDetailsDto to include UserFullName, UserMobile, and VatAmount for invoice generation. - Integrated JavaScript functionality to convert HTML invoices to PDF format.
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using DateTimeConverterCL;
|
||||
|
||||
namespace BackOffice.Common.Utilities;
|
||||
|
||||
/// <summary>ساخت HTML فاکتور برای چاپ مرورگر (jsHtmlToPdf).</summary>
|
||||
public static class OrderInvoicePrint
|
||||
{
|
||||
public sealed class InvoiceModel
|
||||
{
|
||||
public string ShopTitle { get; set; } = "فروشگاه";
|
||||
public string OrderId { get; set; } = "";
|
||||
public string? CustomerName { get; set; }
|
||||
public string? CustomerMobile { get; set; }
|
||||
public string? CustomerNationalCode { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public string? PostalCode { get; set; }
|
||||
public string? PaymentStatus { get; set; }
|
||||
public string? PaymentMethod { get; set; }
|
||||
public string? TransactionId { get; set; }
|
||||
public string? TrackingCode { get; set; }
|
||||
public DateTime? Created { get; set; }
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
public long Subtotal { get; set; }
|
||||
public long DiscountTotal { get; set; }
|
||||
public long CreditUsed { get; set; }
|
||||
public long GatewayAmount { get; set; }
|
||||
public long VatAmount { get; set; }
|
||||
public long TotalAmount { get; set; }
|
||||
public List<InvoiceLine> Lines { get; set; } = new();
|
||||
}
|
||||
|
||||
public sealed class InvoiceLine
|
||||
{
|
||||
public string Title { get; set; } = "";
|
||||
public int Quantity { get; set; }
|
||||
public long UnitPrice { get; set; }
|
||||
public long Discount { get; set; }
|
||||
public long LineTotal { get; set; }
|
||||
}
|
||||
|
||||
public static string BuildHtml(InvoiceModel model)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("<!DOCTYPE html><html lang=\"fa\" dir=\"rtl\"><head><meta charset=\"utf-8\"/>");
|
||||
sb.Append("<title>").Append(Esc($"فاکتور {model.OrderId}")).Append("</title>");
|
||||
sb.Append("""
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
body { font-family: Tahoma, "Segoe UI", sans-serif; color: #111; margin: 24px; font-size: 13px; }
|
||||
h1 { font-size: 20px; margin: 0 0 4px; }
|
||||
.muted { color: #555; }
|
||||
.header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #222; padding-bottom: 12px; margin-bottom: 16px; }
|
||||
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin-bottom: 16px; }
|
||||
.label { color: #666; font-size: 11px; }
|
||||
.value { font-weight: 600; }
|
||||
table { width: 100%; border-collapse: collapse; margin: 12px 0 16px; }
|
||||
th, td { border: 1px solid #ccc; padding: 8px; text-align: right; }
|
||||
th { background: #f3f3f3; }
|
||||
.num { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.totals { width: 320px; margin-right: auto; }
|
||||
.totals td { border: none; padding: 4px 0; }
|
||||
.totals .grand { font-size: 15px; font-weight: 700; border-top: 2px solid #222; padding-top: 8px; }
|
||||
.footer { margin-top: 28px; font-size: 11px; color: #666; border-top: 1px dashed #bbb; padding-top: 8px; }
|
||||
@media print {
|
||||
body { margin: 0; }
|
||||
.no-print { display: none !important; }
|
||||
}
|
||||
</style>
|
||||
""");
|
||||
sb.Append("</head><body>");
|
||||
sb.Append("<div class=\"header\"><div>");
|
||||
sb.Append("<h1>").Append(Esc(model.ShopTitle)).Append("</h1>");
|
||||
sb.Append("<div class=\"muted\">فاکتور فروش</div></div><div>");
|
||||
sb.Append("<div><span class=\"label\">شماره فاکتور: </span><span class=\"value\">").Append(Esc(model.OrderId)).Append("</span></div>");
|
||||
if (model.Created.HasValue)
|
||||
sb.Append("<div><span class=\"label\">تاریخ ثبت: </span>").Append(Esc(FormatDate(model.Created.Value))).Append("</div>");
|
||||
if (model.PaymentDate.HasValue)
|
||||
sb.Append("<div><span class=\"label\">تاریخ پرداخت: </span>").Append(Esc(FormatDate(model.PaymentDate.Value))).Append("</div>");
|
||||
sb.Append("</div></div>");
|
||||
|
||||
sb.Append("<div class=\"grid\">");
|
||||
AppendField(sb, "نام مشتری", model.CustomerName);
|
||||
AppendField(sb, "موبایل", model.CustomerMobile);
|
||||
AppendField(sb, "کد ملی", model.CustomerNationalCode);
|
||||
AppendField(sb, "کد پستی", model.PostalCode);
|
||||
AppendField(sb, "وضعیت پرداخت", model.PaymentStatus);
|
||||
AppendField(sb, "روش پرداخت", model.PaymentMethod);
|
||||
AppendField(sb, "کد تراکنش", model.TransactionId);
|
||||
AppendField(sb, "کد رهگیری", model.TrackingCode);
|
||||
if (!string.IsNullOrWhiteSpace(model.Address))
|
||||
{
|
||||
sb.Append("<div style=\"grid-column:1/-1\"><div class=\"label\">آدرس</div><div class=\"value\">")
|
||||
.Append(Esc(model.Address)).Append("</div></div>");
|
||||
}
|
||||
sb.Append("</div>");
|
||||
|
||||
sb.Append("<table><thead><tr>");
|
||||
sb.Append("<th>#</th><th>کالا</th><th>تعداد</th><th>قیمت واحد</th><th>تخفیف</th><th>مبلغ</th>");
|
||||
sb.Append("</tr></thead><tbody>");
|
||||
var i = 1;
|
||||
foreach (var line in model.Lines)
|
||||
{
|
||||
sb.Append("<tr>");
|
||||
sb.Append("<td class=\"num\">").Append(i++).Append("</td>");
|
||||
sb.Append("<td>").Append(Esc(line.Title)).Append("</td>");
|
||||
sb.Append("<td class=\"num\">").Append(line.Quantity).Append("</td>");
|
||||
sb.Append("<td class=\"num\">").Append(Money(line.UnitPrice)).Append("</td>");
|
||||
sb.Append("<td class=\"num\">").Append(Money(line.Discount)).Append("</td>");
|
||||
sb.Append("<td class=\"num\">").Append(Money(line.LineTotal)).Append("</td>");
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
if (model.Lines.Count == 0)
|
||||
sb.Append("<tr><td colspan=\"6\" class=\"muted\">آیتمی ثبت نشده است</td></tr>");
|
||||
sb.Append("</tbody></table>");
|
||||
|
||||
sb.Append("<table class=\"totals\"><tbody>");
|
||||
if (model.Subtotal > 0)
|
||||
AppendTotalRow(sb, "جمع اقلام", model.Subtotal);
|
||||
if (model.DiscountTotal > 0)
|
||||
AppendTotalRow(sb, "تخفیف", model.DiscountTotal);
|
||||
if (model.VatAmount > 0)
|
||||
AppendTotalRow(sb, "مالیات بر ارزش افزوده", model.VatAmount);
|
||||
if (model.CreditUsed > 0)
|
||||
AppendTotalRow(sb, "پرداخت از کیف اعتباری", model.CreditUsed);
|
||||
if (model.GatewayAmount > 0)
|
||||
AppendTotalRow(sb, "پرداخت درگاه / نقدی", model.GatewayAmount);
|
||||
sb.Append("<tr class=\"grand\"><td>مبلغ قابل پرداخت</td><td class=\"num\">")
|
||||
.Append(Money(model.TotalAmount)).Append(" تومان</td></tr>");
|
||||
sb.Append("</tbody></table>");
|
||||
|
||||
sb.Append("<div class=\"footer\">چاپشده از پنل ادمین — ").Append(Esc(FormatDate(DateTime.Now))).Append("</div>");
|
||||
sb.Append("</body></html>");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static void AppendField(StringBuilder sb, string label, string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) return;
|
||||
sb.Append("<div><div class=\"label\">").Append(Esc(label)).Append("</div><div class=\"value\">")
|
||||
.Append(Esc(value)).Append("</div></div>");
|
||||
}
|
||||
|
||||
private static void AppendTotalRow(StringBuilder sb, string label, long amount)
|
||||
{
|
||||
sb.Append("<tr><td>").Append(Esc(label)).Append("</td><td class=\"num\">")
|
||||
.Append(Money(amount)).Append(" تومان</td></tr>");
|
||||
}
|
||||
|
||||
private static string Money(long amount) => amount.ToString("N0", CultureInfo.InvariantCulture);
|
||||
|
||||
private static string FormatDate(DateTime dt)
|
||||
{
|
||||
try { return dt.ToLocalTime().MiladiToJalaliWithTime(); }
|
||||
catch { return dt.ToLocalTime().ToString("yyyy/MM/dd HH:mm"); }
|
||||
}
|
||||
|
||||
private static string Esc(string? s) => WebUtility.HtmlEncode(s ?? "");
|
||||
}
|
||||
@@ -1,36 +1,72 @@
|
||||
@using BackOffice.Services.DiscountOrder
|
||||
@using BackOffice.Common.BaseComponents
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
<MudIcon Icon="@Icons.Material.Filled.ShoppingCart" Class="ml-2" />
|
||||
جزئیات سفارش #@Order.OrderNumber
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudGrid>
|
||||
<!-- اطلاعات کاربر -->
|
||||
<MudItem xs="12">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">اطلاعات سفارش</MudText>
|
||||
<MudGrid>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">شماره سفارش:</MudText>
|
||||
<MudText Typo="Typo.body1"><strong>@Order.OrderNumber</strong></MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">شناسه کاربر:</MudText>
|
||||
<MudText Typo="Typo.body1">@Order.UserId</MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudStack Spacing="2">
|
||||
<MudText Typo="Typo.h6">جزئیات سفارش شماره @(string.IsNullOrWhiteSpace(Order.OrderNumber) ? Order.Id.ToString() : Order.OrderNumber)</MudText>
|
||||
<MudText Typo="Typo.body2">
|
||||
کاربر:
|
||||
@if (!string.IsNullOrWhiteSpace(Order.UserFullName))
|
||||
{
|
||||
@Order.UserFullName
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>#@Order.UserId</text>
|
||||
}
|
||||
@if (!string.IsNullOrWhiteSpace(DisplayMobile))
|
||||
{
|
||||
<text> (@DisplayMobile)</text>
|
||||
}
|
||||
</MudText>
|
||||
|
||||
<!-- Timeline وضعیت -->
|
||||
<MudItem xs="12">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.subtitle2" GutterBottom="true">Timeline وضعیت</MudText>
|
||||
<MudStack Row="true" Spacing="3" AlignItems="AlignItems.Center" Justify="Justify.Center">
|
||||
<MudPaper Class="pa-3">
|
||||
<MudStack Spacing="2">
|
||||
<MudText Typo="Typo.subtitle2">خلاصه سفارش</MudText>
|
||||
<MudDivider />
|
||||
<MudText Typo="Typo.body2">مبلغ کل: @Order.TotalPrice.ToString("N0") تومان</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Success">
|
||||
از کیف پول اعتباری: @Order.DiscountBalanceUsed.ToString("N0") تومان
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body2">
|
||||
مبلغ پرداختی از درگاه: @Order.GatewayAmount.ToString("N0") تومان
|
||||
</MudText>
|
||||
@if (!string.IsNullOrEmpty(Order.TransactionId))
|
||||
{
|
||||
<MudText Typo="Typo.body2">شناسه پرداخت: @Order.TransactionId</MudText>
|
||||
}
|
||||
@if (Order.Created.HasValue)
|
||||
{
|
||||
<MudText Typo="Typo.body2">
|
||||
تاریخ ثبت: @Order.Created.Value.MiladiToJalaliWithTime()
|
||||
</MudText>
|
||||
}
|
||||
<MudText Typo="Typo.body2">
|
||||
وضعیت پرداخت:
|
||||
<MudChip T="string"
|
||||
Color="@GetPaymentStatusColor(Order.PaymentStatusValue)"
|
||||
Size="Size.Small"
|
||||
Icon="@GetPaymentStatusIcon(Order.PaymentStatusValue)">
|
||||
@GetPaymentStatusText(Order.PaymentStatusValue)
|
||||
</MudChip>
|
||||
</MudText>
|
||||
|
||||
@if (Order.VatAmount > 0)
|
||||
{
|
||||
<MudDivider Class="my-2" />
|
||||
<MudText Typo="Typo.subtitle2">جزئیات مالیات بر ارزش افزوده</MudText>
|
||||
<MudText Typo="Typo.body2">
|
||||
مالیات: @Order.VatAmount.ToString("N0") تومان
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body2">
|
||||
مبلغ نهایی (شامل مالیات): @Order.TotalPrice.ToString("N0") تومان
|
||||
</MudText>
|
||||
}
|
||||
|
||||
<MudDivider Class="my-2" />
|
||||
<MudText Typo="Typo.subtitle2">Timeline وضعیت</MudText>
|
||||
<MudStack Row="true" Spacing="3" AlignItems="AlignItems.Center">
|
||||
@foreach (var step in _timelineSteps)
|
||||
{
|
||||
<MudStack Spacing="0" AlignItems="AlignItems.Center">
|
||||
@@ -41,141 +77,10 @@
|
||||
</MudStack>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- وضعیت سفارش -->
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">وضعیت سفارش</MudText>
|
||||
<MudChip T="string" Color="@GetStatusColor(Order.Status)" Size="Size.Large">
|
||||
@GetStatusText(Order.Status)
|
||||
</MudChip>
|
||||
@if (Order.Created.HasValue)
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mt-2">
|
||||
تاریخ ثبت: @Order.Created.Value.MiladiToJalaliWithTime()
|
||||
</MudText>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- وضعیت پرداخت -->
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">وضعیت پرداخت</MudText>
|
||||
<MudChip T="string"
|
||||
Size="Size.Large"
|
||||
Color="@GetPaymentStatusColor(Order.PaymentStatusValue)"
|
||||
Icon="@GetPaymentStatusIcon(Order.PaymentStatusValue)">
|
||||
@GetPaymentStatusText(Order.PaymentStatusValue)
|
||||
</MudChip>
|
||||
@if (!string.IsNullOrEmpty(Order.TransactionId))
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mt-2">
|
||||
کد تراکنش: @Order.TransactionId
|
||||
</MudText>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- آدرس ارسال -->
|
||||
@if (Order.Address != null)
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">
|
||||
<MudIcon Icon="@Icons.Material.Filled.LocationOn" Size="Size.Small" />
|
||||
آدرس ارسال
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body1"><strong>@Order.Address.Title</strong></MudText>
|
||||
<MudText Typo="Typo.body2">@Order.Address.Address</MudText>
|
||||
@if (!string.IsNullOrWhiteSpace(Order.Address.PostalCode))
|
||||
{
|
||||
<MudText Typo="Typo.body2">کد پستی: @Order.Address.PostalCode</MudText>
|
||||
}
|
||||
@if (!string.IsNullOrWhiteSpace(Order.Address.Phone))
|
||||
{
|
||||
<MudText Typo="Typo.body2">تلفن سفارشدهنده: @Order.Address.Phone</MudText>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
}
|
||||
|
||||
<!-- آیتمهای سفارش -->
|
||||
<MudItem xs="12">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">آیتمهای سفارش</MudText>
|
||||
<MudTable Items="@Order.Items" Hover="true" Dense="true" Elevation="0">
|
||||
<HeaderContent>
|
||||
<MudTh>محصول</MudTh>
|
||||
<MudTh>تعداد</MudTh>
|
||||
<MudTh>قیمت واحد</MudTh>
|
||||
<MudTh>تخفیف</MudTh>
|
||||
<MudTh>قیمت نهایی</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
||||
@if (!string.IsNullOrWhiteSpace(context.ThumbnailPath))
|
||||
{
|
||||
<MudImage Src="@context.ThumbnailPath" Width="40" Height="40"
|
||||
ObjectFit="ObjectFit.Cover" Class="rounded" />
|
||||
}
|
||||
<MudText>@context.ProductTitle</MudText>
|
||||
</MudStack>
|
||||
</MudTd>
|
||||
<MudTd>@context.Count</MudTd>
|
||||
<MudTd>@context.UnitPrice.ToString("N0") تومان</MudTd>
|
||||
<MudTd>
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Success">@context.MaxDiscountPercent%</MudChip>
|
||||
</MudTd>
|
||||
<MudTd><strong>@context.FinalPrice.ToString("N0") تومان</strong></MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- خلاصه مالی -->
|
||||
<MudItem xs="12">
|
||||
<MudPaper Class="pa-4" Elevation="2">
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">خلاصه مالی</MudText>
|
||||
<MudGrid>
|
||||
<MudItem xs="6">
|
||||
<MudText Color="Color.Secondary">مبلغ کل:</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6" Class="text-left">
|
||||
<MudText>@Order.TotalPrice.ToString("N0") تومان</MudText>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="6">
|
||||
<MudText Color="Color.Success">از کیف پول اعتباری:</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6" Class="text-left">
|
||||
<MudText Color="Color.Success">@Order.DiscountBalanceUsed.ToString("N0") تومان</MudText>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12"><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.h6">مبلغ پرداختی از درگاه:</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6" Class="text-left">
|
||||
<MudText Typo="Typo.h6" Color="Color.Primary">
|
||||
<strong>@Order.GatewayAmount.ToString("N0") تومان</strong>
|
||||
</MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- ویرایش وضعیت ارسال -->
|
||||
<MudItem xs="12">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.subtitle2" GutterBottom="true">مدیریت وضعیت ارسال</MudText>
|
||||
<MudDivider Class="mb-3" />
|
||||
<MudGrid>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudDivider Class="my-2" />
|
||||
<MudText Typo="Typo.body2">
|
||||
وضعیت ارسال:
|
||||
<MudSelect T="OrderStatus"
|
||||
Label="وضعیت ارسال"
|
||||
Dense="true"
|
||||
@@ -189,67 +94,131 @@
|
||||
<MudSelectItem T="OrderStatus" Value="@OrderStatus.Cancelled">لغو شده</MudSelectItem>
|
||||
<MudSelectItem T="OrderStatus" Value="@OrderStatus.Returned">مرجوع شده</MudSelectItem>
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
</MudText>
|
||||
<MudTextField T="string"
|
||||
Label="کد رهگیری"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Dense="true"
|
||||
@bind-Value="_trackingCode" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudTextField T="string"
|
||||
Label="یادداشت ادمین"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Dense="true"
|
||||
Lines="3"
|
||||
HelperText="دلیل تغییر وضعیت یا توضیحات اضافی"
|
||||
@bind-Value="_adminNotes" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@if (_newStatus == OrderStatus.Cancelled || _newStatus == OrderStatus.Returned)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Class="mt-2">
|
||||
<MudAlert Severity="Severity.Warning" Dense="true">
|
||||
توجه: در صورت لغو یا مرجوعی سفارش، موجودی محصولات به انبار بازگردانده میشود.
|
||||
</MudAlert>
|
||||
}
|
||||
@if (_newStatus == OrderStatus.Shipped)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Class="mt-2">
|
||||
پس از تغییر وضعیت به "ارسال شده"، اطلاعرسانی به کاربر ارسال خواهد شد.
|
||||
<MudAlert Severity="Severity.Info" Dense="true">
|
||||
پس از تغییر وضعیت به «ارسال شده»، اطلاعرسانی به کاربر ارسال خواهد شد.
|
||||
</MudAlert>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<!-- یادداشتها -->
|
||||
@if (!string.IsNullOrEmpty(Order.Notes) || !string.IsNullOrEmpty(Order.AdminNotes))
|
||||
<MudPaper Class="pa-3">
|
||||
<MudStack Spacing="1">
|
||||
<MudText Typo="Typo.subtitle2">آدرس تحویل</MudText>
|
||||
<MudDivider />
|
||||
@if (Order.Address != null && !string.IsNullOrWhiteSpace(Order.Address.Address))
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
@if (!string.IsNullOrWhiteSpace(Order.Address.Title))
|
||||
{
|
||||
<MudText Typo="Typo.body2"><strong>@Order.Address.Title</strong></MudText>
|
||||
}
|
||||
<MudText Typo="Typo.body2">@Order.Address.Address</MudText>
|
||||
@if (!string.IsNullOrWhiteSpace(Order.Address.PostalCode))
|
||||
{
|
||||
<MudText Typo="Typo.body2">کد پستی: @Order.Address.PostalCode</MudText>
|
||||
}
|
||||
@if (!string.IsNullOrWhiteSpace(DisplayMobile))
|
||||
{
|
||||
<MudText Typo="Typo.body2">تلفن سفارشدهنده: @DisplayMobile</MudText>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.caption">آدرسی ثبت نشده است.</MudText>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Class="pa-3">
|
||||
<MudStack Spacing="1">
|
||||
<MudText Typo="Typo.subtitle2">اقلام فاکتور</MudText>
|
||||
<MudDivider />
|
||||
@if (Order.Items.Count > 0)
|
||||
{
|
||||
<MudTable Items="Order.Items" Dense="true">
|
||||
<HeaderContent>
|
||||
<MudTh>تصویر</MudTh>
|
||||
<MudTh>محصول</MudTh>
|
||||
<MudTh>قیمت واحد</MudTh>
|
||||
<MudTh>تعداد</MudTh>
|
||||
<MudTh>تخفیف</MudTh>
|
||||
<MudTh>قیمت نهایی</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>
|
||||
@if (!string.IsNullOrWhiteSpace(context.ThumbnailPath))
|
||||
{
|
||||
<Image Src="@context.ThumbnailPath" Height="50" Width="50" />
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd>@context.ProductTitle</MudTd>
|
||||
<MudTd>@context.UnitPrice.ToString("N0")</MudTd>
|
||||
<MudTd>@context.Count</MudTd>
|
||||
<MudTd>
|
||||
@if (context.MaxDiscountPercent > 0)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Success">@context.MaxDiscountPercent%</MudChip>
|
||||
}
|
||||
else if (context.DiscountAmount > 0)
|
||||
{
|
||||
@context.DiscountAmount.ToString("N0")
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>-</text>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd>@context.FinalPrice.ToString("N0")</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.caption">آیتمی برای این سفارش ثبت نشده است.</MudText>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Order.Notes))
|
||||
{
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Comment" Size="Size.Small" />
|
||||
یادداشت کاربر
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body1" Class="mb-4">@Order.Notes</MudText>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(Order.AdminNotes))
|
||||
{
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Note" Size="Size.Small" />
|
||||
یادداشت ادمین
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body1">@Order.AdminNotes</MudText>
|
||||
}
|
||||
<MudPaper Class="pa-3">
|
||||
<MudStack Spacing="1">
|
||||
<MudText Typo="Typo.subtitle2">یادداشت کاربر</MudText>
|
||||
<MudDivider />
|
||||
<MudText Typo="Typo.body2">@Order.Notes</MudText>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
}
|
||||
</MudGrid>
|
||||
</MudStack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Secondary"
|
||||
StartIcon="@Icons.Material.Filled.Print"
|
||||
OnClick="PrintInvoiceAsync">
|
||||
چاپ فاکتور
|
||||
</MudButton>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="Close">
|
||||
بستن
|
||||
</MudButton>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using BackOffice.Common.Utilities;
|
||||
using BackOffice.Services.DiscountOrder;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
|
||||
namespace BackOffice.Pages.DiscountShop.Components;
|
||||
@@ -8,6 +10,7 @@ public partial class OrderDetailsDialog
|
||||
{
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
[Inject] public IDiscountOrderService OrderService { get; set; } = default!;
|
||||
[Inject] private IJSRuntime JsRuntime { get; set; } = default!;
|
||||
|
||||
[Parameter] public DiscountOrderDetailsDto Order { get; set; } = null!;
|
||||
|
||||
@@ -183,6 +186,45 @@ public partial class OrderDetailsDialog
|
||||
_ => Icons.Material.Filled.Schedule
|
||||
};
|
||||
|
||||
private async Task PrintInvoiceAsync()
|
||||
{
|
||||
var lines = Order.Items.Select(i => new OrderInvoicePrint.InvoiceLine
|
||||
{
|
||||
Title = i.ProductTitle,
|
||||
Quantity = i.Count,
|
||||
UnitPrice = i.UnitPrice,
|
||||
Discount = i.DiscountAmount,
|
||||
LineTotal = i.FinalPrice > 0 ? i.FinalPrice : i.UnitPrice * i.Count
|
||||
}).ToList();
|
||||
|
||||
var mobile = !string.IsNullOrWhiteSpace(Order.UserMobile)
|
||||
? Order.UserMobile
|
||||
: Order.Address?.Phone;
|
||||
|
||||
var html = OrderInvoicePrint.BuildHtml(new OrderInvoicePrint.InvoiceModel
|
||||
{
|
||||
ShopTitle = "فروشگاه اعتباری — کارا بازار سلامت",
|
||||
OrderId = string.IsNullOrWhiteSpace(Order.OrderNumber) ? Order.Id.ToString() : Order.OrderNumber,
|
||||
CustomerName = Order.UserFullName,
|
||||
CustomerMobile = mobile,
|
||||
Address = Order.Address?.Address,
|
||||
PostalCode = Order.Address?.PostalCode,
|
||||
PaymentStatus = GetPaymentStatusText(Order.PaymentStatusValue),
|
||||
TransactionId = Order.TransactionId,
|
||||
TrackingCode = Order.TrackingCode,
|
||||
Created = Order.Created,
|
||||
Subtotal = lines.Sum(l => l.UnitPrice * l.Quantity),
|
||||
DiscountTotal = lines.Sum(l => l.Discount),
|
||||
CreditUsed = Order.DiscountBalanceUsed,
|
||||
GatewayAmount = Order.GatewayAmount,
|
||||
VatAmount = Order.VatAmount,
|
||||
TotalAmount = Order.TotalPrice,
|
||||
Lines = lines
|
||||
});
|
||||
|
||||
await JsRuntime.InvokeVoidAsync("jsHtmlToPdf", html, $"فاکتور سفارش {Order.Id}");
|
||||
}
|
||||
|
||||
private enum StepState
|
||||
{
|
||||
Inactive = 0,
|
||||
|
||||
@@ -74,6 +74,15 @@ public partial class DiscountOrdersMainPage
|
||||
return;
|
||||
}
|
||||
|
||||
// تکمیل فیلدهای فاکتور از ردیف لیست (جزئیات API نام/موبایل/VAT ندارد)
|
||||
var listRow = _orders?.FirstOrDefault(o => o.Id == orderId);
|
||||
if (listRow != null)
|
||||
{
|
||||
order.UserFullName = listRow.UserFullName;
|
||||
order.UserMobile = listRow.UserMobile;
|
||||
order.VatAmount = listRow.VatAmount;
|
||||
}
|
||||
|
||||
var parameters = new DialogParameters<OrderDetailsDialog> { { x => x.Order, order } };
|
||||
var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Large, FullWidth = true };
|
||||
var dialog = await DialogService.ShowAsync<OrderDetailsDialog>("جزئیات سفارش", parameters, options);
|
||||
|
||||
@@ -170,6 +170,13 @@
|
||||
</MudStack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Secondary"
|
||||
StartIcon="@Icons.Material.Filled.Print"
|
||||
OnClick="PrintInvoiceAsync"
|
||||
Disabled="_model is null || _isLoading">
|
||||
چاپ فاکتور
|
||||
</MudButton>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="Close">
|
||||
بستن
|
||||
</MudButton>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using BackOffice.Common.Utilities;
|
||||
using CMSMicroservice.Protobuf.Protos;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
|
||||
namespace BackOffice.Pages.UserOrder.Components;
|
||||
@@ -9,6 +11,7 @@ public partial class UserOrderDetailsDialog
|
||||
{
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Inject] public UserOrderContract.UserOrderContractClient UserOrderContract { get; set; } = default!;
|
||||
[Inject] private IJSRuntime JsRuntime { get; set; } = default!;
|
||||
|
||||
[Parameter] public long OrderId { get; set; }
|
||||
|
||||
@@ -178,5 +181,61 @@ public partial class UserOrderDetailsDialog
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
|
||||
private async Task PrintInvoiceAsync()
|
||||
{
|
||||
if (_model is null) return;
|
||||
|
||||
var vat = _model.VatInfo;
|
||||
var lines = _model.FactorDetails.Select(f =>
|
||||
{
|
||||
var unit = f.UnitPrice ?? 0;
|
||||
var count = f.Count ?? 0;
|
||||
var discountUnit = f.UnitDiscountPrice ?? 0;
|
||||
var lineDiscount = Math.Max(0, (unit - discountUnit) * count);
|
||||
var lineTotal = discountUnit > 0 ? discountUnit * count : unit * count;
|
||||
return new OrderInvoicePrint.InvoiceLine
|
||||
{
|
||||
Title = f.ProductTitle ?? "",
|
||||
Quantity = count,
|
||||
UnitPrice = unit,
|
||||
Discount = lineDiscount,
|
||||
LineTotal = lineTotal
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
var subtotal = lines.Sum(l => l.UnitPrice * l.Quantity);
|
||||
var discountTotal = lines.Sum(l => l.Discount);
|
||||
var total = vat is { TotalAmount: > 0 } ? vat.TotalAmount : _model.Amount;
|
||||
|
||||
var html = OrderInvoicePrint.BuildHtml(new OrderInvoicePrint.InvoiceModel
|
||||
{
|
||||
ShopTitle = "فروشگاه عادی — کارا بازار سلامت",
|
||||
OrderId = _model.Id.ToString(),
|
||||
CustomerName = _model.UserFullName,
|
||||
CustomerMobile = _model.UserMobile,
|
||||
CustomerNationalCode = _model.UserNationalCode,
|
||||
Address = _model.UserAddressText,
|
||||
PostalCode = _model.PostalCode,
|
||||
PaymentStatus = _model.PaymentStatus switch
|
||||
{
|
||||
PaymentStatus.Success => "پرداخت شده",
|
||||
PaymentStatus.Pending => "در انتظار پرداخت",
|
||||
_ => "پرداخت نشده"
|
||||
},
|
||||
PaymentMethod = GetPaymentMethodText(_model.PaymentMethod.GetHashCode()),
|
||||
TransactionId = _model.TransactionId?.ToString(),
|
||||
TrackingCode = _trackingCode ?? _model.TrackingCode,
|
||||
Created = null,
|
||||
PaymentDate = _model.PaymentDate?.ToDateTime(),
|
||||
Subtotal = subtotal,
|
||||
DiscountTotal = discountTotal,
|
||||
VatAmount = vat?.VatAmount ?? 0,
|
||||
TotalAmount = total,
|
||||
Lines = lines
|
||||
});
|
||||
|
||||
await JsRuntime.InvokeVoidAsync("jsHtmlToPdf", html, $"فاکتور سفارش {_model.Id}");
|
||||
}
|
||||
|
||||
private void Close() => MudDialog.Close();
|
||||
}
|
||||
|
||||
@@ -62,10 +62,14 @@ public class DiscountOrderDetailsDto
|
||||
public long Id { get; set; }
|
||||
public long UserId { get; set; }
|
||||
public string OrderNumber { get; set; } = string.Empty;
|
||||
/// <summary>از ردیف لیست پر میشود (GetOrderById این فیلدها را ندارد)</summary>
|
||||
public string UserFullName { get; set; } = string.Empty;
|
||||
public string UserMobile { get; set; } = string.Empty;
|
||||
public AddressInfoDto? Address { get; set; }
|
||||
public long TotalPrice { get; set; }
|
||||
public long DiscountBalanceUsed { get; set; }
|
||||
public long GatewayAmount { get; set; }
|
||||
public long VatAmount { get; set; }
|
||||
public bool PaymentCompleted { get; set; }
|
||||
/// <summary>مقدار proto PaymentStatus: 0 Pending, 1 Completed, 2 Failed, 3 Refunded</summary>
|
||||
public int PaymentStatusValue { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user