From fc935136074f54cfe9549be90d3771fae341e07e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 10 Aug 2011 17:56:02 +0000 Subject: [PATCH] Fix: works on repair broken features (in progress) --- htdocs/commande/fiche.php | 22 +--- htdocs/compta/facture.php | 105 +++--------------- .../modules/facture/doc/pdf_crabe.modules.php | 16 +-- .../facture/doc/pdf_oursin.modules.php | 16 +-- .../modules/facture/modules_facture.php | 6 +- 5 files changed, 39 insertions(+), 126 deletions(-) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 73e97061f5e..504a0e1852c 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -25,7 +25,7 @@ * \file htdocs/commande/fiche.php * \ingroup commande * \brief Page to show customer order - * \version $Id: fiche.php,v 1.529 2011/08/10 17:40:46 hregis Exp $ + * \version $Id: fiche.php,v 1.530 2011/08/10 17:56:18 hregis Exp $ */ require("../main.inc.php"); @@ -296,24 +296,6 @@ if ($action == 'add' && $user->rights->commande->creer) // Hooks $reshook=$hookmanager->executeHooks('createfrom',$action,$srcobject,$object_id,$object->element); // Note that $action and $object may have been modified by hook if ($reshook < 0) $error++; - /* - if (! empty($object->hooks)) - { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'createfrom')) - { - $res = $module->createfrom($srcobject,$object_id,$object->element); - if ($res < 0) $error++; - } - } - } - } - }*/ } else { @@ -2081,5 +2063,5 @@ else $db->close(); -llxFooter('$Date: 2011/08/10 17:40:46 $ - $Revision: 1.529 $'); +llxFooter('$Date: 2011/08/10 17:56:18 $ - $Revision: 1.530 $'); ?> diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index c8c1516b9ad..451bdc56932 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -25,7 +25,7 @@ * \file htdocs/compta/facture.php * \ingroup facture * \brief Page to create/see an invoice - * \version $Id: facture.php,v 1.850 2011/08/03 00:46:23 eldy Exp $ + * \version $Id: facture.php,v 1.851 2011/08/10 17:56:13 hregis Exp $ */ require('../main.inc.php'); @@ -74,41 +74,17 @@ $usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE; $object=new Facture($db); -// Instantiate hooks of thirdparty module -if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) -{ - $object->callHooks('invoicecard'); -} - +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); +$hookmanager=new HookManager($db); +$hookmanager->callHooks(array('invoicecard')); /******************************************************************************/ /* Actions */ /******************************************************************************/ -// Hook of actions -if (! empty($object->hooks)) -{ - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'doActions')) - { - $reshook+=$module->doActions($object); - if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0)) - { - $mesg=$module->error; $mesgs=$module->errors; - if ($action=='add') $action='create'; - if ($action=='update') $action='edit'; - } - } - } - } - } -} +$reshook=$hookmanager->executeHooks('doActions',$action,$object,$socid); // Note that $action and $object may have been modified by some hooks // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes') @@ -805,23 +781,8 @@ if ($action == 'add' && $user->rights->facture->creer) } // Hooks - if (! empty($object->hooks)) - { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'createfrom')) - { - $res = $module->createfrom($srcobject,$id,$object->element); - if ($res < 0) $error++; - } - } - } - } - } + $reshook=$hookmanager->executeHooks('createfrom',$action,$srcobject,$id,$object->element); // Note that $action and $object may have been modified by hook + if ($reshook < 0) $error++; } else { @@ -1415,7 +1376,7 @@ if (GETPOST('action') == 'builddoc') // En get ou en post $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - $result=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); + $result=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); if ($result <= 0) { dol_print_error($db,$result); @@ -2071,21 +2032,8 @@ else // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes',1); } - - // Hook for external modules - if (empty($formconfirm) && ! empty($object->hooks)) - { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (empty($formconfirm) && method_exists($module,'formconfirm')) $formconfirm = $module->formconfirm($action,$object,$lineid); - } - } - } - } + + if (! $formconfirm) $formconfirm=$hookmanager->executeHooks('formconfirm',$action,$object,$lineid); // Note that $action and $object may have been modified by hook // Print form confirm print $formconfirm; @@ -2603,7 +2551,7 @@ else print ''; // Show object lines - if (! empty($object->lines)) $object->printObjectLines($action,$mysoc,$soc,$lineid,1); + if (! empty($object->lines)) $object->printObjectLines($action,$mysoc,$soc,$lineid,1,$hookmanager); /* * Form to add new line @@ -2612,33 +2560,16 @@ else { $var=true; - $object->formAddFreeProduct(1,$mysoc,$soc); + $object->formAddFreeProduct(1,$mysoc,$soc,$hookmanager); // Add predefined products/services if ($conf->product->enabled || $conf->service->enabled) { $var=!$var; - $object->formAddPredefinedProduct(1,$mysoc,$soc); - } - - // Hook for external modules - if (! empty($object->hooks)) - { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'formAddObject')) - { - $var=!$var; - $module->formAddObject($object); - } - } - } - } + $object->formAddPredefinedProduct(1,$mysoc,$soc,$hookmanager); } + + $reshook=$hookmanager->executeHooks('formAddObject',$action,$object); // Note that $action and $object may have been modified by hook } print "
\n"; @@ -2874,7 +2805,7 @@ else $delallowed=$user->rights->facture->supprimer; print '
'; - $somethingshown=$formfile->show_documents('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang,$object->hooks); + $somethingshown=$formfile->show_documents('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang,$hookmanager); /* * Linked object block @@ -3247,5 +3178,5 @@ else $db->close(); -llxFooter('$Date: 2011/08/03 00:46:23 $ - $Revision: 1.850 $'); +llxFooter('$Date: 2011/08/10 17:56:13 $ - $Revision: 1.851 $'); ?> diff --git a/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php b/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php index 272b400539a..5eed344e67d 100755 --- a/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php @@ -24,7 +24,7 @@ * \ingroup facture * \brief File of class to generate invoices from crab model * \author Laurent Destailleur - * \version $Id: pdf_crabe.modules.php,v 1.12 2011/07/31 23:28:15 eldy Exp $ + * \version $Id: pdf_crabe.modules.php,v 1.13 2011/08/10 17:56:11 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT."/includes/modules/facture/modules_facture.php"); @@ -115,7 +115,7 @@ class pdf_crabe extends ModelePDFFactures * @param hideref Do not show ref * @return int 1=OK, 0=KO */ - function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) + function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false) { global $user,$langs,$conf; @@ -247,7 +247,7 @@ class pdf_crabe extends ModelePDFFactures // Description of product line $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage $curX = $this->posxdesc-1; - pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc); + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,0,$hookmanager); $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut $nexY = $pdf->GetY(); @@ -255,18 +255,18 @@ class pdf_crabe extends ModelePDFFactures // VAT Rate if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) { - $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); + $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->posxtva, $curY); $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R'); } // Prix unitaire HT avant remise - $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); + $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->posxup, $curY); $pdf->MultiCell($this->posxqty-$this->posxup-1, 3, $up_excl_tax, 0, 'R', 0); // Quantity - $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); + $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->posxqty, $curY); $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $qty, 0, 'R'); // Enough for 6 chars @@ -274,12 +274,12 @@ class pdf_crabe extends ModelePDFFactures if ($object->lines[$i]->remise_percent) { $pdf->SetXY ($this->posxdiscount-2, $curY); - $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); + $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R'); } // Total HT ligne - $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); + $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->postotalht, $curY); $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0); diff --git a/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php b/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php index 50991f60be7..b702ddae805 100755 --- a/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php +++ b/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php @@ -25,7 +25,7 @@ * \ingroup facture * \brief Fichier de la classe permettant de generer les factures au modele oursin * \author Sylvain SCATTOLINI base sur un modele de Laurent Destailleur - * \version $Id: pdf_oursin.modules.php,v 1.11 2011/07/31 23:28:15 eldy Exp $ + * \version $Id: pdf_oursin.modules.php,v 1.12 2011/08/10 17:56:10 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); @@ -114,7 +114,7 @@ class pdf_oursin extends ModelePDFFactures * @param hideref Do not show ref * @return int 1=OK, 0=KO */ - function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) + function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false) { global $user,$langs,$conf; @@ -211,7 +211,7 @@ class pdf_oursin extends ModelePDFFactures $curY = $nexY; // Description of product line - pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$this->posxdesc-1,$curY+1,$hideref,$hidedesc); + pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$this->posxdesc-1,$curY+1,$hideref,$hidedesc,0,$hookmanager); $nexY = $pdf->GetY(); @@ -220,31 +220,31 @@ class pdf_oursin extends ModelePDFFactures { if ($this->franchise!=1) { - $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); + $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->marges['g']+118, $curY); $pdf->MultiCell(12, 3, $vat_rate, 0, 'R'); } } // Prix unitaire HT avant remise - $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); + $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->marges['g']+132, $curY); $pdf->MultiCell(16, 3, $up_excl_tax, 0, 'R', 0); // Quantity - $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); + $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->marges['g']+150, $curY); $pdf->MultiCell(10, 3, $qty, 0, 'R'); // Remise sur ligne $pdf->SetXY ($this->marges['g']+160, $curY); if ($object->lines[$i]->remise_percent) { - $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); + $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->MultiCell(14, 3, $remise_percent, 0, 'R'); } // Total HT - $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); + $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY ($this->marges['g']+168, $curY); $pdf->MultiCell(21, 3, $total_excl_tax, 0, 'R', 0); diff --git a/htdocs/includes/modules/facture/modules_facture.php b/htdocs/includes/modules/facture/modules_facture.php index d01c29a5a53..9a2bb575caf 100644 --- a/htdocs/includes/modules/facture/modules_facture.php +++ b/htdocs/includes/modules/facture/modules_facture.php @@ -24,7 +24,7 @@ * \ingroup facture * \brief Fichier contenant la classe mere de generation des factures en PDF * et la classe mere de numerotation des factures - * \version $Id: modules_facture.php,v 1.93 2011/07/31 23:28:16 eldy Exp $ + * \version $Id: modules_facture.php,v 1.94 2011/08/10 17:56:02 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php'); @@ -144,7 +144,7 @@ class ModeleNumRefFactures * @param hideref Hide ref * @return int <0 if KO, >0 if OK */ -function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) +function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { global $conf,$user,$langs; @@ -210,7 +210,7 @@ function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hide // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc) > 0) + if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0) { // Success in building document. We build meta file. facture_meta_create($db, $object->id);