diff --git a/include/class/anc_acc_link.class.php b/include/class/anc_acc_link.class.php
index 48321a0de..aeea0bbc1 100644
--- a/include/class/anc_acc_link.class.php
+++ b/include/class/anc_acc_link.class.php
@@ -31,6 +31,8 @@ class Anc_Acc_Link extends Anc_Print
{
function __contruct($p_cn)
{
+ parent::__construct($p_cn);
+ //@todo to remove = useless since the parent has a database object $db
$this->cn=$p_cn;
}
diff --git a/include/class/anc_acc_list.class.php b/include/class/anc_acc_list.class.php
index 2b62f8657..3677b343a 100644
--- a/include/class/anc_acc_list.class.php
+++ b/include/class/anc_acc_list.class.php
@@ -20,7 +20,8 @@
// Copyright Author Dany De Bontridder danydb@aevalys.eu
/*!\file
- * \brief
+ * \brief Anc_Acc_List Manage the class for reporting about Analytic Accountancy and Accountancy : card - analytic account,
+ * accounting - analytic account,
*/
/*!
@@ -130,12 +131,10 @@ with m as (select oa_id, po_id,
WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = operation_analytique.f_id)
end
AS name,
- case when jrnx.j_poste is not null then
- jrnx.j_poste
- when jrnx.j_poste is null then
- (SELECT fiche_detail.ad_value
- FROM fiche_detail
- WHERE fiche_detail.ad_id = 5 AND fiche_detail.f_id = operation_analytique.f_id) end as j_qcode
+ case when jrnx.j_qcode is not null then
+ jrnx.j_qcode
+ when jrnx.j_qcode is null then
+ jrnx.j_poste end as j_qcode
FROM operation_analytique
left JOIN jrnx USING (j_id) )
SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
@@ -321,6 +320,19 @@ order by
$r.= dossier::hidden();
$r.=HtmlInput::submit('bt_csv',"Export en CSV");
$r.= '';
+ $r.= '
';
return $r;
}
/**
@@ -571,20 +583,18 @@ order by
for ($i=0;$iarow);$i++)
{
- $idx=0;
- $a_csv=array();
- $a_csv[$idx]=$this->arow[$i]['j_qcode']; $idx++;
- $a_csv[$idx]=$this->arow[$i]['name'];$idx++;
- $a_csv[$idx]=$this->arow[$i]['name'];$idx++;
- $a_csv[$idx]=$this->arow[$i]['po_name'];$idx++;
- $a_csv[$idx]=$this->arow[$i]['po_description'];$idx++;
+ $csv->add($this->arow[$i]['j_qcode']);
+ $csv->add($this->arow[$i]['name']);
+ $csv->add($this->arow[$i]['name']);
+ $csv->add($this->arow[$i]['po_name']);
+ $csv->add($this->arow[$i]['po_description']);
$amount=$this->arow[$i]['sum_amount'];
if ($amount==null)$amount=0;
- $a_csv[$idx]=$amount;$idx++;
+ $csv->add($amount,"number");
- $csv->write_header($a_csv);
+ $csv->write();
}
}
//---------------------------------------------------------------------------
@@ -674,5 +684,5 @@ order by
}
-
+
}
\ No newline at end of file
diff --git a/include/class/pdf_anc_acc_list.class.php b/include/class/pdf_anc_acc_list.class.php
new file mode 100644
index 000000000..8be98febb
--- /dev/null
+++ b/include/class/pdf_anc_acc_list.class.php
@@ -0,0 +1,279 @@
+
+
+/**
+ * @file
+ * @brief
+ */
+/* !
+ * \class
+ * \brief export Anc_Acc_List (ANCBCC) to PDF
+ */
+
+class PDF_Anc_Acc_List extends PDF
+{
+
+ private $anc_acc_list;
+ private $str_title;
+ private $a_size;
+
+ function __construct(Anc_Acc_List $p_anc_acc_list)
+ {
+ parent::__construct($p_anc_acc_list->db);
+ $this->anc_acc_list=$p_anc_acc_list;
+ $a_title=array(
+ 1=>_('Comptabilité Analytique Fiche/Activité'),
+ 2=>_("Comptabilité Analytique Poste comptable/Activité"),
+ 3=>_('Comptabilité Analytique Activité/Fiche'),
+ 4=>_('Comptabilité Analytique Activité/Poste Comptable'));
+ if (!isset($a_title[$p_anc_acc_list->card_poste]))
+ {
+ throw new Exception("PAAL.46 : invalid object");
+ }
+ $this->str_title=$a_title[$p_anc_acc_list->card_poste];
+ }
+ /**
+ * @brief Display the total amount
+ * @param type $p_pdf
+ * @param type $p_total
+ */
+ private function put_total($a_size,$p_pdf, $p_total)
+ {
+ $p_pdf->SetFont('DejaVu', 'B', 7);
+ $p_pdf->write_cell($a_size['po_name']+$a_size['po_description'], 5, _("Total"));
+ $p_pdf->write_cell($a_size['po_amount'], 5, nbm($p_total, 2), 0, 0, 'R');
+ $p_pdf->line_new(5);
+ }
+ /**
+ * @brief Print the title
+ * @param PDF $p_pdf
+ * @param int $n_row_idx , idx of anc_acc_list->arow
+ */
+ private function put_title($p_pdf, $n_row_idx)
+ {
+ $p_pdf->SetFont('DejaVu', 'BU', 10);
+ switch ($this->anc_acc_list->card_poste)
+ {
+ case 1:
+
+ $p_pdf->write_cell(190, 12,
+ $this->anc_acc_list->arow[$n_row_idx]['j_qcode']." ".
+ $this->anc_acc_list->arow[$n_row_idx]['name']);
+
+ break;
+ case 2:
+
+ $p_pdf->write_cell(190, 12,
+ $this->anc_acc_list->arow[$n_row_idx]['j_poste']." ".
+ $this->anc_acc_list->arow[$n_row_idx]['name']);
+
+ break;
+ case 3:
+
+ $p_pdf->write_cell(190, 12,
+ $this->anc_acc_list->arow[$n_row_idx]['po_name']." ".
+ $this->anc_acc_list->arow[$n_row_idx]['po_description']);
+
+ break;
+ case 4:
+
+ $p_pdf->write_cell(190, 12,
+ $this->anc_acc_list->arow[$n_row_idx]['po_name']." ".
+ $this->anc_acc_list->arow[$n_row_idx]['po_description']);
+
+ break;
+ default:
+ break;
+ }
+ $p_pdf->line_new();
+ }
+ /**
+ * @brief Return the previous item : card or account or activity depending of the crossing method
+ * @param type $n_row_idx
+ * @return type
+ */
+ private function get_previous($n_row_idx)
+ {
+ switch ($this->anc_acc_list->card_poste)
+ {
+ case 1:
+ return $this->anc_acc_list->arow[$n_row_idx]['f_id'];
+ break;
+ case 2:
+ return $this->anc_acc_list->arow[$n_row_idx]['j_poste'];
+ break;
+ case 3:
+ return $this->anc_acc_list->arow[$n_row_idx]['po_id'];
+ break;
+ case 4:
+ return $this->anc_acc_list->arow[$n_row_idx]['po_id'];
+ break;
+ }
+ }
+ /**
+ * @brief
+ * @return \PDF
+ */
+ private function pdf_card()
+ {
+ $pdf=new PDF($this->anc_acc_list->db);
+ $pdf->setDossierInfo(_("Balance croisée A/C"));
+ $pdf->SetTitle($this->str_title);
+ $pdf->AddPage();
+ $pdf->SetFont('DejaVu', 'B', 12);
+ $pdf->write_cell(190, 12, $this->str_title, 1);
+ $pdf->AliasNbPages();
+
+ $nb_row=count($this->anc_acc_list->arow);
+ $a_size=array("po_name"=>60, "po_description"=>100, "po_amount"=>30);
+ $pdf->line_new(20);
+ $pdf->SetFont('DejaVu', '', 7);
+ $tot_card=0; $tot_glob=0;
+ for ($i=0; $i<$nb_row; $i++)
+ {
+ $fill=$pdf->is_fill($i+1);
+ if ($i==0)
+ {
+ $prev=$this->get_previous($i);
+ $this->put_title($pdf, $i);
+ $pdf->SetFont('DejaVu', '', 7);
+ }
+ if ($prev!=$this->get_previous($i))
+ {
+ $prev=$this->get_previous($i);
+ $this->put_total($a_size,$pdf,$tot_card);
+
+ $this->put_title($pdf, $i);
+ $pdf->SetFont('DejaVu', '', 7);
+ $tot_card=0;
+ }
+ $this->anc_acc_list->arow[$i]['sum_amount']=($this->anc_acc_list->arow[$i]['sum_amount']=="")?0:
+ $this->anc_acc_list->arow[$i]['sum_amount'];
+
+ $tot_card=bcadd($tot_card, $this->anc_acc_list->arow[$i]['sum_amount'], 2);
+ $tot_glob=bcadd($tot_glob, $this->anc_acc_list->arow[$i]['sum_amount'], 2);
+ if ($this->anc_acc_list->card_poste<3)
+ {
+ $pdf->write_cell($a_size['po_name'], 4, $this->anc_acc_list->arow[$i]['po_name'], 0, 0, 'L', $fill);
+ $pdf->write_cell($a_size['po_description'], 4, $this->anc_acc_list->arow[$i]['po_description'], 0, 0,
+ 'L', $fill);
+ $pdf->write_cell($a_size['po_amount'], 4, nbm($this->anc_acc_list->arow[$i]['sum_amount'], 2), 0, 0,
+ 'R', $fill);
+ }
+ elseif ($this->anc_acc_list->card_poste==3)
+ {
+ $pdf->write_cell($a_size['po_name'], 4, $this->anc_acc_list->arow[$i]['j_qcode'], 0, 0, 'L', $fill);
+ $pdf->write_cell($a_size['po_description'], 4, $this->anc_acc_list->arow[$i]['name'], 0, 0, 'L', $fill);
+ $pdf->write_cell($a_size['po_amount'], 4, nbm($this->anc_acc_list->arow[$i]['sum_amount'], 2), 0, 0,
+ 'R', $fill);
+ }
+ elseif ($this->anc_acc_list->card_poste==4)
+ {
+ $pdf->write_cell($a_size['po_name'], 4, $this->anc_acc_list->arow[$i]['j_poste'], 0, 0, 'L', $fill);
+ $pdf->write_cell($a_size['po_description'], 4, $this->anc_acc_list->arow[$i]['name'], 0, 0, 'L', $fill);
+ $pdf->write_cell($a_size['po_amount'], 4, nbm($this->anc_acc_list->arow[$i]['sum_amount'], 2), 0, 0,
+ 'R', $fill);
+ }
+ $pdf->line_new();
+ }
+ $this->put_total($a_size,$pdf,$tot_card);
+ $pdf->SetFont('DejaVu', '', 7);
+
+ $pdf->line_new(5);
+ $pdf->write_cell($a_size['po_name']+$a_size['po_description'], 10, _("Total Global"),'LBT');
+ $pdf->write_cell($a_size['po_amount'], 10, nbm($tot_glob, 2), 'RBT', 0, 'R');
+ $pdf->line_new();
+ return $pdf;
+ }
+
+ public function get_a_size()
+ {
+ return $this->a_size;
+ }
+
+ public function set_a_size($a_size): PDF_Anc_Acc_List
+ {
+ $this->a_size=$a_size;
+ return $this;
+ }
+
+ public function get_anc_acc_list()
+ {
+ return $this->anc_acc_list;
+ }
+
+ public function get_str_title()
+ {
+ return $this->str_title;
+ }
+
+ public function set_anc_acc_list($anc_acc_list): PDF_Anc_Acc_List
+ {
+ $this->anc_acc_list=$anc_acc_list;
+ return $this;
+ }
+
+ public function set_str_title($str_title): PDF_Anc_Acc_List
+ {
+ $this->str_title=$str_title;
+ return $this;
+ }
+ /**
+ * @brief Main function , export the ANCBCC list to PDF, crossed by activity , account or card
+ * @return type
+ * @throws Exception
+ */
+ function export_pdf()
+ {
+
+ if ($this->anc_acc_list->check()!=0)
+ {
+ throw new Exception(_("date invalide"));
+ }
+ switch ($this->anc_acc_list->card_poste)
+ {
+ case 1:
+ // Card - Acc
+ $this->anc_acc_list->load_card();
+ return $this->pdf_card();
+ break;
+ case 2:
+ // Accountancy - Analytic
+ $this->anc_acc_list->load_poste();
+ return $this->pdf_card();
+ break;
+ case 3:
+ // Acc after card
+ $this->anc_acc_list->load_anc_card();
+ return $this->pdf_card();
+ break;
+ case 4:
+ // Analytic - Accountancy
+ $this->anc_acc_list->load_anc_account();
+ return $this->pdf_card();
+ break;
+ default:
+ throw new Exception('AAL700:unknown export');
+ }
+ return;
+ }
+
+}
diff --git a/include/constant.php b/include/constant.php
index ce5670ec1..22cb41ea8 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -116,7 +116,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) {
if ( ! defined ("SYSINFO_DISPLAY")) {
define ("SYSINFO_DISPLAY",TRUE);
}
-define ("DBVERSION",169);
+define ("DBVERSION",170);
define ("MONO_DATABASE",25);
define ("DBVERSIONREPO",20);
define ('NOTFOUND','--not found--');
@@ -597,7 +597,8 @@ function noalyss_class_autoloader($class) {
"mobile_device_mtable"=>"class/mobile_device_mtable.class.php",
"html_input_noalyss"=>"class/html_input_noalyss.class.php",
"card_property"=>"class/card_property.class.php",
- "pdfland"=>"class/pdf_land.class.php"
+ "pdfland"=>"class/pdf_land.class.php",
+ "pdf_anc_acc_list"=>"class/pdf_anc_acc_list.class.php"
);
if ( isset ($aClass[$class]) ) {
require_once NOALYSS_INCLUDE."/".$aClass[$class];
diff --git a/include/export/export_anc_acc_list_pdf.php b/include/export/export_anc_acc_list_pdf.php
new file mode 100644
index 000000000..35e648709
--- /dev/null
+++ b/include/export/export_anc_acc_list_pdf.php
@@ -0,0 +1,34 @@
+
+
+if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
+
+/**
+ * @file
+ * @brief export ANCBCC in PDF
+ */
+
+$bal=new Anc_Acc_List($cn);
+$bal->get_request();
+$pdf=new PDF_Anc_Acc_List($bal);
+$fDate=date('dmy-Hi');
+
+$pdf->export_pdf()->Output( "balance-acc-anc-$fDate.pdf", 'D');
diff --git a/include/sql/patch/upgrade169.sql b/include/sql/patch/upgrade169.sql
new file mode 100644
index 000000000..a8bf261b1
--- /dev/null
+++ b/include/sql/patch/upgrade169.sql
@@ -0,0 +1,6 @@
+begin;
+INSERT INTO public.menu_ref (me_code, me_menu, me_file, me_url, me_description, me_parameter, me_javascript, me_type, me_description_etendue) VALUES('PDF:AncAccList', 'Export Historique Compt. Analytique', 'export_anc_acc_list_pdf.php', NULL, NULL, NULL, NULL, 'PR', NULL);
+
+insert into profile_menu (me_code,p_id,p_type_displayn,pm_default) select 'PDF:AncAccList',p_id,p_type_display,pm_default from profile_menu pm where me_code='CSV:AncAccList';
+insert into version (val,v_description) values (170,'new : export in PDF balance Analytic / Accountancy');
+commit ;
\ No newline at end of file
diff --git a/unit-test/include/class/pdf_anc_acc_list.Test.php b/unit-test/include/class/pdf_anc_acc_list.Test.php
new file mode 100644
index 000000000..fbbfd3bf2
--- /dev/null
+++ b/unit-test/include/class/pdf_anc_acc_list.Test.php
@@ -0,0 +1,163 @@
+
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ *
+ * Author : Dany De Bontridder danydb@noalyss.eu
+ *
+ */
+
+/**
+ * @file
+ * @brief
+ */
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @backupGlobals enabled
+ */
+require 'global.php';
+
+class PDF_Anc_Acc_ListTest extends TestCase
+{
+
+ /**
+ * @var Fiche
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test method is executed.
+ */
+ protected function setUp()
+ {
+ include 'global.php';
+
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test method is executed.
+ */
+ protected function tearDown()
+ {
+
+ }
+
+ /**
+ * the setUpBeforeClass() template methods is called before the first test of the test case
+ * class is run
+ */
+ public static function setUpBeforeClass()
+ {
+ include 'global.php';
+ // insert data into operation_analytique
+ $sql=<<exec_sql($sql);
+ }
+
+ /**
+ * tearDownAfterClass() template methods is calleafter the last test of the test case class is run,
+ *
+ */
+ static function tearDownAfterClass()
+ {
+ include 'global.php';
+ global $g_connection;
+ $g_connection->exec_sql("delete from operation_analytique");
+ }
+
+
+ /**
+ * @brief
+ * @testdox Export to PDF
+ * @param type $p_param
+ * @covers
+ */
+ public function testPdf_Card()
+ {
+ global $g_connection;
+
+ // By card
+
+ $anc_acc_list=new Anc_Acc_List($g_connection);
+ $anc_acc_list->to='31.12.2019';
+ $anc_acc_list->from='01.01.2019';
+ $anc_acc_list->pa_id=1;
+ $anc_acc_list->card_poste=1;
+ $pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
+ $pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-card-activity.pdf","F");
+ $this->assertEquals(76920,filesize(__DIR__."/file/pdf_anc_acc_list-card-activity.pdf"),
+ __DIR__."/file/pdf_anc_acc_list-card-activity.pdf incorrect");
+
+ // By Account / Activity
+ $anc_acc_list=new Anc_Acc_List($g_connection);
+ $anc_acc_list->to='31.12.2019';
+ $anc_acc_list->from='01.01.2019';
+ $anc_acc_list->pa_id=1;
+ $anc_acc_list->card_poste=2;
+ $pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
+ $pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-account-activity.pdf","F");
+ $this->assertEquals(77152,filesize(__DIR__."/file/pdf_anc_acc_list-account-activity.pdf"),
+ __DIR__."/file/pdf_anc_acc_list-account-activity.pdf incorrect ");
+
+ // By Activity / Card
+ $anc_acc_list=new Anc_Acc_List($g_connection);
+ $anc_acc_list->to='31.12.2019';
+ $anc_acc_list->from='01.01.2019';
+ $anc_acc_list->pa_id=1;
+ $anc_acc_list->card_poste=3;
+ $pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
+ $pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-activity-card.pdf","F");
+ $this->assertEquals(77690,filesize(__DIR__."/file/pdf_anc_acc_list-activity-card.pdf"),
+ __DIR__."/file/pdf_anc_acc_list-activity-card.pdf incorrect");
+
+ // By Activity / Account
+ $anc_acc_list=new Anc_Acc_List($g_connection);
+ $anc_acc_list->to='31.12.2019';
+ $anc_acc_list->from='01.01.2019';
+ $anc_acc_list->pa_id=1;
+ $anc_acc_list->card_poste=4;
+ $pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
+ $pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf","F");
+ $this->assertEquals(76411,filesize(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf"),
+ __DIR__."/file/pdf_anc_acc_list-activity-account.pdf incorrect");
+ }
+
+}