Prechádzať zdrojové kódy

PRS DESKTOP - build Job Requi Review Dashboard as a module instead

Nick-PRSDigital@bitbucket.org 2 rokov pred
rodič
commit
08b4f3bd09

+ 0 - 198
prs.desktop/Dashboards/Projects/Job Requisition Items Review Dashboard/JobRequisitionItemStockHoldingReserverGrid.cs

@@ -1,198 +0,0 @@
-using Comal.Classes;
-using InABox.Clients;
-using InABox.Core;
-using InABox.DynamicGrid;
-using InABox.WPF;
-using NPOI.HSSF.Record;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Windows;
-using System.Windows.Media.Imaging;
-
-namespace PRSDesktop
-{
-    public class JobRequisitionItemStockHoldingReserverGrid : DynamicDataGrid<StockHolding>, ISpecificGrid
-    {
-        Guid ProductID = Guid.Empty;
-        Guid JobID = Guid.Empty;
-        String RequiNumber = "";
-        Guid RequiItemID = Guid.Empty;
-        bool actionColumn = true;
-        private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
-        private readonly BitmapImage changeNotAllowed = PRSDesktop.Resources.box.AsBitmapImage();
-        public bool StockReserved = false;
-        public JobRequisitionItemStockHoldingReserverGrid(Guid productid, Guid jobid, Guid requiItemID, string requinumber, bool actioncolumn = true)
-        {
-            ProductID = productid;
-            JobID = jobid;
-            RequiNumber = requinumber;
-            RequiItemID = requiItemID;
-            Options.AddRange(
-                DynamicGridOption.FilterRows,
-                DynamicGridOption.SelectColumns
-                );
-            HiddenColumns.Add(x => x.ID);
-            HiddenColumns.Add(x => x.Location.ID);
-            HiddenColumns.Add(x => x.Product.ID);
-            HiddenColumns.Add(x => x.Style.ID);
-            HiddenColumns.Add(x => x.Job.ID);
-            HiddenColumns.Add(x => x.Job.Deleted);
-            HiddenColumns.Add(x => x.Dimensions.UnitSize);
-            HiddenColumns.Add(x => x.Dimensions.Unit.ID);
-            HiddenColumns.Add(x => x.Dimensions.Unit.Description);
-            HiddenColumns.Add(x => x.Dimensions.Unit.HasHeight);
-            HiddenColumns.Add(x => x.Dimensions.Unit.HasLength);
-            HiddenColumns.Add(x => x.Dimensions.Unit.HasWidth);
-            HiddenColumns.Add(x => x.Dimensions.Unit.HasHeight);
-            HiddenColumns.Add(x => x.Dimensions.Unit.HasQuantity);
-            HiddenColumns.Add(x => x.Dimensions.Unit.Format);
-            HiddenColumns.Add(x => x.Dimensions.Unit.Formula);
-            HiddenColumns.Add(x => x.Dimensions.Length);
-            HiddenColumns.Add(x => x.Dimensions.Width);
-            HiddenColumns.Add(x => x.Dimensions.Height);
-            HiddenColumns.Add(x => x.Dimensions.Quantity);
-
-            actionColumn = actioncolumn;
-            if (actioncolumn)
-                ActionColumns.Add(new DynamicImageColumn(ConfirmedImage, ReserveStock));
-        }
-
-        protected override void GenerateColumns(DynamicGridColumns columns)
-        {
-            columns.Add<StockHolding, string>(x => x.Location.Description, 110, "Location", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Product.Code, 70, "Product Code", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Product.Name, 150, "Product Name", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Job.JobNumber, 50, "Job", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Style.Description, 150, "Style", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, double>(x => x.Units, 50, "Units", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Dimensions.UnitSize, 60, "Size", "", Alignment.MiddleLeft);
-        }
-
-        private bool ReserveStock(CoreRow row)
-        {
-            StockHolding holding = row.ToObject<StockHolding>();
-            //if (holding.Job.IsValid())
-            //{
-            //    CoreTable table = new Client<StockMovement>().Query(new Filter<StockMovement>(x => x.Location.ID).IsEqualTo(holding.ID)
-            //        .And(x => x.JobRequisitionItem.ID).IsEqualTo(RequiItemID),
-            //        new Columns<StockMovement>(x => x.ID));
-            //    if (table.Rows.Any())
-            //    {
-            //        var choiceresult = MessageBox.Show("This will reverse previous stock movements created to reserve from this location. Proceed?", "Alert", MessageBoxButton.YesNo);
-            //        switch (choiceresult)
-            //        {
-            //            case MessageBoxResult.Yes:
-            //                break;
-            //            case MessageBoxResult.No:
-            //                return false;
-            //            default:
-            //                return false;
-            //        }
-            //        List<StockMovement> movements = new List<StockMovement>();
-            //        foreach (CoreRow stockmovementRow in table.Rows)
-            //        {
-            //            StockMovement movement = new StockMovement { ID = Guid.Parse(stockmovementRow.Values[0].ToString()) };
-            //            movements.Add(movement);
-            //        }
-            //        new Client<StockMovement>().Delete(movements, "Stock movements reversed from Job Requi Review Dashboard");
-            //        return true;
-            //    }
-            //    else
-            //    {
-            //        MessageBox.Show("The stock movements for this holding cannot be reversed");
-            //        return false;
-            //    }
-            //}
-            var result = MessageBox.Show("This will reserve stock from the holding now. Proceed?", "Alert", MessageBoxButton.YesNo);
-            switch (result)
-            {
-                case MessageBoxResult.Yes:
-                    break;
-                case MessageBoxResult.No:
-                    return false;
-                default:
-                    return false;
-            }
-            int units = Convert.ToInt32(holding.Units);
-            if (NumberEdit.Execute("Enter number to reserve", 1, units, ref units))
-            {
-                StockMovementBatch batch = new StockMovementBatch();
-                batch.Type = StockMovementBatchType.Transfer;
-                batch.Notes = "Reserving Stock for Requi: " + RequiNumber;
-
-                new Client<StockMovementBatch>().Save(batch, "Created from Job Requi Item Reserve Stock Screen");
-                List<StockMovement> movements = new List<StockMovement>();
-
-                StockMovement issuemovement = new StockMovement();
-                issuemovement.System = true;
-                issuemovement.Batch.Notes = batch.Notes;
-                issuemovement.Batch.Type = StockMovementBatchType.Transfer;
-                issuemovement.Units = units;
-                issuemovement.Issued = units;
-                issuemovement.Dimensions.CopyFrom(holding.Dimensions);
-                issuemovement.Style.ID = holding.Style.ID;
-                issuemovement.Location.ID = holding.Location.ID;
-                issuemovement.Product.ID = holding.Product.ID;
-                issuemovement.Date = batch.Created;
-                issuemovement.IsTransfer = true;
-                issuemovement.Notes = batch.Notes;
-                issuemovement.JobRequisitionItem.ID = RequiItemID;
-                issuemovement.Employee.ID = Guid.Parse(new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.UserID).IsEqualTo(ClientFactory.UserID), new Columns<Employee>(x => x.ID)).Rows.FirstOrDefault().Values[0].ToString());
-
-                StockMovement receivemovement = new StockMovement();
-                receivemovement.Batch.Notes = batch.Notes;
-                receivemovement.Batch.Type = StockMovementBatchType.Transfer;
-                receivemovement.Units = units;
-                receivemovement.Received = units;
-                receivemovement.Dimensions.CopyFrom(holding.Dimensions);
-                receivemovement.Style.ID = holding.Style.ID;
-                receivemovement.Location.ID = holding.Location.ID;
-                receivemovement.Product.ID = holding.Product.ID;
-                receivemovement.Date = batch.Created;
-                receivemovement.IsTransfer = true;
-                receivemovement.Notes = batch.Notes;
-                receivemovement.JobRequisitionItem.ID = RequiItemID;
-                receivemovement.Employee.ID = Guid.Parse(new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.UserID).IsEqualTo(ClientFactory.UserID), new Columns<Employee>(x => x.ID)).Rows.FirstOrDefault().Values[0].ToString());
-                receivemovement.Job.ID = JobID;
-
-                movements.Add(issuemovement);
-                movements.Add(receivemovement);
-                new Client<StockMovement>().Save(movements, "Items reserved from Job Requi Item Reserve Stock Screen");
-
-                StockReserved = true;
-            }
-            return true;
-        }
-
-        private BitmapImage ConfirmedImage(CoreRow row)
-        {
-            if (row == null)
-                return tick;
-            StockHolding holding = row.ToObject<StockHolding>();
-            if (holding.Job.ID == JobID)
-            {
-                CoreTable table = new Client<StockMovement>().Query(new Filter<StockMovement>(x => x.Location.ID).IsEqualTo(holding.ID)
-                    .And(x => x.JobRequisitionItem.ID).IsEqualTo(RequiItemID),
-                    new Columns<StockMovement>(x => x.ID));
-                if (table.Rows.Any())
-                {
-                    return tick;
-                }
-                else
-                    return changeNotAllowed;
-            }
-            else
-                return null;
-        }
-
-
-        protected override void Reload(Filters<StockHolding> criteria, Columns<StockHolding> columns, ref SortOrder<StockHolding> sort, Action<CoreTable, Exception> action)
-        {
-            criteria.Add(new Filter<StockHolding>(x => x.Units).IsGreaterThan(0.0001));
-            criteria.Add(new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(ProductID));
-            criteria.Add(new Filter<StockHolding>(x => x.Job).NotLinkValid().Or(x => x.Job).LinkValid(JobID));
-            base.Reload(criteria, columns, ref sort, action);
-        }
-    }
-}

