dolibarr 19.0.3
api_thirdparties.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2018 Pierre Chéné <pierre.chene44@gmail.com>
4 * Copyright (C) 2019 Cedric Ancelin <icedo.anc@gmail.com>
5 * Copyright (C) 2020-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23use Luracast\Restler\RestException;
24
33{
38 public static $FIELDS = array(
39 'name'
40 );
41
45 public $company;
46
50 public function __construct()
51 {
52 global $db;
53 $this->db = $db;
54
55 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
56 require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
57 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
58 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
59
60 $this->company = new Societe($this->db);
61
62 if (getDolGlobalString('SOCIETE_EMAIL_MANDATORY')) {
63 static::$FIELDS[] = 'email';
64 }
65 }
66
77 public function get($id)
78 {
79 return $this->_fetch($id);
80 }
81
94 public function getByEmail($email)
95 {
96 return $this->_fetch('', '', '', '', '', '', '', '', '', '', $email);
97 }
98
111 public function getByBarcode($barcode)
112 {
113 return $this->_fetch('', '', '', $barcode);
114 }
115
134 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $category = 0, $sqlfilters = '', $properties = '')
135 {
136 $obj_ret = array();
137
138 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
139 throw new RestException(401);
140 }
141
142 // case of external user, we force socids
143 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
144
145 // If the internal user must only see his customers, force searching by him
146 $search_sale = 0;
147 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
148 $search_sale = DolibarrApiAccess::$user->id;
149 }
150
151 $sql = "SELECT t.rowid";
152 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
153 $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
154 }
155 $sql .= " FROM ".MAIN_DB_PREFIX."societe as t";
156 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields AS ef ON ef.fk_object = t.rowid"; // So we will be able to filter on extrafields
157 if ($category > 0) {
158 if ($mode != 4) {
159 $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c";
160 }
161 if (!in_array($mode, array(1, 2, 3))) {
162 $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cc";
163 }
164 }
165 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
166 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
167 }
168 $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
169 $sql .= " WHERE t.entity IN (".getEntity('societe').")";
170 $sql .= " AND t.fk_stcomm = st.id";
171
172 if ($mode == 1) {
173 $sql .= " AND t.client IN (1, 3)";
174 } elseif ($mode == 2) {
175 $sql .= " AND t.client IN (2, 3)";
176 } elseif ($mode == 3) {
177 $sql .= " AND t.client IN (0)";
178 } elseif ($mode == 4) {
179 $sql .= " AND t.fournisseur IN (1)";
180 }
181
182 // Select thirdparties of given category
183 if ($category > 0) {
184 if (!empty($mode) && $mode != 4) {
185 $sql .= " AND c.fk_categorie = ".((int) $category)." AND c.fk_soc = t.rowid";
186 } elseif (!empty($mode) && $mode == 4) {
187 $sql .= " AND cc.fk_categorie = ".((int) $category)." AND cc.fk_soc = t.rowid";
188 } else {
189 $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))";
190 }
191 }
192
193 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
194 $sql .= " AND t.rowid = sc.fk_soc";
195 }
196 //if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
197 if ($socids) {
198 $sql .= " AND t.rowid IN (".$this->db->sanitize($socids).")";
199 }
200 if ($search_sale > 0) {
201 $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
202 }
203 // Insert sale filter
204 if ($search_sale > 0) {
205 $sql .= " AND sc.fk_user = ".((int) $search_sale);
206 }
207 // Add sql filters
208 if ($sqlfilters) {
209 $errormessage = '';
210 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
211 if ($errormessage) {
212 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
213 }
214 }
215
216 $sql .= $this->db->order($sortfield, $sortorder);
217
218 if ($limit) {
219 if ($page < 0) {
220 $page = 0;
221 }
222 $offset = $limit * $page;
223
224 $sql .= $this->db->plimit($limit + 1, $offset);
225 }
226
227 $result = $this->db->query($sql);
228 if ($result) {
229 $num = $this->db->num_rows($result);
230 $min = min($num, ($limit <= 0 ? $num : $limit));
231 $i = 0;
232 while ($i < $min) {
233 $obj = $this->db->fetch_object($result);
234 $soc_static = new Societe($this->db);
235 if ($soc_static->fetch($obj->rowid)) {
236 if (isModEnabled('mailing')) {
237 $soc_static->getNoEmail();
238 }
239 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($soc_static), $properties);
240 }
241 $i++;
242 }
243 } else {
244 throw new RestException(503, 'Error when retrieve thirdparties : '.$this->db->lasterror());
245 }
246 if (!count($obj_ret)) {
247 throw new RestException(404, 'Thirdparties not found');
248 }
249 return $obj_ret;
250 }
251
258 public function post($request_data = null)
259 {
260 if (!DolibarrApiAccess::$user->rights->societe->creer) {
261 throw new RestException(401);
262 }
263 // Check mandatory fields
264 $result = $this->_validate($request_data);
265
266 foreach ($request_data as $field => $value) {
267 if ($field === 'caller') {
268 // 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 whith the caller
269 $this->company->context['caller'] = $request_data['caller'];
270 continue;
271 }
272
273 $this->company->$field = $this->_checkValForAPI($field, $value, $this->company);
274 }
275
276 if ($this->company->create(DolibarrApiAccess::$user) < 0) {
277 throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
278 }
279 if (isModEnabled('mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
280 $this->company->setNoEmail($this->company->no_email);
281 }
282
283 return $this->company->id;
284 }
285
296 public function put($id, $request_data = null)
297 {
298 if (!DolibarrApiAccess::$user->rights->societe->creer) {
299 throw new RestException(401);
300 }
301
302 $result = $this->company->fetch($id);
303 if (!$result) {
304 throw new RestException(404, 'Thirdparty not found');
305 }
306
307 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
308 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
309 }
310
311 foreach ($request_data as $field => $value) {
312 if ($field == 'id') {
313 continue;
314 }
315 if ($field === 'caller') {
316 // 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 whith the caller
317 $this->company->context['caller'] = $request_data['caller'];
318 continue;
319 }
320
321 $this->company->$field = $this->_checkValForAPI($field, $value, $this->company);
322 }
323
324 if (isModEnabled('mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
325 $this->company->setNoEmail($this->company->no_email);
326 }
327
328 if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update', 1) > 0) {
329 return $this->get($id);
330 } else {
331 throw new RestException(500, $this->company->error);
332 }
333 }
334
349 public function merge($id, $idtodelete)
350 {
351 global $user;
352
353 $error = 0;
354
355 if ($id == $idtodelete) {
356 throw new RestException(400, 'Try to merge a thirdparty into itself');
357 }
358
359 if (!DolibarrApiAccess::$user->rights->societe->creer) {
360 throw new RestException(401);
361 }
362
363 $result = $this->company->fetch($id); // include the fetch of extra fields
364 if (!$result) {
365 throw new RestException(404, 'Thirdparty not found');
366 }
367
368 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
369 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
370 }
371
372 $companytoremove = new Societe($this->db);
373 $result = $companytoremove->fetch($idtodelete); // include the fetch of extra fields
374 if (!$result) {
375 throw new RestException(404, 'Thirdparty not found');
376 }
377
378 if (!DolibarrApi::_checkAccessToResource('societe', $companytoremove->id)) {
379 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
380 }
381
382 $user = DolibarrApiAccess::$user;
383 $result = $this->company->mergeCompany($companytoremove->id);
384 if ($result < 0) {
385 throw new RestException(500, 'Error failed to merged thirdparty '.$companytoremove->id.' into '.$id.'. Enable and read log file for more information.');
386 }
387
388 return $this->get($id);
389 }
390
397 public function delete($id)
398 {
399 if (!DolibarrApiAccess::$user->hasRight('societe', 'supprimer')) {
400 throw new RestException(401);
401 }
402 $result = $this->company->fetch($id);
403 if (!$result) {
404 throw new RestException(404, 'Thirdparty not found');
405 }
406 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
407 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
408 }
409 $this->company->oldcopy = clone $this->company;
410
411 $res = $this->company->delete($id);
412 if ($res < 0) {
413 throw new RestException(500, "Can't delete, error occurs");
414 } elseif ($res == 0) {
415 throw new RestException(409, "Can't delete, that product is probably used");
416 }
417
418 return array(
419 'success' => array(
420 'code' => 200,
421 'message' => 'Object deleted'
422 )
423 );
424 }
425
441 public function setThirdpartyPriceLevel($id, $priceLevel)
442 {
443 global $conf;
444
445 if (!isModEnabled('societe')) {
446 throw new RestException(501, 'Module "Thirdparties" needed for this request');
447 }
448
449 if (!isModEnabled("product")) {
450 throw new RestException(501, 'Module "Products" needed for this request');
451 }
452
453 if (!getDolGlobalString('PRODUIT_MULTIPRICES')) {
454 throw new RestException(501, 'Multiprices features activation needed for this request');
455 }
456
457 if ($priceLevel < 1 || $priceLevel > $conf->global->PRODUIT_MULTIPRICES_LIMIT) {
458 throw new RestException(400, 'Price level must be between 1 and ' . getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT'));
459 }
460
461 if (empty(DolibarrApiAccess::$user->rights->societe->creer)) {
462 throw new RestException(401, 'Access to thirdparty '.$id.' not allowed for login '.DolibarrApiAccess::$user->login);
463 }
464
465 $result = $this->company->fetch($id);
466 if ($result < 0) {
467 throw new RestException(404, 'Thirdparty '.$id.' not found');
468 }
469
470 if (empty($result)) {
471 throw new RestException(500, 'Error fetching thirdparty '.$id, array_merge(array($this->company->error), $this->company->errors));
472 }
473
474 if (empty(DolibarrApi::_checkAccessToResource('societe', $this->company->id))) {
475 throw new RestException(401, 'Access to thirdparty '.$id.' not allowed for login '.DolibarrApiAccess::$user->login);
476 }
477
478 $result = $this->company->setPriceLevel($priceLevel, DolibarrApiAccess::$user);
479 if ($result <= 0) {
480 throw new RestException(500, 'Error setting new price level for thirdparty '.$id, array($this->company->db->lasterror()));
481 }
482
483 return $this->_cleanObjectDatas($this->company);
484 }
485
498 public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
499 {
500 if (!DolibarrApiAccess::$user->rights->categorie->lire) {
501 throw new RestException(401);
502 }
503
504 $result = $this->company->fetch($id);
505 if (!$result) {
506 throw new RestException(404, 'Thirdparty not found');
507 }
508
509 $categories = new Categorie($this->db);
510
511 $arrayofcateg = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page);
512
513 if (is_numeric($arrayofcateg) && $arrayofcateg < 0) {
514 throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
515 }
516
517 if (is_numeric($arrayofcateg) && $arrayofcateg >= 0) { // To fix a return of 0 instead of empty array of method getListForItem
518 return array();
519 }
520
521 return $arrayofcateg;
522 }
523
533 public function addCategory($id, $category_id)
534 {
535 if (!DolibarrApiAccess::$user->rights->societe->creer) {
536 throw new RestException(401);
537 }
538
539 $result = $this->company->fetch($id);
540 if (!$result) {
541 throw new RestException(404, 'Thirdparty not found');
542 }
543 $category = new Categorie($this->db);
544 $result = $category->fetch($category_id);
545 if (!$result) {
546 throw new RestException(404, 'category not found');
547 }
548
549 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
550 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
551 }
552 if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
553 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
554 }
555
556 $category->add_type($this->company, 'customer');
557
558 return $this->_cleanObjectDatas($this->company);
559 }
560
571 public function deleteCategory($id, $category_id)
572 {
573 if (!DolibarrApiAccess::$user->rights->societe->creer) {
574 throw new RestException(401);
575 }
576
577 $result = $this->company->fetch($id);
578 if (!$result) {
579 throw new RestException(404, 'Thirdparty not found');
580 }
581 $category = new Categorie($this->db);
582 $result = $category->fetch($category_id);
583 if (!$result) {
584 throw new RestException(404, 'category not found');
585 }
586
587 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
588 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
589 }
590 if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
591 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
592 }
593
594 $category->del_type($this->company, 'customer');
595
596 return $this->_cleanObjectDatas($this->company);
597 }
598
612 public function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
613 {
614 if (!DolibarrApiAccess::$user->rights->categorie->lire) {
615 throw new RestException(401);
616 }
617
618 $result = $this->company->fetch($id);
619 if (!$result) {
620 throw new RestException(404, 'Thirdparty not found');
621 }
622
623 $categories = new Categorie($this->db);
624
625 $result = $categories->getListForItem($id, 'supplier', $sortfield, $sortorder, $limit, $page);
626
627 if (is_numeric($result) && $result < 0) {
628 throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
629 }
630
631 if (is_numeric($result) && $result == 0) { // To fix a return of 0 instead of empty array of method getListForItem
632 return array();
633 }
634
635 return $result;
636 }
637
648 public function addSupplierCategory($id, $category_id)
649 {
650 if (!DolibarrApiAccess::$user->rights->societe->creer) {
651 throw new RestException(401);
652 }
653
654 $result = $this->company->fetch($id);
655 if (!$result) {
656 throw new RestException(404, 'Thirdparty not found');
657 }
658 $category = new Categorie($this->db);
659 $result = $category->fetch($category_id);
660 if (!$result) {
661 throw new RestException(404, 'category not found');
662 }
663
664 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
665 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
666 }
667 if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
668 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
669 }
670
671 $category->add_type($this->company, 'supplier');
672
673 return $this->_cleanObjectDatas($this->company);
674 }
675
686 public function deleteSupplierCategory($id, $category_id)
687 {
688 if (!DolibarrApiAccess::$user->rights->societe->creer) {
689 throw new RestException(401);
690 }
691
692 $result = $this->company->fetch($id);
693 if (!$result) {
694 throw new RestException(404, 'Thirdparty not found');
695 }
696 $category = new Categorie($this->db);
697 $result = $category->fetch($category_id);
698 if (!$result) {
699 throw new RestException(404, 'category not found');
700 }
701
702 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
703 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
704 }
705 if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
706 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
707 }
708
709 $category->del_type($this->company, 'supplier');
710
711 return $this->_cleanObjectDatas($this->company);
712 }
713
714
729 public function getOutStandingProposals($id, $mode = 'customer')
730 {
731 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
732 throw new RestException(401);
733 }
734
735 if (empty($id)) {
736 throw new RestException(400, 'Thirdparty ID is mandatory');
737 }
738
739 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
740 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
741 }
742
743 $result = $this->company->fetch($id);
744 if (!$result) {
745 throw new RestException(404, 'Thirdparty not found');
746 }
747
748 $result = $this->company->getOutstandingProposals($mode);
749
750 unset($result['total_ht']);
751 unset($result['total_ttc']);
752
753 return $result;
754 }
755
756
771 public function getOutStandingOrder($id, $mode = 'customer')
772 {
773 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
774 throw new RestException(401);
775 }
776
777 if (empty($id)) {
778 throw new RestException(400, 'Thirdparty ID is mandatory');
779 }
780
781 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
782 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
783 }
784
785 $result = $this->company->fetch($id);
786 if (!$result) {
787 throw new RestException(404, 'Thirdparty not found');
788 }
789
790 $result = $this->company->getOutstandingOrders($mode);
791
792 unset($result['total_ht']);
793 unset($result['total_ttc']);
794
795 return $result;
796 }
797
812 public function getOutStandingInvoices($id, $mode = 'customer')
813 {
814 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
815 throw new RestException(401);
816 }
817
818 if (empty($id)) {
819 throw new RestException(400, 'Thirdparty ID is mandatory');
820 }
821
822 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
823 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
824 }
825
826 $result = $this->company->fetch($id);
827 if (!$result) {
828 throw new RestException(404, 'Thirdparty not found');
829 }
830
831 $result = $this->company->getOutstandingBills($mode);
832
833 unset($result['total_ht']);
834 unset($result['total_ttc']);
835
836 return $result;
837 }
838
853 public function getSalesRepresentatives($id, $mode = 0)
854 {
855 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
856 throw new RestException(401);
857 }
858
859 if (empty($id)) {
860 throw new RestException(400, 'Thirdparty ID is mandatory');
861 }
862
863 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
864 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
865 }
866
867 $result = $this->company->fetch($id);
868 if (!$result) {
869 throw new RestException(404, 'Thirdparty not found');
870 }
871
872 $result = $this->company->getSalesRepresentatives(DolibarrApiAccess::$user, $mode);
873
874 return $result;
875 }
876
894 public function getFixedAmountDiscounts($id, $filter = "none", $sortfield = "f.type", $sortorder = 'ASC')
895 {
896 $obj_ret = array();
897
898 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
899 throw new RestException(401);
900 }
901
902 if (empty($id)) {
903 throw new RestException(400, 'Thirdparty ID is mandatory');
904 }
905
906 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
907 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
908 }
909
910 $result = $this->company->fetch($id);
911 if (!$result) {
912 throw new RestException(404, 'Thirdparty not found');
913 }
914
915
916 $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";
917 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
918 $sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".((int) $id);
919 if ($filter == "available") {
920 $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL";
921 }
922 if ($filter == "used") {
923 $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)";
924 }
925
926 $sql .= $this->db->order($sortfield, $sortorder);
927
928 $result = $this->db->query($sql);
929 if (!$result) {
930 throw new RestException(503, $this->db->lasterror());
931 } else {
932 $num = $this->db->num_rows($result);
933 while ($obj = $this->db->fetch_object($result)) {
934 $obj_ret[] = $obj;
935 }
936 }
937
938 return $obj_ret;
939 }
940
941
942
957 {
958 if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
959 throw new RestException(401);
960 }
961 if (empty($id)) {
962 throw new RestException(400, 'Thirdparty ID is mandatory');
963 }
964
965 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
966 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
967 }
968
969 /*$result = $this->thirdparty->fetch($id);
970 if( ! $result ) {
971 throw new RestException(404, 'Thirdparty not found');
972 }*/
973
974 $invoice = new Facture($this->db);
975 $result = $invoice->list_replacable_invoices($id);
976 if ($result < 0) {
977 throw new RestException(405, $invoice->error);
978 }
979
980 return $result;
981 }
982
1000 {
1001 if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
1002 throw new RestException(401);
1003 }
1004 if (empty($id)) {
1005 throw new RestException(400, 'Thirdparty ID is mandatory');
1006 }
1007
1008 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
1009 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1010 }
1011
1012 /*$result = $this->thirdparty->fetch($id);
1013 if( ! $result ) {
1014 throw new RestException(404, 'Thirdparty not found');
1015 }*/
1016
1017 $invoice = new Facture($this->db);
1018 $result = $invoice->list_qualified_avoir_invoices($id);
1019 if ($result < 0) {
1020 throw new RestException(405, $invoice->error);
1021 }
1022
1023 return $result;
1024 }
1025
1035 public function getCompanyBankAccount($id)
1036 {
1037 if (!DolibarrApiAccess::$user->rights->societe->lire) {
1038 throw new RestException(401);
1039 }
1040 if (empty($id)) {
1041 throw new RestException(400, 'Thirdparty ID is mandatory');
1042 }
1043
1044 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
1045 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1046 }
1047
1052 $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
1053 $sql .= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur";
1054 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
1055 if ($id) {
1056 $sql .= " WHERE fk_soc = ".((int) $id);
1057 }
1058
1059 $result = $this->db->query($sql);
1060
1061 if ($this->db->num_rows($result) == 0) {
1062 throw new RestException(404, 'Account not found');
1063 }
1064
1065 $i = 0;
1066
1067 $accounts = array();
1068
1069 if ($result) {
1070 $num = $this->db->num_rows($result);
1071 while ($i < $num) {
1072 $obj = $this->db->fetch_object($result);
1073 $account = new CompanyBankAccount($this->db);
1074 if ($account->fetch($obj->rowid)) {
1075 $accounts[] = $account;
1076 }
1077 $i++;
1078 }
1079 } else {
1080 throw new RestException(404, 'Account not found');
1081 }
1082
1083
1084 $fields = array('socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id', 'rum');
1085
1086 $returnAccounts = array();
1087
1088 foreach ($accounts as $account) {
1089 $object = array();
1090 foreach ($account as $key => $value) {
1091 if (in_array($key, $fields)) {
1092 $object[$key] = $value;
1093 }
1094 }
1095 $returnAccounts[] = $object;
1096 }
1097
1098 return $returnAccounts;
1099 }
1100
1110 public function createCompanyBankAccount($id, $request_data = null)
1111 {
1112 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1113 throw new RestException(401);
1114 }
1115 if ($this->company->fetch($id) <= 0) {
1116 throw new RestException(404, 'Error creating Company Bank account, Company doesn\'t exists');
1117 }
1118 $account = new CompanyBankAccount($this->db);
1119
1120 $account->socid = $id;
1121
1122 foreach ($request_data as $field => $value) {
1123 if ($field === 'caller') {
1124 // 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 whith the caller
1125 $this->company->context['caller'] = $request_data['caller'];
1126 continue;
1127 }
1128
1129 $account->$field = $value;
1130 }
1131
1132 if ($account->create(DolibarrApiAccess::$user) < 0) {
1133 throw new RestException(500, 'Error creating Company Bank account');
1134 }
1135
1136 if (empty($account->rum)) {
1137 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
1138 $prelevement = new BonPrelevement($this->db);
1139 $account->rum = $prelevement->buildRumNumber($this->company->code_client, $account->datec, $account->id);
1140 $account->date_rum = dol_now();
1141 }
1142
1143 if ($account->update(DolibarrApiAccess::$user) < 0) {
1144 throw new RestException(500, 'Error updating values');
1145 }
1146
1147 return $this->_cleanObjectDatas($account);
1148 }
1149
1161 public function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null)
1162 {
1163 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1164 throw new RestException(401);
1165 }
1166 if ($this->company->fetch($id) <= 0) {
1167 throw new RestException(404, 'Error creating Company Bank account, Company doesn\'t exists');
1168 }
1169 $account = new CompanyBankAccount($this->db);
1170
1171 $account->fetch($bankaccount_id, $id, -1, '');
1172
1173 if ($account->socid != $id) {
1174 throw new RestException(401);
1175 }
1176
1177
1178 foreach ($request_data as $field => $value) {
1179 if ($field === 'caller') {
1180 // 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 whith the caller
1181 $account->context['caller'] = $request_data['caller'];
1182 continue;
1183 }
1184
1185 $account->$field = $value;
1186 }
1187
1188 if (empty($account->rum)) {
1189 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
1190 $prelevement = new BonPrelevement($this->db);
1191 $account->rum = $prelevement->buildRumNumber($this->company->code_client, $account->datec, $account->id);
1192 $account->date_rum = dol_now();
1193 }
1194
1195 if ($account->update(DolibarrApiAccess::$user) < 0) {
1196 throw new RestException(500, 'Error updating values');
1197 }
1198
1199 return $this->_cleanObjectDatas($account);
1200 }
1201
1212 public function deleteCompanyBankAccount($id, $bankaccount_id)
1213 {
1214 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1215 throw new RestException(401);
1216 }
1217
1218 $account = new CompanyBankAccount($this->db);
1219
1220 $account->fetch($bankaccount_id);
1221
1222 if (!$account->socid == $id) {
1223 throw new RestException(401);
1224 }
1225
1226 return $account->delete(DolibarrApiAccess::$user);
1227 }
1228
1239 public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate')
1240 {
1241 global $conf, $langs;
1242
1243 $langs->loadLangs(array("main", "dict", "commercial", "products", "companies", "banks", "bills", "withdrawals"));
1244
1245 if ($this->company->fetch($id) <= 0) {
1246 throw new RestException(404, 'Thirdparty not found');
1247 }
1248
1249 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1250 throw new RestException(401);
1251 }
1252
1253 $this->company->setDocModel(DolibarrApiAccess::$user, $model);
1254
1255 $this->company->fk_bank = $this->company->fk_account;
1256 $this->company->fk_account = $this->company->fk_account;
1257
1258 $outputlangs = $langs;
1259 $newlang = '';
1260
1261 //if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
1262 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1263 if (isset($this->company->thirdparty->default_lang)) {
1264 $newlang = $this->company->thirdparty->default_lang; // for proposal, order, invoice, ...
1265 } elseif (isset($this->company->default_lang)) {
1266 $newlang = $this->company->default_lang; // for thirdparty
1267 }
1268 }
1269 if (!empty($newlang)) {
1270 $outputlangs = new Translate("", $conf);
1271 $outputlangs->setDefaultLang($newlang);
1272 }
1273
1274 $sql = "SELECT rowid";
1275 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib";
1276 if ($id) {
1277 $sql .= " WHERE fk_soc = ".((int) $id);
1278 }
1279 if ($companybankid) {
1280 $sql .= " AND rowid = ".((int) $companybankid);
1281 }
1282
1283 $i = 0;
1284 $accounts = array();
1285
1286 $result = $this->db->query($sql);
1287 if ($result) {
1288 if ($this->db->num_rows($result) == 0) {
1289 throw new RestException(404, 'Bank account not found');
1290 }
1291
1292 $num = $this->db->num_rows($result);
1293 while ($i < $num) {
1294 $obj = $this->db->fetch_object($result);
1295
1296 $account = new CompanyBankAccount($this->db);
1297 if ($account->fetch($obj->rowid)) {
1298 $accounts[] = $account;
1299 }
1300 $i++;
1301 }
1302 } else {
1303 throw new RestException(500, 'Sql error '.$this->db->lasterror());
1304 }
1305
1306 $moreparams = array(
1307 'use_companybankid' => $accounts[0]->id,
1308 'force_dir_output' => $conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id)
1309 );
1310
1311 $result = $this->company->generateDocument($model, $outputlangs, 0, 0, 0, $moreparams);
1312
1313 if ($result > 0) {
1314 return array("success" => $result);
1315 } else {
1316 throw new RestException(500, 'Error generating the document '.$this->company->error);
1317 }
1318 }
1319
1332 public function getSocieteAccounts($id, $site = null)
1333 {
1334 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
1335 throw new RestException(401);
1336 }
1337
1338 if (!DolibarrApi::_checkAccessToResource('societe', $id)) {
1339 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1340 }
1341
1345 $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
1346 $sql .= " WHERE fk_soc = ".((int) $id);
1347 if ($site) {
1348 $sql .= " AND site ='".$this->db->escape($site)."'";
1349 }
1350
1351 $result = $this->db->query($sql);
1352
1353 if ($result && $this->db->num_rows($result) == 0) {
1354 throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.');
1355 }
1356
1357 $i = 0;
1358
1359 $accounts = array();
1360
1361 $num = $this->db->num_rows($result);
1362 while ($i < $num) {
1363 $obj = $this->db->fetch_object($result);
1364 $account = new SocieteAccount($this->db);
1365
1366 if ($account->fetch($obj->rowid)) {
1367 $accounts[] = $account;
1368 }
1369 $i++;
1370 }
1371
1372 $fields = array('id', 'fk_soc', 'key_account', 'site', 'date_creation', 'tms');
1373
1374 $returnAccounts = array();
1375
1376 foreach ($accounts as $account) {
1377 $object = array();
1378 foreach ($account as $key => $value) {
1379 if (in_array($key, $fields)) {
1380 $object[$key] = $value;
1381 }
1382 }
1383 $returnAccounts[] = $object;
1384 }
1385
1386 return $returnAccounts;
1387 }
1388
1408 public function createSocieteAccount($id, $request_data = null)
1409 {
1410 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1411 throw new RestException(401);
1412 }
1413
1414 if (!isset($request_data['site'])) {
1415 throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !');
1416 }
1417
1418 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($request_data['site'])."'";
1419 $result = $this->db->query($sql);
1420
1421 if ($result && $this->db->num_rows($result) == 0) {
1422 $account = new SocieteAccount($this->db);
1423 if (!isset($request_data['login'])) {
1424 $account->login = "";
1425 }
1426 $account->fk_soc = $id;
1427
1428 foreach ($request_data as $field => $value) {
1429 if ($field === 'caller') {
1430 // 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 whith the caller
1431 $account->context['caller'] = $request_data['caller'];
1432 continue;
1433 }
1434
1435 $account->$field = $value;
1436 }
1437
1438 if ($account->create(DolibarrApiAccess::$user) < 0) {
1439 throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!');
1440 }
1441
1442 $this->_cleanObjectDatas($account);
1443
1444 return $account;
1445 } else {
1446 throw new RestException(409, 'A SocieteAccount entity already exists for this company and site.');
1447 }
1448 }
1449
1472 public function putSocieteAccount($id, $site, $request_data = null)
1473 {
1474 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1475 throw new RestException(401);
1476 }
1477
1478 $sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '".$this->db->escape($site)."'";
1479 $result = $this->db->query($sql);
1480
1481 // We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one.
1482 if ($result && $this->db->num_rows == 0) {
1483 if (!isset($request_data['key_account'])) {
1484 throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !');
1485 }
1486 $account = new SocieteAccount($this->db);
1487 if (!isset($request_data['login'])) {
1488 $account->login = "";
1489 }
1490
1491 foreach ($request_data as $field => $value) {
1492 if ($field === 'caller') {
1493 // 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 whith the caller
1494 $account->context['caller'] = $request_data['caller'];
1495 continue;
1496 }
1497
1498 $account->$field = $value;
1499 }
1500
1501 $account->fk_soc = $id;
1502 $account->site = $site;
1503
1504 if ($account->create(DolibarrApiAccess::$user) < 0) {
1505 throw new RestException(500, 'Error creating SocieteAccount entity.');
1506 }
1507 // We found an existing SocieteAccount entity, we are replacing it
1508 } else {
1509 if (isset($request_data['site']) && $request_data['site'] !== $site) {
1510 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($request_data['site'])."' ";
1511 $result = $this->db->query($sql);
1512
1513 if ($result && $this->db->num_rows($result) !== 0) {
1514 throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site']." but another SocieteAccount entity already exists with this site key.");
1515 }
1516 }
1517
1518 $obj = $this->db->fetch_object($result);
1519
1520 $account = new SocieteAccount($this->db);
1521 $account->id = $obj->rowid;
1522 $account->fk_soc = $id;
1523 $account->site = $site;
1524 if (!isset($request_data['login'])) {
1525 $account->login = "";
1526 }
1527 $account->fk_user_creat = $obj->fk_user_creat;
1528 $account->date_creation = $obj->date_creation;
1529
1530 foreach ($request_data as $field => $value) {
1531 if ($field === 'caller') {
1532 // 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 whith the caller
1533 $account->context['caller'] = $request_data['caller'];
1534 continue;
1535 }
1536
1537 $account->$field = $value;
1538 }
1539
1540 if ($account->update(DolibarrApiAccess::$user) < 0) {
1541 throw new RestException(500, 'Error updating SocieteAccount entity.');
1542 }
1543 }
1544
1545 $this->_cleanObjectDatas($account);
1546
1547 return $account;
1548 }
1549
1566 public function patchSocieteAccount($id, $site, $request_data = null)
1567 {
1568 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1569 throw new RestException(401);
1570 }
1571
1572 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($site)."'";
1573 $result = $this->db->query($sql);
1574
1575 if ($result && $this->db->num_rows($result) == 0) {
1576 throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist.");
1577 } else {
1578 // If the user tries to edit the site member, we check first if
1579 if (isset($request_data['site']) && $request_data['site'] !== $site) {
1580 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id)." AND site = '".$this->db->escape($request_data['site'])."' ";
1581 $result = $this->db->query($sql);
1582
1583 if ($result && $this->db->num_rows($result) !== 0) {
1584 throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from ".$site." to ".$request_data['site']." but another SocieteAccount entity already exists for this thirdparty with this site key.");
1585 }
1586 }
1587
1588 $obj = $this->db->fetch_object($result);
1589 $account = new SocieteAccount($this->db);
1590 $account->fetch($obj->rowid);
1591
1592 foreach ($request_data as $field => $value) {
1593 if ($field === 'caller') {
1594 // 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 whith the caller
1595 $account->context['caller'] = $request_data['caller'];
1596 continue;
1597 }
1598
1599 $account->$field = $value;
1600 }
1601
1602 if ($account->update(DolibarrApiAccess::$user) < 0) {
1603 throw new RestException(500, 'Error updating SocieteAccount account');
1604 }
1605
1606 $this->_cleanObjectDatas($account);
1607
1608 return $account;
1609 }
1610 }
1611
1625 public function deleteSocieteAccount($id, $site)
1626 {
1627 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1628 throw new RestException(401);
1629 }
1630
1631 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '".$this->db->escape($site)."'";
1632 $result = $this->db->query($sql);
1633
1634 if ($result && $this->db->num_rows($result) == 0) {
1635 throw new RestException(404);
1636 } else {
1637 $obj = $this->db->fetch_object($result);
1638 $account = new SocieteAccount($this->db);
1639 $account->fetch($obj->rowid);
1640
1641 if ($account->delete(DolibarrApiAccess::$user) < 0) {
1642 throw new RestException(500, "Error while deleting $site gateway attached to this third party");
1643 }
1644 }
1645 }
1646
1659 public function deleteSocieteAccounts($id)
1660 {
1661 if (!DolibarrApiAccess::$user->rights->societe->creer) {
1662 throw new RestException(401);
1663 }
1664
1669 $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms";
1670 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".((int) $id);
1671
1672 $result = $this->db->query($sql);
1673
1674 if ($result && $this->db->num_rows($result) == 0) {
1675 throw new RestException(404, 'This third party does not have any gateway attached or does not exist.');
1676 } else {
1677 $i = 0;
1678
1679 $num = $this->db->num_rows($result);
1680 while ($i < $num) {
1681 $obj = $this->db->fetch_object($result);
1682 $account = new SocieteAccount($this->db);
1683 $account->fetch($obj->rowid);
1684
1685 if ($account->delete(DolibarrApiAccess::$user) < 0) {
1686 throw new RestException(500, 'Error while deleting gateways attached to this third party');
1687 }
1688 $i++;
1689 }
1690 }
1691 }
1692
1693 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1700 protected function _cleanObjectDatas($object)
1701 {
1702 // phpcs:enable
1703 $object = parent::_cleanObjectDatas($object);
1704
1705 unset($object->nom); // ->name already defined and nom deprecated
1706 unset($object->name_bis); // ->name_alias already defined
1707 unset($object->note); // ->note_private and note_public already defined
1708 unset($object->departement);
1709 unset($object->departement_code);
1710 unset($object->pays);
1711 unset($object->particulier);
1712 unset($object->prefix_comm);
1713
1714 unset($object->siren);
1715 unset($object->siret);
1716 unset($object->ape);
1717
1718 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.
1719
1720 unset($object->total_ht);
1721 unset($object->total_tva);
1722 unset($object->total_localtax1);
1723 unset($object->total_localtax2);
1724 unset($object->total_ttc);
1725
1726 unset($object->lines);
1727 unset($object->thirdparty);
1728
1729 unset($object->fk_delivery_address); // deprecated feature
1730
1731 return $object;
1732 }
1733
1742 private function _validate($data)
1743 {
1744 $thirdparty = array();
1745 foreach (Thirdparties::$FIELDS as $field) {
1746 if (!isset($data[$field])) {
1747 throw new RestException(400, "$field field missing");
1748 }
1749 $thirdparty[$field] = $data[$field];
1750 }
1751 return $thirdparty;
1752 }
1753
1775 private function _fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '')
1776 {
1777 global $conf;
1778
1779 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
1780 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login.'. No read permission on thirdparties.');
1781 }
1782
1783 if ($rowid === 0) {
1784 $result = $this->company->initAsSpecimen();
1785 } else {
1786 $result = $this->company->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias);
1787 }
1788 if (!$result) {
1789 throw new RestException(404, 'Thirdparty not found');
1790 }
1791
1792 if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
1793 throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login.' on this thirdparty');
1794 }
1795 if (isModEnabled('mailing')) {
1796 $this->company->getNoEmail();
1797 }
1798
1799 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
1800 $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
1801 $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
1802 } else {
1803 $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
1804 $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
1805 }
1806
1807 $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount);
1808 $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote);
1809 $this->company->absolute_discount = price2num($absolute_discount, 'MT');
1810 $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT');
1811
1812 return $this->_cleanObjectDatas($this->company);
1813 }
1814}
Class to manage withdrawal receipts.
Class to manage categories.
Class to manage bank accounts description of third parties.
Class for API REST v1.
Definition api.class.php:31
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Definition api.class.php:85
Class to manage invoices.
Class for SocieteAccount.
Class to manage third parties objects (customers, suppliers, prospects...)
setThirdpartyPriceLevel($id, $priceLevel)
Set new price level for the given thirdparty.
_cleanObjectDatas($object)
Clean sensible object datas.
getSupplierCategories($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Get supplier categories for a thirdparty.
getSocieteAccounts($id, $site=null)
Get a specific gateway attached to a thirdparty (by specifying the site key)
getOutStandingOrder($id, $mode='customer')
Get outstanding orders of thirdparty.
getByBarcode($barcode)
Get properties of a thirdparty object by barcode.
generateBankAccountDocument($id, $companybankid=null, $model='sepamandate')
Generate a Document from a bank account record (like SEPA mandate)
addCategory($id, $category_id)
Add a customer category to a thirdparty.
getCompanyBankAccount($id)
Get CompanyBankAccount objects for thirdparty.
getInvoicesQualifiedForReplacement($id)
Return list of invoices qualified to be replaced by another invoice.
post($request_data=null)
Create thirdparty object.
put($id, $request_data=null)
Update thirdparty.
getByEmail($email)
Get properties of a thirdparty object by email.
_validate($data)
Validate fields before create or update object.
addSupplierCategory($id, $category_id)
Add a supplier category to a thirdparty.
merge($id, $idtodelete)
Merge a thirdparty into another one.
deleteSocieteAccounts($id)
Delete all gateways attached to a thirdparty.
__construct()
Constructor.
getCategories($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Get customer categories for a thirdparty.
deleteSupplierCategory($id, $category_id)
Remove the link between a category and the thirdparty.
putSocieteAccount($id, $site, $request_data=null)
Create and attach a new (or replace an existing) specific site gateway to a thirdparty.
updateCompanyBankAccount($id, $bankaccount_id, $request_data=null)
Update CompanyBankAccount object for thirdparty.
deleteSocieteAccount($id, $site)
Delete a specific site gateway attached to a thirdparty (by gateway id)
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $mode=0, $category=0, $sqlfilters='', $properties='')
List thirdparties.
getInvoicesQualifiedForCreditNote($id)
Return list of invoices qualified to be corrected by a credit note.
patchSocieteAccount($id, $site, $request_data=null)
Update specified values of a specific gateway attached to a thirdparty.
getFixedAmountDiscounts($id, $filter="none", $sortfield="f.type", $sortorder='ASC')
Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers....
getOutStandingProposals($id, $mode='customer')
Get outstanding proposals of thirdparty.
_fetch($rowid, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='')
Fetch properties of a thirdparty object.
getSalesRepresentatives($id, $mode=0)
Get representatives of thirdparty.
getOutStandingInvoices($id, $mode='customer')
Get outstanding invoices of thirdparty.
deleteCompanyBankAccount($id, $bankaccount_id)
Delete a bank account attached to a thirdparty.
createSocieteAccount($id, $request_data=null)
Create and attach a new gateway to an existing thirdparty.
createCompanyBankAccount($id, $request_data=null)
Create CompanyBankAccount object for thirdparty.
deleteCategory($id, $category_id)
Remove the link between a customer category and the thirdparty.
Class to manage translations.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.