SpinningWheel while creating Tex and Pdf
parent
653e02a6fb
commit
ec0fd17ee8
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "7.0.3",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,213 +1,236 @@
|
||||
using System.Diagnostics;
|
||||
using Gremlin_BlazorServer.Data.EntityClasses;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Gremlin_BlazorServer.Data.EntityClasses;
|
||||
|
||||
namespace Gremlin_BlazorServer.Services;
|
||||
|
||||
public static class QuoteHandling
|
||||
{
|
||||
public static StringBuilder? CreateTex(Quote quote)
|
||||
{
|
||||
StringBuilder? texString = TexService.CreateTex(quote);
|
||||
if (texString == null)
|
||||
return null;
|
||||
Console.WriteLine(
|
||||
texString.Length > 0
|
||||
? "Creating TexFile succesfully."
|
||||
: "Error during TexFile creation!"
|
||||
);
|
||||
return texString;
|
||||
}
|
||||
|
||||
//FromWindowsGremlin
|
||||
|
||||
public static Quote ReadLineItems(Quote quote, string clipboard)
|
||||
{
|
||||
try
|
||||
{
|
||||
quote = ResetTotals(quote);
|
||||
|
||||
quote.LineItems = ReadLineItemsFromClipboard(clipboard);
|
||||
|
||||
quote.QuoteContains3Pp = DoesContains(quote, "3PP");
|
||||
quote.QuoteContainsRb = DoesContains(quote, "RB");
|
||||
|
||||
quote.TotalListprice = GetTotal(quote, "TotalListprice");
|
||||
quote.TotalDiscount = GetTotal(quote, "AverageDiscount");
|
||||
quote.TotalNet = GetTotal(quote, "TotalNet");
|
||||
|
||||
if (quote.Recipient?.Account != null)
|
||||
quote.ValidFor = CheckForAcademic(quote.Recipient.Account);
|
||||
|
||||
foreach (LineItem lineItem in quote.LineItems)
|
||||
{
|
||||
if (lineItem.OptionNumber == null)
|
||||
break;
|
||||
|
||||
if (lineItem.OptionNumber.StartsWith("8D"))
|
||||
quote.Warranty = int.Parse(lineItem.OptionNumber.Last().ToString()) * 12;
|
||||
|
||||
quote.Warranty = lineItem.OptionNumber switch
|
||||
{
|
||||
"9EC" => 24,
|
||||
"9CC" => 36,
|
||||
_ => quote.Warranty
|
||||
};
|
||||
}
|
||||
|
||||
quote = CalculateTotals(quote);
|
||||
return quote;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<LineItem> ReadLineItemsFromClipboard(string clipboard)
|
||||
{
|
||||
//Zeilen aufteilen
|
||||
IEnumerable<string> clipboardLines = clipboard.Split(Environment.NewLine.ToCharArray());
|
||||
List<string[]> clipboardList = (
|
||||
from clipboardLine in clipboardLines
|
||||
where clipboardLine != ""
|
||||
select clipboardLine.Split('\t')
|
||||
).ToList();
|
||||
return ParseClipboardList(clipboardList);
|
||||
}
|
||||
|
||||
private static List<LineItem> ParseClipboardList(List<string[]> lineItemStrings)
|
||||
{
|
||||
List<LineItem> lineItems = new();
|
||||
CultureInfo cultureInfoUs = new("en-US");
|
||||
|
||||
foreach (string[] lineItemString in lineItemStrings)
|
||||
//Anzahl an Spalten entspricht Clipboard
|
||||
if (lineItemString.Length == 19)
|
||||
{
|
||||
//Header ignorieren
|
||||
if (lineItemString[0] == "#")
|
||||
continue;
|
||||
|
||||
//Dateiinhalt in Klasse schreiben
|
||||
LineItem lineItem =
|
||||
new()
|
||||
{
|
||||
Position = ushort.Parse(lineItemString[0]),
|
||||
ProductNumber = lineItemString[1],
|
||||
OptionNumber = lineItemString[2],
|
||||
ProductLine = lineItemString[3],
|
||||
SapShortDescription = lineItemString[4],
|
||||
Amount = ushort.Parse(lineItemString[5]),
|
||||
ListPrice = decimal.Parse(lineItemString[6], cultureInfoUs),
|
||||
TotalDiscount = decimal.Parse(lineItemString[9], cultureInfoUs),
|
||||
NetPrice = decimal.Parse(lineItemString[10], cultureInfoUs),
|
||||
Total = decimal.Parse(lineItemString[11], cultureInfoUs),
|
||||
SalesDiscount = decimal.Parse(lineItemString[12], cultureInfoUs),
|
||||
ContractualDiscount = decimal.Parse(lineItemString[13], cultureInfoUs),
|
||||
PromotionalDiscount = decimal.Parse(lineItemString[14], cultureInfoUs),
|
||||
DemoDiscount = decimal.Parse(lineItemString[15], cultureInfoUs)
|
||||
};
|
||||
|
||||
lineItems.Add(lineItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Angebot konnte nicht eingelesen werden!");
|
||||
}
|
||||
|
||||
return lineItems;
|
||||
}
|
||||
|
||||
private static byte CheckForAcademic(Account account)
|
||||
{
|
||||
if (account.AccountType?.AccountTypeCode == null)
|
||||
return 60;
|
||||
return (byte)(account.AccountType.AccountTypeCode.StartsWith("N") ? 90 : 60);
|
||||
}
|
||||
|
||||
private static decimal GetFreight(decimal net, decimal freight)
|
||||
{
|
||||
decimal freightNet = net * freight / 100;
|
||||
return freightNet < 3000 ? freightNet : 3000;
|
||||
}
|
||||
|
||||
private static Quote CalculateTotals(Quote quote)
|
||||
{
|
||||
quote.TotalFreightOnly = GetFreight(quote.TotalNet, quote.Freight);
|
||||
quote.TotalFreight = quote.TotalNet + quote.TotalFreightOnly;
|
||||
quote.TotalVat = quote.TotalFreight * Convert.ToDecimal(quote.Vat) / 100;
|
||||
quote.TotalGross = quote.TotalFreight * (100 + Convert.ToDecimal(quote.Vat)) / 100;
|
||||
return quote;
|
||||
}
|
||||
|
||||
private static Quote ResetTotals(Quote quote)
|
||||
{
|
||||
quote.TotalListprice = 0;
|
||||
quote.TotalNet = 0;
|
||||
quote.TotalFreightOnly = 0;
|
||||
quote.TotalFreight = 0;
|
||||
quote.TotalVat = 0;
|
||||
quote.TotalGross = 0;
|
||||
|
||||
return quote;
|
||||
}
|
||||
|
||||
private static decimal GetTotal(Quote quote, string type)
|
||||
{
|
||||
decimal total = 0;
|
||||
if (quote.LineItems == null)
|
||||
return total;
|
||||
foreach (LineItem lineItem in quote.LineItems)
|
||||
switch (type)
|
||||
{
|
||||
case "TotalListprice":
|
||||
total += lineItem.ListPrice;
|
||||
break;
|
||||
case "TotalNet":
|
||||
total += lineItem.Total;
|
||||
break;
|
||||
case "AverageDiscount":
|
||||
total += lineItem.TotalDiscount;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((type == "AverageDiscount") & (quote.LineItems.Count != 0))
|
||||
total /= quote.LineItems.Count;
|
||||
return total;
|
||||
}
|
||||
|
||||
private static bool DoesContains(Quote quote, string type)
|
||||
{
|
||||
if (quote.LineItems == null)
|
||||
return false;
|
||||
foreach (LineItem lineItem in quote.LineItems)
|
||||
switch (type)
|
||||
{
|
||||
case "3PP":
|
||||
if (lineItem.ProductLine == "3PP")
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"Quote contains 3PP with ProductNumber {lineItem.ProductNumber}"
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case "RB":
|
||||
if ((lineItem.ProductLine == "RB") & (lineItem.ProductNumber != "R2005A"))
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"Quote contains RB with ProductNumber {lineItem.ProductNumber}"
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public static async Task<StringBuilder?> CreateTex(Quote quote)
|
||||
{
|
||||
StringBuilder? texString = await TexService.CreateTex(quote);
|
||||
if (texString == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Console.WriteLine(
|
||||
texString.Length > 0
|
||||
? "Creating TexFile succesfully."
|
||||
: "Error during TexFile creation!"
|
||||
);
|
||||
return texString;
|
||||
}
|
||||
|
||||
//FromWindowsGremlin
|
||||
|
||||
public static Quote ReadLineItems(Quote quote, string clipboard)
|
||||
{
|
||||
try
|
||||
{
|
||||
quote = ResetTotals(quote);
|
||||
|
||||
quote.LineItems = ReadLineItemsFromClipboard(clipboard);
|
||||
|
||||
quote.QuoteContains3Pp = DoesContains(quote, "3PP");
|
||||
quote.QuoteContainsRb = DoesContains(quote, "RB");
|
||||
|
||||
quote.TotalListprice = GetTotal(quote, "TotalListprice");
|
||||
quote.TotalDiscount = GetTotal(quote, "AverageDiscount");
|
||||
quote.TotalNet = GetTotal(quote, "TotalNet");
|
||||
|
||||
if (quote.Recipient?.Account != null)
|
||||
{
|
||||
quote.ValidFor = CheckForAcademic(quote.Recipient.Account);
|
||||
}
|
||||
|
||||
foreach (LineItem lineItem in quote.LineItems)
|
||||
{
|
||||
if (lineItem.OptionNumber == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (lineItem.OptionNumber.StartsWith("8D"))
|
||||
{
|
||||
quote.Warranty = int.Parse(lineItem.OptionNumber.Last().ToString()) * 12;
|
||||
}
|
||||
|
||||
quote.Warranty = lineItem.OptionNumber switch
|
||||
{
|
||||
"9EC" => 24,
|
||||
"9CC" => 36,
|
||||
_ => quote.Warranty
|
||||
};
|
||||
}
|
||||
|
||||
quote = CalculateTotals(quote);
|
||||
return quote;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<LineItem> ReadLineItemsFromClipboard(string clipboard)
|
||||
{
|
||||
//Zeilen aufteilen
|
||||
IEnumerable<string> clipboardLines = clipboard.Split(Environment.NewLine.ToCharArray());
|
||||
List<string[]> clipboardList = (
|
||||
from clipboardLine in clipboardLines
|
||||
where clipboardLine != ""
|
||||
select clipboardLine.Split('\t')
|
||||
).ToList();
|
||||
return ParseClipboardList(clipboardList);
|
||||
}
|
||||
|
||||
private static List<LineItem> ParseClipboardList(List<string[]> lineItemStrings)
|
||||
{
|
||||
List<LineItem> lineItems = new();
|
||||
CultureInfo cultureInfoUs = new("en-US");
|
||||
|
||||
foreach (string[] lineItemString in lineItemStrings)
|
||||
{
|
||||
//Anzahl an Spalten entspricht Clipboard
|
||||
if (lineItemString.Length == 19)
|
||||
{
|
||||
//Header ignorieren
|
||||
if (lineItemString[0] == "#")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//Dateiinhalt in Klasse schreiben
|
||||
LineItem lineItem =
|
||||
new()
|
||||
{
|
||||
Position = ushort.Parse(lineItemString[0]),
|
||||
ProductNumber = lineItemString[1],
|
||||
OptionNumber = lineItemString[2],
|
||||
ProductLine = lineItemString[3],
|
||||
SapShortDescription = lineItemString[4],
|
||||
Amount = ushort.Parse(lineItemString[5]),
|
||||
ListPrice = decimal.Parse(lineItemString[6], cultureInfoUs),
|
||||
TotalDiscount = decimal.Parse(lineItemString[9], cultureInfoUs),
|
||||
NetPrice = decimal.Parse(lineItemString[10], cultureInfoUs),
|
||||
Total = decimal.Parse(lineItemString[11], cultureInfoUs),
|
||||
SalesDiscount = decimal.Parse(lineItemString[12], cultureInfoUs),
|
||||
ContractualDiscount = decimal.Parse(lineItemString[13], cultureInfoUs),
|
||||
PromotionalDiscount = decimal.Parse(lineItemString[14], cultureInfoUs),
|
||||
DemoDiscount = decimal.Parse(lineItemString[15], cultureInfoUs)
|
||||
};
|
||||
|
||||
lineItems.Add(lineItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Angebot konnte nicht eingelesen werden!");
|
||||
}
|
||||
}
|
||||
|
||||
return lineItems;
|
||||
}
|
||||
|
||||
private static byte CheckForAcademic(Account account)
|
||||
{
|
||||
return account.AccountType?.AccountTypeCode == null ? (byte)60 : (byte)(account.AccountType.AccountTypeCode.StartsWith("N") ? 90 : 60);
|
||||
}
|
||||
|
||||
private static decimal GetFreight(decimal net, decimal freight)
|
||||
{
|
||||
decimal freightNet = net * freight / 100;
|
||||
return freightNet < 3000 ? freightNet : 3000;
|
||||
}
|
||||
|
||||
private static Quote CalculateTotals(Quote quote)
|
||||
{
|
||||
quote.TotalFreightOnly = GetFreight(quote.TotalNet, quote.Freight);
|
||||
quote.TotalFreight = quote.TotalNet + quote.TotalFreightOnly;
|
||||
quote.TotalVat = quote.TotalFreight * Convert.ToDecimal(quote.Vat) / 100;
|
||||
quote.TotalGross = quote.TotalFreight * (100 + Convert.ToDecimal(quote.Vat)) / 100;
|
||||
return quote;
|
||||
}
|
||||
|
||||
private static Quote ResetTotals(Quote quote)
|
||||
{
|
||||
quote.TotalListprice = 0;
|
||||
quote.TotalNet = 0;
|
||||
quote.TotalFreightOnly = 0;
|
||||
quote.TotalFreight = 0;
|
||||
quote.TotalVat = 0;
|
||||
quote.TotalGross = 0;
|
||||
|
||||
return quote;
|
||||
}
|
||||
|
||||
private static decimal GetTotal(Quote quote, string type)
|
||||
{
|
||||
decimal total = 0;
|
||||
if (quote.LineItems == null)
|
||||
{
|
||||
return total;
|
||||
}
|
||||
|
||||
foreach (LineItem lineItem in quote.LineItems)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "TotalListprice":
|
||||
total += lineItem.ListPrice;
|
||||
break;
|
||||
case "TotalNet":
|
||||
total += lineItem.Total;
|
||||
break;
|
||||
case "AverageDiscount":
|
||||
total += lineItem.TotalDiscount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((type == "AverageDiscount") & (quote.LineItems.Count != 0))
|
||||
{
|
||||
total /= quote.LineItems.Count;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
private static bool DoesContains(Quote quote, string type)
|
||||
{
|
||||
if (quote.LineItems == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (LineItem lineItem in quote.LineItems)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "3PP":
|
||||
if (lineItem.ProductLine == "3PP")
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"Quote contains 3PP with ProductNumber {lineItem.ProductNumber}"
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case "RB":
|
||||
if ((lineItem.ProductLine == "RB") & (lineItem.ProductNumber != "R2005A"))
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"Quote contains RB with ProductNumber {lineItem.ProductNumber}"
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 250 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
# Part Number Opt PL Description Qty Price EUR Breaks EUR Uplift % Total Discount % Net EUR Total EUR Sales Discount YA9% Contractual Discount Y99% Promotion Discount Y07% Demo Discount Y04% PH Code PH Description YMax
|
||||
1 G2790A AZ Agilent 8860 GC-System Kundenspezifisch 1 15152 0 0 45 8333.6 8333.6 45 0 0 0 ISG700G700 6820 GC system
|
||||
2 G2790A 163 AZ S/SL-Kapillareinlass mit EPC fuer 8860 1 2542 0 0 45 1398.1 1398.1 45 0 0 0
|
||||
3 G2790A 205 AZ 7650A 50-Probenflasche ALS 1 13289 0 0 45 7308.95 7308.95 45 0 0 0
|
||||
4 G2790A 210 AZ FID mit EPC fuer 8860 1 3369 0 0 45 1852.95 1852.95 45 0 0 0
|
||||
5 G2790A 324 AZ Hydrogen Sensor Module Series 2 1 3780 0 0 45 2079 2079 45 0 0 0
|
||||
6 M8414AA LI OpenLab CDS Workstation PC-Paket 1 17697 0 0 45 9733.35 9733.35 45 0 0 0 ISF300F110 OpenLAB CDS w/Hardware
|
||||
7 M8414AA 002 LI GC Geraeteverbindung 1 0 0 0 45 0 0 45 0 0 0
|
||||
|
Binary file not shown.
@ -0,0 +1,9 @@
|
||||
# Part Number Opt PL Description Qty Price EUR Breaks EUR Uplift % Total Discount % Net EUR Total EUR Sales Discount YA9% Contractual Discount Y99% Promotion Discount Y07% Demo Discount Y04% PH Code PH Description YMax
|
||||
1 G2790A AZ Agilent 8860 GC-System Kundenspezifisch 1 15152 0 0 45 8333.6 8333.6 45 0 0 0 ISG700G700 6820 GC system
|
||||
2 G2790A 163 AZ S/SL-Kapillareinlass mit EPC fuer 8860 1 2542 0 0 45 1398.1 1398.1 45 0 0 0
|
||||
3 G2790A 205 AZ 7650A 50-Probenflasche ALS 1 13289 0 0 45 7308.95 7308.95 45 0 0 0
|
||||
4 G2790A 210 AZ FID mit EPC fuer 8860 1 3369 0 0 45 1852.95 1852.95 45 0 0 0
|
||||
5 G2790A 324 AZ Hydrogen Sensor Module Series 2 1 3780 0 0 45 2079 2079 45 0 0 0
|
||||
6 M8414AA LI OpenLab CDS Workstation PC-Paket 1 17697 0 0 45 9733.35 9733.35 45 0 0 0 ISF300F110 OpenLAB CDS w/Hardware
|
||||
7 M8414AA 002 LI GC Geraeteverbindung 1 0 0 0 45 0 0 45 0 0 0
|
||||
|
||||
|
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
# Part Number Opt PL Description Qty Price EUR Breaks EUR Uplift % Total Discount % Net EUR Total EUR Sales Discount YA9% Contractual Discount Y99% Promotion Discount Y07% Demo Discount Y04% PH Code PH Description YMax
|
||||
1 G2790A AZ Agilent 8860 GC-System Kundenspezifisch 1 15152 0 0 45 8333.6 8333.6 45 0 0 0 ISG700G700 6820 GC system
|
||||
2 G2790A 163 AZ S/SL-Kapillareinlass mit EPC fuer 8860 1 2542 0 0 45 1398.1 1398.1 45 0 0 0
|
||||
3 G2790A 205 AZ 7650A 50-Probenflasche ALS 1 13289 0 0 45 7308.95 7308.95 45 0 0 0
|
||||
4 G2790A 210 AZ FID mit EPC fuer 8860 1 3369 0 0 45 1852.95 1852.95 45 0 0 0
|
||||
5 G2790A 324 AZ Hydrogen Sensor Module Series 2 1 3780 0 0 45 2079 2079 45 0 0 0
|
||||
6 M8414AA LI OpenLab CDS Workstation PC-Paket 1 17697 0 0 45 9733.35 9733.35 45 0 0 0 ISF300F110 OpenLAB CDS w/Hardware
|
||||
7 M8414AA 002 LI GC Geraeteverbindung 1 0 0 0 45 0 0 45 0 0 0
|
||||
|
Loading…
Reference in New Issue