コード例 #1
0
        public static bool ConfirmFees(string OrderNO,FeesModel FeesM, List<FeesDetailModel> FeesDetailM, out string strMsg)
        {
            string  CompanyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
            string strSq = string.Empty;
            bool isSuc = false;
            strMsg = "";
            //判断单据是否为制单状态,非制单状态不能确认
            if (isHandle(OrderNO, "0"))
            {
                //TransactionManager tran = new TransactionManager();
                //tran.BeginTransaction();
                try
                {                   
                    //判断是否启用自动生成凭证
                    //((UserInfoUtil)SessionUtil.Session["UserInfo"]).IsApply;//自动审核登帐
                    //((UserInfoUtil)SessionUtil.Session["UserInfo"]).IsVoucher;//自动生成凭证
                    if (((UserInfoUtil)SessionUtil.Session["UserInfo"]).IsVoucher == true)
                    {
                        AttestBillModel Model = new AttestBillModel();//凭证主表实例
                        ArrayList DetailList = new ArrayList();//凭证明细数组
                        Model.CompanyCD = CompanyCD;
                        Model.FromName = "";
                        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 = "officedba.Fees";//来源表名
                        Model.FromValue = FeesM.ID;//来源表主键

                        AttestBillDetailsModel DetailModel = new AttestBillDetailsModel();//凭证明细表实例
                        DetailModel.Abstract = FeesM.Note;// dt.Rows[0]["Abstract"].ToString();//摘要
                        DetailModel.CurrencyTypeID = Convert.ToInt32(FeesM.CurrencyType); //币种
                        DetailModel.ExchangeRate = FeesM.CurrencyRate;//汇率
                        DetailModel.SubjectsCD = FeesM.SubjectsNo;//科目编号
                        DetailModel.OriginalAmount = FeesM.TotalPrice;//原币金额
                        DetailModel.DebitAmount = 0;//借方金额
                        DetailModel.CreditAmount = FeesM.TotalPrice * Convert.ToDecimal(FeesM.CurrencyRate);//贷方金额

                        DetailModel.SubjectsDetails = "";
                        DetailModel.FormTBName = "";
                        DetailModel.FileName = "";
                        string Auciliary = VoucherDBHelper.GetSubjectsAuciliaryCD(FeesM.SubjectsNo, CompanyCD);

                        if (Auciliary == "供应商" || Auciliary == "客户" || Auciliary == "职员")
                        {
                            DetailModel.SubjectsDetails = FeesM.ContactUnits;//辅助核算
                            if (Auciliary == "供应商")
                            {
                                DetailModel.FormTBName = "officedba.ProviderInfo";
                                DetailModel.FileName = "CustName";
                            }
                            else if (Auciliary == "客户")
                            {
                                DetailModel.FormTBName = "officedba.CustInfo";
                                DetailModel.FileName = "CustName";
                            }
                            else
                            {
                                DetailModel.FormTBName = "officedba.EmployeeInfo";
                                DetailModel.FileName = "EmployeeName";
                            }
                        }
                        DetailList.Add(DetailModel);


                        //foreach (DataRow row in tempdt.Rows)//根据凭证模板构建凭证明细数组
                        foreach (FeesDetailModel FDetailM in FeesDetailM)
                        {
                            AttestBillDetailsModel DetailM = new AttestBillDetailsModel();//凭证明细表实例
                            DetailM.Abstract = FeesM.Note;//摘要
                            DetailM.CurrencyTypeID = Convert.ToInt32(FeesM.CurrencyType);//币种
                            DetailM.ExchangeRate = FeesM.CurrencyRate;//汇率
                            DetailM.SubjectsCD = FDetailM.SubjectsNo;//科目编号
                            DetailM.OriginalAmount = FDetailM.FeeTotal;//原币金额
                            DetailM.DebitAmount = FDetailM.FeeTotal * Convert.ToDecimal(FeesM.CurrencyRate);//借方金额
                            DetailM.CreditAmount = 0;//贷方金额

                            DetailM.SubjectsDetails = "";
                            DetailM.FormTBName = "";
                            DetailM.FileName = "";

                            DetailList.Add(DetailM);
                        }

                        //自动生成凭证并根据IsApply判断是否登帐 --生成成功
                        int BillID = 0;
                        string IsA = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).IsApply == true ? "1" : "0";
                        if (VoucherDBHelper.InsertIntoAttestBill(Model, DetailList, out BillID, IsA))
                        {

                            SqlParameter[] paras = new SqlParameter[3];
                            strSq = "update  officedba.Fees set ConfirmStatus='1' , Confirmor=@EmployeeID, ";
                            strSq += " ConfirmDate=getdate(),IsAccount='1',Accountor=@EmployeeID,AccountDate=getdate() ";

                            paras[0] = new SqlParameter("@EmployeeID", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID);
                            paras[1] = new SqlParameter("@CompanyCD", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD);
                            paras[2] = new SqlParameter("@FeesNo", OrderNO);

                            strSq += " WHERE FeesNo  = @FeesNo  and CompanyCD=@CompanyCD";

                            //SqlHelper.ExecuteNonQuery(tran.Trans, CommandType.Text, strSq, paras);
                            SqlHelper.ExecuteTransSql(strSq.ToString(), paras);
                            if (SqlHelper.Result.OprateCount > 0)
                            {
                                isSuc = true;
                                strMsg = "确认成功!";
                            }
                            else
                            {
                                isSuc = false;
                                strMsg = "生成凭证失败!";
                            }
                        }
                    }
                    else
                    {
                        SqlParameter[] paras = new SqlParameter[3];
                        strSq = "update  officedba.Fees set ConfirmStatus='1' , Confirmor=@EmployeeID, ";
                        strSq += " ConfirmDate=getdate() ";

                        paras[0] = new SqlParameter("@EmployeeID", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID);
                        paras[1] = new SqlParameter("@CompanyCD", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD);
                        paras[2] = new SqlParameter("@FeesNo", OrderNO);

                        strSq += " WHERE FeesNo  = @FeesNo  and CompanyCD=@CompanyCD";

                        SqlHelper.ExecuteTransSql(strSq.ToString(), paras);
                        if (SqlHelper.Result.OprateCount > 0)
                        {
                            isSuc = true;
                            strMsg = "确认成功!";
                        }
                        else
                        {
                            isSuc = false;
                            strMsg = "确认失败!";
                        }
                    }
                }
                catch (Exception ex)
                {
                    
                    //tran.Rollback();

                    isSuc = false;
                    strMsg = "确认失败,请联系系统管理员!";
                    throw ex;
                }
            }
            else
            {
                isSuc = false;
                strMsg = "该单据已被其他用户确认,不可再次确认!";
            }
            return isSuc;
        }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
        public static bool EndExchangeRate(string[] CurrTypeRate,
            string ItemID, string PeriodNum, ref string AttestNo, ref int AttestID,string DuringDate)
        {
            if (CurrTypeRate == null) return false;
            bool result = false;
            //获取当前企业代码
            string CompanyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
            try
            {
                #region 凭证实体
                //实例凭证单据实体对象
                AttestBillModel Attestmodel = new AttestBillModel();
                //凭证明细实体定义
                AttestBillDetailsModel Detailmodel = null;
                #endregion
                //汇总总金额
                decimal SumTotalPrice = 0;
                //登帐凭证ID号
                string EndAccountID = string.Empty;
                //凭证单据ID
                int ID;
                //会计科目代码
                string SubjectsCD = string.Empty;
                //定义数组存储实体对象
                ArrayList modelList = new ArrayList();

                //获取本币币种ID
                int MasterCurrencyID = Convert.ToInt32(CurrTypeSettingDBHelper.GetMasterCurrency(CompanyCD).Rows[0]["ID"]);
                //获取结转汇兑损益摘要ID

                /*修改于20090604 摘要直接存名称 by 莫申林  start*/
                //int AbstractID;
                //AbstractID = Convert.ToInt32(SummarySettingBus.GetSummaryIDByName(ConstUtil.SUMMARY_JZHDSY_NAME));
                string AbstractID;
                AbstractID = ConstUtil.SUMMARY_JZHDSY_NAME;
                /*修改于20090604 摘要直接存名称 by 莫申林  end*/

                //对输入的资料日期进行处理开始
                //开始时间
                string StartDate = string.Empty;
                //结束时间
                string EndDate = string.Empty;
                string DayEnd = string.Empty;//月末数
                int MothString = Convert.ToInt32(DuringDate.Split('-')[1].ToString());
                int yearString = Convert.ToInt32(DuringDate.Split('-')[0].ToString());
                if (MothString == 4 || MothString == 6 || MothString == 9 || MothString == 11)
                {
                    DayEnd = "-30";
                }
                else if (MothString == 2)
                {
                    if (((yearString % 4 == 0 && yearString % 100 == 0)) || (yearString % 400 == 0))
                    {
                        DayEnd = "-29";
                    }
                    else
                    {
                        DayEnd = "-28";
                    }
                }
                else
                {
                    DayEnd = "-31";
                }
                StartDate = yearString.ToString() + "-" + MothString.ToString() + "-01";
                EndDate = yearString.ToString() + "-" + MothString.ToString() + DayEnd;
                foreach (string array in CurrTypeRate)
                {
                    decimal TempPrice = 0;
                    string[] Currency = array.Split(',');
                    DataTable dt = EndItemProcessing.GetAccountBookEndAmount(CompanyCD, MasterCurrencyID, Convert.ToInt32(Currency[0]),StartDate,EndDate);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        foreach (DataRow rows in dt.Rows)
                        {
                            //外币本币期末余额
                            decimal WbEndAmount, BbEndAmount = 0;
                            //读取外币期末余额
                            WbEndAmount = Convert.ToDecimal(rows["wbEndAmount"]);
                            //读取本币期末余额
                            BbEndAmount = Convert.ToDecimal(rows["EndAmount"]);
                            //计算利率后的金额
                            decimal TotalPrice = WbEndAmount * (Convert.ToDecimal(Currency[1])) - BbEndAmount;
                            SumTotalPrice += TotalPrice;
                            TempPrice += TotalPrice;

                            #region 科目凭证明细赋值
                            if (TotalPrice != 0)
                            {
                                Detailmodel = new AttestBillDetailsModel();//实例凭证明细实体对象
                                // Detailmodel.AttestBillID = ID;
                                Detailmodel.Abstract = AbstractID; //摘要ID
                                Detailmodel.SubjectsCD = rows["SubjectsCD"].ToString();//库存现金科目
                                if (TotalPrice > 0)
                                {
                                    Detailmodel.DebitAmount = TotalPrice;//借方金额
                                    Detailmodel.CreditAmount = 0;//贷方金额
                                }
                                else
                                {
                                    Detailmodel.DebitAmount = 0;//借方金额为0
                                    //Modified 2009-06-26
                                    TotalPrice = Convert.ToDecimal(TotalPrice.ToString().Substring(TotalPrice.ToString().IndexOf("-") + 1, TotalPrice.ToString().Length - TotalPrice.ToString().IndexOf("-") - 1));
                                    Detailmodel.CreditAmount = TotalPrice;//贷方金额
                                }
                                Detailmodel.CurrencyTypeID = MasterCurrencyID;
                                //Detailmodel.CurrencyTypeID = Convert.ToInt32(Currency[0]);//币种
                                Detailmodel.OriginalAmount = TotalPrice;//原币金额
                                //Modified 2009-06-26
                                //  Detailmodel.ExchangeRate = Convert.ToDecimal(Currency[1]);//汇率
                                Detailmodel.ExchangeRate = 1;
                                //明细实体对象添加到数组中
                                modelList.Add(Detailmodel);
                            }
                           #endregion
                        }
                        #region 2009-06-07 Modified by jiangym
                        //if (TempPrice != 0)
                        //{
                        //    #region 本年利润凭证明细赋值
                        //    Detailmodel = new AttestBillDetailsModel();//实例本年利润凭证明细实体对象
                        //  //  Detailmodel.AttestBillID = ID;
                        //    Detailmodel.Abstract = AbstractID; //摘要ID
                        //    Detailmodel.SubjectsCD = SUBJECT_CD_KCXJ_CODE;//库存现金科目
                        //    if (TempPrice > 0)
                        //    {
                        //        Detailmodel.DebitAmount = TempPrice;//借方金额
                        //        Detailmodel.CreditAmount = 0;//贷方金额
                        //    }
                        //    else
                        //    {
                        //        Detailmodel.DebitAmount = 0;//借方金额为0
                        //        //Modified 2009-06-26
                        //        TempPrice = Convert.ToDecimal(TempPrice.ToString().Substring(TempPrice.ToString().IndexOf("-") + 1, TempPrice.ToString().Length - TempPrice.ToString().IndexOf("-") - 1));

                        //        Detailmodel.CreditAmount = TempPrice;//贷方金额
                        //    }
                        //    Detailmodel.CurrencyTypeID = MasterCurrencyID;

                        //  //  Detailmodel.CurrencyTypeID = Convert.ToInt32(Currency[0]);//币种
                        //    Detailmodel.OriginalAmount = TempPrice;//原币金额

                        //    //Modified 2009-06-26

                        //    Detailmodel.ExchangeRate = 1;
                        //   // Detailmodel.ExchangeRate = Convert.ToDecimal(Currency[1]);//汇率


                        //    //明细实体对象添加到数组中
                        //    modelList.Add(Detailmodel);
                        //    #endregion
                        //}
                        #endregion
                    }


                }

                #region 生成汇兑损益明细
                if (SumTotalPrice != 0)
                {
                    Detailmodel = new AttestBillDetailsModel();
                    //  Detailmodel.AttestBillID = ID;
                    Detailmodel.Abstract = AbstractID; //摘要ID
                    Detailmodel.SubjectsCD = SUBJECT_CD_HDSY_CODE;//汇兑损益科目
                    if (SumTotalPrice > 0)
                    {
                        Detailmodel.DebitAmount = 0;//借方金额为0
                        Detailmodel.CreditAmount = SumTotalPrice;//贷方金额
                    }
                    else
                    {
                        SumTotalPrice = Convert.ToDecimal(SumTotalPrice.ToString().Substring(SumTotalPrice.ToString().IndexOf("-") + 1, SumTotalPrice.ToString().Length - SumTotalPrice.ToString().IndexOf("-") - 1));
                        Detailmodel.DebitAmount = SumTotalPrice;//借方金额

                        //Modified 2009-06-26
                    
                        Detailmodel.CreditAmount = 0;//贷方金额为0
                    }
                    Detailmodel.CurrencyTypeID = MasterCurrencyID;//本币类别
                    Detailmodel.OriginalAmount = SumTotalPrice;//原币金额
                    Detailmodel.ExchangeRate = 1;//汇率
                    //明细实体对象添加到数组中
                    modelList.Add(Detailmodel);
                }
                #endregion
                //判断是否有凭证明细
                if (modelList.Count > 0)
                {
                    #region 凭证单据实体赋值
                    int PeriodRecordID=0;

                    result = EndItemProcessing.InsertPeriodProced(CompanyCD, ItemID,PeriodNum,"1",out   PeriodRecordID);
                    if (result)
                    {
                        Attestmodel.CompanyCD = CompanyCD;
                        //获取生成的凭证号
                        Attestmodel.AttestNo = "记-" + VoucherDBHelper.GetMaxAttestNo(CompanyCD, DateTime.Now.ToString());
                        AttestNo = Attestmodel.AttestNo;
                        Attestmodel.VoucherDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                        Attestmodel.AttestName = "记账凭证";
                        Attestmodel.Creator = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID;
                        Attestmodel.status = 0;
                        Attestmodel.FromTbale = "officedba.EndItemProcessedRecord";
                        if (PeriodRecordID > 0)
                        {
                            Attestmodel.FromValue = PeriodRecordID.ToString();
                        }
                        else
                        {
                            Attestmodel.FromValue = "";
                        }
                    }
                    //添加凭证单据信息
                    result = EndItemProcessing.BuildAttestBill(Attestmodel, out ID);
                    AttestID = ID;
                    if (result)
                    {
                        //遍历明细实体给单据编号赋值
                        for (int j = 0; j < modelList.Count; j++)
                        {
                            (modelList[j] as AttestBillDetailsModel).AttestBillID = ID;
                        }
                    }
                    #endregion
                }

                result = EndItemProcessing.BuildEndRatechangeDetailInfo(modelList);
                if (modelList.Count > 0)
                {
                    if (result)
                    {
                        VoucherBus.SetStatus(AttestID.ToString(), "1", "status", 0);
                        VoucherBus.InsertAccount(AttestID);
                    }
                }
                //凭证自动登帐及自动审核
           
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
        /// <summary>
        /// 损益科目期末结转
        /// </summary>
        /// <param name="ItemID"></param>
        /// <param name="PeriodNum"></param>
        /// <param name="getAttestNo"></param>
        /// <param name="AttestID"></param>
        /// <param name="DuringDate"></param>
        /// <returns></returns>
        public static bool ProfitandLossMade(string ItemID, string PeriodNum, ref string getAttestNo, ref string AttestID, string DuringDate)
        {
            try
            {
                string CompanyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
                bool result = false;

                 //开始时间
                string StartDate = string.Empty;
                //结束时间
                string EndDate = string.Empty;
                //月末数
                string DayEnd = string.Empty;
                int MothString = Convert.ToInt32(DuringDate.Split('-')[1].ToString());
                int yearString = Convert.ToInt32(DuringDate.Split('-')[0].ToString());
                if (MothString == 4 || MothString == 6 || MothString == 9 || MothString == 11)
                {
                    DayEnd = "-30";
                }
                else if (MothString == 2)
                {
                    if (((yearString % 4 == 0 && yearString % 100 == 0)) || (yearString % 400 == 0))
                    {
                        DayEnd = "-29";
                    }
                    else
                    {
                        DayEnd = "-28";
                    }
                }
                else
                {
                    DayEnd = "-31";
                }
                StartDate = yearString.ToString() + "-" + MothString.ToString() + "-01";
                EndDate = yearString.ToString() + "-" + MothString.ToString() + DayEnd;
                if (!CheckProfitEndAmount(StartDate, EndDate))
                {

                    //获取本币币种ID
                    int CurrencyID = Convert.ToInt32(CurrTypeSettingDBHelper.GetMasterCurrency(CompanyCD).Rows[0]["ID"]);
                    //获取结转本期损益摘要ID
                    // 修改于20090604 摘要直接存名称 by 莫申林
                    /*修改于20090604 摘要直接存名称 by 莫申林  start*/
                    //int AbstractID;
                    //AbstractID = Convert.ToInt32(SummarySettingBus.GetSummaryIDByName(ConstUtil.SUMMARY_JZBQSY_NAMEA));
                    string AbstractID;
                    AbstractID = ConstUtil.SUMMARY_JZBQSY_NAMEA;
                    /*修改于20090604 摘要直接存名称 by 莫申林  end*/


                    AttestBillModel Attestmodel = new AttestBillModel(); //实例凭证单据实体对象
                    #region 凭证单据实体赋值
                    Attestmodel.CompanyCD = CompanyCD;
                   
                    Attestmodel.AttestName = "记账凭证";
                    Attestmodel.Creator = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID;
                    Attestmodel.status = 0;
                    Attestmodel.FromTbale = "officedba.EndItemProcessedRecord";
                    //   Attestmodel.FromValue = ItemID;
                    Attestmodel.VoucherDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                    Attestmodel.CreateDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                    Attestmodel.Attachment = 0;
                    Attestmodel.FromName = "ProfitandLoss";
                    #region 更新期末处理结转损益状态
                    int PeriodRecordID = 0;
                    result = EndItemProcessing.InsertPeriodProced(CompanyCD, ItemID, PeriodNum, "1", out  PeriodRecordID);
                    #endregion

                    if (PeriodRecordID > 0)
                    {
                        Attestmodel.FromValue = PeriodRecordID.ToString();
                    }
                    else
                    {
                        Attestmodel.FromValue = "";
                    }
                    #endregion

                    DataTable sourcedt = GetProfitandLossInfo(StartDate, EndDate);//获取账簿中所有损益类科目的期末余额
                    DataTable debitdt = GetChangeDt(sourcedt, 0);//期末余额为借方的损益类科目信息数据集
                    DataTable creditdt = GetChangeDt(sourcedt, 1);//期末余额为贷方的损益类科目信息数据集

                    
                    if (debitdt != null && debitdt.Rows.Count > 0)
                    {
                        decimal Money = 0;
                        int VouchreID = 0;
                        ArrayList MyList = new ArrayList();
                        Attestmodel.AttestNo = "记-" + VoucherDBHelper.GetMaxAttestNo(CompanyCD, DateTime.Now.ToString("yyyy-MM-dd"));
                        getAttestNo += Attestmodel.AttestNo + ",";


                        foreach (DataRow dr in debitdt.Rows)
                        {
                            AttestBillDetailsModel Detailmodel = new AttestBillDetailsModel();//凭证明细实体定义
                            Detailmodel.Abstract = AbstractID;//摘要ID
                            Detailmodel.SubjectsCD = dr["SubjectsCD"].ToString();
                            Detailmodel.CurrencyTypeID = CurrencyID;
                            Detailmodel.ExchangeRate = 1;
                            Detailmodel.CreditAmount = Convert.ToDecimal(dr["EndM"].ToString()); //贷方金额
                            Detailmodel.OriginalAmount = Convert.ToDecimal(dr["EndM"].ToString());//外币金额
                            Detailmodel.DebitAmount = 0; //借方金额
                            Detailmodel.SubjectsDetails = "";
                            Detailmodel.FormTBName = "";
                            Detailmodel.FileName = "";
                            Money += Convert.ToDecimal(dr["EndM"].ToString());
                            MyList.Add(Detailmodel);

                        }

                        #region 本年利润凭证明细赋值
                        AttestBillDetailsModel AttestDetailmodel = new AttestBillDetailsModel();//凭证明细实体定义
                        AttestDetailmodel.Abstract = AbstractID;//摘要ID
                        AttestDetailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目
                        AttestDetailmodel.DebitAmount = Money;//借方金额
                        AttestDetailmodel.CurrencyTypeID = CurrencyID;
                        AttestDetailmodel.ExchangeRate = 1;
                        AttestDetailmodel.CreditAmount = 0;//贷方金额
                        AttestDetailmodel.OriginalAmount = Money;//外币金额
                        AttestDetailmodel.SubjectsDetails = "";
                        AttestDetailmodel.FormTBName = "";
                        AttestDetailmodel.FileName = "";
                        //本年利润实体对象添加到数组中
                        MyList.Add(AttestDetailmodel);
                        #endregion

                        result=VoucherBus.InsertIntoAttestBill(Attestmodel, MyList, out VouchreID, "1");
                        AttestID += VouchreID + ",";
                    }


                    if (creditdt != null && creditdt.Rows.Count > 0)
                    {
                        decimal Money = 0;
                        int VouchreID = 0;
                        ArrayList MyList = new ArrayList();
                        Attestmodel.AttestNo = "记-" + VoucherDBHelper.GetMaxAttestNo(CompanyCD, DateTime.Now.ToString("yyyy-MM-dd"));
                        getAttestNo += Attestmodel.AttestNo + ",";


                        foreach (DataRow dr in creditdt.Rows)
                        {
                            AttestBillDetailsModel Detailmodel = new AttestBillDetailsModel();//凭证明细实体定义
                            Detailmodel.Abstract = AbstractID;//摘要ID
                            Detailmodel.SubjectsCD = dr["SubjectsCD"].ToString();
                            Detailmodel.CurrencyTypeID = CurrencyID;
                            Detailmodel.ExchangeRate = 1;
                            Detailmodel.CreditAmount = 0; //贷方金额
                            Detailmodel.OriginalAmount = Convert.ToDecimal(dr["EndM"].ToString());//外币金额
                            Detailmodel.DebitAmount = Convert.ToDecimal(dr["EndM"].ToString()); //借方金额
                            Detailmodel.SubjectsDetails = "";
                            Detailmodel.FormTBName = "";
                            Detailmodel.FileName = "";
                            Money += Convert.ToDecimal(dr["EndM"].ToString());
                            MyList.Add(Detailmodel);

                        }

                        #region 本年利润凭证明细赋值
                        AttestBillDetailsModel AttestDetailmodel = new AttestBillDetailsModel();//凭证明细实体定义
                        AttestDetailmodel.Abstract = AbstractID;//摘要ID
                        AttestDetailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目
                        AttestDetailmodel.DebitAmount = 0;//借方金额
                        AttestDetailmodel.CurrencyTypeID = CurrencyID;
                        AttestDetailmodel.ExchangeRate = 1;
                        AttestDetailmodel.CreditAmount = Money;//贷方金额
                        AttestDetailmodel.OriginalAmount = Money;//外币金额
                        AttestDetailmodel.SubjectsDetails = "";
                        AttestDetailmodel.FormTBName = "";
                        AttestDetailmodel.FileName = "";
                        //本年利润实体对象添加到数组中
                        MyList.Add(AttestDetailmodel);
                        #endregion

                        result=VoucherBus.InsertIntoAttestBill(Attestmodel, MyList, out VouchreID, "1");
                        AttestID += VouchreID + ",";
                    }
                }
                AttestID = AttestID.TrimEnd(new char[] { ',' });
                getAttestNo = getAttestNo.TrimEnd(new char[] { ',' });
                return result;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #5
0
        public static bool ProfitandLossChange(string ItemID, string PeriodNum,
            ref string getAttestNo, ref int AttestID, string DuringDate)
        {
            bool result = false;
            string CompanyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
            try
            {
                #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 = "officedba.EndItemProcessedRecord";
             //   Attestmodel.FromValue = ItemID;
                Attestmodel.VoucherDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));

                #endregion
                int ID;
                ArrayList modelList = new ArrayList();//定义数组存储实体对象
                //添加凭证单据信息

                //开始时间
                string StartDate = string.Empty;
                //结束时间
                string EndDate = string.Empty;
                //月末数
                string DayEnd = string.Empty;
                int MothString = Convert.ToInt32(DuringDate.Split('-')[1].ToString());
                int yearString = Convert.ToInt32(DuringDate.Split('-')[0].ToString());
                if (MothString == 4 || MothString == 6 || MothString == 9 || MothString == 11)
                {
                    DayEnd = "-30";
                }
                else if (MothString == 2)
                {
                    if (((yearString % 4 == 0 && yearString % 100 == 0)) || (yearString % 400 == 0))
                    {
                        DayEnd = "-29";
                    }
                    else
                    {
                        DayEnd = "-28";
                    }
                }
                else
                {
                    DayEnd = "-31";
                }
                StartDate = yearString.ToString() + "-" + MothString.ToString() + "-01";
                EndDate = yearString.ToString() + "-" + MothString.ToString() + DayEnd;
                if (!CheckProfitEndAmount(StartDate,EndDate))
                {
                    #region 凭证单据实体赋值
                    int PeriodRecordID = 0;

                    result = EndItemProcessing.InsertPeriodProced(CompanyCD, ItemID, PeriodNum, "1", out  PeriodRecordID);
                    if (PeriodRecordID > 0)
                    {
                        Attestmodel.FromValue = PeriodRecordID.ToString();
                    }
                    else
                    {
                        Attestmodel.FromValue = "";
                    }


                    result = EndItemProcessing.BuildAttestBill(Attestmodel, out ID);
                    AttestID = ID;
                    //损益类方向为借的ID
                    string AccountIDj = string.Empty;
                    //损益类方向为贷的ID
                    string AccountIDd = string.Empty;
                    //获取本币币种ID
                    int CurrencyID = Convert.ToInt32(CurrTypeSettingDBHelper.GetMasterCurrency(CompanyCD).Rows[0]["ID"]);
                    //获取结转本期损益摘要ID
                    #region 修改于20090604 摘要直接存名称 by 莫申林
                    /*修改于20090604 摘要直接存名称 by 莫申林  start*/
                    //int AbstractID;
                    //AbstractID = Convert.ToInt32(SummarySettingBus.GetSummaryIDByName(ConstUtil.SUMMARY_JZBQSY_NAMEA));
                    string AbstractID;
                    AbstractID = ConstUtil.SUMMARY_JZBQSY_NAMEA;
                    /*修改于20090604 摘要直接存名称 by 莫申林  end*/

               

                    #endregion
                    if (result && ID > 0)
                    {
                        //取出损益类科目方向为借的信息
                        DataTable dtJ = EndItemProcessing.GetSYSubjectsEndAmount(CompanyCD, DIRECTION_J, StartDate,EndDate);
                        if (dtJ != null && dtJ.Rows.Count > 0)
                        {
                            //读取AccountIDj
                            foreach (DataRow rowj in dtJ.Rows)
                            {
                                AccountIDj += rowj["ID"].ToString() + ",";
                            }
                            AccountIDj = AccountIDj.Remove(AccountIDj.Length - 1);
                            //取出损益类方向为借的期末余额
                            DataTable dtJEndAmount = EndItemProcessing.GetSYEndAmountByID(AccountIDj);
                            if (dtJEndAmount != null && dtJEndAmount.Rows.Count > 0)
                            {
                                //读取方向为借的期末余额
                                foreach (DataRow jendrow in dtJEndAmount.Rows)
                                {
                                    if (Convert.ToDecimal(jendrow["EndAmount"]) != 0)
                                    {

                                        #region 明细实体赋值
                                        Detailmodel = new AttestBillDetailsModel();//实例凭证明细实体对象
                                        Detailmodel.AttestBillID = ID;
                                        Detailmodel.CurrencyTypeID = CurrencyID;
                                        Detailmodel.Abstract = AbstractID;//摘要ID
                                        Detailmodel.SubjectsCD = jendrow["SubjectsCD"].ToString();
                                        //判断损益科目方向为借的金额统计是否大于0
                                        //大于则为贷否则为借方

                                        if (Convert.ToDecimal(jendrow["EndAmount"]) > 0)
                                        {
                                            Detailmodel.OriginalAmount = Convert.ToDecimal(jendrow["EndAmount"]);//外币金额
                                            Detailmodel.CreditAmount = Convert.ToDecimal(jendrow["EndAmount"]);//贷方金额
                                            Detailmodel.DebitAmount = 0;
                                            //将损益类科目方向为借的逆向生成的实体添加到数组当中
                                            modelList.Add(Detailmodel);//实体对象添加到数组中

                                            #region 本年利润凭证明细赋值
                                            Detailmodel = new AttestBillDetailsModel();//实例本年利润凭证明细实体对象
                                            Detailmodel.AttestBillID = ID;
                                            Detailmodel.CurrencyTypeID = CurrencyID;
                                            Detailmodel.Abstract = AbstractID;//摘要ID
                                            Detailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目

                                            Detailmodel.OriginalAmount = Convert.ToDecimal(jendrow["EndAmount"]);//外币金额
                                            Detailmodel.DebitAmount = Convert.ToDecimal(jendrow["EndAmount"]);//借方金额
                                            Detailmodel.CreditAmount = 0;//贷方金额为0

                                            //本年利润实体对象添加到数组中
                                            modelList.Add(Detailmodel);
                                            #endregion

                                        }
                                        else
                                        {
                                            decimal EndAmount = Convert.ToDecimal(jendrow["EndAmount"]);
                                            EndAmount = Convert.ToDecimal(EndAmount.ToString().Substring(EndAmount.ToString().IndexOf("-") + 1, EndAmount.ToString().Length - EndAmount.ToString().IndexOf("-") - 1));

                                            //Detailmodel.OriginalAmount = Convert.ToDecimal(jendrow["EndAmount"]);//外币金额
                                            //Detailmodel.DebitAmount = Convert.ToDecimal(jendrow["EndAmount"]);//借方金额
                                            //Detailmodel.CreditAmount = 0;//贷方金额为0
                                            //modelList.Add(Detailmodel);//实体对象添加到数组中

                                            //#region 本年利润凭证明细赋值
                                            //Detailmodel = new AttestBillDetailsModel();//实例本年利润凭证明细实体对象
                                            //Detailmodel.AttestBillID = ID;
                                            //Detailmodel.Abstract = AbstractID;//摘要ID
                                            //Detailmodel.CurrencyTypeID = CurrencyID;
                                            //Detailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目
                                            //Detailmodel.CreditAmount = Convert.ToDecimal(jendrow["EndAmount"]);//贷方金额
                                            //Detailmodel.OriginalAmount = Convert.ToDecimal(jendrow["EndAmount"]);//外币金额
                                            //Detailmodel.DebitAmount = 0;//借方金额为0


                                            Detailmodel.OriginalAmount = EndAmount;//外币金额
                                            Detailmodel.DebitAmount = EndAmount;//借方金额
                                            Detailmodel.CreditAmount = 0;//贷方金额为0
                                            modelList.Add(Detailmodel);//实体对象添加到数组中

                                            #region 本年利润凭证明细赋值
                                            Detailmodel = new AttestBillDetailsModel();//实例本年利润凭证明细实体对象
                                            Detailmodel.AttestBillID = ID;
                                            Detailmodel.Abstract = AbstractID;//摘要ID
                                            Detailmodel.CurrencyTypeID = CurrencyID;
                                            Detailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目
                                            Detailmodel.CreditAmount = EndAmount;//贷方金额
                                            Detailmodel.OriginalAmount = EndAmount; //外币金额
                                            Detailmodel.DebitAmount = 0;//借方金额为0


                                            //本年利润实体对象添加到数组中
                                            modelList.Add(Detailmodel);
                                            #endregion
                                        }
                                        #endregion
                                    }
                                }
                            }
                        }
                        //取出损益类科目方向为贷的信息
                        DataTable dtD = EndItemProcessing.GetSYSubjectsEndAmount(CompanyCD, DIRECTION_D,StartDate,EndDate);
                        if (dtD != null && dtD.Rows.Count > 0)
                        {
                            //读取AccountIDd
                            foreach (DataRow rowd in dtD.Rows)
                            {
                                AccountIDd += rowd["ID"].ToString() + ",";
                            }
                            AccountIDd = AccountIDd.Remove(AccountIDd.Length - 1);
                            //取出损益类方向为贷的期末余额
                            DataTable dtDEndAmount = EndItemProcessing.GetSYEndAmountByID(AccountIDd);
                            if (dtDEndAmount != null && dtDEndAmount.Rows.Count > 0)
                            {
                                //读取方向为贷的期末余额
                                foreach (DataRow Dendrow in dtDEndAmount.Rows)
                                {
                                    #region 明细实体赋值
                                    if (Convert.ToDecimal(Dendrow["EndAmount"]) != 0)
                                    {
                                        Detailmodel = new AttestBillDetailsModel();//实例凭证明细实体对象
                                        Detailmodel.AttestBillID = ID;
                                        Detailmodel.Abstract = AbstractID;//摘要ID
                                        Detailmodel.SubjectsCD = Dendrow["SubjectsCD"].ToString();
                                        Detailmodel.CurrencyTypeID = CurrencyID;

                                        //判断损益科目方向为贷的金额统计是否大于0
                                        //大于则为借否则为贷方
                                        if (Convert.ToDecimal(Dendrow["EndAmount"]) > 0)
                                        {
                                            Detailmodel.CreditAmount = 0; //贷方金额
                                            Detailmodel.OriginalAmount = Convert.ToDecimal(Dendrow["EndAmount"]);//外币金额
                                            Detailmodel.DebitAmount = Convert.ToDecimal(Dendrow["EndAmount"]);//借方金额

                                            //将损益类科目方向为贷的逆向生成的实体添加到数组当中
                                            modelList.Add(Detailmodel);//实体对象添加到数组中

                                            #region 本年利润凭证明细赋值
                                            Detailmodel = new AttestBillDetailsModel();//实例本年利润凭证明细实体对象
                                            Detailmodel.AttestBillID = ID;
                                            Detailmodel.Abstract = AbstractID;//摘要ID
                                            Detailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目
                                            Detailmodel.DebitAmount = 0;//借方金额为0
                                            Detailmodel.CurrencyTypeID = CurrencyID;
                                            Detailmodel.CreditAmount = Convert.ToDecimal(Dendrow["EndAmount"]); ;//贷方金额
                                            Detailmodel.OriginalAmount = Convert.ToDecimal(Dendrow["EndAmount"]);//外币金额
                                            //本年利润实体对象添加到数组中
                                            modelList.Add(Detailmodel);
                                            #endregion

                                        }
                                        else
                                        {

                                            decimal EndAmount = Convert.ToDecimal(Dendrow["EndAmount"]);
                                            EndAmount = Convert.ToDecimal(EndAmount.ToString().Substring(EndAmount.ToString().IndexOf("-") + 1, EndAmount.ToString().Length - EndAmount.ToString().IndexOf("-") - 1));


                                            //Detailmodel.DebitAmount = 0;//借方金额为0
                                            //Detailmodel.OriginalAmount = Convert.ToDecimal(Dendrow["EndAmount"]);//外币金额
                                            //Detailmodel.CreditAmount = Convert.ToDecimal(Dendrow["EndAmount"]); ;//贷方金额
                                            //modelList.Add(Detailmodel);//实体对象添加到数组中

                                            //#region 本年利润凭证明细赋值
                                            //Detailmodel = new AttestBillDetailsModel();//实例本年利润凭证明细实体对象
                                            //Detailmodel.AttestBillID = ID;
                                            //Detailmodel.Abstract = AbstractID;//摘要ID
                                            //Detailmodel.CurrencyTypeID = CurrencyID;
                                            //Detailmodel.OriginalAmount = Convert.ToDecimal(Dendrow["EndAmount"]);//外币金额
                                            //Detailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目
                                            //Detailmodel.CreditAmount = 0;//贷方金额为0
                                            //Detailmodel.DebitAmount = Convert.ToDecimal(Dendrow["EndAmount"]); ;//借方金额


                                            Detailmodel.DebitAmount = 0;//借方金额为0
                                            Detailmodel.OriginalAmount = EndAmount;//外币金额
                                            Detailmodel.CreditAmount = EndAmount;//贷方金额
                                            modelList.Add(Detailmodel);//实体对象添加到数组中

                                            #region 本年利润凭证明细赋值
                                            Detailmodel = new AttestBillDetailsModel();//实例本年利润凭证明细实体对象
                                            Detailmodel.AttestBillID = ID;
                                            Detailmodel.Abstract = AbstractID;//摘要ID
                                            Detailmodel.CurrencyTypeID = CurrencyID;
                                            Detailmodel.OriginalAmount = EndAmount;//外币金额
                                            Detailmodel.SubjectsCD = SUBJECT_CD_DNLY_CODE;//本年利润科目
                                            Detailmodel.CreditAmount = 0;//贷方金额为0
                                            Detailmodel.DebitAmount = EndAmount;//借方金额

                                            //本年利润实体对象添加到数组中
                                            modelList.Add(Detailmodel);
                                            #endregion
                                        }
                                    #endregion
                                    }
                                }
                            }
                        }
                    }
                    //组合更新ID
                    string UpdateID = string.Empty;
                    if (AccountIDd.Length > 0 && AccountIDj.Length > 0)
                    {
                        UpdateID = AccountIDd + "," + AccountIDj;
                    }
                    result = EndItemProcessing.BuildJZDetailInfo(modelList, UpdateID);
                    if (result)
                    {
                         //凭证自动登帐及自动审核
                         VoucherBus.SetStatus(ID.ToString(), "1", "status", 0);
                         VoucherBus.InsertAccount(AttestID);
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
        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;
            }
        }