@ -244,6 +244,7 @@ namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlInvoiceDAL
int iResult = 0 ;
int iResult = 0 ;
string zt = "" ;
string zt = "" ;
string sError = "操作完成!" ;
string sError = "操作完成!" ;
var invlist = strGids . Split ( ',' ) ;
string sAndGids = " and GID in ('" + strGids . Trim ( ) . Replace ( "," , "','" ) + "')" ;
string sAndGids = " and GID in ('" + strGids . Trim ( ) . Replace ( "," , "','" ) + "')" ;
var CWSTARTUSING = MsSysParamSetDAL . GetData ( "PARAMNAME='CWSTARTUSING'" ) ;
var CWSTARTUSING = MsSysParamSetDAL . GetData ( "PARAMNAME='CWSTARTUSING'" ) ;
@ -338,9 +339,17 @@ namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlInvoiceDAL
/ /
/ /
if ( iCount ! = 0 )
if ( iCount ! = 0 )
{
{
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISINVRATESELF" ] . ToString ( ) . Trim ( ) = = "True" )
iResult = getInvSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISINVAMOUNTASSUM" ] . ToString ( ) . Trim ( ) = = "True" )
else iResult = getHxtSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
{
iResult = getInvSumSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK , invlist ) ;
}
else
{
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISINVRATESELF" ] . ToString ( ) . Trim ( ) = = "True" )
iResult = getInvSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
else iResult = getHxtSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
}
zt + = "," + iResult ;
zt + = "," + iResult ;
if ( zt . IndexOf ( "-" ) > 0 )
if ( zt . IndexOf ( "-" ) > 0 )
{
{
@ -398,10 +407,19 @@ namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlInvoiceDAL
/ /
/ /
if ( iCount ! = 0 )
if ( iCount ! = 0 )
{
{
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISINVRATESELF" ] . ToString ( ) . Trim ( ) = = "True" )
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISINVAMOUNTASSUM" ] . ToString ( ) . Trim ( ) = = "True" )
iResult = getInvSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
{
iResult = getInvSumSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK , invlist ) ;
}
else
else
iResult = getHxtSC ( dsCwDesign , dsCwDesignItem , sAndGids , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
{
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISINVRATESELF" ] . ToString ( ) . Trim ( ) = = "True" )
iResult = getInvSC ( dsCwDesign , dsCwDesignItem , sAndGids . Trim ( ) , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
else
iResult = getHxtSC ( dsCwDesign , dsCwDesignItem , sAndGids , headData , bodyList , strUserID , companyid , cfVOUALLNO , VOUAUTOCHECK ) ;
}
zt + = "," + iResult ;
zt + = "," + iResult ;
if ( zt . IndexOf ( "-" ) < 0 )
if ( zt . IndexOf ( "-" ) < 0 )
{
{
@ -430,7 +448,7 @@ namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlInvoiceDAL
result . Message = sError ; //"操作完成!";
result . Message = sError ; //"操作完成!";
return result ;
return result ;
}
}
/// <summary>
/// <summary>
/// 生成凭证
/// 生成凭证
/// </summary>
/// </summary>
@ -439,6 +457,555 @@ namespace DSWeb.MvcShipping.DAL.MsCwVouchersGlInvoiceDAL
/// <returns></returns>
/// <returns></returns>
///
///
/* 按发票开票金额生成凭证*/
protected static int getInvSumSC ( DataSet dsCwDesign , DataSet dsCwDesignItem , string sAndGids , MsCwVouchersGl3 headData , List < MsCwVouchersGl4 > bodyList , string strUserID , string strCompanyID , string cfVOUALLNO , string VOUAUTOCHECK , string [ ] invlist )
{
var result = new DBResult ( ) ;
#region 基本变量
//全部
string sSQL = "" ;
string strEXPLAN = "" ;
string strFCY = "RMB" ;
Decimal dEXCHANGERATE = 0 ;
//应收应付账款
Decimal iAMTDR = 0 ;
Decimal iAMTCR = 0 ;
//差额主营业务收入
Decimal dRMBS = 0 ;
Decimal dRMBF = 0 ;
Decimal dUSDS = 0 ;
Decimal dUSDF = 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 strCwACCDATE = BasicDataRefDAL . GetCwACCDATE ( strUserID ) ;
string strCwSTARTGID = BasicDataRefDAL . GetCwSTARTGID ( strUserID ) ;
# endregion
#region 科目设置
//科目设置 应收RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "AR" ] . ToString ( ) . Trim ( ) + "'" ;
DataSet dsAR = T_ALL_DA . GetAllSQL ( sSQL ) ;
//科目设置 应收USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ARFC" ] . ToString ( ) . Trim ( ) + "'" ;
DataSet dsARFC = T_ALL_DA . GetAllSQL ( sSQL ) ;
//主营业务收入 收入RMB
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "MBINCOME" ] . ToString ( ) . Trim ( ) + "'" ;
DataSet dsMBINCOME = T_ALL_DA . GetAllSQL ( sSQL ) ;
//主营收入外币 收入USD
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "TMFCI" ] . ToString ( ) . Trim ( ) + "'" ;
DataSet dsTMFCI = T_ALL_DA . GetAllSQL ( sSQL ) ;
//销项税
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "OUTPUTTAX" ] . ToString ( ) . Trim ( ) + "'" ;
DataSet dsOUTPUTTAX = T_ALL_DA . GetAllSQL ( sSQL ) ;
# endregion
string DREXPLAN = dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "INVDREXPLAN" ] . ToString ( ) . Trim ( ) ;
string CREXPLAN = dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "INVCREXPLAN" ] . ToString ( ) . Trim ( ) ;
string MBINCOMEEXPLAN = dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "INVMBINCOMEEXPLAN" ] . ToString ( ) . Trim ( ) ;
string MBSPENDINGEXPLAN = dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "INVMBSPENDINGEXPLAN" ] . ToString ( ) . Trim ( ) ;
#region 摘要
string strISEXPLAN = "" ;
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISCLIENTNAME" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLAN + = ",CUSTOMERNAME" ; //是否收付客户名称CUSTOMERNAME
}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISCUSTNO" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLAN + = ",INVOICENO" ; //是否委托编号CUSTNO//发票号
}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISMBLNO" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLAN + = ",MBLNO" ; //是否主提单号
}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISSALE" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLAN + = ",SALE" ; //是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLAN += ",BSSOURCE";//是否业务来源
//}
string strISEXPLANnull = "" ;
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISMBINCOME" ] . ToString ( ) . Trim ( ) = = "False" ) //是否合并生成发票开出凭证中的主营业务科目
{
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISCLIENTNAME" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLANnull + = ",CUSTOMERNAME" ; //是否收付客户名称CUSTOMERNAME
}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISCUSTNO" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLANnull + = ",INVOICENO" ; //是否委托编号CUSTNO//发票号
}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISMBLNO" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLANnull + = ",MBLNO" ; //是否主提单号
}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISSALE" ] . ToString ( ) . Trim ( ) = = "True" )
{
strISEXPLANnull + = ",SALE" ; //是否主提单号
}
//if (dsCwDesign.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VESSEL";//是否船名
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",VOYNO";//是否航次
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBSSOURCE"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BSSOURCE";//是否业务来源
//}
//if (dsCwDesign.Tables[0].Rows[0]["ISBILLNO"].ToString().Trim() == "True")
//{
// strISEXPLANnull += ",BILLNO_ACAD";//是否申请单号
//}
}
# endregion
#region 票号
if ( strISEXPLAN . IndexOf ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "PiaoHao" ] . ToString ( ) . Trim ( ) ) < 0 )
{
strISEXPLAN + = "," + dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "PiaoHao" ] . ToString ( ) . Trim ( ) ;
}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISMBINCOME" ] . ToString ( ) . Trim ( ) = = "False" ) //是否合并生成发票开出凭证中的主营业务科目
{
if ( strISEXPLANnull . IndexOf ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "PiaoHao" ] . ToString ( ) . Trim ( ) ) < 0 )
{
strISEXPLANnull + = "," + dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "PiaoHao" ] . ToString ( ) . Trim ( ) ;
}
}
# endregion
#region 核算科目_分录
//string sqlItemAR = "";
//string sqlItemARFC = "";
//string sqlItemMBINCOME = "";
//string sqlItemTMFCI = "";
# endregion
#region 基本数据集
string strORDNO = getGid ( ) ;
string sqlAR = "" ;
string sqlARFC = "" ;
string sqlMBINCOME = "" ;
string sqlTMFCI = "" ;
string sqlOUTPUTTAX = "" ;
string sqlOUTPUTTAXUSD = "" ;
IList < MsCwVouitemsGl > CwVouitemsEntities = new List < MsCwVouitemsGl > ( ) ;
string strCondition = sAndGids + " and GID in (select [BSGID] from [cw_vouno_bs_gl] WITH(NOLOCK) where BSTABLENAME='ch_fee_invoice' and VOUALLNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "')" ;
//是否按照系统录入汇率
# endregion
sqlARFC = "SELECT * from ch_fee_invoice WHERE 1=1" + strCondition ;
DataSet dsVWChFeeAR = T_ALL_DA . GetAllSQL ( sqlARFC ) ;
Decimal strJie = 0 ;
Decimal strDai = 0 ;
if ( dsVWChFeeAR ! = null )
{
int n = 1 ;
foreach ( var invgid in invlist ) {
for ( int i = 0 ; i < dsVWChFeeAR . Tables [ 0 ] . Rows . Count ; i + + )
{
if ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "GID" ] . ToString ( ) . Trim ( ) = = invgid ) {
#region 摘要内容
strEXPLAN = "" ;
strEXPLAN = DREXPLAN ;
var ISEXPLAN = false ;
if ( strEXPLAN ! = "" ) ISEXPLAN = true ;
if ( ISEXPLAN )
{
strEXPLAN = strEXPLAN . Replace ( "[发票抬头]" , dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVOICECUSTNAME" ] . ToString ( ) . Trim ( ) ) ;
strEXPLAN = strEXPLAN . Replace ( "[发票号]" , dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVOICENO" ] . ToString ( ) . Trim ( ) ) ;
}
else
{
strEXPLAN + = "应收 " + dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "CUSTOMERNAME" ] . ToString ( ) . Trim ( ) + dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVOICENO" ] . ToString ( ) . Trim ( ) ;
}
# endregion
#region 应收账款
MsCwVouitemsGl MsCwVouitemsGl = new MsCwVouitemsGl ( ) ;
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl . ORDNO = strORDNO . Trim ( ) ;
MsCwVouitemsGl . ITEMNO = n ; // 行号
MsCwVouitemsGl . PACCID = "" ; //父级科目贷码
MsCwVouitemsGl . PROPERTY = 0 ; //科目属性
MsCwVouitemsGl . GRADE = 0 ; //科目级别
#region 应收账款
if ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "OTCURRAMOUNT" ] . ToString ( ) . Trim ( ) = = "0" )
{
iAMTDR = iAMTDR + Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVAMOUNT" ] . ToString ( ) . Trim ( ) ) ;
/ /
MsCwVouitemsGl . ACCID = dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "AR" ] . ToString ( ) . Trim ( ) ; //应收账款科目贷码
MsCwVouitemsGl . AMTDR = Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVAMOUNT" ] . ToString ( ) . Trim ( ) ) ; //本位币借方金额(互斥)
MsCwVouitemsGl . AMTCR = 0 ; //本位币贷方金额(互斥)
MsCwVouitemsGl . ISFCY = false ; //是否外币
MsCwVouitemsGl . FCYNO = "RMB" ; //外币编号usd
MsCwVouitemsGl . FCYDR = 0 ; //外币借方金额
MsCwVouitemsGl . FCYCR = 0 ; //外币贷方金额
dRMBS + = Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVAMOUNT" ] . ToString ( ) . Trim ( ) ) ; //本位币借方金额(互斥)
MsCwVouitemsGl . ACCNAME = dsAR . Tables [ 0 ] . Rows [ 0 ] [ "ACCNAME" ] . ToString ( ) . Trim ( ) ; //科目名称
MsCwVouitemsGl . ISDEPTACC = Boolean . Parse ( dsAR . Tables [ 0 ] . Rows [ 0 ] [ "ISDEPTACC" ] . ToString ( ) . Trim ( ) ) ; //核算部门,按规则设置生成
MsCwVouitemsGl . ISEMPLACC = Boolean . Parse ( dsAR . Tables [ 0 ] . Rows [ 0 ] [ "ISEMPLACC" ] . ToString ( ) . Trim ( ) ) ; //核算人员,按规则设置生成
MsCwVouitemsGl . ISCORPACC = Boolean . Parse ( dsAR . Tables [ 0 ] . Rows [ 0 ] [ "ISCORPACC" ] . ToString ( ) . Trim ( ) ) ; //核算客户,按规则设置生成
MsCwVouitemsGl . ISITEMACC = Boolean . Parse ( dsAR . Tables [ 0 ] . Rows [ 0 ] [ "ISITEMACC" ] . ToString ( ) . Trim ( ) ) ; //核算项目,按规则设置生成
if ( dsAR . Tables [ 0 ] . Rows [ 0 ] [ "DC" ] . ToString ( ) . Trim ( ) = = "借" )
{
MsCwVouitemsGl . DC = "D" ; //借方向
}
else
{
MsCwVouitemsGl . DC = "C" ; //贷方向
}
}
else
{
iAMTDR = iAMTDR + Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVAMOUNT" ] . ToString ( ) . Trim ( ) ) ;
/ /
MsCwVouitemsGl . ACCID = dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ARFC" ] . ToString ( ) . Trim ( ) ; //应收账款科目贷码
MsCwVouitemsGl . AMTDR = Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVAMOUNT" ] . ToString ( ) . Trim ( ) ) ; //本位币借方金额(互斥)
MsCwVouitemsGl . AMTCR = 0 ; //本位币贷方金额(互斥)
MsCwVouitemsGl . ISFCY = true ; //是否外币
MsCwVouitemsGl . FCYNO = dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "RECVCURR" ] . ToString ( ) ; //外币编号usd
MsCwVouitemsGl . FCYDR = Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "OTCURRAMOUNT" ] . ToString ( ) . Trim ( ) ) ; //外币借方金额
MsCwVouitemsGl . FCYCR = 0 ; //外币贷方金额
dRMBS + = Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVAMOUNT" ] . ToString ( ) . Trim ( ) ) ; //本位币借方金额(互斥)
MsCwVouitemsGl . ACCNAME = dsARFC . Tables [ 0 ] . Rows [ 0 ] [ "ACCNAME" ] . ToString ( ) . Trim ( ) ; //科目名称
MsCwVouitemsGl . ISDEPTACC = Boolean . Parse ( dsARFC . Tables [ 0 ] . Rows [ 0 ] [ "ISDEPTACC" ] . ToString ( ) . Trim ( ) ) ; //核算部门,按规则设置生成
MsCwVouitemsGl . ISEMPLACC = Boolean . Parse ( dsARFC . Tables [ 0 ] . Rows [ 0 ] [ "ISEMPLACC" ] . ToString ( ) . Trim ( ) ) ; //核算人员,按规则设置生成
MsCwVouitemsGl . ISCORPACC = Boolean . Parse ( dsARFC . Tables [ 0 ] . Rows [ 0 ] [ "ISCORPACC" ] . ToString ( ) . Trim ( ) ) ; //核算客户,按规则设置生成
MsCwVouitemsGl . ISITEMACC = Boolean . Parse ( dsARFC . Tables [ 0 ] . Rows [ 0 ] [ "ISITEMACC" ] . ToString ( ) . Trim ( ) ) ; //核算项目,按规则设置生成
if ( dsARFC . Tables [ 0 ] . Rows [ 0 ] [ "DC" ] . ToString ( ) . Trim ( ) = = "借" )
{
MsCwVouitemsGl . DC = "D" ; //借方向
}
else
{
MsCwVouitemsGl . DC = "C" ; //贷方向
}
}
strJie = strJie + MsCwVouitemsGl . AMTCR ;
/ /
string strACCALL = "" ;
//是否核算客户
MsCwVouitemsGl . CORPID = "" ; //客户(系统)
MsCwVouitemsGl . CUSTOMERNAME = "" ; //客户(系统)
if ( dsAR . Tables [ 0 ] . Rows [ 0 ] [ "ISCORPACC" ] . ToString ( ) . Trim ( ) = = "True" )
{
MsCwVouitemsGl . CORPID = "" ; //客户(系统)
MsCwVouitemsGl . CUSTOMERNAME = dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "CUSTOMERNAME" ] . ToString ( ) . Trim ( ) ; //客户(系统)
strACCALL + = "▁" + MsCwVouitemsGl . CUSTOMERNAME ;
}
MsCwVouitemsGl . EXPLAN = strEXPLAN ; //摘要
MsCwVouitemsGl . FCYEXRATE = 1 ; //汇率
dEXCHANGERATE = 1 ; //汇率
MsCwVouitemsGl . BLNO = "" ;
//string strBLNONAME = dsCwDesign.Tables[0].Rows[0]["PiaoHao"].ToString().Trim();
//if (strBLNONAME.Trim() != "")
//{
// MsCwVouitemsGl.BLNO = dsVWChFeeAR.Tables[0].Rows[i][strBLNONAME].ToString().Trim();
//}
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISVBM" ] . ToString ( ) . Trim ( ) = = "True" )
{
MsCwVouitemsGl . ISSYS = false ; //是否手动录入
}
else
{
MsCwVouitemsGl . ISSYS = true ; //是否手动录入
}
if ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "OTCURRAMOUNT" ] . ToString ( ) . Trim ( ) = = "0" )
{
MsCwVouitemsGl . ACCALL = BasicDataRefDAL . setCAGA ( dsAR . Tables [ 0 ] . Rows [ 0 ] [ "PACCGID" ] . ToString ( ) , MsCwVouitemsGl . ACCNAME . ToString ( ) . Trim ( ) ) + strACCALL ;
}
else
{
MsCwVouitemsGl . ACCALL = BasicDataRefDAL . setCAGA ( dsARFC . Tables [ 0 ] . Rows [ 0 ] [ "PACCGID" ] . ToString ( ) , MsCwVouitemsGl . ACCNAME . ToString ( ) . Trim ( ) ) + strACCALL ;
}
# endregion
MsCwVouitemsGl . QTYUNIT = "" ; //数量包装单位
MsCwVouitemsGl . QTYDR = 0 ; //借方数量
MsCwVouitemsGl . QTYCR = 0 ; //贷方数量
MsCwVouitemsGl . DEPTID = "" ; //部门(系统)
MsCwVouitemsGl . EMPLID = "" ; //人员(系统)
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 . 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 ) ;
#region 摘要内容
strEXPLAN = "" ;
strEXPLAN = MBINCOMEEXPLAN ;
ISEXPLAN = false ;
if ( strEXPLAN ! = "" ) ISEXPLAN = true ;
if ( ISEXPLAN )
{
strEXPLAN = strEXPLAN . Replace ( "[发票抬头]" , dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVOICECUSTNAME" ] . ToString ( ) . Trim ( ) ) ;
strEXPLAN = strEXPLAN . Replace ( "[发票号]" , dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVOICENO" ] . ToString ( ) . Trim ( ) ) ;
}
else
{
strEXPLAN + = "应收 " + dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "CUSTOMERNAME" ] . ToString ( ) . Trim ( ) + dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVOICENO" ] . ToString ( ) . Trim ( ) ;
}
# endregion
#region 收入
n + + ;
MsCwVouitemsGl = new MsCwVouitemsGl ( ) ;
//MsCwVouitemsGl.GID 唯一编码 newid()
MsCwVouitemsGl . ORDNO = strORDNO . Trim ( ) ;
MsCwVouitemsGl . ITEMNO = n ; //行号
MsCwVouitemsGl . PACCID = "" ; //父级科目贷码
MsCwVouitemsGl . PROPERTY = 0 ; //科目属性
MsCwVouitemsGl . GRADE = 0 ; //科目级别
MsCwVouitemsGl . ACCID = dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "MBINCOME" ] . ToString ( ) . Trim ( ) ; //主营业务收入科目贷码
MsCwVouitemsGl . AMTDR = 0 ; //本位币借方金额(互斥)
MsCwVouitemsGl . AMTCR = Decimal . Parse ( dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "INVAMOUNT" ] . ToString ( ) . Trim ( ) ) ; //本位币贷方金额(互斥)
strDai = strDai + MsCwVouitemsGl . AMTCR ;
MsCwVouitemsGl . ISFCY = false ; //是否外币
MsCwVouitemsGl . FCYNO = "RMB" ; //外币
MsCwVouitemsGl . FCYDR = 0 ; //外币借方金额
MsCwVouitemsGl . FCYCR = 0 ; //外币贷方金额
MsCwVouitemsGl . ACCNAME = dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "ACCNAME" ] . ToString ( ) . Trim ( ) ; //科目名称
MsCwVouitemsGl . ISDEPTACC = Boolean . Parse ( dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "ISDEPTACC" ] . ToString ( ) . Trim ( ) ) ; //核算部门,按规则设置生成
MsCwVouitemsGl . ISEMPLACC = Boolean . Parse ( dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "ISEMPLACC" ] . ToString ( ) . Trim ( ) ) ; //核算人员,按规则设置生成
MsCwVouitemsGl . ISCORPACC = Boolean . Parse ( dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "ISCORPACC" ] . ToString ( ) . Trim ( ) ) ; //核算客户,按规则设置生成
MsCwVouitemsGl . ISITEMACC = Boolean . Parse ( dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "ISITEMACC" ] . ToString ( ) . Trim ( ) ) ; //核算项目,按规则设置生成
if ( dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "DC" ] . ToString ( ) . Trim ( ) = = "借" )
{
MsCwVouitemsGl . DC = "D" ; //借方向
}
else
{
MsCwVouitemsGl . DC = "C" ; //贷方向
}
/ /
strACCALL = "" ;
MsCwVouitemsGl . CORPID = "" ; // strEMPLID;//人员(系统)本来应该放客户
MsCwVouitemsGl . CUSTOMERNAME = "" ; // strSALE;//人员(系统)本来应该放客户
if ( dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "ISCORPACC" ] . ToString ( ) . Trim ( ) = = "True" )
{
MsCwVouitemsGl . CORPID = "" ; //客户(系统)
MsCwVouitemsGl . CUSTOMERNAME = dsVWChFeeAR . Tables [ 0 ] . Rows [ i ] [ "CUSTOMERNAME" ] . ToString ( ) . Trim ( ) ; //客户(系统)
strACCALL + = "▁" + MsCwVouitemsGl . CUSTOMERNAME ;
}
MsCwVouitemsGl . ACCALL = BasicDataRefDAL . setCAGA ( dsMBINCOME . Tables [ 0 ] . Rows [ 0 ] [ "PACCGID" ] . ToString ( ) , MsCwVouitemsGl . ACCNAME . ToString ( ) . Trim ( ) ) + strACCALL ;
MsCwVouitemsGl . FCYEXRATE = 1 ; //汇率
if ( dsCwDesign . Tables [ 0 ] . Rows [ 0 ] [ "ISVBM" ] . ToString ( ) . Trim ( ) = = "True" )
{
MsCwVouitemsGl . ISSYS = false ; //是否手动录入
}
else
{
MsCwVouitemsGl . ISSYS = true ; //是否手动录入
}
MsCwVouitemsGl . EXPLAN = strEXPLAN ; //摘要,规则生成 "转运费" +
MsCwVouitemsGl . BLNO = "" ; / /
MsCwVouitemsGl . QTYUNIT = "" ; //数量包装单位
MsCwVouitemsGl . QTYDR = 0 ; //借方数量
MsCwVouitemsGl . QTYCR = 0 ; //贷方数量
MsCwVouitemsGl . DEPTID = "" ; //部门(系统)
MsCwVouitemsGl . EMPLID = "" ; //人员(系统)
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 . 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 ) ;
n + + ;
}
}
}
}
if ( CwVouitemsEntities . Count = = 0 )
{
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids . Replace ( "GID" , "BSGID" ) ;
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS ;
bool bl = T_ALL_DA . GetExecuteSqlCommand ( blSQL ) ;
return - 3 ; //结算无明细数据
}
else
{
#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 = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW.Trim(), sACCDATE);
//string[] items = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
//string sVOUNO = items[2].ToString().Trim();
//string strVOUNO = items[3].ToString().Trim();
MsCwVouchersGl . VOUNO = int . Parse ( cfVOUALLNO . Substring ( cfVOUALLNO . 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 . 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 . STARTGID = strCwSTARTGID ;
MsCwVouchersGl . DbOperationType = DbOperationType . DbotIns ;
MsCwVouchersGl . CREATEUSER = strUserID ; //创建人
MsCwVouchersGl . CREATETIME = DateTime . Now ; //创建时间
MsCwVouchersGl . MODIFIEDUSER = strUserID ; //最后一次更新操作人
MsCwVouchersGl . MODIFIEDTIME = DateTime . Now ; //最后一次更新操作时间
MsCwVouchersGl . ISAUTO = true ;
# endregion
#region 生成入库
var modb = new ModelObjectDB ( ) ;
result = modb . Save ( MsCwVouchersGl ) ;
if ( result . Success = = true )
{
foreach ( var enumValue in CwVouitemsEntities )
{
enumValue . GID = Guid . NewGuid ( ) . ToString ( ) ;
//enumValue.ITEMNO = n;
enumValue . DbOperationType = DbOperationType . DbotIns ;
var modb2 = new ModelObjectDB ( ) ;
DBResult result2 = modb2 . Save ( enumValue ) ;
}
//更新凭证生成关系表中的ORDNO数据
string strLS = sAndGids . Replace ( "GID" , "BSGID" ) ;
string blSQL = "update [cw_vouno_bs_gl] set ORDNO='" + MsCwVouchersGl . ORDNO + "' where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' 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 ) ;
if ( VOUAUTOCHECK = = "1" )
{
string blSQL2 = "update cw_vouchers_gl set ISCHECKED=1,CHECKED='" + strUserID + "',CHECKEDTIME=getdate() where VOUALLNO='" + cfVOUALLNO + "' and [STARTGID]='" + strCwSTARTGID + "'" ;
bool bl2 = T_ALL_DA . GetExecuteSqlCommand ( blSQL2 ) ;
}
}
else
{
//result.Success = false;
//result.Message = result.Message;
//return result;
//删除ch_fee_invoice中未生成的凭证号
//string blSQL = "update ch_fee_invoice set VOUNO='' where VOUNO='" + cfVOUALLNO + "'" + sAndGids.Trim();
//删除凭证生成关系表中的ch_fee_invoice的GID数据
string strLS = sAndGids . Replace ( "GID" , "BSGID" ) ;
string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_invoice' and [STARTGID]='" + strCwSTARTGID + "'" + strLS ;
bool bl = T_ALL_DA . GetExecuteSqlCommand ( blSQL ) ;
return - 2 ; //重复数据
}
# endregion
}
//result.Success = true;
//result.Message = result.Message;
//return result;
return 1 ;
}
/* 按原币生成凭证*/
/* 按原币生成凭证*/
protected static int getHxtSC ( DataSet dsCwDesign , DataSet dsCwDesignItem , string sAndGids , MsCwVouchersGl3 headData , List < MsCwVouchersGl4 > bodyList , string strUserID , string strCompanyID , string cfVOUALLNO , string VOUAUTOCHECK )
protected static int getHxtSC ( DataSet dsCwDesign , DataSet dsCwDesignItem , string sAndGids , MsCwVouchersGl3 headData , List < MsCwVouchersGl4 > bodyList , string strUserID , string strCompanyID , string cfVOUALLNO , string VOUAUTOCHECK )
{
{