]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавления кнопки экспорта таблицы закупки в xslx feature_smirnov_erp-81_shipment_export_to_excel
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 10 Jul 2024 13:03:10 +0000 (16:03 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 10 Jul 2024 13:03:10 +0000 (16:03 +0300)
erp24/modul/shipment/shipment.php
erp24/views/shipment/shipment.php

index bac525815f94a4b18420f5da55ee9e9bfb592dbc..f883dee8ffeeb23ff3f8e4f58c6be6af6ac5b4d1 100644 (file)
@@ -39,6 +39,9 @@ echo'<h3 class="page-title mb-0 text-primary">
 Заказ товара '.($OrderData["name"] ?? '').' id='.$orderId.'</h3>
 <p> ваша роль <b>'. ($users_group[$_SESSION["group_id"]] ?? '').'</b>
 <span onclick="deleteAll();" class="btn btn-danger btn-sm me-2">очистить данные у этой закупки</span>
+<div style="float: right; margin: 20px;">
+<button class="btn btn-success btn-sm" onclick="htmlTableToExcel();">Экспорт таблицы в Excel документ</button>
+</div>
 </p>';
 
 
@@ -52,7 +55,7 @@ showOrderStoresPanel();
 echo'<div id=edit_div></div>';
 if(!empty($store_id)) echo'<input type=hidden name=store_id_id value='.$store_id.' id=store_id_id>';
 
-echo'<div class="table-responsive mt-3"><table class="zak">';
+echo'<div class="table-responsive mt-3"><table id="shipmentTable" class="zak">';
 $html='<thead><tr class="zg"><th class="text-right w-10">наименование 
 
 <span onclick="ajaxUpdateStoreZakup();" class="btn btn-blue btn-sm me-2">пересчитать данные</span>';
@@ -292,6 +295,19 @@ $data=$db::getRows($sql);
  
 $_CONFIG["jscss"] ="<script>
 
+function htmlTableToExcel() {
+    const type = 'xlsx';
+    var data = document.getElementById('shipmentTable');
+    $.each(data.querySelectorAll('input'), (ind, x) => {
+        x.parentNode.textContent = x.value;
+    });
+    var excelFile = XLSX.utils.table_to_book(data, {sheet: 'sheet1'});
+    XLSX.write(excelFile, { bookType: type, bookSST: true, type: 'base64' });
+    moment.locale('ru');
+    XLSX.writeFile(excelFile, 'ShipmentTable_' + moment().format('L') + '.' + type);
+    window.location.reload();
+}
+
 function ajaxUpdateStoreZakup(){
  $('#modal-7 .modal-body').html('Считаем данные');
 jQuery('#modal-7').modal('show', {backdrop: 'static'}); $('#modal-7 .modal-title').text('Обновляем данные');
index 1b9d55efb5f956b5f1b3f261f567d19b6bd395df..908c115ed9c60d9c66cc09d7677417af0c33a029 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+$this->registerJsFile('https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js', ['position' => \yii\web\View::POS_END]);
+
 chdir(__DIR__ . '/../../');
 
 include 'modul/shipment/shipment.php';
\ No newline at end of file