Jelajahi Sumber

Fixing bugs and problems with bill approvals

Kenric Nugteren 5 bulan lalu
induk
melakukan
2a5bac4706

+ 13 - 0
prs.classes/Entities/Bill/Approvals/BillApproval.cs

@@ -7,8 +7,21 @@ namespace Comal.Classes
 {
     public class BillApproval : Entity, ISequenceable, IRemotable, IPersistent, ILicense<AccountsPayableLicense>
     {
+        private class EmployeeLookup : LookupDefinitionGenerator<Employee, BillApproval>
+        {
+            public override Filter<Employee>? DefineFilter(BillApproval[] items)
+            {
+                return new Filter<Employee>(x => x.ID).NotInList(items.ToArray(x => x.Employee.ID));
+            }
+
+            public override Columns<BillApproval> DefineFilterColumns()
+            {
+                return base.DefineFilterColumns().Add(x => x.Employee.ID);
+            }
+        }
         [EditorSequence(1)]
         [EntityRelationship(DeleteAction.Cascade)]
+        [LookupDefinition(typeof(EmployeeLookup))]
         public EmployeeLink Employee { get; set; }
 
         [NullEditor]

+ 19 - 3
prs.desktop/Panels/Suppliers/Bills/SupplierBillApprovalGrid.cs

@@ -31,6 +31,11 @@ public class SupplierBillApprovalGrid : DynamicDataGrid<BillApproval>, ISpecific
         HiddenColumns.Add(x => x.Employee.ID);
         HiddenColumns.Add(x => x.IsCustom);
 
+        foreach(var column in LookupFactory.DefineLookupFilterColumns<BillApproval, Employee, EmployeeLink>(x => x.Employee))
+        {
+            HiddenColumns.Add(column);
+        }
+
         ApproveButton = AddButton("Mark as Approved", null, ApproveButton_Click);
         ApproveButton.IsEnabled = false;
     }
@@ -151,9 +156,20 @@ public class SupplierBillApprovalGrid : DynamicDataGrid<BillApproval>, ISpecific
 
     protected override void DoAdd(bool openEditorOnDirectEdit = false)
     {
-        if (MultiSelectDialog<Employee>.SelectItem(out var employee,
-            LookupFactory.DefineLookupFilter<BillApproval, Employee, EmployeeLink>(x => x.Employee, []),
-            LookupFactory.DefineLookupColumns<BillApproval, Employee, EmployeeLink>(x => x.Employee),
+        var columns = LookupFactory.DefineLookupColumns<BillApproval, Employee, EmployeeLink>(x => x.Employee);
+
+        var employeeColumn = new Column<BillApproval>(x => x.Employee);
+        foreach(var column in DataColumns())
+        {
+            if(employeeColumn.IsParentOf(column.Property))
+            {
+                columns.Add(column.Property[(employeeColumn.Property.Length + 1)..]);
+            }
+        }
+
+        if (MultiSelectDialog.SelectItem(out var employee,
+            LookupFactory.DefineLookupFilter<BillApproval, Employee, EmployeeLink>(x => x.Employee, Data.ToArray<BillApproval>()),
+            columns,
             "Select Bill Approval Employee:"))
         {
             CreateItems(() =>

+ 2 - 1
prs.desktop/Panels/Suppliers/Bills/SupplierBillPanel.xaml

@@ -30,7 +30,8 @@
                 </Grid.RowDefinitions>
                 <local:SupplierBills x:Name="Bills"
                                      Grid.Row="0"
-                                     OnSelectItem="Bills_OnOnSelectItem"/>
+                                     OnSelectItem="Bills_OnOnSelectItem"
+                                     OnChanged="Bills_OnChanged"/>
                 
                 <sf:SfGridSplitter Grid.Row="1"
                                    Height="4"

+ 7 - 4
prs.desktop/Panels/Suppliers/Bills/SupplierBillPanel.xaml.cs

@@ -16,8 +16,6 @@ using System.IO;
 using System.Collections.ObjectModel;
 using System.Windows.Media;
 using System.Runtime.CompilerServices;
-using SuperSocket.ClientEngine;
-using com.sun.tools.@internal.jxc.gen.config;
 
 namespace PRSDesktop;
 
@@ -143,6 +141,8 @@ public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesP
 
     private void SaveApproval()
     {
+        if (_approval is null) return;
+
         Client.Save(_approval, "Approval updated by user.");
     }
 
@@ -260,8 +260,8 @@ public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesP
                 Bills.InitialiseEditorForm(Bill, _bills, null, true);
                 Bill.Visibility = Visibility.Visible;
                 LinkDocumentPage();
-                UpdateApproval();
             }
+            UpdateApproval();
         }
         else
         {
@@ -277,11 +277,14 @@ public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesP
     {
         using (new WaitCursor())
         {
+            // Saving the approval must happen before saving the bill, because otherwise the BillStore's approval stuff is overwritten
+            // by this SaveApproval function.
+            SaveApproval();
+
             var cancel = new System.ComponentModel.CancelEventArgs();
             Bill.SaveItem(cancel);
             if (!cancel.Cancel)
             {
-                SaveApproval();
                 if(_editRows is not null && _bills is not null)
                 {
                     _bills = Bills.LoadBills(_editRows);