Receivals.xaml.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using InABox.Core;
  7. using InABox.Clients;
  8. using Comal.Classes;
  9. using Xamarin.Forms;
  10. using Xamarin.Forms.Xaml;
  11. using XF.Material.Forms.UI.Dialogs;
  12. using Xamarin.Essentials;
  13. using System.IO;
  14. using InABox.Mobile;
  15. using LogType = InABox.Core.LogType;
  16. using PRSSecurity = InABox.Core.Security;
  17. namespace PRS.Mobile
  18. {
  19. [XamlCompilation(XamlCompilationOptions.Compile)]
  20. public partial class Receivals
  21. {
  22. #region Fields & Constructor, OnAppearing
  23. Guid POID = Guid.Empty;
  24. List<POItemShell> poItemShells = new List<POItemShell>();
  25. List<StockLocationShell> stockLocationShells = new List<StockLocationShell>();
  26. bool bOpening = false;
  27. List<Guid> holdingsToLookup = new List<Guid>();
  28. string deviceType = "";
  29. Guid supplierID = Guid.Empty;
  30. string PONumber = "";
  31. Guid consignmentID = Guid.Empty;
  32. string consignmentNumber = "";
  33. List<POItemShell> listReceived = new List<POItemShell>();
  34. public Receivals(Guid _poID, string _PONumber, Guid _supplierID)
  35. {
  36. InitializeComponent();
  37. NavigationPage.SetHasBackButton(this, false);
  38. POID = _poID;
  39. PONumber = _PONumber;
  40. poNumberLbl.Text = "PO: " + _PONumber;
  41. var idiom = DeviceInfo.Idiom;
  42. if (idiom.Equals(DeviceIdiom.Tablet))
  43. {
  44. deviceType = "Tablet";
  45. }
  46. LoadPOItems();
  47. supplierID = _supplierID;
  48. AddIncomingStores();
  49. }
  50. protected override void OnAppearing()
  51. {
  52. base.OnAppearing();
  53. bOpening = false;
  54. }
  55. #endregion
  56. #region User Interaction
  57. private async void Exit_Clicked(object sender, EventArgs e)
  58. {
  59. if (listReceived.Count > 0)
  60. {
  61. DisplayAlert("Alert", "Consignment has items received and must be saved with photos before exiting", "OK");
  62. }
  63. else
  64. Navigation.PopAsync();
  65. }
  66. private async void Save_Clicked(object sender, EventArgs e)
  67. {
  68. ConsignmentCompletionPage completionPage = new ConsignmentCompletionPage(listReceived, consignmentID, consignmentNumber);
  69. completionPage.OnConsignmentSaved += () =>
  70. {
  71. Navigation.PopAsync();
  72. };
  73. Navigation.PushAsync(completionPage);
  74. }
  75. private void ConsignmentList_Tapped(object sender, EventArgs e)
  76. {
  77. if (bOpening)
  78. return;
  79. if (!PRSSecurity.IsAllowed<CanReceiveConsignments>())
  80. {
  81. DisplayAlert("Not allowed", "Please check security setting: Receive Consignments", "OK");
  82. return;
  83. }
  84. bOpening = true;
  85. POItemShell poItemShell = poItemListView.SelectedItem as POItemShell;
  86. if (poItemShell.Nonstock == true)
  87. {
  88. ChooseQtyNonStockItem(poItemShell);
  89. }
  90. else
  91. {
  92. ChooseQtyStockItem(poItemShell);
  93. }
  94. }
  95. private async void ChooseQtyStockItem(POItemShell poItemShell)
  96. {
  97. ConsignmentDetailsPopup popup = new ConsignmentDetailsPopup(poItemShell, stockLocationShells);
  98. popup.OnConsignmentPopupAccepted += async () =>
  99. {
  100. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  101. {
  102. poItemShell.StockLocationID = popup._POItemShell.StockLocationID;
  103. poItemShell.StockLocationCode = popup._POItemShell.StockLocationCode;
  104. poItemShell.StockLocationDescription = popup._POItemShell.StockLocationDescription;
  105. poItemShell.ReceivedQty = popup._POItemShell.ReceivedQty;
  106. StockLocationShell location = stockLocationShells.Find(x => x.ID.Equals(poItemShell.StockLocationID));
  107. if (location == null)
  108. {
  109. var newLocation = App.Data.StockLocations.FirstOrDefault(x => x.ID == poItemShell.StockLocationID);
  110. if (newLocation != null)
  111. stockLocationShells.Add(newLocation);
  112. }
  113. ChooseSavePathwayAsync(poItemShell);
  114. }
  115. };
  116. Navigation.PushAsync(popup);
  117. bOpening = false;
  118. }
  119. private async void ChooseQtyNonStockItem(POItemShell poItemShell)
  120. {
  121. Device.BeginInvokeOnMainThread(async () =>
  122. {
  123. //if nonstock item - only rec qty, otherwise open popup page
  124. string chosenOption = await DisplayPromptAsync("Enter Received Quantity", "", initialValue: poItemShell.ExpectedQty.ToString(), keyboard: Keyboard.Numeric);
  125. if (!string.IsNullOrEmpty(chosenOption) || chosenOption != "Cancel")
  126. {
  127. try
  128. {
  129. double qty = double.Parse(chosenOption);
  130. poItemShell.ReceivedQty = qty;
  131. }
  132. catch
  133. {
  134. DisplayAlert("Error", "Invalid Qty", "OK");
  135. bOpening = false;
  136. return;
  137. }
  138. bOpening = false;
  139. ChooseSavePathwayAsync(poItemShell);
  140. }
  141. else
  142. bOpening = false;
  143. });
  144. }
  145. private void SearchEnt_Changed(object sender, EventArgs e)
  146. {
  147. if (string.IsNullOrWhiteSpace(searchEnt.Text))
  148. {
  149. poItemListView.ItemsSource = poItemShells;
  150. }
  151. else
  152. {
  153. poItemListView.ItemsSource = poItemShells.Where(x =>
  154. x.Description.Contains(searchEnt.Text) || x.Description.Contains(UpperCaseFirst(searchEnt.Text)) || x.Description.Contains(LowerCaseFirst(searchEnt.Text))
  155. || x.Description.Contains(searchEnt.Text.ToUpper()) || x.Description.Contains(searchEnt.Text.ToLower()) ||
  156. x.ExpectedQty.ToString().Contains(searchEnt.Text)
  157. );
  158. }
  159. }
  160. static String UpperCaseFirst(string s)
  161. {
  162. char[] a = s.ToCharArray();
  163. a[0] = char.ToUpper(a[0]);
  164. return new string(a);
  165. }
  166. static String LowerCaseFirst(string s)
  167. {
  168. char[] a = s.ToCharArray();
  169. a[0] = char.ToLower(a[0]);
  170. return new string(a);
  171. }
  172. #endregion
  173. #region Saving
  174. private async Task ChooseSavePathwayAsync(POItemShell poItemShell)
  175. {
  176. if (consignmentID == Guid.Empty)
  177. CreateNewConsignment();
  178. if (poItemShell.ReceivedQty == poItemShell.ExpectedQty)
  179. {
  180. SaveCorrectQuantityPOItem(poItemShell);
  181. }
  182. else if (poItemShell.ReceivedQty < poItemShell.ExpectedQty && poItemShell.ReceivedQty != 0)
  183. {
  184. SaveLesserQuantityPOItem(poItemShell);
  185. }
  186. else if (poItemShell.ReceivedQty > poItemShell.ExpectedQty)
  187. {
  188. SaveExtraQuantityPOItem(poItemShell);
  189. }
  190. }
  191. private async void SaveCorrectQuantityPOItem(POItemShell poItemShell)
  192. {
  193. await Task.Run(() =>
  194. {
  195. poItemShell.ReceivedQty = poItemShell.ExpectedQty;
  196. poItemShell.ReceivedDate = DateTime.Now;
  197. poItemShell.ConsignmentID = consignmentID;
  198. poItemShell.ConsignmentNumber = consignmentNumber;
  199. SavePOItem(poItemShell);
  200. int index = poItemShells.FindIndex(x => x.ID.Equals(poItemShell.ID));
  201. poItemShells.RemoveAt(index);
  202. RefreshLists(poItemShell);
  203. });
  204. }
  205. private void SavePOItem(POItemShell poItemShell)
  206. {
  207. Task.Run(() =>
  208. {
  209. listReceived.Add(poItemShell);
  210. PurchaseOrderItem purchaseOrderItem = new PurchaseOrderItem();
  211. purchaseOrderItem.Description = poItemShell.Description;
  212. purchaseOrderItem.ID = poItemShell.ID;
  213. purchaseOrderItem.Qty = poItemShell.ReceivedQty;
  214. purchaseOrderItem.ReceivedDate = DateTime.Now;
  215. purchaseOrderItem.Consignment.ID = consignmentID;
  216. purchaseOrderItem.PurchaseOrderLink.PONumber = poItemShell.PONumber;
  217. purchaseOrderItem.PurchaseOrderLink.ID = poItemShell.POID;
  218. purchaseOrderItem = CopyDetails(purchaseOrderItem, poItemShell);
  219. DoSavePOItem(purchaseOrderItem);
  220. });
  221. }
  222. private void DoSavePOItem(PurchaseOrderItem purchaseOrderItem)
  223. {
  224. try
  225. {
  226. new Client<PurchaseOrderItem>().Save(purchaseOrderItem, "Updated from mobile device");
  227. }
  228. catch (Exception ex)
  229. {
  230. InABox.Mobile.MobileLogging.Log(ex);
  231. DoSavePOItem(purchaseOrderItem);
  232. }
  233. }
  234. private void RefreshLists(POItemShell poItemShell)
  235. {
  236. Device.BeginInvokeOnMainThread(() =>
  237. {
  238. poItemListView.ItemsSource = null;
  239. poItemListView.ItemsSource = poItemShells;
  240. poItemCountLbl.Text = "Items Unreceived: " + poItemShells.Count;
  241. if (poItemShell.StockLocationID != Guid.Empty)
  242. {
  243. StockLocationShell location = stockLocationShells.Find(x => x.ID.Equals(poItemShell.StockLocationID));
  244. //location.PoItems.Add(poItemShell);
  245. //location.NumberOfReceivedItems = "Received items: " + location.PoItems.Count;
  246. locationsStackLayout.Children.Clear();
  247. foreach (StockLocationShell shell in stockLocationShells)
  248. {
  249. StockLocationViewCell viewcell = new StockLocationViewCell(shell);
  250. locationsStackLayout.Children.Add(viewcell);
  251. }
  252. }
  253. });
  254. }
  255. private async void SaveLesserQuantityPOItem(POItemShell poItemShell)
  256. {
  257. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  258. {
  259. try
  260. {
  261. string originalDescription = poItemShell.Description;
  262. int index = poItemShells.FindIndex(x => x.ID.Equals(poItemShell.ID));
  263. poItemShells.RemoveAt(index);
  264. //placeholder added while all the loading / saving happens - to be replaced later when new purchaseorderitem ID is returned
  265. POItemShell placeHolderShell = poItemShell.DuplicateNewShell(poItemShell);
  266. placeHolderShell.ExpectedQty = poItemShell.ExpectedQty - poItemShell.ReceivedQty;
  267. poItemShells.Insert(index, placeHolderShell);
  268. SavePOItem(poItemShell); //original POItem is saved
  269. CoreTable table = DoQueryPOItem(poItemShell);
  270. while (table == null)
  271. table = DoQueryPOItem(poItemShell);
  272. PurchaseOrderItem purchaseOrderItem = table.Rows.FirstOrDefault()?.ToObject<PurchaseOrderItem>();
  273. if (purchaseOrderItem == null)
  274. return;
  275. purchaseOrderItem.ID = Guid.Empty;
  276. purchaseOrderItem.Created = DateTime.Now;
  277. purchaseOrderItem.LastUpdate = DateTime.Now;
  278. purchaseOrderItem.OriginalValues.Remove("ID", out object obj);
  279. purchaseOrderItem.ReceivedDate = DateTime.MinValue;
  280. purchaseOrderItem.Qty = poItemShell.ExpectedQty - poItemShell.ReceivedQty;
  281. purchaseOrderItem.Description = originalDescription;
  282. purchaseOrderItem.Consignment.ID = Guid.Empty;
  283. purchaseOrderItem = CopyDetails(purchaseOrderItem, poItemShell);
  284. purchaseOrderItem = DoSavePurchaseOrderItem(purchaseOrderItem);
  285. //new purchase order is split from original with different quantity and no consignment linked, saved to database
  286. POItemShell newShell = poItemShell.DuplicateNewShell(poItemShell);
  287. newShell.ID = purchaseOrderItem.ID;
  288. newShell.Description = purchaseOrderItem.Description;
  289. newShell.ExpectedQty = purchaseOrderItem.Qty;
  290. newShell.ConsignmentID = Guid.Empty;
  291. newShell.ConsignmentNumber = "";
  292. //placeholder is replaced by new shell with correct ID
  293. poItemShells.RemoveAt(index);
  294. poItemShells.Insert(index, newShell);
  295. RefreshLists(poItemShell);
  296. }
  297. catch { }
  298. }
  299. }
  300. private PurchaseOrderItem DoSavePurchaseOrderItem(PurchaseOrderItem purchaseOrderItem)
  301. {
  302. try
  303. {
  304. new Client<PurchaseOrderItem>().Save(purchaseOrderItem, "Update from mobile device");
  305. return purchaseOrderItem;
  306. }
  307. catch (Exception ex)
  308. {
  309. InABox.Mobile.MobileLogging.Log(ex);
  310. return DoSavePurchaseOrderItem(purchaseOrderItem);
  311. }
  312. }
  313. private CoreTable DoQueryPOItem(POItemShell poItemShell)
  314. {
  315. try
  316. {
  317. return new Client<PurchaseOrderItem>().Query(new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(poItemShell.ID),
  318. columns);
  319. }
  320. catch (Exception ex)
  321. {
  322. InABox.Mobile.MobileLogging.Log(ex);
  323. return null;
  324. }
  325. }
  326. private async void SaveExtraQuantityPOItem(POItemShell poItemShell)
  327. {
  328. await Task.Run(() =>
  329. {
  330. try
  331. {
  332. string originalDescription = poItemShell.Description;
  333. double originalExpectedQty = poItemShell.ExpectedQty;
  334. double originalReceivedQty = poItemShell.ReceivedQty;
  335. double extraSupplied = originalReceivedQty - originalExpectedQty;
  336. int index = poItemShells.FindIndex(x => x.ID.Equals(poItemShell.ID));
  337. poItemShells.RemoveAt(index);
  338. poItemShell.ReceivedDate = DateTime.Now;
  339. poItemShell.ConsignmentID = consignmentID;
  340. poItemShell.ConsignmentNumber = consignmentNumber;
  341. poItemShell.ReceivedQty = poItemShell.ExpectedQty;
  342. SavePOItem(poItemShell);
  343. RefreshLists(poItemShell);
  344. listReceived.Add(poItemShell);
  345. //for responsive view only
  346. POItemShell newShell = poItemShell.DuplicateNewShell(poItemShell);
  347. newShell.ReceivedQty = extraSupplied;
  348. newShell.ExpectedQty = extraSupplied;
  349. RefreshLists(newShell);
  350. listReceived.Add(newShell);
  351. CoreTable table = QuerySaveExtraQuantityPOItem(poItemShell);
  352. while (table == null)
  353. table = QuerySaveExtraQuantityPOItem(poItemShell);
  354. PurchaseOrderItem newPurchaseOrderItem = table.Rows.FirstOrDefault().ToObject<PurchaseOrderItem>();
  355. if (newPurchaseOrderItem == null)
  356. return;
  357. newPurchaseOrderItem.ReceivedDate = DateTime.Now;
  358. newPurchaseOrderItem.ID = Guid.Empty;
  359. newPurchaseOrderItem.Created = DateTime.Now;
  360. newPurchaseOrderItem.LastUpdate = DateTime.Now;
  361. newPurchaseOrderItem.OriginalValues.Remove("ID", out object obj);
  362. newPurchaseOrderItem.Qty = extraSupplied;
  363. newPurchaseOrderItem.Description = newShell.Description;
  364. newPurchaseOrderItem.Consignment.ID = consignmentID;
  365. newPurchaseOrderItem = CopyDetails(newPurchaseOrderItem, poItemShell);
  366. SavePOItem(newPurchaseOrderItem);
  367. //new purchase order is split from original with different quantity, and consignment linked, saved to database
  368. }
  369. catch
  370. { }
  371. });
  372. }
  373. private void SavePOItem(PurchaseOrderItem newPurchaseOrderItem)
  374. {
  375. try
  376. {
  377. new Client<PurchaseOrderItem>().Save(newPurchaseOrderItem, "Update from mobile device");
  378. }
  379. catch (Exception ex)
  380. {
  381. InABox.Mobile.MobileLogging.Log(ex);
  382. SavePOItem(newPurchaseOrderItem);
  383. }
  384. }
  385. private CoreTable QuerySaveExtraQuantityPOItem(POItemShell poItemShell)
  386. {
  387. try
  388. {
  389. return new Client<PurchaseOrderItem>().Query(new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(poItemShell.ID)
  390. , columns);
  391. }
  392. catch (Exception ex)
  393. {
  394. InABox.Mobile.MobileLogging.Log(ex);
  395. return null;
  396. }
  397. }
  398. private PurchaseOrderItem CopyDetails(PurchaseOrderItem purchaseOrderItem, POItemShell poItemShell)
  399. {
  400. purchaseOrderItem.Product.ID = poItemShell.ProductID;
  401. purchaseOrderItem.Product.NonStock = poItemShell.Nonstock;
  402. purchaseOrderItem.Job.ID = poItemShell.JobID;
  403. purchaseOrderItem.Job.JobNumber = poItemShell.JobNumber;
  404. purchaseOrderItem.Job.Name = poItemShell.JobName;
  405. purchaseOrderItem.Style.ID = poItemShell.StyleID;
  406. purchaseOrderItem.Style.Code = poItemShell.StyleCode;
  407. purchaseOrderItem.Style.Description = poItemShell.StyleDescription;
  408. purchaseOrderItem.StockLocation.ID = poItemShell.StockLocationID;
  409. purchaseOrderItem.StockLocation.Description = poItemShell.StockLocationDescription;
  410. purchaseOrderItem.StockLocation.Code = poItemShell.StockLocationCode;
  411. purchaseOrderItem.Dimensions.Unit.ID = poItemShell.DimensionsUnitID;
  412. purchaseOrderItem.Dimensions.Quantity = poItemShell.DimensionsQuantity;
  413. purchaseOrderItem.Dimensions.Length = poItemShell.DimensionsLength;
  414. purchaseOrderItem.Dimensions.Width = poItemShell.DimensionsWidth;
  415. purchaseOrderItem.Dimensions.Height = poItemShell.DimensionsHeight;
  416. purchaseOrderItem.Dimensions.Weight = poItemShell.DimensionsWeight;
  417. purchaseOrderItem.Cost = poItemShell.Cost;
  418. purchaseOrderItem.Dimensions.Unit.HasHeight = poItemShell.DimensionsHasHeight;
  419. purchaseOrderItem.Dimensions.Unit.HasLength = poItemShell.DimensionsHasLength;
  420. purchaseOrderItem.Dimensions.Unit.HasWidth = poItemShell.DimensionsHasWidth;
  421. purchaseOrderItem.Dimensions.Unit.HasWeight = poItemShell.DimensionsHasWeight;
  422. purchaseOrderItem.Dimensions.Unit.HasQuantity = poItemShell.DimensionsHasQuantity;
  423. purchaseOrderItem.Dimensions.Unit.Formula = poItemShell.DimensionsUnitFormula;
  424. purchaseOrderItem.Dimensions.Unit.Format = poItemShell.DimensionsUnitFormat;
  425. purchaseOrderItem.Dimensions.Unit.Code = poItemShell.DimensionsUnitCode;
  426. purchaseOrderItem.Dimensions.Unit.Description = poItemShell.DimensionsUnitDescription;
  427. purchaseOrderItem.Dimensions.UnitSize = poItemShell.DimensionsUnitSize;
  428. purchaseOrderItem.Dimensions.Value = poItemShell.DimensionsValue;
  429. return purchaseOrderItem;
  430. }
  431. #region ChoosingLocations
  432. private async void ChooseReceivingLocationBtn_Clicked(object sender, EventArgs e)
  433. {
  434. string chosenOption = await DisplayActionSheet("Choose an Option", "Cancel", null, "New Location / Pack", "Existing Location / Pack");
  435. switch (chosenOption)
  436. {
  437. case "Cancel":
  438. return;
  439. break;
  440. case "New Location / Pack":
  441. ChooseNewLocation();
  442. break;
  443. case "Existing Location / Pack":
  444. ChooseReceivingLocation();
  445. break;
  446. default:
  447. return;
  448. break;
  449. }
  450. }
  451. private void ChooseNewLocation()
  452. {
  453. try
  454. {
  455. StockLocationShell location = new StockLocationShell();
  456. location.Active = true;
  457. // location.Warehouse.ID = Guid.Parse("b6249c4a-a834-4927-a42c-87a07895d6bd"); //EXTRUSIONS
  458. // location.Warehouse.Description = "Extrusions";
  459. // location.Warehouse.Code = "EXTRUSIONS";
  460. // location.Area.Warehouse.ID = Guid.Parse("b6249c4a-a834-4927-a42c-87a07895d6bd"); //EXTRUSIONS
  461. // location.Area.Warehouse.Description = "Extrusions";
  462. // location.Area.ID = Guid.Parse("fa02ecd8-e642-49aa-98b5-c04d7ea0f4eb"); //Rack FLOOR
  463. // location.Area.Description = "Rack FLOOR";
  464. // location.Area.Code = "FLOOR";
  465. StockLocationDetailsPage stockLocationDetailsPage = new StockLocationDetailsPage(location);
  466. stockLocationDetailsPage.Saved += (o, loc) =>
  467. {
  468. // if (String.IsNullOrWhiteSpace(loc.Code))
  469. // {
  470. // MaterialDialog.Instance.AlertAsync(message: "Code may not be blank!");
  471. // return false;
  472. // }
  473. //
  474. // if (String.IsNullOrWhiteSpace(loc.Description))
  475. // {
  476. // MaterialDialog.Instance.AlertAsync(message: "Description may not be blank!");
  477. // return false;
  478. // }
  479. //
  480. // if (loc.Area.ID == Guid.Empty)
  481. // {
  482. // MaterialDialog.Instance.AlertAsync(message: "Area may not be blank!");
  483. // return false;
  484. // }
  485. //
  486. // CoreTable others = QueryStockLocations(loc);
  487. // while (others == null)
  488. // others = QueryStockLocations(loc);
  489. //
  490. // if (others.Rows.Any())
  491. // {
  492. // MaterialDialog.Instance.AlertAsync(message: "Location Code already exists!");
  493. // return false;
  494. // }
  495. // try
  496. // {
  497. // loc = SaveStockLocation(loc);
  498. // StockLocationShell_Old shell = new StockLocationShell_Old();
  499. // shell.ID = loc.ID;
  500. // shell.Code = loc.Code;
  501. // shell.Description = loc.Description;
  502. // stockLocationShells.Add(shell);
  503. // Device.BeginInvokeOnMainThread(() =>
  504. // {
  505. // locationsStackLayout.Children.Clear();
  506. // foreach (StockLocationShell_Old shell2 in stockLocationShells)
  507. // {
  508. // StockLocationViewCell viewcell = new StockLocationViewCell(shell2);
  509. // viewcell.stockLocationShell.NumberOfReceivedItems = "Received items: " + shell2.PoItems.Count();
  510. // locationsStackLayout.Children.Add(viewcell);
  511. // }
  512. // });
  513. // }
  514. // catch (Exception err)
  515. // {
  516. // MaterialDialog.Instance.AlertAsync(message: "Unable to save Location\n" + err.Message);
  517. // return false;
  518. // }
  519. // return true;
  520. };
  521. Navigation.PushAsync(stockLocationDetailsPage);
  522. }
  523. catch { }
  524. }
  525. private StockLocation SaveStockLocation(StockLocation loc)
  526. {
  527. try
  528. {
  529. new Client<StockLocation>().Save(loc, "Created Location");
  530. return loc;
  531. }
  532. catch (Exception ex)
  533. {
  534. InABox.Mobile.MobileLogging.Log(ex);
  535. return SaveStockLocation(loc);
  536. }
  537. }
  538. private CoreTable QueryStockLocations(StockLocation loc)
  539. {
  540. try
  541. {
  542. return new Client<StockLocation>().Query(
  543. new Filter<StockLocation>(x => x.Code).IsEqualTo(loc.Code).And(x => x.ID).IsNotEqualTo(loc.ID),
  544. new Columns<StockLocation>(ColumnTypeFlags.None).Add(x => x.ID)
  545. );
  546. }
  547. catch (Exception ex)
  548. {
  549. InABox.Mobile.MobileLogging.Log(ex);
  550. return null;
  551. }
  552. }
  553. private void ChooseReceivingLocation()
  554. {
  555. if (bOpening)
  556. return;
  557. bOpening = true;
  558. StockLocationSelectionPage stockLocationSelectionPage = new StockLocationSelectionPage();
  559. stockLocationSelectionPage.OnLocationSelected += async (s, e) =>
  560. {
  561. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  562. {
  563. foreach (StockLocationShell shell in e.Locations)
  564. {
  565. if (!stockLocationShells.Any(x => x.ID == shell.ID))
  566. {
  567. //shell.Color = Color.Default;
  568. //shell.NumberOfReceivedItems = "Received items: " + shell.PoItems.Count();
  569. stockLocationShells.Add(shell);
  570. }
  571. }
  572. Device.BeginInvokeOnMainThread(() =>
  573. {
  574. locationsStackLayout.Children.Clear();
  575. foreach (StockLocationShell shell in stockLocationShells)
  576. {
  577. StockLocationViewCell viewcell = new StockLocationViewCell(shell);
  578. //viewcell.stockLocationShell.NumberOfReceivedItems = "Received items: " + shell.PoItems.Count();
  579. locationsStackLayout.Children.Add(viewcell);
  580. }
  581. });
  582. }
  583. };
  584. Navigation.PushAsync(stockLocationSelectionPage);
  585. }
  586. #endregion
  587. #endregion
  588. #region Loading
  589. private void AddIncomingStores()
  590. {
  591. Task.Run(() =>
  592. {
  593. try
  594. {
  595. CoreTable table = QueryIncomingStores();
  596. while (table == null)
  597. table = QueryIncomingStores();
  598. StockLocation location = table.Rows.FirstOrDefault().ToObject<StockLocation>();
  599. if (location == null)
  600. return;
  601. var newlocation = App.Data.StockLocations.FirstOrDefault(x => x.ID == location.ID);
  602. if (newlocation != null)
  603. stockLocationShells.Add(newlocation);
  604. // stockLocationShells.Add(new StockLocationShell
  605. // {
  606. // ID = location.ID,
  607. // Code = location.Code,
  608. // Description = location.Description,
  609. // NumberOfReceivedItems = "Received items: ",
  610. // });
  611. StockLocationViewCell viewcell = new StockLocationViewCell(stockLocationShells[0]);
  612. Device.BeginInvokeOnMainThread(() =>
  613. {
  614. locationsStackLayout.Children.Add(viewcell);
  615. });
  616. }
  617. catch { }
  618. });
  619. }
  620. private CoreTable QueryIncomingStores()
  621. {
  622. try
  623. {
  624. return new Client<StockLocation>().Query(
  625. new Filter<StockLocation>(x => x.ID).IsEqualTo(Guid.Parse("3ebb1fe3-21f4-4731-b80a-a28f814982ea")),
  626. new Columns<StockLocation>(ColumnTypeFlags.None).Add(x => x.ID, x => x.Code, x => x.Description));
  627. }
  628. catch (Exception ex)
  629. {
  630. InABox.Mobile.MobileLogging.Log(ex);
  631. return null;
  632. }
  633. }
  634. private void LoadPOItems()
  635. {
  636. Task.Run(() =>
  637. {
  638. try
  639. {
  640. CoreTable table = QueryLoadPOItems();
  641. while (table == null)
  642. table = QueryLoadPOItems();
  643. if (table.Rows.Any())
  644. {
  645. foreach (CoreRow row in table.Rows)
  646. {
  647. POItemShell item = new POItemShell()
  648. {
  649. ID = row.Get<PurchaseOrderItem, Guid>(x => x.ID),
  650. PONumber = row.Get<PurchaseOrderItem, string>(x => x.PurchaseOrderLink.PONumber),
  651. ConsignmentNumber = "Cons: " + row.Get<PurchaseOrderItem, string>(x => x.Consignment.Number),
  652. JobName = row.Get<PurchaseOrderItem, string>(x => x.Job.Name),
  653. JobNumber = row.Get<PurchaseOrderItem, string>(x => x.Job.JobNumber),
  654. Description = row.Get<PurchaseOrderItem, string>(x => x.Description),
  655. ConsignmentID = row.Get<PurchaseOrderItem, Guid>(x => x.Consignment.ID),
  656. POID = row.Get<PurchaseOrderItem, Guid>(x => x.PurchaseOrderLink.ID),
  657. ReceivedDate = row.Get<PurchaseOrderItem, DateTime>(x => x.ReceivedDate),
  658. JobID = row.Get<PurchaseOrderItem, Guid>(x => x.Job.ID),
  659. SupplierCode = row.Get<PurchaseOrderItem, string>(x => x.SupplierCode),
  660. ProductID = row.Get<PurchaseOrderItem, Guid>(x => x.Product.ID),
  661. Nonstock = row.Get<PurchaseOrderItem, bool>(x => x.Product.NonStock),
  662. StyleID = row.Get<PurchaseOrderItem, Guid>(x => x.Style.ID),
  663. StyleCode = row.Get<PurchaseOrderItem, string>(x => x.Style.Code),
  664. StyleDescription = row.Get<PurchaseOrderItem, string>(x => x.Style.Description),
  665. StockLocationID = row.Get<PurchaseOrderItem, Guid>(x => x.Product.DefaultLocation.ID),
  666. StockLocationDescription = row.Get<PurchaseOrderItem, string>(x => x.Product.DefaultLocation.Description),
  667. StockLocationCode = row.Get<PurchaseOrderItem, string>(x => x.Product.DefaultLocation.Code),
  668. DimensionsUnitID = row.Get<PurchaseOrderItem, Guid>(x => x.Dimensions.Unit.ID),
  669. DimensionsQuantity = row.Get<PurchaseOrderItem, double>(x => x.Dimensions.Quantity),
  670. DimensionsLength = row.Get<PurchaseOrderItem, double>(x => x.Dimensions.Length),
  671. DimensionsWidth = row.Get<PurchaseOrderItem, double>(x => x.Dimensions.Width),
  672. DimensionsHeight = row.Get<PurchaseOrderItem, double>(x => x.Dimensions.Height),
  673. DimensionsWeight = row.Get<PurchaseOrderItem, double>(x => x.Dimensions.Weight),
  674. DimensionsValue = row.Get<PurchaseOrderItem, double>(x => x.Dimensions.Value),
  675. DimensionsUnitSize = row.Get<PurchaseOrderItem, string>(x => x.Dimensions.UnitSize),
  676. Cost = row.Get<PurchaseOrderItem, double>(x => x.Cost),
  677. DimensionsHasHeight = row.Get<PurchaseOrderItem, bool>(x => x.Dimensions.Unit.HasHeight),
  678. DimensionsHasLength = row.Get<PurchaseOrderItem, bool>(x => x.Dimensions.Unit.HasLength),
  679. DimensionsHasWidth = row.Get<PurchaseOrderItem, bool>(x => x.Dimensions.Unit.HasWidth),
  680. DimensionsHasWeight = row.Get<PurchaseOrderItem, bool>(x => x.Dimensions.Unit.HasWeight),
  681. DimensionsHasQuantity = row.Get<PurchaseOrderItem, bool>(x => x.Dimensions.Unit.HasQuantity),
  682. DimensionsUnitFormula = row.Get<PurchaseOrderItem, string>(x => x.Dimensions.Unit.Formula),
  683. DimensionsUnitFormat = row.Get<PurchaseOrderItem, string>(x => x.Dimensions.Unit.Format),
  684. DimensionsUnitCode = row.Get<PurchaseOrderItem, string>(x => x.Dimensions.Unit.Code),
  685. DimensionsUnitDescription = row.Get<PurchaseOrderItem, string>(x => x.Dimensions.Unit.Description),
  686. ExpectedQty = row.Get<PurchaseOrderItem, double>(x => x.Qty),
  687. };
  688. if (string.IsNullOrWhiteSpace(item.DimensionsUnitSize) || item.DimensionsUnitID == Guid.Empty)
  689. item = TryFixPOItem(item, row);
  690. poItemShells.Add(item);
  691. }
  692. LoadImages();
  693. Device.BeginInvokeOnMainThread(() =>
  694. {
  695. poItemListView.ItemsSource = poItemShells;
  696. poItemCountLbl.Text = "Items Unreceived: " + poItemShells.Count;
  697. });
  698. }
  699. }
  700. catch (Exception ex)
  701. {
  702. Device.BeginInvokeOnMainThread(() => { DisplayAlert("Error loading Purchase Order items - please try again", ex.Message, "OK"); });
  703. }
  704. });
  705. }
  706. private CoreTable QueryLoadPOItems()
  707. {
  708. try
  709. {
  710. return new Client<PurchaseOrderItem>().Query(
  711. new Filter<PurchaseOrderItem>(x => x.PurchaseOrderLink.ID).IsEqualTo(POID).And(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue),
  712. columns);
  713. }
  714. catch (Exception ex)
  715. {
  716. InABox.Mobile.MobileLogging.Log(ex);
  717. return null;
  718. }
  719. }
  720. private void LoadImages()
  721. {
  722. Task.Run(() =>
  723. {
  724. List<Guid> productIds = new List<Guid>();
  725. foreach (POItemShell shell in poItemShells)
  726. {
  727. productIds.Add(shell.ProductID);
  728. }
  729. List<Guid> imageIds = new List<Guid>();
  730. Dictionary<Guid, Guid> imageProductIds = new Dictionary<Guid, Guid>();
  731. CoreTable table = QueryProductImageIDs(productIds);
  732. while (table == null)
  733. table = QueryProductImageIDs(productIds);
  734. foreach (CoreRow row in table.Rows)
  735. {
  736. if (row.Get<Product, Guid>(x => x.Image.ID) != Guid.Empty)
  737. {
  738. imageProductIds.Add(row.Get<Product, Guid>(x => x.Image.ID), row.Get<Product, Guid>(x => x.ID));
  739. }
  740. }
  741. CoreTable table2 = QueryDocuments(imageProductIds);
  742. while (table2 == null)
  743. table2 = QueryDocuments(imageProductIds);
  744. foreach (CoreRow row in table2.Rows)
  745. {
  746. byte[] data = row.Get<Document, byte[]>(x => x.Data);
  747. Guid imageid = row.Get<Document, Guid>(x => x.ID);
  748. Guid productid = imageProductIds[imageid];
  749. var item = poItemShells.FirstOrDefault(x => x.ProductID == productid);
  750. ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
  751. item.ImageSource = src;
  752. item.ImageVisible = true;
  753. if (deviceType == "Tablet")
  754. item.LastRowHeight = 300;
  755. else
  756. item.LastRowHeight = 150;
  757. }
  758. Device.BeginInvokeOnMainThread(() =>
  759. {
  760. poItemListView.ItemsSource = null;
  761. poItemListView.ItemsSource = poItemShells;
  762. });
  763. });
  764. }
  765. private CoreTable QueryDocuments(Dictionary<Guid, Guid> imageProductIds)
  766. {
  767. try
  768. {
  769. return new Client<Document>().Query(
  770. new Filter<Document>(x => x.ID).InList(imageProductIds.Keys.ToArray()),
  771. new Columns<Document>(ColumnTypeFlags.None).Add(x => x.ID, x => x.Data));
  772. }
  773. catch (Exception ex)
  774. {
  775. InABox.Mobile.MobileLogging.Log(ex);
  776. return null;
  777. }
  778. }
  779. private CoreTable QueryProductImageIDs(List<Guid> productIds)
  780. {
  781. try
  782. {
  783. return new Client<Product>().Query(
  784. new Filter<Product>(x => x.ID).InList(productIds.ToArray()),
  785. new Columns<Product>(ColumnTypeFlags.None).Add(x => x.ID, x => x.Image.ID)
  786. );
  787. }
  788. catch (Exception ex)
  789. {
  790. InABox.Mobile.MobileLogging.Log(ex);
  791. return null;
  792. }
  793. }
  794. private async void CreateNewConsignment()
  795. {
  796. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Creating new consignment"))
  797. {
  798. try
  799. {
  800. Consignment newConsignment = new Consignment() { };
  801. string name = "Unknown Supplier";
  802. if (supplierID != Guid.Empty)
  803. {
  804. newConsignment.Supplier.ID = supplierID;
  805. CoreTable supplierNameTable = QuerySuppliers();
  806. while (supplierNameTable == null)
  807. supplierNameTable = QuerySuppliers();
  808. name = supplierNameTable.Rows.FirstOrDefault().Values[0].ToString();
  809. }
  810. newConsignment.Description = "Consignment for receival of items from " + name + ". Auto generated from mobile app by " + App.Data.Me.Name;
  811. CoreTable consignmentNumberTable = QueryConsignment1();
  812. while (consignmentNumberTable == null)
  813. consignmentNumberTable = QueryConsignment1();
  814. if (consignmentNumberTable.Rows.Any())
  815. {
  816. SetConsignmentNumber(newConsignment, consignmentNumberTable);
  817. }
  818. else
  819. {
  820. CoreTable consignmentNumberTable2 = QueryConsignment2();
  821. while (consignmentNumberTable2 == null)
  822. consignmentNumberTable2 = QueryConsignment2();
  823. if (consignmentNumberTable2.Rows.Any())
  824. {
  825. SetConsignmentNumber(newConsignment, consignmentNumberTable2);
  826. }
  827. else
  828. newConsignment.Number = "APP1" + " From PO: " + PONumber;
  829. }
  830. newConsignment = SaveConsignment(newConsignment);
  831. consignmentID = newConsignment.ID;
  832. Save.IsVisible = true;
  833. consignmentNumber = newConsignment.Number;
  834. consignmentNumberLbl.Text = "Consignment: " + newConsignment.Number;
  835. if (consignmentID == Guid.Empty)
  836. {
  837. DisplayAlert("Error", "Unable to create new consignment", "OK");
  838. Navigation.PopAsync();
  839. }
  840. }
  841. catch { }
  842. }
  843. }
  844. private Consignment SaveConsignment(Consignment newConsignment)
  845. {
  846. try
  847. {
  848. new Client<Consignment>().Save(newConsignment, "Updated from mobile device");
  849. return newConsignment;
  850. }
  851. catch (Exception ex)
  852. {
  853. InABox.Mobile.MobileLogging.Log(ex);
  854. return SaveConsignment(newConsignment);
  855. }
  856. }
  857. private CoreTable QuerySuppliers()
  858. {
  859. try
  860. {
  861. return new Client<Supplier>().Query(
  862. new Filter<Supplier>(x => x.ID).IsEqualTo(supplierID),
  863. new Columns<Supplier>(ColumnTypeFlags.None).Add(x => x.Name)
  864. );
  865. }
  866. catch (Exception ex)
  867. {
  868. InABox.Mobile.MobileLogging.Log(ex);
  869. return null;
  870. }
  871. }
  872. private CoreTable QueryConsignment1()
  873. {
  874. try
  875. {
  876. return new Client<Consignment>().Query(
  877. new Filter<Consignment>(x => x.Number).Contains("APP").And(x => x.Created).IsGreaterThan(DateTime.Today.AddDays(-60)),
  878. new Columns<Consignment>(ColumnTypeFlags.None).Add(x => x.Number, x => x.Created),
  879. new SortOrder<Consignment>(x => x.Created));
  880. }
  881. catch (Exception ex)
  882. {
  883. InABox.Mobile.MobileLogging.Log(ex);
  884. return null;
  885. }
  886. }
  887. private CoreTable QueryConsignment2()
  888. {
  889. try
  890. {
  891. return new Client<Consignment>().Query(
  892. new Filter<Consignment>(x => x.Number).Contains("APP"),
  893. new Columns<Consignment>(ColumnTypeFlags.None).Add(x => x.Number, x => x.Created),
  894. new SortOrder<Consignment>(x => x.Created));
  895. }
  896. catch (Exception ex)
  897. {
  898. InABox.Mobile.MobileLogging.Log(ex);
  899. return null;
  900. }
  901. }
  902. private Consignment SetConsignmentNumber(Consignment newConsignment, CoreTable table)
  903. {
  904. List<int> numbers = new List<int>();
  905. foreach (CoreRow row in table.Rows)
  906. {
  907. string number = row.Values[0].ToString();
  908. if (number.Contains(" From PO"))
  909. {
  910. int index = number.IndexOf(" From PO");
  911. string firstSubstring = number.Substring(0, index);
  912. string secondSubString = firstSubstring.Substring(3, firstSubstring.Length - 3);
  913. try
  914. {
  915. int i = int.Parse(secondSubString);
  916. numbers.Add(i);
  917. }
  918. catch { }
  919. }
  920. }
  921. numbers.Sort();
  922. int lastInt = numbers.Last();
  923. lastInt++;
  924. newConsignment.Number = "APP" + lastInt.ToString() + " From PO" + PONumber;
  925. return newConsignment;
  926. }
  927. Columns<PurchaseOrderItem> columns = new Columns<PurchaseOrderItem>(ColumnTypeFlags.None).Add(x => x.ID,
  928. x => x.PurchaseOrderLink.PONumber,
  929. x => x.Consignment.Number,
  930. x => x.Job.Name,
  931. x => x.Job.JobNumber,
  932. x => x.Description,
  933. x => x.Qty,
  934. x => x.Consignment.ID,
  935. x => x.PurchaseOrderLink.ID,
  936. x => x.ReceivedDate,
  937. x => x.Job.ID,
  938. x => x.SupplierCode,
  939. x => x.Product.ID,
  940. x => x.Product.NonStock,
  941. x => x.Style.ID,
  942. x => x.Style.Code,
  943. x => x.Style.Description,
  944. x => x.Product.Image.ID,
  945. x => x.Product.DefaultLocation.ID,
  946. x => x.Product.DefaultLocation.Description,
  947. x => x.Product.DefaultLocation.Code,
  948. x => x.Dimensions.Unit.ID,
  949. x => x.Dimensions.Quantity,
  950. x => x.Dimensions.Length,
  951. x => x.Dimensions.Width,
  952. x => x.Dimensions.Height,
  953. x => x.Dimensions.Weight,
  954. x => x.Dimensions.Value,
  955. x => x.Dimensions.UnitSize,
  956. x => x.Cost,
  957. x => x.Dimensions.Unit.HasHeight,
  958. x => x.Dimensions.Unit.HasLength,
  959. x => x.Dimensions.Unit.HasWidth,
  960. x => x.Dimensions.Unit.HasWeight,
  961. x => x.Dimensions.Unit.HasQuantity,
  962. x => x.Dimensions.Unit.Formula,
  963. x => x.Dimensions.Unit.Format,
  964. x => x.Dimensions.Unit.Code,
  965. x => x.Dimensions.Unit.Description,
  966. x => x.Product.Dimensions.UnitSize,
  967. x => x.Product.Dimensions.Unit.ID,
  968. x => x.Product.Dimensions.Quantity,
  969. x => x.Product.Dimensions.Length,
  970. x => x.Product.Dimensions.Width,
  971. x => x.Product.Dimensions.Weight,
  972. x => x.Product.Dimensions.Height,
  973. x => x.Product.Dimensions.Value,
  974. x => x.Product.Dimensions.Unit.HasHeight,
  975. x => x.Product.Dimensions.Unit.HasLength,
  976. x => x.Product.Dimensions.Unit.HasWeight,
  977. x => x.Product.Dimensions.Unit.HasWidth,
  978. x => x.Product.Dimensions.Unit.HasQuantity,
  979. x => x.Product.Dimensions.Unit.Format,
  980. x => x.Product.Dimensions.Unit.Formula,
  981. x => x.Product.Dimensions.Unit.Code,
  982. x => x.Product.Dimensions.Unit.Description
  983. );
  984. private POItemShell TryFixPOItem(POItemShell item, CoreRow row)
  985. {
  986. PurchaseOrderItem poItem = row.ToObject<PurchaseOrderItem>();
  987. poItem.Dimensions.Quantity = poItem.Product.Dimensions.Quantity;
  988. poItem.Dimensions.Length = poItem.Product.Dimensions.Length;
  989. poItem.Dimensions.Width = poItem.Product.Dimensions.Width;
  990. poItem.Dimensions.Height = poItem.Product.Dimensions.Height;
  991. poItem.Dimensions.Weight = poItem.Product.Dimensions.Weight;
  992. poItem.Dimensions.Unit.ID = poItem.Product.Dimensions.Unit.ID;
  993. poItem.Dimensions.Unit.HasHeight = poItem.Product.Dimensions.Unit.HasHeight;
  994. poItem.Dimensions.Unit.HasLength = poItem.Product.Dimensions.Unit.HasLength;
  995. poItem.Dimensions.Unit.HasWidth = poItem.Product.Dimensions.Unit.HasWidth;
  996. poItem.Dimensions.Unit.HasWeight = poItem.Product.Dimensions.Unit.HasWeight;
  997. poItem.Dimensions.Unit.HasQuantity = poItem.Product.Dimensions.Unit.HasQuantity;
  998. poItem.Dimensions.Unit.Formula = poItem.Product.Dimensions.Unit.Formula;
  999. poItem.Dimensions.Unit.Code = poItem.Product.Dimensions.Unit.Code;
  1000. poItem.Dimensions.Unit.Description = poItem.Product.Dimensions.Unit.Description;
  1001. poItem.Dimensions.UnitSize = poItem.Product.Dimensions.UnitSize;
  1002. poItem.Dimensions.Value = poItem.Product.Dimensions.Value;
  1003. Task.Run(() => { DoSavePurchaseOrderItem(poItem); });
  1004. item.DimensionsQuantity = poItem.Dimensions.Quantity;
  1005. item.DimensionsLength = poItem.Dimensions.Length;
  1006. item.DimensionsWeight = poItem.Dimensions.Weight;
  1007. item.DimensionsWidth = poItem.Dimensions.Width;
  1008. item.DimensionsHeight = poItem.Dimensions.Height;
  1009. item.DimensionsUnitID = poItem.Dimensions.Unit.ID;
  1010. item.DimensionsHasHeight = poItem.Dimensions.Unit.HasHeight;
  1011. item.DimensionsHasLength = poItem.Dimensions.Unit.HasLength;
  1012. item.DimensionsHasWidth = poItem.Dimensions.Unit.HasWidth;
  1013. item.DimensionsHasWeight = poItem.Dimensions.Unit.HasWeight;
  1014. item.DimensionsHasQuantity = poItem.Dimensions.Unit.HasQuantity;
  1015. item.DimensionsUnitFormula = poItem.Dimensions.Unit.Formula;
  1016. item.DimensionsUnitFormat = poItem.Dimensions.Unit.Format;
  1017. item.DimensionsUnitCode = poItem.Dimensions.Unit.Code;
  1018. item.DimensionsUnitDescription = poItem.Dimensions.Unit.Description;
  1019. item.DimensionsUnitSize = poItem.Dimensions.UnitSize;
  1020. item.DimensionsValue = poItem.Dimensions.Value;
  1021. return item;
  1022. }
  1023. }
  1024. #endregion
  1025. }
  1026. #region Classes
  1027. public class POItemShell
  1028. {
  1029. public Guid ID { get; set; }
  1030. public string PONumber { get; set; }
  1031. public string ConsignmentNumber { get; set; }
  1032. public string Description { get; set; }
  1033. public Guid ConsignmentID { get; set; }
  1034. public Guid POID { get; set; }
  1035. public double ExpectedQty { get; set; }
  1036. public Color Color { get; set; }
  1037. public double ReceivedQty { get; set; }
  1038. public bool HasQAForm { get; set; }
  1039. public bool IsReadyForQA { get; set; }
  1040. public Color QATextColor { get; set; }
  1041. public Color QABtnColor { get; set; }
  1042. public Guid DigitalFormID { get; set; }
  1043. public DateTime FormCompleted { get; set; }
  1044. public DateTime ReceivedDate { get; set; }
  1045. public string SupplierCode { get; set; }
  1046. public Guid ProductID { get; set; }
  1047. public bool Nonstock { get; set; }
  1048. public Guid JobID { get; set; }
  1049. public string JobName { get; set; }
  1050. public string JobNumber { get; set; }
  1051. public Guid StyleID { get; set; }
  1052. public string StyleCode { get; set; }
  1053. public string StyleDescription { get; set; }
  1054. public Guid StockLocationID { get; set; }
  1055. public string StockLocationDescription { get; set; }
  1056. public string StockLocationCode { get; set; }
  1057. public bool ImageVisible { get; set; }
  1058. public ImageSource ImageSource { get; set; }
  1059. public double LastRowHeight { get; set; }
  1060. public double Cost { get; set; }
  1061. public Guid DimensionsUnitID { get; set; }
  1062. public double DimensionsQuantity { get; set; }
  1063. public double DimensionsLength { get; set; }
  1064. public double DimensionsWidth { get; set; }
  1065. public double DimensionsHeight { get; set; }
  1066. public double DimensionsWeight { get; set; }
  1067. public double DimensionsValue { get; set; }
  1068. public string DimensionsUnitSize { get; set; }
  1069. public bool DimensionsHasHeight { get; set; }
  1070. public bool DimensionsHasLength { get; set; }
  1071. public bool DimensionsHasWidth { get; set; }
  1072. public bool DimensionsHasWeight { get; set; }
  1073. public bool DimensionsHasQuantity { get; set; }
  1074. public string DimensionsUnitFormula { get; set; }
  1075. public string DimensionsUnitFormat { get; set; }
  1076. public string DimensionsUnitCode { get; set; }
  1077. public string DimensionsUnitDescription { get; set; }
  1078. public POItemShell()
  1079. {
  1080. ID = Guid.Empty;
  1081. PONumber = string.Empty;
  1082. ConsignmentNumber = string.Empty;
  1083. JobID = Guid.Empty;
  1084. JobName = string.Empty;
  1085. JobNumber = string.Empty;
  1086. Description = string.Empty;
  1087. ConsignmentID = Guid.Empty;
  1088. POID = Guid.Empty;
  1089. ExpectedQty = 0;
  1090. Color = Color.Default;
  1091. ReceivedQty = 0;
  1092. HasQAForm = false;
  1093. IsReadyForQA = false;
  1094. QATextColor = Color.LightGray;
  1095. DigitalFormID = Guid.Empty;
  1096. FormCompleted = DateTime.MinValue;
  1097. ReceivedDate = DateTime.MinValue;
  1098. SupplierCode = string.Empty;
  1099. ProductID = Guid.Empty;
  1100. Nonstock = false;
  1101. StyleID = Guid.Empty;
  1102. StyleCode = string.Empty;
  1103. StyleDescription = string.Empty;
  1104. StockLocationID = Guid.Empty;
  1105. StockLocationCode = "";
  1106. StockLocationDescription = "";
  1107. ImageVisible = false;
  1108. ImageSource = "";
  1109. LastRowHeight = 0;
  1110. DimensionsUnitID = Guid.Empty;
  1111. DimensionsQuantity = 0;
  1112. DimensionsLength = 0;
  1113. DimensionsWidth = 0;
  1114. DimensionsHeight = 0;
  1115. DimensionsWeight = 0;
  1116. DimensionsValue = 0;
  1117. DimensionsUnitSize = "";
  1118. Cost = 0.0;
  1119. DimensionsHasHeight = false;
  1120. DimensionsHasLength = false;
  1121. DimensionsHasWidth = false;
  1122. DimensionsHasWeight = false;
  1123. DimensionsHasQuantity = false;
  1124. DimensionsUnitFormula = "";
  1125. DimensionsUnitFormat = "";
  1126. DimensionsUnitCode = "";
  1127. DimensionsUnitDescription = "";
  1128. }
  1129. public POItemShell DuplicateNewShell(POItemShell poitemshell)
  1130. {
  1131. POItemShell shell = new POItemShell
  1132. {
  1133. ID = poitemshell.ID,
  1134. PONumber = poitemshell.PONumber,
  1135. ConsignmentNumber = poitemshell.ConsignmentNumber,
  1136. JobID = poitemshell.JobID,
  1137. JobName = poitemshell.JobName,
  1138. JobNumber = poitemshell.JobNumber,
  1139. Description = poitemshell.Description,
  1140. ConsignmentID = poitemshell.ConsignmentID,
  1141. POID = poitemshell.POID,
  1142. ExpectedQty = poitemshell.ExpectedQty,
  1143. Color = poitemshell.Color,
  1144. ReceivedQty = poitemshell.ReceivedQty,
  1145. HasQAForm = poitemshell.HasQAForm,
  1146. IsReadyForQA = poitemshell.IsReadyForQA,
  1147. QATextColor = poitemshell.QATextColor,
  1148. QABtnColor = poitemshell.QABtnColor,
  1149. DigitalFormID = poitemshell.DigitalFormID,
  1150. FormCompleted = poitemshell.FormCompleted,
  1151. ReceivedDate = poitemshell.ReceivedDate,
  1152. SupplierCode = poitemshell.SupplierCode,
  1153. ProductID = poitemshell.ProductID,
  1154. Nonstock = poitemshell.Nonstock,
  1155. StyleID = poitemshell.StyleID,
  1156. StyleCode = poitemshell.StyleCode,
  1157. StyleDescription = poitemshell.StyleDescription,
  1158. StockLocationID = poitemshell.StockLocationID,
  1159. StockLocationCode = poitemshell.StockLocationCode,
  1160. StockLocationDescription = poitemshell.StockLocationDescription,
  1161. ImageVisible = poitemshell.ImageVisible,
  1162. ImageSource = poitemshell.ImageSource,
  1163. LastRowHeight = poitemshell.LastRowHeight,
  1164. DimensionsUnitID = poitemshell.DimensionsUnitID,
  1165. DimensionsQuantity = poitemshell.DimensionsQuantity,
  1166. DimensionsLength = poitemshell.DimensionsLength,
  1167. DimensionsWidth = poitemshell.DimensionsWidth,
  1168. DimensionsHeight = poitemshell.DimensionsHeight,
  1169. DimensionsWeight = poitemshell.DimensionsWeight,
  1170. DimensionsValue = poitemshell.DimensionsValue,
  1171. DimensionsUnitSize = poitemshell.DimensionsUnitSize,
  1172. Cost = poitemshell.Cost,
  1173. DimensionsHasHeight = poitemshell.DimensionsHasHeight,
  1174. DimensionsHasLength = poitemshell.DimensionsHasLength,
  1175. DimensionsHasWidth = poitemshell.DimensionsHasWidth,
  1176. DimensionsHasWeight = poitemshell.DimensionsHasWeight,
  1177. DimensionsHasQuantity = poitemshell.DimensionsHasQuantity,
  1178. DimensionsUnitFormula = poitemshell.DimensionsUnitFormula,
  1179. DimensionsUnitFormat = poitemshell.DimensionsUnitFormat,
  1180. DimensionsUnitCode = poitemshell.DimensionsUnitCode,
  1181. DimensionsUnitDescription = poitemshell.DimensionsUnitDescription
  1182. };
  1183. return shell;
  1184. }
  1185. }
  1186. #endregion