Ver código fonte

Improved Product Selection on Purchase Order Item grid

frogsoftware 11 meses atrás
pai
commit
b6e07ca0d5

+ 9 - 2
prs.classes/Entities/PurchaseOrder/PurchaseOrder.cs

@@ -283,6 +283,8 @@ namespace Comal.Classes
                     .Add(x=>x.Job.ID)
                     .Add(x=>x.SupplierCode)
                     .Add(x=>x.SupplierDescription)
+                    .Add(x=>x.SupplierLink.ID)
+                    .Add(x=>x.ForeignCurrencyPrice)
                     .Add(x=>x.CostPrice)
             );
             query.Add(
@@ -301,7 +303,8 @@ namespace Comal.Classes
             {
                 //Check Supplier / Job Specific Pricing
                 var supplierProduct = supplierProducts.FirstOrDefault(x =>
-                    x.Product.ID == item.Product.ID
+                    x.SupplierLink.ID == item.PurchaseOrderLink.SupplierLink.ID
+                    && x.Product.ID == item.Product.ID
                     && x.Style.ID == item.Style.ID
                     && x.Dimensions.Equals(item.Dimensions)
                     && x.Job.ID == item.Job.ID);
@@ -309,13 +312,15 @@ namespace Comal.Classes
                 {
                     UpdateValue<string>(item, x => x.SupplierCode, supplierProduct.SupplierCode);
                     UpdateValue<string>(item, x => x.Description, supplierProduct.SupplierDescription);
+                    UpdateValue<double>(item, x => x.ForeignCurrencyCost, supplierProduct.ForeignCurrencyPrice);
                     UpdateValue<double>(item, x => x.Cost, supplierProduct.CostPrice);
                     continue;
                 }
                 
                 // Check Supplier Pricing
                 supplierProduct = supplierProducts.FirstOrDefault(x =>
-                    x.Product.ID == item.Product.ID
+                    x.SupplierLink.ID == item.PurchaseOrderLink.SupplierLink.ID
+                    && x.Product.ID == item.Product.ID
                     && x.Style.ID == item.Style.ID
                     && x.Dimensions.Equals(item.Dimensions)
                     && x.Job.ID == Guid.Empty);
@@ -323,6 +328,7 @@ namespace Comal.Classes
                 {
                     UpdateValue<string>(item, x => x.SupplierCode, supplierProduct.SupplierCode);
                     UpdateValue<string>(item, x => x.Description, supplierProduct.SupplierDescription);
+                    UpdateValue<double>(item, x => x.ForeignCurrencyCost, supplierProduct.ForeignCurrencyPrice);
                     UpdateValue<double>(item, x => x.Cost, supplierProduct.CostPrice);
                     continue;
                 }
@@ -336,6 +342,7 @@ namespace Comal.Classes
                     UpdateValue<double>(item, x => x.Cost, productInstance.NettCost);
                 else
                     UpdateValue<double>(item, x => x.Cost, 0.0F);
+                UpdateValue<double>(item, x => x.ForeignCurrencyCost, 0.0F);
                 
             }
         }

+ 11 - 0
prs.classes/Entities/PurchaseOrder/PurchaseOrderItem.cs

@@ -92,6 +92,10 @@ namespace Comal.Classes
         [RequiredColumn]
         [DimensionsEditor(typeof(StockDimensions))]
         public override StockDimensions Dimensions { get; set; }
+        
+        [DoubleEditor(Visible = Visible.Optional)]
+        [EditorSequence(8)]
+        public double ForeignCurrencyCost { get; set; }
 
         [CurrencyEditor(Visible = Visible.Default)]
         [EditorSequence(8)]
@@ -215,6 +219,13 @@ namespace Comal.Classes
 
                 if (name.Equals(nameof(Qty)) && after is double qty)
                     ExTax = qty * Cost;
+                
+                else if (name.Equals(nameof(ForeignCurrencyCost)) && (after is double foreigncost) && 
+                         PurchaseOrderLink.SupplierLink.Currency.ID != Guid.Empty)
+                {
+                    Cost = foreigncost / (PurchaseOrderLink.SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : PurchaseOrderLink.SupplierLink.Currency.ExchangeRate);
+                    ExTax = Qty * Cost;
+                }
 
                 else if (name.Equals(nameof(Cost)) && after is double cost)
                     ExTax = Qty * cost;

+ 1 - 0
prs.classes/Entities/PurchaseOrder/PurchaseOrderLink.cs

@@ -20,6 +20,7 @@ namespace Comal.Classes
         //[NullEditor]
         public string SupplierCode { get; set; }
 
