Receivals.xaml.cs 56 KB

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