From 83404ed02e083aed50a7d4ffdbe0c4602ece5920 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 3 Feb 2018 15:28:52 +0100 Subject: [PATCH] Export PDF from ANC , add a progress_bar --- include/anc_great_ledger.inc.php | 9 ++++++--- include/class/document_export.class.php | 18 +++++++++++++----- include/export/export_anc_receipt_pdf.php | 9 ++++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/anc_great_ledger.inc.php b/include/anc_great_ledger.inc.php index 0ecb747af..3cf291be7 100644 --- a/include/anc_great_ledger.inc.php +++ b/include/anc_great_ledger.inc.php @@ -34,10 +34,13 @@ if ($result != null) echo ''; echo _('Tout sélectionner')." ".ICheckBox::toggle_checkbox('export_pdf_bt1','export_anc_receipt_pdf'); echo ''; + $task_id=uniqid(); echo $grandLivre->show_button(); - printf ('
', - _("Le traitement est en cours , merci de patienter sans recharger la page")); - + printf ('', + $task_id, + _("Le traitement est en cours , merci de patienter sans recharger la page") + ); + echo HtmlInput::hidden("task_id",$task_id); echo $grandLivre->button_export_pdf(); echo $grandLivre->display_html(); echo $grandLivre->button_export_pdf(); diff --git a/include/class/document_export.class.php b/include/class/document_export.class.php index e0a96f35e..ac632ddbf 100644 --- a/include/class/document_export.class.php +++ b/include/class/document_export.class.php @@ -19,6 +19,7 @@ // Copyright Author Dany De Bontridder danydb@aevalys.eu require_once NOALYSS_INCLUDE.'/class/pdf_operation.class.php'; +require_once NOALYSS_INCLUDE.'/lib/progress_bar.class.php'; /** * @brief Export DOCUMENT from Analytic accountancy, can transform into PDF * and add a stamp on each pages @@ -118,16 +119,20 @@ class Document_Export * a stamp. If an error occurs then $this->feedback won't be empty * @param $p_array contents all the jr_id */ - function export_all($p_array) + function export_all($p_array, Progress_Bar $progress) { $this->check_file(); + if ( count($p_array)==0) return; ob_start(); $cnt_feedback=0; global $cn; - + // follow progress + $step=round(20/count($p_array)); + $cn->start(); foreach ($p_array as $value) { + $progress->increment($step); // For each file save it into the temp folder, $file = $cn->get_array('select jr_pj,jr_pj_name,jr_pj_number,jr_pj_type from jrn ' . ' where jr_id=$1', array($value)); @@ -173,7 +178,7 @@ class Document_Export continue; } - + $progress->increment($step); // // remove extension $ext = strrpos($filename, "."); @@ -210,6 +215,7 @@ class Document_Export } rename ($this->store_convert . '/' . $file_pdf.'.2',$this->store_convert . '/' . $file_pdf); } + $progress->increment($step); // output $output = $this->store_convert . '/stamp_' . $file_pdf; @@ -238,7 +244,7 @@ class Document_Export // concatenate detail operation with the output $stmt = PDFTK . " " . $detail_operation->get_pdf_filename()." ".$output. ' output ' . $output2; - + $progress->increment($step); passthru($stmt, $status); if ($status <> 0) { @@ -258,10 +264,12 @@ class Document_Export // Move the PDF into another temp directory $this->move_file($output, 'stamp_' . $file_pdf); } - + $progress->set_value(93); // concatenate all pdf into one $this->concatenate_pdf(); + $progress->set_value(100); + ob_clean(); $this->send_pdf(); diff --git a/include/export/export_anc_receipt_pdf.php b/include/export/export_anc_receipt_pdf.php index 890f95032..d6d6b475b 100644 --- a/include/export/export_anc_receipt_pdf.php +++ b/include/export/export_anc_receipt_pdf.php @@ -23,12 +23,14 @@ if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); - +// unlock session +session_write_close(); /** * export all the selected documents for Ana Accountancy in PDF */ require_once NOALYSS_INCLUDE.'/class/document_export.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; +require_once NOALYSS_INCLUDE.'/lib/progress_bar.class.php'; $http=new HttpInput(); $ck = $http->get('ck',"string", 0); if ($ck == 0) @@ -37,5 +39,6 @@ if ($ck == 0) exit(); } $anc=new Document_Export(); - -$anc->export_all($ck); +$task_id=$http->request("task_id"); +$progress=new Progress_Bar($task_id); +$anc->export_all($ck,$progress);