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

5643 lines
287 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.Account.Models.Chfee_Invoiceapplication;
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.MvcShipping.DAL.MsCodeGoodInv;
using DSWeb.Areas.MvcShipping.DAL;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.Areas.Account.Models.TruckChfee_do_detail;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin;
using DSWeb.MvcShipping.DAL.MsSysInvInterFaceSet;
using HcUtility.Core;
using DSWeb.Areas.Account.DAL.Chfee_Invoice;
using DSWeb.MvcShipping.DAL.MsInfoClient;
using DSWeb.MvcShipping.Models.CodeGoodInv;
namespace DSWeb.Areas.Account.DAL.Chfee_Invoiceapplication
{
public partial class ChinvoiceapplicationDAL
{
#region 发票申请列表
static public List<ChInvoiceapplication> GetDataList(int start, int limit, string strCondition, out int totel, 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 *,dbo.GetFeeNoStlByInvNo(BILLNO) as NOSTL from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
sortstring = sortstring.Replace("APPLICANTNAME", "(select ShowName from [user] where GID=cm.APPLICANT)");
sortstring = sortstring.Replace("INVOICECATEGORYREF", "(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY)");
sortstring = sortstring.Replace("BILLSTATUSREF", "(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS)");
sortstring = sortstring.Replace("INVOICENOREF", "(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO)");
sortstring = sortstring.Replace("INVDATE", "(select top 1 INVOICEMAKETIME from ch_fee_invoice where BILLNO=cm.INVBILLNO)");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by APPLYTIME DESC");
}
strSql.Append(@") as num , ");
strSql.Append(" GID,BILLNO,BILLSTATUS,CUSTOMERNAME,ACTUALCUSTOMERNAME,CURRENCY,INVOICECUSTNAME,INVOICECATEGORY ");
strSql.Append(" ,BSNO,MBLNO,VESSELVOYAGE,POL,POD,ETD,APPLYAMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT,AMOUNT");
strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,OPERATOR,OPERATETIME,INVBILLNO ");
strSql.Append(" ,REMARK,SHENREMARK,COMPANYID,ISAPPLY,CUSTRATENO,CUSTADDRTEL,CUSTBANK,RATE,INVOICENO,RECVCURR,FEEAMOUNT ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME");
strSql.Append(",(select DEPTNAME from [VW_user] where userid=cm.APPLICANT) as APPLICANTDEPT");
strSql.Append(",(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVOICENOREF ");
strSql.Append(",(select top 1 INVOICEMAKETIME from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVDATE ");
strSql.Append(",PAYCOMPANYID,(select name from company where gid=cm.PAYCOMPANYID) PAYCOMPANYREF,0 IsAudit,REASON,cm.ISPRINT,cm.PRINTCOUNT ");
strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,cm.PUSHMODE) as PUSHMODEREF,INVTYPE");
strSql.Append(" FROM ch_fee_invoiceapplication 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)); //
totel = getTotalCount(strCondition);
return SetData(strSql);
}
static public List<ChInvoiceapplication> GetDataListAll(string strCondition, string userid = "", string usercode = "", string orgcode = "", string sort = null)
{
var rangstr = "";
if (!string.IsNullOrEmpty(userid))
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 GID,BILLNO,BILLSTATUS,CUSTOMERNAME,ACTUALCUSTOMERNAME,CURRENCY,INVOICECUSTNAME,INVOICECATEGORY ");
strSql.Append(" ,BSNO,MBLNO,VESSELVOYAGE,POL,POD,ETD,APPLYAMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT,AMOUNT");
strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,OPERATOR,OPERATETIME,INVBILLNO ");
strSql.Append(" ,REMARK,SHENREMARK,COMPANYID,ISAPPLY,CUSTRATENO,CUSTADDRTEL,CUSTBANK,RATE,INVOICENO,RECVCURR,FEEAMOUNT ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME");
strSql.Append(",(select DEPTNAME from [VW_user] where userid=cm.APPLICANT) as APPLICANTDEPT");
strSql.Append(",(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVOICENOREF ");
strSql.Append(",(select top 1 INVOICEMAKETIME from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVDATE ");
strSql.Append(",PAYCOMPANYID,(select name from company where gid=cm.PAYCOMPANYID) PAYCOMPANYREF,0 IsAudit,REASON,cm.ISPRINT,cm.PRINTCOUNT ");
strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,cm.PUSHMODE) as PUSHMODEREF,'' as NOSTL,INVTYPE");
strSql.Append(" FROM ch_fee_invoiceapplication cm where 1=1 ");
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);
}
public static int getTotalCount(string strCondition)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) ");
strSql.Append(" FROM ch_fee_invoiceapplication cm where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" 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<ChInvoiceapplication> GetDataInvList(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 GID,cm.BILLNO,BILLSTATUS,CUSTOMERNAME,ACTUALCUSTOMERNAME,CURRENCY,INVOICECUSTNAME,INVOICECATEGORY ");
strSql.Append(" ,BSNO,MBLNO,VESSELVOYAGE,POL,POD,ETD,APPLYAMOUNT,INVAMOUNT,AMOUNTCAPITAL,OTCURRAMOUNT,AMOUNT");
strSql.Append(" ,APPLICANT,APPLYTIME,ENTERTIME,OPERATOR,OPERATETIME,INVBILLNO ");
strSql.Append(" ,REMARK,SHENREMARK,COMPANYID,ISAPPLY,CUSTRATENO,CUSTADDRTEL,CUSTBANK,RATE,INVOICENO,RECVCURR,FEEAMOUNT ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=cm.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=cm.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",(select ShowName from [user] where GID=cm.APPLICANT) as APPLICANTNAME");
strSql.Append(",(select DEPTNAME from [VW_user] where userid=cm.APPLICANT) as APPLICANTDEPT");
strSql.Append(",(select top 1 INVOICENO from ch_fee_invoice where BILLNO=cm.INVBILLNO) as INVOICENOREF,null INVDATE ");
strSql.Append(",PAYCOMPANYID,(select name from company where gid=cm.PAYCOMPANYID) PAYCOMPANYREF,0 IsAudit,REASON,cm.ISPRINT,cm.PRINTCOUNT ");
strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,cm.PUSHMODE) as PUSHMODEREF,'' as NOSTL,INVTYPE");
strSql.Append(" FROM ch_fee_invoiceapplication cm ");
strSql.Append(" left join v_fee_do_payinvoiceNoInv NV ON (NV.BILLNO=cm.BILLNO) where ISNULL(NV.BILLNO,'')<>'' ");
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);
}
static public ChInvoiceapplication GetData(string condition, string userid = "", string usercode = "", string orgcode = "")
{
var list = GetDataListAll(condition,userid,usercode,orgcode);
if (list.Count > 0)
return list[0];
return new ChInvoiceapplication();
}
private static List<ChInvoiceapplication> SetData(StringBuilder strSql)
{
var headList = new List<ChInvoiceapplication>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChInvoiceapplication data = new ChInvoiceapplication();
#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.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.ACTUALCUSTOMERNAME = Convert.ToString(reader["ACTUALCUSTOMERNAME"]);
if (reader["CURRENCY"] != DBNull.Value)
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.INVOICENO = Convert.ToString(reader["INVOICENO"]);
data.INVOICENOREF = Convert.ToString(reader["INVOICENOREF"]);
data.INVOICECUSTNAME = Convert.ToString(reader["INVOICECUSTNAME"]);
data.INVOICECATEGORY = Convert.ToString(reader["INVOICECATEGORY"]);
data.INVOICECATEGORYREF = Convert.ToString(reader["INVOICECATEGORYREF"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.VESSELVOYAGE = Convert.ToString(reader["VESSELVOYAGE"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.POL = Convert.ToString(reader["POL"]);
data.POD = Convert.ToString(reader["POD"]);
if (reader["APPLYAMOUNT"] != DBNull.Value)
data.APPLYAMOUNT = Convert.ToDecimal(reader["APPLYAMOUNT"]);
if (reader["INVAMOUNT"] != DBNull.Value)
data.INVAMOUNT = Convert.ToDecimal(reader["INVAMOUNT"]);
if (reader["AMOUNT"] != DBNull.Value)
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
data.AMOUNTCAPITAL = Convert.ToString(reader["AMOUNTCAPITAL"]);
if (reader["OTCURRAMOUNT"] != DBNull.Value)
data.OTCURRAMOUNT = Convert.ToDecimal(reader["OTCURRAMOUNT"]);
if (reader["RATE"] != DBNull.Value)
data.RATE = Convert.ToDecimal(reader["RATE"]);
else
data.RATE =0;
data.APPLICANT = Convert.ToString(reader["APPLICANT"]);
data.APPLICANTNAME = Convert.ToString(reader["APPLICANTNAME"]);
data.APPLICANTDEPT = Convert.ToString(reader["APPLICANTDEPT"]);
if (reader["APPLYTIME"] != DBNull.Value)
data.APPLYTIME = Convert.ToDateTime(reader["APPLYTIME"]).ToString("yyyy-MM-dd");
if (reader["ENTERTIME"] != DBNull.Value)
data.ENTERTIME = Convert.ToDateTime(reader["ENTERTIME"]);
data.OPERATOR = Convert.ToString(reader["OPERATOR"]);
if (reader["OPERATETIME"] != DBNull.Value)
data.OPERATETIME = Convert.ToDateTime(reader["OPERATETIME"]);
data.SHENREMARK = Convert.ToString(reader["SHENREMARK"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
if (reader["ISAPPLY"] != DBNull.Value)
data.ISAPPLY = Convert.ToBoolean(reader["ISAPPLY"]);
data.CUSTRATENO = Convert.ToString(reader["CUSTRATENO"]);
data.CUSTADDRTEL = Convert.ToString(reader["CUSTADDRTEL"]);
data.CUSTBANK = Convert.ToString(reader["CUSTBANK"]);
data.PAYCOMPANYID = Convert.ToString(reader["PAYCOMPANYID"]);
data.PAYCOMPANYREF = Convert.ToString(reader["PAYCOMPANYREF"]);
data.RECVCURR = Convert.ToString(reader["RECVCURR"]);
data.FEEAMOUNT = Convert.ToString(reader["FEEAMOUNT"]);
data.IsAudit = Convert.ToString(reader["IsAudit"]);
data.REASON = Convert.ToString(reader["REASON"]);
data.PUSHMODE = Convert.ToString(reader["PUSHMODE"]);
data.PUSHMOBILE = Convert.ToString(reader["PUSHMOBILE"]);
data.PUSHEMAIL = Convert.ToString(reader["PUSHEMAIL"]);
data.PUSHMODEREF = Convert.ToString(reader["PUSHMODEREF"]);
data.NOSTL = Convert.ToString(reader["NOSTL"]);
if (reader["INVDATE"] != DBNull.Value)
data.INVDATE = Convert.ToDateTime(reader["INVDATE"]).ToString("yyyy-MM-dd");
data.ISPRINT = Convert.ToString(reader["ISPRINT"]);
if (reader["PRINTCOUNT"] != DBNull.Value)
data.PRINTCOUNT = Convert.ToInt32(reader["PRINTCOUNT"]);
data.INVTYPE = Convert.ToString(reader["INVTYPE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 发票申请明细
static public List<ChInvoiceDetail> GetDetailList(string strCondition,string sort=null)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT GID,PID,SerialNo,GOODSNAME,SPEC,UNIT ");
strSql.Append(",PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE");
strSql.Append(",(Select GOODNAME from code_goods_inv where GID=ch_fee_invoicedetail.GOODSNAME) AS GOODSNAMEREF");
strSql.Append(" FROM ch_fee_invoicedetail ");
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 SerialNo");
}
return DetailSetData(strSql);
}
private static List<ChInvoiceDetail> DetailSetData(StringBuilder strSql)
{
var headList = new List<ChInvoiceDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ChInvoiceDetail data = new ChInvoiceDetail();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PID = Convert.ToString(reader["PID"]);
data.SERIALNO = Convert.ToInt16(reader["SerialNo"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.GOODSNAMEREF = Convert.ToString(reader["GOODSNAMEREF"]);
if (data.GOODSNAMEREF == "" || data.GOODSNAMEREF == null) data.GOODSNAMEREF = data.GOODSNAME;
data.SPEC = Convert.ToString(reader["SPEC"]);
data.UNIT = Convert.ToString(reader["UNIT"]);
data.PKGS = Convert.ToDecimal(reader["PKGS"]);
data.TAXPRICE = Convert.ToDecimal(reader["TAXPRICE"]);
data.PRICE = Convert.ToDecimal(reader["PRICE"]);
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
data.TAXRATE = Convert.ToDecimal(reader["TAXRATE"]);
data.TAX = Convert.ToDecimal(reader["TAX"]);
data.REMARK= Convert.ToString(reader["Remark"]);
data.GOODCODE = Convert.ToString(reader["GOODCODE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
static public List<ChInvoiceapplicationDetail> GetApplicationDetailList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT GID,LINKGID,BILLSTATUS,CUSTOMERNAME,INVOICECUSTNAME,AMOUNT,CURRENCY,REMARK,CUSTRATENO,CUSTADDRTEL,CUSTBANK,CUSTTEL,CUSTADDR ");
strSql.Append(",EMAIL,GOODSNAME,(Select GOODNAME from code_goods_inv where GID=ch_fee_invoiceapplication_detail.GOODSNAME) AS GOODSNAMEREF");
strSql.Append(",(SELECT TOP 1 INVOICENO FROM ch_fee_invoice WHERE BILLNO = ch_fee_invoiceapplication_detail.INVBILLNO) INVOICENO ");
strSql.Append(" FROM ch_fee_invoiceapplication_detail ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where 1=1 and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CUSTOMERNAME");
}
return AppDetailSetData(strSql);
}
private static List<ChInvoiceapplicationDetail> AppDetailSetData(StringBuilder strSql)
{
var headList = new List<ChInvoiceapplicationDetail>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 1200000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
ChInvoiceapplicationDetail data = new ChInvoiceapplicationDetail();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
data.BILLSTATUS = Convert.ToString(reader["BILLSTATUS"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.INVOICECUSTNAME = Convert.ToString(reader["INVOICECUSTNAME"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
if (reader["AMOUNT"] != DBNull.Value)
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
data.CUSTRATENO = Convert.ToString(reader["CUSTRATENO"]);
data.CUSTADDRTEL = Convert.ToString(reader["CUSTADDRTEL"]);
data.CUSTBANK = Convert.ToString(reader["CUSTBANK"]);
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
data.CUSTADDR = Convert.ToString(reader["CUSTADDR"]);
data.EMAIL = Convert.ToString(reader["EMAIL"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.GOODSNAMEREF = Convert.ToString(reader["GOODSNAMEREF"]);
data.INVOICENO = Convert.ToString(reader["INVOICENO"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveAppDetail(ChInvoiceapplication headData, List<ChInvoiceapplicationDetail> bodyList)
{
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_invoiceapplication_detail (GID,BILLSTATUS,LINKGID,CUSTOMERNAME,INVOICECUSTNAME,AMOUNT,CURRENCY,REMARK,CUSTRATENO,CUSTADDRTEL,CUSTBANK,CUSTTEL,CUSTADDR,EMAIL,GOODSNAME)
values (@GID,@BILLSTATUS,@LINKGID,@CUSTOMERNAME,@INVOICECUSTNAME,@AMOUNT,@CURRENCY,@REMARK,@CUSTRATENO,@CUSTADDRTEL,@CUSTBANK,@CUSTTEL,@CUSTADDR,@EMAIL,@GOODSNAME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update ch_fee_invoiceapplication_detail set CUSTOMERNAME=@CUSTOMERNAME,INVOICECUSTNAME=@INVOICECUSTNAME,AMOUNT=@AMOUNT,CURRENCY=@CURRENCY,REMARK=@REMARK,CUSTRATENO=@CUSTRATENO
,CUSTADDRTEL=@CUSTADDRTEL,CUSTBANK=@CUSTBANK,CUSTTEL=@CUSTTEL,CUSTADDR=@CUSTADDR,EMAIL=@EMAIL,GOODSNAME=@GOODSNAME
WHERE GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.LINKGID == "*")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.String,"未开");
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, headData.GID);
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdInsert, "@INVOICECUSTNAME", DbType.String, enumValue.INVOICECUSTNAME);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.String, enumValue.AMOUNT);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@CUSTRATENO", DbType.String, enumValue.CUSTRATENO);
db.AddInParameter(cmdInsert, "@CUSTADDRTEL", DbType.String, enumValue.CUSTADDRTEL);
db.AddInParameter(cmdInsert, "@CUSTBANK", DbType.String, enumValue.CUSTBANK);
db.AddInParameter(cmdInsert, "@CUSTTEL", DbType.String, enumValue.CUSTTEL);
db.AddInParameter(cmdInsert, "@CUSTADDR", DbType.String, enumValue.CUSTADDR);
db.AddInParameter(cmdInsert, "@EMAIL", DbType.String, enumValue.EMAIL);
db.AddInParameter(cmdInsert, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.ExecuteNonQuery(cmdInsert, tran);
}
else {
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdUpdate, "@INVOICECUSTNAME", DbType.String, enumValue.INVOICECUSTNAME);
db.AddInParameter(cmdUpdate, "@AMOUNT", DbType.String, enumValue.AMOUNT);
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@CUSTRATENO", DbType.String, enumValue.CUSTRATENO);
db.AddInParameter(cmdUpdate, "@CUSTADDRTEL", DbType.String, enumValue.CUSTADDRTEL);
db.AddInParameter(cmdUpdate, "@CUSTBANK", DbType.String, enumValue.CUSTBANK);
db.AddInParameter(cmdUpdate, "@CUSTTEL", DbType.String, enumValue.CUSTTEL);
db.AddInParameter(cmdUpdate, "@CUSTADDR", DbType.String, enumValue.CUSTADDR);
db.AddInParameter(cmdUpdate, "@EMAIL", DbType.String, enumValue.EMAIL);
db.AddInParameter(cmdUpdate, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员" + e.Message;
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static DBResult DelInvAppDetail(List<ChInvoiceapplicationDetail> bodyList)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"delete from ch_fee_invoiceapplication_detail where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdInsert, 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 List<ChFeeExrate> GetAppCurrExrateData(ChInvoiceapplication headData, List<ChInvoiceapplicationDetail> bodyList)
{
var headList = new List<ChFeeExrate>();
if (headData.INVTYPE == "原币开票") {
foreach (var body in bodyList)
{
if (body.CURRENCY != "RMB")
{
ChFeeExrate data = new ChFeeExrate();
#region Set DB data to Object
data.CURR = body.CURRENCY;
data.EXRATE = 0;
data.DFEXRATE = 0;
#endregion
headList.Add(data);
}
}
return headList;
}
var strSql = new StringBuilder();
strSql.Append(" SELECT DISTINCT ORIGCURRENCY CURRENCY,EXCHANGERATE ");
strSql.Append(" FROM ch_fee_do f where ORIGCURRENCY<>'RMB' AND BILLNO='"+headData.BILLNO+"'");
return SetCurrExrateData(strSql);
}
public static DBResult CreateInvList(ChInvoiceapplication headData, List<ChInvoiceapplicationDetail> bodyList, List<ChFeeExrate> exratelist, string userid, string username,string companyid)
{
var result = new DBResult();
if (bodyList == null || bodyList.Count == 0) {
result.Success = false;
result.Message = "开票列表不能为空!";
return result;
}
foreach (var body in bodyList) {
var head = new ChInvoice_HangXin();
head.OPERATOR = userid;
head.OPERATORNAME = username;
head.CREATEUSER = userid;
head.PTORRED = "1";//默认为正票
head.SALECORPID = companyid;
head.PAYEE = username;
head.CHECKER = username;
head.PUSHMOBILE = "0";
var defaultPAYEE = MsSysParamSetDAL.GetData("PARAMNAME='INVSKR'").PARAMVALUE;
var defaultCHECKER = MsSysParamSetDAL.GetData("PARAMNAME='INVFHR'").PARAMVALUE;
if (!string.IsNullOrEmpty(defaultPAYEE))
head.PAYEE = defaultPAYEE;
if (!string.IsNullOrEmpty(defaultCHECKER))
head.CHECKER = defaultCHECKER;
head.INVOICETYPE = 2;
head.INVOICETYPEREF = "申请发票";
head.GID = Guid.NewGuid().ToString();
head.BILLNO = PubSysDAL.GetBillNo("0308");
head.COMPANYID = companyid;
head.OPERATOR = userid;
head.OPERATETIME = DateTime.Now;
head.CREATEUSER = userid;
head.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
head.DbOperationType = DbOperationType.DbotIns;
head.CURRENCY = "RMB";
head.RECVCURR = body.CURRENCY;
head.CUSTOMERNAME = headData.CUSTOMERNAME;
head.INVOICECUSTNAME = body.INVOICECUSTNAME;
head.CUSTRATENO = body.CUSTRATENO;
head.CUSTADDR = body.CUSTADDR;
head.CUSTTEL = body.CUSTTEL;
head.CUSTBANK = body.CUSTBANK;
head.PUSHEMAIL = body.EMAIL;
if (head.INVOICECUSTNAME == "" || head.CUSTRATENO == "")
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet dsHSCODE = T_ALL_DA.GetAllSQL("SELECT Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,BillRises1,INVADDRTEL,[DESCRIPTION],RmbBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='RMB' AND LINKID=info_client.GID) Rmbbank,Rmbaccount,usdBillRises,usdbank,usdaccount,TaxNo,Addr,Tel,EMAIL from info_client WHERE SHORTNAME='" + headData.CUSTOMERNAME + "' and CORPID='" + companyid + "'");
if (dsHSCODE != null)
{
if (dsHSCODE.Tables[0].Rows.Count > 0)
{
if (dsHSCODE.Tables[0].Rows[0]["BillRises1"].ToString() != "")
head.INVOICECUSTNAME = dsHSCODE.Tables[0].Rows[0]["BillRises1"].ToString();
else head.INVOICECUSTNAME = dsHSCODE.Tables[0].Rows[0]["DESCRIPTION"].ToString();
if (head.CUSTRATENO == "") head.CUSTRATENO = dsHSCODE.Tables[0].Rows[0]["TaxNo"].ToString();
if (head.CUSTADDRTEL == "")
{
if (dsHSCODE.Tables[0].Rows[0]["INVADDRTEL"].ToString() != "")
head.CUSTADDRTEL = dsHSCODE.Tables[0].Rows[0]["INVADDRTEL"].ToString();
else head.CUSTADDRTEL = dsHSCODE.Tables[0].Rows[0]["Addr"].ToString() + " " + dsHSCODE.Tables[0].Rows[0]["Tel"].ToString();
}
if (string.IsNullOrEmpty(head.CUSTTEL))
{
if (dsHSCODE.Tables[0].Rows[0]["Tel"].ToString() != "")
head.CUSTTEL = dsHSCODE.Tables[0].Rows[0]["Tel"].ToString();
}
if (string.IsNullOrEmpty(head.CUSTADDR))
{
if (dsHSCODE.Tables[0].Rows[0]["Addr"].ToString() != "")
head.CUSTADDR = dsHSCODE.Tables[0].Rows[0]["Addr"].ToString();
}
if (head.CUSTBANK == "")
{
head.CUSTBANK = dsHSCODE.Tables[0].Rows[0]["Rmbbank"].ToString();
}
}
}
}
if (string.IsNullOrEmpty(head.INVITERFACE))
{
var INVITERFACE = MsSysInvInterFaceSetDAL.GetData("INVOICELINE='" + head.INVOICELINEREF + "'", "");
if (INVITERFACE.INVITERFACE == "")
head.INVITERFACE = INVITERFACE.INVITERFACE;
else head.INVITERFACE = "诺诺发票接口";
}
var modb = new ModelObjectDB();
result = modb.Save(head);
if (result.Success) {
AddAppDetailNew(head, headData, body, exratelist, companyid,userid);
ChinvoiceDAL.p_update_Amount(head.BILLNO, head.GID);
}
}
result.Success = true;
result.Message = "生成发票成功" + result.Message;
return result;
}
public static DBResult AddAppDetailNew(ChInvoice_HangXin headdata, ChInvoiceapplication head, ChInvoiceapplicationDetail body, List<ChFeeExrate> exratelist,string companyid,string userid)
{
var result = new DBResult();
//var invdetailDataList = GetDetailList("PID='" + GID + "'");
var invappdetail = ChinvoiceapplicationDAL.GetBodyList("c.BILLNO='" + head.BILLNO + "' and c.ORIGAMOUNT<>ISNULL(c.ORIGSTLAMOUNT,0) ",userid);
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdatefeedo =
db.GetSqlStringCommand(
@" update ch_fee_do set doamount=ISNULL(doamount,0)+@stlamount,origstlamount=ISNULL(origstlamount,0)+@origstlamount where gid=@gid");
var cmdUpdateFEE =
db.GetSqlStringCommand(
@"UPDATE CH_FEE SET INVOICE=ISNULL(INVOICE,0)+@INVOICE,ORDERINVSETTLEMENT=ISNULL(ORDERINVSETTLEMENT,0)+@INVOICE2 WHERE GID=@GID ");
var cmdUpdateInv =
db.GetSqlStringCommand(
@"update ch_fee_invoice set REMARK=REMARK+' '+@REMARK
WHERE BILLNO=@BILLNO");
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 cmdUpdateAppDetail =
db.GetSqlStringCommand(
@"UPDATE ch_fee_invoiceapplication_detail set BILLSTATUS='已开',INVBILLNO=@INVBILLNO where GID=@GID");
var cmdInsertAppSettl =
db.GetSqlStringCommand(
@"insert into ch_fee_do_payapplication (GID,BILLNO,PAYBILLNO,PAY_FEEDOID,FEEDOID,CREATETIME,PAYDOAMOUNT,CURR)
values (@GID,@BILLNO,@PAYBILLNO,@PAY_FEEDOID,@FEEDOID,@CREATETIME,@PAYDOAMOUNT,@CURR) ");
// var cmdUpdateApp =
//db.GetSqlStringCommand(
// @"UPDATE ch_fee_invoiceapplication set BILLSTATUS=3,INVBILLNO=@INVBILLNO,DOINVAMOUNT=ISNULL(DOINVAMOUNT,0)+@DOINVAMOUNT where BILLNO=@BILLNO");
var cmdInsertInvDetail =
db.GetSqlStringCommand(
@"insert ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values (NEWID(),@PID,@SerialNo,@GOODSNAME,@SPEC,@UNIT,@PKGS,@TAXPRICE,@PRICE,@AMOUNT,@TAXRATE,@TAX,@Remark,@GOODCODE) ");
var invdetailid = "";
decimal amtttl = 0;
var stlamount = body.AMOUNT;
if (invappdetail != null)
{
foreach (var feedovalue in invappdetail)
{
decimal balamount = 0;
decimal origamount = 0;
if (stlamount != 0&&(head.INVTYPE == "原币开票"&&feedovalue.ORIGCURRENCY== body.CURRENCY))
{
if (head.INVTYPE == "原币开票")
{
if ((feedovalue.ORIGAMOUNT - feedovalue.ORIGSTLAMOUNT) <= stlamount)
{
balamount = feedovalue.AMOUNT - feedovalue.DOAMOUNT;
origamount = feedovalue.ORIGAMOUNT - feedovalue.ORIGSTLAMOUNT;
if (feedovalue.FEETYPE == 1)
stlamount = stlamount - origamount;
else
stlamount = stlamount + origamount;
}
else
{
origamount = stlamount;
balamount = origamount* feedovalue.EXCHANGERATE;
stlamount =0;
}
}
cmdUpdatefeedo.Parameters.Clear();
db.AddInParameter(cmdUpdatefeedo, "@stlamount", DbType.Decimal, balamount);
db.AddInParameter(cmdUpdatefeedo, "@origstlamount", DbType.Decimal, origamount);
db.AddInParameter(cmdUpdatefeedo, "@gid", DbType.String, feedovalue.FEEDOID);
db.ExecuteNonQuery(cmdUpdatefeedo, tran);
var feedoid = Guid.NewGuid().ToString();
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, feedoid);
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, headdata.BILLNO);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, feedovalue.BSNO);
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, feedovalue.MBLNO);
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, feedovalue.HBLNO);
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, feedovalue.FEEOBJNAME);
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, feedovalue.FEEID);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, feedovalue.FEENAME);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, feedovalue.CURRENCY);
if (feedovalue.ORIGCURRENCY =="RMB")
{
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, origamount);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal,1);
if (feedovalue.FEETYPE == 2)
amtttl = amtttl - origamount;
else
amtttl = amtttl + origamount;
}
else
{
var UExrate = GetExrate(feedovalue.ORIGCURRENCY, exratelist);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(origamount * UExrate, 2));
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, UExrate);
if (feedovalue.FEETYPE == 2)
amtttl = amtttl - Math.Round(origamount * UExrate, 2);
else
amtttl = amtttl + Math.Round(origamount * UExrate, 2);
}
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, feedovalue.FEETYPE);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 7);
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, "@ORIGCURRENCY", DbType.String, feedovalue.ORIGCURRENCY);
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, origamount);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, "");
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdateFEE.Parameters.Clear();
db.AddInParameter(cmdUpdateFEE, "@GID", DbType.String, feedovalue.FEEID);
db.AddInParameter(cmdUpdateFEE, "@INVOICE", DbType.Decimal, origamount);
db.AddInParameter(cmdUpdateFEE, "@INVOICE2", DbType.Decimal, origamount);
db.ExecuteNonQuery(cmdUpdateFEE, tran);
cmdInsertAppSettl.Parameters.Clear();
db.AddInParameter(cmdInsertAppSettl, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertAppSettl, "@BILLNO", DbType.String, headdata.BILLNO);
db.AddInParameter(cmdInsertAppSettl, "@PAYBILLNO", DbType.String, head.BILLNO);
db.AddInParameter(cmdInsertAppSettl, "@PAY_FEEDOID", DbType.String, feedovalue.FEEDOID);
db.AddInParameter(cmdInsertAppSettl, "@FEEDOID", DbType.String, feedoid);
db.AddInParameter(cmdInsertAppSettl, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsertAppSettl, "@PAYDOAMOUNT", DbType.Decimal, origamount);
db.AddInParameter(cmdInsertAppSettl, "@CURR", DbType.String, feedovalue.CURRENCY);
db.ExecuteNonQuery(cmdInsertAppSettl, tran);
}
if (stlamount != 0 && (head.INVTYPE == "人民币折美元开票"|| head.INVTYPE == "美元折人民币开票"))
{
if ((feedovalue.AMOUNT - feedovalue.DOAMOUNT) <= stlamount)
{
balamount = feedovalue.AMOUNT - feedovalue.DOAMOUNT;
origamount = feedovalue.ORIGAMOUNT - feedovalue.ORIGSTLAMOUNT;
if (feedovalue.FEETYPE == 1)
stlamount = stlamount - balamount;
else
stlamount = stlamount + balamount;
}
else
{
balamount = stlamount;
origamount = balamount * feedovalue.EXCHANGERATE;
stlamount = 0;
}
cmdUpdatefeedo.Parameters.Clear();
db.AddInParameter(cmdUpdatefeedo, "@stlamount", DbType.Decimal, balamount);
db.AddInParameter(cmdUpdatefeedo, "@origstlamount", DbType.Decimal, origamount);
db.AddInParameter(cmdUpdatefeedo, "@gid", DbType.String, feedovalue.FEEDOID);
db.ExecuteNonQuery(cmdUpdatefeedo, tran);
var feedoid = Guid.NewGuid().ToString();
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, feedoid);
db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, headdata.BILLNO);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, feedovalue.BSNO);
db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, feedovalue.MBLNO);
db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, feedovalue.HBLNO);
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, feedovalue.FEEOBJNAME);
db.AddInParameter(cmdInsert, "@BSTYPE", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@FEEID", DbType.String, feedovalue.FEEID);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, feedovalue.FEENAME);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, feedovalue.CURRENCY);
if (feedovalue.ORIGCURRENCY == "RMB")
{
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, origamount);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1);
if (feedovalue.FEETYPE == 2)
amtttl = amtttl - origamount;
else
amtttl = amtttl + origamount;
}
else
{
var UExrate = GetExrate(feedovalue.ORIGCURRENCY, exratelist);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(origamount * UExrate, 2));
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, UExrate);
if (feedovalue.FEETYPE == 2)
amtttl = amtttl - Math.Round(origamount * UExrate, 2);
else
amtttl = amtttl + Math.Round(origamount * UExrate, 2);
}
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, feedovalue.FEETYPE);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 7);
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, "@ORIGCURRENCY", DbType.String, feedovalue.ORIGCURRENCY);
db.AddInParameter(cmdInsert, "@ORIGAMOUNT", DbType.Decimal, origamount);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, "");
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdInsertAppSettl.Parameters.Clear();
db.AddInParameter(cmdInsertAppSettl, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertAppSettl, "@BILLNO", DbType.String, headdata.BILLNO);
db.AddInParameter(cmdInsertAppSettl, "@PAYBILLNO", DbType.String, head.BILLNO);
db.AddInParameter(cmdInsertAppSettl, "@PAY_FEEDOID", DbType.String, feedovalue.FEEDOID);
db.AddInParameter(cmdInsertAppSettl, "@FEEDOID", DbType.String, feedoid);
db.AddInParameter(cmdInsertAppSettl, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsertAppSettl, "@PAYDOAMOUNT", DbType.Decimal, origamount);
db.AddInParameter(cmdInsertAppSettl, "@CURR", DbType.String, feedovalue.CURRENCY);
db.ExecuteNonQuery(cmdInsertAppSettl, tran);
cmdUpdateFEE.Parameters.Clear();
db.AddInParameter(cmdUpdateFEE, "@GID", DbType.String, feedovalue.FEEID);
db.AddInParameter(cmdUpdateFEE, "@INVOICE", DbType.Decimal, origamount);
db.AddInParameter(cmdUpdateFEE, "@INVOICE2", DbType.Decimal, origamount);
db.ExecuteNonQuery(cmdUpdateFEE, tran);
}
}
cmdUpdateAppDetail.Parameters.Clear();
db.AddInParameter(cmdUpdateAppDetail, "@GID", DbType.String,body.GID);
db.AddInParameter(cmdUpdateAppDetail, "@INVBILLNO", DbType.String,headdata.BILLNO);
db.ExecuteNonQuery(cmdUpdateAppDetail, tran);
}
//currency = enumValue.CURRENCY;
//rate = enumValue.RATE;
//custrateno = enumValue.CUSTRATENO;
//custaddrtel = enumValue.CUSTADDRTEL;
//custbank = enumValue.CUSTBANK;
//INVOICECATEGORY = enumValue.INVOICECATEGORY;
//ACTUALCUSTOMERNAME = enumValue.ACTUALCUSTOMERNAME;
//INVOICECUSTNAME = enumValue.INVOICECUSTNAME;
//REMARK = REMARK + ' ' + enumValue.REMARK;
//cmdInsert.Parameters.Clear();
//db.AddInParameter(cmdInsert, "@BILLNO", DbType.String, billno);
//db.AddInParameter(cmdInsert, "@AppBILLNO", DbType.String, enumValue.BILLNO);
//db.ExecuteNonQuery(cmdInsert, tran);
//var invdetaillist = GetDetailList("PID='" + enumValue.GID + "'", db, tran);
//var stlinvaount = enumValue.STLINVAMOUNT;
//if (invdetaillist != null)
//{
// foreach (var enumInvDetail in invdetaillist)
// {
// if (stlinvaount != 0)
// {
// bool ishave = false;
// if (enumInvDetail.AMOUNT <= stlinvaount)
// {
// stlinvaount = stlinvaount - enumInvDetail.AMOUNT;
// if (invdetailDataList != null)
// {
// foreach (var invdetailData in invdetailDataList)
// {
// if (invdetailData.GOODSNAME == enumInvDetail.GOODSNAME)
// {
// invdetailData.TAXPRICE = invdetailData.TAXPRICE + enumInvDetail.TAXPRICE;
// invdetailData.PRICE = invdetailData.PRICE + enumInvDetail.PRICE;
// invdetailData.AMOUNT = invdetailData.AMOUNT + enumInvDetail.AMOUNT;
// invdetailData.TAX = invdetailData.TAX + enumInvDetail.TAX;
// ishave = true;
// }
// }
// }
// if (!ishave)
// {
// var invdetailtmp = enumInvDetail;
// invdetailtmp.GID = "*";
// invdetailtmp.PID = GID;
// invdetailDataList.Add(invdetailtmp);
// }
// }
// else
// {
// if (invdetailDataList != null)
// {
// foreach (var invdetailData in invdetailDataList)
// {
// if (invdetailData.GOODSNAME == enumInvDetail.GOODSNAME)
// {
// invdetailData.TAXPRICE = invdetailData.TAXPRICE + enumInvDetail.TAXPRICE * (stlinvaount / enumInvDetail.AMOUNT);
// invdetailData.PRICE = invdetailData.PRICE + enumInvDetail.PRICE * (stlinvaount / enumInvDetail.AMOUNT);
// invdetailData.AMOUNT = invdetailData.AMOUNT + stlinvaount;
// invdetailData.TAX = invdetailData.TAX + enumInvDetail.TAX * (stlinvaount / enumInvDetail.AMOUNT);
// ishave = true;
// }
// }
// }
// if (!ishave)
// {
// var invdetailtmp = enumInvDetail;
// invdetailtmp.GID = "*";
// invdetailtmp.PID = GID;
// invdetailtmp.TAXPRICE = enumInvDetail.TAXPRICE * (stlinvaount / enumInvDetail.AMOUNT);
// invdetailtmp.PRICE = enumInvDetail.PRICE * (stlinvaount / enumInvDetail.AMOUNT);
// invdetailtmp.AMOUNT = stlinvaount;
// invdetailtmp.TAX = enumInvDetail.TAX * (stlinvaount / enumInvDetail.AMOUNT);
// invdetailDataList.Add(invdetailtmp);
// }
// stlinvaount = 0;
// }
// }
// }
//}
//cmdUpdateApp.Parameters.Clear();
//db.AddInParameter(cmdUpdateApp, "@INVBILLNO", DbType.String, billno);
//db.AddInParameter(cmdUpdateApp, "@INVOICENO", DbType.String, invoiceno);
//db.AddInParameter(cmdUpdateApp, "@DOINVAMOUNT", DbType.Decimal, enumValue.DOINVAMOUNT);
//db.AddInParameter(cmdUpdateApp, "@BILLNO", DbType.String, enumValue.BILLNO);
//db.ExecuteNonQuery(cmdUpdateApp, tran);
if (amtttl != 0)
{
var defGOOD = new CodeGoodInv();
if (!string.IsNullOrEmpty(body.GOODSNAME))
defGOOD = MsCodeGoodInvDAL.GetData(" GID='"+ body.GOODSNAME + "' ");
else
defGOOD = MsCodeGoodInvDAL.GetData(" ISDEF='1' and (DEFCURR='' or DEFCURR='" + body.CURRENCY + "') ");
var acctaxrate = head.RATE;
cmdInsertInvDetail.Parameters.Clear();
db.AddInParameter(cmdInsertInvDetail, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInvDetail, "@PID", DbType.String, headdata.GID);
db.AddInParameter(cmdInsertInvDetail, "@SerialNo", DbType.Int32, 1);
if (defGOOD.GOODNAME == "")
{
db.AddInParameter(cmdInsertInvDetail, "@GOODSNAME", DbType.String, "代理运杂费");
db.AddInParameter(cmdInsertInvDetail, "@UNIT", DbType.String, "票");
}
else
{
db.AddInParameter(cmdInsertInvDetail, "@GOODSNAME", DbType.String, defGOOD.GID);
db.AddInParameter(cmdInsertInvDetail, "@UNIT", DbType.String, defGOOD.UNIT);
}
db.AddInParameter(cmdInsertInvDetail, "@SPEC", DbType.String, defGOOD.SPEC);
db.AddInParameter(cmdInsertInvDetail, "@PKGS", DbType.Decimal, 1);
db.AddInParameter(cmdInsertInvDetail, "@TAXPRICE", DbType.Decimal, amtttl);
db.AddInParameter(cmdInsertInvDetail, "@TAXRATE", DbType.Decimal, acctaxrate);
if (acctaxrate == 0)
{
db.AddInParameter(cmdInsertInvDetail, "@PRICE", DbType.Decimal, amtttl);
db.AddInParameter(cmdInsertInvDetail, "@AMOUNT", DbType.Decimal, amtttl);
db.AddInParameter(cmdInsertInvDetail, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2);
var amount = amtttl - tax;
// var amount = Math.Round(amtttl / (1 + acctaxrate / 100),2);
db.AddInParameter(cmdInsertInvDetail, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInvDetail, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInvDetail, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInvDetail, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInvDetail, "@GOODCODE", DbType.String, defGOOD.GOODCODE);
db.ExecuteNonQuery(cmdInsertInvDetail, tran);
var cmd = db.GetStoredProcCommand("p_update_invapplycationstatus");
db.AddInParameter(cmd, "@con_no", DbType.String, head.BILLNO);
db.ExecuteNonQuery(cmd, tran);
}
//db.AddInParameter(cmdUpdateInv, "@REMARK", DbType.String, REMARK);
//db.ExecuteNonQuery(cmdUpdateInv, tran);
tran.Commit();
}
catch (Exception E)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员"+E.Message;
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DeleteAppDetail(ChInvoiceapplication headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmd = db.GetSqlStringCommand("delete from ch_fee_invoiceapplication_detail where LINKGID='" + headData.GID + "'");
db.ExecuteNonQuery(cmd, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#region 发票申请费用明细
static public List<Chfee_do_detail> GetBodyList(string strCondition,string userid,string sort=null)
{
var modPSFEE = MsBaseInfoDAL.GetUserModuleEnable("modPSFEE", userid);
if (!modPSFEE)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
else
{
strCondition = " f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
}
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,f.ACCTAXRATE ");
strSql.Append(",c.FEETYPE,c.CUSTOMERNAME as FEEOBJNAME,(CASE C.FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF,f.EXCHANGERATE ORIGEXCHANGERATE");
strSql.Append(" ,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
strSql.Append(",b.CUSTOMERNAME");
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,b.ENTERP,(select [NAME] FROM company where GID=B.SALECORPID) BSSALECORP");
strSql.Append(",f.Remark Remark,f.INPUTMODE,f.AUDITDATE,f.SALECORP,c.INVOICESETTLENO,C.BILLNO ");
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 b.MBLNO");
}
return BodySetData(strSql);
}
private static List<Chfee_do_detail> BodySetData(StringBuilder strSql)
{
var headList = new List<Chfee_do_detail>();
Database db = DatabaseFactory.CreateDatabase();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 1200000; //要加这一句
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
Chfee_do_detail data = new Chfee_do_detail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.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"]);
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.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
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"]);
if (reader["ORIGEXCHANGERATE"] != DBNull.Value)
data.ORIGEXCHANGERATE = Convert.ToDecimal(reader["ORIGEXCHANGERATE"]);
if (reader["BSSTATUS"] != DBNull.Value)
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]);
if (reader["AUDITDATE"] != DBNull.Value)
data.AUDITDATE = Convert.ToString(reader["AUDITDATE"]);
data.SALECORP = Convert.ToString(reader["SALECORP"]);
data.COMPANYNAME = Convert.ToString(reader["BSSALECORP"]);
data.ENTERP = Convert.ToString(reader["ENTERP"]);
if (reader["ACCTAXRATE"] != DBNull.Value)
data.ACCTAXRATE = Convert.ToDecimal(reader["ACCTAXRATE"]);
data.INVOICESETTLENO = Convert.ToString(reader["INVOICESETTLENO"]);
data.BILLNO = Convert.ToString(reader["BILLNO"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<TruckChfee_do_detail> GetTruckBodyList(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.BSNO,B.TRANSTYPE,B.TRANSSTATUS,B.CUSTOMERNAME,B.CUSTNO,B.CONTRACTNO,B.ORDERNO,B.BSDATE,B.MBLNO,B.CNTRTOTAL,");
strSql.Append("B.ETD,B.ETA,B.OP,B.SALE,B.CUSTSERVICE,B.CUSTATTN,B.CUSTTEL,B.CONSIGNEENAME,B.CONSIGNEEATTN,B.CONSIGNEETEL,B.CONSIGNEEADDR,");
strSql.Append("B.PORTLOAD,B.PORTDISCHARGE,B.GOODSNAME,B.KGS,B.NETWEIGHT,B.CBM,B.PKGS,B.KINDPKGS,B.TRUCKER,B.TRUCKNO");
strSql.Append(",f.Remark Remark,f.INPUTMODE ");
strSql.Append(" FROM ch_fee_do c");
strSql.Append(" left join v_op_truck_bulk b on (b.bsno=c.bsno)");
strSql.Append(" left join ch_fee f on (f.gid=c.feeid) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where (c.ISDELETED=0 or c.ISDELETED IS NULL) and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by b.MBLNO");
}
return TruckBodySetData(strSql);
}
private static List<TruckChfee_do_detail> TruckBodySetData(StringBuilder strSql)
{
var headList = new List<TruckChfee_do_detail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
TruckChfee_do_detail data = new TruckChfee_do_detail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.FEEDOID = Convert.ToString(reader["GID"]);
data.FEEID = Convert.ToString(reader["FEEID"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.FEEOBJNAME = Convert.ToString(reader["FEEOBJNAME"]);
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
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.ORIGSTLAMOUNT = Convert.ToDecimal(reader["ORIGSTLAMOUNT"]);
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToString(reader["ETD"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.SALE = Convert.ToString(reader["SALE"]);
if (reader["ORIGEXCHANGERATE"] != DBNull.Value)
data.ORIGEXCHANGERATE = Convert.ToDecimal(reader["ORIGEXCHANGERATE"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.TRUCKER = Convert.ToString(reader["TRUCKER"]);
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToInt32(reader["PKGS"]);
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);
if (reader["NETWEIGHT"] != DBNull.Value)
data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#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 duino, string userid, string usercode, string orgcode, string sort)
{
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var INVISNOTSTL = MsSysParamSetDAL.GetData("PARAMNAME='INVISNOTSTL'");
var strSql = new StringBuilder();
if (!string.IsNullOrEmpty(duino))
{
strSql.Append("SELECT ");
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
strSql.Append(",b.CUSTOMERNAME,b.CUSTOMNO");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
strSql.Append(",b.DOC,b.SALE");
strSql.Append(",f.GID AS CH_ID,f.FeeType");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
strSql.Append(",f.feeName,f.customerName as FeeObjName,f.amount,f.currency,f.exChangerate,f.AccTaxRate");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append(",f.amount-isnull(f.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount");
}
else
strSql.Append(",f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount");
strSql.Append(",d.DEBITAMOUNT from ch_fee f ");
strSql.Append(" left join v_op_bill b on (b.bsno=f.bsno) ");
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE 1=1 AND D.DUINO='" + duino + "' AND ISNULL(D.INVNO,'')='' ");
}
else
{
strSql.Append("SELECT ");
strSql.Append("b.BSNO,b.OPLB,b.OPLBNAME,b.BSSTATUS,b.ACCDATE,b.MBLNO,b.HBLNO,b.CUSTNO");
strSql.Append(",b.CUSTOMERNAME,b.CUSTOMNO");
strSql.Append(",b.VESSEL,b.VOYNO,b.ETD,b.PORTLOAD");
strSql.Append(",b.PORTDISCHARGE,b.INPUTBY,b.OP,b.CUSTSERVICE");
strSql.Append(",b.DOC,b.SALE");
strSql.Append(",f.GID AS CH_ID,f.FeeType");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
strSql.Append(",f.feeName,f.customerName as FeeObjName,f.amount,f.currency,f.exChangerate,f.AccTaxRate");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append(",f.amount-isnull(f.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount");
}
else
strSql.Append(",f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount");
strSql.Append(",0 DEBITAMOUNT from ch_fee f ");
strSql.Append(" left join v_op_bill b on (b.bsno=f.bsno) WHERE 1=1 ");
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" AND " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by b.BsNo");
}
return SetFeeData(strSql,duino);
}
private static List<BillChfeeDetail> SetFeeData(StringBuilder strSql,string duino)
{
var headList = new List<BillChfeeDetail>();
Database db = DatabaseFactory.CreateDatabase();
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"]);
if (reader["AccTaxRate"]!=DBNull.Value)
data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]);
if (reader["DEBITAMOUNT"] != DBNull.Value)
data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (data.Amount >= 0)
{
if (data.BalAmount > data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
}
else
{
if (data.BalAmount < data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
}
data.BalAmount = balamount;
data.StlAmount = balamount;
}
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 添加列表
static public List<BillCustDetail> GetAddBillList(int start, int limit, string strCondition, string duino, string userid, string usercode, string orgcode, string sort)
{
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPFEERANGE'");
if (PAYUSEFEERANGE.PARAMVALUE == "1")
{
var rangstrfee = GetRangAddFeeDAStr(userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstrfee))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstrfee;
}
else
{
strCondition = rangstrfee;
}
}
}
var modPSFEE = MsBaseInfoDAL.GetUserModuleEnable("modPSFEE", userid);
if (!modPSFEE)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
else
{
strCondition = " f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
}
var INVISNOTSTL = MsSysParamSetDAL.GetData("PARAMNAME='INVISNOTSTL'");
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").Replace("COMPANYID", "b.SALECORPID").Replace("COMPANYNAME", "b.SALECORPID");
// strSql.Append(" order by " + sortstring);
//}
//else
//{
// strSql.Append(" order by f.BsNo");
//}
//strSql.Append(@") as num , ");
strSql.Append("SELECT f.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.INVNO");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.SALECORPID,(SELECT [NAME] from [COMPANY] WHERE GID=b.SALECORPID) SALECORP");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",G.RMBDR RMBDR,");
strSql.Append("G.RMBCR RMBCR,");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.amount-isnull(f.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
}
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
}
strSql.Append("G.USDDR,");
strSql.Append("G.USDCR,");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.amount-isnull(f.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
}
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
}
strSql.Append(" G.OTDR,");
strSql.Append(" G.OTCR,");
if (INVISNOTSTL.PARAMVALUE == "1")
{
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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
}
else
{
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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
}
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,");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.amount-isnull(f.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALRMBCR,");
}
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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,");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.amount-isnull(f.SETTLEMENT,0)-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) ELSE 0 END)ELSE 0 END),0) AS BALUSDCR,");
}
else
{
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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,");
if (INVISNOTSTL.PARAMVALUE == "1")
{
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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
}
else
{
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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
}
if (!string.IsNullOrEmpty(duino))
{
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN d.DEBITAMOUNT ELSE 0 END) ELSE 0 END),0) AS DUIRMBDR");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN d.DEBITAMOUNT ELSE 0 END)ELSE 0 END),0) AS DUIRMBCR");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN d.DEBITAMOUNT ELSE 0 END)ELSE 0 END),0) AS DUIUSDDR");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN d.DEBITAMOUNT ELSE 0 END)ELSE 0 END),0) AS DUIUSDCR");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE d.DEBITAMOUNT END) END) ELSE 0 END),0) AS DUIOTDR");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'USD' THEN 0 ELSE (CASE CURRENCY WHEN 'RMB' THEN 0 ELSE d.DEBITAMOUNT END) END) ELSE 0 END),0) AS DUIOTCR");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN v_op_gain_cust_sum g ON (g.BSNO=B.BSNO and g.CUSTOMERNAME=f.CUSTOMERNAME) ");
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='" + duino + "' AND ISNULL(D.INVNO,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
}
else
{
strSql.Append(",0 AS DUIRMBDR");
strSql.Append(",0 AS DUIRMBCR");
strSql.Append(",0 AS DUIUSDDR");
strSql.Append(",0 AS DUIUSDCR");
strSql.Append(",0 AS DUIOTDR");
strSql.Append(",0 AS DUIOTCR");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" LEFT JOIN v_op_gain_cust_sum g ON (g.BSNO=B.BSNO and g.CUSTOMERNAME=f.CUSTOMERNAME) ");
strSql.Append(" where f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
}
var InvAppFeeStatus = MsSysParamSetDAL.GetData("PARAMNAME='InvAppFeeStatus'");
if (InvAppFeeStatus.PARAMVALUE != "2")
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
else
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append(" and ISNULL(f.AMOUNT,0)<>ISNULL(f.SETTLEMENT,0) ");
}
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
if (isopen == false)
{
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
}
strSql.Append("GROUP BY f.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.INVNO");
strSql.Append(",b.DOC,b.SALE,b.ENTERP,b.CUSTOMNO,b.SALECORPID,f.CUSTOMERNAME");
strSql.Append(",G.RMBDR,G.RMBCR,G.USDDR,G.USDCR,G.OTDR,G.OTCR");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
sortstring = sortstring.Replace("FEEOBJNAME", "F.CUSTOMERNAME").Replace("COMPANYID", "b.SALECORPID").Replace("COMPANYNAME", "b.SALECORPID");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by f.BsNo");
}
//strSql.Append( @")as t ");
//strSql.Append(string.Format("where t.num>={0} and t.num<={1} ", start, start + limit)); //
return SetAddBillData(strSql,duino);
}
public static int getAddBillTotalCount(string strCondition, string duino, string userid, string usercode, string companyid)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPFEERANGE'");
if (PAYUSEFEERANGE.PARAMVALUE == "1")
{
var rangstrfee = GetRangAddFeeDAStr(userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstrfee))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstrfee;
}
else
{
strCondition = rangstrfee;
}
}
}
var modPSFEE = MsBaseInfoDAL.GetUserModuleEnable("modPSFEE", userid);
if (!modPSFEE)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
else
{
strCondition = " f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
}
StringBuilder strSql = new StringBuilder();
if (!string.IsNullOrEmpty(duino))
{
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='" + duino + "' AND ISNULL(D.INVNO,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
}
else
{
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
}
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append("GROUP BY b.BSNO,f.CUSTOMERNAME) AS T ");
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
private static List<BillCustDetail> SetAddBillData(StringBuilder strSql,string duino)
{
var headList = new List<BillCustDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
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.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
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"]);
if (reader["BSSTATUS"] != DBNull.Value)
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
data.FEEOBJNAME = Convert.ToString(reader["CUSTNAME"]);
data.COMPANYID = Convert.ToString(reader["SALECORPID"]);
data.COMPANYNAME = Convert.ToString(reader["SALECORP"]);
data.INVNO = Convert.ToString(reader["INVNO"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDrAmount = Convert.ToDecimal(reader["RMBDR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.RMBDrBalAmount = Convert.ToDecimal(reader["BALRMBDR"]) - Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.RMBDrDoAmount = Convert.ToDecimal(reader["BALRMBDR"]) - Convert.ToDecimal(reader["BALRMBCR"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (reader["DUIRMBDR"] != DBNull.Value)
data.RMBDrDoAmount = Convert.ToDecimal(reader["DUIRMBDR"]);
if (data.RMBDrAmount > 0)
{
if (data.RMBDrBalAmount > data.RMBDrDoAmount) balamount = data.RMBDrDoAmount; else balamount = data.RMBDrBalAmount;
}
else
{
if (data.RMBDrBalAmount < data.RMBDrDoAmount) balamount = data.RMBDrDoAmount; else balamount = data.RMBDrBalAmount;
}
data.RMBDrBalAmount = balamount;
data.RMBDrDoAmount = balamount;
}
if (reader["RMBCR"] != DBNull.Value)
data.RMBCrAmount = Convert.ToDecimal(reader["RMBCR"]);
if (reader["BALRMBCR"] != DBNull.Value)
data.RMBCrBalAmount = Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["BALRMBCR"] != DBNull.Value)
data.RMBCrDoAmount = Convert.ToDecimal(reader["BALRMBCR"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (reader["DUIRMBCR"] != DBNull.Value)
data.RMBCrDoAmount = Convert.ToDecimal(reader["DUIRMBCR"]);
if (data.RMBCrAmount > 0)
{
if (data.RMBCrBalAmount > data.RMBCrDoAmount) balamount = data.RMBCrDoAmount; else balamount = data.RMBCrBalAmount;
}
else
{
if (data.RMBCrBalAmount < data.RMBCrDoAmount) balamount = data.RMBCrDoAmount; else balamount = data.RMBCrBalAmount;
}
data.RMBCrBalAmount = balamount;
data.RMBCrDoAmount = balamount;
}
if (reader["USDDR"] != DBNull.Value)
data.USDDrAmount = Convert.ToDecimal(reader["USDDR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.USDDrBalAmount = Convert.ToDecimal(reader["BALUSDDR"]) - Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.USDDrDoAmount = Convert.ToDecimal(reader["BALUSDDR"]) - Convert.ToDecimal(reader["BALUSDCR"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (reader["DUIUSDDR"] != DBNull.Value)
data.USDDrDoAmount = Convert.ToDecimal(reader["DUIUSDDR"]);
if (data.USDDrAmount > 0)
{
if (data.USDDrBalAmount > data.USDDrDoAmount) balamount = data.USDDrDoAmount; else balamount = data.USDDrBalAmount;
}
else
{
if (data.USDDrBalAmount < data.USDDrDoAmount) balamount = data.USDDrDoAmount; else balamount = data.USDDrBalAmount;
}
data.USDDrBalAmount = balamount;
data.USDDrDoAmount = balamount;
}
if (reader["USDCR"] != DBNull.Value)
data.USDCrAmount = Convert.ToDecimal(reader["USDCR"]);
if (reader["BALUSDCR"] != DBNull.Value)
data.USDCrBalAmount = Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["BALUSDCR"] != DBNull.Value)
data.USDCrDoAmount = Convert.ToDecimal(reader["BALUSDCR"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (reader["DUIUSDCR"] != DBNull.Value)
data.USDCrDoAmount = Convert.ToDecimal(reader["DUIUSDCR"]);
if (data.USDCrAmount > 0)
{
if (data.USDCrBalAmount > data.USDCrDoAmount) balamount = data.USDCrDoAmount; else balamount = data.USDCrBalAmount;
}
else
{
if (data.USDCrBalAmount < data.USDCrDoAmount) balamount = data.USDCrDoAmount; else balamount = data.USDCrBalAmount;
}
data.USDCrBalAmount = balamount;
data.USDCrDoAmount = balamount;
}
if (reader["OTDR"] != DBNull.Value)
data.OTDrAmount = Convert.ToDecimal(reader["OTDR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.OTDrBalAmount = Convert.ToDecimal(reader["BALOTDR"]) - Convert.ToDecimal(reader["BALOTCR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.OTDrDoAmount = Convert.ToDecimal(reader["BALOTDR"]) - Convert.ToDecimal(reader["BALOTCR"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (reader["DUIOTDR"] != DBNull.Value)
data.OTDrDoAmount = Convert.ToDecimal(reader["DUIOTDR"]);
if (data.OTDrAmount > 0)
{
if (data.OTDrBalAmount > data.OTDrDoAmount) balamount = data.OTDrDoAmount; else balamount = data.OTDrBalAmount;
}
else
{
if (data.OTDrBalAmount < data.OTDrDoAmount) balamount = data.OTDrDoAmount; else balamount = data.OTDrBalAmount;
}
data.OTDrBalAmount = balamount;
data.OTDrDoAmount = balamount;
}
if (reader["OTCR"] != DBNull.Value)
data.OTCrAmount = Convert.ToDecimal(reader["OTCR"]);
if (reader["BALOTCR"] != DBNull.Value)
data.OTCrBalAmount = Convert.ToDecimal(reader["BALOTCR"]);
if (reader["BALOTCR"] != DBNull.Value)
data.OTCrDoAmount = Convert.ToDecimal(reader["BALOTCR"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (reader["DUIOTCR"] != DBNull.Value)
data.OTCrDoAmount = Convert.ToDecimal(reader["DUIOTCR"]);
if (data.OTCrAmount > 0)
{
if (data.OTCrBalAmount > data.OTCrDoAmount) balamount = data.OTCrDoAmount; else balamount = data.OTCrBalAmount;
}
else
{
if (data.OTCrBalAmount < data.OTCrDoAmount) balamount = data.OTCrDoAmount; else balamount = data.OTCrBalAmount;
}
data.OTCrBalAmount = balamount;
data.OTCrDoAmount = balamount;
}
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<BillTruckCustDetail> GetAddTruckBillList(int start, int limit, string strCondition, string userid, string usercode, string orgcode, string sort)
{
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var 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").Replace("COMPANYID", "b.SALECORPID").Replace("COMPANYNAME", "b.SALECORPID");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by f.BsNo");
}
strSql.Append(@") as num , ");
strSql.Append("f.BSNO,b.TRANSTYPE,b.TRANSSTATUS,b.CUSTOMERNAME,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.BSDATE,");
strSql.Append("b.ETD,b.ETA,b.OP,b.SALE,b.CUSTSERVICE,b.CUSTATTN,b.CUSTTEL,b.CONSIGNEENAME,b.CONSIGNEEATTN,b.CONSIGNEETEL,b.CONSIGNEEADDR,");
strSql.Append("b.PORTLOAD,b.PORTDISCHARGE,b.GOODSNAME,b.KGS,b.NETWEIGHT,b.CBM,b.PKGS,b.KINDPKGS,b.TRUCKER,b.TRUCKNO,b.MBLNO");
strSql.Append(",F.CUSTOMERNAME AS CUSTNAME ");
strSql.Append(",isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBDR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 2 THEN (CASE CURRENCY WHEN 'RMB' THEN ISNULL(AMOUNT,0) ELSE 0 END) ELSE 0 END),0) AS RMBCR,");
strSql.Append("isnull(SUM(CASE FEETYPE WHEN 1 THEN (CASE CURRENCY WHEN 'RMB' THEN f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) END) END) ELSE 0 END),0) AS BALOTCR");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN v_op_truck_bulk B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var INVISNOTSTL = MsSysParamSetDAL.GetData("PARAMNAME='INVISNOTSTL'");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append(" and ISNULL(f.AMOUNT,0)<>ISNULL(f.SETTLEMENT,0) ");
}
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
if (isopen == false)
{
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
}
strSql.Append("GROUP BY f.BSNO,b.TRANSTYPE,b.TRANSSTATUS,b.CUSTOMERNAME,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.BSDATE");
strSql.Append(",b.ETD,b.ETA,b.OP,b.SALE,b.CUSTSERVICE,b.CUSTATTN,b.CUSTTEL,b.CONSIGNEENAME,b.CONSIGNEEATTN,b.CONSIGNEETEL,b.CONSIGNEEADDR");
strSql.Append(",b.PORTLOAD,b.PORTDISCHARGE,b.GOODSNAME,b.KGS,b.NETWEIGHT,b.CBM,b.PKGS,b.KINDPKGS,b.TRUCKER,b.TRUCKNO,b.MBLNO,f.CUSTOMERNAME");
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} ", start, start + limit)); //
return SetAddTruckBillData(strSql);
}
public static int getAddTruckBillTotalCount(string strCondition, string userid, string usercode, string companyid)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT COUNT(*) FROM (select b.BSNO,f.CUSTOMERNAME ");
strSql.Append(" FROM CH_FEE f ");
strSql.Append(" INNER JOIN v_op_truck_bulk B ON (F.BSNO=B.BSNO) ");
strSql.Append(" where f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append("GROUP BY b.BSNO,f.CUSTOMERNAME) AS T ");
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
private static List<BillTruckCustDetail> SetAddTruckBillData(StringBuilder strSql)
{
var headList = new List<BillTruckCustDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
BillTruckCustDetail data = new BillTruckCustDetail();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");
if (reader["ETA"] != DBNull.Value)
data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd");
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]);
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.TRUCKER = Convert.ToString(reader["TRUCKER"]);
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.OP = Convert.ToString(reader["OP"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.FEEOBJNAME= Convert.ToString(reader["CUSTNAME"]);
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToInt32(reader["PKGS"]);
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);
if (reader["NETWEIGHT"] != DBNull.Value)
data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]);
if (reader["RMBDR"] != DBNull.Value)
data.RMBDrAmount = Convert.ToDecimal(reader["RMBDR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.RMBDrBalAmount = Convert.ToDecimal(reader["BALRMBDR"]) - Convert.ToDecimal(reader["BALRMBCR"]);
if (reader["BALRMBDR"] != DBNull.Value)
data.RMBDrDoAmount = Convert.ToDecimal(reader["BALRMBDR"]) - Convert.ToDecimal(reader["BALRMBCR"]);
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"]) - Convert.ToDecimal(reader["BALUSDCR"]);
if (reader["BALUSDDR"] != DBNull.Value)
data.USDDrDoAmount = Convert.ToDecimal(reader["BALUSDDR"]) - Convert.ToDecimal(reader["BALUSDCR"]);
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"]) - Convert.ToDecimal(reader["BALOTCR"]);
if (reader["BALOTDR"] != DBNull.Value)
data.OTDrDoAmount = Convert.ToDecimal(reader["BALOTDR"]) - Convert.ToDecimal(reader["BALOTCR"]);
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"]);
#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 modPSFEE = MsBaseInfoDAL.GetUserModuleEnable("modPSFEE", userid);
if (!modPSFEE)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
else
{
strCondition = " f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
}
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.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,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);
}
//static public List<ChFeeExrate> GetFeeNowInvCurrList(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;
}
#region 费用列表明细
static public List<ChFeeDetail> GetFeeDetailList(string strCondition,string duino,string userid, string usercode, string orgcode,string sort=null)
{
var strSql = new StringBuilder();
var PAYUSEFEERANGE = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPFEERANGE'");
if (PAYUSEFEERANGE.PARAMVALUE == "1")
{
var rangstrfee = GetRangAddFeeDAStr(userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstrfee))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstrfee;
}
else
{
strCondition = rangstrfee;
}
}
}
var modPSFEE = MsBaseInfoDAL.GetUserModuleEnable("modPSFEE", userid);
if (!modPSFEE)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
else
{
strCondition = " f.FEENAME<>'P/S' AND F.FEENAME<>'HP/S' ";
}
}
if (!string.IsNullOrEmpty(duino))
{
strSql.Append("SELECT * from (SELECT ");
strSql.Append("f.BSNO,f.GID AS CH_ID,FeeType");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount,f.currency,f.exChangerate,f.AccTaxRate,f.remark");
strSql.Append(",(select ShowName from [user] where GID=f.EnteroPerator) as OpName");
strSql.Append(",f.INPUTMODE,f.UNIT,f.UNITPRICE,f.QUANTITY,d.DEBITAMOUNT from ch_fee f ");
strSql.Append(" left join ch_dui_detail d on (d.CH_ID=f.GID) WHERE D.DUINO='" + duino + "' AND ISNULL(D.INVNO,'')='' ");
strSql.Append(" and f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
}
else
{
strSql.Append("SELECT * from (SELECT ");
strSql.Append("f.BSNO,f.GID AS CH_ID,FeeType");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=f.FeeType) as FeeType_Ref");
strSql.Append(",f.feeName,f.customerName,f.amount,f.amount-isnull(f.INVOICE,0)-isnull(f.ORDERINVOICE,0)+isnull(f.ORDERINVSETTLEMENT,0) as balamount,f.currency,f.exChangerate,f.AccTaxRate,f.remark");
strSql.Append(",(select ShowName from [user] where GID=f.EnteroPerator) as OpName");
strSql.Append(",f.INPUTMODE,f.UNIT,f.UNITPRICE,f.QUANTITY,0 DEBITAMOUNT from ch_fee f ");
strSql.Append(" where f.ISINVOICE<>1 and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) and ISNULL(f.INVLINKGID,'')='' ");
}
var InvAppFeeStatus = MsSysParamSetDAL.GetData("PARAMNAME='InvAppFeeStatus'");
if (InvAppFeeStatus.PARAMVALUE != "2")
strSql.Append(" and f.FEESTATUS IN (0,8,9) ");
else
strSql.Append(" and f.FEESTATUS IN (2,0,8,9) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" AND " + strCondition);
}
var INVISNOTSTL = MsSysParamSetDAL.GetData("PARAMNAME='INVISNOTSTL'");
if (INVISNOTSTL.PARAMVALUE == "1")
{
strSql.Append(" and ISNULL(f.AMOUNT,0)<>ISNULL(f.SETTLEMENT,0) ");
}
var isopen = MsBaseInfoDAL.GetUserModuleEnable("modFeenotopen", userid);
if (isopen == false)
{
strSql.Append(" AND ( f.ENTEROPERATOR='" + userid + "' OR ( f.ENTEROPERATOR<>'" + userid + "' AND ISNULL(f.ISOPEN,0)=0)) ");
}
strSql.Append(" ) AS VF ");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by feeName");
}
return SetFeeDetailData(strSql,duino);
}
private static List<ChFeeDetail> SetFeeDetailData(StringBuilder strSql,string duino)
{
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"]);
if (reader["DEBITAMOUNT"] != DBNull.Value)
data.DEBITAMOUNT = Convert.ToDecimal(reader["DEBITAMOUNT"]);
if (!string.IsNullOrEmpty(duino))
{
decimal balamount = 0;
if (data.Amount >= 0)
{
if (data.BalAmount > data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
}
else
{
if (data.BalAmount < data.DEBITAMOUNT) balamount = data.DEBITAMOUNT; else balamount = data.BalAmount;
}
data.BalAmount = balamount;
data.StlAmount = balamount;
}
else
{
if (reader["BalAmount"] != DBNull.Value)
data.StlAmount = Convert.ToDecimal(reader["BalAmount"]);
}
data.Currency = Convert.ToString(reader["Currency"]);
if (reader["exChangerate"] != DBNull.Value)
data.ExChangerate = Convert.ToDecimal(reader["exChangerate"]);
if (reader["AccTaxRate"] != DBNull.Value)
data.AccTaxRate = Convert.ToDecimal(reader["AccTaxRate"]);
data.INPUTMODE = Convert.ToString(reader["INPUTMODE"]);
data.UNIT = Convert.ToString(reader["UNIT"]);
if (reader["UNITPRICE"] != DBNull.Value)
data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]);
if (reader["QUANTITY"] != DBNull.Value)
data.QUANTITY = Convert.ToDecimal(reader["QUANTITY"]);
data.Remark= Convert.ToString(reader["remark"]);
data.INPUTBY = Convert.ToString(reader["OpName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 发票明细保存,删除
public static DBResult SaveInvDetail(string BsNo, List<ChInvoiceDetail> bodyList)
{
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_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values (@GID,@PID,@SerialNo,@GOODSNAME,@SPEC,@UNIT,@PKGS,@TAXPRICE,@PRICE,@AMOUNT,@TAXRATE,@TAX,@Remark,@GOODCODE) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update ch_fee_invoicedetail set SerialNo=@SerialNo,GOODSNAME=@GOODSNAME,SPEC=@SPEC,UNIT=@UNIT,PKGS=@PKGS,TAXPRICE=@TAXPRICE
,PRICE=@PRICE,AMOUNT=@AMOUNT,TAXRATE=@TAXRATE,Remark=@Remark,TAX=@TAX,GOODCODE=@GOODCODE where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.PID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@PID", DbType.String, BsNo);
db.AddInParameter(cmdInsert, "@SerialNo", DbType.Int32, enumValue.SERIALNO);
db.AddInParameter(cmdInsert, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.AddInParameter(cmdInsert, "@SPEC", DbType.String, enumValue.SPEC);
db.AddInParameter(cmdInsert, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdInsert, "@PKGS", DbType.Decimal, enumValue.PKGS);
db.AddInParameter(cmdInsert, "@TAXPRICE", DbType.Decimal, enumValue.TAXPRICE);
db.AddInParameter(cmdInsert, "@PRICE", DbType.Decimal, enumValue.PRICE);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT);
db.AddInParameter(cmdInsert, "@TAXRATE", DbType.Decimal, enumValue.TAXRATE);
db.AddInParameter(cmdInsert, "@TAX", DbType.Decimal, enumValue.TAX);
db.AddInParameter(cmdInsert, "@Remark", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@GOODCODE", DbType.String, enumValue.GOODCODE);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@SerialNo", DbType.Int32, enumValue.SERIALNO);
db.AddInParameter(cmdUpdate, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.AddInParameter(cmdUpdate, "@SPEC", DbType.String, enumValue.SPEC);
db.AddInParameter(cmdUpdate, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdUpdate, "@PKGS", DbType.Decimal, enumValue.PKGS);
db.AddInParameter(cmdUpdate, "@TAXPRICE", DbType.Decimal, enumValue.TAXPRICE);
db.AddInParameter(cmdUpdate, "@PRICE", DbType.Decimal, enumValue.PRICE);
db.AddInParameter(cmdUpdate, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT);
db.AddInParameter(cmdUpdate, "@TAXRATE", DbType.Decimal, enumValue.TAXRATE);
db.AddInParameter(cmdUpdate, "@TAX", DbType.Decimal, enumValue.TAX);
db.AddInParameter(cmdUpdate, "@Remark", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdate, "@GOODCODE", DbType.String, enumValue.GOODCODE);
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 DelInvDetail(List<ChInvoiceDetail> bodyList)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"delete from ch_fee_invoicedetail where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功" + result.Message;
return result;
}
#endregion
public static DBResult AddDetail(string billno, string duino, List<BillChfeeDetail> bodyList, string curr, string companyid,bool isList,string GID,ChInvoiceapplication headdata)
{
var result = new DBResult();
decimal ttlamount = headdata.APPLYAMOUNT;
bool INVAPPMAX = false;
var INVAPPMAXPARAM = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPMAX'");
if (INVAPPMAXPARAM.PARAMVALUE == "1")
{
INVAPPMAX = true;
}
if (ttlamount >= 99999 && INVAPPMAX)
{
result.Success = false;
result.Message = "单张发票申请不能超过100000";
return result;
}
bool ischaoe = false;
var defGOOD = MsCodeGoodInvDAL.GetData(" ISDEF='1' and (DEFCURR='' or DEFCURR='"+headdata.RECVCURR+"')");
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 ORDERINVOICE=ISNULL(ORDERINVOICE,0)+@ORDERINVOICE WHERE GID=@GID ");
var cmdInsertInv =
db.GetSqlStringCommand(
@"insert into ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values (@GID,@PID,@SerialNo,@GOODSNAME,@SPEC,@UNIT,@PKGS,@TAXPRICE,@PRICE,@AMOUNT,@TAXRATE,@TAX,@Remark,@GOODCODE) ");
var cmdUpdateInv =
db.GetSqlStringCommand(
@"update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID ");
decimal amtttl = 0;
decimal acctaxrate =0;
decimal doamount = 0;
decimal StlAmount = 0;
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (ttlamount >= 99999 && INVAPPMAX) break;
if ((ttlamount + Math.Round(enumValue.DoAmount, 2, MidpointRounding.AwayFromZero)) >= 99999 && INVAPPMAX)
{
StlAmount = 0;
doamount = 0;
ischaoe = true;
//doamount = 99999-ttlamount;
//StlAmount = Math.Round(enumValue.StlAmount*((99999 - ttlamount)/doamount),2, MidpointRounding.AwayFromZero);
}
else
{
doamount = Math.Round(enumValue.DoAmount, 2, MidpointRounding.AwayFromZero);
StlAmount = enumValue.StlAmount;
}
ttlamount = ttlamount + doamount;
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);
else
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, curr);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, doamount);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 6);
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, StlAmount);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, duino);
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, "@ORDERINVOICE", DbType.Decimal, StlAmount);
db.ExecuteNonQuery(cmdUpdate, tran);
if (!string.IsNullOrEmpty(duino))
{
var cmdUpdateDui =
db.GetSqlStringCommand(
@"update ch_dui_detail set INVNO=@PAYNO WHERE CH_ID=@GID AND DUINO=@DUINO");
cmdUpdateDui.Parameters.Clear();
db.AddInParameter(cmdUpdateDui, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdateDui, "@PAYNO", DbType.String, billno);
db.AddInParameter(cmdUpdateDui, "@DUINO", DbType.String, duino);
db.ExecuteNonQuery(cmdUpdateDui, tran);
}
if (isList&& doamount!=0)
{
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, 1);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, doamount);
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, headdata.RATE);
if (headdata.RATE == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, doamount);
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, doamount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(doamount / (1 + headdata.RATE / 100) * (headdata.RATE / 100), 2, MidpointRounding.AwayFromZero);
var amount = doamount - tax;
// var amount = Math.Round(enumValue.DoAmount / (1 + enumValue.AccTaxRate / 100),2);
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, "");
db.ExecuteNonQuery(cmdInsertInv, tran);
}
if (enumValue.FeeType == 2)
amtttl = amtttl - doamount;
else
amtttl = amtttl + doamount;
}
}
acctaxrate = headdata.RATE;
if (!isList&& ttlamount!=0)
{
var dataList = GetDetailList(" PID='" + GID + "'");
if (dataList.Count != 0)
{
var invlist = dataList[0];
cmdUpdateInv.Parameters.Clear();
db.AddInParameter(cmdUpdateInv, "@GID", DbType.String, invlist.GID);
if (acctaxrate == 0)
{
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, Math.Round(invlist.AMOUNT + amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, 0);
}
else
{
amtttl = amtttl + (invlist.TAXPRICE*invlist.PKGS);
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, tax);
//var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2);
//var amount = amtttl - tax;
//db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, Math.Round(invlist.AMOUNT + amount, 2));
//db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round(((invlist.AMOUNT + amount) / invlist.PKGS) * (1 + acctaxrate / 100), 2));
//db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amount) / invlist.PKGS, 2));
//db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, invlist.TAX + tax);
}
db.ExecuteNonQuery(cmdUpdateInv, tran);
}
else
{
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
if (defGOOD.GOODNAME == "")
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, "代理运杂费");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
}
else
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, defGOOD.GID);
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, defGOOD.UNIT);
}
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, defGOOD.SPEC);
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, 1);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, acctaxrate);
if (acctaxrate == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amount, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(amount, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, defGOOD.GOODCODE);
db.ExecuteNonQuery(cmdInsertInv, tran);
}
}
if (ischaoe)
{
result.Success = false;
result.Message = "单张发票不能超过十万元";
}
else
{
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 = "保存成功" + result.Message;
return result;
}
public static DBResult AddBill(string billno, string duino, string billcust, string billcurr, string feesql, List<ChFeeExrate> exratelist, string companyid, bool isList, string GID,ChInvoiceapplication headdata,bool custgroup = false,string userid="")
{
var result = new DBResult();
bool INVAPPMAX = false;
decimal ttlamount = headdata.APPLYAMOUNT;
var INVAPPMAXPARAM = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPMAX'");
if (INVAPPMAXPARAM.PARAMVALUE == "1")
{
INVAPPMAX = true;
}
if (ttlamount >= 99999 && INVAPPMAX)
{
result.Success = false;
result.Message = "单张发票申请不能超过100000";
return result;
}
Database db = DatabaseFactory.CreateDatabase();
decimal amtttl = 0;
decimal acctaxrate = 0;
bool adddo = true;
bool ischaoe = false;
var FEENOAUDITCANTSHENINV = MsSysParamSetDAL.GetData("PARAMNAME='FEENOAUDITCANTSHENINV'");
List<DSWeb.MvcShipping.Models.MsOpBill.MsOpBill> billnoinvlist = null;
var defGOOD = MsCodeGoodInvDAL.GetData(" ISDEF='1' and (DEFCURR='' or DEFCURR='" + headdata.RECVCURR + "')");
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (!custgroup)
feesql = feesql + " AND CUSTOMERNAME='" + billcust + "'";
var feelist = GetFeeDetailList(feesql,duino,userid,"", companyid);
if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1")
{
billnoinvlist = MsOpBillDAL.GetDataList(" BSNO IN (select DISTINCT BSNO from ch_fee (NOLOCK) where FEETYPE=1 and (FEESTATUS=1 OR FEESTATUS=2 ) AND BSNO IN (SELECT DISTINCT BSNO FROM CH_FEE f WHERE f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) AND " + feesql + " ))");
}
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 ORDERINVOICE=ISNULL(ORDERINVOICE,0)+@ORDERINVOICE WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-ISNULL(ORDERINVOICE,0))-@ORDERINVOICE)>=0)
OR (AMOUNT<0 AND ((AMOUNT-ISNULL(ORDERINVOICE,0))-@ORDERINVOICE)<=0))");
var cmdInsertInv =
db.GetSqlStringCommand(
@"insert into ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values (@GID,@PID,@SerialNo,@GOODSNAME,@SPEC,@UNIT,@PKGS,@TAXPRICE,@PRICE,@AMOUNT,@TAXRATE,@TAX,@Remark,@GOODCODE) ");
var cmdUpdateInv =
db.GetSqlStringCommand(
@"update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID ");
decimal doamount = 0;
decimal StlAmount = 0;
decimal ORIGAMOUNT = 0;
decimal UExrate = 0;
if (feelist != null)
{
foreach (var enumValue in feelist)
{
//if (ttlamount >= 99999&& INVAPPMAX) break;
if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1")
{
if (billnoinvlist != null)
{
foreach (var billnoinv in billnoinvlist)
{
if (enumValue.BSNO == billnoinv.BSNO) adddo = false;
}
}
}
if (adddo)
{
decimal feettl = 0;
decimal otamount = 0;
if (billcurr==""||billcurr == enumValue.Currency)
{
feettl = enumValue.StlAmount;
if (enumValue.FeeType == 2)
otamount = - enumValue.StlAmount;
else
otamount = enumValue.StlAmount;
if ((ttlamount + Math.Round(otamount, 2, MidpointRounding.AwayFromZero)) >= 100000 && INVAPPMAX)
{
feettl = 0;
doamount = 0;
ischaoe = true;
}
else {
doamount = feettl;
if (enumValue.FeeType == 2)
amtttl = amtttl - enumValue.StlAmount;
else
amtttl = amtttl + enumValue.StlAmount;
ttlamount = ttlamount + otamount;
}
}
else {
UExrate = GetExrate(enumValue.Currency, exratelist);
if (enumValue.FeeType == 2)
otamount = - enumValue.StlAmount * UExrate;
else
otamount = enumValue.StlAmount * UExrate;
feettl = enumValue.StlAmount * UExrate;
feettl = Math.Round(feettl, 2, MidpointRounding.AwayFromZero);
if ((ttlamount + Math.Round(otamount, 2, MidpointRounding.AwayFromZero)) >= 100000 && INVAPPMAX)
{
feettl = 0;
doamount = 0;
ischaoe = true;
//feettl = 99999 - ttlamount;
//doamount = enumValue.StlAmount * (feettl /(enumValue.StlAmount * UExrate));
//amtttl = amtttl + feettl;
//ttlamount = ttlamount + feettl;
}
else {
doamount = enumValue.StlAmount;
if (enumValue.FeeType == 2)
amtttl = amtttl - feettl;
else
amtttl = amtttl + feettl;
ttlamount = ttlamount + otamount;
}
}
if (feettl != 0)
{
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=="")
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency);
else
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, billcurr);
if (billcurr==""||billcurr == enumValue.Currency)
{
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1);
}
else
{
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero));
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, doamount);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 6);
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, duino);
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, doamount);
db.ExecuteNonQuery(cmdUpdate, tran);
if (isList)
{
var defGOODFEELIST = MsCodeGoodInvDAL.GetData(" GOODNAME='代理" + enumValue.FeeName + "'");
var quantity = enumValue.QUANTITY;
if (quantity == 0) quantity = 1;
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
if (defGOODFEELIST.GOODNAME == "")
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, "代理运杂费");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
}
else
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, defGOODFEELIST.GID);
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, defGOODFEELIST.UNIT);
}
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, defGOODFEELIST.SPEC);
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, quantity);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, Math.Round(feettl / quantity, 3, MidpointRounding.AwayFromZero));
// db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal,defGOODFEELIST.TAXRATE);
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, headdata.RATE);
if (headdata.RATE == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(feettl / quantity, 3, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
// var tax = Math.Round(feettl / (1 + defGOODFEELIST.TAXRATE / 100) * (defGOODFEELIST.TAXRATE / 100), 2);
var tax = Math.Round(feettl / (1 + headdata.RATE / 100) * (headdata.RATE / 100), 2, MidpointRounding.AwayFromZero);
var amount = feettl - tax;
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amount / quantity, 3, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, defGOODFEELIST.GOODCODE);
db.ExecuteNonQuery(cmdInsertInv, tran);
}
if (!string.IsNullOrEmpty(duino))
{
var cmdUpdateDui =
db.GetSqlStringCommand(
@"update ch_dui_detail set INVNO=@PAYNO WHERE CH_ID=@GID AND DUINO=@DUINO");
cmdUpdateDui.Parameters.Clear();
db.AddInParameter(cmdUpdateDui, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdateDui, "@PAYNO", DbType.String, billno);
db.AddInParameter(cmdUpdateDui, "@DUINO", DbType.String, duino);
db.ExecuteNonQuery(cmdUpdateDui, tran);
}
}
}
}
}
acctaxrate = headdata.RATE;
if (!isList&& amtttl!=0)
{
// acctaxrate = defGOOD.TAXRATE;
var dataList = GetDetailList(" PID='" + GID + "'");
if (dataList.Count != 0)
{
var invlist = dataList[0];
cmdUpdateInv.Parameters.Clear();
db.AddInParameter(cmdUpdateInv, "@GID", DbType.String, invlist.GID);
if (acctaxrate == 0)
{
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal,Math.Round(invlist.AMOUNT + amtttl,2));
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS,2));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS,2));
db.AddInParameter(cmdUpdateInv, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, 0);
}
else
{
amtttl = amtttl + (invlist.TAXPRICE * invlist.PKGS);
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, tax);
//db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, invlist.AMOUNT + amount);
//db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, ((invlist.AMOUNT + amount) / invlist.PKGS) * (1 + acctaxrate / 100));
//db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, (invlist.AMOUNT + amount) / invlist.PKGS);
//db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, invlist.TAX+tax);
}
db.ExecuteNonQuery(cmdUpdateInv, tran);
}
else
{
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
if (defGOOD.GOODNAME == "")
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, "代理运杂费");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
}
else
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, defGOOD.GID);
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, defGOOD.UNIT);
}
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, defGOOD.SPEC);
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, 1);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl,2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, acctaxrate);
if (acctaxrate == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amtttl,2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(amtttl,2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, defGOOD.GOODCODE);
db.ExecuteNonQuery(cmdInsertInv, tran);
}
}
var MBLNOSTR = "";
if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1")
{
if (billnoinvlist != null)
{
foreach (var billnoinv in billnoinvlist)
{
MBLNOSTR = MBLNOSTR + billnoinv.MBLNO + ",";
}
}
}
if (MBLNOSTR != "") MBLNOSTR = "主提单号:" + MBLNOSTR + " 业务应收费用中存在未审核的费用,不能添加发票申请!";
else MBLNOSTR = "添加成功";
if (ischaoe) {
result.Success = false;
result.Message ="单张发票不能超过十万元";
}
else {
result = new DBResult();
result.Success = true;
result.Message = MBLNOSTR;
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
//result.Success = true;
//result.Message = "保存成功";
return result;
}
public static DBResult AddDetailNew(string billno, string duino, List<BillChfeeDetail> bodyList, string curr, string companyid, bool isList, string GID, ChInvoiceapplication headdata)
{
var result = new DBResult();
decimal ttlamount = headdata.APPLYAMOUNT;
bool INVAPPMAX = false;
var INVAPPMAXPARAM = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPMAX'");
if (INVAPPMAXPARAM.PARAMVALUE == "1")
{
INVAPPMAX = true;
}
if (ttlamount >= 99999 && INVAPPMAX)
{
result.Success = false;
result.Message = "单张发票申请不能超过100000";
return result;
}
bool ischaoe = false;
var defGOOD = MsCodeGoodInvDAL.GetData(" ISDEF='1' and (DEFCURR='' or DEFCURR='" + headdata.RECVCURR + "')");
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 ORDERINVOICE=ISNULL(ORDERINVOICE,0)+@ORDERINVOICE WHERE GID=@GID ");
var cmdInsertInv =
db.GetSqlStringCommand(
@"insert into ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values (@GID,@PID,@SerialNo,@GOODSNAME,@SPEC,@UNIT,@PKGS,@TAXPRICE,@PRICE,@AMOUNT,@TAXRATE,@TAX,@Remark,@GOODCODE) ");
var cmdUpdateInv =
db.GetSqlStringCommand(
@"update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID ");
decimal amtttl = 0;
decimal acctaxrate = 0;
decimal doamount = 0;
decimal StlAmount = 0;
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (ttlamount >= 99999 && INVAPPMAX) break;
if ((ttlamount + Math.Round(enumValue.DoAmount, 2, MidpointRounding.AwayFromZero)) >= 99999 && INVAPPMAX)
{
StlAmount = 0;
doamount = 0;
ischaoe = true;
//doamount = 99999-ttlamount;
//StlAmount = Math.Round(enumValue.StlAmount*((99999 - ttlamount)/doamount),2, MidpointRounding.AwayFromZero);
}
else
{
doamount = Math.Round(enumValue.DoAmount, 2, MidpointRounding.AwayFromZero);
StlAmount = enumValue.StlAmount;
}
ttlamount = ttlamount + doamount;
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);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, doamount);
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int16, enumValue.FeeType);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 6);
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, StlAmount);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, duino);
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, "@ORDERINVOICE", DbType.Decimal, StlAmount);
db.ExecuteNonQuery(cmdUpdate, tran);
if (!string.IsNullOrEmpty(duino))
{
var cmdUpdateDui =
db.GetSqlStringCommand(
@"update ch_dui_detail set INVNO=@PAYNO WHERE CH_ID=@GID AND DUINO=@DUINO");
cmdUpdateDui.Parameters.Clear();
db.AddInParameter(cmdUpdateDui, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdateDui, "@PAYNO", DbType.String, billno);
db.AddInParameter(cmdUpdateDui, "@DUINO", DbType.String, duino);
db.ExecuteNonQuery(cmdUpdateDui, tran);
}
if (isList && doamount != 0)
{
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, 1);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, doamount);
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, headdata.RATE);
if (headdata.RATE == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, doamount);
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, doamount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(doamount / (1 + headdata.RATE / 100) * (headdata.RATE / 100), 2, MidpointRounding.AwayFromZero);
var amount = doamount - tax;
// var amount = Math.Round(enumValue.DoAmount / (1 + enumValue.AccTaxRate / 100),2);
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, "");
db.ExecuteNonQuery(cmdInsertInv, tran);
}
if (enumValue.FeeType == 2)
amtttl = amtttl - doamount;
else
amtttl = amtttl + doamount;
}
}
acctaxrate = headdata.RATE;
if (!isList && ttlamount != 0)
{
var dataList = GetDetailList(" PID='" + GID + "'");
if (dataList.Count != 0)
{
var invlist = dataList[0];
cmdUpdateInv.Parameters.Clear();
db.AddInParameter(cmdUpdateInv, "@GID", DbType.String, invlist.GID);
if (acctaxrate == 0)
{
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, Math.Round(invlist.AMOUNT + amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, 0);
}
else
{
amtttl = amtttl + (invlist.TAXPRICE * invlist.PKGS);
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, tax);
//var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2);
//var amount = amtttl - tax;
//db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, Math.Round(invlist.AMOUNT + amount, 2));
//db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round(((invlist.AMOUNT + amount) / invlist.PKGS) * (1 + acctaxrate / 100), 2));
//db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amount) / invlist.PKGS, 2));
//db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, invlist.TAX + tax);
}
db.ExecuteNonQuery(cmdUpdateInv, tran);
}
else
{
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
if (defGOOD.GOODNAME == "")
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, "代理运杂费");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
}
else
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, defGOOD.GID);
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, defGOOD.UNIT);
}
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, defGOOD.SPEC);
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, 1);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, acctaxrate);
if (acctaxrate == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amount, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(amount, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, defGOOD.GOODCODE);
db.ExecuteNonQuery(cmdInsertInv, tran);
}
}
if (ischaoe)
{
result.Success = false;
result.Message = "单张发票不能超过十万元";
}
else
{
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 = "保存成功" + result.Message;
return result;
}
public static DBResult AddBillNew(string billno, string duino, string billcust, string billcurr, string feesql, List<ChFeeExrate> exratelist, string companyid, bool isList, string GID, ChInvoiceapplication headdata, bool custgroup = false, string userid = "")
{
var result = new DBResult();
bool INVAPPMAX = false;
decimal ttlamount = headdata.APPLYAMOUNT;
var INVAPPMAXPARAM = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPMAX'");
if (INVAPPMAXPARAM.PARAMVALUE == "1")
{
INVAPPMAX = true;
}
if (ttlamount >= 99999 && INVAPPMAX)
{
result.Success = false;
result.Message = "单张发票申请不能超过100000";
return result;
}
Database db = DatabaseFactory.CreateDatabase();
decimal amtttl = 0;
decimal acctaxrate = 0;
bool adddo = true;
bool ischaoe = false;
var FEENOAUDITCANTSHENINV = MsSysParamSetDAL.GetData("PARAMNAME='FEENOAUDITCANTSHENINV'");
List<DSWeb.MvcShipping.Models.MsOpBill.MsOpBill> billnoinvlist = null;
var defGOOD = MsCodeGoodInvDAL.GetData(" ISDEF='1' and (DEFCURR='' or DEFCURR='" + headdata.RECVCURR + "')");
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (!custgroup)
feesql = feesql + " AND CUSTOMERNAME='" + billcust + "'";
var feelist = GetFeeDetailList(feesql, duino, userid, "", companyid);
if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1")
{
billnoinvlist = MsOpBillDAL.GetDataList(" BSNO IN (select DISTINCT BSNO from ch_fee (NOLOCK) where FEETYPE=1 and (FEESTATUS=1 OR FEESTATUS=2 ) AND BSNO IN (SELECT DISTINCT BSNO FROM CH_FEE f WHERE f.ISINVOICE<>1 and f.FEESTATUS IN (0,8,9) and (f.AMOUNT<>(ISNULL(f.INVOICE,0)+ISNULL(f.ORDERINVOICE,0)-ISNULL(f.ORDERINVSETTLEMENT,0))) AND " + feesql + " ))");
}
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 ORDERINVOICE=ISNULL(ORDERINVOICE,0)+@ORDERINVOICE WHERE GID=@GID AND ((AMOUNT>=0 AND ((AMOUNT-ISNULL(ORDERINVOICE,0))-@ORDERINVOICE)>=0)
OR (AMOUNT<0 AND ((AMOUNT-ISNULL(ORDERINVOICE,0))-@ORDERINVOICE)<=0))");
var cmdInsertInv =
db.GetSqlStringCommand(
@"insert into ch_fee_invoicedetail (GID,PID,SerialNo,GOODSNAME,SPEC,UNIT,PKGS,TAXPRICE,PRICE,AMOUNT,TAXRATE,TAX,Remark,GOODCODE)
values (@GID,@PID,@SerialNo,@GOODSNAME,@SPEC,@UNIT,@PKGS,@TAXPRICE,@PRICE,@AMOUNT,@TAXRATE,@TAX,@Remark,@GOODCODE) ");
var cmdUpdateInv =
db.GetSqlStringCommand(
@"update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID ");
decimal doamount = 0;
decimal StlAmount = 0;
decimal ORIGAMOUNT = 0;
decimal UExrate = 0;
if (feelist != null)
{
foreach (var enumValue in feelist)
{
//if (ttlamount >= 99999&& INVAPPMAX) break;
if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1")
{
if (billnoinvlist != null)
{
foreach (var billnoinv in billnoinvlist)
{
if (enumValue.BSNO == billnoinv.BSNO) adddo = false;
}
}
}
if (adddo)
{
decimal feettl = 0;
decimal otamount = 0;
//if (billcurr == enumValue.Currency)
//{
feettl = enumValue.StlAmount;
if (enumValue.FeeType == 2)
otamount = -enumValue.StlAmount;
else
otamount = enumValue.StlAmount;
if ((ttlamount + Math.Round(otamount, 2, MidpointRounding.AwayFromZero)) >= 100000 && INVAPPMAX)
{
feettl = 0;
doamount = 0;
ischaoe = true;
}
else
{
doamount = feettl;
if (enumValue.FeeType == 2)
amtttl = amtttl - enumValue.StlAmount;
else
amtttl = amtttl + enumValue.StlAmount;
ttlamount = ttlamount + otamount;
}
//}
//else
//{
// UExrate = GetExrate(enumValue.Currency, exratelist);
// if (enumValue.FeeType == 2)
// otamount = -enumValue.StlAmount * UExrate;
// else
// otamount = enumValue.StlAmount * UExrate;
// feettl = enumValue.StlAmount * UExrate;
// feettl = Math.Round(feettl, 2, MidpointRounding.AwayFromZero);
// if ((ttlamount + Math.Round(otamount, 2, MidpointRounding.AwayFromZero)) >= 100000 && INVAPPMAX)
// {
// feettl = 0;
// doamount = 0;
// ischaoe = true;
// //feettl = 99999 - ttlamount;
// //doamount = enumValue.StlAmount * (feettl /(enumValue.StlAmount * UExrate));
// //amtttl = amtttl + feettl;
// //ttlamount = ttlamount + feettl;
// }
// else
// {
// doamount = enumValue.StlAmount;
// if (enumValue.FeeType == 2)
// amtttl = amtttl - feettl;
// else
// amtttl = amtttl + feettl;
// ttlamount = ttlamount + otamount;
// }
//}
if (feettl != 0)
{
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);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency);
//if (billcurr == enumValue.Currency)
//{
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsert, "@DOAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, 1);
//}
//else
//{
// db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero));
// 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, doamount);
db.AddInParameter(cmdInsert, "@CATEGORY", DbType.Int16, 6);
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.Int16, 1);
db.AddInParameter(cmdInsert, "@ISDELETED", DbType.Boolean, false);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.DateTime, DateTime.Now);
db.AddInParameter(cmdInsert, "@INVOICESETTLENO", DbType.String, duino);
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdate, "@ORDERINVOICE", DbType.Decimal, doamount);
db.ExecuteNonQuery(cmdUpdate, tran);
if (isList)
{
var defGOODFEELIST = MsCodeGoodInvDAL.GetData(" GOODNAME='代理" + enumValue.FeeName + "'");
var quantity = enumValue.QUANTITY;
if (quantity == 0) quantity = 1;
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
if (defGOODFEELIST.GOODNAME == "")
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, "代理运杂费");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
}
else
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, defGOODFEELIST.GID);
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, defGOODFEELIST.UNIT);
}
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, defGOODFEELIST.SPEC);
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, quantity);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, Math.Round(feettl / quantity, 3, MidpointRounding.AwayFromZero));
// db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal,defGOODFEELIST.TAXRATE);
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, headdata.RATE);
if (headdata.RATE == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(feettl / quantity, 3, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(feettl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
// var tax = Math.Round(feettl / (1 + defGOODFEELIST.TAXRATE / 100) * (defGOODFEELIST.TAXRATE / 100), 2);
var tax = Math.Round(feettl / (1 + headdata.RATE / 100) * (headdata.RATE / 100), 2, MidpointRounding.AwayFromZero);
var amount = feettl - tax;
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amount / quantity, 3, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, defGOODFEELIST.GOODCODE);
db.ExecuteNonQuery(cmdInsertInv, tran);
}
if (!string.IsNullOrEmpty(duino))
{
var cmdUpdateDui =
db.GetSqlStringCommand(
@"update ch_dui_detail set INVNO=@PAYNO WHERE CH_ID=@GID AND DUINO=@DUINO");
cmdUpdateDui.Parameters.Clear();
db.AddInParameter(cmdUpdateDui, "@GID", DbType.String, enumValue.CH_ID);
db.AddInParameter(cmdUpdateDui, "@PAYNO", DbType.String, billno);
db.AddInParameter(cmdUpdateDui, "@DUINO", DbType.String, duino);
db.ExecuteNonQuery(cmdUpdateDui, tran);
}
}
}
}
}
acctaxrate = headdata.RATE;
if (!isList && amtttl != 0)
{
// acctaxrate = defGOOD.TAXRATE;
var dataList = GetDetailList(" PID='" + GID + "'");
if (dataList.Count != 0)
{
var invlist = dataList[0];
cmdUpdateInv.Parameters.Clear();
db.AddInParameter(cmdUpdateInv, "@GID", DbType.String, invlist.GID);
if (acctaxrate == 0)
{
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, Math.Round(invlist.AMOUNT + amtttl, 2));
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS, 2));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT + amtttl) / invlist.PKGS, 2));
db.AddInParameter(cmdUpdateInv, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, 0);
}
else
{
amtttl = amtttl + (invlist.TAXPRICE * invlist.PKGS);
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, tax);
//db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, invlist.AMOUNT + amount);
//db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, ((invlist.AMOUNT + amount) / invlist.PKGS) * (1 + acctaxrate / 100));
//db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, (invlist.AMOUNT + amount) / invlist.PKGS);
//db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, invlist.TAX+tax);
}
db.ExecuteNonQuery(cmdUpdateInv, tran);
}
else
{
cmdInsertInv.Parameters.Clear();
db.AddInParameter(cmdInsertInv, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertInv, "@PID", DbType.String, GID);
db.AddInParameter(cmdInsertInv, "@SerialNo", DbType.Int32, 1);
if (defGOOD.GOODNAME == "")
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, "代理运杂费");
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, "票");
}
else
{
db.AddInParameter(cmdInsertInv, "@GOODSNAME", DbType.String, defGOOD.GID);
db.AddInParameter(cmdInsertInv, "@UNIT", DbType.String, defGOOD.UNIT);
}
db.AddInParameter(cmdInsertInv, "@SPEC", DbType.String, defGOOD.SPEC);
db.AddInParameter(cmdInsertInv, "@PKGS", DbType.Decimal, 1);
db.AddInParameter(cmdInsertInv, "@TAXPRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAXRATE", DbType.Decimal, acctaxrate);
if (acctaxrate == 0)
{
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, Math.Round(amtttl, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(amtttl / (1 + acctaxrate / 100) * (acctaxrate / 100), 2, MidpointRounding.AwayFromZero);
var amount = amtttl - tax;
db.AddInParameter(cmdInsertInv, "@PRICE", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@AMOUNT", DbType.Decimal, amount);
db.AddInParameter(cmdInsertInv, "@TAX", DbType.Decimal, tax);
}
db.AddInParameter(cmdInsertInv, "@Remark", DbType.String, "");
db.AddInParameter(cmdInsertInv, "@GOODCODE", DbType.String, defGOOD.GOODCODE);
db.ExecuteNonQuery(cmdInsertInv, tran);
}
}
var MBLNOSTR = "";
if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1")
{
if (billnoinvlist != null)
{
foreach (var billnoinv in billnoinvlist)
{
MBLNOSTR = MBLNOSTR + billnoinv.MBLNO + ",";
}
}
}
if (MBLNOSTR != "") MBLNOSTR = "主提单号:" + MBLNOSTR + " 业务应收费用中存在未审核的费用,不能添加发票申请!";
else MBLNOSTR = "添加成功";
if (ischaoe)
{
result.Success = false;
result.Message = "单张发票不能超过十万元";
}
else
{
result = new DBResult();
result.Success = true;
result.Message = MBLNOSTR;
}
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,string GID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
decimal AMOUNT = 0;
if (boday != null)
{
var cmddelete = db.GetSqlStringCommand("delete from ch_fee_do where GID=@FEEDOID");
var cmdupdate = db.GetSqlStringCommand("update ch_fee set ORDERINVOICE=ORDERINVOICE-@ORIGAMOUNT where GID=@GID");
var cmdupdatedui = db.GetSqlStringCommand("update ch_dui_detail set INVNO='' where CH_ID=@GID AND INVNO=@PAYNO AND DUINO=@DUINO");
foreach (var enumValue in boday)
{
cmddelete.Parameters.Clear();
db.AddInParameter(cmddelete, "@FEEDOID", DbType.String, enumValue.FEEDOID);
db.ExecuteNonQuery(cmddelete, tran);
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@ORIGAMOUNT", DbType.Decimal, enumValue.ORIGAMOUNT);
db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.FEEID);
db.ExecuteNonQuery(cmdupdate, tran);
if (enumValue.FEETYPE==1)
AMOUNT = AMOUNT + enumValue.AMOUNT;
else AMOUNT = AMOUNT - enumValue.AMOUNT;
if (!string.IsNullOrEmpty(enumValue.INVOICESETTLENO))
{
cmdupdatedui.Parameters.Clear();
db.AddInParameter(cmdupdatedui, "@GID", DbType.String, enumValue.FEEID);
db.AddInParameter(cmdupdatedui, "@PAYNO", DbType.String, enumValue.BILLNO);
db.AddInParameter(cmdupdatedui, "@DUINO", DbType.String, enumValue.INVOICESETTLENO);
db.ExecuteNonQuery(cmdupdatedui, tran);
}
}
}
var dataList =GetDetailList(" PID='"+GID+"'");
if (dataList.Count != 0)
{
var cmdUpdateInv =
db.GetSqlStringCommand(
@"update ch_fee_invoicedetail set TAXPRICE=@TAXPRICE
,PRICE=@PRICE,AMOUNT=@AMOUNT,TAX=@TAX where GID=@GID ");
var invlist = dataList[0];
cmdUpdateInv.Parameters.Clear();
db.AddInParameter(cmdUpdateInv, "@GID", DbType.String, invlist.GID);
if (invlist.TAXRATE== 0)
{
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, Math.Round(invlist.AMOUNT-AMOUNT, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, Math.Round((invlist.AMOUNT - AMOUNT) / invlist.PKGS, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, Math.Round((invlist.AMOUNT - AMOUNT) / invlist.PKGS, 2, MidpointRounding.AwayFromZero));
db.AddInParameter(cmdUpdateInv, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, 0);
}
else
{
var tax = Math.Round(AMOUNT / (1 + invlist.TAXRATE / 100) * (invlist.TAXRATE / 100), 2, MidpointRounding.AwayFromZero);
var amount = AMOUNT - tax;
db.AddInParameter(cmdUpdateInv, "@AMOUNT", DbType.Decimal, invlist.AMOUNT - amount);
db.AddInParameter(cmdUpdateInv, "@TAXPRICE", DbType.Decimal, ((invlist.AMOUNT - amount) / invlist.PKGS) * (1 + invlist.TAXRATE / 100));
db.AddInParameter(cmdUpdateInv, "@PRICE", DbType.Decimal, (invlist.AMOUNT - amount) / invlist.PKGS);
db.AddInParameter(cmdUpdateInv, "@TAX", DbType.Decimal, invlist.TAX- tax);
}
db.ExecuteNonQuery(cmdUpdateInv, 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,string GID)
{
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("p_update_invapplycation");
db.AddInParameter(cmd, "@con_no", DbType.String, billno);
db.AddInParameter(cmd, "@con_gid", DbType.String, GID);
db.ExecuteNonQuery(cmd);
return 0;
}
public static int p_update_AmountNew(string billno, string GID,string deptname,string companyid)
{
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("p_update_invapplycationNew");
db.AddInParameter(cmd, "@con_no", DbType.String, billno);
db.AddInParameter(cmd, "@con_gid", DbType.String, GID);
db.ExecuteNonQuery(cmd);
var headData = ChinvoiceapplicationDAL.GetData(" BILLNO='" + billno + "'");
var dataList = ChinvoiceapplicationDAL.GetApplicationDetailList("LINKGID='" + headData.GID + "'");
decimal ttlinv = 0;
decimal ttlrmbinv = 0;
decimal ttlusdinv = 0;
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var GOODSNAME = T_ALL_DA.GetStrSQL("GOODSNAME", "select top 1 GOODSNAME from SYS_DEPT_ARREARS where DEPT='"+deptname+"' AND OPLBNAME IN (select top 1 OPLBNAME from v_op_bill where BSNO IN (SELECT BSNO FROM CH_FEE_DO WHERE BILLNO='" + headData.BILLNO+ "'))");
var bankList = MsInfoClientDAL.GetBankList(" LINKID in (SELECT GID FROM INFO_CLIENT WHERE SHORTNAME='" + headData.CUSTOMERNAME + "' and CORPID='" + companyid + "')", "0");
if (dataList != null && dataList.Count != 0)
{
foreach (var emv in dataList)
{
if (emv.CURRENCY == "USD") ttlusdinv = ttlusdinv + emv.AMOUNT;
if (emv.CURRENCY == "RMB") ttlrmbinv = ttlrmbinv + emv.AMOUNT;
}
}
if (headData.INVTYPE == "原币开票")
{
if (ttlusdinv != headData.OTCURRAMOUNT)
{
var isfind = false;
if (dataList != null && dataList.Count != 0)
{
foreach (var emv in dataList)
{
if (emv.CURRENCY == "USD")
{
emv.AMOUNT = emv.AMOUNT + (headData.OTCURRAMOUNT - ttlusdinv);
isfind = true;
};
}
}
if (!isfind)
{
ChInvoiceapplicationDetail detail = new ChInvoiceapplicationDetail();
detail.LINKGID = "*";
detail.INVOICECUSTNAME = headData.INVOICECUSTNAME;
detail.CURRENCY = "USD";
detail.AMOUNT = headData.OTCURRAMOUNT;
detail.CUSTRATENO = headData.CUSTRATENO;
detail.CUSTTEL = GetTelephoneList(headData.CUSTADDRTEL);
if (!string.IsNullOrEmpty(detail.CUSTTEL))
detail.CUSTADDR = headData.CUSTADDRTEL.Replace(detail.CUSTTEL,"");
else detail.CUSTADDR = headData.CUSTADDRTEL;
var bank = bankList.Find(X => X.CURRENCY == "USD"&&X.ISINVDEF=="1");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
{
bank = bankList.Find(X => X.CURRENCY == "USD");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
detail.CUSTBANK = headData.CUSTBANK;
}
detail.EMAIL = headData.PUSHEMAIL;
detail.GOODSNAME = GOODSNAME;
dataList.Add(detail);
}
}
if (ttlrmbinv != headData.APPLYAMOUNT)
{
var isfind = false;
if (dataList != null && dataList.Count != 0)
{
foreach (var emv in dataList)
{
if (emv.CURRENCY == "RMB")
{
emv.AMOUNT = emv.AMOUNT + (headData.APPLYAMOUNT - ttlrmbinv);
isfind = true;
};
}
}
if (!isfind)
{
ChInvoiceapplicationDetail detail = new ChInvoiceapplicationDetail();
detail.LINKGID = "*";
detail.INVOICECUSTNAME = headData.INVOICECUSTNAME;
detail.CURRENCY = "RMB";
detail.AMOUNT = headData.APPLYAMOUNT;
detail.CUSTRATENO = headData.CUSTRATENO;
detail.CUSTTEL = GetTelephoneList(headData.CUSTADDRTEL);
if (!string.IsNullOrEmpty(detail.CUSTTEL))
detail.CUSTADDR = headData.CUSTADDRTEL.Replace(detail.CUSTTEL, "");
else detail.CUSTADDR = headData.CUSTADDRTEL;
var bank = bankList.Find(X => X.CURRENCY == "RMB" && X.ISINVDEF == "1");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
{
bank = bankList.Find(X => X.CURRENCY == "RMB");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
detail.CUSTBANK = headData.CUSTBANK;
}
detail.EMAIL = headData.PUSHEMAIL;
detail.GOODSNAME = GOODSNAME;
dataList.Add(detail);
}
}
}
else if (headData.INVTYPE == "美元折人民币开票")
{
if (ttlrmbinv != headData.AMOUNT)
{
var isfind = false;
if (dataList != null && dataList.Count != 0)
{
foreach (var emv in dataList)
{
if (emv.CURRENCY == "RMB")
{
emv.AMOUNT = emv.AMOUNT + (headData.AMOUNT - ttlrmbinv);
isfind = true;
};
}
}
if (!isfind)
{
ChInvoiceapplicationDetail detail = new ChInvoiceapplicationDetail();
detail.LINKGID = "*";
detail.INVOICECUSTNAME = headData.INVOICECUSTNAME;
detail.CURRENCY = "RMB";
detail.AMOUNT = headData.AMOUNT;
detail.CUSTRATENO = headData.CUSTRATENO;
detail.CUSTTEL = GetTelephoneList(headData.CUSTADDRTEL);
if (!string.IsNullOrEmpty(detail.CUSTTEL))
detail.CUSTADDR = headData.CUSTADDRTEL.Replace(detail.CUSTTEL, "");
else detail.CUSTADDR = headData.CUSTADDRTEL;
var bank = bankList.Find(X => X.CURRENCY == "RMB" && X.ISINVDEF == "1");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
{
bank = bankList.Find(X => X.CURRENCY == "RMB");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
detail.CUSTBANK = headData.CUSTBANK;
}
detail.EMAIL = headData.PUSHEMAIL;
detail.GOODSNAME = GOODSNAME;
dataList.Add(detail);
}
}
}
else if (headData.INVTYPE == "人民币折美元开票")
{
if (ttlusdinv != headData.AMOUNT)
{
var isfind = false;
if (dataList != null && dataList.Count != 0)
{
foreach (var emv in dataList)
{
if (emv.CURRENCY == "USD")
{
emv.AMOUNT = emv.AMOUNT + (headData.AMOUNT - ttlusdinv);
isfind = true;
};
}
}
if (!isfind)
{
ChInvoiceapplicationDetail detail = new ChInvoiceapplicationDetail();
detail.LINKGID = "*";
detail.INVOICECUSTNAME = headData.INVOICECUSTNAME;
detail.CURRENCY = "USD";
detail.AMOUNT = headData.AMOUNT;
detail.CUSTRATENO = headData.CUSTRATENO;
detail.CUSTTEL = GetTelephoneList(headData.CUSTADDRTEL);
if (!string.IsNullOrEmpty(detail.CUSTTEL))
detail.CUSTADDR = headData.CUSTADDRTEL.Replace(detail.CUSTTEL, "");
else detail.CUSTADDR = headData.CUSTADDRTEL;
var bank = bankList.Find(X => X.CURRENCY == "USD" && X.ISINVDEF == "1");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
{
bank = bankList.Find(X => X.CURRENCY == "USD");
if (bank != null) detail.CUSTBANK = bank.BANKNAME_ACCOUNT;
else
detail.CUSTBANK = headData.CUSTBANK;
}
detail.EMAIL = headData.PUSHEMAIL;
detail.GOODSNAME = GOODSNAME;
dataList.Add(detail);
}
}
}
ChinvoiceapplicationDAL.SaveAppDetail(headData, dataList);
return 0;
}
public static string GetTelephoneList(string input)
{
//集合存放提取出来的电话号码
//List<string> list = new List<string>();
/*
* 正则表达式提取
* 分为五种格式能兼容11位手机号、3位或4位区号-7位或8位电话号、400电话的两种写法(400-ddd-dddd、400ddddddd)
*/
Regex regex = new Regex(@"(1[3|4|5|6|7|8|9]\d{9})|(0\d{2,3}-\d{7,8})|(400-\d{3}-\d{4})|(400\d{7})");
//Match集合匹配成功的字符串集合
MatchCollection collection = regex.Matches(input);
//遍历Match集合取出值
string telephone="";
foreach (System.Text.RegularExpressions.Match item in collection)
{
foreach (Group group in item.Groups)
{
telephone = group.Value.Trim();
////偶尔会出现重复提取,所以加了去重判断
//if (!string.IsNullOrEmpty(telephone) && !list.Contains(telephone))
//{
// list.Add(telephone);
//}
}
}
return telephone;
}
#region 提交审核和撤销审核
public static DBResult SubmitAudit(String WorkFlowName, String USERID, String bill,string companyid)
{
var result = new DBResult();
T_ALL_DA T_ALL_DA = new T_ALL_DA();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var WorkFlowid = "";
if (WorkFlowid == "")
{
string lsSQL = "select * FROM workflow WHERE COMPANYID='" + companyid + "' AND ISCONDITION=1 and [TYPE]=(SELECT TYPENO FROM workflow_type WHERE [NAME]='" + WorkFlowName + "') "
+ " and GID in (select workflowID from workflow_Userpath where userid ='" + USERID + "') order by SORTNO ";
DataSet dsworkflow = T_ALL_DA.GetAllSQL(lsSQL);
if (dsworkflow != null)
{
if (dsworkflow.Tables[0].Rows.Count > 0)
{
foreach (DataRow row in dsworkflow.Tables[0].Rows)
{
var CONDITIONSQL = Convert.ToString(row["CONDITIONSQL"]);
CONDITIONSQL = CONDITIONSQL.Replace("[业务编号]", "'" + bill + "'");
var strCOUNT = T_ALL_DA.GetStrSQL("BLCT", CONDITIONSQL);
if (strCOUNT != "0")
{
WorkFlowid = Convert.ToString(row["GID"]);
break;
}
}
}
}
if (WorkFlowid == "") WorkFlowid = "no";
}
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName,bill, USERID,bill,bill,"", WorkFlowid);
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("BILLNO=@BILLNO");
if (WorkResult.islast == true)
{
cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=0,OPERATETIME=GETDATE() where BILLNO=@BILLNO");
}
else
{
cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication 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 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,bill,bill,"");
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("BILLNO=@BILLNO");
if (WorkResult.islast == true)
{
cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=0 where BILLNO=@BILLNO");
}
else
{
cmdupdate = db.GetSqlStringCommand("update ch_fee_invoiceapplication 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_invoiceapplication 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_invoiceapplication 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;
}
#endregion
#region 审核或驳回
public static DBResult AuditList(List<ChInvoiceapplication> boday,string PAYCOMPANYID, String USERID)
{
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_invoiceapplication set BILLSTATUS=0 where BILLNO=@BILLNO");
var cmdupdate2 = db.GetSqlStringCommand("update ch_fee_invoiceapplication set BILLSTATUS=0,PAYCOMPANYID=@PAYCOMPANYID where BILLNO=@BILLNO");
foreach (var enumValue in boday)
{
if (enumValue.BILLSTATUS == 2 || enumValue.BILLSTATUS ==4)
{
Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo("InvAudit", enumValue.BILLNO, USERID, tran, enumValue.BILLNO);
if (WorkResult.Success == true&&WorkResult.islast==true)
{
if (boday.Count == 1)
{
cmdupdate2.Parameters.Clear();
db.AddInParameter(cmdupdate2, "@PAYCOMPANYID", DbType.String, PAYCOMPANYID);
db.AddInParameter(cmdupdate2, "@BILLNO", DbType.String, enumValue.BILLNO);
db.ExecuteNonQuery(cmdupdate2, tran);
}
else
{
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;
}
public static DBResult AuditBackList(List<ChInvoiceapplication> 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_invoiceapplication set BILLSTATUS=4,REASON='" + reason + "' where BILLNO=@BILLNO");
foreach (var enumValue in boday)
{
if (enumValue.BILLSTATUS == 2 || enumValue.BILLSTATUS == 0)
{
Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo("InvAudit", enumValue.BILLNO, USERID, "");
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
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(GID) AS CT from ch_fee_invoiceapplication (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 发票审核列表
static public List<ChInvoiceapplication> GetAuditDataList(string strCondition, string userid, string isaudit,string companyid,string sort = null)
{
var strSql = new StringBuilder();
strSql.Append(" SELECT i.GID,i.BILLNO,i.BILLSTATUS,i.CUSTOMERNAME,i.ACTUALCUSTOMERNAME,i.CURRENCY,i.INVOICENO,i.INVOICECUSTNAME,i.INVOICECATEGORY ");
strSql.Append(" ,i.BSNO,i.MBLNO,i.VESSELVOYAGE,i.POL,i.POD,i.ETD,i.APPLYAMOUNT,i.INVAMOUNT,i.AMOUNTCAPITAL,i.OTCURRAMOUNT,i.AMOUNT");
strSql.Append(" ,i.APPLICANT,i.APPLYTIME,i.ENTERTIME,i.OPERATOR,i.OPERATETIME,i.RECVCURR,i.FEEAMOUNT ");
strSql.Append(" ,i.REMARK,i.SHENREMARK,i.COMPANYID,i.ISAPPLY,i.CUSTRATENO,i.CUSTADDRTEL,i.CUSTBANK,i.RATE,'' INVOICENOREF,null INVDATE ");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97010 and EnumValueID=i.BILLSTATUS) as BILLSTATUSREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=97008 and EnumValueID=i.INVOICECATEGORY) as INVOICECATEGORYREF");
strSql.Append(",(select ShowName from [user] where GID=i.APPLICANT) as APPLICANTNAME");
strSql.Append(",(select DEPTNAME from [VW_user] where userid=i.APPLICANT) as APPLICANTDEPT");
strSql.Append(",i.PAYCOMPANYID,(select name from company where gid=i.PAYCOMPANYID) PAYCOMPANYREF,dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno) as IsAudit,i.REASON,i.ISPRINT,i.PRINTCOUNT ");
strSql.Append(",PUSHMODE,PUSHMOBILE,PUSHEMAIL,dbo.F_getEnumValue(0,80002,i.PUSHMODE) as PUSHMODEREF,'' as NOSTL,INVTYPE");
strSql.Append(" FROM ch_fee_invoiceapplication i left join workflow_using wu on wu.bsno=i.billno where 1=1 ");
if (isaudit=="1")
strSql.Append(" and i.BILLSTATUS=2 and dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 ");
else if (isaudit == "2")
// strSql.Append(" and i.BILLSTATUS=0 AND I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ) ");
strSql.Append(" and i.BILLSTATUS=0 ");
else if (isaudit == "")
{
var rangstr = GetRangDAListStr("", userid,"", companyid);
if (!string.IsNullOrEmpty(rangstr))
{
strSql.Append(" and " + rangstr);
}
//strSql.Append(" and (dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 ");
//strSql.Append(" or (I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ))) ");
}
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
public static DBResult GetPrint(string bsno, string userid = "", string usercode = "", string orgcode = "")
{
var AuditPrint = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPPRINTAFTERAUDIT'");
var PrintOne = MsSysParamSetDAL.GetData("PARAMNAME='INVAPPONLYPRINTONE'");
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;
}
#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,VSSQL ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modInvoiceAppList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
string VSSQL = "";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
VSSQL = Convert.ToString(reader["VSSQL"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (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 == "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 == "1")
{
str = " COMPANYID='" + companyid + "' ";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
}
return str;
}
#endregion
#region 发票申请费用查询范围
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modInvoiceAppSearch' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
string VSSQL = "";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
VSSQL = Convert.ToString(reader["VSSQL"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "' OR DOC='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (OP='" + username + "' OR INPUTBY='" + username + "' OR SALE='" + username + "' OR CUSTSERVICE='" + username + "' OR DOC='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var 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 DOC 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 DOC 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 = " (b.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "'";
}
else
{
str = str + " or b.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 = " (b.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
}
else
{
str = str + " or b.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
};
}
str = str + ")";
reader.Close();
}
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
}
return str;
}
public static string GetRangAddFeeDAStr(string userid, string username, string companyid)
{
string str = "";
string modustr = "MODINVAPPFEERANGE";
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["OPID"]) + "' ";
};
}
str = str + ")";
reader.Close();
}
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
return str;
}
public static DBResult PASSAUDITWithGID(string ch_fee_invoiceapplicationGID)
{
var result = new DBResult();
string sql = "update ch_fee_invoiceapplication set BILLSTATUS = 0 where GID = '" + ch_fee_invoiceapplicationGID + "'";
Database db = DatabaseFactory.CreateDatabase();
try
{
int rst = db.ExecuteNonQuery(CommandType.Text, sql);
result.Success = rst > 0;
result.Message = "操作成功!";
return result;
}
catch (Exception e)
{
result.Success = false;
result.Message = e.Message;
return result;
throw;
}
}
#endregion
}
}