From 98ddd02a32e56245b732ec26c84f1da6f809bcc4 Mon Sep 17 00:00:00 2001 From: fhenry Date: Wed, 10 Apr 2013 19:55:21 +0200 Subject: [PATCH 01/14] Qual : PHP Code_Sniffer --- htdocs/commande/class/commande.class.php | 1 - .../thirdparties_services_expired.modules.php | 1 + .../pdf/doc_generic_project_odt.modules.php | 76 +++++++++++-------- .../fourn/class/fournisseur.product.class.php | 1 + htdocs/opensurvey/adminstuds_preview.php | 2 +- htdocs/opensurvey/fonctions.php | 2 +- htdocs/opensurvey/public/choix_date.php | 6 +- htdocs/opensurvey/public/create_survey.php | 2 +- htdocs/opensurvey/public/exportcsv.php | 12 +-- htdocs/public/paybox/paymentko.php | 3 +- htdocs/public/paybox/paymentok.php | 3 +- htdocs/public/paypal/paymentko.php | 3 +- htdocs/public/paypal/paymentok.php | 3 +- 13 files changed, 64 insertions(+), 51 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 0270b0327dd..b6e11a64065 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2783,7 +2783,6 @@ class Commande extends CommonOrder * Update value of extrafields on the proposal * * @param User $user Object user that modify - * @param double $remise Amount discount * @return int <0 if ko, >0 if ok */ function update_extrafields($user) diff --git a/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php b/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php index 4b621b705a2..3865cfe8f66 100755 --- a/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php +++ b/htdocs/core/modules/mailings/thirdparties_services_expired.modules.php @@ -175,6 +175,7 @@ class mailing_thirdparties_services_expired extends MailingTargets * For example if this selector is used to extract 500 different * emails from a text file, this function must return 500. * + * @param string $sql SQL request to get recipitien * @param int $filter Filter * @param string $option Option * @return int Number of recipients diff --git a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php index 34cd23a0a7f..912c9fd25ad 100644 --- a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php @@ -209,7 +209,7 @@ class doc_generic_project_odt extends ModelePDFProjects function get_substitutionarray_project_reference($refdetail,$outputlangs) { global $conf; - + return array( 'projref_type'=>$refdetail['type'], 'projref_ref'=>$refdetail['ref'], @@ -220,7 +220,7 @@ class doc_generic_project_odt extends ModelePDFProjects 'projref_status'=>$refdetail['status'] ); } - + /** * Define array with couple substitution key => substitution value * @@ -242,7 +242,7 @@ class doc_generic_project_odt extends ModelePDFProjects 'taskressource_email'=>$taskressource['email'] ); } - + /** * Define array with couple substitution key => substitution value * @@ -254,7 +254,7 @@ class doc_generic_project_odt extends ModelePDFProjects { global $conf; - return array( + return array( 'tasktime_rowid'=>$tasktime['rowid'], 'tasktime_task_date'=>dol_print_date($tasktime['task_date'],'day'), 'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'],'all'), @@ -265,7 +265,7 @@ class doc_generic_project_odt extends ModelePDFProjects 'tasktime_fullcivname'=>$tasktime['fullcivname'] ); } - + /** * Define array with couple substitution key => substitution value * @@ -276,7 +276,7 @@ class doc_generic_project_odt extends ModelePDFProjects function get_substitutionarray_task_file($file,$outputlangs) { global $conf; - + return array( 'tasksfile_name'=>$file['name'], 'tasksfile_date'=>dol_print_date($file['date'],'day'), @@ -384,6 +384,14 @@ class doc_generic_project_odt extends ModelePDFProjects return -1; } + // Add odtgeneration hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('odtgeneration')); + global $action; if (! is_object($outputlangs)) $outputlangs=$langs; $sav_charset_output=$outputlangs->charset_output; $outputlangs->charset_output='UTF-8'; @@ -534,6 +542,9 @@ class doc_generic_project_odt extends ModelePDFProjects // Replace tags of object + external modules $tmparray=$this->get_substitutionarray_object($object,$outputlangs); complete_substitutions_array($tmparray, $outputlangs, $object); + // Call the ODTSubstitution hook + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks foreach($tmparray as $key=>$value) { try { @@ -564,7 +575,7 @@ class doc_generic_project_odt extends ModelePDFProjects if (!empty($object->fk_soc)) $socid = $object->fk_soc; $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); - + foreach ($tasksarray as $task) @@ -584,10 +595,10 @@ class doc_generic_project_odt extends ModelePDFProjects { } } - + $taskobj=new Task($this->db); $taskobj->fetch($task->id); - + // Replace tags of lines for contacts task $sourcearray=array('internal','external'); $contact_arrray=array(); @@ -601,7 +612,7 @@ class doc_generic_project_odt extends ModelePDFProjects if ((is_array($contact_arrray) && count($contact_arrray) > 0)) { $listlinestaskres = $listlines->__get('tasksressources'); - + foreach ($contact_arrray as $contact) { if ($contact['source']=='internal') { @@ -611,15 +622,15 @@ class doc_generic_project_odt extends ModelePDFProjects } elseif ($contact['source']=='external') { $objectdetail=new Contact($this->db); $objectdetail->fetch($contact['id']); - + $soc=new Societe($this->db); $soc->fetch($contact['socid']); $contact['socname']=$soc->name; } $contact['fullname']=$objectdetail->getFullName($outputlangs,1); - + $tmparray=$this->get_substitutionarray_tasksressource($contact,$outputlangs); - + foreach($tmparray as $key => $val) { try @@ -645,7 +656,7 @@ class doc_generic_project_odt extends ModelePDFProjects $sql .= " WHERE t.fk_task =".$task->id; $sql .= " AND t.fk_user = u.rowid"; $sql .= " ORDER BY t.task_date DESC"; - + $resql = $this->db->query($sql); if ($resql) { @@ -663,9 +674,9 @@ class doc_generic_project_odt extends ModelePDFProjects } else { $row['fullcivname']=''; } - + $tmparray=$this->get_substitutionarray_taskstime($row,$outputlangs); - + foreach($tmparray as $key => $val) { try @@ -684,15 +695,15 @@ class doc_generic_project_odt extends ModelePDFProjects } $this->db->free($resql); } - - + + // Replace tags of project files $listtasksfiles = $listlines->__get('tasksfiles'); - + $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref).'/'.dol_sanitizeFileName($task->ref); $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$','name',SORT_ASC,1); - - + + foreach ($filearray as $filedetail) { $tmparray=$this->get_substitutionarray_task_file($filedetail,$outputlangs); @@ -731,7 +742,7 @@ class doc_generic_project_odt extends ModelePDFProjects $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref); $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$','name',SORT_ASC,1); - + foreach ($filearray as $filedetail) { //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true)); @@ -891,27 +902,27 @@ class doc_generic_project_odt extends ModelePDFProjects { $ref_array=array(); $ref_array['type']=$langs->trans($classname); - + $element = new $classname($this->db); $element->fetch($elementarray[$i]); $element->fetch_thirdparty(); - + //Ref object $ref_array['ref']=$element->ref; - + //Date object $dateref=$element->date; if (empty($dateref)) $dateref=$element->datep; if (empty($dateref)) $dateref=$element->date_contrat; $ref_array['date']=$dateref; - + //Soc object if (is_object($element->thirdparty)) { $ref_array['socname']=$element->thirdparty->name; } else { $ref_array['socname']=''; } - + //Amount object if (empty($valueref['disableamount'])) { if (!empty($element->total_ht)) { @@ -925,9 +936,9 @@ class doc_generic_project_odt extends ModelePDFProjects $ref_array['amountht']=''; $ref_array['amountttc']=''; } - + $ref_array['status']=html_entity_decode($element->getLibStatut(0)); - + $tmparray=$this->get_substitutionarray_project_reference($ref_array,$outputlangs); foreach($tmparray as $key => $val) @@ -945,7 +956,7 @@ class doc_generic_project_odt extends ModelePDFProjects } $listlines->merge(); } - + } } $odfHandler->mergeSegment($listlines); @@ -958,6 +969,11 @@ class doc_generic_project_odt extends ModelePDFProjects return -1; } + // Call the beforeODTSave hook + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); + $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + + // Write new file $odfHandler->saveToDisk($file); diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 09843191692..d310943bbed 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -146,6 +146,7 @@ class ProductFournisseur extends Product * @param string $charges costs affering to product * @param float $remise_percent Discount regarding qty (percent) * @param float $remise Discount regarding qty (amount) + * @param float $newnpr new infobit tva npr * @return int <0 if KO, >=0 if OK */ function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0) diff --git a/htdocs/opensurvey/adminstuds_preview.php b/htdocs/opensurvey/adminstuds_preview.php index 7e7bb6a6967..bbb5f8b09ac 100755 --- a/htdocs/opensurvey/adminstuds_preview.php +++ b/htdocs/opensurvey/adminstuds_preview.php @@ -202,7 +202,7 @@ if (isset($_POST["ajoutercolonne"]) && ($object->format == "D" || $object->forma //on rajoute la valeur dans les valeurs $datesbase = explode(",",$object->sujet); - $taillebase = sizeof($datesbase); + $taillebase = count($datesbase); //recherche de l'endroit de l'insertion de la nouvelle date dans les dates deja entrées dans le tableau if ($nouvelledate < $datesbase[0]) { diff --git a/htdocs/opensurvey/fonctions.php b/htdocs/opensurvey/fonctions.php index 6068ca965f1..a1375e15f0a 100755 --- a/htdocs/opensurvey/fonctions.php +++ b/htdocs/opensurvey/fonctions.php @@ -120,7 +120,7 @@ function get_server_name() /** * is_error * - * @param unknown_type $cerr + * @param unknown_type $cerr error number * @return boolean */ function is_error($cerr) diff --git a/htdocs/opensurvey/public/choix_date.php b/htdocs/opensurvey/public/choix_date.php index 72a24357436..faf67137942 100755 --- a/htdocs/opensurvey/public/choix_date.php +++ b/htdocs/opensurvey/public/choix_date.php @@ -257,9 +257,9 @@ if (issetAndNoEmpty('choixjourajout')) { // Si le test est passé, alors on insere la valeur dans la variable de session qui contient les dates if ($journeuf && issetAndNoEmpty('choixjourajout') === true) { - array_push ($_SESSION["totalchoixjour"],mktime (0,0,0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"])); - sort ($_SESSION["totalchoixjour"]); - $cle=array_search (mktime (0,0,0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"]), $_SESSION["totalchoixjour"]); + array_push($_SESSION["totalchoixjour"],mktime (0,0,0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"])); + sort($_SESSION["totalchoixjour"]); + $cle=array_search(mktime (0,0,0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"]), $_SESSION["totalchoixjour"]); //On sauvegarde les heures deja entrées for ($i = 0; $i < $cle; $i++) { diff --git a/htdocs/opensurvey/public/create_survey.php b/htdocs/opensurvey/public/create_survey.php index c5af8db0cab..f94898ac692 100755 --- a/htdocs/opensurvey/public/create_survey.php +++ b/htdocs/opensurvey/public/create_survey.php @@ -162,7 +162,7 @@ print ''."\n"; print '
'."\n"; -#affichage du cochage par défaut +//affichage du cochage par défaut $cocheplus=''; if ($_SESSION["canedit"]) $cocheplus="checked"; diff --git a/htdocs/opensurvey/public/exportcsv.php b/htdocs/opensurvey/public/exportcsv.php index b2ee0cc1eea..a6d0b0216a4 100755 --- a/htdocs/opensurvey/public/exportcsv.php +++ b/htdocs/opensurvey/public/exportcsv.php @@ -64,7 +64,7 @@ $now=dol_now(); $nbcolonnes=substr_count($object->sujet,',')+1; $toutsujet=explode(",",$object->sujet); -#$toutsujet=str_replace("°","'",$toutsujet); +//$toutsujet=str_replace("°","'",$toutsujet); // affichage des sujets du sondage $input.=$langs->trans("Name").";"; @@ -139,15 +139,15 @@ if ($resql) else dol_print_error($db); -$filesize = strlen( $input ); +$filesize = strlen($input); $filename=$numsondage."_".dol_print_date($now,'%Y%m%d%H%M').".csv"; -header( 'Content-Type: text/csv; charset=utf-8' ); -header( 'Content-Length: '.$filesize ); -header( 'Content-Disposition: attachment; filename="'.$filename.'"' ); -header( 'Cache-Control: max-age=10' ); +header('Content-Type: text/csv; charset=utf-8'); +header('Content-Length: '.$filesize); +header('Content-Disposition: attachment; filename="'.$filename.'"'); +header('Cache-Control: max-age=10'); echo $input; exit; diff --git a/htdocs/public/paybox/paymentko.php b/htdocs/public/paybox/paymentko.php index 4db0684005b..b2c3954c1e9 100644 --- a/htdocs/public/paybox/paymentko.php +++ b/htdocs/public/paybox/paymentko.php @@ -73,8 +73,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu 'New subscription payed', $sendto, $from, - 'New subscription payed '.$fulltag - ); + 'New subscription payed '.$fulltag); $result=$mailfile->sendfile(); if ($result) diff --git a/htdocs/public/paybox/paymentok.php b/htdocs/public/paybox/paymentok.php index ebd3c834d09..0c25e2e3039 100644 --- a/htdocs/public/paybox/paymentok.php +++ b/htdocs/public/paybox/paymentok.php @@ -103,8 +103,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu 'New subscription payed', $sendto, $from, - 'New subscription payed '.$fulltag - ); + 'New subscription payed '.$fulltag); $result=$mailfile->sendfile(); if ($result) diff --git a/htdocs/public/paypal/paymentko.php b/htdocs/public/paypal/paymentko.php index c6fe53ac7b0..ff83d6d831a 100755 --- a/htdocs/public/paypal/paymentko.php +++ b/htdocs/public/paypal/paymentko.php @@ -81,8 +81,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu 'New subscription payed', $sendto, $from, - 'New subscription payed '.$fulltag - ); + 'New subscription payed '.$fulltag); $result=$mailfile->sendfile(); if ($result) diff --git a/htdocs/public/paypal/paymentok.php b/htdocs/public/paypal/paymentok.php index ca11bcb5422..0b425ea8cea 100755 --- a/htdocs/public/paypal/paymentok.php +++ b/htdocs/public/paypal/paymentok.php @@ -140,8 +140,7 @@ if ($PAYPALTOKEN) 'New subscription payed', $sendto, $from, - 'New subscription payed '.$fulltag - ); + 'New subscription payed '.$fulltag); $result=$mailfile->sendfile(); if ($result) From b3b0c73f319339c8fc4fc3778ef2207ead58cbca Mon Sep 17 00:00:00 2001 From: fhenry Date: Thu, 11 Apr 2013 10:51:31 +0200 Subject: [PATCH 02/14] Qual : PHP Code Sniffer --- htdocs/opensurvey/fonctions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/opensurvey/fonctions.php b/htdocs/opensurvey/fonctions.php index 2d817c8a63c..9c3ecba0b2d 100755 --- a/htdocs/opensurvey/fonctions.php +++ b/htdocs/opensurvey/fonctions.php @@ -121,7 +121,6 @@ function get_server_name() * is_error * * @param unknown_type $cerr error number - * @param string $cerr Error value * @return boolean Error key found or not */ function is_error($cerr) From db86735fe63607c3b81e1e386f0ae057edcb7ac8 Mon Sep 17 00:00:00 2001 From: fhenry Date: Thu, 11 Apr 2013 10:52:02 +0200 Subject: [PATCH 03/14] Qual : php code sniffer --- htdocs/opensurvey/public/create_survey.php | 4 ---- htdocs/opensurvey/public/exportcsv.php | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/htdocs/opensurvey/public/create_survey.php b/htdocs/opensurvey/public/create_survey.php index 58684f30c32..729255a6ca1 100755 --- a/htdocs/opensurvey/public/create_survey.php +++ b/htdocs/opensurvey/public/create_survey.php @@ -162,11 +162,7 @@ print ''."\n"; print '
'."\n"; -<<<<<<< HEAD -//affichage du cochage par défaut -======= // Check or not ->>>>>>> branch 'develop' of https://github.com/Dolibarr/dolibarr.git $cocheplus=''; if ($_SESSION["canedit"]) $cocheplus="checked"; diff --git a/htdocs/opensurvey/public/exportcsv.php b/htdocs/opensurvey/public/exportcsv.php index 3b1f22d2243..f933b37a317 100755 --- a/htdocs/opensurvey/public/exportcsv.php +++ b/htdocs/opensurvey/public/exportcsv.php @@ -64,10 +64,6 @@ $now=dol_now(); $nbcolonnes=substr_count($object->sujet,',')+1; $toutsujet=explode(",",$object->sujet); -<<<<<<< HEAD -//$toutsujet=str_replace("°","'",$toutsujet); -======= ->>>>>>> branch 'develop' of https://github.com/Dolibarr/dolibarr.git // affichage des sujets du sondage $input.=$langs->trans("Name").";"; @@ -154,4 +150,4 @@ header('Cache-Control: max-age=10'); echo $input; exit; -?> +?> \ No newline at end of file From 6335918d72cce20b518c5ae5bcc332d88224a8ce Mon Sep 17 00:00:00 2001 From: fhenry Date: Thu, 11 Apr 2013 17:06:53 +0200 Subject: [PATCH 04/14] Quel : indentation --- .../doc/doc_generic_order_odt.modules.php | 458 +++++++++--------- .../doc/doc_generic_invoice_odt.modules.php | 422 ++++++++-------- .../doc/doc_generic_proposal_odt.modules.php | 324 +++++++------ 3 files changed, 605 insertions(+), 599 deletions(-) diff --git a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php index 5ab40fd1e86..00658b7b9cb 100644 --- a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php +++ b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php @@ -1,21 +1,21 @@ * Copyright (C) 2012 Juanjo Menent - * - * 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 3 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, see . - * or see http://www.gnu.org/ - */ +* +* 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 3 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, see . +* or see http://www.gnu.org/ +*/ /** * \file htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php @@ -86,84 +86,84 @@ class doc_generic_order_odt extends ModelePDFCommandes } - /** - * Define array with couple substitution key => substitution value - * - * @param Object $object Main object to use as data source - * @param Translate $outputlangs Lang object to use for output - * @return array Array of substitution - */ - function get_substitutionarray_object($object,$outputlangs) - { - global $conf; + /** + * Define array with couple substitution key => substitution value + * + * @param Object $object Main object to use as data source + * @param Translate $outputlangs Lang object to use for output + * @return array Array of substitution + */ + function get_substitutionarray_object($object,$outputlangs) + { + global $conf; - $resarray=array( - 'object_id'=>$object->id, - 'object_ref'=>$object->ref, - 'object_ref_ext'=>$object->ref_ext, - 'object_ref_customer'=>$object->ref_client, - 'object_date'=>dol_print_date($object->date,'day'), - 'object_date_delivery'=>dol_print_date($object->date_livraison,'dayhour'), - 'object_date_creation'=>dol_print_date($object->date_creation,'day'), - 'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), - 'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), - 'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), - 'object_date_close'=>dol_print_date($object->date_cloture,'dayhour'), - 'object_payment_mode_code'=>$object->mode_reglement_code, - 'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), - 'object_payment_term_code'=>$object->cond_reglement_code, - 'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement), - 'object_total_ht'=>price($object->total_ht,0,$outputlangs), - 'object_total_vat'=>price($object->total_tva,0,$outputlangs), - 'object_total_ttc'=>price($object->total_ttc,0,$outputlangs), - 'object_total_discount_ht' => price($object->getTotalDiscount(), 0, $outputlangs), - 'object_vatrate'=>vatrate($object->tva), - 'object_note_private'=>$object->note, - 'object_note'=>$object->note_public, - ); + $resarray=array( + 'object_id'=>$object->id, + 'object_ref'=>$object->ref, + 'object_ref_ext'=>$object->ref_ext, + 'object_ref_customer'=>$object->ref_client, + 'object_date'=>dol_print_date($object->date,'day'), + 'object_date_delivery'=>dol_print_date($object->date_livraison,'dayhour'), + 'object_date_creation'=>dol_print_date($object->date_creation,'day'), + 'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), + 'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), + 'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), + 'object_date_close'=>dol_print_date($object->date_cloture,'dayhour'), + 'object_payment_mode_code'=>$object->mode_reglement_code, + 'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), + 'object_payment_term_code'=>$object->cond_reglement_code, + 'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement), + 'object_total_ht'=>price($object->total_ht,0,$outputlangs), + 'object_total_vat'=>price($object->total_tva,0,$outputlangs), + 'object_total_ttc'=>price($object->total_ttc,0,$outputlangs), + 'object_total_discount_ht' => price($object->getTotalDiscount(), 0, $outputlangs), + 'object_vatrate'=>vatrate($object->tva), + 'object_note_private'=>$object->note, + 'object_note'=>$object->note_public, + ); - // Add vat by rates - foreach ($object->lines as $line) - { - if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0; - $resarray['object_total_vat_'.$line->tva_tx]+=$line->total_tva; - } + // Add vat by rates + foreach ($object->lines as $line) + { + if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0; + $resarray['object_total_vat_'.$line->tva_tx]+=$line->total_tva; + } - return $resarray; - } + return $resarray; + } - /** - * Define array with couple substitution key => substitution value - * - * @param array $line Array of lines - * @param Translate $outputlangs Lang object to use for output - * @return array Return a substitution array - */ - function get_substitutionarray_lines($line,$outputlangs) - { - global $conf; + /** + * Define array with couple substitution key => substitution value + * + * @param array $line Array of lines + * @param Translate $outputlangs Lang object to use for output + * @return array Return a substitution array + */ + function get_substitutionarray_lines($line,$outputlangs) + { + global $conf; - return array( - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), - 'line_product_ref'=>$line->product_ref, - 'line_product_label'=>$line->product_label, - 'line_desc'=>$line->desc, - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), - 'line_up'=>price($line->subprice, 0, $outputlangs), - 'line_qty'=>$line->qty, - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), - 'line_price_ht'=>price($line->total_ht, 0, $outputlangs), - 'line_price_ttc'=>price($line->total_ttc, 0, $outputlangs), - 'line_price_vat'=>price($line->total_tva, 0, $outputlangs), - 'line_date_start'=>$line->date_start, - 'line_date_end'=>$line->date_end - ); - } + return array( + 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), + 'line_product_ref'=>$line->product_ref, + 'line_product_label'=>$line->product_label, + 'line_desc'=>$line->desc, + 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), + 'line_up'=>price($line->subprice, 0, $outputlangs), + 'line_qty'=>$line->qty, + 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), + 'line_price_ht'=>price($line->total_ht, 0, $outputlangs), + 'line_price_ttc'=>price($line->total_ttc, 0, $outputlangs), + 'line_price_vat'=>price($line->total_tva, 0, $outputlangs), + 'line_date_start'=>$line->date_start, + 'line_date_end'=>$line->date_end + ); + } /** * Return description of a module * - * @param Translate $langs Lang object to use for output + * @param Translate $langs Lang object to use for output * @return string Description */ function info($langs) @@ -191,7 +191,9 @@ class doc_generic_order_odt extends ModelePDFCommandes { $tmpdir=trim($tmpdir); $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); - if (! $tmpdir) { unset($listofdir[$key]); continue; } + if (! $tmpdir) { + unset($listofdir[$key]); continue; + } if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); else { @@ -202,19 +204,19 @@ class doc_generic_order_odt extends ModelePDFCommandes $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); // Add list of substitution keys $texthelp.='
'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'
'; - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it + $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); $texte.= ''; + $texte.= ''; $texte.= ''; + $texte.= ''; + $texte.= ''; $texte.= ''; - $texte.= '
'; $texte.= ''; - $texte.= '  '; - $texte.= ''; - $texte.= '
'; + $texte.= ''; // Scan directories if (count($listofdir)) $texte.=$langs->trans("NumberOfModelFilesFound").': '.count($listoffiles).''; @@ -228,7 +230,7 @@ class doc_generic_order_odt extends ModelePDFCommandes $texte.= ''; /*$texte.= ''; - $texte.= ''; + $texte.= ''; $texte.= ''; $texte.= ''; $texte.= '';*/ @@ -245,9 +247,9 @@ class doc_generic_order_odt extends ModelePDFCommandes * @param Commande $object Object source to build document * @param Translate $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param int $hidedetails Do not show line details - * @param int $hidedesc Do not show desc - * @param int $hideref Do not show ref + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref * @return int 1 if OK, <=0 if KO */ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) @@ -260,14 +262,14 @@ class doc_generic_order_odt extends ModelePDFCommandes return -1; } - // Add odtgeneration hook - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } - $hookmanager->initHooks(array('odtgeneration')); - global $action; + // Add odtgeneration hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('odtgeneration')); + global $action; if (! is_object($outputlangs)) $outputlangs=$langs; $sav_charset_output=$outputlangs->charset_output; @@ -314,7 +316,7 @@ class doc_generic_order_odt extends ModelePDFCommandes $newfiletmp=preg_replace('/\.odt/i','',$newfile); $newfiletmp=preg_replace('/template_/i','',$newfiletmp); $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); - $newfiletmp=$objectref.'_'.$newfiletmp; + $newfiletmp=$objectref.'_'.$newfiletmp; //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; $file=$dir.'/'.$newfiletmp.'.odt'; //print "newdir=".$dir; @@ -325,64 +327,64 @@ class doc_generic_order_odt extends ModelePDFCommandes dol_mkdir($conf->commande->dir_temp); - // If BILLING contact defined on invoice, we use it - $usecontact=false; - $arrayidcontact=$object->getIdContact('external','BILLING'); - if (count($arrayidcontact) > 0) - { - $usecontact=true; - $result=$object->fetch_contact($arrayidcontact[0]); - } + // If BILLING contact defined on invoice, we use it + $usecontact=false; + $arrayidcontact=$object->getIdContact('external','BILLING'); + if (count($arrayidcontact) > 0) + { + $usecontact=true; + $result=$object->fetch_contact($arrayidcontact[0]); + } - // Recipient name - if (! empty($usecontact)) - { - // On peut utiliser le nom de la societe du contact - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; - else $socobject = $object->client; - } - else - { - $socobject=$object->client; - } + // Recipient name + if (! empty($usecontact)) + { + // On peut utiliser le nom de la societe du contact + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; + else $socobject = $object->client; + } + else + { + $socobject=$object->client; + } - // Make substitution - $substitutionarray=array( - '__FROM_NAME__' => $this->emetteur->nom, - '__FROM_EMAIL__' => $this->emetteur->email, - '__TOTAL_TTC__' => $object->total_ttc, - '__TOTAL_HT__' => $object->total_ht, - '__TOTAL_VAT__' => $object->total_vat - ); - complete_substitutions_array($substitutionarray, $langs, $object); - // Call the ODTSubstitution hook - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + // Make substitution + $substitutionarray=array( + '__FROM_NAME__' => $this->emetteur->nom, + '__FROM_EMAIL__' => $this->emetteur->email, + '__TOTAL_TTC__' => $object->total_ttc, + '__TOTAL_HT__' => $object->total_ht, + '__TOTAL_VAT__' => $object->total_vat + ); + complete_substitutions_array($substitutionarray, $langs, $object); + // Call the ODTSubstitution hook + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks // Line of free text $newfreetext=''; $paramfreetext='COMMANDE_FREE_TEXT'; - if (! empty($conf->global->$paramfreetext)) - { - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); - } + if (! empty($conf->global->$paramfreetext)) + { + $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); + } - // Open and load template + // Open and load template require_once ODTPHP_PATH.'odf.php'; $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->commande->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->commande->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' ) ); // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] - //print html_entity_decode($odfHandler->__toString()); - //print exit; + //print html_entity_decode($odfHandler->__toString()); + //print exit; // Make substitutions into odt of freetext @@ -393,29 +395,29 @@ class doc_generic_order_odt extends ModelePDFCommandes { } - // Make substitutions into odt of user info + // Make substitutions into odt of user info $tmparray=$this->get_substitutionarray_user($user,$outputlangs); - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } - } - // Make substitutions into odt of mysoc - $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); + //var_dump($tmparray); exit; + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + //var_dump($value);exit; + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + // Make substitutions into odt of mysoc + $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); //var_dump($tmparray); exit; foreach($tmparray as $key=>$value) { @@ -435,7 +437,7 @@ class doc_generic_order_odt extends ModelePDFCommandes { } } - // Make substitutions into odt of thirdparty + // Make substitutions into odt of thirdparty $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); foreach($tmparray as $key=>$value) { @@ -455,73 +457,73 @@ class doc_generic_order_odt extends ModelePDFCommandes } } // Replace tags of object + external modules - $tmparray=$this->get_substitutionarray_object($object,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $object); - // Call the ODTSubstitution hook - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } - } + $tmparray=$this->get_substitutionarray_object($object,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object); + // Call the ODTSubstitution hook + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } // Replace tags of lines - try - { - $listlines = $odfHandler->setSegment('lines'); - foreach ($object->lines as $line) - { - $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); - // Call the ODTSubstitutionLine hook - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - foreach($tmparray as $key => $val) - { - try - { - $listlines->setVars($key, $val, true, 'UTF-8'); - } - catch(OdfException $e) - { - } - catch(SegmentException $e) - { - } - } - $listlines->merge(); - } - $odfHandler->mergeSegment($listlines); - } - catch(OdfException $e) - { - $this->error=$e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; - } + try + { + $listlines = $odfHandler->setSegment('lines'); + foreach ($object->lines as $line) + { + $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); + // Call the ODTSubstitutionLine hook + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); + $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + foreach($tmparray as $key => $val) + { + try + { + $listlines->setVars($key, $val, true, 'UTF-8'); + } + catch(OdfException $e) + { + } + catch(SegmentException $e) + { + } + } + $listlines->merge(); + } + $odfHandler->mergeSegment($listlines); + } + catch(OdfException $e) + { + $this->error=$e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; + } - // Call the beforeODTSave hook + // Call the beforeODTSave hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - // Write new file + // Write new file //$result=$odfHandler->exportAsAttachedFile('toto'); $odfHandler->saveToDisk($file); if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + @chmod($file, octdec($conf->global->MAIN_UMASK)); $odfHandler=null; // Destroy object diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index 77f673f2220..512bf98be8b 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -2,20 +2,20 @@ /* Copyright (C) 2010-2012 Laurent Destailleur * Copyright (C) 2012 Regis Houssin - * 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 3 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, see . - * or see http://www.gnu.org/ - */ +* 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 3 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, see . +* or see http://www.gnu.org/ +*/ /** * \file htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -86,55 +86,55 @@ class doc_generic_invoice_odt extends ModelePDFFactures } - /** - * Define array with couple substitution key => substitution value - * - * @param Object $object Main object to use as data source - * @param Translate $outputlangs Lang object to use for output - * @return array Array of substitution - */ - function get_substitutionarray_object($object,$outputlangs) - { - global $conf; + /** + * Define array with couple substitution key => substitution value + * + * @param Object $object Main object to use as data source + * @param Translate $outputlangs Lang object to use for output + * @return array Array of substitution + */ + function get_substitutionarray_object($object,$outputlangs) + { + global $conf; - $invoice_source=new Facture($this->db); + $invoice_source=new Facture($this->db); if ($object->fk_facture_source > 0) { - $invoice_source->fetch($object->fk_facture_source); + $invoice_source->fetch($object->fk_facture_source); } $sumpayed = $object->getSommePaiement(); $alreadypayed=price($sumpayed,0,$outputlangs); - $resarray=array( - 'object_id'=>$object->id, - 'object_ref'=>$object->ref, - 'object_ref_ext'=>$object->ref_ext, - 'object_ref_customer'=>$object->ref_client, - 'object_ref_supplier'=>(! empty($object->ref_fournisseur)?$object->ref_fournisseur:''), - 'object_source_invoice_ref'=>$invoice_source->ref, - 'object_date'=>dol_print_date($object->date,'day'), - 'object_date_limit'=>dol_print_date($object->date_lim_reglement,'day'), - 'object_date_creation'=>dol_print_date($object->date_creation,'day'), - 'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), - 'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), - 'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), - 'object_payment_mode_code'=>$object->mode_reglement_code, - 'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), - 'object_payment_term_code'=>$object->cond_reglement_code, - 'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement), - 'object_total_ht'=>price2num($object->total_ht), - 'object_total_vat'=>price2num($object->total_tva), - 'object_total_ttc'=>price2num($object->total_ttc), - 'object_total_discount_ht' => price2num($object->getTotalDiscount(), 0, $outputlangs), - 'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''), - 'object_note_private'=>$object->note, - 'object_note'=>$object->note_public, - // Payments - 'object_already_payed'=>$alreadypayed, - 'object_remain_to_pay'=>price2num($object->total_ttc - $sumpayed) - ); + $resarray=array( + 'object_id'=>$object->id, + 'object_ref'=>$object->ref, + 'object_ref_ext'=>$object->ref_ext, + 'object_ref_customer'=>$object->ref_client, + 'object_ref_supplier'=>(! empty($object->ref_fournisseur)?$object->ref_fournisseur:''), + 'object_source_invoice_ref'=>$invoice_source->ref, + 'object_date'=>dol_print_date($object->date,'day'), + 'object_date_limit'=>dol_print_date($object->date_lim_reglement,'day'), + 'object_date_creation'=>dol_print_date($object->date_creation,'day'), + 'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), + 'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), + 'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), + 'object_payment_mode_code'=>$object->mode_reglement_code, + 'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), + 'object_payment_term_code'=>$object->cond_reglement_code, + 'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement), + 'object_total_ht'=>price2num($object->total_ht), + 'object_total_vat'=>price2num($object->total_tva), + 'object_total_ttc'=>price2num($object->total_ttc), + 'object_total_discount_ht' => price2num($object->getTotalDiscount(), 0, $outputlangs), + 'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''), + 'object_note_private'=>$object->note, + 'object_note'=>$object->note_public, + // Payments + 'object_already_payed'=>$alreadypayed, + 'object_remain_to_pay'=>price2num($object->total_ttc - $sumpayed) + ); - // Add vat by rates + // Add vat by rates foreach ($object->lines as $line) { if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0; @@ -152,41 +152,41 @@ class doc_generic_invoice_odt extends ModelePDFFactures $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key='object',$outputlangs); } - return $resarray; - } + return $resarray; + } - /** - * Define array with couple substitution key => substitution value - * - * @param array $line Array of lines - * @param Translate $outputlangs Lang object to use for output - * @return array Return substitution array - */ - function get_substitutionarray_lines($line,$outputlangs) - { - global $conf; + /** + * Define array with couple substitution key => substitution value + * + * @param array $line Array of lines + * @param Translate $outputlangs Lang object to use for output + * @return array Return substitution array + */ + function get_substitutionarray_lines($line,$outputlangs) + { + global $conf; - return array( - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), - 'line_product_ref'=>$line->product_ref, - 'line_product_label'=>$line->product_label, - 'line_desc'=>$line->desc, - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), - 'line_up'=>price($line->subprice, 0, $outputlangs), - 'line_qty'=>$line->qty, - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), - 'line_price_ht'=>price2num($line->total_ht), - 'line_price_ttc'=>price2num($line->total_ttc), - 'line_price_vat'=>price2num($line->total_tva), - 'line_date_start'=>dol_print_date($line->date_start, 'day', false, $outputlangs), - 'line_date_end'=>dol_print_date($line->date_end, 'day', false, $outputlangs), - ); - } + return array( + 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), + 'line_product_ref'=>$line->product_ref, + 'line_product_label'=>$line->product_label, + 'line_desc'=>$line->desc, + 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), + 'line_up'=>price($line->subprice, 0, $outputlangs), + 'line_qty'=>$line->qty, + 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), + 'line_price_ht'=>price2num($line->total_ht), + 'line_price_ttc'=>price2num($line->total_ttc), + 'line_price_vat'=>price2num($line->total_tva), + 'line_date_start'=>dol_print_date($line->date_start, 'day', false, $outputlangs), + 'line_date_end'=>dol_print_date($line->date_end, 'day', false, $outputlangs), + ); + } /** * Return description of a module * - * @param Translate $langs Lang object to use for output + * @param Translate $langs Lang object to use for output * @return string Description */ function info($langs) @@ -214,7 +214,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures { $tmpdir=trim($tmpdir); $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); - if (! $tmpdir) { unset($listofdir[$key]); continue; } + if (! $tmpdir) { + unset($listofdir[$key]); continue; + } if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); else { @@ -225,19 +227,19 @@ class doc_generic_invoice_odt extends ModelePDFFactures $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); // Add list of substitution keys $texthelp.='
'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'
'; - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it + $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); $texte.= ''; + $texte.= ''; $texte.= ''; + $texte.= ''; + $texte.= ''; $texte.= ''; - $texte.= '
'; $texte.= ''; - $texte.= '  '; - $texte.= ''; - $texte.= '
'; + $texte.= ''; // Scan directories if (count($listofdir)) $texte.=$langs->trans("NumberOfModelFilesFound").': '.count($listoffiles).''; @@ -251,7 +253,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures $texte.= ''; /*$texte.= ''; - $texte.= ''; + $texte.= ''; $texte.= ''; $texte.= ''; $texte.= '';*/ @@ -268,9 +270,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures * @param Facture $object Object source to build document * @param Translate $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param int $hidedetails Do not show line details - * @param int $hidedesc Do not show desc - * @param int $hideref Do not show ref + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref * @return int 1 if OK, <=0 if KO */ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) @@ -283,14 +285,14 @@ class doc_generic_invoice_odt extends ModelePDFFactures return -1; } - // Add odtgeneration hook - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } - $hookmanager->initHooks(array('odtgeneration')); - global $action; + // Add odtgeneration hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('odtgeneration')); + global $action; if (! is_object($outputlangs)) $outputlangs=$langs; $sav_charset_output=$outputlangs->charset_output; @@ -337,7 +339,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures $newfiletmp=preg_replace('/\.odt/i','',$newfile); $newfiletmp=preg_replace('/template_/i','',$newfiletmp); $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); - $newfiletmp=$objectref.'_'.$newfiletmp; + $newfiletmp=$objectref.'_'.$newfiletmp; //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; $file=$dir.'/'.$newfiletmp.'.odt'; //print "newdir=".$dir; @@ -348,70 +350,70 @@ class doc_generic_invoice_odt extends ModelePDFFactures dol_mkdir($conf->facture->dir_temp); - // If BILLING contact defined on invoice, we use it - $usecontact=false; - $arrayidcontact=$object->getIdContact('external','BILLING'); - if (count($arrayidcontact) > 0) - { - $usecontact=true; - $result=$object->fetch_contact($arrayidcontact[0]); - } + // If BILLING contact defined on invoice, we use it + $usecontact=false; + $arrayidcontact=$object->getIdContact('external','BILLING'); + if (count($arrayidcontact) > 0) + { + $usecontact=true; + $result=$object->fetch_contact($arrayidcontact[0]); + } - // Recipient name - if (! empty($usecontact)) - { - // On peut utiliser le nom de la societe du contact - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; - else $socobject = $object->client; - } - else - { - $socobject=$object->client; - } + // Recipient name + if (! empty($usecontact)) + { + // On peut utiliser le nom de la societe du contact + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; + else $socobject = $object->client; + } + else + { + $socobject=$object->client; + } - // Fetch info for linked propal - $linked_propal = $object->fetchObjectLinked('','','',''); - //print_r($object->linkedObjects['propal']); exit; + // Fetch info for linked propal + $linked_propal = $object->fetchObjectLinked('','','',''); + //print_r($object->linkedObjects['propal']); exit; - $propal_object = $object->linkedObjects['propal'][0]; + $propal_object = $object->linkedObjects['propal'][0]; - // Make substitution - $substitutionarray=array( - '__FROM_NAME__' => $this->emetteur->nom, - '__FROM_EMAIL__' => $this->emetteur->email, - '__TOTAL_TTC__' => $object->total_ttc, - '__TOTAL_HT__' => $object->total_ht, - '__TOTAL_VAT__' => $object->total_tva - ); - complete_substitutions_array($substitutionarray, $langs, $object); - // Call the ODTSubstitution hook - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + // Make substitution + $substitutionarray=array( + '__FROM_NAME__' => $this->emetteur->nom, + '__FROM_EMAIL__' => $this->emetteur->email, + '__TOTAL_TTC__' => $object->total_ttc, + '__TOTAL_HT__' => $object->total_ht, + '__TOTAL_VAT__' => $object->total_tva + ); + complete_substitutions_array($substitutionarray, $langs, $object); + // Call the ODTSubstitution hook + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks // Line of free text $newfreetext=''; $paramfreetext='FACTURE_FREE_TEXT'; - if (! empty($conf->global->$paramfreetext)) - { - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); - } + if (! empty($conf->global->$paramfreetext)) + { + $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); + } - // Open and load template + // Open and load template require_once ODTPHP_PATH.'odf.php'; $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->facture->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->facture->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' ) ); // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] - //print html_entity_decode($odfHandler->__toString()); - //print exit; + //print html_entity_decode($odfHandler->__toString()); + //print exit; // Make substitutions into odt of freetext @@ -422,7 +424,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures { } - // Make substitutions into odt of user info + // Make substitutions into odt of user info $array_user=$this->get_substitutionarray_user($user,$outputlangs); $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); @@ -432,74 +434,74 @@ class doc_generic_invoice_odt extends ModelePDFFactures $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal); complete_substitutions_array($tmparray, $outputlangs, $object); - // Call the ODTSubstitution hook - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + // Call the ODTSubstitution hook + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } - } + //var_dump($tmparray); exit; + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + //var_dump($value);exit; + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } // Replace tags of lines - try - { - $listlines = $odfHandler->setSegment('lines'); - foreach ($object->lines as $line) - { - $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); - // Call the ODTSubstitutionLine hook - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - foreach($tmparray as $key => $val) - { - try - { - $listlines->setVars($key, $val, true, 'UTF-8'); - } - catch(OdfException $e) - { - } - catch(SegmentException $e) - { - } - } - $listlines->merge(); - } - $odfHandler->mergeSegment($listlines); - } - catch(OdfException $e) - { - $this->error=$e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; - } + try + { + $listlines = $odfHandler->setSegment('lines'); + foreach ($object->lines as $line) + { + $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); + // Call the ODTSubstitutionLine hook + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); + $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + foreach($tmparray as $key => $val) + { + try + { + $listlines->setVars($key, $val, true, 'UTF-8'); + } + catch(OdfException $e) + { + } + catch(SegmentException $e) + { + } + } + $listlines->merge(); + } + $odfHandler->mergeSegment($listlines); + } + catch(OdfException $e) + { + $this->error=$e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; + } - // Call the beforeODTSave hook + // Call the beforeODTSave hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - // Write new file + // Write new file //$result=$odfHandler->exportAsAttachedFile('toto'); $odfHandler->saveToDisk($file); if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + @chmod($file, octdec($conf->global->MAIN_UMASK)); $odfHandler=null; // Destroy object diff --git a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php index df61cbed461..26d67f09a32 100644 --- a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php +++ b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php @@ -1,21 +1,21 @@ * Copyright (C) 2012 Juanjo Menent - * - * 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 3 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, see . - * or see http://www.gnu.org/ - */ +* +* 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 3 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, see . +* or see http://www.gnu.org/ +*/ /** * \file htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php @@ -89,7 +89,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales /** * Return description of a module * - * @param Translate $langs Lang object to use for output + * @param Translate $langs Lang object to use for output * @return string Description */ function info($langs) @@ -123,7 +123,9 @@ class doc_generic_proposal_odt extends ModelePDFPropales { $tmpdir=trim($tmpdir); $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); - if (! $tmpdir) { unset($listofdir[$key]); continue; } + if (! $tmpdir) { + unset($listofdir[$key]); continue; + } if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); else { @@ -134,19 +136,19 @@ class doc_generic_proposal_odt extends ModelePDFPropales $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); // Add list of substitution keys $texthelp.='
'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'
'; - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it + $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); $texte.= ''; + $texte.= ''; $texte.= ''; + $texte.= ''; + $texte.= ''; $texte.= ''; - $texte.= '
'; $texte.= ''; - $texte.= '  '; - $texte.= ''; - $texte.= '
'; + $texte.= ''; // Scan directories if (count($listofdir)) @@ -190,7 +192,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales $texte.= ''; /*$texte.= ''; - $texte.= ''; + $texte.= ''; $texte.= ''; $texte.= ''; $texte.= '';*/ @@ -207,9 +209,9 @@ class doc_generic_proposal_odt extends ModelePDFPropales * @param Propale $object Object source to build document * @param Translate $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param int $hidedetails Do not show line details - * @param int $hidedesc Do not show desc - * @param int $hideref Do not show ref + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref * @return int 1 if OK, <=0 if KO */ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) @@ -222,14 +224,14 @@ class doc_generic_proposal_odt extends ModelePDFPropales return -1; } - // Add odtgeneration hook - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } - $hookmanager->initHooks(array('odtgeneration')); - global $action; + // Add odtgeneration hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('odtgeneration')); + global $action; if (! is_object($outputlangs)) $outputlangs=$langs; $sav_charset_output=$outputlangs->charset_output; @@ -276,7 +278,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales $newfiletmp=preg_replace('/\.odt/i','',$newfile); $newfiletmp=preg_replace('/template_/i','',$newfiletmp); $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); - $newfiletmp=$objectref.'_'.$newfiletmp; + $newfiletmp=$objectref.'_'.$newfiletmp; //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; $file=$dir.'/'.$newfiletmp.'.odt'; //print "newdir=".$dir; @@ -287,64 +289,64 @@ class doc_generic_proposal_odt extends ModelePDFPropales dol_mkdir($conf->propal->dir_temp); - // If BILLING contact defined on invoice, we use it - $usecontact=false; - $arrayidcontact=$object->getIdContact('external','BILLING'); - if (count($arrayidcontact) > 0) - { - $usecontact=true; - $result=$object->fetch_contact($arrayidcontact[0]); - } + // If BILLING contact defined on invoice, we use it + $usecontact=false; + $arrayidcontact=$object->getIdContact('external','BILLING'); + if (count($arrayidcontact) > 0) + { + $usecontact=true; + $result=$object->fetch_contact($arrayidcontact[0]); + } - // Recipient name - if (! empty($usecontact)) - { - // On peut utiliser le nom de la societe du contact - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; - else $socobject = $object->client; - } - else - { - $socobject=$object->client; - } + // Recipient name + if (! empty($usecontact)) + { + // On peut utiliser le nom de la societe du contact + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; + else $socobject = $object->client; + } + else + { + $socobject=$object->client; + } - // Make substitution - $substitutionarray=array( - '__FROM_NAME__' => $this->emetteur->nom, - '__FROM_EMAIL__' => $this->emetteur->email, - '__TOTAL_TTC__' => $object->total_ttc, - '__TOTAL_HT__' => $object->total_ht, - '__TOTAL_VAT__' => $object->total_vat - ); - complete_substitutions_array($substitutionarray, $langs, $object); - // Call the ODTSubstitution hook - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + // Make substitution + $substitutionarray=array( + '__FROM_NAME__' => $this->emetteur->nom, + '__FROM_EMAIL__' => $this->emetteur->email, + '__TOTAL_TTC__' => $object->total_ttc, + '__TOTAL_HT__' => $object->total_ht, + '__TOTAL_VAT__' => $object->total_vat + ); + complete_substitutions_array($substitutionarray, $langs, $object); + // Call the ODTSubstitution hook + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks // Line of free text $newfreetext=''; $paramfreetext='PROPALE_FREE_TEXT'; - if (! empty($conf->global->$paramfreetext)) - { - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); - } + if (! empty($conf->global->$paramfreetext)) + { + $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); + } - // Open and load template + // Open and load template require_once ODTPHP_PATH.'odf.php'; $odfHandler = new odf( - $srctemplatepath, - array( - 'PATH_TO_TMP' => $conf->propal->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' + $srctemplatepath, + array( + 'PATH_TO_TMP' => $conf->propal->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' ) ); // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] - //print html_entity_decode($odfHandler->__toString()); - //print exit; + //print html_entity_decode($odfHandler->__toString()); + //print exit; // Make substitutions into odt of freetext @@ -355,29 +357,29 @@ class doc_generic_proposal_odt extends ModelePDFPropales { } - // Make substitutions into odt of user info + // Make substitutions into odt of user info $tmparray=$this->get_substitutionarray_user($user,$outputlangs); - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } - } - // Make substitutions into odt of mysoc - $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); + //var_dump($tmparray); exit; + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + //var_dump($value);exit; + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + // Make substitutions into odt of mysoc + $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); //var_dump($tmparray); exit; foreach($tmparray as $key=>$value) { @@ -397,7 +399,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales { } } - // Make substitutions into odt of thirdparty + // Make substitutions into odt of thirdparty $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); foreach($tmparray as $key=>$value) { @@ -417,74 +419,74 @@ class doc_generic_proposal_odt extends ModelePDFPropales } } // Replace tags of object + external modules - $tmparray=$this->get_substitutionarray_propal($object,$outputlangs); - //print_r($tmparray); exit; - complete_substitutions_array($tmparray, $outputlangs, $object); - // Call the ODTSubstitution hook - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - } - } + $tmparray=$this->get_substitutionarray_propal($object,$outputlangs); + //print_r($tmparray); exit; + complete_substitutions_array($tmparray, $outputlangs, $object); + // Call the ODTSubstitution hook + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } // Replace tags of lines - try - { - $listlines = $odfHandler->setSegment('lines'); - foreach ($object->lines as $line) - { - $tmparray=$this->get_substitutionarray_propal_lines($line,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); - // Call the ODTSubstitutionLine hook - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - foreach($tmparray as $key => $val) - { - try - { - $listlines->setVars($key, $val, true, 'UTF-8'); - } - catch(OdfException $e) - { - } - catch(SegmentException $e) - { - } - } - $listlines->merge(); - } - $odfHandler->mergeSegment($listlines); - } - catch(OdfException $e) - { - $this->error=$e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; - } + try + { + $listlines = $odfHandler->setSegment('lines'); + foreach ($object->lines as $line) + { + $tmparray=$this->get_substitutionarray_propal_lines($line,$outputlangs); + complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); + // Call the ODTSubstitutionLine hook + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); + $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + foreach($tmparray as $key => $val) + { + try + { + $listlines->setVars($key, $val, true, 'UTF-8'); + } + catch(OdfException $e) + { + } + catch(SegmentException $e) + { + } + } + $listlines->merge(); + } + $odfHandler->mergeSegment($listlines); + } + catch(OdfException $e) + { + $this->error=$e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; + } - // Call the beforeODTSave hook + // Call the beforeODTSave hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - // Write new file + // Write new file //$result=$odfHandler->exportAsAttachedFile('toto'); $odfHandler->saveToDisk($file); if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + @chmod($file, octdec($conf->global->MAIN_UMASK)); $odfHandler=null; // Destroy object From 9b2cbfef054a8e7b7757b7d17cecb78d6de8fb5a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 11 Apr 2013 17:10:11 +0200 Subject: [PATCH 05/14] Fix: for avoid problem with multicompany thirdparty sharing --- htdocs/core/class/conf.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 764438a273c..06510e28199 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -331,7 +331,8 @@ class Conf // societe if (empty($this->global->SOCIETE_CODECLIENT_ADDON)) $this->global->SOCIETE_CODECLIENT_ADDON="mod_codeclient_leopard"; - if (empty($this->global->SOCIETE_CODEFOURNISSEUR_ADDON)) $this->global->SOCIETE_CODEFOURNISSEUR_ADDON=$this->global->SOCIETE_CODECLIENT_ADDON; + // Unused constant and for avoid problem with multicompany sharing + //if (empty($this->global->SOCIETE_CODEFOURNISSEUR_ADDON)) $this->global->SOCIETE_CODEFOURNISSEUR_ADDON=$this->global->SOCIETE_CODECLIENT_ADDON; if (empty($this->global->SOCIETE_CODECOMPTA_ADDON)) $this->global->SOCIETE_CODECOMPTA_ADDON="mod_codecompta_panicum"; // Security From 030752c4c6fb5451f1c40b0447f14519fd54c62c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 11 Apr 2013 17:24:17 +0200 Subject: [PATCH 06/14] Fix: missing to rename constant --- htdocs/fourn/class/fournisseur.commande.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 90e5afa1726..2c6ad45f30f 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -603,7 +603,7 @@ class CommandeFournisseur extends CommonOrder /** * Renvoie la reference de commande suivante non utilisee en fonction du modele - * de numerotation actif defini dans COMMANDE_SUPPLIER_ADDON + * de numerotation actif defini dans COMMANDE_SUPPLIER_ADDON_NUMBER * * @param Societe $soc objet societe * @return string reference libre pour la facture @@ -615,14 +615,14 @@ class CommandeFournisseur extends CommonOrder $dir = DOL_DOCUMENT_ROOT .'/core/modules/supplier_order/'; - if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON)) + if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) { - $file = $conf->global->COMMANDE_SUPPLIER_ADDON.'.php'; + $file = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER.'.php'; if (is_readable($dir.'/'.$file)) { // Definition du nom de modele de numerotation de commande fournisseur - $modName=$conf->global->COMMANDE_SUPPLIER_ADDON; + $modName=$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER; require_once $dir.'/'.$file; // Recuperation de la nouvelle reference @@ -643,7 +643,7 @@ class CommandeFournisseur extends CommonOrder } else { - print $langs->trans("Error")." ".$langs->trans("Error_FailedToLoad_COMMANDE_SUPPLIER_ADDON_File",$conf->global->COMMANDE_SUPPLIER_ADDON); + print $langs->trans("Error")." ".$langs->trans("Error_FailedToLoad_COMMANDE_SUPPLIER_ADDON_File",$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER); return -2; } } From af40d27eb57012a1b04b1560cb17ad7036505145 Mon Sep 17 00:00:00 2001 From: fhenry Date: Thu, 11 Apr 2013 17:26:49 +0200 Subject: [PATCH 07/14] Remove require_once from odf.php because it cause regression. --- htdocs/includes/odtphp/odf.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 2d5c991fb77..4f737d15b71 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -1,6 +1,4 @@ Date: Thu, 11 Apr 2013 17:31:24 +0200 Subject: [PATCH 08/14] Add hook for substitution --- .../project/pdf/doc_generic_project_odt.modules.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php index 912c9fd25ad..218ae0620dd 100644 --- a/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/pdf/doc_generic_project_odt.modules.php @@ -125,7 +125,7 @@ class doc_generic_project_odt extends ModelePDFProjects 'object_note_private'=>$object->note_private, 'object_note_public'=>$object->note_public, 'object_public'=>$object->public, - 'object_statut'=>html_entity_decode($object->getLibStatut()) + 'object_statut'=>$object->getLibStatut() ); } @@ -478,7 +478,6 @@ class doc_generic_project_odt extends ModelePDFProjects // Make substitutions into odt of user info $tmparray=$this->get_substitutionarray_user($user,$outputlangs); - //var_dump($tmparray); exit; foreach($tmparray as $key=>$value) { try { @@ -805,7 +804,6 @@ class doc_generic_project_odt extends ModelePDFProjects $contact['fullname']=$objectdetail->getFullName($outputlangs,1); $tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs); - complete_substitutions_array($tmparray, $outputlangs, $contact, $contact, "completesubstitutionarray_lines"); foreach($tmparray as $key => $val) { try @@ -937,7 +935,7 @@ class doc_generic_project_odt extends ModelePDFProjects $ref_array['amountttc']=''; } - $ref_array['status']=html_entity_decode($element->getLibStatut(0)); + $ref_array['status']=$element->getLibStatut(0); $tmparray=$this->get_substitutionarray_project_reference($ref_array,$outputlangs); @@ -975,7 +973,8 @@ class doc_generic_project_odt extends ModelePDFProjects // Write new file - $odfHandler->saveToDisk($file); + $odfHandler->saveToDisk($file); + //$odfHandler->exportAsAttachedPDF($file); if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); From e209959c90dc11de2618d0f61dbdee00cacc1984 Mon Sep 17 00:00:00 2001 From: simnandez Date: Thu, 11 Apr 2013 17:58:56 +0200 Subject: [PATCH 09/14] Fix: Remove ChangeLog duplicity --- ChangeLog | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index ffff5a7a6e0..85ac7de62a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -89,24 +89,6 @@ WARNING: If you used external modules, some of them may need to be upgraded due -***** ChangeLog for 3.3.2 compared to 3.3.1 ***** - --Fix: Ducth (nl_NL) translation --Fix: [ bug #790 ] Spanish localtax RE not being correctly calculated --Generalize fix: file with a specific mask not found, again - - - -***** ChangeLog for 3.3.1 compared to 3.3 ***** - -- Fix: [ bug #733 ] Mass emailing tools do not support