You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3070 lines
142 KiB
C#

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;
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))
{
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 ShowName from [user] where GID=cm.AUDITUSER) as AUDITUSERREF");
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 ISINVOICE<>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 ");
strSql.Append(",dbo.GetStlByPayNo(cm.BILLNO) as BALBILLNO,cm.ISPRINT,wxpush,STLRATE,STLAMOUNT,STLCURR ");
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 ShowName from [user] where GID=i.AUDITUSER) as AUDITUSERREF");
strSql.Append(",i.CUSTACCOUNTGID,i.REASON,AUDITREMARK");
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(amount,0)-isnull(invoice,0)) as noinvoice from ch_fee where ISINVOICE<>1 and gid in (select feeid from ch_fee_do where 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 ");
strSql.Append(",dbo.GetBalNoByPayNo(i.BILLNO) as BALBILLNO,i.ISPRINT,i.wxpush,i.STLRATE,i.STLAMOUNT,i.STLCURR ");
strSql.Append(" FROM ch_fee_payapplication i left join workflow_using wu on wu.bsno=i.billno where 1=1 ");
if (isaudit == "3")
strSql.Append(" and dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 ");
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))
{
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();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
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"]);
if (reader["PAYABLETIME"] != DBNull.Value)
data.PAYABLETIME = Convert.ToDateTime(reader["PAYABLETIME"]).ToString("yyyy-MM-dd");
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"]);
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"]);
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"]);
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"]);
#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("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,(SELECT EXCHANGERATE from ch_fee where GID=c.FEEID) ORIGEXCHANGERATE");
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO");
strSql.Append(",b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID");
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 ");
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,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,(SELECT EXCHANGERATE from ch_fee where GID=c.FEEID) ORIGEXCHANGERATE");
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO");
strSql.Append(",b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID");
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 ");
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 + ",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<Chfee_do_detail> GetBodyAuditList(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,(SELECT EXCHANGERATE from ch_fee where GID=c.FEEID) ORIGEXCHANGERATE");
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO,b.CUSTOMNO");
strSql.Append(",b.CUSTOMERNAME,b.BLISSUESTATUS,b.CNTRTOTAL");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.BSSOURCE,B.BSSOURCEDETAIL,B.OPTYPE,b.PARENTID");
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 ");
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);
}
else
{
strSql.Append(" order by c.CREATETIME ");
}
return BodySetData(strSql);
}
private static List<Chfee_do_detail> BodySetData(StringBuilder strSql)
{
var headList = new List<Chfee_do_detail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(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.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.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"]);
if (reader["ORIGEXCHANGERATE"] != DBNull.Value)
data.ORIGEXCHANGERATE = Convert.ToDecimal(reader["ORIGEXCHANGERATE"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.BLISSUESTATUS = Convert.ToString(reader["BLISSUESTATUS"]);
data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
#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);
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,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);
}
private static List<BillChfeeDetail> SetFeeData(StringBuilder strSql)
{
var headList = new List<BillChfeeDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
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["BalAmount"] != DBNull.Value)
data.BalAmount = Convert.ToDecimal(reader["BalAmount"]);
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");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE");
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");
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) ");
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");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE");
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 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");
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");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE");
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");
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_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) ");
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");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE,b.OPTYPE");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.CNTRTOTAL,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 SetAddBillData(strSql);
}
public static int getAddBillTotalCount(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_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) ");
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)
{
var headList = new List<BillCustDetail>();
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;
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.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"]);
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.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"]);
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 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;
}
}
}
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.invoice,f.remark");
strSql.Append(",f.INPUTMODE 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) ");
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 feeName");
}
return SetFeeDetailData(strSql);
}
private static List<ChFeeDetail> SetFeeDetailData(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["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["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"]);
#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, List<BillChfeeDetail> bodyList, string curr, 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 ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
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, "");
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT", DbType.Decimal, enumValue.StlAmount);
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;
}
public static DBResult AddBill(string billno, 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 = GetFeeDetailList(feesql,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 ");
if (feelist != null)
{
foreach (var enumValue in feelist)
{
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, "");
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdate, "@ORDERAMOUNT", DbType.Decimal, enumValue.StlAmount);
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;
}
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");
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);
}
}
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)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, bill, USERID);
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");
}
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 = new DBResult();
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)
{
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)
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, bill, USERID);
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");
}
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 = new DBResult();
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 SubmitAuditBackList(String WorkFlowName, String USERID, String bills)
{
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)
{
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;
}
#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 = "";
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");
foreach (var enumValue in boday)
{
var feecount=GetRdCount(" FEESTATUS NOT IN (0,8,9) AND GID IN (SELECT FEEID FROM CH_FEE_DO WHERE BILLNO='"+enumValue.BILLNO+"')");
if (feecount == 0)
{
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);
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);
}
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 + ")存在未审核费用明细,未审核通过,请先审核费用!";
result = new DBResult();
result.Success = true;
result.Message = "审核通过"+errmsg;
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.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,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
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;
}
#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 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 = " (APPLICANT in (select USERID from user_company where COMPANYID='" + companyid + "') ";
}
else
{
str = str + " or APPLICANT in (select USERID from user_company where COMPANYID='" + 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;
}
#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 ");
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 = "";
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 = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
+ " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
+ " OR SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
+ " OR CUSTSERVICE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))";
}
else if (visiblerange == "1")
{
str = " (OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR CUSTSERVICE in (select showname from [user] where GID 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 = " (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"]) + "'";
}
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"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
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 deptname = rangeDa.GetDEPTNAME(userid);
str = " f.ENTEROPERATOR in (select USERID from user_company where COMPANYID='" + companyid + "') and f.ENTEROPERATOR in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')";
}
else if (visiblerange == "1")
{
str = " f.ENTEROPERATOR in (select USERID from user_company 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
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;
}
}
}