/// <summary> /// 根据单据信息操作账务信息与库存信息 /// </summary> /// <param name="dataContext">数据上下文</param> /// <param name="bill">单据信息</param> public void OpertaionDetailAndStock(DepotManagementDataContext dataContext, S_MaterialRejectBill bill) { MaterialListRejectBill rejectService = new MaterialListRejectBill(); IFinancialDetailManagement serverDetail = ServerModule.ServerModuleFactory.GetServerModule <IFinancialDetailManagement>(); var result = from r in dataContext.S_MaterialListRejectBill where r.Bill_ID == bill.Bill_ID select r; if (result == null || result.Count() == 0) { throw new Exception("获取单据信息失败"); } foreach (var item in result) { S_InDepotDetailBill detailInfo = rejectService.AssignDetailInfo(dataContext, bill, item); S_Stock stockInfo = rejectService.AssignStockInfo(dataContext, bill, item); if (detailInfo == null || stockInfo == null) { throw new Exception("获取账务信息或者库存信息失败"); } serverDetail.ProcessInDepotDetail(dataContext, detailInfo, stockInfo); } }
/// <summary> /// 添加采购退货单 /// </summary> /// <param name="bill">退货单信息</param> /// <param name="returnBill">返回更新后的采购退货单数据集</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回是否成功添加采购退货单</returns> public bool AddBill(S_MaterialRejectBill bill, out IQueryResult returnBill, out string error) { returnBill = null; error = null; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; if (GlobalObject.GeneralFunction.IsNullOrEmpty(bill.Bill_ID)) { throw new Exception("【单据号】获取失败,请重新再试"); } dataContxt.S_MaterialRejectBill.InsertOnSubmit(bill); dataContxt.SubmitChanges(); if (!GetAllBill(out returnBill, out error)) { return(false); } return(true); } catch (Exception exce) { error = exce.Message; return(false); } }
/// <summary> /// 赋值库存信息 /// </summary> /// <param name="context">数据上下文</param> /// <param name="bill">单据信息</param> /// <param name="item">明细信息</param> /// <returns>返回库存信息</returns> public S_Stock AssignStockInfo(DepotManagementDataContext context, S_MaterialRejectBill bill, S_MaterialListRejectBill item) { F_GoodsPlanCost info = m_basicGoodsServer.GetGoodsInfo(context, item.GoodsID); S_Stock stockInfo = new S_Stock(); stockInfo.GoodsID = info.ID; stockInfo.GoodsCode = info.GoodsCode; stockInfo.GoodsName = info.GoodsName; stockInfo.ExistCount = item.Amount; stockInfo.Spec = info.Spec; stockInfo.Provider = item.Provider; stockInfo.BatchNo = item.BatchNo; stockInfo.StorageID = bill.StorageID; return(stockInfo); }
/// <summary> /// 变更金额_采购退货单 /// </summary> /// <param name="dataContxt">数据上下文</param> /// <param name="detailInfo">结算单明细</param> void ChangePrice_S_MaterialRejectBill(DepotManagementDataContext dataContxt, View_Business_Settlement_ProcurementStatementDetail detailInfo) { IMaterialRejectBill serviceMaterialRejectBill = ServerModule.ServerModuleFactory.GetServerModule <IMaterialRejectBill>(); string error = ""; var varRejectList = from a in dataContxt.S_MaterialListRejectBill where a.Bill_ID == detailInfo.入库单号 && a.GoodsID == detailInfo.物品ID && a.BatchNo == detailInfo.批次号 select a; if (varRejectList.Count() != 0) { S_MaterialListRejectBill lnqMaterialList = varRejectList.Single(); lnqMaterialList.InvoiceUnitPrice = detailInfo.发票单价; lnqMaterialList.InvoicePrice = detailInfo.发票金额; lnqMaterialList.HavingInvoice = true; dataContxt.SubmitChanges(); int intFlag = serviceMaterialRejectBill.SetHavingInvoiceReturn(dataContxt, detailInfo.入库单号, out error); if (intFlag == 4) { throw new Exception(error); } else { var varReject = from a in dataContxt.S_MaterialRejectBill where a.Bill_ID == detailInfo.入库单号 select a; if (varReject.Count() != 0) { S_MaterialRejectBill lnqMaterialBill = varReject.Single(); lnqMaterialBill.InvoiceFlag = intFlag; dataContxt.SubmitChanges(); } } } }
/// <summary> /// 修改采购退货单(只修改编制人涉及信息) /// </summary> /// <param name="bill">退货单信息</param> /// <param name="returnBill">返回更新后的采购退货单数据集</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回是否成功添加采购退货单</returns> public bool UpdateBill(S_MaterialRejectBill bill, out IQueryResult returnBill, out string error) { returnBill = null; error = null; DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; try { var result = from r in dataContxt.S_MaterialRejectBill where r.Bill_ID == bill.Bill_ID select r; if (result.Count() == 0) { error = string.Format("没有找到单据号为 {0} 的采购退货单信息,无法进行此操作", bill.Bill_ID); return(false); } S_MaterialRejectBill updateBill = result.Single(); updateBill.Bill_Time = ServerModule.ServerTime.Time; updateBill.Provider = bill.Provider; updateBill.Reason = bill.Reason; updateBill.Remark = bill.Remark; updateBill.BillType = bill.BillType; dataContxt.SubmitChanges(); if (!GetAllBill(out returnBill, out error)) { return(false); } return(true); } catch (Exception exce) { error = exce.Message; return(false); } }
/// <summary> /// 生成采购退货单 /// </summary> /// <param name="context">数据上下文</param> /// <param name="billNo">单据号</param> void InsertRejectBill(DepotManagementDataContext context, string billNo) { string error = null; IMaterialRejectBill serverRejectBill = ServerModule.ServerModuleFactory.GetServerModule <IMaterialRejectBill>(); IMaterialListRejectBill serverRejectListBill = ServerModule.ServerModuleFactory.GetServerModule <IMaterialListRejectBill>(); var varData = from a in context.S_ScrapBill where a.Bill_ID == billNo select a; if (varData.Count() == 0) { return; } S_ScrapBill scarpBill = varData.Single(); List <string> lstProvider = (from a in context.S_ScrapGoods where a.Bill_ID == billNo && a.ResponsibilityProvider == a.Provider select a.Provider).Distinct().ToList(); foreach (string provider in lstProvider) { var dataProviderWork = from a in context.ProviderPrincipal where a.Provider == provider && a.IsMainDuty == true select a; View_HR_Personnel personnelInfo = UniversalFunction.GetPersonnelInfo(context, dataProviderWork.First().PrincipalWorkId); S_MaterialRejectBill bill = new S_MaterialRejectBill(); bill.Bill_ID = m_assignBill.AssignNewNo(context, serverRejectBill, CE_BillTypeEnum.采购退货单.ToString()); bill.Bill_Time = ServerTime.Time; bill.BillStatus = MaterialRejectBillBillStatus.已完成.ToString(); bill.Department = personnelInfo.部门编码; bill.FillInPersonnel = personnelInfo.姓名; bill.FillInPersonnelCode = personnelInfo.工号; bill.DepotManager = BasicInfo.LoginName; bill.Provider = provider; bill.Reason = "由【报废单】:" + billNo + " 生成的报废退货"; bill.Remark = "系统自动生成"; bill.BillType = "总仓库退货单"; bill.StorageID = "01"; bill.OutDepotDate = ServerTime.Time; context.S_MaterialRejectBill.InsertOnSubmit(bill); context.SubmitChanges(); var varData2 = from a in context.S_ScrapGoods where a.Provider == provider && a.Bill_ID == billNo && a.ResponsibilityProvider == a.Provider select a; foreach (S_ScrapGoods goodsInfo in varData2) { string orderForm = GetOrderForm(context, goodsInfo.GoodsID, goodsInfo.BatchNo, provider); if (orderForm == null) { throw new Exception(UniversalFunction.GetGoodsMessage(context, goodsInfo.GoodsID) + " 批次号:【" + goodsInfo.BatchNo + "】 供应商:【" + provider + "】 找不到对应的【订单号】"); } QueryCondition_Store queryInfo = new QueryCondition_Store(); queryInfo.BatchNo = goodsInfo.BatchNo; queryInfo.GoodsID = goodsInfo.GoodsID; queryInfo.StorageID = "01"; S_Stock stockInfo = UniversalFunction.GetStockInfo(context, queryInfo); //插入业务明细信息 S_MaterialListRejectBill goods = new S_MaterialListRejectBill(); goods.Bill_ID = bill.Bill_ID; goods.GoodsID = goodsInfo.GoodsID; goods.Provider = provider; goods.ProviderBatchNo = stockInfo == null ? "" : stockInfo.ProviderBatchNo; goods.BatchNo = goodsInfo.BatchNo; goods.Amount = (decimal)goodsInfo.Quantity; goods.Remark = ""; goods.AssociateID = orderForm; if (!serverRejectListBill.SetPriceInfo(goods.AssociateID, goods, bill.StorageID, out error)) { throw new Exception(error); } context.S_MaterialListRejectBill.InsertOnSubmit(goods); context.SubmitChanges(); } serverRejectBill.OpertaionDetailAndStock(context, bill); context.SubmitChanges(); } }
/// <summary> /// 更新出入库的金额 /// </summary> /// <param name="invoiceTable">需要更新的数据集</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>更新成功True,更新失败False</returns> public bool UpdatePrice(DataTable invoiceTable, out string error) { error = null; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; OrdinaryInDepotBillServer serverOrdinaryBill = new OrdinaryInDepotBillServer(); MaterialRejectBill serverMaterialRejectBill = new MaterialRejectBill(); DateTime dtStart = new DateTime(); DateTime dtEnd = new DateTime(); //获得当前日期的月结起始日期与结束日期 ServerTime.GetMonthlyBalance(ServerTime.Time, out dtStart, out dtEnd); for (int i = 0; i <= invoiceTable.Rows.Count - 1; i++) { string code = invoiceTable.Rows[i]["GoodsCode"].ToString(); string name = invoiceTable.Rows[i]["GoodsName"].ToString(); string spec = invoiceTable.Rows[i]["Spec"].ToString(); View_F_GoodsPlanCost basicGoods = m_basicGoodsServer.GetGoodsInfo(code, name, spec, out error); if (!GlobalObject.GeneralFunction.IsNullOrEmpty(error)) { return(false); } #region 改变入库表的单价(普通入库或者报检入库) var varCheckOutInDepot = from a in dataContxt.S_CheckOutInDepotBill where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() && a.GoodsID == basicGoods.序号 && a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString() select a; //报检入库单单价修改 if (varCheckOutInDepot.Count() != 0) { S_CheckOutInDepotBill lnqCheckOutInDepotBill = varCheckOutInDepot.Single(); lnqCheckOutInDepotBill.UnitInvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); lnqCheckOutInDepotBill.InvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); lnqCheckOutInDepotBill.HavingInvoice = true; dataContxt.SubmitChanges(); } else { int intGoodsID = m_basicGoodsServer.GetGoodsID(invoiceTable.Rows[i]["GoodsCode"].ToString(), invoiceTable.Rows[i]["GoodsName"].ToString(), invoiceTable.Rows[i]["Spec"].ToString()); var varOrdinaryGoods = from a in dataContxt.S_OrdinaryInDepotGoodsBill where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() && a.GoodsID == intGoodsID && a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString() select a; //普通入库单单价修改 if (varOrdinaryGoods.Count() != 0) { S_OrdinaryInDepotGoodsBill lnqOrdinaryGoods = varOrdinaryGoods.Single(); lnqOrdinaryGoods.InvoiceUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); lnqOrdinaryGoods.InvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); lnqOrdinaryGoods.HavingInvoice = true; dataContxt.SubmitChanges(); int intFlag = serverOrdinaryBill.GetHavingInvoice(invoiceTable.Rows[i]["Bill_ID"].ToString(), out error); if (intFlag == 4) { return(false); } else { var varOrdinaryBill = from a in dataContxt.S_OrdinaryInDepotBill where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() select a; if (varOrdinaryBill.Count() != 0) { S_OrdinaryInDepotBill lnqOrdinaryBill = varOrdinaryBill.Single(); lnqOrdinaryBill.InvoiceStatus = intFlag; dataContxt.SubmitChanges(); } } }//采购退货单单价修改 else { intGoodsID = m_basicGoodsServer.GetGoodsID(invoiceTable.Rows[i]["GoodsCode"].ToString(), invoiceTable.Rows[i]["GoodsName"].ToString(), invoiceTable.Rows[i]["Spec"].ToString()); var varRejectList = from a in dataContxt.S_MaterialListRejectBill where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() && a.GoodsID == intGoodsID && a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString() select a; if (varRejectList.Count() != 0) { S_MaterialListRejectBill lnqMaterialList = varRejectList.Single(); lnqMaterialList.InvoiceUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); lnqMaterialList.InvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); lnqMaterialList.HavingInvoice = true; dataContxt.SubmitChanges(); int intFlag = serverMaterialRejectBill.SetHavingInvoiceReturn(invoiceTable.Rows[i]["Bill_ID"].ToString(), out error); if (intFlag == 4) { return(false); } else { var varReject = from a in dataContxt.S_MaterialRejectBill where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() select a; if (varReject.Count() != 0) { S_MaterialRejectBill lnqMaterialBill = varReject.Single(); lnqMaterialBill.InvoiceFlag = intFlag; dataContxt.SubmitChanges(); } } } else { intGoodsID = m_basicGoodsServer.GetGoodsID(invoiceTable.Rows[i]["GoodsCode"].ToString(), invoiceTable.Rows[i]["GoodsName"].ToString(), invoiceTable.Rows[i]["Spec"].ToString()); var varOutsourcing = from a in dataContxt.S_CheckOutInDepotForOutsourcingBill where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() && a.GoodsID == intGoodsID && a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString() select a; //委外报检入库单单价修改 if (varOutsourcing.Count() != 0) { S_CheckOutInDepotForOutsourcingBill lnqOutsourcing = varOutsourcing.Single(); lnqOutsourcing.UnitInvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); lnqOutsourcing.InvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); lnqOutsourcing.HavingInvoice = true; dataContxt.SubmitChanges(); } } } } #endregion #region 改变入库明细表金额 var varInDepotBill = from b in dataContxt.S_InDepotDetailBill where b.GoodsID == basicGoods.序号 && b.InDepotBillID == invoiceTable.Rows[i]["Bill_ID"].ToString() && b.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString() select b; if (varInDepotBill.Count() == 1) { S_InDepotDetailBill lnqInDepotBill = varInDepotBill.Single(); lnqInDepotBill.InvoiceUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); lnqInDepotBill.InvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); if (lnqInDepotBill.FactPrice != Convert.ToDecimal(invoiceTable.Rows[i]["Price"])) { //当查询的记录不在当月的结算日期范围内,插入红冲单据与对冲单据 if (lnqInDepotBill.BillTime < dtStart || lnqInDepotBill.BillTime > dtEnd) { var varDetail = from d in dataContxt.S_InDepotDetailBill where d.GoodsID == basicGoods.序号 && d.InDepotBillID.Contains(invoiceTable.Rows[i]["Bill_ID"].ToString()) && d.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString() && d.BillTime >= dtStart && d.BillTime <= dtEnd select d; //判断是否已经在当前结算日期范围内插入了红冲与对冲数据 if (varDetail.Count() != 0) { foreach (var item in varDetail) { //针对已经插入的对冲数据进行修改 if (item.InDepotBillID.Contains("(对冲单据)")) { item.FactPrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); item.FactUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); } } }//对没有插入的红冲与对冲的记录进行插入 else { //插一条原始的负记录(红冲单据) S_InDepotDetailBill lnqOldInDepotBill = new S_InDepotDetailBill(); lnqOldInDepotBill.ID = Guid.NewGuid(); lnqOldInDepotBill.InDepotBillID = lnqInDepotBill.InDepotBillID + "(红冲单据)"; lnqOldInDepotBill.BatchNo = lnqInDepotBill.BatchNo; lnqOldInDepotBill.BillTime = ServerTime.Time; lnqOldInDepotBill.Department = lnqInDepotBill.Department; lnqOldInDepotBill.FactUnitPrice = lnqInDepotBill.FactUnitPrice; lnqOldInDepotBill.FactPrice = -lnqInDepotBill.FactPrice; lnqOldInDepotBill.FillInPersonnel = lnqInDepotBill.FillInPersonnel; lnqOldInDepotBill.GoodsID = lnqInDepotBill.GoodsID; lnqOldInDepotBill.InDepotCount = -lnqInDepotBill.InDepotCount; lnqOldInDepotBill.Price = -lnqInDepotBill.Price; lnqOldInDepotBill.OperationType = (int)GlobalObject.CE_SubsidiaryOperationType.财务红冲; lnqOldInDepotBill.Provider = lnqInDepotBill.Provider; lnqOldInDepotBill.Remark = lnqInDepotBill.Remark; lnqOldInDepotBill.StorageID = lnqInDepotBill.StorageID; lnqOldInDepotBill.UnitPrice = lnqInDepotBill.UnitPrice; lnqOldInDepotBill.FillInDate = lnqInDepotBill.FillInDate; lnqOldInDepotBill.AffrimPersonnel = lnqInDepotBill.AffrimPersonnel; IFinancialDetailManagement serverDetail = ServerModule.ServerModuleFactory.GetServerModule <IFinancialDetailManagement>(); serverDetail.ProcessInDepotDetail(dataContxt, lnqOldInDepotBill, null); //插一条新的正记录(对冲单据) S_InDepotDetailBill lnqNewInDepotBill = new S_InDepotDetailBill(); lnqNewInDepotBill.ID = Guid.NewGuid(); lnqNewInDepotBill.InDepotBillID = lnqInDepotBill.InDepotBillID + "(对冲单据)"; lnqNewInDepotBill.BatchNo = lnqInDepotBill.BatchNo; lnqNewInDepotBill.BillTime = ServerTime.Time; lnqNewInDepotBill.Department = lnqInDepotBill.Department; lnqNewInDepotBill.FactUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); lnqNewInDepotBill.FactPrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); lnqNewInDepotBill.FillInPersonnel = lnqInDepotBill.FillInPersonnel; lnqNewInDepotBill.GoodsID = lnqInDepotBill.GoodsID; lnqNewInDepotBill.InDepotCount = lnqInDepotBill.InDepotCount; lnqNewInDepotBill.Price = lnqInDepotBill.Price; lnqNewInDepotBill.OperationType = (int)GlobalObject.CE_SubsidiaryOperationType.财务对冲; lnqNewInDepotBill.Provider = lnqInDepotBill.Provider; lnqNewInDepotBill.Remark = lnqInDepotBill.Remark; lnqNewInDepotBill.StorageID = lnqInDepotBill.StorageID; lnqNewInDepotBill.UnitPrice = lnqInDepotBill.UnitPrice; lnqNewInDepotBill.FillInDate = lnqInDepotBill.FillInDate; lnqNewInDepotBill.AffrimPersonnel = lnqInDepotBill.AffrimPersonnel; serverDetail.ProcessInDepotDetail(dataContxt, lnqNewInDepotBill, null); } } else { lnqInDepotBill.FactPrice = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]); lnqInDepotBill.FactUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]); } } dataContxt.SubmitChanges(); } #endregion } return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 删除发票记录 /// </summary> /// <param name="invoiceCode">发票号</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>删除成功返回True,删除失败返回False</returns> public bool DeleteInvoiceInfo(string invoiceCode, out string error) { error = null; string str = "0"; int count = 0; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; OrdinaryInDepotBillServer serverOrdinaryBill = new OrdinaryInDepotBillServer(); MaterialRejectBill serverMaterialRejectBill = new MaterialRejectBill(); string strSql = "select * from B_Invoice where InvoiceCode = '" + invoiceCode + "'"; DataTable dtInvoice = GlobalObject.DatabaseServer.QueryInfo(strSql); for (int i = 0; i <= dtInvoice.Rows.Count - 1; i++) { count = i; decimal dcOldUnitPrice = 0; if (!GlobalObject.GeneralFunction.IsNullOrEmpty(error)) { return(false); } str = "1"; #region 改变入库表的单价(普通入库或者报检入库) var varCheckOutInDepot = from a in dataContxt.S_CheckOutInDepotBill where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() && a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) && a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString() select a; if (varCheckOutInDepot.Count() != 0) { S_CheckOutInDepotBill lnqCheckOutInDepot = varCheckOutInDepot.Single(); lnqCheckOutInDepot.UnitInvoicePrice = 0; lnqCheckOutInDepot.InvoicePrice = 0; lnqCheckOutInDepot.HavingInvoice = false; dcOldUnitPrice = lnqCheckOutInDepot.UnitPrice; dataContxt.SubmitChanges(); } else { var varOrdinaryGoods = from a in dataContxt.S_OrdinaryInDepotGoodsBill where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() && a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) && a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString() select a; if (varOrdinaryGoods.Count() != 0) { S_OrdinaryInDepotGoodsBill lnqOrdinaryGoods = varOrdinaryGoods.Single(); lnqOrdinaryGoods.InvoiceUnitPrice = 0; lnqOrdinaryGoods.InvoicePrice = 0; lnqOrdinaryGoods.HavingInvoice = false; dcOldUnitPrice = lnqOrdinaryGoods.UnitPrice; dataContxt.SubmitChanges(); int intFlag = serverOrdinaryBill.GetHavingInvoice(dtInvoice.Rows[i]["Bill_ID"].ToString(), out error); if (intFlag == 4) { return(false); } else { var varOrdinaryBill = from a in dataContxt.S_OrdinaryInDepotBill where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() select a; if (varOrdinaryBill.Count() != 0) { S_OrdinaryInDepotBill lnqOrdinaryBill = varOrdinaryBill.Single(); lnqOrdinaryBill.InvoiceStatus = intFlag; dataContxt.SubmitChanges(); } } } else { var varRejectList = from a in dataContxt.S_MaterialListRejectBill where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() && a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) && a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString() select a; if (varRejectList.Count() != 0) { S_MaterialListRejectBill lnqMaterialList = varRejectList.Single(); lnqMaterialList.InvoiceUnitPrice = 0; lnqMaterialList.InvoicePrice = 0; lnqMaterialList.HavingInvoice = false; dcOldUnitPrice = lnqMaterialList.UnitPrice; dataContxt.SubmitChanges(); int intFlag = serverMaterialRejectBill.SetHavingInvoiceReturn(dtInvoice.Rows[i]["Bill_ID"].ToString(), out error); if (intFlag == 4) { return(false); } else { var varRejectBill = from a in dataContxt.S_MaterialRejectBill where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() select a; if (varRejectBill.Count() != 0) { S_MaterialRejectBill lnqMaterialBill = varRejectBill.Single(); lnqMaterialBill.InvoiceFlag = intFlag; dataContxt.SubmitChanges(); } } } else { var varOutsourcing = from a in dataContxt.S_CheckOutInDepotForOutsourcingBill where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() && a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) && a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString() select a; if (varOutsourcing.Count() != 0) { S_CheckOutInDepotForOutsourcingBill lnqOutsourcing = varOutsourcing.Single(); lnqOutsourcing.UnitInvoicePrice = 0; lnqOutsourcing.InvoicePrice = 0; lnqOutsourcing.HavingInvoice = false; dcOldUnitPrice = lnqOutsourcing.UnitPrice; dataContxt.SubmitChanges(); } } } } #endregion str = "2"; #region 改变入库明细表金额 var varInDepotDetail = from b in dataContxt.S_InDepotDetailBill where b.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) && b.InDepotBillID.Contains(dtInvoice.Rows[i]["Bill_ID"].ToString()) && b.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString() select b; if (varInDepotDetail.Count() != 0) { if (varInDepotDetail.Count() == 1) { S_InDepotDetailBill lnqInDepotDetailSingle = varInDepotDetail.Single(); lnqInDepotDetailSingle.InvoiceUnitPrice = 0; lnqInDepotDetailSingle.InvoicePrice = 0; lnqInDepotDetailSingle.FactUnitPrice = dcOldUnitPrice; lnqInDepotDetailSingle.FactPrice = Math.Round(dcOldUnitPrice * Convert.ToDecimal(lnqInDepotDetailSingle.InDepotCount), 2); } else { var varInDepotDetailList = from a in varInDepotDetail where a.InDepotBillID == dtInvoice.Rows[i]["Bill_ID"].ToString() select a; S_InDepotDetailBill lnqInDepotDetailData = varInDepotDetailList.Single(); lnqInDepotDetailData.InvoiceUnitPrice = 0; lnqInDepotDetailData.InvoicePrice = 0; lnqInDepotDetailData.FactUnitPrice = dcOldUnitPrice; lnqInDepotDetailData.FactPrice = Math.Round(dcOldUnitPrice * Convert.ToDecimal(lnqInDepotDetailData.InDepotCount), 2); var varData7 = from a in varInDepotDetail where a.InDepotBillID != dtInvoice.Rows[i]["Bill_ID"].ToString() select a; dataContxt.S_InDepotDetailBill.DeleteAllOnSubmit(varData7); } dataContxt.SubmitChanges(); } #endregion } var varInvoice = from a in dataContxt.B_Invoice where a.InvoiceCode == invoiceCode select a; if (varInvoice.Count() > 0) { dataContxt.B_Invoice.DeleteAllOnSubmit(varInvoice); dataContxt.SubmitChanges(); } return(true); } catch (Exception ex) { error = ex.Message + str + count.ToString(); return(false); } }
private void 修改单据ToolStripMenuItem_Click(object sender, EventArgs e) { if (!CheckSelectedRow()) { return; } if (lblBillStatus.Text != MaterialRejectBillBillStatus.新建单据.ToString() && lblBillStatus.Text != MaterialRejectBillBillStatus.等待财务审核.ToString()) { MessageDialog.ShowPromptMessage("您现在不是处于新建单据状态或者等待财务审核状态,无法进行此操作"); return; } if (!CheckUserOperation(dataGridView1.SelectedRows[0])) { return; } if (!CheckDataItem()) { return; } if (dataGridView1.SelectedRows[0].Cells["供应商"].Value.ToString() != txtProvider.Text) { if (m_goodsServer.IsExist(txtBill_ID.Text)) { MessageDialog.ShowPromptMessage("已经设置好物品清单时不允许再修改供应商"); return; } } if (dataGridView1.SelectedRows[0].Cells["单据类型"].Value.ToString() != cmbBillType.Text) { if (m_goodsServer.IsExist(txtBill_ID.Text)) { MessageDialog.ShowPromptMessage("已经设置好物品清单时不允许再修改单据类型"); return; } } S_MaterialRejectBill bill = new S_MaterialRejectBill(); bill.Bill_ID = txtBill_ID.Text; bill.Bill_Time = ServerModule.ServerTime.Time; bill.Provider = txtProvider.Text; bill.Reason = txtReason.Text; bill.Remark = txtRemark.Text; bill.BillType = cmbBillType.Text; bill.StorageID = UniversalFunction.GetStorageID(cmbStorage.Text); if (!m_billServer.UpdateBill(bill, out m_queryResult, out m_error)) { MessageDialog.ShowErrorMessage(m_error); return; } RefreshDataGridView(m_queryResult); PositioningRecord(bill.Bill_ID); }
private void 设置退货清单ToolStripMenuItem_Click(object sender, EventArgs e) { string billNo = txtBill_ID.Text; try { this.dataGridView1.CellEnter -= new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEnter); if (lblBillStatus.Text != MaterialRejectBillBillStatus.新建单据.ToString()) { MessageDialog.ShowPromptMessage("您现在不是处于新建单据状态,无法进行此操作"); return; } if (!CheckDataItem()) { return; } // 如果此单据存在则检查选择行 if (m_billServer.IsExist(txtBill_ID.Text)) { if (!CheckSelectedRow()) { return; } if (!CheckUserOperation(dataGridView1.SelectedRows[0])) { return; } } else { BASE_MaterialRequisitionPurpose purpose = txtProvider.Tag as BASE_MaterialRequisitionPurpose; // 如果此单据还不存在则创建 S_MaterialRejectBill bill = new S_MaterialRejectBill(); bill.Bill_ID = txtBill_ID.Text; bill.Bill_Time = ServerModule.ServerTime.Time; bill.BillStatus = MaterialRejectBillBillStatus.新建单据.ToString(); bill.Department = BasicInfo.DeptCode; bill.FillInPersonnel = BasicInfo.LoginName; bill.FillInPersonnelCode = BasicInfo.LoginID; bill.Provider = txtProvider.Text; bill.Reason = txtReason.Text; bill.Remark = txtRemark.Text; bill.BillType = cmbBillType.Text; bill.StorageID = UniversalFunction.GetStorageID(cmbStorage.Text); if (!m_billServer.AddBill(bill, out m_queryResult, out m_error)) { MessageDialog.ShowErrorMessage(m_error); return; } } FormMaterialListRejectBill form = new FormMaterialListRejectBill(CE_BusinessOperateMode.修改, txtProvider.Text, txtBill_ID.Text); form.ShowDialog(); } finally { this.dataGridView1.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEnter); } RefreshDataGridView(m_queryResult); PositioningRecord(billNo); }
/// <summary> /// 回退单据 /// </summary> /// <param name="djh">回退单据号</param> /// <param name="billStatus">回退单据状态</param> /// <param name="returnBill">返回的查询结果集</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <param name="rebackReason">回退原因</param> /// <returns>回退成功返回True,回退失败返回False</returns> public bool ReturnBill(string djh, string billStatus, out IQueryResult returnBill, out string error, string rebackReason) { returnBill = null; error = null; try { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; var varData = from a in ctx.S_MaterialRejectBill where a.Bill_ID == djh select a; string strMsg = ""; if (varData.Count() == 1) { S_MaterialRejectBill lnqMRequ = varData.Single(); switch (billStatus) { case "新建单据": strMsg = string.Format("{0}号采购退货单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh); m_billMessageServer.PassFlowMessage(djh, strMsg, lnqMRequ.FillInPersonnelCode, false); lnqMRequ.BillStatus = "新建单据"; lnqMRequ.FinanceSignatory = null; break; case "等待财务审核": strMsg = string.Format("{0}号采购退货单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh); m_billMessageServer.PassFlowMessage(djh, strMsg, UniversalFunction.GetPersonnelCode(lnqMRequ.FinanceSignatory), false); lnqMRequ.BillStatus = "等待质检"; lnqMRequ.FinanceSignatory = null; break; default: break; } ctx.SubmitChanges(); } else { error = "数据不唯一或者为空"; return(false); } return(GetAllBill(out returnBill, out error)); } catch (Exception exce) { error = exce.Message; return(false); } }
/// <summary> /// 完成采购退货单 /// </summary> /// <param name="billNo">单据号</param> /// <param name="storeManager">仓库管理员</param> /// <param name="returnBill">返回更新后重新查询的采购退货单数据集</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回是否成功添加采购退货单</returns> public bool FinishBill(string billNo, string storeManager, out IQueryResult returnBill, out string error) { returnBill = null; error = null; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var result = from r in dataContxt.S_MaterialRejectBill where r.Bill_ID == billNo select r; if (result.Count() == 0) { error = string.Format("没有找到单据号为 {0} 的采购退货单信息,无法进行此操作", billNo); return(false); } //if (!CheckBillIsInIsolationManageBill(billNo,out error)) //{ // return false; //} S_MaterialRejectBill bill = result.Single(); if (bill.BillStatus == MaterialRejectBillBillStatus.已完成.ToString()) { error = "单据不能重复退货"; return(false); } bill.DepotManager = storeManager; bill.BillStatus = MaterialRejectBillBillStatus.已完成.ToString(); bill.OutDepotDate = ServerTime.Time; if (bill.BillType.ToString() == "总仓库退货单") { //操作账务信息与库存信息 OpertaionDetailAndStock(dataContxt, bill); ////更新隔离单单据状态 //if (!UpdateIsolationBillStatus(dataContxt, billNo, out error)) //{ // return false; //} } else { if (!SetScrapFlag(dataContxt, bill.Bill_ID, out error)) { return(false); } } // 正式使用单据号 m_assignBill.UseBillNo(dataContxt, "采购退货单", bill.Bill_ID); dataContxt.SubmitChanges(); return(GetAllBill(out returnBill, out error)); } catch (Exception exce) { error = exce.Message; return(false); } }
/// <summary> /// 检查已经关联了不合格品隔离单 /// </summary> /// <param name="billID">退货单号</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>检测合格返回True,不合格返回False</returns> bool CheckBillIsInIsolationManageBill(string billID, out string error) { error = null; DepotManagementDataContext ctx = CommentParameter.DepotDataContext; var varBill = from a in ctx.S_MaterialRejectBill where a.Bill_ID == billID select a; S_MaterialRejectBill lnqBill = new S_MaterialRejectBill(); if (varBill.Count() != 1) { return(false); } else { lnqBill = varBill.Single(); } MaterialListRejectBill serverRejectBill = new MaterialListRejectBill(); string strSql = "select * from S_MaterialListRejectBill where Bill_ID = '" + billID + "'"; DataTable dtBill = GlobalObject.DatabaseServer.QueryInfo(strSql); for (int i = 0; i < dtBill.Rows.Count; i++) { strSql = "select * from S_IsolationManageBill where GoodsID = " + Convert.ToInt32(dtBill.Rows[i]["GoodsID"]) + " and BatchNo = '" + dtBill.Rows[i]["BatchNo"].ToString() + "' and DJZT <> '已完成'"; DataTable dtIsolation = GlobalObject.DatabaseServer.QueryInfo(strSql); if (dtIsolation.Rows.Count > 0) { strSql = "select * from S_IsolationManageBill where GoodsID = " + Convert.ToInt32(dtBill.Rows[i]["GoodsID"]) + " and BatchNo = '" + dtBill.Rows[i]["BatchNo"].ToString() + "' and DJZT <> '已完成'" + "' and AssociateRejectBillID = '" + billID + "'"; DataTable dtIsolationGoods = GlobalObject.DatabaseServer.QueryInfo(strSql); if (dtIsolation.Rows.Count == 0) { error = "不能对隔离且未关联隔离单的物品进行退货!"; return(false); } } if (!serverRejectBill.IsGoodsStockThan(Convert.ToInt32(dtBill.Rows[i]["GoodsID"]), dtBill.Rows[i]["BatchNo"].ToString(), Convert.ToDecimal(dtBill.Rows[i]["Amount"]), dtBill.Rows[i]["Provider"].ToString(), lnqBill.StorageID)) { error = "库存不足,无法退货!"; return(false); } } return(true); }
/// <summary> /// 插入采购退货表 /// </summary> /// <param name="dataContxt">LINQ数据上下文</param> /// <param name="billList">扣货子表</param> /// <param name="billTable">扣货主表</param> /// <param name="billNo">单据号</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>操作成功返回True,操作失败返回False</returns> bool InsertMaterialRejectBill(DepotManagementDataContext dataContxt, DataTable billList, DataTable billTable, string billNo, out string error) { error = null; try { MaterialRejectBill serverRejectBill = new MaterialRejectBill(); string strCGBillNo = m_assignBill.AssignNewNo(serverRejectBill, "采购退货单"); //插入主表信息 S_MaterialRejectBill bill = new S_MaterialRejectBill(); if (billTable.Rows.Count > 0) { bill.Bill_ID = strCGBillNo; bill.Bill_Time = ServerTime.Time; bill.BillStatus = MaterialRejectBillBillStatus.已完成.ToString(); bill.Department = BasicInfo.DeptCode; bill.FillInPersonnel = BasicInfo.LoginName; bill.FillInPersonnelCode = BasicInfo.LoginID; bill.Provider = billList.Rows[0]["供应商"].ToString(); bill.Reason = billList.Rows[0]["扣货原因"].ToString(); bill.Remark = billList.Rows[0]["备注"].ToString() + "(根据物料扣货单【" + billNo + "】系统自动生成)"; bill.BillType = "总仓库退货单"; bill.StorageID = UniversalFunction.GetStorageID(billList.Rows[0]["库房名称"].ToString()); bill.OutDepotDate = ServerTime.Time; dataContxt.S_MaterialRejectBill.InsertOnSubmit(bill); } else { return(false); } for (int i = 0; i < billTable.Rows.Count; i++) { //插入业务明细信息 S_MaterialListRejectBill goods = new S_MaterialListRejectBill(); goods.Bill_ID = strCGBillNo; goods.GoodsID = Convert.ToInt32(billTable.Rows[i]["物品ID"].ToString()); goods.Provider = billTable.Rows[i]["供应商"].ToString(); goods.ProviderBatchNo = ""; goods.BatchNo = billTable.Rows[i]["批次号"].ToString(); goods.Amount = Convert.ToDecimal(billTable.Rows[i]["扣货数"].ToString()); goods.Remark = billTable.Rows[i]["备注"].ToString(); goods.AssociateID = billTable.Rows[i]["关联订单号"].ToString(); if (!new MaterialListRejectBill().SetPriceInfo(goods.AssociateID, goods, UniversalFunction.GetStorageID(billList.Rows[0]["库房名称"].ToString()), out error)) { return(false); } dataContxt.S_MaterialListRejectBill.InsertOnSubmit(goods); } serverRejectBill.OpertaionDetailAndStock(dataContxt, bill); return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 赋值账务信息 /// </summary> /// <param name="context">数据上下文</param> /// <param name="bill">单据信息</param> /// <param name="item">明细信息</param> /// <returns>返回账务信息</returns> public S_InDepotDetailBill AssignDetailInfo(DepotManagementDataContext context, S_MaterialRejectBill bill, S_MaterialListRejectBill item) { IBillTypeServer server = ServerModuleFactory.GetServerModule <IBillTypeServer>(); BASE_BillType billType = server.GetBillTypeFromName("采购退货单"); if (billType == null) { throw new Exception("获取不到单据类型信息"); } S_InDepotDetailBill detailBill = new S_InDepotDetailBill(); detailBill.ID = Guid.NewGuid(); detailBill.BillTime = (DateTime)bill.OutDepotDate; detailBill.FillInPersonnel = bill.FillInPersonnel; detailBill.Department = UniversalFunction.GetDeptInfo(context, bill.Department).部门名称; detailBill.FactPrice = -Math.Round(item.UnitPrice * item.Amount, 2); detailBill.FactUnitPrice = item.UnitPrice; detailBill.GoodsID = item.GoodsID; detailBill.BatchNo = item.BatchNo; detailBill.Provider = item.Provider; detailBill.InDepotBillID = bill.Bill_ID; detailBill.InDepotCount = -item.Amount; detailBill.UnitPrice = item.UnitPrice; detailBill.Price = -Math.Round(item.UnitPrice * item.Amount, 2); detailBill.OperationType = (int)GlobalObject.CE_SubsidiaryOperationType.采购退货; detailBill.StorageID = bill.StorageID; detailBill.Remark = "退货原因:" + bill.Reason + " 备注:" + bill.Remark; detailBill.AffrimPersonnel = bill.DepotManager; detailBill.FillInDate = bill.Bill_Time; return(detailBill); }