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)";
267 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
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');
458 $result = $this->invoice->createFromOrder($order, DolibarrApiAccess::$user);
460 throw new RestException(405, $this->invoice->error);
462 $this->invoice->fetchObjectLinked();
483 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
485 if (!DolibarrApiAccess::$user->hasRight(
'contrat',
'lire')) {
486 throw new RestException(403);
488 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
489 throw new RestException(403);
491 if (empty($contractid)) {
492 throw new RestException(400,
'Contract ID is mandatory');
495 $contract =
new Contrat($this->db);
496 $result = $contract->fetch($contractid);
498 throw new RestException(404,
'Contract not found');
501 $result = $this->invoice->createFromContract($contract, DolibarrApiAccess::$user);
503 throw new RestException(405, $this->invoice->error);
505 $this->invoice->fetchObjectLinked();
523 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
524 throw new RestException(403);
527 $result = $this->invoice->fetch(
$id);
529 throw new RestException(404,
'Invoice not found');
533 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
535 $this->invoice->getLinesArray();
537 foreach ($this->invoice->lines as $line) {
563 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
564 throw new RestException(403);
567 $result = $this->invoice->fetch(
$id);
569 throw new RestException(404,
'Invoice not found');
573 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
576 $request_data = (object) $request_data;
578 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
579 $request_data->label =
sanitizeVal($request_data->label);
581 $updateRes = $this->invoice->updateline(
584 $request_data->subprice,
586 $request_data->remise_percent,
587 $request_data->date_start,
588 $request_data->date_end,
589 $request_data->tva_tx,
590 $request_data->localtax1_tx,
591 $request_data->localtax2_tx,
592 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
593 $request_data->info_bits,
594 $request_data->product_type,
595 $request_data->fk_parent_line,
597 $request_data->fk_fournprice,
598 $request_data->pa_ht,
599 $request_data->label,
600 $request_data->special_code,
601 $request_data->array_options,
602 $request_data->situation_percent,
603 $request_data->fk_unit,
604 $request_data->multicurrency_subprice,
606 $request_data->ref_ext,
610 if ($updateRes > 0) {
611 $result = $this->
get(
$id);
612 unset($result->line);
615 throw new RestException(304, $this->invoice->error);
638 public function postContact(
$id, $contactid, $type, $source =
'external', $notrigger = 0)
640 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
641 throw new RestException(403);
645 if (empty($source)) {
646 throw new RestException(400,
'Source can not be empty');
648 $sql_distinct_source =
"SELECT DISTINCT source";
649 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
650 $sql_distinct_source .=
" WHERE element LIKE 'facture'";
651 $sql_distinct_source .=
" AND source is NOT NULL";
652 $sql_distinct_source .=
" AND active != 0";
653 $source_result = $this->db->query($sql_distinct_source);
654 $source_array = array();
656 if ($source_result) {
657 $num = $this->db->num_rows($source_result);
660 $obj = $this->db->fetch_object($source_result);
661 $source_kind = (
string) $obj->source;
662 array_push($source_array, $source_kind);
667 throw new RestException(503,
'Error when retrieving a list of invoice contact sources: '.$this->db->lasterror());
669 if (!in_array($source, (array) $source_array,
true)) {
670 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active invoice contact types');
675 throw new RestException(400,
'type can not be empty');
678 $sql_distinct_type =
"SELECT DISTINCT code";
679 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
680 $sql_distinct_type .=
" WHERE element LIKE 'facture'";
681 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
682 $sql_distinct_type .=
" AND code is NOT NULL";
683 $sql_distinct_type .=
" AND active != 0";
684 $type_result = $this->db->query($sql_distinct_type);
685 $type_array = array();
688 $num = $this->db->num_rows($type_result);
691 $obj = $this->db->fetch_object($type_result);
693 $type_kind = (
string) $obj->code;
694 array_push($type_array, $type_kind);
699 throw new RestException(503,
'Error when retrieving a list of invoice contact types: '.$this->db->lasterror());
701 if (!in_array($type, (array) $type_array,
true)) {
702 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active invoice contact types');
706 $result = $this->invoice->fetch(
$id);
708 throw new RestException(404,
'Invoice not found');
711 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
714 $result = $this->invoice->add_contact($contactid, $type, $source, $notrigger);
717 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the invoice='.
$id.
' as source='.$source.
' and type='.$type);
718 } elseif ($result == -1) {
719 throw new RestException(400,
'Wrong contact='.$contactid);
720 } elseif ($result == -2) {
721 throw new RestException(400,
'Wrong type='.$type);
722 } elseif ($result == -3) {
723 throw new RestException(400,
'Not allowed contacts');
724 } elseif ($result == -4) {
725 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
726 } elseif ($result == -5) {
727 throw new RestException(400,
'Trigger failed');
728 } elseif ($result == -6) {
729 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
730 } elseif ($result == -7) {
731 throw new RestException(400,
'Some other error');
735 throw new RestException(500,
'Error when added the contact');
741 'message' =>
'Contact='.$contactid.
' linked to the invoice='.
$id.
' as '.$source.
' '.$type
763 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
764 throw new RestException(403);
767 $result = $this->invoice->fetch(
$id);
769 throw new RestException(404,
'Invoice not found');
773 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
776 $contacts = $this->invoice->liste_contact(-1,
'external', 0, $type);
777 $socpeoples = $this->invoice->liste_contact(-1,
'internal', 0, $type);
779 $contacts = array_merge($contacts, $socpeoples);
802 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
803 throw new RestException(403);
806 $result = $this->invoice->fetch(
$id);
809 throw new RestException(404,
'Invoice not found');
813 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
816 $contacts = $this->invoice->liste_contact();
818 foreach ($contacts as $contact) {
819 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
820 $result = $this->invoice->delete_contact($contact[
'rowid']);
823 throw new RestException(500,
'Error when deleted the contact');
849 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
850 throw new RestException(403);
852 if (empty($lineid)) {
853 throw new RestException(400,
'Line ID is mandatory');
857 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
860 $result = $this->invoice->fetch(
$id);
862 throw new RestException(404,
'Invoice not found');
864 if ($this->invoice->status != 0) {
865 throw new RestException(403,
'Invoice not in Draft Status : '.$this->invoice->getLibStatut(1));
868 $updateRes = $this->invoice->deleteLine($lineid,
$id);
869 if ($updateRes > 0) {
870 return $this->
get(
$id);
872 throw new RestException(405, $this->invoice->error);
887 public function put(
$id, $request_data =
null)
889 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
890 throw new RestException(403);
893 throw new RestException(400,
'No invoice with id=0 can exist');
895 $result = $this->invoice->fetch(
$id);
897 throw new RestException(404,
'Invoice not found');
901 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
904 foreach ($request_data as $field => $value) {
905 if ($field ==
'id') {
908 if ($field ===
'caller') {
910 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
913 if ($field ==
'array_options' && is_array($value)) {
914 foreach ($value as $index => $val) {
920 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
923 if ($field ==
'cond_reglement_id') {
924 $this->invoice->date_lim_reglement = $this->invoice->calculate_date_lim_reglement();
929 if (!empty($this->invoice->fk_account)) {
930 if ($this->invoice->setBankAccount((
int) $this->invoice->fk_account) == 0) {
931 throw new RestException(400, $this->invoice->error);
935 if ($this->invoice->update(DolibarrApiAccess::$user) > 0) {
936 return $this->
get(
$id);
938 throw new RestException(500, $this->invoice->error);
952 public function delete(
$id)
954 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'supprimer')) {
955 throw new RestException(403);
958 throw new RestException(400,
'No invoice with id=0 can exist');
960 $result = $this->invoice->fetch(
$id);
962 throw new RestException(404,
'Invoice not found');
966 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
969 $result = $this->invoice->delete(DolibarrApiAccess::$user);
971 throw new RestException(500,
'Error when deleting invoice');
972 } elseif ($result == 0) {
973 throw new RestException(403,
'Invoice not erasable');
979 'message' =>
'Invoice deleted'
1013 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1014 throw new RestException(403);
1017 $result = $this->invoice->fetch(
$id);
1019 throw new RestException(404,
'Invoice not found');
1023 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1026 $request_data = (object) $request_data;
1028 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
1029 $request_data->label =
sanitizeVal($request_data->label);
1032 if (($request_data->product_type != 9 && empty($request_data->fk_parent_line)) || $request_data->product_type == 9) {
1033 $request_data->fk_parent_line = 0;
1037 $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);
1038 $pa_ht = $marginInfos[0];
1040 $updateRes = $this->invoice->addline(
1041 $request_data->desc,
1042 $request_data->subprice,
1044 $request_data->tva_tx,
1045 $request_data->localtax1_tx,
1046 $request_data->localtax2_tx,
1047 $request_data->fk_product,
1048 $request_data->remise_percent,
1049 $request_data->date_start,
1050 $request_data->date_end,
1051 $request_data->fk_code_ventilation,
1052 $request_data->info_bits,
1053 $request_data->fk_remise_except,
1054 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
1055 $request_data->subprice,
1056 $request_data->product_type,
1057 $request_data->rang,
1058 $request_data->special_code,
1059 $request_data->origin,
1060 $request_data->origin_id,
1061 $request_data->fk_parent_line,
1062 empty($request_data->fk_fournprice) ? null : $request_data->fk_fournprice,
1064 $request_data->label,
1065 $request_data->array_options,
1066 $request_data->situation_percent,
1067 $request_data->fk_prev_id,
1068 $request_data->fk_unit,
1070 $request_data->ref_ext
1073 if ($updateRes < 0) {
1074 throw new RestException(400,
'Unable to insert the new line. Check your inputs. '.$this->invoice->error);
1100 public function addContact(
$id, $fk_socpeople, $type_contact, $source, $notrigger = 0)
1102 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1103 throw new RestException(403);
1105 $result = $this->invoice->fetch(
$id);
1107 throw new RestException(404,
'Invoice not found');
1111 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1114 $result = $this->invoice->add_contact($fk_socpeople, $type_contact, $source, $notrigger);
1116 throw new RestException(500,
'Error : '.$this->invoice->error);
1119 $result = $this->invoice->fetch(
$id);
1121 throw new RestException(404,
'Invoice not found');
1152 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1153 throw new RestException(403);
1155 $result = $this->invoice->fetch(
$id);
1157 throw new RestException(404,
'Invoice not found');
1161 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1164 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1166 throw new RestException(304,
'Nothing done.');
1169 throw new RestException(500,
'Error : '.$this->invoice->error);
1172 $result = $this->invoice->fetch(
$id);
1174 throw new RestException(404,
'Invoice not found');
1200 public function validate(
$id, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1202 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1203 throw new RestException(403);
1205 $result = $this->invoice->fetch(
$id);
1207 throw new RestException(404,
'Invoice not found');
1211 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1214 $result = $this->invoice->validate(DolibarrApiAccess::$user, $force_number, $idwarehouse, $notrigger);
1216 throw new RestException(304,
'Error nothing done. May be object is already validated');
1219 throw new RestException(500,
'Error when validating Invoice: '.$this->invoice->error);
1222 $result = $this->invoice->fetch(
$id);
1224 throw new RestException(404,
'Invoice not found');
1233 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1234 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $this->invoice->ref);
1258 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1259 throw new RestException(403);
1261 $result = $this->invoice->fetch(
$id);
1263 throw new RestException(404,
'Invoice not found');
1267 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1270 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
1272 throw new RestException(304,
'Error nothing done. May be object is already validated');
1275 throw new RestException(500,
'Error : '.$this->invoice->error);
1279 $result = $this->invoice->fetch(
$id);
1281 throw new RestException(404,
'Invoice not found');
1310 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1311 throw new RestException(403);
1313 $result = $this->invoice->fetch(
$id);
1315 throw new RestException(404,
'Invoice not found');
1319 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1322 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
1324 throw new RestException(304,
'Nothing done');
1327 throw new RestException(500,
'Error : '.$this->invoice->error);
1331 $result = $this->invoice->fetch(
$id);
1333 throw new RestException(404,
'Invoice not found');
1356 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1358 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1359 throw new RestException(403);
1362 $result = $this->invoice->fetch(
$id);
1364 throw new RestException(404,
'Invoice not found');
1368 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1372 $result = $discountcheck->fetch(0, $this->invoice->id);
1375 throw new RestException(404,
'Discount not found');
1378 throw new RestException(500, $discountcheck->error);
1381 return parent::_cleanObjectDatas($discountcheck);
1401 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1403 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1404 throw new RestException(403);
1407 $result = $this->invoice->fetch(
$id);
1409 throw new RestException(404,
'Invoice not found');
1413 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1416 if ($this->invoice->paye) {
1417 throw new RestException(500,
'Alreay paid');
1420 $this->invoice->fetch(
$id);
1421 $this->invoice->fetch_thirdparty();
1425 $result = $discountcheck->fetch(0, $this->invoice->id);
1437 $amount_ht = $amount_tva = $amount_ttc = array();
1438 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1440 @phan-var-force array<string,float> $amount_ht
1441 @phan-var-force array<string,float> $amount_tva
1442 @phan-var-force array<string,float> $amount_ttc
1443 @phan-var-force array<string,float> $multicurrency_amount_ht
1444 @phan-var-force array<string,float> $multicurrency_amount_tva
1445 @phan-var-force array<string,float> $multicurrency_amount_ttc
1450 foreach ($this->invoice->lines as $line) {
1451 if ($line->product_type < 9 && $line->total_ht != 0) {
1452 if (!array_key_exists($line->tva_tx, $amount_ht)) {
1453 $amount_ht[$line->tva_tx] = 0.0;
1454 $amount_tva[$line->tva_tx] = 0.0;
1455 $amount_ttc[$line->tva_tx] = 0.0;
1456 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
1457 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
1458 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
1461 $amount_ht[$line->tva_tx] += $line->total_ht;
1462 $amount_tva[$line->tva_tx] += $line->total_tva;
1463 $amount_ttc[$line->tva_tx] += $line->total_ttc;
1464 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
1465 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
1466 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
1474 $discount->description =
'(CREDIT_NOTE)';
1476 $discount->description =
'(DEPOSIT)';
1478 $discount->description =
'(EXCESS RECEIVED)';
1480 throw new RestException(500,
'Cant convert to reduc an Invoice of this type');
1483 $discount->fk_soc = $this->invoice->socid;
1484 $discount->socid = $this->invoice->socid;
1485 $discount->fk_facture_source = $this->invoice->id;
1493 $sql =
'SELECT SUM(pf.amount) as total_payments';
1494 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1495 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1496 $sql .=
' WHERE pf.fk_facture = '.((int) $this->invoice->id);
1497 $sql .=
' AND pf.fk_paiement = p.rowid';
1498 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1499 $resql = $this->db->query($sql);
1504 $res = $this->db->fetch_object($resql);
1505 $total_payments = $res->total_payments;
1508 $total_creditnote_and_deposit = 0;
1509 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1510 $sql .=
" re.description, re.fk_facture_source";
1511 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1512 $sql .=
" WHERE fk_facture = ".((int) $this->invoice->id);
1513 $resql = $this->db->query($sql);
1514 if (!empty($resql)) {
1515 while ($obj = $this->db->fetch_object($resql)) {
1516 $total_creditnote_and_deposit += $obj->amount_ttc;
1522 $discount->amount_ht = $discount->amount_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1523 $discount->total_ht = $discount->total_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1524 $discount->amount_tva = 0;
1525 $discount->total_tva = 0;
1526 $discount->tva_tx = 0;
1528 $result = $discount->create(DolibarrApiAccess::$user);
1534 foreach ($amount_ht as $tva_tx => $xxx) {
1535 $discount->amount_ht = abs($amount_ht[$tva_tx]);
1536 $discount->amount_tva = abs($amount_tva[$tva_tx]);
1537 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
1538 $discount->total_ht = abs($amount_ht[$tva_tx]);
1539 $discount->total_tva = abs($amount_tva[$tva_tx]);
1540 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
1541 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
1542 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
1543 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1544 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
1545 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
1546 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1547 $discount->tva_tx = abs((
float) $tva_tx);
1549 $result = $discount->create(DolibarrApiAccess::$user);
1557 if (empty($error)) {
1560 $result = $this->invoice->setPaid(DolibarrApiAccess::$user);
1562 $this->db->commit();
1564 $this->db->rollback();
1565 throw new RestException(500,
'Could not set paid');
1568 $this->db->commit();
1571 $this->db->rollback();
1572 throw new RestException(500,
'Discount creation error');
1599 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1600 throw new RestException(403);
1603 throw new RestException(400,
'Invoice ID is mandatory');
1605 if (empty($discountid)) {
1606 throw new RestException(400,
'Discount ID is mandatory');
1610 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1613 $result = $this->invoice->fetch(
$id);
1615 throw new RestException(404,
'Invoice not found');
1618 $result = $this->invoice->insert_discount($discountid);
1620 throw new RestException(405, $this->invoice->error);
1646 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1648 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1649 throw new RestException(403);
1652 throw new RestException(400,
'Invoice ID is mandatory');
1654 if (empty($discountid)) {
1655 throw new RestException(400,
'Credit ID is mandatory');
1659 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1662 $result = $discount->fetch($discountid);
1664 throw new RestException(404,
'Credit not found');
1667 $result = $discount->link_to_invoice(0,
$id);
1669 throw new RestException(405, $discount->error);
1694 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1695 throw new RestException(403);
1698 throw new RestException(400,
'Invoice ID is mandatory');
1702 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1705 $result = $this->invoice->fetch(
$id);
1707 throw new RestException(404,
'Invoice not found');
1710 $result = $this->invoice->getListOfPayments();
1711 if (!is_array($result) && $result < 0) {
1712 throw new RestException(405, $this->invoice->error);
1742 public function addPayment(
$id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'')
1744 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1746 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1747 throw new RestException(403);
1750 throw new RestException(400,
'Invoice ID is mandatory');
1754 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1758 if (empty($accountid)) {
1759 throw new RestException(400,
'Account ID is mandatory');
1763 if (empty($paymentid)) {
1764 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1768 $result = $this->invoice->fetch(
$id);
1770 throw new RestException(404,
'Invoice not found');
1774 $totalpaid = $this->invoice->getSommePaiement();
1775 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
1776 $totaldeposits = $this->invoice->getSumDepositsUsed();
1781 $multicurrency_amounts = array();
1785 $resteapayer =
price2num($this->invoice->total_ttc + $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1786 $amounts[
$id] = (float)
price2num(-1 * abs((
float) $resteapayer),
'MT');
1788 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1789 $multicurrency_amounts[
$id] = (float)
price2num(-1 * (
float) $newvalue,
'MT');
1791 $resteapayer =
price2num($this->invoice->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1792 $amounts[
$id] = (float) $resteapayer;
1794 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1795 $multicurrency_amounts[
$id] = (float) $newvalue;
1799 $paymentobj =
new Paiement($this->db);
1800 if (is_numeric($datepaye)) {
1801 $paymentobj->datepaye = $datepaye;
1805 $paymentobj->amounts = $amounts;
1806 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1807 $paymentobj->paiementid = $paymentid;
1808 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1809 $paymentobj->num_payment = $num_payment;
1810 $paymentobj->note_private = $comment;
1812 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1813 if ($payment_id < 0) {
1814 $this->db->rollback();
1815 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1819 $label =
'(CustomerInvoicePayment)';
1821 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1822 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1825 $label =
'(CustomerInvoicePaymentBack)';
1827 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1829 $this->db->rollback();
1830 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1834 $this->db->commit();
1869 public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'', $ref_ext =
'', $accepthigherpayment =
false)
1871 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1873 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1874 throw new RestException(403);
1876 foreach ($arrayofamounts as
$id => $amount) {
1878 throw new RestException(400,
'Invoice ID is mandatory. Fill the invoice id and amount into arrayofamounts parameter. For example: {"1": "99.99", "2": "10"}');
1881 throw new RestException(403,
'Access not allowed on invoice ID '.
$id.
' for login '.DolibarrApiAccess::$user->login);
1886 if (empty($accountid)) {
1887 throw new RestException(400,
'Account ID is mandatory');
1890 if (empty($paymentid)) {
1891 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1897 $multicurrency_amounts = array();
1900 foreach ($arrayofamounts as
$id => $amountarray) {
1902 $result = $this->invoice->fetch(
$id);
1904 $this->db->rollback();
1905 throw new RestException(404,
'Invoice ID '.
$id.
' not found');
1908 if (($amountarray[
"amount"] ==
"remain" || $amountarray[
"amount"] > 0) && ($amountarray[
"multicurrency_amount"] ==
"remain" || $amountarray[
"multicurrency_amount"] > 0)) {
1909 $this->db->rollback();
1910 throw new RestException(400,
'Payment in both currency '.
$id.
' ( amount: '.$amountarray[
"amount"].
', multicurrency_amount: '.$amountarray[
"multicurrency_amount"].
')');
1913 $is_multicurrency = 0;
1914 $total_ttc = $this->invoice->total_ttc;
1916 if ($amountarray[
"multicurrency_amount"] > 0 || $amountarray[
"multicurrency_amount"] ==
"remain") {
1917 $is_multicurrency = 1;
1918 $total_ttc = $this->invoice->multicurrency_total_ttc;
1922 $totalpaid = $this->invoice->getSommePaiement($is_multicurrency);
1923 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency);
1924 $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
1925 $remainstopay = $amount = (float)
price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1927 if (!$is_multicurrency && $amountarray[
"amount"] !=
'remain') {
1928 $amount = (float)
price2num($amountarray[
"amount"],
'MT');
1931 if ($is_multicurrency && $amountarray[
"multicurrency_amount"] !=
'remain') {
1932 $amount = (float)
price2num($amountarray[
"multicurrency_amount"],
'MT');
1935 if (abs($amount) > abs($remainstopay) && !$accepthigherpayment) {
1936 $this->db->rollback();
1937 throw new RestException(400,
'Payment amount on invoice ID '.
$id.
' ('.$amount.
') is higher than remain to pay ('.$remainstopay.
')');
1941 $amount = (float)
price2num(-1 * abs((
float) $amount),
'MT');
1944 if ($is_multicurrency) {
1945 $amounts[
$id] =
null;
1947 $multicurrency_amounts[
$id] = (float) $amount;
1949 $amounts[
$id] = (float) $amount;
1951 $multicurrency_amounts[
$id] =
null;
1956 $paymentobj =
new Paiement($this->db);
1957 if (is_numeric($datepaye)) {
1958 $paymentobj->datepaye = $datepaye;
1962 $paymentobj->amounts = $amounts;
1963 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1964 $paymentobj->paiementid = $paymentid;
1965 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1966 $paymentobj->num_payment = $num_payment;
1967 $paymentobj->note_private = $comment;
1968 $paymentobj->ref_ext = $ref_ext;
1969 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1970 if ($payment_id < 0) {
1971 $this->db->rollback();
1972 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1975 $label =
'(CustomerInvoicePayment)';
1976 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1977 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1980 $label =
'(CustomerInvoicePaymentBack)';
1982 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1984 $this->db->rollback();
1985 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1989 $this->db->commit();
2014 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
2016 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
2017 throw new RestException(403);
2020 throw new RestException(400,
'Payment ID is mandatory');
2023 $paymentobj =
new Paiement($this->db);
2024 $result = $paymentobj->fetch(
$id);
2027 throw new RestException(404,
'Payment not found');
2030 if (!empty($num_payment)) {
2031 $result = $paymentobj->update_num($num_payment);
2033 throw new RestException(500,
'Error when updating the payment num');
2040 'message' =>
'Payment updated'
2063 unset(
$object->barcode_type_code);
2064 unset(
$object->barcode_type_label);
2065 unset(
$object->barcode_type_coder);
2081 if ($data ===
null) {
2085 foreach (Invoices::$FIELDS as $field) {
2086 if (!isset($data[$field])) {
2087 throw new RestException(400,
"$field field missing");
2089 $invoice[$field] = $data[$field];
2143 public function indexTemplateInvoices($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
2145 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2146 throw new RestException(403);
2152 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
2157 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
2158 $search_sale = DolibarrApiAccess::$user->id;
2161 $sql =
"SELECT t.rowid";
2162 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_rec AS t";
2163 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
2164 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_rec_extrafields AS ef ON (ef.fk_object = t.rowid)";
2165 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
2167 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
2171 if ($search_sale && $search_sale !=
'-1') {
2172 if ($search_sale == -2) {
2173 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux AS sc WHERE sc.fk_soc = t.fk_soc)";
2174 } elseif ($search_sale > 0) {
2175 $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).
")";
2180 if ($status ==
'active') {
2181 $sql .=
" AND t.suspended = 0 AND t.frequency IS NOT NULL";
2183 if ($status ==
'suspended') {
2184 $sql .=
" AND t.suspended = 1 AND t.frequency IS NOT NULL";
2186 if ($status ==
'draft') {
2187 $sql .=
" AND t.frequency IS NULL";
2192 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2193 if ($errormessage) {
2194 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2199 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
2201 $sql .= $this->db->order($sortfield, $sortorder);
2206 $offset = $limit * $page;
2208 $sql .= $this->db->plimit($limit + 1, $offset);
2211 $result = $this->db->query($sql);
2214 $num = $this->db->num_rows($result);
2215 $min = min($num, ($limit <= 0 ? $num : $limit));
2217 $obj = $this->db->fetch_object($result);
2219 if ($factureRec->fetch($obj->rowid) > 0) {
2220 if ($loadlinkedobjects) {
2222 $factureRec->fetchObjectLinked();
2226 unset($factureRec->lines);
2234 throw new RestException(503,
'Error when retrieving recurring invoice templates: '.$this->db->lasterror());
2238 if ($pagination_data) {
2239 $totalsResult = $this->db->query($sqlTotals);
2240 $total = $this->db->fetch_object($totalsResult)->total;
2245 $obj_ret[
'data'] = $tmp;
2246 $obj_ret[
'pagination'] = array(
2247 'total' => (
int) $total,
2249 'page_count' => ceil((
int) $total / $limit),
2272 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2273 throw new RestException(403);
2276 $result = $this->template_invoice->fetch(
$id, $ref, $ref_ext);
2278 throw new RestException(404,
'Template invoice not found');
2282 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2286 if ($contact_list > -1) {
2287 $tmparray = $this->template_invoice->liste_contact(-1,
'external', $contact_list);
2288 if (is_array($tmparray)) {
2289 $this->template_invoice->contacts_ids = $tmparray;
2293 $this->template_invoice->fetchObjectLinked();
2313 unset(
$object->barcode_type_code);
2314 unset(
$object->barcode_type_label);
2315 unset(
$object->barcode_type_coder);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
Class to manage customers orders.
Class to manage absolute discounts.
_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.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice templates.
putPayment($id, $num_payment='')
Update a payment.
addContact($id, $fk_socpeople, $type_contact, $source, $notrigger=0)
Adds a contact to an invoice.
indexTemplateInvoices($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='', $properties='', $pagination_data=false, $loadlinkedobjects=0, $withLines=true)
List template invoices.
createInvoiceFromOrder($orderid)
Create an invoice using an existing order.
markAsCreditAvailable($id)
Create a discount (credit available) for a credit note or a deposit.
getDiscount($id)
Get discount from invoice.
__construct()
Constructor.
put($id, $request_data=null)
Update invoice.
validate($id, $force_number='', $idwarehouse=0, $notrigger=0)
Validate an invoice.
getContacts($id, $type='')
Get contacts of given invoice.
getByRefExt($ref_ext, $contact_list=1)
Get properties of an invoice object by ref_ext.
_fetch($id, $ref='', $ref_ext='', $contact_list=1)
Get properties of an invoice object.
getByRef($ref, $contact_list=1)
Get properties of an invoice object by ref.
getPayments($id)
Get list of payments of a given invoice.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
post($request_data=null)
Create invoice object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='', $properties='', $pagination_data=false, $loadlinkedobjects=0, $withLines=true)
List invoices.
useDiscount($id, $discountid)
Add a discount line into an invoice (as an invoice line) using an existing absolute discount.
settounpaid($id)
Sets an invoice as unpaid.
getTemplateInvoice($id, $contact_list=1)
Get properties of a template invoice object.
putLine($id, $lineid, $request_data=null)
Update a line to a given invoice.
getLines($id)
Get lines of an invoice.
useCreditNote($id, $discountid)
Add an available credit note discount to payments of an existing invoice.
createInvoiceFromContract($contractid)
Create an invoice using a contract.
addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='', $ref_ext='', $accepthigherpayment=false)
Add a payment to pay partially or completely one or several invoices.
postContact($id, $contactid, $type, $source='external', $notrigger=0)
Add a contact type of given invoice.
_cleanTemplateObjectDatas($object)
Clean sensible object datas.
deleteContact($id, $contactid, $type)
Delete a contact type of given invoice.
postLine($id, $request_data=null)
Add a line to a given invoice.
_fetchTemplateInvoice($id, $ref='', $ref_ext='', $contact_list=1)
Get properties of an invoice object.
_validate($data)
Validate fields before create or update object.
addPayment($id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='')
Add payment line to a specific invoice with the remain to pay as amount.
settopaid($id, $close_code='', $close_note='')
Sets an invoice as paid.
settodraft($id, $idwarehouse=-1)
Sets an invoice as draft.
deleteLine($id, $lineid)
Deletes a line of a given invoice.
Class to manage payments of customer invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_now($mode='gmt')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.