From 6afa1cb2c9eb501ace9692a23b1a1aa858cfb8f3 Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Sun, 17 Mar 2013 14:40:49 +0100 Subject: [PATCH 1/3] normalize --- .../modules/expedition/modules_expedition.php | 40 +++++++++++-------- .../modules_commandefournisseur.php | 22 +++++----- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/htdocs/core/modules/expedition/modules_expedition.php b/htdocs/core/modules/expedition/modules_expedition.php index 0b7d2ffdc54..bf74e1adcd1 100644 --- a/htdocs/core/modules/expedition/modules_expedition.php +++ b/htdocs/core/modules/expedition/modules_expedition.php @@ -5,7 +5,7 @@ * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2011-2012 Philippe Grand + * Copyright (C) 2011-2013 Philippe Grand * * 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 @@ -25,7 +25,8 @@ /** * \file htdocs/core/modules/expedition/modules_expedition.php * \ingroup expedition - * \brief File of class to manage expedition numbering + * \brief File that contains parent class for sending receipts models + * and parent class for sending receipts numbering models */ require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; @@ -60,15 +61,15 @@ abstract class ModelePdfExpedition extends CommonDocGenerator /** - * Classe mere des modeles de numerotation des references d expedition + * Parent Class of numbering models of sending receipts references */ abstract class ModelNumRefExpedition { var $error=''; - /** Return if a module can be used or not + /** Return if a model can be used or not * - * @return boolean true if module can be used + * @return boolean true if model can be used */ function isEnabled() { @@ -88,7 +89,7 @@ abstract class ModelNumRefExpedition } /** - * Return numbering example + * Returns numbering example * * @return string Example */ @@ -110,7 +111,7 @@ abstract class ModelNumRefExpedition } /** - * Return next value + * Returns next value assigned * * @param Societe $objsoc Third party object * @param Object $shipment Shipment object @@ -123,7 +124,7 @@ abstract class ModelNumRefExpedition } /** - * Return numbering version module + * Returns version of the numbering model * * @return string Value */ @@ -158,7 +159,7 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs) $srctemplatepath=''; - // Positionne le modele sur le nom du modele a utiliser + // Sets the model on the model name to use if (! dol_strlen($modele)) { if (! empty($conf->global->EXPEDITION_ADDON_PDF)) @@ -171,7 +172,7 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs) } } - // If selected modele is a filename template (then $modele="modelname:filename") + // If selected model is a filename template (then $modele="modelname:filename") $tmp=explode(':',$modele,2); if (! empty($tmp[1])) { @@ -189,7 +190,7 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs) { $file = $prefix."_expedition_".$modele.".modules.php"; - // On verifie l'emplacement du modele + // We check the model location $file=dol_buildpath($reldir."core/modules/expedition/doc/".$file,0); if (file_exists($file)) { @@ -201,7 +202,7 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs) if ($filefound) break; } - // Charge le modele + // Load the model if ($filefound) { require_once $file; @@ -221,14 +222,14 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs) //require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; //dol_delete_preview($object); - // Appel des triggers + // Calls triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($db); $result=$interface->run_triggers('SHIPPING_BUILDDOC',$object,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // End calls triggers return 1; } @@ -242,8 +243,15 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs) } else { - dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file)); - return -1; + if (! $conf->global->EXPEDITION_ADDON_PDF) + { + print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_PDF_NotDefined"); + } + else + { + print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); + } + return 0; } } ?> \ No newline at end of file diff --git a/htdocs/core/modules/supplier_order/modules_commandefournisseur.php b/htdocs/core/modules/supplier_order/modules_commandefournisseur.php index f9407ba804e..d14d4ae5f43 100644 --- a/htdocs/core/modules/supplier_order/modules_commandefournisseur.php +++ b/htdocs/core/modules/supplier_order/modules_commandefournisseur.php @@ -24,7 +24,7 @@ /** * \file htdocs/core/modules/supplier_order/modules_commandefournisseur.php * \ingroup commande fournisseur - * \brief File that contain parent class for supplier orders models + * \brief File that contains parent class for supplier orders models * and parent class for supplier orders numbering models */ require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; @@ -44,13 +44,13 @@ abstract class ModelePDFSuppliersOrders extends CommonDocGenerator * * @param DoliDB $db Database handler * @param string $maxfilenamelength Max length of value to show - * @return array List of numbers + * @return array List of templates */ static function liste_modeles($db,$maxfilenamelength=0) { global $conf; - $type='order_supplier'; + $type='supplier_order'; $liste=array(); include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -79,7 +79,7 @@ abstract class ModeleNumRefSuppliersOrders return true; } - /** Returns the default description of the model numbering + /** Returns default description of numbering model * * @return string Description Text */ @@ -101,7 +101,7 @@ abstract class ModeleNumRefSuppliersOrders return $langs->trans("NoExample"); } - /** Tests if the numbers already in force in the database do not cause conflicts that would prevent this numbering. + /** Tests if existing numbers make problems with numbering * * @return boolean false if conflict, true if ok */ @@ -120,7 +120,7 @@ abstract class ModeleNumRefSuppliersOrders return $langs->trans("NotAvailable"); } - /** Returns version of the model numbering + /** Returns version of the numbering model * * @return string Value */ @@ -138,7 +138,7 @@ abstract class ModeleNumRefSuppliersOrders /** - * Create a document onto disk according to template module. + * Create a document onto disk according to template model. * * @param DoliDB $db Database handler * @param Object $object Object supplier order @@ -164,7 +164,7 @@ function supplier_order_pdf_create($db, $object, $modele, $outputlangs, $hidedet $srctemplatepath=''; - // Set the model on the model name to use + // Sets the model on the model name to use if (! dol_strlen($modele)) { if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF)) @@ -195,7 +195,7 @@ function supplier_order_pdf_create($db, $object, $modele, $outputlangs, $hidedet { $file = $prefix."_".$modele.".modules.php"; - // We checked the location of the model + // We check the model location $file=dol_buildpath($reldir."core/modules/supplier_order/pdf/".$file,0); if (file_exists($file)) { @@ -229,7 +229,9 @@ function supplier_order_pdf_create($db, $object, $modele, $outputlangs, $hidedet include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($db); $result=$interface->run_triggers('ORDER_SUPPLIER_BUILDDOC',$object,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } // End calls triggers return 1; From 29b8ce1c2dff923a448c9eb5d477b47be83f3ae1 Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Sun, 17 Mar 2013 15:27:52 +0100 Subject: [PATCH 2/3] try to fix: supplier invoice numbering --- htdocs/core/modules/modFournisseur.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index 5868d6d2108..5ebff71df0c 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -102,7 +102,7 @@ class modFournisseur extends DolibarrModules $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_NUMBER"; $this->const[$r][1] = "chaine"; - $this->const[$r][2] = "mod_facture_fournisseur_tulip"; + $this->const[$r][2] = "mod_facture_fournisseur_cactus"; $this->const[$r][3] = 'Nom du gestionnaire de numerotation des factures fournisseur'; $this->const[$r][4] = 0; $r++; From 294b4865d116c1b83b21ea0f9ff428615682739f Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Sun, 17 Mar 2013 16:10:43 +0100 Subject: [PATCH 3/3] normalize and simplify code --- htdocs/admin/supplier_invoice.php | 96 +++++++++++-------------------- 1 file changed, 34 insertions(+), 62 deletions(-) diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php index 49e31d1b86c..f28e3d1a244 100644 --- a/htdocs/admin/supplier_invoice.php +++ b/htdocs/admin/supplier_invoice.php @@ -53,10 +53,10 @@ $specimenthirdparty->initAsSpecimen(); if ($action == 'updateMask') { - $maskconstorder=GETPOST('maskconstorder','alpha'); - $maskorder=GETPOST('maskorder','alpha'); + $maskconstinvoice=GETPOST('maskconstinvoice','alpha'); + $maskvalue=GETPOST('maskvalue','alpha'); - if ($maskconstorder) $res = dolibarr_set_const($db,$maskconstorder,$maskorder,'chaine',0,'',$conf->entity); + if ($maskconstinvoice) $res = dolibarr_set_const($db,$maskconstinvoice,$maskvalue,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; @@ -116,71 +116,37 @@ if ($action == 'specimen') // For invoices } } -if ($action == 'set') +// Activate a model +else if ($action == 'set') { - $label = GETPOST('label','alpha'); - $scandir = GETPOST('scandir','alpha'); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)"; - $sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", "; - $sql.= ($label?"'".$db->escape($label)."'":'null').", "; - $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null"); - $sql.= ")"; - $res=$db->query($sql); - if ($res) - { - - } - // else dol_print_error($db); + $ret = addDocumentModel($value, $type, $label, $scandir); } -if ($action == 'del') +else if ($action == 'del') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql.= " WHERE nom = '".$value."'"; - $sql.= " AND type = '".$type."'"; - $sql.= " AND entity = ".$conf->entity; - $db->query($sql); - if ($res) - { - - } - // else dol_print_error($db); + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$value") dolibarr_del_const($db, 'INVOICE_SUPPLIER_ADDON_PDF',$conf->entity); + } } -if ($action == 'setdoc') +// Set default model +else if ($action == 'setdoc') { - $label = GETPOST('label','alpha'); - $scandir = GETPOST('scandir','alpha'); + if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) + { + // La constante qui a ete lue en avant du nouveau set + // on passe donc par une variable pour avoir un affichage coherent + $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value; + } - $db->begin(); - - if ($type == 'order_supplier' && dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) - { - $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value; - } - - // On active le modele - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql_del.= " WHERE nom = '".$db->escape($value)."'"; - $sql_del.= " AND type = '".$type."'"; - $sql_del.= " AND entity = ".$conf->entity; - $result1=$db->query($sql_del); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)"; - $sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", "; - $sql.= ($label?"'".$db->escape($label)."'":'null').", "; - $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null"); - $sql.= ")"; - $result2=$db->query($sql); - if ($result1 && $result2) - { - $db->commit(); - } - else - { - $db->rollback(); - } + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } } if ($action == 'setmod') @@ -294,7 +260,7 @@ foreach ($dirmodels as $reldir) print $module->info(); print ''; - // Show example of numbering module + // Show example of numbering model print ''; $tmp=$module->getExample(); if (preg_match('/^Error/',$tmp)) { @@ -447,7 +413,7 @@ foreach ($dirmodels as $reldir) print ""; } - // Defaut + // Default print ''; if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name") { @@ -484,6 +450,12 @@ foreach ($dirmodels as $reldir) } print '
'; +print '
'; + +/* + * Other options + * + */ print_titre($langs->trans("OtherOptions")); print '';