2004-10-20 23:06:45 +02:00
|
|
|
|
<?php
|
2004-02-13 15:05:00 +01:00
|
|
|
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2004-08-07 01:39:22 +02:00
|
|
|
|
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
2002-05-11 20:53:13 +02:00
|
|
|
|
*
|
|
|
|
|
|
* $Id$
|
|
|
|
|
|
* $Source$
|
|
|
|
|
|
*
|
|
|
|
|
|
* 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
|
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2004-12-28 16:36:40 +01:00
|
|
|
|
/**
|
2004-10-30 00:31:33 +02:00
|
|
|
|
\file htdocs/actioncomm.class.php
|
|
|
|
|
|
\ingroup commercial
|
|
|
|
|
|
\brief Fichier de la classe des actions commerciales
|
|
|
|
|
|
\version $Revision$
|
2004-09-30 21:28:40 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-12-28 16:36:40 +01:00
|
|
|
|
/** \class ActionComm
|
2004-10-30 00:31:33 +02:00
|
|
|
|
\brief Classe permettant la gestion des actions commerciales
|
2004-09-30 21:28:40 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2003-05-15 21:30:01 +02:00
|
|
|
|
class ActionComm
|
|
|
|
|
|
{
|
2002-05-11 20:53:13 +02:00
|
|
|
|
var $id;
|
|
|
|
|
|
var $db;
|
|
|
|
|
|
|
|
|
|
|
|
var $date;
|
|
|
|
|
|
var $type;
|
|
|
|
|
|
var $priority;
|
|
|
|
|
|
var $user;
|
|
|
|
|
|
var $author;
|
|
|
|
|
|
var $societe;
|
|
|
|
|
|
var $contact;
|
|
|
|
|
|
var $note;
|
|
|
|
|
|
var $percent;
|
2004-11-03 23:02:33 +01:00
|
|
|
|
var $error;
|
2002-05-11 20:53:13 +02:00
|
|
|
|
|
2004-10-30 00:31:33 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Constructeur
|
|
|
|
|
|
* \param db Handler d'acc<EFBFBD>s base de donn<EFBFBD>e
|
2003-09-01 14:23:32 +02:00
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function ActionComm($db)
|
2003-05-15 21:30:01 +02:00
|
|
|
|
{
|
2003-08-03 14:49:38 +02:00
|
|
|
|
$this->db = $db;
|
|
|
|
|
|
$this->societe = new Societe($db);
|
|
|
|
|
|
$this->author = new User($db);
|
2003-09-01 14:26:46 +02:00
|
|
|
|
if (class_exists("Contact"))
|
|
|
|
|
|
{
|
2004-10-30 00:31:33 +02:00
|
|
|
|
$this->contact = new Contact($db);
|
2003-09-01 14:26:46 +02:00
|
|
|
|
}
|
2003-08-03 14:49:38 +02:00
|
|
|
|
}
|
2004-10-30 00:31:33 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
2004-10-30 14:17:49 +02:00
|
|
|
|
* \brief Ajout d'une action en base (et eventuellement dans webcalendar)
|
2004-10-30 00:31:33 +02:00
|
|
|
|
* \param author auteur de la creation de l'action
|
2004-10-30 14:17:49 +02:00
|
|
|
|
* \param webcal ressource webcalendar: 0=on oublie webcal, 1=on ajoute une entr<EFBFBD>e g<EFBFBD>n<EFBFBD>rique dans webcal, objet=ajout de l'objet dans webcal
|
|
|
|
|
|
* \return int id de l'action cr<EFBFBD><EFBFBD>e
|
2002-05-11 20:53:13 +02:00
|
|
|
|
*/
|
2004-10-30 14:17:49 +02:00
|
|
|
|
function add($author, $webcal=0)
|
2003-05-15 21:31:07 +02:00
|
|
|
|
{
|
2004-10-30 14:17:49 +02:00
|
|
|
|
global $conf;
|
|
|
|
|
|
|
2004-08-07 01:39:22 +02:00
|
|
|
|
if (! $this->contact)
|
2003-08-03 14:49:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
$this->contact = 0;
|
|
|
|
|
|
}
|
2004-08-07 01:39:22 +02:00
|
|
|
|
if (! $this->propalrowid)
|
2003-09-01 14:41:25 +02:00
|
|
|
|
{
|
|
|
|
|
|
$this->propalrowid = 0;
|
|
|
|
|
|
}
|
2004-08-07 01:39:22 +02:00
|
|
|
|
if (! $this->percent)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->percent = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (! $this->priority)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->priority = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-01-11 20:26:38 +01:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea, label, fk_action, fk_soc, fk_user_author, fk_user_action, fk_contact, percent, note,priority,propalrowid) ";
|
|
|
|
|
|
$sql .= " VALUES ('$this->date', '$this->libelle', $this->type, $this->societe, $author->id,";
|
2004-08-07 01:39:22 +02:00
|
|
|
|
$sql .= $this->user->id . ", $this->contact, '$this->percent', '$this->note', $this->priority, $this->propalrowid);";
|
2003-05-15 21:31:07 +02:00
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
2004-10-30 14:17:49 +02:00
|
|
|
|
$idaction = $this->db->last_insert_id();
|
|
|
|
|
|
|
|
|
|
|
|
if ($conf->webcal->enabled) {
|
|
|
|
|
|
if (is_object($webcal))
|
|
|
|
|
|
{
|
|
|
|
|
|
// Ajoute entr<74>e dans webcal
|
|
|
|
|
|
$result=$webcal->add($author,$webcal->date,$webcal->texte,$webcal->desc);
|
|
|
|
|
|
if ($result < 0) {
|
2004-11-03 23:02:33 +01:00
|
|
|
|
$this->error="Echec insertion dans webcal: ".$webcal->error;
|
2004-10-30 14:17:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ($webcal == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
// \todo On ajoute une entr<74>e g<>n<EFBFBD>rique, pour l'instant pas utilis<69>
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $idaction;
|
2003-05-15 21:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2004-10-30 00:31:33 +02:00
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return -1;
|
2003-05-15 21:31:07 +02:00
|
|
|
|
}
|
2004-10-30 14:17:49 +02:00
|
|
|
|
|
2002-05-11 20:53:13 +02:00
|
|
|
|
}
|
2004-10-30 00:31:33 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Charge l'objet action depuis la base
|
|
|
|
|
|
* \param id id de l'action a r<EFBFBD>cup<EFBFBD>rer
|
2002-05-11 20:53:13 +02:00
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function fetch($id)
|
2003-07-21 22:47:39 +02:00
|
|
|
|
{
|
2005-01-11 20:14:25 +01:00
|
|
|
|
$sql = "SELECT ".$this->db->pdate("a.datea")." as da, a.note, a.label, c.libelle, fk_soc, fk_user_author, fk_contact, fk_facture, a.percent ";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql .= "FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c WHERE a.id=$id AND a.fk_action=c.id;";
|
2003-05-15 21:31:07 +02:00
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
2004-10-23 23:02:56 +02:00
|
|
|
|
$obj = $this->db->fetch_object();
|
2003-05-15 21:31:07 +02:00
|
|
|
|
|
|
|
|
|
|
$this->id = $id;
|
|
|
|
|
|
$this->type = $obj->libelle;
|
2005-01-11 20:14:25 +01:00
|
|
|
|
$this->libelle = $obj->label;
|
2003-05-15 21:31:07 +02:00
|
|
|
|
$this->date = $obj->da;
|
|
|
|
|
|
$this->note =$obj->note;
|
2003-08-03 15:24:37 +02:00
|
|
|
|
$this->percent =$obj->percent;
|
2003-05-15 21:31:07 +02:00
|
|
|
|
$this->societe->id = $obj->fk_soc;
|
|
|
|
|
|
$this->author->id = $obj->fk_user_author;
|
|
|
|
|
|
$this->contact->id = $obj->fk_contact;
|
2003-07-21 22:47:39 +02:00
|
|
|
|
$this->fk_facture = $obj->fk_facture;
|
|
|
|
|
|
if ($this->fk_facture)
|
|
|
|
|
|
{
|
2003-09-11 22:18:51 +02:00
|
|
|
|
$this->objet_url = '<a href="'. DOL_URL_ROOT . '/compta/facture.php?facid='.$this->fk_facture.'">Facture</a>';
|
2003-07-21 22:47:39 +02:00
|
|
|
|
}
|
2003-05-15 21:31:07 +02:00
|
|
|
|
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2004-08-07 01:39:22 +02:00
|
|
|
|
dolibarr_print_error($this->db);
|
2003-05-15 21:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-10-30 00:31:33 +02:00
|
|
|
|
|
2003-11-17 14:30:36 +01:00
|
|
|
|
/**
|
2004-10-30 00:31:33 +02:00
|
|
|
|
* \brief Supprime l'action de la base
|
|
|
|
|
|
* \param id id de l'action a effacer
|
2004-12-28 16:36:40 +01:00
|
|
|
|
* \return int 1 en cas de succ<EFBFBD>s
|
2002-05-11 20:53:13 +02:00
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function delete($id)
|
2003-09-01 14:23:32 +02:00
|
|
|
|
{
|
2004-10-30 00:31:33 +02:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm WHERE id=$id;";
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
2002-05-11 20:53:13 +02:00
|
|
|
|
}
|
2004-10-30 00:31:33 +02:00
|
|
|
|
|
2003-11-17 14:30:36 +01:00
|
|
|
|
/**
|
2004-10-30 00:31:33 +02:00
|
|
|
|
* \brief Met a jour l'action en base
|
2004-12-28 16:36:40 +01:00
|
|
|
|
* \return int 1 en cas de succ<EFBFBD>s
|
2003-08-03 14:49:38 +02:00
|
|
|
|
*/
|
2004-08-07 20:51:54 +02:00
|
|
|
|
function update()
|
2003-08-03 18:53:46 +02:00
|
|
|
|
{
|
2003-11-17 14:30:36 +01:00
|
|
|
|
if ($this->percent > 100)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->percent = 100;
|
|
|
|
|
|
}
|
2003-08-03 18:53:46 +02:00
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
|
2003-08-03 18:53:46 +02:00
|
|
|
|
$sql .= " SET percent=$this->percent";
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->percent == 100)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= ", datea = now()";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-03 19:28:16 +02:00
|
|
|
|
$sql .= ", fk_contact =". $this->contact->id;
|
|
|
|
|
|
|
2003-08-03 18:53:46 +02:00
|
|
|
|
$sql .= " WHERE id=$this->id;";
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql) )
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-08-07 01:39:22 +02:00
|
|
|
|
|
2002-05-11 20:53:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
?>
|