/// <summary> /// 销退申请单申请保存 /// </summary> /// <param name="orderID"></param> /// <param name="detailList"></param> public void AddSalesOrderReturnAndDetail(SalesOrderReturn sor) { try { #region SalesOrer Save sor.OrderReturnCode = BusinessHandlerFactory.BillDocumentCodeBusinessHandler.GenerateBillDocumentCodeByTypeValue((int)BillDocumentType.SalesOrderReturn).Code; sor.CreateTime = DateTime.Now; sor.UpdateTime = DateTime.Now; #endregion this.Add(sor); foreach (SalesOrderReturnDetail sord in sor.SalesOrderReturnDetails) { if (sord.ReturnAmount > 0) { OutInventoryDetail oid = new OutInventoryDetail(); oid = BusinessHandlerFactory.OutInventoryDetailBusinessHandler.Get(sord.OutInventoryDetailID); oid.OutAmount -= sord.ReturnAmount; BusinessHandlerFactory.OutInventoryDetailBusinessHandler.Save(oid); BusinessHandlerFactory.SalesOrderReturnDetailBusinessHandler.Add(sord); sord.OrderReturnID = sor.Id; } } this.Save(); } catch (Exception ex) { this.HandleException("保存销退明细列表失败", ex); } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (e.ColumnIndex == 1) { Guid id = bList[e.RowIndex].id; SalesOrderReturn sor = list.First(r => r.Id == id); FormSalesOrderReturn frm = new FormSalesOrderReturn(sor, true, true); frm.ShowDialog(); if (frm.DialogResult == DialogResult.OK) { getData(); return; } } if (this.dataGridView1.CurrentCell.OwningColumn.Name.Equals(Column6.Name)) { Guid id = bList[e.RowIndex].id; SalesOrderReturn sor = list.First(r => r.Id == id); FormSalesOrderReturn frm = new FormSalesOrderReturn(sor, true, false); frm.ShowDialog(); } }
/// <summary> /// 根据出库单生成销退单(允许退货一次) /// </summary> /// <param name="orderInfo"></param> public FormSalesOrderReturn(SalesOrderReturn salesOrderReturn) { InitializeComponent(); this.Text = UpdateFormTitle(salesOrderReturn.OrderReturnStatus); this._SalesOrderReturn = salesOrderReturn; this.dgvDrugDetailList.RowPostPaint += delegate(object o, DataGridViewRowPostPaintEventArgs ex) { DataGridViewOperator.SetRowNumber((DataGridView)o, ex); }; this.dgvDrugDetailList.AutoGenerateColumns = false; }
public FormSalesOrderReturn(SalesOrderReturn salesOrderReturn, bool isReadOnly, bool b) { InitializeComponent(); isBalance = b; this.Text = UpdateFormTitle(salesOrderReturn.OrderReturnStatus); this._SalesOrderReturn = salesOrderReturn; this.dgvDrugDetailList.RowPostPaint += delegate(object o, DataGridViewRowPostPaintEventArgs ex) { DataGridViewOperator.SetRowNumber((DataGridView)o, ex); }; this.dgvDrugDetailList.AutoGenerateColumns = false; _ReadOnly = isReadOnly; UpdateBtnEnabled(OrderReturnStatus.None); }
/// <summary> /// 销退审核后处理 /// 更新订单表 /// 更新订单详细表 /// </summary> /// <param name="so"></param> public void AcceptSalesOrderReturn(SalesOrderReturn sor) { SalesOrder so = BusinessHandlerFactory.SalesOrderBusinessHandler.Get(sor.SalesOrderID); //销退后状态为结算 so.OrderStatus = OrderStatus.Banlaced; BusinessHandlerFactory.SalesOrderBusinessHandler.Save(so); try { var db = BusinessHandlerFactory.RepositoryProvider.Db; //订单信息更新 var order = db.SalesOrders.First(p => p.Id == so.Id); order.OrderStatus = OrderStatus.Banlaced;//结算 order.OrderReturnCheckCode = order.OrderReturnCheckCode; order.OrderReturnCheckTime = order.UpdateTime = DateTime.Now; order.UpdateUserId = order.OrderReturnCheckUserID; order.OrderReturnCheckUserID = order.OrderReturnCheckUserID; //获取订单信息和库存信息的集合 var list = db.SalesOrderReturnDetails.Where(p => p.Id == order.Id) .Join(db.SalesOrderDetails.Where(p => p.Id == order.Id), l => l.DrugInventoryRecordID, r => r.DrugInventoryRecordID, (l, r) => new { ReturnAmount = l.ReturnAmount, OrderDetail = r }) .Join(db.InventoryRecords, l => l.OrderDetail.DrugInventoryRecordID, r => r.Id, (l, r) => new { ReturnAmount = l.ReturnAmount, OrderDetail = l.OrderDetail, InvertoryInfo = r }); foreach (var item in list) { item.OrderDetail.Amount -= item.ReturnAmount; item.OrderDetail.UpdateTime = DateTime.Now; item.OrderDetail.UpdateUserId = order.UpdateUserId; item.InvertoryInfo.CurrentInventoryCount += item.ReturnAmount; item.InvertoryInfo.OnSalesOrderCount += item.ReturnAmount; var drugIn = db.DrugInventoryRecords.First(p => p.DrugInfoId == item.InvertoryInfo.DrugInfoId); drugIn.CurrentInventoryCount += item.ReturnAmount; drugIn.OnSalesOrderCount += item.ReturnAmount; } BusinessHandlerFactory.UserLogBusinessHandler.LogUserLog(new UserLog { Content = ConnectedInfoProvider.User.Account + "成功审核销退单:" + sor.OrderReturnCode }); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
/// <summary> ///销退单出库保存 /// </summary> /// <param name="so"></param> public void SaveReturnOrderOutventory(SalesOrderReturn sor) { try { #region SalesOrer Save SalesOrder so = BusinessHandlerFactory.SalesOrderBusinessHandler.Get(sor.SalesOrderID); List <SalesOrderReturnDetail> sordList = sor.SalesOrderReturnDetails.ToList(); foreach (SalesOrderReturnDetail sord in sordList) { //补发的需要更新订单信息,重新出库发货 if (sord.IsReissue) { SalesOrderDetail sod = BusinessHandlerFactory.SalesOrderDetailBusinessHandler.Get(sord.SalesOrderDetailID); if (sord.IsReissue) { sod.ChangeAmount += sord.ReturnAmount; } else { sod.ReturnAmount += sord.ReturnAmount; } sod.OutAmount = sod.Amount - sod.ChangeAmount; BusinessHandlerFactory.SalesOrderDetailBusinessHandler.Save(sod); } } BusinessHandlerFactory.SalesOrderBusinessHandler.Save(so); #endregion this.Save(sor); this.Save(); } catch (Exception ex) { this.HandleException("销退单出库保存失败", ex); } }
/// <summary> /// 销退申请单取消 /// </summary> /// <param name="orderID"></param> /// <param name="detailList"></param> public void CancelSalesOrderReturn(SalesOrderReturn sor) { try { sor.OrderReturnCancelCode = BusinessHandlerFactory.BillDocumentCodeBusinessHandler.GenerateBillDocumentCodeByTypeValue((int)BillDocumentType.OrderReturnCancel).Code; foreach (SalesOrderReturnDetail sord in sor.SalesOrderReturnDetails) { OutInventoryDetail oid = new OutInventoryDetail(); oid = BusinessHandlerFactory.OutInventoryDetailBusinessHandler.Get(sord.OutInventoryDetailID); oid.OutAmount += sord.ReturnAmount; BusinessHandlerFactory.OutInventoryDetailBusinessHandler.Save(oid); BusinessHandlerFactory.SalesOrderReturnDetailBusinessHandler.Delete(sord.Id); } sor.OrderReturnCancelTime = DateTime.Now; this.Save(sor); this.Save(); } catch (Exception ex) { this.HandleException("保存销退明细列表失败", ex); } }
/// <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="sender"></param> /// <param name="e"></param> private void tsbtnSubmit_Click(object sender, EventArgs e) { this.dgvDrugDetailList.EndEdit(); bool flag = false; foreach (DataGridViewRow dr in this.dgvDrugDetailList.Rows) { if (Convert.ToDecimal(dr.Cells["退货数量"].Value) > 0) { flag = true; if (Convert.ToInt32(dr.Cells["dgvcmbReturnReason"].Value) == 0) { MessageBox.Show("您编辑的(" + dr.Cells["商品名称"].Value.ToString() + ")退货理由没有填写。"); dgvDrugDetailList.ClearSelection(); dgvDrugDetailList.CurrentCell = dr.Cells["dgvcmbReturnReason"]; dgvDrugDetailList.BeginEdit(false); return; } if (Convert.ToDecimal(dr.Cells["不可入库数量"].Value) > 0 && Convert.ToInt32(dr.Cells["不可入库处理办法"].Value) == 0) { MessageBox.Show("您编辑的(" + dr.Cells["商品名称"].Value.ToString() + ")不可入库处理办法没有填写。"); dgvDrugDetailList.ClearSelection(); dgvDrugDetailList.CurrentCell = dr.Cells["不可入库处理办法"]; dgvDrugDetailList.BeginEdit(false); return; } } if (Convert.ToDecimal(dr.Cells["退货数量"].Value) != Convert.ToDecimal(dr.Cells["可入库数量"].Value) + Convert.ToDecimal(dr.Cells["不可入库数量"].Value)) { MessageBox.Show("您填写的(" + dr.Cells["商品名称"].Value.ToString() + ")数量有误!\n" + "其退货数量为:" + dr.Cells[退货数量.Name].Value + "不等于可入库数量和可入库数量之和。"); dgvDrugDetailList.ClearSelection(); dr.Selected = true; return; } if (Convert.ToDecimal(dr.Cells["退货数量"].Value) < 0 || Convert.ToDecimal(dr.Cells["可入库数量"].Value) < 0 || Convert.ToDecimal(dr.Cells["不可入库数量"].Value) < 0) { MessageBox.Show("您填写的(" + dr.Cells["商品名称"].Value.ToString() + ")数量有负值!\n"); dgvDrugDetailList.ClearSelection(); dr.Selected = true; return; } Models.SalesOrderReturnDetail sord = (SalesOrderReturnDetail)dr.DataBoundItem; if (sord.IsReissue) { decimal cansaleNum = this.PharmacyDatabaseService.GetDrugInventoryRecordByCondition(out msg, sord.productName, sord.BatchNumber).Sum(r => r.CanSaleNum); if (cansaleNum < sord.ReturnAmount) { MessageBox.Show("当前库存中该药品(名称:" + sord.productName + ",批次号:" + sord.BatchNumber + ")可销售数量小于补发数量,不能执行补发操作!"); return; } } } if (!flag) { MessageBox.Show("列表中没有填写需要退货的数量,无法执行退货流程,您至少需要填写一个品种的退货数量。"); return; } try { string message; SalesOrderReturn orderReturn = new SalesOrderReturn(); orderReturn.Id = Guid.NewGuid(); orderReturn.IsReissue = this.ckbIsReissue.Checked; orderReturn.SalesOrderID = OrderInfo.Id; orderReturn.CreateUserId = AppClientContext.CurrentUser.Id; //orderReturn.OrderReturnCode = this.ucbcSalesReturn.GenarateCode(); orderReturn.OrderReturnReason = this.txtReason.Text; orderReturn.OrderReturnStatusValue = (int)OrderReturnStatus.Waitting; orderReturn.OutInventoryID = OutInfo.Id; //没办法,只能这么写了,获取用户ID Employee[] emp = this.PharmacyDatabaseService.AllEmployees(out msg); var em = emp.FirstOrDefault(r => r.Name.Equals(this.OrderInfo.SalerName)); if (em == null) { MessageBox.Show("该单据异常,销售员:" + this.OrderInfo.SalerName + "被人为删除。此单据为该销售员所定制,系统当前无该销售员信息,所以暂时无法退货,解决办法是恢复该销售员信息,并且锁定该销售员,如果系统中确实无法找到该销售员信息,则可按照姓名新增员工信息和用户信息。"); return; } Guid uid = em.Users.First().Id; orderReturn.SellerID = uid; listSalesOrderReturnDetail = listSalesOrderReturnDetail.Where(r => r.ReturnAmount > 0).ToList(); orderReturn.SalesOrderReturnDetails = listSalesOrderReturnDetail.ToArray(); //调用服务器端 message = PharmacyDatabaseService.AddSalesOrderReturnAndDetail(orderReturn); if (message.Length > 0) { MessageBox.Show(message); } else { orderReturn = this.PharmacyDatabaseService.GetSalesOrderReturn(out msg, orderReturn.Id); this.PharmacyDatabaseService.WriteLog(AppClientContext.CurrentUser.Id, "成功提交销售退货操作:" + orderReturn.OrderReturnCode); MessageBox.Show("成功提交退货申请,单号:" + orderReturn.OrderReturnCode + ",请销售员登陆,执行审核!"); this.tsbtnSubmit.Enabled = false; this.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 初始化画面 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormSalesOrderReturn_Load(object sender, EventArgs e) { try { //提交销退申请 this.tsbtnSubmit.Visible = this.Authorize(ModuleKeys.SubmitOrderReturn); //取消销退申请 if (_SalesOrderReturn != null) { this.tsbtnCancel.Visible = this.Authorize(ModuleKeys.SubmitOrderReturn); } //销售员审核 this.tsbtnSellerApproved.Visible = this.Authorize(ModuleKeys.SellerApprovedOrderReturn); //营业部审核 this.tsbtnTradeApproved.Visible = this.Authorize(ModuleKeys.TradeApprovedOrderReturn); //质量管理部审核 this.tsbtnQualityApproved.Visible = this.Authorize(ModuleKeys.QualityApprovedOrderReturn); //结算 this.toolStripButton1.Visible = this.Authorize(ModuleKeys.BalanceSalesOrderReturn) && isBalance; //结算打印 this.tsbtnPrint.Visible = this.Authorize(ModuleKeys.BalanceSalesOrderReturn); string msg = string.Empty; InitGridViewCombox(); if (this.OutInfo != null) { _SalesOrderReturn = this.PharmacyDatabaseService.GetLastOrderReturnByReturnOrder(out msg, OutInfo.Id); OrderInfo = this.PharmacyDatabaseService.GetSalesOrder(out msg, OutInfo.SalesOrderID); } //创建一个销退信息 if (this.OutInfo != null) { _SalesOrderReturn = new SalesOrderReturn(); _SalesOrderReturn.OrderReturnStatusValue = (int)OrderReturnStatus.None; this.tsbtnCancel.Enabled = false; this.tsbtnSubmit.Enabled = true; _SalesOrderReturn.SalesOrderID = OrderInfo.Id; listSalesOrderReturnDetail = CreateReturnDetailByOrderDetail(OutInfo.SalesOutInventoryDetails); this.lblReturnNo.Text = string.Empty; this.lblOrderNo.Text = OrderInfo.OrderCode; this.lblCreateDate.Text = OrderInfo.SaleDate.Date.ToString("yyyy-MM-dd"); this.lblOutStatus.Text = Utility.getEnumTypeDisplayName <OrderStatus>((OrderStatus)this.OrderInfo.OrderStatusValue); this.dgvDrugDetailList.DataSource = listSalesOrderReturnDetail; } else { OrderInfo = this.PharmacyDatabaseService.GetSalesOrder(out msg, _SalesOrderReturn.SalesOrderID); listSalesOrderReturnDetail = _SalesOrderReturn.SalesOrderReturnDetails.ToList(); this.tsbtnCancel.Enabled = true; this.tsbtnSubmit.Enabled = false; this.txtTotalMoney.Text = listSalesOrderReturnDetail.Select(s => s.ReturnAmount * s.ActualUnitPrice).Sum().ToString(); this.txtReason.Text = _SalesOrderReturn.OrderReturnReason; this.lblReturnNo.Text = _SalesOrderReturn.OrderReturnCode; this.lblOrderNo.Text = OrderInfo.OrderCode; this.lblCreateDate.Text = OrderInfo.SaleDate.Date.ToString("yyyy-MM-dd"); this.lblOutStatus.Text = Utility.getEnumTypeDisplayName <OrderStatus>((OrderStatus)this.OrderInfo.OrderStatusValue); if (isBalance) { this.dgvDrugDetailList.DataSource = listSalesOrderReturnDetail.Where(r => r.ReturnAmount > 0).ToList(); } else { this.dgvDrugDetailList.DataSource = listSalesOrderReturnDetail; } this.dgvDrugDetailList.ReadOnly = true; } UpdateBtnEnabled((OrderReturnStatus)_SalesOrderReturn.OrderReturnStatusValue); dgvDrugDetailList.ClearSelection(); if (_SalesOrderReturn.OrderReturnStatus == OrderReturnStatus.ReturnChecked) { toolStripButton2.Enabled = false; this.tsbtnInVentory.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Log.Error(ex); } }