Browse Source

Added "Convert Dimensions" function to Stock Holding Grid

frogsoftware 11 months ago
parent
commit
cd28784c4a

+ 7 - 4
prs.classes/EnclosedEntities/Dimensions/DimensionUnit.cs

@@ -46,11 +46,16 @@ namespace Comal.Classes
         [EditorSequence(9)]
         public virtual string Format { get; set; } = "\"EACH\"";
         
-        
         [ScriptEditor]
         [EditorSequence(10)]
         public virtual string Conversion { get; set; } = "";
         
+                
+        [NullEditor]
+        public long Sequence { get; set; }
+
+        public bool HasDimensions() => HasHeight || HasWidth || HasLength || HasWeight || HasQuantity;
+        
         public static string ConvertDimensionsMethodName() => "ConvertDimensions";
 
         public static string DefaultConvertDimensionsScript()
@@ -66,9 +71,7 @@ namespace Comal.Classes
                 "    }\n"+
                 "}\n";
         }
-        
-        [NullEditor]
-        public long Sequence { get; set; }
+
 
         public bool Validate(List<String> errors)
         {

+ 2 - 0
prs.classes/EnclosedEntities/Dimensions/DimensionUnitLink.cs

@@ -48,5 +48,7 @@ namespace Comal.Classes
         [RequiredColumn]
         public virtual string Conversion { get; set; }
         
+        public bool HasDimensions() => HasHeight || HasWidth || HasLength || HasWeight || HasQuantity;
+        
     }
 }

+ 2 - 0
prs.classes/EnclosedEntities/Dimensions/IDimensionUnit.cs

@@ -14,5 +14,7 @@ namespace Comal.Classes
         bool HasWeight { get; set; }
         String Formula { get; set; }
         String Format { get; set; }
+        
+        bool HasDimensions();
     }
 }

+ 32 - 3
prs.desktop/Panels/Products/Locations/StockHoldingGrid.cs

@@ -246,10 +246,39 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
             column.AddItem("View Requisition Items", null, ViewRequisitions_Click);
         
         column.AddSeparator();
-
-        var requiitems = holding.LoadRequisitionItems(true).ToList();
         
-        column.AddItem("Relocate Items", null, r => RelocateItems(holding, requiitems.ToArray()));
+        column.AddItem("Relocate Items", null, r =>
+        {
+            var requiitems = holding.LoadRequisitionItems(true).ToList();
+            RelocateItems(holding, requiitems.ToArray());
+        });
+
+        if (holding.Dimensions.Unit.HasDimensions() && holding.Available.IsEffectivelyGreaterThan(0.0))
+            column.AddItem("Convert Dimensions", null, r =>
+            {
+                var calculator = new StockTransformWindow(holding);
+                if (calculator.ShowDialog() == true)
+                {
+                    var transferout = holding.CreateMovement();
+                    transferout.Date = DateTime.Now;
+                    transferout.Issued = calculator.OldAvailable;
+                    transferout.Transaction = Guid.NewGuid();
+                    transferout.Type = StockMovementType.TransferOut;
+
+                    var transferin = holding.CreateMovement();
+                    transferin.Date = transferout.Date.AddTicks(1);
+                    transferin.Dimensions.CopyFrom(calculator.Dimensions);
+                    transferin.Received = calculator.NewAvailable;
+                    transferin.Transaction = transferout.Transaction;
+                    transferin.Type = StockMovementType.TransferIn;
+                    
+                    Client.Save([transferout,transferin], "Converted Dimensions");
+                    
+                    Refresh(false,true);
+                }
+                    
+            });
+
     }
 
     private class StockIssue : BaseObject

+ 283 - 0
prs.desktop/Panels/Products/Locations/StockTransformWindow.xaml

