|
|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
using System.Text;
|
|
|
|
|
@ -19,18 +18,18 @@ public partial class QuoteAdd {
|
|
|
|
|
private bool isCreatingPdf;
|
|
|
|
|
private bool isCreatingTex;
|
|
|
|
|
private bool lineItemsNotReady = true;
|
|
|
|
|
private CustomDescription? newCustomDescription;
|
|
|
|
|
private static CustomDescription newCustomDescription;
|
|
|
|
|
private bool pdfNotReady = true;
|
|
|
|
|
private Quote quote = new();
|
|
|
|
|
private Contact? selectedContact;
|
|
|
|
|
private LineItem? selectedLineItem;
|
|
|
|
|
private List<CustomDescription>? suggestedCustomDescriptions;
|
|
|
|
|
// private List<CustomDescription>? suggestedCustomDescriptions;
|
|
|
|
|
private bool texNotReady = true;
|
|
|
|
|
private string? url;
|
|
|
|
|
[CascadingParameter] private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
|
|
|
|
|
[Inject] public IModalService? ModalService { get; set; }
|
|
|
|
|
[Inject] public static IModalService ModalService { get; set; }
|
|
|
|
|
|
|
|
|
|
public Task ShowCustomDescriptionModal() {
|
|
|
|
|
public static Task ShowCustomDescriptionModal(List<CustomDescription> suggestedCustomDescriptions) {
|
|
|
|
|
return ModalService.Show<CustomDescriptionModal>(builder => {
|
|
|
|
|
builder.Add(parameter => parameter.CustomDescription, newCustomDescription);
|
|
|
|
|
builder.Add(parameter => parameter.SuggestedCustomDescriptions, suggestedCustomDescriptions);
|
|
|
|
|
@ -44,7 +43,7 @@ public partial class QuoteAdd {
|
|
|
|
|
contacts = await GenericController.GetAllAsync<Contact>();
|
|
|
|
|
selectedContact = contacts?.FirstOrDefault();
|
|
|
|
|
if (selectedContact is not null)
|
|
|
|
|
await OnSelectedContactChanged(selectedContact);
|
|
|
|
|
await SelectedContactChanged(selectedContact);
|
|
|
|
|
|
|
|
|
|
SalesRep newSalesRep = new() {
|
|
|
|
|
LastName = "Woitschetzki",
|
|
|
|
|
@ -83,37 +82,8 @@ public partial class QuoteAdd {
|
|
|
|
|
_ = stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
using StreamReader reader = new(stream);
|
|
|
|
|
string fileContent = await reader.ReadToEndAsync();
|
|
|
|
|
quote = QuoteHandling.ReadLineItems(quote, fileContent);
|
|
|
|
|
if (quote.Recipient?.Account?.AccountName is not null) quote = HostingService.SetPath(quote);
|
|
|
|
|
if (quote.LineItems is null) return;
|
|
|
|
|
|
|
|
|
|
FileService.WriteQuoteToTsv(fileContent, quote);
|
|
|
|
|
|
|
|
|
|
//TODO Load all relevant CustomDescriptions upfront
|
|
|
|
|
foreach (LineItem lineItem in quote.LineItems) {
|
|
|
|
|
newCustomDescription = await GenericController.GetAsync<CustomDescription>(newCustomDescription => newCustomDescription.ProductNumber.Equals(lineItem.ProductNumber, StringComparison.Ordinal) && newCustomDescription.OptionNumber.Equals(lineItem.OptionNumber, StringComparison.Ordinal));
|
|
|
|
|
|
|
|
|
|
if (newCustomDescription is null) {
|
|
|
|
|
Console.WriteLine($"Keine CustomDescription für {lineItem.ProductNumber}#{lineItem.OptionNumber} verfügbar!");
|
|
|
|
|
suggestedCustomDescriptions = await SuggestCustomDescriptions(lineItem);
|
|
|
|
|
newCustomDescription = new() { ProductNumber = lineItem.ProductNumber, OptionNumber = lineItem.OptionNumber, Heading = lineItem.SapShortDescription, DescriptionText = lineItem.SapLongDescription };
|
|
|
|
|
|
|
|
|
|
//Show windows to edit new cD
|
|
|
|
|
await ShowCustomDescriptionModal();
|
|
|
|
|
//TODO need to wait for modal!
|
|
|
|
|
|
|
|
|
|
//Insert new CustomDescription to db
|
|
|
|
|
newCustomDescription.AccountId = 1;
|
|
|
|
|
_ = await GenericController.InsertAsync(newCustomDescription);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lineItem.Product = await GenericController.GetAsync<Product>(p => p.ProductNumber.Equals(lineItem.ProductNumber) && p.OptionNumber.Equals(lineItem.OptionNumber));
|
|
|
|
|
if (lineItem.Product is null) return;
|
|
|
|
|
lineItem.ProductId = lineItem.Product.ProductId;
|
|
|
|
|
lineItem.Product.CustomDescription = await GenericController.GetAsync<CustomDescription>(cD => cD.ProductNumber.Equals(lineItem.ProductNumber) && cD.OptionNumber.Equals(lineItem.OptionNumber));
|
|
|
|
|
lineItem.Quote = quote;
|
|
|
|
|
lineItem.QuoteId = lineItem.Quote.QuoteId;
|
|
|
|
|
}
|
|
|
|
|
quote = await QuoteHandling.GenerateQuoteFromString(quote, fileContent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exc) {
|
|
|
|
|
@ -125,18 +95,6 @@ public partial class QuoteAdd {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<List<CustomDescription>?> SuggestCustomDescriptions(LineItem lineItem) {
|
|
|
|
|
//IList<CustomDescription>? fromProductNumber = await genericController.GetAllAsync<CustomDescription>(cD => cD.ProductNumber.Equals(lineItem.ProductNumber, StringComparison.Ordinal));
|
|
|
|
|
IList<CustomDescription>? fromOptionNumber = new List<CustomDescription>();
|
|
|
|
|
if (lineItem.OptionNumber != "")
|
|
|
|
|
fromOptionNumber = await GenericController.GetAllAsync<CustomDescription>(cD => cD.OptionNumber.Equals(lineItem.OptionNumber, StringComparison.Ordinal));
|
|
|
|
|
//if (fromOptionNumber == null && fromProductNumber == null) return null;
|
|
|
|
|
//if (fromOptionNumber == null) return fromProductNumber.ToList();
|
|
|
|
|
//if (fromProductNumber == null) return fromOptionNumber.ToList();
|
|
|
|
|
//return fromProductNumber.Union(fromOptionNumber).ToList();
|
|
|
|
|
return fromOptionNumber.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SelectQuoteOnWritten(FileWrittenEventArgs e) {
|
|
|
|
|
Console.WriteLine($"File: {e.File.Name} Position: {e.Position} Data: {Convert.ToBase64String(e.Data)}");
|
|
|
|
|
}
|
|
|
|
|
@ -145,7 +103,7 @@ public partial class QuoteAdd {
|
|
|
|
|
Console.WriteLine($"File: {e.File.Name} Progress: {e.Percentage}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnSelectedContactChanged(Contact newSelectedContact) {
|
|
|
|
|
private async Task SelectedContactChanged(Contact newSelectedContact) {
|
|
|
|
|
quote.Recipient = await GenericController.GetAsync<Contact>(c => c.ContactId.Equals(newSelectedContact.ContactId));
|
|
|
|
|
|
|
|
|
|
if (quote.Recipient is not null)
|
|
|
|
|
@ -193,55 +151,31 @@ public partial class QuoteAdd {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnOpenPdfApp() {
|
|
|
|
|
PdfService.OpenPdfWithOkular(quote);
|
|
|
|
|
}
|
|
|
|
|
private void OnOpenPdfApp() => PdfService.OpenPdfWithOkular(quote);
|
|
|
|
|
|
|
|
|
|
private async Task OnOpenPdfNewTab() {
|
|
|
|
|
await JsRuntime.InvokeVoidAsync("OpenNewTab", $"quotes/{url}");
|
|
|
|
|
}
|
|
|
|
|
private async Task OnOpenPdfNewTab() => await JsRuntime.InvokeVoidAsync("OpenNewTab", $"quotes/{url}");
|
|
|
|
|
|
|
|
|
|
private void OnDescriptionChanged(string description) {
|
|
|
|
|
quote.Description = description;
|
|
|
|
|
}
|
|
|
|
|
private void OnDescriptionChanged(string description) => quote.Description = description;
|
|
|
|
|
|
|
|
|
|
private void OnQuotationNumberChanged(string quotationNumber) {
|
|
|
|
|
quote.QuotationNumber = quotationNumber;
|
|
|
|
|
}
|
|
|
|
|
private void OnQuotationNumberChanged(string quotationNumber) => quote.QuotationNumber = quotationNumber;
|
|
|
|
|
|
|
|
|
|
private void OnValidForChanged(string validFor) {
|
|
|
|
|
quote.ValidFor = byte.Parse(validFor);
|
|
|
|
|
}
|
|
|
|
|
private void OnValidForChanged(string validFor) => quote.ValidFor = byte.Parse(validFor);
|
|
|
|
|
|
|
|
|
|
private void OnVATChanged(string vat) {
|
|
|
|
|
quote.Vat = float.Parse(vat);
|
|
|
|
|
}
|
|
|
|
|
private void OnVATChanged(string vat) => quote.Vat = float.Parse(vat);
|
|
|
|
|
|
|
|
|
|
private void OnIsPriceInformationChanged(bool isPriceInformation) {
|
|
|
|
|
quote.IsPriceInformation = isPriceInformation;
|
|
|
|
|
}
|
|
|
|
|
private void OnIsPriceInformationChanged(bool isPriceInformation) => quote.IsPriceInformation = isPriceInformation;
|
|
|
|
|
|
|
|
|
|
private void OnShowBruttoChanged(bool onShowBrutto) {
|
|
|
|
|
quote.ShowBrutto = onShowBrutto;
|
|
|
|
|
}
|
|
|
|
|
private void OnShowBruttoChanged(bool onShowBrutto) => quote.ShowBrutto = onShowBrutto;
|
|
|
|
|
|
|
|
|
|
private void OnShowDiscountsChanged(bool showDiscount) {
|
|
|
|
|
quote.ShowDiscounts = showDiscount;
|
|
|
|
|
}
|
|
|
|
|
private void OnShowDiscountsChanged(bool showDiscount) => quote.ShowDiscounts = showDiscount;
|
|
|
|
|
|
|
|
|
|
private void OnShowSinglePricesChanged(bool showSinglePrices) {
|
|
|
|
|
quote.ShowSinglePrices = showSinglePrices;
|
|
|
|
|
}
|
|
|
|
|
private void OnShowSinglePricesChanged(bool showSinglePrices) => quote.ShowSinglePrices = showSinglePrices;
|
|
|
|
|
|
|
|
|
|
private void OnSelectedLineItemChanged(LineItem _selectedLineItem) {
|
|
|
|
|
selectedLineItem = _selectedLineItem;
|
|
|
|
|
}
|
|
|
|
|
private void OnSelectedLineItemChanged(LineItem newSelectedLineItem) => selectedLineItem = newSelectedLineItem;
|
|
|
|
|
|
|
|
|
|
private void OnWarrantyChanged(string warranty) {
|
|
|
|
|
quote.Warranty = int.Parse(warranty);
|
|
|
|
|
}
|
|
|
|
|
private void OnWarrantyChanged(string warranty) => quote.Warranty = int.Parse(warranty);
|
|
|
|
|
|
|
|
|
|
private void OnCancel() {
|
|
|
|
|
NavigationManager.NavigateTo("Quotes/QuoteIndex");
|
|
|
|
|
}
|
|
|
|
|
private void OnCancel() => NavigationManager.NavigateTo("Quotes/QuoteIndex");
|
|
|
|
|
|
|
|
|
|
private async Task<string> GetClipboardTextAsync() => await JsRuntime.InvokeAsync<string>("navigator.clipboard.readText");
|
|
|
|
|
}
|