namespace TM.Bosman.Transforms {
    
    
    [Microsoft.XLANGs.BaseTypes.SchemaReference(@"TM.Shared.Schemas.OrderStatus", typeof(global::TM.Shared.Schemas.OrderStatus))]
    [Microsoft.XLANGs.BaseTypes.SchemaReference(@"TM.Bosman.Schemas.EFACT_D96A_IFTSTA_BOSMAN", typeof(global::TM.Bosman.Schemas.EFACT_D96A_IFTSTA_BOSMAN))]
    public sealed class TM_Shared_OrderStatus_to_TM_Bosman_IFTSTA : global::Microsoft.XLANGs.BaseTypes.TransformBase {
        
        private const string _strMap = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0""
                xmlns:ScriptNS0=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS0""
                xmlns:ScriptNS1=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS1""
                
                xmlns:DateTime=""TM.Shared.Components.DateTime""
                xmlns:SSO=""TM.Shared.Components.SSO""
                xmlns:String=""TM.Shared.Components.String""

                xmlns:s0=""http://TM.KLG.com/KLG/OrderStatus""
                xmlns:ns0=""http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006""
                 
                exclude-result-prefixes=""s0 ns0 ScriptNS0 ScriptNS1 DateTime SSO String"">
  
  <xsl:output omit-xml-declaration=""yes"" method=""xml"" version=""1.0"" indent=""yes"" />

  <!-- Region global variable initialization -->

  <!-- region connectionString -->
  <xsl:variable name=""connectionString"" select=""SSO:GetValue('TM.Bosman', 'ESBLookupConnectionString2016')""/>
  <!-- end region -->

  <!-- end region -->

  <!-- region templates -->

  <xsl:template match=""/"">
    <xsl:apply-templates select=""/s0:StatusReport"" />
  </xsl:template>

  <xsl:template match=""/s0:StatusReport"">

    <ns0:EFACT_D96A_IFTSTA_BOSMAN>
      <UNH>
        <UNH1>
          <xsl:value-of select=""DateTime:FormatDateTime(TimeStamp, 'yyyy-MM-ddTHH:mm:ss', 'yyyyMMddHHmmss')"" />
        </UNH1>
        <UNH2>
          <UNH2.1>IFTSTA</UNH2.1>
          <UNH2.2>D</UNH2.2>
          <UNH2.3>96A</UNH2.3>
          <UNH2.4>UN</UNH2.4>
          <UNH2.5>EAN002</UNH2.5>
        </UNH2>
      </UNH>
      <ns0:BGM>
        <!-- Max length of BGM02 is 35 -->
        <BGM02>
          <xsl:value-of select=""substring(/s0:StatusReport/Status/ShipmentReference,1,35)""/>
        </BGM02>
      </ns0:BGM>
      <ns0:DTM>
        <ns0:C507>
          <C50701>137</C50701>
          <C50702>
            <xsl:value-of select=""DateTime:FormatDateTime(TimeStamp, 'yyyy-MM-ddTHH:mm:ss', 'yyyyMMdd')"" />
          </C50702>
          <C50703>102</C50703>
        </ns0:C507>
      </ns0:DTM>
      <ns0:CNILoop1>
        <ns0:CNI>
          <!-- Momenteel bevat Shared.Status maximaal 1 bericht -->
          <CNI01>1</CNI01>
          <ns0:C503>
            <C50301>
              <xsl:choose>
                <xsl:when test=""contains(/s0:StatusReport/Status/ShipmentReference,'/')"">
                  <xsl:value-of select=""normalize-space(substring-after(/s0:StatusReport/Status/ShipmentReference,'/'))""/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select=""/s0:StatusReport/Status/ShipmentReference""/>
                </xsl:otherwise>
              </xsl:choose>
            </C50301>
          </ns0:C503>
        </ns0:CNI>
        <ns0:STSLoop1>
          <ns0:STS>
            <ns0:C601>
              <C60101>1</C60101>
            </ns0:C601>
            <ns0:C555>
              <C55501>
                <xsl:variable name=""status"">
                  <xsl:choose>
                    <xsl:when test=""ScriptNS0:DBValueExtract(string(ScriptNS0:DBLookup(0, /s0:StatusReport/Status/StatusCode, $connectionString, 'TM_Bosman_StatusCode', 'KLG')), 'Bosman') != ''"">
                      <xsl:value-of select=""ScriptNS0:DBValueExtract(string(ScriptNS0:DBLookup(0, /s0:StatusReport/Status/StatusCode, $connectionString, 'TM_Bosman_StatusCode', 'KLG')), 'Bosman')"" />
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select=""/s0:StatusReport/Status/StatusCode""/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:variable>
                <xsl:value-of select=""$status""/>
              </C55501>
            </ns0:C555>
          </ns0:STS>
          <ns0:DTM_3>
            <ns0:C507_3>
              <C50701>334</C50701>
              <xsl:choose>
                <xsl:when test=""String:Left(Status/StatusTimeStamp,1)>'0'"">
                  <C50702>
                    <xsl:value-of select=""DateTime:FormatDateTime(Status/StatusTimeStamp, 'yyyy-MM-ddTHH:mm:ss', 'yyyyMMddHHmm')"" />
                  </C50702>
                  <C50703>203</C50703>
                </xsl:when>
                <xsl:otherwise>
                  <C50702>000101010000</C50702>
                  <C50703>102</C50703>
                </xsl:otherwise>
              </xsl:choose>
            </ns0:C507_3>
          </ns0:DTM_3>
        </ns0:STSLoop1>
      </ns0:CNILoop1>
      <UNT>
        <UNT1>0</UNT1>
        <UNT2>
          <xsl:value-of select=""DateTime:FormatDateTime(TimeStamp, 'yyyy-MM-ddTHH:mm:ss', 'yyyyMMddHHmmss')"" />
        </UNT2>
      </UNT>
      
