diff --git a/dev/initdata/generate-facture.php b/dev/initdata/generate-facture.php index c0b52d70d24..56c1e4a0e3f 100644 --- a/dev/initdata/generate-facture.php +++ b/dev/initdata/generate-facture.php @@ -102,7 +102,7 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0) $result=$facture->create($user); if ($result >= 0) { - $result=$facture->set_valid($user,$socid); + $result=$facture->validate($user); if ($result) { $nbp = rand(2, 5); diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 3686224acee..d5de853df5a 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -241,15 +241,22 @@ foreach ($conf->file->dol_document_root as $dirroot) { while (($file = readdir($handle))!==false) { - if (is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') + if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) { - $filebis = $file."/".$file.".modules.php"; - - if (is_readable($dir.$filebis)) + $filebis = $file; + $classname = preg_replace('/\.php$/','',$file); + // For compatibility + if (! is_file($dir.$filebis)) + { + $filebis = $file."/".$file.".modules.php"; + $classname = "mod_facture_".$file; + } + //print "x".$dir."-".$filebis."-".$classname; + if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, strlen($filebis)-3, 3) == 'php') { // Chargement de la classe de numerotation require_once($dir.$filebis); - $classname = "mod_facture_".$file; + $module = new $classname($db); // Show modules according to features level @@ -260,7 +267,7 @@ foreach ($conf->file->dol_document_root as $dirroot) { $var = !$var; print ''; - echo "$file"; + echo preg_replace('/mod_facture_/','',preg_replace('/\.php$/','',$file)); print "\n"; print $module->info(); @@ -271,13 +278,14 @@ foreach ($conf->file->dol_document_root as $dirroot) print ''.$module->getExample().''; print ''; - if ($conf->global->FACTURE_ADDON == "$file") + //print "> ".$conf->global->FACTURE_ADDON." - ".$file; + if ($conf->global->FACTURE_ADDON == $file || $conf->global->FACTURE_ADDON.'.php' == $file) { print img_picto($langs->trans("Activated"),'on'); } else { - print ''.img_picto($langs->trans("Disabled"),'off').''; + print ''.img_picto($langs->trans("Disabled"),'off').''; } print ''; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index b8c8a834bcf..312c00bb59c 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -213,7 +213,7 @@ switch ( $_GET['action'] ) $resultcreate=$invoice->create($user,0,dol_stringtotime($obj_facturation->paiement_le())); if ($resultcreate > 0) { - $resultvalid=$invoice->set_valid($user,$conf_fksoc,$obj_facturation->num_facture()); + $resultvalid=$invoice->validate($user,$obj_facturation->num_facture()); } else { @@ -227,7 +227,7 @@ switch ( $_GET['action'] ) $resultcreate=$invoice->create($user,0,0); if ($resultcreate > 0) { - $resultvalid=$invoice->set_valid($user,$conf_fksoc,$obj_facturation->num_facture()); + $resultvalid=$invoice->validate($user,$obj_facturation->num_facture()); $id = $invoice->id; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 6444c759757..5067e82be1d 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -310,7 +310,7 @@ if ($_REQUEST['action'] == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $ $fac->fetch($_GET['facid']); $fac->fetch_client(); - $result = $fac->set_valid($user); + $result = $fac->validate($user); if ($result >= 0) { // Define output language @@ -679,7 +679,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) { $desc=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); - + // Dates $date_start=$prop->lignes[$i]->date_debut_prevue; if ($prop->lignes[$i]->date_debut_reel) $date_start=$prop->lignes[$i]->date_debut_reel; @@ -703,7 +703,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) 0, $prop->lignes[$i]->product_type ); - + if ($result < 0) { $error++; @@ -721,13 +721,13 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $error++; } } - + // If creation from order else if ($_POST['commandeid']) { $facture->commandeid = $_POST['commandeid']; $facid = $facture->create($user); - + if ($facid > 0) { $comm = new Commande($db); @@ -738,11 +738,11 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) for ($i = 0 ; $i < sizeof($lines) ; $i++) { $desc=($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); - + // Dates $date_start=$comm->lignes[$i]->date_start; $date_end=$comm->lignes[$i]->date_end; - + // Should use a function using total_ht, total_ttc and total_vat $result = $facture->addline( $facid, @@ -802,7 +802,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) if ($contrat->lignes[$i]->date_debut_reel) $date_start=$contrat->lignes[$i]->date_debut_reel; $date_end=$contrat->lignes[$i]->date_fin_prevue; if ($contrat->lignes[$i]->date_fin_reel) $date_end=$contrat->lignes[$i]->date_fin_reel; - + $result = $facture->addline( $facid, $desc, @@ -835,7 +835,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $error++; } } - + // If some invoice's lines already known else { @@ -1553,7 +1553,7 @@ if ($_GET['action'] == 'create') $object = new $classname($db); $object->fetch($_GET['originid']); $object->fetch_client(); - + $soc = $object->client; $cond_reglement_id = (!empty($object->cond_reglement_id)?$object->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:0)); $mode_reglement_id = (!empty($object->mode_reglement_id)?$object->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); @@ -2516,7 +2516,7 @@ else $nbrows=8; if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; if ($conf->projet->enabled) $nbrows++; - + //Local taxes if ($mysoc->pays_code=='ES' && $conf->global->MAIN_FEATURES_LEVEL >= 1) { @@ -2847,7 +2847,7 @@ else print ''.$langs->trans('Currency'.$conf->monnaie).''; print ''.$langs->trans('AmountVAT').''.price($fac->total_tva).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; - + // Amount Local Taxes if ($mysoc->pays_code=='ES' && $conf->global->MAIN_FEATURES_LEVEL >= 1) { @@ -2864,7 +2864,7 @@ else print ''.$langs->trans("Currency".$conf->monnaie).''; } } - + print ''.$langs->trans('AmountTTC').''.price($fac->total_ttc).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 056583a65ad..bca01cae101 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1294,11 +1294,10 @@ class Facture extends CommonObject /** * \brief Tag la facture comme validee + appel trigger BILL_VALIDATE * \param user Utilisateur qui valide la facture - * \param soc Ne sert plus. \\TODO A virer * \param force_number Reference a forcer de la facture * \return int <0 si ko, >0 si ok */ - function set_valid($user, $soc='', $force_number='') + function validate($user, $force_number='') { global $conf,$langs; @@ -1307,14 +1306,14 @@ class Facture extends CommonObject // Protection if (! $this->brouillon) { - dol_syslog("Facture::set_valid no draft status", LOG_WARNING); + dol_syslog("Facture::validate no draft status", LOG_WARNING); return 0; } if (! $user->rights->facture->valider) { $this->error='Permission denied'; - dol_syslog("Facture::set_valid ".$this->error, LOG_ERR); + dol_syslog("Facture::validate ".$this->error, LOG_ERR); return -1; } @@ -1397,11 +1396,11 @@ class Facture extends CommonObject } $sql.= ' WHERE rowid = '.$this->id; - dol_syslog("Facture::set_valid sql=".$sql); + dol_syslog("Facture::validate sql=".$sql); $resql=$this->db->query($sql); if (! $resql) { - dol_syslog("Facture::set_valid Echec update - 10 - sql=".$sql, LOG_ERR); + dol_syslog("Facture::validate Echec update - 10 - sql=".$sql, LOG_ERR); dol_print_error($this->db); $error++; } @@ -1450,7 +1449,7 @@ class Facture extends CommonObject $dirdest = $conf->facture->dir_output.'/'.$snumfa; if (file_exists($dirsource)) { - dol_syslog("Facture::set_valid rename dir ".$dirsource." into ".$dirdest); + dol_syslog("Facture::validate rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) { @@ -2238,20 +2237,36 @@ class Facture extends CommonObject if (empty($conf->global->FACTURE_ADDON)) { - $conf->global->FACTURE_ADDON='terre'; + $conf->global->FACTURE_ADDON='mod_facture_terre'; } - $file = $conf->global->FACTURE_ADDON."/".$conf->global->FACTURE_ADDON.".modules.php"; - $classname = "mod_facture_".$conf->global->FACTURE_ADDON; - - // Include file with class $mybool=false; + + $file = $conf->global->FACTURE_ADDON.".php"; + $classname = $conf->global->FACTURE_ADDON; + // Include file with class foreach ($conf->file->dol_document_root as $dirroot) { $dir = $dirroot."/includes/modules/facture/"; // Load file with numbering class (if found) $mybool|=@include_once($dir.$file); } + + // For compatibility + if (! $mybool) + { + $file = $conf->global->FACTURE_ADDON."/".$conf->global->FACTURE_ADDON.".modules.php"; + $classname = "mod_facture_".$conf->global->FACTURE_ADDON; + // Include file with class + foreach ($conf->file->dol_document_root as $dirroot) + { + $dir = $dirroot."/includes/modules/facture/"; + // Load file with numbering class (if found) + $mybool|=@include_once($dir.$file); + } + } + //print "xx".$mybool.$dir.$file."-".$classname; + if (! $mybool) dol_print_error('',"Failed to include file ".$file); $obj = new $classname(); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index a17168fe89b..1f0b9fedfea 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -563,7 +563,7 @@ class FactureFournisseur extends Facture * \param user Object user * \return int <0 if KO, =0 if nothing to do, >0 if OK */ - function set_valid($user) + function validate($user) { global $conf,$langs; @@ -572,7 +572,7 @@ class FactureFournisseur extends Facture // Protection if ($this->statut > 0) // This is to avoid to validate twice (avoid errors on logs and stock management) { - dol_syslog("FactureFournisseur::set_valid no draft status", LOG_WARNING); + dol_syslog("FactureFournisseur::validate no draft status", LOG_WARNING); return 0; } @@ -582,7 +582,7 @@ class FactureFournisseur extends Facture $sql.= " SET fk_statut = 1, fk_user_valid = ".$user->id; $sql.= " WHERE rowid = ".$this->id; - dol_syslog("FactureFournisseur::set_valid sql=".$sql); + dol_syslog("FactureFournisseur::validate sql=".$sql); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 1f6088411af..08ecca192a2 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -94,7 +94,7 @@ if ($_REQUEST['action'] == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $ { $facturefourn=new FactureFournisseur($db); $facturefourn->fetch($_GET['facid']); - $result = $facturefourn->set_valid($user); + $result = $facturefourn->validate($user); } if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') diff --git a/htdocs/includes/modules/facture/mercure/mercure.modules.php b/htdocs/includes/modules/facture/mod_facture_mercure.php similarity index 100% rename from htdocs/includes/modules/facture/mercure/mercure.modules.php rename to htdocs/includes/modules/facture/mod_facture_mercure.php diff --git a/htdocs/includes/modules/facture/mod_facture_terre.php b/htdocs/includes/modules/facture/mod_facture_terre.php new file mode 100644 index 00000000000..15a9e855a96 --- /dev/null +++ b/htdocs/includes/modules/facture/mod_facture_terre.php @@ -0,0 +1,166 @@ + + * Copyright (C) 2005-2009 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 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/includes/modules/facture/terre/terre.modules.php + * \ingroup facture + * \brief File containing class for numbering module Terre + * \version $Id$ + */ +require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); + +/** \class mod_facture_terre + * \brief Classe du modele de numerotation de reference de facture Terre + */ +class mod_facture_terre extends ModeleNumRefFactures +{ + var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' + var $prefixinvoice='FA'; + var $prefixcreditnote='AV'; + var $error=''; + + /** \brief Renvoi la description du modele de numerotation + * \return string Texte descripif + */ + function info() + { + global $langs; + + $langs->load("bills"); + + return $langs->trans('TerreNumRefModelDesc1',$this->prefixinvoice,$this->prefixcreditnote); + } + + /** \brief Renvoi un exemple de numerotation + * \return string Example + */ + function getExample() + { + return $this->prefixinvoice."0501-0001"; + } + + /** \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette num�rotation de fonctionner. + * \return boolean false si conflit, true si ok + */ + function canBeActivated() + { + global $langs,$conf; + + $langs->load("bills"); + + // Check invoice num + $fayymm=''; + + $sql = "SELECT MAX(facnumber)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $sql.= " WHERE facnumber like '".$this->prefixinvoice."%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $fayymm = substr($row[0],0,6); + } + if ($fayymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$fayymm)) + { + $this->error=$langs->trans('TerreNumRefModelError'); + return false; + } + + // Check credit note num + $fayymm=''; + + $sql = "SELECT MAX(facnumber)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $sql.= " WHERE facnumber like '".$this->prefixcreditnote."%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $fayymm = substr($row[0],0,6); + } + if ($fayymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$fayymm)) + { + $this->error=$langs->trans('TerreNumRefModelError'); + return false; + } + + return true; + } + + /** \brief Renvoi prochaine valeur attribuee + * \param objsoc Objet societe + * \param facture Objet facture + * \return string Valeur + */ + function getNextValue($objsoc,$facture) + { + global $db,$conf; + + if ($facture->type == 2) $prefix=$this->prefixcreditnote; + else $prefix=$this->prefixinvoice; + + // D'abord on recupere la valeur max (reponse immediate car champ ind�x�) + $posindice=8; + + $sql = "SELECT MAX(SUBSTRING(facnumber,".$posindice.")) as max"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $sql.= " WHERE facnumber like '".$prefix."%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + dol_syslog("mod_facture_terre::getNextValue sql=".$sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) $max = intval($obj->max); + else $max=0; + } + else + { + dol_syslog("mod_facture_terre::getNextValue sql=".$sql, LOG_ERR); + return -1; + } + + $date=$facture->date; // This is invoice date (not creation date) + $yymm = strftime("%y%m",$date); + $num = sprintf("%04s",$max+1); + + dol_syslog("mod_facture_terre::getNextValue return ".$prefix.$yymm."-".$num); + return $prefix.$yymm."-".$num; + } + + /** \brief Return next free value + * \param objsoc Object third party + * \param objforref Object for number to search + * \return string Next free value + */ + function getNumRef($objsoc,$objforref) + { + return $this->getNextValue($objsoc,$objforref); + } + +} + +?> diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 6040141a391..62f363a3098 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -214,8 +214,6 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) migrate_links_transfert($db,$langs,$conf); - migrate_delete_old_files($db,$langs,$conf); - // Script pour V2.2 -> V2.4 migrate_commande_expedition($db,$langs,$conf); @@ -290,6 +288,11 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) // La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation. $db->commit(); $db->close(); + + // Actions for all version (not in database) + migrate_delete_old_files($db,$langs,$conf); + + migrate_delete_old_dir($db,$langs,$conf); } print ''; @@ -1744,6 +1747,39 @@ function migrate_delete_old_files($db,$langs,$conf) return $result; } +/* + * Remove deprecated directories + */ +function migrate_delete_old_dir($db,$langs,$conf) +{ + $result=true; + + dolibarr_install_syslog("upgrade2::migrate_delete_old_dir"); + + // List of files to delete + $filetodeletearray=array( + DOL_DOCUMENT_ROOT.'/includes/modules/facture/terre', + DOL_DOCUMENT_ROOT.'/includes/modules/facture/mercure' + ); + + foreach ($filetodeletearray as $filetodelete) + { + //print ''.$filetodelete."
\n"; + if (file_exists($filetodelete)) + { + $result=dol_delete_dir_recursive($filetodelete); + } + if (! $result) + { + $langs->load("errors"); + print '
'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteDir",$filetodelete); + print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'
'; + } + } + return $result; +} + + /* * Disable/Reenable features modules. * We must do this when internal menu of module or permissions has changed