From 25ef8ad6892ef3cc2fb0c979195b16d580f6950e Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 27 Jul 2019 17:50:42 +0200 Subject: [PATCH] Code Cleaning split PDF into PDF_Core and PDF --- include/class/anc_balance_double.class.php | 2 +- include/class/anc_balance_simple.class.php | 2 +- include/class/pdf.class.php | 144 ++++++ include/class/pdf_land.class.php | 71 +++ include/class/pdf_operation.class.php | 2 +- include/class/pdfbalance_simple.class.php | 63 +++ include/class/print_ledger_detail.class.php | 2 +- include/class/print_ledger_fin.class.php | 2 +- include/class/print_ledger_misc.class.php | 2 +- include/class/print_ledger_simple.class.php | 2 +- .../print_ledger_simple_without_vat.class.php | 2 +- include/export/export_balance_pdf.php | 3 +- include/export/export_fiche_balance_pdf.php | 2 +- include/export/export_fiche_detail_pdf.php | 2 +- include/export/export_fiche_pdf.php | 2 +- include/export/export_form_pdf.php | 4 +- include/export/export_gl_pdf.php | 2 +- include/export/export_ledger_pdf.php | 2 +- include/export/export_poste_detail_pdf.php | 2 +- include/export/export_security_pdf.php | 2 +- include/lib/pdf.class.php | 414 ------------------ include/lib/pdf_core.class.php | 225 ++++++++++ 22 files changed, 522 insertions(+), 432 deletions(-) create mode 100644 include/class/pdf.class.php create mode 100644 include/class/pdf_land.class.php create mode 100644 include/class/pdfbalance_simple.class.php delete mode 100644 include/lib/pdf.class.php create mode 100644 include/lib/pdf_core.class.php diff --git a/include/class/anc_balance_double.class.php b/include/class/anc_balance_double.class.php index 92337a374..0851e5bb6 100644 --- a/include/class/anc_balance_double.class.php +++ b/include/class/anc_balance_double.class.php @@ -30,7 +30,7 @@ require_once NOALYSS_INCLUDE.'/lib/ibutton.class.php'; require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php'; require_once NOALYSS_INCLUDE.'/class/anc_print.class.php'; require_once NOALYSS_INCLUDE.'/class/anc_plan.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; /** * @class * @brief Print the crossed balance between 2 plan diff --git a/include/class/anc_balance_simple.class.php b/include/class/anc_balance_simple.class.php index 4766cc365..6a9764eea 100644 --- a/include/class/anc_balance_simple.class.php +++ b/include/class/anc_balance_simple.class.php @@ -27,7 +27,7 @@ require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php'; require_once NOALYSS_INCLUDE.'/class/anc_print.class.php'; require_once NOALYSS_INCLUDE.'/class/anc_plan.class.php'; require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdfbalance_simple.class.php'; require_once NOALYSS_INCLUDE.'/header_print.php'; /*! \brief manage the simple balance for CA, inherit from balance_ca * diff --git a/include/class/pdf.class.php b/include/class/pdf.class.php new file mode 100644 index 000000000..f091ef37d --- /dev/null +++ b/include/class/pdf.class.php @@ -0,0 +1,144 @@ +cn = $p_cn; + + $this->own = new Noalyss_Parameter_Folder($this->cn); + $this->soc = $this->own->MY_NAME; + $this->date = date('d.m.Y'); + parent::__construct($orientation,$unit,$format); + date_default_timezone_set ('Europe/Paris'); + } + function setDossierInfo($dossier = "n/a") + { + $this->dossier = dossier::name()." ".$dossier; + } + function Header() + { + //Arial bold 12 + $this->SetFont('DejaVu', 'B', 12); + //Title + parent::Cell(0,10,$this->dossier, 'B', 0, 'C'); + //Line break + parent::Ln(20); + } + function Footer() + { + //Position at 2 cm from bottom + $this->SetY(-20); + //Arial italic 8 + $this->SetFont('Arial', '', 8); + //Page number + parent::Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); + parent::Ln(3); + // Created by NOALYSS + parent::Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); + } + /** + *@brief retrieve the client name and quick_code + *@param $p_jr_id jrn.jr_id + *@param $p_jrn_type ledger type ACH VEN FIN + *@return array (0=>qcode,1=>name) or for FIN 0=>customer qc 1=>customer name 2=>bank qc 3=>bank name + *@see class_print_ledger_simple, class_print_ledger_simple_without_vat + */ + function get_tiers($p_jr_id,$p_jrn_type) + { + if ( $p_jrn_type=='ACH' ) + { + $array=$this->cn->get_array('SELECT + jrnx.j_grpt, + quant_purchase.qp_supplier, + quant_purchase.qp_internal, + jrn.jr_internal + FROM + public.quant_purchase, + public.jrnx, + public.jrn + WHERE + quant_purchase.j_id = jrnx.j_id AND + jrnx.j_grpt = jrn.jr_grpt_id and jr_id=$1',array($p_jr_id)); + if (count($array)==0) return array("ERREUR $p_jr_id",''); + $customer_id=$array[0]['qp_supplier']; + $fiche=new Fiche($this->cn,$customer_id); + $customer_qc=$fiche->get_quick_code($customer_id); + $customer_name=$fiche->getName(); + return array($customer_qc,$customer_name); + } + if ( $p_jrn_type=='VEN' ) + { + $array=$this->cn->get_array('SELECT + quant_sold.qs_client + FROM + public.quant_sold, + public.jrnx, + public.jrn + WHERE + quant_sold.j_id = jrnx.j_id AND + jrnx.j_grpt = jrn.jr_grpt_id and jr_id=$1',array($p_jr_id)); + if (count($array)==0) return array("ERREUR $p_jr_id",''); + $customer_id=$array[0]['qs_client']; + $fiche=new Fiche($this->cn,$customer_id); + $customer_qc=$fiche->get_quick_code($customer_id); + $customer_name=$fiche->getName(); + return array($customer_qc,$customer_name); + } + if ( $p_jrn_type=='FIN' ) + { + $array=$this->cn->get_array('SELECT + qf_other,qf_bank + FROM + public.quant_fin + WHERE + quant_fin.jr_id =$1',array($p_jr_id)); + if (count($array)==0) return array("ERREUR $p_jr_id",'','',''); + $customer_id=$array[0]['qf_other']; + $fiche=new Fiche($this->cn,$customer_id); + $customer_qc=$fiche->get_quick_code($customer_id); + $customer_name=$fiche->getName(); + + $bank_id=$array[0]['qf_bank']; + $fiche=new Fiche($this->cn,$bank_id); + $bank_qc=$fiche->get_quick_code($bank_id); + $bank_name=$fiche->getName(); + + return array($customer_qc,$customer_name,$bank_qc,$bank_name); + } + } + + +} \ No newline at end of file diff --git a/include/class/pdf_land.class.php b/include/class/pdf_land.class.php new file mode 100644 index 000000000..811f39b87 --- /dev/null +++ b/include/class/pdf_land.class.php @@ -0,0 +1,71 @@ +bigger=0; + + parent::__construct($p_cn,'L', $unit, $format); + date_default_timezone_set ('Europe/Paris'); + $this->AddFont('DejaVu','','DejaVuSans.ttf',true); + $this->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true); + $this->AddFont('DejaVu','BI','DejaVuSans-BoldOblique.ttf',true); + $this->AddFont('DejaVuCond','','DejaVuSansCondensed.ttf',true); + $this->AddFont('DejaVuCond','B','DejaVuSansCondensed-Bold.ttf',true); + $this->AddFont('DejaVuCond','I','DejaVuSansCondensed-Oblique.ttf',true); + + $this->cn = $p_cn; + $this->own = new Noalyss_Parameter_Folder($this->cn); + $this->soc = $this->own->MY_NAME; + $this->date = date('d.m.Y'); + } + function Header() + { + //Arial bold 12 + $this->SetFont('DejaVu', 'B', 10); + //Title + $this->Cell(0,10,$this->dossier, 'B', 0, 'C'); + //Line break + $this->Ln(20); + } + function Footer() + { + //Position at 2 cm from bottom + $this->SetY(-20); + //Arial italic 8 + $this->SetFont('DejaVuCond', 'I', 8); + //Page number + $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); + $this->Ln(3); + // Created by NOALYSS + $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); + + } +} \ No newline at end of file diff --git a/include/class/pdf_operation.class.php b/include/class/pdf_operation.class.php index 19dc67d39..867b24392 100644 --- a/include/class/pdf_operation.class.php +++ b/include/class/pdf_operation.class.php @@ -25,7 +25,7 @@ * Detail Operation ACC + ANC , it will use Acc_Operation and Anc_Operation * */ -require_once NOALYSS_INCLUDE . '/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE . '/class/pdf.class.php'; require_once NOALYSS_INCLUDE . '/class/acc_operation.class.php'; require_once NOALYSS_INCLUDE . '/class/acc_ledger.class.php'; require_once NOALYSS_INCLUDE . '/class/acc_operation.class.php'; diff --git a/include/class/pdfbalance_simple.class.php b/include/class/pdfbalance_simple.class.php new file mode 100644 index 000000000..d1da93504 --- /dev/null +++ b/include/class/pdfbalance_simple.class.php @@ -0,0 +1,63 @@ +dossier='Balance simple '.dossier::name(); + $this->from_poste=$p_from_poste; + $this->to_poste=$to_poste; + $this->from=$p_from; + $this->to=$p_to; + } + function Header() + { + parent::Header(); + $this->SetFont('DejaVu','B',8); + $titre=sprintf("Balance simple poste %s %s date %s %s", + $this->from_poste, + $this->to_poste, + $this->from, + $this->to); + $this->Cell(0,7,$titre,1,0,'C'); + + $this->Ln(); + $this->SetFont('DejaVu','',6); + + $this->Cell(110,7,'Poste Comptable','B'); + $this->Cell(20,7,'Débit','B',0,'L'); + $this->Cell(20,7,'Crédit','B',0,'L'); + $this->Cell(20,7,'Solde','B',0,'L'); + $this->Cell(20,7,'D/C','B',0,'L'); + $this->Ln(); + + } +} diff --git a/include/class/print_ledger_detail.class.php b/include/class/print_ledger_detail.class.php index d8c458cd4..2c59ecfb8 100644 --- a/include/class/print_ledger_detail.class.php +++ b/include/class/print_ledger_detail.class.php @@ -23,7 +23,7 @@ * \brief this class extends PDF and let you export the detailled printing * of any ledgers */ -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf_land.class.php'; class Print_Ledger_Detail extends PDF { diff --git a/include/class/print_ledger_fin.class.php b/include/class/print_ledger_fin.class.php index bfa141c81..3fa367fef 100644 --- a/include/class/print_ledger_fin.class.php +++ b/include/class/print_ledger_fin.class.php @@ -22,7 +22,7 @@ /*!\file * \brief print a listing of financial */ -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; class Print_Ledger_Financial extends PDF { private $rap_amount; /* amount from begining exercice */ diff --git a/include/class/print_ledger_misc.class.php b/include/class/print_ledger_misc.class.php index 72910b4e6..037f5378f 100644 --- a/include/class/print_ledger_misc.class.php +++ b/include/class/print_ledger_misc.class.php @@ -22,7 +22,7 @@ /*!\file * \brief print a listing of financial */ -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; class Print_Ledger_Misc extends PDF { function __construct($p_cn,$p_jrn) diff --git a/include/class/print_ledger_simple.class.php b/include/class/print_ledger_simple.class.php index 114d5f201..ef21133cf 100644 --- a/include/class/print_ledger_simple.class.php +++ b/include/class/print_ledger_simple.class.php @@ -23,7 +23,7 @@ * \brief this class extends PDF and let you export the detailled printing * of any ledgers */ -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; class Print_Ledger_Simple extends PDF { diff --git a/include/class/print_ledger_simple_without_vat.class.php b/include/class/print_ledger_simple_without_vat.class.php index ec77e2381..56653592f 100644 --- a/include/class/print_ledger_simple_without_vat.class.php +++ b/include/class/print_ledger_simple_without_vat.class.php @@ -23,7 +23,7 @@ * \brief this class extends PDF and let you export the detailled printing * of any ledgers */ -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; class Print_Ledger_Simple_Without_Vat extends PDF { diff --git a/include/export/export_balance_pdf.php b/include/export/export_balance_pdf.php index f78fc392a..2490bb13f 100644 --- a/include/export/export_balance_pdf.php +++ b/include/export/export_balance_pdf.php @@ -35,7 +35,8 @@ require_once NOALYSS_INCLUDE . '/class/database.class.php'; include_once("class/acc_balance.class.php"); require_once NOALYSS_INCLUDE . '/header_print.php'; require_once NOALYSS_INCLUDE . '/class/dossier.class.php'; -require_once NOALYSS_INCLUDE . '/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE . '/class/pdf.class.php'; +require_once NOALYSS_INCLUDE . '/class/pdf_land.class.php'; require_once NOALYSS_INCLUDE . '/lib/http_input.class.php'; $http = new HttpInput(); diff --git a/include/export/export_fiche_balance_pdf.php b/include/export/export_fiche_balance_pdf.php index e25d87a85..3c027cb53 100644 --- a/include/export/export_fiche_balance_pdf.php +++ b/include/export/export_fiche_balance_pdf.php @@ -27,7 +27,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); // Security we check if user does exist and his privilege require_once NOALYSS_INCLUDE.'/class/user.class.php'; require_once NOALYSS_INCLUDE.'/class/database.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/class/lettering.class.php'; require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; diff --git a/include/export/export_fiche_detail_pdf.php b/include/export/export_fiche_detail_pdf.php index 187d7bf61..de21a96ff 100644 --- a/include/export/export_fiche_detail_pdf.php +++ b/include/export/export_fiche_detail_pdf.php @@ -31,7 +31,7 @@ require_once NOALYSS_INCLUDE.'/class/fiche.class.php'; require_once NOALYSS_INCLUDE.'/header_print.php'; require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_operation.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; $http=new HttpInput(); diff --git a/include/export/export_fiche_pdf.php b/include/export/export_fiche_pdf.php index 04ceae7a0..03585e55a 100644 --- a/include/export/export_fiche_pdf.php +++ b/include/export/export_fiche_pdf.php @@ -28,7 +28,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); // Security we check if user does exist and his privilege require_once NOALYSS_INCLUDE.'/class/user.class.php'; require_once NOALYSS_INCLUDE.'/class/database.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/class/lettering.class.php'; require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; diff --git a/include/export/export_form_pdf.php b/include/export/export_form_pdf.php index a6d5682fe..71ad34ee4 100644 --- a/include/export/export_form_pdf.php +++ b/include/export/export_form_pdf.php @@ -31,7 +31,7 @@ require_once NOALYSS_INCLUDE.'/class/user.class.php'; require_once NOALYSS_INCLUDE.'/header_print.php'; require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_report.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; $http=new HttpInput(); @@ -55,7 +55,7 @@ $pdf->setTitle("Rapport ".$Libelle,true); // Step ?? //-- -$p_step=$http->get('p_step',"string",0); +$step=$http->get('p_step',"string",0); if ( $step == 0 ) { // No step asked diff --git a/include/export/export_gl_pdf.php b/include/export/export_gl_pdf.php index a335fcce0..eda3328e3 100644 --- a/include/export/export_gl_pdf.php +++ b/include/export/export_gl_pdf.php @@ -30,7 +30,7 @@ include_once('lib/impress.class.php'); require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php'; require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; require_once NOALYSS_INCLUDE.'/class/user.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; $http=new HttpInput(); $from_periode = $http->get("from_periode","date"); diff --git a/include/export/export_ledger_pdf.php b/include/export/export_ledger_pdf.php index eb224b09b..9f30e8d93 100644 --- a/include/export/export_ledger_pdf.php +++ b/include/export/export_ledger_pdf.php @@ -28,7 +28,7 @@ if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; $gDossier = dossier::id(); -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/class/user.class.php'; require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; require_once NOALYSS_INCLUDE.'/class/database.class.php'; diff --git a/include/export/export_poste_detail_pdf.php b/include/export/export_poste_detail_pdf.php index edb91ced6..f755dab26 100644 --- a/include/export/export_poste_detail_pdf.php +++ b/include/export/export_poste_detail_pdf.php @@ -31,7 +31,7 @@ require_once NOALYSS_INCLUDE.'/header_print.php'; require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; require_once NOALYSS_INCLUDE.'/class/acc_operation.class.php'; require_once NOALYSS_INCLUDE.'/class/user.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; $http=new HttpInput(); diff --git a/include/export/export_security_pdf.php b/include/export/export_security_pdf.php index 47ef7df61..9f461c66c 100755 --- a/include/export/export_security_pdf.php +++ b/include/export/export_security_pdf.php @@ -26,7 +26,7 @@ require_once NOALYSS_INCLUDE.'/class/dossier.class.php'; $gDossier=dossier::id(); require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; require_once NOALYSS_INCLUDE.'/class/database.class.php'; -require_once NOALYSS_INCLUDE.'/lib/pdf.class.php'; +require_once NOALYSS_INCLUDE.'/class/pdf.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; $http=new HttpInput(); diff --git a/include/lib/pdf.class.php b/include/lib/pdf.class.php deleted file mode 100644 index 90600bd7b..000000000 --- a/include/lib/pdf.class.php +++ /dev/null @@ -1,414 +0,0 @@ -width=$w ; - $this->height=$h ; - $this->text=$txt; - $this->border=$border; - $this->new_line=$ln; - $this->align=$align; - $this->fill=$fill; - $this->link=$link; - $this->type=$type; - return $this; - } -} -class PDF extends TFPDF -{ - - var $cn = null; - var $own = null; - var $soc = ""; - var $dossier = "n/a"; - var $date = ""; - private $cells=array(); - - public function __construct ($p_cn = null, $orientation = 'P', $unit = 'mm', $format = 'A4') - { - $this->bigger=0; - if($p_cn == null) die("No database connection. Abort."); - - parent::__construct($orientation, $unit, $format); - $this->AddFont('DejaVu','','DejaVuSans.ttf',true); - $this->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true); - $this->AddFont('DejaVu','BI','DejaVuSans-BoldOblique.ttf',true); - $this->AddFont('DejaVuCond','','DejaVuSansCondensed.ttf',true); - $this->AddFont('DejaVuCond','B','DejaVuSansCondensed-Bold.ttf',true); - $this->AddFont('DejaVuCond','I','DejaVuSansCondensed-Oblique.ttf',true); - date_default_timezone_set ('Europe/Paris'); - - $this->cn = $p_cn; - $this->own = new Noalyss_Parameter_Folder($this->cn); - $this->soc = $this->own->MY_NAME; - $this->date = date('d.m.Y'); - $this->cells=array(); - } - - function setDossierInfo($dossier = "n/a") - { - $this->dossier = dossier::name()." ".$dossier; - } - - function Header() - { - //Arial bold 12 - $this->SetFont('DejaVu', 'B', 12); - //Title - parent::Cell(0,10,$this->dossier, 'B', 0, 'C'); - //Line break - parent::Ln(20); - } - function Footer() - { - //Position at 2 cm from bottom - $this->SetY(-20); - //Arial italic 8 - $this->SetFont('Arial', '', 8); - //Page number - parent::Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); - parent::Ln(3); - // Created by NOALYSS - parent::Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); - } - /** - * Count the number of rows a p_text will take for a multicell - * @param $p_text String - * @param $p_colSize size of the column in User Unit - */ - private function count_nb_row($p_text,$p_colSize) - { - // If colSize is bigger than the size of the string then it takes 1 line - if ( $this->GetStringWidth($p_text) <= $p_colSize) return 1; - $nRow=0; - $aWords=explode(' ',$p_text); - $nb_words=count($aWords); - $string=""; - - for ($i=0;$i < $nb_words;$i++){ - // Concatenate String with current word + a space - $string.=$aWords[$i]; - - // if there is a word after add a space - if ( $i+1 < $nb_words) $string.=" "; - - // Compute new size and compare to the colSize - if ( $this->GetStringWidth($string) >= $p_colSize) { - // If the size of the string if bigger than we add a row, the current - // word is the first word of the next line - $nRow++; - $string=$aWords[$i]; - } - } - $nRow++; - return $nRow; - - - - } - /** - * Check if a page must be added due a MultiCell - * @return boolean - */ - private function check_page_add() - { - // break on page - $size=count($this->cells); - for ($i=0;$i < $size ; $i++) - { - if ($this->cells[$i]->type == 'M' ) - { - /** - * On doit calculer si le texte dépasse la texte et compter le - * nombre de lignes que le texte prendrait. Ensuite il faut - * faire un saut de page (renvoit true) si dépasse - */ - - $sizetext=$this->GetStringWidth($this->cells[$i]->text); - - // if text bigger than column width then check - - $y=$this->GetY(); - $nb_row=$this->count_nb_row($this->cells[$i]->text, $this->cells[$i]->width); - $height=$this->cells[$i]->height*$nb_row; - - // If the text is bigger than a sheet of paper then return false - if ($height >= $this->h) return false; - - if ( $y + $height > ($this->h - $this->bMargin -7 )) - return true; - - } - } - return false; - } - private function print_row() - { - static $e=0; - $e++; - if ( $this->check_page_add() == true ) $this->AddPage (); - $this->bigger=0; - $size=count($this->cells); - $cell=$this->cells; - if ($size == 0 )return; - for ($i=0;$i < $size ; $i++) - { - $a=$cell[$i]; - $a->text= str_replace("\\", "", $a->text); - switch ($a->type) - { - case "M": - $x_m=$this->GetX(); - $y_m=$this->GetY(); - parent::MultiCell( - $a->width, - $a->height, - $a->text, - $a->border, - $a->align, - $a->fill - ); - $x_m=$x_m+$a->width; - $tmp=$this->GetY()-$y_m; - if ( $tmp > $this->bigger) $this->bigger=$tmp; - $this->SetXY($x_m,$y_m); - break; - - case "C": - - parent::Cell( $a->width, - $a->height, - $a->text, - $a->border, - $a->new_line, - $a->align, - $a->fill, - $a->link); - break; - - default: - break; - } - } - $this->cells=array(); - } - private function add_cell(Cellule $Ce) - { - $size=count($this->cells); - $this->cells[$size]=$Ce; - - } - function write_cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') - { - $this->add_cell(new Cellule($w,$h,$txt,$border,$ln,$align,$fill,$link,'C')); - - } - function LongLine($w,$h,$txt,$border=0,$align='',$fill=false) - { - $this->add_cell(new Cellule($w,$h,$txt,$border,0,$align,$fill,'','M')); - - } - function line_new($p_step=null){ - $this->print_row(); - if ( $this->bigger==0) - parent::Ln($p_step); - else - parent::Ln($this->bigger); - $this->bigger=0; - } - /** - *@brief retrieve the client name and quick_code - *@param $p_jr_id jrn.jr_id - *@param $p_jrn_type ledger type ACH VEN FIN - *@return array (0=>qcode,1=>name) or for FIN 0=>customer qc 1=>customer name 2=>bank qc 3=>bank name - *@see class_print_ledger_simple, class_print_ledger_simple_without_vat - */ - function get_tiers($p_jr_id,$p_jrn_type) - { - if ( $p_jrn_type=='ACH' ) - { - $array=$this->cn->get_array('SELECT - jrnx.j_grpt, - quant_purchase.qp_supplier, - quant_purchase.qp_internal, - jrn.jr_internal - FROM - public.quant_purchase, - public.jrnx, - public.jrn - WHERE - quant_purchase.j_id = jrnx.j_id AND - jrnx.j_grpt = jrn.jr_grpt_id and jr_id=$1',array($p_jr_id)); - if (count($array)==0) return array("ERREUR $p_jr_id",''); - $customer_id=$array[0]['qp_supplier']; - $fiche=new Fiche($this->cn,$customer_id); - $customer_qc=$fiche->get_quick_code($customer_id); - $customer_name=$fiche->getName(); - return array($customer_qc,$customer_name); - } - if ( $p_jrn_type=='VEN' ) - { - $array=$this->cn->get_array('SELECT - quant_sold.qs_client - FROM - public.quant_sold, - public.jrnx, - public.jrn - WHERE - quant_sold.j_id = jrnx.j_id AND - jrnx.j_grpt = jrn.jr_grpt_id and jr_id=$1',array($p_jr_id)); - if (count($array)==0) return array("ERREUR $p_jr_id",''); - $customer_id=$array[0]['qs_client']; - $fiche=new Fiche($this->cn,$customer_id); - $customer_qc=$fiche->get_quick_code($customer_id); - $customer_name=$fiche->getName(); - return array($customer_qc,$customer_name); - } - if ( $p_jrn_type=='FIN' ) - { - $array=$this->cn->get_array('SELECT - qf_other,qf_bank - FROM - public.quant_fin - WHERE - quant_fin.jr_id =$1',array($p_jr_id)); - if (count($array)==0) return array("ERREUR $p_jr_id",'','',''); - $customer_id=$array[0]['qf_other']; - $fiche=new Fiche($this->cn,$customer_id); - $customer_qc=$fiche->get_quick_code($customer_id); - $customer_name=$fiche->getName(); - - $bank_id=$array[0]['qf_bank']; - $fiche=new Fiche($this->cn,$bank_id); - $bank_qc=$fiche->get_quick_code($bank_id); - $bank_name=$fiche->getName(); - - return array($customer_qc,$customer_name,$bank_qc,$bank_name); - } - } - - -} - -class PDFLand extends PDF -{ - - public function __construct ($p_cn = null, $orientation = 'P', $unit = 'mm', $format = 'A4') - { - - if($p_cn == null) die("No database connection. Abort."); - $this->bigger=0; - - parent::__construct($p_cn,'L', $unit, $format); - date_default_timezone_set ('Europe/Paris'); - $this->AddFont('DejaVu','','DejaVuSans.ttf',true); - $this->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true); - $this->AddFont('DejaVu','BI','DejaVuSans-BoldOblique.ttf',true); - $this->AddFont('DejaVuCond','','DejaVuSansCondensed.ttf',true); - $this->AddFont('DejaVuCond','B','DejaVuSansCondensed-Bold.ttf',true); - $this->AddFont('DejaVuCond','I','DejaVuSansCondensed-Oblique.ttf',true); - - $this->cn = $p_cn; - $this->own = new Noalyss_Parameter_Folder($this->cn); - $this->soc = $this->own->MY_NAME; - $this->date = date('d.m.Y'); - } - function Header() - { - //Arial bold 12 - $this->SetFont('DejaVu', 'B', 10); - //Title - $this->Cell(0,10,$this->dossier, 'B', 0, 'C'); - //Line break - $this->Ln(20); - } - function Footer() - { - //Position at 2 cm from bottom - $this->SetY(-20); - //Arial italic 8 - $this->SetFont('DejaVuCond', 'I', 8); - //Page number - $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); - $this->Ln(3); - // Created by NOALYSS - $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); - - } -} - -class PDFBalance_simple extends PDF -{ - /** - *@brief set_info(dossier,from poste,to poste, from periode, to periode) - *@param $p_from_poste start = poste - *@param $p_to_poste end = poste - *@param $p_from periode start - *@param $p_to periode end - */ - function set_info($p_from_poste,$to_poste,$p_from,$p_to) - { - $this->dossier='Balance simple '.dossier::name(); - $this->from_poste=$p_from_poste; - $this->to_poste=$to_poste; - $this->from=$p_from; - $this->to=$p_to; - } - function Header() - { - parent::Header(); - $this->SetFont('DejaVu','B',8); - $titre=sprintf("Balance simple poste %s %s date %s %s", - $this->from_poste, - $this->to_poste, - $this->from, - $this->to); - $this->Cell(0,7,$titre,1,0,'C'); - - $this->Ln(); - $this->SetFont('DejaVu','',6); - - $this->Cell(110,7,'Poste Comptable','B'); - $this->Cell(20,7,'Débit','B',0,'L'); - $this->Cell(20,7,'Crédit','B',0,'L'); - $this->Cell(20,7,'Solde','B',0,'L'); - $this->Cell(20,7,'D/C','B',0,'L'); - $this->Ln(); - - } -} diff --git a/include/lib/pdf_core.class.php b/include/lib/pdf_core.class.php new file mode 100644 index 000000000..805bd8761 --- /dev/null +++ b/include/lib/pdf_core.class.php @@ -0,0 +1,225 @@ +width=$w ; + $this->height=$h ; + $this->text=$txt; + $this->border=$border; + $this->new_line=$ln; + $this->align=$align; + $this->fill=$fill; + $this->link=$link; + $this->type=$type; + return $this; + } +} +class PDF_Core extends TFPDF +{ + + + + private $cells=array(); + + public function __construct ( $orientation = 'P', $unit = 'mm', $format = 'A4') + { + $this->bigger=0; + + parent::__construct($orientation, $unit, $format); + $this->AddFont('DejaVu','','DejaVuSans.ttf',true); + $this->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true); + $this->AddFont('DejaVu','BI','DejaVuSans-BoldOblique.ttf',true); + $this->AddFont('DejaVuCond','','DejaVuSansCondensed.ttf',true); + $this->AddFont('DejaVuCond','B','DejaVuSansCondensed-Bold.ttf',true); + $this->AddFont('DejaVuCond','I','DejaVuSansCondensed-Oblique.ttf',true); + + + + $this->cells=array(); + } + + + /** + * Count the number of rows a p_text will take for a multicell + * @param $p_text String + * @param $p_colSize size of the column in User Unit + */ + private function count_nb_row($p_text,$p_colSize) + { + // If colSize is bigger than the size of the string then it takes 1 line + if ( $this->GetStringWidth($p_text) <= $p_colSize) return 1; + $nRow=0; + $aWords=explode(' ',$p_text); + $nb_words=count($aWords); + $string=""; + + for ($i=0;$i < $nb_words;$i++){ + // Concatenate String with current word + a space + $string.=$aWords[$i]; + + // if there is a word after add a space + if ( $i+1 < $nb_words) $string.=" "; + + // Compute new size and compare to the colSize + if ( $this->GetStringWidth($string) >= $p_colSize) { + // If the size of the string if bigger than we add a row, the current + // word is the first word of the next line + $nRow++; + $string=$aWords[$i]; + } + } + $nRow++; + return $nRow; + + + + } + /** + * Check if a page must be added due a MultiCell + * @return boolean + */ + private function check_page_add() + { + // break on page + $size=count($this->cells); + for ($i=0;$i < $size ; $i++) + { + if ($this->cells[$i]->type == 'M' ) + { + /** + * On doit calculer si le texte dépasse la texte et compter le + * nombre de lignes que le texte prendrait. Ensuite il faut + * faire un saut de page (renvoit true) si dépasse + */ + + $sizetext=$this->GetStringWidth($this->cells[$i]->text); + + // if text bigger than column width then check + + $y=$this->GetY(); + $nb_row=$this->count_nb_row($this->cells[$i]->text, $this->cells[$i]->width); + $height=$this->cells[$i]->height*$nb_row; + + // If the text is bigger than a sheet of paper then return false + if ($height >= $this->h) return false; + + if ( $y + $height > ($this->h - $this->bMargin -7 )) + return true; + + } + } + return false; + } + private function print_row() + { + static $e=0; + $e++; + if ( $this->check_page_add() == true ) $this->AddPage (); + $this->bigger=0; + $size=count($this->cells); + $cell=$this->cells; + if ($size == 0 )return; + for ($i=0;$i < $size ; $i++) + { + $a=$cell[$i]; + $a->text= str_replace("\\", "", $a->text); + switch ($a->type) + { + case "M": + $x_m=$this->GetX(); + $y_m=$this->GetY(); + parent::MultiCell( + $a->width, + $a->height, + $a->text, + $a->border, + $a->align, + $a->fill + ); + $x_m=$x_m+$a->width; + $tmp=$this->GetY()-$y_m; + if ( $tmp > $this->bigger) $this->bigger=$tmp; + $this->SetXY($x_m,$y_m); + break; + + case "C": + + parent::Cell( $a->width, + $a->height, + $a->text, + $a->border, + $a->new_line, + $a->align, + $a->fill, + $a->link); + break; + + default: + break; + } + } + $this->cells=array(); + } + private function add_cell(Cellule $Ce) + { + $size=count($this->cells); + $this->cells[$size]=$Ce; + + } + function write_cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='') + { + $this->add_cell(new Cellule($w,$h,$txt,$border,$ln,$align,$fill,$link,'C')); + + } + function LongLine($w,$h,$txt,$border=0,$align='',$fill=false) + { + $this->add_cell(new Cellule($w,$h,$txt,$border,0,$align,$fill,'','M')); + + } + function line_new($p_step=null){ + $this->print_row(); + if ( $this->bigger==0) + parent::Ln($p_step); + else + parent::Ln($this->bigger); + $this->bigger=0; + } + + +} +