public ManifestModel GenerateManifest(Xamarin.Essentials.Location location)
 {
     return(_manifestManager.GetManifestDraft(eventTypeEnum: EventTypeEnum.MOVE_MANIFEST, manifestId: ManifestId,
                                              barcodeCollection: ConstantManager.Barcodes ?? new List <BarcodeModel>(), (long)location.Latitude, (long)location.Longitude, tags: Tags ?? new List <Tag>(), tagsStr: TagsStr,
                                              partnerModel: ConstantManager.Partner, newPallets: new List <NewPallet>(), batches: new List <NewBatch>(),
                                              closedBatches: new List <string>(), null, validationStatus: 2, contents: Contents));
 }
Beispiel #2
0
        public ManifestModel GenerateManifest(IList <PalletModel> palletCollection, Xamarin.Essentials.Location location)
        {
            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,
                        Icon     = item.Icon,
                        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.ManifestId,
                    BuildDate         = DateTimeOffset.UtcNow.Date,
                    StockLocation     = ConstantManager.Partner.PartnerId,
                    StockLocationId   = ConstantManager.Partner.PartnerId,
                    StockLocationName = ConstantManager.Partner.FullName,
                    OwnerId           = AppSettings.CompanyId,
                    PalletId          = pallet.BatchId,
                    ReferenceKey      = "",
                    IsPalletze        = IsPalletze
                };
                foreach (var item in palletItems)
                {
                    newPallet.PalletItems.Add(item);
                }
                newPallets.Add(newPallet);
            }

            List <NewBatch> newBatches = new List <NewBatch>
            {
                NewBatchModel,
            };

            return(_manifestManager.GetManifestDraft(eventTypeEnum: EventTypeEnum.FILL_MANIFEST, manifestId: ManifestId,
                                                     barcodeCollection: ConstantManager.Barcodes ?? new List <BarcodeModel>(), (long)location.Latitude, (long)location.Longitude, tags: new List <Tag>(), tagsStr: "",
                                                     partnerModel: ConstantManager.Partner, newPallets: newPallets ?? new List <NewPallet>(), batches: newBatches,
                                                     closedBatches: new List <string>(), null, validationStatus: 4, contents: SizeButtonTitle, size: SizeButtonTitle));
        }
        public ManifestModel GenerateManifest(Xamarin.Essentials.Location location, string manifestId = "")
        {
            List <MaintainKeg> kegs = new List <MaintainKeg>();
            MaintainKeg        keg  = null;

            MaintenanceModel model = new MaintenanceModel
            {
                MaintenanceDoneRequestModel = new MaintenanceDoneRequestModel()
            };

            foreach (var item in BarcodeCollection)
            {
                keg = new MaintainKeg
                {
                    Barcode          = item.Barcode,
                    ScanDate         = DateTimeOffset.Now,
                    ValidationStatus = 4
                };
                kegs.Add(keg);
                model.MaintenanceDoneRequestModel.Kegs.Add(keg);
            }

            foreach (var item in ConstantManager.MaintainTypeCollection.Where(x => x.IsToggled == true).Select(y => y.Id).ToList())
            {
                model.MaintenanceDoneRequestModel.ActionsPerformed.Add(item);
            }

            model.MaintenanceDoneRequestModel.DatePerformed        = DateTimeOffset.Now.AddDays(-2);
            model.MaintenanceDoneRequestModel.LocationId           = ConstantManager.Partner.PartnerId;
            model.MaintenanceDoneRequestModel.MaintenancePostingId = _uuidManager.GetUuId();
            model.MaintenanceDoneRequestModel.Latitude             = (long)location.Latitude;
            model.MaintenanceDoneRequestModel.Longitude            = (long)location.Longitude;
            model.MaintenanceDoneRequestModel.Notes        = Notes;
            model.MaintenanceDoneRequestModel.PartnerModel = ConstantManager.Partner;

            return(_manifestManager.GetManifestDraft(eventTypeEnum: EventTypeEnum.REPAIR_MANIFEST, manifestId: !string.IsNullOrEmpty(manifestId) ? manifestId : _uuidManager.GetUuId(),
                                                     barcodeCollection: BarcodeCollection, (long)location.Latitude, (long)location.Longitude, tags: ConstantManager.Tags, ConstantManager.TagsStr, partnerModel: ConstantManager.Partner,
                                                     newPallets: new List <NewPallet>(), batches: new List <NewBatch>(),
                                                     closedBatches: new List <string>(), model, validationStatus: 4, contents: ""));
        }
        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();
            }
        }