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.

1174 lines
64 KiB
C#

10 months ago
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class InvoiceApplicationDA
{
private const string PARM_INVOICE_APP_GID = "@gid";
private const string PARM_INVOICE_APP_BILL_NO = "@bill_no";
private const string PARM_INVOCIE_APP_BILL_STATUS = "@bill_status";
private const string PARM_INVOICE_APP_CUSTOMER_NAME = "@customer_name";
private const string PARM_INVOICE_APP_INVOICENO = "@invoice_no";
private const string PARM_INVOICE_APP_INVOICE_CUST_NAME = "@invoice_customer";
private const string PARM_INVOICE_APP_BSNO = "@bsno";
private const string PARM_INVOICE_APP_VESSEL_VOYAGE = "@vessel_voyage";
private const string PARM_INVOICE_APP_ETD = "@etd";
private const string PARM_INVOICE_APP_POL = "@pol";
private const string PARM_INVOICE_APP_POD = "@pod";
private const string PARM_INVOICE_APP_FEE_ITEM = "@fee_item";
private const string PARM_INVOICE_APP_AMOUNT_LIST = "@amount_list";
private const string PARM_INVOICE_APP_APPLYAMOUNT = "@apply_amount";
private const string PARM_INVOICE_APP_AMOUNT_CAPITAL = "@amount_capital";
private const string PARM_INVOICE_APP_CURRENCY = "@currency";
private const string PARM_INVOICE_APP_REMARK = "@remark";
private const string PARM_INVOICE_APP_APPLICANT = "@applicant";
private const string PARM_INVOICE_APP_APPLY_TIME = "@apply_time";
private const string PARM_INVOICE_APP_ENTER_TIME = "@enter_time";
private const string PARM_INVOICE_APP_OPERATOR = "@operator";
private const string PARM_INVOICE_APP_OPERATE_TIME = "@operate_time";
private const string PARM_INVOICE_APP_MBLNO = "@mblno";
private const string PARM_INVOICE_APP_IS_APPLY = "@is_apply";
private const string PARM_INVOICE_APP_IS_DELETE = "@is_delete";
private const string PARM_INVOICE_APP_DELETE_USER = "@delete_user";
private const string PARM_INVOICE_APP_DELETE_TIME = "@delete_time";
private const string PARM_INVOICE_APP_LIKE = "@like";
private const string PARM_INVOICE_APP_COMPANY_ID = "@company_id";
private const string PARM_INVOICE_APP_RATE = "@rate";
//ch_fee_do
private string PARM_FEE_DO_GID = "@gid";
private string PARM_FEE_DO_BILL_NO = "@bill_no";
private string PARM_FEE_DO_BSNO = "@bsno";
private string PARM_FEE_DO_MBL_NO = "@mbl_no";
private string PARM_FEE_DO_HBL_NO = "@nbl_no";
private string PARM_FEE_DO_CUSTOMER_NAME = "@customer_name";
private string PARM_FEE_DO_BSTYPE = "@bs_type";
private string PARM_FEE_DO_FEE_ID = "@fee_id";
private string PARM_FEE_DO_FEE_NAME = "@fee_name";
private string PARM_FEE_DO_CURRENCY = "@currency";
private string PARM_FEE_DO_AMOUNT = "@amount";
private string PARM_FEE_DO_DO_AMOUNT = "@do_amount";
private string PARM_FEE_DO_FEE_TYPE = "@fee_type";
private string PARM_FEE_DO_CATEGORY = "@category";
private string PARM_FEE_DO_BILL_STATUS = "@bill_status";
private string PARM_FEE_DO_REMARK = "@remark";
private string PARM_FEE_DO_ORIG_CURRENCY = "@orig_currency";
private string PARM_FEE_DO_EXCHANGE_RATE = "@exchange_rate";
private string PARM_FEE_DO_ORIG_AMOUNT = "@orig_amount";
private string PARM_FEE_DO_COMPANY_ID = "@company_id";
//ch_fee
private const string PARM_FEE_GID = "@gid";
private const string PARM_FEE_ORDER_INVOCE = "@order_invoice";
private const string SQL_SELECT_GET_SERVERTIME = " SELECT GETDATE() ";//获取服务端时间
private const string SQL_SELECT_INVOICE_APP_BY_BILLNO = " SELECT GID, BILLNO, BILLSTATUS, CUSTOMERNAME, INVOICENO, INVOICECUSTNAME, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, AMOUNTLIST, "
+ " APPLYAMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, ENTERTIME, OPERATOR, OPERATETIME,MBLNO,ISAPPLY,ISDELETE,DELETEUSER,DELETETIME "
+ " FROM ch_fee_invoiceapplication WHERE BILLNO = @bill_no";
private const string SQL_SELECT_INVOICE_APP_BY_GID = " SELECT GID, BILLNO, BILLSTATUS, CUSTOMERNAME, INVOICENO, INVOICECUSTNAME, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, AMOUNTLIST, "
+ " APPLYAMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, ENTERTIME, OPERATOR, OPERATETIME,MBLNO,ISAPPLY,ISDELETE,DELETEUSER,DELETETIME "
+ " FROM ch_fee_invoiceapplication WHERE GID = @gid";
private const string SQL_INSERT_INVOICE_APP_NO_APPLY = " INSERT INTO ch_fee_invoiceapplication(GID, BILLNO, BILLSTATUS, CUSTOMERNAME, INVOICENO, INVOICECUSTNAME, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, AMOUNTLIST, "
+ " APPLYAMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, ENTERTIME,MBLNO,ISAPPLY,APPLICANT, APPLYTIME ) "
+ " VALUES(@gid,@bill_no,@bill_status,@customer_name,@invoice_no,@invoice_customer,@bsno,@vessel_voyage,@etd,@pol,@pod,@fee_item,@amount_list,@apply_amount,@amount_capital, "
+ " @currency,@remark,getdate(),@mblno,@is_apply,@applicant,GETDATE()) ";
private const string SQL_INSERT_INVOICE_APP_NO_APPLY_NO_ETD = " INSERT INTO ch_fee_invoiceapplication(GID, BILLNO, BILLSTATUS, CUSTOMERNAME, INVOICENO, INVOICECUSTNAME, BSNO, VESSELVOYAGE, POL, POD, FEEITEM, AMOUNTLIST, "
+ " APPLYAMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, ENTERTIME,MBLNO,ISAPPLY,APPLICANT, APPLYTIME ) "
+ " VALUES(@gid,@bill_no,@bill_status,@customer_name,@invoice_no,@invoice_customer,@bsno,@vessel_voyage,@pol,@pod,@fee_item,@amount_list,@apply_amount,@amount_capital, "
+ " @currency,@remark,getdate(),@mblno,@is_apply,@applicant,GETDATE()) ";
private const string SQL_UPDATE_INVOICE_APPLICATION_STATUS = "UPDATE ch_fee_invoiceapplication SET BILLSTATUS = @bill_status,ISAPPLY = @is_apply WHERE GID = @gid ";
private const string SQL_DELETE_INVOICE_APPLICATION = "DELETE FROM ch_fee_invoiceapplication WHERE GID = @gid";
private const string SQL_UPDATE_FROM_FEE_DO_TO_FEE = " UPDATE ch_fee SET ORDERINVOICE = ch_fee_do.DOAMOUNT FROM ch_fee_do WHERE ch_fee_do.FEEID = ch_fee.GID AND ch_fee_do.BILLNO = @bill_no ";
private const string SQL_SELECT_GET_SERVER_TIME = " SELECT GETDATE() ";
private const string SQL_SELECT_LAST_BILL_NO = " SELECT TOP 1 BILLNO FROM ch_fee_invoiceapplication WHERE BILLNO LIKE @like AND COMPANYID = @company_id ORDER BY BILLNO DESC ";
/// <summary>
/// 获取含有发票审核权限的人员信息id
/// </summary>
/// <param name="companyid">公司id</param>
/// <returns></returns>
public DataTable GetMessageAuditor(string companyid)
{
string SQL_SELECT_MEEAGEAUDITOR = "select distinct A.userid from [user_action] A join [action] B on A.actionid=B.gid join [sys_module] C on B.moduleid=C.gid where c.description like '%发票开出%' and A.userid in(select userid from [user_company] where companyid=@companyid)";
SqlParameter[] param = new SqlParameter[]{
new SqlParameter("@companyid",companyid)
};
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_MEEAGEAUDITOR, param).Tables[0];
}
catch (Exception error)
{
throw new Exception(error.Message,error);
}
return table;
}
#region 驳回发票申请
/// <summary>
/// 驳回发票申请
/// </summary>
/// <param name="tempInvoiceAppID">发票申请GID</param>
/// <param name="tempUserID">操作人GID</param>
/// <param name="tempBillNO">发票申请业务编号</param>
/// <returns>值1表示发票申请驳回成功 值不等于1表示发票申请驳回失败</returns>
public int voidInvoiceApplication(string tempInvoiceAppID,string tempUserID,string tempBillNO)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
iResult = -3;
string SQL_UPDATE_CH_FEE_ORDER_INVOICE_VOID = " UPDATE ch_fee SET ORDERINVOICE = ch_fee.ORDERINVOICE - C.ORDERAMOUNT "
+ " FROM (SELECT B.FEEID,B.ORIGAMOUNT as ORDERAMOUNT FROM ch_fee_invoiceapplication as A INNER JOIN ch_fee_do as B ON A.BILLNO = B.BILLNO "
+ " WHERE B.CATEGORY = 6 AND ISNULL(A.ISDELETE,0) <> 1 AND ISNULL(B.ISDELETED,0) <> 1 AND A.GID = '" + tempInvoiceAppID + "' ) AS C "
+ " WHERE ch_fee.GID = C.FEEID ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_ORDER_INVOICE_VOID, null);
//
iResult = -4;
string SQL_UPDATE_INVOICE_APPLICATION_VOID = " UPDATE ch_fee_invoiceapplication SET ISDELETE = 1,DELETEUSER = '" + tempUserID + "',DELETETIME = GETDATE(),BILLSTATUS = 4 WHERE GID = '" + tempInvoiceAppID + "' AND ISNULL(ISDELETE,0) <> 1 ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_INVOICE_APPLICATION_VOID, null);
//
iResult = -5;
string SQL_UPDATE_INVOICE_APPLICATION_FEEDO_VOID = " UPDATE ch_fee_do SET ISDELETED = 1,DELETEUSER = '" + tempUserID + "',DELETETIME = GETDATE() WHERE BILLNO = '" + tempBillNO + "' AND CATEGORY = 6 AND ISNULL(ISDELETED,0) <> 1";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_INVOICE_APPLICATION_FEEDO_VOID, null);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 获取数据库服务端时间
/// <summary>
/// 获取数据库服务端时间
/// </summary>
/// <returns>DateTime类型 时间</returns>
public DateTime GetServerTime()
{
DateTime dbServerTime = DateTime.MinValue;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_GET_SERVER_TIME, null))
{
try
{
if (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
dbServerTime = sqlRead.GetDateTime(0);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return dbServerTime;
}
#endregion
#region 删除开票申请
/// <summary>
/// 删除开票申请
/// </summary>
/// <param name="tempInvoiceApplicationGID">开票申请GID</param>
/// <returns>值1删除成功 值-1删除失败,有异常</returns>
public int DeleteInvoiceApplication(string tempInvoiceApplicationGID)
{
int iResult = 0;
SqlParameter parm = new SqlParameter(PARM_INVOICE_APP_GID, SqlDbType.VarChar, 36);
parm.Value = tempInvoiceApplicationGID;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_DELETE_INVOICE_APPLICATION, parm);
if (iResult > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#endregion
#region 更新开票申请状态值
/// <summary>
/// 更新开票申请状态值
/// </summary>
/// <param name="tempGID">开票申请GID</param>
/// <param name="iStatus">更新开票申请状态值</param>
/// <param name="bIsApply">开票申请状态是否为已提交</param>
/// <returns>值1表示更新成功 值-1表示更新异常失败</returns>
public int UpdateInvoiceApplicationStatus(string tempGID, int iStatus, bool bIsApply, string tempBillNO)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_APP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APP_IS_APPLY,SqlDbType.Bit),
new SqlParameter(PARM_INVOCIE_APP_BILL_STATUS,SqlDbType.Int)
};
parms[0].Value = tempGID;
parms[1].Value = bIsApply;
parms[2].Value = iStatus;
//将未提交的开票申请更新为提交开票状态
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_INVOICE_APPLICATION_STATUS, parms);
//ch_fee_do金额更新ch_fee表申请开票金额字段
SqlParameter[] feeDoParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,20)
};
feeDoParms[0].Value = tempBillNO;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_FROM_FEE_DO_TO_FEE, feeDoParms);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 根据业务编号获取开票申请信息
/// <summary>
/// 根据业务编号获取开票申请信息
/// </summary>
/// <param name="tempBillNO">业务编号</param>
/// <returns>开票申请信息实体类</returns>
public InvoiceApplicationEntity GetInvoiceApplicationByBillNO(string tempBillNO)
{
//初始化返回变量
InvoiceApplicationEntity invoiceApplicationEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_INVOICE_APP_BILL_NO, SqlDbType.VarChar, 20);
parm.Value = tempBillNO;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INVOICE_APP_BY_BILLNO, parm))
{
try
{
invoiceApplicationEntity = new InvoiceApplicationEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
invoiceApplicationEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
invoiceApplicationEntity.BillNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
invoiceApplicationEntity.BillStatus = sqlRead.GetInt32(2);
}
if (!sqlRead.IsDBNull(3))
{
invoiceApplicationEntity.CustomerName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
invoiceApplicationEntity.InvoiceNO = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
invoiceApplicationEntity.InvoiceCustomer = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
invoiceApplicationEntity.BSNO = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
invoiceApplicationEntity.VesselVoyage = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
invoiceApplicationEntity.ETD = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
invoiceApplicationEntity.POL = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
invoiceApplicationEntity.POD = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
invoiceApplicationEntity.FeeItem = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
invoiceApplicationEntity.AmountList = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
invoiceApplicationEntity.ApplyAmount = sqlRead.GetDecimal(13);
}
if (!sqlRead.IsDBNull(14))
{
invoiceApplicationEntity.AmountCapital = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
invoiceApplicationEntity.Currency = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
invoiceApplicationEntity.Remark = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
invoiceApplicationEntity.Applicant = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
invoiceApplicationEntity.ApplyTime = sqlRead.GetDateTime(18);
}
if (!sqlRead.IsDBNull(19))
{
invoiceApplicationEntity.EnterTime = sqlRead.GetDateTime(19);
}
if (!sqlRead.IsDBNull(20))
{
invoiceApplicationEntity.Operator = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
invoiceApplicationEntity.OperateTime = sqlRead.GetDateTime(21);
}
if (!sqlRead.IsDBNull(22))
{
invoiceApplicationEntity.MBLNO = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
invoiceApplicationEntity.IsApply = sqlRead.GetBoolean(23);
}
if (!sqlRead.IsDBNull(24))
{
invoiceApplicationEntity.IsDelete = sqlRead.GetBoolean(24);
}
if (!sqlRead.IsDBNull(25))
{
invoiceApplicationEntity.DeleteUser = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
invoiceApplicationEntity.DeleteTime = sqlRead.GetDateTime(26);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return invoiceApplicationEntity;
}
#endregion
#region 根据开票申请信息GID获取开票申请信息
/// <summary>
/// 根据开票申请信息GID获取开票申请信息
/// </summary>
/// <param name="tempBillNO">开票申请GID</param>
/// <returns>开票申请信息实体类</returns>
public InvoiceApplicationEntity GetInvoiceApplicationByGID(string tempGID)
{
//初始化返回变量
InvoiceApplicationEntity invoiceApplicationEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_INVOICE_APP_GID, SqlDbType.VarChar, 36);
parm.Value = tempGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INVOICE_APP_BY_GID, parm))
{
try
{
invoiceApplicationEntity = new InvoiceApplicationEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
invoiceApplicationEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
invoiceApplicationEntity.BillNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
invoiceApplicationEntity.BillStatus = sqlRead.GetInt32(2);
}
if (!sqlRead.IsDBNull(3))
{
invoiceApplicationEntity.CustomerName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
invoiceApplicationEntity.InvoiceNO = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
invoiceApplicationEntity.InvoiceCustomer = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
invoiceApplicationEntity.BSNO = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
invoiceApplicationEntity.VesselVoyage = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
invoiceApplicationEntity.ETD = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
invoiceApplicationEntity.POL = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
invoiceApplicationEntity.POD = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
invoiceApplicationEntity.FeeItem = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
invoiceApplicationEntity.AmountList = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
invoiceApplicationEntity.ApplyAmount = sqlRead.GetDecimal(13);
}
if (!sqlRead.IsDBNull(14))
{
invoiceApplicationEntity.AmountCapital = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
invoiceApplicationEntity.Currency = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
invoiceApplicationEntity.Remark = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
invoiceApplicationEntity.Applicant = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
invoiceApplicationEntity.ApplyTime = sqlRead.GetDateTime(18);
}
if (!sqlRead.IsDBNull(19))
{
invoiceApplicationEntity.EnterTime = sqlRead.GetDateTime(19);
}
if (!sqlRead.IsDBNull(20))
{
invoiceApplicationEntity.Operator = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
invoiceApplicationEntity.OperateTime = sqlRead.GetDateTime(21);
}
if (!sqlRead.IsDBNull(22))
{
invoiceApplicationEntity.MBLNO = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
invoiceApplicationEntity.IsApply = sqlRead.GetBoolean(23);
}
if (!sqlRead.IsDBNull(24))
{
invoiceApplicationEntity.IsDelete = sqlRead.GetBoolean(24);
}
if (!sqlRead.IsDBNull(25))
{
invoiceApplicationEntity.DeleteUser = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
invoiceApplicationEntity.DeleteTime = sqlRead.GetDateTime(26);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return invoiceApplicationEntity;
}
#endregion
#region 将开票申请信息插入开票申请表ch_fee_invoiceapplication
/// <summary>
/// 将开票申请信息插入开票申请表ch_fee_invoiceapplication
/// </summary>
/// <param name="tempInvoiceApplicationEntity">开票信息实体类</param>
/// <param name="tempFeeDoEntities">FeeDo实体类</param>
/// <returns>值1表示插入成功 值-1表示插入失败 有异常</returns>
public int InsertInvoiceApplication(InvoiceApplicationEntity tempInvoiceApplicationEntity, IList<FeeDoEntity> tempFeeDoEntities)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strLastBillNo = "";
string strNewBillNo = "";
//先获取SQL SERVER 数据库端服务器时间
DateTime nowServerDateTime = (DateTime)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_GET_SERVERTIME, null);
if (nowServerDateTime == DateTime.MinValue)
{
throw new Exception("未正常获取到服务端时间");
}
//获取分公司的票号头字符
string tempBANKSHEAD = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + tempInvoiceApplicationEntity.CompanyID.ToString().Trim() + "'", null) as string;
//生成申请编号起始串
string strBillNoProfix = CreateBeginTitleCode(nowServerDateTime, tempBANKSHEAD+"IA", 4);
SqlParameter[] getLastBillParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_APP_LIKE, SqlDbType.VarChar, 200),
new SqlParameter(PARM_INVOICE_APP_COMPANY_ID,SqlDbType.VarChar,36)
};
getLastBillParms[0].Value = strBillNoProfix + "%";
getLastBillParms[1].Value = tempInvoiceApplicationEntity.CompanyID;
//获取最大的编号
string tempLastBillNo = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_LAST_BILL_NO, getLastBillParms) as string;
strLastBillNo = tempLastBillNo ?? "";
//生成付费申请编号
strNewBillNo = CreateSettleCode(nowServerDateTime, tempBANKSHEAD+"IA", 4, strLastBillNo);
//将申请开票信息写入ch_fee_invoiceapplication表
SqlParameter[] appParms = null;
#region 开票申请参数
if (tempInvoiceApplicationEntity.ETD != DateTime.MinValue)
{
appParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_APP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APP_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOCIE_APP_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_APP_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICENO,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_ETD,SqlDbType.DateTime),
new SqlParameter(PARM_INVOICE_APP_POL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_POD,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_FEE_ITEM,SqlDbType.VarChar,8000),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_APP_APPLYAMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_APP_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APP_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APP_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_APP_IS_APPLY,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_APP_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_APP_COMPANY_ID,SqlDbType.VarChar,36)
};
appParms[0].Value = tempInvoiceApplicationEntity.GID;
appParms[1].Value = strNewBillNo;
appParms[2].Value = tempInvoiceApplicationEntity.BillStatus;
appParms[3].Value = tempInvoiceApplicationEntity.CustomerName;
appParms[4].Value = tempInvoiceApplicationEntity.InvoiceNO;
appParms[5].Value = tempInvoiceApplicationEntity.InvoiceCustomer;
appParms[6].Value = tempInvoiceApplicationEntity.BSNO;
appParms[7].Value = tempInvoiceApplicationEntity.VesselVoyage;
appParms[8].Value = tempInvoiceApplicationEntity.ETD;
appParms[9].Value = tempInvoiceApplicationEntity.POL;
appParms[10].Value = tempInvoiceApplicationEntity.POD;
appParms[11].Value = tempInvoiceApplicationEntity.FeeItem;
appParms[12].Value = tempInvoiceApplicationEntity.AmountList;
appParms[13].Value = tempInvoiceApplicationEntity.ApplyAmount;
appParms[14].Value = tempInvoiceApplicationEntity.AmountCapital;
appParms[15].Value = tempInvoiceApplicationEntity.Currency;
appParms[16].Value = tempInvoiceApplicationEntity.Remark;
appParms[17].Value = tempInvoiceApplicationEntity.Applicant;
appParms[18].Value = tempInvoiceApplicationEntity.MBLNO;
appParms[19].Value = tempInvoiceApplicationEntity.IsApply;
appParms[20].Value = tempInvoiceApplicationEntity.Rate;
appParms[21].Value = tempInvoiceApplicationEntity.CompanyID;
}
else
{
appParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_APP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APP_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOCIE_APP_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_APP_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICENO,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_POL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_POD,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_FEE_ITEM,SqlDbType.VarChar,8000),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_APP_APPLYAMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_APP_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APP_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APP_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_APP_IS_APPLY,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_APP_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_APP_COMPANY_ID,SqlDbType.VarChar,36)
};
appParms[0].Value = tempInvoiceApplicationEntity.GID;
appParms[1].Value = strNewBillNo;
appParms[2].Value = tempInvoiceApplicationEntity.BillStatus;
appParms[3].Value = tempInvoiceApplicationEntity.CustomerName;
appParms[4].Value = tempInvoiceApplicationEntity.InvoiceNO;
appParms[5].Value = tempInvoiceApplicationEntity.InvoiceCustomer;
appParms[6].Value = tempInvoiceApplicationEntity.BSNO;
appParms[7].Value = tempInvoiceApplicationEntity.VesselVoyage;
appParms[8].Value = tempInvoiceApplicationEntity.POL;
appParms[9].Value = tempInvoiceApplicationEntity.POD;
appParms[10].Value = tempInvoiceApplicationEntity.FeeItem;
appParms[11].Value = tempInvoiceApplicationEntity.AmountList;
appParms[12].Value = tempInvoiceApplicationEntity.ApplyAmount;
appParms[13].Value = tempInvoiceApplicationEntity.AmountCapital;
appParms[14].Value = tempInvoiceApplicationEntity.Currency;
appParms[15].Value = tempInvoiceApplicationEntity.Remark;
appParms[16].Value = tempInvoiceApplicationEntity.Applicant;
appParms[17].Value = tempInvoiceApplicationEntity.MBLNO;
appParms[18].Value = tempInvoiceApplicationEntity.IsApply;
appParms[19].Value = tempInvoiceApplicationEntity.Rate;
appParms[20].Value = tempInvoiceApplicationEntity.CompanyID;
}
#endregion
if (tempInvoiceApplicationEntity.ETD == DateTime.MinValue)
{
string SQL_INSERT_INVOICE_APP_NO_ETD = " INSERT INTO ch_fee_invoiceapplication(GID, BILLNO, BILLSTATUS, CUSTOMERNAME, INVOICENO, INVOICECUSTNAME, BSNO, VESSELVOYAGE, POL, POD, FEEITEM, AMOUNTLIST, "
+ " APPLYAMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME,MBLNO,ISAPPLY,RATE,COMPANYID ) "
+ " VALUES(@gid,@bill_no,@bill_status,@customer_name,@invoice_no,@invoice_customer,@bsno,@vessel_voyage,@pol,@pod,@fee_item,@amount_list"
+ ",@apply_amount,@amount_capital,@currency,@remark,@applicant,getdate(),@mblno,@is_apply,@rate,@company_id ) ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_APP_NO_ETD, appParms);
}
else
{
string SQL_INSERT_INVOICE_APP = "INSERT INTO ch_fee_invoiceapplication(GID, BILLNO, BILLSTATUS, CUSTOMERNAME, INVOICENO, INVOICECUSTNAME, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, AMOUNTLIST, "
+ " APPLYAMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME,MBLNO,ISAPPLY,RATE,COMPANYID ) "
+ " VALUES(@gid,@bill_no,@bill_status,@customer_name,@invoice_no,@invoice_customer,@bsno,@vessel_voyage,@etd,@pol,@pod,@fee_item,@amount_list"
+ ",@apply_amount,@amount_capital,@currency,@remark,@applicant,getdate(),@mblno,@is_apply,@rate,@company_id) ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_APP, appParms);
}
//将费用信息写入ch_fee_do表
foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
{
if (feeDoEntity.Orig == 1)
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_FEE_DO_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_BILL_NO, SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSNO, SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_MBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_HBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSTYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_FEE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_FEE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_CATEGORY,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_FEE_DO_ORIG_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEE_DO_ORIG_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_FEE_DO_COMPANY_ID,SqlDbType.VarChar,36)
};
parms[0].Value = feeDoEntity.GID;
parms[1].Value = strNewBillNo;
parms[2].Value = feeDoEntity.BSNO;
parms[3].Value = feeDoEntity.MBLNO;
parms[4].Value = feeDoEntity.HBLNO;
parms[5].Value = feeDoEntity.CustomerName;
parms[6].Value = feeDoEntity.BSType;
parms[7].Value = feeDoEntity.FeeID;
parms[8].Value = feeDoEntity.FeeName;
parms[9].Value = feeDoEntity.Currency;
parms[10].Value = feeDoEntity.Amount;
parms[11].Value = feeDoEntity.DoAmount;
parms[12].Value = feeDoEntity.FeeType;
parms[13].Value = feeDoEntity.Category;
parms[14].Value = feeDoEntity.BillStatus;
parms[15].Value = feeDoEntity.Remark;
parms[16].Value = feeDoEntity.OrigCurrency;
parms[17].Value = feeDoEntity.ExchangeRate;
parms[18].Value = feeDoEntity.OriginalFeeCSTL;
parms[19].Value = feeDoEntity.CompanyID;
//ch_fee_do
string SQL_INSERT_FEE_DO = " INSERT INTO ch_fee_do(GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,ORIGCURRENCY,EXCHANGERATE,ORIGAMOUNT,COMPANYID) "
+ " VALUES(@gid,@bill_no,@bsno,@mbl_no,@nbl_no,@customer_name,@bs_type,@fee_id,@fee_name,@currency,@amount,@do_amount,@fee_type,@category,@bill_status,@remark,@orig_currency,@exchange_rate,@orig_amount,@company_id) ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, parms);
//更新ch_fee表申请开票金额字段
SqlParameter[] feeParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_ORDER_INVOCE,SqlDbType.Decimal,20)
};
feeParms[0].Value = feeDoEntity.FeeID;
feeParms[1].Value = feeDoEntity.OriginalFeeCSTL;
string SQL_UPDATE_CH_FEE_ORDER_INVOICE = "UPDATE ch_fee SET ORDERINVOICE = ISNULL(ORDERINVOICE,0)+@order_invoice WHERE GID = @gid AND AMOUNT >= @order_invoice AND (AMOUNT-ISNULL(ORDERINVOICE,0)) >= @order_invoice";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_ORDER_INVOICE, feeParms);
}
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 将开票申请信息插入开票申请表ch_fee_invoiceapplication,但不进行申请操作
/// <summary>
/// 将开票申请信息插入开票申请表ch_fee_invoiceapplication,但不进行申请操作
/// </summary>
/// <param name="tempInvoiceApplicationEntity">开票信息实体类</param>
/// <param name="tempFeeDoEntities">FeeDo实体类</param>
/// <returns>值1表示插入成功 值-1表示插入失败 有异常</returns>
public int InsertInvoiceApplicationNoApply(InvoiceApplicationEntity tempInvoiceApplicationEntity, IList<FeeDoEntity> tempFeeDoEntities)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] parms = null;
if (tempInvoiceApplicationEntity.ETD != DateTime.MinValue)
{
parms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_APP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APP_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOCIE_APP_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_APP_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICENO,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_ETD,SqlDbType.DateTime),
new SqlParameter(PARM_INVOICE_APP_POL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_POD,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_APP_APPLYAMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_APP_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APP_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_APP_IS_APPLY,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_APP_APPLICANT,SqlDbType.VarChar,36)
};
parms[0].Value = tempInvoiceApplicationEntity.GID;
parms[1].Value = tempInvoiceApplicationEntity.BillNO;
parms[2].Value = tempInvoiceApplicationEntity.BillStatus;
parms[3].Value = tempInvoiceApplicationEntity.CustomerName;
parms[4].Value = tempInvoiceApplicationEntity.InvoiceNO;
parms[5].Value = tempInvoiceApplicationEntity.InvoiceCustomer;
parms[6].Value = tempInvoiceApplicationEntity.BSNO;
parms[7].Value = tempInvoiceApplicationEntity.VesselVoyage;
parms[8].Value = tempInvoiceApplicationEntity.ETD;
parms[9].Value = tempInvoiceApplicationEntity.POL;
parms[10].Value = tempInvoiceApplicationEntity.POD;
parms[11].Value = tempInvoiceApplicationEntity.FeeItem;
parms[12].Value = tempInvoiceApplicationEntity.AmountList;
parms[13].Value = tempInvoiceApplicationEntity.ApplyAmount;
parms[14].Value = tempInvoiceApplicationEntity.AmountCapital;
parms[15].Value = tempInvoiceApplicationEntity.Currency;
parms[16].Value = tempInvoiceApplicationEntity.Remark;
parms[17].Value = tempInvoiceApplicationEntity.MBLNO;
parms[18].Value = tempInvoiceApplicationEntity.IsApply;
parms[19].Value = tempInvoiceApplicationEntity.Applicant;
}
else
{
parms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_APP_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APP_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOCIE_APP_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_APP_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICENO,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_APP_POL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_POD,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_APP_APPLYAMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_APP_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_APP_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_APP_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APP_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_APP_IS_APPLY,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_APP_APPLICANT,SqlDbType.VarChar,36)
};
parms[0].Value = tempInvoiceApplicationEntity.GID;
parms[1].Value = tempInvoiceApplicationEntity.BillNO;
parms[2].Value = tempInvoiceApplicationEntity.BillStatus;
parms[3].Value = tempInvoiceApplicationEntity.CustomerName;
parms[4].Value = tempInvoiceApplicationEntity.InvoiceNO;
parms[5].Value = tempInvoiceApplicationEntity.InvoiceCustomer;
parms[6].Value = tempInvoiceApplicationEntity.BSNO;
parms[7].Value = tempInvoiceApplicationEntity.VesselVoyage;
parms[8].Value = tempInvoiceApplicationEntity.POL;
parms[9].Value = tempInvoiceApplicationEntity.POD;
parms[10].Value = tempInvoiceApplicationEntity.FeeItem;
parms[11].Value = tempInvoiceApplicationEntity.AmountList;
parms[12].Value = tempInvoiceApplicationEntity.ApplyAmount;
parms[13].Value = tempInvoiceApplicationEntity.AmountCapital;
parms[14].Value = tempInvoiceApplicationEntity.Currency;
parms[15].Value = tempInvoiceApplicationEntity.Remark;
parms[16].Value = tempInvoiceApplicationEntity.MBLNO;
parms[17].Value = tempInvoiceApplicationEntity.IsApply;
parms[18].Value = tempInvoiceApplicationEntity.Applicant;
}
if (tempInvoiceApplicationEntity.ETD == DateTime.MinValue)
{
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_APP_NO_APPLY_NO_ETD, parms);
}
else
{
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_APP_NO_APPLY, parms);
}
//将费用信息写入ch_fee_do表
foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
{
if (feeDoEntity.Orig == 1)
{
SqlParameter[] feeDoParms = new SqlParameter[]{
new SqlParameter(PARM_FEE_DO_GID, SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_BILL_NO, SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSNO, SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_MBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_HBL_NO,SqlDbType.VarChar,30),
new SqlParameter(PARM_FEE_DO_CUSTOMER_NAME,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_BSTYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_FEE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_FEE_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_FEE_DO_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_DO_AMOUNT,SqlDbType.Decimal,40),
new SqlParameter(PARM_FEE_DO_FEE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_CATEGORY,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_BILL_STATUS,SqlDbType.Int),
new SqlParameter(PARM_FEE_DO_REMARK,SqlDbType.VarChar,1024)
};
feeDoParms[0].Value = feeDoEntity.GID;
feeDoParms[1].Value = feeDoEntity.BillNO;
feeDoParms[2].Value = feeDoEntity.BSNO;
feeDoParms[3].Value = feeDoEntity.MBLNO;
feeDoParms[4].Value = feeDoEntity.HBLNO;
feeDoParms[5].Value = feeDoEntity.CustomerName;
feeDoParms[6].Value = feeDoEntity.BSType;
feeDoParms[7].Value = feeDoEntity.FeeID;
feeDoParms[8].Value = feeDoEntity.FeeName;
feeDoParms[9].Value = feeDoEntity.Currency;
feeDoParms[10].Value = feeDoEntity.Amount;
feeDoParms[11].Value = feeDoEntity.DoAmount;
feeDoParms[12].Value = feeDoEntity.FeeType;
feeDoParms[13].Value = feeDoEntity.Category;
feeDoParms[14].Value = feeDoEntity.BillStatus;
feeDoParms[15].Value = feeDoEntity.Remark;
//ch_fee_do
string SQL_INSERT_FEE_DO = " INSERT INTO ch_fee_do(GID,BILLNO,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,ORIGCURRENCY,EXCHANGERATE,ORIGAMOUNT,COMPANYID) "
+ " VALUES(@gid,@bill_no,@bsno,@mbl_no,@nbl_no,@customer_name,@bs_type,@fee_id,@fee_name,@currency,@amount,@do_amount,@fee_type,@category,@bill_status,@remark,@orig_currency,@exchange_rate,@orig_amount,@company_id) ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, feeDoParms);
}
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 获取SQL语句查询数据集
/// <summary>
/// 获取SQL语句查询数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet tempSet = new DataSet();
tempSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return tempSet;
}
#endregion
#region 获取发票申请页数信息
/// <summary>
/// 获取发票申请页数信息
/// </summary>
/// <param name="tempSql">执行的SQL语句</param>
/// <returns>返回总页数</returns>
public int GetInvoiceApplicationPageCount(string tempSql)
{
int iResult = 0;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, tempSql, null))
{
try
{
while (sqlRead.Read())
{
iResult = sqlRead.GetInt32(0);
}
}
catch (Exception error)
{
throw error;
}
}
return iResult;
}
#endregion
#region 生成发票编号起始串
/// <summary>
/// 生成发票编号起始串
/// </summary>
/// <param name="tempNowDateTime">当前服务器时间</param>
/// <param name="tempBeginTitle">发票编号起始串头字母</param>
/// <param name="tempCodeLength">发票编号累计编码长度</param>
/// <returns>返回发票编号起始串</returns>
private string CreateBeginTitleCode(DateTime tempNowDateTime, string tempBeginTitle, int tempCodeLength)
{
int CodeLength = tempCodeLength;
string strFeeType = tempBeginTitle;
//解析当前时间
DateTime nowDateTime = tempNowDateTime;
string strYear = nowDateTime.Year.ToString();
string strMonth = nowDateTime.Month.ToString().Length < 2 ? "0" + nowDateTime.Month.ToString() : nowDateTime.Month.ToString();
//获取年+月组合的字符串
string strDateTime = strYear + strMonth;
//将申请编号抬头+日期作为结算编号
string strCodePrefix = strFeeType + strDateTime;
return strCodePrefix;
}
#endregion
#region 生成发票编号
/// <summary>
/// 生成发票编号
/// </summary>
/// <param name="tempNowDateTime">当前服务器时间</param>
/// <param name="tempBeginTitle">发票编号起始串头字母</param>
/// <param name="tempCodeLength">发票编号累计编码长度</param>
/// <param name="tempLastBillNo">最大结算编号</param>
/// <returns>返回新的发票编号</returns>
private string CreateSettleCode(DateTime tempNowDateTime, string tempBeginTitle, int tempCodeLength, string tempLastBillNo)
{
int CodeLength = tempCodeLength;
string strSettleCode = "";
string strFeeType = tempBeginTitle;
//解析当前时间
DateTime nowDateTime = tempNowDateTime;
string strYear = nowDateTime.Year.ToString();
string strMonth = nowDateTime.Month.ToString().Length < 2 ? "0" + nowDateTime.Month.ToString() : nowDateTime.Month.ToString();
//获取年+月组合的字符串
string strDateTime = strYear + strMonth;
//将结算编号抬头+日期作为结算编号
string strCodePrefix = strFeeType + strDateTime;
//string strSql = "SELECT TOP 1 BILLNO FROM ch_fee_payapplication WHERE BILLNO LIKE '" + strFeeType + strDateTime + "%' ORDER BY BILLNO DESC";
//DataTable billTable = feeDoDA.GetExcuteSql(strSql).Tables[0];
ArrayList codeArg = new ArrayList();
for (int i = 0; i < CodeLength; i++)
{
codeArg.Add(0);
}
string strCode = "";//编号
if (tempLastBillNo != "")
{
string oldCode = tempLastBillNo;
if (oldCode.IndexOf(strCodePrefix) >= 0)
{
oldCode = oldCode.Substring(strCodePrefix.Length, oldCode.Length - strCodePrefix.Length);
if (oldCode.Length == CodeLength)
{
for (int i = 0; i < oldCode.Length; i++)
{
if (oldCode[i].ToString().IndexOf("0") == 0)
{
oldCode = oldCode.Remove(i, 1);
i = -1;
continue;
}
else
{
break;
}
}
}
}
int newNum = int.Parse(oldCode);
newNum = newNum + 1;
string strNewNum = newNum.ToString();
int codeArgCount = codeArg.Count - 1;
for (int i = strNewNum.Length - 1; i >= 0; i--)
{
codeArg[codeArgCount] = strNewNum[i];
codeArgCount--;
}
//for (int i = 0; i < strNewNum.Length; i++)
//{
// codeArg[i] = strNewNum[i];
//}
}
else
{
int iOld = int.Parse(codeArg[codeArg.Count - 1].ToString());
codeArg[codeArg.Count - 1] = (iOld + 1).ToString();
}
for (int i = 0; i < codeArg.Count; i++)
{
strCode += codeArg[i].ToString();
}
strSettleCode = strFeeType + strDateTime + strCode;
return strSettleCode;
}
#endregion
}
}