You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
16 KiB
232 lines
16 KiB
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
|
|
{
|
|
/// <summary>
|
|
/// 进销存统计表
|
|
/// </summary>
|
|
public class YERP_001 : 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();
|
|
//<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_001_INVENTORY_DATA">
|
|
// <soapenv:Header/>
|
|
// <soapenv:Body>
|
|
// <yerp:YERP_001_OA1_MT>
|
|
// <!--1 or more repetitions:-->
|
|
// <INVT_DATA>
|
|
// <YYYY_MM_DD>2024-08-20</YYYY_MM_DD>
|
|
// <INVT_NM>BR8040</INVT_NM>
|
|
// <INVT_CD>103016</INVT_CD>
|
|
// <BSC_QTY>0.00</BSC_QTY>
|
|
// <BSC_AMT>0.00</BSC_AMT>
|
|
// <PCHS_QTY>15000.00</PCHS_QTY>
|
|
// <PCHS_AMT>245870.26</PCHS_AMT>
|
|
// <ESTM_QTY>0.00</ESTM_QTY>
|
|
// <ESTM_AMT>0.00</ESTM_AMT>
|
|
// <ETC_WHG_QTY>8305.00</ETC_WHG_QTY>
|
|
// <ETC_WHG_AMT>157592.50</ETC_WHG_AMT>
|
|
// <ETC_RLS_QTY>8388.00</ETC_RLS_QTY>
|
|
// <ETC_RLS_AMT>151226.81</ETC_RLS_AMT>
|
|
// <MOVE_QTY>0.00</MOVE_QTY>
|
|
// <MOVE_AMT>0.00</MOVE_AMT>
|
|
// <SL_QTY>6450.0000</SL_QTY>
|
|
// <SL_RVN>102513.2100</SL_RVN>
|
|
// <SL_AMT>115839.8800</SL_AMT>
|
|
// <FRTX_AVRG_PRC>0</FRTX_AVRG_PRC>
|
|
// <SMTX_AVRG_PRC>0</SMTX_AVRG_PRC>
|
|
// <RLS_QTY>6450.00</RLS_QTY>
|
|
// <SL_COST>108183.8000</SL_COST>
|
|
// <SLS_TOT_GAIN>-5670.59</SLS_TOT_GAIN>
|
|
// <SLS_TOT_PRTO>?</SLS_TOT_PRTO>
|
|
// <TE_QTY>8467.00</TE_QTY>
|
|
// <TE_AMT>144052.15</TE_AMT>
|
|
// </INVT_DATA>
|
|
// </yerp:YERP_001_OA1_MT>
|
|
// </soapenv:Body>
|
|
// </soapenv:Envelope>
|
|
// 202404
|
|
// 过滤时间为上个月
|
|
string Date = "2023";// Dates.ToString("yyyy");
|
|
string Muoth = Dates.AddMonths(-1).ToString("MM");
|
|
string Day = Dates.ToString("dd");
|
|
var beginPeriod = "2023-01-01";//Date + Muoth;
|
|
var endPeriod = "2023-12-31";//Date + Muoth;
|
|
string sqls = @"
|
|
begin transaction
|
|
|
|
exec Sa_MoveSRMDetail N'JXCASKALL',N' ',N'{0}',N'{1}',N'{2}',N' ',N' ',N' ',N' ',N''
|
|
|
|
select identity(int,0,1) as baseid,isnull([存货名称],'') as [存货名称],isnull([规格型号],'') as [规格型号],isnull([存货编码],'') as [存货编码],(Convert(Decimal(38,2),SUM([cInvDefine12]))) as [cInvDefine12],(Convert(Decimal(38,2),SUM([cInvDefine11]))) as
|
|
[cInvDefine11],Convert(Decimal(38,2),SUM(isnull([期初金额],0)+isnull([采购金额],0)+isnull([其他入库金额],0)-isnull([销售成本],0)-isnull([其他出库金额],0))) as [期末金额],Convert(Decimal(38,2),SUM(isnull([期初数量],0)+isnull([采购数量],0)+isnull([其他入库数量],0)-isnull([其他出库数量],0)-isnull([出库数量],0))) as [期末数量],(Convert(Decimal(38,4),SUM([销售收入]))) as [销售收入],(Convert(Decimal(38,4),SUM([销售成本]))) as [销售成本],Convert(Decimal(38,2),SUM(isnull([销售收入],0)-isnull([销售成本],0))) as [毛利],(Convert(Decimal(38,2),SUM([出库数量]))) as [出库数量],(Convert(Decimal(38,4),SUM([销售金额]))) as [销售金额],(Convert(Decimal(38,4),SUM([销售数量]))) as [销售数量],(Convert(Decimal(38,2),SUM([调拨金额]))) as [调拨金额],(Convert(Decimal(38,2),SUM([调拨数量]))) as [调拨数量],(Convert(Decimal(38,2),SUM([其他出库金额]))) as [其他出库金额],(Convert(Decimal(38,2),SUM([其他出库数量]))) as [其他出库数量],(Convert(Decimal(38,2),SUM([其他入库金额]))) as [其他入库金额],(Convert(Decimal(38,2),SUM([其他入库数量]))) as [其他入库数量],(Convert(Decimal(38,2),SUM([暂估金额]))) as [暂估金额],(Convert(Decimal(38,2),SUM([暂估数量]))) as [暂估数量],(Convert(Decimal(38,2),SUM([采购金额]))) as [采购金额],(Convert(Decimal(38,2),SUM([采购数量]))) as [采购数量],(Convert(Decimal(38,2),SUM([期初金额]))) as [期初金额],(Convert(Decimal(38,2),SUM([期初数量]))) as [期初数量]
|
|
into tempdb..JXCASKALL_1 from tempdb..JXCASKALL
|
|
where 1 = 1 group by isnull([存货名称],''),isnull([规格型号],''),isnull([存货编码],'')
|
|
having isnull(sum([期初数量]),0)<> 0 or isnull(sum([采购数量]),0)<> 0 or isnull(sum([采购金额]),0) <> 0 or isnull(sum([其他入库数量]),0) <> 0 or isnull(sum([其他入库金额] ),0)<> 0 or isnull(sum([出库数量]),0)<>0 or isnull(sum([其他出库数量] ),0)<> 0 or isnull(sum([其他出库金额]),0) <> 0 or isnull(sum([期初金额]),0) <> 0 or isnull(sum([暂估数量]),0) <> 0 or isnull(sum([暂估金额] ),0)<> 0 or isnull(sum([销售数量]),0) <> 0 or isnull(sum([销售金额] ),0)<> 0 or isnull(sum([调拨数量]),0) <> 0 or isnull(sum([调拨金额]),0) <> 0 or isnull(sum([销售收入]),0) <> 0 or isnull(sum([销售成本]),0) <> 0
|
|
|
|
|
|
|
|
select A.* into TEMPDB..JXCASKALLNEW from TEMPDB..JXCASKALL A
|
|
inner join TEMPDB..JXCASKALL_1 sum on isnull(A.[存货名称],'')=isnull(sum.[存货名称],'') and isnull(A.[规格型号],'')=isnull(sum.[规格型号],'') and isnull(A.[存货编码],'')=isnull(sum.[存货编码],'')
|
|
select sum.* into TEMPDB..JXCASKALLNEW_1 from TEMPDB..JXCASKALL_1 sum
|
|
|
|
|
|
select identity(int,0,1) as index__id,* into tempdb..JXCASKALLNEW_index from
|
|
( select baseid +0 as baseid, [存货名称],[规格型号],[存货编码] from tempdb..JXCASKALLNEW_1)A where 1=0
|
|
|
|
|
|
|
|
insert into TEMPDB..JXCASKALLNEW_index
|
|
select * from (select top 1000 baseid +0 as baseid, [存货名称],[规格型号],[存货编码]
|
|
from TEMPDB..JXCASKALLNEW_1 order by [存货名称] asc)a
|
|
|
|
|
|
select B.index__id,a.存货名称 INVT_NM,a.存货编码 INVT_CD,a.期初数量 BSC_QTY,a.期初金额 BSC_AMT,a.采购数量 PCHS_QTY,a.采购金额 PCHS_AMT,a.暂估数量 ESTM_QTY,a.暂估金额 ESTM_AMT,a.其他入库数量 ETC_WHG_QTY,
|
|
a.其他入库金额 ETC_WHG_AMT,a.其他出库数量 ETC_RLS_QTY,a.其他出库金额 ETC_RLS_AMT,a.调拨数量 MOVE_QTY,a.调拨金额 MOVE_AMT,a.销售数量 SL_QTY,a.销售收入 SL_RVN,a.销售金额 SL_AMT,
|
|
'' FRTX_AVRG_PRC,
|
|
'' SMTX_AVRG_PRC,
|
|
a.出库数量 RLS_QTY,a.销售成本 SL_COST,a.毛利 SLS_TOT_GAIN,
|
|
'' SLS_TOT_PRTO,a.期末数量 TE_QTY,a.期末金额 TE_AMT
|
|
|
|
|
|
from TEMPDB..JXCASKALLNEW_1 A inner join
|
|
TEMPDB..JXCASKALLNEW_index B on A.baseid=B.baseid
|
|
|
|
drop table tempdb..JXCASKALL
|
|
drop table tempdb..JXCASKALL_1
|
|
drop table TEMPDB..JXCASKALLNEW
|
|
drop table TEMPDB..JXCASKALLNEW_1
|
|
drop table TEMPDB..JXCASKALLNEW_index
|
|
|
|
rollback transaction";
|
|
sqls = string.Format(sqls, Date, beginPeriod, endPeriod);
|
|
log.Info("YERP_001 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("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_001_INVENTORY_DATA\">");
|
|
soapRequestData.Append("<soapenv:Header/>");
|
|
soapRequestData.Append("<soapenv:Body>");
|
|
soapRequestData.Append("<yerp:YERP_001_OA1_MT>");
|
|
//循环数据
|
|
foreach (DataRow itemRow in vbsdt.Rows)
|
|
{
|
|
//原循环部分 begin
|
|
soapRequestData.Append("<INVT_DATA>");
|
|
soapRequestData.Append("<YYYY_MM_DD>" + Dates.ToString("yyyy-MM-dd") + "</YYYY_MM_DD>");
|
|
soapRequestData.Append(itemRow["INVT_NM"] != null ? "<INVT_NM>" + itemRow["INVT_NM"].ToString() + "</INVT_NM>" : "<INVT_NM>" + "</INVT_NM>");
|
|
soapRequestData.Append(itemRow["INVT_CD"] != null ? "<INVT_CD>" + itemRow["INVT_CD"].ToString() + "</INVT_CD>" : "<INVT_CD>" + "</INVT_CD>");
|
|
soapRequestData.Append(itemRow["BSC_QTY"] != null ? "<BSC_QTY>" + itemRow["BSC_QTY"].ToString() + "</BSC_QTY>" : "<BSC_QTY>" + "</BSC_QTY>");
|
|
soapRequestData.Append(itemRow["BSC_AMT"] != null ? "<BSC_AMT>" + itemRow["BSC_AMT"].ToString() + "</BSC_AMT>" : "<BSC_AMT>" + "</BSC_AMT>");
|
|
soapRequestData.Append(itemRow["PCHS_QTY"] != null ? "<PCHS_QTY>" + itemRow["PCHS_QTY"].ToString() + "</PCHS_QTY>" : "<PCHS_QTY>" + "</PCHS_QTY>");
|
|
soapRequestData.Append(itemRow["PCHS_AMT"] != null ? "<PCHS_AMT>" + itemRow["PCHS_AMT"].ToString() + "</PCHS_AMT>" : "<PCHS_AMT>" + "</PCHS_AMT>");
|
|
soapRequestData.Append(itemRow["ESTM_QTY"] != null ? "<ESTM_QTY>" + itemRow["ESTM_QTY"].ToString() + "</ESTM_QTY>" : "<ESTM_QTY>" + "</ESTM_QTY>");
|
|
soapRequestData.Append(itemRow["ESTM_AMT"] != null ? "<ESTM_AMT>" + itemRow["ESTM_AMT"].ToString() + "</ESTM_AMT>" : "<ESTM_AMT>" + "</ESTM_AMT>");
|
|
soapRequestData.Append(itemRow["ETC_WHG_QTY"] != null ? "<ETC_WHG_QTY>" + itemRow["ETC_WHG_QTY"].ToString() + "</ETC_WHG_QTY>" : "<ETC_WHG_QTY>" + "</ETC_WHG_QTY>");
|
|
soapRequestData.Append(itemRow["ETC_WHG_AMT"] != null ? "<ETC_WHG_AMT>" + itemRow["ETC_WHG_AMT"].ToString() + "</ETC_WHG_AMT>" : "<ETC_WHG_AMT>" + "</ETC_WHG_AMT>");
|
|
soapRequestData.Append(itemRow["ETC_RLS_QTY"] != null ? "<ETC_RLS_QTY>" + itemRow["ETC_RLS_QTY"].ToString() + "</ETC_RLS_QTY>" : "<ETC_RLS_QTY>" + "</ETC_RLS_QTY>");
|
|
soapRequestData.Append(itemRow["ETC_RLS_AMT"] != null ? "<ETC_RLS_AMT>" + itemRow["ETC_RLS_AMT"].ToString() + "</ETC_RLS_AMT>" : "<ETC_RLS_AMT>" + "</ETC_RLS_AMT>");
|
|
soapRequestData.Append(itemRow["MOVE_QTY"] != null ? "<MOVE_QTY>" + itemRow["MOVE_QTY"].ToString() + "</MOVE_QTY>" : "<MOVE_QTY>" + "</MOVE_QTY>");
|
|
soapRequestData.Append(itemRow["MOVE_AMT"] != null ? "<MOVE_AMT>" + itemRow["MOVE_AMT"].ToString() + "</MOVE_AMT>" : "<MOVE_AMT>" + "</MOVE_AMT>");
|
|
soapRequestData.Append(itemRow["SL_QTY"] != null ? "<SL_QTY>" + itemRow["SL_QTY"].ToString() + "</SL_QTY>" : "<SL_QTY>" + "</SL_QTY>");
|
|
soapRequestData.Append(itemRow["SL_RVN"] != null ? "<SL_RVN>" + itemRow["SL_RVN"].ToString() + "</SL_RVN>" : "<SL_RVN>" + "</SL_RVN>");
|
|
soapRequestData.Append(itemRow["SL_AMT"] != null ? "<SL_AMT>" + itemRow["SL_AMT"].ToString() + "</SL_AMT>" : "<SL_AMT>" + "</SL_AMT>");
|
|
soapRequestData.Append(itemRow["FRTX_AVRG_PRC"] != null ? "<FRTX_AVRG_PRC>" + itemRow["FRTX_AVRG_PRC"].ToString() + "</FRTX_AVRG_PRC>" : "<FRTX_AVRG_PRC>" + "</FRTX_AVRG_PRC>");
|
|
soapRequestData.Append(itemRow["SMTX_AVRG_PRC"] != null ? "<SMTX_AVRG_PRC>" + itemRow["SMTX_AVRG_PRC"].ToString() + "</SMTX_AVRG_PRC>" : "<SMTX_AVRG_PRC>" + "</SMTX_AVRG_PRC>");
|
|
soapRequestData.Append(itemRow["RLS_QTY"] != null ? "<RLS_QTY>" + itemRow["RLS_QTY"].ToString() + "</RLS_QTY>" : "<RLS_QTY>" + "</RLS_QTY>");
|
|
soapRequestData.Append(itemRow["SL_COST"] != null ? "<SL_COST>" + itemRow["SL_COST"].ToString() + "</SL_COST>" : "<SL_COST>" + "</SL_COST>");
|
|
soapRequestData.Append(itemRow["SLS_TOT_GAIN"] != null ? "<SLS_TOT_GAIN>" + itemRow["SLS_TOT_GAIN"].ToString() + "</SLS_TOT_GAIN>" : "<SLS_TOT_GAIN>" + "</SLS_TOT_GAIN>");
|
|
soapRequestData.Append(itemRow["SLS_TOT_PRTO"] != null ? "<SLS_TOT_PRTO>" + itemRow["SLS_TOT_PRTO"].ToString() + "</SLS_TOT_PRTO>" : "<SLS_TOT_PRTO>" + "</SLS_TOT_PRTO>");
|
|
soapRequestData.Append(itemRow["TE_QTY"] != null ? "<TE_QTY>" + itemRow["TE_QTY"].ToString() + "</TE_QTY>" : "<TE_QTY>" + "</TE_QTY>");
|
|
soapRequestData.Append(itemRow["TE_AMT"] != null ? "<TE_AMT>" + itemRow["TE_AMT"].ToString() + "</TE_AMT>" : "<TE_AMT>" + "</TE_AMT>");
|
|
soapRequestData.Append("</INVT_DATA>");
|
|
//原循环部分 end
|
|
}
|
|
soapRequestData.Append("</yerp:YERP_001_OA1_MT>");
|
|
soapRequestData.Append("</soapenv:Body>");
|
|
soapRequestData.Append("</soapenv:Envelope>");
|
|
string postData = soapRequestData.ToString();
|
|
log.Info("YERP_001 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_001_OA1_SI&interfaceNamespace=http://skch.com/YERP_001_INVENTORY_DATA";
|
|
rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
|
|
|
|
log.Info("YERP_001 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;
|
|
}
|
|
}
|
|
}
|
|
}
|