+ 0 - 25
prs.desktop/Dashboards/Projects/Job Requisition Items Review Dashboard/JobRequisitionReserveWindow.xaml

@@ -1,25 +0,0 @@
-<wpf:ThemableWindow x:Class="PRSDesktop.JobRequisitionReserveWindow"
-        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"
-		xmlns:wpf="clr-namespace:InABox.Wpf;assembly=InABox.Wpf"
-        mc:Ignorable="d"
-        Title="Reserve Stock Window" Height="450" Width="800">
-    <Grid>
-        <Grid.RowDefinitions>
-            <RowDefinition Height="40"/>
-            <RowDefinition Height="*"/>
-            <RowDefinition Height="40"/>
-        </Grid.RowDefinitions>
-        <Label Grid.Row="0" Margin="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontWeight="Bold"
-            Content="Stock Holdings for Product - Press the green tick column to reserve from a Stock Holding"/>
-
-        <Grid Grid.Row="1" x:Name="grid" Margin="5">
-            
-        </Grid>
-
-        <Button x:Name="okBtn" Grid.Row="2" Content="Close" Width="100" Click="okBtn_Click" Margin="668,5,32,5"/>
-    </Grid>
-</wpf:ThemableWindow>

+ 0 - 35
prs.desktop/Dashboards/Projects/Job Requisition Items Review Dashboard/JobRequisitionReserveWindow.xaml.cs

