From ac275fb85de127b2851d00e98e2a39b6a37dd262 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 3 May 2007 15:54:21 +0000 Subject: [PATCH] =?UTF-8?q?Add:=20mod=E8le=20de=20num=E9rotation=20command?= =?UTF-8?q?e=20client=20param=E9trable=20"saphir"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/admin/commande.php | 11 +- .../modules/commande/mod_commande_diamant.php | 4 +- .../modules/commande/mod_commande_saphir.php | 449 ++++++++++++++++++ .../modules/facture/pluton/pluton.modules.php | 7 + 4 files changed, 468 insertions(+), 3 deletions(-) create mode 100644 htdocs/includes/modules/commande/mod_commande_saphir.php diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 015eb73fe43..e998b99cd65 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -134,6 +134,13 @@ if ($_POST["action"] == 'deliverycostline') dolibarr_set_const($db, "COMMANDE_ADD_DELIVERY_COST_LINE",$_POST["addline"]); } +// défini les constantes du modèle saphir +if ($_POST["action"] == 'updateMatrice') dolibarr_set_const($db, "COMMANDE_NUM_MATRICE",$_POST["matrice"]); +if ($_POST["action"] == 'updatePrefixCommande') dolibarr_set_const($db, "COMMANDE_NUM_PREFIX",$_POST["prefixcommande"]); +if ($_POST["action"] == 'setOffset') dolibarr_set_const($db, "COMMANDE_NUM_DELTA",$_POST["offset"]); +if ($_POST["action"] == 'setFiscalMonth') dolibarr_set_const($db, "SOCIETE_FISCAL_MONTH_START",$_POST["fiscalmonth"]); +if ($_POST["action"] == 'setNumRestart') dolibarr_set_const($db, "COMMANDE_NUM_RESTART_BEGIN_YEAR",$_POST["numrestart"]); + /* * Affichage page */ @@ -194,10 +201,12 @@ if ($handle) print ''.$langs->trans("Activate").''; } print ''; + + $commande = new Commande($db); // Info $htmltooltip=''; - $nextval=$module->getNextValue(); + $nextval=$module->getNextValue($mysoc,$commande); if ($nextval != $langs->trans("NotAvailable")) { $htmltooltip=''.$langs->trans("NextValue").': '.$nextval; diff --git a/htdocs/includes/modules/commande/mod_commande_diamant.php b/htdocs/includes/modules/commande/mod_commande_diamant.php index 71d93c63f0a..ce00366bd77 100644 --- a/htdocs/includes/modules/commande/mod_commande_diamant.php +++ b/htdocs/includes/modules/commande/mod_commande_diamant.php @@ -29,7 +29,7 @@ \version $Revision$ */ -include_once("modules_commande.php"); +include_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php"); /** @@ -153,7 +153,7 @@ class mod_commande_diamant extends ModeleNumRefCommandes */ function commande_get_num($objsoc=0) { - return $this->getNextValue(); + return $this->getNextValue($objsoc); } } ?> diff --git a/htdocs/includes/modules/commande/mod_commande_saphir.php b/htdocs/includes/modules/commande/mod_commande_saphir.php new file mode 100644 index 00000000000..b1fe0aab8a0 --- /dev/null +++ b/htdocs/includes/modules/commande/mod_commande_saphir.php @@ -0,0 +1,449 @@ + + * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2005-2007 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/ + * + * $Id$ + * $Source$ + * + */ + +/** + \file htdocs/includes/modules/facture/pluton/mod_commande_saphir.php + \ingroup facture + \brief Fichier contenant la classe du modèle de numérotation de référence de commande Saphir + \version $Revision$ +*/ + +require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php"); + +/** + \class mod_commande_saphir + \brief Classe du modèle de numérotation de référence de commande Saphir +*/ +class mod_commande_saphir extends ModeleNumRefCommandes +{ + var $prefixcommande=''; + var $commandenummatrice=''; + var $error=''; + + /** \brief Constructeur + */ + function mod_commande_saphir() + { + $this->nom = "Saphir"; + } + + /** \brief Renvoi la description du modele de numérotation + * \return string Texte descripif + */ +function info() + { + global $conf,$langs; + + $langs->load("bills"); + + $form = new Form($db); + + $texte = $langs->trans('SaphirNumRefModelDesc1')."
\n"; + $texte.= ''; + + // Paramétrage de la matrice + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // Paramétrage du prefix des commandes + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // On détermine un offset sur le compteur + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // On défini le debut d'année fiscale + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // On défini si le compteur se remet à zero en debut d'année + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + $texte.= '
Matrice de disposition des objets (prefix,mois,année,compteur...)
'.$form->textwithhelp('',$langs->trans("MatriceOrderDesc"),1,1).'
Préfix des commandes
'.$form->textwithhelp('',$langs->trans("PrefixOrderDesc"),1,1).'
Appliquer un offset sur le compteur
'.$form->textwithhelp('',$langs->trans("OffsetDesc"),1,1).'
Début d\'année fiscale
'; + $texte.= $form->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonth',1); + $texte.= ''.$form->textwithwarning('',$langs->trans("FiscalMonthStartDesc"),1).'
Le compteur se remet à zéro en début d\'année
'; + $texte.= $form->selectyesno('numrestart',$conf->global->COMMANDE_NUM_RESTART_BEGIN_YEAR,1); + $texte.= ''.$form->textwithhelp('',$langs->trans("NumRestartDesc"),1,1).'