@@ -0,0 +1,283 @@
+<Window x:Class="PRSDesktop.StockTransformWindow"
+        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:wpf="clr-namespace:InABox.WPF;assembly=InABox.Wpf"
+        xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
+        mc:Ignorable="d"
+        Title="Convert Dimensions" Height="400" Width="300" SizeToContent="Height" WindowStartupLocation="CenterScreen">
+    <Window.DataContext>
+        <local:StockTransformWindowViewModel x:Name="_viewModel"/>
+    </Window.DataContext>
+    <Window.Resources>
+        <wpf:BooleanToGridLengthConverter x:Key="BooleanToGridLengthConverter" TrueValue="40" FalseValue="0" />
+    </Window.Resources>
+    <Grid Margin="5">
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="*"/>
+            <ColumnDefinition Width="80"/>
+            <ColumnDefinition Width="80"/>
+        </Grid.ColumnDefinitions>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="40"/>
+            <RowDefinition Height="{Binding OldDimensions.Unit.HasHeight, Converter={StaticResource BooleanToGridLengthConverter}}"/>
+            <RowDefinition Height="{Binding OldDimensions.Unit.HasWidth, Converter={StaticResource BooleanToGridLengthConverter}}"/>
+            <RowDefinition Height="{Binding OldDimensions.Unit.HasLength, Converter={StaticResource BooleanToGridLengthConverter}}"/>
+            <RowDefinition Height="{Binding OldDimensions.Unit.HasQuantity, Converter={StaticResource BooleanToGridLengthConverter}}"/>
+            <RowDefinition Height="{Binding OldDimensions.Unit.HasWeight, Converter={StaticResource BooleanToGridLengthConverter}}"/>
+            <RowDefinition Height="10"/>
+            <RowDefinition Height="40"/>
+            <RowDefinition Height="40"/>
+            <RowDefinition Height="10"/>
+            <RowDefinition Height="40"/>
+        </Grid.RowDefinitions>
+        
+        <syncfusion:SfTextBoxExt
+            Grid.Row="0"
+            Grid.Column="1"
+            Text="Current"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Margin="5,5,0,0"
+            Background="WhiteSmoke"/>
+        <syncfusion:SfTextBoxExt
+            Grid.Row="0"
+            Grid.Column="2"
+            Text="New"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Margin="5,5,0,0"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+        
+        <syncfusion:SfTextBoxExt
+            Grid.Row="1"
+            Grid.Column="0"
+            Text="Height"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            Margin="5,5,0,0"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding OldDimensions.Height}"
+            Grid.Row="1"
+            Grid.Column="1"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding NewDimensions.Height, Mode=TwoWay}"
+            Grid.Row="1"
+            Grid.Column="2"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="LightYellow"/>
+        
+        <syncfusion:SfTextBoxExt
+            Grid.Row="2"
+            Grid.Column="0"
+            Text="Width"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            Margin="5,5,0,0"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding OldDimensions.Width}"
+            Grid.Row="2"
+            Grid.Column="1"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding NewDimensions.Width, Mode=TwoWay}"
+            Grid.Row="2"
+            Grid.Column="2"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="LightYellow"/>
+        
+        <syncfusion:SfTextBoxExt
+            Grid.Row="3"
+            Grid.Column="0"
+            Text="Length"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            Margin="5,5,0,0"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding OldDimensions.Length}"
+            Grid.Row="3"
+            Grid.Column="1"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding NewDimensions.Length, Mode=TwoWay}"
+            Grid.Row="3"
+            Grid.Column="2"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="LightYellow"/>
+        
+        <syncfusion:SfTextBoxExt
+            Grid.Row="4"
+            Grid.Column="0"
+            Text="Quantity"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            Margin="5,5,0,0"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding OldDimensions.Quantity}"
+            Grid.Row="4"
+            Grid.Column="1"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding NewDimensions.Quantity, Mode=TwoWay}"
+            Grid.Row="4"
+            Grid.Column="2"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="LightYellow"/>
+        
+        <syncfusion:SfTextBoxExt
+            Grid.Row="5"
+            Grid.Column="0"
+            Text="Weight"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            Margin="5,5,0,0"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding OldDimensions.Weight}"
+            Grid.Row="5"
+            Grid.Column="1"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding NewDimensions.Weight, Mode=TwoWay}"
+            Grid.Row="5"
+            Grid.Column="2"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="LightYellow"/>
+        
+        <syncfusion:SfTextBoxExt
+            Grid.Row="7"
+            Grid.Column="0"
+            Text="Unit Size"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            Margin="5,5,0,0"
+            IsReadOnly="True"/>
+        <syncfusion:SfTextBoxExt
+
+            Text="{Binding OldUnitSize}"
+            Grid.Row="7"
+            Grid.Column="1"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+        <syncfusion:SfTextBoxExt
+            Text="{Binding NewUnitSize}"
+            Grid.Row="7"
+            Grid.Column="2"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+
+        <syncfusion:SfTextBoxExt
+            Grid.Row="8"
+            Grid.Column="0"
+            Text="Available"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            Margin="5,5,0,0"
+            IsReadOnly="True"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding OldAvailable, Mode=TwoWay}"
+            MaxValue="{Binding MaxAvailable}"
+            Grid.Row="8"
+            Grid.Column="1"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="LightYellow"/>
+        <syncfusion:DoubleTextBox
+            Value="{Binding NewAvailable}"
+            Grid.Row="8"
+            Grid.Column="2"
+            Margin="5,5,0,0"
+            VerticalAlignment="Stretch"
+            HorizontalAlignment="Stretch"
+            HorizontalContentAlignment="Center"
+            VerticalContentAlignment="Center"
+            Background="WhiteSmoke"
+            IsReadOnly="True"/>
+
+
+        <Button
+            Grid.Row="10"
+            Grid.Column="1"
+            Content="OK"
+            Margin="5,5,0,0"
+            Click="OK_Click"/>
+        <Button
+            Grid.Row="10"
+            Grid.Column="2"
+            Content="Cancel"
+            Margin="5,5,0,0"
+            Click="Cancel_Click"/>
+
+    </Grid>
+</Window>

