123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using InABox.Core;
- using InABox.Clients;
- using Comal.Classes;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using System.Threading;
- using System.Threading.Tasks;
- using comal.timesheets.QAForms;
- using XF.Material.Forms.UI.Dialogs;
- using comal.timesheets;
- using Xamarin.Essentials;
- using System.IO;
- using PRSSecurity = InABox.Core.Security;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class Receivals : ContentPage
- {
- #region Fields & Constructor, OnAppearing
- Guid POID = Guid.Empty;
- List<POItemShell> poItemShells = new List<POItemShell>();
- List<StockLocationShell> stockLocationShells = new List<StockLocationShell>();
- bool bOpening = false;
- List<Guid> holdingsToLookup = new List<Guid>();
- string deviceType = "";
- Guid supplierID = Guid.Empty;
- string PONumber = "";
- Guid consignmentID = Guid.Empty;
- string consignmentNumber = "";
- List<POItemShell> listReceived = new List<POItemShell>();
- public Receivals(Guid _poID, string _PONumber, Guid _supplierID)
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- POID = _poID;
- PONumber = _PONumber;
- poNumberLbl.Text = "PO: " + _PONumber;
- var idiom = DeviceInfo.Idiom;
- if (idiom.Equals(DeviceIdiom.Tablet))
- {
- deviceType = "Tablet";
- }
- LoadPOItems();
- supplierID = _supplierID;
- AddIncomingStores();
- }
- protected override void OnAppearing()
- {
- base.OnAppearing();
- bOpening = false;
- }
- #endregion
- #region User Interaction
- private async void Exit_Clicked(object sender, EventArgs e)
- {
- if (listReceived.Count > 0)
- {
- DisplayAlert("Alert", "Consignment has items received and must be saved with photos before exiting", "OK");
- }
- else
- Navigation.PopAsync();
- }
- private async void Save_Clicked(object sender, EventArgs e)
- {
- ConsignmentCompletionPage completionPage = new ConsignmentCompletionPage(listReceived, consignmentID, consignmentNumber);
- completionPage.OnConsignmentSaved += () =>
- {
- Navigation.PopAsync();
- };
- Navigation.PushAsync(completionPage);
- }
- private void ConsignmentList_Tapped(object sender, EventArgs e)
- {
- if (bOpening)
- return;
- if (!PRSSecurity.IsAllowed<CanReceiveConsignments>())
- {
- DisplayAlert("Not allowed", "Please check security setting: Receive Consignments", "OK");
- return;
- }
- bOpening = true;
- POItemShell poItemShell = poItemListView.SelectedItem as POItemShell;
- if (poItemShell.Nonstock == true)
- {
- ChooseQtyNonStockItem(poItemShell);
- }
- else
- {
- ChooseQtyStockItem(poItemShell);
- }
- }
- private async void ChooseQtyStockItem(POItemShell poItemShell)
- {
- ConsignmentDetailsPopup popup = new ConsignmentDetailsPopup(poItemShell, stockLocationShells);
- popup.OnConsignmentPopupAccepted += async () =>
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- poItemShell.StockLocationID = popup._POItemShell.StockLocationID;
- poItemShell.StockLocationCode = popup._POItemShell.StockLocationCode;
- poItemShell.StockLocationDescription = popup._POItemShell.StockLocationDescription;
- poItemShell.ReceivedQty = popup._POItemShell.ReceivedQty;
- StockLocationShell location = stockLocationShells.Find(x => x.ID.Equals(poItemShell.StockLocationID));
- if (location == null)
- {
- StockLocationShell newLocation = new StockLocationShell()
- {
- ID = poItemShell.StockLocationID,
- Code = poItemShell.StockLocationCode,
- Description = poItemShell.StockLocationDescription
- };
- stockLocationShells.Add(newLocation);
- }
- ChooseSavePathwayAsync(poItemShell);
- }
- };
- Navigation.PushAsync(popup);
- bOpening = false;
- }
- private async void ChooseQtyNonStockItem(POItemShell poItemShell)
- {
- Device.BeginInvokeOnMainThread(async () =>
- {
- //if nonstock item - only rec qty, otherwise open popup page
- string chosenOption = await DisplayPromptAsync("Enter Received Quantity", "", initialValue: poItemShell.ExpectedQty.ToString(), keyboard: Keyboard.Numeric);
- if (!string.IsNullOrEmpty(chosenOption) || chosenOption != "Cancel")
- {
- try
- {
- double qty = double.Parse(chosenOption);
- poItemShell.ReceivedQty = qty;
- }
- catch
- {
- DisplayAlert("Error", "Invalid Qty", "OK");
- bOpening = false;
- return;
- }
- bOpening = false;
- ChooseSavePathwayAsync(poItemShell);
- }
- else
- bOpening = false;
- });
- }
- private void SearchEnt_Changed(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(searchEnt.Text))
- {
- poItemListView.ItemsSource = poItemShells;
- }
- else
- {
- poItemListView.ItemsSource = poItemShells.Where(x =>
- x.Description.Contains(searchEnt.Text) || x.Description.Contains(UpperCaseFirst(searchEnt.Text)) || x.Description.Contains(LowerCaseFirst(searchEnt.Text))
- || x.Description.Contains(searchEnt.Text.ToUpper()) || x.Description.Contains(searchEnt.Text.ToLower()) ||
- x.ExpectedQty.ToString().Contains(searchEnt.Text)
- );
- }
- }
- static String UpperCaseFirst(string s)
- {
- char[] a = s.ToCharArray();
- a[0] = char.ToUpper(a[0]);
- return new string(a);
- }
- static String LowerCaseFirst(string s)
- {
- char[] a = s.ToCharArray();
- a[0] = char.ToLower(a[0]);
- return new string(a);
- }
- #endregion
- #region Saving
- private async Task ChooseSavePathwayAsync(POItemShell poItemShell)
- {
- if (consignmentID == Guid.Empty)
- await CreateNewConsignment();
- if (poItemShell.ReceivedQty == poItemShell.ExpectedQty)
- {
- SaveCorrectQuantityPOItem(poItemShell);
- }
- else if (poItemShell.ReceivedQty < poItemShell.ExpectedQty && poItemShell.ReceivedQty != 0)
- {
- SaveLesserQuantityPOItem(poItemShell);
- }
- else if (poItemShell.ReceivedQty > poItemShell.ExpectedQty)
- {
- SaveExtraQuantityPOItem(poItemShell);
- }
- }
- private async void SaveCorrectQuantityPOItem(POItemShell poItemShell)
- {
- await Task.Run(() =>
- {
- poItemShell.ReceivedQty = poItemShell.ExpectedQty;
- poItemShell.ReceivedDate = DateTime.Now;
- poItemShell.ConsignmentID = consignmentID;
- poItemShell.ConsignmentNumber = consignmentNumber;
- SavePOItem(poItemShell);
- int index = poItemShells.FindIndex(x => x.ID.Equals(poItemShell.ID));
- poItemShells.RemoveAt(index);
- RefreshLists(poItemShell);
- });
- }
- private void SavePOItem(POItemShell poItemShell)
- {
- Task.Run(() =>
- {
- listReceived.Add(poItemShell);
- PurchaseOrderItem purchaseOrderItem = new PurchaseOrderItem();
- purchaseOrderItem.Description = poItemShell.Description;
- purchaseOrderItem.ID = poItemShell.ID;
- purchaseOrderItem.Qty = poItemShell.ReceivedQty;
- purchaseOrderItem.ReceivedDate = DateTime.Now;
- purchaseOrderItem.Consignment.ID = consignmentID;
- purchaseOrderItem.PurchaseOrderLink.PONumber = poItemShell.PONumber;
- purchaseOrderItem.PurchaseOrderLink.ID = poItemShell.POID;
- purchaseOrderItem = CopyDetails(purchaseOrderItem, poItemShell);
- new Client<PurchaseOrderItem>().Save(purchaseOrderItem, "Updated from mobile device");
- });
- }
- private void RefreshLists(POItemShell poItemShell)
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- poItemListView.ItemsSource = null;
- poItemListView.ItemsSource = poItemShells;
- poItemCountLbl.Text = "Items Unreceived: " + poItemShells.Count;
- if (poItemShell.StockLocationID != Guid.Empty)
- {
- StockLocationShell location = stockLocationShells.Find(x => x.ID.Equals(poItemShell.StockLocationID));
- location.PoItems.Add(poItemShell);
- location.NumberOfReceivedItems = "Received items: " + location.PoItems.Count;
- locationsStackLayout.Children.Clear();
- foreach (StockLocationShell shell in stockLocationShells)
- {
- StockLocationViewCell viewcell = new StockLocationViewCell(shell);
- locationsStackLayout.Children.Add(viewcell);
- }
- }
- });
- }
- private async void SaveLesserQuantityPOItem(POItemShell poItemShell)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- try
- {
- string originalDescription = poItemShell.Description;
- int index = poItemShells.FindIndex(x => x.ID.Equals(poItemShell.ID));
- poItemShells.RemoveAt(index);
- //placeholder added while all the loading / saving happens - to be replaced later when new purchaseorderitem ID is returned
- POItemShell placeHolderShell = poItemShell.DuplicateNewShell(poItemShell);
- placeHolderShell.ExpectedQty = poItemShell.ExpectedQty - poItemShell.ReceivedQty;
- poItemShells.Insert(index, placeHolderShell);
- SavePOItem(poItemShell); //original POItem is saved
- CoreTable table = new Client<PurchaseOrderItem>().Query(new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(poItemShell.ID),
- columns);
- PurchaseOrderItem purchaseOrderItem = table.Rows.FirstOrDefault()?.ToObject<PurchaseOrderItem>();
- if (purchaseOrderItem == null)
- return;
- purchaseOrderItem.ID = Guid.Empty;
- purchaseOrderItem.Created = DateTime.Now;
- purchaseOrderItem.LastUpdate = DateTime.Now;
- purchaseOrderItem.OriginalValues.Remove("ID", out object obj);
- purchaseOrderItem.ReceivedDate = DateTime.MinValue;
- purchaseOrderItem.Qty = poItemShell.ExpectedQty - poItemShell.ReceivedQty;
- purchaseOrderItem.Description = originalDescription;
- purchaseOrderItem.Consignment.ID = Guid.Empty;
- purchaseOrderItem = CopyDetails(purchaseOrderItem, poItemShell);
- new Client<PurchaseOrderItem>().Save(purchaseOrderItem, "Update from mobile device");
- //new purchase order is split from original with different quantity and no consignment linked, saved to database
- POItemShell newShell = poItemShell.DuplicateNewShell(poItemShell);
- newShell.ID = purchaseOrderItem.ID;
- newShell.Description = purchaseOrderItem.Description;
- newShell.ExpectedQty = purchaseOrderItem.Qty;
- newShell.ConsignmentID = Guid.Empty;
- newShell.ConsignmentNumber = "";
- //placeholder is replaced by new shell with correct ID
- poItemShells.RemoveAt(index);
- poItemShells.Insert(index, newShell);
- RefreshLists(poItemShell);
- }
- catch { }
- }
- }
- private async void SaveExtraQuantityPOItem(POItemShell poItemShell)
- {
- await Task.Run(() =>
- {
- try
- {
- string originalDescription = poItemShell.Description;
- double originalExpectedQty = poItemShell.ExpectedQty;
- double originalReceivedQty = poItemShell.ReceivedQty;
- double extraSupplied = originalReceivedQty - originalExpectedQty;
- int index = poItemShells.FindIndex(x => x.ID.Equals(poItemShell.ID));
- poItemShells.RemoveAt(index);
- poItemShell.ReceivedDate = DateTime.Now;
- poItemShell.ConsignmentID = consignmentID;
- poItemShell.ConsignmentNumber = consignmentNumber;
- poItemShell.ReceivedQty = poItemShell.ExpectedQty;
- SavePOItem(poItemShell);
- RefreshLists(poItemShell);
- listReceived.Add(poItemShell);
- //for responsive view only
- POItemShell newShell = poItemShell.DuplicateNewShell(poItemShell);
- newShell.ReceivedQty = extraSupplied;
- newShell.ExpectedQty = extraSupplied;
- RefreshLists(newShell);
- listReceived.Add(newShell);
- CoreTable table = new Client<PurchaseOrderItem>().Query(new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(poItemShell.ID)
- , columns);
- PurchaseOrderItem newPurchaseOrderItem = table.Rows.FirstOrDefault().ToObject<PurchaseOrderItem>();
- if (newPurchaseOrderItem == null)
- return;
- newPurchaseOrderItem.ReceivedDate = DateTime.Now;
- newPurchaseOrderItem.ID = Guid.Empty;
- newPurchaseOrderItem.Created = DateTime.Now;
- newPurchaseOrderItem.LastUpdate = DateTime.Now;
- newPurchaseOrderItem.OriginalValues.Remove("ID", out object obj);
- newPurchaseOrderItem.Qty = extraSupplied;
- newPurchaseOrderItem.Description = newShell.Description;
- newPurchaseOrderItem.Consignment.ID = consignmentID;
- newPurchaseOrderItem = CopyDetails(newPurchaseOrderItem, poItemShell);
- new Client<PurchaseOrderItem>().Save(newPurchaseOrderItem, "Update from mobile device");
- //new purchase order is split from original with different quantity, and consignment linked, saved to database
- }
- catch
- { }
- });
- }
- private PurchaseOrderItem CopyDetails(PurchaseOrderItem purchaseOrderItem, POItemShell poItemShell)
- {
- purchaseOrderItem.Product.ID = poItemShell.ProductID;
- purchaseOrderItem.Product.NonStock = poItemShell.Nonstock;
- purchaseOrderItem.Job.ID = poItemShell.JobID;
- purchaseOrderItem.Job.JobNumber = poItemShell.JobNumber;
- purchaseOrderItem.Job.Name = poItemShell.JobName;
- purchaseOrderItem.Style.ID = poItemShell.StyleID;
- purchaseOrderItem.Style.Code = poItemShell.StyleCode;
- purchaseOrderItem.Style.Description = poItemShell.StyleDescription;
- purchaseOrderItem.StockLocation.ID = poItemShell.StockLocationID;
- purchaseOrderItem.StockLocation.Description = poItemShell.StockLocationDescription;
- purchaseOrderItem.StockLocation.Code = poItemShell.StockLocationCode;
- purchaseOrderItem.Dimensions.Unit.ID = poItemShell.DimensionsUnitID;
- purchaseOrderItem.Dimensions.Quantity = poItemShell.DimensionsQuantity;
- purchaseOrderItem.Dimensions.Length = poItemShell.DimensionsLength;
- purchaseOrderItem.Dimensions.Width = poItemShell.DimensionsWidth;
- purchaseOrderItem.Dimensions.Height = poItemShell.DimensionsHeight;
- purchaseOrderItem.Dimensions.Weight = poItemShell.DimensionsWeight;
- purchaseOrderItem.Dimensions.Value = poItemShell.DimensionsValue;
- purchaseOrderItem.Dimensions.UnitSize = poItemShell.DimensionsUnitSize;
- purchaseOrderItem.Cost = poItemShell.Cost;
- return purchaseOrderItem;
- }
- #region ChoosingLocations
- private async void ChooseReceivingLocationBtn_Clicked(object sender, EventArgs e)
- {
- string chosenOption = await DisplayActionSheet("Choose an Option", "Cancel", null, "New Location / Pack", "Existing Location / Pack");
- switch (chosenOption)
- {
- case "Cancel":
- return;
- break;
- case "New Location / Pack":
- ChooseNewLocation();
- break;
- case "Existing Location / Pack":
- ChooseReceivingLocation();
- break;
- default:
- return;
- break;
- }
- }
- private void ChooseNewLocation()
- {
- try
- {
- StockLocation location = new StockLocation();
- location.Active = true;
- location.Warehouse.ID = Guid.Parse("b6249c4a-a834-4927-a42c-87a07895d6bd"); //EXTRUSIONS
- location.Warehouse.Description = "Extrusions";
- location.Warehouse.Code = "EXTRUSIONS";
- location.Area.Warehouse.ID = Guid.Parse("b6249c4a-a834-4927-a42c-87a07895d6bd"); //EXTRUSIONS
- location.Area.Warehouse.Description = "Extrusions";
- location.Area.ID = Guid.Parse("fa02ecd8-e642-49aa-98b5-c04d7ea0f4eb"); //Rack FLOOR
- location.Area.Description = "Rack FLOOR";
- location.Area.Code = "FLOOR";
- LocationDetailsPage locationDetailsPage = new LocationDetailsPage(location);
- locationDetailsPage.OnSave += (o, loc) =>
- {
- if (String.IsNullOrWhiteSpace(loc.Code))
- {
- MaterialDialog.Instance.AlertAsync(message: "Code may not be blank!");
- return false;
- }
- if (String.IsNullOrWhiteSpace(loc.Description))
- {
- MaterialDialog.Instance.AlertAsync(message: "Description may not be blank!");
- return false;
- }
- if (loc.Area.ID == Guid.Empty)
- {
- MaterialDialog.Instance.AlertAsync(message: "Area may not be blank!");
- return false;
- }
- CoreTable others = new Client<StockLocation>().Query(
- new Filter<StockLocation>(x => x.Code).IsEqualTo(loc.Code).And(x => x.ID).IsNotEqualTo(loc.ID),
- new Columns<StockLocation>(x => x.ID)
- );
- if (others.Rows.Any())
- {
- MaterialDialog.Instance.AlertAsync(message: "Location Code already exists!");
- return false;
- }
- try
- {
- new Client<StockLocation>().Save(loc, "Created Location");
- StockLocationShell shell = new StockLocationShell();
- shell.ID = loc.ID;
- shell.Code = loc.Code;
- shell.Description = loc.Description;
- stockLocationShells.Add(shell);
- Device.BeginInvokeOnMainThread(() =>
- {
- locationsStackLayout.Children.Clear();
- foreach (StockLocationShell shell2 in stockLocationShells)
- {
- StockLocationViewCell viewcell = new StockLocationViewCell(shell2);
- viewcell.stockLocationShell.NumberOfReceivedItems = "Received items: " + shell2.PoItems.Count();
- locationsStackLayout.Children.Add(viewcell);
- }
- });
- }
- catch (Exception err)
- {
- MaterialDialog.Instance.AlertAsync(message: "Unable to save Location\n" + err.Message);
- return false;
- }
- return true;
- };
- Navigation.PushAsync(locationDetailsPage);
- }
- catch { }
- }
- private void ChooseReceivingLocation()
- {
- if (bOpening)
- return;
- bOpening = true;
- StockLocationSelectionPage stockLocationSelectionPage = new StockLocationSelectionPage(true);
- stockLocationSelectionPage.OnMultiLocationSelected += async (s) =>
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- foreach (StockLocationShell shell in s)
- {
- if (!stockLocationShells.Any(x => x.ID == shell.ID))
- {
- shell.Color = Color.Default;
- shell.NumberOfReceivedItems = "Received items: " + shell.PoItems.Count();
- stockLocationShells.Add(shell);
- }
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- locationsStackLayout.Children.Clear();
- foreach (StockLocationShell shell in stockLocationShells)
- {
- StockLocationViewCell viewcell = new StockLocationViewCell(shell);
- viewcell.stockLocationShell.NumberOfReceivedItems = "Received items: " + shell.PoItems.Count();
- locationsStackLayout.Children.Add(viewcell);
- }
- });
- }
- };
- Navigation.PushAsync(stockLocationSelectionPage);
- }
- #endregion
- #endregion
- #region Loading
- private void AddIncomingStores()
- {
- Task.Run(() =>
- {
- try
- {
- StockLocation location = new Client<StockLocation>().Query(
- new Filter<StockLocation>(x => x.ID).IsEqualTo(Guid.Parse("3ebb1fe3-21f4-4731-b80a-a28f814982ea")),
- new Columns<StockLocation>(x => x.ID, x => x.Code, x => x.Description))
- .Rows.FirstOrDefault().ToObject<StockLocation>();
- stockLocationShells.Add(new StockLocationShell
- {
- ID = location.ID,
- Code = location.Code,
- Description = location.Description,
- NumberOfReceivedItems = "Received items: ",
- });
- StockLocationViewCell viewcell = new StockLocationViewCell(stockLocationShells[0]);
- Device.BeginInvokeOnMainThread(() =>
- {
- locationsStackLayout.Children.Add(viewcell);
- });
- }
- catch { }
- });
- }
- private void LoadPOItems()
- {
- Task.Run(() =>
- {
- try
- {
- CoreTable table = new Client<PurchaseOrderItem>().Query(
- new Filter<PurchaseOrderItem>(x => x.PurchaseOrderLink.ID).IsEqualTo(POID).And(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue),
- columns);
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- List<object> list = row.Values;
- if (list[0] == null) { list[0] = Guid.Empty; } //0
- if (list[1] == null) { list[1] = ""; } //1
- if (list[2] == null) { list[2] = ""; } //2
- if (list[3] == null) { list[3] = ""; } //3
- if (list[4] == null) { list[4] = ""; } //4
- if (list[5] == null) { list[5] = ""; } //5
- if (list[6] == null) { list[6] = 0F; } //6
- if (list[7] == null) { list[7] = Guid.Empty; } //7
- if (list[8] == null) { list[8] = Guid.Empty; } //8
- if (list[9] == null) { list[9] = DateTime.MinValue; } //9
- if (list[10] == null) { list[10] = Guid.Empty; } //10
- if (list[11] == null) { list[11] = ""; } //11
- if (list[12] == null) { list[12] = Guid.Empty; } //12
- if (list[13] == null) { list[13] = false; } //13
- if (list[14] == null) { list[14] = Guid.Empty; } //14
- if (list[15] == null) { list[15] = ""; } //15
- if (list[16] == null) { list[16] = ""; } //16
- if (list[17] == null) { list[17] = Guid.Empty; } //17
- if (list[18] == null) { list[18] = ""; } //18
- if (list[19] == null) { list[19] = ""; } //19
- if (list[20] == null) { list[20] = Guid.Empty; } //20
- if (list[21] == null) { list[21] = 0; } //21
- if (list[22] == null) { list[22] = 0; } //22
- if (list[23] == null) { list[23] = 0; } //23
- if (list[24] == null) { list[24] = 0; } //24
- if (list[25] == null) { list[25] = 0; } //25
- if (list[26] == null) { list[26] = 0; } //26
- if (list[27] == null) { list[27] = ""; } //27
- POItemShell item = new POItemShell()
- {
- ID = Guid.Parse(list[0].ToString()),
- PONumber = list[1].ToString(),
- ConsignmentNumber = "Cons: " + list[2].ToString(),
- JobName = list[3].ToString(),
- JobNumber = list[4].ToString(),
- Description = list[5].ToString(),
- ConsignmentID = Guid.Parse(list[7].ToString()),
- POID = Guid.Parse(list[8].ToString()),
- //FormCompleted = DateTime.Parse(list[10].ToString()),
- ReceivedDate = DateTime.Parse(list[9].ToString()),
- JobID = Guid.Parse(list[10].ToString()),
- SupplierCode = list[11].ToString(),
- ProductID = Guid.Parse(list[12].ToString()),
- Nonstock = Boolean.Parse(list[13].ToString()),
- StyleID = Guid.Parse(list[14].ToString()),
- StyleCode = list[15].ToString(),
- StyleDescription = list[16].ToString(),
- StockLocationID = Guid.Parse(list[17].ToString()),
- StockLocationDescription = list[18].ToString(),
- StockLocationCode = list[19].ToString(),
- DimensionsUnitID = Guid.Parse(list[20].ToString()),
- DimensionsQuantity = double.Parse(list[21].ToString()),
- DimensionsLength = double.Parse(list[22].ToString()),
- DimensionsWidth = double.Parse(list[23].ToString()),
- DimensionsHeight = double.Parse(list[24].ToString()),
- DimensionsWeight = double.Parse(list[25].ToString()),
- DimensionsValue = double.Parse(list[26].ToString()),
- DimensionsUnitSize = list[27].ToString()
- };
- if (double.TryParse(list[6].ToString(), out double result))
- item.ExpectedQty = result;
- poItemShells.Add(item);
- }
- LoadProductImages();
- Device.BeginInvokeOnMainThread(() =>
- {
- poItemListView.ItemsSource = poItemShells;
- poItemCountLbl.Text = "Items Unreceived: " + poItemShells.Count;
- });
- }
- }
- catch(Exception ex)
- {
- Device.BeginInvokeOnMainThread(() => { DisplayAlert("Error loading Purchase Order items - please try again", ex.Message, "OK"); });
- }
- });
- }
- private void LoadProductImages()
- {
- Task.Run(() =>
- {
- foreach (POItemShell shell in poItemShells)
- {
- if (shell.ProductID != Guid.Empty)
- {
- CoreTable table = new Client<Product>().Query
- (
- new Filter<Product>(x => x.ID).IsEqualTo(shell.ProductID).And(x => x.Image.ID).IsNotEqualTo(Guid.Empty),
- new Columns<Product>(x => x.Image.ID)
- );
- CoreTable table1 = new Client<Document>().Query
- (
- new Filter<Document>(x => x.ID).IsEqualTo(Guid.Parse(table.Rows.First().Values[0].ToString())),
- new Columns<Document>(x => x.Data)
- );
- CoreRow docrow = table1.Rows.FirstOrDefault();
- if (docrow != null)
- {
- byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
- ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
- if (src != null)
- {
- shell.ImageSource = src;
- shell.ImageVisible = true;
- if (deviceType == "Tablet")
- {
- shell.LastRowHeight = 300;
- }
- else
- {
- shell.LastRowHeight = 150;
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- poItemListView.ItemsSource = null;
- poItemListView.ItemsSource = poItemShells;
- });
- }
- }
- }
- }
- });
- }
- private async Task CreateNewConsignment()
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Creating new consignment"))
- {
- try
- {
- Consignment newConsignment = new Consignment() { };
- string name = "Unknown Supplier";
- if (supplierID != Guid.Empty)
- {
- newConsignment.Supplier.ID = supplierID;
- CoreTable supplierNameTable = new Client<Supplier>().Query(
- new Filter<Supplier>(x => x.ID).IsEqualTo(supplierID),
- new Columns<Supplier>(x => x.Name)
- );
- name = supplierNameTable.Rows.FirstOrDefault().Values[0].ToString();
- }
- newConsignment.Description = "Consignment for receival of items from " + name + ". Auto generated from mobile app by " + GlobalVariables.EmpName;
- CoreTable consignmentNumberTable = new Client<Consignment>().Query(
- new Filter<Consignment>(x => x.Number).Contains("APP").And(x => x.Created).IsGreaterThan(DateTime.Today.AddDays(-60)),
- new Columns<Consignment>(x => x.Number, x => x.Created),
- new SortOrder<Consignment>(x => x.Created));
- if (consignmentNumberTable.Rows.Any())
- {
- SetConsignmentNumber(newConsignment, consignmentNumberTable);
- }
- else
- {
- CoreTable consignmentNumberTable2 = new Client<Consignment>().Query(
- new Filter<Consignment>(x => x.Number).Contains("APP"),
- new Columns<Consignment>(x => x.Number, x => x.Created),
- new SortOrder<Consignment>(x => x.Created));
- if (consignmentNumberTable2.Rows.Any())
- {
- SetConsignmentNumber(newConsignment, consignmentNumberTable2);
- }
- else
- newConsignment.Number = "APP1" + " From PO: " + PONumber;
- }
- new Client<Consignment>().Save(newConsignment, "Updated from mobile device");
- consignmentID = newConsignment.ID;
- saveBtn.IsVisible = true;
- consignmentNumber = newConsignment.Number;
- consignmentNumberLbl.Text = "Consignment: " + newConsignment.Number;
- if (consignmentID == Guid.Empty)
- {
- DisplayAlert("Error", "Unable to create new consignment", "OK");
- Navigation.PopAsync();
- }
- }
- catch { }
- }
- }
- private Consignment SetConsignmentNumber(Consignment newConsignment, CoreTable table)
- {
- List<int> numbers = new List<int>();
- foreach (CoreRow row in table.Rows)
- {
- string number = row.Values[0].ToString();
- if (number.Contains(" From PO"))
- {
- int index = number.IndexOf(" From PO");
- string firstSubstring = number.Substring(0, index);
- string secondSubString = firstSubstring.Substring(3, firstSubstring.Length - 3);
- try
- {
- int i = int.Parse(secondSubString);
- numbers.Add(i);
- }
- catch { }
- }
- }
- numbers.Sort();
- int lastInt = numbers.Last();
- lastInt++;
- newConsignment.Number = "APP" + lastInt.ToString() + " From PO" + PONumber;
- return newConsignment;
- }
- Columns<PurchaseOrderItem> columns = new Columns<PurchaseOrderItem>(x => x.ID, //0
- x => x.PurchaseOrderLink.PONumber, //1
- x => x.Consignment.Number, //2
- x => x.Job.Name, //3
- x => x.Job.JobNumber, //4
- x => x.Description, //5
- x => x.Qty, //6
- x => x.Consignment.ID, //7
- x => x.PurchaseOrderLink.ID, //8
- x => x.ReceivedDate, //9
- x => x.Job.ID, //10
- x => x.SupplierCode, //11
- x => x.Product.ID, //12
- x => x.Product.NonStock, //13
- x => x.Style.ID, //14
- x => x.Style.Code, //15
- x => x.Style.Description, //16
- x => x.Product.DefaultLocation.ID, //17
- x => x.Product.DefaultLocation.Description, //18
- x => x.Product.DefaultLocation.Code, //19
- x => x.Dimensions.Unit.ID, //20
- x => x.Dimensions.Quantity, //21
- x => x.Dimensions.Length, //22
- x => x.Dimensions.Width, //23
- x => x.Dimensions.Height, //24
- x => x.Dimensions.Weight, //25
- x => x.Dimensions.Value, //26
- x => x.Dimensions.UnitSize, //27
- x => x.Cost //28
- );
- }
- #endregion
- }
- #region Classes
- public class POItemShell
- {
- public Guid ID { get; set; }
- public string PONumber { get; set; }
- public string ConsignmentNumber { get; set; }
- public string Description { get; set; }
- public Guid ConsignmentID { get; set; }
- public Guid POID { get; set; }
- public double ExpectedQty { get; set; }
- public Color Color { get; set; }
- public double ReceivedQty { get; set; }
- public bool HasQAForm { get; set; }
- public bool IsReadyForQA { get; set; }
- public Color QATextColor { get; set; }
- public Color QABtnColor { get; set; }
- public Guid DigitalFormID { get; set; }
- public DateTime FormCompleted { get; set; }
- public DateTime ReceivedDate { get; set; }
- public string SupplierCode { get; set; }
- public Guid ProductID { get; set; }
- public bool Nonstock { get; set; }
- public Guid JobID { get; set; }
- public string JobName { get; set; }
- public string JobNumber { get; set; }
- public Guid StyleID { get; set; }
- public string StyleCode { get; set; }
- public string StyleDescription { get; set; }
- public Guid StockLocationID { get; set; }
- public string StockLocationDescription { get; set; }
- public string StockLocationCode { get; set; }
- public bool ImageVisible { get; set; }
- public ImageSource ImageSource { get; set; }
- public double LastRowHeight { get; set; }
- public double Cost { get; set; }
- public Guid DimensionsUnitID { get; set; }
- public double DimensionsQuantity { get; set; }
- public double DimensionsLength { get; set; }
- public double DimensionsWidth { get; set; }
- public double DimensionsHeight { get; set; }
- public double DimensionsWeight { get; set; }
- public double DimensionsValue { get; set; }
- public string DimensionsUnitSize { get; set; }
- public POItemShell()
- {
- ID = Guid.Empty;
- PONumber = string.Empty;
- ConsignmentNumber = string.Empty;
- JobID = Guid.Empty;
- JobName = string.Empty;
- JobNumber = string.Empty;
- Description = string.Empty;
- ConsignmentID = Guid.Empty;
- POID = Guid.Empty;
- ExpectedQty = 0;
- Color = Color.Default;
- ReceivedQty = 0;
- HasQAForm = false;
- IsReadyForQA = false;
- QATextColor = Color.LightGray;
- DigitalFormID = Guid.Empty;
- FormCompleted = DateTime.MinValue;
- ReceivedDate = DateTime.MinValue;
- SupplierCode = string.Empty;
- ProductID = Guid.Empty;
- Nonstock = false;
- StyleID = Guid.Empty;
- StyleCode = string.Empty;
- StyleDescription = string.Empty;
- StockLocationID = Guid.Empty;
- StockLocationCode = "";
- StockLocationDescription = "";
- ImageVisible = false;
- ImageSource = "";
- LastRowHeight = 0;
- DimensionsUnitID = Guid.Empty;
- DimensionsQuantity = 0;
- DimensionsLength = 0;
- DimensionsWidth = 0;
- DimensionsHeight = 0;
- DimensionsWeight = 0;
- DimensionsValue = 0;
- DimensionsUnitSize = "";
- Cost = 0.0;
- }
- public POItemShell DuplicateNewShell(POItemShell poitemshell)
- {
- POItemShell shell = new POItemShell
- {
- ID = poitemshell.ID,
- PONumber = poitemshell.PONumber,
- ConsignmentNumber = poitemshell.ConsignmentNumber,
- JobID = poitemshell.JobID,
- JobName = poitemshell.JobName,
- JobNumber = poitemshell.JobNumber,
- Description = poitemshell.Description,
- ConsignmentID = poitemshell.ConsignmentID,
- POID = poitemshell.POID,
- ExpectedQty = poitemshell.ExpectedQty,
- Color = poitemshell.Color,
- ReceivedQty = poitemshell.ReceivedQty,
- HasQAForm = poitemshell.HasQAForm,
- IsReadyForQA = poitemshell.IsReadyForQA,
- QATextColor = poitemshell.QATextColor,
- QABtnColor = poitemshell.QABtnColor,
- DigitalFormID = poitemshell.DigitalFormID,
- FormCompleted = poitemshell.FormCompleted,
- ReceivedDate = poitemshell.ReceivedDate,
- SupplierCode = poitemshell.SupplierCode,
- ProductID = poitemshell.ProductID,
- Nonstock = poitemshell.Nonstock,
- StyleID = poitemshell.StyleID,
- StyleCode = poitemshell.StyleCode,
- StyleDescription = poitemshell.StyleDescription,
- StockLocationID = poitemshell.StockLocationID,
- StockLocationCode = poitemshell.StockLocationCode,
- StockLocationDescription = poitemshell.StockLocationDescription,
- ImageVisible = poitemshell.ImageVisible,
- ImageSource = poitemshell.ImageSource,
- LastRowHeight = poitemshell.LastRowHeight,
- DimensionsUnitID = poitemshell.DimensionsUnitID,
- DimensionsQuantity = poitemshell.DimensionsQuantity,
- DimensionsLength = poitemshell.DimensionsLength,
- DimensionsWidth = poitemshell.DimensionsWidth,
- DimensionsHeight = poitemshell.DimensionsHeight,
- DimensionsWeight = poitemshell.DimensionsWeight,
- DimensionsValue = poitemshell.DimensionsValue,
- DimensionsUnitSize = poitemshell.DimensionsUnitSize,
- Cost = poitemshell.Cost
- };
- return shell;
- }
- }
- #endregion
|