--- /tmp/dsg/dolibarr/htdocs/societe/class/github_api_contacts.class.php +++ /tmp/dsg/dolibarr/htdocs/societe/class/client_api_contacts.class.php @@ -46,7 +46,7 @@ /** * Constructor */ - public function __construct() + public function __construct() { global $db, $conf; $this->db = $db; @@ -64,12 +64,11 @@ * * @param int $id ID of contact * @param int $includecount Count and return also number of elements the contact is used as a link for - * @param int $includeroles Includes roles of the contact * @return array|mixed data without useless information * * @throws RestException */ - public function get($id, $includecount = 0, $includeroles = 0) + public function get($id, $includecount = 0) { if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { @@ -93,60 +92,7 @@ if ($includecount) { - $this->contact->load_ref_elements(); - } - - if ($includeroles) - { - $this->contact->fetchRoles(); - } - - return $this->_cleanObjectDatas($this->contact); - } - - /** - * Get properties of a contact object by Email - * - * @param string $email Email of contact - * @param int $includecount Count and return also number of elements the contact is used as a link for - * @param int $includeroles Includes roles of the contact - * @return array|mixed data without useless information - * - * @url GET email/{email} - * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 User or group not found - */ - public function getByEmail($email, $includecount = 0, $includeroles = 0) - { - if (!DolibarrApiAccess::$user->rights->societe->contact->lire) - { - throw new RestException(401, 'No permission to read contacts'); - } - if (empty($email)) { - $result = $this->contact->initAsSpecimen(); - } else { - $result = $this->contact->fetch('', '', '', $email); - } - - if (!$result) - { - throw new RestException(404, 'Contact not found'); - } - - if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) - { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if ($includecount) - { - $this->contact->load_ref_elements(); - } - - if ($includeroles) - { - $this->contact->fetchRoles(); + $this->contact->load_ref_elements(); } return $this->_cleanObjectDatas($this->contact); @@ -162,26 +108,25 @@ * @param int $limit Limit for list * @param int $page Page number * @param string $thirdparty_ids Thirdparty ids to filter contacts of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} - * @param int $category Use this param to filter list by category + * @param int $category Use this param to filter list by category * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" * @param int $includecount Count and return also number of elements the contact is used as a link for - * @param int $includeroles Includes roles of the contact * @return array Array of contact objects - * + * * @throws RestException - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $includecount = 0, $includeroles = 0) - { + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $includecount = 0) + { global $db, $conf; $obj_ret = array(); if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { - throw new RestException(401, 'No permission to read contacts'); - } - - // case of external user, $thirdparty_ids param is ignored and replaced by user's socid + throw new RestException(401, 'No permission to read contacts'); + } + + // case of external user, $thirdparty_ids param is ignored and replaced by user's socid $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids; // If the internal user must only see his customers, force searching by him @@ -191,9 +136,9 @@ $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t"; - if ($category > 0) { + if ($category > 0) { $sql .= ", ".MAIN_DB_PREFIX."categorie_contact as c"; - } + } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as te ON te.fk_object = t.rowid"; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { // We need this table joined to the select in order to filter by sale @@ -213,24 +158,24 @@ $sql .= " AND sc.fk_user = ".$search_sale; } - // Select contacts of given category - if ($category > 0) { - $sql .= " AND c.fk_categorie = ".$this->db->escape($category); + // Select contacts of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category); $sql .= " AND c.fk_socpeople = t.rowid "; - } - - // Add sql filters - if ($sqlfilters) - { - if (!DolibarrApi::_checkFilters($sqlfilters)) - { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); - } - $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; - } - - $sql .= $this->db->order($sortfield, $sortorder); + } + + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); if ($limit) { @@ -240,36 +185,31 @@ } $offset = $limit * $page; - $sql .= $this->db->plimit($limit + 1, $offset); - } - $result = $this->db->query($sql); + $sql .= $db->plimit($limit + 1, $offset); + } + $result = $db->query($sql); if ($result) { - $num = $this->db->num_rows($result); + $num = $db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); - $i = 0; + $i = 0; while ($i < $min) { - $obj = $this->db->fetch_object($result); - $contact_static = new Contact($this->db); + $obj = $db->fetch_object($result); + $contact_static = new Contact($db); if ($contact_static->fetch($obj->rowid)) { - $contact_static->fetchRoles(); - if ($includecount) - { - $contact_static->load_ref_elements(); - } - if ($includeroles) - { - $contact_static->fetchRoles(); - } - + if ($includecount) + { + $contact_static->load_ref_elements(); + } $obj_ret[] = $this->_cleanObjectDatas($contact_static); } $i++; } - } else { + } + else { throw new RestException(503, 'Error when retrieve contacts : '.$sql); } if (!count($obj_ret)) @@ -285,8 +225,8 @@ * @param array $request_data Request datas * @return int ID of contact */ - public function post($request_data = null) - { + public function post($request_data = null) + { if (!DolibarrApiAccess::$user->rights->societe->contact->creer) { throw new RestException(401, 'No permission to create/update contacts'); @@ -299,7 +239,7 @@ $this->contact->$field = $value; } if ($this->contact->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, "Error creating contact", array_merge(array($this->contact->error), $this->contact->errors)); + throw new RestException(500, "Error creating contact", array_merge(array($this->contact->error), $this->contact->errors)); } return $this->contact->id; } @@ -311,8 +251,8 @@ * @param array $request_data Datas * @return int */ - public function put($id, $request_data = null) - { + public function put($id, $request_data = null) + { if (!DolibarrApiAccess::$user->rights->societe->contact->creer) { throw new RestException(401, 'No permission to create/update contacts'); @@ -331,8 +271,8 @@ foreach ($request_data as $field => $value) { - if ($field == 'id') continue; - $this->contact->$field = $value; + if ($field == 'id') continue; + $this->contact->$field = $value; } if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) @@ -347,8 +287,8 @@ * @param int $id Contact ID * @return integer */ - public function delete($id) - { + public function delete($id) + { if (!DolibarrApiAccess::$user->rights->societe->contact->supprimer) { throw new RestException(401, 'No permission to delete contacts'); @@ -363,7 +303,7 @@ { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $this->contact->oldcopy = clone $this->contact; + $this->contact->oldcopy = clone $this->contact; return $this->contact->delete(); } @@ -376,62 +316,62 @@ * * @url POST {id}/createUser */ - public function createUser($id, $request_data = null) - { - //if (!DolibarrApiAccess::$user->rights->user->user->creer) { - //throw new RestException(401); - //} - - if (!isset($request_data["login"])) - throw new RestException(400, "login field missing"); - if (!isset($request_data["password"])) - throw new RestException(400, "password field missing"); - - if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { - throw new RestException(401, 'No permission to read contacts'); - } - if (!DolibarrApiAccess::$user->rights->user->user->creer) { - throw new RestException(401, 'No permission to create user'); - } - - $contact = new Contact($this->db); - $contact->fetch($id); - if ($contact->id <= 0) { - throw new RestException(404, 'Contact not found'); - } - - if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - // Check mandatory fields - $login = $request_data["login"]; - $password = $request_data["password"]; - $useraccount = new User($this->db); - $result = $useraccount->create_from_contact($contact, $login, $password); - if ($result <= 0) { - throw new RestException(500, "User not created"); - } - // password parameter not used in create_from_contact - $useraccount->setPassword($useraccount, $password); - - return $result; - } - - /** - * Get categories for a contact - * - * @param int $id ID of contact - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * - * @return mixed - * - * @url GET {id}/categories - */ - public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + public function createUser($id, $request_data = null) + { + //if (!DolibarrApiAccess::$user->rights->user->user->creer) { + //throw new RestException(401); + //} + + if (!isset($request_data["login"])) + throw new RestException(400, "login field missing"); + if (!isset($request_data["password"])) + throw new RestException(400, "password field missing"); + + if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { + throw new RestException(401, 'No permission to read contacts'); + } + if (!DolibarrApiAccess::$user->rights->user->user->creer) { + throw new RestException(401, 'No permission to create user'); + } + + $contact = new Contact($this->db); + $contact->fetch($id); + if ($contact->id <= 0) { + throw new RestException(404, 'Contact not found'); + } + + if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + // Check mandatory fields + $login = $request_data["login"]; + $password = $request_data["password"]; + $useraccount = new User($this->db); + $result = $useraccount->create_from_contact($contact, $login, $password); + if ($result <= 0) { + throw new RestException(500, "User not created"); + } + // password parameter not used in create_from_contact + $useraccount->setPassword($useraccount, $password); + + return $result; + } + + /** + * Get categories for a contact + * + * @param int $id ID of contact + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * + * @return mixed + * + * @url GET {id}/categories + */ + public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { if (!DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); @@ -450,131 +390,131 @@ } return $result; - } - - /** - * Add a category to a contact - * - * @url POST {id}/categories/{category_id} - * - * @param int $id Id of contact - * @param int $category_id Id of category - * - * @return mixed - * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 Category or contact not found - */ - public function addCategory($id, $category_id) - { - if (!DolibarrApiAccess::$user->rights->societe->contact->creer) { - throw new RestException(401, 'Insufficient rights'); - } - - $result = $this->contact->fetch($id); - if (!$result) { - throw new RestException(404, 'Contact not found'); - } - $category = new Categorie($this->db); - $result = $category->fetch($category_id); - if (!$result) { - throw new RestException(404, 'category not found'); - } - - if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $category->add_type($this->contact, 'contact'); - - return $this->_cleanObjectDatas($this->contact); - } - - /** - * Remove the link between a category and a contact - * - * @url DELETE {id}/categories/{category_id} - * - * @param int $id Id of contact - * @param int $category_id Id of category - * @return mixed - * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 Category or contact not found - */ - public function deleteCategory($id, $category_id) - { - if (!DolibarrApiAccess::$user->rights->societe->contact->creer) { - throw new RestException(401, 'Insufficient rights'); - } - - $result = $this->contact->fetch($id); - if (!$result) { - throw new RestException(404, 'Contact not found'); - } - $category = new Categorie($this->db); - $result = $category->fetch($category_id); - if (!$result) { - throw new RestException(404, 'category not found'); - } - - if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $category->del_type($this->contact, 'contact'); - - return $this->_cleanObjectDatas($this->contact); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore - /** - * Clean sensible object datas - * - * @param Object $object Object to clean - * @return Object Object with cleaned properties - */ - protected function _cleanObjectDatas($object) - { - // phpcs:enable - $object = parent::_cleanObjectDatas($object); - - unset($object->total_ht); - unset($object->total_tva); - unset($object->total_localtax1); - unset($object->total_localtax2); - unset($object->total_ttc); - - unset($object->note); - unset($object->lines); - unset($object->thirdparty); - - return $object; - } - - /** - * Validate fields before create or update object - * - * @param array|null $data Data to validate - * @return array - * @throws RestException - */ - private function _validate($data) - { - $contact = array(); - foreach (Contacts::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $contact[$field] = $data[$field]; - } - - return $contact; - } + } + + /** + * Add a category to a contact + * + * @url POST {id}/categories/{category_id} + * + * @param int $id Id of contact + * @param int $category_id Id of category + * + * @return mixed + * + * @throws RestException 401 Insufficient rights + * @throws RestException 404 Category or contact not found + */ + public function addCategory($id, $category_id) + { + if (!DolibarrApiAccess::$user->rights->societe->contact->creer) { + throw new RestException(401, 'Insufficient rights'); + } + + $result = $this->contact->fetch($id); + if (!$result) { + throw new RestException(404, 'Contact not found'); + } + $category = new Categorie($this->db); + $result = $category->fetch($category_id); + if (!$result) { + throw new RestException(404, 'category not found'); + } + + if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $category->add_type($this->contact, 'contact'); + + return $this->_cleanObjectDatas($this->contact); + } + + /** + * Remove the link between a category and a contact + * + * @url DELETE {id}/categories/{category_id} + * + * @param int $id Id of contact + * @param int $category_id Id of category + * @return mixed + * + * @throws RestException 401 Insufficient rights + * @throws RestException 404 Category or contact not found + */ + public function deleteCategory($id, $category_id) + { + if (!DolibarrApiAccess::$user->rights->societe->contact->creer) { + throw new RestException(401, 'Insufficient rights'); + } + + $result = $this->contact->fetch($id); + if (!$result) { + throw new RestException(404, 'Contact not found'); + } + $category = new Categorie($this->db); + $result = $category->fetch($category_id); + if (!$result) { + throw new RestException(404, 'category not found'); + } + + if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $category->del_type($this->contact, 'contact'); + + return $this->_cleanObjectDatas($this->contact); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + /** + * Clean sensible object datas + * + * @param Object $object Object to clean + * @return array Array of cleaned object properties + */ + protected function _cleanObjectDatas($object) + { + // phpcs:enable + $object = parent::_cleanObjectDatas($object); + + unset($object->total_ht); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + unset($object->total_ttc); + + unset($object->note); + unset($object->lines); + unset($object->thirdparty); + + return $object; + } + + /** + * Validate fields before create or update object + * + * @param array|null $data Data to validate + * @return array + * @throws RestException + */ + private function _validate($data) + { + $contact = array(); + foreach (Contacts::$FIELDS as $field) { + if (!isset($data[$field])) { + throw new RestException(400, "$field field missing"); + } + $contact[$field] = $data[$field]; + } + + return $contact; + } } --- /tmp/dsg/dolibarr/htdocs/societe/class/github_api_thirdparties.class.php +++ /tmp/dsg/dolibarr/htdocs/societe/class/client_api_thirdparties.class.php @@ -2,7 +2,6 @@ /* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2018 Pierre Chéné <pierre.chene44@gmail.com> * Copyright (C) 2019 Cedric Ancelin <icedo.anc@gmail.com> - * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr> * * 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 @@ -20,6 +19,7 @@ use Luracast\Restler\RestException; + /** * API class for thirdparties * @@ -45,7 +45,7 @@ /** * Constructor */ - public function __construct() + public function __construct() { global $db, $conf; $this->db = $db; @@ -67,48 +67,31 @@ * * Return an array with thirdparty informations * - * @param int $id Id of third party to load - * @return array|mixed Cleaned Societe object + * @param int $id ID of thirdparty + * @return array|mixed data without useless information * * @throws RestException */ - public function get($id) - { - return $this->_fetch($id); - } + public function get($id) + { + return $this->_fetch($id); + } /** * Get properties of a thirdparty object by email. * * Return an array with thirdparty informations * - * @param string $email Email of third party to load - * @return array|mixed Cleaned Societe object - * - * @url GET email/{email} + * @param string $email Sort field + * @return array|mixed data without useless information + * + * @url GET byEmail/{email} * * @throws RestException */ public function getByEmail($email) { - return $this->_fetch('', '', '', '', '', '', '', '', '', '', $email); - } - - /** - * Get properties of a thirdparty object by barcode. - * - * Return an array with thirdparty informations - * - * @param string $barcode Barcode of third party to load - * @return array|mixed Cleaned Societe object - * - * @url GET barcode/{barcode} - * - * @throws RestException - */ - public function getByBarcode($barcode) - { - return $this->_fetch('', '', '', $barcode); + return $this->_fetch('', '', '', '', '', '', '', '', '', '', $email); } /** @@ -128,8 +111,10 @@ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')" * @return array Array of thirdparty objects */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '') - { + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '') + { + global $db; + $obj_ret = array(); // case of external user, we force socids @@ -142,26 +127,26 @@ $sql = "SELECT t.rowid"; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; - if ($category > 0) { + if ($category > 0) { if ($mode != 4) $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; if (!in_array($mode, array(1, 2, 3))) $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc"; - } + } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; $sql .= " WHERE t.entity IN (".getEntity('societe').")"; $sql .= " AND t.fk_stcomm = st.id"; if ($mode == 1) $sql .= " AND t.client IN (1, 3)"; - elseif ($mode == 2) $sql .= " AND t.client IN (2, 3)"; - elseif ($mode == 3) $sql .= " AND t.client IN (0)"; - elseif ($mode == 4) $sql .= " AND t.fournisseur IN (1)"; - - // Select thirdparties of given category - if ($category > 0) { - if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_soc = t.rowid"; } - elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$this->db->escape($category)." AND cc.fk_soc = t.rowid"; } - else { $sql .= " AND ((c.fk_categorie = ".$this->db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$this->db->escape($category)." AND cc.fk_soc = t.rowid))"; } - } + if ($mode == 2) $sql .= " AND t.client IN (2, 3)"; + if ($mode == 3) $sql .= " AND t.client IN (0)"; + if ($mode == 4) $sql .= " AND t.fournisseur IN (1)"; + + // Select thirdparties of given category + if ($category > 0) { + if (!empty($mode) && $mode != 4) { $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid"; } + elseif (!empty($mode) && $mode == 4) { $sql .= " AND cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid"; } + else { $sql .= " AND ((c.fk_categorie = ".$db->escape($category)." AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".$db->escape($category)." AND cc.fk_soc = t.rowid))"; } + } if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; @@ -183,34 +168,36 @@ $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - $sql .= $this->db->order($sortfield, $sortorder); + $sql .= $db->order($sortfield, $sortorder); if ($limit) { - if ($page < 0) { + if ($page < 0) + { $page = 0; } $offset = $limit * $page; - $sql .= $this->db->plimit($limit + 1, $offset); - } - - $result = $this->db->query($sql); + $sql .= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); if ($result) { - $num = $this->db->num_rows($result); + $num = $db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); - $i = 0; + $i = 0; while ($i < $min) { - $obj = $this->db->fetch_object($result); - $soc_static = new Societe($this->db); + $obj = $db->fetch_object($result); + $soc_static = new Societe($db); if ($soc_static->fetch($obj->rowid)) { $obj_ret[] = $this->_cleanObjectDatas($soc_static); } $i++; } - } else { - throw new RestException(503, 'Error when retrieve thirdparties : '.$this->db->lasterror()); + } + else { + throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror()); } if (!count($obj_ret)) { throw new RestException(404, 'Thirdparties not found'); @@ -224,7 +211,7 @@ * @param array $request_data Request datas * @return int ID of thirdparty */ - public function post($request_data = null) + public function post($request_data = null) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -246,9 +233,9 @@ * * @param int $id Id of thirdparty to update * @param array $request_data Datas - * @return array|mixed|boolean - */ - public function put($id, $request_data = null) + * @return int + */ + public function put($id, $request_data = null) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -268,9 +255,8 @@ $this->company->$field = $value; } - if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) { + if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) return $this->get($id); - } return false; } @@ -289,9 +275,9 @@ * * @url PUT {id}/merge/{idtodelete} */ - public function merge($id, $idtodelete) - { - global $hookmanager; + public function merge($id, $idtodelete) + { + global $db, $hookmanager; $error = 0; @@ -313,7 +299,7 @@ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $this->companytoremove = new Societe($this->db); + $this->companytoremove = new Societe($db); $result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields if (!$result) { @@ -332,7 +318,7 @@ // Call same code than into action 'confirm_merge' - $this->db->begin(); + $db->begin(); // Recopy some data $object->client = $object->client | $soc_origin->client; @@ -369,7 +355,7 @@ } // Merge categories - $static_cat = new Categorie($this->db); + $static_cat = new Categorie($db); $custcats = $static_cat->containing($soc_origin->id, 'customer', 'id'); $object->setCategories($custcats, 'customer'); $suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id'); @@ -395,9 +381,8 @@ } // Move links - if (!$error) { - // This list is also into the societe/card.php file - // TODO Mutualise the list into object societe.class.php + if (!$error) + { $objects = array( 'Adherent' => '/adherents/class/adherent.class.php', 'Societe' => '/societe/class/societe.class.php', @@ -408,7 +393,6 @@ 'Facture' => '/compta/facture/class/facture.class.php', 'FactureRec' => '/compta/facture/class/facture-rec.class.php', 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php', - 'Mo' => '/mrp/class/mo.class.php', 'Contact' => '/contact/class/contact.class.php', 'Contrat' => '/contrat/class/contrat.class.php', 'Expedition' => '/expedition/class/expedition.class.php', @@ -417,11 +401,10 @@ 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php', 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php', 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php', - 'Livraison' => '/delivery/class/delivery.class.php', + 'Livraison' => '/livraison/class/livraison.class.php', 'Product' => '/product/class/product.class.php', 'Project' => '/projet/class/project.class.php', - 'Ticket' => '/ticket/class/ticket.class.php', - 'User' => '/user/class/user.class.php' + 'User' => '/user/class/user.class.php', ); //First, all core objects must update their tables @@ -429,54 +412,64 @@ { require_once DOL_DOCUMENT_ROOT.$object_file; - if (!$error && !$object_name::replaceThirdparty($this->db, $soc_origin->id, $object->id)) { - $error++; - //setEventMessages($this->db->lasterror(), null, 'errors'); + if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) + { + $errors++; + //setEventMessages($db->lasterror(), null, 'errors'); } } } // External modules should update their ones too - if (!$error) { - $reshook = $hookmanager->executeHooks('replaceThirdparty', array( + if (!$errors) + { + $reshook = $hookmanager->executeHooks('replaceThirdparty', array( 'soc_origin' => $soc_origin->id, 'soc_dest' => $object->id ), $soc_dest, $action); - if ($reshook < 0) { + if ($reshook < 0) + { //setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - $error++; - } - } - - - if (!$error) { + $errors++; + } + } + + + if (!$error) + { $object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id); // Call trigger $result = $object->call_trigger('COMPANY_MODIFY', $user); - if ($result < 0) { + if ($result < 0) + { //setEventMessages($object->error, $object->errors, 'errors'); $error++; } // End call triggers } - if (!$error) { + if (!$error) + { //We finally remove the old thirdparty - if ($soc_origin->delete($soc_origin->id, $user) < 1) { - $error++; + if ($soc_origin->delete($soc_origin->id, $user) < 1) + { + $errors++; } } // End of merge - if ($error) { - $this->db->rollback(); + if ($error) + { + $db->rollback(); throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.'); - } else { - $this->db->commit(); + } + else + { + $db->commit(); } return $this->get($id); @@ -488,7 +481,7 @@ * @param int $id Thirparty ID * @return integer */ - public function delete($id) + public function delete($id) { if (!DolibarrApiAccess::$user->rights->societe->supprimer) { throw new RestException(401); @@ -500,68 +493,8 @@ if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $this->company->oldcopy = clone $this->company; + $this->company->oldcopy = clone $this->company; return $this->company->delete($id); - } - - /** - * Set new price level for the given thirdparty - * - * @param int $id ID of thirdparty - * @param int $priceLevel Price level to apply to thirdparty - * @return object Thirdparty data without useless information - * - * @url PUT {id}/setpricelevel - * - * @throws RestException 400 Price level out of bounds - * @throws RestException 401 Access not allowed for your login - * @throws RestException 404 Thirdparty not found - * @throws RestException 500 Error fetching/setting price level - * @throws RestException 501 Request needs modules "Thirdparties" and "Products" and setting Multiprices activated - */ - public function setThirdpartyPriceLevel($id, $priceLevel) - { - global $conf; - - if (empty($conf->societe->enabled)) { - throw new RestException(501, 'Module "Thirdparties" needed for this request'); - } - - if (empty($conf->product->enabled)) { - throw new RestException(501, 'Module "Products" needed for this request'); - } - - if (empty($conf->global->PRODUIT_MULTIPRICES)) { - throw new RestException(501, 'Multiprices features activation needed for this request'); - } - - if ($priceLevel < 1 || $priceLevel > $conf->global->PRODUIT_MULTIPRICES_LIMIT) { - throw new RestException(400, 'Price level must be between 1 and '.$conf->global->PRODUIT_MULTIPRICES_LIMIT); - } - - if (empty(DolibarrApiAccess::$user->rights->societe->creer)) { - throw new RestException(401, 'Access to thirdparty '.$id.' not allowed for login '.DolibarrApiAccess::$user->login); - } - - $result = $this->company->fetch($id); - if ($result < 0) { - throw new RestException(404, 'Thirdparty '.$id.' not found'); - } - - if (empty($result)) { - throw new RestException(500, 'Error fetching thirdparty '.$id, array_merge(array($this->company->error), $this->company->errors)); - } - - if (empty(DolibarrApi::_checkAccessToResource('societe', $this->company->id))) { - throw new RestException(401, 'Access to thirdparty '.$id.' not allowed for login '.DolibarrApiAccess::$user->login); - } - - $result = $this->company->set_price_level($priceLevel, DolibarrApiAccess::$user); - if ($result <= 0) { - throw new RestException(500, 'Error setting new price level for thirdparty '.$id, array($this->company->db->lasterror())); - } - - return $this->_cleanObjectDatas($this->company); } /** @@ -577,7 +510,7 @@ * * @url GET {id}/categories */ - public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { if (!DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); @@ -616,7 +549,7 @@ * * @url POST {id}/categories/{category_id} */ - public function addCategory($id, $category_id) + public function addCategory($id, $category_id) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -654,7 +587,7 @@ * * @url DELETE {id}/categories/{category_id} */ - public function deleteCategory($id, $category_id) + public function deleteCategory($id, $category_id) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -695,7 +628,7 @@ * * @url GET {id}/supplier_categories */ - public function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + public function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { if (!DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); @@ -734,7 +667,7 @@ * * @url POST {id}/supplier_categories/{category_id} */ - public function addSupplierCategory($id, $category_id) + public function addSupplierCategory($id, $category_id) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -772,7 +705,7 @@ * * @url DELETE {id}/supplier_categories/{category_id} */ - public function deleteSupplierCategory($id, $category_id) + public function deleteSupplierCategory($id, $category_id) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -815,8 +748,10 @@ * @throws RestException 401 * @throws RestException 404 */ - public function getOutStandingProposals($id, $mode = 'customer') - { + public function getOutStandingProposals($id, $mode = 'customer') + { + $obj_ret = array(); + if (!DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } @@ -857,8 +792,10 @@ * @throws RestException 401 * @throws RestException 404 */ - public function getOutStandingOrder($id, $mode = 'customer') - { + public function getOutStandingOrder($id, $mode = 'customer') + { + $obj_ret = array(); + if (!DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } @@ -898,8 +835,10 @@ * @throws RestException 401 * @throws RestException 404 */ - public function getOutStandingInvoices($id, $mode = 'customer') - { + public function getOutStandingInvoices($id, $mode = 'customer') + { + $obj_ret = array(); + if (!DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } @@ -939,8 +878,10 @@ * @throws RestException 401 * @throws RestException 404 */ - public function getSalesRepresentatives($id, $mode = 0) - { + public function getSalesRepresentatives($id, $mode = 0) + { + $obj_ret = array(); + if (!DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } @@ -980,7 +921,7 @@ * @throws RestException 404 * @throws RestException 503 */ - public function getFixedAmountDiscounts($id, $filter = "none", $sortfield = "f.type", $sortorder = 'ASC') + public function getFixedAmountDiscounts($id, $filter = "none", $sortfield = "f.type", $sortorder = 'ASC') { $obj_ret = array(); @@ -1038,8 +979,8 @@ * @throws RestException 404 * @throws RestException 405 */ - public function getInvoicesQualifiedForReplacement($id) - { + public function getInvoicesQualifiedForReplacement($id) + { if (!DolibarrApiAccess::$user->rights->facture->lire) { throw new RestException(401); } @@ -1068,7 +1009,7 @@ /** * Return list of invoices qualified to be corrected by a credit note. * Invoices matching the following rules are returned - * (validated + payment on process) or classified (paid completely or paid partialy) + not already replaced + not already a credit note + * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note * * @param int $id Id of thirdparty * @@ -1081,8 +1022,8 @@ * @throws RestException 404 * @throws RestException 405 */ - public function getInvoicesQualifiedForCreditNote($id) - { + public function getInvoicesQualifiedForCreditNote($id) + { if (!DolibarrApiAccess::$user->rights->facture->lire) { throw new RestException(401); } @@ -1117,8 +1058,10 @@ * * @url GET {id}/bankaccounts */ - public function getCompanyBankAccount($id) - { + public function getCompanyBankAccount($id) + { + global $db, $conf; + if (!DolibarrApiAccess::$user->rights->facture->lire) { throw new RestException(401); } @@ -1140,7 +1083,7 @@ if ($id) $sql .= " WHERE fk_soc = ".$id." "; - $result = $this->db->query($sql); + $result = $db->query($sql); if ($result->num_rows == 0) { throw new RestException(404, 'Account not found'); @@ -1152,17 +1095,18 @@ if ($result) { - $num = $this->db->num_rows($result); + $num = $db->num_rows($result); while ($i < $num) { - $obj = $this->db->fetch_object($result); - $account = new CompanyBankAccount($this->db); + $obj = $db->fetch_object($result); + $account = new CompanyBankAccount($db); if ($account->fetch($obj->rowid)) { $accounts[] = $account; } $i++; } - } else { + } + else { throw new RestException(404, 'Account not found'); } @@ -1189,11 +1133,11 @@ * @param int $id ID of thirdparty * @param array $request_data Request data * - * @return array|mixed BankAccount of thirdparty + * @return object BankAccount of thirdparty * * @url POST {id}/bankaccounts */ - public function createCompanyBankAccount($id, $request_data = null) + public function createCompanyBankAccount($id, $request_data = null) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -1232,11 +1176,11 @@ * @param int $bankaccount_id ID of CompanyBankAccount * @param array $request_data Request data * - * @return array|mixed BankAccount of thirdparty + * @return object BankAccount of thirdparty * * @url PUT {id}/bankaccounts/{bankaccount_id} */ - public function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null) + public function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null) { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); @@ -1280,8 +1224,8 @@ * * @url DELETE {id}/bankaccounts/{bankaccount_id} */ - public function deleteCompanyBankAccount($id, $bankaccount_id) - { + public function deleteCompanyBankAccount($id, $bankaccount_id) + { if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); } @@ -1308,54 +1252,58 @@ */ public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate') { - global $conf, $langs; - - $langs->loadLangs(array("main", "dict", "commercial", "products", "companies", "banks", "bills", "withdrawals")); - - if ($this->company->fetch($id) <= 0) { - throw new RestException(404, 'Thirdparty not found'); - } - - if (!DolibarrApiAccess::$user->rights->societe->creer) { - throw new RestException(401); - } + global $conf; + + $this->langs->loadLangs(array("main", "dict", "commercial", "products", "companies", "banks", "bills", "withdrawals")); + + $this->company->fetch($id); + + $action = 'builddoc'; + if (!DolibarrApiAccess::$user->rights->societe->creer) + throw new RestException(401); $this->company->setDocModel(DolibarrApiAccess::$user, $model); $this->company->fk_bank = $this->company->fk_account; - $outputlangs = $langs; + $outputlangs = $this->langs; $newlang = ''; - //if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) { - if (isset($this->company->thirdparty->default_lang)) { - $newlang = $this->company->thirdparty->default_lang; // for proposal, order, invoice, ... - } elseif (isset($this->company->default_lang)) { - $newlang = $this->company->default_lang; // for thirdparty - } - } + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang = $this->company->thirdparty->default_lang; // for proposal, order, invoice, ... + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang = $this->company->default_lang; // for thirdparty if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } + // To be sure vars is defined + $hidedetails = $hidedesc = $hideref = 0; + $moreparams = null; + if (empty($hidedetails)) $hidedetails = 0; + if (empty($hidedesc)) $hidedesc = 0; + if (empty($hideref)) $hideref = 0; + if (empty($moreparams)) $moreparams = null; + + $sql = "SELECT rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib"; if ($id) $sql .= " WHERE fk_soc = ".$id." "; - if ($companybankid) $sql .= " AND rowid = ".$companybankid.""; + if ($companybankid) $sql .= " AND id = ".$companybankid.""; $i = 0; $accounts = array(); $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result) == 0) { + if ($result) + { + if ($result->num_rows == 0) { throw new RestException(404, 'Bank account not found'); } $num = $this->db->num_rows($result); - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($result); $account = new CompanyBankAccount($this->db); @@ -1364,38 +1312,47 @@ } $i++; } - } else { - throw new RestException(500, 'Sql error '.$this->db->lasterror()); + } + else + { + throw new RestException(404, 'Bank account not found'); } $moreparams = array( - 'use_companybankid' => $accounts[0]->id, - 'force_dir_output' => $conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id) + 'use_companybankid'=>$accounts[0]->id, + 'force_dir_output'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id) ); - $result = $this->company->generateDocument($model, $outputlangs, 0, 0, 0, $moreparams); - - if ($result > 0) { + $result = 0; + + $result = $this->company->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + + if ($result > 0) + { return array("success" => $result); - } else { + } + else + { throw new RestException(500); } - } - - /** + } + + /** * Get a specific gateway attached to a thirdparty (by specifying the site key) * * @param int $id ID of thirdparty * @param string $site Site key * - * @return array|mixed + * @return SocieteAccount[] * @throws RestException 401 Unauthorized: User does not have permission to read thirdparties * @throws RestException 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty * * @url GET {id}/gateways/ */ - public function getSocieteAccounts($id, $site = null) - { + public function getSocieteAccounts($id, $site = null) + { + global $db, $conf; + if (!DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } @@ -1411,9 +1368,9 @@ $sql .= " WHERE fk_soc = $id"; if ($site) $sql .= " AND site ='$site'"; - $result = $this->db->query($sql); - - if ($result && $this->db->num_rows($result) == 0) { + $result = $db->query($sql); + + if ($result->num_rows == 0) { throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.'); } @@ -1421,11 +1378,11 @@ $accounts = array(); - $num = $this->db->num_rows($result); + $num = $db->num_rows($result); while ($i < $num) { - $obj = $this->db->fetch_object($result); - $account = new SocieteAccount($this->db); + $obj = $db->fetch_object($result); + $account = new SocieteAccount($db); if ($account->fetch($obj->rowid)) { $accounts[] = $account; @@ -1460,7 +1417,7 @@ * @param int $id ID of thirdparty * @param array $request_data Request data * - * @return array|mixed + * @return SocieteAccount * * @throws RestException 401 Unauthorized: User does not have permission to read thirdparties * @throws RestException 409 Conflict: A SocieteAccount entity (gateway) already exists for this company and site. @@ -1469,8 +1426,10 @@ * * @url POST {id}/gateways */ - public function createSocieteAccount($id, $request_data = null) - { + public function createSocieteAccount($id, $request_data = null) + { + global $db; + if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); } @@ -1479,10 +1438,10 @@ throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !'); } - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$this->db->escape($request_data['site'])."'"; - $result = $this->db->query($sql); - - if ($result && $this->db->num_rows($result) == 0) { + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$request_data['site']."' "; + $result = $db->query($sql); + + if ($result->num_rows == 0) { $account = new SocieteAccount($this->db); if (!isset($request_data['login'])) { $account->login = ""; @@ -1518,7 +1477,7 @@ * @param string $site Site key * @param array $request_data Request data * - * @return array|mixed + * @return SocieteAccount * * @throws RestException 401 Unauthorized: User does not have permission to read thirdparties * @throws RestException 422 Unprocessable Entity: You must pass the site attribute in your request data ! @@ -1526,17 +1485,19 @@ * * @url PUT {id}/gateways/{site} */ - public function putSocieteAccount($id, $site, $request_data = null) - { + public function putSocieteAccount($id, $site, $request_data = null) + { + global $db; + if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); } - $sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '".$this->db->escape($site)."'"; - $result = $this->db->query($sql); + $sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; + $result = $db->query($sql); // We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one. - if ($result && $this->db->num_rows == 0) { + if ($result->num_rows == 0) { if (!isset($request_data['key_account'])) { throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !'); } @@ -1558,15 +1519,15 @@ // We found an existing SocieteAccount entity, we are replacing it } else { if (isset($request_data['site']) && $request_data['site'] !== $site) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$this->db->escape($request_data['site'])."' "; - $result = $this->db->query($sql); - - if ($result && $this->db->num_rows($result) !== 0) { + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$request_data['site']."' "; + $result = $db->query($sql); + + if ($result->num_rows !== 0) { throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site']." but another SocieteAccount entity already exists with this site key."); } } - $obj = $this->db->fetch_object($result); + $obj = $db->fetch_object($result); $account = new SocieteAccount($this->db); $account->id = $obj->rowid; @@ -1598,7 +1559,7 @@ * @param string $site Site key * @param array $request_data Request data * - * @return array|mixed + * @return SocieteAccount * * @throws RestException 401 Unauthorized: User does not have permission to read thirdparties * @throws RestException 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty @@ -1607,28 +1568,30 @@ * * @url PATCH {id}/gateways/{site} */ - public function patchSocieteAccount($id, $site, $request_data = null) - { + public function patchSocieteAccount($id, $site, $request_data = null) + { + global $db; + if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); } $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; - $result = $this->db->query($sql); - - if ($result && $this->db->num_rows($result) == 0) { + $result = $db->query($sql); + + if ($result->num_rows == 0) { throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist."); } else { // If the user tries to edit the site member, we check first if if (isset($request_data['site']) && $request_data['site'] !== $site) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$this->db->escape($request_data['site'])."' "; - $result = $this->db->query($sql); - - if ($result && $this->db->num_rows($result) !== 0) + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$request_data['site']."' "; + $result = $db->query($sql); + + if ($result->num_rows !== 0) throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site']." but another SocieteAccount entity already exists for this thirdparty with this site key."); } - $obj = $this->db->fetch_object($result); + $obj = $db->fetch_object($result); $account = new SocieteAccount($this->db); $account->fetch($obj->rowid); @@ -1658,19 +1621,22 @@ * * @url DELETE {id}/gateways/{site} */ - public function deleteSocieteAccount($id, $site) - { + public function deleteSocieteAccount($id, $site) + { + global /** @var Database $db */ + $db; + if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); } - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '".$this->db->escape($site)."'"; - $result = $this->db->query($sql); - - if ($result && $this->db->num_rows($result) == 0) { + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; + $result = $db->query($sql); + + if ($result->num_rows == 0) { throw new RestException(404); } else { - $obj = $this->db->fetch_object($result); + $obj = $db->fetch_object($result); $account = new SocieteAccount($this->db); $account->fetch($obj->rowid); @@ -1686,14 +1652,17 @@ * @param int $id ID of thirdparty * * @return void - * @throws RestException 401 Unauthorized: User does not have permission to delete thirdparties gateways - * @throws RestException 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty - * @throws RestException 500 Internal Server Error: Error deleting SocieteAccount entity + * @throws RestException(401) Unauthorized: User does not have permission to delete thirdparties gateways + * @throws RestException(404) Not Found: Specified thirdparty ID does not belongs to an existing thirdparty + * @throws RestException(500) Internal Server Error: Error deleting SocieteAccount entity * * @url DELETE {id}/gateways */ - public function deleteSocieteAccounts($id) - { + public function deleteSocieteAccounts($id) + { + global /** @var Database $db */ + $db; + if (!DolibarrApiAccess::$user->rights->societe->creer) { throw new RestException(401); } @@ -1703,20 +1672,20 @@ */ $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id; - - $result = $this->db->query($sql); - - if ($result && $this->db->num_rows($result) == 0) { + $sql .= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id "; + + $result = $db->query($sql); + + if ($result->num_rows == 0) { throw new RestException(404, 'This third party does not have any gateway attached or does not exist.'); } else { $i = 0; - $num = $this->db->num_rows($result); + $num = $db->num_rows($result); while ($i < $num) { - $obj = $this->db->fetch_object($result); - $account = new SocieteAccount($this->db); + $obj = $db->fetch_object($result); + $account = new SocieteAccount($db); $account->fetch($obj->rowid); if ($account->delete(DolibarrApiAccess::$user) < 0) { @@ -1727,16 +1696,16 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Clean sensible object datas * - * @param Object $object Object to clean - * @return array|mixed Object with cleaned properties + * @param object $object Object to clean + * @return array Array of cleaned object properties */ protected function _cleanObjectDatas($object) - { - // phpcs:enable + { + // phpcs:enable $object = parent::_cleanObjectDatas($object); unset($object->nom); // ->name already defined and nom deprecated @@ -1761,11 +1730,6 @@ unset($object->fk_delivery_address); // deprecated feature - unset($object->skype); - unset($object->twitter); - unset($object->facebook); - unset($object->linkedin); - return $object; } @@ -1777,26 +1741,26 @@ * * @throws RestException */ - private function _validate($data) - { - $thirdparty = array(); - foreach (Thirdparties::$FIELDS as $field) { - if (!isset($data[$field])) - throw new RestException(400, "$field field missing"); - $thirdparty[$field] = $data[$field]; - } - return $thirdparty; - } - - /** - * Fetch properties of a thirdparty object. - * - * Return an array with thirdparty informations - * - * @param int $rowid Id of third party to load (Use 0 to get a specimen record, use null to use other search criterias) + private function _validate($data) + { + $thirdparty = array(); + foreach (Thirdparties::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $thirdparty[$field] = $data[$field]; + } + return $thirdparty; + } + + /** + * Fetch properties of a thirdparty object. + * + * Return an array with thirdparty informations + * + * @param int $rowid Id of third party to load * @param string $ref Reference of third party, name (Warning, this can return several records) * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) - * @param string $barcode Barcode of third party to load + * @param string $ref_int Internal reference of third party (not used by dolibarr) * @param string $idprof1 Prof id 1 of third party (Warning, this can return several records) * @param string $idprof2 Prof id 2 of third party (Warning, this can return several records) * @param string $idprof3 Prof id 3 of third party (Warning, this can return several records) @@ -1805,42 +1769,39 @@ * @param string $idprof6 Prof id 6 of third party (Warning, this can return several records) * @param string $email Email of third party (Warning, this can return several records) * @param string $ref_alias Name_alias of third party (Warning, this can return several records) - * @return array|mixed cleaned Societe object - * - * @throws RestException - */ - private function _fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') - { - global $conf; - if (!DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } - if ($rowid === 0) { - $result = $this->company->initAsSpecimen(); - } else { - $result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias); - } - if (!$result) { - throw new RestException(404, 'Thirdparty not found'); - } - - if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice - $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice - } else { - $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; - $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; - } - - $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount); - $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote); - $this->company->absolute_discount = price2num($absolute_discount, 'MT'); - $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT'); - - return $this->_cleanObjectDatas($this->company); - } + * @return array|mixed data without useless information + * + * @throws RestException + */ + private function _fetch($rowid, $ref = '', $ref_ext = '', $ref_int = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') + { + global $conf; + if (!DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } + + $result = $this->company->fetch($rowid, $ref, $ref_ext, $ref_int, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias); + if (!$result) { + throw new RestException(404, 'Thirdparty not found'); + } + + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice + $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice + } else { + $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; + $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; + } + + $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount); + $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote); + $this->company->absolute_discount = price2num($absolute_discount, 'MT'); + $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT'); + + return $this->_cleanObjectDatas($this->company); + } } --- /tmp/dsg/dolibarr/htdocs/societe/class/github_client.class.php +++ /tmp/dsg/dolibarr/htdocs/societe/class/client_client.class.php @@ -1,7 +1,6 @@ <?php /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> - * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr> * * 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 @@ -30,66 +29,68 @@ */ class Client extends Societe { - public $next_prev_filter = "te.client in (1,2,3)"; // Used to add a filter in Form::showrefnav method + public $next_prev_filter = "te.client in (1,2,3)"; // Used to add a filter in Form::showrefnav method - public $cacheprospectstatus = array(); + public $cacheprospectstatus = array(); /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - $this->db = $db; + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - $this->client = 3; - $this->fournisseur = 0; - } + $this->client = 3; + $this->fournisseur = 0; + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Load indicators into this->nb for board - * - * @return int <0 if KO, >0 if OK - */ - public function load_state_board() - { - // phpcs:enable - global $user; + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Load indicators into this->nb for board + * + * @return int <0 if KO, >0 if OK + */ + public function load_state_board() + { + // phpcs:enable + global $user; - $this->nb = array("prospects" => 0, "customers" => 0); - $clause = "WHERE"; + $this->nb = array("customers" => 0, "prospects" => 0); + $clause = "WHERE"; - $sql = "SELECT count(s.rowid) as nb, s.client"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$user->socid) - { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; - $sql .= " WHERE sc.fk_user = ".$user->id; - $clause = "AND"; - } - $sql .= " ".$clause." s.client IN (1,2,3)"; - $sql .= ' AND s.entity IN ('.getEntity($this->element).')'; - $sql .= " GROUP BY s.client"; + $sql = "SELECT count(s.rowid) as nb, s.client"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + if (!$user->rights->societe->client->voir && !$user->socid) + { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; + $sql .= " WHERE sc.fk_user = ".$user->id; + $clause = "AND"; + } + $sql .= " ".$clause." s.client IN (1,2,3)"; + $sql .= ' AND s.entity IN ('.getEntity($this->element).')'; + $sql .= " GROUP BY s.client"; - $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { - if ($obj->client == 1 || $obj->client == 3) $this->nb["customers"] += $obj->nb; - if ($obj->client == 2 || $obj->client == 3) $this->nb["prospects"] += $obj->nb; - } - $this->db->free($resql); - return 1; - } else { - dol_print_error($this->db); - $this->error = $this->db->lasterror(); - return -1; - } - } + $resql = $this->db->query($sql); + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { + if ($obj->client == 1 || $obj->client == 3) $this->nb["customers"] += $obj->nb; + if ($obj->client == 2 || $obj->client == 3) $this->nb["prospects"] += $obj->nb; + } + $this->db->free($resql); + return 1; + } + else + { + dol_print_error($this->db); + $this->error = $this->db->lasterror(); + return -1; + } + } /** * Load array of prospect status @@ -97,20 +98,20 @@ * @param int $active 1=Active only, 0=Not active only, -1=All * @return int <0 if KO, >0 if OK */ - public function loadCacheOfProspStatus($active = 1) - { - global $langs; + public function loadCacheOfProspStatus($active = 1) + { + global $langs; - $sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcomm"; + $sql = "SELECT id, code, libelle as label FROM ".MAIN_DB_PREFIX."c_stcomm"; if ($active >= 0) $sql .= " WHERE active = ".$active; $resql = $this->db->query($sql); $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { $obj = $this->db->fetch_object($resql); - $this->cacheprospectstatus[$obj->id] = array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code)), 'picto'=>$obj->picto); + $this->cacheprospectstatus[$obj->id] = array('id'=>$obj->id, 'code'=>$obj->code, 'label'=> ($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code))); $i++; } return 1; - } + } } --- /tmp/dsg/dolibarr/htdocs/societe/class/github_companybankaccount.class.php +++ /tmp/dsg/dolibarr/htdocs/societe/class/client_companybankaccount.class.php @@ -41,18 +41,18 @@ public $date_rum; /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * Date modification record (tms) - * - * @var integer - */ - public $datem; + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + /** + * Date modification record (tms) + * + * @var integer + */ + public $datem; /** @@ -78,7 +78,7 @@ * @param int $notrigger 1=Disable triggers * @return int <0 if KO, >= 0 if OK */ - public function create(User $user = null, $notrigger = 0) + public function create(User $user = null, $notrigger = 0) { $now = dol_now(); $error = 0; @@ -111,14 +111,20 @@ if (!$error) { return 1; - } else { + } + else + { return 0; } - } else { + } + else + { return 1; } } - } else { + } + else + { print $this->db->error(); return 0; } @@ -131,7 +137,7 @@ * @param int $notrigger 1=Disable triggers * @return int <=0 if KO, >0 if OK */ - public function update(User $user = null, $notrigger = 0) + public function update(User $user = null, $notrigger = 0) { global $conf; $error = 0; @@ -161,7 +167,8 @@ } if (trim($this->label) != '') $sql .= ",label = '".$this->db->escape($this->label)."'"; - else $sql .= ",label = NULL"; + else + $sql .= ",label = NULL"; $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); @@ -176,13 +183,19 @@ if (!$error) { return 1; - } else { + } + else + { return -1; } - } else { + } + else + { return 1; } - } else { + } + else + { dol_print_error($this->db); return -1; } @@ -197,7 +210,7 @@ * @param int $type If id of company filled, we say if we want record of this type only * @return int <0 if KO, >0 if OK */ - public function fetch($id, $socid = 0, $default = 1, $type = 'ban') + public function fetch($id, $socid = 0, $default = 1, $type = 'ban') { if (empty($id) && empty($socid)) return -1; @@ -245,7 +258,9 @@ $this->db->free($resql); return 1; - } else { + } + else + { dol_print_error($this->db); return -1; } @@ -258,7 +273,7 @@ * @param int $notrigger 1=Disable triggers * @return int <0 if KO, >0 if OK */ - public function delete(User $user = null, $notrigger = 0) + public function delete(User $user = null, $notrigger = 0) { global $conf; @@ -292,7 +307,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1 * $error; } @@ -325,7 +342,7 @@ * @param int $rib RIB id * @return int 0 if KO, 1 if OK */ - public function setAsDefault($rib = 0) + public function setAsDefault($rib = 0) { $sql1 = "SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX."societe_rib"; $sql1 .= " WHERE rowid = ".($rib ? $rib : $this->id); @@ -337,7 +354,9 @@ if ($this->db->num_rows($result1) == 0) { return 0; - } else { + } + else + { $obj = $this->db->fetch_object($result1); $this->db->begin(); @@ -357,12 +376,16 @@ dol_print_error($this->db); $this->db->rollback(); return -1; - } else { + } + else + { $this->db->commit(); return 1; } } - } else { + } + else + { dol_print_error($this->db); return -1; } @@ -375,7 +398,7 @@ * * @return void */ - public function initAsSpecimen() + public function initAsSpecimen() { $this->specimen = 1; $this->ref = 'CBA'; --- /tmp/dsg/dolibarr/htdocs/societe/class/github_companypaymentmode.class.php +++ /tmp/dsg/dolibarr/htdocs/societe/class/client_companypaymentmode.class.php @@ -133,12 +133,12 @@ /** * @var int Thirdparty ID */ - public $fk_soc; - - /** - * @var string company payment mode label - */ - public $label; + public $fk_soc; + + /** + * @var string company payment mode label + */ + public $label; public $bank; public $code_banque; @@ -178,18 +178,18 @@ public $ending_date; /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * Date modification record (tms) - * - * @var integer - */ - public $tms; + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + /** + * Date modification record (tms) + * + * @var integer + */ + public $tms; public $import_key; // END MODULEBUILDER PROPERTIES @@ -199,19 +199,19 @@ // If this object has a subtable with lines /** - * @var string Name of subtable line + * @var int Name of subtable line */ //public $table_element_line = 'companypaymentmodedet'; /** - * @var string Field with ID of parent key if this field has a parent + * @var int Field with ID of parent key if this field has a parent */ //public $fk_element = 'fk_companypaymentmode'; /** - * @var string Name of subtable class that manage subtable lines + * @var int Name of subtable class that manage subtable lines */ //public $class_element_line = 'CompanyPaymentModeline'; /** - * @var array List of child tables. To test if we can delete object. + * @var array List of child tables. To test if we can delete object. */ //protected $childtables=array(); /** @@ -260,45 +260,45 @@ public function createFromClone(User $user, $fromid) { global $hookmanager, $langs; - $error = 0; - - dol_syslog(__METHOD__, LOG_DEBUG); - - $object = new self($this->db); - - $this->db->begin(); - - // Load source object - $object->fetchCommon($fromid); - // Reset some properties - unset($object->id); - unset($object->fk_user_creat); - unset($object->import_key); - - // Clear fields - $object->ref = "copy_of_".$object->ref; - $object->title = $langs->trans("CopyOf")." ".$object->title; - // ... - - // Create clone + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $object->fetchCommon($fromid); + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); + + // Clear fields + $object->ref = "copy_of_".$object->ref; + $object->title = $langs->trans("CopyOf")." ".$object->title; + // ... + + // Create clone $object->context['createfromclone'] = 'createfromclone'; - $result = $object->createCommon($user); - if ($result < 0) { - $error++; - $this->error = $object->error; - $this->errors = $object->errors; - } - - unset($object->context['createfromclone']); - - // End - if (!$error) { - $this->db->commit(); - return $object; - } else { - $this->db->rollback(); - return -1; - } + $result = $object->createCommon($user); + if ($result < 0) { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + } + + unset($object->context['createfromclone']); + + // End + if (!$error) { + $this->db->commit(); + return $object; + } else { + $this->db->rollback(); + return -1; + } } /** @@ -364,47 +364,48 @@ * * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) * @param string $option On what the link point to ('nolink', ...) - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string String with URL */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) + public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) { global $db, $conf, $langs; - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; - - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips - - $result = ''; - $companylink = ''; - - $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>'; - $label .= '<br>'; - $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref; - - $url = dol_buildpath('/monmodule/companypaymentmode_card.php', 1).'?id='.$this->id; - - if ($option != 'nolink') - { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; - } - - $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label = $langs->trans("ShowCompanyPaymentMode"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + + $result = ''; + $companylink = ''; + + $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>'; + $label .= '<br>'; + $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref; + + $url = dol_buildpath('/monmodule/companypaymentmode_card.php', 1).'?id='.$this->id; + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + + $linkclose = ''; + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("ShowCompanyPaymentMode"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); $linkstart = '<a href="'.$url.'"'; $linkstart .= $linkclose.'>'; @@ -426,7 +427,7 @@ * @param string $alltypes 1=The default is for all payment types instead of per type * @return int 0 if KO, 1 if OK */ - public function setAsDefault($id = 0, $alltypes = 0) + public function setAsDefault($id = 0, $alltypes = 0) { $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib"; $sql1 .= " WHERE rowid = ".($id ? $id : $this->id); @@ -438,7 +439,9 @@ if ($this->db->num_rows($result1) == 0) { return 0; - } else { + } + else + { $obj = $this->db->fetch_object($result1); $type = ''; @@ -463,12 +466,16 @@ dol_print_error($this->db); $this->db->rollback(); return -1; - } else { + } + else + { $this->db->commit(); return 1; } } - } else { + } + else + { dol_print_error($this->db); return -1; } @@ -480,12 +487,12 @@ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label of status */ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0) { return $this->LibStatut($this->status, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return the status * @@ -518,7 +525,7 @@ * @param int $id Id of object * @return void */ - public function info($id) + public function info($id) { $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; $sql .= ' fk_user_creat, fk_user_modif'; @@ -558,7 +565,9 @@ } $this->db->free($result); - } else { + } + else + { dol_print_error($this->db); } } --- /tmp/dsg/dolibarr/htdocs/societe/class/github_societe.class.php +++ /tmp/dsg/dolibarr/htdocs/societe/class/client_societe.class.php @@ -16,7 +16,6 @@ * Copyright (C) 2018 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2019-2020 Josep LluÃs Amador <joseplluis@lliuretic.cat> * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr> - * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr> * * 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 @@ -38,7 +37,6 @@ * \brief File for third party class */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; /** @@ -46,8 +44,6 @@ */ class Societe extends CommonObject { - use CommonIncoterm; - /** * @var string ID to identify managed object */ @@ -59,13 +55,13 @@ public $table_element = 'societe'; /** - * @var string Field with ID of parent key if this field has a parent or for child tables + * @var int Field with ID of parent key if this field has a parent or for child tables */ public $fk_element = 'fk_soc'; - /** - * @var string Fields for combobox - */ + /** + * @var string Fields for combobox + */ public $fieldsforcombobox = 'nom,name_alias'; /** @@ -161,8 +157,8 @@ 'instagram' =>array('type'=>'varchar(255)', 'label'=>'Instagram', 'enabled'=>1, 'visible'=>-1, 'position'=>155), 'facebook' =>array('type'=>'varchar(255)', 'label'=>'Facebook', 'enabled'=>1, 'visible'=>-1, 'position'=>160), 'twitter' =>array('type'=>'varchar(255)', 'label'=>'Twitter', 'enabled'=>1, 'visible'=>-1, 'position'=>165),*/ - 'fk_effectif' =>array('type'=>'integer', 'label'=>'Workforce', 'enabled'=>1, 'visible'=>-1, 'position'=>170), - 'fk_typent' =>array('type'=>'integer', 'label'=>'TypeOfCompany', 'enabled'=>1, 'visible'=>-1, 'position'=>175), + 'fk_effectif' =>array('type'=>'integer', 'label'=>'Fk effectif', 'enabled'=>1, 'visible'=>-1, 'position'=>170), + 'fk_typent' =>array('type'=>'integer', 'label'=>'Fk typent', 'enabled'=>1, 'visible'=>-1, 'position'=>175), 'fk_forme_juridique' =>array('type'=>'integer', 'label'=>'JuridicalStatus', 'enabled'=>1, 'visible'=>-1, 'position'=>180), 'fk_currency' =>array('type'=>'varchar(3)', 'label'=>'Currency', 'enabled'=>1, 'visible'=>-1, 'position'=>185), 'siren' =>array('type'=>'varchar(128)', 'label'=>'Idprof1', 'enabled'=>1, 'visible'=>-1, 'position'=>190), @@ -173,7 +169,7 @@ 'idprof6' =>array('type'=>'varchar(128)', 'label'=>'Idprof6', 'enabled'=>1, 'visible'=>-1, 'position'=>207), 'tva_intra' =>array('type'=>'varchar(20)', 'label'=>'Tva intra', 'enabled'=>1, 'visible'=>-1, 'position'=>210), 'capital' =>array('type'=>'double(24,8)', 'label'=>'Capital', 'enabled'=>1, 'visible'=>-1, 'position'=>215), - 'fk_stcomm' =>array('type'=>'integer', 'label'=>'CommercialStatus', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>220), + 'fk_stcomm' =>array('type'=>'integer', 'label'=>'Fk stcomm', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>220), 'note_private' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>225), 'note_public' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>230), 'prefix_comm' =>array('type'=>'varchar(5)', 'label'=>'Prefix comm', 'enabled'=>'$conf->global->SOCIETE_USEPREFIX', 'visible'=>-1, 'position'=>235), @@ -245,9 +241,9 @@ */ public $name_alias; - /** - * @var int Physical thirdparty not a company - */ + /** + * @var int Physical thirdparty not a company + */ public $particulier; /** @@ -255,14 +251,14 @@ */ public $address; - /** - * @var string Zip code of thirdparty - */ + /** + * @var string Zip code of thirdparty + */ public $zip; - /** - * @var string Town of thirdparty - */ + /** + * @var string Town of thirdparty + */ public $town; /** @@ -277,14 +273,14 @@ */ public $state_id; - /** - * @var string State code - */ + /** + * @var string State code + */ public $state_code; - /** - * @var string State name - */ + /** + * @var string State name + */ public $state; /** @@ -293,9 +289,9 @@ */ public $region_code; - /** - * @var string Region name - */ + /** + * @var string Region name + */ public $region; /** @@ -335,10 +331,10 @@ */ public $email; - /** - * @var array array of socialnetworks - */ - public $socialnetworks; + /** + * @var array array of socialnetworks + */ + public $socialnetworks; /** * Skype username @@ -361,11 +357,11 @@ */ public $facebook; - /** - * LinkedIn username - * @var string + /** + * LinkedIn username + * @var string * @deprecated - */ + */ public $linkedin; /** @@ -418,9 +414,9 @@ */ public $idprof6; - /** - * @var string Prefix comm - */ + /** + * @var string Prefix comm + */ public $prefix_comm; /** @@ -440,14 +436,14 @@ public $localtax2_assuj; public $localtax2_value; - /** - * @var string Manager - */ + /** + * @var string Manager + */ public $managers; - /** - * @var float Capital - */ + /** + * @var float Capital + */ public $capital; /** @@ -464,11 +460,10 @@ public $remise_supplier_percent; public $mode_reglement_supplier_id; public $cond_reglement_supplier_id; - public $transport_mode_supplier_id; - - /** - * @var int ID - */ + + /** + * @var int ID + */ public $fk_prospectlevel; /** @@ -501,6 +496,9 @@ */ public $user_creation; + + public $specimen; + /** * 0=no customer, 1=customer, 2=prospect, 3=customer and prospect * @var int @@ -537,11 +535,11 @@ */ public $code_compta; - /** - * Accounting code for client - * @var string - */ - public $code_compta_client; + /** + * Accounting code for client + * @var string + */ + public $code_compta_client; /** * Accounting code for suppliers @@ -575,12 +573,6 @@ public $stcomm_id; /** - * Status prospect picto - * @var string - */ - public $stcomm_picto; - - /** * Status prospect label * @var int */ @@ -602,9 +594,9 @@ */ public $order_min_amount; - /** - * @var string Supplier min order amount - */ + /** + * @var string Supplier min order amount + */ public $supplier_order_min_amount; /** @@ -663,83 +655,68 @@ */ public $webservices_key; - /** - * @var string Logo - */ + /** + * @var string Logo + */ public $logo; - /** - * @var string logo small - */ + /** + * @var string logo small + */ public $logo_small; - /** - * @var string Logo mini - */ + /** + * @var string Logo mini + */ public $logo_mini; - /** - * @var string Logo squarred - */ + /** + * @var string Logo squarred + */ public $logo_squarred; - /** - * @var string Logo squarred small - */ + /** + * @var string Logo squarred small + */ public $logo_squarred_small; - /** - * @var string Logo squarred mini - */ + /** + * @var string Logo squarred mini + */ public $logo_squarred_mini; + /** + * @var int ID Incoterms + */ + public $fk_incoterms; + + /** + * @var string Incoterms Location + */ + public $location_incoterms; + + /** + * @var string Incoterm label + */ + public $label_incoterms; //Used into tooltip // Multicurrency /** - * @var int ID - */ + * @var int ID + */ public $fk_multicurrency; - /** - * @var string Multicurrency code - */ + /** + * @var string Multicurrency code + */ public $multicurrency_code; /** - * @var Account|string Default BAN account + * @var Account Default BAN account */ public $bank_account; - /** - * Third party is no customer - */ - const NO_CUSTOMER = 0; - - /** - * Third party is a customer - */ - const CUSTOMER = 1; - - /** - * Third party is a prospect - */ - const PROSPECT = 2; - - /** - * Third party is a customer and a prospect - */ - const CUSTOMER_AND_PROSPECT = 3; - - /** - * Third party is no supplier - */ - const NO_SUPPLIER = 0; - - /** - * Third party is a supplier - */ - const SUPPLIER = 1; /** * Constructor @@ -748,8 +725,6 @@ */ public function __construct($db) { - global $conf; - $this->db = $db; $this->client = 0; @@ -760,13 +735,6 @@ $this->forme_juridique_code = 0; $this->tva_assuj = 1; $this->status = 1; - - if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { - $this->fields['address']['showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST; - $this->fields['zip']['showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST; - $this->fields['town']['showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST; - //$this->fields['fk_pays']['showoncombobox'] = $conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST; - } } @@ -775,33 +743,27 @@ * $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement. * * @param User $user Object of user that ask creation - * @return int >=0 if OK, <0 if KO - */ - public function create(User $user) + * @return int >= 0 if OK, < 0 if KO + */ + public function create(User $user) { global $langs, $conf, $mysoc; $error = 0; // Clean parameters - if (empty($this->status)) { - $this->status = 0; - } + if (empty($this->status)) $this->status = 0; $this->name = $this->name ?trim($this->name) : trim($this->nom); - $this->setUpperOrLowerCase(); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name); $this->nom = $this->name; // For backward compatibility - if (empty($this->client)) { - $this->client = 0; - } - if (empty($this->fournisseur)) { - $this->fournisseur = 0; - } + if (empty($this->client)) $this->client = 0; + if (empty($this->fournisseur)) $this->fournisseur = 0; $this->import_key = trim($this->import_key); - if (!empty($this->multicurrency_code)) { - $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - } - if (empty($this->fk_multicurrency)) { + if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + if (empty($this->fk_multicurrency)) + { $this->multicurrency_code = ''; $this->fk_multicurrency = 0; } @@ -813,25 +775,23 @@ $this->db->begin(); // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) - if ($this->code_client == -1 || $this->code_client === 'auto') { - $this->get_codeclient($this, 0); - } - if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') { - $this->get_codefournisseur($this, 1); - } + if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0); + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1); // Check more parameters (including mandatory setup // If error, this->errors[] is filled $result = $this->verify(); - if ($result >= 0) { + if ($result >= 0) + { $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)"; $sql .= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'"; - $sql .= ", ".(!empty($user->id) ? ((int) $user->id) : "null"); + $sql .= ", ".(!empty($user->id) ? "'".$user->id."'" : "null"); $sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null"); $sql .= ", ".$this->status; + $sql .= ", ".(!empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'" : "null"); $sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null"); $sql .= ", 0"; $sql .= ", ".(int) $this->fk_incoterms; @@ -842,52 +802,63 @@ dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) { + if ($result) + { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe"); $ret = $this->update($this->id, $user, 0, 1, 1, 'add'); // Ajout du commercial affecte - if ($this->commercial_id != '' && $this->commercial_id != -1) { + if ($this->commercial_id != '' && $this->commercial_id != -1) + { $this->add_commercial($user, $this->commercial_id); } // si un commercial cree un client il lui est affecte automatiquement - elseif (empty($user->rights->societe->client->voir)) { + elseif (empty($user->rights->societe->client->voir)) + { $this->add_commercial($user, $user->id); } - if ($ret >= 0) { + if ($ret >= 0) + { // Call trigger $result = $this->call_trigger('COMPANY_CREATE', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; // End call triggers - } else { - $error++; - } - - if (!$error) { + } + else $error++; + + if (!$error) + { dol_syslog(get_class($this)."::Create success id=".$this->id); $this->db->commit(); return $this->id; - } else { - dol_syslog(get_class($this)."::Create echec update ".$this->error.(empty($this->errors) ? '' : ' '.join(',', $this->errors)), LOG_ERR); + } + else + { + dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR); $this->db->rollback(); return -4; } - } else { - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + } + else + { + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { $this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...) $result = -1; - } else { + } + else + { $this->error = $this->db->lasterror(); $result = -2; } $this->db->rollback(); return $result; } - } else { + } + else + { $this->db->rollback(); dol_syslog(get_class($this)."::Create fails verify ".join(',', $this->errors), LOG_WARNING); return -3; @@ -895,16 +866,16 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a contact/address from thirdparty * * @param User $user Object user * @return int <0 if KO, >0 if OK */ - public function create_individual(User $user) - { - // phpcs:enable + public function create_individual(User $user) + { + // phpcs:enable require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $contact = new Contact($this->db); @@ -924,7 +895,8 @@ $contact->phone_pro = $this->phone; $result = $contact->create($user); - if ($result < 0) { + if ($result < 0) + { $this->error = $contact->error; $this->errors = $contact->errors; dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR); @@ -939,7 +911,7 @@ * * @return int 0 if OK, <0 if KO */ - public function verify() + public function verify() { global $conf, $langs, $mysoc; @@ -950,43 +922,57 @@ $this->name = trim($this->name); $this->nom = $this->name; // For backward compatibility - if (!$this->name) { + if (!$this->name) + { $this->errors[] = 'ErrorBadThirdPartyName'; $result = -2; } - if ($this->client) { + if ($this->client) + { $rescode = $this->check_codeclient(); - if ($rescode != 0 && $rescode != -5) { - if ($rescode == -1) { + if ($rescode <> 0) + { + if ($rescode == -1) + { $this->errors[] = 'ErrorBadCustomerCodeSyntax'; - } elseif ($rescode == -2) { + } + elseif ($rescode == -2) + { $this->errors[] = 'ErrorCustomerCodeRequired'; - } elseif ($rescode == -3) { + } + elseif ($rescode == -3) + { $this->errors[] = 'ErrorCustomerCodeAlreadyUsed'; - } elseif ($rescode == -4) { + } + elseif ($rescode == -4) + { $this->errors[] = 'ErrorPrefixRequired'; - } else { - $this->errors[] = 'ErrorUnknownOnCustomerCodeCheck'; - } - + } $result = -3; } } - if ($this->fournisseur) { + if ($this->fournisseur) + { $rescode = $this->check_codefournisseur(); - if ($rescode != 0 && $rescode != -5) { - if ($rescode == -1) { + if ($rescode <> 0) + { + if ($rescode == -1) + { $this->errors[] = 'ErrorBadSupplierCodeSyntax'; - } elseif ($rescode == -2) { + } + elseif ($rescode == -2) + { $this->errors[] = 'ErrorSupplierCodeRequired'; - } elseif ($rescode == -3) { + } + elseif ($rescode == -3) + { $this->errors[] = 'ErrorSupplierCodeAlreadyUsed'; - } elseif ($rescode == -4) { + } + elseif ($rescode == -5) + { $this->errors[] = 'ErrorPrefixRequired'; - } else { - $this->errors[] = 'ErrorUnknownOnSupplierCodeCheck'; } $result = -3; } @@ -994,17 +980,22 @@ // Check for duplicate or mandatory fields defined into setup $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); - foreach ($array_to_check as $key) { + foreach ($array_to_check as $key) + { $keymin = strtolower($key); $i = (int) preg_replace('/[^0-9]/', '', $key); $vallabel = $this->$keymin; - if ($i > 0) { - if ($this->isACompany()) { + if ($i > 0) + { + if ($this->isACompany()) + { // Check for mandatory prof id (but only if country is same than ours) - if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) { + if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) + { $idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY'; - if (!$vallabel && !empty($conf->global->$idprof_mandatory)) { + if (!$vallabel && !empty($conf->global->$idprof_mandatory)) + { $langs->load("errors"); $error++; $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')'; @@ -1013,27 +1004,35 @@ } // Check for unicity on profid - if (!$error && $vallabel && $this->id_prof_verifiable($i)) { - if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { + if (!$error && $vallabel && $this->id_prof_verifiable($i)) + { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) + { $langs->load("errors"); $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; } } - } else { + } + else + { //var_dump($conf->global->SOCIETE_EMAIL_UNIQUE); //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY); - if ($key == 'EMAIL') { + if ($key == 'EMAIL') + { // Check for mandatory - if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) { + if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) + { $langs->load("errors"); $error++; $this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')'; } // Check for unicity - if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) { - if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { + if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) + { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) + { $langs->load("errors"); $error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; } @@ -1042,9 +1041,7 @@ } } - if ($error) { - $result = -4; - } + if ($error) $result = -4; return $result; } @@ -1061,15 +1058,13 @@ * @param int $nosyncmember Do not synchronize info of linked member * @return int <0 if KO, >=0 if OK */ - public function update($id, $user = '', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action = 'update', $nosyncmember = 1) + public function update($id, $user = '', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action = 'update', $nosyncmember = 1) { global $langs, $conf, $hookmanager; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - if (empty($id)) { - $id = $this->id; - } + if (empty($id)) $id = $this->id; $error = 0; @@ -1077,6 +1072,8 @@ $now = dol_now(); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name); // Clean parameters $this->id = $id; $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); @@ -1086,8 +1083,7 @@ $this->ref_ext = trim($this->ref_ext); $this->address = $this->address ?trim($this->address) : trim($this->address); $this->zip = $this->zip ?trim($this->zip) : trim($this->zip); - $this->town = $this->town ?trim($this->town) : trim($this->town); - $this->setUpperOrLowerCase(); + $this->town = $this->town ?trim($this->town) : trim($this->town); $this->state_id = trim($this->state_id); $this->country_id = ($this->country_id > 0) ? $this->country_id : 0; $this->phone = trim($this->phone); @@ -1113,14 +1109,11 @@ $this->tva_assuj = trim($this->tva_assuj); $this->tva_intra = dol_sanitizeFileName($this->tva_intra, ''); - if (empty($this->status)) { - $this->status = 0; - } - - if (!empty($this->multicurrency_code)) { - $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - } - if (empty($this->fk_multicurrency)) { + if (empty($this->status)) $this->status = 0; + + if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + if (empty($this->fk_multicurrency)) + { $this->multicurrency_code = ''; $this->fk_multicurrency = 0; } @@ -1132,12 +1125,8 @@ $this->localtax1_value = trim($this->localtax1_value); $this->localtax2_value = trim($this->localtax2_value); - if ($this->capital != '') { - $this->capital = price2num(trim($this->capital)); - } - if (!is_numeric($this->capital)) { - $this->capital = ''; // '' = undef - } + if ($this->capital != '') $this->capital = price2num(trim($this->capital)); + if (!is_numeric($this->capital)) $this->capital = ''; // '' = undef $this->effectif_id = trim($this->effectif_id); $this->forme_juridique_code = trim($this->forme_juridique_code); @@ -1146,44 +1135,41 @@ $this->barcode = trim($this->barcode); // For automatic creation - if ($this->code_client == -1 || $this->code_client === 'auto') { - $this->get_codeclient($this, 0); - } - if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') { - $this->get_codefournisseur($this, 1); - } + if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0); + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1); $this->code_compta = trim($this->code_compta); $this->code_compta_fournisseur = trim($this->code_compta_fournisseur); // Check parameters. More tests are done later in the ->verify() - if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) { + if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) + { $langs->load("errors"); $this->error = $langs->trans("BadValueForParameterClientOrSupplier"); return -1; } $customer = false; - if (!empty($allowmodcodeclient) && !empty($this->client)) { + if (!empty($allowmodcodeclient) && !empty($this->client)) + { // Attention get_codecompta peut modifier le code suivant le module utilise - if (empty($this->code_compta)) { + if (empty($this->code_compta)) + { $ret = $this->get_codecompta('customer'); - if ($ret < 0) { - return -1; - } + if ($ret < 0) return -1; } $customer = true; } $supplier = false; - if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) { + if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) + { // Attention get_codecompta peut modifier le code suivant le module utilise - if ($this->code_compta_fournisseur == "") { + if ($this->code_compta_fournisseur == "") + { $ret = $this->get_codecompta('supplier'); - if ($ret < 0) { - return -1; - } + if ($ret < 0) return -1; } $supplier = true; @@ -1202,31 +1188,33 @@ // Check name is required and codes are ok or unique. // If error, this->errors[] is filled $result = 0; - if ($action != 'add' && $action != 'merge') { + if ($action != 'add' && $action != 'merge') + { // We don't check when update called during a create because verify was already done. // For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error $result = $this->verify(); // If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update // So we can update record that were using and old numbering rule. - if (is_array($this->errors)) { - if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) { - if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) { - unset($this->errors[$key]); // Remove error message - } - } - if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) { - if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) { - unset($this->errors[$key]); // Remove error message - } - } - if (empty($this->errors)) { // If there is no more error, we can make like if there is no error at all + if (is_array($this->errors)) + { + if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) + { + if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message + } + if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) + { + if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message + } + if (empty($this->errors)) // If there is no more error, we can make like if there is no error at all + { $result = 0; } } } - if ($result >= 0) { + if ($result >= 0) + { dol_syslog(get_class($this)."::update verify ok or not done"); $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET "; @@ -1244,8 +1232,8 @@ $sql .= ",phone = ".(!empty($this->phone) ? "'".$this->db->escape($this->phone)."'" : "null"); $sql .= ",fax = ".(!empty($this->fax) ? "'".$this->db->escape($this->fax)."'" : "null"); - $sql .= ",email = ".(!empty($this->email) ? "'".$this->db->escape($this->email)."'" : "null"); - $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; + $sql .= ",email = ".(!empty($this->email) ? "'".$this->db->escape($this->email)."'" : "null"); + $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; $sql .= ",url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null"); $sql .= ",parent = ".($this->parent > 0 ? $this->parent : "null"); @@ -1267,32 +1255,33 @@ // Local taxes $sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null"); $sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null"); - if ($this->localtax1_assuj == 1) { - if ($this->localtax1_value != '') { + if ($this->localtax1_assuj == 1) + { + if ($this->localtax1_value != '') + { $sql .= ",localtax1_value =".$this->localtax1_value; - } else { - $sql .= ",localtax1_value =0.000"; - } - } else { - $sql .= ",localtax1_value =0.000"; - } - - if ($this->localtax2_assuj == 1) { - if ($this->localtax2_value != '') { + } + else $sql .= ",localtax1_value =0.000"; + } + else $sql .= ",localtax1_value =0.000"; + + if ($this->localtax2_assuj == 1) + { + if ($this->localtax2_value != '') + { $sql .= ",localtax2_value =".$this->localtax2_value; - } else { - $sql .= ",localtax2_value =0.000"; - } - } else { - $sql .= ",localtax2_value =0.000"; - } + } + else $sql .= ",localtax2_value =0.000"; + } + else $sql .= ",localtax2_value =0.000"; $sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital); $sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null"); $sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null"); - if (isset($this->stcomm_id)) { + if (isset($this->stcomm_id)) + { $sql .= ",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id : "0"); } $sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0"); @@ -1301,10 +1290,8 @@ $sql .= ",mode_reglement = ".(!empty($this->mode_reglement_id) ? "'".$this->db->escape($this->mode_reglement_id)."'" : "null"); $sql .= ",cond_reglement = ".(!empty($this->cond_reglement_id) ? "'".$this->db->escape($this->cond_reglement_id)."'" : "null"); - $sql .= ",transport_mode = ".(!empty($this->transport_mode_id) ? "'".$this->db->escape($this->transport_mode_id)."'" : "null"); $sql .= ",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ? "'".$this->db->escape($this->mode_reglement_supplier_id)."'" : "null"); $sql .= ",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ? "'".$this->db->escape($this->cond_reglement_supplier_id)."'" : "null"); - $sql .= ",transport_mode_supplier = ".(!empty($this->transport_mode_supplier_id) ? "'".$this->db->escape($this->transport_mode_supplier_id)."'" : "null"); $sql .= ",fk_shipping_method = ".(!empty($this->shipping_method_id) ? "'".$this->db->escape($this->shipping_method_id)."'" : "null"); $sql .= ",client = ".(!empty($this->client) ? $this->client : 0); @@ -1325,33 +1312,40 @@ $sql .= ", fk_incoterms = ".$this->fk_incoterms; $sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null"); - if ($customer) { + if ($customer) + { $sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null"); $sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null"); } - if ($supplier) { + if ($supplier) + { $sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null"); $sql .= ", code_compta_fournisseur = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); } $sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : "null"); $sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency; $sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'"; - $sql .= ", model_pdf = '".$this->db->escape($this->model_pdf)."'"; $sql .= " WHERE rowid = ".(int) $id; $resql = $this->db->query($sql); - if ($resql) { - if (is_object($this->oldcopy)) { // If we have information on old values - if ($this->oldcopy->country_id != $this->country_id) { + if ($resql) + { + if (is_object($this->oldcopy)) // If we have information on old values + { + if ($this->oldcopy->country_id != $this->country_id) + { unset($this->country_code); unset($this->country); } - if ($this->oldcopy->state_id != $this->state_id) { + if ($this->oldcopy->state_id != $this->state_id) + { unset($this->state_code); unset($this->state); } - } else { + } + else + { unset($this->country_code); // We clean this, in the doubt, because it may have been changed after an update of country_id unset($this->country); unset($this->state_code); @@ -1360,9 +1354,11 @@ $nbrowsaffected = $this->db->affected_rows($resql); - if (!$error && $nbrowsaffected) { + if (!$error && $nbrowsaffected) + { // Update information on linked member if it is an update - if (!$nosyncmember && !empty($conf->adherent->enabled)) { + if (!$nosyncmember && !empty($conf->adherent->enabled)) + { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; dol_syslog(get_class($this)."::update update linked member"); @@ -1370,7 +1366,8 @@ $lmember = new Adherent($this->db); $result = $lmember->fetch(0, 0, $this->id); - if ($result > 0) { + if ($result > 0) + { $lmember->company = $this->name; //$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname; // We keep firstname and lastname of member unchanged //$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname; // We keep firstname and lastname of member unchanged @@ -1384,13 +1381,16 @@ $lmember->country_id = $this->country_id; $result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates - if ($result < 0) { + if ($result < 0) + { $this->error = $lmember->error; $this->errors = array_merge($this->errors, $lmember->errors); dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR); $error++; } - } elseif ($result < 0) { + } + elseif ($result < 0) + { $this->error = $lmember->error; $error++; } @@ -1400,50 +1400,63 @@ $action = 'update'; // Actions on extra fields - if (!$error) { + if (!$error) + { $result = $this->insertExtraFields(); - if ($result < 0) { + if ($result < 0) + { $error++; } } // Actions on extra languages - if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) { // For avoid conflicts if trigger used + if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) // For avoid conflicts if trigger used + { $result = $this->insertExtraLanguages(); - if ($result < 0) { + if ($result < 0) + { $error++; } } - if (!$error && $call_trigger) { + if (!$error && $call_trigger) + { // Call trigger $result = $this->call_trigger('COMPANY_MODIFY', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; // End call triggers } - if (!$error) { + if (!$error) + { dol_syslog(get_class($this)."::Update success"); $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } - } else { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { // Doublon $this->error = $langs->trans("ErrorDuplicateField"); $result = -1; - } else { + } + else + { $this->error = $this->db->lasterror(); $result = -2; } $this->db->rollback(); return $result; } - } else { + } + else + { $this->db->rollback(); dol_syslog(get_class($this)."::Update fails verify ".join(',', $this->errors), LOG_WARNING); return -3; @@ -1456,7 +1469,7 @@ * @param int $rowid Id of third party to load * @param string $ref Reference of third party, name (Warning, this can return several records) * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) - * @param string $barcode Barcode of third party to load + * @param string $notused Not used * @param string $idprof1 Prof id 1 of third party (Warning, this can return several records) * @param string $idprof2 Prof id 2 of third party (Warning, this can return several records) * @param string $idprof3 Prof id 3 of third party (Warning, this can return several records) @@ -1467,16 +1480,14 @@ * @param string $ref_alias Name_alias 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, 0 if not found. */ - public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') + public function fetch($rowid, $ref = '', $ref_ext = '', $notused = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') { global $langs; global $conf; - if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) { - return -1; - } - - $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.address, s.datec as date_creation, s.prefix_comm'; + if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1; + + $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm'; $sql .= ', s.status'; $sql .= ', s.price_level'; $sql .= ', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif'; @@ -1490,10 +1501,8 @@ $sql .= ', s.fk_forme_juridique as forme_juridique_code'; $sql .= ', s.webservices_url, s.webservices_key'; $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode'; - $sql .= ', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.transport_mode'; - $sql .= ', s.fk_account, s.tva_assuj'; - $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier'; - $sql .= ', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred'; + $sql .= ', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj'; + $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred'; $sql .= ', s.fk_shipping_method'; $sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms'; $sql .= ', s.order_min_amount, s.supplier_order_min_amount'; @@ -1502,10 +1511,10 @@ $sql .= ', e.libelle as effectif'; $sql .= ', c.code as country_code, c.label as country'; $sql .= ', d.code_departement as state_code, d.nom as state'; - $sql .= ', st.libelle as stcomm, st.picto as stcomm_picto'; + $sql .= ', st.libelle as stcomm'; $sql .= ', te.code as typent_code'; $sql .= ', i.libelle as label_incoterms'; - $sql .= ', sr.remise_client, model_pdf'; + $sql .= ', sr.remise_client'; $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid'; @@ -1517,51 +1526,31 @@ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_remise as sr ON sr.rowid = (SELECT MAX(rowid) FROM '.MAIN_DB_PREFIX.'societe_remise WHERE fk_soc = s.rowid AND entity IN ('.getEntity('discount').'))'; $sql .= ' WHERE s.entity IN ('.getEntity($this->element).')'; - if ($rowid) { - $sql .= ' AND s.rowid = '.$rowid; - } - if ($ref) { - $sql .= " AND s.nom = '".$this->db->escape($ref)."'"; - } - if ($ref_alias) { - $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'"; - } - if ($ref_ext) { - $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'"; - } - if ($barcode) { - $sql .= " AND s.barcode = '".$this->db->escape($barcode)."'"; - } - if ($idprof1) { - $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'"; - } - if ($idprof2) { - $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'"; - } - if ($idprof3) { - $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'"; - } - if ($idprof4) { - $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'"; - } - if ($idprof5) { - $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'"; - } - if ($idprof6) { - $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'"; - } - if ($email) { - $sql .= " AND s.email = '".$this->db->escape($email)."'"; - } + if ($rowid) $sql .= ' AND s.rowid = '.$rowid; + if ($ref) $sql .= " AND s.nom = '".$this->db->escape($ref)."'"; + if ($ref_alias) $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'"; + if ($ref_ext) $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'"; + if ($notused) $sql .= " AND s.ref_int = '".$this->db->escape($notused)."'"; + if ($idprof1) $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'"; + if ($idprof2) $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'"; + if ($idprof3) $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'"; + if ($idprof4) $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'"; + if ($idprof5) $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'"; + if ($idprof6) $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'"; + if ($email) $sql .= " AND s.email = '".$this->db->escape($email)."'"; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); - if ($num > 1) { + if ($num > 1) + { $this->error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.'; dol_syslog($this->error, LOG_ERR); $result = -2; - } elseif ($num) { // $num = 1 + } + elseif ($num) // $num = 1 + { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -1573,6 +1562,7 @@ $this->nom = $obj->name; // deprecated $this->name_alias = $obj->name_alias; $this->ref_ext = $obj->ref_ext; + $this->ref_int = $obj->ref_int; $this->date_creation = $this->db->jdate($obj->date_creation); $this->date_modification = $this->db->jdate($obj->date_modification); @@ -1595,9 +1585,8 @@ $label = ($transcode != 'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm); $this->stcomm_id = $obj->fk_stcomm; // id status prospect $this->status_prospect_label = $label; // label status prospect - $this->stcomm_picto = $obj->stcomm_picto; // picto statut commercial - - $this->email = $obj->email; + + $this->email = $obj->email; $this->socialnetworks = (array) json_decode($obj->socialnetworks, true); $this->url = $obj->url; @@ -1647,25 +1636,22 @@ $this->prefix_comm = $obj->prefix_comm; - $this->remise_percent = $obj->remise_client ? price2num($obj->remise_client) : 0; // 0.000000 must be 0 + $this->remise_percent = price2num($obj->remise_client); // 0.000000 must be 0 $this->remise_supplier_percent = $obj->remise_supplier; $this->mode_reglement_id = $obj->mode_reglement; $this->cond_reglement_id = $obj->cond_reglement; - $this->transport_mode_id = $obj->transport_mode; $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier; $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier; - $this->transport_mode_supplier_id = $obj->transport_mode_supplier; $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null; $this->fk_account = $obj->fk_account; - $this->client = $obj->client; + $this->client = $obj->client; $this->fournisseur = $obj->fournisseur; $this->note = $obj->note_private; // TODO Deprecated for backward comtability $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; - $this->model_pdf = $obj->model_pdf; - $this->modelpdf = $obj->model_pdf; // deprecated + $this->modelpdf = $obj->model_pdf; $this->default_lang = $obj->default_lang; $this->logo = $obj->logo; $this->logo_squarred = $obj->logo_squarred; @@ -1690,26 +1676,27 @@ // multicurrency $this->fk_multicurrency = $obj->fk_multicurrency; $this->multicurrency_code = $obj->multicurrency_code; - $this->model_pdf = $obj->model_pdf; $result = 1; // fetch optionals attributes and labels $this->fetch_optionals(); - } else { + } + else + { $result = 0; } $this->db->free($resql); - } else { + } + else + { $this->error = $this->db->lasterror(); $result = -3; } // Use first price level if level not defined for third party - if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) { - $this->price_level = 1; - } + if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) $this->price_level = 1; return $result; } @@ -1722,13 +1709,11 @@ * @param int $call_trigger 0=No, 1=yes * @return int <0 if KO, 0 if nothing done, >0 if OK */ - public function delete($id, User $fuser = null, $call_trigger = 1) + public function delete($id, User $fuser = null, $call_trigger = 1) { global $langs, $conf, $user; - if (empty($fuser)) { - $fuser = $user; - } + if (empty($fuser)) $fuser = $user; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1739,47 +1724,54 @@ // Test if child exists $objectisused = $this->isObjectUsed($id); - if (empty($objectisused)) { + if (empty($objectisused)) + { $this->db->begin(); // User is mandatory for trigger call - if (!$error && $call_trigger) { + if (!$error && $call_trigger) + { // Call trigger $result = $this->call_trigger('COMPANY_DELETE', $fuser); - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; // End call triggers } - if (!$error) { + if (!$error) + { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $static_cat = new Categorie($this->db); $toute_categs = array(); // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) - if ($this->client || $this->prospect) { + if ($this->client || $this->prospect) + { $toute_categs['customer'] = $static_cat->containing($this->id, Categorie::TYPE_CUSTOMER); } - if ($this->fournisseur) { + if ($this->fournisseur) + { $toute_categs['supplier'] = $static_cat->containing($this->id, Categorie::TYPE_SUPPLIER); } // Remove each "Categorie" - foreach ($toute_categs as $type => $categs_type) { - foreach ($categs_type as $cat) { + foreach ($toute_categs as $type => $categs_type) + { + foreach ($categs_type as $cat) + { $cat->del_type($this, $type); } } } - if (!$error) { - foreach ($this->childtablesoncascade as $tabletodelete) { - $deleteFromObject = explode(':', $tabletodelete); - if (count($deleteFromObject) >= 2) { - $className = str_replace('@', '', $deleteFromObject[0]); - $filepath = $deleteFromObject[1]; - $columnName = $deleteFromObject[2]; + if (!$error) + { + foreach ($this->childtablesoncascade as $tabletodelete) + { + $deleteFromObject=explode(':', $tabletodelete); + if (count($deleteFromObject)>=2) { + $className=str_replace('@', '', $deleteFromObject[0]); + $filepath=$deleteFromObject[1]; + $columnName=$deleteFromObject[2]; if (dol_include_once($filepath)) { $child_object = new $className($this->db); $result = $child_object->deleteByParentField($id, $columnName); @@ -1790,12 +1782,12 @@ } } else { $error++; - $this->errors[] = 'Cannot include child class file '.$filepath; + $this->errors[] = 'Cannot include child class file ' .$filepath; break; } } else { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete; - $sql .= " WHERE fk_soc = ".$id; + $sql = "DELETE FROM " . MAIN_DB_PREFIX . $tabletodelete; + $sql .= " WHERE fk_soc = " . $id; if (!$this->db->query($sql)) { $error++; $this->errors[] = $this->db->lasterror(); @@ -1806,83 +1798,92 @@ } // Removed extrafields - if (!$error) { + if (!$error) + { $result = $this->deleteExtraFields(); - if ($result < 0) { + if ($result < 0) + { $error++; dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); } } // Remove links to subsidiaries companies - if (!$error) { + if (!$error) + { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET parent = NULL"; $sql .= " WHERE parent = ".$id; - if (!$this->db->query($sql)) { + if (!$this->db->query($sql)) + { $error++; $this->errors[] = $this->db->lasterror(); } } // Remove third party - if (!$error) { + if (!$error) + { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe"; $sql .= " WHERE rowid = ".$id; - if (!$this->db->query($sql)) { + if (!$this->db->query($sql)) + { $error++; $this->errors[] = $this->db->lasterror(); } } - if (!$error) { + if (!$error) + { $this->db->commit(); // Delete directory - if (!empty($conf->societe->multidir_output[$entity])) { + if (!empty($conf->societe->multidir_output[$entity])) + { $docdir = $conf->societe->multidir_output[$entity]."/".$id; - if (dol_is_dir($docdir)) { + if (dol_is_dir($docdir)) + { dol_delete_dir_recursive($docdir); } } return 1; - } else { + } + else + { dol_syslog($this->error, LOG_ERR); $this->db->rollback(); return -1; } - } else { - dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); - } + } + else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); return 0; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define third party as a customer * * @return int <0 if KO, >0 if OK */ - public function set_as_client() - { - // phpcs:enable - if ($this->id) { + public function set_as_client() + { + // phpcs:enable + if ($this->id) + { $newclient = 1; - if ($this->client == 2 || $this->client == 3) { - $newclient = 3; //If prospect, we keep prospect tag - } + if ($this->client == 2 || $this->client == 3) $newclient = 3; //If prospect, we keep prospect tag $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET client = ".$newclient; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $this->client = $newclient; return 1; - } else { - return -1; - } + } + else return -1; } return 0; } @@ -1896,21 +1897,23 @@ * @param User $user User who sets the discount * @return int <0 if KO, >0 if OK */ - public function set_remise_client($remise, $note, User $user) - { - // phpcs:enable + public function set_remise_client($remise, $note, User $user) + { + // phpcs:enable global $conf, $langs; // Parameter cleaning $note = trim($note); - if (!$note) { + if (!$note) + { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason")); return -2; } dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id); - if ($this->id) { + if ($this->id) + { $this->db->begin(); $now = dol_now(); @@ -1920,7 +1923,8 @@ $sql .= " SET remise_client = '".$this->db->escape($remise)."'"; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) { + if (!$resql) + { $this->db->rollback(); $this->error = $this->db->error(); return -1; @@ -1935,7 +1939,8 @@ $sql .= ")"; $resql = $this->db->query($sql); - if (!$resql) { + if (!$resql) + { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; @@ -1955,21 +1960,23 @@ * @param User $user User who sets the discount * @return int <0 if KO, >0 if OK */ - public function set_remise_supplier($remise, $note, User $user) - { - // phpcs:enable + public function set_remise_supplier($remise, $note, User $user) + { + // phpcs:enable global $conf, $langs; // Parameter cleaning $note = trim($note); - if (!$note) { + if (!$note) + { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason")); return -2; } dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id); - if ($this->id) { + if ($this->id) + { $this->db->begin(); $now = dol_now(); @@ -1979,7 +1986,8 @@ $sql .= " SET remise_supplier = '".$this->db->escape($remise)."'"; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) { + if (!$resql) + { $this->db->rollback(); $this->error = $this->db->error(); return -1; @@ -1994,7 +2002,8 @@ $sql .= ")"; $resql = $this->db->query($sql); - if (!$resql) { + if (!$resql) + { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; @@ -2005,7 +2014,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add a discount for third party * @@ -2016,9 +2025,9 @@ * @param int $discount_type 0 => customer discount, 1 => supplier discount * @return int <0 if KO, id of discount record if OK */ - public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0) - { - // phpcs:enable + public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0) + { + // phpcs:enable global $langs; // Clean parameters @@ -2026,20 +2035,24 @@ $desc = trim($desc); // Check parameters - if (!$remise > 0) { + if (!$remise > 0) + { $this->error = $langs->trans("ErrorWrongValueForParameter", "1"); return -1; } - if (!$desc) { + if (!$desc) + { $this->error = $langs->trans("ErrorWrongValueForParameter", "3"); return -2; } - if ($this->id > 0) { + if ($this->id > 0) + { // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $vatrate, $reg)) { + if (preg_match('/\((.*)\)/', $vatrate, $reg)) + { $vat_src_code = $reg[1]; $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } @@ -2055,21 +2068,23 @@ $discount->amount_tva = $discount->multicurrency_amount_tva = price2num($remise * $vatrate / 100, 'MT'); $discount->amount_ttc = $discount->multicurrency_amount_ttc = price2num($discount->amount_ht + $discount->amount_tva, 'MT'); - $discount->tva_tx = price2num($vatrate); + $discount->tva_tx = price2num($vatrate, 'MT'); $discount->vat_src_code = $vat_src_code; $discount->description = $desc; $result = $discount->create($user); - if ($result > 0) { + if ($result > 0) + { return $result; - } else { + } + else + { $this->error = $discount->error; return -3; } - } else { - return 0; - } + } + else return 0; } /** @@ -2081,15 +2096,18 @@ * @param int $discount_type 0 => customer discount, 1 => supplier discount * @return int <0 if KO, Credit note amount otherwise */ - public function getAvailableDiscounts($user = '', $filter = '', $maxvalue = 0, $discount_type = 0) + public function getAvailableDiscounts($user = '', $filter = '', $maxvalue = 0, $discount_type = 0) { require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; $discountstatic = new DiscountAbsolute($this->db); $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type); - if ($result >= 0) { + if ($result >= 0) + { return $result; - } else { + } + else + { $this->error = $discountstatic->error; return -1; } @@ -2098,13 +2116,11 @@ /** * Return array of sales representatives * - * @param User $user Object user - * @param int $mode 0=Array with properties, 1=Array of id. - * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb' - * @param string $sortorder Sort order, separated by comma. Example: 'ASC,DESC'; - * @return array Array of sales representatives of third party - */ - public function getSalesRepresentatives(User $user, $mode = 0, $sortfield = null, $sortorder = null) + * @param User $user Object user + * @param int $mode 0=Array with properties, 1=Array of id. + * @return array Array of sales representatives of third party + */ + public function getSalesRepresentatives(User $user, $mode = 0) { global $conf; @@ -2112,30 +2128,29 @@ $sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo"; $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u"; - if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) + { $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql .= " WHERE ((ug.fk_user = sc.fk_user"; $sql .= " AND ug.entity = ".$conf->entity.")"; $sql .= " OR u.admin = 1)"; - } else { + } + else $sql .= " WHERE entity in (0, ".$conf->entity.")"; - } $sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id; - if (empty($sortfield) && empty($sortorder)) { - $sortfield = 'u.lastname,u.firstname'; - $sortorder = 'ASC,ASC'; - } - $sql .= $this->db->order($sortfield, $sortorder); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($resql); - if (empty($mode)) { + if (empty($mode)) + { $reparray[$i]['id'] = $obj->rowid; $reparray[$i]['lastname'] = $obj->lastname; $reparray[$i]['firstname'] = $obj->firstname; @@ -2147,19 +2162,22 @@ $reparray[$i]['entity'] = $obj->entity; $reparray[$i]['login'] = $obj->login; $reparray[$i]['photo'] = $obj->photo; - } else { + } + else + { $reparray[] = $obj->rowid; } $i++; } return $reparray; - } else { + } + else { dol_print_error($this->db); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set the price level * @@ -2167,17 +2185,19 @@ * @param User $user Use making change * @return int <0 if KO, >0 if OK */ - public function set_price_level($price_level, User $user) - { - // phpcs:enable - if ($this->id) { + public function set_price_level($price_level, User $user) + { + // phpcs:enable + if ($this->id) + { $now = dol_now(); $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET price_level = '".$this->db->escape($price_level)."'"; $sql .= " WHERE rowid = ".$this->id; - if (!$this->db->query($sql)) { + if (!$this->db->query($sql)) + { dol_print_error($this->db); return -1; } @@ -2186,7 +2206,8 @@ $sql .= " (datec, fk_soc, price_level, fk_user_author)"; $sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")"; - if (!$this->db->query($sql)) { + if (!$this->db->query($sql)) + { dol_print_error($this->db); return -1; } @@ -2195,7 +2216,7 @@ return -1; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add link to sales representative * @@ -2203,59 +2224,69 @@ * @param int $commid Id of user * @return int <=0 if KO, >0 if OK */ - public function add_commercial(User $user, $commid) + public function add_commercial(User $user, $commid) { // phpcs:enable $error = 0; - if ($this->id > 0 && $commid > 0) { - $this->db->begin(); - - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; - $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; - - $resql = $this->db->query($sql); - if (!$resql) { - dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); - $error++; - } - } - - if (!$error) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux"; - $sql .= " (fk_soc, fk_user)"; - $sql .= " VALUES (".$this->id.", ".$commid.")"; - - $resql = $this->db->query($sql); - if (!$resql) { - dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); - $error++; - } - } - - if (!$error) { + if ($this->id > 0 && $commid > 0) + { + $this->db->begin(); + + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; + $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; + + $resql = $this->db->query($sql); + if (!$resql) + { + dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); + $error++; + } + } + + if (!$error) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux"; + $sql .= " (fk_soc, fk_user)"; + $sql .= " VALUES (".$this->id.", ".$commid.")"; + + $resql = $this->db->query($sql); + if (!$resql) + { + dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); + $error++; + } + } + + if (!$error) + { $this->context = array('commercial_modified'=>$commid); $result = $this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE', $user); - if ($result < 0) { - $error++; - } - } - - if (!$error) { - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; + if ($result < 0) + { + $error++; + } + } + + if (!$error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; } } return 0; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add link to sales representative * @@ -2263,22 +2294,22 @@ * @param int $commid Id of user * @return void */ - public function del_commercial(User $user, $commid) - { - // phpcs:enable + public function del_commercial(User $user, $commid) + { + // phpcs:enable $error = 0; $this->context = array('commercial_modified'=>$commid); $result = $this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE', $user); - if ($result < 0) { - $error++; - } - - if ($this->id > 0 && $commid > 0) { + if ($result < 0) $error++; + + if ($this->id > 0 && $commid > 0) + { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; - if (!$this->db->query($sql)) { + if (!$this->db->query($sql)) + { dol_syslog(get_class($this)."::del_commercial Erreur"); } } @@ -2295,56 +2326,61 @@ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string String with URL */ - public function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1) + public function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1) { global $conf, $langs, $hookmanager; - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips $name = $this->name ? $this->name : $this->nom; - if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) { - if (empty($option) && $this->client > 0) { - $option = 'customer'; - } - if (empty($option) && $this->fournisseur > 0) { - $option = 'supplier'; - } - } - - if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) { + if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) { + if (empty($option) && $this->client > 0) $option = 'customer'; + if (empty($option) && $this->fournisseur > 0) $option = 'supplier'; + } + + if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) + { $code = ''; - if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) { + if (($this->client) && (!empty($this->code_client)) + && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2 + ) + ) + { $code = $this->code_client.' - '; } - if (($this->fournisseur) && (!empty($this->code_fournisseur)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3)) { + if (($this->fournisseur) && (!empty($this->code_fournisseur)) + && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3 + ) + ) + { $code .= $this->code_fournisseur.' - '; } - if ($code) { - if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) { - $name = $code.' '.$name; - } else { - $name = $code; - } - } - } - - if (!empty($this->name_alias)) { - $name .= ' ('.$this->name_alias.')'; - } + if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) + { + $name = $code.' '.$name; + } + else + { + $name = $code; + } + } + + if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')'; $result = ''; $label = ''; $linkstart = ''; $linkend = ''; - if (!empty($this->logo) && class_exists('Form')) { + if (!empty($this->logo) && class_exists('Form')) + { $label .= '<div class="photointooltip">'; $label .= Form::showphoto('societe', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. $label .= '</div><div style="clear: both;"></div>'; - } elseif (!empty($this->logo_squarred) && class_exists('Form')) { + } + elseif (!empty($this->logo_squarred) && class_exists('Form')) + { /*$label.= '<div class="photointooltip">'; $label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. $label.= '</div><div style="clear: both;"></div>';*/ @@ -2352,85 +2388,83 @@ $label .= '<div class="centpercent">'; - if ($option == 'customer' || $option == 'compta' || $option == 'category') { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Customer").'</u>'; + if ($option == 'customer' || $option == 'compta' || $option == 'category') + { + $label .= '<u>'.$langs->trans("Customer").'</u>'; + $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id; + } + elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) + { + $label .= '<u>'.$langs->trans("Prospect").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id; - } elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Prospect").'</u>'; - $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id; - } elseif ($option == 'supplier' || $option == 'category_supplier') { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Supplier").'</u>'; + } + elseif ($option == 'supplier' || $option == 'category_supplier') + { + $label .= '<u>'.$langs->trans("Supplier").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id; - } elseif ($option == 'agenda') { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>'; + } + elseif ($option == 'agenda') + { + $label .= '<u>'.$langs->trans("ThirdParty").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id; - } elseif ($option == 'project') { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>'; + } + elseif ($option == 'project') + { + $label .= '<u>'.$langs->trans("ThirdParty").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id; - } elseif ($option == 'margin') { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>'; + } + elseif ($option == 'margin') + { + $label .= '<u>'.$langs->trans("ThirdParty").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1'; - } elseif ($option == 'contact') { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>'; + } + elseif ($option == 'contact') + { + $label .= '<u>'.$langs->trans("ThirdParty").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id; - } elseif ($option == 'ban') { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>'; + } + elseif ($option == 'ban') + { + $label .= '<u>'.$langs->trans("ThirdParty").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id; } // By default - if (empty($linkstart)) { - $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ThirdParty").'</u>'; + if (empty($linkstart)) + { + $label .= '<u>'.$langs->trans("ThirdParty").'</u>'; $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id; } + + if (!empty($this->name)) + { + $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->name; + if (!empty($this->name_alias)) $label .= ' ('.$this->name_alias.')'; + } + $label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email; + if (!empty($this->country_code)) + $label .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code; + if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) + $label .= '<br><b>'.$langs->trans('VATIntra').':</b> '.$this->tva_intra; + if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) + { + if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label .= '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1; + if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label .= '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2; + if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label .= '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3; + if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label .= '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4; + if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label .= '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5; + if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label .= '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6; + } + if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) + $label .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client; + if (!empty($this->code_fournisseur) && $this->fournisseur) + $label .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur; + if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) + $label .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client); + if (!empty($conf->accounting->enabled) && $this->fournisseur) + $label .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur; if (isset($this->status)) { - $label .= ' '.$this->getLibStatut(5); - } - - if (!empty($this->name)) { - $label .= '<br><b>'.$langs->trans('Name').':</b> '.dol_escape_htmltag($this->name); - if (!empty($this->name_alias)) { - $label .= ' ('.dol_escape_htmltag($this->name_alias).')'; - } - } - $label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email; - if (!empty($this->country_code)) { - $label .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code; - } - if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) { - $label .= '<br><b>'.$langs->trans('VATIntra').':</b> '.dol_escape_htmltag($this->tva_intra); - } - if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) { - if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) { - $label .= '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1; - } - if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) { - $label .= '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2; - } - if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) { - $label .= '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3; - } - if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) { - $label .= '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4; - } - if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) { - $label .= '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5; - } - if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) { - $label .= '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6; - } - } - if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) { - $label .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client; - } - if (!empty($this->code_fournisseur) && $this->fournisseur) { - $label .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur; - } - if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) { - $label .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client); - } - if (!empty($conf->accounting->enabled) && $this->fournisseur) { - $label .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur; + $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5); } $label .= '</div>'; @@ -2438,24 +2472,22 @@ $linkstart .= (!empty($this->canvas) ? '&canvas='.$this->canvas : ''); // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $linkstart .= '&save_lastsearch_values=1'; - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $linkstart .= '&save_lastsearch_values=1'; $linkstart .= '"'; $linkclose = ''; - if (empty($notooltip)) { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { $label = $langs->trans("ShowCompany"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' class="classfortooltip refurl"'; - /* + /* $hookmanager->initHooks(array('thirdpartydao')); $parameters=array('id'=>$this->id); $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -2466,37 +2498,23 @@ $linkend = '</a>'; global $user; - if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) { + if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) + { $linkstart = ''; $linkend = ''; } $result .= $linkstart; - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); - } + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($name, $maxlen) : $name); $result .= $linkend; global $action; $hookmanager->initHooks(array('thirdpartydao')); - $parameters = array( - 'id'=>$this->id, - 'getnomurl'=>$result, - 'withpicto '=> $withpicto, - 'option'=> $option, - 'maxlen'=> $maxlen, - 'notooltip'=> $notooltip, - 'save_lastsearch_value'=> $save_lastsearch_value - ); + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($reshook > 0) $result = $hookmanager->resPrint; + else $result .= $hookmanager->resPrint; return $result; } @@ -2507,7 +2525,7 @@ * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label of status */ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0) { return $this->LibStatut($this->status, $mode); } @@ -2520,18 +2538,17 @@ * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto * @return string Status label */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable + public function LibStatut($status, $mode = 0) + { + // phpcs:enable global $langs; $langs->load('companies'); $statusType = 'status4'; - if ($status == 0) { - $statusType = 'status6'; - } - - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + if ($status == 0) $statusType = 'status5'; + + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { $this->labelStatus[0] = $langs->trans("ActivityCeased"); $this->labelStatus[1] = $langs->trans("InActivity"); $this->labelStatusShort[0] = $langs->trans("ActivityCeased"); @@ -2539,55 +2556,53 @@ } return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of contacts emails existing for third party * * @param int $addthirdparty 1=Add also a record for thirdparty email * @return array Array of contacts emails */ - public function thirdparty_and_contact_email_array($addthirdparty = 0) - { - // phpcs:enable + public function thirdparty_and_contact_email_array($addthirdparty = 0) + { + // phpcs:enable global $langs; $contact_emails = $this->contact_property_array('email', 1); - if ($this->email && $addthirdparty) { - if (empty($this->name)) { - $this->name = $this->nom; - } + if ($this->email && $addthirdparty) + { + if (empty($this->name)) $this->name = $this->nom; $contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">"; } //var_dump($contact_emails) return $contact_emails; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of contacts mobile phone existing for third party * * @return array Array of contacts emails */ - public function thirdparty_and_contact_phone_array() - { - // phpcs:enable + public function thirdparty_and_contact_phone_array() + { + // phpcs:enable global $langs; $contact_phone = $this->contact_property_array('mobile'); - if (!empty($this->phone)) { // If a phone of thirdparty is defined, we add it ot mobile of contacts - if (empty($this->name)) { - $this->name = $this->nom; - } + if (!empty($this->phone)) // If a phone of thirdparty is defined, we add it ot mobile of contacts + { + if (empty($this->name)) $this->name = $this->nom; // TODO: Tester si tel non deja present dans tableau contact $contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">"; } return $contact_phone; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of contacts emails or mobile existing for third party * @@ -2595,9 +2610,9 @@ * @param int $hidedisabled 1=Hide contact if disabled * @return array Array of contacts emails or mobile. Example: array(id=>'Name <email>') */ - public function contact_property_array($mode = 'email', $hidedisabled = 0) - { - // phpcs:enable + public function contact_property_array($mode = 'email', $hidedisabled = 0) + { + // phpcs:enable global $langs; $contact_property = array(); @@ -2609,45 +2624,49 @@ $sql .= " ORDER BY lastname, firstname"; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $nump = $this->db->num_rows($resql); - if ($nump) { + if ($nump) + { $sepa = "("; $sepb = ")"; - if ($mode == 'email') { + if ($mode == 'email') + { //$sepa="<"; $sepb=">"; $sepa = "<"; $sepb = ">"; } $i = 0; - while ($i < $nump) { + while ($i < $nump) + { $obj = $this->db->fetch_object($resql); - if ($mode == 'email') { - $property = $obj->email; - } elseif ($mode == 'mobile') { - $property = $obj->phone_mobile; - } else { - $property = $obj->$mode; - } + if ($mode == 'email') $property = $obj->email; + elseif ($mode == 'mobile') $property = $obj->phone_mobile; + else $property = $obj->$mode; // Show all contact. If hidedisabled is 1, showonly contacts with status = 1 - if ($obj->status == 1 || empty($hidedisabled)) { - if (empty($property)) { - if ($mode == 'email') { - $property = $langs->transnoentitiesnoconv("NoEMail"); - } elseif ($mode == 'mobile') { - $property = $langs->transnoentitiesnoconv("NoMobilePhone"); - } + if ($obj->status == 1 || empty($hidedisabled)) + { + if (empty($property)) + { + if ($mode == 'email') $property = $langs->transnoentitiesnoconv("NoEMail"); + elseif ($mode == 'mobile') $property = $langs->transnoentitiesnoconv("NoMobilePhone"); } - if (!empty($obj->poste)) { + if (!empty($obj->poste)) + { $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); - } else { + } + else + { $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); } } $i++; } } - } else { + } + else + { dol_print_error($this->db); } return $contact_property; @@ -2660,24 +2679,29 @@ * * @return array array of contacts */ - public function contact_array() - { - // phpcs:enable + public function contact_array() + { + // phpcs:enable $contacts = array(); $sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $nump = $this->db->num_rows($resql); - if ($nump) { + if ($nump) + { $i = 0; - while ($i < $nump) { + while ($i < $nump) + { $obj = $this->db->fetch_object($resql); $contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname); $i++; } } - } else { + } + else + { dol_print_error($this->db); } return $contacts; @@ -2689,19 +2713,22 @@ * * @return array $contacts array of contacts */ - public function contact_array_objects() - { - // phpcs:enable + public function contact_array_objects() + { + // phpcs:enable require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $contacts = array(); $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $nump = $this->db->num_rows($resql); - if ($nump) { + if ($nump) + { $i = 0; - while ($i < $nump) { + while ($i < $nump) + { $obj = $this->db->fetch_object($resql); $contact = new Contact($this->db); $contact->fetch($obj->rowid); @@ -2709,13 +2736,15 @@ $i++; } } - } else { + } + else + { dol_print_error($this->db); } return $contacts; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return property of contact from its id * @@ -2723,84 +2752,85 @@ * @param string $mode 'email' or 'mobile' * @return string Email of contact with format: "Full name <email>" */ - public function contact_get_property($rowid, $mode) - { - // phpcs:enable + public function contact_get_property($rowid, $mode) + { + // phpcs:enable $contact_property = ''; - if (empty($rowid)) { - return ''; - } + if (empty($rowid)) return ''; $sql = "SELECT rowid, email, phone_mobile, lastname, firstname"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople"; - $sql .= " WHERE rowid = ".((int) $rowid); + $sql .= " WHERE rowid = '".$rowid."'"; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $nump = $this->db->num_rows($resql); - if ($nump) { + if ($nump) + { $obj = $this->db->fetch_object($resql); - if ($mode == 'email') { - $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">"; - } elseif ($mode == 'mobile') { - $contact_property = $obj->phone_mobile; - } + if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">"; + elseif ($mode == 'mobile') $contact_property = $obj->phone_mobile; } return $contact_property; - } else { + } + else + { dol_print_error($this->db); } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return bank number property of thirdparty (label or rum) * * @param string $mode 'label' or 'rum' or 'format' - * @return string Bank label or RUM or '' if no bank account found - */ - public function display_rib($mode = 'label') - { - // phpcs:enable + * @return string Bank number + */ + public function display_rib($mode = 'label') + { + // phpcs:enable require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; $bac = new CompanyBankAccount($this->db); $bac->fetch(0, $this->id); - if ($bac->id > 0) { // If a bank account has been found for company $this->id - if ($mode == 'label') { - return $bac->getRibLabel(true); - } elseif ($mode == 'rum') { - if (empty($bac->rum)) { - require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; - $prelevement = new BonPrelevement($this->db); - $bac->fetch_thirdparty(); - $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id); - } - return $bac->rum; - } elseif ($mode == 'format') { - return $bac->frstrecur; - } else { - return 'BadParameterToFunctionDisplayRib'; - } - } else { - return ''; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + if ($mode == 'label') + { + return $bac->getRibLabel(true); + } + elseif ($mode == 'rum') + { + if (empty($bac->rum)) + { + require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; + $prelevement = new BonPrelevement($this->db); + $bac->fetch_thirdparty(); + $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id); + } + return $bac->rum; + } + elseif ($mode == 'format') + { + return $bac->frstrecur; + } + + return 'BadParameterToFunctionDisplayRib'; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return Array of RIB * * @return array|int 0 if KO, Array of CompanyBanckAccount if OK */ - public function get_all_rib() - { - // phpcs:enable + public function get_all_rib() + { + // phpcs:enable require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id; $result = $this->db->query($sql); @@ -2831,19 +2861,19 @@ * @param int $type Should be 0 to say customer * @return void */ - public function get_codeclient($objsoc = 0, $type = 0) - { - // phpcs:enable + public function get_codeclient($objsoc = 0, $type = 0) + { + // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) + { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) { + foreach ($dirsociete as $dirroot) + { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) { - break; - } + if ($res) break; } $mod = new $module(); @@ -2863,19 +2893,19 @@ * @param int $type Should be 1 to say supplier * @return void */ - public function get_codefournisseur($objsoc = 0, $type = 1) - { - // phpcs:enable + public function get_codefournisseur($objsoc = 0, $type = 1) + { + // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) + { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) { + foreach ($dirsociete as $dirroot) + { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) { - break; - } + if ($res) break; } $mod = new $module(); @@ -2892,35 +2922,31 @@ * * @return int 0=No, 1=Yes */ - public function codeclient_modifiable() - { - // phpcs:enable + public function codeclient_modifiable() + { + // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) + { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) { + foreach ($dirsociete as $dirroot) + { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) { - break; - } + if ($res) break; } $mod = new $module(); dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module); - if ($mod->code_modifiable_null && !$this->code_client) { - return 1; - } - if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) { - return 1; - } - if ($mod->code_modifiable) { - return 1; // A mettre en dernier - } + if ($mod->code_modifiable_null && !$this->code_client) return 1; + if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1; + if ($mod->code_modifiable) return 1; // A mettre en dernier return 0; - } else { + } + else + { return 0; } } @@ -2932,41 +2958,37 @@ * * @return int 0=No, 1=Yes */ - public function codefournisseur_modifiable() - { - // phpcs:enable + public function codefournisseur_modifiable() + { + // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) + { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) { + foreach ($dirsociete as $dirroot) + { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) { - break; - } + if ($res) break; } $mod = new $module(); dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module); - if ($mod->code_modifiable_null && !$this->code_fournisseur) { - return 1; - } - if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) { - return 1; - } - if ($mod->code_modifiable) { - return 1; // A mettre en dernier - } + if ($mod->code_modifiable_null && !$this->code_fournisseur) return 1; + if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1; + if ($mod->code_modifiable) return 1; // A mettre en dernier return 0; - } else { + } + else + { return 0; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Check customer code * @@ -2975,39 +2997,35 @@ * -2 ErrorCustomerCodeRequired * -3 ErrorCustomerCodeAlreadyUsed * -4 ErrorPrefixRequired - * -5 NotConfigured - Setup empty so any value may be ok or not - * -6 Other (see this->error) - */ - public function check_codeclient() - { - // phpcs:enable + */ + public function check_codeclient() + { + // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) + { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) { + foreach ($dirsociete as $dirroot) + { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) { - break; - } + if ($res) break; } $mod = new $module(); - dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module); - $result = $mod->verif($this->db, $this->code_client, $this, 0); - if ($result) { // If error - $this->error = $mod->error; - $this->errors = $mod->errors; - } + dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module); + $result = $mod->verif($this->db, $this->code_client, $this, 0); return $result; - } else { + } + else + { return 0; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Check supplier code * @@ -3016,34 +3034,30 @@ * -2 ErrorCustomerCodeRequired * -3 ErrorCustomerCodeAlreadyUsed * -4 ErrorPrefixRequired - * -5 NotConfigured - Setup empty so any value may be ok or not - * -6 Other (see this->error) - */ - public function check_codefournisseur() - { - // phpcs:enable + */ + public function check_codefournisseur() + { + // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) + { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) { + foreach ($dirsociete as $dirroot) + { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) { - break; - } + if ($res) break; } $mod = new $module(); dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module); $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1); - if ($result) { // If error - $this->error = $mod->error; - $this->errors = $mod->errors; - } return $result; - } else { + } + else + { return 0; } } @@ -3057,107 +3071,110 @@ * @param string $type Type of thirdparty ('customer' or 'supplier') * @return int 0 if OK, <0 if $type is not valid */ - public function get_codecompta($type) - { - // phpcs:enable + public function get_codecompta($type) + { + // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) { + if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) + { $res = false; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) { + foreach ($dirsociete as $dirroot) + { $res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php'); - if ($res) { - break; - } - } - - if ($res) { + if ($res) break; + } + + if ($res) + { $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON; $mod = new $classname; // Set code count in $mod->code $result = $mod->get_code($this->db, $this, $type); - if ($type == 'customer') { - $this->code_compta = $mod->code; - } elseif ($type == 'supplier') { - $this->code_compta_fournisseur = $mod->code; - } + if ($type == 'customer') $this->code_compta = $mod->code; + elseif ($type == 'supplier') $this->code_compta_fournisseur = $mod->code; return $result; - } else { + } + else + { $this->error = 'ErrorAccountancyCodeNotDefined'; return -1; } - } else { - if ($type == 'customer') { - $this->code_compta = ''; - } elseif ($type == 'supplier') { - $this->code_compta_fournisseur = ''; - } + } + else + { + if ($type == 'customer') $this->code_compta = ''; + elseif ($type == 'supplier') $this->code_compta_fournisseur = ''; return 0; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define parent commany of current company * * @param int $id Id of thirdparty to set or '' to remove * @return int <0 if KO, >0 if OK */ - public function set_parent($id) - { - // phpcs:enable - if ($this->id) { + public function set_parent($id) + { + // phpcs:enable + if ($this->id) + { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET parent = ".($id > 0 ? $id : "null"); $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this).'::set_parent', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $this->parent = $id; return 1; - } else { + } + else + { return -1; } - } else { - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Returns if a profid sould be verified to be unique - * - * @param int $idprof 1,2,3,4,5,6 (Example: 1=siren, 2=siret, 3=naf, 4=rcs/rm, 5=eori, 6=idprof6) - * @return boolean true if the ID must be unique - */ - public function id_prof_verifiable($idprof) - { - // phpcs:enable + } + else return -1; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Returns if a profid sould be verified + * + * @param int $idprof 1,2,3,4,5,6 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm,5=idprof5,6=idprof6) + * @return boolean true , false + */ + public function id_prof_verifiable($idprof) + { + // phpcs:enable global $conf; - switch ($idprof) { + switch ($idprof) + { case 1: - $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false : true); + $ret = (!$conf->global->SOCIETE_IDPROF1_UNIQUE ?false:true); break; case 2: - $ret = (empty($conf->global->SOCIETE_IDPROF2_UNIQUE) ? false : true); + $ret = (!$conf->global->SOCIETE_IDPROF2_UNIQUE ?false:true); break; case 3: - $ret = (empty($conf->global->SOCIETE_IDPROF3_UNIQUE) ? false : true); + $ret = (!$conf->global->SOCIETE_IDPROF3_UNIQUE ?false:true); break; case 4: - $ret = (empty($conf->global->SOCIETE_IDPROF4_UNIQUE) ? false : true); + $ret = (!$conf->global->SOCIETE_IDPROF4_UNIQUE ?false:true); break; case 5: - $ret = (empty($conf->global->SOCIETE_IDPROF5_UNIQUE) ? false : true); + $ret = (!$conf->global->SOCIETE_IDPROF5_UNIQUE ?false:true); break; case 6: - $ret = (empty($conf->global->SOCIETE_IDPROF6_UNIQUE) ? false : true); + $ret = (!$conf->global->SOCIETE_IDPROF6_UNIQUE ?false:true); break; default: $ret = false; @@ -3166,7 +3183,7 @@ return $ret; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Verify if a profid exists into database for others thirds * @@ -3175,12 +3192,13 @@ * @param int $socid Id of thirdparty to exclude (if update) * @return boolean True if exists, False if not */ - public function id_prof_exists($idprof, $value, $socid = 0) - { - // phpcs:enable + public function id_prof_exists($idprof, $value, $socid = 0) + { + // phpcs:enable $field = $idprof; - switch ($idprof) { // For backward compatibility + switch ($idprof) // For backward compatibility + { case '1': case 'idprof1': $field = "siren"; @@ -3203,28 +3221,26 @@ case '6': $field = "idprof6"; break; - } + } //Verify duplicate entries - $sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$this->db->escape($value)."' AND entity IN (".getEntity('societe').")"; - if ($socid) { - $sql .= " AND rowid <> ".$socid; - } + $sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")"; + if ($socid) $sql .= " AND rowid <> ".$socid; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $obj = $this->db->fetch_object($resql); $count = $obj->idprof; - } else { + } + else + { $count = 0; print $this->db->error(); } $this->db->free($resql); - if ($count > 0) { - return true; - } else { - return false; - } + if ($count > 0) return true; + else return false; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3236,166 +3252,144 @@ * @return int <=0 if KO, >0 if OK * TODO better to have this in a lib than into a business class */ - public function id_prof_check($idprof, $soc) - { - // phpcs:enable + public function id_prof_check($idprof, $soc) + { + // phpcs:enable global $conf; $ok = 1; - if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) { - return 1; - } + if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1; // Check SIREN if country FR - if ($idprof == 1 && $soc->country_code == 'FR') { + if ($idprof == 1 && $soc->country_code == 'FR') + { $chaine = trim($this->idprof1); $chaine = preg_replace('/(\s)/', '', $chaine); - if (!is_numeric($chaine)) { - return -1; - } - if (dol_strlen($chaine) != 9) { - return -1; - } + if (!is_numeric($chaine)) return -1; + if (dol_strlen($chaine) != 9) return -1; // on prend chaque chiffre un par un // si son index (position dans la chaîne en commence à 0 au premier caractère) est impair // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 // on ajoute cette valeur à la somme totale - $sum = 0; - for ($index = 0; $index < 9; $index++) { + + for ($index = 0; $index < 9; $index++) + { $number = (int) $chaine[$index]; - if (($index % 2) != 0) { - if (($number *= 2) > 9) { - $number -= 9; - } - } + if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; } $sum += $number; } // le numéro est valide si la somme des chiffres est multiple de 10 - if (($sum % 10) != 0) { - return -1; - } + if (($sum % 10) != 0) return -1; } // Verifie SIRET si pays FR - if ($idprof == 2 && $soc->country_code == 'FR') { + if ($idprof == 2 && $soc->country_code == 'FR') + { $chaine = trim($this->idprof2); $chaine = preg_replace('/(\s)/', '', $chaine); - if (!is_numeric($chaine)) { - return -1; - } - if (dol_strlen($chaine) != 14) { - return -1; - } + if (!is_numeric($chaine)) return -1; + if (dol_strlen($chaine) != 14) return -1; // on prend chaque chiffre un par un // si son index (position dans la chaîne en commence à 0 au premier caractère) est pair // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 // on ajoute cette valeur à la somme totale - $sum = 0; - for ($index = 0; $index < 14; $index++) { + + for ($index = 0; $index < 14; $index++) + { $number = (int) $chaine[$index]; - if (($index % 2) == 0) { - if (($number *= 2) > 9) { - $number -= 9; - } - } + if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; } $sum += $number; } // le numéro est valide si la somme des chiffres est multiple de 10 - if (($sum % 10) != 0) { - return -1; - } + if (($sum % 10) != 0) return -1; } //Verify CIF/NIF/NIE if pays ES //Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad - if ($idprof == 1 && $soc->country_code == 'ES') { + if ($idprof == 1 && $soc->country_code == 'ES') + { $string = trim($this->idprof1); $string = preg_replace('/(\s)/', '', $string); $string = strtoupper($string); //Check format - if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) { - return 0; - } + if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) + return 0; $num = array(); + for ($i = 0; $i < 9; $i++) + { + $num[$i] = substr($string, $i, 1); + } + + //Check NIF + if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) + return 1; + else + return -1; + + //algorithm checking type code CIF + $sum = $num[2] + $num[4] + $num[6]; + for ($i = 1; $i < 8; $i += 2) + $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1)); + $n = 10 - substr($sum, strlen($sum) - 1, 1); + + //Chek special NIF + if (preg_match('/^[KLM]{1}/', $string)) + if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) + return 1; + else + return -1; + + //Check CIF + if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) + if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) + return 2; + else + return -2; + + //Check NIE T + if (preg_match('/^[T]{1}/', $string)) + if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) + return 3; + else + return -3; + + //Check NIE XYZ + if (preg_match('/^[XYZ]{1}/', $string)) + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1)) + return 3; + else + return -3; + + //Can not be verified + return -4; + } + + //Verify NIF if country is PT + //Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad + if ($idprof == 1 && $soc->country_code == 'PT') + { + $string = trim($this->idprof1); + $string = preg_replace('/(\s)/', '', $string); + for ($i = 0; $i < 9; $i++) { $num[$i] = substr($string, $i, 1); } - - //Check NIF - if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) { - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) { - return 1; - } else { - return -1; - } - } - - //algorithm checking type code CIF - $sum = $num[2] + $num[4] + $num[6]; - for ($i = 1; $i < 8; $i += 2) { - $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1)); - } - $n = 10 - substr($sum, strlen($sum) - 1, 1); - - //Chek special NIF - if (preg_match('/^[KLM]{1}/', $string)) { - if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) { - return 1; - } else { - return -1; - } - } - - //Check CIF - if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) { - if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) { - return 2; - } else { - return -2; - } - } - - //Check NIE T - if (preg_match('/^[T]{1}/', $string)) { - if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) { - return 3; - } else { - return -3; - } - } - - //Check NIE XYZ - if (preg_match('/^[XYZ]{1}/', $string)) { - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1)) { - return 3; - } else { - return -3; - } - } - - //Can not be verified - return -4; - } - - //Verify NIF if country is PT - //Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad - if ($idprof == 1 && $soc->country_code == 'PT') { - $string = trim($this->idprof1); - $string = preg_replace('/(\s)/', '', $string); //Check NIF if (preg_match('/(^[0-9]{9}$)/', $string)) { return 1; - } else { + } + else { return -1; } } @@ -3403,7 +3397,7 @@ return $ok; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return an url to check online a professional id or empty string * @@ -3412,9 +3406,9 @@ * @return string Url or empty string if no URL known * TODO better in a lib than into business class */ - public function id_prof_url($idprof, $thirdparty) - { - // phpcs:enable + public function id_prof_url($idprof, $thirdparty) + { + // phpcs:enable global $conf, $langs, $hookmanager; $url = ''; @@ -3429,7 +3423,7 @@ } // TODO Move links to validate professional ID into a dictionary table "country" + "link" - $strippedIdProf1 = str_replace(' ', '', $thirdparty->idprof1); + $strippedIdProf1 = str_replace(' ', '', $thirdparty->idprof1); if ($idprof == 1 && $thirdparty->country_code == 'FR') { $url = 'http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1; // See also http://avis-situation-sirene.insee.fr/ } @@ -3449,7 +3443,8 @@ if ($url) { return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>'; } - } else { + } + else { return $hookmanager->resPrint; } @@ -3462,15 +3457,18 @@ * * @return bool true if the company has projects, false otherwise */ - public function has_projects() - { - // phpcs:enable + public function has_projects() + { + // phpcs:enable $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $obj = $this->db->fetch_object($resql); $count = $obj->numproj; - } else { + } + else + { $count = 0; print $this->db->error(); } @@ -3485,7 +3483,7 @@ * @param int $id Id of thirdparty to load * @return void */ - public function info($id) + public function info($id) { $sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,"; $sql .= " fk_user_creat, fk_user_modif"; @@ -3493,8 +3491,10 @@ $sql .= " WHERE s.rowid = ".$id; $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -3517,7 +3517,9 @@ } $this->db->free($result); - } else { + } + else + { dol_print_error($this->db); } } @@ -3527,7 +3529,7 @@ * * @return boolean true=is a company, false=a and user */ - public function isACompany() + public function isACompany() { global $conf; @@ -3535,15 +3537,15 @@ $isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1; // 0 by default if (!empty($this->tva_intra)) { $isacompany = 1; - } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) { + } + elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) { $isacompany = 1; - } elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') { + } + elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') + { // TODO Add a field is_a_company into dictionary - if (preg_match('/^TE_PRIVATE/', $this->typent_code)) { - $isacompany = 0; - } else { - $isacompany = 1; - } + if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany = 0; + else $isacompany = 1; } return $isacompany; @@ -3554,7 +3556,7 @@ * * @return boolean true = country inside EEC, false = country outside EEC */ - public function isInEEC() + public function isInEEC() { require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; return isInEEC($this); @@ -3566,50 +3568,55 @@ * * @return int 0 if success, <> 0 if error */ - public function LoadSupplierCateg() - { - // phpcs:enable + public function LoadSupplierCateg() + { + // phpcs:enable $this->SupplierCategories = array(); $sql = "SELECT rowid, label"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; $sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER; $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { $this->SupplierCategories[$obj->rowid] = $obj->label; } return 0; - } else { + } + else + { return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Insert link supplier - category * * @param int $categorie_id Id of category * @return int 0 if success, <> 0 if error */ - public function AddFournisseurInCategory($categorie_id) - { - // phpcs:enable - if ($categorie_id > 0 && $this->id > 0) { + public function AddFournisseurInCategory($categorie_id) + { + // phpcs:enable + if ($categorie_id > 0 && $this->id > 0) + { $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) "; $sql .= " VALUES (".$categorie_id.", ".$this->id.")"; - if ($resql = $this->db->query($sql)) { - return 0; - } - } else { + if ($resql = $this->db->query($sql)) return 0; + } + else + { return 0; } return -1; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a third party into database from a member object * @@ -3619,17 +3626,15 @@ * @param string $customercode Customer code * @return int <0 if KO, id of created account if OK */ - public function create_from_member(Adherent $member, $socname = '', $socalias = '', $customercode = '') + public function create_from_member(Adherent $member, $socname = '', $socalias = '', $customercode = '') { // phpcs:enable - global $conf, $user, $langs; + global $user, $langs; dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); $name = $socname ? $socname : $member->societe; - if (empty($name)) { - $name = $member->getFullName($langs); - } + if (empty($name)) $name = $member->getFullName($langs); $alias = $socalias ? $socalias : ''; @@ -3644,7 +3649,7 @@ $this->country_id = $member->country_id; $this->phone = $member->phone; // Prof phone $this->email = $member->email; - $this->socialnetworks = $member->socialnetworks; + $this->socialnetworks = $member->socialnetworks; $this->entity = $member->entity; $this->client = 1; // A member is a customer by default @@ -3655,39 +3660,28 @@ // Cree et positionne $this->id $result = $this->create($user); - if ($result >= 0) { - // Auto-create contact on thirdparty creation - if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) { - // Fill fields needed by contact - $this->name_bis = $member->lastname; - $this->firstname = $member->firstname; - $this->civility_id = $member->civility_id; - - dol_syslog("We ask to create a contact/address too", LOG_DEBUG); - $result = $this->create_individual($user); - if ($result < 0) - { - setEventMessages($this->error, $this->errors, 'errors'); - $this->db->rollback(); - return -1; - } - } - + if ($result >= 0) + { $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; $sql .= " SET fk_soc=".$this->id; $sql .= " WHERE rowid=".$member->id; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $this->db->commit(); return $this->id; - } else { + } + else + { $this->error = $this->db->error(); $this->db->rollback(); return -1; } - } else { + } + else + { // $this->error deja positionne dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',', $this->errors), LOG_ERR); @@ -3702,7 +3696,7 @@ * @param Conf $conf Conf object (possibility to use another entity) * @return void */ - public function setMysoc(Conf $conf) + public function setMysoc(Conf $conf) { global $langs; @@ -3720,13 +3714,16 @@ // We define country_id, country_code and country $country_id = $country_code = $country_label = ''; - if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) { + if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) + { $tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY); $country_id = $tmp[0]; - if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label" + if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label" + { $country_code = $tmp[1]; $country_label = $tmp[2]; - } else // For backward compatibility + } + else // For backward compatibility { dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING); include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; @@ -3737,21 +3734,23 @@ $this->country_id = $country_id; $this->country_code = $country_code; $this->country = $country_label; - if (is_object($langs)) { - $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label; - } + if (is_object($langs)) $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label; //TODO This could be replicated for region but function `getRegion` didn't exist, so I didn't added it. // We define state_id, state_code and state $state_id = 0; $state_code = $state_label = ''; - if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) { + if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) + { $tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_STATE); $state_id = $tmp[0]; - if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" + if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" + { $state_code = $tmp[1]; $state_label = $tmp[2]; - } else { // For backward compatibility - dol_syslog("Your state setup use an old syntax (entity=".$conf->entity."). Reedit it using setup area.", LOG_ERR); + } + else // For backward compatibility + { + dol_syslog("Your state setup use an old syntax. Reedit it using setup area.", LOG_ERR); include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $state_code = getState($state_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore $state_label = getState($state_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore @@ -3760,9 +3759,7 @@ $this->state_id = $state_id; $this->state_code = $state_code; $this->state = $state_label; - if (is_object($langs)) { - $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label; - } + if (is_object($langs)) $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label; $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL; $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX; @@ -3776,24 +3773,12 @@ $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL; $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL; $this->socialnetworks = array(); - if (!empty($this->facebook_url)) { - $this->socialnetworks['facebook'] = $this->facebook_url; - } - if (!empty($this->twitter_url)) { - $this->socialnetworks['twitter'] = $this->twitter_url; - } - if (!empty($this->linkedin_url)) { - $this->socialnetworks['linkedin'] = $this->linkedin_url; - } - if (!empty($this->instagram_url)) { - $this->socialnetworks['instagram'] = $this->instagram_url; - } - if (!empty($this->youtube_url)) { - $this->socialnetworks['youtube'] = $this->youtube_url; - } - if (!empty($this->github_url)) { - $this->socialnetworks['github'] = $this->github_url; - } + if (! empty($this->facebook_url)) $this->socialnetworks['facebook'] = $this->facebook_url; + if (! empty($this->twitter_url)) $this->socialnetworks['twitter'] = $this->twitter_url; + if (! empty($this->linkedin_url)) $this->socialnetworks['linkedin'] = $this->linkedin_url; + if (! empty($this->instagram_url)) $this->socialnetworks['instagram'] = $this->instagram_url; + if (! empty($this->youtube_url)) $this->socialnetworks['youtube'] = $this->youtube_url; + if (! empty($this->github_url)) $this->socialnetworks['github'] = $this->github_url; // Id prof generiques $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN; @@ -3830,13 +3815,12 @@ * * @return int >0 if ok */ - public function initAsSpecimen() + public function initAsSpecimen() { $now = dol_now(); // Initialize parameters $this->id = 0; - $this->entity = 1; $this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now, 'dayhourlog'); $this->nom = $this->name; // For backward compatibility $this->ref_ext = 'Ref ext'; @@ -3887,26 +3871,22 @@ * @param int $localTaxNum To get info for only localtax1 or localtax2 * @return boolean true or false */ - public function useLocalTax($localTaxNum = 0) + public function useLocalTax($localTaxNum = 0) { $sql = "SELECT t.localtax1, t.localtax2"; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'"; $sql .= " AND t.active = 1"; - if (empty($localTaxNum)) { - $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; - } elseif ($localTaxNum == 1) { - $sql .= " AND t.localtax1_type <> '0'"; - } elseif ($localTaxNum == 2) { - $sql .= " AND t.localtax2_type <> '0'"; - } + if (empty($localTaxNum)) $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; + elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'"; + elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'"; $resql = $this->db->query($sql); - if ($resql) { - return ($this->db->num_rows($resql) > 0); - } else { - return false; - } + if ($resql) + { + return ($this->db->num_rows($resql) > 0); + } + else return false; } /** @@ -3914,7 +3894,7 @@ * * @return boolean true or false */ - public function useNPR() + public function useNPR() { $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; @@ -3923,11 +3903,11 @@ dol_syslog("useNPR", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { return ($this->db->num_rows($resql) > 0); - } else { - return false; - } + } + else return false; } /** @@ -3936,7 +3916,7 @@ * * @return boolean true or false */ - public function useRevenueStamp() + public function useRevenueStamp() { $sql = "SELECT COUNT(*) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r, ".MAIN_DB_PREFIX."c_country as c"; @@ -3945,10 +3925,13 @@ dol_syslog("useRevenueStamp", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $obj = $this->db->fetch_object($resql); - return (($obj->nb > 0) ?true:false); - } else { + return (($obj->nb > 0) ?true:false); + } + else + { $this->error = $this->db->lasterror(); return false; } @@ -3959,26 +3942,27 @@ * * @return string Libelle */ - public function getLibProspLevel() + public function getLibProspLevel() { return $this->LibProspLevel($this->fk_prospectlevel); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return label of prospect level * * @param int $fk_prospectlevel Prospect level * @return string label of level */ - public function LibProspLevel($fk_prospectlevel) - { - // phpcs:enable + public function LibProspLevel($fk_prospectlevel) + { + // phpcs:enable 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)) { + if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) + { $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label'); } return $lib; @@ -3993,9 +3977,9 @@ * @return int <0 if KO, >0 if OK * @deprecated Use update function instead */ - public function set_prospect_level(User $user) - { - // phpcs:enable + public function set_prospect_level(User $user) + { + // phpcs:enable return $this->update($this->id, $user); } @@ -4006,79 +3990,67 @@ * @param string $label Label to use for status for added status * @return string Libelle */ - public function getLibProspCommStatut($mode = 0, $label = '') - { - return $this->LibProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + public function getLibProspCommStatut($mode = 0, $label = '') + { + return $this->LibProspCommStatut($this->stcomm_id, $mode, $label); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return label of a given status * * @param int|string $status Id or code for prospection status * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto * @param string $label Label to use for status for added status - * @param string $picto Name of image file to show ('filenew', ...) - * If no extension provided, we use '.png'. Image must be stored into theme/xxx/img directory. - * Example: picto.png if picto.png is stored into htdocs/theme/mytheme/img - * Example: picto.png@mymodule if picto.png is stored into htdocs/mymodule/img - * Example: /mydir/mysubdir/picto.png if picto.png is stored into htdocs/mydir/mysubdir (pictoisfullpath must be set to 1) * @return string Label of prospection status */ - public function LibProspCommStatut($status, $mode = 0, $label = '', $picto = '') - { - // phpcs:enable + public function LibProspCommStatut($status, $mode = 0, $label = '') + { + // phpcs:enable global $langs; $langs->load('customers'); - if ($mode == 2) { - if ($status == '-1' || $status == 'ST_NO') { - return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); - } elseif ($status == '0' || $status == 'ST_NEVER') { - return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); - } elseif ($status == '1' || $status == 'ST_TODO') { - return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); - } elseif ($status == '2' || $status == 'ST_PEND') { - return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); - } elseif ($status == '3' || $status == 'ST_DONE') { - return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); - } else { - return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); - } - } elseif ($mode == 3) { - if ($status == '-1' || $status == 'ST_NO') { - return img_action($langs->trans("StatusProspect-1"), -1, $picto); - } elseif ($status == '0' || $status == 'ST_NEVER') { - return img_action($langs->trans("StatusProspect0"), 0, $picto); - } elseif ($status == '1' || $status == 'ST_TODO') { - return img_action($langs->trans("StatusProspect1"), 1, $picto); - } elseif ($status == '2' || $status == 'ST_PEND') { - return img_action($langs->trans("StatusProspect2"), 2, $picto); - } elseif ($status == '3' || $status == 'ST_DONE') { - return img_action($langs->trans("StatusProspect3"), 3, $picto); - } else { - return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto); - } - } elseif ($mode == 4) { - if ($status == '-1' || $status == 'ST_NO') { - return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); - } elseif ($status == '0' || $status == 'ST_NEVER') { - return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); - } elseif ($status == '1' || $status == 'ST_TODO') { - return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); - } elseif ($status == '2' || $status == 'ST_PEND') { - return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); - } elseif ($status == '3' || $status == 'ST_DONE') { - return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); - } else { - return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); + if ($mode == 2) + { + if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1"); + elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0"); + elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1"); + elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2"); + elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3"); + else + { + return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); + } + } + if ($mode == 3) + { + if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1); + elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0); + elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1); + elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2); + elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3); + else + { + return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0); + } + } + if ($mode == 4) + { + if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1"); + elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0"); + elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1"); + elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2"); + elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3"); + else + { + return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); } } return "Error, mode/status not found"; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set outstanding value * @@ -4086,9 +4058,9 @@ * @return int <0 if KO, >0 if OK * @deprecated Use update function instead */ - public function set_OutstandingBill(User $user) - { - // phpcs:enable + public function set_OutstandingBill(User $user) + { + // phpcs:enable return $this->update($this->id, $user); } @@ -4098,12 +4070,10 @@ * @param string $mode 'customer' or 'supplier' * @return array array('opened'=>Amount, 'total'=>Total amount) */ - public function getOutstandingProposals($mode = 'customer') + public function getOutstandingProposals($mode = 'customer') { $table = 'propal'; - if ($mode == 'supplier') { - $table = 'supplier_proposal'; - } + if ($mode == 'supplier') $table = 'supplier_proposal'; $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".$this->id; @@ -4115,22 +4085,23 @@ dol_syslog("getOutstandingProposals", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; while ($obj = $this->db->fetch_object($resql)) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; - if ($obj->status != 0) { - // Not a draft + if ($obj->status != 0) // Not a draft + { $outstandingOpened += $obj->total_ttc; } } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' - } else { + } + else return array(); - } } /** @@ -4139,12 +4110,10 @@ * @param string $mode 'customer' or 'supplier' * @return array array('opened'=>Amount, 'total'=>Total amount) */ - public function getOutstandingOrders($mode = 'customer') + public function getOutstandingOrders($mode = 'customer') { $table = 'commande'; - if ($mode == 'supplier') { - $table = 'commande_fournisseur'; - } + if ($mode == 'supplier') $table = 'commande_fournisseur'; $sql = "SELECT rowid, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".$this->id; @@ -4156,37 +4125,35 @@ dol_syslog("getOutstandingOrders", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; while ($obj = $this->db->fetch_object($resql)) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; - if ($obj->status != 0) { - // Not a draft + if ($obj->status != 0) // Not a draft + { $outstandingOpened += $obj->total_ttc; } } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' - } else { + } + else return array(); - } } /** * Return amount of bill not paid and total * * @param string $mode 'customer' or 'supplier' - * @param int $late 0 => all invoice, 1=> only late * @return array array('opened'=>Amount, 'total'=>Total amount) */ - public function getOutstandingBills($mode = 'customer', $late = 0) + public function getOutstandingBills($mode = 'customer') { $table = 'facture'; - if ($mode == 'supplier') { - $table = 'facture_fourn'; - } + if ($mode == 'supplier') $table = 'facture_fourn'; /* Accurate value of remain to pay is to sum remaintopay for each invoice $paiement = $invoice->getSommePaiement(); @@ -4195,15 +4162,9 @@ $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); */ - if ($mode == 'supplier') { - $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - } else { - $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - } + if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".$this->id; - if (!empty($late)) { - $sql .= " AND date_lim_reglement < '".$this->db->idate(dol_now())."'"; - } if ($mode == 'supplier') { $sql .= " AND entity IN (".getEntity('facture_fourn').")"; } else { @@ -4212,31 +4173,37 @@ dol_syslog("getOutstandingBills", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; - if ($mode == 'supplier') { + if ($mode == 'supplier') + { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $tmpobject = new FactureFournisseur($this->db); - } else { + } + else + { require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $tmpobject = new Facture($this->db); } while ($obj = $this->db->fetch_object($resql)) { - $tmpobject->id = $obj->rowid; - - if ($obj->status != $tmpobject::STATUS_DRAFT // Not a draft - && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code == 'replaced') // Not a replaced invoice - ) { + $tmpobject->id = $obj->rowid; + + if ($obj->status != $tmpobject::STATUS_DRAFT // Not a draft + && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code == 'replaced') // Not a replaced invoice + ) + { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; } if ($obj->paye == 0 && $obj->status != $tmpobject::STATUS_DRAFT // Not a draft && $obj->status != $tmpobject::STATUS_ABANDONED // Not abandonned - && $obj->status != $tmpobject::STATUS_CLOSED) { // Not classified as paid - //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason + && $obj->status != $tmpobject::STATUS_CLOSED) // Not classified as paid + //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason + { $paiement = $tmpobject->getSommePaiement(); $creditnotes = $tmpobject->getSumCreditNotesUsed(); $deposits = $tmpobject->getSumDepositsUsed(); @@ -4244,14 +4211,17 @@ $outstandingOpened += $obj->total_ttc - $paiement - $creditnotes - $deposits; } - //if credit note is converted but not used - // TODO Do this also for customer ? - if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) { - $outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed(); - } + //if credit note is converted but not used + // TODO Do this also for customer ? + if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) + { + $outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed(); + } } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' - } else { + } + else + { return array(); } } @@ -4261,40 +4231,35 @@ * * @return string Label */ - public function getLibCustProspStatut() + public function getLibCustProspStatut() { return $this->LibCustProspStatut($this->client); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return the label of the customer/prospect status * * @param int $status Id of prospection status * @return string Label of prospection status */ - public function LibCustProspStatut($status) - { - // phpcs:enable + public function LibCustProspStatut($status) + { + // phpcs:enable global $langs; $langs->load('companies'); - if ($status == 0) { - return $langs->trans("NorProspectNorCustomer"); - } elseif ($status == 1) { - return $langs->trans("Customer"); - } elseif ($status == 2) { - return $langs->trans("Prospect"); - } elseif ($status == 3) { - return $langs->trans("ProspectCustomer"); - } + if ($status == 0) return $langs->trans("NorProspectNorCustomer"); + elseif ($status == 1) return $langs->trans("Customer"); + elseif ($status == 2) return $langs->trans("Prospect"); + elseif ($status == 3) return $langs->trans("ProspectCustomer"); } /** * Create a document onto disk according to template module. * - * @param string $modele Generator to use. Caller must set it to obj->model_pdf or GETPOST('model','alpha') for example. + * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf','alpha') for example. * @param Translate $outputlangs objet lang a utiliser pour traduction * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description @@ -4306,28 +4271,33 @@ { global $conf, $user, $langs; - if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) { + if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) + { $modelpath = "core/modules/bank/doc/"; include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; $companybankaccount = new CompanyBankAccount($this->db); $result = $companybankaccount->fetch($moreparams['use_companybankid']); - if (!$result) { - dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors); - } + if (!$result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors); $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); - } else { + } + else + { // Positionne le modele sur le nom du modele a utiliser - if (!dol_strlen($modele)) { - if (!empty($conf->global->COMPANY_ADDON_PDF)) { + if (!dol_strlen($modele)) + { + if (!empty($conf->global->COMPANY_ADDON_PDF)) + { $modele = $conf->global->COMPANY_ADDON_PDF; - } else { + } + else + { print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined"); return 0; } } - if (!isset($this->bank_account)) { + if (! isset($this->bank_account)) { require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; $bac = new CompanyBankAccount($this->db); $result = $bac->fetch(0, $this->id); @@ -4395,9 +4365,11 @@ } } foreach ($to_add as $add) { - if ($c->fetch($add) > 0) { + if ($c->fetch($add) > 0) + { $result = $c->add_type($this, $type_categ); - if ($result < 0) { + if ($result < 0) + { $error++; $this->error = $c->error; $this->errors = $c->errors; @@ -4413,10 +4385,9 @@ * Sets sales representatives of the thirdparty * * @param int[]|int $salesrep User ID or array of user IDs - * @param bool $onlyAdd Only add (no delete before) * @return int <0 if KO, >0 if OK */ - public function setSalesRep($salesrep, $onlyAdd = false) + public function setSalesRep($salesrep) { global $user; @@ -4425,17 +4396,16 @@ $salesrep = array($salesrep); } - $to_del = array(); // Nothing to delete - $to_add = $salesrep; - if ($onlyAdd === false) { - // Get current users - $existing = $this->getSalesRepresentatives($user, 1); - - // Diff - if (is_array($existing)) { - $to_del = array_diff($existing, $salesrep); - $to_add = array_diff($salesrep, $existing); - } + // Get current users + $existing = $this->getSalesRepresentatives($user, 1); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $salesrep); + $to_add = array_diff($salesrep, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $salesrep; } $error = 0; @@ -4446,7 +4416,8 @@ } foreach ($to_add as $add) { $result = $this->add_commercial($user, $add); - if ($result < 0) { + if ($result < 0) + { $error++; break; } @@ -4455,31 +4426,6 @@ return $error ? -1 : 1; } - /** - * Define third-party type of current company - * - * @param int $typent_id third party type rowid in llx_c_typent - * @return int <0 if KO, >0 if OK - */ - public function setThirdpartyType($typent_id) - { - if ($this->id) { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; - $sql .= " SET fk_typent = ".($typent_id > 0 ? $typent_id : "null"); - $sql .= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this).'::setThirdpartyType', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $this->typent_id = $typent_id; - $this->typent_code = dol_getIdFromCode($this->db, $this->$typent_id, 'c_typent', 'id', 'code'); - return 1; - } else { - return -1; - } - } else { - return -1; - } - } /** * Function used to replace a thirdparty id with another one. @@ -4492,7 +4438,8 @@ */ public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) { - if ($origin_id == $dest_id) { + if ($origin_id == $dest_id) + { dol_syslog('Error: Try to merge a thirdparty into itself'); return false; } --- /tmp/dsg/dolibarr/htdocs/societe/class/github_societeaccount.class.php +++ /tmp/dsg/dolibarr/htdocs/societe/class/client_societeaccount.class.php @@ -119,7 +119,7 @@ /** * @var int Thirdparty ID */ - public $fk_soc; + public $fk_soc; public $site; public $site_account; @@ -142,13 +142,13 @@ public $tms; /** - * @var int ID - */ + * @var int ID + */ public $fk_user_creat; /** - * @var int ID - */ + * @var int ID + */ public $fk_user_modif; public $import_key; @@ -159,6 +159,33 @@ public $status; // END MODULEBUILDER PROPERTIES + + + + + // If this object has a subtable with lines + + /** + * @var int Name of subtable line + */ + //public $table_element_line = 'societe_accountdet'; + /** + * @var int Field with ID of parent key if this field has a parent + */ + //public $fk_element = 'fk_societe_account'; + /** + * @var int Name of subtable class that manage subtable lines + */ + //public $class_element_line = 'societeAccountline'; + /** + * @var array List of child tables. To test if we can delete object. + */ + //protected $childtables=array(); + /** + * @var societeAccountLine[] Array of subtable lines + */ + //public $lines = array(); + /** @@ -197,45 +224,45 @@ public function createFromClone(User $user, $fromid) { global $hookmanager, $langs; - $error = 0; - - dol_syslog(__METHOD__, LOG_DEBUG); - - $object = new self($this->db); - - $this->db->begin(); - - // Load source object - $object->fetchCommon($fromid); - // Reset some properties - unset($object->id); - unset($object->fk_user_creat); - unset($object->import_key); - - // Clear fields - $object->ref = "copy_of_".$object->ref; - $object->title = $langs->trans("CopyOf")." ".$object->title; - // ... - - // Create clone + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $object->fetchCommon($fromid); + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); + + // Clear fields + $object->ref = "copy_of_".$object->ref; + $object->title = $langs->trans("CopyOf")." ".$object->title; + // ... + + // Create clone $object->context['createfromclone'] = 'createfromclone'; - $result = $object->createCommon($user); - if ($result < 0) { - $error++; - $this->error = $object->error; - $this->errors = $object->errors; - } - - unset($object->context['createfromclone']); - - // End - if (!$error) { - $this->db->commit(); - return $object; - } else { - $this->db->rollback(); - return -1; - } + $result = $object->createCommon($user); + if ($result < 0) { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + } + + unset($object->context['createfromclone']); + + // End + if (!$error) { + $this->db->commit(); + return $object; + } else { + $this->db->rollback(); + return -1; + } } /** @@ -304,14 +331,14 @@ } /** - * Try to find the thirdparty id from an another site/system external id. - * - * @param string $id Id of customer in external system (example: 'cu_xxxxxxxxxxxxx', ...) - * @param string $site Site (example: 'stripe', '...') - * @param int $status Status (0=test, 1=live) - * @return int Id of third party - * @see getCustomerAccount() - */ + * Try to find the thirdparty id from an another site/system external id. + * + * @param string $id Id of customer in external system (example: 'cu_xxxxxxxxxxxxx', ...) + * @param string $site Site (example: 'stripe', '...') + * @param int $status Status (0=test, 1=live) + * @return int Id of third party + * @see getCustomerAccount() + */ public function getThirdPartyID($id, $site, $status = 0) { $socid = 0; @@ -363,50 +390,51 @@ * Return a link to the object card (with optionaly the picto) * * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) - * @param string $option On what the link point to ('nolink', ...) - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @return string String with URL - */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) - { + * @param string $option On what the link point to ('nolink', ...) + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string String with URL + */ + public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) + { global $db, $conf, $langs; - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; - - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips - - $result = ''; - - $this->ref = $this->login; - - $label = '<u>'.$langs->trans("WebsiteAccount").'</u>'; - $label .= '<br>'; - $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref; - //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref; - - $url = dol_buildpath('/website/websiteaccount_card.php', 1).'?id='.$this->id; - - if ($option != 'nolink') - { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; - } - - $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label = $langs->trans("WebsiteAccount"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + + $result = ''; + + $this->ref = $this->login; + + $label = '<u>'.$langs->trans("WebsiteAccount").'</u>'; + $label .= '<br>'; + $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref; + //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref; + + $url = dol_buildpath('/website/websiteaccount_card.php', 1).'?id='.$this->id; + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + + $linkclose = ''; + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("WebsiteAccount"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); $linkstart = '<a href="'.$url.'"'; $linkstart .= $linkclose.'>'; @@ -418,7 +446,7 @@ $result .= $linkend; return $result; - } + } /** * Retourne le libelle du status d'un user (actif, inactif) @@ -431,7 +459,7 @@ return $this->LibStatut($this->status, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return the status * @@ -441,7 +469,7 @@ */ public static function LibStatut($status, $mode = 0) { - // phpcs:enable + // phpcs:enable global $langs; if ($mode == 0) @@ -449,27 +477,33 @@ $prefix = ''; if ($status == 1) return $langs->trans('Enabled'); elseif ($status == 0) return $langs->trans('Disabled'); - } elseif ($mode == 1) + } + elseif ($mode == 1) { if ($status == 1) return $langs->trans('Enabled'); elseif ($status == 0) return $langs->trans('Disabled'); - } elseif ($mode == 2) + } + elseif ($mode == 2) { if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); - } elseif ($mode == 3) + } + elseif ($mode == 3) { if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4'); elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5'); - } elseif ($mode == 4) + } + elseif ($mode == 4) { if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled'); elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled'); - } elseif ($mode == 5) + } + elseif ($mode == 5) { if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4'); elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5'); - } elseif ($mode == 6) + } + elseif ($mode == 6) { if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4'); elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5'); @@ -522,7 +556,9 @@ } $this->db->free($result); - } else { + } + else + { dol_print_error($this->db); } }