dolibarr 25.0.0-alpha
api_supplier_invoices.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22use Luracast\Restler\RestException;
23
24require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
25require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
27
36{
40 public static $FIELDS = array(
41 'socid',
42 );
43
47 public $invoice;
48
52 public function __construct()
53 {
54 global $db;
55 $this->db = $db;
56 $this->invoice = new FactureFournisseur($this->db);
57 }
58
70 public function get($id)
71 {
72 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "lire")) {
73 throw new RestException(403);
74 }
75
76 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
77 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
78 }
79
80 $result = $this->invoice->fetch($id);
81 if (!$result) {
82 throw new RestException(404, 'Supplier invoice not found');
83 }
84
85 // Retrieve credit note ids
86 $this->invoice->getListIdAvoirFromInvoice();
87
88 $this->invoice->fetchObjectLinked();
89 return $this->_cleanObjectDatas($this->invoice);
90 }
91
112 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $status = '', $sqlfilters = '', $properties = '', $pagination_data = false)
113 {
114 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "lire")) {
115 throw new RestException(403);
116 }
117
118 $obj_ret = array();
119
120 // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
121 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
122
123 // If the internal user must only see his customers, force searching by him
124 $search_sale = 0;
125 if (!DolibarrApiAccess::$user->hasRight("societe", "client", "voir")) {
126 $search_sale = DolibarrApiAccess::$user->id;
127 }
128
129 $sql = "SELECT t.rowid";
130 $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn AS t";
131 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
132 $sql .= ' WHERE t.entity IN (' . getEntity('supplier_invoice') . ')';
133 if ($socids) {
134 $sql .= " AND t.fk_soc IN (" . $this->db->sanitize($socids) . ")";
135 }
136 // Filter by status
137 if ($status == 'draft') {
138 $sql .= " AND t.fk_statut IN (0)";
139 }
140 if ($status == 'unpaid') {
141 $sql .= " AND t.fk_statut IN (1)";
142 }
143 if ($status == 'paid') {
144 $sql .= " AND t.fk_statut IN (2)";
145 }
146 if ($status == 'cancelled') {
147 $sql .= " AND t.fk_statut IN (3)";
148 }
149 // Search on sale representative
150 if ($search_sale && $search_sale != '-1') {
151 if ($search_sale == -2) {
152 $sql .= " AND ".getSalesRepresentativeSqlFilter('t.fk_soc', 0, 1);
153 } elseif ($search_sale > 0) {
154 $sql .= " AND ".getSalesRepresentativeSqlFilter('t.fk_soc', (int) $search_sale);
155 }
156 }
157 // Add sql filters
158 if ($sqlfilters) {
159 $errormessage = '';
160 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
161 if ($errormessage) {
162 throw new RestException(400, 'Error when validating parameter sqlfilters -> ' . $errormessage);
163 }
164 }
165
166 //this query will return total supplier invoices with the filters given
167 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
168
169 $sql .= $this->db->order($sortfield, $sortorder);
170 if ($limit) {
171 if ($page < 0) {
172 $page = 0;
173 }
174 $offset = $limit * $page;
175
176 $sql .= $this->db->plimit($limit + 1, $offset);
177 }
178
179 $result = $this->db->query($sql);
180 if ($result) {
181 $i = 0;
182 $num = $this->db->num_rows($result);
183 $min = min($num, ($limit <= 0 ? $num : $limit));
184 while ($i < $min) {
185 $obj = $this->db->fetch_object($result);
186 $invoice_static = new FactureFournisseur($this->db);
187 if ($invoice_static->fetch($obj->rowid)) {
188 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($invoice_static), $properties);
189 }
190 $i++;
191 }
192 } else {
193 throw new RestException(503, 'Error when retrieve supplier invoice list : ' . $this->db->lasterror());
194 }
195
196 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
197 if ($pagination_data) {
198 $totalsResult = $this->db->query($sqlTotals);
199 $total = $this->db->fetch_object($totalsResult)->total;
200
201 $tmp = $obj_ret;
202 $obj_ret = [];
203
204 $obj_ret['data'] = $tmp;
205 $obj_ret['pagination'] = [
206 'total' => (int) $total,
207 'page' => $page, //count starts from 0
208 'page_count' => ceil((int) $total / $limit),
209 'limit' => $limit
210 ];
211 }
212
213 return $obj_ret;
214 }
215
232 public function post($request_data = null)
233 {
234 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
235 throw new RestException(403, "Insufficiant rights");
236 }
237
238 if (!is_array($request_data)) {
239 $request_data = array();
240 }
241
242 // Check mandatory fields (not using output, only possible exception is important)
243 $this->_validate($request_data);
244
245 foreach ($request_data as $field => $value) {
246 if ($field === 'caller') {
247 // 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
248 $this->invoice->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
249 continue;
250 }
251
252 $this->invoice->$field = $this->_checkValForAPI($field, $value, $this->invoice);
253 }
254 if (!array_key_exists('date', $request_data)) {
255 $this->invoice->date = dol_now();
256 }
257
258 if ($this->invoice->create(DolibarrApiAccess::$user) < 0) {
259 throw new RestException(500, "Error creating invoice ", array_merge(array($this->invoice->error), $this->invoice->errors));
260 }
261 return $this->invoice->id;
262 }
263
276 public function put($id, $request_data = null)
277 {
278 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
279 throw new RestException(403);
280 }
281
282 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
283 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
284 }
285
286 $result = $this->invoice->fetch($id);
287 if (!$result) {
288 throw new RestException(404, 'Supplier invoice not found');
289 }
290
291 if (!is_array($request_data)) {
292 $request_data = array();
293 }
294
295 foreach ($request_data as $field => $value) {
296 if ($field == 'id') {
297 continue;
298 }
299 if ($field === 'caller') {
300 // 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
301 $this->invoice->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
302 continue;
303 }
304 if ($field == 'array_options' && is_array($value)) {
305 foreach ($value as $index => $val) {
306 $this->invoice->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->invoice);
307 }
308 continue;
309 }
310
311 $this->invoice->$field = $this->_checkValForAPI($field, $value, $this->invoice);
312 }
313
314 if ($this->invoice->update(DolibarrApiAccess::$user)) {
315 return $this->get($id);
316 }
317
318 return false;
319 }
320
334 public function delete($id)
335 {
336 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "supprimer")) {
337 throw new RestException(403);
338 }
339 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
340 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
341 }
342 $result = $this->invoice->fetch($id);
343 if (!$result) {
344 throw new RestException(404, 'Supplier invoice not found');
345 }
346
347 if ($this->invoice->delete(DolibarrApiAccess::$user) < 0) {
348 throw new RestException(500, 'Error when deleting invoice');
349 }
350
351 return array(
352 'success' => array(
353 'code' => 200,
354 'message' => 'Supplier invoice deleted'
355 )
356 );
357 }
358
378 public function validate($id, $idwarehouse = 0, $notrigger = 0)
379 {
380 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
381 throw new RestException(403);
382 }
383
384 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
385 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
386 }
387
388 $result = $this->invoice->fetch($id);
389 if (!$result) {
390 throw new RestException(404, 'Invoice not found');
391 }
392
393 $result = $this->invoice->validate(DolibarrApiAccess::$user, '', $idwarehouse, $notrigger);
394 if ($result == 0) {
395 throw new RestException(304, 'Error nothing done. The invoice is already validated');
396 }
397 if ($result < 0) {
398 throw new RestException(500, 'Error when validating Invoice: ' . $this->invoice->error);
399 }
400
401 return array(
402 'success' => array(
403 'code' => 200,
404 'message' => 'Invoice validated (Ref=' . $this->invoice->ref . ')'
405 )
406 );
407 }
408
424 public function settodraft($id, $idwarehouse = -1, $notrigger = 0)
425 {
426 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
427 throw new RestException(403);
428 }
429 $result = $this->invoice->fetch($id);
430 if (!$result) {
431 throw new RestException(404, 'Invoice not found');
432 }
433
434 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
435 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
436 }
437
438 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
439 if ($result == 0) {
440 throw new RestException(304, 'Nothing done.');
441 }
442 if ($result < 0) {
443 throw new RestException(500, 'Error : ' . $this->invoice->error);
444 }
445
446 $result = $this->invoice->fetch($id);
447 if (!$result) {
448 throw new RestException(404, 'Invoice not found');
449 }
450
451 return $this->_cleanObjectDatas($this->invoice);
452 }
453
469 public function getPayments($id)
470 {
471 if (empty($id)) {
472 throw new RestException(400, 'Invoice ID is mandatory');
473 }
474
475 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "lire")) {
476 throw new RestException(403);
477 }
478 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
479 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
480 }
481
482 $result = $this->invoice->fetch($id);
483 if (!$result) {
484 throw new RestException(404, 'Invoice not found');
485 }
486
487 $result = $this->invoice->getListOfPayments();
488 if ($this->invoice->error !== '') {
489 throw new RestException(405, $this->invoice->error);
490 }
491
492 return $result;
493 }
494
495
518 public function addPayment($id, $datepaye, $payment_mode_id, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $amount = null)
519 {
520 if (empty($id)) {
521 throw new RestException(400, 'Invoice ID is mandatory');
522 }
523
524 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
525 throw new RestException(403);
526 }
527 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
528 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
529 }
530
531 $result = $this->invoice->fetch($id);
532 if (!$result) {
533 throw new RestException(404, 'Invoice not found');
534 }
535
536 if (isModEnabled("bank")) {
537 if (empty($accountid)) {
538 throw new RestException(400, 'Bank account ID is mandatory');
539 }
540 }
541
542 if (empty($payment_mode_id)) {
543 throw new RestException(400, 'Payment mode ID is mandatory');
544 }
545
546 if (null !== $amount && $amount > 0) {
547 // We use the amount given in parameter
548 $paymentamount = $amount;
549 } else {
550 // We calculate the remain to pay, and use it as amount
551 $totalpaid = $this->invoice->getSommePaiement();
552 $totaldeposits = $this->invoice->getSumDepositsUsed();
553 $paymentamount = price2num($this->invoice->total_ttc - $totalpaid - $totaldeposits, 'MT');
554 }
555
556 $this->db->begin();
557
558 $amounts = array();
559 $multicurrency_amounts = array();
560
561 $paymentamount = (float) price2num($paymentamount, 'MT');
562
563 $amounts[$id] = $paymentamount;
564
565 // Multicurrency
566 // getWay() switches the payment to the invoice currency as soon as a multicurrency amount is set, so
567 // this value must match the partial amount, not always the full invoice TTC. When a partial amount was
568 // requested, convert it at the invoice rate (multicurrency_total_ttc / total_ttc); otherwise use the
569 // full multicurrency TTC (full payment).
570 if (null !== $amount && $amount > 0 && !empty($this->invoice->total_ttc)) {
571 $newvalue = (float) price2num($paymentamount * $this->invoice->multicurrency_total_ttc / $this->invoice->total_ttc, 'MT');
572 } else {
573 $newvalue = (float) price2num($this->invoice->multicurrency_total_ttc, 'MT');
574 }
575 $multicurrency_amounts[$id] = $newvalue;
576
577 // Creation of payment line
578 $paiement = new PaiementFourn($this->db);
579 $paiement->datepaye = $datepaye;
580 $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id
581 $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
582 $paiement->paiementid = $payment_mode_id;
583 $paiement->paiementcode = (string) dol_getIdFromCode($this->db, (string) $payment_mode_id, 'c_paiement', 'id', 'code', 1);
584 $paiement->num_payment = $num_payment;
585 $paiement->note_private = $comment;
586
587 $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices
588 if ($paiement_id < 0) {
589 $this->db->rollback();
590 throw new RestException(400, 'Payment error : ' . $paiement->error);
591 }
592
593 if (isModEnabled("bank")) {
594 $result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, $chqemetteur, $chqbank);
595 if ($result < 0) {
596 $this->db->rollback();
597 throw new RestException(400, 'Add payment to bank error : ' . $paiement->error);
598 }
599 }
600
601 $this->db->commit();
602
603 return $paiement_id;
604 }
605
621 public function settopaid($id, $close_code = '', $close_note = '')
622 {
623 if (!DolibarrApiAccess::$user->hasRight('fournisseur', 'facture', 'creer')) {
624 throw new RestException(403);
625 }
626
627 $result = $this->invoice->fetch($id);
628 if (!$result) {
629 throw new RestException(404, 'Supplier invoice not found');
630 }
631
632 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
633 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
634 }
635
636 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
637 if ($result == 0) {
638 throw new RestException(304, 'Error nothing done. Maybe object is already paid or not payable.');
639 }
640 if ($result < 0) {
641 throw new RestException(500, 'Error: ' . $this->invoice->error);
642 }
643
644 $result = $this->invoice->fetch($id);
645 if (!$result) {
646 throw new RestException(404, 'Supplier invoice not found');
647 }
648
649 return $this->_cleanObjectDatas($this->invoice);
650 }
651
665 public function settounpaid($id)
666 {
667 if (!DolibarrApiAccess::$user->hasRight('fournisseur', 'facture', 'creer')) {
668 throw new RestException(403);
669 }
670
671 $result = $this->invoice->fetch($id);
672 if (!$result) {
673 throw new RestException(404, 'Supplier invoice not found');
674 }
675
676 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
677 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
678 }
679
680 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
681 if ($result == 0) {
682 throw new RestException(304, 'Nothing done.');
683 }
684 if ($result < 0) {
685 throw new RestException(500, 'Error: ' . $this->invoice->error);
686 }
687
688 $result = $this->invoice->fetch($id);
689 if (!$result) {
690 throw new RestException(404, 'Supplier invoice not found');
691 }
692
693 return $this->_cleanObjectDatas($this->invoice);
694 }
695
710 public function getLines($id)
711 {
712 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
713 throw new RestException(403);
714 }
715 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
716 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
717 }
718
719 $result = $this->invoice->fetch($id);
720 if (!$result) {
721 throw new RestException(404, 'Supplier invoice not found');
722 }
723
724 $this->invoice->fetch_lines();
725 $result = array();
726 foreach ($this->invoice->lines as $line) {
727 array_push($result, $this->_cleanObjectDatas($line));
728 }
729 return $result;
730 }
731
751 public function postLine($id, $request_data = null)
752 {
753 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
754 throw new RestException(403);
755 }
756
757 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
758 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
759 }
760
761 $result = $this->invoice->fetch($id);
762 if (!$result) {
763 throw new RestException(404, 'Supplier invoice not found');
764 }
765
766 $request_data = (object) $request_data;
767
768 $request_data->description = sanitizeVal($request_data->description, 'restricthtml');
769 $request_data->ref_supplier = sanitizeVal($request_data->ref_supplier);
770
771 $updateRes = $this->invoice->addline(
772 $request_data->description,
773 $request_data->pu_ht,
774 $request_data->tva_tx,
775 $request_data->localtax1_tx,
776 $request_data->localtax2_tx,
777 $request_data->qty,
778 $request_data->fk_product,
779 $request_data->remise_percent,
780 $request_data->date_start,
781 $request_data->date_end,
782 $request_data->fk_code_ventilation,
783 $request_data->info_bits,
784 $request_data->price_base_type ? $request_data->price_base_type : 'HT',
785 $request_data->product_type,
786 $request_data->rang,
787 0,
788 $request_data->array_options,
789 $request_data->fk_unit,
790 $request_data->origin_id,
791 $request_data->multicurrency_subprice,
792 $request_data->ref_supplier,
793 $request_data->special_code
794 );
795
796 if ($updateRes < 0) {
797 throw new RestException(400, 'Unable to insert the new line. Check your inputs. ' . $this->invoice->error);
798 }
799
800 return $updateRes;
801 }
802
820 public function putLine($id, $lineid, $request_data = null)
821 {
822 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
823 throw new RestException(403);
824 }
825
826 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
827 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
828 }
829
830 $result = $this->invoice->fetch($id);
831 if (!$result) {
832 throw new RestException(404, 'Supplier invoice not found');
833 }
834
835 $request_data = (object) $request_data;
836
837 $request_data->description = sanitizeVal($request_data->description, 'restricthtml');
838 $request_data->ref_supplier = sanitizeVal($request_data->ref_supplier);
839
840 $updateRes = $this->invoice->updateline(
841 $lineid,
842 $request_data->description,
843 $request_data->pu_ht,
844 $request_data->tva_tx,
845 $request_data->localtax1_tx,
846 $request_data->localtax2_tx,
847 $request_data->qty,
848 $request_data->fk_product,
849 $request_data->price_base_type ? $request_data->price_base_type : 'HT',
850 $request_data->info_bits,
851 $request_data->product_type,
852 $request_data->remise_percent,
853 0,
854 $request_data->date_start,
855 $request_data->date_end,
856 $request_data->array_options,
857 $request_data->fk_unit,
858 $request_data->multicurrency_subprice,
859 $request_data->ref_supplier,
860 $request_data->rang
861 );
862
863 if ($updateRes > 0) {
864 $result = $this->get($id);
865 unset($result->line);
866 return $this->_cleanObjectDatas($result);
867 } else {
868 throw new RestException(304, $this->invoice->error);
869 }
870 }
871
889 public function deleteLine($id, $lineid)
890 {
891 if (empty($lineid)) {
892 throw new RestException(400, 'Line ID is mandatory');
893 }
894
895 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
896 throw new RestException(403);
897 }
898 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
899 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
900 }
901
902 $result = $this->invoice->fetch($id);
903 if (!$result) {
904 throw new RestException(404, 'Supplier invoice not found');
905 }
906
907 // TODO Check the lineid $lineid is a line of object
908
909 $updateRes = $this->invoice->deleteLine($lineid);
910 if ($updateRes > 0) {
911 return array(
912 'success' => array(
913 'code' => 200,
914 'message' => 'line '.$lineid.' deleted'
915 )
916 );
917 } else {
918 throw new RestException(405, $this->invoice->error);
919 }
920 }
921
922 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
932 protected function _cleanObjectDatas($object)
933 {
934 // phpcs:enable
935 $object = parent::_cleanObjectDatas($object);
936
937 unset($object->rowid);
938 unset($object->barcode_type);
939 unset($object->barcode_type_code);
940 unset($object->barcode_type_label);
941 unset($object->barcode_type_coder);
942
943 return $object;
944 }
945
954 private function _validate($data)
955 {
956 if ($data === null) {
957 $data = array();
958 }
959 $invoice = array();
960 foreach (SupplierInvoices::$FIELDS as $field) {
961 if (!isset($data[$field])) {
962 throw new RestException(400, "$field field missing");
963 }
964 $invoice[$field] = $data[$field];
965 }
966 return $invoice;
967 }
968}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class for API REST v1.
Definition api.class.php:35
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
Class to manage suppliers invoices.
Class to manage payments for supplier invoices.
settodraft($id, $idwarehouse=-1, $notrigger=0)
Sets an invoice as draft.
validate($id, $idwarehouse=0, $notrigger=0)
Validate an invoice.
settopaid($id, $close_code='', $close_note='')
Sets a supplier invoice as paid.
deleteLine($id, $lineid)
Deletes a line of a given supplier invoice.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='', $properties='', $pagination_data=false)
List invoices.
getLines($id)
Get lines of a supplier invoice.
getPayments($id)
Get list of payments of a given supplier invoice.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
settounpaid($id)
Sets a supplier invoice as unpaid.
addPayment($id, $datepaye, $payment_mode_id, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='', $amount=null)
Add payment line to a specific supplier invoice with the remain to pay as amount.
post($request_data=null)
Create supplier invoice object.
postLine($id, $request_data=null)
Add a line to given supplier invoice.
put($id, $request_data=null)
Update supplier invoice.
_validate($data)
Validate fields before create or update object.
putLine($id, $lineid, $request_data=null)
Update a line to a given supplier invoice.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string