|
|
using System;
|
|
|
using System.IO;
|
|
|
using System.Data;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using DSWeb.MvcShipping.Models.MsCwVouchersGl;
|
|
|
using DSWeb.MvcShipping.Models.MsCwVouitemsGl;
|
|
|
using DSWeb.MvcShipping.Models.MsCwGenlegAccitems;
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
using DSWeb.EntityDA;
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
using HcUtility.Comm;
|
|
|
using System.Data.SqlClient;
|
|
|
using DSWeb.DataAccess;
|
|
|
using HcUtility.Core;
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
using Kingdee.BOS.WebApi.Client;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using Newtonsoft.Json;
|
|
|
using DSWeb.Areas.SysMng.DAL.SysUser;
|
|
|
using DSWeb.SoftMng.DBUtility;
|
|
|
using SocialExplorer.IO.FastDBF;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlDAL
|
|
|
{
|
|
|
public class MsCwVouchersGlDAL
|
|
|
{
|
|
|
#region 查询主表
|
|
|
static public List<MsCwVouchersVouitemsGl> GetDataListHJ(int start, int limit, string strCondition, string userid, string usercode, string companyid,string strCwSTARTGID, string sort = null)
|
|
|
{
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//strSql.Append(" order by convert(int,VOUNO) desc,VOUDATE desc");
|
|
|
strSql.Append(" order by VOUALLNO desc,VOUDATE desc");
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append(@") as num , ");
|
|
|
|
|
|
strSql.Append("ORDNO,VOUALLNO,VOUNO,VKNO,VOUDATE,ACCYEAR,ACCMONTH,ATTACHS,ACCDATE,PREPARED,ISCHECKED,CHECKED,ENTERED,ISEXPORT,SUM(case when FCYNO='RMB' THEN AMTDR ELSE 0 END) as AMTDR,SUM(case when FCYNO='RMB' THEN AMTCR ELSE 0 END) as AMTCR,SUM(FCYDR) as FCYDR,SUM(FCYCR) as FCYCR,SUM(AMTDR) as QTYDR,SUM(AMTCR) as QTYCR,CREATEUSER,CREATETIME,CREATEUSERNAME,MODIFIEDUSER,MODIFIEDTIME,MODIFIEDUSERNAME,ISCOPY,ISAUTO from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
strSql.Append(" GROUP BY ORDNO,VOUALLNO,VOUNO,VKNO,VOUDATE,ACCYEAR,ACCMONTH,ATTACHS,ACCDATE,PREPARED,ISCHECKED,CHECKED,ENTERED,ISEXPORT,CREATEUSER,CREATETIME,CREATEUSERNAME,MODIFIEDUSER,MODIFIEDTIME,MODIFIEDUSERNAME,ISCOPY,ISAUTO");
|
|
|
//
|
|
|
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>={0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
|
|
|
return SetDataHJ(strSql);
|
|
|
}
|
|
|
|
|
|
public static int getHJTotalCount(string strCondition, string strCwSTARTGID, string userid, string usercode, string orgcode)
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT COUNT(*) FROM (SELECT ORDNO,VOUALLNO,VOUNO,VKNO,VOUDATE,ACCYEAR,ACCMONTH,ATTACHS,ACCDATE,PREPARED,ISCHECKED,CHECKED,ENTERED,ISEXPORT,SUM(case when FCYNO='RMB' THEN AMTDR ELSE 0 END) as AMTDR,SUM(case when FCYNO='RMB' THEN AMTCR ELSE 0 END) as AMTCR,SUM(FCYDR) as FCYDR,SUM(FCYCR) as FCYCR,SUM(AMTDR) as QTYDR,SUM(AMTCR) as QTYCR,CREATEUSER,CREATETIME,CREATEUSERNAME,MODIFIEDUSER,MODIFIEDTIME,MODIFIEDUSERNAME,ISCOPY,ISAUTO from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) ");// and CORPID='" + companyid + "'
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
strSql.Append(" GROUP BY ORDNO,VOUALLNO,VOUNO,VKNO,VOUDATE,ACCYEAR,ACCMONTH,ATTACHS,ACCDATE,PREPARED,ISCHECKED,CHECKED,ENTERED,ISEXPORT,CREATEUSER,CREATETIME,CREATEUSERNAME,MODIFIEDUSER,MODIFIEDTIME,MODIFIEDUSERNAME,ISCOPY,ISAUTO) AS V ");
|
|
|
|
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
cnt = Convert.ToInt32(reader[0]);
|
|
|
}
|
|
|
}
|
|
|
return cnt;
|
|
|
}
|
|
|
|
|
|
|
|
|
private static List<MsCwVouchersVouitemsGl> SetDataHJ(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<MsCwVouchersVouitemsGl>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
MsCwVouchersVouitemsGl data = new MsCwVouchersVouitemsGl();
|
|
|
#region Set DB data to Object
|
|
|
data.ORDNO = (reader["ORDNO"] == null ? "" : Convert.ToString(reader["ORDNO"]));//唯一编码 newid()
|
|
|
data.VOUALLNO = (reader["VOUALLNO"] == null ? "" : Convert.ToString(reader["VOUALLNO"]));//年+月+自动生成编号=凭证号
|
|
|
data.VOUNO = (reader["VOUNO"] == null ? 0 : Convert.ToInt32(reader["VOUNO"]));//月初清零
|
|
|
data.VKNO = (reader["VKNO"] == null ? "" : Convert.ToString(reader["VKNO"]));//凭证字
|
|
|
if (reader["VOUDATE"] != null && reader["VOUDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["VOUDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["VOUDATE"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.VOUDATE = reader["VOUDATE"].ToString().Trim();//凭证日期
|
|
|
}
|
|
|
data.ACCYEAR = (reader["ACCYEAR"] == null ? "" : Convert.ToString(reader["ACCYEAR"]));//年
|
|
|
data.ACCMONTH = (reader["ACCMONTH"] == null ? "" : Convert.ToString(reader["ACCMONTH"]));//月
|
|
|
data.ATTACHS = (reader["ATTACHS"] == null ? 0 : Convert.ToInt32(reader["ATTACHS"]));//附件(单据)数
|
|
|
data.ACCDATE = (reader["ACCDATE"] == null ? "" : Convert.ToString(reader["ACCDATE"]));//月
|
|
|
data.PREPARED = (reader["PREPARED"] == null ? "" : Convert.ToString(reader["PREPARED"]));//制单人
|
|
|
data.ISCHECKED = (reader["ISCHECKED"] == null ? false : Convert.ToBoolean(reader["ISCHECKED"]));//是否审核
|
|
|
data.CHECKED = (reader["CHECKED"] == null ? "" : Convert.ToString(reader["CHECKED"]));//审核人
|
|
|
data.ENTERED = (reader["ENTERED"] == null ? "" : Convert.ToString(reader["ENTERED"]));//记账人
|
|
|
data.ISEXPORT = (reader["ISEXPORT"] == null ? false : Convert.ToBoolean(reader["ISEXPORT"]));//是否导出凭证
|
|
|
data.AMTDR = (reader["AMTDR"] == null ? 0 : Convert.ToDecimal(reader["AMTDR"]));//本位币借方
|
|
|
data.AMTCR = (reader["AMTCR"] == null ? 0 : Convert.ToDecimal(reader["AMTCR"]));//本位币贷方
|
|
|
data.FCYDR = (reader["FCYDR"] == null ? 0 : Convert.ToDecimal(reader["FCYDR"]));//外币借方
|
|
|
data.FCYCR = (reader["FCYCR"] == null ? 0 : Convert.ToDecimal(reader["FCYCR"]));//外币贷方
|
|
|
data.QTYDR = (reader["QTYDR"] == null ? 0 : Convert.ToDecimal(reader["QTYDR"]));//综合本位币借方
|
|
|
data.QTYCR = (reader["QTYCR"] == null ? 0 : Convert.ToDecimal(reader["QTYCR"]));//综合本位币贷方
|
|
|
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人
|
|
|
data.CREATEUSERNAME = (reader["CREATEUSERNAME"] == null ? "" : Convert.ToString(reader["CREATEUSERNAME"]));//创建人
|
|
|
if (reader["CREATETIME"] != null && reader["CREATETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["CREATETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["CREATETIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
|
|
|
}
|
|
|
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//最后一次更新操作人
|
|
|
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//最后一次更新操作人
|
|
|
if (reader["MODIFIEDTIME"] != null && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["MODIFIEDTIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更新操作时间
|
|
|
}
|
|
|
if (reader["ISCOPY"] != DBNull.Value)
|
|
|
data.ISCOPY = Convert.ToBoolean(reader["ISCOPY"]);
|
|
|
data.ISAUTOSTR = "手工";
|
|
|
if (reader["ISAUTO"] != DBNull.Value)
|
|
|
{
|
|
|
data.ISAUTO = Convert.ToBoolean(reader["ISAUTO"]);
|
|
|
if (data.ISAUTO) data.ISAUTOSTR = "自动";
|
|
|
}
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
static public MsCwVouchersGl GetData(string condition, string companyid, string userid)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT *,ISNULL((SELECT TOP (1) SHOWNAME FROM [user] WITH(NOLOCK) WHERE (GID = Cw_Vouchers_Gl.CHECKED)), '未审核') AS CHECKEDNAME,(select top 1 SHOWNAME from [user] where GID=Cw_Vouchers_Gl.CREATEUSER) as CREATEUSERNAME,(select top 1 SHOWNAME from [user] where GID=Cw_Vouchers_Gl.MODIFIEDUSER) as MODIFIEDUSERNAME from Cw_Vouchers_Gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
|
{
|
|
|
strSql.Append(" and " + condition);
|
|
|
}
|
|
|
var list=SetData(strSql);
|
|
|
if (list.Count > 0)
|
|
|
return list[0];
|
|
|
return new MsCwVouchersGl();
|
|
|
}
|
|
|
|
|
|
private static List<MsCwVouchersGl> SetData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<MsCwVouchersGl>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
MsCwVouchersGl data = new MsCwVouchersGl();
|
|
|
#region Set DB data to Object
|
|
|
data.ORDNO = (reader["ORDNO"] == null ? "" : Convert.ToString(reader["ORDNO"]));//唯一编码 newid()
|
|
|
data.VOUNO = (reader["VOUNO"] == null ? "" : Convert.ToString(reader["VOUNO"]));//月初清零
|
|
|
data.VKNO = (reader["VKNO"] == null ? "" : Convert.ToString(reader["VKNO"]));//凭证字
|
|
|
if (reader["VOUDATE"] != null && reader["VOUDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["VOUDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["VOUDATE"].ToString().Trim() != "")
|
|
|
{
|
|
|
//data.VOUDATE = Convert.ToDateTime(reader["VOUDATE"]);//凭证日期
|
|
|
data.VOUDATE = DateTime.Parse(reader["VOUDATE"].ToString()).ToString("yyyy-MM-dd").Trim();//凭证日期
|
|
|
}
|
|
|
data.ACCYEAR = (reader["ACCYEAR"] == null ? "" : Convert.ToString(reader["ACCYEAR"]));//年
|
|
|
data.ACCMONTH = (reader["ACCMONTH"] == null ? "" : Convert.ToString(reader["ACCMONTH"]));//月
|
|
|
data.ATTACHS = (reader["ATTACHS"] == null ? 0 : Convert.ToInt32(reader["ATTACHS"]));//附件(单据)数
|
|
|
data.AMTDR = (reader["AMTDR"] == null ? 0 : Convert.ToDecimal(reader["AMTDR"]));//本位币借方
|
|
|
data.AMTCR = (reader["AMTCR"] == null ? 0 : Convert.ToDecimal(reader["AMTCR"]));//本位币贷方
|
|
|
data.FCY = (reader["FCY"] == null ? "" : Convert.ToString(reader["FCY"]));//是否含有外币科目
|
|
|
data.QTY = (reader["QTY"] == null ? "" : Convert.ToString(reader["QTY"]));//是否含有数量科目
|
|
|
data.VOUPROP = (reader["VOUPROP"] == null ? "" : Convert.ToString(reader["VOUPROP"]));//凭证属性
|
|
|
data.PREPARED = (reader["PREPARED"] == null ? "" : Convert.ToString(reader["PREPARED"]));//制单人
|
|
|
data.CHECKED = (reader["CHECKED"] == null ? "" : Convert.ToString(reader["CHECKED"]));//审核人
|
|
|
data.ENTERED = (reader["ENTERED"] == null ? "" : Convert.ToString(reader["ENTERED"]));//记账人
|
|
|
data.ERRMSG = (reader["ERRMSG"] == null ? "" : Convert.ToString(reader["ERRMSG"]));//错误信息
|
|
|
data.ISDELETE = (reader["ISDELETE"] == null ? false : Convert.ToBoolean(reader["ISDELETE"]));//是否废除
|
|
|
data.DELETEUSER = (reader["DELETEUSER"] == null ? "" : Convert.ToString(reader["DELETEUSER"]));//废除操作人
|
|
|
if (reader["DELETETIME"] != null && reader["DELETETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["DELETETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["DELETETIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.DELETETIME = Convert.ToDateTime(reader["DELETETIME"]);//废除时间
|
|
|
}
|
|
|
data.VOUALLNO = (reader["VOUALLNO"] == null ? "" : Convert.ToString(reader["VOUALLNO"]));//年+月+自动生成编号=凭证号
|
|
|
data.ISEXPORT = (reader["ISEXPORT"] == null ? false : Convert.ToBoolean(reader["ISEXPORT"]));//是否导出凭证
|
|
|
data.ISCHECKED = (reader["ISCHECKED"] == null ? false : Convert.ToBoolean(reader["ISCHECKED"]));//是否审核
|
|
|
if (reader["CHECKEDTIME"] != null && reader["CHECKEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["CHECKEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["CHECKEDTIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.CHECKEDTIME = Convert.ToDateTime(reader["CHECKEDTIME"]);//审核时间
|
|
|
}
|
|
|
data.CHECKEDNAME = (reader["CHECKEDNAME"] == null ? "" : Convert.ToString(reader["CHECKEDNAME"]));//审核人
|
|
|
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人
|
|
|
data.CREATEUSERNAME = (reader["CREATEUSERNAME"] == null ? "" : Convert.ToString(reader["CREATEUSERNAME"]));//创建人
|
|
|
if (reader["CREATETIME"] != null && reader["CREATETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["CREATETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["CREATETIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
|
|
|
}
|
|
|
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//最后一次更新操作人
|
|
|
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//最后一次更新操作人
|
|
|
if (reader["MODIFIEDTIME"] != null && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["MODIFIEDTIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更新操作时间
|
|
|
}
|
|
|
if (reader["ISCOPY"] != DBNull.Value)
|
|
|
data.ISCOPY = Convert.ToBoolean(reader["ISCOPY"]);
|
|
|
data.ISAUTOSTR = "手工";
|
|
|
if (reader["ISAUTO"] != DBNull.Value)
|
|
|
{
|
|
|
data.ISAUTO = Convert.ToBoolean(reader["ISAUTO"]);
|
|
|
if (data.ISAUTO) data.ISAUTOSTR = "自动";
|
|
|
}
|
|
|
|
|
|
data.COPYORDNO = Convert.ToString(reader["COPYORDNO"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
static public List<MsCwVouchersVouitemsGl> GetDataCwVVList(int start, int limit, string strCondition, string userid, string usercode, string companyid,string strCwSTARTGID, string sort = null)
|
|
|
{
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//strSql.Append(" order by convert(int,VOUNO) desc,VOUDATE desc,ITEMNO");
|
|
|
strSql.Append(" order by VOUALLNO desc,VOUDATE desc,ITEMNO");
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append(@") as num , ");
|
|
|
|
|
|
strSql.Append("* from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>={0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
//
|
|
|
|
|
|
return SetDataCwVV(strSql);
|
|
|
}
|
|
|
public static int getTotalCount(string strCondition, string strCwSTARTGID, string userid, string usercode, string orgcode)
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT count(*) from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
cnt = Convert.ToInt32(reader[0]);
|
|
|
}
|
|
|
}
|
|
|
return cnt;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public MsCwVouchersVouitemsGl GetDataVW(string condition, string companyid, string userid)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT * from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
|
{
|
|
|
strSql.Append(" and " + condition);
|
|
|
}
|
|
|
var list = SetDataCwVV(strSql);
|
|
|
if (list.Count > 0)
|
|
|
return list[0];
|
|
|
return new MsCwVouchersVouitemsGl();
|
|
|
}
|
|
|
|
|
|
private static List<MsCwVouchersVouitemsGl> SetDataCwVV(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<MsCwVouchersVouitemsGl>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
MsCwVouchersVouitemsGl data = new MsCwVouchersVouitemsGl();
|
|
|
#region Set DB data to Object
|
|
|
data.ORDNO = (reader["ORDNO"] == null ? "" : Convert.ToString(reader["ORDNO"]));//唯一编码 newid()
|
|
|
data.VOUNO = (reader["VOUNO"] == null ? 0 : Convert.ToInt32(reader["VOUNO"]));//月初清零
|
|
|
data.VKNO = (reader["VKNO"] == null ? "" : Convert.ToString(reader["VKNO"]));//凭证字
|
|
|
if (reader["VOUDATE"] != null && reader["VOUDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["VOUDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["VOUDATE"].ToString().Trim() != "")
|
|
|
{
|
|
|
//data.VOUDATE = Convert.ToDateTime(reader["VOUDATE"]);//凭证日期
|
|
|
data.VOUDATE = reader["VOUDATE"].ToString().Trim();//凭证日期
|
|
|
}
|
|
|
data.ACCYEAR = (reader["ACCYEAR"] == null ? "" : Convert.ToString(reader["ACCYEAR"]));//年
|
|
|
data.ACCMONTH = (reader["ACCMONTH"] == null ? "" : Convert.ToString(reader["ACCMONTH"]));//月
|
|
|
data.ATTACHS = (reader["ATTACHS"] == null ? 0 : Convert.ToInt32(reader["ATTACHS"]));//附件(单据)数
|
|
|
//data.AMTDR = (reader["AMTDR"] == null ? 0 : Convert.ToDecimal(reader["AMTDR"]));//本位币借方
|
|
|
//data.AMTCR = (reader["AMTCR"] == null ? 0 : Convert.ToDecimal(reader["AMTCR"]));//本位币贷方
|
|
|
data.FCY = (reader["FCY"] == null ? "" : Convert.ToString(reader["FCY"]));//是否含有外币科目
|
|
|
data.QTY = (reader["QTY"] == null ? "" : Convert.ToString(reader["QTY"]));//是否含有数量科目
|
|
|
data.VOUPROP = (reader["VOUPROP"] == null ? "" : Convert.ToString(reader["VOUPROP"]));//凭证属性
|
|
|
data.PREPARED = (reader["PREPARED"] == null ? "" : Convert.ToString(reader["PREPARED"]));//制单人
|
|
|
data.CHECKED = (reader["CHECKED"] == null ? "" : Convert.ToString(reader["CHECKED"]));//审核人
|
|
|
data.ENTERED = (reader["ENTERED"] == null ? "" : Convert.ToString(reader["ENTERED"]));//记账人
|
|
|
data.ERRMSG = (reader["ERRMSG"] == null ? "" : Convert.ToString(reader["ERRMSG"]));//错误信息
|
|
|
data.ISDELETE = (reader["ISDELETE"] == null ? false : Convert.ToBoolean(reader["ISDELETE"]));//是否废除
|
|
|
data.DELETEUSER = (reader["DELETEUSER"] == null ? "" : Convert.ToString(reader["DELETEUSER"]));//废除操作人
|
|
|
if (reader["DELETETIME"] != null && reader["DELETETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["DELETETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["DELETETIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.DELETETIME = Convert.ToDateTime(reader["DELETETIME"]);//废除时间
|
|
|
}
|
|
|
data.VOUALLNO = (reader["VOUALLNO"] == null ? "" : Convert.ToString(reader["VOUALLNO"]));//年+月+自动生成编号=凭证号
|
|
|
data.ISEXPORT = (reader["ISEXPORT"] == null ? false : Convert.ToBoolean(reader["ISEXPORT"]));//是否导出凭证
|
|
|
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码 newid()
|
|
|
data.ORDNO = (reader["ORDNO"] == null ? "" : Convert.ToString(reader["ORDNO"]));
|
|
|
data.ITEMNO = (reader["ITEMNO"] == null ? 0 : Convert.ToInt32(reader["ITEMNO"]));//行号
|
|
|
data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]));//科目代码
|
|
|
data.PACCID = (reader["PACCID"] == null ? "" : Convert.ToString(reader["PACCID"]));//父级科目代码
|
|
|
data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]));//科目名称
|
|
|
data.PROPERTY = (reader["PROPERTY"] == null ? 0 : Convert.ToInt32(reader["PROPERTY"]));//科目属性
|
|
|
data.GRADE = (reader["GRADE"] == null ? 0 : Convert.ToInt32(reader["GRADE"]));//科目级别
|
|
|
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]));//借贷方向
|
|
|
data.AMTDR = (reader["AMTDR"] == null ? 0 : Convert.ToDecimal(reader["AMTDR"]));//本位币借方金额(互斥)
|
|
|
data.AMTCR = (reader["AMTCR"] == null ? 0 : Convert.ToDecimal(reader["AMTCR"]));//本位币贷方金额(互斥)
|
|
|
data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否外币
|
|
|
data.FCYNO = (reader["FCYNO"] == null ? "" : Convert.ToString(reader["FCYNO"]));//外币编号usd
|
|
|
data.FCYEXRATE = (reader["FCYEXRATE"] == null ? 0 : Convert.ToDecimal(reader["FCYEXRATE"]));//汇率
|
|
|
data.FCYDR = (reader["FCYDR"] == null ? 0 : Convert.ToDecimal(reader["FCYDR"]));//外币借方金额
|
|
|
data.FCYCR = (reader["FCYCR"] == null ? 0 : Convert.ToDecimal(reader["FCYCR"]));//外币贷方金额
|
|
|
data.QTYUNIT = (reader["QTYUNIT"] == null ? "" : Convert.ToString(reader["QTYUNIT"]));//数量包装单位
|
|
|
data.QTYDR = (reader["QTYDR"] == null ? 0 : Convert.ToDecimal(reader["QTYDR"]));//借方数量
|
|
|
data.QTYCR = (reader["QTYCR"] == null ? 0 : Convert.ToDecimal(reader["QTYCR"]));//贷方数量
|
|
|
data.EXPLAN = (reader["EXPLAN"] == null ? "" : Convert.ToString(reader["EXPLAN"]));//摘要,规则生成
|
|
|
data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//核算部门,按规则设置生成
|
|
|
data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//核算人员,按规则设置生成
|
|
|
data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//核算客户,按规则设置生成
|
|
|
data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//核算项目,按规则设置生成
|
|
|
data.DEPTID = (reader["DEPTID"] == null ? "" : Convert.ToString(reader["DEPTID"]));//部门(系统)
|
|
|
data.EMPLID = (reader["EMPLID"] == null ? "" : Convert.ToString(reader["EMPLID"]));//人员(系统)
|
|
|
data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//客户(系统)
|
|
|
data.PITEMID = (reader["PITEMID"] == null ? 0 : Convert.ToInt32(reader["PITEMID"]));//父级项目编号
|
|
|
data.ITEMID = (reader["ITEMID"] == null ? "" : Convert.ToString(reader["ITEMID"]));//项目编号
|
|
|
data.FIELD1 = (reader["FIELD1"] == null ? "" : Convert.ToString(reader["FIELD1"]));//预留字段1
|
|
|
data.FIELD2 = (reader["FIELD2"] == null ? "" : Convert.ToString(reader["FIELD2"]));//预留字段2
|
|
|
data.FIELD3 = (reader["FIELD3"] == null ? "" : Convert.ToString(reader["FIELD3"]));//预留字段3
|
|
|
data.FIELD4 = (reader["FIELD4"] == null ? "" : Convert.ToString(reader["FIELD4"]));//预留字段4
|
|
|
data.FIELD5 = (reader["FIELD5"] == null ? "" : Convert.ToString(reader["FIELD5"]));//预留字段5
|
|
|
data.FIELD6 = (reader["FIELD6"] == null ? "" : Convert.ToString(reader["FIELD6"]));//预留字段6
|
|
|
data.FIELD7 = (reader["FIELD7"] == null ? "" : Convert.ToString(reader["FIELD7"]));//预留字段7
|
|
|
data.FIELD8 = (reader["FIELD8"] == null ? "" : Convert.ToString(reader["FIELD8"]));//预留字段8
|
|
|
data.FIELD9 = (reader["FIELD9"] == null ? "" : Convert.ToString(reader["FIELD9"]));//预留字段9
|
|
|
data.FIELD10 = (reader["FIELD10"] == null ? "" : Convert.ToString(reader["FIELD10"]));//预留字段10
|
|
|
data.ISSYS = (reader["ISSYS"] == null ? false : Convert.ToBoolean(reader["ISSYS"]));//是否手动录入
|
|
|
data.FSETTLCODE = (reader["FSETTLCODE"] == null ? "" : Convert.ToString(reader["FSETTLCODE"]));//结算方式
|
|
|
data.FSETTLENO = (reader["FSETTLENO"] == null ? "" : Convert.ToString(reader["FSETTLENO"]));//财务辅助编号
|
|
|
data.CUSTOMERNAME = (reader["CUSTOMERNAME"] == null ? "" : Convert.ToString(reader["CUSTOMERNAME"]));//委托单位
|
|
|
data.SALE = (reader["SALE"] == null ? "" : Convert.ToString(reader["SALE"]));//揽货人
|
|
|
data.BLNO = (reader["BLNO"] == null ? "" : Convert.ToString(reader["BLNO"]));//业务编号
|
|
|
data.ITEMGID = (reader["ITEMGID"] == null ? "" : Convert.ToString(reader["ITEMGID"]));
|
|
|
data.DEPTGID = (reader["DEPTGID"] == null ? "" : Convert.ToString(reader["DEPTGID"]));
|
|
|
data.ACCALL = (reader["ACCALL"] == null ? "" : Convert.ToString(reader["ACCALL"]));
|
|
|
//data.FCYAMT = (reader["FCYAMT"] == null ? 0 : Convert.ToDecimal(reader["FCYAMT"]));//原币金额
|
|
|
data.ISCHECKED = (reader["ISCHECKED"] == null ? false : Convert.ToBoolean(reader["ISCHECKED"]));//是否审核
|
|
|
if (reader["CHECKEDTIME"] != null && reader["CHECKEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["CHECKEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["CHECKEDTIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.CHECKEDTIME = Convert.ToDateTime(reader["CHECKEDTIME"]);//审核时间
|
|
|
}
|
|
|
if (reader["FSETTLDATE"] != null && reader["FSETTLDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["FSETTLDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["FSETTLDATE"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.FSETTLDATE = Convert.ToDateTime(reader["FSETTLDATE"]);//结算时间
|
|
|
}
|
|
|
data.CREATEUSER = (reader["CREATEUSER_d"] == null ? "" : Convert.ToString(reader["CREATEUSER_d"]));//创建人
|
|
|
data.CREATEUSERNAME = (reader["CREATEUSERNAME_d"] == null ? "" : Convert.ToString(reader["CREATEUSERNAME_d"]));//创建人
|
|
|
if (reader["CREATETIME_d"] != null && reader["CREATETIME_d"].ToString().Trim().IndexOf("0001") < 0 && reader["CREATETIME_d"].ToString().Trim().IndexOf("1900") < 0 && reader["CREATETIME_d"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME_d"]);//创建时间
|
|
|
}
|
|
|
data.MODIFIEDUSER = (reader["MODIFIEDUSER_d"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER_d"]));//最后一次更新操作人
|
|
|
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME_d"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME_d"]));//最后一次更新操作人
|
|
|
if (reader["MODIFIEDTIME_d"] != null && reader["MODIFIEDTIME_d"].ToString().Trim().IndexOf("0001") < 0 && reader["MODIFIEDTIME_d"].ToString().Trim().IndexOf("1900") < 0 && reader["MODIFIEDTIME_d"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME_d"]);//最后一次更新操作时间
|
|
|
}
|
|
|
if (reader["ISCOPY"] != DBNull.Value)
|
|
|
data.ISCOPY = Convert.ToBoolean(reader["ISCOPY"]);
|
|
|
data.ISAUTOSTR = "手工";
|
|
|
if (reader["ISAUTO"] != DBNull.Value)
|
|
|
{
|
|
|
data.ISAUTO = Convert.ToBoolean(reader["ISAUTO"]);
|
|
|
if (data.ISAUTO) data.ISAUTOSTR = "自动";
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
static public string GetDataListStr(string strCondition, string userid, string sort = null)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT GID,GID as 唯一编码,VOUALLNO as 凭证字号,VOUDATE as 凭证日期,VKNO as 凭证字,VOUNO as 凭证号,ITEMNO as 行号,EXPLAN as 摘要,ACCID as 科目代码,ACCALL as 会计科目,FCYNO as 原币币别,FCYEXRATE as 汇率,FCYAMT as 原币金额,AMTDR as 借方金额,AMTCR as 贷方金额,PREPARED as 制单人,MODIFIEDUSERNAME_d as 改单人,CHECKED as 审核人 from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring+ ",ITEMNO");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//strSql.Append(" order by convert(int,VOUNO) desc,VOUDATE desc,ITEMNO");
|
|
|
strSql.Append(" order by VOUALLNO desc,VOUDATE desc,ITEMNO");
|
|
|
}
|
|
|
return strSql.ToString();
|
|
|
}
|
|
|
|
|
|
static public string GetDataListStrHJ(string strCondition, string userid, string sort = null)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT ORDNO,ORDNO as 唯一编码,VOUALLNO as 凭证字号,VOUNO as 凭证号,VKNO as 凭证字,VOUDATE as 凭证日期,ACCYEAR as 凭证年,ACCMONTH as 凭证月,ATTACHS as 附件数,ACCDATE as 会计期间,PREPARED as 制单人,ISCHECKED as 是否审核,CHECKED as 审核人,ENTERED as 记账人,MODIFIEDUSERNAME as 改单人,ISEXPORT as 是否导出凭证,SUM(case when FCYNO='RMB' THEN AMTDR ELSE 0 END) as 本位币借方,SUM(case when FCYNO='RMB' THEN AMTCR ELSE 0 END) as 本位币贷方,SUM(FCYDR) as 外币借方,SUM(FCYCR) as 外币贷方,SUM(AMTDR) as 综合本位币借方,SUM(AMTCR) as 综合本位币贷方 from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
strSql.Append(" GROUP BY ORDNO,VOUALLNO,VOUNO,VKNO,VOUDATE,ACCYEAR,ACCMONTH,ATTACHS,ACCDATE,PREPARED,ISCHECKED,CHECKED,ENTERED,ISEXPORT,MODIFIEDUSERNAME");
|
|
|
//strSql.Append(" order by convert(int,VOUNO) desc,VOUDATE desc");
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by VOUALLNO desc,VOUDATE desc");
|
|
|
}
|
|
|
return strSql.ToString();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 查询明细表
|
|
|
static public List<MsCwVouitemsGl> GetDetailList(string strCondition, string userid, string usercode, string companyid)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT GID, ORDNO, ITEMNO, ACCID, PACCID, ACCNAME, PROPERTY, GRADE, DC, AMTDR, AMTCR, ISFCY, FCYNO, FCYEXRATE, FCYDR, FCYCR, QTYUNIT, QTYDR, QTYCR, EXPLAN, ISDEPTACC, ISEMPLACC, ISCORPACC, ISITEMACC, DEPTID, EMPLID, CORPID, PITEMID, ITEMID, FIELD10, FIELD9, FIELD8, FIELD7, FIELD6, FIELD5, FIELD4, FIELD3, FIELD2, FIELD1, ISSYS, FSETTLCODE, FSETTLENO, MODIFIEDUSER, MODIFIEDTIME, CUSTOMERNAME, SALE, BLNO, ITEMGID, DEPTGID,(ACCID+'-'+ACCALL) as ACCALL,FSETTLDATE,isnull((case when FCYDR=0 then FCYCR else FCYDR end),0) as FCYAMT from Cw_Vouitems_Gl WITH(NOLOCK) where 1=1");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
// strSql.Append(" order by AMTDR DESC,ORDNO ,ITEMNO");
|
|
|
strSql.Append(" order by ORDNO ,ITEMNO");
|
|
|
|
|
|
return SetDetail(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<MsCwVouitemsGl> SetDetail(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<MsCwVouitemsGl>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
MsCwVouitemsGl data = new MsCwVouitemsGl();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码 newid()
|
|
|
data.ORDNO = (reader["ORDNO"] == null ? "" : Convert.ToString(reader["ORDNO"]));
|
|
|
data.ITEMNO = (reader["ITEMNO"] == null ? 0 : Convert.ToInt32(reader["ITEMNO"]));//行号
|
|
|
data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]));//科目代码
|
|
|
data.PACCID = (reader["PACCID"] == null ? "" : Convert.ToString(reader["PACCID"]));//父级科目代码
|
|
|
data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]));//科目名称
|
|
|
data.PROPERTY = (reader["PROPERTY"] == null ? 0 : Convert.ToInt32(reader["PROPERTY"]));//科目属性
|
|
|
data.GRADE = (reader["GRADE"] == null ? 0 : Convert.ToInt32(reader["GRADE"]));//科目级别
|
|
|
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]));//借贷方向
|
|
|
data.AMTDR = (reader["AMTDR"] == null ? 0 : Convert.ToDecimal(reader["AMTDR"]));//本位币借方金额(互斥)
|
|
|
data.AMTCR = (reader["AMTCR"] == null ? 0 : Convert.ToDecimal(reader["AMTCR"]));//本位币贷方金额(互斥)
|
|
|
data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否外币
|
|
|
data.FCYNO = (reader["FCYNO"] == null ? "" : Convert.ToString(reader["FCYNO"]));//外币编号usd
|
|
|
data.FCYEXRATE = (reader["FCYEXRATE"] == null ? 0 : Convert.ToDecimal(reader["FCYEXRATE"]));//汇率
|
|
|
data.FCYDR = (reader["FCYDR"] == null ? 0 : Convert.ToDecimal(reader["FCYDR"]));//外币借方金额
|
|
|
data.FCYCR = (reader["FCYCR"] == null ? 0 : Convert.ToDecimal(reader["FCYCR"]));//外币贷方金额
|
|
|
data.QTYUNIT = (reader["QTYUNIT"] == null ? "" : Convert.ToString(reader["QTYUNIT"]));//数量包装单位
|
|
|
data.QTYDR = (reader["QTYDR"] == null ? 0 : Convert.ToDecimal(reader["QTYDR"]));//借方数量
|
|
|
data.QTYCR = (reader["QTYCR"] == null ? 0 : Convert.ToDecimal(reader["QTYCR"]));//贷方数量
|
|
|
data.EXPLAN = (reader["EXPLAN"] == null ? "" : Convert.ToString(reader["EXPLAN"]));//摘要,规则生成
|
|
|
data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//核算部门,按规则设置生成
|
|
|
data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//核算人员,按规则设置生成
|
|
|
data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//核算客户,按规则设置生成
|
|
|
data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//核算项目,按规则设置生成
|
|
|
data.DEPTID = (reader["DEPTID"] == null ? "" : Convert.ToString(reader["DEPTID"]));//部门(系统)
|
|
|
data.EMPLID = (reader["EMPLID"] == null ? "" : Convert.ToString(reader["EMPLID"]));//人员(系统)
|
|
|
data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//客户(系统)
|
|
|
data.PITEMID = (reader["PITEMID"] == null ? 0 : Convert.ToInt32(reader["PITEMID"]));//父级项目编号
|
|
|
data.ITEMID = (reader["ITEMID"] == null ? "" : Convert.ToString(reader["ITEMID"]));//项目编号
|
|
|
data.FIELD1 = (reader["FIELD1"] == null ? "" : Convert.ToString(reader["FIELD1"]));//预留字段1
|
|
|
data.FIELD2 = (reader["FIELD2"] == null ? "" : Convert.ToString(reader["FIELD2"]));//预留字段2
|
|
|
data.FIELD3 = (reader["FIELD3"] == null ? "" : Convert.ToString(reader["FIELD3"]));//预留字段3
|
|
|
data.FIELD4 = (reader["FIELD4"] == null ? "" : Convert.ToString(reader["FIELD4"]));//预留字段4
|
|
|
data.FIELD5 = (reader["FIELD5"] == null ? "" : Convert.ToString(reader["FIELD5"]));//预留字段5
|
|
|
data.FIELD6 = (reader["FIELD6"] == null ? "" : Convert.ToString(reader["FIELD6"]));//预留字段6
|
|
|
data.FIELD7 = (reader["FIELD7"] == null ? "" : Convert.ToString(reader["FIELD7"]));//预留字段7
|
|
|
data.FIELD8 = (reader["FIELD8"] == null ? "" : Convert.ToString(reader["FIELD8"]));//预留字段8
|
|
|
data.FIELD9 = (reader["FIELD9"] == null ? "" : Convert.ToString(reader["FIELD9"]));//预留字段9
|
|
|
data.FIELD10 = (reader["FIELD10"] == null ? "" : Convert.ToString(reader["FIELD10"]));//预留字段10
|
|
|
data.ISSYS = (reader["ISSYS"] == null ? false : Convert.ToBoolean(reader["ISSYS"]));//是否手动录入
|
|
|
data.FSETTLCODE = (reader["FSETTLCODE"] == null ? "" : Convert.ToString(reader["FSETTLCODE"]));//结算方式
|
|
|
data.FSETTLENO = (reader["FSETTLENO"] == null ? "" : Convert.ToString(reader["FSETTLENO"]));//财务辅助编号
|
|
|
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//最后一次更新操作人
|
|
|
if (reader["MODIFIEDTIME"] != null && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("0001") < 0 && reader["MODIFIEDTIME"].ToString().Trim().IndexOf("1900") < 0 && reader["MODIFIEDTIME"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更新操作时间
|
|
|
}
|
|
|
data.CUSTOMERNAME = (reader["CUSTOMERNAME"] == null ? "" : Convert.ToString(reader["CUSTOMERNAME"]));//委托单位
|
|
|
data.SALE = (reader["SALE"] == null ? "" : Convert.ToString(reader["SALE"]));//揽货人
|
|
|
data.BLNO = (reader["BLNO"] == null ? "" : Convert.ToString(reader["BLNO"]));//业务编号
|
|
|
data.ITEMGID = (reader["ITEMGID"] == null ? "" : Convert.ToString(reader["ITEMGID"]));
|
|
|
data.DEPTGID = (reader["DEPTGID"] == null ? "" : Convert.ToString(reader["DEPTGID"]));
|
|
|
data.ACCALL = (reader["ACCALL"] == null ? "" : Convert.ToString(reader["ACCALL"]));
|
|
|
data.FCYAMT = (reader["FCYAMT"] == null ? 0 : Convert.ToDecimal(reader["FCYAMT"]));//原币金额
|
|
|
if (reader["FSETTLDATE"] != null && reader["FSETTLDATE"].ToString().Trim().IndexOf("0001") < 0 && reader["FSETTLDATE"].ToString().Trim().IndexOf("1900") < 0 && reader["FSETTLDATE"].ToString().Trim() != "")
|
|
|
{
|
|
|
data.FSETTLDATE = Convert.ToDateTime(reader["FSETTLDATE"]);//结算日期
|
|
|
}
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 根据币别,获取汇率值
|
|
|
public static string GetFCYEXRATE(string FCY, string LINKGID, string strCompanyID, string strUserID)
|
|
|
{
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
|
|
|
string strFCY = "RMB,1";
|
|
|
if (FCY.Trim() == "")
|
|
|
{
|
|
|
string sSQL2 = "select top 1 isnull(CURRENCY,'RMB') as CURRENCY from cw_accitems_currency where LINKGID='" + LINKGID + "' ORDER BY CURRENCY";
|
|
|
FCY = T_ALL_DA.GetStrSQL("CURRENCY", sSQL2);
|
|
|
}
|
|
|
if (FCY != "RMB")
|
|
|
{
|
|
|
string sSQL = "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='" + FCY + "'";// and CORPID='" + strCompanyID + "'
|
|
|
strFCY = T_ALL_DA.GetStrSQL("DEFAULTRATE", sSQL);
|
|
|
if (strFCY.Trim() == "")
|
|
|
{
|
|
|
//return "请先设置帐套信息!";
|
|
|
return "-1";
|
|
|
}
|
|
|
strFCY = FCY + "," + strFCY;
|
|
|
}
|
|
|
return strFCY;
|
|
|
}
|
|
|
public static string GetFCYEXRATEVOUDATE(string FCY, string LINKGID, string strCompanyID, string strUserID, string VouDate)
|
|
|
{
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
if (VouDate == "") {
|
|
|
VouDate = BasicDataRefDAL.GetCwACCDATE(strUserID);
|
|
|
}
|
|
|
else
|
|
|
VouDate = VouDate.Substring(0, 7);
|
|
|
// string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
|
|
|
string strFCY = "RMB,1";
|
|
|
if (FCY.Trim() == "")
|
|
|
{
|
|
|
string sSQL2 = "select top 1 isnull(CURRENCY,'RMB') as CURRENCY from cw_accitems_currency where LINKGID='" + LINKGID + "' ORDER BY CURRENCY";
|
|
|
FCY = T_ALL_DA.GetStrSQL("CURRENCY", sSQL2);
|
|
|
}
|
|
|
if (FCY != "RMB")
|
|
|
{
|
|
|
string sSQL = "SELECT top 1 DEFAULTRATE=isnull((select top 1 BEGRATE from cw_currency_rate where LINKGID=code_currency.GID and ISDELETE=0 and ACCDATE= '" + VouDate + "' and STARTGID='" + strCwSTARTGID + "'),DEFAULTRATE) from code_currency WITH(NOLOCK) where CODENAME='" + FCY + "'";// and CORPID='" + strCompanyID + "'
|
|
|
strFCY = T_ALL_DA.GetStrSQL("DEFAULTRATE", sSQL);
|
|
|
if (strFCY.Trim() == "")
|
|
|
{
|
|
|
//return "请先设置帐套信息!";
|
|
|
return "-1";
|
|
|
}
|
|
|
strFCY = FCY + "," + strFCY;
|
|
|
}
|
|
|
return strFCY;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 删除
|
|
|
public static DBResult Delete(string gids, string strUserID)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
var result = new DBResult();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
try
|
|
|
{
|
|
|
/*原删除各个表(停用)
|
|
|
var sGids = " and ORDNO in ('" + gids.Replace(",", "','") + "')";
|
|
|
var cmdDelete = db.GetSqlStringCommand("UPDATE ch_fee SET VOUALLNO='' where VOUALLNO in (select VOUALLNO from Cw_Vouchers_Gl where 1=1" + sGids + ")");
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
cmdDelete = db.GetSqlStringCommand("UPDATE ch_fee_settlement SET VOUCHERNO='' where VOUCHERNO in (select VOUALLNO from Cw_Vouchers_Gl where 1=1" + sGids + ")");
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
cmdDelete = db.GetSqlStringCommand("UPDATE ch_fee_invoice SET VOUNO='' where VOUNO in (select VOUALLNO from Cw_Vouchers_Gl where 1=1" + sGids + ")");
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
cmdDelete = db.GetSqlStringCommand("UPDATE ch_fee_invoicehexiao SET VOUNO='' where VOUNO in (select VOUALLNO from Cw_Vouchers_Gl where 1=1" + sGids + ")");
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
*/
|
|
|
|
|
|
var sGids = " and ORDNO in ('" + gids.Replace(",", "','") + "')";
|
|
|
var cmdDelete = db.GetSqlStringCommand("delete from [cw_vouno_bs_gl] where STARTGID='" + strCwSTARTGID + "'" + sGids);
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
//把删除的凭证号插入序号的漏号补号表
|
|
|
cmdDelete = db.GetSqlStringCommand("INSERT INTO [code_fill_serialno]([GID],[TABLENAME],[SERIALNO],[CREATEUSER],[CREATETIME],[ISDELETE],[DELETEUSER],[DELETETIME],STARTGID) select newid(),'cw_vouchers_gl',VOUALLNO,'" + strUserID + "',getdate(),0,'',getdate(),'" + strCwSTARTGID + "' from cw_vouchers_gl where 1=1" + sGids);
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
cmdDelete = db.GetSqlStringCommand("delete from Cw_Vouitems_Gl where 1=1" + sGids);
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
cmdDelete = db.GetSqlStringCommand("delete from Cw_Vouchers_Gl where 1=1" + sGids);
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "删除出现错误,请重试!";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
result.Success = true;
|
|
|
result.Message = "操作成功";
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static DBResult DeleteDetail(MsCwVouitemsGl headData)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
try
|
|
|
{
|
|
|
var cmdDelete = db.GetSqlStringCommand("delete from Cw_Vouitems_Gl where GID='" + headData.GID + "'");
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
var cmdDelete2 = db.GetSqlStringCommand("delete from Cw_Vouitems_Gl where COPYGID='" + headData.GID + "'");
|
|
|
db.ExecuteNonQuery(cmdDelete2, tran);
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "删除出现错误,请重试!";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
result.Success = true;
|
|
|
result.Message = "操作成功";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 审核/返审
|
|
|
public static DBResult setISCHECKED(string gids, string iTYPE, int iOK, int iSkip, string USERID, string SHOWNAME, string COMPANYID)
|
|
|
{
|
|
|
iOK = 0;
|
|
|
string strError = "";
|
|
|
string strError2 = "";
|
|
|
var result = new DBResult();
|
|
|
string strGIDs = gids.Trim().Replace(",", "','");
|
|
|
string sGIDs = "";
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(USERID);
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
DataSet ds = T_ALL_DA.GetAllSQL("SELECT * from [VW_cw_vouchers_vouitems_gl] WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ORDNO in ('" + strGIDs + "')");
|
|
|
var AccList = BasicDataRefDAL.GetCwAccitemsGlAll(" DETAILED=1 and ISENABLE=1 ", USERID);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
string[] items = gids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
for (int j = 0; j < items.Length; j++)
|
|
|
{
|
|
|
Decimal dlAMTDR = 0;
|
|
|
Decimal dlAMTCR = 0;
|
|
|
int iBreak = 0;
|
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows[i]["ORDNO"].ToString().Trim() == items[j].ToString().Trim())
|
|
|
{
|
|
|
if (iTYPE.Trim() == "1")
|
|
|
{
|
|
|
|
|
|
foreach (var Accitems in AccList)
|
|
|
{
|
|
|
if (Accitems.ACCID == ds.Tables[0].Rows[i]["ACCID"].ToString().Trim()) {
|
|
|
if (Accitems.ISCORPACC) {
|
|
|
if (ds.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() == "") {
|
|
|
iBreak++;
|
|
|
strError = strError + "凭证号:" + ds.Tables[0].Rows[i]["VOUNO"].ToString().Trim() + ",行号:" + ds.Tables[0].Rows[i]["ITEMNO"].ToString().Trim() + ",科目" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "核算客户不能为空!";
|
|
|
}
|
|
|
}
|
|
|
if (Accitems.ISDEPTACC)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows[i]["DEPTGID"].ToString().Trim() == "")
|
|
|
{
|
|
|
iBreak++;
|
|
|
strError = strError + "凭证号:" + ds.Tables[0].Rows[i]["VOUNO"].ToString().Trim() + ",行号:" + ds.Tables[0].Rows[i]["ITEMNO"].ToString().Trim() + ",科目" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "核算部门不能为空!";
|
|
|
}
|
|
|
}
|
|
|
if (Accitems.ISEMPLACC)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows[i]["SALE"].ToString().Trim() == "")
|
|
|
{
|
|
|
iBreak++;
|
|
|
strError = strError + "凭证号:" + ds.Tables[0].Rows[i]["VOUNO"].ToString().Trim() + ",行号:" + ds.Tables[0].Rows[i]["ITEMNO"].ToString().Trim() + ",科目" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "核算人员不能为空!";
|
|
|
}
|
|
|
}
|
|
|
if (Accitems.ISITEMACC)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows[i]["ITEMID"].ToString().Trim() == "")
|
|
|
{
|
|
|
iBreak++;
|
|
|
strError = strError + "凭证号:" + ds.Tables[0].Rows[i]["VOUNO"].ToString().Trim() + ",行号:" + ds.Tables[0].Rows[i]["ITEMNO"].ToString().Trim() + ",科目" + ds.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "核算项目不能为空!";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ds.Tables[0].Rows[i]["EXPLAN"].ToString().Trim() == "")
|
|
|
{
|
|
|
iSkip++;
|
|
|
strError = strError+ "摘要不能为空!";
|
|
|
iBreak++;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
dlAMTDR += Decimal.Parse(ds.Tables[0].Rows[i]["AMTDR"].ToString().Trim());
|
|
|
dlAMTCR += Decimal.Parse(ds.Tables[0].Rows[i]["AMTCR"].ToString().Trim());
|
|
|
}
|
|
|
}
|
|
|
if (iBreak > 0)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
//
|
|
|
if (dlAMTDR != 0 || dlAMTCR != 0)
|
|
|
{
|
|
|
if (dlAMTDR != dlAMTCR)
|
|
|
{
|
|
|
iSkip++;
|
|
|
strError2 = "借贷不平衡!";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sGIDs += "," + items[j].ToString().Trim();
|
|
|
iOK++;
|
|
|
}
|
|
|
}
|
|
|
else if (dlAMTDR == dlAMTCR)
|
|
|
{
|
|
|
sGIDs += "," + items[j].ToString().Trim();
|
|
|
iOK++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
strGIDs = "";
|
|
|
if(sGIDs!="")
|
|
|
{
|
|
|
strGIDs = sGIDs.Trim().Substring(1).Replace(",", "','");
|
|
|
}
|
|
|
if (strGIDs != "")
|
|
|
{
|
|
|
#region 审核/返审
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
try
|
|
|
{
|
|
|
var cmdDelete = db.GetSqlStringCommand("update Cw_Vouchers_Gl set ISCHECKED=1,CHECKED='" + USERID + "',CHECKEDTIME=getdate() where ORDNO in ('" + strGIDs + "')");
|
|
|
if (iTYPE.Trim() == "0")
|
|
|
{
|
|
|
cmdDelete = db.GetSqlStringCommand("update Cw_Vouchers_Gl set ISCHECKED=0,CHECKED='',CHECKEDTIME=getdate(),ISCARRY=0 where ORDNO in ('" + strGIDs + "')");
|
|
|
}
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "操作出现错误,请重试!";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 结转已审核的凭证到总账本期发生额
|
|
|
string strVOUDATE = "SELECT top 1 SUBSTRING(convert(varchar,VOUDATE,23),1,7) as VOUDATE from [Cw_Vouchers_Gl] WITH(NOLOCK) where ORDNO in ('" + strGIDs + "')";
|
|
|
strVOUDATE = T_ALL_DA.GetStrSQL("VOUDATE", strVOUDATE);
|
|
|
bool bl = SaveBQFSE(strVOUDATE, USERID, COMPANYID);
|
|
|
if (!bl)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "操作出现错误,请重试!";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "操作完成!成功:" + iOK + "条,跳过:" + iSkip + "条。";
|
|
|
if (strError.Trim() != "" || strError2 != "")
|
|
|
{
|
|
|
result.Message = "操作完成!成功:" + iOK + "条,跳过:" + iSkip + "条。问题:" + strError + strError2;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 结转已审核的凭证到总账本期发生额、累计额
|
|
|
public static bool SaveBQFSE(string strVOUDATE, string strUserID, string companyid)
|
|
|
{
|
|
|
#region 默认操作
|
|
|
bool bl = true;
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
//
|
|
|
DateTime rq2 = DateTime.Parse(strVOUDATE.Trim());
|
|
|
string strYEAR = rq2.Year.ToString().Trim();
|
|
|
string strMONTH = rq2.Month.ToString().Trim();
|
|
|
if (strMONTH.Length == 1)
|
|
|
{
|
|
|
strMONTH = "0" + strMONTH;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 更新本期的发生额合计、累计合计
|
|
|
#region SQL语句
|
|
|
string strSql = "select *"
|
|
|
//AMTYEARDR RMB期初借方
|
|
|
//AMTYEARCR RMB期初贷方
|
|
|
//+ ",AMTYEARBLC=(case WHEN DC2='借' THEN ISNULL((AMTYEARDR-AMTYEARCR),0) ELSE ISNULL((AMTYEARCR-AMTYEARDR),0) END)" //RMB期初余额
|
|
|
//+ ",AMTDR2=AMTDR" //RMB本月借方
|
|
|
//+ ",AMTCR2=AMTCR" //RMB本月贷方
|
|
|
//+ ",AMTBLC=(case WHEN DC2='借' THEN ISNULL((AMTDR-AMTCR),0) ELSE ISNULL((AMTCR-AMTDR),0) END)" //RMB本月余额
|
|
|
//+ ",AMTLASTDR=ISNULL((AMTYEARDR+AMTDR),0)" //RMB累计借方
|
|
|
//+ ",AMTLASTCR=ISNULL((AMTYEARCR+AMTCR),0)" //RMB累计贷方
|
|
|
//+ ",AMTLASTBLC=(case WHEN DC2='借' THEN ISNULL(((AMTYEARDR-AMTYEARCR)+(AMTDR-AMTCR)),0) ELSE ISNULL(((AMTYEARCR-AMTYEARDR)+(AMTCR-AMTDR)),0) END)" //RMB累计余额
|
|
|
// //FCYYEARDR 外币期初借方
|
|
|
// //FCYYEARCR 外币期初贷方
|
|
|
//+ ",FCYYEARBLC=(case WHEN DC2='借' THEN ISNULL((FCYYEARDR-FCYYEARCR),0) ELSE ISNULL((FCYYEARCR-FCYYEARDR),0) END)" //外币期初余额
|
|
|
//+ ",FCYDR2=FCYDR" //外币本月借方
|
|
|
//+ ",FCYCR2=FCYCR" //外币本月贷方
|
|
|
//+ ",FCYBLC=(case WHEN DC2='借' THEN ISNULL((FCYDR-FCYCR),0) ELSE ISNULL((FCYCR-FCYDR),0) END)" //外币本月余额
|
|
|
//+ ",FCYLASTDR=ISNULL((FCYYEARDR+FCYDR),0)" //外币累计借方
|
|
|
//+ ",FCYLASTCR=ISNULL((FCYYEARCR+FCYCR),0)" //外币累计贷方
|
|
|
//+ ",FCYLASTBLC=(case WHEN DC2='借' THEN ISNULL(((FCYYEARDR-FCYYEARCR)+(FCYDR-FCYCR)),0) ELSE ISNULL(((FCYYEARCR-FCYYEARDR)+(FCYCR-FCYDR)),0) END)" //外币累计余额
|
|
|
// //QTYYEARDR 期初借方
|
|
|
// //QTYYEARCR 期初贷方
|
|
|
//+ ",QTYYEARBLC=(case WHEN DC2='借' THEN ISNULL((QTYYEARDR-QTYYEARCR),0) ELSE ISNULL((QTYYEARCR-QTYYEARDR),0) END)" //期初余额
|
|
|
//+ ",QTYDR2=QTYDR" //本月借方
|
|
|
//+ ",QTYCR2=QTYCR" //本月贷方
|
|
|
//+ ",QTYBLC=(case WHEN DC2='借' THEN ISNULL((QTYDR-QTYCR),0) ELSE ISNULL((QTYCR-QTYDR),0) END)" //本月余额
|
|
|
//+ ",QTYLASTDR=ISNULL((QTYYEARDR+QTYDR),0)" //累计借方
|
|
|
//+ ",QTYLASTCR=ISNULL((QTYYEARCR+QTYCR),0)" //累计贷方
|
|
|
//+ ",QTYLASTBLC=(case WHEN DC2='借' THEN ISNULL(((QTYYEARDR-QTYYEARCR)+(QTYDR-QTYCR)),0) ELSE ISNULL(((QTYYEARCR-QTYYEARDR)+(QTYCR-QTYDR)),0) END)" //累计余额
|
|
|
//+ " from ("
|
|
|
//+ "select ACCGID,PACCGID,ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO"
|
|
|
//+ ",AMTYEARDR=ISNULL((select top 1 AMTYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//RMB期初借方
|
|
|
//+ ",AMTYEARCR=ISNULL((select top 1 AMTYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//RMB期初贷方
|
|
|
//+ ",sum(AMTDR_RMB) as AMTDR"//RMB本月借方
|
|
|
//+ ",sum(AMTCR_RMB) as AMTCR"//RMB本月贷方
|
|
|
//+ ",FCYYEARDR=ISNULL((select top 1 FCYYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//外币期初借方
|
|
|
//+ ",FCYYEARCR=ISNULL((select top 1 FCYYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//外币期初贷方
|
|
|
//+ ",sum(FCYDR) as FCYDR"//外币本月借方
|
|
|
//+ ",sum(FCYCR) as FCYCR"//外币本月贷方
|
|
|
//+ ",QTYYEARDR=ISNULL((select top 1 QTYYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//期初借方
|
|
|
//+ ",QTYYEARCR=ISNULL((select top 1 QTYYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//期初贷方
|
|
|
//+ ",sum(AMTDR) as QTYDR"//本月借方
|
|
|
//+ ",sum(AMTCR) as QTYCR"//本月贷方
|
|
|
//+ ",DC2"
|
|
|
//+ " from ("
|
|
|
//+ "select *"
|
|
|
//+ ",(case FCYNO WHEN 'RMB' THEN AMTDR ELSE 0 END) as AMTDR_RMB"//RMB本月借方
|
|
|
//+ ",(case FCYNO WHEN 'RMB' THEN AMTCR ELSE 0 END) as AMTCR_RMB"//RMB本月贷方
|
|
|
//+ ",ACCGID=ISNULL((select top 1 GID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",PACCGID=ISNULL((select top 1 PACCGID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",DC2=ISNULL((select top 1 DC from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item WITH(NOLOCK) where GID=Cw_Vouitems_Gl.ITEMGID),'')"
|
|
|
//+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept WITH(NOLOCK) where GID=Cw_Vouitems_Gl.DEPTGID),'')"
|
|
|
//+ " from Cw_Vouitems_Gl WITH(NOLOCK) where 1=1"
|
|
|
//+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=1 and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7))"
|
|
|
//+ ") as a"
|
|
|
//+ " group BY ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,DC2,ACCGID,PACCGID"
|
|
|
//+ ") as b"
|
|
|
//+ " order by ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME";
|
|
|
|
|
|
|
|
|
+ ",AMTYEARBLC=(case WHEN DC2='借' THEN ISNULL((AMTYEARDR-AMTYEARCR),0) ELSE ISNULL((AMTYEARCR-AMTYEARDR),0) END)" //RMB期初余额
|
|
|
+ ",AMTDR2=AMTDR" //RMB本月借方
|
|
|
+ ",AMTCR2=AMTCR" //RMB本月贷方
|
|
|
+ ",AMTBLC=(case WHEN DC2='借' THEN ISNULL((AMTDR-AMTCR),0) ELSE ISNULL((AMTCR-AMTDR),0) END)" //RMB本月余额
|
|
|
+ ",AMTLASTDR=ISNULL((AMTYEARDR+AMTDR),0)" //RMB累计借方
|
|
|
+ ",AMTLASTCR=ISNULL((AMTYEARCR+AMTCR),0)" //RMB累计贷方
|
|
|
+ ",AMTLASTBLC=(case WHEN DC2='借' THEN ISNULL(((AMTYEARDR-AMTYEARCR)+(AMTDR-AMTCR)),0) ELSE ISNULL(((AMTYEARCR-AMTYEARDR)+(AMTCR-AMTDR)),0) END)" //RMB累计余额
|
|
|
//FCYYEARDR 外币期初借方
|
|
|
//FCYYEARCR 外币期初贷方
|
|
|
+ ",FCYYEARBLC=(case WHEN DC2='借' THEN ISNULL((FCYYEARDR-FCYYEARCR),0) ELSE ISNULL((FCYYEARCR-FCYYEARDR),0) END)" //外币期初余额
|
|
|
+ ",FCYDR2=FCYDR" //外币本月借方
|
|
|
+ ",FCYCR2=FCYCR" //外币本月贷方
|
|
|
+ ",FCYBLC=(case WHEN DC2='借' THEN ISNULL((FCYDR-FCYCR),0) ELSE ISNULL((FCYCR-FCYDR),0) END)" //外币本月余额
|
|
|
+ ",FCYLASTDR=ISNULL((FCYYEARDR+FCYDR),0)" //外币累计借方
|
|
|
+ ",FCYLASTCR=ISNULL((FCYYEARCR+FCYCR),0)" //外币累计贷方
|
|
|
+ ",FCYLASTBLC=(case WHEN DC2='借' THEN ISNULL(((FCYYEARDR-FCYYEARCR)+(FCYDR-FCYCR)),0) ELSE ISNULL(((FCYYEARCR-FCYYEARDR)+(FCYCR-FCYDR)),0) END)" //外币累计余额
|
|
|
//QTYYEARDR 期初借方
|
|
|
//QTYYEARCR 期初贷方
|
|
|
+ ",QTYYEARBLC=(case WHEN DC2='借' THEN ISNULL((QTYYEARDR-QTYYEARCR),0) ELSE ISNULL((QTYYEARCR-QTYYEARDR),0) END)" //期初余额
|
|
|
+ ",QTYDR2=QTYDR" //本月借方
|
|
|
+ ",QTYCR2=QTYCR" //本月贷方
|
|
|
+ ",QTYBLC=(case WHEN DC2='借' THEN ISNULL((QTYDR-QTYCR),0) ELSE ISNULL((QTYCR-QTYDR),0) END)" //本月余额
|
|
|
+ ",QTYLASTDR=ISNULL((QTYYEARDR+QTYDR),0)" //累计借方
|
|
|
+ ",QTYLASTCR=ISNULL((QTYYEARCR+QTYCR),0)" //累计贷方
|
|
|
+ ",QTYLASTBLC=(case WHEN DC2='借' THEN ISNULL(((QTYYEARDR-QTYYEARCR)+(QTYDR-QTYCR)),0) ELSE ISNULL(((QTYYEARCR-QTYYEARDR)+(QTYCR-QTYDR)),0) END)" //累计余额
|
|
|
+ " from ("
|
|
|
+ "select ACCGID,PACCGID,ACCID,ACCNAME,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO"
|
|
|
+ ",gl.AMTYEARDR"//RMB期初借方
|
|
|
+ ",gl.AMTYEARCR"//RMB期初贷方
|
|
|
+ ",sum(AMTDR_RMB) as AMTDR"//RMB本月借方
|
|
|
+ ",sum(AMTCR_RMB) as AMTCR"//RMB本月贷方
|
|
|
+ ",gl.FCYYEARDR"//外币期初借方
|
|
|
+ ",gl.FCYYEARCR"//外币期初贷方
|
|
|
+ ",sum(a.FCYDR) as FCYDR"//外币本月借方
|
|
|
+ ",sum(a.FCYCR) as FCYCR"//外币本月贷方
|
|
|
+ ",gl.QTYYEARDR"//期初借方
|
|
|
+ ",gl.QTYYEARCR"//期初贷方
|
|
|
+ ",sum(a.AMTDR) as QTYDR"//本月借方
|
|
|
+ ",sum(a.AMTCR) as QTYCR"//本月贷方
|
|
|
+ ",DC2"
|
|
|
+ " from ("
|
|
|
+ "select *"
|
|
|
+ ",(case FCYNO WHEN 'RMB' THEN AMTDR ELSE 0 END) as AMTDR_RMB"//RMB本月借方
|
|
|
+ ",(case FCYNO WHEN 'RMB' THEN AMTCR ELSE 0 END) as AMTCR_RMB"//RMB本月贷方
|
|
|
+ ",ACCGID=ISNULL((select top 1 GID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",PACCGID=ISNULL((select top 1 PACCGID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",DC2=ISNULL((select top 1 DC from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item WITH(NOLOCK) where GID=Cw_Vouitems_Gl.ITEMGID),'')"
|
|
|
+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept WITH(NOLOCK) where GID=Cw_Vouitems_Gl.DEPTGID),'')"
|
|
|
+ " from Cw_Vouitems_Gl WITH(NOLOCK) where 1=1"
|
|
|
+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=1 and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7))"
|
|
|
+ ") as a"
|
|
|
|
|
|
+ " left join cw_genleg_accitems gl WITH(NOLOCK) on (gl.[STARTGID]='" + strCwSTARTGID + "' and gl.CURRENCY=a.FCYNO and gl.DEPTACC=a.DEPTNAME and gl.EMPLACC=a.SALE and gl.CORPACC=a.CUSTOMERNAME and gl.ITEMACC=a.ITEMNAME and gl.ACCDATE=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and gl.LINKGID=a.ACCGID) "
|
|
|
|
|
|
+ " group BY ACCID,ACCNAME,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,DC2,ACCGID,PACCGID,gl.AMTYEARDR,gl.AMTYEARCR,gl.FCYYEARDR,gl.FCYYEARCR,gl.QTYYEARDR,gl.QTYYEARCR"
|
|
|
+ ") as b"
|
|
|
+ " order by ACCID,ACCNAME,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME";
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
DataSet dsCwGenlegAccitems = T_ALL_DA.GetAllSQL(strSql);
|
|
|
|
|
|
#region 生成入库
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
#region 清空当月的总账表信息
|
|
|
string sls = "update cw_genleg_accitems SET"
|
|
|
+ " AMTDR=0"//RMB本月借方
|
|
|
+ ",AMTCR=0"//RMB本月贷方
|
|
|
+ ",AMTBLC=0"//RMB本月余额
|
|
|
+ ",AMTLASTDR=0"//RMB累计借方
|
|
|
+ ",AMTLASTCR=0"//RMB累计贷方
|
|
|
+ ",AMTLASTBLC=0"//RMB累计余额
|
|
|
+ ",FCYDR=0"//外币本月借方
|
|
|
+ ",FCYCR=0"//外币本月贷方
|
|
|
+ ",FCYBLC=0"//外币本月余额
|
|
|
+ ",FCYLASTDR=0"//外币累计借方
|
|
|
+ ",FCYLASTCR=0"//外币累计贷方
|
|
|
+ ",FCYLASTBLC=0"//外币累计余额
|
|
|
+ ",QTYDR=0"//本月借方
|
|
|
+ ",QTYCR=0"//本月贷方
|
|
|
+ ",QTYBLC=0"//本月余额
|
|
|
+ ",QTYLASTDR=0"//累计借方
|
|
|
+ ",QTYLASTCR=0"//累计贷方
|
|
|
+ ",QTYLASTBLC=0"//累计余额"
|
|
|
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
|
|
|
+ " where STARTGID='" + strCwSTARTGID + "'"//账套启用GID
|
|
|
+ " and ACCDATE=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7)";//会计期间
|
|
|
#endregion
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sls, null);
|
|
|
|
|
|
int isNull = 0;
|
|
|
#region 为空的状况
|
|
|
if (dsCwGenlegAccitems != null)
|
|
|
{
|
|
|
if (dsCwGenlegAccitems.Tables[0].Rows.Count <= 0)
|
|
|
{
|
|
|
#region 为空的状况
|
|
|
strSql = "select *"
|
|
|
//AMTYEARDR RMB期初借方
|
|
|
//AMTYEARCR RMB期初贷方
|
|
|
//+ ",AMTYEARBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB期初余额
|
|
|
//+ ",AMTDR2=0" //RMB本月借方
|
|
|
//+ ",AMTCR2=0" //RMB本月贷方
|
|
|
//+ ",AMTBLC=0" //RMB本月余额
|
|
|
//+ ",AMTLASTDR=ISNULL(AMTYEARDR,0)" //RMB累计借方
|
|
|
//+ ",AMTLASTCR=ISNULL(AMTYEARCR,0)" //RMB累计贷方
|
|
|
//+ ",AMTLASTBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB累计余额
|
|
|
// //FCYYEARDR 外币期初借方
|
|
|
// //FCYYEARCR 外币期初贷方
|
|
|
//+ ",FCYYEARBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币期初余额
|
|
|
//+ ",FCYDR2=0" //外币本月借方
|
|
|
//+ ",FCYCR2=0" //外币本月贷方
|
|
|
//+ ",FCYBLC=0" //外币本月余额
|
|
|
//+ ",FCYLASTDR=ISNULL(FCYYEARDR,0)" //外币累计借方
|
|
|
//+ ",FCYLASTCR=ISNULL(FCYYEARCR,0)" //外币累计贷方
|
|
|
//+ ",FCYLASTBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币累计余额
|
|
|
// //QTYYEARDR 期初借方
|
|
|
// //QTYYEARCR 期初贷方
|
|
|
//+ ",QTYYEARBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //期初余额
|
|
|
//+ ",QTYDR2=0" //本月借方
|
|
|
//+ ",QTYCR2=0" //本月贷方
|
|
|
//+ ",QTYBLC=0" //本月余额
|
|
|
//+ ",QTYLASTDR=ISNULL(QTYYEARDR,0)" //累计借方
|
|
|
//+ ",QTYLASTCR=ISNULL(QTYYEARCR,0)" //累计贷方
|
|
|
//+ ",QTYLASTBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //累计余额
|
|
|
//+ " from ("
|
|
|
//+ "select ACCGID,PACCGID,ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO"
|
|
|
//+ ",AMTYEARDR=ISNULL((select top 1 AMTYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//RMB期初借方
|
|
|
//+ ",AMTYEARCR=ISNULL((select top 1 AMTYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//RMB期初贷方
|
|
|
//+ ",sum(AMTDR_RMB) as AMTDR"//RMB本月借方
|
|
|
//+ ",sum(AMTCR_RMB) as AMTCR"//RMB本月贷方
|
|
|
//+ ",FCYYEARDR=ISNULL((select top 1 FCYYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//外币期初借方
|
|
|
//+ ",FCYYEARCR=ISNULL((select top 1 FCYYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//外币期初贷方
|
|
|
//+ ",sum(FCYDR) as FCYDR"//外币本月借方
|
|
|
//+ ",sum(FCYCR) as FCYCR"//外币本月贷方
|
|
|
//+ ",QTYYEARDR=ISNULL((select top 1 QTYYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//期初借方
|
|
|
//+ ",QTYYEARCR=ISNULL((select top 1 QTYYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//期初贷方
|
|
|
//+ ",sum(AMTDR) as QTYDR"//本月借方
|
|
|
//+ ",sum(AMTCR) as QTYCR"//本月贷方
|
|
|
//+ ",DC2"
|
|
|
//+ " from ("
|
|
|
//+ "select *"
|
|
|
//+ ",(case FCYNO WHEN 'RMB' THEN AMTDR ELSE 0 END) as AMTDR_RMB"//RMB本月借方
|
|
|
//+ ",(case FCYNO WHEN 'RMB' THEN AMTCR ELSE 0 END) as AMTCR_RMB"//RMB本月贷方
|
|
|
//+ ",ACCGID=ISNULL((select top 1 GID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",PACCGID=ISNULL((select top 1 PACCGID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",DC2=ISNULL((select top 1 DC from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item WITH(NOLOCK) where GID=Cw_Vouitems_Gl.ITEMGID),'')"
|
|
|
//+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept WITH(NOLOCK) where GID=Cw_Vouitems_Gl.DEPTGID),'')"
|
|
|
//+ " from Cw_Vouitems_Gl WITH(NOLOCK) where 1=1"
|
|
|
//+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=0 and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7))"
|
|
|
//+ ") as a"
|
|
|
//+ " group BY ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,DC2,ACCGID,PACCGID"
|
|
|
//+ ") as b"
|
|
|
//+ " order by ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME";
|
|
|
|
|
|
+ ",AMTYEARBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB期初余额
|
|
|
+ ",AMTDR2=0" //RMB本月借方
|
|
|
+ ",AMTCR2=0" //RMB本月贷方
|
|
|
+ ",AMTBLC=0" //RMB本月余额
|
|
|
+ ",AMTLASTDR=ISNULL(AMTYEARDR,0)" //RMB累计借方
|
|
|
+ ",AMTLASTCR=ISNULL(AMTYEARCR,0)" //RMB累计贷方
|
|
|
+ ",AMTLASTBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB累计余额
|
|
|
//FCYYEARDR 外币期初借方
|
|
|
//FCYYEARCR 外币期初贷方
|
|
|
+ ",FCYYEARBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币期初余额
|
|
|
+ ",FCYDR2=0" //外币本月借方
|
|
|
+ ",FCYCR2=0" //外币本月贷方
|
|
|
+ ",FCYBLC=0" //外币本月余额
|
|
|
+ ",FCYLASTDR=ISNULL(FCYYEARDR,0)" //外币累计借方
|
|
|
+ ",FCYLASTCR=ISNULL(FCYYEARCR,0)" //外币累计贷方
|
|
|
+ ",FCYLASTBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币累计余额
|
|
|
//QTYYEARDR 期初借方
|
|
|
//QTYYEARCR 期初贷方
|
|
|
+ ",QTYYEARBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //期初余额
|
|
|
+ ",QTYDR2=0" //本月借方
|
|
|
+ ",QTYCR2=0" //本月贷方
|
|
|
+ ",QTYBLC=0" //本月余额
|
|
|
+ ",QTYLASTDR=ISNULL(QTYYEARDR,0)" //累计借方
|
|
|
+ ",QTYLASTCR=ISNULL(QTYYEARCR,0)" //累计贷方
|
|
|
+ ",QTYLASTBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //累计余额
|
|
|
+ " from ("
|
|
|
+ "select ACCGID,PACCGID,ACCID,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO"
|
|
|
+ ",gl.AMTYEARDR"//RMB期初借方
|
|
|
+ ",gl.AMTYEARCR"//RMB期初贷方
|
|
|
+ ",sum(AMTDR_RMB) as AMTDR"//RMB本月借方
|
|
|
+ ",sum(AMTCR_RMB) as AMTCR"//RMB本月贷方
|
|
|
+ ",gl.FCYYEARDR"//外币期初借方
|
|
|
+ ",gl.FCYYEARCR"//外币期初贷方
|
|
|
+ ",sum(a.FCYDR) as FCYDR"//外币本月借方
|
|
|
+ ",sum(a.FCYCR) as FCYCR"//外币本月贷方
|
|
|
+ ",gl.QTYYEARDR"//期初借方
|
|
|
+ ",gl.QTYYEARCR"//期初贷方
|
|
|
+ ",sum(a.AMTDR) as QTYDR"//本月借方
|
|
|
+ ",sum(a.AMTCR) as QTYCR"//本月贷方
|
|
|
+ ",DC2"
|
|
|
+ " from ("
|
|
|
+ "select *"
|
|
|
+ ",(case FCYNO WHEN 'RMB' THEN AMTDR ELSE 0 END) as AMTDR_RMB"//RMB本月借方
|
|
|
+ ",(case FCYNO WHEN 'RMB' THEN AMTCR ELSE 0 END) as AMTCR_RMB"//RMB本月贷方
|
|
|
+ ",ACCGID=ISNULL((select top 1 GID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",PACCGID=ISNULL((select top 1 PACCGID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",DC2=ISNULL((select top 1 DC from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item WITH(NOLOCK) where GID=Cw_Vouitems_Gl.ITEMGID),'')"
|
|
|
+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept WITH(NOLOCK) where GID=Cw_Vouitems_Gl.DEPTGID),'')"
|
|
|
+ " from Cw_Vouitems_Gl WITH(NOLOCK) where 1=1"
|
|
|
+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=0 and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7))"
|
|
|
+ ") as a"
|
|
|
+ " left join cw_genleg_accitems gl WITH(NOLOCK) on (gl.[STARTGID]='" + strCwSTARTGID + "' and gl.CURRENCY=a.FCYNO and gl.DEPTACC=a.DEPTNAME and gl.EMPLACC=a.SALE and gl.CORPACC=a.CUSTOMERNAME and gl.ITEMACC=a.ITEMNAME and gl.ACCDATE=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and gl.LINKGID=a.ACCGID) "
|
|
|
|
|
|
|
|
|
+ " group BY ACCID,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,DC2,ACCGID,PACCGID,gl.AMTYEARDR,gl.AMTYEARCR,gl.FCYYEARDR,gl.FCYYEARCR,gl.QTYYEARDR,gl.QTYYEARCR"
|
|
|
+ ") as b"
|
|
|
+ " order by ACCID,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME";
|
|
|
|
|
|
#endregion
|
|
|
dsCwGenlegAccitems = T_ALL_DA.GetAllSQL(strSql);
|
|
|
isNull++;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
#region 为空的状况
|
|
|
strSql = "select *"
|
|
|
//AMTYEARDR RMB期初借方
|
|
|
//AMTYEARCR RMB期初贷方
|
|
|
//+ ",AMTYEARBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB期初余额
|
|
|
//+ ",AMTDR2=0" //RMB本月借方
|
|
|
//+ ",AMTCR2=0" //RMB本月贷方
|
|
|
//+ ",AMTBLC=0" //RMB本月余额
|
|
|
//+ ",AMTLASTDR=ISNULL(AMTYEARDR,0)" //RMB累计借方
|
|
|
//+ ",AMTLASTCR=ISNULL(AMTYEARCR,0)" //RMB累计贷方
|
|
|
//+ ",AMTLASTBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB累计余额
|
|
|
// //FCYYEARDR 外币期初借方
|
|
|
// //FCYYEARCR 外币期初贷方
|
|
|
//+ ",FCYYEARBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币期初余额
|
|
|
//+ ",FCYDR2=0" //外币本月借方
|
|
|
//+ ",FCYCR2=0" //外币本月贷方
|
|
|
//+ ",FCYBLC=0" //外币本月余额
|
|
|
//+ ",FCYLASTDR=ISNULL(FCYYEARDR,0)" //外币累计借方
|
|
|
//+ ",FCYLASTCR=ISNULL(FCYYEARCR,0)" //外币累计贷方
|
|
|
//+ ",FCYLASTBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币累计余额
|
|
|
// //QTYYEARDR 期初借方
|
|
|
// //QTYYEARCR 期初贷方
|
|
|
//+ ",QTYYEARBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //期初余额
|
|
|
//+ ",QTYDR2=0" //本月借方
|
|
|
//+ ",QTYCR2=0" //本月贷方
|
|
|
//+ ",QTYBLC=0" //本月余额
|
|
|
//+ ",QTYLASTDR=ISNULL(QTYYEARDR,0)" //累计借方
|
|
|
//+ ",QTYLASTCR=ISNULL(QTYYEARCR,0)" //累计贷方
|
|
|
//+ ",QTYLASTBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //累计余额
|
|
|
//+ " from ("
|
|
|
//+ "select ACCGID,PACCGID,ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO"
|
|
|
//+ ",AMTYEARDR=ISNULL((select top 1 AMTYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//RMB期初借方
|
|
|
//+ ",AMTYEARCR=ISNULL((select top 1 AMTYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//RMB期初贷方
|
|
|
//+ ",sum(AMTDR_RMB) as AMTDR"//RMB本月借方
|
|
|
//+ ",sum(AMTCR_RMB) as AMTCR"//RMB本月贷方
|
|
|
//+ ",FCYYEARDR=ISNULL((select top 1 FCYYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//外币期初借方
|
|
|
//+ ",FCYYEARCR=ISNULL((select top 1 FCYYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//外币期初贷方
|
|
|
//+ ",sum(FCYDR) as FCYDR"//外币本月借方
|
|
|
//+ ",sum(FCYCR) as FCYCR"//外币本月贷方
|
|
|
//+ ",QTYYEARDR=ISNULL((select top 1 QTYYEARDR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//期初借方
|
|
|
//+ ",QTYYEARCR=ISNULL((select top 1 QTYYEARCR from cw_genleg_accitems WITH(NOLOCK) 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,'" + strVOUDATE + "',23),1,7) and LINKGID=(SELECT top 1 GID from cw_accitems_gl WITH(NOLOCK) where GID=a.ACCGID)),0)"//期初贷方
|
|
|
//+ ",sum(AMTDR) as QTYDR"//本月借方
|
|
|
//+ ",sum(AMTCR) as QTYCR"//本月贷方
|
|
|
//+ ",DC2"
|
|
|
//+ " from ("
|
|
|
//+ "select *"
|
|
|
//+ ",(case FCYNO WHEN 'RMB' THEN AMTDR ELSE 0 END) as AMTDR_RMB"//RMB本月借方
|
|
|
//+ ",(case FCYNO WHEN 'RMB' THEN AMTCR ELSE 0 END) as AMTCR_RMB"//RMB本月贷方
|
|
|
//+ ",ACCGID=ISNULL((select top 1 GID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",PACCGID=ISNULL((select top 1 PACCGID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",DC2=ISNULL((select top 1 DC from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
//+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item WITH(NOLOCK) where GID=Cw_Vouitems_Gl.ITEMGID),'')"
|
|
|
//+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept WITH(NOLOCK) where GID=Cw_Vouitems_Gl.DEPTGID),'')"
|
|
|
//+ " from Cw_Vouitems_Gl WITH(NOLOCK) where 1=1"
|
|
|
//+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=0 and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7))"
|
|
|
//+ ") as a"
|
|
|
//+ " group BY ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,DC2,ACCGID,PACCGID"
|
|
|
//+ ") as b"
|
|
|
//+ " order by ACCID,ACCNAME,ACCALL,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME";
|
|
|
|
|
|
+ ",AMTYEARBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB期初余额
|
|
|
+ ",AMTDR2=0" //RMB本月借方
|
|
|
+ ",AMTCR2=0" //RMB本月贷方
|
|
|
+ ",AMTBLC=0" //RMB本月余额
|
|
|
+ ",AMTLASTDR=ISNULL(AMTYEARDR,0)" //RMB累计借方
|
|
|
+ ",AMTLASTCR=ISNULL(AMTYEARCR,0)" //RMB累计贷方
|
|
|
+ ",AMTLASTBLC=ISNULL((AMTYEARDR-AMTYEARCR),0)" //RMB累计余额
|
|
|
//FCYYEARDR 外币期初借方
|
|
|
//FCYYEARCR 外币期初贷方
|
|
|
+ ",FCYYEARBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币期初余额
|
|
|
+ ",FCYDR2=0" //外币本月借方
|
|
|
+ ",FCYCR2=0" //外币本月贷方
|
|
|
+ ",FCYBLC=0" //外币本月余额
|
|
|
+ ",FCYLASTDR=ISNULL(FCYYEARDR,0)" //外币累计借方
|
|
|
+ ",FCYLASTCR=ISNULL(FCYYEARCR,0)" //外币累计贷方
|
|
|
+ ",FCYLASTBLC=ISNULL((FCYYEARDR-FCYYEARCR),0)" //外币累计余额
|
|
|
//QTYYEARDR 期初借方
|
|
|
//QTYYEARCR 期初贷方
|
|
|
+ ",QTYYEARBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //期初余额
|
|
|
+ ",QTYDR2=0" //本月借方
|
|
|
+ ",QTYCR2=0" //本月贷方
|
|
|
+ ",QTYBLC=0" //本月余额
|
|
|
+ ",QTYLASTDR=ISNULL(QTYYEARDR,0)" //累计借方
|
|
|
+ ",QTYLASTCR=ISNULL(QTYYEARCR,0)" //累计贷方
|
|
|
+ ",QTYLASTBLC=ISNULL((QTYYEARDR-QTYYEARCR),0)" //累计余额
|
|
|
+ " from ("
|
|
|
+ "select ACCGID,PACCGID,ACCID,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO"
|
|
|
+ ",gl.AMTYEARDR"//RMB期初借方
|
|
|
+ ",gl.AMTYEARCR"//RMB期初贷方
|
|
|
+ ",sum(AMTDR_RMB) as AMTDR"//RMB本月借方
|
|
|
+ ",sum(AMTCR_RMB) as AMTCR"//RMB本月贷方
|
|
|
+ ",gl.FCYYEARDR"//外币期初借方
|
|
|
+ ",gl.FCYYEARCR"//外币期初贷方
|
|
|
+ ",sum(a.FCYDR) as FCYDR"//外币本月借方
|
|
|
+ ",sum(a.FCYCR) as FCYCR"//外币本月贷方
|
|
|
+ ",gl.QTYYEARDR"//期初借方
|
|
|
+ ",gl.QTYYEARCR"//期初贷方
|
|
|
+ ",sum(a.AMTDR) as QTYDR"//本月借方
|
|
|
+ ",sum(a.AMTCR) as QTYCR"//本月贷方
|
|
|
+ ",DC2"
|
|
|
+ " from ("
|
|
|
+ "select *"
|
|
|
+ ",(case FCYNO WHEN 'RMB' THEN AMTDR ELSE 0 END) as AMTDR_RMB"//RMB本月借方
|
|
|
+ ",(case FCYNO WHEN 'RMB' THEN AMTCR ELSE 0 END) as AMTCR_RMB"//RMB本月贷方
|
|
|
+ ",ACCGID=ISNULL((select top 1 GID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",PACCGID=ISNULL((select top 1 PACCGID from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",DC2=ISNULL((select top 1 DC from cw_accitems_gl WITH(NOLOCK) where ACCID=Cw_Vouitems_Gl.ACCID and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4)),'')"
|
|
|
+ ",ITEMNAME=ISNULL((select top 1 ITEMNAME from cw_item WITH(NOLOCK) where GID=Cw_Vouitems_Gl.ITEMGID),'')"
|
|
|
+ ",DEPTNAME=ISNULL((select top 1 DEPTNAME from sys_dept WITH(NOLOCK) where GID=Cw_Vouitems_Gl.DEPTGID),'')"
|
|
|
+ " from Cw_Vouitems_Gl WITH(NOLOCK) where 1=1"
|
|
|
+ " and ORDNO in(select ORDNO FROM Cw_Vouchers_Gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=0 and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7))"
|
|
|
+ ") as a"
|
|
|
+ " left join cw_genleg_accitems gl WITH(NOLOCK) on (gl.[STARTGID]='" + strCwSTARTGID + "' and gl.CURRENCY=a.FCYNO and gl.DEPTACC=a.DEPTNAME and gl.EMPLACC=a.SALE and gl.CORPACC=a.CUSTOMERNAME and gl.ITEMACC=a.ITEMNAME and gl.ACCDATE=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and gl.LINKGID=a.ACCGID) "
|
|
|
+ " group BY ACCID,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME,FCYNO,DC2,ACCGID,PACCGID,gl.AMTYEARDR,gl.AMTYEARCR,gl.FCYYEARDR,gl.FCYYEARCR,gl.QTYYEARDR,gl.QTYYEARCR"
|
|
|
+ ") as b"
|
|
|
+ " order by ACCID,CUSTOMERNAME,SALE,ITEMNAME,DEPTNAME";
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
dsCwGenlegAccitems = T_ALL_DA.GetAllSQL(strSql);
|
|
|
isNull++;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 默认结转科目_入库
|
|
|
foreach (DataTable myTable in dsCwGenlegAccitems.Tables)
|
|
|
{
|
|
|
foreach (DataRow myRow in myTable.Rows)//遍历表
|
|
|
{
|
|
|
#region 科目情况是否存在
|
|
|
string sSQL = "select count(*) as inum from cw_genleg_accitems WITH(NOLOCK)"
|
|
|
+" where (ISDELETE=0 or ISDELETE is null)"
|
|
|
+ " and [STARTGID]='" + strCwSTARTGID + "'"
|
|
|
+ " and YEAR='" + strYEAR + "'"//年
|
|
|
+ " and MONTH='" + strMONTH + "'"//月
|
|
|
+ " and LINKGID='" + myRow["ACCGID"].ToString().Trim() + "'"//科目GID
|
|
|
+ " and DEPTACC='" + myRow["DEPTNAME"].ToString().Trim() + "'"//核算部门
|
|
|
+ " and EMPLACC='" + myRow["SALE"].ToString().Trim() + "'"//核算人员
|
|
|
+ " and CORPACC='" + myRow["CUSTOMERNAME"].ToString().Trim() + "'"//核算客户
|
|
|
+ " and ITEMACC='" + myRow["ITEMNAME"].ToString().Trim() + "'"//核算项目
|
|
|
+ " and CURRENCY='" + myRow["FCYNO"].ToString().Trim() + "'";
|
|
|
#endregion
|
|
|
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL));
|
|
|
if (inum > 0)
|
|
|
{
|
|
|
#region 更新语句
|
|
|
sSQL = "UPDATE [cw_genleg_accitems] SET "
|
|
|
//+ " AMTYEARDR='" + myRow["AMTYEARDR"].ToString().Trim() + "'"//RMB期初借方
|
|
|
//+ ",AMTYEARCR='" + myRow["AMTYEARCR"].ToString().Trim() + "'"//RMB期初贷方
|
|
|
//+ ",AMTYEARBLC='" + myRow["AMTYEARBLC"].ToString().Trim() + "'"//RMB期初余额
|
|
|
+ " AMTDR='" + (myRow["AMTDR2"].ToString().Trim() == "" ? "0" : myRow["AMTDR2"].ToString().Trim()) + "'"//RMB本月借方
|
|
|
+ ",AMTCR='" + (myRow["AMTCR2"].ToString().Trim() == "" ? "0" : myRow["AMTCR2"].ToString().Trim()) + "'"//RMB本月贷方
|
|
|
+ ",AMTBLC='" + (myRow["AMTBLC"].ToString().Trim() == "" ? "0" : myRow["AMTBLC"].ToString().Trim()) + "'"//RMB本月余额
|
|
|
+ ",AMTLASTDR='" +( myRow["AMTLASTDR"].ToString().Trim() == "" ? "0" : myRow["AMTLASTDR"].ToString().Trim()) + "'"//RMB累计借方
|
|
|
+ ",AMTLASTCR='" + (myRow["AMTLASTCR"].ToString().Trim() == "" ? "0" : myRow["AMTLASTCR"].ToString().Trim()) + "'"//RMB累计贷方
|
|
|
+ ",AMTLASTBLC='" + (myRow["AMTLASTBLC"].ToString().Trim() == "" ? "0" : myRow["AMTLASTBLC"].ToString().Trim()) + "'"//RMB累计余额
|
|
|
//+ ",FCYYEARDR='" + myRow["FCYYEARDR"].ToString().Trim() + "'"//外币期初借方
|
|
|
//+ ",FCYYEARCR='" + myRow["FCYYEARCR"].ToString().Trim() + "'"//外币期初贷方
|
|
|
//+ ",FCYYEARBLC='" + myRow["FCYYEARBLC"].ToString().Trim() + "'"//外币期初余额
|
|
|
+ ",FCYDR='" + (myRow["FCYDR2"].ToString().Trim() == "" ? "0" : myRow["FCYDR2"].ToString().Trim()) + "'"//外币本月借方
|
|
|
+ ",FCYCR='" + (myRow["FCYCR2"].ToString().Trim() == "" ? "0" : myRow["FCYCR2"].ToString().Trim() )+ "'"//外币本月贷方
|
|
|
+ ",FCYBLC='" + (myRow["FCYBLC"].ToString().Trim() == "" ? "0" : myRow["FCYBLC"].ToString().Trim() )+ "'"//外币本月余额
|
|
|
+ ",FCYLASTDR='" + (myRow["FCYLASTDR"].ToString().Trim() == "" ? "0" : myRow["FCYLASTDR"].ToString().Trim()) + "'"//外币累计借方
|
|
|
+ ",FCYLASTCR='" + (myRow["FCYLASTCR"].ToString().Trim() == "" ? "0" : myRow["FCYLASTCR"].ToString().Trim()) + "'"//外币累计贷方
|
|
|
+ ",FCYLASTBLC='" + (myRow["FCYLASTBLC"].ToString().Trim() == "" ? "0" : myRow["FCYLASTBLC"].ToString().Trim()) + "'"//外币累计余额
|
|
|
//+ ",QTYYEARDR='" + myRow["QTYYEARDR"].ToString().Trim() + "'"//期初借方
|
|
|
//+ ",QTYYEARCR='" + myRow["QTYYEARCR"].ToString().Trim() + "'"//期初贷方
|
|
|
//+ ",QTYYEARBLC='" + myRow["QTYYEARBLC"].ToString().Trim() + "'"//期初余额
|
|
|
+ ",QTYDR='" + (myRow["QTYDR2"].ToString().Trim() == "" ? "0" : myRow["QTYDR2"].ToString().Trim()) + "'"//本月借方
|
|
|
+ ",QTYCR='" + (myRow["QTYCR2"].ToString().Trim() == "" ? "0" : myRow["QTYCR2"].ToString().Trim()) + "'"//本月贷方
|
|
|
+ ",QTYBLC='" + (myRow["QTYBLC"].ToString().Trim() == "" ? "0" : myRow["QTYBLC"].ToString().Trim()) + "'"//本月余额
|
|
|
+ ",QTYLASTDR='" + (myRow["QTYLASTDR"].ToString().Trim() == "" ? "0" : myRow["QTYLASTDR"].ToString().Trim()) + "'"//累计借方
|
|
|
+ ",QTYLASTCR='" + (myRow["QTYLASTCR"].ToString().Trim() == "" ? "0" : myRow["QTYLASTCR"].ToString().Trim()) + "'"//累计贷方
|
|
|
+ ",QTYLASTBLC='" + (myRow["QTYLASTBLC"].ToString().Trim() == "" ? "0" : myRow["QTYLASTBLC"].ToString().Trim()) + "'"//累计余额
|
|
|
+ ",MODIFIEDUSER='" + strUserID.Trim() + "'"//更改操作人gid
|
|
|
+ ",MODIFIEDTIME=getdate()"//更改操作时间
|
|
|
+ " where (ISDELETE=0 or ISDELETE is null)"
|
|
|
+ " and [STARTGID]='" + strCwSTARTGID + "'"
|
|
|
+ " and YEAR='" + strYEAR + "'"//年
|
|
|
+ " and MONTH='" + strMONTH + "'"//月
|
|
|
+ " and LINKGID='" + myRow["ACCGID"].ToString().Trim() + "'"//科目GID
|
|
|
+ " and DEPTACC='" + myRow["DEPTNAME"].ToString().Trim() + "'"//核算部门
|
|
|
+ " and EMPLACC='" + myRow["SALE"].ToString().Trim() + "'"//核算人员
|
|
|
+ " and CORPACC='" + myRow["CUSTOMERNAME"].ToString().Trim() + "'"//核算客户
|
|
|
+ " and ITEMACC='" + myRow["ITEMNAME"].ToString().Trim() + "'"//核算项目
|
|
|
+ " and CURRENCY='" + myRow["FCYNO"].ToString().Trim() + "'";//币别
|
|
|
|
|
|
//+ ",CORPID='" + myRow[""].ToString().Trim() + "'"//分公司代码
|
|
|
//+ ",ISDELETE='" + myRow[""].ToString().Trim() + "'"//是否删除
|
|
|
//+ ",DELETEUSER='" + myRow[""].ToString().Trim() + "'"//删除人
|
|
|
//+ ",DELETETIME='" + myRow[""].ToString().Trim() + "'"//删除时间
|
|
|
//+ ",CREATEUSER='" + myRow[""].ToString().Trim() + "'"//创建人gid
|
|
|
//+ ",CREATETIME='" + myRow[""].ToString().Trim() + "'"//创建时间
|
|
|
//+ ",ISENABLE='" + myRow[""].ToString().Trim() + "'"//是否入账
|
|
|
//+ ",PFADR='" + myRow[""].ToString().Trim() + "'"//损益类科目本年累计数借方
|
|
|
//+ ",PFACR='" + myRow[""].ToString().Trim() + "'"//损益类科目本年累计数贷方
|
|
|
//+ ",STARTGID='" + myRow[""].ToString().Trim() + "'"//账套启用GID
|
|
|
//+ ",ACCDATE='" + myRow[""].ToString().Trim() + "'"//会计期间
|
|
|
#endregion
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (isNull == 0)//不为空的状况
|
|
|
{
|
|
|
#region 插入语句
|
|
|
sSQL = "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) VALUES("
|
|
|
+ "newid()"//年
|
|
|
+ ",'" + strYEAR + "'"//年
|
|
|
+ ",'" + strMONTH + "'"//月
|
|
|
+ ",'" + myRow["ACCGID"].ToString().Trim() + "'"//科目GID
|
|
|
+ ",'" + myRow["DEPTNAME"].ToString().Trim() + "'"//核算部门
|
|
|
+ ",'" + myRow["SALE"].ToString().Trim() + "'"//核算人员
|
|
|
+ ",'" + myRow["CUSTOMERNAME"].ToString().Trim() + "'"//核算客户
|
|
|
+ ",'" + myRow["ITEMNAME"].ToString().Trim() + "'"//核算项目
|
|
|
+ ",'" + myRow["FCYNO"].ToString().Trim() + "'"//币别
|
|
|
+ ",'" + (myRow["AMTYEARDR"].ToString().Trim() == "" ? "0" : myRow["AMTYEARDR"].ToString().Trim()) + "'"//RMB期初借方
|
|
|
+ ",'" + (myRow["AMTYEARCR"].ToString().Trim() == "" ? "0" : myRow["AMTYEARCR"].ToString().Trim()) + "'"//RMB期初贷方
|
|
|
+ ",'" + (myRow["AMTYEARBLC"].ToString().Trim() == "" ? "0" : myRow["AMTYEARBLC"].ToString().Trim()) + "'"//RMB期初余额
|
|
|
+ ",'" + (myRow["AMTDR2"].ToString().Trim() == "" ? "0" : myRow["AMTDR2"].ToString().Trim()) + "'"//RMB本月借方
|
|
|
+ ",'" + (myRow["AMTCR2"].ToString().Trim() == "" ? "0" : myRow["AMTCR2"].ToString().Trim()) + "'"//RMB本月贷方
|
|
|
+ ",'" + (myRow["AMTBLC"].ToString().Trim() == "" ? "0" : myRow["AMTBLC"].ToString().Trim()) + "'"//RMB本月余额
|
|
|
+ ",'" + (myRow["AMTLASTDR"].ToString().Trim() == "" ? "0" : myRow["AMTLASTDR"].ToString().Trim()) + "'"//RMB累计借方
|
|
|
+ ",'" + (myRow["AMTLASTCR"].ToString().Trim() == "" ? "0" : myRow["AMTLASTCR"].ToString().Trim()) + "'"//RMB累计贷方
|
|
|
+ ",'" + (myRow["AMTLASTBLC"].ToString().Trim() == "" ? "0" : myRow["AMTLASTBLC"].ToString().Trim()) + "'"//RMB累计余额
|
|
|
+ ",'" + (myRow["FCYYEARDR"].ToString().Trim() == "" ? "0" : myRow["FCYYEARDR"].ToString().Trim()) + "'"//外币期初借方
|
|
|
+ ",'" + (myRow["FCYYEARCR"].ToString().Trim() == "" ? "0" : myRow["FCYYEARCR"].ToString().Trim()) + "'"//外币期初贷方
|
|
|
+ ",'" + (myRow["FCYYEARBLC"].ToString().Trim() == "" ? "0" : myRow["FCYYEARBLC"].ToString().Trim()) + "'"//外币期初余额
|
|
|
+ ",'" + (myRow["FCYDR2"].ToString().Trim() == "" ? "0" : myRow["FCYDR2"].ToString().Trim()) + "'"//外币本月借方
|
|
|
+ ",'" + (myRow["FCYCR2"].ToString().Trim() == "" ? "0" : myRow["FCYCR2"].ToString().Trim()) + "'"//外币本月贷方
|
|
|
+ ",'" + (myRow["FCYBLC"].ToString().Trim() == "" ? "0" : myRow["FCYBLC"].ToString().Trim()) + "'"//外币本月余额
|
|
|
+ ",'" + (myRow["FCYLASTDR"].ToString().Trim() == "" ? "0" : myRow["FCYLASTDR"].ToString().Trim()) + "'"//外币累计借方
|
|
|
+ ",'" + (myRow["FCYLASTCR"].ToString().Trim() == "" ? "0" : myRow["FCYLASTCR"].ToString().Trim()) + "'"//外币累计贷方
|
|
|
+ ",'" + (myRow["FCYLASTBLC"].ToString().Trim() == "" ? "0" : myRow["FCYLASTBLC"].ToString().Trim()) + "'"//外币累计余额
|
|
|
+ ",'" + (myRow["QTYYEARDR"].ToString().Trim() == "" ? "0" : myRow["QTYYEARDR"].ToString().Trim()) + "'"//期初借方
|
|
|
+ ",'" + (myRow["QTYYEARCR"].ToString().Trim() == "" ? "0" : myRow["QTYYEARCR"].ToString().Trim()) + "'"//期初贷方
|
|
|
+ ",'" + (myRow["QTYYEARBLC"].ToString().Trim() == "" ? "0" : myRow["QTYYEARBLC"].ToString().Trim()) + "'"//期初余额
|
|
|
+ ",'" + (myRow["QTYDR2"].ToString().Trim() == "" ? "0" : myRow["QTYDR2"].ToString().Trim()) + "'"//本月借方
|
|
|
+ ",'" + (myRow["QTYCR2"].ToString().Trim() == "" ? "0" : myRow["QTYCR2"].ToString().Trim()) + "'"//本月贷方
|
|
|
+ ",'" + (myRow["QTYBLC"].ToString().Trim() == "" ? "0" : myRow["QTYBLC"].ToString().Trim()) + "'"//本月余额
|
|
|
+ ",'" + (myRow["QTYLASTDR"].ToString().Trim() == "" ? "0" : myRow["QTYLASTDR"].ToString().Trim()) + "'"//累计借方
|
|
|
+ ",'" + (myRow["QTYLASTCR"].ToString().Trim() == "" ? "0" : myRow["QTYLASTCR"].ToString().Trim()) + "'"//累计贷方
|
|
|
+ ",'" + (myRow["QTYLASTBLC"].ToString().Trim() == "" ? "0" : myRow["QTYLASTBLC"].ToString().Trim()) + "'"//累计余额
|
|
|
+ ",'" + companyid + "'"//分公司代码
|
|
|
+ ",0"//是否删除
|
|
|
+ ",'" + strUserID.Trim() + "'"//删除人
|
|
|
+ ",getdate()"//删除时间
|
|
|
+ ",'" + strUserID.Trim() + "'"//创建人gid
|
|
|
+ ",getdate()"//创建时间
|
|
|
+ ",'" + strUserID.Trim() + "'"//更改操作人gid
|
|
|
+ ",getdate()"//更改操作时间
|
|
|
+ ",1"//是否入账
|
|
|
+ ",0"//损益类科目本年累计数借方
|
|
|
+ ",0"//损益类科目本年累计数贷方
|
|
|
+ ",'" + strCwSTARTGID + "'"//账套启用GID
|
|
|
+ ",SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7))";//会计期间
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 合计其他当月余额为0的总账表信息的累计金额
|
|
|
sls = "update cw_genleg_accitems SET"
|
|
|
//+ ",AMTYEARDR=0"//RMB期初借方
|
|
|
//+ ",AMTYEARCR=0"//RMB期初贷方
|
|
|
//+ ",AMTYEARBLC=0"//RMB期初余额
|
|
|
//+ ",AMTDR=0"//RMB本月借方
|
|
|
//+ ",AMTCR=0"//RMB本月贷方
|
|
|
//+ ",AMTBLC=0"//RMB本月余额
|
|
|
+ " AMTLASTDR=AMTYEARDR+AMTDR"//RMB累计借方
|
|
|
+ ",AMTLASTCR=AMTYEARCR+AMTCR"//RMB累计贷方
|
|
|
+ ",AMTLASTBLC=AMTYEARBLC+AMTBLC"//RMB累计余额
|
|
|
//+ ",FCYYEARDR=0"//外币期初借方
|
|
|
//+ ",FCYYEARCR=0"//外币期初贷方
|
|
|
//+ ",FCYYEARBLC=0"//外币期初余额
|
|
|
//+ ",FCYDR=0"//外币本月借方
|
|
|
//+ ",FCYCR=0"//外币本月贷方
|
|
|
//+ ",FCYBLC=0"//外币本月余额
|
|
|
+ ",FCYLASTDR=FCYYEARDR+FCYDR"//外币累计借方
|
|
|
+ ",FCYLASTCR=FCYYEARCR+FCYCR"//外币累计贷方
|
|
|
+ ",FCYLASTBLC=FCYYEARBLC+FCYBLC"//外币累计余额
|
|
|
//+ ",QTYYEARDR=0"//期初借方
|
|
|
//+ ",QTYYEARCR=0"//期初贷方
|
|
|
//+ ",QTYYEARBLC=0"//期初余额
|
|
|
//+ ",QTYDR=0"//本月借方
|
|
|
//+ ",QTYCR=0"//本月贷方
|
|
|
//+ ",QTYBLC=0"//本月余额
|
|
|
+ ",QTYLASTDR=QTYYEARDR+QTYDR"//累计借方
|
|
|
+ ",QTYLASTCR=QTYYEARCR+QTYCR"//累计贷方
|
|
|
+ ",QTYLASTBLC=QTYYEARBLC+QTYBLC"//累计余额
|
|
|
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
|
|
|
+ " where STARTGID='" + strCwSTARTGID + "'"//账套启用GID
|
|
|
+ " and ACCDATE=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and QTYLASTBLC=0";//会计期间
|
|
|
#endregion
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sls, null);
|
|
|
|
|
|
#region 合计损益类科目当月累计借贷金额
|
|
|
sls = "update cw_genleg_accitems SET"
|
|
|
+ " AMTLASTDR=(SELECT isnull(sum(AMTDR),0) from cw_genleg_accitems as a where STARTGID='" + strCwSTARTGID + "' and ACCDATE<=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and ISDELETE=0 and ISENABLE=1 and LINKGID=cw_genleg_accitems.LINKGID and DEPTACC=cw_genleg_accitems.DEPTACC and EMPLACC=cw_genleg_accitems.EMPLACC and CORPACC=cw_genleg_accitems.CORPACC and ITEMACC=cw_genleg_accitems.ITEMACC)"//RMB累计借方
|
|
|
+ ",AMTLASTCR=(SELECT isnull(sum(AMTCR),0) from cw_genleg_accitems as a where STARTGID='" + strCwSTARTGID + "' and ACCDATE<=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and ISDELETE=0 and ISENABLE=1 and LINKGID=cw_genleg_accitems.LINKGID and DEPTACC=cw_genleg_accitems.DEPTACC and EMPLACC=cw_genleg_accitems.EMPLACC and CORPACC=cw_genleg_accitems.CORPACC and ITEMACC=cw_genleg_accitems.ITEMACC)"//RMB累计贷方
|
|
|
+ ",FCYLASTDR=(SELECT isnull(sum(FCYDR),0) from cw_genleg_accitems as a where STARTGID='" + strCwSTARTGID + "' and ACCDATE<=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and ISDELETE=0 and ISENABLE=1 and LINKGID=cw_genleg_accitems.LINKGID and DEPTACC=cw_genleg_accitems.DEPTACC and EMPLACC=cw_genleg_accitems.EMPLACC and CORPACC=cw_genleg_accitems.CORPACC and ITEMACC=cw_genleg_accitems.ITEMACC)"//外币累计借方
|
|
|
+ ",FCYLASTCR=(SELECT isnull(sum(FCYCR),0) from cw_genleg_accitems as a where STARTGID='" + strCwSTARTGID + "' and ACCDATE<=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and ISDELETE=0 and ISENABLE=1 and LINKGID=cw_genleg_accitems.LINKGID and DEPTACC=cw_genleg_accitems.DEPTACC and EMPLACC=cw_genleg_accitems.EMPLACC and CORPACC=cw_genleg_accitems.CORPACC and ITEMACC=cw_genleg_accitems.ITEMACC)"//外币累计贷方
|
|
|
+ ",QTYLASTDR=(SELECT isnull(sum(QTYDR),0) from cw_genleg_accitems as a where STARTGID='" + strCwSTARTGID + "' and ACCDATE<=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and ISDELETE=0 and ISENABLE=1 and LINKGID=cw_genleg_accitems.LINKGID and DEPTACC=cw_genleg_accitems.DEPTACC and EMPLACC=cw_genleg_accitems.EMPLACC and CORPACC=cw_genleg_accitems.CORPACC and ITEMACC=cw_genleg_accitems.ITEMACC)"//累计借方
|
|
|
+ ",QTYLASTCR=(SELECT isnull(sum(QTYCR),0) from cw_genleg_accitems as a where STARTGID='" + strCwSTARTGID + "' and ACCDATE<=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and ISDELETE=0 and ISENABLE=1 and LINKGID=cw_genleg_accitems.LINKGID and DEPTACC=cw_genleg_accitems.DEPTACC and EMPLACC=cw_genleg_accitems.EMPLACC and CORPACC=cw_genleg_accitems.CORPACC and ITEMACC=cw_genleg_accitems.ITEMACC)"//累计贷方
|
|
|
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
|
|
|
+ " where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and LINKGID in (select GID from [cw_accitems_gl] where [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "' and ACCATTRIBUTE='损益')";
|
|
|
#endregion
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sls, null);
|
|
|
|
|
|
#region 合计损益类科目当月累计余额
|
|
|
sls = "update cw_genleg_accitems SET"
|
|
|
+ " AMTLASTBLC=(case when (select top 1 DC from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID)='借' then isnull((AMTDR-AMTCR),0) else isnull((AMTCR-AMTDR),0) end)"//RMB累计余额
|
|
|
+ ",FCYLASTBLC=(case when (select top 1 DC from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID)='借' then isnull((FCYDR-FCYCR),0) else isnull((FCYCR-FCYDR),0) end)"//外币累计余额
|
|
|
+ ",QTYLASTBLC=(case when (select top 1 DC from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID)='借' then isnull((QTYDR-QTYCR),0) else isnull((QTYCR-QTYDR),0) end)"//累计余额
|
|
|
+ ",CORPID='" + companyid + "',MODIFIEDUSER='" + strUserID + "',MODIFIEDTIME=GETDATE()"
|
|
|
+ " where STARTGID='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7) and LINKGID in (select GID from [cw_accitems_gl] where [YEAR]='" + strYEAR + "' and [STARTGID]='" + strCwSTARTGID + "' and ACCATTRIBUTE='损益')";
|
|
|
#endregion
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sls, null);
|
|
|
|
|
|
//事务提交
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
//result.Success = false;
|
|
|
//result.Message = "操作出现错误,请重试!";
|
|
|
//return result;
|
|
|
return false;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
#endregion
|
|
|
//
|
|
|
#region 根据末级科目,调整父类科目
|
|
|
string lsSQL = "select PACCGID from cw_accitems_gl WITH(NOLOCK) where DETAILED=1 and ACCID in (select ACCID from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and ISCHECKED=1 and SUBSTRING(convert(varchar,VOUDATE,23),1,7)=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,7)) and [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING(convert(varchar,'" + strVOUDATE + "',23),1,4) and PACCGID<>'0' and PACCGID<>'ZC' and PACCGID<>'FZ' and PACCGID<>'GT' and PACCGID<>'QY' and PACCGID<>'CB' and PACCGID<>'SY' group by PACCGID";
|
|
|
DataSet ds = T_ALL_DA.GetAllSQL(lsSQL);
|
|
|
|
|
|
string sSQLAcc = "SELECT GID,ACCID,ACCNAME,DETAILED,DC,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,REMARKS,[YEAR],[MONTH],PACCGID=(case when (PACCGID='ZC' or PACCGID='FZ' or PACCGID='GT' or PACCGID='QY' or PACCGID='CB' or PACCGID='SY') then '0' else PACCGID end),ACCATTRIBUTE,ISENABLE,ACCTYPE,PACCID=(select top 1 ACCID from [cw_accitems_gl] as a where [STARTGID]='" + strCwSTARTGID + "' and a.gid=cw_accitems_gl.PACCGID),PACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] as b where [STARTGID]='" + strCwSTARTGID + "' and b.gid=cw_accitems_gl.PACCGID),gid as [id],ACCID+' '+ACCNAME as [NAME],0 as DR,0 as CR from [cw_accitems_gl] WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING('" + strVOUDATE + "',1,4) order by [YEAR],ACCID";
|
|
|
DataSet dsAcc = T_ALL_DA.GetAllSQL(sSQLAcc);
|
|
|
|
|
|
if (ds != null)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
foreach (DataTable myTable in ds.Tables)
|
|
|
{
|
|
|
foreach (DataRow myRow in myTable.Rows)//遍历表
|
|
|
{
|
|
|
string sPACCGID = myRow["PACCGID"].ToString().Trim();
|
|
|
SaveRow(strVOUDATE, rq2, sPACCGID, strUserID, companyid, dsAcc);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//result.Success = true;
|
|
|
//result.Message = "操作成功" + result.Message;
|
|
|
//return result;
|
|
|
#endregion
|
|
|
return bl;
|
|
|
}
|
|
|
|
|
|
public static void SaveRow(string strACCDATE, DateTime rq, string PACCGID, string strUSERID, string strCOMPANYID,DataSet ds)
|
|
|
{
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
|
|
|
//string PACCGID = myRow["PACCGID"].ToString().Trim();
|
|
|
//string CURRENCY = myRow["FCYNO"].ToString().Trim();
|
|
|
//ZC','FZ','GT','QY','CB','SY
|
|
|
if (PACCGID != "0" && PACCGID != "ZC" && PACCGID != "FZ" && PACCGID != "GT" && PACCGID != "QY" && PACCGID != "CB" && PACCGID != "SY")
|
|
|
{
|
|
|
|
|
|
if (ds != null)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
while (PACCGID.Trim() != "")
|
|
|
{
|
|
|
var isfind = false;
|
|
|
|
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows[i]["GID"].ToString().Trim() == PACCGID)
|
|
|
{
|
|
|
isfind = true;
|
|
|
string pDC = ds.Tables[0].Rows[i]["DC"].ToString().Trim();
|
|
|
var sSQL = "SELECT CURRENCY,sum(AMTYEARDR) as AMTYEARDR,sum(AMTYEARCR) as AMTYEARCR,sum(case when '" + pDC + "'=DC then AMTYEARBLC else (-AMTYEARBLC) end) as AMTYEARBLC,sum(AMTDR) as AMTDR,sum(AMTCR) as AMTCR,sum(case when '" + pDC + "'=DC then AMTBLC else (-AMTBLC) end) as AMTBLC,sum(AMTLASTDR) as AMTLASTDR,sum(AMTLASTCR) as AMTLASTCR,sum(case when '" + pDC + "'=DC then AMTLASTBLC else (-AMTLASTBLC) end) as AMTLASTBLC,sum(FCYYEARDR) as FCYYEARDR,sum(FCYYEARCR) as FCYYEARCR,sum(case when '" + pDC + "'=DC then FCYYEARBLC else (-FCYYEARBLC) end) as FCYYEARBLC,sum(FCYDR) as FCYDR,sum(FCYCR) as FCYCR,sum(case when '" + pDC + "'=DC then FCYBLC else (-FCYBLC) end) as FCYBLC,sum(FCYLASTDR) as FCYLASTDR,sum(FCYLASTCR) as FCYLASTCR,sum(case when '" + pDC + "'=DC then FCYLASTBLC else (-FCYLASTBLC) end) as FCYLASTBLC,sum(QTYYEARDR) as QTYYEARDR,sum(QTYYEARCR) as QTYYEARCR,sum(case when '" + pDC + "'=DC then QTYYEARBLC else (-QTYYEARBLC) end) as QTYYEARBLC,sum(QTYDR) as QTYDR,sum(QTYCR) as QTYCR,sum(case when '" + pDC + "'=DC then QTYBLC else (-QTYBLC) end) as QTYBLC,sum(QTYLASTDR) as QTYLASTDR,sum(QTYLASTCR) as QTYLASTCR,sum(case when '" + pDC + "'=DC then QTYLASTBLC else (-QTYLASTBLC) end) as QTYLASTBLC,sum(PFADR) as PFADR,sum(PFACR) as PFACR from [vw_cw_genleg_accitems_gl] WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,'" + strACCDATE + "',23),1,7) and LINKGID in(select gid from cw_accitems_gl WITH(NOLOCK) where PACCGID='" + PACCGID.Trim() + "' and [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "') group by CURRENCY";
|
|
|
DataSet dsLS = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (dsLS != null)
|
|
|
{
|
|
|
if (dsLS.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
foreach (DataTable myTable in dsLS.Tables)
|
|
|
{
|
|
|
foreach (DataRow dsLSRow in myTable.Rows)//遍历表
|
|
|
{
|
|
|
string PACCGID_gid = T_ALL_DA.GetStrSQL("gid", "select top 1 isnull(gid,'') as gid from cw_genleg_accitems WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and ACCDATE=SUBSTRING(convert(varchar,'" + strACCDATE + "',23),1,7) and [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and LINKGID='" + PACCGID.Trim() + "' and DEPTACC='' and EMPLACC='' and CORPACC='' and ITEMACC='' and CURRENCY='" + dsLSRow["CURRENCY"].ToString().Trim() + "'");
|
|
|
MsCwGenlegAccitems headRow = new MsCwGenlegAccitems();
|
|
|
if (PACCGID_gid.Trim() != "")//"edit"
|
|
|
{
|
|
|
#region 更新cw_genleg_accitems表
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
#region 更新cw_genleg_accitems表
|
|
|
string sSQL2 = "update cw_genleg_accitems set"
|
|
|
+ " AMTDR=" + dsLSRow["AMTDR"].ToString().Trim()//RMB期初借方
|
|
|
+ ",AMTCR=" + dsLSRow["AMTCR"].ToString().Trim()//RMB期初贷方
|
|
|
+ ",AMTBLC=" + dsLSRow["AMTBLC"].ToString().Trim()//RMB期初余额
|
|
|
+ ",AMTLASTDR=" + dsLSRow["AMTLASTDR"].ToString().Trim()//RMB累计借方
|
|
|
+ ",AMTLASTCR=" + dsLSRow["AMTLASTCR"].ToString().Trim()//RMB累计贷方
|
|
|
+ ",AMTLASTBLC=" + dsLSRow["AMTLASTBLC"].ToString().Trim()//RMB累计余额
|
|
|
+ ",FCYDR=" + dsLSRow["FCYDR"].ToString().Trim()//外币期初借方
|
|
|
+ ",FCYCR=" + dsLSRow["FCYCR"].ToString().Trim()//外币期初贷方
|
|
|
+ ",FCYBLC=" + dsLSRow["FCYBLC"].ToString().Trim()//外币期初余额
|
|
|
+ ",FCYLASTDR=" + dsLSRow["FCYLASTDR"].ToString().Trim()//外币累计借方
|
|
|
+ ",FCYLASTCR=" + dsLSRow["FCYLASTCR"].ToString().Trim()//外币累计贷方
|
|
|
+ ",FCYLASTBLC=" + dsLSRow["FCYLASTBLC"].ToString().Trim()//外币累计余额
|
|
|
+ ",QTYDR=" + dsLSRow["QTYDR"].ToString().Trim()//期初借方
|
|
|
+ ",QTYCR=" + dsLSRow["QTYCR"].ToString().Trim()//期初贷方
|
|
|
+ ",QTYBLC=" + dsLSRow["QTYBLC"].ToString().Trim()//期初余额
|
|
|
+ ",QTYLASTDR=" + dsLSRow["QTYLASTDR"].ToString().Trim()//累计借方
|
|
|
+ ",QTYLASTCR=" + dsLSRow["QTYLASTCR"].ToString().Trim()//累计贷方
|
|
|
+ ",QTYLASTBLC=" + dsLSRow["QTYLASTBLC"].ToString().Trim()//累计余额
|
|
|
+ ",CORPID='" + strCOMPANYID + "',MODIFIEDUSER='" + strUSERID + "',MODIFIEDTIME=GETDATE()"
|
|
|
+ " where GID='" + PACCGID_gid.Trim() + "'";
|
|
|
#endregion
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL2, null);
|
|
|
|
|
|
//事务提交
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
//sqlTran.Rollback();
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 未了不更新期初数,暂时不用此方法
|
|
|
/*
|
|
|
#region 默认值
|
|
|
headRow.YEAR = rq.Year.ToString();//年
|
|
|
headRow.MONTH = rq.Month.ToString();//月
|
|
|
if (rq.Month.ToString().Length == 1)
|
|
|
{
|
|
|
headRow.MONTH = "0" + rq.Month.ToString();//月
|
|
|
}
|
|
|
headRow.ACCDATE = headRow.YEAR.ToString() + "-" + headRow.MONTH.ToString();//月
|
|
|
headRow.LINKGID = PACCGID.Trim();//科目GID
|
|
|
headRow.DEPTACC = "";//核算部门
|
|
|
headRow.EMPLACC = "";//核算人员
|
|
|
headRow.CORPACC = "";//核算客户
|
|
|
headRow.ITEMACC = "";//核算项目
|
|
|
headRow.CURRENCY = dsLSRow["CURRENCY"].ToString().Trim();//币别
|
|
|
headRow.AMTYEARDR = Decimal.Parse(dsLSRow["AMTYEARDR"].ToString().Trim());//RMB期初借方
|
|
|
headRow.AMTYEARCR = Decimal.Parse(dsLSRow["AMTYEARCR"].ToString().Trim());//RMB期初贷方
|
|
|
headRow.AMTYEARBLC = Decimal.Parse(dsLSRow["AMTYEARBLC"].ToString().Trim());//RMB期初余额
|
|
|
headRow.AMTDR = Decimal.Parse(dsLSRow["AMTDR"].ToString().Trim());//RMB本月借方
|
|
|
headRow.AMTCR = Decimal.Parse(dsLSRow["AMTCR"].ToString().Trim());//RMB本月贷方
|
|
|
headRow.AMTBLC = Decimal.Parse(dsLSRow["AMTBLC"].ToString().Trim());//RMB本月余额
|
|
|
headRow.AMTLASTDR = Decimal.Parse(dsLSRow["AMTLASTDR"].ToString().Trim());//RMB累计借方
|
|
|
headRow.AMTLASTCR = Decimal.Parse(dsLSRow["AMTLASTCR"].ToString().Trim());//RMB累计贷方
|
|
|
headRow.AMTLASTBLC = Decimal.Parse(dsLSRow["AMTLASTBLC"].ToString().Trim());//RMB累计余额
|
|
|
headRow.FCYYEARDR = Decimal.Parse(dsLSRow["FCYYEARDR"].ToString().Trim());//外币期初借方
|
|
|
headRow.FCYYEARCR = Decimal.Parse(dsLSRow["FCYYEARCR"].ToString().Trim());//外币期初贷方
|
|
|
headRow.FCYYEARBLC = Decimal.Parse(dsLSRow["FCYYEARBLC"].ToString().Trim());//外币期初余额
|
|
|
headRow.FCYDR = Decimal.Parse(dsLSRow["FCYDR"].ToString().Trim());//外币本月借方
|
|
|
headRow.FCYCR = Decimal.Parse(dsLSRow["FCYCR"].ToString().Trim());//外币本月贷方
|
|
|
headRow.FCYBLC = Decimal.Parse(dsLSRow["FCYBLC"].ToString().Trim());//外币本月余额
|
|
|
headRow.FCYLASTDR = Decimal.Parse(dsLSRow["FCYLASTDR"].ToString().Trim());//外币累计借方
|
|
|
headRow.FCYLASTCR = Decimal.Parse(dsLSRow["FCYLASTCR"].ToString().Trim());//外币累计贷方
|
|
|
headRow.FCYLASTBLC = Decimal.Parse(dsLSRow["FCYLASTBLC"].ToString().Trim());//外币累计余额
|
|
|
headRow.QTYYEARDR = Decimal.Parse(dsLSRow["QTYYEARDR"].ToString().Trim());//期初借方
|
|
|
headRow.QTYYEARCR = Decimal.Parse(dsLSRow["QTYYEARCR"].ToString().Trim());//期初贷方
|
|
|
headRow.QTYYEARBLC = Decimal.Parse(dsLSRow["QTYYEARBLC"].ToString().Trim());//期初余额
|
|
|
headRow.QTYDR = Decimal.Parse(dsLSRow["QTYDR"].ToString().Trim());//本月借方
|
|
|
headRow.QTYCR = Decimal.Parse(dsLSRow["QTYCR"].ToString().Trim());//本月贷方
|
|
|
headRow.QTYBLC = Decimal.Parse(dsLSRow["QTYBLC"].ToString().Trim());//本月余额
|
|
|
headRow.QTYLASTDR = Decimal.Parse(dsLSRow["QTYLASTDR"].ToString().Trim());//累计借方
|
|
|
headRow.QTYLASTCR = Decimal.Parse(dsLSRow["QTYLASTCR"].ToString().Trim());//累计贷方
|
|
|
headRow.QTYLASTBLC = Decimal.Parse(dsLSRow["QTYLASTBLC"].ToString().Trim());//累计余额
|
|
|
headRow.PFADR = Decimal.Parse(dsLSRow["PFADR"].ToString().Trim());//损益类本年累计数借方
|
|
|
headRow.PFACR = Decimal.Parse(dsLSRow["PFACR"].ToString().Trim());//损益类本年累计数贷方
|
|
|
headRow.CORPID = strCOMPANYID;//分公司代码
|
|
|
headRow.ISDELETE = false;//是否删除
|
|
|
headRow.DELETEUSER = "";//删除人
|
|
|
headRow.DELETETIME = DateTime.Now;//删除时间
|
|
|
headRow.CREATEUSER = strUSERID;//创建人gid
|
|
|
headRow.CREATETIME = DateTime.Now;//创建时间
|
|
|
headRow.MODIFIEDUSER = strUSERID;//更改操作人gid
|
|
|
headRow.MODIFIEDTIME = DateTime.Now;//更改操作时间
|
|
|
//headRow.IsInitialEntry = dsLSRow["IsInitialEntry"].ToString().Trim() == "0" ? false : true;//更改操作时间
|
|
|
#endregion
|
|
|
headRow.GID = PACCGID_gid.Trim();//唯一编码
|
|
|
headRow.DbOperationType = DbOperationType.DbotUpd;
|
|
|
headRow.ModelUIStatus = "E";
|
|
|
*/
|
|
|
#endregion
|
|
|
}
|
|
|
else//add
|
|
|
{
|
|
|
#region 默认值
|
|
|
headRow.YEAR = rq.Year.ToString();//年
|
|
|
headRow.MONTH = rq.Month.ToString();//月
|
|
|
if (rq.Month.ToString().Length == 1)
|
|
|
{
|
|
|
headRow.MONTH = "0" + rq.Month.ToString();//月
|
|
|
}
|
|
|
headRow.ACCDATE = headRow.YEAR.ToString() + "-" + headRow.MONTH.ToString();//月
|
|
|
headRow.LINKGID = PACCGID.Trim();//科目GID
|
|
|
headRow.DEPTACC = "";//核算部门
|
|
|
headRow.EMPLACC = "";//核算人员
|
|
|
headRow.CORPACC = "";//核算客户
|
|
|
headRow.ITEMACC = "";//核算项目
|
|
|
headRow.CURRENCY = dsLSRow["CURRENCY"].ToString().Trim();//币别
|
|
|
headRow.AMTYEARDR = Decimal.Parse(dsLSRow["AMTYEARDR"].ToString().Trim());//RMB期初借方
|
|
|
headRow.AMTYEARCR = Decimal.Parse(dsLSRow["AMTYEARCR"].ToString().Trim());//RMB期初贷方
|
|
|
headRow.AMTYEARBLC = Decimal.Parse(dsLSRow["AMTYEARBLC"].ToString().Trim());//RMB期初余额
|
|
|
headRow.AMTDR = Decimal.Parse(dsLSRow["AMTDR"].ToString().Trim());//RMB本月借方
|
|
|
headRow.AMTCR = Decimal.Parse(dsLSRow["AMTCR"].ToString().Trim());//RMB本月贷方
|
|
|
headRow.AMTBLC = Decimal.Parse(dsLSRow["AMTBLC"].ToString().Trim());//RMB本月余额
|
|
|
headRow.AMTLASTDR = Decimal.Parse(dsLSRow["AMTLASTDR"].ToString().Trim());//RMB累计借方
|
|
|
headRow.AMTLASTCR = Decimal.Parse(dsLSRow["AMTLASTCR"].ToString().Trim());//RMB累计贷方
|
|
|
headRow.AMTLASTBLC = Decimal.Parse(dsLSRow["AMTLASTBLC"].ToString().Trim());//RMB累计余额
|
|
|
headRow.FCYYEARDR = Decimal.Parse(dsLSRow["FCYYEARDR"].ToString().Trim());//外币期初借方
|
|
|
headRow.FCYYEARCR = Decimal.Parse(dsLSRow["FCYYEARCR"].ToString().Trim());//外币期初贷方
|
|
|
headRow.FCYYEARBLC = Decimal.Parse(dsLSRow["FCYYEARBLC"].ToString().Trim());//外币期初余额
|
|
|
headRow.FCYDR = Decimal.Parse(dsLSRow["FCYDR"].ToString().Trim());//外币本月借方
|
|
|
headRow.FCYCR = Decimal.Parse(dsLSRow["FCYCR"].ToString().Trim());//外币本月贷方
|
|
|
headRow.FCYBLC = Decimal.Parse(dsLSRow["FCYBLC"].ToString().Trim());//外币本月余额
|
|
|
headRow.FCYLASTDR = Decimal.Parse(dsLSRow["FCYLASTDR"].ToString().Trim());//外币累计借方
|
|
|
headRow.FCYLASTCR = Decimal.Parse(dsLSRow["FCYLASTCR"].ToString().Trim());//外币累计贷方
|
|
|
headRow.FCYLASTBLC = Decimal.Parse(dsLSRow["FCYLASTBLC"].ToString().Trim());//外币累计余额
|
|
|
headRow.QTYYEARDR = Decimal.Parse(dsLSRow["QTYYEARDR"].ToString().Trim());//期初借方
|
|
|
headRow.QTYYEARCR = Decimal.Parse(dsLSRow["QTYYEARCR"].ToString().Trim());//期初贷方
|
|
|
headRow.QTYYEARBLC = Decimal.Parse(dsLSRow["QTYYEARBLC"].ToString().Trim());//期初余额
|
|
|
headRow.QTYDR = Decimal.Parse(dsLSRow["QTYDR"].ToString().Trim());//本月借方
|
|
|
headRow.QTYCR = Decimal.Parse(dsLSRow["QTYCR"].ToString().Trim());//本月贷方
|
|
|
headRow.QTYBLC = Decimal.Parse(dsLSRow["QTYBLC"].ToString().Trim());//本月余额
|
|
|
headRow.QTYLASTDR = Decimal.Parse(dsLSRow["QTYLASTDR"].ToString().Trim());//累计借方
|
|
|
headRow.QTYLASTCR = Decimal.Parse(dsLSRow["QTYLASTCR"].ToString().Trim());//累计贷方
|
|
|
headRow.QTYLASTBLC = Decimal.Parse(dsLSRow["QTYLASTBLC"].ToString().Trim());//累计余额
|
|
|
headRow.PFADR = Decimal.Parse(dsLSRow["PFADR"].ToString().Trim());//损益类本年累计数借方
|
|
|
headRow.PFACR = Decimal.Parse(dsLSRow["PFACR"].ToString().Trim());//损益类本年累计数贷方
|
|
|
|
|
|
headRow.CORPID = strCOMPANYID;//分公司代码
|
|
|
headRow.ISDELETE = false;//是否删除
|
|
|
headRow.DELETEUSER = "";//删除人
|
|
|
headRow.DELETETIME = DateTime.Now;//删除时间
|
|
|
headRow.CREATEUSER = strUSERID;//创建人gid
|
|
|
headRow.CREATETIME = DateTime.Now;//创建时间
|
|
|
headRow.MODIFIEDUSER = strUSERID;//更改操作人gid
|
|
|
headRow.MODIFIEDTIME = DateTime.Now;//更改操作时间
|
|
|
headRow.ISENABLE = true;//是否入账
|
|
|
#endregion
|
|
|
headRow.GID = Guid.NewGuid().ToString().Trim();//唯一编码
|
|
|
headRow.DbOperationType = DbOperationType.DbotIns;
|
|
|
//headRow.ModelUIStatus = "E";
|
|
|
var modb = new ModelObjectDB();
|
|
|
DBResult result = modb.Save(headRow);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
if (ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "0" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "ZC" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "FZ" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "GT" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "QY" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "CB" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "SY")
|
|
|
{
|
|
|
PACCGID = "";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PACCGID = ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim();
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!isfind) PACCGID = "";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
string sSql = "update cw_genleg_accitems set [STARTGID]='" + strCwSTARTGID + "',CORPID='" + strCOMPANYID + "',MODIFIEDUSER='" + strUSERID + "',MODIFIEDTIME=GETDATE() where STARTGID='' or STARTGID is null";
|
|
|
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSql);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 1.上一条 / 2.下一条
|
|
|
public static DBResult setPrevious(int iTYPE, string ORDNO, string strCondition, string userid)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
int iORDNO = 0;
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT ORDNO,VOUALLNO,convert(int,VOUNO) as VOUNO,VOUDATE from VW_cw_vouchers_vouitems_gl WITH(NOLOCK) where STARTGID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition.Replace("ACCDATE", "SUBSTRING(convert(char(10),VOUDATE,120),1,7)"));
|
|
|
}
|
|
|
strSql.Append(" group by ORDNO,VOUALLNO,VOUNO,VOUDATE");//
|
|
|
//strSql.Append(" order by convert(int,VOUNO) desc,VOUDATE desc");
|
|
|
strSql.Append(" order by VOUALLNO desc,VOUDATE desc");
|
|
|
DataSet ds = T_ALL_DA.GetAllSQL(strSql.ToString());
|
|
|
if (ds != null)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
int iCount = ds.Tables[0].Rows.Count;
|
|
|
for (int i = 0; i < iCount; i++)
|
|
|
{
|
|
|
if (ds.Tables[0].Rows[i]["ORDNO"].ToString().Trim() == ORDNO.Trim())
|
|
|
{
|
|
|
iORDNO = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
if (iTYPE == 1)//上一条
|
|
|
{
|
|
|
if (iORDNO == 0)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "囧,已经没有上一张了!";
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = true;
|
|
|
result.Message = ds.Tables[0].Rows[iORDNO - 1]["ORDNO"].ToString().Trim();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else if (iTYPE == 2)//下一条
|
|
|
{
|
|
|
if (iORDNO == iCount-1)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "囧,已经没有下一张了!";
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = true;
|
|
|
result.Message = ds.Tables[0].Rows[iORDNO + 1]["ORDNO"].ToString().Trim();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
result.Success = false;
|
|
|
result.Message = "囧,已经没有了!";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 是否已经维护财务代码
|
|
|
public static string GetISFINANCESOFTCODE(string TYPE, string VALUE, string strCompanyID, string userid)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string sSQL = "";
|
|
|
if (TYPE == "DeptName")
|
|
|
{
|
|
|
sSQL = "select top 1 FINANCESOFTCODE from sys_dept WITH(NOLOCK) where DEPTNAME='" + VALUE.ToString() + "'";
|
|
|
}
|
|
|
else if (TYPE == "CustNAME")
|
|
|
{
|
|
|
sSQL = "select top 1 (case when (FARCODE='' or FAPCODE='') then '' else FARCODE end) as FINANCESOFTCODE from info_client WITH(NOLOCK) where SHORTNAME='" + VALUE.ToString() + "'";
|
|
|
}
|
|
|
else if (TYPE == "SALE")
|
|
|
{
|
|
|
sSQL = "select top 1 FINANCESOFTCODE from user_baseinfo,[user] WITH(NOLOCK) where [user].GID=user_baseinfo.USERID and [user].SHOWNAME='" + VALUE.ToString() + "'";
|
|
|
}
|
|
|
else if (TYPE == "ITEMNAME")
|
|
|
{
|
|
|
sSQL = "select top 1 FINANCESOFTCODE from cw_item WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ITEMNAME='" + VALUE.ToString() + "'";//
|
|
|
}
|
|
|
//
|
|
|
string sFINANCESOFTCODE = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", sSQL);
|
|
|
if (sFINANCESOFTCODE.Trim() == "")
|
|
|
{
|
|
|
//return "请先设置帐套信息!";
|
|
|
return "-1";
|
|
|
}
|
|
|
return VALUE.ToString();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 是否复制到其他账套
|
|
|
public static DBResult CopyVouToOther(string STARTGID, string gids, string strCompanyID, string strUserID,string UserName)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
string sSQL = "";
|
|
|
string sResult = "";
|
|
|
string sCondition = "";
|
|
|
string sgids = "'" + gids.Trim().Replace(",", "','") + "'";
|
|
|
sCondition = " ORDNO in (" + sgids + ")";
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT * FROM ");
|
|
|
strSql.Append(" cw_vouchers_gl WHERE "+ sCondition);
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
var headData = new MsCwVouchersGl();
|
|
|
headData.STARTGID = STARTGID;
|
|
|
headData.COPYORDNO= Convert.ToString(reader["ORDNO"]);
|
|
|
headData.VOUDATE = Convert.ToString(reader["VOUDATE"]);
|
|
|
headData.ACCYEAR = Convert.ToString(reader["ACCYEAR"]);
|
|
|
headData.ISAUTO = Convert.ToBoolean(reader["ISAUTO"]);
|
|
|
headData.ACCMONTH = Convert.ToString(reader["ACCMONTH"]); ;
|
|
|
headData.PREPARED = Convert.ToString(reader["PREPARED"]);//制单人
|
|
|
headData.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);//创建人
|
|
|
headData.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
|
|
|
headData.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);//最后一次更新操作人
|
|
|
headData.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//最后一次更新操作时间
|
|
|
headData.VKNO = Convert.ToString(reader["VKNO"]);
|
|
|
//string sVOUNOList = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(headData.VKNO.ToString(), (headData.ACCYEAR + "-" + headData.ACCMONTH), strUserID, STARTGID);
|
|
|
//string[] ayList = sVOUNOList.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
headData.VOUNO = Convert.ToString(reader["VOUNO"]);
|
|
|
// string strVOUNO = ayList[3].ToString();
|
|
|
// headData.VOUALLNO = headData.VKNO + headData.ACCYEAR + headData.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
|
|
|
headData.VOUALLNO = Convert.ToString(reader["VOUALLNO"]);
|
|
|
|
|
|
var ORDNO = "VOU" + Guid.NewGuid().ToString().Trim().Replace("-", "");
|
|
|
headData.ORDNO = ORDNO;//唯一编码 newid()
|
|
|
headData.AMTDR = Convert.ToDecimal(reader["AMTDR"]); //本位币借方
|
|
|
headData.AMTCR = Convert.ToDecimal(reader["AMTCR"]);//本位币贷方
|
|
|
headData.FCY = Convert.ToString(reader["FCY"]);//是否含有外币科目
|
|
|
headData.QTY = Convert.ToString(reader["QTY"]);//是否含有数量科目
|
|
|
if (reader["ATTACHS"] != DBNull.Value)
|
|
|
headData.ATTACHS = Convert.ToInt32(reader["ATTACHS"]);//箱型1
|
|
|
headData.VOUPROP = "";//凭证属性
|
|
|
headData.CHECKED = "";//审核人
|
|
|
headData.ENTERED = "";//记账人
|
|
|
headData.ERRMSG = "";//错误信息
|
|
|
headData.ISDELETE = false;//是否废除
|
|
|
headData.DELETEUSER = "";//废除操作人
|
|
|
//headData.DELETETIME = null;//废除时间
|
|
|
headData.ISEXPORT = false;//是否导出凭证
|
|
|
headData.DbOperationType = DbOperationType.DbotIns;
|
|
|
var modb = new ModelObjectDB();
|
|
|
result = modb.Save(headData);
|
|
|
if (result.Success) {
|
|
|
sSQL = "INSERT INTO [cw_vouitems_gl] ([GID],[ORDNO],[ITEMNO],[ACCID],[PACCID],[ACCNAME],[PROPERTY],[GRADE],[DC],[AMTDR],[AMTCR]"
|
|
|
+ ",[ISFCY],[FCYNO],[FCYEXRATE],[FCYDR],[FCYCR],[QTYUNIT],[QTYDR],[QTYCR],[EXPLAN],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC],[DEPTID],[EMPLID],[CORPID],[PITEMID],[ITEMID],[FIELD10]"
|
|
|
+ ",[FIELD9],[FIELD8],[FIELD7],[FIELD6],[FIELD5],[FIELD4],[FIELD3],[FIELD2],[FIELD1],[ISSYS],[FSETTLCODE],[FSETTLENO],[MODIFIEDUSER],[MODIFIEDTIME],[CUSTOMERNAME],[SALE],[BLNO],[ITEMGID]"
|
|
|
+ ",[DEPTGID],[ACCALL],[FSETTLDATE],[CREATEUSER],[CREATETIME],[COPYGID]) SELECT NEWID(),'" + ORDNO + "',[ITEMNO],[ACCID],[PACCID],[ACCNAME],[PROPERTY],[GRADE],[DC],[AMTDR]"
|
|
|
+ ",[AMTCR],[ISFCY],[FCYNO],[FCYEXRATE],[FCYDR],[FCYCR],[QTYUNIT],[QTYDR],[QTYCR],[EXPLAN],[ISDEPTACC],[ISEMPLACC],[ISCORPACC],[ISITEMACC]"
|
|
|
+ ",[DEPTID],[EMPLID],[CORPID],[PITEMID],[ITEMID],[FIELD10],[FIELD9],[FIELD8],[FIELD7],[FIELD6],[FIELD5],[FIELD4],[FIELD3],[FIELD2]"
|
|
|
+ ",[FIELD1],[ISSYS],[FSETTLCODE],[FSETTLENO],[MODIFIEDUSER],[MODIFIEDTIME],[CUSTOMERNAME],[SALE],[BLNO],[ITEMGID],[DEPTGID],[ACCALL]"
|
|
|
+ ",[FSETTLDATE],'" + strUserID + "',GETDATE(),GID FROM [cw_vouitems_gl] WHERE ORDNO='"+ Convert.ToString(reader["ORDNO"]) + "'";
|
|
|
T_ALL_DA.GetExecuteSqlCommand(sSQL);
|
|
|
sSQL = " UPDATE cw_vouchers_gl SET ISCOPY=1 WHERE ORDNO='" + Convert.ToString(reader["ORDNO"]) + "'";
|
|
|
T_ALL_DA.GetExecuteSqlCommand(sSQL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "复制成功";
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 是否导出数据
|
|
|
public static DBResult getIsExport(string strCondition, string gids, string strCompanyID, string strUserID)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
string sSQL = "";
|
|
|
string sResult = "";
|
|
|
string sCondition = "";
|
|
|
string sgids = "'" + gids.Trim().Replace(",", "','") + "'";
|
|
|
if (gids.Trim() == "")
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
sCondition = " and " + strCondition;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sCondition = " and ORDNO in (" + sgids + ")";
|
|
|
}
|
|
|
//
|
|
|
|
|
|
//判断借贷平衡
|
|
|
sSQL = "select VOUALLNO,cha from (select (SUM(AMTDR)-SUM(AMTCR)) as cha,VOUALLNO from VW_cw_vouchers_vouitems_gl where 1=1" + sCondition + " group by VOUALLNO,ORDNO) as a where cha<>'0.00' group by VOUALLNO,cha order by cha desc";
|
|
|
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
|
{
|
|
|
sResult += "凭证 " + ds.Tables[0].Rows[i]["VOUALLNO"].ToString().Trim() + " 借贷不平衡,不能导出凭证!\r\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//借贷是否同时为0
|
|
|
//sSQL = "select VOUALLNO from (select (case SUM(AMTDR) when '0.00' then SUM(AMTCR) else SUM(AMTDR) end) as amt,VOUALLNO=(select VOUALLNO from cw_vouchers_gl where ORDNO=VW_cw_vouchers_vouitems_gl.ORDNO) from VW_cw_vouchers_vouitems_gl where 1=1" + sCondition + " group by VOUALLNO,ORDNO) as a where amt='0.00' group by VOUALLNO order by VOUALLNO";
|
|
|
//ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
//if (ds != null)
|
|
|
//{
|
|
|
// for (int k = 0; k < ds.Tables[0].Rows.Count; k++)
|
|
|
// {
|
|
|
// sResult += "凭证 " + ds.Tables[0].Rows[k]["VOUALLNO"].ToString().Trim() + " 有借贷双方同为“0”的数据,不能导出凭证!\r\n";
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
//外币科目汇率不能为0或1
|
|
|
sSQL = " select VOUALLNO from ( ";
|
|
|
sSQL = sSQL + " select (case FCYDR when '0.00' then FCYCR else FCYDR end) as fcy";
|
|
|
sSQL = sSQL + ",FCYEXRATE,(select VOUALLNO from cw_vouchers_gl where ORDNO=VW_cw_vouchers_vouitems_gl.ORDNO) as VOUALLNO";
|
|
|
sSQL = sSQL + " from VW_cw_vouchers_vouitems_gl";
|
|
|
sSQL = sSQL + " where 1=1" + sCondition;
|
|
|
sSQL = sSQL + " and ((FCYEXRATE=0) or (FCYEXRATE=1 and fcyno<>'RMB')) ";
|
|
|
sSQL = sSQL + " ) as a where fcy<>'0.00' and ";
|
|
|
sSQL = sSQL + " (FCYEXRATE='1.00' or FCYEXRATE='0.00') ";
|
|
|
sSQL = sSQL + " group by VOUALLNO order by VOUALLNO";
|
|
|
ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
for (int k = 0; k < ds.Tables[0].Rows.Count; k++)
|
|
|
{
|
|
|
sResult += "凭证 " + ds.Tables[0].Rows[k]["VOUALLNO"].ToString().Trim() + " 有外币科目的汇率为“0”或“1”的数据,不能导出凭证!\r\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//财务代码是否为空
|
|
|
sSQL = "select VOUALLNO from (select VOUALLNO=(select VOUALLNO from cw_vouchers_gl where ORDNO=VW_cw_vouchers_vouitems_gl.ORDNO) from VW_cw_vouchers_vouitems_gl where (accid is null or accid='')" + sCondition + ") as a group by VOUALLNO order by VOUALLNO";
|
|
|
ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
|
|
|
{
|
|
|
sResult += "凭证 " + ds.Tables[0].Rows[j]["VOUALLNO"].ToString().Trim() + " 有财务科目代码为空的数据,不能导出凭证!\r\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//客户财务代码是否为空
|
|
|
sSQL = "select CUSTOMERNAME,VOUALLNO from (select CUSTOMERNAME,VOUALLNO=(select VOUALLNO from cw_vouchers_gl where ORDNO=VW_cw_vouchers_vouitems_gl.ORDNO) from VW_cw_vouchers_vouitems_gl where ISCORPACC=1 and (CUSTOMERNAME is not null and CUSTOMERNAME<>'' and (CORPID is null or CORPID='') and (FIELD3 is null or FIELD3=''))" + sCondition + ") as a group by CUSTOMERNAME,VOUALLNO order by VOUALLNO";
|
|
|
ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
|
|
|
{
|
|
|
sResult += "凭证 " + ds.Tables[0].Rows[j]["VOUALLNO"].ToString().Trim() + " 客户:"+ ds.Tables[0].Rows[j]["CUSTOMERNAME"].ToString().Trim() + " 客户财务代码为空的数据,不能导出凭证!\r\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//人员财务代码是否为空
|
|
|
sSQL = "select VOUALLNO from (select VOUALLNO=(select VOUALLNO from cw_vouchers_gl where ORDNO=VW_cw_vouchers_vouitems_gl.ORDNO) from VW_cw_vouchers_vouitems_gl where ISEMPLACC=1 and (EMPLID is null or EMPLID='')" + sCondition + ") as a group by VOUALLNO order by VOUALLNO";
|
|
|
ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
|
|
|
{
|
|
|
sResult += "凭证 " + ds.Tables[0].Rows[j]["VOUALLNO"].ToString().Trim() + " 有人员财务代码为空的数据,不能导出凭证!\r\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//部门财务代码是否为空
|
|
|
sSQL = "select VOUALLNO from (select VOUALLNO=(select VOUALLNO from cw_vouchers_gl where ORDNO=VW_cw_vouchers_vouitems_gl.ORDNO) from VW_cw_vouchers_vouitems_gl where ISDEPTACC=1 and (DEPTID is null or DEPTID='')" + sCondition + ") as a group by VOUALLNO order by VOUALLNO";
|
|
|
ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
|
|
|
{
|
|
|
sResult += "凭证 " + ds.Tables[0].Rows[j]["VOUALLNO"].ToString().Trim() + " 有部门财务代码为空的数据,不能导出凭证!\r\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//项目财务代码是否为空
|
|
|
sSQL = "select VOUALLNO from (select VOUALLNO=(select VOUALLNO from cw_vouchers_gl where ORDNO=VW_cw_vouchers_vouitems_gl.ORDNO) from VW_cw_vouchers_vouitems_gl where ISITEMACC=1 and (ITEMID is null or ITEMID='')" + sCondition + ") as a group by VOUALLNO order by VOUALLNO";
|
|
|
ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
|
|
|
{
|
|
|
sResult += "凭证 " + ds.Tables[0].Rows[j]["VOUALLNO"].ToString().Trim() + " 有项目财务代码为空的数据,不能导出凭证!\r\n";
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
if (sResult == "")
|
|
|
{
|
|
|
result.Success = true;
|
|
|
result.Message = "";
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = sResult;
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_金蝶迷你
|
|
|
public static DBResult setExcelReportGlMN(string strCondition, string sPath)
|
|
|
{
|
|
|
string sName = "kismn";// +DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
string sSql = "";
|
|
|
var result = new DBResult();
|
|
|
string filename = sPath + "\\" + sName + ".dbf";
|
|
|
if (!System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
result.Data = filename;
|
|
|
//
|
|
|
try
|
|
|
{
|
|
|
//string sSql = "delete from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName;
|
|
|
sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName;
|
|
|
bool bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//sSql = "insert into OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName + "("
|
|
|
sSql = "insert into OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName + "("
|
|
|
+ " FDATE,FPERIOD,FGROUP,FNUM,FENTRYID,FEXP,FACCTID,FCLSNAME1,FOBJID1,FOBJNAME1"
|
|
|
+ ",FCLSNAME2,FOBJID2,FOBJNAME2,FCLSNAME3,FOBJID3,FOBJNAME3,FCLSNAME4,FOBJID4,FOBJNAME4,FTRANSID"
|
|
|
+ ",FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO"
|
|
|
//+ ",FSETTLDATE"
|
|
|
+ ",FPREPARE,FPAY,FCASH,FPOSTER,FCHECKER,FATTCHMENT,FPOSTED,FMODULE,FDELETED,FSERIALNO"
|
|
|
+ ",FTRANSDATE,FCASHFLOW,FUNITNAME,FREFERENCE,FSETTLEDT) "
|
|
|
+ "select "
|
|
|
+ " VouDate,AccMonth,VKNO,VOUNO,ROW_NUMBER() OVER ( PARTITION BY ORDNO ORDER BY ORDNO,ITEMNO )-1 as ITEMNO ,left(ExPlan,118) ExPlan,ACCID,CORPACC,CorpID,CUSTOMERNAME"
|
|
|
//+ ",CORPACC,CorpID,CUSTOMERNAME,null,null,null,null,null,null,BLNO"
|
|
|
+ ",CASE WHEN ISNULL(EMPLACC,'')<>'' then EMPLACC ELSE CORPACC END,case when isnull(EMPLID,'')<>'' then EMPLID else CorpID end,case when isnull(EMPLID,'')<>'' then EMPLID else CorpID end,null,null,null,null,null,null,left(BLNO,118) BLNO"//财务说不需要提单号字段的内容导入金蝶中
|
|
|
+ ",FCYNO,FCYEXRATE,DC,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO"
|
|
|
//+ ",FSETTLDATE"
|
|
|
+ ",PREPARED,null,null,null,null,ATTACHS,'False',null,'False',VOUNO"
|
|
|
+ ",null,null,null,null,null "
|
|
|
+ " from VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by ORDNO,ITEMNO";
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//iResult = 1;
|
|
|
sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
result.Message = execError.Message + sSql;
|
|
|
return result;
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_金蝶标准
|
|
|
public static DBResult setExcelReportGlBZ(string strCondition, string sPath)
|
|
|
{
|
|
|
|
|
|
var result = new DBResult();
|
|
|
string sName = "kisbz";
|
|
|
string sSql = "";
|
|
|
string filename = sPath + "\\kisbz.dbf";
|
|
|
if (!System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
result.Data = filename;
|
|
|
//
|
|
|
try
|
|
|
{
|
|
|
//string sSql = "delete from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName;
|
|
|
sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName;
|
|
|
bool bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//sSql = "insert into OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName + "("
|
|
|
sSql = "insert into OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName + "("
|
|
|
+ " FDATE,FPERIOD,FGROUP,FNUM,FENTRYID,FEXP,FACCTID,FCLSNAME1,FOBJID1,FOBJNAME1"
|
|
|
+ ",FCLSNAME2,FOBJID2,FOBJNAME2,FCLSNAME3,FOBJID3,FOBJNAME3,FCLSNAME4,FOBJID4,FOBJNAME4,FTRANSID"
|
|
|
+ ",FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO,FSETTLDATE"
|
|
|
+ ",FPREPARE,FPAY,FCASH,FPOSTER,FCHECKER,FATTCHMENT,FPOSTED,FMODULE,FDELETED,FSERIALNO"
|
|
|
+ ",FTRANSDATE,FCASHFLOW,FUNITNAME,FREFERENCE) "
|
|
|
+ "select "
|
|
|
+ " VouDate,AccMonth,VKNO,VOUNO,ROW_NUMBER() OVER ( PARTITION BY ORDNO ORDER BY ORDNO,ITEMNO )-1 as ITEMNO,left(ExPlan,118) ExPlan,ACCID,CORPACC,CorpID,CUSTOMERNAME"
|
|
|
+ ",CASE WHEN ISNULL(EMPLACC,'')<>'' then EMPLACC ELSE CORPACC END,case when isnull(EMPLID,'')<>'' then EMPLID else CorpID end,case when isnull(EMPLID,'')<>'' then EMPLID else CorpID end,null,null,null,null,null,null,BLNO"
|
|
|
+ ",FCYNO,FCYEXRATE,DC,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO,FSETTLDATE"
|
|
|
+ ",PREPARED,null,null,null,null,ATTACHS,'False',null,'False',VOUNO"
|
|
|
+ ",null,null,null,null "
|
|
|
+ " from VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by ORDNO,ITEMNO";
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//iResult = 1;
|
|
|
sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
//iResult = -1;//有异常,插入失败
|
|
|
result.Data = "-1";
|
|
|
result.Message = execError.Message + sSql;
|
|
|
return result;
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_金蝶标准
|
|
|
public static DBResult setExcelReportGlK32(string strCondition, string sPath)
|
|
|
{
|
|
|
|
|
|
var result = new DBResult();
|
|
|
string sSql = "";
|
|
|
string sName = "kisk32";
|
|
|
string filename = sPath + "\\kisk32.dbf";
|
|
|
if (!System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
result.Data = filename;
|
|
|
//
|
|
|
try
|
|
|
{
|
|
|
//string sSql = "delete from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName;
|
|
|
sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName;
|
|
|
bool bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//sSql = "insert into OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName + "("
|
|
|
sSql = "insert into OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName + "("
|
|
|
+ " FDATE,FPERIOD,FGROUP,FNUM,FENTRYID,FEXP,FACCTID,FCLSNAME1,FOBJID1,FOBJNAME1"
|
|
|
+ ",FCLSNAME2,FOBJID2,FOBJNAME2,FCLSNAME3,FOBJID3,FOBJNAME3,FCLSNAME4,FOBJID4,FOBJNAME4,FCLSNAME5,FOBJID5,FOBJNAME5,FCLSNAME6,FOBJID6,FOBJNAME6,FCLSNAME7,FOBJID7,FOBJNAME7,FCLSNAME8"
|
|
|
+ ",FOBJID8,FOBJNAME8,FOBJNAME9,FOBJID9,FCLSNAME9,FCLSNAME10,FOBJID10,FOBJNAME10,FCLSNAME11,FOBJID11"
|
|
|
+ ",FOBJNAME11,FCLSNAME12,FOBJID12,FOBJNAME12,FCLSNAME13,FOBJID13,FOBJNAME13,FCLSNAME14,FOBJID14,FOBJNAME14"
|
|
|
+ ",FCLSNAME15,FOBJID15,FOBJNAME15,FTRANSID"
|
|
|
+ ",FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO"
|
|
|
+ ",FPREPARE,FPAY,FCASH,FPOSTER,FCHECKER,FATTCHMENT,FPOSTED,FMODULE,FDELETED,FSERIALNO"
|
|
|
+ ",FTRANSDATE,FCASHFLOW,FUNITNAME,FREFERENCE) "
|
|
|
+ "select "
|
|
|
+ " VouDate,AccMonth,VKNO,VOUNO,ROW_NUMBER() OVER ( PARTITION BY ORDNO ORDER BY ORDNO,ITEMNO )-1 as ITEMNO,left(ExPlan,118) ExPlan,ACCID,CORPACC,CorpID,CUSTOMERNAME"
|
|
|
+ ",EMPLACC,EMPLID,EMPLID,null,null,null,null,null,null"
|
|
|
+ ",null,null,null,null,null,null,null,null,null,null"
|
|
|
+ ",null,null,null,null,null,null,null,null,null,null"
|
|
|
+ ",null,null,null,null,null,null,null,null,null,null"
|
|
|
+ ",null,null,null,BLNO"
|
|
|
+ ",FCYNO,FCYEXRATE,CASE WHEN DC='D' THEN '1' ELSE '0' END,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO"
|
|
|
+ ",PREPARED,null,null,null,null,ATTACHS,'False',null,'False',VOUNO"
|
|
|
+ ",VouDate,null,null,null "
|
|
|
+ " from VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by ORDNO,ITEMNO";
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//iResult = 1;
|
|
|
sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
result.Message = execError.Message + sSql;
|
|
|
return result;
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_金蝶K3
|
|
|
public static DBResult setExcelReportGlK3(string strCondition, string sPath)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
string sName = "kisk3";
|
|
|
string filename = sPath + "\\kisk3.dbf";
|
|
|
if (!System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
{
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
var sSql = "";
|
|
|
result.Data = filename;
|
|
|
//
|
|
|
try
|
|
|
{
|
|
|
//string sSql = "delete from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName;
|
|
|
sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName;
|
|
|
bool bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//sSql = "insert into OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName + "("
|
|
|
sSql = "insert into OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName + "("
|
|
|
+ " FDATE,FTRANSDATE,FPERIOD,FGROUP,FNUM,FENTRYID,FEXP,FACCTID,FCLSNAME1,FOBJID1,FOBJNAME1"
|
|
|
+ ",FCLSNAME2,FOBJID2,FOBJNAME2,FCLSNAME3,FOBJID3,FOBJNAME3,FCLSNAME4,FOBJID4,FOBJNAME4,FTRANSID"
|
|
|
+ ",FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO"
|
|
|
+ ",FPREPARE,FPAY,FCASH,FPOSTER,FCHECKER,FATTCHMENT,FPOSTED,FMODULE,FDELETED,FSERIALNO"
|
|
|
+ ",FCASHFLOW,FUNITNAME,FREFERENCE) "
|
|
|
+ "select "
|
|
|
+ " VouDate,VouDate,AccMonth,VKNO,VOUNO,ROW_NUMBER() OVER ( PARTITION BY ORDNO ORDER BY ORDNO,ITEMNO )-1 as ITEMNO,left(ExPlan,118) ExPlan,ACCID,CORPACC,CorpID,CUSTOMERNAME"
|
|
|
+ ",CASE WHEN ISNULL(EMPLACC,'')<>'' then EMPLACC ELSE CORPACC END,case when isnull(EMPLID,'')<>'' then EMPLID else CorpID end,case when isnull(EMPLID,'')<>'' then EMPLID else CorpID end,null,null,null,null,null,null,BLNO"
|
|
|
+ ",FCYNO,FCYEXRATE,DC,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO"
|
|
|
+ ",PREPARED,null,null,null,null,ATTACHS,'False',null,'False',VOUNO"
|
|
|
+ ",null,null,null "
|
|
|
+ " from VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by ORDNO,ITEMNO";
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//iResult = 1;
|
|
|
sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
//result.Data = "-1";
|
|
|
//result.Message = execError.Message + sSql;
|
|
|
result.Data = "-1";
|
|
|
result.Message = execError.Message + sSql;
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_用友U8
|
|
|
public static string setExcelReportGlU8(string strCondition, DataSet dsCwDesign, string path, string strCompanyID)
|
|
|
{
|
|
|
string filename = path + "\\U8" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
|
|
|
if (System.IO.File.Exists(filename))
|
|
|
{
|
|
|
System.IO.File.Delete(filename);
|
|
|
}
|
|
|
FileStream f = new FileStream(filename, FileMode.Create);
|
|
|
StreamWriter r = new StreamWriter(f, Encoding.Default);
|
|
|
//
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
string ls = "";
|
|
|
#region sSQL
|
|
|
string sSQL = "SELECT VOUNO, VKNO, CONVERT(varchar(10), VOUDATE, 120) AS VOUDATE, ACCYEAR, ACCMONTH, ATTACHS, FCY, QTY, VOUPROP, PREPARED, CHECKED, ENTERED, ERRMSG, ISDELETE, DELETEUSER, DELETETIME, VOUALLNO, ISEXPORT, GID, ORDNO, ITEMNO, ACCID, PACCID, ACCNAME, PROPERTY, GRADE, DC, AMTDR, AMTCR, ISFCY, FCYNO, FCYEXRATE, FCYDR, FCYCR, QTYUNIT, QTYDR, QTYCR, EXPLAN, ISDEPTACC, ISEMPLACC, ISCORPACC, ISITEMACC, DEPTID, EMPLID, CORPID, PITEMID, ITEMID, FIELD10, FIELD9, FIELD8, FIELD7, FIELD6, FIELD5, FIELD4, CORPID as FIELD3, FIELD2, FIELD1, ISSYS, FSETTLCODE, FSETTLENO,FSETTLDATE, MODIFIEDUSER, MODIFIEDTIME, CUSTOMERNAME, SALE, BLNO FROM VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by VOUALLNO,AMTDR DESC,ITEMNO";
|
|
|
#endregion
|
|
|
DataSet DS = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (DS != null)
|
|
|
{
|
|
|
string strCompanyName = T_ALL_DA.GetStrSQL("FULLNAME", "select top 1 FULLNAME from [company] where gid='" + strCompanyID + "'");
|
|
|
//
|
|
|
ls = "填制凭证,V800";
|
|
|
r.WriteLine(ls.Trim());
|
|
|
//用友U8 凭证导出 导出凭证
|
|
|
foreach (DataTable myTable in DS.Tables)
|
|
|
{
|
|
|
foreach (DataRow myRow in myTable.Rows)//遍历表
|
|
|
{
|
|
|
#region 整合字符串
|
|
|
ls = (myRow["VOUDATE"].ToString().Trim() == "" ? "" : ("\"" + myRow["VOUDATE"].ToString().Trim() + "\""));//F1日期
|
|
|
ls += "," + (myRow["VKNO"].ToString().Trim() == "" ? "" : ("\"" + myRow["VKNO"].ToString().Trim() + "\""));//F2类别
|
|
|
ls += "," + (myRow["VOUNO"].ToString().Trim() == "" ? "" : ("\"" + myRow["VOUNO"].ToString().Trim() + "\""));//F3凭证号
|
|
|
//ls += "," + (dsCwDesign.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim() == "" ? "0" : dsCwDesign.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim());//F4附单据数AFFIXNO
|
|
|
ls += "," + (myRow["ATTACHS"].ToString().Trim() == "" ? "0" : myRow["ATTACHS"].ToString().Trim());//F4附单据数
|
|
|
ls += "," + (myRow["EXPLAN"].ToString().Trim() == "" ? "" : ("\"" + myRow["EXPLAN"].ToString().Trim() + "\""));//F5摘要
|
|
|
ls += "," + (myRow["ACCID"].ToString().Trim() == "" ? "" : ("\"" + myRow["ACCID"].ToString().Trim() + "\""));//F6科目编码
|
|
|
ls += "," + myRow["AMTDR"].ToString().Trim();//F7借方
|
|
|
ls += "," + myRow["AMTCR"].ToString().Trim();//F8贷方
|
|
|
ls += ",0.00";// + myRow["FCYNO"].ToString().Trim();//F9数量/外币编号
|
|
|
//
|
|
|
if (myRow["FCYDR"].ToString().Trim() != "0.00" || myRow["FCYCR"].ToString().Trim() != "0.00")
|
|
|
{
|
|
|
ls += "," + ((myRow["FCYDR"].ToString().Trim() == "0.00" ? myRow["FCYCR"].ToString().Trim() : myRow["FCYDR"].ToString().Trim()));//F10外币
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ls += "," + ((myRow["AMTDR"].ToString().Trim() == "0.00" ? myRow["AMTCR"].ToString().Trim() : myRow["AMTDR"].ToString().Trim()));//F7借方//F8贷方
|
|
|
}
|
|
|
//
|
|
|
ls += "," + Decimal.Parse(myRow["FCYEXRATE"].ToString().Trim()).ToString("F4");//F11汇率
|
|
|
ls += "," + (myRow["PREPARED"].ToString().Trim() == "" ? "" : ("\"" + myRow["PREPARED"].ToString().Trim() + "\""));//F12制单人
|
|
|
ls += "," + (myRow["FSETTLCODE"].ToString().Trim() == "" ? "" : ("\"" + myRow["FSETTLCODE"].ToString().Trim() + "\"")); ;//F13结算方式
|
|
|
string sbl = "";
|
|
|
sbl = T_ALL_DA.GetStrSQL("gid", "select gid from cw_design_gl where AR='" + myRow["ACCID"].ToString().Trim() + "' or ARFC='" + myRow["ACCID"].ToString().Trim() + "' or AP='" + myRow["ACCID"].ToString().Trim() + "' or APFC='" + myRow["ACCID"].ToString().Trim() + "'");
|
|
|
if (sbl.Trim() == "")// && myRow["ACCID"].ToString().Trim() != "100206"
|
|
|
{
|
|
|
ls += ",";//F14票号
|
|
|
ls += ",";//F15发生日期
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ls += "," + (myRow["BLNO"].ToString().Trim() == "" ? "" : ("\"" + myRow["BLNO"].ToString().Trim() + "\""));//F14票号
|
|
|
ls += "," + (myRow["VOUDATE"].ToString().Trim() == "" ? "" : ("\"" + myRow["VOUDATE"].ToString().Trim() + "\""));//F15发生日期
|
|
|
}
|
|
|
//ls += ",";//F14票号
|
|
|
//ls += ",";//F15发生日期
|
|
|
ls += "," + (myRow["EMPLID"].ToString().Trim() == "" ? "" : ("\"" + myRow["EMPLID"].ToString().Trim() + "\""));//F17个人编码
|
|
|
ls += "," + (myRow["DEPTID"].ToString().Trim() == "" ? "" : ("\"" + myRow["DEPTID"].ToString().Trim() + "\""));//F16部门编码
|
|
|
|
|
|
ls += "," + (myRow["CORPID"].ToString().Trim() == "" ? "" : ("\"" + myRow["CORPID"].ToString().Trim() + "\""));//F18客户编码
|
|
|
ls += "," + (myRow["FIELD3"].ToString().Trim() == "" ? "" : ("\"" + myRow["FIELD3"].ToString().Trim() + "\"")); ;//F19供应商编码 FIELD3
|
|
|
ls += ",";//F20业务员
|
|
|
ls += "," + (myRow["ITEMID"].ToString().Trim() == "" ? "" : ("\"" + myRow["ITEMID"].ToString().Trim() + "\"")); ;//F21项目编码
|
|
|
ls += ",";//F22自定义项
|
|
|
ls += ",";//F23自定义项2
|
|
|
ls += ",";//F24自由项1
|
|
|
ls += ",";//F25自由项2
|
|
|
ls += ",";//F26自由项3
|
|
|
ls += ",";//F27自由项4
|
|
|
ls += ",0";//F28自由项5
|
|
|
ls += ",";//F29自由项6
|
|
|
ls += ",0.00";//F30自由项7
|
|
|
ls += ",";//F31自由项8
|
|
|
ls += ",";//F32自由项9
|
|
|
ls += ",";//F33自由项10
|
|
|
ls += ",";//F34外部系统标识
|
|
|
ls += ",";//F35业务类型
|
|
|
ls += ",";//F36单据类型
|
|
|
ls += ",";//F37单据日期
|
|
|
ls += ",";//F38单据号
|
|
|
ls += "," + (dsCwDesign.Tables[0].Rows[0]["ISVBM"].ToString().Trim().Equals("True") ? "0" : "1");//F39凭证是否可改
|
|
|
ls += ",1";//F40分录是否可增删
|
|
|
ls += ",1";//F41合计金额是否保值
|
|
|
ls += ",1";//F42数值是否可改
|
|
|
ls += ",1";//F43科目是否可改
|
|
|
ls += ",";//F44受控科目
|
|
|
ls += ",1";//F45往来是否可改
|
|
|
ls += ",1";//F46部门是否可改
|
|
|
ls += ",1";//F47项目是否可改
|
|
|
ls += ",0";//F48往来项是否必输
|
|
|
ls += ",";//F49账套号
|
|
|
ls += ",";//F50核算单位
|
|
|
ls += ",";//F51会计年度
|
|
|
ls += ",";//F52会计期间
|
|
|
ls += ",";//F53类别顺序号
|
|
|
ls += ",";//F54凭证号
|
|
|
ls += ",";//F55审核人
|
|
|
ls += ",";//F56记账人
|
|
|
ls += ",0";//F57是否记账
|
|
|
ls += ",";//F58出纳人
|
|
|
ls += ",";//F59行号
|
|
|
ls += ",";//F60外币名称
|
|
|
ls += ",0.00";//F61单价
|
|
|
ls += ",";//F62科目名称
|
|
|
ls += ",";//F63部门名称
|
|
|
ls += ",";//F64个人名称
|
|
|
ls += "," + (myRow["CUSTOMERNAME"].ToString().Trim() == "" ? "" : ("\"" + myRow["CUSTOMERNAME"].ToString().Trim() + "\""));//F65客户简称
|
|
|
ls += ",";//F66供应商简称
|
|
|
ls += ",";//F67项目名称
|
|
|
ls += ",";//F68项目大类编码
|
|
|
ls += ",";//F69项目大类名称
|
|
|
ls += ",";//F70对方科目
|
|
|
ls += ",0";//F71银行两清标志
|
|
|
ls += ",0";//F72往来两清标志
|
|
|
ls += ",0";//F73银行核销标志
|
|
|
ls += ",";//F74外部系统名称
|
|
|
ls += ",";//F75外部账套号
|
|
|
ls += ",0";//F76外部会计年度
|
|
|
ls += ",0";//F77外部会计期间
|
|
|
ls += ",";//F78外部制单日期
|
|
|
ls += ",";//F79外部系统版本
|
|
|
ls += ",";//F80凭证标识
|
|
|
ls += ",";//F81分录自动编号
|
|
|
ls += ",";//F82唯一标识
|
|
|
ls += ",";//F83主管签字
|
|
|
ls += ",";//F84自由项11
|
|
|
ls += ",";//F85自由项12
|
|
|
ls += ",";//F86自由项13
|
|
|
ls += ",";//F87自由项14
|
|
|
ls += ",0";//F88自由项15
|
|
|
ls += ",0.00";//F89自由项16
|
|
|
#endregion
|
|
|
r.WriteLine(ls);
|
|
|
}
|
|
|
}
|
|
|
//标记已经导出凭证
|
|
|
string sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSql);
|
|
|
r.Close();
|
|
|
f.Close();
|
|
|
}
|
|
|
return filename;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_用友NC
|
|
|
public static string setExcelReportGlNC(string strCondition, DataSet dsCwDesign, string path, string strCompanyID)
|
|
|
{
|
|
|
string filename = path + "\\NC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
|
|
|
if (System.IO.File.Exists(filename))
|
|
|
{
|
|
|
System.IO.File.Delete(filename);
|
|
|
}
|
|
|
FileStream f = new FileStream(filename, FileMode.Create);
|
|
|
StreamWriter r = new StreamWriter(f, Encoding.Default);
|
|
|
//
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
string ls = "";
|
|
|
#region sSQL
|
|
|
string sSQL = "SELECT ROW_NUMBER() OVER (ORDER BY ACCID) AS RowNumber,'0010100011801-0001','01' pzlb,VOUNO,'0' fdjs, PREPARED, ";//0-5
|
|
|
sSQL = sSQL + " CONVERT(varchar(10), VOUDATE, 120) AS VOUDATE, EXPLAN,ACCID,'人民币' bz, "; //6-9
|
|
|
sSQL = sSQL + " FCYDR,AMTDR,'' jtbbj,'' qjbbj,'01120' ywdybm,'' dj,'' jfsl,'' dfsl, ";//10-17
|
|
|
sSQL = sSQL + " FCYCR,AMTCR,'' _20,'' _21,BLNO,'' _23,'' _24, CONVERT(varchar(10), VOUDATE, 120) AS BSDATE, ";//18-25
|
|
|
sSQL = sSQL + " '' _26,'' _27,'' _28,'' _29,'' _30,'' _31,'' _32,'' _33,'' _34,'' _35,'' _36, ";//26-36
|
|
|
sSQL = sSQL + " '1' _37,'' _38,'' _39,";//37-39
|
|
|
sSQL = sSQL + " FIELD1, FIELD2, FIELD3, FIELD4, FIELD5, FIELD6, FIELD7, FIELD8, FIELD9";
|
|
|
sSQL = sSQL + " FROM VW_cw_vouchers_vouitems_gl where 1=1" + strCondition;
|
|
|
sSQL = sSQL + " order by ACCID ";
|
|
|
#endregion
|
|
|
DataSet DS = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (DS != null)
|
|
|
{
|
|
|
string strCompanyName = T_ALL_DA.GetStrSQL("FULLNAME", "select top 1 FULLNAME from [company] where gid='" + strCompanyID + "'");
|
|
|
// //
|
|
|
ls = "\"null_$head,main_m_pk_accountingbook,main_m_pk_vouchertype,main_m_num,main_m_attachment,main_pk_prepared,main_m_prepareddate,m_explanation,m_accsubjcode,m_pk_currtype,m_debitamount,m_localdebitamount,m_groupdebitamount,m_globaldebitamount,unitname,m_price,m_debitquantity,m_creditquantity,m_creditamount,m_localcreditamount,m_groupcreditamount,m_globalcreditamount,m_checkno,m_checkdate,verifyno,verifydate,m_bankaccount,billtype,m_checkstyle,vat_pk_vatcountry,vat_pk_receivecountry,vat_businesscode,vat_pk_clientvatcode,vat_pk_suppliervatcode,vat_pk_taxcode,vat_direction,vat_moneyamount,m_excrate2,excrate3,excrate4,ass_1,ass_2,ass_3,ass_4,ass_5,ass_6,ass_7,ass_8,ass_9\"\t核算账簿\t凭证类别编码 凭证号 附单据数 制单人编码 制单日期 摘要 科目编码 币种 原币借方金额 本币借方金额 集团本币借方金额 全局本币借方金额 业务单元编码 单价 借方数量 贷方数量 原币贷方金额 本币贷方金额 集团本币贷方金额 全局本币贷方金额 结算号 结算日期 核销号 业务日期 银行账户 票据类型 结算方式 报税国家 收货国 交易代码 客户VAT注册码 供应商VAT注册码 税码 VAT方向 计税金额 组织本币汇率 集团本币汇率 全局本币汇率 辅助核算1 辅助核算2 辅助核算3 辅助核算4 辅助核算5 辅助核算6 辅助核算7 辅助核算8 辅助核算9";
|
|
|
ls = ls.Replace(" ", "\t");
|
|
|
r.WriteLine(ls.Trim());
|
|
|
//用友U8 凭证导出 导出凭证
|
|
|
var linenum = 0;
|
|
|
foreach (DataTable myTable in DS.Tables)
|
|
|
{
|
|
|
foreach (DataRow myRow in myTable.Rows)//遍历表
|
|
|
{
|
|
|
linenum++;
|
|
|
ls = linenum.ToString();//0列 行号
|
|
|
#region ls
|
|
|
ls += "\t" + "0010100011801-0001";//1列 "核算账簿 推测是帐套号"
|
|
|
ls += "\t" + "1";//2列 凭证类别编码
|
|
|
ls += "\t";//3列 凭证号 自动生成
|
|
|
ls += "\t" + "0";//F4附单据数
|
|
|
ls += "\t" + (myRow["PREPARED"].ToString().Trim() == "" ? "" : ("\"" + myRow["PREPARED"].ToString().Trim() + "\""));//5 制单人
|
|
|
ls += "\t" + (myRow["VOUDATE"].ToString().Trim() == "" ? "" : ("\"" + myRow["VOUDATE"].ToString().Trim() + "\""));//6 制单日期
|
|
|
ls += "\t" + (myRow["EXPLAN"].ToString().Trim() == "" ? "" : ("\"" + myRow["EXPLAN"].ToString().Trim() + "\""));// 7 摘要
|
|
|
ls += "\t" + myRow["ACCID"].ToString().Trim();//8 科目编码
|
|
|
ls += "\t" + "人民币";//9 币种
|
|
|
ls += "\t" + myRow["FCYDR"].ToString().Trim();//10 原币借方
|
|
|
ls += "\t" + myRow["AMTDR"].ToString().Trim();//11 本币借方
|
|
|
ls += "\t";//集团本币借方金额
|
|
|
ls += "\t";//全局本币借方金额
|
|
|
ls += "\t" + "01120";//业务单元编码14
|
|
|
ls += "\t";//单价15
|
|
|
ls += "\t";//借方数量16
|
|
|
ls += "\t";//贷方数量17
|
|
|
ls += "\t" + myRow["FCYCR"].ToString().Trim(); ;//原币贷方金额18
|
|
|
ls += "\t" + myRow["AMTCR"].ToString().Trim();//本币贷方金额19
|
|
|
ls += "\t";//集团本币贷方金额 20
|
|
|
ls += "\t";//全局本币贷方金额21
|
|
|
ls += "\t";//结算号22//此处放置支票号
|
|
|
ls += "\t";//结算日期23
|
|
|
ls += "\t";//核销号24
|
|
|
ls += "\t" + (myRow["VOUDATE"].ToString().Trim() == "" ? "" : ("\"" + myRow["VOUDATE"].ToString().Trim() + "\"")); ;//业务日期25
|
|
|
ls += "\t";//银行账户26
|
|
|
ls += "\t";//票据类型27
|
|
|
ls += "\t";//结算方式
|
|
|
ls += "\t";//报税国家
|
|
|
ls += "\t";//收货国30
|
|
|
ls += "\t";//交易代码
|
|
|
ls += "\t";//客户VAT注册码
|
|
|
ls += "\t";//供应商VAT注册码
|
|
|
ls += "\t";//税码
|
|
|
ls += "\t";//VAT方向35
|
|
|
ls += "\t";//计税金额
|
|
|
ls += "\t" + "1";//组织本币汇率37
|
|
|
ls += "\t";//集团本币汇率
|
|
|
ls += "\t";//全局本币汇率
|
|
|
ls += "\t" + myRow["FIELD1"].ToString().Trim(); //辅助核算1 40
|
|
|
ls += "\t" + myRow["FIELD2"].ToString().Trim();//辅助核算2
|
|
|
ls += "\t" + myRow["FIELD3"].ToString().Trim();//辅助核算3
|
|
|
ls += "\t" + myRow["FIELD4"].ToString().Trim();//辅助核算4
|
|
|
ls += "\t" + myRow["FIELD5"].ToString().Trim();//辅助核算5
|
|
|
ls += "\t" + myRow["FIELD6"].ToString().Trim();//辅助核算6
|
|
|
ls += "\t" + myRow["FIELD7"].ToString().Trim();//辅助核算7
|
|
|
ls += "\t" + myRow["FIELD8"].ToString().Trim();//辅助核算8
|
|
|
ls += "\t" + myRow["FIELD9"].ToString().Trim();//辅助核算9 48
|
|
|
//共49列
|
|
|
#endregion
|
|
|
r.WriteLine(ls);
|
|
|
}
|
|
|
}
|
|
|
////////////////////////////////////
|
|
|
//标记已经导出凭证
|
|
|
string sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSql);
|
|
|
//
|
|
|
r.Close();
|
|
|
f.Close();
|
|
|
}
|
|
|
return filename;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_金蝶专业版
|
|
|
public static DBResult setExcelReportGlZY(string strCondition, string sPath)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
string sSql = "";
|
|
|
string sName = "kiszy";// +DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
string filename = sPath + "//" + sName + ".dbf";
|
|
|
if (!System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
result.Data = filename;
|
|
|
//
|
|
|
//if (System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
//{
|
|
|
// System.IO.File.Delete(filename);
|
|
|
//}
|
|
|
//string oldFilename = oldPath + "//" + "kiszy.dbf";
|
|
|
//File.Copy(@oldFilename, @filename, true);
|
|
|
//
|
|
|
try
|
|
|
{
|
|
|
//string sSql = "delete from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName;
|
|
|
//sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName;
|
|
|
|
|
|
//bool bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
bool bl = true;
|
|
|
if (bl)
|
|
|
{
|
|
|
//sSql = "insert into OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName + "("
|
|
|
sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName
|
|
|
+" insert into OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName + "("
|
|
|
+ " FDATE,FTRANSDATE,FPERIOD,FGROUP,FNUM,FENTRYID,FEXP,FACCTID"
|
|
|
+ ",FCLSNAME1,FOBJID1,FOBJNAME1,FCLSNAME2,FOBJID2,FOBJNAME2,FCLSNAME3,FOBJID3,FOBJNAME3,FCLSNAME4,FOBJID4,FOBJNAME4"
|
|
|
+ ",FCLSNAME5,FOBJID5,FOBJNAME5,FCLSNAME6,FOBJID6,FOBJNAME6,FCLSNAME7,FOBJID7,FOBJNAME7,FCLSNAME8,FOBJID8,FOBJNAME8"
|
|
|
+ ",FCLSNAME9,FOBJID9,FOBJNAME9,FCLSNAME10,FOBJID10,FOBJNAME10,FCLSNAME11,FOBJID11,FOBJNAME11,FCLSNAME12,FOBJID12,FOBJNAME12"
|
|
|
+ ",FCLSNAME13,FOBJID13,FOBJNAME13,FCLSNAME14,FOBJID14,FOBJNAME14,FCLSNAME15,FOBJID15,FOBJNAME15"
|
|
|
// + ",FTRANSID,FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO,FSETTLDATE"
|
|
|
+ ",FTRANSID,FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO"
|
|
|
+ ",FPREPARE,FPAY,FCASH,FPOSTER,FCHECKER,FATTCHMENT,FPOSTED,FMODULE,FDELETED,FSERIALNO"
|
|
|
+ ",FUNITNAME,FREFERENCE,FCASHFLOW,FHANDLER) "
|
|
|
+ "select "
|
|
|
+ " VouDate,VouDate,AccMonth,VKNO,VOUNO,ROW_NUMBER() OVER ( PARTITION BY ORDNO ORDER BY ORDNO,ITEMNO )-1 as ITEMNO,left(ExPlan,118) ExPlan,ACCID"
|
|
|
+ ",CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTACC ELSE CORPACC END,CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTID ELSE CorpID END,CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTNAME ELSE CUSTOMERNAME END"
|
|
|
+ ",CASE WHEN ISNULL(EMPLACC,'')<>'' then EMPLACC ELSE '' END,case when isnull(EMPLID,'')<>'' then EMPLID else '' end,case when isnull(EMPLID,'')<>'' then EMPLID else '' end,null,null,null,null,null,null"
|
|
|
+ ",null,null,null,null,null,null,null,null,null,null,null,null"
|
|
|
+ ",null,null,null,null,null,null,null,null,null,null,null,null"
|
|
|
+ ",null,null,null,null,null,null,null,null,null"
|
|
|
// + ",BLNO,FCYNO,FCYEXRATE,DC,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO,FSETTLDATE"
|
|
|
+ ",BLNO,FCYNO,FCYEXRATE,CASE WHEN DC='D' THEN '1' ELSE CASE WHEN DC='C' THEN '0' ELSE DC END END,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO"
|
|
|
+ ",PREPARED,null,null,null,null,ATTACHS,'False',null,'False',VOUNO"
|
|
|
+ ",null,null,null,null "
|
|
|
+ " from VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by ORDNO,ITEMNO";
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//iResult = 1;
|
|
|
sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iResult = -1;
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iResult = -1;
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
//iResult = -1;//有异常,插入失败
|
|
|
result.Data = "-1";
|
|
|
result.Message = execError.Message+ sSql;
|
|
|
return result;
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static DBResult setExcelReportGlZY2(string strCondition, string sPath)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
string sSql = "";
|
|
|
string sName = "kiszy";// +DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
string filename = sPath + "//" + sName + ".dbf";
|
|
|
if (!System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
result.Data = filename;
|
|
|
//
|
|
|
//if (System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
//{
|
|
|
// System.IO.File.Delete(filename);
|
|
|
//}
|
|
|
//string oldFilename = oldPath + "//" + "kiszy.dbf";
|
|
|
//File.Copy(@oldFilename, @filename, true);
|
|
|
//
|
|
|
try
|
|
|
{
|
|
|
//string sSql = "delete from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName;
|
|
|
//sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName;
|
|
|
|
|
|
//bool bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
bool bl = true;
|
|
|
if (bl)
|
|
|
{
|
|
|
//sSql = "insert into OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=" + sPath + ";Extended Properties=dBASE IV;User ID=Admin;Password=')..." + sName + "("
|
|
|
sSql = "delete from OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName
|
|
|
+ " insert into OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=" + sPath + ";Extended Properties=dBASE 5.0;User ID=Admin;Password=')..." + sName + "("
|
|
|
+ " FDATE,FPERIOD,FGROUP,FNUM,FENTRYID,FEXP,FACCTID"
|
|
|
+ ",FCLSNAME1,FOBJID1,FOBJNAME1,FCLSNAME2,FOBJID2,FOBJNAME2,FCLSNAME3,FOBJID3,FOBJNAME3,FCLSNAME4,FOBJID4,FOBJNAME4"
|
|
|
|
|
|
// + ",FTRANSID,FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO,FSETTLDATE"
|
|
|
+ ",FTRANSID,FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO"
|
|
|
+ ",FPREPARE,FPAY,FCASH,FPOSTER,FCHECKER,FATTCHMENT,FPOSTED,FMODULE,FDELETED,FSERIALNO,FTRANSDATE"
|
|
|
+ ",FUNITNAME,FREFERENCE,FCASHFLOW) "
|
|
|
+ "select "
|
|
|
+ " VouDate,AccMonth,VKNO,VOUNO,ROW_NUMBER() OVER ( PARTITION BY ORDNO ORDER BY ORDNO,ITEMNO )-1 as ITEMNO,left(ExPlan,118) ExPlan,ACCID"
|
|
|
+ ",CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTACC ELSE CORPACC END,CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTID ELSE CorpID END,CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTNAME ELSE CUSTOMERNAME END"
|
|
|
+ ",CASE WHEN ISNULL(EMPLACC,'')<>'' then EMPLACC ELSE '' END,case when isnull(EMPLID,'')<>'' then EMPLID else '' end,case when isnull(EMPLID,'')<>'' then EMPLID else '' end,null,null,null,null,null,null"
|
|
|
// + ",BLNO,FCYNO,FCYEXRATE,DC,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO,FSETTLDATE"
|
|
|
+ ",BLNO,FCYNO,FCYEXRATE,CASE WHEN DC='D' THEN '1' ELSE CASE WHEN DC='C' THEN '0' ELSE DC END END,(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT,null,0,AMTDR,AMTCR,FSETTLCODE,FSETTLENO"
|
|
|
+ ",PREPARED,null,null,null,null,ATTACHS,'False',null,'False',VOUNO,VouDate"
|
|
|
+ ",null,null,null "
|
|
|
+ " from VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by ORDNO,ITEMNO";
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
if (bl)
|
|
|
{
|
|
|
//iResult = 1;
|
|
|
sSql = " update cw_vouchers_gl set ISEXPORT=1 where 1=1" + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
bl = SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iResult = -1;
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//iResult = -1;
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
//iResult = -1;//有异常,插入失败
|
|
|
result.Data = "-1";
|
|
|
result.Message = execError.Message + sSql;
|
|
|
return result;
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出金蝶云接口
|
|
|
|
|
|
static public string GetCurrencyCode(string Curr)
|
|
|
{
|
|
|
string EDICODE = "";
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("select FINANCESOFTCODE from code_currency where CODENAME='" + Curr + "'");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
EDICODE = Convert.ToString(reader["FINANCESOFTCODE"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
if (EDICODE == "") EDICODE = Curr;
|
|
|
|
|
|
|
|
|
return EDICODE;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static DBResult setExcelReportGlJDYUN(string strCondition, string userid, string usercode, string companyid, string strCwSTARTGID)
|
|
|
{
|
|
|
|
|
|
var result = new DBResult();
|
|
|
string sSql = "";
|
|
|
var dataList = MsCwVouchersGlDAL.GetDataListHJ(0, 1000, strCondition, userid, usercode, companyid, strCwSTARTGID);
|
|
|
if (dataList.Count == 0) {
|
|
|
result.Success = false;
|
|
|
result.Message = "没有要导出的数据!";
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
var JDURL = MsSysParamSet.MsSysParamSetDAL.GetData("PARAMNAME='JDYUNURL'").PARAMVALUE;
|
|
|
var JDID = MsSysParamSet.MsSysParamSetDAL.GetData("PARAMNAME='JDYUNID'").PARAMVALUE;
|
|
|
var user = SysUserDAL.GetData("U.GID='"+ userid + "'");
|
|
|
var JDYUNUSER = user.CWUSERNAME;
|
|
|
var JDYUNPASS = user.CWPASSWORD;
|
|
|
if (JDURL == "" || JDYUNUSER == "" || JDYUNPASS == "") {
|
|
|
result.Success = false;
|
|
|
result.Message = "请在参数设置中设置 金蝶云的URL、账套ID、用户名和密码!";
|
|
|
return result;
|
|
|
}
|
|
|
var CwStart= MsCwDesignStartusingDAL.MsCwDesignStartusingDAL.GetData("GID='"+ strCwSTARTGID + "'", companyid, userid);
|
|
|
// JDID = CwStart.FINANCESOFTCODE;
|
|
|
K3CloudApiClient client = new K3CloudApiClient(JDURL);
|
|
|
var loginResult = client.ValidateLogin(JDID, JDYUNUSER, JDYUNPASS, 2052);
|
|
|
var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
|
|
|
//登录结果类型等于1,代表登录成功
|
|
|
if (resultType == 1)
|
|
|
{
|
|
|
JDVoucher Voucher = new JDVoucher();
|
|
|
Voucher.IsDeleteEntry = true;
|
|
|
Voucher.IsVerifyBaseDataField = false;
|
|
|
Voucher.SubSystemId = "";
|
|
|
Voucher.IsEntryBatchFill = true;
|
|
|
Voucher.ValidateFlag = true;
|
|
|
Voucher.NumberSearch = true;
|
|
|
Voucher.IsAutoSubmitAndAudit = false;
|
|
|
Voucher.NeedUpDateFields = new List<string>();
|
|
|
Voucher.NeedReturnFields = new List<string>();
|
|
|
Voucher.InterationFlags = "";
|
|
|
|
|
|
var VoucherDetailList = new List<VoucherDetail>();
|
|
|
foreach (var vou in dataList)
|
|
|
{
|
|
|
|
|
|
VoucherDetail VoucherDetail = new VoucherDetail();
|
|
|
VoucherDetail.FVOUCHERID = 0;
|
|
|
VoucherDetail.FAccountBookID = new JDFNumber { FNumber = CwStart.FINANCESOFTCODE };
|
|
|
VoucherDetail.FDate = vou.VOUDATE;
|
|
|
VoucherDetail.FBUSDATE = vou.VOUDATE;
|
|
|
VoucherDetail.FVOUCHERGROUPID = new JDFNumber { FNumber = "PRE001" };
|
|
|
VoucherDetail.FVOUCHERGROUPNO = "1";
|
|
|
VoucherDetail.FYEAR =Convert.ToInt16(vou.ACCYEAR);
|
|
|
VoucherDetail.FDocumentStatus = "Z";
|
|
|
VoucherDetail.FISADJUSTVOUCHER = false;
|
|
|
VoucherDetail.FPERIOD = Convert.ToInt16(vou.ACCMONTH);
|
|
|
VoucherDetail.FSourceBillKey = new JDFNumber { FNumber = "" };
|
|
|
var voudetaildataList = MsCwVouchersGlDAL.GetDataCwVVList(0, 1000,"ORDNO='"+vou.ORDNO+"'", userid, usercode, companyid, strCwSTARTGID);
|
|
|
var vouitemsList = new List<JDVouitems>();
|
|
|
foreach (var voudetail in voudetaildataList)
|
|
|
{
|
|
|
JDVouitems vouitems = new JDVouitems();
|
|
|
vouitems.FEXPLANATION = voudetail.EXPLAN;
|
|
|
vouitems.FACCOUNTID = new JDFNumber { FNumber = voudetail.ACCID };
|
|
|
vouitems.FCURRENCYID = new JDFNumber { FNumber = GetCurrencyCode(voudetail.FCYNO) };
|
|
|
vouitems.FEXCHANGERATETYPE = new JDFNumber { FNumber = "HLTX01_SYS" };
|
|
|
if (voudetail.CORPID!="")
|
|
|
vouitems.FDetailID = new JDFDetailID { FDETAILID__FFLEX6 = new JDFNumber { FNumber = voudetail.CORPID }, FDETAILID__FFLEX4 = new JDFNumber { FNumber = voudetail.CORPID } };
|
|
|
vouitems.FEXCHANGERATE = voudetail.FCYEXRATE;
|
|
|
if (voudetail.FCYNO != "RMB")
|
|
|
{
|
|
|
if (voudetail.FCYDR != 0)
|
|
|
{
|
|
|
vouitems.FAMOUNTFOR = voudetail.FCYDR;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
vouitems.FAMOUNTFOR = voudetail.FCYCR;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
if (voudetail.AMTCR != 0)
|
|
|
{
|
|
|
vouitems.FAMOUNTFOR = voudetail.AMTCR;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
vouitems.FAMOUNTFOR = voudetail.AMTDR;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (voudetail.AMTCR != 0)
|
|
|
{
|
|
|
vouitems.FCREDIT = voudetail.AMTCR;
|
|
|
}
|
|
|
else {
|
|
|
vouitems.FDEBIT = voudetail.AMTDR;
|
|
|
|
|
|
}
|
|
|
vouitemsList.Add(vouitems);
|
|
|
}
|
|
|
VoucherDetail.FEntity = vouitemsList;
|
|
|
VoucherDetailList.Add(VoucherDetail);
|
|
|
}
|
|
|
Voucher.Model = VoucherDetailList;
|
|
|
|
|
|
var resultstr = JsonConvert.SerializeObject(Voucher);
|
|
|
var loginResult2 = client.BatchSave("GL_VOUCHER", JsonConvert.SerializeObject(Voucher));
|
|
|
var Resultstr = JsonConvert.DeserializeObject<JDResultData>(loginResult2);
|
|
|
if (Resultstr.Result.ResponseStatus.IsSuccess)
|
|
|
{
|
|
|
sSql = " update cw_vouchers_gl set ISEXPORT=1 where " + strCondition.Replace("ACCDATE", "(ACCYEAR+'-'+ACCMONTH)");
|
|
|
SqlHelper.ExecuteSql(SqlHelper.ConnectionStringLocalTransaction, sSql);
|
|
|
result.Success = true;
|
|
|
result.Message = "导出成功";
|
|
|
}
|
|
|
else {
|
|
|
var errstr = "";
|
|
|
var errorlist = Resultstr.Result.ResponseStatus.Errors;
|
|
|
foreach (var error in errorlist)
|
|
|
{
|
|
|
errstr = errstr + error.FieldName + " " + error.Message;
|
|
|
|
|
|
}
|
|
|
result.Success = false;
|
|
|
result.Message = "导出错误"+errstr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
result.Success = false;
|
|
|
result.Message = "登陆金蝶云失败";
|
|
|
}
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 导出接口_11_金蝶K3WISE
|
|
|
|
|
|
|
|
|
private static readonly string[] FieldArray = { "FDATE","FTRANSDATE","FPERIOD","FGROUP","FNUM","FENTRYID","FEXP","FACCTID"
|
|
|
,"FCLSNAME1","FOBJID1","FOBJNAME1","FCLSNAME2","FOBJID2","FOBJNAME2","FCLSNAME3","FOBJID3","FOBJNAME3","FCLSNAME4","FOBJID4","FOBJNAME4"
|
|
|
,"FCLSNAME5","FOBJID5","FOBJNAME5","FCLSNAME6","FOBJID6","FOBJNAME6","FCLSNAME7","FOBJID7","FOBJNAME7","FCLSNAME8","FOBJID8","FOBJNAME8"
|
|
|
,"FCLSNAME9","FOBJID9","FOBJNAME9","FCLSNAME10","FOBJID10","FOBJNAME10","FCLSNAME11","FOBJID11","FOBJNAME11"
|
|
|
,"FCLSNAME12","FOBJID12","FOBJNAME12"
|
|
|
,"FCLSNAME13","FOBJID13","FOBJNAME13","FCLSNAME14","FOBJID14","FOBJNAME14","FCLSNAME15","FOBJID15","FOBJNAME15"
|
|
|
,"FTRANSID","FCYID","FEXCHRATE","FDC","FFCYAMT","FQTY","FPRICE","FDEBIT","FCREDIT","FSETTLCODE","FSETTLENO"
|
|
|
,"FPREPARE","FPAY","FCASH","FPOSTER","FCHECKER","FATTCHMENT","FPOSTED","FMODULE","FDELETED","FSERIALNO"
|
|
|
,"FUNITNAME","FREFERENCE","FCASHFLOW","FHANDLER" };
|
|
|
|
|
|
private static readonly string[] DS7FieldArray = { "VouDate,VouDate,AccMonth,VKNO,VOUNO" };
|
|
|
|
|
|
public static DBResult setExcelReportGlK3wise(string strCondition, string sPath)
|
|
|
{
|
|
|
//H:\DS7发布版2019\ToolProject\FastDBF\K3WISEModel_20210520.dbf
|
|
|
|
|
|
var modelPath = sPath + "/K3WISEModel_20210520.dbf";
|
|
|
|
|
|
var result = new DBResult();
|
|
|
string sSql = "";
|
|
|
string sName = "K3WISE";// +DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
string filename = sPath + "//" + sName + ".dbf";
|
|
|
//if (!System.IO.File.Exists(filename))//判断文件是否寸在
|
|
|
//{
|
|
|
// return result;
|
|
|
//}
|
|
|
File.Copy(modelPath, filename, true);//三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
|
|
|
//复制一个模板出来 然后在其中写入
|
|
|
result.Data = filename;
|
|
|
|
|
|
|
|
|
//获取一个DBF文件对象
|
|
|
DbfFile dbf = new DbfFile(Encoding.Default);
|
|
|
dbf.Open(filename, FileMode.Open);
|
|
|
|
|
|
//计数器 看赋值时在第几个字段出错
|
|
|
var _i = 0;
|
|
|
var itemvalue = "";
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
bool bl = true;
|
|
|
if (bl)
|
|
|
{
|
|
|
|
|
|
sSql = ""//"select "
|
|
|
//+ " FDATE,FTRANSDATE,FPERIOD,FGROUP,FNUM,FENTRYID,FEXP,FACCTID"
|
|
|
//+ ",FCLSNAME1,FOBJID1,FOBJNAME1,FCLSNAME2,FOBJID2,FOBJNAME2,FCLSNAME3,FOBJID3,FOBJNAME3,FCLSNAME4,FOBJID4,FOBJNAME4"
|
|
|
//+ ",FCLSNAME5,FOBJID5,FOBJNAME5,FCLSNAME6,FOBJID6,FOBJNAME6,FCLSNAME7,FOBJID7,FOBJNAME7,FCLSNAME8,FOBJID8,FOBJNAME8"
|
|
|
//+ ",FCLSNAME9,FOBJID9,FOBJNAME9,FCLSNAME10,FOBJID10,FOBJNAME10,FCLSNAME11,FOBJID11,FOBJNAME11,FCLSNAME12,FOBJID12,FOBJNAME12"
|
|
|
//+ ",FCLSNAME13,FOBJID13,FOBJNAME13,FCLSNAME14,FOBJID14,FOBJNAME14,FCLSNAME15,FOBJID15,FOBJNAME15"
|
|
|
//+ ",FTRANSID,FCYID,FEXCHRATE,FDC,FFCYAMT,FQTY,FPRICE,FDEBIT,FCREDIT,FSETTLCODE,FSETTLENO"
|
|
|
//+ ",FPREPARE,FPAY,FCASH,FPOSTER,FCHECKER,FATTCHMENT,FPOSTED,FMODULE,FDELETED,FSERIALNO"
|
|
|
//+ ",FUNITNAME,FREFERENCE,FCASHFLOW,FHANDLER) "
|
|
|
+ "select "
|
|
|
+ " VouDate,VouDate,AccMonth,VKNO,VOUNO,ROW_NUMBER() OVER ( PARTITION BY ORDNO ORDER BY ORDNO,ITEMNO )-1 as ITEMNO" //0-5
|
|
|
+ ",left(ExPlan,118) ExPlan,ACCID"//6 FEXP 7FACCTID
|
|
|
+ ",CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTACC ELSE CORPACC END" //8 FLSNAME1
|
|
|
+ ",CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTID ELSE CorpID END" //9 FOBJID1
|
|
|
+ ",CASE WHEN ISNULL(CORPACC,'')='' THEN DEPTNAME ELSE (select top 1 BillRises1 from info_client where shortname=CUSTOMERNAME) END" //10 FOBJNAME1
|
|
|
+ ",CASE WHEN ISNULL(EMPLACC,'')<>'' then EMPLACC ELSE '' END" //11
|
|
|
+ ",case when isnull(EMPLID,'')<>'' then EMPLID else '' end"//12
|
|
|
+ ",case when isnull(EMPLID,'')<>'' then EMPLID else '' end"//13
|
|
|
+ ",null,null,null,null,null,null"//14-19
|
|
|
+ ",null,null,null,null,null,null,null,null,null,null,null,null"//20-31
|
|
|
+ ",null,null,null,null,null,null,null,null,null,null,null,null"//32-43
|
|
|
+ ",null,null,null,null,null,null,null,null,null"//44-52
|
|
|
+ ",BLNO"//53
|
|
|
+ ",FCYNO"//54
|
|
|
+ ",FCYEXRATE"//55
|
|
|
+ ",CASE WHEN DC='D' THEN '1' ELSE CASE WHEN DC='C' THEN '0' ELSE DC END END"//56
|
|
|
+ ",(case FCYNO when 'RMB' then AMTDR+AMTCR else FCYDR+FCYCR end) as FFCYAMT"//57
|
|
|
+ ",0"//58
|
|
|
+ ",0"//59
|
|
|
+ ",AMTDR"//60
|
|
|
+ ",AMTCR"//61
|
|
|
+ ",FSETTLCODE"//62 FSETTLCODE * 空白
|
|
|
+ ",FSETTLENO"//63
|
|
|
+ ",PREPARED"//64
|
|
|
+ ",null,null,null,null"//65-68
|
|
|
+ ",ATTACHS"//69
|
|
|
+ ",'False'"//70
|
|
|
+ ",null"//71
|
|
|
+ ",'False'"//72
|
|
|
+ ",VOUNO"//73
|
|
|
+ ",null,null,null,null,'1' "//74-78
|
|
|
+ " from VW_cw_vouchers_vouitems_gl where 1=1" + strCondition + " order by ORDNO,ITEMNO";
|
|
|
|
|
|
var _dbset = DbHelperSQL.Query(sSql);
|
|
|
|
|
|
DataTable dt = _dbset.Tables[0];
|
|
|
|
|
|
|
|
|
|
|
|
foreach (DataRow row in dt.Rows)
|
|
|
{
|
|
|
|
|
|
var newrecord = new DbfRecord(dbf.Header) { AllowDecimalTruncate = true };
|
|
|
|
|
|
foreach (var item in row.ItemArray)
|
|
|
{
|
|
|
itemvalue = item.ToString();
|
|
|
newrecord[_i] = item.ToString();
|
|
|
_i++;
|
|
|
}
|
|
|
dbf.Write(newrecord, true);
|
|
|
_i = 0;
|
|
|
itemvalue = "";
|
|
|
}
|
|
|
dbf.Close();
|
|
|
|
|
|
result.setMessage(true,"导出成功");
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dbf.Close();
|
|
|
//iResult = -1;
|
|
|
result.Data = "-1";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
dbf.Close();
|
|
|
|
|
|
//iResult = -1;//有异常,插入失败
|
|
|
result.Data = "-1";
|
|
|
result.Message = "["+ _i.ToString()+"/"+ itemvalue + "]"+ execError.Message + sSql;
|
|
|
return result;
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
dbf.Close();
|
|
|
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 根据上传删除的附件数,更新凭证附单据张数,需求编号:SR2017062800004
|
|
|
public static DBResult setAttachs(string sORDNO)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
try
|
|
|
{
|
|
|
var cmdDelete = db.GetSqlStringCommand("update cw_vouchers_gl set ATTACHS=isnull((select count(*) as ATTACHS from [Receipt_Doc] where bsno='" + sORDNO + "'),1) where ORDNO='" + sORDNO + "'");
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "删除出现错误,请重试!";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
result.Success = true;
|
|
|
result.Message = "操作成功";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
public static DBResult GetNoVKNO(string accdatefr, string accdateto, 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 = "";
|
|
|
//
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 判断凭证是否连号
|
|
|
string sSQL = "select VKNO from VW_cw_vouchers_vouitems_gl where STARTGID='" + strCwSTARTGID + "' and ACCDATE>='" + accdatefr + "' and ACCDATE<='" + accdateto + "' 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 ACCDATE>='" + accdatefr + "' and ACCDATE<='" + accdateto + "' and VKNO='" + ds.Tables[0].Rows[i]["VKNO"].ToString() + "' group by VOUNO order by convert(int,VOUNO) DESC";
|
|
|
DataSet ds2 = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
if (ds2 != null)
|
|
|
{
|
|
|
if (ds2.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
var vounum = Convert.ToInt32(ds2.Tables[0].Rows[0]["VOUNO"].ToString().Trim());
|
|
|
for (int m=1;m<vounum;m++)
|
|
|
{
|
|
|
var isfind = false;
|
|
|
for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
|
|
|
{
|
|
|
if (ds2.Tables[0].Rows[j]["VOUNO"].ToString().Trim() == m.ToString())
|
|
|
{
|
|
|
isfind = true;
|
|
|
continue;
|
|
|
// break;
|
|
|
}
|
|
|
}
|
|
|
if (!isfind) sError += "、" + ds.Tables[0].Rows[i]["VKNO"].ToString() + "字第" + m.ToString().Trim() + "号";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (sError != "")
|
|
|
{
|
|
|
sError = sError.Substring(1) + "凭证的凭证号不连续!";
|
|
|
result.Success = false;
|
|
|
result.Message = sError;
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = true;
|
|
|
result.Message = "";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
//
|
|
|
}
|
|
|
}
|