|
@@ -5,6 +5,8 @@ using Comal.Classes;
|
|
|
using InABox.Core;
|
|
|
using PRSStores;
|
|
|
using System;
|
|
|
+using InABox.Database;
|
|
|
+using InABox.Scripting;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using Columns = InABox.Core.Columns;
|
|
|
|
|
@@ -13,6 +15,44 @@ namespace Comal.Stores;
|
|
|
internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
{
|
|
|
|
|
|
+ static PurchaseOrderItemStore()
|
|
|
+ {
|
|
|
+ RegisterListener<ProductDimensionUnit>(ReloadProductDimensionUnitCache);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Dictionary<Guid, ScriptDocument>? _productdimensionunitcache = null;
|
|
|
+
|
|
|
+ private static void ReloadProductDimensionUnitCache(Guid[]? ids)
|
|
|
+ {
|
|
|
+ if (_productdimensionunitcache == null)
|
|
|
+ _productdimensionunitcache = new Dictionary<Guid, ScriptDocument>();
|
|
|
+
|
|
|
+ var scripts = DbFactory.Provider.Query(
|
|
|
+ ids != null
|
|
|
+ ? new Filter<ProductDimensionUnit>(x => x.ID).InList(ids)
|
|
|
+ : null,
|
|
|
+ Columns.None<ProductDimensionUnit>()
|
|
|
+ .Add(x => x.ID)
|
|
|
+ .Add(x => x.Conversion)
|
|
|
+ ).ToDictionary<ProductDimensionUnit, Guid, String>(x => x.ID, x => x.Conversion);
|
|
|
+
|
|
|
+ foreach (var id in scripts.Keys)
|
|
|
+ {
|
|
|
+ var doc = !String.IsNullOrWhiteSpace(scripts[id]) ? new ScriptDocument(scripts[id]) : null;
|
|
|
+ if (doc?.Compile() == true)
|
|
|
+ _productdimensionunitcache[id] = doc;
|
|
|
+ else
|
|
|
+ _productdimensionunitcache.Remove(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TransformDimensions(PurchaseOrderItem item)
|
|
|
+ {
|
|
|
+ if (_productdimensionunitcache == null)
|
|
|
+ ReloadProductDimensionUnitCache(null);
|
|
|
+ if (_productdimensionunitcache?.TryGetValue(item.Dimensions.Unit.ID, out ScriptDocument? script) == true)
|
|
|
+ script.Execute("Module",DimensionUnit.ConvertDimensionsMethodName(), [item]);
|
|
|
+ }
|
|
|
|
|
|
private void UpdateStockMovements(PurchaseOrderItem entity)
|
|
|
{
|
|
@@ -26,7 +66,7 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
}
|
|
|
FindSubStore<StockMovement>().Save(movements, "Updated by purchase order modification");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void CreateStockMovements(PurchaseOrderItem entity)
|
|
|
{
|
|
|
if (!entity.Product.IsValid())
|
|
@@ -216,6 +256,8 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
Logger.Send(LogType.Information, UserID, "PurchaseOrderItem.Unit Size is zero!");
|
|
|
entity.Dimensions.CopyFrom(productrow.ToObject<Product>().DefaultInstance.Dimensions);
|
|
|
}
|
|
|
+
|
|
|
+ TransformDimensions(entity);
|
|
|
|
|
|
if (entity.Job.ID == Guid.Empty)
|
|
|
{
|
|
@@ -297,6 +339,7 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
}
|
|
|
|
|
|
FindSubStore<StockMovement>().Save(movements, "Updated by Purchase Order Modification");
|
|
|
+ entity.CancelChanges();
|
|
|
}
|
|
|
|
|
|
private static void CreateMovement(PurchaseOrderItem entity, Guid locationid, List<StockMovement> movements, JobRequisitionItem jri, double qty, double cost)
|