@@ -1,35 +0,0 @@
-using InABox.Wpf;
-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 JobRequisitionReserveWindow.xaml
-    /// </summary>
-    public partial class JobRequisitionReserveWindow : ThemableWindow
-    {
-        public bool StockReserved = false;
-        public JobRequisitionReserveWindow()
-        {
-            InitializeComponent();
-        }
-
-        private void okBtn_Click(object sender, RoutedEventArgs e)
-        {
-            StockReserved = true;
-            Close();
-        }
-    }
-}

+ 0 - 38
prs.desktop/Dashboards/Projects/Job Requisition Items Review Dashboard/JobRequisitionReviewDashboard.xaml

@@ -1,38 +0,0 @@
-<UserControl x:Class="PRSDesktop.JobRequisitionReviewDashboard"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:PRSDesktop"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800">
-    <Grid>
-        <Grid.RowDefinitions>
-            <RowDefinition Height="auto"/>
-            <RowDefinition Height="*"/>
-        </Grid.RowDefinitions>
-
-        <Grid Grid.Row="0">
-            <Grid.ColumnDefinitions>
-                <ColumnDefinition Width="auto"/>
-                <ColumnDefinition Width="auto"/>
-            </Grid.ColumnDefinitions>
-
-            <Label Grid.Row="0" Content="Supplier: " VerticalAlignment="Center"/>
-
-            <ComboBox Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="Filter_SelectionChanged" HorizontalContentAlignment="Left"
-                      Width="300"
-                  x:Name="filterComboBox">
-                <ComboBox.ItemTemplate>
-                    <DataTemplate>
-                        <TextBlock Text="{Binding Text}"/>
-                    </DataTemplate>
-                </ComboBox.ItemTemplate>
-            </ComboBox>
-        </Grid>
-        
-        
-        <local:JobRequisitionReviewGrid Grid.Row="1"
-            x:Name="Grid"/>
-    </Grid>
-</UserControl>

+ 0 - 67
prs.desktop/Dashboards/Projects/Job Requisition Items Review Dashboard/JobRequisitionReviewDashboard.xaml.cs

@@ -1,67 +0,0 @@
-using Comal.Classes;
-using InABox.Core;
-using InABox.DynamicGrid;
-using InABox.WPF;
-using PRSDesktop.WidgetGroups;
-using InABox.Clients;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media.Imaging;
-using System.Windows.Media;
-using InABox.Configuration;
-
-namespace PRSDesktop
-{
-    public class JobRequisitionReviewDashboardProperties : IUserConfigurationSettings, IDashboardProperties { }
-
-    public class JobRequisitionReviewDashboardElement : DashboardElement<JobRequisitionReviewDashboard, Projects, JobRequisitionReviewDashboardProperties> { }
-    /// <summary>
-    /// Interaction logic for JobRequisitionReviewDashboard.xaml
-    /// </summary>
-    /// 
-    //Job Requi Review Dashboard works with JobRequisitionReviewGrid (for viewing data), and also allows:
-    // 1. Changing the status of a Job Requi Item line via an action column with context menu.
-    // Of note is "Reserving" stock - using the JobRequisitionReserveWindow, which works with the JobRequisitionItemStockHoldingReserverGrid
-    // 2. Create a purchase order from a selection of one or more lines using the added button. If the PO process is cancelled, the PO and items created are cleaned up
-    // 3. Splitting Job Requi Item lines
-    public partial class JobRequisitionReviewDashboard : UserControl, IDashboardWidget<Projects, JobRequisitionReviewDashboardProperties>
-    {
-        public List<JobRequiReviewDashboardFilterItem> filterItems = new List<JobRequiReviewDashboardFilterItem>();
-        
-        public JobRequisitionReviewDashboardProperties Properties { get; set; }
-        public event LoadSettings<JobRequisitionReviewDashboardProperties>? LoadSettings;
-        public event SaveSettings<JobRequisitionReviewDashboardProperties>? SaveSettings;
-
-        public JobRequisitionReviewDashboard()
-        {
-            InitializeComponent();
-            Grid.Refresh(true, true);
-        }
-        public void Refresh()
-        {
-        }
-
-        public void Setup()
-        {
-        }
-
-        public void Shutdown()
-        {
-        }
-
-        private void Filter_SelectionChanged(object sender, SelectionChangedEventArgs e)
-        {
-            var item = filterComboBox.SelectedItem as JobRequiReviewDashboardFilterItem;
-            Grid.RefreshOnFilterChanged(item.SupplierID);
-        }
-
-       
-    }
-
-
-
-    
-}

