Browse Source

Added SplitLine to Purchase Order OneToMany

Kenric Nugteren 1 year ago
parent
commit
be98de99de

+ 78 - 0
prs.desktop/Panels/Suppliers/PurchaseOrders/SupplierPurchaseOrderItemOneToMany.cs

@@ -31,8 +31,14 @@ namespace PRSDesktop
             HiddenColumns.Add(x => x.BillLine.Deleted);
             HiddenColumns.Add(x => x.Consignment.ID);
 
+            HiddenColumns.Add(x => x.Job.ID);
+            HiddenColumns.Add(x => x.StockLocation.ID);
+            HiddenColumns.Add(x => x.PurchaseGL.ID);
+            HiddenColumns.Add(x => x.CostCentre.ID);
+            HiddenColumns.Add(x => x.Product.ID);
             HiddenColumns.Add(x => x.Product.Code);
             HiddenColumns.Add(x => x.Product.Name);
+            HiddenColumns.Add(x => x.Style.ID);
             HiddenColumns.Add(x => x.Description);
             HiddenColumns.Add(x => x.TaxCode.ID);
             HiddenColumns.Add(x => x.TaxCode.Code);
@@ -43,6 +49,18 @@ namespace PRSDesktop
             HiddenColumns.Add(x => x.Tax);
             HiddenColumns.Add(x => x.IncTax);
             HiddenColumns.Add(x => x.ReceivedDate);
+            HiddenColumns.Add(x => x.Qty);
+            HiddenColumns.Add(x => x.Balance);
+            HiddenColumns.Add(x => x.PORevision);
+            HiddenColumns.Add(x => x.DueDate);
+
+            HiddenColumns.Add(x => x.SupplierCode);
+            foreach (var column in new Columns<PurchaseOrderItem>()
+                .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local)
+                .GetColumns())
+            {
+                HiddenColumns.Add(column);
+            }
 
             HiddenColumns.Add(x => x.PurchaseOrderLink.SupplierLink.ID);
             HiddenColumns.Add(x => x.PurchaseOrderLink.Category.ID);
@@ -116,6 +134,11 @@ namespace PRSDesktop
         {
             if (row == null) return;
 
+            if (Security.CanEdit<PurchaseOrderItem>())
+            {
+                column.AddItem("Split Line", PRSDesktop.Resources.split, SplitLine, enabled: row.Get<PurchaseOrderItem, DateTime>(x => x.ReceivedDate).IsEmpty());
+            }
+
             if(row.Get<PurchaseOrderItem, Guid>(x => x.Consignment.ID) != Guid.Empty)
             {
                 column.AddItem("View Consignment", null, ViewConsignment);
@@ -128,6 +151,61 @@ namespace PRSDesktop
                 row.ToObject<PurchaseOrderItem>);
         }
 
+        private void SplitLine(CoreRow? row)
+        {
+            if (row is null)
+                return;
+            var qty = row.Get<PurchaseOrderItem, double>(x => x.Qty);
+            var value = qty / 2;
+            if(DoubleEdit.Execute("Enter quantity to split on:", 0.0, qty, ref value))
+            {
+                var first = LoadItem(row);
+                var newLine = new PurchaseOrderItem
+                {
+                };
+                newLine.BillLine.ID = first.BillLine.ID;
+                newLine.BillLine.Synchronise(first.BillLine);
+                newLine.StockLocation.ID = first.StockLocation.ID;
+                newLine.StockLocation.Synchronise(first.StockLocation);
+                newLine.Consignment.ID = first.Consignment.ID;
+                newLine.Consignment.Synchronise(first.Consignment);
+                newLine.PurchaseGL.ID = first.PurchaseGL.ID;
+                newLine.PurchaseGL.Synchronise(first.PurchaseGL);
+                newLine.CostCentre.ID = first.CostCentre.ID;
+                newLine.CostCentre.Synchronise(first.CostCentre);
+                newLine.Product.ID = first.Product.ID;
+                newLine.Product.Synchronise(first.Product);
+                newLine.Style.ID = first.Style.ID;
+                newLine.Style.Synchronise(first.Style);
+                newLine.TaxCode.ID = first.TaxCode.ID;
+                newLine.TaxCode.Synchronise(first.TaxCode);
+                newLine.PurchaseOrderLink.ID = first.PurchaseOrderLink.ID;
+                newLine.PurchaseOrderLink.Synchronise(first.PurchaseOrderLink);
+                newLine.Job.ID = first.Job.ID;
+                newLine.Job.Synchronise(first.Job);
+                newLine.Dimensions.CopyFrom(first.Dimensions);
+
+                newLine.Description = first.Description;
+                newLine.TaxRate = first.TaxRate;
+                newLine.ExTax = first.ExTax;
+                newLine.Tax = first.Tax;
+                newLine.IncTax = first.IncTax;
+                newLine.Cost = first.Cost;
+                newLine.Balance = first.Balance;
+                newLine.PORevision = first.PORevision;
+                newLine.DueDate = first.DueDate;
+                newLine.SupplierCode = first.SupplierCode;
+
+                first.Qty = value;
+                newLine.Qty = qty - value;
+
+                SaveItem(first);
+                SaveItem(newLine);
+                Refresh(false, true);
+                DoChanged();
+            }
+        }
+
         private void ViewConsignment(CoreRow? row)
         {
             if (row is null) return;