+ 112 - 0
prs.desktop/Panels/Products/Locations/StockTransformWindow.xaml.cs

@@ -0,0 +1,112 @@
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using System.Windows;
+using Comal.Classes;
+
+namespace PRSDesktop;
+
+public class StockTransformWindowViewModel : INotifyPropertyChanged
+{
+    private double _oldAvailable;
+    private double _newAvailable;
+
+    public void Load(StockHolding holding)
+    {
+        OldDimensions.CopyFrom(holding.Dimensions, true);
+        NewDimensions.CopyFrom(holding.Dimensions, true);
+        MaxAvailable = holding.Available;
+        OldAvailable = holding.Available;
+        NewAvailable = holding.Available;
+    }
+
+    public void Unload(StockHolding holding)
+    {
+        holding.Dimensions.CopyFrom(NewDimensions, true);
+        holding.Units = NewAvailable;
+    }
+    
+    public StockDimensions OldDimensions { get; private set; }
+
+    public StockDimensions NewDimensions { get; private set; }
+
+    public string OldUnitSize { get; set; }
+    
+    public string NewUnitSize { get; set; }
+
+    public double MaxAvailable { get; private set; }
+    
+    public double OldAvailable
+    {
+        get => _oldAvailable;
+        set
+        {
+            if (value.Equals(_oldAvailable)) return;
+            _oldAvailable = value;
+            NewAvailable = value * OldDimensions.Value / NewDimensions.Value;
+            OnPropertyChanged();
+        }
+    }
+
+    public double NewAvailable
+    {
+        get => _newAvailable;
+        set
+        {
+            if (value.Equals(_newAvailable)) return;
+            _newAvailable = value;
+            OnPropertyChanged();
+        }
+    }
+
+    public StockTransformWindowViewModel()
+    {
+        OldDimensions = new StockDimensions();
+        NewDimensions = new StockDimensions();
+        NewDimensions.PropertyChanged += (sender, args) =>
+        {
+            NewAvailable = OldAvailable * OldDimensions.Value / NewDimensions.Value;
+            OldUnitSize = OldDimensions.UnitSize;
+            NewUnitSize = NewDimensions.UnitSize;
+        };
+    }
+
+    public event PropertyChangedEventHandler? PropertyChanged;
+
+    protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
+    {
+        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+    }
+
+    protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
+    {
+        if (EqualityComparer<T>.Default.Equals(field, value)) return false;
+        field = value;
+        OnPropertyChanged(propertyName);
+        return true;
+    }
+}
+
+public partial class StockTransformWindow : Window
+{
+    
+    public StockDimensions Dimensions => _viewModel.NewDimensions;
+    public double NewAvailable => _viewModel.NewAvailable;
+    public double OldAvailable => _viewModel.OldAvailable;
+    
+    public StockTransformWindow(StockHolding holding)
+    {
+        InitializeComponent();
+        _viewModel.Load(holding);
+    }
+
+    private void OK_Click(object sender, RoutedEventArgs e)
+    {
+        DialogResult = true;
+    }
+
+    private void Cancel_Click(object sender, RoutedEventArgs e)
+    {
+        DialogResult = false;
+    }
+}