private bool AddUnq(DrugsUnqualication du) { du.createTime = DateTime.Now; if (du.DrugInventoryRecordID != Guid.Empty) { DrugInventoryRecord dir = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(du.DrugInventoryRecordID); if (du.source.Contains("新建")) { if (du.quantity > dir.CanSaleNum) { du = null; dir = null; throw new Exception("库存不足,新增失败,请修改不合格数量!"); } dir.drugsUnqualicationNum += du.quantity; dir.Valid = dir.CanSaleNum > 0 ? true : false; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(dir); } dir = null; } du.createTime = DateTime.Now; BusinessHandlerFactory.DrugsUnqualicationBusinessHandler.Add(du); du = null; return(true); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { this.dataGridView1.EndEdit(); if (e.RowIndex < 0) { return; } if (e.ColumnIndex != this.dataGridView1.ColumnCount - 1) { return; } if (MessageBox.Show("注意:需要提交损益申请吗?", "提示", MessageBoxButtons.OKCancel) != System.Windows.Forms.DialogResult.OK) { return; } DrugInventoryRecord dir = this.PharmacyDatabaseService.GetDrugInventoryRecord(out msg, storage[e.RowIndex].InventoryID); dir.DismantingAmount = storage[e.RowIndex].DismantingAmount; dir.Valid = false; if (this.PharmacyDatabaseService.SaveDrugInventoryRecord(out msg, dir)) { MessageBox.Show("申请成功!"); } else { MessageBox.Show("申请失败!请联系管理员!"); } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 1) { if (MessageBox.Show("需要修改该药品锁定状态吗?", "提示", MessageBoxButtons.OKCancel) != System.Windows.Forms.DialogResult.OK) { return; } var Row = dataGridView1.Rows[e.RowIndex]; Guid id = Guid.Parse(Row.Cells[0].Value.ToString()); DrugInventoryRecord dir = this.PharmacyDatabaseService.GetDrugInventoryRecord(out msg, id); if (dir == null) { return; } bool isLock = Convert.ToBoolean(Row.Cells[1].EditedFormattedValue); dir.Valid = !isLock; if (this.PharmacyDatabaseService.SaveDrugInventoryRecord(out msg, dir)) { string isLockStr = !isLock ? "解锁" : "锁定"; string prompt = Row.Cells[2].Value.ToString() + "药品,批次号为:" + dir.BatchNumber + ",被" + isLockStr; MessageBox.Show(prompt + "\n设置成功!"); } else { MessageBox.Show("设置失败!"); Row.Cells[1].Value = !isLock; } } }
/// <summary> /// 新增一条零售和零售明细记录 /// </summary> /// <param name="userId"></param> /// <returns></returns public void AddRetailOrderAndDetails(RetailOrder ro) { try { //增加零售记录 List <RetailOrderDetail> rodList = ro.RetailOrderDetails.ToList(); this.Add(ro); //增加零售记录明细 foreach (RetailOrderDetail rod in rodList) { //处理药物库存实体 DrugInventoryRecord drugInventory = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.GetRetailLeftDrugInventoryRecord(rod); BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(drugInventory); int piecemealNumber = drugInventory.DrugInfo.PiecemealNumber; //处理库存实体 InventoryRecord Inventory = BusinessHandlerFactory.InventoryRecordBusinessHandler.GetRetailLeftDrugInventoryRecord(rod, drugInventory.DrugInfoId, piecemealNumber); BusinessHandlerFactory.InventoryRecordBusinessHandler.Save(Inventory); rod.RetailOrderId = ro.Id; BusinessHandlerFactory.RetailOrderDetailBusinessHandler.Add(rod); } this.Save(); } catch (Exception ex) { this.HandleException("新增一条零售和零售明细记录失败", ex); } }
private bool ModUnq(DrugsUnqualication du) { du.updateTime = DateTime.Now; if (du.DrugInventoryRecordID != Guid.Empty) { DrugsUnqualication duOld = BusinessHandlerFactory.DrugsUnqualicationBusinessHandler.Get(du.Id); DrugInventoryRecord dir = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(du.DrugInventoryRecordID); if (dir == null) { du = null; dir = null; throw new Exception("库存出错,无法保存!"); } dir.drugsUnqualicationNum -= duOld.quantity; dir.drugsUnqualicationNum += du.quantity; if (dir.CanSaleNum < 0) { du = null; dir = null; throw new Exception("库存不足,无法保存!建议修改不合格数量!"); } dir.Valid = dir.CanSaleNum > 0 ? true : false; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(dir); } BusinessHandlerFactory.DrugsUnqualicationBusinessHandler.Save(du); return(true); }
/// <summary> /// 移库右键菜单 /// </summary> /// <param name="sender">sender内含tag属性为warehousezone对象</param> /// <param name="e"></param> private void DrugInventoryMoveClick(object sender, EventArgs e) { WarehouseZone wz = ((ToolStripDropDownItem)sender).Tag as WarehouseZone; if (wz.Name == this.comboBox1.SelectedText) { return; } ApprovalFlowType aft = this.PharmacyDatabaseService.GetApprovalFlowTypeByBusiness(out msg, ApprovalType.drugsInventoryMove).FirstOrDefault(); if (aft == null) { MessageBox.Show("请先通知管理员设定移库审批,并设定其审批节点!"); return; } if (MessageBox.Show("确定需要申请该药品移库至:" + wz.Name + "吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } Guid InventoryID = storage[this.dataGridView1.SelectedCells[0].RowIndex].InventoryID; DrugInventoryRecord dir = this.PharmacyDatabaseService.GetDrugInventoryRecord(out msg, InventoryID); if (dir == null) { MessageBox.Show("读取库存表失败!"); return; } DrugsInventoryMove dim = new DrugsInventoryMove(); dim.Id = Guid.NewGuid(); dim.ApprovalStatusValue = 1; dim.batchNo = dir.BatchNumber; dim.createTime = DateTime.Now; dim.createUID = BugsBox.Pharmacy.AppClient.Common.AppClientContext.currentUser.Id; dim.Deleted = false; dim.Description = "移库至" + wz.Name; dim.drugName = dir.DrugInfo.ProductGeneralName; dim.flowID = Guid.NewGuid(); dim.inventoryRecordID = dir.Id; dim.OriginWareHouseID = dir.WarehouseZoneId; dim.quantity = dir.CanSaleNum; dim.updateTime = DateTime.Now; dim.WareHouseID = wz.Id; bool b = this.PharmacyDatabaseService.AddDrugsInventoryMoveByFlowID(dim, aft.Id, "新增移库审批", out msg); if (b) { this.PharmacyDatabaseService.WriteLog(dim.createUID, "成功提交移库申请信息:" + dim.drugName + "被成功申请移至" + dim.OriginWareHouseID); if (MessageBox.Show("成功申请移库信息" + wz.Name + ",请至右键菜单->移库记录查询界面查询!需要打开移库记录查询窗口吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } Form_DrugInventoryMove frm = new Form_DrugInventoryMove(); frm.ShowDialog(); } }
/// <summary> /// 根据销售订单获取获取出库详细 /// </summary> /// <param name="SalesOrderId"></param> /// <returns></returns> public List <OutInventoryDetail> GetOutInventoryDetailFromOrderDetail(Guid orderID) { try { List <SalesOrderDetail> salesOrderDetails = BusinessHandlerFactory.SalesOrderDetailBusinessHandler .Fetch(p => p.SalesOrderID == orderID && p.OutAmount < (p.Amount - p.ReturnAmount)) //还有未发的货 .ToList(); List <OutInventoryDetail> detailList = new List <OutInventoryDetail>(); foreach (var sDetail in salesOrderDetails) { var detail = new OutInventoryDetail(); detail.ActualUnitPrice = sDetail.ActualUnitPrice; detail.Index = sDetail.Index; detail.productCode = sDetail.productCode; detail.productName = sDetail.productName; detail.BatchNumber = sDetail.BatchNumber; detail.UnitPrice = sDetail.UnitPrice; detail.Amount = sDetail.Amount - sDetail.OutAmount - sDetail.ReturnAmount; detail.Price = sDetail.Price; detail.DictionaryDosageCode = sDetail.DictionaryDosageCode; detail.SpecificationCode = sDetail.SpecificationCode; detail.PruductDate = sDetail.PruductDate; detail.OutValidDate = sDetail.OutValidDate; detail.FactoryName = sDetail.FactoryName; detail.MeasurementUnit = sDetail.MeasurementUnit; detail.Origin = sDetail.Origin; detail.Description = "数量正确"; DrugInventoryRecord drugInventoryRecord = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(sDetail.DrugInventoryRecordID); if (drugInventoryRecord == null) { BusinessHandlerFactory.SalesOrderDetailBusinessHandler.Delete(sDetail.Id); continue; } WarehouseZone warehouseZone = BusinessHandlerFactory.WarehouseZoneBusinessHandler.Get(drugInventoryRecord.WarehouseZoneId); warehouseZone.Warehouse = BusinessHandlerFactory.WarehouseBusinessHandler.Get(warehouseZone.WarehouseId); detail.WarehouseName = warehouseZone.Warehouse.Name; detail.WarehouseCode = warehouseZone.Warehouse.Code; detail.WarehouseZoneCode = warehouseZone.Code; detail.WarehouseZoneName = warehouseZone.Name; detail.CanSaleNum = drugInventoryRecord.CanSaleNum; detail.SalesOrderId = sDetail.SalesOrderID; detail.SalesOrderDetailId = sDetail.Id; detailList.Add(detail); } return(detailList); } catch (Exception ex) { return(this.HandleException <List <OutInventoryDetail> >("根据销售订单好获取输出订单模型失败", ex)); } }
private void button1_Click(object sender, EventArgs e) { DrugSearch ds = new DrugSearch(); ds.ShowDialog(); string msg; DrugInventoryRecord item = PharmacyDatabaseService.GetDrugInventoryRecord(out msg, DrugInventoryId); txtProductName.Text = item.DrugInfo.ProductName; }
/// <summary> /// 根据零售单获取更新后的库存实体 /// </summary> /// <param name="rod"></param> /// <returns></returns> protected internal DrugInventoryRecord GetRetailLeftDrugInventoryRecord(RetailOrderDetail rod) { Guid drugInventoryID = rod.DrugInventoryRecordID; decimal consumeQty = rod.Amount; //获取药物库存实体 DrugInventoryRecord drugInventory = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(drugInventoryID); int piecemealNumber = drugInventory.DrugInfo.PiecemealNumber; #region DrugInventoryRecord 药物实体库存处理 if (rod.Amount < drugInventory.CurrentInventoryCount) { if (rod.IsDismanting) { //当前拆零数量是否满足该条零售的拆零数量 //如果拆零数量不足,则再拆一个单位 if (drugInventory.DismantingAmount < rod.DismantingAmount) { drugInventory.CurrentInventoryCount = drugInventory.CurrentInventoryCount - 1; drugInventory.DismantingAmount = drugInventory.DismantingAmount + piecemealNumber; } //存库存表的当前可用拆零数量扣掉该零售拆零数量 drugInventory.DismantingAmount = drugInventory.DismantingAmount - rod.DismantingAmount; //将零售拆零数量累加到可用库存的拆零零售数量 drugInventory.RetailDismantingAmount = drugInventory.RetailDismantingAmount + rod.DismantingAmount; if (piecemealNumber > 0) { //如果已售的零售数量大于一个单位,则需要装包 if (drugInventory.RetailDismantingAmount >= piecemealNumber) { drugInventory.RetailCount = drugInventory.RetailCount + drugInventory.RetailDismantingAmount / piecemealNumber; drugInventory.RetailDismantingAmount = drugInventory.RetailDismantingAmount % piecemealNumber; } } } else { //存库存表的当前可用库存扣掉该零售数量 drugInventory.CurrentInventoryCount = drugInventory.CurrentInventoryCount - rod.Amount; //将零售数量累加到可用库存的零售数量 drugInventory.RetailCount = drugInventory.RetailCount + rod.Amount; } } else { throw new Exception("库存数量不足"); } #endregion return(drugInventory); }
void miDrugInfo_Click() { Guid saleOrderDetailID = Guid.Empty; Guid InvID = _salesOrderList[this.dgvMain.CurrentRow.Index].DrugInventoryRecordID; DrugInventoryRecord diir = this.PharmacyDatabaseService.GetDrugInventoryRecord(out message, InvID); Guid druginfoID = diir.DrugInfoId; if (diir.Id != Guid.Empty) { Form_HistoryPurchase frm = new Form_HistoryPurchase(druginfoID, 3); frm.ShowDialog(); this.dgvMain.Focus(); } }
/// <summary> /// 根据零售退货单获取更新后的库存实体 /// </summary> /// <param name="rod"></param> /// <returns></returns> protected internal DrugInventoryRecord GetRetailReturnLeftDrugInventoryRecord(RetailOrderDetail rod) { Guid drugInventoryID = rod.DrugInventoryRecordID; decimal returnQty = rod.ReturnAmount; //获取药物库存实体 DrugInventoryRecord drugInventory = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(drugInventoryID); int piecemealNumber = drugInventory.DrugInfo.PiecemealNumber; #region DrugInventoryRecord 药物实体库存处理 if (rod.IsDismanting) { //将退库的零售拆零数量累加到药品库存的待售零售拆零数量上 drugInventory.DismantingAmount += returnQty; if (piecemealNumber > 0) { //如果待售零售拆零数量大于一个单位,则需要装包 if (drugInventory.DismantingAmount >= piecemealNumber) { drugInventory.CurrentInventoryCount += drugInventory.DismantingAmount / piecemealNumber; drugInventory.DismantingAmount = drugInventory.DismantingAmount % piecemealNumber; } } //将退库的零售拆零数量从已售的拆零零售数量里扣除 //已售拆零数量是不够扣除拆零退货数量,则从已售零售里拆包 if (drugInventory.RetailDismantingAmount < returnQty) { drugInventory.RetailCount -= 1; drugInventory.RetailDismantingAmount += piecemealNumber; } drugInventory.RetailDismantingAmount -= returnQty; } else { //存库存表的当前可用库存加上改退货数量 drugInventory.CurrentInventoryCount += returnQty; //将已经销售的零售数量累减去退货数量 drugInventory.RetailCount -= returnQty; } #endregion return(drugInventory); }
private void DrugSouce_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedCells.Count > 0) { Guid InvID = storage[this.dataGridView1.SelectedCells[0].RowIndex].InventoryID; DrugInventoryRecord diir = this.PharmacyDatabaseService.GetDrugInventoryRecord(out msg, InvID); Guid pinId = diir.PurchaseInInventeryOrderDetailId; if (pinId != Guid.Empty) { Common.Form_HistoryPurchase frm = new Common.Form_HistoryPurchase(pinId, 1); frm.ShowDialog(); this.dataGridView1.Focus(); } } }
private bool delUnq(drugsUnqualication du) { du.DeleteTime = DateTime.Now; if (du.DrugInventoryRecordID != Guid.Empty) { DrugInventoryRecord dir = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(du.DrugInventoryRecordID); if (dir == null) { du = null; dir = null; throw new Exception("库存出错,无法保存!"); } dir.drugsUnqualicationNum -= du.quantity; dir.Valid = dir.CanSaleNum > 0 ? true : false; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(dir); } BusinessHandlerFactory.DrugsUnqualificationHandler.Delete(du.Id); return(true); }
/// <summary> /// 删除一条零售和零售明细记录 /// </summary> /// <param name="userId"></param> /// <returns></returns public void DeleteRetailOrderAndDetails(Guid retailOrderID) { try { //增加销售记录 this.Delete(retailOrderID); List <RetailOrderDetail> retailOrderDetailList = this.Get(retailOrderID).RetailOrderDetails.ToList(); foreach (RetailOrderDetail item in retailOrderDetailList) { Guid drugInventoryID = item.DrugInventoryRecordID; decimal consumeQty = item.Amount; //获取药物库存实体 DrugInventoryRecord drugInventory = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(drugInventoryID); //存库存表的当前可用库存扣掉该订单明细数量 drugInventory.CurrentInventoryCount = drugInventory.CurrentInventoryCount + item.Amount; //在销售单但未出库数量 累计当前订单明细数量 drugInventory.OnSalesOrderCount = drugInventory.OnSalesOrderCount - item.Amount; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(drugInventory); //获取库存实体 InventoryRecord Inventory = BusinessHandlerFactory.InventoryRecordBusinessHandler.GetInventoryRecordByDrugInfoID(drugInventory.DrugInfoId); //存库存表的当前可用库存扣掉该订单明细数量 Inventory.CurrentInventoryCount = Inventory.CurrentInventoryCount + item.Amount; //在销售单但未出库数量 累计当前订单明细数量 Inventory.OnSalesOrderCount = Inventory.OnSalesOrderCount - item.Amount; BusinessHandlerFactory.InventoryRecordBusinessHandler.Save(Inventory); //删除订单明细 BusinessHandlerFactory.RetailOrderDetailBusinessHandler.Delete(item.Id); } this.Save(); } catch (Exception ex) { this.HandleException("删除一条订单和订单明细记录失败", ex); } }
private void buttonSelectDrugInventoryRecord_Click(object sender, EventArgs e) { if (Mode != FormRunMode.Add) { return; } try { var form = new FormAllDrugInventoryRecordSelector(); form.ShowInTaskbar = false; form.SelectMode = SelectMode.Single; if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK && form.SelectedDrugInventoryRecords != null && form.SelectedDrugInventoryRecords.Count == 1) { CurrentDrugInventoryRecord = form.SelectedDrugInventoryRecords.FirstOrDefault(); } } catch (Exception ex) { Log.Error(ex); } }
public System.Collections.Generic.IEnumerable <DrugInventoryRecord> GetDrugInventoryRecordBySalesOrderId(Guid SoId) { if (SoId == null || SoId == Guid.Empty) { return(null); } var c = BusinessHandlerFactory.SalesOrderBusinessHandler.Get(SoId); if (c == null) { return(null); } var results = (from salesorder in BusinessHandlerFactory.SalesOrderBusinessHandler.Queryable join i in BusinessHandlerFactory.SalesOrderDetailBusinessHandler.Queryable on salesorder.Id equals i.SalesOrderID join d in this.Queryable on i.DrugInventoryRecordID equals d.Id join drug in BusinessHandlerFactory.DrugInfoBusinessHandler.Queryable on d.DrugInfoId equals drug.Id where !salesorder.Deleted && !i.Deleted && !d.Deleted && salesorder.Id == SoId select new { DrugInfo = drug, Record = d }); List <DrugInventoryRecord> records = new List <DrugInventoryRecord>(); var record = new DrugInventoryRecord(); foreach (var result in results) { record = result.Record; record.DrugInfo = result.DrugInfo; records.Add(record); } return(records); }
public bool SaveDrugMaintainDetailAndUndeterminate(Models.DrugMaintainRecordDetail[] dmrds) { lock (locker) { string outDetail = string.Empty; try { foreach (DrugMaintainRecordDetail dmrd in dmrds) { dmrd.CheckDate = DateTime.Now; this.Save(dmrd); decimal UndeNum = dmrd.MaintainCount - Convert.ToDecimal(dmrd.CheckqualifiedNumber); if (UndeNum > 0) { DrugsUndeterminate du = RepositoryProvider.Db.DrugsUndeterminates.Where(r => r.UnqualificationApprovalID == dmrd.Id).ToList().FirstOrDefault(); if (du == null) { du = new DrugsUndeterminate(); du.BatchNumber = dmrd.BatchNumber; du.conclusionDate = DateTime.Now; Guid emId = RepositoryProvider.Db.Users.Where(r => r.Id == dmrd.UserId).ToList().FirstOrDefault().EmployeeId; du.creater = RepositoryProvider.Db.Employees.Where(r => r.Id == emId).FirstOrDefault().Name; du.createTime = DateTime.Now; du.DosageType = dmrd.DictionaryDosageCode; DrugInventoryRecord dir = RepositoryProvider.Db.DrugInventoryRecords.Where(r => r.Id == dmrd.DrugInventoryRecordId).ToList().First(); du.DrugInfoID = dir.DrugInfoId; du.drugName = dmrd.ProductName; du.ExpireDate = dmrd.OutValidDate; du.Id = Guid.NewGuid(); du.InventoryID = dmrd.DrugInventoryRecordId; if (!dir.PurchaseInInventeryOrderDetailId.Equals(Guid.Empty)) { PurchaseInInventeryOrderDetail piio = RepositoryProvider.Db.PurchaseInInventeryOrderDetails.Where(r => r.Id == dir.PurchaseInInventeryOrderDetailId).FirstOrDefault(); PurchaseInInventeryOrder pi = RepositoryProvider.Db.PurchaseInInventeryOrders.Where(r => r.Id == piio.PurchaseInInventeryOrderId).FirstOrDefault(); Guid orderId = pi.PurchaseOrderId; PurchaseOrder po = RepositoryProvider.Db.PurchaseOrders.Where(r => r.Id == orderId).ToList().First(); du.OrderDocumentID = po.DocumentNumber; du.PurchaseOrderID = pi.Id; du.supplyer = RepositoryProvider.Db.SupplyUnits.Where(r => r.Id == po.SupplyUnitId).ToList().First().Name; } else { du.OrderDocumentID = "前期库存,无入库单号"; du.PurchaseOrderID = Guid.Empty; du.supplyer = "无"; } du.proc = 0; du.produceDate = dmrd.PruductDate; du.DocumentNumber = new BillDocumentCodeBusinessHandler(BusinessHandlerFactory.RepositoryProvider, null).GenerateBillDocumentCodeByTypeValue((int)BillDocumentType.DrugUndeterminate).Code; du.PurchasePrice = dir.PurchasePricce; du.QualificationQuantity = Convert.ToDecimal(dmrd.CheckqualifiedNumber); du.quantity = UndeNum; du.rsn = "养护疑问药品复查"; du.Source = "养护"; du.Specific = dmrd.DictionarySpecificationCode; du.sta = string.Empty; du.staSignDate = DateTime.Now; du.staSigner = string.Empty; du.storeID = dir.StoreId; du.UnqualificationApprovalID = dmrd.Id; //该字段临时作为质量复查单的id。 du.UnqualificationQuantity = 0; du.updateTime = DateTime.Now; du.wareHouse = RepositoryProvider.Db.WarehouseZones.Where(r => r.Id == dir.WarehouseZoneId).First().Name; du.Origin = dir.Decription; BusinessHandlerFactory.DrugsUndeterminateBusinessHandler.Add(du); decimal cansaleNum = dir.CanSaleNum; dir.drugsUnqualicationNum += UndeNum;//库存记录中加上质量复查数量,然后保存。 if (dir.CanSaleNum < 0) { outDetail = "养护品种细节数据在当月1日自动完成,库存数量发生变化," + du.drugName + "当前库存数量为:" + cansaleNum + ",提交养护疑问药品数量不正确。"; throw new Exception("养护品种细节数据在当月1日自动完成,库存数量发生变化," + du.drugName + "当前库存数量为:" + cansaleNum + ",提交养护疑问药品数量不正确。"); } dir.Valid = dir.CanSaleNum > 0 ? true : false; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(dir); } } } this.Save(); string documentNumber = dmrds.FirstOrDefault().BillDocumentNo; var re = RepositoryProvider.Db.DrugMaintainRecordDetails.Where(r => r.CheckDate == null && r.BillDocumentNo == documentNumber && r.Deleted == false).FirstOrDefault(); if (re == null) { var c = RepositoryProvider.Db.DrugMaintainRecords.Where(r => r.BillDocumentNo == documentNumber).FirstOrDefault(); if (c == null) { return(false); } c.CompleteState = 1; this.Save(); } return(true); } catch (Exception e) { this.HandleException("养护细节提交失败!" + outDetail, e); return(false); } } }
/// <summary> ///销退单入库保存 /// </summary> /// <param name="so"></param> public void SaveReturnOrderInventory(SalesOrderReturn sor) { try { //处理库存的退库信息 List <SalesOrderReturnDetail> salesOrderReturnDetailList = sor.SalesOrderReturnDetails.ToList(); OutInventory oi = null; int index = 0; foreach (SalesOrderReturnDetail item in salesOrderReturnDetailList) { index++; Guid drugInventoryID = item.DrugInventoryRecordID; decimal returnQtyIn = item.CanInAmount; //获取药物库存实体 DrugInventoryRecord drugInventory = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(drugInventoryID); //在销售单但未出库数量 累计当前订单明细数量 drugInventory.SalesCount -= returnQtyIn; drugInventory.CurrentInventoryCount += returnQtyIn; if (item.IsReissue) { drugInventory.OnSalesOrderCount += returnQtyIn; if (oi == null) { OutInventory oib = BusinessHandlerFactory.OutInventoryBusinessHandler.GetOutInventoryByOrderID(sor.SalesOrderID).ToList().First(); oi = new OutInventory(); oi.CreateUserId = oib.CreateUserId; oi.OrderCode = oib.OrderCode; oi.OrderOutInventoryCheckNumber = oib.OrderOutInventoryCheckNumber; oi.OrderOutInventoryCheckTime = oib.OrderOutInventoryCheckTime; oi.OrderOutInventoryCheckUserID = oib.OrderOutInventoryCheckUserID; oi.OrderOutInventoryTime = oib.OrderOutInventoryTime; oi.OrderOutInventoryUserID = oib.OrderOutInventoryUserID; oi.OutInventoryDate = DateTime.Now; oi.OutInventoryNumber = new BillDocumentCodeBusinessHandler(BusinessHandlerFactory.RepositoryProvider, null).GenerateBillDocumentCodeByTypeValue((int)BillDocumentType.SalesOrderOutInventory).Code; oi.ReviewerId = new Guid(); oi.SalesOrderID = oib.SalesOrderID; oi.storekeeperId = oib.storekeeperId; oi.Id = Guid.NewGuid(); oi.CreateTime = DateTime.Now; oi.Deleted = false; oi.Description = "销退补货出库单"; oi.OutInventoryStatus = OutInventoryStatus.Outing; oi.OutInventoryStatusValue = (int)OutInventoryStatus.Outing; oi.OutInventoryType = OutInventoryType.SalesReissue; oi.OutInventoryTypeValue = (int)OutInventoryType.SalesReissue; oi.SalesOrderReturnID = sor.Id; oi.TotalMoney = item.ActualUnitPrice * item.ReturnAmount; BusinessHandlerFactory.OutInventoryBusinessHandler.Add(oi); } OutInventoryDetail oid = new OutInventoryDetail(); oid.ActualUnitPrice = item.ActualUnitPrice; oid.Amount = item.ReturnAmount; oid.BatchNumber = item.BatchNumber; oid.CanSaleNum = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(item.DrugInventoryRecordID).CanSaleNum + item.CanInAmount; oid.CreateTime = DateTime.Now; oid.CreateUserId = item.CreateUserId; oid.Deleted = false; oid.Description = "销退补货出库细节"; oid.DictionaryDosageCode = item.DictionaryDosageCode; oid.DrugInventoryRecordID = item.DrugInventoryRecordID; oid.FactoryName = item.FactoryName; oid.Id = Guid.NewGuid(); oid.Index = index; oid.MeasurementUnit = item.MeasurementUnit; oid.Origin = item.Origin; oid.OutAmount = item.ReturnAmount; oid.OutValidDate = item.OutValidDate; oid.Price = item.Price; oid.productCode = item.productCode; oid.productName = item.productName; oid.PruductDate = item.PruductDate; oid.SalesOrderDetailId = item.SalesOrderDetailID; oid.SalesOrderDetailReturnId = item.Id; oid.SalesOrderId = sor.SalesOrderID; oid.SalesOrderReturnId = sor.Id; oid.SalesOutInventoryID = oi.Id; oid.SpecificationCode = item.SpecificationCode; oid.StoreId = item.StoreId; oid.UnitPrice = item.UnitPrice; oid.UpdateTime = DateTime.Now; oid.UpdateUserId = item.UpdateUserId; OutInventoryDetail outinv = BusinessHandlerFactory.OutInventoryDetailBusinessHandler.Get(item.OutInventoryDetailID); oid.WarehouseCode = outinv.WarehouseCode; oid.WarehouseName = outinv.WarehouseName; oid.WarehouseZoneCode = outinv.WarehouseZoneCode; oid.WarehouseZoneName = outinv.WarehouseZoneName; BusinessHandlerFactory.OutInventoryDetailBusinessHandler.Add(oid); } //drugInventory.PurchaseReturnNumber = item.ReturnAmount; drugInventory.Valid = true; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(drugInventory); //在销售单但未出库数量 累计当前订单明细数量 if (item.IsReissue) { drugInventory.OnSalesOrderCount += returnQtyIn; } } this.Save(sor); this.Save(); } catch (Exception ex) { this.HandleException("销退单入库保存失败", ex); } }
/// <summary> /// 更新配送信息 /// </summary> /// <param name="userId"></param> /// <returns></returns> public void UpdateDelivery(Delivery delivery) { try { //更新配送信息表 this.Save(delivery); if (delivery.DeliveryStatus == DeliveryStatus.Outed) { if (delivery.OutInventoryID != Guid.Empty) { OutInventory oi = BusinessHandlerFactory.OutInventoryBusinessHandler.Get(delivery.OutInventoryID); SalesOrder so = BusinessHandlerFactory.SalesOrderBusinessHandler.Get(oi.SalesOrderID); so.OrderStatusValue = OrderStatus.Delivering.GetHashCode(); //更新库存信息 List <OutInventoryDetail> outInventoryList = BusinessHandlerFactory.OutInventoryDetailBusinessHandler.Fetch(p => p.SalesOutInventoryID == delivery.OutInventoryID).ToList(); foreach (OutInventoryDetail item in outInventoryList) { Guid drugInventoryID = item.DrugInventoryRecordID; decimal outQty = item.OutAmount; //获取药物库存实体 DrugInventoryRecord drugInventory = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(drugInventoryID); //在销售单但未出库数量 累计当前订单明细数量 drugInventory.SalesCount += outQty; drugInventory.CurrentInventoryCount -= outQty; drugInventory.OnSalesOrderCount -= outQty; drugInventory.Valid = drugInventory.CanSaleNum > 0; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(drugInventory); //获取库存实体 InventoryRecord inventory = BusinessHandlerFactory.InventoryRecordBusinessHandler.GetInventoryRecordByDrugInfoID(drugInventory.DrugInfoId); if (inventory != null) //应该能为NULL,Debug中却出现了. { //在销售单但未出库数量 累计当前订单明细数量 inventory.SalesCount += outQty; inventory.CurrentInventoryCount -= outQty; inventory.OnSalesOrderCount -= outQty; BusinessHandlerFactory.InventoryRecordBusinessHandler.Save(inventory); } } } } //签收后 if (delivery.DeliveryStatus == DeliveryStatus.Signed) { //更新车辆信息 if (delivery.VehicleID != Guid.Empty) { var vehicle = BusinessHandlerFactory.VehicleBusinessHandler.Get(delivery.VehicleID); vehicle.Status = false; //设置状态为可用 BusinessHandlerFactory.VehicleBusinessHandler.Save(vehicle); } } this.Save(); } catch (Exception ex) { this.HandleException("更新配送信息失败", ex); } finally { Dispose(); } }
/// <summary> /// 根据审核结果更新实体审核信息 /// 对业务表的操作:审批同意且审批节点流完,需要更新业务表 后者审批拒绝需要更新业务表 /// </summary> /// <param name="flowTypeIndex"></param> /// <param name="flowId"></param> /// <param name="status"></param> private void UpdateEntityByApprovalStatus(int flowTypeIndex, Guid flowId, ApprovalStatus status) { try { switch (flowTypeIndex) { case (int)ApprovalType.SupplyUnitApproval: case (int)ApprovalType.SupplyUnitEditApproval: case (int)ApprovalType.SupplyUnitLockApproval: SupplyUnit su = new SupplyUnit(); su = (SupplyUnit)GetObjectEntityInstance(flowTypeIndex, flowId, status); if (su == null) //测试时可能为NULL { BusinessHandlerFactory.SupplyUnitBusinessHandler.Save(su); } break; case (int)ApprovalType.DrugInfoApproval: case (int)ApprovalType.DrugInfoEditApproval: case (int)ApprovalType.DrugInfoLockApproval: DrugInfo di = new DrugInfo(); di = (DrugInfo)GetObjectEntityInstance(flowTypeIndex, flowId, status); if (di == null) //测试时可能为NULL { BusinessHandlerFactory.DrugInfoBusinessHandler.Save(di); } break; case (int)ApprovalType.PurchaseUnitApproval: case (int)ApprovalType.PurchaseUnitEditApproval: case (int)ApprovalType.PurchaseUnitLockApproval: PurchaseUnit pu = new PurchaseUnit(); pu = (PurchaseUnit)GetObjectEntityInstance(flowTypeIndex, flowId, status); if (pu == null) //测试时可能为NULL { BusinessHandlerFactory.PurchaseUnitBusinessHandler.Save(pu); } break; case (int)ApprovalType.drugsUnqualityApproval: DrugsUnqualication du = (DrugsUnqualication)GetObjectEntityInstance(flowTypeIndex, flowId, status); BusinessHandlerFactory.DrugsUnqualicationBusinessHandler.Save(du); break; case (int)ApprovalType.drugsBreakageApproval: DrugsBreakage db = (DrugsBreakage)GetObjectEntityInstance(flowTypeIndex, flowId, status); if (db == null) //测试时可能为NULL { if (status == ApprovalStatus.Reject) { db.Deleted = true; db.DeleteTime = DateTime.Now; db.ApprovalStatus = ApprovalStatus.Reject; } BusinessHandlerFactory.DrugsBreakageBusinessHandler.Save(db); } break; case (int)ApprovalType.drugsInventoryMove: DrugsInventoryMove dim = (DrugsInventoryMove)GetObjectEntityInstance(flowTypeIndex, flowId, status); if (status == ApprovalStatus.Approvaled) { DrugInventoryRecord dir = BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Get(dim.inventoryRecordID); dir.WarehouseZoneId = dim.WareHouseID; BusinessHandlerFactory.DrugInventoryRecordBusinessHandler.Save(dir); } BusinessHandlerFactory.DrugsInventoryMoveBusinessHandler.Save(dim); break; case (int)ApprovalType.VehicleApproval: Vehicle v = (Vehicle)GetObjectEntityInstance(flowTypeIndex, flowId, status); BusinessHandlerFactory.VehicleBusinessHandler.Save(v); break; case (int)ApprovalType.DirectSalesApproval: DirectSalesOrder dso = (Models.DirectSalesOrder)GetObjectEntityInstance(flowTypeIndex, flowId, status); BusinessHandlerFactory.DirectSalesOrderBusinessHandler.Save(dso); break; } } catch (Exception ex) { this.HandleException("根据审核结果更新实体审核信息失败", ex); } }