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.

2342 lines
148 KiB
C#

11 months ago
using System;
using System.Data;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
using System.Collections;
using System.Collections.Generic;
namespace DSWeb.EntityDA
{
public class InvoiceDA
{
//ch_fee_invoice
private const string PARM_INVOICE_GID = "@gid";
private const string PARM_INVOICE_BILL_NO = "@bill_no";
private const string PARM_INVOICE_INVOICE_NO = "@invoice_no";
private const string PARM_INVOICE_CUSTOMER_NAME = "@customer_name";
private const string PARM_INVOICE_INVOICE_CUST_NAME = "@invoice_customer";
private const string PARM_INVOICE_INVOICE_MAKE_TIME = "@invoice_make_time";
private const string PARM_INVOICE_BSNO = "@bsno";
private const string PARM_INVOICE_VESSEL_VOYAGE = "@vessel_voyage";
private const string PARM_INVOICE_ETD = "@etd";
private const string PARM_INVOICE_POL = "@pol";
private const string PARM_INVOICE_POD = "@pod";
private const string PARM_INVOICE_FEE_ITEM = "@fee_item";
private const string PARM_INVOICE_AMOUNT_LIST = "@amount_list";
private const string PARM_INVOICE_AMOUNT = "@amount";
private const string PARM_INVOICE_AMOUNT_CAPITAL = "@amount_capital";
private const string PARM_INVOICE_CURRENCY = "@currency";
private const string PARM_INVOICE_REMARK = "@remark";
private const string PARM_INVOICE_APPLICANT = "@applicant";
private const string PARM_INVOICE_APPLY_TIME = "@apply_time";
private const string PARM_INVOICE_OPERATOR = "@operator";
private const string PARM_INVOICE_LICENSE_CODE = "@license_code";
private const string PARM_INVOICE_TAX_CODE = "@tax_code";
private const string PARM_INVOICE_INVOICE_TYPE = "@invoice_type";
private const string PARM_INVOICE_IS_DELETE = "@is_delete";
private const string PARM_INVOICE_DELETE_OPERATOR = "@delete_operator";
private const string PARM_INVOICE_DELETE_TIME = "@delete_time";
private const string PARM_INVOICE_IS_NEED_PRINT = "@is_need_print";
private const string PARM_INVOICE_IS_NEED_FEE = "@is_need_fee";
private const string PARM_INVOICE_BANK = "@bank";
private const string PARM_INVOICE_ACCOUNT = "@account";
private const string PARM_INVOICE_OPERATE_TIME = "@operate_time";
private const string PARM_INVOICE_MBLNO = "@mblno";
private const string PARM_INVOICE_EXCHANGE_RATE = "@exchange_rate";
private const string PARM_INVOICE_PRINT_CAPITAL = "@print_capital";
private const string PARM_INVOICE_PRINT_AMOUNT = "@print_amount";
private const string PARM_INVOICE_PRINT_TITLE = "@print_title";
private const string PARM_INVOICE_RATE = "@rate";
private const string PARM_INVOICE_LIKE = "@like";
private const string PARM_INVOICE_COMPANY_ID = "@company_id";
//ch_fee_invoiceapplication
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_OPERATOR = "@operator";
private const string PARM_INVOICE_APP_OPERATE_TIME = "@operate_time";
//ch_fee_do
private const string PARM_FEE_DO_GID = "@gid";
private const string PARM_FEE_DO_BILL_NO = "@bill_no";
private const string PARM_FEE_DO_BSNO = "@bsno";
private const string PARM_FEE_DO_MBL_NO = "@mbl_no";
private const string PARM_FEE_DO_HBL_NO = "@nbl_no";
private const string PARM_FEE_DO_CUSTOMER_NAME = "@customer_name";
private const string PARM_FEE_DO_BSTYPE = "@bs_type";
private const string PARM_FEE_DO_FEE_ID = "@fee_id";
private const string PARM_FEE_DO_FEE_NAME = "@fee_name";
private const string PARM_FEE_DO_CURRENCY = "@currency";
private const string PARM_FEE_DO_AMOUNT = "@amount";
private const string PARM_FEE_DO_DO_AMOUNT = "@do_amount";
private const string PARM_FEE_DO_FEE_TYPE = "@fee_type";
private const string PARM_FEE_DO_CATEGORY = "@category";
private const string PARM_FEE_DO_BILL_STATUS = "@bill_status";
private const string PARM_FEE_DO_REMARK = "@remark";
private const string PARM_FEE_DO_ORIG_CURRENCY = "@orig_currency";
private const string PARM_FEE_DO_EXCHANGE_RATE = "@exchange_rate";
private const string PARM_FEE_DO_ORIG_AMOUNT = "@orig_amount";
private const string PARM_FEE_DO_COMPANY_ID = "@company_id";
private const string PARM_FEE_DO_INVOICEAPP_BILLNO = "@invoiceapp_billno";
//ch_fee
private const string PARM_FEE_GID = "@gid";
private const string PARM_FEE_ORDER_INVOCE = "@order_invoice";
private const string PARM_FEE_STATUS = "@fee_status";
private const string PARM_FEE_INVOICE = "@invoice";
private const string PARM_FEE_ISINVOICE = "@is_invoice";
//ch_fee_invoicebooks
//private string PARM_INVOICE_BOOK_GID = "@gid";
//ch_fee_invoiceitems
//private string PARM_INVOICE_BOOK_ITEM_GID = "@gid";
private string PARM_INVOICE_BOOK_ITEM_INVOICE_NUM = "@invoice_num";
private string PARM_INVOICE_BOOK_ITEM_IS_MAKE_OUT = "@is_makeout";
//private string PARM_INVOICE_BOOK_ITEM_MAKEOUT_TIME = "@makeout_time";
private string PARM_INVOICE_BOOK_ITEM_MAKEOUT_USER = "@makeout_user";
//结算关联表ch_fee_settle_link
private const string PARM_CH_FEE_SETTLE_LINK = "@gid";
private const string PARM_CH_FEE_SETTLE_SETTLE_ID = "@settle_id";
private const string PARM_CH_FEE_SETTLE_TYPE = "@type";
private const string PARM_CH_FEE_SETTLE_RELATION_SUB_ID = "@relation_sub_id";
private const string PARM_CH_FEE_SETTLE_CREATE_USER = "@create_user";
private const string PARM_CH_FEE_SETTLE_CREATE_TIME = "@create_time";
private const string SQL_SELECT_GET_SERVERTIME = " SELECT GETDATE() ";//获取服务端时间
private const string SQL_SELECT_INVOICE_BY_GID = " SELECT GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, "
+ " AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE, "
+ " ISDELETE, DELETEOPERATOR, DELETETIME, ISNEEDPRINT, ISNEEDFEE FROM ch_fee_invoice WHERE GID = @gid ";
private const string SQL_SELECT_INVOICE_BY_BILLNO = " SELECT GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, "
+ " AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE, "
+ " ISDELETE, DELETEOPERATOR, DELETETIME, ISNEEDPRINT, ISNEEDFEE FROM ch_fee_invoice WHERE BILLNO = @bill_no ";
private const string SQL_INSERT_INVOICE = " INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM,"
+ " AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE,"
+ " ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,PRINTTITLE,COMPANYID )"
+ " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@etd,@pol,@pod,@fee_item,@amount_list, "
+ " @amount,@amount_capital,@currency,@remark,@applicant,@apply_time,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),"
+ " @is_delete,@mblno,@exchange_rate,@print_amount,@print_capital,@print_title,@company_id)";
private const string SQL_INSERT_INVOICE_NO_ETD = " INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, POL, POD, FEEITEM,"
+ " AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE,"
+ " ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,PRINTTITLE,COMPANYID )"
+ " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@pol,@pod,@fee_item,@amount_list, "
+ " @amount,@amount_capital,@currency,@remark,@applicant,@apply_time,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),"
+ " @is_delete,@mblno,@exchange_rate,@print_amount,@print_capital,@print_title,@company_id)";
//private const string SQL_INSERT_INVOICE_DIRECT = " INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE, ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,COMPANYID,APPLICANT )"
// + " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@etd,@pol,@pod,@fee_item,@amount_list, "
// + " @amount,@amount_capital,@currency,@remark,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),@is_delete,@mblno,"
// + " @exchange_rate,@print_amount,@print_capital,@print_title,@company_id,@APPLICANT)";
//private const string SQL_INSERT_INVOICE_DIRECT_NO_ETD = " INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, POL, POD, FEEITEM, AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE, ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,PRINTTITLE,COMPANYID,APPLICANT )"
// + " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@pol,@pod,@fee_item,@amount_list, "
// + " @amount,@amount_capital,@currency,@remark,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),@is_delete,@mblno,"
// + " @exchange_rate,@print_amount,@print_capital,@print_title,@company_id,@APPLICANT)";
//ch_fee_do
private const 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) ";
private const string SQL_UPDATE_FEE_ORDER_INVOICE = "UPDATE ch_fee SET ORDERINVOICE=0,INVOICENUM='' WHERE GID = @gid";
//更新ch_fee_invoiceapplication状态
private const string SQL_UPDATE_INVOICE_APPLICATION_STATUS = "UPDATE ch_fee_invoiceapplication SET BILLSTATUS = @bill_status WHERE BILLNO = @bill_no";
//更新ch_fee_do表状态
private const string SQL_UPDATE_FEE_DO_CATEGORY = "UPDATE ch_fee_do SET CATEGORY = 7 WHERE BILLNO = @bill_no AND CATEGORY = @category";
//打印发票
private const string SQL_UPDATE_INVOICE_IS_NEED_PRINT = "UPDATE ch_fee_invoice SET ISNEEDPRINT = 1 WHERE GID = @gid";
private const string SQL_UPDATE_CH_FEE_INVOICE_APPLICATION = " UPDATE ch_fee_invoiceapplication SET INVOICENO = A.INVOICENO,INVOICECUSTNAME = A.INVOICECUSTNAME,"
+ " OPERATOR = A.OPERATOR,OPERATETIME = A.INVOICEMAKETIME,CUSTOMERNAME = A.CUSTOMERNAME,BILLSTATUS = 3 "
+ " FROM ch_fee_invoice as A WHERE ch_fee_invoiceapplication.BILLNO = A.BILLNO AND A.BILLNO = @bill_no ";
//private const string SQL_UPDATE_CH_FEE_INVOICE = " UPDATE ch_fee SET ISINVOICE = @is_invoice,INVOICE = @INVOICE WHERE GID = @gid ";
private const string SQL_SELECT_CH_FEE_INVOIC_APPLICATION_OPERATE_TIME = "SELECT OPERATETIME FROM ch_fee_invoiceapplication WHERE GID = @gid";
private const string SQL_UPDATE_CH_FEE_INVOCIE_ITEMS_MAKEOUT = " UPDATE ch_fee_invoiceitems SET ISMAKEOUT = @is_makeout,MAKEOUTTIME = GETDATE(),MAKEOUTUSER = @makeout_user WHERE INVOICENUM = @invoice_num";
private const string SQL_UPDATE_CH_FEE_INVOICE_BY_DO = " UPDATE ch_fee SET ch_fee.INVOICE = C.INVOICE,INVOICENUM = @invoice_no,ISINVOICE = 1"
+ " FROM ( SELECT B.GID,CASE WHEN B.AMOUNT < A.AMOUNT THEN A.AMOUNT-B.AMOUNT ELSE B.AMOUNT END as INVOICE "
+ " FROM ch_fee_do as A INNER JOIN ch_fee as B ON A.FEEID = B.GID WHERE BILLNO = @bill_no) as C WHERE ch_fee.GID = C.GID";
private const string SQL_UPDATE_CH_FEE_INVOICE = "UPDATE ch_fee SET INVOICE = ISNULL(INVOICE,0)+@invoice WHERE GID = @gid AND AMOUNT >= @invoice AND (AMOUNT-INVOICE) >= @invoice";
//获取最大发票开出业务编号
private const string SQL_SELECT_LAST_BILL_NO = " SELECT TOP 1 BILLNO FROM ch_fee_invoice WHERE BILLNO LIKE @like AND COMPANYID = @company_id ORDER BY BILLNO DESC ";
//发票申请开出时发票申请ch_fee_do生成发票开出ch_fee_do
private const string SQL_INSERT_FEE_DO_APP_TO_MAKEOUT = " 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) "
+ " SELECT newid(),@bill_no,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,ORIGCURRENCY,EXCHANGERATE,ORIGAMOUNT,COMPANYID FROM ch_fee_do WHERE ch_fee_do.BILLNO = @invoiceapp_billno AND COMPANYID = @company_id ";
//建立发票开出关联信息(生成发票开出和发票申请关联关系)
private const string SQL_INSERT_CH_FEE_SETTLE_LINK = " INSERT INTO ch_fee_settle_link(GID,TYPE,SETTLEID,RELATIONSUBID,CREATEUSER,CREATETIME) "
+ " VALUES(newid(),@type,@settle_id,@relation_sub_id,@create_user,GETDATE()) ";
//更新发票申请记录表示已开出发票
private const string SQL_UPDATE_CH_FEE_INVOICEAPP_STATUS = " UPDATE ch_fee_invoiceapplication SET BILLSTATUS = 3 WHERE GID = @gid ";
//根据发票开出费用明细更新费用表
private const string SQL_UPDATE_CH_FEE_BY_CH_FEE_DO_FOR_MERGE = " UPDATE ch_fee SET ch_fee.INVOICE = ISNULL(ch_fee.INVOICE,0) + ch_fee_do.ORIGAMOUNT,ch_fee.INVOICENUM = @INVOICENUM "
+ " FROM ch_fee_do WHERE ch_fee.GID = ch_fee_do.FEEID AND ch_fee_do.BILLNO = @bill_no AND ch_fee_do.COMPANYID = @company_id ";
#region 打印发票
/// <summary>
/// 打印发票
/// </summary>
/// <param name="tempInvoiceGID">发票GID</param>
/// <returns>值1表示打印成功 值小于1表示打印失败</returns>
public int PrintInvoiceByGID(string tempInvoiceGID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] printIVParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36)
};
printIVParms[0].Value = tempInvoiceGID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_INVOICE_IS_NEED_PRINT, printIVParms);
//事务提交
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="tempInvoiceGID">发票GID</param>
/// <param name="strOperatorGID">操作人GID</param>
/// <returns>值1表示废除成功 值小于1表示废除失败</returns>
public int VoidInvoiceByGID(string tempInvoiceGID, string strOperatorGID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//删除ch_fee_do表中发票相关的信息
string SQL_DELETE_FEE_DO = "update ch_fee_do set ISDELETED=1,DELETEUSER = '" + strOperatorGID + "',DELETETIME = GETDATE() WHERE BILLNO in (select billno from ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "')";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_FEE_DO, null);
//废除发票
string SQL_UPDATE_INVOICE_VOID = "UPDATE ch_fee_invoice SET DELETEOPERATOR = '" + strOperatorGID + "',DELETETIME = GETDATE(),ISDELETE = 1 WHERE GID = '" + tempInvoiceGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_INVOICE_VOID, null);
string ls = "UPDATE ch_fee_invoiceapplication SET BILLSTATUS=2 WHERE BILLSTATUS=3 and gid in (select RELATIONSUBID from ch_fee_settle_link where SETTLEID = '" + tempInvoiceGID + "')";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, ls, null);
//
//string SQL_UPDATE_CH_FEE_ORDERINVOICE_FOR_VOID = " UPDATE ch_fee SET ORDERINVOICE = ORDERINVOICE - D.ORIGAMOUNT "
//+ " FROM ( SELECT FEEID,ORIGAMOUNT FROM ch_fee_invoiceapplication AS A INNER JOIN ch_fee_do AS B "
//+ " ON A.BILLNO = B.BILLNO AND A.COMPANYID = B.COMPANYID INNER JOIN ch_fee_settle_link as C ON C.RELATIONSUBID = A.GID "
//+ " WHERE C.SETTLEID = '" + tempInvoiceGID + "' ) AS D WHERE ch_fee.GID = D.FEEID ";
string SQL_UPDATE_CH_FEE_ORDERINVOICE_FOR_VOID = " UPDATE ch_fee SET INVOICENUM='',INVOICE=isnull((INVOICE - D.ORIGAMOUNT),0)"
+ " FROM ( SELECT FEEID,ORIGAMOUNT FROM ch_fee_invoiceapplication AS A INNER JOIN ch_fee_do AS B "
+ " ON A.BILLNO = B.BILLNO AND A.COMPANYID = B.COMPANYID INNER JOIN ch_fee_settle_link as C ON C.RELATIONSUBID = A.GID "
+ " WHERE C.SETTLEID = '" + tempInvoiceGID + "' ) AS D WHERE ch_fee.GID = D.FEEID ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_ORDERINVOICE_FOR_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 申请发票删除
public int DeleteInvoiceByGID(string tempInvoiceGID, string invoiceBillNO, string strUserID)//IList<FeeDoEntity> tempFeeDoEntities
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
//{
//}
//更新ch_fee表请求开票费信息
string sls = "UPDATE ch_fee SET INVOICENUM='',INVOICE=0 WHERE GID in (select feeid from ch_fee_do where BILLNO = '" + invoiceBillNO + "')";//tempFeeDoEntities[0].BillNO
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sls, null);
//更新ch_fee_invoiceapplication表申请状态
sls = "UPDATE ch_fee_invoiceapplication SET BILLSTATUS=2 WHERE GID=(select top 1 RELATIONSUBID FROM ch_fee_settle_link WHERE SETTLEID = '" + tempInvoiceGID + "') and BILLSTATUS=3";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sls, null);
//删除ch_fee_do表中发票相关的信息
string SQL_DELETE_FEE_DO = "DELETE FROM ch_fee_do WHERE BILLNO = '" + invoiceBillNO + "'";//tempFeeDoEntities[0].BillNO
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_FEE_DO, null);
//删除发票关联信息
string ls = "DELETE FROM ch_fee_settle_link WHERE SETTLEID = '" + tempInvoiceGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, ls, null);
//还原发票册状态
string sSQL = " UPDATE ch_fee_invoiceitems SET ISMAKEOUT=0,MAKEOUTTIME=GETDATE(),MAKEOUTUSER='" + strUserID + "' WHERE INVOICENUM = (select top 1 INVOICENO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "')";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
//删除发票信息
string SQL_DELETE_INVOICE = "DELETE FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_INVOICE, null);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 自由发票删除
public int DeleteInvoiceByGID2(string tempInvoiceGID, string invoiceBillNO, string strUserID)//IList<FeeDoEntity> tempFeeDoEntities
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
//{
//}
//更新ch_fee表请求开票费信息
string sls = "UPDATE ch_fee SET INVOICENUM='',INVOICE=0,ORDERINVOICE=0 WHERE GID in (select feeid from ch_fee_do where BILLNO = '" + invoiceBillNO + "')";//tempFeeDoEntities[0].BillNO
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sls, null);
//删除ch_fee_do表中发票相关的信息
string SQL_DELETE_FEE_DO = "DELETE FROM ch_fee_do WHERE BILLNO = '" + invoiceBillNO + "'";//tempFeeDoEntities[0].BillNO
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_FEE_DO, null);
//删除发票关联信息
string ls = "DELETE FROM ch_fee_settle_link WHERE SETTLEID = '" + tempInvoiceGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, ls, null);
//还原发票册状态
string sSQL = " UPDATE ch_fee_invoiceitems SET ISMAKEOUT=0,MAKEOUTTIME=GETDATE(),MAKEOUTUSER='" + strUserID + "' WHERE INVOICENUM = (select top 1 INVOICENO FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "')";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSQL, null);
//删除发票信息
string SQL_DELETE_INVOICE = "DELETE FROM ch_fee_invoice WHERE GID = '" + tempInvoiceGID + "'";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_DELETE_INVOICE, 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>
/// <param name="tempBillNO">发票申请编号BILLNO</param>
/// <returns>InvoiceEntity实体类</returns>
public InvoiceEntity GetInvoiceByBillNO(string tempBillNO)
{
//初始化返回变量
InvoiceEntity invoiceEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_INVOICE_BILL_NO, SqlDbType.VarChar, 20);
parm.Value = tempBillNO;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INVOICE_BY_BILLNO, parm))
{
try
{
invoiceEntity = new InvoiceEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
invoiceEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
invoiceEntity.InvoiceNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
invoiceEntity.BillNO = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
invoiceEntity.CustomerName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
invoiceEntity.InvoiceCustName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
invoiceEntity.InvoiceMakeTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
invoiceEntity.Bank = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
invoiceEntity.Account = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
invoiceEntity.BSNO = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
invoiceEntity.VesselVoyage = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
invoiceEntity.ETD = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
invoiceEntity.POL = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
invoiceEntity.POD = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
invoiceEntity.FeeItem = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
invoiceEntity.AmountList = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
invoiceEntity.Amount = sqlRead.GetDecimal(15);
}
if (!sqlRead.IsDBNull(16))
{
invoiceEntity.AmountCapital = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
invoiceEntity.Currency = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
invoiceEntity.Remark = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
invoiceEntity.Applicant = sqlRead.GetString(19);
}
if (!sqlRead.IsDBNull(20))
{
invoiceEntity.ApplyTime = sqlRead.GetDateTime(20);
}
if (!sqlRead.IsDBNull(21))
{
invoiceEntity.Operator = sqlRead.GetString(21);
}
if (!sqlRead.IsDBNull(22))
{
invoiceEntity.LicenseCode = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
invoiceEntity.TaxCode = sqlRead.GetString(23);
}
if (!sqlRead.IsDBNull(24))
{
invoiceEntity.InvoiceType = sqlRead.GetInt32(24);
}
if (!sqlRead.IsDBNull(25))
{
invoiceEntity.IsDelete = sqlRead.GetBoolean(25);
}
if (!sqlRead.IsDBNull(26))
{
invoiceEntity.DeleteOperator = sqlRead.GetString(26);
}
if (!sqlRead.IsDBNull(27))
{
invoiceEntity.DeleteTime = sqlRead.GetDateTime(27);
}
if (!sqlRead.IsDBNull(28))
{
invoiceEntity.IsNeedPrint = sqlRead.GetBoolean(28);
}
if (!sqlRead.IsDBNull(29))
{
invoiceEntity.IsNeedFee = sqlRead.GetBoolean(29);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return invoiceEntity;
}
#endregion
#region 通过发票GID获取发票信息
/// <summary>
/// 通过发票GID获取发票信息
/// </summary>
/// <param name="tempGID">发票GID</param>
/// <returns>InvoiceEntity实体类</returns>
public InvoiceEntity GetInvoiceByGID(string tempGID)
{
//初始化返回变量
InvoiceEntity invoiceEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_INVOICE_GID, SqlDbType.VarChar, 36);
parm.Value = tempGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INVOICE_BY_GID, parm))
{
try
{
invoiceEntity = new InvoiceEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
invoiceEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
invoiceEntity.InvoiceNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
invoiceEntity.BillNO = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
invoiceEntity.CustomerName = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
invoiceEntity.InvoiceCustName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
invoiceEntity.InvoiceMakeTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
invoiceEntity.Bank = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
invoiceEntity.Account = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
invoiceEntity.BSNO = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
invoiceEntity.VesselVoyage = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
invoiceEntity.ETD = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
invoiceEntity.POL = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
invoiceEntity.POD = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
invoiceEntity.FeeItem = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
invoiceEntity.AmountList = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
invoiceEntity.Amount = sqlRead.GetDecimal(15);
}
if (!sqlRead.IsDBNull(16))
{
invoiceEntity.AmountCapital = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
invoiceEntity.Currency = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
invoiceEntity.Remark = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
invoiceEntity.Applicant = sqlRead.GetString(19);
}
if (!sqlRead.IsDBNull(20))
{
invoiceEntity.ApplyTime = sqlRead.GetDateTime(20);
}
if (!sqlRead.IsDBNull(21))
{
invoiceEntity.Operator = sqlRead.GetString(21);
}
if (!sqlRead.IsDBNull(22))
{
invoiceEntity.LicenseCode = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
invoiceEntity.TaxCode = sqlRead.GetString(23);
}
if (!sqlRead.IsDBNull(24))
{
invoiceEntity.InvoiceType = sqlRead.GetInt32(24);
}
if (!sqlRead.IsDBNull(25))
{
invoiceEntity.IsDelete = sqlRead.GetBoolean(25);
}
if (!sqlRead.IsDBNull(26))
{
invoiceEntity.DeleteOperator = sqlRead.GetString(26);
}
if (!sqlRead.IsDBNull(27))
{
invoiceEntity.DeleteTime = sqlRead.GetDateTime(27);
}
if (!sqlRead.IsDBNull(28))
{
invoiceEntity.IsNeedPrint = sqlRead.GetBoolean(28);
}
if (!sqlRead.IsDBNull(29))
{
invoiceEntity.IsNeedFee = sqlRead.GetBoolean(29);
}
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return invoiceEntity;
}
#endregion
#region ####
//public int InsertInvoice(InvoiceEntity tempInvoiceEntity, IList<FeeDoEntity> tempFeeDoEntities, string tempOldBillNO)
//{
// int iResult = 0;
// using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
// {
// try
// {
// SqlParameter[] makeParms = null;
// if (tempInvoiceEntity.ETD == DateTime.MinValue)
// {
// #region 插入开票记录参数
// makeParms = new SqlParameter[] {
// new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
// new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
// new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
// new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200)
// };
// makeParms[0].Value = tempInvoiceEntity.GID;
// makeParms[1].Value = tempInvoiceEntity.BillNO;
// makeParms[2].Value = tempInvoiceEntity.CustomerName;
// makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
// makeParms[4].Value = tempInvoiceEntity.Bank;
// makeParms[5].Value = tempInvoiceEntity.Account;
// makeParms[6].Value = tempInvoiceEntity.BSNO;
// makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
// makeParms[8].Value = tempInvoiceEntity.POL;
// makeParms[9].Value = tempInvoiceEntity.POD;
// makeParms[10].Value = tempInvoiceEntity.FeeItem;
// makeParms[11].Value = tempInvoiceEntity.AmountList;
// makeParms[12].Value = tempInvoiceEntity.Amount;
// makeParms[13].Value = tempInvoiceEntity.AmountCapital;
// makeParms[14].Value = tempInvoiceEntity.Currency;
// makeParms[15].Value = tempInvoiceEntity.Remark;
// makeParms[16].Value = tempInvoiceEntity.Applicant;
// makeParms[17].Value = tempInvoiceEntity.ApplyTime;
// makeParms[18].Value = tempInvoiceEntity.Operator;
// makeParms[19].Value = tempInvoiceEntity.LicenseCode;
// makeParms[20].Value = tempInvoiceEntity.TaxCode;
// makeParms[21].Value = tempInvoiceEntity.InvoiceType;
// makeParms[22].Value = tempInvoiceEntity.IsNeedPrint;
// makeParms[23].Value = tempInvoiceEntity.IsNeedFee;
// makeParms[24].Value = tempInvoiceEntity.IsDelete;
// makeParms[25].Value = tempInvoiceEntity.InvoiceNO;
// makeParms[26].Value = tempInvoiceEntity.MBLNO;
// makeParms[27].Value = tempInvoiceEntity.ExchangeRate;
// makeParms[28].Value = tempInvoiceEntity.PrintAmount;
// makeParms[29].Value = tempInvoiceEntity.PrintCaptial;
// makeParms[30].Value = tempInvoiceEntity.PrintTitle;
// #endregion
// int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_NO_ETD, makeParms);
// if (existVal > 0)
// {
// iResult = 1;
// }
// else
// {
// iResult = -1;//执行异常
// }
// }
// else
// {
// #region 插入开票记录参数
// makeParms = new SqlParameter[] {
// new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_ETD,SqlDbType.SmallDateTime),
// new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
// new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
// new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
// new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200)
// };
// makeParms[0].Value = tempInvoiceEntity.GID;
// makeParms[1].Value = tempInvoiceEntity.BillNO;
// makeParms[2].Value = tempInvoiceEntity.CustomerName;
// makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
// makeParms[4].Value = tempInvoiceEntity.Bank;
// makeParms[5].Value = tempInvoiceEntity.Account;
// makeParms[6].Value = tempInvoiceEntity.BSNO;
// makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
// makeParms[8].Value = tempInvoiceEntity.ETD;
// makeParms[9].Value = tempInvoiceEntity.POL;
// makeParms[10].Value = tempInvoiceEntity.POD;
// makeParms[11].Value = tempInvoiceEntity.FeeItem;
// makeParms[12].Value = tempInvoiceEntity.AmountList;
// makeParms[13].Value = tempInvoiceEntity.Amount;
// makeParms[14].Value = tempInvoiceEntity.AmountCapital;
// makeParms[15].Value = tempInvoiceEntity.Currency;
// makeParms[16].Value = tempInvoiceEntity.Remark;
// makeParms[17].Value = tempInvoiceEntity.Applicant;
// makeParms[18].Value = tempInvoiceEntity.ApplyTime;
// makeParms[19].Value = tempInvoiceEntity.Operator;
// makeParms[20].Value = tempInvoiceEntity.LicenseCode;
// makeParms[21].Value = tempInvoiceEntity.TaxCode;
// makeParms[22].Value = tempInvoiceEntity.InvoiceType;
// makeParms[23].Value = tempInvoiceEntity.IsNeedPrint;
// makeParms[24].Value = tempInvoiceEntity.IsNeedFee;
// makeParms[25].Value = tempInvoiceEntity.IsDelete;
// makeParms[26].Value = tempInvoiceEntity.InvoiceNO;
// makeParms[27].Value = tempInvoiceEntity.MBLNO;
// makeParms[28].Value = tempInvoiceEntity.ExchangeRate;
// makeParms[29].Value = tempInvoiceEntity.PrintAmount;
// makeParms[30].Value = tempInvoiceEntity.PrintCaptial;
// makeParms[31].Value = tempInvoiceEntity.PrintTitle;
// #endregion
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE, makeParms);
// }
// //更新ch_fee_invoiceapplication表,将BillStatus状态更新为已开出
// SqlParameter[] appParms = new SqlParameter[] {
// new SqlParameter(PARM_INVOICE_APP_BILL_NO,SqlDbType.VarChar,20)
// };
// appParms[0].Value = tempOldBillNO;
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOICE_APPLICATION, appParms);
// //更新发票册发票信息,根据发票号码将发票状态改为已开出
// SqlParameter[] invoiceBookItemParms = new SqlParameter[] {
// new SqlParameter(PARM_INVOICE_BOOK_ITEM_INVOICE_NUM,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_BOOK_ITEM_IS_MAKE_OUT,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_BOOK_ITEM_MAKEOUT_USER,SqlDbType.VarChar,36)
// };
// invoiceBookItemParms[0].Value = tempInvoiceEntity.InvoiceNO;
// invoiceBookItemParms[1].Value = true;
// invoiceBookItemParms[2].Value = tempInvoiceEntity.Operator;
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOCIE_ITEMS_MAKEOUT, invoiceBookItemParms);
// //先更新ch_fee费用信息
// SqlParameter[] feeParms = new SqlParameter[] {
// new SqlParameter(PARM_FEE_ISINVOICE,SqlDbType.Bit),
// new SqlParameter(PARM_FEE_INVOICE,SqlDbType.Decimal,20),
// new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36)
// };
// //插入一条新的记录到ch_fee_do表
// SqlParameter[] doParms = 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)
// };
// //遍历ch_fee_do与ch_fee表
// foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
// {
// doParms[0].Value = Guid.NewGuid().ToString();
// doParms[1].Value = tempInvoiceEntity.BillNO;//插入新的业务编号
// doParms[2].Value = feeDoEntity.BSNO;
// doParms[3].Value = feeDoEntity.MBLNO;
// doParms[4].Value = feeDoEntity.HBLNO;
// doParms[5].Value = feeDoEntity.CustomerName;
// doParms[6].Value = feeDoEntity.BSType;
// doParms[7].Value = feeDoEntity.FeeID;
// doParms[8].Value = feeDoEntity.FeeName;
// doParms[9].Value = feeDoEntity.Currency;
// doParms[10].Value = feeDoEntity.Amount;
// doParms[11].Value = feeDoEntity.DoAmount;
// doParms[12].Value = feeDoEntity.FeeType;
// doParms[13].Value = feeDoEntity.Category;
// doParms[14].Value = feeDoEntity.BillStatus;
// doParms[15].Value = feeDoEntity.Remark;
// doParms[16].Value = feeDoEntity.OrigCurrency;
// doParms[17].Value = feeDoEntity.ExchangeRate;
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, doParms);
// }
// //更新ch_fee表
// SqlParameter[] updateFeeParms = new SqlParameter[]{
// new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,200)
// };
// updateFeeParms[0].Value = tempInvoiceEntity.BillNO;
// updateFeeParms[1].Value = tempInvoiceEntity.InvoiceNO;
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOICE_BY_DO, updateFeeParms);
// ////更新ch_fee_do状态,将发票申请状态-6 更新为发票开出状态-7
// //SqlParameter[] doParms = new SqlParameter[]{
// // new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,20),
// // new SqlParameter(PARM_FEE_DO_CATEGORY,SqlDbType.Int)
// //};
// //doParms[0].Value = tempInvoiceEntity.BillNO;
// //doParms[1].Value = 6;
// //SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_FEE_DO_CATEGORY, doParms);
// //事务提交
// sqlTran.Commit();
// iResult = 1;//状态为1表示插入成功
// }
// catch (Exception execError)
// {
// iResult = -1;//有异常,插入失败
// sqlTran.Rollback();
// iResult = -2;//插入异常,事务已回滚成功
// throw execError;
// }
// finally
// {
// SqlHelper.CloseConnection();
// }
// }
// return iResult;
//}
#endregion
/// <summary>
/// 开出发票申请
/// </summary>
/// <param name="tempInvoiceEntity">发票开出实体类</param>
/// <param name="tempInvoiceAppGID">发票申请GID</param>
/// <param name="tempInvoiceAppBillNO">发票申请BILLNO</param>
/// <returns>值1表示插入成功 值不等于表示插入失败</returns>
public int InsertInvoiceByApplication(InvoiceEntity tempInvoiceEntity,string tempInvoiceAppGID,string tempInvoiceAppBillNO)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//判断发票号是否已经开出(包含废除的)
string sSQL = "SELECT count(*) as nums FROM ch_fee_invoice WHERE INVOICENO='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "'"; // and (ISDELETE=0 or ISDELETE is null)";
int invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum > 0)
{
iResult = -3;//ch_fee_invoice 因发票号重复,开出失败
return iResult;
}
else
{
sSQL = "SELECT count(*) as nums FROM ch_fee_invoiceitems as B INNER JOIN ch_fee_invoicebooks as A ON B.BOOKID = A.GID WHERE B.INVOICENUM='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "'";
invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum != 0)
{
sSQL = "SELECT count(*) as nums FROM ch_fee_invoiceitems as B INNER JOIN ch_fee_invoicebooks as A ON B.BOOKID = A.GID WHERE B.INVOICENUM='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "' and (A.ISDELETE<>1 and A.ISLOCK<>1 and B.ISDELETE<>1 and B.ISLOCK<>1 and B.ISMAKEOUT<>1)";
invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum == 0)
{
iResult = -4;//ch_fee_invoiceitems 此发票在发票册中已开出或删除或锁定,开出失败!
return iResult;
}
}
}
//
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='" + tempInvoiceEntity.CompanyID.ToString().Trim() + "'", null) as string;
//生成申请编号起始串
string strBillNoProfix = CreateBeginTitleCode(nowServerDateTime, tempBANKSHEAD+"IV", 4);
SqlParameter[] getLastBillParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_LIKE, SqlDbType.VarChar, 200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36)
};
getLastBillParms[0].Value = strBillNoProfix + "%";
getLastBillParms[1].Value = tempInvoiceEntity.CompanyID;
//获取最大的编号
string tempLastBillNo = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_LAST_BILL_NO, getLastBillParms) as string;
strLastBillNo = tempLastBillNo ?? "";
//生成付费申请编号
strNewBillNo = CreateSettleCode(nowServerDateTime, tempBANKSHEAD+"IV", 4, strLastBillNo);
SqlParameter[] makeParms = null;
if (tempInvoiceEntity.ETD == DateTime.MinValue)
{
#region 插入开票记录参数
makeParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36)
};
makeParms[0].Value = tempInvoiceEntity.GID;
makeParms[1].Value = strNewBillNo;
makeParms[2].Value = tempInvoiceEntity.CustomerName;
makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
makeParms[4].Value = tempInvoiceEntity.Bank;
makeParms[5].Value = tempInvoiceEntity.Account;
makeParms[6].Value = tempInvoiceEntity.BSNO;
makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
makeParms[8].Value = tempInvoiceEntity.POL;
makeParms[9].Value = tempInvoiceEntity.POD;
makeParms[10].Value = tempInvoiceEntity.FeeItem;
makeParms[11].Value = tempInvoiceEntity.AmountList;
makeParms[12].Value = tempInvoiceEntity.Amount;
makeParms[13].Value = tempInvoiceEntity.AmountCapital;
makeParms[14].Value = tempInvoiceEntity.Currency;
makeParms[15].Value = tempInvoiceEntity.Remark;
makeParms[16].Value = tempInvoiceEntity.Applicant;
makeParms[17].Value = tempInvoiceEntity.ApplyTime;
makeParms[18].Value = tempInvoiceEntity.Operator;
makeParms[19].Value = tempInvoiceEntity.LicenseCode;
makeParms[20].Value = tempInvoiceEntity.TaxCode;
makeParms[21].Value = tempInvoiceEntity.InvoiceType;
makeParms[22].Value = tempInvoiceEntity.IsNeedPrint;
makeParms[23].Value = tempInvoiceEntity.IsNeedFee;
makeParms[24].Value = tempInvoiceEntity.IsDelete;
makeParms[25].Value = tempInvoiceEntity.InvoiceNO;
makeParms[26].Value = tempInvoiceEntity.MBLNO;
makeParms[27].Value = tempInvoiceEntity.ExchangeRate;
makeParms[28].Value = tempInvoiceEntity.PrintAmount;
makeParms[29].Value = tempInvoiceEntity.PrintCaptial;
makeParms[30].Value = tempInvoiceEntity.PrintTitle;
makeParms[31].Value = tempInvoiceEntity.CompanyID;
#endregion
//private const string SQL_INSERT_INVOICE_NO_ETD = " INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, POL, POD, FEEITEM,"
// + " AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE,"
// + " ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,PRINTTITLE,COMPANYID )"
// + " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@pol,@pod,@fee_item,@amount_list, "
// + " @amount,@amount_capital,@currency,@remark,@applicant,@apply_time,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),"
// + " @is_delete,@mblno,@exchange_rate,@print_amount,@print_capital,@print_title,@company_id)";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_NO_ETD, makeParms);
}
else
{
#region 插入开票记录参数
makeParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ETD,SqlDbType.SmallDateTime),
new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36)
};
makeParms[0].Value = tempInvoiceEntity.GID;
makeParms[1].Value = strNewBillNo;
makeParms[2].Value = tempInvoiceEntity.CustomerName;
makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
makeParms[4].Value = tempInvoiceEntity.Bank;
makeParms[5].Value = tempInvoiceEntity.Account;
makeParms[6].Value = tempInvoiceEntity.BSNO;
makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
makeParms[8].Value = tempInvoiceEntity.ETD;
makeParms[9].Value = tempInvoiceEntity.POL;
makeParms[10].Value = tempInvoiceEntity.POD;
makeParms[11].Value = tempInvoiceEntity.FeeItem;
makeParms[12].Value = tempInvoiceEntity.AmountList;
makeParms[13].Value = tempInvoiceEntity.Amount;
makeParms[14].Value = tempInvoiceEntity.AmountCapital;
makeParms[15].Value = tempInvoiceEntity.Currency;
makeParms[16].Value = tempInvoiceEntity.Remark;
makeParms[17].Value = tempInvoiceEntity.Applicant;
makeParms[18].Value = tempInvoiceEntity.ApplyTime;
makeParms[19].Value = tempInvoiceEntity.Operator;
makeParms[20].Value = tempInvoiceEntity.LicenseCode;
makeParms[21].Value = tempInvoiceEntity.TaxCode;
makeParms[22].Value = tempInvoiceEntity.InvoiceType;
makeParms[23].Value = tempInvoiceEntity.IsNeedPrint;
makeParms[24].Value = tempInvoiceEntity.IsNeedFee;
makeParms[25].Value = tempInvoiceEntity.IsDelete;
makeParms[26].Value = tempInvoiceEntity.InvoiceNO;
makeParms[27].Value = tempInvoiceEntity.MBLNO;
makeParms[28].Value = tempInvoiceEntity.ExchangeRate;
makeParms[29].Value = tempInvoiceEntity.PrintAmount;
makeParms[30].Value = tempInvoiceEntity.PrintCaptial;
makeParms[31].Value = tempInvoiceEntity.PrintTitle;
makeParms[32].Value = tempInvoiceEntity.CompanyID;
#endregion
//private const string SQL_INSERT_INVOICE = " INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM,"
// + " AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, APPLICANT, APPLYTIME, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE,"
// + " ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,PRINTTITLE,COMPANYID )"
// + " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@etd,@pol,@pod,@fee_item,@amount_list, "
// + " @amount,@amount_capital,@currency,@remark,@applicant,@apply_time,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),"
// + " @is_delete,@mblno,@exchange_rate,@print_amount,@print_capital,@print_title,@company_id)";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE, makeParms);
}
//生成ch_fee_do信息
SqlParameter[] inserFeeDoParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_DO_INVOICEAPP_BILLNO,SqlDbType.VarChar,20)
};
inserFeeDoParms[0].Value = strNewBillNo;
inserFeeDoParms[1].Value = tempInvoiceEntity.CompanyID;
inserFeeDoParms[2].Value = tempInvoiceAppBillNO;
//发票申请开出时发票申请ch_fee_do生成发票开出ch_fee_do
//private const string SQL_INSERT_FEE_DO_APP_TO_MAKEOUT = " 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) "
// + " SELECT newid(),@bill_no,BSNO,MBLNO,HBLNO,CUSTOMERNAME,BSTYPE,FEEID,FEENAME,CURRENCY,AMOUNT,DOAMOUNT,FEETYPE,CATEGORY,BILLSTATUS,REMARK,ORIGCURRENCY,EXCHANGERATE,ORIGAMOUNT,COMPANYID FROM ch_fee_do WHERE ch_fee_do.BILLNO = @invoiceapp_billno AND COMPANYID = @company_id ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO_APP_TO_MAKEOUT, inserFeeDoParms);
SqlParameter[] updateFeeParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_FEE_DO_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter("@INVOICENUM",SqlDbType.VarChar,200)
};
updateFeeParms[0].Value = strNewBillNo;
updateFeeParms[1].Value = tempInvoiceEntity.CompanyID;
updateFeeParms[2].Value = tempInvoiceEntity.InvoiceNO;
//根据发票开出费用明细更新费用表
//private const string SQL_UPDATE_CH_FEE_BY_CH_FEE_DO_FOR_MERGE = " UPDATE ch_fee SET ch_fee.INVOICE = ISNULL(ch_fee.INVOICE,0) + ch_fee_do.ORIGAMOUNT,ch_fee.INVOICENUM = @INVOICENUM "
// + " FROM ch_fee_do WHERE ch_fee.GID = ch_fee_do.FEEID AND ch_fee_do.BILLNO = @bill_no AND ch_fee_do.COMPANYID = @company_id ";
//根据发票开出费用明细更新费用表
string SQL_UPDATE_CH_FEE_BY_CH_FEE_DO_FOR_MERGE2 = " UPDATE ch_fee SET ch_fee.INVOICE = ISNULL(ch_fee.INVOICE,0) + ch_fee_do.ORIGAMOUNT,ch_fee.INVOICENUM = @INVOICENUM "
+ " FROM ch_fee_do WHERE ch_fee.GID = ch_fee_do.FEEID AND ch_fee_do.BILLNO = @bill_no AND ch_fee_do.COMPANYID = @company_id ";//,ch_fee.ORDERINVOICE = ISNULL(ch_fee.ORDERINVOICE,0) + ch_fee_do.ORIGAMOUNT
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_BY_CH_FEE_DO_FOR_MERGE2, updateFeeParms);
//生成关联关系
SqlParameter[] insertSettleLinkParms = new SqlParameter[] {
new SqlParameter(PARM_CH_FEE_SETTLE_SETTLE_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CH_FEE_SETTLE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_CH_FEE_SETTLE_RELATION_SUB_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_CH_FEE_SETTLE_CREATE_USER,SqlDbType.VarChar,36),
};
insertSettleLinkParms[0].Value = tempInvoiceEntity.GID;
insertSettleLinkParms[1].Value = 2;
insertSettleLinkParms[2].Value = tempInvoiceAppGID;
insertSettleLinkParms[3].Value = tempInvoiceEntity.Operator;
//建立发票开出关联信息(生成发票开出和发票申请关联关系)
//private const string SQL_INSERT_CH_FEE_SETTLE_LINK = " INSERT INTO ch_fee_settle_link(GID,TYPE,SETTLEID,RELATIONSUBID,CREATEUSER,CREATETIME) "
// + " VALUES(newid(),@type,@settle_id,@relation_sub_id,@create_user,GETDATE()) ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_CH_FEE_SETTLE_LINK, insertSettleLinkParms);
SqlParameter[] updateInvoiceAppParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_APP_GID,SqlDbType.VarChar,36)
};
updateInvoiceAppParms[0].Value = tempInvoiceAppGID;
//更新发票申请记录表示已开出发票
//private const string SQL_UPDATE_CH_FEE_INVOICEAPP_STATUS = " UPDATE ch_fee_invoiceapplication SET BILLSTATUS = 3 WHERE GID = @gid ";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOICEAPP_STATUS, updateInvoiceAppParms);
//更新发票册发票信息,根据发票号码将发票状态改为已开出
SqlParameter[] invoiceBookItemParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_BOOK_ITEM_INVOICE_NUM,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_BOOK_ITEM_IS_MAKE_OUT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_BOOK_ITEM_MAKEOUT_USER,SqlDbType.VarChar,36)
};
invoiceBookItemParms[0].Value = tempInvoiceEntity.InvoiceNO;
invoiceBookItemParms[1].Value = true;
invoiceBookItemParms[2].Value = tempInvoiceEntity.Operator;
//private const string SQL_UPDATE_CH_FEE_INVOCIE_ITEMS_MAKEOUT = " UPDATE ch_fee_invoiceitems SET ISMAKEOUT = @is_makeout,MAKEOUTTIME = GETDATE(),MAKEOUTUSER = @makeout_user WHERE INVOICENUM = @invoice_num";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOCIE_ITEMS_MAKEOUT, invoiceBookItemParms);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#region 手动直接开发票
/// <summary>
/// 手动直接开发票
/// </summary>
/// <returns>值1表示开出成功 值不等于1表示开出失败</returns>
public int InsertInvoiceDirect(InvoiceEntity tempInvoiceEntity, IList<FeeDoEntity> tempFeeDoEntities)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//判断发票号是否已经开出(包含废除的)
string sSQL = "SELECT count(*) as nums FROM ch_fee_invoice WHERE INVOICENO='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "'"; // and (ISDELETE=0 or ISDELETE is null)";
int invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum > 0)
{
iResult = -3;//ch_fee_invoice 因发票号重复,开出失败
return iResult;
}
else
{
sSQL = "SELECT count(*) as nums FROM ch_fee_invoiceitems as B INNER JOIN ch_fee_invoicebooks as A ON B.BOOKID = A.GID WHERE B.INVOICENUM='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "'";
invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum != 0)
{
sSQL = "SELECT count(*) as nums FROM ch_fee_invoiceitems as B INNER JOIN ch_fee_invoicebooks as A ON B.BOOKID = A.GID WHERE B.INVOICENUM='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "' and (A.ISDELETE<>1 and A.ISLOCK<>1 and B.ISDELETE<>1 and B.ISLOCK<>1 and B.ISMAKEOUT<>1)";
invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum == 0)
{
iResult = -4;//ch_fee_invoiceitems 此发票在发票册中已开出或删除或锁定,开出失败!
return iResult;
}
}
}
//
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='" + tempInvoiceEntity.CompanyID.ToString().Trim() + "'", null) as string;
//生成申请编号起始串
string strBillNoProfix = CreateBeginTitleCode(nowServerDateTime, tempBANKSHEAD+"IV", 4);
SqlParameter[] getLastBillParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_LIKE, SqlDbType.VarChar, 200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36)
};
getLastBillParms[0].Value = strBillNoProfix + "%";
getLastBillParms[1].Value = tempInvoiceEntity.CompanyID;
//获取最大的编号
string tempLastBillNo = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_LAST_BILL_NO, getLastBillParms) as string;
strLastBillNo = tempLastBillNo ?? "";
//生成付费申请编号
strNewBillNo = CreateSettleCode(nowServerDateTime, tempBANKSHEAD+"IV", 4, strLastBillNo);
SqlParameter[] makeParms = null;
if (tempInvoiceEntity.ETD == DateTime.MinValue)
{
#region 插入开票记录参数
makeParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter("@APPLICANT",SqlDbType.VarChar,36)
};
makeParms[0].Value = tempInvoiceEntity.GID;
makeParms[1].Value = strNewBillNo;
makeParms[2].Value = tempInvoiceEntity.CustomerName;
makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
makeParms[4].Value = tempInvoiceEntity.Bank;
makeParms[5].Value = tempInvoiceEntity.Account;
makeParms[6].Value = tempInvoiceEntity.BSNO;
makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
makeParms[8].Value = tempInvoiceEntity.POL;
makeParms[9].Value = tempInvoiceEntity.POD;
makeParms[10].Value = tempInvoiceEntity.FeeItem;
makeParms[11].Value = tempInvoiceEntity.AmountList;
makeParms[12].Value = tempInvoiceEntity.Amount;
makeParms[13].Value = tempInvoiceEntity.AmountCapital;
makeParms[14].Value = tempInvoiceEntity.Currency;
makeParms[15].Value = tempInvoiceEntity.Remark;
makeParms[16].Value = tempInvoiceEntity.Operator;
makeParms[17].Value = tempInvoiceEntity.LicenseCode;
makeParms[18].Value = tempInvoiceEntity.TaxCode;
makeParms[19].Value = tempInvoiceEntity.InvoiceType;
makeParms[20].Value = tempInvoiceEntity.IsNeedPrint;
makeParms[21].Value = tempInvoiceEntity.IsNeedFee;
makeParms[22].Value = tempInvoiceEntity.IsDelete;
makeParms[23].Value = tempInvoiceEntity.InvoiceNO;
makeParms[24].Value = tempInvoiceEntity.MBLNO;
makeParms[25].Value = tempInvoiceEntity.ExchangeRate;
makeParms[26].Value = tempInvoiceEntity.PrintAmount;
makeParms[27].Value = tempInvoiceEntity.PrintCaptial;
makeParms[28].Value = tempInvoiceEntity.PrintTitle;
makeParms[29].Value = tempInvoiceEntity.CompanyID;
makeParms[30].Value = tempInvoiceEntity.Applicant;
#endregion
string APPLYTIME_name = tempInvoiceEntity.ApplyTime.ToString().Trim().IndexOf("0001")>-1 ? "" : ",APPLYTIME";
string APPLYTIME = tempInvoiceEntity.ApplyTime.ToString().Trim().IndexOf("0001")>-1 ? "" : ",'" + tempInvoiceEntity.ApplyTime.ToString().Trim() + "'";
string SQL_INSERT_INVOICE_DIRECT_NO_ETD = String.Format(" INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, POL, POD, FEEITEM, AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE, ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,PRINTTITLE,COMPANYID,APPLICANT{0})"
+ " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@pol,@pod,@fee_item,@amount_list, @amount,@amount_capital,@currency,@remark,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),@is_delete,@mblno, @exchange_rate,@print_amount,@print_capital,@print_title,@company_id,@APPLICANT{1})", APPLYTIME_name, APPLYTIME);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_DIRECT_NO_ETD, makeParms);
}
else
{
#region 插入开票记录参数
makeParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ETD,SqlDbType.SmallDateTime),
new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter("@APPLICANT",SqlDbType.VarChar,36)
};
makeParms[0].Value = tempInvoiceEntity.GID;
makeParms[1].Value = strNewBillNo;
makeParms[2].Value = tempInvoiceEntity.CustomerName;
makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
makeParms[4].Value = tempInvoiceEntity.Bank;
makeParms[5].Value = tempInvoiceEntity.Account;
makeParms[6].Value = tempInvoiceEntity.BSNO;
makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
makeParms[8].Value = tempInvoiceEntity.ETD;
makeParms[9].Value = tempInvoiceEntity.POL;
makeParms[10].Value = tempInvoiceEntity.POD;
makeParms[11].Value = tempInvoiceEntity.FeeItem;
makeParms[12].Value = tempInvoiceEntity.AmountList;
makeParms[13].Value = tempInvoiceEntity.Amount;
makeParms[14].Value = tempInvoiceEntity.AmountCapital;
makeParms[15].Value = tempInvoiceEntity.Currency;
makeParms[16].Value = tempInvoiceEntity.Remark;
makeParms[17].Value = tempInvoiceEntity.Operator;
makeParms[18].Value = tempInvoiceEntity.LicenseCode;
makeParms[19].Value = tempInvoiceEntity.TaxCode;
makeParms[20].Value = tempInvoiceEntity.InvoiceType;
makeParms[21].Value = tempInvoiceEntity.IsNeedPrint;
makeParms[22].Value = tempInvoiceEntity.IsNeedFee;
makeParms[23].Value = tempInvoiceEntity.IsDelete;
makeParms[24].Value = tempInvoiceEntity.InvoiceNO;
makeParms[25].Value = tempInvoiceEntity.MBLNO;
makeParms[26].Value = tempInvoiceEntity.ExchangeRate;
makeParms[27].Value = tempInvoiceEntity.PrintAmount;
makeParms[28].Value = tempInvoiceEntity.PrintCaptial;
makeParms[29].Value = tempInvoiceEntity.PrintTitle;
makeParms[30].Value = tempInvoiceEntity.CompanyID;
makeParms[31].Value = tempInvoiceEntity.Applicant;
#endregion
string APPLYTIME_name = tempInvoiceEntity.ApplyTime.ToString().Trim().IndexOf("0001") > -1 ? "" : ",APPLYTIME";
string APPLYTIME = tempInvoiceEntity.ApplyTime.ToString().Trim().IndexOf("0001") > -1 ? "" : ",'" + tempInvoiceEntity.ApplyTime.ToString().Trim() + "'";
string SQL_INSERT_INVOICE_DIRECT = String.Format(" INSERT INTO ch_fee_invoice(GID, INVOICENO, BILLNO, CUSTOMERNAME, INVOICECUSTNAME, INVOICEMAKETIME,BANK,ACCOUNT, BSNO, VESSELVOYAGE, ETD, POL, POD, FEEITEM, AMOUNTLIST, AMOUNT, AMOUNTCAPITAL, CURRENCY, REMARK, OPERATOR, LICENSECODE, TAXCODE, INVOICETYPE, ISNEEDPRINT, ISNEEDFEE,OPERATETIME,ISDELETE,MBLNO,EXCHANGERATE,PRINTAMOUNT,PRINTCAPITAL,COMPANYID,APPLICANT{0})"
+ " VALUES(@gid,@invoice_no,@bill_no,@customer_name,@invoice_customer,GETDATE(),@bank,@account,@bsno,@vessel_voyage,@etd,@pol,@pod,@fee_item,@amount_list, @amount,@amount_capital,@currency,@remark,@operator,@license_code,@tax_code,@invoice_type,@is_need_print,@is_need_fee,GETDATE(),@is_delete,@mblno, @exchange_rate,@print_amount,@print_capital,@print_title,@company_id,@APPLICANT{1})", APPLYTIME_name, APPLYTIME);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_DIRECT, makeParms);
}
//插入一条新的记录到ch_fee_do表
SqlParameter[] doParms = 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,50),
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)
};
//遍历ch_fee_do与ch_fee表
foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
{
doParms[0].Value = feeDoEntity.GID;//Guid.NewGuid().ToString();
doParms[1].Value = strNewBillNo;//插入新的业务编号
doParms[2].Value = feeDoEntity.BSNO;
doParms[3].Value = feeDoEntity.MBLNO;
doParms[4].Value = feeDoEntity.HBLNO;
doParms[5].Value = feeDoEntity.CustomerName;
doParms[6].Value = feeDoEntity.BSType;
doParms[7].Value = feeDoEntity.FeeID;
doParms[8].Value = feeDoEntity.FeeName;
doParms[9].Value = feeDoEntity.Currency;
doParms[10].Value = feeDoEntity.Amount;
doParms[11].Value = feeDoEntity.DoAmount;
doParms[12].Value = feeDoEntity.FeeType;
doParms[13].Value = feeDoEntity.Category;
doParms[14].Value = feeDoEntity.BillStatus;
doParms[15].Value = feeDoEntity.Remark;
doParms[16].Value = feeDoEntity.OrigCurrency;
doParms[17].Value = feeDoEntity.ExchangeRate;
doParms[18].Value = feeDoEntity.OriginalFeeCSTL;
doParms[19].Value = feeDoEntity.CompanyID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, doParms);
}
//更新发票册发票信息,根据发票号码将发票状态改为已开出
SqlParameter[] invoiceBookItemParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_BOOK_ITEM_INVOICE_NUM,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_BOOK_ITEM_IS_MAKE_OUT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_BOOK_ITEM_MAKEOUT_USER,SqlDbType.VarChar,36)
};
invoiceBookItemParms[0].Value = tempInvoiceEntity.InvoiceNO;
invoiceBookItemParms[1].Value = true;
invoiceBookItemParms[2].Value = tempInvoiceEntity.Operator;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOCIE_ITEMS_MAKEOUT, invoiceBookItemParms);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region ####
//#region 通过引入费用开发票
///// <summary>
///// 通过引入费用开发票
///// </summary>
///// <param name="tempInvoiceEntity">发票实体类</param>
///// <param name="tempFeeDoEntities">FeeDo实体类</param>
///// <param name="tempBillNO">申请业务编号</param>
///// <param name="IsApplication">是否为申请开票</param>
///// <returns>值1表示插入成功 值-1表示插入失败</returns>
//public int InsertImportInvoice(InvoiceEntity tempInvoiceEntity, IList<FeeDoEntity> tempFeeDoEntities, IList<FeeEntity> tempFeeEntities)
//{
// int iResult = 0;
// using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
// {
// try
// {
// SqlParameter[] makeParms = null;
// if (tempInvoiceEntity.ETD == DateTime.MinValue)
// {
// #region 插入开票记录参数
// makeParms = new SqlParameter[] {
// new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
// new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
// new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
// new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
// new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200)
// };
// makeParms[0].Value = tempInvoiceEntity.GID;
// makeParms[1].Value = tempInvoiceEntity.BillNO;
// makeParms[2].Value = tempInvoiceEntity.CustomerName;
// makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
// makeParms[4].Value = tempInvoiceEntity.Bank;
// makeParms[5].Value = tempInvoiceEntity.Account;
// makeParms[6].Value = tempInvoiceEntity.BSNO;
// makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
// makeParms[8].Value = tempInvoiceEntity.POL;
// makeParms[9].Value = tempInvoiceEntity.POD;
// makeParms[10].Value = tempInvoiceEntity.FeeItem;
// makeParms[11].Value = tempInvoiceEntity.AmountList;
// makeParms[12].Value = tempInvoiceEntity.Amount;
// makeParms[13].Value = tempInvoiceEntity.AmountCapital;
// makeParms[14].Value = tempInvoiceEntity.Currency;
// makeParms[15].Value = tempInvoiceEntity.Remark;
// makeParms[16].Value = tempInvoiceEntity.Applicant;
// makeParms[17].Value = tempInvoiceEntity.ApplyTime;
// makeParms[18].Value = tempInvoiceEntity.Operator;
// makeParms[19].Value = tempInvoiceEntity.LicenseCode;
// makeParms[20].Value = tempInvoiceEntity.TaxCode;
// makeParms[21].Value = tempInvoiceEntity.InvoiceType;
// makeParms[22].Value = tempInvoiceEntity.IsNeedPrint;
// makeParms[23].Value = tempInvoiceEntity.IsNeedFee;
// makeParms[24].Value = tempInvoiceEntity.IsDelete;
// makeParms[25].Value = tempInvoiceEntity.InvoiceNO;
// makeParms[26].Value = tempInvoiceEntity.MBLNO;
// makeParms[27].Value = tempInvoiceEntity.ExchangeRate;
// makeParms[28].Value = tempInvoiceEntity.PrintAmount;
// makeParms[29].Value = tempInvoiceEntity.PrintCaptial;
// makeParms[30].Value = tempInvoiceEntity.PrintTitle;
// #endregion
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_NO_ETD, makeParms);
// }
// else
// {
// #region 插入开票记录参数
// makeParms = new SqlParameter[] {
// new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_ETD,SqlDbType.SmallDateTime),
// new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
// new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
// new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
// new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
// new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
// new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
// new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
// new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
// new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
// new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200)
// };
// makeParms[0].Value = tempInvoiceEntity.GID;
// makeParms[1].Value = tempInvoiceEntity.BillNO;
// makeParms[2].Value = tempInvoiceEntity.CustomerName;
// makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
// makeParms[4].Value = tempInvoiceEntity.Bank;
// makeParms[5].Value = tempInvoiceEntity.Account;
// makeParms[6].Value = tempInvoiceEntity.BSNO;
// makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
// makeParms[8].Value = tempInvoiceEntity.ETD;
// makeParms[9].Value = tempInvoiceEntity.POL;
// makeParms[10].Value = tempInvoiceEntity.POD;
// makeParms[11].Value = tempInvoiceEntity.FeeItem;
// makeParms[12].Value = tempInvoiceEntity.AmountList;
// makeParms[13].Value = tempInvoiceEntity.Amount;
// makeParms[14].Value = tempInvoiceEntity.AmountCapital;
// makeParms[15].Value = tempInvoiceEntity.Currency;
// makeParms[16].Value = tempInvoiceEntity.Remark;
// makeParms[17].Value = tempInvoiceEntity.Applicant;
// makeParms[18].Value = tempInvoiceEntity.ApplyTime;
// makeParms[19].Value = tempInvoiceEntity.Operator;
// makeParms[20].Value = tempInvoiceEntity.LicenseCode;
// makeParms[21].Value = tempInvoiceEntity.TaxCode;
// makeParms[22].Value = tempInvoiceEntity.InvoiceType;
// makeParms[23].Value = tempInvoiceEntity.IsNeedPrint;
// makeParms[24].Value = tempInvoiceEntity.IsNeedFee;
// makeParms[25].Value = tempInvoiceEntity.IsDelete;
// makeParms[26].Value = tempInvoiceEntity.InvoiceNO;
// makeParms[27].Value = tempInvoiceEntity.MBLNO;
// makeParms[28].Value = tempInvoiceEntity.ExchangeRate;
// makeParms[29].Value = tempInvoiceEntity.PrintAmount;
// makeParms[30].Value = tempInvoiceEntity.PrintCaptial;
// makeParms[31].Value = tempInvoiceEntity.PrintTitle;
// #endregion
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE, makeParms);
// }
// //先更新ch_fee费用信息
// SqlParameter[] feeParms = new SqlParameter[] {
// new SqlParameter(PARM_FEE_ISINVOICE,SqlDbType.Bit),
// new SqlParameter(PARM_FEE_INVOICE,SqlDbType.Decimal,20),
// new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36)
// };
// //插入一条新的记录到ch_fee_do表
// SqlParameter[] doParms = 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)
// };
// //遍历ch_fee_do与ch_fee表
// foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
// {
// doParms[0].Value = feeDoEntity.GID;//Guid.NewGuid().ToString();
// doParms[1].Value = tempInvoiceEntity.BillNO;//插入新的业务编号
// doParms[2].Value = feeDoEntity.BSNO;
// doParms[3].Value = feeDoEntity.MBLNO;
// doParms[4].Value = feeDoEntity.HBLNO;
// doParms[5].Value = feeDoEntity.CustomerName;
// doParms[6].Value = feeDoEntity.BSType;
// doParms[7].Value = feeDoEntity.FeeID;
// doParms[8].Value = feeDoEntity.FeeName;
// doParms[9].Value = feeDoEntity.Currency;
// doParms[10].Value = feeDoEntity.Amount;
// doParms[11].Value = feeDoEntity.DoAmount;
// doParms[12].Value = feeDoEntity.FeeType;
// doParms[13].Value = feeDoEntity.Category;
// doParms[14].Value = feeDoEntity.BillStatus;
// doParms[15].Value = feeDoEntity.Remark;
// doParms[16].Value = feeDoEntity.OrigCurrency;
// doParms[17].Value = feeDoEntity.ExchangeRate;
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, doParms);
// }
// SqlParameter[] updateFeeParms = new SqlParameter[]{
// new SqlParameter(PARM_FEE_DO_BILL_NO,SqlDbType.VarChar,36),
// new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,200)
// };
// updateFeeParms[0].Value = tempInvoiceEntity.BillNO;
// updateFeeParms[1].Value = tempInvoiceEntity.InvoiceNO;
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOICE_BY_DO, updateFeeParms);
// //更新发票册发票信息,根据发票号码将发票状态改为已开出
// SqlParameter[] invoiceBookItemParms = new SqlParameter[] {
// new SqlParameter(PARM_INVOICE_BOOK_ITEM_INVOICE_NUM,SqlDbType.VarChar,200),
// new SqlParameter(PARM_INVOICE_BOOK_ITEM_IS_MAKE_OUT,SqlDbType.Bit),
// new SqlParameter(PARM_INVOICE_BOOK_ITEM_MAKEOUT_USER,SqlDbType.VarChar,36)
// };
// invoiceBookItemParms[0].Value = tempInvoiceEntity.InvoiceNO;
// invoiceBookItemParms[1].Value = true;
// invoiceBookItemParms[2].Value = tempInvoiceEntity.Operator;
// SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOCIE_ITEMS_MAKEOUT, invoiceBookItemParms);
// //事务提交
// sqlTran.Commit();
// iResult = 1;//状态为1表示插入成功
// }
// catch (Exception execError)
// {
// iResult = -1;//有异常,插入失败
// sqlTran.Rollback();
// iResult = -2;//插入异常,事务已回滚成功
// throw execError;
// }
// finally
// {
// SqlHelper.CloseConnection();
// }
// }
// return iResult;
//}
//#endregion
#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
public int InsertImportInvoice(InvoiceEntity tempInvoiceEntity, IList<FeeDoEntity> tempFeeDoEntities)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//判断发票号是否已经开出(包含废除的)
string sSQL = "SELECT count(*) as nums FROM ch_fee_invoice WHERE INVOICENO='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "'"; // and (ISDELETE=0 or ISDELETE is null)";
int invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum > 0)
{
iResult = -3;//ch_fee_invoice 因发票号重复,开出失败
return iResult;
}
else
{
sSQL = "SELECT count(*) as nums FROM ch_fee_invoiceitems as B INNER JOIN ch_fee_invoicebooks as A ON B.BOOKID = A.GID WHERE B.INVOICENUM='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "'";
invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum != 0)
{
sSQL = "SELECT count(*) as nums FROM ch_fee_invoiceitems as B INNER JOIN ch_fee_invoicebooks as A ON B.BOOKID = A.GID WHERE B.INVOICENUM='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "' and (A.ISDELETE<>1 and A.ISLOCK<>1 and B.ISDELETE<>1 and B.ISLOCK<>1 and B.ISMAKEOUT<>1)";
invoicenum = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, sSQL, null);
if (invoicenum == 0)
{
iResult = -4;//ch_fee_invoiceitems 此发票在发票册中已开出或删除或锁定,开出失败!
return iResult;
}
}
}
//
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='" + tempInvoiceEntity.CompanyID.ToString().Trim() + "'", null) as string;
//生成申请编号起始串
string strBillNoProfix = CreateBeginTitleCode(nowServerDateTime, tempBANKSHEAD+"IV", 4);
SqlParameter[] getLastBillParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_LIKE, SqlDbType.VarChar, 200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36)
};
getLastBillParms[0].Value = strBillNoProfix + "%";
getLastBillParms[1].Value = tempInvoiceEntity.CompanyID;
//获取最大的编号
string tempLastBillNo = (String)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_LAST_BILL_NO, getLastBillParms) as string;
strLastBillNo = tempLastBillNo ?? "";
//生成付费申请编号
strNewBillNo = CreateSettleCode(nowServerDateTime, tempBANKSHEAD+"IV", 4, strLastBillNo);
SqlParameter[] makeParms = null;
if (tempInvoiceEntity.ETD == DateTime.MinValue)
{
#region 插入开票记录参数
makeParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36)
};
makeParms[0].Value = tempInvoiceEntity.GID;
makeParms[1].Value = strNewBillNo;
makeParms[2].Value = tempInvoiceEntity.CustomerName;
makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
makeParms[4].Value = tempInvoiceEntity.Bank;
makeParms[5].Value = tempInvoiceEntity.Account;
makeParms[6].Value = tempInvoiceEntity.BSNO;
makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
makeParms[8].Value = tempInvoiceEntity.POL;
makeParms[9].Value = tempInvoiceEntity.POD;
makeParms[10].Value = tempInvoiceEntity.FeeItem;
makeParms[11].Value = tempInvoiceEntity.AmountList;
makeParms[12].Value = tempInvoiceEntity.Amount;
makeParms[13].Value = tempInvoiceEntity.AmountCapital;
makeParms[14].Value = tempInvoiceEntity.Currency;
makeParms[15].Value = tempInvoiceEntity.Remark;
makeParms[16].Value = tempInvoiceEntity.Applicant;
makeParms[17].Value = tempInvoiceEntity.ApplyTime;
makeParms[18].Value = tempInvoiceEntity.Operator;
makeParms[19].Value = tempInvoiceEntity.LicenseCode;
makeParms[20].Value = tempInvoiceEntity.TaxCode;
makeParms[21].Value = tempInvoiceEntity.InvoiceType;
makeParms[22].Value = tempInvoiceEntity.IsNeedPrint;
makeParms[23].Value = tempInvoiceEntity.IsNeedFee;
makeParms[24].Value = tempInvoiceEntity.IsDelete;
makeParms[25].Value = tempInvoiceEntity.InvoiceNO;
makeParms[26].Value = tempInvoiceEntity.MBLNO;
makeParms[27].Value = tempInvoiceEntity.ExchangeRate;
makeParms[28].Value = tempInvoiceEntity.PrintAmount;
makeParms[29].Value = tempInvoiceEntity.PrintCaptial;
makeParms[30].Value = tempInvoiceEntity.PrintTitle;
makeParms[31].Value = tempInvoiceEntity.CompanyID;
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE_NO_ETD, makeParms);
}
else
{
#region 插入开票记录参数
makeParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_BILL_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_CUSTOMER_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_INVOICE_CUST_NAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_BANK,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ACCOUNT,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_BSNO,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_VESSEL_VOYAGE,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_ETD,SqlDbType.SmallDateTime),
new SqlParameter(PARM_INVOICE_POL,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_POD,SqlDbType.VarChar,50),
new SqlParameter(PARM_INVOICE_FEE_ITEM,SqlDbType.VarChar,5000),
new SqlParameter(PARM_INVOICE_AMOUNT_LIST,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_AMOUNT_CAPITAL,SqlDbType.VarChar,100),
new SqlParameter(PARM_INVOICE_CURRENCY,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_REMARK,SqlDbType.VarChar,1024),
new SqlParameter(PARM_INVOICE_APPLICANT,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_APPLY_TIME,SqlDbType.DateTime),
new SqlParameter(PARM_INVOICE_OPERATOR,SqlDbType.VarChar,36),
new SqlParameter(PARM_INVOICE_LICENSE_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_TAX_CODE,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_INVOICE_TYPE,SqlDbType.Int),
new SqlParameter(PARM_INVOICE_IS_NEED_PRINT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_NEED_FEE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_IS_DELETE,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_INVOICE_NO,SqlDbType.VarChar,20),
new SqlParameter(PARM_INVOICE_MBLNO,SqlDbType.VarChar,30),
new SqlParameter(PARM_INVOICE_EXCHANGE_RATE,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_AMOUNT,SqlDbType.Decimal,20),
new SqlParameter(PARM_INVOICE_PRINT_CAPITAL,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_PRINT_TITLE,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_COMPANY_ID,SqlDbType.VarChar,36)
};
makeParms[0].Value = tempInvoiceEntity.GID;
makeParms[1].Value = strNewBillNo;
makeParms[2].Value = tempInvoiceEntity.CustomerName;
makeParms[3].Value = tempInvoiceEntity.InvoiceCustName;
makeParms[4].Value = tempInvoiceEntity.Bank;
makeParms[5].Value = tempInvoiceEntity.Account;
makeParms[6].Value = tempInvoiceEntity.BSNO;
makeParms[7].Value = tempInvoiceEntity.VesselVoyage;
makeParms[8].Value = tempInvoiceEntity.ETD;
makeParms[9].Value = tempInvoiceEntity.POL;
makeParms[10].Value = tempInvoiceEntity.POD;
makeParms[11].Value = tempInvoiceEntity.FeeItem;
makeParms[12].Value = tempInvoiceEntity.AmountList;
makeParms[13].Value = tempInvoiceEntity.Amount;
makeParms[14].Value = tempInvoiceEntity.AmountCapital;
makeParms[15].Value = tempInvoiceEntity.Currency;
makeParms[16].Value = tempInvoiceEntity.Remark;
makeParms[17].Value = tempInvoiceEntity.Applicant;
makeParms[18].Value = tempInvoiceEntity.ApplyTime;
makeParms[19].Value = tempInvoiceEntity.Operator;
makeParms[20].Value = tempInvoiceEntity.LicenseCode;
makeParms[21].Value = tempInvoiceEntity.TaxCode;
makeParms[22].Value = tempInvoiceEntity.InvoiceType;
makeParms[23].Value = tempInvoiceEntity.IsNeedPrint;
makeParms[24].Value = tempInvoiceEntity.IsNeedFee;
makeParms[25].Value = tempInvoiceEntity.IsDelete;
makeParms[26].Value = tempInvoiceEntity.InvoiceNO;
makeParms[27].Value = tempInvoiceEntity.MBLNO;
makeParms[28].Value = tempInvoiceEntity.ExchangeRate;
makeParms[29].Value = tempInvoiceEntity.PrintAmount;
makeParms[30].Value = tempInvoiceEntity.PrintCaptial;
makeParms[31].Value = tempInvoiceEntity.PrintTitle;
makeParms[32].Value = tempInvoiceEntity.CompanyID;
#endregion
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INVOICE, makeParms);
}
//插入一条新的记录到ch_fee_do表
SqlParameter[] doParms = 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)
};
//将费用信息写入ch_fee_do表
foreach (FeeDoEntity feeDoEntity in tempFeeDoEntities)
{
doParms[0].Value = feeDoEntity.GID;//Guid.NewGuid().ToString();
doParms[1].Value = strNewBillNo;//插入新的业务编号
doParms[2].Value = feeDoEntity.BSNO;
doParms[3].Value = feeDoEntity.MBLNO;
doParms[4].Value = feeDoEntity.HBLNO;
doParms[5].Value = feeDoEntity.CustomerName;
doParms[6].Value = feeDoEntity.BSType;
doParms[7].Value = feeDoEntity.FeeID;
doParms[8].Value = feeDoEntity.FeeName;
doParms[9].Value = feeDoEntity.Currency;
doParms[10].Value = feeDoEntity.Amount;
doParms[11].Value = feeDoEntity.DoAmount;
doParms[12].Value = feeDoEntity.FeeType;
doParms[13].Value = feeDoEntity.Category;
doParms[14].Value = feeDoEntity.BillStatus;
doParms[15].Value = feeDoEntity.Remark;
doParms[16].Value = feeDoEntity.OrigCurrency;
doParms[17].Value = feeDoEntity.ExchangeRate;
doParms[18].Value = feeDoEntity.OriginalFeeCSTL;
doParms[19].Value = feeDoEntity.CompanyID;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_FEE_DO, doParms);
//更新ch_fee表开票金额字段
SqlParameter[] feeParms = new SqlParameter[] {
new SqlParameter(PARM_FEE_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_FEE_INVOICE,SqlDbType.Decimal,20)
};
feeParms[0].Value = feeDoEntity.FeeID;
feeParms[1].Value = feeDoEntity.OriginalFeeCSTL;
//private const string SQL_UPDATE_CH_FEE_INVOICE = "UPDATE ch_fee SET INVOICE = ISNULL(INVOICE,0)+@invoice WHERE GID = @gid AND AMOUNT >= @invoice AND (AMOUNT-INVOICE) >= @invoice";
string SQL_UPDATE_CH_FEE_INVOICE_ORDERINVOICE2 = "UPDATE ch_fee SET INVOICE = ISNULL(INVOICE,0)+@invoice,ORDERINVOICE=ISNULL(INVOICE,0)+@invoice,INVOICENUM='" + tempInvoiceEntity.InvoiceNO.ToString().Trim() + "' WHERE GID = @gid AND AMOUNT >= @invoice AND (AMOUNT-isnull(INVOICE,0)) >= @invoice";
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOICE_ORDERINVOICE2, feeParms);
}
//更新发票册发票信息,根据发票号码将发票状态改为已开出
SqlParameter[] invoiceBookItemParms = new SqlParameter[] {
new SqlParameter(PARM_INVOICE_BOOK_ITEM_INVOICE_NUM,SqlDbType.VarChar,200),
new SqlParameter(PARM_INVOICE_BOOK_ITEM_IS_MAKE_OUT,SqlDbType.Bit),
new SqlParameter(PARM_INVOICE_BOOK_ITEM_MAKEOUT_USER,SqlDbType.VarChar,36)
};
invoiceBookItemParms[0].Value = tempInvoiceEntity.InvoiceNO;
invoiceBookItemParms[1].Value = true;
invoiceBookItemParms[2].Value = tempInvoiceEntity.Operator;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_CH_FEE_INVOCIE_ITEMS_MAKEOUT, invoiceBookItemParms);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#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
}
}