<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ef="urn:DGFIP:EtatsFrais" 
    xmlns:inv="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
    xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    xmlns:dgfip="urn:DGFIP:EtatFrais:OrdreMission" 
    version="1.0">

    <xsl:output encoding="ISO-8859-1" method="html" indent="yes"/>
    
    <xsl:variable name="pays" select="document('./resources/iso_3166-1_list_fr.xml')"/>
    <xsl:variable name="SituationsFamille" select="document('./resources/situationsFamiliales.xml')"/>
    <xsl:variable name="TypesFrais" select="document('./resources/typesFrais.xml')"/>
    <xsl:variable name="TypesEtatFrais" select="document('./resources/typesEtatFrais.xml')"/>
    <xsl:variable name="NaturesOM" select="document('./resources/naturesOM.xml')"/>
    
    <xsl:decimal-format name="decformat" decimal-separator="," grouping-separator=" " digit="#" pattern-separator=";" NaN="NaN" minus-sign="-"> </xsl:decimal-format>
    
    <xsl:template match="/">
        <html>
            <head>
                <title>Etat de Frais</title>
                <style type="text/css" media="print">
                    .invoiceDiv {
                        width: 100%;
                    }
                </style>
                <style type="text/css" media="screen">
                    .invoiceDiv {
                        width: 190mm;
                    }
                    th {
                    color: white;
                    background-color: #999999;
                    }
                </style>
                <style type="text/css" media="all">
                    body, p, th, td {
                        font-size: 14;
                    }
                    .titre0 {
                        font-weight: bold;
                        font-family: Arial, Helvetica, sans-serif;
                        font-size: 24;
                    }
                    .center {
                        text-align: center;
                    }
                    .top {
                        vertical-align: top;
                    }
                    .gras {
                        font-weight: bold;
                    }
                    .right {
                        text-align: right;
                    }
                    .bordered {
                        border-style: solid;
                        border-width: 1px;
                        border-color: black;v
                        padding: 10px;
                    }
                    .collapsed {
                        border-collapse: collapse;
                        border-spacing: 0px;
                    }
                    .titre1 {
                        margin-top: 12px;
                        margin-bottom: 0px;
                        font-wieght: bold;
                        font-size: 16;
                    }
                    .nosign {
                        list-style-type: none;
                    }
                </style>
            </head>
            <body>
                <center>
                <xsl:apply-templates/>
                </center>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="//ef:EtatsFrais/ef:Invoice">
        <xsl:variable name="extension" select="./cec:UBLExtensions/cec:UBLExtension[cec:ExtensionURI='DGFIP:EtatFrais:OrdreMission']/cec:ExtensionContent/dgfip:EtatFraisExtension"></xsl:variable>
        <div class="invoiceDiv">
            <table width="100%">
                <colgroup>
                    <col width="33%" style="text-align: center;"/>
                    <col width="34%" style="text-align: center;"/>
                    <col width="33%" style="text-align: center;"/>
                </colgroup>
                <tbody>
                    <tr>
                        <td> </td>
                        <td class="center titre0">ETAT DES FRAIS</td>
                        <td class="top right">OM n° <xsl:value-of select="$extension/dgfip:OrdreMission/dgfip:ID"/><br/>Edf n° <xsl:value-of select="./cbc:ID"/></td>
                    </tr>
                </tbody>
            </table>
            <xsl:variable name="agentExt" select="$extension/dgfip:OrdreMission/dgfip:Agent"/>
            <xsl:variable name="agent" select="./cac:AccountingSupplierParty/cac:Party"/>
            <table width="100%">
                <colgroup>
                    <col width="50%"/>
                    <col width="50%"/>
                </colgroup>
                <tbody>
                    <tr>
                        <td colspan="2">Exposés par <span class="gras"><xsl:if test="$agent/cac:Person/cbc:Title"><xsl:value-of select="concat($agent/cac:Person/cbc:Title/text(),' ')"/> </xsl:if><xsl:value-of select="concat($agent/cac:Person/cbc:FirstName/text(),' ')"/> <xsl:value-of select="$agent/cac:Person/cbc:FamilyName/text()"/></span></td>
                    </tr>
                    <tr>
                        <td>Grade : <span class="gras"><xsl:value-of select="$agentExt/dgfip:Grade"/></span></td>
                        <td>Direction : <span class="gras"><xsl:value-of select="./cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID"/></span></td>
                    </tr>
                    <tr>
                        <td>en résidence à <span class="gras"><xsl:value-of select="$agent/cac:PhysicalLocation/cac:Address/cbc:CityName"/></span></td>
                        <td>à l'occasion d'un déplacement à <span class="gras"><xsl:value-of select="$extension/dgfip:OrdreMission/dgfip:LieuDeplacement/@Commune"/><xsl:if test="string-length($extension/dgfip:OrdreMission/dgfip:LieuDeplacement/@CodPays) &gt; 0"> (<xsl:call-template name="libPays"><xsl:with-param name="cod" select="$extension/dgfip:OrdreMission/dgfip:LieuDeplacement/@CodPays"></xsl:with-param></xsl:call-template>)</xsl:if></span></td>
                    </tr>
                    <td colspan="2">Identifiant <span class="gras"><xsl:value-of select="./cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID"/></span></td>
                </tbody>
            </table>

            <p>&#160;</p>
            
            <table width="100%" style="bordered collapsed" cellpadding="0" cellspacing="0">
                <colgroup>
                    <col width="25%"/>
                    <col width="25%"/>
                    <col width="25%"/>
                    <col width="25%"/>
                </colgroup>
                <thead>
                    <tr>
                        <th class="bordered" colspan="2">Départ de la résidence administrative</th>
                        <th class="bordered" colspan="2">Arrivée à la résidence administrative</th>
                    </tr>
                    <tr>
                        <th class="bordered">Date</th>
                        <th class="bordered">Heure</th>
                        <th class="bordered">Date</th>
                        <th class="bordered">Heure</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="bordered" align="center"><xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$extension/dgfip:OrdreMission/dgfip:DateDepart"/><xsl:with-param name="formataffichage">date</xsl:with-param></xsl:call-template></td>
                        <td class="bordered" align="center"><xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$extension/dgfip:OrdreMission/dgfip:DateDepart"/><xsl:with-param name="formataffichage">heure</xsl:with-param></xsl:call-template></td>
                        <td class="bordered" align="center"><xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$extension/dgfip:OrdreMission/dgfip:DateRetour"/><xsl:with-param name="formataffichage">date</xsl:with-param></xsl:call-template></td>
                        <td class="bordered" align="center"><xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$extension/dgfip:OrdreMission/dgfip:DateRetour"/><xsl:with-param name="formataffichage">heure</xsl:with-param></xsl:call-template></td>
                    </tr>
                </tbody>
            </table>
            
            <p>&#160;</p>

            <table width="100%" style="bordered collapsed" cellpadding="0" cellspacing="0">
                <colgroup>
                    <col width="60%"/>
                    <col width="10%"/>
                    <col width="10%"/>
                    <col width="10%"/>
                    <col width="10%"/>
                </colgroup>
                <thead>
                    <tr>
                        <th class="bordered">Frais</th>
                        <th class="bordered">Imputation</th>
                        <th class="bordered">Quantité</th>
                        <th class="bordered">Prix unitaire</th>
                        <th class="bordered">Prix Total</th>
                    </tr>
                </thead>
                <tbody>
    <!-- Ordre d'affichage des lignes :
        1) Hotel (catégorie = HOTEL, NUITEE)
        2) Repas (catégorie = REPAS)
        3) Transports (catégorie = PARKING, VOITURE, 2_ROUES, TAXI, PEAGE, TRAIN, AVION, CAR, BATEAU, AUTRE_TRANSPORT_COMMUN, ABONNEMENT)
        4) Divers (catégorie = AUTRE, AVANCE_FRAIS)
    -->
                    <xsl:for-each select="./cac:InvoiceLine[cac:Item/cac:BuyersItemIdentification/cbc:ID = 'HOTEL'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'NUITEE']">
                        <xsl:call-template name="invoiceLine">
                            <xsl:with-param name="line" select="."/>
                        </xsl:call-template>
                    </xsl:for-each>

                    <xsl:for-each select="./cac:InvoiceLine[cac:Item/cac:BuyersItemIdentification/cbc:ID = 'REPAS']">
                        <xsl:call-template name="invoiceLine">
                            <xsl:with-param name="line" select="."/>
                        </xsl:call-template>
                    </xsl:for-each>
                    
                    <xsl:for-each select="./cac:InvoiceLine[cac:Item/cac:BuyersItemIdentification/cbc:ID = 'PARKING'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'VOITURE'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = '2_ROUES'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'TAXI'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'PEAGE'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'TRAIN'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'AVION'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'CAR'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'BATEAU'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'AUTRE_TRANSPORT_COMMUN'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'ABONNEMENT']">
                        <xsl:call-template name="invoiceLine">
                            <xsl:with-param name="line" select="."/>
                        </xsl:call-template>
                    </xsl:for-each>
                    
                    <xsl:for-each select="./cac:InvoiceLine[cac:Item/cac:BuyersItemIdentification/cbc:ID = 'AUTRE'
                        or cac:Item/cac:BuyersItemIdentification/cbc:ID = 'AVANCE_FRAIS']">
                        <xsl:call-template name="invoiceLine">
                            <xsl:with-param name="line" select="."/>
                        </xsl:call-template>
                    </xsl:for-each>
                </tbody>
            </table>

            <p>&#160;</p>
            
            <table width="40%" style="bordered collapsed" cellpadding="0" cellspacing="0" align="right">
                <colgroup>
                    <col width="60%"/>
                    <col width="40%"/>
                </colgroup>
                <tr>
                    <td class="bordered">Total</td>
                    <td class="bordered right"><xsl:call-template name="number"><xsl:with-param name="num" select="./cac:LegalMonetaryTotal/cbc:LineExtensionAmount"/></xsl:call-template></td>
                </tr>
            </table>

            <p>&#160;</p>
            <p>&#160;</p>
            
            <table width="40%" style="bordered collapsed" cellpadding="0" cellspacing="0" align="left">
                <colgroup>
                    <col width="100%"/>
                </colgroup>
                <tr>
                    <td class="bordered"><xsl:choose>
                        <xsl:when test="./cac:PaymentMeans/cbc:PaymentMeansCode/text() = 'V'"><p class="titre1" align="center">Paiement par virement</p>
                            <p class="titre1">&#160;</p>
                            <xsl:choose>
                                <xsl:when test="(./cac:PaymentMeans/cbc:PaymentChannelCode/text() = 'IBAN') and (substring(./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID/text(), 1, 2) = 'FR')">
                                    Compte n° : <xsl:value-of select="substring(./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID,15,11)"/><br/>
                                    Agence : <xsl:value-of select="./cac:PaymentMeans/cac:PayeeFinancialAccount/cac:FinancialInstitutionBranch/cbc:ID"/><br/>
                                    Code banque : <xsl:value-of select="substring(./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID,5,5)"/><br/>
                                    Code guichet : <xsl:value-of select="substring(./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID,10,5)"/><br/>
                                    Clé : <xsl:value-of select="substring(./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID,26,2)"/><br/>
                                </xsl:when>
                                <xsl:when test="(./cac:PaymentMeans/cbc:PaymentChannelCode/text() = 'IBAN') and (substring(./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID/text(), 1, 2) != 'FR')">
                                    <p>IBAN : <span class="gras"><xsl:value-of select="./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID"/></span></p>
                                </xsl:when>
                                <xsl:when test="./cac:PaymentMeans/cbc:PaymentChannelCode/text() = 'BBAN'">
                                    Compte bancaire : <span class="gras"><xsl:value-of select="./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID"/></span><br/>
                                    Code banque : <span class="gras"><xsl:value-of select="./cac:PaymentMeans/cac:PayeeFinancialAccount/cac:FinancialInstitutionBranch/cbc:ID"/></span><br/>
                                    Agence : <xsl:value-of select="./cac:PaymentMeans/cac:PayeeFinancialAccount/cac:FinancialInstitutionBranch/cbc:Name"/><br/>
                                    Clé pays : <span class="gras"><xsl:value-of select="./cac:PaymentMeans/cac:PayeeFinancialAccount/cac:Country/cbc:IdentificationCode"/></span><br/>
                                    Clé : <span class="gras"><xsl:value-of select="./cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:PaymentNote"/></span>
                                </xsl:when>
                                <xsl:otherwise>Définition du compte bancaire non reconnue</xsl:otherwise>
                            </xsl:choose>
                        </xsl:when>
                        <xsl:when test="./cac:PaymentMeans/cbc:PaymentMeansCode/text() = 'C'">Paiement par chèque</xsl:when>
                        <xsl:when test="./cac:PaymentMeans/cbc:PaymentMeansCode/text() = 'O'">Paiement en devise étrangère</xsl:when>
                        <xsl:otherwise>Mode de paiement non reconnu</xsl:otherwise>
                    </xsl:choose>
                    </td>
                </tr>
            </table>

            <xsl:variable name="valideurEF" select="$extension/dgfip:EtatFrais/dgfip:Valideur"/>
            <p>Fait le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="./cbc:IssueDate"/></xsl:call-template></p>
            <p>Vu et certifié par :</p>
            <span class="gras"><xsl:if test="$valideurEF/cac:Person/cbc:Title"><xsl:value-of select="concat($valideurEF/cac:Person/cbc:Title/text(),' ')"/> </xsl:if><xsl:value-of select="concat($valideurEF/cac:Person/cbc:FirstName/text(),' ')"/> <xsl:value-of select="$valideurEF/cac:Person/cbc:FamilyName/text()"/></span>
            
            <p>&#160;</p>
            <p>&#160;</p>
            <p>&#160;</p>
            <p>&#160;</p>
            
            <hr/>
            <hr/>
            
            <p class="titre0">Informations complémentaires</p>
            
            <p class="titre1">Etat de frais</p>
            <table width="100%" style="bordered collapsed" cellpadding="0" cellspacing="0">
                <colgroup>
                    <col width="20%"/>
                    <col width="80%"/>
                </colgroup>
                <tr>
                    <td class="bordered">Type d'état de frais</td>
                    <td class="bordered"><xsl:call-template name="libTypeEtatFrais"><xsl:with-param name="cod" select="./cbc:InvoiceTypeCode"/></xsl:call-template></td>
                </tr>
                <tr>
                    <td class="bordered">Valideur de l'EF</td>
                    <td class="bordered"><xsl:if test="$valideurEF/cac:Person/cbc:Title"><xsl:value-of select="concat($valideurEF/cac:Person/cbc:Title/text(),' ')"/> </xsl:if><xsl:value-of select="concat($valideurEF/cac:Person/cbc:FirstName/text(),' ')"/> <xsl:value-of select="$valideurEF/cac:Person/cbc:FamilyName/text()"/></td>
                </tr>
                <tr>
                    <td class="bordered">Identifiant SAP de l'utilisateur ayant validé l'EF</td>
                    <td class="bordered"><xsl:value-of select="$valideurEF/cac:PartyIdentification/cbc:ID"/></td>
                </tr>
                <tr>
                    <td class="bordered">Devise de l’état de frais</td>
                    <td class="bordered"><xsl:value-of select="./cac:LegalMonetaryTotal/cbc:LineExtensionAmount/@currencyID"/>&#160;</td>
                </tr>
            </table>
            
            <p class="titre1">Agent</p>
            <table width="100%" style="bordered collapsed" cellpadding="0" cellspacing="0">
                <colgroup>
                    <col width="20%"/>
                    <col width="80%"/>
                </colgroup>
                <tr>
                    <td class="bordered">Identifiant AMM</td>
                    <td class="bordered"><xsl:value-of select="$agent/cac:PartyIdentification/cbc:ID"/></td>
                </tr>
                <tr>
                    <td class="bordered">Identifiants tiers</td>
                    <td class="bordered">Type tiers : <xsl:value-of select="$agentExt/dgfip:AgentChorus/dgfip:TypeTiers"/><br/>
                        Identifiant fonctionnel du tiers : <xsl:value-of select="$agentExt/dgfip:AgentChorus/dgfip:IdFoncTiers"/><br/>
                        Identifiant Chorus du tiers : <xsl:value-of select="$agentExt/dgfip:AgentChorus/dgfip:IdChorusTiers"/><br/>
                    </td>
                </tr>
                <tr>
                    <td class="bordered">Nom de l'agent</td>
                    <td class="bordered"><xsl:if test="$agent/cac:Person/cbc:Title"><xsl:value-of select="concat($agent/cac:Person/cbc:Title/text(),' ')"/> </xsl:if><xsl:value-of select="concat($agent/cac:Person/cbc:FirstName/text(),' ')"/> <xsl:value-of select="$agent/cac:Person/cbc:FamilyName/text()"/></td>
                </tr>
                <tr>
                    <td class="bordered">Résidence familiale</td>
                    <td class="bordered"><xsl:for-each select="$agent/cac:PostalAddress/cac:AddressLine/cbc:Line"><br/><xsl:value-of select="."/></xsl:for-each><br/>
                        <xsl:value-of select="$agent/cac:PostalAddress/cbc:PostalZone"/><br/>
                        <xsl:value-of select="$agent/cac:PostalAddress/cbc:CityName"/></td>
                </tr>
                <tr>
                    <td class="bordered">Résidence administrative</td>
                    <td class="bordered"><xsl:for-each select="$agent/cac:PhysicalLocation/cac:Address/cac:AddressLine/cbc:Line"><br/><xsl:value-of select="."/></xsl:for-each><br/>
                        <xsl:value-of select="$agent/cac:PhysicalLocation/cac:Address/cbc:PostalZone"/><br/>
                        <xsl:value-of select="$agent/cac:PhysicalLocation/cac:Address/cbc:CityName"/></td>
                </tr>
                <tr>
                    <td class="bordered">Situation de famille</td>
                    <td class="bordered"><xsl:call-template name="libSitFam"><xsl:with-param name="cod" select="$agentExt/dgfip:SituationFamille/text()"/></xsl:call-template>&#160;</td>
                </tr>
                <tr>
                    <td class="bordered">Nombre d'enfants</td>
                    <td class="bordered"><xsl:value-of select="$agentExt/dgfip:NbEnfants"/>&#160;</td>
                </tr>
            </table>
            
            <p class="titre1">Ordre de mission</p>
            <table width="100%" style="bordered collapsed" cellpadding="0" cellspacing="0">
                <colgroup>
                    <col width="20%"/>
                    <col width="80%"/>
                </colgroup>
                <tr>
                    <td class="bordered">Nature de l'OM</td>
                    <td class="bordered"><xsl:call-template name="libNatureOM"><xsl:with-param name="cod" select="$extension/dgfip:OrdreMission/dgfip:NatureOM"/></xsl:call-template></td>
                </tr>
                <tr>
                    <td class="bordered">Valideur</td>
                    <td class="bordered"><xsl:if test="$extension/dgfip:OrdreMission/dgfip:Valideur/cac:Person/cbc:Title"><xsl:value-of select="concat($extension/dgfip:OrdreMission/dgfip:Valideur/cac:Person/cbc:Title/text(),' ')"/> </xsl:if><xsl:value-of select="concat($extension/dgfip:OrdreMission/dgfip:Valideur/cac:Person/cbc:FirstName/text(),' ')"/> <xsl:value-of select="$extension/dgfip:OrdreMission/dgfip:Valideur/cac:Person/cbc:FamilyName/text()"/></td>
                </tr>
            </table>
        </div>
    </xsl:template>
    
    <xsl:template name="invoiceLine">
        <xsl:param name="line"/>
        <tr>
            <td class="bordered top"><span class="gras"><xsl:call-template name="libTypeFrais"><xsl:with-param name="cod" select="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID"/></xsl:call-template></span>
                <xsl:if test="count($line/cac:Item/cbc:Name) = 1"><br/><xsl:value-of select="$line/cac:Item/cbc:Name"/></xsl:if>
                <xsl:for-each select="$line/cbc:Note"><br/><xsl:value-of select="."/></xsl:for-each>
                <xsl:if test="count($line/cac:Item/cbc:Description) &gt; 0"><br/><xsl:value-of select="$line/cac:Item/cbc:Description"/></xsl:if>
                <xsl:choose>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'VOITURE'">
                        <ul>
                            <li class="nosign">Trajet de <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>) à <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>)</li>
                            <li class="nosign">Départ le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_DEPART']/cbc:Value"></xsl:with-param></xsl:call-template>, arrivée le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_ARRIVEE']/cbc:Value"></xsl:with-param></xsl:call-template></li>
                            <li class="nosign">Véhicule : <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='IMMATRICULATION']/cbc:Value"/> - <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='PUISSANCE']/cbc:Value"/> CV. <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='KM_DEBUT_ANNEE']/cbc:Value"/> km depuis le début de l'année / <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='NB_KM_AUTORISES']/cbc:Value"/> km autorisés.</li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = '2_ROUES'">
                        <ul>
                            <li class="nosign">Trajet de <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>) à <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>)</li>
                            <li class="nosign">Départ le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_DEPART']/cbc:Value"></xsl:with-param></xsl:call-template>, arrivée le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_ARRIVEE']/cbc:Value"></xsl:with-param></xsl:call-template></li>
                            <li class="nosign">Véhicule : <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='IMMATRICULATION']/cbc:Value"/> - Cylindrée : <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='CYLINDREE']/cbc:Value"/> - <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='KM_DEBUT_ANNEE']/cbc:Value"/> km depuis le début de l'année / <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='NB_KM_AUTORISES']/cbc:Value"/> km autorisés.</li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'TAXI'">
                        <ul>
                            <li class="nosign">De <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>)</li>
                            <li class="nosign">A <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>)</li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'PEAGE'">
                        <ul>
                            <li class="nosign">De <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>)</li>
                            <li class="nosign">A <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>)</li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'TRAIN'">
                        <ul>
                            <li class="nosign">De <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>) le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_DEPART']/cbc:Value"></xsl:with-param><xsl:with-param name="formataffichage">dateheure</xsl:with-param></xsl:call-template></li>
                            <li class="nosign">A <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>) le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_ARRIVEE']/cbc:Value"></xsl:with-param><xsl:with-param name="formataffichage">dateheure</xsl:with-param></xsl:call-template></li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'AVION'">
                        <ul>
                            <li class="nosign">De <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>) le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_DEPART']/cbc:Value"></xsl:with-param><xsl:with-param name="formataffichage">dateheure</xsl:with-param></xsl:call-template></li>
                            <li class="nosign">A <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>) le <xsl:call-template name="format-date"><xsl:with-param name="datebrute" select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='DATE_ARRIVEE']/cbc:Value"></xsl:with-param><xsl:with-param name="formataffichage">dateheure</xsl:with-param></xsl:call-template></li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'CAR'">
                        <ul>
                            <li class="nosign">De <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>)</li>
                            <li class="nosign">A <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>)</li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'BATEAU'">
                        <ul>
                            <li class="nosign">De <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>)</li>
                            <li class="nosign">A <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>)</li>
                        </ul>
                    </xsl:when>
                    <xsl:when test="$line/cac:Item/cac:BuyersItemIdentification/cbc:ID = 'AUTRE_TRANSPORT_COMMUN'">
                        <ul>
                            <li class="nosign">De <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_DEPART_CP']/cbc:Value"/>)</li>
                            <li class="nosign">A <xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_COMMUNE']/cbc:Value"/> (<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='LIEU_ARRIVEE_CP']/cbc:Value"/>)</li>
                        </ul>
                    </xsl:when>
                </xsl:choose>
                
            </td>
            <td class="bordered top center">&#160;<xsl:value-of select="$line/cac:Item/cac:AdditionalItemProperty[cbc:Name='CH_COMPTE_PCE']/cbc:Value"/></td>
            <td class="bordered top right">&#160;<xsl:value-of select="$line/cbc:InvoicedQuantity"/></td>
            <td class="bordered top right">&#160;<xsl:if test="count($line/cac:Price/cbc:PriceAmount) = 1"><xsl:call-template name="number"><xsl:with-param name="num" select="$line/cac:Price/cbc:PriceAmount"/></xsl:call-template></xsl:if></td>
            <td class="bordered top right">&#160;<xsl:call-template name="number"><xsl:with-param name="num" select="$line/cbc:LineExtensionAmount"/></xsl:call-template></td>
        </tr>
    </xsl:template>
    
    <xsl:template name="libPays">
        <xsl:param name="cod"/>
        <xsl:value-of select="$pays/ISO_3166-1_List_fr/ISO_3166-1_Entry[ISO_3166-1_Alpha-2_code=$cod]/ISO_3166-1_Country_name/text()"/>
    </xsl:template>
    
    <xsl:template name="libSitFam">
        <xsl:param name="cod"/>
        <xsl:value-of select="$SituationsFamille/SituationsFamiliales/situation[@code=$cod]/text()"/>
    </xsl:template>

    <xsl:template name="libTypeEtatFrais">
        <xsl:param name="cod"/>
        <xsl:value-of select="$TypesEtatFrais/TypesEtatFrais/EtatFrais[@code=$cod]/text()"/>
    </xsl:template>
    
    <xsl:template name="libTypeFrais">
        <xsl:param name="cod"/>
        <xsl:value-of select="$TypesFrais/TypesFrais/Frais[@code=$cod]/text()"/>
    </xsl:template>
    
    <xsl:template name="libNatureOM">
        <xsl:param name="cod"/>
        <xsl:value-of select="$NaturesOM/NaturesOM/Nature[@code=$cod]/text()"/>
    </xsl:template>
    
    <xsl:template name="format-date">
        <xsl:param name="datebrute"/>
        <xsl:param name="formataffichage" select="'date'"/> <!-- valeurs attendues : date / heure / dateheure -->
        <xsl:if test="($formataffichage = 'date') or ($formataffichage = 'dateheure')">
            <xsl:value-of select="substring($datebrute, 9, 2)"/>
            <xsl:text>/</xsl:text>
            <xsl:value-of select="substring($datebrute, 6, 2)"/>
            <xsl:text>/</xsl:text>
            <xsl:value-of select="substring($datebrute, 1, 4)"/>
        </xsl:if>
        <xsl:if test="($formataffichage = 'heure') or ($formataffichage = 'dateheure')">
            <xsl:text> </xsl:text>
            <xsl:value-of select="substring($datebrute, 12, 2)"/>
            <xsl:text>:</xsl:text>
            <xsl:value-of select="substring($datebrute, 15, 2)"/>
        </xsl:if>
    </xsl:template>
    
    <xsl:template name="number">
        <xsl:param name="num"/>
        <xsl:choose>
            <xsl:when test="string-length($num) = 0"/>
            <xsl:when test="number($num) = 0"/>
            <xsl:when test="string(number($num)) = 'NaN'"/>
            <xsl:otherwise>
                <xsl:value-of select="format-number($num,'# ###,00;-# ###,00','decformat')"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
