Exemple #1
0
        public CostContractBillPageViewModel(INavigationService navigationService,
                                             IProductService productService,
                                             IUserService userService,
                                             ITerminalService terminalService,
                                             IWareHousesService wareHousesService,
                                             IAccountingService accountingService,
                                             ICostContractService costContractService,
                                             IDialogService dialogService) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "费用合同";

            _costContractService = costContractService;
            this.BillType        = BillTypeEnum.CostContractBill;

            InitBill();

            //验证
            var valid_IsReversed         = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作");
            var valid_IsAudited          = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作");
            var valid_TerminalId         = this.ValidationRule(x => x.Bill.CustomerId, _isZero, "客户未指定");
            var valid_AccountingOptionId = this.ValidationRule(x => x.Bill.AccountingOptionId, _isZero, "费用类型未指定");
            var valid_ItemCount          = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "合同项目为空,请先添加");


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

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

                if (x != null)
                {
                    var product = ProductSeries.Select(p => p).Where(p => p.ProductId == x.ProductId).FirstOrDefault();
                    if (product != null)
                    {
                        product.UnitId   = x.UnitId ?? 0;
                        product.Quantity = x.TotalQuantity;
                        product.Remark   = x.Remark;
                        product.UnitName = x.UnitName;

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

                        if (x.SmallUnitId > 0)
                        {
                            product.Id                      = x.Id;
                            product.bigOption.Name          = x.UnitName;
                            product.SmallPriceUnit.Quantity = x.TotalQuantity;
                            product.SmallPriceUnit.Remark   = x.Remark;
                            product.SmallPriceUnit.UnitId   = x.SmallUnitId ?? 0;
                        }

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

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

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

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

                    if (Bill.CustomerId == 0)
                    {
                        Bill.CustomerId = Settings.UserId;
                    }

                    var postData = new CostContractUpdateModel()
                    {
                        BillNumber = this.Bill.BillNumber,
                        EmployeeId = Settings.UserId,
                        CustomerId = Bill.CustomerId,
                        AccountingOptionId = Bill.AccountingOptionId,
                        Year = DateTime.Now.Year,
                        Month = DateTime.Now.Month,
                        ContractType = 1, //按单位量总计兑付
                        SaleRemark = Bill.SaleRemark,
                        Remark = Bill.Remark,
                        Items = Bill.Items
                    };

                    return await SubmitAsync(postData, Bill.Id, _costContractService.CreateOrUpdateAsync, (result) =>
                    {
                        Bill = new CostContractBillModel();
                    }, token: new System.Threading.CancellationToken());
                }));
            },
                                                                                   this.IsValid());

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

            //费用选择
            this.AccountingSelected = ReactiveCommand.Create <object>(async e =>
            {
                if (!valid_TerminalId.IsValid)
                {
                    this.Alert(valid_TerminalId.Message[0]); return;
                }
                await SelectCostAccounting((data) =>
                {
                    Bill.AccountingOptionId   = data.AccountingOptionId;
                    Bill.AccountingOptionName = data.Name;
                }, BillTypeEnum.CostContractBill);
            });

            //添加商品
            this.AddProductCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (!valid_TerminalId.IsValid)
                {
                    this.Alert(valid_TerminalId.Message[0]); return;
                }
                if (!valid_AccountingOptionId.IsValid)
                {
                    this.Alert(valid_AccountingOptionId.Message[0]); return;
                }
                if (!valid_IsAudited.IsValid)
                {
                    this.Alert(valid_IsAudited.Message[0]); return;
                }
                await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("SerchKey", Filter.SerchKey));
            });

            //审核
            this.AuditingDataCommand = ReactiveCommand.Create <object>(async _ =>
            {
                //是否具有审核权限
                await this.Access(AccessGranularityEnum.CostContractApproved);
                await SubmitAsync(Bill.Id, _costContractService.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);
                    }
                });
            }, this.WhenAny(x => x.Bill.Id, (x) => x.GetValue() > 0));

            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //整单备注
                { MenuEnum.REMARK, (m, vm) => {
                      AllRemak((result) => { Bill.Remark = result; }, Bill.Remark);
                  } },
                //清空单据
                { MenuEnum.CLEAR, (m, vm) => {
                      ClearBill <CostContractBillModel, CostContractItemModel>(Bill, DoClear);
                  } },
                //销售备注
                { MenuEnum.SALEREMARK, (m, vm) => {
                      AllRemak((result) => { Bill.SaleRemark = result; }, Bill.SaleRemark);
                  } }
            });
        }
