Include (KZLibrary, KZISSetup)
///
Projekt: KZIS
///
Author : M. Brousek
///
Created: 29.4.2010
///
Description: Třída BO pro volání metod WS Clienta služby ZNeOSAll systému SAP.
/// Služba je určena pro přenos dat číselníků, primárně udržovaných v systému SAP.
Class KZIS.BO.SAP.ZNEOSALL Extends Ens.BusinessOperation [ ProcedureBlock ]
{
Parameter ADAPTER = "EnsLib.SOAP.OutboundAdapter";
/// Inicializace WS, přiřazení URL podle nastavení uloženého v Setupu (globals).
/// V tomto nastavení lze určit jeden ze tří možných serverů, na kterých jsou systém SAP a příslušné služby instalovány.
/// Viz též KZIS.MW.Setup
Method InitImport()
{
Set ..Adapter.WebServiceClientClass = "KZIS.WS.Client.SAP.ZNEOSALL"
Set ..Adapter.WebServiceURL = $$$SAPZNeOSAllURL
}
/// Dokončení zpracování aktuální úlohy
Method DoneImport()
{
}
Method ParseCostCenterItem(ByRef pItem As KZIS.WS.Client.SAP.tns.ZINVITEM, ByRef pRow As KZIS.Data.DS.CostCenter)
{
if ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.KOD")
{
set pRow.Number = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.NAZEV")
{
set pRow.ShortName = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.HIERARCHIE")
{
set pRow.ParentNo = $E(pItem.PARVA, 1, 10)
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.VEDOUCI")
{
set pRow.Official = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.DRUH")
{
set pRow.Kind = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.INV_USEK")
{
set pRow.InvDept = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.PLATNE_DO")
{
set pRow.ValidFrom = $$$SAPToDate(pItem.PARVA)
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAP_STREDISKO.PLATNE_OD")
{
set pRow.ValidTo = $$$SAPToDate(pItem.PARVA)
}
}
Method ParseMaterialGroupItem(ByRef pItem As KZIS.WS.Client.SAP.tns.ZINVITEM, ByRef pRow As KZIS.Data.DS.MaterialGroup)
{
//$$$LOGINFO("ParNa: "_$ZCONVERT(pItem.PARNA,"U")_"; ParVa: "_pItem.PARVA)
if ($ZCONVERT(pItem.PARNA,"U") = "SAPSKUP_MAT.KOD")
{
set pRow.Number = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAPSKUP_MAT.NAZEV")
{
set pRow.Name = pItem.PARVA
}
}
Method ParseVendorItem(ByRef pItem As KZIS.WS.Client.SAP.tns.ZINVITEM, ByRef pRow As KZIS.Data.DS.Vendor)
{
if ($ZCONVERT(pItem.PARNA,"U") = "SAPSUPPLIER.KOD")
{
set pRow.Number = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAPSUPPLIER.NAZEV")
{
set pRow.Name = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "")
{
set pRow.State = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SADROBEC")
{
set pRow.City = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SADRULICE")
{
set pRow.Street = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SADRPOP")
{
set pRow.HouseNo = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SADRPSC")
{
set pRow.ZipCode = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "")
{
set pRow.ICO = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "")
{
set pRow.DIC = pItem.PARVA
}
elseif ($ZCONVERT(pItem.PARNA,"U") = "SAPSUPPLIER.AKTIVNI")
{
set pRow.Active = $$$SAPToBoolean(pItem.PARVA)
}
}
Method KZCostCentersOUT(pRequest As KZIS.Msg.MW.BODataRequest, Output pResponse As KZIS.Msg.MW.CommonDataResponse) As %Library.Status
{
$$$LOGINFO("Starting operation: 'ZNeOSAll.KZCostCentersOUT'. SAP IFCode: "_$$$SAPIFCode)
Set tSC = ..Adapter.InvokeMethod("KZCostCentersOUT",.ETHEADERS,$$$SAPIFCode,"CCEN_FULL",pRequest.Transaction.TransactionID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set pResponse = ##class(KZIS.Msg.MW.CommonDataResponse).%New()
Quit:'$ISOBJECT(pResponse) $$$ERROR($$$GeneralError,"Error creating ZNeOSAll service Response")
Set pResponse.Transaction = pRequest.Transaction
$$$LOGINFO("Operation: 'ZNeOSAll.KZCostCentersOUT', saving data. RecCount: "_ETITEMS.Count())
//Save response to DS
set tCurrentRec = ""
set tItemsCount = ETITEMS.Count()
for i=1:1:tItemsCount
{
set tItem = ETITEMS.GetAt(i)
if (tCurrentRec = "") || (tItem.OBJID '= tCurrentRec.ObjID)
{
if (tCurrentRec '= "")
{
set tSC = tCurrentRec.%Save()
if $$$ISERR(tSC)
{
throw $$$KZISError("BO ZNeOSAll.CostCentersOUT error:", "Error saving new rec")
}
}
set tCurrentRec = ##class(KZIS.Data.DS.CostCenter).%New()
set tCurrentRec.ObjID = tItem.OBJID
set tCurrentRec.Transaction = pRequest.Transaction
}
do ..ParseCostCenterItem(.tItem, .tCurrentRec)
}
if (tCurrentRec '= "")
{
set tSC = tCurrentRec.%Save()
if $$$ISERR(tSC)
{
throw $$$KZISError("BO ZNeOSAll.CostCentersOUT error:", "Error saving new rec")
}
}
$$$LOGINFO("Operation: 'ZNeOSAll.KZCostCentersOUT' finished")
set tSC = $$$OK
Quit tSC
}
Method KZMaterialGroupsOUT(pRequest As KZIS.Msg.MW.BODataRequest, Output pResponse As KZIS.Msg.MW.CommonDataResponse) As %Library.Status
{
$$$LOGINFO("Starting operation: 'ZNeOSAll.KZMaterialGroupsOUT'. SAP IFCode: "_$$$SAPIFCode)
Set tSC = ..Adapter.InvokeMethod("KZMaterialGroupsOUT",.ETHEADERS,$$$SAPIFCode,"SR04",pRequest.Transaction.TransactionID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set pResponse = ##class(KZIS.Msg.MW.CommonDataResponse).%New()
Quit:'$ISOBJECT(pResponse) $$$ERROR($$$GeneralError,"Error creating ZNeOSAll service Response")
Set pResponse.Transaction = pRequest.Transaction
$$$LOGINFO("Operation: 'ZNeOSAll.KZMaterialGroupsOUT', saving data. RecCount: "_ETITEMS.Count())
//Save response to DS
set tCurrentRec = ""
set tItemsCount = ETITEMS.Count()
for i=1:1:tItemsCount
{
set tItem = ETITEMS.GetAt(i)
if (tCurrentRec = "") || (tItem.OBJID '= tCurrentRec.ObjID)
{
if (tCurrentRec '= "")
{
set tCurrentRec.Category = ##class(KZIS.Data.DS.MatGroupXBookingClass).GetBClassNoByMGoupNumber(tCurrentRec.Number)
set tSC = tCurrentRec.%Save()
if $$$ISERR(tSC)
{
throw $$$KZISError("BO ZNeOSAll.MaterialGroupsOUT error:", "Error saving new rec")
}
}
set tCurrentRec = ##class(KZIS.Data.DS.MaterialGroup).%New()
set tCurrentRec.ObjID = tItem.OBJID
set tCurrentRec.Transaction = pRequest.Transaction
}
do ..ParseMaterialGroupItem(.tItem, .tCurrentRec)
}
if (tCurrentRec '= "")
{
set tSC = tCurrentRec.%Save()
if $$$ISERR(tSC)
{
throw $$$KZISError("BO ZNeOSAll.MaterialGroupsOUT error:", "Error saving new rec")
}
}
$$$LOGINFO("Operation: 'ZNeOSAll.KZMaterialGroupsOUT' finished")
set tSC = $$$OK
Quit tSC
}
Method KZVendorsOUT(pRequest As KZIS.Msg.MW.BODataRequest, Output pResponse As KZIS.Msg.MW.CommonDataResponse) As %Library.Status
{
$$$LOGINFO("Starting operation: 'ZNeOSAll.KZVendorsOUT'. SAP IFCode: "_$$$SAPIFCode)
Set tSC = ..Adapter.InvokeMethod("KZVendorsOUT",.ETHEADERS,$$$SAPIFCode,"SR06",pRequest.Transaction.TransactionID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set pResponse = ##class(KZIS.Msg.MW.CommonDataResponse).%New()
Quit:'$ISOBJECT(pResponse) $$$ERROR($$$GeneralError,"Error creating ZNeOSAll service Response")
Set pResponse.Transaction = pRequest.Transaction
$$$LOGINFO("Operation: 'ZNeOSAll.KZVendorsOUT', saving data. RecCount: "_ETITEMS.Count())
//Save response to DS
set tCurrentRec = ""
set tItemsCount = ETITEMS.Count()
for i=1:1:tItemsCount
{
set tItem = ETITEMS.GetAt(i)
if (tCurrentRec = "") || (tItem.OBJID '= tCurrentRec.ObjID)
{
if (tCurrentRec '= "")
{
set tSC = tCurrentRec.%Save()
if $$$ISERR(tSC)
{
throw $$$KZISError("BO ZNeOSAll.VendorsOUT error:", "Error saving new rec")
}
}
set tCurrentRec = ##class(KZIS.Data.DS.Vendor).%New()
set tCurrentRec.ObjID = tItem.OBJID
set tCurrentRec.Transaction = pRequest.Transaction
}
do ..ParseMaterialGroupItem(.tItem, .tCurrentRec)
}
if (tCurrentRec '= "")
{
set tSC = tCurrentRec.%Save()
if $$$ISERR(tSC)
{
throw $$$KZISError("BO ZNeOSAll.VendorsOUT error:", "Error saving new rec")
}
}
$$$LOGINFO("Operation: 'ZNeOSAll.KZVendorsOUT' finished")
set tSC = $$$OK
Quit tSC
}
Method KZMaterialMasterIN(pRequest As KZIS.Msg.SAP.ZNeOSAllRequest.KZMaterialMasterINRequest, Output pResponse As KZIS.Msg.SAP.ZNeOSAllResponse.KZMaterialMasterINResponse) As %Library.Status
{
Set tSC = ..Adapter.InvokeMethod("KZMaterialMasterIN",.ETHEADERS,pRequest.ITHEADERS,pRequest.ITITEMS,pRequest.IFCODE,pRequest.ITRANSID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set tSC = pRequest.NewResponse(.pResponse) Quit:$$$ISERR(tSC) tSC
Set pResponse.ETHEADERS=ETHEADERS,pResponse.ETITEMS = ETITEMS,pResponse.ETRETURN = ETRETURN
Quit $$$OK
}
Method KZPurchaseOrdersHistoryOUT(pRequest As KZIS.Msg.SAP.ZNeOSAllRequest.KZPurchaseOrdersHistoryOUTRequest, Output pResponse As KZIS.Msg.SAP.ZNeOSAllResponse.KZPurchaseOrdersHistoryOUTResponse) As %Library.Status
{
Set tSC = ..Adapter.InvokeMethod("KZPurchaseOrdersHistoryOUT",.ETHEADERS,pRequest.ITHEADERS,pRequest.ITITEMS,pRequest.IFCODE,pRequest.ITRANSID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set tSC = pRequest.NewResponse(.pResponse) Quit:$$$ISERR(tSC) tSC
Set pResponse.ETHEADERS=ETHEADERS,pResponse.ETITEMS = ETITEMS,pResponse.ETRETURN = ETRETURN
Quit $$$OK
}
Method KZPurchaseOrdersNeOSIN(pRequest As KZIS.Msg.SAP.ZNeOSAllRequest.KZPurchaseOrdersNeOSINRequest, Output pResponse As KZIS.Msg.SAP.ZNeOSAllResponse.KZPurchaseOrdersNeOSINResponse) As %Library.Status
{
Set tSC = ..Adapter.InvokeMethod("KZPurchaseOrdersNeOSIN",.ETHEADERS,pRequest.ITHEADERS,pRequest.ITITEMS,pRequest.IFCODE,pRequest.ITRANSID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set tSC = pRequest.NewResponse(.pResponse) Quit:$$$ISERR(tSC) tSC
Set pResponse.ETHEADERS=ETHEADERS,pResponse.ETITEMS = ETITEMS,pResponse.ETRETURN = ETRETURN
Quit $$$OK
}
Method KZUnitGroupsOUT(pRequest As KZIS.Msg.SAP.ZNeOSAllRequest.KZUnitGroupsOUTRequest, Output pResponse As KZIS.Msg.SAP.ZNeOSAllResponse.KZUnitGroupsOUTResponse) As %Library.Status
{
Set tSC = ..Adapter.InvokeMethod("KZUnitGroupsOUT",.ETHEADERS,pRequest.IFCODE,pRequest.IINTID,pRequest.ITRANSID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set tSC = pRequest.NewResponse(.pResponse) Quit:$$$ISERR(tSC) tSC
Set pResponse.ETHEADERS=ETHEADERS,pResponse.ETITEMS = ETITEMS,pResponse.ETRETURN = ETRETURN
Quit $$$OK
}
Method KZUnitsOUT(pRequest As KZIS.Msg.SAP.ZNeOSAllRequest.KZUnitsOUTRequest, Output pResponse As KZIS.Msg.SAP.ZNeOSAllResponse.KZUnitsOUTResponse) As %Library.Status
{
Set tSC = ..Adapter.InvokeMethod("KZUnitsOUT",.ETHEADERS,pRequest.IFCODE,pRequest.IINTID,pRequest.ITRANSID,.ETITEMS,.ETRETURN) Quit:$$$ISERR(tSC) tSC
Set tSC = pRequest.NewResponse(.pResponse) Quit:$$$ISERR(tSC) tSC
Set pResponse.ETHEADERS=ETHEADERS,pResponse.ETITEMS = ETITEMS,pResponse.ETRETURN = ETRETURN
Quit $$$OK
}
Method DispatchServiceRequest(pRequest As KZIS.Msg.MW.BODataRequest, Output pResponse As KZIS.Msg.MW.CommonDataResponse) As %Library.Status
{
Quit:'$ISOBJECT(pRequest) $$$ERROR($$$GeneralError,"BO SAP.ZNeOSAll error: 'Request missing'")
Quit:'$ISOBJECT(pRequest.Transaction) $$$ERROR($$$GeneralError,"BO SAP.ZNeOSAll error: 'Transaction missing'")
TRY
{
do ..InitImport()
if pRequest.Transaction.Kind.Code = $$$tkcSAPCostCenters
{
do ..KZCostCentersOUT(pRequest, pResponse)
}
elseif pRequest.Transaction.Kind.Code = $$$tkcSAPMaterialGroups
{
do ..KZMaterialGroupsOUT(pRequest, pResponse)
}
elseif pRequest.Transaction.Kind.Code = $$$tkcSAPVendors
{
do ..KZVendorsOUT(pRequest, pResponse)
}
else
{
throw $$$KZISError("BO SAP.ZNeOSAll error:", "Invalid transaction kind code")
}
set pResponse = ##class(KZIS.Msg.MW.CommonDataResponse).%New()
set pResponse.Transaction = pRequest.Transaction
do ..DoneImport()
$$$LOGINFO("BO SAP.ZNeOSAll: '"_pRequest.Transaction.Kind.Description_"' finished")
set tSC = $$$OK
}
CATCH E
{
$$$LOGERROR("BO SAP.ZNeOSAll error: 'Exception("_E.Location_": "_E.Name_" - "_E.Data_")'")
set tSC = $$$ERROR($$$GeneralError)
}
Quit tSC
}
XData MessageMap
{
DispatchServiceRequest
}
}