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 $result = $this->invoice->createFromContract($contract, DolibarrApiAccess::$user);
509 throw new RestException(405, $this->invoice->error);
511 $this->invoice->fetchObjectLinked();
529 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
530 throw new RestException(403);
533 $result = $this->invoice->fetch(
$id);
535 throw new RestException(404,
'Invoice not found');
539 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
541 $this->invoice->getLinesArray();
543 foreach ($this->invoice->lines as $line) {
569 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
570 throw new RestException(403);
573 $result = $this->invoice->fetch(
$id);
575 throw new RestException(404,
'Invoice not found');
579 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
582 $request_data = (object) $request_data;
584 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
585 $request_data->label =
sanitizeVal($request_data->label);
587 $updateRes = $this->invoice->updateline(
590 $request_data->subprice,
592 $request_data->remise_percent,
593 $request_data->date_start,
594 $request_data->date_end,
595 $request_data->tva_tx,
596 $request_data->localtax1_tx,
597 $request_data->localtax2_tx,
598 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
599 $request_data->info_bits,
600 $request_data->product_type,
601 $request_data->fk_parent_line,
603 $request_data->fk_fournprice,
604 $request_data->pa_ht,
605 $request_data->label,
606 $request_data->special_code,
607 $request_data->array_options,
608 $request_data->situation_percent,
609 $request_data->fk_unit,
610 $request_data->multicurrency_subprice,
612 $request_data->ref_ext,
616 if ($updateRes > 0) {
617 $result = $this->
get(
$id);
618 unset($result->line);
621 throw new RestException(304, $this->invoice->error);
644 public function postContact(
$id, $contactid, $type, $source =
'external', $notrigger = 0)
646 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
647 throw new RestException(403);
651 if (empty($source)) {
652 throw new RestException(400,
'Source can not be empty');
654 $sql_distinct_source =
"SELECT DISTINCT source";
655 $sql_distinct_source .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
656 $sql_distinct_source .=
" WHERE element LIKE 'facture'";
657 $sql_distinct_source .=
" AND source is NOT NULL";
658 $sql_distinct_source .=
" AND active != 0";
659 $source_result = $this->db->query($sql_distinct_source);
660 $source_array = array();
662 if ($source_result) {
663 $num = $this->db->num_rows($source_result);
666 $obj = $this->db->fetch_object($source_result);
667 $source_kind = (
string) $obj->source;
668 array_push($source_array, $source_kind);
673 throw new RestException(503,
'Error when retrieving a list of invoice contact sources: '.$this->db->lasterror());
675 if (!in_array($source, (array) $source_array,
true)) {
676 throw new RestException(400,
'Combo of Source='.$source.
' and Type='.$type.
' not found in dictionary with active invoice contact types');
681 throw new RestException(400,
'type can not be empty');
684 $sql_distinct_type =
"SELECT DISTINCT code";
685 $sql_distinct_type .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact";
686 $sql_distinct_type .=
" WHERE element LIKE 'facture'";
687 $sql_distinct_type .=
" AND source='".$this->db->escape($source).
"'";
688 $sql_distinct_type .=
" AND code is NOT NULL";
689 $sql_distinct_type .=
" AND active != 0";
690 $type_result = $this->db->query($sql_distinct_type);
691 $type_array = array();
694 $num = $this->db->num_rows($type_result);
697 $obj = $this->db->fetch_object($type_result);
699 $type_kind = (
string) $obj->code;
700 array_push($type_array, $type_kind);
705 throw new RestException(503,
'Error when retrieving a list of invoice contact types: '.$this->db->lasterror());
707 if (!in_array($type, (array) $type_array,
true)) {
708 throw new RestException(400,
'Combo of Type='.$type.
' and Source='.$source.
' not found in dictionary with active invoice contact types');
712 $result = $this->invoice->fetch(
$id);
714 throw new RestException(404,
'Invoice not found');
717 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
720 $result = $this->invoice->add_contact($contactid, $type, $source, $notrigger);
723 throw new RestException(400,
'Already exists: Contact='.$contactid.
' is already linked to the invoice='.
$id.
' as source='.$source.
' and type='.$type);
724 } elseif ($result == -1) {
725 throw new RestException(400,
'Wrong contact='.$contactid);
726 } elseif ($result == -2) {
727 throw new RestException(400,
'Wrong type='.$type);
728 } elseif ($result == -3) {
729 throw new RestException(400,
'Not allowed contacts');
730 } elseif ($result == -4) {
731 throw new RestException(400,
'ErrorCommercialNotAllowedForThirdparty');
732 } elseif ($result == -5) {
733 throw new RestException(400,
'Trigger failed');
734 } elseif ($result == -6) {
735 throw new RestException(400,
'DB_ERROR_RECORD_ALREADY_EXISTS');
736 } elseif ($result == -7) {
737 throw new RestException(400,
'Some other error');
741 throw new RestException(500,
'Error when added the contact');
747 'message' =>
'Contact='.$contactid.
' linked to the invoice='.
$id.
' as '.$source.
' '.$type
769 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
770 throw new RestException(403);
773 $result = $this->invoice->fetch(
$id);
775 throw new RestException(404,
'Invoice not found');
779 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
782 $contacts = $this->invoice->liste_contact(-1,
'external', 0, $type);
783 $socpeoples = $this->invoice->liste_contact(-1,
'internal', 0, $type);
785 $contacts = array_merge($contacts, $socpeoples);
808 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
809 throw new RestException(403);
812 $result = $this->invoice->fetch(
$id);
815 throw new RestException(404,
'Invoice not found');
819 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
822 $contacts = $this->invoice->liste_contact();
824 foreach ($contacts as $contact) {
825 if ($contact[
'id'] == $contactid && $contact[
'code'] == $type) {
826 $result = $this->invoice->delete_contact($contact[
'rowid']);
829 throw new RestException(500,
'Error when deleted the contact');
855 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
856 throw new RestException(403);
858 if (empty($lineid)) {
859 throw new RestException(400,
'Line ID is mandatory');
863 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
866 $result = $this->invoice->fetch(
$id);
868 throw new RestException(404,
'Invoice not found');
870 if ($this->invoice->status != 0) {
871 throw new RestException(403,
'Invoice not in Draft Status : '.$this->invoice->getLibStatut(1));
874 $updateRes = $this->invoice->deleteLine($lineid,
$id);
875 if ($updateRes > 0) {
876 return $this->
get(
$id);
878 throw new RestException(405, $this->invoice->error);
893 public function put(
$id, $request_data =
null)
895 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
896 throw new RestException(403);
899 throw new RestException(400,
'No invoice with id=0 can exist');
901 $result = $this->invoice->fetch(
$id);
903 throw new RestException(404,
'Invoice not found');
907 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
910 foreach ($request_data as $field => $value) {
911 if ($field ==
'id') {
914 if ($field ===
'caller') {
916 $this->invoice->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
919 if ($field ==
'array_options' && is_array($value)) {
920 foreach ($value as $index => $val) {
926 $this->invoice->$field = $this->
_checkValForAPI($field, $value, $this->invoice);
929 if ($field ==
'cond_reglement_id') {
930 $this->invoice->date_lim_reglement = $this->invoice->calculate_date_lim_reglement();
935 if (!empty($this->invoice->fk_account)) {
936 if ($this->invoice->setBankAccount((
int) $this->invoice->fk_account) == 0) {
937 throw new RestException(400, $this->invoice->error);
941 if ($this->invoice->update(DolibarrApiAccess::$user) > 0) {
942 return $this->
get(
$id);
944 throw new RestException(500, $this->invoice->error);
958 public function delete(
$id)
960 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'supprimer')) {
961 throw new RestException(403);
964 throw new RestException(400,
'No invoice with id=0 can exist');
966 $result = $this->invoice->fetch(
$id);
968 throw new RestException(404,
'Invoice not found');
972 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
975 $result = $this->invoice->delete(DolibarrApiAccess::$user);
977 throw new RestException(500,
'Error when deleting invoice');
978 } elseif ($result == 0) {
979 throw new RestException(403,
'Invoice not erasable');
985 'message' =>
'Invoice deleted'
1019 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1020 throw new RestException(403);
1023 $result = $this->invoice->fetch(
$id);
1025 throw new RestException(404,
'Invoice not found');
1029 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1032 $request_data = (object) $request_data;
1034 $request_data->desc =
sanitizeVal($request_data->desc,
'restricthtml');
1035 $request_data->label =
sanitizeVal($request_data->label);
1038 if (($request_data->product_type != 9 && empty($request_data->fk_parent_line)) || $request_data->product_type == 9) {
1039 $request_data->fk_parent_line = 0;
1043 $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);
1044 $pa_ht = $marginInfos[0];
1046 $updateRes = $this->invoice->addline(
1047 $request_data->desc,
1048 $request_data->subprice,
1050 $request_data->tva_tx,
1051 $request_data->localtax1_tx,
1052 $request_data->localtax2_tx,
1053 $request_data->fk_product,
1054 $request_data->remise_percent,
1055 $request_data->date_start,
1056 $request_data->date_end,
1057 $request_data->fk_code_ventilation,
1058 $request_data->info_bits,
1059 $request_data->fk_remise_except,
1060 $request_data->price_base_type ? $request_data->price_base_type :
'HT',
1061 $request_data->subprice,
1062 $request_data->product_type,
1063 $request_data->rang,
1064 $request_data->special_code,
1065 $request_data->origin,
1066 $request_data->origin_id,
1067 $request_data->fk_parent_line,
1068 empty($request_data->fk_fournprice) ? null : $request_data->fk_fournprice,
1070 $request_data->label,
1071 $request_data->array_options,
1072 $request_data->situation_percent,
1073 $request_data->fk_prev_id,
1074 $request_data->fk_unit,
1076 $request_data->ref_ext
1079 if ($updateRes < 0) {
1080 throw new RestException(400,
'Unable to insert the new line. Check your inputs. '.$this->invoice->error);
1106 public function addContact(
$id, $fk_socpeople, $type_contact, $source, $notrigger = 0)
1108 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1109 throw new RestException(403);
1111 $result = $this->invoice->fetch(
$id);
1113 throw new RestException(404,
'Invoice not found');
1117 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1120 $result = $this->invoice->add_contact($fk_socpeople, $type_contact, $source, $notrigger);
1122 throw new RestException(500,
'Error : '.$this->invoice->error);
1125 $result = $this->invoice->fetch(
$id);
1127 throw new RestException(404,
'Invoice not found');
1158 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1159 throw new RestException(403);
1161 $result = $this->invoice->fetch(
$id);
1163 throw new RestException(404,
'Invoice not found');
1167 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1170 $result = $this->invoice->setDraft(DolibarrApiAccess::$user, $idwarehouse);
1172 throw new RestException(304,
'Nothing done.');
1175 throw new RestException(500,
'Error : '.$this->invoice->error);
1178 $result = $this->invoice->fetch(
$id);
1180 throw new RestException(404,
'Invoice not found');
1206 public function validate(
$id, $force_number =
'', $idwarehouse = 0, $notrigger = 0)
1208 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1209 throw new RestException(403);
1211 $result = $this->invoice->fetch(
$id);
1213 throw new RestException(404,
'Invoice not found');
1217 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1220 $result = $this->invoice->validate(DolibarrApiAccess::$user, $force_number, $idwarehouse, $notrigger);
1222 throw new RestException(304,
'Error nothing done. May be object is already validated');
1225 throw new RestException(500,
'Error when validating Invoice: '.$this->invoice->error);
1228 $result = $this->invoice->fetch(
$id);
1230 throw new RestException(404,
'Invoice not found');
1239 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1240 $this->invoice->online_payment_url = getOnlinePaymentUrl(0,
'invoice', (
string) $this->invoice->ref);
1264 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1265 throw new RestException(403);
1267 $result = $this->invoice->fetch(
$id);
1269 throw new RestException(404,
'Invoice not found');
1273 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1276 $result = $this->invoice->setPaid(DolibarrApiAccess::$user, $close_code, $close_note);
1278 throw new RestException(304,
'Error nothing done. May be object is already validated');
1281 throw new RestException(500,
'Error : '.$this->invoice->error);
1285 $result = $this->invoice->fetch(
$id);
1287 throw new RestException(404,
'Invoice not found');
1316 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1317 throw new RestException(403);
1319 $result = $this->invoice->fetch(
$id);
1321 throw new RestException(404,
'Invoice not found');
1325 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1328 $result = $this->invoice->setUnpaid(DolibarrApiAccess::$user);
1330 throw new RestException(304,
'Nothing done');
1333 throw new RestException(500,
'Error : '.$this->invoice->error);
1337 $result = $this->invoice->fetch(
$id);
1339 throw new RestException(404,
'Invoice not found');
1362 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1364 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1365 throw new RestException(403);
1368 $result = $this->invoice->fetch(
$id);
1370 throw new RestException(404,
'Invoice not found');
1374 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1378 $result = $discountcheck->fetch(0, $this->invoice->id);
1381 throw new RestException(404,
'Discount not found');
1384 throw new RestException(500, $discountcheck->error);
1387 return parent::_cleanObjectDatas($discountcheck);
1407 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1409 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1410 throw new RestException(403);
1413 $result = $this->invoice->fetch(
$id);
1415 throw new RestException(404,
'Invoice not found');
1419 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1422 if ($this->invoice->paye) {
1423 throw new RestException(500,
'Alreay paid');
1426 $this->invoice->fetch(
$id);
1427 $this->invoice->fetch_thirdparty();
1431 $result = $discountcheck->fetch(0, $this->invoice->id);
1443 $amount_ht = $amount_tva = $amount_ttc = array();
1444 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
1446 @phan-var-force array<string,float> $amount_ht
1447 @phan-var-force array<string,float> $amount_tva
1448 @phan-var-force array<string,float> $amount_ttc
1449 @phan-var-force array<string,float> $multicurrency_amount_ht
1450 @phan-var-force array<string,float> $multicurrency_amount_tva
1451 @phan-var-force array<string,float> $multicurrency_amount_ttc
1456 foreach ($this->invoice->lines as $line) {
1457 if ($line->product_type < 9 && $line->total_ht != 0) {
1458 if (!array_key_exists($line->tva_tx, $amount_ht)) {
1459 $amount_ht[$line->tva_tx] = 0.0;
1460 $amount_tva[$line->tva_tx] = 0.0;
1461 $amount_ttc[$line->tva_tx] = 0.0;
1462 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
1463 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
1464 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
1467 $amount_ht[$line->tva_tx] += $line->total_ht;
1468 $amount_tva[$line->tva_tx] += $line->total_tva;
1469 $amount_ttc[$line->tva_tx] += $line->total_ttc;
1470 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
1471 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
1472 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
1480 $discount->description =
'(CREDIT_NOTE)';
1482 $discount->description =
'(DEPOSIT)';
1484 $discount->description =
'(EXCESS RECEIVED)';
1486 throw new RestException(500,
'Cant convert to reduc an Invoice of this type');
1489 $discount->fk_soc = $this->invoice->socid;
1490 $discount->socid = $this->invoice->socid;
1491 $discount->fk_facture_source = $this->invoice->id;
1499 $sql =
'SELECT SUM(pf.amount) as total_payments';
1500 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf, '.MAIN_DB_PREFIX.
'paiement as p';
1501 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
1502 $sql .=
' WHERE pf.fk_facture = '.((int) $this->invoice->id);
1503 $sql .=
' AND pf.fk_paiement = p.rowid';
1504 $sql .=
' AND p.entity IN ('.getEntity(
'invoice').
')';
1505 $resql = $this->db->query($sql);
1510 $res = $this->db->fetch_object($resql);
1511 $total_payments = $res->total_payments;
1514 $total_creditnote_and_deposit = 0;
1515 $sql =
"SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
1516 $sql .=
" re.description, re.fk_facture_source";
1517 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re";
1518 $sql .=
" WHERE fk_facture = ".((int) $this->invoice->id);
1519 $resql = $this->db->query($sql);
1520 if (!empty($resql)) {
1521 while ($obj = $this->db->fetch_object($resql)) {
1522 $total_creditnote_and_deposit += $obj->amount_ttc;
1528 $discount->amount_ht = $discount->amount_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1529 $discount->total_ht = $discount->total_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
1530 $discount->amount_tva = 0;
1531 $discount->total_tva = 0;
1532 $discount->tva_tx = 0;
1534 $result = $discount->create(DolibarrApiAccess::$user);
1540 foreach ($amount_ht as $tva_tx => $xxx) {
1541 $discount->amount_ht = abs($amount_ht[$tva_tx]);
1542 $discount->amount_tva = abs($amount_tva[$tva_tx]);
1543 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
1544 $discount->total_ht = abs($amount_ht[$tva_tx]);
1545 $discount->total_tva = abs($amount_tva[$tva_tx]);
1546 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
1547 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
1548 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
1549 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1550 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
1551 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
1552 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
1553 $discount->tva_tx = abs((
float) $tva_tx);
1555 $result = $discount->create(DolibarrApiAccess::$user);
1563 if (empty($error)) {
1566 $result = $this->invoice->setPaid(DolibarrApiAccess::$user);
1568 $this->db->commit();
1570 $this->db->rollback();
1571 throw new RestException(500,
'Could not set paid');
1574 $this->db->commit();
1577 $this->db->rollback();
1578 throw new RestException(500,
'Discount creation error');
1605 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1606 throw new RestException(403);
1609 throw new RestException(400,
'Invoice ID is mandatory');
1611 if (empty($discountid)) {
1612 throw new RestException(400,
'Discount ID is mandatory');
1616 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1619 $result = $this->invoice->fetch(
$id);
1621 throw new RestException(404,
'Invoice not found');
1624 $result = $this->invoice->insert_discount($discountid);
1626 throw new RestException(405, $this->invoice->error);
1652 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
1654 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
1655 throw new RestException(403);
1658 throw new RestException(400,
'Invoice ID is mandatory');
1660 if (empty($discountid)) {
1661 throw new RestException(400,
'Credit ID is mandatory');
1665 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1668 $result = $discount->fetch($discountid);
1670 throw new RestException(404,
'Credit not found');
1673 $result = $discount->link_to_invoice(0,
$id);
1675 throw new RestException(405, $discount->error);
1700 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1701 throw new RestException(403);
1704 throw new RestException(400,
'Invoice ID is mandatory');
1708 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1711 $result = $this->invoice->fetch(
$id);
1713 throw new RestException(404,
'Invoice not found');
1716 $result = $this->invoice->getListOfPayments();
1717 if (!is_array($result) && $result < 0) {
1718 throw new RestException(405, $this->invoice->error);
1748 public function addPayment(
$id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'')
1750 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1752 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1753 throw new RestException(403);
1756 throw new RestException(400,
'Invoice ID is mandatory');
1760 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
1764 if (empty($accountid)) {
1765 throw new RestException(400,
'Account ID is mandatory');
1769 if (empty($paymentid)) {
1770 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1774 $result = $this->invoice->fetch(
$id);
1776 throw new RestException(404,
'Invoice not found');
1780 $totalpaid = $this->invoice->getSommePaiement();
1781 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
1782 $totaldeposits = $this->invoice->getSumDepositsUsed();
1787 $multicurrency_amounts = array();
1791 $resteapayer =
price2num($this->invoice->total_ttc + $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1792 $amounts[
$id] = (float)
price2num(-1 * abs((
float) $resteapayer),
'MT');
1794 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1795 $multicurrency_amounts[
$id] = (float)
price2num(-1 * (
float) $newvalue,
'MT');
1797 $resteapayer =
price2num($this->invoice->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1798 $amounts[
$id] = (float) $resteapayer;
1800 $newvalue =
price2num($this->invoice->multicurrency_total_ttc,
'MT');
1801 $multicurrency_amounts[
$id] = (float) $newvalue;
1805 $paymentobj =
new Paiement($this->db);
1806 if (is_numeric($datepaye)) {
1807 $paymentobj->datepaye = $datepaye;
1811 $paymentobj->amounts = $amounts;
1812 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1813 $paymentobj->paiementid = $paymentid;
1814 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1815 $paymentobj->num_payment = $num_payment;
1816 $paymentobj->note_private = $comment;
1818 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1819 if ($payment_id < 0) {
1820 $this->db->rollback();
1821 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1825 $label =
'(CustomerInvoicePayment)';
1827 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1828 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1831 $label =
'(CustomerInvoicePaymentBack)';
1833 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1835 $this->db->rollback();
1836 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1840 $this->db->commit();
1875 public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment =
'', $comment =
'', $chqemetteur =
'', $chqbank =
'', $ref_ext =
'', $accepthigherpayment =
false)
1877 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1879 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
1880 throw new RestException(403);
1882 foreach ($arrayofamounts as
$id => $amount) {
1884 throw new RestException(400,
'Invoice ID is mandatory. Fill the invoice id and amount into arrayofamounts parameter. For example: {"1": "99.99", "2": "10"}');
1887 throw new RestException(403,
'Access not allowed on invoice ID '.
$id.
' for login '.DolibarrApiAccess::$user->login);
1892 if (empty($accountid)) {
1893 throw new RestException(400,
'Account ID is mandatory');
1896 if (empty($paymentid)) {
1897 throw new RestException(400,
'Payment ID or Payment Code is mandatory');
1903 $multicurrency_amounts = array();
1906 foreach ($arrayofamounts as
$id => $amountarray) {
1908 $result = $this->invoice->fetch(
$id);
1910 $this->db->rollback();
1911 throw new RestException(404,
'Invoice ID '.
$id.
' not found');
1914 if (($amountarray[
"amount"] ==
"remain" || $amountarray[
"amount"] > 0) && ($amountarray[
"multicurrency_amount"] ==
"remain" || $amountarray[
"multicurrency_amount"] > 0)) {
1915 $this->db->rollback();
1916 throw new RestException(400,
'Payment in both currency '.
$id.
' ( amount: '.$amountarray[
"amount"].
', multicurrency_amount: '.$amountarray[
"multicurrency_amount"].
')');
1919 $is_multicurrency = 0;
1920 $total_ttc = $this->invoice->total_ttc;
1922 if ($amountarray[
"multicurrency_amount"] > 0 || $amountarray[
"multicurrency_amount"] ==
"remain") {
1923 $is_multicurrency = 1;
1924 $total_ttc = $this->invoice->multicurrency_total_ttc;
1928 $totalpaid = $this->invoice->getSommePaiement($is_multicurrency);
1929 $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency);
1930 $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
1931 $remainstopay = $amount = (float)
price2num($total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1933 if (!$is_multicurrency && $amountarray[
"amount"] !=
'remain') {
1934 $amount = (float)
price2num($amountarray[
"amount"],
'MT');
1937 if ($is_multicurrency && $amountarray[
"multicurrency_amount"] !=
'remain') {
1938 $amount = (float)
price2num($amountarray[
"multicurrency_amount"],
'MT');
1941 if (abs($amount) > abs($remainstopay) && !$accepthigherpayment) {
1942 $this->db->rollback();
1943 throw new RestException(400,
'Payment amount on invoice ID '.
$id.
' ('.$amount.
') is higher than remain to pay ('.$remainstopay.
')');
1947 $amount = (float)
price2num(-1 * abs((
float) $amount),
'MT');
1950 if ($is_multicurrency) {
1951 $amounts[
$id] =
null;
1953 $multicurrency_amounts[
$id] = (float) $amount;
1955 $amounts[
$id] = (float) $amount;
1957 $multicurrency_amounts[
$id] =
null;
1962 $paymentobj =
new Paiement($this->db);
1963 if (is_numeric($datepaye)) {
1964 $paymentobj->datepaye = $datepaye;
1968 $paymentobj->amounts = $amounts;
1969 $paymentobj->multicurrency_amounts = $multicurrency_amounts;
1970 $paymentobj->paiementid = $paymentid;
1971 $paymentobj->paiementcode = (
string)
dol_getIdFromCode($this->db, (
string) $paymentid,
'c_paiement',
'id',
'code', 1);
1972 $paymentobj->num_payment = $num_payment;
1973 $paymentobj->note_private = $comment;
1974 $paymentobj->ref_ext = $ref_ext;
1975 $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices ==
'yes' ? 1 : 0));
1976 if ($payment_id < 0) {
1977 $this->db->rollback();
1978 throw new RestException(400,
'Payment error : '.$paymentobj->error);
1981 $label =
'(CustomerInvoicePayment)';
1982 if ($paymentobj->paiementcode ==
'CHQ' && empty($chqemetteur)) {
1983 throw new RestException(400,
'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
1986 $label =
'(CustomerInvoicePaymentBack)';
1988 $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user,
'payment', $label, $accountid, $chqemetteur, $chqbank);
1990 $this->db->rollback();
1991 throw new RestException(400,
'Add payment to bank error : '.$paymentobj->error);
1995 $this->db->commit();
2020 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
2022 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
2023 throw new RestException(403);
2026 throw new RestException(400,
'Payment ID is mandatory');
2029 $paymentobj =
new Paiement($this->db);
2030 $result = $paymentobj->fetch(
$id);
2033 throw new RestException(404,
'Payment not found');
2037 $tmparray = $paymentobj->getBillsArray();
2038 foreach ($tmparray as $tmpinvoiceid) {
2040 throw new RestException(403,
'Payment is on invoices that are not all allowed for login '.DolibarrApiAccess::$user->login);
2044 if (!empty($num_payment)) {
2045 $result = $paymentobj->update_num($num_payment);
2047 throw new RestException(500,
'Error when updating the payment num');
2054 'message' =>
'Payment updated'
2077 unset(
$object->barcode_type_code);
2078 unset(
$object->barcode_type_label);
2079 unset(
$object->barcode_type_coder);
2095 if ($data ===
null) {
2099 foreach (Invoices::$FIELDS as $field) {
2100 if (!isset($data[$field])) {
2101 throw new RestException(400,
"$field field missing");
2103 $invoice[$field] = $data[$field];
2157 public function indexTemplateInvoices($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $status =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0, $withLines =
true)
2159 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2160 throw new RestException(403);
2166 $socids = DolibarrApiAccess::$user->socid ?: $thirdparty_ids;
2171 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socids) {
2172 $search_sale = DolibarrApiAccess::$user->id;
2175 $sql =
"SELECT t.rowid";
2176 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_rec AS t";
2177 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe AS s ON (s.rowid = t.fk_soc)";
2178 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_rec_extrafields AS ef ON (ef.fk_object = t.rowid)";
2179 $sql .=
' WHERE t.entity IN ('.getEntity(
'invoice').
')';
2181 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
2185 if ($search_sale && $search_sale !=
'-1') {
2186 if ($search_sale == -2) {
2187 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux AS sc WHERE sc.fk_soc = t.fk_soc)";
2188 } elseif ($search_sale > 0) {
2189 $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).
")";
2194 if ($status ==
'active') {
2195 $sql .=
" AND t.suspended = 0 AND t.frequency IS NOT NULL";
2197 if ($status ==
'suspended') {
2198 $sql .=
" AND t.suspended = 1 AND t.frequency IS NOT NULL";
2200 if ($status ==
'draft') {
2201 $sql .=
" AND t.frequency IS NULL";
2207 if ($errormessage) {
2208 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2213 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
2215 $sql .= $this->db->order($sortfield, $sortorder);
2220 $offset = $limit * $page;
2222 $sql .= $this->db->plimit($limit + 1, $offset);
2225 $result = $this->db->query($sql);
2228 $num = $this->db->num_rows($result);
2229 $min = min($num, ($limit <= 0 ? $num : $limit));
2231 $obj = $this->db->fetch_object($result);
2233 if ($factureRec->fetch($obj->rowid) > 0) {
2234 if ($loadlinkedobjects) {
2236 $factureRec->fetchObjectLinked();
2240 unset($factureRec->lines);
2248 throw new RestException(503,
'Error when retrieving recurring invoice templates: '.$this->db->lasterror());
2252 if ($pagination_data) {
2253 $totalsResult = $this->db->query($sqlTotals);
2254 $total = $this->db->fetch_object($totalsResult)->total;
2259 $obj_ret[
'data'] = $tmp;
2260 $obj_ret[
'pagination'] = array(
2261 'total' => (
int) $total,
2263 'page_count' => ceil((
int) $total / $limit),
2286 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
2287 throw new RestException(403);
2290 $result = $this->template_invoice->fetch(
$id, $ref, $ref_ext);
2292 throw new RestException(404,
'Template invoice not found');
2296 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
2300 if ($contact_list > -1) {
2301 $tmparray = $this->template_invoice->liste_contact(-1,
'external', $contact_list);
2302 if (is_array($tmparray)) {
2303 $this->template_invoice->contacts_ids = $tmparray;
2307 $this->template_invoice->fetchObjectLinked();
2327 unset(
$object->barcode_type_code);
2328 unset(
$object->barcode_type_label);
2329 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.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice templates.
putPayment($id, $num_payment='')
Update a payment.
addContact($id, $fk_socpeople, $type_contact, $source, $notrigger=0)
Adds a contact to an invoice.
indexTemplateInvoices($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='', $properties='', $pagination_data=false, $loadlinkedobjects=0, $withLines=true)
List template invoices.
createInvoiceFromOrder($orderid)
Create an invoice using an existing order.
markAsCreditAvailable($id)
Create a discount (credit available) for a credit note or a deposit.
getDiscount($id)
Get discount from invoice.
__construct()
Constructor.
put($id, $request_data=null)
Update invoice.
validate($id, $force_number='', $idwarehouse=0, $notrigger=0)
Validate an invoice.
getContacts($id, $type='')
Get contacts of given invoice.
getByRefExt($ref_ext, $contact_list=1)
Get properties of an invoice object by ref_ext.
_fetch($id, $ref='', $ref_ext='', $contact_list=1)
Get properties of an invoice object.
getByRef($ref, $contact_list=1)
Get properties of an invoice object by ref.
getPayments($id)
Get list of payments of a given invoice.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
post($request_data=null)
Create invoice object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='', $properties='', $pagination_data=false, $loadlinkedobjects=0, $withLines=true)
List invoices.
useDiscount($id, $discountid)
Add a discount line into an invoice (as an invoice line) using an existing absolute discount.
settounpaid($id)
Sets an invoice as unpaid.
getTemplateInvoice($id, $contact_list=1)
Get properties of a template invoice object.
putLine($id, $lineid, $request_data=null)
Update a line to a given invoice.
getLines($id)
Get lines of an invoice.
useCreditNote($id, $discountid)
Add an available credit note discount to payments of an existing invoice.
createInvoiceFromContract($contractid)
Create an invoice using a contract.
addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='', $ref_ext='', $accepthigherpayment=false)
Add a payment to pay partially or completely one or several invoices.
postContact($id, $contactid, $type, $source='external', $notrigger=0)
Add a contact type of given invoice.
_cleanTemplateObjectDatas($object)
Clean sensible object datas.
deleteContact($id, $contactid, $type)
Delete a contact type of given invoice.
postLine($id, $request_data=null)
Add a line to a given invoice.
_fetchTemplateInvoice($id, $ref='', $ref_ext='', $contact_list=1)
Get properties of an invoice object.
_validate($data)
Validate fields before create or update object.
addPayment($id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='')
Add payment line to a specific invoice with the remain to pay as amount.
settopaid($id, $close_code='', $close_note='')
Sets an invoice as paid.
settodraft($id, $idwarehouse=-1)
Sets an invoice as draft.
deleteLine($id, $lineid)
Deletes a line of a given invoice.
Class to manage payments of customer invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_now($mode='gmt')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.