/// <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); }
/// <summary> /// 添加物品信息 /// </summary> /// <param name="orderFormNumber">订单号</param> /// <param name="goods">物品信息</param> /// <param name="storageID">库房ID</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回操作是否成功的标志</returns> public bool AddGoods(string orderFormNumber, S_MaterialListRejectBill goods, string storageID, out string error) { try { error = null; DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; if (!SetPriceInfo(orderFormNumber, goods, storageID, out error)) { return(false); } if (!UpdateAssicotaeBillID(dataContxt, goods.Bill_ID, goods.GoodsID, goods.BatchNo, out error)) { return(false); } dataContxt.S_MaterialListRejectBill.InsertOnSubmit(goods); dataContxt.SubmitChanges(); return(true); } catch (Exception exce) { error = exce.Message; return(false); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0) { MessageDialog.ShowPromptMessage("请选择要修改的记录后再进行此操作"); return; } else if (dataGridView1.SelectedRows.Count > 1) { MessageDialog.ShowPromptMessage("只能选择要修改的一条记录后再进行此操作"); return; } if (!CheckDataItem()) { return; } S_MaterialListRejectBill goods = new S_MaterialListRejectBill(); View_S_MaterialListRejectBill viewGoods = GetGoodsInfo(dataGridView1.SelectedRows[0]); goods.ID = viewGoods.序号; goods.Bill_ID = m_billNo; if (txtCode.Tag != null && (int)txtCode.Tag != 0) { goods.GoodsID = (int)txtCode.Tag; } else { goods.GoodsID = viewGoods.物品ID; } goods.Provider = txtProvider.Text; goods.ProviderBatchNo = txtProviderBatchNo.Text; goods.BatchNo = txtBatchNo.Text; goods.Amount = numAmount.Value; goods.Remark = txtRemark.Text; if (!m_goodsServer.UpdateGoods(txtAssociateID.Text, goods, m_strStorage, out m_error)) { MessageDialog.ShowErrorMessage(m_error); return; } GetCodeInfoFromForm(); m_queryGoodsInfo = m_goodsServer.GetGoods(m_billNo); RefreshDataGridView(m_queryGoodsInfo); PositioningRecord(m_strGoodsCode, m_strGoodsName, m_strSpec); }
/// <summary> /// 检查相同物品 /// </summary> /// <param name="Dt">需要检测的数据集</param> /// <param name="goods">物品明细信息</param> /// <returns>不相同返回True,相同返回False</returns> bool CheckSameGoods(DataTable dt, S_MaterialListRejectBill goods) { for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["物品ID"].ToString() == goods.GoodsID.ToString() && dt.Rows[i]["批次号"].ToString() == goods.BatchNo.ToString()) { MessageBox.Show("不能添加同一个物品,请重新确认物品", "提示"); return(false); } } return(true); }
/// <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(); } } } }
private void btnBatchCreate_Click(object sender, EventArgs e) { 退货业务报废物品筛选窗体 Form = new 退货业务报废物品筛选窗体(m_strProvider); Form.ShowDialog(); DataTable dt = Form.DtScrap; if (dt == null || dt.Rows.Count == 0) { return; } for (int i = 0; i < dt.Rows.Count; i++) { S_MaterialListRejectBill goods = new S_MaterialListRejectBill(); goods.Bill_ID = m_billNo; goods.GoodsID = Convert.ToInt32(dt.Rows[i]["GoodsID"].ToString()); goods.Provider = dt.Rows[i]["Provider"].ToString(); goods.ProviderBatchNo = ""; goods.BatchNo = dt.Rows[i]["BatchNo"].ToString(); goods.Amount = Convert.ToDecimal(dt.Rows[i]["Quantity"].ToString()); goods.Remark = dt.Rows[i]["Reason"].ToString(); goods.AssociateID = dt.Rows[i]["Bill_ID"].ToString(); IQueryable <View_S_MaterialListRejectBill> IQReject = dataGridView1.DataSource as IQueryable <View_S_MaterialListRejectBill>; DataTable dvt = GlobalObject.GeneralFunction.ConvertToDataTable <View_S_MaterialListRejectBill>(IQReject); if (CheckSameGoods(dvt, goods)) { if (!m_goodsServer.AddGoods(txtAssociateID.Text, goods, m_strStorage, out m_error)) { MessageDialog.ShowErrorMessage(m_error); return; } } } GetCodeInfoFromForm(); m_queryGoodsInfo = m_goodsServer.GetGoods(m_billNo); RefreshDataGridView(m_queryGoodsInfo); }
private void btnSelectScraptBill_Click(object sender, EventArgs e) { 对应的隔离单 Form = new 对应的隔离单(txtAssociateID.Text.Trim(), m_strStorage); Form.ShowDialog(); DataTable dt = Form.m_dtIsolation; if (dt == null || dt.Rows.Count == 0) { return; } for (int i = 0; i < dt.Rows.Count; i++) { S_MaterialListRejectBill goods = new S_MaterialListRejectBill(); goods.Bill_ID = m_billNo; goods.GoodsID = Convert.ToInt32(dt.Rows[i]["物品ID"].ToString()); goods.Provider = dt.Rows[i]["供货单位"].ToString(); goods.ProviderBatchNo = dt.Rows[i]["供方批次号"].ToString(); goods.BatchNo = dt.Rows[i]["批次号"].ToString(); goods.Amount = Convert.ToDecimal(dt.Rows[i]["退货数"].ToString()); goods.Remark = "隔离退货单【" + dt.Rows[i]["隔离单号"].ToString() + "】"; goods.AssociateID = txtAssociateID.Text; IQueryable <View_S_MaterialListRejectBill> IQReject = dataGridView1.DataSource as IQueryable <View_S_MaterialListRejectBill>; DataTable dvt = GlobalObject.GeneralFunction.ConvertToDataTable <View_S_MaterialListRejectBill>(IQReject); if (CheckSameGoods(dvt, goods)) { if (!m_goodsServer.AddGoods(txtAssociateID.Text, goods, m_strStorage, out m_error)) { MessageDialog.ShowErrorMessage(m_error); return; } } } GetCodeInfoFromForm(); m_queryGoodsInfo = m_goodsServer.GetGoods(m_billNo); RefreshDataGridView(m_queryGoodsInfo); }
private void btnAdd_Click(object sender, EventArgs e) { if (!CheckDataItem()) { return; } if (!m_goodsServer.IsGoodsStockThan((int)txtCode.Tag, txtBatchNo.Text, numAmount.Value, txtProvider.Text, m_strStorage)) { MessageDialog.ShowPromptMessage("库存不足,请重新填写库存"); return; } S_MaterialListRejectBill goods = new S_MaterialListRejectBill(); goods.Bill_ID = m_billNo; goods.GoodsID = (int)txtCode.Tag; goods.Provider = txtProvider.Text; goods.ProviderBatchNo = txtProviderBatchNo.Text; goods.BatchNo = txtBatchNo.Text; goods.Amount = numAmount.Value; goods.Remark = txtRemark.Text; goods.AssociateID = txtAssociateID.Text; IQueryable <View_S_MaterialListRejectBill> IQReject = dataGridView1.DataSource as IQueryable <View_S_MaterialListRejectBill>; DataTable dvt = GlobalObject.GeneralFunction.ConvertToDataTable <View_S_MaterialListRejectBill>(IQReject); if (CheckSameGoods(dvt, goods)) { if (!m_goodsServer.AddGoods(txtAssociateID.Text, goods, m_strStorage, out m_error)) { MessageDialog.ShowErrorMessage(m_error); return; } } GetCodeInfoFromForm(); m_queryGoodsInfo = m_goodsServer.GetGoods(m_billNo); RefreshDataGridView(m_queryGoodsInfo); PositioningRecord(m_strGoodsCode, m_strGoodsName, m_strSpec); }
/// <summary> /// 更新物品信息 /// </summary> /// <param name="orderFormNumber">订单号</param> /// <param name="goods">物品信息</param> /// <param name="storageID">库房ID</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回操作是否成功的标志</returns> public bool UpdateGoods(string orderFormNumber, S_MaterialListRejectBill goods, string storageID, out string error) { try { error = null; DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var result = from r in dataContxt.S_MaterialListRejectBill where r.ID == goods.ID select r; if (result.Count() > 0) { S_MaterialListRejectBill updateGoods = result.Single(); updateGoods.Bill_ID = goods.Bill_ID; updateGoods.GoodsID = goods.GoodsID; updateGoods.Provider = goods.Provider; updateGoods.BatchNo = goods.BatchNo; updateGoods.ProviderBatchNo = goods.ProviderBatchNo; updateGoods.Amount = goods.Amount; updateGoods.Remark = goods.Remark; if (!SetPriceInfo(orderFormNumber, updateGoods, storageID, out error)) { return(false); } dataContxt.SubmitChanges(); } 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); } }
/// <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="orderFormNumber">订单号</param> /// <param name="goods">物品信息</param> /// <param name="storageID">库房ID</param> /// <param name="error">出错时返回错误信息,无错时返回null</param> /// <returns>返回操作是否成功的标志</returns> public bool SetPriceInfo(string orderFormNumber, S_MaterialListRejectBill goods, string storageID, out string error) { decimal factUnitPrice = 0; decimal planUnitPrice = 0; if (!string.IsNullOrEmpty(orderFormNumber)) { if (orderFormNumber.Length > 3 && orderFormNumber.Substring(0, 3) == "BFD") { factUnitPrice = m_storeServer.GetFactUnitPrice(goods.GoodsID, goods.Provider, goods.BatchNo, storageID); } else { string strSql = "select b.UnitPrice/(1+cess/100) as UnitPrice from B_OrderFormInfo as a " + " inner join B_BargainInfo as d on a.BargainNumber = d.BargainNumber " + " inner join B_BargainGoods as b on a.BargainNumber = b.BargainNumber " + " where a.orderFormNumber = '" + orderFormNumber + "' and b.GoodsID = " + Convert.ToInt32(goods.GoodsID); DataTable dtBargainPrice = GlobalObject.DatabaseServer.QueryInfo(strSql); if (dtBargainPrice.Rows.Count == 0) { factUnitPrice = 0; } else { //委外报检的物品单价直接从委外报检入库单中的单价金额获得 if (goods.BatchNo.Contains("WJD")) { strSql = " select UnitPrice from S_CheckOutInDepotForOutsourcingBill where Bill_ID = '" + goods.BatchNo + "' "; DataTable dtRawMaterialPrice = GlobalObject.DatabaseServer.QueryInfo(strSql); if (dtRawMaterialPrice.Rows.Count == 0) { factUnitPrice = 0; } else { factUnitPrice = Convert.ToDecimal(dtRawMaterialPrice.Rows[0][0]); } } else { factUnitPrice = Convert.ToDecimal(dtBargainPrice.Rows[0][0].ToString()); } } } } if (!m_basicGoodsServer.GetPlanUnitPrice(goods.GoodsID, out planUnitPrice, out error)) { return(false); } goods.PlanUnitPrice = planUnitPrice; goods.PlanPrice = planUnitPrice * goods.Amount; goods.UnitPrice = factUnitPrice; goods.Price = factUnitPrice * goods.Amount; goods.TotalPrice = CalculateClass.GetTotalPrice(goods.Price); return(true); }