+        [RequiredColumn]
         public SupplierLink SupplierLink { get; set; }
 
         [NullEditor]

+ 1 - 1
prs.classes/Entities/Supplier/SupplierProduct.cs

@@ -100,7 +100,7 @@ namespace Comal.Classes
             }
             else if (name.Equals(nameof(TradePrice)))
             {
-                if (SupplierLink.Currency.ID != Guid.Empty) 
+                if (SupplierLink.Currency.ID != Guid.Empty)
                     ForeignCurrencyPrice = (double)after * SupplierLink.Currency.ExchangeRate;
                 CostPrice = (double)after * (100.0F - Discount) / 100.0F;
             }

+ 157 - 0
prs.desktop/Panels/PurchaseOrders/SupplierPurchaseOrderItemOneToMany.cs

@@ -24,6 +24,9 @@ public class SupplierPurchaseOrderItemOneToMany : DynamicOneToManyGrid<PurchaseO
 
     public SupplierPurchaseOrderItemOneToMany() : base()
     {
+        
+        
+        
         HiddenColumns.Add(x => x.ID);
 
         HiddenColumns.Add(x => x.Description);
@@ -78,11 +81,16 @@ public class SupplierPurchaseOrderItemOneToMany : DynamicOneToManyGrid<PurchaseO
         HiddenColumns.Add(x => x.OpenForms);
         ActionColumns.Add(new DynamicMenuColumn(BuildFormsMenu) { Position = DynamicActionColumnPosition.End });
         ActionColumns.Add(new DynamicImageColumn(FormsImage) { Position = DynamicActionColumnPosition.Start, ToolTip = FormsToolTip });
+        
     }
 
