[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 23/46: Task #0002014: Comptabilité analytique
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 23/46: Task #0002014: Comptabilité analytique = export des pièces des opérations rapprochées |
Date: |
Tue, 13 Jul 2021 05:01:56 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 0e0cb7ca0f63af5a0ba8a67b7512eff8fe7f09e7
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Jun 16 18:06:02 2021 +0200
Task #0002014: Comptabilité analytique = export des pièces des opérations
rapprochées
---
include/anc_great_ledger.inc.php | 19 +-
include/class/document_export.class.php | 320 +++++++++++++++++++-----------
include/class/pdf_operation.class.php | 22 ++
include/export/export_anc_receipt_pdf.php | 3 +-
4 files changed, 244 insertions(+), 120 deletions(-)
diff --git a/include/anc_great_ledger.inc.php b/include/anc_great_ledger.inc.php
index da41277..13ca0e1 100644
--- a/include/anc_great_ledger.inc.php
+++ b/include/anc_great_ledger.inc.php
@@ -47,6 +47,17 @@ if ($result != null)
$type_pdf->add_value(_("Un PDF par opération"),2);
$type_pdf->set_position("in-absolute");
echo $type_pdf->input();
+
+ // propose to download also the reconcilied operation with its receipt
+// echo _("Avec documents des opérations rapprochées");
+// $checkbox=new ICheckBox("receipt_reconcilied", 0);
+//
+// echo $checkbox->input();
+ $type_pdf=new Select_Box("reconcilied_document",_("Opérations
rapprochées"));
+ $type_pdf->add_value(_("Opérations rapprochées avec documents"),1);
+ $type_pdf->add_value(_("Opérations rapprochées sans documents"),2);
+ $type_pdf->set_position("in-absolute");
+ echo $type_pdf->input();
echo $grandLivre->button_export_pdf();
echo $grandLivre->display_html();
@@ -71,16 +82,20 @@ if ($result != null)
{
valid=false;
}
-
+ if (document.getElementById("reconcilied_document").value == "-1" )
+ {
+ valid=false;
+ }
if ( valid ) {
progress_bar_start(p_task_id,p_message);
return true;
} else {
- smoke.alert("<?=_('Choisissez au moins une opération et le type
d\'export')?>");
+ smoke.alert("<?=_('Choisissez au moins une opération, les
opérations rapprochées et le type d\'export')?>");
return false;
}
}
+
</script>
<?php
}
diff --git a/include/class/document_export.class.php
b/include/class/document_export.class.php
index 3b36d98..6158a5a 100644
--- a/include/class/document_export.class.php
+++ b/include/class/document_export.class.php
@@ -42,9 +42,12 @@ class Document_Export
$this->store_pdf = tempnam($_ENV['TMP'], 'pdf_');
unlink($this->store_convert);
unlink($this->store_pdf);
+ $this->progress=NULL;
umask(0);
- if ( mkdir($this->store_convert) == FALSE ) throw new
Exception(sprintf("Create %s failed",$this->store_onvert));
- if ( mkdir($this->store_pdf)== FALSE ) throw new
Exception(sprintf("Create %s failed",$this->store_pdf));
+ if ( mkdir($this->store_convert) == FALSE )
+ throw new Exception(sprintf("Create %s
failed",$this->store_onvert));
+ if ( mkdir($this->store_pdf)== FALSE )
+ throw new Exception(sprintf("Create %s failed",$this->store_pdf));
}
/**
* @brief concatenate all PDF into a single one and save it into the
@@ -151,169 +154,121 @@ class Document_Export
/**
* @brief export all the pieces in PDF and transform them into a PDF with
* a stamp. If an error occurs then $this->feedback won't be empty
- * @param $p_array contents all the jr_id
+ * @param $p_array contents all the jr_id
* @param Progress_Bar $progress is the progress bar
* @param int $p_separate 1 everything in a single PDF or a ZIP with all
PDF
+ * @param int $reconcilied_operation 1 with receipt of reconcilied
operation 2 without them
+ *
*/
- function export_all($p_array, Progress_Bar $progress,$p_separate=1)
+ function export_all($p_array, Progress_Bar
$progress,$p_separate=1,$reconcilied_document)
{
+ $this->progress=$this->progress;
+
$this->check_file();
- if ( count($p_array)==0) return;
+ if (count($p_array)==0)
+ return;
ob_start();
$cnt_feedback=0;
global $cn;
- // follow progress
- $step=round(16/count($p_array),2);
- $cn->start();
+ // follow progress
+ $step=round(16/count($p_array), 2);
+
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));
- if ($file[0]['jr_pj'] == '')
- continue;
- $filename=clean_filename($file[0]['jr_pj_name']);
- $cn->lo_export($file[0]['jr_pj'], $this->store_convert . '/' .
$filename);
+ $output_receipt=$this->export_receipt($value, $progress, $step);
- // Convert this file into PDF
- if ($file[0]['jr_pj_type'] != 'application/pdf')
- {
- $status = 0;
- $arg="
".escapeshellarg($this->store_convert.DIRECTORY_SEPARATOR.$filename);
- echo "arg = [".$arg."]";
- passthru(OFFICE . " " . $arg , $status);
- if ($status <> 0)
- {
- $this->feedback[$cnt_feedback]['file'] = $filename;
- $this->feedback[$cnt_feedback]['message'] = ' cannot
convert to PDF';
- $this->feedback[$cnt_feedback]['error'] = $status;
- $cnt_feedback++;
- continue;
- }
- }
- // Create a image with the stamp + formula
- $img = imagecreatefromgif(NOALYSS_INCLUDE .
'/template/template.gif');
- $font = imagecolorallocatealpha($img, 100, 100, 100, 110);
- imagettftext($img, 40, 25, 500, 1000, $font, NOALYSS_INCLUDE .
'/tfpdf/font/unifont/DejaVuSans.ttf', _("Copie certifiée conforme à
l'original"));
- imagettftext($img, 40, 25, 550, 1100, $font, NOALYSS_INCLUDE.
'/tfpdf/font/unifont/DejaVuSans.ttf', $file[0]['jr_pj_number']);
- imagettftext($img, 40, 25, 600, 1200, $font, NOALYSS_INCLUDE.
'/tfpdf/font/unifont/DejaVuSans.ttf', $file[0]['jr_pj_name']);
- imagegif($img, $this->store_convert . '/' . 'stamp.gif');
-
- // transform gif file to pdf with convert tool
- $stmt = CONVERT_GIF_PDF . " " .
escapeshellarg($this->store_convert . '/' . 'stamp.gif') . " " .
escapeshellarg($this->store_convert . '/stamp.pdf');
- passthru($stmt, $status);
- if ($status <> 0)
+ if ($output_receipt==NULL)
{
- $this->feedback[$cnt_feedback]['file'] = 'stamp.pdf';
- $this->feedback[$cnt_feedback]['message'] = ' cannot convert
to PDF';
- $this->feedback[$cnt_feedback]['error'] = $status;
- $cnt_feedback++;
continue;
}
+ $output=$output_receipt['output'];
+ $file_pdf=$output_receipt['filepdf'];
-
- $progress->increment($step);
- //
- // remove extension
- $ext = strrpos($filename, ".");
- $file_pdf = substr($filename, 0, $ext);
- $file_pdf .=".pdf";
+ // export also the receipt of reconcilied operation
+ $a_reconcilied_operation=[];
+ if ( $reconcilied_document == 1 ) {
+ $a_reconcilied_operation=$cn->get_array("select
jr_id,jra_concerned
+ from jrn_rapt where jra_concerned=$1 or jr_id=$1",
[$value]);
+ }
- //-----------------------------------
- // Fix broken PDF , actually pdftk can not handle all the PDF
- if ( FIX_BROKEN_PDF == 'YES' && PDF2PS != 'NOT' && PS2PDF !=
'NOT') {
-
- $stmpt = PDF2PS." ". escapeshellarg($this->store_convert . '/'
. $file_pdf)." ". escapeshellarg($this->store_convert . '/' . $file_pdf.'.ps');
-
- passthru($stmpt,$status);
-
- if ($status <> 0)
+ // for each reconcilied operation , export the receipt and
concantenate
+ foreach ($a_reconcilied_operation as $reconcilied_operation)
+ {
+
$op=($reconcilied_operation['jr_id']==$value)?$reconcilied_operation['jra_concerned']:$reconcilied_operation['jr_id'];
+
+ $output_rec=$this->export_receipt($op, $progress, $step);
+ if ($output_rec==NULL)
{
- $this->feedback[$cnt_feedback]['file'] =
$this->store_convert . '/' . $file_pdf;
- $this->feedback[$cnt_feedback]['message'] = ' cannot force
to PDF';
- $this->feedback[$cnt_feedback]['error'] = $status;
- $cnt_feedback++;
continue;
}
- $stmpt = PS2PDF." ". escapeshellarg($this->store_convert . '/'
. $file_pdf.'.ps')." ". escapeshellarg($this->store_convert . '/' .
$file_pdf.'.2');
-
- passthru($stmpt,$status);
-
- if ($status <> 0)
+ // concatenate detail operation with the output
+ $output3=$this->store_convert.'/tmp_operation_'.$file_pdf;
+
+ $stmt=PDFTK." ".$output." ".$output_rec['output'].
+ ' output '.$output3;
+
+ passthru($stmt, $status);
+ if ($status<>0)
{
- $this->feedback[$cnt_feedback]['file'] =
$this->store_convert . '/' . $file_pdf;
- $this->feedback[$cnt_feedback]['message'] = ' cannot force
to PDF';
- $this->feedback[$cnt_feedback]['error'] = $status;
+ $cnt_feedback=count($this->feedback);
+ $this->feedback[$cnt_feedback]['file']=$output3;
+ $this->feedback[$cnt_feedback]['message']=_('Echec ');
+ $this->feedback[$cnt_feedback]['error']=$status;
$cnt_feedback++;
continue;
}
- rename ($this->store_convert . '/' .
$file_pdf.'.2',$this->store_convert . '/' . $file_pdf);
+ unlink($output_rec['output']);
+ rename($output3, $output);
}
$progress->increment($step);
- // output
- $output = $this->store_convert . '/stamp_' . $file_pdf;
-
- // Concatenate stamp + file
- $stmt = PDFTK . " " . escapeshellarg($this->store_convert . '/' .
$file_pdf) . ' stamp ' . $this->store_convert .
- '/stamp.pdf output ' . $output;
-
- passthru($stmt, $status);
- if ($status <> 0)
- {
- $this->feedback[$cnt_feedback]['file'] = $file_pdf;
- $this->feedback[$cnt_feedback]['message'] = _(' ne peut pas
convertir en PDF');
- $this->feedback[$cnt_feedback]['error'] = $status;
- $cnt_feedback++;
- continue;
- }
-
// create the pdf with the detail of operation
- $detail_operation = new PDF_Operation($cn,$value);
- $detail_operation->export_pdf(array("acc","anc"));
+ $detail_operation=new PDF_Operation($cn, $value);
+ $detail_operation->export_pdf(array("acc", "anc"));
// output 2
- $output2 = $this->store_convert . '/operation_' . $file_pdf;
-
+ $output2=$this->store_convert.'/operation_'.$file_pdf;
+
// concatenate detail operation with the output
- $stmt = PDFTK . " " . $detail_operation->get_pdf_filename()."
".$output.
- ' output ' . $output2;
-
+ $stmt=PDFTK." ".$detail_operation->get_pdf_filename()." ".$output.
+ ' output '.$output2;
+
$progress->increment($step);
passthru($stmt, $status);
- if ($status <> 0)
+ if ($status<>0)
{
-
- $this->feedback[$cnt_feedback]['file'] = $file_pdf;
- $this->feedback[$cnt_feedback]['message'] = _('Echec Ajout
detail ');
- $this->feedback[$cnt_feedback]['error'] = $status;
+ $cnt_feedback=count($this->feedback);
+ $this->feedback[$cnt_feedback]['file']=$output2;
+ $this->feedback[$cnt_feedback]['message']=_('Echec Ajout
detail ');
+ $this->feedback[$cnt_feedback]['error']=$status;
$cnt_feedback++;
continue;
}
// remove doc with detail
$detail_operation->unlink();
-
+
// overwrite old with new PDF
- rename ($output2,$output);
-
+ rename($output2, $output);
+
// Move the PDF into another temp directory
- $this->move_file($output, 'stamp_' . $file_pdf);
+ $this->move_file($output, 'stamp_'.$file_pdf);
}
-
+
$progress->set_value(93);
- if ( $p_separate == 1) {
+ if ($p_separate==1)
+ {
// concatenate all pdf into one
$this->concatenate_pdf();
-
ob_clean();
$this->send_pdf();
-
- } else {
+ }
+ else
+ {
// Put all PDF In a zip file
$this->make_zip();
ob_clean();
@@ -322,10 +277,10 @@ class Document_Export
$progress->set_value(100);
// remove files from "conversion folder"
- // $this->clean_folder();
-
+ // $this->clean_folder();
}
- /**
+
+ /**
* @brief check that the files are installed
* throw a exception if one is missing
*/
@@ -345,4 +300,135 @@ class Document_Export
}
}
+ /**
+ * @brief export a file (
+ * @param type $p_jrn_id
+ * @param $progress
+ * @return string
+ */
+ function export_receipt($p_jrn_id, Progress_Bar $progress,$step)
+ {
+ global $cn;
+ $cnt_feedback=count($this->feedback);
+
+ // 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($p_jrn_id));
+
+
+ if ($file[0]['jr_pj']=='')
+ {
+ return null;
+ }
+
+
+ $filename=clean_filename($file[0]['jr_pj_name']);
+
+ $cn->start();
+ $cn->lo_export($file[0]['jr_pj'], $this->store_convert.'/'.$filename);
+ $cn->commit();
+
+ // Convert this file into PDF
+ if ($file[0]['jr_pj_type']!='application/pdf')
+ {
+ $status=0;
+ $arg="
".escapeshellarg($this->store_convert.DIRECTORY_SEPARATOR.$filename);
+ echo "arg = [".$arg."]";
+ passthru(OFFICE." ".$arg, $status);
+ if ($status<>0)
+ {
+ $this->feedback[$cnt_feedback]['file']=$filename;
+ $this->feedback[$cnt_feedback]['message']=' cannot convert to
PDF';
+ $this->feedback[$cnt_feedback]['error']=$status;
+ return null;
+ }
+ }
+ // Create a image with the stamp + formula
+ $img=imagecreatefromgif(NOALYSS_INCLUDE.'/template/template.gif');
+ $font=imagecolorallocatealpha($img, 100, 100, 100, 110);
+ imagettftext($img, 40, 25, 500, 1000, $font,
+ NOALYSS_INCLUDE.'/tfpdf/font/unifont/DejaVuSans.ttf'
+ , _("Copie certifiée conforme à l'original"));
+ imagettftext($img, 40, 25, 550, 1100, $font,
+ NOALYSS_INCLUDE.'/tfpdf/font/unifont/DejaVuSans.ttf'
+ , $file[0]['jr_pj_number']);
+ imagettftext($img, 40, 25, 600, 1200, $font,
+ NOALYSS_INCLUDE.'/tfpdf/font/unifont/DejaVuSans.ttf'
+ , $file[0]['jr_pj_name']);
+ imagegif($img, $this->store_convert.'/'.'stamp.gif');
+
+ // transform gif file to pdf with convert tool
+ $stmt=CONVERT_GIF_PDF."
".escapeshellarg($this->store_convert.'/'.'stamp.gif')." "
+ .escapeshellarg($this->store_convert.'/stamp.pdf');
+ passthru($stmt, $status);
+ if ($status<>0)
+ {
+ $this->feedback[$cnt_feedback]['file']='stamp.pdf';
+ $this->feedback[$cnt_feedback]['message']=' cannot convert to PDF';
+ $this->feedback[$cnt_feedback]['error']=$status;
+ return null;
+ }
+
+
+ $progress->increment($step);
+ //
+ // remove extension
+ $ext=strrpos($filename, ".");
+ $file_pdf=substr($filename, 0, $ext);
+ $file_pdf.=".pdf";
+
+ //-----------------------------------
+ // Fix broken PDF , actually pdftk can not handle all the PDF
+ if (FIX_BROKEN_PDF=='YES'&&PDF2PS!='NOT'&&PS2PDF!='NOT')
+ {
+
+ $stmpt=PDF2PS."
".escapeshellarg($this->store_convert.'/'.$file_pdf).
+ "
".escapeshellarg($this->store_convert.'/'.$file_pdf.'.ps');
+
+ passthru($stmpt, $status);
+
+ if ($status<>0)
+ {
+
$this->feedback[$cnt_feedback]['file']=$this->store_convert.'/'.$file_pdf;
+ $this->feedback[$cnt_feedback]['message']=' cannot force to
PDF';
+ $this->feedback[$cnt_feedback]['error']=$status;
+ $cnt_feedback++;
+ return null;
+ }
+ $stmpt=PS2PDF."
".escapeshellarg($this->store_convert.'/'.$file_pdf.'.ps').
+ "
".escapeshellarg($this->store_convert.'/'.$file_pdf.'.2');
+
+ passthru($stmpt, $status);
+
+ if ($status<>0)
+ {
+
$this->feedback[$cnt_feedback]['file']=$this->store_convert.'/'.$file_pdf;
+ $this->feedback[$cnt_feedback]['message']=' cannot force to
PDF';
+ $this->feedback[$cnt_feedback]['error']=$status;
+ $cnt_feedback++;
+ return null;
+ }
+ rename($this->store_convert.'/'.$file_pdf.'.2',
$this->store_convert.'/'.$file_pdf);
+ }
+ $progress->increment($step);
+ // output
+ $output=$this->store_convert.'/stamp_'.$file_pdf;
+
+ // Concatenate stamp + file
+ $stmt=PDFTK." ".escapeshellarg($this->store_convert.'/'.$file_pdf)
+ .' stamp '.$this->store_convert.
+ '/stamp.pdf output '.$output;
+
+ passthru($stmt, $status);
+ if ($status<>0)
+ {
+
+ $this->feedback[$cnt_feedback]['file']=$file_pdf;
+ $this->feedback[$cnt_feedback]['message']=_(' ne peut pas
convertir en PDF');
+ $this->feedback[$cnt_feedback]['error']=$status;
+ return null;
+ }
+ return array("output"=>$output,"filepdf"=>$file_pdf);
+ }
+
}
diff --git a/include/class/pdf_operation.class.php
b/include/class/pdf_operation.class.php
index 3403d01..d7f4b7f 100644
--- a/include/class/pdf_operation.class.php
+++ b/include/class/pdf_operation.class.php
@@ -272,6 +272,24 @@ class PDF_Operation extends PDF {
$this->pdf->line_new(6);
}
}
+ /**
+ * print reconcilied operations
+ */
+ private function print_reconcilied_operation()
+ {
+ // find the reconcilied operations
+ $a_reconcilied_operation=$this->cn->get_array("select
jr_id,jra_concerned from jrn_rapt where jra_concerned=$1 or jr_id=$1",
+ [$this->jr_id]);
+ $this->print_section(_("Opérations rapprochées"));
+ // for each operation , print info (amount, ledger,... )
+ foreach ($a_reconcilied_operation as $reconcilied_operation) {
+
$op=($reconcilied_operation['jr_id']==$this->jr_id)?$reconcilied_operation['jra_concerned']:$reconcilied_operation['jr_id'];
+ $operation=new PDF_Operation($this->cn,$op);
+ $operation->pdf=$this->pdf;
+ $operation->print_operation_info();
+ }
+
+ }
private function print_anc_header($pa_plan) {
$nb=count($pa_plan);
$this->pdf->SetFont('DejaVu', 'B', 8);
@@ -427,6 +445,8 @@ class PDF_Operation extends PDF {
//write date + ledger + detail items + total
$this->print_operation_info();
+
+
// Write only for Sale or purchase summary (QCode, label,amount,tva...)
$this->print_operation_quant();
@@ -441,6 +461,8 @@ class PDF_Operation extends PDF {
if (array_search("anc", $p_option) !== false )
$this->print_anc_writing();
+ // write information for reconcilied operations
+ $this->print_reconcilied_operation();
// if option contains EXTEND add document name + comment + action name
// if options contains ANC export ANC plan table
}
diff --git a/include/export/export_anc_receipt_pdf.php
b/include/export/export_anc_receipt_pdf.php
index 0c6e525..45d5ef0 100644
--- a/include/export/export_anc_receipt_pdf.php
+++ b/include/export/export_anc_receipt_pdf.php
@@ -40,8 +40,9 @@ if ($ck == 0)
}
$anc=new Document_Export();
$type_pdf=$http->get("type_pdf","number",1);
+$reconcilied_document=$http->get("reconcilied_document","number",1);
$task_id=$http->request("task_id");
$progress=new Progress_Bar($task_id);
-$anc->export_all($ck,$progress,$type_pdf);
+$anc->export_all($ck,$progress,$type_pdf,$reconcilied_document);
- [Noalyss-commit] [noalyss] 07/46: ocument : add phpunit test, (continued)
- [Noalyss-commit] [noalyss] 07/46: ocument : add phpunit test, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 11/46: protect SQL, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 16/46: Improve email sent : check if file attached, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 15/46: Task #0001417: Reconnexion souple connect, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 09/46: Add waiting_box, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 17/46: Task #0001595: CA - liste d'opérations - pas de choix de l'execice., Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 19/46: clean code : remove useless comment, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 20/46: New #0001983: CA - permettre désactivation poste, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 18/46: Bug: possible to set an empy name for an Analytic plan, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 21/46: Bug #0002011: Encodage opération – Verrouillage nombre de lignes si non vides, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 23/46: Task #0002014: Comptabilité analytique = export des pièces des opérations rapprochées,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 27/46: Task #0002014: Comptabilité analytique ordre par date Database_Core setter/getter for sql, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 24/46: Task #0001974: Duplication d'opération – Inclure l'intitulé, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 33/46: If database connx failed then reload the form, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 12/46: Merge branch 'master' of gitlab.noalyss.eu:noalyss/noalyss, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 22/46: Cosmetic, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 26/46: Typo menu, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 28/46: Task #0002015: Export CSV depuis ANCGL : ajout de colonnes, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 29/46: Use autoload, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 31/46: Module decrease font-size, Dany De Bontridder, 2021/07/13
- [Noalyss-commit] [noalyss] 32/46: Code Cleaning #0002022: Utilisation d'un autoloader, Dany De Bontridder, 2021/07/13