using Quartz;
using Quartz.Xml.JobSchedulingData20;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Linq.Mapping;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web.UI;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace ICSSoft.FromERP
{
///
/// 营业务税金及附加明细账
///
public class YERP_005 : IJob
{
private static object key = new object();
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void Execute(IJobExecutionContext context)
{
try
{
lock (key)
{
log.Info("开始……………………………………………………………………");
Execute();
log.Info("结束……………………………………………………………………");
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
public async void Execute()
{
try
{
Configuration config = GetConfig();
//string url = config.ConnectionStrings.ConnectionStrings["APIAddStdWorkHour"].ConnectionString.ToString();
var Dates = DateTime.Now;
//log.Info("获取创建定额工时接口 " + url);
//if (string.IsNullOrEmpty(url))
//{
// return;
//}
string conStr = ICSHelper.GetConnectString();
//PdfDocument doc = new PdfDocument();
//doc.LoadFromFile(@"C:\Users\andyxin\Desktop\日常文档\TS3400series_5200.pdf");//选择Microsoft XPS Document Writer打印机
//doc.PrintSettings.PrinterName = "Canon TS3400 series";//打印PDF文档到XPS格式
////doc.PrintSettings.PrintToFile(filename + ".pdf");
//doc.Print();
////log.Info("打印成功: " + path);
//Dictionary dParam = new Dictionary();
//dParam.Add("RCARD", "123456");
//dParam.Add("INVSTD", "654321");
//dParam.Add("DEFINE", "测试OK");
//BTPrint(@"D:\汇川27x7mm2排1.btw", "Microsoft Print to PDF", dParam);
//string aa = " < soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns: yerp = \"http://skch.com/YERP_005_TAX_VAT\" > " + @"
// < soapenv:Header />
// < soapenv:Body >
// < yerp:YERP_005_OA1_MT >
// < !--1 or more repetitions: -->
// < TAX_SURTAX >
// < SBJ_CD > 1 SBJ_CD >
// < SBJ_NM > 1 SBJ_NM >
// < YYYY >? YYYY >
// < MM >? MM >
// < DD >? DD >
// < SPTDOC >? SPTDOC >
// < SMR >? SMR >
// < ODR_ACC >? ODR_ACC >
// < !--Optional : -->
// < DBTO_AMT >? DBTO_AMT >
// < !--Optional : -->
// < CRDTO_AMT >? CRDTO_AMT >
// < !--Optional : -->
// < DBTO_CRDTO_DVSN > DBTO_CRDTO_DVSN >
// < !--Optional : -->
// < BLNC >? BLNC >
// TAX_SURTAX >
// yerp : YERP_005_OA1_MT >
// soapenv : Body >
// soapenv : Envelope >";
//< soapenv:Envelope xmlns:soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: yerp = "http://skch.com/YERP_005_TAX_VAT" >
// < soapenv:Header />
// < soapenv:Body >
// < yerp:YERP_005_OA1_MT >
// < !--1 or more repetitions: -->
// < TAX_SURTAX >
// < SBJ_CD > 6403 SBJ_CD >
// < SBJ_NM > 营业税金及附加 SBJ_NM >
// < !--Optional : -->
// < YYYY > 2024 YYYY >
// < !--Optional : -->
// < MM > 7 MM >
// < !--Optional : -->
// < SMR > 期初余额 SMR >
// < !--Optional : -->
// < DBTO_CRDTO_DVSN > 平 DBTO_CRDTO_DVSN >
// < !--Optional : -->
// < BLNC > 0.00000000 BLNC >
// TAX_SURTAX >
// yerp : YERP_005_OA1_MT >
// soapenv : Body >
// soapenv : Envelope >
// 202404
// 过滤时间为上个月
string Date = Dates.ToString("yyyy");
string beginMuoth = Dates.AddMonths(-1).ToString("MM");
string endMuoth = Dates.ToString("MM");
string Day = Dates.ToString("dd");
var beginPeriod =Date + beginMuoth;// "200001";
var endPeriod = Date + endMuoth;
string sqls = @"begin transaction
exec GL_Ledger @tblname=N'yysjmxz',@KmCode=N'6403',@beginPeriod={0},@endPeriod={1},@bVouch=0,@bequal=1,@sum=0,@bMJ=1,@swhere=N'',@sAuth=N'',@ReportID=N'GL13',@ReportType=0,@iUnite=0
select autoid,cCode SBJ_CD,ccode_name SBJ_NM,iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,cDCode ODR_ACC,md DBTO_AMT,mc CRDTO_AMT,(case when ibook is null then '平' else (case when ibook ='1' then '贷' else '借' end) end) DBTO_CRDTO_DVSN,tmpme,
(Select Sum(tmpme) from tempdb..yysjmxz where autoid<=a.autoid) BLNC from tempdb..yysjmxz a
rollback transaction";
sqls = string.Format(sqls, beginPeriod, endPeriod);
log.Info("YERP_005 sql:" + sqls);
DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
log.Info("sql结果数量"+vbsdt.Rows.Count);
if (vbsdt.Rows.Count > 0)
{
StringBuilder soapRequestData = new StringBuilder();
soapRequestData.Append("");
soapRequestData.Append("");
soapRequestData.Append("");
soapRequestData.Append("");
//循环数据
foreach (DataRow itemRow in vbsdt.Rows)
{
//原循环部分 begin
soapRequestData.Append("");
soapRequestData.Append(itemRow["SBJ_CD"] != null ? "" + itemRow["SBJ_CD"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["SBJ_NM"] != null ? "" + itemRow["SBJ_NM"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["YYYY"] != null ? "" + itemRow["YYYY"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["MM"] != null ? "" + itemRow["MM"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DD"] != null ? "" + itemRow["DD"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["SPTDOC"] != null ? "" + itemRow["SPTDOC"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["SMR"] != null ? "" + itemRow["SMR"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["ODR_ACC"] != null ? "" + itemRow["ODR_ACC"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DBTO_AMT"] != null ? "" + itemRow["DBTO_AMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["CRDTO_AMT"] != null ? "" + itemRow["CRDTO_AMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DBTO_CRDTO_DVSN"] != null ? "" + itemRow["DBTO_CRDTO_DVSN"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["BLNC"] != null ? "" + itemRow["BLNC"].ToString() + "" : "" + "");
soapRequestData.Append("");
//原循环部分 end
}
soapRequestData.Append("");
soapRequestData.Append("");
soapRequestData.Append("");
string postData = soapRequestData.ToString();
log.Info("YERP_005 xmlRequest:" + postData);
string statusCode;
string resultContent;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
RestOpHelper rop = new RestOpHelper();
rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
rop.Clientp12PassWord = "Yonyou2024!";
rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_005_OA1_SI&interfaceNamespace=http://skch.com/YERP_005_TAX_VAT";
rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
log.Info("YERP_005 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
public static Configuration GetConfig()
{
Assembly assembly = Assembly.GetCallingAssembly();
string path = string.Format("{0}.config", assembly.Location);
if (!File.Exists(path))
{
throw new FileNotFoundException(path + "路径下的文件未找到!");
}
try
{
ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
configFile.ExeConfigFilename = path;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
return config;
}
catch (Exception)
{
throw;
}
}
}
}