|
@@ -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()
|