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

3365 lines
113 KiB
C#

This file contains ambiguous Unicode characters!

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

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using HcUtility.Core;
using Newtonsoft.Json;
using DSWeb.TruckMng.Helper;
using Newtonsoft.Json.Converters;
using DSWeb.Areas.Account.Models.Chfee_Invoice;
using NuonuoSDK;
using DSWeb.Areas.Account.Models.Chfee_Invoiceapplication;
using DSWeb.Areas.CommMng.DAL;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.Account.DAL.Chfee_Invoice_HangXin;
using HcUtility.Comm;
using System.Web.Mvc;
using DSWeb.MvcShipping.Models.CodeGoodInv;
using Quartz;
using DSWeb.Areas.MvcShipping.Comm;
using Newtonsoft.Json.Linq;
using DSWeb.Areas.SysMng.Models.DBTableConn;
using DSWeb.Areas.SysMng.DAL.DBTableConn;
using DSWeb.MvcShipping.DAL.MsSysInvInterFaceSet;
using static System.Net.WebRequestMethods;
using sun.security.krb5.@internal.crypto;
using DSWeb.Areas.CommMng.Controllers;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using System.Web;
namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin
{
[JsonObject]
public class ChInvoice_HangXin : Chfee_Invoice.ChInvoice
{
#region 私有成员 在Chfee_Invoice.ChInvoice 基础上增加的字段
private string _CUSTTEL = string.Empty;//购方电话
private string _CUSTADDR = string.Empty;//购方地址
private string _PTORRED = "1"; //开票类型:1,正票;2,红票 80001
private string _REDCODE = string.Empty;//冲红时填写的对应蓝票票代码红票必填不满12位请左补0
private string _REDNUM = string.Empty;//冲红时填写的对应蓝票票号码红票必填不满8位请左补0
private string _PUSHMODE = "-1";//推送方式:-1,不推送;0,邮箱;1,手机(默认);2,邮箱、手机 80002
private string _PUSHMOBILE = string.Empty;//购方手机(开票成功会短信提醒购方,不受推送方式影响)
private string _PUSHEMAIL = string.Empty;//推送邮箱pushMode为0或2时此项为必填
private string _INVOICELINE = "p";
//发票种类:p,普通发票(电票)(默认);c,普通发票(纸票);s,专用发票;e,收购发票(电票);f,收购发票(纸质) 80003
public bool () { return (_INVOICELINE == "bs" || _INVOICELINE == "pc" || _INVOICELINE == "es" || _INVOICELINE == "ec"); }
private string _EINVOICESTATE = string.Empty; //接口开票是否成功。开票成功时记录为true 80004
private string _INVOICEINFOURL = string.Empty; //发票详情地址 一个url 直接显示诺诺开票的发票详情页 开票成功后读取发票详情并记录
private string _INVOICEPDFURL = string.Empty; //发票PDF地址 开票成功后读取发票详情并记录
private string _PTORREDREF = string.Empty; //
private string _PUSHMODEREF = string.Empty;
private string _EINVOICESTATEREF = string.Empty;
private string _INVOICELINEREF = string.Empty;
private string _TAXCODE = string.Empty;
private string _OFFICEPHONE = string.Empty;
private string _ADDRESS = string.Empty;
private string _invoiceSerialNum = string.Empty;//诺诺开票的流水号
private string _INVOICECODE = string.Empty;//发票代码
private string _PAYEE = string.Empty;//收款人
private string _CHECKER = string.Empty;//复核人
private string _SETRED = string.Empty;//是否被冲红
private string _INVITERFACE = string.Empty;//发票接口
#endregion
#region 读写属性
[ModelDB]
public string CUSTTEL
{
get { return _CUSTTEL; }
set { _CUSTTEL = value; }
}
[ModelDB]
public string CUSTADDR
{
get { return _CUSTADDR; }
set { _CUSTADDR = value; }
}
/// <summary>
/// 1正票 2红票
/// </summary>
[ModelDB]
public string PTORRED
{
get { return _PTORRED; }
set { _PTORRED = value; }
}
/// <summary>
/// 被冲红(蓝票)发票代码
/// </summary>
[ModelDB]
public string REDCODE
{
get { return _REDCODE; }
set { _REDCODE = value; }
}
/// <summary>
/// 被冲红(蓝票)发票号码
/// </summary>
[ModelDB]
public string REDNUM
{
get { return _REDNUM; }
set { _REDNUM = value; }
}
/// <summary>
/// -1不推送 0邮箱 1电话 2邮箱+电话
/// </summary>
[ModelDB]
public string PUSHMODE
{
get { return _PUSHMODE; }
set { _PUSHMODE = value; }
}
[ModelDB]
public string PUSHMOBILE
{
get { return _PUSHMOBILE; }
set { _PUSHMOBILE = value; }
}
[ModelDB]
public string PUSHEMAIL
{
get { return _PUSHEMAIL; }
set { _PUSHEMAIL = value; }
}
[ModelDB]
public string INVOICELINE
{
get { return _INVOICELINE; }
set { _INVOICELINE = value; }
}
public bool ISEInvoice
{
get
{
if (INVOICELINE == "p" || INVOICELINE == "e")
return true;
else return false;
}
}
[ModelDB]
public string EINVOICESTATE
{
get { return _EINVOICESTATE; }
set { _EINVOICESTATE = value; }
}
[ModelDB]
public string INVOICEINFOURL
{
get { return _INVOICEINFOURL; }
set { _INVOICEINFOURL = value; }
}
[ModelDB]
public string INVOICEPDFURL
{
get { return _INVOICEPDFURL; }
set { _INVOICEPDFURL = value; }
}
/// <summary>
/// 发票流水号 诺诺平台接收正确的开票信息后返回该值
/// </summary>
[ModelDB]
public string INVOICESERIALNUM
{
get { return _invoiceSerialNum; }
set { _invoiceSerialNum = value; }
}
[ModelDB]
public string INVOICECODE
{
get { return _INVOICECODE; }
set { _INVOICECODE = value; }
}
public string PTORREDREF
{
get { return _PTORREDREF; }
set { _PTORREDREF = value; }
}
public string PUSHMODEREF
{
get { return _PUSHMODEREF; }
set { _PUSHMODEREF = value; }
}
public string INVOICELINEREF
{
get { return _INVOICELINEREF; }
set { _INVOICELINEREF = value; }
}
public string EINVOICESTATEREF
{
get { return _EINVOICESTATEREF; }
set { _EINVOICESTATEREF = value; }
}
/// <summary>
/// 销方税号
/// </summary>
new public string TAXCODE
{
get { return _TAXCODE; }
set { _TAXCODE = value; }
}
public string OFFICEPHONE
{
get { return _OFFICEPHONE; }
set { _OFFICEPHONE = value; }
}
public string ADDRESS
{
get { return _ADDRESS; }
set { _ADDRESS = value; }
}
public string BILLRISES { get; set; }
/// <summary>
/// 收款人
/// </summary>
[ModelDB]
public string PAYEE
{
get { return _PAYEE; }
set { _PAYEE = value; }
}
/// <summary>
/// 复核人
/// </summary>
[ModelDB]
public string CHECKER
{
get { return _CHECKER; }
set { _CHECKER = value; }
}
[ModelDB]
public string SETRED
{
get { return _SETRED; }
set { _SETRED = value; }
}
[ModelDB]
public string INVITERFACE
{
get { return _INVITERFACE; }
set { _INVITERFACE = value; }
}
[ModelDB]
public bool ISFRINV { get; set; }
#endregion
#region 诺诺全电发票增加的字段
/// <summary>
/// 冲红原因1:销货退回;2:开票有误;3:服务中止;4:发生销售折让(开具红票时且票种为 p, c, e, f, r 需要传--成品油发票除外;不传时默认为 1)
/// </summary>
[ModelDB]
public string redReason { get; set; } = "";
/// <summary>
/// 红字信息表编号.专票冲红时此项必填,且必须在备注中注明“开具红字增值税专用发票信息表编号 ZZZZZZZZZZZZZZZZ” 字样
/// ,其 中“Z” 为开具红字增值税专用发票所需要的长度为 16位信息表编号建议 16 位,最长可支持 24 位)。
/// </summary>
[ModelDB]
public string billInfoNo { get; set; } = "";
/// <summary>
/// 红字确认单 uuid
/// </summary>
[ModelDB]
public string billUuid { get; set; } = "";
/// <summary>
/// 购买方经办人姓名(全电发票特有字段)
/// </summary>
[ModelDB]
public string buyerManagerName { get; set; } = "";
/// <summary>
/// 经办人证件类型101-组织机构代码证, 102-营业执照, 103-税务登记证, 199-其他单位证件
/// , 201-居民身份证, 202-军官证, 203-武警警官证, 204-士兵证, 205-军队离退休干部证
/// , 206-残疾人证, 207-残疾军人证1-8 级),208-外国护照, 210-港澳居民来往内地通行证
/// , 212-中华人民共和国往来港澳通行证, 213-台湾居民来往大陆通行证
/// , 214-大陆居民往来台湾通行证, 215-外国人居留证, 216-外交官证 299-其他个人证件(全电发票特有)
/// </summary>
[ModelDB]
public string managerCardType { get; set; } = "";
[ModelDB]
public string managerCardNo { get; set; } = "";
#endregion
public ChInvoice_HangXin()
{
TableName = "ch_fee_invoice";
}
public static decimal getarraysum(string[] feearray)
{
var result = 0M;
for (var _i = 0; _i < feearray.Length; _i++)
{
try
{
result += Convert.ToDecimal(feearray[_i]);
}
catch { }
}
return result;
}
public void SetP2Value(BaseTableMC P2data)
{
var connList = DBTableConnDAL.getConn("联力P2发票");
BSNO = P2data.GetValue("BSNO");
CUSTOMERNAME = P2data.GetValue("CUSTOMERNAME");
INVOICECUSTNAME = P2data.GetValue("INVOICECUSTNAME");
VESSELVOYAGE = P2data.GetValue("VESSEL") + ";" + P2data.GetValue("VOYAGE");
ETD = P2data.GetValue("ETD");
POL = P2data.GetValue("POL");
POD = P2data.GetValue("POD");
RECVCURR = P2data.GetValue("CURRENCY");
CURRENCY = "RMB";
CUSTRATENO = P2data.GetValue("CUSTRATENO");
if (RECVCURR == "RMB")
{
AMOUNT = getarraysum(P2data.GetSplitField("AMOUNT", "\r\n"));
};
if (RECVCURR != "RMB")
{
AMOUNT = 0M;
var pricearray = P2data.GetSplitField("INVAMOUNT", "\r\n");
var numarray = P2data.GetSplitField("NUM", "\r\n");
for (var _i = 0; _i < pricearray.Length; _i++)
{
try
{
AMOUNT += Convert.ToDecimal(pricearray[_i]) * Convert.ToDecimal(numarray[_i]);
}
catch { }
}
}
INVAMOUNT = AMOUNT;
if (RECVCURR != "RMB")
{
OTCURRAMOUNT = getarraysum(P2data.GetSplitField("AMOUNT", "\r\n"));
}
else
{
OTCURRAMOUNT = 0M;
}
AMOUNTCAPITAL = P2data.GetValue("AMOUNTCAPITAL");
REMARK = P2data.GetValue("REMARK");
INVOICETYPE = 2;
OPERATETIME = DateTime.Now;
MBLNO = P2data.GetValue("MBLNO");
CUSTADDRTEL = P2data.GetValue("CUSTADDRTEL");
CUSTBANK = P2data.GetValue("CUSTBANK");
PUSHMODE = "0";
PUSHMOBILE = "0";
PUSHEMAIL = "";
//如果是红票 需要设定一些值
PTORRED = "1";//默认正票
INVOICELINE = "p";//默认普通电票
if (P2data.GetValue("REDINVOICE") == "1")
{
PTORRED = "2";
BaseTableMC fromdbbase = new BaseTableMC("M_INVOICE", "INVOICE_ID", "", "P2DB");
var BeREDDataList = DBTableConnDAL.getToList(fromdbbase, "联力P2发票", " INVOICE_ID='" + P2data.GetValue("REDBSNO") + "'");
if (BeREDDataList.Count > 0)
{
var BeRedinvoice = BeREDDataList[0];
REDNUM = BeRedinvoice.GetValue("INVOICENO");
REDCODE = BeRedinvoice.GetValue("INVOICECODE");
CUSTADDRTEL = BeRedinvoice.GetValue("CUSTADDRTEL");
CUSTBANK = BeRedinvoice.GetValue("CUSTBANK");
CUSTRATENO = BeRedinvoice.GetValue("CUSTRATENO");
}
}
}
}
[JsonObject]
public class HXInvoice
{
public HXInvoice_Head order;
public HXInvoice(ChInvoice_HangXin head, List<ChInvoiceDetail> body)
{
this.order = new HXInvoice_Head(head);
List<HXInvoice_Detail> invoiceDetail = new List<HXInvoice_Detail>();
foreach (var detail in body)
{
var item = new HXInvoice_Detail(detail);
invoiceDetail.Add(item);
}
this.order.invoiceDetail = invoiceDetail;
}
}
[JsonObject]
public class HXInvoice_Head
{
protected ChInvoice_HangXin ChInvoice_HangXin;
public HXInvoice_Head()
{
}
public HXInvoice_Head(ChInvoice_HangXin ChInvoice_HangXin)
{
this.ChInvoice_HangXin = ChInvoice_HangXin;
}
public List<HXInvoice_Detail> invoiceDetail;
#region R&W
public string buyerName
{
get { return ChInvoice_HangXin.INVOICECUSTNAME; }
}
public string buyerTaxNum
{
get { return ChInvoice_HangXin.CUSTRATENO; }
}
public string buyerTel
{
get { return ChInvoice_HangXin.CUSTTEL; }
}
public string buyerAddress
{
get { return ChInvoice_HangXin.CUSTADDR; }
}
public string buyerAccount
{
get { return ChInvoice_HangXin.CUSTBANK; }
}
public string orderNo
{
get { return ChInvoice_HangXin.BILLNO; }
}
public string invoiceDate
{
get { return ChInvoice_HangXin.INVOICEMAKETIME + " 12:00:00"; }
}
/// <summary>
/// 开票员
/// </summary>
public string clerk
{
get { return ChInvoice_HangXin.OPERATORNAME; }
}
public string salerTaxNum
{
get { return ChInvoice_HangXin.TAXCODE; }
}
public string salerTel
{
get { return ChInvoice_HangXin.OFFICEPHONE; }
}
public string salerAddress
{
get { return ChInvoice_HangXin.ADDRESS; }
}
public string salerAccount
{
get { return ChInvoice_HangXin.ACCOUNT; }
}
public string invoiceType
{
get { return ChInvoice_HangXin.PTORRED; }
}
public string remark
{
get { return ChInvoice_HangXin.REMARK; }
}
public string invoiceCode
{
get
{
if (string.IsNullOrWhiteSpace(ChInvoice_HangXin.REDCODE))
{
return "";
}
return ChInvoice_HangXin.REDCODE.Length == 11 ? "0" + ChInvoice_HangXin.REDCODE : ChInvoice_HangXin.REDCODE;
}
}
public string invoiceNum
{
get { return ChInvoice_HangXin.REDNUM; }
}
public string pushMode
{
get { return ChInvoice_HangXin.PUSHMODE; }
}
public string buyerPhone
{
get { return ChInvoice_HangXin.PUSHMOBILE; }
}
public string email
{
get { return ChInvoice_HangXin.PUSHEMAIL; }
}
public string invoiceLine
{
get
{
return ChInvoice_HangXin.INVOICELINE;
}
}
/// <summary>
/// 收款人
/// </summary>
public string payee
{
get
{
return ChInvoice_HangXin.PAYEE;
}
}
public string checker
{
get
{
return ChInvoice_HangXin.CHECKER;
}
}
#endregion
}
//ChInvoiceDetail
[JsonObject]
public class HXInvoice_Detail
{
protected ChInvoiceDetail ChInvoiceDetail;
public HXInvoice_Detail()
{
}
public HXInvoice_Detail(ChInvoiceDetail ChInvoiceDetail)
{
this.ChInvoiceDetail = ChInvoiceDetail;
}
#region R&W
public string goodsName//品名
{
get { return ChInvoiceDetail.GOODSNAMEREF; }
}
public string num//数量
{
get { return Math.Round(ChInvoiceDetail.PKGS, 0, MidpointRounding.AwayFromZero).ToString(); }
}
public string withTaxFlag//单价是否含税0不含1含税 固定为0
{
get { return "0"; }
}
public string price//单价
{
get { return Math.Round(ChInvoiceDetail.PRICE, 2, MidpointRounding.AwayFromZero).ToString(); }
}
public string tax
//税额,[不含税金额] * [税率] = [税额];税额允许误差为 0.06。红票为负。不含税金额、税额、含税金额任何一个不传时,会根据传入的单价,数量进行计算,可能和实际数值存在误差,建议都传入
{
get { return Math.Round(ChInvoiceDetail.TAX, 2, MidpointRounding.AwayFromZero).ToString(); }
}
public string taxIncludedAmount
//"含税金额,[不含税金额] + [税额] = [含税金额],红票为负。不含税金额、税额、含税金额任何一个不传时,会根据传入的单价,数量进行计算,可能和实际数值存在误差,建议都传入"
{
get
{
return (Math.Round(ChInvoiceDetail.AMOUNT, 2, MidpointRounding.AwayFromZero) + Math.Round(ChInvoiceDetail.TAX, 2, MidpointRounding.AwayFromZero)).ToString();
}
}
public string taxExcludedAmount
//不含税金额。红票为负。不含税金额、税额、含税金额任何一个不传时,会根据传入的单价,数量进行计算,可能和实际数值存在误差,建议都传入
{
get { return Math.Round(ChInvoiceDetail.AMOUNT, 2, MidpointRounding.AwayFromZero).ToString(); }
}
public string taxRate
{
get
{
return Math.Round((ChInvoiceDetail.TAXRATE / 100), 2, MidpointRounding.AwayFromZero).ToString();
}
}
public string specType
{
get { return ChInvoiceDetail.SPEC; }
}
public string unit
{
get { return ChInvoiceDetail.UNIT; }
}
public string goodsCode
{
get { return ChInvoiceDetail.GOODCODE; }
}
/// <summary>
///下列三项从相关的code_goods_inv表中查找 优惠政策0不使用1使用
///增值税特殊管理
///零税率标识:空,非零税;1,免税;2,不征税;3,普通零税率
///如无则分别填入 10不使用 2空 3空 非零税率
///
/// 全电票内容来自枚举类型80007
/// 全电发票时: 01简易征收 02稀土产品 03免税 04不征税 05先征后退 06100%先征后退 0750%先征后退
/// 08按 3%简易征收 09按 5%简易征收 10按 5%简易征收减按 1.5%计征 11即征即退 30% 12即征即退 50%
/// 13即征即退 70% 14即征即退 100% 15超税负 3%即征即退 16超税负 8%即征即退
/// 17超税负 12%即征即退 18超税负6%即征即退
/// </summary>
///
public string favouredPolicyFlag
{
get { return ChInvoiceDetail.ISUSEPREF; }
}
public string favouredPolicyName
{
get { return ChInvoiceDetail.DEFREMARK; }
}
public string zeroRateFlag
{
get { return ChInvoiceDetail.ZTAXTYPE; }
}
#endregion
}
[JsonObject]
public class NuoNuoQuanDianInvoice
{
public NuoNuoQuanDian_Head order;
public NuoNuoQuanDianInvoice(ChInvoice_HangXin head, List<ChInvoiceDetail> body)
{
this.order = new NuoNuoQuanDian_Head(head);
List<NuoNuoQuanDian_Detail> invoiceDetail = new List<NuoNuoQuanDian_Detail>();
foreach (var detail in body)
{
var item = new NuoNuoQuanDian_Detail(detail);
invoiceDetail.Add(item);
}
this.order.invoiceDetail = invoiceDetail;
}
}
[JsonObject]
public class NuoNuoQuanDian_Head : HXInvoice_Head
{
public NuoNuoQuanDian_Head()
{
}
public NuoNuoQuanDian_Head(ChInvoice_HangXin _ChInvoice)
{
ChInvoice_HangXin = _ChInvoice;
//需增加
//获取callback地址
}
//public string redReason { get { return ChInvoice_HangXin.redReason; } }
public string billInfoNo { get { return ChInvoice_HangXin.billInfoNo; } }
public string departmentId { get; set; } = "";
public string clerkId { get; set; } = "";
public string listFlag { get; set; } = "0";
public string listName { get; set; } = "";
/// <summary>
/// 全电纸票类型(全电纸票时才需要传):(票种为 ec 时,默认 04票种为 es 时,默认为 1130; 04 2016 版增值税普通发票(二联折叠票)
/// , 05 2016 版增值税普通发票(五联折叠票), 1130增值税专用发票中文三联无金额限制版
/// , 1140 增值税专用发票(中文四联无金额限制版),1160 增值税专用发票(中文六联无金额限制版)
/// , 1170 增值税专用发票(中文七联无金额限制版)
/// </summary>
public string paperInvoiceType
{
get
{
if (ChInvoice_HangXin.INVOICELINE == "ec") return "04";
if (ChInvoice_HangXin.INVOICELINE == "es") return "1130";
return "";
}
}
/// <summary>
/// 特定要素0 普通发票(默认)、 1 成品油 、 3 建筑服务、 4货物运输服务、 31 建安发票、 32 房地产销售发票
/// 目前默认普通发票
/// </summary>
public string specificFactor { get; set; } = "0";
/// <summary>
/// 回传发票信息地址(开票完成、开票失败)
/// 增加系统配置项目 诺诺电票回调地址
/// </summary>
public string callBackUrl { get; set; } = "0";
/// <summary>
/// 分机号(开票终端号,只能 为空或数字)
/// </summary>
public string extensionNumber { get; set; } = "150";
/// <summary>
/// 终端号(开票终端号,只能 为空或数字)
/// </summary>
public string terminalNumber { get; set; } = "";
/// <summary>
/// 机器编号12 位盘号)
/// 增加系统配置项目 税盘盘号
/// </summary>
public string machineCode { get; set; } = "";
/// <summary>
/// 是否机动车类专票 0-否 1-是
/// </summary>
public string vehicleFlag { get; set; } = "0";
/// <summary>
/// 是否隐藏编码表版本号 0-否 1-是(默认 0在企业资质中也配置为是隐藏的时候
/// 并且此字段传 1 的时候代开发票 税率显示***
/// </summary>
public string hiddenBmbbbh { get; set; } = "0";
public string nextInvoiceCode { get; set; } = "";
public string nextInvoiceNum { get; set; } = "";
public string invoiceNumEnd { get; set; } = "";
public string surveyAnswerType { get; set; } = "";
public string buyerManagerName { get { return ChInvoice_HangXin.buyerManagerName; } }
public string managerCardType { get { return ChInvoice_HangXin.managerCardType; } }
public string managerCardNo { get { return ChInvoice_HangXin.managerCardNo; } }
public List<NuoNuoQuanDian_Detail> invoiceDetail;
}
[JsonObject]
public class NuoNuoQuanDian_Detail : HXInvoice_Detail
{
public NuoNuoQuanDian_Detail()
{
}
public NuoNuoQuanDian_Detail(ChInvoiceDetail ChInvoiceDetail)
{
this.ChInvoiceDetail = ChInvoiceDetail;
}
public string goodsCode { get; set; } = "";
public string selfCode { get; set; } = "";
/// <summary>
/// 发票行性质0,正常行;1,折扣行;2,被折扣行,红票只有正常行
/// </summary>
public string invoiceLineProperty { get; set; } = "0";
}
[JsonObject]
public class NuoNuoQuanDian_SetRed : HXInvoice_Head
{
public NuoNuoQuanDian_SetRed()
{
}
public NuoNuoQuanDian_SetRed(ChInvoice_HangXin _ChInvoice)
{
ChInvoice_HangXin = _ChInvoice;
}
public string billInfoNo { get { return ChInvoice_HangXin.billInfoNo; } }
public string deptId { get; set; } = "";
public string departmentId { get; set; } = "";
public string clerkId { get; set; } = "";
public string listFlag { get; set; } = "0";
public string orderTime { get; set; } = "";
public string invoiceId { get { return ChInvoice_HangXin.INVOICESERIALNUM; } }
public string billNo { get; set; } = "";
public string billUuid { get; set; } = "";
public string invoiceLine { get { return ChInvoice_HangXin.INVOICELINE; } }
public string callBackUrl { get; set; } = "";
public string invoiceCode { get { return ChInvoice_HangXin.INVOICECODE; } }
public string invoiceNumber { get { return ChInvoice_HangXin.INVOICENO; } }
public string taxNum { get { return ChInvoice_HangXin.TAXCODE; } }
public string extensionNumber { get; set; } = "150";
}
[JsonObject]
public class NuoNuoQuanDian_RedConfirm //: HXInvoice_Head
{
protected ChInvoice_HangXin ChInvoice_HangXin;
public NuoNuoQuanDian_RedConfirm()
{
}
public NuoNuoQuanDian_RedConfirm(ChInvoice_HangXin _ChInvoice)
{
ChInvoice_HangXin = _ChInvoice;
}
/// <summary>
/// 红字确认单申请号,需要保持唯一,不传的话系统自动生成一个;
/// 此处使用蓝票的billno
/// </summary>
public string billId { get { return ChInvoice_HangXin.BILLNO; } }
/// <summary>
/// 对应蓝票发票种类: bs:电子发票(增值税专用发票) pc:电子发票(普通发票)es:全电纸质发票(增值税专用发票) ec:全电纸质发票(普通发票
/// </summary>
public string blueInvoiceLine { get { return ChInvoice_HangXin.INVOICELINE; } }
/// <summary>
/// 申请方(录入方)身份: 0 销方 1 购方
/// </summary>
public string applySource { get; set; } = "0";
/// <summary>
/// 对应蓝票全电号码(全电普票、全电专票都需要)
/// </summary>
public string blueInvoiceNumber { get { return ChInvoice_HangXin.REDNUM; } }
public string billTime { get; set; }
/// <summary>
/// 销方税号
/// </summary>
public string sellerTaxNo { get { return ChInvoice_HangXin.TAXCODE; } }
/// <summary>
/// 销方名称,申请说明为销方申请时可为空
/// </summary>
public string sellerName { get; set; } = "";
/// <summary>
/// 部门门店 id诺诺网系统中的 id
/// </summary>
public string departmentId { get; set; } = "";
/// <summary>
/// 开票员 id诺诺网系统中的 id
/// </summary>
public string clerkId { get; set; } = "";
/// <summary>
/// 购方税号
/// </summary>
public string buyerTaxNo
{
get { return ChInvoice_HangXin.CUSTRATENO; }
}
///// <summary>
///// 购方名称 父类已有
///// </summary>
public string buyerName
{
get { return ChInvoice_HangXin.INVOICECUSTNAME; }
}
/// <summary>
/// 蓝字发票增值税用途(预留字段可为空): 1 勾选抵扣 2 出口退税 3 代办出口退税 4 不抵扣
/// </summary>
public string vatUsage { get; set; }
/// <summary>
/// 蓝字发票消费税用途(预留字段可为空)
/// </summary>
public string saleTaxUsage { get; set; }
/// <summary>
/// 发票入账状态(预留字段可为空): 0 未入账 1已入账
/// </summary>
public string accountStatus { get; set; }
/// <summary>
/// 冲红原因: 1 销货退回 2 开票有误 3 服务中止 4 销售折让
/// </summary>
public string redReason { get { return ChInvoice_HangXin.redReason; } }
/// <summary>
/// 分机号 150
/// </summary>
public string extensionNumber { get; set; } = "150";
/// <summary>
/// 是否自动开票0 否(不传默认 01 是;传 1时
/// 所申请的确认单变为购销双方已确认或无需确认状态时,
/// 而自动开具红票。目前该字段不生效,电票都自动开,纸票都不自动
/// </summary>
public string autoInvoice { get; set; } = "1";
//若有值,则在无需确认或购销双方已确认后去自动开红票,发票的开票单号用该值
public string orderNo { get { return ChInvoice_HangXin.BILLNO; } }
public string phone
{
get
{
if (ChInvoice_HangXin.PUSHMOBILE == "0") return "";
else
return ChInvoice_HangXin.PUSHMOBILE;
}
}
public string email { get { return ChInvoice_HangXin.PUSHEMAIL; } }
public string callbackUrl { get; set; } = "";
}
/// <summary>
/// 依托ds7系统中保存的红票来读取当时发出的红字发票确认单
/// 由于当时发出的申请单编号是红字发票的BILLNO故可以依据这个进行读取
/// </summary>
[JsonObject]
public class NuoNuoQuanDian_ReadRedConfirm : HXInvoice_Head
{
public NuoNuoQuanDian_ReadRedConfirm()
{
}
public NuoNuoQuanDian_ReadRedConfirm(ChInvoice_HangXin _ChInvoice)
{
ChInvoice_HangXin = _ChInvoice;
}
/// <summary>
/// 操作方身份: 0 销方 1 购方
/// </summary>
public string identity { get; set; } = "0";
/// <summary>
/// 红字确认单状态(不传则查全部状态):
/// 01 无需确认
/// 02销方录入待购方确认 03 购方录入待销方确认
/// 04 购销双方已确认
/// 05 作废(销方录入购方否认)
/// 06 作废(购方录入销方否认) 07 作废(超 72 小时未确认)
/// 08 作废(发起方已撤销) 09 作废(确认后撤销) 15 申请中 16 申请失败
/// </summary>
public string billStatus { get; set; }
/// <summary>
/// 红字确认单申请号 ds7当中红票的billno
/// </summary>
public string billId { get { return ChInvoice_HangXin.BILLNO; } }
/// <summary>
/// 红字确认单编号
/// </summary>
public string billNo { get; set; }
/// <summary>
/// 红字确认单 uuid
/// </summary>
public string billUuid { get; set; }
/// <summary>
/// 填开起始时间,确认单申请号/编号/uuid 有值时,可为空, 允许最大查询范围为 90 天
/// </summary>
public string billTimeStart { get; set; }
/// <summary>
/// 填开结束时间,确认单申请号/编号/uuid 有值时,可为空, 允许最大查询范围为 90 天
/// </summary>
public string billTimeEnd { get; set; }
/// <summary>
/// 每页数量(默认 10最大 50
/// </summary>
public string pageSize { get; set; }
/// <summary>
/// 当前页码(默认 1
/// </summary>
public string pageNo { get; set; }
}
/// <summary>
/// 航信接口token管理
/// </summary>
public class HangXinRequestHelper
{
public Boolean CanUse = true;
public string ERRORMSG = "";
public static List<HangXinRequestHelper> HXTokenHelperList = new List<HangXinRequestHelper>();
/// <summary>
/// 刷新所有需要刷新的token
/// 20191122 准备放弃该算法 改为从接口获取
/// </summary>
//internal static void RefreshTokens()
//{
// //BasicDataRefDAL.SaveLog("RefreshTokens HXTokenHelperList.count="+ HXTokenHelperList.Count.ToString(), "诺诺平台", "刷新token", "方法被调用2");
// //if (HXTokenHelperList.Count == 0) {
// ReadToken();
// //}
// if (HXTokenHelperList == null) return;
// foreach (var hx in HXTokenHelperList) {
// hx.ResetToken();
// }
// //throw new NotImplementedException();
//}
//public static void clear(string accessToken) {
// if (HXTokenHelperList == null) return;
// foreach (var hx in HXTokenHelperList)
// {
// if (hx.accessToken == accessToken)
// hx.accessToken = "";
// }
//}
#region 基础属性
/// <summary>
/// 我公司的appKey和密码 不写入数据库 只存在程序内
/// </summary>
///
/* 沙盒测试账户 需使用青岛鑫鹏威
* 339901999999142 Abcd1234
public static string appKey { get { return "SD23646802"; } }
public static string appSecret { get { return "SDFAFF5B0AED4465"; } }
*/
/* 正式地址测试账户 纸票测试用 需使用深圳鑫鹏威
//339901999999516
public static string appKey { get { return "G6bvh0ke"; } }
public static string appSecret { get { return "6850C5AED14E4177"; } }
*/
/* 正式地址 大简云*/
public string appKey { get; set; } = "23646802";
public string appSecret { get; set; } = "CBFAFF5B0AED4465";
/// <summary>
/// 使用沙盒地址还是实际工作地址
/// </summary>
public static string URL
{
get
{
//return sandboxUrl; //沙盒测试地址
return normalUrl;
}
}
/// <summary>
/// 商户模式的Token
/// </summary>
public string MerchantToken { get; set; }
/// <summary>
/// 在服务商模式当中,客户输入选定账户的认证信息后返回的一个随机码
/// 每次认证时会被更新。但执行getISVToken或refreshISVToken不会改变code
/// </summary>
public string code { get; set; }
/// <summary>
/// 税号 客户输入的选定账户
/// </summary>
public string taxnum { get; set; }
/// <summary>
/// 接收诺诺平台返回值的url需要在其中标好账户id以对应正确的实例化helper对象
/// </summary>
public static string redirectUri { get; set; }
//private static string ISVToken { get; set; }
/// <summary>
/// getISVToken时返回 refreshToken 时不变
/// </summary>
public string accessToken { get; set; }
/// <summary>
/// getISVToken时返回 refreshToken时改变
/// </summary>
public string refreshToken { get; set; }
/// <summary>
/// 同一客户税号这个userid似乎不变
/// </summary>
public string userId { get; set; }
/// <summary>
/// 如果此次返回内容有错误编号 则返回错误
/// </summary>
public bool refstateTrue
{
get
{
if (!string.IsNullOrEmpty(error)) { return false; }
else return true;
}
}
public string error_description { get; set; }
public string error { get; set; }
private static string sandboxUrl = "https://sandbox.nuonuocs.cn/open/v1/services";
private static string normalUrl = "https://sdk.nuonuo.com/open/v1/services";
//爬虫服务器接口
private static string _IURL = "http://47.104.90.170:5200/fp/token/";
//private static string _IURL = "http://118.190.106.151:5200/fp/token/";
//沙盒爬虫
private static string _SandBoxURL = "http://47.104.90.170:5200/cs/token/";
//private static string _SandBoxURL = "http://118.190.106.151:5200/cs/token/";
private static string _url { get; set; }
const string ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
public static string returnStr { get; set; }
protected static string getSendid()
{
return Guid.NewGuid().ToString().Replace("-", "").Substring(0, 32); // 唯一标识由企业自己生成32位随机码
}
private DateTime _tokenstarttime { get; set; }
//public DateTime gettokenstarttime { get { return _tokenstarttime; } }
public DateTime tokenstarttime { get { return _tokenstarttime; } set { _tokenstarttime = value; } }
public DateTime tokenneedresettime { get { return _tokenstarttime.AddHours(23); } }
/// <summary>
/// 需要初始化。如果有用户认证的code则返回true否则需要前台弹出StartUrl窗口录入认证信息
/// 20191122 改为接口维护token后 固定返回false
/// </summary>
public bool needStart
{
get
{
//if (string.IsNullOrEmpty(code))
//{
// return true;
//}
//else if (System.DateTime.Now > _tokenstarttime.AddHours(24))
//{
// return true;
//}
if (accessToken == "") return true;
else
return false;
}
}
/// <summary>
/// 需要刷新 即当前时间晚于上次刷新23小时
/// /// 20191122 改为接口维护token后 固定返回false
/// </summary>
public bool needresettoken
{
get
{
//if (System.DateTime.Now >= tokenneedresettime)
//{
// return true;
//}
return false;
}
}
/// <summary>
/// 具备刷新条件 即token不为空
/// </summary>
//public bool canresettoken
//{
// get
// {
// if (!string.IsNullOrEmpty(refreshToken))
// return true;
// else return false;
// }
//}
#endregion
//public bool ResetToken()
//{
// //BasicDataRefDAL.SaveLog("tokenstarttime="+ tokenstarttime.ToString("yyyy-MM-dd HH:mm:ss")+ ";refreshToken=" + refreshToken + ";accessToken=" + accessToken + ";needresettoken=" + needresettoken.ToString() + ";canresettoken=" + canresettoken.ToString(), "诺诺平台", "刷新令牌", "判断");
// if (needresettoken && canresettoken)
// {
// refreshISVToken();
// return !needresettoken;
// }
// else return false;
//}
/// <summary>
/// 商户获取访问令牌
/// </summary>
/// <returns></returns>
//public string getMerchantToken()
//{
// //BasicDataRefDAL.SaveLog("appKey="+appKey+ ";appSecret=" + appSecret, "诺诺平台", "商户获取访问令牌", "发送值");
// var result = NNOpenSDK.getMerchantToken(appKey, appSecret);
// dealResponse_token(returnStr);
// //DoSaveToken();
// BasicDataRefDAL.SaveLog(result, "诺诺平台", "商户获取访问令牌", "返回值");
// return result;
//}
//public string setMerchantToken()
//{
// this.MerchantToken = getMerchantToken();
// return this.MerchantToken;
//}
/// <summary>
/// ISV获取访问令牌
/// </summary>
/// <returns></returns>
//private ISVTokenmb getISVToken()
//{
// ISVTokenmb _ISVToken = new ISVTokenmb();
// //BasicDataRefDAL.SaveLog("appKey=" + appKey + ";appSecret=" + appSecret + ";code=" + code + ";taxnum=" + taxnum + ";redirectUri=" + redirectUri, "诺诺平台", "ISV获取访问令牌", "发送值");
// returnStr = NNOpenSDK.getISVToken(appKey, appSecret, code, taxnum, redirectUri);
// BasicDataRefDAL.SaveLog(returnStr, "诺诺平台", "ISV获取访问令牌", "返回值");
// dealResponse_token(returnStr);
// return _ISVToken;
//}
/// <summary>
/// 用认证窗口返回的数据读取token
/// </summary>
/// <returns></returns>
//public string setISVToken()
//{
// //此处应判断
// //1 token 是否已存在 如不存在则获取needStart
// //如存在则判断更新时间needresettoken
// //if (needStart || needresettoken)
// //{
// var _ISVToken = getISVToken();
// return returnStr;
// //}
// //else return "no need to start Token";
// /*"{\"access_token\":\"98600c833f178852e2f4d51cexk9yegi\",\"refresh_token\":\"faf038898dec26eac62640aaed0506cb\",\"oauthUser\":\"{\\\"userName\\\":\\\"339901999999142\\\",\\\"registerType\\\":\\\"1\\\"}\",\"expires_in\":86356,\"userId\":\"d1aa0da6bc9840ae83c1120cecd057ac\"}"*/
// /*{"error_description":"The code is used a second time, please authorization again","error":"070317"}*/
// /*{"error_description":"Incorrect parameter or Authorization out of date","error":"070313"}*/
//}
/// <summary>
/// ISV获取刷新令牌 强制执行
/// </summary>
/// <returns></returns>
//public string refreshISVToken()
//{
// try
// {
// BasicDataRefDAL.SaveLog("refreshToken=" + refreshToken + ";userId=" + userId + ";appSecret=" + appSecret , "诺诺平台", "ISV获取刷新令牌", "发送值");
// returnStr = NNOpenSDK.refreshISVToken(refreshToken, userId, appSecret);
// BasicDataRefDAL.SaveLog(returnStr, "诺诺平台", "ISV获取刷新令牌", "返回值");
// dealRefresh_token(returnStr);
// return returnStr;
// }
// catch {
// return "";
// }
//}
/// <summary>
/// ISV获取刷新令牌 如非必要则不执行
/// </summary>
/// <returns></returns>
//public string setrefreshISVToken()
//{
// if (needStart)
// {
// return "need to start,can not refresh";
// }
// if (needresettoken)
// {
// return (refreshISVToken());
// }
// else return "no need to refresh";
//}
public HangXinRequestHelper()
{
tokenstarttime = Convert.ToDateTime("1900-01-01");
}
public HangXinRequestHelper(string taxnum)
{
this.taxnum = taxnum;
if (HXTokenHelperList == null) HXTokenHelperList = new List<HangXinRequestHelper>();
HXTokenHelperList.Add(this);
}
public HangXinRequestHelper(string taxnum, string accessToken)
{
this.taxnum = taxnum;
this.accessToken = accessToken;
if (HXTokenHelperList == null) HXTokenHelperList = new List<HangXinRequestHelper>();
var curr = HXTokenHelperList.Find(o => o.taxnum == taxnum);
if (!(curr == null))
{
curr.accessToken = accessToken;
}
else
{
HXTokenHelperList.Add(this);
}
}
/// <summary>
/// 处理 获取令牌/刷新令牌 命令的返回值
/// </summary>
/// <param name="response"></param>
//private void dealResponse_token(string response) {
// var _ISVToken = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<ISVTokenmb>(response);
// error = _ISVToken.error;
// if (string.IsNullOrEmpty(error))
// {
// accessToken = _ISVToken.access_token;
// refreshToken = _ISVToken.refresh_token;
// userId = _ISVToken.userId;
// var userinfo = _ISVToken._oauthUser;
// taxnum = userinfo.userName;
// tokenstarttime = System.DateTime.Now;
// var i = BasicDataRefDAL.ExecSql(getUpdStr());
// if (i == 0)
// {
// try
// {
// i = BasicDataRefDAL.ExecSql(getInsertStr());
// BasicDataRefDAL.SaveLog(getInsertStr(), "诺诺平台", "保存Token", "Insert");
// }
// catch { }
// }
// else
// {
// BasicDataRefDAL.SaveLog(getUpdStr(), "诺诺平台", "保存Token", "Update");
// }
// }
// else
// {
// error_description = _ISVToken.error_description;
// }
//}
//private void dealRefresh_token(string response) {
// var _ISVToken = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<Refreshtokenmb>(response);
// error = _ISVToken.error;
// if (string.IsNullOrEmpty(error))
// {
// accessToken = _ISVToken.access_token;
// refreshToken = _ISVToken.refresh_token;
// var i = BasicDataRefDAL.ExecSql(getUpdStr());
// BasicDataRefDAL.SaveLog(getUpdStr(), "诺诺平台", "保存Token", "refresh Update");
// }
// else
// {
// error_description = _ISVToken.error_description;
// }
//}
public static HangXinRequestHelper getHelper(string taxnum)
{
//ReadToken();
//foreach (var h in HXTokenHelperList)
//{
// if (h.taxnum == taxnum)
// {
// return h;
// }
//}
//var result = new HangXinRequestHelper(taxnum);
//return result;
var _token = getPortToken(taxnum);
return _token;
}
protected static HangXinRequestHelper getPortToken(string taxnum)
{
try
{
///读取接口token
//JObject reqObj = new JObject();
//reqObj.Add("taxnum", taxnum);
var dic = new Dictionary<string, string>();
dic.Add("taxnum", taxnum);
var rtn = WebRequestHelper.DoPost(_IURL, dic, 10000);
//var rtn = WebRequestHelper.DoPost(_SandBoxURL, dic, 20000);
//RepCZModel CZM = Newtonsoft.Json.JsonConvert.DeserializeObject<RepCZModel>(rtn);
PortTokenmb pt = Newtonsoft.Json.JsonConvert.DeserializeObject<PortTokenmb>(rtn);
if (pt.status == "1")
{
foreach (var hx in HXTokenHelperList)
{
if (hx.taxnum == taxnum)
{
hx.accessToken = pt.message;
hx.CanUse = true;
hx.ERRORMSG = "";
return hx;
}
}
var result = new HangXinRequestHelper(taxnum, pt.message);
return result;
}
else
return new HangXinRequestHelper(taxnum, "");
}
catch (Exception e)
{
var result = new HangXinRequestHelper(taxnum, "");
result.CanUse = false;
result.ERRORMSG = "没有取得开票密钥:" + e.Message;
return result;
}
}
protected static HangXinRequestHelper getPortToken_(string taxnum,string CORPID)
{
try
{
var result = new HangXinRequestHelper();
var INVITERFACE = MsSysInvInterFaceSetDAL.GetData("INVITERFACE='诺诺全电发票'", "");
if (string.IsNullOrWhiteSpace(INVITERFACE.NUONUOAPPKEY))
{
return result;
}
else
{
result.appKey = INVITERFACE.NUONUOAPPKEY;
result.appSecret = INVITERFACE.NUONUOAPPSECRET;
}
var dic = new Dictionary<string, string>
{
{ "taxnum", taxnum },
{ "client_id", result.appKey },
{ "client_secret", result.appSecret }
};
var porturl = "http://47.104.90.170:5200/fp/free_type/";
var rtn = WebRequestHelper.DoPost(porturl, dic, 10000);
//var rtn = WebRequestHelper.DoPost(_SandBoxURL, dic, 20000);
//RepCZModel CZM = Newtonsoft.Json.JsonConvert.DeserializeObject<RepCZModel>(rtn);
PortTokenmb pt = Newtonsoft.Json.JsonConvert.DeserializeObject<PortTokenmb>(rtn);
if (pt.status == "1")
{
//foreach (var hx in HXTokenHelperList)
//{
// if (hx.taxnum == taxnum)
// {
// hx.accessToken = pt.message;
// hx.CanUse = true;
// hx.ERRORMSG = "";
// return hx;
// }
//}
result.accessToken = pt.message;
return result;
}
else
return new HangXinRequestHelper(taxnum, "");
}
catch (Exception e)
{
var result = new HangXinRequestHelper(taxnum);
result.CanUse = false;
result.ERRORMSG = "没有取得开票密钥:" + e.Message;
return result;
}
}
/// <summary>
/// 开出发票
/// </summary>
/// <param name="head"></param>
/// <param name="detailList"></param>
/// <returns></returns>
public DBResult PostInvoice(ChInvoice_HangXin head, List<ChInvoiceDetail> detailList)
{
var billno = head.BILLNO;
//20191028 如果该发票的状态为开票失败 则将其billno临时变更为billno+时分秒以避开诺诺平台的orderNo不能重复的逻辑
//然后处理返回值时将新的流水号写回。
//20191108
//if (head.EINVOICESTATE == "3"|| head.EINVOICESTATE == "0")
//{
// head.BILLNO= billno+ DateTime.Now.ToString("HHmmss");
//}
var _head = new HXInvoice(head, detailList);
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(_head);
var _r = "";
_r = PostInvoice(json);
var _return = dealresponse_KP(_r);
if (_return.code == "E0000")
{
//开票提交成功
var invoiceSerialNum = _return.result.invoiceSerialNum;
//立即调用读取发票信息的方法 将返回值设置进head 并保存
head.INVOICESERIALNUM = invoiceSerialNum;
head.BILLNO = billno;
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
var modb = new ModelObjectDB();
var result = modb.Save(head);
result = ReadInvoice(head);
//var returndate = ChinvoiceDAL.GetDataList(0, 1, "cm.INVOICESERIALNUM='" + head.INVOICESERIALNUM + "'", head.OPERATOR);
//result.Data = returndate;
return result;
}
else if (_return.code == "070101" || _return.code == "070301")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要重新认证", null);
return result;
}
else if (_return.code == "E9106")
{
//E9106 订单编号不能重复
//同billno重复发送 执行一次用订单号读取
return ReadInvoice_BILLNO(head);
}
else
{
var reault = new DBResult(false, _return.message, head);
return reault;
}
}
public string PostInvoice(string json)
{
string method = "nuonuo.electronInvoice.requestBilling";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "发票开出", "发送值");
string result = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(result, "诺诺平台", "发票开出", "返回值");
return result;
}
public DBResult ReadInvoice(string INVOICESERIALNUM, string USERID)
{
var head = ChinvoiceDAL.GetData("cm.INVOICESERIALNUM='" + INVOICESERIALNUM + "'");
var _r = ReadInvoice(head);
return _r;
}
public DBResult ReadInvoice(ChInvoice_HangXin head)
{
if (string.IsNullOrEmpty(head.INVOICESERIALNUM))
{
var result = new DBResult { Success = false, Message = "还未成功进行平台开票,无可读数据", Data = "" };
return result;
}
string method = "nuonuo.electronInvoice.CheckEInvoice";
var json = "{" + "\"invoiceSerialNum\":[\"" + head.INVOICESERIALNUM + "\"]" + "}";
if (string.IsNullOrWhiteSpace(head.INVOICESERIALNUM))
{
//如果流水号为空 则改为按业务编号读取
method = "nuonuo.electronInvoice.querySerialNum";
json = "{" + "\"orderNo\":[\"" + head.BILLNO + "\"]" + "}";
}
//读取业务
//string method = "nuonuo.electronInvoice.querySerialNum";
//var json = "{" + "\"orderNo\":[\"" + head.BILLNO + "\"]" + "}";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "读取发票信息", "发送值");
string _r = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(_r, "诺诺平台", "读取发票信息", "返回值");
var _return = dealresponse_Read(_r);
if (_return.code == "070101" || _return.code == "070301")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要重新认证", null);
return result;
}
if (_return.code == "070302")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要联系诺诺平台开通相关权限", null);
return result;
}
if (_return.code == "E0000")
{
//开票信息读取成功
var returndate = ChinvoiceDAL.GetData("cm.INVOICESERIALNUM='" + head.INVOICESERIALNUM + "'");
head = returndate;
//var invoiceSerialNum = _return.result[0].invoiceSerialNum;
var info = _return.result[0];
//立即调用读取发票信息的方法 将返回值设置进head 并保存
//head.INVOICESERIALNUM = invoiceSerialNum;
head.INVOICECODE = info.invoiceCode;
head.INVOICENO = info.invoiceNum;
head.EINVOICESTATE = info.status;
head.INVOICEINFOURL = info.invoiceImageUrl;
head.INVOICEPDFURL = info.invoiceFileUrl;
head.INVOICEMAKETIME = info.invoiceDate;
//if (!string.IsNullOrWhiteSpace(info.invoiceSerialNum))
//{
// head.INVOICESERIALNUM = info.invoiceSerialNum;
//}
//head.REMARK = head.REMARK.Replace(info.remark,"")+ info.remark;
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
var modb = new ModelObjectDB();
var result = modb.Save(head);
result.Message = info.resultMsg;
if (info.resultMsg.Contains("开具结果:0,开具失败原因:开票异常"))
{
result.Message = "开票异常,请尝试重新连接税控盘、重新启动税控软件和诺诺客户端,然后再次读取发票信息;如仍显示此提示,请联系诺诺平台客服人员,并提供销方税号和此发票的流水号";
}
return result;
}
else
{
var msg = _return.code + ":" + _return.describe;
var result = new DBResult { Success = false, Message = DSWeb.TruckMng.Helper.JsonConvert.Serialize(msg), Data = "" };
return result;
}
}
public DBResult ReadInvoice_BILLNO(ChInvoice_HangXin head)
{
//读取业务
string method = "nuonuo.electronInvoice.querySerialNum";
var json = "{" + "\"orderNo\":[\"" + head.BILLNO + "\"]" + "}";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "读取发票信息", "发送值");
string _r = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(_r, "诺诺平台", "读取发票信息", "返回值");
var _return = dealresponse_Read(_r);
if (_return.code == "070101" || _return.code == "070301")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要重新认证", null);
return result;
}
if (_return.code == "070302")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要联系诺诺平台开通相关权限", null);
return result;
}
if (_return.code == "E0000")
{
//开票信息读取成功
var returndate = ChinvoiceDAL.GetData("cm.INVOICESERIALNUM='" + head.INVOICESERIALNUM + "'");
head = returndate;
//var invoiceSerialNum = _return.result[0].invoiceSerialNum;
var info = _return.result[0];
//立即调用读取发票信息的方法 将返回值设置进head 并保存
//head.INVOICESERIALNUM = invoiceSerialNum;
head.INVOICECODE = info.invoiceCode;
head.INVOICENO = info.invoiceNum;
head.EINVOICESTATE = info.status;
head.INVOICEINFOURL = info.invoiceImageUrl;
head.INVOICEPDFURL = info.invoiceFileUrl;
head.INVOICEMAKETIME = info.invoiceDate;
if (!string.IsNullOrWhiteSpace(info.invoiceSerialNum))
{
head.INVOICESERIALNUM = info.invoiceSerialNum;
}
//head.REMARK = head.REMARK.Replace(info.remark,"")+ info.remark;
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
var modb = new ModelObjectDB();
var result = modb.Save(head);
result.Message = info.resultMsg;
if (info.resultMsg.Contains("开具结果:0,开具失败原因:开票异常"))
{
result.Message = "开票异常,请尝试重新连接税控盘、重新启动税控软件和诺诺客户端,然后再次读取发票信息;如仍显示此提示,请联系诺诺平台客服人员,并提供销方税号和此发票的流水号";
}
return result;
}
else
{
var msg = _return.code + ":" + _return.describe;
var result = new DBResult { Success = false, Message = DSWeb.TruckMng.Helper.JsonConvert.Serialize(msg), Data = "" };
return result;
}
}
public DBResult VoidInvoice(ChInvoice_HangXin head)
{
if (string.IsNullOrEmpty(head.INVOICESERIALNUM))
{
var result = new DBResult { Success = false, Message = "还未成功进行平台开票,不需要执行作废", Data = "" };
return result;
}
//作废接口
string method = "nuonuo.electronInvoice.invoiceCancellation";
// String content = "{" +
//"\"invoiceId\":\"19051413444101000011\"," +
//"\"invoiceCode\":\"033001800211\"," +
//"\"invoiceNo\":\"07912653\"" +
//"}";
var json = "{" +
"\"invoiceId\":\"" + head.INVOICESERIALNUM + "\"," +
"\"invoiceCode\":\"" + head.INVOICECODE + "\"," +
"\"invoiceNo\":\"" + head.INVOICENO + "\"" +
"}";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "发票作废", "发送值");
string _r = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(_r, "诺诺平台", "发票作废", "返回值");
var _return = dealresponse_KP(_r);
if (_return.code == "E0000")
{
//作废请求成功
var invoiceSerialNum = _return.result.invoiceId;
head.INVOICESERIALNUM = invoiceSerialNum;
head.ISDELETE = "true";
var result = ReadInvoice(head);
//var result = new DBResult { Success = true, Message = _return.code + ":" + _return.describe, Data = head };
return result;
}
else
{
var msg = _return.code + _return.status + ":" + _return.describe + _return.msg;
var result = new DBResult { Success = false, Message = DSWeb.TruckMng.Helper.JsonConvert.Serialize(msg), Data = "" };
return result;
}
}
/// <summary>
/// 处理开票命令返回值
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
private KPResponse dealresponse_KP(string json)
{
var result = new KPResponse();
result = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<KPResponse>(json.Trim('"'));
return result;
}
/// <summary>
/// 处理 读取发票信息命令
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
private ReadResponse dealresponse_Read(string json)
{
var result = new ReadResponse();
result = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<ReadResponse>(json.Trim('"'));
return result;
}
/// <summary>
/// 执行save操作
/// </summary>
//private void DoSaveToken()
//{
// if (HXTokenHelperList==null ||HXTokenHelperList.Count == 0) return;
// SaveToken();
//}
/// <summary>
/// 将数据库内记录的token信息读入static列表
/// </summary>
private static void ReadToken()
{
//BasicDataRefDAL.SaveLog(" SELECT * from Invoice_HangXinToken ", "诺诺平台", "读取数据库token", "读取数据库token");
/* 20191210 废弃
var strSql = " SELECT * from Invoice_HangXinToken ";
Database db = DatabaseFactory.CreateDatabase();
bool neednew = false;
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
neednew = true;
if (HXTokenHelperList == null) HXTokenHelperList = new List<HangXinRequestHelper>();
foreach (var hx in HXTokenHelperList)
{
//BasicDataRefDAL.SaveLog(" 循环税号token:" + hx.taxnum+";reader税号:"+ Convert.ToString(reader["TAXNUM"]), "诺诺平台", "读取数据库token", "读取数据库token");
if (hx.taxnum == Convert.ToString(reader["TAXNUM"]))
{
//BasicDataRefDAL.SaveLog(" 刷新税号token:"+ hx.taxnum, "诺诺平台", "读取数据库token", "读取数据库token");
hx.code = Convert.ToString(reader["CODE"]);
hx.userId = Convert.ToString(reader["USERID"]);
hx.accessToken = Convert.ToString(reader["ACCESSTOKEN"]);
hx.refreshToken = Convert.ToString(reader["REFRESHTOKEN"]);
if (reader["STARTTIME"] != DBNull.Value)
hx.tokenstarttime = Convert.ToDateTime(reader["STARTTIME"]);
//if (reader["SAVETIME"] != DBNull.Value)
// hx = Convert.ToString(reader["SAVETIME"]);
hx.error = Convert.ToString(reader["ERROR"]);
hx.error_description = Convert.ToString(reader["ERROR_DESCRIPTION"]);
neednew = false;
break;
}
}
if (neednew)
{
var hx = new HangXinRequestHelper(Convert.ToString(reader["TAXNUM"]));
//BasicDataRefDAL.SaveLog(" 增加税号token:" + hx.taxnum, "诺诺平台", "读取数据库token", "读取数据库token");
hx.code = Convert.ToString(reader["CODE"]);
hx.userId = Convert.ToString(reader["USERID"]);
hx.accessToken = Convert.ToString(reader["ACCESSTOKEN"]);
hx.refreshToken = Convert.ToString(reader["REFRESHTOKEN"]);
if (reader["STARTTIME"] != DBNull.Value)
hx.tokenstarttime = Convert.ToDateTime(reader["STARTTIME"]);
//if (reader["SAVETIME"] != DBNull.Value)
// hx = Convert.ToString(reader["SAVETIME"]);
hx.error = Convert.ToString(reader["ERROR"]);
hx.error_description = Convert.ToString(reader["ERROR_DESCRIPTION"]);
}
//BasicDataRefDAL.SaveLog(HangXinRequestHelper.HXTokenHelperList.Count.ToString(), "诺诺平台", "Token实体类总数", "读取数据库token");
}
}
*/
}
/// <summary>
/// 保存token信息当获取和刷新时执行一次
/// </summary>
/// <param name="hx"></param>
/// <returns></returns>
//private bool SaveToken() {
// bool result = false;
// var i = BasicDataRefDAL.ExecSql(getUpdStr());
// if (i == 0) {
// try
// {
// i = BasicDataRefDAL.ExecSql(getInsertStr());
// BasicDataRefDAL.SaveLog(getInsertStr(), "诺诺平台", "保存Token", "SaveToken");
// }
// catch { }
// }
// else {
// BasicDataRefDAL.SaveLog(getUpdStr(), "诺诺平台", "保存Token", "SaveToken");
// }
// if (i > 0) result = true;
// return result;
//}
/// <summary>
/// 获取插入数据库所需的语句
/// Invoice_HangXinToken
/// TAXNUM,CODE,USERID,ACCESSTOKEN,REFRESHTOKEN,STARTTIME,SAVETIME,ERROR,ERROR_DESCRIPTION
/// </summary>
/// <returns></returns>
private string getInsertStr()
{
var result = string.Format(" insert into Invoice_HangXinToken values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", taxnum, code, userId, accessToken, refreshToken, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), error, error_description);
return result;
}
private string getUpdStr()
{
var result = string.Format(" update Invoice_HangXinToken set CODE='{1}',USERID='{2}',ACCESSTOKEN='{3}',REFRESHTOKEN='{4}',STARTTIME='{5}',SAVETIME='{6}',ERROR='{7}',ERROR_DESCRIPTION='{8}' where TAXNUM='{0}'", taxnum, code, userId, accessToken, refreshToken, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), error, error_description);
return result;
}
}
public class : HangXinRequestHelper
{
public static getHelper(string taxnum,string CORPID)
{
var _token = getPortToken_(taxnum,CORPID);
result = new ();
result.appKey = _token.appKey;
result.appSecret = _token.appSecret;
result.accessToken = _token.accessToken;
result.taxnum = taxnum;
return result;
}
//接口函数的地址不同
public DBResult ReadInvoice(ChInvoice_HangXin head)
{
if (string.IsNullOrEmpty(head.INVOICESERIALNUM) && !head.())
{
var result = new DBResult { Success = false, Message = "还未成功进行平台开票,无可读数据", Data = "" };
return result;
}
string method = "nuonuo.OpeMplatform.queryInvoiceResult";
var json = "{" + "\"serialNos\":[\"" + head.INVOICESERIALNUM + "\"]," + "\"orderNo\":[]," + "\"isOfferInvoiceDetail\":0 }";
if (string.IsNullOrWhiteSpace(head.INVOICESERIALNUM))
{
//如果流水号为空 则改为按业务编号读取
method = "nuonuo.OpeMplatform.queryInvoiceResult";
json = "{" + "\"orderNos\":[\"" + head.BILLNO + "\"]," + "\"serialNos\":[]," + "\"isOfferInvoiceDetail\":0 }";
}
//读取业务
//string method = "nuonuo.electronInvoice.querySerialNum";
//var json = "{" + "\"orderNo\":[\"" + head.BILLNO + "\"]" + "}";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "读取发票信息", "发送值");
string _r = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(_r, "诺诺平台", "读取发票信息", "返回值");
var _return = dealresponse_Read(_r);
if (_return.code == "070101" || _return.code == "070301")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要重新认证", null);
return result;
}
if (_return.code == "070302")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要联系诺诺平台开通相关权限", null);
return result;
}
if (_return.code == "E0000")
{
//开票信息读取成功
var returndate = new ChInvoice_HangXin();
if (!head.())
{
returndate = ChinvoiceDAL.GetData("cm.INVOICESERIALNUM='" + head.INVOICESERIALNUM + "'");
}
if (head.())
{
returndate = ChinvoiceDAL.GetData("cm.BILLNO='" + head.BILLNO + "'");
}
head = returndate;
//var invoiceSerialNum = _return.result[0].invoiceSerialNum;
var info = _return.result[0];
//立即调用读取发票信息的方法 将返回值设置进head 并保存
//head.INVOICESERIALNUM = invoiceSerialNum;
head.INVOICECODE = info.invoiceCode;
head.INVOICENO = info.invoiceNo;
head.EINVOICESTATE = info.status;
head.INVOICEINFOURL = info.pdfUrl;
head.INVOICEPDFURL = info.pdfUrl;
head.INVOICEMAKETIME = BasicDataRefDAL.Timestamp2Datetime(info.invoiceTime).ToString("yyyy-MM-dd HH:mm:ss");
//if (!string.IsNullOrWhiteSpace(info.invoiceSerialNum))
//{
// head.INVOICESERIALNUM = info.invoiceSerialNum;
//}
//head.REMARK = head.REMARK.Replace(info.remark,"")+ info.remark;
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
head.INVOICEMAKETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var modb = new ModelObjectDB();
var result = modb.Save(head);
if (!result.Success)
return result;
result.Message = info.statusMsg;
if (result.Message.IndexOf("失败") >= 0)
{
result.Success = false;
result.Message += ":" + info.failCause;
//此处调用一次重推
var hx = getHelper(head.TAXCODE,head.COMPANYID);
hx.(head);
}
else
{
result.Message += ":" + info.failCause;
}
result.Data = head;
return result;
}
else
{
var failCause = "";
try
{
var info = _return.result[0];
failCause = "[" + info.failCause + "]";
}
catch
{
}
var msg = _return.code + ":" + _return.describe + failCause;
var result = new DBResult { Success = false, Message = DSWeb.TruckMng.Helper.JsonConvert.Serialize(msg), Data = "" };
return result;
}
}
public DBResult (ChInvoice_HangXin head)
{
var result = new DBResult();
if (string.IsNullOrEmpty(head.INVOICESERIALNUM))
{
result = new DBResult { Success = false, Message = "还未成功进行平台开票,无重试数据", Data = "" };
return result;
}
var senid = Guid.NewGuid().ToString();
string method = "nuonuo.OpeMplatform.reInvoice";
var content = new
{
fpqqlsh = head.INVOICESERIALNUM,
orderno = head.BILLNO,
nextInvoiceCode = "",
invoiceNumStart = "",
invoiceNumEnd = ""
};
var json = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(content);
//"{" + "\"fpqqlsh\":\"" + head.INVOICESERIALNUM + "\"," + "\"orderNo\":[]," + "\"isOfferInvoiceDetail\":0 }";
//读取业务
//string method = "nuonuo.electronInvoice.querySerialNum";
//var json = "{" + "\"orderNo\":[\"" + head.BILLNO + "\"]" + "}";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "重推发票信息", "发送值");
string _r = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(_r, "诺诺平台", "重推发票信息", "返回值");
var _return = dealresponse_Read(_r);
return result;
}
private ReadResponse_ dealresponse_Read(string json)
{
var result = new ReadResponse_();
result = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<ReadResponse_>(json.Trim('"'));
return result;
}
public DBResult PostInvoice(ChInvoice_HangXin head, List<ChInvoiceDetail> detailList)
{
var billno = head.BILLNO;
var _head = new NuoNuoQuanDianInvoice(head, detailList);
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(_head);
var _r = "";
_r = PostInvoice(json);
var _return = dealresponse_KP(_r);
if (_return.code == "E0000")
{
//开票提交成功
var invoiceSerialNum = _return.result.invoiceSerialNum;
//立即调用读取发票信息的方法 将返回值设置进head 并保存
head.INVOICESERIALNUM = invoiceSerialNum;
head.BILLNO = billno;
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
var modb = new ModelObjectDB();
var result = modb.Save(head);
result = ReadInvoice(head);
//var returndate = ChinvoiceDAL.GetDataList(0, 1, "cm.INVOICESERIALNUM='" + head.INVOICESERIALNUM + "'", head.OPERATOR);
//result.Data = returndate;
return result;
}
else if (_return.code == "070101" || _return.code == "070301")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
var result = new DBResult(false, "需要重新认证", null);
return result;
}
else if (_return.code == "E9106")
{
//E9106 订单编号不能重复
//同billno重复发送 执行一次用订单号读取
return ReadInvoice_BILLNO(head);
}
else
{
var reault = new DBResult(false, _return.message, head);
return reault;
}
}
private string PostInvoice(string json)
{
string method = "nuonuo.OpeMplatform.requestBillingNew";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "发票开出", "发送值");
string result = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(result, "诺诺平台", "发票开出", "返回值");
return result;
}
/// <summary>
/// 诺诺全电 快速冲红
/// </summary>
/// <param name="head"></param>
/// <param name="detailList"></param>
/// <returns></returns>
public DBResult PostRedInvoice(ref ChInvoice_HangXin head)
{
//var billno = head.BILLNO;
var _head = new NuoNuoQuanDian_SetRed(head);
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(_head);
string method = "nuonuo.OpeMplatform.fastInvoiceRed";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "快捷冲红", "发送值");
string rtn = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(rtn, "诺诺平台", "快捷冲红", "返回值");
var _return = dealresponse_KP(rtn);
var result = new DBResult();
if (_return.code == "E0000")
{
//冲红提交成功
var invoiceSerialNum = _return.result.invoiceSerialNum;
//立即调用读取发票信息的方法 将返回值设置进head 并保存
head.INVOICESERIALNUM = invoiceSerialNum;
return result.OK();
}
else if (_return.code == "070101" || _return.code == "070301")
{
//appkey与token问题 需要重新认证
//HangXinRequestHelper.clear(accessToken);
result.SetErrorInfo("需要重新认证");
return result;
}
else if (_return.code == "E9106")
{
//E9106 订单编号不能重复
//同billno重复发送 执行一次用订单号读取
return ReadInvoice_BILLNO(head);
}
else
{
var reault = new DBResult(false, _return.message, head);
return reault;
}
}
/// <summary>
/// 诺诺全电 红字确认单申请
/// </summary>
/// <param name="head"></param>
/// <param name="detailList"></param>
/// <returns></returns>
public DBResult PostRedConfirm(ChInvoice_HangXin head, ref ChInvoice_HangXin bluehead, List<ChInvoiceDetail> detailList,HttpSessionStateBase Session)
{
//var billno = head.BILLNO;
//20230529 增加判断 如果INVOICEMAKETIME到当前时间 小于24小时 则提示错误并返回
//
var _head = new NuoNuoQuanDian_RedConfirm(head);
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(_head);
string method = "nuonuo.OpeMplatform.saveInvoiceRedConfirm";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺全电", "红字确认单", "发送值");
string rtn = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(rtn, "诺诺全电", "红字确认单", "返回值");
var _return = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<>(rtn.Trim('"'));
var result = new DBResult();
if (_return.code == "E0000")
{
//红字申请单提交成功
//读取红字确认单
var _r = ReadRedConfirm(ref head, detailList);
if (!_r.Success)
{
if (_r.Message != "红字确认单申请中")
bluehead.billUuid = "";
return _r;
}
else
{
var hx = .getHelper(head.TAXCODE, head.COMPANYID);
if (!hx.CanUse)
{
result.SetErrorInfo(hx.ERRORMSG);
return result;
}
//if (hx.accessToken == "")
//{
// BasicDataRefDAL.SaveLog("NNReadInv;税号" + head.TAXCODE + "的 accessToken为空", "", "诺诺平台", "返回认证窗口");
// var _r = TokenPage();
// return _r;
//}
result = hx.ReadInvoice(head);
if (!result.Success)
{
return result;
}
//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 = ChinvoiceDAL.SetInvoiceFee(BlueInvoice,Session);
}
//如果状态为开出成功 则执行锁定
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);
}
returndate = ChinvoiceDAL.GetData(" BILLNO='" + head.BILLNO + "'");
}
result.Data = returndate;
return result;
}
}
//else if (_return.code == "070101" || _return.code == "070301")
//{
// //appkey与token问题 需要重新认证
// //HangXinRequestHelper.clear(accessToken);
// result.SetErrorInfo("需要重新认证");
// return result;
//}
//else if (_return.code == "E9106")
//{
// //E9106 订单编号不能重复
// //同billno重复发送 执行一次用订单号读取
// return ReadInvoice_BILLNO(head);
//}
else
{
bluehead.billUuid = "";
var reault = new DBResult(false, _return.message, head);
return reault;
}
}
/// <summary>
/// 用户查询全电发票红字确认单
/// </summary>
/// <param name="head"></param>
/// <returns></returns>
public DBResult ReadRedConfirm(ref ChInvoice_HangXin head, List<ChInvoiceDetail> detailList = null)
{
//var billno = head.BILLNO;
var _head = new NuoNuoQuanDian_ReadRedConfirm(head);
var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(_head);
string method = "nuonuo.OpeMplatform.queryInvoiceRedConfirm";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺全电", "读红字单", "发送值");
string rtn = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(rtn, "诺诺全电", "读红字单", "返回值");
var _return = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<>(rtn.Trim('"'));
var result = new DBResult();
if (_return.code == "E0000")
{
//根据查询结果读取红票信息
//税务那边实际的红票的订单编号 即为红字申请单orderno也就是当时传过去的咱们的发票BILLNO
if (_return.())
{
//则读取红票
//如不为空 这就是发出红字申请单之后返回结果成功立刻读的
//如为空 就是已产生的红票读取 就不保存了
if (detailList != null)
{
head.INVOICESERIALNUM = "";
var modb = new ModelObjectDB();
result = ChinvoiceDAL.SaveInvDetail(head.GID, detailList);
if (result.Success == true)
{
result = modb.Save(head);
};
}
//result = ReadInvoice(head);
//return result;
;
}
else
{
/*红字确认单状态(不传则查全部状态): 01 无需确认 02
销方录入待购方确认 03 购方录入待销方确认 04 购销双方
已确认 05 作废(销方录入购方否认) 06 作废(购方录入
销方否认) 07 作废(超 72 小时未确认) 08 作废(发起方
已撤销) 09 作废(确认后撤销) 15 申请中 16 申请失败*/
if (_return.())
{
return result.SetErrorInfo("红字确认单申请中");
}
else
{
return result.SetErrorInfo(_return.());
}
}
return result.OK();
}
else
{
var reault = new DBResult(false, _return.message, head);
return reault;
}
}
private KPResponse dealresponse_KP(string json)
{
var result = new KPResponse();
result = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<KPResponse>(json.Trim('"'));
return result;
}
public DBResult VoidInvoice(ChInvoice_HangXin head)
{
if (string.IsNullOrEmpty(head.INVOICESERIALNUM))
{
var result = new DBResult { Success = false, Message = "还未成功进行平台开票,不需要执行作废", Data = "" };
return result;
}
//作废接口
string method = "nuonuo.electronInvoice.invoiceCancellation";
// String content = "{" +
//"\"invoiceId\":\"19051413444101000011\"," +
//"\"invoiceCode\":\"033001800211\"," +
//"\"invoiceNo\":\"07912653\"" +
//"}";
var json = "{" +
"\"invoiceId\":\"" + head.INVOICESERIALNUM + "\"," +
"\"invoiceCode\":\"" + head.INVOICECODE + "\"," +
"\"invoiceNo\":\"" + head.INVOICENO + "\"" +
"}";
BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "发票作废", "发送值");
string _r = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json);
BasicDataRefDAL.SaveLog(_r, "诺诺平台", "发票作废", "返回值");
var _return = dealresponse_KP(_r);
if (_return.code == "E0000")
{
//作废请求成功
var invoiceSerialNum = _return.result.invoiceId;
head.INVOICESERIALNUM = invoiceSerialNum;
head.ISDELETE = "true";
var result = ReadInvoice(head);
//var result = new DBResult { Success = true, Message = _return.code + ":" + _return.describe, Data = head };
return result;
}
else
{
var msg = _return.code + _return.status + ":" + _return.describe + _return.msg;
var result = new DBResult { Success = false, Message = DSWeb.TruckMng.Helper.JsonConvert.Serialize(msg), Data = "" };
return result;
}
}
}
public class PortTokenmb
{
public string message { get; set; }
public string status { get; set; }
}
[JsonObject]
public class ISVTokenmb : ModelObjectBillHead
{
public string access_token { get; set; }
public string refresh_token { get; set; }
public string expires_in { get; set; }
public string userId { get; set; }
public string oauthUser { get; set; }
public oauthUser _oauthUser
{
get
{
oauthUser r_oauthUser = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<oauthUser>(oauthUser);//DSWeb.TruckMng.Helper.
return r_oauthUser;
}
}
public string error_description { get; set; }
public string error { get; set; }
/*"{\"access_token\":\"98600c833f178852e2f4d51cexk9yegi\",
* \"refresh_token\":\"faf038898dec26eac62640aaed0506cb\",
* \"oauthUser\":\"
* {\\\"userName\\\":\\\"339901999999142\\\",
* \\\"registerType\\\":\\\"1\\\"}\",
* \"expires_in\":86356,
* \"userId\":\"d1aa0da6bc9840ae83c1120cecd057ac\"}"*/
}
[JsonObject]
public class Refreshtokenmb
{
//{"access_token":"1213ef77eab8280536a1a41jehndvz3i","refresh_token":"1a743ee6fd1d965db2b39943e703da4a","expires_in":86400}
//{"error_description":"Incorrect refreshToken[8ffb4a7e21691a5d295ee4f64920fc0d]","error":"070314"}
public string access_token { get; set; }
public string refresh_token { get; set; }
public string error_description { get; set; }
public string error { get; set; }
}
[JsonObject]
public class oauthUser : ModelObjectBillBody
{
public string userName { get; set; }
public string registerType { get; set; }
}
[JsonObject]
///解析开票命令返回值;作废命令返回值
public class KPResponse
{
public string code { get; set; }
public string describe { get; set; }
public string msg { get; set; }
public string status { get; set; }
public string message { get { return code + ":" + describe; } }
//public KPResult _result { get {return DSWeb.TruckMng.Helper.JsonConvert.Deserialize<KPResult>(result);} }
public KPResult result { get; set; }
}
[JsonObject]
///解析开票命令返回值内的result
public class KPResult
{
public string invoiceSerialNum { get; set; }
public string invoiceId { get; set; }
}
[JsonObject]
public class : KPResponse
{
//{"code":"E0000","describe":"调用成功","result":"IN2023051900001"}
public new string result { get; set; }
}
[JsonObject]
///解析开票命令返回值;作废命令返回值
public class : KPResponse
{
public new result result { get; set; }
public bool ()
{
return result.billStatus() == "01";
}
public string ()
{
return result.errormsg();
}
public bool ()
{
return result.billStatus() == "15";
}
}
public class result
{
public int total { get; set; }
public new List<> list { get; set; }
public string billStatus()
{
if (list == null || list.Count == 0) return null;
return list[0].billStatus;
}
public string errormsg()
{
if (list == null || list.Count == 0) return null;
return list[0].billMessage;
}
}
public class
{
/// <summary>
///
/// </summary>
public int id { get; set; }
/// <summary>
///
/// </summary>
public string billId { get; set; }
/// <summary>
///
/// </summary>
public int detailIndex { get; set; }
/// <summary>
///
/// </summary>
public int blueDetailIndex { get; set; }
/// <summary>
/// 代理运杂费
/// </summary>
public string goodsName { get; set; }
/// <summary>
///
/// </summary>
public string unit { get; set; }
/// <summary>
///
/// </summary>
public string specType { get; set; }
/// <summary>
///
/// </summary>
public string taxExcludedPrice { get; set; }
/// <summary>
///
/// </summary>
public string taxExcludedAmount { get; set; }
/// <summary>
///
/// </summary>
public string num { get; set; }
/// <summary>
///
/// </summary>
public string taxRate { get; set; }
/// <summary>
///
/// </summary>
public string taxAmount { get; set; }
/// <summary>
///
/// </summary>
public string goodsCode { get; set; }
/// <summary>
///
/// </summary>
public string favouredPolicyFlag { get; set; }
/// <summary>
///
/// </summary>
public string favouredPolicyName { get; set; }
/// <summary>
///
/// </summary>
public string zeroRateFlag { get; set; }
/// <summary>
/// 经纪代理服务
/// </summary>
public string goodsCodeAbb { get; set; }
/// <summary>
///
/// </summary>
public string price { get; set; }
/// <summary>
///
/// </summary>
public int withTaxFlag { get; set; }
/// <summary>
///
/// </summary>
public string deduction { get; set; }
/// <summary>
///
/// </summary>
public string taxIncludedAmount { get; set; }
}
public class
{
/// <summary>
///
/// </summary>
public int id { get; set; }
/// <summary>
///
/// </summary>
public string billId { get; set; }
/// <summary>
///
/// </summary>
public string billNo { get; set; }
/// <summary>
///
/// </summary>
public string billUuid { get; set; }
/// <summary>
///
/// </summary>
public string billStatus { get; set; }
/// <summary>
///
/// </summary>
public string requestStatus { get; set; }
/// <summary>
///
/// </summary>
public string billMessage { get; set; }
/// <summary>
///
/// </summary>
public int openStatus { get; set; }
/// <summary>
///
/// </summary>
public int applySource { get; set; }
/// <summary>
///
/// </summary>
public DateTime billTime { get; set; }
/// <summary>
///
/// </summary>
public string taxExcludedAmount { get; set; }
/// <summary>
///
/// </summary>
public string taxAmount { get; set; }
/// <summary>
///
/// </summary>
public string taxIncludeAmount { get; set; }
/// <summary>
///
/// </summary>
public string blueElecInvoiceNumber { get; set; }
/// <summary>
///
/// </summary>
public string blueInvoiceNumber { get; set; }
/// <summary>
///
/// </summary>
public string blueInvoiceCode { get; set; }
/// <summary>
///
/// </summary>
public DateTime blueInvoiceTime { get; set; }
/// <summary>
///
/// </summary>
public string blueInvoiceLine { get; set; }
/// <summary>
///
/// </summary>
public string sellerTaxNo { get; set; }
/// <summary>
/// 青岛锦海运通供应链有限公司
/// </summary>
public string sellerName { get; set; }
/// <summary>
///
/// </summary>
public string buyerTaxNo { get; set; }
/// <summary>
/// 青岛东宝电子有限公司
/// </summary>
public string buyerName { get; set; }
/// <summary>
///
/// </summary>
public DateTime createTime { get; set; }
/// <summary>
///
/// </summary>
public DateTime updateTime { get; set; }
/// <summary>
///
/// </summary>
public string sellerAccount { get; set; }
/// <summary>
/// 中国建设银行平度支行 37101997906051000773
/// </summary>
public string buyerAccount { get; set; }
/// <summary>
///
/// </summary>
public string vatUsage { get; set; }
/// <summary>
///
/// </summary>
public string saleTaxUsage { get; set; }
/// <summary>
///
/// </summary>
public string accountStatus { get; set; }
/// <summary>
///
/// </summary>
public string departmentId { get; set; }
/// <summary>
///
/// </summary>
public string clerkId { get; set; }
/// <summary>
///
/// </summary>
public string extensionNumber { get; set; }
/// <summary>
///
/// </summary>
public string taxNum { get; set; }
/// <summary>
///
/// </summary>
public string account { get; set; }
/// <summary>
///
/// </summary>
public string redReason { get; set; }
/// <summary>
///
/// </summary>
public string confirmAgreement { get; set; }
/// <summary>
///
/// </summary>
public string confirmReason { get; set; }
/// <summary>
///
/// </summary>
public string confirmTime { get; set; }
/// <summary>
///
/// </summary>
public int requestSrc { get; set; }
/// <summary>
///
/// </summary>
public List<> detail { get; set; }
}
[JsonObject]
///解析读取发票信息命令返回值
public class ReadResponse
{
public string code { get; set; }
public string describe { get; set; }
public bool success { get { if (code == "E0000") return true; else return false; } }
/*
public List<ReadResult> _result
{
get {
List<ReadResult> _list = new List<ReadResult>();
foreach (var str in result)
{
var info = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<ReadResult>(str);
_list.Add(info);
}
return _list;
}
//set { _result = value }
}
public List<string> result { get; set; }
*/
public List<ReadResult> result { get; set; }
}
[JsonObject]
///解析读取发票信息命令返回值
public class ReadResponse_ : ReadResponse
{
public List<ReadResult_> result { get; set; }
}
[JsonObject]
///用于解析“读取发票信息”方法返回的发票信息
public class ReadResult
{
#region private Fields
private string _orderNo = string.Empty;
private string _invoiceSerialNum = string.Empty;
private string _status = string.Empty;
private string _statusMsg = string.Empty;
private string _resultMsg = string.Empty;
private string _invoiceFileUrl = string.Empty;
private string _invoiceImageUrl = string.Empty;
private string _invoiceDate = string.Empty;
private string _invoiceCode = string.Empty;
private string _invoiceNum = string.Empty;
private string _taxExcludedAmount = string.Empty;
private string _taxIncludedAmount = string.Empty;
private string _buyerName = string.Empty;
private string _buyerTaxNum = string.Empty;
private string _invoiceLine = string.Empty;
#endregion
#region public Fields
public string orderNo
{
get { return _orderNo; }
set { _orderNo = value; }
}
public string invoiceSerialNum
{
get { return _invoiceSerialNum; }
set { _invoiceSerialNum = value; }
}
public string status
{
get { return _status; }
set { _status = value; }
}
public string statusMsg
{
get { return _statusMsg; }
set { _statusMsg = value; }
}
public string resultMsg
{
get { return _resultMsg; }
set { _resultMsg = value; }
}
public string invoiceFileUrl
{
get { return _invoiceFileUrl; }
set { _invoiceFileUrl = value; }
}
public string invoiceImageUrl
{
get { return _invoiceImageUrl; }
set { _invoiceImageUrl = value; }
}
public string invoiceDate
{
get { return _invoiceDate; }
set { _invoiceDate = value; }
}
public string invoiceCode
{
get { return _invoiceCode; }
set { _invoiceCode = value; }
}
public string invoiceNum
{
get { return _invoiceNum; }
set { _invoiceNum = value; }
}
public string taxExcludedAmount
{
get { return _taxExcludedAmount; }
set { _taxExcludedAmount = value; }
}
public string taxIncludedAmount
{
get { return _taxIncludedAmount; }
set { _taxIncludedAmount = value; }
}
public string buyerName
{
get { return _buyerName; }
set { _buyerName = value; }
}
public string buyerTaxNum
{
get { return _buyerTaxNum; }
set { _buyerTaxNum = value; }
}
public string invoiceLine
{
get { return _invoiceLine; }
set { _invoiceLine = value; }
}
public string remark
{
get;
set;
}
#endregion
}
///用于解析“读取发票信息”方法返回的发票信息
public class ReadResult_
{
/// <summary>
/// 流水号
/// </summary>
public string serialNo { get; set; }
/// <summary>
/// 业务编号
/// </summary>
public string orderNo { get; set; }
/// <summary>
///
/// </summary>
public string status { get; set; }
/// <summary>
/// 开票完成(最终状态)
/// </summary>
public string statusMsg { get; set; }
/// <summary>
///
/// </summary>
public string failCause { get; set; }
/// <summary>
///
/// </summary>
public string pdfUrl { get; set; }
/// <summary>
///
/// </summary>
public string pictureUrl { get; set; }
/// <summary>
///
/// </summary>
public long invoiceTime { get; set; }
/// <summary>
///
/// </summary>
public string invoiceCode { get; set; }
/// <summary>
///
/// </summary>
public string invoiceNo { get; set; }
/// <summary>
///
/// </summary>
public string exTaxAmount { get; set; }
/// <summary>
///
/// </summary>
public string taxAmount { get; set; }
/// <summary>
/// 个人2
/// </summary>
public string payerName { get; set; }
/// <summary>
///
/// </summary>
public string payerTaxNo { get; set; }
/// <summary>
/// 电子增值税普通发票
/// </summary>
public string invoiceKind { get; set; }
/// <summary>
///
/// </summary>
public string checkCode { get; set; }
/// <summary>
/// 含底图纸票pdf地址
/// </summary>
public string paperPdfUrl { get; set; }
public string ofdUrl { get; set; }
/// <summary>
///
/// </summary>
public List<InvoiceItems> invoiceItems { get; set; }
}
public class InvoiceItems
{
/// <summary>
/// 门票
/// </summary>
public string itemName { get; set; }
/// <summary>
/// 张
/// </summary>
public string itemUnit { get; set; }
/// <summary>
///
/// </summary>
public string itemPrice { get; set; }
/// <summary>
///
/// </summary>
public string itemTaxRate { get; set; }
/// <summary>
///
/// </summary>
public string itemNum { get; set; }
/// <summary>
///
/// </summary>
public string itemAmount { get; set; }
/// <summary>
///
/// </summary>
public string itemTaxAmount { get; set; }
/// <summary>
///
/// </summary>
public string itemSpec { get; set; }
/// <summary>
///
/// </summary>
public string itemCode { get; set; }
/// <summary>
///
/// </summary>
public string isIncludeTax { get; set; }
/// <summary>
///
/// </summary>
public string invoiceLineProperty { get; set; }
/// <summary>
///
/// </summary>
public string zeroRateFlag { get; set; }
/// <summary>
///
/// </summary>
public string favouredPolicyName { get; set; }
/// <summary>
///
/// </summary>
public string favouredPolicyFlag { get; set; }
}
[JsonObject]
public class P2INVOICE : BaseTableMC
{
}
//public class InvoiceFeeSum
//{
// public string CURR { get; set; }
// public decimal amount { get; set; }
// public decimal exchange { get; set; }
//}
}