diff --git a/CompControl.SapFrameworkConnector/App.config b/CompControl.SapFrameworkConnector/App.config index e7094ce..afb52f9 100644 --- a/CompControl.SapFrameworkConnector/App.config +++ b/CompControl.SapFrameworkConnector/App.config @@ -1,46 +1,182 @@ - + - + - - - - - - - - - - + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CompControl.SapFrameworkConnector/CompControl.SapFrameworkConnector.csproj b/CompControl.SapFrameworkConnector/CompControl.SapFrameworkConnector.csproj index 1a78ebc..ffdc9f5 100644 --- a/CompControl.SapFrameworkConnector/CompControl.SapFrameworkConnector.csproj +++ b/CompControl.SapFrameworkConnector/CompControl.SapFrameworkConnector.csproj @@ -1,5 +1,6 @@ + Debug @@ -13,6 +14,8 @@ true true + + AnyCPU @@ -34,15 +37,207 @@ 4 - - ExternalDLLs\CompControl.dll + + packages\CompControl.4.0.3.2\lib\net472\CompControl.dll - - ExternalDLLs\CompControl.ErpConnector.Service.dll + + packages\CompControl.ErpConnector.Utility.1.0.6\lib\netstandard2.0\CompControl.ErpConnector.Utility.dll + + + packages\CompControl.ProductionControl.Utility.1.0.0-beta.18\lib\netstandard2.0\CompControl.ProductionControl.Utility.dll + + + packages\CompControl.StockControlWMS.1.0.2.19-beta.1\lib\netstandard2.0\CompControl.StockControlWMS.dll + + + packages\CompControl.StockControlWMS.API.Client.1.0.3-beta.1\lib\netstandard2.0\CompControl.StockControlWMS.API.Client.dll + + + packages\Dapper.2.1.66\lib\net461\Dapper.dll + + + packages\Dapper.Contrib.2.0.78\lib\net461\Dapper.Contrib.dll + + + packages\FirebirdSql.Data.FirebirdClient.10.3.3\lib\net48\FirebirdSql.Data.FirebirdClient.dll + + + packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll packages\log4net.3.2.0\lib\net462\log4net.dll + + packages\Microsoft.AspNetCore.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.dll + + + packages\Microsoft.AspNetCore.Authentication.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Abstractions.dll + + + packages\Microsoft.AspNetCore.Authentication.Core.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Core.dll + + + packages\Microsoft.AspNetCore.Authorization.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Authorization.dll + + + packages\Microsoft.AspNetCore.Authorization.Policy.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Authorization.Policy.dll + + + packages\Microsoft.AspNetCore.Connections.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Connections.Abstractions.dll + + + packages\Microsoft.AspNetCore.Diagnostics.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Diagnostics.dll + + + packages\Microsoft.AspNetCore.Diagnostics.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Diagnostics.Abstractions.dll + + + packages\Microsoft.AspNetCore.HostFiltering.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.HostFiltering.dll + + + packages\Microsoft.AspNetCore.Hosting.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.dll + + + packages\Microsoft.AspNetCore.Hosting.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll + + + packages\Microsoft.AspNetCore.Hosting.Server.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll + + + packages\Microsoft.AspNetCore.Http.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.dll + + + packages\Microsoft.AspNetCore.Http.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll + + + packages\Microsoft.AspNetCore.Http.Extensions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Extensions.dll + + + packages\Microsoft.AspNetCore.Http.Features.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll + + + packages\Microsoft.AspNetCore.HttpOverrides.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.HttpOverrides.dll + + + packages\Microsoft.AspNetCore.JsonPatch.9.0.9\lib\net462\Microsoft.AspNetCore.JsonPatch.dll + + + packages\Microsoft.AspNetCore.Mvc.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Abstractions.dll + + + packages\Microsoft.AspNetCore.Mvc.Core.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll + + + packages\Microsoft.AspNetCore.ResponseCaching.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.ResponseCaching.Abstractions.dll + + + packages\Microsoft.AspNetCore.Routing.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Routing.dll + + + packages\Microsoft.AspNetCore.Routing.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Routing.Abstractions.dll + + + packages\Microsoft.AspNetCore.Server.IISIntegration.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.IISIntegration.dll + + + packages\Microsoft.AspNetCore.Server.Kestrel.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.dll + + + packages\Microsoft.AspNetCore.Server.Kestrel.Core.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Core.dll + + + packages\Microsoft.AspNetCore.Server.Kestrel.Https.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Https.dll + + + packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.dll + + + packages\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll + + + packages\Microsoft.AspNetCore.WebUtilities.2.3.0\lib\netstandard2.0\Microsoft.AspNetCore.WebUtilities.dll + + + packages\Microsoft.Bcl.AsyncInterfaces.9.0.9\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + packages\Microsoft.Extensions.Configuration.8.0.0\lib\net462\Microsoft.Extensions.Configuration.dll + + + packages\Microsoft.Extensions.Configuration.Abstractions.9.0.0\lib\net462\Microsoft.Extensions.Configuration.Abstractions.dll + + + packages\Microsoft.Extensions.Configuration.Binder.9.0.0\lib\net462\Microsoft.Extensions.Configuration.Binder.dll + + + packages\Microsoft.Extensions.Configuration.CommandLine.8.0.0\lib\net462\Microsoft.Extensions.Configuration.CommandLine.dll + + + packages\Microsoft.Extensions.Configuration.EnvironmentVariables.8.0.0\lib\net462\Microsoft.Extensions.Configuration.EnvironmentVariables.dll + + + packages\Microsoft.Extensions.Configuration.FileExtensions.8.0.1\lib\net462\Microsoft.Extensions.Configuration.FileExtensions.dll + + + packages\Microsoft.Extensions.Configuration.Json.8.0.1\lib\net462\Microsoft.Extensions.Configuration.Json.dll + + + packages\Microsoft.Extensions.Configuration.UserSecrets.8.0.1\lib\net462\Microsoft.Extensions.Configuration.UserSecrets.dll + + + packages\Microsoft.Extensions.DependencyInjection.9.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll + + + packages\Microsoft.Extensions.DependencyInjection.Abstractions.9.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + packages\Microsoft.Extensions.DependencyModel.9.0.0\lib\net462\Microsoft.Extensions.DependencyModel.dll + + + packages\Microsoft.Extensions.Diagnostics.Abstractions.9.0.0\lib\net462\Microsoft.Extensions.Diagnostics.Abstractions.dll + + + packages\Microsoft.Extensions.FileProviders.Abstractions.9.0.0\lib\net462\Microsoft.Extensions.FileProviders.Abstractions.dll + + + packages\Microsoft.Extensions.FileProviders.Physical.8.0.0\lib\net462\Microsoft.Extensions.FileProviders.Physical.dll + + + packages\Microsoft.Extensions.FileSystemGlobbing.8.0.0\lib\net462\Microsoft.Extensions.FileSystemGlobbing.dll + + + packages\Microsoft.Extensions.Hosting.Abstractions.9.0.0\lib\net462\Microsoft.Extensions.Hosting.Abstractions.dll + + + packages\Microsoft.Extensions.Logging.9.0.0\lib\net462\Microsoft.Extensions.Logging.dll + + + packages\Microsoft.Extensions.Logging.Abstractions.9.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll + + + packages\Microsoft.Extensions.Logging.Configuration.8.0.1\lib\net462\Microsoft.Extensions.Logging.Configuration.dll + + + packages\Microsoft.Extensions.Logging.Console.8.0.1\lib\net462\Microsoft.Extensions.Logging.Console.dll + + + packages\Microsoft.Extensions.Logging.Debug.8.0.1\lib\net462\Microsoft.Extensions.Logging.Debug.dll + + + packages\Microsoft.Extensions.ObjectPool.8.0.11\lib\net462\Microsoft.Extensions.ObjectPool.dll + + + packages\Microsoft.Extensions.Options.9.0.0\lib\net462\Microsoft.Extensions.Options.dll + + + packages\Microsoft.Extensions.Options.ConfigurationExtensions.8.0.0\lib\net462\Microsoft.Extensions.Options.ConfigurationExtensions.dll + + + packages\Microsoft.Extensions.Primitives.9.0.0\lib\net462\Microsoft.Extensions.Primitives.dll + + + packages\Microsoft.Net.Http.Headers.2.3.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll + packages\Microsoft.Owin.4.2.3\lib\net45\Microsoft.Owin.dll @@ -53,7 +248,7 @@ packages\Microsoft.Owin.Hosting.4.2.3\lib\net45\Microsoft.Owin.Hosting.dll - packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll @@ -67,29 +262,131 @@ ExternalDLLs\sapnco_utils.dll - - - packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + packages\Serilog.4.3.0\lib\net471\Serilog.dll + + packages\Serilog.AspNetCore.9.0.0\lib\net462\Serilog.AspNetCore.dll + + + packages\Serilog.Extensions.Hosting.9.0.0\lib\net462\Serilog.Extensions.Hosting.dll + + + packages\Serilog.Extensions.Logging.9.0.0\lib\net462\Serilog.Extensions.Logging.dll + + + packages\Serilog.Formatting.Compact.3.0.0\lib\net471\Serilog.Formatting.Compact.dll + + + packages\Serilog.Settings.Configuration.9.0.0\lib\net462\Serilog.Settings.Configuration.dll + + + packages\Serilog.Sinks.Console.6.0.0\lib\net471\Serilog.Sinks.Console.dll + + + packages\Serilog.Sinks.Debug.3.0.0\lib\net471\Serilog.Sinks.Debug.dll + + + packages\Serilog.Sinks.File.6.0.0\lib\net471\Serilog.Sinks.File.dll + + + packages\CompControl.StockControlWMS.1.0.2.19-beta.1\lib\netstandard2.0\StockControlWMS.dll + + + packages\CompControl.StockControlWMS.API.Client.1.0.3-beta.1\lib\netstandard2.0\StockControlWMS.API.Client.dll + + + + packages\System.Buffers.4.6.0\lib\net462\System.Buffers.dll + + + packages\System.Collections.Immutable.8.0.0\lib\net462\System.Collections.Immutable.dll + + + + + packages\System.Data.Odbc.9.0.5\lib\net462\System.Data.Odbc.dll + + + packages\System.Diagnostics.DiagnosticSource.9.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll + + + packages\System.IO.4.3.0\lib\net462\System.IO.dll + True + True + + + packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + True + True + + + packages\System.IO.Pipelines.9.0.9\lib\net462\System.IO.Pipelines.dll + - - packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + packages\System.Memory.4.6.0\lib\net462\System.Memory.dll packages\Microsoft.AspNet.WebApi.Client.6.0.0\lib\net45\System.Net.Http.Formatting.dll + + packages\System.Net.Http.Json.9.0.9\lib\net462\System.Net.Http.Json.dll + - - packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + packages\System.Numerics.Vectors.4.6.0\lib\net462\System.Numerics.Vectors.dll - - packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + packages\System.Reflection.Metadata.8.0.1\lib\net462\System.Reflection.Metadata.dll - - packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll + True + True + + + packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll + True + True + + + packages\System.Security.Cryptography.Cng.5.0.0\lib\net47\System.Security.Cryptography.Cng.dll + + + packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + True + + + packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + packages\System.Text.Encodings.Web.9.0.9\lib\net462\System.Text.Encodings.Web.dll + + + packages\System.Text.Json.9.0.9\lib\net462\System.Text.Json.dll + + + packages\System.Threading.Channels.8.0.0\lib\net462\System.Threading.Channels.dll + + + packages\System.Threading.Tasks.Extensions.4.6.0\lib\net462\System.Threading.Tasks.Extensions.dll + + + + packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -105,6 +402,9 @@ + + packages\ToString.Fody.1.11.1\lib\net452\ToString.dll + @@ -130,6 +430,7 @@ + @@ -140,6 +441,23 @@ Service.cs - + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + \ No newline at end of file diff --git a/CompControl.SapFrameworkConnector/FodyWeavers.xml b/CompControl.SapFrameworkConnector/FodyWeavers.xml new file mode 100644 index 0000000..117b063 --- /dev/null +++ b/CompControl.SapFrameworkConnector/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/CompControl.SapFrameworkConnector/GBS/GBSApiController.cs b/CompControl.SapFrameworkConnector/GBS/GBSApiController.cs index 21b1a1a..701977d 100644 --- a/CompControl.SapFrameworkConnector/GBS/GBSApiController.cs +++ b/CompControl.SapFrameworkConnector/GBS/GBSApiController.cs @@ -12,5 +12,6 @@ namespace CompControl.SapFrameworkConnector { private static readonly log4net.ILog _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + //Controller for Custom BAPIs } } diff --git a/CompControl.SapFrameworkConnector/ILLink/ILLink.Descriptors.LibraryBuild.xml b/CompControl.SapFrameworkConnector/ILLink/ILLink.Descriptors.LibraryBuild.xml new file mode 100644 index 0000000..a42d7f0 --- /dev/null +++ b/CompControl.SapFrameworkConnector/ILLink/ILLink.Descriptors.LibraryBuild.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/CompControl.SapFrameworkConnector/Jenkinsfile b/CompControl.SapFrameworkConnector/Jenkinsfile new file mode 100644 index 0000000..59af789 --- /dev/null +++ b/CompControl.SapFrameworkConnector/Jenkinsfile @@ -0,0 +1,97 @@ +pipeline { + agent { label 'windows-agent' } + + environment { + REPO_CLONE_URL = 'https://git.compcontrol.de/CompControl/CompControl.git' + PROJECT_DIR = '.' + NUGET_SOURCE = 'https://nexus.compcontrol.de/repository/nuget-hosted/' + } + + triggers { + GenericTrigger( + causeString: 'Triggered by Gitea Webhook', + token: 'compcontrol', + genericVariables: [ + [key: 'ref', value: '$.ref'] + ], + regexpFilterText: '$ref', + regexpFilterExpression: 'refs/heads/main', + printContributedVariables: true, + printPostContent: false + ) + } + + stages { + + stage('Checkout') { + steps { + git branch: 'main', + url: "${env.REPO_CLONE_URL}", + credentialsId: '708b5429-833f-4685-8004-c0f916454cbb' + } + } + +// stage('Info') { +// steps { +// dir("${env.PROJECT_DIR}") { +// echo "msbuild -version: " +// bat 'msbuild -version' +// echo "dotnet msbuild -version: " +// bat 'dotnet msbuild -version' +// } +// } +// } + + stage('Pack') { + steps { + dir("${env.PROJECT_DIR}") { + bat 'dotnet clean' + bat 'if exist bin\\Release rmdir /s /q bin\\Release' + bat "\"${tool 'MSBuild_2022'}\\MSBuild.exe\" CompControl.csproj /p:Configuration=Release" + bat 'nuget pack . -Properties Configuration=Release -OutputDirectory bin\\Release' + } + } + } + + stage('Deploy') { + steps { + dir("${env.PROJECT_DIR}") { + script { + def nupkgFiles = bat(script: 'dir /b bin\\Release\\*.nupkg 2>nul', returnStatus: true) + if (nupkgFiles == 0) { + withCredentials([string(credentialsId: 'nuget-api-key', variable: 'NUGET_API_KEY')]) { + def pushResult = bat( + script: "dotnet nuget push bin\\Release\\*.nupkg --source ${env.NUGET_SOURCE} --api-key %NUGET_API_KEY%", + returnStatus: true + ) + + if (pushResult == 0) { + echo "NuGet package pushed successfully" + } else { + echo "NuGet push failed (likely version already exists) - continuing pipeline" + unstable("Package version already exists") + } + } + } else { + error "No .nupkg files found in bin\\Release" + } + } + } + } + } + + } + + post { + always { + cleanWs() + } + failure { + echo 'Pipeline failed!' + } + success { + echo 'Pipeline completed successfully!' + } + } + +} diff --git a/CompControl.SapFrameworkConnector/Service.cs b/CompControl.SapFrameworkConnector/Service.cs index 0672792..fe91a5d 100644 --- a/CompControl.SapFrameworkConnector/Service.cs +++ b/CompControl.SapFrameworkConnector/Service.cs @@ -3,9 +3,7 @@ using Microsoft.Owin; using Microsoft.Owin.Hosting; using SAP.Middleware.Connector; using System; -using System.Configuration; using System.ServiceProcess; -using System.Xml; namespace CompControl.SapFrameworkConnector { diff --git a/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs b/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs index e697f3a..6094110 100644 --- a/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs +++ b/CompControl.SapFrameworkConnector/Standard/SapStandardFunctions.cs @@ -1,11 +1,12 @@ -using CompControl.ErpConnector.Service.Models; -using log4net; +using CompControl.ErpConnector.Utility.Models; using SAP.Middleware.Connector; using System; using System.Collections.Generic; using System.Text; -using static CompControl.ErpConnector.Service.Models.Cicor_SapModels; -using static CompControl.ErpConnector.Service.Models.SapDataTypes; +using static CompControl.ErpConnector.Utility.Models.SAP_CompControl_Models; +using static CompControl.ErpConnector.Utility.Models.SAP_BAPI_Models; +using System.Security; +using System.Threading; namespace CompControl.SapFrameworkConnector { @@ -14,71 +15,93 @@ namespace CompControl.SapFrameworkConnector private static readonly log4net.ILog _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Logger - public static ApiResultBestellungen GetBestellung(string poNo) + public static ApiResultBestellungen GetBestellung(string poNo, bool useDetailsAlternative = false) { ApiResultBestellungen result = new ApiResultBestellungen(); - BAPI_PO_GETDETAIL_IMPORT import = new BAPI_PO_GETDETAIL_IMPORT() { PURCHASEORDER = poNo }; - BAPI_PO_GETDETAIL_EXPORT details = BAPI_PO_GETDETAILS(import); + BAPI_PO_GETDETAIL_IMPORT import = new BAPI_PO_GETDETAIL_IMPORT() { PURCHASEORDER = poNo, ITEMS = "X" }; + BAPI_PO_GETDETAIL_EXPORT details = new BAPI_PO_GETDETAIL_EXPORT(); + if (useDetailsAlternative) { details = BAPI_PO_GETDETAILS1(import); _log.Debug($"using BAPI_PO_GETDETAILS-1 !!!"); } + else { details = BAPI_PO_GETDETAILS(import); _log.Debug($"using BAPI_PO_GETDETAILS"); } + + _log.Debug($"PO_RET => {details.PO_ITEM_HISTORY.Count} HISTCOUNT, {details.PO_ITEMS.Count} POITEMS"); int cnt = 0; - foreach (BAPIEKPO det in details.PO_ITEMS) + try { - cnt++; - string inspect = ""; - string inspectInfo = ""; - string prioText = ""; - string prioChar = ""; - string ItemText1 = ""; - bool posIsClosed = false; - DateTime expDeliverDate = DateTime.MaxValue; - - if (det.QUAL_INSP.Equals("X")) + foreach (BAPIEKPO det in details.PO_ITEMS) { - inspect = "Q"; - if (ConfigHelper.SapLanguage.Equals("DE")) { inspectInfo = "Qualitaetspruefung erforderlich!"; } - else { inspectInfo = "Quality check mandatory!"; } + cnt++; + string inspect = ""; + string inspectInfo = ""; + string prioText = ""; + string prioChar = ""; + string itemText1 = ""; + bool posIsClosed = false; + DateTime expDeliverDate = DateTime.MaxValue; + + if (det.QUAL_INSP.Equals("X")) + { + inspect = "Q"; + if (ConfigHelper.SapLanguage.Equals("DE")) { inspectInfo = "Qualitaetspruefung erforderlich!"; } + else { inspectInfo = "Quality check mandatory!"; } + } + + expDeliverDate = ConvertSapDateToDateTime(det.ExpectedDeliveryDate); + if (det.QUANTITY <= det.QUANTITYPROCESSED) { posIsClosed = true; } + + //GetMAKTXfromMATNR_IMPORT getMak = new GetMAKTXfromMATNR_IMPORT(); + //getMak.MATNR = det.MATERIAL.Trim(); + //GetMAKTXfromMATNR_EXPORT outMak = GetMAKTXfromMATNR(getMak); + //ItemText1 = outMak.MAKTX; + + GrDataItem gr = new GrDataItem(); + gr.AcceptedManufacturesLink = cnt.ToString(); + gr.Created = ConvertSapDateToDateTime(details.PO_HEADER.CREATED_ON); + gr.LastUpdate = ConvertSapDateToDateTime(det.CHANGED_ON); + gr.PosIsClosed = posIsClosed; + gr.OrderNo = det.PO_NUMBER; + gr.OrderPos = det.PO_ITEM; + gr.OrderQuantity = det.QUANTITY; + gr.ItemNo = det.MATERIAL.Trim(); + gr.ItemText1 = itemText1; + if (!det.SHORT_TEXT.Trim().Equals("")) { gr.ItemText1 = det.SHORT_TEXT; } + gr.ItemNoRef = gr.CustomValue05 = det.PUR_MAT ?? ""; + gr.OrderPosInfoText = det.ACCTASSCAT; + gr.QuantityProcessed = det.QUANTITYPROCESSED; + gr.QuantityUnit = det.UNIT ?? ""; + gr.Plant = det.PLANT ?? ""; + gr.Inspection = inspect ?? ""; + gr.InspectionInfo = inspectInfo ?? ""; + gr.Priority = prioChar ?? ""; + gr.PriorityInfoText = prioText ?? ""; + gr.CustomValue01 = det.QUAL_INSP ?? ""; + gr.ExpectedDeliveryDate = expDeliverDate; + gr.MPN = (det.MANU_MAT ?? "").Trim(); + gr.SupplierNo = details.PO_HEADER.VENDOR ?? ""; + gr.SupplierName = details.PO_HEADER.VEND_NAME ?? ""; + gr.SupplierItemNo = det.VEND_MAT ?? ""; + gr.StorageLocation = det.STOR_LOC ?? ""; + gr.Schedule = (det.SCHEDULE ?? "").TrimStart('0'); + gr.CustomValue08 = details.PO_HEADER.DOC_TYPE ?? ""; + if (!det.DELETE_IND.Equals("L")) { result.GrDataItems.Add(gr); } + else { _log.Debug($"GetBest: Pos was not qualified for return => {gr}"); } } - expDeliverDate = ConvertSapDateToDateTime(det.ExpectedDeliveryDate, false); - if (det.QUANTITY <= det.QUANTITYPROCESSED) { posIsClosed = true; } - - GetMAKTXfromMATNR_IMPORT getMak = new GetMAKTXfromMATNR_IMPORT(); - getMak.MATNR = det.MATERIAL.Trim(); - GetMAKTXfromMATNR_EXPORT outMak = GetMAKTXfromMATNR(getMak); - ItemText1 = outMak.MAKTX; - - GrDataItem gr = new GrDataItem(); - gr.AcceptedManufacturesLink = cnt.ToString(); - gr.Created = ConvertSapDateToDateTime(details.PO_HEADER.CREATED_ON); - gr.LastUpdate = ConvertSapDateToDateTime(det.CHANGED_ON); - gr.PosIsClosed = posIsClosed; - gr.OrderNo = det.PO_NUMBER; - gr.OrderPos = det.PO_ITEM; - gr.OrderQuantity = det.QUANTITY; - gr.ItemNo = det.MATERIAL.Trim(); - gr.ItemText1 = ItemText1; - gr.ItemNoRef = gr.CustomValue05 = det.PUR_MAT; - gr.OrderPosInfoText = det.ACCTASSCAT; - gr.QuantityProcessed = det.QUANTITYPROCESSED; - gr.QuantityUnit = det.UNIT; - gr.Plant = det.PLANT; - gr.Inspection = inspect; - gr.InspectionInfo = inspectInfo; - gr.Priority = prioChar; - gr.PriorityInfoText = prioText; - gr.CustomValue01 = det.QUAL_INSP; - gr.ExpectedDeliveryDate = expDeliverDate; - gr.MPN = det.MANU_MAT.Trim(); - gr.SupplierNo = details.PO_HEADER.VENDOR; - gr.SupplierName = details.PO_HEADER.VEND_NAME; - gr.SupplierItemNo = det.VEND_MAT; - gr.StorageLocation = det.STOR_LOC; - gr.Schedule = det.SCHEDULE.TrimStart('0'); - gr.CustomValue08 = details.PO_HEADER.DOC_TYPE; - if (!det.DELETE_IND.Equals("L")) { result.GrDataItems.Add(gr); } + if (result.GrDataItems.Count == 0 && !useDetailsAlternative) + { + _log.Debug($"No positions found, will now try alternative GET_DETAILS..."); + result = GetBestellung(poNo, true); + } + } + catch (Exception ex) + { + string ermsg = $"GetBestellung: General Error, please check LOG of ErpConnector!"; + _log.Error(ermsg + $" => {ex}"); + result.ErrorNumber = 900; + result.MessageTechnical = result.MessageShort = ermsg; } - _log.Debug($"Result of GetBestellungen now consists of {result.GrDataItems.Count} GrDataItems and {result.ManufacturerDataItems.Count} ManufactuerDataItems..."); + _log.Debug($"Result of GetBestellung now consists of {result.GrDataItems.Count} GrDataItems and {result.ManufacturerDataItems.Count} ManufacturerDataItems..."); return result; } @@ -193,8 +216,76 @@ namespace CompControl.SapFrameworkConnector //----------------------------------------------------------------------------------------------------------------------------------------------------------------------- + public static ApiResultDefault ExecuteGoodsMovement(GoodsMovementParameters par) + { + ApiResultDefault result = new ApiResultDefault(); + + try + { + if (par == null) { throw new Exception($"GoodsMovementParameters are NULL!!!"); } + _log.Debug($"ExecuteGoodsMovement => Received Item => {par.ToString()}"); + StringBuilder sb = new StringBuilder(); + sb.AppendLine($"\r\nSAP PARAMS GOODSMVT ===>"); + + BAPI_GOODSMVT_CREATE_IMPORT import = new BAPI_GOODSMVT_CREATE_IMPORT(); + import.GOODSMVT_CODE.GM_CODE = par.MovementCode; + + //MAYBE DELETE LATER! + par.UserName = ConfigHelper.SapDefaultUSER; + + BAPI2017_GM_HEAD_01 head = new BAPI2017_GM_HEAD_01(); + head.PR_UNAME = par.UserName; sb.AppendLine($"PR_UNAME: {par.UserName}"); + head.DOC_DATE = ConvertDateTimeToSapTime(DateTime.Now); sb.AppendLine($"DOC_DATE: {ConvertDateTimeToSapTime(DateTime.Now)}"); + head.REF_DOC_NO = par.RefDocNo; sb.AppendLine($"REF_DOC_NO: {par.RefDocNo}"); + head.PSTNG_DATE = par.PostingDate; sb.AppendLine($"PSTNG_DATE: {par.PostingDate}"); + import.GOODSMVT_HEADER = head; + + foreach (GoodMovementItem moveit in par.MoveItems) + { + sb.AppendLine($"\r\nMoveItem:"); + BAPI2017_GM_ITEM_CREATE item = new BAPI2017_GM_ITEM_CREATE(); + item.BATCH = moveit.Batch ?? ""; sb.AppendLine($" BATCH: {item.BATCH ?? ""}"); + item.EXPIRYDATE = moveit.ExpiryDate ?? ""; sb.AppendLine($" EXPIRYDATE: {item.EXPIRYDATE ?? ""}"); + item.MATERIAL = moveit.ItemNo ?? ""; sb.AppendLine($" MATERIAL: {item.MATERIAL ?? ""}"); + item.ITEM_TEXT = moveit.ItemText ?? ""; sb.AppendLine($" ITEM_TEXT: {item.ITEM_TEXT}"); + item.MVT_IND = moveit.MoveIndicator ?? ""; sb.AppendLine($" MVT_IND: {item.MVT_IND}"); + item.MOVE_TYPE = moveit.MoveType ?? ""; sb.AppendLine($" MOVE_TYPE: {item.MOVE_TYPE}"); + item.MOVE_BATCH = moveit.Move_Batch ?? ""; sb.AppendLine($" MOVE_BATCH: {item.MOVE_BATCH}"); + item.MOVE_PLANT = moveit.Move_Plant ?? ""; sb.AppendLine($" MOVE_PLANT: {item.MOVE_PLANT}"); + item.STGE_LOC = moveit.StorageLocation ?? ""; sb.AppendLine($" STGE_LOC: {item.STGE_LOC}"); + item.PO_NUMBER = moveit.OrderNo ?? ""; sb.AppendLine($" PO_NUMBER: {item.PO_NUMBER}"); + item.PO_ITEM = moveit.OrderPos ?? ""; sb.AppendLine($" PO_ITEM: {item.PO_ITEM}"); + item.PLANT = moveit.Plant ?? ""; sb.AppendLine($" PLANT: {item.PLANT}"); + item.ENTRY_QNT = Convert.ToInt32(moveit.Quantity); sb.AppendLine($" ENTRY_QNT: {item.ENTRY_QNT}"); + item.ENTRY_UOM = moveit.QuantityUnit ?? ""; sb.AppendLine($" ENTRY_UOM: {item.ENTRY_UOM}"); + item.SPEC_STOCK = moveit.SpecStock ?? ""; sb.AppendLine($" SPEC_STOCK: {item.SPEC_STOCK ?? ""}"); + item.STCK_TYPE = moveit.StockType ?? ""; sb.AppendLine($" STCK_TYPE: {item.STCK_TYPE}"); + item.VENDOR = moveit.Vendor ?? ""; sb.AppendLine($" VENDOR: {item.VENDOR}"); + import.GOODSMVT_ITEM.Add(item); + } + _log.Debug($"Added {import.GOODSMVT_ITEM.Count} items to GOODSMVT"); + _log.Debug(sb.ToString()); + BAPI_GOODSMVT_CREATE_EXPORT export = BAPI_GOODSMVT_CREATE_WithDirectCommit(import); + //BAPI_TRANSACTION_COMMIT(); + } + catch (Exception ex) + { + string ermsg = $"Could not Execute GoodMovement! => {ex}"; + _log.Error(ermsg); + result.ErrorNumber = 900; + result.MessageShort = ermsg; + } + + return result; + } + + //----------------------------------------------------------------------------------------------------------------------------------------------------------------------- + private static DateTime ConvertSapDateToDateTime(string sapDate, bool delimitersUsed = true) { + if ((sapDate ?? "").Equals("")) { sapDate = "2199-01-01"; } + _log.Debug($"SapDateConversion => Input = '{sapDate}' "); + if (delimitersUsed) //Style: 2022-02-18, mostly gotten from SAP with GetString on DATS { int year = Convert.ToInt32(sapDate.Substring(0, 4)); @@ -386,7 +477,7 @@ namespace CompControl.SapFrameworkConnector fields3.CurrentIndex = 0; fields3.SetValue(0, "MAKTX"); func3.SetValue("QUERY_TABLE", "MAKT"); func3.SetValue("DELIMITER", ";"); - func3.SetValue("USE_ET_DATA_4_RETURN", "0"); + //func3.SetValue("USE_ET_DATA_4_RETURN", "0"); func3.Invoke(dest); //Invoke function at Sap destination IRfcTable rfcTable3 = func3.GetTable("DATA"); //Process return values @@ -412,6 +503,7 @@ namespace CompControl.SapFrameworkConnector { string errorMsg = ""; BAPI_PO_GETDETAIL_EXPORT export = new BAPI_PO_GETDETAIL_EXPORT(); + export.PO_ITEMS = new List(); List poItemBuffer = new List(); @@ -441,19 +533,18 @@ namespace CompControl.SapFrameworkConnector export.PO_HEADER.DOC_TYPE = po_header_struct.GetString("DOC_TYPE"); export.PO_HEADER.VENDOR = po_header_struct.GetString("VENDOR"); export.PO_HEADER.VEND_NAME = po_header_struct.GetString("VEND_NAME"); - if (!(export.PO_HEADER.DOC_TYPE.Equals("MP") || export.PO_HEADER.DOC_TYPE.Equals("MP") || export.PO_HEADER.DOC_TYPE.Equals("MP") || export.PO_HEADER.DOC_TYPE.Equals("ZBRO"))) { } IRfcTable po_items_table = func.GetTable("PO_ITEMS"); foreach (IRfcStructure row in po_items_table) { BAPIEKPO temp = new BAPIEKPO(); - temp.PO_NUMBER = row.GetString("PO_NUMBER").TrimStart('0') ?? ""; - temp.PO_ITEM = row.GetString("PO_ITEM").TrimStart('0') ?? ""; + temp.PO_NUMBER = row.GetString("PO_NUMBER") ?? ""; + temp.PO_ITEM = row.GetString("PO_ITEM") ?? ""; temp.STATUS = row.GetString("STATUS") ?? ""; temp.CHANGED_ON = row.GetString("CHANGED_ON") ?? ""; temp.SHORT_TEXT = row.GetString("SHORT_TEXT") ?? ""; - temp.MATERIAL = row.GetString("MATERIAL").TrimStart('0') ?? ""; - temp.PUR_MAT = row.GetString("PUR_MAT").TrimStart('0') ?? ""; + temp.MATERIAL = row.GetString("MATERIAL") ?? ""; + temp.PUR_MAT = row.GetString("PUR_MAT") ?? ""; temp.QUANTITY = row.GetDecimal("QUANTITY"); temp.UNIT = row.GetString("UNIT") ?? ""; temp.PLANT = row.GetString("PLANT") ?? ""; @@ -466,6 +557,9 @@ namespace CompControl.SapFrameworkConnector temp.STOR_LOC = row.GetString("STORE_LOC") ?? ""; temp.DELETE_IND = row.GetString("DELETE_IND") ?? ""; poItemBuffer.Add(temp); + export.PO_ITEMS.Add(temp); + + _log.Debug($"Received PO_ITEM => NO={temp.PO_NUMBER}, Item={temp.PO_ITEM}, DELETE_IND => {temp.DELETE_IND} Quan={temp.QUANTITY}"); } IRfcTable po_item_hist_total = func.GetTable("PO_ITEM_HISTORY_TOTALS"); @@ -508,6 +602,126 @@ namespace CompControl.SapFrameworkConnector temp.DELIV_UNIT = row.GetString("DELIV_UNIT") ?? ""; export.PO_ITEM_HISTORY.Add(temp); } + + _log.Debug($"BAPI_PO_GETDETAILS: Received {poItemBuffer.Count} PO_ITEMS, {export.PO_ITEM_HISTORY_TOTAL.Count} PO_ITEM_HISTORY_TOTALS, {export.PO_ITEM_HISTORY.Count} PO_ITEM_HISTORY"); + } + catch (Exception ex) { errorMsg += "CI: SAP Other Exception: " + ex; } + } + else { _log.Debug("Error, IMPORT for BAPI_PO_GETDETAILS was NULL! "); } + + if (!errorMsg.Equals("")) { _log.Debug(errorMsg); } + + return export; + } + private static BAPI_PO_GETDETAIL_EXPORT BAPI_PO_GETDETAILS1(BAPI_PO_GETDETAIL_IMPORT import) + { + string errorMsg = ""; + BAPI_PO_GETDETAIL_EXPORT export = new BAPI_PO_GETDETAIL_EXPORT(); + export.PO_ITEMS = new List(); + List poItemBuffer = new List(); + + if (import != null) + { + try + { + RfcDestination dest = RfcDestinationManager.GetDestination(ConfigHelper.ActiveSapDestinationName); + IRfcFunction func = dest.Repository.CreateFunction("BAPI_PO_GETDETAIL1"); //Create Function with BAPI_PO_GETDETAIL1 + func.SetValue("PURCHASEORDER", import.PURCHASEORDER?.Trim().PadLeft(10, '0')); //Set Value to function + + // Set optional parameters for BAPI_PO_GETDETAIL1 + func.SetValue("ACCOUNT_ASSIGNMENT", "X"); + func.SetValue("ITEM_TEXT", "X"); + func.SetValue("HEADER_TEXT", "X"); + func.SetValue("DELIVERY_ADDRESS", "X"); + func.SetValue("VERSION", "X"); + func.SetValue("SERVICES", "X"); + func.SetValue("SERIALNUMBERS", "X"); + func.SetValue("INVOICEPLAN", "X"); + + func.Invoke(dest); //Invoke function at Sap destination + + // Export: POHEADER + IRfcStructure po_header_struct = func.GetStructure("POHEADER"); + export.PO_HEADER.PO_NUMBER = po_header_struct.GetString("PO_NUMBER"); + export.PO_HEADER.CREATED_ON = po_header_struct.GetString("DOC_DATE") ?? ""; + export.PO_HEADER.CREATED_BY = po_header_struct.GetString("CREATED_BY") ?? ""; + export.PO_HEADER.DOC_TYPE = po_header_struct.GetString("DOC_TYPE"); + export.PO_HEADER.VENDOR = po_header_struct.GetString("VENDOR"); + //export.PO_HEADER.VEND_NAME = po_header_struct.GetString("VENDOR_NAME") ?? ""; + + // Tables: POITEM + IRfcTable po_items_table = func.GetTable("POITEM"); + foreach (IRfcStructure row in po_items_table) + { + BAPIEKPO temp = new BAPIEKPO(); + temp.PO_NUMBER = row.GetString("PO_NUMBER")?.TrimStart('0') ?? ""; + temp.PO_ITEM = row.GetString("PO_ITEM")?.TrimStart('0') ?? ""; + temp.STATUS = row.GetString("PO_STATUS") ?? ""; + temp.CHANGED_ON = row.GetString("CHANGED_ON") ?? ""; + temp.SHORT_TEXT = row.GetString("SHORT_TEXT") ?? ""; + temp.MATERIAL = row.GetString("MATERIAL")?.TrimStart('0') ?? ""; + temp.PUR_MAT = row.GetString("PURCHASING_MAT_NO")?.TrimStart('0') ?? ""; + temp.QUANTITY = row.GetDecimal("QUANTITY"); + temp.UNIT = row.GetString("UNIT") ?? ""; + temp.PLANT = row.GetString("PLANT") ?? ""; + temp.MAT_GRP = row.GetString("MATL_GROUP") ?? ""; + temp.ACCTASSCAT = row.GetString("ACCTASSCAT") ?? ""; + temp.QUAL_INSP = row.GetString("QUAL_INSP") ?? ""; + temp.MANU_MAT = row.GetString("MANU_MAT") ?? ""; + temp.MFR_NO = row.GetString("MANUF_NO") ?? ""; + temp.VEND_MAT = row.GetString("VENDOR_MATERIAL_NO") ?? ""; + temp.STOR_LOC = row.GetString("STORAGE_LOCATION") ?? ""; + temp.DELETE_IND = row.GetString("DELETE_IND") ?? ""; + poItemBuffer.Add(temp); + export.PO_ITEMS.Add(temp); + + _log.Debug($"Received PO_ITEM => NO={temp.PO_NUMBER}, Item={temp.PO_ITEM}, DELETE_IND => {temp.DELETE_IND} Quan={temp.QUANTITY}"); + } + + // Tables: POHISTORY_TOTALS + IRfcTable po_item_hist_total = func.GetTable("POHISTORY_TOTALS"); + foreach (IRfcStructure row in po_item_hist_total) + { + BAPIEKBES temp = new BAPIEKBES(); + temp.BLOCKED_QY = row.GetDecimal("BLOCKED_QTY"); + temp.BL_QTY = row.GetDecimal("BL_QTY"); + temp.BL_QTY_TOTAL = row.GetDecimal("BL_QTY_TOTAL"); + temp.DELIV_QTY = row.GetDecimal("DELIVERY_QTY"); + temp.DL_QTY_TOTAL = row.GetDecimal("DL_QTY_TOTAL"); + temp.DL_QTY_TRSP = row.GetDecimal("DL_QTY_TRSP"); + temp.IV_QTY = row.GetDecimal("INVOICE_QTY"); + temp.IV_QTY_TOTAL = row.GetDecimal("IV_QTY_TOTAL"); + temp.PO_ITEM = row.GetString("PO_ITEM")?.TrimStart('0') ?? ""; + temp.PO_PR_QNT = row.GetDecimal("ORDER_QTY"); + temp.SERIAL_NO = row.GetString("SERIAL_NO")?.TrimStart('0') ?? ""; + temp.WITHDR_QTY = row.GetDecimal("WITHDRAWAL_QTY"); + export.PO_ITEM_HISTORY_TOTAL.Add(temp); + } + + // Tables: POHISTORY + IRfcTable po_item_hist = func.GetTable("POHISTORY"); + foreach (IRfcStructure row in po_item_hist) + { + BAPIEKBE temp = new BAPIEKBE(); + temp.BATCH = row.GetString("BATCH") ?? ""; + temp.DOC_YEAR = row.GetString("DOC_YEAR") ?? ""; + temp.MATDOC_ITM = row.GetString("MATDOC_ITM") ?? ""; + temp.MATERIAL = row.GetString("MATERIAL") ?? ""; + temp.MAT_DOC = row.GetString("MATDOC_NO") ?? ""; + temp.MOVE_TYPE = row.GetString("MOVE_TYPE") ?? ""; + temp.PO_ITEM = row.GetString("PO_ITEM") ?? ""; + temp.PROCESS_ID = row.GetString("PROCESS_ID") ?? ""; + temp.PSTNG_DATE = row.GetString("POSTING_DATE") ?? ""; + temp.PUR_MAT = row.GetString("PURCHASING_MATERIAL") ?? ""; + temp.QUANTITY = row.GetDecimal("QUANTITY"); + temp.REF_DOC_NO = row.GetString("REF_DOC_NO") ?? ""; + temp.SERIAL_NO = row.GetString("SERIAL_NO") ?? ""; + temp.DELIV_QTY = row.GetDecimal("DELIVERY_QTY"); + temp.DELIV_UNIT = row.GetString("DELIVERY_UNIT") ?? ""; + export.PO_ITEM_HISTORY.Add(temp); + } + + _log.Debug($"BAPI_PO_GETDETAIL1: Received {poItemBuffer.Count} POITEM, {export.PO_ITEM_HISTORY_TOTAL.Count} POHISTORY_TOTALS, {export.PO_ITEM_HISTORY.Count} POHISTORY"); } catch (Exception ex) { errorMsg += "CI: SAP Other Exception: " + ex; } } @@ -788,135 +1002,135 @@ namespace CompControl.SapFrameworkConnector return export; } - private static BAPI_MATERIAL_GETALL_EXPORT BAPI_MATERIAL_GETALL(BAPI_MATERIAL_GETALL_IMPORT import) - { - string errorMsg = ""; - BAPI_MATERIAL_GETALL_EXPORT export = new BAPI_MATERIAL_GETALL_EXPORT(); + //private static BAPI_MATERIAL_GETALL_EXPORT BAPI_MATERIAL_GETALL(BAPI_MATERIAL_GETALL_IMPORT import) + //{ + // string errorMsg = ""; + // BAPI_MATERIAL_GETALL_EXPORT export = new BAPI_MATERIAL_GETALL_EXPORT(); - try - { - RfcDestination dest = RfcDestinationManager.GetDestination(ConfigHelper.ActiveSapDestinationName); - IRfcFunction func = dest.Repository.CreateFunction("BAPI_MATERIAL_GETALL"); //Create Function - func.SetValue("MATERIAL", import.MATERIAL?.Trim().PadLeft(18, '0')); //Set Value to function - if (!import.WAREHOUSENUMBER.Equals(string.Empty)) { func.SetValue("WAREHOUSENUMBER", import.WAREHOUSENUMBER?.Trim().PadLeft(3, '0')); } //Set Value to function - func.Invoke(dest); //Invoke function at Sap destination + // try + // { + // RfcDestination dest = RfcDestinationManager.GetDestination(ConfigHelper.ActiveSapDestinationName); + // IRfcFunction func = dest.Repository.CreateFunction("BAPI_MATERIAL_GETALL"); //Create Function + // func.SetValue("MATERIAL", import.MATERIAL?.Trim().PadLeft(18, '0')); //Set Value to function + // if (!import.WAREHOUSENUMBER.Equals(string.Empty)) { func.SetValue("WAREHOUSENUMBER", import.WAREHOUSENUMBER?.Trim().PadLeft(3, '0')); } //Set Value to function + // func.Invoke(dest); //Invoke function at Sap destination - IRfcStructure clientdata_struct = func.GetStructure("CLIENTDATA"); - export.CLIENTDATA.MATERIAL = clientdata_struct.GetString("MATERIAL"); - export.CLIENTDATA.MATL_TYPE = clientdata_struct.GetString("MATL_TYPE"); - export.CLIENTDATA.CREATED_ON = clientdata_struct.GetString("CREATED_ON"); - export.CLIENTDATA.LAST_CHNGE = clientdata_struct.GetString("LAST_CHNGE"); - export.CLIENTDATA.CREATED_BY = clientdata_struct.GetString("CREATED_BY"); - export.CLIENTDATA.CHANGED_BY = clientdata_struct.GetString("CHANGED_BY"); - export.CLIENTDATA.MATL_GROUP = clientdata_struct.GetString("MATL_GROUP"); - export.CLIENTDATA.BASE_UOM = clientdata_struct.GetString("BASE_UOM"); - export.CLIENTDATA.BASE_UOM_ISO = clientdata_struct.GetString("BASE_UOM_ISO"); - export.CLIENTDATA.SHELF_LIFE = clientdata_struct.GetString("SHELF_LIFE"); - export.CLIENTDATA.PUR_STATUS = clientdata_struct.GetString("PUR_STATUS"); - export.CLIENTDATA.MANU_MAT = clientdata_struct.GetString("MANU_MAT"); - export.CLIENTDATA.MFR_NO = clientdata_struct.GetString("MFR_NO"); - _log.Debug($"CLIENTDATA: MATERIAL={export.CLIENTDATA.MATERIAL} | MFR:{export.CLIENTDATA.MFR_NO}"); + // IRfcStructure clientdata_struct = func.GetStructure("CLIENTDATA"); + // export.CLIENTDATA.MATERIAL = clientdata_struct.GetString("MATERIAL"); + // export.CLIENTDATA.MATL_TYPE = clientdata_struct.GetString("MATL_TYPE"); + // export.CLIENTDATA.CREATED_ON = clientdata_struct.GetString("CREATED_ON"); + // export.CLIENTDATA.LAST_CHNGE = clientdata_struct.GetString("LAST_CHNGE"); + // export.CLIENTDATA.CREATED_BY = clientdata_struct.GetString("CREATED_BY"); + // export.CLIENTDATA.CHANGED_BY = clientdata_struct.GetString("CHANGED_BY"); + // export.CLIENTDATA.MATL_GROUP = clientdata_struct.GetString("MATL_GROUP"); + // export.CLIENTDATA.BASE_UOM = clientdata_struct.GetString("BASE_UOM"); + // export.CLIENTDATA.BASE_UOM_ISO = clientdata_struct.GetString("BASE_UOM_ISO"); + // export.CLIENTDATA.SHELF_LIFE = clientdata_struct.GetString("SHELF_LIFE"); + // export.CLIENTDATA.PUR_STATUS = clientdata_struct.GetString("PUR_STATUS"); + // export.CLIENTDATA.MANU_MAT = clientdata_struct.GetString("MANU_MAT"); + // export.CLIENTDATA.MFR_NO = clientdata_struct.GetString("MFR_NO"); + // _log.Debug($"CLIENTDATA: MATERIAL={export.CLIENTDATA.MATERIAL} | MFR:{export.CLIENTDATA.MFR_NO}"); - IRfcStructure plantdata_struct = func.GetStructure("PLANTDATA"); - export.PLANTDATA.PLANT = plantdata_struct.GetString("PLANT"); + // IRfcStructure plantdata_struct = func.GetStructure("PLANTDATA"); + // export.PLANTDATA.PLANT = plantdata_struct.GetString("PLANT"); - IRfcStructure storedata_struct = func.GetStructure("STORAGELOCATIONDATA"); - export.STORAGELOCATIONDATA.STGE_LOC = storedata_struct.GetString("STGE_LOC"); - export.STORAGELOCATIONDATA.PLANT = storedata_struct.GetString("PLANT"); + // IRfcStructure storedata_struct = func.GetStructure("STORAGELOCATIONDATA"); + // export.STORAGELOCATIONDATA.STGE_LOC = storedata_struct.GetString("STGE_LOC"); + // export.STORAGELOCATIONDATA.PLANT = storedata_struct.GetString("PLANT"); - IRfcStructure warehouse_struct = func.GetStructure("WAREHOUSENUMBERDATA"); - export.WAREHOUSENUMBERDATA.WHSE_NO = warehouse_struct.GetString("WHSE_NO"); - export.WAREHOUSENUMBERDATA.LEQ_UNIT_1 = warehouse_struct.GetString("LEQ_UNIT_1"); - export.WAREHOUSENUMBERDATA.LEQ_UNIT_1_ISO = warehouse_struct.GetString("LEQ_UNIT_1_ISO"); - export.WAREHOUSENUMBERDATA.LEQ_UNIT_2 = warehouse_struct.GetString("LEQ_UNIT_2"); - export.WAREHOUSENUMBERDATA.LEQ_UNIT_2_ISO = warehouse_struct.GetString("LEQ_UNIT_2_ISO"); - export.WAREHOUSENUMBERDATA.LEQ_UNIT_3 = warehouse_struct.GetString("LEQ_UNIT_3"); - export.WAREHOUSENUMBERDATA.LEQ_UNIT_3_ISO = warehouse_struct.GetString("LEQ_UNIT_3_ISO"); - export.WAREHOUSENUMBERDATA.L_EQUIP_1 = warehouse_struct.GetString("L_EQUIP_1"); - export.WAREHOUSENUMBERDATA.L_EQUIP_2 = warehouse_struct.GetString("L_EQUIP_2"); - export.WAREHOUSENUMBERDATA.L_EQUIP_3 = warehouse_struct.GetString("L_EQUIP_3"); - export.WAREHOUSENUMBERDATA.PLACEMENT = warehouse_struct.GetString("PLACEMENT"); //Cicor: If KA1 or KA5 => reserve LeNum - _log.Debug("Placement: " + export.WAREHOUSENUMBERDATA.PLACEMENT); - export.WAREHOUSENUMBERDATA.UNITTYPE_1 = warehouse_struct.GetString("UNITTYPE_1"); - export.WAREHOUSENUMBERDATA.UNITTYPE_2 = warehouse_struct.GetString("UNITTYPE_2"); - export.WAREHOUSENUMBERDATA.UNITTYPE_3 = warehouse_struct.GetString("UNITTYPE_3"); + // IRfcStructure warehouse_struct = func.GetStructure("WAREHOUSENUMBERDATA"); + // export.WAREHOUSENUMBERDATA.WHSE_NO = warehouse_struct.GetString("WHSE_NO"); + // export.WAREHOUSENUMBERDATA.LEQ_UNIT_1 = warehouse_struct.GetString("LEQ_UNIT_1"); + // export.WAREHOUSENUMBERDATA.LEQ_UNIT_1_ISO = warehouse_struct.GetString("LEQ_UNIT_1_ISO"); + // export.WAREHOUSENUMBERDATA.LEQ_UNIT_2 = warehouse_struct.GetString("LEQ_UNIT_2"); + // export.WAREHOUSENUMBERDATA.LEQ_UNIT_2_ISO = warehouse_struct.GetString("LEQ_UNIT_2_ISO"); + // export.WAREHOUSENUMBERDATA.LEQ_UNIT_3 = warehouse_struct.GetString("LEQ_UNIT_3"); + // export.WAREHOUSENUMBERDATA.LEQ_UNIT_3_ISO = warehouse_struct.GetString("LEQ_UNIT_3_ISO"); + // export.WAREHOUSENUMBERDATA.L_EQUIP_1 = warehouse_struct.GetString("L_EQUIP_1"); + // export.WAREHOUSENUMBERDATA.L_EQUIP_2 = warehouse_struct.GetString("L_EQUIP_2"); + // export.WAREHOUSENUMBERDATA.L_EQUIP_3 = warehouse_struct.GetString("L_EQUIP_3"); + // export.WAREHOUSENUMBERDATA.PLACEMENT = warehouse_struct.GetString("PLACEMENT"); //Cicor: If KA1 or KA5 => reserve LeNum + // _log.Debug("Placement: " + export.WAREHOUSENUMBERDATA.PLACEMENT); + // export.WAREHOUSENUMBERDATA.UNITTYPE_1 = warehouse_struct.GetString("UNITTYPE_1"); + // export.WAREHOUSENUMBERDATA.UNITTYPE_2 = warehouse_struct.GetString("UNITTYPE_2"); + // export.WAREHOUSENUMBERDATA.UNITTYPE_3 = warehouse_struct.GetString("UNITTYPE_3"); - IRfcStructure salesdata_struct = func.GetStructure("SALESDATA"); - export.SALESDATA.SALES_ORG = salesdata_struct.GetString("SALES_ORG"); - export.SALESDATA.DISTR_CHAN = salesdata_struct.GetString("DISTR_CHAN"); - _log.Debug($"SALESSATA: ORG={export.SALESDATA.SALES_ORG} | CHAIN:{export.SALESDATA.DISTR_CHAN}"); + // IRfcStructure salesdata_struct = func.GetStructure("SALESDATA"); + // export.SALESDATA.SALES_ORG = salesdata_struct.GetString("SALES_ORG"); + // export.SALESDATA.DISTR_CHAN = salesdata_struct.GetString("DISTR_CHAN"); + // _log.Debug($"SALESSATA: ORG={export.SALESDATA.SALES_ORG} | CHAIN:{export.SALESDATA.DISTR_CHAN}"); - IRfcTable materialdescription_table = func.GetTable("MATERIALDESCRIPTION"); - _log.Debug($"MAT_GET_ALL: found {materialdescription_table.Count} rows in MATERIALDESCRIPTION"); - foreach (IRfcStructure row in materialdescription_table) - { - BAPI_MAKT_GA temp = new BAPI_MAKT_GA(); - temp.LANGU = row.GetString("LANGU"); - temp.LANGU_ISO = row.GetString("LANGU_ISO"); - temp.MATL_DESC = row.GetString("MATL_DESC"); - if (ConfigHelper.SapLanguage.Equals(temp.LANGU_ISO)) - { - export.MATERIALDESCRIPTION.Add(temp); - _log.Debug($"MATDESC: LANG={temp.LANGU}|{temp.LANGU_ISO} | MATL_DESC:{temp.MATL_DESC}"); - } - } + // IRfcTable materialdescription_table = func.GetTable("MATERIALDESCRIPTION"); + // _log.Debug($"MAT_GET_ALL: found {materialdescription_table.Count} rows in MATERIALDESCRIPTION"); + // foreach (IRfcStructure row in materialdescription_table) + // { + // BAPI_MAKT_GA temp = new BAPI_MAKT_GA(); + // temp.LANGU = row.GetString("LANGU"); + // temp.LANGU_ISO = row.GetString("LANGU_ISO"); + // temp.MATL_DESC = row.GetString("MATL_DESC"); + // if (ConfigHelper.SapLanguage.Equals(temp.LANGU_ISO)) + // { + // export.MATERIALDESCRIPTION.Add(temp); + // _log.Debug($"MATDESC: LANG={temp.LANGU}|{temp.LANGU_ISO} | MATL_DESC:{temp.MATL_DESC}"); + // } + // } - IRfcTable materialtext_table = func.GetTable("MATERIALTEXT"); - _log.Debug($"MAT_GET_ALL: found {materialtext_table.Count} rows in MATERIALTEXT"); - foreach (IRfcStructure row in materialtext_table) - { - BAPI_MLTX_GA temp = new BAPI_MLTX_GA(); - temp.APPLOBJECT = row.GetString("APPLOBJECT"); - temp.FORMAT_COL = row.GetString("FORMAT_COL"); - temp.LANGU = row.GetString("LANGU"); - temp.LANGU_ISO = row.GetString("LANGU_ISO"); - temp.TEXT_ID = row.GetString("TEXT_ID"); - temp.TEXT_LINE = row.GetString("TEXT_LINE"); - temp.TEXT_NAME = row.GetString("TEXT_NAME"); - if (ConfigHelper.SapLanguage.Equals(temp.LANGU_ISO)) - { - export.MATERIALTEXT.Add(temp); - _log.Debug($"MAT_GET_ALL MATTXT: APPLOBJ={temp.APPLOBJECT} | FORMATCOL:{temp.FORMAT_COL} | LANG:{temp.LANGU}|{temp.LANGU_ISO} | TEXT:{temp.TEXT_ID}|{temp.TEXT_LINE}|{temp.TEXT_NAME}"); - } - } + // IRfcTable materialtext_table = func.GetTable("MATERIALTEXT"); + // _log.Debug($"MAT_GET_ALL: found {materialtext_table.Count} rows in MATERIALTEXT"); + // foreach (IRfcStructure row in materialtext_table) + // { + // BAPI_MLTX_GA temp = new BAPI_MLTX_GA(); + // temp.APPLOBJECT = row.GetString("APPLOBJECT"); + // temp.FORMAT_COL = row.GetString("FORMAT_COL"); + // temp.LANGU = row.GetString("LANGU"); + // temp.LANGU_ISO = row.GetString("LANGU_ISO"); + // temp.TEXT_ID = row.GetString("TEXT_ID"); + // temp.TEXT_LINE = row.GetString("TEXT_LINE"); + // temp.TEXT_NAME = row.GetString("TEXT_NAME"); + // if (ConfigHelper.SapLanguage.Equals(temp.LANGU_ISO)) + // { + // export.MATERIALTEXT.Add(temp); + // _log.Debug($"MAT_GET_ALL MATTXT: APPLOBJ={temp.APPLOBJECT} | FORMATCOL:{temp.FORMAT_COL} | LANG:{temp.LANGU}|{temp.LANGU_ISO} | TEXT:{temp.TEXT_ID}|{temp.TEXT_LINE}|{temp.TEXT_NAME}"); + // } + // } - IRfcTable extension_table = func.GetTable("EXTENSIONOUT"); - _log.Debug($"MAT_GET_ALL: found {extension_table.Count} rows in EXTENSIONOUT"); - foreach (IRfcStructure row in extension_table) - { - BAPIPAREX temp = new BAPIPAREX(); - temp.STRUCTURE = row.GetString("STRUCTURE"); - temp.VALUEPART1 = row.GetString("VALUEPART1"); - temp.VALUEPART2 = row.GetString("VALUEPART2"); - temp.VALUEPART3 = row.GetString("VALUEPART3"); - temp.VALUEPART4 = row.GetString("VALUEPART4"); - export.EXTENSIONOUT.Add(temp); - _log.Debug($"MAT_GET_ALL EXTENSIONOUT: STRUCT={temp.STRUCTURE} | VAL1:{temp.VALUEPART1} | VAL2:{temp.VALUEPART2}"); - } + // IRfcTable extension_table = func.GetTable("EXTENSIONOUT"); + // _log.Debug($"MAT_GET_ALL: found {extension_table.Count} rows in EXTENSIONOUT"); + // foreach (IRfcStructure row in extension_table) + // { + // BAPIPAREX temp = new BAPIPAREX(); + // temp.STRUCTURE = row.GetString("STRUCTURE"); + // temp.VALUEPART1 = row.GetString("VALUEPART1"); + // temp.VALUEPART2 = row.GetString("VALUEPART2"); + // temp.VALUEPART3 = row.GetString("VALUEPART3"); + // temp.VALUEPART4 = row.GetString("VALUEPART4"); + // export.EXTENSIONOUT.Add(temp); + // _log.Debug($"MAT_GET_ALL EXTENSIONOUT: STRUCT={temp.STRUCTURE} | VAL1:{temp.VALUEPART1} | VAL2:{temp.VALUEPART2}"); + // } - IRfcTable return_table = func.GetTable("RETURN"); - _log.Debug($"MAT_GET_ALL: found {return_table.Count} rows in RETURN"); - foreach (IRfcStructure row in return_table) - { - BAPIRETURN temp = new BAPIRETURN(); - temp.CODE = row.GetString("CODE"); - temp.LOG_MSG_NO = row.GetString("LOG_MSG_NO"); - temp.LOG_NO = row.GetString("LOG_NO"); - temp.MESSAGE = row.GetString("MESSAGE"); - temp.MESSAGE_V1 = row.GetString("MESSAGE_V1"); - temp.MESSAGE_V2 = row.GetString("MESSAGE_V2"); - temp.MESSAGE_V3 = row.GetString("MESSAGE_V3"); - temp.MESSAGE_V4 = row.GetString("MESSAGE_V4"); - export.RETURN.Add(temp); - _log.Debug($"MAT_GET_ALL RETURN: Code={temp.CODE} | Msg:{temp.MESSAGE}"); - } - } - catch (Exception ex) { errorMsg += "CI: SAP Other Exception: " + ex; } + // IRfcTable return_table = func.GetTable("RETURN"); + // _log.Debug($"MAT_GET_ALL: found {return_table.Count} rows in RETURN"); + // foreach (IRfcStructure row in return_table) + // { + // BAPIRETURN temp = new BAPIRETURN(); + // temp.CODE = row.GetString("CODE"); + // temp.LOG_MSG_NO = row.GetString("LOG_MSG_NO"); + // temp.LOG_NO = row.GetString("LOG_NO"); + // temp.MESSAGE = row.GetString("MESSAGE"); + // temp.MESSAGE_V1 = row.GetString("MESSAGE_V1"); + // temp.MESSAGE_V2 = row.GetString("MESSAGE_V2"); + // temp.MESSAGE_V3 = row.GetString("MESSAGE_V3"); + // temp.MESSAGE_V4 = row.GetString("MESSAGE_V4"); + // export.RETURN.Add(temp); + // _log.Debug($"MAT_GET_ALL RETURN: Code={temp.CODE} | Msg:{temp.MESSAGE}"); + // } + // } + // catch (Exception ex) { errorMsg += "CI: SAP Other Exception: " + ex; } - if (!errorMsg.Equals("")) { _log.Debug(errorMsg); } + // if (!errorMsg.Equals("")) { _log.Debug(errorMsg); } - return export; - } + // return export; + //} private static BAPI_BATCH_CREATE_EXPORT BAPI_BATCH_CREATE(BAPI_BATCH_CREATE_IMPORT import) { @@ -1022,14 +1236,15 @@ namespace CompControl.SapFrameworkConnector try { RfcDestination dest = RfcDestinationManager.GetDestination(ConfigHelper.ActiveSapDestinationName); - IRfcFunction func = dest.Repository.CreateFunction("Z_CMP_GOODSMVT_CREATE"); + IRfcFunction func = dest.Repository.CreateFunction("BAPI_GOODSMVT_CREATE"); IRfcStructure goodsmvt_header = func.GetStructure("GOODSMVT_HEADER"); goodsmvt_header.SetValue("DOC_DATE", import.GOODSMVT_HEADER.DOC_DATE); goodsmvt_header.SetValue("PR_UNAME", import.GOODSMVT_HEADER.PR_UNAME); goodsmvt_header.SetValue("PSTNG_DATE", import.GOODSMVT_HEADER.PSTNG_DATE); goodsmvt_header.SetValue("REF_DOC_NO", import.GOODSMVT_HEADER.REF_DOC_NO); - goodsmvt_header.SetValue("VER_GR_GI_SLIP", "2"); - goodsmvt_header.SetValue("VER_GR_GI_SLIPX", "X"); + //goodsmvt_header.SetValue("ELIKZ", " "); + //goodsmvt_header.SetValue("VER_GR_GI_SLIP", "2"); + //goodsmvt_header.SetValue("VER_GR_GI_SLIPX", "X"); func.GetStructure("GOODSMVT_CODE").SetValue("GM_CODE", import.GOODSMVT_CODE.GM_CODE); IRfcTable goodsmvt_item = func.GetTable("GOODSMVT_ITEM"); @@ -1037,28 +1252,29 @@ namespace CompControl.SapFrameworkConnector foreach (BAPI2017_GM_ITEM_CREATE item in import.GOODSMVT_ITEM) { goodsmvt_item.Append(); - goodsmvt_item.SetValue("BATCH", item.BATCH); - goodsmvt_item.SetValue("DELIV_ITEM", item.DELIV_ITEM); - goodsmvt_item.SetValue("DELIV_NUMB", item.DELIV_NUMB); - goodsmvt_item.SetValue("ENTRY_QNT", item.ENTRY_QNT); - goodsmvt_item.SetValue("ENTRY_UOM", item.ENTRY_UOM); - goodsmvt_item.SetValue("ENTRY_UOM_ISO", item.ENTRY_UOM_ISO); - goodsmvt_item.SetValue("EXPIRYDATE", item.EXPIRYDATE); - goodsmvt_item.SetValue("ITEM_TEXT", item.ITEM_TEXT); - goodsmvt_item.SetValue("MATERIAL", item.MATERIAL); - goodsmvt_item.SetValue("MOVE_BATCH", item.MOVE_BATCH); - goodsmvt_item.SetValue("MOVE_PLANT", item.MOVE_PLANT); - goodsmvt_item.SetValue("MOVE_STLOC", item.MOVE_STLOC); - goodsmvt_item.SetValue("MOVE_TYPE", item.MOVE_TYPE); - goodsmvt_item.SetValue("MVT_IND", item.MVT_IND); - goodsmvt_item.SetValue("NO_TRANSFER_REQ", item.NO_TRANSFER_REQ); - goodsmvt_item.SetValue("PLANT", item.PLANT); - goodsmvt_item.SetValue("PO_ITEM", item.PO_ITEM); - goodsmvt_item.SetValue("PO_NUMBER", item.PO_NUMBER); - goodsmvt_item.SetValue("SPEC_STOCK", item.SPEC_STOCK); - goodsmvt_item.SetValue("STCK_TYPE", item.STCK_TYPE); - goodsmvt_item.SetValue("STGE_LOC", item.STGE_LOC); - goodsmvt_item.SetValue("VENDOR", item.VENDOR); + //goodsmvt_header.SetValue("NO_MORE_GR", " "); + if (item.DELIV_ITEM != null && !item.BATCH.Trim().Equals("")) { goodsmvt_item.SetValue("BATCH", item.BATCH); } + if (item.DELIV_ITEM != null && !item.DELIV_ITEM.Trim().Equals("")) { goodsmvt_item.SetValue("DELIV_ITEM", item.DELIV_ITEM); } + if (item.DELIV_NUMB != null && !item.DELIV_NUMB.Trim().Equals("")) { goodsmvt_item.SetValue("DELIV_NUMB", item.DELIV_NUMB); } + goodsmvt_item.SetValue("ENTRY_QNT", item.ENTRY_QNT); + if (item.ENTRY_UOM != null && !item.ENTRY_UOM.Trim().Equals("")) { goodsmvt_item.SetValue("ENTRY_UOM", item.ENTRY_UOM); } + if (item.ENTRY_UOM_ISO != null && !item.ENTRY_UOM_ISO.Trim().Equals("")) { goodsmvt_item.SetValue("ENTRY_UOM_ISO", item.ENTRY_UOM_ISO); } + if (item.EXPIRYDATE != null && !item.EXPIRYDATE.Trim().Equals("")) { goodsmvt_item.SetValue("EXPIRYDATE", item.EXPIRYDATE); } + if (item.ITEM_TEXT != null && !item.ITEM_TEXT.Trim().Equals("")) { goodsmvt_item.SetValue("ITEM_TEXT", item.ITEM_TEXT); } + if (item.MATERIAL != null && !item.MATERIAL.Trim().Equals("")) { goodsmvt_item.SetValue("MATERIAL", item.MATERIAL); } + if (item.MOVE_BATCH != null && !item.MOVE_BATCH.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_BATCH", item.MOVE_BATCH); } + if (item.MOVE_PLANT != null && !item.MOVE_PLANT.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_PLANT", item.MOVE_PLANT); } + if (item.MOVE_STLOC != null && !item.MOVE_STLOC.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_STLOC", item.MOVE_STLOC); } + if (item.MOVE_TYPE != null && !item.MOVE_TYPE.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_TYPE", item.MOVE_TYPE); } + if (item.MVT_IND != null && !item.MVT_IND.Trim().Equals("")) { goodsmvt_item.SetValue("MVT_IND", item.MVT_IND); } + if (item.NO_TRANSFER_REQ != null && !item.NO_TRANSFER_REQ.Trim().Equals("")) { goodsmvt_item.SetValue("NO_TRANSFER_REQ", item.NO_TRANSFER_REQ); } + if (item.PLANT != null && !item.PLANT.Trim().Equals("")) { goodsmvt_item.SetValue("PLANT", item.PLANT); } + if (item.PO_ITEM != null && !item.PO_ITEM.Trim().Equals("")) { goodsmvt_item.SetValue("PO_ITEM", item.PO_ITEM.PadLeft(5, '0')); } + if (item.PO_NUMBER != null && !item.PO_NUMBER.Trim().Equals("")) { goodsmvt_item.SetValue("PO_NUMBER", item.PO_NUMBER); } + if (item.SPEC_STOCK != null && !item.SPEC_STOCK.Trim().Equals("")) { goodsmvt_item.SetValue("SPEC_STOCK", item.SPEC_STOCK); } + if (item.STCK_TYPE != null && !item.STCK_TYPE.Trim().Equals("")) { goodsmvt_item.SetValue("STCK_TYPE", item.STCK_TYPE); } + if (item.STGE_LOC != null && !item.STGE_LOC.Trim().Equals("")) { goodsmvt_item.SetValue("STGE_LOC", item.STGE_LOC); } + if (item.VENDOR != null && !item.VENDOR.Trim().Equals("")) { goodsmvt_item.SetValue("VENDOR", item.VENDOR); } _log.Debug($"GOODSMVT: Will transmit reel => MATERIAL:{item.MATERIAL}, QNT:{item.ENTRY_QNT}"); } func.Invoke(dest); @@ -1090,8 +1306,68 @@ namespace CompControl.SapFrameworkConnector _log.Debug($"Return ({temp.TYPE} | {temp.ID} | NUM:{temp.NUMBER}): " + temp.MESSAGE + $" | V1:{temp.MESSAGE_V1} | V2:{temp.MESSAGE_V2} | V3:{temp.MESSAGE_V3} | V4:{temp.MESSAGE_V4}"); } + } + catch (Exception ex) { errorMsg += "SAP Other Exception: " + ex; export.RETURN.Add(new BAPIRET2() { TYPE = "E", MESSAGE = ex.ToString() }); } - ret_table = func.GetTable("RETURN2"); + if (!errorMsg.Equals("")) { _log.Error(errorMsg); } + + return export; + } + + private static BAPI_GOODSMVT_CREATE_EXPORT BAPI_GOODSMVT_CREATE_WithDirectCommit(BAPI_GOODSMVT_CREATE_IMPORT import) + { + string errorMsg = ""; + BAPI_GOODSMVT_CREATE_EXPORT export = new BAPI_GOODSMVT_CREATE_EXPORT(); + + try + { + RfcDestination dest = RfcDestinationManager.GetDestination(ConfigHelper.ActiveSapDestinationName); + IRfcFunction func = dest.Repository.CreateFunction("BAPI_GOODSMVT_CREATE"); + IRfcStructure goodsmvt_header = func.GetStructure("GOODSMVT_HEADER"); + goodsmvt_header.SetValue("DOC_DATE", import.GOODSMVT_HEADER.DOC_DATE); + goodsmvt_header.SetValue("PR_UNAME", import.GOODSMVT_HEADER.PR_UNAME); + goodsmvt_header.SetValue("PSTNG_DATE", import.GOODSMVT_HEADER.PSTNG_DATE); + goodsmvt_header.SetValue("REF_DOC_NO", import.GOODSMVT_HEADER.REF_DOC_NO); + func.GetStructure("GOODSMVT_CODE").SetValue("GM_CODE", import.GOODSMVT_CODE.GM_CODE); + IRfcTable goodsmvt_item = func.GetTable("GOODSMVT_ITEM"); + + _log.Debug($"GOODSMVT: Will transmit {import.GOODSMVT_ITEM.Count} reels to SAP"); + foreach (BAPI2017_GM_ITEM_CREATE item in import.GOODSMVT_ITEM) + { + goodsmvt_item.Append(); + //goodsmvt_header.SetValue("NO_MORE_GR", " "); + if (item.DELIV_ITEM != null && !item.BATCH.Trim().Equals("")) { goodsmvt_item.SetValue("BATCH", item.BATCH); } + if (item.DELIV_ITEM != null && !item.DELIV_ITEM.Trim().Equals("")) { goodsmvt_item.SetValue("DELIV_ITEM", item.DELIV_ITEM); } + if (item.DELIV_NUMB != null && !item.DELIV_NUMB.Trim().Equals("")) { goodsmvt_item.SetValue("DELIV_NUMB", item.DELIV_NUMB); } + goodsmvt_item.SetValue("ENTRY_QNT", item.ENTRY_QNT); + if (item.ENTRY_UOM != null && !item.ENTRY_UOM.Trim().Equals("")) { goodsmvt_item.SetValue("ENTRY_UOM", item.ENTRY_UOM); } + if (item.ENTRY_UOM_ISO != null && !item.ENTRY_UOM_ISO.Trim().Equals("")) { goodsmvt_item.SetValue("ENTRY_UOM_ISO", item.ENTRY_UOM_ISO); } + if (item.EXPIRYDATE != null && !item.EXPIRYDATE.Trim().Equals("")) { goodsmvt_item.SetValue("EXPIRYDATE", item.EXPIRYDATE); } + if (item.ITEM_TEXT != null && !item.ITEM_TEXT.Trim().Equals("")) { goodsmvt_item.SetValue("ITEM_TEXT", item.ITEM_TEXT); } + if (item.MATERIAL != null && !item.MATERIAL.Trim().Equals("")) { goodsmvt_item.SetValue("MATERIAL", item.MATERIAL); } + if (item.MOVE_BATCH != null && !item.MOVE_BATCH.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_BATCH", item.MOVE_BATCH); } + if (item.MOVE_PLANT != null && !item.MOVE_PLANT.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_PLANT", item.MOVE_PLANT); } + if (item.MOVE_STLOC != null && !item.MOVE_STLOC.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_STLOC", item.MOVE_STLOC); } + if (item.MOVE_TYPE != null && !item.MOVE_TYPE.Trim().Equals("")) { goodsmvt_item.SetValue("MOVE_TYPE", item.MOVE_TYPE); } + if (item.MVT_IND != null && !item.MVT_IND.Trim().Equals("")) { goodsmvt_item.SetValue("MVT_IND", item.MVT_IND); } + if (item.NO_TRANSFER_REQ != null && !item.NO_TRANSFER_REQ.Trim().Equals("")){ goodsmvt_item.SetValue("NO_TRANSFER_REQ", item.NO_TRANSFER_REQ); } + if (item.PLANT != null && !item.PLANT.Trim().Equals("")) { goodsmvt_item.SetValue("PLANT", item.PLANT); } + if (item.PO_ITEM != null && !item.PO_ITEM.Trim().Equals("")) { goodsmvt_item.SetValue("PO_ITEM", item.PO_ITEM); } + if (item.PO_NUMBER != null && !item.PO_NUMBER.Trim().Equals("")) { goodsmvt_item.SetValue("PO_NUMBER", item.PO_NUMBER); } + if (item.SPEC_STOCK != null && !item.SPEC_STOCK.Trim().Equals("")) { goodsmvt_item.SetValue("SPEC_STOCK", item.SPEC_STOCK); } + if (item.STCK_TYPE != null && !item.STCK_TYPE.Trim().Equals("")) { goodsmvt_item.SetValue("STCK_TYPE", item.STCK_TYPE); } + if (item.STGE_LOC != null && !item.STGE_LOC.Trim().Equals("")) { goodsmvt_item.SetValue("STGE_LOC", item.STGE_LOC); } + if (item.VENDOR != null && !item.VENDOR.Trim().Equals("")) { goodsmvt_item.SetValue("VENDOR", item.VENDOR); } + _log.Debug($"GOODSMVT: Will transmit reel => MATERIAL:{item.MATERIAL}, QNT:{item.ENTRY_QNT}"); + } + func.Invoke(dest); + + export.MATDOCUMENTYEAR = func.GetString("MATDOCUMENTYEAR"); + export.MATERIALDOCUMENT = func.GetString("MATERIALDOCUMENT"); + + _log.Debug($"GOODSMVT_CREATE: MATERIALDOCUMENTYEAR={export.MATDOCUMENTYEAR} MATERIALDOCUMENT={export.MATERIALDOCUMENT}"); + + IRfcTable ret_table = func.GetTable("RETURN"); foreach (IRfcStructure row in ret_table) { BAPIRET2 temp = new BAPIRET2(); @@ -1109,41 +1385,89 @@ namespace CompControl.SapFrameworkConnector temp.ROW = ret_table.GetString("ROW"); temp.SYSTEM = ret_table.GetString("SYSTEM"); temp.TYPE = ret_table.GetString("TYPE"); - export.RETURN.Add(temp); //Also add to same return + export.RETURN.Add(temp); - _log.Debug($"Return2 ({temp.TYPE} | {temp.ID} | NUM:{temp.NUMBER}): " + temp.MESSAGE + $" | V1:{temp.MESSAGE_V1} | V2:{temp.MESSAGE_V2} | V3:{temp.MESSAGE_V3} | V4:{temp.MESSAGE_V4}"); + _log.Debug($"Return ({temp.TYPE} | {temp.ID} | NUM:{temp.NUMBER}): " + temp.MESSAGE + $" | V1:{temp.MESSAGE_V1} | V2:{temp.MESSAGE_V2} | V3:{temp.MESSAGE_V3} | V4:{temp.MESSAGE_V4}"); } + + + //--------------------------------------------------------------------------------------------------------------------- + + Thread.Sleep(1000); + IRfcFunction func2 = dest.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT"); + func2.SetValue("WAIT", "X"); + func2.Invoke(dest); + try + { + IRfcStructure ret_table2 = func2.GetStructure("RETURN"); + if (ret_table2 == null) { _log.Debug($"Attention: Return table of BAPI_TRANSACTION_COMMIT is NULL!!!"); } + else + { + BAPIRET2 temp = new BAPIRET2(); + temp.FIELD = ret_table2.GetString("FIELD") ?? ""; + temp.ID = ret_table2.GetString("ID") ?? ""; + temp.LOG_MSG_NO = ret_table2.GetString("LOG_MSG_NO") ?? ""; + temp.LOG_NO = ret_table2.GetString("LOG_NO") ?? ""; + temp.MESSAGE = ret_table2.GetString("MESSAGE") ?? ""; + temp.MESSAGE_V1 = ret_table2.GetString("MESSAGE_V1") ?? ""; + temp.MESSAGE_V2 = ret_table2.GetString("MESSAGE_V2") ?? ""; + temp.MESSAGE_V3 = ret_table2.GetString("MESSAGE_V3") ?? ""; + temp.MESSAGE_V4 = ret_table2.GetString("MESSAGE_V4") ?? ""; + temp.NUMBER = ret_table2.GetString("NUMBER") ?? ""; + temp.PARAMETER = ret_table2.GetString("PARAMETER") ?? ""; + temp.ROW = ret_table2.GetString("ROW") ?? ""; + temp.SYSTEM = ret_table2.GetString("SYSTEM") ?? ""; + temp.TYPE = ret_table2.GetString("TYPE") ?? ""; + export.RETURN.Add(temp); + _log.Debug($"Return of BAPI_TRANSACTION_COMMIT ({temp.TYPE} | {temp.ID} | NUM:{temp.NUMBER}): " + temp.MESSAGE + $" | V1:{temp.MESSAGE_V1} | V2:{temp.MESSAGE_V2} | V3:{temp.MESSAGE_V3} | V4:{temp.MESSAGE_V4}"); + } + } + catch (Exception e) { _log.Error($"Could not load RETURN of BAPI_TRANSACTION_COMMIT => {e}"); } } - catch (Exception ex) { errorMsg += "CI: SAP Other Exception: " + ex; export.RETURN.Add(new BAPIRET2() { TYPE = "E", MESSAGE = ex.ToString() }); } + catch (Exception ex) { errorMsg += "SAP Other Exception: " + ex; export.RETURN.Add(new BAPIRET2() { TYPE = "E", MESSAGE = ex.ToString() }); } if (!errorMsg.Equals("")) { _log.Error(errorMsg); } return export; } - private static NUMBER_GET_NEXT_EXPORT NUMBER_GET_NEXT() + private static BAPI_TRANSACTION_COMMIT_EXPORT BAPI_TRANSACTION_COMMIT() //BAPI_TRANSACTION_COMMIT_IMPORT import ??? { string errorMsg = ""; - NUMBER_GET_NEXT_EXPORT export = new NUMBER_GET_NEXT_EXPORT(); - _log.Debug($"Will try to execute NUMBER_GET_NEXT: Now Z_CMP_GET_NEXT_SU\n"); + BAPI_TRANSACTION_COMMIT_EXPORT export = new BAPI_TRANSACTION_COMMIT_EXPORT(); + _log.Debug($"Will try to execute BAPI_TRANSACTION_COMMIT"); try - { + { RfcDestination dest = RfcDestinationManager.GetDestination(ConfigHelper.ActiveSapDestinationName); - IRfcFunction func = dest.Repository.CreateFunction("Z_CMP_GET_NEXT_SU"); + IRfcFunction func = dest.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT"); + func.SetValue("WAIT", "X"); func.Invoke(dest); - export.NUMBER = func.GetString("E_NUMBER"); - export.QUANTITY = func.GetInt("E_QUANTITY"); - export.RETURNCODE = func.GetString("RETURNCODE"); - - StringBuilder ms = new StringBuilder(); - ms.Append($"Results of NUMBER_GET_NEXT:\n"); - ms.Append($"E_NUMBER: {export.NUMBER}\n"); - ms.Append($"RETURNCODE: {export.RETURNCODE}"); - _log.Debug(ms.ToString()); + try + { + IRfcStructure ret_table = func.GetStructure("RETURN"); + BAPIRET2 temp = new BAPIRET2(); + temp.FIELD = ret_table.GetString("FIELD"); + temp.ID = ret_table.GetString("ID"); + temp.LOG_MSG_NO = ret_table.GetString("LOG_MSG_NO"); + temp.LOG_NO = ret_table.GetString("LOG_NO"); + temp.MESSAGE = ret_table.GetString("MESSAGE"); + temp.MESSAGE_V1 = ret_table.GetString("MESSAGE_V1"); + temp.MESSAGE_V2 = ret_table.GetString("MESSAGE_V2"); + temp.MESSAGE_V3 = ret_table.GetString("MESSAGE_V3"); + temp.MESSAGE_V4 = ret_table.GetString("MESSAGE_V4"); + temp.NUMBER = ret_table.GetString("NUMBER"); + temp.PARAMETER = ret_table.GetString("PARAMETER"); + temp.ROW = ret_table.GetString("ROW"); + temp.SYSTEM = ret_table.GetString("SYSTEM"); + temp.TYPE = ret_table.GetString("TYPE"); + export.RETURN.Add(temp); + _log.Debug($"Return of BAPI_TRANSACTION_COMMIT ({temp.TYPE} | {temp.ID} | NUM:{temp.NUMBER}): " + temp.MESSAGE + $" | V1:{temp.MESSAGE_V1} | V2:{temp.MESSAGE_V2} | V3:{temp.MESSAGE_V3} | V4:{temp.MESSAGE_V4}"); + } + catch (Exception e) { _log.Error($"Could not load RETURN of BAPI_TRANSACTION_COMMIT => {e}"); } } - catch (Exception ex) { errorMsg += "CI: SAP Other Exception: " + ex; } + catch (Exception ex) { errorMsg += "SAP Other Exception: " + ex; } if (!errorMsg.Equals("")) { _log.Debug(errorMsg); } diff --git a/CompControl.SapFrameworkConnector/Standard/StandardApiController.cs b/CompControl.SapFrameworkConnector/Standard/StandardApiController.cs index 65e899b..7382fc6 100644 --- a/CompControl.SapFrameworkConnector/Standard/StandardApiController.cs +++ b/CompControl.SapFrameworkConnector/Standard/StandardApiController.cs @@ -4,7 +4,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using System.Web.Http; -using CompControl.ErpConnector.Service.Models; +using CompControl.ErpConnector.Utility.Models; namespace CompControl.SapFrameworkConnector @@ -23,7 +23,7 @@ namespace CompControl.SapFrameworkConnector try { - SapStandardFunctions.GetBestellung(filterBestellungen.OrderNo); + result = SapStandardFunctions.GetBestellung(filterBestellungen.OrderNo); if (result.IsSuccessful) { _log.Debug(result); } //Action was successful => log for debug else { _log.Error(result); } //An error occurred @@ -52,7 +52,7 @@ namespace CompControl.SapFrameworkConnector try { - SapStandardFunctions.GetHerstellerdaten(itemNo); + result = SapStandardFunctions.GetHerstellerdaten(itemNo); if (result.IsSuccessful) { _log.Debug(result); } //Action was successful => log for debug else { _log.Error(result); } //An error occurred @@ -130,5 +130,35 @@ namespace CompControl.SapFrameworkConnector return Request.CreateResponse(HttpStatusCode.OK, result); } + + [Route("goodsmovement")] + [HttpPut] + public async Task ExecuteGoodsMovement([FromBody] SAP_CompControl_Models.GoodsMovementParameters par, CancellationToken cancellationToken) + { + ApiResultDefault result = new ApiResultDefault(); //New ApiResult to return via Web + _log.Debug("ExecuteGoodsMovement received "); + + try + { + result = SapStandardFunctions.ExecuteGoodsMovement(par); + + if (result.IsSuccessful) { _log.Debug(result); } //Action was successful => log for debug + else { _log.Error(result); } //An error occurred + } + catch (Exception ex) + { + string sm = $"ExecuteGoodsMovement: An unexpected error occured => " + ex; + _log.Error(sm); + result = new ApiResultDefault //Default ApiResult on error + { + ErrorNumber = 101, + MessageShort = sm, + MessageLong = sm, + MessageTechnical = $"{sm} [] - {ex}" + }; + } + + return Request.CreateResponse(HttpStatusCode.OK, result); + } } } diff --git a/CompControl.SapFrameworkConnector/packages.config b/CompControl.SapFrameworkConnector/packages.config index 09a5b87..94bc7f7 100644 --- a/CompControl.SapFrameworkConnector/packages.config +++ b/CompControl.SapFrameworkConnector/packages.config @@ -1,18 +1,116 @@  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file