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';
41 public static $FIELDS = array(
53 private $template_invoice;
63 $this->invoice =
new Facture($this->db);
64 $this->template_invoice =
new FactureRec($this->db);
82 public function get(
$id, $contact_list = 1, $properties =
'', $withLines =
true)
84 $invoice = $this->
_fetch(
$id,
'',
'', $contact_list);
87 unset($invoice->lines);
110 return $this->
_fetch(0, $ref,
'', $contact_list);
130 return $this->
_fetch(0,
'', $ref_ext, $contact_list);
146 private function _fetch(
$id, $ref =
'', $ref_ext =
'', $contact_list = 1)
148 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
149 throw new RestException(403);
151 if (empty(
$id) && empty($ref) && empty($ref_ext)) {
152 throw new RestException(400,
'No invoice can be found with no criteria');
154 $result = $this->invoice->fetch(
$id, $ref, $ref_ext);
156 throw new RestException(404,
'Invoice not found');
160 $this->invoice->totalpaid = $this->invoice->getSommePaiement();
161 $this->invoice->totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
162 $this->invoice->totaldeposits = $this->invoice->getSumDepositsUsed();
163 $this->invoice->remaintopay =
price2num($this->invoice->total_ttc - $this->invoice->totalpaid - $this->invoice->totalcreditnotes - $this->invoice->totaldeposits,
'MT');
166 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
170 $this->invoice->getListIdAvoirFromInvoice();
173 if ($contact_list > -1) {
174 $tmparray = $this->invoice->liste_contact(-1,
'external', $contact_list);
175 if (is_array($tmparray)) {
176 $this->invoice->contacts_ids = $tmparray;
178 $tmparray = $this->invoice->liste_contact(-1,
'internal', $contact_list);
179 if (is_array($tmparray)) {
180 $this->invoice->contacts_ids = $tmparray;
184 $this->invoice->fetchObjectLinked();
187 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
188 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $this->invoice->ref);
218 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
220 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
221 throw new RestException(403);
227 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
231 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
232 $search_sale = DolibarrApiAccess::$user->id;
235 $sql =
"SELECT t.rowid";
236 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture AS t";
237 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
238 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_extrafields AS ef ON (ef.fk_object = t.rowid)";
239 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
241 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
244 if ($search_sale && $search_sale !=
'-1') {
245 if ($search_sale == -2) {
246 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
247 } elseif ($search_sale > 0) {
248 $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).
")";
252 if ($status ==
'draft') {
253 $sql .=
" AND t.fk_statut IN (0)";
255 if ($status ==
'unpaid') {
256 $sql .=
" AND t.fk_statut IN (1)";
258 if ($status ==
'paid') {
259 $sql .=
" AND t.fk_statut IN (2)";
261 if ($status ==
'cancelled') {
262 $sql .=
" AND t.fk_statut IN (3)";
269 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
274 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
276 $sql .= $this->db->order($sortfield, $sortorder);
281 $offset = $limit * $page;
283 $sql .= $this->db->plimit($limit + 1, $offset);
286 $result = $this->db->query($sql);
289 $num = $this->db->num_rows($result);
290 $min = min($num, ($limit <= 0 ? $num : $limit));
292 $obj = $this->db->fetch_object($result);
293 $invoice_static =
new Facture($this->db);
294 if ($invoice_static->fetch($obj->rowid) > 0) {
296 $invoice_static->totalpaid = $invoice_static->getSommePaiement();
297 $invoice_static->totalcreditnotes = $invoice_static->getSumCreditNotesUsed();
298 $invoice_static->totaldeposits = $invoice_static->getSumDepositsUsed();
299 $invoice_static->remaintopay =
price2num($invoice_static->total_ttc - $invoice_static->totalpaid - $invoice_static->totalcreditnotes - $invoice_static->totaldeposits,
'MT');
302 $invoice_static->getListIdAvoirFromInvoice();
305 $tmparray = $invoice_static->liste_contact(-1,
'external', 1);
306 if (is_array($tmparray)) {
307 $invoice_static->contacts_ids = $tmparray;
310 if ($loadlinkedobjects) {
312 $invoice_static->fetchObjectLinked();
316 unset($invoice_static->lines);
320 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
321 $invoice_static->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $invoice_static->ref);
328 throw new RestException(503,
'Error when retrieve invoice list : '.$this->db->lasterror());
332 if ($pagination_data) {
333 $totalsResult = $this->db->query($sqlTotals);
334 $total = $this->db->fetch_object($totalsResult)->total;
339 $obj_ret[
'data'] = $tmp;
340 $obj_ret[
'pagination'] = [
341 'total' => (int) $total,
343 'page_count' => ceil((
int) $total / $limit),
361 public function post($request_data =
null)
364 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
365 throw new RestException(403,
"Insufficiant rights");
368 if (!is_array($request_data)) {
369 $request_data = array();
376 $socid = (int) $request_data[
'socid'];
377 $thirdpartytmp =
new Societe($this->db);
378 $thirdparty_result = $thirdpartytmp->fetch($socid);
379 if ($thirdparty_result < 1) {
380 throw new RestException(404,
'Thirdparty with id='.$socid.
' not found or not allowed');
383 throw new RestException(404,
'Thirdparty with id='.$thirdpartytmp->id.
' not found or not allowed');
386 foreach ($request_data as $field => $value) {
387 if ($field ===
'caller') {
389 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
392 if ($field ==
'id') {
393 throw new RestException(400,
'Creating with id field is forbidden');
395 if ($field ==
'entity' && ((
int) $value) != ((
int)
$conf->entity)) {
396 throw new RestException(403,
'Creating with entity='.((
int) $value).
' MUST be the same entity='.((
int)
$conf->entity).
' as your API user/key belongs to');
399 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
401 if (!array_key_exists(
'date', $request_data)) {
402 $this->invoice->date =
dol_now();
413 if ($this->invoice->create(DolibarrApiAccess::$user, 0, (empty($request_data[
"date_lim_reglement"]) ? 0 : $request_data[
"date_lim_reglement"])) < 0) {
414 throw new RestException(500,
"Error creating invoice", array_merge(array($this->invoice->error), $this->invoice->errors));
416 return ((
int) $this->invoice->id);
437 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
439 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
440 throw new RestException(403);
442 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
443 throw new RestException(403);
445 if (empty($orderid)) {
446 throw new RestException(400,
'Order ID is mandatory');
449 throw new RestException(403,
'Access not allowed on order for login '.DolibarrApiAccess::$user->login);
453 $result = $order->fetch($orderid);
455 throw new RestException(404,
'Order not found');
461 throw new RestException(405,
'Order '.$order->ref.
' is not eligible for invoicing: its status does not allow creating an invoice');
464 $result = $this->invoice->createFromOrder($order, DolibarrApiAccess::$user);
466 throw new RestException(405, $this->invoice->error);
468 $this->invoice->fetchObjectLinked();
489 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
491 if (!DolibarrApiAccess::$user->hasRight(
'contrat',
'lire')) {
492 throw new RestException(403);
494 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
495 throw new RestException(403);
497 if (empty($contractid)) {
498 throw new RestException(400,
'Contract ID is mandatory');
501 $contract =
new Contrat($this->db);
502 $result = $contract->fetch($contractid);
504 throw new RestException(404,
'Contract not found');
507 throw new RestException(403,
'Access to contract '.$contract->id.
' not allowed for login '.DolibarrApiAccess::$user->login);
510 $result = $this->invoice->createFromContract($contract, DolibarrApiAccess::$user);
512 throw new RestException(405, $this->invoice->error);
514 $this->invoice->fetchObjectLinked();
532 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
533 throw new RestException(403);
536 $result = $this->invoice->fetch(
$id);
538 throw new RestException(404,
'Invoice not found');
542 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
544 $this->invoice->getLinesArray();
546 foreach ($this->invoice->lines as $line) {
572 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
573 throw new RestException(403);
576 $result = $this->invoice->fetch(
$id);
578 throw new RestException(404,
'Invoice not found');
582 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
585 $request_data = (object) $request_data;
587 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
588 $request_data->label =
sanitizeVal($request_data->label);
591 $result = $invoiceline->fetch($lineid);
593 throw new RestException(404,
'Invoice line not found');
596 if ($invoiceline->fk_facture !=
$id) {
597 throw new RestException(403,
'Line does not belong to this invoice');
600 $updateRes = $this->invoice->updateline(
603 $request_data->subprice,
605 $request_data->remise_percent,
606 $request_data->date_start,
607 $request_data->date_end,
608 $request_data->tva_tx,
609 $request_data->localtax1_tx,
610 $request_data->localtax2_tx,
611 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
612 $request_data->info_bits,
613 $request_data->product_type,
614 $request_data->fk_parent_line,
616 $request_data->fk_fournprice,
617 $request_data->pa_ht,
618 $request_data->label,
619 $request_data->special_code,
620 $request_data->array_options,
621 $request_data->situation_percent,
622 $request_data->fk_unit,
623 $request_data->multicurrency_subprice,
625 $request_data->ref_ext,
629 if ($updateRes > 0) {
630 $result = $this->
get(
$id);
631 unset($result->line);
634 throw new RestException(304, $this->invoice->error);
657 public function postContact(
$id, $contactid, $type, $source =
'external', $notrigger = 0)
659 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
660 throw new RestException(403);
664 if (empty($source)) {
665 throw new RestException(400,
'Source can not be empty');
667 $sql_distinct_source =
"SELECT DISTINCT source";
668 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
669 $sql_distinct_source .=
" WHERE element LIKE 'facture'";
670 $sql_distinct_source .=
" AND source is NOT NULL";
671 $sql_distinct_source .=
" AND active != 0";
672 $source_result = $this->db->query($sql_distinct_source);
673 $source_array = array();
675 if ($source_result) {
676 $num = $this->db->num_rows($source_result);
679 $obj = $this->db->fetch_object($source_result);
680 $source_kind = (
string) $obj->source;
681 array_push($source_array, $source_kind);
686 throw new RestException(503,
'Error when retrieving a list of invoice contact sources: '.$this->db->lasterror());
688 if (!in_array($source, (array) $source_array,
true)) {
689 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active invoice contact types');
694 throw new RestException(400,
'type can not be empty');
697 $sql_distinct_type =
"SELECT DISTINCT code";
698 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
699 $sql_distinct_type .=
" WHERE element LIKE 'facture'";
700 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
701 $sql_distinct_type .=
" AND code is NOT NULL";
702 $sql_distinct_type .=
" AND active != 0";
703 $type_result = $this->db->query($sql_distinct_type);
704 $type_array = array();
707 $num = $this->db->num_rows($type_result);
710 $obj = $this->db->fetch_object($type_result);
712 $type_kind = (
string) $obj->code;
713 array_push($type_array, $type_kind);
718 throw new RestException(503,
'Error when retrieving a list of invoice contact types: '.$this->db->lasterror());
720 if (!in_array($type, (array) $type_array,
true)) {
721 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active invoice contact types');
725 $result = $this->invoice->fetch(
$id);
727 throw new RestException(404,
'Invoice not found');
730 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
733 $result = $this->invoice->add_contact($contactid, $type, $source, $notrigger);
736 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the invoice='.
$id.
' as source='.$source.
' and type='.$type);
737 } elseif ($result == -1) {
738 throw new RestException(400,
'Wrong contact='.$contactid);
739 } elseif ($result == -2) {
740 throw new RestException(400,
'Wrong type='.$type);
741 } elseif ($result == -3) {
742 throw new RestException(400,
'Not allowed contacts');
743 } elseif ($result == -4) {
744 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
745 } elseif ($result == -5) {
746 throw new RestException(400,
'Trigger failed');
747 } elseif ($result == -6) {
748 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
749 } elseif ($result == -7) {
750 throw new RestException(400,
'Some other error');
754 throw new RestException(500,
'Error when added the contact');
760 'message' =>
'Contact='.$contactid.
' linked to the invoice='.
$id.
' as '.$source.
' '.$type
782 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
783 throw new RestException(403);
786 $result = $this->invoice->fetch(
$id);
788 throw new RestException(404,
'Invoice not found');
792 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
795 $contacts = $this->invoice->liste_contact(-1,
'external', 0, $type);
796 $socpeoples = $this->invoice->liste_contact(-1,
'internal', 0, $type);
798 $contacts = array_merge($contacts, $socpeoples);
821 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
822 throw new RestException(403);
825 $result = $this->invoice->fetch(
$id);
828 throw new RestException(404,
'Invoice not found');
832 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
835 $contacts = $this->invoice->liste_contact();
837 foreach ($contacts as $contact) {
838 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
839 $result = $this->invoice->delete_contact($contact[
'rowid']);
842 throw new RestException(500,
'Error when deleted the contact');
868 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
869 throw new RestException(403);
871 if (empty($lineid)) {
872 throw new RestException(400,
'Line ID is mandatory');
876 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
879 $result = $this->invoice->fetch(
$id);
881 throw new RestException(404,
'Invoice not found');
883 if ($this->invoice->status != 0) {
884 throw new RestException(403,
'Invoice not in Draft Status : '.$this->invoice->getLibStatut(1));
887 $updateRes = $this->invoice->deleteLine($lineid,
$id);
888 if ($updateRes > 0) {
889 return $this->
get(
$id);
891 throw new RestException(405, $this->invoice->error);
906 public function put(
$id, $request_data =
null)
908 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
909 throw new RestException(403);
912 throw new RestException(400,
'No invoice with id=0 can exist');
914 $result = $this->invoice->fetch(
$id);
916 throw new RestException(404,
'Invoice not found');
920 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
923 foreach ($request_data as $field => $value) {
924 if ($field ==
'id') {
927 if ($field ===
'caller') {
929 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
932 if ($field ==
'array_options' && is_array($value)) {
933 foreach ($value as $index => $val) {
939 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
942 if ($field ==
'cond_reglement_id') {
943 $this->invoice->date_lim_reglement = $this->invoice->calculate_date_lim_reglement();
948 if (!empty($this->invoice->fk_account)) {
949 if ($this->invoice->setBankAccount((
int) $this->invoice->fk_account) == 0) {
950 throw new RestException(400, $this->invoice->error);
954 if ($this->invoice->update(DolibarrApiAccess::$user) > 0) {
955 return $this->
get(
$id);
957 throw new RestException(500, $this->invoice->error);
971 public function delete(
$id)
973 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'supprimer')) {
974 throw new RestException(403);
977 throw new RestException(400,
'No invoice with id=0 can exist');
979 $result = $this->invoice->fetch(
$id);
981 throw new RestException(404,
'Invoice not found');
985 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
988 $result = $this->invoice->delete(DolibarrApiAccess::$user);
990 throw new RestException(500,
'Error when deleting invoice');
991 } elseif ($result == 0) {
992 throw new RestException(403,
'Invoice not erasable');
998 'message' =>
'Invoice deleted'
1032 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1033 throw new RestException(403);
1036 $result = $this->invoice->fetch(
$id);
1038 throw new RestException(404,
'Invoice not found');
1042 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1045 $request_data = (object) $request_data;
1047 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
1048 $request_data->label =
sanitizeVal($request_data->label);
1051 if (($request_data->product_type != 9 && empty($request_data->fk_parent_line)) || $request_data->product_type == 9) {
1052 $request_data->fk_parent_line = 0;
1056 $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);
1057 $pa_ht = $marginInfos[0];
1059 $updateRes = $this->invoice->addline(
1060 $request_data->desc,
1061 $request_data->subprice,
1063 $request_data->tva_tx,
1064 $request_data->localtax1_tx,
1065 $request_data->localtax2_tx,
1066 $request_data->fk_product,
1067 $request_data->remise_percent,
1068 $request_data->date_start,
1069 $request_data->date_end,
1070 $request_data->fk_code_ventilation,
1071 $request_data->info_bits,
1072 $request_data->fk_remise_except,
1073 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
1074 $request_data->subprice,
1075 $request_data->product_type,
1076 $request_data->rang,
1077 $request_data->special_code,
1078 $request_data->origin,
1079 $request_data->origin_id,
1080 $request_data->fk_parent_line,
1081 empty($request_data->fk_fournprice) ? null : $request_data->fk_fournprice,
1083 $request_data->label,
1084 $request_data->array_options,
1085 $request_data->situation_percent,
1086 $request_data->fk_prev_id,
1087 $request_data->fk_unit,
1089 $request_data->ref_ext
1092 if ($updateRes < 0) {
1093 throw new RestException(400,
'Unable to insert the new line. Check your inputs. '.$this->invoice->error);
1119 public function addContact(
$id, $fk_socpeople, $type_contact, $source, $notrigger = 0)
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->add_contact($fk_socpeople, $type_contact, $source, $notrigger);
1135 throw new RestException(500,
'Error : '.$this->invoice->error);
1138 $result = $this->invoice->fetch(
$id);
1140 throw new RestException(404,
'Invoice not found');
1171 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1172 throw new RestException(403);
1174 $result = $this->invoice->fetch(
$id);
1176 throw new RestException(404,
'Invoice not found');
1180 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1183 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1185 throw new RestException(304,
'Nothing done.');
1188 throw new RestException(500,
'Error : '.$this->invoice->error);
1191 $result = $this->invoice->fetch(
$id);
1193 throw new RestException(404,
'Invoice not found');
1219 public function validate(
$id, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1221 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1222 throw new RestException(403);
1224 $result = $this->invoice->fetch(
$id);
1226 throw new RestException(404,
'Invoice not found');
1230 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1233 $result = $this->invoice->validate(DolibarrApiAccess::$user, $force_number, $idwarehouse, $notrigger);
1235 throw new RestException(304,
'Error nothing done. May be object is already validated');
1238 throw new RestException(500,
'Error when validating Invoice: '.$this->invoice->error);
1241 $result = $this->invoice->fetch(
$id);
1243 throw new RestException(404,
'Invoice not found');
1252 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1253 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $this->invoice->ref);
1277 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1278 throw new RestException(403);
1280 $result = $this->invoice->fetch(
$id);
1282 throw new RestException(404,
'Invoice not found');
1286 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1289 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
1291 throw new RestException(304,
'Error nothing done. May be object is already validated');
1294 throw new RestException(500,
'Error : '.$this->invoice->error);
1298 $result = $this->invoice->fetch(
$id);
1300 throw new RestException(404,
'Invoice not found');
1329 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1330 throw new RestException(403);
1332 $result = $this->invoice->fetch(
$id);
1334 throw new RestException(404,
'Invoice not found');
1338 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1341 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
1343 throw new RestException(304,
'Nothing done');
1346 throw new RestException(500,
'Error : '.$this->invoice->error);
1350 $result = $this->invoice->fetch(
$id);
1352 throw new RestException(404,
'Invoice not found');
1375 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1377 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1378 throw new RestException(403);
1381 $result = $this->invoice->fetch(
$id);
1383 throw new RestException(404,
'Invoice not found');
1387 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1391 $result = $discountcheck->fetch(0, $this->invoice->id);
1394 throw new RestException(404,
'Discount not found');
1397 throw new RestException(500, $discountcheck->error);
1400 return parent::_cleanObjectDatas($discountcheck);
1420 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1422 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1423 throw new RestException(403);
1426 $result = $this->invoice->fetch(
$id);
1428 throw new RestException(404,
'Invoice not found');
1432 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1435 if ($this->invoice->paye) {
1436 throw new RestException(500,
'Alreay paid');
1439 $this->invoice->fetch(
$id);
1440 $this->invoice->fetch_thirdparty();
1444 $result = $discountcheck->fetch(0, $this->invoice->id);
1456 $amount_ht = $amount_tva = $amount_ttc = array();
1457 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1459 @phan-var-force array<string,float> $amount_ht
1460 @phan-var-force array<string,float> $amount_tva
1461 @phan-var-force array<string,float> $amount_ttc
1462 @phan-var-force array<string,float> $multicurrency_amount_ht
1463 @phan-var-force array<string,float> $multicurrency_amount_tva
1464 @phan-var-force array<string,float> $multicurrency_amount_ttc
1469 foreach ($this->invoice->lines as $line) {
1470 if ($line->product_type < 9 && $line->total_ht != 0) {
1471 if (!array_key_exists($line->tva_tx, $amount_ht)) {
1472 $amount_ht[$line->tva_tx] = 0.0;
1473 $amount_tva[$line->tva_tx] = 0.0;
1474 $amount_ttc[$line->tva_tx] = 0.0;
1475 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
1476 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
1477 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
1480 $amount_ht[$line->tva_tx] += $line->total_ht;
1481 $amount_tva[$line->tva_tx] += $line->total_tva;
1482 $amount_ttc[$line->tva_tx] += $line->total_ttc;
1483 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
1484 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
1485 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
1493 $discount->description =
'(CREDIT_NOTE)';
1495 $discount->description =
'(DEPOSIT)';
1497 $discount->description =
'(EXCESS RECEIVED)';
1499 throw new RestException(500,
'Cant convert to reduc an Invoice of this type');
1502 $discount->fk_soc = $this->invoice->socid;
1503 $discount->socid = $this->invoice->socid;
1504 $discount->fk_facture_source = $this->invoice->id;
1512 $sql =
'SELECT SUM(pf.amount) as total_payments';
1513 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1514 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1515 $sql .=
' WHERE pf.fk_facture = '.((int) $this->invoice->id);
1516 $sql .=
' AND pf.fk_paiement = p.rowid';
1517 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1518 $resql = $this->db->query($sql);
1523 $res = $this->db->fetch_object($resql);
1524 $total_payments = $res->total_payments;
1527 $total_creditnote_and_deposit = 0;
1528 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1529 $sql .=
" re.description, re.fk_facture_source";
1530 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1531 $sql .=
" WHERE fk_facture = ".((int) $this->invoice->id);
1532 $resql = $this->db->query($sql);
1533 if (!empty($resql)) {
1534 while ($obj = $this->db->fetch_object($resql)) {
1535 $total_creditnote_and_deposit += $obj->amount_ttc;
1541 $discount->amount_ht = $discount->amount_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1542 $discount->total_ht = $discount->total_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1543 $discount->amount_tva = 0;
1544 $discount->total_tva = 0;
1545 $discount->tva_tx = 0;
1547 $result = $discount->create(DolibarrApiAccess::$user);
1553 foreach ($amount_ht as $tva_tx => $xxx) {
1554 $discount->amount_ht = abs($amount_ht[$tva_tx]);
1555 $discount->amount_tva = abs($amount_tva[$tva_tx]);
1556 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
1557 $discount->total_ht = abs($amount_ht[$tva_tx]);
1558 $discount->total_tva = abs($amount_tva[$tva_tx]);
1559 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
1560 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
1561 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
1562 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1563 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
1564 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
1565 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1566 $discount->tva_tx = abs((
float) $tva_tx);
1568 $result = $discount->create(DolibarrApiAccess::$user);
1576 if (empty($error)) {
1579 $result = $this->invoice->setPaid(DolibarrApiAccess::$user);
1581 $this->db->commit();
1583 $this->db->rollback();
1584 throw new RestException(500,
'Could not set paid');
1587 $this->db->commit();
1590 $this->db->rollback();
1591 throw new RestException(500,
'Discount creation error');
1618 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1619 throw new RestException(403);
1622 throw new RestException(400,
'Invoice ID is mandatory');
1624 if (empty($discountid)) {
1625 throw new RestException(400,
'Discount ID is mandatory');
1629 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1632 $result = $this->invoice->fetch(
$id);
1634 throw new RestException(404,
'Invoice not found');
1637 $result = $this->invoice->insert_discount($discountid);
1639 throw new RestException(405, $this->invoice->error);
1665 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1667 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1668 throw new RestException(403);
1671 throw new RestException(400,
'Invoice ID is mandatory');
1673 if (empty($discountid)) {
1674 throw new RestException(400,
'Credit ID is mandatory');
1678 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1681 $result = $discount->fetch($discountid);
1683 throw new RestException(404,
'Credit not found');
1686 $result = $discount->link_to_invoice(0,
$id);
1688 throw new RestException(405, $discount->error);
1713 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1714 throw new RestException(403);
1717 throw new RestException(400,
'Invoice ID is mandatory');
1721 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1724 $result = $this->invoice->fetch(
$id);
1726 throw new RestException(404,
'Invoice not found');
1729 $result = $this->invoice->getListOfPayments();
1730 if (!is_array($result) && $result < 0) {
1731 throw new RestException(405, $this->invoice->error);
1761 public function addPayment(
$id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'')
1763 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1765 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1766 throw new RestException(403);
1769 throw new RestException(400,
'Invoice ID is mandatory');
1773 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1777 if (empty($accountid)) {
1778 throw new RestException(400,
'Account ID is mandatory');
1782 if (empty($paymentid)) {
1783 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1787 $result = $this->invoice->fetch(
$id);
1789 throw new RestException(404,
'Invoice not found');
1793 $totalpaid = $this->invoice->getSommePaiement();
1794 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
1795 $totaldeposits = $this->invoice->getSumDepositsUsed();
1800 $multicurrency_amounts = array();
1804 $resteapayer =
price2num($this->invoice->total_ttc + $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1805 $amounts[
$id] = (float)
price2num(-1 * abs((
float) $resteapayer),
'MT');
1807 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1808 $multicurrency_amounts[
$id] = (float)
price2num(-1 * (
float) $newvalue,
'MT');
1810 $resteapayer =
price2num($this->invoice->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1811 $amounts[
$id] = (float) $resteapayer;
1813 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1814 $multicurrency_amounts[
$id] = (float) $newvalue;
1818 $paymentobj =
new Paiement($this->db);
1819 if (is_numeric($datepaye)) {
1820 $paymentobj->datepaye = $datepaye;
1824 $paymentobj->amounts = $amounts;
1825 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1826 $paymentobj->paiementid = $paymentid;
1827 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1828 $paymentobj->num_payment = $num_payment;
1829 $paymentobj->note_private = $comment;
1831 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1832 if ($payment_id < 0) {
1833 $this->db->rollback();
1834 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1838 $label =
'(CustomerInvoicePayment)';
1840 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1841 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1844 $label =
'(CustomerInvoicePaymentBack)';
1846 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1848 $this->db->rollback();
1849 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1853 $this->db->commit();
1888 public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'', $ref_ext =
'', $accepthigherpayment =
false)
1890 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1892 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1893 throw new RestException(403);
1895 foreach ($arrayofamounts as
$id => $amount) {
1897 throw new RestException(400,
'Invoice ID is mandatory. Fill the invoice id and amount into arrayofamounts parameter. For example: {"1": "99.99", "2": "10"}');
1900 throw new RestException(403,
'Access not allowed on invoice ID '.
$id.
' for login '.DolibarrApiAccess::$user->login);
1905 if (empty($accountid)) {
1906 throw new RestException(400,
'Account ID is mandatory');
1909 if (empty($paymentid)) {
1910 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1916 $multicurrency_amounts = array();
1919 foreach ($arrayofamounts as
$id => $amountarray) {
1921 $result = $this->invoice->fetch(
$id);
1923 $this->db->rollback();
1924 throw new RestException(404,
'Invoice ID '.
$id.
' not found');
1927 if (($amountarray[
"amount"] ==
"remain" || $amountarray[
"amount"] > 0) && ($amountarray[
"multicurrency_amount"] ==
"remain" || $amountarray[
"multicurrency_amount"] > 0)) {
1928 $this->db->rollback();
1929 throw new RestException(400,
'Payment in both currency '.
$id.
' ( amount: '.$amountarray[
"amount"].
', multicurrency_amount: '.$amountarray[
"multicurrency_amount"].
')');
1932 $is_multicurrency = 0;
1933 $total_ttc = $this->invoice->total_ttc;
1935 if ($amountarray[
"multicurrency_amount"] > 0 || $amountarray[
"multicurrency_amount"] ==
"remain") {
1936 $is_multicurrency = 1;
1937 $total_ttc = $this->invoice->multicurrency_total_ttc;
1941 $totalpaid = $this->invoice->getSommePaiement($is_multicurrency);
1942 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency);
1943 $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
1944 $remainstopay = $amount = (float)
price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1946 if (!$is_multicurrency && $amountarray[
"amount"] !=
'remain') {
1947 $amount = (float)
price2num($amountarray[
"amount"],
'MT');
1950 if ($is_multicurrency && $amountarray[
"multicurrency_amount"] !=
'remain') {
1951 $amount = (float)
price2num($amountarray[
"multicurrency_amount"],
'MT');
1954 if (abs($amount) > abs($remainstopay) && !$accepthigherpayment) {
1955 $this->db->rollback();
1956 throw new RestException(400,
'Payment amount on invoice ID '.
$id.
' ('.$amount.
') is higher than remain to pay ('.$remainstopay.
')');
1960 $amount = (float)
price2num(-1 * abs((
float) $amount),
'MT');
1963 if ($is_multicurrency) {
1964 $amounts[
$id] =
null;
1966 $multicurrency_amounts[
$id] = (float) $amount;
1968 $amounts[
$id] = (float) $amount;
1970 $multicurrency_amounts[
$id] =
null;
1975 $paymentobj =
new Paiement($this->db);
1976 if (is_numeric($datepaye)) {
1977 $paymentobj->datepaye = $datepaye;
1981 $paymentobj->amounts = $amounts;
1982 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1983 $paymentobj->paiementid = $paymentid;
1984 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1985 $paymentobj->num_payment = $num_payment;
1986 $paymentobj->note_private = $comment;
1987 $paymentobj->ref_ext = $ref_ext;
1988 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1989 if ($payment_id < 0) {
1990 $this->db->rollback();
1991 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1994 $label =
'(CustomerInvoicePayment)';
1995 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1996 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1999 $label =
'(CustomerInvoicePaymentBack)';
2001 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
2003 $this->db->rollback();
2004 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
2008 $this->db->commit();
2033 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
2035 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
2036 throw new RestException(403);
2039 throw new RestException(400,
'Payment ID is mandatory');
2042 $paymentobj =
new Paiement($this->db);
2043 $result = $paymentobj->fetch(
$id);
2046 throw new RestException(404,
'Payment not found');
2050 $tmparray = $paymentobj->getBillsArray();
2051 foreach ($tmparray as $tmpinvoiceid) {
2053 throw new RestException(403,
'Payment is on invoices that are not all allowed for login '.DolibarrApiAccess::$user->login);
2057 if (!empty($num_payment)) {
2058 $result = $paymentobj->update_num($num_payment);
2060 throw new RestException(500,
'Error when updating the payment num');
2067 'message' =>
'Payment updated'
2090 unset(
$object->barcode_type_code);
2091 unset(
$object->barcode_type_label);
2092 unset(
$object->barcode_type_coder);
2108 if ($data ===
null) {
2112 foreach (Invoices::$FIELDS as $field) {
2113 if (!isset($data[$field])) {
2114 throw new RestException(400,
"$field field missing");
2116 $invoice[$field] = $data[$field];
2170 public function indexTemplateInvoices($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
2172 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2173 throw new RestException(403);
2179 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
2184 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
2185 $search_sale = DolibarrApiAccess::$user->id;
2188 $sql =
"SELECT t.rowid";
2189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_rec AS t";
2190 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
2191 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_rec_extrafields AS ef ON (ef.fk_object = t.rowid)";
2192 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
2194 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
2198 if ($search_sale && $search_sale !=
'-1') {
2199 if ($search_sale == -2) {
2200 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux AS sc WHERE sc.fk_soc = t.fk_soc)";
2201 } elseif ($search_sale > 0) {
2202 $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).
")";
2207 if ($status ==
'active') {
2208 $sql .=
" AND t.suspended = 0 AND t.frequency IS NOT NULL";
2210 if ($status ==
'suspended') {
2211 $sql .=
" AND t.suspended = 1 AND t.frequency IS NOT NULL";
2213 if ($status ==
'draft') {
2214 $sql .=
" AND t.frequency IS NULL";
2220 if ($errormessage) {
2221 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2226 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
2228 $sql .= $this->db->order($sortfield, $sortorder);
2233 $offset = $limit * $page;
2235 $sql .= $this->db->plimit($limit + 1, $offset);
2238 $result = $this->db->query($sql);
2241 $num = $this->db->num_rows($result);
2242 $min = min($num, ($limit <= 0 ? $num : $limit));
2244 $obj = $this->db->fetch_object($result);
2246 if ($factureRec->fetch($obj->rowid) > 0) {
2247 if ($loadlinkedobjects) {
2249 $factureRec->fetchObjectLinked();
2253 unset($factureRec->lines);
2261 throw new RestException(503,
'Error when retrieving recurring invoice templates: '.$this->db->lasterror());
2265 if ($pagination_data) {
2266 $totalsResult = $this->db->query($sqlTotals);
2267 $total = $this->db->fetch_object($totalsResult)->total;
2272 $obj_ret[
'data'] = $tmp;
2273 $obj_ret[
'pagination'] = array(
2274 'total' => (
int) $total,
2276 'page_count' => ceil((
int) $total / $limit),
2299 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2300 throw new RestException(403);
2303 $result = $this->template_invoice->fetch(
$id, $ref, $ref_ext);
2305 throw new RestException(404,
'Template invoice not found');
2309 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2313 if ($contact_list > -1) {
2314 $tmparray = $this->template_invoice->liste_contact(-1,
'external', $contact_list);
2315 if (is_array($tmparray)) {
2316 $this->template_invoice->contacts_ids = $tmparray;
2320 $this->template_invoice->fetchObjectLinked();
2340 unset(
$object->barcode_type_code);
2341 unset(
$object->barcode_type_label);
2342 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 lines.
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
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.