浏览代码

Wrote the AddToExistingOrder() function

Kenric Nugteren 10 月之前
父节点
当前提交
d41710ab16

+ 1 - 1
prs.desktop/PRSDesktop.csproj

@@ -916,7 +916,7 @@
         <XamlRuntime>Wpf</XamlRuntime>
         <SubType>Designer</SubType>
       </Page>
-      <Page Update="Panels\Reservation Management\ReservationManagementPurchasing.xaml">
+      <Page Update="Panels\Reservation Management\Purchasing\ReservationManagementPurchasing.xaml">
         <Generator>MSBuild:Compile</Generator>
       </Page>
       <Page Update="Panels\Reservation Management\ReservationManagementPanel.xaml">

+ 0 - 0
prs.desktop/Panels/Reservation Management/ReservationManagementPurchasing.xaml → prs.desktop/Panels/Reservation Management/Purchasing/ReservationManagementPurchasing.xaml


+ 1 - 1
prs.desktop/Panels/Reservation Management/ReservationManagementPurchasing.xaml.cs → prs.desktop/Panels/Reservation Management/Purchasing/ReservationManagementPurchasing.xaml.cs

@@ -249,7 +249,7 @@ public partial class ReservationManagementPurchasing : UserControl
         }
     }
 
-    private bool CreatePOItemsFromRequiItems(IList<JobRequisitionItem> selected, List<PurchaseOrderItem> items)
+    public bool CreatePOItemsFromRequiItems(IList<JobRequisitionItem> selected, List<PurchaseOrderItem> items)
     {
         // These columns probably are already there, but if they aren't, let's load them.
         Client.EnsureColumns(selected,

+ 12 - 0
prs.desktop/Panels/Reservation Management/Purchasing/ReservationManagementPurchasingWindow.xaml

@@ -0,0 +1,12 @@
+<Window x:Class="PRSDesktop.ReservationManagementPurchasingWindow"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:PRSDesktop"
+        mc:Ignorable="d"
+        Title="ReservationManagementPurchasingWindow" Height="450" Width="800">
+    <Grid Margin="5">
+        <local:ReservationManagementPurchasing x:Name="Purchasing"/>
+    </Grid>
+</Window>

+ 25 - 0
prs.desktop/Panels/Reservation Management/Purchasing/ReservationManagementPurchasingWindow.xaml.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace PRSDesktop;
+/// <summary>
+/// Interaction logic for ReservationManagementPurchasingWindow.xaml
+/// </summary>
+public partial class ReservationManagementPurchasingWindow : Window
+{
+    public ReservationManagementPurchasingWindow()
+    {
+        InitializeComponent();
+    }
+}

+ 42 - 2
prs.desktop/Panels/Reservation Management/ReservationManagementItemGrid.cs

@@ -140,6 +140,7 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
         HiddenColumns.Add(x => x.Issued);
 
         HiddenColumns.Add(x => x.Product.ID);
+        HiddenColumns.Add(x => x.Product.Name);
         HiddenColumns.Add(x => x.Product.Code);
         HiddenColumns.Add(x => x.Product.Group.ID);
         HiddenColumns.Add(x => x.Product.Group.Code);
@@ -325,7 +326,6 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
 
     #region CreatePurchaseOrder
 
-    
     private bool PurchaseOrder_Click(Button button, CoreRow[] rows)
     {
         if(rows.Length == 0)
@@ -382,6 +382,8 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
         }
     }
 
+    Window? PurchasingWindow;
+
     private void AddToExistingOrder(CoreRow[] rows)
     {
         var dlg = new MultiSelectDialog<PurchaseOrder>(
@@ -391,6 +393,45 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
         if (dlg.ShowDialog())
         {
             var id = dlg.IDs().First();
+
+            var jris = rows.ToArray<JobRequisitionItem>();
+
+            var pois = new List<(PurchaseOrderItem poi, PurchaseOrderItemAllocation poia)>();
+
+            foreach (var jobRequisitionItem in jris)
+            {
+                // We only want stuff which doesn't have enough total stock allocated, which is the InStock and Issued added together.
+                if(!jobRequisitionItem.Qty.IsEffectivelyGreaterThan(jobRequisitionItem.InStock + jobRequisitionItem.Issued))
+                    continue;
+
+                var poItem = new PurchaseOrderItem
+                {
+                    Description = jobRequisitionItem.Product.Name,
+                    Qty = jobRequisitionItem.Qty
+                };
+                poItem.Product.ID = jobRequisitionItem.Product.ID;
+                poItem.Product.Synchronise(jobRequisitionItem.Product);
+                poItem.Dimensions.CopyFrom(jobRequisitionItem.Dimensions);
+                poItem.Style.ID = jobRequisitionItem.Style.ID;
+                poItem.Style.Synchronise(jobRequisitionItem.Style);
+                poItem.PurchaseOrderLink.ID = id;
+
+                var allocation = new PurchaseOrderItemAllocation();
+                allocation.Job.CopyFrom(jobRequisitionItem.Job);
+                allocation.JobRequisitionItem.CopyFrom(jobRequisitionItem);
+
+                pois.Add((poItem, allocation));
+            }
+
+            Client.Save(pois.Select(x => x.poi), "Created from Reservation Management Screen");
+
+            foreach(var (poi, poia) in pois)
+            {
+                poia.Item.CopyFrom(poi);
+            }
+            Client.Save(pois.Select(x => x.poia), "Created from Reservation Management Screen");
+
+            ViewPurchaseOrder(id);
         }
     }
 
@@ -564,7 +605,6 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
         CreateOrder.IsEnabled = bAny;
         CreatePickingList.IsEnabled = bAny;
         ConsolidateHoldings.IsEnabled = bAny;
-        
     }
 
     #region Action Column Buttons

+ 0 - 54
prs.desktop/Panels/Reservation Management/ReservationManagementPanel.xaml.cs

@@ -22,73 +22,19 @@ public partial class ReservationManagementPanel : UserControl, IPanel<JobRequisi
 {
     private ReservationManagementGlobalSettings _globalSettings = null!; // Initialised in Setup()
 
-    //private DynamicSplitPanelView CurrentView;
-
     //private List<PurchaseOrder> PurchaseOrders = new List<PurchaseOrder>();
 
     public ReservationManagementPanel()
     {
         InitializeComponent();
-
-        //CurrentView = SplitPanel.View;
-
-        // JobRequiItems.Reconfigure(options =>
-        // {
-        //     var canMultiSelect = Mode != PanelMode.Reserve || SplitPanel.View == DynamicSplitPanelView.Master;
-        //     if(canMultiSelect)
-        //     {
-        //         options.MultiSelect = true;
-        //     }
-        //     else
-        //     {
-        //         options.MultiSelect = false;
-        //     }
-        // });
     }
 
-    // enum PanelMode
-    // {
-    //     Reserve,
-    //     Purchase
-    // }
-
-    //private PanelMode Mode { get; set; }
-
-    // private void SelectDetailButton(Button button)
-    // {
-    //     reserveBtn.Background = new SolidColorBrush(Colors.WhiteSmoke);
-    //     reserveBtn.Foreground = new SolidColorBrush(Colors.Black);
-    //     foreach(var btn in PurchaseOrderButtons.Children.OfType<Button>())
-    //     {
-    //         btn.Background = new SolidColorBrush(Colors.WhiteSmoke);
-    //         btn.Foreground = new SolidColorBrush(Colors.Black);
-    //     }
-    //     AddPOButton.Background = new SolidColorBrush(Colors.WhiteSmoke);
-    //     AddPOButton.Foreground = new SolidColorBrush(Colors.Black);
-    //     button.Background = ThemeManager.SelectedTabItemBackgroundBrush;
-    //     button.Foreground = ThemeManager.SelectedTabItemForegroundBrush;
-    // }
-
     private void Reconfigure()
     {
         JobRequiItems.Reconfigure();
         OnUpdateDataModel?.Invoke(SectionName, DataModel(Selection.None));
     }
 
-    // private void SelectReserved()
-    // {
-    //     SelectDetailButton(reserveBtn);
-    //
-    //     reserveCol.Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star);
-    //     purchaseCol.Width = new System.Windows.GridLength(0);
-    //
-    //     if(Mode != PanelMode.Reserve)
-    //     {
-    //         Mode = PanelMode.Reserve;
-    //         Reconfigure();
-    //     }
-    // }
-    
     // private void SelectNewPurchaseOrder()
     // {
     //     SelectDetailButton(AddPOButton);