+ 0 - 38
prs.desktop/Dashboards/Projects/Job Requisition Items Review Dashboard/StockHoldingToolTipGrid.cs

@@ -1,38 +0,0 @@
-using Comal.Classes;
-using InABox.Core;
-using InABox.DynamicGrid;
-using System;
-
-namespace PRSDesktop
-{
-    public class StockHoldingToolTipGrid : DynamicDataGrid<StockHolding>, ISpecificGrid
-    {
-        Guid ProductID = Guid.Empty;
-        Guid JobID = Guid.Empty;
-
-        public StockHoldingToolTipGrid(Guid productid, Guid jobid, Guid requiItemID, string requinumber)
-        {
-            ProductID = productid;
-            JobID = jobid;
-        }
-
-        protected override DynamicGridColumns LoadColumns()
-        {
-            var columns = new DynamicGridColumns();
-            columns.Add<StockHolding, string>(x => x.Location.Description, 110, "Location", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Job.JobNumber, 50, "Job", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Style.Description, 250, "Style", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, double>(x => x.Units, 50, "Units", "", Alignment.MiddleLeft);
-            columns.Add<StockHolding, string>(x => x.Dimensions.UnitSize, 60, "Size", "", Alignment.MiddleLeft);
-            return columns;
-        }
-
-        protected override void Reload(Filters<StockHolding> criteria, Columns<StockHolding> columns, ref SortOrder<StockHolding> sort, Action<CoreTable, Exception> action)
-        {
-            criteria.Add(new Filter<StockHolding>(x => x.Units).IsGreaterThan(0.0001));
-            criteria.Add(new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(ProductID));
-            criteria.Add(new Filter<StockHolding>(x => x.Job).NotLinkValid().Or(x => x.Job).LinkValid(JobID));
-            base.Reload(criteria, columns, ref sort, action);
-        }
-    }
-}

+ 143 - 0
prs.desktop/JobRequiItemAvailableStockGrid.cs

@@ -0,0 +1,143 @@
+using Comal.Classes;
+using InABox.Clients;
+using InABox.Core;
+using InABox.DynamicGrid;
+using InABox.WPF;
+using jdk.nashorn.@internal.ir.debug;
+using NPOI.SS.Formula.Functions;
+using org.omg.PortableInterceptor;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace PRSDesktop
+{
+    public delegate void StockReserved();
+    public class JobRequiItemAvailableStockGrid : DynamicDataGrid<StockHolding>
+    {
+        public event StockReserved OnStockReserved;
+        public Guid ProductID = Guid.Empty;
+        public JobRequisitionItem Item = new JobRequisitionItem();
+        public Guid empID = new Guid();
+
+        public JobRequiItemAvailableStockGrid()
+        {
+            Options.AddRange(
+                 DynamicGridOption.SelectColumns,
+                 DynamicGridOption.FilterRows,
+                 DynamicGridOption.RecordCount,
+                 DynamicGridOption.EditRows
+             );
+            HiddenColumns.Add(x => x.Qty);
+            AddButton("Reserve For Job", null, ReserveStock);
+        }
+
+        private bool ReserveStock(Button btn, CoreRow[] rows)
+        {
+            if (!rows.Any())
+            {
+                MessageBox.Show("Please select at least one holding to reserve");
+                return false;
+            }
+
+            var holding = rows[0].ToObject<StockHolding>();
+            int units = 0;
+
+            if (Item.Qty <= holding.Units)
+                units = Convert.ToInt32(Item.Qty);
+            else
+                units = Convert.ToInt32(holding.Units);
+
+            if (NumberEdit.Execute("Enter amount to reserve", 1, units, ref units))
+            {
+                StockMovementBatch batch = new StockMovementBatch();
+                batch.Type = StockMovementBatchType.Transfer;
+                batch.Notes = "Reserving Stock for Requi: " + Item.Requisition.Number;
+
+                new Client<StockMovementBatch>().Save(batch, "Created from Job Requi Item Reserve Stock Function");
+                List<StockMovement> movements = new List<StockMovement>
+                {
+                    CreateMovement(StockMovementType.Issue, units, holding, batch),
+                    CreateMovement(StockMovementType.Receive, units, holding, batch)
+                };
+
+                new Client<StockMovement>().Save(movements, "Created from Job Requi Item Reserve Stock Function");
+
+                Item.Status = JobRequisitionItemStatus.Reserved;
+
+                new Client<JobRequisitionItem>().Save(Item, "Updated from Job Requi Item Reserve Stock Function");
+               
+                MessageBox.Show("Success - " + Item.Product.Name + " stock reserved for Requisition " + Item.Requisition.Number);
+
+                OnStockReserved?.Invoke();
+            }
+
+            return true;
+        }
+
+        enum StockMovementType 
+        {
+            Issue,
+            Receive
+        }
+
+        private StockMovement CreateMovement(StockMovementType type, double units, StockHolding holding, StockMovementBatch batch)
+        {
+            StockMovement mvt = new StockMovement();
+            mvt.System = true;
+            mvt.Batch.ID = batch.ID;
+            mvt.Batch.Type = StockMovementBatchType.Transfer;         
+            mvt.Dimensions.CopyFrom(holding.Dimensions);
+            mvt.Style.ID = holding.Style.ID;
+            mvt.Location.ID = holding.Location.ID;
+            mvt.Product.ID = holding.Product.ID;
+            mvt.Date = DateTime.Now;
+            mvt.IsTransfer = true;
+            mvt.Notes = "Reserving Stock for Requi: " + Item.Requisition.Number;
+            mvt.JobRequisitionItem.ID = Item.ID;
+            mvt.Employee.ID = empID;
+
+            if (type == StockMovementType.Issue)
+            {
+                mvt.Issued = units;
+                mvt.Job.ID = holding.Job.ID;
+            }
+            else
+            {
+                mvt.Received = units;
+                mvt.Job.ID = Item.Job.ID;
+            }
+                
+            return mvt;
+        }
+
+        
+
+        protected override void Reload(Filters<StockHolding> criteria, Columns<StockHolding> columns, ref SortOrder<StockHolding> sort, Action<CoreTable, Exception> action)
+        {
+            if (ProductID != Guid.Empty)
+                criteria.Add(new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(ProductID));
+            else
+                criteria.Add(new Filter<StockHolding>().None());
+
+            base.Reload(criteria, columns, ref sort, action);
+        }
+
+        protected override bool FilterRecord(CoreRow row)
+        {
+            var result = base.FilterRecord(row);
+            if (result)
+            {
+                var qty = row.Get<StockHolding, double>(x => x.Qty);
+                var iszero = CoreUtils.IsEffectivelyEqual(qty, 0.0F);
+                result = !iszero;
+            }
+
+            return result;
+        }
+    }
+}

+ 44 - 0
prs.desktop/JobRequiItemMovementsGrid.cs

@@ -0,0 +1,44 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.DynamicGrid;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace PRSDesktop
+{
+    public class JobRequiItemMovementsGrid : DynamicDataGrid<StockMovement>
+    {
+        public Guid JobRequiItemID = Guid.Empty;
+        public JobRequiItemMovementsGrid()
+        {
+            Options.AddRange(
+                     DynamicGridOption.SelectColumns,
+                     DynamicGridOption.FilterRows,
+                     DynamicGridOption.RecordCount,
+                     DynamicGridOption.EditRows
+                 );
+            HiddenColumns.Add(x => x.Qty);
+
+            Options.Remove(DynamicGridOption.AddRows);
+            Options.Remove(DynamicGridOption.DeleteRows);
+            Options.Remove(DynamicGridOption.ImportData);
+            Options.Remove(DynamicGridOption.ExportData);
+
+        }
+
+        protected override void Reload(Filters<StockMovement> criteria, Columns<StockMovement> columns, ref SortOrder<StockMovement>? sort, Action<CoreTable?, Exception?> action)
+        {
+            if (JobRequiItemID != Guid.Empty)
+                criteria.Add(new Filter<StockMovement>(x => x.JobRequisitionItem.ID).IsEqualTo(JobRequiItemID));
+            else
+                criteria.Add(new Filter<StockMovement>().None());
+
+            base.Reload(criteria, columns, ref sort, action);
+        }
+    }
+}

+ 27 - 114
prs.desktop/JobRequisitionReviewGrid.cs

@@ -14,10 +14,14 @@ using System.Windows.Media;
 
 namespace PRSDesktop
 {
+    public delegate void JobRequiItemSelect(JobRequisitionItem item);
+    public delegate void GridRefresh();
     public class JobRequisitionReviewGrid : DynamicDataGrid<JobRequisitionItem>
     {
+        public event JobRequiItemSelect OnJobRequiItemSelected;
+        public event GridRefresh OnGridRefresh;
         List<Guid> filterProductIDs = new List<Guid>();
-        Guid empID = new Guid();
+        public Guid empID = new Guid();
         string empName = "";
         bool bIncludeArchived = false;
         bool bViewCancelled = false;
@@ -75,8 +79,8 @@ namespace PRSDesktop
 
             AddButton("Include Archived", null, ViewArchived);
             AddButton("Include Cancelled", null, ViewCancelled);
-
-            ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.rack.AsBitmapImage(), null) { ToolTip = ShowStockToolTip });
+            
+            OnSelectItem += JobRequisitionReviewGrid_OnSelectItem;
 
             ColumnsTag = "JobRequisitionReview";
 
@@ -88,13 +92,17 @@ namespace PRSDesktop
             }
         }
 
