From 9872ecfb6d1e0702bf746deb4b42da824a2e5681 Mon Sep 17 00:00:00 2001
From: Philippe Grand <philippe.grand@atoo-net.com>
Date: Wed, 15 Jun 2011 17:35:26 +0000
Subject: [PATCH] add possibility to fill trainer Accreditation number

---
 htdocs/admin/company.php                       | 12 ++++++++++++
 htdocs/install/mysql/migration/3.0.0-3.1.0.sql |  1 +
 htdocs/lib/pdf.lib.php                         |  5 +++++
 htdocs/master.inc.php                          |  2 ++
 htdocs/societe/class/societe.class.php         | 11 +++++++++--
 5 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php
index 8966da61e6d..a315de333c2 100644
--- a/htdocs/admin/company.php
+++ b/htdocs/admin/company.php
@@ -2,6 +2,7 @@
 /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2010      Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2011      Philippe Grand       <philippe.grand@atoo-net.com>
  *
  * 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
@@ -136,6 +137,7 @@ if ( (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["c
     dolibarr_set_const($db, "MAIN_INFO_APE",$_POST["ape"],'chaine',0,'',$conf->entity);
     dolibarr_set_const($db, "MAIN_INFO_RCS",$_POST["rcs"],'chaine',0,'',$conf->entity);
     dolibarr_set_const($db, "MAIN_INFO_TVAINTRA",$_POST["tva"],'chaine',0,'',$conf->entity);
+    dolibarr_set_const($db, "MAIN_INFO_TRAINER",$_POST["trainer"],'chaine',0,'',$conf->entity);
 
     dolibarr_set_const($db, "SOCIETE_FISCAL_MONTH_START",$_POST["fiscalmonthstart"],'chaine',0,'',$conf->entity);
 
@@ -476,6 +478,12 @@ if ((isset($_GET["action"]) && $_GET["action"] == 'edit')
     print '</td></tr>';
 
     print '</table>';
+    
+    // Trainer accreditation
+    $var=!$var;
+    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("TrainerId").'</td><td>';
+    print '<input name="trainer" size="20" value="' . $conf->global->MAIN_INFO_TRAINER . '">';
+    print '</td></tr>';
 
 
     /*
@@ -786,6 +794,10 @@ else
         }
         print '</td></tr>';
     }
+    
+    // Trainer accreditation
+	$var=!$var;
+    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("TrainerId").'</td><td>' . $conf->global->MAIN_INFO_TRAINER . '</td></tr>';
 
     // TVA
     $var=!$var;
diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql
index 88704e228d1..3ac9aedf5c6 100755
--- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql
+++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql
@@ -27,6 +27,7 @@ ALTER TABLE llx_c_actioncomm ADD COLUMN position integer NOT NULL DEFAULT 0;
 ALTER TABLE llx_propal ADD COLUMN fk_demand_reason integer NULL DEFAULT 0;
 ALTER TABLE llx_commande_fournisseur ADD COLUMN fk_cond_reglement integer NULL DEFAULT 0;
 ALTER TABLE llx_commande_fournisseur ADD COLUMN fk_mode_reglement integer NULL DEFAULT 0;
+ALTER TABLE llx_societe ADD COLUMN idtrainer varchar(32) NULL DEFAULT '0' AFTER idprof4;
 
 ALTER TABLE llx_commande_fournisseur MODIFY model_pdf varchar(255);
 ALTER TABLE llx_commande MODIFY model_pdf varchar(255);
diff --git a/htdocs/lib/pdf.lib.php b/htdocs/lib/pdf.lib.php
index 4e4ea3471ee..1bbd578557c 100644
--- a/htdocs/lib/pdf.lib.php
+++ b/htdocs/lib/pdf.lib.php
@@ -4,6 +4,7 @@
  * Copyright (C) 2007      Patrick Raguin       <patrick.raguin@gmail.com>
  * Copyright (C) 2010-2011 Regis Houssin        <regis@dolibarr.fr>
  * Copyright (C) 2010      Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2011      Philippe Grand       <philippe.grand@atoo-net.com>
  *
  * 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
@@ -566,6 +567,10 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
         $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
         if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
         $line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
+    }
+	// Trainer accreditation
+	{
+        $line4.=($line4?" - ":"").$outputlangs->transnoentities("TrainerId").": ".$outputlangs->convToOutputCharset($fromcompany->idtrainer);
     }
     // IntraCommunautary VAT
     if ($fromcompany->tva_intra != '')
diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php
index a0924d4b28c..7e20464a925 100644
--- a/htdocs/master.inc.php
+++ b/htdocs/master.inc.php
@@ -8,6 +8,7 @@
  * Copyright (C) 2005 	   Simon Tosser         <simon@kornog-computing.com>
  * Copyright (C) 2006 	   Andre Cianfarani     <andre.cianfarani@acdeveloppement.net>
  * Copyright (C) 2010      Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2011      Philippe Grand       <philippe.grand@atoo-net.com>
  *
  * 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
@@ -261,6 +262,7 @@ if (! defined('NOREQUIREDB') && ! defined('NOREQUIRESOC'))
 	$mysoc->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
 	$mysoc->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
 	$mysoc->tva_intra=$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
+	$mysoc->idtrainer=empty($conf->global->MAIN_INFO_TRAINER)?'':$conf->global->MAIN_INFO_TRAINER;
 	$mysoc->capital=$conf->global->MAIN_INFO_CAPITAL;
 	$mysoc->forme_juridique_code=$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
 	$mysoc->email=$conf->global->MAIN_INFO_SOCIETE_MAIL;
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index f8946035f5b..5939ae818fc 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -7,6 +7,7 @@
  * Copyright (C) 2005-2009 Regis Houssin        <regis@dolibarr.fr>
  * Copyright (C) 2008      Patrick Raguin       <patrick.raguin@auguria.net>
  * Copyright (C) 2010      Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2011      Philippe Grand       <philippe.grand@atoo-net.com>
  *
  * 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
@@ -79,6 +80,7 @@ class Societe extends CommonObject
     var $idprof2;	// IdProf2
     var $idprof3;	// IdProf3
     var $idprof4;	// IdProf4
+    var $idtrainer; // Trainer accreditation
 
     var $prefix_comm;
 
@@ -401,6 +403,7 @@ class Societe extends CommonObject
         $this->siret=trim($this->siret);
         $this->ape=trim($this->ape);
         $this->idprof4=trim($this->idprof4);
+        $this->idtrainer=trim($this->idtrainer);
         $this->prefix_comm=trim($this->prefix_comm);
 
         $this->tva_assuj=trim($this->tva_assuj);
@@ -465,6 +468,7 @@ class Societe extends CommonObject
             $sql .= ",siret   = '". $this->db->escape($this->siret)   ."'";
             $sql .= ",ape     = '". $this->db->escape($this->ape)     ."'";
             $sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
+            $sql .= ",idtrainer = '". $this->db->escape($this->idtrainer) ."'";
 
             $sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->tva_assuj."'":"null");
             $sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
@@ -575,9 +579,10 @@ class Societe extends CommonObject
      *    @param      idprof2		Prof id 2 of third party (Warning, this can return several records)
      *    @param      idprof3		Prof id 3 of third party (Warning, this can return several records)
      *    @param      idprof4		Prof id 4 of third party (Warning, this can return several records)
+     *    @param      idtrainer		Prof idtrainer of third party (Warning, this can return several records)
      *    @return     int			>0 if OK, <0 if KO or if two records found for same ref or idprof.
      */
-    function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='')
+    function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idtrainer='')
     {
         global $langs;
         global $conf;
@@ -589,7 +594,7 @@ class Societe extends CommonObject
         $sql .= ', s.price_level';
         $sql .= ', s.tms as date_update';
         $sql .= ', s.tel, s.fax, s.email, s.url, s.cp as zip, s.ville as town, s.note, s.client, s.fournisseur';
-        $sql .= ', s.siren, s.siret, s.ape, s.idprof4';
+        $sql .= ', s.siren, s.siret, s.ape, s.idprof4, s.idtrainer';
         $sql .= ', s.capital, s.tva_intra';
         $sql .= ', s.fk_typent as typent_id';
         $sql .= ', s.fk_effectif as effectif_id';
@@ -619,6 +624,7 @@ class Societe extends CommonObject
         if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($siret)."' AND s.entity = ".$conf->entity;
         if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($ape)."' AND s.entity = ".$conf->entity;
         if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity = ".$conf->entity;
+        if ($idtrainer) $sql .= " WHERE s.idtrainer = '".$this->db->escape($idtrainer)."' AND s.entity = ".$conf->entity;
 
         $resql=$this->db->query($sql);
         dol_syslog("Societe::fetch ".$sql);
@@ -685,6 +691,7 @@ class Societe extends CommonObject
                 $this->ape			= $obj->ape; // TODO obsolete
                 $this->idprof3		= $obj->ape;
                 $this->idprof4		= $obj->idprof4;
+                $this->idtrainer	= $obj->idtrainer;
 
                 $this->capital   = $obj->capital;
 
-- 
GitLab