You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/OA/DAL/Baoxiao/Baoxiao2DAL.cs

2202 lines
124 KiB
C#

3 years ago
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.OA.Models.Baoxiao;
using DSWeb.Areas.OA.Models.Comm;
using Microsoft.Practices.EnterpriseLibrary.Data;
using HcUtility.Comm;
using DSWeb.Areas.Account.Models.MsCwVouchersGl3;
using DSWeb.MvcShipping.Models.MsCwVouchersGl;
using DSWeb.MvcShipping.Models.MsCwVouitemsGl;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.EntityDA;
using HcUtility.Core;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.Areas.OA.DAL.Baoxiao2
{
public partial class BaoxiaoDAL
{
#region 报销单列表
//报销单列表
static public List<Baoxiao2mb> GetDataList(string strCondition, string USERID, string sort = null)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(USERID);
var strSql = new StringBuilder();
strSql.Append(" select BXGID,bx.BSNO,COMPANY,DEPTNAME,CREATEUSER,BXNO,BX.JKTYPE,BX.JKREASON,BX.JJNO,BX.JJDATE ");
strSql.Append(" ,dbo.trimdate(CREATEDATE) CREATEDATE ");
strSql.Append(" ,bx.ISDELETE,bx.DELETEUSER,bx.DELETETIME,BXSTATUS,REMARK,AMOUNT ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=bx.bxstatus) as bxstatus_Ref ");
strSql.Append(" ,CHEQUENO,CHEQUEAMOUNT,BX.ISVOU,(case BX.ISVOU when 1 then '是' else '否' end) ISVOU_REF,BX.VOUCHERNO ");
strSql.Append(" ,(case (select isnull(sum(obp.amount),0) from OA_Baoxiao_Pay obp where obp.BXGID=bx.BXGID) ");
strSql.Append(" when isnull(bx.amount,0) then '是' else '否' end) ISPAYED ");
strSql.Append(" ,BX.RMBAMOUNT,BX.USDAMOUNT,BX.OTHERAMOUNT");
strSql.Append(" ,(select showname from vw_user where userid=(select top 1 auditor from workflow_do where billno=bx.BXGID order by AUDITTIME DESC )) auditor");
strSql.Append(" ,(select top 1 dbo.trimtime(AUDITTIME) from workflow_do where billno=bx.BXGID order by AUDITTIME DESC ) audittime");
strSql.Append(" ,(case when EXISTS (select * from ch_Fee where BX.BXGID=BXGID and ISNULL(JKGID,'')<>'') then '借款' else '直接报销' end) isjk ");
strSql.Append(" ,dbo.[F_CHFEE_BX2remark](BXGID) FEEREMARK ");
strSql.Append(" ,VOUALLNO=isnull((select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=BX.BXGID and BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "'),'')");
strSql.Append(",BX.SALECORPID,(select [NAME] from [company] where GID=BX.SALECORPID) as SALECORP");
strSql.Append(" FROM vw_Baoxiao BX ");
strSql.Append(" where (bx.isdelete=0 or bx.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);
}
else
{
strSql.Append(" order by CREATEDATE DESC");
}
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string USERID, string sort = null)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(USERID);
var strSql = new StringBuilder();
strSql.Append(" select BXGID,bx.BSNO,COMPANY,DEPTNAME,CREATEUSER,BXNO,BX.JKTYPE,BX.JKREASON,BX.JJNO,BX.JJDATE ");
strSql.Append(" ,dbo.trimdate(CREATEDATE) CREATEDATE ");
strSql.Append(" ,bx.ISDELETE,bx.DELETEUSER,bx.DELETETIME,BXSTATUS,REMARK,AMOUNT ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=bx.bxstatus) as bxstatus_Ref ");
strSql.Append(" ,CHEQUENO,CHEQUEAMOUNT,BX.ISVOU,(case BX.ISVOU when 1 then '是' else '否' end) ISVOU_REF,BX.VOUCHERNO ");
strSql.Append(" ,(case (select isnull(sum(obp.amount),0) from OA_Baoxiao_Pay obp where obp.BXGID=bx.BXGID) ");
strSql.Append(" when isnull(bx.amount,0) then '是' else '否' end) ISPAYED ");
strSql.Append(" ,BX.RMBAMOUNT,BX.USDAMOUNT,BX.OTHERAMOUNT");
strSql.Append(" ,(select showname from vw_user where userid=(select top 1 auditor from workflow_do where billno=bx.BXGID order by AUDITTIME DESC )) auditor");
strSql.Append(" ,(select top 1 dbo.trimtime(AUDITTIME) from workflow_do where billno=bx.BXGID order by AUDITTIME DESC ) audittime");
strSql.Append(" ,(case when EXISTS (select * from ch_Fee where BX.BXGID=BXGID and ISNULL(JKGID,'')<>'') then '借款' else '直接报销' end) isjk ");
strSql.Append(" ,dbo.[F_CHFEE_BX2remark](BXGID) FEEREMARK ");
strSql.Append(" ,VOUALLNO=isnull((select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=BX.BXGID and BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "'),'')");
strSql.Append(",BX.SALECORPID,(select [NAME] from [company] where GID=BX.SALECORPID) as SALECORP");
strSql.Append(" FROM vw_Baoxiao BX ");
strSql.Append(" where (bx.isdelete=0 or bx.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);
}
else
{
strSql.Append(" order by CREATEDATE DESC");
}
return strSql.ToString();
}
static public List<Baoxiao2mb> GetZCDataList(string strCondition, string USERID, string sort = null)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(USERID);
var strSql = new StringBuilder();
strSql.Append(" select BXGID,bx.BSNO,COMPANY,DEPTNAME,CREATEUSER,BXNO,BX.JKTYPE,BX.JKREASON,BX.JJNO,BX.JJDATE ");
strSql.Append(" ,dbo.trimdate(CREATEDATE) CREATEDATE ");
strSql.Append(" ,bx.ISDELETE,bx.DELETEUSER,bx.DELETETIME,BXSTATUS,REMARK,AMOUNT ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=bx.bxstatus) as bxstatus_Ref ");
strSql.Append(" ,CHEQUENO,CHEQUEAMOUNT,BX.ISVOU,(case BX.ISVOU when 1 then '是' else '否' end) ISVOU_REF,BX.VOUCHERNO ");
strSql.Append(" ,(case (select isnull(sum(obp.amount),0) from OA_Baoxiao_Pay obp where obp.BXGID=bx.BXGID) ");
strSql.Append(" when isnull(bx.amount,0) then '是' else '否' end) ISPAYED ");
strSql.Append(" ,BX.RMBAMOUNT,BX.USDAMOUNT,BX.OTHERAMOUNT");
strSql.Append(" ,(select showname from vw_user where userid=(select top 1 auditor from workflow_do where billno=bx.BXGID order by AUDITTIME DESC )) auditor");
strSql.Append(" ,(select top 1 dbo.trimtime(AUDITTIME) from workflow_do where billno=bx.BXGID order by AUDITTIME DESC ) audittime");
strSql.Append(" ,(case when EXISTS (select * from ch_Fee where BX.BXGID=BXGID and ISNULL(JKGID,'')<>'') then '借款' else '直接报销' end) isjk ");
strSql.Append(" ,dbo.[F_CHFEE_BX2remark](BXGID) FEEREMARK ");
strSql.Append(" ,VOUALLNO=isnull((select top 1 VOUALLNO from cw_vouno_bs_gl WITH(NOLOCK) where BSGID=BX.BXGID and BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "'),'')");
strSql.Append(",BX.SALECORPID,(select [NAME] from [company] where GID=BX.SALECORPID) as SALECORP");
strSql.Append(" FROM vw_Baoxiao BX ");
strSql.Append(" where (bx.isdelete=0 or bx.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);
}
else
{
strSql.Append(" order by CREATEDATE DESC");
}
return SetData(strSql);
}
static public Baoxiao2mb GetData (string condition, string USERID)
{
var list = GetDataList(condition, USERID);
if (list.Count > 0)
return list[0];
return new Baoxiao2mb();
}
private static List<Baoxiao2mb> SetData ( StringBuilder strSql )
{
var headList = new List<Baoxiao2mb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Baoxiao2mb data = new Baoxiao2mb();
#region Set DB data to Object
data.BXGID = Convert.ToString(reader["BXGID"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.COMPANY = Convert.ToString(reader["COMPANY"]);
data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEDATE = Convert.ToString(reader["CREATEDATE"]);
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);
data.BXSTATUS = Convert.ToString(reader["BXSTATUS"]);
data.BXSTATUS_REF = Convert.ToString(reader["BXSTATUS_REF"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.AMOUNT = Convert.ToString(reader["AMOUNT"]);
data.CHEQUENO = Convert.ToString(reader["CHEQUENO"]);
data.CHEQUEAMOUNT = Convert.ToString(reader["CHEQUEAMOUNT"]);
data.ISVOU_REF = Convert.ToString(reader["ISVOU_REF"]);
data.VOUCHERNO = Convert.ToString(reader["VOUCHERNO"]);
data.BXNO = Convert.ToString(reader["BXNO"]);
data.ISPAYED = Convert.ToString(reader["ISPAYED"]);
data.RMBAMOUNT = Convert.ToString(reader["RMBAMOUNT"]);
data.USDAMOUNT = Convert.ToString(reader["USDAMOUNT"]);
data.OTHERAMOUNT = Convert.ToString(reader["OTHERAMOUNT"]);
data.AUDITOR = Convert.ToString(reader["AUDITOR"]);
data.AUDITTIME = Convert.ToString(reader["AUDITTIME"]);
data.ISJK = Convert.ToString(reader["ISJK"]);
data.FEEREMARK = Convert.ToString(reader["FEEREMARK"]);
data.VOUALLNO = Convert.ToString(reader["VOUALLNO"]);
data.JKTYPE = Convert.ToString(reader["JKTYPE"]);
data.JKREASON = Convert.ToString(reader["JKREASON"]);
data.JJNO = Convert.ToString(reader["JJNO"]);
data.SALECORPID = Convert.ToString(reader["SALECORPID"]);
data.SALECORP = Convert.ToString(reader["SALECORP"]);
if (reader["JJDATE"] != DBNull.Value)
data.JJDATE = Convert.ToDateTime(reader["JJDATE"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region
static public List<BaoXiao2Bodymb> GetBaoXiao2Body ( string condition )
{
var strSql = new StringBuilder();
strSql.Append(" select GID,JKGID,BXGID,BSNO,FEEDESCRIPTION,PaymentGID,CARGO_GID ");
strSql.Append(" ,FEETYPE,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=FeeType) FEETYPE_REF ");
strSql.Append(" ,FEESTATUS,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=FeeStatus) FEESTATUS_REF ");
strSql.Append(" ,SALESNO,FEENAME,CURRENCY,AMOUNT,NOTAXAMOUNT,CUSTOMERNAME,MODIFIEDUSER,MODIFIEDTIME,Remark,Settlement,INVOICENUM,TAXRATE ");
strSql.Append(" ,(select showname from vw_user where userid=(select enteroperator from oa_jiekuan where GID=c.JKGID)) JKNAME");
strSql.Append(" ,(select dbo.trimdate(enterdate) from oa_jiekuan where GID=c.JKGID) JKDATE");
strSql.Append(" ,case isnull(c.REASON,'') when '' then (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=36 and EnumValueID=(select JKTYPE from oa_jiekuan where GID=c.JKGID)) else c.REASON end JKTYPE_REF");
strSql.Append(" ,(SELECT TOP 1 MBLNO FROM V_OP_BILL WHERE BSNO=C.BSNO) MBLNO ");
strSql.Append(" from ch_fee c ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
return SetJieKuan2Body(strSql);
}
static public List<BaoXiao2Bodymb> GetBaoXiaoZCBody(string condition)
{
var strSql = new StringBuilder();
strSql.Append(" select GID,JKGID,BXGID,BSNO,FEEDESCRIPTION,PaymentGID,CARGO_GID ");
strSql.Append(" ,FEETYPE,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=FeeType) FEETYPE_REF ");
strSql.Append(" ,FEESTATUS,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=FeeStatus) FEESTATUS_REF ");
strSql.Append(" ,SALESNO,FEENAME,CURRENCY,AMOUNT,NOTAXAMOUNT,CUSTOMERNAME,MODIFIEDUSER,MODIFIEDTIME,Remark,Settlement,INVOICENUM,TAXRATE ");
strSql.Append(" ,(select showname from vw_user where userid=(select enteroperator from oa_jiekuan where GID=c.JKGID)) JKNAME");
strSql.Append(" ,(select dbo.trimdate(enterdate) from oa_jiekuan where GID=c.JKGID) JKDATE");
strSql.Append(" ,case isnull(c.REASON,'') when '' then (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=36 and EnumValueID=(select JKTYPE from oa_jiekuan where GID=c.JKGID)) else c.REASON end JKTYPE_REF");
strSql.Append(" ,(SELECT TOP 1 MBLNO FROM V_OP_BILL WHERE BSNO=C.PaymentGID) MBLNO ");
strSql.Append(" from ch_fee c ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
return SetJieKuan2Body(strSql);
}
private static List<BaoXiao2Bodymb> SetJieKuan2Body ( StringBuilder strSql )
{
var headList = new List<BaoXiao2Bodymb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BaoXiao2Bodymb data = new BaoXiao2Bodymb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.JKGID = Convert.ToString(reader["JKGID"]);
data.BXGID = Convert.ToString(reader["BXGID"]);
data.PaymentGID = Convert.ToString(reader["PaymentGID"]);
data.CARGO_GID = Convert.ToString(reader["CARGO_GID"]);
data.FEETYPE = Convert.ToString(reader["FEETYPE"]);
data.FEETYPE_REF = Convert.ToString(reader["FEETYPE_REF"]);
data.FEESTATUS = Convert.ToString(reader["FEESTATUS"]);
data.FEESTATUS_REF = Convert.ToString(reader["FEESTATUS_REF"]);
data.SALESNO = Convert.ToString(reader["SALESNO"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
if (reader["AMOUNT"] != DBNull.Value)
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
if (reader["NOTAXAMOUNT"] != DBNull.Value)
data.NOTAXAMOUNT = Convert.ToDecimal(reader["NOTAXAMOUNT"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.JKNAME = Convert.ToString(reader["JKNAME"]);
data.JKDATE = Convert.ToString(reader["JKDATE"]);
data.JKTYPE_REF = Convert.ToString(reader["JKTYPE_REF"]);
data.SETTLEMENT = Convert.ToDecimal(reader["SETTLEMENT"]);
data.INVOICENUM = Convert.ToString(reader["INVOICENUM"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.FEEDESCRIPTION = Convert.ToString(reader["FEEDESCRIPTION"]);
if (reader["TAXRATE"] != DBNull.Value)
data.TAXRATE = Convert.ToDecimal(reader["TAXRATE"]);
if (data.TAXRATE==0)
data.TAX =0;
else
data.TAX = Math.Round(data.AMOUNT - data.NOTAXAMOUNT, 2, MidpointRounding.AwayFromZero);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 审核用报销单列表
//报销单列表
static public List<BaoxiaoAuditmb> GetAuditDataList(string strCondition,string workflowname,string corpid,string userid)
{
var strSql = new StringBuilder();
strSql.Append(" declare @workflowname varchar(50),@corpid varchar(50),@userid varchar(50)");
strSql.Append(" set @workflowname ='" + workflowname + "'");
strSql.Append(" set @corpid ='" + corpid + "'");
strSql.Append(" set @userid ='" + userid + "'");
strSql.Append(" select BXGID,bx.BSNO,COMPANY,DEPTNAME,CREATEUSER,BXNO,");
strSql.Append(" case CREATEDATE when '1900-1-1' then '' else CONVERT(varchar, CREATEDATE, 120 ) end CREATEDATE ");
strSql.Append(" ,bx.ISDELETE,bx.DELETEUSER,bx.DELETETIME,BXSTATUS,REMARK,AMOUNT ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=bx.bxstatus) as bxstatus_Ref ");
strSql.Append(" ,CHEQUENO,CHEQUEAMOUNT,BX.ISVOU,(case BX.ISVOU when 1 then '是' else '否' end) ISVOU_REF,BX.VOUCHERNO ");
strSql.Append(" ,(case BX.ISVOU when 1 then '是' else '否' end) ISVOU_REF,BX.VOUCHERNO ");
strSql.Append(" ,(case (select isnull(sum(obp.amount),0) from OA_Baoxiao_Pay obp where obp.BXGID=bx.BXGID) ");
strSql.Append(" when isnull(bx.amount,0) then '是' else '否' end) ISPAYED ");
strSql.Append(" ,dbo.[GetUsingStep](wu.workflowid,wu.currentid,@userid,wu.stepno) usingStep,wu.workflowid ");
strSql.Append(" FROM OA_Baoxiao BX left join workflow_using wu on wu.bsno=bx.bxgid ");
strSql.Append(" where (bx.isdelete=0 or bx.isdelete is null) ");
//strSql.Append(" and dbo.[GetUsingStep](@workflowname,@corpid,wu.currentid,@userid,wu.stepno)<>0 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
return SetAuditData(strSql);
}
static public Baoxiaomb GetAuditData(string condition, string USERID)
{
var list = GetDataList(condition, USERID);
if (list.Count > 0)
return list[0];
return new Baoxiaomb();
}
private static List<BaoxiaoAuditmb> SetAuditData(StringBuilder strSql)
{
var headList = new List<BaoxiaoAuditmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BaoxiaoAuditmb data = new BaoxiaoAuditmb();
#region Set DB data to Object
data.BXGID = Convert.ToString(reader["BXGID"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.COMPANY = Convert.ToString(reader["COMPANY"]);
data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEDATE = Convert.ToString(reader["CREATEDATE"]);
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);
data.BXSTATUS = Convert.ToString(reader["BXSTATUS"]);
data.BXSTATUS_REF = Convert.ToString(reader["BXSTATUS_REF"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.AMOUNT = Convert.ToString(reader["AMOUNT"]);
data.CHEQUENO = Convert.ToString(reader["CHEQUENO"]);
data.CHEQUEAMOUNT = Convert.ToString(reader["CHEQUEAMOUNT"]);
data.ISVOU_REF = Convert.ToString(reader["ISVOU_REF"]);
data.VOUCHERNO = Convert.ToString(reader["VOUCHERNO"]);
data.BXNO = Convert.ToString(reader["BXNO"]);
data.ISPAYED = Convert.ToString(reader["ISPAYED"]);
data.USINGSTEP = Convert.ToString(reader["USINGSTEP"]);
data.WORKFLOWID = Convert.ToString(reader["WORKFLOWID"]);
//data.WORKFLOWUSING_GID = Convert.ToString(reader["WORKFLOWUSING_GID"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
static public List<BSNOmb> GetBSNO(string COMPANYID)
{
var strSql = new StringBuilder();
strSql.Append(" select bsno,CUSTNO,mblno,HBLNO,'' OPLB from V_op_bs ");
strSql.Append(" where inputby in (select showname from [user] where gid in(select userid from user_company where companyid='" + COMPANYID + "' )) ");
//feestatus=0 and
//strSql.Append(" union all ");
//strSql.Append(" select bsno,CUSTNO+'_'+mblno code,mblno from op_seai ");
//strSql.Append(" where feestatus=0 and inputby in (select showname from [user] where gid in(select userid from user_company where companyid='" + COMPANYID + "' )) ");
//strSql.Append(" FROM OA_Baoxiao BX ");
return SetDataBSNO(strSql);
}
/*
static public List<BSNOmb> GetAllBSNO ( string COMPANYID )
{
var strSql = new StringBuilder();
strSql.Append(" select bsno,CUSTNO,mblno,OPLB from V_op_bs ");
return SetDataBSNO(strSql);
}*/
static public List<BSNOmb> GetAllBSNO ( string condition )
{
var strSql = new StringBuilder();
strSql.Append(" select bsno,CUSTNO,mblno,OPLB,HBLNO from V_op_bs where 1=1 " + condition + " ");
return SetDataBSNO(strSql);
}
static public List<BSNOmb> GetTruckMBLNO ( string condition )
{
var strSql = new StringBuilder();
strSql.Append(" select distinct mblno,HBLNO,'' BSNO,'' CUSTNO,'' OPLB from V_OP_BS ");
return SetDataBSNO(strSql);
}
static public List<BSNOmb> GetTruckBSNO ( string condition )
{
var strSql = new StringBuilder();
strSql.Append(" select bsno, CUSTNO ,mblno,OPLB,HBLNO from V_OP_BS ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(condition);
}
return SetDataBSNO(strSql);
}
private static List<BSNOmb> SetDataBSNO(StringBuilder strSql)
{
var headList = new List<BSNOmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BSNOmb data = new BSNOmb();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#region 查询费用数据
static public List<MsChFee> GetFeeList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT ");
strSql.Append(" c.GId,c.BsNo,vs.MBLNO , c.FeeStatus,vs.CUSTNO, ");
strSql.Append(" (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=c.FeeStatus) as FeeStatus_Ref ");
strSql.Append(" ,FeeType, (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=c.FeeType) as FeeType_Ref ");
strSql.Append(" ,FeeName,(select NAME from vMsTruckFeeType where NAME=c.FeeName) as FeeName_Ref ");
strSql.Append(" ,FeeDescription,CustomerType,c.CustomerName, ");
strSql.Append(" (select top 1 CustName from vMsTruckClient v where v.CustName=c.CustomerName) as CustomerName_Ref ");
strSql.Append(" ,Unit,UnitPrice,Quantity,Amount,Currency,ExChangerate,Reason ");
strSql.Append(" ,Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice,SubmitDate ");
strSql.Append(" ,Auditoperator,AuditDate,EnteroPerator,EnterDate,DebitNo,IsDebit,IsOpen ");
strSql.Append(" ,IsAdvancedpay,Sort,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus,InvoiceNum ");
strSql.Append(" ,ChequeNum,WmsOutBsNo,c.BXGID,C.TAX,C.TAXRATE,C.NOTAXAMOUNT,C.reason,C.CHEQUENUM,C.ISOPEN, ");
strSql.Append(" case c.isopen when 1 then '是' else '否' end ISOPEN_REF ");
strSql.Append(" from ch_fee c left join v_op_bs vs on vs.bsno=c.bsno ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetFeeData(strSql);
}
static public List<MsChFeeAmount> GetAmountList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT ");
strSql.Append(" c.GId,c.BsNo,vs.MBLNO , c.FeeStatus,vs.CUSTNO, ");
strSql.Append(" (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=c.FeeStatus) as FeeStatus_Ref ");
strSql.Append(" ,FeeType, (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=c.FeeType) as FeeType_Ref ");
strSql.Append(" ,FeeName,(select NAME from vMsTruckFeeType where NAME=c.FeeName) as FeeName_Ref ");
strSql.Append(" ,FeeDescription,CustomerType,c.CustomerName, ");
strSql.Append(" (select top 1 CustName from vMsTruckClient v where v.CustName=c.CustomerName) as CustomerName_Ref ");
strSql.Append(" ,Unit,UnitPrice,Quantity,Amount,Currency,ExChangerate,Reason ");
strSql.Append(" ,Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice,SubmitDate ");
strSql.Append(" ,Auditoperator,AuditDate,EnteroPerator,EnterDate,DebitNo,IsDebit,IsOpen ");
strSql.Append(" ,IsAdvancedpay,Sort,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus,InvoiceNum ");
strSql.Append(" ,ChequeNum,WmsOutBsNo,c.BXGID,C.TAX,C.TAXRATE,C.NOTAXAMOUNT,C.reason,C.CHEQUENUM,C.ISOPEN, ");
strSql.Append(" case c.isopen when 1 then '是' else '否' end ISOPEN_REF,c.feeName+'_'+convert(varchar(50),c.Amount) as FeeNameAmount ");
strSql.Append(" from ch_fee c left join vw_settlement vs on vs.bsno=c.bsno ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetAmountData(strSql);
}
private static List<MsChFee> SetFeeData(StringBuilder strSql)
{
var bodyList = new List<MsChFee>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsChFee data = new MsChFee();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.BsNo = Convert.ToString(reader["BsNo"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.FeeStatus = Convert.ToDecimal(reader["FeeStatus"]);
data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]);
data.FeeType = Convert.ToDecimal(reader["FeeType"]);
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
data.FeeName = Convert.ToString(reader["FeeName"]);
data.FeeName_Ref = Convert.ToString(reader["FeeName_Ref"]);
data.FeeDescription = Convert.ToString(reader["FeeDescription"]);
data.CustomerType = Convert.ToString(reader["CustomerType"]);
data.CustomerName = Convert.ToString(reader["CustomerName"]);
data.CustomerName_Ref = Convert.ToString(reader["CustomerName_Ref"]);
data.Unit = Convert.ToString(reader["Unit"]);
data.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]);
data.Quantity = Convert.ToDecimal(reader["Quantity"]);
data.Amount = Convert.ToDecimal(reader["Amount"]);
data.TAX = Convert.ToString(reader["TAX"]);
data.Taxrate = Convert.ToDecimal(reader["TAXRATE"]);
data.NOTAXAMOUNT = Convert.ToString(reader["NOTAXAMOUNT"]);
data.Currency = Convert.ToString(reader["Currency"]);
data.ExChangerate = Convert.ToDecimal(reader["ExChangerate"]);
data.Reason = Convert.ToString(reader["Reason"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.Commissionrate = Convert.ToDecimal(reader["Commissionrate"]);
data.Settlement = Convert.ToDecimal(reader["Settlement"]);
if (reader["Invoice"] != DBNull.Value)
data.Invoice = Convert.ToDecimal(reader["Invoice"]);
data.OrderAmount = Convert.ToDecimal(reader["OrderAmount"]);
data.OrderInvoice = Convert.ToDecimal(reader["OrderInvoice"]);
if (reader["SubmitDate"] != DBNull.Value)
data.SubmitDate = Convert.ToDateTime(reader["SubmitDate"]);
data.Auditoperator = Convert.ToString(reader["Auditoperator"]);
if (reader["AuditDate"] != DBNull.Value)
data.AuditDate = Convert.ToDateTime(reader["AuditDate"]);
data.EnteroPerator = Convert.ToString(reader["EnteroPerator"]);
if (reader["EnterDate"] != DBNull.Value)
data.EnterDate = Convert.ToDateTime(reader["EnterDate"]);
data.DebitNo = Convert.ToString(reader["DebitNo"]);
data.IsDebit = Convert.ToString(reader["IsDebit"]);
data.IsOpen = Convert.ToString(reader["IsOpen"]);
data.IsAdvancedpay = Convert.ToString(reader["IsAdvancedpay"]);
data.Sort = Convert.ToString(reader["Sort"]);
data.IsInvoice = Convert.ToString(reader["IsInvoice"]);
data.FeeFrt = Convert.ToString(reader["FeeFrt"]);
data.IsCrmOrderFee = Convert.ToString(reader["IsCrmOrderFee"]);
data.AuditStatus = Convert.ToDecimal(reader["AuditStatus"]);
data.InvoiceNum = Convert.ToString(reader["InvoiceNum"]);
data.ChequeNum = Convert.ToString(reader["ChequeNum"]);
data.WmsOutBsNo = Convert.ToString(reader["WmsOutBsNo"]);
data.BXGID = Convert.ToString(reader["BXGID"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.Reason = Convert.ToString(reader["Reason"]);
data.CHEQUENUM = Convert.ToString(reader["CHEQUENUM"]);
data.IsOpen = Convert.ToString(reader["IsOpen"]);
data.IsOpen_REF = Convert.ToString(reader["IsOpen_REF"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
private static List<MsChFeeAmount> SetAmountData(StringBuilder strSql)
{
var bodyList = new List<MsChFeeAmount>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsChFeeAmount data = new MsChFeeAmount();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.BsNo = Convert.ToString(reader["BsNo"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.FeeStatus = Convert.ToDecimal(reader["FeeStatus"]);
data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]);
data.FeeType = Convert.ToDecimal(reader["FeeType"]);
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
data.FeeName = Convert.ToString(reader["FeeName"]);
data.FeeName_Ref = Convert.ToString(reader["FeeName_Ref"]);
data.FeeDescription = Convert.ToString(reader["FeeDescription"]);
data.CustomerType = Convert.ToString(reader["CustomerType"]);
data.CustomerName = Convert.ToString(reader["CustomerName"]);
data.CustomerName_Ref = Convert.ToString(reader["CustomerName_Ref"]);
data.Unit = Convert.ToString(reader["Unit"]);
data.UnitPrice = Convert.ToDecimal(reader["UnitPrice"]);
data.Quantity = Convert.ToDecimal(reader["Quantity"]);
data.Amount = Convert.ToDecimal(reader["Amount"]);
data.TAX = Convert.ToString(reader["TAX"]);
data.Taxrate = Convert.ToDecimal(reader["TAXRATE"]);
data.NOTAXAMOUNT = Convert.ToString(reader["NOTAXAMOUNT"]);
data.Currency = Convert.ToString(reader["Currency"]);
data.ExChangerate = Convert.ToDecimal(reader["ExChangerate"]);
data.Reason = Convert.ToString(reader["Reason"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.Commissionrate = Convert.ToDecimal(reader["Commissionrate"]);
data.Settlement = Convert.ToDecimal(reader["Settlement"]);
if (reader["Invoice"] != DBNull.Value)
data.Invoice = Convert.ToDecimal(reader["Invoice"]);
data.OrderAmount = Convert.ToDecimal(reader["OrderAmount"]);
data.OrderInvoice = Convert.ToDecimal(reader["OrderInvoice"]);
if (reader["SubmitDate"] != DBNull.Value)
data.SubmitDate = Convert.ToDateTime(reader["SubmitDate"]);
data.Auditoperator = Convert.ToString(reader["Auditoperator"]);
if (reader["AuditDate"] != DBNull.Value)
data.AuditDate = Convert.ToDateTime(reader["AuditDate"]);
data.EnteroPerator = Convert.ToString(reader["EnteroPerator"]);
if (reader["EnterDate"] != DBNull.Value)
data.EnterDate = Convert.ToDateTime(reader["EnterDate"]);
data.DebitNo = Convert.ToString(reader["DebitNo"]);
data.IsDebit = Convert.ToString(reader["IsDebit"]);
data.IsOpen = Convert.ToString(reader["IsOpen"]);
data.IsAdvancedpay = Convert.ToString(reader["IsAdvancedpay"]);
data.Sort = Convert.ToString(reader["Sort"]);
data.IsInvoice = Convert.ToString(reader["IsInvoice"]);
data.FeeFrt = Convert.ToString(reader["FeeFrt"]);
data.IsCrmOrderFee = Convert.ToString(reader["IsCrmOrderFee"]);
data.AuditStatus = Convert.ToDecimal(reader["AuditStatus"]);
data.InvoiceNum = Convert.ToString(reader["InvoiceNum"]);
data.ChequeNum = Convert.ToString(reader["ChequeNum"]);
data.WmsOutBsNo = Convert.ToString(reader["WmsOutBsNo"]);
data.BXGID = Convert.ToString(reader["BXGID"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.Reason = Convert.ToString(reader["Reason"]);
data.CHEQUENUM = Convert.ToString(reader["CHEQUENUM"]);
data.IsOpen = Convert.ToString(reader["IsOpen"]);
data.IsOpen_REF = Convert.ToString(reader["IsOpen_REF"]);
data.FeeNameAmount = Convert.ToString(reader["FeeNameAmount"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 查询支付数据
static public List<BXPaymb> GetPayList(string BXGID,string USERID)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT *, ");
strSql.Append(" (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=26 and EnumValueID=obp.settlementtype) as settlementtype_Ref ");
strSql.Append(" ,(select top 1 accname from cw_accitems_gl where accid=OPERATORSIDE_gl and startgid=(select top 1 startgid from [cw_design_startusing_user] where usergid='" + USERID + "')) OPERATORSIDE_gl_REF");
strSql.Append(" from OA_Baoxiao_Pay obp ");
if (BXGID.Trim() != String.Empty)
{
strSql.Append(" where BXGID='" + BXGID+"'");
}
return SetPayData(strSql);
}
private static List<BXPaymb> SetPayData(StringBuilder strSql)
{
var bodyList = new List<BXPaymb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BXPaymb data = new BXPaymb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BXGID = Convert.ToString(reader["BXGID"]);
data.SETTLEMENTTYPE = Convert.ToString(reader["SETTLEMENTTYPE"]);
data.SETTLEMENTTYPE_REF = Convert.ToString(reader["SETTLEMENTTYPE_REF"]);
data.TICKETNO = Convert.ToString(reader["TICKETNO"]);
data.AMOUNT = Convert.ToString(reader["AMOUNT"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.FINANCIALCODE = Convert.ToString(reader["FINANCIALCODE"]);
data.OPERATORSIDE_gl = Convert.ToString(reader["OPERATORSIDE_gl"]);
data.OPERATORSIDE_gl_REF = Convert.ToString(reader["OPERATORSIDE_gl_REF"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 提交申请
// 根据handle类型执行更新操作更新费用信息ch_fee.feestatus和工作流运行表WorkFlowDo信息
// 费用状态值 费用状态主要有11个状态,分别为
// 审核通过STATUS=0录入状态STATUS=1提交审核STATUS=2申请修改 (STATUS=3)
// 取消申请(STATUS=5)驳回提交STATUS=6驳回申请STATUS=7部分结算STATUS=8结算完毕STATUS=9
//List<C_Mmb> chfeeList
internal static DBResult Audit(int newStatus, string WorkFlowName, /*string DEPTGID,*/ string USERID, string Reason, List<Baoxiaomb> BaoxiaoList)
{
var result = new DBResult();
var islast = false;
foreach (var BX in BaoxiaoList)
{
islast = false;
if (WorkFlowDAL.GetWorkFlowFinal_BSNO(WorkFlowName, BX.BXGID, USERID))
islast = true;
var status = int.Parse(BX.BXSTATUS);
var canAudit = true;
var BXGID = BX.BXGID;
BX.WORKFLOWID = WorkFlowDAL.GetBSNOWorkFlowID(WorkFlowName, BXGID)[0].GID;
if (newStatus == 2)
{
canAudit = status == 1 || status == 6;
}
else if (newStatus == 0)
{
canAudit = status == 2;
}
else if (newStatus == 6)
{
canAudit = status == 0 || status == 2;
}
else if (newStatus == 8 || newStatus == 9)
{
canAudit = status == 0;
}
else if (WorkFlowDAL.GetWorkFlowDo(BX.WORKFLOWID, BX.BXGID)!=0)
{
canAudit = false;
}
if (!canAudit)
{
result.Success = false;
if (newStatus == 2)
result.Message = "只有在'录入状态'和'驳回提交'状态下才能提交审核操作";
else if (newStatus == 0)
{
result.Message = "只有在‘提交审核’状态下才能进行‘审核通过’操作";
}
else if (newStatus == 6)
{
result.Message = "只有在‘审核通过’或‘提交审核’状态下才能进行此操作";
}
else if (newStatus == 8 || newStatus == 9)
{
result.Message = "只有在‘审核通过’状态下才能进行此操作";
}
else if (newStatus==1)
{
result.Message = "只有未经审核的单据才能撤回";
}
return result;
}
}
Database db = DatabaseFactory.CreateDatabase();
//if ()
var updateSql = " update OA_Baoxiao set BXStatus=@BXStatus where BXGID=@BXGID ";
if (newStatus == 0 )
{
updateSql = updateSql + " insert into ch_fee_do (gid,billno,bsno,mblno,customername,bstype,feeid,feename,currency, ";
updateSql = updateSql + " amount,doamount,feetype,category,billstatus,createtime,exchangerate,origamount,companyid ";
updateSql = updateSql + " )select newid(),BXGID,bsno,'',customername,2,gid,feename,currency, ";
updateSql = updateSql + " amount,amount as doamount,2,8,1,getdate(),1,amount, ";
updateSql = updateSql + " (select companyid from user_company uc where uc.userid=f.enteroperator) ";
updateSql = updateSql + " from ch_fee f where bxgid=@BXGID ";
if (islast)
{
updateSql = updateSql + " update ch_fee set feestatus=9,orderamount=amount,settlement=amount where BXGID=@BXGID ";
}
else
{
updateSql = updateSql + " update ch_fee set feestatus=2,orderamount=amount where BXGID=@BXGID ";
}
foreach (var BX in BaoxiaoList)
{
WorkFlowDAL.InsertWorkFlowDo(WorkFlowName, BX.BXGID, USERID,BX.BXNO);
}
}
else if (newStatus == 6)
{
updateSql = updateSql + " delete from ch_fee_do where feeid in(select gid from ch_fee where bxgid=@BXGID ) ";
updateSql = updateSql + " update ch_fee set feestatus=6,orderamount=0,settlement=0 where BXGID=@BXGID ";
foreach (var BX in BaoxiaoList)
{
WorkFlowDAL.DeleteWorkFlowDo(WorkFlowName, BX.BXGID, USERID, Reason);
}
}else if (newStatus == 2)
{
foreach (var BX in BaoxiaoList)
{
WorkFlowDAL.WorkFlowStart(WorkFlowName, BX.BXGID,USERID,BX.BXNO,BX.BXGID,"","","备注:"+BX.REMARK);
}
updateSql = updateSql + " update ch_fee set feestatus=2,orderamount=amount where BXGID=@BXGID ";
}
else if (newStatus == 1)
{
foreach (var BX in BaoxiaoList)
{
WorkFlowDAL.DeleteWorkFlowUsing(WorkFlowName, BX.BXGID, USERID);
}
}
else {
updateSql = updateSql + " update ch_fee set feestatus=@BXStatus where BXGID=@BXGID ";
}
const string enumSql =
"select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=@EnumValueID";
if (newStatus == 0 && islast != true)
{
newStatus = 2;
}
using (DbConnection connection = db.CreateConnection())
{
connection.Open();
try
{
var cmdEnum = db.GetSqlStringCommand(enumSql);
db.AddInParameter(cmdEnum, "@EnumValueID", DbType.Int32, newStatus);
var newStatusRef = Convert.ToString(db.ExecuteScalar(cmdEnum));
DbTransaction transaction = connection.BeginTransaction();
try
{
foreach (var BX in BaoxiaoList)
{
var cmdUpdate = db.GetSqlStringCommand(updateSql);
db.AddInParameter(cmdUpdate, "@BXStatus", DbType.Int32, newStatus);
db.AddInParameter(cmdUpdate, "@BXGID", DbType.String, BX.BXGID);
db.ExecuteNonQuery(cmdUpdate, transaction);
}
transaction.Commit();
result.Success = true;
result.Message = "提交成功";
result.Data = newStatusRef;
}
catch (Exception e)
{
transaction.Rollback();
result.Success = false;
if (e is MsChFeeDealException)
result.Message = e.Message;
else
result.Message = "执行提交发生未知错误,请重试";
}
}
finally
{
connection.Close();
}
}
if (newStatus==0||result.Success == true)
{
SetGZ(BaoxiaoList);//设置挂账信息
}
return result;
}
#endregion
public static int SetGZ(List<Baoxiaomb> BaoxiaoList)
{
var _count = 0;
var updateSql = "";
foreach (var BX in BaoxiaoList)
{
var BXGID = BX.BXGID;
updateSql = " update ch_fee set feestatus=0 where ";
updateSql = updateSql + " CHEQUENUM in( select TICKETNO from OA_Baoxiao_Pay where SETTLEMENTTYPE=4 and bxgid='" + BXGID + "') ";
updateSql = updateSql + " and bxgid='"+BXGID+"' ";
updateSql = updateSql + " update ch_fee set feestatus=9 where ";
updateSql = updateSql + " CHEQUENUM in( select TICKETNO from OA_Baoxiao_Pay where SETTLEMENTTYPE<>4 and bxgid='" + BXGID + "') ";
updateSql = updateSql + " and bxgid='" + BXGID + "' ";
}
return _count;
}
#region 删除报销单下的费用
static public int DELBXChFee(string BXGID)
{
var strSql = new StringBuilder();
strSql.Append(" delete from ch_fee where bxgid =( '" + BXGID + "')");
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region 解除费用与报销单的关联
public static int FeeUnUnion(List<MsChFeeAmount> feeUnUnionList)
{
var strSql = new StringBuilder();
var _count = 0;
foreach (var Fee in feeUnUnionList)
{
var GID = Fee.GId;
strSql.Append(" update ch_fee set bxgid = null where gid='" + GID + "' ");
_count = _count + SetFee(strSql);
}
return _count;//ExecuteNonQuery
}
#endregion
public static int SetFee(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#region 将借款单费用添加至报销单
static public int AddJKFee ( string BXGID, string FeeList )
{
var _count = 0;
var strSql = new StringBuilder();
if (FeeList != "")
{
strSql.Append(" Update ch_fee set bxgid='" + BXGID + "' where gid in( " + FeeList + ") ");
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
}
return _count;
}
static public int DelJKFee ( string FeeList )
{
var _count = 0;
var strSql = new StringBuilder();
if (FeeList != "")
{
strSql.Append(" delete from ch_fee where gid in( " + FeeList + ") and isnull(jkgid,'')='' and feestatus in(1,6) ");
strSql.Append(" Update ch_fee set bxgid='',feestatus=0,settlement=0 where gid in( " + FeeList + ") ");
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
}
return _count;
}
#endregion
#region 生成总账凭证
#region 生成汇率列表
static public List<MsCwVouchersGl4> GetCodeCurrencyList(string strGids, string companyid, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
var strSql = new StringBuilder();
strSql.Append("select CURRENCY,(select top 1 BEGRATE from cw_currency_rate where ACCDATE='" + strCwACCDATE + "' and STARTGID='" + strCwSTARTGID + "' and LINKGID in (select GID from code_currency where CODENAME=VW_OA_Baoxiao_chFee.CURRENCY)) as FCYEXRATE from VW_OA_Baoxiao_chFee where CURRENCY<>'RMB'");
if (!string.IsNullOrEmpty(strGids))
{
string strCondition = " and BXGID in ('" + strGids.Trim().Replace(",", "','") + "')";
strSql.Append(strCondition);
}
else
{
strSql.Append(" and 1<0");
}
strSql.Append(" group by CURRENCY order by CURRENCY");
return SetCodeCurrencyData(strSql);
}
private static List<MsCwVouchersGl4> SetCodeCurrencyData(StringBuilder strSql)
{
var headList = new List<MsCwVouchersGl4>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwVouchersGl4 data = new MsCwVouchersGl4();
#region Set DB data to Object
data.CURR = (reader["CURRENCY"] == null ? "" : Convert.ToString(reader["CURRENCY"]));
data.FCYEXRATE = (reader["FCYEXRATE"] == null ? "" : Convert.ToString(reader["FCYEXRATE"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 生成总账凭证
public static DBResult onAddCwVouchers(string strGids, MsCwVouchersGl3 headData, List<MsCwVouchersGl4> bodyList, string strUserID, string strSHOWNAME, string companyid)
{
Database db = DatabaseFactory.CreateDatabase();
var result = new DBResult();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "";
int iResult = 0;
string zt = "";
string sError = "操作完成!";
string strError = "";
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
var CWSTARTUSING = MsSysParamSetDAL.GetData("PARAMNAME='CWSTARTUSING'");
if (CWSTARTUSING.PARAMVALUE != "")
{
if (strCwSTARTGID != CWSTARTUSING.PARAMVALUE)
{
result.Success = false;
result.Message = "当前账套不是设置的账套,不能生成凭证!";
return result;
}
}
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
string sNum = "";
string strCondition = " and BXGID not in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "')";
string sAndGids = " and BXGID in ('" + strGids.Trim().Replace(",", "','") + "')";
#region 生成前的判断
//帐套设置
sSQL = "SELECT top 1 * from cw_design_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "'";// and CORPID='"+companyid+"'
DataSet dsCwDesign = T_ALL_DA.GetAllSQL(sSQL);
if (dsCwDesign == null)
{
result.Success = false;
result.Message = "请先设置帐套信息!" + result.Message;
return result;
}
//银行账户设置
sSQL = "select ACCOUNT from (SELECT isnull(REASON,'') as ACCOUNT from VW_OA_Baoxiao_chFee where 1=1 " + strCondition + sAndGids + " and REASON<>'' and REASON is not NULL and REASON<>'现金') as a group by ACCOUNT";// where CORPID='"+companyid+"'
DataSet dsACCOUNT = T_ALL_DA.GetAllSQL(sSQL);
if (dsACCOUNT != null)
{
if (dsACCOUNT.Tables[0].Rows.Count > 0)
{
int isLS = 0;
for (int i = 0; i < dsACCOUNT.Tables[0].Rows.Count; i++)
{
sSQL = "SELECT count(*) as inum from cw_accitems_gl INNER JOIN sys_bank on cw_accitems_gl.ACCID=sys_bank.CWGLACCID where sys_bank.BANKNAME in ('" + dsACCOUNT.Tables[0].Rows[i]["ACCOUNT"].ToString().Trim() + "') and cw_accitems_gl.[year]=SUBSTRING('" + strCwACCDATE + "',1,4) and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "'";// where CORPID='"+companyid+"'
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL));
if (inum == 0)
{
isLS++;
}
}
if (isLS > 0)
{
result.Success = false;
result.Message = "请先设置账户总账代码信息!" + result.Message;
return result;
}
}
}
//帐套设置_核算科目
sSQL = "SELECT [GID],[LINKGID],[ITEMGID],[OPTYPE],[MODIFIEDUSER],[MODIFIEDTIME],[MODIFIEDUSERNAME]=(select top 1 SHOWNAME from [user] where gid=[cw_design_gl_item].MODIFIEDUSER),[ITEMCODE]=(SELECT top 1 ITEMCODE from cw_item where GID=[cw_design_gl_item].[ITEMGID]),[ITEMNAME]=(SELECT top 1 ITEMNAME from cw_item where GID=[cw_design_gl_item].[ITEMGID]) FROM [cw_design_gl_item] WITH(NOLOCK) where LINKGID in (SELECT top 1 GID from cw_design_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "') ORDER BY [ITEMCODE]";
DataSet dsCwDesignItem = T_ALL_DA.GetAllSQL(sSQL);
//判断总账科目是否完全配置好
//判断是否有核算项目的科目
if (dsCwDesignItem == null)
{
//现金
sSQL = "SELECT COUNT(*) as inum from cw_accitems_gl where ISITEMACC=1 and ACCID in ('" + dsCwDesign.Tables[0].Rows[0]["CASH"].ToString().Trim() + "') and [STARTGID]='" + strCwSTARTGID + "'";
sNum = T_ALL_DA.GetStrSQL("inum", sSQL);
if (sNum != "" && sNum != "0")
{
result.Success = false;
result.Message = "请先设置帐套信息中的核算项目匹配设置!" + result.Message;
return result;
}
//银行
sSQL = "SELECT COUNT(*) as inum from cw_accitems_gl where ISITEMACC=1 and ACCID in (select CWGLACCID from sys_bank where CWGLACCID<>'' and CWGLACCID is not null) and [STARTGID]='" + strCwSTARTGID + "'";
sNum = T_ALL_DA.GetStrSQL("inum", sSQL);
if (sNum != "" && sNum != "0")
{
result.Success = false;
result.Message = "请先设置银行信息中的核算项目匹配设置!" + result.Message;
return result;
}
}
#endregion
string[] items = strGids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
int n = 0;
if (items.Length > 0)
{
for (int i = 0; i < items.Length; i++)
{
sAndGids = " and BXGID in ('" + items[i].ToString().Trim().Replace(",", "','") + "')";
DBResult result2 = GetIsVoucher(items[i].ToString().Trim(), strUserID);
if (!result2.Success)
{
strError = result2.Message;
}
else
{
#region 判断贷方科目是否存在当前账套中
string blSQL = "select count(*) as iNum from VW_OA_Baoxiao_Pay WITH(NOLOCK) where OPERATORSIDE_gl not in (select accid from cw_accitems_gl where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]='" + strCwACCDATE.Substring(0, 4) + "' and DETAILED=1)" + sAndGids;
int iNum = int.Parse(T_ALL_DA.GetStrSQL("iNum", blSQL));
if (iNum > 0)
{
strError = "录入的科目不存在当前账套中,请重新选择!";
continue;
}
#endregion
#region 提前生成凭证号
string sACCDATE = headData.VOUDATE.Substring(0, 7);
if (DateTime.Parse(sACCDATE + "-01") < DateTime.Parse(strCwACCDATE + "-01"))
{
sACCDATE = strCwACCDATE;
}
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();
string strVOUNOhj = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW, sACCDATE, strUserID);
string[] items2 = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
string strVOUNO = items2[3].ToString().Trim();
string sACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (sACCMONTH.ToString().Length == 1)
{
sACCMONTH = "0" + sACCMONTH.ToString();//月
}
string cfVOUALLNO = strBPVW + DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString() + sACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
#endregion
#region 把凭证号和业务GID插入到凭证生成的关系表
blSQL = "INSERT INTO [cw_vouno_bs_gl]([GID],[BSTABLENAME],[BSGID],[VOUALLNO],[ORDNO],[STARTGID],[CREATEUSER],[CREATETIME])"
+ "select newid() as [GID],'OA_Baoxiao' as [BSTABLENAME],BXGID as [BSGID],'" + cfVOUALLNO + "' as [VOUALLNO],'' as [ORDNO],'" + strCwSTARTGID + "' as [STARTGID],'" + strUserID + "' as [CREATEUSER],getdate() as [CREATETIME]"
+ " from OA_Baoxiao WITH(NOLOCK) where 1=1" + sAndGids + " and BXGID not in (select BSGID from cw_vouno_bs_gl WITH(NOLOCK) where BSTABLENAME='OA_Baoxiao' and [STARTGID]='" + strCwSTARTGID + "')";
#endregion
int iCount = db.ExecuteNonQuery(CommandType.Text, blSQL);
if (iCount != 0)
{
iResult = getSC(dsCwDesign, dsCwDesignItem, sAndGids, headData, bodyList, strCwACCDATE, strUserID, companyid, cfVOUALLNO);
zt += "," + iResult;
if (zt.IndexOf("-") < 0)
{
n++;
}
}
else
{
strError = "有已经生成凭证的数据,不允许重复生成,请重新选择!";
continue;
}
}
}
}
if (strError.Trim() != "")
{
sError = strError.Trim() + "</br>";
}
sError = "共" + items.Length + "票单据,生成" + n + "条凭证,失败" + (items.Length - n) + "条凭证!";
result.Success = true;
result.Message = sError;//"操作完成!";
return result;
}
/// <summary>
/// 生成凭证
/// </summary>
/// <param name="ds">帐套设置数据集</param>
/// <param name="sGids">gid业务编号</param>
/// <returns></returns>
protected static int getSC(DataSet dsCwDesign, DataSet dsCwDesignItem, string sAndGids, MsCwVouchersGl3 headData, List<MsCwVouchersGl4> bodyList, string strACCDATE, string strUserID, string strCompanyID, string cfVOUALLNO)
{
var result = new DBResult();
#region 基本变量
//全部
string sSQL = "";
string strFCY = "RMB";
Decimal dEXCHANGERATE = 0;
//总合计
Decimal strJie = 0;
Decimal strDai = 0;
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();//凭证字
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCondition = sAndGids + " and BXGID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='OA_Baoxiao' and VOUALLNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "')";
#endregion
#region 科目设置
//科目设置 现金
sSQL = "SELECT top 1 * from cw_accitems_gl where ACCID='" + dsCwDesign.Tables[0].Rows[0]["CASH"].ToString().Trim() + "' and [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "'";
DataSet dsCASH = T_ALL_DA.GetAllSQL(sSQL);
//科目设置 银行账号
sSQL = "SELECT cw_accitems_gl.*,sys_bank.GID as BankGid,sys_bank.BANKNAME from cw_accitems_gl INNER JOIN sys_bank on cw_accitems_gl.ACCID=sys_bank.CWGLACCID where cw_accitems_gl.[YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and cw_accitems_gl.[STARTGID]='" + strCwSTARTGID + "' and sys_bank.BANKNAME in (select ACCOUNT from (SELECT isnull(REASON,'') as ACCOUNT from VW_OA_Baoxiao_chFee where 1=1" + strCondition + " and REASON<>'' and REASON is not NULL) as a group by ACCOUNT)";
DataSet dsBank = T_ALL_DA.GetAllSQL(sSQL);
//科目设置 其他科目
sSQL = "SELECT * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and accid in (select OPERATORSIDE_gl from VW_OA_Baoxiao_Pay where 1=1" + strCondition + " and OPERATORSIDE_gl<>'' and OPERATORSIDE_gl is not NULL)";
DataSet dsOther = T_ALL_DA.GetAllSQL(sSQL);
//科目设置 汇兑损益
sSQL = "SELECT top 1 * from cw_accitems_gl where ACCID='" + dsCwDesign.Tables[0].Rows[0]["EGOL"].ToString().Trim() + "' and [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "'";
DataSet dsEGOL = T_ALL_DA.GetAllSQL(sSQL);
#endregion
#region 摘要
string strISEXPLANdai = ",REMARK_F";
string strISEXPLANjie = ",REMARK_P";
#region 屏蔽的摘要判断
//if (dsCwDesign.Tables[0].Rows[0]["ISRPCLIENTNAME"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",CUSTOMERSIDE";//是否收付客户名称
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISRPCUSTNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",CUSTNO";//是否收付委托编号
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISRPMBLNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",MBLNO";//是否收付主提单号
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISRPVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VESSEL";//是否收付船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISRPVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VOYNO";//是否收付航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISRPBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",BSSOURCE";//是否收付业务来源
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISRPBILLNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",BILLNO";//是否收付结算单号
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISRPBILLNO_ACAD"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",BILLNO_ACAD";//是否收付申请单号
//}
#endregion
#endregion
#region 基本数据集
#region 基本信息
string strORDNO = getGid();
string sqlCASH = "";
string sqlBank = "";
ArrayList alBank = new ArrayList();
ArrayList alBankDs = new ArrayList();
string sqlOther = "";
ArrayList alOther = new ArrayList();
ArrayList alOtherDs = new ArrayList();
IList<MsCwVouitemsGl> CwVouitemsEntities = new List<MsCwVouitemsGl>();
#endregion
#region 提取费率
string tbRATE = "";
string tbRATE_CASH = "";
//是否按照系统录入汇率
if (headData.ISRATE == true)
{
tbRATE = "EXCHANGERATE";
tbRATE_CASH = "EXCHANGERATE";
}
else
{
tbRATE = "EXCHANGERATE";
tbRATE_CASH = "(CASE";
if (bodyList != null)
{
if (bodyList.Count > 0)
{
for (int i = 0; i < bodyList.Count; i++)
{
tbRATE_CASH += " WHEN CURRENCY='" + bodyList[i].CURR.ToString().Trim() + "' THEN " + bodyList[i].FCYEXRATE.ToString().Trim();
}
}
}
tbRATE_CASH += " ELSE EXCHANGERATE END)";
}
#endregion
#region 贷方科目设置:现金、账户
#region 现金
#region 核算科目
string sISEXPLAN = "";
//是否核算客户
if (dsCASH.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
//是否核算人员
if (dsCASH.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsCASH.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID,DEPTNAME";//是否揽货人的部门
}
//是否核算项目
if (dsCASH.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsCASH.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
{
sqlCASH = "SELECT FEETYPE,CURRENCY,EXCHANGERATE,REASON"
+ ",SUM(je) AS je,SUM(hj) AS hj" + sISEXPLAN//,SETTLETYPE + strISEXPLAN
+ " from ("
+ "SELECT (CASE WHEN FEETYPE = 1 THEN '应收账款' WHEN FEETYPE=2 THEN '应付账款' ELSE '' END) as FEETYPE"
+ ",CURRENCY,EXCHANGERATE"
+ ",SUM(AMOUNT_F) AS je"
+ ",convert(decimal(18,2),round(SUM(AMOUNT_F*" + tbRATE_CASH + "),2)) AS hj"
+ sISEXPLAN + strISEXPLANdai
+ " From VW_OA_Baoxiao_chFee WHERE 1=1" + strCondition + " and REASON='现金'"
+ " GROUP BY EXCHANGERATE,CURRENCY,REASON,FEETYPE" + sISEXPLAN + strISEXPLANdai
+ ") as a"
+ " GROUP BY EXCHANGERATE,CURRENCY,REASON,FEETYPE" + sISEXPLAN + strISEXPLANdai
+ " ORDER BY CURRENCY,FEETYPE" + sISEXPLAN + strISEXPLANdai;
}
else
{
sqlCASH = "SELECT (CASE WHEN FEETYPE = 1 THEN '应收账款' WHEN FEETYPE=2 THEN '应付账款' ELSE '' END) as FEETYPE,'RMB' as CURRENCY,1 as EXCHANGERATE"
+ ",SUM(AMOUNT_F) AS je"
+ ",convert(decimal(18,2),round(SUM(AMOUNT_F*" + tbRATE_CASH + "),2)) AS hj"
+ sISEXPLAN + strISEXPLANdai
+ " From VW_OA_Baoxiao_chFee WHERE 1=1" + strCondition + " and REASON='现金'"
+ " GROUP BY FEETYPE" + sISEXPLAN + strISEXPLANdai
+ " ORDER BY FEETYPE" + sISEXPLAN + strISEXPLANdai;
}
#endregion
#region 银行账户
if (dsBank != null)
{
for (int i = 0; i < dsBank.Tables[0].Rows.Count; i++)
{
#region 循环账户
#region 核算科目
sISEXPLAN = "";
//是否核算客户
if (dsBank.Tables[0].Rows[i]["ISCORPACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
//是否核算人员
if (dsBank.Tables[0].Rows[i]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsBank.Tables[0].Rows[i]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID,DEPTNAME";//是否揽货人的部门
}
//是否核算项目
if (dsBank.Tables[0].Rows[i]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
//ISFCY 是否核算外币
if (dsBank.Tables[0].Rows[i]["ISFCY"].ToString().Trim() == "True")
{
sqlBank = "SELECT FEETYPE,CURRENCY,EXCHANGERATE,REASON"
+ ",SUM(je) AS je,SUM(hj) AS hj" + sISEXPLAN + strISEXPLANdai
+ " from ("
+ "SELECT (CASE WHEN FEETYPE = 1 THEN '应收账款' WHEN FEETYPE=2 THEN '应付账款' ELSE '' END) as FEETYPE"
+ ",CURRENCY,EXCHANGERATE"
+ ",SUM(AMOUNT_F) AS je"
+ ",convert(decimal(18,2),round(SUM(AMOUNT_F*" + tbRATE_CASH + "),2)) AS hj"
+ sISEXPLAN + strISEXPLANdai
+ " From VW_OA_Baoxiao_chFee WHERE 1=1" + strCondition
+ " and REASON='" + dsBank.Tables[0].Rows[i]["ACCNAME"].ToString().Trim() + "'"
+ " GROUP BY EXCHANGERATE,CURRENCY,REASON,FEETYPE" + sISEXPLAN + strISEXPLANdai
+ ") as a"
+ " GROUP BY EXCHANGERATE,CURRENCY,REASON,FEETYPE" + sISEXPLAN + strISEXPLANdai
+ " ORDER BY CURRENCY,FEETYPE" + sISEXPLAN + strISEXPLANdai;
}
else
{
sqlBank = "SELECT (CASE WHEN FEETYPE = 1 THEN '应收账款' WHEN FEETYPE=2 THEN '应付账款' ELSE '' END) as FEETYPE"
+ ",'RMB' as CURRENCY,1 as EXCHANGERATE,REASON"
+ ",SUM(AMOUNT_F) AS je"
+ ",convert(decimal(18,2),round(SUM(AMOUNT_F*" + tbRATE_CASH + "),2)) AS hj"
+ sISEXPLAN + strISEXPLANdai
+ " From VW_OA_Baoxiao_chFee WHERE 1=1" + strCondition
+ " and REASON='" + dsBank.Tables[0].Rows[i]["ACCNAME"].ToString().Trim() + "'"
+ " GROUP BY FEETYPE,REASON" + sISEXPLAN + strISEXPLANdai
+ " ORDER BY FEETYPE,REASON" + sISEXPLAN + strISEXPLANdai;
}
alBank.Add(sqlBank);
#endregion
}
}
#endregion
#endregion
#region 借方科目设置其他科目dsOther
if (dsOther != null)
{
for (int i = 0; i < dsOther.Tables[0].Rows.Count; i++)
{
#region 循环其他科目
#region 核算科目
sISEXPLAN = "";
//是否核算客户
if (dsOther.Tables[0].Rows[i]["ISCORPACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",CUSTOMERNAME";//是否委托单位
}
//是否核算人员
if (dsOther.Tables[0].Rows[i]["ISEMPLACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",SALE";//是否揽货人
}
//是否核算部门
if (dsOther.Tables[0].Rows[i]["ISDEPTACC"].ToString().Trim() == "True")
{
sISEXPLAN += ",DEPTGID,DEPTNAME";//是否揽货人的部门
}
//是否核算项目
if (dsOther.Tables[0].Rows[i]["ISITEMACC"].ToString().Trim() == "True")
{
if (dsCwDesignItem != null)
{
sISEXPLAN += ",OPLBNAME";//是否核算项目
}
}
#endregion
sqlOther = "SELECT 'RMB' as CURRENCY,1 as EXCHANGERATE,SUM(AMOUNT_P) AS je,SUM(AMOUNT_P) AS hj,OPERATORSIDE_gl" + sISEXPLAN + strISEXPLANjie
+ " From VW_OA_Baoxiao_Pay WHERE 1=1" + strCondition
+ " and OPERATORSIDE_gl='" + dsOther.Tables[0].Rows[i]["ACCID"].ToString().Trim() + "'"
+ " GROUP BY OPERATORSIDE_gl" + sISEXPLAN + strISEXPLANjie
+ " ORDER BY OPERATORSIDE_gl" + sISEXPLAN + strISEXPLANjie;
alOther.Add(sqlOther);
#endregion
}
}
#endregion
#region 数据集
DataSet dsVwcfsdCASH = null;
if (sqlCASH.Trim() != "")
{
dsVwcfsdCASH = T_ALL_DA.GetAllSQL(sqlCASH);
}
if (alBank != null)
{
if (alBank.Count > 0)
{
for (int i = 0; i < alBank.Count; i++)
{
DataSet dsVwcfsdBank = null;
if (alBank[i].ToString().Trim() != "")//sqlBank
{
dsVwcfsdBank = T_ALL_DA.GetAllSQL(alBank[i].ToString().Trim());//sqlBank
if (dsVwcfsdBank != null)
{
if (dsVwcfsdBank.Tables[0].Rows.Count > 0)
{
alBankDs.Add(dsVwcfsdBank);
}
}
}
}
}
}
if (alOther != null)
{
if (alOther.Count > 0)
{
for (int i = 0; i < alOther.Count; i++)
{
DataSet dsVwcfsdOther = null;
if (alOther[i].ToString().Trim() != "")//sqlOther
{
dsVwcfsdOther = T_ALL_DA.GetAllSQL(alOther[i].ToString().Trim());//sqlOther
if (dsVwcfsdOther != null)
{
if (dsVwcfsdOther.Tables[0].Rows.Count > 0)
{
alOtherDs.Add(dsVwcfsdOther);
}
}
}
}
}
}
#endregion
#endregion
if ((dsVwcfsdCASH != null || alBankDs.Count > 0) && alOtherDs.Count > 0)
{
#region 明细表_实体类
#region 插入明细表 现金
if (dsVwcfsdCASH != null)
{
if (dsVwcfsdCASH.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsVwcfsdCASH.Tables[0].Rows.Count; i++)
{
if (dsVwcfsdCASH.Tables[0].Rows[i]["hj"].ToString().Trim() == "")
{
continue;
}
#region 插入明细表 现金_全额
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
MsCwVouitemsGl.ACCID = dsCASH.Tables[0].Rows[0]["ACCID"].ToString().Trim();//科目代码
MsCwVouitemsGl.ACCNAME = dsCASH.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
//
if (dsVwcfsdCASH.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
MsCwVouitemsGl.AMTDR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVwcfsdCASH.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
strJie = strJie + Decimal.Parse(dsVwcfsdCASH.Tables[0].Rows[i]["hj"].ToString().Trim());
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
}
else
{
MsCwVouitemsGl.AMTDR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(dsVwcfsdCASH.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
strJie = strJie + Decimal.Parse(dsVwcfsdCASH.Tables[0].Rows[i]["hj"].ToString().Trim());
MsCwVouitemsGl.ISFCY = true;//是否外币
MsCwVouitemsGl.FCYDR = 0;//外币贷方金额
MsCwVouitemsGl.FCYCR = Decimal.Parse(dsVwcfsdCASH.Tables[0].Rows[i]["je"].ToString().Trim());//外币借方金额
}
MsCwVouitemsGl.DC = "C";//贷方向
strBPVW = dsCwDesign.Tables[0].Rows[0]["BPVW"].ToString().Trim();
MsCwVouitemsGl.FCYNO = dsVwcfsdCASH.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币编号usd
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(dsVwcfsdCASH.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = Decimal.Parse(dsVwcfsdCASH.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsCASH.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsCASH.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsCASH.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsCASH.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (dsCASH.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = dsVwcfsdCASH.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (dsCASH.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = dsVwcfsdCASH.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (dsCASH.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = dsVwcfsdCASH.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + dsVwcfsdCASH.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (dsCASH.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int j = 0; j < dsCwDesignItem.Tables[0].Rows.Count; j++)
{
if (dsVwcfsdCASH.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[j]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[j]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[j]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(dsCASH.Tables[0].Rows[0]["PACCGID"].ToString(), MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.BLNO = "";
MsCwVouitemsGl.EXPLAN = dsVwcfsdCASH.Tables[0].Rows[i]["REMARK_F"].ToString().Trim();//摘要规则生成ALL
//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//strDEPTID;//部门(系统)
MsCwVouitemsGl.EMPLID = "";//strEMPLID;//人员(系统)
MsCwVouitemsGl.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.ISSYS = true;//是否手动录入
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
}
}
#endregion
#region 插入明细表 账户
if (alBankDs != null)
{
if (alBankDs.Count > 0)
{
for (int j = 0; j < alBankDs.Count; j++)
{
DataSet ds = (DataSet)alBankDs[j];
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
#region 插入明细表 现金_全额
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["hj"].ToString().Trim() == "")
{
continue;
}
#region 插入明细表 现金_全额
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
//MsCwVouitemsGl.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString().Trim();//科目代码
//MsCwVouitemsGl.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
string lsPACCGID = "";// ds.Tables[0].Rows[0]["PACCGID"].ToString().Trim();
if (dsBank != null)
{
if (dsBank.Tables[0].Rows.Count > 0)
{
for (int k = 0; k < dsBank.Tables[0].Rows.Count; k++)
{
if (ds.Tables[0].Rows[i]["REASON"].ToString().Trim() == dsBank.Tables[0].Rows[k]["BANKNAME"].ToString().Trim())
{
MsCwVouitemsGl.ACCID = dsBank.Tables[0].Rows[k]["ACCID"].ToString().Trim();//科目代码
MsCwVouitemsGl.ACCNAME = dsBank.Tables[0].Rows[k]["ACCNAME"].ToString().Trim();//科目名称
lsPACCGID = dsBank.Tables[0].Rows[0]["PACCGID"].ToString().Trim();
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsBank.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsBank.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsBank.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsBank.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
}
}
}
}
//
if (ds.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
MsCwVouitemsGl.AMTDR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
strJie = strJie + Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
}
else
{
MsCwVouitemsGl.AMTDR = 0;//本位币贷方金额(互斥)
MsCwVouitemsGl.AMTCR = Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
strJie = strJie + Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());
MsCwVouitemsGl.ISFCY = true;//是否外币
MsCwVouitemsGl.FCYDR = 0;//外币贷方金额
MsCwVouitemsGl.FCYCR = Decimal.Parse(ds.Tables[0].Rows[i]["je"].ToString().Trim());//外币借方金额
}
MsCwVouitemsGl.DC = "C";//借方向
strBPVW = dsCwDesign.Tables[0].Rows[0]["BPVW"].ToString().Trim();
MsCwVouitemsGl.FCYNO = ds.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币编号usd
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(ds.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = Decimal.Parse(ds.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (MsCwVouitemsGl.ISCORPACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = ds.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (MsCwVouitemsGl.ISEMPLACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = ds.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (MsCwVouitemsGl.ISDEPTACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = ds.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
strACCALL += "▁" + ds.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (MsCwVouitemsGl.ISITEMACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int k = 0; k < dsCwDesignItem.Tables[0].Rows.Count; k++)
{
if (ds.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[k]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[k]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[k]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(lsPACCGID, MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.BLNO = "";
MsCwVouitemsGl.EXPLAN = ds.Tables[0].Rows[i]["REMARK_F"].ToString().Trim();//摘要规则生成ALL
//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//strDEPTID;//部门(系统)
MsCwVouitemsGl.EMPLID = "";//strEMPLID;//人员(系统)
MsCwVouitemsGl.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.ISSYS = true;//是否手动录入
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
#endregion
}
}
}
}
}
#endregion
#region 插入明细表 其他科目
if (alOtherDs != null)
{
if (alOtherDs.Count > 0)
{
for (int j = 0; j < alOtherDs.Count; j++)
{
DataSet ds = (DataSet)alOtherDs[j];
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
#region 插入明细表 现金_全额
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["hj"].ToString().Trim() == "")
{
continue;
}
#region 插入明细表 现金_全额
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl();
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl.ORDNO = strORDNO.Trim();
MsCwVouitemsGl.ITEMNO = 0;//行号
MsCwVouitemsGl.PACCID = "";//父级科目贷码
MsCwVouitemsGl.PROPERTY = 0;//科目属性
MsCwVouitemsGl.GRADE = 0;//科目级别
//MsCwVouitemsGl.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString().Trim();//科目代码
//MsCwVouitemsGl.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
string lsPACCGID = "";// ds.Tables[0].Rows[0]["PACCGID"].ToString().Trim();
if (dsOther != null)
{
if (dsOther.Tables[0].Rows.Count > 0)
{
for (int k = 0; k < dsOther.Tables[0].Rows.Count; k++)
{
if (ds.Tables[0].Rows[i]["OPERATORSIDE_gl"].ToString().Trim() == dsOther.Tables[0].Rows[k]["ACCID"].ToString().Trim())
{
MsCwVouitemsGl.ACCID = dsOther.Tables[0].Rows[k]["ACCID"].ToString().Trim();//科目代码
MsCwVouitemsGl.ACCNAME = dsOther.Tables[0].Rows[k]["ACCNAME"].ToString().Trim();//科目名称
lsPACCGID = dsOther.Tables[0].Rows[0]["PACCGID"].ToString().Trim();
MsCwVouitemsGl.ISDEPTACC = Boolean.Parse(dsOther.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
MsCwVouitemsGl.ISEMPLACC = Boolean.Parse(dsOther.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
MsCwVouitemsGl.ISCORPACC = Boolean.Parse(dsOther.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
MsCwVouitemsGl.ISITEMACC = Boolean.Parse(dsOther.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
}
}
}
}
//
if (ds.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
MsCwVouitemsGl.AMTDR = Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币借方金额(互斥)
strDai = strDai + Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());
MsCwVouitemsGl.ISFCY = false;//是否外币
MsCwVouitemsGl.FCYDR = 0;//外币借方金额
MsCwVouitemsGl.FCYCR = 0;//外币贷方金额
}
else
{
MsCwVouitemsGl.AMTDR = Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币贷方金额(互斥)
MsCwVouitemsGl.AMTCR = 0;//本位币借方金额(互斥)
strDai = strDai + Decimal.Parse(ds.Tables[0].Rows[i]["hj"].ToString().Trim());
MsCwVouitemsGl.ISFCY = true;//是否外币
MsCwVouitemsGl.FCYDR = Decimal.Parse(ds.Tables[0].Rows[i]["je"].ToString().Trim());//外币贷方金额
MsCwVouitemsGl.FCYCR = 0;//外币借方金额
}
MsCwVouitemsGl.DC = "D";//借方向
strBPVW = dsCwDesign.Tables[0].Rows[0]["BPVW"].ToString().Trim();
MsCwVouitemsGl.FCYNO = ds.Tables[0].Rows[i]["CURRENCY"].ToString().Trim();//外币编号usd
MsCwVouitemsGl.FCYEXRATE = Decimal.Parse(ds.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = Decimal.Parse(ds.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
//
string strACCALL = "";
//是否核算客户
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = "";//客户(系统)
if (MsCwVouitemsGl.ISCORPACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.CORPID = "";//客户(系统)
MsCwVouitemsGl.CUSTOMERNAME = ds.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
strACCALL += "▁" + MsCwVouitemsGl.CUSTOMERNAME;
}
//是否核算人员_揽货人
if (MsCwVouitemsGl.ISEMPLACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.SALE = ds.Tables[0].Rows[i]["SALE"].ToString().Trim();//人员名称
strACCALL += "▁" + MsCwVouitemsGl.SALE;
}
//是否核算部门
if (MsCwVouitemsGl.ISDEPTACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.DEPTGID = ds.Tables[0].Rows[i]["DEPTGID"].ToString().Trim();//揽货人的部门
// strACCALL += "▁" + ds.Tables[0].Rows[i]["DEPTNAME"].ToString().Trim();
}
//是否核算项目
if (MsCwVouitemsGl.ISITEMACC.ToString().Trim() == "True")
{
MsCwVouitemsGl.ITEMGID = "";
if (dsCwDesignItem != null)
{
for (int k = 0; k < dsCwDesignItem.Tables[0].Rows.Count; k++)
{
if (ds.Tables[0].Rows[0]["OPLBNAME"].ToString().Trim() == dsCwDesignItem.Tables[0].Rows[k]["OPTYPE"].ToString().Trim())
{
MsCwVouitemsGl.ITEMGID = dsCwDesignItem.Tables[0].Rows[k]["ITEMGID"].ToString().Trim();//是否核算项目
strACCALL += "▁" + dsCwDesignItem.Tables[0].Rows[k]["ITEMNAME"].ToString().Trim();
}
}
}
}
MsCwVouitemsGl.ACCALL = BasicDataRefDAL.setCAGA(lsPACCGID, MsCwVouitemsGl.ACCNAME.ToString().Trim()) + strACCALL;
MsCwVouitemsGl.BLNO = "";
MsCwVouitemsGl.EXPLAN = ds.Tables[0].Rows[i]["REMARK_P"].ToString().Trim();//摘要规则生成ALL
//
MsCwVouitemsGl.QTYUNIT = "";//数量包装单位
MsCwVouitemsGl.QTYDR = 0;//借方数量
MsCwVouitemsGl.QTYCR = 0;//贷方数量
MsCwVouitemsGl.DEPTID = "";//strDEPTID;//部门(系统)
MsCwVouitemsGl.EMPLID = "";//strEMPLID;//人员(系统)
MsCwVouitemsGl.SALE = "";//strSALE;//人员名称
MsCwVouitemsGl.PITEMID = 0;//父级项目编号
MsCwVouitemsGl.ITEMID = "";//项目编号
MsCwVouitemsGl.FIELD1 = "";//预留字段1
MsCwVouitemsGl.FIELD2 = "";//预留字段2
MsCwVouitemsGl.FIELD3 = "";//预留字段3
MsCwVouitemsGl.FIELD4 = "";//预留字段4
MsCwVouitemsGl.FIELD5 = "";//预留字段5
MsCwVouitemsGl.FIELD6 = "";//预留字段6
MsCwVouitemsGl.FIELD7 = "";//预留字段7
MsCwVouitemsGl.FIELD8 = "";//预留字段8
MsCwVouitemsGl.FIELD9 = "";//预留字段9
MsCwVouitemsGl.FIELD10 = "";//预留字段10
MsCwVouitemsGl.ISSYS = true;//是否手动录入
MsCwVouitemsGl.FSETTLCODE = "";//结算方式
MsCwVouitemsGl.FSETTLENO = "";//财务辅助编号
MsCwVouitemsGl.FSETTLDATE = DateTime.Parse(DateTime.Parse(headData.VOUDATE).ToString("yyyy-MM-dd"));//结算日期
MsCwVouitemsGl.CREATEUSER = strUserID;//创建人
MsCwVouitemsGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouitemsGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouitemsGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
CwVouitemsEntities.Add(MsCwVouitemsGl);
}
#endregion
}
}
}
}
}
#endregion
#endregion
#region 插入主表
MsCwVouchersGl MsCwVouchersGl = new MsCwVouchersGl();
MsCwVouchersGl.ORDNO = strORDNO.Trim();//唯一编码 newid() varchar (36)
MsCwVouchersGl.VOUDATE = headData.VOUDATE;//凭证日期
////strY + "~" + strM + "~" + sVOUNO + "~" + strVOUNO + "~" + strVOUDATE + "~" + strACCDATE;
//string sACCDATE = headData.VOUDATE.Substring(0, 7);
//if (DateTime.Parse(sACCDATE + "-01") < DateTime.Parse(strACCDATE + "-01"))
//{
// sACCDATE = strACCDATE;
//}
//string strVOUNOhj = MsBaseInfoDAL.GetCwVOUNO(strBPVW.Trim(), sACCDATE, strUserID);
//string[] items = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
//string sVOUNO = items[2].ToString().Trim();
//string strVOUNO = items[3].ToString().Trim();
//MsCwVouchersGl.VOUNO = sVOUNO;//月初清零 varchar (16)
MsCwVouchersGl.VOUNO = int.Parse(cfVOUALLNO.Trim().Substring(cfVOUALLNO.Trim().Length-4)).ToString();//sVOUNO;//月初清零 varchar (16)
MsCwVouchersGl.ACCYEAR = DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString();//年
MsCwVouchersGl.ACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (MsCwVouchersGl.ACCMONTH.ToString().Length == 1)
{
MsCwVouchersGl.ACCMONTH = "0" + MsCwVouchersGl.ACCMONTH.ToString();//月
}
MsCwVouchersGl.VKNO = strBPVW.Trim();//凭证字
//MsCwVouchersGl.VOUALLNO = MsCwVouchersGl.VKNO + MsCwVouchersGl.ACCYEAR + MsCwVouchersGl.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
MsCwVouchersGl.VOUALLNO = cfVOUALLNO.Trim().Replace("记", strBPVW.Trim());//年+月+自动生成编号=凭证号
MsCwVouchersGl.ATTACHS = 1;// int.Parse(dsCwDesign.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim());//附件(单据)数
MsCwVouchersGl.AMTDR = strJie;// iAMTDR;//本位币借方
MsCwVouchersGl.AMTCR = strDai;//iAMTDR;// iAMTCR;//本位币贷方
MsCwVouchersGl.FCY = strFCY;//是否含有外币科目
MsCwVouchersGl.QTY = "";//是否含有数量科目
MsCwVouchersGl.VOUPROP = "";//凭证属性
MsCwVouchersGl.PREPARED = headData.PREPARED.ToString().Trim();//制单人
MsCwVouchersGl.CHECKED = "";//审核人
MsCwVouchersGl.ENTERED = "";//记账人
MsCwVouchersGl.ERRMSG = "";//错误信息
MsCwVouchersGl.ISDELETE = false;//是否废除
MsCwVouchersGl.DELETEUSER = "";//废除操作人
MsCwVouchersGl.DbOperationType = DbOperationType.DbotIns;
MsCwVouchersGl.STARTGID = strCwSTARTGID;
MsCwVouchersGl.CREATEUSER = strUserID;//创建人
MsCwVouchersGl.CREATETIME = DateTime.Now;//创建时间
MsCwVouchersGl.MODIFIEDUSER = strUserID;//最后一次更新操作人
MsCwVouchersGl.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
#endregion
#region 生成入库
var modb = new ModelObjectDB();
result = modb.Save(MsCwVouchersGl);
if (result.Success == true)
{
2 years ago
//int n = 1;
2 years ago
BasicDataRefDAL.SetGLOrder(ref CwVouitemsEntities);
3 years ago
foreach (var enumValue in CwVouitemsEntities)
{
enumValue.GID = Guid.NewGuid().ToString();
2 years ago
//enumValue.ITEMNO = n;//行号
3 years ago
enumValue.DbOperationType = DbOperationType.DbotIns;
var modb2 = new ModelObjectDB();
DBResult result2 = modb2.Save(enumValue);
2 years ago
//n++;
3 years ago
}
//更新凭证生成关系表中的ORDNO数据
string strLS = sAndGids.Replace("BXGID", "BSGID");
string blSQL = "update [cw_vouno_bs_gl] set ORDNO='" + MsCwVouchersGl.ORDNO + "' where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='OA_Baoxiao' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
blSQL = "update code_fill_serialno set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=GETDATE() where TABLENAME='cw_vouchers_gl' and SERIALNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "'";
bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
}
else
{
//result.Success = false;
//result.Message = result.Message;
//return result;
//删除凭证生成关系表中的OA_Baoxiao的GID数据
string strLS = sAndGids.Replace("BXGID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='OA_Baoxiao' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -2;//重复数据
}
#endregion
}
else
{
//删除凭证生成关系表中的OA_Baoxiao的GID数据
string strLS = sAndGids.Replace("BXGID", "BSGID");
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='OA_Baoxiao' and [STARTGID]='" + strCwSTARTGID + "'" + strLS;
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
return -3;//结算无明细数据
}
//result.Success = true;
//result.Message = result.Message;
//return result;
return 1;
}
#endregion
#region 判断是否生成
public static String getGid()
{
string strgid = Guid.NewGuid().ToString();
strgid = strgid.Replace("-", "");
strgid = "VOU" + strgid;
return strgid;
}
public static DBResult GetIsVoucher(string strGids, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
var result = new DBResult();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "SELECT count(*) as inum from VW_OA_Baoxiao_chFee where BXGID in ('" + strGids.Trim().Replace(",", "','") + "') and (BXGID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "') or FEESTATUS=1 or REASON='' or REASON is null)";
int inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL));
if (inum == 0)
{
sSQL = "SELECT count(*) as inum from VW_OA_Baoxiao_Pay where BXGID in ('" + strGids.Trim().Replace(",", "','") + "') and (BXGID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "') or OPERATORSIDE_gl='' or OPERATORSIDE_gl is null)";
inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL));
if (inum == 0)
{
sSQL = "SELECT count(*) as inum from VW_OA_Baoxiao_Pay where BXGID in ('" + strGids.Trim().Replace(",", "','") + "') and BXGID not in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "')";
inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL));
if (inum == 0)
{
result.Success = false;
result.Message = "请选择已审核通过、支付方式、总账科目、结算方式不为空,且未生成凭证的单据!";
return result;
}
else
{
sSQL = "SELECT count(*) as inum from VW_OA_Baoxiao_chFee where BXGID in ('" + strGids.Trim().Replace(",", "','") + "') and BXGID not in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='OA_Baoxiao' and STARTGID='" + strCwSTARTGID + "')";
inum = int.Parse(T_ALL_DA.GetStrSQL("inum", sSQL));
if (inum == 0)
{
result.Success = false;
result.Message = "请选择已审核通过、支付方式、总账科目、结算方式不为空,且未生成凭证的单据!";
return result;
}
else
{
result.Success = true;
result.Message = "";
return result;
}
}
}
else
{
result.Success = false;
result.Message = "请选择已审核通过、支付方式、总账科目、结算方式不为空,且未生成凭证的单据!";
return result;
}
}
else
{
result.Success = false;
result.Message = "请选择已审核通过、支付方式、总账科目、结算方式不为空,且未生成凭证的单据!";
return result;
}
}
/// <summary>
/// 是否自动弹出结算总账凭证
/// </summary>
/// <returns></returns>
public static DBResult onIsSettlementsopen(string strUserID)
{
var result = new DBResult();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string sSQL = "SELECT top 1 ISSETTLEMENTSOPEN from cw_design_gl WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "'";
Boolean blISSETTLEMENTSOPEN = Boolean.Parse(T_ALL_DA.GetStrSQL("ISSETTLEMENTSOPEN", sSQL));
if (blISSETTLEMENTSOPEN)
{
result.Success = true;
result.Message = "";
return result;
}
else
{
result.Success = false;
result.Message = "";
return result;
}
}
#endregion
#endregion
}
internal class MsChFeeDealException : Exception
{
internal MsChFeeDealException(string message) : base(message)
{
}
}
//
}