23use Luracast\Restler\RestException;
25require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
26require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture-rec.class.php';
40 public static $FIELDS = array(
52 private $template_invoice;
62 $this->invoice =
new Facture($this->db);
63 $this->template_invoice =
new FactureRec($this->db);
79 public function get(
$id, $contact_list = 1, $properties =
'', $withLines =
true)
81 $invoice = $this->
_fetch(
$id,
'',
'', $contact_list);
84 unset($invoice->lines);
105 return $this->
_fetch(0, $ref,
'', $contact_list);
123 return $this->
_fetch(0,
'', $ref_ext, $contact_list);
139 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $contact_list = 1)
141 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
142 throw new RestException(403);
144 if (empty(
$id) && empty($ref)&& empty($ref_ext)) {
145 throw new RestException(400,
'No invoice can be found with no criteria');
147 $result = $this->invoice->fetch(
$id, $ref, $ref_ext);
149 throw new RestException(404,
'Invoice not found');
153 $this->invoice->totalpaid = $this->invoice->getSommePaiement();
154 $this->invoice->totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
155 $this->invoice->totaldeposits = $this->invoice->getSumDepositsUsed();
156 $this->invoice->remaintopay =
price2num($this->invoice->total_ttc - $this->invoice->totalpaid - $this->invoice->totalcreditnotes - $this->invoice->totaldeposits,
'MT');
159 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
163 $this->invoice->getListIdAvoirFromInvoice();
166 if ($contact_list > -1) {
167 $tmparray = $this->invoice->liste_contact(-1,
'external', $contact_list);
168 if (is_array($tmparray)) {
169 $this->invoice->contacts_ids = $tmparray;
171 $tmparray = $this->invoice->liste_contact(-1,
'internal', $contact_list);
172 if (is_array($tmparray)) {
173 $this->invoice->contacts_ids = $tmparray;
177 $this->invoice->fetchObjectLinked();
180 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
181 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', $this->invoice->ref);
209 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
211 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
212 throw new RestException(403);
218 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
222 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
223 $search_sale = DolibarrApiAccess::$user->id;
226 $sql =
"SELECT t.rowid";
227 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture AS t";
228 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
229 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_extrafields AS ef ON (ef.fk_object = t.rowid)";
230 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
232 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
235 if ($search_sale && $search_sale !=
'-1') {
236 if ($search_sale == -2) {
237 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
238 } elseif ($search_sale > 0) {
239 $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).
")";
243 if ($status ==
'draft') {
244 $sql .=
" AND t.fk_statut IN (0)";
246 if ($status ==
'unpaid') {
247 $sql .=
" AND t.fk_statut IN (1)";
249 if ($status ==
'paid') {
250 $sql .=
" AND t.fk_statut IN (2)";
252 if ($status ==
'cancelled') {
253 $sql .=
" AND t.fk_statut IN (3)";
260 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
265 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
267 $sql .= $this->db->order($sortfield, $sortorder);
272 $offset = $limit * $page;
274 $sql .= $this->db->plimit($limit + 1, $offset);
277 $result = $this->db->query($sql);
280 $num = $this->db->num_rows($result);
281 $min = min($num, ($limit <= 0 ? $num : $limit));
283 $obj = $this->db->fetch_object($result);
284 $invoice_static =
new Facture($this->db);
285 if ($invoice_static->fetch($obj->rowid) > 0) {
287 $invoice_static->totalpaid = $invoice_static->getSommePaiement();
288 $invoice_static->totalcreditnotes = $invoice_static->getSumCreditNotesUsed();
289 $invoice_static->totaldeposits = $invoice_static->getSumDepositsUsed();
290 $invoice_static->remaintopay =
price2num($invoice_static->total_ttc - $invoice_static->totalpaid - $invoice_static->totalcreditnotes - $invoice_static->totaldeposits,
'MT');
293 $invoice_static->getListIdAvoirFromInvoice();
296 $tmparray = $invoice_static->liste_contact(-1,
'external', 1);
297 if (is_array($tmparray)) {
298 $invoice_static->contacts_ids = $tmparray;
301 if ($loadlinkedobjects) {
303 $invoice_static->fetchObjectLinked();
307 unset($invoice_static->lines);
311 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
312 $invoice_static->online_payment_url = getOnlinePaymentUrl(0,
'invoice', $invoice_static->ref);
319 throw new RestException(503,
'Error when retrieve invoice list : '.$this->db->lasterror());
323 if ($pagination_data) {
324 $totalsResult = $this->db->query($sqlTotals);
325 $total = $this->db->fetch_object($totalsResult)->total;
330 $obj_ret[
'data'] = $tmp;
331 $obj_ret[
'pagination'] = [
332 'total' => (int) $total,
334 'page_count' => ceil((
int) $total / $limit),
350 public function post($request_data =
null)
353 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
354 throw new RestException(403,
"Insufficiant rights");
357 if (!is_array($request_data)) {
358 $request_data = array();
365 $socid = (int) $request_data[
'socid'];
366 $thirdpartytmp =
new Societe($this->db);
367 $thirdparty_result = $thirdpartytmp->fetch($socid);
368 if ($thirdparty_result < 1) {
369 throw new RestException(404,
'Thirdparty with id='.$socid.
' not found or not allowed');
372 throw new RestException(404,
'Thirdparty with id='.$thirdpartytmp->id.
' not found or not allowed');
375 foreach ($request_data as $field => $value) {
376 if ($field ===
'caller') {
378 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
381 if ($field ==
'id') {
382 throw new RestException(400,
'Creating with id field is forbidden');
384 if ($field ==
'entity' && ((
int) $value) != ((
int) $conf->entity)) {
385 throw new RestException(403,
'Creating with entity='.((
int) $value).
' MUST be the same entity='.((
int) $conf->entity).
' as your API user/key belongs to');
388 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
390 if (!array_key_exists(
'date', $request_data)) {
391 $this->invoice->date =
dol_now();
402 if ($this->invoice->create(DolibarrApiAccess::$user, 0, (empty($request_data[
"date_lim_reglement"]) ? 0 : $request_data[
"date_lim_reglement"])) < 0) {
403 throw new RestException(500,
"Error creating invoice", array_merge(array($this->invoice->error), $this->invoice->errors));
405 return ((
int) $this->invoice->id);
424 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
426 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
427 throw new RestException(403);
429 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
430 throw new RestException(403);
432 if (empty($orderid)) {
433 throw new RestException(400,
'Order ID is mandatory');
436 throw new RestException(403,
'Access not allowed on order for login '.DolibarrApiAccess::$user->login);
440 $result = $order->fetch($orderid);
442 throw new RestException(404,
'Order not found');
445 $result = $this->invoice->createFromOrder($order, DolibarrApiAccess::$user);
447 throw new RestException(405, $this->invoice->error);
449 $this->invoice->fetchObjectLinked();
468 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
470 if (!DolibarrApiAccess::$user->hasRight(
'contrat',
'lire')) {
471 throw new RestException(403);
473 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
474 throw new RestException(403);
476 if (empty($contractid)) {
477 throw new RestException(400,
'Contract ID is mandatory');
480 $contract =
new Contrat($this->db);
481 $result = $contract->fetch($contractid);
483 throw new RestException(404,
'Contract not found');
486 $result = $this->invoice->createFromContract($contract, DolibarrApiAccess::$user);
488 throw new RestException(405, $this->invoice->error);
490 $this->invoice->fetchObjectLinked();
506 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
507 throw new RestException(403);
510 $result = $this->invoice->fetch(
$id);
512 throw new RestException(404,
'Invoice not found');
516 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
518 $this->invoice->getLinesArray();
520 foreach ($this->invoice->lines as $line) {
544 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
545 throw new RestException(403);
548 $result = $this->invoice->fetch(
$id);
550 throw new RestException(404,
'Invoice not found');
554 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
557 $request_data = (object) $request_data;
559 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
560 $request_data->label =
sanitizeVal($request_data->label);
562 $updateRes = $this->invoice->updateline(
565 $request_data->subprice,
567 $request_data->remise_percent,
568 $request_data->date_start,
569 $request_data->date_end,
570 $request_data->tva_tx,
571 $request_data->localtax1_tx,
572 $request_data->localtax2_tx,
573 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
574 $request_data->info_bits,
575 $request_data->product_type,
576 $request_data->fk_parent_line,
578 $request_data->fk_fournprice,
579 $request_data->pa_ht,
580 $request_data->label,
581 $request_data->special_code,
582 $request_data->array_options,
583 $request_data->situation_percent,
584 $request_data->fk_unit,
585 $request_data->multicurrency_subprice,
587 $request_data->ref_ext,
591 if ($updateRes > 0) {
592 $result = $this->
get(
$id);
593 unset($result->line);
596 throw new RestException(304, $this->invoice->error);
617 public function postContact(
$id, $contactid, $type, $source =
'external', $notrigger = 0)
619 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
620 throw new RestException(403);
624 if (empty($source)) {
625 throw new RestException(400,
'Source can not be empty');
627 $sql_distinct_source =
"SELECT DISTINCT source";
628 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
629 $sql_distinct_source .=
" WHERE element LIKE 'facture'";
630 $sql_distinct_source .=
" AND source is NOT NULL";
631 $sql_distinct_source .=
" AND active != 0";
632 $source_result = $this->db->query($sql_distinct_source);
633 $source_array = array();
635 if ($source_result) {
636 $num = $this->db->num_rows($source_result);
639 $obj = $this->db->fetch_object($source_result);
640 $source_kind = (string) $obj->source;
641 array_push($source_array, $source_kind);
646 throw new RestException(503,
'Error when retrieving a list of invoice contact sources: '.$this->db->lasterror());
648 if (!in_array($source, (array) $source_array,
true)) {
649 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active invoice contact types');
654 throw new RestException(400,
'type can not be empty');
657 $sql_distinct_type =
"SELECT DISTINCT code";
658 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
659 $sql_distinct_type .=
" WHERE element LIKE 'facture'";
660 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
661 $sql_distinct_type .=
" AND code is NOT NULL";
662 $sql_distinct_type .=
" AND active != 0";
663 $type_result = $this->db->query($sql_distinct_type);
664 $type_array = array();
667 $num = $this->db->num_rows($type_result);
670 $obj = $this->db->fetch_object($type_result);
672 $type_kind = (string) $obj->code;
673 array_push($type_array, $type_kind);
678 throw new RestException(503,
'Error when retrieving a list of invoice contact types: '.$this->db->lasterror());
680 if (!in_array($type, (array) $type_array,
true)) {
681 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active invoice contact types');
685 $result = $this->invoice->fetch(
$id);
687 throw new RestException(404,
'Invoice not found');
690 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
693 $result = $this->invoice->add_contact($contactid, $type, $source, $notrigger);
696 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the invoice='.
$id.
' as source='.$source.
' and type='.$type);
697 } elseif ($result == -1) {
698 throw new RestException(400,
'Wrong contact='.$contactid);
699 } elseif ($result == -2) {
700 throw new RestException(400,
'Wrong type='.$type);
701 } elseif ($result == -3) {
702 throw new RestException(400,
'Not allowed contacts');
703 } elseif ($result == -4) {
704 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
705 } elseif ($result == -5) {
706 throw new RestException(400,
'Trigger failed');
707 } elseif ($result == -6) {
708 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
709 } elseif ($result == -7) {
710 throw new RestException(400,
'Some other error');
714 throw new RestException(500,
'Error when added the contact');
720 'message' =>
'Contact='.$contactid.
' linked to the invoice='.
$id.
' as '.$source.
' '.$type
740 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
741 throw new RestException(403);
744 $result = $this->invoice->fetch(
$id);
746 throw new RestException(404,
'Invoice not found');
750 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
753 $contacts = $this->invoice->liste_contact(-1,
'external', 0, $type);
754 $socpeoples = $this->invoice->liste_contact(-1,
'internal', 0, $type);
756 $contacts = array_merge($contacts, $socpeoples);
777 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
778 throw new RestException(403);
781 $result = $this->invoice->fetch(
$id);
784 throw new RestException(404,
'Invoice not found');
788 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
791 $contacts = $this->invoice->liste_contact();
793 foreach ($contacts as $contact) {
794 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
795 $result = $this->invoice->delete_contact($contact[
'rowid']);
798 throw new RestException(500,
'Error when deleted the contact');
822 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
823 throw new RestException(403);
825 if (empty($lineid)) {
826 throw new RestException(400,
'Line ID is mandatory');
830 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
833 $result = $this->invoice->fetch(
$id);
835 throw new RestException(404,
'Invoice not found');
837 if ($this->invoice->status != 0) {
838 throw new RestException(403,
'Invoice not in Draft Status : '.$this->invoice->getLibStatut(1));
841 $updateRes = $this->invoice->deleteLine($lineid,
$id);
842 if ($updateRes > 0) {
843 return $this->
get(
$id);
845 throw new RestException(405, $this->invoice->error);
858 public function put(
$id, $request_data =
null)
860 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
861 throw new RestException(403);
864 throw new RestException(400,
'No invoice with id=0 can exist');
866 $result = $this->invoice->fetch(
$id);
868 throw new RestException(404,
'Invoice not found');
872 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
875 foreach ($request_data as $field => $value) {
876 if ($field ==
'id') {
879 if ($field ===
'caller') {
881 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
884 if ($field ==
'array_options' && is_array($value)) {
885 foreach ($value as $index => $val) {
886 $this->invoice->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->invoice);
891 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
894 if ($field ==
'cond_reglement_id') {
895 $this->invoice->date_lim_reglement = $this->invoice->calculate_date_lim_reglement();
900 if (!empty($this->invoice->fk_account)) {
901 if ($this->invoice->setBankAccount($this->invoice->fk_account) == 0) {
902 throw new RestException(400, $this->invoice->error);
906 if ($this->invoice->update(DolibarrApiAccess::$user) > 0) {
907 return $this->
get(
$id);
909 throw new RestException(500, $this->invoice->error);
921 public function delete(
$id)
923 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'supprimer')) {
924 throw new RestException(403);
927 throw new RestException(400,
'No invoice with id=0 can exist');
929 $result = $this->invoice->fetch(
$id);
931 throw new RestException(404,
'Invoice not found');
935 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
938 $result = $this->invoice->delete(DolibarrApiAccess::$user);
940 throw new RestException(500,
'Error when deleting invoice');
941 } elseif ($result == 0) {
942 throw new RestException(403,
'Invoice not erasable');
948 'message' =>
'Invoice deleted'
980 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
981 throw new RestException(403);
984 $result = $this->invoice->fetch(
$id);
986 throw new RestException(404,
'Invoice not found');
990 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
993 $request_data = (object) $request_data;
995 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
996 $request_data->label =
sanitizeVal($request_data->label);
999 if (($request_data->product_type != 9 && empty($request_data->fk_parent_line)) || $request_data->product_type == 9) {
1000 $request_data->fk_parent_line = 0;
1004 $marginInfos =
getMarginInfos($request_data->subprice, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, $request_data->fk_fournprice, $request_data->pa_ht);
1005 $pa_ht = $marginInfos[0];
1007 $updateRes = $this->invoice->addline(
1008 $request_data->desc,
1009 $request_data->subprice,
1011 $request_data->tva_tx,
1012 $request_data->localtax1_tx,
1013 $request_data->localtax2_tx,
1014 $request_data->fk_product,
1015 $request_data->remise_percent,
1016 $request_data->date_start,
1017 $request_data->date_end,
1018 $request_data->fk_code_ventilation,
1019 $request_data->info_bits,
1020 $request_data->fk_remise_except,
1021 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
1022 $request_data->subprice,
1023 $request_data->product_type,
1024 $request_data->rang,
1025 $request_data->special_code,
1026 $request_data->origin,
1027 $request_data->origin_id,
1028 $request_data->fk_parent_line,
1029 empty($request_data->fk_fournprice) ? null : $request_data->fk_fournprice,
1031 $request_data->label,
1032 $request_data->array_options,
1033 $request_data->situation_percent,
1034 $request_data->fk_prev_id,
1035 $request_data->fk_unit,
1037 $request_data->ref_ext
1040 if ($updateRes < 0) {
1041 throw new RestException(400,
'Unable to insert the new line. Check your inputs. '.$this->invoice->error);
1065 public function addContact(
$id, $fk_socpeople, $type_contact, $source, $notrigger = 0)
1067 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1068 throw new RestException(403);
1070 $result = $this->invoice->fetch(
$id);
1072 throw new RestException(404,
'Invoice not found');
1076 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1079 $result = $this->invoice->add_contact($fk_socpeople, $type_contact, $source, $notrigger);
1081 throw new RestException(500,
'Error : '.$this->invoice->error);
1084 $result = $this->invoice->fetch(
$id);
1086 throw new RestException(404,
'Invoice not found');
1115 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1116 throw new RestException(403);
1118 $result = $this->invoice->fetch(
$id);
1120 throw new RestException(404,
'Invoice not found');
1124 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1127 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1129 throw new RestException(304,
'Nothing done.');
1132 throw new RestException(500,
'Error : '.$this->invoice->error);
1135 $result = $this->invoice->fetch(
$id);
1137 throw new RestException(404,
'Invoice not found');
1161 public function validate(
$id, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1163 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1164 throw new RestException(403);
1166 $result = $this->invoice->fetch(
$id);
1168 throw new RestException(404,
'Invoice not found');
1172 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1175 $result = $this->invoice->validate(DolibarrApiAccess::$user, $force_number, $idwarehouse, $notrigger);
1177 throw new RestException(304,
'Error nothing done. May be object is already validated');
1180 throw new RestException(500,
'Error when validating Invoice: '.$this->invoice->error);
1183 $result = $this->invoice->fetch(
$id);
1185 throw new RestException(404,
'Invoice not found');
1194 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1195 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', $this->invoice->ref);
1217 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1218 throw new RestException(403);
1220 $result = $this->invoice->fetch(
$id);
1222 throw new RestException(404,
'Invoice not found');
1226 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1229 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
1231 throw new RestException(304,
'Error nothing done. May be object is already validated');
1234 throw new RestException(500,
'Error : '.$this->invoice->error);
1238 $result = $this->invoice->fetch(
$id);
1240 throw new RestException(404,
'Invoice not found');
1267 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1268 throw new RestException(403);
1270 $result = $this->invoice->fetch(
$id);
1272 throw new RestException(404,
'Invoice not found');
1276 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1279 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
1281 throw new RestException(304,
'Nothing done');
1284 throw new RestException(500,
'Error : '.$this->invoice->error);
1288 $result = $this->invoice->fetch(
$id);
1290 throw new RestException(404,
'Invoice not found');
1311 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1313 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1314 throw new RestException(403);
1317 $result = $this->invoice->fetch(
$id);
1319 throw new RestException(404,
'Invoice not found');
1323 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1327 $result = $discountcheck->fetch(0, $this->invoice->id);
1330 throw new RestException(404,
'Discount not found');
1333 throw new RestException(500, $discountcheck->error);
1336 return parent::_cleanObjectDatas($discountcheck);
1354 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1356 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1357 throw new RestException(403);
1360 $result = $this->invoice->fetch(
$id);
1362 throw new RestException(404,
'Invoice not found');
1366 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1369 if ($this->invoice->paye) {
1370 throw new RestException(500,
'Alreay paid');
1373 $this->invoice->fetch(
$id);
1374 $this->invoice->fetch_thirdparty();
1378 $result = $discountcheck->fetch(0, $this->invoice->id);
1390 $amount_ht = $amount_tva = $amount_ttc = array();
1391 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1393 @phan-var-force array<string,float> $amount_ht
1394 @phan-var-force array<string,float> $amount_tva
1395 @phan-var-force array<string,float> $amount_ttc
1396 @phan-var-force array<string,float> $multicurrency_amount_ht
1397 @phan-var-force array<string,float> $multicurrency_amount_tva
1398 @phan-var-force array<string,float> $multicurrency_amount_ttc
1403 foreach ($this->invoice->lines as $line) {
1404 if ($line->product_type < 9 && $line->total_ht != 0) {
1405 if (!array_key_exists($line->tva_tx, $amount_ht)) {
1406 $amount_ht[$line->tva_tx] = 0.0;
1407 $amount_tva[$line->tva_tx] = 0.0;
1408 $amount_ttc[$line->tva_tx] = 0.0;
1409 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
1410 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
1411 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
1414 $amount_ht[$line->tva_tx] += $line->total_ht;
1415 $amount_tva[$line->tva_tx] += $line->total_tva;
1416 $amount_ttc[$line->tva_tx] += $line->total_ttc;
1417 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
1418 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
1419 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
1427 $discount->description =
'(CREDIT_NOTE)';
1429 $discount->description =
'(DEPOSIT)';
1431 $discount->description =
'(EXCESS RECEIVED)';
1433 throw new RestException(500,
'Cant convert to reduc an Invoice of this type');
1436 $discount->fk_soc = $this->invoice->socid;
1437 $discount->socid = $this->invoice->socid;
1438 $discount->fk_facture_source = $this->invoice->id;
1446 $sql =
'SELECT SUM(pf.amount) as total_payments';
1447 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1448 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1449 $sql .=
' WHERE pf.fk_facture = '.((int) $this->invoice->id);
1450 $sql .=
' AND pf.fk_paiement = p.rowid';
1451 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1452 $resql = $this->db->query($sql);
1457 $res = $this->db->fetch_object($resql);
1458 $total_payments = $res->total_payments;
1461 $total_creditnote_and_deposit = 0;
1462 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1463 $sql .=
" re.description, re.fk_facture_source";
1464 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1465 $sql .=
" WHERE fk_facture = ".((int) $this->invoice->id);
1466 $resql = $this->db->query($sql);
1467 if (!empty($resql)) {
1468 while ($obj = $this->db->fetch_object($resql)) {
1469 $total_creditnote_and_deposit += $obj->amount_ttc;
1475 $discount->amount_ht = $discount->amount_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1476 $discount->total_ht = $discount->total_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1477 $discount->amount_tva = 0;
1478 $discount->total_tva = 0;
1479 $discount->tva_tx = 0;
1481 $result = $discount->create(DolibarrApiAccess::$user);
1487 foreach ($amount_ht as $tva_tx => $xxx) {
1488 $discount->amount_ht = abs($amount_ht[$tva_tx]);
1489 $discount->amount_tva = abs($amount_tva[$tva_tx]);
1490 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
1491 $discount->total_ht = abs($amount_ht[$tva_tx]);
1492 $discount->total_tva = abs($amount_tva[$tva_tx]);
1493 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
1494 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
1495 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
1496 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1497 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
1498 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
1499 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1500 $discount->tva_tx = abs((
float) $tva_tx);
1502 $result = $discount->create(DolibarrApiAccess::$user);
1510 if (empty($error)) {
1513 $result = $this->invoice->setPaid(DolibarrApiAccess::$user);
1515 $this->db->commit();
1517 $this->db->rollback();
1518 throw new RestException(500,
'Could not set paid');
1521 $this->db->commit();
1524 $this->db->rollback();
1525 throw new RestException(500,
'Discount creation error');
1550 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1551 throw new RestException(403);
1554 throw new RestException(400,
'Invoice ID is mandatory');
1556 if (empty($discountid)) {
1557 throw new RestException(400,
'Discount ID is mandatory');
1561 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1564 $result = $this->invoice->fetch(
$id);
1566 throw new RestException(404,
'Invoice not found');
1569 $result = $this->invoice->insert_discount($discountid);
1571 throw new RestException(405, $this->invoice->error);
1595 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1597 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1598 throw new RestException(403);
1601 throw new RestException(400,
'Invoice ID is mandatory');
1603 if (empty($discountid)) {
1604 throw new RestException(400,
'Credit ID is mandatory');
1608 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1611 $result = $discount->fetch($discountid);
1613 throw new RestException(404,
'Credit not found');
1616 $result = $discount->link_to_invoice(0,
$id);
1618 throw new RestException(405, $discount->error);
1641 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1642 throw new RestException(403);
1645 throw new RestException(400,
'Invoice ID is mandatory');
1649 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1652 $result = $this->invoice->fetch(
$id);
1654 throw new RestException(404,
'Invoice not found');
1657 $result = $this->invoice->getListOfPayments();
1658 if (!is_array($result) && $result < 0) {
1659 throw new RestException(405, $this->invoice->error);
1687 public function addPayment(
$id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'')
1689 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1691 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1692 throw new RestException(403);
1695 throw new RestException(400,
'Invoice ID is mandatory');
1699 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1703 if (empty($accountid)) {
1704 throw new RestException(400,
'Account ID is mandatory');
1708 if (empty($paymentid)) {
1709 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1713 $result = $this->invoice->fetch(
$id);
1715 throw new RestException(404,
'Invoice not found');
1719 $totalpaid = $this->invoice->getSommePaiement();
1720 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
1721 $totaldeposits = $this->invoice->getSumDepositsUsed();
1722 $resteapayer =
price2num($this->invoice->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1727 $multicurrency_amounts = array();
1731 $resteapayer =
price2num($resteapayer,
'MT');
1732 $amounts[
$id] = (float)
price2num(-1 * abs((
float) $resteapayer),
'MT');
1734 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1735 $multicurrency_amounts[
$id] = (float)
price2num(-1 * (
float) $newvalue,
'MT');
1737 $resteapayer =
price2num($resteapayer,
'MT');
1738 $amounts[
$id] = (float) $resteapayer;
1740 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1741 $multicurrency_amounts[
$id] = (float) $newvalue;
1745 $paymentobj =
new Paiement($this->db);
1746 if (is_numeric($datepaye)) {
1747 $paymentobj->datepaye = $datepaye;
1751 $paymentobj->amounts = $amounts;
1752 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1753 $paymentobj->paiementid = $paymentid;
1754 $paymentobj->paiementcode = (string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1755 $paymentobj->num_payment = $num_payment;
1756 $paymentobj->note_private = $comment;
1758 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1759 if ($payment_id < 0) {
1760 $this->db->rollback();
1761 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1765 $label =
'(CustomerInvoicePayment)';
1767 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1768 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1771 $label =
'(CustomerInvoicePaymentBack)';
1773 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1775 $this->db->rollback();
1776 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1780 $this->db->commit();
1813 public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'', $ref_ext =
'', $accepthigherpayment =
false)
1815 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1817 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1818 throw new RestException(403);
1820 foreach ($arrayofamounts as
$id => $amount) {
1822 throw new RestException(400,
'Invoice ID is mandatory. Fill the invoice id and amount into arrayofamounts parameter. For example: {"1": "99.99", "2": "10"}');
1825 throw new RestException(403,
'Access not allowed on invoice ID '.
$id.
' for login '.DolibarrApiAccess::$user->login);
1830 if (empty($accountid)) {
1831 throw new RestException(400,
'Account ID is mandatory');
1834 if (empty($paymentid)) {
1835 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1841 $multicurrency_amounts = array();
1844 foreach ($arrayofamounts as
$id => $amountarray) {
1845 $result = $this->invoice->fetch((
int)
$id);
1847 $this->db->rollback();
1848 throw new RestException(404,
'Invoice ID '.
$id.
' not found');
1851 if (($amountarray[
"amount"] ==
"remain" || $amountarray[
"amount"] > 0) && ($amountarray[
"multicurrency_amount"] ==
"remain" || $amountarray[
"multicurrency_amount"] > 0)) {
1852 $this->db->rollback();
1853 throw new RestException(400,
'Payment in both currency '.
$id.
' ( amount: '.$amountarray[
"amount"].
', multicurrency_amount: '.$amountarray[
"multicurrency_amount"].
')');
1856 $is_multicurrency = 0;
1857 $total_ttc = $this->invoice->total_ttc;
1859 if ($amountarray[
"multicurrency_amount"] > 0 || $amountarray[
"multicurrency_amount"] ==
"remain") {
1860 $is_multicurrency = 1;
1861 $total_ttc = $this->invoice->multicurrency_total_ttc;
1865 $totalpaid = $this->invoice->getSommePaiement($is_multicurrency);
1866 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency);
1867 $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
1868 $remainstopay = $amount = (float)
price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1870 if (!$is_multicurrency && $amountarray[
"amount"] !=
'remain') {
1871 $amount = (float)
price2num($amountarray[
"amount"],
'MT');
1874 if ($is_multicurrency && $amountarray[
"multicurrency_amount"] !=
'remain') {
1875 $amount = (float)
price2num($amountarray[
"multicurrency_amount"],
'MT');
1878 if (abs($amount) > abs($remainstopay) && !$accepthigherpayment) {
1879 $this->db->rollback();
1880 throw new RestException(400,
'Payment amount on invoice ID '.
$id.
' ('.$amount.
') is higher than remain to pay ('.$remainstopay.
')');
1884 $amount = (float)
price2num(-1 * abs((
float) $amount),
'MT');
1887 if ($is_multicurrency) {
1888 $amounts[
$id] =
null;
1890 $multicurrency_amounts[
$id] = (float) $amount;
1892 $amounts[
$id] = (float) $amount;
1894 $multicurrency_amounts[
$id] =
null;
1899 $paymentobj =
new Paiement($this->db);
1900 if (is_numeric($datepaye)) {
1901 $paymentobj->datepaye = $datepaye;
1905 $paymentobj->amounts = $amounts;
1906 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1907 $paymentobj->paiementid = $paymentid;
1908 $paymentobj->paiementcode = (string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1909 $paymentobj->num_payment = $num_payment;
1910 $paymentobj->note_private = $comment;
1911 $paymentobj->ref_ext = $ref_ext;
1912 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1913 if ($payment_id < 0) {
1914 $this->db->rollback();
1915 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1918 $label =
'(CustomerInvoicePayment)';
1919 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1920 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1923 $label =
'(CustomerInvoicePaymentBack)';
1925 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1927 $this->db->rollback();
1928 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1932 $this->db->commit();
1955 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1957 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1958 throw new RestException(403);
1961 throw new RestException(400,
'Payment ID is mandatory');
1964 $paymentobj =
new Paiement($this->db);
1965 $result = $paymentobj->fetch(
$id);
1968 throw new RestException(404,
'Payment not found');
1971 if (!empty($num_payment)) {
1972 $result = $paymentobj->update_num($num_payment);
1974 throw new RestException(500,
'Error when updating the payment num');
1981 'message' =>
'Payment updated'
2004 unset(
$object->barcode_type_code);
2005 unset(
$object->barcode_type_label);
2006 unset(
$object->barcode_type_coder);
2022 if ($data ===
null) {
2026 foreach (Invoices::$FIELDS as $field) {
2027 if (!isset($data[$field])) {
2028 throw new RestException(400,
"$field field missing");
2030 $invoice[$field] = $data[$field];
2080 public function indexTemplateInvoices($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
2082 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2083 throw new RestException(403);
2089 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
2094 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
2095 $search_sale = DolibarrApiAccess::$user->id;
2098 $sql =
"SELECT t.rowid";
2099 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_rec AS t";
2100 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
2101 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_rec_extrafields AS ef ON (ef.fk_object = t.rowid)";
2102 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
2104 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
2108 if ($search_sale && $search_sale !=
'-1') {
2109 if ($search_sale == -2) {
2110 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux AS sc WHERE sc.fk_soc = t.fk_soc)";
2111 } elseif ($search_sale > 0) {
2112 $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).
")";
2117 if ($status ==
'active') {
2118 $sql .=
" AND t.suspended = 0 AND t.frequency IS NOT NULL";
2120 if ($status ==
'suspended') {
2121 $sql .=
" AND t.suspended = 1 AND t.frequency IS NOT NULL";
2123 if ($status ==
'draft') {
2124 $sql .=
" AND t.frequency IS NULL";
2130 if ($errormessage) {
2131 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2136 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
2138 $sql .= $this->db->order($sortfield, $sortorder);
2143 $offset = $limit * $page;
2145 $sql .= $this->db->plimit($limit + 1, $offset);
2148 $result = $this->db->query($sql);
2151 $num = $this->db->num_rows($result);
2152 $min = min($num, ($limit <= 0 ? $num : $limit));
2154 $obj = $this->db->fetch_object($result);
2156 if ($factureRec->fetch($obj->rowid) > 0) {
2157 if ($loadlinkedobjects) {
2159 $factureRec->fetchObjectLinked();
2163 unset($factureRec->lines);
2171 throw new RestException(503,
'Error when retrieving recurring invoice templates: '.$this->db->lasterror());
2175 if ($pagination_data) {
2176 $totalsResult = $this->db->query($sqlTotals);
2177 $total = $this->db->fetch_object($totalsResult)->total;
2182 $obj_ret[
'data'] = $tmp;
2183 $obj_ret[
'pagination'] = array(
2184 'total' => (
int) $total,
2186 'page_count' => ceil((
int) $total / $limit),
2209 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2210 throw new RestException(403);
2213 $result = $this->template_invoice->fetch(
$id, $ref, $ref_ext);
2215 throw new RestException(404,
'Template invoice not found');
2219 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2223 if ($contact_list > -1) {
2224 $tmparray = $this->template_invoice->liste_contact(-1,
'external', $contact_list);
2225 if (is_array($tmparray)) {
2226 $this->template_invoice->contacts_ids = $tmparray;
2230 $this->template_invoice->fetchObjectLinked();
2250 unset(
$object->barcode_type_code);
2251 unset(
$object->barcode_type_label);
2252 unset(
$object->barcode_type_coder);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
Class to manage customers orders.
Class to manage absolute discounts.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice templates.
putPayment($id, $num_payment='')
Update a payment.
addContact($id, $fk_socpeople, $type_contact, $source, $notrigger=0)
Adds a contact to an invoice.
indexTemplateInvoices($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='', $properties='', $pagination_data=false, $loadlinkedobjects=0, $withLines=true)
List template invoices.
createInvoiceFromOrder($orderid)
Create an invoice using an existing order.
markAsCreditAvailable($id)
Create a discount (credit available) for a credit note or a deposit.
getDiscount($id)
Get discount from invoice.
__construct()
Constructor.
put($id, $request_data=null)
Update invoice.
validate($id, $force_number='', $idwarehouse=0, $notrigger=0)
Validate an invoice.
getContacts($id, $type='')
Get contacts of given invoice.
getByRefExt($ref_ext, $contact_list=1)
Get properties of an invoice object by ref_ext.
_fetch($id, $ref='', $ref_ext='', $contact_list=1)
Get properties of an invoice object.
getByRef($ref, $contact_list=1)
Get properties of an invoice object by ref.
getPayments($id)
Get list of payments of a given invoice.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
post($request_data=null)
Create invoice object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='', $properties='', $pagination_data=false, $loadlinkedobjects=0, $withLines=true)
List invoices.
useDiscount($id, $discountid)
Add a discount line into an invoice (as an invoice line) using an existing absolute discount.
settounpaid($id)
Sets an invoice as unpaid.
getTemplateInvoice($id, $contact_list=1)
Get properties of a template invoice object.
putLine($id, $lineid, $request_data=null)
Update a line to a given invoice.
getLines($id)
Get lines of an invoice.
useCreditNote($id, $discountid)
Add an available credit note discount to payments of an existing invoice.
createInvoiceFromContract($contractid)
Create an invoice using a contract.
addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='', $ref_ext='', $accepthigherpayment=false)
Add a payment to pay partially or completely one or several invoices.
postContact($id, $contactid, $type, $source='external', $notrigger=0)
Add a contact type of given invoice.
_cleanTemplateObjectDatas($object)
Clean sensible object datas.
deleteContact($id, $contactid, $type)
Delete a contact type of given invoice.
postLine($id, $request_data=null)
Add a line to a given invoice.
_fetchTemplateInvoice($id, $ref='', $ref_ext='', $contact_list=1)
Get properties of an invoice object.
_validate($data)
Validate fields before create or update object.
addPayment($id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='')
Add payment line to a specific invoice with the remain to pay as amount.
settopaid($id, $close_code='', $close_note='')
Sets an invoice as paid.
settodraft($id, $idwarehouse=-1)
Sets an invoice as draft.
deleteLine($id, $lineid)
Deletes a line of a given invoice.
Class to manage payments of customer invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
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)
forgeSQLFromUniversalSearchCriteria
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.