|
|
using System;
|
|
|
using System.Data;
|
|
|
using System.Data.Common;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using DSWeb.Areas.Account.Models.Chfee_Payapplication;
|
|
|
using DSWeb.Areas.Account.Models.Chfee_do_detail;
|
|
|
using DSWeb.Areas.Account.Models.MsOpBill;
|
|
|
using DSWeb.Areas.Account.Models.BillChfeeDetail;
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
using DSWeb.Areas.Account.Models.Chfee_Exrate;
|
|
|
using DSWeb.Areas.Account.Models.Chfee_do_Sum;
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
using DSWeb.EntityDA;
|
|
|
using HcUtility.Comm;
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
using DSWeb.Areas.Account.Models.ChfeeDetail;
|
|
|
using DSWeb.Areas.Account.Models.Chfee_Invoicehexiao;
|
|
|
using DSWeb.MvcShipping.DAL.MsSysParamSet;
|
|
|
using DSWeb.Areas.Mobile.DAL;
|
|
|
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
|
|
|
using DSWeb.Areas.Account.Models.TruckChfee_do_detail;
|
|
|
using System.Data.SqlClient;
|
|
|
using DSWeb.Areas.Account.Models.BSNOLB;
|
|
|
using System.Web.Mvc;
|
|
|
using System.Web;
|
|
|
using System.IO;
|
|
|
using HtmlAgilityPack;
|
|
|
|
|
|
namespace DSWeb.Areas.Account.DAL.Chfee_Payapplication
|
|
|
{
|
|
|
public partial class ChpayapplicationDAL
|
|
|
{
|
|
|
#region 付费申请列表
|
|
|
|
|
|
static public List<ChPayapplication> GetDataList(int start, int limit, string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null)
|
|
|
{
|
|
|
|
|
|
var rangstr = GetRangDAListStr("", userid, usercode, orgcode);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
|
|
|
sortstring = sortstring.Replace("APPLICANTNAME", "(select ShowName from [user] where GID=cm.APPLICANT)");
|
|
|
sortstring = sortstring.Replace("SETTLETYPEREF", "(select STLNAME from [code_stlmode] where STLCODE=cm.SETTLETYPE)");
|
|
|
sortstring = sortstring.Replace("RMBDOAMOUNT", "(select SUM(CASE FEETYPE WHEN 1 THEN -DOAMOUNT ELSE DOAMOUNT END) from ch_fee_do where CURRENCY='RMB' AND BILLNO=cm.BILLNO)");
|
|
|
sortstring = sortstring.Replace("USDDOAMOUNT", "(select SUM(CASE FEETYPE WHEN 1 THEN -DOAMOUNT ELSE DOAMOUNT END) from ch_fee_do where CURRENCY='USD' AND BILLNO=cm.BILLNO)");
|
|
|
sortstring = sortstring.Replace("SALECORP", "cm.SALECORPID");
|
|
|
sortstring = sortstring.Replace("APPLICANTDEPT", "(select DEPTNAME from VW_user where userid=cm.APPLICANT)");
|
|
|
sortstring = sortstring.Replace("BILLSTATUSREF", "BILLSTATUS");
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by APPLYTIME DESC");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append(@") as num , ");
|
|
|
|
|
|
strSql.Append(" GID,BILLNO,BILLSTATUS,CUSTOMERNAME,CURR,CHEQUEPAYABLE,SETTLETYPE,PAYTYPE");
|
|
|
strSql.Append(" ,PAYABLETIME,AMOUNTRMB,RATE,AMOUNTUSD,AMOUNTOT,SETTLERMB,SETTLEUSD,SETTLEOT,SETTLERATE");
|
|
|
strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,SETTLEUSER,SETTLETIME,AUDITUSER,AUDITTIME ");
|
|
|
strSql.Append(" ,REMARK,COMPANYID,ISAPP,PAYAPPID,CHEQUENUMREMARK,INVDATE,INVNO, ");
|
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97005 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME");
|
|
|
strSql.Append(",(select DEPTNAME from VW_user where userid=cm.APPLICANT) as APPLICANTDEPT");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=cm.AUDITUSER) as AUDITUSERREF");
|
|
|
strSql.Append(",(select STLNAME from [code_stlmode] where STLCODE=cm.SETTLETYPE) as SETTLETYPEREF");
|
|
|
strSql.Append(",CUSTACCOUNTGID,cm.REASON,AUDITREMARK");
|
|
|
strSql.Append(",(select SUM(CASE FEETYPE WHEN 1 THEN -DOAMOUNT ELSE DOAMOUNT END) from ch_fee_do where CURRENCY='RMB' AND BILLNO=cm.BILLNO) as RMBDOAMOUNT ");
|
|
|
strSql.Append(",(select SUM(CASE FEETYPE WHEN 1 THEN -DOAMOUNT ELSE DOAMOUNT END) from ch_fee_do where CURRENCY='USD' AND BILLNO=cm.BILLNO) as USDDOAMOUNT ");
|
|
|
strSql.Append(",(select SUM(CASE FEETYPE WHEN 1 THEN -DOAMOUNT ELSE DOAMOUNT END) from ch_fee_do where CURRENCY!='RMB' AND CURRENCY!='USD' AND BILLNO=cm.BILLNO) as OTDOAMOUNT ");
|
|
|
strSql.Append(",(select CODENAME+'_'+bankname from info_client_bank where gid=cm.CUSTACCOUNTGID) CUSTBANKNAME");
|
|
|
strSql.Append(",(select ACCOUNT from info_client_bank where gid=cm.CUSTACCOUNTGID) CUSTACCOUNT");
|
|
|
strSql.Append(",ISNULL((select sum(isnull(amount,0)-isnull(invoice,0)) as noinvoice from ch_fee where isnull(ISINVOICE,0)<>1 and gid in (select feeid from ch_fee_do where BILLNO=cm.BILLNO)),0) as NOINVOICE");
|
|
|
strSql.Append(",cm.BS_CUSTOMERNAME,0 IsAudit,PREAMOUNTRMB,PREAMOUNTUSD,PREAMOUNTOT,STLNAME,RECREMARK,PREDICTPROFIT,RECSTLDATE,PAYREASON ");
|
|
|
strSql.Append(",dbo.GetStlByPayNo(cm.BILLNO) as BALBILLNO,cm.ISPRINT,cm.PRINTCOUNT,wxpush,STLRATE,STLAMOUNT,STLCURR,ISREVINV ");
|
|
|
strSql.Append(",cm.SALECORPID,(select [NAME] from [company] where GID=cm.SALECORPID) as SALECORP");
|
|
|
strSql.Append(" FROM ch_fee_payapplication cm where 1=1 ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
|
|
|
return SetData(strSql);
|
|
|
}
|
|
|
public static int getTotalCount(string strCondition, string userid, string usercode, string orgcode)
|
|
|
{
|
|
|
var rangstr = GetRangDAListStr("", userid, usercode, orgcode);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select count(*) ");
|
|
|
strSql.Append(" from ch_fee_payapplication cm ");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
}
|
|
|
|
|
|
int cnt = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
cnt = Convert.ToInt32(reader[0]);
|
|
|
}
|
|
|
}
|
|
|
return cnt;
|
|
|
}
|
|
|
|
|
|
|
|
|
static public ChPayapplication GetData(string condition, string userid = "", string usercode = "", string orgcode = "")
|
|
|
{
|
|
|
var list = GetDataList(0,1,condition,userid,usercode,orgcode);
|
|
|
if (list.Count > 0)
|
|
|
return list[0];
|
|
|
|
|
|
return new ChPayapplication();
|
|
|
}
|
|
|
|
|
|
#region 付费审核列表
|
|
|
|
|
|
static public List<ChPayapplication> GetAuditDataList(string strCondition, string userid, string isaudit, string usercode, string orgcode, string sort = null)
|
|
|
{
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" SELECT i.GID,i.BILLNO,i.BILLSTATUS,i.CUSTOMERNAME,i.CURR,i.CHEQUEPAYABLE,i.SETTLETYPE,i.PAYTYPE ");
|
|
|
strSql.Append(" ,i.PAYABLETIME,i.AMOUNTRMB,i.RATE,i.AMOUNTUSD,i.AMOUNTOT,i.SETTLERMB as RMBDOAMOUNT,i.SETTLEUSD as USDDOAMOUNT,i.SETTLEOT as OTDOAMOUNT,i.SETTLERATE");
|
|
|
strSql.Append(" ,i.APPLICANT,i.APPLYTIME,i.ENTERTIME,i.SETTLEUSER,i.SETTLETIME,i.AUDITUSER,i.AUDITTIME ");
|
|
|
strSql.Append(" ,i.REMARK,i.COMPANYID,i.ISAPP,i.PAYAPPID,i.CHEQUENUMREMARK,INVDATE,INVNO, ");
|
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97005 and EnumValueID=i.BILLSTATUS) as BILLSTATUSREF");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=i.APPLICANT) as APPLICANTNAME");
|
|
|
strSql.Append(",(select DEPTNAME from VW_user where userid=i.APPLICANT) as APPLICANTDEPT");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=i.AUDITUSER) as AUDITUSERREF");
|
|
|
strSql.Append(",i.CUSTACCOUNTGID,i.REASON,AUDITREMARK");
|
|
|
strSql.Append(",(select STLNAME from [code_stlmode] where STLCODE=i.SETTLETYPE) as SETTLETYPEREF");
|
|
|
strSql.Append(",(select CODENAME+'_'+bankname from info_client_bank where gid=i.CUSTACCOUNTGID) CUSTBANKNAME");
|
|
|
strSql.Append(",(select ACCOUNT from info_client_bank where gid=i.CUSTACCOUNTGID) CUSTACCOUNT");
|
|
|
strSql.Append(",ISNULL((select sum(isnull(f.amount,0)-isnull(f.invoice,0)) as noinvoice from ch_fee f left join ch_fee_do d on (d.FEEID=f.GID) where ISINVOICE<>1 and d.BILLNO=i.BILLNO),0) as NOINVOICE");
|
|
|
strSql.Append(",i.BS_CUSTOMERNAME,dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno) as IsAudit ");
|
|
|
strSql.Append(",i.PREAMOUNTRMB,i.PREAMOUNTUSD,i.PREAMOUNTOT,i.STLNAME,i.RECREMARK,i.PREDICTPROFIT,i.RECSTLDATE,i.PAYREASON ");
|
|
|
strSql.Append(",dbo.GetBalNoByPayNo(i.BILLNO) as BALBILLNO,i.ISPRINT,i.PRINTCOUNT,i.wxpush,i.STLRATE,i.STLAMOUNT,i.STLCURR ");
|
|
|
strSql.Append(",i.SALECORPID,(select [NAME] from [company] where GID=i.SALECORPID) as SALECORP,i.ISREVINV");
|
|
|
strSql.Append(" FROM ch_fee_payapplication i left join workflow_using wu on wu.bsno=i.billno where 1=1 ");
|
|
|
if (isaudit == "3")
|
|
|
{
|
|
|
var rangstr = GetRangDAListStr("", userid, usercode, orgcode);
|
|
|
strSql.Append(" and i.BILLSTATUS=2 and dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 ");
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
strSql.Append(" and " + rangstr);
|
|
|
}
|
|
|
}
|
|
|
else if (isaudit == "2")
|
|
|
{
|
|
|
var rangstr = GetRangDAListStr("", userid, usercode, orgcode);
|
|
|
strSql.Append(" and i.BILLSTATUS=0 ");// AND I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ) ");
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
strSql.Append(" and " + rangstr);
|
|
|
}
|
|
|
}
|
|
|
else if (isaudit == "1")
|
|
|
{
|
|
|
var rangstr = GetRangDAListStr("", userid, usercode, orgcode);
|
|
|
strSql.Append(" and i.BILLSTATUS=2 ");// AND I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ) ");
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
strSql.Append(" and " + rangstr);
|
|
|
}
|
|
|
}
|
|
|
else if (isaudit == "")
|
|
|
{
|
|
|
var rangstr = GetRangDAListStr("", userid, usercode, orgcode);
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
strSql.Append(" and " + rangstr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("APPLICANTNAME", "(select ShowName from [user] where GID=i.APPLICANT)");
|
|
|
sortstring = sortstring.Replace("SETTLETYPEREF", "(select STLNAME from [code_stlmode] where STLCODE=i.SETTLETYPE)");
|
|
|
sortstring = sortstring.Replace("SALECORP", "i.SALECORPID");
|
|
|
sortstring = sortstring.Replace("APPLICANTDEPT", "(select DEPTNAME from VW_user where userid=i.APPLICANT)");
|
|
|
sortstring = sortstring.Replace("BILLSTATUSREF", "i.BILLSTATUS");
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by APPLYTIME desc ");
|
|
|
|
|
|
}
|
|
|
return SetData(strSql);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
private static List<ChPayapplication> SetData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<ChPayapplication>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
|
cmd.CommandText = strSql.ToString();
|
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(cmd))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ChPayapplication data = new ChPayapplication();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.BILLNO = Convert.ToString(reader["BILLNO"]);
|
|
|
if (reader["BILLSTATUS"] != DBNull.Value)
|
|
|
data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]);
|
|
|
data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]);
|
|
|
data.PAYTYPE = Convert.ToString(reader["PAYTYPE"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
if (reader["CURR"] != DBNull.Value)
|
|
|
data.CURR = Convert.ToString(reader["CURR"]);
|
|
|
data.CHEQUEPAYABLE = Convert.ToString(reader["CHEQUEPAYABLE"]);
|
|
|
if (reader["SETTLETYPE"] != DBNull.Value)
|
|
|
data.SETTLETYPE = Convert.ToInt32(reader["SETTLETYPE"]);
|
|
|
data.SETTLETYPEREF = Convert.ToString(reader["SETTLETYPEREF"]);
|
|
|
if (reader["PAYABLETIME"] != DBNull.Value)
|
|
|
data.PAYABLETIME = Convert.ToDateTime(reader["PAYABLETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
if (reader["AMOUNTRMB"] != DBNull.Value)
|
|
|
data.AMOUNTRMB = Convert.ToDecimal(reader["AMOUNTRMB"]);
|
|
|
if (reader["AMOUNTUSD"] != DBNull.Value)
|
|
|
data.AMOUNTUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
|
|
|
if (reader["AMOUNTOT"] != DBNull.Value)
|
|
|
data.AMOUNTOT = Convert.ToDecimal(reader["AMOUNTOT"]);
|
|
|
if (reader["RATE"] != DBNull.Value)
|
|
|
data.RATE = Convert.ToDecimal(reader["RATE"]);
|
|
|
if (reader["RMBDOAMOUNT"] != DBNull.Value)
|
|
|
data.SETTLERMB = Convert.ToDecimal(reader["RMBDOAMOUNT"]);
|
|
|
if (reader["USDDOAMOUNT"] != DBNull.Value)
|
|
|
data.SETTLEUSD = Convert.ToDecimal(reader["USDDOAMOUNT"]);
|
|
|
if (reader["OTDOAMOUNT"] != DBNull.Value)
|
|
|
data.SETTLEOT = Convert.ToDecimal(reader["OTDOAMOUNT"]);
|
|
|
if (reader["SETTLERATE"] != DBNull.Value)
|
|
|
data.SETTLERATE = Convert.ToDecimal(reader["SETTLERATE"]);
|
|
|
data.APPLICANT = Convert.ToString(reader["APPLICANT"]);
|
|
|
data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]);
|
|
|
data.APPLICANTDEPT = Convert.ToString(reader["APPLICANTDEPT"]);
|
|
|
if (reader["APPLYTIME"] != DBNull.Value)
|
|
|
data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]);
|
|
|
if (reader["ENTERTIME"] != DBNull.Value)
|
|
|
data.ENTERTIME = Convert.ToDateTime(reader["ENTERTIME"]);
|
|
|
if (reader["SETTLETIME"] != DBNull.Value)
|
|
|
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]);
|
|
|
if (reader["AUDITTIME"] != DBNull.Value)
|
|
|
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]);
|
|
|
data.SETTLEUSER = Convert.ToString(reader["SETTLEUSER"]);
|
|
|
data.AUDITUSER = Convert.ToString(reader["AUDITUSERREF"]);
|
|
|
data.REMARK = Convert.ToString(reader["REMARK"]);
|
|
|
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
|
|
|
data.AUDITREMARK = Convert.ToString(reader["AUDITREMARK"]);
|
|
|
data.REASON = Convert.ToString(reader["REASON"]);
|
|
|
|
|
|
if (reader["ISAPP"] != DBNull.Value)
|
|
|
data.ISAPP = Convert.ToBoolean(reader["ISAPP"]);
|
|
|
if (reader["ISREVINV"] != DBNull.Value)
|
|
|
data.ISREVINV = Convert.ToBoolean(reader["ISREVINV"]);
|
|
|
data.PAYAPPID = Convert.ToString(reader["PAYAPPID"]);
|
|
|
data.CHEQUENUMREMARK = Convert.ToString(reader["CHEQUENUMREMARK"]);
|
|
|
data.INVNO = Convert.ToString(reader["INVNO"]);
|
|
|
if (reader["INVDATE"] != DBNull.Value)
|
|
|
data.INVDATE = Convert.ToDateTime(reader["INVDATE"]).ToString("yyyy-MM-dd");
|
|
|
data.CUSTACCOUNTGID = Convert.ToString(reader["CUSTACCOUNTGID"]);
|
|
|
data.CUSTBANKNAME = Convert.ToString(reader["CUSTBANKNAME"]);
|
|
|
data.CUSTACCOUNT = Convert.ToString(reader["CUSTACCOUNT"]);
|
|
|
if (reader["NOINVOICE"] != DBNull.Value && Convert.ToDecimal(reader["NOINVOICE"]) == 0)
|
|
|
data.ISINVOICE = "是";
|
|
|
data.BS_CUSTOMERNAME = Convert.ToString(reader["BS_CUSTOMERNAME"]);
|
|
|
if (reader["IsAudit"] != DBNull.Value)
|
|
|
data.IsAudit = Convert.ToString(reader["IsAudit"]);
|
|
|
if (reader["PREAMOUNTRMB"] != DBNull.Value)
|
|
|
data.PREAMOUNTRMB = Convert.ToDecimal(reader["PREAMOUNTRMB"]);
|
|
|
if (reader["PREAMOUNTUSD"] != DBNull.Value)
|
|
|
data.PREAMOUNTUSD = Convert.ToDecimal(reader["PREAMOUNTUSD"]);
|
|
|
if (reader["PREAMOUNTOT"] != DBNull.Value)
|
|
|
data.PREAMOUNTOT = Convert.ToDecimal(reader["PREAMOUNTOT"]);
|
|
|
data.BALAMOUNTRMB = data.PREAMOUNTRMB - data.AMOUNTRMB;
|
|
|
data.BALAMOUNTUSD = data.PREAMOUNTUSD - data.AMOUNTUSD;
|
|
|
data.BALAMOUNTOT = data.PREAMOUNTOT - data.AMOUNTOT;
|
|
|
data.BALBILLNO = Convert.ToString(reader["BALBILLNO"]);
|
|
|
data.ISPRINT = Convert.ToString(reader["ISPRINT"]);
|
|
|
if (reader["PRINTCOUNT"] != DBNull.Value)
|
|
|
data.PRINTCOUNT = Convert.ToInt32(reader["PRINTCOUNT"]);
|
|
|
data.WxPush = Convert.ToString(reader["wxpush"]);
|
|
|
if (reader["STLRATE"] != DBNull.Value)
|
|
|
data.STLRATE = Convert.ToDecimal(reader["STLRATE"]);
|
|
|
if (reader["STLAMOUNT"] != DBNull.Value)
|
|
|
data.STLAMOUNT = Convert.ToDecimal(reader["STLAMOUNT"]);
|
|
|
data.STLCURR = Convert.ToString(reader["STLCURR"]);
|
|
|
data.SALECORP = Convert.ToString(reader["SALECORP"]);
|
|
|
data.SALECORPID = Convert.ToString(reader["SALECORPID"]);
|
|
|
data.STLNAME = Convert.ToString(reader["STLNAME"]);
|
|
|
data.RECREMARK = Convert.ToString(reader["RECREMARK"]);
|
|
|
data.PREDICTPROFIT = Convert.ToString(reader["PREDICTPROFIT"]);
|
|
|
data.RECSTLDATE = Convert.ToString(reader["RECSTLDATE"]);
|
|
|
data.PAYREASON = Convert.ToString(reader["PAYREASON"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 付费申请费用明细
|
|
|
|
|
|
static public List<Chfee_do_detail> GetBodyList(int start, int limit, string strCondition, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("FEEOBJNAME", "f.CUSTOMERNAME");
|
|
|
sortstring = sortstring.Replace("FEENAME", "C.FEENAME");
|
|
|
sortstring = sortstring.Replace("AMOUNT", "C.AMOUNT");
|
|
|
sortstring = sortstring.Replace("MBLNO", "B.MBLNO");
|
|
|
sortstring = sortstring.Replace("CUSTNO", "B.CUSTNO");
|
|
|
sortstring = sortstring.Replace("CUSTOMERNAME", "B.CUSTOMERNAME");
|
|
|
|
|
|
strSql.Append(" order by " + sortstring + ",C.CREATETIME");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by C.CREATETIME,b.ETD,b.MBLNO ");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append(@") as num , ");
|
|
|
|
|
|
|
|
|
strSql.Append(" c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE ");
|
|
|
strSql.Append(",c.FEETYPE,f.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE,f.ACCTAXRATE");
|
|
|
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
|
|
|
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE");
|
|
|
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where BILLNO IN (SELECT BILLNO FROM ch_fee_do_invoice WHERE FEEID=c.FEEID)) INVOICENO ");
|
|
|
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR,c.INVOICESETTLENO ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
return BodySetData(strSql);
|
|
|
}
|
|
|
|
|
|
static public List<Chfee_do_detail> GetBodyAllList( string strCondition, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE ");
|
|
|
strSql.Append(",c.FEETYPE,f.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE,f.ACCTAXRATE");
|
|
|
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
|
|
|
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE");
|
|
|
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where BILLNO IN (SELECT BILLNO FROM ch_fee_do_invoice WHERE FEEID=c.FEEID)) INVOICENO ");
|
|
|
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR,c.INVOICESETTLENO ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("FEEOBJNAME", "f.CUSTOMERNAME");
|
|
|
sortstring = sortstring.Replace("FEENAME", "C.FEENAME");
|
|
|
sortstring = sortstring.Replace("AMOUNT", "C.AMOUNT");
|
|
|
sortstring = sortstring.Replace("MBLNO", "B.MBLNO");
|
|
|
sortstring = sortstring.Replace("CUSTNO", "B.CUSTNO");
|
|
|
sortstring = sortstring.Replace("CUSTOMERNAME", "B.CUSTOMERNAME");
|
|
|
|
|
|
strSql.Append(" order by " + sortstring + ",C.CREATETIME");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by C.CREATETIME,b.ETD,b.MBLNO ");
|
|
|
|
|
|
}
|
|
|
|
|
|
return BodySetData(strSql);
|
|
|
}
|
|
|
static public string GetBodyAllListStr(string strCondition, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE ");
|
|
|
strSql.Append(",c.FEETYPE,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE,f.ACCTAXRATE");
|
|
|
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
|
|
|
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.CARRIER,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) COMPANYNAME");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE");
|
|
|
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where BILLNO IN (SELECT BILLNO FROM ch_fee_do_invoice WHERE FEEID=c.FEEID)) INVOICENO ");
|
|
|
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,c.INVOICESETTLENO ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring + ",CREATETIME");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by CREATETIME,ETD,MBLNO ");
|
|
|
|
|
|
}
|
|
|
|
|
|
return strSql.ToString();
|
|
|
}
|
|
|
|
|
|
static public List<Chfee_do_detail> GetModifyBodyAllList(string strCondition, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,f.AMOUNT,f.NOTAXAMOUNT DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE ");
|
|
|
strSql.Append(",c.FEETYPE,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.TAXRATE ORIGEXCHANGERATE,f.ACCTAXRATE");
|
|
|
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
|
|
|
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE");
|
|
|
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where BILLNO IN (SELECT BILLNO FROM ch_fee_do_invoice WHERE FEEID=c.FEEID)) INVOICENO ");
|
|
|
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME,0 TTLNODR,c.INVOICESETTLENO ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("FEEOBJNAME", "f.CUSTOMERNAME");
|
|
|
sortstring = sortstring.Replace("FEENAME", "C.FEENAME");
|
|
|
sortstring = sortstring.Replace("AMOUNT", "C.AMOUNT");
|
|
|
sortstring = sortstring.Replace("MBLNO", "B.MBLNO");
|
|
|
sortstring = sortstring.Replace("CUSTNO", "B.CUSTNO");
|
|
|
sortstring = sortstring.Replace("CUSTOMERNAME", "B.CUSTOMERNAME");
|
|
|
strSql.Append(" order by " + sortstring + ",C.CREATETIME");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by C.CREATETIME,b.ETD,b.MBLNO ");
|
|
|
|
|
|
}
|
|
|
|
|
|
return BodySetData(strSql);
|
|
|
}
|
|
|
|
|
|
public static int getbodyTotalCount(string strCondition, string userid, string usercode, string orgcode)
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select count(c.GID) ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
|
|
|
int cnt = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
cnt = Convert.ToInt32(reader[0]);
|
|
|
}
|
|
|
}
|
|
|
return cnt;
|
|
|
}
|
|
|
static public List<TruckChfee_do_detail> GetTruckBodyList(int start, int limit, string strCondition, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("CUSTOMERNAME", "C.CUSTOMERNAME");
|
|
|
strSql.Append(" order by " + sortstring + ",C.CREATETIME");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by C.CREATETIME,b.ETD,b.MBLNO ");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append(@") as num , ");
|
|
|
|
|
|
|
|
|
strSql.Append(" c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE ");
|
|
|
strSql.Append(",c.FEETYPE,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE,f.ACCTAXRATE");
|
|
|
strSql.Append(",B.TRANSTYPE,B.TRANSSTATUS,B.CUSTOMERNAME,B.CUSTNO,B.CONTRACTNO,B.ORDERNO,B.BSDATE,B.MBLNO,B.CNTRTOTAL,");
|
|
|
strSql.Append("B.ETD,B.ETA,B.OP,B.SALE,B.CUSTSERVICE,B.CUSTATTN,B.CUSTTEL,B.CONSIGNEENAME,B.CONSIGNEEATTN,B.CONSIGNEETEL,B.CONSIGNEEADDR,");
|
|
|
strSql.Append("B.PORTLOAD,B.PORTDISCHARGE,B.GOODSNAME,B.KGS,B.NETWEIGHT,B.CBM,B.PKGS,B.KINDPKGS,B.TRUCKER,B.TRUCKNO");
|
|
|
strSql.Append(",f.Remark Remark,f.INPUTMODE,C.CREATETIME ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_truck_bulk b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
return BodyTruckSetData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<TruckChfee_do_detail> BodyTruckSetData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<TruckChfee_do_detail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
|
cmd.CommandText = strSql.ToString();
|
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(cmd))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
TruckChfee_do_detail data = new TruckChfee_do_detail();
|
|
|
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.FEEDOID = Convert.ToString(reader["GID"]);
|
|
|
data.FEEID = Convert.ToString(reader["FEEID"]);
|
|
|
data.FEENAME = Convert.ToString(reader["FEENAME"]);
|
|
|
data.FEEOBJNAME = Convert.ToString(reader["FEEOBJNAME"]);
|
|
|
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
|
|
|
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
|
|
|
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
|
|
|
if (reader["AMOUNT"] != DBNull.Value)
|
|
|
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
|
|
|
if (reader["DOAMOUNT"] != DBNull.Value)
|
|
|
data.DOAMOUNT = Convert.ToDecimal(reader["DOAMOUNT"]);
|
|
|
data.ORIGCURRENCY = Convert.ToString(reader["ORIGCURRENCY"]);
|
|
|
if (reader["ORIGAMOUNT"] != DBNull.Value)
|
|
|
data.ORIGAMOUNT = Convert.ToDecimal(reader["ORIGAMOUNT"] == DBNull.Value ? "0" : reader["ORIGAMOUNT"]);
|
|
|
if (reader["ORIGSTLAMOUNT"] != DBNull.Value)
|
|
|
data.ORIGSTLAMOUNT = Convert.ToDecimal(reader["ORIGSTLAMOUNT"]);
|
|
|
if (reader["EXCHANGERATE"] != DBNull.Value)
|
|
|
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
|
|
|
if (reader["ETD"] != DBNull.Value)
|
|
|
data.ETD = Convert.ToString(reader["ETD"]);
|
|
|
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
|
|
|
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
|
|
|
data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
|
|
|
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
|
|
|
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
|
|
|
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
|
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
|
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
|
|
|
data.SALE = Convert.ToString(reader["SALE"]);
|
|
|
if (reader["ORIGEXCHANGERATE"] != DBNull.Value)
|
|
|
data.ORIGEXCHANGERATE = Convert.ToDecimal(reader["ORIGEXCHANGERATE"]);
|
|
|
data.REMARK = Convert.ToString(reader["REMARK"]);
|
|
|
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
|
|
|
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
|
|
|
data.TRUCKER = Convert.ToString(reader["TRUCKER"]);
|
|
|
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
|
|
|
if (reader["PKGS"] != DBNull.Value)
|
|
|
data.PKGS = Convert.ToInt32(reader["PKGS"]);
|
|
|
if (reader["KGS"] != DBNull.Value)
|
|
|
data.KGS = Convert.ToDecimal(reader["KGS"]);
|
|
|
if (reader["CBM"] != DBNull.Value)
|
|
|
data.CBM = Convert.ToDecimal(reader["CBM"]);
|
|
|
if (reader["NETWEIGHT"] != DBNull.Value)
|
|
|
data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
public static int getTruckbodyTotalCount(string strCondition, string userid, string usercode, string orgcode)
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select count(c.GID) ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_truck_bulk b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
|
|
|
int cnt = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
cnt = Convert.ToInt32(reader[0]);
|
|
|
}
|
|
|
}
|
|
|
return cnt;
|
|
|
}
|
|
|
|
|
|
static public List<Chfee_do_detail> GetBodyAuditList(int start, int limit, string strCondition, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("FEEOBJNAME", "f.CUSTOMERNAME");
|
|
|
sortstring = sortstring.Replace("FEENAME", "C.FEENAME");
|
|
|
sortstring = sortstring.Replace("AMOUNT", "C.AMOUNT");
|
|
|
sortstring = sortstring.Replace("MBLNO", "B.MBLNO");
|
|
|
sortstring = sortstring.Replace("CUSTNO", "B.CUSTNO");
|
|
|
sortstring = sortstring.Replace("CUSTOMERNAME", "B.CUSTOMERNAME");
|
|
|
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by c.CREATETIME ");
|
|
|
|
|
|
}
|
|
|
strSql.Append(@") as num , ");
|
|
|
strSql.Append(" c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,ISNULL(c.ORIGSTLAMOUNT,0) AS ORIGSTLAMOUNT,c.EXCHANGERATE ");
|
|
|
strSql.Append(",c.FEETYPE,f.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE,f.ACCTAXRATE");
|
|
|
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
|
|
|
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE");
|
|
|
strSql.Append(",b.DOC,b.SALE,(select top 1 INVNO from ch_fee_invoicehexiao where BILLNO IN (SELECT BILLNO FROM ch_fee_do_invoice WHERE FEEID=c.FEEID)) INVOICENO ");
|
|
|
strSql.Append(",f.Remark Remark,f.INPUTMODE,(g.TTLDR-g.STLTTLDR) TTLNODR,c.INVOICESETTLENO ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
|
|
|
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
|
|
|
strSql.Append(" left join v_op_gain_sum_ttl g on (g.bsno=c.PARENTID)");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
|
|
|
|
|
|
return BodySetData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<Chfee_do_detail> BodySetData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<Chfee_do_detail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
|
cmd.CommandText = strSql.ToString();
|
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
|
using (IDataReader reader = db.ExecuteReader(cmd))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Chfee_do_detail data = new Chfee_do_detail();
|
|
|
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.PARENTID = Convert.ToString(reader["PARENTID"]);
|
|
|
data.FEEDOID = Convert.ToString(reader["GID"]);
|
|
|
data.FEEID = Convert.ToString(reader["FEEID"]);
|
|
|
data.FEENAME = Convert.ToString(reader["FEENAME"]);
|
|
|
data.FEEOBJNAME = Convert.ToString(reader["FEEOBJNAME"]);
|
|
|
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
|
|
|
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
|
|
|
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
|
|
|
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
|
|
|
data.DOAMOUNT = Convert.ToDecimal(reader["DOAMOUNT"]);
|
|
|
data.ORIGCURRENCY = Convert.ToString(reader["ORIGCURRENCY"]);
|
|
|
data.ORIGAMOUNT = Convert.ToDecimal(reader["ORIGAMOUNT"]==DBNull.Value?"0":reader["ORIGAMOUNT"]);
|
|
|
data.ORIGSTLAMOUNT = Convert.ToDecimal(reader["ORIGSTLAMOUNT"]);
|
|
|
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
|
|
|
if (reader["ETD"] != DBNull.Value)
|
|
|
data.ETD = Convert.ToString(reader["ETD"]);
|
|
|
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
|
|
|
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
|
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.HBLNO = Convert.ToString(reader["HBLNO"]);
|
|
|
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
|
|
|
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.VESSEL = Convert.ToString(reader["VESSEL"]);
|
|
|
data.VOYNO = Convert.ToString(reader["VOYNO"]);
|
|
|
data.CARRIER = Convert.ToString(reader["CARRIER"]);
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
|
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
|
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
|
|
|
data.DOC = Convert.ToString(reader["DOC"]);
|
|
|
data.SALE = Convert.ToString(reader["SALE"]);
|
|
|
data.INVOICENO = Convert.ToString(reader["INVOICENO"]);
|
|
|
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
|
|
|
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
|
|
|
if (reader["BSSTATUS"] != DBNull.Value)
|
|
|
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
|
|
|
data.BSSTATUSREF= Convert.ToString(reader["BSSTATUSREF"]);
|
|
|
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
|
|
|
if (reader["ORIGEXCHANGERATE"] != DBNull.Value)
|
|
|
data.ORIGEXCHANGERATE = Convert.ToDecimal(reader["ORIGEXCHANGERATE"]);
|
|
|
if (reader["ACCTAXRATE"] != DBNull.Value)
|
|
|
data.ACCTAXRATE = Convert.ToDecimal(reader["ACCTAXRATE"]);
|
|
|
data.Remark = Convert.ToString(reader["Remark"]);
|
|
|
data.BLISSUESTATUS = Convert.ToString(reader["BLISSUESTATUS"]);
|
|
|
data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]);
|
|
|
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
|
|
|
data.COMPANYNAME = Convert.ToString(reader["BSSALECORP"]);
|
|
|
data.ENTERP = Convert.ToString(reader["ENTERP"]);
|
|
|
if (reader["TTLNODR"] != DBNull.Value)
|
|
|
data.TTLNODR = Convert.ToDecimal(reader["TTLNODR"]);
|
|
|
data.BSTYPE = Convert.ToString(reader["BSTYPE"]);
|
|
|
data.INVOICESETTLENO = Convert.ToString(reader["INVOICESETTLENO"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 明细金额币别合计
|
|
|
|
|
|
static public List<Chfee_do_Sum> GetBodySumList(string strCondition)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" SELECT c.FEETYPE,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,c.ORIGCURRENCY CURRENCY,Sum(c.ORIGAMOUNT) AMOUNT ");
|
|
|
strSql.Append(" FROM ch_fee_do c");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
|
|
|
}
|
|
|
strSql.Append(" Group by c.FEETYPE,c.ORIGCURRENCY");
|
|
|
return BodySumSetData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<Chfee_do_Sum> BodySumSetData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<Chfee_do_Sum>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Chfee_do_Sum data = new Chfee_do_Sum();
|
|
|
|
|
|
#region Set DB data to Object
|
|
|
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
|
|
|
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
|
|
|
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
|
|
|
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Inquery FeeDataList
|
|
|
|
|
|
//static public List<BillChfeeDetail> GetFeeDataList(string strCondition, string userid, string usercode, string orgcode, string sort)
|
|
|
//{
|
|
|
|
|
|
// var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
|
|
|
|
|
|
// var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
// var isopenstr = "";
|
|
|
// if (isopen == false)
|
|
|
// {
|
|
|
// isopenstr = " ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ";
|
|
|
// if (!string.IsNullOrEmpty(rangstr))
|
|
|
// rangstr = rangstr + " and " + isopenstr;
|
|
|
// else
|
|
|
// rangstr = isopenstr;
|
|
|
// }
|
|
|
|
|
|
|
|
|
// if (!string.IsNullOrEmpty(rangstr))
|
|
|
// {
|
|
|
// if (!string.IsNullOrEmpty(strCondition))
|
|
|
// {
|
|
|
// strCondition = strCondition + " and " + rangstr;
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// strCondition = rangstr;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// var strSql = new StringBuilder();
|
|
|
|
|
|
// strSql.Append("SELECT ");
|
|
|
// strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
|
|
|
// strSql.Append(",b.CUSTOMERNAME,b.CUSTOMNO");
|
|
|
// strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
|
|
|
// strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
|
|
|
// strSql.Append(",b.DOC,b.SALE");
|
|
|
// strSql.Append(",f.GID AS CH_ID,f.FeeType");
|
|
|
// strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
|
|
|
// strSql.Append(",f.feeName,f.customerName as FeeObjName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,0 DEBITAMOUNT,f.currency,f.exChangerate,isnull(f.invoice,0) as invoice");
|
|
|
// strSql.Append(" from ch_fee f ");
|
|
|
// strSql.Append(" left join v_op_bill b on (b.bsno=f.bsno)");
|
|
|
|
|
|
// if (!string.IsNullOrEmpty(strCondition))
|
|
|
// {
|
|
|
// strSql.Append(" where " + strCondition);
|
|
|
// }
|
|
|
// var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
|
|
|
|
// if (!string.IsNullOrEmpty(sortstring))
|
|
|
// {
|
|
|
// strSql.Append(" order by " + sortstring);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// strSql.Append(" order by b.BsNo");
|
|
|
|
|
|
// }
|
|
|
// return SetFeeData(strSql,"");
|
|
|
//}
|
|
|
|
|
|
static public List<BillChfeeDetail> GetFeeDataList(string strCondition,string duino, string userid, string usercode, string orgcode, string sort)
|
|
|
{
|
|
|
|
|
|
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
|
|
|
|
|
|
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
var isopenstr = "";
|
|
|
if (isopen == false)
|
|
|
{
|
|
|
isopenstr = " ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ";
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
rangstr = rangstr + " and " + isopenstr;
|
|
|
else
|
|
|
rangstr = isopenstr;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
|
|
|
strSql.Append(",b.CUSTOMERNAME,b.CUSTOMNO");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
|
|
|
strSql.Append(",b.DOC,b.SALE");
|
|
|
strSql.Append(",f.GID AS CH_ID,f.FeeType");
|
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
|
|
|
strSql.Append(",f.feeName,f.customerName as FeeObjName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,d.DEBITAMOUNT,f.currency,f.exChangerate,isnull(f.invoice,0) as invoice");
|
|
|
|
|
|
strSql.Append(" from ch_fee f ");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=f.bsno)");
|
|
|
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE 1=1 AND D.DUINO='" + duino + "' AND ISNULL(D.PAYNO,'')='' ");
|
|
|
}
|
|
|
else {
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
|
|
|
strSql.Append(",b.CUSTOMERNAME,b.CUSTOMNO");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
|
|
|
strSql.Append(",b.DOC,b.SALE");
|
|
|
strSql.Append(",f.GID AS CH_ID,f.FeeType");
|
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
|
|
|
strSql.Append(",f.feeName,f.customerName as FeeObjName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,0 DEBITAMOUNT,f.currency,f.exChangerate,isnull(f.invoice,0) as invoice");
|
|
|
strSql.Append(" from ch_fee f ");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=f.bsno)");
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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 b.BsNo");
|
|
|
|
|
|
}
|
|
|
return SetFeeData(strSql,duino);
|
|
|
}
|
|
|
|
|
|
private static List<BillChfeeDetail> SetFeeData(StringBuilder strSql, string duino)
|
|
|
{
|
|
|
var headList = new List<BillChfeeDetail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
|
cmd.CommandText = strSql.ToString();
|
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(cmd))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
BillChfeeDetail data = new BillChfeeDetail();
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
if (reader["ETD"] != DBNull.Value)
|
|
|
data.ETD = Convert.ToString(reader["ETD"]);
|
|
|
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
|
|
|
data.OPLB = Convert.ToString(reader["OPLB"]);
|
|
|
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.HBLNO = Convert.ToString(reader["HBLNO"]);
|
|
|
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
|
|
|
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.VESSEL = Convert.ToString(reader["VESSEL"]);
|
|
|
data.VOYNO = Convert.ToString(reader["VOYNO"]);
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
|
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
|
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
|
|
|
data.DOC = Convert.ToString(reader["DOC"]);
|
|
|
data.SALE = Convert.ToString(reader["SALE"]);
|
|
|
|
|
|
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
|
|
|
|
|
|
data.CH_ID = Convert.ToString(reader["CH_ID"]);
|
|
|
data.FeeType = Convert.ToInt16(reader["FeeType"]);
|
|
|
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
|
|
|
data.FeeName = Convert.ToString(reader["feeName"]);
|
|
|
data.FeeObjName = Convert.ToString(reader["FeeObjName"]);
|
|
|
data.Amount = Convert.ToDecimal(reader["Amount"]);
|
|
|
if (reader["DEBITAMOUNT"] != DBNull.Value)
|
|
|
data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]);
|
|
|
|
|
|
if (reader["BalAmount"] != DBNull.Value)
|
|
|
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
|
|
|
if (data.Amount >= 0)
|
|
|
{
|
|
|
if (data.BalAmount > data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.BalAmount < data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
|
|
|
}
|
|
|
data.BalAmount = balamount;
|
|
|
data.StlAmount = balamount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (reader["BalAmount"] != DBNull.Value)
|
|
|
data.StlAmount = Convert.ToDecimal(reader["BalAmount"]);
|
|
|
}
|
|
|
data.Currency = Convert.ToString(reader["Currency"]);
|
|
|
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
|
|
|
data.Invoice = Convert.ToDecimal(reader["invoice"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 添加列表
|
|
|
|
|
|
static public List<BillCustDetail> GetAddBillList(string strCondition, string userid, string usercode, string orgcode, string sort)
|
|
|
{
|
|
|
|
|
|
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
|
|
|
strSql.Append(",b.CUSTOMERNAME");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD,b.CARRIER");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE,b.STLNAME");
|
|
|
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.CNTRTOTAL");
|
|
|
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVCR,0 BALTTLDR");
|
|
|
strSql.Append(",0 AS DUIRMBDR");
|
|
|
strSql.Append(",0 AS DUIRMBCR");
|
|
|
strSql.Append(",0 AS DUIUSDDR");
|
|
|
strSql.Append(",0 AS DUIUSDCR");
|
|
|
strSql.Append(",0 AS DUIOTDR");
|
|
|
strSql.Append(",0 AS DUIOTCR");
|
|
|
strSql.Append(" FROM CH_FEE f ");
|
|
|
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
|
|
|
strSql.Append(" where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'");
|
|
|
if (SeaeDefaultSort.PARAMVALUE != "2")
|
|
|
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
|
|
|
else
|
|
|
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
|
|
|
|
|
|
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
if (isopen == false)
|
|
|
{
|
|
|
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
strSql.Append("GROUP BY b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
|
|
|
strSql.Append(",b.CUSTOMERNAME");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD,b.CARRIER");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE,b.STLNAME");
|
|
|
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.CNTRTOTAL,f.CUSTOMERNAME");
|
|
|
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring=sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME");
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by b.ETD,b.MBLNO,b.BsNo");
|
|
|
|
|
|
}
|
|
|
return SetAddBillData(strSql,"");
|
|
|
}
|
|
|
|
|
|
static public List<BillCustDetail> GetAddBillList(int start, int limit, string strCondition,string duino, string userid, string usercode, string orgcode, string sort)
|
|
|
{
|
|
|
|
|
|
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='PAYUSEFEERANGE'");
|
|
|
if (PAYUSEFEERANGE.PARAMVALUE == "1")
|
|
|
{
|
|
|
var rangstrfee = GetRangAddFeeDAStr(userid, usercode, orgcode);
|
|
|
if (!string.IsNullOrEmpty(rangstrfee))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstrfee;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstrfee;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME");
|
|
|
sortstring = sortstring.Replace("BALRMBINVCR", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
sortstring = sortstring.Replace("BALUSDINVCR", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
sortstring = sortstring.Replace("RMBCrBalAmount", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
sortstring = sortstring.Replace("USDCrBalAmount", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by b.ETD,b.MBLNO,b.BsNo");
|
|
|
|
|
|
}
|
|
|
strSql.Append(@") as num , ");
|
|
|
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
|
|
|
strSql.Append(",b.CUSTOMERNAME");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD,b.CARRIER");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE,b.STLNAME");
|
|
|
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.CNTRTOTAL");
|
|
|
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME,(select [NAME] FROM company where GID=B.SALECORPID) SALECORP ");
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVCR");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN d.DEBITAMOUNT ELSE 0 END) ELSE 0 END),0) AS DUIRMBDR");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN d.DEBITAMOUNT ELSE 0 END)ELSE 0 END),0) AS DUIRMBCR");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN d.DEBITAMOUNT ELSE 0 END)ELSE 0 END),0) AS DUIUSDDR");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN d.DEBITAMOUNT ELSE 0 END)ELSE 0 END),0) AS DUIUSDCR");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE d.DEBITAMOUNT END) END) ELSE 0 END),0) AS DUIOTDR");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE d.DEBITAMOUNT END) END) ELSE 0 END),0) AS DUIOTCR");
|
|
|
|
|
|
|
|
|
|
|
|
strSql.Append(",G.RMBDR BLRMBDR,G.STLRMBDR BLSTLRMBDR,G.USDDR BLUSDDR,G.STLUSDDR BLSTLUSDDR,G.TTLDR-G.STLTTLDR BALTTLDR ");
|
|
|
strSql.Append(" FROM CH_FEE f ");
|
|
|
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
|
|
|
strSql.Append(" LEFT JOIN v_op_gain_sum G ON (G.BSNO=F.BSNO) ");
|
|
|
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='" + duino + "' AND ISNULL(D.PAYNO,'')='' ");
|
|
|
strSql.Append(" and (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVCR");
|
|
|
strSql.Append(",0 AS DUIRMBDR");
|
|
|
strSql.Append(",0 AS DUIRMBCR");
|
|
|
strSql.Append(",0 AS DUIUSDDR");
|
|
|
strSql.Append(",0 AS DUIUSDCR");
|
|
|
strSql.Append(",0 AS DUIOTDR");
|
|
|
strSql.Append(",0 AS DUIOTCR");
|
|
|
|
|
|
|
|
|
strSql.Append(",G.RMBDR BLRMBDR,G.STLRMBDR BLSTLRMBDR,G.USDDR BLUSDDR,G.STLUSDDR BLSTLUSDDR,G.TTLDR-G.STLTTLDR BALTTLDR ");
|
|
|
strSql.Append(" FROM CH_FEE f ");
|
|
|
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
|
|
|
strSql.Append(" LEFT JOIN v_op_gain_sum G ON (G.BSNO=F.BSNO) ");
|
|
|
strSql.Append(" where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'");
|
|
|
if (SeaeDefaultSort.PARAMVALUE != "2")
|
|
|
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
|
|
|
else
|
|
|
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
|
|
|
|
|
|
|
|
|
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
if (isopen == false)
|
|
|
{
|
|
|
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append("GROUP BY b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.ORDERNO");
|
|
|
strSql.Append(",b.CUSTOMERNAME,B.SALECORPID");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD,b.CARRIER");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE,b.STLNAME");
|
|
|
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.CNTRTOTAL,G.RMBDR,G.STLRMBDR,G.USDDR,G.STLUSDDR,G.TTLDR-G.STLTTLDR,f.CUSTOMERNAME");
|
|
|
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
|
|
|
return SetAddBillData(strSql,duino);
|
|
|
}
|
|
|
|
|
|
public static int getAddBillTotalCount(string strCondition,string duino, string userid, string usercode, string companyid)
|
|
|
{
|
|
|
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='PAYUSEFEERANGE'");
|
|
|
if (PAYUSEFEERANGE.PARAMVALUE == "1")
|
|
|
{
|
|
|
var rangstrfee = GetRangAddFeeDAStr(userid, usercode, companyid);
|
|
|
if (!string.IsNullOrEmpty(rangstrfee))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstrfee;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstrfee;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
|
|
|
strSql.Append(" FROM CH_FEE f ");
|
|
|
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
|
|
|
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='" + duino + "' AND ISNULL(D.PAYNO,'')='' ");
|
|
|
strSql.Append(" and (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
|
|
|
strSql.Append(" FROM CH_FEE f ");
|
|
|
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
|
|
|
strSql.Append(" where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'");
|
|
|
if (SeaeDefaultSort.PARAMVALUE != "2")
|
|
|
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
|
|
|
else
|
|
|
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
|
|
|
|
|
|
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
if (isopen == false)
|
|
|
{
|
|
|
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append("GROUP BY b.BSNO,f.CUSTOMERNAME) AS T ");
|
|
|
|
|
|
int cnt = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
cnt = Convert.ToInt32(reader[0]);
|
|
|
}
|
|
|
}
|
|
|
return cnt;
|
|
|
}
|
|
|
|
|
|
private static List<BillCustDetail> SetAddBillData(StringBuilder strSql,string duino)
|
|
|
{
|
|
|
var headList = new List<BillCustDetail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
decimal BLRMBDR = 0;
|
|
|
decimal BLUSDDR = 0;
|
|
|
decimal BLSTLRMBDR = 0;
|
|
|
decimal BLSTLUSDDR = 0;
|
|
|
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
|
cmd.CommandText = strSql.ToString();
|
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(cmd))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
BLRMBDR = 0;
|
|
|
BLUSDDR = 0;
|
|
|
BLSTLRMBDR = 0;
|
|
|
BLSTLUSDDR = 0;
|
|
|
BillCustDetail data = new BillCustDetail();
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
if (reader["ETD"] != DBNull.Value)
|
|
|
data.ETD = Convert.ToString(reader["ETD"]);
|
|
|
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
|
|
|
data.OPLB = Convert.ToString(reader["OPLB"]);
|
|
|
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
|
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.HBLNO = Convert.ToString(reader["HBLNO"]);
|
|
|
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
|
|
|
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.VESSEL = Convert.ToString(reader["VESSEL"]);
|
|
|
data.VOYNO = Convert.ToString(reader["VOYNO"]);
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
data.CARRIER = Convert.ToString(reader["CARRIER"]);
|
|
|
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
|
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
|
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
|
|
|
data.DOC = Convert.ToString(reader["DOC"]);
|
|
|
data.SALE = Convert.ToString(reader["SALE"]);
|
|
|
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
|
|
|
data.SALECORP = Convert.ToString(reader["SALECORP"]);
|
|
|
|
|
|
|
|
|
data.STLNAME = Convert.ToString(reader["STLNAME"]);
|
|
|
if (reader["BLRMBDR"] != DBNull.Value)
|
|
|
BLRMBDR = Convert.ToDecimal(reader["BLRMBDR"]);
|
|
|
if (reader["BLUSDDR"] != DBNull.Value)
|
|
|
BLUSDDR = Convert.ToDecimal(reader["BLUSDDR"]);
|
|
|
if (reader["BLSTLRMBDR"] != DBNull.Value)
|
|
|
BLSTLRMBDR = Convert.ToDecimal(reader["BLSTLRMBDR"]);
|
|
|
if (reader["BLSTLUSDDR"] != DBNull.Value)
|
|
|
BLSTLUSDDR = Convert.ToDecimal(reader["BLSTLUSDDR"]);
|
|
|
if (BLRMBDR == BLSTLRMBDR && BLRMBDR!=0)
|
|
|
data.RMBDRSTATUS ="已收回";
|
|
|
if (BLSTLRMBDR == 0 && BLRMBDR != 0)
|
|
|
data.RMBDRSTATUS = "未收";
|
|
|
if (BLSTLRMBDR!=0&&BLRMBDR != BLSTLRMBDR)
|
|
|
data.RMBDRSTATUS = "部分收回";
|
|
|
if (BLUSDDR == BLSTLUSDDR && BLUSDDR != 0)
|
|
|
data.USDDRSTATUS = "已收回";
|
|
|
if (BLSTLUSDDR == 0 && BLUSDDR != 0)
|
|
|
data.USDDRSTATUS = "未收";
|
|
|
if (BLSTLUSDDR !=0&&BLUSDDR != BLSTLUSDDR)
|
|
|
data.USDDRSTATUS = "部分收回";
|
|
|
|
|
|
|
|
|
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
|
|
|
data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]);
|
|
|
|
|
|
if (reader["RMBDR"] != DBNull.Value)
|
|
|
data.RMBDrAmount = Convert.ToDecimal(reader["RMBDR"]);
|
|
|
if (reader["BALRMBDR"] != DBNull.Value)
|
|
|
{
|
|
|
data.RMBDrBalAmount = Convert.ToDecimal(reader["BALRMBDR"]);
|
|
|
data.RMBDrDoAmount = Convert.ToDecimal(reader["BALRMBDR"]);
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
if (reader["DUIRMBDR"] != DBNull.Value)
|
|
|
data.RMBDrDoAmount = Convert.ToDecimal(reader["DUIRMBDR"]);
|
|
|
if (data.RMBDrAmount > 0)
|
|
|
{
|
|
|
if (data.RMBDrBalAmount > data.RMBDrDoAmount) balamount = data.RMBDrDoAmount; else balamount = data.RMBDrBalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.RMBDrBalAmount < data.RMBDrDoAmount) balamount = data.RMBDrDoAmount; else balamount = data.RMBDrBalAmount;
|
|
|
}
|
|
|
data.RMBDrBalAmount = balamount;
|
|
|
data.RMBDrDoAmount = balamount;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (reader["RMBCR"] != DBNull.Value)
|
|
|
data.RMBCrAmount = Convert.ToDecimal(reader["RMBCR"]);
|
|
|
if (reader["BALRMBCR"] != DBNull.Value)
|
|
|
data.RMBCrBalAmount = Convert.ToDecimal(reader["BALRMBCR"]);
|
|
|
if (reader["BALRMBCR"] != DBNull.Value)
|
|
|
data.RMBCrDoAmount = Convert.ToDecimal(reader["BALRMBCR"]);
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
if (reader["DUIRMBCR"] != DBNull.Value)
|
|
|
data.RMBCrDoAmount = Convert.ToDecimal(reader["DUIRMBCR"]);
|
|
|
if (data.RMBCrAmount > 0)
|
|
|
{
|
|
|
if (data.RMBCrBalAmount > data.RMBCrDoAmount) balamount = data.RMBCrDoAmount; else balamount = data.RMBCrBalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.RMBCrBalAmount < data.RMBCrDoAmount) balamount = data.RMBCrDoAmount; else balamount = data.RMBCrBalAmount;
|
|
|
}
|
|
|
data.RMBCrBalAmount = balamount;
|
|
|
data.RMBCrDoAmount = balamount;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (reader["USDDR"] != DBNull.Value)
|
|
|
data.USDDrAmount = Convert.ToDecimal(reader["USDDR"]);
|
|
|
if (reader["BALUSDDR"] != DBNull.Value)
|
|
|
data.USDDrBalAmount = Convert.ToDecimal(reader["BALUSDDR"]);
|
|
|
if (reader["BALUSDDR"] != DBNull.Value)
|
|
|
data.USDDrDoAmount = Convert.ToDecimal(reader["BALUSDDR"]);
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
if (reader["DUIUSDDR"] != DBNull.Value)
|
|
|
data.USDDrDoAmount = Convert.ToDecimal(reader["DUIUSDDR"]);
|
|
|
if (data.USDDrAmount > 0)
|
|
|
{
|
|
|
if (data.USDDrBalAmount > data.USDDrDoAmount) balamount = data.USDDrDoAmount; else balamount = data.USDDrBalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.USDDrBalAmount < data.USDDrDoAmount) balamount = data.USDDrDoAmount; else balamount = data.USDDrBalAmount;
|
|
|
}
|
|
|
data.USDDrBalAmount = balamount;
|
|
|
data.USDDrDoAmount = balamount;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (reader["USDCR"] != DBNull.Value)
|
|
|
data.USDCrAmount = Convert.ToDecimal(reader["USDCR"]);
|
|
|
if (reader["BALUSDCR"] != DBNull.Value)
|
|
|
data.USDCrBalAmount = Convert.ToDecimal(reader["BALUSDCR"]);
|
|
|
if (reader["BALUSDCR"] != DBNull.Value)
|
|
|
data.USDCrDoAmount = Convert.ToDecimal(reader["BALUSDCR"]);
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
if (reader["DUIUSDCR"] != DBNull.Value)
|
|
|
data.USDCrDoAmount = Convert.ToDecimal(reader["DUIUSDCR"]);
|
|
|
if (data.USDCrAmount > 0)
|
|
|
{
|
|
|
if (data.USDCrBalAmount > data.USDCrDoAmount) balamount = data.USDCrDoAmount; else balamount = data.USDCrBalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.USDCrBalAmount < data.USDCrDoAmount) balamount = data.USDCrDoAmount; else balamount = data.USDCrBalAmount;
|
|
|
}
|
|
|
data.USDCrBalAmount = balamount;
|
|
|
data.USDCrDoAmount = balamount;
|
|
|
}
|
|
|
|
|
|
if (reader["OTDR"] != DBNull.Value)
|
|
|
data.OTDrAmount = Convert.ToDecimal(reader["OTDR"]);
|
|
|
if (reader["BALOTDR"] != DBNull.Value)
|
|
|
data.OTDrBalAmount = Convert.ToDecimal(reader["BALOTDR"]);
|
|
|
if (reader["BALOTDR"] != DBNull.Value)
|
|
|
data.OTDrDoAmount = Convert.ToDecimal(reader["BALOTDR"]);
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
if (reader["DUIOTDR"] != DBNull.Value)
|
|
|
data.OTDrDoAmount = Convert.ToDecimal(reader["DUIOTDR"]);
|
|
|
if (data.OTDrAmount > 0)
|
|
|
{
|
|
|
if (data.OTDrBalAmount > data.OTDrDoAmount) balamount = data.OTDrDoAmount; else balamount = data.OTDrBalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.OTDrBalAmount < data.OTDrDoAmount) balamount = data.OTDrDoAmount; else balamount = data.OTDrBalAmount;
|
|
|
}
|
|
|
data.OTDrBalAmount = balamount;
|
|
|
data.OTDrDoAmount = balamount;
|
|
|
}
|
|
|
|
|
|
if (reader["OTCR"] != DBNull.Value)
|
|
|
data.OTCrAmount = Convert.ToDecimal(reader["OTCR"]);
|
|
|
if (reader["BALOTCR"] != DBNull.Value)
|
|
|
data.OTCrBalAmount = Convert.ToDecimal(reader["BALOTCR"]);
|
|
|
if (reader["BALOTCR"] != DBNull.Value)
|
|
|
data.OTCrDoAmount = Convert.ToDecimal(reader["BALOTCR"]);
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
if (reader["DUIOTCR"] != DBNull.Value)
|
|
|
data.OTCrDoAmount = Convert.ToDecimal(reader["DUIOTCR"]);
|
|
|
if (data.OTCrAmount > 0)
|
|
|
{
|
|
|
if (data.OTCrBalAmount > data.OTCrDoAmount) balamount = data.OTCrDoAmount; else balamount = data.OTCrBalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.OTCrBalAmount < data.OTCrDoAmount) balamount = data.OTCrDoAmount; else balamount = data.OTCrBalAmount;
|
|
|
}
|
|
|
data.OTCrBalAmount = balamount;
|
|
|
data.OTCrDoAmount = balamount;
|
|
|
}
|
|
|
|
|
|
if (reader["BALRMBINVDR"] != DBNull.Value)
|
|
|
data.BALRMBINVDR = Convert.ToDecimal(reader["BALRMBINVDR"]);
|
|
|
if (reader["BALRMBINVCR"] != DBNull.Value)
|
|
|
data.BALRMBINVCR = Convert.ToDecimal(reader["BALRMBINVCR"]);
|
|
|
if (reader["BALUSDINVDR"] != DBNull.Value)
|
|
|
data.BALUSDINVDR = Convert.ToDecimal(reader["BALUSDINVDR"]);
|
|
|
if (reader["BALUSDINVCR"] != DBNull.Value)
|
|
|
data.BALUSDINVCR = Convert.ToDecimal(reader["BALUSDINVCR"]);
|
|
|
if (reader["BALTTLDR"] != DBNull.Value)
|
|
|
data.BALTTLDR = Convert.ToDecimal(reader["BALTTLDR"]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
|
|
|
static public List<BillTruckCustDetail> GetAddTruckBillList(int start, int limit, string strCondition, string userid, string usercode, string orgcode, string sort)
|
|
|
{
|
|
|
|
|
|
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='PAYUSEFEERANGE'");
|
|
|
if (PAYUSEFEERANGE.PARAMVALUE == "1")
|
|
|
{
|
|
|
var rangstrfee = GetRangAddFeeDAStr(userid, usercode, orgcode);
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstrfee;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * from (SELECT row_number() over (");
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME");
|
|
|
sortstring = sortstring.Replace("BALRMBINVCR", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
sortstring = sortstring.Replace("BALUSDINVCR", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
sortstring = sortstring.Replace("RMBCrBalAmount", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
sortstring = sortstring.Replace("USDCrBalAmount", "isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0)");
|
|
|
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by b.ETD,b.MBLNO,b.BsNo");
|
|
|
|
|
|
}
|
|
|
strSql.Append(@") as num , ");
|
|
|
strSql.Append("b.BSNO,b.TRANSTYPE,b.TRANSSTATUS,b.CUSTOMERNAME,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.BSDATE,");
|
|
|
strSql.Append("b.ETD,b.ETA,b.OP,b.SALE,b.CUSTSERVICE,b.CUSTATTN,b.CUSTTEL,b.CONSIGNEENAME,b.CONSIGNEEATTN,b.CONSIGNEETEL,b.CONSIGNEEADDR,");
|
|
|
strSql.Append("b.PORTLOAD,b.PORTDISCHARGE,b.GOODSNAME,b.KGS,b.NETWEIGHT,b.CBM,b.PKGS,b.KINDPKGS,b.TRUCKER,b.TRUCKNO,b.MBLNO");
|
|
|
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
|
|
|
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END) ELSE 0 END),0) AS BALRMBDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN ISNULL(AMOUNT,0) ELSE 0 END)ELSE 0 END),0) AS USDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE ISNULL(AMOUNT,0) END) END)ELSE 0 END),0) AS OTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDINVCR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVDR,");
|
|
|
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN f.AMOUNT-ISNULL(INVOICE,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBINVCR");
|
|
|
strSql.Append(",G.RMBDR BLRMBDR,G.STLRMBDR BLSTLRMBDR,G.USDDR BLUSDDR,G.STLUSDDR BLSTLUSDDR ");
|
|
|
strSql.Append(" FROM CH_FEE f ");
|
|
|
strSql.Append(" INNER JOIN v_op_truck_bulk B ON (F.BSNO=B.BSNO) ");
|
|
|
strSql.Append(" LEFT JOIN v_op_gain_sum G ON (G.BSNO=F.BSNO) ");
|
|
|
strSql.Append(" where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'");
|
|
|
if (SeaeDefaultSort.PARAMVALUE != "2")
|
|
|
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
|
|
|
else
|
|
|
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
|
|
|
|
|
|
|
|
|
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
if (isopen == false)
|
|
|
{
|
|
|
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append("GROUP BY b.BSNO,b.TRANSTYPE,b.TRANSSTATUS,b.CUSTOMERNAME,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.BSDATE");
|
|
|
strSql.Append(",b.ETD,b.ETA,b.OP,b.SALE,b.CUSTSERVICE,b.CUSTATTN,b.CUSTTEL,b.CONSIGNEENAME,b.CONSIGNEEATTN,b.CONSIGNEETEL,b.CONSIGNEEADDR");
|
|
|
strSql.Append(",b.PORTLOAD,b.PORTDISCHARGE,b.GOODSNAME,b.KGS,b.NETWEIGHT,b.CBM,b.PKGS,b.KINDPKGS,b.TRUCKER,b.TRUCKNO,b.MBLNO");
|
|
|
strSql.Append(",G.RMBDR,G.STLRMBDR,G.USDDR,G.STLUSDDR,f.CUSTOMERNAME");
|
|
|
|
|
|
strSql.Append(@")as t ");
|
|
|
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
|
|
|
|
|
|
return SetAddTruckBillData(strSql);
|
|
|
}
|
|
|
|
|
|
public static int getAddTruckBillTotalCount(string strCondition, string userid, string usercode, string companyid)
|
|
|
{
|
|
|
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
|
|
|
strSql.Append(" FROM CH_FEE f ");
|
|
|
strSql.Append(" INNER JOIN v_op_truck_bulk B ON (F.BSNO=B.BSNO) ");
|
|
|
strSql.Append(" where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'");
|
|
|
if (SeaeDefaultSort.PARAMVALUE != "2")
|
|
|
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
|
|
|
else
|
|
|
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
|
|
|
|
|
|
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
if (isopen == false)
|
|
|
{
|
|
|
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append("GROUP BY b.BSNO,f.CUSTOMERNAME) AS T ");
|
|
|
|
|
|
int cnt = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
cnt = Convert.ToInt32(reader[0]);
|
|
|
}
|
|
|
}
|
|
|
return cnt;
|
|
|
}
|
|
|
|
|
|
private static List<BillTruckCustDetail> SetAddTruckBillData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<BillTruckCustDetail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
decimal BLRMBDR = 0;
|
|
|
decimal BLUSDDR = 0;
|
|
|
decimal BLSTLRMBDR = 0;
|
|
|
decimal BLSTLUSDDR = 0;
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
BLRMBDR = 0;
|
|
|
BLUSDDR = 0;
|
|
|
BLSTLRMBDR = 0;
|
|
|
BLSTLUSDDR = 0;
|
|
|
BillTruckCustDetail data = new BillTruckCustDetail();
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
if (reader["ETD"] != DBNull.Value)
|
|
|
data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");
|
|
|
if (reader["ETA"] != DBNull.Value)
|
|
|
data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd");
|
|
|
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
|
|
|
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
|
|
|
data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
|
|
|
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
|
|
|
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
|
|
|
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
|
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
|
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
|
|
|
data.SALE = Convert.ToString(reader["SALE"]);
|
|
|
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
|
|
|
data.TRUCKER = Convert.ToString(reader["TRUCKER"]);
|
|
|
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);
|
|
|
if (reader["PKGS"] != DBNull.Value)
|
|
|
data.PKGS = Convert.ToInt32(reader["PKGS"]);
|
|
|
if (reader["KGS"] != DBNull.Value)
|
|
|
data.KGS = Convert.ToDecimal(reader["KGS"]);
|
|
|
if (reader["NETWEIGHT"] != DBNull.Value)
|
|
|
data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]);
|
|
|
if (reader["CBM"] != DBNull.Value)
|
|
|
data.CBM = Convert.ToDecimal(reader["CBM"]);
|
|
|
if (reader["BLRMBDR"] != DBNull.Value)
|
|
|
BLRMBDR = Convert.ToDecimal(reader["BLRMBDR"]);
|
|
|
if (reader["BLUSDDR"] != DBNull.Value)
|
|
|
BLUSDDR = Convert.ToDecimal(reader["BLUSDDR"]);
|
|
|
if (reader["BLSTLRMBDR"] != DBNull.Value)
|
|
|
BLSTLRMBDR = Convert.ToDecimal(reader["BLSTLRMBDR"]);
|
|
|
if (reader["BLSTLUSDDR"] != DBNull.Value)
|
|
|
BLSTLUSDDR = Convert.ToDecimal(reader["BLSTLUSDDR"]);
|
|
|
if (BLRMBDR == BLSTLRMBDR && BLRMBDR != 0)
|
|
|
data.RMBDRSTATUS = "已收回";
|
|
|
if (BLSTLRMBDR == 0 && BLRMBDR != 0)
|
|
|
data.RMBDRSTATUS = "未收";
|
|
|
if (BLRMBDR != BLSTLRMBDR)
|
|
|
data.RMBDRSTATUS = "部分收回";
|
|
|
if (BLUSDDR == BLSTLUSDDR && BLUSDDR != 0)
|
|
|
data.USDDRSTATUS = "已收回";
|
|
|
if (BLSTLUSDDR == 0 && BLUSDDR != 0)
|
|
|
data.USDDRSTATUS = "未收";
|
|
|
if (BLUSDDR != BLSTLUSDDR)
|
|
|
data.USDDRSTATUS = "部分收回";
|
|
|
|
|
|
|
|
|
data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]);
|
|
|
|
|
|
if (reader["RMBDR"] != DBNull.Value)
|
|
|
data.RMBDrAmount = Convert.ToDecimal(reader["RMBDR"]);
|
|
|
if (reader["BALRMBDR"] != DBNull.Value)
|
|
|
data.RMBDrBalAmount = Convert.ToDecimal(reader["BALRMBDR"]);
|
|
|
if (reader["BALRMBDR"] != DBNull.Value)
|
|
|
data.RMBDrDoAmount = Convert.ToDecimal(reader["BALRMBDR"]);
|
|
|
|
|
|
if (reader["RMBCR"] != DBNull.Value)
|
|
|
data.RMBCrAmount = Convert.ToDecimal(reader["RMBCR"]);
|
|
|
if (reader["BALRMBCR"] != DBNull.Value)
|
|
|
data.RMBCrBalAmount = Convert.ToDecimal(reader["BALRMBCR"]);
|
|
|
if (reader["BALRMBCR"] != DBNull.Value)
|
|
|
data.RMBCrDoAmount = Convert.ToDecimal(reader["BALRMBCR"]);
|
|
|
if (reader["USDDR"] != DBNull.Value)
|
|
|
data.USDDrAmount = Convert.ToDecimal(reader["USDDR"]);
|
|
|
if (reader["BALUSDDR"] != DBNull.Value)
|
|
|
data.USDDrBalAmount = Convert.ToDecimal(reader["BALUSDDR"]);
|
|
|
if (reader["BALUSDDR"] != DBNull.Value)
|
|
|
data.USDDrDoAmount = Convert.ToDecimal(reader["BALUSDDR"]);
|
|
|
if (reader["USDCR"] != DBNull.Value)
|
|
|
data.USDCrAmount = Convert.ToDecimal(reader["USDCR"]);
|
|
|
if (reader["BALUSDCR"] != DBNull.Value)
|
|
|
data.USDCrBalAmount = Convert.ToDecimal(reader["BALUSDCR"]);
|
|
|
if (reader["BALUSDCR"] != DBNull.Value)
|
|
|
data.USDCrDoAmount = Convert.ToDecimal(reader["BALUSDCR"]);
|
|
|
|
|
|
if (reader["OTDR"] != DBNull.Value)
|
|
|
data.OTDrAmount = Convert.ToDecimal(reader["OTDR"]);
|
|
|
if (reader["BALOTDR"] != DBNull.Value)
|
|
|
data.OTDrBalAmount = Convert.ToDecimal(reader["BALOTDR"]);
|
|
|
if (reader["BALOTDR"] != DBNull.Value)
|
|
|
data.OTDrDoAmount = Convert.ToDecimal(reader["BALOTDR"]);
|
|
|
if (reader["OTCR"] != DBNull.Value)
|
|
|
data.OTCrAmount = Convert.ToDecimal(reader["OTCR"]);
|
|
|
if (reader["BALOTCR"] != DBNull.Value)
|
|
|
data.OTCrBalAmount = Convert.ToDecimal(reader["BALOTCR"]);
|
|
|
if (reader["BALOTCR"] != DBNull.Value)
|
|
|
data.OTCrDoAmount = Convert.ToDecimal(reader["BALOTCR"]);
|
|
|
|
|
|
if (reader["BALRMBINVDR"] != DBNull.Value)
|
|
|
data.BALRMBINVDR = Convert.ToDecimal(reader["BALRMBINVDR"]);
|
|
|
if (reader["BALRMBINVCR"] != DBNull.Value)
|
|
|
data.BALRMBINVCR = Convert.ToDecimal(reader["BALRMBINVCR"]);
|
|
|
if (reader["BALUSDINVDR"] != DBNull.Value)
|
|
|
data.BALUSDINVDR = Convert.ToDecimal(reader["BALUSDINVDR"]);
|
|
|
if (reader["BALUSDINVCR"] != DBNull.Value)
|
|
|
data.BALUSDINVCR = Convert.ToDecimal(reader["BALUSDINVCR"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 费用列表明细
|
|
|
static public List<ChFeeDetail> GetFeeDetailList(string strCondition,string duino,string userid,string usercode,string companyid,string sort=null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='PAYUSEFEERANGE'");
|
|
|
if (PAYUSEFEERANGE.PARAMVALUE == "1")
|
|
|
{
|
|
|
var rangstr = GetRangAddFeeDAStr(userid, usercode, companyid);
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
strSql.Append("SELECT * from (select ");
|
|
|
strSql.Append("f.BSNO,f.GID AS CH_ID,FeeType");
|
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
|
|
|
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,f.currency,f.exChangerate,f.AccTaxRate,f.invoice,f.remark");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=f.EnteroPerator) as OpName");
|
|
|
strSql.Append(",f.INPUTMODE,f.SALECORP,d.DEBITAMOUNT from ch_fee f ");
|
|
|
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='" + duino + "' AND ISNULL(D.PAYNO,'')='' and (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
strSql.Append("SELECT * from (select ");
|
|
|
strSql.Append("f.BSNO,f.GID AS CH_ID,FeeType");
|
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
|
|
|
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,f.currency,f.exChangerate,f.AccTaxRate,f.invoice,f.remark");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=f.EnteroPerator) as OpName");
|
|
|
strSql.Append(",f.INPUTMODE,f.SALECORP,0 DEBITAMOUNT from ch_fee f where (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var SeaeDefaultSort = MsSysParamSetDAL.GetData("PARAMNAME='PayAppFeeStatus'");
|
|
|
if (SeaeDefaultSort.PARAMVALUE != "2")
|
|
|
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
|
|
|
else
|
|
|
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
|
|
|
|
|
|
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
|
|
|
if (isopen == false)
|
|
|
{
|
|
|
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
|
|
|
}
|
|
|
|
|
|
|
|
|
strSql.Append(" ) AS VF ");
|
|
|
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
sortstring = sortstring.Replace("StlAmount", "balamount");
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by balamount");
|
|
|
|
|
|
}
|
|
|
|
|
|
return SetFeeDetailData(strSql,duino);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<ChFeeDetail> SetFeeDetailData(StringBuilder strSql,string duino)
|
|
|
{
|
|
|
var headList = new List<ChFeeDetail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
|
cmd.CommandText = strSql.ToString();
|
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
|
using (IDataReader reader = db.ExecuteReader(cmd))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ChFeeDetail data = new ChFeeDetail();
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.CH_ID = Convert.ToString(reader["CH_ID"]);
|
|
|
data.FeeType = Convert.ToInt16(reader["FeeType"]);
|
|
|
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
|
|
|
data.FeeName = Convert.ToString(reader["feeName"]);
|
|
|
data.CustomerName = Convert.ToString(reader["customerName"]);
|
|
|
data.Amount = Convert.ToDecimal(reader["Amount"]);
|
|
|
if (reader["BalAmount"] != DBNull.Value)
|
|
|
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
|
|
|
if (reader["DEBITAMOUNT"] != DBNull.Value)
|
|
|
data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]);
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
decimal balamount = 0;
|
|
|
|
|
|
if (data.Amount >= 0)
|
|
|
{
|
|
|
if (data.BalAmount > data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (data.BalAmount < data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
|
|
|
}
|
|
|
data.BalAmount = balamount;
|
|
|
data.StlAmount = balamount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (reader["BalAmount"] != DBNull.Value)
|
|
|
data.StlAmount = Convert.ToDecimal(reader["BalAmount"]);
|
|
|
}
|
|
|
|
|
|
|
|
|
data.Currency = Convert.ToString(reader["Currency"]);
|
|
|
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
|
|
|
if (reader["invoice"] != DBNull.Value)
|
|
|
data.Invoice = Convert.ToDecimal(reader["invoice"]);
|
|
|
data.Remark = Convert.ToString(reader["Remark"]);
|
|
|
data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]);
|
|
|
data.SALECORP = Convert.ToString(reader["SALECORP"]);
|
|
|
if (reader["AccTaxRate"] != DBNull.Value)
|
|
|
data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]);
|
|
|
data.INPUTBY = Convert.ToString(reader["OpName"]);
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
static public List<Chfee_do_Sum> GetAddSum(string strCondition, string userid, string usercode, string orgcode)
|
|
|
{
|
|
|
|
|
|
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append(" SELECT f.FEETYPE,(CASE f.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.CURRENCY,Sum(f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0)) AMOUNT ");
|
|
|
strSql.Append(" from ch_fee f ");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=f.bsno)");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
}
|
|
|
strSql.Append(" Group by f.FEETYPE,f.CURRENCY");
|
|
|
|
|
|
return BodySumSetData(strSql);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public List<ChFeeExrate> GetCurrExrateData(string billcust, string billcurr, string feesql, bool custgroup = false)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append(" SELECT DISTINCT CURRENCY,EXCHANGERATE ");
|
|
|
if (!custgroup)
|
|
|
strSql.Append(" FROM ch_fee f where CURRENCY<>'" + billcurr + "' AND CUSTOMERNAME='" + billcust + "'");
|
|
|
else
|
|
|
strSql.Append(" FROM ch_fee f where CURRENCY<>'" + billcurr + "'");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(feesql))
|
|
|
{
|
|
|
strSql.Append(" and " + feesql);
|
|
|
}
|
|
|
|
|
|
return SetCurrExrateData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<ChFeeExrate> SetCurrExrateData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<ChFeeExrate>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ChFeeExrate data = new ChFeeExrate();
|
|
|
#region Set DB data to Object
|
|
|
data.CURR = Convert.ToString(reader["CURRENCY"]);
|
|
|
data.EXRATE = 0;
|
|
|
if (reader["EXCHANGERATE"] != DBNull.Value)
|
|
|
data.DFEXRATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static DBResult AddDetail(string billno,string duino, List<ChFeeDetail> bodyList, string curr, string companyid,string salecorp)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
var STLONESALECORP = MsSysParamSetDAL.GetData("PARAMNAME='STLONESALECORP'");
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
var cmdInsert =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"insert into ch_fee_do (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
|
|
|
,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,ISDELETED,CREATETIME
|
|
|
,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO,COMPANYID)
|
|
|
values (@GID,@BILLNO,@BSNO,@MBLNO,@HBLNO,@CUSTOMERNAME,@BSTYPE,@FEEID,@FEENAME,@CURRENCY
|
|
|
,@AMOUNT,@DOAMOUNT,@FEETYPE,@CATEGORY,@BILLSTATUS,@ISDELETED,@CREATETIME
|
|
|
,@EXCHANGERATE,@ORIGCURRENCY,@ORIGAMOUNT,@INVOICESETTLENO,@COMPANYID) ");
|
|
|
|
|
|
var cmdUpdate =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"UPDATE CH_FEE SET ORDERAMOUNT=ISNULL(ORDERAMOUNT,0)+@ORDERAMOUNT WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT2)>=0)
|
|
|
OR (AMOUNT<0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT3)<=0))");
|
|
|
|
|
|
|
|
|
if (bodyList != null)
|
|
|
{
|
|
|
foreach (var enumValue in bodyList)
|
|
|
{
|
|
|
|
|
|
if ((enumValue.DoAmount!=0)&&((STLONESALECORP.PARAMVALUE == "1" && salecorp != "" && salecorp == enumValue.SALECORP)|| STLONESALECORP.PARAMVALUE != "1"))
|
|
|
{
|
|
|
|
|
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
|
|
|
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT", DbType.Decimal, enumValue.StlAmount);
|
|
|
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT2", DbType.Decimal, enumValue.StlAmount);
|
|
|
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT3", DbType.Decimal, enumValue.StlAmount);
|
|
|
var updatecount=db.ExecuteNonQuery(cmdUpdate, tran);
|
|
|
|
|
|
if (updatecount == 1)
|
|
|
{
|
|
|
cmdInsert.Parameters.Clear();
|
|
|
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
|
|
|
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO);
|
|
|
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, enumValue.MBLNO);
|
|
|
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, enumValue.HBLNO);
|
|
|
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.FeeObjName);
|
|
|
//var tops = enumValue.BSNO.Substring(0, 7);
|
|
|
//if (tops == "topseae")
|
|
|
// db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, true);
|
|
|
//else
|
|
|
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false);
|
|
|
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, enumValue.CH_ID);
|
|
|
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName);
|
|
|
if (curr == "")
|
|
|
{
|
|
|
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency);
|
|
|
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.DoAmount);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, curr);
|
|
|
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.DoAmount);
|
|
|
}
|
|
|
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
|
|
|
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType);
|
|
|
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 4);
|
|
|
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
|
|
|
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false);
|
|
|
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
|
|
|
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, enumValue.ExChangerate);
|
|
|
db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, enumValue.Currency);
|
|
|
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, enumValue.StlAmount);
|
|
|
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, duino);
|
|
|
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
|
|
|
|
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(duino))
|
|
|
{
|
|
|
var cmdUpdateDui =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"update ch_dui_detail set PAYNO=@PAYNO WHERE CH_ID=@GID AND DUINO=@DUINO");
|
|
|
cmdUpdateDui.Parameters.Clear();
|
|
|
db.AddInParameter(cmdUpdateDui, "@GID", DbType.String, enumValue.CH_ID);
|
|
|
db.AddInParameter(cmdUpdateDui, "@PAYNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmdUpdateDui, "@DUINO", DbType.String, duino);
|
|
|
db.ExecuteNonQuery(cmdUpdateDui, tran);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "保存成功" + result.Message;
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static DBResult AddBill(string billno,string duino, string billcust, string billcurr, string feesql, List<ChFeeExrate> exratelist, string companyid,string userid, bool custgroup = false)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
if (!custgroup)
|
|
|
feesql = feesql + " AND CUSTOMERNAME='" + billcust + "'";
|
|
|
var feelist = GetFeeDataList(feesql, duino, userid,userid,companyid,"");
|
|
|
|
|
|
|
|
|
var cmdInsert =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"insert into ch_fee_do (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
|
|
|
,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,ISDELETED,CREATETIME
|
|
|
,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO,COMPANYID)
|
|
|
values (@GID,@BILLNO,@BSNO,@MBLNO,@HBLNO,@CUSTOMERNAME,@BSTYPE,@FEEID,@FEENAME,@CURRENCY
|
|
|
,@AMOUNT,@DOAMOUNT,@FEETYPE,@CATEGORY,@BILLSTATUS,@ISDELETED,@CREATETIME
|
|
|
,@EXCHANGERATE,@ORIGCURRENCY,@ORIGAMOUNT,@INVOICESETTLENO,@COMPANYID) ");
|
|
|
|
|
|
var cmdUpdate =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"UPDATE CH_FEE SET ORDERAMOUNT=ISNULL(ORDERAMOUNT,0)+@ORDERAMOUNT WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT2)>=0)
|
|
|
OR (AMOUNT<0 AND ((AMOUNT-SETTLEMENT)-@ORDERAMOUNT3)<=0))");
|
|
|
|
|
|
|
|
|
|
|
|
if (feelist != null)
|
|
|
{
|
|
|
foreach (var enumValue in feelist)
|
|
|
{
|
|
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
|
|
|
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT", DbType.Decimal, enumValue.StlAmount);
|
|
|
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT2", DbType.Decimal, enumValue.StlAmount);
|
|
|
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT3", DbType.Decimal, enumValue.StlAmount);
|
|
|
var updatecount=db.ExecuteNonQuery(cmdUpdate, tran);
|
|
|
|
|
|
if (updatecount == 1)
|
|
|
{
|
|
|
cmdInsert.Parameters.Clear();
|
|
|
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
|
|
|
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, enumValue.BSNO);
|
|
|
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, "");
|
|
|
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, "");
|
|
|
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
|
|
|
//var tops = enumValue.BSNO.Substring(0, 7);
|
|
|
//if (tops == "topseae")
|
|
|
// db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, true);
|
|
|
//else
|
|
|
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false);
|
|
|
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, enumValue.CH_ID);
|
|
|
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName);
|
|
|
if (billcurr == null || billcurr == "")
|
|
|
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency);
|
|
|
else
|
|
|
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, billcurr);
|
|
|
|
|
|
if (billcurr == enumValue.Currency)
|
|
|
{
|
|
|
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount);
|
|
|
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
|
|
|
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
if (billcurr == "")
|
|
|
{
|
|
|
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount);
|
|
|
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
|
|
|
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var UExrate = GetExrate(enumValue.Currency, exratelist);
|
|
|
|
|
|
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.StlAmount * UExrate);
|
|
|
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
|
|
|
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, UExrate);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType);
|
|
|
db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, enumValue.Currency);
|
|
|
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, enumValue.StlAmount);
|
|
|
|
|
|
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 4);
|
|
|
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
|
|
|
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false);
|
|
|
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
|
|
|
|
|
|
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, duino);
|
|
|
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
|
|
|
|
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(duino)) {
|
|
|
var cmdUpdateDui =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"update ch_dui_detail set PAYNO=@PAYNO WHERE CH_ID=@GID AND DUINO=@DUINO");
|
|
|
cmdUpdateDui.Parameters.Clear();
|
|
|
db.AddInParameter(cmdUpdateDui, "@GID", DbType.String, enumValue.CH_ID);
|
|
|
db.AddInParameter(cmdUpdateDui, "@PAYNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmdUpdateDui, "@DUINO", DbType.String,duino);
|
|
|
db.ExecuteNonQuery(cmdUpdateDui, 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;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static Decimal GetExrate(string curr, List<ChFeeExrate> exratelist)
|
|
|
{
|
|
|
decimal exrate = 0;
|
|
|
if (exratelist != null)
|
|
|
{
|
|
|
foreach (var enumValue in exratelist)
|
|
|
{
|
|
|
if (enumValue.CURR == curr)
|
|
|
{
|
|
|
exrate = enumValue.EXRATE;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return exrate;
|
|
|
}
|
|
|
|
|
|
public static DBResult DelFeeDo(List<Chfee_do_detail> boday)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
if (boday != null)
|
|
|
{
|
|
|
|
|
|
|
|
|
var cmddelete = db.GetSqlStringCommand("delete from ch_fee_do where GID=@FEEDOID");
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee set ORDERAMOUNT=ORDERAMOUNT-@ORIGAMOUNT where GID=@GID");
|
|
|
|
|
|
var cmdupdatedui = db.GetSqlStringCommand("update ch_dui_detail set PAYNO='' where CH_ID=@GID AND PAYNO=@PAYNO AND DUINO=@DUINO");
|
|
|
|
|
|
foreach (var enumValue in boday)
|
|
|
{
|
|
|
cmddelete.Parameters.Clear();
|
|
|
db.AddInParameter(cmddelete, "@FEEDOID", DbType.String, enumValue.FEEDOID);
|
|
|
db.ExecuteNonQuery(cmddelete, tran);
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@ORIGAMOUNT", DbType.Decimal, enumValue.ORIGAMOUNT);
|
|
|
db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.FEEID);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
if (!string.IsNullOrEmpty(enumValue.INVOICESETTLENO)) {
|
|
|
cmdupdatedui.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdatedui, "@GID", DbType.String, enumValue.FEEID);
|
|
|
db.AddInParameter(cmdupdatedui, "@PAYNO", DbType.String, enumValue.BILLNO);
|
|
|
db.AddInParameter(cmdupdatedui, "@DUINO", DbType.String, enumValue.INVOICESETTLENO);
|
|
|
db.ExecuteNonQuery(cmdupdatedui, 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;
|
|
|
}
|
|
|
|
|
|
public static DBResult DoModify(ChPayapplication head,string custname,string taxrate)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
var CUSTNAME = custname;
|
|
|
decimal TAXRATE = Convert.ToDecimal(taxrate) /100;
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var boday = GetModifyBodyAllList("c.BILLNO='"+head.BILLNO+"'");
|
|
|
|
|
|
if (boday != null)
|
|
|
{
|
|
|
|
|
|
|
|
|
// var cmddelete = db.GetSqlStringCommand("delete from ch_fee_do where GID=@FEEDOID");
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee set CUSTOMERNAME=@CUSTOMERNAME,AMOUNT=@AMOUNT,TAXRATE=@TAXRATE,ORDERAMOUNT=ORDERAMOUNT+@ORDERAMOUNT,TAX=@TAX where GID=@GID");
|
|
|
var cmdupdatefeedo = db.GetSqlStringCommand("update ch_fee_do set CUSTOMERNAME=@CUSTOMERNAME,AMOUNT=@AMOUNT,ORIGAMOUNT=@ORIGAMOUNT where GID=@GID");
|
|
|
|
|
|
foreach (var enumValue in boday)
|
|
|
{
|
|
|
if (enumValue.AMOUNT == enumValue.ORIGAMOUNT)
|
|
|
{
|
|
|
var AMOUNT = Math.Round(enumValue.DOAMOUNT * (1 + TAXRATE), 2, MidpointRounding.AwayFromZero);
|
|
|
var ORDERPOOR = AMOUNT - enumValue.ORIGAMOUNT;
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@CUSTOMERNAME", DbType.String, CUSTNAME);
|
|
|
db.AddInParameter(cmdupdate, "@AMOUNT", DbType.Decimal, AMOUNT);
|
|
|
db.AddInParameter(cmdupdate, "@TAXRATE", DbType.Decimal, TAXRATE);
|
|
|
db.AddInParameter(cmdupdate, "@TAX", DbType.Decimal, AMOUNT- enumValue.DOAMOUNT);
|
|
|
db.AddInParameter(cmdupdate, "@ORDERAMOUNT", DbType.Decimal, ORDERPOOR);
|
|
|
db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.FEEID);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
cmdupdatefeedo.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdatefeedo, "@CUSTOMERNAME", DbType.String, CUSTNAME);
|
|
|
db.AddInParameter(cmdupdatefeedo, "@AMOUNT", DbType.Decimal, AMOUNT);
|
|
|
db.AddInParameter(cmdupdatefeedo, "@ORIGAMOUNT", DbType.Decimal, AMOUNT);
|
|
|
db.AddInParameter(cmdupdatefeedo, "@GID", DbType.String, enumValue.FEEDOID);
|
|
|
db.ExecuteNonQuery(cmdupdatefeedo, tran);
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
var AMOUNT = Math.Round(enumValue.DOAMOUNT * (1 + TAXRATE), 2, MidpointRounding.AwayFromZero);
|
|
|
var ORIGAMOUNT = Math.Round(enumValue.ORIGAMOUNT / (1 + enumValue.ORIGEXCHANGERATE) * (1 + TAXRATE), 2, MidpointRounding.AwayFromZero);
|
|
|
var ORDERPOOR = ORIGAMOUNT - enumValue.ORIGAMOUNT;
|
|
|
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@CUSTOMERNAME", DbType.String, CUSTNAME);
|
|
|
db.AddInParameter(cmdupdate, "@AMOUNT", DbType.Decimal, AMOUNT);
|
|
|
db.AddInParameter(cmdupdate, "@TAXRATE", DbType.Decimal, TAXRATE);
|
|
|
db.AddInParameter(cmdupdate, "@TAX", DbType.Decimal, AMOUNT - enumValue.DOAMOUNT);
|
|
|
db.AddInParameter(cmdupdate, "@ORDERAMOUNT", DbType.Decimal, ORDERPOOR);
|
|
|
db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.FEEID);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
cmdupdatefeedo.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdatefeedo, "@CUSTOMERNAME", DbType.String, CUSTNAME);
|
|
|
db.AddInParameter(cmdupdatefeedo, "@AMOUNT", DbType.Decimal, Math.Round(ORIGAMOUNT *enumValue.EXCHANGERATE,2, MidpointRounding.AwayFromZero));
|
|
|
db.AddInParameter(cmdupdatefeedo, "@ORIGAMOUNT", DbType.Decimal, ORIGAMOUNT);
|
|
|
db.AddInParameter(cmdupdatefeedo, "@GID", DbType.String, enumValue.FEEDOID);
|
|
|
db.ExecuteNonQuery(cmdupdatefeedo, tran);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
var cmdupdatebs = db.GetSqlStringCommand("update op_truck_bulk_pc set TRUCKER=@CUSTOMERNAME where BSNO IN (SELECT BSNO FROM CH_FEE_DO WHERE BILLNO='"+head.BILLNO+"') ");
|
|
|
var cmdupdatepay = db.GetSqlStringCommand("update ch_fee_payapplication set CUSTOMERNAME=@CUSTOMERNAME WHERE BILLNO='" + head.BILLNO + "' ");
|
|
|
cmdupdatebs.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdatebs, "@CUSTOMERNAME", DbType.String, CUSTNAME);
|
|
|
db.ExecuteNonQuery(cmdupdatebs, tran);
|
|
|
cmdupdatepay.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdatepay, "@CUSTOMERNAME", DbType.String, CUSTNAME);
|
|
|
db.ExecuteNonQuery(cmdupdatepay, 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;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static int p_update_Amount(string billno)
|
|
|
{
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
var cmd = db.GetStoredProcCommand("p_update_payapplycation");
|
|
|
db.AddInParameter(cmd, "@con_no", DbType.String, billno);
|
|
|
db.ExecuteNonQuery(cmd);
|
|
|
|
|
|
var _r = Set_BS_CUSTOMERNAME(billno);
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static DBResult Set_BS_CUSTOMERNAME ( string billno )
|
|
|
{
|
|
|
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_payapplication set BS_CUSTOMERNAME=(select dbo.F_chfeedo_Client(@BILLNO)) where billno=@BILLNO2 ");
|
|
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdUpdate, "@BILLNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmdUpdate, "@BILLNO2", DbType.String, billno);
|
|
|
db.ExecuteNonQuery(cmdUpdate, tran);
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "保存成功" + result.Message;
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 提交审核和撤销审核
|
|
|
|
|
|
public static DBResult SubmitAudit(String WorkFlowName, String USERID, String bill,string companyid)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var WorkFlowid = "";
|
|
|
if (WorkFlowid == "")
|
|
|
{
|
|
|
string lsSQL = "select * FROM workflow WHERE COMPANYID='" + companyid + "' AND ISCONDITION=1 and [TYPE]=(SELECT TYPENO FROM workflow_type WHERE [NAME]='" + WorkFlowName + "') "
|
|
|
+ " and GID in (select workflowID from workflow_Userpath where userid ='" + USERID + "') order by SORTNO ";
|
|
|
DataSet dsworkflow = T_ALL_DA.GetAllSQL(lsSQL);
|
|
|
if (dsworkflow != null)
|
|
|
{
|
|
|
if (dsworkflow.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
foreach (DataRow row in dsworkflow.Tables[0].Rows)
|
|
|
{
|
|
|
var CONDITIONSQL = Convert.ToString(row["CONDITIONSQL"]);
|
|
|
CONDITIONSQL = CONDITIONSQL.Replace("[业务编号]", "'" + bill + "'");
|
|
|
var strCOUNT = T_ALL_DA.GetStrSQL("BLCT", CONDITIONSQL);
|
|
|
if (strCOUNT != "0")
|
|
|
{
|
|
|
WorkFlowid = Convert.ToString(row["GID"]);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (WorkFlowid == "") WorkFlowid = "no";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, bill, USERID,bill, bill,"", WorkFlowid);
|
|
|
|
|
|
|
|
|
|
|
|
if (WorkResult.Success == true)
|
|
|
{
|
|
|
var cmdupdate = db.GetSqlStringCommand("BILLNO=@BILLNO");
|
|
|
if (WorkResult.islast == true)
|
|
|
{
|
|
|
result.Message2 = "1";
|
|
|
cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=0,AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BILLNO=@BILLNO");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=2 where BILLNO=@BILLNO");
|
|
|
}
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "提交审核成功";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "提交审核错误!";
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "提交审核错误,请重试或联系系统管理员 "+e.Message;
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
//发送微信推送
|
|
|
#region 发送微信推送
|
|
|
//发送微信推送
|
|
|
string sqltype = "SELECT NAME from workflow WHERE GID= (select WORKFLOWID from workflow_using where bsno = '" + bill + "')";
|
|
|
Database db2 = DatabaseFactory.CreateDatabase();
|
|
|
var typeobj = db2.ExecuteScalar(CommandType.Text, sqltype);
|
|
|
if (typeobj != null && typeobj != DBNull.Value && typeobj.ToString() != "")
|
|
|
{
|
|
|
string typename = typeobj.ToString();
|
|
|
if (typename == "付费审核" || typename == "全部付费用审核")
|
|
|
{
|
|
|
TemplateMessageDAL.Send(0, bill);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static DBResult SubmitAuditList(String WorkFlowName, String USERID, String bills,string companyid)
|
|
|
{
|
|
|
|
|
|
var FEECLOSEPAYAUTOAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='FEECLOSEPAYAUTOAUDIT'");
|
|
|
|
|
|
|
|
|
var result = new DBResult();
|
|
|
var billList = bills.Split(',');
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
foreach (var bill in billList)
|
|
|
{
|
|
|
|
|
|
var isclose = false;
|
|
|
if (FEECLOSEPAYAUTOAUDIT.PARAMVALUE == "1")
|
|
|
{
|
|
|
|
|
|
var dataList = ChpayapplicationDAL.GetBodyAllList("BILLNO='" + bill + "'");
|
|
|
if (dataList != null)
|
|
|
{
|
|
|
|
|
|
foreach (var enumValue in dataList)
|
|
|
{
|
|
|
if (enumValue.FEESTATUSREF != "锁定") isclose = false;
|
|
|
}
|
|
|
if (isclose)
|
|
|
{
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=0,AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BILLNO=@BILLNO");
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!isclose)
|
|
|
{
|
|
|
|
|
|
var WorkFlowid = "";
|
|
|
if (WorkFlowid == "")
|
|
|
{
|
|
|
string lsSQL = "select * FROM workflow WHERE COMPANYID='" + companyid + "' AND ISCONDITION=1 and [TYPE]=(SELECT TYPENO FROM workflow_type WHERE [NAME]='" + WorkFlowName + "') "
|
|
|
+ " and GID in (select workflowID from workflow_Userpath where userid ='" + USERID + "') order by SORTNO ";
|
|
|
DataSet dsworkflow = T_ALL_DA.GetAllSQL(lsSQL);
|
|
|
if (dsworkflow != null)
|
|
|
{
|
|
|
if (dsworkflow.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
foreach (DataRow row in dsworkflow.Tables[0].Rows)
|
|
|
{
|
|
|
var CONDITIONSQL = Convert.ToString(row["CONDITIONSQL"]);
|
|
|
CONDITIONSQL = CONDITIONSQL.Replace("[业务编号]", "'" + bill + "'");
|
|
|
var strCOUNT = T_ALL_DA.GetStrSQL("BLCT", CONDITIONSQL);
|
|
|
if (strCOUNT != "0")
|
|
|
{
|
|
|
WorkFlowid = Convert.ToString(row["GID"]);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (WorkFlowid == "") WorkFlowid = "no";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, bill, USERID, bill, bill, "", WorkFlowid);
|
|
|
|
|
|
if (WorkResult.Success == true)
|
|
|
{
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("BILLNO=@BILLNO");
|
|
|
if (WorkResult.islast == true)
|
|
|
{
|
|
|
cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=0,AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BILLNO=@BILLNO");
|
|
|
result.Message2 = "1";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=2 where BILLNO=@BILLNO");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "提交审核成功";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "提交审核错误!";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "提交审核错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static DBResult SubmitAuditBack(string WorkFlowName, String USERID, String bill)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, bill, USERID);
|
|
|
if (WorkResult.Success == true)
|
|
|
{
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=1 where BILLNO=@BILLNO");
|
|
|
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
result = new DBResult();
|
|
|
result.Success = true;
|
|
|
result.Message = "撤销提交成功";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result = new DBResult();
|
|
|
result.Success = false;
|
|
|
result.Message = "已部分审核此业务,不允许撤回提交!";
|
|
|
}
|
|
|
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "撤销提交错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static DBResult SelBsLock(List<BSNOLB> billData, string type)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var i = 0;
|
|
|
var j = 0;
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
foreach (var enumValue in billData)
|
|
|
{
|
|
|
if (type == "ETD")
|
|
|
{
|
|
|
var cmdUpdate = db.GetSqlStringCommand(
|
|
|
@"if (select bsno from op_close where bsno='" + enumValue.BSNO + "') is null insert into op_close values(newid(),'" + enumValue.BSNO + "',null,null,null,null,1"
|
|
|
+ ",null,null) else update op_close set ETDCLOSE=1"
|
|
|
+ " where BSNO='" + enumValue.BSNO + "' ");
|
|
|
|
|
|
db.ExecuteNonQuery(cmdUpdate, tran);
|
|
|
}
|
|
|
else if (type == "应收")
|
|
|
{
|
|
|
//var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEETYPE=1 AND FEESTATUS NOT IN (0,8,9) and BSNO='" + enumValue.BSNO + "'");
|
|
|
//var IntFeeCount = Convert.ToInt16(FeeCount);
|
|
|
//if (IntFeeCount == 0)
|
|
|
//{
|
|
|
var cmdUpdate = db.GetSqlStringCommand(
|
|
|
@"if (select bsno from op_close where bsno='" + enumValue.BSNO + "') is null insert into op_close values(newid(),'" + enumValue.BSNO + "',null,null,null,null,null"
|
|
|
+ ",1,null) else update op_close set DRCLOSE=1"
|
|
|
+ " where BSNO='" + enumValue.BSNO + "' ");
|
|
|
|
|
|
db.ExecuteNonQuery(cmdUpdate, tran);
|
|
|
//}
|
|
|
}
|
|
|
else if (type == "应付")
|
|
|
{
|
|
|
//var FeeCount = db.ExecuteScalar(CommandType.Text, "SELECT COUNT(GID) as FeeCount from ch_fee where FEETYPE=2 AND FEESTATUS NOT IN (0,8,9) and BSNO='" + enumValue.BSNO + "'");
|
|
|
//var IntFeeCount = Convert.ToInt16(FeeCount);
|
|
|
//if (IntFeeCount == 0)
|
|
|
//{
|
|
|
var cmdUpdate = db.GetSqlStringCommand(
|
|
|
@"if (select bsno from op_close where bsno='" + enumValue.BSNO + "') is null insert into op_close values(newid(),'" + enumValue.BSNO + "',null,null,null,null,null"
|
|
|
+ ",null,1) else update op_close set CRCLOSE=1"
|
|
|
+ " where BSNO='" + enumValue.BSNO + "' ");
|
|
|
|
|
|
db.ExecuteNonQuery(cmdUpdate, tran);
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
result.Success = true;
|
|
|
result.Message = "锁定成功";
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
result.Success =false;
|
|
|
result.Message = "锁定出错"+e.Message;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static DBResult SubmitAuditBackList(String WorkFlowName, String USERID, String bills,string usercode,string companyid)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
var billList = bills.Split(',');
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
foreach (var bill in billList)
|
|
|
{
|
|
|
var headdata = ChpayapplicationDAL.GetData(" BILLNO='" + bill + "'", USERID, usercode,companyid);
|
|
|
if (headdata.BILLSTATUS == 2)
|
|
|
{
|
|
|
|
|
|
Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, bill, USERID);
|
|
|
if (WorkResult.Success == true)
|
|
|
{
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=1 where BILLNO=@BILLNO");
|
|
|
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
result = new DBResult();
|
|
|
result.Success = true;
|
|
|
result.Message = "撤销提交成功";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result = new DBResult();
|
|
|
result.Success = false;
|
|
|
result.Message = "已部分审核此业务,不允许撤回提交!";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "撤销提交错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static DBResult UpdateApp(String bills,string type)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
var billList = bills.Split(',');
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
foreach (var bill in billList)
|
|
|
{
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set ISAPP="+type+" where BILLNO=@BILLNO");
|
|
|
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
public static DBResult UpdateISREVINV(String bills, string type)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
var billList = bills.Split(',');
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
foreach (var bill in billList)
|
|
|
{
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set ISREVINV=" + type + " where BILLNO=@BILLNO");
|
|
|
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, bill);
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 审核或驳回
|
|
|
|
|
|
public static DBResult AuditList(List<ChPayapplication> boday, String USERID)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var errmsg = "";
|
|
|
var errnotmsg = "";
|
|
|
|
|
|
if (boday != null)
|
|
|
{
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set STLCURR=@STLCURR,STLRATE=@STLRATE,STLAMOUNT=@STLAMOUNT,BILLSTATUS=0,AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BILLNO=@BILLNO");
|
|
|
var cmdupdate2 = db.GetSqlStringCommand("update ch_fee_payapplication set STLCURR=@STLCURR,STLRATE=@STLRATE,STLAMOUNT=@STLAMOUNT,AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BILLNO=@BILLNO");
|
|
|
var cmdupdatefee = db.GetSqlStringCommand("update ch_fee set FEESTATUS=0,AUDITOPERATOR='" + USERID + "',AUDITDATE=GETDATE() where (FEESTATUS=1 or FEESTATUS=2) and GID IN (SELECT FEEID FROM CH_FEE_DO WHERE BILLNO=@BILLNO) ");
|
|
|
|
|
|
foreach (var enumValue in boday)
|
|
|
{
|
|
|
|
|
|
var feedolist = GetBodyAllList("BILLNO='"+enumValue.BILLNO+ "' AND ((CASE WHEN F.AMOUNT>0 THEN (F.AMOUNT-F.SETTLEMENT)-C.ORIGAMOUNT END)<0 OR(CASE WHEN F.AMOUNT < 0 THEN(F.AMOUNT - F.SETTLEMENT) - C.ORIGAMOUNT END) > 0)");
|
|
|
if (feedolist.Count > 0)
|
|
|
{
|
|
|
errnotmsg = errnotmsg + "单号:" + enumValue.BILLNO + ",";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
var feecount = GetRdCount(" FEESTATUS NOT IN (0,8,9) AND GID IN (SELECT FEEID FROM CH_FEE_DO WHERE BILLNO='" + enumValue.BILLNO + "')");
|
|
|
var PAYAUDITAUDITFEE = MsSysParamSetDAL.GetData("PARAMNAME='PAYAUDITAUDITFEE'");
|
|
|
if (feecount == 0 || PAYAUDITAUDITFEE.PARAMVALUE == "1")
|
|
|
{
|
|
|
if (enumValue.BILLSTATUS == 2 || enumValue.BILLSTATUS == 6)
|
|
|
{
|
|
|
//Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo("FeeSettleAudit", enumValue.BILLNO, USERID, enumValue.BILLNO, enumValue.BILLNO, "审核通过URL");
|
|
|
Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo("FeeSettleAudit", enumValue.BILLNO, USERID, tran, enumValue.BILLNO);
|
|
|
if (WorkResult.Success == true)
|
|
|
{
|
|
|
if (WorkResult.islast == true)
|
|
|
{
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@STLCURR", DbType.String, enumValue.STLCURR);
|
|
|
db.AddInParameter(cmdupdate, "@STLRATE", DbType.Decimal, enumValue.STLRATE);
|
|
|
db.AddInParameter(cmdupdate, "@STLAMOUNT", DbType.Decimal, enumValue.STLAMOUNT);
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
if (feecount != 0 && PAYAUDITAUDITFEE.PARAMVALUE == "1")
|
|
|
{
|
|
|
cmdupdatefee.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdatefee, "@BILLNO", DbType.String, enumValue.BILLNO);
|
|
|
db.ExecuteNonQuery(cmdupdatefee, tran);
|
|
|
}
|
|
|
result.Message2 = "1";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
cmdupdate2.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate2, "@STLCURR", DbType.String, enumValue.STLCURR);
|
|
|
db.AddInParameter(cmdupdate2, "@STLRATE", DbType.Decimal, enumValue.STLRATE);
|
|
|
db.AddInParameter(cmdupdate2, "@STLAMOUNT", DbType.Decimal, enumValue.STLAMOUNT);
|
|
|
db.AddInParameter(cmdupdate2, "@BILLNO", DbType.String, enumValue.BILLNO);
|
|
|
db.ExecuteNonQuery(cmdupdate2, tran);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
errmsg = errmsg + "单号:" + enumValue.BILLNO + ",";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (errmsg != "") errmsg = ",但其中(" + errmsg + ")存在未审核费用明细,未审核通过,请先审核费用!";
|
|
|
if (errnotmsg != "") errnotmsg = ",但其中(" + errnotmsg + ")存在申请申请金额和未结金额不一致,不能审核通过!";
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "审核通过"+errmsg+ errnotmsg;
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "审核出现错误,请重试或联系系统管理员"+e.Message;
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//发送微信推送
|
|
|
#region 发送微信推送
|
|
|
//发送微信推送
|
|
|
if (boday.Count>0)
|
|
|
{
|
|
|
string sqltype = "SELECT NAME from workflow WHERE GID= (select WORKFLOWID from workflow_using where bsno = '"+boday[0].BILLNO+"')";
|
|
|
var typeobj = db.ExecuteScalar(CommandType.Text, sqltype);
|
|
|
if (typeobj != null && typeobj != DBNull.Value && typeobj.ToString() != "")
|
|
|
{
|
|
|
string typename = typeobj.ToString();
|
|
|
if (typename == "付费审核")
|
|
|
{
|
|
|
TemplateMessageDAL.Send(0, boday[0].BILLNO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static DBResult AuditBackList(List<ChPayapplication> boday, String USERID,string reason)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
if (boday != null)
|
|
|
{
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee_payapplication set BILLSTATUS=6,AUDITUSER='',AUDITTIME=null,ISPRINT='0',REASON='" + reason+"' where BILLNO=@BILLNO");
|
|
|
|
|
|
foreach (var enumValue in boday)
|
|
|
{
|
|
|
if (enumValue.BILLSTATUS == 2 || enumValue.BILLSTATUS == 0)
|
|
|
{
|
|
|
Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo("FeeSettleAudit", enumValue.BILLNO, USERID, reason, enumValue.BILLNO, enumValue.BILLNO, "驳回提交URL");
|
|
|
if (WorkResult.Success == true)
|
|
|
{
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@BILLNO", DbType.String, enumValue.BILLNO);
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 申请入帐
|
|
|
static public List<ChBalapplication> GetBalList(string billno)
|
|
|
{
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" SELECT [GID],cm.BILLNO,[BILLSTATUS],[CUSTOMERNAME],[AMOUNTRMB],[RATE],[AMOUNTUSD],[APPLICANT] ");
|
|
|
strSql.Append(",[APPLYTIME],[ENTERTIME],[AUDITUSER],[AUDITTIME],[REMARK],[ISDELETE] ,[DELETEUSER]");
|
|
|
strSql.Append(",[DELETETIME],[COMPANYID] ,[CURR],");
|
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97005 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=cm.AUDITUSER) as AUDITUSERREF");
|
|
|
strSql.Append(",f.RMBSTLAMOUNT ");
|
|
|
strSql.Append(",f.USDSTLAMOUNT ");
|
|
|
strSql.Append(" FROM v_fee_do_invoicehexiao f left join ch_fee_balapplication cm on (cm.BILLNO=f.BALBILLNO) where f.BILLNO='" + billno + "'");
|
|
|
|
|
|
return SetBalData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<ChBalapplication> SetBalData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<ChBalapplication>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ChBalapplication data = new ChBalapplication();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.BILLNO = Convert.ToString(reader["BILLNO"]);
|
|
|
data.BILLSTATUS = Convert.ToInt32(reader["BILLSTATUS"]);
|
|
|
data.BILLSTATUSREF = Convert.ToString(reader["BILLSTATUSREF"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
|
|
|
if (reader["AMOUNTRMB"] != DBNull.Value)
|
|
|
data.AMOUNTRMB = Convert.ToDecimal(reader["AMOUNTRMB"]);
|
|
|
if (reader["AMOUNTUSD"] != DBNull.Value)
|
|
|
data.AMOUNTUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
|
|
|
|
|
|
if (reader["RMBSTLAMOUNT"] != DBNull.Value)
|
|
|
data.BALAMOUNTRMB = Convert.ToDecimal(reader["RMBSTLAMOUNT"]);
|
|
|
if (reader["USDSTLAMOUNT"] != DBNull.Value)
|
|
|
data.BALAMOUNTUSD = Convert.ToDecimal(reader["USDSTLAMOUNT"]);
|
|
|
|
|
|
data.STLAMOUNTRMB = data.BALAMOUNTRMB;
|
|
|
data.STLAMOUNTUSD = data.BALAMOUNTUSD;
|
|
|
|
|
|
data.APPLICANT = Convert.ToString(reader["APPLICANT"]);
|
|
|
data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]);
|
|
|
if (reader["APPLYTIME"] != DBNull.Value)
|
|
|
data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]).ToString("yyyy-MM-dd");
|
|
|
if (reader["ENTERTIME"] != DBNull.Value)
|
|
|
data.ENTERTIME = Convert.ToDateTime(reader["ENTERTIME"]);
|
|
|
|
|
|
data.REMARK = Convert.ToString(reader["REMARK"]);
|
|
|
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
static public List<ChBalapplication> GetBalAddList(string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null)
|
|
|
{
|
|
|
var rangstr = GetRangDAListStr("", userid, usercode, orgcode);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strCondition = rangstr;
|
|
|
}
|
|
|
}
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select * from (SELECT cm.GID,cm.BILLNO,cm.BILLSTATUS,cm.CUSTOMERNAME,cm.AMOUNTRMB,cm.RATE,cm.AMOUNTUSD,cm.APPLICANT ");
|
|
|
strSql.Append(",cm.APPLYTIME,cm.ENTERTIME,cm.AUDITUSER,cm.AUDITTIME,cm.REMARK");
|
|
|
strSql.Append(",cm.COMPANYID ,cm.CURR,");
|
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97005 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=cm.AUDITUSER) as AUDITUSERREF");
|
|
|
strSql.Append(",sum(CASE WHEN b.CURRENCY='RMB' THEN CASE WHEN b.FEETYPE=1 then -b.balamount else b.balamount end ELSE 0 END) as RMBSTLAMOUNT ");
|
|
|
strSql.Append(",sum(CASE WHEN b.CURRENCY='RMB' THEN CASE WHEN b.FEETYPE=1 then -b.ORIGAMOUNT else b.ORIGAMOUNT end ELSE 0 END) as RMBORIGAMOUNT ");
|
|
|
strSql.Append(",sum(CASE WHEN b.CURRENCY!='RMB' THEN CASE WHEN b.FEETYPE=1 then -b.balamount else b.balamount end ELSE 0 END) as USDSTLAMOUNT ");
|
|
|
strSql.Append(",sum(CASE WHEN b.CURRENCY!='RMB' THEN CASE WHEN b.FEETYPE=1 then -b.ORIGAMOUNT else b.ORIGAMOUNT end ELSE 0 END) as USDORIGAMOUNT ");
|
|
|
strSql.Append(" FROM ch_fee_balapplication cm left join v_BalStlSum b on (b.BALBILLNO=cm.BILLNO) where 1=1 ");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
strSql.Append(" GROUP BY cm.GID,cm.BILLNO,cm.BILLSTATUS,cm.CUSTOMERNAME,cm.AMOUNTRMB,cm.RATE,cm.AMOUNTUSD,cm.APPLICANT ");
|
|
|
strSql.Append(",cm.APPLYTIME,cm.ENTERTIME,cm.AUDITUSER,cm.AUDITTIME,cm.REMARK");
|
|
|
strSql.Append(",cm.COMPANYID ,cm.CURR ");
|
|
|
|
|
|
|
|
|
strSql.Append(" ) as tt where RMBSTLAMOUNT!=0 or USDSTLAMOUNT!=0 ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by APPLYTIME DESC");
|
|
|
|
|
|
}
|
|
|
return SetBalData(strSql);
|
|
|
}
|
|
|
|
|
|
static public List<ChFeeDetail> GetBalFeeDetailList(string strCondition)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append("f.BSNO,f.GID AS CH_ID,f.FeeType,d.GID FEEDOID,d.MBLNO,d.HBLNO");
|
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
|
|
|
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,d.ORIGAMOUNT,f.currency,f.exChangerate,f.invoice");
|
|
|
strSql.Append(" from ch_fee_do_invoice d left join ch_fee f on (f.GID=d.FEEID) where (f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
|
|
|
return SetBalFeeDetailData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<ChFeeDetail> SetBalFeeDetailData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<ChFeeDetail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ChFeeDetail data = new ChFeeDetail();
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.CH_ID = Convert.ToString(reader["FEEDOID"]);
|
|
|
data.FEEID = Convert.ToString(reader["CH_ID"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.HBLNO = Convert.ToString(reader["HBLNO"]);
|
|
|
data.FeeType = Convert.ToInt16(reader["FeeType"]);
|
|
|
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
|
|
|
data.FeeName = Convert.ToString(reader["feeName"]);
|
|
|
data.CustomerName = Convert.ToString(reader["customerName"]);
|
|
|
data.Amount = Convert.ToDecimal(reader["Amount"]);
|
|
|
if (reader["ORIGAMOUNT"] != DBNull.Value)
|
|
|
data.StlAmount = Convert.ToDecimal(reader["ORIGAMOUNT"]);
|
|
|
if (reader["BalAmount"] != DBNull.Value)
|
|
|
{
|
|
|
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
|
|
|
}
|
|
|
else data.BalAmount = data.Amount;
|
|
|
|
|
|
|
|
|
data.StlAmount = data.BalAmount;
|
|
|
|
|
|
|
|
|
|
|
|
data.Currency = Convert.ToString(reader["Currency"]);
|
|
|
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
|
|
|
if (reader["invoice"] != DBNull.Value)
|
|
|
data.Invoice = Convert.ToDecimal(reader["invoice"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
static public List<ChFeeDetail> GetBalFeeDetailList(string strCondition, Database db, DbTransaction tran)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT d.BILLNO,");
|
|
|
strSql.Append("f.BSNO,f.GID AS CH_ID,f.FeeType,d.GID FEEDOID,d.MBLNO,d.HBLNO");
|
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
|
|
|
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0) as balamount,d.ORIGAMOUNT,f.currency,f.exChangerate,f.invoice");
|
|
|
strSql.Append(" from ch_fee_do_invoice d left join ch_fee f on (f.GID=d.FEEID) where (f.amount-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
|
|
|
return SetBalFeeDetailData(strSql,db,tran);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<ChFeeDetail> SetBalFeeDetailData(StringBuilder strSql, Database db, DbTransaction tran)
|
|
|
{
|
|
|
var headList = new List<ChFeeDetail>();
|
|
|
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ChFeeDetail data = new ChFeeDetail();
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.CH_ID = Convert.ToString(reader["FEEDOID"]);
|
|
|
data.FEEID = Convert.ToString(reader["CH_ID"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.HBLNO = Convert.ToString(reader["HBLNO"]);
|
|
|
data.BILLNO = Convert.ToString(reader["BILLNO"]);
|
|
|
data.FeeType = Convert.ToInt16(reader["FeeType"]);
|
|
|
data.FeeType_Ref = Convert.ToString(reader["FeeType_Ref"]);
|
|
|
data.FeeName = Convert.ToString(reader["feeName"]);
|
|
|
data.CustomerName = Convert.ToString(reader["customerName"]);
|
|
|
data.Amount = Convert.ToDecimal(reader["Amount"]);
|
|
|
if (reader["ORIGAMOUNT"] != DBNull.Value)
|
|
|
data.StlAmount = Convert.ToDecimal(reader["ORIGAMOUNT"]);
|
|
|
if (reader["BalAmount"] != DBNull.Value)
|
|
|
{
|
|
|
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
|
|
|
}
|
|
|
else data.BalAmount = data.Amount;
|
|
|
|
|
|
|
|
|
data.StlAmount = data.BalAmount;
|
|
|
data.Currency = Convert.ToString(reader["Currency"]);
|
|
|
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
|
|
|
if (reader["invoice"] != DBNull.Value)
|
|
|
data.Invoice = Convert.ToDecimal(reader["invoice"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static DBResult AddBalDetail(string billno, List<ChBalapplication> bodyList, string companyid)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
var cmdInsert =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"insert into ch_fee_do (GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY
|
|
|
,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,ISDELETED,CREATETIME
|
|
|
,EXCHANGERATE,ORIGCURRENCY,ORIGAMOUNT,INVOICESETTLENO,COMPANYID)
|
|
|
values (@GID,@BILLNO,@BSNO,@MBLNO,@HBLNO,@CUSTOMERNAME,@BSTYPE,@FEEID,@FEENAME,@CURRENCY
|
|
|
,@AMOUNT,@DOAMOUNT,@FEETYPE,@CATEGORY,@BILLSTATUS,@ISDELETED,@CREATETIME
|
|
|
,@EXCHANGERATE,@ORIGCURRENCY,@ORIGAMOUNT,@INVOICESETTLENO,@COMPANYID) ");
|
|
|
|
|
|
|
|
|
var cmdUpdate =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"UPDATE CH_FEE SET ORDERAMOUNT=ISNULL(ORDERAMOUNT,0)+@ORDERAMOUNT WHERE GID=@GID ");
|
|
|
|
|
|
|
|
|
var cmdInsertAppSettl =
|
|
|
db.GetSqlStringCommand(
|
|
|
@"insert into ch_fee_do_payapplication (GID,BILLNO,PAYBILLNO,PAY_FEEDOID,FEEDOID,CREATETIME,PAYDOAMOUNT)
|
|
|
values (@GID,@BILLNO,@PAYBILLNO,@PAY_FEEDOID,@FEEDOID,@CREATETIME,@PAYDOAMOUNT) ");
|
|
|
|
|
|
var cmd = db.GetStoredProcCommand("p_update_payapplycation");
|
|
|
|
|
|
|
|
|
if (bodyList != null)
|
|
|
{
|
|
|
foreach (var enumValue in bodyList)
|
|
|
{
|
|
|
|
|
|
List<ChFeeDetail> feedolist = GetBalFeeDetailList(" d.BILLNO in (select BILLNO FROM ch_fee_invoicehexiao WHERE BALBILLNO='" + enumValue.BILLNO + "') ", db, tran);
|
|
|
|
|
|
var stlamountrmb = enumValue.STLAMOUNTRMB;
|
|
|
var stlamountusd = enumValue.STLAMOUNTUSD;
|
|
|
|
|
|
if (feedolist != null)
|
|
|
{
|
|
|
|
|
|
foreach (var feedovalue in feedolist)
|
|
|
{
|
|
|
|
|
|
decimal balamount = 0;
|
|
|
if ((stlamountrmb != 0 || stlamountusd != 0)&&feedovalue.BalAmount!=0)
|
|
|
{
|
|
|
|
|
|
if (feedovalue.Currency == "RMB")
|
|
|
{
|
|
|
|
|
|
if (feedovalue.BalAmount <= stlamountrmb)
|
|
|
{
|
|
|
balamount = feedovalue.BalAmount;
|
|
|
}
|
|
|
else {
|
|
|
balamount = stlamountrmb;
|
|
|
|
|
|
}
|
|
|
stlamountrmb = stlamountrmb - balamount;
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
if (feedovalue.BalAmount <= stlamountusd)
|
|
|
{
|
|
|
balamount = feedovalue.BalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
balamount = stlamountusd;
|
|
|
|
|
|
}
|
|
|
stlamountusd = stlamountusd - balamount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
var feedoid = Guid.NewGuid().ToString();
|
|
|
cmdInsert.Parameters.Clear();
|
|
|
db.AddInParameter(cmdInsert, "@GID", DbType.String, feedoid);
|
|
|
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, feedovalue.BSNO);
|
|
|
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String,"");
|
|
|
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, "");
|
|
|
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, feedovalue.CustomerName);
|
|
|
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, true);
|
|
|
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, feedovalue.FEEID);
|
|
|
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, feedovalue.FeeName);
|
|
|
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, feedovalue.Currency);
|
|
|
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, balamount);
|
|
|
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
|
|
|
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, feedovalue.FeeType);
|
|
|
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 4);
|
|
|
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
|
|
|
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false);
|
|
|
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
|
|
|
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1);
|
|
|
db.AddInParameter(cmdInsert, "@ORIGCURRENCY", DbType.String, feedovalue.Currency);
|
|
|
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, balamount);
|
|
|
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, "");
|
|
|
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
|
|
|
|
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdUpdate, "@GID", DbType.String, feedovalue.FEEID);
|
|
|
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT", DbType.Decimal,balamount);
|
|
|
db.ExecuteNonQuery(cmdUpdate, tran);
|
|
|
|
|
|
cmdInsertAppSettl.Parameters.Clear();
|
|
|
db.AddInParameter(cmdInsertAppSettl, "@GID", DbType.String, Guid.NewGuid().ToString());
|
|
|
db.AddInParameter(cmdInsertAppSettl, "@BILLNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmdInsertAppSettl, "@PAYBILLNO", DbType.String, feedovalue.BILLNO);
|
|
|
db.AddInParameter(cmdInsertAppSettl, "@PAY_FEEDOID", DbType.String, feedovalue.CH_ID);
|
|
|
db.AddInParameter(cmdInsertAppSettl, "@FEEDOID", DbType.String, feedoid);
|
|
|
db.AddInParameter(cmdInsertAppSettl, "@CREATETIME", DbType.DateTime, DateTime.Now);
|
|
|
db.AddInParameter(cmdInsertAppSettl, "@PAYDOAMOUNT", DbType.Decimal, balamount);
|
|
|
db.ExecuteNonQuery(cmdInsertAppSettl, tran);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
cmd.Parameters.Clear();
|
|
|
db.AddInParameter(cmd, "@con_no", DbType.String, billno);
|
|
|
db.ExecuteNonQuery(cmd, tran);
|
|
|
|
|
|
|
|
|
tran.Commit();
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "保存成功" + result.Message;
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "保存成功" + result.Message;
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static DBResult DelBalApp(List<ChBalapplication> boday, string billno)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
if (boday != null)
|
|
|
{
|
|
|
|
|
|
|
|
|
var cmddelete = db.GetSqlStringCommand("delete from ch_fee_do where GID=@FEEDOID");
|
|
|
|
|
|
var cmdupdate = db.GetSqlStringCommand("update ch_fee set ORDERAMOUNT=ORDERAMOUNT-@ORIGAMOUNT where GID=@GID");
|
|
|
|
|
|
var cmddeleteappfeedo = db.GetSqlStringCommand("delete from ch_fee_do_payapplication where BILLNO IN (SELECT BILLNO FROM ch_fee_invoicehexiao WHERE BALBILLNO=@BILLNO) AND PAY_FEEDOID=@PAYFEEDOID AND FEEDOID=@FEEDOID");
|
|
|
|
|
|
var cmd = db.GetStoredProcCommand("p_update_payapplycation");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var enumValue in boday)
|
|
|
{
|
|
|
|
|
|
List<Chfee_do_detail> feedolist = GetPayBodyList(" p.BILLNO='" + billno + "' and p.PAYBILLNO BILLNO IN (SELECT BILLNO FROM ch_fee_invoicehexiao WHERE BALBILLNO='" + enumValue.BILLNO + "')", db, tran);
|
|
|
|
|
|
|
|
|
if (feedolist != null)
|
|
|
{
|
|
|
|
|
|
foreach (var feedovalue in feedolist)
|
|
|
{
|
|
|
|
|
|
cmddelete.Parameters.Clear();
|
|
|
db.AddInParameter(cmddelete, "@FEEDOID", DbType.String, feedovalue.FEEDOID);
|
|
|
db.ExecuteNonQuery(cmddelete, tran);
|
|
|
|
|
|
cmdupdate.Parameters.Clear();
|
|
|
db.AddInParameter(cmdupdate, "@ORIGAMOUNT", DbType.Decimal, feedovalue.ORIGAMOUNT);
|
|
|
db.AddInParameter(cmdupdate, "@GID", DbType.String, feedovalue.FEEID);
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
cmddeleteappfeedo.Parameters.Clear();
|
|
|
db.AddInParameter(cmddeleteappfeedo, "@BILLNO", DbType.String, billno);
|
|
|
db.AddInParameter(cmddeleteappfeedo, "@PAYFEEDOID", DbType.String, feedovalue.PAYFEEDOID);
|
|
|
db.AddInParameter(cmddeleteappfeedo, "@FEEDOID", DbType.String, feedovalue.FEEDOID);
|
|
|
db.ExecuteNonQuery(cmddeleteappfeedo, tran);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
cmd.Parameters.Clear();
|
|
|
db.AddInParameter(cmd, "@con_no", DbType.String, billno);
|
|
|
db.ExecuteNonQuery(cmd, 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;
|
|
|
}
|
|
|
static public List<Chfee_do_detail> GetPayBodyList(string strCondition, Database db, DbTransaction tran)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" SELECT c.GID,c.BSNO,c.FEEID,c.FEENAME,c.CURRENCY,c.AMOUNT,c.DOAMOUNT,c.ORIGCURRENCY,c.ORIGAMOUNT,c.EXCHANGERATE ");
|
|
|
strSql.Append(",c.FEETYPE,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,p.PAY_FEEDOID,p.PAYDOAMOUNT PAYDOAMOUNT");
|
|
|
strSql.Append(" FROM ch_fee_do_payapplication p left join ch_fee_do c ON (c.gid=p.FEEDOID) ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where 1=1 and " + strCondition);
|
|
|
}
|
|
|
return PayBodySetData(strSql, db, tran);
|
|
|
}
|
|
|
|
|
|
private static List<Chfee_do_detail> PayBodySetData(StringBuilder strSql, Database db, DbTransaction tran)
|
|
|
{
|
|
|
var headList = new List<Chfee_do_detail>();
|
|
|
using (IDataReader reader = db.ExecuteReader(tran, CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Chfee_do_detail data = new Chfee_do_detail();
|
|
|
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.FEEDOID = Convert.ToString(reader["GID"]);
|
|
|
data.FEEID = Convert.ToString(reader["FEEID"]);
|
|
|
data.FEENAME = Convert.ToString(reader["FEENAME"]);
|
|
|
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
|
|
|
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
|
|
|
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
|
|
|
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
|
|
|
data.DOAMOUNT = Convert.ToDecimal(reader["DOAMOUNT"]);
|
|
|
data.ORIGCURRENCY = Convert.ToString(reader["ORIGCURRENCY"]);
|
|
|
data.ORIGAMOUNT = Convert.ToDecimal(reader["ORIGAMOUNT"]);
|
|
|
|
|
|
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
|
|
|
if (reader["PAYDOAMOUNT"] != DBNull.Value)
|
|
|
data.PAYDOAMOUNT = Convert.ToDecimal(reader["PAYDOAMOUNT"]);
|
|
|
data.PAYFEEDOID = Convert.ToString(reader["PAY_FEEDOID"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 派工单
|
|
|
|
|
|
|
|
|
static public List<ChWork> GetWorkList(string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null)
|
|
|
{
|
|
|
|
|
|
var rangstr = GetWorkRangDAListStr("modPaySettlementList", userid, usercode, orgcode);
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT GID,BILLNO,BILLSTATUS,SETTLETIME,AUDITUSER,AUDITTIME,APPLICANT,APPLYTIME,REMARK,COMPANYID ");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=ch_fee_work.APPLICANT) as APPLICANTREF");
|
|
|
strSql.Append(",(select ShowName from [user] where GID=ch_fee_work.AUDITUSER) as AUDITUSERREF");
|
|
|
strSql.Append(" from ch_fee_work ");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
}
|
|
|
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by SETTLETIME desc");
|
|
|
|
|
|
}
|
|
|
|
|
|
return SetWorkData(strSql);
|
|
|
}
|
|
|
|
|
|
public static string GetWorkRangDAListStr(string tb, string userid, string username, string companyid)
|
|
|
{
|
|
|
string str = "";
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID ");
|
|
|
strSql.Append(" from VW_User_Authority ");
|
|
|
strSql.Append(" where [NAME]='modPaySettlementList' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
|
string visiblerange = "4";
|
|
|
string operaterange = "4";
|
|
|
string AUTHORITYID = "";
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
|
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
|
|
|
break;
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
if (visiblerange == "4")
|
|
|
{
|
|
|
str = " (APPLICANT='" + userid + "')";
|
|
|
}
|
|
|
else if (visiblerange == "3")
|
|
|
{
|
|
|
str = " (APPLICANT='" + userid + "')";
|
|
|
}
|
|
|
else if (visiblerange == "2")
|
|
|
{
|
|
|
var rangeDa = new RangeDA();
|
|
|
var deptname = rangeDa.GetDEPTNAME(userid);
|
|
|
str = " APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "') and APPLICANT in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')";
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "1")
|
|
|
{
|
|
|
str = " APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "')";
|
|
|
}
|
|
|
else if (visiblerange == "5")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " (COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or COMPANYID='" + Convert.ToString(reader["COMPANYID"]) + "'";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "6")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " (APPLICANT='" + Convert.ToString(reader["OPID"]) + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or APPLICANT='" + Convert.ToString(reader["OPID"]) + "'";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (visiblerange == "0")
|
|
|
{
|
|
|
str = " 1=1 ";
|
|
|
}
|
|
|
|
|
|
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
|
|
|
static public ChWork GetWorkData(string condition)
|
|
|
{
|
|
|
var list = GetWorkList(condition);
|
|
|
if (list.Count > 0)
|
|
|
return list[0];
|
|
|
|
|
|
return new ChWork();
|
|
|
}
|
|
|
|
|
|
private static List<ChWork> SetWorkData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<ChWork>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ChWork data = new ChWork();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.BILLNO = Convert.ToString(reader["BILLNO"]);
|
|
|
if (reader["BILLSTATUS"] != DBNull.Value)
|
|
|
data.BILLSTATUS = Convert.ToString(reader["BILLSTATUS"]);
|
|
|
data.APPLICANT = Convert.ToString(reader["APPLICANT"]);
|
|
|
data.APPLICANTREF = Convert.ToString(reader["APPLICANTREF"]);
|
|
|
if (reader["APPLYTIME"] != DBNull.Value)
|
|
|
data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
if (reader["SETTLETIME"] != DBNull.Value)
|
|
|
data.SETTLETIME = Convert.ToDateTime(reader["SETTLETIME"]).ToString("yyyy-MM-dd");
|
|
|
if (reader["AUDITTIME"] != DBNull.Value)
|
|
|
data.AUDITTIME = Convert.ToString(reader["AUDITTIME"]);
|
|
|
data.AUDITUSER = Convert.ToString(reader["AUDITUSER"]);
|
|
|
data.AUDITUSERREF = Convert.ToString(reader["AUDITUSERREF"]);
|
|
|
data.REMARK = Convert.ToString(reader["REMARK"]);
|
|
|
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
public static DBResult AddWorkList(ChWork headdata,List<ChPayapplication> BodyList, string userid)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
if (BodyList != null)
|
|
|
{
|
|
|
foreach (var NewData in BodyList)
|
|
|
{
|
|
|
|
|
|
var cmdupdate =
|
|
|
db.GetSqlStringCommand("update ch_fee_payapplication set WORKBILLNO='"+headdata.BILLNO+"' where GID='"+NewData.GID+"'");
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
}
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "添加出现错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "添加成功";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
public static DBResult DelWorkList(ChWork headdata, List<ChPayapplication> BodyList, string userid)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
if (BodyList != null)
|
|
|
{
|
|
|
foreach (var NewData in BodyList)
|
|
|
{
|
|
|
|
|
|
var cmdupdate =
|
|
|
db.GetSqlStringCommand("update ch_fee_payapplication set WORKBILLNO='' where GID='" + NewData.GID + "'");
|
|
|
db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
|
|
|
}
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
|
|
|
result.Success = false;
|
|
|
result.Message = "添加出现错误,请重试或联系系统管理员";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "添加成功";
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
static public int GetRdCount(string strCondition)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT Count(GID) AS CT from ch_fee (NOLOCK) ");
|
|
|
if (strCondition.Trim() != String.Empty)
|
|
|
{
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
}
|
|
|
var ct = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ct = Convert.ToInt16(reader["CT"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return ct;
|
|
|
}
|
|
|
|
|
|
static public int GetPayRdCount(string strCondition)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT Count(GID) AS CT from ch_fee_payapplication (NOLOCK) ");
|
|
|
if (strCondition.Trim() != String.Empty)
|
|
|
{
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
}
|
|
|
var ct = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
ct = Convert.ToInt16(reader["CT"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return ct;
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 付费申请列表权限范围
|
|
|
|
|
|
public static string GetRangDAListStr(string tb, string userid, string username, string companyid)
|
|
|
{
|
|
|
string str = "";
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID ");
|
|
|
strSql.Append(" from VW_User_Authority ");
|
|
|
strSql.Append(" where [NAME]='modPaySettleAppList' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
|
string visiblerange = "4";
|
|
|
string operaterange = "4";
|
|
|
string AUTHORITYID = "";
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
|
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
if (visiblerange == "4")
|
|
|
{
|
|
|
str = " (APPLICANT='" + userid + "')";
|
|
|
}
|
|
|
else if (visiblerange == "3")
|
|
|
{
|
|
|
str = " (APPLICANT='" + userid + "')";
|
|
|
}
|
|
|
else if (visiblerange == "2")
|
|
|
{
|
|
|
var rangeDa = new RangeDA();
|
|
|
var deptid= rangeDa.GetDEPTGID(userid);
|
|
|
str = " APPLICANT in (select USERID from vw_user where deptgid='" + deptid + "') ";
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "1")
|
|
|
{
|
|
|
str = " COMPANYID='" + companyid + "' ";
|
|
|
}
|
|
|
else if (visiblerange == "5")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " COMPANYID='" + companyid + "' ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or COMPANYID='" + companyid + "' ";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "6")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select OPID from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " (APPLICANT='" + Convert.ToString(reader["OPID"]) + "' ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or APPLICANT='" + Convert.ToString(reader["OPID"]) + "'";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "0")
|
|
|
{
|
|
|
str = " 1=1 ";
|
|
|
}
|
|
|
|
|
|
|
|
|
return str;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 付费申请费用查询范围
|
|
|
|
|
|
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
|
|
|
{
|
|
|
string str = "";
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID ,VSSQL");
|
|
|
strSql.Append(" from VW_User_Authority ");
|
|
|
strSql.Append(" where [NAME]='modPaySettleAppSearch' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
|
string visiblerange = "4";
|
|
|
string operaterange = "4";
|
|
|
string AUTHORITYID = "";
|
|
|
string VSSQL = "";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
|
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
|
|
|
VSSQL = Convert.ToString(reader["VSSQL"]);
|
|
|
break;
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
if (visiblerange == "4")
|
|
|
{
|
|
|
str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "' OR DOC='" + username + "')";
|
|
|
}
|
|
|
else if (visiblerange == "3")
|
|
|
{
|
|
|
str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "' OR DOC='" + username + "')";
|
|
|
}
|
|
|
else if (visiblerange == "2")
|
|
|
{
|
|
|
var rangeDa = new RangeDA();
|
|
|
var deptid = rangeDa.GetDEPTGID(userid);
|
|
|
str = " (OP in (select showname from vw_user where deptgid='" + deptid + "') OR SALE in (select showname from vw_user where deptgid='" + deptid + "') OR CUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') "
|
|
|
+ " OR FRCUSTSERVICE in (select showname from vw_user where deptgid='" + deptid + "') OR INPUTBY in (select showname from vw_user where deptgid='" + deptid + "') OR DOC in (select showname from vw_user where deptgid='" + deptid + "'))";
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "1")
|
|
|
{
|
|
|
str = " (OP in (select showname from vw_user where COMPANYID='" + companyid + "') OR SALE in (select showname from vw_user where COMPANYID='" + companyid + "') OR CUSTSERVICE in (select showname from vw_user where COMPANYID='" + companyid + "') "
|
|
|
+ " OR FRCUSTSERVICE in (select showname from vw_user where COMPANYID='" + companyid + "') OR INPUTBY in (select showname from vw_user where COMPANYID='" + companyid + "') OR DOC in (select showname from vw_user where COMPANYID='" + companyid + "'))";
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "5")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " (Corpid='" + Convert.ToString(reader["COMPANYID"]) + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or Corpid='" + Convert.ToString(reader["COMPANYID"]) + "'";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "6")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " (OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' OR DOC='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' OR DOC='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "0")
|
|
|
{
|
|
|
str = " 1=1 ";
|
|
|
}
|
|
|
VSSQL = VSSQL.Trim();
|
|
|
if (!string.IsNullOrEmpty(VSSQL))
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(str))
|
|
|
{
|
|
|
str = str + " and (" + VSSQL + ") ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = " (" + VSSQL + ") ";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static string GetRangAddFeeDAStr(string userid, string username, string companyid)
|
|
|
{
|
|
|
string str = "";
|
|
|
string modustr = "MODPAYAPPFEE";
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID ");
|
|
|
strSql.Append(" from VW_User_Authority ");
|
|
|
strSql.Append(" where [NAME]='" + modustr + "' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
|
string visiblerange = "4";
|
|
|
string operaterange = "4";
|
|
|
string AUTHORITYID = "";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
|
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
|
|
|
break;
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
if (visiblerange == "4")
|
|
|
{
|
|
|
str = " f.ENTEROPERATOR='" + userid + "'";
|
|
|
}
|
|
|
else if (visiblerange == "3")
|
|
|
{
|
|
|
str = " f.ENTEROPERATOR='" + userid + "'";
|
|
|
}
|
|
|
else if (visiblerange == "2")
|
|
|
{
|
|
|
var rangeDa = new RangeDA();
|
|
|
var deptid = rangeDa.GetDEPTGID(userid);
|
|
|
str = " f.ENTEROPERATOR in (select USERID from vw_user where deptid='" + deptid + "') ";
|
|
|
}
|
|
|
else if (visiblerange == "1")
|
|
|
{
|
|
|
str = " f.ENTEROPERATOR in (select USERID from vw_user where COMPANYID='" + companyid + "') ";
|
|
|
}
|
|
|
else if (visiblerange == "5")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select USERID FROM user_company WHERE COMPANYID IN (select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1)");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " (f.ENTEROPERATOR='" + Convert.ToString(reader["USERID"]) + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or f.ENTEROPERATOR='" + Convert.ToString(reader["USERID"]) + "'";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "6")
|
|
|
{
|
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = " (f.ENTEROPERATOR='" + Convert.ToString(reader["OPID"]) + "' ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str + " or f.ENTEROPERATOR='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
|
|
|
};
|
|
|
}
|
|
|
str = str + ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "0")
|
|
|
{
|
|
|
str = " 1=1 ";
|
|
|
}
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 生成邮件
|
|
|
|
|
|
static public List<Chfee_do_detail> GetBodyBsList(string strCondition, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("SELECT b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
|
|
|
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE");
|
|
|
strSql.Append(",b.DOC,b.SALE ");
|
|
|
strSql.Append(",isnull(SUM(CASE WHEN ORIGCURRENCY='RMB' THEN (CASE FEETYPE=2 THEN ISNULL(ORIGAMOUNT,0) ELSE ISNULL(-ORIGAMOUNT,0) END) ELSE 0 END),0) AS RMBCR");
|
|
|
strSql.Append(",isnull(SUM(CASE WHEN ORIGCURRENCY='USD' THEN (CASE FEETYPE=2 THEN ISNULL(ORIGAMOUNT,0) ELSE ISNULL(-ORIGAMOUNT,0) END) ELSE 0 END),0) AS USDCR");
|
|
|
|
|
|
strSql.Append(",(select TTLDR-TTLCR from v_op_gain_sum_ttl where BSNO=b.PARENTID) TTLPROFIT FROM ch_fee_do c");
|
|
|
strSql.Append(" left join v_op_bill b on (b.bsno=c.bsno)");
|
|
|
|
|
|
strSql.Append("GROUP BY b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO,(CASE b.BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF");
|
|
|
strSql.Append(",(CASE b.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
|
|
|
strSql.Append(",b.VESSEL,b.VOYNO,b.CARRIER,b.ETD,b.PORTLOAD,b.ENTERP");
|
|
|
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID,b.BSTYPE");
|
|
|
strSql.Append(",b.DOC,b.SALE ");
|
|
|
|
|
|
|
|
|
strSql.Append(" order by b.ETD,b.MBLNO ");
|
|
|
|
|
|
return BodySetBsData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<Chfee_do_detail> BodySetBsData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<Chfee_do_detail>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
|
cmd.CommandText = strSql.ToString();
|
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
|
using (IDataReader reader = db.ExecuteReader(cmd))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Chfee_do_detail data = new Chfee_do_detail();
|
|
|
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.PARENTID = Convert.ToString(reader["PARENTID"]);
|
|
|
if (reader["RMBCR"] != DBNull.Value)
|
|
|
data.AMOUNT = Convert.ToDecimal(reader["RMBCR"]);
|
|
|
if (reader["USDCR"] != DBNull.Value)
|
|
|
data.DOAMOUNT = Convert.ToDecimal(reader["USDCR"]);
|
|
|
if (reader["TTLPROFIT"] != DBNull.Value)
|
|
|
data.FAMOUNT= Convert.ToDecimal(reader["TTLPROFIT"]);
|
|
|
if (reader["ETD"] != DBNull.Value)
|
|
|
data.ETD = Convert.ToString(reader["ETD"]);
|
|
|
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
|
|
|
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
|
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
data.HBLNO = Convert.ToString(reader["HBLNO"]);
|
|
|
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
|
|
|
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.VESSEL = Convert.ToString(reader["VESSEL"]);
|
|
|
data.VOYNO = Convert.ToString(reader["VOYNO"]);
|
|
|
data.CARRIER = Convert.ToString(reader["CARRIER"]);
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
|
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
|
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
|
|
|
data.DOC = Convert.ToString(reader["DOC"]);
|
|
|
data.SALE = Convert.ToString(reader["SALE"]);
|
|
|
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
|
|
|
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
|
|
|
if (reader["BSSTATUS"] != DBNull.Value)
|
|
|
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
|
|
|
data.BSSTATUSREF = Convert.ToString(reader["BSSTATUSREF"]);
|
|
|
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);
|
|
|
data.BLISSUESTATUS = Convert.ToString(reader["BLISSUESTATUS"]);
|
|
|
data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]);
|
|
|
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
|
|
|
data.ENTERP = Convert.ToString(reader["ENTERP"]);
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
public static DBResult GetEmailHtml(string billno, string userid, string username, string companyid)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
var htmlfile = HttpContext.Current.Server.MapPath("../../EDIFiles/付费申请单.html");
|
|
|
|
|
|
if (File.Exists(htmlfile))
|
|
|
{
|
|
|
var head = GetData("cm.BILLNO='"+billno+"'",userid,username,companyid);
|
|
|
var bodylist = GetBodyAllList("c.BILLNO='"+billno+"'");
|
|
|
|
|
|
var content = File.ReadAllText(htmlfile);
|
|
|
content = content.Replace("OP", head.APPLICANTNAME.Replace("\r\n", "<br />"));
|
|
|
content = content.Replace("$DATE$", head.PAYABLETIME.Replace("\r\n", "<br />"));
|
|
|
content = content.Replace("$CUSTOMERNAME$", head.CUSTOMERNAME.Replace("\r\n", "<br />"));
|
|
|
content = content.Replace("$CUSTBANKCOUNT$", head.CUSTBANKNAME+" "+head.CUSTACCOUNT);
|
|
|
//content = content.Replace("$ISNOFEE$", head.MBLNO);
|
|
|
//content = content.Replace("$ISCONTRACT$", head.MBLNO);
|
|
|
content = content.Replace("$PAYREASON$", head.PAYREASON);
|
|
|
content = content.Replace("$BS_CUSTOMERNAME$", head.BS_CUSTOMERNAME);
|
|
|
content = content.Replace("$STLNAME$", head.STLNAME);
|
|
|
content = content.Replace("$RECREMARK$", head.RECREMARK);
|
|
|
content = content.Replace("$RECSTLDATE$", head.RECSTLDATE);
|
|
|
var amountstr = "";
|
|
|
if (head.AMOUNTRMB != 0) amountstr = amountstr = " RMB:" + head.AMOUNTRMB.ToString();
|
|
|
if (head.AMOUNTUSD != 0) amountstr = amountstr = " USD:" + head.AMOUNTUSD.ToString();
|
|
|
|
|
|
content = content.Replace("$AMOUNT$", amountstr);
|
|
|
|
|
|
HtmlDocument htmlDoc = new HtmlDocument();
|
|
|
htmlDoc.LoadHtml(content);
|
|
|
var nodeTbList = htmlDoc.GetElementbyId("tbOpList");
|
|
|
nodeTbList.RemoveAllChildren();
|
|
|
foreach (var item in bodylist) {
|
|
|
var tr = htmlDoc.CreateElement("tr");
|
|
|
nodeTbList.AppendChild(tr);
|
|
|
var MBLNO = htmlDoc.CreateElement("td");
|
|
|
tr.AppendChild(MBLNO);
|
|
|
MBLNO.SetAttributeValue("style", "height:30px;font-size: 14px;color:#666;padding-left:15px; border-right:1px solid #0081ff;border-bottom:1px solid #0081ff;border-left:1px solid #0081ff;");
|
|
|
MBLNO.InnerHtml = $"{item.MBLNO}";
|
|
|
var CUSTNO = htmlDoc.CreateElement("td");
|
|
|
tr.AppendChild(CUSTNO);
|
|
|
CUSTNO.SetAttributeValue("style", "color: #0081ff;font-family: KaiTi;font-size: 14px;height:40px; padding-left:15px; border-right:1px solid #0081ff;border-bottom:1px solid #0081ff;");
|
|
|
CUSTNO.InnerHtml = $"{item.CUSTNO}";
|
|
|
var USD = htmlDoc.CreateElement("td");
|
|
|
tr.AppendChild(USD);
|
|
|
USD.SetAttributeValue("style", "color: #0081ff;font-family: KaiTi;font-size: 14px;height:40px; padding-left:15px; border-right:1px solid #0081ff;border-bottom:1px solid #0081ff;");
|
|
|
USD.InnerHtml = $"{item.DOAMOUNT}";
|
|
|
var RMB = htmlDoc.CreateElement("td");
|
|
|
tr.AppendChild(RMB);
|
|
|
RMB.SetAttributeValue("style", "color: #0081ff;font-family: KaiTi;font-size: 14px;height:40px; padding-left:15px; border-right:1px solid #0081ff;border-bottom:1px solid #0081ff;");
|
|
|
RMB.InnerHtml = $"{item.AMOUNT}";
|
|
|
var PROFIT = htmlDoc.CreateElement("td");
|
|
|
tr.AppendChild(PROFIT);
|
|
|
PROFIT.SetAttributeValue("style", "color: #0081ff;font-family: KaiTi;font-size: 14px;height:40px; padding-left:15px; border-right:1px solid #0081ff;border-bottom:1px solid #0081ff;");
|
|
|
PROFIT.InnerHtml = $"{item.FAMOUNT}";
|
|
|
var CNTR = htmlDoc.CreateElement("td");
|
|
|
tr.AppendChild(CNTR);
|
|
|
CNTR.SetAttributeValue("style", "color: #0081ff;font-family: KaiTi;font-size: 14px;height:40px; padding-left:15px; border-right:1px solid #0081ff;border-bottom:1px solid #0081ff;");
|
|
|
CNTR.InnerHtml = $"{item.CNTRTOTAL}";
|
|
|
}
|
|
|
StringWriter writer = new StringWriter();
|
|
|
htmlDoc.Save(writer);
|
|
|
string str = writer.ToString();
|
|
|
result.Success = true;
|
|
|
result.Data = str;
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
result.Success = false;
|
|
|
result.Message ="没找到相应的邮件html模板!";
|
|
|
|
|
|
|
|
|
}
|
|
|
return result;
|
|
|
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
public static DBResult GetPrint(string bsno, string userid = "", string usercode = "", string orgcode = "")
|
|
|
{
|
|
|
|
|
|
var AuditPrint = MsSysParamSetDAL.GetData("PARAMNAME='PAYAPPPRINTAFTERAUDIT'");
|
|
|
var PrintOne = MsSysParamSetDAL.GetData("PARAMNAME='PAYAPPONLYPRINTONE'");
|
|
|
var result = new DBResult();
|
|
|
if (AuditPrint.PARAMVALUE != "1"&&PrintOne.PARAMVALUE != "1")
|
|
|
{
|
|
|
result = new DBResult();
|
|
|
result.Success = true;
|
|
|
result.Message = "成功";
|
|
|
}
|
|
|
|
|
|
var PAYBILL = GetData(" cm.BILLNO='" + bsno + "'", userid, usercode, orgcode);
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
try
|
|
|
{
|
|
|
//var cmdupdatePrt = db.GetSqlStringCommand("update ch_fee_payapplication set ISPRINT='1' where BILLNO=@BILLNO");
|
|
|
//cmdupdatePrt.Parameters.Clear();
|
|
|
//db.AddInParameter(cmdupdatePrt, "@BILLNO", DbType.String, bsno);
|
|
|
//db.ExecuteNonQuery(cmdupdatePrt, tran);
|
|
|
|
|
|
if (AuditPrint.PARAMVALUE == "1")
|
|
|
{
|
|
|
|
|
|
if (PAYBILL.BILLSTATUS != 0 && PAYBILL.BILLSTATUS != 4 && PAYBILL.BILLSTATUS != 5)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "此票申请未审核,请审核通过后再打印付费申请";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (PrintOne.PARAMVALUE == "1")
|
|
|
{
|
|
|
|
|
|
if (PAYBILL.ISPRINT == "1")
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "此票申请已打印过,不允许重复打印";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new DBResult();
|
|
|
result.Success = true;
|
|
|
result.Message = "成功";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result = new DBResult();
|
|
|
result.Success = true;
|
|
|
result.Message = "成功";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
if (PrintOne.PARAMVALUE == "1")
|
|
|
{
|
|
|
|
|
|
if (PAYBILL.ISPRINT == "1")
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "此票申请已打印过,不允许重复打印";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = new DBResult();
|
|
|
result.Success = true;
|
|
|
result.Message = "成功";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
result = new DBResult();
|
|
|
result.Success = true;
|
|
|
result.Message = "成功";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "发生错误";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|