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');
448 throw new RestException(405,
'Order '.$order->ref.
' is not eligible for invoicing: its status does not allow creating an invoice');
451 $result = $this->invoice->createFromOrder($order, DolibarrApiAccess::$user);
453 throw new RestException(405, $this->invoice->error);
455 $this->invoice->fetchObjectLinked();
474 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
476 if (!DolibarrApiAccess::$user->hasRight(
'contrat',
'lire')) {
477 throw new RestException(403);
479 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
480 throw new RestException(403);
482 if (empty($contractid)) {
483 throw new RestException(400,
'Contract ID is mandatory');
486 $contract =
new Contrat($this->db);
487 $result = $contract->fetch($contractid);
489 throw new RestException(404,
'Contract not found');
492 $result = $this->invoice->createFromContract($contract, DolibarrApiAccess::$user);
494 throw new RestException(405, $this->invoice->error);
496 $this->invoice->fetchObjectLinked();
512 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
513 throw new RestException(403);
516 $result = $this->invoice->fetch(
$id);
518 throw new RestException(404,
'Invoice not found');
522 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
524 $this->invoice->getLinesArray();
526 foreach ($this->invoice->lines as $line) {
550 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
551 throw new RestException(403);
554 $result = $this->invoice->fetch(
$id);
556 throw new RestException(404,
'Invoice not found');
560 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
563 $request_data = (object) $request_data;
565 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
566 $request_data->label =
sanitizeVal($request_data->label);
568 $updateRes = $this->invoice->updateline(
571 $request_data->subprice,
573 $request_data->remise_percent,
574 $request_data->date_start,
575 $request_data->date_end,
576 $request_data->tva_tx,
577 $request_data->localtax1_tx,
578 $request_data->localtax2_tx,
579 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
580 $request_data->info_bits,
581 $request_data->product_type,
582 $request_data->fk_parent_line,
584 $request_data->fk_fournprice,
585 $request_data->pa_ht,
586 $request_data->label,
587 $request_data->special_code,
588 $request_data->array_options,
589 $request_data->situation_percent,
590 $request_data->fk_unit,
591 $request_data->multicurrency_subprice,
593 $request_data->ref_ext,
597 if ($updateRes > 0) {
598 $result = $this->
get(
$id);
599 unset($result->line);
602 throw new RestException(304, $this->invoice->error);
623 public function postContact(
$id, $contactid, $type, $source =
'external', $notrigger = 0)
625 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
626 throw new RestException(403);
630 if (empty($source)) {
631 throw new RestException(400,
'Source can not be empty');
633 $sql_distinct_source =
"SELECT DISTINCT source";
634 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
635 $sql_distinct_source .=
" WHERE element LIKE 'facture'";
636 $sql_distinct_source .=
" AND source is NOT NULL";
637 $sql_distinct_source .=
" AND active != 0";
638 $source_result = $this->db->query($sql_distinct_source);
639 $source_array = array();
641 if ($source_result) {
642 $num = $this->db->num_rows($source_result);
645 $obj = $this->db->fetch_object($source_result);
646 $source_kind = (string) $obj->source;
647 array_push($source_array, $source_kind);
652 throw new RestException(503,
'Error when retrieving a list of invoice contact sources: '.$this->db->lasterror());
654 if (!in_array($source, (array) $source_array,
true)) {
655 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active invoice contact types');
660 throw new RestException(400,
'type can not be empty');
663 $sql_distinct_type =
"SELECT DISTINCT code";
664 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
665 $sql_distinct_type .=
" WHERE element LIKE 'facture'";
666 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
667 $sql_distinct_type .=
" AND code is NOT NULL";
668 $sql_distinct_type .=
" AND active != 0";
669 $type_result = $this->db->query($sql_distinct_type);
670 $type_array = array();
673 $num = $this->db->num_rows($type_result);
676 $obj = $this->db->fetch_object($type_result);
678 $type_kind = (string) $obj->code;
679 array_push($type_array, $type_kind);
684 throw new RestException(503,
'Error when retrieving a list of invoice contact types: '.$this->db->lasterror());
686 if (!in_array($type, (array) $type_array,
true)) {
687 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active invoice contact types');
691 $result = $this->invoice->fetch(
$id);
693 throw new RestException(404,
'Invoice not found');
696 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
699 $result = $this->invoice->add_contact($contactid, $type, $source, $notrigger);
702 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the invoice='.
$id.
' as source='.$source.
' and type='.$type);
703 } elseif ($result == -1) {
704 throw new RestException(400,
'Wrong contact='.$contactid);
705 } elseif ($result == -2) {
706 throw new RestException(400,
'Wrong type='.$type);
707 } elseif ($result == -3) {
708 throw new RestException(400,
'Not allowed contacts');
709 } elseif ($result == -4) {
710 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
711 } elseif ($result == -5) {
712 throw new RestException(400,
'Trigger failed');
713 } elseif ($result == -6) {
714 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
715 } elseif ($result == -7) {
716 throw new RestException(400,
'Some other error');
720 throw new RestException(500,
'Error when added the contact');
726 'message' =>
'Contact='.$contactid.
' linked to the invoice='.
$id.
' as '.$source.
' '.$type
746 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
747 throw new RestException(403);
750 $result = $this->invoice->fetch(
$id);
752 throw new RestException(404,
'Invoice not found');
756 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
759 $contacts = $this->invoice->liste_contact(-1,
'external', 0, $type);
760 $socpeoples = $this->invoice->liste_contact(-1,
'internal', 0, $type);
762 $contacts = array_merge($contacts, $socpeoples);
783 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
784 throw new RestException(403);
787 $result = $this->invoice->fetch(
$id);
790 throw new RestException(404,
'Invoice not found');
794 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
797 $contacts = $this->invoice->liste_contact();
799 foreach ($contacts as $contact) {
800 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
801 $result = $this->invoice->delete_contact($contact[
'rowid']);
804 throw new RestException(500,
'Error when deleted the contact');
828 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
829 throw new RestException(403);
831 if (empty($lineid)) {
832 throw new RestException(400,
'Line ID is mandatory');
836 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
839 $result = $this->invoice->fetch(
$id);
841 throw new RestException(404,
'Invoice not found');
843 if ($this->invoice->status != 0) {
844 throw new RestException(403,
'Invoice not in Draft Status : '.$this->invoice->getLibStatut(1));
847 $updateRes = $this->invoice->deleteLine($lineid,
$id);
848 if ($updateRes > 0) {
849 return $this->
get(
$id);
851 throw new RestException(405, $this->invoice->error);
864 public function put(
$id, $request_data =
null)
866 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
867 throw new RestException(403);
870 throw new RestException(400,
'No invoice with id=0 can exist');
872 $result = $this->invoice->fetch(
$id);
874 throw new RestException(404,
'Invoice not found');
878 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
881 foreach ($request_data as $field => $value) {
882 if ($field ==
'id') {
885 if ($field ===
'caller') {
887 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
890 if ($field ==
'array_options' && is_array($value)) {
891 foreach ($value as $index => $val) {
892 $this->invoice->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->invoice);
897 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
900 if ($field ==
'cond_reglement_id') {
901 $this->invoice->date_lim_reglement = $this->invoice->calculate_date_lim_reglement();
906 if (!empty($this->invoice->fk_account)) {
907 if ($this->invoice->setBankAccount($this->invoice->fk_account) == 0) {
908 throw new RestException(400, $this->invoice->error);
912 if ($this->invoice->update(DolibarrApiAccess::$user) > 0) {
913 return $this->
get(
$id);
915 throw new RestException(500, $this->invoice->error);
927 public function delete(
$id)
929 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'supprimer')) {
930 throw new RestException(403);
933 throw new RestException(400,
'No invoice with id=0 can exist');
935 $result = $this->invoice->fetch(
$id);
937 throw new RestException(404,
'Invoice not found');
941 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
944 $result = $this->invoice->delete(DolibarrApiAccess::$user);
946 throw new RestException(500,
'Error when deleting invoice');
947 } elseif ($result == 0) {
948 throw new RestException(403,
'Invoice not erasable');
954 'message' =>
'Invoice deleted'
986 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
987 throw new RestException(403);
990 $result = $this->invoice->fetch(
$id);
992 throw new RestException(404,
'Invoice not found');
996 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
999 $request_data = (object) $request_data;
1001 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
1002 $request_data->label =
sanitizeVal($request_data->label);
1005 if (($request_data->product_type != 9 && empty($request_data->fk_parent_line)) || $request_data->product_type == 9) {
1006 $request_data->fk_parent_line = 0;
1010 $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);
1011 $pa_ht = $marginInfos[0];
1013 $updateRes = $this->invoice->addline(
1014 $request_data->desc,
1015 $request_data->subprice,
1017 $request_data->tva_tx,
1018 $request_data->localtax1_tx,
1019 $request_data->localtax2_tx,
1020 $request_data->fk_product,
1021 $request_data->remise_percent,
1022 $request_data->date_start,
1023 $request_data->date_end,
1024 $request_data->fk_code_ventilation,
1025 $request_data->info_bits,
1026 $request_data->fk_remise_except,
1027 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
1028 $request_data->subprice,
1029 $request_data->product_type,
1030 $request_data->rang,
1031 $request_data->special_code,
1032 $request_data->origin,
1033 $request_data->origin_id,
1034 $request_data->fk_parent_line,
1035 empty($request_data->fk_fournprice) ? null : $request_data->fk_fournprice,
1037 $request_data->label,
1038 $request_data->array_options,
1039 $request_data->situation_percent,
1040 $request_data->fk_prev_id,
1041 $request_data->fk_unit,
1043 $request_data->ref_ext
1046 if ($updateRes < 0) {
1047 throw new RestException(400,
'Unable to insert the new line. Check your inputs. '.$this->invoice->error);
1071 public function addContact(
$id, $fk_socpeople, $type_contact, $source, $notrigger = 0)
1073 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1074 throw new RestException(403);
1076 $result = $this->invoice->fetch(
$id);
1078 throw new RestException(404,
'Invoice not found');
1082 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1085 $result = $this->invoice->add_contact($fk_socpeople, $type_contact, $source, $notrigger);
1087 throw new RestException(500,
'Error : '.$this->invoice->error);
1090 $result = $this->invoice->fetch(
$id);
1092 throw new RestException(404,
'Invoice not found');
1121 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1122 throw new RestException(403);
1124 $result = $this->invoice->fetch(
$id);
1126 throw new RestException(404,
'Invoice not found');
1130 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1133 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1135 throw new RestException(304,
'Nothing done.');
1138 throw new RestException(500,
'Error : '.$this->invoice->error);
1141 $result = $this->invoice->fetch(
$id);
1143 throw new RestException(404,
'Invoice not found');
1167 public function validate(
$id, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1169 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1170 throw new RestException(403);
1172 $result = $this->invoice->fetch(
$id);
1174 throw new RestException(404,
'Invoice not found');
1178 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1181 $result = $this->invoice->validate(DolibarrApiAccess::$user, $force_number, $idwarehouse, $notrigger);
1183 throw new RestException(304,
'Error nothing done. May be object is already validated');
1186 throw new RestException(500,
'Error when validating Invoice: '.$this->invoice->error);
1189 $result = $this->invoice->fetch(
$id);
1191 throw new RestException(404,
'Invoice not found');
1200 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1201 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', $this->invoice->ref);
1223 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1224 throw new RestException(403);
1226 $result = $this->invoice->fetch(
$id);
1228 throw new RestException(404,
'Invoice not found');
1232 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1235 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
1237 throw new RestException(304,
'Error nothing done. May be object is already validated');
1240 throw new RestException(500,
'Error : '.$this->invoice->error);
1244 $result = $this->invoice->fetch(
$id);
1246 throw new RestException(404,
'Invoice not found');
1273 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1274 throw new RestException(403);
1276 $result = $this->invoice->fetch(
$id);
1278 throw new RestException(404,
'Invoice not found');
1282 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1285 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
1287 throw new RestException(304,
'Nothing done');
1290 throw new RestException(500,
'Error : '.$this->invoice->error);
1294 $result = $this->invoice->fetch(
$id);
1296 throw new RestException(404,
'Invoice not found');
1317 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1319 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1320 throw new RestException(403);
1323 $result = $this->invoice->fetch(
$id);
1325 throw new RestException(404,
'Invoice not found');
1329 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1333 $result = $discountcheck->fetch(0, $this->invoice->id);
1336 throw new RestException(404,
'Discount not found');
1339 throw new RestException(500, $discountcheck->error);
1342 return parent::_cleanObjectDatas($discountcheck);
1360 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1362 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1363 throw new RestException(403);
1366 $result = $this->invoice->fetch(
$id);
1368 throw new RestException(404,
'Invoice not found');
1372 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1375 if ($this->invoice->paye) {
1376 throw new RestException(500,
'Alreay paid');
1379 $this->invoice->fetch(
$id);
1380 $this->invoice->fetch_thirdparty();
1384 $result = $discountcheck->fetch(0, $this->invoice->id);
1396 $amount_ht = $amount_tva = $amount_ttc = array();
1397 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1399 @phan-var-force array<string,float> $amount_ht
1400 @phan-var-force array<string,float> $amount_tva
1401 @phan-var-force array<string,float> $amount_ttc
1402 @phan-var-force array<string,float> $multicurrency_amount_ht
1403 @phan-var-force array<string,float> $multicurrency_amount_tva
1404 @phan-var-force array<string,float> $multicurrency_amount_ttc
1409 foreach ($this->invoice->lines as $line) {
1410 if ($line->product_type < 9 && $line->total_ht != 0) {
1411 if (!array_key_exists($line->tva_tx, $amount_ht)) {
1412 $amount_ht[$line->tva_tx] = 0.0;
1413 $amount_tva[$line->tva_tx] = 0.0;
1414 $amount_ttc[$line->tva_tx] = 0.0;
1415 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
1416 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
1417 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
1420 $amount_ht[$line->tva_tx] += $line->total_ht;
1421 $amount_tva[$line->tva_tx] += $line->total_tva;
1422 $amount_ttc[$line->tva_tx] += $line->total_ttc;
1423 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
1424 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
1425 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
1433 $discount->description =
'(CREDIT_NOTE)';
1435 $discount->description =
'(DEPOSIT)';
1437 $discount->description =
'(EXCESS RECEIVED)';
1439 throw new RestException(500,
'Cant convert to reduc an Invoice of this type');
1442 $discount->fk_soc = $this->invoice->socid;
1443 $discount->socid = $this->invoice->socid;
1444 $discount->fk_facture_source = $this->invoice->id;
1452 $sql =
'SELECT SUM(pf.amount) as total_payments';
1453 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1454 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1455 $sql .=
' WHERE pf.fk_facture = '.((int) $this->invoice->id);
1456 $sql .=
' AND pf.fk_paiement = p.rowid';
1457 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1458 $resql = $this->db->query($sql);
1463 $res = $this->db->fetch_object($resql);
1464 $total_payments = $res->total_payments;
1467 $total_creditnote_and_deposit = 0;
1468 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1469 $sql .=
" re.description, re.fk_facture_source";
1470 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1471 $sql .=
" WHERE fk_facture = ".((int) $this->invoice->id);
1472 $resql = $this->db->query($sql);
1473 if (!empty($resql)) {
1474 while ($obj = $this->db->fetch_object($resql)) {
1475 $total_creditnote_and_deposit += $obj->amount_ttc;
1481 $discount->amount_ht = $discount->amount_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1482 $discount->total_ht = $discount->total_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1483 $discount->amount_tva = 0;
1484 $discount->total_tva = 0;
1485 $discount->tva_tx = 0;
1487 $result = $discount->create(DolibarrApiAccess::$user);
1493 foreach ($amount_ht as $tva_tx => $xxx) {
1494 $discount->amount_ht = abs($amount_ht[$tva_tx]);
1495 $discount->amount_tva = abs($amount_tva[$tva_tx]);
1496 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
1497 $discount->total_ht = abs($amount_ht[$tva_tx]);
1498 $discount->total_tva = abs($amount_tva[$tva_tx]);
1499 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
1500 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
1501 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
1502 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1503 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
1504 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
1505 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1506 $discount->tva_tx = abs((
float) $tva_tx);
1508 $result = $discount->create(DolibarrApiAccess::$user);
1516 if (empty($error)) {
1519 $result = $this->invoice->setPaid(DolibarrApiAccess::$user);
1521 $this->db->commit();
1523 $this->db->rollback();
1524 throw new RestException(500,
'Could not set paid');
1527 $this->db->commit();
1530 $this->db->rollback();
1531 throw new RestException(500,
'Discount creation error');
1556 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1557 throw new RestException(403);
1560 throw new RestException(400,
'Invoice ID is mandatory');
1562 if (empty($discountid)) {
1563 throw new RestException(400,
'Discount ID is mandatory');
1567 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1570 $result = $this->invoice->fetch(
$id);
1572 throw new RestException(404,
'Invoice not found');
1575 $result = $this->invoice->insert_discount($discountid);
1577 throw new RestException(405, $this->invoice->error);
1601 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1603 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1604 throw new RestException(403);
1607 throw new RestException(400,
'Invoice ID is mandatory');
1609 if (empty($discountid)) {
1610 throw new RestException(400,
'Credit ID is mandatory');
1614 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1617 $result = $discount->fetch($discountid);
1619 throw new RestException(404,
'Credit not found');
1622 $result = $discount->link_to_invoice(0,
$id);
1624 throw new RestException(405, $discount->error);
1647 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1648 throw new RestException(403);
1651 throw new RestException(400,
'Invoice ID is mandatory');
1655 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1658 $result = $this->invoice->fetch(
$id);
1660 throw new RestException(404,
'Invoice not found');
1663 $result = $this->invoice->getListOfPayments();
1664 if (!is_array($result) && $result < 0) {
1665 throw new RestException(405, $this->invoice->error);
1693 public function addPayment(
$id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'')
1695 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1697 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1698 throw new RestException(403);
1701 throw new RestException(400,
'Invoice ID is mandatory');
1705 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1709 if (empty($accountid)) {
1710 throw new RestException(400,
'Account ID is mandatory');
1714 if (empty($paymentid)) {
1715 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1719 $result = $this->invoice->fetch(
$id);
1721 throw new RestException(404,
'Invoice not found');
1725 $totalpaid = $this->invoice->getSommePaiement();
1726 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
1727 $totaldeposits = $this->invoice->getSumDepositsUsed();
1728 $resteapayer =
price2num($this->invoice->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1733 $multicurrency_amounts = array();
1737 $resteapayer =
price2num($resteapayer,
'MT');
1738 $amounts[
$id] = (float)
price2num(-1 * abs((
float) $resteapayer),
'MT');
1740 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1741 $multicurrency_amounts[
$id] = (float)
price2num(-1 * (
float) $newvalue,
'MT');
1743 $resteapayer =
price2num($resteapayer,
'MT');
1744 $amounts[
$id] = (float) $resteapayer;
1746 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1747 $multicurrency_amounts[
$id] = (float) $newvalue;
1751 $paymentobj =
new Paiement($this->db);
1752 if (is_numeric($datepaye)) {
1753 $paymentobj->datepaye = $datepaye;
1757 $paymentobj->amounts = $amounts;
1758 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1759 $paymentobj->paiementid = $paymentid;
1760 $paymentobj->paiementcode = (string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1761 $paymentobj->num_payment = $num_payment;
1762 $paymentobj->note_private = $comment;
1764 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1765 if ($payment_id < 0) {
1766 $this->db->rollback();
1767 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1771 $label =
'(CustomerInvoicePayment)';
1773 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1774 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1777 $label =
'(CustomerInvoicePaymentBack)';
1779 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1781 $this->db->rollback();
1782 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1786 $this->db->commit();
1819 public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'', $ref_ext =
'', $accepthigherpayment =
false)
1821 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1823 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1824 throw new RestException(403);
1826 foreach ($arrayofamounts as
$id => $amount) {
1828 throw new RestException(400,
'Invoice ID is mandatory. Fill the invoice id and amount into arrayofamounts parameter. For example: {"1": "99.99", "2": "10"}');
1831 throw new RestException(403,
'Access not allowed on invoice ID '.
$id.
' for login '.DolibarrApiAccess::$user->login);
1836 if (empty($accountid)) {
1837 throw new RestException(400,
'Account ID is mandatory');
1840 if (empty($paymentid)) {
1841 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1847 $multicurrency_amounts = array();
1850 foreach ($arrayofamounts as
$id => $amountarray) {
1851 $result = $this->invoice->fetch((
int)
$id);
1853 $this->db->rollback();
1854 throw new RestException(404,
'Invoice ID '.
$id.
' not found');
1857 if (($amountarray[
"amount"] ==
"remain" || $amountarray[
"amount"] > 0) && ($amountarray[
"multicurrency_amount"] ==
"remain" || $amountarray[
"multicurrency_amount"] > 0)) {
1858 $this->db->rollback();
1859 throw new RestException(400,
'Payment in both currency '.
$id.
' ( amount: '.$amountarray[
"amount"].
', multicurrency_amount: '.$amountarray[
"multicurrency_amount"].
')');
1862 $is_multicurrency = 0;
1863 $total_ttc = $this->invoice->total_ttc;
1865 if ($amountarray[
"multicurrency_amount"] > 0 || $amountarray[
"multicurrency_amount"] ==
"remain") {
1866 $is_multicurrency = 1;
1867 $total_ttc = $this->invoice->multicurrency_total_ttc;
1871 $totalpaid = $this->invoice->getSommePaiement($is_multicurrency);
1872 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency);
1873 $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
1874 $remainstopay = $amount = (float)
price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1876 if (!$is_multicurrency && $amountarray[
"amount"] !=
'remain') {
1877 $amount = (float)
price2num($amountarray[
"amount"],
'MT');
1880 if ($is_multicurrency && $amountarray[
"multicurrency_amount"] !=
'remain') {
1881 $amount = (float)
price2num($amountarray[
"multicurrency_amount"],
'MT');
1884 if (abs($amount) > abs($remainstopay) && !$accepthigherpayment) {
1885 $this->db->rollback();
1886 throw new RestException(400,
'Payment amount on invoice ID '.
$id.
' ('.$amount.
') is higher than remain to pay ('.$remainstopay.
')');
1890 $amount = (float)
price2num(-1 * abs((
float) $amount),
'MT');
1893 if ($is_multicurrency) {
1894 $amounts[
$id] =
null;
1896 $multicurrency_amounts[
$id] = (float) $amount;
1898 $amounts[
$id] = (float) $amount;
1900 $multicurrency_amounts[
$id] =
null;
1905 $paymentobj =
new Paiement($this->db);
1906 if (is_numeric($datepaye)) {
1907 $paymentobj->datepaye = $datepaye;
1911 $paymentobj->amounts = $amounts;
1912 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1913 $paymentobj->paiementid = $paymentid;
1914 $paymentobj->paiementcode = (string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1915 $paymentobj->num_payment = $num_payment;
1916 $paymentobj->note_private = $comment;
1917 $paymentobj->ref_ext = $ref_ext;
1918 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1919 if ($payment_id < 0) {
1920 $this->db->rollback();
1921 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1924 $label =
'(CustomerInvoicePayment)';
1925 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1926 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1929 $label =
'(CustomerInvoicePaymentBack)';
1931 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1933 $this->db->rollback();
1934 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1938 $this->db->commit();
1961 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1963 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1964 throw new RestException(403);
1967 throw new RestException(400,
'Payment ID is mandatory');
1970 $paymentobj =
new Paiement($this->db);
1971 $result = $paymentobj->fetch(
$id);
1974 throw new RestException(404,
'Payment not found');
1977 if (!empty($num_payment)) {
1978 $result = $paymentobj->update_num($num_payment);
1980 throw new RestException(500,
'Error when updating the payment num');
1987 'message' =>
'Payment updated'
2010 unset(
$object->barcode_type_code);
2011 unset(
$object->barcode_type_label);
2012 unset(
$object->barcode_type_coder);
2028 if ($data ===
null) {
2032 foreach (Invoices::$FIELDS as $field) {
2033 if (!isset($data[$field])) {
2034 throw new RestException(400,
"$field field missing");
2036 $invoice[$field] = $data[$field];
2086 public function indexTemplateInvoices($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
2088 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2089 throw new RestException(403);
2095 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
2100 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
2101 $search_sale = DolibarrApiAccess::$user->id;
2104 $sql =
"SELECT t.rowid";
2105 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_rec AS t";
2106 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
2107 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_rec_extrafields AS ef ON (ef.fk_object = t.rowid)";
2108 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
2110 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
2114 if ($search_sale && $search_sale !=
'-1') {
2115 if ($search_sale == -2) {
2116 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux AS sc WHERE sc.fk_soc = t.fk_soc)";
2117 } elseif ($search_sale > 0) {
2118 $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).
")";
2123 if ($status ==
'active') {
2124 $sql .=
" AND t.suspended = 0 AND t.frequency IS NOT NULL";
2126 if ($status ==
'suspended') {
2127 $sql .=
" AND t.suspended = 1 AND t.frequency IS NOT NULL";
2129 if ($status ==
'draft') {
2130 $sql .=
" AND t.frequency IS NULL";
2136 if ($errormessage) {
2137 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2142 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
2144 $sql .= $this->db->order($sortfield, $sortorder);
2149 $offset = $limit * $page;
2151 $sql .= $this->db->plimit($limit + 1, $offset);
2154 $result = $this->db->query($sql);
2157 $num = $this->db->num_rows($result);
2158 $min = min($num, ($limit <= 0 ? $num : $limit));
2160 $obj = $this->db->fetch_object($result);
2162 if ($factureRec->fetch($obj->rowid) > 0) {
2163 if ($loadlinkedobjects) {
2165 $factureRec->fetchObjectLinked();
2169 unset($factureRec->lines);
2177 throw new RestException(503,
'Error when retrieving recurring invoice templates: '.$this->db->lasterror());
2181 if ($pagination_data) {
2182 $totalsResult = $this->db->query($sqlTotals);
2183 $total = $this->db->fetch_object($totalsResult)->total;
2188 $obj_ret[
'data'] = $tmp;
2189 $obj_ret[
'pagination'] = array(
2190 'total' => (
int) $total,
2192 'page_count' => ceil((
int) $total / $limit),
2215 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2216 throw new RestException(403);
2219 $result = $this->template_invoice->fetch(
$id, $ref, $ref_ext);
2221 throw new RestException(404,
'Template invoice not found');
2225 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2229 if ($contact_list > -1) {
2230 $tmparray = $this->template_invoice->liste_contact(-1,
'external', $contact_list);
2231 if (is_array($tmparray)) {
2232 $this->template_invoice->contacts_ids = $tmparray;
2236 $this->template_invoice->fetchObjectLinked();
2256 unset(
$object->barcode_type_code);
2257 unset(
$object->barcode_type_label);
2258 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.
const STATUS_DRAFT
Draft status.
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.