{% extends 'layout.twig' %}

{% block body %}
    <div class="contenu clearfix"  id="fournisseurs">
    <h1>
        {{ titre }}
        
        {% if sousTitre == 'MultiFournisseur'  %}		
            {% if btnAjouter %}			
                {{ Button('Nouvel incident' | trad, true, path('GlobalApplication.Incidents.creationIncidents', {MODULE:MODULE, id: id, menuLeft:menuLeft,menuActif:menuActive}), '', '','','ajout') }}
            {% endif %}

            {% if IncidentFournisseur | length %}
                {{ ButtonExport(path('GlobalApplication.Incidents.exportIncidents', {MODULE:MODULE, id:id, menuLeft:menuleft,menuActif:menuActive }), 'filtre_incidents', path('Ajax.Erreur.popupInformation') , path('Ajax.Outil.appelAsync')) }}
            {% endif %}
            
        {% endif %}
    </h1>
    {{ ariane() }}
    
    <div id="detail_fournisseur" class="clearfix titre_div">
        <h2>
            {% if sousTitre != 'MultiFournisseur'  %}
                {{ sousTitre }} : {% if libelle!='' %}{{ libelle }} ({{ id }}){% else %}{{ idAvenant??id }}{% endif %}
            
                {% if btnAjouter %}			
                    {{ Button('Nouvel incident' | trad, true, path('GlobalApplication.Incidents.creationIncidents', {MODULE:MODULE, id: id, menuLeft:menuLeft,menuActif:menuActive}), '', '','','ajout') }}
                {% endif %}
    
                {% if IncidentFournisseur | length %}
                    {{ ButtonExport(path('GlobalApplication.Incidents.exportIncidents', {MODULE:MODULE, id:id, menuLeft:menuleft,menuActif:menuActive }), 'filtre_incidents', path('Ajax.Erreur.popupInformation') , path('Ajax.Outil.appelAsync')) }}
                {% endif %}
                
            {% endif %}
        </h2>
        
        {{ arianeSub() }}
            
        <form method="POST" id="filtre_incidents">
            <div class="tab-content">
            
            
                <div id="incidents" class="pad-15">
                    <table class="table table-hover">
                        <thead class="thead-dark">
                            <tr>
                                <th scope="col" width="130px">{{ triTable('DATE',  infoPagination.filter.tri_DATE, 'Date' | trad ,null,null,'filtre_incidents' ) }}</th>
                                <th scope="col" >{{ triTable('LIBELLE_CATINC',  infoPagination.filter.tri_LIBELLE_CATINC, 'Catégorie de l\'incident' | trad ,null,null,'filtre_incidents' ) }}</th>
                                <th scope="col" >{{ triTable('LIBELLE2_INC',  infoPagination.filter.tri_LIBELLE2_INC, 'Incident' | trad,null,null,'filtre_incidents' ) }}</th>
                                {% if MODULE!='Fournisseur' %}
                                    <th scope="col" >{{ triTable('FOU',  infoPagination.filter.tri_FOU, 'Fournisseur' | trad,null,null,'filtre_incidents' ) }}</th>
                                {% endif %}
                                <th scope="col" >{{ triTable('DESCRIPT',  infoPagination.filter.tri_DESCRIPT, 'Description' | trad,null,null,'filtre_incidents' ) }}</th>
                                <th scope="col" width="4%" >{{ triTable('NIVEAU_FOUR',  infoPagination.filter.tri_NIVEAU_FOUR, 'Niveau' | trad,null,null,'filtre_incidents' ) }}</th>
                                <th scope="col" width="3%" class="align-center">{{ 'Actions' | trad }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="recherche">

                                <td>{{ filterTable("DATE", infoPagination.filter.filter_date_DATE, "", "incidents", "", "filtre_incidents", "date") }}</td>
                                <td>{{ filterSelect("LIBELLE_CATINC", post.filter_LIBELLE_CATINC, listeCat, "incidents", "", "", "filtre_incidents") }}</td>
                                <td>
                                {% set listTypeAvailable = {
                                    'FACTURE': ['FACNDEM', 'DBLFAC', 'ERRFDP', 'ERRDET', 'ERRTVA', 'ERRQTE', 'ERRPRIX', 'FANCONF', 'CNEGNR', 'PDTMANQ', 'CDPNR', 'MLONR'],
                                    'LIVRAIS': ['LIVINC', 'RET LIV', 'REPORT', 'REFUS', 'MANQ'],
                                    'FOURN': ['DE_REF', 'RELDOC'],
                                    'COMMANDE': ['REL CDE', 'ABPART'],
                                    'RELDOC': ['DOCATT', 'RELDOC']
                                }[ post.filter_LIBELLE_CATINC ] %}
                                {{ filterSelect(
                                    "LIBELLE2_INC",
                                    post.filter_LIBELLE2_INC,
                                    listeIncident 
                                    | filter((item, key) => listTypeAvailable is empty or key in listTypeAvailable),
                                    "incidents", "", "", "filtre_incidents"
                                ) }}</td>
                                {% if MODULE != 'Fournisseur' %} 
                                    <td>
                                        {{
                                            filter('ZOOM',{
                                                'key'         : 'FOU' ~ spliter() ~ 'RS',
                                                'value'       : post['filter_FOU' ~ spliter() ~ 'RS'],
                                                'formName'    : 'filtre_incidents',
                                                'zoomPath'    : path('Ajax.liste.fournisseur'),
                                                'zoomTitle'   : 'Fournisseur'| trad|e('js'),
                                                'title'       : 'Fournisseur'| trad|e('js')
                                            })
                                        }}
                                    </td>
                                {% endif %}
                                <td>{{ filterTable("DESCRIPT", infoPagination.filter.filter_DESCRIPT, "", "incidents", "", "filtre_incidents") }}</td>
                                <td>{{ filterTable("NIVEAU_FOUR", infoPagination.filter.filter_NIVEAU_FOUR,  "", "incidents", "", "filtre_incidents") }}</td>
                                <td></td>
                            </tr>
                    
                            {% for incident in IncidentFournisseur %}
                            <tr id="incident{{ loop.index }}">
                                <td class="loupe">{{ incident.DTE_OCCUR | dateTrad }}</td>
                                <td>{{ entityLabel(incident, 'CODE_CAT', 'LIBELLE_CATINC') }}</td>
                                <td>{{ entityLabel(incident, 'CODE', 'LIBELLE2_INC') }}</td>
                                {% if MODULE != 'Fournisseur' %}
                                    <td>{{ convertLibelleGlobal('FOURNISS', '', incident.FOU) }} {% if incident.FOU != '' %}({{ incident.FOU }}){% endif %}
                                    </td>
                                {% endif %}
                                <td>{{ incident.DESCRIPT }}</td>
                                <td>{{ incident.NIVEAU_FOUR }}</td>
                                <td class="parametrage">
                                	{{ menuContextuel('incident'~loop.index, false, incident.menuContextuel, 6) }}          
                                

                                </td>
                            </tr>
                            <tr id="incident{{ loop.index }}detail" class="detail_ligne hide_detail">
                                <td colspan="7">
                                    <h4>{{ 'Détail de l\'incident' | trad }}</h4>
                                    <div class="colonne3">
                                        <div class="informations">
                                            <p>
                                                <span class="champs_label">{{ 'N° de Commande' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.NO_CDE }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'N° de ligne Cde' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.PO_CDE }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'Code article' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.ART }}</span>
                                            </p>
                                        </div>
                                    </div>
                                    <div class="colonne3">
                                        <div class="informations">
                                            <p>
                                                <span class="champs_label">{{ 'N° de BR' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.NO_BR }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'N° de ligne BR' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.PO_BR }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'Qté en anomalie' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.QTE_REFU|number_format(3, '.', ' ') }}</span>
                                            </p>
                                        </div>
                                    </div>
                                    <div class="colonne3 last">
                                        <div class="informations">
                                            <p>
                                                <span class="champs_label">{{ 'Commande créée le' | trad  }}</span>
                                                <span class="resultat align-right">{{ incident.DTE_CREAT |dateTrad }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'Date de livraison' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.DTE_LIV |dateTrad }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'Utilisateur' | trad }}</span>
                                                <span class="resultat align-right">
                                                    {% if incident.INCF_USER|trim %}
                                                        {{ incident.Util_NOM }} ({{ incident.INCF_USER }})
                                                    {% endif %}
                                                </span>
                                            </p>
                                        </div>
                                    </div>
                                    <div class="colonne3">
                                        <div class="informations">
                                            <p>
                                                <span class="champs_label">{{ 'N° de Facture' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.NO_FACT }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'Litige fermé' | trad }}</span>
                                                <span class="resultat align-right">{{ incident.INC_FERME | boolTrad }}</span>
                                            </p>
                                        </div>
                                    </div>
                                    <div class="full">
                                        <div class="informations">
                                            <p>
                                                <span class="champs_label">{{ 'Libellé article' | trad }}</span>
                                                <span>{{ incident.DES_ART }}</span>
                                            </p>
                                            <p>
                                                <span class="champs_label">{{ 'Commentaire' | trad }}</span>
                                                <span>{{ incident.CONTMEMO | nl2br }}</span>
                                            </p>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                    {{ paginations(path('GlobalApplication.Incidents.incidents', {MODULE:MODULE, id:id}),infoPagination.nombreDePage, infoPagination.page, infoPagination.post, '') }}
                </div>	
            </div>
        </form>
    </div>
</div>
{% endblock %}