+        private void JobRequisitionReviewGrid_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
+        {
+            OnJobRequiItemSelected?.Invoke(SelectedRows[0].ToObject<JobRequisitionItem>());
+        }
 
         private bool ViewCancelled(Button button, CoreRow[] rows)
         {
             if (bViewCancelled)
             {
                 bViewCancelled = false;
-                button.Content = "Includ Cancelled";
+                button.Content = "Include Cancelled";
             }
             else
             {
@@ -102,10 +110,7 @@ namespace PRSDesktop
                 button.Content = "Exclude Cancelled";
             }
 
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(true, true);
-            });
+            OnGridRefresh?.Invoke();
 
             return true;
         }
@@ -123,30 +128,11 @@ namespace PRSDesktop
                 button.Content = "Exclude Archived";
             }
 
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(true, true);
-            });
+            OnGridRefresh?.Invoke();
 
             return true;
         }
 
-        private FrameworkElement ShowStockToolTip(DynamicActionColumn arg1, CoreRow row)
-        {
-            JobRequisitionItem item = row.ToObject<JobRequisitionItem>();
-            var holdings = new StockHoldingToolTipGrid(item.Product.ID, item.Job.ID, item.ID, item.Requisition.Number.ToString());
-            holdings.Refresh(true, true);
-
-            Frame frame = new Frame();
-            frame.Background = new SolidColorBrush(Colors.LightYellow);
-            frame.Padding = new Thickness(10);
-            frame.BorderBrush = new SolidColorBrush(Colors.DarkGray);
-            frame.BorderThickness = new Thickness(1);
-            frame.Content = holdings;
-
-            return frame;
-        }
-
         private bool CreateTreatmentPO(Button button, CoreRow[] rows)
         {
             return true;
@@ -197,65 +183,6 @@ namespace PRSDesktop
             return valid;
         }
 
