diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php
index 84987129be3..8b840353d8a 100644
--- a/htdocs/comm/fiche.php
+++ b/htdocs/comm/fiche.php
@@ -27,10 +27,15 @@
* \brief Page to show customer card of a third party
*/
+error_reporting(E_ALL);
+ini_set('display_errors', true);
+ini_set('html_errors', false);
+
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
@@ -109,6 +114,15 @@ if ($action == 'setassujtva' && $user->rights->societe->creer)
if (! $result) dol_print_error($result);
}
+// set prospect level
+if ($action == 'setprospectlevel' && $user->rights->societe->creer)
+{
+ $object->fetch($socid);
+ $object->fk_prospectlevel=GETPOST('prospect_level_id','int');
+ $object->set_prospect_level($user);
+ if ($result < 0) setEventMessage($object->error,'errors');
+}
+
/*
@@ -121,6 +135,7 @@ llxHeader('',$langs->trans('CustomerCard'));
$contactstatic = new Contact($db);
$userstatic=new User($db);
$form = new Form($db);
+$formcompany=new FormCompany($db);
if ($mode == 'search')
@@ -359,6 +374,21 @@ if ($id > 0)
print '
'.$object->price_level." | ";
print '';
}
+
+ // Level of prospect
+ print '| ';
+ print '';
+ print ' | ';
+ if ($action == 'editlevel')
+ $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_prospectlevel,'prospect_level_id',1);
+ else
+ print $object->getLibProspLevel();
+ print " | ";
+ print '
';
// Sales representative
include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
diff --git a/htdocs/comm/prospect/class/prospect.class.php b/htdocs/comm/prospect/class/prospect.class.php
index 68440aa0b84..ec0454c4847 100644
--- a/htdocs/comm/prospect/class/prospect.class.php
+++ b/htdocs/comm/prospect/class/prospect.class.php
@@ -148,9 +148,9 @@ class Prospect extends Societe
*
* @return string Libelle
*/
- function getLibLevel()
+ function getLibProspLevel()
{
- return $this->LibLevel($this->fk_prospectlevel);
+ return $this->LibProspLevel($this->fk_prospectlevel);
}
/**
@@ -159,7 +159,7 @@ class Prospect extends Societe
* @param int $fk_prospectlevel Prospect level
* @return string Libelle du niveau
*/
- function LibLevel($fk_prospectlevel)
+ function LibProspLevel($fk_prospectlevel)
{
global $langs;
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index db147ffde86..7dd0a6b1ff7 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -2655,6 +2655,73 @@ class Societe extends CommonObject
return false;
}
+
+ /**
+ * Return prostect level
+ *
+ * @return string Libelle
+ */
+ function getLibProspLevel()
+ {
+ return $this->LibProspLevel($this->fk_prospectlevel);
+ }
+
+ /**
+ * Return label of prospect level
+ *
+ * @param int $fk_prospectlevel Prospect level
+ * @return string label of level
+ */
+ function LibProspLevel($fk_prospectlevel)
+ {
+ global $langs;
+
+ $lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
+ // If lib not found in language file, we get label from cache/databse
+ if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
+ {
+ $lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
+ }
+ return $lib;
+ }
+
+
+ /**
+ * Definit la societe comme un client
+ *
+ * @param float $remise Valeur en % de la remise
+ * @param string $note Note/Motif de modification de la remise
+ * @param User $user Utilisateur qui definie la remise
+ * @return int <0 if KO, >0 if OK
+ */
+ function set_prospect_level($user)
+ {
+ global $langs;
+
+ if ($this->id)
+ {
+ $this->db->begin();
+
+ $now=dol_now();
+
+ // Positionne remise courante
+ $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
+ $sql.= " fk_prospectlevel='".$this->fk_prospectlevel."'";
+ $sql.= " ,fk_user_modif='".$user->id."'";
+ $sql.= " WHERE rowid = ".$this->id;
+ dol_syslog(get_class($this)."::set_prospect_level sql=".$sql);
+ $resql=$this->db->query($sql);
+ if (! $resql)
+ {
+ $this->db->rollback();
+ $this->error=$this->db->error();
+ return -1;
+ }
+
+ $this->db->commit();
+ return 1;
+ }
+ }
}