using InABox.Core; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Comal.Classes { [Caption("Allocation")] public class PurchaseOrderItemAllocation : Entity, IRemotable, IPersistent, ILicense , IOneToMany, IOneToMany, IOneToMany { [EntityRelationship(DeleteAction.Cascade)] public PurchaseOrderItemLink Item { get; set; } /// /// This may not be blank. /// [EntityRelationship(DeleteAction.Cascade)] [EditorSequence(1)] public JobLink Job { get; set; } private class JobRequisitionItemLookup : LookupDefinitionGenerator { public override Columns DefineFilterColumns() { return base.DefineFilterColumns().Add(x => x.Job.ID); } public override Filter? DefineFilter(PurchaseOrderItemAllocation[] items) { return new Filter(x => x.Job.ID).InList(items.ToArray(x => x.Job.ID)); } } /// /// This may be an empty link. The interface is as such: if there is no JRI, then we are creating a reserve and allocation just against the job. If there is a JRI, /// then received stock is reserved and allocated for the JRI. /// [EntityRelationship(DeleteAction.Cascade)] [LookupDefinition(typeof(JobRequisitionItemLookup))] [EditorSequence(2)] public JobRequisitionItemLink JobRequisitionItem { get; set; } [EditorSequence(3)] public double Quantity { get; set; } [NullEditor] public bool Nominated { get; set; } protected override void DoPropertyChanged(string name, object? before, object? after) { base.DoPropertyChanged(name, before, after); if(name == $"{nameof(Job)}.{nameof(Job.ID)}") { JobRequisitionItem.ID = Guid.Empty; JobRequisitionItem.Clear(); } } } public class PurchaseOrderItemAllocationJobLink : EntityLink { [NullEditor] public override Guid ID { get; set; } public LightJobLink Job { get; set; } public LightPurchaseOrderItemLink Item { get; set; } } }