New: Model mercure is complete
This commit is contained in:
parent
579c94d335
commit
798701385d
@ -28,13 +28,14 @@
|
|||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
|
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class mod_facture_pluton
|
\class mod_facture_mercure
|
||||||
\brief Classe du mod<EFBFBD>le de num<EFBFBD>rotation de r<EFBFBD>f<EFBFBD>rence de facture Mercure
|
\brief Classe du modele de numerotation de reference de facture Mercure
|
||||||
*/
|
*/
|
||||||
class mod_facture_mercure extends ModeleNumRefFactures
|
class mod_facture_mercure extends ModeleNumRefFactures
|
||||||
{
|
{
|
||||||
var $version='experimental'; // 'development', 'experimental', 'dolibarr'
|
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
|
||||||
var $prefixinvoice;
|
var $prefixinvoice;
|
||||||
var $prefixcreditnote;
|
var $prefixcreditnote;
|
||||||
var $matrice;
|
var $matrice;
|
||||||
@ -52,37 +53,38 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
*/
|
*/
|
||||||
function info()
|
function info()
|
||||||
{
|
{
|
||||||
global $conf,$langs;
|
global $conf,$langs;
|
||||||
|
|
||||||
$langs->load("bills");
|
$langs->load("bills");
|
||||||
|
|
||||||
$form = new Form($db);
|
$form = new Form($db);
|
||||||
|
|
||||||
$texte = $langs->trans('MercureNumRefModelDesc1')."<br>\n";
|
$texte = $langs->trans('MercureNumRefModelDesc1')."<br>\n";
|
||||||
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||||
$texte.= '<input type="hidden" name="action" value="updateMask">';
|
$texte.= '<input type="hidden" name="action" value="updateMask">';
|
||||||
$texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
|
$texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
|
||||||
$texte.= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
|
$texte.= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
|
||||||
$texte.= '<table class="nobordernopadding" width="100%">';
|
$texte.= '<table class="nobordernopadding" width="100%">';
|
||||||
|
|
||||||
// Parametrage du prefix des factures
|
// Parametrage du prefix des factures
|
||||||
$texte.= '<tr><td>'.$langs->trans("InvoiceStandard").'</td>';
|
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").')</td>';
|
||||||
// $texte.= '<td align="right"><input type="text" class="flat" size="24" name="prefixfacture" value="'.$conf->global->FACTURE_NUM_PREFIX.'"></td>';
|
// $texte.= '<td align="right"><input type="text" class="flat" size="24" name="prefixfacture" value="'.$conf->global->FACTURE_NUM_PREFIX.'"></td>';
|
||||||
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">',$langs->trans("MercureMaskCodes"),1,1).'</td>';
|
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">',$langs->trans("MercureMaskCodes"),1,1).'</td>';
|
||||||
$texte.= '</tr>';
|
|
||||||
|
|
||||||
// Parametrage du prefix des avoirs
|
$texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
|
||||||
$texte.= '<tr><td>'.$langs->trans("InvoiceAvoir").'</td>';
|
|
||||||
//$texte.= '<td align="right"><input type="text" class="flat" size="24" name="prefixavoir" value="'.$conf->global->AVOIR_NUM_PREFIX.'"></td>';
|
|
||||||
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">',$langs->trans("MercureMaskCodes"),1,1).'</td>';
|
|
||||||
$texte.= '</tr>';
|
|
||||||
|
|
||||||
$texte.= '<tr><td> </td><td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td></tr>';
|
$texte.= '</tr>';
|
||||||
|
|
||||||
$texte.= '</table>';
|
// Parametrage du prefix des avoirs
|
||||||
$texte.= '</form>';
|
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").')</td>';
|
||||||
|
//$texte.= '<td align="right"><input type="text" class="flat" size="24" name="prefixavoir" value="'.$conf->global->AVOIR_NUM_PREFIX.'"></td>';
|
||||||
|
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">',$langs->trans("MercureMaskCodes"),1,1).'</td>';
|
||||||
|
$texte.= '</tr>';
|
||||||
|
|
||||||
return $texte;
|
$texte.= '</table>';
|
||||||
|
$texte.= '</form>';
|
||||||
|
|
||||||
|
return $texte;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoi un exemple de numerotation
|
/** \brief Renvoi un exemple de numerotation
|
||||||
@ -101,10 +103,10 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
return $numExample;
|
return $numExample;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoi prochaine valeur attribuee
|
/** \brief Return next value
|
||||||
* \param objsoc Objet societe
|
* \param objsoc Object third party
|
||||||
* \param facture Objet facture
|
* \param facture Object invoice
|
||||||
* \return string Valeur
|
* \return string Value if OK, 0 if KO
|
||||||
*/
|
*/
|
||||||
function getNextValue($objsoc,$facture)
|
function getNextValue($objsoc,$facture)
|
||||||
{
|
{
|
||||||
@ -114,58 +116,102 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
if ($facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
|
if ($facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
|
||||||
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
|
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
|
||||||
|
|
||||||
if (! $mask) return 'Error format not defined';
|
if (! $mask)
|
||||||
|
{
|
||||||
|
$this->error='ErrorFormatNotDefined';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Replace all code that ar not {0...0}
|
// Extract value for mask counter, mask raz and mask offset
|
||||||
$newmask=$mask;
|
if (! eregi('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$mask,$reg)) return 'ErrorBadMask';
|
||||||
$newmask=str_ireplace('{yyyy}','yyyy',$newmask);
|
$masktri=$reg[1].$reg[2].$reg[3];
|
||||||
$newmask=str_ireplace('{yy}','yy',$newmask);
|
$maskcounter=$reg[1];
|
||||||
$newmask=str_ireplace('{mm}','mm',$newmask);
|
$maskraz=-1;
|
||||||
$newmask=str_ireplace('{dd}','dd',$newmask);
|
$maskoffset=0;
|
||||||
//print "newmask=".$newmask;
|
|
||||||
|
|
||||||
$posnumstart=strpos($newmask,'{0'); // Pos of {
|
$maskwithonlyymcode=$mask;
|
||||||
$posnumend =strpos($newmask,'0}')+1; // Pos of }
|
$maskwithonlyymcode=eregi_replace('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$maskcounter,$maskwithonlyymcode);
|
||||||
|
$maskwithonlyymcode=eregi_replace('\{dd\}','dd',$maskwithonlyymcode);
|
||||||
|
$maskwithnocode=$maskwithonlyymcode;
|
||||||
|
$maskwithnocode=eregi_replace('\{yyyy\}','yyyy',$maskwithnocode);
|
||||||
|
$maskwithnocode=eregi_replace('\{yy\}','yy',$maskwithnocode);
|
||||||
|
$maskwithnocode=eregi_replace('\{y\}','y',$maskwithnocode);
|
||||||
|
$maskwithnocode=eregi_replace('\{mm\}','mm',$maskwithnocode);
|
||||||
|
//print "maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode."\n<br>";
|
||||||
|
|
||||||
if ($posnumstart <= 0 || $posnumend <= 1) return 'Error in format';
|
// If an offset is asked
|
||||||
|
if (! empty($reg[2]) && eregi('^\+',$reg[2])) $maskoffset=eregi_replace('^\+','',$reg[2]);
|
||||||
|
if (! empty($reg[3]) && eregi('^\+',$reg[3])) $maskoffset=eregi_replace('^\+','',$reg[3]);
|
||||||
|
|
||||||
$sqlstring='SUBSTRING(facnumber, '.($posnumstart+1).', '.($posnumend-$posnumstart-1).')';
|
// If a restore to zero after a month is asked we check if there is already a value for this year.
|
||||||
|
if (! empty($reg[2]) && eregi('^@',$reg[2])) $maskraz=eregi_replace('^@','',$reg[2]);
|
||||||
|
if (! empty($reg[3]) && eregi('^@',$reg[3])) $maskraz=eregi_replace('^@','',$reg[3]);
|
||||||
|
if ($maskraz >= 0)
|
||||||
|
{
|
||||||
|
if ($maskraz > 1 && ! eregi('^(.*)\{(y+)\}\{(m+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
|
||||||
|
if ($maskraz <= 1 && ! eregi('^(.*)\{(y+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazIfNoYearInMask';
|
||||||
|
//print "x".$maskwithonlyymcode." ".$maskraz;
|
||||||
|
|
||||||
|
// Define $yearcomp and $monthcomp (that will be use de filter request to search max number)
|
||||||
|
$monthcomp=$maskraz;
|
||||||
|
$yearoffset=0;
|
||||||
|
$yearcomp=0;
|
||||||
|
if (date("m") < $maskraz) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year
|
||||||
|
if (strlen($reg[2]) == 4) $yearcomp=sprintf("%04d",date("Y")+$yearoffset);
|
||||||
|
if (strlen($reg[2]) == 2) $yearcomp=sprintf("%02d",date("y")+$yearoffset);
|
||||||
|
if (strlen($reg[2]) == 1) $yearcomp=substr(date("y"),2,1)+$yearoffset;
|
||||||
|
|
||||||
|
$sqlwhere='';
|
||||||
|
$sqlwhere.='SUBSTRING(facnumber, '.(strlen($reg[1])+1).', '.strlen($reg[2]).') >= '.$yearcomp;
|
||||||
|
if ($monthcomp > 1) // Test useless if monthcomp = 1 (or 0 is same as 1)
|
||||||
|
{
|
||||||
|
$sqlwhere.=' AND ';
|
||||||
|
$sqlwhere.='SUBSTRING(facnumber, '.(strlen($reg[1])+strlen($reg[2])+1).', '.strlen($reg[3]).') >= '.$monthcomp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."<br>\n";
|
||||||
|
|
||||||
|
$posnumstart=strpos($maskwithnocode,$maskcounter); // Pos of counter in final string (from 0 to ...)
|
||||||
|
if ($posnumstart < 0) return 'ErrorBadMask';
|
||||||
|
$sqlstring='SUBSTRING(facnumber, '.($posnumstart+1).', '.strlen($maskcounter).')';
|
||||||
//print "x".$sqlstring;
|
//print "x".$sqlstring;
|
||||||
|
|
||||||
|
// Get counter in database
|
||||||
$counter=0;
|
$counter=0;
|
||||||
|
|
||||||
$sql = "SELECT MAX(".$sqlstring.") as val";
|
$sql = "SELECT MAX(".$sqlstring.") as val";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
||||||
$sql.= " WHERE facnumber not like '(%'";
|
$sql.= " WHERE facnumber not like '(%'";
|
||||||
if ($facture->type == 2) $sql.= " AND type = 2";
|
if ($facture->type == 2) $sql.= " AND type = 2";
|
||||||
else $sql.=" AND type != 2";
|
else $sql.=" AND type != 2";
|
||||||
|
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
||||||
|
|
||||||
//print $sql;
|
//print $sql;
|
||||||
|
dolibarr_syslog("mod_facture_mercure::getNextValue sql=".$sql, LOG_DEBUG);
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
$counter = $obj->val;
|
$counter = $obj->val;
|
||||||
}
|
}
|
||||||
if (eregi('[^0-9]',$counter)) $counter=0;
|
else dolibarr_print_error($db);
|
||||||
|
if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
|
||||||
$counter++;
|
$counter++;
|
||||||
|
|
||||||
$sizeofnum=$posnumend-$posnumstart;
|
|
||||||
//print $counter."-".$sizeofnum."-".$posnumstart."-".$posnumend;
|
|
||||||
|
|
||||||
// Build numFinal
|
// Build numFinal
|
||||||
$numFinal = $mask;
|
$numFinal = $mask;
|
||||||
|
|
||||||
// We replace special codes
|
// We replace special codes
|
||||||
$numFinal = str_ireplace('{yyyy}',date("Y"),$numFinal);
|
$numFinal = str_ireplace('{yyyy}',date("Y"),$numFinal);
|
||||||
$numFinal = str_ireplace('{yy}',date("y"),$numFinal);
|
$numFinal = str_ireplace('{yy}',date("y"),$numFinal);
|
||||||
|
$numFinal = str_ireplace('{y}' ,substr(date("y"),2,1),$numFinal);
|
||||||
$numFinal = str_ireplace('{mm}',date("m"),$numFinal);
|
$numFinal = str_ireplace('{mm}',date("m"),$numFinal);
|
||||||
$numFinal = str_ireplace('{dd}',date("d"),$numFinal);
|
$numFinal = str_ireplace('{dd}',date("d"),$numFinal);
|
||||||
|
|
||||||
// Now we replace the counter
|
// Now we replace the counter
|
||||||
$nummask='{'.str_pad('',$sizeofnum-1,"0").'}';
|
$maskbefore='{'.$masktri.'}';
|
||||||
$numcount=str_pad($counter,$sizeofnum-1,"0",STR_PAD_LEFT);
|
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
||||||
//print 'x'.$nummask.'-'.$sizeofnum.'y';
|
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
||||||
$numFinal = str_ireplace($nummask,$numcount,$numFinal);
|
$numFinal = str_ireplace($maskbefore,$maskafter,$numFinal);
|
||||||
|
|
||||||
dolibarr_syslog("mod_facture_mercure::getNextValue return ".$numFinal);
|
dolibarr_syslog("mod_facture_mercure::getNextValue return ".$numFinal);
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
|
|||||||
@ -1,154 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
||||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
||||||
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
|
|
||||||
*
|
|
||||||
* 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/orion/orion.modules.php
|
|
||||||
\ingroup facture
|
|
||||||
\brief Fichier contenant la classe du modèle de numérotation de référence de facture Orion
|
|
||||||
\version $Revision$
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
|
|
||||||
|
|
||||||
/**
|
|
||||||
\class mod_facture_orion
|
|
||||||
\brief Classe du modèle de numérotation de référence de facture Orion
|
|
||||||
*/
|
|
||||||
class mod_facture_orion extends ModeleNumRefFactures
|
|
||||||
{
|
|
||||||
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
|
|
||||||
|
|
||||||
/** \brief Renvoi la description du modele de numérotation
|
|
||||||
* \return string Texte descripif
|
|
||||||
*/
|
|
||||||
function info()
|
|
||||||
{
|
|
||||||
global $conf,$langs;
|
|
||||||
|
|
||||||
$langs->load("bills");
|
|
||||||
|
|
||||||
$texte = $langs->trans('OrionNumRefModelDesc1')."<br>\n";
|
|
||||||
$texte.= $langs->trans('OrionNumRefModelDesc2')."<br>\n";
|
|
||||||
$texte.= $langs->trans('OrionNumRefModelDesc3')."<br>\n";
|
|
||||||
$texte.= $langs->trans('OrionNumRefModelDesc4')."<br>\n";
|
|
||||||
|
|
||||||
if ($conf->global->SOCIETE_FISCAL_MONTH_START)
|
|
||||||
{
|
|
||||||
$texte.= ' ('.$langs->trans('DefinedAndHasThisValue').' : '.monthArrayOrSelected($conf->global->SOCIETE_FISCAL_MONTH_START).')';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$texte.= ' ('.$langs->trans('IsNotDefined').')';
|
|
||||||
}
|
|
||||||
return $texte;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \brief Renvoi un exemple de numérotation
|
|
||||||
* \return string Example
|
|
||||||
*/
|
|
||||||
function getExample()
|
|
||||||
{
|
|
||||||
return "FA0600001";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \brief Renvoi prochaine valeur attribuée
|
|
||||||
* \param objsoc Objet société
|
|
||||||
* \param facture Objet facture
|
|
||||||
* \return string Valeur
|
|
||||||
*/
|
|
||||||
function getNextValue($objsoc,$facture)
|
|
||||||
{
|
|
||||||
global $db,$conf;
|
|
||||||
|
|
||||||
// On défini l'année fiscale
|
|
||||||
$prefix='FA';
|
|
||||||
$current_month = date("n");
|
|
||||||
|
|
||||||
if (is_object($facture) && $facture->date)
|
|
||||||
{
|
|
||||||
$create_month = strftime("%m",$facture->date);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$create_month = $current_month;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START)
|
|
||||||
{
|
|
||||||
$yy = strftime("%y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")+1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$yy = strftime("%y",time());
|
|
||||||
}
|
|
||||||
|
|
||||||
// On récupère la valeur max (réponse immédiate car champ indéxé)
|
|
||||||
$fayy='';
|
|
||||||
$sql = "SELECT MAX(facnumber)";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$row = $db->fetch_row($resql);
|
|
||||||
if ($row) $fayy = substr($row[0],0,4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si au moins un champ respectant le modèle a été trouvée
|
|
||||||
if (eregi('FA[0-9][0-9]',$fayy))
|
|
||||||
{
|
|
||||||
// Recherche rapide car restreint par un like sur champ indexé
|
|
||||||
$posindice=5;
|
|
||||||
$sql = "SELECT MAX(0+SUBSTRING(facnumber,$posindice))";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$row = $db->fetch_row($resql);
|
|
||||||
$max = $row[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$max=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$num = sprintf("%05s",$max+1);
|
|
||||||
|
|
||||||
return "FA$yy$num";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** \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 getNumRef($objsoc=0,$facture)
|
|
||||||
{
|
|
||||||
return $this->getNextValue($objsoc,$facture);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
@ -1,160 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
||||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
||||||
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
|
|
||||||
*
|
|
||||||
* 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/titan/titan.modules.php
|
|
||||||
\ingroup facture
|
|
||||||
\brief Fichier contenant la classe du modèle de numérotation de référence de facture Titan
|
|
||||||
\version $Revision$
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
|
|
||||||
|
|
||||||
/**
|
|
||||||
\class mod_facture_titan
|
|
||||||
\brief Classe du modèle de numérotation de référence de facture Titan
|
|
||||||
*/
|
|
||||||
class mod_facture_titan extends ModeleNumRefFactures
|
|
||||||
{
|
|
||||||
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
|
|
||||||
|
|
||||||
|
|
||||||
/** \brief Renvoi la description du modele de numérotation
|
|
||||||
* \return string Texte descripif
|
|
||||||
*/
|
|
||||||
function info()
|
|
||||||
{
|
|
||||||
global $conf,$langs;
|
|
||||||
|
|
||||||
$langs->load("bills");
|
|
||||||
|
|
||||||
$texte = $langs->trans('TitanNumRefModelDesc1')."<br>\n";
|
|
||||||
$texte.= $langs->trans('TitanNumRefModelDesc2')."<br>\n";
|
|
||||||
$texte.= $langs->trans('TitanNumRefModelDesc3')."<br>\n";
|
|
||||||
$texte.= $langs->trans('TitanNumRefModelDesc4')."<br>\n";
|
|
||||||
|
|
||||||
if ($conf->global->SOCIETE_FISCAL_MONTH_START)
|
|
||||||
{
|
|
||||||
$texte.= ' ('.$langs->trans('DefinedAndHasThisValue').' : '.monthArrayOrSelected($conf->global->SOCIETE_FISCAL_MONTH_START).')';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$texte.= ' ('.$langs->trans('IsNotDefined').')';
|
|
||||||
}
|
|
||||||
return $texte;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \brief Renvoi un exemple de numérotation
|
|
||||||
* \return string Example
|
|
||||||
*/
|
|
||||||
function getExample()
|
|
||||||
{
|
|
||||||
return "FA0600001";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \brief Renvoi prochaine valeur attribuée
|
|
||||||
* \param objsoc Objet société
|
|
||||||
* \param facture Objet facture
|
|
||||||
* \return string Valeur
|
|
||||||
*/
|
|
||||||
function getNextValue($objsoc,$facture)
|
|
||||||
{
|
|
||||||
global $db,$conf;
|
|
||||||
|
|
||||||
// On défini l'année fiscale
|
|
||||||
$prefix='FA';
|
|
||||||
$current_month = date("n");
|
|
||||||
|
|
||||||
if (is_object($facture) && $facture->date)
|
|
||||||
{
|
|
||||||
$create_month = strftime("%m",$facture->date);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$create_month = $current_month;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START)
|
|
||||||
{
|
|
||||||
$yy = strftime("%y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")+1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$yy = strftime("%y",time());
|
|
||||||
}
|
|
||||||
|
|
||||||
// On récupère la valeur max (réponse immédiate car champ indéxé)
|
|
||||||
$fisc=$prefix.$yy;
|
|
||||||
$fayy='';
|
|
||||||
$sql = "SELECT MAX(facnumber)";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
|
||||||
$sql.= " WHERE facnumber like '${fisc}%'";
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$row = $db->fetch_row($resql);
|
|
||||||
if ($row) $fayy = substr($row[0],0,4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si au moins un champ respectant le modèle a été trouvée
|
|
||||||
if (eregi('FA[0-9][0-9]',$fayy))
|
|
||||||
{
|
|
||||||
// Recherche rapide car restreint par un like sur champ indexé
|
|
||||||
$date = strftime("%Y%m", time());
|
|
||||||
$posindice=5;
|
|
||||||
$sql = "SELECT MAX(0+SUBSTRING(facnumber,$posindice))";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
|
|
||||||
$sql.= " WHERE facnumber like '${fayy}%'";
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$row = $db->fetch_row($resql);
|
|
||||||
$max = $row[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$max=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$num = sprintf("%05s",$max+1);
|
|
||||||
|
|
||||||
return "FA$yy$num";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** \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 getNumRef($objsoc=0,$facture)
|
|
||||||
{
|
|
||||||
return $this->getNextValue($objsoc,$facture);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
Loading…
Reference in New Issue
Block a user