コード例 #1
0
        public AllocationBillPageViewModel(INavigationService navigationService,
                                           IProductService productService,
                                           IUserService userService,
                                           ITerminalService terminalService,
                                           IWareHousesService wareHousesService,
                                           IAccountingService accountingService,
                                           IDialogService dialogService,
                                           IMicrophoneService microphoneService
                                           ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "调拨单";
            _microphoneService = microphoneService;

            InitBill();

            //验证
            var valid_IsReversed          = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作");
            var valid_IsAudited           = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作");
            var valid_ShipmentWareHouseId = this.ValidationRule(x => x.Bill.ShipmentWareHouseId, _isZero, "出货仓库未指定");
            var valid_IncomeWareHouseId   = this.ValidationRule(x => x.Bill.IncomeWareHouseId, _isZero, "入货仓库未指定");
            var valid_ProductCount        = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目");

            //添加商品
            this.AddProductCommand = ReactiveCommand.Create <object>(async e =>
            {
                try
                {
                    if (this.Bill.ReversedStatus)
                    {
                        _dialogService.ShortAlert("已红冲单据不能操作"); return;
                    }

                    if (this.Bill.AuditedStatus)
                    {
                        _dialogService.ShortAlert("已审核单据不能操作!"); return;
                    }

                    if (!valid_ShipmentWareHouseId.IsValid)
                    {
                        _dialogService.ShortAlert(valid_ShipmentWareHouseId.Message[0]);
                        return;
                    }

                    if (!valid_IncomeWareHouseId.IsValid)
                    {
                        _dialogService.ShortAlert(valid_IncomeWareHouseId.Message[0]);
                        return;
                    }

                    if (Bill.ShipmentWareHouseId == Bill.IncomeWareHouseId)
                    {
                        _dialogService.ShortAlert("出入库不能相同!");
                        return;
                    }

                    //传入当前主库
                    this.WareHouse.Id   = Bill.ShipmentWareHouseId;
                    this.WareHouse.Name = Bill.ShipmentWareHouseName;

                    this.Filter.WareHouseId   = Bill.ShipmentWareHouseId;
                    this.Filter.WareHouseName = Bill.ShipmentWareHouseName;

                    //ShipmentWareHouseId
                    //IncomeWareHouseId

                    await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName),
                                             ("Bill", Bill),
                                             ("Filter", Filter),
                                             ("WareHouse", WareHouse),
                                             ("SerchKey", Filter.SerchKey));
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });

            //编辑商品
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                try
                {
                    if (this.Bill.ReversedStatus)
                    {
                        _dialogService.ShortAlert("已红冲单据不能操作");
                        return;
                    }

                    if (this.Bill.AuditedStatus)
                    {
                        _dialogService.ShortAlert("已审核单据不能操作");
                        return;
                    }

                    if (this.Bill.IsSubmitBill)
                    {
                        _dialogService.ShortAlert("已提交的单据不能编辑");
                        return;
                    }

                    if (item != null)
                    {
                        var product = ProductSeries.Select(p => p).Where(p => p.Id == item.ProductId).FirstOrDefault();
                        if (product != null)
                        {
                            product.UnitId   = item.UnitId;
                            product.Quantity = item.Quantity;
                            product.Remark   = item.Remark;
                            product.Subtotal = item.Subtotal;
                            product.UnitName = item.UnitName;
                            product.GUID     = item.GUID;
                            if (item.BigUnitId > 0)
                            {
                                product.bigOption.Name        = item.UnitName;
                                product.BigPriceUnit.Quantity = item.Quantity;
                                product.BigPriceUnit.UnitId   = item.BigUnitId ?? 0;
                                product.BigPriceUnit.Remark   = item.Remark;
                            }

                            if (item.SmallUnitId > 0)
                            {
                                product.bigOption.Name          = item.UnitName;
                                product.SmallPriceUnit.Quantity = item.Quantity;
                                product.SmallPriceUnit.UnitId   = item.SmallUnitId;
                                product.SmallPriceUnit.Remark   = item.Remark;
                            }

                            await this.NavigateAsync("EditAllocationProductPage", ("Product", product));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }

                this.Selecter = null;
            }, ex => _dialogService.ShortAlert(ex.ToString()))
            .DisposeWith(DeactivateWith);

            //提交单据
            this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ =>
            {
                return(await this.Access(AccessGranularityEnum.AllocationFormSave, async() =>
                {
                    if (this.Bill.ReversedStatus)
                    {
                        _dialogService.ShortAlert("已红冲单据不能操作");
                        return Unit.Default;
                    }

                    if (this.Bill.AuditedStatus)
                    {
                        _dialogService.ShortAlert("已审核单据不能操作");
                        return Unit.Default;
                    }

                    if (!valid_ShipmentWareHouseId.IsValid)
                    {
                        this.Alert(valid_ShipmentWareHouseId.Message[0]); return Unit.Default;
                    }
                    if (!valid_IncomeWareHouseId.IsValid)
                    {
                        this.Alert(valid_IncomeWareHouseId.Message[0]); return Unit.Default;
                    }
                    if (!valid_ProductCount.IsValid)
                    {
                        this.Alert(valid_ProductCount.Message[0]); return Unit.Default;
                    }

                    var zero = Bill.Items?.Where(s => s.Quantity == 0).Count() > 0;
                    if (zero)
                    {
                        this.Alert("存在数量为空的调拨商品!");
                        return Unit.Default;
                    }

                    var postMData = new AllocationUpdateModel()
                    {
                        BillNumber = Bill.BillNumber,
                        ShipmentWareHouseId = Bill.ShipmentWareHouseId,
                        IncomeWareHouseId = Bill.IncomeWareHouseId,
                        CreatedOnUtc = Bill.CreatedOnUtc,
                        AllocationByMinUnit = false,
                        Remark = Bill.Remark,
                        //商品项目
                        Items = Bill.Items?.ToList(),
                    };

                    ShowPrintBtn = true;
                    if (IsNeedShowPrompt)
                    {
                        var ok = await _dialogService.ShowConfirmAsync("是否保存并提交吗?", "", "确定", "取消");
                        if (!ok)
                        {
                            return Unit.Default;
                        }
                    }
                    IsNeedShowPrompt = true;

                    var gr = Bill.AuditedStatus;
                    return await SubmitAsync(postMData, Bill.Id, _wareHousesService.CreateOrUpdateAllocationbillAsync, async(result) =>
                    {
                        if (IsNeedPrint)
                        {
                            Bill.BillType = BillTypeEnum.AllocationBill;
                            await SelectPrint((AllocationBillModel)Bill.Clone());
                        }
                        IsNeedPrint = false;
                        Bill = new AllocationBillModel();
                        InitBill();
                    }, gr, token: new System.Threading.CancellationToken());
                }));
            },
                                                                                   this.IsValid());

            //存储记录
            this.SaveCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (!this.Bill.AuditedStatus && this.Bill.ShipmentWareHouseId != 0 && this.Bill.ShipmentWareHouseId != Settings.AllocationBill?.ShipmentWareHouseId)
                {
                    var ok = await _dialogService.ShowConfirmAsync("你是否要保存单据?", "提示", "确定", "取消");
                    if (ok)
                    {
                        if (!this.Bill.AuditedStatus)
                        {
                            Settings.AllocationBill = this.Bill;
                        }
                    }
                }
                await _navigationService.GoBackAsync();
            });

            //审核
            this.AuditingDataCommand = ReactiveCommand.CreateFromTask <object>(async _ =>
            {
                //是否具有审核权限
                await this.Access(AccessGranularityEnum.AllocationFormApproved);
                await SubmitAsync(Bill.Id, _wareHousesService.AuditingAsync, async(result) =>
                {
                    //红冲审核水印
                    this.Bill.AuditedStatus = true;

                    var _conn = App.Resolve <ILiteDbService <MessageInfo> >();
                    var ms    = await _conn.Table.FindByIdAsync(SelecterMessage.Id);
                    if (ms != null)
                    {
                        ms.IsRead = true;
                        await _conn.UpsertAsync(ms);
                    }
                }, token: new System.Threading.CancellationToken());
            }, this.WhenAny(x => x.Bill.Id, (x) => x.GetValue() > 0));


            //启用麦克风
            this.WhenAnyValue(x => x.EnableMicrophone)
            .Subscribe(async x =>
            {
                var micAccessGranted = await _microphoneService.GetPermissionsAsync();
                if (!micAccessGranted)
                {
                    this.Alert("请打开麦克风");
                }
            })
            .DisposeWith(this.DeactivateWith);
            //匹配声音
            this.RecognitionCommand = ReactiveCommand.Create(() =>
            {
                RecognitionSpeech((key) =>
                {
                    Filter.SerchKey = key;
                    ((ICommand)this.AddProductCommand)?.Execute(null);
                });
            });
            //切换语音助手
            this.SpeechCommand = ReactiveCommand.Create(() =>
            {
                if (IsFooterVisible)
                {
                    IsVisible       = true;
                    IsExpanded      = true;
                    IsFooterVisible = false;
                }
                else
                {
                    IsVisible       = false;
                    IsExpanded      = false;
                    IsFooterVisible = true;
                }
            });


            //工具栏打印
            this.PrintCommand = ReactiveCommand.Create(async() =>
            {
                await Print();
            });

            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //整单备注
                { MenuEnum.REMARK, (m, vm) => {
                      AllRemak((result) =>
                        {
                            Bill.Remark = result;
                        }, Bill.Remark);
                  } },