Exemple #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);
                  } },
Exemple #3
0
        public ExchangeBillPageViewModel(INavigationService navigationService,
                                         IExchangeBillService exchangeBillService,
                                         IProductService productService,
                                         IUserService userService,
                                         ITerminalService terminalService,
                                         IWareHousesService wareHousesService,
                                         IAccountingService accountingService,
                                         IMicrophoneService microphoneService,
                                         ISaleBillService saleBillService,
                                         //IMapper mapper,
                                         IDialogService dialogService
                                         ) : base(navigationService,
                                                  productService, terminalService,
                                                  userService, wareHousesService,
                                                  accountingService, dialogService)
        {
            Title = "换货单";

            _saleBillService     = saleBillService;
            _exchangeBillService = exchangeBillService;
            _microphoneService   = microphoneService;
            //_mapper = mapper;

            InitBill();

            #region //配送日期指定
            var weekDays  = new List <WeekDay>();
            var startTime = DateTime.Now;
            var endTime   = DateTime.Now.AddDays(7);
            while (endTime.Subtract(startTime).Days > 0)
            {
                var wd = new WeekDay
                {
                    Wname           = $"{startTime:MM-dd} - {GlobalSettings.GetWeek(startTime.DayOfWeek.ToString())}",
                    Date            = startTime,
                    AMTimeRange     = $"09:00-12:00",
                    PMTimeRange     = $"15:00-21:00",
                    SelectedCommand = ReactiveCommand.Create <WeekDay>(r =>
                    {
                        this.WeekDays.ForEach(s => { s.Selected = false; });
                        r.Selected       = !r.Selected;
                        this.DeliverDate = r;
                        this.AMTimeRange = r.AMTimeRange;
                        this.PMTimeRange = r.PMTimeRange;
                    })
                };
                weekDays.Add(wd);
                startTime = startTime.AddDays(1);
            }
            var defaultWd = weekDays.FirstOrDefault();
            if (defaultWd != null)
            {
                defaultWd.Selected = true;
                this.AMTimeRange   = defaultWd.AMTimeRange;
                this.PMTimeRange   = defaultWd.PMTimeRange;
            }
            this.WeekDays = new ObservableCollection <WeekDay>(weekDays);

            #endregion

            //验证
            var valid_IsReversed     = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作");
            var valid_IsAudited      = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作");
            var valid_TerminalId     = this.ValidationRule(x => x.Bill.TerminalId, _isZero, "客户未指定");
            var valid_BusinessUserId = this.ValidationRule(x => x.Bill.DeliveryUserId, _isZero, "配送员未指定");
            var valid_WareHouseId    = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定");
            var valid_ProductCount   = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目");

            //添加商品
            this.AddProductCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (this.Bill.AuditedStatus && !this.ReferencePage.Equals("UnDeliveryPage"))
                {
                    _dialogService.ShortAlert("已审核单据不能操作");
                    return;
                }

                if (!valid_TerminalId.IsValid)
                {
                    _dialogService.ShortAlert(valid_TerminalId.Message[0]);
                    ((ICommand)CustomSelected)?.Execute(null);
                    return;
                }

                if (!valid_WareHouseId.IsValid)
                {
                    _dialogService.ShortAlert(valid_WareHouseId.Message[0]);
                    ((ICommand)StockSelected)?.Execute(null);
                    return;
                }

                if (!valid_BusinessUserId.IsValid)
                {
                    _dialogService.ShortAlert(valid_BusinessUserId.Message[0]);
                    ((ICommand)DeliverSelected)?.Execute(null);
                    return;
                }

                //转向商品选择
                await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName),
                                         ("WareHouse", WareHouse),
                                         ("TerminalId", Bill.TerminalId),
                                         ("Terminaler", this.Terminal),
                                         ("SerchKey", Filter.SerchKey));
            });

            //编辑商品
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                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.Price    = item.Price;
                        product.Amount   = item.Amount;
                        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;
                            product.BigPriceUnit.Amount   = item.Amount;
                            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.Amount   = item.Amount;
                            product.SmallPriceUnit.Remark   = item.Remark;
                        }

                        await this.NavigateAsync("EditProductPage", ("Product", product), ("Reference", PageName), ("Item", item), ("WareHouse", WareHouse));
                    }
                }

                this.Selecter = null;
            })
            .DisposeWith(DeactivateWith);

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

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

                    //结算方式
                    Bill.PayTypeId = 0;
                    Bill.PayTypeName = "";

                    if (Bill.BusinessUserId == 0)
                    {
                        Bill.BusinessUserId = Settings.UserId;
                    }

                    var postMData = new ExchangeBillUpdateModel()
                    {
                        BillNumber = this.Bill.BillNumber,
                        //客户
                        TerminalId = Bill.TerminalId,
                        //业务员
                        BusinessUserId = Bill.BusinessUserId,
                        //送货员
                        DeliveryUserId = Bill.DeliveryUserId,
                        //仓库
                        WareHouseId = Bill.WareHouseId,
                        //交易日期
                        TransactionDate = DateTime.Now,
                        //默认售价方式
                        DefaultAmountId = Settings.DefaultPricePlan,
                        //备注
                        Remark = Bill.Remark,
                        //优惠金额
                        PreferentialAmount = 0,
                        //优惠后金额
                        PreferentialEndAmount = 0,
                        //欠款金额
                        OweCash = 0,
                        //商品项目
                        Items = Bill.Items,
                        //收款账户
                        //预收款
                        AdvanceAmount = 0,
                        //预收款余额
                        AdvanceAmountBalance = 0,
                        //配送时间
                        DeliverDate = this.DeliverDate?.Date ?? DateTime.Now,
                        AMTimeRange = this.DeliverDate?.AMTimeRange,
                        PMTimeRange = this.DeliverDate?.PMTimeRange
                    };


                    return await SubmitAsync(postMData, Bill.Id, _exchangeBillService.CreateOrUpdateAsync, async(result) =>
                    {
                        BillId = result.Code;
                        //清空单据
                        Bill = new ExchangeBillModel();


                        if (IsVisit) //拜访时开单
                        {
                            //转向拜访界面
                            await this.NavigateAsync("VisitStorePage", ("BillTypeId", BillTypeEnum.ExchangeBill),
                                                     ("BillId", BillId),
                                                     ("Amount", Bill.SumAmount));
                        }
                    }, !IsVisit, token: new System.Threading.CancellationToken());
                }));
            },