'; + + return $texte; + } + + /** \brief Renvoi un exemple de numérotation + * \return string Example + */ + function getExample() + { + global $conf; + + $this->prefixorder = $conf->global->COMMANDE_NUM_PREFIX; + $this->ordernummatrice = $conf->global->COMMANDE_NUM_MATRICE; + + if ($this->ordernummatrice != '') + { + $resultatMatrice = Array(); + $numMatrice = ''; + + $matricePrefix = "PREF|COM"; // PREF : prefix libre (ex: C pour commande), COM : prefix du client + $matriceYear = "[A]{2,4}"; // l'année est sur 2 ou 4 chiffres + $matriceMonth = "[M]{2}"; // le mois est sur 2 chiffres + $matriceCounter = "[C]{1,}"; //le compteur a un nombre de chiffres libre + $matriceTiret = "[-]{1}"; // on recherche si il y a des tirets de séparation + + $matrice = Array('prefix'=>$matricePrefix, + 'year'=>$matriceYear, + 'month'=>$matriceMonth, + 'counter'=>$matriceCounter + ); + + // on détermine l'emplacement des tirets + $resultTiret = preg_split('/'.$matriceTiret.'/',$this->ordernummatrice, -1, PREG_SPLIT_OFFSET_CAPTURE); + + $j = 0; + + // on détermine les objets de la matrice + for ($i = 0; $i < count($resultTiret); $i++) + { + foreach($resultTiret[$i] as $idResultTiret => $valueResultTiret) + { + // Ajout des tirets + if ($j != $resultTiret[$i][1]) + { + $numMatrice .= '-'; + $j = $resultTiret[$i][1]; + } + foreach($matrice as $idMatrice => $valueMatrice) + { + $resultCount = eregi(''.$valueMatrice.'',$valueResultTiret,$resultatMatrice); + if ($resultCount) + { + // On récupère le préfix utilisé + if ($idMatrice == 'prefix' && $resultatMatrice[0] == 'COM') + { + if ($objsoc->prefix_comm) + { + $prefix = $objsoc->prefix_comm; + } + else + { + $prefix = 'COM'; + } + $numMatrice .= $prefix; + } + else if ($idMatrice == 'prefix' && $resultatMatrice[0] == 'PREF') + { + $prefix = $this->prefixorder; + $numMatrice .= $prefix; + } + else if ($idMatrice == 'year') + { + // On récupère le nombre de chiffres pour l'année + $numbityear = $resultCount; + // On défini le mois du début d'année fiscale + $fiscal_current_month = date("n"); + $create_month = $fiscal_current_month; + + // On change d'année fiscal si besoin + if($conf->global->SOCIETE_FISCAL_MONTH_START && $fiscal_current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START) + { + $yy = substr(strftime("%Y",mktime(0,0,0,date("m"),date("d"),date("Y")+1)),$numbityear); + } + else + { + $yy = substr(strftime("%Y",time()),$numbityear); + } + $numMatrice .= $yy; + } + else if ($idMatrice == 'month') + { + // On récupère le mois si besoin + $mm = strftime("%m",time()); + $numMatrice .= $mm; + } + else if ($idMatrice == 'counter') + { + // On récupère le nombre de chiffres pour le compteur + $numbitcounter = $resultCount; + } + } + } + } + } + + // On récupère le nombre de chiffres du compteur + $arg = '%0'.$numbitcounter.'s'; + $num = sprintf($arg,$conf->global->COMMANDE_NUM_DELTA?$conf->global->COMMANDE_NUM_DELTA:1); + + // Construction de l'exemple de numérotation + $numExample = $numMatrice.$num; + + return $numExample; + } + } + + /** \brief Renvoi prochaine valeur attribuée + * \param objsoc Objet société + * \param facture Objet facture + * \return string Valeur + */ + function getNextValue($objsoc,$commande) + { + global $db,$conf; + + $this->prefixorder = $conf->global->COMMANDE_NUM_PREFIX; + $this->ordernummatrice = $conf->global->COMMANDE_NUM_MATRICE; + + if ($this->ordernummatrice != '') + { + $resultatMatrice = Array(); + $numMatrice = Array(); + + $matricePrefix = "PREF|COM"; // PREF : prefix libre (ex: C pour commande), COM : prefix du client + $matriceYear = "[A]{2,4}"; // l'année est sur 2 ou 4 chiffres + $matriceMonth = "[M]{2}"; // le mois est sur 2 chiffres + $matriceCounter = "[C]{1,}"; //le compteur a un nombre de chiffres libre + $matriceTiret = "[-]{1}"; // on recherche si il y a des tirets de séparation + + $matrice = Array('prefix'=>$matricePrefix, + 'year'=>$matriceYear, + 'month'=>$matriceMonth, + 'counter'=>$matriceCounter + ); + + // on détermine l'emplacement des tirets + $resultTiret = preg_split('/'.$matriceTiret.'/',$this->ordernummatrice, -1, PREG_SPLIT_OFFSET_CAPTURE); + + $j = 0; + $k = 0; + + // on détermine les objets de la matrice + for ($i = 0; $i < count($resultTiret); $i++) + { + foreach($resultTiret[$i] as $idResultTiret => $valueResultTiret) + { + // Ajout des tirets + if ($j != $resultTiret[$i][1]) + { + $numMatrice[$k] = '-'; + $searchLast .= '-'; + $searchLastWithNoYear .= '-'; + $searchLastWithPreviousYear .= '-'; + $j = $resultTiret[$i][1]; + $k++; + } + foreach($matrice as $idMatrice => $valueMatrice) + { + $resultCount = eregi(''.$valueMatrice.'',$valueResultTiret,$resultatMatrice); + if ($resultCount) + { + // On récupère le préfix utilisé + if ($idMatrice == 'prefix' && $resultatMatrice[0] == 'COM') + { + if ($objsoc->prefix_comm) + { + $prefix = $objsoc->prefix_comm; + } + else + { + $prefix = 'COM'; + } + $numMatrice[$k] = '$prefix'; + $searchLast .= $prefix; + $searchLastWithNoYear .= $prefix; + $searchLastWithPreviousYear .= $prefix; + $k++; + } + else if ($idMatrice == 'prefix' && $resultatMatrice[0] == 'PREF') + { + $prefix = $this->prefixorder; + $numMatrice[$k] = '$prefix'; + $searchLast .= $prefix; + $searchLastWithNoYear .= $prefix; + $searchLastWithPreviousYear .= $prefix; + $k++; + } + else if ($idMatrice == 'year') + { + // On récupère le nombre de chiffres pour l'année + $numbityear = $resultCount; + // On défini le mois du début d'année fiscale + $current_month = date("n"); + + if (is_object($commande) && $commande->date) + { + $create_month = strftime("%m",$commande->date); + } + else + { + $create_month = $current_month; + } + + // On change d'année fiscal si besoin + if($conf->global->SOCIETE_FISCAL_MONTH_START && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START) + { + $yy = substr(strftime("%Y",mktime(0,0,0,date("m"),date("d"),date("Y")+1)),$numbityear); + } + else + { + $yy = substr(strftime("%Y",time()),$numbityear); + } + $numMatrice[$k] = '$yy'; + $searchLast .= $yy; + for ($l = 1; $l <= $numbityear; $l++) + { + $searchLastWithNoYear .= '[0-9]'; + } + $previousYear = substr(strftime("%Y",mktime(0,0,0,date("m"),date("d"),date("Y")-1)),$numbityear); + $searchLastWithPreviousYear .= $previousYear; + $k++; + } + else if ($idMatrice == 'month') + { + // On récupère le mois si besoin + $mm = strftime("%m",time()); + $numMatrice[$k] = '$mm'; + $searchLast .= $mm; + $searchLastWithNoYear .= $mm; + $searchLastWithPreviousYear .= $mm; + $k++; + } + else if ($idMatrice == 'counter') + { + // On récupère le nombre de chiffres pour le compteur + $numbitcounter = $resultCount; + $numMatrice[$k] = '$num'; + $k++; + } + } + } + } + } + + // On récupère la valeur max (réponse immédiate car champ indéxé) + $posindice = $numbitcounter; + $comyy=''; + $sql = "SELECT MAX(ref)"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + if ($conf->global->COMMANDE_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref like '${searchLast}%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $comyy = substr($row[0],0,-$posindice); + } + + //on vérifie si il y a une année précédente + //sinon le delta sera appliqué de nouveau sur la nouvelle année + $lastyy=''; + $sql = "SELECT MAX(ref)"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + $sql.= " WHERE ref like '${searchLastWithPreviousYear}%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $lastyy = substr($row[0],0,-$posindice); + } + + // Si au moins un champ respectant le modèle a été trouvée + if (eregi('^'.$searchLastWithNoYear.'',$comyy)) + { + // Recherche rapide car restreint par un like sur champ indexé + $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + $sql.= " WHERE ref like '${comyy}%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $max = $row[0]; + } + } + else if (!eregi('^'.$searchLastWithPreviousYear.'',$lastyy)) + { + // on applique le delta une seule fois + $max=$conf->global->COMMANDE_NUM_DELTA?$conf->global->COMMANDE_NUM_DELTA-1:0; + } + else + { + $max=0; + } + + // On applique le nombre de chiffres du compteur + $arg = '%0'.$numbitcounter.'s'; + $num = sprintf($arg,$max+1); + $numFinal = ''; + + foreach($numMatrice as $objetMatrice) + { + if ($objetMatrice == '-') $numFinal .= $objetMatrice; + if ($objetMatrice == '$prefix') $numFinal .= $prefix; + if ($objetMatrice == '$yy') $numFinal .= $yy; + if ($objetMatrice == '$mm') $numFinal .= $mm; + if ($objetMatrice == '$num') $numFinal .= $num; + } + + dolibarr_syslog("mod_commande_saphir::getNextValue return ".$numFinal); + return $numFinal; + } + } + + + /** \brief Renvoie la référence de commande suivante non utilisée + * \param objsoc Objet société + * \param facture Objet facture + * \return string Texte descripif + */ + function commande_get_num($objsoc=0,$commande) + { + return $this->getNextValue($objsoc,$commande); + } +} + +?> \ No newline at end of file diff --git a/htdocs/includes/modules/facture/pluton/pluton.modules.php b/htdocs/includes/modules/facture/pluton/pluton.modules.php index b62bb76d5c3..977dd3bca94 100644 --- a/htdocs/includes/modules/facture/pluton/pluton.modules.php +++ b/htdocs/includes/modules/facture/pluton/pluton.modules.php @@ -63,6 +63,7 @@ function info() $texte.= ''; $texte.= ''; $texte.= ''; + $texte.= ''.$form->textwithhelp('',$langs->trans("MatriceInvoiceDesc"),1,1).''; $texte.= ''; // Paramétrage du prefix des factures @@ -71,6 +72,7 @@ function info() $texte.= ''; $texte.= ''; $texte.= ''; + $texte.= ''.$form->textwithhelp('',$langs->trans("PrefixInvoiceDesc"),1,1).''; $texte.= ''; // Paramétrage du prefix des avoirs @@ -79,6 +81,7 @@ function info() $texte.= ''; $texte.= ''; $texte.= ''; + $texte.= ''.$form->textwithhelp('',$langs->trans("PrefixCreditNoteDesc"),1,1).''; $texte.= ''; // On détermine un offset sur le compteur @@ -87,6 +90,7 @@ function info() $texte.= ''; $texte.= ''; $texte.= ''; + $texte.= ''.$form->textwithhelp('',$langs->trans("OffsetDesc"),1,1).''; $texte.= ''; // On défini si le debut d'année fiscale @@ -96,6 +100,7 @@ function info() $texte.= ''; $texte.= $form->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonth',1); $texte.= ''; + $texte.= ''.$form->textwithwarning('',$langs->trans("FiscalMonthStartDesc"),1).''; $texte.= ''; // On défini si le compteur se remet à zero en debut d'année @@ -105,6 +110,7 @@ function info() $texte.= ''; $texte.= $form->selectyesno('numrestart',$conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR,1); $texte.= ''; + $texte.= ''.$form->textwithhelp('',$langs->trans("NumRestartDesc"),1,1).''; $texte.= ''; // On défini si le compteur des avoirs s'incrémente avec les factures @@ -114,6 +120,7 @@ function info() $texte.= ''; $texte.= $form->selectyesno('numwithinvoice',$conf->global->AVOIR_NUM_WITH_INVOICE,1); $texte.= ''; + $texte.= ''.$form->textwithhelp('',$langs->trans("CreditNoteNumWithInvoiceDesc"),1,1).''; $texte.= ''; $texte.= '
';