dolibarr/htdocs/societe/class/api_thirdparties.class.php

2819 lines
96 KiB
PHP
Raw Permalink Normal View History

<?php
2024-03-14 22:39:16 +00:00
/* 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-2025 Frédéric France <frederic.france@free.fr>
2024-03-14 22:39:16 +00:00
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
* Copyright (C) 2025 William Mead <william@m34d.com>
* Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2026 Benjamin Falière <benjamin@faliere.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use Luracast\Restler\RestException;
/**
* API class for thirdparties
*
* @since 3.8.0 Initial implementation
*
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
class Thirdparties extends DolibarrApi
2015-05-05 22:55:42 +00:00
{
/**
2025-03-03 00:49:20 +00:00
* @var string[] Mandatory fields, checked when we create and update the object
*/
2021-02-26 20:17:52 +00:00
public static $FIELDS = array(
'name'
);
/**
* @var Societe {@type Societe}
*/
public $company;
/**
* Constructor
*/
public function __construct()
{
2024-03-14 22:39:16 +00:00
global $db;
$this->db = $db;
2017-10-22 12:48:42 +00:00
2020-12-21 14:25:15 +00:00
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
2017-10-22 12:48:42 +00:00
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2018-10-16 19:43:40 +00:00
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
2024-03-13 22:14:49 +00:00
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
2017-10-22 12:48:42 +00:00
$this->company = new Societe($this->db);
2023-11-27 11:08:48 +00:00
if (getDolGlobalString('SOCIETE_EMAIL_MANDATORY')) {
static::$FIELDS[] = 'email';
}
}
/**
* Get a third party
*
* Return the third party object
*
* @since 3.8.0 Initial implementation
*
* @param int $id ID of the third party to load
* @return Object Object with cleaned properties
*
2023-09-26 16:43:25 +00:00
* @throws RestException
*/
public function get($id)
{
return $this->_fetch($id);
}
/**
* Get properties of a third party by email.
*
* Return an array with third party information
*
* @since 11.0.0 Initial implementation
*
* @param string $email Email of the third party to load
* @return array|mixed Cleaned Societe object
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @url GET email/{email}
*
* @throws RestException
*/
public function getByEmail($email)
{
return $this->_fetch(null, '', '', '', '', '', '', '', '', '', $email);
}
2020-08-29 09:39:10 +00:00
2020-08-29 09:37:16 +00:00
/**
* Get a third party by barcode.
2020-08-29 09:37:16 +00:00
*
* Return an array with third party information
2020-08-29 09:37:16 +00:00
*
* @since 13.0.0 Initial implementation
2020-08-29 09:37:16 +00:00
*
* @param string $barcode Barcode of the third party
* @return array|mixed Cleaned Societe object
*
* @url GET barcode/{barcode}
2020-08-29 09:37:16 +00:00
*
* @throws RestException
*/
public function getByBarcode($barcode)
{
return $this->_fetch(null, '', '', $barcode);
2020-08-29 09:37:16 +00:00
}
/**
* List third parties
*
* Get a list of third parties
*
* @since 3.8.0 Initial implementation
* @since 21.0.0 Data pagination
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit List limit
* @param int $page Page number
* @param int $mode Set to 0 to show all third parties, Set to 1 to show only customers, 2 for prospects, 3 for neither customer nor prospect, 4 for suppliers
* @param int $category Use this param to filter the list by category
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "((t.nom:like:'TheCompany%') or (t.name_alias:like:'TheCompany%')) and (t.datec:<:'20160101')"
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
* @param bool $pagination_data If this parameter is set to true, the response will include pagination data. The default value is false. Page starts from 0*
* @return array Array of third party objects
2025-03-03 00:49:20 +00:00
* @phan-return Societe[]|array{data:Societe[],pagination:array{total:int,page:int,page_count:int,limit:int}}
* @phpstan-return Societe[]|array{data:Societe[],pagination:array{total:int,page:int,page_count:int,limit:int}}
*
* @throws RestException 400
* @throws RestException 403
* @throws RestException 404
* @throws RestException 503
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '', $properties = '', $pagination_data = false)
{
$obj_ret = array();
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
// case of external user, we force socids
$socids = DolibarrApiAccess::$user->socid ? (string) DolibarrApiAccess::$user->socid : '';
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'client', 'voir') && !$socids) {
2021-02-26 20:17:52 +00:00
$search_sale = DolibarrApiAccess::$user->id;
}
$sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as t";
2022-12-15 19:34:23 +00:00
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields AS ef ON ef.fk_object = t.rowid"; // So we will be able to filter on extrafields
if ($category > 0) {
2021-02-26 20:17:52 +00:00
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";
}
}
2020-05-28 17:50:27 +00:00
$sql .= " WHERE t.entity IN (".getEntity('societe').")";
2021-02-26 20:17:52 +00:00
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 third parties of a given category
if ($category > 0) {
2021-02-26 20:17:52 +00:00
if (!empty($mode) && $mode != 4) {
2021-06-09 13:36:47 +00:00
$sql .= " AND c.fk_categorie = ".((int) $category)." AND c.fk_soc = t.rowid";
2021-02-26 20:17:52 +00:00
} elseif (!empty($mode) && $mode == 4) {
2021-06-09 13:36:47 +00:00
$sql .= " AND cc.fk_categorie = ".((int) $category)." AND cc.fk_soc = t.rowid";
2021-02-26 20:17:52 +00:00
} else {
2021-06-09 13:36:47 +00:00
$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))";
2021-02-26 20:17:52 +00:00
}
}
2021-02-26 20:17:52 +00:00
if ($socids) {
2021-03-22 10:30:18 +00:00
$sql .= " AND t.rowid IN (".$this->db->sanitize($socids).")";
2021-02-26 20:17:52 +00:00
}
// Search on sale representative
if ($search_sale && $search_sale != '-1') {
if ($search_sale == -2) {
$sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.rowid)";
} elseif ($search_sale > 0) {
$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).")";
}
}
// Add sql filters
2021-02-26 20:17:52 +00:00
if ($sqlfilters) {
2021-12-20 19:49:32 +00:00
$errormessage = '';
2023-02-25 18:48:33 +00:00
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
if ($errormessage) {
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
}
}
//this query will return total thirdparties with the filters given
$sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit) {
2020-11-05 22:03:44 +00:00
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
2020-09-19 21:30:29 +00:00
$sql .= $this->db->plimit($limit + 1, $offset);
}
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2021-02-26 20:17:52 +00:00
if ($result) {
2020-09-19 21:30:29 +00:00
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0;
2021-02-26 20:17:52 +00:00
while ($i < $min) {
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
$soc_static = new Societe($this->db);
if ($soc_static->fetch($obj->rowid)) {
2022-08-29 12:46:26 +00:00
if (isModEnabled('mailing')) {
$soc_static->getNoEmail();
}
2023-09-26 16:04:48 +00:00
$obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($soc_static), $properties);
}
$i++;
}
2020-05-21 13:05:19 +00:00
} else {
throw new RestException(503, 'Error when retrieve third parties : '.$this->db->lasterror());
}
if (!count($obj_ret)) {
$message = '';
switch ($mode) {
case 0:
$message = 'No third parties found';
break;
case 1:
$message = 'No customers found';
break;
case 2:
$message = 'No prospects found';
break;
case 3:
$message = 'No other third parties found';
break;
case 4:
$message = 'No suppliers found';
}
throw new RestException(404, $message);
}
//if $pagination_data is true, the response will contain element data with all values and element pagination with pagination data(total,page,limit)
if ($pagination_data) {
$totalsResult = $this->db->query($sqlTotals);
$total = $this->db->fetch_object($totalsResult)->total;
$tmp = $obj_ret;
$obj_ret = [];
$obj_ret['data'] = $tmp;
$obj_ret['pagination'] = [
'total' => (int) $total,
'page' => $page, //count starts from 0
'page_count' => ceil((int) $total / $limit),
'limit' => $limit
];
}
2015-05-03 14:59:47 +00:00
return $obj_ret;
}
/**
* Create a third party
*
* @since 3.8.0 Initial implementation
*
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return int ID of third party
*
* @throws RestException
*/
public function post($request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
// External api user does not know internal country ID
if (!isset($request_data['country_id']) && isset($request_data['country_code'])) {
$field = strlen($request_data['country_code']) > 2 ? 'code_iso' : 'code';
$id = dol_getIdFromCode($this->db, $request_data['country_code'], "c_country", $field, "rowid");
if ($id < 0) {
throw new RestException(404, 'Country code not found in database: ' . $this->db->error);
}
$request_data['country_id'] = $id;
}
// Check mandatory fields
$result = $this->_validate($request_data);
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$this->company->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
if ($field == 'array_options' && is_array($value)) {
$this->company->fetch_optionals(); // To force the load of the extrafields definition by fetch_name_optionals_label()
foreach ($value as $index => $val) {
$this->company->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->company);
}
continue;
}
2024-03-14 22:39:16 +00:00
$this->company->$field = $this->_checkValForAPI($field, $value, $this->company);
}
2021-02-26 20:17:52 +00:00
if ($this->company->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
2021-02-26 20:17:52 +00:00
}
2022-08-29 12:46:26 +00:00
if (isModEnabled('mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
$this->company->setNoEmail($this->company->no_email);
}
return $this->company->id;
}
/**
* Update third party
*
* @since 3.8.0 Initial implementation
*
* @param int $id ID of thirdparty to update
* @param array $request_data Data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return Object Updated object
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500
*/
public function put($id, $request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
foreach ($request_data as $field => $value) {
2021-02-26 20:17:52 +00:00
if ($field == 'id') {
continue;
}
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$this->company->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
if ($field == 'array_options' && is_array($value)) {
foreach ($value as $index => $val) {
$this->company->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->company);
}
continue;
}
2024-03-14 22:39:16 +00:00
$this->company->$field = $this->_checkValForAPI($field, $value, $this->company);
}
2022-08-29 12:46:26 +00:00
if (isModEnabled('mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
$this->company->setNoEmail($this->company->no_email);
}
if ($this->company->update($id, DolibarrApiAccess::$user, 1, 1, 1, 'update', 1) > 0) {
return $this->get($id);
} else {
throw new RestException(500, $this->company->error);
2020-11-05 22:03:44 +00:00
}
}
/**
* Merge a third party into another third party
*
* Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a third party into a target third party,
2024-03-16 15:21:43 +00:00
* then delete the merged third party.
* If a property has a defined value both in the third party to delete and the third party to keep, the value of the third party to
* delete will be ignored, the value of the target third party will remain, except for notes (content is concatenated).
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of thirdparty to keep (the target third party)
* @param int $idtodelete ID of thirdparty to remove (the third party to delete), once data has been merged into the target third party.
* @return Object Return the resulted third party.
*
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @url PUT {id}/merge/{idtodelete}
*
* @throws RestException
*/
public function merge($id, $idtodelete)
{
2021-02-26 20:17:52 +00:00
if ($id == $idtodelete) {
throw new RestException(400, 'Try to merge a thirdparty into itself');
}
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id); // include the fetch of extra fields
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
2023-08-06 11:02:33 +00:00
$companytoremove = new Societe($this->db);
$result = $companytoremove->fetch($idtodelete); // include the fetch of extra fields
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
2023-08-06 11:02:33 +00:00
if (!DolibarrApi::_checkAccessToResource('societe', $companytoremove->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$user = DolibarrApiAccess::$user;
QUAL Refactor merging companies and fix #26272 with Reception objects (#26320) * societe: add missing model_pdf field The field is used by the class but wasn't declared. * societe: expose Societe::mergeCompany The code is directly copied from societe/card.php with as less changes as possible. The original code came from deb91ad7c17490934c988b36823a21ba03354733. * societe: remove fields from property copy $phone_pro and $fk_project are not existing for societe. This was added from deb91ad7c17490934c988b36823a21ba03354733. * SocieteTest: test the merge functionality This test is a simple smoke test to check that the mergeCompany() will work correctly on simple case and actually merge the details of the company. More complex deduplication pattern with objects referencing the deleted Societe object, will be written for each of the different object class in their respective test file. * societe: card: use the new mergeCompany function Since the code is almost the same, there should be no differences in behaviour right now. * societe: api_thirdparties: use Societe::mergeCompany() * societe: fix issue when merging companies When a Societe object is merged against another, its related objects are supposed to reference the new Societe object so that the databse doesn't raise foreign key errors. The list references the objects that need to be transformed, and Reception objects weren't part of this list. Fix #26272 * ReceptionTest: check company merge hook Before a Societe object is destroyed from the database, every object referencing the FK should be destroyed or should reference another object. In the case of two companies being merged, the case arises and Reception objects need to be moved to the new company. This commit brings a non-regression test for this case. Refs #26272 * Update societe.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2023-10-26 14:30:38 +00:00
$result = $this->company->mergeCompany($companytoremove->id);
2021-02-26 20:17:52 +00:00
if ($result < 0) {
2023-08-06 11:02:33 +00:00
throw new RestException(500, 'Error failed to merged thirdparty '.$companytoremove->id.' into '.$id.'. Enable and read log file for more information.');
}
return $this->get($id);
}
/**
* Delete a third party
*
* @since 3.8.0 Initial implementation
*
* @param int $id ID of the third party
* @return array
2025-03-02 14:10:25 +00:00
* @phan-return array{success:array{code:int,message:string}}
* @phpstan-return array{success:array{code:int,message:string}}
*
* @throws RestException
*/
public function delete($id)
{
2022-09-10 09:19:54 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'supprimer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
2025-03-03 13:23:57 +00:00
$this->company->oldcopy = clone $this->company; // @phan-suppress-current-line PhanTypeMismatchProperty
$res = $this->company->delete($id);
2022-11-25 23:57:35 +00:00
if ($res < 0) {
throw new RestException(500, "Can't delete, error occurs");
2022-11-25 23:57:35 +00:00
} elseif ($res == 0) {
throw new RestException(409, "Can't delete, that product is probably used");
}
return array(
'success' => array(
'code' => 200,
'message' => 'Object deleted'
)
);
}
/**
* Set a new price level for the given third party
*
* @since 13.0.0 Initial implementation
*
* @param int $id ID of thirdparty
* @param int $priceLevel Price level to apply to thirdparty
2024-03-16 15:21:43 +00:00
* @return Object Thirdparty data without useless information
*
* @url PUT {id}/setpricelevel/{priceLevel}
*
* @throws RestException 400 Price level out of bounds
* @throws RestException 401 Access not allowed for your login
* @throws RestException 404 Third party 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;
2022-08-29 07:29:56 +00:00
if (!isModEnabled('societe')) {
throw new RestException(501, 'Module "Thirdparties" needed for this request');
}
2023-04-18 18:16:02 +00:00
if (!isModEnabled("product")) {
throw new RestException(501, 'Module "Products" needed for this request');
}
if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
throw new RestException(501, 'Multiprices features activation needed for this request');
}
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if ($priceLevel < 1 || $priceLevel > getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT')) {
2023-10-15 16:39:13 +00:00
throw new RestException(400, 'Price level must be between 1 and ' . getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT'));
}
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-04-07 12:59:25 +00:00
throw new RestException(403, '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))) {
2024-04-07 12:59:25 +00:00
throw new RestException(403, 'Access to thirdparty '.$id.' not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->setPriceLevel($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);
}
NEW - API Get sales representative (#39338) * Doc * New import Leave Balance (Datastructure) (#37001) * New import Leave Balance (Datastructure) * fix --------- Co-authored-by: Lucas Marcouiller <lmarcouiller@dolicloud.com> * Qual: Update Phan baseline.txt with reduced issue counts (#36996) This commit updates the Phan baseline.txt file. * Better log * Log * Better error management * Doc * Fix error message * CI * Try to fix CI * fix phan (#37007) * CI * fix phan (#37008) PhanTypeMismatchArgumentNullable Argument 3 ($txt) is $productlot->batch of type ?string but \TCPDF::MultiCell() takes string defined at htdocs/includes/tecnickcom/tcpdf/tcpdf.php:5871 (expected type to be non-nullable) * CI * NEW Add new EUID number (#36997) * Doc * ci * Fix CI * Improve OAuth HTTP error details (#36951) Keep throwing TokenResponseException on HTTP 4xx/5xx while also capturing the response body (ignore_errors) to include a short snippet for admins. Co-authored-by: caminotravelcenter <caminotravelcenter@localhost> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * NEW add import of leave balance (Implementation) (#37011) * New add import Leave Balance * add eof * Update modHoliday.class.php --------- Co-authored-by: Lucas Marcouiller <lmarcouiller@dolicloud.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * NEW add image format avif (#37014) * add format avif * Update functions.lib.php * Exclude non interesting warning * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * CI * CI * CI * Trans * CI * CI * CI * Fix typo in phpstan.neon.dist for isset() rule (#37018) See https://github.com/Dolibarr/dolibarr/actions/runs/21444577128/job/61756970301?pr=37017 * Remove jstz.min.js from JavaScript array (#37017) jstz.min.js was deleted in https://github.com/Dolibarr/dolibarr/commit/5599ac733b07d990d64e3ff18b30b3dca16d5b86 * Remove jstz.min.js from JavaScript array (#37017) jstz.min.js was deleted in https://github.com/Dolibarr/dolibarr/commit/5599ac733b07d990d64e3ff18b30b3dca16d5b86 * prevent ST_AsWKT() (#37013) * prevent ST_AsWKT() * Update commonobject.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * prevent ST_AsWKT() (#37013) * prevent ST_AsWKT() * Update commonobject.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Try to fix phan * CI * CI * ci * ci * css * qual: Update french texts (comments) to english (#37009) * qual: Update french texts (comments) to english * Qual: Update comment to english in card-rec.php and card.php Translation of comments in the files card-rec.php and card.php. * Qual: Translate comments to English * Qual: Translate comments to English * Fix space into tab * Fix spelling * Qual: Translate comments to English * Update website.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * ci * Clean code * Fix test * Debug v23 * Merge manually changes from #37012 that seems good. * Log * More robust phpunit * Populate openid data from wellknow url (#37023) * Delete inexistant file File jstz.min.js was deleted in https://github.com/Dolibarr/dolibarr/commit/5599ac733b07d990d64e3ff18b30b3dca16d5b86 * Populate openid parameters from wellknow url * CI * Debug v23 - fix code for rounding * MCP server sql part (#37025) * Create llx_ai_request_log.sql * Create llx_ai_request_log.key.sql * Update 23.0.0-24.0.0.sql * Update llx_ai_request_log.sql * Update 23.0.0-24.0.0.sql * Remove foreign key constraint from llx_ai_request_log Removed foreign key constraint for fk_user in llx_ai_request_log. --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Debug v24 * Fix syntax error * NEW allow to disable freezone product on takepos (#37004) * allow to disable freezone product on takepos * Conditionally add FreeZone product to menus * Add NoFreeZoneProduct language entry --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Fix label of dispute * [database] Minimum amount and subscription's amount formula description (#37021) * Remove jstz.min.js from JavaScript array (#37017) jstz.min.js was deleted in https://github.com/Dolibarr/dolibarr/commit/5599ac733b07d990d64e3ff18b30b3dca16d5b86 * prevent ST_AsWKT() (#37013) * prevent ST_AsWKT() * Update commonobject.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * css * Update llx_adherent_type.sql add minimumamount and amountformuladescription rows * Update 22.0.0-23.0.0.sql add minimumamount and amountformuladescription column --------- Co-authored-by: hansemschnokeloch <hansemschnokeloch@users.noreply.github.com> Co-authored-by: atm-jonathan <146709163+atm-jonathan@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * NEW: Display thirdparty name with ref in supplier orders linked objects (#36952) Co-authored-by: Zakaria Boushaba <z.boushaba@vold.africa> * css * Debug v23 * Fix type * CI * CI * Test without file list * CI * Add api document management for holiday (#36915) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * NEW Invoice - List - use select2 multiselect for status (#36834) * NEW Invoice - List - use select2 multiselect for status * Optimize * CI * CI * Review * Duplicate line and last problem * CI --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * FIX Pb in total price of line when adding the discount of a down payment when unit price was using a high accuracy. * Clean code * try to fix phan * Fix phan * Clean code * Clean code * Debug v23 * Fix LDAP * fix facture.class.php (#37031) * Debug v23 * Qual: Update french comments with 'nombre' (#37032) Update french comments with 'nombre' in their phrasing Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * fix phan (#37029) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * fix phan (#37030) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Doc * Doc comment * FIX When bank direct debit SEPA ref is > 99 * Fix when there is more than 99 direct debit in same month * Debug v24 * Merge branch '23.0' of git@github.com:Dolibarr/dolibarr.git into 23.0 * CSS * Fix when there is more than 99 direct debit in same month * Debug v24 * FIX Division by zero * FIX Division by zero * More log * More log * More log * More Log * Fix IPN payment * Fix IPN * Log * Clean code * Debug v23 - Fix ipn for dispute and withdraw funds. * fix CI (#37033) * fix CI (#37033) * CI * fix french doc (#36897) * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix * fix * fix * fix * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * fix french doc * Update html.form.class.php * Update html.form.class.php * Update index.php * fix * fix * fix * fix * fix * fix * fix * fix * Update modules_facture.php * Update phpstan.neon.dist --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Translate French comments to English (#37044) * Qual: Translate French comments to English * Qual: Translate French comments to English * Qual: Translate French comments to English ("niveau") (#37041) Translate French comments to English (comments with "niveau") * fix french doc (#37040) * warning error if no societe->id defined (#37039) * fix french doc (#37037) * fix french doc * Update dispatch.php * Update dispatch.php * Update graph.php * fix french doc (#37047) * fix french doc * Update index.php * Update index.php * Fix CI * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * CI * Fix CI * Minimum amount and subscription's amount formula description (#37006) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Warning on export/import - Add isset() protection in Export::load_arrays() & Import::load_arrays() (#37043) * Warning on export - Add isset() protection in Export::load_arrays() * Warning on import - Add isset() protection in Import::load_arrays() --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Clean comment * Warning on account model (#37042) * Error on account model * Simplify rowid assignment in accountmodel.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Fix #35394 Display public note on first page (#36993) * Display public note (an incoterms and sales rep signat) only on real first page * Display public note (an incoterms and sales rep signat) only on real first page --------- Co-authored-by: vmaury <vmaury@vmaury-Lafite-Pro-16-AMD> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * FIX: Add htmlname and selectedrate to parameters array for hook (#36998) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * FIX: Add htmlname and selectedrate to parameters array for hook (#36998) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Fix CI * Fix CI * Fix CI * Fix ci * Qual: Translate French comments to English (#37052) * Qual: Translate French 'valeur' in comments to English (#37051) * NEW Accountancy - Select between accrual accounting and cash accounting (#37050) * Qual: Translate french 'avec' comments to English (#37049) # Qual: Translate french 'avec' comments to English * FIX divisa rate indirect to direct because Dolibarr use indirect for default (#37046) * FIX rate_indirect to rate_direct Direct : 1 Divisa Currency = X Currency Main. Indirect : 1 Currency Main = X Divisa Currency. Then for Dolibarr use is Indirect for default * FIX divisa rate indirect to direct Direct : 1 Divisa Currency = X Currency Main. Indirect: 1 Currency Main = X Divisa Currency. Then for Dolibarr use is Indirect for default * FIX divisa rate indirect to direct Direct : 1 Divisa Currency = X Currency Main. Indirect: 1 Currency Main = X Divisa Currency. Then for Dolibarr use is Indirect for default * FIX divisa rate indirect to direct Direct : 1 Divisa Currency = X Currency Main. Indirect: 1 Currency Main = X Divisa Currency. Then for Dolibarr use is Indirect for default * FIX divisa rate indirect to direct Direct : 1 Divisa Currency = X Currency Main. Indirect: 1 Currency Main = X Divisa Currency. Then for Dolibarr use is Indirect for default * Divisa rate direct Direct : 1 Divisa Currency = X Currency Main. Indirect: 1 Currency Main = X Divisa Currency. Then for Dolibarr use is Indirect for default * Add col rate_direct because Dolibarr use for.default rate indirect --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * CI * Add thumbnails for avif (#37045) * vignette for avif * vignette for avif * vignette for avif * vignette for avif * vignette for avif * vignette for avif * vignette for avif * vignette for avif * vignette for avif * vignette for avif * vignette for avif * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * FIX #36892 * NEW : Manage discount for all lines for supplier elements. (#36954) * NEW : Manage remise for all lines for supplier elements. * Cast remise_percent to float in updateline call --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Fix Signature position (#37048) Move up the position of the signature to fix its explosion on 3 pages * remove french doc and fix travis migration missing (#37053) * fix french doc * fix french doc * fix french doc * fix french doc * Clean up comments in card.php Removed unnecessary comments from card.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Debug v23 * Fix CSS * Fix CSS * Fix sql syntax error * Fix sql syntax error * Add optionnal img to openid login (#37060) * fix french doc (#37056) * fix french doc * fix french doc * fix french doc * doc translation * doc translation * doc translation * doc translation * doc translation * load tables in init for create categorie table associated (#37059) * Fix situation invoice * Fix situation invoice * Debug v23 * Link and filter on ountry for holiday types * Link and filter on ountry for holiday types * Trans * Debug v23 * css * CSS on current day * Debug v23 * css * More complete message * Make array of dispute status a shared constant * Debug v23 * Debug v23 * bad link on sql in fichinter list (#37081) * bad link on sql in fichinter list (#37081) * FIX: TakePOS, webapp-hardware-bridge and TakePOS-Connector for modern weighing scales (#37078) * feat: CustomerDisplay through Webapp-Hardware-Bridge * feat: WeighingScale through Webapp-Hardware-Bridge * feat: WeighingScale through Webapp-Hardware-Bridge * fix: looks like a typo * feat: for small screens * fix: attribut contenant le prix du produit ajouté * feat: ajout d'un callback de gestion d'erreur * Clean code for Takepos * Debug v23 * Fix new path of dolreceiptprinter.class.php * Adjust signature appearance position in PDF generation (#37076) * EmailCollector: exclude sender emails/domains (#37075) # Conflicts: # htdocs/langs/en_US/admin.lang Co-authored-by: braito4 <braito4@users.noreply.github.com> * fix: dev/examples/zapier/package.json to reduce vulnerabilities (#37071) The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-LODASH-15053838 Co-authored-by: snyk-bot <snyk-bot@snyk.io> * translate french doc to english (#37064) * fix french doc * fix french doc * fix french doc * fix french doc * fix * fix * fix * fix * Trans * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Change translation function to transnoentities (#37065) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Change translation function to transnoentities (#37065) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * NEW Show total multicurrency on payment (#37070) * Total multicurrency * Total multicurrency paiment * total result multicurrency * show total multicurrency * Fix CI * CLOSE #37085 - Popup notif is just under the menu bar * fix: add missing geturl lib (#37088) * Fix CI * Restrict to modiied files * #36843 Update card-rec.php (#37062) The item desc is already added into the line when selecting the Item. No Need to concat it again when clicking the "add" button. * Clean code * Fix CI * Doc * Fix CI * family assignment logic on user perms of external modules (#36456) * family assignment logic on user perms of external modules Updated family assignment logic to default to 'other' if family does not exist in $familyinfo. * Update copyright year for Charlene Benke * family assignment logic on user perms of external modules (#36456) * family assignment logic on user perms of external modules Updated family assignment logic to default to 'other' if family does not exist in $familyinfo. * Update copyright year for Charlene Benke * Fix comment and keep external modules out of core modules * Close #36975 * Close #36975 * css * NEW : hide remise_except unit price on invoice lines (#37066) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * NEW(API): create fixed amount discount (#37091) * NEW(API): create fixed amount discount * FIX CI * FIX CI --------- Co-authored-by: Benjamin Falière <benjamin.faliere@altairis.fr> * Fix phan * CI * FIX * FIX * NEW - Add in API for thirdparies getRepresentative * FIX * Update api_thirdparties.class.php * Update api_thirdparties.class.php * Enhance return type annotation in API documentation Updated return type documentation for representatives. --------- Co-authored-by: Laurent Destailleur <eldy@users.sourceforge.net> Co-authored-by: Lucas Marcouiller <45882981+Hystepik@users.noreply.github.com> Co-authored-by: Lucas Marcouiller <lmarcouiller@dolicloud.com> Co-authored-by: MDW <mdeweerd@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: Alexandre SPANGARO <alexandre.spangaro@gmail.com> Co-authored-by: Braito <braito4@hotmail.com> Co-authored-by: caminotravelcenter <caminotravelcenter@localhost> Co-authored-by: hansemschnokeloch <hansemschnokeloch@users.noreply.github.com> Co-authored-by: atm-jonathan <146709163+atm-jonathan@users.noreply.github.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Charlène Benke <1179011+defrance@users.noreply.github.com> Co-authored-by: Thatoo <Thatoo@users.noreply.github.com> Co-authored-by: Zakaria Boushaba <48571684+Boushabazakaria@users.noreply.github.com> Co-authored-by: Zakaria Boushaba <z.boushaba@vold.africa> Co-authored-by: Vincent Maury <artec.vm@arnac.net> Co-authored-by: vmaury <vmaury@vmaury-Lafite-Pro-16-AMD> Co-authored-by: Jyhere <jyhere@gmail.com> Co-authored-by: Lenin Rivas <53640168+leninrivas@users.noreply.github.com> Co-authored-by: ThomasNgr-OpenDSI <tnegre@open-dsi.fr> Co-authored-by: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Co-authored-by: LePat <patrick.muscat@gmail.com> Co-authored-by: braito4 <braito4@users.noreply.github.com> Co-authored-by: snyk-bot <snyk-bot@snyk.io> Co-authored-by: Vanyo <vanyolai@gmail.com> Co-authored-by: AWeerWolf <74211972+AWeerWolf@users.noreply.github.com> Co-authored-by: Benjamin Falière <121813548+BenjaminFlr@users.noreply.github.com> Co-authored-by: Benjamin Falière <benjamin.faliere@altairis.fr> Co-authored-by: Anthony Berton <anthony.berton@bb2a.fr>
2026-07-31 21:51:57 +00:00
/**
* Get a customer representative to a third party
*
* @since 24.0.0 Initial implementation
*
* @param int $id ID of the third party
* @return array<array{id:int,lastname:string,firstname:string,email:string,phone:string,office_phone:string,office_fax:string,user_mobile:string,personal_mobile:string,job:string,statut:int,status:int,entity:int,login:string,photo:string,gender:string}> Return array of representatives if OK, < 0 if KO
*
* @url GET {id}/representative
*
* @throws RestException 401 Access not allowed for your login
* @throws RestException 404 User or Third party not found
*/
public function getRepresentative($id)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'reader')) {
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->getSalesRepresentatives(DolibarrApiAccess::$user);
/** @var array<array{id:int,lastname:string,firstname:string,email:string,phone:string,office_phone:string,office_fax:string,user_mobile:string,personal_mobile:string,job:string,statut:int,status:int,entity:int,login:string,photo:string,gender:string}> $result */
return $result;
}
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
/**
* Add a customer representative to a third party
*
* @since 20.0.0 Initial implementation
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
*
* @param int $id ID of the third party
* @param int $representative_id ID of representative
* @return int Return integer <=0 if KO, >0 if OK
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
*
* @url POST {id}/representative/{representative_id}
2024-02-25 09:03:04 +00:00
*
* @throws RestException 401 Access not allowed for your login
* @throws RestException 404 User or Third party not found
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
*/
public function addRepresentative($id, $representative_id)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$usertmp = new User($this->db);
$result = $usertmp->fetch($representative_id);
if (!$result) {
throw new RestException(404, 'User not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
}
$result = $this->company->add_commercial(DolibarrApiAccess::$user, $representative_id);
return $result;
}
/**
* Remove the link between a customer representative and a third party
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
*
* @since 20.0.0 Initial implementation
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
*
* @param int $id ID of the third party
* @param int $representative_id ID of representative
* @return int Return integer <=0 if KO, >0 if OK
*
* @url DELETE {id}/representative/{representative_id}
2024-02-25 09:03:04 +00:00
*
* @throws RestException 401 Access not allowed for your login
* @throws RestException 404 User or Third party not found
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
*/
public function deleteRepresentative($id, $representative_id)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'supprimer')) {
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$usertmp = new User($this->db);
$result = $usertmp->fetch($representative_id);
if (!$result) {
throw new RestException(404, 'User not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
}
$result = $this->company->del_commercial(DolibarrApiAccess::$user, $representative_id);
return $result;
}
/**
* Get customer categories for a third party
*
* @since 5.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit List limit
* @param int $page Page number
* @return array
2025-03-03 13:23:57 +00:00
* @phan-return array<int,array{id:int,fk_parent:int,label:string,description:string,color:string,position:int,socid:int,type:string,entity:int,array_options:array<string,mixed>,visible:int,ref_ext:string,multilangs?:array<string,array{label:string,description:string,note?:string}>}>
* @phpstan-return array<int,array{id:int,fk_parent:int,label:string,description:string,color:string,position:int,socid:int,type:string,entity:int,array_options:array<string,mixed>,visible:int,ref_ext:string,multilangs?:array<string,array{label:string,description:string,note?:string}>}>
*
* @url GET {id}/categories
*
* @throws RestException
*/
public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
2017-10-03 17:09:46 +00:00
}
$result = $this->company->fetch($id);
2021-02-26 20:17:52 +00:00
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
// Check that user has permission on thirdparty ID
if (!DolibarrApi::_checkAccessToResource('societe', $this->company)) {
throw new RestException(404, 'Third party not allowed for login '.DolibarrApiAccess::$user->login);
}
$categories = new Categorie($this->db);
2023-04-30 01:10:20 +00:00
$arrayofcateg = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page);
2023-04-30 01:10:20 +00:00
if (is_numeric($arrayofcateg) && $arrayofcateg < 0) {
throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
}
2023-05-02 01:38:57 +00:00
if (is_numeric($arrayofcateg) && $arrayofcateg >= 0) { // To fix a return of 0 instead of empty array of method getListForItem
return array();
}
2023-04-30 01:10:20 +00:00
return $arrayofcateg;
}
/**
* Add a customer category to a third party
*
* @since 5.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $category_id ID of category
* @return Object
*
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @url PUT {id}/categories/{category_id}
*
* @throws RestException
*/
public function addCategory($id, $category_id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Third party not found');
}
$category = new Categorie($this->db);
$result = $category->fetch($category_id);
if (!$result) {
throw new RestException(404, 'category not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$category->add_type($this->company, 'customer');
return $this->_cleanObjectDatas($this->company);
}
/**
* Remove the link between a customer category and the third party
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $category_id ID of category
*
* @return Object
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @url DELETE {id}/categories/{category_id}
*
* @throws RestException
*/
public function deleteCategory($id, $category_id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$category = new Categorie($this->db);
$result = $category->fetch($category_id);
if (!$result) {
throw new RestException(404, 'category not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$category->del_type($this->company, 'customer');
return $this->_cleanObjectDatas($this->company);
}
/**
* Get supplier categories for a third party
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit List limit
* @param int $page Page number
*
* @return array
2025-03-03 13:23:57 +00:00
* @phan-return array<int,array{id:int,fk_parent:int,label:string,description:string,color:string,position:int,socid:int,type:string,entity:int,array_options:array<string,mixed>,visible:int,ref_ext:string,multilangs?:array<string,array{label:string,description:string,note?:string}>}>
* @phpstan-return array<int,array{id:int,fk_parent:int,label:string,description:string,color:string,position:int,socid:int,type:string,entity:int,array_options:array<string,mixed>,visible:int,ref_ext:string,multilangs?:array<string,array{label:string,description:string,note?:string}>}>
*
* @url GET {id}/supplier_categories
*
* @throws RestException
*/
public function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id);
2021-02-26 20:17:52 +00:00
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
// Check that user has permission on thirdparty ID
if (!DolibarrApi::_checkAccessToResource('societe', $this->company)) {
throw new RestException(404, 'Third party not allowed for login '.DolibarrApiAccess::$user->login);
}
$categories = new Categorie($this->db);
$result = $categories->getListForItem($id, 'supplier', $sortfield, $sortorder, $limit, $page);
2021-02-26 20:17:52 +00:00
if (is_numeric($result) && $result < 0) {
throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
}
2021-02-26 20:17:52 +00:00
if (is_numeric($result) && $result == 0) { // To fix a return of 0 instead of empty array of method getListForItem
return array();
}
return $result;
}
/**
* Add a supplier category to a third party
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $category_id ID of category
* @return mixed
*
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @url PUT {id}/supplier_categories/{category_id}
*
* @throws RestException
*/
public function addSupplierCategory($id, $category_id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$category = new Categorie($this->db);
$result = $category->fetch($category_id);
if (!$result) {
throw new RestException(404, 'category not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$category->add_type($this->company, 'supplier');
return $this->_cleanObjectDatas($this->company);
}
/**
* Remove the link between a category and the third party
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $category_id ID of category
*
* @return mixed
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @url DELETE {id}/supplier_categories/{category_id}
*
* @throws RestException
*/
public function deleteSupplierCategory($id, $category_id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$category = new Categorie($this->db);
$result = $category->fetch($category_id);
if (!$result) {
throw new RestException(404, 'category not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$category->del_type($this->company, 'supplier');
return $this->_cleanObjectDatas($this->company);
}
/**
* Get outstanding proposals for a third party
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
2023-09-26 16:43:25 +00:00
* @param string $mode 'customer' or 'supplier'
*
* @url GET {id}/outstandingproposals
*
* @return array List of outstandings proposals of thirdparty
2025-03-03 13:23:57 +00:00
* @phan-return array{opened?:float}
* @phpstan-return array{opened?:float}
*
2020-02-20 12:42:43 +00:00
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
*/
public function getOutStandingProposals($id, $mode = 'customer')
{
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$result = $this->company->getOutstandingProposals($mode);
unset($result['total_ht']);
unset($result['total_ttc']);
return $result;
}
/**
* Get outstanding orders for a third party
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
2023-09-26 16:43:25 +00:00
* @param string $mode 'customer' or 'supplier'
*
* @url GET {id}/outstandingorders
*
* @return array List of outstandings orders of the third party
2025-03-03 13:23:57 +00:00
* @phan-return array{opened?:float}
* @phpstan-return array{opened?:float}
*
2020-02-20 12:42:43 +00:00
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
*/
public function getOutStandingOrder($id, $mode = 'customer')
{
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$result = $this->company->getOutstandingOrders($mode);
unset($result['total_ht']);
unset($result['total_ttc']);
return $result;
}
/**
* Get outstanding invoices for a third party
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
2023-09-26 16:43:25 +00:00
* @param string $mode 'customer' or 'supplier'
*
* @url GET {id}/outstandinginvoices
*
* @return array List of outstanding invoices of the third party
2025-03-03 13:23:57 +00:00
* @phan-return array{opened?:float}
* @phpstan-return array{opened?:float}
*
2020-02-20 12:42:43 +00:00
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
*/
public function getOutStandingInvoices($id, $mode = 'customer')
{
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$result = $this->company->getOutstandingBills($mode);
unset($result['total_ht']);
unset($result['total_ttc']);
return $result;
}
/**
* Get representatives of a third party
*
* @since 11.0.0 Initial implementation
*
* @param int $id ID of the third party
2023-12-02 21:28:04 +00:00
* @param int $mode 0=Array with properties, 1=Array of id.
*
* @url GET {id}/representatives
*
* @return array List of representatives of the third party
2025-03-03 13:23:57 +00:00
* @phan-return int[]|array<array{id:int,lastname:string,firstname:string,email:string,phone:string,office_phone:string,office_fax:string,user_mobile:string,personal_mobile:string,job:string,statut:int,status:int,entity:int,login:string,photo:string,gender:string}>
* @phpstan-return int[]|array<array{id:int,lastname:string,firstname:string,email:string,phone:string,office_phone:string,office_fax:string,user_mobile:string,personal_mobile:string,job:string,statut:int,status:int,entity:int,login:string,photo:string,gender:string}>
*
2020-02-20 12:42:43 +00:00
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
*/
public function getSalesRepresentatives($id, $mode = 0)
{
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->fetch($id);
if ($result <= 0) {
throw new RestException(404, 'Thirdparty not found');
}
$result = $this->company->getSalesRepresentatives(DolibarrApiAccess::$user, $mode);
return $result;
}
/**
* Get fixed amount discount of a third party
*
* all sources: deposit, credit note, commercial offers, etc.
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of the third party
2025-11-28 14:14:29 +00:00
* @param string $mode 'customer' or 'supplier'
* @param string $filter Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts {@choice none,available,used}
* @param string $sortfield Sort field
* @param string $sortorder Sort order
*
* @url GET {id}/fixedamountdiscounts
*
* @return array List of fixed discount of the third party
2025-03-03 13:23:57 +00:00
* @phan-return stdClass[]
* @phpstan-return stdClass[]
*
2020-02-20 12:42:43 +00:00
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
* @throws RestException 503
*/
2025-11-28 14:25:15 +00:00
public function getFixedAmountDiscounts($id, $mode = 'customer', $filter = "none", $sortfield = "f.type", $sortorder = 'ASC')
{
$obj_ret = array();
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
2025-11-28 14:14:29 +00:00
$sql = '';
if ($mode === 'customer') {
$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";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = re.fk_facture_source";
$sql .= " WHERE re.fk_soc = ".((int) $id);
2025-11-28 14:14:29 +00:00
if ($filter == "available") {
$sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
}
if ($filter == "used") {
$sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
}
2025-11-28 14:40:57 +00:00
} elseif ($mode === 'supplier') {
2025-11-28 14:14:29 +00:00
$sql = "SELECT f.ref, f.type as factype, re.fk_invoice_supplier_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_invoice_supplier, re.fk_invoice_supplier_line";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = re.fk_invoice_supplier_source";
2025-11-28 14:14:29 +00:00
$sql .= " WHERE f.rowid = re.fk_invoice_supplier_source AND re.fk_soc = ".((int) $id);
if ($filter == "available") {
$sql .= " AND re.fk_invoice_supplier IS NULL AND re.fk_invoice_supplier_line IS NULL";
}
if ($filter == "used") {
$sql .= " AND (re.fk_invoice_supplier IS NOT NULL OR re.fk_invoice_supplier_line IS NOT NULL)";
}
2021-02-26 20:17:52 +00:00
}
$sql .= $this->db->order($sortfield, $sortorder);
$result = $this->db->query($sql);
if (!$result) {
throw new RestException(503, $this->db->lasterror());
} else {
2025-09-28 20:20:44 +00:00
//$num = $this->db->num_rows($result);
while ($obj = $this->db->fetch_object($result)) {
$obj_ret[] = $obj;
}
}
return $obj_ret;
}
/**
* Create a fixed amount discount for a thirdparty
*
* @since 24.0.0 Initial implementation
*
* @param int $id ID of thirdparty
* @param array $request_data Request data
* - amount float Amount including tax (required if price_base_type is TTC)
* - description string Description of the discount (required)
* - tva_tx float VAT rate in percentage
* - discount_type int Type of discount: 0 = customer discount, 1 = supplier discount (default: 0)
* - price_base_type string Price base type: 'HT' or 'TTC' (default: 'HT')
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
* @url POST {id}/fixedamountdiscounts
*
* @return int ID of the created discount
*
* @throws RestException 400 Bad request
* @throws RestException 401 Access not allowed for login
* @throws RestException 404 Thirdparty not found
* @throws RestException 500 Error creating discount
*/
public function createFixedAmountDiscount($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
throw new RestException(403);
}
// Check mandatory fields
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!isset($request_data['amount'])) {
throw new RestException(400, 'Missing required field: amount');
}
if (!isset($request_data['description'])) {
throw new RestException(400, 'Missing required field: description');
}
// Check access to resource
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(401, 'Access not allowed for login'.DolibarrApiAccess::$user->login);
}
// Fetch thirdparty to verify it exists
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating discount, thirdparty not found');
}
// Validate amount
if (!is_numeric($request_data['amount']) || $request_data['amount'] <= 0) {
throw new RestException(400, 'Invalid amount_ht: must be a positive number');
}
$amount = (float) $request_data['amount'];
// Validate VAT rate
if (isset($request_data['tva_tx']) && (!is_numeric($request_data['tva_tx']) || $request_data['tva_tx'] < 0)) {
throw new RestException(400, 'Invalid tva_tx: must be a positive number or zero');
}
$tva_tx = isset($request_data['tva_tx']) ? (float) $request_data['tva_tx'] : 0;
// Get price base type (HT or TTC) : HT as default
$price_base_type = 'HT';
if (isset($request_data['price_base_type'])) {
$price_base_type = strtoupper($request_data['price_base_type']);
if ($price_base_type !== 'HT' && $price_base_type !== 'TTC') {
throw new RestException(400, 'Invalid price_base_type: must be "HT" or "TTC"');
}
}
// Get discount type (0 = customer, 1 = supplier): 0 as default
$discount_type = 0;
if (isset($request_data['discount_type'])) {
$discount_type = (int) $request_data['discount_type'];
if ($discount_type !== 0 && $discount_type !== 1) {
throw new RestException(400, 'Invalid discount_type: must be 0 (customer) or 1 (supplier)');
}
}
// Get description
$description = $request_data['description'];
if (empty(trim($description))) {
throw new RestException(400, 'Description cannot be empty');
}
// Prepare VAT rate with code if provided
$vatrate = "";
if (isset($request_data['vat_src_code']) && !empty($request_data['vat_src_code'])) {
$vatrate = $tva_tx . ' (' . $request_data['vat_src_code'] . ')';
}
// Create the discount using Societe::set_remise_except()
$this->db->begin();
$result = $this->company->set_remise_except($amount, DolibarrApiAccess::$user, $description, $vatrate, $discount_type, $price_base_type);
if ($result > 0) {
$this->db->commit();
return $result;
} else {
$this->db->rollback();
throw new RestException(500, 'Error creating discount: '.$this->company->error, array_merge(array($this->company->error), $this->company->errors));
}
}
[NEW] Add function to split a discount in 2 by API REST (#34786) * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 * Revert "Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active :" This reverts commit 80e67e665ad904e631fbe8892671eeb7d614eb2f. * Correction for the generation of the bankjournal for a payment for different third parties party (in case of payment multi third partie is active, ie option "Allow payments on different third parties bills but same parent company" = true). correction for the bug issue https://github.com/Dolibarr/dolibarr/issues/34755 * Revert "Correction for the generation of the bankjournal for a payment for different third parties party (in case of payment multi third partie is active, ie option "Allow payments on different third parties bills but same parent company" = true)." This reverts commit 12ccfa60fa25b2ab2c0885a95478c703898566ba. * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 (Sorry for the 2 failed pull request: I'm begginer in use of git) * Revert "Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active :" This reverts commit 6fb35a6d2e1d0b0622423460f6b39111ebb1a606. * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 (Sorry for the 2 failed pull request: I'm begginer in use of git) * correction commit for phan * Correction for Travis CI * I forgot to correct a line * Correction for phpcs * ajout d'un test si la requete sql de recherche d'un total pour la ligne échoue * activation of this fix only if option FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS is on * spelling correction in comment that don't pass pre-commit check * trailing whitespace forget * Add function to split a discount in 2 by API REST * correction for phan & php-stan * correction for phan & php-stan * correction for phan & php-stan * Update api_thirdparties.class.php * Update api_thirdparties.class.php * Update api_thirdparties.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-08-06 21:11:10 +00:00
/**
* Split a discount in 2 smaller discount
*
* @param int $id ID of the thirdparty
* @param int $discountid ID of a discount coming from a credit note
* @param float $amount_ttc_1 Amount 1 (inc. tax)
* @param float $amount_ttc_2 Amount 2 (inc. tax)
*
*
* @url POST {id}/splitdiscount/{discountid}
*
* @return array List of fixed discount of the third party
* @phan-return stdClass[]
* @phpstan-return stdClass[]
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 403
* @throws RestException 404
* @throws RestException 405
* @throws RestException 409
* @throws RestException 500
*/
public function splitdiscount($id, $discountid, $amount_ttc_1, $amount_ttc_2)
{
$obj_ret = array();
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer') || !DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (empty($discountid)) {
throw new RestException(400, 'Discount ID is mandatory');
}
if (empty($amount_ttc_1) || empty($amount_ttc_2)) {
throw new RestException(400, 'Amount are mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$result = $this->company->fetch($id);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
$discount = new DiscountAbsolute($this->db);
$res = $discount->fetch($discountid);
if (!($res > 0)) {
throw new RestException(404, 'Discount not found');
}
if ($discount->socid != $id) {
throw new RestException(405, 'Discount not owned by this thirdpartie');
}
if (price2num((float) $amount_ttc_1 + (float) $amount_ttc_2) != $discount->amount_ttc) {
[NEW] Add function to split a discount in 2 by API REST (#34786) * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 * Revert "Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active :" This reverts commit 80e67e665ad904e631fbe8892671eeb7d614eb2f. * Correction for the generation of the bankjournal for a payment for different third parties party (in case of payment multi third partie is active, ie option "Allow payments on different third parties bills but same parent company" = true). correction for the bug issue https://github.com/Dolibarr/dolibarr/issues/34755 * Revert "Correction for the generation of the bankjournal for a payment for different third parties party (in case of payment multi third partie is active, ie option "Allow payments on different third parties bills but same parent company" = true)." This reverts commit 12ccfa60fa25b2ab2c0885a95478c703898566ba. * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 (Sorry for the 2 failed pull request: I'm begginer in use of git) * Revert "Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active :" This reverts commit 6fb35a6d2e1d0b0622423460f6b39111ebb1a606. * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 (Sorry for the 2 failed pull request: I'm begginer in use of git) * correction commit for phan * Correction for Travis CI * I forgot to correct a line * Correction for phpcs * ajout d'un test si la requete sql de recherche d'un total pour la ligne échoue * activation of this fix only if option FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS is on * spelling correction in comment that don't pass pre-commit check * trailing whitespace forget * Add function to split a discount in 2 by API REST * correction for phan & php-stan * correction for phan & php-stan * correction for phan & php-stan * Update api_thirdparties.class.php * Update api_thirdparties.class.php * Update api_thirdparties.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-08-06 21:11:10 +00:00
throw new RestException(405, 'Sum of the 2 discounts is different that the original discount');
}
if ($discount->fk_facture_line) {
throw new RestException(409, 'Discount is already used');
}
$newdiscount1 = new DiscountAbsolute($this->db);
$newdiscount2 = new DiscountAbsolute($this->db);
$newdiscount1->fk_facture_source = $discount->fk_facture_source;
$newdiscount2->fk_facture_source = $discount->fk_facture_source;
$newdiscount1->fk_facture = $discount->fk_facture;
$newdiscount2->fk_facture = $discount->fk_facture;
$newdiscount1->fk_facture_line = $discount->fk_facture_line;
$newdiscount2->fk_facture_line = $discount->fk_facture_line;
$newdiscount1->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
$newdiscount2->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
$newdiscount1->fk_invoice_supplier = $discount->fk_invoice_supplier;
$newdiscount2->fk_invoice_supplier = $discount->fk_invoice_supplier;
$newdiscount1->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
$newdiscount2->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
if ($discount->description == '(CREDIT_NOTE)' || $discount->description == '(DEPOSIT)') {
$newdiscount1->description = $discount->description;
$newdiscount2->description = $discount->description;
} else {
$newdiscount1->description = $discount->description.' (1)';
$newdiscount2->description = $discount->description.' (2)';
}
$newdiscount1->fk_user = $discount->fk_user;
$newdiscount2->fk_user = $discount->fk_user;
$newdiscount1->fk_soc = $discount->fk_soc;
$newdiscount1->socid = $discount->socid;
$newdiscount2->fk_soc = $discount->fk_soc;
$newdiscount2->socid = $discount->socid;
$newdiscount1->discount_type = $discount->discount_type;
$newdiscount2->discount_type = $discount->discount_type;
$newdiscount1->datec = $discount->datec;
$newdiscount2->datec = $discount->datec;
$newdiscount1->tva_tx = $discount->tva_tx;
$newdiscount2->tva_tx = $discount->tva_tx;
$newdiscount1->vat_src_code = $discount->vat_src_code;
$newdiscount2->vat_src_code = $discount->vat_src_code;
$newdiscount1->amount_ttc = $amount_ttc_1;
$newdiscount2->amount_ttc = price2num($discount->amount_ttc - $newdiscount1->amount_ttc);
$newdiscount1->amount_ht = price2num($newdiscount1->amount_ttc / (1 + $newdiscount1->tva_tx / 100), 'MT');
$newdiscount2->amount_ht = price2num($newdiscount2->amount_ttc / (1 + $newdiscount2->tva_tx / 100), 'MT');
$newdiscount1->amount_tva = price2num($newdiscount1->amount_ttc - $newdiscount1->amount_ht);
$newdiscount2->amount_tva = price2num($newdiscount2->amount_ttc - $newdiscount2->amount_ht);
$newdiscount1->multicurrency_amount_ttc = (float) $amount_ttc_1 * ($discount->multicurrency_amount_ttc / $discount->amount_ttc);
$newdiscount2->multicurrency_amount_ttc = price2num($discount->multicurrency_amount_ttc - $newdiscount1->multicurrency_amount_ttc);
$newdiscount1->multicurrency_amount_ht = price2num($newdiscount1->multicurrency_amount_ttc / (1 + $newdiscount1->tva_tx / 100), 'MT');
$newdiscount2->multicurrency_amount_ht = price2num($newdiscount2->multicurrency_amount_ttc / (1 + $newdiscount2->tva_tx / 100), 'MT');
$newdiscount1->multicurrency_amount_tva = price2num($newdiscount1->multicurrency_amount_ttc - $newdiscount1->multicurrency_amount_ht);
$newdiscount2->multicurrency_amount_tva = price2num($newdiscount2->multicurrency_amount_ttc - $newdiscount2->multicurrency_amount_ht);
// DiscountAbsolute->amount_ttc ->amount_ht ->amount_tva are marked as @deprecated but seems to yet be in use so we fill ->amout_xxx and ->total_xxx
// the same for multicurrency_amount_xxx and multicurrency_total_xxx
$newdiscount1->total_ttc = (float) price2num($newdiscount1->amount_ttc);
$newdiscount1->total_ht = (float) price2num($newdiscount1->amount_ht);
$newdiscount1->total_tva = (float) price2num($newdiscount1->amount_tva);
$newdiscount2->total_ttc = (float) price2num($newdiscount2->amount_ttc);
$newdiscount2->total_ht = (float) price2num($newdiscount2->amount_ht);
$newdiscount2->total_tva = (float) price2num($newdiscount2->amount_tva);
$newdiscount1->multicurrency_total_ttc = (float) price2num($newdiscount1->multicurrency_amount_ttc);
$newdiscount1->multicurrency_total_ht = (float) price2num($newdiscount1->multicurrency_amount_ht);
$newdiscount1->multicurrency_total_tva = (float) price2num($newdiscount1->multicurrency_amount_tva);
$newdiscount2->multicurrency_total_ttc = (float) price2num($newdiscount2->multicurrency_amount_ttc);
$newdiscount2->multicurrency_total_ht = (float) price2num($newdiscount2->multicurrency_amount_ht);
$newdiscount2->multicurrency_total_tva = (float) price2num($newdiscount2->multicurrency_amount_tva);
$this->db->begin();
$discount->fk_facture_source = 0; // This is to delete only the require record (that we will recreate with two records) and not all family with same fk_facture_source
// This is to delete only the require record (that we will recreate with two records) and not all family with same fk_invoice_supplier_source
$discount->fk_invoice_supplier_source = 0;
$res = $discount->delete(DolibarrApiAccess::$user);
$newid1 = $newdiscount1->create(DolibarrApiAccess::$user);
$newid2 = $newdiscount2->create(DolibarrApiAccess::$user);
if ($res <= 0 || $newid1 <= 0 || $newid2 <= 0) {
$this->db->rollback();
throw new RestException(500, 'Operation fail');
}
$this->db->commit();
$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";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE re.rowid IN (".((int) $newid1).",".((int) $newid2).") AND f.rowid = re.fk_facture_source AND re.fk_soc = ".((int) $id);
[NEW] Add function to split a discount in 2 by API REST (#34786) * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 * Revert "Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active :" This reverts commit 80e67e665ad904e631fbe8892671eeb7d614eb2f. * Correction for the generation of the bankjournal for a payment for different third parties party (in case of payment multi third partie is active, ie option "Allow payments on different third parties bills but same parent company" = true). correction for the bug issue https://github.com/Dolibarr/dolibarr/issues/34755 * Revert "Correction for the generation of the bankjournal for a payment for different third parties party (in case of payment multi third partie is active, ie option "Allow payments on different third parties bills but same parent company" = true)." This reverts commit 12ccfa60fa25b2ab2c0885a95478c703898566ba. * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 (Sorry for the 2 failed pull request: I'm begginer in use of git) * Revert "Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active :" This reverts commit 6fb35a6d2e1d0b0622423460f6b39111ebb1a606. * Correction for the generation of the bankjournal for a paiement for different third parties party (in case of paiement multi third partie is active : option "Allow payments on different third parties bills but same parent company" = true) I've made a bug issu about it : https://github.com/Dolibarr/dolibarr/issues/34755 (Sorry for the 2 failed pull request: I'm begginer in use of git) * correction commit for phan * Correction for Travis CI * I forgot to correct a line * Correction for phpcs * ajout d'un test si la requete sql de recherche d'un total pour la ligne échoue * activation of this fix only if option FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS is on * spelling correction in comment that don't pass pre-commit check * trailing whitespace forget * Add function to split a discount in 2 by API REST * correction for phan & php-stan * correction for phan & php-stan * correction for phan & php-stan * Update api_thirdparties.class.php * Update api_thirdparties.class.php * Update api_thirdparties.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-08-06 21:11:10 +00:00
$sql .= $this->db->order("f.type", "ASC");
$result = $this->db->query($sql);
if (!$result) {
throw new RestException(503, $this->db->lasterror());
} else {
// $num = $this->db->num_rows($result);
while ($obj = $this->db->fetch_object($result)) {
$obj_ret[] = $obj;
}
}
return $obj_ret;
}
/**
* Return invoices qualified to be replaced by another invoice
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of a third party
*
* @url GET {id}/getinvoicesqualifiedforreplacement
*
* @return array
2025-03-03 13:23:57 +00:00
* @phan-return array<int,array{id:int,ref:string,status:int,paid:int,alreadypaid:int}>|int
* @phpstan-return array<int,array{id:int,ref:string,status:int,paid:int,alreadypaid:int}>|int
2020-02-20 12:42:43 +00:00
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
* @throws RestException 405
*/
public function getInvoicesQualifiedForReplacement($id)
{
2023-06-19 21:18:13 +00:00
if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
/*$result = $this->thirdparty->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Thirdparty not found');
}*/
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$invoice = new Facture($this->db);
$result = $invoice->list_replacable_invoices($id);
if ($result < 0) {
throw new RestException(405, $invoice->error);
}
return $result;
}
/**
* Return 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 partially) + not already replaced + not already a credit note
*
* @since 7.0.0 Initial implementation
*
* @param int $id ID of a third party
*
* @url GET {id}/getinvoicesqualifiedforcreditnote
*
* @return array
2025-03-03 13:23:57 +00:00
* @phan-return array<int,array{ref:string,status:int,type:int,paye:int,paymentornot:int}>|int
* @phpstan-return array<int,array{ref:string,status:int,type:int,paye:int,paymentornot:int}>|int
2020-02-20 12:42:43 +00:00
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
* @throws RestException 405
*/
public function getInvoicesQualifiedForCreditNote($id)
{
2023-06-19 21:18:13 +00:00
if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
/*$result = $this->thirdparty->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Thirdparty not found');
}*/
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$invoice = new Facture($this->db);
$result = $invoice->list_qualified_avoir_invoices($id);
2025-03-03 13:23:57 +00:00
if (!is_array($result) && $result < 0) {
throw new RestException(405, $invoice->error);
}
return $result;
}
2018-08-26 16:15:14 +00:00
/**
* Get company notifications for a third party
*
* @since 20.0.0 Initial implementation
*
* @param int $id ID of the third party
*
* @return array
2025-03-03 13:23:57 +00:00
* @phan-return array<array{id:int,socid:int,event:string,contact_id:int,datec:int,tms:string,type:string}>
* @phpstan-return array<array{id:int,socid:int,event:string,contact_id:int,datec:int,tms:string,type:string}>
*
* @url GET {id}/notifications
*
* @throws RestException
*/
public function getCompanyNotification($id)
{
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
2024-03-19 14:55:23 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
throw new RestException(403);
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
2024-03-19 14:55:23 +00:00
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
/**
* We select all the records that match the socid
*/
$sql = "SELECT rowid as id, fk_action as event, fk_soc as socid, fk_contact as contact_id, type, datec, tms";
$sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
if ($id) {
$sql .= " WHERE fk_soc = ".((int) $id);
}
$result = $this->db->query($sql);
if ($this->db->num_rows($result) == 0) {
throw new RestException(404, 'Notification not found');
}
$i = 0;
2024-03-13 22:31:27 +00:00
$notifications = array();
if ($result) {
2025-09-28 20:20:44 +00:00
$i = 0;
$num = $this->db->num_rows($result);
2025-09-28 20:20:44 +00:00
//$min = min($num, ($limit <= 0 ? $num : $limit));
$min = $num;
while ($i < $min) {
$obj = $this->db->fetch_object($result);
2024-03-13 21:13:57 +00:00
$notifications[] = $obj;
$i++;
}
} else {
2024-03-11 22:24:26 +00:00
throw new RestException(404, 'No notifications found');
}
$fields = array('id', 'socid', 'event', 'contact_id', 'datec', 'tms', 'type');
2024-03-11 22:24:26 +00:00
$returnNotifications = array();
foreach ($notifications as $notification) {
$object = array();
foreach ($notification as $key => $value) {
if (in_array($key, $fields)) {
$object[$key] = $value;
}
}
2024-03-11 22:24:26 +00:00
$returnNotifications[] = $object;
}
2025-03-03 13:23:57 +00:00
// Too complex for phan ?: @phan-suppress-next-line PhanTypeMismatchReturn
2024-03-11 22:24:26 +00:00
return $returnNotifications;
}
2024-03-16 08:46:32 +00:00
/**
* Create a company notification for a third party
*
* @since 20.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
2024-03-16 08:46:32 +00:00
*
* @return array|mixed Notification of the third party
*
* @url POST {id}/notifications
2024-03-16 08:46:32 +00:00
*
* @throws RestException
2024-03-16 08:46:32 +00:00
*/
public function createCompanyNotification($id, $request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
throw new RestException(403, "User has no right to update thirdparties");
}
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Thirdparty Notification, Thirdparty doesn\'t exists');
}
$notification = new Notify($this->db);
$notification->socid = $id;
foreach ($request_data as $field => $value) {
$notification->$field = $this->_checkValForAPI($field, $value, $notification);
2024-03-16 08:46:32 +00:00
}
$event = $notification->event;
if (!$event) {
throw new RestException(500, 'Error creating Thirdparty Notification, request_data missing event');
}
$socid = $notification->socid;
$contact_id = $notification->contact_id;
$exists_sql = "SELECT rowid, fk_action as event, fk_soc as socid, fk_contact as contact_id, type, datec, tms as datem";
$exists_sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
2025-03-03 13:23:57 +00:00
$exists_sql .= " WHERE fk_action = '".$this->db->escape((string) $event)."'";
$exists_sql .= " AND fk_soc = '".$this->db->escape((string) $socid)."'";
$exists_sql .= " AND fk_contact = '".$this->db->escape((string) $contact_id)."'";
$exists_result = $this->db->query($exists_sql);
if ($this->db->num_rows($exists_result) > 0) {
throw new RestException(403, 'Notification already exists');
}
2024-03-16 08:46:32 +00:00
if ($notification->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating Thirdparty Notification');
}
if ($notification->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating values');
}
return $this->_cleanObjectDatas($notification);
}
/**
* Create a company notification for a third party using action trigger code
*
* @since 21.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param string $code Action Trigger code
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
* @return array|mixed Notification for the third party
* @phan-return Notify
*
* @url POST {id}/notificationsbycode/{code}
*
* @throws RestException
*/
public function createCompanyNotificationByCode($id, $code, $request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
throw new RestException(403, "User has no right to update thirdparties");
}
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Thirdparty Notification, Thirdparty doesn\'t exists');
}
$notification = new Notify($this->db);
$notification->socid = $id;
$sql = "SELECT t.rowid as id FROM ".MAIN_DB_PREFIX."c_action_trigger as t";
$sql .= " WHERE t.code = '".$this->db->escape($code)."'";
$result = $this->db->query($sql);
if ($this->db->num_rows($result) == 0) {
throw new RestException(404, 'Action Trigger code not found');
}
$notification->event = $this->db->fetch_row($result)[0];
foreach ($request_data as $field => $value) {
if ($field === 'event') {
throw new RestException(500, 'Error creating Thirdparty Notification, request_data contains event key');
}
if ($field === 'fk_action') {
throw new RestException(500, 'Error creating Thirdparty Notification, request_data contains fk_action key');
}
$notification->$field = $this->_checkValForAPI($field, $value, $notification);
}
$event = $notification->event;
$socid = $notification->socid;
$contact_id = $notification->contact_id;
$exists_sql = "SELECT rowid, fk_action as event, fk_soc as socid, fk_contact as contact_id, type, datec, tms as datem";
$exists_sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
2025-03-03 13:23:57 +00:00
$exists_sql .= " WHERE fk_action = '".$this->db->escape((string) $event)."'";
$exists_sql .= " AND fk_soc = '".$this->db->escape((string) $socid)."'";
$exists_sql .= " AND fk_contact = '".$this->db->escape((string) $contact_id)."'";
$exists_result = $this->db->query($exists_sql);
if ($this->db->num_rows($exists_result) > 0) {
throw new RestException(403, 'Notification already exists');
}
if ($notification->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating Thirdparty Notification, are request_data well formed?');
}
2024-03-16 08:46:32 +00:00
if ($notification->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating values');
}
return $this->_cleanObjectDatas($notification);
}
/**
* Delete a company notification attached to a third party
*
* @since 20.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $notification_id ID of CompanyNotification
*
* @return int -1 if error, 1 if correct deletion
*
* @url DELETE {id}/notifications/{notification_id}
*
* @throws RestException
*/
public function deleteCompanyNotification($id, $notification_id)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
throw new RestException(403);
}
2024-03-13 22:14:49 +00:00
$notification = new Notify($this->db);
$notification->fetch($notification_id);
$socid = (int) $notification->socid;
if ($socid == $id) {
return $notification->delete(DolibarrApiAccess::$user);
} else {
throw new RestException(403, "Not allowed due to bad consistency of input data");
}
}
2024-03-15 22:50:01 +00:00
/**
* Update a company notification for a third party
2024-03-15 22:50:01 +00:00
*
* @since 20.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $notification_id ID of CompanyNotification
* @param array $request_data Request data
* @return array|mixed Notification for the third party
*
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
2024-03-15 22:50:01 +00:00
*
* @url PUT {id}/notifications/{notification_id}
2024-03-15 22:50:01 +00:00
*
* @throws RestException
2024-03-15 22:50:01 +00:00
*/
public function updateCompanyNotification($id, $notification_id, $request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
throw new RestException(403, "User has no right to update thirdparties");
}
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Company Notification, Company doesn\'t exists');
}
$notification = new Notify($this->db);
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$notification->fetch($notification_id, $id);
2024-03-15 22:50:01 +00:00
if ($notification->socid != $id) {
throw new RestException(403, "Not allowed due to bad consistency of input data");
}
foreach ($request_data as $field => $value) {
$notification->$field = $this->_checkValForAPI($field, $value, $notification);
2024-03-15 22:50:01 +00:00
}
if ($notification->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating values');
}
return $this->_cleanObjectDatas($notification);
}
/**
* Get company bank accounts of a third party
2018-06-29 23:34:51 +00:00
*
* @since 9.0.0 Initial implementation
2018-06-29 23:34:51 +00:00
*
* @param int $id ID of the third party
*
* @return array
2025-03-03 13:23:57 +00:00
* @phan-return array<array{socid?:int,default_rib?:string,frstrecur?:string,1000110000001?:string,datec:string,datem:string,label:string,bank:string,bic:string,iban:string,id:int,rum:string}>
* @phpstan-return array<array{socid?:int,default_rib?:string,frstrecur?:string,1000110000001?:string,datec:string,datem:string,label:string,bank:string,bic:string,iban:string,id:int,rum:string}>
*
* @url GET {id}/bankaccounts
*
* @throws RestException
*/
public function getCompanyBankAccount($id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (empty($id)) {
throw new RestException(400, 'Thirdparty ID is mandatory');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
/**
2018-06-27 09:01:20 +00:00
* We select all the records that match the socid
*/
$sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation as address, proprio,";
$sql .= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
2021-02-26 20:17:52 +00:00
if ($id) {
$sql .= " WHERE fk_soc = ".((int) $id);
2021-02-26 20:17:52 +00:00
}
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
if ($this->db->num_rows($result) == 0) {
throw new RestException(404, 'Account not found');
2018-06-29 23:34:51 +00:00
}
$i = 0;
2019-07-13 22:31:28 +00:00
$accounts = array();
2021-02-26 20:17:52 +00:00
if ($result) {
2025-09-28 20:20:44 +00:00
$i = 0;
2020-09-19 21:30:29 +00:00
$num = $this->db->num_rows($result);
2025-09-28 20:20:44 +00:00
//$min = min($num, ($limit <= 0 ? $num : $limit));
$min = $num;
while ($i < $min) {
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
2024-11-25 02:11:31 +00:00
2020-09-19 21:30:29 +00:00
$account = new CompanyBankAccount($this->db);
if ($account->fetch($obj->rowid)) {
$accounts[] = $account;
}
$i++;
}
2020-05-21 13:05:19 +00:00
} else {
throw new RestException(404, 'Account not found');
}
2018-06-29 23:34:51 +00:00
2019-07-13 22:31:28 +00:00
$fields = array('socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id', 'rum');
2019-07-13 22:31:28 +00:00
$returnAccounts = array();
2019-10-27 16:01:23 +00:00
foreach ($accounts as $account) {
$object = array();
foreach ($account as $key => $value) {
if (in_array($key, $fields)) {
2024-10-24 11:03:52 +00:00
if ($key == 'iban') {
$object[$key] = dolDecrypt($value);
} else {
$object[$key] = $value;
}
}
2019-10-27 16:01:23 +00:00
}
$returnAccounts[] = $object;
2018-06-29 23:34:51 +00:00
}
return $returnAccounts;
}
/**
* Create a company bank account for a third party
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
2018-06-29 23:34:51 +00:00
*
* @return array|mixed BankAccount of the third party
2018-06-29 23:34:51 +00:00
*
* @url POST {id}/bankaccounts
*
* @throws RestException
*/
public function createCompanyBankAccount($id, $request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
2020-04-13 07:15:01 +00:00
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Company Bank account, Company doesn\'t exists');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$account = new CompanyBankAccount($this->db);
$account->socid = $id;
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$this->company->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$account->$field = $this->_checkValForAPI('extrafields', $value, $account);
}
2021-02-26 20:17:52 +00:00
if ($account->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating Company Bank account');
2021-02-26 20:17:52 +00:00
}
2020-04-13 07:15:01 +00:00
if (empty($account->rum)) {
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
$prelevement = new BonPrelevement($this->db);
2026-01-20 16:39:40 +00:00
$account->rum = $prelevement->buildRumNumber((string) $this->company->code_client, $account->datec, (string) $account->id);
2020-04-13 07:15:01 +00:00
$account->date_rum = dol_now();
}
2021-02-26 20:17:52 +00:00
if ($account->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating values');
2021-02-26 20:17:52 +00:00
}
2018-06-29 23:34:51 +00:00
2020-04-13 07:25:06 +00:00
return $this->_cleanObjectDatas($account);
}
/**
* Update a company bank account of a third party
2018-06-29 23:34:51 +00:00
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $bankaccount_id ID of CompanyBankAccount
* @param array $request_data Request data
* @return array|mixed BankAccount of the third party
*
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
2018-06-29 23:34:51 +00:00
*
* @url PUT {id}/bankaccounts/{bankaccount_id}
2018-06-29 23:34:51 +00:00
*
* @throws RestException
*/
public function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
2020-04-13 07:15:01 +00:00
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Error creating Company Bank account, Company doesn\'t exists');
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$account = new CompanyBankAccount($this->db);
Qual: Ignore false positive for suspicious param positions (#28693) * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored * Qual: Ignore suspicious param positions # Qual: Ignore suspicious param positions Add annotations to ignore false positives about suspicious parameter positions. The cases that require more analysis or may be actual bad parameters positions are not ignored
2024-03-07 19:16:48 +00:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$account->fetch($bankaccount_id, '', $id, -1, '');
if ($account->socid != $id) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
2018-06-29 23:34:51 +00:00
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$account->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$account->$field = $this->_checkValForAPI($field, $value, $account);
}
2020-04-13 07:39:31 +00:00
if (empty($account->rum)) {
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
$prelevement = new BonPrelevement($this->db);
2026-01-20 16:39:40 +00:00
$account->rum = $prelevement->buildRumNumber((string) $this->company->code_client, $account->datec, (string) $account->id);
2020-04-13 07:39:31 +00:00
$account->date_rum = dol_now();
}
2021-02-26 20:17:52 +00:00
if ($account->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating values');
2021-02-26 20:17:52 +00:00
}
2018-06-29 23:34:51 +00:00
2020-04-13 07:25:06 +00:00
return $this->_cleanObjectDatas($account);
}
/**
* Delete a bank account attached to a third party
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param int $bankaccount_id ID of CompanyBankAccount
*
* @return int -1 if error, 1 if correct deletion
2018-06-29 23:34:51 +00:00
*
* @url DELETE {id}/bankaccounts/{bankaccount_id}
2018-06-29 23:34:51 +00:00
*
* @throws RestException
*/
public function deleteCompanyBankAccount($id, $bankaccount_id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$account = new CompanyBankAccount($this->db);
$account->fetch($bankaccount_id);
$socid = (int) $account->socid;
2024-03-15 19:07:56 +00:00
if ($socid == $id) {
return $account->delete(DolibarrApiAccess::$user);
} else {
2024-03-15 21:30:55 +00:00
throw new RestException(403, "Not allowed due to bad consistency of input data");
}
}
/**
* Generate a document from a bank account record
*
* Like SEPA mandate
*
* @since 9.0.0 Initial implementation
2018-09-19 16:33:11 +00:00
*
* @param int $id ID of the third party
* @param int $companybankid ID of company bank
* @param string $model Model of document to generate
* @return array
2025-03-03 13:23:57 +00:00
* @phan-return array{success:int<0,1>}
* @phpstan-return array{success:int<0,1>}
2018-09-19 16:33:11 +00:00
*
* @url GET {id}/generateBankAccountDocument/{companybankid}/{model}
*
* @throws RestException
*/
2018-09-19 12:47:11 +00:00
public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate')
{
2020-11-24 23:16:36 +00:00
global $conf, $langs;
2018-09-20 15:09:31 +00:00
2020-11-24 23:16:36 +00:00
$langs->loadLangs(array("main", "dict", "commercial", "products", "companies", "banks", "bills", "withdrawals"));
2020-11-24 23:16:36 +00:00
if ($this->company->fetch($id) <= 0) {
throw new RestException(404, 'Thirdparty not found');
}
2018-09-20 15:09:31 +00:00
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
2020-11-24 23:16:36 +00:00
}
2018-09-20 15:09:31 +00:00
$this->company->setDocModel(DolibarrApiAccess::$user, $model);
$this->company->fk_bank = $this->company->fk_account;
// $this->company->fk_account = $this->company->fk_account;
2018-09-20 15:09:31 +00:00
2020-11-24 23:16:36 +00:00
$outputlangs = $langs;
$newlang = '';
2018-09-20 15:09:31 +00:00
2022-09-24 12:56:50 +00:00
//if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
2020-11-24 23:16:36 +00:00
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 (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
2018-09-20 15:09:31 +00:00
$sql = "SELECT rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
2021-02-26 20:17:52 +00:00
if ($id) {
2021-03-22 12:31:06 +00:00
$sql .= " WHERE fk_soc = ".((int) $id);
2021-02-26 20:17:52 +00:00
}
if ($companybankid) {
2021-03-22 12:31:06 +00:00
$sql .= " AND rowid = ".((int) $companybankid);
2021-02-26 20:17:52 +00:00
}
2018-09-19 16:33:11 +00:00
$i = 0;
$accounts = array();
2018-09-20 15:09:31 +00:00
$result = $this->db->query($sql);
2020-11-24 23:16:36 +00:00
if ($result) {
if ($this->db->num_rows($result) == 0) {
2018-09-20 15:09:31 +00:00
throw new RestException(404, 'Bank account not found');
}
$num = $this->db->num_rows($result);
2025-09-28 20:20:44 +00:00
//$min = min($num, ($limit <= 0 ? $num : $limit));
$min = $num;
while ($i < $min) {
$obj = $this->db->fetch_object($result);
2018-09-20 15:09:31 +00:00
$account = new CompanyBankAccount($this->db);
2018-09-20 15:09:31 +00:00
if ($account->fetch($obj->rowid)) {
$accounts[] = $account;
}
$i++;
}
2020-05-21 13:05:19 +00:00
} else {
2020-11-24 23:16:36 +00:00
throw new RestException(500, 'Sql error '.$this->db->lasterror());
}
$moreparams = array(
2020-11-24 23:16:36 +00:00
'use_companybankid' => $accounts[0]->id,
'force_dir_output' => $conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName((string) $this->company->id)
);
2018-09-20 15:09:31 +00:00
2020-11-24 23:16:36 +00:00
$result = $this->company->generateDocument($model, $outputlangs, 0, 0, 0, $moreparams);
2018-09-20 15:09:31 +00:00
2020-11-24 23:16:36 +00:00
if ($result > 0) {
return array("success" => $result);
2020-05-21 13:05:19 +00:00
} else {
throw new RestException(500, 'Error generating the document '.$this->company->error);
}
}
/**
* Get a specific account attached to a third party
*
* Specify the site key
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param string $site Site key
*
* @return array|mixed
*
2020-02-20 12:42:43 +00:00
* @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}/accounts/
*/
public function getSocieteAccounts($id, $site = null)
{
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
/**
* We select all the records that match the socid
*/
$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
2021-03-22 12:31:06 +00:00
$sql .= " WHERE fk_soc = ".((int) $id);
2021-02-26 20:17:52 +00:00
if ($site) {
2021-03-22 12:41:43 +00:00
$sql .= " AND site ='".$this->db->escape($site)."'";
2021-02-26 20:17:52 +00:00
}
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2020-10-31 10:57:35 +00:00
if ($result && $this->db->num_rows($result) == 0) {
throw new RestException(404, 'This thirdparty does not have any account attached or does not exist.');
}
$i = 0;
2019-07-13 22:31:28 +00:00
$accounts = array();
2025-09-28 20:20:44 +00:00
$i = 0;
2020-09-19 21:30:29 +00:00
$num = $this->db->num_rows($result);
2025-09-28 20:20:44 +00:00
//$min = min($num, ($limit <= 0 ? $num : $limit));
$min = $num;
while ($i < $min) {
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
$account = new SocieteAccount($this->db);
if ($account->fetch($obj->rowid)) {
$accounts[] = $account;
}
$i++;
}
2019-07-13 22:31:28 +00:00
$fields = array('id', 'fk_soc', 'key_account', 'site', 'date_creation', 'tms');
2019-07-13 22:31:28 +00:00
$returnAccounts = array();
2019-10-27 16:01:23 +00:00
foreach ($accounts as $account) {
$object = array();
foreach ($account as $key => $value) {
if (in_array($key, $fields)) {
$object[$key] = $value;
}
2019-10-27 16:01:23 +00:00
}
$returnAccounts[] = $object;
}
return $returnAccounts;
}
/**
* Get a specific third party by account
*
* @since 21.0.0 Initial implementation
*
* @param string $site Site key
* @param string $key_account Key of the account
*
* @return array|mixed
*
* @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 /accounts/{site}/{key_account}
*
* @throws RestException
*/
public function getSocieteByAccounts($site, $key_account)
{
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
throw new RestException(403);
}
$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
$sql .= " WHERE site = '".$this->db->escape($site)."' AND key_account = '".$this->db->escape($key_account)."'";
$sql .= " AND entity IN (".getEntity('societe').")";
$result = $this->db->query($sql);
if ($result && $this->db->num_rows($result) == 1) {
$obj = $this->db->fetch_object($result);
$returnThirdparty = $this->_fetch($obj->fk_soc);
} else {
throw new RestException(404, 'This account have many thirdparties attached or does not exist.');
}
if (!DolibarrApi::_checkAccessToResource('societe', $returnThirdparty->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
return $returnThirdparty;
}
/**
* Create and attach a new account to an existing third party
*
* Possible fields for request_data (request body) are specified in <code>llx_societe_account</code> table.<br>
* See <a href="https://wiki.dolibarr.org/index.php/Table_llx_societe_account">Table llx_societe_account</a> wiki page for more information<br><br>
* <u>Example body payload :</u> <pre>{"key_account": "cus_DAVkLSs1LYyYI", "site": "stripe"}</pre>
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
* @return array|mixed
2020-02-20 12:54:41 +00:00
*
2020-02-20 12:42:43 +00:00
* @throws RestException 401 Unauthorized: User does not have permission to read thirdparties
* @throws RestException 409 Conflict: An Account already exists for this company and site.
2020-02-20 12:42:43 +00:00
* @throws RestException 422 Unprocessable Entity: You must pass the site attribute in your request data !
* @throws RestException 500 Internal Server Error: Error creating SocieteAccount account
*
* @url POST {id}/accounts
*/
public function createSocieteAccount($id, $request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (!isset($request_data['site'])) {
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 = ".((int) $id)." AND site = '".$this->db->escape($request_data['site'])."'";
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2020-10-31 10:57:35 +00:00
if ($result && $this->db->num_rows($result) == 0) {
$account = new SocieteAccount($this->db);
if (!isset($request_data['login'])) {
$account->login = "";
}
$account->fk_soc = $id;
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$account->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$account->$field = $this->_checkValForAPI($field, $value, $account);
}
2021-02-26 20:17:52 +00:00
if ($account->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!');
2021-02-26 20:17:52 +00:00
}
$this->_cleanObjectDatas($account);
return $account;
} else {
throw new RestException(409, 'A SocieteAccount entity already exists for this company and site.');
}
}
/**
* Create and attach a new (or replace an existing) specific site account for a third party
*
* You <strong>MUST</strong> pass all values to keep (otherwise, they will be deleted) !<br>
* If you just need to update specific fields prefer <code>PUT /thirdparties/{id}/accounts/{site}</code> endpoint.<br><br>
* When a <strong>SocieteAccount</strong> entity does not exist for the <code>id</code> and <code>site</code>
* supplied, a new one will be created. In that case <code>fk_soc</code> and <code>site</code> members form
* request body payload will be ignored and <code>id</code> and <code>site</code> query strings parameters
* will be used instead.
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param string $site Site key
* @param array $request_data Request data
* @return array|mixed
*
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
2020-02-20 12:42:43 +00:00
* @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 !
* @throws RestException 500 Internal Server Error: Error updating SocieteAccount entity
*
* @url POST {id}/accounts/{site}
*/
public function postSocieteAccount($id, $site, $request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($site)."'";
2020-09-19 21:30:29 +00:00
$result = $this->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($result) == 0) {
if (!isset($request_data['key_account'])) {
throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !');
}
$account = new SocieteAccount($this->db);
if (!isset($request_data['login'])) {
$account->login = "";
}
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$account->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$account->$field = $this->_checkValForAPI($field, $value, $account);
}
$account->fk_soc = $id;
$account->site = $site;
2019-10-27 16:01:23 +00:00
if ($account->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating SocieteAccount entity.');
2019-10-27 16:01:23 +00:00
}
// We found an existing SocieteAccount entity, we are replacing it
} else {
2019-10-27 16:01:23 +00:00
if (isset($request_data['site']) && $request_data['site'] !== $site) {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($request_data['site'])."' ";
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2020-10-31 10:57:35 +00:00
if ($result && $this->db->num_rows($result) !== 0) {
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.");
2019-10-27 16:01:23 +00:00
}
}
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
$account = new SocieteAccount($this->db);
$account->id = $obj->rowid;
$account->fk_soc = $id;
$account->site = $site;
if (!isset($request_data['login'])) {
$account->login = "";
}
$account->fk_user_creat = $obj->fk_user_creat;
$account->date_creation = $obj->date_creation;
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$account->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$account->$field = $this->_checkValForAPI($field, $value, $account);
}
2021-02-26 20:17:52 +00:00
if ($account->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating SocieteAccount entity.');
2021-02-26 20:17:52 +00:00
}
}
$this->_cleanObjectDatas($account);
return $account;
}
/**
* Update specified values of a specific account attached to a third party
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param string $site Site key
* @param array $request_data Request data
* @return array|mixed
*
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
2020-02-20 12:42:43 +00:00
* @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
* @throws RestException 409 Conflict: Another SocieteAccount entity already exists for this thirdparty with this site key.
* @throws RestException 500 Internal Server Error: Error updating SocieteAccount entity
*
* @url PUT {id}/accounts/{site}
*/
public function putSocieteAccount($id, $site, $request_data = null)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
2021-04-30 08:57:21 +00:00
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($site)."'";
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2020-10-31 10:57:35 +00:00
if ($result && $this->db->num_rows($result) == 0) {
throw new RestException(404, "This thirdparty does not have $site account 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 = ".((int) $id)." AND site = '".$this->db->escape($request_data['site'])."' ";
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2021-02-26 20:17:52 +00:00
if ($result && $this->db->num_rows($result) !== 0) {
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.");
2021-02-26 20:17:52 +00:00
}
}
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
$account = new SocieteAccount($this->db);
$account->fetch($obj->rowid);
foreach ($request_data as $field => $value) {
if ($field === 'caller') {
// Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
$account->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
continue;
}
$account->$field = $this->_checkValForAPI($field, $value, $account);
}
2021-02-26 20:17:52 +00:00
if ($account->update(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error updating SocieteAccount account');
2021-02-26 20:17:52 +00:00
}
$this->_cleanObjectDatas($account);
return $account;
}
}
/**
* Delete a specific site account attached to a third party
*
* by account id
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
* @param string $site Site key
*
* @return void
*
* @throws RestException 401 Unauthorized: User does not have permission to delete thirdparties accounts
2020-02-20 12:42:43 +00:00
* @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}/accounts/{site}
*/
public function deleteSocieteAccount($id, $site)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($site)."'";
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2020-10-31 10:57:35 +00:00
if ($result && $this->db->num_rows($result) == 0) {
throw new RestException(404);
} else {
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
$account = new SocieteAccount($this->db);
$account->fetch($obj->rowid);
if ($account->delete(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error while deleting $site account attached to this third party");
}
}
}
/**
* Delete all accounts attached to a third party
*
* @since 9.0.0 Initial implementation
*
* @param int $id ID of the third party
*
* @return void
*
* @throws RestException 401 Unauthorized: User does not have permission to delete thirdparties accounts
2020-10-31 08:50:50 +00:00
* @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}/accounts
*/
public function deleteSocieteAccounts($id)
{
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 14:58:49 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
2024-02-01 18:16:58 +00:00
throw new RestException(403);
}
/**
* We select all the records that match the socid
*/
$sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id);
2020-09-19 21:30:29 +00:00
$result = $this->db->query($sql);
2020-10-31 10:57:35 +00:00
if ($result && $this->db->num_rows($result) == 0) {
throw new RestException(404, 'This third party does not have any account attached or does not exist.');
} else {
$i = 0;
2025-09-28 20:20:44 +00:00
$i = 0;
2020-09-19 21:30:29 +00:00
$num = $this->db->num_rows($result);
2025-09-28 20:20:44 +00:00
//$min = min($num, ($limit <= 0 ? $num : $limit));
$min = $num;
while ($i < $min) {
2020-09-19 21:30:29 +00:00
$obj = $this->db->fetch_object($result);
$account = new SocieteAccount($this->db);
$account->fetch($obj->rowid);
if ($account->delete(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error while deleting account attached to this third party');
}
$i++;
}
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
* @phpstan-template T
*
* @param Object $object Object to clean
2023-05-02 01:38:57 +00:00
* @return Object Object with cleaned properties
* @phpstan-param T $object
* @phpstan-return T
*/
2019-03-04 18:57:46 +00:00
protected function _cleanObjectDatas($object)
{
// phpcs:enable
$object = parent::_cleanObjectDatas($object);
unset($object->nom); // ->name already defined and nom deprecated
unset($object->name_bis); // ->name_alias already defined
unset($object->note); // ->note_private and note_public already defined
2019-11-02 13:20:43 +00:00
unset($object->departement);
unset($object->departement_code);
unset($object->pays);
unset($object->particulier);
2019-11-02 13:26:27 +00:00
unset($object->prefix_comm);
2018-01-11 00:16:14 +00:00
2022-08-27 17:02:05 +00:00
unset($object->siren);
unset($object->siret);
unset($object->ape);
unset($object->commercial_id); // This property is used in create/update only. It does not exists in read mode because there is several sales representatives.
unset($object->total_ht);
unset($object->total_tva);
unset($object->total_localtax1);
unset($object->total_localtax2);
unset($object->total_ttc);
unset($object->lines);
unset($object->thirdparty);
unset($object->fk_delivery_address); // deprecated feature
2019-11-02 13:20:43 +00:00
return $object;
}
/**
* Validate fields before create or update object
*
2025-03-02 14:10:25 +00:00
* @param ?array<string,string> $data Data to validate
* @return array<string,string>
*
* @throws RestException
*/
private function _validate($data)
{
2025-03-02 14:10:25 +00:00
if ($data === null) {
$data = array();
}
$thirdparty = array();
foreach (Thirdparties::$FIELDS as $field) {
2021-02-26 20:17:52 +00:00
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
2021-02-26 20:17:52 +00:00
}
$thirdparty[$field] = $data[$field];
}
return $thirdparty;
}
/**
* Fetch properties of a thirdparty object.
*
* Return an array with thirdparty information
*
* @param ?int $rowid Id of third party to load (Use 0 to get a specimen record, use null to use other search criteria)
* @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)
2020-08-29 09:37:16 +00:00
* @param string $barcode Barcode of third party to load
* @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)
* @param string $idprof4 Prof id 4 of third party (Warning, this can return several records)
* @param string $idprof5 Prof id 5 of third party (Warning, this can return several records)
* @param string $idprof6 Prof id 6 of third party (Warning, this can return several records)
2023-09-26 16:43:25 +00:00
* @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 object cleaned Societe object
2025-03-03 13:23:57 +00:00
* @phan-return Societe
* @phpstan-return Societe
*
* @throws RestException
*/
private function _fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '')
{
2022-09-10 09:10:33 +00:00
if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login.'. No read permission on thirdparties.');
}
2025-05-22 16:57:32 +00:00
if ($rowid === 0) {
2020-10-29 22:56:42 +00:00
$result = $this->company->initAsSpecimen();
} else {
2025-05-22 16:57:32 +00:00
$result = $this->company->fetch((int) $rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
2020-10-29 22:56:42 +00:00
}
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login.' on this thirdparty');
}
2022-08-29 12:46:26 +00:00
if (isModEnabled('mailing')) {
$this->company->getNoEmail();
}
2023-11-27 11:08:48 +00:00
if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be subtracted 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)%')";
}
2025-03-03 13:23:57 +00:00
$absolute_discount = $this->company->getAvailableDiscounts(null, $filterabsolutediscount);
$absolute_creditnote = $this->company->getAvailableDiscounts(null, $filtercreditnote);
$this->company->absolute_discount = price2num($absolute_discount, 'MT');
$this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT');
return $this->_cleanObjectDatas($this->company);
}
}