Ver código fonte

PRS STORES - adding required dimensions columns

Nick-PRSDigital@bitbucket.org 2 anos atrás
pai
commit
11099c4191
1 arquivos alterados com 57 adições e 21 exclusões
  1. 57 21
      prs.stores/PurchaseOrderItemStore.cs

+ 57 - 21
prs.stores/PurchaseOrderItemStore.cs

@@ -9,7 +9,7 @@ namespace Comal.Stores
 {
     internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
     {
-        
+
         private void UpdateStockMovements(PurchaseOrderItem entity)
         {
             if (!entity.Product.IsValid())
@@ -43,7 +43,16 @@ namespace Comal.Stores
                         x => x.Dimensions.Height,
                         x => x.Dimensions.Weight,
                         x => x.Notes,
-                        x => x.Cost
+                        x => x.Cost,
+                        x => x.Dimensions.Unit.HasHeight,
+                        x => x.Dimensions.Unit.HasLength,
+                        x => x.Dimensions.Unit.HasWidth,
+                        x => x.Dimensions.Unit.HasWeight,
+                        x => x.Dimensions.Unit.HasQuantity,
+                        x => x.Dimensions.Unit.Formula,
+                        x => x.Dimensions.Unit.Format,
+                        x => x.Dimensions.Unit.Code,
+                        x => x.Dimensions.Unit.Description
                     )
                 ).Rows.Select(x => x.ToObject<StockMovement>()).ToList();
                 if (!result.Any())
@@ -57,6 +66,7 @@ namespace Comal.Stores
                 return Provider.Query(
                     new Filter<Product>(x => x.ID).IsEqualTo(entity.Product.ID),
                     new Columns<Product>(
+                        x => x.ID,
                         x => x.DefaultLocation.ID,
                         x => x.Warehouse.ID,
                         x => x.Dimensions.Unit.ID,
@@ -67,7 +77,16 @@ namespace Comal.Stores
                         x => x.Dimensions.Width,
                         x => x.Dimensions.Height,
                         x => x.Dimensions.Weight,
-                        x => x.NonStock
+                        x => x.NonStock,
+                        x => x.Dimensions.Unit.HasHeight,
+                        x => x.Dimensions.Unit.HasLength,
+                        x => x.Dimensions.Unit.HasWidth,
+                        x => x.Dimensions.Unit.HasWeight,
+                        x => x.Dimensions.Unit.HasQuantity,
+                        x => x.Dimensions.Unit.Formula,
+                        x => x.Dimensions.Unit.Format,
+                        x => x.Dimensions.Unit.Code,
+                        x => x.Dimensions.Unit.Description
                     )
                 ).Rows.FirstOrDefault();
             });
@@ -85,16 +104,16 @@ namespace Comal.Stores
             Task.WaitAll(movementtask, producttask, locationtask);
 
             var movements = movementtask.Result;
-            var product = producttask.Result;
+            var productrow = producttask.Result;
             var defaultlocations = locationtask.Result;
 
-            if (product == null)
+            if (productrow == null)
             {
                 Logger.Send(LogType.Information, UserID, "Cannot Find PurchaseOrderItem.Product.ID!");
                 return;
             }
 
