diff --git a/Gremlin/MVVM/Operations/PDFHandler.cs b/Gremlin/MVVM/Operations/PDFHandler.cs index fd394ce..1e055e1 100644 --- a/Gremlin/MVVM/Operations/PDFHandler.cs +++ b/Gremlin/MVVM/Operations/PDFHandler.cs @@ -66,26 +66,26 @@ namespace Gremlin.Operations } } - private static void RunningPDFLaTeX(string quotePath, string fileName, int runs) - { - for (int i = 0; i < runs; i++) - { - using (Process process = new()) - { - process.StartInfo.FileName = "pdflatex"; - process.StartInfo.Arguments = quotePath == "" ? $"{fileName}.tex" : $"{quotePath}\\{fileName}.tex"; - process.StartInfo.UseShellExecute = false; - try - { - _ = process.Start(); - } - catch (Exception ex) - { - ErrorHandler.ShowErrorInMessageBox(ex); - } - process.WaitForExit(); - } - } - } + //private static void RunningPDFLaTeX(string quotePath, string fileName, int runs) + //{ + // for (int i = 0; i < runs; i++) + // { + // using (Process process = new()) + // { + // process.StartInfo.FileName = "pdflatex"; + // process.StartInfo.Arguments = quotePath == "" ? $"{fileName}.tex" : $"{quotePath}\\{fileName}.tex"; + // process.StartInfo.UseShellExecute = false; + // try + // { + // _ = process.Start(); + // } + // catch (Exception ex) + // { + // ErrorHandler.ShowErrorInMessageBox(ex); + // } + // process.WaitForExit(); + // } + // } + //} } } diff --git a/Gremlin/MVVM/ViewModels/QuoteViewModel.cs b/Gremlin/MVVM/ViewModels/QuoteViewModel.cs index eb4d893..6c95526 100644 --- a/Gremlin/MVVM/ViewModels/QuoteViewModel.cs +++ b/Gremlin/MVVM/ViewModels/QuoteViewModel.cs @@ -2,6 +2,7 @@ using Microsoft.Win32; using System; using System.Collections.ObjectModel; +using System.Diagnostics; using System.IO; using System.Linq; @@ -17,9 +18,6 @@ namespace Gremlin.MVVM private string _quoteNumber; private int _warranty = 12; private int _validity = 60; - private decimal _totalListprice; - private decimal _averageDiscount; - private decimal _totalNet; private float _vAT = 19f; private bool? _showBrutto = true; private bool? _singlePrices = true; @@ -31,7 +29,7 @@ namespace Gremlin.MVVM private bool? _showDiscounts = true; public string QuoteType { get => _quoteType; set { _quoteType = value; NotifyOfPropertyChange(() => QuoteType); } } - + public string QuotePath { get => _quotePath; @@ -42,7 +40,6 @@ namespace Gremlin.MVVM } } - public bool? ShowBrutto { get => _showBrutto; set { _showBrutto = value; NotifyOfPropertyChange(() => ShowBrutto); } } public string QuoteNumber { get => _quoteNumber; set { _quoteNumber = value; NotifyOfPropertyChange(() => QuoteNumber); } } public int Warranty { get => _warranty; set { _warranty = value; NotifyOfPropertyChange(() => Warranty); } } @@ -52,14 +49,16 @@ namespace Gremlin.MVVM public bool? AttachDataSheets { get => _attachDataSheets; set { _attachDataSheets = value; NotifyOfPropertyChange(() => AttachDataSheets); } } public bool? UseMailTemplate { get => _useMailTemplate; set { _useMailTemplate = value; NotifyOfPropertyChange(() => UseMailTemplate); } } public bool? ShowDiscounts { get => _showDiscounts; set { _showDiscounts = value; NotifyOfPropertyChange(() => ShowDiscounts); } } + public float VAT { get => _vAT; set { _vAT = value; NotifyOfPropertyChange(() => VAT); } } public ObservableCollection LineItemsViewModel { get => _lineItemsVM; set { _lineItemsVM = value; NotifyOfPropertyChange(() => LineItemsViewModel); } } public ContactViewModel Recipient { get => _recipient; set { _recipient = value; NotifyOfPropertyChange(() => Recipient); } } public ContactViewModel SalesRep { get => _salesRep; set { _salesRep = value; NotifyOfPropertyChange(() => SalesRep); } } - public decimal TotalListprice { get => _totalListprice; set { _totalListprice = value; NotifyOfPropertyChange(() => TotalListprice); } } - public decimal AverageDiscount { get => _averageDiscount; set { _averageDiscount = value; NotifyOfPropertyChange(() => AverageDiscount); } } - public decimal TotalNet { get => _totalNet; set { _totalNet = value; NotifyOfPropertyChange(() => TotalNet); } } - public float VAT { get => _vAT; set { _vAT = value; NotifyOfPropertyChange(() => VAT); } } + + public decimal TotalListprice { get => GetTotal("TotalListprice"); } + public decimal AverageDiscount { get => GetTotal("AverageDiscount"); } + public decimal TotalNet { get => GetTotal("TotalNet"); } + public bool QuoteContains3PP { get => _quoteContains3PP; set { _quoteContains3PP = value; NotifyOfPropertyChange(() => QuoteContains3PP); } } public bool QuoteContainsRB { get => _quoteContainsRB; set { _quoteContainsRB = value; NotifyOfPropertyChange(() => QuoteContainsRB); } } @@ -100,7 +99,8 @@ namespace Gremlin.MVVM internal static QuoteViewModel CreateQuote(string quoteNumber, ContactViewModel recipient, ContactViewModel salesRep, float vAT = 19f, string quoteType = "ein Analysegerät", bool? brutto = true, int warranty = 12, bool? singlePrices = true, bool? brochures = true, bool? dataSheets = true, bool? mailTemplate = true, string quotePath = "", int validity = 60, bool? showDiscounts = true) { - decimal totalListprice = 0, totalDiscount = 0, calcTotalNet = 0; + //decimal totalListprice = 0; + //decimal totalDiscount = 0, calcTotalNet = 0; bool quoteContains3PP = false, quoteContainsRB = false; QuoteViewModel quoteVM = new(quoteNumber, quoteType, recipient, salesRep, brutto, vAT, warranty, validity, quotePath, singlePrices, brochures, dataSheets, mailTemplate, showDiscounts); @@ -112,9 +112,9 @@ namespace Gremlin.MVVM foreach (LineItemViewModel lineItemVM in lineItemsVM) { - totalListprice += lineItemVM.ListPrice; - totalDiscount += lineItemVM.TotalDiscount; - calcTotalNet += lineItemVM.CalcTotalNet; //Use calculated values + //totalListprice += lineItemVM.ListPrice; + //totalDiscount += lineItemVM.TotalDiscount; + //calcTotalNet += lineItemVM.CalcTotalNet; //Use calculated values switch (lineItemVM.ProductLine) { @@ -136,13 +136,13 @@ namespace Gremlin.MVVM quoteVM.LineItemsViewModel.Add(lineItemVM); } + //quoteVM.TotalListprice = totalListprice; - quoteVM.TotalListprice = totalListprice; - if (lineItemsVM.Count != 0) - { - quoteVM.AverageDiscount = (decimal)MathF.Round((float)(totalDiscount / lineItemsVM.Count), 3); - } - quoteVM.TotalNet = calcTotalNet; //Use calculated values + //if (lineItemsVM.Count != 0) + //{ + // quoteVM.AverageDiscount = (decimal)MathF.Round((float)(totalDiscount / lineItemsVM.Count), 3); + //} + //quoteVM.TotalNet = calcTotalNet; //Use calculated values quoteVM.QuoteContainsRB = quoteContainsRB; quoteVM.QuoteContains3PP = quoteContains3PP; @@ -187,5 +187,28 @@ namespace Gremlin.MVVM QuotePath = fileInfo.DirectoryName; } } + + private decimal GetTotal(string type) + { + decimal total = 0; + + foreach (LineItemViewModel lineItemVM in LineItemsViewModel) + { + switch (type) + { + case "TotalListprice": + total += lineItemVM.ListPrice; break; + case "TotalNet": + total += lineItemVM.CalcTotalNet; break; + case "AverageDiscount": + total += lineItemVM.TotalDiscount; break; + } + } + + if (type == "AverageDiscount") { total /= LineItemsViewModel.Count; } + + Debug.WriteLine($"{type} = {total}"); + return total; + } } } \ No newline at end of file