-        private void Reserve_Clicked(CoreRow row)
-        {
-            JobRequisitionItem item = row.ToObject<JobRequisitionItem>();
-
-            CoreTable table = new Client<StockHolding>().Query
-                (
-                new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(item.Product.ID)
-                    .And(x => x.Job).NotLinkValid(),
-                new Columns<StockHolding>(x => x.Units)
-                );
-            if (table.Rows.Count == 0)
-            {
-                MessageBox.Show("No free stock found for this product.");
-                return;
-            }
-
-            double units = 0.0;
-            foreach (CoreRow corerow in table.Rows)
-            {
-                List<Object> list = corerow.Values;
-                if (list[0] == null) list[0] = 0;
-                double holdingUnits = double.Parse(list[0].ToString());
-                units = units + holdingUnits;
-            }
-
-
-            if (item.Qty > units)
-            {
-                var result = MessageBox.Show("Current free stock for this product is " + units + ". Amount required for this requisition line is " + item.Qty +
-                ". Do you want to split this requisition line?", "Alert", MessageBoxButton.YesNo);
-                switch (result)
-                {
-                    case MessageBoxResult.Yes:
-                        SplitLine(item, units, item.Qty - units, "line split due to insufficient stock holdings");
-                        return;
-                    case MessageBoxResult.No:
-                        break;
-                    default:
-                        return;
-                }
-            }
-            Dispatcher.BeginInvoke(() =>
-            {
-                JobRequisitionReserveWindow window = new JobRequisitionReserveWindow();
-                JobRequisitionItemStockHoldingReserverGrid holdings = new JobRequisitionItemStockHoldingReserverGrid
-                (
-                    item.Product.ID, item.Requisition.Job.ID, item.ID, item.Requisition.Job.JobNumber + " (" + item.Requisition.Number + ")"
-                );
-                holdings.Refresh(true, true);
-                window.grid.Children.Add(holdings);
-                window.SizeToContent = SizeToContent.WidthAndHeight;
-
-                window.ShowDialog();
-                if (holdings.StockReserved || window.StockReserved)
-                    SaveRow(row, JobRequisitionItemStatus.Reserved, "Line marked reserved by " + empName + " on " + DateTime.Now.ToString("dd MMM yy"));
-            });
-
-        }
-
         private void SplitLine(JobRequisitionItem item, double oldItemQty, double newItemQty, string notes)
         {
             List<JobRequisitionItem> items = new List<JobRequisitionItem>();
@@ -283,10 +210,7 @@ namespace PRSDesktop
             items.Add(item);
             new Client<JobRequisitionItem>().Save(items, "Split lines from Job Requi Item Review Dashboard");
             MessageBox.Show("Line split - original line Qty is now " + item.Qty + ". New line Qty is " + newItem.Qty, "Success");
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(true, true);
-            });
+            OnGridRefresh?.Invoke();
         }
 
         private void SplitLine_Clicked(CoreRow row)
@@ -405,10 +329,7 @@ namespace PRSDesktop
         private void SaveAndRefreshScreen(List<JobRequisitionItem> requiItems)
         {
             new Client<JobRequisitionItem>().Save(requiItems, "Updated on Create Purchase Order from Job Requi Dashboard");
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(false, true);
-            });
+            OnGridRefresh?.Invoke();
         }
 
         private List<PurchaseOrderItem> AddPOItems(CoreTable table, List<PurchaseOrderItem> poItems)
