Bladeren bron

Improvements to approvals

Kenric Nugteren 7 maanden geleden
bovenliggende
commit
2464b7e4bb

+ 17 - 0
prs.desktop/Panels/Suppliers/Bills/SupplierBillApprovalGrid.cs

@@ -0,0 +1,17 @@
+using Comal.Classes;
+using InABox.DynamicGrid;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRSDesktop;
+
+public class SupplierBillApprovalGrid : DynamicOneToManyGrid<Bill, BillApproval>
+{
+    public SupplierBillApprovalGrid()
+    {
+        HiddenColumns.Add(x => x.Employee.ID);
+    }
+}

+ 14 - 3
prs.desktop/Panels/Suppliers/Bills/SupplierBillEditLayout.xaml

@@ -9,7 +9,8 @@
     xmlns:wpf="clr-namespace:InABox.Wpf;assembly=InABox.Wpf"
     xmlns:sf="http://schemas.syncfusion.com/wpf"
     mc:Ignorable="d" 
-    d:DesignHeight="450" d:DesignWidth="800">
+    d:DesignHeight="450" d:DesignWidth="800"
+    x:Name="Layout">
     <dynamicGrid:DynamicEditorGridLayout.Resources>
         <BoolToVisibilityConverter x:Key="boolVisibilityConverter"/>
     </dynamicGrid:DynamicEditorGridLayout.Resources>
@@ -71,9 +72,19 @@
                                     Grid.Row="3" CurrencyDecimalDigits="2"
                                     Height="25" Width="150"
                                     Margin="0,0,0,10"
-                                    Background="WhiteSmoke"
                                     VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
-                                    Value="{Binding BillAmount}"/>
+                                    Value="{Binding BillAmount}">
+                    <sf:CurrencyTextBox.Style>
+                        <Style TargetType="sf:CurrencyTextBox">
+                            <Setter Property="Background" Value="LightGreen"/>
+                            <Style.Triggers>
+                                <DataTrigger Binding="{Binding BillLessThanPO}" Value="False">
+                                    <Setter Property="Background" Value="LightSalmon"/>
+                                </DataTrigger>
+                            </Style.Triggers>
+                        </Style>
+                    </sf:CurrencyTextBox.Style>
+                </sf:CurrencyTextBox>
                 <Button x:Name="ApproveButton" Grid.Row="4"
                         Content="Approve"
                         Width="150"

+ 5 - 0
prs.desktop/Panels/Suppliers/Bills/SupplierBillEditLayout.xaml.cs

@@ -1,5 +1,6 @@
 using Comal.Classes;
 using InABox.DynamicGrid;
+using InABox.Wpf;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -47,6 +48,7 @@ public partial class SupplierBillEditLayout : DynamicEditorGridLayout, INotifyPr
         {
             _poAmount = value;
             OnPropertyChanged();
+            OnPropertyChanged(nameof(BillLessThanPO));
         }
     }
 
@@ -58,6 +60,7 @@ public partial class SupplierBillEditLayout : DynamicEditorGridLayout, INotifyPr
         {
             _billAmount = value;
             OnPropertyChanged();
+            OnPropertyChanged(nameof(BillLessThanPO));
         }
     }
 
@@ -84,6 +87,8 @@ public partial class SupplierBillEditLayout : DynamicEditorGridLayout, INotifyPr
         }
     }
 
