public static bool BuildAttestBill(AttestBillModel Attestmodel, out int ID) { bool result = false; StringBuilder Attestsql = new StringBuilder(); Attestsql.AppendLine("Insert into officedba.AttestBill"); Attestsql.AppendLine("(CompanyCD,VoucherDate,AttestNo,"); Attestsql.AppendLine("AttestName,Creator,CreateDate,"); Attestsql.AppendLine("status,FromTbale,FromValue)"); Attestsql.AppendLine("Values(@CompanyCD,@VoucherDate,"); Attestsql.AppendLine("@AttestNo,@AttestName,@Creator,getdate(),"); Attestsql.AppendLine("@status,@FromTbale,@FromValue)"); Attestsql.AppendLine("set @IntID= @@IDENTITY"); SqlCommand CmdAttest = new SqlCommand(); CmdAttest.Parameters.AddWithValue("@CompanyCD", SqlDbType.VarChar).Value = Attestmodel.CompanyCD; CmdAttest.Parameters.AddWithValue("@AttestNo", SqlDbType.VarChar).Value = Attestmodel.AttestNo; CmdAttest.Parameters.AddWithValue("@AttestName", SqlDbType.VarChar).Value = Attestmodel.AttestName; CmdAttest.Parameters.AddWithValue("@Creator", SqlDbType.Int).Value = Attestmodel.Creator; CmdAttest.Parameters.AddWithValue("@status", SqlDbType.Int).Value = Attestmodel.status; CmdAttest.Parameters.AddWithValue("@FromTbale", SqlDbType.VarChar).Value = Attestmodel.FromTbale; CmdAttest.Parameters.AddWithValue("@FromValue", SqlDbType.VarChar).Value = Attestmodel.FromValue; CmdAttest.Parameters.AddWithValue("@VoucherDate", SqlDbType.DateTime).Value = Attestmodel.VoucherDate; SqlParameter Ret = new SqlParameter("@IntID", SqlDbType.Int); //定义返回值参数 Ret.Direction = ParameterDirection.Output; CmdAttest.Parameters.Add(Ret); CmdAttest.CommandText = Attestsql.ToString(); ArrayList cmdList = new ArrayList(); cmdList.Add(CmdAttest); //添加已期末处理的项目信息 // InsertPeriodProced(Attestmodel.CompanyCD, ItemID,"1", PeriodNum, cmdList); // UpdateEndItemIsAccount(ItemID,cmdList);//更新登帐状态 result = SqlHelper.ExecuteTransWithArrayList(cmdList); ID = Convert.ToInt32(Ret.Value); return(result); }
/// <summary> ///保存数据信息至凭证主表 /// </summary> /// <param name="Model"></param> /// <returns></returns> public static bool InsertIntoAttestBill(AttestBillModel Model) { StringBuilder sql = new StringBuilder(); sql.AppendLine("Insert into Officedba.CurrencyTypeSetting ( CompanyCD,CurrencyName, "); sql.AppendLine("CurrencySymbol,isMaster,ExchangeRate,ConvertWay,ChangeTime,UsedStatus )"); sql.AppendLine("Values(@CompanyCD,@CurrencyName,@CurrencySymbol,"); sql.AppendLine("@isMaster,@ExchangeRate,@ConvertWay,@ChangeTime,@UsedStatus )"); SqlParameter[] parms = new SqlParameter[8]; //parms[0] = SqlHelper.GetParameter("@CompanyCD", Model.CompanyCD); //parms[1] = SqlHelper.GetParameter("@CurrencyName", Model.CurrencyName); //parms[2] = SqlHelper.GetParameter("@CurrencySymbol", Model.CurrencySymbol); //parms[3] = SqlHelper.GetParameter("@isMaster", Model.isMaster); //parms[4] = SqlHelper.GetParameter("@ExchangeRate", Model.ExchangeRate); //parms[5] = SqlHelper.GetParameter("@ConvertWay", Model.ConvertWay); //parms[6] = SqlHelper.GetParameter("@ChangeTime", Model.ChangeTime); //parms[7] = SqlHelper.GetParameter("@UsedStatus", Model.UsedStatus); SqlHelper.ExecuteTransSql(sql.ToString(), parms); return(SqlHelper.Result.OprateCount > 0 ? true : false); }
public static bool CountFixAssetDepreciation(string ItemID, string PeriodNum, ref string getAttestNo, ref int AttestID) { //获取当前操作用户企业编码 bool result = false;//执行返回结果 try { int PeriodID = 0; string CompanyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD; DataTable dt = FixAssetInfoDBHelper.GetAssetInfoByCompanyCD(CompanyCD, PeriodNum); if (dt != null && dt.Rows.Count > 0) { #region 固定资产计提折旧计算 //计算方法 string CountMethod = string.Empty; //预计使用年限 int EstimateUseYear; //预计净残值率 decimal EstiResiValue; //原值 decimal OriginalValue; //月折旧率 decimal MonthDeprRate; //期末净值 decimal EndNetValue; //本期净值 decimal CurrentNetValue; //本期减值准备 decimal CurrValueRe; //月折旧额 decimal MonthDeprPrice = 0; //累计月折旧额 decimal CountTotalDeprPrice = 0; ArrayList DeprDetailList = new ArrayList(); ArrayList DeprPeriodList = new ArrayList(); //计提前固定资产实体数组 ArrayList FixDeprAfterList = new ArrayList(); //定义固定资产计提明细实体 FixAssetDeprDetailModel DeprDetailmodel = null; //资产计提 FixAssetPeriodDeprModel DeprPeriodmodel = null; //资产计提前实体 FixAssetDeprAfterModel FixDeprAftermodel = null; foreach (DataRow rows in dt.Rows) { //读取期末净值 EndNetValue = Convert.ToDecimal(rows["EndNetValue"]); //读取计算方法 CountMethod = rows["CountMethod"].ToString(); //读取预计净残值率 EstiResiValue = Convert.ToDecimal(rows["EstiResiValue"]); //读取原价 OriginalValue = Convert.ToDecimal(rows["OriginalValue"]); //读取本期减值准备 CurrValueRe = Convert.ToDecimal(rows["CurrValueRe"]); //读取月折旧率 MonthDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]); //实例固定资产计提明细实体 DeprDetailmodel = new FixAssetDeprDetailModel(); #region 固定资产计提明细赋值 //给固定资产计提明细赋值 DeprDetailmodel.CompanyCD = CompanyCD; DeprDetailmodel.Creator = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID; //固定资产名称 DeprDetailmodel.FixName = rows["FixName"].ToString(); //固定资产编号 DeprDetailmodel.FixNo = rows["FixNo"].ToString(); //资产类别 DeprDetailmodel.FixType = Convert.ToInt32(rows["FixType"]); //资产数量 DeprDetailmodel.Number = Convert.ToInt32(rows["FixNumber"]); //资产原值 DeprDetailmodel.OriginalValue = Convert.ToDecimal(rows["OriginalValue"]); //使用日期 DeprDetailmodel.UsedDate = Convert.ToDateTime(rows["UseDate"]); //使用年限 DeprDetailmodel.UsedYears = Convert.ToDecimal(rows["UsedYear"]); //预计使用年限 DeprDetailmodel.EstimateUse = Convert.ToDecimal(rows["EstimateUse"]); //计算预计净残值 decimal Yjcz = OriginalValue * (EstiResiValue / 100); #endregion //判断期末净值大于计净残值则进行折旧处理 if (EndNetValue > Yjcz) { //年限平均法 if (CountMethod == ConstUtil.ASSETCOUNT_METHOD_NXPJF_CODE) { //读取期初减值准备 decimal ReduValueRe = Convert.ToDecimal(rows["ReduValueRe"]); //读取预计使用年限 EstimateUseYear = Convert.ToInt32(rows["EstimateUse"]); //MonthDeprPrice = Math.Round(MonthDeprRate * OriginalValue, 2);//计算月折旧额 //读取月折旧额 MonthDeprPrice = Convert.ToDecimal(rows["AmorDeprM"]); //计算本期期末净值 CurrentNetValue = EndNetValue - MonthDeprPrice - CurrValueRe; //本期期末净值 DeprDetailmodel.EndNetValue = CurrentNetValue; //月折旧额 DeprDetailmodel.MDeprPrice = MonthDeprPrice; //计算累计折旧额 CountTotalDeprPrice = Convert.ToDecimal(rows["TotalDeprPrice"]) + MonthDeprPrice; DeprDetailmodel.TotalDeprPrice = CountTotalDeprPrice; //累计减值 DeprDetailmodel.TotalImpairment = (ReduValueRe + CurrValueRe); //计算月折旧额 //如果本期净值大于净残值则更新 if (CurrentNetValue > Yjcz) { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]);; FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Math.Round(CurrentNetValue, 2); DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = 0; DeprPeriodmodel.AmorDeprM = MonthDeprPrice; DeprPeriodmodel.TotalDeprPrice = CountTotalDeprPrice; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } else { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]); FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Yjcz; DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = 0; DeprPeriodmodel.AmorDeprM = MonthDeprPrice; DeprPeriodmodel.TotalDeprPrice = Convert.ToDecimal(rows["EndNetValue"]) - Yjcz; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } } //工作量法 else if (CountMethod == ConstUtil.ASSETCOUNT_METHOD_GZLF_CODE) { //读取月折旧额 MonthDeprPrice = Convert.ToDecimal(rows["AmorDeprM"]); //计算本期期末净值 CurrentNetValue = EndNetValue - MonthDeprPrice - CurrValueRe; //计算累计折旧额 CountTotalDeprPrice = Convert.ToDecimal(rows["TotalDeprPrice"]) + MonthDeprPrice; //如果本期净值大于原净值则不更新 if (CurrentNetValue > Yjcz) { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]);; FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Math.Round(CurrentNetValue, 2); DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = 0; DeprPeriodmodel.AmorDeprM = MonthDeprPrice; DeprPeriodmodel.TotalDeprPrice = CountTotalDeprPrice; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } else { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]);; FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Yjcz; DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = 0; DeprPeriodmodel.AmorDeprM = MonthDeprPrice; DeprPeriodmodel.TotalDeprPrice = Convert.ToDecimal(rows["EndNetValue"]) - Yjcz; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } }//年限总和法 else if (CountMethod == ConstUtil.ASSETCOUNT_METHOD_NXZHF_CODE) { //年折旧率 decimal YearDeprRate = 0; //读取预计使用年限 EstimateUseYear = Convert.ToInt32(rows["EstimateUse"]); //读取已使用年限 int UsedYears = Convert.ToInt32(rows["UsedYear"]); //计算年折旧率 YearDeprRate = Convert.ToDecimal((EstimateUseYear - UsedYears)) / (Convert.ToDecimal(EstimateUseYear) * (Convert.ToDecimal(EstimateUseYear + 1)) / 2) * (100 / 100); //计算月折旧率 MonthDeprRate = YearDeprRate / 12; //计算月折旧额 MonthDeprPrice = (OriginalValue - (OriginalValue * (EstiResiValue / 100))) * MonthDeprRate; //计算本期期末净值 CurrentNetValue = EndNetValue - MonthDeprPrice - CurrValueRe; //计算累计折旧额 CountTotalDeprPrice = Convert.ToDecimal(rows["TotalDeprPrice"]) + MonthDeprPrice; if (CurrentNetValue > Yjcz) { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]);; FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Math.Round(CurrentNetValue, 2); DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = Math.Round(MonthDeprRate, 8); DeprPeriodmodel.AmorDeprM = Math.Round(MonthDeprPrice, 2); DeprPeriodmodel.TotalDeprPrice = CountTotalDeprPrice; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } else { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]);; FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Yjcz; DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = Math.Round(MonthDeprRate, 8); DeprPeriodmodel.AmorDeprM = MonthDeprPrice; DeprPeriodmodel.TotalDeprPrice = Convert.ToDecimal(rows["EndNetValue"]) - Yjcz; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } }//双倍余额递减法 else if (CountMethod == ConstUtil.ASSETCOUNT_METHOD_SBYETJS_CODE) { //读取预计使用年限 EstimateUseYear = Convert.ToInt32(rows["EstimateUse"]); //年折旧率 decimal YearDeprRate = 0; //计算年折旧率 YearDeprRate = 2 / Convert.ToDecimal(EstimateUseYear) * (100 / 100); //计算月折旧率 MonthDeprRate = YearDeprRate / 12; //计算月折旧额 MonthDeprPrice = EndNetValue * MonthDeprRate; //计算本期期末净值 CurrentNetValue = EndNetValue - MonthDeprPrice - CurrValueRe; //计算累计折旧额 CountTotalDeprPrice = Convert.ToDecimal(rows["TotalDeprPrice"]) + MonthDeprPrice; if (CurrentNetValue > Yjcz) { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]);; FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Math.Round(CurrentNetValue, 2); DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = Math.Round(MonthDeprRate, 8); DeprPeriodmodel.AmorDeprM = Math.Round(MonthDeprPrice, 2); DeprPeriodmodel.TotalDeprPrice = CountTotalDeprPrice; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } else { #region 添加固定资产折旧前信息实体 FixDeprAftermodel = new FixAssetDeprAfterModel(); FixDeprAftermodel.AmorDeprM = rows["AmorDeprM"] != DBNull.Value ? Convert.ToDecimal(rows["AmorDeprM"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.AmorDeprRate = Convert.ToDecimal(rows["AmorDeprRate"]);; FixDeprAftermodel.CompanyCD = CompanyCD; FixDeprAftermodel.EndNetValue = rows["EndNetValue"] != DBNull.Value ? Convert.ToDecimal(rows["EndNetValue"]) : Convert.ToDecimal(DBNull.Value); FixDeprAftermodel.FixNo = rows["FixNo"].ToString(); FixDeprAftermodel.PeriodNum = Convert.ToInt32(PeriodNum); FixDeprAftermodel.TotalDeprPrice = rows["TotalDeprPrice"] != DBNull.Value ? Convert.ToDecimal(rows["TotalDeprPrice"]) : Convert.ToDecimal(DBNull.Value); FixDeprAfterList.Add(FixDeprAftermodel); #endregion DeprPeriodmodel = new FixAssetPeriodDeprModel(); DeprPeriodmodel.CompanyCD = CompanyCD; DeprPeriodmodel.EndNetValue = Yjcz; DeprPeriodmodel.FixNo = rows["FixNo"].ToString(); DeprPeriodmodel.AmorDeprRate = Math.Round(MonthDeprRate, 8); DeprPeriodmodel.AmorDeprM = MonthDeprPrice; DeprPeriodmodel.TotalDeprPrice = Convert.ToDecimal(rows["EndNetValue"]) - Yjcz; DeprDetailList.Add(DeprDetailmodel); DeprPeriodList.Add(DeprPeriodmodel); } } } } #endregion //折旧固定资产明细 result = FixAssetInfoDBHelper.UpdateEndFixAssetInfo(DeprDetailList, DeprPeriodList, CompanyCD, PeriodNum, ItemID, ref PeriodID, FixDeprAfterList); } if (result) { #region 凭证单据明细实体 //凭证单据实体 AttestBillModel Attestmodel = new AttestBillModel(); //凭证明细实体定义 AttestBillDetailsModel Detailmodel = null; #endregion #region 凭证单据实体赋值 Attestmodel.CompanyCD = CompanyCD; Attestmodel.AttestNo = "记-" + VoucherDBHelper.GetMaxAttestNo(CompanyCD, DateTime.Now.ToString()); getAttestNo = Attestmodel.AttestNo; Attestmodel.AttestName = "记账凭证"; Attestmodel.Creator = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID; Attestmodel.status = 0; Attestmodel.FromTbale = "EndItemProcessedRecord,FixWithInfo,FixPeriodDeprDetails"; Attestmodel.FromValue = PeriodID.ToString() + "," + PeriodNum.ToString(); Attestmodel.VoucherDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); #endregion int ID; ArrayList modelList = new ArrayList();//定义数组存储实体对象 //添加凭证单据信息 result = FixAssetInfoDBHelper.BuildDepreAttestBill(Attestmodel, out ID, ItemID, PeriodNum); AttestID = ID; if (result && ID > 0) { //获取固定资产科目汇总金额信息 DataTable AttestDetail = FixAssetInfoDBHelper.GetBuildAttestInfo(CompanyCD); //获取折旧凭证摘要ID string AbstractID; AbstractID = ConstUtil.SUMMARY_ZCJZ_NAME; #endregion //获取本币币种ID int MasterCurrencyID = Convert.ToInt32(CurrTypeSettingDBHelper.GetMasterCurrency(CompanyCD).Rows[0]["ID"]); if (AttestDetail != null && AttestDetail.Rows.Count > 0) { foreach (DataRow drows in AttestDetail.Rows) { #region 凭证明细实体赋值 Detailmodel = new AttestBillDetailsModel(); Detailmodel.AttestBillID = ID; Detailmodel.Abstract = AbstractID; // 摘要 Detailmodel.SubjectsCD = drows["AccuDeprSubjeCD"].ToString(); //累计折旧科目 贷 Detailmodel.CreditAmount = Convert.ToDecimal(drows["CountSum"]); //贷方金额 Detailmodel.DebitAmount = 0; Detailmodel.OriginalAmount = Convert.ToDecimal(drows["CountSum"]); //外币金额 Detailmodel.CurrencyTypeID = MasterCurrencyID; //本币ID Detailmodel.ExchangeRate = 1; //本币汇率 modelList.Add(Detailmodel); Detailmodel = new AttestBillDetailsModel(); Detailmodel.AttestBillID = ID; Detailmodel.Abstract = AbstractID; // 摘要 Detailmodel.CreditAmount = 0; Detailmodel.SubjectsCD = drows["DeprCostSubjeCD"].ToString(); //折旧费用科目 借 Detailmodel.DebitAmount = Convert.ToDecimal(drows["CountSum"]); //借方金额 Detailmodel.OriginalAmount = Convert.ToDecimal(drows["CountSum"]); //外币金额 Detailmodel.CurrencyTypeID = MasterCurrencyID; //本币ID Detailmodel.ExchangeRate = 1; //本币汇率 modelList.Add(Detailmodel); #endregion } //凭证自动登帐及自动审核 result = FixAssetInfoDBHelper.BuildDepreDetailInfo(modelList); if (result) { VoucherBus.SetStatus(ID.ToString(), "1", "status", 0); VoucherBus.InsertAccount(AttestID); } } } } return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// 业务单确认时自动生成凭证--自动登帐--启用自动生成凭证时生成凭证后自动回写源单登记凭证状态 /// </summary> /// <param name="TemplateType">模板类别(1.采购订单,2. 销售订单,3. 委托代销单,4. 销售退货单,5. 采购入库,6. 其他出库单,7. 销售出库单,8. 其他入库单,9.收款单,10.付款单)</param> /// <param name="CompanyCD">公司编号</param> /// <param name="IsVoucher">是否自动生成凭证 0 不生成 1 启用自动生成</param> /// <param name="IsApply">凭证是否自动登帐 0 不登帐 1 启用自动登帐</param> /// <param name="BillAmount">业务单含税金额合计</param> /// <param name="FromTBInfo">来源表信息,格式来源表名+,+来源表主键(业务单主表名称(带上架构),自动生成凭证的业务单主键)必填</param> /// <param name="CurrencyInfo">业务单币种信息,格式为(币种ID,汇率)必填,若业务单无币种汇率,则默认传本位币及汇率</param> /// <param name="ProOrCustID">科目辅助核算ID(默认为业务单中的供应商或客户主键)</param> /// <param name="returnV">返回提示信息</param> /// <returns></returns> public static bool AutoVoucherInsert(int TemplateType, string CompanyCD, string IsVoucher, string IsApply, decimal BillAmount, string FromTBInfo, string CurrencyInfo, int ProOrCustID, out string returnV) { bool rev = true; string returnValue = string.Empty; int BillID = 0; //生成凭证的凭证主键 if (IsVoucher == "1") //自动生成凭证 { /*判断某业务单是否配置生成凭证模板--start*/ StringBuilder SelectTemplateSQL = new StringBuilder(); SelectTemplateSQL.AppendLine("select Abstract,TemNo from officedba.VoucherTemplate "); SelectTemplateSQL.AppendLine(" where CompanyCD=@CompanyCD and TemType=@TemType and UsedStatus='1' "); SqlCommand comm = new SqlCommand(); comm.CommandText = SelectTemplateSQL.ToString(); comm.Parameters.AddWithValue("@CompanyCD", SqlDbType.VarChar).Value = CompanyCD; comm.Parameters.AddWithValue("@TemType", SqlDbType.Int).Value = TemplateType; DataTable dt = SqlHelper.ExecuteSearch(comm); /*判断某业务单是否配置生成凭证模板--End*/ if (dt != null && dt.Rows.Count > 0) { /*获取业务单对应的凭证模板明细--start*/ StringBuilder TemplateDetailSQL = new StringBuilder(); TemplateDetailSQL.AppendLine(" select SubjectsNo,Direction,Scale "); TemplateDetailSQL.AppendLine(" from officedba.VoucherTemplateDetail "); TemplateDetailSQL.AppendLine(" where CompanyCD=@CompanyCD "); TemplateDetailSQL.AppendLine(" and TemNo=@TemNo"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = TemplateDetailSQL.ToString(); cmd.Parameters.AddWithValue("@CompanyCD", SqlDbType.VarChar).Value = CompanyCD; cmd.Parameters.AddWithValue("@TemNo", SqlDbType.VarChar).Value = dt.Rows[0]["TemNo"].ToString(); DataTable tempdt = SqlHelper.ExecuteSearch(cmd); /*获取业务单对应的凭证模板明细--End*/ if (tempdt != null && tempdt.Rows.Count > 0) { AttestBillModel Model = new AttestBillModel(); //凭证主表实例 ArrayList DetailList = new ArrayList(); //凭证明细数组 Model.Attachment = 1; //附件数 Model.AttestName = "记账凭证"; //凭证名称 Model.VoucherDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); //凭证日期 Model.AttestNo = "记-" + VoucherDBHelper.GetMaxAttestNo(CompanyCD, DateTime.Now.ToString("yyyy-MM-dd")); //凭证号 Model.Creator = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID; //制单人 Model.CreateDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); //制单日期 Model.FromTbale = FromTBInfo.Split(',')[0].ToString(); //来源表名 Model.FromValue = FromTBInfo.Split(',')[1].ToString(); //来源表主键 Model.CompanyCD = CompanyCD; Model.FromName = ""; foreach (DataRow row in tempdt.Rows) //根据凭证模板构建凭证明细数组 { AttestBillDetailsModel DetailModel = new AttestBillDetailsModel(); //凭证明细表实例 DetailModel.Abstract = dt.Rows[0]["Abstract"].ToString(); //摘要 DetailModel.CurrencyTypeID = int.Parse(CurrencyInfo.Split(',')[0].ToString()); //币种 DetailModel.ExchangeRate = Convert.ToDecimal(CurrencyInfo.Split(',')[1].ToString()); //汇率 DetailModel.SubjectsCD = row["SubjectsNo"].ToString(); //科目编号 decimal orgAmount = BillAmount * Convert.ToDecimal(row["Scale"].ToString()) / 100; DetailModel.OriginalAmount = orgAmount; //原币金额 if (row["Direction"].ToString() == "0") { DetailModel.DebitAmount = orgAmount * Convert.ToDecimal(CurrencyInfo.Split(',')[1].ToString()); //借方金额 DetailModel.CreditAmount = 0; //贷方金额 } else { DetailModel.DebitAmount = 0; //借方金额 DetailModel.CreditAmount = orgAmount * Convert.ToDecimal(CurrencyInfo.Split(',')[1].ToString()); //贷方金额 } string Auciliary = VoucherDBHelper.GetSubjectsAuciliaryCD(row["SubjectsNo"].ToString(), CompanyCD); DetailModel.SubjectsDetails = ""; DetailModel.FormTBName = ""; DetailModel.FileName = ""; if (Auciliary == "供应商" || Auciliary == "客户") { DetailModel.SubjectsDetails = ProOrCustID.ToString();//辅助核算 if (Auciliary == "供应商") { DetailModel.FormTBName = "officedba.ProviderInfo"; DetailModel.FileName = "CustName"; } else { DetailModel.FormTBName = "officedba.CustInfo"; DetailModel.FileName = "CustName"; } } DetailList.Add(DetailModel); } if (VoucherDBHelper.InsertIntoAttestBill(Model, DetailList, out BillID, "0"))//自动生成凭证并根据IsApply判断是否登帐 --生成成功 { /*更新原始业务单登记凭证状态 start*/ StringBuilder UpdateSourceTB = new StringBuilder(); UpdateSourceTB.AppendLine("update {0} set IsAccount=@IsAccount,AccountDate=@AccountDate, "); UpdateSourceTB.AppendLine("Accountor=@Accountor , AttestBillID=@AttestBillID "); UpdateSourceTB.AppendLine(" where ID=@ID "); string UpdateSourceTBSQL = string.Format(UpdateSourceTB.ToString(), FromTBInfo.Split(',')[0].ToString()); SqlParameter[] parms = { new SqlParameter("@IsAccount", "1"), new SqlParameter("@AccountDate", DateTime.Now.ToString("yyyy-MM-dd")), new SqlParameter("@Accountor", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID.ToString()), new SqlParameter("@AttestBillID", BillID.ToString()), new SqlParameter("@ID", FromTBInfo.Split(',')[1].ToString()) }; if (SqlHelper.ExecuteTransSql(UpdateSourceTBSQL, parms) > 0)//更新业务单成功 { // } else { returnValue = " 警告:自动生成凭证失败!"; rev = false; //删除凭证操作开始 VoucherDBHelper.DeleteAttestBillInfo(BillID.ToString()); //删除凭证操作结束 } /*更新原始业务单登记凭证状态 End*/ if (IsApply == "1")//自动生成凭证是否自动登帐 --否 { if (!VoucherDBHelper.InsertAccount(BillID)) { returnValue = " 警告:自动生成凭证失败!"; rev = false; //删除凭证操作开始 VoucherDBHelper.DeleteAttestBillInfo(BillID.ToString()); //删除凭证操作结束 /*更新原始业务单登记凭证状态 start*/ StringBuilder AntiUpdateSourceTB = new StringBuilder(); AntiUpdateSourceTB.AppendLine("update {0} set IsAccount=@IsAccount,AccountDate=@AccountDate, "); AntiUpdateSourceTB.AppendLine("Accountor=@Accountor , AttestBillID=@AttestBillID "); AntiUpdateSourceTB.AppendLine(" where ID=@ID "); string AntiUpdateSourceTBSQL = string.Format(UpdateSourceTB.ToString(), FromTBInfo.Split(',')[0].ToString()); SqlParameter[] Antiparms = { new SqlParameter("@IsAccount", "0"), new SqlParameter("@AccountDate", DateTime.Now.ToString("yyyy-MM-dd")), new SqlParameter("@Accountor", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID.ToString()), new SqlParameter("@AttestBillID", BillID.ToString()), new SqlParameter("@ID", FromTBInfo.Split(',')[1].ToString()) }; SqlHelper.ExecuteTransSql(AntiUpdateSourceTBSQL, Antiparms);//更新业务单成功 /*更新原始业务单登记凭证状态 End*/ } } } else { returnValue = " 警告:自动生成凭证失败!"; rev = false; } } } else { //未设置模板 returnValue = "警告:自动生成凭证失败,请在“财务管理-初始设置”中设置或启用对应的凭证模板!"; rev = false; } } returnV = returnValue; return(rev); }