StocktakePage.xaml.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. using comal.timesheets.CustomControls;
  2. using Comal.Classes;
  3. using InABox.Clients;
  4. using InABox.Core;
  5. using Plugin.Media;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Linq.Expressions;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using Xamarin.CommunityToolkit.Extensions;
  15. using Xamarin.CommunityToolkit.UI.Views;
  16. using Xamarin.Essentials;
  17. using Xamarin.Forms;
  18. using Xamarin.Forms.Xaml;
  19. using XF.Material.Forms.UI.Dialogs;
  20. namespace comal.timesheets
  21. {
  22. [XamlCompilation(XamlCompilationOptions.Compile)]
  23. public partial class StocktakePage : ContentPage
  24. {
  25. #region Fields, Constructor and OnAppearing
  26. List<StockLocationShell> stockLocationShells = new List<StockLocationShell>();
  27. List<StockHoldingShell> stockHoldingShells = new List<StockHoldingShell>();
  28. string DeviceType = "";
  29. StockLocationShell openLocation = new StockLocationShell();
  30. bool bOpening = false;
  31. Color stockHoldingCheckedColor = Color.FromHex("#3eb489");
  32. List<StockMovement> movementsToUpdate = new List<StockMovement>();
  33. public StocktakePage(Guid locationid)
  34. {
  35. InitializeComponent();
  36. var idiom = DeviceInfo.Idiom;
  37. if (idiom.Equals(DeviceIdiom.Tablet))
  38. {
  39. DeviceType = "Tablet";
  40. }
  41. NavigationPage.SetHasBackButton(this, false);
  42. if (locationid != Guid.Empty)
  43. LoadLocation(locationid);
  44. }
  45. protected override void OnAppearing()
  46. {
  47. base.OnAppearing();
  48. bOpening = false;
  49. }
  50. #endregion
  51. #region Button Presses
  52. private async void ExitWithoutSaving(object sender, EventArgs e)
  53. {
  54. if (openLocation.ID != Guid.Empty)
  55. {
  56. string chosenOption = await DisplayActionSheet("Leave without saving?", "Cancel", null, "Yes", "No");
  57. switch (chosenOption)
  58. {
  59. case "Cancel":
  60. return;
  61. case "Yes":
  62. Navigation.PopAsync();
  63. break;
  64. case "No":
  65. return;
  66. default:
  67. return;
  68. }
  69. }
  70. else
  71. Navigation.PopAsync();
  72. }
  73. private void AddLocation_Clicked(object sender, EventArgs e)
  74. {
  75. if (bOpening)
  76. return;
  77. bOpening = true;
  78. StockLocationSelectionPage stockLocationSelectionPage = new StockLocationSelectionPage(true);
  79. stockLocationSelectionPage.OnMultiLocationSelected += (s) =>
  80. {
  81. foreach (StockLocationShell shell in s)
  82. {
  83. if (!stockLocationShells.Any(x => x.ID == shell.ID))
  84. {
  85. shell.Color = Color.Default;
  86. stockLocationShells.Add(shell);
  87. if (string.IsNullOrWhiteSpace(shell.NumberOfHoldings))
  88. FindHoldingNumber(shell);
  89. }
  90. }
  91. Device.BeginInvokeOnMainThread(() =>
  92. {
  93. leftListView.ItemsSource = null;
  94. leftListView.ItemsSource = stockLocationShells;
  95. });
  96. };
  97. Navigation.PushAsync(stockLocationSelectionPage);
  98. }
  99. private void AddItem_Clicked(object sender, EventArgs e)
  100. {
  101. if (openLocation.ID != Guid.Empty)
  102. {
  103. if (GlobalVariables.ProductsLoaded)
  104. {
  105. ProductList products = new ProductList(GlobalVariables.ProductShells, true);
  106. products.OnProductSelected += (() =>
  107. {
  108. StockHoldingShell shell = new StockHoldingShell();
  109. shell.Code = products.SelectedProduct.Code;
  110. shell.Name = products.SelectedProduct.Name;
  111. shell.ImageID = products.SelectedProduct.ImageID;
  112. shell.ProductID = products.SelectedProduct.ID;
  113. shell.DisplayJob = openLocation.JobNumber;
  114. if (!string.IsNullOrWhiteSpace(openLocation.JobNumber))
  115. {
  116. shell.JobNumber = openLocation.JobNumber.Substring(6);
  117. }
  118. shell.JobID = openLocation.JobID;
  119. shell.Units = 0;
  120. shell.DisplayUnits = "Units: 0";
  121. shell.DisplayFinish = "Finish: Select";
  122. shell.DimensionsUnitID = products.SelectedProduct.DimensionsUnitID;
  123. shell.DimensionsQuantity = products.SelectedProduct.DimensionsQuantity;
  124. shell.DimensionsLength = products.SelectedProduct.DimensionsLength;
  125. shell.DimensionsWidth = products.SelectedProduct.DimensionsWidth;
  126. shell.DimensionsHeight = products.SelectedProduct.DimensionsHeight;
  127. shell.DimensionsWeight = products.SelectedProduct.DimensionsWeight;
  128. shell.DimensionsValue = products.SelectedProduct.DimensionsValue;
  129. shell.DimensionsUnitSize = products.SelectedProduct.DimensionsUnitSize;
  130. shell.DimensionsHasHeight = products.SelectedProduct.DimensionsHasHeight;
  131. shell.DimensionsHasLength = products.SelectedProduct.DimensionsHasLength;
  132. shell.DimensionsHasWidth = products.SelectedProduct.DimensionsHasWidth;
  133. shell.DimensionsHasWeight = products.SelectedProduct.DimensionsHasWeight;
  134. shell.DimensionsHasQuantity = products.SelectedProduct.DimensionsHasQuantity;
  135. shell.DimensionsUnitFormula = products.SelectedProduct.DimensionsUnitFormula;
  136. shell.DimensionsUnitFormat = products.SelectedProduct.DimensionsUnitFormat;
  137. shell.DimensionsUnitCode = products.SelectedProduct.DimensionsUnitCode;
  138. shell.DimensionsUnitDescription = products.SelectedProduct.DimensionsUnitDescription;
  139. stockHoldingShells.Add(shell);
  140. rightListView.ItemsSource = null;
  141. rightListView.ItemsSource = stockHoldingShells;
  142. if (shell.ImageID != Guid.Empty)
  143. LoadImage(shell);
  144. });
  145. Navigation.PushAsync(products);
  146. }
  147. }
  148. else
  149. {
  150. string alert = "";
  151. if (stockLocationShells.Count == 0)
  152. {
  153. alert = "Add a location first";
  154. }
  155. else
  156. {
  157. alert = "Open a location first";
  158. }
  159. DisplayAlert("Alert", alert, "OK");
  160. }
  161. }
  162. #endregion
  163. #region Lists Tapped
  164. private async void LeftListView_Tapped(object sender, EventArgs e)// open/close a location
  165. {
  166. StockLocationShell stockLocationShell = leftListView.SelectedItem as StockLocationShell;
  167. if (openLocation.ID == stockLocationShell.ID) //close location and save movements
  168. {
  169. bool allComplete = true;
  170. bool allIncomplete = true;
  171. foreach (StockHoldingShell shell in stockHoldingShells)
  172. {
  173. if (shell.Color != stockHoldingCheckedColor)
  174. allComplete = false;
  175. else
  176. allIncomplete = false;
  177. }
  178. if (!allComplete && !allIncomplete)
  179. {
  180. DisplayAlert("Alert", "Not all holdings have been checked for this location / pack", "OK");
  181. return;
  182. }
  183. if (allIncomplete)
  184. {
  185. openLocation.ID = Guid.Empty;
  186. openLocation.Code = "";
  187. openLocation.Description = "";
  188. stockLocationShell.Color = Color.Default;
  189. stockLocationShell.OpenCloseLocation = "Open";
  190. int index = stockLocationShells.FindIndex(x => x.ID.Equals(stockLocationShell.ID));
  191. stockLocationShells.RemoveAt(index);
  192. stockLocationShells.Insert(index, stockLocationShell);
  193. leftListView.ItemsSource = null;
  194. leftListView.ItemsSource = stockLocationShells;
  195. rightListView.ItemsSource = null;
  196. stockHoldingShells.Clear();
  197. rightCountLbl.Text = "Items: " + stockHoldingShells.Count();
  198. movementsToUpdate.Clear();
  199. return;
  200. }
  201. StockTakeCompletionPage stockTakeCompletionPage = new StockTakeCompletionPage(movementsToUpdate);
  202. stockTakeCompletionPage.OnStockTakeCompleted += () =>
  203. {
  204. openLocation.ID = Guid.Empty;
  205. openLocation.Code = "";
  206. openLocation.Description = "";
  207. stockLocationShell.Color = stockHoldingCheckedColor;
  208. stockLocationShell.OpenCloseLocation = "Completed";
  209. int index = stockLocationShells.FindIndex(x => x.ID.Equals(stockLocationShell.ID));
  210. stockLocationShells.RemoveAt(index);
  211. stockLocationShells.Insert(index, stockLocationShell);
  212. leftListView.ItemsSource = null;
  213. leftListView.ItemsSource = stockLocationShells;
  214. rightListView.ItemsSource = null;
  215. stockHoldingShells.Clear();
  216. rightCountLbl.Text = "Items: " + stockHoldingShells.Count();
  217. movementsToUpdate.Clear();
  218. };
  219. Navigation.PushAsync(stockTakeCompletionPage);
  220. }
  221. else if (openLocation.ID == Guid.Empty) //open the location and load holdings
  222. {
  223. Filter<StockHolding> filter = new Filter<StockHolding>(x => x.Location.ID).IsEqualTo(stockLocationShell.ID);
  224. openLocation.ID = stockLocationShell.ID;
  225. openLocation.Code = stockLocationShell.Code;
  226. openLocation.Description = stockLocationShell.Description;
  227. stockLocationShell.Color = Color.Orange;
  228. stockLocationShell.OpenCloseLocation = "Close";
  229. LoadHoldings(filter);
  230. int index = stockLocationShells.FindIndex(x => x.ID.Equals(stockLocationShell.ID));
  231. stockLocationShells.RemoveAt(index);
  232. stockLocationShells.Insert(index, stockLocationShell);
  233. leftListView.ItemsSource = null;
  234. leftListView.ItemsSource = stockLocationShells;
  235. }
  236. else if (openLocation.ID != Guid.Empty)
  237. {
  238. DisplayAlert("Alert", "Currently Open Location must be closed first", "OK");
  239. }
  240. }
  241. private void RightListView_Tapped(object sender, EventArgs e) //open popup to confirm, on closing turns green
  242. {
  243. if (bOpening)
  244. return;
  245. bOpening = true;
  246. StockHoldingShell shell = rightListView.SelectedItem as StockHoldingShell;
  247. StockHoldingShell originalShell = DuplicateShell(shell);
  248. ProductStyle style = new ProductStyle() { ID = shell.StyleID, Code = shell.StyleCode, Description = shell.Finish };
  249. Job job = new Job() { ID = shell.JobID, JobNumber = shell.JobNumber };
  250. RecTransferPopup popup = new RecTransferPopup(shell, style, job, job, true);
  251. StockMovement additionalmovement = new StockMovement();
  252. popup.OnRecTransferItemAccepted += () =>
  253. {
  254. StockMovement movement = new StockMovement() { };
  255. movement.Dimensions.Unit.ID = shell.DimensionsUnitID;
  256. movement.Dimensions.Quantity = shell.DimensionsQuantity;
  257. movement.Dimensions.Length = shell.DimensionsLength;
  258. movement.Dimensions.Width = shell.DimensionsWidth;
  259. movement.Dimensions.Height = shell.DimensionsHeight;
  260. movement.Dimensions.Weight = shell.DimensionsWeight;
  261. movement.Dimensions.Unit.HasHeight = shell.DimensionsHasHeight;
  262. movement.Dimensions.Unit.HasLength = shell.DimensionsHasLength;
  263. movement.Dimensions.Unit.HasWidth = shell.DimensionsHasWidth;
  264. movement.Dimensions.Unit.HasWeight = shell.DimensionsHasWeight;
  265. movement.Dimensions.Unit.HasQuantity = shell.DimensionsHasQuantity;
  266. movement.Dimensions.Unit.Code = shell.DimensionsUnitCode;
  267. movement.Dimensions.Unit.Description = shell.DimensionsUnitDescription;
  268. movement.Dimensions.Value = shell.DimensionsValue;
  269. movement.Dimensions.Unit.Formula = shell.DimensionsUnitFormula;
  270. movement.Dimensions.Unit.Format = shell.DimensionsUnitFormat;
  271. movement.Dimensions.UnitSize = shell.DimensionsUnitSize;
  272. movement.Product.ID = shell.ProductID;
  273. movement.Product.Code = shell.Code;
  274. movement.Product.Name = shell.Name;
  275. movement.Employee.ID = GlobalVariables.EmpID;
  276. movement.Employee.Name = GlobalVariables.EmpName;
  277. movement.Location.ID = openLocation.ID;
  278. movement.Location.Description = openLocation.Description;
  279. movement.Location.Code = openLocation.Code;
  280. movement.Job.ID = shell.JobID;
  281. movement.Job.JobNumber = shell.JobNumber;
  282. movement.Style.ID = shell.StyleID;
  283. movement.Style.Code = shell.StyleCode;
  284. movement.Style.Description = shell.Finish;
  285. if (popup.Shell.Units < originalShell.Units)
  286. {
  287. movement.Issued = originalShell.Units - popup.Shell.Units;
  288. movement.Notes = "Updated incorrect Qty during stocktake. Less Qty than expected.";
  289. }
  290. else if (popup.Shell.Units > originalShell.Units)
  291. {
  292. movement.Received = popup.Shell.Units - originalShell.Units;
  293. movement.Notes = "Updated incorrect Qty during stocktake. More Qty than expected.";
  294. }
  295. else if (popup.Shell.Units == originalShell.Units)
  296. {
  297. movement.Received = 0;
  298. movement.Issued = 0;
  299. movement.Notes = "Confirmed correct Qty during stocktake.";
  300. }
  301. //if style is changed, create a movement that issues everything from the original style
  302. //in addition to the first movement created being changed to a receive of the entered qty in the new style
  303. //no need to find the difference in Qty from the original. First movement qty issued should be 0
  304. if (popup.Shell.StyleID != originalShell.StyleID)
  305. {
  306. additionalmovement.Dimensions.Unit.ID = shell.DimensionsUnitID;
  307. additionalmovement.Dimensions.Quantity = shell.DimensionsQuantity;
  308. additionalmovement.Dimensions.Length = shell.DimensionsLength;
  309. additionalmovement.Dimensions.Width = shell.DimensionsWidth;
  310. additionalmovement.Dimensions.Height = shell.DimensionsHeight;
  311. additionalmovement.Dimensions.Weight = shell.DimensionsWeight;
  312. additionalmovement.Dimensions.Unit.HasHeight = shell.DimensionsHasHeight;
  313. additionalmovement.Dimensions.Unit.HasLength = shell.DimensionsHasLength;
  314. additionalmovement.Dimensions.Unit.HasWidth = shell.DimensionsHasWidth;
  315. additionalmovement.Dimensions.Unit.HasWeight = shell.DimensionsHasWeight;
  316. additionalmovement.Dimensions.Unit.HasQuantity = shell.DimensionsHasQuantity;
  317. additionalmovement.Dimensions.Unit.Code = shell.DimensionsUnitCode;
  318. additionalmovement.Dimensions.Unit.Description = shell.DimensionsUnitDescription;
  319. additionalmovement.Dimensions.Value = shell.DimensionsValue;
  320. additionalmovement.Dimensions.Unit.Formula = shell.DimensionsUnitFormula;
  321. additionalmovement.Dimensions.Unit.Format = shell.DimensionsUnitFormat;
  322. additionalmovement.Dimensions.UnitSize = shell.DimensionsUnitSize;
  323. additionalmovement.Product.ID = shell.ProductID;
  324. additionalmovement.Product.Code = shell.Code;
  325. additionalmovement.Product.Name = shell.Name;
  326. additionalmovement.Employee.ID = GlobalVariables.EmpID;
  327. additionalmovement.Employee.Name = GlobalVariables.EmpName;
  328. additionalmovement.Location.ID = openLocation.ID;
  329. additionalmovement.Location.Description = openLocation.Description;
  330. additionalmovement.Location.Code = openLocation.Code;
  331. additionalmovement.Job.ID = shell.JobID;
  332. additionalmovement.Job.JobNumber = shell.JobNumber;
  333. additionalmovement.Style.ID = originalShell.StyleID;
  334. additionalmovement.Style.Code = originalShell.StyleCode;
  335. additionalmovement.Style.Description = originalShell.Finish;
  336. additionalmovement.Notes = movement.Notes + " Also changed finish during stocktake";
  337. additionalmovement.Issued = originalShell.Units;
  338. movementsToUpdate.Add(additionalmovement);
  339. movement.Issued = 0;
  340. movement.Received = popup.Shell.Units;
  341. movement.Notes = movement.Notes + " Also changed finish during stocktake";
  342. }
  343. movementsToUpdate.Add(movement);
  344. shell.Color = stockHoldingCheckedColor;
  345. int index = stockHoldingShells.FindIndex(x => x.ID.Equals(shell.ID));
  346. stockHoldingShells.RemoveAt(index);
  347. stockHoldingShells.Insert(index, shell);
  348. Device.BeginInvokeOnMainThread(() =>
  349. {
  350. rightListView.ItemsSource = null;
  351. rightListView.ItemsSource = stockHoldingShells;
  352. });
  353. };
  354. Navigation.PushAsync(popup);
  355. }
  356. #endregion
  357. #region Utilities
  358. private async void FindHoldingNumber(StockLocationShell shell)
  359. {
  360. //TODO replace code that showed number of holdings
  361. //Task.Run(() =>
  362. //{
  363. // CoreTable table = new Client<StockLocation>().Query(new Filter<StockLocation>(x => x.ID).IsEqualTo(shell.ID),
  364. // new Columns<StockLocation>(x => x.Holdings));
  365. // if (table.Rows.Any())
  366. // {
  367. // List<object> list = table.Rows.First().Values;
  368. // shell.NumberOfHoldings = "Holdings: " + list[0].ToString();
  369. // int index = stockLocationShells.FindIndex(x => x.ID.Equals(shell.ID));
  370. // stockLocationShells.RemoveAt(index);
  371. // stockLocationShells.Insert(index, shell);
  372. // Device.BeginInvokeOnMainThread(() =>
  373. // {
  374. // leftListView.ItemsSource = null;
  375. // leftListView.ItemsSource = stockLocationShells;
  376. // });
  377. // }
  378. //});
  379. }
  380. private async void LoadLocation(Guid locationid)
  381. {
  382. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  383. {
  384. CoreTable table = new Client<StockLocation>().Query(new Filter<StockLocation>(x => x.ID).IsEqualTo(locationid),
  385. new Columns<StockLocation>(x => x.Description, x => x.Code, x => x.Warehouse.Description,
  386. x => x.Area.Description, x => x.Job.JobNumber)
  387. );
  388. if (table.Rows.Any())
  389. {
  390. StockLocation location = table.Rows.First().ToObject<StockLocation>();
  391. StockLocationShell shell = new StockLocationShell()
  392. {
  393. ID = locationid,
  394. Description = location.Description,
  395. Warehouse = "Warehouse: " + location.Warehouse.Description,
  396. Area = "Area: " + location.Area.Description,
  397. JobNumber = "Job: " + location.Job.JobNumber,
  398. Code = location.Code,
  399. NumberOfHoldings = "Holdings: LOADING...",
  400. JobID = location.Job.ID,
  401. JobName = location.Job.Name
  402. };
  403. stockLocationShells.Add(shell);
  404. Device.BeginInvokeOnMainThread(() =>
  405. {
  406. leftListView.ItemsSource = null;
  407. leftListView.ItemsSource = stockLocationShells;
  408. });
  409. FindHoldingNumber(shell);
  410. }
  411. }
  412. }
  413. private StockHoldingShell DuplicateShell(StockHoldingShell shell)
  414. {
  415. StockHoldingShell NewShell = new StockHoldingShell()
  416. {
  417. ID = shell.ID,
  418. Code = shell.Code,
  419. Name = shell.Name,
  420. DimensionsUnitID = shell.DimensionsUnitID,
  421. DimensionsQuantity = shell.DimensionsQuantity,
  422. DimensionsLength = shell.DimensionsLength,
  423. DimensionsWidth = shell.DimensionsWidth,
  424. DimensionsHeight = shell.DimensionsHeight,
  425. DimensionsWeight = shell.DimensionsWeight,
  426. DimensionsValue = shell.DimensionsValue,
  427. DimensionsHasHeight = shell.DimensionsHasHeight,
  428. DimensionsHasLength = shell.DimensionsHasLength,
  429. DimensionsHasQuantity = shell.DimensionsHasQuantity,
  430. DimensionsHasWidth = shell.DimensionsHasWidth,
  431. DimensionsHasWeight = shell.DimensionsHasWeight,
  432. DimensionsUnitCode = shell.DimensionsUnitCode,
  433. DimensionsUnitDescription = shell.DimensionsUnitDescription,
  434. DimensionsUnitFormat = shell.DimensionsUnitFormat,
  435. DimensionsUnitFormula = shell.DimensionsUnitFormula,
  436. DimensionsUnitSize = shell.DimensionsUnitSize,
  437. Finish = shell.Finish,
  438. Units = shell.Units,
  439. DisplayUnits = shell.DisplayUnits,
  440. JobID = shell.JobID,
  441. JobName = shell.JobName,
  442. JobNumber = shell.JobNumber,
  443. DisplayJob = shell.DisplayJob,
  444. DisplayFinish = shell.DisplayFinish,
  445. StyleID = shell.StyleID,
  446. StyleCode = shell.StyleCode,
  447. ProductID = shell.ProductID,
  448. DisplaySize = shell.DisplaySize,
  449. LastRowHeight = shell.LastRowHeight,
  450. ImageID = shell.ImageID,
  451. ImageSource = shell.ImageSource,
  452. ImageVisible = shell.ImageVisible,
  453. Color = shell.Color
  454. };
  455. return NewShell;
  456. }
  457. private void LoadImage(StockHoldingShell shell)
  458. {
  459. CoreTable table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(shell.ImageID));
  460. if (table.Rows.Any())
  461. {
  462. CoreRow docrow = table.Rows.FirstOrDefault();
  463. if (docrow != null)
  464. {
  465. byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
  466. ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
  467. if (src != null)
  468. {
  469. shell.ImageSource = src;
  470. shell.ImageVisible = true;
  471. if (DeviceType == "Tablet")
  472. {
  473. shell.LastRowHeight = 300;
  474. }
  475. else
  476. {
  477. shell.LastRowHeight = 150;
  478. }
  479. Device.BeginInvokeOnMainThread(() =>
  480. {
  481. rightListView.ItemsSource = null;
  482. rightListView.ItemsSource = stockHoldingShells;
  483. });
  484. }
  485. }
  486. }
  487. }
  488. private void LoadImages()
  489. {
  490. Task.Run(() =>
  491. {
  492. foreach (StockHoldingShell shell in stockHoldingShells)
  493. {
  494. if (shell.ImageID != Guid.Empty)
  495. {
  496. LoadImage(shell);
  497. }
  498. }
  499. });
  500. }
  501. private async void LoadHoldings(Filter<StockHolding> _filter)
  502. {
  503. await Task.Run(() =>
  504. {
  505. CoreTable table = new Client<StockHolding>().Query
  506. (
  507. _filter,
  508. new Columns<StockHolding>
  509. (
  510. x => x.ID,
  511. x => x.Product.Code,
  512. x => x.Product.Name,
  513. x => x.Style.Description,
  514. x => x.Units,
  515. x => x.Location.ID,
  516. x => x.Job.ID,
  517. x => x.Job.Name,
  518. x => x.Job.JobNumber,
  519. x => x.Style.ID,
  520. x => x.Style.Code,
  521. x => x.Product.ID,
  522. x => x.Product.Image.ID,
  523. x => x.Dimensions.UnitSize,
  524. x => x.Dimensions.Unit.ID,
  525. x => x.Dimensions.Quantity,
  526. x => x.Dimensions.Length,
  527. x => x.Dimensions.Width,
  528. x => x.Dimensions.Height,
  529. x => x.Dimensions.Weight,
  530. x => x.Dimensions.Value,
  531. x => x.Dimensions.Unit.HasQuantity,
  532. x => x.Dimensions.Unit.HasLength,
  533. x => x.Dimensions.Unit.HasWeight,
  534. x => x.Dimensions.Unit.HasWidth,
  535. x => x.Dimensions.Unit.HasHeight,
  536. x => x.Dimensions.Unit.Format,
  537. x => x.Dimensions.Unit.Formula
  538. ),
  539. null
  540. );
  541. if (table.Rows.Any())
  542. {
  543. foreach (CoreRow row in table.Rows)
  544. {
  545. StockHoldingShell shell = new StockHoldingShell();
  546. shell.ID = row.Get<StockHolding, Guid>(x => x.Location.ID).ToString()
  547. + row.Get<StockHolding, Guid>(x => x.Product.ID).ToString()
  548. + row.Get<StockHolding, Guid>(x => x.Job.ID).ToString()
  549. + row.Get<StockHolding, Guid>(x => x.Style.ID).ToString()
  550. + row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
  551. shell.Code = row.Get<StockHolding, string>(x => x.Product.Code);
  552. shell.Name = row.Get<StockHolding, string>(x => x.Product.Name);
  553. shell.Finish = row.Get<StockHolding, string>(x => x.Style.Description);
  554. shell.DisplayFinish = "Finish: " + shell.Finish;
  555. shell.Units = row.Get<StockHolding, double>(x => x.Units);
  556. shell.DimensionsUnitSize = row.Get<StockHolding, string>(x => x.Dimensions.UnitSize);
  557. shell.DisplaySize = "UOM: " + shell.DimensionsUnitSize;
  558. shell.DisplayUnits = "Units: " + shell.Units;
  559. shell.JobID = row.Get<StockHolding, Guid>(x => x.Job.ID);
  560. shell.JobName = row.Get<StockHolding, string>(x => x.Job.Name);
  561. shell.JobNumber = row.Get<StockHolding, string>(x => x.Job.JobNumber);
  562. shell.DisplayJob = "Job: " + shell.JobNumber;
  563. shell.StyleID = row.Get<StockHolding, Guid>(x => x.Style.ID);
  564. shell.StyleCode = row.Get<StockHolding, string>(x => x.Style.Code);
  565. shell.ProductID = row.Get<StockHolding, Guid>(x => x.Product.ID);
  566. shell.ImageID = row.Get<StockHolding, Guid>(x => x.Product.Image.ID);
  567. shell.DimensionsUnitID = row.Get<StockHolding, Guid>(x => x.Dimensions.Unit.ID);
  568. shell.DimensionsQuantity = row.Get<StockHolding, double>(x => x.Dimensions.Quantity);
  569. shell.DimensionsLength = row.Get<StockHolding, double>(x => x.Dimensions.Length);
  570. shell.DimensionsWidth = row.Get<StockHolding, double>(x => x.Dimensions.Width);
  571. shell.DimensionsHeight = row.Get<StockHolding, double>(x => x.Dimensions.Height);
  572. shell.DimensionsWeight = row.Get<StockHolding, double>(x => x.Dimensions.Weight);
  573. shell.DimensionsValue = row.Get<StockHolding, double>(x => x.Dimensions.Value);
  574. shell.DimensionsHasHeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasHeight);
  575. shell.DimensionsHasWeight = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWeight);
  576. shell.DimensionsHasLength = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasLength);
  577. shell.DimensionsHasQuantity = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasQuantity);
  578. shell.DimensionsHasWidth = row.Get<StockHolding, bool>(x => x.Dimensions.Unit.HasWidth);
  579. shell.DimensionsUnitFormat = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Format);
  580. shell.DimensionsUnitFormula = row.Get<StockHolding, string>(x => x.Dimensions.Unit.Formula);
  581. if (!shell.Code.Contains("FREIGHT") && shell.Units != 0)
  582. {
  583. stockHoldingShells.Add(shell);
  584. }
  585. }
  586. LoadImages();
  587. Device.BeginInvokeOnMainThread(() =>
  588. {
  589. rightCountLbl.Text = "Items: " + stockHoldingShells.Count();
  590. rightListView.ItemsSource = null;
  591. rightListView.ItemsSource = stockHoldingShells;
  592. });
  593. }
  594. });
  595. }
  596. #endregion
  597. }
  598. public class StockLocationShell
  599. {
  600. public Guid ID { get; set; }
  601. public string Description { get; set; }
  602. public string Code { get; set; }
  603. public string Warehouse { get; set; }
  604. public string Area { get; set; }
  605. public string NumberOfHoldings { get; set; }
  606. public string OpenCloseLocation { get; set; }
  607. public Color Color { get; set; }
  608. public string JobNumber { get; set; }
  609. public Guid JobID { get; set; }
  610. public String JobName { get; set; }
  611. public List<POItemShell> PoItems { get; set; }
  612. public string NumberOfReceivedItems { get; set; }
  613. public StockLocationShell()
  614. {
  615. ID = Guid.Empty;
  616. Description = "";
  617. Warehouse = "";
  618. Area = "";
  619. NumberOfHoldings = "";
  620. OpenCloseLocation = "Open";
  621. Color = Color.Default;
  622. JobNumber = "";
  623. Code = "";
  624. PoItems = new List<POItemShell>();
  625. NumberOfReceivedItems = "";
  626. JobID = Guid.Empty;
  627. JobName = "";
  628. }
  629. }
  630. }