2006-06-18 17:06:29 +02:00
< ? php
2010-08-05 11:12:07 +02:00
/* Copyright ( C ) 2006 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2010-03-25 12:25:10 +01:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis @ dolibarr . fr >
2010-06-17 19:12:34 +02:00
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
2006-06-18 17:06:29 +02:00
*
* 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 .
*/
/**
2010-06-08 01:52:43 +02:00
* \file htdocs / core / class / commonobject . class . php
2009-06-19 09:32:39 +02:00
* \ingroup core
* \brief Fichier de la classe mere des classes metiers ( facture , contrat , propal , commande , etc ... )
* \version $Id $
2009-02-20 23:53:15 +01:00
*/
2006-06-18 17:06:29 +02:00
/**
2009-06-19 09:32:39 +02:00
* \class CommonObject
* \brief Classe mere pour heritage des classes metiers
2009-02-20 23:53:15 +01:00
*/
2006-06-18 17:06:29 +02:00
class CommonObject
{
2010-08-06 18:10:03 +02:00
// Instantiate classes of thirdparty module
var $objModules = array ();
2010-08-18 09:28:12 +02:00
2010-05-04 20:33:22 +02:00
/**
* \brief Check if ref is used .
* \return int < 0 if KO , 0 if not found , > 0 if found
*/
function verifyNumRef ()
{
global $conf ;
$sql = " SELECT rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . $this -> element ;
$sql .= " WHERE ref = ' " . $this -> ref . " ' " ;
$sql .= " AND entity = " . $conf -> entity ;
dol_syslog ( " CommonObject::verifyNumRef sql= " . $sql , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
return $num ;
}
else
{
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " CommonObject::verifyNumRef " . $this -> error , LOG_ERR );
return - 1 ;
}
}
2006-06-18 17:06:29 +02:00
/**
2010-05-28 20:13:17 +02:00
* \brief Add a link between element $this -> element and a contact
* \param fk_socpeople Id of contact to link
* \param type_contact Type of contact ( code or id )
* \param source external = Contact extern ( llx_socpeople ), internal = Contact intern ( llx_user )
* \return int < 0 if KO , > 0 if OK
2009-02-20 23:53:15 +01:00
*/
2010-05-28 11:37:12 +02:00
function add_contact ( $fk_socpeople , $type_contact , $source = 'external' , $notrigger = 0 )
2006-06-18 17:06:29 +02:00
{
2010-05-28 20:13:17 +02:00
global $user , $conf , $langs ;
2006-06-18 17:06:29 +02:00
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::add_contact $fk_socpeople , $type_contact , $source " );
2006-06-18 17:06:29 +02:00
2010-05-28 20:13:17 +02:00
// Check parameters
2006-06-18 17:06:29 +02:00
if ( $fk_socpeople <= 0 )
{
$this -> error = $langs -> trans ( " ErrorWrongValueForParameter " , " 1 " );
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::add_contact " . $this -> error , LOG_ERR );
2006-06-18 17:06:29 +02:00
return - 1 ;
}
if ( ! $type_contact )
{
$this -> error = $langs -> trans ( " ErrorWrongValueForParameter " , " 2 " );
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::add_contact " . $this -> error , LOG_ERR );
2006-06-18 17:06:29 +02:00
return - 2 ;
}
$id_type_contact = 0 ;
if ( is_numeric ( $type_contact ))
{
$id_type_contact = $type_contact ;
}
else
{
// On recherche id type_contact
$sql = " SELECT tc.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_type_contact as tc " ;
$sql .= " WHERE element=' " . $this -> element . " ' " ;
$sql .= " AND source=' " . $source . " ' " ;
$sql .= " AND code=' " . $type_contact . " ' AND active=1 " ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$obj = $this -> db -> fetch_object ( $resql );
$id_type_contact = $obj -> rowid ;
}
}
2010-05-28 20:13:17 +02:00
$datecreate = dol_now ();
2006-06-18 17:06:29 +02:00
2009-02-20 23:53:15 +01:00
// Insertion dans la base
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " element_contact " ;
$sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) " ;
$sql .= " VALUES ( " . $this -> id . " , " . $fk_socpeople . " , " ;
2006-06-18 17:06:29 +02:00
$sql .= $this -> db -> idate ( $datecreate );
$sql .= " , 4, ' " . $id_type_contact . " ' " ;
2009-02-20 23:53:15 +01:00
$sql .= " ) " ;
dol_syslog ( " CommonObject::add_contact sql= " . $sql );
2006-06-18 17:06:29 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
2009-02-20 23:53:15 +01:00
{
2010-05-28 11:37:12 +02:00
if ( ! $notrigger )
{
// Call triggers
include_once ( DOL_DOCUMENT_ROOT . " /core/class/interfaces.class.php " );
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( strtoupper ( $this -> element ) . '_ADD_CONTACT' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// End call triggers
}
2010-05-28 20:13:17 +02:00
2009-02-20 23:53:15 +01:00
return 1 ;
}
else
{
2007-10-31 13:55:01 +01:00
if ( $this -> db -> errno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
$this -> error = $this -> db -> errno ();
return - 2 ;
}
else
{
2010-05-28 20:13:17 +02:00
$this -> error = $this -> db -> error ();
2009-02-20 23:53:15 +01:00
dol_syslog ( $this -> error , LOG_ERR );
2007-10-31 13:55:01 +01:00
return - 1 ;
}
2009-02-20 23:53:15 +01:00
}
2006-06-18 17:06:29 +02:00
}
2009-02-20 23:53:15 +01:00
/**
2010-05-28 20:13:17 +02:00
* \brief Update a link to contact line
* \param rowid Id of line contact - element
* \param statut New status of link
* \param type_contact_id Id of contact type
* \return int < 0 if KO , >= 0 if OK
2009-02-20 23:53:15 +01:00
*/
2006-06-18 17:06:29 +02:00
function update_contact ( $rowid , $statut , $type_contact_id )
{
2009-02-20 23:53:15 +01:00
// Insertion dans la base
$sql = " UPDATE " . MAIN_DB_PREFIX . " element_contact set " ;
$sql .= " statut = " . $statut . " , " ;
$sql .= " fk_c_type_contact = ' " . $type_contact_id . " ' " ;
$sql .= " where rowid = " . $rowid ;
// Retour
if ( $this -> db -> query ( $sql ) )
{
return 0 ;
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
}
2006-06-18 17:06:29 +02:00
/**
2010-05-28 20:13:17 +02:00
* \brief Delete a link to contact line
* \param rowid Id of link line to delete
2009-02-20 23:53:15 +01:00
* \return statur > 0 si ok , < 0 si ko
*/
2010-05-28 11:37:12 +02:00
function delete_contact ( $rowid , $notrigger = 0 )
2009-02-20 23:53:15 +01:00
{
2010-05-28 20:13:17 +02:00
global $user , $langs , $conf ;
2009-02-20 23:53:15 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " element_contact " ;
$sql .= " WHERE rowid = " . $rowid ;
dol_syslog ( " CommonObject::delete_contact sql= " . $sql );
if ( $this -> db -> query ( $sql ))
{
2010-05-28 11:37:12 +02:00
if ( ! $notrigger )
{
// Call triggers
include_once ( DOL_DOCUMENT_ROOT . " /core/class/interfaces.class.php " );
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( strtoupper ( $this -> element ) . '_DELETE_CONTACT' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// End call triggers
}
2010-05-28 20:13:17 +02:00
2009-02-20 23:53:15 +01:00
return 1 ;
}
else
{
2008-04-04 12:37:58 +02:00
$this -> error = $this -> db -> lasterror ();
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::delete_contact error= " . $this -> error , LOG_ERR );
return - 1 ;
}
}
2010-05-04 20:33:22 +02:00
2010-04-29 17:35:52 +02:00
/**
2010-05-28 20:13:17 +02:00
* \brief Delete all links between an object $this and all its contacts
* \return int > 0 if OK , < 0 if KO
2010-04-29 17:35:52 +02:00
*/
function delete_linked_contact ()
{
$temp = array ();
2010-05-28 20:13:17 +02:00
$typeContact = $this -> liste_type_contact ( '' );
2010-05-04 20:33:22 +02:00
2010-04-29 17:35:52 +02:00
foreach ( $typeContact as $key => $value )
{
array_push ( $temp , $key );
}
$listId = implode ( " , " , $temp );
2010-05-04 20:33:22 +02:00
2010-04-29 17:35:52 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " element_contact " ;
$sql .= " WHERE element_id = " . $this -> id ;
$sql .= " AND fk_c_type_contact IN ( " . $listId . " ) " ;
dol_syslog ( " CommonObject::delete_linked_contact sql= " . $sql );
if ( $this -> db -> query ( $sql ))
{
return 1 ;
}
else
{
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " CommonObject::delete_linked_contact error= " . $this -> error , LOG_ERR );
return - 1 ;
}
}
2009-02-20 23:53:15 +01:00
/**
2010-04-24 15:39:16 +02:00
* \brief Get array of all contacts for an object
* \param statut Status of lines to get ( - 1 = all )
* \param source Source of contact : external or thirdparty ( llx_socpeople ) or internal ( llx_user )
* \return array Array of id of contacts
2009-02-20 23:53:15 +01:00
*/
function liste_contact ( $statut =- 1 , $source = 'external' )
{
global $langs ;
$tab = array ();
2010-01-26 14:28:25 +01:00
$sql = " SELECT ec.rowid, ec.statut, ec.fk_socpeople as id " ;
if ( $source == 'internal' ) $sql .= " , '-1' as socid " ;
2010-04-24 15:39:16 +02:00
if ( $source == 'external' || $source == 'thirdparty' ) $sql .= " , t.fk_soc as socid " ;
2010-01-26 14:28:25 +01:00
$sql .= " , t.name as nom, t.firstname " ;
$sql .= " , tc.source, tc.element, tc.code, tc.libelle " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_type_contact tc " ;
$sql .= " , " . MAIN_DB_PREFIX . " element_contact ec " ;
2009-02-20 23:53:15 +01:00
if ( $source == 'internal' ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user t on ec.fk_socpeople = t.rowid " ;
2010-04-24 15:39:16 +02:00
if ( $source == 'external' || $source == 'thirdparty' ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " socpeople t on ec.fk_socpeople = t.rowid " ;
2009-02-20 23:53:15 +01:00
$sql .= " WHERE ec.element_id = " . $this -> id ;
$sql .= " AND ec.fk_c_type_contact=tc.rowid " ;
$sql .= " AND tc.element=' " . $this -> element . " ' " ;
if ( $source == 'internal' ) $sql .= " AND tc.source = 'internal' " ;
2010-04-24 15:39:16 +02:00
if ( $source == 'external' || $source == 'thirdparty' ) $sql .= " AND tc.source = 'external' " ;
2009-02-20 23:53:15 +01:00
$sql .= " AND tc.active=1 " ;
if ( $statut >= 0 ) $sql .= " AND ec.statut = ' " . $statut . " ' " ;
$sql .= " ORDER BY t.name ASC " ;
dol_syslog ( " CommonObject::liste_contact sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
$transkey = " TypeContact_ " . $obj -> element . " _ " . $obj -> source . " _ " . $obj -> code ;
$libelle_type = ( $langs -> trans ( $transkey ) != $transkey ? $langs -> trans ( $transkey ) : $obj -> libelle );
2010-01-26 14:28:25 +01:00
$tab [ $i ] = array ( 'source' => $obj -> source , 'socid' => $obj -> socid , 'id' => $obj -> id , 'nom' => $obj -> nom , 'firstname' => $obj -> firstname ,
2006-06-18 17:06:29 +02:00
'rowid' => $obj -> rowid , 'code' => $obj -> code , 'libelle' => $libelle_type , 'status' => $obj -> statut );
2009-02-20 23:53:15 +01:00
$i ++ ;
}
return $tab ;
}
else
{
$this -> error = $this -> db -> error ();
dol_print_error ( $this -> db );
return - 1 ;
}
}
/**
* \brief Le detail d ' un contact
* \param rowid L ' identifiant du contact
* \return object L ' objet construit par DoliDb . fetch_object
*/
function detail_contact ( $rowid )
{
$sql = " SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact, " ;
$sql .= " tc.code, tc.libelle, " ;
$sql .= " s.fk_soc " ;
$sql .= " FROM ( " . MAIN_DB_PREFIX . " element_contact as ec, " . MAIN_DB_PREFIX . " c_type_contact as tc) " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " socpeople as s ON ec.fk_socpeople=s.rowid " ; // Si contact de type external, alors il est li<6C> <20> une societe
$sql .= " WHERE ec.rowid = " . $rowid ;
$sql .= " AND ec.fk_c_type_contact=tc.rowid " ;
$sql .= " AND tc.element = ' " . $this -> element . " ' " ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$obj = $this -> db -> fetch_object ( $resql );
return $obj ;
}
else
{
$this -> error = $this -> db -> error ();
dol_print_error ( $this -> db );
return null ;
}
}
/**
* \brief La liste des valeurs possibles de type de contacts
2010-04-29 17:35:52 +02:00
* \param source internal , external or all if not defined
2010-01-25 23:24:40 +01:00
* \param order Sort order by : code or rowid
2009-02-20 23:53:15 +01:00
* \return array La liste des natures
*/
2010-04-29 17:35:52 +02:00
function liste_type_contact ( $source = 'internal' , $order = 'code' )
2009-02-20 23:53:15 +01:00
{
global $langs ;
$tab = array ();
2010-01-25 23:24:40 +01:00
$sql = " SELECT DISTINCT tc.rowid, tc.code, tc.libelle " ;
2009-02-20 23:53:15 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_type_contact as tc " ;
2010-01-25 23:24:40 +01:00
$sql .= " WHERE tc.element=' " . $this -> element . " ' " ;
2010-05-28 20:13:17 +02:00
if ( ! empty ( $source )) $sql .= " AND tc.source=' " . $source . " ' " ;
2010-01-25 23:24:40 +01:00
$sql .= " ORDER by tc. " . $order ;
2009-02-20 23:53:15 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
$transkey = " TypeContact_ " . $this -> element . " _ " . $source . " _ " . $obj -> code ;
$libelle_type = ( $langs -> trans ( $transkey ) != $transkey ? $langs -> trans ( $transkey ) : $obj -> libelle );
$tab [ $obj -> rowid ] = $libelle_type ;
$i ++ ;
}
return $tab ;
}
else
{
$this -> error = $this -> db -> error ();
// dol_print_error($this->db);
return null ;
}
}
/**
2009-06-07 10:39:51 +02:00
* \brief Retourne id des contacts d 'une source et d' un type actif donne
2009-02-20 23:53:15 +01:00
* Exemple : contact client de facturation ( 'external' , 'BILLING' )
* Exemple : contact client de livraison ( 'external' , 'SHIPPING' )
* Exemple : contact interne suivi paiement ( 'internal' , 'SALESREPFOLL' )
2007-09-16 05:55:35 +02:00
* \param source 'external' or 'internal'
2007-10-31 13:55:01 +01:00
* \param code 'BILLING' , 'SHIPPING' , 'SALESREPFOLL' , ...
2010-04-01 10:47:41 +02:00
** \param status limited to a certain status
2009-02-20 23:53:15 +01:00
* \return array Liste des id contacts
*/
2010-04-01 10:47:41 +02:00
function getIdContact ( $source , $code , $status = 0 )
2009-02-20 23:53:15 +01:00
{
$result = array ();
$i = 0 ;
$sql = " SELECT ec.fk_socpeople " ;
2010-06-15 21:03:21 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " element_contact as ec, " ;
$sql .= " " . MAIN_DB_PREFIX . " c_type_contact as tc " ;
2009-02-20 23:53:15 +01:00
$sql .= " WHERE ec.element_id = " . $this -> id ;
2010-04-01 10:47:41 +02:00
$sql .= " AND ec.fk_c_type_contact = tc.rowid " ;
2009-02-20 23:53:15 +01:00
$sql .= " AND tc.element = ' " . $this -> element . " ' " ;
$sql .= " AND tc.source = ' " . $source . " ' " ;
$sql .= " AND tc.code = ' " . $code . " ' " ;
$sql .= " AND tc.active = 1 " ;
2010-04-01 10:47:41 +02:00
if ( $status ) $sql .= " AND ec.statut = " . $status ;
2010-06-15 21:03:21 +02:00
// FIXME Add filter on entity
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::getIdContact sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
$result [ $i ] = $obj -> fk_socpeople ;
$i ++ ;
}
}
else
{
$this -> error = $this -> db -> error ();
dol_syslog ( " CommonObject::getIdContact " . $this -> error , LOG_ERR );
return null ;
}
return $result ;
}
/**
* \brief Charge le contact d ' id $id dans this -> contact
* \param contactid Id du contact
* \return int < 0 if KO , > 0 if OK
*/
function fetch_contact ( $contactid )
{
2010-04-28 09:55:43 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /contact/class/contact.class.php " );
2008-02-24 18:01:48 +01:00
$contact = new Contact ( $this -> db );
$result = $contact -> fetch ( $contactid );
$this -> contact = $contact ;
2007-09-14 23:02:13 +02:00
return $result ;
2009-02-20 23:53:15 +01:00
}
/**
2010-05-12 13:58:58 +02:00
* \brief Load the third party of object from id $this -> socid into this -> client
2009-02-20 23:53:15 +01:00
* \return int < 0 if KO , > 0 if OK
*/
2010-05-12 13:58:58 +02:00
function fetch_thirdparty ()
2009-02-20 23:53:15 +01:00
{
2009-06-19 09:32:39 +02:00
global $conf ;
2009-07-07 18:19:37 +02:00
2010-05-05 20:08:42 +02:00
if ( empty ( $this -> socid )) return 0 ;
2009-02-20 23:53:15 +01:00
$client = new Societe ( $this -> db );
$result = $client -> fetch ( $this -> socid );
$this -> client = $client ;
2009-06-19 09:32:39 +02:00
// Use first price level if level not defined for third party
if ( $conf -> global -> PRODUIT_MULTIPRICES && empty ( $this -> client -> price_level )) $this -> client -> price_level = 1 ;
2009-07-07 18:19:37 +02:00
2007-09-14 23:02:13 +02:00
return $result ;
2009-02-20 23:53:15 +01:00
}
/**
2010-03-11 15:31:16 +01:00
* \brief Charge le projet d ' id $this -> fk_project dans this -> projet
2010-05-05 20:08:42 +02:00
* \return int < 0 if KO , >= 0 if OK
2009-02-20 23:53:15 +01:00
*/
function fetch_projet ()
{
2010-05-05 20:08:42 +02:00
if ( empty ( $this -> fk_project )) return 0 ;
2010-03-11 15:31:16 +01:00
$project = new Project ( $this -> db );
$result = $project -> fetch ( $this -> fk_project );
$this -> projet = $project ;
2007-09-14 23:02:13 +02:00
return $result ;
2009-02-20 23:53:15 +01:00
}
2007-05-04 20:56:49 +02:00
2008-02-24 18:01:48 +01:00
/**
2009-02-20 23:53:15 +01:00
* \brief Charge le user d ' id userid dans this -> user
* \param userid Id du contact
* \return int < 0 if KO , > 0 if OK
*/
function fetch_user ( $userid )
{
2010-04-28 09:31:34 +02:00
$user = new User ( $this -> db );
$result = $user -> fetch ( $userid );
2008-02-24 18:01:48 +01:00
$this -> user = $user ;
2007-09-14 23:02:13 +02:00
return $result ;
2009-02-20 23:53:15 +01:00
}
2008-02-24 18:01:48 +01:00
2007-09-14 23:02:13 +02:00
/**
2009-12-23 11:07:48 +01:00
* \brief Charge l 'adresse de livraison d' id $this -> fk_delivery_address dans this -> deliveryaddress
2009-02-20 23:53:15 +01:00
* \param userid Id du contact
* \return int < 0 if KO , > 0 if OK
*/
2007-05-14 17:18:40 +02:00
function fetch_adresse_livraison ( $deliveryaddressid )
2007-09-14 23:02:13 +02:00
{
$address = new Societe ( $this -> db );
$result = $address -> fetch_adresse_livraison ( $deliveryaddressid );
$this -> deliveryaddress = $address ;
2009-12-23 11:07:48 +01:00
$this -> adresse = $address ; // TODO obsolete
$this -> address = $address ;
2007-09-14 23:02:13 +02:00
return $result ;
}
2009-12-15 12:46:54 +01:00
2009-12-15 11:39:22 +01:00
/**
* \brief Read linked document
*/
function fetch_object ()
{
$object = $this -> origin ;
2010-04-24 15:39:16 +02:00
2010-03-13 16:52:30 +01:00
// TODO uniformise code
if ( $object == 'shipping' ) $object = 'expedition' ;
if ( $object == 'delivery' ) $object = 'livraison' ;
2010-04-01 12:21:48 +02:00
2010-04-09 09:55:37 +02:00
$classname = ucfirst ( $object );
$this -> $object = new $classname ( $this -> db );
2009-12-15 11:39:22 +01:00
$this -> $object -> fetch ( $this -> origin_id );
}
2008-02-24 18:01:48 +01:00
2007-07-29 13:09:04 +02:00
2007-11-05 23:37:41 +01:00
/**
2009-02-20 23:53:15 +01:00
* \brief Load properties id_previous and id_next
* \param filter Optional filter
2009-10-04 14:16:45 +02:00
* \param fieldid Name of field to use for the select MAX and MIN
* \return int < 0 if KO , > 0 if OK
2009-02-20 23:53:15 +01:00
*/
2007-11-05 23:37:41 +01:00
function load_previous_next_ref ( $filter = '' , $fieldid )
{
2009-11-28 13:06:11 +01:00
global $conf , $user ;
2009-10-04 14:16:45 +02:00
2007-11-05 23:37:41 +01:00
if ( ! $this -> table_element )
{
2010-06-09 20:25:20 +02:00
dol_print_error ( " CommonObject::load_previous_next_ref was called on objet with property table_element not defined " , LOG_ERR );
2007-11-05 23:37:41 +01:00
return - 1 ;
}
2007-10-29 21:36:02 +01:00
2009-10-04 14:16:45 +02:00
// this->ismultientitymanaged contains
// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
2009-11-28 15:14:21 +01:00
$alias = 's' ;
if ( $this -> element == 'societe' ) $alias = 'te' ;
2009-10-04 14:16:45 +02:00
2009-11-28 13:06:11 +01:00
$sql = " SELECT MAX(te. " . $fieldid . " ) " ;
2009-10-04 14:16:45 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . $this -> table_element . " as te " ;
2009-11-28 15:14:21 +01:00
if ( $this -> ismultientitymanaged == 2 || ( $this -> element != 'societe' && ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir )) $sql .= " , " . MAIN_DB_PREFIX . " societe as s " ; // If we need to link to societe to limit select to entity
if ( ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON " . $alias . " .rowid = sc.fk_soc " ;
2009-10-04 14:16:45 +02:00
$sql .= " WHERE te. " . $fieldid . " < ' " . addslashes ( $this -> ref ) . " ' " ;
2009-11-28 15:14:21 +01:00
if ( ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir ) $sql .= " AND sc.fk_user = " . $user -> id ;
2007-11-05 23:37:41 +01:00
if ( isset ( $filter )) $sql .= " AND " . $filter ;
2009-11-29 18:18:11 +01:00
if ( $this -> ismultientitymanaged == 2 || ( $this -> element != 'societe' && ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir )) $sql .= ' AND te.fk_soc = s.rowid' ; // If we need to link to societe to limit select to entity
2010-06-09 20:25:20 +02:00
if ( $this -> ismultientitymanaged == 1 ) $sql .= ' AND te.entity IN (0,' . $conf -> entity . ')' ;
2008-02-24 15:41:07 +01:00
2009-11-28 15:21:10 +01:00
//print $sql."<br>";
2007-11-05 23:37:41 +01:00
$result = $this -> db -> query ( $sql ) ;
if ( ! $result )
{
$this -> error = $this -> db -> error ();
return - 1 ;
}
$row = $this -> db -> fetch_row ( $result );
$this -> ref_previous = $row [ 0 ];
2008-02-24 15:41:07 +01:00
2008-02-24 18:01:48 +01:00
2009-11-28 13:06:11 +01:00
$sql = " SELECT MIN(te. " . $fieldid . " ) " ;
2009-10-04 14:16:45 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . $this -> table_element . " as te " ;
2009-11-28 15:14:21 +01:00
if ( $this -> ismultientitymanaged == 2 || ( $this -> element != 'societe' && ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir )) $sql .= " , " . MAIN_DB_PREFIX . " societe as s " ; // If we need to link to societe to limit select to entity
if ( ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON " . $alias . " .rowid = sc.fk_soc " ;
2009-10-04 14:16:45 +02:00
$sql .= " WHERE te. " . $fieldid . " > ' " . addslashes ( $this -> ref ) . " ' " ;
2009-11-28 15:14:21 +01:00
if ( ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir ) $sql .= " AND sc.fk_user = " . $user -> id ;
2007-11-05 23:37:41 +01:00
if ( isset ( $filter )) $sql .= " AND " . $filter ;
2009-11-29 18:18:11 +01:00
if ( $this -> ismultientitymanaged == 2 || ( $this -> element != 'societe' && ! $this -> isnolinkedbythird && ! $user -> rights -> societe -> client -> voir )) $sql .= ' AND te.fk_soc = s.rowid' ; // If we need to link to societe to limit select to entity
2010-06-09 20:25:20 +02:00
if ( $this -> ismultientitymanaged == 1 ) $sql .= ' AND te.entity IN (0,' . $conf -> entity . ')' ;
2009-10-04 14:16:45 +02:00
// Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null
2008-02-24 15:41:07 +01:00
2009-04-27 22:37:50 +02:00
//print $sql."<br>";
2007-11-05 23:37:41 +01:00
$result = $this -> db -> query ( $sql ) ;
if ( ! $result )
{
$this -> error = $this -> db -> error ();
return - 2 ;
}
$row = $this -> db -> fetch_row ( $result );
$this -> ref_next = $row [ 0 ];
2008-02-24 18:01:48 +01:00
2007-11-05 23:37:41 +01:00
return 1 ;
}
2008-02-24 18:01:48 +01:00
2009-02-20 23:53:15 +01:00
/**
2010-04-24 15:39:16 +02:00
* \brief Return list of id of contacts of project
* \param source Source of contact : external ( llx_socpeople ) or internal ( llx_user ) or thirdparty ( llx_societe )
* \return array Array of id of contacts ( if source = external or internal )
* Array of id of third parties with at least one contact on project ( if source = thirdparty )
2009-02-20 23:53:15 +01:00
*/
function getListContactId ( $source = 'external' )
{
$contactAlreadySelected = array ();
$tab = $this -> liste_contact ( - 1 , $source );
$num = sizeof ( $tab );
$i = 0 ;
while ( $i < $num )
{
2010-04-24 15:39:16 +02:00
if ( $source == 'thirdparty' ) $contactAlreadySelected [ $i ] = $tab [ $i ][ 'socid' ];
else $contactAlreadySelected [ $i ] = $tab [ $i ][ 'id' ];
2009-02-20 23:53:15 +01:00
$i ++ ;
}
return $contactAlreadySelected ;
}
2007-11-05 23:37:41 +01:00
2008-02-24 18:01:48 +01:00
2008-02-24 16:51:06 +01:00
/**
2009-12-15 09:15:11 +01:00
* \brief Link element with a project
2009-02-20 23:53:15 +01:00
* \param projid Project id to link element to
* \return int < 0 if KO , > 0 if OK
*/
2010-03-11 15:31:16 +01:00
function setProject ( $projectid )
2008-02-24 16:51:06 +01:00
{
if ( ! $this -> table_element )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::setProject was called on objet with property table_element not defined " , LOG_ERR );
2008-02-24 16:51:06 +01:00
return - 1 ;
}
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element ;
2010-03-11 15:31:16 +01:00
if ( $projectid ) $sql .= ' SET fk_projet = ' . $projectid ;
2008-02-24 16:51:06 +01:00
else $sql .= ' SET fk_projet = NULL' ;
$sql .= ' WHERE rowid = ' . $this -> id ;
2008-02-24 18:01:48 +01:00
2009-03-23 20:13:51 +01:00
dol_syslog ( " CommonObject::setProject sql= " . $sql );
2008-02-24 16:51:06 +01:00
if ( $this -> db -> query ( $sql ))
{
2010-03-11 15:31:16 +01:00
$this -> fk_project = $projectid ;
2008-02-24 16:51:06 +01:00
return 1 ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-02-24 16:51:06 +01:00
return - 1 ;
}
}
2008-02-24 18:01:48 +01:00
2008-02-24 17:16:34 +01:00
/**
2009-02-20 23:53:15 +01:00
* \brief Set last model used by doc generator
* \param user User object that make change
* \param modelpdf Modele name
* \return int < 0 if KO , > 0 if OK
*/
2008-02-24 17:16:34 +01:00
function setDocModel ( $user , $modelpdf )
{
if ( ! $this -> table_element )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::setDocModel was called on objet with property table_element not defined " , LOG_ERR );
2008-02-24 17:16:34 +01:00
return - 1 ;
}
$sql = " UPDATE " . MAIN_DB_PREFIX . $this -> table_element ;
$sql .= " SET model_pdf = ' " . $modelpdf . " ' " ;
$sql .= " WHERE rowid = " . $this -> id ;
// if ($this->element == 'facture') $sql.= " AND fk_statut < 2";
// if ($this->element == 'propal') $sql.= " AND fk_statut = 0";
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::setDocModel sql= " . $sql );
2008-02-24 17:16:34 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$this -> modelpdf = $modelpdf ;
return 1 ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-02-24 17:16:34 +01:00
return 0 ;
}
}
2008-02-24 18:01:48 +01:00
2008-02-24 17:46:42 +01:00
/**
2010-08-20 18:22:30 +02:00
* Stocke un numero de rang pour toutes les lignes de detail d 'un element qui n' en ont pas .
* @ param renum true to renum all already ordered lines , false to renum only not already ordered lines .
2009-02-20 23:53:15 +01:00
*/
2010-01-05 01:04:45 +01:00
function line_order ( $renum = false )
2008-02-24 17:46:42 +01:00
{
if ( ! $this -> table_element_line )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::line_order was called on objet with property table_element_line not defined " , LOG_ERR );
2008-02-24 17:46:42 +01:00
return - 1 ;
}
if ( ! $this -> fk_element )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::line_order was called on objet with property fk_element not defined " , LOG_ERR );
2008-02-24 17:46:42 +01:00
return - 1 ;
}
$sql = 'SELECT count(rowid) FROM ' . MAIN_DB_PREFIX . $this -> table_element_line ;
$sql .= ' WHERE ' . $this -> fk_element . '=' . $this -> id ;
2010-01-05 01:04:45 +01:00
if ( ! $renum ) $sql .= ' AND rang = 0' ;
2010-07-02 17:38:32 +02:00
if ( $renum ) $sql .= ' AND rang <> 0' ;
2008-02-24 17:46:42 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$row = $this -> db -> fetch_row ( $resql );
$nl = $row [ 0 ];
}
if ( $nl > 0 )
{
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $this -> table_element_line ;
$sql .= ' WHERE ' . $this -> fk_element . ' = ' . $this -> id ;
$sql .= ' ORDER BY rang ASC, rowid ASC' ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$row = $this -> db -> fetch_row ( $resql );
$li [ $i ] = $row [ 0 ];
$i ++ ;
}
}
for ( $i = 0 ; $i < sizeof ( $li ) ; $i ++ )
{
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element_line . ' SET rang = ' . ( $i + 1 );
$sql .= ' WHERE rowid = ' . $li [ $i ];
if ( ! $this -> db -> query ( $sql ) )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( $this -> db -> error ());
2008-02-24 17:46:42 +01:00
}
}
}
}
2010-08-20 18:22:30 +02:00
/**
2010-08-22 15:40:44 +02:00
*
2010-08-20 18:22:30 +02:00
* Enter description here ...
* @ param unknown_type $rowid
*/
2008-02-24 17:46:42 +01:00
function line_up ( $rowid )
{
$this -> line_order ();
2010-08-20 17:56:33 +02:00
// Get rang of line
$rang = $this -> getRangOfLine ( $rowid );
2008-02-24 17:46:42 +01:00
2010-08-20 18:22:30 +02:00
// Update position of line
$this -> updateLineUp ( $rowid , $rang );
}
/**
2010-08-22 15:40:44 +02:00
*
2010-08-20 18:22:30 +02:00
* Enter description here ...
* @ param unknown_type $rowid
*/
function line_down ( $rowid )
{
$this -> line_order ();
// Get rang of line
$rang = $this -> getRangOfLine ( $rowid );
// Get max value for rang
$max = $this -> line_max ();
// Update position of line
$this -> updateLineDown ( $rowid , $rang , $max );
}
2010-08-22 15:40:44 +02:00
2010-08-20 19:57:25 +02:00
/**
* Update position of line ( rang )
*/
function updateRangOfLine ( $rowid , $rang )
{
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element_line . ' SET rang = ' . $rang ;
$sql .= ' WHERE rowid = ' . $rowid ;
if ( ! $this -> db -> query ( $sql ) )
{
dol_print_error ( $this -> db );
}
}
2010-08-22 15:40:44 +02:00
2010-08-20 18:22:30 +02:00
/**
* Update position of line up ( rang )
*/
function updateLineUp ( $rowid , $rang )
{
2008-02-24 17:46:42 +01:00
if ( $rang > 1 )
{
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element_line . ' SET rang = ' . $rang ;
$sql .= ' WHERE ' . $this -> fk_element . ' = ' . $this -> id ;
$sql .= ' AND rang = ' . ( $rang - 1 );
if ( $this -> db -> query ( $sql ) )
{
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element_line . ' SET rang = ' . ( $rang - 1 );
$sql .= ' WHERE rowid = ' . $rowid ;
if ( ! $this -> db -> query ( $sql ) )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-02-24 17:46:42 +01:00
}
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-02-24 17:46:42 +01:00
}
}
}
2010-08-22 15:40:44 +02:00
2010-08-20 18:22:30 +02:00
/**
* Update position of line down ( rang )
*/
function updateLineDown ( $rowid , $rang , $max )
2008-02-24 17:46:42 +01:00
{
if ( $rang < $max )
{
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element_line . ' SET rang = ' . $rang ;
$sql .= ' WHERE ' . $this -> fk_element . ' = ' . $this -> id ;
$sql .= ' AND rang = ' . ( $rang + 1 );
if ( $this -> db -> query ( $sql ) )
{
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element_line . ' SET rang = ' . ( $rang + 1 );
$sql .= ' WHERE rowid = ' . $rowid ;
if ( ! $this -> db -> query ( $sql ) )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-02-24 17:46:42 +01:00
}
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2008-02-24 17:46:42 +01:00
}
}
2008-02-24 18:01:48 +01:00
}
2010-08-22 15:40:44 +02:00
2010-08-20 17:56:33 +02:00
/**
* Get position of line ( rang )
* @ result int Value of rang in table of lines
*/
function getRangOfLine ( $rowid )
{
$sql = 'SELECT rang FROM ' . MAIN_DB_PREFIX . $this -> table_element_line ;
$sql .= ' WHERE rowid =' . $rowid ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$row = $this -> db -> fetch_row ( $resql );
return $row [ 0 ];
}
}
2010-08-22 15:40:44 +02:00
2010-08-20 19:09:07 +02:00
/**
* Get rowid of the line relative to its position
* @ result int Rowid of the line
*/
function getIdOfLine ( $rang )
{
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $this -> table_element_line ;
$sql .= ' WHERE ' . $this -> fk_element . ' = ' . $this -> id ;
$sql .= ' AND rang = ' . $rang ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$row = $this -> db -> fetch_row ( $resql );
return $row [ 0 ];
}
}
2010-07-29 17:30:18 +02:00
2010-07-02 20:16:27 +02:00
/**
2010-08-18 09:28:12 +02:00
* Get max value used for position of line ( rang )
* @ result int Max value of rang in table of lines
2010-07-02 20:16:27 +02:00
*/
function line_max ()
{
$sql = 'SELECT max(rang) FROM ' . MAIN_DB_PREFIX . $this -> table_element_line ;
$sql .= ' WHERE ' . $this -> fk_element . ' = ' . $this -> id ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$row = $this -> db -> fetch_row ( $resql );
return $row [ 0 ];
}
}
2008-02-24 18:01:48 +01:00
/**
2009-02-20 23:53:15 +01:00
* \brief Update private note of element
* \param note New value for note
* \return int < 0 if KO , > 0 if OK
*/
2008-02-24 18:01:48 +01:00
function update_note ( $note )
{
if ( ! $this -> table_element )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_note was called on objet with property table_element not defined " , LOG_ERR );
2008-02-24 18:01:48 +01:00
return - 1 ;
}
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element ;
2010-02-03 17:57:23 +01:00
// TODO uniformize fields note_private
if ( $this -> table_element == 'fichinter' || $this -> table_element == 'projet' || $this -> table_element == 'projet_task' )
{
$sql .= " SET note_private = ' " . addslashes ( $note ) . " ' " ;
}
else
{
$sql .= " SET note = ' " . addslashes ( $note ) . " ' " ;
}
2008-02-24 18:01:48 +01:00
$sql .= " WHERE rowid = " . $this -> id ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_note sql= " . $sql , LOG_DEBUG );
2008-02-24 18:01:48 +01:00
if ( $this -> db -> query ( $sql ))
{
$this -> note = $note ;
return 1 ;
}
else
{
$this -> error = $this -> db -> error ();
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_note error= " . $this -> error , LOG_ERR );
2008-02-24 18:01:48 +01:00
return - 1 ;
}
}
/**
2009-02-20 23:53:15 +01:00
* \brief Update public note of element
* \param note_public New value for note
* \return int < 0 if KO , > 0 if OK
*/
2008-02-24 18:01:48 +01:00
function update_note_public ( $note_public )
{
if ( ! $this -> table_element )
{
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_note_public was called on objet with property table_element not defined " , LOG_ERR );
2008-02-24 18:01:48 +01:00
return - 1 ;
}
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element ;
$sql .= " SET note_public = ' " . addslashes ( $note_public ) . " ' " ;
$sql .= " WHERE rowid = " . $this -> id ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_note_public sql= " . $sql );
2008-02-24 18:01:48 +01:00
if ( $this -> db -> query ( $sql ))
{
$this -> note_public = $note_public ;
return 1 ;
}
else
{
$this -> error = $this -> db -> error ();
return - 1 ;
}
}
2008-03-07 11:34:16 +01:00
/**
2009-02-20 23:53:15 +01:00
* \brief Update total_ht , total_ttc and total_vat for an object ( sum of lines )
* \return int < 0 si ko , > 0 si ok
*/
2008-03-07 11:34:16 +01:00
function update_price ()
{
include_once ( DOL_DOCUMENT_ROOT . '/lib/price.lib.php' );
2009-02-16 22:37:28 +01:00
2008-03-07 11:34:16 +01:00
$err = 0 ;
// List lines to sum
$fieldtva = 'total_tva' ;
2010-06-17 21:36:46 +02:00
$fieldlocaltax1 = 'total_localtax1' ;
$fieldlocaltax2 = 'total_localtax2' ;
2010-07-29 17:30:18 +02:00
if ( $this -> element == 'facture_fourn' )
2010-06-17 21:36:46 +02:00
{
$fieldtva = 'tva' ;
}
2010-07-29 17:30:18 +02:00
2010-06-17 21:36:46 +02:00
$sql = 'SELECT qty, total_ht, ' . $fieldtva . ' as total_tva, ' . $fieldlocaltax1 . ' as total_localtax1, ' . $fieldlocaltax2 . ' as total_localtax2, total_ttc' ;
2008-03-07 11:34:16 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this -> table_element_line ;
$sql .= ' WHERE ' . $this -> fk_element . ' = ' . $this -> id ;
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_price sql= " . $sql );
2008-03-07 11:34:16 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$this -> total_ht = 0 ;
$this -> total_tva = 0 ;
2010-06-17 19:12:34 +02:00
$this -> total_localtax1 = 0 ;
$this -> total_localtax2 = 0 ;
2008-03-07 11:34:16 +01:00
$this -> total_ttc = 0 ;
2009-02-16 22:37:28 +01:00
2008-03-07 11:34:16 +01:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
$this -> total_ht += $obj -> total_ht ;
2008-03-19 00:24:24 +01:00
$this -> total_tva += $obj -> total_tva ;
2010-06-17 19:12:34 +02:00
$this -> total_localtax1 += $obj -> total_localtax1 ;
$this -> total_localtax2 += $obj -> total_localtax2 ;
2008-03-07 11:34:16 +01:00
$this -> total_ttc += $obj -> total_ttc ;
$i ++ ;
}
$this -> db -> free ( $resql );
// Now update field total_ht, total_ttc and tva
$fieldht = 'total_ht' ;
2010-07-29 17:30:18 +02:00
2008-03-07 11:34:16 +01:00
$fieldtva = 'tva' ;
2010-07-29 17:30:18 +02:00
2010-06-17 21:36:46 +02:00
$fieldlocaltax1 = 'localtax1' ;
$fieldlocaltax2 = 'localtax2' ;
2010-07-29 17:30:18 +02:00
2008-03-19 01:31:03 +01:00
$fieldttc = 'total_ttc' ;
2010-07-29 17:30:18 +02:00
2010-06-17 21:36:46 +02:00
if ( $this -> element == 'facture' || $this -> element == 'facturerec' )
{
$fieldht = 'total' ;
}
2010-07-29 17:30:18 +02:00
if ( $this -> element == 'facture_fourn' )
2010-06-17 21:36:46 +02:00
{
$fieldtva = 'total_tva' ;
}
2010-07-29 17:30:18 +02:00
2010-06-17 19:12:34 +02:00
if ( $this -> element == 'propal' )
{
$fieldttc = 'total' ;
}
2009-02-16 22:37:28 +01:00
2008-03-07 11:34:16 +01:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this -> table_element . ' SET' ;
$sql .= " " . $fieldht . " =' " . price2num ( $this -> total_ht ) . " ', " ;
$sql .= " " . $fieldtva . " =' " . price2num ( $this -> total_tva ) . " ', " ;
2010-06-17 19:12:34 +02:00
$sql .= " " . $fieldlocaltax1 . " =' " . price2num ( $this -> total_localtax1 ) . " ', " ;
$sql .= " " . $fieldlocaltax2 . " =' " . price2num ( $this -> total_localtax2 ) . " ', " ;
2008-03-19 01:31:03 +01:00
$sql .= " " . $fieldttc . " =' " . price2num ( $this -> total_ttc ) . " ' " ;
2008-03-07 11:34:16 +01:00
$sql .= ' WHERE rowid = ' . $this -> id ;
2008-03-19 01:31:03 +01:00
//print "xx".$sql;
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_price sql= " . $sql );
2008-03-07 11:34:16 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
return 1 ;
}
else
{
$this -> error = $this -> db -> error ();
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_price error= " . $this -> error , LOG_ERR );
2008-03-07 11:34:16 +01:00
return - 1 ;
}
}
else
{
$this -> error = $this -> db -> error ();
2009-02-20 23:53:15 +01:00
dol_syslog ( " CommonObject::update_price error= " . $this -> error , LOG_ERR );
2008-03-07 11:34:16 +01:00
return - 1 ;
}
2009-02-16 22:37:28 +01:00
}
2009-12-15 12:46:54 +01:00
2009-12-11 11:17:58 +01:00
/**
* Add objects linked in llx_element_element .
*/
2009-12-11 17:31:42 +01:00
function add_object_linked ()
2009-12-11 11:17:58 +01:00
{
2009-12-11 17:31:42 +01:00
$this -> db -> begin ();
2009-12-15 12:46:54 +01:00
2009-12-11 11:17:58 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " element_element ( " ;
$sql .= " fk_source " ;
$sql .= " , sourcetype " ;
$sql .= " , fk_target " ;
$sql .= " , targettype " ;
$sql .= " ) VALUES ( " ;
2009-12-11 17:31:42 +01:00
$sql .= $this -> origin_id ;
$sql .= " , ' " . $this -> origin . " ' " ;
$sql .= " , " . $this -> id ;
$sql .= " , ' " . $this -> element . " ' " ;
$sql .= " ) " ;
2009-12-15 12:46:54 +01:00
2009-12-11 17:31:42 +01:00
if ( $this -> db -> query ( $sql ))
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> error = $this -> db -> lasterror () . " - sql= $sql " ;
$this -> db -> rollback ();
return 0 ;
}
2009-12-11 11:17:58 +01:00
}
2009-06-04 21:42:34 +02:00
/**
* Load array of objects linked to current object . Links are loaded into this -> linked_object array .
*/
2009-12-12 21:41:27 +01:00
function load_object_linked ( $sourceid = '' , $sourcetype = '' , $targetid = '' , $targettype = '' )
2009-06-04 21:42:34 +02:00
{
$this -> linked_object = array ();
2009-12-15 12:46:54 +01:00
2009-12-12 21:41:27 +01:00
$sourceid = ( ! empty ( $sourceid ) ? $sourceid : $this -> id );
$targetid = ( ! empty ( $targetid ) ? $targetid : $this -> id );
$sourcetype = ( ! empty ( $sourcetype ) ? $sourcetype : $this -> origin );
$targettype = ( ! empty ( $targettype ) ? $targettype : $this -> element );
2009-06-04 21:42:34 +02:00
// Links beetween objects are stored in this table
2009-12-11 11:17:58 +01:00
$sql = 'SELECT fk_source, sourcetype, fk_target, targettype' ;
2009-06-04 21:42:34 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'element_element' ;
2009-12-12 21:41:27 +01:00
$sql .= " WHERE (fk_source = ' " . $sourceid . " ' AND sourcetype = ' " . $sourcetype . " ') " ;
$sql .= " OR (fk_target = ' " . $targetid . " ' AND targettype = ' " . $targettype . " ') " ;
2009-12-15 12:46:54 +01:00
2009-06-04 21:42:34 +02:00
dol_syslog ( " CommonObject::load_object_linked sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $resql );
2009-12-12 21:41:27 +01:00
if ( $obj -> fk_source == $sourceid )
2009-06-04 21:42:34 +02:00
{
2010-04-08 21:44:45 +02:00
$this -> linked_object [ $obj -> targettype ][] = $obj -> fk_target ;
2009-06-04 21:42:34 +02:00
}
2009-12-12 21:41:27 +01:00
if ( $obj -> fk_target == $targetid )
2009-06-04 21:42:34 +02:00
{
2010-04-08 21:44:45 +02:00
$this -> linked_object [ $obj -> sourcetype ][] = $obj -> fk_source ;
2009-06-04 21:42:34 +02:00
}
$i ++ ;
}
}
2009-06-04 22:29:45 +02:00
else
{
dol_print_error ( $this -> db );
}
2009-06-04 21:42:34 +02:00
}
2009-12-15 12:46:54 +01:00
2009-12-15 09:15:11 +01:00
/**
2009-12-15 12:46:54 +01:00
* \brief Set statut of an object
2009-12-15 09:15:11 +01:00
* \param statut Statut to set
2009-12-15 12:46:54 +01:00
* \param elementid Id of element to force ( use this -> id by default )
* \param elementtype Type of element to force ( use -> this -> element by default )
2009-12-15 09:15:11 +01:00
* \return int < 0 if ko , > 0 if ok
*/
function setStatut ( $statut , $elementId = '' , $elementType = '' )
{
$elementId = ( ! empty ( $elementId ) ? $elementId : $this -> id );
2010-05-13 01:03:33 +02:00
$elementTable = ( ! empty ( $elementType ) ? $elementType : $this -> table_element );
2009-12-15 12:46:54 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . $elementTable ;
2009-12-15 09:15:11 +01:00
$sql .= " SET fk_statut = " . $statut ;
$sql .= " WHERE rowid= " . $elementId ;
2009-12-15 12:46:54 +01:00
2009-12-15 09:15:11 +01:00
dol_syslog ( " CommonObject::setStatut sql= " . $sql , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
2009-12-15 12:46:54 +01:00
$this -> error = $this -> db -> lasterror ();
dol_syslog ( " CommonObject::setStatut " . $this -> error , LOG_ERR );
2009-12-15 09:15:11 +01:00
return - 1 ;
}
2009-12-15 12:46:54 +01:00
2009-12-15 09:15:11 +01:00
return 1 ;
}
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
/**
* \brief Fetch field list
*/
function getFieldList ()
{
global $conf , $langs ;
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
$this -> field_list = array ();
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
$sql = " SELECT rowid, name, alias, title, align, sort, search, enabled, rang " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_field_list " ;
2010-03-26 16:43:17 +01:00
$sql .= " WHERE element = ' " . $this -> fieldListName . " ' " ;
2010-03-25 12:25:10 +01:00
$sql .= " AND entity = " . $conf -> entity ;
$sql .= " ORDER BY rang ASC " ;
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$fieldlist = array ();
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
$fieldlist [ " id " ] = $obj -> rowid ;
$fieldlist [ " name " ] = $obj -> name ;
2010-03-26 16:43:17 +01:00
$fieldlist [ " alias " ] = $obj -> alias ;
2010-03-25 12:25:10 +01:00
$fieldlist [ " title " ] = $langs -> trans ( $obj -> title );
$fieldlist [ " align " ] = $obj -> align ;
$fieldlist [ " sort " ] = $obj -> sort ;
$fieldlist [ " search " ] = $obj -> search ;
$fieldlist [ " enabled " ] = verifCond ( $obj -> enabled );
$fieldlist [ " order " ] = $obj -> rang ;
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
array_push ( $this -> field_list , $fieldlist );
2010-04-24 15:39:16 +02:00
2010-03-25 12:25:10 +01:00
$i ++ ;
}
$this -> db -> free ( $resql );
}
else
{
print $sql ;
}
}
2010-08-18 09:28:12 +02:00
2010-08-05 11:12:07 +02:00
/**
2010-08-06 18:10:03 +02:00
* Instantiate hooks of thirdparty module
* @ param $type Type of hook
2010-08-05 11:12:07 +02:00
*/
2010-08-06 18:10:03 +02:00
function callHooks ( $type = 'objectcard' )
2010-08-05 11:12:07 +02:00
{
2010-08-06 18:10:03 +02:00
global $conf ;
2010-08-18 09:28:12 +02:00
2010-08-06 18:10:03 +02:00
foreach ( $conf -> hooks_modules as $module => $hooks )
{
if ( $conf -> $module -> enabled && in_array ( $type , $hooks ))
{
// Include class and library of thirdparty module
if ( file_exists ( DOL_DOCUMENT_ROOT . '/' . $module . '/class/' . $module . '.class.php' ))
{
require_once ( DOL_DOCUMENT_ROOT . '/' . $module . '/class/' . $module . '.class.php' );
}
if ( file_exists ( DOL_DOCUMENT_ROOT . '/' . $module . '/lib/' . $module . '.lib.php' ))
{
require_once ( DOL_DOCUMENT_ROOT . '/' . $module . '/lib/' . $module . '.lib.php' );
}
2010-08-18 09:28:12 +02:00
2010-08-06 18:10:03 +02:00
$classname = ucfirst ( $module );
$this -> objModules [] = new $classname ( $this -> db );
}
}
2010-08-05 11:12:07 +02:00
}
2010-08-18 09:28:12 +02:00
2010-08-05 11:12:07 +02:00
/**
* Show add predefined products / services form
*/
2010-08-05 11:45:59 +02:00
function showAddPredefinedProductForm ( $dateSelector = 0 )
2010-08-05 11:12:07 +02:00
{
global $conf , $langs ;
global $html , $bc , $var ;
include ( DOL_DOCUMENT_ROOT . '/core/tpl/addpredefinedproductform.tpl.php' );
}
2010-08-18 09:28:12 +02:00
2010-08-06 18:10:03 +02:00
/**
* Show add free products / services form
*/
function showAddFreeProductForm ( $dateSelector = 0 )
{
global $conf , $langs ;
global $html , $bc , $var ;
include ( DOL_DOCUMENT_ROOT . '/core/tpl/addfreeproductform.tpl.php' );
}
2010-04-24 15:39:16 +02:00
2010-04-08 21:44:45 +02:00
/**
2010-08-05 11:12:07 +02:00
* Show linked object block
* @ param $object
* @ param $objectid
* @ param $somethingshown
2010-04-08 21:44:45 +02:00
*/
function showLinkedObjectBlock ( $object , $objectid , $somethingshown = 0 )
{
2010-04-09 14:23:58 +02:00
global $langs , $bc ;
2010-04-24 15:39:16 +02:00
2010-04-09 08:20:10 +02:00
$num = sizeof ( $objectid );
if ( $num )
{
2010-04-09 14:23:58 +02:00
$classpath = $object . '/class' ;
$tplpath = $object ;
2010-05-26 00:22:24 +02:00
// TODO uniformiser emplacement classe
2010-04-29 08:20:03 +02:00
if ( $object == 'facture' ) $tplpath = 'compta/' . $object ; $classpath = $tplpath . '/class' ;
if ( $object == 'propal' ) $tplpath = 'comm/' . $object ; $classpath = $tplpath . '/class' ;
2010-04-24 15:39:16 +02:00
2010-04-09 09:55:37 +02:00
$classname = ucfirst ( $object );
2010-04-09 14:23:58 +02:00
if ( ! class_exists ( $classname )) require ( DOL_DOCUMENT_ROOT . " / " . $classpath . " / " . $object . " .class.php " );
2010-04-09 09:55:37 +02:00
$linkedObjectBlock = new $classname ( $this -> db );
2010-04-09 14:23:58 +02:00
include ( DOL_DOCUMENT_ROOT . '/' . $tplpath . '/tpl/linkedobjectblock.tpl.php' );
2010-04-09 08:47:13 +02:00
return $num ;
2010-04-09 08:20:10 +02:00
}
2010-04-08 21:44:45 +02:00
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
/**
* Return HTML table with title list
2010-08-18 09:28:12 +02:00
* TODO mettre le html dans un template
2010-08-10 00:39:20 +02:00
*/
function print_title_list ()
{
global $conf , $langs ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Description' ) . '</td>' ;
if ( $conf -> global -> PRODUIT_USE_MARKUP ) print '<td align="right" width="80">' . $langs -> trans ( 'Markup' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right" width="80">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'TotalHTShort' ) . '</td>' ;
print '<td width="48" colspan="3"> </td>' ;
print " </tr> \n " ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
/**
* Return HTML with object lines list
* @ param lines Object lines
*/
function printLinesList ( $lines , $dateSelector = 0 )
{
$num = count ( $lines );
$var = true ;
$i = 0 ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
foreach ( $lines as $line )
{
$var =! $var ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
$this -> printLine ( $line , $var , $num , $i , $dateSelector );
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
$i ++ ;
}
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
/**
* Return HTML with selected object line
* @ param line Selected object line
2010-08-18 09:28:12 +02:00
* TODO mettre le html dans un template
2010-08-10 00:39:20 +02:00
*/
function printLine ( $line , $var = true , $num = 0 , $i = 0 , $dateSelector = 0 )
{
global $conf , $langs , $user ;
global $html , $bc ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
$element = $this -> element ;
// TODO uniformiser
if ( $element == 'propal' ) $element = 'propale' ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Show product and description
$type = $line -> product_type ? $line -> product_type : $line -> fk_product_type ;
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if ( ! empty ( $line -> date_start )) $type = 1 ;
if ( ! empty ( $line -> date_end )) $type = 1 ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Ligne en mode visu
if ( $_GET [ 'action' ] != 'editline' || $_GET [ 'lineid' ] != $line -> id )
{
print '<tr ' . $bc [ $var ] . '>' ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Produit
if ( $line -> fk_product > 0 )
{
$product_static = new Product ( $db );
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
print '<td>' ;
print '<a name="' . $line -> id . '"></a>' ; // ancre pour retourner sur la ligne;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Show product and description
$product_static -> type = $line -> fk_product_type ;
$product_static -> id = $line -> fk_product ;
$product_static -> ref = $line -> ref ;
$product_static -> libelle = $line -> product_label ;
$text = $product_static -> getNomUrl ( 1 );
$text .= ' - ' . $line -> product_label ;
$description = ( $conf -> global -> PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr ( $line -> description ));
print $html -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Show range
print_date_range ( $line -> date_start , $line -> date_end );
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Add description in form
if ( $conf -> global -> PRODUIT_DESC_IN_FORM )
{
print ( $line -> description && $line -> description != $line -> product_label ) ? '<br>' . dol_htmlentitiesbr ( $line -> description ) : '' ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
print '</td>' ;
}
else
{
print '<td>' ;
print '<a name="' . $line -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
if (( $line -> info_bits & 2 ) == 2 )
{
print '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $this -> socid . '">' ;
print img_object ( $langs -> trans ( " ShowReduc " ), 'reduc' ) . ' ' . $langs -> trans ( " Discount " );
print '</a>' ;
if ( $line -> description )
{
if ( $line -> description == '(CREDIT_NOTE)' )
{
2010-08-15 17:39:55 +02:00
$discount = new DiscountAbsolute ( $this -> db );
2010-08-10 00:39:20 +02:00
$discount -> fetch ( $line -> fk_remise_except );
print ' - ' . $langs -> transnoentities ( " DiscountFromCreditNote " , $discount -> getNomUrl ( 0 ));
}
else
{
print ' - ' . nl2br ( $line -> description );
}
}
}
else
{
if ( $type == 1 ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
print $text . ' ' . nl2br ( $line -> description );
// Show range
print_date_range ( $line -> date_start , $line -> date_end );
}
print " </td> \n " ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// VAT Rate
print '<td align="right" nowrap="nowrap">' . vatrate ( $line -> tva_tx , '%' , $line -> info_bits ) . '</td>' ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// U.P HT
print '<td align="right" nowrap="nowrap">' . price ( $line -> subprice ) . " </td> \n " ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Qty
print '<td align="right" nowrap="nowrap">' ;
if ((( $line -> info_bits & 2 ) != 2 ) && $line -> special_code != 3 )
{
print $line -> qty ;
}
else print ' ' ;
print '</td>' ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Remise percent (negative or positive)
if ( ! empty ( $line -> remise_percent ) && $line -> special_code != 3 )
{
print '<td align="right">' . dol_print_reduction ( $line -> remise_percent , $langs ) . " </td> \n " ;
}
else
{
print '<td> </td>' ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Montant total HT
if ( $line -> special_code == 3 )
{
// Si ligne en option
print '<td align="right" nowrap="nowrap">' . $langs -> trans ( 'Option' ) . '</td>' ;
}
else
{
print '<td align="right" nowrap="nowrap">' . price ( $line -> total_ht ) . " </td> \n " ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Icone d'edition et suppression
if ( $this -> statut == 0 && $user -> rights -> $element -> creer )
{
print '<td align="center">' ;
if (( $line -> info_bits & 2 ) == 2 )
{
// Ligne remise predefinie, on permet pas modif
}
else
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=editline&lineid=' . $line -> id . '#' . $line -> id . '">' ;
print img_edit ();
print '</a>' ;
}
print '</td>' ;
print '<td align="center">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=ask_deleteline&lineid=' . $line -> id . '">' ;
print img_delete ();
print '</a></td>' ;
if ( $num > 1 )
{
print '<td align="center">' ;
if ( $i > 0 )
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=up&rowid=' . $line -> id . '">' ;
print img_up ();
print '</a>' ;
}
if ( $i < $num - 1 )
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=down&rowid=' . $line -> id . '">' ;
print img_down ();
print '</a>' ;
}
print '</td>' ;
}
}
else
{
print '<td colspan="3"> </td>' ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
print '</tr>' ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Ligne en mode update
if ( $this -> statut == 0 && $_GET [ " action " ] == 'editline' && $user -> rights -> propale -> creer && $_GET [ " lineid " ] == $line -> id )
{
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '#' . $line -> id . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="updateligne">' ;
print '<input type="hidden" name="id" value="' . $this -> id . '">' ;
print '<input type="hidden" name="lineid" value="' . $_GET [ " lineid " ] . '">' ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td>' ;
print '<a name="' . $line -> id . '"></a>' ; // ancre pour retourner sur la ligne
if ( $line -> fk_product > 0 )
{
print '<input type="hidden" name="productid" value="' . $line -> fk_product . '">' ;
print '<a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $line -> fk_product . '">' ;
if ( $line -> fk_product_type == 1 ) print img_object ( $langs -> trans ( 'ShowService' ), 'service' );
else print img_object ( $langs -> trans ( 'ShowProduct' ), 'product' );
print ' ' . $line -> ref . '</a>' ;
print ' - ' . nl2br ( $line -> product_label );
print '<br>' ;
}
if ( $_GET [ " action " ] == 'editline' )
{
// editeur wysiwyg
if ( $conf -> fckeditor -> enabled && $conf -> global -> FCKEDITOR_ENABLE_DETAILS )
{
require_once ( DOL_DOCUMENT_ROOT . " /lib/doleditor.class.php " );
$doleditor = new DolEditor ( 'desc' , $line -> description , 164 , 'dolibarr_details' );
$doleditor -> Create ();
}
else
{
$nbrows = ROWS_2 ;
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) $nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
print '<textarea name="desc" cols="70" class="flat" rows="' . $nbrows . '">' . dol_htmlentitiesbr_decode ( $line -> description ) . '</textarea>' ;
}
}
print '</td>' ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// TODO a déplacer dans classe module marge
//if ($conf->global->PRODUIT_USE_MARKUP) print '<td align="right">'.vatrate($line->marge_tx).'%</td>';
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
print '<td align="right">' ;
print $html -> select_tva ( 'tva_tx' , $line -> tva_tx , $mysoc , $societe , '' , $line -> info_bits );
print '</td>' ;
print '<td align="right"><input size="6" type="text" class="flat" name="subprice" value="' . price ( $line -> subprice , 0 , '' , 0 ) . '"></td>' ;
print '<td align="right">' ;
if (( $line -> info_bits & 2 ) != 2 )
{
print '<input size="2" type="text" class="flat" name="qty" value="' . $line -> qty . '">' ;
}
else print ' ' ;
print '</td>' ;
print '<td align="right" nowrap>' ;
if (( $line -> info_bits & 2 ) != 2 )
{
print '<input size="1" type="text" class="flat" name="remise_percent" value="' . $line -> remise_percent . '">%' ;
}
else print ' ' ;
print '</td>' ;
print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
print '<br><input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"></td>' ;
print '</tr>' . " \n " ;
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
// Start and end dates selector
if ( $conf -> service -> enabled && $dateSelector )
{
print '<tr ' . $bc [ $var ] . '>' ;
print '<td colspan="9">' . $langs -> trans ( 'ServiceLimitedDuration' ) . ' ' . $langs -> trans ( 'From' ) . ' ' ;
print $html -> select_date ( $line -> date_start , 'date_start' , $usehm , $usehm , $line -> date_start ? 0 : 1 , " updateligne " );
print ' ' . $langs -> trans ( 'to' ) . ' ' ;
print $html -> select_date ( $line -> date_end , 'date_end' , $usehm , $usehm , $line -> date_end ? 0 : 1 , " updateligne " );
print '</td>' ;
print '</tr>' ;
}
2010-08-18 09:28:12 +02:00
2010-08-10 00:39:20 +02:00
print " </form> \n " ;
}
}
2009-06-04 21:42:34 +02:00
2006-06-18 17:06:29 +02:00
}
?>