24use Luracast\Restler\RestException;
 
   39  public static $FIELDS = array(
 
   56    require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
 
   57    require_once DOL_DOCUMENT_ROOT.
'/societe/class/societeaccount.class.php';
 
   58    require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
 
   59    require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
 
   60    require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
 
   62    $this->company = 
new Societe($this->db);
 
   65      static::$FIELDS[] = 
'email';
 
 
   79  public function get(
$id)
 
 
   98    return $this->
_fetch(
null, 
'', 
'', 
'', 
'', 
'', 
'', 
'', 
'', 
'', $email);
 
 
  115    return $this->
_fetch(
null, 
'', 
'', $barcode);
 
 
  137  public function index($sortfield = 
"t.rowid", $sortorder = 
'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = 
'', $properties = 
'', $pagination_data = 
false)
 
  141    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
  142      throw new RestException(403);
 
  146    $socids = DolibarrApiAccess::$user->socid ? (string) DolibarrApiAccess::$user->socid : 
'';
 
  150    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'client', 
'voir') && !$socids) {
 
  151      $search_sale = DolibarrApiAccess::$user->id;
 
  154    $sql = 
"SELECT t.rowid";
 
  155    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe as t";
 
  156    $sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_extrafields AS ef ON ef.fk_object = t.rowid"; 
 
  159        $sql .= 
", ".MAIN_DB_PREFIX.
"categorie_societe as c";
 
  161      if (!in_array($mode, array(1, 2, 3))) {
 
  162        $sql .= 
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as cc";
 
  165    $sql .= 
", ".MAIN_DB_PREFIX.
"c_stcomm as st";
 
  166    $sql .= 
" WHERE t.entity IN (".getEntity(
'societe').
")";
 
  167    $sql .= 
" AND t.fk_stcomm = st.id";
 
  169      $sql .= 
" AND t.client IN (1, 3)";
 
  170    } elseif ($mode == 2) {
 
  171      $sql .= 
" AND t.client IN (2, 3)";
 
  172    } elseif ($mode == 3) {
 
  173      $sql .= 
" AND t.client IN (0)";
 
  174    } elseif ($mode == 4) {
 
  175      $sql .= 
" AND t.fournisseur IN (1)";
 
  179      if (!empty($mode) && $mode != 4) {
 
  180        $sql .= 
" AND c.fk_categorie = ".((int) $category).
" AND c.fk_soc = t.rowid";
 
  181      } elseif (!empty($mode) && $mode == 4) {
 
  182        $sql .= 
" AND cc.fk_categorie = ".((int) $category).
" AND cc.fk_soc = t.rowid";
 
  184        $sql .= 
" AND ((c.fk_categorie = ".((int) $category).
" AND c.fk_soc = t.rowid) OR (cc.fk_categorie = ".((int) $category).
" AND cc.fk_soc = t.rowid))";
 
  188      $sql .= 
" AND t.rowid IN (".$this->db->sanitize($socids).
")";
 
  191    if ($search_sale && $search_sale != 
'-1') {
 
  192      if ($search_sale == -2) {
 
  193        $sql .= 
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.rowid)";
 
  194      } elseif ($search_sale > 0) {
 
  195        $sql .= 
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.rowid AND sc.fk_user = ".((int) $search_sale).
")";
 
  203        throw new RestException(400, 
'Error when validating parameter sqlfilters -> '.$errormessage);
 
  208    $sqlTotals = str_replace(
'SELECT t.rowid', 
'SELECT count(t.rowid) as total', $sql);
 
  210    $sql .= $this->db->order($sortfield, $sortorder);
 
  215      $offset = $limit * $page;
 
  217      $sql .= $this->db->plimit($limit + 1, $offset);
 
  220    $result = $this->db->query($sql);
 
  222      $num = $this->db->num_rows($result);
 
  223      $min = min($num, ($limit <= 0 ? $num : $limit));
 
  226        $obj = $this->db->fetch_object($result);
 
  227        $soc_static = 
new Societe($this->db);
 
  228        if ($soc_static->fetch($obj->rowid)) {
 
  229          if (isModEnabled(
'mailing')) {
 
  230            $soc_static->getNoEmail();
 
  237      throw new RestException(503, 
'Error when retrieve thirdparties : '.$this->db->lasterror());
 
  239    if (!count($obj_ret)) {
 
  240      throw new RestException(404, 
'Thirdparties not found');
 
  244    if ($pagination_data) {
 
  245      $totalsResult = $this->db->query($sqlTotals);
 
  246      $total = $this->db->fetch_object($totalsResult)->total;
 
  251      $obj_ret[
'data'] = $tmp;
 
  252      $obj_ret[
'pagination'] = [
 
  253        'total' => (int) $total,
 
  255        'page_count' => ceil((
int) $total / $limit),
 
 
  269  public function post($request_data = 
null)
 
  271    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  272      throw new RestException(403);
 
  275    $result = $this->
_validate($request_data);
 
  277    foreach ($request_data as $field => $value) {
 
  278      if ($field === 
'caller') {
 
  280        $this->company->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
  284      $this->company->$field = $this->
_checkValForAPI($field, $value, $this->company);
 
  287    if ($this->company->create(DolibarrApiAccess::$user) < 0) {
 
  288      throw new RestException(500, 
'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
 
  290    if (isModEnabled(
'mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
 
  291      $this->company->setNoEmail($this->company->no_email);
 
  294    return $this->company->id;
 
 
  308  public function put(
$id, $request_data = 
null)
 
  310    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  311      throw new RestException(403);
 
  314    $result = $this->company->fetch(
$id);
 
  316      throw new RestException(404, 
'Thirdparty not found');
 
  320      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  323    foreach ($request_data as $field => $value) {
 
  324      if ($field == 
'id') {
 
  327      if ($field === 
'caller') {
 
  329        $this->company->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
  332      if ($field == 
'array_options' && is_array($value)) {
 
  333        foreach ($value as $index => $val) {
 
  334          $this->company->array_options[$index] = $val;
 
  338      $this->company->$field = $this->
_checkValForAPI($field, $value, $this->company);
 
  341    if (isModEnabled(
'mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
 
  342      $this->company->setNoEmail($this->company->no_email);
 
  345    if ($this->company->update(
$id, DolibarrApiAccess::$user, 1, 1, 1, 
'update', 1) > 0) {
 
  346      return $this->
get(
$id);
 
  348      throw new RestException(500, $this->company->error);
 
 
  368    if (
$id == $idtodelete) {
 
  369      throw new RestException(400, 
'Try to merge a thirdparty into itself');
 
  372    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  373      throw new RestException(403);
 
  376    $result = $this->company->fetch(
$id); 
 
  378      throw new RestException(404, 
'Thirdparty not found');
 
  382      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  385    $companytoremove = 
new Societe($this->db);
 
  386    $result = $companytoremove->fetch($idtodelete); 
 
  388      throw new RestException(404, 
'Thirdparty not found');
 
  392      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  395    $user = DolibarrApiAccess::$user;
 
  396    $result = $this->company->mergeCompany($companytoremove->id);
 
  398      throw new RestException(500, 
'Error failed to merged thirdparty '.$companytoremove->id.
' into '.
$id.
'. Enable and read log file for more information.');
 
  401    return $this->
get(
$id);
 
 
  410  public function delete(
$id)
 
  412    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'supprimer')) {
 
  413      throw new RestException(403);
 
  415    $result = $this->company->fetch(
$id);
 
  417      throw new RestException(404, 
'Thirdparty not found');
 
  420      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  422    $this->company->oldcopy = clone $this->company;
 
  424    $res = $this->company->delete(
$id);
 
  426      throw new RestException(500, 
"Can't delete, error occurs");
 
  427    } elseif ($res == 0) {
 
  428      throw new RestException(409, 
"Can't delete, that product is probably used");
 
  434        'message' => 
'Object deleted' 
 
  458    if (!isModEnabled(
'societe')) {
 
  459      throw new RestException(501, 
'Module "Thirdparties" needed for this request');
 
  462    if (!isModEnabled(
"product")) {
 
  463      throw new RestException(501, 
'Module "Products" needed for this request');
 
  467      throw new RestException(501, 
'Multiprices features activation needed for this request');
 
  470    if ($priceLevel < 1 || $priceLevel > 
getDolGlobalString(
'PRODUIT_MULTIPRICES_LIMIT')) {
 
  471      throw new RestException(400, 
'Price level must be between 1 and ' . 
getDolGlobalString(
'PRODUIT_MULTIPRICES_LIMIT'));
 
  474    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  475      throw new RestException(403, 
'Access to thirdparty '.
$id.
' not allowed for login '.DolibarrApiAccess::$user->login);
 
  478    $result = $this->company->fetch(
$id);
 
  480      throw new RestException(404, 
'Thirdparty '.
$id.
' not found');
 
  483    if (empty($result)) {
 
  484      throw new RestException(500, 
'Error fetching thirdparty '.
$id, array_merge(array($this->company->error), $this->company->errors));
 
  488      throw new RestException(403, 
'Access to thirdparty '.
$id.
' not allowed for login '.DolibarrApiAccess::$user->login);
 
  491    $result = $this->company->setPriceLevel($priceLevel, DolibarrApiAccess::$user);
 
  493      throw new RestException(500, 
'Error setting new price level for thirdparty '.
$id, array($this->company->db->lasterror()));
 
 
  513    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  514      throw new RestException(403);
 
  516    $result = $this->company->fetch(
$id);
 
  518      throw new RestException(404, 
'Thirdparty not found');
 
  520    $usertmp = 
new User($this->db);
 
  521    $result = $usertmp->fetch($representative_id);
 
  523      throw new RestException(404, 
'User not found');
 
  526      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  528    $result = $this->company->add_commercial(DolibarrApiAccess::$user, $representative_id);
 
 
  547    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'supprimer')) {
 
  548      throw new RestException(403);
 
  550    $result = $this->company->fetch(
$id);
 
  552      throw new RestException(404, 
'Thirdparty not found');
 
  554    $usertmp = 
new User($this->db);
 
  555    $result = $usertmp->fetch($representative_id);
 
  557      throw new RestException(404, 
'User not found');
 
  560      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  562    $result = $this->company->del_commercial(DolibarrApiAccess::$user, $representative_id);
 
 
  579  public function getCategories(
$id, $sortfield = 
"s.rowid", $sortorder = 
'ASC', $limit = 0, $page = 0)
 
  581    if (!DolibarrApiAccess::$user->hasRight(
'categorie', 
'lire')) {
 
  582      throw new RestException(403);
 
  585    $result = $this->company->fetch(
$id);
 
  587      throw new RestException(404, 
'Thirdparty not found');
 
  592    $arrayofcateg = $categories->getListForItem(
$id, 
'customer', $sortfield, $sortorder, $limit, $page);
 
  594    if (is_numeric($arrayofcateg) && $arrayofcateg < 0) {
 
  595      throw new RestException(503, 
'Error when retrieve category list : '.$categories->error);
 
  598    if (is_numeric($arrayofcateg) && $arrayofcateg >= 0) {  
 
  602    return $arrayofcateg;
 
 
  616    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  617      throw new RestException(403);
 
  620    $result = $this->company->fetch(
$id);
 
  622      throw new RestException(404, 
'Thirdparty not found');
 
  625    $result = $category->fetch($category_id);
 
  627      throw new RestException(404, 
'category not found');
 
  631      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  634      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  637    $category->add_type($this->company, 
'customer');
 
 
  654    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  655      throw new RestException(403);
 
  658    $result = $this->company->fetch(
$id);
 
  660      throw new RestException(404, 
'Thirdparty not found');
 
  663    $result = $category->fetch($category_id);
 
  665      throw new RestException(404, 
'category not found');
 
  669      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  672      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  675    $category->del_type($this->company, 
'customer');
 
 
  695    if (!DolibarrApiAccess::$user->hasRight(
'categorie', 
'lire')) {
 
  696      throw new RestException(403);
 
  699    $result = $this->company->fetch(
$id);
 
  701      throw new RestException(404, 
'Thirdparty not found');
 
  706    $result = $categories->getListForItem(
$id, 
'supplier', $sortfield, $sortorder, $limit, $page);
 
  708    if (is_numeric($result) && $result < 0) {
 
  709      throw new RestException(503, 
'Error when retrieve category list : '.$categories->error);
 
  712    if (is_numeric($result) && $result == 0) {  
 
 
  731    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  732      throw new RestException(403);
 
  735    $result = $this->company->fetch(
$id);
 
  737      throw new RestException(404, 
'Thirdparty not found');
 
  740    $result = $category->fetch($category_id);
 
  742      throw new RestException(404, 
'category not found');
 
  746      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  749      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  752    $category->add_type($this->company, 
'supplier');
 
 
  769    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
  770      throw new RestException(403);
 
  773    $result = $this->company->fetch(
$id);
 
  775      throw new RestException(404, 
'Thirdparty not found');
 
  778    $result = $category->fetch($category_id);
 
  780      throw new RestException(404, 
'category not found');
 
  784      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  787      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  790    $category->del_type($this->company, 
'supplier');
 
 
  812    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
  813      throw new RestException(403);
 
  817      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
  821      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  824    $result = $this->company->fetch(
$id);
 
  826      throw new RestException(404, 
'Thirdparty not found');
 
  829    $result = $this->company->getOutstandingProposals($mode);
 
  831    unset($result[
'total_ht']);
 
  832    unset($result[
'total_ttc']);
 
 
  854    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
  855      throw new RestException(403);
 
  859      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
  863      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  866    $result = $this->company->fetch(
$id);
 
  868      throw new RestException(404, 
'Thirdparty not found');
 
  871    $result = $this->company->getOutstandingOrders($mode);
 
  873    unset($result[
'total_ht']);
 
  874    unset($result[
'total_ttc']);
 
 
  895    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
  896      throw new RestException(403);
 
  900      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
  904      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  907    $result = $this->company->fetch(
$id);
 
  909      throw new RestException(404, 
'Thirdparty not found');
 
  912    $result = $this->company->getOutstandingBills($mode);
 
  914    unset($result[
'total_ht']);
 
  915    unset($result[
'total_ttc']);
 
 
  936    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
  937      throw new RestException(403);
 
  941      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
  945      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  948    $result = $this->company->fetch(
$id);
 
  950      throw new RestException(404, 
'Thirdparty not found');
 
  953    $result = $this->company->getSalesRepresentatives(DolibarrApiAccess::$user, $mode);
 
 
  979    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
  980      throw new RestException(403);
 
  984      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
  988      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
  991    $result = $this->company->fetch(
$id);
 
  993      throw new RestException(404, 
'Thirdparty not found');
 
  997    $sql = 
"SELECT f.ref, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line";
 
  998    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
 
  999    $sql .= 
" WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".((int) 
$id);
 
 1000    if ($filter == 
"available") {
 
 1001      $sql .= 
" AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
 
 1003    if ($filter == 
"used") {
 
 1004      $sql .= 
" AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
 
 1007    $sql .= $this->db->order($sortfield, $sortorder);
 
 1009    $result = $this->db->query($sql);
 
 1011      throw new RestException(503, $this->db->lasterror());
 
 1013      $num = $this->db->num_rows($result);
 
 1014      while ($obj = $this->db->fetch_object($result)) {
 
 
 1039    if (!DolibarrApiAccess::$user->hasRight(
'facture', 
'lire')) {
 
 1040      throw new RestException(403);
 
 1043      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
 1047      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
 1055    require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
 
 1056    $invoice = 
new Facture($this->db);
 
 1057    $result = $invoice->list_replacable_invoices(
$id);
 
 1059      throw new RestException(405, $invoice->error);
 
 
 1083    if (!DolibarrApiAccess::$user->hasRight(
'facture', 
'lire')) {
 
 1084      throw new RestException(403);
 
 1087      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
 1091      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
 1099    require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
 
 1100    $invoice = 
new Facture($this->db);
 
 1101    $result = $invoice->list_qualified_avoir_invoices(
$id);
 
 1103      throw new RestException(405, $invoice->error);
 
 
 1121      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
 1123    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
 1124      throw new RestException(403);
 
 1127      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
 1134    $sql = 
"SELECT rowid as id, fk_action as event, fk_soc as socid, fk_contact as contact_id, type, datec, tms";
 
 1135    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"notify_def";
 
 1137      $sql .= 
" WHERE fk_soc  = ".((int) 
$id);
 
 1140    $result = $this->db->query($sql);
 
 1141    if ($this->db->num_rows($result) == 0) {
 
 1142      throw new RestException(404, 
'Notification not found');
 
 1147    $notifications = array();
 
 1150      $num = $this->db->num_rows($result);
 
 1152        $obj = $this->db->fetch_object($result);
 
 1153        $notifications[] = $obj;
 
 1157      throw new RestException(404, 
'No notifications found');
 
 1160    $fields = array(
'id', 
'socid', 
'event', 
'contact_id', 
'datec', 
'tms', 
'type');
 
 1162    $returnNotifications = array();
 
 1164    foreach ($notifications as $notification) {
 
 1166      foreach ($notification as $key => $value) {
 
 1167        if (in_array($key, $fields)) {
 
 1171      $returnNotifications[] = 
$object;
 
 1174    return $returnNotifications;
 
 
 1188    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1189      throw new RestException(403, 
"User has no right to update thirdparties");
 
 1191    if ($this->company->fetch(
$id) <= 0) {
 
 1192      throw new RestException(404, 
'Error creating Thirdparty Notification, Thirdparty doesn\'t exists');
 
 1194    $notification = 
new Notify($this->db);
 
 1196    $notification->socid = 
$id;
 
 1198    foreach ($request_data as $field => $value) {
 
 1199      $notification->$field = $value;
 
 1202    $event = $notification->event;
 
 1204      throw new RestException(500, 
'Error creating Thirdparty Notification, request_data missing event');
 
 1206    $socid = $notification->socid;
 
 1207    $contact_id = $notification->contact_id;
 
 1209    $exists_sql = 
"SELECT rowid, fk_action as event, fk_soc as socid, fk_contact as contact_id, type, datec, tms as datem";
 
 1210    $exists_sql .= 
" FROM ".MAIN_DB_PREFIX.
"notify_def";
 
 1211    $exists_sql .= 
" WHERE fk_action = '".$this->db->escape($event).
"'";
 
 1212    $exists_sql .= 
" AND fk_soc = '".$this->db->escape($socid).
"'";
 
 1213    $exists_sql .= 
" AND fk_contact = '".$this->db->escape($contact_id).
"'";
 
 1215    $exists_result = $this->db->query($exists_sql);
 
 1216    if ($this->db->num_rows($exists_result) > 0) {
 
 1217      throw new RestException(403, 
'Notification already exists');
 
 1220    if ($notification->create(DolibarrApiAccess::$user) < 0) {
 
 1221      throw new RestException(500, 
'Error creating Thirdparty Notification');
 
 1224    if ($notification->update(DolibarrApiAccess::$user) < 0) {
 
 1225      throw new RestException(500, 
'Error updating values');
 
 
 1244    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1245      throw new RestException(403, 
"User has no right to update thirdparties");
 
 1247    if ($this->company->fetch(
$id) <= 0) {
 
 1248      throw new RestException(404, 
'Error creating Thirdparty Notification, Thirdparty doesn\'t exists');
 
 1250    $notification = 
new Notify($this->db);
 
 1251    $notification->socid = 
$id;
 
 1253    $sql = 
"SELECT t.rowid as id FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
 
 1254    $sql .= 
" WHERE t.code = '".$this->db->escape($code).
"'";
 
 1256    $result = $this->db->query($sql);
 
 1257    if ($this->db->num_rows($result) == 0) {
 
 1258      throw new RestException(404, 
'Action Trigger code not found');
 
 1261    $notification->event = $this->db->fetch_row($result)[0];
 
 1262    foreach ($request_data as $field => $value) {
 
 1263      if ($field === 
'event') {
 
 1264        throw new RestException(500, 
'Error creating Thirdparty Notification, request_data contains event key');
 
 1266      if ($field === 
'fk_action') {
 
 1267        throw new RestException(500, 
'Error creating Thirdparty Notification, request_data contains fk_action key');
 
 1269      $notification->$field = $value;
 
 1272    $event = $notification->event;
 
 1273    $socid = $notification->socid;
 
 1274    $contact_id = $notification->contact_id;
 
 1276    $exists_sql = 
"SELECT rowid, fk_action as event, fk_soc as socid, fk_contact as contact_id, type, datec, tms as datem";
 
 1277    $exists_sql .= 
" FROM ".MAIN_DB_PREFIX.
"notify_def";
 
 1278    $exists_sql .= 
" WHERE fk_action = '".$this->db->escape($event).
"'";
 
 1279    $exists_sql .= 
" AND fk_soc = '".$this->db->escape($socid).
"'";
 
 1280    $exists_sql .= 
" AND fk_contact = '".$this->db->escape($contact_id).
"'";
 
 1282    $exists_result = $this->db->query($exists_sql);
 
 1283    if ($this->db->num_rows($exists_result) > 0) {
 
 1284      throw new RestException(403, 
'Notification already exists');
 
 1287    if ($notification->create(DolibarrApiAccess::$user) < 0) {
 
 1288      throw new RestException(500, 
'Error creating Thirdparty Notification, are request_data well formed?');
 
 1291    if ($notification->update(DolibarrApiAccess::$user) < 0) {
 
 1292      throw new RestException(500, 
'Error updating values');
 
 
 1310    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1311      throw new RestException(403);
 
 1314    $notification = 
new Notify($this->db);
 
 1316    $notification->fetch($notification_id);
 
 1318    $socid = (int) $notification->socid;
 
 1320    if ($socid == 
$id) {
 
 1321      return $notification->delete(DolibarrApiAccess::$user);
 
 1323      throw new RestException(403, 
"Not allowed due to bad consistency of input data");
 
 
 1340    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1341      throw new RestException(403, 
"User has no right to update thirdparties");
 
 1343    if ($this->company->fetch(
$id) <= 0) {
 
 1344      throw new RestException(404, 
'Error creating Company Notification, Company doesn\'t exists');
 
 1346    $notification = 
new Notify($this->db);
 
 1349    $notification->fetch($notification_id, 
$id);
 
 1351    if ($notification->socid != 
$id) {
 
 1352      throw new RestException(403, 
"Not allowed due to bad consistency of input data");
 
 1355    foreach ($request_data as $field => $value) {
 
 1356      $notification->$field = $value;
 
 1359    if ($notification->update(DolibarrApiAccess::$user) < 0) {
 
 1360      throw new RestException(500, 
'Error updating values');
 
 
 1377    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
 1378      throw new RestException(403);
 
 1381      throw new RestException(400, 
'Thirdparty ID is mandatory');
 
 1385      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
 1392    $sql = 
"SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation as address, proprio,";
 
 1393    $sql .= 
" owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
 
 1394    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
 
 1396      $sql .= 
" WHERE fk_soc  = ".((int) 
$id);
 
 1399    $result = $this->db->query($sql);
 
 1401    if ($this->db->num_rows($result) == 0) {
 
 1402      throw new RestException(404, 
'Account not found');
 
 1407    $accounts = array();
 
 1410      $num = $this->db->num_rows($result);
 
 1412        $obj = $this->db->fetch_object($result);
 
 1415        if ($account->fetch($obj->rowid)) {
 
 1416          $accounts[] = $account;
 
 1421      throw new RestException(404, 
'Account not found');
 
 1425    $fields = array(
'socid', 
'default_rib', 
'frstrecur', 
'1000110000001', 
'datec', 
'datem', 
'label', 
'bank', 
'bic', 
'iban', 
'id', 
'rum');
 
 1427    $returnAccounts = array();
 
 1429    foreach ($accounts as $account) {
 
 1431      foreach ($account as $key => $value) {
 
 1432        if (in_array($key, $fields)) {
 
 1433          if ($key == 
'iban') {
 
 1443    return $returnAccounts;
 
 
 1457    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1458      throw new RestException(403);
 
 1460    if ($this->company->fetch(
$id) <= 0) {
 
 1461      throw new RestException(404, 
'Error creating Company Bank account, Company doesn\'t exists');
 
 1465    $account->socid = 
$id;
 
 1467    foreach ($request_data as $field => $value) {
 
 1468      if ($field === 
'caller') {
 
 1470        $this->company->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
 1474      $account->$field = $this->
_checkValForAPI(
'extrafields', $value, $account);
 
 1477    if ($account->create(DolibarrApiAccess::$user) < 0) {
 
 1478      throw new RestException(500, 
'Error creating Company Bank account');
 
 1481    if (empty($account->rum)) {
 
 1482      require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
 
 1484      $account->rum = $prelevement->buildRumNumber($this->company->code_client, $account->datec, $account->id);
 
 1485      $account->date_rum = 
dol_now();
 
 1488    if ($account->update(DolibarrApiAccess::$user) < 0) {
 
 1489      throw new RestException(500, 
'Error updating values');
 
 
 1508    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1509      throw new RestException(403);
 
 1511    if ($this->company->fetch(
$id) <= 0) {
 
 1512      throw new RestException(404, 
'Error creating Company Bank account, Company doesn\'t exists');
 
 1517    $account->fetch($bankaccount_id, 
'', 
$id, -1, 
'');
 
 1519    if ($account->socid != 
$id) {
 
 1520      throw new RestException(403);
 
 1524    foreach ($request_data as $field => $value) {
 
 1525      if ($field === 
'caller') {
 
 1527        $account->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
 1534    if (empty($account->rum)) {
 
 1535      require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
 
 1537      $account->rum = $prelevement->buildRumNumber($this->company->code_client, $account->datec, $account->id);
 
 1538      $account->date_rum = 
dol_now();
 
 1541    if ($account->update(DolibarrApiAccess::$user) < 0) {
 
 1542      throw new RestException(500, 
'Error updating values');
 
 
 1560    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1561      throw new RestException(403);
 
 1566    $account->fetch($bankaccount_id);
 
 1568    $socid = (int) $account->socid;
 
 1570    if ($socid == 
$id) {
 
 1571      return $account->delete(DolibarrApiAccess::$user);
 
 1573      throw new RestException(403, 
"Not allowed due to bad consistency of input data");
 
 
 1589    global 
$conf, $langs;
 
 1591    $langs->loadLangs(array(
"main", 
"dict", 
"commercial", 
"products", 
"companies", 
"banks", 
"bills", 
"withdrawals"));
 
 1593    if ($this->company->fetch(
$id) <= 0) {
 
 1594      throw new RestException(404, 
'Thirdparty not found');
 
 1597    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1598      throw new RestException(403);
 
 1601    $this->company->setDocModel(DolibarrApiAccess::$user, $model);
 
 1603    $this->company->fk_bank = $this->company->fk_account;
 
 1606    $outputlangs = $langs;
 
 1611      if (isset($this->company->thirdparty->default_lang)) {
 
 1612        $newlang = $this->company->thirdparty->default_lang; 
 
 1613      } elseif (isset($this->company->default_lang)) {
 
 1614        $newlang = $this->company->default_lang; 
 
 1617    if (!empty($newlang)) {
 
 1619      $outputlangs->setDefaultLang($newlang);
 
 1622    $sql = 
"SELECT rowid";
 
 1623    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
 
 1625      $sql .= 
" WHERE fk_soc = ".((int) 
$id);
 
 1627    if ($companybankid) {
 
 1628      $sql .= 
" AND rowid = ".((int) $companybankid);
 
 1632    $accounts = array();
 
 1634    $result = $this->db->query($sql);
 
 1636      if ($this->db->num_rows($result) == 0) {
 
 1637        throw new RestException(404, 
'Bank account not found');
 
 1640      $num = $this->db->num_rows($result);
 
 1642        $obj = $this->db->fetch_object($result);
 
 1645        if ($account->fetch($obj->rowid)) {
 
 1646          $accounts[] = $account;
 
 1651      throw new RestException(500, 
'Sql error '.$this->db->lasterror());
 
 1654    $moreparams = array(
 
 1655      'use_companybankid' => $accounts[0]->
id,
 
 1656      'force_dir_output' => 
$conf->societe->multidir_output[$this->company->entity].
'/'.
dol_sanitizeFileName((
string) $this->company->id)
 
 1659    $result = $this->company->generateDocument($model, $outputlangs, 0, 0, 0, $moreparams);
 
 1662      return array(
"success" => $result);
 
 1664      throw new RestException(500, 
'Error generating the document '.$this->company->error);
 
 
 1682    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
 1683      throw new RestException(403);
 
 1687      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
 1693    $sql = 
"SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX.
"societe_account";
 
 1694    $sql .= 
" WHERE fk_soc = ".((int) 
$id);
 
 1696      $sql .= 
" AND site ='".$this->db->escape($site).
"'";
 
 1699    $result = $this->db->query($sql);
 
 1701    if ($result && $this->db->num_rows($result) == 0) {
 
 1702      throw new RestException(404, 
'This thirdparty does not have any account attached or does not exist.');
 
 1707    $accounts = array();
 
 1709    $num = $this->db->num_rows($result);
 
 1711      $obj = $this->db->fetch_object($result);
 
 1714      if ($account->fetch($obj->rowid)) {
 
 1715        $accounts[] = $account;
 
 1720    $fields = array(
'id', 
'fk_soc', 
'key_account', 
'site', 
'date_creation', 
'tms');
 
 1722    $returnAccounts = array();
 
 1724    foreach ($accounts as $account) {
 
 1726      foreach ($account as $key => $value) {
 
 1727        if (in_array($key, $fields)) {
 
 1734    return $returnAccounts;
 
 
 1751    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
 1752      throw new RestException(403);
 
 1755    $sql = 
"SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX.
"societe_account";
 
 1756    $sql .= 
" WHERE site = '".$this->db->escape($site).
"' AND key_account = '".$this->db->escape($key_account).
"'";
 
 1757    $sql .= 
" AND entity IN (".getEntity(
'societe').
")";
 
 1759    $result = $this->db->query($sql);
 
 1761    if ($result && $this->db->num_rows($result) == 1) {
 
 1762        $obj = $this->db->fetch_object($result);
 
 1763        $returnThirdparty = $this->
_fetch($obj->fk_soc);
 
 1765        throw new RestException(404, 
'This account have many thirdparties attached or does not exist.');
 
 1769      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login);
 
 1772    return $returnThirdparty;
 
 
 1796    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1797      throw new RestException(403);
 
 1800    if (!isset($request_data[
'site'])) {
 
 1801      throw new RestException(422, 
'Unprocessable Entity: You must pass the site attribute in your request data !');
 
 1804    $sql = 
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_account WHERE fk_soc  = ".((int) 
$id).
" AND site = '".$this->db->escape($request_data[
'site']).
"'";
 
 1805    $result = $this->db->query($sql);
 
 1807    if ($result && $this->db->num_rows($result) == 0) {
 
 1809      if (!isset($request_data[
'login'])) {
 
 1810        $account->login = 
"";
 
 1812      $account->fk_soc = 
$id;
 
 1814      foreach ($request_data as $field => $value) {
 
 1815        if ($field === 
'caller') {
 
 1817          $account->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
 1824      if ($account->create(DolibarrApiAccess::$user) < 0) {
 
 1825        throw new RestException(500, 
'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!');
 
 1832      throw new RestException(409, 
'A SocieteAccount entity already exists for this company and site.');
 
 
 1860    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1861      throw new RestException(403);
 
 1864    $sql = 
"SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX.
"societe_account WHERE fk_soc = $id AND site = '".$this->db->escape($site).
"'";
 
 1865    $result = $this->db->query($sql);
 
 1868    if ($result && $this->db->num_rows == 0) {
 
 1869      if (!isset($request_data[
'key_account'])) {
 
 1870        throw new RestException(422, 
'Unprocessable Entity: You must pass the key_account attribute in your request data !');
 
 1873      if (!isset($request_data[
'login'])) {
 
 1874        $account->login = 
"";
 
 1877      foreach ($request_data as $field => $value) {
 
 1878        if ($field === 
'caller') {
 
 1880          $account->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
 1887      $account->fk_soc = 
$id;
 
 1888      $account->site = $site;
 
 1890      if ($account->create(DolibarrApiAccess::$user) < 0) {
 
 1891        throw new RestException(500, 
'Error creating SocieteAccount entity.');
 
 1895      if (isset($request_data[
'site']) && $request_data[
'site'] !== $site) {
 
 1896        $sql = 
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_account WHERE fk_soc  = ".((int) 
$id).
" AND site = '".$this->db->escape($request_data[
'site']).
"' ";
 
 1897        $result = $this->db->query($sql);
 
 1899        if ($result && $this->db->num_rows($result) !== 0) {
 
 1900          throw new RestException(409, 
"You are trying to update this thirdparty Account for $site to ".$request_data[
'site'].
" but another Account already exists with this site key.");
 
 1904      $obj = $this->db->fetch_object($result);
 
 1907      $account->id = $obj->rowid;
 
 1908      $account->fk_soc = 
$id;
 
 1909      $account->site = $site;
 
 1910      if (!isset($request_data[
'login'])) {
 
 1911        $account->login = 
"";
 
 1913      $account->fk_user_creat = $obj->fk_user_creat;
 
 1914      $account->date_creation = $obj->date_creation;
 
 1916      foreach ($request_data as $field => $value) {
 
 1917        if ($field === 
'caller') {
 
 1919          $account->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
 1926      if ($account->update(DolibarrApiAccess::$user) < 0) {
 
 1927        throw new RestException(500, 
'Error updating SocieteAccount entity.');
 
 
 1954    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 1955      throw new RestException(403);
 
 1958    $sql = 
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_account WHERE fk_soc = ".((int) 
$id).
" AND site = '".$this->db->escape($site).
"'";
 
 1959    $result = $this->db->query($sql);
 
 1961    if ($result && $this->db->num_rows($result) == 0) {
 
 1962      throw new RestException(404, 
"This thirdparty does not have $site account attached or does not exist.");
 
 1965      if (isset($request_data[
'site']) && $request_data[
'site'] !== $site) {
 
 1966        $sql = 
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_account WHERE fk_soc  = ".((int) 
$id).
" AND site = '".$this->db->escape($request_data[
'site']).
"' ";
 
 1967        $result = $this->db->query($sql);
 
 1969        if ($result && $this->db->num_rows($result) !== 0) {
 
 1970          throw new RestException(409, 
"You are trying to update this thirdparty Account for ".$site.
" to ".$request_data[
'site'].
" but another Account already exists for this thirdparty with this site key.");
 
 1974      $obj = $this->db->fetch_object($result);
 
 1976      $account->fetch($obj->rowid);
 
 1978      foreach ($request_data as $field => $value) {
 
 1979        if ($field === 
'caller') {
 
 1981          $account->context[
'caller'] = 
sanitizeVal($request_data[
'caller'], 
'aZ09');
 
 1988      if ($account->update(DolibarrApiAccess::$user) < 0) {
 
 1989        throw new RestException(500, 
'Error updating SocieteAccount account');
 
 
 2013    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 2014      throw new RestException(403);
 
 2017    $sql = 
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_account WHERE fk_soc  = $id AND site = '".$this->db->escape($site).
"'";
 
 2018    $result = $this->db->query($sql);
 
 2020    if ($result && $this->db->num_rows($result) == 0) {
 
 2021      throw new RestException(404);
 
 2023      $obj = $this->db->fetch_object($result);
 
 2025      $account->fetch($obj->rowid);
 
 2027      if ($account->delete(DolibarrApiAccess::$user) < 0) {
 
 2028        throw new RestException(500, 
"Error while deleting $site account attached to this third party");
 
 
 2047    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'creer')) {
 
 2048      throw new RestException(403);
 
 2055    $sql = 
"SELECT rowid, fk_soc, key_account, site, date_creation, tms";
 
 2056    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe_account WHERE fk_soc = ".((int) 
$id);
 
 2058    $result = $this->db->query($sql);
 
 2060    if ($result && $this->db->num_rows($result) == 0) {
 
 2061      throw new RestException(404, 
'This third party does not have any account attached or does not exist.');
 
 2065      $num = $this->db->num_rows($result);
 
 2067        $obj = $this->db->fetch_object($result);
 
 2069        $account->fetch($obj->rowid);
 
 2071        if ($account->delete(DolibarrApiAccess::$user) < 0) {
 
 2072          throw new RestException(500, 
'Error while deleting account attached to this third party');
 
 
 2095    unset(
$object->departement_code);
 
 2104    unset(
$object->commercial_id); 
 
 2108    unset(
$object->total_localtax1);
 
 2109    unset(
$object->total_localtax2);
 
 2115    unset(
$object->fk_delivery_address); 
 
 
 2130    $thirdparty = array();
 
 2131    foreach (Thirdparties::$FIELDS as $field) {
 
 2132      if (!isset($data[$field])) {
 
 2133        throw new RestException(400, 
"$field field missing");
 
 2135      $thirdparty[$field] = $data[$field];
 
 
 2161  private function _fetch($rowid, $ref = 
'', $ref_ext = 
'', $barcode = 
'', $idprof1 = 
'', $idprof2 = 
'', $idprof3 = 
'', $idprof4 = 
'', $idprof5 = 
'', $idprof6 = 
'', $email = 
'', $ref_alias = 
'')
 
 2163    if (!DolibarrApiAccess::$user->hasRight(
'societe', 
'lire')) {
 
 2164      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login.
'. No read permission on thirdparties.');
 
 2168      $result = $this->company->initAsSpecimen();
 
 2170      $result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
 
 2173      throw new RestException(404, 
'Thirdparty not found');
 
 2177      throw new RestException(403, 
'Access not allowed for login '.DolibarrApiAccess::$user->login.
' on this thirdparty');
 
 2179    if (isModEnabled(
'mailing')) {
 
 2180      $this->company->getNoEmail();
 
 2184      $filterabsolutediscount = 
"fk_facture_source IS NULL"; 
 
 2185      $filtercreditnote = 
"fk_facture_source IS NOT NULL"; 
 
 2187      $filterabsolutediscount = 
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
 
 2188      $filtercreditnote = 
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
 
 2191    $absolute_discount = $this->company->getAvailableDiscounts(
'', $filterabsolutediscount);
 
 2192    $absolute_creditnote = $this->company->getAvailableDiscounts(
'', $filtercreditnote);
 
 2193    $this->company->absolute_discount = 
price2num($absolute_discount, 
'MT');
 
 2194    $this->company->absolute_creditnote = 
price2num($absolute_creditnote, 
'MT');
 
 
 
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
 
Class to manage withdrawal receipts.
 
Class to manage categories.
 
Class to manage bank accounts description of third parties.
 
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
 
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
 
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
 
Class to manage invoices.
 
Class to manage the table of subscription to notifications.
 
Class for SocieteAccount.
 
Class to manage third parties objects (customers, suppliers, prospects...)
 
updateCompanyNotification($id, $notification_id, $request_data=null)
Update CompanyNotification object for thirdparty.
 
setThirdpartyPriceLevel($id, $priceLevel)
Set new price level for the given thirdparty.
 
_cleanObjectDatas($object)
Clean sensible object datas.
 
getSocieteByAccounts($site, $key_account)
Get a specific thirdparty by account.
 
getSupplierCategories($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Get supplier categories for a thirdparty.
 
deleteCompanyNotification($id, $notification_id)
Delete a CompanyNotification attached to a thirdparty.
 
getSocieteAccounts($id, $site=null)
Get a specific account attached to a thirdparty (by specifying the site key)
 
getOutStandingOrder($id, $mode='customer')
Get outstanding orders of thirdparty.
 
addRepresentative($id, $representative_id)
Add a customer representative to a thirdparty.
 
getByBarcode($barcode)
Get properties of a thirdparty object by barcode.
 
generateBankAccountDocument($id, $companybankid=null, $model='sepamandate')
Generate a Document from a bank account record (like SEPA mandate)
 
createCompanyNotificationByCode($id, $code, $request_data=null)
Create CompanyNotification object for thirdparty using action trigger code.
 
getCompanyNotification($id)
Get CompanyNotification objects for thirdparty.
 
addCategory($id, $category_id)
Add a customer category to a thirdparty.
 
getCompanyBankAccount($id)
Get CompanyBankAccount objects for thirdparty.
 
getInvoicesQualifiedForReplacement($id)
Return list of invoices qualified to be replaced by another invoice.
 
post($request_data=null)
Create thirdparty object.
 
put($id, $request_data=null)
Update thirdparty.
 
getByEmail($email)
Get properties of a thirdparty object by email.
 
_validate($data)
Validate fields before create or update object.
 
addSupplierCategory($id, $category_id)
Add a supplier category to a thirdparty.
 
merge($id, $idtodelete)
Merge a third party into another one.
 
deleteSocieteAccounts($id)
Delete all accounts attached to a thirdparty.
 
__construct()
Constructor.
 
getCategories($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Get customer categories for a thirdparty.
 
deleteSupplierCategory($id, $category_id)
Remove the link between a category and the thirdparty.
 
deleteRepresentative($id, $representative_id)
Delete a customer representative to a thirdparty.
 
createCompanyNotification($id, $request_data=null)
Create CompanyNotification object for thirdparty.
 
putSocieteAccount($id, $site, $request_data=null)
Create and attach a new (or replace an existing) specific site account to a thirdparty.
 
updateCompanyBankAccount($id, $bankaccount_id, $request_data=null)
Update CompanyBankAccount object for thirdparty.
 
deleteSocieteAccount($id, $site)
Delete a specific site account attached to a thirdparty (by account id)
 
getInvoicesQualifiedForCreditNote($id)
Return list of invoices qualified to be corrected by a credit note.
 
patchSocieteAccount($id, $site, $request_data=null)
Update specified values of a specific account attached to a thirdparty.
 
getFixedAmountDiscounts($id, $filter="none", $sortfield="f.type", $sortorder='ASC')
Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers....
 
getOutStandingProposals($id, $mode='customer')
Get outstanding proposals of thirdparty.
 
_fetch($rowid, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='')
Fetch properties of a thirdparty object.
 
getSalesRepresentatives($id, $mode=0)
Get representatives of thirdparty.
 
getOutStandingInvoices($id, $mode='customer')
Get outstanding invoices of thirdparty.
 
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $mode=0, $category=0, $sqlfilters='', $properties='', $pagination_data=false)
List thirdparties.
 
deleteCompanyBankAccount($id, $bankaccount_id)
Delete a bank account attached to a thirdparty.
 
createSocieteAccount($id, $request_data=null)
Create and attach a new account to an existing thirdparty.
 
createCompanyBankAccount($id, $request_data=null)
Create CompanyBankAccount object for thirdparty.
 
deleteCategory($id, $category_id)
Remove the link between a customer category and the thirdparty.
 
Class to manage translations.
 
Class to manage Dolibarr users.
 
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
 
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
 
dol_now($mode='auto')
Return date for now.
 
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
 
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
 
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
 
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
 
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
 
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.