| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Linq.Expressions;
 
- using InABox.Core;
 
- using PRSClasses;
 
- namespace Comal.Classes
 
- {
 
-     [UserTracking(typeof(Bill))]
 
-     [Caption("Purchase Order Items")]
 
-     public class PurchaseOrderItem : StockEntity, IRemotable, IPersistent, IOneToMany<PurchaseOrder>, ITaxable, IOneToMany<Consignment>, IOneToMany<Job>,
 
-         ILicense<AccountsPayableLicense>, IPostableFragment<PurchaseOrder>, IJobMaterial
 
-     {
 
-         
 
-         [RequiredColumn]
 
-         [EntityRelationship(DeleteAction.Cascade)]
 
-         public PurchaseOrderLink PurchaseOrderLink { get; set; }
 
-         
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         [EditorSequence(1)]
 
-         [RequiredColumn]
 
-         public override ProductLink Product { get; set; }
 
-         
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         [EditorSequence(2)]
 
-         public ProductStyleLink Style { get; set; }
 
-         
 
-         [EditorSequence(3)]
 
-         [RequiredColumn]
 
-         [DimensionsEditor(typeof(StockDimensions))]
 
-         public override StockDimensions Dimensions { get; set; }
 
-         private class AllocationsFormula : ComplexFormulaGenerator<PurchaseOrderItem, string>
 
-         {
 
-             public override IComplexFormulaNode<PurchaseOrderItem, string> GetFormula() =>
 
-                 Aggregate<PurchaseOrderItemAllocation>(
 
-                         AggregateCalculation.Concat,
 
-                         x => x.Property(x => x.Job.JobNumber))
 
-                     .WithLink(x => x.Item.ID, x => x.ID);
 
-         }
 
-         [ComplexFormula(typeof(AllocationsFormula))]
 
-         [TextBoxEditor(Visible=Visible.Optional,Editable = Editable.Hidden)]
 
-         public string Allocations { get; set; }
 
-         
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         [EditorSequence(4)]
 
-         public JobLink Job { get; set; }
 
-         [MemoEditor(Visible = Visible.Default)]
 
-         [EditorSequence(6)]
 
-         public string Description { get; set; }
 
-         
 
-         [DoubleEditor(Visible = Visible.Default)]
 
-         [EditorSequence(7)]
 
-         public double Qty { get; set; } = 1;
 
-         
 
-         [CurrencyEditor(Visible = Visible.Optional)]
 
-         [EditorSequence(8)]
 
-         public double ForeignCurrencyCost { get; set; }
 
-         [CurrencyEditor(Visible = Visible.Default)]
 
-         [EditorSequence(9)]
 
-         public double Cost { get; set; }
 
-         
 
-         [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
 
-         [EditorSequence(10)]
 
-         public double ExTax { get; set; }
 
-         
 
-         [EditorSequence(11)]
 
-         public TaxCodeLink TaxCode { get; set; }
 
-         [NullEditor]
 
-         public double TaxRate { get; set; }
 
-         [EditorSequence(12)]
 
-         [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
 
-         public double Tax { get; set; }
 
-         [EditorSequence(13)]
 
-         [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
 
-         public double IncTax { get; set; }
 
-         
 
-         [EditorSequence("Additional",1)]
 
-         [IntegerEditor(Visible = Visible.Optional)]
 
-         public int PORevision { get; set; }
 
-         
 
-         [CodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
 
-         [EditorSequence("Additional",2)]
 
-         public string SupplierCode { get; set; }
 
-         
 
-         [EditorSequence("Additional",3)]
 
-         public PurchaseGLCodeLink PurchaseGL { get; set; }
 
-         
 
-         [EditorSequence("Additional",4)]
 
-         public CostCentreLink CostCentre { get; set; }
 
-         
 
-         [DateTimeEditor(Visible = Visible.Default)]
 
-         [EditorSequence("Additional",5)]
 
-         public DateTime DueDate { get; set; }
 
-         
 
-         [EditorSequence("Additional",6)]
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         public ConsignmentLink Consignment { get; set; }
 
-         
 
-         [EditorSequence("Additional",7)]   
 
-         public StockLocationLink StockLocation { get; set; }
 
-         
 
-         [DateTimeEditor(Visible = Visible.Default)]
 
-         [EditorSequence("Additional",8)]
 
-         public DateTime ReceivedDate { get; set; }
 
-         [TextBoxEditor(Visible = Visible.Optional)]
 
-         [EditorSequence("Additional",9)]
 
-         public string ReceivedReference { get; set; }
 
-         
 
-         
 
-         [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden, Summary = Summary.Sum)]
 
-         public double Balance { get; set; }
 
-         
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         public BillLineLink BillLine { get; set; }
 
-         [NullEditor]
 
-         public string PostedReference { get; set; }
 
-         
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         [NullEditor]
 
-         [Obsolete("Replaced with Product", true)]
 
-         public ProductLink ProductLink
 
-         {
 
-             get { return Product; }
 
-             set { /* We cannot set the 'Product' to this value, because that would stuff the SubObject internal linking, so we do nothing instead. */ }
 
-         }
 
-         
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         [NullEditor]
 
-         [Obsolete("Replaced with Style", true)]
 
-         public ProductStyleLink StyleLink
 
-         {
 
-             get { return Style; }
 
-             set { /* Same as ProductLink */ }
 
-         }
 
-         
 
-         
 
-         [NullEditor]
 
-         [Obsolete("Replaced with Dimensions", true)]
 
-         public double UnitSize { get; set; }
 
-         
 
-         [NullEditor]
 
-         [Obsolete]
 
-         public StockMovementLink StockMovement { get; set; }
 
-         
 
-         [NullEditor]
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         public ManufacturingPacketLink Packet { get; set; }
 
-         private class FormCountAggregate : ComplexFormulaGenerator<PurchaseOrderItem, int>
 
-         {
 
-             public override IComplexFormulaNode<PurchaseOrderItem, int> GetFormula() =>
 
-                 Count<PurchaseOrderItemForm, Guid>(
 
-                     x => x.Property(x => x.ID))
 
-                 .WithLink(x => x.Parent.ID, x => x.ID);
 
-         }
 
-         [NullEditor]
 
-         [ComplexFormula(typeof(FormCountAggregate))]
 
-         public int FormCount { get; set; }
 
-         private class OpenFormsAggregate : ComplexFormulaGenerator<PurchaseOrderItem, int>
 
-         {
 
-             public override IComplexFormulaNode<PurchaseOrderItem, int> GetFormula() =>
 
-                 Count<PurchaseOrderItemForm, Guid>(
 
-                     x => x.Property(x => x.ID),
 
-                     new Filter<PurchaseOrderItemForm>(x => x.FormCompleted).IsEqualTo(DateTime.MinValue)
 
-                         .Or(x => x.FormData).IsEqualTo(""))
 
-                 .WithLink(x => x.Parent.ID, x => x.ID);
 
-         }
 
-         [NullEditor]
 
-         [ComplexFormula(typeof(OpenFormsAggregate))]
 
-         public int OpenForms { get; set; }
 
-         
 
-         static PurchaseOrderItem()
 
-         {
 
-             LinkedProperties.Register<PurchaseOrderItem, ProductLink, String>(x => x.Product, x => x.Code, x => x.SupplierCode);
 
-             LinkedProperties.Register<PurchaseOrderItem, ProductLink, String>(x => x.Product, x => x.Name, x => x.Description);
 
-             
 
-             LinkedProperties.Register<PurchaseOrderItem, TaxCodeLink, Guid>(x => x.Product.TaxCode, x => x.ID, x => x.TaxCode.ID);
 
-             LinkedProperties.Register<PurchaseOrderItem, TaxCodeLink, String>(x => x.Product.TaxCode, x => x.Code,
 
-                 x => x.TaxCode.Code);
 
-             LinkedProperties.Register<PurchaseOrderItem, TaxCodeLink, String>(x => x.Product.TaxCode, x => x.Description,
 
-                 x => x.TaxCode.Description);
 
-             LinkedProperties.Register<PurchaseOrderItem, TaxCodeLink, double>(x => x.Product.TaxCode, x => x.Rate,
 
-                 x => x.TaxCode.Rate);
 
-             LinkedProperties.Register<PurchaseOrderItem, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
 
-             
 
-             LinkedProperties.Register<PurchaseOrderItem, PurchaseGLCodeLink, Guid>(x => x.Product.PurchaseGL, x => x.ID, x => x.PurchaseGL.ID);
 
-             LinkedProperties.Register<PurchaseOrderItem, CostCentreLink, Guid>(x => x.Product.CostCentre, x => x.ID, x => x.CostCentre.ID);
 
-             
 
-             LinkedProperties.Register<PurchaseOrderItem, ProductStyleLink, Guid>(x => x.Product.DefaultInstance.Style, x => x.ID, x => x.Style.ID);
 
-             LinkedProperties.Register<PurchaseOrderItem, ProductStyleLink, String>(x => x.Product.DefaultInstance.Style, x => x.Code, x => x.Style.Code);
 
-             LinkedProperties.Register<PurchaseOrderItem, ProductStyleLink, String>(x => x.Product.DefaultInstance.Style, x => x.Description, x => x.Style.Description);
 
-             LinkedProperties.Register<PurchaseOrderItem, ProductInstanceLink, double>(x => x.Product.DefaultInstance, x => x.NettCost,
 
-                 x => x.Cost);
 
-             StockEntity.LinkStockDimensions<PurchaseOrderItem>();
 
-             
 
-         }
 
-         
 
-         private bool bChanging;
 
-         protected override void DoPropertyChanged(string name, object? before, object? after)
 
-         {
 
-             base.DoPropertyChanged(name, before, after);
 
-             
 
-             if (bChanging)
 
-                 return;
 
-             try
 
-             {
 
-                 bChanging = true;
 
-                 if (name.Equals(nameof(Qty)) && after is double qty)
 
-                     ExTax = qty * Cost;
 
-                 
 
-                 else if (name.Equals(nameof(ForeignCurrencyCost)) && (after is double foreigncost) && 
 
-                          PurchaseOrderLink.SupplierLink.Currency.ID != Guid.Empty)
 
-                 {
 
-                     Cost = foreigncost / (PurchaseOrderLink.SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : PurchaseOrderLink.SupplierLink.Currency.ExchangeRate);
 
-                     ExTax = Qty * Cost;
 
-                 }
 
-                 else if (name.Equals(nameof(Cost)) && (after is double cost))
 
-                 {
 
-                     ExTax = cost * Qty;
 
-                     if (PurchaseOrderLink.SupplierLink.Currency.ID != Guid.Empty)
 
-                         ForeignCurrencyCost = cost * (PurchaseOrderLink.SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : PurchaseOrderLink.SupplierLink.Currency.ExchangeRate);
 
-                     
 
-                 }
 
-                 else if (name.Equals(nameof(ExTax)) && after is double extax)
 
-                 {
 
-                     if (Qty == 0)
 
-                         Qty = 1;
 
-                     Cost = extax / Qty;
 
-                     if (PurchaseOrderLink.SupplierLink.Currency.ID != Guid.Empty)
 
-                         ForeignCurrencyCost = Cost * (PurchaseOrderLink.SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : PurchaseOrderLink.SupplierLink.Currency.ExchangeRate);
 
-                 }
 
-                 else if (name.Equals(nameof(IncTax)) && after is double inctax)
 
-                     Balance = ReceivedDate.IsEmpty() ? inctax : 0.00F;
 
-                 else if (name.Equals(nameof(ReceivedDate)) && after is DateTime received)
 
-                     Balance = received.IsEmpty() ? IncTax : 0.00F;
 
-             }
 
-             finally
 
-             {
 
-                 bChanging = false;
 
-             }
 
-             
 
-         }
 
-     }
 
- }
 
 
  |