-            if (product.Get<Product, bool>(x => x.NonStock))
+            if (productrow.Get<Product, bool>(x => x.NonStock))
             {
                 Logger.Send(LogType.Information, UserID, "PurchaseOrderItem.Product is marked as Non Stock!");
                 return;
@@ -103,9 +122,9 @@ namespace Comal.Stores
             if (!locationValid)
             {
                 Logger.Send(LogType.Information, UserID, "PurchaseOrderItem.Location.ID is blank!");
-                if (product != null)
+                if (productrow != null)
                 {
-                    var productlocationid = product.EntityLinkID<Product, StockLocationLink>(x => x.DefaultLocation) ?? Guid.Empty;
+                    var productlocationid = productrow.EntityLinkID<Product, StockLocationLink>(x => x.DefaultLocation) ?? Guid.Empty;
                     if (productlocationid != Guid.Empty)
                     {
                         Logger.Send(LogType.Information, UserID, "- Using Product.DefaultLocation.ID as location");
@@ -113,7 +132,7 @@ namespace Comal.Stores
                     }
                     else
                     {
-                        var productwarehouseid = product.Get<Product, Guid>(c => c.Warehouse.ID);
+                        var productwarehouseid = productrow.Get<Product, Guid>(c => c.Warehouse.ID);
                         var row = defaultlocations.Rows.FirstOrDefault(r => r.Get<StockLocation, Guid>(c => c.Warehouse.ID) == productwarehouseid);
                         if (row != null)
                         {
@@ -132,7 +151,7 @@ namespace Comal.Stores
                         locationid = row.Get<StockLocation, Guid>(x => x.ID);
                     }
                 }
-                
+
                 if (locationid == Guid.Empty)
                 {
                     Logger.Send(LogType.Information, UserID, "- Cannot find Location : Skipping Movement Creation");
@@ -140,19 +159,20 @@ namespace Comal.Stores
                 }
             }
 
-            
+
             if (
-                (entity.Dimensions.Unit.ID == Guid.Empty) 
-                && (entity.Dimensions.Height == 0) 
-                && (entity.Dimensions.Width == 0) 
-                && (entity.Dimensions.Length == 0) 
+                (entity.Dimensions.Unit.ID == Guid.Empty)
+                && (entity.Dimensions.Height == 0)
+                && (entity.Dimensions.Width == 0)
+                && (entity.Dimensions.Length == 0)
                 && (entity.Dimensions.Weight == 0)
                 )
             {
                 Logger.Send(LogType.Information, UserID, "PurchaseOrderItem.Unit Size is zero!");
-                entity.Dimensions.CopyFrom(product.ToObject<Product>().Dimensions);
+                entity.Dimensions.CopyFrom(productrow.ToObject<Product>().Dimensions);
             }
-            
+
+            var product = productrow.ToObject<Product>();
 
             foreach (var movement in movements)
             {
@@ -164,12 +184,27 @@ namespace Comal.Stores
                 movement.OrderItem.ID = entity.ID;
                 movement.Job.ID = entity.Job.ID;
                 movement.Location.ID = locationid;
-                movement.Dimensions.CopyFrom(entity.Dimensions);
                 movement.Style.ID = entity.Style.ID;
                 movement.Style.Code = entity.Style.Code;
                 movement.Style.Description = entity.Style.Description;
                 movement.Notes = string.Format("Received on PO {0}", entity.PurchaseOrderLink.PONumber);
                 movement.Cost = entity.Cost;
+                movement.Dimensions.UnitSize = product.Dimensions.UnitSize;
+                movement.Dimensions.Unit.ID = product.Dimensions.Unit.ID;
+                movement.Dimensions.Height = product.Dimensions.Height;
+                movement.Dimensions.Length = product.Dimensions.Length;
+                movement.Dimensions.Width = product.Dimensions.Width;
+                movement.Dimensions.Weight = product.Dimensions.Weight;
+                movement.Dimensions.Quantity = product.Dimensions.Quantity;
+                movement.Dimensions.Unit.HasHeight = product.Dimensions.Unit.HasHeight;
+                movement.Dimensions.Unit.HasWidth = product.Dimensions.Unit.HasWidth;
+                movement.Dimensions.Unit.HasLength = product.Dimensions.Unit.HasLength;
+                movement.Dimensions.Unit.HasWeight = product.Dimensions.Unit.HasWeight;
+                movement.Dimensions.Unit.HasQuantity = product.Dimensions.Unit.HasQuantity;
+                movement.Dimensions.Unit.Formula = product.Dimensions.Unit.Formula;
+                movement.Dimensions.Unit.Format = product.Dimensions.Unit.Format;
+                movement.Dimensions.Unit.Code = product.Dimensions.Unit.Code;
+                movement.Dimensions.Unit.Description = product.Dimensions.Unit.Description;
             }
 
             var updates = movements.Where(x => x.IsChanged());
@@ -177,6 +212,7 @@ namespace Comal.Stores
                 FindSubStore<StockMovement>().Save(updates, "Updated by Purchase Order Modification");
         }
 
+
         private void DeleteStockMovements(PurchaseOrderItem entity)
         {
             var movements = Provider.Query(
@@ -187,7 +223,7 @@ namespace Comal.Stores
             if (movements.Any())
                 FindSubStore<StockMovement>().Delete(movements, "Purchase Order Item marked as Unreceived");
         }
-        
+
         protected override void BeforeSave(PurchaseOrderItem entity)
         {
             base.BeforeSave(entity);
@@ -197,7 +233,7 @@ namespace Comal.Stores
         protected override void AfterSave(PurchaseOrderItem entity)
         {
             base.AfterSave(entity);
-            
+
             if (entity.ReceivedDate.IsEmpty())
                 DeleteStockMovements(entity);
             else
@@ -231,7 +267,7 @@ namespace Comal.Stores
         {
             base.BeforeDelete(entity);
             DeleteStockMovements(entity);
-            
+
             var delete = Provider.Query(
                 new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(entity.ID),
                 new Columns<PurchaseOrderItem>(x => x.ID)