GBS now working!
This commit is contained in:
@@ -6,6 +6,8 @@ using System.Text;
|
|||||||
using static CompControl.ErpConnector.Utility.Models.SAP_CompControl_Models;
|
using static CompControl.ErpConnector.Utility.Models.SAP_CompControl_Models;
|
||||||
using static CompControl.ErpConnector.Utility.Models.SAP_BAPI_Models;
|
using static CompControl.ErpConnector.Utility.Models.SAP_BAPI_Models;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
//using System.Text.Json;
|
||||||
|
|
||||||
namespace CompControl.SapFrameworkConnector
|
namespace CompControl.SapFrameworkConnector
|
||||||
{
|
{
|
||||||
@@ -17,6 +19,7 @@ namespace CompControl.SapFrameworkConnector
|
|||||||
public static ApiResultBestellungen GetBestellung(string poNo, bool useDetailsAlternative = false)
|
public static ApiResultBestellungen GetBestellung(string poNo, bool useDetailsAlternative = false)
|
||||||
{
|
{
|
||||||
ApiResultBestellungen result = new ApiResultBestellungen();
|
ApiResultBestellungen result = new ApiResultBestellungen();
|
||||||
|
ApiResultBestellungen resultSAG = new ApiResultBestellungen();
|
||||||
BAPI_PO_GETDETAIL_IMPORT import = new BAPI_PO_GETDETAIL_IMPORT() { PURCHASEORDER = poNo, ITEMS = "X" };
|
BAPI_PO_GETDETAIL_IMPORT import = new BAPI_PO_GETDETAIL_IMPORT() { PURCHASEORDER = poNo, ITEMS = "X" };
|
||||||
BAPI_PO_GETDETAIL_EXPORT details = new BAPI_PO_GETDETAIL_EXPORT();
|
BAPI_PO_GETDETAIL_EXPORT details = new BAPI_PO_GETDETAIL_EXPORT();
|
||||||
if (useDetailsAlternative) { details = BAPI_PO_GETDETAILS1(import); _log.Debug($"using BAPI_PO_GETDETAILS-1 !!!"); }
|
if (useDetailsAlternative) { details = BAPI_PO_GETDETAILS1(import); _log.Debug($"using BAPI_PO_GETDETAILS-1 !!!"); }
|
||||||
@@ -100,33 +103,54 @@ namespace CompControl.SapFrameworkConnector
|
|||||||
result.MessageTechnical = result.MessageShort = ermsg;
|
result.MessageTechnical = result.MessageShort = ermsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==> MAYBE NEVER NEEDED: Lieferplan is also delivered with PO_DETAILS with sufficient rights
|
try
|
||||||
//if (result.GrDataItems.Count == 0) //If no Items were found take a look at SAG instead of PO
|
{
|
||||||
//{
|
BAPI_SAG_GETDETAIL_IMPORT sagInput = new BAPI_SAG_GETDETAIL_IMPORT();
|
||||||
// _log.Debug($"Could not find any PO Items, will now try and search for SAG '{poNo}'");
|
sagInput.PURCHASINGDOCUMENT = poNo;
|
||||||
// try
|
sagInput.SHIPPING_DATA = "X";
|
||||||
// {
|
sagInput.SCHEDULE_DATA = "X";
|
||||||
// BAPI_SAG_GETDETAIL_IMPORT sagInput = new BAPI_SAG_GETDETAIL_IMPORT();
|
sagInput.ITEM_DATA = "X";
|
||||||
// sagInput.PURCHASINGDOCUMENT = poNo;
|
BAPI_SAG_GETDETAIL_EXPORT sagDetails = BAPI_SAG_GETDETAIL(sagInput);
|
||||||
// sagInput.SHIPPING_DATA = "X";
|
|
||||||
// sagInput.SCHEDULE_DATA = "X";
|
|
||||||
// sagInput.ITEM_DATA = "X";
|
|
||||||
// BAPI_SAG_GETDETAIL_EXPORT sagDetails = BAPI_SAG_GETDETAIL(sagInput);
|
|
||||||
|
|
||||||
// //TODO: Add logic if RFC works!
|
//TODO: Add logic if RFC works!
|
||||||
// //foreach ()
|
if (sagDetails.SCHEDULE.Count > 0) //Only if any Items were returned!
|
||||||
// //{
|
{
|
||||||
|
List<GrDataItem> newGrList = new List<GrDataItem>();
|
||||||
|
foreach (GrDataItem gr in result.GrDataItems)
|
||||||
|
{
|
||||||
|
bool atLeastOnePosFound = false;
|
||||||
|
foreach (BAPIMEOUTSCHEDULE schedule in sagDetails.SCHEDULE)
|
||||||
|
{
|
||||||
|
GrDataItem grCopy = JsonConvert.DeserializeObject<GrDataItem>(JsonConvert.SerializeObject(gr)); //Kopierpfusch
|
||||||
|
|
||||||
// //}
|
if (schedule.ITEM_NO.Equals(gr.OrderPos))
|
||||||
// }
|
{
|
||||||
// catch (Exception ex)
|
_log.Debug($"Matching SAGSCHEDULE => PosNo={schedule.ITEM_NO}, SchedLine={schedule.SCHED_LINE}, Qty={schedule.QUANTITY}, Date={schedule.DELIVERY_DATE}");
|
||||||
// {
|
|
||||||
// string ermsg = $"GetBestellung SAG: General Error, please check LOG of ErpConnector!";
|
if (schedule.DELIVERY_DATE.Trim().Equals("")) { schedule.DELIVERY_DATE = "01.01.2199"; }
|
||||||
// _log.Error(ermsg + $" => {ex}");
|
string day = schedule.DELIVERY_DATE.Substring(0, 2);
|
||||||
// result.ErrorNumber = 900;
|
string month = schedule.DELIVERY_DATE.Substring(3, 2);
|
||||||
// result.MessageTechnical = result.MessageShort = ermsg;
|
string year = schedule.DELIVERY_DATE.Substring(6, 4);
|
||||||
// }
|
DateTime delDate = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day));
|
||||||
//}
|
|
||||||
|
grCopy.OrderQuantity = schedule.QUANTITY;
|
||||||
|
grCopy.Schedule = schedule.SCHED_LINE;
|
||||||
|
grCopy.ExpectedDeliveryDate = delDate;
|
||||||
|
newGrList.Add(grCopy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.GrDataItems = newGrList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string ermsg = $"GetBestellung SAG: General Error, please check LOG of ErpConnector!";
|
||||||
|
_log.Error(ermsg + $" => {ex}");
|
||||||
|
result.ErrorNumber = 900;
|
||||||
|
result.MessageTechnical = result.MessageShort = ermsg;
|
||||||
|
}
|
||||||
|
|
||||||
_log.Debug($"Result of GetBestellung now consists of {result.GrDataItems.Count} GrDataItems and {result.ManufacturerDataItems.Count} ManufacturerDataItems...");
|
_log.Debug($"Result of GetBestellung now consists of {result.GrDataItems.Count} GrDataItems and {result.ManufacturerDataItems.Count} ManufacturerDataItems...");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user