Exemple #1
0
        /// <summary>
        /// 提交单据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="billId"></param>
        /// <returns></returns>
        public async Task <APIResult <CostContractUpdateModel> > CreateOrUpdateAsync(CostContractUpdateModel data, int billId = 0, CancellationToken calToken = default)
        {
            try
            {
                int storeId = Settings.StoreId;
                int userId  = Settings.UserId;

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

                return(results);
            }
            catch (Exception e)
            {
                e.HandleException();
                return(null);
            }
        }
Exemple #2
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);
                  } }
            });
        }