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';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
42 public static $FIELDS = array(
54 private $template_invoice;
64 $this->invoice =
new Facture($this->db);
65 $this->template_invoice =
new FactureRec($this->db);
83 public function get(
$id, $contact_list = 1, $properties =
'', $withLines =
true)
85 $invoice = $this->
_fetch(
$id,
'',
'', $contact_list);
88 unset($invoice->lines);
111 return $this->
_fetch(0, $ref,
'', $contact_list);
131 return $this->
_fetch(0,
'', $ref_ext, $contact_list);
147 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $contact_list = 1)
149 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
150 throw new RestException(403);
152 if (empty(
$id) && empty($ref) && empty($ref_ext)) {
153 throw new RestException(400,
'No invoice can be found with no criteria');
155 $result = $this->invoice->fetch(
$id, $ref, $ref_ext);
157 throw new RestException(404,
'Invoice not found');
161 $this->invoice->totalpaid = $this->invoice->getSommePaiement();
162 $this->invoice->totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
163 $this->invoice->totaldeposits = $this->invoice->getSumDepositsUsed();
164 $this->invoice->remaintopay =
price2num($this->invoice->total_ttc - $this->invoice->totalpaid - $this->invoice->totalcreditnotes - $this->invoice->totaldeposits,
'MT');
167 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
171 $this->invoice->getListIdAvoirFromInvoice();
174 if ($contact_list > -1) {
175 $tmparray = $this->invoice->liste_contact(-1,
'external', $contact_list);
176 if (is_array($tmparray)) {
177 $this->invoice->contacts_ids = $tmparray;
179 $tmparray = $this->invoice->liste_contact(-1,
'internal', $contact_list);
180 if (is_array($tmparray)) {
181 $this->invoice->contacts_ids = $tmparray;
185 $this->invoice->fetchObjectLinked();
188 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
189 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $this->invoice->ref);
219 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
221 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
222 throw new RestException(403);
228 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
232 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
233 $search_sale = DolibarrApiAccess::$user->id;
236 $sql =
"SELECT t.rowid";
237 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture AS t";
238 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
239 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_extrafields AS ef ON (ef.fk_object = t.rowid)";
240 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
242 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
245 if ($search_sale && $search_sale !=
'-1') {
246 if ($search_sale == -2) {
247 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', 0, 1);
248 } elseif ($search_sale > 0) {
249 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', (
int) $search_sale);
253 if ($status ==
'draft') {
254 $sql .=
" AND t.fk_statut IN (0)";
256 if ($status ==
'unpaid') {
257 $sql .=
" AND t.fk_statut IN (1)";
259 if ($status ==
'paid') {
260 $sql .=
" AND t.fk_statut IN (2)";
262 if ($status ==
'cancelled') {
263 $sql .=
" AND t.fk_statut IN (3)";
270 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
275 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
277 $sql .= $this->db->order($sortfield, $sortorder);
282 $offset = $limit * $page;
284 $sql .= $this->db->plimit($limit + 1, $offset);
287 $result = $this->db->query($sql);
290 $num = $this->db->num_rows($result);
291 $min = min($num, ($limit <= 0 ? $num : $limit));
293 $obj = $this->db->fetch_object($result);
294 $invoice_static =
new Facture($this->db);
295 if ($invoice_static->fetch($obj->rowid) > 0) {
297 $invoice_static->totalpaid = $invoice_static->getSommePaiement();
298 $invoice_static->totalcreditnotes = $invoice_static->getSumCreditNotesUsed();
299 $invoice_static->totaldeposits = $invoice_static->getSumDepositsUsed();
300 $invoice_static->remaintopay =
price2num($invoice_static->total_ttc - $invoice_static->totalpaid - $invoice_static->totalcreditnotes - $invoice_static->totaldeposits,
'MT');
303 $invoice_static->getListIdAvoirFromInvoice();
306 $tmparray = $invoice_static->liste_contact(-1,
'external', 1);
307 if (is_array($tmparray)) {
308 $invoice_static->contacts_ids = $tmparray;
311 if ($loadlinkedobjects) {
313 $invoice_static->fetchObjectLinked();
317 unset($invoice_static->lines);
321 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
322 $invoice_static->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $invoice_static->ref);
329 throw new RestException(503,
'Error when retrieve invoice list : '.$this->db->lasterror());
333 if ($pagination_data) {
334 $totalsResult = $this->db->query($sqlTotals);
335 $total = $this->db->fetch_object($totalsResult)->total;
340 $obj_ret[
'data'] = $tmp;
341 $obj_ret[
'pagination'] = [
342 'total' => (int) $total,
344 'page_count' => ceil((
int) $total / $limit),
362 public function post($request_data =
null)
365 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
366 throw new RestException(403,
"Insufficiant rights");
369 if (!is_array($request_data)) {
370 $request_data = array();
377 $socid = (int) $request_data[
'socid'];
378 $thirdpartytmp =
new Societe($this->db);
379 $thirdparty_result = $thirdpartytmp->fetch($socid);
380 if ($thirdparty_result < 1) {
381 throw new RestException(404,
'Thirdparty with id='.$socid.
' not found or not allowed');
384 throw new RestException(404,
'Thirdparty with id='.$thirdpartytmp->id.
' not found or not allowed');
387 foreach ($request_data as $field => $value) {
388 if ($field ===
'caller') {
390 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
393 if ($field ==
'id') {
394 throw new RestException(400,
'Creating with id field is forbidden');
396 if ($field ==
'entity' && ((
int) $value) != ((
int)
$conf->entity)) {
397 throw new RestException(403,
'Creating with entity='.((
int) $value).
' MUST be the same entity='.((
int)
$conf->entity).
' as your API user/key belongs to');
400 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
402 if (!array_key_exists(
'date', $request_data)) {
403 $this->invoice->date =
dol_now();
414 if ($this->invoice->create(DolibarrApiAccess::$user, 0, (empty($request_data[
"date_lim_reglement"]) ? 0 : $request_data[
"date_lim_reglement"])) < 0) {
415 throw new RestException(500,
"Error creating invoice", array_merge(array($this->invoice->error), $this->invoice->errors));
417 return ((
int) $this->invoice->id);
438 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
440 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
441 throw new RestException(403);
443 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
444 throw new RestException(403);
446 if (empty($orderid)) {
447 throw new RestException(400,
'Order ID is mandatory');
450 throw new RestException(403,
'Access not allowed on order for login '.DolibarrApiAccess::$user->login);
454 $result = $order->fetch($orderid);
456 throw new RestException(404,
'Order not found');
462 throw new RestException(405,
'Order '.$order->ref.
' is not eligible for invoicing: its status does not allow creating an invoice');
465 $result = $this->invoice->createFromOrder($order, DolibarrApiAccess::$user);
467 throw new RestException(405, $this->invoice->error);
469 $this->invoice->fetchObjectLinked();
490 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
492 if (!DolibarrApiAccess::$user->hasRight(
'contrat',
'lire')) {
493 throw new RestException(403);
495 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
496 throw new RestException(403);
498 if (empty($contractid)) {
499 throw new RestException(400,
'Contract ID is mandatory');
502 $contract =
new Contrat($this->db);
503 $result = $contract->fetch($contractid);
505 throw new RestException(404,
'Contract not found');
508 $result = $this->invoice->createFromContract($contract, DolibarrApiAccess::$user);
510 throw new RestException(405, $this->invoice->error);
512 $this->invoice->fetchObjectLinked();
530 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
531 throw new RestException(403);
534 $result = $this->invoice->fetch(
$id);
536 throw new RestException(404,
'Invoice not found');
540 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
542 $this->invoice->getLinesArray();
544 foreach ($this->invoice->lines as $line) {
570 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
571 throw new RestException(403);
574 $result = $this->invoice->fetch(
$id);
576 throw new RestException(404,
'Invoice not found');
580 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
583 $request_data = (object) $request_data;
585 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
586 $request_data->label =
sanitizeVal($request_data->label);
588 $updateRes = $this->invoice->updateline(
591 $request_data->subprice,
593 $request_data->remise_percent,
594 $request_data->date_start,
595 $request_data->date_end,
596 $request_data->tva_tx,
597 $request_data->localtax1_tx,
598 $request_data->localtax2_tx,
599 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
600 $request_data->info_bits,
601 $request_data->product_type,
602 $request_data->fk_parent_line,
604 $request_data->fk_fournprice,
605 $request_data->pa_ht,
606 $request_data->label,
607 $request_data->special_code,
608 $request_data->array_options,
609 $request_data->situation_percent,
610 $request_data->fk_unit,
611 $request_data->multicurrency_subprice,
613 $request_data->ref_ext,
617 if ($updateRes > 0) {
618 $result = $this->
get(
$id);
619 unset($result->line);
622 throw new RestException(304, $this->invoice->error);
645 public function postContact(
$id, $contactid, $type, $source =
'external', $notrigger = 0)
647 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
648 throw new RestException(403);
652 if (empty($source)) {
653 throw new RestException(400,
'Source can not be empty');
655 $sql_distinct_source =
"SELECT DISTINCT source";
656 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
657 $sql_distinct_source .=
" WHERE element LIKE 'facture'";
658 $sql_distinct_source .=
" AND source is NOT NULL";
659 $sql_distinct_source .=
" AND active != 0";
660 $source_result = $this->db->query($sql_distinct_source);
661 $source_array = array();
663 if ($source_result) {
664 $num = $this->db->num_rows($source_result);
667 $obj = $this->db->fetch_object($source_result);
668 $source_kind = (
string) $obj->source;
669 array_push($source_array, $source_kind);
674 throw new RestException(503,
'Error when retrieving a list of invoice contact sources: '.$this->db->lasterror());
676 if (!in_array($source, (array) $source_array,
true)) {
677 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active invoice contact types');
682 throw new RestException(400,
'type can not be empty');
685 $sql_distinct_type =
"SELECT DISTINCT code";
686 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
687 $sql_distinct_type .=
" WHERE element LIKE 'facture'";
688 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
689 $sql_distinct_type .=
" AND code is NOT NULL";
690 $sql_distinct_type .=
" AND active != 0";
691 $type_result = $this->db->query($sql_distinct_type);
692 $type_array = array();
695 $num = $this->db->num_rows($type_result);
698 $obj = $this->db->fetch_object($type_result);
700 $type_kind = (
string) $obj->code;
701 array_push($type_array, $type_kind);
706 throw new RestException(503,
'Error when retrieving a list of invoice contact types: '.$this->db->lasterror());
708 if (!in_array($type, (array) $type_array,
true)) {
709 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active invoice contact types');
713 $result = $this->invoice->fetch(
$id);
715 throw new RestException(404,
'Invoice not found');
718 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
721 $result = $this->invoice->add_contact($contactid, $type, $source, $notrigger);
724 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the invoice='.
$id.
' as source='.$source.
' and type='.$type);
725 } elseif ($result == -1) {
726 throw new RestException(400,
'Wrong contact='.$contactid);
727 } elseif ($result == -2) {
728 throw new RestException(400,
'Wrong type='.$type);
729 } elseif ($result == -3) {
730 throw new RestException(400,
'Not allowed contacts');
731 } elseif ($result == -4) {
732 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
733 } elseif ($result == -5) {
734 throw new RestException(400,
'Trigger failed');
735 } elseif ($result == -6) {
736 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
737 } elseif ($result == -7) {
738 throw new RestException(400,
'Some other error');
742 throw new RestException(500,
'Error when added the contact');
748 'message' =>
'Contact='.$contactid.
' linked to the invoice='.
$id.
' as '.$source.
' '.$type
770 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
771 throw new RestException(403);
774 $result = $this->invoice->fetch(
$id);
776 throw new RestException(404,
'Invoice not found');
780 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
783 $contacts = $this->invoice->liste_contact(-1,
'external', 0, $type);
784 $socpeoples = $this->invoice->liste_contact(-1,
'internal', 0, $type);
786 $contacts = array_merge($contacts, $socpeoples);
809 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
810 throw new RestException(403);
813 $result = $this->invoice->fetch(
$id);
816 throw new RestException(404,
'Invoice not found');
820 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
823 $contacts = $this->invoice->liste_contact();
825 foreach ($contacts as $contact) {
826 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
827 $result = $this->invoice->delete_contact($contact[
'rowid']);
830 throw new RestException(500,
'Error when deleted the contact');
856 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
857 throw new RestException(403);
859 if (empty($lineid)) {
860 throw new RestException(400,
'Line ID is mandatory');
864 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
867 $result = $this->invoice->fetch(
$id);
869 throw new RestException(404,
'Invoice not found');
871 if ($this->invoice->status != 0) {
872 throw new RestException(403,
'Invoice not in Draft Status : '.$this->invoice->getLibStatut(1));
875 $updateRes = $this->invoice->deleteLine($lineid,
$id);
876 if ($updateRes > 0) {
877 return $this->
get(
$id);
879 throw new RestException(405, $this->invoice->error);
894 public function put(
$id, $request_data =
null)
896 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
897 throw new RestException(403);
900 throw new RestException(400,
'No invoice with id=0 can exist');
902 $result = $this->invoice->fetch(
$id);
904 throw new RestException(404,
'Invoice not found');
908 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
911 foreach ($request_data as $field => $value) {
912 if ($field ==
'id') {
915 if ($field ===
'caller') {
917 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
920 if ($field ==
'array_options' && is_array($value)) {
921 foreach ($value as $index => $val) {
927 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
930 if ($field ==
'cond_reglement_id') {
931 $this->invoice->date_lim_reglement = $this->invoice->calculate_date_lim_reglement();
936 if (!empty($this->invoice->fk_account)) {
937 if ($this->invoice->setBankAccount((
int) $this->invoice->fk_account) == 0) {
938 throw new RestException(400, $this->invoice->error);
942 if ($this->invoice->update(DolibarrApiAccess::$user) > 0) {
943 return $this->
get(
$id);
945 throw new RestException(500, $this->invoice->error);
959 public function delete(
$id)
961 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'supprimer')) {
962 throw new RestException(403);
965 throw new RestException(400,
'No invoice with id=0 can exist');
967 $result = $this->invoice->fetch(
$id);
969 throw new RestException(404,
'Invoice not found');
973 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
976 $result = $this->invoice->delete(DolibarrApiAccess::$user);
978 throw new RestException(500,
'Error when deleting invoice');
979 } elseif ($result == 0) {
980 throw new RestException(403,
'Invoice not erasable');
986 'message' =>
'Invoice deleted'
1020 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1021 throw new RestException(403);
1024 $result = $this->invoice->fetch(
$id);
1026 throw new RestException(404,
'Invoice not found');
1030 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1033 $request_data = (object) $request_data;
1035 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
1036 $request_data->label =
sanitizeVal($request_data->label);
1039 if (($request_data->product_type != 9 && empty($request_data->fk_parent_line)) || $request_data->product_type == 9) {
1040 $request_data->fk_parent_line = 0;
1044 $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);
1045 $pa_ht = $marginInfos[0];
1047 $updateRes = $this->invoice->addline(
1048 $request_data->desc,
1049 $request_data->subprice,
1051 $request_data->tva_tx,
1052 $request_data->localtax1_tx,
1053 $request_data->localtax2_tx,
1054 $request_data->fk_product,
1055 $request_data->remise_percent,
1056 $request_data->date_start,
1057 $request_data->date_end,
1058 $request_data->fk_code_ventilation,
1059 $request_data->info_bits,
1060 $request_data->fk_remise_except,
1061 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
1062 $request_data->subprice,
1063 $request_data->product_type,
1064 $request_data->rang,
1065 $request_data->special_code,
1066 $request_data->origin,
1067 $request_data->origin_id,
1068 $request_data->fk_parent_line,
1069 empty($request_data->fk_fournprice) ? null : $request_data->fk_fournprice,
1071 $request_data->label,
1072 $request_data->array_options,
1073 $request_data->situation_percent,
1074 $request_data->fk_prev_id,
1075 $request_data->fk_unit,
1077 $request_data->ref_ext
1080 if ($updateRes < 0) {
1081 throw new RestException(400,
'Unable to insert the new line. Check your inputs. '.$this->invoice->error);
1107 public function addContact(
$id, $fk_socpeople, $type_contact, $source, $notrigger = 0)
1109 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1110 throw new RestException(403);
1112 $result = $this->invoice->fetch(
$id);
1114 throw new RestException(404,
'Invoice not found');
1118 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1121 $result = $this->invoice->add_contact($fk_socpeople, $type_contact, $source, $notrigger);
1123 throw new RestException(500,
'Error : '.$this->invoice->error);
1126 $result = $this->invoice->fetch(
$id);
1128 throw new RestException(404,
'Invoice not found');
1159 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1160 throw new RestException(403);
1162 $result = $this->invoice->fetch(
$id);
1164 throw new RestException(404,
'Invoice not found');
1168 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1171 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1173 throw new RestException(304,
'Nothing done.');
1176 throw new RestException(500,
'Error : '.$this->invoice->error);
1179 $result = $this->invoice->fetch(
$id);
1181 throw new RestException(404,
'Invoice not found');
1207 public function validate(
$id, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1209 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1210 throw new RestException(403);
1212 $result = $this->invoice->fetch(
$id);
1214 throw new RestException(404,
'Invoice not found');
1218 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1221 $result = $this->invoice->validate(DolibarrApiAccess::$user, $force_number, $idwarehouse, $notrigger);
1223 throw new RestException(304,
'Error nothing done. May be object is already validated');
1226 throw new RestException(500,
'Error when validating Invoice: '.$this->invoice->error);
1229 $result = $this->invoice->fetch(
$id);
1231 throw new RestException(404,
'Invoice not found');
1240 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1241 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $this->invoice->ref);
1265 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1266 throw new RestException(403);
1268 $result = $this->invoice->fetch(
$id);
1270 throw new RestException(404,
'Invoice not found');
1274 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1277 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
1279 throw new RestException(304,
'Error nothing done. May be object is already validated');
1282 throw new RestException(500,
'Error : '.$this->invoice->error);
1286 $result = $this->invoice->fetch(
$id);
1288 throw new RestException(404,
'Invoice not found');
1317 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1318 throw new RestException(403);
1320 $result = $this->invoice->fetch(
$id);
1322 throw new RestException(404,
'Invoice not found');
1326 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1329 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
1331 throw new RestException(304,
'Nothing done');
1334 throw new RestException(500,
'Error : '.$this->invoice->error);
1338 $result = $this->invoice->fetch(
$id);
1340 throw new RestException(404,
'Invoice not found');
1363 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1365 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1366 throw new RestException(403);
1369 $result = $this->invoice->fetch(
$id);
1371 throw new RestException(404,
'Invoice not found');
1375 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1379 $result = $discountcheck->fetch(0, $this->invoice->id);
1382 throw new RestException(404,
'Discount not found');
1385 throw new RestException(500, $discountcheck->error);
1388 return parent::_cleanObjectDatas($discountcheck);
1408 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1410 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1411 throw new RestException(403);
1414 $result = $this->invoice->fetch(
$id);
1416 throw new RestException(404,
'Invoice not found');
1420 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1423 if ($this->invoice->paye) {
1424 throw new RestException(500,
'Alreay paid');
1427 $this->invoice->fetch(
$id);
1428 $this->invoice->fetch_thirdparty();
1432 $result = $discountcheck->fetch(0, $this->invoice->id);
1444 $amount_ht = $amount_tva = $amount_ttc = array();
1445 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1447 @phan-var-force array<string,float> $amount_ht
1448 @phan-var-force array<string,float> $amount_tva
1449 @phan-var-force array<string,float> $amount_ttc
1450 @phan-var-force array<string,float> $multicurrency_amount_ht
1451 @phan-var-force array<string,float> $multicurrency_amount_tva
1452 @phan-var-force array<string,float> $multicurrency_amount_ttc
1457 foreach ($this->invoice->lines as $line) {
1458 if ($line->product_type < 9 && $line->total_ht != 0) {
1459 if (!array_key_exists($line->tva_tx, $amount_ht)) {
1460 $amount_ht[$line->tva_tx] = 0.0;
1461 $amount_tva[$line->tva_tx] = 0.0;
1462 $amount_ttc[$line->tva_tx] = 0.0;
1463 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
1464 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
1465 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
1468 $amount_ht[$line->tva_tx] += $line->total_ht;
1469 $amount_tva[$line->tva_tx] += $line->total_tva;
1470 $amount_ttc[$line->tva_tx] += $line->total_ttc;
1471 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
1472 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
1473 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
1481 $discount->description =
'(CREDIT_NOTE)';
1483 $discount->description =
'(DEPOSIT)';
1485 $discount->description =
'(EXCESS RECEIVED)';
1487 throw new RestException(500,
'Cant convert to reduc an Invoice of this type');
1490 $discount->fk_soc = $this->invoice->socid;
1491 $discount->socid = $this->invoice->socid;
1492 $discount->fk_facture_source = $this->invoice->id;
1500 $sql =
'SELECT SUM(pf.amount) as total_payments';
1501 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1502 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1503 $sql .=
' WHERE pf.fk_facture = '.((int) $this->invoice->id);
1504 $sql .=
' AND pf.fk_paiement = p.rowid';
1505 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1506 $resql = $this->db->query($sql);
1511 $res = $this->db->fetch_object($resql);
1512 $total_payments = $res->total_payments;
1515 $total_creditnote_and_deposit = 0;
1516 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1517 $sql .=
" re.description, re.fk_facture_source";
1518 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1519 $sql .=
" WHERE fk_facture = ".((int) $this->invoice->id);
1520 $resql = $this->db->query($sql);
1521 if (!empty($resql)) {
1522 while ($obj = $this->db->fetch_object($resql)) {
1523 $total_creditnote_and_deposit += $obj->amount_ttc;
1529 $discount->amount_ht = $discount->amount_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1530 $discount->total_ht = $discount->total_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1531 $discount->amount_tva = 0;
1532 $discount->total_tva = 0;
1533 $discount->tva_tx = 0;
1535 $result = $discount->create(DolibarrApiAccess::$user);
1541 foreach ($amount_ht as $tva_tx => $xxx) {
1542 $discount->amount_ht = abs($amount_ht[$tva_tx]);
1543 $discount->amount_tva = abs($amount_tva[$tva_tx]);
1544 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
1545 $discount->total_ht = abs($amount_ht[$tva_tx]);
1546 $discount->total_tva = abs($amount_tva[$tva_tx]);
1547 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
1548 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
1549 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
1550 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1551 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
1552 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
1553 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1554 $discount->tva_tx = abs((
float) $tva_tx);
1556 $result = $discount->create(DolibarrApiAccess::$user);
1564 if (empty($error)) {
1567 $result = $this->invoice->setPaid(DolibarrApiAccess::$user);
1569 $this->db->commit();
1571 $this->db->rollback();
1572 throw new RestException(500,
'Could not set paid');
1575 $this->db->commit();
1578 $this->db->rollback();
1579 throw new RestException(500,
'Discount creation error');
1606 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1607 throw new RestException(403);
1610 throw new RestException(400,
'Invoice ID is mandatory');
1612 if (empty($discountid)) {
1613 throw new RestException(400,
'Discount ID is mandatory');
1617 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1620 $result = $this->invoice->fetch(
$id);
1622 throw new RestException(404,
'Invoice not found');
1625 $result = $this->invoice->insert_discount($discountid);
1627 throw new RestException(405, $this->invoice->error);
1653 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1655 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1656 throw new RestException(403);
1659 throw new RestException(400,
'Invoice ID is mandatory');
1661 if (empty($discountid)) {
1662 throw new RestException(400,
'Credit ID is mandatory');
1666 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1669 $result = $discount->fetch($discountid);
1671 throw new RestException(404,
'Credit not found');
1674 $result = $discount->link_to_invoice(0,
$id);
1676 throw new RestException(405, $discount->error);
1701 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1702 throw new RestException(403);
1705 throw new RestException(400,
'Invoice ID is mandatory');
1709 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1712 $result = $this->invoice->fetch(
$id);
1714 throw new RestException(404,
'Invoice not found');
1717 $result = $this->invoice->getListOfPayments();
1718 if (!is_array($result) && $result < 0) {
1719 throw new RestException(405, $this->invoice->error);
1749 public function addPayment(
$id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'')
1751 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1753 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1754 throw new RestException(403);
1757 throw new RestException(400,
'Invoice ID is mandatory');
1761 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1765 if (empty($accountid)) {
1766 throw new RestException(400,
'Account ID is mandatory');
1770 if (empty($paymentid)) {
1771 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1775 $result = $this->invoice->fetch(
$id);
1777 throw new RestException(404,
'Invoice not found');
1781 $totalpaid = $this->invoice->getSommePaiement();
1782 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
1783 $totaldeposits = $this->invoice->getSumDepositsUsed();
1788 $multicurrency_amounts = array();
1792 $resteapayer =
price2num($this->invoice->total_ttc + $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1793 $amounts[
$id] = (float)
price2num(-1 * abs((
float) $resteapayer),
'MT');
1795 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1796 $multicurrency_amounts[
$id] = (float)
price2num(-1 * (
float) $newvalue,
'MT');
1798 $resteapayer =
price2num($this->invoice->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1799 $amounts[
$id] = (float) $resteapayer;
1801 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1802 $multicurrency_amounts[
$id] = (float) $newvalue;
1806 $paymentobj =
new Paiement($this->db);
1807 if (is_numeric($datepaye)) {
1808 $paymentobj->datepaye = $datepaye;
1812 $paymentobj->amounts = $amounts;
1813 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1814 $paymentobj->paiementid = $paymentid;
1815 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1816 $paymentobj->num_payment = $num_payment;
1817 $paymentobj->note_private = $comment;
1819 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1820 if ($payment_id < 0) {
1821 $this->db->rollback();
1822 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1826 $label =
'(CustomerInvoicePayment)';
1828 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1829 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1832 $label =
'(CustomerInvoicePaymentBack)';
1834 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1836 $this->db->rollback();
1837 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1841 $this->db->commit();
1876 public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'', $ref_ext =
'', $accepthigherpayment =
false)
1878 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1880 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1881 throw new RestException(403);
1883 foreach ($arrayofamounts as
$id => $amount) {
1885 throw new RestException(400,
'Invoice ID is mandatory. Fill the invoice id and amount into arrayofamounts parameter. For example: {"1": "99.99", "2": "10"}');
1888 throw new RestException(403,
'Access not allowed on invoice ID '.
$id.
' for login '.DolibarrApiAccess::$user->login);
1893 if (empty($accountid)) {
1894 throw new RestException(400,
'Account ID is mandatory');
1897 if (empty($paymentid)) {
1898 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1904 $multicurrency_amounts = array();
1907 foreach ($arrayofamounts as
$id => $amountarray) {
1909 $result = $this->invoice->fetch(
$id);
1911 $this->db->rollback();
1912 throw new RestException(404,
'Invoice ID '.
$id.
' not found');
1915 if (($amountarray[
"amount"] ==
"remain" || $amountarray[
"amount"] > 0) && ($amountarray[
"multicurrency_amount"] ==
"remain" || $amountarray[
"multicurrency_amount"] > 0)) {
1916 $this->db->rollback();
1917 throw new RestException(400,
'Payment in both currency '.
$id.
' ( amount: '.$amountarray[
"amount"].
', multicurrency_amount: '.$amountarray[
"multicurrency_amount"].
')');
1920 $is_multicurrency = 0;
1921 $total_ttc = $this->invoice->total_ttc;
1923 if ($amountarray[
"multicurrency_amount"] > 0 || $amountarray[
"multicurrency_amount"] ==
"remain") {
1924 $is_multicurrency = 1;
1925 $total_ttc = $this->invoice->multicurrency_total_ttc;
1929 $totalpaid = $this->invoice->getSommePaiement($is_multicurrency);
1930 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency);
1931 $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
1932 $remainstopay = $amount = (float)
price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1934 if (!$is_multicurrency && $amountarray[
"amount"] !=
'remain') {
1935 $amount = (float)
price2num($amountarray[
"amount"],
'MT');
1938 if ($is_multicurrency && $amountarray[
"multicurrency_amount"] !=
'remain') {
1939 $amount = (float)
price2num($amountarray[
"multicurrency_amount"],
'MT');
1942 if (abs($amount) > abs($remainstopay) && !$accepthigherpayment) {
1943 $this->db->rollback();
1944 throw new RestException(400,
'Payment amount on invoice ID '.
$id.
' ('.$amount.
') is higher than remain to pay ('.$remainstopay.
')');
1948 $amount = (float)
price2num(-1 * abs((
float) $amount),
'MT');
1951 if ($is_multicurrency) {
1952 $amounts[
$id] =
null;
1954 $multicurrency_amounts[
$id] = (float) $amount;
1956 $amounts[
$id] = (float) $amount;
1958 $multicurrency_amounts[
$id] =
null;
1963 $paymentobj =
new Paiement($this->db);
1964 if (is_numeric($datepaye)) {
1965 $paymentobj->datepaye = $datepaye;
1969 $paymentobj->amounts = $amounts;
1970 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1971 $paymentobj->paiementid = $paymentid;
1972 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1973 $paymentobj->num_payment = $num_payment;
1974 $paymentobj->note_private = $comment;
1975 $paymentobj->ref_ext = $ref_ext;
1976 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1977 if ($payment_id < 0) {
1978 $this->db->rollback();
1979 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1982 $label =
'(CustomerInvoicePayment)';
1983 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1984 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1987 $label =
'(CustomerInvoicePaymentBack)';
1989 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1991 $this->db->rollback();
1992 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1996 $this->db->commit();
2021 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
2023 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
2024 throw new RestException(403);
2027 throw new RestException(400,
'Payment ID is mandatory');
2030 $paymentobj =
new Paiement($this->db);
2031 $result = $paymentobj->fetch(
$id);
2034 throw new RestException(404,
'Payment not found');
2038 $tmparray = $paymentobj->getBillsArray();
2039 foreach ($tmparray as $tmpinvoiceid) {
2041 throw new RestException(403,
'Payment is on invoices that are not all allowed for login '.DolibarrApiAccess::$user->login);
2045 if (!empty($num_payment)) {
2046 $result = $paymentobj->update_num($num_payment);
2048 throw new RestException(500,
'Error when updating the payment num');
2055 'message' =>
'Payment updated'
2078 unset(
$object->barcode_type_code);
2079 unset(
$object->barcode_type_label);
2080 unset(
$object->barcode_type_coder);
2096 if ($data ===
null) {
2100 foreach (Invoices::$FIELDS as $field) {
2101 if (!isset($data[$field])) {
2102 throw new RestException(400,
"$field field missing");
2104 $invoice[$field] = $data[$field];
2158 public function indexTemplateInvoices($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
2160 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2161 throw new RestException(403);
2167 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
2172 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
2173 $search_sale = DolibarrApiAccess::$user->id;
2176 $sql =
"SELECT t.rowid";
2177 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_rec AS t";
2178 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
2179 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_rec_extrafields AS ef ON (ef.fk_object = t.rowid)";
2180 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
2182 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
2186 if ($search_sale && $search_sale !=
'-1') {
2187 if ($search_sale == -2) {
2188 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux AS sc WHERE sc.fk_soc = t.fk_soc)";
2189 } elseif ($search_sale > 0) {
2190 $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).
")";
2195 if ($status ==
'active') {
2196 $sql .=
" AND t.suspended = 0 AND t.frequency IS NOT NULL";
2198 if ($status ==
'suspended') {
2199 $sql .=
" AND t.suspended = 1 AND t.frequency IS NOT NULL";
2201 if ($status ==
'draft') {
2202 $sql .=
" AND t.frequency IS NULL";
2208 if ($errormessage) {
2209 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2214 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
2216 $sql .= $this->db->order($sortfield, $sortorder);
2221 $offset = $limit * $page;
2223 $sql .= $this->db->plimit($limit + 1, $offset);
2226 $result = $this->db->query($sql);
2229 $num = $this->db->num_rows($result);
2230 $min = min($num, ($limit <= 0 ? $num : $limit));
2232 $obj = $this->db->fetch_object($result);
2234 if ($factureRec->fetch($obj->rowid) > 0) {
2235 if ($loadlinkedobjects) {
2237 $factureRec->fetchObjectLinked();
2241 unset($factureRec->lines);
2249 throw new RestException(503,
'Error when retrieving recurring invoice templates: '.$this->db->lasterror());
2253 if ($pagination_data) {
2254 $totalsResult = $this->db->query($sqlTotals);
2255 $total = $this->db->fetch_object($totalsResult)->total;
2260 $obj_ret[
'data'] = $tmp;
2261 $obj_ret[
'pagination'] = array(
2262 'total' => (
int) $total,
2264 'page_count' => ceil((
int) $total / $limit),
2287 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2288 throw new RestException(403);
2291 $result = $this->template_invoice->fetch(
$id, $ref, $ref_ext);
2293 throw new RestException(404,
'Template invoice not found');
2297 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2301 if ($contact_list > -1) {
2302 $tmparray = $this->template_invoice->liste_contact(-1,
'external', $contact_list);
2303 if (is_array($tmparray)) {
2304 $this->template_invoice->contacts_ids = $tmparray;
2308 $this->template_invoice->fetchObjectLinked();
2328 unset(
$object->barcode_type_code);
2329 unset(
$object->barcode_type_label);
2330 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.
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
Class to manage 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, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.