+
+
     protected override void Init()
     {
         base.Init();
+        
+        AddButton("Catalog", PRSDesktop.Resources.product.AsBitmapImage(), SearchProducts);
 
         if (Security.IsAllowed<CanViewConsignmentModule>())
         {
@@ -494,6 +502,155 @@ public class SupplierPurchaseOrderItemOneToMany : DynamicOneToManyGrid<PurchaseO
 
         base.SelectItems(rows);
     }
+    
+    private bool SearchProducts(Button button, CoreRow[] rows)
+    {
+        var dlg = new MultiSelectDialog<ProductInstance>(
+            new Filter<ProductInstance>().All(),
+            Columns.None<ProductInstance>()
+                .Add(x => x.ID)
+                .Add(x => x.Product.ID)
+                .Add(x => x.Product.Code)
+                .Add(x => x.Product.Name)
+                .Add(x => x.Product.TaxCode.ID)
+                .Add(x => x.Product.TaxCode.Code)
+                .Add(x => x.Product.TaxCode.Description)
+                .Add(x => x.Product.TaxCode.Rate)
+                .Add(x => x.Product.PurchaseGL.ID)
+                .Add(x => x.Product.PurchaseGL.Code)
+                .Add(x => x.Product.PurchaseGL.Description)
+                .Add(x => x.Product.CostCentre.ID)
+                .Add(x => x.Product.CostCentre.Code)
+                .Add(x => x.Product.CostCentre.Description)
+                .Add(x => x.Style.ID)
+                .Add(x => x.Style.Code)
+                .Add(x => x.Style.Description)
+                .AddDimensionsColumns(x => x.Dimensions)
+                .Add(x => x.NettCost),
+            false
+        );
+        if (dlg.ShowDialog() == true)
+        {
+            CreateItems(() =>
+            {
+                var result = new List<PurchaseOrderItem>();
+                var pi = dlg.Data().Rows.FirstOrDefault()?.ToObject<ProductInstance>();
+                if (pi == null)
+                    return result;
+                
+                var sp = new Client<SupplierProduct>().Query(
+                    new Filter<SupplierProduct>(x => x.Product.ID).IsEqualTo(pi.Product.ID)
+                        .And(x=>x.Style.ID).IsEqualTo(pi.Style.ID)
+                        .And(x=>x.Dimensions).DimensionEquals(pi.Dimensions),
+                    Columns.None<SupplierProduct>().Add(x => x.ID)
+                        .Add(x => x.Product.ID)
+                        .Add(x => x.Product.Code)
+                        .Add(x => x.Product.Name)
+                        .Add(x => x.Product.TaxCode.ID)
+                        .Add(x => x.Product.TaxCode.Code)
+                        .Add(x => x.Product.TaxCode.Description)
+                        .Add(x => x.Product.TaxCode.Rate)
+                        .Add(x => x.Product.PurchaseGL.ID)
+                        .Add(x => x.Product.PurchaseGL.Code)
+                        .Add(x => x.Product.PurchaseGL.Description)
+                        .Add(x => x.Product.CostCentre.ID)
+                        .Add(x => x.Product.CostCentre.Code)
+                        .Add(x => x.Product.CostCentre.Description)
+                        .Add(x => x.Style.ID)
+                        .Add(x => x.Style.Code)
+                        .Add(x => x.Style.Description)
+                        .Add(x=>x.Job.ID)
+                        .Add(x=>x.Job.JobNumber)
+                        .Add(x=>x.Job.Name)
+                        .AddDimensionsColumns(x => x.Dimensions)
+                        .Add(x => x.CostPrice)
+                        .Add(x => x.ForeignCurrencyPrice)
+                ).Rows.FirstOrDefault()?.ToObject<SupplierProduct>();
+
+                if (sp != null)
+                {
+                    var poi = CreateItem();
+                    poi.Product.ID = sp.Product.ID;
+                    poi.Product.Synchronise(sp.Product);
+                    poi.Style.ID = sp.Style.ID;
+                    poi.Style.Synchronise(sp.Style);
+                    poi.Dimensions.CopyFrom(sp.Dimensions);
+                    poi.Job.ID = sp.Job.ID;
+                    poi.Job.Synchronise(sp.Job);
+                    poi.ForeignCurrencyCost = sp.ForeignCurrencyPrice;
+                    poi.Cost = sp.CostPrice;
+                    result.Add(poi);
+                }
+                else if (pi != null)
+                {
+                    var poi = CreateItem();
+                    poi.Product.ID = pi.Product.ID;
+                    poi.Product.Synchronise(pi.Product);
+                    poi.Style.ID = pi.Style.ID;
+                    poi.Style.Synchronise(pi.Style);
+                    poi.Dimensions.CopyFrom(pi.Dimensions);
+                    poi.Cost = pi.NettCost;
+                    result.Add(poi);
+                }
+                return result;
+            });
+        }
+        return false;
+    }
+
+    protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
+    {
+        var dlg = new MultiSelectDialog<SupplierProduct>(
+            new Filter<SupplierProduct>(x => x.SupplierLink.ID).IsEqualTo(Item.SupplierLink.ID),
+            Columns.None<SupplierProduct>().Add(x => x.ID)
+                .Add(x => x.Product.ID)
+                .Add(x => x.Product.Code)
+                .Add(x => x.Product.Name)
+                .Add(x => x.Product.TaxCode.ID)
+                .Add(x => x.Product.TaxCode.Code)
+                .Add(x => x.Product.TaxCode.Description)
+                .Add(x => x.Product.TaxCode.Rate)
+                .Add(x => x.Product.PurchaseGL.ID)
+                .Add(x => x.Product.PurchaseGL.Code)
+                .Add(x => x.Product.PurchaseGL.Description)
+                .Add(x => x.Product.CostCentre.ID)
+                .Add(x => x.Product.CostCentre.Code)
+                .Add(x => x.Product.CostCentre.Description)
+                .Add(x => x.Style.ID)
+                .Add(x => x.Style.Code)
+                .Add(x => x.Style.Description)
+                .Add(x=>x.Job.ID)
+                .Add(x=>x.Job.JobNumber)
+                .Add(x=>x.Job.Name)
+                .AddDimensionsColumns(x => x.Dimensions)
+                .Add(x => x.CostPrice)
+                .Add(x => x.ForeignCurrencyPrice),
+            false
+        );
+        if (dlg.ShowDialog() == true)
+        {
+            CreateItems(() =>
+            {
+                var result = new List<PurchaseOrderItem>();
+                var sp = dlg.Data().Rows.FirstOrDefault()?.ToObject<SupplierProduct>();
+                if (sp != null)
+                {
+                    var poi = CreateItem();
+                    poi.Product.ID = sp.Product.ID;
+                    poi.Product.Synchronise(sp.Product);
+                    poi.Style.ID = sp.Style.ID;
+                    poi.Style.Synchronise(sp.Style);
+                    poi.Dimensions.CopyFrom(sp.Dimensions);
+                    poi.Job.ID = sp.Job.ID;
+                    poi.Job.Synchronise(sp.Job);
+                    poi.ForeignCurrencyCost = sp.ForeignCurrencyPrice;
+                    poi.Cost = sp.CostPrice;
+                    result.Add(poi);
+                }
+                return result;
+            });
+        }
+    }
 
     protected override void CustomiseEditor(PurchaseOrderItem[] items, DynamicGridColumn column, BaseEditor editor)
     {