/// <summary> /// 提交单据 /// </summary> /// <param name="data"></param> /// <param name="billId"></param> /// <returns></returns> public async Task <APIResult <CostExpenditureUpdateModel> > CreateOrUpdateAsync(CostExpenditureUpdateModel data, int billId = 0, CancellationToken calToken = default) { try { int storeId = Settings.StoreId; int userId = Settings.UserId; var api = RefitServiceBuilder.Build <ICostExpenditureApi>(URL); var results = await _makeRequest.Start(api.CreateOrUpdateAsync(data, storeId, userId, billId, calToken), calToken); return(results); } catch (Exception e) { e.HandleException(); return(null); } }
public CostExpenditureBillPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, ICostExpenditureService costExpenditureService, ISaleBillService saleBillService, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "费用支出"; _costExpenditureService = costExpenditureService; _saleBillService = saleBillService; 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_ItemCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加费用项目"); var valid_SelectesCount = this.ValidationRule(x => x.PaymentMethods.Selectes.Count, _isZero, "请选择支付方式"); //提交单据 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { //await this.Access(AccessGranularityEnum.ExpenseExpenditureSave); return(await this.Access(AccessGranularityEnum.ExpenseExpenditureSave, async() => { if (this.Bill.ReversedStatus) { _dialogService.ShortAlert("已红冲单据不能操作"); return Unit.Default; } var postData = new CostExpenditureUpdateModel() { CustomerId = this.Bill.TerminalId, BillNumber = this.Bill.BillNumber, EmployeeId = Settings.UserId, OweCash = Bill.OweCash, Remark = Bill.Remark, Items = Bill.Items, Accounting = PaymentMethods.Selectes.Select(a => { return new AccountMaping() { AccountingOptionId = a.AccountingOptionId, CollectionAmount = a.CollectionAmount, Name = a.Name, BillId = 0, }; }).ToList(), }; return await SubmitAsync(postData, 0, _costExpenditureService.CreateOrUpdateAsync, (result) => { Bill = new CostExpenditureBillModel(); }, token: new System.Threading.CancellationToken()); })); }, this.IsValid()); //存储记录 this.SaveCommand = ReactiveCommand.Create <object>(async e => { if (!this.Bill.AuditedStatus && this.Bill.TerminalId != 0 && this.Bill.TerminalId != Settings.CostExpenditureBill?.TerminalId) { var ok = await _dialogService.ShowConfirmAsync("你是否要保存单据?", "提示", "确定", "取消"); if (ok) { if (!this.Bill.AuditedStatus) { Settings.CostExpenditureBill = this.Bill; } } } await _navigationService.GoBackAsync(); }); //编辑费用 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; } await this.NavigateAsync("AddCostPage", ("Terminaler", this.Terminal), ("Selecter", x)); this.Selecter = null; }) .DisposeWith(DeactivateWith); //添加费用 this.AddCostCommand = ReactiveCommand.Create <object>(async e => { if (!valid_TerminalId.IsValid) { _dialogService.ShortAlert(valid_TerminalId.Message[0]); return; } if (this.Bill.AuditedStatus) { _dialogService.ShortAlert("已审核单据不能操作!"); return; } await this.NavigateAsync("AddCostPage", ("Terminaler", this.Terminal)); }); //更多支付方式 this.MorePaymentCommand = ReactiveCommand.Create <object>(async e => { if (!valid_TerminalId.IsValid) { _dialogService.ShortAlert("客户未指定!"); return; } this.PaymentMethods.PreferentialAmountShowFiled = false; await this.NavigateAsync("PaymentMethodPage", ("PaymentMethods", this.PaymentMethods), ("BillType", this.BillType)); }); //审核 this.AuditingDataCommand = ReactiveCommand.Create <object>(async _ => { //是否具有审核权限 await this.Access(AccessGranularityEnum.ExpenseExpenditureApproved); await SubmitAsync(Bill.Id, _costExpenditureService.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.RefusedCommand = ReactiveCommand.CreateFromTask <object>(async _ => { try { var ok = await _dialogService.ShowConfirmAsync("你确定要放弃签收吗?", "", "确定", "取消"); if (ok) { var postMData = new DeliverySignUpdateModel() { //不关联调拨单 DispatchItemId = 0, DispatchBillId = 0, StoreId = Settings.StoreId, BillId = Bill.Id, BillTypeId = (int)BillTypeEnum.CostExpenditureBill, // Latitude = GlobalSettings.Latitude, Longitude = GlobalSettings.Longitude, Signature = "" }; await SubmitAsync(postMData, postMData.Id, _saleBillService.RefusedConfirmAsync, async(result) => { await _navigationService.GoBackAsync(); }); } } catch (Exception) { await _dialogService.ShowAlertAsync("拒签失败,服务器请求错误!", "", "取消"); } }); //签收 this.ConfirmCommand = ReactiveCommand.CreateFromTask <object>(async _ => { try { //如果签收距离>50 则计数 if (Terminal.CalcDistance() > 50) { var tmp = Settings.Abnormal; if (tmp != null) { tmp.Id = Terminal.Id; tmp.Counter += 1; Settings.Abnormal = tmp; } else { Settings.Abnormal = new AbnormalNum { Id = Terminal.Id, Counter = 1 }; } } var signature = await CrossDiaglogKit.Current.GetSignaturePadAsync("手写签名", "", Keyboard.Default, defaultValue: "", placeHolder: "请手写签名..."); if (!string.IsNullOrEmpty(signature)) { var postMData = new DeliverySignUpdateModel() { //不关联调拨单 DispatchItemId = 0, DispatchBillId = 0, StoreId = Settings.StoreId, BillId = Bill.Id, BillTypeId = (int)BillTypeEnum.CostExpenditureBill, // Latitude = GlobalSettings.Latitude, Longitude = GlobalSettings.Longitude, Signature = signature }; //如果终端异常签收大于5次,则拍照 //if (Settings.Abnormal.Counter > 5) //{ // await TakePhotograph((u, m) => // { // var photo = new RetainPhoto // { // DisplayPath = $"{GlobalSettings.FileCenterEndpoint}HRXHJS/document/image/" + u.Id + "" // }; // postMData.RetainPhotos.Add(photo); // }); //} if (Settings.Abnormal.Counter > 5 && postMData.RetainPhotos.Count == 0) { await _dialogService.ShowAlertAsync("拒绝操作,请留存拍照!", "", "取消"); return; } await SubmitAsync(postMData, postMData.Id, _saleBillService.DeliverySignConfirmAsync, async(result) => { await _navigationService.GoBackAsync(); }); } } catch (Exception) { await _dialogService.ShowAlertAsync("签收失败,服务器请求错误!", "", "取消"); } }); //绑定页面菜单 _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>(null, DoClear); } }, //销售备注 { MenuEnum.SALEREMARK, (m, vm) => { AllRemak((result) => { Bill.Remark = result; }, Bill.Remark); } } }); }