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/Controllers/Chfee_invoice_HangXinContro...

2985 lines
120 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.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;
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"]);
headData.OPERATOR = Convert.ToString(Session["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)
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='" + headData.INVOICELINEREF + "'", "");
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;
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""}]";
//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("checkinfoBILLNO=" + 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);
}
}
}
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)
{
//如果已有pdf地址 则直接返回
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);
}
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);
}
}
}
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;
}
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 == "诺诺全电发票")
{
//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) };
}
//增加判断 如果原票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) };
//}
}
if (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改成一个新的发票信息
//将发票明细也同样处理
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.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 == "诺诺全电发票")
{
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;
foreach (var detail in detailList)
{
//数量 税额 含税金额 不含税金额 取负数
detail.SetRed();
detail.PID = "*";
}
redhead.REMARK = REDREMARK_Quandian(redhead);
}
}
var modb = new ModelObjectDB();
if (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);
}
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("checkinfoBILLNO=" + 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
}
}