From 8e3f0172fc1f392d3e2a7ac3053e26e8f998aaf9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2013 00:00:31 +0200 Subject: [PATCH] Fix: Fix tons of pb with num ref system of supplier invoices. --- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/core/lib/fourn.lib.php | 12 +- .../modules/facture/mod_facture_terre.php | 8 +- .../mod_facture_fournisseur_cactus.php | 115 ++++++++++++------ .../mod_facture_fournisseur_tulip.php | 33 ++--- .../fourn/class/fournisseur.facture.class.php | 81 ++++++------ htdocs/fourn/facture/fiche.php | 14 ++- htdocs/langs/en_US/admin.lang | 3 + 8 files changed, 157 insertions(+), 111 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f4dc4527c74..614ed7e2823 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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 diff --git a/htdocs/core/lib/fourn.lib.php b/htdocs/core/lib/fourn.lib.php index 0ae8a67c60b..5e3b2a7f91b 100644 --- a/htdocs/core/lib/fourn.lib.php +++ b/htdocs/core/lib/fourn.lib.php @@ -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'; diff --git a/htdocs/core/modules/facture/mod_facture_terre.php b/htdocs/core/modules/facture/mod_facture_terre.php index c7a4d77298a..1b7072ebbb5 100644 --- a/htdocs/core/modules/facture/mod_facture_terre.php +++ b/htdocs/core/modules/facture/mod_facture_terre.php @@ -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'); diff --git a/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_cactus.php b/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_cactus.php index 7e1febf3189..01f1a481f86 100644 --- a/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_cactus.php +++ b/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_cactus.php @@ -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; + if ($object->type == 2) $prefix=$this->prefixcreditnote; + else $prefix=$this->prefixinvoice; - $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; + // 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); + } } ?> diff --git a/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_tulip.php b/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_tulip.php index d0ee9e23738..855cf4c74ae 100644 --- a/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_tulip.php +++ b/htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_tulip.php @@ -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 diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index d3c7d12d98a..759258888cf 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -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/'; + // 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'; - if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) + $mybool=false; + + $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) { - $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; - - // Recuperation de la nouvelle reference - $objMod = new $modName($this->db); - - $numref = ""; - $numref = $objMod->invoice_get_num($soc,$this); - - 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; - } + $dir = $dirroot."/core/modules/supplier_invoice/"; + // Load file with numbering class (if found) + $mybool|=@include_once $dir.$file; } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_NUMBER_NotDefined"); - return -3; + + if (! $mybool) + { + dol_print_error('',"Failed to include file ".$file); + return ''; + } + + $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; } } diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index d85bd03e067..24577bbf3f1 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -1161,7 +1161,7 @@ if ($action == 'create') print ''; // print ''; print ''; - + // Private note print ''.$langs->trans('NotePrivate').''; print ''; @@ -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.='
'; + $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 '
'; } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index c941d3c1c50..238d9e39dee 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -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.
Example: /usr/local/share/GeoIP/GeoIP.dat