From 977571e0322eeaf1338632d1c0dee3dcad8566f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Fri, 24 Aug 2012 18:32:19 +0200 Subject: [PATCH 1/2] Forgot to apply the patch to the rest of the files --- htdocs/fourn/commande/document.php | 20 +++++++++++++++++++- htdocs/fourn/commande/history.php | 20 +++++++++++++++++++- htdocs/fourn/commande/note.php | 20 +++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php index da69298763e..643dc943a48 100644 --- a/htdocs/fourn/commande/document.php +++ b/htdocs/fourn/commande/document.php @@ -160,7 +160,25 @@ if ($object->id > 0) if ($object->methode_commande) { - print ''.$langs->trans("Method").''.$object->methode_commande.''; + $sql = "SELECT rowid, code, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; + $sql.= " WHERE active=1 AND rowid = ".$db->escape($object->methode_commande_id); + + $resql = $db->query($sql); + + if ($resql && $db->num_rows($resql)) + { + $obj = $db->fetch_object($resql); + + // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut + $methode_commande = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->libelle!='-'?$obj->libelle:'')); + } + else + { + dol_print_error($db); + } + + print ''.$langs->trans("Method").''.$methode_commande.''; } } diff --git a/htdocs/fourn/commande/history.php b/htdocs/fourn/commande/history.php index 2ba34ecc885..b4eb7a08241 100644 --- a/htdocs/fourn/commande/history.php +++ b/htdocs/fourn/commande/history.php @@ -109,7 +109,25 @@ if ($id > 0 || ! empty($ref)) if ($commande->methode_commande) { - print ''.$langs->trans("Method").''.$commande->methode_commande.''; + $sql = "SELECT rowid, code, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; + $sql.= " WHERE active=1 AND rowid = ".$db->escape($commande->methode_commande_id); + + $resql = $db->query($sql); + + if ($resql && $db->num_rows($resql)) + { + $obj = $db->fetch_object($resql); + + // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut + $methode_commande = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->libelle!='-'?$obj->libelle:'')); + } + else + { + dol_print_error($db); + } + + print ''.$langs->trans("Method").''.$methode_commande.''; } } diff --git a/htdocs/fourn/commande/note.php b/htdocs/fourn/commande/note.php index d3e61d40999..4e7ba219d98 100644 --- a/htdocs/fourn/commande/note.php +++ b/htdocs/fourn/commande/note.php @@ -130,7 +130,25 @@ if ($id > 0 || ! empty($ref)) if ($object->methode_commande) { - print ''.$langs->trans("Method").''.$object->methode_commande.''; + $sql = "SELECT rowid, code, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; + $sql.= " WHERE active=1 AND rowid = ".$db->escape($object->methode_commande_id); + + $resql = $db->query($sql); + + if ($resql && $db->num_rows($resql)) + { + $obj = $db->fetch_object($resql); + + // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut + $methode_commande = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->libelle!='-'?$obj->libelle:'')); + } + else + { + dol_print_error($db); + } + + print ''.$langs->trans("Method").''.$methode_commande.''; } } From 082753d115bb391a9d06020f2e74223437fe6031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Fri, 24 Aug 2012 19:55:31 +0200 Subject: [PATCH 2/2] Refactored code --- .../class/fournisseur.commande.class.php | 38 +++++++++++++++++++ htdocs/fourn/commande/document.php | 21 +--------- htdocs/fourn/commande/fiche.php | 20 +--------- htdocs/fourn/commande/history.php | 20 +--------- htdocs/fourn/commande/note.php | 23 ++--------- 5 files changed, 45 insertions(+), 77 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 53211070923..e4cd29813db 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -5,6 +5,7 @@ * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2010-2012 Philippe Grand + * Copyright (C) 2012 Marcos García * * 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 @@ -1840,6 +1841,43 @@ class CommandeFournisseur extends CommonOrder return -1; } } + + /** + * Returns the translated input method + * + * @return string + */ + function getInputMethod() + { + global $db, $langs; + + if ($this->methode_commande_id > 0) + { + $sql = "SELECT rowid, code, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; + $sql.= " WHERE active=1 AND rowid = ".$db->escape($this->methode_commande_id); + + $query = $db->query($sql); + + if ($query && $db->num_rows($query)) + { + $result = $db->fetch_object($query); + + $string = $langs->trans($result->code); + + if ($string == $result->code) + { + $string = $obj->libelle != '-' ? $obj->libelle : ''; + } + + return $string; + } + + dol_print_error($db); + } + + return ''; + } } diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php index 643dc943a48..80530156201 100644 --- a/htdocs/fourn/commande/document.php +++ b/htdocs/fourn/commande/document.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2012 Marcos García * * 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 @@ -160,25 +161,7 @@ if ($object->id > 0) if ($object->methode_commande) { - $sql = "SELECT rowid, code, libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; - $sql.= " WHERE active=1 AND rowid = ".$db->escape($object->methode_commande_id); - - $resql = $db->query($sql); - - if ($resql && $db->num_rows($resql)) - { - $obj = $db->fetch_object($resql); - - // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $methode_commande = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->libelle!='-'?$obj->libelle:'')); - } - else - { - dol_print_error($db); - } - - print ''.$langs->trans("Method").''.$methode_commande.''; + print ''.$langs->trans("Method").''.$object->getInputMethod().''; } } diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 18de50e8c2c..7837a4c347a 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -1118,25 +1118,7 @@ if ($id > 0 || ! empty($ref)) if ($object->methode_commande) { - $sql = "SELECT rowid, code, libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; - $sql.= " WHERE active=1 AND rowid = ".$db->escape($object->methode_commande_id); - - $resql = $db->query($sql); - - if ($resql && $db->num_rows($resql)) - { - $obj = $db->fetch_object($resql); - - // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $methode_commande = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->libelle!='-'?$obj->libelle:'')); - } - else - { - dol_print_error($db); - } - - print ''.$langs->trans("Method").''.$methode_commande.''; + print ''.$langs->trans("Method").''.$object->getInputMethod().''; } } diff --git a/htdocs/fourn/commande/history.php b/htdocs/fourn/commande/history.php index b4eb7a08241..4dd2e12fd0e 100644 --- a/htdocs/fourn/commande/history.php +++ b/htdocs/fourn/commande/history.php @@ -109,25 +109,7 @@ if ($id > 0 || ! empty($ref)) if ($commande->methode_commande) { - $sql = "SELECT rowid, code, libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; - $sql.= " WHERE active=1 AND rowid = ".$db->escape($commande->methode_commande_id); - - $resql = $db->query($sql); - - if ($resql && $db->num_rows($resql)) - { - $obj = $db->fetch_object($resql); - - // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $methode_commande = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->libelle!='-'?$obj->libelle:'')); - } - else - { - dol_print_error($db); - } - - print ''.$langs->trans("Method").''.$methode_commande.''; + print ''.$langs->trans("Method").''.$commande->getInputMethod().''; } } diff --git a/htdocs/fourn/commande/note.php b/htdocs/fourn/commande/note.php index 4e7ba219d98..3fd9a18a8f5 100644 --- a/htdocs/fourn/commande/note.php +++ b/htdocs/fourn/commande/note.php @@ -1,7 +1,8 @@ * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2012 Marcos García * * 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 @@ -130,25 +131,7 @@ if ($id > 0 || ! empty($ref)) if ($object->methode_commande) { - $sql = "SELECT rowid, code, libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; - $sql.= " WHERE active=1 AND rowid = ".$db->escape($object->methode_commande_id); - - $resql = $db->query($sql); - - if ($resql && $db->num_rows($resql)) - { - $obj = $db->fetch_object($resql); - - // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $methode_commande = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->libelle!='-'?$obj->libelle:'')); - } - else - { - dol_print_error($db); - } - - print ''.$langs->trans("Method").''.$methode_commande.''; + print ''.$langs->trans("Method").''.$object->getInputMethod().''; } }