You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3409 lines
278 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCwCarryOver;
using DSWeb.MvcShipping.Models.MsCwVouchersGl;
using DSWeb.MvcShipping.Models.MsCwVouitemsGl;
using DSWeb.MvcShipping.DAL.MsCwVouchersGlDAL;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using HcUtility.Core;
using DSWeb.EntityDA;
using DSWeb.Models;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.DAL.MsCwCarryOverDAL
{
public class MsCwCarryOverDAL
{
#region 查询
static public List<MsCwVouitemsGl2> GetDataList(string strCondition, string companyid, string strUSERID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUSERID);
var strSql = new StringBuilder();
strSql.Append("select FCYNO as GID,FCYNO,FCYNAME=(select top 1 DESCRIPTION from code_currency where CODENAME=FCYACC.FCYNO),FCYEXRATE=(SELECT top 1 DEFAULTRATE=isnull((select top 1 BEGRATE from cw_currency_rate where LINKGID=code_currency.GID and ISDELETE=0 and ACCDATE= '" + strCwACCDATE + "' and STARTGID='" + strCwSTARTGID + "'),DEFAULTRATE) from code_currency WITH(NOLOCK) where CODENAME=FCYACC.FCYNO)"// and CORPID='" + companyid + "'
+ ",FCYEXRATE2=(SELECT top 1 DEFAULTRATE=isnull((select top 1 ENDRATE=ISNULL((CASE WHEN ENDRATE=1 THEN BEGRATE else ENDRATE END),BEGRATE) from cw_currency_rate where LINKGID=code_currency.GID and ISDELETE=0"// and CORPID='" + companyid + "'
//+ " and SUBSTRING(ACCDATE,1,4)= '" + DateTime.Parse(strACCDATE + "-01").Year + "'"
+ " and ACCDATE= '" + strCwACCDATE + "' and STARTGID='" + strCwSTARTGID + "'"
+ "),DEFAULTRATE) from code_currency WITH(NOLOCK) where CODENAME=FCYACC.FCYNO) from (select distinct CURRENCY FCYNO FROM cw_genleg_accitems where STARTGID='"+ strCwSTARTGID + "' AND CURRENCY<>'RMB') FCYACC WHERE 1=1 ");
// strSql.Append(" and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from cw_carry_over WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' ORDER by ACCDATE DESC),(select top 1 STARTMONTH from cw_design_startusing where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "') order by STARTMONTH desc)))");
// strSql.Append(" and FCYNO<>'RMB'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" group by FCYNO order by FCYNO");
return SetData(strSql);
}
private static List<MsCwVouitemsGl2> SetData(StringBuilder strSql)
{
var headList = new List<MsCwVouitemsGl2>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwVouitemsGl2 data = new MsCwVouitemsGl2();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
data.FCYNO = (reader["FCYNO"] == null ? "" : Convert.ToString(reader["FCYNO"]));
data.FCYNAME = (reader["FCYNAME"] == null ? "" : Convert.ToString(reader["FCYNAME"]));
data.FCYEXRATE = (reader["FCYEXRATE"] == null ? 0 : Convert.ToDecimal(reader["FCYEXRATE"]));
data.FCYEXRATE2 = (reader["FCYEXRATE2"] == null ? 0 : Convert.ToDecimal(reader["FCYEXRATE2"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public MsCwVouchersGl2 GetData(string condition, string companyid, string strUSERID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
//调汇的默认科目
var strSql = new StringBuilder();
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=cw_carry_accitems.MODIFIEDUSER) from cw_carry_accitems WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "'");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
//会计期间
var strSql4 = new StringBuilder();
strSql4.Append("select ACCDATE");
strSql4.Append(",convert(varchar,dateadd(day,-day(ACCDATE+'-01'),dateadd(month,1,(ACCDATE+'-01'))),23) as VOUDATE");
strSql4.Append(",year(ACCDATE+'-01') as [YEAR]");
strSql4.Append(",month(ACCDATE+'-01') as [MONTH2]");
strSql4.Append(",SUBSTRING(convert(varchar,(ACCDATE+'-01'),23),6,2) as [MONTH]");
strSql4.Append(",VOUNO=isnull((select top 1 (VOUNO+1) from Cw_Vouchers_Gl WHERE STARTGID='" + strCwSTARTGID + "' and VKNO='记' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=a.ACCDATE AND (CarryOverType='' or CarryOverType is NULL) ORDER by convert(int,VOUNO) desc),'1')");//1001
strSql4.Append(",VOUNO2=isnull((select top 1 (VOUNO+2) as VOUNO from Cw_Vouchers_Gl WHERE STARTGID='" + strCwSTARTGID + "' and VKNO='记' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=a.ACCDATE AND (CarryOverType='' or CarryOverType is NULL) ORDER by convert(int,VOUNO) desc),'2')");//1002
strSql4.Append(",VOUNUM=(select COUNT(*) as VOUNUM from Cw_Vouchers_Gl WHERE STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=a.ACCDATE AND (CarryOverType='' or CarryOverType is NULL))");
strSql4.Append(",VOUNUM_ISCHECKED=(select COUNT(*) as VOUNUM from Cw_Vouchers_Gl WHERE STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=a.ACCDATE and (ISCHECKED=0 or ISCHECKED is null))");// AND (CarryOverType='' or CarryOverType is NULL)
strSql4.Append(",isCarryOverType=(select (case VOUNUM when 0 then 'false' else 'true' end) as isCarryOverType from (select COUNT(*) as VOUNUM from Cw_Vouchers_Gl WHERE STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=a.ACCDATE AND (CarryOverType<>'' and CarryOverType is not NULL)) as a)");// and ISCHECKED=1
strSql4.Append(",VOUNUM_ISCARRY=(select COUNT(*) as VOUNUM from Cw_Vouchers_Gl WHERE STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=a.ACCDATE and (ISCARRY=0 or ISCARRY is null) AND (CarryOverType='' or CarryOverType is NULL))");
strSql4.Append(" from (SELECT isnull((SELECT top 1 SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE from cw_carry_over WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' ORDER by ACCDATE DESC),(select top 1 STARTMONTH from cw_design_startusing where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "') order by STARTMONTH desc)) as ACCDATE) as a");
if (!string.IsNullOrEmpty(condition))
{
strSql4.Append(" and " + condition);
}
//
var list = SetData2(strSql, strSql4);
if (list.Count > 0)
return list[0];
return new MsCwVouchersGl2();
}
private static List<MsCwVouchersGl2> SetData2(StringBuilder strSql, StringBuilder strSql4)
{
var headList = new List<MsCwVouchersGl2>();
MsCwVouchersGl2 data = new MsCwVouchersGl2();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
#region 调汇的默认科目
data.ExchangeGains = "";
data.ExchangeLoss = "";
data.CurrentYearProfits = "";
data.UndistributedProfit = "";
data.CORPID = "";
data.MODIFIEDUSER = "";
data.MODIFIEDTIME = DateTime.Now;
data.MODIFIEDUSERNAME = "";
DataSet ds = T_ALL_DA.GetAllSQL(strSql.ToString());
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
data.ExchangeGains = ds.Tables[0].Rows[0]["ExchangeGains"].ToString();
data.ExchangeLoss = ds.Tables[0].Rows[0]["ExchangeLoss"].ToString();
data.CurrentYearProfits = ds.Tables[0].Rows[0]["CurrentYearProfits"].ToString();
data.UndistributedProfit = ds.Tables[0].Rows[0]["UndistributedProfit"].ToString();
data.CORPID = ds.Tables[0].Rows[0]["CORPID"].ToString();
data.MODIFIEDUSER = ds.Tables[0].Rows[0]["MODIFIEDUSER"].ToString();
data.MODIFIEDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString());
data.MODIFIEDUSERNAME = ds.Tables[0].Rows[0]["MODIFIEDUSERNAME"].ToString();
}
}
#endregion
#region 会计期间
data.VKNO = "记";
data.VKNO2 = "记";
data.YEAR = DateTime.Now.Year.ToString();
data.MONTH = DateTime.Now.Year.ToString();
if (DateTime.Now.Year.ToString().Length < 2)
{
data.MONTH = "0" + DateTime.Now.Year.ToString();
}
data.ACCDATE = data.YEAR + data.MONTH;
data.VOUDATE = data.YEAR + data.MONTH + "31";
data.VOUDATE2 = data.YEAR + data.MONTH + "31";
data.MONTH2 = DateTime.Now.Year.ToString();
data.VOUNUM = "0";
data.VOUNUM_ISCHECKED = "0";
data.VOUNUM_ISCARRY = "0";
data.lbTitle = data.YEAR + " 年第 " + data.MONTH2 + " 期 共录入凭证 " + data.VOUNUM + " 张,其中未审核凭证 " + data.VOUNUM_ISCHECKED + " 张、未包含在月末结转凭证中的 " + data.VOUNUM_ISCARRY + " 张 (注意:没录入凭证、有未审核凭证、有未包含在月末结转凭证中的,则不能使用此模块!)";
data.isCarryOverType = "False";
DataSet ds4 = T_ALL_DA.GetAllSQL(strSql4.ToString());
if (ds4 != null)
{
if (ds4.Tables[0].Rows.Count > 0)
{
data.YEAR = ds4.Tables[0].Rows[0]["YEAR"].ToString();
data.MONTH = ds4.Tables[0].Rows[0]["MONTH"].ToString();
data.MONTH2 = ds4.Tables[0].Rows[0]["MONTH2"].ToString();
data.ACCDATE = ds4.Tables[0].Rows[0]["ACCDATE"].ToString();
data.VOUNO = ds4.Tables[0].Rows[0]["VOUNO"].ToString();
data.VOUNO2 = ds4.Tables[0].Rows[0]["VOUNO2"].ToString();
data.VOUDATE = ds4.Tables[0].Rows[0]["VOUDATE"].ToString();
data.VOUDATE2 = ds4.Tables[0].Rows[0]["VOUDATE"].ToString();
data.VOUNUM = ds4.Tables[0].Rows[0]["VOUNUM"].ToString();
data.VOUNUM_ISCHECKED = ds4.Tables[0].Rows[0]["VOUNUM_ISCHECKED"].ToString();
data.VOUNUM_ISCARRY = ds4.Tables[0].Rows[0]["VOUNUM_ISCARRY"].ToString();
data.lbTitle = data.YEAR + " 年第 " + data.MONTH2 + " 期 共录入凭证 " + data.VOUNUM + " 张,其中未审核凭证 " + data.VOUNUM_ISCHECKED + " 张、未包含在月末结转凭证中的 " + data.VOUNUM_ISCARRY + " 张 (注意:没录入凭证、有未审核凭证、有未包含在月末结转凭证中的,则不能使用此模块!)";
data.isCarryOverType = ds4.Tables[0].Rows[0]["isCarryOverType"].ToString();
}
}
#endregion
headList.Add(data);
return headList;
}
#endregion
#region 生成结转凭证
public static DBResult AddEdit(MsCwVouchersGl2 headData, List<MsCwVouitemsGl2> bodyList, string strUserID, string strSHOWNAME, string companyid)
{
#region 默认操作
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strVOUNO = headData.VOUNO.ToString().Trim();
var result = new DBResult();
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 默认结转科目_入库
string sSQL = "select top 1 gid from cw_carry_accitems WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "'";// and CORPID='" + companyid + "'
string sGID = T_ALL_DA.GetStrSQL("gid", sSQL);//科目
if (sGID == "")//插入0
{
sSQL = "INSERT INTO [cw_carry_accitems]([GID],[ExchangeGains],[ExchangeLoss],[CurrentYearProfits],[UndistributedProfit],[CORPID],[MODIFIEDUSER],[MODIFIEDTIME],STARTGID) VALUES(newid(),'" + headData.ExchangeGains.ToString().Trim() + "','" + headData.ExchangeLoss.ToString().Trim() + "','" + headData.CurrentYearProfits.ToString().Trim() + "','" + headData.UndistributedProfit.ToString().Trim() + "','" + companyid + "','" + strUserID + "',GETDATE(),'" + strCwSTARTGID + "')";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
else//更新
{
sSQL = "UPDATE [cw_carry_accitems] SET [ExchangeGains] = '" + headData.ExchangeGains.ToString().Trim() + "',[ExchangeLoss] = '" + headData.ExchangeLoss.ToString().Trim() + "',[CurrentYearProfits] = '" + headData.CurrentYearProfits.ToString().Trim() + "',[UndistributedProfit] = '" + headData.UndistributedProfit.ToString().Trim() + "',[CORPID] = '" + companyid + "',[MODIFIEDUSER] = '" + strUserID + "',[MODIFIEDTIME] = GETDATE(),STARTGID='" + strCwSTARTGID + "' WHERE [GID] = '" + sGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
#endregion
#region 删除现有的
string strSqlDel = "delete from Cw_Vouitems_Gl where ORDNO in (select ORDNO from Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and (CarryOverType='期末调汇' or CarryOverType='结转损益' or CarryOverType='年末结转') and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7))";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlDel, null);
strSqlDel = "delete from Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and (CarryOverType='期末调汇' or CarryOverType='结转损益' or CarryOverType='年末结转') and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7)";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSqlDel, null);
#endregion
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
#region 期末调汇
#region 基本设定
string strSql = "";
string strORDNO = getGid();
string cType1_ORDNO = getGid();
MsCwVouchersGl CwVouchersGlDA = new MsCwVouchersGl();
IList<MsCwVouchersGl> CwVouchersGlEntities = new List<MsCwVouchersGl>();
IList<MsCwVouitemsGl> CwVouitemsGlEntities = new List<MsCwVouitemsGl>();
#endregion
/*//是否需要生成汇率调整
bool blHLTZB = false;
if (headData.cbHLTZB.ToString().Trim() == "true")//是否需要生成汇率调整
{
blHLTZB = true;
}
else
{
if (strCwACCDATE.Substring(5) == "12")//如果是年末结转则强制生成汇兑损益
{
blHLTZB = true;
}
}
*/
if (headData.cbHLTZB.ToString().Trim() == "true")//是否需要生成汇率调整
{
#region 循环生成_实体类赋值
if (bodyList != null)
{
if (bodyList.Count > 0)
{
int inum = 1;
Decimal dlAMTDR = 0;//结转汇兑损失/结转汇兑损失例如财务费用_汇兑损益 借
Decimal dlAMTCR = 0;//结转汇兑收益/结转汇兑收益例如营业外收入_其他 贷
int iscType1 = 0;
int iscType2 = 0;
foreach (var enumValue in bodyList)
{
#region 更新汇率表的本期期末汇率
string FCYGID = T_ALL_DA.GetStrSQL("GID", "select top 1 GID from code_currency where CODENAME='" + enumValue.FCYNO.ToString() + "'");
string sls = "update cw_currency_rate set ENDRATE=" + enumValue.FCYEXRATE2.ToString() + ",MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=getdate() where (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strCwACCDATE + "' and STARTGID='" + strCwSTARTGID + "' and LINKGID='" + FCYGID + "'";// and CORPID='" + companyid + "'
#endregion
T_ALL_DA.GetExecuteSqlCommand(sls);
#region 更新汇率表的下期期初汇率
DateTime dt = DateTime.Parse(strCwACCDATE + "-01");
DateTime dt2 = dt.AddMonths(1);
string sYear = dt2.Year.ToString();
string sMonth = dt2.Month.ToString();
if (sMonth.Length == 1)
{
sMonth = "0" + sMonth;
}
string strACCDATE_New = sYear + "-" + sMonth;
sls = "update cw_currency_rate set BEGRATE=" + enumValue.FCYEXRATE2.ToString() + ",MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=getdate() where (ISDELETE=0 or ISDELETE is null) and ACCDATE='" + strACCDATE_New + "' and STARTGID='" + strCwSTARTGID + "' and LINKGID='" + FCYGID + "' and (BEGRATE=0 or BEGRATE=1)";// and CORPID='" + companyid + "'
#endregion
T_ALL_DA.GetExecuteSqlCommand(sls);
#region 插入明细表_合计数据集_按每条凭证合计_暂时屏蔽
/*
strSql = "select *"
+ ",AMTDR4=(FCYDR3*" + enumValue.FCYEXRATE2.ToString() + "-AMTDR3)"
+ ",AMTCR4=(FCYCR3*" + enumValue.FCYEXRATE2.ToString() + "-AMTCR3)"
+ ",AMTDRCE=((FCYDR+FCYDR3)*" + enumValue.FCYEXRATE2.ToString() + "-(AMTDR+AMTDR3))"
+ ",AMTCRCE=((FCYCR+FCYCR3)*" + enumValue.FCYEXRATE2.ToString() + "-(AMTCR+AMTCR3))"
+ ",FCYDRCE=cast((((FCYDR+FCYDR3)*" + enumValue.FCYEXRATE2.ToString() + "-(AMTDR+AMTDR3))/" + enumValue.FCYEXRATE2.ToString() + ") as decimal(18,2))"
+ ",FCYCRCE=cast((((FCYCR+FCYCR3)*" + enumValue.FCYEXRATE2.ToString() + "-(AMTCR+AMTCR3))/" + enumValue.FCYEXRATE2.ToString() + ") as decimal(18,2))"
+ " from ("
+ "(select ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME"
+ ",(case when (sum(AMTDR)-sum(AMTCR))>0 THEN (sum(AMTDR)-sum(AMTCR)) else 0 END) as AMTDR"
+ ",(case when (sum(AMTCR)-sum(AMTDR))>0 THEN (sum(AMTCR)-sum(AMTDR)) else 0 END) as AMTCR"
+ ",(case when (sum(FCYDR)-sum(FCYCR))>0 THEN (sum(FCYDR)-sum(FCYCR)) else 0 END) as FCYDR"
+ ",(case when (sum(FCYCR)-sum(FCYDR))>0 THEN (sum(FCYCR)-sum(FCYDR)) else 0 END) as FCYCR"
+ ",FCYNO"//,DC
+ ",(case when (sum(AMTDR2)-sum(AMTCR2))>0 THEN (sum(AMTDR2)-sum(AMTCR2)) else 0 END) as AMTDR2"
+ ",(case when (sum(AMTCR2)-sum(AMTDR2))>0 THEN (sum(AMTCR2)-sum(AMTDR2)) else 0 END) as AMTCR2"
+ ",DC2"
+ ",AMTDR3=ISNULL((select top 1 QTYYEARDR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ ",AMTCR3=ISNULL((select top 1 QTYYEARCR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ ",FCYDR3=ISNULL((select top 1 FCYYEARDR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ ",FCYCR3=ISNULL((select top 1 FCYYEARCR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ " from (select *"
+ ",AMTDR2=(FCYDR*" + enumValue.FCYEXRATE2.ToString() + "-AMTDR)"
+ ",AMTCR2=(FCYCR*" + enumValue.FCYEXRATE2.ToString() + "-AMTCR)"
+ ",DC2=(select top 1 DC from cw_accitems_gl where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,4))"
+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item where GID=Cw_Vouitems_Gl.ITEMGID),'')"
+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept where GID=Cw_Vouitems_Gl.DEPTGID),'')"
+ " from Cw_Vouitems_Gl where 1=1"
+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and CarryOverType<>'期末调汇' and CarryOverType<>'结转损益')"
+ " and FCYNO='" + enumValue.FCYNO.ToString() + "' ) as a"
+ " group BY ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,DC2)"
+ " union "
+ "(select AG.ACCID,AG.ACCNAME,AG.ACCNAME as ACCALL,G.CORPACC as CUSTOMERNAME,G.EMPLACC as SALE,G.ITEMACC as ITEMNAME,G.DEPTACC as DEPTNAME,0 as AMTDR,0 as AMTCR,0 as FCYDR,0 as FCYCR,G.CURRENCY as FCYNO,0 as AMTDR2,0 as AMTCR2,AG.DC as DC2"
+ ",isnull(sum(G.QTYYEARDR),0) as AMTDR3"
+ ",isnull(sum(G.QTYYEARCR),0) as AMTCR3"
+ ",isnull(sum(G.FCYYEARDR),0) as FCYDR3"
+ ",isnull(sum(G.FCYYEARCR),0) as FCYCR3"
+ " from cw_genleg_accitems as G INNER JOIN cw_accitems_gl as AG ON AG.GID = G.LINKGID"
+ " where G.[STARTGID]='" + strCwSTARTGID + "' and AG.[YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and AG.[STARTGID]='" + strCwSTARTGID + "' and AG.DETAILED=1 and AG.ISENABLE=1 and CURRENCY='" + enumValue.FCYNO.ToString() + "'and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and (G.QTYYEARDR<>0 or G.QTYYEARCR<>0 or G.FCYYEARDR<>0 or G.FCYYEARCR<>0)"
+ "and LINKGID not in (select LINKGID=(select GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=Cw_Vouitems_Gl.ACCID) from Cw_Vouitems_Gl where FCYNO='USD' and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and CarryOverType<>'期末调汇' and CarryOverType<>'结转损益'))"
+ " group BY AG.ACCID,AG.ACCNAME,G.CORPACC,G.EMPLACC,G.ITEMACC,G.DEPTACC,G.CURRENCY,AG.DC)"
+ ") as b"//,DC
+ " where ((AMTDR+AMTDR3)-(AMTCR+AMTCR3))<>0"
+ " order by ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO";
*/
#endregion
#region 插入明细表_合计数据集_按总账表合计
strSql = "select *"
+ ",AMTDRCE=(case when DC='借' then cast((FCYLASTBLC*" + enumValue.FCYEXRATE2.ToString() + "-(QTYLASTBLC-AMTLASTBLC)) as decimal(18,2)) else 0 end)"
+ ",AMTCRCE=(case when DC='借' then 0 else cast((FCYLASTBLC*" + enumValue.FCYEXRATE2.ToString() + "-(QTYLASTBLC-AMTLASTBLC)) as decimal(18,2)) end)"
+ ",FCYDRCE=(case when DC='借' then cast(((FCYLASTBLC*" + enumValue.FCYEXRATE2.ToString() + "-(QTYLASTBLC-AMTLASTBLC))/" + enumValue.FCYEXRATE2.ToString() + ") as decimal(18,2)) else 0 end)"
+ ",FCYCRCE=(case when DC='借' then 0 else cast(((FCYLASTBLC*" + enumValue.FCYEXRATE2.ToString() + "-(QTYLASTBLC-AMTLASTBLC))/" + enumValue.FCYEXRATE2.ToString() + ") as decimal(18,2)) end)"
+ " from VW_cw_genleg_accitems_gl WITH(NOLOCK)"
+ " where DETAILED=1 and ACCATTRIBUTE<>'损益'"
+ " and STARTGID='" + strCwSTARTGID + "'"
+ " and currency<>'RMB' and currency='" + enumValue.FCYNO.ToString() + "' and (FCYLASTBLC<>0 or QTYLASTBLC<>0)"
+ " and ([YEAR]+'-'+[MONTH])=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7)";
#endregion
DataSet dsCwVouitemsGl = T_ALL_DA.GetAllSQL(strSql);
#region 插入明细表_实体类赋值
if (dsCwVouitemsGl != null)
{
if (dsCwVouitemsGl.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsCwVouitemsGl.Tables[0].Rows.Count; i++)
{
#region 插入明细表_实体类赋值
MsCwVouitemsGl MsCwVouitemsGl3 = new MsCwVouitemsGl();
MsCwVouitemsGl3.GID = Guid.NewGuid().ToString();
MsCwVouitemsGl3.ORDNO = strORDNO.Trim();
MsCwVouitemsGl3.ITEMNO = inum;// 行号
inum++;
MsCwVouitemsGl3.PACCID = "";//父级科目贷码
MsCwVouitemsGl3.PROPERTY = 0;//科目属性
MsCwVouitemsGl3.GRADE = 0;//科目级别
//
MsCwVouitemsGl3.FCYNO = dsCwVouitemsGl.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币编号usd
MsCwVouitemsGl3.ISFCY = true;//是否外币
MsCwVouitemsGl3.FCYEXRATE = Decimal.Parse(enumValue.FCYEXRATE2.ToString().Trim());//汇率
MsCwVouitemsGl3.FCYDR = 0;
MsCwVouitemsGl3.FCYCR = 0;
//
if (dsCwVouitemsGl.Tables[0].Rows[i]["DC"].ToString().Trim() == "借")//"借"
{
#region 借
if (Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim()) == 0)
{
MsCwVouitemsGl3.AMTDR = Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["AMTDRCE"].ToString().Trim());
//MsCwVouitemsGl3.FCYDR = Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["FCYDRCE"].ToString().Trim());
}
else
{
MsCwVouitemsGl3.AMTDR = -Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim());
//MsCwVouitemsGl3.FCYDR = -Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["FCYCRCE"].ToString().Trim());
}
if (MsCwVouitemsGl3.AMTDR > 0)
{
dlAMTCR += MsCwVouitemsGl3.AMTDR;
MsCwVouitemsGl3.EXPLAN = "结转汇兑收益";
MsCwVouitemsGl3.cType = "收益";
iscType1++;
}
else
{
dlAMTDR += (-MsCwVouitemsGl3.AMTDR);
MsCwVouitemsGl3.EXPLAN = "结转汇兑损失";
MsCwVouitemsGl3.cType = "损失";
iscType2++;
if (headData.cType.ToString().Trim() == "1")
{
MsCwVouitemsGl3.ORDNO = cType1_ORDNO.Trim();
}
}
MsCwVouitemsGl3.AMTCR = 0;
MsCwVouitemsGl3.DC = "D";//借方向
#endregion
}
else
{
#region 贷
if (Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim()) == 0)
{
MsCwVouitemsGl3.AMTCR = -Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["AMTDRCE"].ToString().Trim());
//MsCwVouitemsGl3.FCYCR = -Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["FCYDRCE"].ToString().Trim());
}
else
{
MsCwVouitemsGl3.AMTCR = Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim());
//MsCwVouitemsGl3.FCYCR = Decimal.Parse(dsCwVouitemsGl.Tables[0].Rows[i]["FCYCRCE"].ToString().Trim());
}
if (MsCwVouitemsGl3.AMTCR > 0)
{
dlAMTDR += MsCwVouitemsGl3.AMTCR;
MsCwVouitemsGl3.EXPLAN = "结转汇兑损失";
MsCwVouitemsGl3.cType = "损失";
iscType2++;
}
else
{
dlAMTCR += (-MsCwVouitemsGl3.AMTCR);
MsCwVouitemsGl3.EXPLAN = "结转汇兑收益";
MsCwVouitemsGl3.cType = "收益";
iscType1++;
}
MsCwVouitemsGl3.AMTDR = 0;
MsCwVouitemsGl3.DC = "C";//贷方向
#endregion
}
MsCwVouitemsGl3.ACCID = dsCwVouitemsGl.Tables[0].Rows[i]["ACCID"].ToString().Trim();//科目
MsCwVouitemsGl3.ACCNAME = dsCwVouitemsGl.Tables[0].Rows[i]["ACCNAME"].ToString().Trim();//科目名称
//
string strACCALL = "";
MsCwVouitemsGl3.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl3.CUSTOMERNAME = "";//客户(系统)
MsCwVouitemsGl3.SALE = "";//人员名称
MsCwVouitemsGl3.DEPTGID = "";//揽货人的部门
MsCwVouitemsGl3.ISDEPTACC = false;//核算部门,按规则设置生成
MsCwVouitemsGl3.ISEMPLACC = false;//核算人员,按规则设置生成
MsCwVouitemsGl3.ISCORPACC = false;//核算客户,按规则设置生成
MsCwVouitemsGl3.ISITEMACC = false;//核算项目,按规则设置生成
if (dsCwVouitemsGl.Tables[0].Rows[i]["CORPACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISCORPACC = true;//核算客户,按规则设置生成
MsCwVouitemsGl3.CORPID = "";//客户(系统)
MsCwVouitemsGl3.CUSTOMERNAME = dsCwVouitemsGl.Tables[0].Rows[i]["CORPACC"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl3.CUSTOMERNAME;
}
if (dsCwVouitemsGl.Tables[0].Rows[i]["EMPLACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISEMPLACC = true;//核算人员,按规则设置生成
MsCwVouitemsGl3.SALE = dsCwVouitemsGl.Tables[0].Rows[i]["EMPLACC"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl3.SALE;
}
if (dsCwVouitemsGl.Tables[0].Rows[i]["DEPTACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISDEPTACC = true;//核算部门,按规则设置生成
string lsSQL = "select top 1 GID from sys_dept WITH(NOLOCK) where DEPTNAME='" + dsCwVouitemsGl.Tables[0].Rows[i]["DEPTACC"].ToString().Trim() + "'";
MsCwVouitemsGl3.DEPTGID = T_ALL_DA.GetStrSQL("GID", lsSQL);//揽货人的部门
lsSQL = "select top 1 FINANCESOFTCODE from sys_dept WITH(NOLOCK) where DEPTNAME='" + dsCwVouitemsGl.Tables[0].Rows[i]["DEPTACC"].ToString().Trim() + "'";
MsCwVouitemsGl3.DEPTID = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", lsSQL);
strACCALL += "▁" + dsCwVouitemsGl.Tables[0].Rows[i]["DEPTACC"].ToString().Trim();
}
if (dsCwVouitemsGl.Tables[0].Rows[i]["ITEMACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISITEMACC = true;//核算项目,按规则设置生成
string lsSQL = "select top 1 GID from cw_item WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and ITEMNAME='" + dsCwVouitemsGl.Tables[0].Rows[i]["ITEMACC"].ToString().Trim() + "'";
MsCwVouitemsGl3.ITEMGID = T_ALL_DA.GetStrSQL("GID", lsSQL);//是否核算项目
strACCALL += "▁" + dsCwVouitemsGl.Tables[0].Rows[i]["ITEMACC"].ToString().Trim();
}
MsCwVouitemsGl3.ACCALL = BasicDataRefDAL.setCAGA(dsCwVouitemsGl.Tables[0].Rows[i]["PACCGID"].ToString(), MsCwVouitemsGl3.ACCNAME.ToString().Trim()) + strACCALL;
//
MsCwVouitemsGl3.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl3.QTYDR = 0;//借方数量
MsCwVouitemsGl3.QTYCR = 0;//贷方数量
MsCwVouitemsGl3.DEPTID = "";//部门(系统)
MsCwVouitemsGl3.EMPLID = "";//人员(系统)
MsCwVouitemsGl3.ITEMID = "0";//项目编号
MsCwVouitemsGl3.PITEMID = 0;//父级项目编号
MsCwVouitemsGl3.FIELD1 = "";//预留字段1
MsCwVouitemsGl3.FIELD2 = "";//预留字段2
MsCwVouitemsGl3.FIELD3 = "";//预留字段3
MsCwVouitemsGl3.FIELD4 = "";//预留字段4
MsCwVouitemsGl3.FIELD5 = "";//预留字段5
MsCwVouitemsGl3.FIELD6 = "";//预留字段6
MsCwVouitemsGl3.FIELD7 = "";//预留字段7
MsCwVouitemsGl3.FIELD8 = "";//预留字段8
MsCwVouitemsGl3.FIELD9 = "";//预留字段9
MsCwVouitemsGl3.FIELD10 = "";//预留字段10
MsCwVouitemsGl3.ISSYS = false;//是否手动录入
MsCwVouitemsGl3.FSETTLCODE = "";//结算方式
MsCwVouitemsGl3.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl3.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl3.BLNO = "";
MsCwVouitemsGl3.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl3.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl3.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl3.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsGlEntities.Add(MsCwVouitemsGl3);
}
}
}
#endregion
}
#region 结转汇兑收益/结转汇兑收益例如营业外收入_其他 贷
if (dlAMTCR != 0)
{
#region 插入明细表_实体类赋值
MsCwVouitemsGl MsCwVouitemsGl2 = new MsCwVouitemsGl();
MsCwVouitemsGl2.GID = Guid.NewGuid().ToString();
MsCwVouitemsGl2.ORDNO = strORDNO.Trim();
MsCwVouitemsGl2.ITEMNO = inum;//行号
inum++;
//
string sDC = "select top 1 DC from cw_accitems_gl With(NOLOCK) where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + headData.ExchangeGains.ToString().Trim() + "'";
sDC = T_ALL_DA.GetStrSQL("DC", sDC);//科目
if (sDC == "借")
{
#region 借
MsCwVouitemsGl2.AMTDR = -dlAMTCR;
MsCwVouitemsGl2.FCYDR = 0;
MsCwVouitemsGl2.AMTCR = 0;
MsCwVouitemsGl2.FCYCR = 0;
MsCwVouitemsGl2.DC = "D";//借方向
#endregion
}
else
{
#region 贷
MsCwVouitemsGl2.AMTDR = 0;
MsCwVouitemsGl2.FCYDR = 0;
MsCwVouitemsGl2.AMTCR = dlAMTCR;
MsCwVouitemsGl2.FCYCR = 0;
MsCwVouitemsGl2.DC = "C";//借方向
#endregion
}
MsCwVouitemsGl2.ISFCY = false;//是否外币
MsCwVouitemsGl2.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl2.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl2.CUSTOMERNAME = "";//客户(系统)
MsCwVouitemsGl2.ITEMGID = "";//项目名称//varchar
MsCwVouitemsGl2.DEPTGID = "";
//
MsCwVouitemsGl2.ACCID = "";//科目
MsCwVouitemsGl2.ACCALL = "";
string sSQL = "select top 1 * from cw_accitems_gl With(NOLOCK) where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + headData.ExchangeGains.ToString().Trim() + "'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
MsCwVouitemsGl2.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString();//科目
MsCwVouitemsGl2.ACCALL = BasicDataRefDAL.setCAGA(ds.Tables[0].Rows[0]["PACCGID"].ToString(), ds.Tables[0].Rows[0]["ACCNAME"].ToString());
MsCwVouitemsGl2.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString();
}
}
//
MsCwVouitemsGl2.FCYEXRATE = 1;//汇率
MsCwVouitemsGl2.ISDEPTACC = false;//核算部门,按规则设置生成
MsCwVouitemsGl2.ISEMPLACC = false;//核算人员,按规则设置生成
MsCwVouitemsGl2.ISCORPACC = false;//核算客户,按规则设置生成
MsCwVouitemsGl2.ISITEMACC = false;//核算项目,按规则设置生成
MsCwVouitemsGl2.EXPLAN = "结转汇兑收益";//headData.EXPLAN.ToString().Trim();//摘要规则生成ALL
MsCwVouitemsGl2.cType = "收益";//headData.EXPLAN.ToString().Trim();//摘要规则生成ALL
iscType1++;
//
MsCwVouitemsGl2.PACCID = "";//父级科目贷码
MsCwVouitemsGl2.PROPERTY = 0;//科目属性
MsCwVouitemsGl2.GRADE = 0;//科目级别
MsCwVouitemsGl2.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl2.QTYDR = 0;//借方数量
MsCwVouitemsGl2.QTYCR = 0;//贷方数量
MsCwVouitemsGl2.CORPID = "";//客户(系统)
MsCwVouitemsGl2.DEPTID = "";//部门(系统)
MsCwVouitemsGl2.EMPLID = "";//人员(系统)
MsCwVouitemsGl2.ITEMID = "0";//项目编号
MsCwVouitemsGl2.PITEMID = 0;//父级项目编号
MsCwVouitemsGl2.FIELD1 = "";//预留字段1
MsCwVouitemsGl2.FIELD2 = "";//预留字段2
MsCwVouitemsGl2.FIELD3 = "";//预留字段3
MsCwVouitemsGl2.FIELD4 = "";//预留字段4
MsCwVouitemsGl2.FIELD5 = "";//预留字段5
MsCwVouitemsGl2.FIELD6 = "";//预留字段6
MsCwVouitemsGl2.FIELD7 = "";//预留字段7
MsCwVouitemsGl2.FIELD8 = "";//预留字段8
MsCwVouitemsGl2.FIELD9 = "";//预留字段9
MsCwVouitemsGl2.FIELD10 = "";//预留字段10
MsCwVouitemsGl2.ISSYS = false;//是否手动录入
MsCwVouitemsGl2.FSETTLCODE = "";//结算方式
MsCwVouitemsGl2.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl2.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl2.BLNO = "";
MsCwVouitemsGl2.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl2.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl2.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl2.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsGlEntities.Add(MsCwVouitemsGl2);
}
#endregion
#region 结转汇兑损失/结转汇兑损失例如财务费用_汇兑损益 借
if (dlAMTDR != 0)
{
#region 插入明细表_实体类赋值
MsCwVouitemsGl MsCwVouitemsGl1 = new MsCwVouitemsGl();
MsCwVouitemsGl1.GID = Guid.NewGuid().ToString();
MsCwVouitemsGl1.ORDNO = strORDNO.Trim();
MsCwVouitemsGl1.ITEMNO = inum;//行号
inum++;
//
string sDC = "select top 1 DC from cw_accitems_gl With(NOLOCK) where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + headData.ExchangeLoss.ToString().Trim() + "'";
sDC = T_ALL_DA.GetStrSQL("DC", sDC);//科目
if (sDC == "借")
{
#region 借
MsCwVouitemsGl1.AMTDR = dlAMTDR;
MsCwVouitemsGl1.FCYDR = 0;
MsCwVouitemsGl1.AMTCR = 0;
MsCwVouitemsGl1.FCYCR = 0;
MsCwVouitemsGl1.DC = "D";//借方向
#endregion
}
else
{
#region 贷
MsCwVouitemsGl1.AMTDR = 0;
MsCwVouitemsGl1.FCYDR = 0;
MsCwVouitemsGl1.AMTCR = -dlAMTDR;
MsCwVouitemsGl1.FCYCR = 0;
MsCwVouitemsGl1.DC = "C";//借方向
#endregion
}
//
MsCwVouitemsGl1.ISFCY = false;//是否外币
MsCwVouitemsGl1.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl1.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl1.CUSTOMERNAME = "";//客户(系统)
MsCwVouitemsGl1.ITEMGID = "";//项目名称//varchar
MsCwVouitemsGl1.DEPTGID = "";
//
MsCwVouitemsGl1.ACCID = "";//科目
MsCwVouitemsGl1.ACCALL = "";
// MsCwVouitemsGl1.ACCNAME = headData.ExchangeLoss.ToString().Trim();
string sSQL = "select top 1 * from cw_accitems_gl With(NOLOCK) where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + headData.ExchangeLoss.ToString().Trim() + "'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
MsCwVouitemsGl1.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString();//科目
MsCwVouitemsGl1.ACCALL = BasicDataRefDAL.setCAGA(ds.Tables[0].Rows[0]["PACCGID"].ToString(), ds.Tables[0].Rows[0]["ACCNAME"].ToString());
MsCwVouitemsGl1.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString();
}
}
//
MsCwVouitemsGl1.FCYEXRATE = 1;//汇率
MsCwVouitemsGl1.ISDEPTACC = false;//核算部门,按规则设置生成
MsCwVouitemsGl1.ISEMPLACC = false;//核算人员,按规则设置生成
MsCwVouitemsGl1.ISCORPACC = false;//核算客户,按规则设置生成
MsCwVouitemsGl1.ISITEMACC = false;//核算项目,按规则设置生成
MsCwVouitemsGl1.EXPLAN = "结转汇兑损失";//headData.EXPLAN.ToString().Trim();//摘要规则生成ALL
MsCwVouitemsGl1.cType = "损失";//headData.EXPLAN.ToString().Trim();//摘要规则生成ALL
iscType2++;
if (headData.cType.ToString().Trim() == "1")
{
MsCwVouitemsGl1.ORDNO = cType1_ORDNO.Trim();
}
//
MsCwVouitemsGl1.PACCID = "";//父级科目贷码
MsCwVouitemsGl1.PROPERTY = 0;//科目属性
MsCwVouitemsGl1.GRADE = 0;//科目级别
MsCwVouitemsGl1.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl1.QTYDR = 0;//借方数量
MsCwVouitemsGl1.QTYCR = 0;//贷方数量
MsCwVouitemsGl1.CORPID = "";//客户(系统)
MsCwVouitemsGl1.DEPTID = "";//部门(系统)
MsCwVouitemsGl1.EMPLID = "";//人员(系统)
MsCwVouitemsGl1.ITEMID = "0";//项目编号
MsCwVouitemsGl1.PITEMID = 0;//父级项目编号
MsCwVouitemsGl1.FIELD1 = "";//预留字段1
MsCwVouitemsGl1.FIELD2 = "";//预留字段2
MsCwVouitemsGl1.FIELD3 = "";//预留字段3
MsCwVouitemsGl1.FIELD4 = "";//预留字段4
MsCwVouitemsGl1.FIELD5 = "";//预留字段5
MsCwVouitemsGl1.FIELD6 = "";//预留字段6
MsCwVouitemsGl1.FIELD7 = "";//预留字段7
MsCwVouitemsGl1.FIELD8 = "";//预留字段8
MsCwVouitemsGl1.FIELD9 = "";//预留字段9
MsCwVouitemsGl1.FIELD10 = "";//预留字段10
MsCwVouitemsGl1.ISSYS = false;//是否手动录入
MsCwVouitemsGl1.FSETTLCODE = "";//结算方式
MsCwVouitemsGl1.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl1.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl1.BLNO = "";
MsCwVouitemsGl1.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl1.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl1.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl1.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsGlEntities.Add(MsCwVouitemsGl1);
}
#endregion
///////////////////////////////////////////////////////
#region 凭证分类_插入主表
if (headData.cType.ToString().Trim() == "2")
{
#region 生成一张凭证,既包括收益也包括损失
#region 插入主表
MsCwVouchersGl MsCwVouchersGl = new MsCwVouchersGl();
MsCwVouchersGl.ORDNO = strORDNO.Trim();//唯一编码 newid()
DateTime rq = DateTime.Parse(headData.VOUDATE.ToString().Trim());
MsCwVouchersGl.VOUDATE = rq.ToString().Trim();//
MsCwVouchersGl.ACCYEAR = rq.Year.ToString().Trim();//年=""
string strACCMONTH = rq.Month.ToString().Trim();
if (strACCMONTH.Length == 1)
{
strACCMONTH = "0" + strACCMONTH;
}
MsCwVouchersGl.VKNO = headData.VKNO.ToString().Trim();//凭证字
MsCwVouchersGl.VOUNO = strVOUNO;//月初清零
MsCwVouchersGl.ACCMONTH = strACCMONTH;//月
string strVOUALLNO = MsCwVouchersGl.VOUNO.ToString();
for (int i = 0; i < (4 - MsCwVouchersGl.VOUNO.ToString().Length); i++)
{
strVOUALLNO = "0" + strVOUALLNO;
}
strVOUALLNO = MsCwVouchersGl.VKNO + MsCwVouchersGl.ACCYEAR + strACCMONTH + strVOUALLNO;
MsCwVouchersGl.VOUALLNO = strVOUALLNO;//月初清零
MsCwVouchersGl.ATTACHS = 0;//附件(单据)数
MsCwVouchersGl.AMTDR = 0;//本位币借方
MsCwVouchersGl.AMTCR = 0;//本位币贷方
MsCwVouchersGl.FCY = "";//是否含有外币科目
MsCwVouchersGl.QTY = "";//是否含有数量科目
MsCwVouchersGl.VOUPROP = "";//凭证属性
MsCwVouchersGl.PREPARED = strSHOWNAME.Trim();//制单人
MsCwVouchersGl.CHECKED = "";//审核人
MsCwVouchersGl.ENTERED = "";//记账人
MsCwVouchersGl.ERRMSG = "";//错误信息
MsCwVouchersGl.ISDELETE = false;//是否废除
MsCwVouchersGl.DELETEUSER = "";//废除操作人
//MsCwVouchersGl.DELETETIME="";//废除时间
MsCwVouchersGl.CarryOverType = "期末调汇";//废除操作人
MsCwVouchersGl.STARTGID = strCwSTARTGID;
#endregion
CwVouchersGlEntities.Add(MsCwVouchersGl);
#endregion
}
else
{
if (iscType1 > 0)
{
#region 插入主表
MsCwVouchersGl MsCwVouchersGl = new MsCwVouchersGl();
MsCwVouchersGl.ORDNO = strORDNO.Trim();//唯一编码 newid()
DateTime rq = DateTime.Parse(headData.VOUDATE.ToString().Trim());
MsCwVouchersGl.VOUDATE = rq.ToString().Trim();
MsCwVouchersGl.ACCYEAR = rq.Year.ToString().Trim();//年
string strACCMONTH = rq.Month.ToString().Trim();
if (strACCMONTH.Length == 1)
{
strACCMONTH = "0" + strACCMONTH;
}
MsCwVouchersGl.VKNO = headData.VKNO.ToString().Trim();//凭证字
MsCwVouchersGl.VOUNO = strVOUNO;//月初清零
MsCwVouchersGl.ACCMONTH = strACCMONTH;//月
string strVOUALLNO = MsCwVouchersGl.VOUNO.ToString();
for (int i = 0; i < (4 - MsCwVouchersGl.VOUNO.ToString().Length); i++)
{
strVOUALLNO = "0" + strVOUALLNO;
}
strVOUALLNO = MsCwVouchersGl.VKNO + MsCwVouchersGl.ACCYEAR + strACCMONTH + strVOUALLNO;
MsCwVouchersGl.VOUALLNO = strVOUALLNO;//月初清零
MsCwVouchersGl.ATTACHS = 0;//附件(单据)数
MsCwVouchersGl.AMTDR = 0;//本位币借方
MsCwVouchersGl.AMTCR = 0;//本位币贷方
MsCwVouchersGl.FCY = "";//是否含有外币科目
MsCwVouchersGl.QTY = "";//是否含有数量科目
MsCwVouchersGl.VOUPROP = "";//凭证属性
MsCwVouchersGl.PREPARED = strSHOWNAME.Trim();//制单人
MsCwVouchersGl.CHECKED = "";//审核人
MsCwVouchersGl.ENTERED = "";//记账人
MsCwVouchersGl.ERRMSG = "";//错误信息
MsCwVouchersGl.ISDELETE = false;//是否废除
MsCwVouchersGl.DELETEUSER = "";//废除操作人
//MsCwVouchersGl.DELETETIME="";//废除时间
MsCwVouchersGl.CarryOverType = "期末调汇";//废除操作人
MsCwVouchersGl.STARTGID = strCwSTARTGID;
CwVouchersGlEntities.Add(MsCwVouchersGl);
#endregion
if (iscType2 > 0)
{
#region 分别生成收益凭证和损失凭证
#region 插入主表
MsCwVouchersGl MsCwVouchersGl1 = new MsCwVouchersGl();
MsCwVouchersGl1.ORDNO = cType1_ORDNO.Trim();//唯一编码 newid()
rq = DateTime.Parse(headData.VOUDATE.ToString().Trim());
MsCwVouchersGl1.VOUDATE = rq.ToString().Trim();//
MsCwVouchersGl1.ACCYEAR = rq.Year.ToString().Trim();//年
strACCMONTH = rq.Month.ToString().Trim();
if (strACCMONTH.Length == 1)
{
strACCMONTH = "0" + strACCMONTH;
}
MsCwVouchersGl1.VKNO = headData.VKNO.ToString().Trim();//凭证字
strVOUNO = (int.Parse(headData.VOUNO) + 1).ToString().Trim();
MsCwVouchersGl1.VOUNO = strVOUNO;//月初清零
MsCwVouchersGl1.ACCMONTH = strACCMONTH;//月
string sVOUALLNO = MsCwVouchersGl1.VOUNO.ToString();
for (int i = 0; i < (4 - MsCwVouchersGl1.VOUNO.ToString().Length); i++)
{
sVOUALLNO = "0" + sVOUALLNO;
}
sVOUALLNO = MsCwVouchersGl1.VKNO + MsCwVouchersGl1.ACCYEAR + strACCMONTH + sVOUALLNO;
MsCwVouchersGl.VOUALLNO = sVOUALLNO;//月初清零
MsCwVouchersGl1.ATTACHS = 0;//附件(单据)数
MsCwVouchersGl1.AMTDR = 0;//本位币借方
MsCwVouchersGl1.AMTCR = 0;//本位币贷方
MsCwVouchersGl1.FCY = "";//是否含有外币科目
MsCwVouchersGl1.QTY = "";//是否含有数量科目
MsCwVouchersGl1.VOUPROP = "";//凭证属性
MsCwVouchersGl1.PREPARED = strSHOWNAME.Trim();//制单人
MsCwVouchersGl1.CHECKED = "";//审核人
MsCwVouchersGl1.ENTERED = "";//记账人
MsCwVouchersGl1.ERRMSG = "";//错误信息
MsCwVouchersGl1.ISDELETE = false;//是否废除
MsCwVouchersGl1.DELETEUSER = "";//废除操作人
//MsCwVouchersGl1.DELETETIME="";//废除时间
MsCwVouchersGl1.CarryOverType = "期末调汇";//废除操作人
MsCwVouchersGl1.STARTGID = strCwSTARTGID;
CwVouchersGlEntities.Add(MsCwVouchersGl1);
#endregion
#endregion
}
}
else
{
if (iscType2 > 0)
{
#region 分别生成收益凭证和损失凭证
#region 插入主表
MsCwVouchersGl MsCwVouchersGl = new MsCwVouchersGl();
MsCwVouchersGl.ORDNO = cType1_ORDNO.Trim();//唯一编码 newid()
DateTime rq = DateTime.Parse(headData.VOUDATE.ToString().Trim());
MsCwVouchersGl.VOUDATE = rq.ToString();//
MsCwVouchersGl.ACCYEAR = rq.Year.ToString().Trim();//年
string strACCMONTH = rq.Month.ToString().Trim();
if (strACCMONTH.Length == 1)
{
strACCMONTH = "0" + strACCMONTH;
}
MsCwVouchersGl.VKNO = headData.VKNO.ToString().Trim();//凭证字
MsCwVouchersGl.VOUNO = strVOUNO;//月初清零
MsCwVouchersGl.ACCMONTH = strACCMONTH;//月
string sVOUALLNO = MsCwVouchersGl.VOUNO.ToString();
for (int i = 0; i < (4 - MsCwVouchersGl.VOUNO.ToString().Length); i++)
{
sVOUALLNO = "0" + sVOUALLNO;
}
sVOUALLNO = MsCwVouchersGl.VKNO + MsCwVouchersGl.ACCYEAR + MsCwVouchersGl.ACCMONTH + sVOUALLNO;
MsCwVouchersGl.VOUALLNO = sVOUALLNO;//月初清零
MsCwVouchersGl.ATTACHS = 0;//附件(单据)数
MsCwVouchersGl.AMTDR = 0;//本位币借方
MsCwVouchersGl.AMTCR = 0;//本位币贷方
MsCwVouchersGl.FCY = "";//是否含有外币科目
MsCwVouchersGl.QTY = "";//是否含有数量科目
MsCwVouchersGl.VOUPROP = "";//凭证属性
MsCwVouchersGl.PREPARED = strSHOWNAME.Trim();//制单人
MsCwVouchersGl.CHECKED = "";//审核人
MsCwVouchersGl.ENTERED = "";//记账人
MsCwVouchersGl.ERRMSG = "";//错误信息
MsCwVouchersGl.ISDELETE = false;//是否废除
MsCwVouchersGl.DELETEUSER = "";//废除操作人
//MsCwVouchersGl.DELETETIME="";//废除时间
MsCwVouchersGl.CarryOverType = "期末调汇";//废除操作人
MsCwVouchersGl.STARTGID = strCwSTARTGID;
CwVouchersGlEntities.Add(MsCwVouchersGl);
#endregion
#endregion
}
}
}
#endregion
}
}
#endregion
#region 生成入库
result = new DBResult();
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 期末调汇_入库
if (bodyList != null)
{
if (bodyList.Count > 0)
{
if (CwVouitemsGlEntities != null)
{
if (CwVouitemsGlEntities.Count > 0)
{
#region 插入明细表
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("insert into Cw_Vouitems_Gl(");
strSql2.Append("GID,AMTDR,AMTCR,ISFCY,FCYNO,FCYEXRATE,FCYDR,FCYCR,QTYUNIT,QTYDR,QTYCR,ORDNO,EXPLAN,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,DEPTID,EMPLID,CORPID,PITEMID,ITEMID,ITEMNO,FIELD10,FIELD9,FIELD8,FIELD7,FIELD6,FIELD5,FIELD4,FIELD3,FIELD2,FIELD1,ACCID,ISSYS,FSETTLCODE,FSETTLENO,PACCID,ACCNAME,PROPERTY,GRADE,DC,CUSTOMERNAME,SALE,BLNO,ITEMGID,DEPTGID,ACCALL,FSETTLDATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql2.Append(") values (");
strSql2.Append("newid(),@AMTDR,@AMTCR,@ISFCY,@FCYNO,@FCYEXRATE,@FCYDR,@FCYCR,@QTYUNIT,@QTYDR,@QTYCR,@ORDNO,@EXPLAN,@ISDEPTACC,@ISEMPLACC,@ISCORPACC,@ISITEMACC,@DEPTID,@EMPLID,@CORPID,@PITEMID,@ITEMID,@ITEMNO,@FIELD10,@FIELD9,@FIELD8,@FIELD7,@FIELD6,@FIELD5,@FIELD4,@FIELD3,@FIELD2,@FIELD1,@ACCID,@ISSYS,@FSETTLCODE,@FSETTLENO,@PACCID,@ACCNAME,@PROPERTY,@GRADE,@DC,@CUSTOMERNAME,@SALE,@BLNO,@ITEMGID,@DEPTGID,@ACCALL,getdate(),@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql2.Append(") ");
#region SqlParameter
SqlParameter[] parameters = new SqlParameter[]{
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ISFCY", SqlDbType.Bit,1) ,
new SqlParameter("@FCYNO", SqlDbType.VarChar,8) ,
new SqlParameter("@FCYEXRATE", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYUNIT", SqlDbType.VarChar,10) ,
new SqlParameter("@QTYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@EXPLAN", SqlDbType.VarChar,60) ,
new SqlParameter("@ISDEPTACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISEMPLACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISCORPACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISITEMACC", SqlDbType.Bit,1) ,
new SqlParameter("@DEPTID", SqlDbType.VarChar,18) ,
new SqlParameter("@EMPLID", SqlDbType.VarChar,18) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,18) ,
new SqlParameter("@PITEMID", SqlDbType.Int,4) ,
new SqlParameter("@ITEMID", SqlDbType.VarChar,50) ,
new SqlParameter("@ITEMNO", SqlDbType.Int,4) ,
new SqlParameter("@FIELD10", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD9", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD8", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD7", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD6", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD5", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD4", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD3", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD2", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD1", SqlDbType.VarChar,50) ,
new SqlParameter("@ACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ISSYS", SqlDbType.Bit,1) ,
new SqlParameter("@FSETTLCODE", SqlDbType.VarChar,20) ,
new SqlParameter("@FSETTLENO", SqlDbType.VarChar,20) ,
new SqlParameter("@PACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ACCNAME", SqlDbType.VarChar,60) ,
new SqlParameter("@PROPERTY", SqlDbType.Int,4) ,
new SqlParameter("@GRADE", SqlDbType.Int,4) ,
new SqlParameter("@DC", SqlDbType.VarChar,1),
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20),
new SqlParameter("@SALE", SqlDbType.VarChar,10),
new SqlParameter("@BLNO", SqlDbType.VarChar,30),
new SqlParameter("@ITEMGID", SqlDbType.VarChar,100),
new SqlParameter("@DEPTGID", SqlDbType.VarChar,100),
new SqlParameter("@ACCALL", SqlDbType.VarChar,500) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
#endregion
foreach (MsCwVouitemsGl model in CwVouitemsGlEntities)
{
#region 插入明细表参数赋值
//parameters[0].Value = model.GID;
parameters[0].Value = model.AMTDR;
parameters[1].Value = model.AMTCR;
parameters[2].Value = model.ISFCY;
parameters[3].Value = model.FCYNO;
parameters[4].Value = model.FCYEXRATE;
parameters[5].Value = model.FCYDR;
parameters[6].Value = model.FCYCR;
parameters[7].Value = model.QTYUNIT;
parameters[8].Value = model.QTYDR;
parameters[9].Value = model.QTYCR;
parameters[10].Value = model.ORDNO;
parameters[11].Value = model.EXPLAN;
parameters[12].Value = model.ISDEPTACC;
parameters[13].Value = model.ISEMPLACC;
parameters[14].Value = model.ISCORPACC;
parameters[15].Value = model.ISITEMACC;
parameters[16].Value = model.DEPTID;
parameters[17].Value = model.EMPLID;
parameters[18].Value = model.CORPID;
parameters[19].Value = model.PITEMID;
parameters[20].Value = model.ITEMID;
parameters[21].Value = model.ITEMNO;
parameters[22].Value = model.FIELD10;
parameters[23].Value = model.FIELD9;
parameters[24].Value = model.FIELD8;
parameters[25].Value = model.FIELD7;
parameters[26].Value = model.FIELD6;
parameters[27].Value = model.FIELD5;
parameters[28].Value = model.FIELD4;
parameters[29].Value = model.FIELD3;
parameters[30].Value = model.FIELD2;
parameters[31].Value = model.FIELD1;
parameters[32].Value = model.ACCID;
parameters[33].Value = model.ISSYS;
parameters[34].Value = model.FSETTLCODE;
parameters[35].Value = model.FSETTLENO;
parameters[36].Value = model.PACCID;
parameters[37].Value = model.ACCNAME;
parameters[38].Value = model.PROPERTY;
parameters[39].Value = model.GRADE;
parameters[40].Value = model.DC;
parameters[41].Value = model.CUSTOMERNAME;
parameters[42].Value = model.SALE;
parameters[43].Value = model.BLNO;
parameters[44].Value = model.ITEMGID;
parameters[45].Value = model.DEPTGID;
parameters[46].Value = model.ACCALL;
parameters[47].Value = strUserID;
parameters[48].Value = strUserID;
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), parameters);
}
#endregion
#region 插入主表
if (CwVouchersGlEntities != null)
{
if (CwVouchersGlEntities.Count > 0)
{
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("insert into Cw_Vouchers_Gl(");
strSql1.Append("ORDNO,FCY,QTY,VOUPROP,PREPARED,CHECKED,ENTERED,ERRMSG,ISDELETE,VOUNO,VKNO,{0}ACCYEAR,ACCMONTH,ATTACHS,AMTDR,AMTCR,VOUALLNO,CarryOverType,STARTGID,ISCARRY,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISAUTO");//,DELETEUSER,DELETETIME
strSql1.Append(") values (");
strSql1.Append("@ORDNO,@FCY,@QTY,@VOUPROP,@PREPARED,@CHECKED,@ENTERED,@ERRMSG,@ISDELETE,@VOUNO,@VKNO,{1}@ACCYEAR,@ACCMONTH,@ATTACHS,@AMTDR,@AMTCR,@VOUALLNO,@CarryOverType,'" + strCwSTARTGID + "','True',@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),1");//,@DELETEUSER,@DELETETIME
strSql1.Append(") ");
#region 插入主表参数赋值
SqlParameter[] parameters1 = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@FCY", SqlDbType.VarChar,1) ,
new SqlParameter("@QTY", SqlDbType.VarChar,1) ,
new SqlParameter("@VOUPROP", SqlDbType.VarChar,1) ,
new SqlParameter("@PREPARED", SqlDbType.VarChar,10) ,
new SqlParameter("@CHECKED", SqlDbType.VarChar,10) ,
new SqlParameter("@ENTERED", SqlDbType.VarChar,10) ,
new SqlParameter("@ERRMSG", SqlDbType.VarChar,6) ,
new SqlParameter("@ISDELETE", SqlDbType.Bit,1) ,
//new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@VOUNO", SqlDbType.VarChar,16) ,
new SqlParameter("@VKNO", SqlDbType.VarChar,8) ,
//new SqlParameter("@VOUDATE", SqlDbType.DateTime) ,
new SqlParameter("@ACCYEAR", SqlDbType.VarChar,4) ,
new SqlParameter("@ACCMONTH", SqlDbType.VarChar,2) ,
new SqlParameter("@ATTACHS", SqlDbType.Int,4) ,
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@VOUALLNO", SqlDbType.VarChar,16) ,
new SqlParameter("@CarryOverType", SqlDbType.VarChar,50) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
#endregion
foreach (MsCwVouchersGl model in CwVouchersGlEntities)
{
#region 插入主表参数赋值
parameters1[0].Value = model.ORDNO;
parameters1[1].Value = model.FCY;
parameters1[2].Value = model.QTY;
parameters1[3].Value = model.VOUPROP;
parameters1[4].Value = model.PREPARED;
parameters1[5].Value = model.CHECKED;
parameters1[6].Value = model.ENTERED;
parameters1[7].Value = model.ERRMSG;
parameters1[8].Value = model.ISDELETE;
//parameters1[9].Value = model.DELETEUSER;
//parameters1[10].Value = model.DELETETIME;
parameters1[9].Value = model.VOUNO;
parameters1[10].Value = model.VKNO;
//parameters1[11].Value = model.VOUDATE;
parameters1[11].Value = model.ACCYEAR;
parameters1[12].Value = model.ACCMONTH;
parameters1[13].Value = model.ATTACHS;
parameters1[14].Value = model.AMTDR;
parameters1[15].Value = model.AMTCR;
parameters1[16].Value = model.VOUALLNO;
parameters1[17].Value = model.CarryOverType;
parameters1[18].Value = strUserID;
parameters1[19].Value = strUserID;
#endregion
string strVOUDATE = model.VOUDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.VOUDATE.ToString() + "',";
string strVOUDATE_name = strVOUDATE.Equals("") ? "" : "VOUDATE,";
string sSql1 = String.Format(strSql1.ToString(), strVOUDATE_name, strVOUDATE);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql1, parameters1);
}
}
}
#endregion
//如果有期末调汇则凭证号加1
strVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
}
}
}
}
#endregion
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
}
#endregion
#region 结转损益
#region 基本设定
IList<MsCwVouitemsGl> CwVouitemsGlEntities2 = new List<MsCwVouitemsGl>();
string strORDNO2 = getGid();
int inum2 = 1;
Decimal dlAMTDR2 = 0;//本年利润 借
Decimal dlAMTCR2 = 0;//本年利润 贷
Decimal dlBLC = 0;//本期本年利润余额
#endregion
#region 插入明细表_合计数据集
strSql = "select *"
+ ",AMTDRCE=(case when DC2='借' then ((AMTDR+AMTDR3)-(AMTCR+AMTCR3)) else 0 end)"
+ ",AMTCRCE=(case when DC2='贷' then ((AMTCR+AMTCR3)-(AMTDR+AMTDR3)) else 0 end)"
+ ",FCYDRCE=(case when DC2='借' then ((FCYDR+FCYDR3)-(FCYCR+FCYCR3)) else 0 end)"
+ ",FCYCRCE=(case when DC2='贷' then ((FCYCR+FCYCR3)-(FCYDR+FCYDR3)) else 0 end)"
+ " from ("
+ " select ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,FCYEXRATE"
+ ",sum(AMTDR) as AMTDR"
+ ",sum(AMTCR) as AMTCR"
+ ",sum(FCYDR) as FCYDR"
+ ",sum(FCYCR) as FCYCR"
+ ",DC,DC2"
+ ",AMTDR3=ISNULL((select top 1 AMTYEARDR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + headData.VOUDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ ",AMTCR3=ISNULL((select top 1 AMTYEARCR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + headData.VOUDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ ",FCYDR3=ISNULL((select top 1 FCYYEARDR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + headData.VOUDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ ",FCYCR3=ISNULL((select top 1 FCYYEARCR from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and CURRENCY=a.FCYNO and DEPTACC=a.DEPTNAME and EMPLACC=a.SALE and CORPACC=a.CUSTOMERNAME and ITEMACC=a.ITEMNAME and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + headData.VOUDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID=a.ACCID)),0)"
+ " from ("
+ " select *"
+ ",DC2=ISNULL((select top 1 DC from cw_accitems_gl where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,4)),'')"
+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item where GID=Cw_Vouitems_Gl.ITEMGID),'')"
+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept where GID=Cw_Vouitems_Gl.DEPTGID),'')"
+ " from Cw_Vouitems_Gl where 1=1"
+ " and ACCID in (select ACCID from [cw_accitems_gl] where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCATTRIBUTE='损益') "
+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and CarryOverType<>'结转损益')"
//+ " and FCYNO='RMB'"
+ ") as a"
+ " group BY ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,DC,DC2,FCYNO,FCYEXRATE) as b"
+ " order by ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,FCYEXRATE";
#endregion
DataSet dsCwVouitemsGl2 = T_ALL_DA.GetAllSQL(strSql);
#region 插入明细表_实体类赋值
if (dsCwVouitemsGl2 != null)
{
if (dsCwVouitemsGl2.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsCwVouitemsGl2.Tables[0].Rows.Count; i++)
{
#region 插入明细表_实体类赋值
MsCwVouitemsGl MsCwVouitemsGl3 = new MsCwVouitemsGl();
MsCwVouitemsGl3.GID = Guid.NewGuid().ToString();
MsCwVouitemsGl3.ORDNO = strORDNO2.Trim();
MsCwVouitemsGl3.ITEMNO = inum2;// 行号
inum2++;
MsCwVouitemsGl3.PACCID = "";//父级科目贷码
MsCwVouitemsGl3.PROPERTY = 0;//科目属性
MsCwVouitemsGl3.GRADE = 0;//科目级别
//
MsCwVouitemsGl3.FCYNO = dsCwVouitemsGl2.Tables[0].Rows[i]["FCYNO"].ToString().Trim();//外币编号usd
MsCwVouitemsGl3.ISFCY = false;//是否外币
if (MsCwVouitemsGl3.FCYNO.ToString().Trim() != "RMB")
{
MsCwVouitemsGl3.ISFCY = true;//是否外币
}
MsCwVouitemsGl3.FCYEXRATE = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYEXRATE"].ToString().Trim());//汇率
MsCwVouitemsGl3.FCYDR = 0;
MsCwVouitemsGl3.FCYCR = 0;
#region 按科目属性中定义的科目方向进行反方向结转
if (dsCwVouitemsGl2.Tables[0].Rows[i]["DC2"].ToString().Trim() == "贷")//"借"
{
#region 借
if (Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim()) == 0)
{
MsCwVouitemsGl3.AMTDR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTDRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYDR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYDRCE"].ToString().Trim());
}
}
else
{
MsCwVouitemsGl3.AMTDR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYDR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYDRCE"].ToString().Trim());
}
}
dlAMTDR2 += MsCwVouitemsGl3.AMTDR;
MsCwVouitemsGl3.AMTCR = 0;
MsCwVouitemsGl3.DC = "D";//借方向
#endregion
}
else
{
#region 贷
if (Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim()) == 0)
{
MsCwVouitemsGl3.AMTCR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTDRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYCR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYDRCE"].ToString().Trim());
}
}
else
{
MsCwVouitemsGl3.AMTCR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYCR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYCRCE"].ToString().Trim());
}
}
dlAMTCR2 += MsCwVouitemsGl3.AMTCR;
MsCwVouitemsGl3.AMTDR = 0;
MsCwVouitemsGl3.DC = "C";//贷方向
#endregion
}
#endregion
#region 按科目余额反向结转
if (headData.cbJZFS.ToString().Trim() == "true")
{
if (Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim()) == 0)
{
MsCwVouitemsGl3.AMTDR = 0;
MsCwVouitemsGl3.AMTCR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTDRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYCR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYDRCE"].ToString().Trim());
}
dlAMTCR2 += MsCwVouitemsGl3.AMTCR;
MsCwVouitemsGl3.DC = "C";//借方向
if (Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTDRCE"].ToString().Trim()) < 0)
{
MsCwVouitemsGl3.AMTDR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTDRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYDR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYDRCE"].ToString().Trim());
}
MsCwVouitemsGl3.AMTCR = 0;
dlAMTDR2 += MsCwVouitemsGl3.AMTDR;
MsCwVouitemsGl3.DC = "D";//借方向
}
}
else
{
MsCwVouitemsGl3.AMTDR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYDR = Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYCRCE"].ToString().Trim());
}
MsCwVouitemsGl3.AMTCR = 0;
dlAMTDR2 += MsCwVouitemsGl3.AMTDR;
MsCwVouitemsGl3.DC = "D";//借方向
if (Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim()) < 0)
{
MsCwVouitemsGl3.AMTDR = 0;
MsCwVouitemsGl3.AMTCR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["AMTCRCE"].ToString().Trim());
if (MsCwVouitemsGl3.ISFCY)
{
MsCwVouitemsGl3.FCYCR = -Decimal.Parse(dsCwVouitemsGl2.Tables[0].Rows[i]["FCYCRCE"].ToString().Trim());
}
dlAMTCR2 += MsCwVouitemsGl3.AMTCR;
MsCwVouitemsGl3.DC = "C";//借方向
}
}
}
#endregion
MsCwVouitemsGl3.SALE = dsCwVouitemsGl2.Tables[0].Rows[i]["SALE"].ToString().Trim();//strSALE;//人员名称
MsCwVouitemsGl3.CUSTOMERNAME = dsCwVouitemsGl2.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
string sSQL = "select top 1 GID from cw_item WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and ITEMNAME='" + dsCwVouitemsGl2.Tables[0].Rows[i]["ITEMNAME"].ToString().Trim() + "'";
MsCwVouitemsGl3.ITEMGID = T_ALL_DA.GetStrSQL("GID", sSQL);//项目名称//varchar
sSQL = "select top 1 GID from sys_dept WITH(NOLOCK) where DEPTNAME='" + dsCwVouitemsGl2.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim() + "'";
MsCwVouitemsGl3.DEPTGID = T_ALL_DA.GetStrSQL("GID", sSQL);
sSQL = "select top 1 FINANCESOFTCODE from sys_dept WITH(NOLOCK) where DEPTNAME='" + dsCwVouitemsGl2.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim() + "'";
MsCwVouitemsGl3.DEPTID = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", sSQL);
MsCwVouitemsGl3.ACCALL = dsCwVouitemsGl2.Tables[0].Rows[i]["ACCALL"].ToString().Trim();//科目名称
MsCwVouitemsGl3.ACCID = dsCwVouitemsGl2.Tables[0].Rows[i]["ACCID"].ToString().Trim();//科目
MsCwVouitemsGl3.ACCNAME = dsCwVouitemsGl2.Tables[0].Rows[i]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl3.ISDEPTACC = false;//核算部门,按规则设置生成
MsCwVouitemsGl3.ISEMPLACC = false;//核算人员,按规则设置生成
MsCwVouitemsGl3.ISCORPACC = false;//核算客户,按规则设置生成
MsCwVouitemsGl3.ISITEMACC = false;//核算项目,按规则设置生成
MsCwVouitemsGl3.EXPLAN = "结转本期损益";//摘要规则生成ALL
if (dsCwVouitemsGl2.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISDEPTACC = true;//核算部门,按规则设置生成
}
if (dsCwVouitemsGl2.Tables[0].Rows[i]["SALE"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISEMPLACC = true;//核算人员,按规则设置生成
}
if (dsCwVouitemsGl2.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISCORPACC = true;//核算客户,按规则设置生成
}
if (dsCwVouitemsGl2.Tables[0].Rows[i]["ITEMNAME"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISITEMACC = true;//核算项目,按规则设置生成
}
//
MsCwVouitemsGl3.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl3.QTYDR = 0;//借方数量
MsCwVouitemsGl3.QTYCR = 0;//贷方数量
MsCwVouitemsGl3.CORPID = "";//客户(系统)
MsCwVouitemsGl3.DEPTID = "";//部门(系统)
MsCwVouitemsGl3.EMPLID = "";//人员(系统)
MsCwVouitemsGl3.ITEMID = "0";//项目编号
MsCwVouitemsGl3.PITEMID = 0;//父级项目编号
MsCwVouitemsGl3.FIELD1 = "";//预留字段1
MsCwVouitemsGl3.FIELD2 = "";//预留字段2
MsCwVouitemsGl3.FIELD3 = "";//预留字段3
MsCwVouitemsGl3.FIELD4 = "";//预留字段4
MsCwVouitemsGl3.FIELD5 = "";//预留字段5
MsCwVouitemsGl3.FIELD6 = "";//预留字段6
MsCwVouitemsGl3.FIELD7 = "";//预留字段7
MsCwVouitemsGl3.FIELD8 = "";//预留字段8
MsCwVouitemsGl3.FIELD9 = "";//预留字段9
MsCwVouitemsGl3.FIELD10 = "";//预留字段10
MsCwVouitemsGl3.ISSYS = false;//是否手动录入
MsCwVouitemsGl3.FSETTLCODE = "";//结算方式
MsCwVouitemsGl3.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl3.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl3.BLNO = "";
MsCwVouitemsGl3.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl3.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl3.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl3.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsGlEntities2.Add(MsCwVouitemsGl3);
}
//
#region 更新月末结转标志 ISCARRY
string sls = "update cw_vouchers_gl set ISCARRY=1 where ORDNO in (select ORDNO FROM Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7))";
#endregion
T_ALL_DA.GetExecuteSqlCommand(sls);
}
}
else {
#region 更新月末结转标志 ISCARRY
string sls = "update cw_vouchers_gl set ISCARRY=1 where ORDNO in (select ORDNO FROM Cw_Vouchers_Gl where STARTGID='" + strCwSTARTGID + "' and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7))";
#endregion
T_ALL_DA.GetExecuteSqlCommand(sls);
}
#endregion
#region 本年利润
if (dlAMTDR2 != dlAMTCR2)
{
#region 本年利润
MsCwVouitemsGl MsCwVouitemsGl4 = new MsCwVouitemsGl();
MsCwVouitemsGl4.GID = Guid.NewGuid().ToString();
MsCwVouitemsGl4.ORDNO = strORDNO2.Trim();
MsCwVouitemsGl4.ITEMNO = inum2;//行号
inum2++;
if (dlAMTDR2 > dlAMTCR2)
{
#region 借
MsCwVouitemsGl4.AMTDR = 0;
MsCwVouitemsGl4.FCYDR = 0;
MsCwVouitemsGl4.AMTCR = dlAMTDR2 - dlAMTCR2;
MsCwVouitemsGl4.FCYCR = 0;
MsCwVouitemsGl4.DC = "D";//借方向
dlBLC = dlAMTDR2 - dlAMTCR2;
#endregion
}
else
{
#region 贷
MsCwVouitemsGl4.AMTDR = dlAMTCR2 - dlAMTDR2;
MsCwVouitemsGl4.FCYDR = 0;
MsCwVouitemsGl4.AMTCR = 0;
MsCwVouitemsGl4.FCYCR = 0;
MsCwVouitemsGl4.DC = "C";//借方向
dlBLC = -(dlAMTCR2 - dlAMTDR2);
#endregion
}
MsCwVouitemsGl4.ISFCY = false;//是否外币
MsCwVouitemsGl4.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl4.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl4.CUSTOMERNAME = "";//客户(系统)
MsCwVouitemsGl4.ITEMGID = "";//项目名称//varchar
MsCwVouitemsGl4.DEPTGID = "";
//
MsCwVouitemsGl4.ACCID = "";//科目
MsCwVouitemsGl4.ACCALL = "";
MsCwVouitemsGl4.ACCNAME = headData.CurrentYearProfits.ToString().Trim();
string sSQL = "select top 1 * from cw_accitems_gl With(NOLOCK) where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + headData.CurrentYearProfits.ToString().Trim() + "'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
MsCwVouitemsGl4.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString();//科目
MsCwVouitemsGl4.ACCALL = BasicDataRefDAL.setCAGA(ds.Tables[0].Rows[0]["PACCGID"].ToString(), ds.Tables[0].Rows[0]["ACCNAME"].ToString());
MsCwVouitemsGl4.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString();//科目
}
}
//
MsCwVouitemsGl4.FCYEXRATE = 1;//汇率
MsCwVouitemsGl4.ISDEPTACC = false;//核算部门,按规则设置生成
MsCwVouitemsGl4.ISEMPLACC = false;//核算人员,按规则设置生成
MsCwVouitemsGl4.ISCORPACC = false;//核算客户,按规则设置生成
MsCwVouitemsGl4.ISITEMACC = false;//核算项目,按规则设置生成
MsCwVouitemsGl4.EXPLAN = "结转本期损益";//摘要规则生成ALL
//
MsCwVouitemsGl4.PACCID = "";//父级科目贷码
MsCwVouitemsGl4.PROPERTY = 0;//科目属性
MsCwVouitemsGl4.GRADE = 0;//科目级别
MsCwVouitemsGl4.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl4.QTYDR = 0;//借方数量
MsCwVouitemsGl4.QTYCR = 0;//贷方数量
MsCwVouitemsGl4.CORPID = "";//客户(系统)
MsCwVouitemsGl4.DEPTID = "";//部门(系统)
MsCwVouitemsGl4.EMPLID = "";//人员(系统)
MsCwVouitemsGl4.ITEMID = "0";//项目编号
MsCwVouitemsGl4.PITEMID = 0;//父级项目编号
MsCwVouitemsGl4.FIELD1 = "";//预留字段1
MsCwVouitemsGl4.FIELD2 = "";//预留字段2
MsCwVouitemsGl4.FIELD3 = "";//预留字段3
MsCwVouitemsGl4.FIELD4 = "";//预留字段4
MsCwVouitemsGl4.FIELD5 = "";//预留字段5
MsCwVouitemsGl4.FIELD6 = "";//预留字段6
MsCwVouitemsGl4.FIELD7 = "";//预留字段7
MsCwVouitemsGl4.FIELD8 = "";//预留字段8
MsCwVouitemsGl4.FIELD9 = "";//预留字段9
MsCwVouitemsGl4.FIELD10 = "";//预留字段10
MsCwVouitemsGl4.ISSYS = false;//是否手动录入
MsCwVouitemsGl4.FSETTLCODE = "";//结算方式
MsCwVouitemsGl4.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl4.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl4.BLNO = "";
MsCwVouitemsGl4.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl4.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl4.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl4.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
CwVouitemsGlEntities2.Add(MsCwVouitemsGl4);
#endregion
}
#endregion
///////////////////////////////////////////////////////
#region 插入主表
MsCwVouchersGl MsCwVouchersGl4 = new MsCwVouchersGl();
MsCwVouchersGl4.ORDNO = strORDNO2.Trim();//唯一编码 newid()
DateTime rq2 = DateTime.Parse(headData.VOUDATE.ToString().Trim());
MsCwVouchersGl4.VOUDATE = rq2.ToString();//
MsCwVouchersGl4.ACCYEAR = rq2.Year.ToString();//年
string strACCMONTH2 = rq2.Month.ToString();
if (strACCMONTH2.Length == 1)
{
strACCMONTH2 = "0" + strACCMONTH2;
}
MsCwVouchersGl4.VKNO = headData.VKNO.ToString().Trim();//凭证字
//strVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
MsCwVouchersGl4.VOUNO = strVOUNO;//月初清零
MsCwVouchersGl4.ACCMONTH = strACCMONTH2;//月
string strVOUALLNO2 = MsCwVouchersGl4.VOUNO.ToString();
for (int i = 0; i < (4 - MsCwVouchersGl4.VOUNO.ToString().Length); i++)
{
strVOUALLNO2 = "0" + strVOUALLNO2;
}
strVOUALLNO2 = MsCwVouchersGl4.VKNO + MsCwVouchersGl4.ACCYEAR + MsCwVouchersGl4.ACCMONTH + strVOUALLNO2;
MsCwVouchersGl4.VOUALLNO = strVOUALLNO2;//月初清零
MsCwVouchersGl4.ATTACHS = 0;//附件(单据)数
MsCwVouchersGl4.AMTDR = 0;//本位币借方
MsCwVouchersGl4.AMTCR = 0;//本位币贷方
MsCwVouchersGl4.FCY = "";//是否含有外币科目
MsCwVouchersGl4.QTY = "";//是否含有数量科目
MsCwVouchersGl4.VOUPROP = "";//凭证属性
MsCwVouchersGl4.PREPARED = strSHOWNAME.Trim();//制单人
MsCwVouchersGl4.CHECKED = "";//审核人
MsCwVouchersGl4.ENTERED = "";//记账人
MsCwVouchersGl4.ERRMSG = "";//错误信息
MsCwVouchersGl4.ISDELETE = false;//是否废除
MsCwVouchersGl4.DELETEUSER = "";//废除操作人
//MsCwVouchersGl4.DELETETIME="";//废除时间
MsCwVouchersGl4.CarryOverType = "结转损益";//废除操作人
MsCwVouchersGl4.STARTGID = strCwSTARTGID;
MsCwVouchersGl4.ISCARRY = true;
MsCwVouchersGl4.CREATEUSER = strUserID;//创建人
MsCwVouchersGl4.CREATETIME = DateTime.Now;//创建时间
MsCwVouchersGl4.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouchersGl4.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
#region 生成入库
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 默认结转科目_入库
string sSQL = "select top 1 gid from cw_carry_accitems With(NOLOCK) where STARTGID='" + strCwSTARTGID + "'";// and CORPID='" + companyid + "'
string sGID = T_ALL_DA.GetStrSQL("gid", sSQL);//科目
if (sGID == "")//插入0
{
sSQL = "INSERT INTO [cw_carry_accitems]([GID],[ExchangeGains],[ExchangeLoss],[CurrentYearProfits],[UndistributedProfit],[CORPID],[MODIFIEDUSER],[MODIFIEDTIME],STARTGID) VALUES(newid(),'" + headData.ExchangeGains.ToString().Trim() + "','" + headData.ExchangeLoss.ToString().Trim() + "','" + headData.CurrentYearProfits.ToString().Trim() + "','" + headData.UndistributedProfit.ToString().Trim() + "','" + companyid + "','" + strUserID + "',GETDATE(),'" + strCwSTARTGID + "')";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
else//更新
{
sSQL = "UPDATE [cw_carry_accitems] SET [ExchangeGains] = '" + headData.ExchangeGains.ToString().Trim() + "',[ExchangeLoss] = '" + headData.ExchangeLoss.ToString().Trim() + "',[CurrentYearProfits] = '" + headData.CurrentYearProfits.ToString().Trim() + "',[UndistributedProfit] = '" + headData.UndistributedProfit.ToString().Trim() + "',[CORPID] = '" + companyid + "',[MODIFIEDUSER] = '" + strUserID + "',[MODIFIEDTIME] = GETDATE(),STARTGID='" + strCwSTARTGID + "' WHERE [GID] = '" + sGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
#endregion
#region 期末调汇_入库
if (CwVouitemsGlEntities2 != null)
{
if (CwVouitemsGlEntities2.Count > 0)
{
#region 插入明细表
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("insert into Cw_Vouitems_Gl(");
strSql2.Append("GID,AMTDR,AMTCR,ISFCY,FCYNO,FCYEXRATE,FCYDR,FCYCR,QTYUNIT,QTYDR,QTYCR,ORDNO,EXPLAN,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,DEPTID,EMPLID,CORPID,PITEMID,ITEMID,ITEMNO,FIELD10,FIELD9,FIELD8,FIELD7,FIELD6,FIELD5,FIELD4,FIELD3,FIELD2,FIELD1,ACCID,ISSYS,FSETTLCODE,FSETTLENO,PACCID,ACCNAME,PROPERTY,GRADE,DC,CUSTOMERNAME,SALE,BLNO,ITEMGID,DEPTGID,ACCALL,FSETTLDATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql2.Append(") values (");
strSql2.Append("newid(),@AMTDR,@AMTCR,@ISFCY,@FCYNO,@FCYEXRATE,@FCYDR,@FCYCR,@QTYUNIT,@QTYDR,@QTYCR,@ORDNO,@EXPLAN,@ISDEPTACC,@ISEMPLACC,@ISCORPACC,@ISITEMACC,@DEPTID,@EMPLID,@CORPID,@PITEMID,@ITEMID,@ITEMNO,@FIELD10,@FIELD9,@FIELD8,@FIELD7,@FIELD6,@FIELD5,@FIELD4,@FIELD3,@FIELD2,@FIELD1,@ACCID,@ISSYS,@FSETTLCODE,@FSETTLENO,@PACCID,@ACCNAME,@PROPERTY,@GRADE,@DC,@CUSTOMERNAME,@SALE,@BLNO,@ITEMGID,@DEPTGID,@ACCALL,getdate(),@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql2.Append(") ");
#region SqlParameter
SqlParameter[] parameters = new SqlParameter[]{
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ISFCY", SqlDbType.Bit,1) ,
new SqlParameter("@FCYNO", SqlDbType.VarChar,8) ,
new SqlParameter("@FCYEXRATE", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYUNIT", SqlDbType.VarChar,10) ,
new SqlParameter("@QTYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@EXPLAN", SqlDbType.VarChar,60) ,
new SqlParameter("@ISDEPTACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISEMPLACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISCORPACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISITEMACC", SqlDbType.Bit,1) ,
new SqlParameter("@DEPTID", SqlDbType.VarChar,18) ,
new SqlParameter("@EMPLID", SqlDbType.VarChar,18) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,18) ,
new SqlParameter("@PITEMID", SqlDbType.Int,4) ,
new SqlParameter("@ITEMID", SqlDbType.VarChar,50) ,
new SqlParameter("@ITEMNO", SqlDbType.Int,4) ,
new SqlParameter("@FIELD10", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD9", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD8", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD7", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD6", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD5", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD4", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD3", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD2", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD1", SqlDbType.VarChar,50) ,
new SqlParameter("@ACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ISSYS", SqlDbType.Bit,1) ,
new SqlParameter("@FSETTLCODE", SqlDbType.VarChar,20) ,
new SqlParameter("@FSETTLENO", SqlDbType.VarChar,20) ,
new SqlParameter("@PACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ACCNAME", SqlDbType.VarChar,60) ,
new SqlParameter("@PROPERTY", SqlDbType.Int,4) ,
new SqlParameter("@GRADE", SqlDbType.Int,4) ,
new SqlParameter("@DC", SqlDbType.VarChar,1),
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20),
new SqlParameter("@SALE", SqlDbType.VarChar,10),
new SqlParameter("@BLNO", SqlDbType.VarChar,30),
new SqlParameter("@ITEMGID", SqlDbType.VarChar,100),
new SqlParameter("@DEPTGID", SqlDbType.VarChar,100),
new SqlParameter("@ACCALL", SqlDbType.VarChar,500),
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
#endregion
foreach (MsCwVouitemsGl model in CwVouitemsGlEntities2)
{
#region 插入明细表参数赋值
//parameters[0].Value = model.GID;
parameters[0].Value = model.AMTDR;
parameters[1].Value = model.AMTCR;
parameters[2].Value = model.ISFCY;
parameters[3].Value = model.FCYNO;
parameters[4].Value = model.FCYEXRATE;
parameters[5].Value = model.FCYDR;
parameters[6].Value = model.FCYCR;
parameters[7].Value = model.QTYUNIT;
parameters[8].Value = model.QTYDR;
parameters[9].Value = model.QTYCR;
parameters[10].Value = model.ORDNO;
parameters[11].Value = model.EXPLAN;
parameters[12].Value = model.ISDEPTACC;
parameters[13].Value = model.ISEMPLACC;
parameters[14].Value = model.ISCORPACC;
parameters[15].Value = model.ISITEMACC;
parameters[16].Value = model.DEPTID;
parameters[17].Value = model.EMPLID;
parameters[18].Value = model.CORPID;
parameters[19].Value = model.PITEMID;
parameters[20].Value = model.ITEMID;
parameters[21].Value = model.ITEMNO;
parameters[22].Value = model.FIELD10;
parameters[23].Value = model.FIELD9;
parameters[24].Value = model.FIELD8;
parameters[25].Value = model.FIELD7;
parameters[26].Value = model.FIELD6;
parameters[27].Value = model.FIELD5;
parameters[28].Value = model.FIELD4;
parameters[29].Value = model.FIELD3;
parameters[30].Value = model.FIELD2;
parameters[31].Value = model.FIELD1;
parameters[32].Value = model.ACCID;
parameters[33].Value = model.ISSYS;
parameters[34].Value = model.FSETTLCODE;
parameters[35].Value = model.FSETTLENO;
parameters[36].Value = model.PACCID;
parameters[37].Value = model.ACCNAME;
parameters[38].Value = model.PROPERTY;
parameters[39].Value = model.GRADE;
parameters[40].Value = model.DC;
parameters[41].Value = model.CUSTOMERNAME;
parameters[42].Value = model.SALE;
parameters[43].Value = model.BLNO;
parameters[44].Value = model.ITEMGID;
parameters[45].Value = model.DEPTGID;
parameters[46].Value = model.ACCALL;
parameters[47].Value = strUserID;
parameters[48].Value = strUserID;
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), parameters);
}
#endregion
#region 插入主表
if (MsCwVouchersGl4 != null)
{
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("insert into Cw_Vouchers_Gl(");
strSql1.Append("ORDNO,FCY,QTY,VOUPROP,PREPARED,CHECKED,ENTERED,ERRMSG,ISDELETE,VOUNO,VKNO,{0}ACCYEAR,ACCMONTH,ATTACHS,AMTDR,AMTCR,VOUALLNO,CarryOverType,STARTGID,ISCARRY,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISAUTO");//,DELETEUSER,DELETETIME
strSql1.Append(") values (");
strSql1.Append("@ORDNO,@FCY,@QTY,@VOUPROP,@PREPARED,@CHECKED,@ENTERED,@ERRMSG,@ISDELETE,@VOUNO,@VKNO,{1}@ACCYEAR,@ACCMONTH,@ATTACHS,@AMTDR,@AMTCR,@VOUALLNO,@CarryOverType,'" + strCwSTARTGID + "','True',@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),1");//,@DELETEUSER,@DELETETIME
strSql1.Append(") ");
#region 插入主表参数赋值
SqlParameter[] parameters1 = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@FCY", SqlDbType.VarChar,1) ,
new SqlParameter("@QTY", SqlDbType.VarChar,1) ,
new SqlParameter("@VOUPROP", SqlDbType.VarChar,1) ,
new SqlParameter("@PREPARED", SqlDbType.VarChar,10) ,
new SqlParameter("@CHECKED", SqlDbType.VarChar,10) ,
new SqlParameter("@ENTERED", SqlDbType.VarChar,10) ,
new SqlParameter("@ERRMSG", SqlDbType.VarChar,6) ,
new SqlParameter("@ISDELETE", SqlDbType.Bit,1) ,
//new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@VOUNO", SqlDbType.VarChar,16) ,
new SqlParameter("@VKNO", SqlDbType.VarChar,8) ,
//new SqlParameter("@VOUDATE", SqlDbType.DateTime) ,
new SqlParameter("@ACCYEAR", SqlDbType.VarChar,4) ,
new SqlParameter("@ACCMONTH", SqlDbType.VarChar,2) ,
new SqlParameter("@ATTACHS", SqlDbType.Int,4) ,
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@VOUALLNO", SqlDbType.VarChar,16) ,
new SqlParameter("@CarryOverType", SqlDbType.VarChar,50),
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
#endregion
#region 插入主表参数赋值
parameters1[0].Value = MsCwVouchersGl4.ORDNO;
parameters1[1].Value = MsCwVouchersGl4.FCY;
parameters1[2].Value = MsCwVouchersGl4.QTY;
parameters1[3].Value = MsCwVouchersGl4.VOUPROP;
parameters1[4].Value = MsCwVouchersGl4.PREPARED;
parameters1[5].Value = MsCwVouchersGl4.CHECKED;
parameters1[6].Value = MsCwVouchersGl4.ENTERED;
parameters1[7].Value = MsCwVouchersGl4.ERRMSG;
parameters1[8].Value = MsCwVouchersGl4.ISDELETE;
//parameters1[9].Value = MsCwVouchersGl4.DELETEUSER;
//parameters1[10].Value = MsCwVouchersGl4.DELETETIME;
parameters1[9].Value = MsCwVouchersGl4.VOUNO;
parameters1[10].Value = MsCwVouchersGl4.VKNO;
//parameters1[11].Value = MsCwVouchersGl4.VOUDATE;
parameters1[11].Value = MsCwVouchersGl4.ACCYEAR;
parameters1[12].Value = MsCwVouchersGl4.ACCMONTH;
parameters1[13].Value = MsCwVouchersGl4.ATTACHS;
parameters1[14].Value = MsCwVouchersGl4.AMTDR;
parameters1[15].Value = MsCwVouchersGl4.AMTCR;
parameters1[16].Value = MsCwVouchersGl4.VOUALLNO;
parameters1[17].Value = MsCwVouchersGl4.CarryOverType;
parameters1[18].Value = MsCwVouchersGl4.CREATEUSER;
parameters1[19].Value = MsCwVouchersGl4.MODIFIEDUSER;
#endregion
string strVOUDATE = MsCwVouchersGl4.VOUDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + MsCwVouchersGl4.VOUDATE.ToString() + "',";
string strVOUDATE_name = strVOUDATE.Equals("") ? "" : "VOUDATE,";
string sSql1 = String.Format(strSql1.ToString(), strVOUDATE_name, strVOUDATE);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql1, parameters1);
}
#endregion
}
}
#endregion
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
#endregion
#region 年末结转
#region 基本设定
IList<MsCwVouitemsGl> CwVouitemsGlEntities3 = new List<MsCwVouitemsGl>();
string strORDNO3 = getGid();
int inum3 = 1;
string sMONTH = strCwACCDATE.Substring(5);
//年末结转则凭证号加1
strVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
#endregion
if (sMONTH == "12")
{
#region 从总账表取期末累计余额_本年利润
//本年利润
strSql = "SELECT ACCID=ISNULL((SELECT TOP 1 ACCID from cw_accitems_gl WHERE GID=[cw_genleg_accitems].LINKGID),''),ACCNAME=ISNULL((SELECT TOP 1 ACCNAME from cw_accitems_gl WHERE GID=[cw_genleg_accitems].LINKGID),''),DC2=ISNULL((select top 1 DC from cw_accitems_gl WHERE GID=[cw_genleg_accitems].LINKGID),''),ITEMGID=ISNULL((select top 1 GID from cw_item WHERE ITEMNAME=[cw_genleg_accitems].ITEMACC),''),DEPTGID=ISNULL((select top 1 GID from sys_dept WHERE DEPTNAME=[cw_genleg_accitems].DEPTACC),''),DEPTID=ISNULL((select top 1 FINANCESOFTCODE from sys_dept WHERE DEPTNAME=[cw_genleg_accitems].DEPTACC),''),BLC=(QTYLASTBLC+" + dlBLC + "),* FROM [cw_genleg_accitems] where [STARTGID]='" + strCwSTARTGID + "' and ACCDATE='" + strCwACCDATE + "' and LINKGID=(select GID from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and ACCID='" + headData.CurrentYearProfits.ToString().Trim() + "' and [STARTGID]='" + strCwSTARTGID + "' )";// and AMTLASTBLC<>0
#endregion
DataSet dsCurrentYearProfits = T_ALL_DA.GetAllSQL(strSql);
#region 插入明细表_实体类赋值
if (dsCurrentYearProfits != null)
{
if (dsCurrentYearProfits.Tables[0].Rows.Count > 0)
{
#region 插入明细表_实体类赋值
MsCwVouitemsGl MsCwVouitemsGl3 = new MsCwVouitemsGl();
MsCwVouitemsGl MsCwVouitemsGl4 = new MsCwVouitemsGl();
MsCwVouitemsGl3.GID = Guid.NewGuid().ToString();
MsCwVouitemsGl3.ORDNO = strORDNO3.Trim();
MsCwVouitemsGl3.ITEMNO = inum3;// 行号
inum3++;
MsCwVouitemsGl3.PACCID = "";//父级科目贷码
MsCwVouitemsGl3.PROPERTY = 0;//科目属性
MsCwVouitemsGl3.GRADE = 0;//科目级别
//
MsCwVouitemsGl4.GID = Guid.NewGuid().ToString();
MsCwVouitemsGl4.ORDNO = strORDNO3.Trim();
MsCwVouitemsGl4.ITEMNO = inum3;// 行号
inum3++;
MsCwVouitemsGl4.PACCID = "";//父级科目贷码
MsCwVouitemsGl4.PROPERTY = 0;//科目属性
MsCwVouitemsGl4.GRADE = 0;//科目级别
//
#region 按科目属性中定义的科目方向进行反方向结转
if (dsCurrentYearProfits.Tables[0].Rows[0]["DC2"].ToString().Trim() == "贷")//"借"
{
#region 科目贷方
if (Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim()) > 0)
{
MsCwVouitemsGl3.AMTDR = Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl4.AMTCR = Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl3.DC = "D";//借方向
MsCwVouitemsGl4.DC = "C";//借方向
}
else if (Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim()) < 0)
{
MsCwVouitemsGl3.AMTCR = -Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl4.AMTDR = -Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl3.DC = "C";//借方向
MsCwVouitemsGl4.DC = "D";//借方向
}
#endregion
}
else
{
#region 科目借方
if (Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim()) > 0)
{
MsCwVouitemsGl3.AMTCR = Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl4.AMTDR = Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl3.DC = "C";//借方向
MsCwVouitemsGl4.DC = "D";//借方向
}
else if (Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim()) < 0)
{
MsCwVouitemsGl3.AMTDR = -Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl4.AMTCR = -Decimal.Parse(dsCurrentYearProfits.Tables[0].Rows[0]["BLC"].ToString().Trim());
MsCwVouitemsGl3.DC = "D";//借方向
MsCwVouitemsGl4.DC = "C";//借方向
}
#endregion
}
MsCwVouitemsGl3.FCYDR = 0;
MsCwVouitemsGl3.FCYCR = 0;
MsCwVouitemsGl4.FCYDR = 0;
MsCwVouitemsGl4.FCYCR = 0;
#endregion
//
MsCwVouitemsGl3.ISFCY = false;//是否外币
MsCwVouitemsGl3.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl3.SALE = dsCurrentYearProfits.Tables[0].Rows[0]["EMPLACC"].ToString().Trim();//strSALE;//人员名称
MsCwVouitemsGl3.CUSTOMERNAME = dsCurrentYearProfits.Tables[0].Rows[0]["CORPACC"].ToString().Trim();//客户(系统)
MsCwVouitemsGl3.ITEMGID = dsCurrentYearProfits.Tables[0].Rows[0]["ITEMGID"].ToString().Trim();//项目名称//varchar
MsCwVouitemsGl3.DEPTGID = dsCurrentYearProfits.Tables[0].Rows[0]["DEPTGID"].ToString().Trim();
MsCwVouitemsGl3.DEPTID = dsCurrentYearProfits.Tables[0].Rows[0]["DEPTID"].ToString().Trim();
MsCwVouitemsGl3.ACCALL = dsCurrentYearProfits.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl3.ACCID = dsCurrentYearProfits.Tables[0].Rows[0]["ACCID"].ToString().Trim();//科目
MsCwVouitemsGl3.ACCNAME = dsCurrentYearProfits.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
MsCwVouitemsGl3.FCYEXRATE = 1;//汇率
MsCwVouitemsGl3.ISDEPTACC = false;//核算部门,按规则设置生成
MsCwVouitemsGl3.ISEMPLACC = false;//核算人员,按规则设置生成
MsCwVouitemsGl3.ISCORPACC = false;//核算客户,按规则设置生成
MsCwVouitemsGl3.ISITEMACC = false;//核算项目,按规则设置生成
MsCwVouitemsGl3.EXPLAN = "结转本年利润";//摘要规则生成ALL
if (dsCurrentYearProfits.Tables[0].Rows[0]["DEPTACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISDEPTACC = true;//核算部门,按规则设置生成
}
if (dsCurrentYearProfits.Tables[0].Rows[0]["EMPLACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISEMPLACC = true;//核算人员,按规则设置生成
}
if (dsCurrentYearProfits.Tables[0].Rows[0]["CORPACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISCORPACC = true;//核算客户,按规则设置生成
}
if (dsCurrentYearProfits.Tables[0].Rows[0]["ITEMACC"].ToString().Trim() != "")
{
MsCwVouitemsGl3.ISITEMACC = true;//核算项目,按规则设置生成
}
//
MsCwVouitemsGl4.ISFCY = false;//是否外币
MsCwVouitemsGl4.FCYNO = "RMB";//外币编号usd
MsCwVouitemsGl4.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl4.CUSTOMERNAME = "";//客户(系统)
MsCwVouitemsGl4.ITEMGID = "";//项目名称//varchar
MsCwVouitemsGl4.DEPTGID = "";
//
MsCwVouitemsGl4.ACCID = "";//科目
MsCwVouitemsGl4.ACCALL = "";
string sSQL = "select top 1 * from cw_accitems_gl With(NOLOCK) where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + headData.UndistributedProfit.ToString().Trim() + "'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
MsCwVouitemsGl4.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString();//科目
MsCwVouitemsGl4.ACCALL = BasicDataRefDAL.setCAGA(ds.Tables[0].Rows[0]["PACCGID"].ToString(), ds.Tables[0].Rows[0]["ACCNAME"].ToString());
MsCwVouitemsGl4.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString();
}
}
//
MsCwVouitemsGl4.FCYEXRATE = 1;//汇率
MsCwVouitemsGl4.ISDEPTACC = false;//核算部门,按规则设置生成
MsCwVouitemsGl4.ISEMPLACC = false;//核算人员,按规则设置生成
MsCwVouitemsGl4.ISCORPACC = false;//核算客户,按规则设置生成
MsCwVouitemsGl4.ISITEMACC = false;//核算项目,按规则设置生成
MsCwVouitemsGl4.EXPLAN = "结转本年利润";//摘要规则生成ALL
//
MsCwVouitemsGl3.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl3.QTYDR = 0;//借方数量
MsCwVouitemsGl3.QTYCR = 0;//贷方数量
MsCwVouitemsGl3.CORPID = "";//客户(系统)
MsCwVouitemsGl3.DEPTID = "";//部门(系统)
MsCwVouitemsGl3.EMPLID = "";//人员(系统)
MsCwVouitemsGl3.ITEMID = "0";//项目编号
MsCwVouitemsGl3.PITEMID = 0;//父级项目编号
MsCwVouitemsGl3.FIELD1 = "";//预留字段1
MsCwVouitemsGl3.FIELD2 = "";//预留字段2
MsCwVouitemsGl3.FIELD3 = "";//预留字段3
MsCwVouitemsGl3.FIELD4 = "";//预留字段4
MsCwVouitemsGl3.FIELD5 = "";//预留字段5
MsCwVouitemsGl3.FIELD6 = "";//预留字段6
MsCwVouitemsGl3.FIELD7 = "";//预留字段7
MsCwVouitemsGl3.FIELD8 = "";//预留字段8
MsCwVouitemsGl3.FIELD9 = "";//预留字段9
MsCwVouitemsGl3.FIELD10 = "";//预留字段10
MsCwVouitemsGl3.ISSYS = false;//是否手动录入
MsCwVouitemsGl3.FSETTLCODE = "";//结算方式
MsCwVouitemsGl3.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl3.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl3.BLNO = "";
MsCwVouitemsGl3.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl3.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl3.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl3.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
//
MsCwVouitemsGl4.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl4.QTYDR = 0;//借方数量
MsCwVouitemsGl4.QTYCR = 0;//贷方数量
MsCwVouitemsGl4.CORPID = "";//客户(系统)
MsCwVouitemsGl4.DEPTID = "";//部门(系统)
MsCwVouitemsGl4.EMPLID = "";//人员(系统)
MsCwVouitemsGl4.ITEMID = "0";//项目编号
MsCwVouitemsGl4.PITEMID = 0;//父级项目编号
MsCwVouitemsGl4.FIELD1 = "";//预留字段1
MsCwVouitemsGl4.FIELD2 = "";//预留字段2
MsCwVouitemsGl4.FIELD3 = "";//预留字段3
MsCwVouitemsGl4.FIELD4 = "";//预留字段4
MsCwVouitemsGl4.FIELD5 = "";//预留字段5
MsCwVouitemsGl4.FIELD6 = "";//预留字段6
MsCwVouitemsGl4.FIELD7 = "";//预留字段7
MsCwVouitemsGl4.FIELD8 = "";//预留字段8
MsCwVouitemsGl4.FIELD9 = "";//预留字段9
MsCwVouitemsGl4.FIELD10 = "";//预留字段10
MsCwVouitemsGl4.ISSYS = false;//是否手动录入
MsCwVouitemsGl4.FSETTLCODE = "";//结算方式
MsCwVouitemsGl4.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl4.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl4.BLNO = "";
MsCwVouitemsGl4.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl4.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl4.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl4.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsGlEntities3.Add(MsCwVouitemsGl3);
CwVouitemsGlEntities3.Add(MsCwVouitemsGl4);
}
}
#endregion
///////////////////////////////////////////////////////
#region 插入主表
MsCwVouchersGl MsCwVouchersGl5 = new MsCwVouchersGl();
MsCwVouchersGl5.ORDNO = strORDNO3.Trim();//唯一编码 newid()
DateTime rq3 = DateTime.Parse(headData.VOUDATE.ToString().Trim());
MsCwVouchersGl5.VOUDATE = rq3.ToString();//
MsCwVouchersGl5.ACCYEAR = rq3.Year.ToString();//年
string strACCMONTH3 = rq3.Month.ToString();
if (strACCMONTH3.Length == 1)
{
strACCMONTH3 = "0" + strACCMONTH3;
}
MsCwVouchersGl5.VKNO = headData.VKNO.ToString().Trim();//凭证字
//strVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
MsCwVouchersGl5.VOUNO = strVOUNO;//月初清零
MsCwVouchersGl5.ACCMONTH = strACCMONTH3;//月
string strVOUALLNO3 = MsCwVouchersGl5.VOUNO.ToString();
for (int i = 0; i < (4 - MsCwVouchersGl5.VOUNO.ToString().Length); i++)
{
strVOUALLNO3 = "0" + strVOUALLNO3;
}
strVOUALLNO3 = MsCwVouchersGl5.VKNO + MsCwVouchersGl5.ACCYEAR + MsCwVouchersGl5.ACCMONTH + strVOUALLNO3;
MsCwVouchersGl5.VOUALLNO = strVOUALLNO3;//月初清零
MsCwVouchersGl5.ATTACHS = 0;//附件(单据)数
MsCwVouchersGl5.AMTDR = 0;//本位币借方
MsCwVouchersGl5.AMTCR = 0;//本位币贷方
MsCwVouchersGl5.FCY = "";//是否含有外币科目
MsCwVouchersGl5.QTY = "";//是否含有数量科目
MsCwVouchersGl5.VOUPROP = "";//凭证属性
MsCwVouchersGl5.PREPARED = strSHOWNAME.Trim();//制单人
MsCwVouchersGl5.CHECKED = "";//审核人
MsCwVouchersGl5.ENTERED = "";//记账人
MsCwVouchersGl5.ERRMSG = "";//错误信息
MsCwVouchersGl5.ISDELETE = false;//是否废除
MsCwVouchersGl5.DELETEUSER = "";//废除操作人
//MsCwVouchersGl5.DELETETIME="";//废除时间
MsCwVouchersGl5.CarryOverType = "年末结转";//废除操作人
MsCwVouchersGl5.STARTGID = strCwSTARTGID;
MsCwVouchersGl5.ISCARRY = true;
MsCwVouchersGl5.CREATEUSER = strUserID;//创建人
MsCwVouchersGl5.CREATETIME = DateTime.Now;//创建时间
MsCwVouchersGl5.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouchersGl5.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
#region 生成入库
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 默认结转科目_入库
string sSQL = "select top 1 gid from cw_carry_accitems WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "'";// and CORPID='" + companyid + "'
string sGID = T_ALL_DA.GetStrSQL("gid", sSQL);//科目
if (sGID == "")//插入0
{
sSQL = "INSERT INTO [cw_carry_accitems]([GID],[ExchangeGains],[ExchangeLoss],[CurrentYearProfits],[UndistributedProfit],[CORPID],[MODIFIEDUSER],[MODIFIEDTIME],STARTGID) VALUES(newid(),'" + headData.ExchangeGains.ToString().Trim() + "','" + headData.ExchangeLoss.ToString().Trim() + "','" + headData.CurrentYearProfits.ToString().Trim() + "','" + headData.UndistributedProfit.ToString().Trim() + "','" + companyid + "','" + strUserID + "',GETDATE(),'" + strCwSTARTGID + "')";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
else//更新
{
sSQL = "UPDATE [cw_carry_accitems] SET [ExchangeGains] = '" + headData.ExchangeGains.ToString().Trim() + "',[ExchangeLoss] = '" + headData.ExchangeLoss.ToString().Trim() + "',[CurrentYearProfits] = '" + headData.CurrentYearProfits.ToString().Trim() + "',[UndistributedProfit] = '" + headData.UndistributedProfit.ToString().Trim() + "',[CORPID] = '" + companyid + "',[MODIFIEDUSER] = '" + strUserID + "',[MODIFIEDTIME] = GETDATE(),STARTGID='" + strCwSTARTGID + "' WHERE [GID] = '" + sGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
}
#endregion
#region 期末调汇_入库
if (CwVouitemsGlEntities3 != null)
{
if (CwVouitemsGlEntities3.Count > 0)
{
#region 插入明细表
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("insert into Cw_Vouitems_Gl(");
strSql2.Append("GID,AMTDR,AMTCR,ISFCY,FCYNO,FCYEXRATE,FCYDR,FCYCR,QTYUNIT,QTYDR,QTYCR,ORDNO,EXPLAN,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,DEPTID,EMPLID,CORPID,PITEMID,ITEMID,ITEMNO,FIELD10,FIELD9,FIELD8,FIELD7,FIELD6,FIELD5,FIELD4,FIELD3,FIELD2,FIELD1,ACCID,ISSYS,FSETTLCODE,FSETTLENO,PACCID,ACCNAME,PROPERTY,GRADE,DC,CUSTOMERNAME,SALE,BLNO,ITEMGID,DEPTGID,ACCALL,FSETTLDATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql2.Append(") values (");
strSql2.Append("newid(),@AMTDR,@AMTCR,@ISFCY,@FCYNO,@FCYEXRATE,@FCYDR,@FCYCR,@QTYUNIT,@QTYDR,@QTYCR,@ORDNO,@EXPLAN,@ISDEPTACC,@ISEMPLACC,@ISCORPACC,@ISITEMACC,@DEPTID,@EMPLID,@CORPID,@PITEMID,@ITEMID,@ITEMNO,@FIELD10,@FIELD9,@FIELD8,@FIELD7,@FIELD6,@FIELD5,@FIELD4,@FIELD3,@FIELD2,@FIELD1,@ACCID,@ISSYS,@FSETTLCODE,@FSETTLENO,@PACCID,@ACCNAME,@PROPERTY,@GRADE,@DC,@CUSTOMERNAME,@SALE,@BLNO,@ITEMGID,@DEPTGID,@ACCALL,getdate(),@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql2.Append(") ");
#region SqlParameter
SqlParameter[] parameters = new SqlParameter[]{
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ISFCY", SqlDbType.Bit,1) ,
new SqlParameter("@FCYNO", SqlDbType.VarChar,8) ,
new SqlParameter("@FCYEXRATE", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYUNIT", SqlDbType.VarChar,10) ,
new SqlParameter("@QTYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@EXPLAN", SqlDbType.VarChar,60) ,
new SqlParameter("@ISDEPTACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISEMPLACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISCORPACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISITEMACC", SqlDbType.Bit,1) ,
new SqlParameter("@DEPTID", SqlDbType.VarChar,18) ,
new SqlParameter("@EMPLID", SqlDbType.VarChar,18) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,18) ,
new SqlParameter("@PITEMID", SqlDbType.Int,4) ,
new SqlParameter("@ITEMID", SqlDbType.VarChar,50) ,
new SqlParameter("@ITEMNO", SqlDbType.Int,4) ,
new SqlParameter("@FIELD10", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD9", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD8", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD7", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD6", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD5", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD4", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD3", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD2", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD1", SqlDbType.VarChar,50) ,
new SqlParameter("@ACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ISSYS", SqlDbType.Bit,1) ,
new SqlParameter("@FSETTLCODE", SqlDbType.VarChar,20) ,
new SqlParameter("@FSETTLENO", SqlDbType.VarChar,20) ,
new SqlParameter("@PACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ACCNAME", SqlDbType.VarChar,60) ,
new SqlParameter("@PROPERTY", SqlDbType.Int,4) ,
new SqlParameter("@GRADE", SqlDbType.Int,4) ,
new SqlParameter("@DC", SqlDbType.VarChar,1),
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20),
new SqlParameter("@SALE", SqlDbType.VarChar,10),
new SqlParameter("@BLNO", SqlDbType.VarChar,30),
new SqlParameter("@ITEMGID", SqlDbType.VarChar,100),
new SqlParameter("@DEPTGID", SqlDbType.VarChar,100),
new SqlParameter("@ACCALL", SqlDbType.VarChar,500),
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
#endregion
foreach (MsCwVouitemsGl model in CwVouitemsGlEntities3)
{
#region 插入明细表参数赋值
//parameters[0].Value = model.GID;
parameters[0].Value = model.AMTDR;
parameters[1].Value = model.AMTCR;
parameters[2].Value = model.ISFCY;
parameters[3].Value = model.FCYNO;
parameters[4].Value = model.FCYEXRATE;
parameters[5].Value = model.FCYDR;
parameters[6].Value = model.FCYCR;
parameters[7].Value = model.QTYUNIT;
parameters[8].Value = model.QTYDR;
parameters[9].Value = model.QTYCR;
parameters[10].Value = model.ORDNO;
parameters[11].Value = model.EXPLAN;
parameters[12].Value = model.ISDEPTACC;
parameters[13].Value = model.ISEMPLACC;
parameters[14].Value = model.ISCORPACC;
parameters[15].Value = model.ISITEMACC;
parameters[16].Value = model.DEPTID;
parameters[17].Value = model.EMPLID;
parameters[18].Value = model.CORPID;
parameters[19].Value = model.PITEMID;
parameters[20].Value = model.ITEMID;
parameters[21].Value = model.ITEMNO;
parameters[22].Value = model.FIELD10;
parameters[23].Value = model.FIELD9;
parameters[24].Value = model.FIELD8;
parameters[25].Value = model.FIELD7;
parameters[26].Value = model.FIELD6;
parameters[27].Value = model.FIELD5;
parameters[28].Value = model.FIELD4;
parameters[29].Value = model.FIELD3;
parameters[30].Value = model.FIELD2;
parameters[31].Value = model.FIELD1;
parameters[32].Value = model.ACCID;
parameters[33].Value = model.ISSYS;
parameters[34].Value = model.FSETTLCODE;
parameters[35].Value = model.FSETTLENO;
parameters[36].Value = model.PACCID;
parameters[37].Value = model.ACCNAME;
parameters[38].Value = model.PROPERTY;
parameters[39].Value = model.GRADE;
parameters[40].Value = model.DC;
parameters[41].Value = model.CUSTOMERNAME;
parameters[42].Value = model.SALE;
parameters[43].Value = model.BLNO;
parameters[44].Value = model.ITEMGID;
parameters[45].Value = model.DEPTGID;
parameters[46].Value = model.ACCALL;
parameters[47].Value = strUserID;
parameters[48].Value = strUserID;
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), parameters);
}
#endregion
#region 插入主表
if (MsCwVouchersGl5 != null)
{
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("insert into Cw_Vouchers_Gl(");
strSql1.Append("ORDNO,FCY,QTY,VOUPROP,PREPARED,CHECKED,ENTERED,ERRMSG,ISDELETE,VOUNO,VKNO,{0}ACCYEAR,ACCMONTH,ATTACHS,AMTDR,AMTCR,VOUALLNO,CarryOverType,STARTGID,ISCARRY,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISAUTO");//,DELETEUSER,DELETETIME
strSql1.Append(") values (");
strSql1.Append("@ORDNO,@FCY,@QTY,@VOUPROP,@PREPARED,@CHECKED,@ENTERED,@ERRMSG,@ISDELETE,@VOUNO,@VKNO,{1}@ACCYEAR,@ACCMONTH,@ATTACHS,@AMTDR,@AMTCR,@VOUALLNO,@CarryOverType,'" + strCwSTARTGID + "','True',@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),1");//,@DELETEUSER,@DELETETIME
strSql1.Append(") ");
#region 插入主表参数赋值
SqlParameter[] parameters1 = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@FCY", SqlDbType.VarChar,1) ,
new SqlParameter("@QTY", SqlDbType.VarChar,1) ,
new SqlParameter("@VOUPROP", SqlDbType.VarChar,1) ,
new SqlParameter("@PREPARED", SqlDbType.VarChar,10) ,
new SqlParameter("@CHECKED", SqlDbType.VarChar,10) ,
new SqlParameter("@ENTERED", SqlDbType.VarChar,10) ,
new SqlParameter("@ERRMSG", SqlDbType.VarChar,6) ,
new SqlParameter("@ISDELETE", SqlDbType.Bit,1) ,
//new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@VOUNO", SqlDbType.VarChar,16) ,
new SqlParameter("@VKNO", SqlDbType.VarChar,8) ,
//new SqlParameter("@VOUDATE", SqlDbType.DateTime) ,
new SqlParameter("@ACCYEAR", SqlDbType.VarChar,4) ,
new SqlParameter("@ACCMONTH", SqlDbType.VarChar,2) ,
new SqlParameter("@ATTACHS", SqlDbType.Int,4) ,
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@VOUALLNO", SqlDbType.VarChar,16) ,
new SqlParameter("@CarryOverType", SqlDbType.VarChar,50),
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
#endregion
#region 插入主表参数赋值
parameters1[0].Value = MsCwVouchersGl5.ORDNO;
parameters1[1].Value = MsCwVouchersGl5.FCY;
parameters1[2].Value = MsCwVouchersGl5.QTY;
parameters1[3].Value = MsCwVouchersGl5.VOUPROP;
parameters1[4].Value = MsCwVouchersGl5.PREPARED;
parameters1[5].Value = MsCwVouchersGl5.CHECKED;
parameters1[6].Value = MsCwVouchersGl5.ENTERED;
parameters1[7].Value = MsCwVouchersGl5.ERRMSG;
parameters1[8].Value = MsCwVouchersGl5.ISDELETE;
//parameters1[9].Value = MsCwVouchersGl5.DELETEUSER;
//parameters1[10].Value = MsCwVouchersGl5.DELETETIME;
parameters1[9].Value = MsCwVouchersGl5.VOUNO;
parameters1[10].Value = MsCwVouchersGl5.VKNO;
//parameters1[11].Value = MsCwVouchersGl5.VOUDATE;
parameters1[11].Value = MsCwVouchersGl5.ACCYEAR;
parameters1[12].Value = MsCwVouchersGl5.ACCMONTH;
parameters1[13].Value = MsCwVouchersGl5.ATTACHS;
parameters1[14].Value = MsCwVouchersGl5.AMTDR;
parameters1[15].Value = MsCwVouchersGl5.AMTCR;
parameters1[16].Value = MsCwVouchersGl5.VOUALLNO;
parameters1[17].Value = MsCwVouchersGl5.CarryOverType;
parameters1[18].Value = MsCwVouchersGl5.CREATEUSER;
parameters1[19].Value = MsCwVouchersGl5.MODIFIEDUSER;
#endregion
string strVOUDATE = MsCwVouchersGl5.VOUDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + MsCwVouchersGl5.VOUDATE.ToString() + "',";
string strVOUDATE_name = strVOUDATE.Equals("") ? "" : "VOUDATE,";
string sSql1 = String.Format(strSql1.ToString(), strVOUDATE_name, strVOUDATE);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql1, parameters1);
}
#endregion
}
}
#endregion
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
}
#endregion
//
result.Success = true;
result.Message = "操作成功" + result.Message;
return result;
}
public static String getGid()
{
string strgid = Guid.NewGuid().ToString();
strgid = strgid.Replace("-", "");
strgid = "VOU" + strgid;
return strgid;
}
#endregion
#region 判断凭证是否连号
public static DBResult isSave(MsCwVouchersGl2 headData, string strUserID, string companyid)
{
#region 默认操作
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var result = new DBResult();
string sError = "";
//
DateTime rq2 = DateTime.Parse(headData.VOUDATE.ToString().Trim());
string strYEAR = rq2.Year.ToString();
string strMONTH = rq2.Month.ToString();
if (strMONTH.Length == 1)
{
strMONTH = "0" + strMONTH;
}
#endregion
#region 判断凭证是否连号
string sSQL = "select VKNO from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCYEAR='" + strYEAR + "' and ACCMONTH='" + strMONTH + "' and ISCHECKED=1 group by VKNO";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
sSQL = "select VOUNO from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=1 and ACCYEAR='" + strYEAR + "' and ACCMONTH='" + strMONTH + "' and VKNO='" + ds.Tables[0].Rows[i]["VKNO"].ToString() + "' group by VOUNO order by convert(int,VOUNO)";
DataSet ds2 = T_ALL_DA.GetAllSQL(sSQL);
if (ds2 != null)
{
if (ds2.Tables[0].Rows.Count > 0)
{
for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
{
if (ds2.Tables[0].Rows[j]["VOUNO"].ToString().Trim() != (j+1).ToString())
{
sError += "、" + ds.Tables[0].Rows[i]["VKNO"].ToString() + "字第" + ds2.Tables[0].Rows[j]["VOUNO"].ToString().Trim() + "号";
break;
}
}
}
}
}
}
}
if (sError != "")
{
sError = sError.Substring(1) + "凭证的凭证号不连续!是否继续?";
result.Success = false;
result.Message = sError;
return result;
}
else
{
result.Success = true;
result.Message = "";
return result;
}
#endregion
}
#endregion
#region 结转到下期
public static DBResult Save(MsCwVouchersGl2 headData, string strUserID, string companyid)
{
#region 默认操作
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var result = new DBResult();
//
DateTime rq2 = DateTime.Parse(headData.VOUDATE.ToString().Trim());
string strYEAR = rq2.Year.ToString();
string strMONTH = rq2.Month.ToString();
if (strMONTH.Length == 1)
{
strMONTH = "0" + strMONTH;
}
DateTime rq3 = rq2.AddMonths(1);
string strYEAR_new = rq3.Year.ToString();
string strMONTH_new = rq3.Month.ToString();
if (strMONTH_new.Length == 1)
{
strMONTH_new = "0" + strMONTH_new;
}
#endregion
#region 结转到下期sql查询超时此方法暂时屏蔽重新优化程序
//using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
//{
// try
// {
// #region 非损益类sql查询超时此方法暂时屏蔽重新优化程序
// //#region 判断下期是否有总账数据,如果有则合计金额
// //string sSQL = " select a.GID,a.[YEAR],a.[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY"
// //+ ",AMTYEARDR=isnull((SELECT (case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//RMB期初借方
// //+ ",AMTYEARCR=isnull((SELECT (case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//RMB期初贷方
// //+ ",AMTYEARBLC=isnull((SELECT AMTLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//RMB期初余额
// //+ ",AMTDR"//RMB本月借方
// //+ ",AMTCR"//RMB本月贷方
// //+ ",AMTBLC"//RMB本月余额
// //+ ",AMTLASTDR=ISNULL((AMTDR+isnull((SELECT (case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//RMB累计借方
// //+ ",AMTLASTCR=ISNULL((AMTCR+isnull((SELECT (case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//RMB累计贷方
// //+ ",AMTLASTBLC=ISNULL((AMTBLC+isnull((SELECT AMTLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//RMB累计余额
// //+ ",FCYYEARDR=isnull((SELECT (case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//外币期初借方
// //+ ",FCYYEARCR=isnull((SELECT (case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//外币期初贷方
// //+ ",FCYYEARBLC=isnull((SELECT FCYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//外币期初余额
// //+ ",FCYDR"//外币本月借方
// //+ ",FCYCR"//外币本月贷方
// //+ ",FCYBLC"//外币本月余额
// //+ ",FCYLASTDR=ISNULL((FCYDR+isnull((SELECT (case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//外币累计借方
// //+ ",FCYLASTCR=ISNULL((FCYCR+isnull((SELECT (case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//外币累计贷方
// //+ ",FCYLASTBLC=ISNULL((FCYBLC+isnull((SELECT FCYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//外币累计余额
// //+ ",QTYYEARDR=isnull((SELECT (case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//期初借方
// //+ ",QTYYEARCR=isnull((SELECT (case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//期初贷方
// //+ ",QTYYEARBLC=isnull((SELECT QTYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//期初余额
// //+ ",QTYDR"//本月借方
// //+ ",QTYCR"//本月贷方
// //+ ",QTYBLC"//本月余额
// //+ ",QTYLASTDR=ISNULL((QTYDR+isnull((SELECT (case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//累计借方
// //+ ",QTYLASTCR=ISNULL((QTYCR+isnull((SELECT (case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//累计贷方
// //+ ",QTYLASTBLC=ISNULL((QTYBLC+isnull((SELECT QTYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//累计余额
// //+ ",CORPID,ISDELETE,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,a.ISENABLE,PFADR,PFACR,a.STARTGID,ACCDATE"
// //+ " from cw_genleg_accitems as a INNER JOIN cw_accitems_gl ON a.LINKGID = cw_accitems_gl.GID"
// //+ " where a.[STARTGID]='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and cw_accitems_gl.ACCATTRIBUTE<>'损益' and cw_accitems_gl.[YEAR]='" + strYEAR + "' and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "'";// and CORPID='" + companyid + "'
// //#endregion
// //DataSet dsCwGenlegAccitems = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, sSQL, null);
// //if (dsCwGenlegAccitems != null)
// //{
// // if (dsCwGenlegAccitems.Tables[0].Rows.Count > 0)
// // {
// // //更新
// // for (int i = 0; i < dsCwGenlegAccitems.Tables[0].Rows.Count; i++)
// // {
// // #region 结转到下期_不包含损益
// // string sSQL2 = "update cw_genleg_accitems set"
// // + " AMTYEARDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTYEARDR"].ToString().Trim()//RMB期初借方
// // + ",AMTYEARCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTYEARCR"].ToString().Trim()//RMB期初贷方
// // + ",AMTYEARBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTYEARBLC"].ToString().Trim()//RMB期初余额
// // + ",AMTLASTDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTLASTDR"].ToString().Trim()//RMB累计借方
// // + ",AMTLASTCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTLASTCR"].ToString().Trim()//RMB累计贷方
// // + ",AMTLASTBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTLASTBLC"].ToString().Trim()//RMB累计余额
// // + ",FCYYEARDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYYEARDR"].ToString().Trim()//外币期初借方
// // + ",FCYYEARCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYYEARCR"].ToString().Trim()//外币期初贷方
// // + ",FCYYEARBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYYEARBLC"].ToString().Trim()//外币期初余额
// // + ",FCYLASTDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYLASTDR"].ToString().Trim()//外币累计借方
// // + ",FCYLASTCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYLASTCR"].ToString().Trim()//外币累计贷方
// // + ",FCYLASTBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYLASTBLC"].ToString().Trim()//外币累计余额
// // + ",QTYYEARDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYYEARDR"].ToString().Trim()//期初借方
// // + ",QTYYEARCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYYEARCR"].ToString().Trim()//期初贷方
// // + ",QTYYEARBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYYEARBLC"].ToString().Trim()//期初余额
// // + ",QTYLASTDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYLASTDR"].ToString().Trim()//累计借方
// // + ",QTYLASTCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYLASTCR"].ToString().Trim()//累计贷方
// // + ",QTYLASTBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYLASTBLC"].ToString().Trim()//累计余额
// // + ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
// // + " where GID='" + dsCwGenlegAccitems.Tables[0].Rows[i]["GID"].ToString().Trim() + "'";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
// // }
// // //插入
// // #region 结转到下期_不包含损益
// // string sSQL3 = "INSERT INTO cw_genleg_accitems (GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,PFADR,PFACR,STARTGID,ACCDATE)"
// // + " select newid() as GID,"//唯一编码
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,4) as [YEAR],"//年
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),6,2) as [MONTH],"//月
// // + "LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,"
// // + "(case when a.DC='借' then AMTLASTBLC ELSE 0 end) as AMTYEARDR,"//RMB期初借方
// // + "(case when a.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTYEARCR,"//RMB期初贷方
// // + "AMTLASTBLC as AMTYEARBLC,"//RMB期初余额
// // + "0 as AMTDR,"//RMB本月借方
// // + "0 as AMTCR,"//RMB本月贷方
// // + "0 as AMTBLC,"//RMB本月余额
// // + "(case when a.DC='借' then AMTLASTBLC ELSE 0 end) as AMTLASTDR,"//RMB累计借方
// // + "(case when a.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTLASTCR,"//RMB累计贷方
// // + "AMTLASTBLC as AMTLASTBLC,"//RMB累计余额
// // + "(case when a.DC='借' then FCYLASTBLC ELSE 0 end) as FCYYEARDR,"//外币期初借方
// // + "(case when a.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYYEARCR,"//外币期初贷方
// // + "FCYLASTBLC as FCYYEARBLC,"//外币期初余额
// // + "0 as FCYDR,"//外币本月借方
// // + "0 as FCYCR,"//外币本月贷方
// // + "0 as FCYBLC,"//外币本月余额
// // + "(case when a.DC='借' then FCYLASTBLC ELSE 0 end) as FCYLASTDR,"//外币累计借方
// // + "(case when a.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYLASTCR,"//外币累计贷方
// // + "FCYLASTBLC as FCYLASTBLC,"//外币累计余额
// // + "(case when a.DC='借' then QTYLASTBLC ELSE 0 end) as QTYYEARDR,"//期初借方
// // + "(case when a.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYYEARCR,"//期初贷方
// // + "QTYLASTBLC as QTYYEARBLC,"//期初余额
// // + "0 as QTYDR,"//本月借方
// // + "0 as QTYCR,"//本月贷方
// // + "0 as QTYBLC,"//本月余额
// // + "(case when a.DC='借' then QTYLASTBLC ELSE 0 end) as QTYLASTDR,"//累计借方
// // + "(case when a.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYLASTCR,"//累计贷方
// // + "QTYLASTBLC as QTYLASTBLC,"//累计余额
// // + "'" + companyid + "' as CORPID,"//分公司代码
// // + "'False' as ISDELETE,'' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'True' as ISENABLE,PFADR,PFACR,STARTGID,"//账套启用GID
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE"//会计期间
// // + " from VW_cw_genleg_accitems_gl as a where a.STARTGID='" + strCwSTARTGID + "' and [ACCYEAR]='" + strYEAR + "' and ACCDATE='" + strYEAR + "-" + strMONTH + "' and ACCATTRIBUTE<>'损益' and a.GID NOT in (SELECT b.gid from (select * from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and [ACCYEAR]='" + strYEAR + "' and ACCDATE='" + strYEAR + "-" + strMONTH + "' and ACCATTRIBUTE<>'损益') as b, (select * from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and [ACCYEAR]='" + strYEAR + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and ACCATTRIBUTE<>'损益') as c where b.STARTGID=c.STARTGID and b.LINKGID=c.LINKGID and b.DEPTACC=c.DEPTACC and b.EMPLACC=c.EMPLACC and b.CORPACC=c.CORPACC and b.ITEMACC=c.ITEMACC and b.CURRENCY=c.CURRENCY)";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL3, null);
// // }
// // else
// // {
// // //插入
// // #region 结转到下期_不包含损益
// // string sSQL2 = "INSERT INTO cw_genleg_accitems (GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,PFADR,PFACR,STARTGID,ACCDATE)"
// // + " select newid() as GID,"//唯一编码
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,4) as [YEAR],"//年
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),6,2) as [MONTH],"//月
// // + "LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,"
// // + "(case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) as AMTYEARDR,"//RMB期初借方
// // + "(case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTYEARCR,"//RMB期初贷方
// // + "AMTLASTBLC as AMTYEARBLC,"//RMB期初余额
// // + "0 as AMTDR,"//RMB本月借方
// // + "0 as AMTCR,"//RMB本月贷方
// // + "0 as AMTBLC,"//RMB本月余额
// // + "(case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) as AMTLASTDR,"//RMB累计借方
// // + "(case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTLASTCR,"//RMB累计贷方
// // + "AMTLASTBLC as AMTLASTBLC,"//RMB累计余额
// // + "(case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) as FCYYEARDR,"//外币期初借方
// // + "(case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYYEARCR,"//外币期初贷方
// // + "FCYLASTBLC as FCYYEARBLC,"//外币期初余额
// // + "0 as FCYDR,"//外币本月借方
// // + "0 as FCYCR,"//外币本月贷方
// // + "0 as FCYBLC,"//外币本月余额
// // + "(case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) as FCYLASTDR,"//外币累计借方
// // + "(case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYLASTCR,"//外币累计贷方
// // + "FCYLASTBLC as FCYLASTBLC,"//外币累计余额
// // + "(case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) as QTYYEARDR,"//期初借方
// // + "(case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYYEARCR,"//期初贷方
// // + "QTYLASTBLC as QTYYEARBLC,"//期初余额
// // + "0 as QTYDR,"//本月借方
// // + "0 as QTYCR,"//本月贷方
// // + "0 as QTYBLC,"//本月余额
// // + "(case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) as QTYLASTDR,"//累计借方
// // + "(case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYLASTCR,"//累计贷方
// // + "QTYLASTBLC as QTYLASTBLC,"//累计余额
// // + "'" + companyid + "' as CORPID,"//分公司代码
// // + "'False' as ISDELETE,'' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'True' as ISENABLE,PFADR,PFACR,cw_genleg_accitems.STARTGID,"//账套启用GID
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE"//会计期间
// // + " from cw_genleg_accitems INNER JOIN cw_accitems_gl ON cw_genleg_accitems.LINKGID = cw_accitems_gl.GID where cw_accitems_gl.[YEAR]='" + strYEAR + "' and ACCDATE='" + strYEAR + "-" + strMONTH + "' and cw_accitems_gl.ACCATTRIBUTE<>'损益' and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "' and cw_genleg_accitems.[STARTGID]='" + strCwSTARTGID + "'";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
// // }
// //}
// //else
// //{
// // //插入
// // #region 结转到下期_不包含损益
// // string sSQL2 = "INSERT INTO cw_genleg_accitems (GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,PFADR,PFACR,STARTGID,ACCDATE)"
// // + " select newid() as GID,"//唯一编码
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,4) as [YEAR],"//年
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),6,2) as [MONTH],"//月
// // + "LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,"
// // + "(case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) as AMTYEARDR,"//RMB期初借方
// // + "(case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTYEARCR,"//RMB期初贷方
// // + "AMTLASTBLC as AMTYEARBLC,"//RMB期初余额
// // + "0 as AMTDR,"//RMB本月借方
// // + "0 as AMTCR,"//RMB本月贷方
// // + "0 as AMTBLC,"//RMB本月余额
// // + "(case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) as AMTLASTDR,"//RMB累计借方
// // + "(case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTLASTCR,"//RMB累计贷方
// // + "AMTLASTBLC as AMTLASTBLC,"//RMB累计余额
// // + "(case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) as FCYYEARDR,"//外币期初借方
// // + "(case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYYEARCR,"//外币期初贷方
// // + "FCYLASTBLC as FCYYEARBLC,"//外币期初余额
// // + "0 as FCYDR,"//外币本月借方
// // + "0 as FCYCR,"//外币本月贷方
// // + "0 as FCYBLC,"//外币本月余额
// // + "(case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) as FCYLASTDR,"//外币累计借方
// // + "(case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYLASTCR,"//外币累计贷方
// // + "FCYLASTBLC as FCYLASTBLC,"//外币累计余额
// // + "(case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) as QTYYEARDR,"//期初借方
// // + "(case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYYEARCR,"//期初贷方
// // + "QTYLASTBLC as QTYYEARBLC,"//期初余额
// // + "0 as QTYDR,"//本月借方
// // + "0 as QTYCR,"//本月贷方
// // + "0 as QTYBLC,"//本月余额
// // + "(case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) as QTYLASTDR,"//累计借方
// // + "(case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYLASTCR,"//累计贷方
// // + "QTYLASTBLC as QTYLASTBLC,"//累计余额
// // + "'" + companyid + "' as CORPID,"//分公司代码
// // + "'False' as ISDELETE,'' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'True' as ISENABLE,PFADR,PFACR,cw_genleg_accitems.STARTGID,"//账套启用GID
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE"//会计期间
// // + " from cw_genleg_accitems INNER JOIN cw_accitems_gl ON cw_genleg_accitems.LINKGID = cw_accitems_gl.GID where cw_accitems_gl.[YEAR]='" + strYEAR + "' and ACCDATE='" + strYEAR + "-" + strMONTH + "' and cw_accitems_gl.ACCATTRIBUTE<>'损益' and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "' and cw_genleg_accitems.[STARTGID]='" + strCwSTARTGID + "'";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
// //}
// #endregion
// #region 损益类sql查询超时此方法暂时屏蔽重新优化程序
// //#region 判断下期是否有总账数据,如果有则合计金额
// //sSQL = " select a.GID,a.[YEAR],a.[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY"
// //+ ",AMTYEARDR=isnull((SELECT (case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//RMB期初借方
// //+ ",AMTYEARCR=isnull((SELECT (case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//RMB期初贷方
// //+ ",AMTYEARBLC=isnull((SELECT AMTLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//RMB期初余额
// //+ ",AMTDR"//RMB本月借方
// //+ ",AMTCR"//RMB本月贷方
// //+ ",AMTBLC"//RMB本月余额
// //+ ",AMTLASTDR=ISNULL((AMTDR+isnull((SELECT AMTLASTDR from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//RMB累计借方
// //+ ",AMTLASTCR=ISNULL((AMTCR+isnull((SELECT AMTLASTCR from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//RMB累计贷方
// //+ ",AMTLASTBLC=ISNULL((AMTBLC+isnull((SELECT AMTLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//RMB累计余额
// //+ ",FCYYEARDR=isnull((SELECT (case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//外币期初借方
// //+ ",FCYYEARCR=isnull((SELECT (case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//外币期初贷方
// //+ ",FCYYEARBLC=isnull((SELECT FCYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//外币期初余额
// //+ ",FCYDR"//外币本月借方
// //+ ",FCYCR"//外币本月贷方
// //+ ",FCYBLC"//外币本月余额
// //+ ",FCYLASTDR=ISNULL((FCYDR+isnull((SELECT FCYLASTDR from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//外币累计借方
// //+ ",FCYLASTCR=ISNULL((FCYCR+isnull((SELECT FCYLASTCR from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//外币累计贷方
// //+ ",FCYLASTBLC=ISNULL((FCYBLC+isnull((SELECT FCYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//外币累计余额
// //+ ",QTYYEARDR=isnull((SELECT (case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//期初借方
// //+ ",QTYYEARCR=isnull((SELECT (case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//期初贷方
// //+ ",QTYYEARBLC=isnull((SELECT QTYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)"//期初余额
// //+ ",QTYDR"//本月借方
// //+ ",QTYCR"//本月贷方
// //+ ",QTYBLC"//本月余额
// //+ ",QTYLASTDR=ISNULL((QTYDR+isnull((SELECT QTYLASTDR from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//累计借方
// //+ ",QTYLASTCR=ISNULL((QTYCR+isnull((SELECT QTYLASTCR from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//累计贷方
// //+ ",QTYLASTBLC=ISNULL((QTYBLC+isnull((SELECT QTYLASTBLC from cw_genleg_accitems where a.STARTGID=STARTGID and a.LINKGID=LINKGID and a.DEPTACC=DEPTACC and a.EMPLACC=EMPLACC and a.CORPACC=CORPACC and a.ITEMACC=ITEMACC and a.CURRENCY=CURRENCY and ACCDATE='" + strYEAR + "-" + strMONTH + "'),0)),0)"//累计余额
// //+ ",CORPID,ISDELETE,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,a.ISENABLE,PFADR,PFACR,a.STARTGID,ACCDATE"
// //+ " from cw_genleg_accitems as a INNER JOIN cw_accitems_gl ON a.LINKGID = cw_accitems_gl.GID"
// //+ " where a.[STARTGID]='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and cw_accitems_gl.ACCATTRIBUTE='损益' and cw_accitems_gl.[YEAR]='" + strYEAR + "' and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "'";// and CORPID='" + companyid + "'
// //#endregion
// //DataSet dsCwGenlegAccitems2 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, sSQL, null);
// //if (dsCwGenlegAccitems2 != null)
// //{
// // if (dsCwGenlegAccitems2.Tables[0].Rows.Count > 0)
// // {
// // //更新
// // for (int i = 0; i < dsCwGenlegAccitems2.Tables[0].Rows.Count; i++)
// // {
// // #region 结转到下期_不包含损益
// // string sSQL2 = "update cw_genleg_accitems set"
// // + " AMTYEARDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTYEARDR"].ToString().Trim()//RMB期初借方
// // + ",AMTYEARCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTYEARCR"].ToString().Trim()//RMB期初贷方
// // + ",AMTYEARBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTYEARBLC"].ToString().Trim()//RMB期初余额
// // + ",AMTLASTDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTLASTDR"].ToString().Trim()//RMB累计借方
// // + ",AMTLASTCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTLASTCR"].ToString().Trim()//RMB累计贷方
// // + ",AMTLASTBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTLASTBLC"].ToString().Trim()//RMB累计余额
// // + ",FCYYEARDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYYEARDR"].ToString().Trim()//外币期初借方
// // + ",FCYYEARCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYYEARCR"].ToString().Trim()//外币期初贷方
// // + ",FCYYEARBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYYEARBLC"].ToString().Trim()//外币期初余额
// // + ",FCYLASTDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYLASTDR"].ToString().Trim()//外币累计借方
// // + ",FCYLASTCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYLASTCR"].ToString().Trim()//外币累计贷方
// // + ",FCYLASTBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYLASTBLC"].ToString().Trim()//外币累计余额
// // + ",QTYYEARDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYYEARDR"].ToString().Trim()//期初借方
// // + ",QTYYEARCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYYEARCR"].ToString().Trim()//期初贷方
// // + ",QTYYEARBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYYEARBLC"].ToString().Trim()//期初余额
// // + ",QTYLASTDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYLASTDR"].ToString().Trim()//累计借方
// // + ",QTYLASTCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYLASTCR"].ToString().Trim()//累计贷方
// // + ",QTYLASTBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYLASTBLC"].ToString().Trim()//累计余额
// // + ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
// // + " where GID='" + dsCwGenlegAccitems2.Tables[0].Rows[i]["GID"].ToString().Trim() + "'";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
// // }
// // //插入
// // #region 结转到下期_损益
// // string sSQL3 = "INSERT INTO cw_genleg_accitems (GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,PFADR,PFACR,STARTGID,ACCDATE)"
// // + " select newid() as GID,"//唯一编码
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,4) as [YEAR],"//年
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),6,2) as [MONTH],"//月
// // + "LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,"
// // + "(case when a.DC='借' then AMTLASTBLC ELSE 0 end) as AMTYEARDR,"//RMB期初借方
// // + "(case when a.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTYEARCR,"//RMB期初贷方
// // + "AMTLASTBLC as AMTYEARBLC,"//RMB期初余额
// // + "0 as AMTDR,"//RMB本月借方
// // + "0 as AMTCR,"//RMB本月贷方
// // + "0 as AMTBLC,"//RMB本月余额
// // + "AMTLASTDR,"//RMB累计借方
// // + "AMTLASTCR,"//RMB累计贷方
// // + "AMTLASTBLC,"//RMB累计余额
// // + "(case when a.DC='借' then FCYLASTBLC ELSE 0 end) as FCYYEARDR,"//外币期初借方
// // + "(case when a.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYYEARCR,"//外币期初贷方
// // + "FCYLASTBLC as FCYYEARBLC,"//外币期初余额
// // + "0 as FCYDR,"//外币本月借方
// // + "0 as FCYCR,"//外币本月贷方
// // + "0 as FCYBLC,"//外币本月余额
// // + "FCYLASTDR,"//外币累计借方
// // + "FCYLASTCR,"//外币累计贷方
// // + "FCYLASTBLC,"//外币累计余额
// // + "(case when a.DC='借' then QTYLASTBLC ELSE 0 end) as QTYYEARDR,"//期初借方
// // + "(case when a.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYYEARCR,"//期初贷方
// // + "QTYLASTBLC as QTYYEARBLC,"//期初余额
// // + "0 as QTYDR,"//本月借方
// // + "0 as QTYCR,"//本月贷方
// // + "0 as QTYBLC,"//本月余额
// // + "QTYLASTDR,"//累计借方
// // + "QTYLASTCR,"//累计贷方
// // + "QTYLASTBLC,"//累计余额
// // + "'" + companyid + "' as CORPID,"//分公司代码
// // + "'False' as ISDELETE,'' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'True' as ISENABLE,PFADR,PFACR,STARTGID,"//账套启用GID
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE"//会计期间
// // + " from VW_cw_genleg_accitems_gl as a where a.STARTGID='" + strCwSTARTGID + "' and [ACCYEAR]=SUBSTRING('" + headData.VOUDATE + "',1,4) and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and ACCATTRIBUTE='损益' and a.GID NOT in (SELECT b.gid from (select * from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and [ACCYEAR]='" + strYEAR + "' and ACCDATE='" + strYEAR + "-" + strMONTH + "' and ACCATTRIBUTE='损益') as b, (select * from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and [ACCYEAR]='" + strYEAR + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and ACCATTRIBUTE='损益') as c where b.STARTGID=c.STARTGID and b.LINKGID=c.LINKGID and b.DEPTACC=c.DEPTACC and b.EMPLACC=c.EMPLACC and b.CORPACC=c.CORPACC and b.ITEMACC=c.ITEMACC and b.CURRENCY=c.CURRENCY)";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL3, null);
// // }
// // else
// // {
// // //插入
// // #region 结转到下期_损益
// // string sSQL2 = "INSERT INTO cw_genleg_accitems (GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,PFADR,PFACR,STARTGID,ACCDATE)"
// // + " select newid() as GID,"//唯一编码
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,4) as [YEAR],"//年
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),6,2) as [MONTH],"//月
// // + "LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,"
// // + "(case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) as AMTYEARDR,"//RMB期初借方
// // + "(case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTYEARCR,"//RMB期初贷方
// // + "AMTLASTBLC as AMTYEARBLC,"//RMB期初余额
// // + "0 as AMTDR,"//RMB本月借方
// // + "0 as AMTCR,"//RMB本月贷方
// // + "0 as AMTBLC,"//RMB本月余额
// // + "AMTLASTDR,"//RMB累计借方
// // + "AMTLASTCR,"//RMB累计贷方
// // + "AMTLASTBLC,"//RMB累计余额
// // + "(case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) as FCYYEARDR,"//外币期初借方
// // + "(case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYYEARCR,"//外币期初贷方
// // + "FCYLASTBLC as FCYYEARBLC,"//外币期初余额
// // + "0 as FCYDR,"//外币本月借方
// // + "0 as FCYCR,"//外币本月贷方
// // + "0 as FCYBLC,"//外币本月余额
// // + "FCYLASTDR,"//外币累计借方
// // + "FCYLASTCR,"//外币累计贷方
// // + "FCYLASTBLC,"//外币累计余额
// // + "(case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) as QTYYEARDR,"//期初借方
// // + "(case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYYEARCR,"//期初贷方
// // + "QTYLASTBLC as QTYYEARBLC,"//期初余额
// // + "0 as QTYDR,"//本月借方
// // + "0 as QTYCR,"//本月贷方
// // + "0 as QTYBLC,"//本月余额
// // + "QTYLASTDR,"//累计借方
// // + "QTYLASTCR,"//累计贷方
// // + "QTYLASTBLC,"//累计余额
// // + "'" + companyid + "' as CORPID,"//分公司代码
// // + "'False' as ISDELETE,'' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'True' as ISENABLE,PFADR,PFACR,cw_genleg_accitems.STARTGID,"//账套启用GID
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE"//会计期间
// // + " from cw_genleg_accitems INNER JOIN cw_accitems_gl ON cw_genleg_accitems.LINKGID = cw_accitems_gl.GID where cw_accitems_gl.[YEAR]=SUBSTRING('" + headData.VOUDATE + "',1,4) and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and cw_accitems_gl.ACCATTRIBUTE='损益' and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "' and cw_genleg_accitems.[STARTGID]='" + strCwSTARTGID + "'";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
// // }
// //}
// //else
// //{
// // //插入
// // #region 结转到下期_损益
// // string sSQL2 = "INSERT INTO cw_genleg_accitems (GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,PFADR,PFACR,STARTGID,ACCDATE)"
// // + " select newid() as GID,"//唯一编码
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,4) as [YEAR],"//年
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),6,2) as [MONTH],"//月
// // + "LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,"
// // + "(case when cw_accitems_gl.DC='借' then AMTLASTBLC ELSE 0 end) as AMTYEARDR,"//RMB期初借方
// // + "(case when cw_accitems_gl.DC='贷' then AMTLASTBLC ELSE 0 end) as AMTYEARCR,"//RMB期初贷方
// // + "AMTLASTBLC as AMTYEARBLC,"//RMB期初余额
// // + "0 as AMTDR,"//RMB本月借方
// // + "0 as AMTCR,"//RMB本月贷方
// // + "0 as AMTBLC,"//RMB本月余额
// // + "AMTLASTDR,"//RMB累计借方
// // + "AMTLASTCR,"//RMB累计贷方
// // + "AMTLASTBLC,"//RMB累计余额
// // + "(case when cw_accitems_gl.DC='借' then FCYLASTBLC ELSE 0 end) as FCYYEARDR,"//外币期初借方
// // + "(case when cw_accitems_gl.DC='贷' then FCYLASTBLC ELSE 0 end) as FCYYEARCR,"//外币期初贷方
// // + "FCYLASTBLC as FCYYEARBLC,"//外币期初余额
// // + "0 as FCYDR,"//外币本月借方
// // + "0 as FCYCR,"//外币本月贷方
// // + "0 as FCYBLC,"//外币本月余额
// // + "FCYLASTDR,"//外币累计借方
// // + "FCYLASTCR,"//外币累计贷方
// // + "FCYLASTBLC,"//外币累计余额
// // + "(case when cw_accitems_gl.DC='借' then QTYLASTBLC ELSE 0 end) as QTYYEARDR,"//期初借方
// // + "(case when cw_accitems_gl.DC='贷' then QTYLASTBLC ELSE 0 end) as QTYYEARCR,"//期初贷方
// // + "QTYLASTBLC as QTYYEARBLC,"//期初余额
// // + "0 as QTYDR,"//本月借方
// // + "0 as QTYCR,"//本月贷方
// // + "0 as QTYBLC,"//本月余额
// // + "QTYLASTDR,"//累计借方
// // + "QTYLASTCR,"//累计贷方
// // + "QTYLASTBLC,"//累计余额
// // + "'" + companyid + "' as CORPID,"//分公司代码
// // + "'False' as ISDELETE,'' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'True' as ISENABLE,PFADR,PFACR,cw_genleg_accitems.STARTGID,"//账套启用GID
// // + "SUBSTRING(convert(varchar,dateadd(month,1,(ACCDATE+'-01')),23),1,7) as ACCDATE"//会计期间
// // + " from cw_genleg_accitems INNER JOIN cw_accitems_gl ON cw_genleg_accitems.LINKGID = cw_accitems_gl.GID where cw_accitems_gl.[YEAR]=SUBSTRING('" + headData.VOUDATE + "',1,4) and ACCDATE=SUBSTRING(convert(varchar,'" + headData.VOUDATE + "',23),1,7) and cw_accitems_gl.ACCATTRIBUTE='损益' and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "' and cw_genleg_accitems.[STARTGID]='" + strCwSTARTGID + "'";
// // #endregion
// // SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
// //}
// #endregion
// #region 更新cw_carry_over语句
// string sSQL4 = "INSERT INTO [cw_carry_over]([GID],[ACCDATE],[YEAR],[MONTH],[CORPID],[MODIFIEDUSER],[MODIFIEDTIME],STARTGID) VALUES(newid(),'" + strYEAR + "-" + strMONTH + "','" + strYEAR + "','" + strMONTH + "','" + companyid + "','" + strUserID + "',GETDATE(),'" + strCwSTARTGID + "')";
// #endregion
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL4, null);
// //事务提交
// sqlTran.Commit();
// }
// catch (Exception)
// {
// sqlTran.Rollback();
// result.Success = false;
// result.Message = "操作出现错误,请重试!";
// return result;
// }
// finally
// {
// SqlHelper.CloseConnection();
// sqlTran.Dispose();
// }
//}
#endregion
#region 结转到下期重新优化后的程序选择程序嵌套的方法循环执行更新语句避免一条语句造成的sql查询超时需求编号SR2017060900002
#region 非损益类+损益类
#region 判断下期是否有总账数据,如果有则合计金额
//取当前账期数据
string sSQL1 = " UPDATE B SET B.AMTYEARDR = (CASE WHEN A.DC = '借' THEN A.AMTLASTBLC ELSE 0 END),"
+ "B.AMTYEARCR = (CASE WHEN A.DC = '贷' THEN A.AMTLASTBLC ELSE 0 END),"
+ "B.AMTYEARBLC = A.AMTLASTBLC,"
+ "B.AMTLASTDR = (CASE WHEN A.DC = '借' THEN B.AMTDR + A.AMTLASTBLC ELSE B.AMTDR END),"
+ "B.AMTLASTcR = (CASE WHEN A.DC = '贷' THEN B.AMTCR + A.AMTLASTBLC ELSE B.AMTCR END),"
+ "B.AMTLASTBLC = B.AMTBLC+A.AMTLASTBLC,"
+ "B.FCYYEARDR = (CASE WHEN A.DC = '借' THEN A.FCYLASTBLC ELSE 0 END),"
+ "B.FCYYEARCR = (CASE WHEN A.DC = '贷' THEN A.FCYLASTBLC ELSE 0 END),"
+ "B.FCYYEARBLC = A.FCYLASTBLC,"
+ "B.FCYLASTDR = (CASE WHEN A.DC = '借' THEN B.FCYDR + A.FCYLASTBLC ELSE 0 END),"
+ "B.FCYLASTcR = (CASE WHEN A.DC = '贷' THEN B.FCYCR + A.FCYLASTBLC ELSE 0 END),"
+ "B.FCYLASTBLC = B.FCYBLC+A.FCYLASTBLC,"
+ "B.QTYYEARDR = (CASE WHEN A.DC = '借' THEN A.QTYLASTBLC ELSE 0 END),"
+ "B.QTYYEARCR = (CASE WHEN A.DC = '贷' THEN A.QTYLASTBLC ELSE 0 END),"
+ "B.QTYYEARBLC = A.QTYLASTBLC,"
+ "B.QTYLASTDR = (CASE WHEN A.DC = '借' THEN B.QTYDR + A.QTYLASTBLC ELSE 0 END),"
+ "B.QTYLASTcR = (CASE WHEN A.DC = '贷' THEN B.QTYCR + A.QTYLASTBLC ELSE 0 END),"
+ "B.QTYLASTBLC = B.QTYBLC+A.QTYLASTBLC "
+ " from VW_cw_genleg_accitems_gl A,VW_cw_genleg_accitems_gl B"
+ " where a.[STARTGID]='" + strCwSTARTGID + "' and a.ACCDATE='" + strYEAR + "-" + strMONTH + "' "
+ " and B.[STARTGID]= '" + strCwSTARTGID + "' and B.ACCDATE= '" + strYEAR_new + "-" + strMONTH_new + "'"
+ " AND A.LINKGID= B.LINKGID AND A.DEPTACC= B.DEPTACC AND A.EMPLACC= B.EMPLACC AND A.CORPACC= B.CORPACC AND A.ITEMACC= B.ITEMACC AND A.CURRENCY= B.CURRENCY";// and ACCATTRIBUTE<>'损益' and CORPID='" + companyid + "'
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL1);
if (!bl)
{
result.Success = false;
result.Message = "操作出现错误,请重试!" + sSQL1;
return result;
}
string sSQL11 = " INSERT INTO cw_genleg_accitems (GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,"
+ " QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,PFADR,PFACR,STARTGID,ACCDATE)"
+ " select newid() as GID,'" + strYEAR_new + "' as [YEAR],'" + strMONTH_new + "' as [MONTH],"
+ " LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,(case when DC = '借' then AMTLASTBLC ELSE 0 end) as AMTYEARDR,(case when DC = '贷' then AMTLASTBLC ELSE 0 end) as AMTYEARCR,AMTLASTBLC as AMTYEARBLC,0 as AMTDR,0 as AMTCR,0 as AMTBLC,"
+ " (case when DC = '借' then AMTLASTBLC ELSE 0 end) as AMTLASTDR,(case when DC = '贷' then AMTLASTBLC ELSE 0 end) as AMTLASTCR,AMTLASTBLC as AMTLASTBLC,(case when DC = '借' then FCYLASTBLC ELSE 0 end) as FCYYEARDR,"
+ " (case when DC = '贷' then FCYLASTBLC ELSE 0 end) as FCYYEARCR,FCYLASTBLC as FCYYEARBLC,0 as FCYDR,0 as FCYCR,0 as FCYBLC,(case when DC = '借' then FCYLASTBLC ELSE 0 end) as FCYLASTDR,(case when DC = '贷' then FCYLASTBLC ELSE 0 end) as FCYLASTCR,"
+ " FCYLASTBLC as FCYLASTBLC,(case when DC = '借' then QTYLASTBLC ELSE 0 end) as QTYYEARDR,(case when DC = '贷' then QTYLASTBLC ELSE 0 end) as QTYYEARCR,QTYLASTBLC as QTYYEARBLC,0 as QTYDR,0 as QTYCR,0 as QTYBLC,(case when DC = '借' then QTYLASTBLC ELSE 0 end) as QTYLASTDR,"
+ " (case when DC = '贷' then QTYLASTBLC ELSE 0 end) as QTYLASTCR,QTYLASTBLC as QTYLASTBLC,'" + companyid + "' as CORPID,'False' as ISDELETE,'' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,"
+ " '" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,'True' as ISENABLE,PFADR,PFACR,STARTGID,SUBSTRING(convert(varchar, dateadd(month, 1, (ACCDATE + '-01')), 23), 1, 7) as ACCDATE"
+ " from VW_cw_genleg_accitems_gl A where [STARTGID] = '" + strCwSTARTGID + "' and ACCDATE = '" + strYEAR + "-" + strMONTH + "'"
+ " AND NOT EXISTS"
+ " (SELECT 1 FROM VW_cw_genleg_accitems_gl B WHERE B.[STARTGID] = '" + strCwSTARTGID + "' and B.ACCDATE = '" + strYEAR_new + "-" + strMONTH_new + "'"
+ " AND A.LINKGID = B.LINKGID AND A.DEPTACC = B.DEPTACC AND A.EMPLACC = B.EMPLACC AND A.CORPACC = B.CORPACC AND A.ITEMACC = B.ITEMACC AND A.CURRENCY = B.CURRENCY)";// and ACCATTRIBUTE<>'损益' and CORPID='" + companyid + "'
bl = T_ALL_DA.GetExecuteSqlCommand(sSQL11);
if (!bl)
{
result.Success = false;
result.Message = "操作出现错误,请重试!" + sSQL11;
return result;
}
//取下期账期数据
sSQL1 = " select * from vw_cw_genleg_accitems_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and ACCDATE='" + strYEAR_new + "-" + strMONTH_new + "' and [YEAR]='" + strYEAR_new + "'";// and ACCATTRIBUTE<>'损益' and CORPID='" + companyid + "'
#endregion
#endregion
#region 更新cw_carry_over语句
sSQL1 = "INSERT INTO [cw_carry_over]([GID],[ACCDATE],[YEAR],[MONTH],[CORPID],[MODIFIEDUSER],[MODIFIEDTIME],STARTGID) VALUES(newid(),'" + strYEAR + "-" + strMONTH + "','" + strYEAR + "','" + strMONTH + "','" + companyid + "','" + strUserID + "',GETDATE(),'" + strCwSTARTGID + "')";
#endregion
bool bl2 = T_ALL_DA.GetExecuteSqlCommand(sSQL1);
if (!bl2)
{
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
#endregion
#region 年末结转
if (strMONTH == "12")
{
//是否有下年科目
DBResult result1 = MsCwAccitemsGlDAL.MsCwAccitemsGlDAL.isShowCopy((int.Parse(strYEAR)+1).ToString(), strUserID);
if (result1.Message.ToString().Trim() == "0")
{
//生成下年科目
DBResult result2 = MsCwAccitemsGlDAL.MsCwAccitemsGlDAL.onCopy(companyid, strUserID);
}
#region 第一步 总账数据合计金额
int isHJJE = 0;//判断是否执行_总账数据合计金额
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 非损益类
#region 判断下期是否有总账数据,如果有则合计金额
string sSQL = "select ACCID,ACCNAME,GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY"
+ ",AMTYEARDR,AMTYEARCR,AMTYEARBLC"
+ ",AMTDR=isnull((SELECT AMTDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTCR=isnull((SELECT AMTCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTBLC=isnull((SELECT AMTBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTLASTDR=isnull((AMTYEARDR+isnull((SELECT AMTDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",AMTLASTCR=isnull((AMTYEARCR+isnull((SELECT AMTCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",AMTLASTBLC=isnull((AMTYEARBLC+isnull((SELECT AMTBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",FCYYEARDR,FCYYEARCR,FCYYEARBLC"
+ ",FCYDR=isnull((SELECT FCYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYCR=isnull((SELECT FCYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYBLC=isnull((SELECT FCYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYLASTDR=isnull((FCYYEARDR+isnull((SELECT FCYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",FCYLASTCR=isnull((FCYYEARCR+isnull((SELECT FCYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",FCYLASTBLC=isnull((FCYYEARBLC+isnull((SELECT FCYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",QTYYEARDR,QTYYEARCR,QTYYEARBLC"
+ ",QTYDR=isnull((SELECT QTYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYCR=isnull((SELECT QTYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYBLC=isnull((SELECT QTYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYLASTDR=isnull((QTYYEARDR+isnull((SELECT QTYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",QTYLASTCR=isnull((QTYYEARCR+isnull((SELECT QTYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",QTYLASTBLC=isnull((QTYYEARBLC+isnull((SELECT QTYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)),0)"
+ ",ISENABLE=isnull((SELECT ISENABLE from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",CORPID,ISDELETE,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,PFADR,PFACR,STARTGID,ACCDATE"
+ " from VW_cw_genleg_accitems_gl as a"
+ " where a.STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and ACCATTRIBUTE<>'损益' and [ACCYEAR]='" + strYEAR + "' and CORPID='" + companyid + "'"
+ " ORDER BY ACCID";
#endregion
DataSet dsCwGenlegAccitems = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, sSQL, null);
if (dsCwGenlegAccitems != null)
{
if (dsCwGenlegAccitems.Tables[0].Rows.Count > 0)
{
isHJJE = 1;
//更新
for (int i = 0; i < dsCwGenlegAccitems.Tables[0].Rows.Count; i++)
{
#region 结转到下期_不包含损益
string sSQL2 = "update cw_genleg_accitems set"
+ " AMTYEARDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTYEARDR"].ToString().Trim()//RMB期初借方
+ ",AMTYEARCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTYEARCR"].ToString().Trim()//RMB期初贷方
+ ",AMTYEARBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTYEARBLC"].ToString().Trim()//RMB期初余额
+ ",AMTDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTDR"].ToString().Trim()//RMB借方
+ ",AMTCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTCR"].ToString().Trim()//RMB贷方
+ ",AMTBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTBLC"].ToString().Trim()//RMB余额
+ ",AMTLASTDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTLASTDR"].ToString().Trim()//RMB累计借方
+ ",AMTLASTCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTLASTCR"].ToString().Trim()//RMB累计贷方
+ ",AMTLASTBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["AMTLASTBLC"].ToString().Trim()//RMB累计余额
+ ",FCYYEARDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYYEARDR"].ToString().Trim()//外币期初借方
+ ",FCYYEARCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYYEARCR"].ToString().Trim()//外币期初贷方
+ ",FCYYEARBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYYEARBLC"].ToString().Trim()//外币期初余额
+ ",FCYDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYDR"].ToString().Trim()//外币借方
+ ",FCYCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYCR"].ToString().Trim()//外币贷方
+ ",FCYBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYBLC"].ToString().Trim()//外币余额
+ ",FCYLASTDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYLASTDR"].ToString().Trim()//外币累计借方
+ ",FCYLASTCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYLASTCR"].ToString().Trim()//外币累计贷方
+ ",FCYLASTBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["FCYLASTBLC"].ToString().Trim()//外币累计余额
+ ",QTYYEARDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYYEARDR"].ToString().Trim()//期初借方
+ ",QTYYEARCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYYEARCR"].ToString().Trim()//期初贷方
+ ",QTYYEARBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYYEARBLC"].ToString().Trim()//期初余额
+ ",QTYDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYDR"].ToString().Trim()//借方
+ ",QTYCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYCR"].ToString().Trim()//贷方
+ ",QTYBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYBLC"].ToString().Trim()//余额
+ ",QTYLASTDR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYLASTDR"].ToString().Trim()//累计借方
+ ",QTYLASTCR=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYLASTCR"].ToString().Trim()//累计贷方
+ ",QTYLASTBLC=" + dsCwGenlegAccitems.Tables[0].Rows[i]["QTYLASTBLC"].ToString().Trim()//累计余额
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
+ " where GID='" + dsCwGenlegAccitems.Tables[0].Rows[i]["GID"].ToString().Trim() + "'";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
}
}
}
#endregion
#region 损益类
#region 判断下期是否有总账数据,如果有则合计金额
sSQL = "select ACCID,ACCNAME,GID,[YEAR],[MONTH],LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY"
+ ",0 as AMTYEARDR,0 as AMTYEARCR,0 as AMTYEARBLC"
+ ",AMTDR=isnull((SELECT AMTDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTCR=isnull((SELECT AMTCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTBLC=isnull((SELECT AMTBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTLASTDR=isnull((SELECT AMTDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTLASTCR=isnull((SELECT AMTCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",AMTLASTBLC=isnull((SELECT AMTBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",0 as FCYYEARDR,0 as FCYYEARCR,0 as FCYYEARBLC"
+ ",FCYDR=isnull((SELECT FCYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYCR=isnull((SELECT FCYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYBLC=isnull((SELECT FCYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYLASTDR=isnull((SELECT FCYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYLASTCR=isnull((SELECT FCYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",FCYLASTBLC=isnull((SELECT FCYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",0 as QTYYEARDR,0 as QTYYEARCR,0 as QTYYEARBLC"
+ ",QTYDR=isnull((SELECT QTYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYCR=isnull((SELECT QTYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYBLC=isnull((SELECT QTYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYLASTDR=isnull((SELECT QTYDR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYLASTCR=isnull((SELECT QTYCR from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",QTYLASTBLC=isnull((SELECT QTYBLC from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",ISENABLE=isnull((SELECT ISENABLE from VW_cw_genleg_accitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCYEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=a.ACCID AND DEPTACC=a.DEPTACC AND EMPLACC=a.EMPLACC AND CORPACC=a.CORPACC AND ITEMACC=a.ITEMACC AND CURRENCY=a.CURRENCY),0)"
+ ",CORPID,ISDELETE,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,PFADR,PFACR,STARTGID,ACCDATE"
+ " from VW_cw_genleg_accitems_gl as a"
+ " where a.STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and ACCATTRIBUTE='损益' and [ACCYEAR]='" + strYEAR + "' and CORPID='" + companyid + "'"
+ " ORDER BY ACCID";
#endregion
DataSet dsCwGenlegAccitems2 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, sSQL, null);
if (dsCwGenlegAccitems2 != null)
{
if (dsCwGenlegAccitems2.Tables[0].Rows.Count > 0)
{
isHJJE = 1;
//更新
for (int i = 0; i < dsCwGenlegAccitems2.Tables[0].Rows.Count; i++)
{
#region 结转到下期_不包含损益
string sSQL2 = "update cw_genleg_accitems set"
+ " AMTYEARDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTYEARDR"].ToString().Trim()//RMB期初借方
+ ",AMTYEARCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTYEARCR"].ToString().Trim()//RMB期初贷方
+ ",AMTYEARBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTYEARBLC"].ToString().Trim()//RMB期初余额
+ ",AMTDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTDR"].ToString().Trim()//RMB借方
+ ",AMTCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTCR"].ToString().Trim()//RMB贷方
+ ",AMTBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTBLC"].ToString().Trim()//RMB余额
+ ",AMTLASTDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTLASTDR"].ToString().Trim()//RMB累计借方
+ ",AMTLASTCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTLASTCR"].ToString().Trim()//RMB累计贷方
+ ",AMTLASTBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["AMTLASTBLC"].ToString().Trim()//RMB累计余额
+ ",FCYYEARDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYYEARDR"].ToString().Trim()//外币期初借方
+ ",FCYYEARCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYYEARCR"].ToString().Trim()//外币期初贷方
+ ",FCYYEARBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYYEARBLC"].ToString().Trim()//外币期初余额
+ ",FCYDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYDR"].ToString().Trim()//外币借方
+ ",FCYCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYCR"].ToString().Trim()//外币贷方
+ ",FCYBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYBLC"].ToString().Trim()//外币余额
+ ",FCYLASTDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYLASTDR"].ToString().Trim()//外币累计借方
+ ",FCYLASTCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYLASTCR"].ToString().Trim()//外币累计贷方
+ ",FCYLASTBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["FCYLASTBLC"].ToString().Trim()//外币累计余额
+ ",QTYYEARDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYYEARDR"].ToString().Trim()//期初借方
+ ",QTYYEARCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYYEARCR"].ToString().Trim()//期初贷方
+ ",QTYYEARBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYYEARBLC"].ToString().Trim()//期初余额
+ ",QTYDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYDR"].ToString().Trim()//借方
+ ",QTYCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYCR"].ToString().Trim()//贷方
+ ",QTYBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYBLC"].ToString().Trim()//余额
+ ",QTYLASTDR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYLASTDR"].ToString().Trim()//累计借方
+ ",QTYLASTCR=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYLASTCR"].ToString().Trim()//累计贷方
+ ",QTYLASTBLC=" + dsCwGenlegAccitems2.Tables[0].Rows[i]["QTYLASTBLC"].ToString().Trim()//累计余额
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
+ " where GID='" + dsCwGenlegAccitems2.Tables[0].Rows[i]["GID"].ToString().Trim() + "'";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
}
}
}
#endregion
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
#region 第二步 删除2016-01数据
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
if (isHJJE == 1)//如果执行_总账数据合计金额
{
#region 删除2016-01数据
string sSQL6 = "delete from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and LINKGID in (SELECT gid from cw_accitems_gl WHERE [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID in (SELECT ACCID from cw_accitems_gl WHERE [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "'))";// and CORPID='" + companyid + "'
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL6, null);
}
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
#region 第三步 把2015年有的而2016年没有的科目插入2016年科目表
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
if (isHJJE == 1)//判断是否执行_总账数据合计金额
{
#region 把原2015的科目GID装换成2016的科目GID
string sSQL4 = "INSERT INTO [cw_accitems_gl]([GID],[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS],[YEAR],[MONTH],[PACCGID],[ACCATTRIBUTE],[ISENABLE],[ACCTYPE],[STARTGID]) "
+ " SELECT NEWID() as GID,[ACCID],[ACCNAME],[DETAILED],[DC],[ISFCY],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[REMARKS],SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) as [YEAR],'01' as [MONTH],[PACCGID]=ISNULL((SELECT top 1 gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and ACCID=SUBSTRING(convert(varchar,a.ACCID,23),1,(len(a.ACCID)-2))),[PACCGID]),[ACCATTRIBUTE],0 as [ISENABLE],[ACCTYPE],[STARTGID] from cw_accitems_gl as a WHERE [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "' and ACCID NOT in (SELECT ACCID from cw_accitems_gl WHERE [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4))";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL4, null);
}
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
#region 第四步 把原2015的科目GID装换成2016的科目GID
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
if (isHJJE == 1)//如果执行_总账数据合计金额
{
#region 把原2015的科目GID装换成2016的科目GID
string sSQL4 = "update cw_genleg_accitems SET LINKGID=("
+ "select top 1 bGID from ("
+ "select a.GID as aGID,b.GID as bGID"
+ " from (select gid,ACCID from cw_accitems_gl where [year]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "' GROUP by gid,ACCID) as a"
+ " INNER JOIN "
+ "(select gid,ACCID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and [year]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) GROUP by gid,ACCID) as b "
+ " on a.ACCID=b.ACCID "
+ ") as c "
+ " where c.aGID=cw_genleg_accitems.LINKGID"
+ ")"
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
+ " where ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and LINKGID in (SELECT gid from cw_accitems_gl WHERE [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "')";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL4, null);
}
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
#region 第五步 期初处理
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 把2016的科目GID总账设为期初
string sSQL5 = "UPDATE cw_genleg_accitems set IsInitialEntry=1"
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
+ " WHERE [STARTGID]='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and LINKGID in (select gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and year=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4)) and (QTYYEARDR<>0 or QTYYEARCR<>0 or QTYYEARBLC<>0)";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL5, null);
#region 判断是否有新一年的凭证数据有则期初启用为1否则为0
int iNum = 0;
#region 判断是否有新一年的凭证数据有则期初启用为1否则为0
/*
sSQL5 = "select count(*) as inum from VW_cw_vouchers_vouitems_gl WHERE STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and [ACCGID] in (select gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and year=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4))";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL5, null);
if (statusObj != null)
{
if (statusObj.ToString().Trim() != "")
{
iNum = int.Parse(statusObj.ToString().Trim());
if (iNum > 0)//判断是否有新一年的凭证数据有则期初启用为1否则为0
{
iNum = 1;
}
}
}
//
if (iNum == 1)
{
#region 如果启用,则需补充其他未入账科目
sSQL5 = "insert into cw_genleg_accitems(GID,YEAR,MONTH,LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,STARTGID,ACCDATE,IsInitialEntry) "
+ "(select newid() as GID, SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) as [YEAR],'01' as [MONTH],GID as LINKGID,'' as DEPTACC,'' as EMPLACC,'' as CORPACC,'' as ITEMACC,'RMB' as CURRENCY,0 as AMTYEARDR,0 as AMTYEARCR,0 as AMTYEARBLC,0 as AMTDR,0 as AMTCR,0 as AMTBLC,0 as AMTLASTDR,0 as AMTLASTCR,0 as AMTLASTBLC,0 as FCYYEARDR,0 as FCYYEARCR,0 as FCYYEARBLC,0 as FCYDR,0 as FCYCR,0 as FCYBLC,0 as FCYLASTDR,0 as FCYLASTCR,0 as FCYLASTBLC,0 as QTYYEARDR,0 as QTYYEARCR,0 as QTYYEARBLC,0 as QTYDR,0 as QTYCR,0 as QTYBLC,0 as QTYLASTDR,0 as QTYLASTCR,0 as QTYLASTBLC,'" + companyid + "' as CORPID,0 as ISDELETE,'" + strUserID + "' as DELETEUSER,getdate() as DELETETIME,'" + strUserID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUserID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,1 as ISENABLE,'',(SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4)+'-01'),0 from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) and gid not in (select LINKGID from cw_genleg_accitems where [YEAR]<=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4)))";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL5, null);
}
*/
#endregion
//
sSQL5 = "UPDATE cw_genleg_accitems set ISENABLE=" + iNum + ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE() WHERE [STARTGID]='" + strCwSTARTGID + "' and LINKGID in (select gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and year=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4))";//ACCDATE=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,7) and
string sSQL51 = "UPDATE cw_accitems_gl set ISENABLE=" + iNum + " WHERE [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4)";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL5, null);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL51, null);
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
#endregion
#region 第六步 更新资产负债表模板
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
string sSQL7 = "select count(*) as inum from cw_sofp_template_detail WHERE [LINKGID] in (select gid from cw_sofp_template where [STARTGID]='" + strCwSTARTGID + "') and [ACCGID] in (select gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and year=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4))";
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL7));
if (inum == 0)
{
RptCwSofpDAL.RptCwSofpDAL.isSaveRow("formRptCwSofpIndex", strCwACCDATE, strCwSTARTGID, strUserID, companyid);
}
#endregion
#region 第七步 更新利润表模板
string sSQL8 = "select count(*) as inum from cw_pl_template_detail WHERE [LINKGID] in (select gid from cw_pl_template where [STARTGID]='" + strCwSTARTGID + "') and [ACCGID] in (select gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and year=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4))";
inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL8));
if (inum == 0)
{
RptCwPLDAL.RptCwPLDAL.isSaveRow("formRptCwPLIndex", strCwACCDATE, strCwSTARTGID, strUserID, companyid);
}
#endregion
#region 第八步 更新cw_accitems_currency模板
string sSQL9 = "select count(*) as inum from cw_accitems_currency WHERE [LINKGID] in (select gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and year=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4))";
inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL9));
if (inum == 0)
{
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 把2015的科目GID替换为2016的科目GID
sSQL9 = "INSERT INTO [cw_accitems_currency]([GID],[LINKGID],[CURRENCY],[CORPID],[CREATEUSER],[CREATETIME])"
+ " SELECT TOP 1 NEWID() as GID"
+ ",[LINKGID]="
+ "("
+ "select top 1 bGID from ("
+ " select a.GID as aGID,b.GID as bGID"
+ " from (select gid,ACCID from cw_accitems_gl where [year]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "' GROUP by gid,ACCID) as a"
+ " ,(select gid,ACCID from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and [year]=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4) GROUP by gid,ACCID) as b"
+ " where a.ACCID=b.ACCID"
+ ") as c "
+ " where c.aGID=[cw_accitems_currency].LINKGID"
+ ")"
+ ",[CURRENCY],[CORPID],[CREATEUSER],GETDATE() as [CREATETIME]"
+ " from [cw_accitems_currency]"
+ " where [LINKGID] in (select gid from cw_accitems_gl where [year]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "') ORDER BY CREATETIME DESC ";
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL9, null);
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
}
#endregion
#region 第九步 更新cw_currency_rate模板
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_currency where CODENAME<>'RMB'");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
MsCwCurrencyRateDAL.MsCwCurrencyRateDAL.isSaveRow(ds.Tables[0].Rows[i]["CODENAME"].ToString(), strUserID, companyid);
}
}
}
#endregion
#region 第十步 更新现金流量表模板
string sSQL10 = "select count(*) as inum from cw_cfs_template_detail WHERE LINKGID in (select gid from cw_cfs_template where [STARTGID]='" + strCwSTARTGID + "') and [ACCGID] in (select gid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and year=SUBSTRING(convert(varchar,dateadd(month,1,('" + rq2 + "')),23),1,4))";
inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL10));
if (inum == 0)
{
DataSet dsCCM = T_ALL_DA.GetAllSQL("select GID from [cw_cfs_model] where STARTGID='" + strCwSTARTGID + "'");
if (dsCCM != null)
{
if (dsCCM.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsCCM.Tables[0].Rows.Count; i++)
{
RptCwCfsDAL.RptCwCfsDAL.isSaveRow(dsCCM.Tables[0].Rows[i]["GID"].ToString(), strCwACCDATE, strUserID, companyid);
}
}
}
}
#endregion
}
#endregion
result.Success = true;
result.Message = "操作成功" + result.Message;
return result;
}
#endregion
#region 返结转到上期
public static DBResult SaveReturn(string strUserID, string companyid)
{
#region 默认操作
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var result = new DBResult();
//
DateTime rq1 = DateTime.Parse(strCwACCDATE.Trim() + "-01");
DateTime rq2 = rq1.AddMonths(-1);
string strYEAR = rq2.Year.ToString();
string strMONTH = rq2.Month.ToString();
if (strMONTH.Length == 1)
{
strMONTH = "0" + strMONTH;
}
#endregion
#region 返结转到上期
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string sSQL2 = "delete from [cw_carry_over] where ACCDATE='" + strYEAR + "-" + strMONTH + "' and STARTGID='" + strCwSTARTGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
//事务提交
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "操作出现错误,请重试!";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
//
result.Success = true;
result.Message = "操作成功" + result.Message;
return result;
#endregion
}
#endregion
}
}