コード例 #2
0
        public TrackAllocationBillPageViewModel(INavigationService navigationService,
                                                IProductService productService,
                                                IUserService userService,
                                                ITerminalService terminalService,
                                                IWareHousesService wareHousesService,
                                                IAccountingService accountingService,
                                                IDialogService dialogService
                                                ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "装车调拨";

            InitBill();

            //验证
            var valid_ShipmentWareHouseId = this.ValidationRule(x => x.Bill.ShipmentWareHouseId, _isZero, "出货仓库未指定");
            var valid_IncomeWareHouseId   = this.ValidationRule(x => x.Bill.IncomeWareHouseId, _isZero, "入货仓库未指定");
            var valid_ProductCount        = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目");
            var valid_IsVieweBill         = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作");

            //添加商品
            this.AddProductCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (Bill.ShipmentWareHouseId == 0)
                {
                    _dialogService.ShortAlert(valid_ShipmentWareHouseId.Message[0]);
                    return;
                }

                if (Bill.IncomeWareHouseId == 0)
                {
                    _dialogService.ShortAlert(valid_IncomeWareHouseId.Message[0]);
                    return;
                }

                if (Bill.ShipmentWareHouseId == Bill.IncomeWareHouseId)
                {
                    _dialogService.ShortAlert("出入库不能相同!");
                    return;
                }
                //传入当前主库
                this.WareHouse.Id         = Bill.ShipmentWareHouseId;
                this.WareHouse.Name       = Bill.ShipmentWareHouseName;
                this.Filter.WareHouseId   = Bill.ShipmentWareHouseId;
                this.Filter.WareHouseName = Bill.ShipmentWareHouseName;

                await this.NavigateAsync("SelectProductPage",
                                         ("Reference", this.PageName),
                                         ("Bill", Bill),
                                         ("Filter", Filter),
                                         ("WareHouse", WareHouse),
                                         ("SerchKey", Filter.SerchKey));
            });

            //编辑商品
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                if (item != null)
                {
                    var product = ProductSeries.Select(p => p).Where(p => p.Id == item.ProductId).FirstOrDefault();
                    if (product != null)
                    {
                        product.UnitId   = item.UnitId;
                        product.Quantity = item.Quantity;
                        product.Remark   = item.Remark;
                        product.Subtotal = item.Subtotal;
                        product.UnitName = item.UnitName;

                        if (item.BigUnitId > 0)
                        {
                            product.bigOption.Name        = item.UnitName;
                            product.BigPriceUnit.Quantity = item.Quantity;
                            product.BigPriceUnit.UnitId   = item.BigUnitId ?? 0;
                            product.BigPriceUnit.Remark   = item.Remark;
                        }

                        if (item.SmallUnitId > 0)
                        {
                            product.bigOption.Name          = item.UnitName;
                            product.SmallPriceUnit.Quantity = item.Quantity;
                            product.SmallPriceUnit.UnitId   = item.SmallUnitId;
                            product.SmallPriceUnit.Remark   = item.Remark;
                        }

                        await this.NavigateAsync("EditAllocationProductPage", ("Product", product));
                    }
                }

                this.Selecter = null;
            }, ex => _dialogService.ShortAlert(ex.ToString()))
            .DisposeWith(DeactivateWith);

            //提交单据
            this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ =>
            {
                //await this.Access(AccessGranularityEnum.TrackSchedulingScheduling);
                return(await this.Access(AccessGranularityEnum.TrackSchedulingScheduling, async() =>
                {
                    if (!valid_ShipmentWareHouseId.IsValid)
                    {
                        this.Alert(valid_ShipmentWareHouseId.Message[0]); return Unit.Default;
                    }
                    if (!valid_IncomeWareHouseId.IsValid)
                    {
                        this.Alert(valid_IncomeWareHouseId.Message[0]); return Unit.Default;
                    }
                    if (!valid_ProductCount.IsValid)
                    {
                        this.Alert(valid_ProductCount.Message[0]); return Unit.Default;
                    }

                    var postMData = new AllocationUpdateModel()
                    {
                        BillNumber = this.Bill.BillNumber,
                        ShipmentWareHouseId = Bill.ShipmentWareHouseId,
                        IncomeWareHouseId = Bill.IncomeWareHouseId,
                        CreatedOnUtc = Bill.CreatedOnUtc,
                        AllocationByMinUnit = false,
                        Remark = Bill.Remark,
                        //商品项目
                        Items = Bill.Items?.Where(i => i.Quantity > 0).ToList(),
                    };

                    return await SubmitAsync(postMData, Bill.Id, _wareHousesService.CreateOrUpdateAllocationbillAsync, (result) =>
                    {
                        Bill = new AllocationBillModel();
                    });
                }));
            },
                                                                                   this.IsValid());

            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //整单备注
                { MenuEnum.REMARK, (m, vm) => {
                      AllRemak((result) =>
                        {
                            Bill.Remark = result;
                        }, Bill.Remark);
                  } },
コード例 #3
0
        /// <summary>
        /// 创建库存调拨单
        /// </summary>
        /// <param name="data"></param>
        /// <param name="billId"></param>
        /// <returns></returns>
        public async Task <APIResult <AllocationUpdateModel> > CreateOrUpdateAllocationbillAsync(AllocationUpdateModel data, int billId = 0, CancellationToken calToken = default)
        {
            try
            {
                int storeId = Settings.StoreId;
                int userId  = Settings.UserId;

                var api     = RefitServiceBuilder.Build <IWareHousesApi>(URL);
                var results = await _makeRequest.Start(api.CreateOrUpdateAllocationbillAsync(data, storeId, userId, billId, calToken), calToken);

                return(results);
            }
            catch (Exception e)
            {
                e.HandleException();
                return(null);
            }
        }