Exemple #4
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);
                  } },
Exemple #5
0
        public ReturnOrderBillPageViewModel(INavigationService navigationService,
                                            IReturnReservationBillService returnReservationBillService,
                                            IProductService productService,
                                            IUserService userService,
                                            ITerminalService terminalService,
                                            IWareHousesService wareHousesService,
                                            IAccountingService accountingService,
                                            IMicrophoneService microphoneService,
                                            IDialogService dialogService) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "退货订单";

            _returnReservationBillService = returnReservationBillService;
            //_saleBillService = saleBillService;

            _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_TerminalId     = this.ValidationRule(x => x.Bill.TerminalId, _isZero, "客户未指定");
            var valid_BusinessUserId = this.ValidationRule(x => x.Bill.DeliveryUserId, _isZero, "配送员未指定");
            var valid_WareHouseId    = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定");
            var valid_ProductCount   = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目");
            var valid_SelectesCount  = this.ValidationRule(x => x.PaymentMethods.Selectes.Count, _isZero, "请选择支付方式");


            //初始化
            this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() =>
            {
                var whs = await _wareHousesService.GetWareHousesAsync(this.BillType, force: true);
                if (whs != null && whs.FirstOrDefault() != null)
                {
                    var wh = whs.FirstOrDefault();
                    if (Bill.WareHouseId == 0)
                    {
                        WareHouse        = wh;
                        Bill.WareHouseId = wh.Id;
                    }

                    if (string.IsNullOrEmpty(Bill.WareHouseName))
                    {
                        Bill.WareHouseName = wh.Name;
                    }

                    if (Bill.Id == 0 && Bill.DeliveryUserId == 0)
                    {
                        Bill.DeliveryUserId   = Settings.UserId;
                        Bill.DeliveryUserName = Settings.UserRealName;
                    }
                }
                InitPayment();
            }));

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

                if (!valid_TerminalId.IsValid)
                {
                    _dialogService.ShortAlert(valid_TerminalId.Message[0]);
                    ((ICommand)CustomSelected)?.Execute(null);
                    return;
                }

                if (!valid_WareHouseId.IsValid || WareHouse == null)
                {
                    _dialogService.ShortAlert(valid_WareHouseId.Message[0]);
                    ((ICommand)StockSelected)?.Execute(null);
                    return;
                }

                if (!valid_BusinessUserId.IsValid)
                {
                    _dialogService.ShortAlert(valid_BusinessUserId.Message[0]);
                    ((ICommand)DeliverSelected)?.Execute(null);
                    return;
                }

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

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

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

                //已提交未审核的可以编辑
                if (this.Bill.IsSubmitBill && !this.Bill.AuditedStatus)
                {
                    _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.Price    = item.Price;
                        product.Amount   = item.Amount;
                        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;
                            product.BigPriceUnit.Amount   = item.Amount;
                            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.Amount   = item.Amount;
                            product.SmallPriceUnit.Remark   = item.Remark;
                        }
                        await this.NavigateAsync("EditProductPage", ("Product", product), ("Reference", PageName), ("Item", item), ("WareHouse", WareHouse));
                    }
                }

                this.Selecter = null;
            })
            .DisposeWith(DeactivateWith);

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

                    if (this.Bill.AuditedStatus)
                    {
                        _dialogService.ShortAlert("已审核单据不能操作");
                        return Unit.Default;
                    }
                    if (IsNeedShowPrompt)
                    {
                        var ok = await _dialogService.ShowConfirmAsync("是否保存并提交吗?", "", "确定", "取消");
                        if (!ok)
                        {
                            return Unit.Default;
                        }
                    }
                    IsNeedShowPrompt = true;

                    if (Bill.BusinessUserId == 0)
                    {
                        Bill.BusinessUserId = Settings.UserId;
                    }

                    var postMData = new ReturnReservationBillUpdateModel()
                    {
                        BillNumber = this.Bill.BillNumber,
                        //客户
                        TerminalId = Bill.TerminalId,
                        //业务员
                        BusinessUserId = Bill.BusinessUserId,
                        //仓库
                        WareHouseId = Bill.WareHouseId,
                        //交易日期
                        TransactionDate = DateTime.Now,
                        //默认售价方式
                        DefaultAmountId = Settings.DefaultPricePlan,
                        //备注
                        Remark = Bill.Remark,
                        //优惠金额
                        PreferentialAmount = Bill.PreferentialAmount,
                        //优惠后金额
                        PreferentialEndAmount = Bill.SumAmount - Bill.PreferentialAmount,
                        //欠款金额
                        OweCash = Bill.OweCash,
                        //商品项目
                        Items = Bill.Items?.Where(i => i.Quantity > 0).ToList(),
                        //收款账户
                        Accounting = PaymentMethods.Selectes.Select(a =>
                        {
                            return new AccountMaping()
                            {
                                AccountingOptionId = a.AccountingOptionId,
                                CollectionAmount = a.CollectionAmount,
                                Name = a.Name,
                                BillId = 0,
                            };
                        }).ToList()
                    };

                    return await SubmitAsync(postMData, Bill.Id, _returnReservationBillService.CreateOrUpdateAsync, async(result) =>
                    {
                        if (IsNeedPrint)
                        {
                            Bill.BillType = BillTypeEnum.SaleBill;
                            await SelectPrint((ReturnReservationBillModel)Bill.Clone());
                        }
                        IsNeedPrint = false;

                        BillId = result.Code;
                        ClearBillCache();
                        PaymentMethods.Selectes.Clear();
                        InitPayment();
                        if (IsVisit)
                        {
                            //转向拜访界面
                            //await this.NavigateAsync("VisitStorePage", ("BillTypeId",BillTypeEnum.ReturnReservationBill),("BillId", BillId),("Amount", Bill.SumAmount));
                            await _navigationService.GoBackAsync(("BillTypeId", BillTypeEnum.ReturnReservationBill), ("BillId", BillId), ("Amount", Bill.SumAmount));
                        }
                    }, token: new System.Threading.CancellationToken());
                }));
            },
