@ -14,6 +14,16 @@ using DSWeb.Areas.Account.Models.Chfee_Invoice;
using DSWeb.Areas.Account.DAL.Chfee_Invoice ;
using DSWeb.Areas.Account.Models.Chfee_Settlement ;
using DSWeb.Areas.Account.DAL.Chfee_Settlement ;
using DSWeb.Areas.Account.Models.Chfee_Payapplication ;
using DSWeb.Areas.Account.DAL.Chfee_Payapplication ;
using DSWeb.MvcShipping.DAL.ChMonthCloseDAL ;
using DSWeb.MvcShipping.Models.MsChFee ;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet ;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL ;
using System.Web.UI.WebControls ;
using DSWeb.Areas.MvcShipping.Models.Message.VGM ;
using DSWeb.MvcShipping.DAL.MsInfoClient ;
using DSWeb.MvcShipping.Models.SysBillType ;
namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
{
@ -29,7 +39,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
strSql . Append ( " SELECT [GID],[PCNO],[SFNO],[TRANSTYPE],[DRAWEE_BANK] ,[DRAWEE_ACCOUNT],[DRAWEE_NAME],[PAYEE_BANK],[PAYEE_ACCOUNT]" ) ;
strSql . Append ( ",[PAYEE_NAME],[TRANSDATE],[CURRENCY],[AMOUNT],[TRANSNO],[IMPORTDATE],[IMPORTER],[ISFIT],[FITCOUNT],[INVNO],[FITDATE]" ) ;
strSql . Append ( ",[FITTYPE],[PRINTDATE],[ISPRINT],[PRINTER],[SALE],[ATTITIONAL],[REMARK],[SUMMARY],FITUSER,CREATEUSER,CREATETIME" ) ;
strSql . Append ( ",(select ShowName from[user] where GID = ch_fee_bankdata.CREATEUSER) as CREATEUSERREF ") ;
strSql . Append ( ",(select ShowName from[user] where GID = ch_fee_bankdata.CREATEUSER) as CREATEUSERREF ,ACCOUNT,BANK,ISSTL,STLBILLNO,BANKGID,BALANCE ") ;
strSql . Append ( " FROM ch_fee_bankdata where CORPID='" + orgcode + "' " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
@ -44,7 +54,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
}
else
{
strSql . Append ( " order by PCNO DESC,SFNO ") ;
strSql . Append ( " order by TRANSDATE DESC,PCNO DESC ") ;
}
@ -72,7 +82,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
#region Set DB data to Object
data . GID = Convert . ToString ( reader [ "GID" ] ) ;
if ( reader [ "PCNO" ] ! = DBNull . Value )
data . PCNO = Convert . To Int32 ( reader [ "PCNO" ] ) ;
data . PCNO = Convert . To String ( reader [ "PCNO" ] ) ;
if ( reader [ "SFNO" ] ! = DBNull . Value )
data . SFNO = Convert . ToInt32 ( reader [ "SFNO" ] ) ;
@ -117,6 +127,66 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
data . CREATEUSERREF = Convert . ToString ( reader [ "CREATEUSERREF" ] ) ;
if ( reader [ "CREATETIME" ] ! = DBNull . Value )
data . CREATETIME = Convert . ToDateTime ( reader [ "CREATETIME" ] ) . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
data . ACCOUNT = Convert . ToString ( reader [ "ACCOUNT" ] ) ;
data . BANK = Convert . ToString ( reader [ "BANK" ] ) ;
if ( reader [ "ISSTL" ] ! = DBNull . Value )
data . ISSTL = Convert . ToBoolean ( reader [ "ISSTL" ] ) ;
data . STLBILLNO = Convert . ToString ( reader [ "STLBILLNO" ] ) ;
data . BANKGID = Convert . ToString ( reader [ "BANKGID" ] ) ;
if ( reader [ "BALANCE" ] ! = DBNull . Value )
data . BALANCE = Convert . ToDecimal ( reader [ "BALANCE" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
static public List < ChBankdataSum > GetDataSumList ( string strCondition , string userid = "" , string usercode = "" , string orgcode = "" , string sort = null )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " SELECT SUM(CASE WHEN TRANSTYPE='来账' AND CURRENCY='CNY' THEN AMOUNT ELSE 0 END) RMBDR " ) ;
strSql . Append ( ",SUM(CASE WHEN TRANSTYPE='来账' AND CURRENCY='USD' THEN AMOUNT ELSE 0 END) USDDR" ) ;
strSql . Append ( ",SUM(CASE WHEN TRANSTYPE='往账' AND CURRENCY='CNY' THEN AMOUNT ELSE 0 END) RMBCR " ) ;
strSql . Append ( ",SUM(CASE WHEN TRANSTYPE='往账' AND CURRENCY='USD' THEN AMOUNT ELSE 0 END) USDCR" ) ;
strSql . Append ( " FROM ch_fee_bankdata where CORPID='" + orgcode + "' " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " and " + strCondition ) ;
}
return SetSUMData ( strSql ) ;
}
private static List < ChBankdataSum > SetSUMData ( StringBuilder strSql )
{
var headList = new List < ChBankdataSum > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
ChBankdataSum data = new ChBankdataSum ( ) ;
#region Set DB data to Object
if ( reader [ "RMBDR" ] ! = DBNull . Value )
data . RMBDR = Convert . ToDecimal ( reader [ "RMBDR" ] ) ;
if ( reader [ "USDDR" ] ! = DBNull . Value )
data . USDDR = Convert . ToDecimal ( reader [ "USDDR" ] ) ;
if ( reader [ "RMBCR" ] ! = DBNull . Value )
data . RMBCR = Convert . ToDecimal ( reader [ "RMBCR" ] ) ;
if ( reader [ "USDCR" ] ! = DBNull . Value )
data . USDCR = Convert . ToDecimal ( reader [ "USDCR" ] ) ;
# endregion
headList . Add ( data ) ;
}
@ -131,7 +201,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
#region 结算匹配
public static DBResult AddAutoBankDataStlDetail ( string condition , string fitcondition , string user name, string userid , string companyid )
public static DBResult AddAutoBankDataStlDetail ( string condition , string fitcondition , string user id, string username , string companyid )
{
var result = new DBResult ( ) ;
var BankdataList = ChBankdataDAL . GetDataList ( condition , userid , username , companyid ) ;
@ -146,7 +216,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
var InvList = ChsettlementDAL . GetDataListAll ( fitcondition + invsql ) ;
if ( InvList . Count = = 1 )
{
result = AddBankDataStlDetail ( InvList , Bankdata . GID , user name, userid ) ;
result = AddBankDataStlDetail ( InvList , Bankdata . GID , user id, username ) ;
}
}
@ -159,7 +229,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
}
public static DBResult AddBankDataStlDetail ( List < ChSettlement > boday , string billno , string user name, string userid )
public static DBResult AddBankDataStlDetail ( List < ChSettlement > boday , string billno , string user id, string username )
{
var result = new DBResult ( ) ;
@ -237,30 +307,76 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
# endregion
public static DBResult AddAutoBankDataDetail ( string condition , string fitcondition , string username , string userid , string companyid )
public static DBResult AddAutoBankDataDetail ( string condition , string fitcondition , string payfitcondition , string userid , string username , string companyid )
{
var result = new DBResult ( ) ;
var BankdataList = ChBankdataDAL . GetDataList ( condition , userid , username , companyid ) ;
var stlBankdataList = new List < ChBankdata > ( ) ;
if ( BankdataList ! = null & & BankdataList . Count ! = 0 )
{
foreach ( var Bankdata in BankdataList ) {
var invsql = " INVOICECUSTNAME='" + Bankdata . DRAWEE_NAME + "' and RECVCURR='" + Bankdata . CURRENCY + "' and (AMOUNT=" + Bankdata . AMOUNT + " or OTCURRAMOUNT=" + Bankdata . AMOUNT + ") " ;
invsql = invsql + " and EXISTS (select 1 from ch_fee f left join ch_fee_do d on (d.FEEID=f.GID) and cm.BILLNO=d.BILLNO AND F.AMOUNT<>F.SETTLEMENT) " ;
var InvList = ChinvoiceDAL . GetDataList ( 0 , 5 , fitcondition , userid , username , companyid ) ;
if ( InvList . Count = = 1 ) {
result = AddBankDataDetailAuto ( InvList , Bankdata . GID , username , userid ) ;
if ( ! Bankdata . ISFIT )
{
if ( Bankdata . TRANSTYPE = = "来账" )
{
var invsql = " INVOICECUSTNAME='" + Bankdata . DRAWEE_NAME + "' and RECVCURR='" + Bankdata . CURRENCY . Replace ( "CNY" , "RMB" ) . Trim ( ) + "' and (AMOUNT=" + Bankdata . AMOUNT + " or OTCURRAMOUNT=" + Bankdata . AMOUNT + ") " ;
invsql = invsql + " and EXISTS (select 1 from ch_fee f left join ch_fee_do d on (d.FEEID=f.GID) WHERE cm.BILLNO=d.BILLNO AND F.AMOUNT<>F.SETTLEMENT) " ;
if ( ! string . IsNullOrEmpty ( fitcondition ) )
invsql = invsql + " and " + fitcondition ;
var InvList = ChsettlementDAL . GetRecvInvAllDataList ( invsql , userid , username , companyid ) ;
if ( InvList . Count = = 1 & & InvList [ 0 ] . DOAMOUNT = = Bankdata . AMOUNT )
{
result = AddBankDataDetail ( InvList , Bankdata . GID , userid , username , "自动" ) ;
Bankdata . ISFIT = true ;
stlBankdataList . Add ( Bankdata ) ;
}
}
else
{
var invsql = " CM.BILLSTATUS IN (0,4,5) and (CURR='" + Bankdata . CURRENCY . Replace ( "CNY" , "RMB" ) . Trim ( ) + "' and (AMOUNTUSD+AMOUNTRMB+AMOUNTOT)=" + Bankdata . AMOUNT + ")" ;
invsql = invsql + " and EXISTS (select 1 from ch_fee f left join ch_fee_do d on (d.FEEID=f.GID) WHERE cm.BILLNO=d.BILLNO AND F.AMOUNT<>F.SETTLEMENT) " ;
invsql = invsql + " and EXISTS (select 1 from info_client C WHERE C.SHORTNAME=CM.CUSTOMERNAME AND C.[DESCRIPTION]='" + Bankdata . PAYEE_NAME + "') " ;
if ( ! string . IsNullOrEmpty ( payfitcondition ) )
invsql = invsql + " and " + payfitcondition ;
var InvList = ChsettlementDAL . GetPayDCDataAllList ( invsql , "" , "RMB" ) ;
var curr = Bankdata . CURRENCY . Replace ( "CNY" , "RMB" ) . Trim ( ) ;
// var InvList = ChpayapplicationDAL.Do_GetDataList(0,1,invsql);
if ( InvList . Count = = 1 )
{
decimal FITAMOUNT = 0 ;
if ( curr = = "RMB" ) FITAMOUNT = FITAMOUNT + InvList [ 0 ] . STLAMOUNT ;
if ( curr = = "USD" ) FITAMOUNT = FITAMOUNT + InvList [ 0 ] . USDSTLAMOUNT ;
if ( curr ! = "RMB" & & curr ! = "USD" ) FITAMOUNT = FITAMOUNT + InvList [ 0 ] . OTSTLAMOUNT ;
if ( FITAMOUNT = = Bankdata . AMOUNT )
{
result = AddBankDataPayDetail ( InvList , Bankdata . GID , userid , username , "自动" ) ;
Bankdata . ISFIT = true ;
stlBankdataList . Add ( Bankdata ) ;
}
}
}
}
}
AddAutoBankDataSTL ( stlBankdataList , userid , username , companyid ) ;
}
result . Success = true ;
result . Message = "匹配发票成功" ;
result . Message = "匹配 成功";
return result ;
}
public static DBResult AddBankDataDetailAuto ( List < ChInvoice > boday , string billno , string username , string userid )
public static DBResult AddBankDataDetail ( List < ChInvoice > boday , string billno , string userid , string username , string fittype = "手动" )
{
var result = new DBResult ( ) ;
@ -282,12 +398,11 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
@ "insert into ch_fee_bankdata_fitdetail (GID,LINKGID,INVOICENO,BILLNO,CREATEUSER,CREATETIME)
values ( @GID , @LINKGID , @INVOICENO , @BILLNO , @CREATEUSER , @CREATETIME ) ");
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_bankdata set ISFIT=1,FITDATE=GETDATE(),FITTYPE=' 自动 ',FITUSER=@FITUSER,FITCOUNT=@FITCOUNT,INVNO=@INVNO where GID=@GID") ;
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_bankdata set ISFIT=1,FITDATE=GETDATE(),FITTYPE=' "+ fittype + " ',FITUSER=@FITUSER,FITCOUNT=@FITCOUNT,INVNO=@INVNO where GID=@GID") ;
int invcount = 0 ;
string invnostr = "" ;
decimal amount = 0 ;
foreach ( var enumValue in boday )
{
@ -305,7 +420,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
}
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@FITUSER" , DbType . String , username ) ;
db . AddInParameter ( cmdupdate , "@FITUSER" , DbType . String , username ) ;
db . AddInParameter ( cmdupdate , "@FITCOUNT" , DbType . Int16 , invcount ) ;
db . AddInParameter ( cmdupdate , "@INVNO" , DbType . String , invnostr ) ;
db . AddInParameter ( cmdupdate , "@GID" , DbType . String , billno ) ;
@ -330,17 +445,18 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
}
}
result . Success = true ;
result . Message = "匹配发票成功" ;
//result.Success = true ;
//result.Message = "匹配发票成功" ;
return result ;
}
public static DBResult AddBankDataDetail ( List < ChInvoice > boday , string billno , string username , string userid )
public static DBResult AddBankDataPayDetail ( List < ChPaySettlement > boday , string billno , string userid , string username , string fittype = "手动" )
{
var result = new DBResult ( ) ;
var bank = GetData ( "GID='" + billno + "'" ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
@ -358,41 +474,29 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
@ "insert into ch_fee_bankdata_fitdetail (GID,LINKGID,INVOICENO,BILLNO,CREATEUSER,CREATETIME)
values ( @GID , @LINKGID , @INVOICENO , @BILLNO , @CREATEUSER , @CREATETIME ) ");
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_bankdata set ISFIT= @ISFIT,FITDATE=GETDATE(),FITTYPE='手动',FITUSER=@FITUSER,FITCOUNT=FITCOUNT+@FITCOUNT,INVNO=INVNO+ @INVNO where GID=@GID") ;
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_bankdata set ISFIT= 1,FITDATE=GETDATE(),FITTYPE='"+ fittype + "',FITUSER=@FITUSER,FITCOUNT=@FITCOUNT,INVNO= @INVNO where GID=@GID") ;
int invcount = 0 ;
string invnostr = "" ;
decimal amount = 0 ;
foreach ( var enumValue in boday )
{
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@LINKGID" , DbType . String , billno ) ;
db . AddInParameter ( cmdInsert , "@INVOICENO" , DbType . String , enumValue . INV OICE NO) ;
db . AddInParameter ( cmdInsert , "@INVOICENO" , DbType . String , enumValue . INV NO) ;
db . AddInParameter ( cmdInsert , "@BILLNO" , DbType . String , enumValue . BILLNO ) ;
db . AddInParameter ( cmdInsert , "@CREATEUSER" , DbType . String , username ) ;
db . AddInParameter ( cmdInsert , "@CREATETIME" , DbType . String , DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
invcount = invcount + 1 ;
if ( ! string . IsNullOrEmpty ( invnostr ) ) invnostr = invnostr + ";" + enumValue . INVOICENO ;
else invnostr = enumValue . INVOICENO ;
if ( enumValue . RECVCURR = = "RMB" ) amount = amount + enumValue . AMOUNT ;
else amount = amount + enumValue . OTCURRAMOUNT ;
if ( ! string . IsNullOrEmpty ( invnostr ) ) invnostr = invnostr + ";" + enumValue . INVNO ;
else invnostr = enumValue . INVNO ;
}
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@FITUSER" , DbType . String , username ) ;
if ( bank . AMOUNT = = amount )
{
db . AddInParameter ( cmdupdate , "@ISFIT" , DbType . Boolean , true ) ;
}
else {
db . AddInParameter ( cmdupdate , "@ISFIT" , DbType . Boolean , false ) ;
}
db . AddInParameter ( cmdupdate , "@FITUSER" , DbType . String , username ) ;
db . AddInParameter ( cmdupdate , "@FITCOUNT" , DbType . Int16 , invcount ) ;
db . AddInParameter ( cmdupdate , "@INVNO" , DbType . String , invnostr ) ;
db . AddInParameter ( cmdupdate , "@GID" , DbType . String , billno ) ;
@ -402,7 +506,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
result = new DBResult ( ) ;
result . Success = true ;
result . Message = "匹配 发票 成功";
result . Message = "匹配 付费申请 成功";
tran . Commit ( ) ;
}
@ -411,14 +515,359 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "匹配 发票 出现错误,请重试或联系系统管理员";
result . Message = "匹配 付费申请 出现错误,请重试或联系系统管理员";
return result ;
}
}
result . Success = true ;
result . Message = "匹配发票成功" ;
result . Message = "匹配付费申请成功" ;
return result ;
}
public static DBResult AddAutoBankDataSTL ( string condition , string userid , string username , string companyid )
{
var result = new DBResult ( ) ;
var BankdataList = ChBankdataDAL . GetDataList ( condition , userid , username , companyid ) ;
if ( BankdataList ! = null & & BankdataList . Count ! = 0 )
{
foreach ( var Bankdata in BankdataList )
{
if ( Bankdata . ISFIT & & ! Bankdata . ISSTL )
{
if ( Bankdata . TRANSTYPE = = "收入" )
{
var head = new ChSettlement ( ) ;
head . GID = Guid . NewGuid ( ) . ToString ( ) ;
head . BILLDATE = DateTime . Now ;
head . SETTLEUSER = userid ;
head . SETTLEUSERREF = username ;
var period = ChMonthCloseDAL . GetData ( "" , companyid ) ;
if ( Convert . ToDateTime ( period . FDAY ) > DateTime . Now )
{
head . SETTLETIME = period . FDAY ;
}
else
head . SETTLETIME = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
head . CURR = Bankdata . CURRENCY ;
head . SETTLETYPE = 7 ;
head . RATE = 1 ;
head . BILLTYPE = 1 ;
head . SETTLEMODE = 3 ;
var billnoset = MsSysBillNoSetDAL . GetData ( "OPLBNAME='收费结算'" , companyid ) ;
if ( billnoset . BILLTYPE ! = "" )
head . BILLNO = MsSysBillNoSetDAL . GetBillNo ( billnoset , head . SETTLETIME . ToString ( ) . Trim ( ) , head . BILLDATE . ToString ( ) . Trim ( ) ) ;
else head . BILLNO = PubSysDAL . GetBillNo ( "0305" ) ;
head . COMPANYID = companyid ;
head . DbOperationType = DbOperationType . DbotIns ;
var bankList = MsBaseInfoDAL . GetBANKList ( "ACCOUNT='" + Bankdata . ACCOUNT + "'" , head . COMPANYID ) ;
if ( bankList ! = null & & bankList . Count ! = 0 )
{
foreach ( var bank in bankList )
{
head . ACCOUNT = bank . GID ;
}
}
var modb = new ModelObjectDB ( ) ;
var result2 = modb . Save ( head ) ;
if ( result2 . Success )
{
var addinvlist = ChsettlementDAL . GetRecvInvAllDataList ( "BILLNO in (select BILLNO FROM ch_fee_bankdata_fitdetail WHERE LINKGID='" + Bankdata . GID + "')" , userid , username , companyid ) ;
if ( addinvlist ! = null & & addinvlist . Count ! = 0 )
{
var exrateList = ChsettlementDAL . GetInvCurrExrateData ( addinvlist , head . CURR ) ;
result = ChsettlementDAL . RecvInvAddAppDetail ( head . BILLNO , addinvlist , head . CURR , companyid , exrateList ) ;
if ( result . Success ) {
UpdateBankDataStl ( Bankdata . GID , head . BILLNO , username , userid ) ;
}
}
}
}
else
{
var head = new ChSettlement ( ) ;
head . GID = Guid . NewGuid ( ) . ToString ( ) ;
head . BILLDATE = DateTime . Now ;
head . SETTLEUSER = userid ;
head . SETTLEUSERREF = username ;
var period = ChMonthCloseDAL . GetData ( "" , companyid ) ;
if ( Convert . ToDateTime ( period . FDAY ) > DateTime . Now )
{
head . SETTLETIME = period . FDAY ;
}
else
head . SETTLETIME = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
head . CURR = Bankdata . CURRENCY ;
head . SETTLETYPE = 7 ;
head . RATE = 1 ;
head . BILLTYPE = 2 ;
head . SETTLEMODE = 1 ;
var billnoset = MsSysBillNoSetDAL . GetData ( "OPLBNAME='付费结算'" , companyid ) ;
if ( billnoset . BILLTYPE ! = "" )
head . BILLNO = MsSysBillNoSetDAL . GetBillNo ( billnoset , head . SETTLETIME . ToString ( ) . Trim ( ) , head . BILLDATE . ToString ( ) . Trim ( ) ) ;
else
head . BILLNO = PubSysDAL . GetBillNo ( "0304" ) ;
head . COMPANYID = companyid ;
head . DbOperationType = DbOperationType . DbotIns ;
var bankList = MsBaseInfoDAL . GetBANKList ( "ACCOUNT='" + Bankdata . ACCOUNT + "'" , head . COMPANYID ) ;
if ( bankList ! = null & & bankList . Count ! = 0 )
{
foreach ( var bank in bankList )
{
head . ACCOUNT = bank . GID ;
}
}
var modb = new ModelObjectDB ( ) ;
var result2 = modb . Save ( head ) ;
if ( result2 . Success )
{
var addinvlist = ChsettlementDAL . GetPayDCDataList ( "BILLNO in (select BILLNO FROM ch_fee_bankdata_fitdetail WHERE LINKGID='" + Bankdata . GID + "')" , userid , username , companyid , "" , "RMB" ) ;
if ( addinvlist ! = null & & addinvlist . Count ! = 0 )
{
var exrateList = ChsettlementDAL . GetAppCurrExrateData ( addinvlist , head . CURR , "" , true ) ;
result = ChsettlementDAL . AddAppDCDetail ( head . BILLNO , addinvlist , head . CURR , companyid , "" , exrateList , true ) ;
if ( result . Success )
{
UpdateBankDataStl ( Bankdata . GID , head . BILLNO , username , userid ) ;
}
}
}
}
}
}
}
result . Success = true ;
result . Message = "结算成功" ;
return result ;
}
public static DBResult AddAutoBankDataSTL ( List < ChBankdata > BankdataList , string userid , string username , string companyid )
{
var result = new DBResult ( ) ;
if ( BankdataList ! = null & & BankdataList . Count ! = 0 )
{
foreach ( var Bankdata in BankdataList )
{
if ( Bankdata . ISFIT & & ! Bankdata . ISSTL )
{
if ( Bankdata . TRANSTYPE = = "来账" )
{
var addinvlist = ChsettlementDAL . GetRecvInvAllDataList ( "BILLNO in (select BILLNO FROM ch_fee_bankdata_fitdetail WHERE LINKGID='" + Bankdata . GID + "')" , userid , username , companyid ) ;
var head = new ChSettlement ( ) ;
head . GID = Guid . NewGuid ( ) . ToString ( ) ;
head . BILLDATE = DateTime . Now ;
head . SETTLEUSER = userid ;
head . SETTLEUSERREF = username ;
var period = ChMonthCloseDAL . GetData ( "" , companyid ) ;
if ( Convert . ToDateTime ( period . FDAY ) > DateTime . Now )
{
head . SETTLETIME = period . FDAY ;
}
else
head . SETTLETIME = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
head . CURR = Bankdata . CURRENCY . Replace ( "CNY" , "RMB" ) . Trim ( ) ;
head . CUSTOMERNAME = MsInfoClientDAL . GetData ( "[DESCRIPTION]='" + Bankdata . DRAWEE_NAME . Trim ( ) + "'" ) . SHORTNAME ;
if ( string . IsNullOrEmpty ( head . CUSTOMERNAME ) ) {
if ( addinvlist ! = null & & addinvlist . Count ! = 0 )
{
head . CUSTOMERNAME = addinvlist [ 0 ] . CUSTOMERNAME ;
}
}
head . SETTLETYPE = 7 ;
head . RATE = 1 ;
head . BILLTYPE = 1 ;
head . SETTLEMODE = 3 ;
var billnoset = MsSysBillNoSetDAL . GetData ( "OPLBNAME='收费结算'" , companyid ) ;
if ( billnoset . BILLTYPE ! = "" )
head . BILLNO = MsSysBillNoSetDAL . GetBillNo ( billnoset , head . SETTLETIME . ToString ( ) . Trim ( ) , head . BILLDATE . ToString ( ) . Trim ( ) ) ;
else head . BILLNO = PubSysDAL . GetBillNo ( "0305" ) ;
head . COMPANYID = companyid ;
head . DbOperationType = DbOperationType . DbotIns ;
var bankList = MsBaseInfoDAL . GetBANKList ( "ACCOUNT='" + Bankdata . PAYEE_ACCOUNT . Trim ( ) + "'" , "" ) ;
if ( bankList ! = null & & bankList . Count ! = 0 )
{
foreach ( var bank in bankList )
{
head . ACCOUNT = bank . GID ;
if ( head . CURR = = "RMB" ) head . ACCOUNTRMB = bank . GID ;
if ( head . CURR = = "USD" ) head . ACCOUNTUSD = bank . GID ;
}
}
var modb = new ModelObjectDB ( ) ;
var result2 = modb . Save ( head ) ;
if ( result2 . Success )
{
if ( addinvlist ! = null & & addinvlist . Count ! = 0 )
{
var exrateList = ChsettlementDAL . GetInvCurrExrateData ( addinvlist , head . CURR ) ;
result = ChsettlementDAL . RecvInvAddAppDetail ( head . BILLNO , addinvlist , head . CURR , companyid , exrateList ) ;
if ( result . Success )
{
UpdateBankDataStl ( Bankdata . GID , head . BILLNO , username , userid ) ;
ChsettlementDAL . p_update_Amount ( head . BILLNO , 1 ) ;
ChsettlementDAL . Lock ( head . BILLNO , "" ) ;
}
}
}
}
else
{
var addinvlist = ChsettlementDAL . GetPayDCDataList ( "cm.BILLSTATUS=0 and cm.BILLNO in (select BILLNO FROM ch_fee_bankdata_fitdetail WHERE LINKGID='" + Bankdata . GID + "')" , userid , username , companyid , "" , "RMB" ) ;
var head = new ChSettlement ( ) ;
head . GID = Guid . NewGuid ( ) . ToString ( ) ;
head . BILLDATE = DateTime . Now ;
head . SETTLEUSER = userid ;
head . SETTLEUSERREF = username ;
var period = ChMonthCloseDAL . GetData ( "" , companyid ) ;
if ( Convert . ToDateTime ( period . FDAY ) > DateTime . Now )
{
head . SETTLETIME = period . FDAY ;
}
else
head . SETTLETIME = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
head . CURR = Bankdata . CURRENCY . Replace ( "CNY" , "RMB" ) . Trim ( ) ;
head . SETTLETYPE = 7 ;
head . RATE = 1 ;
head . BILLTYPE = 2 ;
head . SETTLEMODE = 1 ;
var billnoset = MsSysBillNoSetDAL . GetData ( "OPLBNAME='付费结算'" , companyid ) ;
if ( billnoset . BILLTYPE ! = "" )
head . BILLNO = MsSysBillNoSetDAL . GetBillNo ( billnoset , head . SETTLETIME . ToString ( ) . Trim ( ) , head . BILLDATE . ToString ( ) . Trim ( ) ) ;
else
head . BILLNO = PubSysDAL . GetBillNo ( "0304" ) ;
head . COMPANYID = companyid ;
head . DbOperationType = DbOperationType . DbotIns ;
var bankList = MsBaseInfoDAL . GetBANKList ( "ACCOUNT='" + Bankdata . DRAWEE_ACCOUNT . Trim ( ) + "'" , "" ) ;
if ( bankList ! = null & & bankList . Count ! = 0 )
{
foreach ( var bank in bankList )
{
head . ACCOUNT = bank . GID ;
if ( head . CURR = = "RMB" ) head . ACCOUNTRMB = bank . GID ;
if ( head . CURR = = "USD" ) head . ACCOUNTUSD = bank . GID ;
}
}
head . CUSTOMERNAME = MsInfoClientDAL . GetData ( "[DESCRIPTION]='" + Bankdata . PAYEE_NAME . Trim ( ) + "'" ) . SHORTNAME ;
if ( string . IsNullOrEmpty ( head . CUSTOMERNAME ) )
{
if ( addinvlist ! = null & & addinvlist . Count ! = 0 )
{
head . CUSTOMERNAME = addinvlist [ 0 ] . CUSTOMERNAME ;
}
}
var modb = new ModelObjectDB ( ) ;
var result2 = modb . Save ( head ) ;
if ( result2 . Success )
{
if ( addinvlist ! = null & & addinvlist . Count ! = 0 )
{
var exrateList = ChsettlementDAL . GetAppCurrExrateData ( addinvlist , head . CURR , "" , true ) ;
result = ChsettlementDAL . AddAppDCDetail ( head . BILLNO , addinvlist , head . CURR , companyid , head . CURR , exrateList , true ) ;
if ( result . Success )
{
UpdateBankDataStl ( Bankdata . GID , head . BILLNO , username , userid ) ;
ChsettlementDAL . p_update_Amount ( head . BILLNO , 2 ) ;
ChsettlementDAL . Lock ( head . BILLNO , "" ) ;
}
}
}
}
}
}
}
result . Success = true ;
result . Message = "结算成功" ;
return result ;
}
public static DBResult UpdateBankDataStl ( string GID , string billno , string username , string userid )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
var cmdupdate = db . GetSqlStringCommand ( "update ch_fee_bankdata set ISSTL=1,STLDATE=GETDATE(),STLBY=@FITUSER,STLBILLNO=@STLBILLNO where GID=@GID" ) ;
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@FITUSER" , DbType . String , username ) ;
db . AddInParameter ( cmdupdate , "@STLBILLNO" , DbType . String , billno ) ;
db . AddInParameter ( cmdupdate , "@GID" , DbType . String , GID ) ;
db . ExecuteNonQuery ( cmdupdate , tran ) ;
result = new DBResult ( ) ;
result . Success = true ;
result . Message = "结算成功" ;
tran . Commit ( ) ;
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "结算出现错误,请重试或联系系统管理员" ;
return result ;
}
}
result . Success = true ;
result . Message = "结算成功" ;
return result ;
}
@ -491,13 +940,13 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
var TRANSTYPE = Convert . ToString ( row [ "交易类型[ Transaction Type ]" ] ) . Replace ( "\"" , "" ) . Replace ( "\t" , "" ) ;
var DRAWEE_NAME = Convert . ToString ( row [ "付款人名称[ Payer's Name ]" ] ) . Replace ( "\"" , "" ) . Replace ( "\t" , "" ) ;
if ( ! string . IsNullOrEmpty ( TRANSTYPE ) & & TRANSTYPE = = "来账" && DRAWEE_NAME . IndexOf ( "经汉" ) < 0 )
if ( ! string . IsNullOrEmpty ( TRANSTYPE ) & & TRANSTYPE = = "来账" )
{
num = num + 1 ;
var headData = new ChBankdata ( ) ;
headData . GID = System . Guid . NewGuid ( ) . ToString ( ) ;
headData . DbOperationType = DbOperationType . DbotIns ;
headData . PCNO = Convert . ToInt32 ( pcno ) + 1 ;
headData . PCNO = ( Convert . ToInt32 ( pcno ) + 1 ) . ToString ( ) ;
headData . SFNO = num ;
headData . TRANSTYPE = TRANSTYPE ;
headData . DRAWEE_BANK = Convert . ToString ( row [ "付款人开户行名[ Payer account bank ]" ] ) . Replace ( "\"" , "" ) . Replace ( "\t" , "" ) ;
@ -568,11 +1017,11 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
var headData = new ChBankdata ( ) ;
headData . GID = System . Guid . NewGuid ( ) . ToString ( ) ;
headData . DbOperationType = DbOperationType . DbotIns ;
headData . PCNO = Convert . ToInt32 ( pcno ) + 1 ;
headData . PCNO = ( Convert . ToInt32 ( pcno ) + 1 ) . ToString ( ) ;
headData . SFNO = num ;
if ( ! string . IsNullOrEmpty ( DR ) )
{
headData . TRANSTYPE = " 收入 ";
headData . TRANSTYPE = " 来账 ";
headData . DRAWEE_BANK = BANK ;
headData . DRAWEE_ACCOUNT = ACCOUNT ;
headData . DRAWEE_NAME = DRAWEE_NAME ;
@ -580,7 +1029,7 @@ namespace DSWeb.Areas.Account.DAL.Chfee_bankdata
headData . PAYEE_ACCOUNT = "" ;
headData . PAYEE_NAME = "" ;
} else {
headData . TRANSTYPE = " 支出 ";
headData . TRANSTYPE = " 往账 ";
headData . DRAWEE_BANK = "" ;
headData . DRAWEE_ACCOUNT = "" ;
headData . DRAWEE_NAME = "" ;