public override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); try { if (parameters.ContainsKey("Bill")) { if (ReferencePage.Equals("AllocationBillPage")) { this.ShowGift = false; parameters.TryGetValue("Bill", out AllocationBillModel bill); if (bill != null) { this.Bill = bill; } } } if (ReferencePage == "InventoryOPBillPage") { ShowStockQty = false; ShowGift = false; } if (ReferencePage == "PurchaseOrderBillPage") { ShowStockQty = true; ShowGift = false; } //盘点单 if (ReferencePage == "InventoryOPBillPage") { ProductSeries.ToList().ForEach(p => { TempProductSeries.Add(p); }); } } catch (Exception ex) { Crashes.TrackError(ex); } }
public override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); try { if (parameters.ContainsKey("Products")) { parameters.TryGetValue("Products", out List <ProductModel> products); if (products != null) { ProductSeries = new ObservableCollection <ProductModel>(products); } } if (parameters.ContainsKey("Bill")) { if (ReferencePage.Equals("AllocationBillPage")) { parameters.TryGetValue("Bill", out AllocationBillModel Bill); if (Bill != null) { foreach (var p in ProductSeries.ToList()) { var outs = p.StockQuantities.Where(q => q.WareHouseId == Bill.ShipmentWareHouseId).FirstOrDefault(); var ins = p.StockQuantities.Where(q => q.WareHouseId == Bill.IncomeWareHouseId).FirstOrDefault(); p.ShipmentUsableQuantity = outs != null ? outs.UsableQuantity : 0; p.IncomeUsableQuantity = ins != null ? ins.UsableQuantity : 0; } } } } } catch (Exception ex) { Crashes.TrackError(ex); } }
public AddProductPageViewModel( INavigationService navigationService, IDialogService dialogService ) : base(navigationService, dialogService) { Title = "添加商品"; CompanySetting = JsonConvert.DeserializeObject <CompanySettingModel>(Settings.CompanySetting); //更改重算 this.BigEntryUnfocused = ReactiveCommand.Create <ProductModel>((p) => { CalcChanged(p, 0); }); this.SmallEntryUnfocused = ReactiveCommand.Create <ProductModel>((p) => { CalcChanged(p, 1); }); //选择价格 this.SmallPriceSelected = ReactiveCommand.Create <int>((pid) => { CalcSmallPrice(pid); }); this.BigPriceSelected = ReactiveCommand.Create <int>((pid) => { CalcBigPrice(pid); }); //保存 this.SaveCommand = ReactiveCommand.Create(async() => { try { bool vaildQuantity = false; bool vaildBigPrice = false; bool vaildSmallPrice = false; bool vaildBigQuantity = false; bool vaildSmallQuantity = false; bool vaildGiftQuantity = false; if (!string.IsNullOrEmpty(ReferencePage)) { //数量 ProductSeries.ToList().ForEach(p => { vaildQuantity = (p.BigPriceUnit.Quantity == 0 || p.SmallPriceUnit.Quantity == 0); if (vaildQuantity) { return; } }); //赠送 ProductSeries.ToList().ForEach(p => { vaildGiftQuantity = (p.GiveProduct.BigUnitQuantity == 0 && p.GiveProduct.SmallUnitQuantity == 0); if (vaildGiftQuantity) { return; } }); //大单位 ProductSeries.ToList().ForEach(p => { vaildBigPrice = (p.BigPriceUnit.Quantity > 0 && (p.BigPriceUnit?.Price == null || p.BigPriceUnit?.Price < 0)); if (vaildBigPrice) { return; } }); ProductSeries.ToList().ForEach(p => { vaildBigQuantity = (p.BigPriceUnit.Quantity <= 0); if (vaildBigQuantity) { return; } }); //小单位 ProductSeries.ToList().ForEach(p => { vaildSmallPrice = (p.SmallPriceUnit.Quantity > 0 && (p.SmallPriceUnit?.Price == null || p.SmallPriceUnit?.Price < 0)); if (vaildSmallPrice) { return; } }); ProductSeries.ToList().ForEach(p => { vaildSmallQuantity = (p.SmallPriceUnit.Quantity <= 0); if (vaildSmallQuantity) { return; } }); if (vaildGiftQuantity) { if (vaildBigQuantity && vaildSmallQuantity) { this.Alert("商品数量不能为空"); return; } } if (vaildBigQuantity && !vaildBigPrice && !vaildQuantity) { this.Alert("商品大单位数量不能为空"); return; } if (vaildBigPrice && !vaildBigQuantity && !vaildQuantity) { this.Alert("商品大单位价格不能为空"); return; } if (vaildSmallQuantity && !vaildSmallPrice && !vaildQuantity) { this.Alert("商品小单位数量不能为空"); return; } if (vaildSmallPrice && !vaildSmallQuantity && !vaildQuantity) { this.Alert("商品小单位价格不能为空"); return; } var products = ProductSeries.Where(s => s.BigPriceUnit.Quantity > 0 && s.BigPriceUnit.Price >= 0 || s.SmallPriceUnit.Quantity > 0 && s.SmallPriceUnit.Price >= 0 || s.GiveProduct.BigUnitQuantity > 0 || s.GiveProduct.SmallUnitQuantity >= 0).ToList(); //转向引用页 var redirectPage = $"../../"; await this.NavigateAsync(redirectPage, ("ProductSeries", products)); } } catch (Exception ex) { Crashes.TrackError(ex); } }); //移除商品 this.RemoveCommend = ReactiveCommand.Create <int>(async(pid) => { try { var porductId = pid; var products = ProductSeries; var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); if (product != null) { products.Remove(product); } ProductSeries = new ObservableCollection <ProductModel>(products); if (products.Count == 0) { await _navigationService.GoBackAsync(); } } catch (Exception ex) { Crashes.TrackError(ex); } }); //拷贝商品 this.CopyCommend = ReactiveCommand.Create <int>((pid) => { try { var porductId = pid; var products = ProductSeries; var product = ProductSeries.Where(p => p.Id == porductId).Select(p => p).FirstOrDefault(); if (product != null) { var newModel = new ProductModel { Id = product.Id, ProductId = product.Id, ProductName = product.ProductName, Name = product.Name, UnitId = product.UnitId, Quantity = product.Quantity, Price = product.Price, Amount = product.Amount, Remark = product.Remark, Subtotal = product.Subtotal, StockQty = product.StockQty, UnitConversion = product.UnitConversion, UnitName = product.UnitName, Units = product.Units, BigPriceUnit = new PriceUnit() { Amount = product.BigPriceUnit.Amount, Price = product.BigPriceUnit.Price, Quantity = product.BigPriceUnit.Quantity, Remark = product.BigPriceUnit.Remark, UnitId = product.BigPriceUnit.UnitId, UnitName = product.BigPriceUnit.UnitName }, SmallPriceUnit = new PriceUnit() { Amount = product.SmallPriceUnit.Amount, Price = product.SmallPriceUnit.Price, Quantity = product.SmallPriceUnit.Quantity, Remark = product.SmallPriceUnit.Remark, UnitId = product.SmallPriceUnit.UnitId, UnitName = product.SmallPriceUnit.UnitName } }; newModel.BigPriceUnit.UnitId = product.BigUnitId ?? 0; newModel.SmallPriceUnit.UnitId = product.SmallUnitId ?? 0; products.Add(newModel); } ProductSeries = new ObservableCollection <ProductModel>(products); } catch (Exception ex) { Crashes.TrackError(ex); } }); }
public InventoryOPBillPageViewModel(INavigationService navigationService, IProductService productService, IUserService userService, ITerminalService terminalService, IWareHousesService wareHousesService, IAccountingService accountingService, IInventoryService inventoryService, IDialogService dialogService ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService) { Title = "盘点单"; _inventoryService = inventoryService; this.BillType = BillTypeEnum.InventoryPartTaskBill; this.Bill = new InventoryPartTaskBillModel() { BillTypeId = (int)this.BillType, InventoryPerson = Settings.UserId, BillNumber = CommonHelper.GetBillNumber(CommonHelper.GetEnumDescription(BillType).Split(',')[1], Settings.StoreId) }; //验证 var valid_IsReversed = this.ValidationRule(x => x.Bill.ReversedStatus, _isBool, "已红冲单据不能操作"); var valid_IsAudited = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_WareHouseId = this.ValidationRule(x => x.Bill.WareHouseId, _isZero, "仓库未指定"); var valid_InventoryPerson = this.ValidationRule(x => x.Bill.InventoryPerson, _isZero, "盘点人未指定"); var valid_IsVieweBill = this.ValidationRule(x => x.Bill.AuditedStatus, _isBool, "已审核单据不能操作"); var valid_ProductCount = this.ValidationRule(x => x.Bill.Items.Count, _isZero, "请添加商品项目"); //初始化 this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { var result = await _inventoryService.GetInventoryPartTaskBillAsync(Bill.Id, calToken: new System.Threading.CancellationToken()); if (result != null) { UpdateUI(result); } })); //删除选择 this.DeleteCommand = ReactiveCommand.Create <object>(e => { int productId = (int)e; var product = Bill.Items?.Select(p => p).Where(p => p.ProductId == productId).FirstOrDefault(); if (product != null) { Bill.Items?.Remove(product); var lists = Bill.Items; Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }); //添加商品 this.AddProductCommand = ReactiveCommand.Create <object>(async e => { if (!valid_WareHouseId.IsValid) { this.Alert(valid_WareHouseId.Message[0]); return; } if (!valid_InventoryPerson.IsValid) { this.Alert(valid_InventoryPerson.Message[0]); return; } if (!valid_IsVieweBill.IsValid) { this.Alert(valid_IsVieweBill.Message[0]); return; } await this.NavigateAsync("SelectProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("Products", ProductSeries.ToList())); }); //选择仓库 this.StockSelected = ReactiveCommand.Create <object>(async e => { await SelectStock(async(result) => { if (result != null && WareHouse != null && Bill != null) { WareHouse.Id = result.Id; WareHouse.Name = result.Column; Bill.WareHouseId = result.Id; Bill.WareHouseName = result.Column; var pendings = await _inventoryService.CheckInventoryAsync(result.Id, new System.Threading.CancellationToken()); if (pendings != null && pendings.Any()) { WareHouse.Id = 0; WareHouse.Name = ""; Bill.WareHouseId = 0; Bill.WareHouseName = ""; this.Alert("库存正在盘点中,不能在生成盘点单!"); return; } } }, BillTypeEnum.InventoryAllTaskBill); }); //保存盘点 this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object, Unit>(async _ => { return(await this.Access(AccessGranularityEnum.InventoryAllSave, async() => { if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return Unit.Default; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return Unit.Default; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return Unit.Default; } var postMData = new InventoryPartTaskUpdateModel() { BillNumber = this.Bill.BillNumber, InventoryPerson = Bill.InventoryPerson, WareHouseId = Bill.WareHouseId, InventoryDate = DateTime.Now, Items = Bill.Items }; var confirm = await _dialogService.ShowConfirmAsync("确认保存盘点吗?", okText: "确定", cancelText: "取消"); if (confirm) { return await SubmitAsync(postMData, Bill.Id, _inventoryService.CreateOrUpdateAsync, (result) => { Bill.Id = result.Return; Bill.InventoryPerson = postMData.InventoryPerson; Bill.WareHouseId = postMData.WareHouseId; }, false, token: new System.Threading.CancellationToken()); } else { return Unit.Default; } })); }, this.IsValid()); //放弃盘点 this.CancelCommand = ReactiveCommand.CreateFromTask <object>(async e => { if (Bill.Id == 0) { this.Alert("操作失败,你需要先保存盘点!"); return; } if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return; } var confirm = await _dialogService.ShowConfirmAsync("确认放弃盘点吗?", okText: "确定", cancelText: "取消"); if (confirm) { await _inventoryService.CancelTakeInventoryAsync(Bill.Id, new System.Threading.CancellationToken()); } }); //完成确认 this.CompletedCommand = ReactiveCommand.CreateFromTask <object>(async e => { if (Bill.Id == 0) { this.Alert("操作失败,你需要先保存盘点!"); return; } if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return; } var confirm = await _dialogService.ShowConfirmAsync("确认完成盘点吗?", okText: "确定", cancelText: "取消"); if (confirm) { if (Bill.InventoryPerson == 0) { this.Alert("盘点人未指定!"); return; } if (Bill.WareHouseId == 0) { this.Alert("仓库未指定!"); return; } if (Bill.Items?.Count == 0) { this.Alert("请添加商品项目!"); return; } var result = await _inventoryService.SetInventoryCompletedAsync(Bill.Id, new System.Threading.CancellationToken()); if (!result) { this.Alert("抱歉,系统错误,请反馈技术支持!"); } } }); //编辑商品 this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500)) .Skip(1) .Where(x => x != null) .SubOnMainThread(async item => { if (this.Bill.IsSubmitBill) { _dialogService.ShortAlert("已提交的单据不能编辑"); return; } if (item != null) { List <ProductModel> products = null; var product = new ProductModel() { Name = item.ProductName, ProductName = item.ProductName, ProductId = item.ProductId, BigPriceUnit = new PriceUnit() { UnitId = item.BigUnitId ?? 0, Quantity = item.BigQuantity ?? 0, UnitName = item.bigOption.Name }, SmallPriceUnit = new PriceUnit() { UnitId = item.SmallUnitId, Quantity = item.SmallUnitQuantity ?? 0, UnitName = item.smallOption.Name }, StockQty = item.StockQty, UnitConversion = item.UnitConversion }; products.Add(product); await this.NavigateAsync("AddInventoryProductPage", ("Reference", this.PageName), ("WareHouse", WareHouse), ("Products", products)); } }) .DisposeWith(DeactivateWith); //扫码商品 this.ScanBarCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("ScanBarcodePage", ("action", "add"))); //绑定页面菜单 _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> > { //全部 { Enums.MenuEnum.ALL, (m, vm) => { var lists = Bill.Items?.ToList(); Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }, //未盘点 { MenuEnum.WART, (m, vm) => { var lists = Bill.Items?.Where(s => string.IsNullOrEmpty(s.StatusName)).ToList(); Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }, //已盘点 { MenuEnum.YPD, (m, vm) => { var lists = Bill.Items?.Where(s => !string.IsNullOrEmpty(s.StatusName)).ToList(); Bill.Items = new ObservableCollection <InventoryPartTaskItemModel>(lists); } }, //整单备注 { MenuEnum.REMARK, (m, vm) => { AllRemak((result) => { Bill.Remark = result; }, Bill.Remark); } }, //历史单据 { MenuEnum.HISTORY, async(m, vm) => { await SelectHistory(); } } }); this.BindBusyCommand(Load); }