+    public bool BillLessThanPO => BillAmount <= POAmount;
+
 
     public SupplierBillEditLayout()
     {

+ 40 - 18
prs.desktop/Panels/Suppliers/Bills/SupplierBillPanel.xaml.cs

@@ -121,6 +121,8 @@ public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesP
     #region Approval
 
     private BillApproval? _approval = null;
+    private DynamicOneToManyGrid<Bill, BillApproval>? _approvalPage = null;
+    private SupplierBillLineGrid? _billLinePage = null;
 
     private void EditLayout_Approve()
     {
@@ -130,13 +132,17 @@ public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesP
         {
             _approval.Approved = DateTime.Now;
             EditLayout.IsApproved = true;
-            Client.Save(_approval, "Approved by user.");
+            _approvalPage?.SaveItem(_approval);
+            _approvalPage?.Refresh(false, true);
+            _approvalPage?.DoChanged();
         }
         else
         {
             _approval.Approved = DateTime.MinValue;
             EditLayout.IsApproved = false;
-            Client.Save(_approval, "Unapproved by user.");
+            _approvalPage?.SaveItem(_approval);
+            _approvalPage?.Refresh(false, true);
+            _approvalPage?.DoChanged();
         }
     }
 
@@ -144,32 +150,48 @@ public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesP
     {
         if(_bills is not null && _bills.Length == 1)
         {
-            _approval = Client.Query<BillApproval>(
-                new Filter<BillApproval>(x => x.Bill.ID).IsEqualTo(_bills[0].ID)
-                    .And(x => x.Employee.ID).IsEqualTo(App.EmployeeID),
-                Columns.Required<BillApproval>()
-                    .Add(x => x.ID)
-                    .Add(x => x.Approved))
-                .ToObjects<BillApproval>().FirstOrDefault();
-            EditLayout.CanApprove = _approval is not null;
-            EditLayout.IsApproved = _approval is not null ? _approval.Approved != DateTime.MinValue : false;
-
-            var billLinePage = Bill.Pages.OfType<SupplierBillLineGrid>().FirstOrDefault();
-            if(billLinePage is not null)
+            if(Bill.Pages.TryGetPage<DynamicOneToManyGrid<Bill, BillApproval>>(out _approvalPage))
             {
-                EditLayout.BillAmount = billLinePage.Items.Sum(x => x.IncTax);
-                EditLayout.POAmount = billLinePage.Items.Sum(x =>
+                _approval = _approvalPage.Items.FirstOrDefault(x => x.Employee.ID == App.EmployeeID);
+                    
+                EditLayout.CanApprove = _approval is not null;
+                EditLayout.IsApproved = _approval is not null ? _approval.Approved != DateTime.MinValue : false;
+
+                if(Bill.Pages.TryGetPage(out _billLinePage))
                 {
-                    return x.OrderItem.IncTax + x.Consignment.IncTax;
-                });
+                    _billLinePage.OnChanged += BillLinePage_OnChanged;
+
+                    EditLayout.BillAmount = _billLinePage.Items.Sum(x => x.IncTax);
+                    EditLayout.POAmount = _billLinePage.Items.Sum(x =>
+                    {
+                        return x.OrderItem.IncTax + x.Consignment.IncTax;
+                    });
+                }
+            }
+            else
+            {
+                _approval = null;
+                EditLayout.CanApprove = false;
             }
         }
         else
         {
             _approval = null;
+            EditLayout.CanApprove = false;
         }
     }
 
+    private void BillLinePage_OnChanged(object? sender, EventArgs e)
+    {
+        if (_billLinePage is null) return;
+
+        EditLayout.BillAmount = _billLinePage.Items.Sum(x => x.IncTax);
+        EditLayout.POAmount = _billLinePage.Items.Sum(x =>
+        {
+            return x.OrderItem.IncTax + x.Consignment.IncTax;
+        });
+    }
+
     #endregion
 
     private void CheckSaved(CancelEventArgs cancel)

+ 13 - 5
prs.desktop/Panels/Suppliers/Bills/SupplierBills.cs

@@ -80,11 +80,19 @@ namespace PRSDesktop
                 columns: Columns.None<BillType>().Add(x => x.ID),
                 title: "Select Bill Type:"))
             {
-                var oldEmployees = Client.Query(
-                    new Filter<BillTypeEmployee>(x => x.BillType.ID).IsEqualTo(bill.BillType.ID),
-                    Columns.None<BillTypeEmployee>().Add(x => x.Employee.ID),
-                    new SortOrder<BillTypeEmployee>(x => x.Sequence))
-                    .ToArray<BillTypeEmployee>();
+                BillTypeEmployee[] oldEmployees;
+                if(bill.BillType.ID != Guid.Empty)
+                {
+                    oldEmployees = Client.Query(
+                        new Filter<BillTypeEmployee>(x => x.BillType.ID).IsEqualTo(bill.BillType.ID),
+                        Columns.None<BillTypeEmployee>().Add(x => x.Employee.ID),
+                        new SortOrder<BillTypeEmployee>(x => x.Sequence))
+                        .ToArray<BillTypeEmployee>();
+                }
+                else
+                {
+                    oldEmployees = [];
+                }
 
                 var newEmployees = Client.Query(
                     new Filter<BillTypeEmployee>(x => x.BillType.ID).IsEqualTo(billType.ID),