123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using System;
- using System.Linq;
- using InABox.Core;
- using PRSClasses;
- namespace Comal.Classes
- {
- [UserTracking(typeof(Product))]
- public class SupplierProduct : StockEntity, IPersistent, IRemotable, ILicense<ProductManagementLicense>, IExportable, IImportable, IManyToMany<Supplier, Product>, IJobMaterial
- {
- private bool bChanging;
- [RequiredColumn]
- [EditorSequence(0)]
- public SupplierLink SupplierLink { get; set; }
- [EntityRelationship(DeleteAction.SetNull)]
- [NullEditor]
- [Obsolete("Replaced with Product", true)]
- public ProductLink ProductLink
- {
- get { return Product; }
- set { Product = value; }
- }
-
- [EntityRelationship(DeleteAction.SetNull)]
- [EditorSequence(1)]
- public override ProductLink Product { get; set; }
-
- [EditorSequence(2)]
- [RequiredColumn]
- [DimensionsEditor(typeof(StockDimensions))]
- public override StockDimensions Dimensions { get; set; }
-
- [EntityRelationship(DeleteAction.SetNull)]
- [EditorSequence(3)]
- public ProductStyleGroupLink StyleGroup { get; set; }
-
- [EntityRelationship(DeleteAction.SetNull)]
- [EditorSequence(4)]
- public ProductStyleLink Style { get; set; }
-
- /// <summary>
- /// The product code as the supplier knows it.
- /// </summary>
- [Comment("Product code as the supplier knows it.")]
- [CodeEditor(Editable = Editable.Enabled)]
- [EditorSequence(5)]
- public string SupplierCode { get; set; }
- /// <summary>
- /// Product description as the supplier knows it.
- /// </summary>
- [Comment("Product description as the supplier knows it.")]
- [TextBoxEditor]
- [EditorSequence(6)]
- public string SupplierDescription { get; set; }
- [TextBoxEditor]
- [EditorSequence(7)]
- public string SupplierCategory { get; set; }
-
-
- private class DiscountGroupLookup : LookupDefinitionGenerator<SupplierDiscountGroup, SupplierProduct>
- {
- public override Filter<SupplierDiscountGroup> DefineFilter(SupplierProduct[] items)
- {
- var suppliers = items.Select(x => x.SupplierLink.ID).Distinct().ToArray();
- if (suppliers.Length != 1)
- return new Filter<SupplierDiscountGroup>().None();
- return new Filter<SupplierDiscountGroup>(x=>x.Supplier.ID).IsEqualTo(suppliers[0]);
-
- }
- public override Columns<SupplierProduct> DefineFilterColumns()
- => Columns.None<SupplierProduct>().Add(x => x.SupplierLink.ID);
- public override Columns<SupplierDiscountGroup> DefineColumns()
- => Columns.None<SupplierDiscountGroup>().Add(x=>x.ID).Add(x=>x.Code).Add(x=>x.Description);
- public override string FormatDisplay(CoreRow row)
- => $"{row.Get<SupplierDiscountGroup, string>(x => x.Code)}: {row.Get<SupplierDiscountGroup, string>(x => x.Description)}";
- }
- [LookupDefinition(typeof(DiscountGroupLookup))]
- [EntityRelationship(DeleteAction.SetNull)]
- [EditorSequence(8)]
- public SupplierDiscountGroupLink DiscountGroup { get; set; }
-
- [EditorSequence(8)]
- public JobLink Job { get; set; }
-
- [CurrencyEditor(Visible = Visible.Optional)]
- [EditorSequence(9)]
- public double ForeignCurrencyPrice { get; set; }
-
- [CurrencyEditor(Visible = Visible.Optional)]
- [EditorSequence(10)]
- public double TradePrice { get; set; }
- [DoubleEditor(Visible = Visible.Optional)]
- [EditorSequence(11)]
- public double Discount { get; set; }
- [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
- [EditorSequence(12)]
- public double CostPrice { get; set; }
- [EditorSequence(13)]
- public TaxCodeLink TaxCode { get; set; }
- [URLEditor]
- [EditorSequence(14)]
- public string URL { get; set; }
- [TimestampEditor]
- [EditorSequence(15)]
- public DateTime Expired { get; set; }
-
- static SupplierProduct()
- {
- LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Code, x => x.SupplierCode);
- LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Name, x => x.SupplierDescription);
- StockEntity.LinkStockDimensions<SupplierProduct>();
- }
- private static String STYLEGROUPID = CoreUtils.GetFullPropertyName<SupplierProduct, Guid>(x => x.StyleGroup.ID, ".");
- private static String STYLEID = CoreUtils.GetFullPropertyName<SupplierProduct, Guid>(x => x.Style.ID, ".");
-
- protected override void DoPropertyChanged(string name, object? before, object? after)
- {
- base.DoPropertyChanged(name, before, after);
- if (bChanging)
- return;
- bChanging = true;
-
- if (name.Equals(nameof(ForeignCurrencyPrice)) && SupplierLink.Currency.ID != Guid.Empty)
- {
- TradePrice = (double)after / (SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : SupplierLink.Currency.ExchangeRate);
- CostPrice = TradePrice * (100.0F - Discount) / 100.0F;
- }
- else if (name.Equals(nameof(TradePrice)))
- {
- if (SupplierLink.Currency.ID != Guid.Empty)
- ForeignCurrencyPrice = (double)after * SupplierLink.Currency.ExchangeRate;
- CostPrice = (double)after * (100.0F - Discount) / 100.0F;
- }
- else if (name.Equals(nameof(Discount)))
- CostPrice = TradePrice * (100.0F - (double)after) / 100.0F;
- //else if (name.Equals(name,nameof(CostPrice)))
- // TradePrice = Discount == 100.0F ? double.MaxValue : (double)after / ((100.0F - Discount) / 100.0F);
- else if (name.Equals(STYLEGROUPID))
- Style.CopyFrom(new ProductStyleLink());
- else if (name.Equals(STYLEID))
- StyleGroup.CopyFrom(new ProductStyleGroupLink());
-
- bChanging = false;
- }
- }
- }
|