diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index daad3e51e16..d9f8daa9882 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -41,6 +41,11 @@ abstract class CommonObject
*/
public $db;
+ /**
+ * @var int The object identifier
+ */
+ public $id;
+
/**
* @var string Error string
* @deprecated Use instead the array of error strings
@@ -92,33 +97,245 @@ abstract class CommonObject
*/
public $canvas;
-
- public $name;
- public $lastname;
- public $firstname;
- public $civility_id;
/**
- * @deprecated
- * @see thirdparty
+ * @var Project The related project
+ * @see fetch_projet()
*/
- public $client;
+ public $project;
/**
- * @var Societe
+ * @var int The related project ID
+ * @see setProject(), project
*/
- public $thirdparty;
+ public $fk_project;
/**
* @deprecated
* @see project
*/
public $projet;
+
/**
- * @var Project
+ * @var Contact a related contact
+ * @see fetch_contact()
*/
- public $project;
+ public $contact;
+ /**
+ * @var int The related contact ID
+ * @see fetch_contact()
+ */
+ public $contact_id;
+
+ /**
+ * @var Societe A related thirdparty
+ * @see fetch_thirdparty()
+ */
+ public $thirdparty;
+ /**
+ * @deprecated
+ * @see thirdparty
+ */
+ public $client;
+
+ /**
+ * @var User A related user
+ * @see fetch_user()
+ */
+ public $user;
+
+ /**
+ * @var CommonObject An originating object?
+ * @see fetch_origin()
+ */
+ public $origin;
+ /**
+ * @var int The originating object?
+ * @see fetch_origin(), origin
+ */
+ public $origin_id;
+
+ /**
+ * @var string The object's reference
+ */
+ public $ref;
+ /**
+ * @var string The object's previous reference
+ */
+ public $ref_previous;
+ /**
+ * @var string The object's next reference
+ */
+ public $ref_next;
+ /**
+ * @var string An external reference for the object
+ */
+ public $ref_ext;
+
+ /**
+ * @var string
+ */
+ public $element;
+ /**
+ * @var string
+ */
+ public $table_element;
+ /**
+ * @var
+ */
+ public $table_element_line;
+
+ /**
+ * @var int The object's status
+ * @see setStatut()
+ */
+ public $statut;
+
+ /**
+ * @var string
+ * @see getFullAddress()
+ */
+ public $country;
+ /**
+ * @var int
+ * @see getFullAddress(), country
+ */
+ public $country_id;
+ /**
+ * @var string
+ * @see getFullAddress(), isInEEC(), country
+ */
+ public $country_code;
+
+ /**
+ * @var int
+ * @see fetch_barcode()
+ */
+ public $barcode_type;
+ /**
+ * @var string
+ * @see fetch_barcode(), barcode_type
+ */
+ public $barcode_type_code;
+ /**
+ * @var string
+ * @see fetch_barcode(), barcode_type
+ */
+ public $barcode_type_label;
+ /**
+ * @var string
+ * @see fetch_barcode(), barcode_type
+ */
+ public $barcode_type_coder;
+
+ /**
+ * @var int Payment method ID?
+ * @see setPaymentMethods()
+ */
+ public $mode_reglement_id;
+
+ /**
+ * @var string Payment terms ID
+ * @see setPaymentTerms()
+ */
+ public $cond_reglement_id;
+ /**
+ * @deprecated
+ * @see cond_reglement_id;
+ */
+ public $cond_reglement;
+
+ /**
+ * @var int Delivery address ID
+ * @see setDeliveryAddress()
+ */
+ public $fk_delivery_address;
+
+ /**
+ * @var int Shipping method ID
+ * @see setShippingMethod()
+ */
+ public $shipping_method_id;
+
+ /**
+ * @var string
+ * @see SetDocModel()
+ */
+ public $modelpdf;
+
+ /**
+ * @var int Bank account ID
+ * @see SetBankAccount()
+ */
+ public $fk_account;
+
+ /**
+ * @var string Public note
+ * @see update_note()
+ */
+ public $note_public;
+ /**
+ * @var string Private note
+ * @see update_note()
+ */
+ public $note_private;
+ /**
+ * @deprecated
+ * @see note_public
+ */
+ public $note;
+
+ /**
+ * @var float
+ * @see update_price()
+ */
+ public $total_ht;
+ /**
+ * @var float
+ * @see update_price()
+ */
+ public $total_tva;
+ /**
+ * @var float
+ * @see update_price()
+ */
+ public $total_localtax1;
+ /**
+ * @var float
+ * @see update_price()
+ */
+ public $total_localtax2;
+ /**
+ * @var float
+ * @see update_price()
+ */
+ public $total_ttc;
+
+ /**
+ * @var CommonObjectLine[]
+ */
+ public $lines;
+
+ /**
+ * @var int
+ * @see setIncoterms()
+ */
+ public $fk_incoterms;
+ /**
+ * @var string
+ * @see SetIncoterms()
+ */
+ public $libelle_incoterms;
+ /**
+ * @var string
+ * @see display_incoterms()
+ */
+ public $location_incoterms;
+
+ public $name;
+ public $lastname;
+ public $firstname;
+ public $civility_id;
// No constructor as it is an abstract class
-
/**
* Check an object id/ref exists
* If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch
@@ -178,8 +395,6 @@ abstract class CommonObject
*/
function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0)
{
- global $conf;
-
//print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."
\n";
$lastname=$this->lastname;
$firstname=$this->firstname;
@@ -223,13 +438,13 @@ abstract class CommonObject
*
* @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link
* @param int $type_contact Type of contact (code or id). Must be if or code found into table llx_c_type_contact. For example: SALESREPFOLL
- * @param int $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
+ * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
* @param int $notrigger Disable all triggers
* @return int <0 if KO, >0 if OK
*/
function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0)
{
- global $user,$conf,$langs;
+ global $user,$langs;
dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source");
@@ -321,8 +536,6 @@ abstract class CommonObject
*/
function copy_linked_contact($objFrom, $source='internal')
{
- global $user,$langs,$conf;
-
$contacts = $objFrom->liste_contact(-1, $source);
foreach($contacts as $contact)
{
@@ -373,7 +586,7 @@ abstract class CommonObject
*/
function delete_contact($rowid, $notrigger=0)
{
- global $user,$langs,$conf;
+ global $user;
$this->db->begin();
@@ -545,7 +758,7 @@ abstract class CommonObject
* Return array with list of possible values for type of contacts
*
* @param string $source 'internal', 'external' or 'all'
- * @param string $order Sort order by 'code' or 'rowid'
+ * @param string $order Sort order by : 'code' or 'rowid'
* @param int $option 0=Return array id->label, 1=Return array code->label
* @param int $activeonly 0=all status of contact, 1=only the active
* @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE')
@@ -769,7 +982,7 @@ abstract class CommonObject
}
}
}
- else return 0;
+ return 0;
}
/**
@@ -891,10 +1104,8 @@ abstract class CommonObject
* @param User|string $user Update last update fields also if user object provided
* @return int <0 if KO, >0 if OK
*/
- function setValueFrom($field, $value, $table='', $id='', $format='', $id_field='', $user='')
+ function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $user='')
{
- global $conf;
-
if (empty($table)) $table=$this->table_element;
if (empty($id)) $id=$this->id;
if (empty($format)) $format='text';
@@ -933,7 +1144,7 @@ abstract class CommonObject
*/
function load_previous_next_ref($filter,$fieldid,$nodbprefix=0)
{
- global $conf, $user;
+ global $user;
if (! $this->table_element)
{
@@ -1253,6 +1464,8 @@ abstract class CommonObject
}
}
+ // TODO: Move line related operations to CommonObjectLine?
+
/**
* Save a new position (field rang) for details lines.
* You can choose to set position for lines with already a position or lines without any position defined.
@@ -1918,7 +2131,7 @@ abstract class CommonObject
* @return void
* @see add_object_linked, updateObjectLinked, deleteObjectLinked
*/
- function fetchObjectLinked($sourceid='',$sourcetype='',$targetid='',$targettype='',$clause='OR',$alsosametype=1)
+ function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1)
{
global $conf;
@@ -1948,7 +2161,7 @@ abstract class CommonObject
if (empty($sourceid) && empty($targetid))
{
- dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERROR);
+ dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR);
return -1;
}
@@ -2082,7 +2295,7 @@ abstract class CommonObject
* @return int >0 if OK, <0 if KO
* @see add_object_linked, fetObjectLinked, deleteObjectLinked
*/
- function updateObjectLinked($sourceid='', $sourcetype='', $targetid='', $targettype='')
+ function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='')
{
$updatesource=false;
$updatetarget=false;
@@ -2128,7 +2341,7 @@ abstract class CommonObject
* @return int >0 if OK, <0 if KO
* @see add_object_linked, updateObjectLinked, fetchObjectLinked
*/
- function deleteObjectLinked($sourceid='', $sourcetype='', $targetid='', $targettype='')
+ function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='')
{
$deletesource=false;
$deletetarget=false;
@@ -2180,7 +2393,7 @@ abstract class CommonObject
* @param string $elementType Type of element to force (use this->table_element by default)
* @return int <0 if KO, >0 if OK
*/
- function setStatut($status,$elementId='',$elementType='')
+ function setStatut($status,$elementId=null,$elementType='')
{
global $user,$langs,$conf;
@@ -2324,7 +2537,6 @@ abstract class CommonObject
foreach($this->childtables as $table)
{
// Check if third party can be deleted
- $nb=0;
$sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table;
$sql.= " WHERE ".$this->fk_element." = ".$id;
$resql=$this->db->query($sql);
@@ -2398,10 +2610,9 @@ abstract class CommonObject
$pu_ht = $obj->pu_ht;
$qty= $obj->qty;
- $discount_percent_line = $obj->remise_percent;
$total_ht = $obj->total_ht;
- $total_discount_line = price2num(($pu_ht * $qty) - $total_ht, 'MT');
+ $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT'));
$total_discount += $total_discount_line;
$i++;
@@ -2451,7 +2662,7 @@ abstract class CommonObject
function display_incoterms()
{
$out = '';
- $this->incoterms_libelle = '';
+ $this->libelle_incoterms = '';
if (!empty($this->fk_incoterms))
{
$sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms;
@@ -2640,8 +2851,8 @@ abstract class CommonObject
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
*
* @param string $action Action code
- * @param Societe $seller Object of seller third party
- * @param Societe $buyer Object of buyer third party
+ * @param string $seller Object of seller third party
+ * @param string $buyer Object of buyer third party
* @param int $selected Object line selected
* @param int $dateSelector 1=Show also date range input fields
* @return void
@@ -2734,12 +2945,12 @@ abstract class CommonObject
if (empty($line->fk_parent_line))
{
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
- $reshook=$hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
else
{
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
- $reshook=$hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
+ $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
}
else
@@ -2755,16 +2966,16 @@ abstract class CommonObject
* Return HTML content of a detail line
* TODO Move this into an output class file (htmlline.class.php)
*
- * @param string $action GET/POST action
- * @param CommonObjectLine $line Selected object line to output
- * @param string $var Is it a an odd line (true)
- * @param int $num Number of line (0)
- * @param int $i I
- * @param int $dateSelector 1=Show also date range input fields
- * @param Societe $seller Object of seller third party
- * @param Societe $buyer Object of buyer third party
- * @param int $selected Object line selected
- * @param object $extrafieldsline Object of extrafield line attribute
+ * @param string $action GET/POST action
+ * @param CommonObjectLine $line Selected object line to output
+ * @param string $var Is it a an odd line (true)
+ * @param int $num Number of line (0)
+ * @param int $i I
+ * @param int $dateSelector 1=Show also date range input fields
+ * @param string $seller Object of seller third party
+ * @param string $buyer Object of buyer third party
+ * @param int $selected Object line selected
+ * @param int $extrafieldsline Object of extrafield line attribute
* @return void
*/
function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0)
@@ -2895,7 +3106,6 @@ abstract class CommonObject
}
print '