@@ -453,8 +374,11 @@ namespace PRSDesktop
         {
             JobReqItem.PurchaseOrderItem.ID = item.ID;
             JobReqItem.PurchaseOrderItem.DueDate = item.DueDate;
-            JobReqItem.Status = JobRequisitionItemStatus.OnOrder;
-            JobReqItem.Notes = JobReqItem.Notes + Environment.NewLine + "Line marked as On Order by " + empName + " on " + DateTime.Now.ToString("dd MMM yy");
+            if (JobReqItem.Status != JobRequisitionItemStatus.OnOrder)
+            {
+                JobReqItem.Notes = JobReqItem.Notes + Environment.NewLine + "Line marked as On Order by " + empName + " on " + DateTime.Now.ToString("dd MMM yy");
+                JobReqItem.Status = JobRequisitionItemStatus.OnOrder;
+            }
             return JobReqItem;
         }
 
@@ -521,10 +445,9 @@ namespace PRSDesktop
             item.Status = status;
             item.Notes = item.Notes + Environment.NewLine + note;
             new Client<JobRequisitionItem>().Save(item, "Updated From Job Requisition Review Dashboard");
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(true, true);
-            });
+
+            OnGridRefresh?.Invoke();
+
         }
 
         private void SaveItem(JobRequisitionItem item, JobRequisitionItemStatus status, string note)
@@ -532,10 +455,7 @@ namespace PRSDesktop
             item.Status = status;
             item.Notes = item.Notes + Environment.NewLine + note;
             new Client<JobRequisitionItem>().Save(item, "Updated From Job Requisition Review Dashboard");
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(true, true);
-            });
+            OnGridRefresh?.Invoke();
         }
 
         private void MultiSaveRows(CoreRow[] rows, JobRequisitionItemStatus status, string note)
@@ -550,10 +470,7 @@ namespace PRSDesktop
                 items.Add(item);
             }
             new Client<JobRequisitionItem>().Save(items, "Updated From Job Requisition Review Dashboard");
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(true, true);
-            });
+            OnGridRefresh?.Invoke();
         }
 
 
@@ -599,15 +516,11 @@ namespace PRSDesktop
                     }
                 }
             }
