page.sheet.import.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. User::check_access('import','read');
  3. require_once(__DIR__.SLASH.'Import.class.php');
  4. require_once(__DIR__.SLASH.'ImportMapping.class.php');
  5. global $myUser;
  6. $import = Import::provide();
  7. if($import->id==0){
  8. $import->label = 'Sans titre';
  9. $import->startLine = 2;
  10. $import->headerLine = 1;
  11. $import->hasheader = 1;
  12. }
  13. $allowedExtensions = array();
  14. foreach(Import::templates() as $template)
  15. $allowedExtensions[] = $template->extension;
  16. ?>
  17. <div class="plugin-import" data-mode="<?php echo $myUser->can('import','configure') ? 'configure':'execute' ?>">
  18. <div id="import-form" class="row justify-content-md-center import-form" data-action="import_save" data-id="<?php echo $import->id; ?>">
  19. <div class="col-md-8">
  20. <div class="row">
  21. <div class="col-md-12 shadow-sm bg-white p-3">
  22. <h3>Import
  23. <a href="index.php" class="btn btn-small btn-dark right mr-2">Retour</a>
  24. <div class="btn btn-small btn-info mb-2 btn-dark mx-2 right" data-scope="import" data-uid="<?php echo $import->id; ?>" data-show-important="true" data-type="history" data-tooltip title="Ouvrir l'historique"> <i class="far fa-comment-dots"></i></div>
  25. </h3>
  26. <label for="label">Libellé</label>
  27. <input value="<?php echo $import->label; ?>" <?php echo $myUser->can('import','configure') ? '':'readonly' ?> class="form-control" type="text" onchange="import_save()" id="label" >
  28. <div class="configure-only mt-2">
  29. <label for="entity">Donnée ERP à renseigner</label>
  30. <input value="<?php echo $import->entity; ?>" onchange="import_save()" data-type="entitypicker" class="form-control" type="text" id="entity" >
  31. </div>
  32. <div class="update-only my-2 file-container">
  33. <label for="file">Fichier Excel</label>
  34. <small class="text-muted configure-only">Fichier excel d'exemple à importer (au moins une ligne de données (fichiers autorisés: <?php echo implode(',',$allowedExtensions); ?>))</small>
  35. <small class="text-muted execute-only">Fichier excel à importer (fichiers autorisés: <?php echo implode(',',$allowedExtensions); ?>)</small>
  36. <input class="component-file-default bg-white shadow-sm rounded-sm" type="text" data-label="Faites glisser votre fichier excel ici" data-type="file" data-extension="xlsx,xls" data-action="import_file" data-limit="1" data-id="file" data-data='{"scope":"import","slug":"import"}' id="file" >
  37. </div>
  38. <div class="configure-only">
  39. <label for="hasheader"><input <?php echo $import->hasheader == 1 ? 'checked="checked"' : '' ?> onchange="import_save()" data-type="checkbox" type="checkbox" id="hasheader"> Mon fichier comporte une en-tête</label>
  40. <div id="template-settings"></div>
  41. <label for="headerLine">N° de ligne d'en-tête (si existante)</label>
  42. <small class="text-muted">Optionnel (defaut: 1)</small>
  43. <input onchange="import_save()" value="<?php echo $import->headerLine; ?>" class="form-control" type="number" id="headerLine" >
  44. <label for="startLine">N° de ligne de départ de données</label>
  45. <small class="text-muted">Optionnel (defaut: 2)</small>
  46. <input onchange="import_save()" value="<?php echo $import->startLine; ?>" class="form-control" type="number" id="startLine" >
  47. <hr/>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="row mt-3 hasfile-only configure-only">
  52. <div class="col-md-12 shadow-sm bg-white">
  53. <h4 class="my-3"><i class="far fa-file-excel text-success"></i> EXCEL <i class="fas fa-long-arrow-alt-right"></i> <i class="fas fa-database text-warning"></i> BASE </h4>
  54. <div class="btn btn-dark w-100 btn-import-deduction my-2" onclick="import_mapping_deduction()"><i class="fas fa-search-plus"></i> Déduire les champs</div>
  55. <!-- présentation tableau -->
  56. <table id="import-mappings" class="table table-striped " data-entity-search="import_mapping_search">
  57. <thead>
  58. <tr>
  59. <th data-sortable="excelColumn">Colonne Excel</th>
  60. <th data-sortable="modifier">Macro de modification</th>
  61. <th data-sortable="entityField">Colonne ERP</th>
  62. <th data-sortable="uniticy">Si valeur non unique</th>
  63. <th><div class="btn btn-sm text-danger right" data-tooltip title="Supprimer toutes les lignes" onclick="import_mapping_delete('all');"><i class="far fa-trash-alt"></i></div></th>
  64. </tr>
  65. </thead>
  66. <tbody>
  67. <tr data-id="{{id}}" class="hidden item-line">
  68. <td class="align-middle import-label-column">
  69. <input type="text" data-id="excelColumn" onchange="import_mapping_save(this)" class="border-0 d-inline-block bg-transparent excelColumn" value="{{excelColumn}}">
  70. {{#excelColumnName}} <small class="text-muted">- {{excelColumnName}}</small>{{/excelColumnName}}
  71. <label><input type="checkbox" class="fixedValueCheckbox" data-type="checkbox" onclick="import_mapping_fixed_change(this);"> Valeur fixe</label>
  72. <input type="text" data-id="excelColumnFixedValue" onchange="import_mapping_save(this)" class="form-control hidden excelColumnFixedValue">
  73. </td>
  74. <td class="align-middle"><select class="form-control" onchange="import_mapping_save(this)" data-id="modifier">
  75. <option value="">-</option>
  76. <?php foreach(Import::macros() as $key=>$macro): ?>
  77. <option value="<?php echo $key; ?>"><?php echo $macro['label']; ?></option>
  78. <?php endforeach; ?>
  79. </select></td>
  80. <td class="align-middle">
  81. <select class="form-control entityField" onchange="import_entity_field_change(this)" data-id="entityField"></select>
  82. <select class="form-control entitySubField mt-1 hidden" onchange="import_mapping_save(this)" data-id="entitySubField"></select>
  83. <input type="text" data-tpl-type="entitypicker" data-id="entityRelated" onchange="import_mapping_save(this)" class="entityRelated hidden form-control input-small mt-1">
  84. <input type="text" data-tpl-type="checkbox-list" data-depth="2" onchange="import_mapping_save(this)" data-multi-level-select="true" data-id="entityRelatedField" class="entityRelatedField hidden form-control input-small mt-1">
  85. </td>
  86. <td>
  87. <select class="form-control unique mt-1 " onchange="import_mapping_save(this)" data-id="unique">
  88. <?php foreach(ImportMapping::uniqueness() as $key=>$unique): ?>
  89. <option value="<?php echo $key; ?>"><?php echo $unique['label']; ?></option>
  90. <?php endforeach; ?>
  91. </select>
  92. </td>
  93. <td class="align-middle text-right">
  94. <div class="btn-group btn-group-sm" role="group">
  95. <div class="btn text-danger" data-tooltip title="Supprimer cette ligne" onclick="import_mapping_delete(this);"><i class="far fa-trash-alt"></i></div>
  96. </div>
  97. </td>
  98. </tr>
  99. </tbody>
  100. <thead>
  101. <tr id="import-mapping-form" data-action="import_mapping_save" data-id="">
  102. <th colspan="5" class="text-center"><div onclick="import_mapping_add();" class="btn btn-success"><i class="fas fa-plus"></i></div></th>
  103. </tr>
  104. </thead>
  105. </table>
  106. </div>
  107. <br/>
  108. </div>
  109. <div class="row mt-3 update-only">
  110. <div class="col-md-12 shadow-sm bg-white p-3">
  111. <div class="btn btn-primary btn-import w-100" onclick="import_execute()"><i class="fas fa-file-import"></i> Importer</div>
  112. </div>
  113. </div>
  114. <div class="row mt-3 update-only import-excel-table-container hidden">
  115. <div class="col-md-12 p-3">
  116. <h3>Résultat d'import</h3>
  117. <ul class="import-stats-list">
  118. <template>
  119. <li class="shadow-sm" data-slug="{{slug}}"><i class="fas fa-times"></i> <span>{{value}}</span> {{label}}</li>
  120. </template>
  121. </ul>
  122. <table class="import-excel-table hidden shadow-sm bg-white mt-2">
  123. <thead class="title-head">
  124. <tr>
  125. <th colspan="4">Fichier.xlsx</th>
  126. </tr>
  127. </thead>
  128. <thead class="column-head">
  129. <tr>
  130. <th><img src="plugin/import/img/triangle.png"></th>
  131. <template>
  132. <th>{{.}}</th>
  133. </template>
  134. </tr>
  135. </thead>
  136. <tbody>
  137. <template>
  138. <tr class="state-{{state}}">
  139. <th>{{lineNumber}}</th>
  140. </tr>
  141. </template>
  142. <template>
  143. <td class="state-{{state}}">{{value}} {{#state}}<br><strong>{{stateLabel}}</strong>{{/state}}{{#message}}: {{message}}{{/message}}</td>
  144. </template>
  145. </tbody>
  146. </table>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. </div>