/// <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); } }