using Quartz;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ICSSoft.FromERP
{
///
/// 销售发票列表
///
public class YERP_002 : 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;
string conStr = ICSHelper.GetConnectString();
// 202404
// 过滤时间为上个月
string Date = Dates.ToString("yyyy");
string Muoth = Dates.AddMonths(-1).ToString("MM");
string Day = Dates.ToString("dd");
//
//
//
//
//
//
//
// ?
// ?
// ?
// ?
// ?
// ?
// ?
// ?
// ?
// ?
//
// ?
//
// ?
// ?
// ?
// ?
//
// ?
// ?
//
// ?
// ?
// ?
// ?
// ?
// ?
// ?
//
// ?
//
// ?
//
// ?
// ?
// ?
//
// ?
//
// ?
//
// ?
//
// ?
// ?
// ?
//
//
//
//
var beginPeriod = "2023-07-01";// Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-06-01";
var endPeriod = "2023-08-01";// Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-07-01";
string sqls = @"
select b.cSOCode P_ORDER_NUM,cBusType BIZ_TYP,cSTName SL_TYP,cSBVCode INVC_NO,dDate INVC_DE,cDLCode DO_NO,cCusCode CUST_CD,cCusName CUST_NM,cexch_name CUR,iExchRate ER,
cDepName SL_TEAM, cPsn_Name SL_PIC,cWhCode WH, b.cInvCode INVT_CD, c.cInvAddCode INVT_ACD, c.cInvName INVT_NM, c.cInvStd STDD_MDL, b.iQuantity QTY, b.iQuotedPrice STMT, iTaxUnitPrice PRTX_UPRC,
iUnitPrice FRTX_UPRC, iMoney FRTX_AMT,b.iTaxRate TXRTO, iTax TX_AMT,iSum PRTX_AMT, KL DISRTO1,KL2 DISRTO2, iDisCount DIS_AMT,cMaker CRTR, cChecker REVR,a.csscode STTL_TYP_CD, a.cSCCode DLVR_TYP_CD,
d.cSCName DLVR_TYP, cSSName STTL_TYP,
iSum - iExchSum OUTST_AMT, --原币价税合计 - 累计原币收款金额
iNatSum - iMoneySum OUTST_LCUR, --本币价税合计-累计本币收款金额
0 Printnum,a.dDate
from dbo.SaleBillVouch a left join dbo.SaleBillVouchs b on A.SBVID = B.SBVID
left join dbo.Inventory c on b.cInvCode = c.cInvCode
left join dbo.ShippingChoice d on a.cSCCode = d.cSCCode
left join dbo.SettleStyle e on a.csscode = e.cSSCode
left join dbo.SaleType f on a.cSTCode = f.cSTCode
left join dbo.hr_hi_person h on a.cPersonCode = h.cPsn_Num
left join dbo.Department j on j.cDepCode = a.cDepCode WHERE 1 = 1 and a.dDate >= '{0}' and a.dDate <= '{1}'";
sqls = string.Format(sqls, beginPeriod, endPeriod);
log.Info("YERP_002 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["P_ORDER_NUM"] != null ? "" + itemRow["P_ORDER_NUM"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["BIZ_TYP"] != null ? "" + itemRow["BIZ_TYP"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["SL_TYP"] != null ? "" + itemRow["SL_TYP"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["INVC_NO"] != null ? "" + itemRow["INVC_NO"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["INVC_DE"] != null ? "" + itemRow["INVC_DE"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DO_NO"] != null ? "" + itemRow["DO_NO"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["CUST_CD"] != null ? "" + itemRow["CUST_CD"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["CUST_NM"] != null ? "" + itemRow["CUST_NM"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["CUR"] != null ? "" + itemRow["CUR"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["ER"] != null ? "" + itemRow["ER"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["SL_TEAM"] != null ? "" + itemRow["SL_TEAM"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["SL_PIC"] != null ? "" + itemRow["SL_PIC"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["WH"] != null ? "" + itemRow["WH"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["INVT_CD"] != null ? "" + itemRow["INVT_CD"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["INVT_NM"] != null ? "" + itemRow["INVT_NM"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["STDD_MDL"] != null ? "" + Regex.Replace(itemRow["STDD_MDL"].ToString(), @"[^0-9]+", "") + "" : "" + "");
soapRequestData.Append(itemRow["QTY"] != null ? "" + itemRow["QTY"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["STMT"] != null ? "" + itemRow["STMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["PRTX_UPRC"] != null ? "" + itemRow["PRTX_UPRC"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["FRTX_UPRC"] != null ? "" + itemRow["FRTX_UPRC"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["FRTX_AMT"] != null ? "" + itemRow["FRTX_AMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["TXRTO"] != null ? "" + itemRow["TXRTO"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["TX_AMT"] != null ? "" + itemRow["TX_AMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["PRTX_AMT"] != null ? "" + itemRow["PRTX_AMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DISRTO1"] != null ? "" + itemRow["DISRTO1"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DISRTO2"] != null ? "" + itemRow["DISRTO2"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DIS_AMT"] != null ? "" + itemRow["DIS_AMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["CRTR"] != null ? "" + itemRow["CRTR"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["REVR"] != null ? "" + itemRow["REVR"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["STTL_TYP_CD"] != null ? "" + itemRow["STTL_TYP_CD"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DLVR_TYP_CD"] != null ? "" + itemRow["DLVR_TYP_CD"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["DLVR_TYP"] != null ? "" + itemRow["DLVR_TYP"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["STTL_TYP"] != null ? "" + itemRow["STTL_TYP"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["OUTST_AMT"] != null ? "" + itemRow["OUTST_AMT"].ToString() + "" : "" + "");
soapRequestData.Append(itemRow["OUTST_LCUR"] != null ? "" + itemRow["OUTST_LCUR"].ToString() + "" : "" + "");
soapRequestData.Append("");
//原循环部分 end
}
soapRequestData.Append("");
soapRequestData.Append("");
soapRequestData.Append("");
string postData = soapRequestData.ToString();
log.Info("YERP_002 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_002_OA1_SI&interfaceNamespace=http://skch.com/YERP_002_SALES_INVOICE";
rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
log.Info("YERP_002 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;
}
}
}
}