diff --git a/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor b/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor index 8100cec..a43e052 100644 --- a/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor +++ b/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor @@ -1,13 +1,15 @@ -@inject ISnackbar Snackbar + +@inject ISnackbar Snackbar @inject IRestWrapper RestWrapper @inject IUserUtility UserUtility @inject IDialogService DialogService +@inject IPrintingService PrintingService - + @@ -20,28 +22,28 @@ - + @ViewModel.PageDto.UserFullName - + @ViewModel.PageDto.UserPhoneNumber - + @ViewModel.PageDto.DiscountCode - + @ViewModel.PageDto?.OrderDelivery?.Address - - @ViewModel.PageDto?.OrderDelivery?.ShippingMethod + + @ViewModel.PageDto?.OrderDelivery?.ShippingMethod - + کالاهای این سفارش @@ -86,7 +88,7 @@ - + مبــــالغ @@ -191,6 +193,7 @@ Icon="@Icons.Material.Outlined.Print" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Info" + OnClickCallback="@(()=> PrintingService.Print("http://localhost:32770/api/order/efc18848-fde5-4687-a9f3-0df6aff8b8ed/invoice?access_token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJQZXJtaXNzaW9uIjpbIk1hbmFnZUJsb2dzIiwiTWFuYWdlQmxvZ3MiLCJNYW5hZ2VCcmFuZHMiLCJWaWV3QnJhbmRzIiwiTWFuYWdlQ2F0ZWdvcmllcyIsIlZpZXdDYXRlZ29yaWVzIiwiTWFuYWdlRGlzY291bnRzIiwiVmlld0Rpc2NvdW50cyIsIk1hbmFnZU9yZGVycyIsIlZpZXdBbGxPcmRlcnMiLCJWaWV3TWluZU9yZGVycyIsIkNyZWF0ZU9yZGVyIiwiTWFuYWdlUHJvZHVjdHMiLCJWaWV3UHJvZHVjdHMiLCJBZGRSZXZpZXciLCJBZGRSZXZpZXciLCJDb25maXJtUmV2aWV3IiwiVmlld0FsbFJldmlld3MiLCJWaWV3TWluZVJldmlld3MiLCJNYW5hZ2VXYXJlaG91c2VzIiwiVmlld1dhcmVob3VzZXMiLCJNYW5hZ2VTaGlwcGluZyIsIlZpZXdTaGlwcGluZyIsIk1hbmFnZVVzZXJzIiwiVmlld1VzZXJzIiwiTWFuYWdlRmlsZXMiLCJWaWV3RmlsZXMiXSwicm9sZSI6IlJvb3RBZG1pbiIsIlJvbGVJZCI6ImVmNjYxYTFkLWE2NGItNDc1NC05NDJhLWQwZTlhMWY2YWQ3NSIsIlNpZ25VcFN0YXR1cyI6IjAiLCJ1bmlxdWVfbmFtZSI6IjA5MjE0ODAyODEzIiwibmFtZWlkIjoiMjRmOTMwMDQtN2E3My00ZmRiLWE4OTMtYTRjOTkxOTRhMjBhIiwiZW1haWwiOiJhdnZhbXBpZXJAZ21haWwuY29tIiwiSnd0SUQiOiIzMmNlYTMzOCIsImdlbmRlciI6IkZlbWFsZSIsIm5iZiI6MTcwODg3MTM0NywiZXhwIjoxNzEwMTY3MzQ3LCJpYXQiOjE3MDg4NzEzNDcsImlzcyI6IkJyaXpjbyIsImF1ZCI6IkJyaXpjbyJ9.rupn8kw0V5hNkMvFkkoKo5gUbLy0k-ZxYQM-RptsRlxLhVeA9024u5tS2hY1QazxE9di8HAsebPZeVDnJ4gGuw",true))" Content="چاپــ فاکتور" /> بستن @@ -210,9 +213,9 @@ protected override async Task OnInitializedAsync() { if (Order == null) - ViewModel = new OrderActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog); + ViewModel = new OrderActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog , PrintingService); else - ViewModel = new OrderActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog, Order); + ViewModel = new OrderActionDialogBoxViewModel(Snackbar, RestWrapper, UserUtility, DialogService, MudDialog, Order, PrintingService); await ViewModel.InitializeAsync(); await base.OnInitializedAsync(); } diff --git a/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor.cs b/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor.cs index 8de30ae..90778c9 100644 --- a/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor.cs +++ b/NetinaShop.AdminPanel.PWA/Dialogs/OrderActionDialogBox.razor.cs @@ -1,4 +1,6 @@ -namespace NetinaShop.AdminPanel.PWA.Dialogs; +using Append.Blazor.Printing; + +namespace NetinaShop.AdminPanel.PWA.Dialogs; public class OrderActionDialogBoxViewModel : BaseViewModel { @@ -8,21 +10,26 @@ public class OrderActionDialogBoxViewModel : BaseViewModel private readonly IUserUtility _userUtility; private readonly IDialogService _dialogService; private readonly MudDialogInstance _mudDialog; + private readonly IPrintingService _printingService; - public OrderActionDialogBoxViewModel(ISnackbar snackbar, IRestWrapper restWrapper, IUserUtility userUtility, IDialogService dialogService, MudDialogInstance mudDialog) + public OrderActionDialogBoxViewModel(ISnackbar snackbar, IRestWrapper restWrapper, IUserUtility userUtility, IDialogService dialogService, + MudDialogInstance mudDialog, + IPrintingService printingService) { _snackbar = snackbar; _restWrapper = restWrapper; _userUtility = userUtility; _dialogService = dialogService; _mudDialog = mudDialog; + _printingService = printingService; } public OrderActionDialogBoxViewModel(ISnackbar snackbar, IRestWrapper restWrapper, IUserUtility userUtility, IDialogService dialogService, MudDialogInstance mudDialog, - OrderSDto order) + OrderSDto order, + IPrintingService printingService) { _snackbar = snackbar; _restWrapper = restWrapper; @@ -31,6 +38,7 @@ public class OrderActionDialogBoxViewModel : BaseViewModel _mudDialog = mudDialog; PageDto.Id = order.Id; IsEditing = true; + _printingService = printingService; } @@ -58,6 +66,9 @@ public class OrderActionDialogBoxViewModel : BaseViewModel PageDto = order; switch (PageDto.OrderStatus) { + case OrderStatus.OrderBag: + ConfirmOrderButtonText = "ثبت پرداختی سفارش"; + break; case OrderStatus.Submitted: ConfirmOrderButtonText = "ثبت پرداختی سفارش"; break; @@ -78,12 +89,10 @@ public class OrderActionDialogBoxViewModel : BaseViewModel { var exe = await ex.GetContentAsAsync(); _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); - _mudDialog.Cancel(); } catch (Exception e) { _snackbar.Add(e.Message, Severity.Error); - _mudDialog.Cancel(); } finally { @@ -93,6 +102,38 @@ public class OrderActionDialogBoxViewModel : BaseViewModel }; } + public async Task PrintInvoiceAsync() + { + try + { + var token = await _userUtility.GetBearerTokenAsync(); + if (token == null) + throw new Exception("Token is null"); + IsProcessing = true; + string fileUrl = $"{Address.OrderController}/{PageDto.Id}/invoice?access_token={token.Split("Bearer").Last().Trim()}"; + + var content = await _restWrapper.OrderRestApi.GetOrderInvoice(PageDto.Id, token); + var bytes = await content.ReadAsByteArrayAsync(); + var base64 = Convert.ToBase64String(bytes); + await _printingService.Print(fileUrl, showModal: true); + Console.WriteLine(fileUrl); + } + catch (ApiException ex) + { + var exe = await ex.GetContentAsAsync(); + _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); + } + catch (Exception e) + { + _snackbar.Add(e.Message, Severity.Error); + } + finally + { + + IsProcessing = false; + } + } + public async Task SubmitConfirmAsync() { var options = new DialogOptions { CloseOnEscapeKey = true }; diff --git a/NetinaShop.AdminPanel.PWA/NetinaShop.AdminPanel.PWA.csproj b/NetinaShop.AdminPanel.PWA/NetinaShop.AdminPanel.PWA.csproj index ccaacd9..1e7254b 100644 --- a/NetinaShop.AdminPanel.PWA/NetinaShop.AdminPanel.PWA.csproj +++ b/NetinaShop.AdminPanel.PWA/NetinaShop.AdminPanel.PWA.csproj @@ -15,6 +15,7 @@ + diff --git a/NetinaShop.AdminPanel.PWA/Program.cs b/NetinaShop.AdminPanel.PWA/Program.cs index ff60fb3..4899134 100644 --- a/NetinaShop.AdminPanel.PWA/Program.cs +++ b/NetinaShop.AdminPanel.PWA/Program.cs @@ -1,3 +1,4 @@ +using Append.Blazor.Printing; using Blazored.LocalStorage; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Web; @@ -35,5 +36,6 @@ builder.Services.AddBlazoredLocalStorage(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); +builder.Services.AddScoped(); builder.Services.AddPWAUpdater(); await builder.Build().RunAsync(); diff --git a/NetinaShop.AdminPanel.PWA/Services/RestServices/IOrderRestApi.cs b/NetinaShop.AdminPanel.PWA/Services/RestServices/IOrderRestApi.cs index 1adac03..f27a31c 100644 --- a/NetinaShop.AdminPanel.PWA/Services/RestServices/IOrderRestApi.cs +++ b/NetinaShop.AdminPanel.PWA/Services/RestServices/IOrderRestApi.cs @@ -10,4 +10,7 @@ public interface IOrderRestApi [Post("/{id}/confirm")] Task ConfirmOrderStepAsync(Guid id,[Query] OrderStatus nextOrderStatus , [Header("Authorization")] string authorization); + + [Get("/{id}/invoice")] + Task GetOrderInvoice(Guid id, [Header("Authorization")] string authorization); } \ No newline at end of file diff --git a/NetinaShop.AdminPanel.PWA/Services/RestServices/RestWrapper.cs b/NetinaShop.AdminPanel.PWA/Services/RestServices/RestWrapper.cs index a91f697..4487feb 100644 --- a/NetinaShop.AdminPanel.PWA/Services/RestServices/RestWrapper.cs +++ b/NetinaShop.AdminPanel.PWA/Services/RestServices/RestWrapper.cs @@ -7,7 +7,7 @@ public class RestWrapper : IRestWrapper { Formatting = Newtonsoft.Json.Formatting.Indented, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore, - + })); public ICrudApiRest CrudApiRest(string address) where T : class diff --git a/NetinaShop.AdminPanel.PWA/_Imports.razor b/NetinaShop.AdminPanel.PWA/_Imports.razor index 3a0ccc4..b01f18f 100644 --- a/NetinaShop.AdminPanel.PWA/_Imports.razor +++ b/NetinaShop.AdminPanel.PWA/_Imports.razor @@ -24,3 +24,4 @@ @using Blazorise.Extensions @using NetinaShop.AdminPanel.PWA.Utilities @using Microsoft.AspNetCore.Components.Authorization +@using Append.Blazor.Printing