using System ;
using System.Linq ;
using System.Web.Mvc ;
using DSWeb.Areas.Account.DAL.Chfee_Invoice_HangXin ;
using DSWeb.Areas.Account.DAL.Chfee_Invoiceapplication ;
using DSWeb.Areas.Account.Models.Chfee_Invoiceapplication ;
using DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin ;
using DSWeb.Areas.Account.Models.Chfee_do_detail ;
using DSWeb.Areas.Account.Models.BillChfeeDetail ;
using DSWeb.MvcShipping.Helper ;
using DSWeb.MvcShipping.Comm.Cookie ;
using DSWeb.Areas.CommMng.DAL ;
using System.Collections.Generic ;
using HcUtility.Comm ;
using HcUtility.Core ;
using DSWeb.EntityDA ;
using DSWeb.Areas.Account.Models.Chfee_Exrate ;
using System.IO ;
using Microsoft.Practices.EnterpriseLibrary.Data ;
using System.Text ;
using System.Data ;
using InvokeWebService ;
using DSWeb.Areas.Account.Models.RytInvoice ;
using System.Xml.Serialization ;
using System.Xml ;
using DSWeb.MvcShipping.DAL.MsSysParamSet ;
using DSWeb.Areas.SysMng.DAL.DBTableConn ;
using DSWeb.Areas.SysMng.Models.DBTableConn ;
using Spire.Pdf ;
using Aspose.Words ;
using iTextSharp.text ;
using iTextSharp.text.pdf ;
using DSWeb.MvcShipping.DAL.MsSysInvInterFaceSet ;
using DSWeb.Common.Helper ;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL ;
using System.ServiceModel.Configuration ;
using DSWeb.Areas.MvcShipping.Helper ;
using DSWeb.SoftMng.Model ;
using DSWeb.MvcShipping.DAL.MsInfoClient ;
using System.Web.UI.WebControls ;
using DSWeb.Areas.CommMng.Models ;
using DSWeb.SoftMng.Filter ;
using DSWeb.Areas.Import.DAL.ReceiptDoc ;
using DSWeb.Areas.SysMng.DAL.SysUser ;
using DSWeb.MvcShipping.DAL.MsSeaeOrderDAL ;
using Renci.SshNet.Common ;
using sun.swing ;
using DSWeb.MvcShipping.DAL.DsSendmail ;
using DSWeb.Areas.MvcShipping.Models.Message.VGM ;
using DSWeb.MvcShipping.Models.MsChFee ;
using DSWeb.Areas.Dispatch.DB ;
using System.Net.Http ;
namespace DSWeb.Areas.Account.Controllers
{
[JsonRequestBehavior]
public class Chfee_invoice_HangXinController : Controller
{
/ /
// GET:
public ActionResult Index ( )
{
return View ( ) ;
}
/ /
// GET: /
public ActionResult Edit ( )
{
return View ( ) ;
}
public ActionResult BLEdit ( )
{
return View ( ) ;
}
public ActionResult AppEdit ( )
{
return View ( ) ;
}
public ActionResult BookEdit ( )
{
return View ( ) ;
}
public ActionResult BookIndex ( )
{
return View ( ) ;
}
public ActionResult DetailView ( )
{
return View ( ) ;
}
public ActionResult OUTDB_P2_Index ( )
{
return View ( ) ;
}
public ActionResult OUTDB_P2_Edit ( )
{
return View ( ) ;
}
#region Get
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetDataList ( int start , int limit , string sort , string condition )
{
var canlogin = BasicDataRefDAL . CheckLogin ( Session ) ;
if ( ! canlogin . Success )
{
return ( ContentResult ) canlogin . Data ;
}
if ( sort ! = null )
{
sort = sort . Replace ( "OPERATORNAME" , "OPERATOR" ) ;
sort = sort . Replace ( "DELOPERATORNAME" , "DELETEOPERATOR" ) ;
sort = sort . Replace ( "SALECORP" , "SALECORPID" ) ;
sort = sort . Replace ( "INVOICECATEGORYREF" , "INVOICECATEGORY" ) ;
sort = sort . Replace ( "INVOICETYPEREF" , "INVOICETYPE" ) ;
sort = sort . Replace ( "APPLICANT" , "(select top 1 (select ShowName from [user] where GID=ap.applicant) APPLICANT from ch_fee_invoiceapplication ap where invbillno=cm.BILLNO)" ) ;
}
var dataList = ChinvoiceDAL . GetDataList ( start , limit , condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
int count = ChinvoiceDAL . getTotalCount ( condition , CookieConfig . GetCookie_UserId ( Request ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetDataListStr ( int start , int limit , string sort , string condition , int billtype )
{
var dataListStr = ChinvoiceDAL . GetDataListStr ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , data = dataListStr } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetData ( string handle , string condition , bool isapp )
{
ChInvoice_HangXin head = null ;
if ( handle = = "edit" | | handle = = "copyadd" )
{
head = ChinvoiceDAL . GetData ( condition ) ;
}
if ( head = = null )
{
head = new ChInvoice_HangXin ( ) ;
}
if ( handle = = "add" )
{
head . OPERATOR = Convert . ToString ( Session [ "USERID" ] ) ;
head . OPERATORNAME = Convert . ToString ( Session [ "SHOWNAME" ] ) ;
head . CREATEUSER = Convert . ToString ( Session [ "USERID" ] ) ;
head . PTORRED = "1" ; //默认为正票
head . SALECORPID = Session [ "COMPANYID" ] . ToString ( ) ;
head . PAYEE = Convert . ToString ( Session [ "SHOWNAME" ] ) ;
head . CHECKER = Convert . ToString ( Session [ "SHOWNAME" ] ) ;
head . PUSHMOBILE = "0" ;
head . INVOICELINE = MsSysParamSetDAL . GetData ( "PARAMNAME='DEFAULTINVOICELINE'" ) . PARAMVALUE ;
var defaultPAYEE = MsSysParamSetDAL . GetData ( "PARAMNAME='INVSKR'" ) . PARAMVALUE ;
var defaultCHECKER = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFHR'" ) . PARAMVALUE ;
var defaultINVKPR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVKPR'" ) . PARAMVALUE ;
if ( ! string . IsNullOrEmpty ( defaultPAYEE ) )
head . PAYEE = defaultPAYEE ;
if ( ! string . IsNullOrEmpty ( defaultCHECKER ) )
head . CHECKER = defaultCHECKER ;
if ( ! string . IsNullOrEmpty ( defaultINVKPR ) )
{
head . OPERATORNAME = defaultINVKPR ;
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
var USERID = T_ALL_DA . GetStrSQL ( "USERID" , "select top 1 USERID from VW_user where SHOWNAME='" + defaultINVKPR + "'" ) ;
head . OPERATOR = USERID ;
}
if ( isapp )
{
head . INVOICETYPE = 2 ;
head . INVOICETYPEREF = "申请发票" ;
}
else
{
head . INVOICETYPE = 1 ;
head . INVOICETYPEREF = "自由发票" ;
}
}
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , data = head } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetDetailList ( string condition )
{
var dataList = ChinvoiceDAL . GetDetailList ( condition ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetBillList ( string condition , string sort )
{
var dataList = ChinvoiceDAL . GetBodyList ( condition , sort ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetTruckBillList ( string condition , string sort )
{
var dataList = ChinvoiceDAL . GetTruckBodyList ( condition , sort ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetBillSum ( string condition )
{
var dataList = ChinvoiceDAL . GetBodySumList ( condition ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetFeeDataList ( int start , int limit , string sort , string condition )
{
var dataList = ChinvoiceDAL . GetFeeDataList ( condition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetBillDataList ( int start , int limit , string sort , string condition )
{
var dataList = ChinvoiceDAL . GetAddBillList ( start , limit , condition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
int count = ChinvoiceDAL . getAddBillTotalCount ( condition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , totalCount = count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetTruckBillDataList ( int start , int limit , string sort , string condition )
{
var dataList = ChinvoiceDAL . GetAddTruckBillList ( start , limit , condition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
int count = ChinvoiceDAL . getAddTruckBillTotalCount ( condition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , totalCount = count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetFeeDetailList ( string sort , string condition )
{
var dataList = ChinvoiceDAL . GetFeeDetailList ( condition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetAddSum ( string condition )
{
var dataList = ChinvoiceDAL . GetAddSum ( condition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
# endregion
#region save
public ContentResult Save ( string opstatus , string data , string body )
{
var headData = JsonConvert . Deserialize < ChInvoice_HangXin > ( data ) ;
var bodyList = JsonConvert . Deserialize < List < ChInvoiceDetail > > ( body ) ;
if ( opstatus = = "add" )
{
headData . GID = Guid . NewGuid ( ) . ToString ( ) ;
headData . BILLNO = PubSysDAL . GetBillNo ( "0308" ) ;
headData . COMPANYID = Convert . ToString ( Session [ "COMPANYID" ] ) ;
var defaultPAYEE = MsSysParamSetDAL . GetData ( "PARAMNAME='INVSKR'" ) . PARAMVALUE ;
var defaultCHECKER = MsSysParamSetDAL . GetData ( "PARAMNAME='INVFHR'" ) . PARAMVALUE ;
var defaultINVKPR = MsSysParamSetDAL . GetData ( "PARAMNAME='INVKPR'" ) . PARAMVALUE ;
if ( ! string . IsNullOrEmpty ( defaultPAYEE ) )
headData . PAYEE = defaultPAYEE ;
if ( ! string . IsNullOrEmpty ( defaultCHECKER ) )
headData . CHECKER = defaultCHECKER ;
if ( ! string . IsNullOrEmpty ( defaultINVKPR ) )
{
headData . OPERATORNAME = defaultINVKPR ;
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
var USERID = T_ALL_DA . GetStrSQL ( "USERID" , "select top 1 USERID from VW_user where SHOWNAME='" + defaultINVKPR + "'" ) ;
headData . OPERATOR = USERID ;
}
headData . OPERATETIME = DateTime . Now ;
headData . CREATEUSER = Convert . ToString ( Session [ "USERID" ] ) ;
headData . CREATETIME = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
headData . DbOperationType = DbOperationType . DbotIns ;
}
else if ( opstatus = = "edit" )
{
headData . DbOperationType = DbOperationType . DbotUpd ;
headData . ModelUIStatus = "E" ;
}
else
{
headData . DbOperationType = DbOperationType . DbotDel ;
}
//填写未指定但当前可以填写的其他信息
if ( ( ! headData . ISFRINV ) & & ( headData . INVOICECUSTNAME = = "" | | headData . CUSTRATENO = = "" ) )
{
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
DataSet dsHSCODE = T_ALL_DA . GetAllSQL ( "SELECT Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,BillRises1,INVADDRTEL,[DESCRIPTION],RmbBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='RMB' AND LINKID=info_client.GID) Rmbbank,Rmbaccount,usdBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='USD' AND LINKID=info_client.GID) usdbank,usdaccount,TaxNo,Addr,Tel from info_client WHERE SHORTNAME='" + headData . CUSTOMERNAME + "'" ) ;
if ( dsHSCODE ! = null )
{
if ( dsHSCODE . Tables [ 0 ] . Rows . Count > 0 )
{
if ( dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "BillRises1" ] . ToString ( ) ! = "" )
headData . INVOICECUSTNAME = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "BillRises1" ] . ToString ( ) ;
else headData . INVOICECUSTNAME = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "DESCRIPTION" ] . ToString ( ) ;
if ( headData . CUSTRATENO = = "" ) headData . CUSTRATENO = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "TaxNo" ] . ToString ( ) ;
if ( headData . CUSTADDRTEL = = "" )
{
if ( dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "INVADDRTEL" ] . ToString ( ) ! = "" )
headData . CUSTADDRTEL = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "INVADDRTEL" ] . ToString ( ) ;
else headData . CUSTADDRTEL = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Addr" ] . ToString ( ) + " " + dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Tel" ] . ToString ( ) ;
}
if ( string . IsNullOrEmpty ( headData . CUSTTEL ) )
{
if ( dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Tel" ] . ToString ( ) ! = "" )
headData . CUSTTEL = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Tel" ] . ToString ( ) ;
}
if ( string . IsNullOrEmpty ( headData . CUSTADDR ) )
{
if ( dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Addr" ] . ToString ( ) ! = "" )
headData . CUSTADDR = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Addr" ] . ToString ( ) ;
}
if ( headData . CUSTBANK = = "" )
{
if ( headData . RECVCURR = = "USD" )
headData . CUSTBANK = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "usdbank" ] . ToString ( ) ;
else
headData . CUSTBANK = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Rmbbank" ] . ToString ( ) ;
}
}
}
}
if ( ( ! headData . ISFRINV ) & & ( string . IsNullOrEmpty ( headData . CUSTTEL ) | | string . IsNullOrEmpty ( headData . CUSTADDR ) ) )
{
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
DataSet dsHSCODE = T_ALL_DA . GetAllSQL ( "SELECT Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,BillRises1,INVADDRTEL,[DESCRIPTION],RmbBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='RMB' AND LINKID=info_client.GID) Rmbbank,Rmbaccount,usdBillRises,usdbank,usdaccount,TaxNo,Addr,Tel from info_client WHERE SHORTNAME='" + headData . CUSTOMERNAME + "'" ) ;
if ( dsHSCODE ! = null )
{
if ( dsHSCODE . Tables [ 0 ] . Rows . Count > 0 )
{
var custaddtel = "" ;
if ( headData . CUSTADDRTEL = = "" )
{
if ( dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "INVADDRTEL" ] . ToString ( ) ! = "" )
custaddtel = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "INVADDRTEL" ] . ToString ( ) ;
else custaddtel = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Addr" ] . ToString ( ) + " " + dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Tel" ] . ToString ( ) ;
headData . CUSTADDRTEL = custaddtel ;
}
else
{
if ( dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "INVADDRTEL" ] . ToString ( ) ! = "" )
custaddtel = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "INVADDRTEL" ] . ToString ( ) ;
else custaddtel = dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Addr" ] . ToString ( ) + " " + dsHSCODE . Tables [ 0 ] . Rows [ 0 ] [ "Tel" ] . ToString ( ) ;
}
if ( string . IsNullOrEmpty ( headData . CUSTTEL ) & & ! string . IsNullOrEmpty ( custaddtel ) )
{
if ( custaddtel . Length ! = 0 )
headData . CUSTTEL = ChinvoiceDAL . GetTelephoneList ( custaddtel ) ;
}
if ( string . IsNullOrEmpty ( headData . CUSTADDR ) & & ! string . IsNullOrEmpty ( custaddtel . Trim ( ) ) )
{
if ( custaddtel . Length ! = 0 & & ! string . IsNullOrEmpty ( headData . CUSTTEL ) )
headData . CUSTADDR = custaddtel . Replace ( headData . CUSTTEL , "" ) ;
}
}
}
}
if ( headData . CUSTBANK = = null ) headData . CUSTBANK = "" ;
if ( ! string . IsNullOrEmpty ( headData . RECVCURR ) & & string . IsNullOrEmpty ( headData . CUSTBANK ) & & ! string . IsNullOrEmpty ( headData . CUSTOMERNAME ) )
{
var bankList = MsInfoClientDAL . GetBankList ( "LINKID in (select GID FROM info_client WHERE SHORTNAME='" + headData . CUSTOMERNAME + "')" ) ;
if ( bankList ! = null & & bankList . Count ! = 0 )
{
foreach ( var bank in bankList )
{
if ( ( bank . CURRENCY = = headData . RECVCURR ) & & ( bank . ISINVDEF = = "1" ) )
headData . CUSTBANK = bank . BANKNAME_ACCOUNT ;
}
}
}
var isPost = true ;
var errorstr = "" ;
if ( headData . INVOICENO ! = "" )
{
var ct = ChinvoiceDAL . GetRdCount ( "GID<>'" + headData . GID + "' AND INVOICENO='" + headData . INVOICENO + "' and COMPANYID='" + Convert . ToString ( Session [ "COMPANYID" ] ) + "'" ) ;
if ( ct ! = 0 )
{
isPost = false ;
errorstr = "发票号重复" ;
}
}
//if (string.IsNullOrEmpty(headData.INVITERFACE))
//{
var INVITERFACE = MsSysInvInterFaceSetDAL . GetData ( $" INVOICELINE=(select enumvaluename from tSysEnumValue where EnumTypeID=80003 and EnumValueID='{headData.INVOICELINE}') " , headData . SALECORPID ) ;
//if (INVITERFACE.INVITERFACE == "")
headData . INVITERFACE = INVITERFACE . INVITERFACE ;
//else
//headData.INVITERFACE = "诺诺发票接口";
//}
//else
//{
//}
if ( ! string . IsNullOrEmpty ( headData . CUSTTEL ) & & ( headData . CUSTTEL . Trim ( ) . Length > 20 ) )
{
isPost = false ;
errorstr = "客户电话长度不允许超过20" ;
}
//if (!string.IsNullOrEmpty(headData.CUSTADDR) && (headData.CUSTADDR.Trim().Length > 80))
//{
// isPost = false;
// errorstr = "客户电话长度不允许超过80";
//}
if ( ! string . IsNullOrEmpty ( headData . SALECORPID ) & & ! string . IsNullOrEmpty ( headData . ACCOUNT ) )
{
var banklist = MsBaseInfoDAL . GetAllBANKList ( "LINKID='" + headData . SALECORPID + "'" ) ;
if ( banklist . Find ( x = > ( x . CURRENCY = = headData . RECVCURR | | x . CURRENCY = = "" ) & & x . BANKACCOUNT = = headData . ACCOUNT ) = = null )
{
isPost = false ;
errorstr = "银行及账号于收款单位和币别不一致,请检查" ;
}
}
if ( isPost )
{
if ( headData . INVOICEMAKETIME = = "" ) headData . INVOICEMAKETIME = null ;
if ( headData . ETD = = "" ) headData . ETD = null ;
headData . CUSTRATENO = headData . CUSTRATENO . Trim ( ) ;
headData . CUSTBANK = headData . CUSTBANK . Trim ( ) ;
headData . REMARK = headData . REMARK . Trim ( ) ;
var BILLNO = headData . BILLNO ;
//20240823 购方税号/销方税号 去除所有空格
if ( headData . TAXCODE ! = null )
headData . TAXCODE = headData . TAXCODE . Replace ( " " , "" ) ;
if ( headData . CUSTRATENO ! = null )
headData . CUSTRATENO = headData . CUSTRATENO . Replace ( " " , "" ) ;
var modb = new ModelObjectDB ( ) ;
DBResult result = ChinvoiceDAL . SaveInvDetail ( headData . GID , bodyList ) ;
if ( result . Success = = true )
{
result = modb . Save ( headData ) ;
//ChinvoiceDAL.UpdateInvNoUse(headData.INVOICENO, Convert.ToString(Session["USERID"]),headData.BILLNO);
//if (headData.EXCHANGERATE != 0)
//{
// ChinvoiceDAL.updateFeeTax(headData.BILLNO, headData.EXCHANGERATE);
//}
} ;
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = ChinvoiceDAL . GetData ( " BILLNO='" + BILLNO + "'" , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) )
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
else
{
var jsonRespose = new JsonResponse { Success = false , Message = errorstr + "不允许保存!" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
public ContentResult AddDetail ( string bill , string data , string curr , bool islist , string GID , string invoiceno )
{
//首先判断是否有 modInvoiceImport发票引入费用 权限
//var ar = BasicDataRefDAL.GetAR("modInvoiceImport", Session["USERID"].ToString());
//if
var bodyList = JsonConvert . Deserialize < List < BillChfeeDetail > > ( data ) ;
var headdata = ChinvoiceDAL . GetData ( " BILLNO='" + bill + "'" , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var modb = new ModelObjectDB ( ) ;
DBResult result = ChinvoiceDAL . AddDetail ( bill , bodyList , curr , Convert . ToString ( Session [ "COMPANYID" ] ) , islist , GID , headdata ) ;
if ( result . Success ) { ChinvoiceDAL . p_update_Amount ( bill , GID ) ; }
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult AddBill ( string bill , string feesql , string storeCurrExrate , bool islist , string GID , bool custgroup = false )
{
//首先判断是否有 modInvoiceImport发票引入费用 权限
var headData = JsonConvert . Deserialize < ChInvoice_HangXin > ( bill ) ;
var exrateList = JsonConvert . Deserialize < List < ChFeeExrate > > ( storeCurrExrate ) ;
if ( ( exrateList = = null ) | | ( exrateList . Count = = 0 ) )
{
exrateList = ChinvoiceDAL . GetCurrExrateData ( headData . CUSTOMERNAME , headData . CURRENCY , feesql , custgroup ) ;
if ( exrateList . Count = = 0 )
{
var modb = new ModelObjectDB ( ) ;
DBResult result = ChinvoiceDAL . AddBill ( headData , feesql , exrateList , Convert . ToString ( Session [ "COMPANYID" ] ) , islist , GID , Convert . ToString ( Session [ "USERID" ] ) , custgroup ) ;
if ( result . Success ) { ChinvoiceDAL . p_update_Amount ( headData . BILLNO , GID ) ; }
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
else
{
var jsonRespose = new JsonResponse { Success = true , Message = "查询成功" , Data = exrateList . ToList ( ) } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
else
{
var modb = new ModelObjectDB ( ) ;
DBResult result = ChinvoiceDAL . AddBill ( headData , feesql , exrateList , Convert . ToString ( Session [ "COMPANYID" ] ) , islist , GID , Convert . ToString ( Session [ "USERID" ] ) ) ;
if ( result . Success ) { ChinvoiceDAL . p_update_Amount ( headData . BILLNO , GID ) ; }
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
public ContentResult DelBill ( string data , string billno , string GID )
{
//首先判断是否有 modInvoiceImport发票引入费用 权限
var bodyList = JsonConvert . Deserialize < List < Chfee_do_detail > > ( data ) ;
DBResult result = ChinvoiceDAL . DelFeeDo ( bodyList , GID ) ;
if ( result . Success ) { ChinvoiceDAL . p_update_Amount ( billno , GID ) ; }
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
/ /
public ContentResult Delete ( string data )
{
var headData = JsonConvert . Deserialize < ChInvoice_HangXin > ( data ) ;
headData = ChinvoiceDAL . GetData ( " cm.BILLNO='" + headData . BILLNO + "'" ) ;
DBResult result ;
//首先判断是否有 modInvLock 发票开出锁定
//20191205 防止已经获得【流水号】的发票业务被删除
if ( ! string . IsNullOrWhiteSpace ( headData . INVOICESERIALNUM ) & & headData . INVAMOUNT > 0 )
{
var jsonRespose1 = new JsonResponse { Success = false , Message = "已经获得流水号且仍包含费用的发票业务不能删除" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose1 ) } ;
}
if ( ! string . IsNullOrWhiteSpace ( headData . INVOICESERIALNUM ) & & ! string . IsNullOrWhiteSpace ( headData . INVOICENO ) )
{
var jsonRespose1 = new JsonResponse { Success = false , Message = "已经实际开出的发票业务不能删除" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose1 ) } ;
}
if ( headData . EINVOICESTATEREF = = "开票中" )
{
var jsonRespose1 = new JsonResponse { Success = false , Message = "当前发票状态不允许删除" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose1 ) } ;
}
result = SetInvoiceFee ( headData ) ;
if ( result . Success = = true )
{
var modb = new ModelObjectDB ( ) ;
modb . Delete ( headData ) ;
ChinvoiceDAL . UpdateInvNoCancelUse ( headData . INVOICENO ) ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
var blUpSQL = " insert into sys_log(GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER) values(NEWID(),'" + headData . BILLNO + "','删除发票','" + DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) + "','" + headData . INVOICENO + '(' + headData . CUSTOMERNAME + ')' + "','" + Convert . ToString ( Session [ "USERID" ] ) + "')" ;
bool bl = T_ALL_DA . GetExecuteSqlCommand ( blUpSQL ) ;
}
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
/// <summary>
/// 看看USERID是否能操作这条数据的ModName功能
/// </summary>
/// <param name="head"></param>
/// <param name="ModName"></param>
/// <param name="USERID"></param>
/// <returns></returns>
private bool CanOperate ( ChInvoice_HangXin head , string ModName )
{
var rangestr = BasicDataRefDAL . CanOperateStr_INVOICE ( ModName , Session [ "USERID" ] . ToString ( ) ) ;
var _L = ChinvoiceDAL . GetData ( "GID='" + head . GID + "' and " + rangestr ) ;
if ( _L . GID = = head . GID )
{
return true ;
}
else return false ;
}
/// <summary>
/// 发票作废
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public ContentResult DeleteUp ( string data )
{
//首先判断是否有 modInvLock 发票开出锁定
var headData = JsonConvert . Deserialize < ChInvoice_HangXin > ( data ) ;
//if (!CanOperate(headData, "modInvLock")) {
// var jsonRespose = new JsonResponse { Success =false, Message = "您还不具备针对这条业务的‘发票开出锁定’权限" };
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
//}
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
var strCT = T_ALL_DA . GetStrSQL ( "CT" , "select COUNT(*) CT from ch_fee_do_payapplication where PAYBILLNO='" + headData . BILLNO + "'" ) ;
if ( strCT ! = "0" & & strCT ! = "" )
{
var jsonRespose2 = new JsonResponse { Success = false , Message = "已发票结算,不允许作废" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose2 ) } ;
}
return DeleteUp ( headData ) ;
}
private ContentResult DeleteUp ( ChInvoice_HangXin headData )
{
//首先判断是否有 modInvLock 发票开出锁定
//if (!CanOperate(headData, "modInvLock"))
//{
// var jsonRespose1 = new JsonResponse { Success = false, Message = "您还不具备针对这条业务的‘发票开出锁定’权限" };
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose1) };
//}
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
var strCT = T_ALL_DA . GetStrSQL ( "CT" , "select COUNT(*) CT from ch_fee_do_payapplication where PAYBILLNO='" + headData . BILLNO + "'" ) ;
if ( strCT ! = "0" & & strCT ! = "" )
{
var jsonRespose2 = new JsonResponse { Success = false , Message = "已发票结算,不允许作废" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose2 ) } ;
}
DBResult result ;
result = SetInvoiceFee ( headData ) ;
if ( result . Success = = true )
{
ChinvoiceDAL . UpdateDelete ( headData . BILLNO , Convert . ToString ( Session [ "USERID" ] ) ) ;
//ChinvoiceDAL.UpdateInvNoDelete(headData.INVOICENO, Convert.ToString(Session["USERID"]));
}
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
/// <summary>
/// 发票作废取消
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public ContentResult CancelDeleteUp ( string data )
{
var headData = JsonConvert . Deserialize < ChInvoice_HangXin > ( data ) ;
//首先判断是否有 modInvLock 发票开出锁定
//if (!CanOperate(headData, "modInvLock"))
//{
// var jsonRespose1 = new JsonResponse { Success = false, Message = "您还不具备针对这条业务的‘发票开出锁定’权限" };
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose1) };
//}
DBResult result ;
result = ChinvoiceDAL . UpdateDelete ( headData . BILLNO , Convert . ToString ( Session [ "USERID" ] ) , false ) ;
if ( result . Success = = true )
{
ChinvoiceDAL . UpdateInvNoDelete ( headData . INVOICENO , Convert . ToString ( Session [ "USERID" ] ) , false ) ;
}
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
# endregion
public ContentResult GetInvoiceNo ( string condition )
{
var dataList = ChinvoiceDAL . GetInvoiceNo ( Convert . ToString ( Session [ "COMPANYID" ] ) , Convert . ToString ( Session [ "USERID" ] ) ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
#region 发票申请添加
public ContentResult AddAppDetail ( string bill , string data , string invoiceno , string GID )
{
var bodyList = JsonConvert . Deserialize < List < ChInvoiceapplication > > ( data ) ;
var StrGid = "" ;
if ( bodyList ! = null )
{
foreach ( var enumValue in bodyList )
{
if ( StrGid = = "" )
StrGid = "'" + enumValue . GID + "'" ;
else
StrGid = StrGid + ",'" + enumValue . GID + "'" ;
}
}
if ( StrGid ! = "" )
{
StrGid = "(" + StrGid + ")" ;
var dataList = ChinvoiceapplicationDAL . GetDataInvList ( " BILLSTATUS=0 and cm.GID IN " + StrGid , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
if ( dataList ! = null & & dataList . Count ! = 0 )
{
var modb = new ModelObjectDB ( ) ;
DBResult result = ChinvoiceDAL . AddAppDetail ( bill , dataList , invoiceno , Convert . ToString ( Session [ "COMPANYID" ] ) , GID ) ;
if ( result . Success ) { ChinvoiceDAL . p_update_Amount ( bill , GID ) ; }
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
else
{
var jsonRespose = new JsonResponse { Success = false , Message = "发票申请已生成发票,请刷新!" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
else
{
var jsonRespose = new JsonResponse { Success = false , Message = "无需要添加的发票申请!" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
public ContentResult DelAppBill ( string data , string billno , string GID )
{
var bodyList = JsonConvert . Deserialize < List < ChInvoiceapplication > > ( data ) ;
DBResult result = ChinvoiceDAL . DelAppList ( bodyList , billno ) ;
if ( result . Success ) { ChinvoiceDAL . p_update_Amount ( billno , GID ) ; }
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult DelInvDetail ( string billno , string body , string GID )
{
var bodyList = JsonConvert . Deserialize < List < ChInvoiceDetail > > ( body ) ;
DBResult result = ChinvoiceDAL . DelInvDetail ( bodyList ) ;
if ( result . Success ) { ChinvoiceDAL . p_update_Amount ( billno , GID ) ; }
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
# endregion
#region 锁定和撤销锁定
public ContentResult Lock ( string bill )
{
//首先判断是否有 modInvLock 发票开出锁定
DBResult result = ChinvoiceDAL . Lock ( bill , Convert . ToString ( Session [ "USERID" ] ) ) ;
var json = JsonConvert . Serialize ( result ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult UnLock ( string bill )
{
//首先判断是否有 modInvLock 发票开出锁定
DBResult result = ChinvoiceDAL . UnLock ( bill , Convert . ToString ( Session [ "USERID" ] ) ) ;
var json = JsonConvert . Serialize ( result ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult LockList ( string bills )
{
//首先判断是否有 modInvLock 发票开出锁定
DBResult result = ChinvoiceDAL . LockList ( bills , Convert . ToString ( Session [ "USERID" ] ) ) ;
var json = JsonConvert . Serialize ( result ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult UnLockList ( string bills )
{
//首先判断是否有 modInvLock 发票开出锁定
DBResult result = ChinvoiceDAL . UnLockList ( bills , Convert . ToString ( Session [ "USERID" ] ) ) ;
var json = JsonConvert . Serialize ( result ) ;
return new ContentResult ( ) { Content = json } ;
}
# endregion
#region 保存指定发票业务list的PDF文件 将其拼合成一个dpf后返回url
public ContentResult GetONEPDF ( string BILLNOS , string sort = "" )
{
JsonResponse result = new JsonResponse ( ) ;
try
{
var BILLList = new List < ChInvoice_HangXin > ( ) ;
//var billnoList = BasicDataRefDAL.getStrListfromCommaStr(BILLNOS, ',');
var billnoSqlStr = "'" + BILLNOS . Replace ( "," , "','" ) + "'" ;
var condition = $" cm.billno in({billnoSqlStr})" ;
DatasetSort _sort = new DatasetSort ( ) ;
var sortstr = @"[{""property"":""INVOICEMAKETIME"",""direction"":""asc""},{""property"":""INVOICENO"",""direction"":""asc""}]" ;
//if (!string.IsNullOrWhiteSpace(sort))
//{
// if (sort == "INVOICEMAKETIME")
// {
// //_sort.property="INVOICEMAKETIME";
// // _sort.direction = "asc";
// sortstr = @"[{""property"":""INVOICEMAKETIME"",""direction"":""asc""}]";
// }
//}
var dataList = ChinvoiceDAL . GetDataList ( 0 , 9999 , condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sortstr ) ;
if ( dataList = = null | | dataList . Count = = 0 )
{
result . Success = false ;
result . Message = "没有可以打印的发票文件" ;
return result . getContentReult ( ) ;
}
//var _h = dataList[0];
//if (_h.INVITERFACE == "诺诺全电发票")
//{
// //诺诺全电 保持用开票时间排序
//}
//else
//{
//}
BasicDataRefDAL . ClearPath ( BasicDataRefDAL . getPath ( "INVOICEPDF" ) ) ;
var pdflist = new List < string > ( ) ;
foreach ( var invoice in dataList )
{
//var billno = bill.BILLNO;
//var invoice = ChinvoiceDAL.GetData($" BILLNO ='{billno}' ");
if ( ! string . IsNullOrWhiteSpace ( invoice . INVOICEPDFURL ) )
{
var filename = BasicDataRefDAL . HttpDownloadFile ( invoice . INVOICEPDFURL , "INVOICEPDF" , invoice . INVOICENO + ".pdf" ) ;
pdflist . Add ( filename ) ;
//if (pdflist.Count == 1) {
// pdflist.Add(filename);
//}
}
}
if ( pdflist . Count = = 0 )
{
result . Success = false ;
result . Message = "没有可以打印的发票文件" ;
return result . getContentReult ( ) ;
}
else
{
//pdflist.OrderBy(o => o);
//var _h = dataList[0];
//if (_h.INVITERFACE == "诺诺全电发票")
//{
// //诺诺全电
//}
//else
//{
// pdflist.Sort(delegate (string p1, string p2)
// {
// return p1.CompareTo(p2);
// });
//}
//20240325 原逻辑是将pdf文件根据文件名(发票号)排序,现在是查询时用开票时间排序,生成时不排序
}
var pdfarray = pdflist . ToArray ( ) ;
SavePDF ( pdfarray ) ;
result . Success = true ;
result . Message = "" ;
result . Data = "../../INVOICEPDF/" + Session [ "USERID" ] . ToString ( ) + ".pdf" ;
}
catch ( Exception e )
{
result . Success = false ;
result . Message = e . Message ;
}
return result . getContentReult ( ) ;
}
private void SavePDF ( string [ ] pdfarray )
{
string outputFileName = BasicDataRefDAL . getPath ( "INVOICEPDF" ) + Session [ "USERID" ] . ToString ( ) + ".pdf" ;
//PdfDocumentBase doc = PdfDocument.MergeFiles(pdfarray);
//doc.Pages.Insert(0);
//doc.Pages.RemoveAt(0);
//doc.Save(outputFileName, FileFormat.PDF);
iTextSharp . text . Document document = new iTextSharp . text . Document ( new PdfReader ( pdfarray [ 0 ] ) . GetPageSize ( 1 ) ) ;
PdfCopy copy = new PdfCopy ( document , new FileStream ( outputFileName , FileMode . Create ) ) ;
document . Open ( ) ;
for ( int i = 0 ; i < pdfarray . Length ; i + + )
{
PdfReader reader = new PdfReader ( pdfarray [ i ] ) ;
int n = reader . NumberOfPages ;
for ( int j = 1 ; j < = n ; j + + )
{
document . NewPage ( ) ;
PdfImportedPage page = copy . GetImportedPage ( reader , j ) ;
copy . AddPage ( page ) ;
}
}
document . Close ( ) ;
}
//private void SavePDF_Aspose(string[] pdfarray)
//{
// string outputFileName = BasicDataRefDAL.getPath("INVOICEPDF") + Session["USERID"].ToString() + ".pdf";
// PdfDocumentBase doc = PdfDocument.MergeFiles(pdfarray);
// doc.Pages.Insert(0);
// doc.Pages.RemoveAt(0);
// doc.Save(outputFileName, FileFormat.PDF);
//}
# endregion
public ContentResult ExpInv ( string bills )
{
var bodyList = JsonConvert . Deserialize < List < ChInvoice_HangXin > > ( bills ) ;
var path = Server . MapPath ( "../../EDIFiles/ExportInv" ) ;
if ( ! Directory . Exists ( path ) )
{
Directory . CreateDirectory ( path ) ;
}
/ /
var result = new DBResult ( ) ;
var filename = "" ;
filename = ChinvoiceDAL . CreateInvList ( bodyList , path ) ;
if ( filename ! = "" )
{
//result.Data = "../../EDIFiles/ExportInv/" + filename;
result . Data = filename ;
filename = Path . GetFileName ( filename ) ;
result . Success = true ;
result . Message = filename ;
}
else
{
result . Success = false ;
result . Message = "无当前匹配的导出文件!" ;
}
/ /
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message , Data = result . Data } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult ExpDZInv ( string bills )
{
var bodyList = JsonConvert . Deserialize < List < ChInvoice_HangXin > > ( bills ) ;
var path = Server . MapPath ( "../../EDIFiles/ExportInv" ) ;
if ( ! Directory . Exists ( path ) )
{
Directory . CreateDirectory ( path ) ;
}
/ /
var result = new DBResult ( ) ;
var filename = "" ;
filename = ChinvoiceDAL . CreateDZInvList ( bodyList , path , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
if ( filename ! = "" )
{
//result.Data = "../../EDIFiles/ExportInv/" + filename;
result . Data = filename ;
filename = Path . GetFileName ( filename ) ;
result . Success = true ;
result . Message = filename ;
}
else
{
result . Success = false ;
result . Message = "无当前匹配的导出文件!" ;
}
/ /
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message , Data = result . Data } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
#region 航信接口调用
public ContentResult test ( string str )
{
var result = new KPResponse ( ) ;
var _s = str . Replace ( "\\\"" , "\"" ) ;
result = DSWeb . TruckMng . Helper . JsonConvert . Deserialize < KPResponse > ( _s ) ;
var jsonRespose = new JsonResponse
{
Success = true ,
Message = "" ,
Data = result
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ActionResult test2 ( string str )
{
return View ( str ) ;
}
/// <summary>
/// 接收诺诺平台跳回的url信息,
/// 20191122后已无作用
/// </summary>
/// <param name="code"></param>
/// <param name="taxnum"></param>
/// <returns></returns>
//public ActionResult setCustCode(string code, string taxnum)
//{
// BasicDataRefDAL.SaveLog("code="+ code+ ";taxnum="+ taxnum,"诺诺平台","认证窗口回调","接收认证数据");
// var hx = HangXinRequestHelper.getHelper(taxnum);
// if (hx.code != code || hx.needStart )
// {
// hx.code = code;
// hx.setISVToken();
// }
// return View();
//}
private JsonResponse checkinfo ( string BILLNO , string redirecturl , string redReason = "" , bool setred = false )
{
var result = new DBResult ( ) ;
var head = new ChInvoice_HangXin ( ) ;
//var detail = new List<chinvoice_de>
var jsonRespose = new JsonResponse { Success = true , Message = result . Message , Data = result . Data } ;
//首先判断数据完整性与合法性
head = ChinvoiceDAL . GetData ( "cm.BILLNO='" + BILLNO + "'" ) ;
if ( string . IsNullOrEmpty ( head . INVOICELINE ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = "发票种类不能为空!" ;
}
if ( head . BILLNO ! = "" )
{
if ( string . IsNullOrEmpty ( head . INVITERFACE ) )
{
var INVITERFACE = MsSysInvInterFaceSetDAL . GetData ( "INVOICELINE='" + head . INVOICELINEREF + "'" , "" ) ;
if ( INVITERFACE . INVITERFACE ! = "" )
head . INVITERFACE = INVITERFACE . INVITERFACE ;
else head . INVITERFACE = "诺诺发票接口" ;
if ( head . INVITERFACE = = "诺诺全电发票" )
{
if ( setred )
{
if ( ! string . IsNullOrWhiteSpace ( redReason ) )
{
head . redReason = redReason ;
}
else
{
//jsonRespose.Success = false;
//jsonRespose.Message = "必须选择冲红理由!";
//return jsonRespose;
head . redReason = "2" ;
}
}
}
head . DbOperationType = DbOperationType . DbotUpd ;
head . ModelUIStatus = "E" ;
var modb = new ModelObjectDB ( ) ;
result = modb . Save ( head ) ;
}
else
{
if ( head . INVITERFACE = = "诺诺全电发票" )
{
if ( setred )
{
if ( ! string . IsNullOrWhiteSpace ( redReason ) )
{
head . redReason = redReason ;
head . DbOperationType = DbOperationType . DbotUpd ;
head . ModelUIStatus = "E" ;
var modb = new ModelObjectDB ( ) ;
result = modb . Save ( head ) ;
}
else
{
//jsonRespose.Success = false;
//jsonRespose.Message = "必须选择冲红理由!";
//return jsonRespose;
head . redReason = "2" ;
head . DbOperationType = DbOperationType . DbotUpd ;
head . ModelUIStatus = "E" ;
var modb = new ModelObjectDB ( ) ;
result = modb . Save ( head ) ;
}
}
}
}
//head = list[0];
jsonRespose . Data = head ;
}
else
{
jsonRespose . Success = false ;
jsonRespose . Message = "没有找到可以开票的发票信息,可能是权限不足或登录信息丢失。" ;
}
var checkcan = checkCanPost ( head ) ;
if ( checkcan . Success = = false )
{
jsonRespose . Success = false ;
jsonRespose . Message = checkcan . Message ;
}
else
{
if ( head . INVITERFACE = = "诺诺发票接口" | | head . INVITERFACE = = "" )
{
//如果该税号的token需要 返回认证窗口
var hx = HangXinRequestHelper . getHelper ( head . TAXCODE ) ;
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return jsonRespose ;
}
HangXinRequestHelper . redirectUri = redirecturl ; //getRedirecturl(redirecturl);
if ( hx . needStart )
{
BasicDataRefDAL . SaveLog ( "checkinfo; BILLNO=" + BILLNO , "" , "诺诺平台" , "返回认证窗口" ) ;
jsonRespose = TokenPage ( ) ;
}
}
else
{
jsonRespose . Success = true ;
jsonRespose . Message = "" ;
return jsonRespose ;
}
}
return jsonRespose ;
}
private JsonResponse TokenPage ( )
{
var jsonRespose = new JsonResponse { Success = true , Message = "" , Data = "" } ;
jsonRespose . Success = false ;
jsonRespose . Message = "需要认证诺诺用户名和密码" ;
var 原 诺 诺 第 三 方 方 式 开 票 = HangXinRequestHelper . getHelper ( "" ) ;
var newwindowurl = "https://open.jss.com.cn/authorization.html?client_id=" + 原 诺 诺 第 三 方 方 式 开 票 . appSecret + "&response_type=code&redirect_uri=" + HangXinRequestHelper . redirectUri + "&appKey=" + 原 诺 诺 第 三 方 方 式 开 票 . appKey + "" ;
jsonRespose . Data = newwindowurl ;
return jsonRespose ;
}
/// <summary>
/// 航信接口 开票
/// </summary>
/// <param name="bill"></param>
/// <returns></returns>
public ContentResult NNMakeInv ( string bill , string redirecturl )
{
//首先判断是否有 modInvLock 发票开出锁定
var result = new DBResult ( ) ;
//var detail = new List<chinvoice_de>
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message , Data = result . Data } ;
//首先判断数据完整性与合法性
var checkresult = checkinfo ( bill , redirecturl ) ;
if ( ! checkresult . Success )
{
return new ContentResult ( ) { Content = JsonConvert . Serialize ( checkresult ) } ;
}
else
{
var head = ( ChInvoice_HangXin ) checkresult . Data ;
decimal invamount = 0 ;
var invitems = ChinvoiceapplicationDAL . GetDetailList ( "PID='" + head . GID + "'" , "" ) ;
foreach ( var invitem in invitems )
{
invamount = invamount + invitem . AMOUNT + invitem . TAX ;
}
if ( invamount ! = head . INVAMOUNT )
{
var jsonRespose2 = new JsonResponse { Success = false , Message = "开票明细与开票金额不一致,请检查!" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose2 ) } ;
}
ChInvoice_HangXin returndate = null ;
if ( head . INVITERFACE = = "诺诺发票接口" | | head . INVITERFACE = = "" )
{
var hx = HangXinRequestHelper . getHelper ( head . TAXCODE ) ;
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
//20191107 如果该发票存在流水号 则首先去诺诺平台进行一次读取
//如开票信息形如
/*"{\"code\":\"E0000\",\"describe\":\"查询发票信息成功\",\"result\":[{\"orderNo\":\"IN2019110700005\",\"taxExcludedAmount\":500.00,\"c_invoiceid\":\"19110716260203390480\",\"invoiceImageUrl\":\"\",\"buyerName\":\"青岛世悠联国际物流有限公司\",\"invoiceCode\":\"\",\"invoiceNum\":\"\",\"resultMsg\":\"[][2019-11-07 16:30:02] 单据号:19110716260203390480,开具结果:0,开具失败原因:开票异常:\",\"checkCode\":\"\",\"invoiceSerialNum\":\"19110716260203390480\",\"statusMsg\":\"开票失败\",\"buyerTaxNum\":\"91370202MA3CGDCU83\",\"invoiceFileUrl\":\"\",\"invoiceLine\":\"电子增值税普通发票\",\"taxIncludedAmount\":500.00,\"status\":3}]}"*/
//则可能代表失败的原因是 ukey验证 的部分,也许重启税控软件和诺诺客户端可以解决问题。
if ( ! string . IsNullOrEmpty ( head . INVOICESERIALNUM ) )
{ //如果该发票流水号不为空
result = hx . ReadInvoice ( head ) ;
}
else
{
HangXinRequestHelper . redirectUri = getRedirecturl ( redirecturl ) ;
var detailList = ChinvoiceDAL . GetDetailList ( "PID='" + head . GID + "'" ) ;
//var CodeGoodInvList = MsCodeGoodInvDAL.GetDataList(" gid in (SELECT GOODSNAME FROM ch_fee_invoicedetail where PID = '"+ head.GID + "')");
if ( ! string . IsNullOrWhiteSpace ( hx . accessToken ) )
{
result = hx . PostInvoice ( head , detailList ) ;
}
if ( result . Message = = "需要重新认证" | | string . IsNullOrWhiteSpace ( hx . accessToken ) )
{
BasicDataRefDAL . SaveLog ( "PostInvoice 反回‘需要重新认证’" , "" , "诺诺平台" , "返回认证窗口" ) ;
var _r = TokenPage ( ) ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( _r ) } ;
}
//returndate = ChinvoiceDAL.GetData(" BILLNO='" + head.BILLNO + "'");
}
}
else if ( head . INVITERFACE = = "瑞宏发票接口" )
{
RuihongHelper ruihongHelper = new RuihongHelper ( ) ;
string msg = null ;
if ( ! string . IsNullOrEmpty ( head . INVOICESERIALNUM ) )
{ //如果该发票流水号不为空
result . Success = ruihongHelper . QueryInvoiceRecord ( head . GID , head . INVOICESERIALNUM , out msg ) ;
result . Message = msg ;
}
else
{
if ( head . PTORRED = = "2" )
{
result . Success = ruihongHelper . RedInvoiceRecord ( head . GID , out msg ) ;
result . Message = msg ;
}
else
{
result . Success = ruihongHelper . PostInvoiceRecord ( head . GID , out msg ) ;
result . Message = msg ;
}
}
}
else if ( head . INVITERFACE = = "诺诺全电发票" )
{
var hx = 诺 诺 全 电 发 票 . getHelper ( head ) ;
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
if ( ! string . IsNullOrEmpty ( head . INVOICESERIALNUM ) )
{ //如果该发票流水号不为空
result = hx . ReadInvoice ( head ) ;
}
else
{
//HangXinRequestHelper.redirectUri = getRedirecturl(redirecturl);
var detailList = ChinvoiceDAL . GetDetailList ( "PID='" + head . GID + "'" ) ;
//var CodeGoodInvList = MsCodeGoodInvDAL.GetDataList(" gid in (SELECT GOODSNAME FROM ch_fee_invoicedetail where PID = '"+ head.GID + "')");
if ( ! string . IsNullOrWhiteSpace ( hx . accessToken ) )
{
result = hx . PostInvoice ( head , detailList ) ;
}
}
}
else if ( head . INVITERFACE = = "东胜乐企他用" )
{
var hp = new 东 胜 乐 企 他 用 ( head , Convert . ToString ( Session [ "USERID" ] ) ) ;
//var cansend = hp.CanSend();
//if (cansend.Success == false) {
// return BasicDataRefDAL.GetContentResult(cansend);
//}
result = hp . DoSend_BlueInvoice ( ) ;
result . Data = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
return BasicDataRefDAL . GetContentResult ( result ) ;
}
returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
if ( returndate . EINVOICESTATE = = "2" & & returndate . BILLSTATUS = = 0 )
{
//20200106 添加 如sys_param_set.PARAMNAME=INVOICEAUTOLOCK 没有值或值为false 则不执行锁定
var needautolock = MsSysParamSetDAL . GetSysParam ( "INVOICEAUTOLOCK" ) . isnullortrue ( ) ;
if ( needautolock )
{
ChinvoiceDAL . Lock ( returndate . BILLNO , Convert . ToString ( Session [ "USERID" ] ) ) ;
}
returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
}
jsonRespose . Success = result . Success ;
jsonRespose . Message = result . Message ;
jsonRespose . Data = returndate ;
}
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
/// <summary>
/// 读取诺诺平台上的发票信息 通过发票流水号 ch_fee_invoice.invoiceser
/// </summary>
/// <param name="taxnum"></param>
/// <param name="BILLNO"></param>
/// <returns></returns>
public ContentResult NNReadInv ( string BILLNO , string redirecturl )
{
var headdata = ChinvoiceDAL . GetData ( " cm.BILLNO='" + BILLNO + "'" ) ;
if ( headdata . PTORRED = = "2" )
{
//如果已有pdf地址 则直接返回
var isfee = ChinvoiceDAL . GetStCount ( "PAYBILLNO='" + BILLNO + "'" ) ;
if ( isfee ! = 0 )
{
var jsonRespose2 = new JsonResponse { Success = false , Message = "已发票结算,不允许冲红" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose2 ) } ;
}
}
var canlogin = BasicDataRefDAL . CheckLogin ( Session ) ;
if ( ! canlogin . Success )
{
return ( ContentResult ) canlogin . Data ;
}
JsonResponse result = new JsonResponse ( ) ;
if ( ! string . IsNullOrWhiteSpace ( headdata . INVOICEPDFURL ) )
{
result . Success = true ;
result . Data = headdata ;
}
else
{
if ( headdata . INVITERFACE = = "诺诺发票接口" | | headdata . INVITERFACE = = "" )
{
result = Do_NNReadInv ( BILLNO , redirecturl ) ;
}
else if ( headdata . INVITERFACE = = "瑞宏发票接口" )
{
RuihongHelper ruihongHelper = new RuihongHelper ( ) ;
string msg = null ;
var succ = ruihongHelper . QueryInvoiceRecord ( headdata . GID , headdata . INVOICESERIALNUM , out msg ) ;
result . Success = succ ;
result . Message = msg ;
result . Data = ChinvoiceDAL . GetData ( " BILLNO='" + headdata . BILLNO + "'" ) ;
}
else if ( headdata . INVITERFACE = = "诺诺全电发票" )
{
//诺诺全电发票的红票 读取其实是 读取红字确认单查询接口
if ( headdata . PTORRED = = "1" )
{
result = Do_NuoNuoQuanDianReadInv ( BILLNO ) ;
}
if ( headdata . PTORRED = = "2" )
{
var _r = NNRedConfirm_Read ( BILLNO ) ;
return BasicDataRefDAL . GetContentResult ( _r ) ;
}
}
else if ( headdata . INVITERFACE = = "东胜乐企他用" )
{
//诺诺全电发票的红票 读取其实是 读取红字确认单查询接口
if ( headdata . PTORRED = = "1" )
{
var hp = new 东 胜 乐 企 他 用 ( headdata , Convert . ToString ( Session [ "USERID" ] ) ) ;
var _r = hp . DoReadInvoice ( ) ;
if ( _r . Success = = false )
{
var sqlstr = $" update ch_fee_invoice set INVOICESERIALNUM='' where BILLNO='{headdata.BILLNO}'" ;
BasicDataRefDAL . ExecSql ( sqlstr ) ;
}
if ( string . IsNullOrWhiteSpace ( headdata . INVOICEPDFURL ) )
{
//初次读取 成功后发送邮件
if ( ! string . IsNullOrWhiteSpace ( headdata . PUSHEMAIL ) )
{
//NNSendMail(headdata.BILLNO, headdata.PUSHEMAIL);
NNSendMail_Djy ( headdata . BILLNO , headdata . PUSHEMAIL ) ;
}
}
_r . Data = ChinvoiceDAL . GetData ( " BILLNO='" + headdata . BILLNO + "'" ) ;
return BasicDataRefDAL . GetContentResult ( _r ) ;
}
if ( headdata . PTORRED = = "2" )
{
var hp = new 东 胜 乐 企 他 用 ( headdata , Convert . ToString ( Session [ "USERID" ] ) ) ;
var _r = hp . DoReadInvoice ( "2" ) ;
if ( _r . Success = = true & & _r . Message . Contains ( "开票成功" ) )
{
ChinvoiceDAL . SetRed ( headdata ) ;
//将原票内的申请和费用恢复原状
var BlueInvoice = ChinvoiceDAL . GetData ( " cm.INVOICECODE='" + headdata . REDCODE + "' and cm.INVOICENO='" + headdata . REDNUM + "'" ) ;
SetInvoiceFee ( BlueInvoice ) ;
if ( string . IsNullOrWhiteSpace ( headdata . INVOICEPDFURL ) )
{
//初次读取 成功后发送邮件
if ( ! string . IsNullOrWhiteSpace ( headdata . PUSHEMAIL ) )
{
//NNSendMail(headdata.BILLNO, headdata.PUSHEMAIL);
NNSendMail_Djy ( headdata . BILLNO , headdata . PUSHEMAIL ) ;
}
}
}
_r . Data = ChinvoiceDAL . GetData ( " BILLNO='" + headdata . BILLNO + "'" ) ;
return BasicDataRefDAL . GetContentResult ( _r ) ;
}
}
}
return result . getContentReult ( ) ;
}
public ContentResult NNReadInv_P2 ( string BILLNO , string redirecturl )
{
var headdata = ChinvoiceDAL . GetData ( " cm.BILLNO='" + BILLNO + "'" ) ;
JsonResponse result = new JsonResponse ( ) ;
if ( ! string . IsNullOrWhiteSpace ( headdata . INVOICEPDFURL ) )
{
result . Success = true ;
result . Data = headdata ;
}
else
{
if ( headdata . INVITERFACE = = "诺诺发票接口" | | headdata . INVITERFACE = = "" )
{
result = Do_NNReadInv ( BILLNO , redirecturl ) ;
if ( result . Success )
{
//将相应信息写回P2
//1.正票/冲红 根据BSNO将P2的发票号和发票代码写回
//2.作废 根据BSNO将P2的 B_CANCEL设为1
var invoice = ( ChInvoice_HangXin ) result . Data ;
var sqlstr = $" update M_INVOICE set INVOICE_NO='{invoice.INVOICENO}',INVOICE_CODE='{invoice.INVOICECODE}',REMARK='{invoice.REMARK}' where INVOICE_ID='{invoice.BSNO}'" ;
BasicDataRefDAL . ExecSql_DB ( sqlstr , "P2DB" ) ;
}
}
else if ( headdata . INVITERFACE = = "瑞宏发票接口" )
{
RuihongHelper ruihongHelper = new RuihongHelper ( ) ;
string msg = null ;
var succ = ruihongHelper . QueryInvoiceRecord ( headdata . GID , headdata . INVOICESERIALNUM , out msg ) ;
var invoice = ChinvoiceDAL . GetData ( " BILLNO='" + headdata . BILLNO + "'" ) ;
result . Success = succ ;
result . Message = msg ;
result . Data = invoice ;
var sqlstr = $" update M_INVOICE set INVOICE_NO='{invoice.INVOICENO}',INVOICE_CODE='{invoice.INVOICECODE}',REMARK='{invoice.REMARK}' where INVOICE_ID='{invoice.BSNO}'" ;
BasicDataRefDAL . ExecSql_DB ( sqlstr , "P2DB" ) ;
}
else if ( headdata . INVITERFACE = = "诺诺全电发票" )
{
//诺诺全电发票的红票 读取其实是 读取红字确认单查询接口
if ( headdata . PTORRED = = "1" )
{
result = Do_NuoNuoQuanDianReadInv ( BILLNO ) ;
if ( result . Success )
{
//将相应信息写回P2
//1.正票/冲红 根据BSNO将P2的发票号和发票代码写回
//2.作废 根据BSNO将P2的 B_CANCEL设为1
var invoice = ( ChInvoice_HangXin ) result . Data ;
var sqlstr = $" update M_INVOICE set INVOICE_NO='{invoice.INVOICENO}',INVOICE_CODE='{invoice.INVOICECODE}',REMARK='{invoice.REMARK}' where INVOICE_ID='{invoice.BSNO}'" ;
BasicDataRefDAL . ExecSql_DB ( sqlstr , "P2DB" ) ;
}
}
if ( headdata . PTORRED = = "2" )
{
var _r = NNRedConfirm_Read ( BILLNO ) ;
if ( _r . Success )
{
//将相应信息写回P2
//1.正票/冲红 根据BSNO将P2的发票号和发票代码写回
//2.作废 根据BSNO将P2的 B_CANCEL设为1
var invoice = ( ChInvoice_HangXin ) result . Data ;
var sqlstr = $" update M_INVOICE set INVOICE_NO='{invoice.INVOICENO}',INVOICE_CODE='{invoice.INVOICECODE}',REMARK='{invoice.REMARK}' where INVOICE_ID='{invoice.BSNO}'" ;
BasicDataRefDAL . ExecSql_DB ( sqlstr , "P2DB" ) ;
}
return BasicDataRefDAL . GetContentResult ( _r ) ;
}
}
}
return result . getContentReult ( ) ;
}
private JsonResponse Do_NNReadInv ( string BILLNO , string redirecturl )
{
//var hx = HangXinRequestHelper.getHelper(taxnum);
//var result = new DBResult();
//var detail = new List<chinvoice_de>
var jsonRespose = new JsonResponse { Success = false , Message = "" , Data = "" } ;
//首先判断数据完整性与合法性
var checkresult = checkCanRead ( BILLNO , redirecturl ) ;
if ( ! checkresult . Success ) return checkresult ;
var head = ( ChInvoice_HangXin ) checkresult . Data ;
var hx = HangXinRequestHelper . getHelper ( head . TAXCODE ) ;
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return jsonRespose ;
}
if ( hx . accessToken = = "" )
{
BasicDataRefDAL . SaveLog ( "NNReadInv;税号" + head . TAXCODE + "的 accessToken为空" , "" , "诺诺平台" , "返回认证窗口" ) ;
var _r = TokenPage ( ) ;
return _r ;
}
var result = hx . ReadInvoice ( head ) ;
if ( result . Message = = "需要重新认证" )
{
//HangXinRequestHelper.clear(hx.accessToken);
BasicDataRefDAL . SaveLog ( "ReadInvoice 反回‘需要重新认证’" , "" , "诺诺平台" , "返回认证窗口" ) ;
var _r = TokenPage ( ) ;
return _r ;
}
var returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
if ( head . PTORRED = = "2" )
{
ChinvoiceDAL . SetRed ( head ) ;
//将原票内的申请和费用恢复原状
var BlueInvoice = ChinvoiceDAL . GetData ( " cm.INVOICECODE='" + head . REDCODE + "' and cm.INVOICENO='" + head . REDNUM + "'" ) ;
result = SetInvoiceFee ( BlueInvoice ) ;
}
//如果状态为开出成功 则执行锁定
if ( returndate . EINVOICESTATE = = "2" & & returndate . BILLSTATUS = = 0 )
{
//ChinvoiceDAL.Lock(returndate.BILLNO);
//20200106 添加 如sys_param_set.PARAMNAME=INVOICEAUTOLOCK 没有值或值为false 则不执行锁定
var needautolock = MsSysParamSetDAL . GetSysParam ( "INVOICEAUTOLOCK" ) . isnullortrue ( ) ;
if ( needautolock )
{
ChinvoiceDAL . Lock ( returndate . BILLNO , Convert . ToString ( Session [ "USERID" ] ) ) ;
}
returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
}
result . Data = returndate ;
jsonRespose = new JsonResponse ( result ) ;
return jsonRespose ;
}
/// <summary>
/// 邮件转发
/// </summary>
/// <param name="BILLNO"></param>
/// <param name="redirecturl"></param>
/// <returns></returns>
public ContentResult NNSendMail ( string BILLNO , string EMAIL )
{
//如果已有pdf地址 则直接返回
var headData = ChinvoiceDAL . GetData ( " cm.BILLNO='" + BILLNO + "'" ) ;
var cdc = new Common . DB . CommonDataContext ( ) ;
var 销 方 抬 头 = cdc . company . First ( x = > x . GID = = headData . SALECORPID ) . BILLRISES ;
DBResult result = new DBResult ( ) ;
if ( ! string . IsNullOrWhiteSpace ( headData . INVOICEPDFURL ) )
{
var mailtitle = $"您收到一张 【{销方抬头}】开具的发票 票号:{headData.INVOICENO} 金额:{headData.INVAMOUNT}" ;
var Body = new StringBuilder ( ) ;
Body . Append ( "<html> <Body>" ) ;
//Body.Append($"<br /><a href=\"{headData.INVOICEINFOURL}\">电子发票:{headData.INVOICENO}</a><br />");
Body . Append ( $"<br />购方名称:{headData.INVOICECUSTNAME}<br />" ) ;
Body . Append ( $"<br />发票号码:{headData.INVOICENO}<br />" ) ;
Body . Append ( $"<br />开票日期:{headData.INVOICEMAKETIME.Replace(" 00 : 00 : 00.000 ", " ")}<br />" ) ;
Body . Append ( $"<br />合计金额:{headData.INVAMOUNT}<br />" ) ;
Body . Append ( $"<br /><a href=\" { headData . INVOICEPDFURL } \ ">PDF链接(点击查看)</a><br />" ) ;
var mailto = EMAIL ;
var MAILTONAME = "admin@dongshengsoft.com" ;
var PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTONAME'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTONAME = PARAMVALUE . PARAMVALUE ;
var MAILTOPASSWORD = "ds!@#)(*" ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTOPASSWORD'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTOPASSWORD = PARAMVALUE . PARAMVALUE ;
var MAILTOSERVER = "smtpcom.263xmail.com" ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTOSERVER'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTOSERVER = PARAMVALUE . PARAMVALUE ;
var MAILTOPORT = "465" ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTOPORT'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTOPORT = PARAMVALUE . PARAMVALUE ;
var MAILISSSL = false ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILISSSL'" ) ;
if ( PARAMVALUE . PARAMVALUE = = "1" ) MAILISSSL = true ;
SendEmail se = new SendEmail ( mailto , MAILTONAME , "" , "" , mailtitle , Body . ToString ( ) , true ) ;
// SendEmail se = new SendEmail("dev001@dongshengsoft.com", "admin@dongshengsoft.com", "", "", mailtopic, mailbody, false);
//string filePath = filename;
//se.Attachments(filePath);
try
{
se . SetSmtp ( MAILTONAME , MAILTOPASSWORD , MAILTOSERVER , Convert . ToInt32 ( MAILTOPORT ) , MAILISSSL , System . Net . Mail . MailPriority . Normal ) ; //必须在所有参数设置完后调用此方法
}
catch ( Exception e )
{
se . SetSmtp ( MAILTONAME , MAILTOPASSWORD , MAILTOSERVER , Convert . ToInt32 ( MAILTOPORT ) , MAILISSSL , System . Net . Mail . MailPriority . Normal ) ; //必须在所有参数设置完后调用此方法
}
result . OK ( "发送成功" ) ;
}
else
{
result . SetErrorInfo ( "请先读取发票" ) ;
}
return BasicDataRefDAL . GetContentResult ( result ) ;
}
/// <summary>
/// 邮件转发
/// </summary>
/// <param name="BILLNO"></param>
/// <param name="redirecturl"></param>
/// <returns></returns>
public ContentResult NNSendMail_Djy2 ( string BILLNO , string EMAIL )
{
//如果已有pdf地址 则直接返回
var headData = ChinvoiceDAL . GetData ( " cm.BILLNO='" + BILLNO + "'" ) ;
var cdc = new Common . DB . CommonDataContext ( ) ;
var 销 方 抬 头 = cdc . company . First ( x = > x . GID = = headData . SALECORPID ) . BILLRISES ;
DBResult result = new DBResult ( ) ;
if ( ! string . IsNullOrWhiteSpace ( headData . INVOICEPDFURL ) )
{
var mailtitle = $"您收到一张 【{销方抬头}】开具的发票 票号:{headData.INVOICENO} 金额:{headData.INVAMOUNT}" ;
var Body = new StringBuilder ( ) ;
Body = new StringBuilder ( GetDjyInvMail ( ) ) ;
Body = Body . Replace ( "$VIEW_URL$" , headData . INVOICEPDFURL ) ;
Body = Body . Replace ( "$CUST_NAME$" , headData . INVOICECUSTNAME ) ;
Body = Body . Replace ( "$INV_DATA$" , headData . INVOICEMAKETIME . Replace ( " 00:00:00.000" , "" ) ) ;
Body = Body . Replace ( "$TOTAL$" , headData . INVAMOUNT . ToString ( ) ) ;
Body = Body . Replace ( "$INV_CODE$" , headData . INVOICENO ) ;
Body = Body . Replace ( "$PDF_URL$" , headData . INVOICEPDFURL ) ;
var mailto = EMAIL ;
var MAILTONAME = "admin@dongshengsoft.com" ;
var PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTONAME'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTONAME = PARAMVALUE . PARAMVALUE ;
var MAILTOPASSWORD = "ds!@#)(*" ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTOPASSWORD'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTOPASSWORD = PARAMVALUE . PARAMVALUE ;
var MAILTOSERVER = "smtpcom.263xmail.com" ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTOSERVER'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTOSERVER = PARAMVALUE . PARAMVALUE ;
var MAILTOPORT = "465" ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILTOPORT'" ) ;
if ( PARAMVALUE . PARAMVALUE ! = "" ) MAILTOPORT = PARAMVALUE . PARAMVALUE ;
var MAILISSSL = false ;
PARAMVALUE = MsSysParamSetDAL . GetData ( "PARAMNAME='MAILISSSL'" ) ;
if ( PARAMVALUE . PARAMVALUE = = "1" ) MAILISSSL = true ;
SendEmail se = new SendEmail ( mailto , MAILTONAME , "" , "" , mailtitle , Body . ToString ( ) , true ) ;
// SendEmail se = new SendEmail("dev001@dongshengsoft.com", "admin@dongshengsoft.com", "", "", mailtopic, mailbody, false);
//string filePath = filename;
//se.Attachments(filePath);
try
{
se . SetSmtp ( MAILTONAME , MAILTOPASSWORD , MAILTOSERVER , Convert . ToInt32 ( MAILTOPORT ) , MAILISSSL , System . Net . Mail . MailPriority . Normal ) ; //必须在所有参数设置完后调用此方法
}
catch ( Exception e )
{
se . SetSmtp ( MAILTONAME , MAILTOPASSWORD , MAILTOSERVER , Convert . ToInt32 ( MAILTOPORT ) , MAILISSSL , System . Net . Mail . MailPriority . Normal ) ; //必须在所有参数设置完后调用此方法
}
result . OK ( "发送成功" ) ;
}
else
{
result . SetErrorInfo ( "请先读取发票" ) ;
}
return BasicDataRefDAL . GetContentResult ( result ) ;
}
public ContentResult NNSendMail_Djy ( string BILLNO , string EMAIL )
{
var headData = ChinvoiceDAL . GetData ( " cm.BILLNO='" + BILLNO + "'" ) ;
var cdc = new Common . DB . CommonDataContext ( ) ;
var 销 方 抬 头 = cdc . company . First ( x = > x . GID = = headData . SALECORPID ) . BILLRISES ;
DBResult result = new DBResult ( ) ;
if ( ! string . IsNullOrWhiteSpace ( headData . INVOICEPDFURL ) )
{
DjyEmailSendReq hp = new DjyEmailSendReq ( ) ;
hp . SendTo = EMAIL ;
hp . Title = $"您收到一张 【{销方抬头}】开具的发票 票号:{headData.INVOICENO} 金额:{headData.INVAMOUNT}" ;
hp . Body = GetDjyInvMail ( ) ;
hp . Body = hp . Body . Replace ( "$VIEW_URL$" , headData . INVOICEPDFURL ) ;
hp . Body = hp . Body . Replace ( "$CUST_NAME$" , headData . INVOICECUSTNAME ) ;
hp . Body = hp . Body . Replace ( "$INV_DATA$" , headData . INVOICEMAKETIME . Replace ( " 00:00:00.000" , "" ) ) ;
hp . Body = hp . Body . Replace ( "$TOTAL$" , headData . INVAMOUNT . ToString ( ) ) ;
hp . Body = hp . Body . Replace ( "$INV_CODE$" , headData . INVOICENO ) ;
hp . Body = hp . Body . Replace ( "$PDF_URL$" , headData . INVOICEPDFURL ) ;
/ * SmtpConfig 值 说 明
CANGDAN dongshengcangdan @h8j . top
INVOICE inv @mail . myshipping . net
NOREPLAY noreplay @mail . myshipping . net
SERVICE service @mail . myshipping . net
SPOT spot @mail . myshipping . net
* /
hp . SmtpConfig = "INVOICE" ;
var pdfbase64 = BasicDataRefDAL . GetUrlBase64 ( headData . INVOICEPDFURL ) ;
if ( ! string . IsNullOrWhiteSpace ( pdfbase64 ) )
{
var pdf = new Attaches ( ) ;
pdf . AttachName = headData . INVOICENO + ".pdf" ;
pdf . AttachContent = pdfbase64 ;
hp . Attaches = new List < Attaches > ( ) ;
hp . Attaches . Add ( pdf ) ;
}
BasicDataRefDAL . SendEmailByDjy ( hp ) ;
//SendEmailByDjy
result . OK ( "转发成功" ) ;
}
else
{
result . SetErrorInfo ( "请先读取发票" ) ;
}
return BasicDataRefDAL . GetContentResult ( result ) ;
}
/// <summary>
///
///
///$VIEW_URL$ 发票地址
///$CUST_NAME$ 购方名称
///$INV_DATA$ 开票日期
///$TOTAL$ 合计金额
///$INV_CODE$发票号码
///$PDF_URL$ 发票下载地址
/// </summary>
///
/// <returns></returns>
public static string GetDjyInvMail ( )
{
var result = @ "<!DOCTYPE html>
< html >
< head >
< meta charset = "" utf - 8 "" / >
< title > 发 送 发 票 邮 件 < / title >
< / head >
< body >
< div style = "" width : 728 px ; border : 1 px solid # e5e6e7 ; margin : 20 px auto ; padding - bottom : 40 px ; "" >
< img src = "" data : image / jpg ; base64 , / 9 j / 4 QDeRXhpZgAASUkqAAgAAAAHABIBAwABAAAAAQAAABoBBQABAAAAYgAAABsBBQABAAAAagAAACgBAwABAAAAAgAAADEBAgAcAAAAcgAAADIBAgAXAAAAjgAAAGmHBAABAAAApgAAAAAAAACA / AoAECcAAID8CgAQJwAAQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzADIwMjAtMDctMDFUMTU6MDcrMDg6MDAAAAMAAJAHAAQAAAAwMjIwAqAEAAEAAADYAgAAA6AEAAEAAADPAAAAAAAAAM8AAAAAAP / sABFEdWNreQABAAQAAABkAAD / 4 Ry3aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu + 7 vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI / PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI + IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI + IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcDpDcmVhdGVEYXRlPSIyMDIwLTA3LTAxVDEwOjE1OjUwKzA4OjAwIiB4bXA6TWV0YWRhdGFEYXRlPSIyMDIwLTA3LTAxVDE1OjA3KzA4OjAwIiB4bXA6TW9kaWZ5RGF0ZT0iMjAyMC0wNy0wMVQxNTowNyswODowMCIgZGM6Zm9ybWF0PSJpbWFnZS9qcGVnIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjc1NzcwMjk4QkI2OTExRUE4ODYxRTNEQ0Y5Q0JERjc1IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjc1NzcwMjk5QkI2OTExRUE4ODYxRTNEQ0Y5Q0JERjc1IiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9InhtcC5kaWQ6MzQ3RjZFOUMzNUJCRUExMUI0MkVGNjVFMzdDNkZFQjUiPiA8eG1wTU06SGlzdG9yeT4gPHJkZjpTZXE + IDxyZGY6bGkgc3RFdnQ6YWN0aW9uPSJjcmVhdGVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjM0N0Y2RTlDMzVCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDEwOjE1OjUwKzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjM1N0Y2RTlDMzVCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDExOjUzOjU5KzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjM2N0Y2RTlDMzVCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDEzOjM1KzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjM3N0Y2RTlDMzVCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDEzOjM1OjMzKzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjM4N0Y2RTlDMzVCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDEzOjQwOjE4KzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjM5N0Y2RTlDMzVCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDE0OjAwOjUyKzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjNDN0Y2RTlDMzVCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDE0OjAzOjE4KzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjQ3NTdFN0YyNjBCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDE0OjA2OjA1KzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249InNhdmVkIiBzdEV2dDppbnN0YW5jZUlEPSJ4bXAuaWlkOjQ4NTdFN0YyNjBCQkVBMTFCNDJFRjY1RTM3QzZGRUI1IiBzdEV2dDp3aGVuPSIyMDIwLTA3LTAxVDE0OjA2OjI4KzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHN0RXZ0OmNoYW5nZWQ9Ii8iLz4gPHJkZjpsaSBzdEV2dDphY3Rpb249In
< div style = "" padding : 0 px 40 px ; "" >
< p style = "" margin - top : 30 px ; color : # 666 ; "" > 尊 敬 的 的 客 户 , 您 好 ! < / p >
< p style = "" margin - top : 15 px ; color : # 666 ; text - indent : 2 em ; "" > 您 收 到 一 张 电 子 发 票 , 点 击 & nbsp ; & nbsp ; < a style = "" border - bottom : 1 px solid # 4395f f ; padding - bottom : 2 px ; text - decoration : none ; color : # 4395f f ; "" href = "" $ VIEW_URL $"" > 查 看 发 票 < / a > , 摘 要 信 息 如 下 : < / p >
< / div >
< div style = "" width : 588 px ; background : # f9fbff ; border : 1 px solid # e0e2e4 ; padding : 20 px 30 px ; margin : 20 px auto ; "" >
< table >
< tbody >
< tr style = "" height : 26 px ; "" >
< td colspan = "" 2 "" style = "" color : # 666 ; "" >
购 方 名 称 : < span style = "" color : # 4395f f ; "" > $ CUST_NAME $ < / span >
< / td >
< / tr >
< tr style = "" height : 26 px ; "" >
< td style = "" width : 338 px ; color : # 666 ; "" >
开 票 日 期 : < span style = "" color : # 4395f f ; "" > $ INV_DATA $ < / span >
< / td >
< td style = "" width : 166 px ; color : # 666 ; "" >
合 计 金 额 : < span style = "" color : # 4395f f ; "" > $ TOTAL $ < / span >
< / td >
< / tr >
< tr style = "" height : 26 px ; "" >
发 票 号 码 : < span style = "" color : # 4395f f ; "" > $ INV_CODE $ < / span >
< / td >
< td style = "" width : 166 px ; color : # 666 ; "" >
< / td >
< / tr >
< tr style = "" height : 26 px ; "" >
< td colspan = "" 2 "" style = "" color : # 666 ; "" >
发 票 下 载 地 址 : < a style = "" color : # 4395f f ; "" href = "" $ PDF_URL $"" > $ PDF_URL $ < / a >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
< div style = "" padding : 0 40 px ; "" >
< p style = "" text - indent : 2 em ; color : # 666 ; "" > 此 致 < / p >
< p style = "" color : # 666 ; "" > 大 简 云 ( < a style = "" border - bottom : 1 px solid # 4395f f ; padding - bottom : 2 px ; text - decoration : none ; color : # 4395f f ; "" href = "" http : //www.myshipping.net"">http://www.myshipping.net</a>) </p>
< / div >
< / div >
< / body >
< / html > ";
//$VIEW_URL$ 发票地址
//$CUST_NAME$ 购方名称
//$INV_DATA$ 开票日期
//$TOTAL$ 合计金额
//$INV_CODE$发票号码
//$PDF_URL$ 发票下载地址
return result ;
}
public JsonResponse Do_NuoNuoQuanDianReadInv ( string BILLNO )
{
//var hx = HangXinRequestHelper.getHelper(taxnum);
//var result = new DBResult();
//var detail = new List<chinvoice_de>
var jsonRespose = new JsonResponse { Success = false , Message = "" , Data = "" } ;
//首先判断数据完整性与合法性
var checkresult = checkCanRead ( BILLNO ) ;
if ( ! checkresult . Success ) return checkresult ;
var head = ( ChInvoice_HangXin ) checkresult . Data ;
var hx = 诺 诺 全 电 发 票 . getHelper ( head ) ;
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return jsonRespose ;
}
if ( hx . accessToken = = "" )
{
BasicDataRefDAL . SaveLog ( "NNReadInv;税号" + head . TAXCODE + "的 accessToken为空" , "" , "诺诺平台" , "返回认证窗口" ) ;
var _r = TokenPage ( ) ;
return _r ;
}
var result = hx . ReadInvoice ( head ) ;
if ( ! result . Success )
{
return new JsonResponse { Success = result . Success , Message = result . Message , Data = "" } ; ;
}
//if (result.Message == "需要重新认证")
//{
// //HangXinRequestHelper.clear(hx.accessToken);
// BasicDataRefDAL.SaveLog("ReadInvoice 反回‘需要重新认证’", "", "诺诺平台", "返回认证窗口");
// var _r = TokenPage();
// return _r;
//}
var returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
if ( head . PTORRED = = "2" )
{
ChinvoiceDAL . SetRed ( head ) ;
//将原票内的申请和费用恢复原状
var BlueInvoice = ChinvoiceDAL . GetData ( " cm.INVOICECODE='" + head . REDCODE + "' and cm.INVOICENO='" + head . REDNUM + "'" ) ;
result = SetInvoiceFee ( BlueInvoice ) ;
}
//如果状态为开出成功 则执行锁定
if ( returndate . EINVOICESTATE = = "2" & & returndate . BILLSTATUS = = 0 )
{
//ChinvoiceDAL.Lock(returndate.BILLNO);
//20200106 添加 如sys_param_set.PARAMNAME=INVOICEAUTOLOCK 没有值或值为false 则不执行锁定
var needautolock = MsSysParamSetDAL . GetSysParam ( "INVOICEAUTOLOCK" ) . isnullortrue ( ) ;
if ( needautolock )
{
ChinvoiceDAL . Lock ( returndate . BILLNO , Convert . ToString ( Session [ "USERID" ] ) ) ;
}
returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
}
result . Data = returndate ;
jsonRespose = new JsonResponse ( result ) ;
return jsonRespose ;
}
public static string getRedirecturl ( string redirecturl )
{
return redirecturl ;
}
/// <summary>
/// 将发票业务内的申请或者费用恢复原状
/// </summary>
/// <param name="BlueInvoice"></param>
/// <returns></returns>
public DBResult SetInvoiceFee ( ChInvoice_HangXin BlueInvoice )
{
//var result = new DBResult();
//if (BlueInvoice.INVOICETYPE == 2)
//{
// //申请开票
// var dataList = ChinvoiceapplicationDAL.GetDataListAll("INVBILLNO='" + BlueInvoice.BILLNO + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
// result = ChinvoiceDAL.DelAppList(dataList, BlueInvoice.BILLNO);
//}
//else
//{
// var dataList = ChinvoiceDAL.GetBodyList("BILLNO='" + BlueInvoice.BILLNO + "'");
// result = ChinvoiceDAL.DelFeeDo(dataList, BlueInvoice.GID);
//}
//return result;
var result = ChinvoiceDAL . SetInvoiceFee ( BlueInvoice , Session ) ;
return result ;
}
/// <summary>
/// 发票作废
/// </summary>
/// <param name="BILLNO"></param>
/// <param name="redirecturl"></param>
/// <returns></returns>
public ContentResult NNVoidInv ( string BILLNO , string redirecturl )
{
//首先判断是否有 modInvLock 发票开出锁定
var result = Do_NNVoidInv ( BILLNO , redirecturl ) ;
return result . getContentReult ( ) ;
}
public ContentResult NNVoidInv_P2 ( string BILLNO , string redirecturl )
{
//首先判断是否有 modInvLock 发票开出锁定
var result = Do_NNVoidInv ( BILLNO , redirecturl ) ;
if ( result . Success )
{
//将相应信息写回P2
//1.正票/冲红 根据BSNO将P2的发票号和发票代码写回
//2.作废 根据BSNO将P2的 B_CANCEL设为1
var invoice = ( ChInvoice_HangXin ) result . Data ;
var sqlstr = $" update M_INVOICE set B_CANCEL='1' where INVOICE_ID='{invoice.BSNO}'" ;
BasicDataRefDAL . ExecSql_DB ( sqlstr , "P2DB" ) ;
}
return result . getContentReult ( ) ;
}
public JsonResponse Do_NNVoidInv ( string BILLNO , string redirecturl )
{
var jsonRespose = new JsonResponse { Success = false , Message = "" , Data = "" } ;
//首先判断数据完整性与合法性 以及如果缺少认证信息则返回重新进行认证
var checkresult = checkinfo ( BILLNO , redirecturl ) ;
if ( ! checkresult . Success ) return checkresult ;
var head = ( ChInvoice_HangXin ) checkresult . Data ;
if ( string . IsNullOrEmpty ( head . INVOICESERIALNUM ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = "没有进行平台开票的发票无法进行作废操作。" ;
return jsonRespose ;
}
if ( head . PTORRED = = "2" | | head . SETRED = = "true" )
{
jsonRespose . Success = false ;
jsonRespose . Message = "冲红或被冲红的发票不能作废" ;
return jsonRespose ;
}
if ( head . ISDELETE = = "true" )
{
jsonRespose . Success = false ;
jsonRespose . Message = "已作废的发票不能再次作废" ;
return jsonRespose ;
}
if ( head . ISEInvoice )
{
jsonRespose . Success = false ;
jsonRespose . Message = "电子发票不能作废,只能冲红" ;
return jsonRespose ;
}
var hx = new HangXinRequestHelper ( ) ;
if ( head . INVITERFACE = = "诺诺发票接口" | | head . INVITERFACE = = "" )
{
hx = HangXinRequestHelper . getHelper ( head . TAXCODE ) ;
}
else if ( head . INVITERFACE = = "瑞宏发票接口" )
{
}
else if ( head . INVITERFACE = = "诺诺全电发票" | | head . INVITERFACE = = "东胜乐企他用" )
{
//hx = 诺诺全电发票.getHelper(head.TAXCODE);
//jsonRespose.Success = false;
//jsonRespose.Message = "全电发票没有作废操作,请执行冲红操作。";
//return jsonRespose;
}
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return jsonRespose ;
}
var result = hx . VoidInvoice ( head ) ;
var _result = new ContentResult ( ) ;
//发送作废成功,则实际进行作废操作
if ( result . Success )
{
_result = DeleteUp ( head ) ;
}
var returndate = ChinvoiceDAL . GetData ( " cm.BILLNO='" + BILLNO + "'" ) ;
result . Data = returndate ;
JsonResponse respose = new JsonResponse ( result ) ;
return respose ;
}
/// <summary>
/// 发票冲红
/// </summary>
/// <param name="BILLNO"></param>
/// <param name="redirecturl"></param>
/// <returns></returns>
public ContentResult NNSetRed ( string bill , string redirecturl , string redReason = "" )
{
//首先判断是否有 modInvLock 发票开出锁定
var result = new DBResult ( ) ;
//var detail = new List<chinvoice_de>
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message , Data = result . Data } ;
//首先判断数据完整性与合法性 及检查平台认证
var checkresult = checkinfo ( bill , redirecturl , redReason , true ) ;
//被冲红的蓝票信息
var BlueInvoice = ChinvoiceDAL . GetData ( " cm.billno='" + bill + "'" ) ;
BlueInvoice . billUuid = BlueInvoice . GID . Replace ( "-" , "" ) ;
if ( BlueInvoice . ISNEEDFEE = = "1" )
{
jsonRespose . Success = false ;
jsonRespose . Message = $"该蓝票已结算,当前无法冲红" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
if ( ! checkresult . Success )
{
return new ContentResult ( ) { Content = JsonConvert . Serialize ( checkresult ) } ;
}
else
{
var head = ( ChInvoice_HangXin ) checkresult . Data ;
var BlueHead = head ;
if ( head . INVITERFACE = = "诺诺全电发票" )
{
//全电发票没有发票代码
if ( string . IsNullOrEmpty ( head . INVOICENO ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = "该电子发票没有发票号,无法进行冲红。" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
if ( string . IsNullOrEmpty ( redReason ) )
{
//jsonRespose.Success = false;
//jsonRespose.Message = "必须选择冲红理由。";
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
redReason = "2" ;
}
//增加判断 如果原票createtime晚于当前时间24小时之前, 则报错不允许开出
//20231120 取消此限制
//if (BlueInvoice.INVOICEMAKETIME == null || BlueInvoice.INVOICEMAKETIME == "" || Convert.ToDateTime(BlueInvoice.INVOICEMAKETIME) > DateTime.Now.AddDays(-1))
//{
// jsonRespose.Success = false;
// jsonRespose.Message = $"该蓝票为{BlueInvoice.INVOICEMAKETIME}开出,当前无法冲红";
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
//}
}
else if ( head . INVITERFACE = = "东胜乐企他用" )
{
if ( string . IsNullOrEmpty ( head . INVOICENO ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = "该电子发票没有发票号,无法进行冲红。" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
if ( string . IsNullOrEmpty ( redReason ) )
{
//jsonRespose.Success = false;
//jsonRespose.Message = "必须选择冲红理由。";
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
redReason = "2" ;
}
}
else
//if (head.INVITERFACE != "诺诺全电发票" && head.INVITERFACE != "东胜乐企他用")
{
if ( string . IsNullOrEmpty ( head . INVOICENO ) | | string . IsNullOrEmpty ( head . INVOICECODE ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = "该发票没有发票号和发票代码,无法进行冲红。" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
var beRedBillNo = head . BILLNO ;
var RedCode = head . INVOICECODE ;
var RedNo = head . INVOICENO ;
var detailList = ChinvoiceDAL . GetDetailList ( "PID='" + head . GID + "'" ) ;
var redhead = AutoMapperHelper . MapTo < ChInvoice_HangXin , ChInvoice_HangXin > ( head ) ;
//如果已经存在一张相应的红票, 则将现在这个head变成那个红票
var _existRed = ChinvoiceDAL . GetData ( " REDNUM='" + head . INVOICENO + "' and REDCODE='" + head . INVOICECODE + "' " ) ;
if ( _existRed . BILLNO ! = "*" )
{
head = _existRed ;
head . REMARK = REDREMARK ( head . REMARK ) ;
detailList = ChinvoiceDAL . GetDetailList ( "PID='" + head . GID + "'" ) ;
head . DbOperationType = DbOperationType . DbotUpd ;
head . ModelUIStatus = "E" ;
}
else
{
if ( head . INVITERFACE ! = "诺诺全电发票" & & head . INVITERFACE ! = "东胜乐企他用" )
{
//将该head改成一个新的发票信息
//将发票明细也同样处理
head . GID = System . Guid . NewGuid ( ) . ToString ( ) ;
head . BILLNO = PubSysDAL . GetBillNo ( "0308" ) ;
head . PTORRED = "2" ; // 开票类型 红票
head . INVOICECODE = "" ;
head . INVOICENO = "" ;
head . EINVOICESTATE = "0" ;
head . INVOICESERIALNUM = "" ;
//head.BILLSTATUS = 0;
head . REDCODE = RedCode ;
head . REDNUM = RedNo ;
head . INVAMOUNT = head . INVAMOUNT * - 1 ;
head . INVOICEPDFURL = "" ;
head . INVOICEINFOURL = "" ;
head . OTCURRAMOUNT = head . OTCURRAMOUNT * - 1 ;
head . DbOperationType = DbOperationType . DbotIns ;
head . ModelUIStatus = "I" ;
head . BILLSTATUS = 1 ;
foreach ( var detail in detailList )
{
//数量 税额 含税金额 不含税金额 取负数
detail . SetRed ( ) ;
detail . PID = "*" ;
}
#region SR2020060200007 红票清空推送模式和推送邮箱
head . PUSHMODE = "-1" ;
head . PUSHEMAIL = "" ;
head . PUSHMOBILE = "0" ;
# endregion
head . REMARK = REDREMARK ( head . REMARK ) ;
}
if ( head . INVITERFACE = = "诺诺全电发票" ) //|| head.INVITERFACE == "东胜乐企他用"
{
redhead . GID = System . Guid . NewGuid ( ) . ToString ( ) ;
//redhead.BILLNO = PubSysDAL.GetBillNo("0308");
redhead . PTORRED = "2" ; // 开票类型 红票
redhead . redReason = redReason ;
redhead . REDCODE = RedCode ;
redhead . REDNUM = RedNo ;
redhead . INVAMOUNT = redhead . INVAMOUNT * - 1 ;
redhead . INVOICEPDFURL = "" ;
redhead . INVOICEINFOURL = "" ;
redhead . DbOperationType = DbOperationType . DbotIns ;
redhead . ModelUIStatus = "I" ;
redhead . BILLSTATUS = 1 ;
redhead . OTCURRAMOUNT = head . OTCURRAMOUNT * - 1 ;
foreach ( var detail in detailList )
{
//数量 税额 含税金额 不含税金额 取负数
detail . SetRed ( ) ;
detail . PID = "*" ;
}
redhead . REMARK = REDREMARK_Quandian ( redhead ) ;
}
if ( head . INVITERFACE = = "东胜乐企他用" )
{
redhead . GID = System . Guid . NewGuid ( ) . ToString ( ) ;
//redhead.BILLNO = PubSysDAL.GetBillNo("0308");
redhead . PTORRED = "2" ; // 开票类型 红票
redhead . redReason = redReason ;
redhead . REDCODE = RedCode ;
redhead . REDNUM = RedNo ;
redhead . INVAMOUNT = redhead . INVAMOUNT * - 1 ;
redhead . INVOICEPDFURL = "" ;
redhead . INVOICEINFOURL = "" ;
redhead . DbOperationType = DbOperationType . DbotIns ;
redhead . ModelUIStatus = "I" ;
redhead . BILLSTATUS = 1 ;
redhead . OTCURRAMOUNT = redhead . OTCURRAMOUNT * - 1 ;
foreach ( var detail in detailList )
{
//数量 税额 含税金额 不含税金额 取负数
detail . SetRed ( ) ;
detail . PID = "*" ;
}
redhead . REMARK = REDREMARK_Quandian ( redhead ) ;
}
}
var modb = new ModelObjectDB ( ) ;
if ( head . INVITERFACE ! = "诺诺全电发票" & & head . INVITERFACE ! = "东胜乐企他用" )
{
//一般的红票业务此时保存红票信息
result = ChinvoiceDAL . SaveInvDetail ( head . GID , detailList ) ;
if ( result . Success = = true )
{
result = modb . Save ( head ) ;
} ;
}
var returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
if ( head . INVITERFACE = = "诺诺发票接口" | | head . INVITERFACE = = "" )
{
var hx = HangXinRequestHelper . getHelper ( head . TAXCODE ) ;
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return jsonRespose . getContentReult ( ) ;
}
HangXinRequestHelper . redirectUri = getRedirecturl ( redirecturl ) ;
result = hx . PostInvoice ( head , detailList ) ;
returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
//如果状态为开出成功 则执行锁定
//并将被冲红的原发票的setred属性设置成true
if ( returndate . EINVOICESTATE = = "2" & & returndate . BILLSTATUS = = 0 )
{
//ChinvoiceDAL.Lock(returndate.BILLNO);
//20200106 添加 如sys_param_set.PARAMNAME=INVOICEAUTOLOCK 没有值或值为false 则不执行锁定
var needautolock = MsSysParamSetDAL . GetSysParam ( "INVOICEAUTOLOCK" ) . isnullortrue ( ) ;
if ( needautolock )
{
ChinvoiceDAL . Lock ( returndate . BILLNO , Convert . ToString ( Session [ "USERID" ] ) ) ;
}
ChinvoiceDAL . SetRed ( returndate ) ;
//将原票内的申请和费用恢复原状
/ /
result = SetInvoiceFee ( BlueInvoice ) ;
}
}
else if ( head . INVITERFACE = = "瑞宏发票接口" )
{
RuihongHelper ruihongHelper = new RuihongHelper ( ) ;
string msg = null ;
result . Success = ruihongHelper . RedInvoiceRecord ( returndate . GID , out msg ) ;
result . Message = msg ;
if ( result . Success )
{
var needautolock = MsSysParamSetDAL . GetSysParam ( "INVOICEAUTOLOCK" ) . isnullortrue ( ) ;
if ( needautolock )
{
ChinvoiceDAL . Lock ( returndate . BILLNO , Convert . ToString ( Session [ "USERID" ] ) ) ;
}
ChinvoiceDAL . SetRed ( returndate ) ;
//将原票内的申请和费用恢复原状
/ /
result = SetInvoiceFee ( BlueInvoice ) ;
}
}
else if ( head . INVITERFACE = = "诺诺全电发票" )
{
var hx = 诺 诺 全 电 发 票 . getHelper ( head ) ;
if ( head . PTORRED = = "2" )
{
redhead = AutoMapperHelper . MapTo < ChInvoice_HangXin , ChInvoice_HangXin > ( head ) ;
//redhead.REDNUM = head.INVOICENO;
result = hx . ReadInvoice ( redhead ) ;
if ( ! result . Success )
{
return BasicDataRefDAL . GetContentResult ( result ) ;
}
else
{
ChinvoiceDAL . SetRed ( redhead ) ;
BlueInvoice = ChinvoiceDAL . GetData ( " cm.INVOICECODE='" + head . REDCODE + "' and cm.INVOICENO='" + head . REDNUM + "'" ) ;
result = SetInvoiceFee ( BlueInvoice ) ;
return BasicDataRefDAL . GetContentResult ( result ) ;
}
}
else
{
//20230529
//1 如果ch_fee_invoice.billuuid有值的话
//这个值是最近一次提交的红字确认单订单编码
//用这个值读取红字确认单状态 如成功则做红票相应的处理
//如状态15申请中 则不做操作返回申请中
//如非成功和15 则返回错误 并清空billuuid;
//2 如果ch_fee_invoice.billuuid无值 则重新产生值并发出红字确认单
//此时head.billUuid如果不为空 代表已有红字申请单
if ( ! string . IsNullOrWhiteSpace ( head . billUuid ) ) //&&
{
//redhead.BILLNO = redhead.billUuid;
redhead . GID = redhead . billUuid ;
var _r = hx . ReadRedConfirm ( ref redhead , detailList ) ;
if ( ! _r . Success )
{
if ( _r . Message ! = "红字确认单申请中" & & _r . Message ! = "提交失败,请先完成扫脸身份认证后再试。" )
{
//head.billUuid = "";
//modb.Save(head);
}
else
{
modb . Save ( head ) ;
}
return BasicDataRefDAL . GetContentResult ( _r ) ;
}
else
{
//var hx = 诺诺全电发票.getHelper(head.TAXCODE);
if ( ! hx . CanUse )
{
result . SetErrorInfo ( hx . ERRORMSG ) ;
return BasicDataRefDAL . GetContentResult ( result ) ;
}
//if (hx.accessToken == "")
//{
// BasicDataRefDAL.SaveLog("NNReadInv;税号" + head.TAXCODE + "的 accessToken为空", "", "诺诺平台", "返回认证窗口");
// var _r = TokenPage();
// return _r;
//}
result = hx . ReadInvoice ( redhead ) ;
if ( ! result . Success )
{
return BasicDataRefDAL . GetContentResult ( result ) ;
}
//if (result.Message == "需要重新认证")
//{
// //HangXinRequestHelper.clear(hx.accessToken);
// BasicDataRefDAL.SaveLog("ReadInvoice 反回‘需要重新认证’", "", "诺诺平台", "返回认证窗口");
// var _r = TokenPage();
// return _r;
//}
returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
if ( redhead . PTORRED = = "2" )
{
ChinvoiceDAL . SetRed ( redhead ) ;
//将原票内的申请和费用恢复原状
BlueInvoice = ChinvoiceDAL . GetData ( " cm.INVOICECODE='" + redhead . REDCODE + "' and cm.INVOICENO='" + redhead . REDNUM + "'" ) ;
result = SetInvoiceFee ( BlueInvoice ) ;
}
//如果状态为开出成功 则执行锁定
if ( returndate . EINVOICESTATE = = "2" & & returndate . BILLSTATUS = = 0 )
{
//ChinvoiceDAL.Lock(returndate.BILLNO);
//20200106 添加 如sys_param_set.PARAMNAME=INVOICEAUTOLOCK 没有值或值为false 则不执行锁定
var needautolock = MsSysParamSetDAL . GetSysParam ( "INVOICEAUTOLOCK" ) . isnullortrue ( ) ;
if ( needautolock )
{
ChinvoiceDAL . Lock ( returndate . BILLNO , Convert . ToString ( Session [ "USERID" ] ) ) ;
}
returndate = ChinvoiceDAL . GetData ( " BILLNO='" + head . BILLNO + "'" ) ;
}
result . Data = returndate ;
return BasicDataRefDAL . GetContentResult ( result ) ;
}
}
else
{
//head.billUuid如果为空 代表还没发红字申请单
//获取红票信息并发出
redhead . BILLNO = PubSysDAL . GetBillNo ( "0308" ) ;
head . billUuid = head . GID . Replace ( "-" , "" ) ;
redhead . GID = head . billUuid ;
//T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
//var blUpSQL = $" update ch_fee_invoice set billUuid='{head.billUuid}' where GID='{redhead.GID}'";
//bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
result = hx . PostRedConfirm ( redhead , ref head , detailList , Session ) ;
if ( result . Success = = false )
{
}
else
{
returndate = ( ChInvoice_HangXin ) result . Data ;
}
}
//诺诺全电票根据红字申请单的结果读取确认单
}
modb . Save ( head ) ;
}
else if ( head . INVITERFACE = = "东胜乐企他用" )
{
//http://60.209.125.238:32222/single/file/uQWgweivofs0kqoA3wllrvQefbLURSKwNwUMXuG2uwX5OAW02GtkjrvK7y3Wb0N3
//请求成功 则调用head.BILLNO = PubSysDAL.GetBillNo("0308"); 获取billno
//然后保存 并清除蓝票费用内容
//失败则返回失败
//head.redReason = redReason;
head . redReason = "01" ;
var cdc = new Common . DB . CommonDataContext ( ) ;
var enumvalueList = cdc . tSysEnumValue . Where ( x = > x . EnumTypeID = = 80008 & & x . EnumValueID = = head . redReason ) . ToList ( ) ;
if ( enumvalueList ! = null & & enumvalueList . Count > 0 )
{
head . redReason = enumvalueList [ 0 ] . EnumValueName_2 ;
}
var hp = new 东 胜 乐 企 他 用 ( head , Convert . ToString ( Session [ "USERID" ] ) ) ;
result = hp . DoSend_RedInvoice ( ) ;
if ( result . Success = = false )
{
return BasicDataRefDAL . GetContentResult ( result ) ;
}
var 红 字 确 认 单 申 请 返 回 值 = JsonConvert . Deserialize < 乐 企 他 用 红 字 确 认 单 申 请 返 回 > ( result . Data . ToString ( ) ) ;
if ( 红 字 确 认 单 申 请 返 回 值 . success = = false | | 红 字 确 认 单 申 请 返 回 值 . data = = null )
{
result . Message = "" ;
result . SetErrorInfo ( "服务器响应出错:" + 红 字 确 认 单 申 请 返 回 值 . msg ) ;
return BasicDataRefDAL . GetContentResult ( result ) ;
}
redhead . BILLNO = PubSysDAL . GetBillNo ( "0308" ) ;
redhead . billUuid = 红 字 确 认 单 申 请 返 回 值 . data . senid ;
redhead . INVOICENO = "" ;
result = modb . Save ( redhead ) ;
if ( result . Success = = false )
{
return BasicDataRefDAL . GetContentResult ( result ) ;
}
result . Data = ChinvoiceDAL . GetData ( " BILLNO='" + redhead . BILLNO + "'" ) ;
//return BasicDataRefDAL.GetContentResult(result);
//ChinvoiceDAL.SetRed(redhead);
////将原票内的申请和费用恢复原状
//var BlueInvoice2 = ChinvoiceDAL.GetData(" cm.INVOICECODE='" + redhead.REDCODE + "' and cm.INVOICENO='" + redhead.REDNUM + "'");
//result = SetInvoiceFee(BlueInvoice2);
}
jsonRespose . Success = result . Success ;
jsonRespose . Message = result . Message ;
jsonRespose . Data = returndate ;
}
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
/// <summary>
/// 诺诺全电发票 读取红字申请单
/// </summary>
/// <param name="bill"></param>
/// <returns></returns>
public DBResult NNRedConfirm_Read ( string BILLNO )
{
ChInvoice_HangXin head = ChinvoiceDAL . GetData ( "cm.BILLNO='" + BILLNO + "'" ) ;
var result = new DBResult ( ) ;
var hx = 诺 诺 全 电 发 票 . getHelper ( head ) ;
if ( ! hx . CanUse )
{
result . SetErrorInfo ( hx . ERRORMSG ) ;
return result ;
}
result = hx . ReadRedConfirm ( ref head ) ;
if ( ! result . Success ) { return result ; }
else
{
var _r = Do_NuoNuoQuanDianReadInv ( head . BILLNO ) ;
result . Success = _r . Success ;
result . Message = _r . Message ;
result . Data = _r . Data ;
}
return result ;
}
/// <summary>
/// 红票票面备注 固定追加
/// 对应正数发票代码:037021900111号码:84769822
/// 共42字节, 而总长度不能超过130字节
/// 因此红票的备注需要截断超过88字节长度的部分
/// </summary>
/// <param name="REMARK"></param>
/// <returns></returns>
private string REDREMARK ( string REMARK )
{
if ( REMARK . Length < = 88 ) return REMARK ;
else
{
while ( ( REMARK . Length > 88 ) & & ( REMARK . IndexOf ( " " ) > = 0 ) )
{
REMARK = REMARK . Replace ( " " , " " ) ;
}
if ( REMARK . Length > 88 )
{
REMARK = REMARK . Replace ( "\n" , "" ) ;
}
if ( REMARK . Length > 88 )
{
REMARK = REMARK . Substring ( 0 , 88 ) ;
}
return REMARK ;
}
}
private string REDREMARK_Quandian ( ChInvoice_HangXin head )
{
/ /
var 购 方 信 息 = " 购方账号:" + head . CUSTBANK ;
var 销 方 信 息 = " 销方账号:" + head . ACCOUNT ;
head . REMARK + = 购 方 信 息 + 销 方 信 息 ;
return head . REMARK ;
}
/// <summary>
/// 检查能否发出开票信息
/// </summary>
/// <param name="head"></param>
/// <returns></returns>
private DBResult checkCanPost ( ChInvoice_HangXin head )
{
var result = new DBResult ( true , "" , "" ) ;
if ( head . ISFRINV )
{
return result ;
}
if ( string . IsNullOrEmpty ( head . INVOICECUSTNAME ) ) setErrorMessage ( ref result , "购方名称 不能为空" ) ;
if ( string . IsNullOrEmpty ( head . PUSHMOBILE ) ) setErrorMessage ( ref result , "推送的手机号码 不能为空" ) ;
var ErrorInfo = "销售方公司(我方公司)没有维护:" ;
var LocalErrorInfo = "销售方公司(我方公司)没有维护:" ;
if ( string . IsNullOrWhiteSpace ( head . TAXCODE ) )
{
result . Success = false ;
LocalErrorInfo + = " 税务登记号 " ;
}
if ( string . IsNullOrWhiteSpace ( head . ADDRESS ) )
{
result . Success = false ;
if ( LocalErrorInfo ! = ErrorInfo )
LocalErrorInfo + = "、" ;
LocalErrorInfo + = " 公司地址 " ;
}
if ( string . IsNullOrWhiteSpace ( head . BILLRISES ) )
{
result . Success = false ;
if ( LocalErrorInfo ! = ErrorInfo )
LocalErrorInfo + = "、" ;
LocalErrorInfo + = " 公司发票抬头 " ;
}
if ( string . IsNullOrWhiteSpace ( head . OFFICEPHONE ) )
{
result . Success = false ;
if ( LocalErrorInfo ! = ErrorInfo )
LocalErrorInfo + = "、" ;
LocalErrorInfo + = " 办公电话 " ;
}
if ( LocalErrorInfo ! = ErrorInfo )
{
LocalErrorInfo + = " ,请在企业信息内录入。" ;
setErrorMessage ( ref result , LocalErrorInfo ) ;
}
if ( head . PTORRED = = "2" )
{
if ( string . IsNullOrEmpty ( head . REDCODE ) ) setErrorMessage ( ref result , "冲红时 蓝票代码 不能为空" ) ;
if ( string . IsNullOrEmpty ( head . REDCODE ) ) setErrorMessage ( ref result , "冲红时 蓝票号码 不能为空" ) ;
}
return result ;
}
/// <summary>
/// 检查能否发出读取发票信息
/// </summary>
/// <param name="BILLNO"></param>
/// <param name="redirecturl"></param>
/// <returns></returns>
private JsonResponse checkCanRead ( string BILLNO , string redirecturl = "" )
{
var result = new DBResult ( ) ;
var head = new ChInvoice_HangXin ( ) ;
//var detail = new List<chinvoice_de>
var jsonRespose = new JsonResponse { Success = true , Message = result . Message , Data = result . Data } ;
//首先判断数据完整性与合法性
head = ChinvoiceDAL . GetData ( "cm.BILLNO='" + BILLNO + "'" ) ;
if ( head . BILLNO ! = "" )
{
//head = list[0];
jsonRespose . Data = head ;
}
else
{
jsonRespose . Success = false ;
jsonRespose . Message = "没有找到可以开票的发票信息,可能是权限不足或登录信息丢失。" ;
}
if ( redirecturl ! = "" )
{
//如果该税号的token需要 返回认证窗口
var hx = HangXinRequestHelper . getHelper ( head . TAXCODE ) ;
if ( ! hx . CanUse )
{
jsonRespose . Success = false ;
jsonRespose . Message = hx . ERRORMSG ;
return jsonRespose ;
}
HangXinRequestHelper . redirectUri = getRedirecturl ( redirecturl ) ;
if ( hx . needStart )
{
BasicDataRefDAL . SaveLog ( "checkinfo; BILLNO=" + BILLNO , "" , "诺诺平台" , "返回认证窗口" ) ;
jsonRespose = TokenPage ( ) ;
}
}
return jsonRespose ;
}
private void setErrorMessage ( ref DBResult r , string message )
{
r . setMessage ( false , message ) ;
}
# endregion
public ContentResult UpdatePrint ( string billno )
{
DBResult result = ChinvoiceDAL . UpdatePrint ( billno ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
#region 发票模板
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetRemarksTemplate ( string TemplateName )
{
DBResult result = ChinvoiceDAL . GetRemarksTemplate ( Convert . ToString ( Session [ "COMPANYID" ] ) , TemplateName ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message , Data = result . Data } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult SaveRemarksTemplate ( string Template , string TemplateName )
{
DBResult result = ChinvoiceDAL . SaveRemarksTemplate ( Template , Convert . ToString ( Session [ "COMPANYID" ] ) , TemplateName ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult GetRemarksData ( string billno , string TemplateName )
{
var dataList = ChinvoiceDAL . GetBsList ( "c.BILLNO='" + billno + "'" ) ;
DBResult result = ChinvoiceDAL . GetRemarksData ( dataList , Convert . ToString ( Session [ "COMPANYID" ] ) , billno , TemplateName ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message , Data = result . Data } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
# endregion
#region 发票票册
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetBookDataList ( int start , int limit , string sort , string condition )
{
var dataList = ChinvoiceDAL . GetBookDataList ( condition , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetBookData ( string handle , string condition )
{
ChInvoiceBook_HangXin head = null ;
if ( handle = = "edit" )
{
var list = ChinvoiceDAL . GetBookDataList ( condition , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
if ( list . Count > 0 )
head = list [ 0 ] ;
}
if ( head = = null )
{
head = new ChInvoiceBook_HangXin ( ) ;
}
if ( handle = = "add" )
{
head . CREATEUSER = Convert . ToString ( Session [ "USERID" ] ) ;
head . CREATEUSERREF = Convert . ToString ( Session [ "SHOWNAME" ] ) ;
head . COMPANYID = Convert . ToString ( Session [ "COMPANYID" ] ) ;
}
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , data = head } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult SaveBook ( string opstatus , string data )
{
var headData = JsonConvert . Deserialize < ChInvoiceBook_HangXin > ( data ) ;
if ( opstatus = = "add" )
{
headData . GID = Guid . NewGuid ( ) . ToString ( ) ;
headData . COMPANYID = Convert . ToString ( Session [ "COMPANYID" ] ) ;
headData . CREATEUSER = Convert . ToString ( Session [ "USERID" ] ) ;
headData . CREATETIME = DateTime . Now . ToString ( ) ;
headData . DbOperationType = DbOperationType . DbotIns ;
}
else if ( opstatus = = "edit" )
{
headData . DbOperationType = DbOperationType . DbotUpd ;
headData . ModelUIStatus = "E" ;
}
else
{
headData . DbOperationType = DbOperationType . DbotDel ;
}
if ( headData . TYPE = = "" ) headData . TYPE = "0" ;
var BILLNO = headData . GID ;
var modb = new ModelObjectDB ( ) ;
DBResult result = modb . Save ( headData ) ;
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = ChinvoiceDAL . GetBookData ( " GID='" + BILLNO + "'" , Convert . ToString ( Session [ "COMPANYID" ] ) )
} ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult DeleteBook ( string data )
{
var headData = JsonConvert . Deserialize < ChInvoiceBook_HangXin > ( data ) ;
var isfee = ChinvoiceDAL . GetMakeOutCount ( headData . GID ) ;
if ( isfee )
{
var jsonRespose = new JsonResponse { Success = false , Message = "此票册已有开出发票,不允许删除!" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
else
{
DBResult result ;
var modb = new ModelObjectDB ( ) ;
result = modb . Delete ( headData ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
public ContentResult CreateBookitems ( string data )
{
var headData = JsonConvert . Deserialize < ChInvoiceBook_HangXin > ( data ) ;
DBResult result = ChinvoiceDAL . CreateBookitems ( headData , Convert . ToString ( Session [ "USERID" ] ) ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult LockBookitems ( string data )
{
var headData = JsonConvert . Deserialize < List < ChInvoiceBookdetail_HangXin > > ( data ) ;
DBResult result = ChinvoiceDAL . LockBookitems ( headData ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult CancelLockBookitems ( string data )
{
var headData = JsonConvert . Deserialize < List < ChInvoiceBookdetail_HangXin > > ( data ) ;
DBResult result = ChinvoiceDAL . CancelLockBookitems ( headData ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult GetBookitemsDataList ( string condition , string sort )
{
var dataList = ChinvoiceDAL . GetBookitemsDataList ( condition , sort ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult DeleteUpBook ( string data )
{
var headData = JsonConvert . Deserialize < ChInvoiceBook_HangXin > ( data ) ;
DBResult result ;
result = ChinvoiceDAL . DeleteUpBook ( headData . GID , Convert . ToString ( Session [ "USERID" ] ) ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
# endregion
#region 参照部分
# endregion
#region 联力 连接P2系统的sql数据库表 查询没有发票号的M_invoice表内容
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetP2Invoice ( string condition )
{
var canlogin = BasicDataRefDAL . CheckLogin ( Session ) ;
if ( ! canlogin . Success )
{
return ( ContentResult ) canlogin . Data ;
}
var _count = 0 ;
//(string TABLENAME,string _PKEY,string _sql,string DBNAME)
BaseTableMC fromdbbase = new BaseTableMC ( "M_INVOICE" , "INVOICE_ID" , "" , "P2DB" ) ;
var dataList = DBTableConnDAL . getToList ( fromdbbase , "联力P2发票" , condition ) ;
var list_2 = ModelObjectBill . getDicList ( ModelObjectConvert < BaseTableMC > . ToModelObjectList ( dataList ) ) ;
var json = JsonConvert . Serialize ( new
{
Success = true ,
Message = "查询成功" ,
totalCount = _count ,
data = list_2 . ToList ( )
} ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetP2Invoice_Fee ( string INVOICE_ID )
{
var canlogin = BasicDataRefDAL . CheckLogin ( Session ) ;
if ( ! canlogin . Success )
{
return ( ContentResult ) canlogin . Data ;
}
var _count = 0 ;
//(string TABLENAME,string _PKEY,string _sql,string DBNAME)
BaseTableMC fromdbbase = new BaseTableMC ( "M_INVOICE" , "INVOICE_ID" , "" , "P2DB" ) ;
if ( string . IsNullOrWhiteSpace ( INVOICE_ID ) ) INVOICE_ID = "0" ;
var dataList = DBTableConnDAL . getToList ( fromdbbase , "联力P2发票_明细" , $"INVOICE_ID='{INVOICE_ID}'" ) ;
var resultlist = new List < BaseTableMC > ( ) ;
var splitword = "\r\n" ;
if ( dataList . Count > 0 )
{
foreach ( var data in dataList )
{
var feenamearray = data . GetSplitField ( "FEENAME" , splitword ) ;
var amoutarray = data . GetSplitField ( "AMOUNT" , splitword ) ;
var PRICEarray = data . GetSplitField ( "PRICE" , splitword ) ;
var ratearray = data . GetSplitField ( "RATE" , splitword ) ;
var NUMarray = data . GetSplitField ( "NUM" , splitword ) ;
if ( feenamearray . Length > 1 )
{
for ( var _i = 0 ; _i < feenamearray . Length ; _i + + )
{
if ( string . IsNullOrWhiteSpace ( feenamearray [ _i ] ) ) continue ;
var resultdata = new BaseTableMC ( ) ;
resultdata . SetValue ( "CURRENCY" , data . GetValue ( "CURRENCY" ) ) ;
resultdata . SetValue ( "FEENAME" , feenamearray [ _i ] ) ;
resultdata . SetValue ( "AMOUNT" , amoutarray [ _i ] ) ;
resultdata . SetValue ( "PRICE" , PRICEarray [ _i ] ) ;
resultdata . SetValue ( "RATE" , ratearray [ _i ] ) ;
resultdata . SetValue ( "NUM" , NUMarray [ _i ] ) ;
resultlist . Add ( resultdata ) ;
}
}
else
{
resultlist . Add ( data ) ;
}
}
}
var list_2 = ModelObjectBill . getDicList ( ModelObjectConvert < BaseTableMC > . ToModelObjectList ( resultlist ) ) ;
var json = JsonConvert . Serialize ( new
{
Success = true ,
Message = "查询成功" ,
totalCount = _count ,
data = list_2 . ToList ( )
} ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetP2_CUST ( string condition = " isnull(invoice_no,'')='' " )
{
var canlogin = BasicDataRefDAL . CheckLogin ( Session ) ;
if ( ! canlogin . Success )
{
return ( ContentResult ) canlogin . Data ;
}
var _count = 0 ;
//(string TABLENAME,string _PKEY,string _sql,string DBNAME)
BaseTableMC fromdbbase = new BaseTableMC ( "M_INVOICE" , "INVOICE_ID" , "" , "P2DB" ) ;
var dataList = DBTableConnDAL . getToList ( fromdbbase , "联力P2发票_开票单位" , condition , " select distinct COMPANY_CODE from M_INVOICE " ) ;
var list_2 = ModelObjectBill . getDicList ( ModelObjectConvert < BaseTableMC > . ToModelObjectList ( dataList ) ) ;
var json = JsonConvert . Serialize ( new
{
Success = true ,
Message = "查询成功" ,
totalCount = _count ,
data = list_2 . ToList ( )
} ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetP2_CURRENCY ( string condition = " isnull(invoice_no,'')='' " )
{
var canlogin = BasicDataRefDAL . CheckLogin ( Session ) ;
if ( ! canlogin . Success )
{
return ( ContentResult ) canlogin . Data ;
}
var _count = 0 ;
//(string TABLENAME,string _PKEY,string _sql,string DBNAME)
BaseTableMC fromdbbase = new BaseTableMC ( "M_INVOICE" , "INVOICE_ID" , "" , "P2DB" ) ;
var dataList = DBTableConnDAL . getToList ( fromdbbase , "联力P2发票_币别" , condition , " select distinct CURR_TYPE from M_INVOICE " ) ;
var list_2 = ModelObjectBill . getDicList ( ModelObjectConvert < BaseTableMC > . ToModelObjectList ( dataList ) ) ;
var json = JsonConvert . Serialize ( new
{
Success = true ,
Message = "查询成功" ,
totalCount = _count ,
data = list_2 . ToList ( )
} ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult GetP2_CREATOR ( string condition = " isnull(invoice_no,'')='' " )
{
var canlogin = BasicDataRefDAL . CheckLogin ( Session ) ;
if ( ! canlogin . Success )
{
return ( ContentResult ) canlogin . Data ;
}
var _count = 0 ;
//(string TABLENAME,string _PKEY,string _sql,string DBNAME)
BaseTableMC fromdbbase = new BaseTableMC ( "M_INVOICE" , "INVOICE_ID" , "" , "P2DB" ) ;
var dataList = DBTableConnDAL . getToList ( fromdbbase , "联力P2发票_申请人" , condition , " select distinct CREATE_BY from M_INVOICE " ) ;
var list_2 = ModelObjectBill . getDicList ( ModelObjectConvert < BaseTableMC > . ToModelObjectList ( dataList ) ) ;
var json = JsonConvert . Serialize ( new
{
Success = true ,
Message = "查询成功" ,
totalCount = _count ,
data = list_2 . ToList ( )
} ) ;
return new ContentResult ( ) { Content = json } ;
}
public ContentResult SaveNewP2 ( string opstatus , string data , string GID , string localdata )
{
var headData = JsonConvert . Deserialize < ChInvoice_HangXin > ( data ) ;
var localData = JsonConvert . Deserialize < ChInvoice_HangXin > ( localdata ) ;
BaseTableMC fromdbbase = new BaseTableMC ( "M_INVOICE" , "INVOICE_ID" , "" , "P2DB" ) ;
var P2DataList = DBTableConnDAL . getToList ( fromdbbase , "联力P2发票" , " INVOICE_ID='" + headData . BSNO + "'" ) ;
var bodyList = new List < ChInvoiceDetail > ( ) ;
var SaveBodyList = new List < ChInvoiceDetail > ( ) ;
var P2Data = new BaseTableMC ( ) ;
if ( P2DataList . Count ( ) > 0 )
{
P2Data = P2DataList [ 0 ] ;
}
if ( opstatus = = "add" )
{
//查看是否已被使用 如是则返回错误并结束
var isexists = CheckExists ( " BSNO='" + headData . BSNO + "' " ) ;
if ( ! isexists . Success )
{
return isexists . getContentReult ( ) ;
}
localData . GID = Guid . NewGuid ( ) . ToString ( ) ;
localData . BILLNO = PubSysDAL . GetBillNo ( "0308" ) ;
localData . COMPANYID = Convert . ToString ( Session [ "COMPANYID" ] ) ;
localData . OPERATOR = Convert . ToString ( Session [ "USERID" ] ) ;
localData . OPERATETIME = DateTime . Now ;
localData . DbOperationType = DbOperationType . DbotIns ;
}
else if ( opstatus = = "edit" )
{
//localData = ChinvoiceDAL.GetData(" GID='"+ GID + "' ");
var isexists = CheckExists ( " BSNO='" + headData . BSNO + "' and GID<>'" + GID + "' " ) ;
if ( ! isexists . Success )
{
return isexists . getContentReult ( ) ;
}
localData . DbOperationType = DbOperationType . DbotUpd ;
bodyList = ChinvoiceDAL . GetDetailList ( " PID='" + localData . GID + "' " ) ;
}
localData . SetP2Value ( P2Data ) ;
if ( bodyList . Count > 0 )
{
ChinvoiceDAL . DelInvDetail ( bodyList ) ;
}
SaveBodyList = ChInvoiceDetail . GetP2DetailList ( P2Data , ( localData . PTORRED = = "2" ) ) ;
var BILLNO = localData . BILLNO ;
var modb = new ModelObjectDB ( ) ;
DBResult result = ChinvoiceDAL . SaveInvDetail ( localData . GID , SaveBodyList ) ;
if ( result . Success = = true )
{
result = modb . Save ( localData ) ;
//ChinvoiceDAL.UpdateInvNoUse(headData.INVOICENO, Convert.ToString(Session["USERID"]),headData.BILLNO);
//if (headData.EXCHANGERATE != 0)
//{
// ChinvoiceDAL.updateFeeTax(headData.BILLNO, headData.EXCHANGERATE);
//}
} ;
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = ChinvoiceDAL . GetData ( " BILLNO='" + BILLNO + "'" , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) )
} ;
return jsonRespose . getContentReult ( ) ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
private JsonResponse CheckExists ( string condition )
{
var existsdata = ChinvoiceDAL . GetData ( condition ) ;
JsonResponse result = new JsonResponse ( ) ;
if ( ! string . IsNullOrWhiteSpace ( existsdata . GID ) )
{
result . Success = false ;
result . Message = "该发票已经被使用!" ;
}
else
{
result . Success = true ;
}
return result ;
}
# endregion
}
}