Browse Source

Added PostedSTatus field to IPostable. Added button to process items on InvoicePanel, and added postedstatus column in InvoiceListGrid

Kenric Nugteren 1 year ago
parent
commit
1b5e446797

+ 6 - 0
prs.classes/Entities/Invoice/Invoice.cs

@@ -137,6 +137,11 @@ namespace Comal.Classes
         public double Balance { get; set; }
 
         [NullEditor]
+        [LoggableProperty]
+        public PostedStatus PostedStatus { get; set; }
+
+        [NullEditor]
+        [LoggableProperty]
         public DateTime Posted { get; set; }
 
         public Expression<Func<Invoice, int>> AutoIncrementField()
@@ -155,6 +160,7 @@ namespace Comal.Classes
             JobLink = new JobLink();
             CustomerLink = new CustomerLink();
             Date = DateTime.Today;
+            PostedStatus = PostedStatus.NeverPosted;
         }
 
         public override string ToString()

+ 40 - 0
prs.desktop/Panels/Invoices/InvoiceListGrid.cs

@@ -10,11 +10,16 @@ using InABox.Reports;
 using InABox.Core.Reports;
 using InABox.Wpf.Reports;
 using InABox.WPF;
+using System.Windows.Media.Imaging;
+using com.sun.org.apache.xpath.@internal;
 
 namespace PRSDesktop
 {
     public class InvoiceListGrid : DynamicDataGrid<Invoice>
     {
+        private static readonly BitmapImage? tick = PRSDesktop.Resources.tick.AsBitmapImage();
+        private static readonly BitmapImage? warning = PRSDesktop.Resources.warning.AsBitmapImage();
+
         public InvoiceListGrid()
         {
             Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.EditRows,
@@ -23,6 +28,41 @@ namespace PRSDesktop
             AddButton("Email", PRSDesktop.Resources.email.AsBitmapImage(), EmailInvoice2);
             HiddenColumns.Add(x => x.CustomerLink.ID);
             HiddenColumns.Add(x => x.JobLink.ID);
+            HiddenColumns.Add(x => x.PostedStatus);
+            ActionColumns.Add(new DynamicImageColumn(Posted_Image, Posted_Click)
+            {
+                ToolTip = Posted_ToolTip
+            });
+        }
+
+        private bool Posted_Click(CoreRow? arg)
+        {
+            return false;
+        }
+
+        private FrameworkElement? Posted_ToolTip(DynamicActionColumn column, CoreRow? row)
+        {
+            if (row is null)
+            {
+                return column.TextToolTip("Invoice Processed Status");
+            }
+            return column.TextToolTip(row.Get<Invoice, PostedStatus>(x => x.PostedStatus) switch
+            {
+                PostedStatus.PostFailed => "Processing Failed",
+                PostedStatus.Posted => "Processed",
+                PostedStatus.NeverPosted or _ => "Not posted yet",
+            });
+        }
+
+        private BitmapImage? Posted_Image(CoreRow? arg)
+        {
+            if(arg is null) return tick;
+            return arg.Get<Invoice, PostedStatus>(x => x.PostedStatus) switch
+            {
+                PostedStatus.PostFailed => warning,
+                PostedStatus.Posted => tick,
+                PostedStatus.NeverPosted or _ => null,
+            };
         }
 
         public Guid JobID { get; set; }

+ 99 - 0
prs.desktop/Panels/Invoices/InvoicePanel.xaml.cs

@@ -1,9 +1,16 @@
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
+using System.Windows;
 using System.Windows.Controls;
+using com.sun.corba.se.impl.protocol.giopmsgheaders;
+using com.sun.security.ntlm;
 using Comal.Classes;
+using InABox.Clients;
+using InABox.Configuration;
 using InABox.Core;
+using InABox.Core.Postable;
 using InABox.DynamicGrid;
 
 namespace PRSDesktop
@@ -41,8 +48,100 @@ namespace PRSDesktop
             return new Dictionary<string, object[]> { { typeof(Invoice).EntityName(), Invoices.SelectedRows } };
         }
 
+        private static void ConfigureInvoicePost()
+        {
+            var invoicePostSettings = PosterUtils.LoadPostableSettings<Invoice>();
+
+            var grid = (DynamicGridUtils.CreateDynamicGrid(typeof(DynamicGrid<>), typeof(PostableSettings)) as DynamicGrid<PostableSettings>)!;
+            if (grid.EditItems(new PostableSettings[] { invoicePostSettings }))
+            {
+                PosterUtils.SavePostableSettings<Invoice>(invoicePostSettings);
+            }
+        }
+
         public void CreateToolbarButtons(IPanelHost host)
         {
+            var invoicePostSettings = PosterUtils.LoadPostableSettings<Invoice>();
+            if (Security.CanPost<Invoice>())
+            {
+                Bitmap? image = null;
+                if(invoicePostSettings.Thumbnail.ID != Guid.Empty)
+                {
+                    var icon = new Client<Document>()
+                        .Load(new Filter<Document>(x => x.ID).IsEqualTo(invoicePostSettings.Thumbnail.ID)).FirstOrDefault();
+                    if(icon is not null)
+                    {
+                        image = new ImageConverter().ConvertFrom(icon.Data) as Bitmap;
+                    }
+                }
+                host.CreatePanelAction(new PanelAction
+                {
+                    Caption = invoicePostSettings.ButtonName.NotWhiteSpaceOr("Process Invoices"),
+                    Image = image ?? PRSDesktop.Resources.edit,
+                    OnExecute = action =>
+                    {
+                        var rows = Invoices.SelectedRows.Select(x => x.ToObject<Invoice>()).ToList();
+                        if (!rows.Any())
+                        {
+                            MessageBox.Show("Please select at least one invoice.");
+                            return;
+                        }
+                        try
+                        {
+                            if (PosterUtils.Process(rows))
+                            {
+                                MessageBox.Show("Processing successful!");
+                                Invoices.Refresh(false, true);
+                            }
+                            else
+                            {
+                                MessageBox.Show("Processing failed.");
+                                Invoices.Refresh(false, true);
+                            }
+                        }
+                        catch (RepostedException)
+                        {
+                            MessageBox.Show("At least one of the items you selected has already been processed. Processing cancelled.");
+                        }
+                        catch (MissingSettingsException)
+                        {
+                            if (Security.CanConfigurePost<Invoice>())
+                            {
+                                if(MessageBox.Show("Processing has not been configured for Invoices. Would you like to configure this now?",
+                                    "Configure Processing?", MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes)
+                                {
+                                    ConfigureInvoicePost();
+                                }
+                                else
+                                {
+                                    MessageBox.Show("Processing cancelled.");
+                                }
+                            }
+                            else
+                            {
+                                MessageBox.Show("Processing has not been configured for Invoices!");
+                            }
+                        }
+                        catch(Exception e)
+                        {
+                            MessageBox.Show($"Processing failed: {e.Message}");
+                            Invoices.Refresh(false, true);
+                        }
+                    }
+                });
+            }
+
+            if (Security.CanConfigurePost<Invoice>())
+            {
+                host.CreateSetupAction(new PanelAction
+                {
+                    Caption = "Configure Invoice Processing",
+                    OnExecute = action =>
+                    {
+                        ConfigureInvoicePost();
+                    }
+                });
+            }
         }
 
         public void Setup()

+ 10 - 2
prs.shared/Posters/InvoiceCSVPoster.cs

@@ -14,6 +14,10 @@ namespace PRS.Shared
         public double Paid { get; set; }
 
         public double Balance { get; set; }
+
+        public string Description { get; set; }
+
+        public Guid ID { get; set; }
     }
 
     public class InvoiceCSVPoster : ICSVPoster<Invoice>
@@ -24,8 +28,10 @@ namespace PRS.Shared
             export.DefineMapping(new()
             {
                 new("Number", x => x.Number),
+                new("Description", x => x.Description),
                 new("Paid", x => x.Paid),
-                new("Balance", x => x.Balance)
+                new("Balance", x => x.Balance),
+                new("ID", x => x.ID)
             });
             foreach(var entity in entities)
             {
@@ -33,7 +39,9 @@ namespace PRS.Shared
                 {
                     Number = entity.Number,
                     Paid = entity.AmountPaid,
-                    Balance = entity.Balance
+                    Balance = entity.Balance,
+                    ID = entity.ID,
+                    Description = entity.Description
                 });
             }
             return export;