Skip to content
Snippets Groups Projects
Commit 8e3f0172 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: Fix tons of pb with num ref system of supplier invoices.

parent fe20f8ae
No related branches found
No related tags found
No related merge requests found
......@@ -2448,7 +2448,7 @@ class Facture extends CommonInvoice
}
/**
* Return next reference of invoice not already used (or last reference)
* Return next reference of customer invoice not already used (or last reference)
* according to numbering module defined into constant FACTURE_ADDON
*
* @param Society $soc object company
......
......@@ -166,7 +166,12 @@ function supplierorder_admin_prepare_head($object)
$head[$h][1] = $langs->trans("SupplierOrder");
$head[$h][2] = 'order';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/supplier_invoice.php";
$head[$h][1] = $langs->trans("SuppliersInvoice");
$head[$h][2] = 'invoice';
$h++;
complete_head_from_modules($conf,$langs,$object,$head,$h,'supplierorder_admin');
$head[$h][0] = DOL_URL_ROOT.'/admin/supplierorder_extrafields.php';
......@@ -174,11 +179,6 @@ function supplierorder_admin_prepare_head($object)
$head[$h][2] = 'supplierorder';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/supplier_invoice.php";
$head[$h][1] = $langs->trans("SuppliersInvoice");
$head[$h][2] = 'invoice';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoice_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoices");
$head[$h][2] = 'supplierinvoice';
......
......@@ -137,7 +137,7 @@ class mod_facture_terre extends ModeleNumRefFactures
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
dol_syslog("mod_facture_terre::getNextValue sql=".$sql);
dol_syslog(get_class($this)."::getNextValue sql=".$sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
......@@ -146,7 +146,7 @@ class mod_facture_terre extends ModeleNumRefFactures
}
else
{
dol_syslog("mod_facture_terre::getNextValue sql=".$sql, LOG_ERR);
dol_syslog(get_class($this)."::getNextValue sql=".$sql, LOG_ERR);
return -1;
}
......@@ -160,7 +160,7 @@ class mod_facture_terre extends ModeleNumRefFactures
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
$sql.= " AND entity = ".$conf->entity;
dol_syslog("mod_facture_terre::getNextValue sql=".$sql);
dol_syslog(get_class($this)."::getNextValue sql=".$sql);
$resql=$db->query($sql);
if ($resql)
{
......@@ -177,7 +177,7 @@ class mod_facture_terre extends ModeleNumRefFactures
$yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
dol_syslog("mod_facture_terre::getNextValue return ".$prefix.$yymm."-".$num);
dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
return $prefix.$yymm."-".$num;
}
else dol_print_error('','Bad parameter for getNextValue');
......
......@@ -35,7 +35,7 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = '';
var $nom = 'Cactus';
var $prefix='SI';
var $prefixinvoice='SI';
/**
......@@ -46,7 +46,7 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
function info()
{
global $langs;
return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
return $langs->trans("SimpleNumRefModelDesc",$this->prefixinvoice);
}
......@@ -57,7 +57,7 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
*/
function getExample()
{
return $this->prefix."1301-0001";
return $this->prefixinvoice."1301-0001";
}
......@@ -75,7 +75,7 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
$posindice=8;
$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
$sql.= " WHERE ref LIKE '".$this->prefixinvoice."____-%'";
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
if ($resql)
......@@ -83,7 +83,7 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
$row = $db->fetch_row($resql);
if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; }
}
if (! $siyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$siyymm))
if (! $siyymm || preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$siyymm))
{
return true;
}
......@@ -96,52 +96,87 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
}
/**
* Return next value
* Return next value
*
* @param Societe $objsoc Object third party
* @param Object $object Object
* @return string Value if OK, 0 if KO
* @param Societe $objsoc Object third party
* @param Object $object Object
* @param string $mode 'next' for next value or 'last' for last value
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc=0,$object='')
function getNextValue($objsoc,$object,$mode='next')
{
global $db,$conf;
// D'abord on recupere la valeur max
$posindice=8;
$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " WHERE ref like '".$this->prefix."____-%'";
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj) $max = intval($obj->max);
else $max=0;
}
//$date=time();
$date=$object->datec; // Not always defined
if (empty($date)) $date=$object->date; // Creation date is invoice date for suppliers invoices
$yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
return $this->prefix.$yymm."-".$num;
if ($object->type == 2) $prefix=$this->prefixcreditnote;
else $prefix=$this->prefixinvoice;
// D'abord on recupere la valeur max
$posindice=8;
$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; // This is standard SQL
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " WHERE ref LIKE '".$prefix."____-%'";
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
dol_syslog(get_class($this)."::getNextValue sql=".$sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj) $max = intval($obj->max);
else $max=0;
}
else
{
dol_syslog(get_class($this)."::getNextValue sql=".$sql, LOG_ERR);
return -1;
}
if ($mode == 'last')
{
$num = sprintf("%04s",$max);
$ref='';
$sql = "SELECT ref as ref";
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " WHERE ref LIKE '".$prefix."____-".$num."'";
$sql.= " AND entity = ".$conf->entity;
dol_syslog(get_class($this)."::getNextValue sql=".$sql);
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj) $ref = $obj->ref;
}
else dol_print_error($db);
return $ref;
}
else if ($mode == 'next')
{
$date=$object->date; // This is invoice date (not creation date)
$yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num);
return $prefix.$yymm."-".$num;
}
else dol_print_error('','Bad parameter for getNextValue');
}
/**
* Renvoie la reference de facture suivante non utilisee
*
* @param Societe $objsoc Object third party
* @param Object $object Object
* @return string Texte descripif
* Return next free value
*
* @param Societe $objsoc Object third party
* @param string $objforref Object for number to search
* @param string $mode 'next' for next value or 'last' for last value
* @return string Next free value
*/
function invoice_get_num($objsoc=0,$object='')
{
return $this->getNextValue($objsoc,$object);
}
function getNumRef($objsoc,$objforref,$mode='next')
{
return $this->getNextValue($objsoc,$objforref,$mode);
}
}
?>
......@@ -102,13 +102,14 @@ class mod_facture_fournisseur_tulip extends ModeleNumRefSuppliersInvoices
}
/**
* Return next value
* Return next value
*
* @param Societe $objsoc Object third party
* @param Object $object Object
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc=0,$object='')
* @param Societe $objsoc Object third party
* @param Object $object Object
* @param string $mode 'next' for next value or 'last' for last value
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$object,$mode='next')
{
global $db,$conf;
......@@ -128,18 +129,18 @@ class mod_facture_fournisseur_tulip extends ModeleNumRefSuppliersInvoices
return $numFinal;
}
/**
* Renvoie la reference de facture suivante non utilisee
*
* @param Societe $objsoc Object third party
* @param Object $object Object
* @return string Texte descripif
* Return next free value
*
* @param Societe $objsoc Object third party
* @param string $objforref Object for number to search
* @param string $mode 'next' for next value or 'last' for last value
* @return string Next free value
*/
function invoice_get_num($objsoc=0,$object='')
{
return $this->getNextValue($objsoc,$object);
}
function getNumRef($objsoc,$objforref,$mode='next')
{
return $this->getNextValue($objsoc,$objforref,$mode);
}
}
?>
\ No newline at end of file
......@@ -1336,55 +1336,52 @@ class FactureFournisseur extends CommonInvoice
}
/**
* Renvoie la reference de facture suivante non utilisee en fonction du modele
* de numerotation actif defini dans INVOICE_SUPPLIER_ADDON_NUMBER
*
* @param Societe $soc objet societe
* @return string reference libre pour la facture
*/
function getNextNumRef($soc)
* Return next reference of supplier invoice not already used (or last reference)
* according to numbering module defined into constant INVOICE_SUPPLIER_ADDON_NUMBER
*
* @param Society $soc object company
* @param string $mode 'next' for next value or 'last' for last value
* @return string free ref or last ref
*/
function getNextNumRef($soc,$mode='next')
{
global $db, $langs, $conf;
$langs->load("orders");
$dir = DOL_DOCUMENT_ROOT .'/core/modules/supplier_invoice/';
if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER))
{
$file = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER.'.php';
if (is_readable($dir.'/'.$file))
{
// Definition du nom de modele de numerotation de commande fournisseur
$modName=$conf->global->INVOICE_SUPPLIER_ADDON_NUMBER;
require_once $dir.'/'.$file;
// Clean parameters (if not defined or using deprecated value)
if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER='mod_facture_fournisseur_cactus';
// Recuperation de la nouvelle reference
$objMod = new $modName($this->db);
$mybool=false;
$numref = "";
$numref = $objMod->invoice_get_num($soc,$this);
$file = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER.".php";
$classname = $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER;
// Include file with class
foreach ($conf->file->dol_document_root as $dirroot)
{
$dir = $dirroot."/core/modules/supplier_invoice/";
// Load file with numbering class (if found)
$mybool|=@include_once $dir.$file;
}
if ( $numref != "")
{
return $numref;
}
else
{
dol_print_error($db, get_class($this)."::getNextNumRef ".$obj->error);
return -1;
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("Error_FailedToLoad_INVOICE_SUPPLIER_ADDON_NUMBER_File",$conf->global->INVOICE_SUPPLIER_ADDON_NUMBER);
return -2;
}
if (! $mybool)
{
dol_print_error('',"Failed to include file ".$file);
return '';
}
else
{
print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_NUMBER_NotDefined");
return -3;
$obj = new $classname();
$numref = "";
$numref = $obj->getNumRef($soc,$this,$mode);
if ( $numref != "")
{
return $numref;
}
else
{
//dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
return false;
}
}
......
......@@ -1161,7 +1161,7 @@ if ($action == 'create')
print '</td>';
// print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
print '</tr>';
// Private note
print '<tr><td>'.$langs->trans('NotePrivate').'</td>';
print '<td>';
......@@ -1328,7 +1328,17 @@ else
{
$numref = $object->ref;
}
$text=$langs->trans('ConfirmValidateBill',$numref);
/*if (! empty($conf->notification->enabled))
{
require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
$notify=new Notify($db);
$text.='<br>';
$text.=$notify->confirmMessage('NOTIFY_VAL_FAC_SUP',$object->socid);
}*/
$formquestion=array();
if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1))
{
$langs->load("stocks");
......@@ -1341,7 +1351,7 @@ else
array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
}
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $object->ref), 'confirm_valid', $formquestion, 1, 1, 240);
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1, 240);
if ($ret == 'html') print '<br>';
}
......
......@@ -950,6 +950,8 @@ ExtraFieldsThirdParties=Complementary attributes (thirdparty)
ExtraFieldsContacts=Complementary attributes (contact/address)
ExtraFieldsMember=Complementary attributes (member)
ExtraFieldsMemberType=Complementary attributes (Member type)
ExtraFieldsSupplierOrders=Complementary attributes (orders)
ExtraFieldsSupplierInvoices=Complementary attributes (invoices)
ExtraFieldHasWrongValue=Attribut %s has a wrong value.
AlphaNumOnlyCharsAndNoSpace=only alphanumericals characters without space
SendingMailSetup=Setup of sendings by email
......@@ -1400,6 +1402,7 @@ MultiCompanySetup=Multi-company module setup
SuppliersSetup=Supplier module setup
SuppliersCommandModel=Complete template of supplier order (logo...)
SuppliersInvoiceModel=Complete template of supplier invoice (logo...)
SuppliersInvoiceNumberingModel=Supplier invoices numbering models
##### GeoIPMaxmind #####
GeoIPMaxmindSetup=GeoIP Maxmind module setup
PathToGeoIPMaxmindCountryDataFile=Path to file containing Maxmind ip to country translation.<br>Example: /usr/local/share/GeoIP/GeoIP.dat
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment