V6ProjectSelection.xaml.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using Comal.Classes;
  8. using InABox.Clients;
  9. using InABox.Core;
  10. using InABox.DynamicGrid;
  11. using InABox.Wpf;
  12. using InABox.WPF;
  13. using NPOI.OpenXmlFormats.Wordprocessing;
  14. using PRSDesktop.Integrations.V6;
  15. namespace PRSDesktop;
  16. public partial class V6ProjectSelection : Window
  17. {
  18. private V6Client _client;
  19. private Func<V6Project, bool>? _filter;
  20. private Action<V6Project>? _selected;
  21. public V6ProjectSelection(V6Client client, Func<V6Project,bool> filter, Action<V6Project> selected)
  22. {
  23. _client = client;
  24. _filter = filter;
  25. _selected = selected;
  26. InitializeComponent();
  27. ImportCosts.SelectedValue = _client.Settings.ImportCosts;
  28. ImportDesigns.SelectedValue = _client.Settings.ImportDesigns;
  29. if (_client.IsConnected)
  30. {
  31. Projects.Items = _client.GetProjects()
  32. .Where(filter)
  33. .ToList();
  34. // Task<List<V6Project>> v6Task = Task.Run(() =>
  35. // {
  36. // var _quotes = _client.IsConnected
  37. // ? _client?.GetQuotes()?.ToList()
  38. // : null;
  39. // return _quotes ?? new List<V6Project>();
  40. // });
  41. //
  42. // Task<List<JobScope>> prsTask = Task.Run(() => Client.Query<JobScope>(null,
  43. // Columns.None<JobScope>().Add(x => x.Job.ID).Add(x => x.Job.JobNumber).Add(x=>x.Job.SourceRef).Add(x=>x.Job.DefaultScope.ID).Add(x=>x.ID).Add(x=>x.Number).Add(x=>x.SourceRef)
  44. // ).ToObjects<JobScope>().ToList());
  45. //
  46. // Task.WaitAll(v6Task,prsTask);
  47. //
  48. // var quotes = v6Task.Result;
  49. // var scopes = prsTask.Result;
  50. // Projects.Items = quotes
  51. // .Where(q => string.IsNullOrWhiteSpace(q.Variation)
  52. // ? !scopes.Any(x=>string.Equals(x.Job.DefaultScope.SourceRef, $"{q.Number}"))
  53. // : !scopes.Any(x=> string.Equals(x.SourceRef,$"{q.Number}")))
  54. // .ToList();
  55. }
  56. else
  57. {
  58. MessageWindow.ShowMessage("Not Connected to V6!","Error");
  59. Projects.Items = new List<V6Project>();
  60. }
  61. Projects.Refresh(true,true);
  62. }
  63. private void Cancel_Click(object sender, RoutedEventArgs e)
  64. {
  65. DialogResult = false;
  66. }
  67. private void Projects_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  68. {
  69. Ok.IsEnabled = Projects.SelectedRows.Any();
  70. }
  71. private void OK_Click(object sender, RoutedEventArgs e)
  72. {
  73. var _project = Projects.LoadItem(Projects.SelectedRows.First());
  74. _selected?.Invoke(_project);
  75. DialogResult = true;
  76. // var _importCosts = (V6CostType)ImportCosts.SelectedValue;
  77. // var _importDesigns = (V6DesignType)ImportDesigns.SelectedValue;
  78. //
  79. // ManufacturingTemplate? _template = new ManufacturingTemplate();
  80. // ManufacturingTemplateStage[] _stages = [];
  81. //
  82. // MultiQuery query = new MultiQuery();
  83. //
  84. // if (_importDesigns == V6DesignType.Approved)
  85. // {
  86. // query.Add(new Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo(_client.Settings.PacketTemplate));
  87. // query.Add(new Filter<ManufacturingTemplateStage>(x => x.Template.Code).IsEqualTo(_client.Settings.PacketTemplate));
  88. // }
  89. //
  90. // query.Query();
  91. //
  92. // if (_importDesigns == V6DesignType.Approved)
  93. // {
  94. // _template = query.Get<ManufacturingTemplate>().Rows.FirstOrDefault()?.ToObject<ManufacturingTemplate>();
  95. // _stages = query.Get<ManufacturingTemplateStage>().ToObjects<ManufacturingTemplateStage>().ToArray();
  96. // }
  97. //
  98. // if (_template == null)
  99. // {
  100. // MessageWindow.ShowMessage(
  101. // "Packet Template setting has not been configured correctly!\nPlease correct this and try again.", "Error");
  102. // return;
  103. // }
  104. //
  105. // List<string> _finishes = new();
  106. // List<V6Profile> _profiles = new();
  107. // List<V6Component> _components = new();
  108. // List<V6Glass> _glass = new();
  109. // List<V6Labour> _labour = new();
  110. //
  111. // List<ProductStyle> _styles = new();
  112. // List<Product> _products = new();
  113. // List<Activity> _activities = new();
  114. //
  115. // Dictionary<V6Elevation, V6Drawings> _designs = new();
  116. //
  117. // List<V6Profile> _missingProfiles = new();
  118. // List<V6Component> _missingComponents = new();
  119. // List<V6Glass> _missingGlass = new();
  120. // List<V6Labour> _missingLabour = new();
  121. // List<string> _missingFinishes = new();
  122. //
  123. // string exception = null;
  124. //
  125. // if (_importCosts != V6CostType.None)
  126. // {
  127. //
  128. // Progress.ShowModal("Checking Products", progress =>
  129. // {
  130. //
  131. // try
  132. // {
  133. // progress.Report("Loading Profiles");
  134. // _profiles = _client.GetProfiles(_project.Number, _project.Variation);
  135. // }
  136. // catch (Exception _exception)
  137. // {
  138. // exception = $"Error retrieving Profiles : {_exception.Message}";
  139. // return;
  140. // }
  141. //
  142. // try
  143. // {
  144. // progress.Report("Loading Components");
  145. // _components = _client.GetComponents(_project.Number, _project.Variation);
  146. // }
  147. // catch (Exception _exception)
  148. // {
  149. // exception = $"Error retrieving Components : {_exception.Message}";
  150. // return;
  151. // }
  152. //
  153. // try
  154. // {
  155. // progress.Report("Loading Glass");
  156. // _glass = _client.GetGlass(_project.Number, _project.Variation);
  157. // }
  158. // catch (Exception _exception)
  159. // {
  160. // exception = $"Error retrieving Glass : {_exception.Message}";
  161. // return;
  162. // }
  163. //
  164. // progress.Report("Checking PRS Codes");
  165. //
  166. // MultiQuery query = new MultiQuery();
  167. //
  168. // var _productStyles = _profiles.Select(x => x.Finish)
  169. // .Union(_glass.Select(x => x.Treatment))
  170. // .Distinct()
  171. // .ToArray();
  172. //
  173. // query.Add(
  174. // new Filter<ProductStyle>(x => x.Code).InList(_productStyles),
  175. // Columns.None<ProductStyle>().Add(x => x.ID).Add(x => x.Code)
  176. // );
  177. //
  178. // var _productcodes = _profiles.Select(x => x.Code)
  179. // .Union(_components.Select(x => x.Code))
  180. // .Union(_glass.Select(x => x.Code))
  181. // .Distinct()
  182. // .ToArray();
  183. //
  184. // query.Add(
  185. // new Filter<Product>(x => x.Code).InList(_productcodes),
  186. // Columns.None<Product>()
  187. // .Add(x => x.ID)
  188. // .Add(x => x.Code)
  189. // .Add(x => x.Name)
  190. // .Add(x => x.UnitOfMeasure.ID)
  191. // .Add(x => x.UnitOfMeasure.Code)
  192. // .Add(x => x.UnitOfMeasure.Description)
  193. // .Add(x => x.UnitOfMeasure.HasQuantity)
  194. // .Add(x => x.UnitOfMeasure.HasLength)
  195. // .Add(x => x.UnitOfMeasure.HasWidth)
  196. // .Add(x => x.UnitOfMeasure.HasHeight)
  197. // .Add(x => x.UnitOfMeasure.Format)
  198. // .Add(x => x.UnitOfMeasure.Formula)
  199. // .Add(x => x.TaxCode.ID)
  200. // .Add(x => x.TaxCode.Code)
  201. // );
  202. //
  203. // query.Query();
  204. //
  205. // _styles = query.Get<ProductStyle>().ToObjects<ProductStyle>().ToList();
  206. // _products = query.Get<Product>().ToObjects<Product>().ToList();
  207. //
  208. // _missingFinishes.AddRange(_productStyles.Where(c => !string.IsNullOrWhiteSpace(c) && !_styles.Any(p => string.Equals(p.Code, c))));
  209. //
  210. // var _missingCodes = _productcodes.Where(c => !_products.Any(p => string.Equals(p.Code, c))).ToArray();
  211. // _missingProfiles.AddRange(_profiles.Where(x => _missingCodes.Contains(x.Code)));
  212. // _missingComponents.AddRange(_components.Where(x => _missingCodes.Contains(x.Code)));
  213. // _missingGlass.AddRange(_glass.Where(x => _missingCodes.Contains(x.Code)));
  214. //
  215. // });
  216. //
  217. // if (!string.IsNullOrWhiteSpace(exception))
  218. // {
  219. // MessageWindow.ShowMessage(exception,"V6 Error",PRSDesktop.Resources.warning.AsBitmapImage());
  220. // return;
  221. // }
  222. //
  223. // if (_missingProfiles.Any() || _missingComponents.Any() || _missingGlass.Any())
  224. // {
  225. // if (!MessageWindow.ShowYesNo(
  226. // $"The following products do not exist in PRS\n" +
  227. // $"- {string.Join("\n- ", _missingProfiles.Select(x => x.Code)
  228. // .Union(_missingComponents.Select(x => x.Code))
  229. // .Union(_missingGlass.Select(x => x.Code))
  230. // .Distinct().OrderBy(x => x))}\n\n" +
  231. // $"Do you wish to create them now?",
  232. // "Create Missing Products"))
  233. // return;
  234. // }
  235. //
  236. // if (_missingFinishes.Any())
  237. // {
  238. // if (!MessageWindow.ShowYesNo(
  239. // $"The following styles do not exist in PRS\n" +
  240. // $"- {string.Join("\n- ", _missingFinishes
  241. // .Distinct().OrderBy(x => x))}\n\n" +
  242. // $"Do you wish to create them now?",
  243. // "Create Missing Styles"))
  244. // return;
  245. // }
  246. //
  247. // Progress.ShowModal("Checking Labour", progress =>
  248. // {
  249. //
  250. // progress.Report("Loading Labour");
  251. // _labour = _client.GetLabour(_project.Number, _project.Variation);
  252. // var _labourcodes = _labour.Select(x => x.Code).Distinct().ToArray();
  253. // _activities = Client.Query(
  254. // new Filter<Activity>(x => x.Code).InList(_labourcodes),
  255. // Columns.None<Activity>()
  256. // .Add(x => x.ID)
  257. // .Add(x => x.Code)
  258. // .Add(x => x.Description)
  259. // ).ToObjects<Activity>().ToList();
  260. // var _missingCodes = _labourcodes.Where(l => !_activities.Any(a => string.Equals(a.Code, l))).ToArray();
  261. // _missingLabour.AddRange(_labour.Where(x => _missingCodes.Contains(x.Code)));
  262. //
  263. // });
  264. //
  265. // if (_missingLabour.Any())
  266. // {
  267. // if (!MessageWindow.ShowOKCancel(
  268. // $"The following products do not exist in PRS\n" +
  269. // $"- {string.Join("\n- ", _missingLabour.Select(x => x.Code).Distinct().OrderBy(x => x))}\n\n" +
  270. // $"Do you wish to create them?",
  271. // "Create Missing Activities"))
  272. // return;
  273. // }
  274. // }
  275. //
  276. // List<String> designExceptions = new();
  277. // if (_importDesigns != V6DesignType.None)
  278. // {
  279. //
  280. // List<V6Elevation> _designlist = new();
  281. // Progress.ShowModal("Checking Designs", progress =>
  282. // {
  283. // try
  284. // {
  285. // _designlist = _client.GetItems(_project.Number, _project.Variation);
  286. // }
  287. // catch (Exception _exception)
  288. // {
  289. // designExceptions.Add($"Error retrieving designs : {_exception.Message}");
  290. // return;
  291. // }
  292. //
  293. // foreach (var _design in _designlist)
  294. // {
  295. // try
  296. // {
  297. // _designs[_design] = new V6Drawings();
  298. // }
  299. // catch (Exception _exception)
  300. // {
  301. // designExceptions.Add($"Error retrieving design [{_design.Description}]: {_exception.Message}");
  302. // }
  303. // }
  304. //
  305. // });
  306. // }
  307. //
  308. // if (designExceptions.Any())
  309. // {
  310. // MessageWindow.ShowMessage(string.Join("\n",designExceptions),"V6 Error",PRSDesktop.Resources.warning.AsBitmapImage());
  311. // return;
  312. // }
  313. //
  314. // string createException = "";
  315. // Progress.ShowModal("Creating Job", progress =>
  316. // {
  317. // try
  318. // {
  319. //
  320. // var _scope = CreateJob(_project, _client.Settings.JobStatus, _client.Settings.TaxCode);
  321. //
  322. // // if (_importCosts != V6ImportCosts.None)
  323. // // {
  324. // // CreateMissingStyles(_missingFinishes, _styles);
  325. // // CreateMissingProducts<V6Profile>(_profileUom, _taxCode, _missingProfiles, _products);
  326. // // CreateMissingProducts<V6Component>(_componentUom, _taxCode, _missingComponents, _products);
  327. // // CreateMissingProducts<V6Glass>(_glassUom, _taxCode, _missingGlass, _products);
  328. // // CreateMissingLabour(_missingLabour, _activities);
  329. // //
  330. // // progress.Report("Creating Bill of Materials");
  331. // // var bom = CreateBillofMaterials(_project, _scope,
  332. // // _profiles, _profileUom,
  333. // // _components, _componentUom,
  334. // // _glass, _glassUom,
  335. // // _products, _styles);
  336. // //
  337. // // if (_importCosts == V6ImportCosts.Requisitions)
  338. // // {
  339. // // // Convert BOM to Requisition
  340. // // }
  341. // //
  342. // // progress.Report("Creating Labour Budget");
  343. // // CreateActivities(_project, _scope, _labour, _activities);
  344. // // }
  345. // //
  346. // // if (_importDesigns != V6ImportDesigns.None)
  347. // // {
  348. // // progress.Report("Loading Drawings");
  349. // // foreach (var _key in _designs.Keys)
  350. // // {
  351. // // progress.Report($"Loading Drawing: {_key.Description}");
  352. // // _designs[_key] = _client.GetDrawings(_key.ID);
  353. // // }
  354. // //
  355. // // if (_importDesigns == V6ImportDesigns.ForApproval)
  356. // // CreateStagedSetouts(_project, _scope, _designs, _template, _stages);
  357. // // else
  358. // // CreateManufacturingPackets(_project, _scope, _designs, _template, _stages);
  359. // // }
  360. // }
  361. // catch (Exception _exception)
  362. // {
  363. // createException = $"Error Creating Job: {_exception.Message}\n{_exception.StackTrace}";
  364. // }
  365. // });
  366. //
  367. // if (!string.IsNullOrWhiteSpace(createException))
  368. // {
  369. // MessageWindow.ShowMessage(createException,"PRS Error",PRSDesktop.Resources.warning.AsBitmapImage());
  370. // return;
  371. // }
  372. //
  373. // // List<String> _missing = new();
  374. // // _missing.AddRange(_missingLabour.Select(x => $"- Activity {x.Code}: {x.Description}").Distinct().OrderBy(x => x));
  375. // // _missing.AddRange(_missingFinishes.Select(x => $"- Style {x}").Distinct().OrderBy(x => x));
  376. // // _missing.AddRange(_missingProfiles.Select(x => $"- Product {x.Code}: {x.Description}")
  377. // // .Union(_missingComponents.Select(x => $"- Product {x.Code}: {x.Description}"))
  378. // // .Union(_missingGlass.Select(x => $"- Product {x.Code}: {x.Description}"))
  379. // // .Distinct()
  380. // // .OrderBy(x => x));
  381. // // if (_missing.Any())
  382. // // MessageWindow.ShowMessage($"The following items were auto-created and should be manually checked:\n{String.Join("\n",_missing)}","Results");
  383. // DialogResult = true;
  384. }
  385. // private static void CreateMissingLabour(List<V6Labour> missinglabour, List<Activity> activitylist)
  386. // {
  387. // List<Activity> _updates = new();
  388. // foreach (var _missing in missinglabour)
  389. // {
  390. // if (!_updates.Any(x => String.Equals(x.Code, _missing.Code)))
  391. // {
  392. // var _activity = new Activity();
  393. // _activity.Code = _missing.Code;
  394. // _activity.Description = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(_missing.Code.ToLower());
  395. // _activity.Problem.Notes = new string[] { "Created by V6 Import" };
  396. // _updates.Add(_activity);
  397. // }
  398. // }
  399. //
  400. // Client.Save(_updates, "Created by V6 Import");
  401. // activitylist.AddRange(_updates);
  402. // }
  403. //
  404. // private static void CreateMissingStyles( List<string> missingitems, List<ProductStyle> styleList)
  405. // {
  406. //
  407. // List<ProductStyle> _updates = new();
  408. // foreach (var _missingitem in missingitems)
  409. // {
  410. // if (!_updates.Any(x => String.Equals(x.Code, _missingitem)))
  411. // {
  412. // var _productstyle = new ProductStyle();
  413. // _productstyle.Code = _missingitem;
  414. // _productstyle.Description = _missingitem;
  415. // _productstyle.Problem.Notes = new string[] { "Created by V6 Import" };
  416. // _updates.Add(_productstyle);
  417. // }
  418. // }
  419. //
  420. // Client.Save(_updates, "Created by V6 Import");
  421. // styleList.AddRange(_updates);
  422. // }
  423. //
  424. // private static void CreateMissingProducts<T>(ProductDimensionUnit uom, TaxCode tax, List<T> missingitems, List<Product> productlist) where T : V6BOMItem
  425. // {
  426. //
  427. // List<Product> _updates = new();
  428. // foreach (var _missingitem in missingitems)
  429. // {
  430. // if (!_updates.Any(x => String.Equals(x.Code, _missingitem.Code)))
  431. // {
  432. // var _product = new Product();
  433. // _product.UnitOfMeasure.CopyFrom(uom);
  434. // _product.Code = _missingitem.Code;
  435. // _product.Name = _missingitem.Description;
  436. // _product.Problem.Notes = new string[] { "Created by V6 Import" };
  437. // _product.TaxCode.CopyFrom(tax);
  438. // _updates.Add(_product);
  439. // }
  440. // }
  441. //
  442. // Client.Save(_updates, "Created by V6 Import");
  443. // productlist.AddRange(_updates);
  444. // }
  445. // private static JobScope CreateJob(V6Project project, JobStatusLink status, TaxCodeLink tax)
  446. // {
  447. // var _jobno = $"V{project.Number}";
  448. // MultiQuery query = new MultiQuery();
  449. // query.Add(
  450. // new Filter<Job>(x=>x.JobNumber).IsEqualTo(_jobno),
  451. // Columns.Required<Job>().Add(x=>x.DefaultScope.ID)
  452. // );
  453. // if (!string.IsNullOrWhiteSpace(project.ClientID))
  454. // {
  455. // query.Add(
  456. // new Filter<Customer>(x => x.Code).IsEqualTo(project.ClientID),
  457. // Columns.Required<Customer>()
  458. // );
  459. // }
  460. // query.Query();
  461. //
  462. // var _scope = new JobScope();
  463. //
  464. // var _job = query.Get<Job>().ToObjects<Job>().FirstOrDefault();
  465. //
  466. // var _customer = !string.IsNullOrWhiteSpace(project.ClientID)
  467. // ? query.Get<Customer>().ToObjects<Customer>().FirstOrDefault()
  468. // : null;
  469. //
  470. // if (_job == null)
  471. // {
  472. //
  473. // if (!string.IsNullOrWhiteSpace(project.ClientID) && _customer == null)
  474. // {
  475. // _customer = new Customer();
  476. // _customer.Code = project.ClientID;
  477. // _customer.Name = project.ClientName;
  478. // _customer.Delivery.Street = project.Street;
  479. // _customer.Delivery.City = project.City;
  480. // _customer.Delivery.State = project.State;
  481. // _customer.Delivery.PostCode = project.PostCode;
  482. // Client.Save(_customer,"Imported From V6");
  483. // }
  484. //
  485. // _job = new Job();
  486. // _job.JobNumber = _jobno;
  487. // _job.Name = project.Title;
  488. // _job.JobStatus.CopyFrom(status);
  489. // if (_customer != null)
  490. // {
  491. // _job.Customer.CopyFrom(_customer);
  492. // _job.Account.CopyFrom(_customer);
  493. // }
  494. // _job.SiteAddress.Street = project.Street;
  495. // _job.SiteAddress.City = project.City;
  496. // _job.SiteAddress.State = project.State;
  497. // _job.SiteAddress.PostCode = project.PostCode;
  498. // Client.Save(_job,"Imported From V6");
  499. // _scope.ID = _job.DefaultScope.ID;
  500. // _scope.CommitChanges();
  501. // }
  502. // _scope.Job.ID = _job.ID;
  503. // _scope.Number = project.Variation;
  504. // _scope.SourceRef = $"{project.ID}.{project.Revision}";
  505. // _scope.Description = string.IsNullOrWhiteSpace(project.Variation)
  506. // ? "Main Job"
  507. // : project.Title;
  508. // _scope.ExTax = project.SellPrice;
  509. // _scope.TaxCode.CopyFrom(tax);
  510. // _scope.Type = string.IsNullOrWhiteSpace(project.Variation)
  511. // ? JobScopeType.Contract
  512. // : JobScopeType.Variation;
  513. // Client.Save(_scope, "Imported From V6");
  514. // return _scope;
  515. // }
  516. // private JobBillOfMaterials CreateBillofMaterials(V6Quote quote,
  517. // JobScope scope,
  518. // List<V6Profile> profiles, ProductDimensionUnit profileUOM,
  519. // List<V6Component> components, ProductDimensionUnit componentUOM,
  520. // List<V6Glass> glass, ProductDimensionUnit glassUOM,
  521. // List<Product> _products, List<ProductStyle> _styles)
  522. // {
  523. // var _bom = new JobBillOfMaterials();
  524. // _bom.Job.ID = scope.Job.ID;
  525. // _bom.Description = string.IsNullOrWhiteSpace(quote.Variation)
  526. // ? "Main Job"
  527. // : $"{quote.Variation}";
  528. // Client.Save(_bom,"Imported From V6");
  529. //
  530. // List<JobBillOfMaterialsItem> _bomitems = new();
  531. //
  532. // foreach (var _profile in profiles)
  533. // {
  534. // var _bomitem = new JobBillOfMaterialsItem();
  535. // _bomitem.BillOfMaterials.ID = _bom.ID;
  536. // _bomitem.Job.ID = scope.Job.ID;
  537. // _bomitem.Scope.ID = scope.ID;
  538. //
  539. // if (_products.FirstOrDefault(x => x.Code == _profile.Code) is { } _p)
  540. // {
  541. // _bomitem.Product.CopyFrom(_p);
  542. // _bomitem.Dimensions.Unit.CopyFrom(profileUOM);
  543. // _bomitem.Dimensions.Length = _profile.Length;
  544. // }
  545. // else
  546. // _bomitem.Problem.Notes = new string[] { $"Unable to Locate Product: {_profile.Quantity} x {_profile.Code}: {_profile.Description} ({_profile.Length})" };
  547. //
  548. // if (!string.IsNullOrWhiteSpace(_profile.Finish))
  549. // {
  550. // if (_styles.FirstOrDefault(x => x.Code == _profile.Finish) is { } _s)
  551. // _bomitem.Style.CopyFrom(_s);
  552. // else
  553. // _bomitem.Problem.Notes = new string[] { $"Unable to Locate Style: {_profile.Finish}" };
  554. // }
  555. //
  556. // _bomitem.Quantity = _profile.Quantity;
  557. // _bomitem.UnitCost = _profile.Cost;
  558. // _bomitems.Add(_bomitem);
  559. // }
  560. //
  561. // foreach (var _component in components)
  562. // {
  563. // var _bomitem = new JobBillOfMaterialsItem();
  564. // _bomitem.BillOfMaterials.ID = _bom.ID;
  565. // _bomitem.Job.ID = scope.Job.ID;
  566. // _bomitem.Scope.ID = scope.ID;
  567. // if (_products.FirstOrDefault(x => x.Code == _component.Code) is { } _s)
  568. // {
  569. // _bomitem.Product.CopyFrom(_s);
  570. // _bomitem.Dimensions.Unit.CopyFrom(componentUOM);
  571. // _bomitem.Dimensions.Quantity = 1;
  572. // _bomitems.Add(_bomitem);
  573. // }
  574. // else
  575. // _bomitem.Problem.Notes = new string[] { $"Unable to Locate Product: {_component.Quantity} x {_component.Code}: {_component.Description} ({_component.PackSize})" };
  576. //
  577. // _bomitem.Quantity = _component.Quantity * _component.PackSize;
  578. // _bomitem.UnitCost = _component.Cost;
  579. // }
  580. //
  581. // foreach (var _glass in glass)
  582. // {
  583. // var _bomitem = new JobBillOfMaterialsItem();
  584. // _bomitem.BillOfMaterials.ID = _bom.ID;
  585. // _bomitem.Job.ID = scope.Job.ID;
  586. // _bomitem.Scope.ID = scope.ID;
  587. // if (_products.FirstOrDefault(x => x.Code == _glass.Code) is { } _p)
  588. // {
  589. // _bomitem.Product.CopyFrom(_p);
  590. // _bomitem.Dimensions.Unit.CopyFrom(glassUOM);
  591. // _bomitem.Dimensions.Height = _glass.Height * 25.4;
  592. // _bomitem.Dimensions.Width = _glass.Width * 25.4;
  593. // _bomitems.Add(_bomitem);
  594. // }
  595. // else
  596. // _bomitem.Problem.Notes = new string[] {
  597. // $"Unable to Locate Product: {_glass.Code}: {_glass.Description} ({_glass.Height} x {_glass.Width})" };
  598. //
  599. // if (!string.IsNullOrWhiteSpace(_glass.Treatment))
  600. // {
  601. // if (_styles.FirstOrDefault(x => x.Code == _glass.Treatment) is { } _s)
  602. // _bomitem.Style.CopyFrom(_s);
  603. // else
  604. // _bomitem.Problem.Notes = new string[] { $"Unable to Locate Style: {_glass.Treatment})" };
  605. // }
  606. //
  607. // _bomitem.Quantity = _glass.Quantity;
  608. // _bomitem.UnitCost = _glass.Cost;
  609. //
  610. // }
  611. //
  612. // Client.Save(_bomitems,"Imported From V6");
  613. // return _bom;
  614. // }
  615. //
  616. // private void CreateActivities(V6Quote project, JobScope scope, List<V6Labour> labour, List<Activity> activities)
  617. // {
  618. // var _jobactivities = Client.Query(
  619. // new Filter<JobActivity>(x => x.JobLink.ID).IsEqualTo(scope.Job.ID),
  620. // Columns.Required<JobActivity>()
  621. // .Add(x => x.JobLink.ID)
  622. // .Add(x => x.ActivityLink.ID)
  623. // .Add(x => x.Budget)
  624. // ).ToObjects<JobActivity>().ToList();
  625. //
  626. // List<JobActivity> _updates = new List<JobActivity>();
  627. // foreach (var _labour in labour)
  628. // {
  629. // var _activity = activities.FirstOrDefault(x => string.Equals(x.Code, _labour.Code)) ?? new Activity();
  630. // var _jobactivity = _jobactivities.FirstOrDefault(x => x.ActivityLink.ID == _activity.ID) ?? new JobActivity();
  631. // _jobactivity.JobLink.ID = scope.Job.ID;
  632. // _jobactivity.ActivityLink.CopyFrom(_activity);
  633. // _jobactivity.Budget += TimeSpan.FromHours(_labour.Quantity);
  634. // _updates.Add(_jobactivity);
  635. // }
  636. // Client.Save(_updates,"Imported From V6");
  637. // }
  638. //
  639. // private void CreateManufacturingPackets(V6Quote project, JobScope scope, Dictionary<V6Elevation, V6Drawings> designs, ManufacturingTemplate template, ManufacturingTemplateStage[] stages)
  640. // {
  641. // foreach (var _design in designs)
  642. // {
  643. // var _setout = new Setout();
  644. // _setout.JobLink.ID = scope.Job.ID;
  645. // _setout.Description = _design.Key.Description;
  646. // _setout.Number = _design.Key.Description;
  647. // Client.Save(_setout,"Imported From V6");
  648. //
  649. // var _drawings = _client.DecodeDrawings(_design.Value.Drawings, new string[] { "FrameDrawing" });
  650. // List<Document> _documents = new();
  651. // foreach (var _drawing in _drawings)
  652. // {
  653. // var _document = new Document();
  654. // _document.FileName = System.IO.Path.ChangeExtension(_drawing.FileName, ".pdf");
  655. // _document.Data = ImageUtils.BitmapToPdf(_drawing.Data);
  656. // _documents.Add(_document);
  657. // }
  658. // if (_documents.Any())
  659. // Client.Save(_documents, "Imported From V6");
  660. //
  661. // List<SetoutDocument> _setoutdocuments = new();
  662. // foreach (var _document in _documents)
  663. // {
  664. // var _setoutdocument = new SetoutDocument();
  665. // _setoutdocument.EntityLink.CopyFrom(_setout);
  666. // _setoutdocument.DocumentLink.CopyFrom(_document);
  667. // _setoutdocument.Thumbnail = ImageUtils.GetPDFThumbnail(_document.Data, 256, 256);
  668. // _setoutdocuments.Add(_setoutdocument);
  669. // }
  670. // if (_setoutdocuments.Any())
  671. // Client.Save(_setoutdocuments, "Imported From V6");
  672. //
  673. // var _packet = new ManufacturingPacket();
  674. // _packet.SetoutLink.ID = _setout.ID;
  675. // _packet.ManufacturingTemplateLink.CopyFrom(template);
  676. // _packet.Title = _setout.Description;
  677. // _packet.Quantity = _design.Key.Quantity;
  678. // Client.Save(_packet,"Imported From V6");
  679. //
  680. // List<ManufacturingPacketStage> _packetstages = new();
  681. // foreach (var _templatestage in stages)
  682. // {
  683. // var _packetstage = new ManufacturingPacketStage
  684. // {
  685. // Time = _templatestage.Time,
  686. // SequenceType = _templatestage.SequenceType,
  687. // Sequence = _templatestage.Sequence
  688. // };
  689. // _packetstage.Parent.ID = _packet.ID;
  690. // _packetstage.ManufacturingSectionLink.ID = _templatestage.Section.ID;
  691. // _packetstage.ManufacturingSectionLink.Name = _templatestage.Section.Name;
  692. // _packetstages.Add(_packetstage);
  693. // }
  694. // if (_packetstages.Any())
  695. // Client.Save(_packetstages,"Imported from V6");
  696. // }
  697. // }
  698. // private void CreateStagedSetouts(V6Quote project, JobScope scope, Dictionary<V6Elevation, V6Drawings> designs, ManufacturingTemplate template, ManufacturingTemplateStage[] stages)
  699. // {
  700. // foreach (var _design in designs)
  701. // {
  702. // var _setout = new StagingSetout();
  703. // _setout.JobLink.ID = scope.Job.ID;
  704. // _setout.Number = _design.Key.Description;
  705. // Client.Save(_setout,"Imported From V6");
  706. //
  707. //
  708. // var _drawings = _client.DecodeDrawings(_design.Value.Drawings, new string[] { "FrameDrawing" });
  709. // List<Document> _documents = new();
  710. // foreach (var _drawing in _drawings)
  711. // {
  712. // var _document = new Document();
  713. // _document.FileName = System.IO.Path.ChangeExtension(_drawing.FileName, ".pdf");
  714. // _document.Data = ImageUtils.BitmapToPdf(_drawing.Data);
  715. // _documents.Add(_document);
  716. // }
  717. // if (_documents.Any())
  718. // Client.Save(_documents, "Imported From V6");
  719. //
  720. // List<StagingSetoutDocument> _setoutdocuments = new();
  721. // foreach (var _document in _documents)
  722. // {
  723. // var _setoutdocument = new StagingSetoutDocument();
  724. // _setoutdocument.EntityLink.CopyFrom(_setout);
  725. // _setoutdocument.DocumentLink.CopyFrom(_document);
  726. // _setoutdocument.Thumbnail = ImageUtils.GetPDFThumbnail(_document.Data, 256, 256);
  727. // _setoutdocuments.Add(_setoutdocument);
  728. // }
  729. // if (_setoutdocuments.Any())
  730. // Client.Save(_setoutdocuments, "Imported From V6");
  731. //
  732. // var _packet = new StagingManufacturingPacket();
  733. // _packet.StagingSetout.ID = _setout.ID;
  734. // _packet.Template.CopyFrom(template);
  735. // _packet.Title = _setout.Number;
  736. // _packet.Quantity = _design.Key.Quantity;
  737. // Client.Save(_packet,"Imported From V6");
  738. //
  739. // List<StagingManufacturingPacketStage> _packetstages = new();
  740. // foreach (var _templatestage in stages)
  741. // {
  742. // var _packetstage = new StagingManufacturingPacketStage
  743. // {
  744. // Time = _templatestage.Time,
  745. // SequenceType = _templatestage.SequenceType,
  746. // Sequence = _templatestage.Sequence
  747. // };
  748. // _packetstage.Packet.ID = _packet.ID;
  749. // _packetstage.Section.ID = _templatestage.Section.ID;
  750. // _packetstage.Section.Name = _templatestage.Section.Name;
  751. // _packetstages.Add(_packetstage);
  752. // }
  753. // if (_packetstages.Any())
  754. // Client.Save(_packetstages,"Imported from V6");
  755. //
  756. // }
  757. // }
  758. }