V6ProjectSelection.xaml.cs 34 KB

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