Exemple #6
0
        public SelectProductPageViewModel(INavigationService navigationService,
                                          IProductService productService,
                                          IDialogService dialogService) : base(navigationService, dialogService)
        {
            Title = "选择商品";

            _navigationService = navigationService;
            _dialogService     = dialogService;
            _productService    = productService;

            //只显库存商品
            this.WhenAnyValue(x => x.UsableQuantity)
            .Skip(1)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
                this.ForceRefresh = true;
            }).DisposeWith(DeactivateWith);

            //我的收藏
            this.WhenAnyValue(x => x.UsableFavorite)
            .Skip(1)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
                this.ForceRefresh = true;
            }).DisposeWith(DeactivateWith);

            //搜索
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Where(s => !string.IsNullOrEmpty(s))
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler)
            .Subscribe(s =>
            {
                ((ICommand)SerchCommand)?.Execute(s);
            }).DisposeWith(DeactivateWith);

            this.SerchCommand = ReactiveCommand.Create <string>(e =>
            {
                if (string.IsNullOrEmpty(Filter.SerchKey))
                {
                    this.Alert("请输入关键字!");
                    return;
                }
                ((ICommand)Load)?.Execute(null);
            });

            //Load
            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    ItemTreshold   = 1;
                    DataVewEnable  = false;
                    NullViewEnable = true;

                    var items = await GetProductsPage(0, 50);
                    if (items != null && items.Any())
                    {
                        //清除列表
                        ProductSeries?.Clear();
                        foreach (var item in items)
                        {
                            if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0)
                            {
                                ProductSeries.Add(item);
                            }
                        }
                    }
                }
                catch (Exception ex) { Crashes.TrackError(ex); }
                finally
                {
                    DataVewEnable  = true;
                    NullViewEnable = false;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                using (var dig = UserDialogs.Instance.Loading("加载中..."))
                {
                    try
                    {
                        int pageIdex         = ProductSeries.Count / 50;
                        var items            = await GetProductsPage(pageIdex, PageSize);
                        var previousLastItem = ProductSeries.Last();
                        if (items != null)
                        {
                            foreach (var item in items)
                            {
                                if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0)
                                {
                                    ProductSeries.Add(item);
                                }
                            }

                            if (items.Count() == 0 || items.Count() == ProductSeries.Count)
                            {
                                ItemTreshold = -1;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        ItemTreshold = -1;
                    }
                }
            }, this.WhenAny(x => x.ProductSeries, x => x.GetValue().Count > 0));


            //初始类别
            this.InitCatagory = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    var result = await _productService.GetAllCategoriesAsync(true, new System.Threading.CancellationToken());
                    if (result != null && result.Any())
                    {
                        var categories = result.ToList();
                        if (categories != null && categories.Any())
                        {
                            foreach (var op in categories)
                            {
                                op.SelectedCommand = ReactiveCommand.Create <int>(r =>
                                {
                                    op.Selected = !op.Selected;
                                });
                            }
                            this.BindCategories = new ObservableCollection <CategoryModel>(categories);
                        }
                    }
                }
                catch (Exception ex) { Crashes.TrackError(ex); }
            });
            //选择类别
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(x =>
            {
                if (x != null)
                {
                    Filter.CatagoryIds = new int[] { x.Id };
                    this.ForceRefresh  = true;

                    foreach (var op in this.BindCategories)
                    {
                        op.Selected = false;
                    }

                    x.Selected = !x.Selected;

                    ((ICommand)Load)?.Execute(null);
                }
                Selecter = null;
            })
            .DisposeWith(DeactivateWith);


            this.WhenAnyValue(x => x.ReferencePage)
            .Where(x => !string.IsNullOrEmpty(x))
            .Subscribe(x =>
            {
                this.ShowStockQty = !(x.Equals("InventoryOPBillPage") || x.Equals("InventoryBillPage"));
            }).DisposeWith(DeactivateWith);

            //选择礼品
            this.SelectGiftsCommand = ReactiveCommand.Create(async() =>
            {
                await this.NavigateAsync("SelectGiftsPage", ("WareHouse", WareHouse), ("Terminaler", this.Terminal));
            });
            //保存选择商品
            this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object>(async e =>
            {
                if (string.IsNullOrEmpty(ReferencePage))
                {
                    await _navigationService.GoBackAsync();
                    return;
                }

                var products = ProductSeries.Select(p => p).Where(p => p.Selected == true).ToList();
                if (products.Count == 0)
                {
                    this.Alert("请选择商品项目");
                    return;
                }

                if (ReferencePage == nameof(InventoryReportPage))
                {
                    //添加上报商品
                    await this.NavigateAsync(nameof(AddReportProductPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(AllocationBillPage))
                {
                    if (this.Bill == null)
                    {
                        this.Alert("单据不能关联,请确保参数");
                        return;
                    }

                    //添加调拨商品
                    await this.NavigateAsync(nameof(AddAllocationProductPage),
                                             ("Bill", Bill),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(BackStockBillPage))
                {
                    //添加回库调拨单商品
                    await this.NavigateAsync(nameof(AddBackStockBillPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(TrackAllocationBillPage))
                {
                    //添加回库调拨单商品
                    await this.NavigateAsync(nameof(AddAllocationProductPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(CostContractBillPage))
                {
                    //添加合同商品
                    await this.NavigateAsync(nameof(AddCostContractProductPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(InventoryOPBillPage) || ReferencePage == nameof(InventoryBillPage))
                {
                    //追加商品
                    if (TempProductSeries.Any())
                    {
                        var temps = TempProductSeries.ToList();
                        foreach (var tp in temps)
                        {
                            if (products.Where(s => s.ProductId == tp.ProductId).Count() == 0)
                            {
                                products.Add(tp);
                            }
                        }
                    }

                    //添加盘点商品
                    await this.NavigateAsync(nameof(AddInventoryProductPage),
                                             ("Reference", ReferencePage),
                                             ("WareHouse", WareHouse),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(FilterPage))
                {
                    //过滤
                    await _navigationService.GoBackAsync(
                        ("Filter", Filter),
                        ("Reference", ReferencePage),
                        ("Products", products));
                }
                else if (ReferencePage == nameof(PurchaseOrderBillPage))
                {
                    //添加采购商品
                    await this.NavigateAsync(nameof(AddPurchaseProductPage),
                                             ("WareHouse", WareHouse),
                                             ("Reference", ReferencePage),
                                             ("Products", products)
                                             );
                }
                else if (ReferencePage == nameof(ExchangeBillPage))
                {
                    //添加换货商品
                    await this.NavigateAsync(nameof(AddExchangeProductPage),
                                             ("WareHouse", WareHouse),
                                             ("Reference", ReferencePage),
                                             ("Products", products)
                                             );
                }
                else
                {
                    //添加单据商品
                    await this.NavigateAsync($"{nameof(AddProductPage)}",
                                             ("WareHouse", WareHouse),
                                             ("Reference", ReferencePage),
                                             ("Products", products)
                                             );
                }
            });
            //收藏
            this.FavoriteCommand = ReactiveCommand.Create <ProductModel>(p =>
            {
                try
                {
                    var ps = Settings.FavoriteProducts;
                    this.Filter.SerchKey = "";
                    if (!p.Favorited)
                    {
                        if (!ps.Select(s => s.ProductId).Contains(p.ProductId))
                        {
                            p.Favorited = true;
                            ps.Add(p);
                            Settings.FavoriteProducts = ps;
                            _dialogService.ShortAlert("收藏成功!");
                        }
                    }
                    else
                    {
                        var cur = ps.Where(s => s.ProductId == p.ProductId).FirstOrDefault();
                        if (cur != null)
                        {
                            cur.Favorited = false;
                            p.Favorited   = false;
                            ps.Remove(cur);
                            Settings.FavoriteProducts = ps;
                            _dialogService.ShortAlert("收藏已移除!");
                        }
                    }

                    if (UsableFavorite)
                    {
                        if (ProductSeries != null && ProductSeries.Any())
                        {
                            var reload = ProductSeries.Where(s => s.Favorited == true).ToList();
                            if (reload != null && reload.Any())
                            {
                                this.ProductSeries = new ObservableCollection <ProductModel>(reload);
                            }
                            else
                            {
                                this.UsableFavorite = false;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });

            this.BindBusyCommand(Load);

            this.Load.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.ItemTresholdReachedCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.InitCatagory.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.SelectGiftsCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.SubmitDataCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.FavoriteCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
        }
Exemple #7
0
        public PurchaseOrderBillPageViewModel(INavigationService navigationService,
                                              IProductService productService,
                                              IUserService userService,
                                              ITerminalService terminalService,
                                              IWareHousesService wareHousesService,
                                              IAccountingService accountingService,
                                              IPurchaseBillService purchaseBillService,
                                              IManufacturerService manufacturerService,
                                              IMicrophoneService microphoneService,
                                              IDialogService dialogService
                                              ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "采购单";

            _purchaseBillService = purchaseBillService;
            _manufacturerService = manufacturerService;

            _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_ManufacturerId = this.ValidationRule(x => x.Bill.ManufacturerId, _isZero, "供应商未指定");
            var valid_WareHouseId    = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定");
            var valid_ProductCount   = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目");
            var valid_SelectesCount  = this.ValidationRule(x => x.PaymentMethods.Selectes.Count, _isZero, "请选择支付方式");


            //初始化
            this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() =>
            {
                var whs = await _wareHousesService.GetWareHousesAsync(this.BillType, force: true);
                if (whs != null && whs.FirstOrDefault() != null)
                {
                    var wh = whs.FirstOrDefault();
                    if (Bill.WareHouseId == 0)
                    {
                        WareHouse        = wh;
                        Bill.WareHouseId = wh.Id;
                    }

                    if (string.IsNullOrEmpty(Bill.WareHouseName))
                    {
                        Bill.WareHouseName = wh.Name;
                    }
                }

                var result = await _purchaseBillService.GetInitDataAsync(calToken: new System.Threading.CancellationToken());
                if (result != null)
                {
                    var defaultAccs = result.PurchaseBillAccountings.Select(s => new AccountingModel()
                    {
                        Default              = true,
                        AccountingOptionId   = s.AccountingOptionId,
                        AccountingOptionName = s.AccountingOptionName,
                        AccountCodeTypeId    = s.AccountCodeTypeId,
                        Name = s.Name
                    }).ToList();

                    PaymentMethods.Selectes = new ObservableCollection <AccountingModel>(defaultAccs);
                }
            }));

            //提交单据
            this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ =>
            {
                //await this.Access(AccessGranularityEnum.PurchaseBillsSave);

                return(await this.Access(AccessGranularityEnum.PurchaseBillsSave, async() =>
                {
                    if (this.Bill.ReversedStatus)
                    {
                        _dialogService.ShortAlert("已红冲单据不能操作");
                        return Unit.Default;
                    }

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

                    var dateTime = UtcHelper.ConvertDateTimeInt(DateTime.Now.ToUniversalTime());

                    if (Bill.BusinessUserId == 0)
                    {
                        Bill.BusinessUserId = Settings.UserId;
                    }

                    var postMData = new PurchaseItemUpdateModel()
                    {
                        BillNumber = this.Bill.BillNumber,
                        //供应商
                        ManufacturerId = Bill.ManufacturerId,
                        //业务员
                        BusinessUserId = Bill.BusinessUserId,
                        //仓库
                        WareHouseId = Bill.WareHouseId,
                        //交易日期
                        //TransactionDate = DateTime.Now,
                        TransactionDate = dateTime,
                        //按最小单位采购
                        IsMinUnitPurchase = true,
                        //备注
                        Remark = Bill.Remark,
                        //优惠金额
                        PreferentialAmount = Bill.PreferentialAmount,
                        //优惠后金额
                        PreferentialEndAmount = Bill.SumAmount - Bill.PreferentialAmount,
                        //欠款金额
                        OweCash = Bill.OweCash,
                        //商品项目(保存量大于零的商品)
                        Items = Bill.Items?.Where(i => i.Quantity > 0).ToList(),
                        //收款账户
                        Accounting = PaymentMethods.Selectes.Select(a =>
                        {
                            return new AccountMaping()
                            {
                                AccountingOptionId = a.AccountingOptionId,
                                CollectionAmount = a.CollectionAmount,
                                Name = a.Name,
                                BillId = 0,
                            };
                        }).ToList()
                    };

                    return await SubmitAsync(postMData, Bill.Id, _purchaseBillService.CreateOrUpdateAsync, (result) =>
                    {
                        Bill = new PurchaseBillModel();
                    }, token: new System.Threading.CancellationToken());
                }));
            },
                                                                                   this.IsValid());

            //存储记录
            this.SaveCommand = ReactiveCommand.Create <object>(async e =>
            {
                var c1 = this.Bill.ManufacturerId != 0 && this.Bill.ManufacturerId != (Settings.PurchaseBill?.ManufacturerId ?? 0);
                var c3 = this.Bill.WareHouseId != 0 && this.Bill.WareHouseId != (Settings.PurchaseBill?.WareHouseId ?? 0);
                var c4 = this.Bill.Items?.Count != (Settings.PurchaseBill?.Items?.Count ?? 0);
                if (!this.Bill.AuditedStatus && (c1 || c3 || c4))
                {
                    if (!this.Bill.AuditedStatus && !this.Bill.IsSubmitBill)
                    {
                        var ok = await _dialogService.ShowConfirmAsync("你是否要保存单据?", "提示", "确定", "取消");
                        if (ok)
                        {
                            Settings.PurchaseBill = this.Bill;
                        }
                        else
                        {
                            await _navigationService.GoBackAsync();
                        }
                    }
                }
                else
                {
                    await _navigationService.GoBackAsync();
                }
            });

            //商品编辑
            this.ItemSelectedCommand = ReactiveCommand.Create <CollectionView>(async e =>
            {
                if (this.Bill.ReversedStatus)
                {
                    _dialogService.ShortAlert("已红冲单据不能操作");
                    return;
                }

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

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

                if (e.SelectedItem != null)
                {
                    var item = Selecter;
                    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.Price    = item.Price;
                            product.Amount   = item.Amount;
                            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.Amount   = item.Amount;
                                product.BigPriceUnit.Remark   = item.Remark;
                            }

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

                            await this.NavigateAsync("EditProductPage", ("Product", product), ("Reference", PageName), ("Item", item), ("WareHouse", WareHouse));
                        }
                    }
                }
            });

            //添加商品
            this.AddProductCommand = ReactiveCommand.Create <object>(async e =>
            {
                if (!valid_IsAudited.IsValid)
                {
                    _dialogService.ShortAlert("已审核单据不能操作!");
                    return;
                }

                if (!valid_ManufacturerId.IsValid)
                {
                    _dialogService.ShortAlert("请选择供应商!");
                    ((ICommand)ManufacturerSelected)?.Execute(null);
                    return;
                }

                if (!valid_WareHouseId.IsValid || WareHouse == null)
                {
                    _dialogService.ShortAlert("请选择仓库!");
                    ((ICommand)StockSelected)?.Execute(null);
                    return;
                }

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

            //审核
            this.AuditingDataCommand = ReactiveCommand.CreateFromTask <object>(async _ =>
            {
                //是否具有审核权限
                await this.Access(AccessGranularityEnum.PurchaseBillsApproved);
                await SubmitAsync(Bill.Id, _purchaseBillService.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);
                    }
                });
            }, 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(DeactivateWith);
            //匹配声音
            this.RecognitionCommand = ReactiveCommand.Create(() =>
            {
                if (!valid_ManufacturerId.IsValid)
                {
                    _dialogService.ShortAlert("请选择供应商!");
                    return;
                }

                if (!valid_WareHouseId.IsValid)
                {
                    _dialogService.ShortAlert("请选择仓库!");
                    return;
                }

                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() =>
            {
                if (Bill.Items.Count == 0)
                {
                    Alert("请添加商品项目");
                    return;
                }
                Bill.BillType = BillTypeEnum.PurchaseBill;
                await SelectPrint(Bill);
            });

            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //支付方式
                { MenuEnum.PAY, (m, vm) => {
                      if (Bill.SumAmount == 0)
                      {
                          this.Alert("请添加商品项目!"); return;
                      }
                      PaymentMethodBaseModel payments = this.PaymentMethods;
                      SelectPaymentMethods(("PaymentMethods", payments),
                                           ("TBalance", this.TBalance),
                                           ("BillType", this.BillType),
                                           ("Reference", PageName));
                  } },