123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Linq.Expressions;
- using InABox.Core;
- namespace Comal.Classes
- {
- public class StockMovementDocumentCount : CoreAggregate<StockMovement, StockMovementBatchDocument, Guid>
- {
- public override Expression<Func<StockMovementBatchDocument, Guid>> Aggregate => x => x.ID;
- public override AggregateCalculation Calculation => AggregateCalculation.Count;
- public override Dictionary<Expression<Func<StockMovementBatchDocument, object>>, Expression<Func<StockMovement, object>>> Links =>
- new Dictionary<Expression<Func<StockMovementBatchDocument, object>>, Expression<Func<StockMovement, object>>>()
- {
- { StockMovementBatchDocument => StockMovementBatchDocument.EntityLink.ID, StockMovement => StockMovement.Batch.ID }
- };
- }
- public class StockMovementLink : EntityLink<StockMovement>
- {
- [NullEditor]
- public override Guid ID { get; set; }
- }
-
- public class StockMovementUnitsFormula : IFormula<StockMovement, double>
- {
- public Expression<Func<StockMovement, double>> Value => x => x.Received;
- public Expression<Func<StockMovement, double>>[] Modifiers => new Expression<Func<StockMovement, double>>[] { x => x.Issued };
- public FormulaOperator Operator => FormulaOperator.Subtract;
-
- public FormulaType Type => FormulaType.Virtual;
- }
-
- public class StockMovementQuantityFormula : IFormula<StockMovement, double>
- {
- public Expression<Func<StockMovement, double>> Value => x => x.Units;
- public Expression<Func<StockMovement, double>>[] Modifiers => new Expression<Func<StockMovement, double>>[] { x => x.Dimensions.Value };
- public FormulaOperator Operator => FormulaOperator.Multiply;
-
- public FormulaType Type => FormulaType.Virtual;
- }
- public class StockMovementIsRemnantCondition : ICondition<StockHolding, double, object>
- {
- public Expression<Func<StockHolding, double>> Left => x => x.Dimensions.Value;
- public Condition Condition => Condition.LessThan;
- public Expression<Func<StockHolding, double>> Right => x => x.Product.Dimensions.Value;
- public Expression<Func<StockHolding, object>> True => x => true;
- public Expression<Func<StockHolding, object>> False => x => null;
-
- public ConditionType Type => ConditionType.Virtual;
- }
- [UserTracking("Warehousing")]
- public class StockMovement : StockEntity, IRemotable, IPersistent, IOneToMany<StockLocation>, IOneToMany<Product>,
- ILicense<WarehouseLicense>, IStockHolding, IJobMaterial, IExportable, IImportable
- {
- [DateTimeEditor]
- [EditorSequence(0)]
- public DateTime Date { get; set; }
- [EditorSequence(1)]
- [EntityRelationship(DeleteAction.Cascade)]
- [RequiredColumn]
- public override ProductLink Product { get; set; }
- [EditorSequence(2)]
- [EntityRelationship(DeleteAction.SetNull)]
- public ProductStyleLink Style { get; set; }
- [EntityRelationship(DeleteAction.SetNull)]
- public StockLocationLink Location { get; set; }
- [DoubleEditor]
- [EditorSequence(3)]
- public double Received { get; set; }
- [DoubleEditor]
- [EditorSequence(3)]
- public double Issued { get; set; }
-
- // Units = Received - Issued
- [Formula(typeof(StockMovementUnitsFormula))]
- [EditorSequence(4)]
- [DoubleEditor(Visible=Visible.Optional, Editable = Editable.Hidden)]
- public double Units { get; set; }
-
- [EditorSequence(5)]
- [RequiredColumn]
- public override StockDimensions Dimensions { get; set; }
-
- // IsRemnant = Dimensions.Value < Product.Dimensions.Value
- [CheckBoxEditor(Editable = Editable.Hidden)]
- [Condition(typeof(StockMovementIsRemnantCondition))]
- [EditorSequence(6)]
- public bool IsRemnant { get; set; }
-
- // Qty = Units * Dimensions.Value
- [EditorSequence(7)]
- [Formula(typeof(StockMovementQuantityFormula))]
- [DoubleEditor(Editable = Editable.Hidden)]
- public double Qty { get; set; }
-
- [EditorSequence(8)]
- [EntityRelationship(DeleteAction.SetNull)]
- public JobLink Job { get; set; }
- [EditorSequence(9)]
- [EntityRelationship(DeleteAction.SetNull)]
- public EmployeeLink Employee { get; set; }
- [MemoEditor]
- [EditorSequence(10)]
- public string Notes { get; set; }
-
- [NullEditor]
- public Guid Transaction { get; set; }
- [NullEditor]
- public bool System { get; set; }
- [NullEditor]
- public bool IsTransfer { get; set; }
- [NullEditor]
- public PurchaseOrderItemLink OrderItem { get; set; }
- [NullEditor]
- public JobRequisitionItemLink JobRequisitionItem { get; set; }
- [Aggregate(typeof(StockMovementDocumentCount))]
- [NullEditor]
- public int Documents { get; set; }
- /// <summary>
- /// Used to Group together movements (particularly images)
- /// when transactions are uploaded from Mobile Devices
- /// </summary>
- [NullEditor]
- [EntityRelationship(DeleteAction.Cascade)]
- public StockMovementBatchLink Batch { get; set; }
-
- [NullEditor]
- [Obsolete("Replaced with Dimensions", true)]
- public double UnitSize { get; set; }
- [CurrencyEditor(Visible = Visible.Default)]
- [EditorSequence(11)]
- public double Cost { get; set; }
- protected override void Init()
- {
- base.Init();
- Style = new ProductStyleLink(() => this);
- Location = new StockLocationLink();
- Employee = new EmployeeLink();
- Job = new JobLink();
- Transaction = Guid.NewGuid();
- IsTransfer = false;
- OrderItem = new PurchaseOrderItemLink();
- Batch = new StockMovementBatchLink();
- JobRequisitionItem = new JobRequisitionItemLink();
- Cost = 0.0;
- }
- static StockMovement()
- {
- StockEntity.LinkStockDimensions<StockMovement>();
- LinkedProperties.Register<StockMovement, ProductStyleLink, Guid>(x=>x.Product.DefaultStyle, x => x.ID, x => x.Style.ID);
- }
- private static Column<StockMovement> unitsize = new Column<StockMovement>(x => x.Dimensions.Value);
- private static Column<StockMovement> issued = new Column<StockMovement>(x => x.Issued);
- private static Column<StockMovement> received = new Column<StockMovement>(x => x.Received);
- private bool bChanging;
- protected override void DoPropertyChanged(string name, object before, object after)
- {
- if (bChanging)
- return;
- if (unitsize.IsEqualTo(name))
- {
- bChanging = true;
- Qty = (Received - Issued) * (double)after;
- bChanging = false;
- }
- else if (issued.IsEqualTo(name))
- {
- bChanging = true;
- Units = (Received - (double)after);
- Qty = Units * Dimensions.Value;
- bChanging = false;
- }
- else if (received.IsEqualTo(name))
- {
- bChanging = true;
- Units = ((double)after - Issued);
- Qty = Units * Dimensions.Value;
- bChanging = false;
- }
- else
- base.DoPropertyChanged(name, before, after);
- }
- }
- }
|