dolibarr 24.0.1
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';
26
35{
39 public static $FIELDS = array(
40 'socid',
41 );
42
46 public $invoice;
47
51 public function __construct()
52 {
53 global $db;
54 $this->db = $db;
55 $this->invoice = new FactureFournisseur($this->db);
56 }
57
69 public function get($id)
70 {
71 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "lire")) {
72 throw new RestException(403);
73 }
74
75 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
76 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
77 }
78
79 $result = $this->invoice->fetch($id);
80 if (!$result) {
81 throw new RestException(404, 'Supplier invoice not found');
82 }
83
84 // Retrieve credit note ids
85 $this->invoice->getListIdAvoirFromInvoice();
86
87 $this->invoice->fetchObjectLinked();
88 return $this->_cleanObjectDatas($this->invoice);
89 }
90
111 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $status = '', $sqlfilters = '', $properties = '', $pagination_data = false)
112 {
113 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "lire")) {
114 throw new RestException(403);
115 }
116
117 $obj_ret = array();
118
119 // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
120 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
121
122 // If the internal user must only see his customers, force searching by him
123 $search_sale = 0;
124 if (!DolibarrApiAccess::$user->hasRight("societe", "client", "voir")) {
125 $search_sale = DolibarrApiAccess::$user->id;
126 }
127
128 $sql = "SELECT t.rowid";
129 $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn AS t";
130 $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
131 $sql .= ' WHERE t.entity IN (' . getEntity('supplier_invoice') . ')';
132 if ($socids) {
133 $sql .= " AND t.fk_soc IN (" . $this->db->sanitize($socids) . ")";
134 }
135 // Filter by status
136 if ($status == 'draft') {
137 $sql .= " AND t.fk_statut IN (0)";
138 }
139 if ($status == 'unpaid') {
140 $sql .= " AND t.fk_statut IN (1)";
141 }
142 if ($status == 'paid') {
143 $sql .= " AND t.fk_statut IN (2)";
144 }
145 if ($status == 'cancelled') {
146 $sql .= " AND t.fk_statut IN (3)";
147 }
148 // Search on sale representative
149 if ($search_sale && $search_sale != '-1') {
150 if ($search_sale == -2) {
151 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
152 } elseif ($search_sale > 0) {
153 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
154 }
155 }
156 // Add sql filters
157 if ($sqlfilters) {
158 $errormessage = '';
159 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
160 if ($errormessage) {
161 throw new RestException(400, 'Error when validating parameter sqlfilters -> ' . $errormessage);
162 }
163 }
164
165 //this query will return total supplier invoices with the filters given
166 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
167
168 $sql .= $this->db->order($sortfield, $sortorder);
169 if ($limit) {
170 if ($page < 0) {
171 $page = 0;
172 }
173 $offset = $limit * $page;
174
175 $sql .= $this->db->plimit($limit + 1, $offset);
176 }
177
178 $result = $this->db->query($sql);
179 if ($result) {
180 $i = 0;
181 $num = $this->db->num_rows($result);
182 $min = min($num, ($limit <= 0 ? $num : $limit));
183 while ($i < $min) {
184 $obj = $this->db->fetch_object($result);
185 $invoice_static = new FactureFournisseur($this->db);
186 if ($invoice_static->fetch($obj->rowid)) {
187 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($invoice_static), $properties);
188 }
189 $i++;
190 }
191 } else {
192 throw new RestException(503, 'Error when retrieve supplier invoice list : ' . $this->db->lasterror());
193 }
194
195 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
196 if ($pagination_data) {
197 $totalsResult = $this->db->query($sqlTotals);
198 $total = $this->db->fetch_object($totalsResult)->total;
199
200 $tmp = $obj_ret;
201 $obj_ret = [];
202
203 $obj_ret['data'] = $tmp;
204 $obj_ret['pagination'] = [
205 'total' => (int) $total,
206 'page' => $page, //count starts from 0
207 'page_count' => ceil((int) $total / $limit),
208 'limit' => $limit
209 ];
210 }
211
212 return $obj_ret;
213 }
214
231 public function post($request_data = null)
232 {
233 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
234 throw new RestException(403, "Insufficiant rights");
235 }
236
237 if (!is_array($request_data)) {
238 $request_data = array();
239 }
240
241 // Check mandatory fields (not using output, only possible exception is important)
242 $this->_validate($request_data);
243
244 foreach ($request_data as $field => $value) {
245 if ($field === 'caller') {
246 // 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
247 $this->invoice->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
248 continue;
249 }
250
251 $this->invoice->$field = $this->_checkValForAPI($field, $value, $this->invoice);
252 }
253 if (!array_key_exists('date', $request_data)) {
254 $this->invoice->date = dol_now();
255 }
256
257 if ($this->invoice->create(DolibarrApiAccess::$user) < 0) {
258 throw new RestException(500, "Error creating invoice ", array_merge(array($this->invoice->error), $this->invoice->errors));
259 }
260 return $this->invoice->id;
261 }
262
275 public function put($id, $request_data = null)
276 {
277 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
278 throw new RestException(403);
279 }
280
281 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
282 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
283 }
284
285 $result = $this->invoice->fetch($id);
286 if (!$result) {
287 throw new RestException(404, 'Supplier invoice not found');
288 }
289
290 if (!is_array($request_data)) {
291 $request_data = array();
292 }
293
294 foreach ($request_data as $field => $value) {
295 if ($field == 'id') {
296 continue;
297 }
298 if ($field === 'caller') {
299 // 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
300 $this->invoice->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
301 continue;
302 }
303 if ($field == 'array_options' && is_array($value)) {
304 foreach ($value as $index => $val) {
305 $this->invoice->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->invoice);
306 }
307 continue;
308 }
309
310 $this->invoice->$field = $this->_checkValForAPI($field, $value, $this->invoice);
311 }
312
313 if ($this->invoice->update(DolibarrApiAccess::$user)) {
314 return $this->get($id);
315 }
316
317 return false;
318 }
319
333 public function delete($id)
334 {
335 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "supprimer")) {
336 throw new RestException(403);
337 }
338 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
339 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
340 }
341 $result = $this->invoice->fetch($id);
342 if (!$result) {
343 throw new RestException(404, 'Supplier invoice not found');
344 }
345
346 $result = $this->invoice->delete(DolibarrApiAccess::$user);
347 if ($result < 0) {
348 throw new RestException(500, 'Error when deleting invoice');
349 } elseif ($result == 0) {
350 throw new RestException(403, 'Invoice not erasable');
351 }
352
353 return array(
354 'success' => array(
355 'code' => 200,
356 'message' => 'Supplier invoice deleted'
357 )
358 );
359 }
360
380 public function validate($id, $idwarehouse = 0, $notrigger = 0)
381 {
382 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
383 throw new RestException(403);
384 }
385
386 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
387 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
388 }
389
390 $result = $this->invoice->fetch($id);
391 if (!$result) {
392 throw new RestException(404, 'Invoice not found');
393 }
394
395 $result = $this->invoice->validate(DolibarrApiAccess::$user, '', $idwarehouse, $notrigger);
396 if ($result == 0) {
397 throw new RestException(304, 'Error nothing done. The invoice is already validated');
398 }
399 if ($result < 0) {
400 throw new RestException(500, 'Error when validating Invoice: ' . $this->invoice->error);
401 }
402
403 return array(
404 'success' => array(
405 'code' => 200,
406 'message' => 'Invoice validated (Ref=' . $this->invoice->ref . ')'
407 )
408 );
409 }
410
426 public function settodraft($id, $idwarehouse = -1, $notrigger = 0)
427 {
428 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
429 throw new RestException(403);
430 }
431 $result = $this->invoice->fetch($id);
432 if (!$result) {
433 throw new RestException(404, 'Invoice not found');
434 }
435
436 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
437 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
438 }
439
440 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
441 if ($result == 0) {
442 throw new RestException(304, 'Nothing done.');
443 }
444 if ($result < 0) {
445 throw new RestException(500, 'Error : ' . $this->invoice->error);
446 }
447
448 $result = $this->invoice->fetch($id);
449 if (!$result) {
450 throw new RestException(404, 'Invoice not found');
451 }
452
453 return $this->_cleanObjectDatas($this->invoice);
454 }
455
471 public function getPayments($id)
472 {
473 if (empty($id)) {
474 throw new RestException(400, 'Invoice ID is mandatory');
475 }
476
477 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "lire")) {
478 throw new RestException(403);
479 }
480 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
481 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
482 }
483
484 $result = $this->invoice->fetch($id);
485 if (!$result) {
486 throw new RestException(404, 'Invoice not found');
487 }
488
489 $result = $this->invoice->getListOfPayments();
490 if ($this->invoice->error !== '') {
491 throw new RestException(405, $this->invoice->error);
492 }
493
494 return $result;
495 }
496
497
520 public function addPayment($id, $datepaye, $payment_mode_id, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $amount = null)
521 {
522 if (empty($id)) {
523 throw new RestException(400, 'Invoice ID is mandatory');
524 }
525
526 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
527 throw new RestException(403);
528 }
529 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
530 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
531 }
532
533 $result = $this->invoice->fetch($id);
534 if (!$result) {
535 throw new RestException(404, 'Invoice not found');
536 }
537
538 if (isModEnabled("bank")) {
539 if (empty($accountid)) {
540 throw new RestException(400, 'Bank account ID is mandatory');
541 }
542 }
543
544 if (empty($payment_mode_id)) {
545 throw new RestException(400, 'Payment mode ID is mandatory');
546 }
547
548 if (null !== $amount && $amount > 0) {
549 // We use the amount given in parameter
550 $paymentamount = $amount;
551 } else {
552 // We calculate the remain to pay, and use it as amount
553 $totalpaid = $this->invoice->getSommePaiement();
554 $totaldeposits = $this->invoice->getSumDepositsUsed();
555 $paymentamount = price2num($this->invoice->total_ttc - $totalpaid - $totaldeposits, 'MT');
556 }
557
558 $this->db->begin();
559
560 $amounts = array();
561 $multicurrency_amounts = array();
562
563 $paymentamount = (float) price2num($paymentamount, 'MT');
564
565 $amounts[$id] = $paymentamount;
566
567 // Multicurrency
568 // getWay() switches the payment to the invoice currency as soon as a multicurrency amount is set, so
569 // this value must match the partial amount, not always the full invoice TTC. When a partial amount was
570 // requested, convert it at the invoice rate (multicurrency_total_ttc / total_ttc); otherwise use the
571 // full multicurrency TTC (full payment).
572 if (null !== $amount && $amount > 0 && !empty($this->invoice->total_ttc)) {
573 $newvalue = (float) price2num($paymentamount * $this->invoice->multicurrency_total_ttc / $this->invoice->total_ttc, 'MT');
574 } else {
575 $newvalue = (float) price2num($this->invoice->multicurrency_total_ttc, 'MT');
576 }
577 $multicurrency_amounts[$id] = $newvalue;
578
579 // Creation of payment line
580 $paiement = new PaiementFourn($this->db);
581 $paiement->datepaye = $datepaye;
582 $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id
583 $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
584 $paiement->paiementid = $payment_mode_id;
585 $paiement->paiementcode = (string) dol_getIdFromCode($this->db, (string) $payment_mode_id, 'c_paiement', 'id', 'code', 1);
586 $paiement->num_payment = $num_payment;
587 $paiement->note_private = $comment;
588
589 $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices
590 if ($paiement_id < 0) {
591 $this->db->rollback();
592 throw new RestException(400, 'Payment error : ' . $paiement->error);
593 }
594
595 if (isModEnabled("bank")) {
596 $result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, $chqemetteur, $chqbank);
597 if ($result < 0) {
598 $this->db->rollback();
599 throw new RestException(400, 'Add payment to bank error : ' . $paiement->error);
600 }
601 }
602
603 $this->db->commit();
604
605 return $paiement_id;
606 }
607
623 public function settopaid($id, $close_code = '', $close_note = '')
624 {
625 if (!DolibarrApiAccess::$user->hasRight('fournisseur', 'facture', 'creer')) {
626 throw new RestException(403);
627 }
628
629 $result = $this->invoice->fetch($id);
630 if (!$result) {
631 throw new RestException(404, 'Supplier invoice not found');
632 }
633
634 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
635 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
636 }
637
638 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
639 if ($result == 0) {
640 throw new RestException(304, 'Error nothing done. Maybe object is already paid or not payable.');
641 }
642 if ($result < 0) {
643 throw new RestException(500, 'Error: ' . $this->invoice->error);
644 }
645
646 $result = $this->invoice->fetch($id);
647 if (!$result) {
648 throw new RestException(404, 'Supplier invoice not found');
649 }
650
651 return $this->_cleanObjectDatas($this->invoice);
652 }
653
667 public function settounpaid($id)
668 {
669 if (!DolibarrApiAccess::$user->hasRight('fournisseur', 'facture', 'creer')) {
670 throw new RestException(403);
671 }
672
673 $result = $this->invoice->fetch($id);
674 if (!$result) {
675 throw new RestException(404, 'Supplier invoice not found');
676 }
677
678 if (!DolibarrApi::_checkAccessToResource('fournisseur', $this->invoice->id, 'facture_fourn', 'facture')) {
679 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
680 }
681
682 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
683 if ($result == 0) {
684 throw new RestException(304, 'Nothing done.');
685 }
686 if ($result < 0) {
687 throw new RestException(500, 'Error: ' . $this->invoice->error);
688 }
689
690 $result = $this->invoice->fetch($id);
691 if (!$result) {
692 throw new RestException(404, 'Supplier invoice not found');
693 }
694
695 return $this->_cleanObjectDatas($this->invoice);
696 }
697
712 public function getLines($id)
713 {
714 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
715 throw new RestException(403);
716 }
717 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
718 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
719 }
720
721 $result = $this->invoice->fetch($id);
722 if (!$result) {
723 throw new RestException(404, 'Supplier invoice not found');
724 }
725
726 $this->invoice->fetch_lines();
727 $result = array();
728 foreach ($this->invoice->lines as $line) {
729 array_push($result, $this->_cleanObjectDatas($line));
730 }
731 return $result;
732 }
733
753 public function postLine($id, $request_data = null)
754 {
755 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
756 throw new RestException(403);
757 }
758
759 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
760 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
761 }
762
763 $result = $this->invoice->fetch($id);
764 if (!$result) {
765 throw new RestException(404, 'Supplier invoice not found');
766 }
767
768 $request_data = (object) $request_data;
769
770 $request_data->description = sanitizeVal($request_data->description, 'restricthtml');
771 $request_data->ref_supplier = sanitizeVal($request_data->ref_supplier);
772
773 $updateRes = $this->invoice->addline(
774 $request_data->description,
775 $request_data->pu_ht,
776 $request_data->tva_tx,
777 $request_data->localtax1_tx,
778 $request_data->localtax2_tx,
779 $request_data->qty,
780 $request_data->fk_product,
781 $request_data->remise_percent,
782 $request_data->date_start,
783 $request_data->date_end,
784 $request_data->fk_code_ventilation,
785 $request_data->info_bits,
786 $request_data->price_base_type ? $request_data->price_base_type : 'HT',
787 $request_data->product_type,
788 $request_data->rang,
789 0,
790 $request_data->array_options,
791 $request_data->fk_unit,
792 $request_data->origin_id,
793 $request_data->multicurrency_subprice,
794 $request_data->ref_supplier,
795 $request_data->special_code
796 );
797
798 if ($updateRes < 0) {
799 throw new RestException(400, 'Unable to insert the new line. Check your inputs. ' . $this->invoice->error);
800 }
801
802 return $updateRes;
803 }
804
822 public function putLine($id, $lineid, $request_data = null)
823 {
824 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
825 throw new RestException(403);
826 }
827
828 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
829 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
830 }
831
832 $result = $this->invoice->fetch($id);
833 if (!$result) {
834 throw new RestException(404, 'Supplier invoice not found');
835 }
836
837 $request_data = (object) $request_data;
838
839 $request_data->description = sanitizeVal($request_data->description, 'restricthtml');
840 $request_data->ref_supplier = sanitizeVal($request_data->ref_supplier);
841
842 $updateRes = $this->invoice->updateline(
843 $lineid,
844 $request_data->description,
845 $request_data->pu_ht,
846 $request_data->tva_tx,
847 $request_data->localtax1_tx,
848 $request_data->localtax2_tx,
849 $request_data->qty,
850 $request_data->fk_product,
851 $request_data->price_base_type ? $request_data->price_base_type : 'HT',
852 $request_data->info_bits,
853 $request_data->product_type,
854 $request_data->remise_percent,
855 0,
856 $request_data->date_start,
857 $request_data->date_end,
858 $request_data->array_options,
859 $request_data->fk_unit,
860 $request_data->multicurrency_subprice,
861 $request_data->ref_supplier,
862 $request_data->rang
863 );
864
865 if ($updateRes > 0) {
866 $result = $this->get($id);
867 unset($result->line);
868 return $this->_cleanObjectDatas($result);
869 } else {
870 throw new RestException(304, $this->invoice->error);
871 }
872 }
873
891 public function deleteLine($id, $lineid)
892 {
893 if (empty($lineid)) {
894 throw new RestException(400, 'Line ID is mandatory');
895 }
896
897 if (!DolibarrApiAccess::$user->hasRight("fournisseur", "facture", "creer")) {
898 throw new RestException(403);
899 }
900 if (!DolibarrApi::_checkAccessToResource('fournisseur', $id, 'facture_fourn', 'facture')) {
901 throw new RestException(403, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
902 }
903
904 $result = $this->invoice->fetch($id);
905 if (!$result) {
906 throw new RestException(404, 'Supplier invoice not found');
907 }
908
909 // TODO Check the lineid $lineid is a line of object
910
911 $updateRes = $this->invoice->deleteLine($lineid);
912 if ($updateRes > 0) {
913 return array(
914 'success' => array(
915 'code' => 200,
916 'message' => 'line '.$lineid.' deleted'
917 )
918 );
919 } else {
920 throw new RestException(405, $this->invoice->error);
921 }
922 }
923
924 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
934 protected function _cleanObjectDatas($object)
935 {
936 // phpcs:enable
937 $object = parent::_cleanObjectDatas($object);
938
939 unset($object->rowid);
940 unset($object->barcode_type);
941 unset($object->barcode_type_code);
942 unset($object->barcode_type_label);
943 unset($object->barcode_type_coder);
944
945 return $object;
946 }
947
956 private function _validate($data)
957 {
958 if ($data === null) {
959 $data = array();
960 }
961 $invoice = array();
962 foreach (SupplierInvoices::$FIELDS as $field) {
963 if (!isset($data[$field])) {
964 throw new RestException(400, "$field field missing");
965 }
966 $invoice[$field] = $data[$field];
967 }
968 return $invoice;
969 }
970}
$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
buildzip.php