| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.Integration.Awg;
- using InABox.Integration.Logikal;
- using InABox.WPF;
- using Microsoft.Xaml.Behaviors.Core;
- using PRSDesktop.Integrations.Logikal;
- namespace PRSDesktop.Integrations.Common;
- public class AWGMappingWindowViewModel : DependencyObject
- {
-
- private static readonly DependencyProperty SourceTypeProperty = DependencyProperty.Register(
- nameof(SourceType),
- typeof(IntegrationSourceType),
- typeof(AWGMappingWindowViewModel)
- );
- public IntegrationSourceType SourceType
- {
- get => (IntegrationSourceType)GetValue(SourceTypeProperty);
- set => SetValue(SourceTypeProperty, value);
- }
-
- // public static DependencyProperty JobIDProperty = DependencyProperty.Register(
- // nameof(JobID),
- // typeof(Guid),
- // typeof(IntegrationBOMWindowViewModel)
- // );
- //
- // public Guid JobID
- // {
- // get => (Guid)GetValue(JobIDProperty);
- // set => SetValue(JobIDProperty, value);
- // }
-
- // public static DependencyProperty BOMProperty = DependencyProperty.Register(
- // nameof(BOM),
- // typeof(IAwgBOM<IAwgFinish, IAwgProfile, IAwgGasket, IAwgComponent, IAwgGlass, IAwgLabour>),
- // typeof(IntegrationBOMWindowViewModel),
- // new FrameworkPropertyMetadata(BOMChanged));
- //
- // private static void BOMChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- // {
- //
- // if (d is not IntegrationBOMWindowViewModel model)
- // return;
- //
- // var bom =
- // e.NewValue as IAwgBOM<IAwgFinish, IAwgProfile, IAwgGasket, IAwgComponent, IAwgGlass,
- // IAwgLabour>;
- //
- // var styles = model.ExtractMappings<ProductStyleIntegrationSource, IAwgFinish, ProductStyle, ProductStyleLink, ProductStyleIntegrationSource>(
- // bom?.Finishes, x => x.Code, x => x.Description, x => x.Code);
- //
- // var profiles = model.ExtractMappings<ProductIntegrationSource,IAwgProfile,Product,ProductLink, ProductIntegrationSource>(
- // bom?.Profiles, x => x.Code, x => x.Description, x => x.Code);
- //
- // var gaskets = model.ExtractMappings<ProductIntegrationSource,IAwgGasket,Product,ProductLink, ProductIntegrationSource>(
- // bom?.Gaskets, x => x.Code, x => x.Description, x => x.Code);
- //
- // var components = model.ExtractMappings<ProductIntegrationSource,IAwgComponent,Product,ProductLink, ProductIntegrationSource>(
- // bom?.Components, x => x.Code, x => x.Description, x => x.Code);
- //
- // var glass = model.ExtractMappings<ProductIntegrationSource,IAwgGlass,Product,ProductLink, ProductIntegrationSource>(
- // bom?.Glass, x => x.Code, x => x.Description, x => x.Code);
- //
- // var labour = model.ExtractMappings<ActivityIntegrationSource,IAwgLabour,Activity,ActivityLink, ActivityIntegrationSource>(
- // bom?.Labour, x => x.Code, x => x.Description, x => x.Code);
- //
- // Task.WaitAll(styles, profiles, gaskets, components, glass, labour);
- // model.Styles = styles.Result;
- // model.Profiles = profiles.Result;
- // model.Gaskets = gaskets.Result;
- // model.Components = components.Result;
- // model.Glass = glass.Result;
- // model.Labour = labour.Result;
- // model.CheckChanged();
- // }
- //
- // public IAwgBOM<IAwgFinish, IAwgProfile, IAwgGasket, IAwgComponent, IAwgGlass, IAwgLabour>? BOM
- // {
- // get => GetValue(BOMProperty) as IAwgBOM<IAwgFinish, IAwgProfile, IAwgGasket, IAwgComponent, IAwgGlass, IAwgLabour>;
- // set => SetValue(BOMProperty, value);
- // }
-
-
- private static readonly DependencyProperty FinishesProperty = DependencyProperty.Register(
- nameof(Finishes),
- typeof(IEnumerable<IAwgFinish>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(FinishesChanged)
- );
- private static void FinishesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgFinish> finishes)
- return;
- var mappings =
- model.ExtractMappings<ProductStyleIntegrationSource, IAwgFinish, ProductStyle, ProductStyleLink>(
- finishes, x => x.Code, x => x.Description, x => x.Code);
- mappings.Wait();
- model.FinishMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgFinish>? Finishes
- {
- get => GetValue(FinishesProperty) as IEnumerable<IAwgFinish>;
- set => SetValue(FinishesProperty, value);
- }
-
- private static readonly DependencyProperty ProfilesProperty = DependencyProperty.Register(
- nameof(Profiles),
- typeof(IEnumerable<IAwgProfile>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(ProfilesChanged)
- );
- private static void ProfilesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgProfile> profiles)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource,IAwgProfile,Product,ProductLink>(
- profiles, x => x.Code, x => x.Description, x => x.Code);
- mappings.Wait();
- model.ProfileMappings = mappings.Result;
- model.CheckChanged();
- }
-
- public IEnumerable<IAwgProfile>? Profiles
- {
- get => GetValue(ProfilesProperty) as IEnumerable<IAwgProfile>;
- set => SetValue(ProfilesProperty, value);
- }
-
- private static readonly DependencyProperty GasketsProperty = DependencyProperty.Register(
- nameof(Gaskets),
- typeof(IEnumerable<IAwgGasket>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(GasketsChanged)
- );
- private static void GasketsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGasket> gaskets)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource,IAwgGasket,Product,ProductLink>(
- gaskets, x => x.Code, x => x.Description, x => x.Code);
- mappings.Wait();
- model.GasketMappings = mappings.Result;
- model.CheckChanged();
- }
-
- public IEnumerable<IAwgGasket>? Gaskets
- {
- get => GetValue(GasketsProperty) as IEnumerable<IAwgGasket>;
- set => SetValue(GasketsProperty, value);
- }
-
- private static readonly DependencyProperty ComponentsProperty = DependencyProperty.Register(
- nameof(Components),
- typeof(IEnumerable<IAwgComponent>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(ComponentsChanged)
- );
- private static void ComponentsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgComponent> components)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource,IAwgComponent,Product,ProductLink>(
- components, x => x.Code, x => x.Description, x => x.Code);
- mappings.Wait();
- model.ComponentMappings = mappings.Result;
- model.CheckChanged();
- }
-
- public IEnumerable<IAwgComponent>? Components
- {
- get => GetValue(ComponentsProperty) as IEnumerable<IAwgComponent>;
- set => SetValue(ComponentsProperty, value);
- }
-
- private static readonly DependencyProperty GlassProperty = DependencyProperty.Register(
- nameof(Glass),
- typeof(IEnumerable<IAwgGlass>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(GlassChanged)
- );
- private static void GlassChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGlass> glass)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource,IAwgGlass,Product,ProductLink>(
- glass, x => x.Code, x => x.Description, x => x.Code);
- mappings.Wait();
- model.GlassMappings = mappings.Result;
- model.CheckChanged();
- }
-
- public IEnumerable<IAwgGlass>? Glass
- {
- get => GetValue(GlassProperty) as IEnumerable<IAwgGlass>;
- set => SetValue(GlassProperty, value);
- }
-
- private static readonly DependencyProperty LabourProperty = DependencyProperty.Register(
- nameof(Labour),
- typeof(IEnumerable<IAwgLabour>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(LabourChanged)
- );
- private static void LabourChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgLabour> labour)
- return;
- var mappings = model.ExtractMappings<ActivityIntegrationSource,IAwgLabour,Activity,ActivityLink>(
- labour, x => x.Code, x => x.Description, x => x.Code);
- mappings.Wait();
- model.LabourMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgLabour>? Labour
- {
- get => GetValue(LabourProperty) as IEnumerable<IAwgLabour>;
- set => SetValue(LabourProperty, value);
- }
-
- private static readonly DependencyProperty FinishMappingsProperty = DependencyProperty.Register(
- nameof(FinishMappings),
- typeof(List<ProductStyleIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
-
- public List<ProductStyleIntegrationSource>? FinishMappings
- {
- get => GetValue(FinishMappingsProperty) as List<ProductStyleIntegrationSource>;
- set => SetValue(FinishMappingsProperty, value);
- }
-
-
- private static readonly DependencyProperty ProfileMappingsProperty = DependencyProperty.Register(
- nameof(ProfileMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
-
- public List<ProductIntegrationSource>? ProfileMappings
- {
- get => GetValue(ProfileMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(ProfileMappingsProperty, value);
- }
-
- private static readonly DependencyProperty GasketMappingsProperty = DependencyProperty.Register(
- nameof(GasketMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
-
- public List<ProductIntegrationSource>? GasketMappings
- {
- get => GetValue(GasketMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(GasketMappingsProperty, value);
- }
-
- private static readonly DependencyProperty ComponentMappingsProperty = DependencyProperty.Register(
- nameof(ComponentMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
-
- public List<ProductIntegrationSource>? ComponentMappings
- {
- get => GetValue(ComponentMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(ComponentMappingsProperty, value);
- }
-
-
- private static readonly DependencyProperty GlassMappingsProperty = DependencyProperty.Register(
- nameof(GlassMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
-
- public List<ProductIntegrationSource>? GlassMappings
- {
- get => GetValue(GlassMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(GlassMappingsProperty, value);
- }
-
-
- private static readonly DependencyProperty LabourMappingsProperty = DependencyProperty.Register(
- nameof(LabourMappings),
- typeof(List<ActivityIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
-
- public List<ActivityIntegrationSource>? LabourMappings
- {
- get => GetValue(LabourMappingsProperty) as List<ActivityIntegrationSource>;
- set => SetValue(LabourMappingsProperty, value);
- }
-
- private static readonly DependencyProperty SectionsProperty = DependencyProperty.Register(
- nameof(Sections),
- typeof(Dictionary<string, BitmapImage>),
- typeof(AWGMappingWindowViewModel)
- );
-
- private Dictionary<string,BitmapImage> _sections = new()
- {
- { "Finishes", PRSDesktop.Resources.palette.AsBitmapImage(64, 64) },
- { "Profiles", PRSDesktop.Resources.profile.AsBitmapImage(64, 64) },
- { "Gaskets", PRSDesktop.Resources.gasket.AsBitmapImage(64, 64) },
- { "Components", PRSDesktop.Resources.fixings.AsBitmapImage(64, 64) },
- { "Glass", PRSDesktop.Resources.glass.AsBitmapImage(64, 64) },
- { "Labour", PRSDesktop.Resources.quality.AsBitmapImage(64, 64) },
- };
- public Dictionary<string, BitmapImage> Sections
- {
- get => (Dictionary<string, BitmapImage>)GetValue(SectionsProperty);
- set => SetValue(SectionsProperty, value);
- }
-
- private static readonly DependencyProperty SelectedSectionProperty = DependencyProperty.Register(
- nameof(SelectedSection),
- typeof(KeyValuePair<string, BitmapImage>),
- typeof(AWGMappingWindowViewModel)
- );
-
- public KeyValuePair<string, BitmapImage> SelectedSection
- {
- get => (KeyValuePair<string, BitmapImage>)GetValue(SelectedSectionProperty);
- set => SetValue(SelectedSectionProperty, value);
- }
-
- private static readonly DependencyProperty MappingsCompleteProperty = DependencyProperty.Register(
- nameof(MappingsComplete),
- typeof(bool),
- typeof(AWGMappingWindowViewModel)
- );
- public bool MappingsComplete
- {
- get => (bool)GetValue(MappingsCompleteProperty);
- set => SetValue(MappingsCompleteProperty, value);
- }
- private LogikalSettings _settings;
-
- public AWGMappingWindowViewModel()
- {
- Sections = _sections;
- SelectedSection = Sections.First();
- _settings = new GlobalConfiguration<LogikalSettings>().Load();
- }
-
- public Task<List<TCode>> ExtractMappings<TCode,TType,TEntity,TLink>(
- IEnumerable<TType>? items,
- Func<TType,string?> logikalcode,
- Func<TType,string?> logikaldescription,
- Expression<Func<TEntity,object?>> entitycode)
- where TType : IAwgBOMItem
- where TCode : BaseIntegrationSource<TEntity,TLink>, IRemotable, IPersistent, new()
- where TEntity : Entity, IRemotable,IPersistent, new()
- where TLink :EntityLink<TEntity>
- {
- return Task.Run(() =>
- {
- var f = entitycode.Compile();
- var results = new List<TCode>();
- if (items == null)
- return results;
- var sourceitems = new Dictionary<string, string>();
- foreach (var item in items)
- sourceitems[logikalcode(item) ?? ""] = logikaldescription(item) ?? "";
- MultiQuery query = new();
- query.Add<TEntity>(
- new Filter<TEntity>(entitycode).InList(sourceitems.Keys.ToArray()),
- Columns.Required<TEntity>().Add(x => x.ID).Add(entitycode)
- );
- var entitycodecol = $"Entity.{CoreUtils.GetFullPropertyName(entitycode, ".")}";
- query.Add<TCode>(
- new Filter<TCode>(x => x.Code).InList(sourceitems.Keys.ToArray()),
- Columns.Required<TCode>()
- .Add(x => x.ID)
- .Add(x => x.Code)
- .Add(x=>x.Entity.ID)
- .Add(entitycodecol)
- );
- query.Query();
- var mappings = query.Get<TCode>().ToObjects<TCode>().ToArray();
- var entities = query.Get<TEntity>();
- foreach (var sourceitem in sourceitems)
- {
- var result = new TCode()
- {
- Code = sourceitem.Key,
- Description = sourceitem.Value
- };
- var mapping = mappings.FirstOrDefault(x => string.Equals(x.Code, sourceitem.Key));
- if (mapping != null)
- result.Entity.CopyFrom(mapping.Entity);
- else
- {
- var entity = entities.Rows.FirstOrDefault(r => string.Equals(sourceitem.Key,r.Get<TEntity,object?>(entitycode)));
- if (entity != null)
- result.Entity.CopyFrom(entity.ToObject<TEntity>());
- }
- results.Add(result);
- result.PropertyChanged += (s, e) =>
- {
- // TMapping mapping = mappingtable.Rows.FirstOrDefault(r =>
- // string.Equals(r.Get<TMapping, String>(c => c.Code), result.Code))?.ToObject<TMapping>();
- // if (mapping == null)
- // mapping = new TMapping() { Code = result.Code };
- // mapping.Entity.ID = result.Entity.ID;
- // new Client<TMapping>().Save(mapping, "Created from BOM Integration Window");
- CheckChanged();
- };
- }
- return results;
- });
- }
- private void CheckChanged()
- {
- Dispatcher.BeginInvoke(() =>
- {
- var styles = FinishMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false;
- var profiles = ProfileMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false;
- var glass = GlassMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false;
- var components = ComponentMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false;
- var labour = LabourMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false;
- MappingsComplete = styles && profiles && glass && components && labour;
- });
- }
- public ICommand CreateStyle => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<ProductStyle, ProductStyleIntegrationSource> args)
- {
- args.Entity.Code = args.Mapping.Code ?? "";
- args.Entity.Description = args.Mapping.Description ?? "";
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- public ICommand CreateProfile => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- args.Entity.Code = args.Mapping.Code ?? "";
- args.Entity.Name = args.Mapping.Description ?? "";
- args.Entity.UnitOfMeasure.CopyFrom(_settings.ProfileUom);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
-
- public ICommand CreateGasket => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- args.Entity.Code = args.Mapping.Code ?? "";
- args.Entity.Name = args.Mapping.Description ?? "";
- args.Entity.UnitOfMeasure.CopyFrom(_settings.GasketUom);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
-
- public ICommand CreateComponent => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- args.Entity.Code = args.Mapping.Code ?? "";
- args.Entity.Name = args.Mapping.Description ?? "";
- args.Entity.UnitOfMeasure.CopyFrom(_settings.ComponentUom);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
-
- public ICommand CreateGlass => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- args.Entity.Code = args.Mapping.Code ?? "";
- args.Entity.Name = args.Mapping.Description ?? "";
- args.Entity.UnitOfMeasure.CopyFrom(_settings.GlassUom);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
-
- public ICommand CreateActivity => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Activity, ActivityIntegrationSource> args)
- {
- args.Entity.Code = args.Mapping.Code ?? "";
- args.Entity.Description = args.Mapping.Description ?? "";
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
-
- private class RawDimensions : IBaseDimensions
- {
- public double Quantity { get; set; }
- public double Length { get; set; }
- public double Width { get; set; }
- public double Height { get; set; }
- public double Weight { get; set; }
- }
- public void GetParts(
- Action<ProductLink, ProductStyleLink?, IBaseDimensions, double, double>? productCallback,
- Action<ActivityLink, TimeSpan, double>? labourCallback)
- {
- GetParts(Profiles,Gaskets,Components,Glass,Labour,productCallback,labourCallback);
- }
-
- public void GetParts<TProfile, TGasket, TComponent, TGlass, TLabour>(
- IEnumerable<TProfile>? profiles,
- IEnumerable<TGasket>? gaskets,
- IEnumerable<TComponent>? components,
- IEnumerable<TGlass>? glasses,
- IEnumerable<TLabour>? labour,
- Action<ProductLink, ProductStyleLink?, IBaseDimensions, double, double>? productCallback,
- Action<ActivityLink, TimeSpan, double>? labourCallback)
- where TProfile : IAwgProfile
- where TGasket : IAwgGasket
- where TComponent : IAwgComponent
- where TGlass : IAwgGlass
- where TLabour : IAwgLabour
- {
- if (profiles != null)
- {
- foreach (var profile in profiles)
- {
- var profilemapping = ProfileMappings?.FirstOrDefault(x => x.Code == profile.Code);
- var stylemapping = FinishMappings?.FirstOrDefault(x => string.Equals(x.Code, profile.Finish));
- if (profilemapping != null && productCallback is not null)
- {
- productCallback(
- profilemapping.Entity,
- stylemapping?.Entity,
- new RawDimensions() { Length = profile.Length },
- profile.Quantity,
- profile.Cost);
- }
- }
- }
- if (gaskets != null)
- {
- foreach (var gasket in gaskets)
- {
- var gasketmapping = GasketMappings?.FirstOrDefault(x => x.Code == gasket.Code);
- if (gasketmapping != null && productCallback is not null)
- {
- productCallback(
- gasketmapping.Entity,
- null,
- new RawDimensions() { Length = gasket.Length },
- gasket.Quantity,
- gasket.Cost);
- }
- }
- }
- if (components != null)
- {
- foreach (var component in components)
- {
- var componentmapping = ComponentMappings?.FirstOrDefault(x => string.Equals(x.Code, component.Code));
- if (componentmapping != null && productCallback is not null)
- {
- productCallback(
- componentmapping.Entity,
- null,
- new RawDimensions() { Quantity = component.PackSize },
- component.Quantity,
- component.Cost);
- }
- }
- }
- if (glasses != null)
- {
- foreach (var glass in glasses)
- {
- var glassmapping = GlassMappings?.FirstOrDefault(x => string.Equals(x.Code, glass.Code));
- if (glassmapping != null && productCallback is not null)
- {
- productCallback(
- glassmapping.Entity,
- null,
- new RawDimensions() { Height = glass.Height, Width = glass.Width },
- glass.Quantity,
- glass.Cost);
- }
- }
- }
- if (labour != null)
- {
- foreach (var activity in labour)
- {
- var activitymapping = LabourMappings?.FirstOrDefault(x => string.Equals(x.Code, activity.Code));
- if (activitymapping != null && labourCallback is not null)
- {
- labourCallback(
- activitymapping.Entity,
- TimeSpan.FromHours(activity.Quantity),
- activity.Cost);
- }
- }
- }
- }
-
- // public void CreateBOM()
- // {
- // if (Finishes == null || Profiles == null || Gaskets == null || Components == null || Glass == null || Labour == null)
- // return;
- //
- // List<JobBillOfMaterialsItem> items = new List<JobBillOfMaterialsItem>();
- //
- // foreach (var profile in Profiles)
- // {
- // var profilemapping = ProfileMappings?.FirstOrDefault(x => x.Code == profile.Code);
- // var stylemapping = FinishMappings?.FirstOrDefault(x => string.Equals(x.Code, profile.Finish));
- // if (profilemapping != null)
- // {
- // JobBillOfMaterialsItem newitem = new JobBillOfMaterialsItem();
- // newitem.Product.CopyFrom(profilemapping.Entity);
- // newitem.Dimensions.Unit.CopyFrom(profilemapping.Entity.UnitOfMeasure);
- // newitem.Dimensions.Length = profile.Length;
- // if (stylemapping != null)
- // newitem.Style.CopyFrom(stylemapping.Entity);
- // newitem.Quantity = profile.Quantity;
- // newitem.UnitCost = profile.Cost;
- // items.Add(newitem);
- // }
- // }
- //
- // foreach (var component in Components)
- // {
- // var componentmapping = ComponentMappings?.FirstOrDefault(x => string.Equals(x.Code, component.Code));
- // if (componentmapping != null)
- // {
- // JobBillOfMaterialsItem newitem = new JobBillOfMaterialsItem();
- // newitem.Product.CopyFrom(componentmapping.Entity);
- // newitem.Dimensions.Unit.CopyFrom(componentmapping.Entity.UnitOfMeasure);
- // newitem.Dimensions.Quantity = component.PackSize;
- // newitem.Quantity = component.Quantity;
- // newitem.UnitCost = component.Cost;
- // items.Add(newitem);
- // }
- // }
- //
- // foreach (var glass in Glass)
- // {
- // var glassmapping = GlassMappings?.FirstOrDefault(x => string.Equals(x.Code, glass.Code));
- // if (glassmapping != null)
- // {
- // JobBillOfMaterialsItem newitem = new JobBillOfMaterialsItem();
- // newitem.Product.CopyFrom(glassmapping.Entity);
- // newitem.Dimensions.Unit.CopyFrom(glassmapping.Entity.UnitOfMeasure);
- // newitem.Dimensions.Height = glass.Height;
- // newitem.Dimensions.Height = glass.Width;
- // newitem.Quantity = glass.Quantity;
- // newitem.UnitCost = glass.Cost;
- // items.Add(newitem);
- // }
- // }
- //
- // List<JobBillOfMaterialsActivity> activities = new List<JobBillOfMaterialsActivity>();
- //
- // foreach (var activity in Labour)
- // {
- // var activitymapping = LabourMappings?.FirstOrDefault(x => string.Equals(x.Code, activity.Code));
- // if (activitymapping != null)
- // {
- // JobBillOfMaterialsActivity newactivity = new JobBillOfMaterialsActivity();
- // newactivity.ActivityLink.CopyFrom(activitymapping.Entity);
- // newactivity.Duration = TimeSpan.FromHours(activity.Quantity);
- // newactivity.HourlyCost = activity.Cost;
- // activities.Add(newactivity);
- // }
- // }
- //
- // var _jobbom = new JobBillOfMaterials();
- // _jobbom.Job.ID = JobID;
- // _jobbom.Description = $"BOM Imported {DateTime.Now}";
- //
- // Progress.ShowModal("Creating BOM...", progress =>
- // {
- // Client.Save(_jobbom, "Imported From Logikal");
- //
- // progress.Report("Updating Items");
- // foreach (var item in items)
- // {
- // item.BillOfMaterials.ID = _jobbom.ID;
- // item.Job.ID = _jobbom.Job.ID;
- // }
- //
- // Client.Save(items, "Imported From Logikal");
- //
- // progress.Report("Updating Labour");
- // foreach (var activity in activities)
- // {
- // activity.BillOfMaterials.ID = _jobbom.ID;
- // activity.JobLink.ID = _jobbom.Job.ID;
- // }
- //
- // Client.Save(activities, "Imported From Logikal");
- //
- //
- // });
- // }
- }
|