-            Dispatcher.BeginInvoke(() =>
-            {
-                Refresh(true, true);
-            });
+            OnGridRefresh?.Invoke();
         }
 
         private void BuildMenu(DynamicMenuColumn column, CoreRow row)
         {
-            column.AddItem("Reserve", PRSDesktop.Resources.project, Reserve_Clicked);
             column.AddItem("Treatment Required", PRSDesktop.Resources.palette, TreatmentRequired_Clicked);
             column.AddItem("Order Required", PRSDesktop.Resources.purchase, OrderRequired_Clicked);
             column.AddItem("Mark as Not Checked", PRSDesktop.Resources.disabled, Uncheck_Clicked);

+ 49 - 0
prs.desktop/JobRequisitionsPanel.xaml

@@ -0,0 +1,49 @@
+<UserControl x:Class="PRSDesktop.JobRequisitionsPanel"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PRSDesktop" xmlns:dynamicgrid="clr-namespace:InABox.DynamicGrid;assembly=InABox.Wpf"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="900">
+    <dynamicgrid:DynamicSplitPanel MasterCaption="Job Requisition Items" DetailCaption="Available Stock" AnchorWidth="1200" AllowableViews="Combined" View="Combined">
+        <dynamicgrid:DynamicSplitPanel.Header>
+            <Border CornerRadius="5,5,0,0" BorderBrush="Gray" BorderThickness="0.75" DockPanel.Dock="Top"
+                    Background="WhiteSmoke">
+                <Label Content="Job Requisition Item List" HorizontalContentAlignment="Center" />
+            </Border>
+        </dynamicgrid:DynamicSplitPanel.Header>
+
+        <dynamicgrid:DynamicSplitPanel.Master>
+            <local:JobRequisitionReviewGrid Grid.Row="0" x:Name="jobRequiItems" Margin="0,2,0,0"/>
+        </dynamicgrid:DynamicSplitPanel.Master>
+
+        <dynamicgrid:DynamicSplitPanel.DetailHeader>
+            <Border CornerRadius="5,5,0,0" BorderBrush="Gray" BorderThickness="0.75" DockPanel.Dock="Top"
+                    Background="WhiteSmoke">
+                <Label Content="Current Stock of Product" HorizontalContentAlignment="Center" />
+            </Border>
+        </dynamicgrid:DynamicSplitPanel.DetailHeader>
+
+        <dynamicgrid:DynamicSplitPanel.Detail>
+            <local:JobRequiItemAvailableStockGrid x:Name="availableHoldingsGrid" Margin="0,2,0,0"/>
+        </dynamicgrid:DynamicSplitPanel.Detail>
+
+        <dynamicgrid:DynamicSplitPanel.DetailHeight>
+           500
+        </dynamicgrid:DynamicSplitPanel.DetailHeight>
+
+        <dynamicgrid:DynamicSplitPanel.SecondaryDetail>
+            <DockPanel Grid.Row="0">
+                <Border CornerRadius="0,0,0,0" BorderBrush="Gray" BorderThickness="0.75" DockPanel.Dock="Top"
+                    Background="WhiteSmoke">
+                    <Label Content="Stock Movement History For Item" HorizontalContentAlignment="Center" />
+                </Border>
+                <local:JobRequiItemMovementsGrid x:Name="movementHistoryGrid" Margin="0,2,0,0"/>
+            </DockPanel>
+        </dynamicgrid:DynamicSplitPanel.SecondaryDetail>
+
+        
+
+    </dynamicgrid:DynamicSplitPanel>
+</UserControl>

+ 107 - 0
prs.desktop/JobRequisitionsPanel.xaml.cs

@@ -0,0 +1,107 @@
+using com.sun.tools.javac.file;
+using Comal.Classes;
+using InABox.Core;
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace PRSDesktop
+{
+    /// <summary>
+    /// Interaction logic for JobRequisitionsPanel.xaml
+    /// </summary>
+    public partial class JobRequisitionsPanel : UserControl, IPanel<JobRequisitionItem>
+    {
+        public JobRequisitionsPanel()
+        {
+            InitializeComponent();
+        }
+
+        public bool IsReady { get; set; }
+
+        public string SectionName => "Job Requisitions";
+
+        public event DataModelUpdateEvent? OnUpdateDataModel;
+
+        public void CreateToolbarButtons(IPanelHost host)
+        {
+
+        }
+
+        public DataModel DataModel(Selection selection)
+        {
+            var ids = jobRequiItems.ExtractValues(x => x.ID, selection).ToArray();
+            return new BaseDataModel<JobRequisitionItem>(new Filter<JobRequisitionItem>(x => x.ID).InList(ids));
+        }
+
+        public void Heartbeat(TimeSpan time)
+        {
+
+        }
+
+        public void Refresh()
+        {
+            jobRequiItems.Refresh(true, true);
+            availableHoldingsGrid.Refresh(true, true);
+            movementHistoryGrid.Refresh(true, true);
+        }
+
+        public Dictionary<string, object[]> Selected()
+        {
+            var result = new Dictionary<string, object[]>();
+            result[typeof(JobRequisitionItem).EntityName()] = jobRequiItems.SelectedRows;
+            return result;
+        }
+
+        public void Setup()
+        {
+            SetupJobRequiItemGrid();
+            availableHoldingsGrid.empID = jobRequiItems.empID;
+            availableHoldingsGrid.OnStockReserved += AvailableHoldingsGrid_OnStockReserved;
+        }
+
+        private void AvailableHoldingsGrid_OnStockReserved()
+        {
+            jobRequiItems.Refresh(false, true);
+            availableHoldingsGrid.Refresh(false, true);
+            movementHistoryGrid.Refresh(false, true);
+        }
+
+        private void SetupJobRequiItemGrid()
+        {
+            jobRequiItems.OnJobRequiItemSelected += JobRequiItemGrid_OnJobRequiItemSelected;
+            jobRequiItems.OnGridRefresh += JobRequiItems_OnGridRefresh;
+            jobRequiItems.Refresh(true, true);
+        }
+
+        private void JobRequiItems_OnGridRefresh()
+        {
+            jobRequiItems.Refresh(false, true);
+        }
+
+        private void JobRequiItemGrid_OnJobRequiItemSelected(JobRequisitionItem item)
+        {
+            availableHoldingsGrid.Item = item;
+            availableHoldingsGrid.ProductID = item.Product.ID;
+            availableHoldingsGrid.Refresh(true, true);
+            movementHistoryGrid.JobRequiItemID = item.ID;
+            movementHistoryGrid.Refresh(true, true);
+        }
+
+        public void Shutdown()
+        {
+
+        }
+    }
+}

+ 3 - 0
prs.desktop/MainWindow.xaml

@@ -540,6 +540,9 @@
                     <fluent:Button x:Name="StockSummaryButton" Header="Stock Forecast"
                                    LargeIcon="pack://application:,,,/Resources/kpi.png"
                                    Click="StockSummaryButton_Clicked" MinWidth="60" />
+                    <fluent:Button x:Name="JobRequisitionDashboardButton" Header="Stock Requisitions"
+                                   LargeIcon="pack://application:,,,/Resources/requisition.png"
+                                   Click="JobRequisitionDashboardButton_Clicked" MinWidth="60" />
                 </fluent:RibbonGroupBox>
 
                 <fluent:RibbonGroupBox x:Name="ProductReports" Width="Auto" MinWidth="60" Header="Print"

+ 7 - 1
prs.desktop/MainWindow.xaml.cs

@@ -2159,6 +2159,11 @@ namespace PRSDesktop
             LoadWindow<StockSummaryPanel>((Fluent.Button)sender);
         }
 
+        private void JobRequisitionDashboardButton_Clicked(object sender, RoutedEventArgs e)
+        {
+            LoadWindow<JobRequisitionsPanel>((Fluent.Button)sender);
+        }
+
         private void KitsMasterList_Click(object sender, RoutedEventArgs e)
         {
             LoadWindow<KitPanel>((Fluent.Button)sender);
@@ -4097,6 +4102,7 @@ namespace PRSDesktop
         }
 
         #endregion
-        
+
+       
     }
 }