internal void AssignValueToAddPalletAsync(string _batchId, IList <BarcodeModel> barcodes)
 {
     try
     {
         if (barcodes.Count == 0)
         {
             PalletCollection.Clear();
             Kegs = default;
         }
         else if (!PalletCollection.Any(x => x.BatchId == _batchId))
         {
             PalletCollection.Add(new PalletModel()
             {
                 Barcode = barcodes, Count = barcodes.Count(), BatchId = _batchId
             });
             CountKegs();
         }
         else
         {
             PalletCollection.Where(x => x.BatchId == _batchId).FirstOrDefault().Barcode = barcodes;
             PalletCollection.Where(x => x.BatchId == _batchId).FirstOrDefault().Count   = barcodes.Count;
             CountKegs();
         }
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
 private void CountKegs()
 {
     if (PalletCollection.Sum(x => x.Count) > 1)
     {
         Kegs = string.Format("({0} Kegs)", PalletCollection.Sum(x => x.Count));
     }
     else
     {
         Kegs = string.Format("({0} Keg)", PalletCollection.Sum(x => x.Count));
     }
 }
Esempio n. 3
0
        private void AssignInitialValue(ManifestModel manifestModel)
        {
            try
            {
                NewBatchModel            = manifestModel?.NewBatches.FirstOrDefault();
                SizeButtonTitle          = manifestModel?.Size;
                DestinationTitle         = manifestModel?.OwnerName;
                ManifestId               = manifestModel?.ManifestId;
                ConstantManager.Barcodes = manifestModel?.BarcodeModels;

                try
                {
                    PartnerModel partner = new PartnerModel()
                    {
                        PartnerId = manifestModel?.ReceiverId,
                        FullName  = manifestModel?.OwnerName
                    };
                    ConstantManager.Partner = partner;
                    if (manifestModel.Tags != null)
                    {
                        ConstantManager.Tags = new List <Tag>();
                        foreach (var item in manifestModel.Tags)
                        {
                            ConstantManager.Tags.Add(item);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }

                foreach (var item in manifestModel.NewPallets)
                {
                    PalletModel palletModel = new PalletModel
                    {
                        Count      = item.PalletItems.Count,
                        ManifestId = ManifestId,
                        BatchId    = item.PalletId
                    };
                    palletModel.Barcode = ConstantManager.Barcodes;
                    if (PalletCollection == null)
                    {
                        PalletCollection = new List <PalletModel>();
                    }
                    PalletCollection.Add(palletModel);
                    IsPalletze = item.IsPalletze;
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
Esempio n. 4
0
        private void Cleanup()
        {
            try
            {
                PalletCollection.Clear();

                AddPalletToFillScanMsg msg = new AddPalletToFillScanMsg
                {
                    CleanUp = true
                };
                MessagingCenter.Send(msg, "AddPalletToFillScanMsg");
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
Esempio n. 5
0
 private void DeleteManifest(string manifestId)
 {
     try
     {
         var RealmDb  = Realm.GetInstance(RealmDbManager.GetRealmDbConfig());
         var manifest = RealmDb.All <ManifestModel>().First(b => b.ManifestId == manifestId);
         using (var trans = RealmDb.BeginWrite())
         {
             RealmDb.Remove(manifest);
             trans.Commit();
         }
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex);
     }
     ConstantManager.Barcodes?.Clear();
     PalletCollection?.Clear();
 }
        public void Cleanup()
        {
            try
            {
                PalletCollection.Clear();
                Kegs = default;
                ConstantManager.Barcodes.Clear();
                ConstantManager.Tags.Clear();
                ConstantManager.Partner = null;

                AddPalletToFillScanMsg msg = new AddPalletToFillScanMsg
                {
                    CleanUp = true
                };
                MessagingCenter.Send(msg, "AddPalletToFillScanMsg");
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
 internal void AssignFillScanValue(IList <BarcodeModel> _barcodes, string _batchId)
 {
     try
     {
         PalletModel pallet = PalletCollection.Where(x => x.BatchId == _batchId).FirstOrDefault();
         if (pallet != null)
         {
             using (var db = Realm.GetInstance(RealmDbManager.GetRealmDbConfig()).BeginWrite())
             {
                 pallet.Barcode = _barcodes;
                 pallet.Count   = _barcodes.Count();
                 db.Commit();
             }
         }
         else
         {
             PalletCollection.Add(new PalletModel()
             {
                 Barcode = _barcodes,
                 Count   = _barcodes.Count(),
                 BatchId = _batchId,
             });
         }
         if (PalletCollection.Sum(x => x.Count) > 1)
         {
             Kegs = string.Format("({0} Kegs)", PalletCollection.Sum(x => x.Count));
         }
         else
         {
             Kegs = string.Format("({0} Keg)", PalletCollection.Sum(x => x.Count));
         }
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
        public async void SubmitCommandRecieverAsync()
        {
            try
            {
                var location = await _geolocationService.GetLastLocationAsync();

                var barcodes     = ConstantManager.Barcodes;
                var tags         = ConstantManager.Tags;
                var partnerModel = ConstantManager.Partner;

                if (PalletCollection.Count == 0)
                {
                    await _dialogService.DisplayAlertAsync("Error", "Error: Please add some scans.", "Ok");

                    return;
                }

                IEnumerable <PalletModel> empty = PalletCollection.Where(x => x.Barcode.Count == 0);
                if (empty.ToList().Count > 0)
                {
                    string result = await _dialogService.DisplayActionSheetAsync("Error? \n Some pallets have 0 scans. Do you want to edit them or remove the empty pallets.", null, null, "Remove empties", "Edit");

                    if (result == "Remove empties")
                    {
                        foreach (var item in empty.Reverse())
                        {
                            PalletCollection.Remove(item);
                        }
                        if (PalletCollection.Count == 0)
                        {
                            return;
                        }
                    }
                    if (result == "Edit")
                    {
                        await ItemTappedCommandRecieverAsync(empty.FirstOrDefault());

                        return;
                    }
                }

                List <string>    closedBatches = new List <string>();
                List <NewPallet> newPallets    = new List <NewPallet>();
                NewPallet        newPallet     = null;
                List <TItem>     palletItems   = new List <TItem>();
                TItem            palletItem    = null;

                foreach (var pallet in PalletCollection)
                {
                    foreach (var item in pallet.Barcode)
                    {
                        palletItem = new TItem
                        {
                            Barcode  = item.Barcode,
                            ScanDate = DateTimeOffset.UtcNow.Date,
                            TagsStr  = item.TagsStr
                        };

                        if (item.Tags != null)
                        {
                            foreach (var tag in item.Tags)
                            {
                                palletItem.Tags.Add(tag);
                            }
                        }
                        palletItems.Add(palletItem);
                    }

                    newPallet = new NewPallet
                    {
                        Barcode           = pallet.BatchId,
                        BuildDate         = DateTimeOffset.UtcNow.Date,
                        StockLocation     = partnerModel?.PartnerId,
                        StockLocationId   = partnerModel?.PartnerId,
                        StockLocationName = partnerModel?.FullName,
                        OwnerId           = AppSettings.CompanyId,
                        PalletId          = _uuidManager.GetUuId(),
                        ReferenceKey      = "",
                    };
                    if (tags != null)
                    {
                        foreach (var item in tags)
                        {
                            newPallet.Tags.Add(item);
                        }
                    }
                    foreach (var item in palletItems)
                    {
                        newPallet.PalletItems.Add(item);
                    }
                    newPallets.Add(newPallet);
                }

                bool accept = await _dialogService.DisplayAlertAsync("Close batch", "Mark this batch as completed?", "Yes", "No");

                if (accept)
                {
                    closedBatches = PalletCollection.Select(x => x.ManifestId).ToList();
                }

                Loader.StartLoading();
                ManifestModel model = null;
                try
                {
                    model = _manifestManager.GetManifestDraft(EventTypeEnum.FILL_MANIFEST, ManifestId ?? PalletCollection.FirstOrDefault().ManifestId,
                                                              barcodes, location != null?(long)location.Latitude:0, location != null ? (long)location.Longitude:0, tags, string.Empty, partnerModel, newPallets, new List <NewBatch>(), closedBatches, null, 4);
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
                if (model != null)
                {
                    try
                    {
                        var current = Connectivity.NetworkAccess;
                        if (current == NetworkAccess.Internet)
                        {
                            var manifestPostModel = await _moveService.PostManifestAsync(model, AppSettings.SessionId, Configuration.NewManifest);

                            try
                            {
                                AddorUpdateManifestOffline(model, false);
                            }
                            catch (Exception ex)
                            {
                                Crashes.TrackError(ex);
                            }
                            await GetPostedManifestDetail();
                        }
                        else
                        {
                            try
                            {
                                AddorUpdateManifestOffline(model, true);
                            }
                            catch (Exception ex)
                            {
                                Crashes.TrackError(ex);
                            }
                            await GetPostedManifestDetail();
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                    finally
                    {
                        model         = null;
                        barcodes      = null;
                        tags          = null;
                        partnerModel  = null;
                        closedBatches = null;
                        newPallets    = null;
                        newPallet     = null;
                        palletItems   = null;
                        palletItem    = null;
                        Cleanup();
                    }
                }
                else
                {
                    await _dialogService.DisplayAlertAsync("Alert", "Something goes wrong please check again", "Ok");
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
            finally
            {
                Loader.StopLoading();
            }
        }
 private void DeleteItemCommandReciever(PalletModel model)
 {
     PalletCollection.Remove(model);
     CountKegs();
 }
Esempio n. 10
0
 public Shipment(PalletCollection pallets)
 {
     Pallets = pallets;
 }