    </ns0:EFACT_D96A_IFTSTA_BOSMAN>
  </xsl:template>
  

  <!-- end region -->

  <xsl:variable name=""dbClose"" select=""ScriptNS0:DBLookupShutdown()""/>

</xsl:stylesheet>";
        
        private const int _useXSLTransform = 0;
        
        private const string _strArgList = @"<ExtensionObjects>
  <ExtensionObject Namespace=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS0"" 
                   AssemblyName=""Microsoft.BizTalk.BaseFunctoids, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
                   ClassName=""Microsoft.BizTalk.BaseFunctoids.FunctoidScripts"" />
  <ExtensionObject Namespace=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS1"" 
                   AssemblyName=""Microsoft.BizTalk.CrossReferencing, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
                   ClassName=""Microsoft.BizTalk.CrossReferencing.CrossReferencing"" />

  <ExtensionObject Namespace=""TM.Shared.Components.Biztalk""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.BiztalkFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.DateTime""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.DateTimeFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.KeyList""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.KeyListFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.SSO""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.SSOFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.String""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.StringFunctions"" />

  <ExtensionObject Namespace=""TM.Bosman.Components.MSsql""
                   AssemblyName=""TM.Bosman.Components, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ef8f53020aeb0dca""
                   ClassName=""TM.Bosman.Components.MSsql"" />
  <ExtensionObject Namespace=""TM.Bosman.Components.Logging""
                   AssemblyName=""TM.Bosman.Components, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ef8f53020aeb0dca""
                   ClassName=""TM.Bosman.Components.Logging"" />

</ExtensionObjects>";
        
        private const string _strSrcSchemasList0 = @"TM.Shared.Schemas.OrderStatus";
        
        private const global::TM.Shared.Schemas.OrderStatus _srcSchemaTypeReference0 = null;
        
        private const string _strTrgSchemasList0 = @"TM.Bosman.Schemas.EFACT_D96A_IFTSTA_BOSMAN";
        
        private const global::TM.Bosman.Schemas.EFACT_D96A_IFTSTA_BOSMAN _trgSchemaTypeReference0 = null;
        
        public override string XmlContent {
            get {
                return _strMap;
            }
        }
        
        public override int UseXSLTransform {
            get {
                return _useXSLTransform;
            }
        }
        
        public override string XsltArgumentListContent {
            get {
                return _strArgList;
            }
        }
        
        public override string[] SourceSchemas {
            get {
                string[] _SrcSchemas = new string [1];
                _SrcSchemas[0] = @"TM.Shared.Schemas.OrderStatus";
                return _SrcSchemas;
            }
        }
        
        public override string[] TargetSchemas {
            get {
                string[] _TrgSchemas = new string [1];
                _TrgSchemas[0] = @"TM.Bosman.Schemas.EFACT_D96A_IFTSTA_BOSMAN";
                return _TrgSchemas;
            }
        }
    }
}
