26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
97 public $totaldeposits;
98 public $totalcreditnotes;
101 public $sumpayed_multicurrency;
103 public $sumdeposit_multicurrency;
104 public $sumcreditnote;
105 public $sumcreditnote_multicurrency;
123 $remaintopay =
price2num($this->total_ttc - $alreadypaid,
'MT');
124 if ($this->statut == self::STATUS_CLOSED && $this->close_code ==
'discount_vat') {
139 $table =
'paiement_facture';
140 $field =
'fk_facture';
141 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
142 $table =
'paiementfourn_facturefourn';
143 $field =
'fk_facturefourn';
146 $sql =
"SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount";
147 $sql .=
" FROM ".$this->db->prefix().$table;
148 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
150 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
154 $obj = $this->
db->fetch_object(
$resql);
159 if ($multicurrency < 0) {
160 $this->sumpayed = $obj->amount;
161 $this->sumpayed_multicurrency = $obj->multicurrency_amount;
162 return array(
'alreadypaid'=>(
float) $obj->amount,
'alreadypaid_multicurrency'=>(
float) $obj->multicurrency_amount);
163 } elseif ($multicurrency) {
164 $this->sumpayed_multicurrency = $obj->multicurrency_amount;
165 return (
float) $obj->multicurrency_amount;
167 $this->sumpayed = $obj->amount;
168 return (
float) $obj->amount;
174 $this->error = $this->
db->lasterror();
194 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
197 $result = $discountstatic->getSumDepositsUsed($this, $multicurrency);
200 if ($multicurrency) {
201 $this->sumdeposit_multicurrency = $result;
203 $this->sumdeposit = $result;
208 $this->error = $discountstatic->error;
221 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
224 $result = $discountstatic->getSumCreditNotesUsed($this, $multicurrency);
226 if ($multicurrency) {
227 $this->sumcreditnote_multicurrency = $result;
229 $this->sumcreditnote = $result;
234 $this->error = $discountstatic->error;
247 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
250 $result = $discountstatic->getSumFromThisCreditNotesNotUsed($this, $multicurrency);
254 $this->error = $discountstatic->error;
268 $sql =
"SELECT rowid";
269 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
270 $sql .=
" WHERE fk_facture_source = ".((int) $this->
id);
271 $sql .=
" AND type = 2";
277 $row = $this->
db->fetch_row(
$resql);
278 $idarray[] = $row[0];
295 $sql =
"SELECT rowid";
296 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
297 $sql .=
" WHERE fk_facture_source = ".((int) $this->
id);
298 $sql .=
" AND type < 2";
299 if ($option ==
'validated') {
300 $sql .=
' AND fk_statut = 1';
307 $sql .=
" ORDER BY fk_statut DESC";
311 $obj = $this->
db->fetch_object(
$resql);
334 $table =
'paiement_facture';
335 $table2 =
'paiement';
336 $field =
'fk_facture';
337 $field2 =
'fk_paiement';
338 $field3 =
', p.ref_ext';
339 $sharedentity =
'facture';
340 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
341 $table =
'paiementfourn_facturefourn';
342 $table2 =
'paiementfourn';
343 $field =
'fk_facturefourn';
344 $field2 =
'fk_paiementfourn';
346 $sharedentity =
'facture_fourn';
349 $sql =
"SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code".$field3;
350 $sql .=
" FROM ".$this->db->prefix().$table.
" as pf, ".$this->
db->prefix().$table2.
" as p, ".$this->
db->prefix().
"c_paiement as t";
351 $sql .=
" WHERE pf.".$field.
" = ".((int) $this->
id);
352 $sql .=
" AND pf.".$field2.
" = p.rowid";
353 $sql .=
' AND p.fk_paiement = t.id';
354 $sql .=
' AND p.entity IN ('.getEntity($sharedentity).
')';
356 $sql .=
" AND t.code='PRE'";
359 dol_syslog(get_class($this).
"::getListOfPayments", LOG_DEBUG);
365 $obj = $this->
db->fetch_object(
$resql);
366 $tmp = array(
'amount'=>$obj->amount,
'type'=>$obj->code,
'date'=>$obj->datep,
'num'=>$obj->num,
'ref'=>$obj->ref);
367 if (!empty($field3)) {
368 $tmp[
'ref_ext'] = $obj->ref_ext;
377 if ($this->element ==
'facture' || $this->element ==
'invoice') {
378 $sql =
"SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type";
379 $sql .=
' FROM '.$this->db->prefix().
'societe_remise_except as rc, '.$this->
db->prefix().
'facture as f';
380 $sql .=
' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $this->
id);
381 $sql .=
' AND (f.type = 2 OR f.type = 0 OR f.type = 3)';
382 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
383 $sql =
"SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type";
384 $sql .=
' FROM '.$this->db->prefix().
'societe_remise_except as rc, '.$this->
db->prefix().
'facture_fourn as f';
385 $sql .=
' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $this->
id);
386 $sql .=
' AND (f.type = 2 OR f.type = 0 OR f.type = 3)';
395 $obj = $this->
db->fetch_object(
$resql);
396 if ($multicurrency) {
397 $retarray[] = array(
'amount'=>$obj->multicurrency_amount,
'type'=>$obj->type,
'date'=>$obj->date,
'num'=>
'0',
'ref'=>$obj->ref);
399 $retarray[] = array(
'amount'=>$obj->amount,
'type'=>$obj->type,
'date'=>$obj->date,
'num'=>
'',
'ref'=>$obj->ref);
404 $this->error = $this->
db->lasterror();
413 $this->error = $this->
db->lasterror();
440 $tmppart = substr($this->
ref, 1, 4);
442 if ($this->statut == self::STATUS_DRAFT && $tmppart ===
'PROV') {
446 if (!empty($conf->global->INVOICE_CAN_NEVER_BE_REMOVED)) {
451 if ($tmppart !==
'PROV') {
453 if ($ventilExportCompta != 0) {
458 if ($this->element !=
'invoice_supplier') {
459 if (empty($this->thirdparty)) {
462 $maxref = $this->getNextNumRef($this->thirdparty,
'last');
466 if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $maxref !=
'' && $maxref != $this->ref) {
473 if ($this->situation_cycle_ref && method_exists($this,
'is_last_in_cycle')) {
474 $last = $this->is_last_in_cycle();
483 if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0) {
497 $alreadydispatched = 0;
499 $type =
'customer_invoice';
500 if ($this->element ==
'invoice_supplier') {
501 $type =
'supplier_invoice';
504 $sql =
" SELECT COUNT(ab.rowid) as nb FROM ".$this->db->prefix().
"accounting_bookkeeping as ab WHERE ab.doc_type='".$this->
db->escape($type).
"' AND ab.fk_doc = ".((int) $this->
id);
507 $obj = $this->
db->fetch_object(
$resql);
509 $alreadydispatched = $obj->nb;
512 $this->error = $this->
db->lasterror();
516 if ($alreadydispatched) {
533 $labellong =
"Unknown";
535 $labellong =
"InvoiceStandard";
536 $labelshort =
"InvoiceStandardShort";
538 $labellong =
"InvoiceReplacement";
539 $labelshort =
"InvoiceReplacementShort";
541 $labellong =
"InvoiceAvoir";
542 $labelshort =
"CreditNote";
544 $labellong =
"InvoiceDeposit";
545 $labelshort =
"Deposit";
547 $labellong =
"InvoiceProForma";
548 $labelshort =
"ProForma";
550 $labellong =
"InvoiceSituation";
551 $labelshort =
"Situation";
556 $out .=
'<span class="badgeneutral" title="'.dol_escape_htmltag($langs->trans($labellong)).
'">';
558 $out .= $langs->trans($withbadge == 2 ? $labelshort : $labellong);
574 return $this->
LibStatut($this->paye, $this->statut, $mode, $alreadypaid, $this->
type);
588 public function LibStatut($paye, $status, $mode = 0, $alreadypaid = -1, $type = -1)
591 global $langs, $hookmanager;
592 $langs->load(
'bills');
598 $statusType =
'status0';
602 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusDraft');
603 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusDraft');
604 } elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) {
606 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusCanceled');
607 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusCanceled');
609 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedUnpaid');
610 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedUnpaid');
612 $statusType =
'status5';
613 } elseif (($status == 3 || $status == 2) && $alreadypaid > 0) {
614 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedPaidPartially');
615 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedPaidPartially');
616 $statusType =
'status9';
617 } elseif ($alreadypaid == 0) {
618 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
619 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusNotPaid');
620 $statusType =
'status1';
622 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusStarted');
623 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusStarted');
624 $statusType =
'status3';
627 $statusType =
'status6';
629 if ($type == self::TYPE_CREDIT_NOTE) {
630 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaidBackOrConverted');
631 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaidBackOrConverted');
632 } elseif ($type == self::TYPE_DEPOSIT) {
633 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusConverted');
634 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusConverted');
636 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaid');
637 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaid');
645 'alreadypaid' => $alreadypaid,
649 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
652 return $hookmanager->resPrint;
657 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
671 if (!$cond_reglement) {
672 $cond_reglement = $this->cond_reglement_code;
674 if (!$cond_reglement) {
675 $cond_reglement = $this->cond_reglement_id;
677 if (!$cond_reglement) {
685 $sqltemp =
"SELECT c.type_cdr, c.nbjour, c.decalage";
686 $sqltemp .=
" FROM ".$this->db->prefix().
"c_payment_term as c";
687 if (is_numeric($cond_reglement)) {
688 $sqltemp .=
" WHERE c.rowid=".((int) $cond_reglement);
690 $sqltemp .=
" WHERE c.entity IN (".getEntity(
'c_payment_term').
")";
691 $sqltemp .=
" AND c.code = '".$this->db->escape($cond_reglement).
"'";
694 dol_syslog(get_class($this).
'::calculate_date_lim_reglement', LOG_DEBUG);
695 $resqltemp = $this->
db->query($sqltemp);
697 if ($this->
db->num_rows($resqltemp)) {
698 $obj = $this->
db->fetch_object($resqltemp);
699 $cdr_nbjour = $obj->nbjour;
700 $cdr_type = $obj->type_cdr;
701 $cdr_decalage = $obj->decalage;
704 $this->error = $this->
db->error();
707 $this->
db->free($resqltemp);
712 if ($cdr_type == 0) {
713 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
715 $datelim += ($cdr_decalage * 3600 * 24);
716 } elseif ($cdr_type == 1) {
718 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
720 $mois = date(
'm', $datelim);
721 $annee = date(
'Y', $datelim);
729 $datelim =
dol_mktime(12, 0, 0, $mois, 1, $annee);
730 $datelim -= (3600 * 24);
732 $datelim += ($cdr_decalage * 3600 * 24);
733 } elseif ($cdr_type == 2 && !empty($cdr_decalage)) {
735 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
736 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
738 $date_piece =
dol_mktime(0, 0, 0, date(
'm', $datelim), date(
'd', $datelim), date(
'Y', $datelim));
739 $date_lim_current =
dol_mktime(0, 0, 0, date(
'm', $datelim), $cdr_decalage, date(
'Y', $datelim));
742 $diff = $date_piece - $date_lim_current;
745 $datelim = $date_lim_current;
747 $datelim = $date_lim_next;
750 return 'Bad value for type_cdr in database for record cond_reglement = '.$cond_reglement;
774 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
776 if ($this->statut > self::STATUS_DRAFT && $this->paye == 0) {
777 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
779 $bac->fetch(0, $this->socid);
781 $sql =
"SELECT count(*)";
782 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
783 if ($type ==
'bank-transfer') {
784 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
786 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
788 $sql .=
" AND ext_payment_id IS NULL";
789 $sql .=
" AND traite = 0";
791 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
794 $row = $this->
db->fetch_row(
$resql);
807 if (empty($amount)) {
808 $amount =
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
811 if (is_numeric($amount) && $amount != 0) {
812 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
813 if ($type ==
'bank-transfer') {
814 $sql .=
'fk_facture_fourn, ';
816 $sql .=
'fk_facture, ';
818 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)';
819 $sql .=
" VALUES (".((int) $this->
id);
820 $sql .=
", ".((float)
price2num($amount));
821 $sql .=
", '".$this->db->idate($now).
"'";
822 $sql .=
", ".((int) $fuser->id);
823 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
824 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
825 $sql .=
", '".$this->db->escape($bac->number).
"'";
826 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
827 $sql .=
", '".$this->db->escape($sourcetype).
"'";
828 $sql .=
", ".((int) $conf->entity);
831 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
834 $this->error = $this->
db->lasterror();
835 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
839 $this->error =
'WithdrawRequestErrorNilAmount';
840 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
846 $payment_mode_id =
dol_getIdFromCode($this->
db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
847 if ($payment_mode_id > 0) {
857 $this->error =
"A request already exists";
858 dol_syslog(get_class($this).
'::demandeprelevement Impossible de creer une demande, demande deja en cours');
862 $this->error = $this->
db->error();
863 dol_syslog(get_class($this).
'::demandeprelevement Erreur -2');
867 $this->error =
"Status of invoice does not allow this";
868 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->statut, $this->paye, $this->mode_reglement_id");
886 global $conf, $mysoc, $user, $langs;
888 if (empty($conf->global->STRIPE_SEPA_DIRECT_DEBIT)) {
895 dol_syslog(get_class($this).
"::makeStripeSepaRequest 0", LOG_DEBUG);
897 if ($this->statut > self::STATUS_DRAFT && $this->paye == 0) {
898 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
900 $result = $bac->fetch(0, $this->socid, 1,
'ban');
901 if ($result <= 0 || empty($bac->id)) {
902 $this->error = $langs->trans(
"ThirdpartyHasNoDefaultBanAccount");
903 $this->errors[] = $this->error;
904 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error);
908 $sql =
"SELECT rowid, date_demande, amount, fk_facture, fk_facture_fourn";
909 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
910 $sql .=
" WHERE rowid = ".((int) $did);
912 dol_syslog(get_class($this).
"::makeStripeSepaRequest 1", LOG_DEBUG);
915 $obj = $this->
db->fetch_object(
$resql);
922 $amount = $obj->amount;
935 $amounttocheck =
price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,
'MT');
939 if (is_numeric($amount) && $amount != 0) {
940 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
942 $companypaymentmode->fetch($bac->id);
945 $service =
'StripeTest';
947 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha')) {
948 $service =
'StripeLive';
952 dol_syslog(
"makeStripeSepaRequest amount = ".$amount.
" service=" . $service .
" servicestatus=" . $servicestatus .
" thirdparty_id=" . $this->socid .
" companypaymentmode=" . $companypaymentmode->id);
954 $this->stripechargedone = 0;
955 $this->stripechargeerror = 0;
958 $currency = $conf->currency;
960 global $stripearrayofkeysbyenv;
961 global $savstripearrayofkeysbyenv;
963 $errorforinvoice = 0;
967 dol_syslog(
"--- Process invoice thirdparty_id=" . $this->
id .
", thirdparty_name=" . $this->thirdparty->name .
" id=" . $this->id .
", ref=" . $this->ref .
", datef=" .
dol_print_date($this->date,
'dayhourlog'), LOG_DEBUG);
971 $amounttopay = $this->total_ttc - $alreadypayed - $amount_credit_notes_included;
975 $arrayzerounitcurrency = [
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF'];
976 $amountstripe = $amounttopay;
977 if (!in_array($currency, $arrayzerounitcurrency)) {
978 $amountstripe = $amountstripe * 100;
981 if ($amountstripe > 0) {
984 dol_syslog(
"We will try to pay with companypaymentmodeid=" . $companypaymentmode->id .
" stripe_card_ref=" . $companypaymentmode->stripe_card_ref .
" mode=" . $companypaymentmode->status, LOG_DEBUG);
987 $resultthirdparty = $thirdparty->fetch($this->socid);
989 include_once DOL_DOCUMENT_ROOT .
'/stripe/class/stripe.class.php';
993 if (empty($savstripearrayofkeysbyenv)) {
994 $savstripearrayofkeysbyenv = $stripearrayofkeysbyenv;
996 dol_syslog(
"makeStripeSepaRequest Current Stripe environment is " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
997 dol_syslog(
"makeStripeSepaRequest Current Saved Stripe environment is " . $savstripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
999 $foundalternativestripeaccount =
'';
1002 if (!empty($thirdparty->array_options[
'options_stripeaccount'])) {
1003 dol_syslog(
"makeStripeSepaRequest The thirdparty id=" . $thirdparty->id .
" has a dedicated Stripe Account, so we switch to it.");
1005 $tmparray = explode(
'@', $thirdparty->array_options[
'options_stripeaccount']);
1006 if (!empty($tmparray[1])) {
1007 $tmparray2 = explode(
':', $tmparray[1]);
1008 if (!empty($tmparray2[3])) {
1009 $stripearrayofkeysbyenv = [
1011 "publishable_key" => $tmparray2[0],
1012 "secret_key" => $tmparray2[1]
1015 "publishable_key" => $tmparray2[2],
1016 "secret_key" => $tmparray2[3]
1020 $stripearrayofkeys = $stripearrayofkeysbyenv[$servicestatus];
1021 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1023 $foundalternativestripeaccount = $tmparray[0];
1025 dol_syslog(
"We use now customer=" . $foundalternativestripeaccount .
" publishable_key=" . $stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1029 if (!$foundalternativestripeaccount) {
1030 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1032 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1033 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1034 dol_syslog(
"We found a bad value for Stripe Account for thirdparty id=" . $thirdparty->id .
", so we ignore it and keep using the global one, so " . $stripearrayofkeys[
'publishable_key'], LOG_WARNING);
1037 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1039 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1040 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1041 dol_syslog(
"The thirdparty id=" . $thirdparty->id .
" has no dedicated Stripe Account, so we use global one, so " . json_encode($stripearrayofkeys), LOG_DEBUG);
1045 dol_syslog(
"makeStripeSepaRequest get stripe account", LOG_DEBUG);
1046 $stripeacc = $stripe->getStripeAccount($service, $this->socid);
1047 dol_syslog(
"makeStripeSepaRequest get stripe account return " . json_encode($stripeacc), LOG_DEBUG);
1049 if ($foundalternativestripeaccount) {
1050 if (empty($stripeacc)) {
1051 $customer = \Stripe\Customer::retrieve([
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources']);
1053 $customer = \Stripe\Customer::retrieve([
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'], [
"stripe_account" => $stripeacc]);
1056 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
1057 if (empty($customer) && !empty($stripe->error)) {
1058 $this->errors[] = $stripe->error;
1069 $postactionmessages = [];
1071 if ($resultthirdparty > 0 && !empty($customer)) {
1072 if (!$error && !empty($this->array_options[
'options_delayautopayment']) && $this->array_options[
'options_delayautopayment'] > $now && empty($calledinmyaccountcontext)) {
1073 $errmsg =
'Payment try was canceled (invoice qualified by the automatic payment was delayed after the ' .
dol_print_date($this->array_options[
'options_delayautopayment'],
'day') .
')';
1078 $this->errors[] = $errmsg;
1084 if ($companypaymentmode->type ==
'ban') {
1086 $stripecard = $stripe->sepaStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1088 $stripecard = $stripe->cardStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1092 $FULLTAG =
'INV=' . $this->
id .
'-CUS=' . $thirdparty->id;
1093 $description =
'Stripe payment from doTakePaymentStripeForThirdparty: ' . $FULLTAG .
' ref=' . $this->ref;
1095 $stripefailurecode =
'';
1096 $stripefailuremessage =
'';
1097 $stripefailuredeclinecode =
'';
1099 if (preg_match(
'/^card_/', $stripecard->id)) {
1100 dol_syslog(
"* Create charge on card " . $stripecard->id .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1106 $charge = \Stripe\Charge::create([
1107 'amount' =>
price2num($amountstripe,
'MU'),
1108 'currency' => $currency,
1110 'description' => $description,
1111 'metadata' => [
"FULLTAG" => $FULLTAG,
'Recipient' => $mysoc->name,
'dol_version' => DOL_VERSION,
'dol_entity' => $conf->entity,
'ipaddress' => $ipaddress],
1112 'customer' => $customer->id,
1114 'source' => $stripecard,
1115 'statement_descriptor' =>
dol_trunc(
'INV=' . $this->
id, 10,
'right',
'UTF-8', 1),
1117 }
catch (\
Stripe\Error\Card $e) {
1119 $body = $e->getJsonBody();
1120 $err = $body[
'error'];
1122 $stripefailurecode = $err[
'code'];
1123 $stripefailuremessage = $err[
'message'];
1124 $stripefailuredeclinecode = $err[
'decline_code'];
1126 $stripefailurecode =
'UnknownChargeError';
1127 $stripefailuremessage = $e->getMessage();
1131 dol_syslog(
"* Create payment on SEPA " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1133 dol_syslog(
"* Create payment on card " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1137 $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer->id, $stripeacc, $servicestatus, 0,
'automatic',
true, $stripecard->id, 1);
1139 $charge =
new stdClass();
1141 if ($paymentintent->status ===
'succeeded' || $paymentintent->status ===
'processing') {
1142 $charge->status =
'ok';
1143 $charge->id = $paymentintent->id;
1144 $charge->customer = $customer->id;
1145 } elseif ($paymentintent->status ===
'requires_action') {
1147 dol_syslog(var_export($paymentintent,
true), LOG_DEBUG);
1149 $charge->status =
'failed';
1150 $charge->customer = $customer->id;
1151 $charge->failure_code = $stripe->code;
1152 $charge->failure_message = $stripe->error;
1153 $charge->failure_declinecode = $stripe->declinecode;
1154 $stripefailurecode = $stripe->code;
1155 $stripefailuremessage =
'Action required. Contact the support at ';
1156 $stripefailuredeclinecode = $stripe->declinecode;
1158 dol_syslog(var_export($paymentintent,
true), LOG_DEBUG);
1160 $charge->status =
'failed';
1161 $charge->customer = $customer->id;
1162 $charge->failure_code = $stripe->code;
1163 $charge->failure_message = $stripe->error;
1164 $charge->failure_declinecode = $stripe->declinecode;
1165 $stripefailurecode = $stripe->code;
1166 $stripefailuremessage = $stripe->error;
1167 $stripefailuredeclinecode = $stripe->declinecode;
1175 if (empty($charge) || $charge->status ==
'failed') {
1176 dol_syslog(
'Failed to charge card or payment mode ' . $stripecard->id .
' stripefailurecode=' . $stripefailurecode .
' stripefailuremessage=' . $stripefailuremessage .
' stripefailuredeclinecode=' . $stripefailuredeclinecode, LOG_WARNING);
1179 $this->stripechargeerror++;
1183 $errmsg = $langs->trans(
"FailedToChargeCard");
1184 if (!empty($charge)) {
1185 if ($stripefailuredeclinecode ==
'authentication_required') {
1186 $errauthenticationmessage = $langs->trans(
"ErrSCAAuthentication");
1187 $errmsg = $errauthenticationmessage;
1188 } elseif (in_array($stripefailuredeclinecode, [
'insufficient_funds',
'generic_decline'])) {
1189 $errmsg .=
': ' . $charge->failure_code;
1190 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' ' . $charge->failure_message;
1191 if (empty($stripefailurecode)) {
1192 $stripefailurecode = $charge->failure_code;
1194 if (empty($stripefailuremessage)) {
1195 $stripefailuremessage = $charge->failure_message;
1198 $errmsg .=
': failure_code=' . $charge->failure_code;
1199 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' failure_message=' . $charge->failure_message;
1200 if (empty($stripefailurecode)) {
1201 $stripefailurecode = $charge->failure_code;
1203 if (empty($stripefailuremessage)) {
1204 $stripefailuremessage = $charge->failure_message;
1208 $errmsg .=
': ' . $stripefailurecode .
' - ' . $stripefailuremessage;
1209 $errmsg .= ($stripefailuredeclinecode ?
' - ' . $stripefailuredeclinecode :
'');
1212 $description =
'Stripe payment ERROR from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1213 $postactionmessages[] = $errmsg .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
1214 $this->errors[] = $errmsg;
1216 dol_syslog(
'Successfuly charge card ' . $stripecard->id);
1218 $postactionmessages[] =
'Success to charge card (' . $charge->id .
' with ' . $stripearrayofkeys[
'publishable_key'] .
')';
1222 $this->stripechargedone++;
1225 $description =
'Stripe payment OK (' . $charge->id .
') from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1231 $TRANSACTIONID = $charge->id;
1232 $currency = $conf->currency;
1233 $paymentmethod =
'stripe';
1234 $emetteur_name = $charge->customer;
1239 if ($paymentmethod ==
'paybox') {
1240 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1242 if ($paymentmethod ==
'paypal') {
1243 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1245 if ($paymentmethod ==
'stripe') {
1246 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1248 if (empty($paymentTypeId)) {
1251 $paymentType =
'PRE';
1253 $paymentType = $_SESSION[
"paymentType"];
1254 if (empty($paymentType)) {
1255 $paymentType =
'CB';
1258 $paymentTypeId =
dol_getIdFromCode($this->
db, $paymentType,
'c_paiement',
'code',
'id', 1);
1261 $currencyCodeType = $currency;
1263 $ispostactionok = 1;
1266 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
1268 $paiement->datepaye = $now;
1269 $paiement->date = $now;
1270 if ($currencyCodeType == $conf->currency) {
1271 $paiement->amounts = [$this->
id => $amounttopay];
1273 $paiement->multicurrency_amounts = [$this->
id => $amounttopay];
1275 $postactionmessages[] =
'Payment was done in a different currency than currency expected of company';
1276 $ispostactionok = -1;
1281 $paiement->paiementid = $paymentTypeId;
1282 $paiement->num_paiement =
'';
1283 $paiement->num_payment =
'';
1285 $paiement->note_public =
'StripeSepa payment ' .
dol_print_date($now,
'standard') .
' using ' . $paymentmethod . ($ipaddress ?
' from ip ' . $ipaddress :
'') .
' - Transaction ID = ' . $TRANSACTIONID;
1286 $paiement->note_private =
'StripeSepa payment ' .
dol_print_date($now,
'standard') .
' using ' . $paymentmethod . ($ipaddress ?
' from ip ' . $ipaddress :
'') .
' - Transaction ID = ' . $TRANSACTIONID;
1287 $paiement->ext_payment_id = $charge->id .
':' . $customer->id .
'@' . $stripearrayofkeys[
'publishable_key'];
1288 $paiement->ext_payment_site =
'stripe';
1290 if (!$errorforinvoice) {
1291 dol_syslog(
'* Record payment for invoice id ' . $this->
id .
'. It includes closing of invoice and regenerating document');
1294 $paiement_id = $paiement->create($user, 1);
1295 if ($paiement_id < 0) {
1296 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . join(
"<br>\n", $paiement->errors);
1297 $ispostactionok = -1;
1301 $postactionmessages[] =
'Payment created';
1304 dol_syslog(
"The payment has been created for invoice id " . $this->
id);
1311 if ($paymentmethod ==
'paybox') {
1312 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1314 if ($paymentmethod ==
'paypal') {
1315 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1317 if ($paymentmethod ==
'stripe') {
1318 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1321 if ($bankaccountid > 0) {
1322 $label =
'(CustomerInvoicePayment)';
1324 $label =
'(CustomerInvoicePaymentBack)';
1326 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid, $emetteur_name,
'');
1328 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . join(
"<br>\n", $paiement->errors);
1329 $ispostactionok = -1;
1333 $postactionmessages[] =
'Bank transaction of payment created (by doTakePaymentStripeForThirdparty)';
1336 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
1337 $ispostactionok = -1;
1343 if ($ispostactionok < 1) {
1344 $description =
'Stripe payment OK (' . $charge->id .
' - ' . $amounttopay .
' ' . $conf->currency .
') but post action KO from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1346 $description =
'Stripe payment+post action OK (' . $charge->id .
' - ' . $amounttopay .
' ' . $conf->currency .
') from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1353 $labeltouse =
'InvoicePaymentSuccess';
1354 $sendemailtocustomer = 1;
1356 if (empty($charge) || $charge->status ==
'failed') {
1357 $labeltouse =
'InvoicePaymentFailure';
1358 if ($noemailtocustomeriferror) {
1359 $sendemailtocustomer = 0;
1364 if (empty($charge) || $charge->status ==
'failed') {
1365 $actioncode =
'PAYMENT_STRIPE_KO';
1366 $extraparams = $stripefailurecode;
1367 $extraparams .= (($extraparams && $stripefailuremessage) ?
' - ' :
'') . $stripefailuremessage;
1368 $extraparams .= (($extraparams && $stripefailuredeclinecode) ?
' - ' :
'') . $stripefailuredeclinecode;
1370 $actioncode =
'PAYMENT_STRIPE_OK';
1376 dol_syslog(
"No card or payment method found for this stripe customer " . $customer->id, LOG_WARNING);
1377 $this->errors[] =
'Failed to get card | payment method for stripe customer = ' . $customer->id;
1379 $labeltouse =
'InvoicePaymentFailure';
1380 $sendemailtocustomer = 1;
1381 if ($noemailtocustomeriferror) {
1382 $sendemailtocustomer = 0;
1385 $description =
'Failed to find or use the payment mode - no credit card defined for the customer account';
1386 $stripefailurecode =
'BADPAYMENTMODE';
1387 $stripefailuremessage =
'Failed to find or use the payment mode - no credit card defined for the customer account';
1388 $postactionmessages[] = $description .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
1392 $actioncode =
'PAYMENT_STRIPE_KO';
1398 $sendemailtocustomer = 0;
1401 $stripefailurecode =
'';
1402 $stripefailuremessage =
'';
1410 if ($resultthirdparty <= 0) {
1411 dol_syslog(
'SellYourSaasUtils Failed to load customer for thirdparty_id = ' . $thirdparty->id, LOG_WARNING);
1412 $this->errors[] =
'Failed to load customer for thirdparty_id = ' . $thirdparty->id;
1414 dol_syslog(
'SellYourSaasUtils Failed to get Stripe customer id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'], LOG_WARNING);
1415 $this->errors[] =
'Failed to get Stripe customer id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
1420 $labeltouse =
'InvoicePaymentFailure';
1421 $sendemailtocustomer = 1;
1422 if ($noemailtocustomeriferror) {
1423 $sendemailtocustomer = 0;
1426 $description =
'Failed to find or use your payment mode (no payment mode for this customer id)';
1427 $stripefailurecode =
'BADPAYMENTMODE';
1428 $stripefailuremessage =
'Failed to find or use your payment mode (no payment mode for this customer id)';
1429 $postactionmessages = [];
1433 $actioncode =
'PAYMENT_STRIPE_KO';
1438 if ($sendemailtocustomer && $labeltouse) {
1439 dol_syslog(
"* Send email with result of payment - " . $labeltouse);
1442 $outputlangs =
new Translate(
'', $conf);
1443 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1444 $outputlangs->loadLangs([
"main",
"members",
"bills"]);
1447 $arraydefaultmessage =
null;
1449 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1452 if (!empty($labeltouse)) {
1453 $arraydefaultmessage = $formmail->getEMailTemplate($this->
db,
'facture_send', $user, $outputlangs, 0, 1, $labeltouse);
1456 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1457 $subject = $arraydefaultmessage->topic;
1458 $msg = $arraydefaultmessage->content;
1469 $foundcontract =
null;
1471 if (is_array($this->linkedObjects[
'contrat']) && count($this->linkedObjects[
'contrat']) > 0) {
1473 foreach ($this->linkedObjects[
'contrat'] as $idcontract => $contract) {
1474 $substitutionarray[
'__CONTRACT_REF__'] = $contract->ref_customer;
1475 $substitutionarray[
'__REFCLIENT__'] = $contract->ref_customer;
1476 $substitutionarray[
'__REF_CLIENT__'] = $contract->ref_customer;
1477 $foundcontract = $contract;
1482 dol_syslog(
'__DIRECTDOWNLOAD_URL_INVOICE__=' . $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__']);
1506 if (is_object($invoice)) {
1507 $invoicediroutput = $conf->facture->dir_output;
1509 $fileparams =
dol_most_recent_file($invoicediroutput .
'/' . $this->
ref, preg_quote($this->ref,
'/') .
'[^\-]+*.pdf');
1510 $file = $fileparams[
'fullname'];
1515 $listofpaths = [$file];
1516 $listofnames = [basename($file)];
1522 $trackid =
'inv' . $this->id;
1523 $moreinheader =
'X-Dolibarr-Info: makeStripeSepaRequest' .
"\r\n";
1526 include_once DOL_DOCUMENT_ROOT .
'/core/class/CMailFile.class.php';
1527 $mailfile =
new CMailFile($subjecttosend, $this->thirdparty->email, $from, $texttosend, $listofpaths, $listofmimes, $listofnames,
'',
'', 0, -1,
'',
'', $trackid, $moreinheader);
1528 if ($mailfile->sendfile()) {
1531 $this->error = $langs->trans(
"ErrorFailedToSendMail", $from, $this->thirdparty->email) .
'. ' . $mailfile->error;
1536 $errmsg = $this->error;
1537 $postactionmessages[] = $errmsg;
1538 $ispostactionok = -1;
1541 $postactionmessages[] =
'Email sent to thirdparty (to ' . $this->thirdparty->email .
' with invoice document attached: ' . $file .
', language = ' . $outputlangs->defaultlang .
')';
1543 $postactionmessages[] =
'Email sent to thirdparty (to ' . $this->thirdparty->email .
' without any attached document, language = ' . $outputlangs->defaultlang .
')';
1549 dol_syslog(
"* Record event for payment result - " . $description);
1550 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1555 $actioncomm->type_code =
'AC_OTH_AUTO';
1556 $actioncomm->code =
'AC_' . $actioncode;
1557 $actioncomm->label = $description;
1558 $actioncomm->note_private = join(
",\n", $postactionmessages);
1559 $actioncomm->fk_project = $this->fk_project;
1560 $actioncomm->datep = $now;
1561 $actioncomm->datef = $now;
1562 $actioncomm->percentage = -1;
1563 $actioncomm->socid = $thirdparty->id;
1564 $actioncomm->contactid = 0;
1565 $actioncomm->authorid = $user->id;
1566 $actioncomm->userownerid = $user->id;
1576 $actioncomm->fk_element = $this->id;
1577 $actioncomm->elementtype = $this->element;
1578 $actioncomm->extraparams =
dol_trunc($extraparams, 250);
1580 $actioncomm->create($user);
1584 $this->postactionmessages = $postactionmessages;
1588 dol_syslog(
'Error ' . $e->getMessage(), LOG_ERR);
1589 $this->errors[] =
'Error ' . $e->getMessage();
1594 dol_syslog(
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->
ref .
". Why is the invoice not classified 'Paid' ?", LOG_WARNING);
1595 $this->errors[] =
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->ref .
". Why is the invoice not classified 'Paid' ?";
1598 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_demande(";
1599 $sql .=
"fk_facture, ";
1600 $sql .=
" amount, date_demande, fk_user_demande, ext_payment_id, ext_payment_site, sourcetype, entity)";
1601 $sql .=
" VALUES (".$this->id;
1602 $sql .=
",".((float)
price2num($amount));
1603 $sql .=
",'".$this->db->idate($now).
"'";
1604 $sql .=
",".((int) $fuser->id);
1605 $sql .=
",'".$this->db->escape($stripe_id).
"'";
1606 $sql .=
",'".$this->db->escape($stripe_uri).
"'";
1607 $sql .=
",'".$this->db->escape($sourcetype).
"'";
1608 $sql .=
",".$conf->entity;
1611 dol_syslog(get_class($this).
"::makeStripeSepaRequest", LOG_DEBUG);
1614 $this->error = $this->
db->lasterror();
1615 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur');
1619 $this->error =
'WithdrawRequestErrorNilAmount';
1620 dol_syslog(get_class($this).
'::makeStripeSepaRequest WithdrawRequestErrorNilAmount');
1626 $payment_mode_id =
dol_getIdFromCode($this->
db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
1627 if ($payment_mode_id > 0) {
1637 $this->error = $this->
db->error();
1638 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur -2');
1642 $this->error =
"Status of invoice does not allow this";
1643 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error.
" $this->statut, $this->paye, $this->mode_reglement_id");
1659 $sql =
'DELETE FROM '.$this->db->prefix().
'prelevement_demande';
1660 $sql .=
' WHERE rowid = '.((int) $did);
1661 $sql .=
' AND traite = 0';
1662 if ($this->
db->query($sql)) {
1665 $this->error = $this->
db->lasterror();
1666 dol_syslog(get_class($this).
'::demande_prelevement_delete Error '.$this->error);
1679 global $conf, $mysoc;
1682 $tmplang->setDefaultLang(
'en_US');
1683 $tmplang->load(
"main");
1688 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
1689 $pricetaxstring =
price2num($this->total_tva, 2, 1);
1716 $s = pack(
'C1', 1).pack(
'C1', strlen($mysoc->name)).$mysoc->name;
1717 $s .= pack(
'C1', 2).pack(
'C1', strlen($mysoc->tva_intra)).$mysoc->tva_intra;
1718 $s .= pack(
'C1', 3).pack(
'C1', strlen($datestring)).$datestring;
1719 $s .= pack(
'C1', 4).pack(
'C1', strlen($pricewithtaxstring)).$pricewithtaxstring;
1720 $s .= pack(
'C1', 5).pack(
'C1', strlen($pricetaxstring)).$pricetaxstring;
1726 $s = base64_encode($s);
1739 global $conf, $mysoc;
1742 $tmplang->setDefaultLang(
'en_US');
1743 $tmplang->load(
"main");
1745 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
1746 $pricetaxstring =
price2num($this->total_tva, 2, 1);
1748 $complementaryinfo =
'';
1762 $complementaryinfo =
'//S1/10/'.str_replace(
'/',
'', $this->
ref).
'/11/'.$datestring;
1763 if ($this->ref_client) {
1764 $complementaryinfo .=
'/20/'.$this->ref_client;
1766 if ($this->thirdparty->tva_intra) {
1767 $complementaryinfo .=
'/30/'.$this->thirdparty->tva_intra;
1770 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
1779 if ($this->fk_account > 0) {
1781 $bankaccount->fetch($this->fk_account);
1782 $s .= $bankaccount->iban.
"\n";
1786 if ($bankaccount->id > 0 &&
getDolGlobalString(
'PDF_SWISS_QRCODE_USE_OWNER_OF_ACCOUNT_AS_CREDITOR')) {
1790 $s .=
dol_trunc($bankaccount->proprio, 70,
'right',
'UTF-8', 1).
"\n";
1791 $addresslinearray = explode(
"\n", $bankaccount->owner_address);
1792 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
1793 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
1799 $s .=
dol_trunc($mysoc->name, 70,
'right',
'UTF-8', 1).
"\n";
1800 $addresslinearray = explode(
"\n", $mysoc->address);
1801 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
1802 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
1803 $s .=
dol_trunc($mysoc->zip, 16,
'right',
'UTF-8', 1).
"\n";
1804 $s .=
dol_trunc($mysoc->town, 35,
'right',
'UTF-8', 1).
"\n";
1805 $s .=
dol_trunc($mysoc->country_code, 2,
'right',
'UTF-8', 1).
"\n";
1816 $s .=
price($pricewithtaxstring, 0,
'none', 0, 0, 2).
"\n";
1817 $s .= ($this->multicurrency_code ? $this->multicurrency_code : $conf->currency).
"\n";
1820 $s .=
dol_trunc($this->thirdparty->name, 70,
'right',
'UTF-8', 1).
"\n";
1821 $addresslinearray = explode(
"\n", $this->thirdparty->address);
1822 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
1823 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
1824 $s .=
dol_trunc($this->thirdparty->zip, 16,
'right',
'UTF-8', 1).
"\n";
1825 $s .=
dol_trunc($this->thirdparty->town, 35,
'right',
'UTF-8', 1).
"\n";
1826 $s .=
dol_trunc($this->thirdparty->country_code, 2,
'right',
'UTF-8', 1).
"\n";
1831 if ($complementaryinfo) {
1832 $s .= $complementaryinfo.
"\n";
1838 if ($complementaryinfo) {
1839 $s .= $complementaryinfo.
"\n";
1849 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1877 public $product_type = 0;
1883 public $product_ref;
1889 public $product_label;
1895 public $product_desc;
1926 public $vat_src_code;
1938 public $localtax1_tx;
1944 public $localtax2_tx;
1950 public $localtax1_type;
1956 public $localtax2_type;
1962 public $remise_percent;
1987 public $total_localtax1;
1993 public $total_localtax2;
2001 public $date_start_fill;
2002 public $date_end_fill;
2004 public $buy_price_ht;
2017 public $info_bits = 0;
2019 public $special_code = 0;
2021 public $fk_multicurrency;
2022 public $multicurrency_code;
2023 public $multicurrency_subprice;
2024 public $multicurrency_total_ht;
2025 public $multicurrency_total_tva;
2026 public $multicurrency_total_ttc;
2028 public $fk_user_author;
2029 public $fk_user_modif;
2031 public $fk_accounting_account;
Class to manage bank accounts.
Class to manage agenda events (actions)
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Superclass for invoices classes.
const TYPE_CREDIT_NOTE
Credit note invoice.
demande_prelevement($fuser, $amount=0, $type='direct-debit', $sourcetype='facture')
Create a withdrawal request for a direct debit order or a credit transfer order.
const STATUS_CLOSED
Classified paid.
getSumCreditNotesUsed($multicurrency=0)
Return amount (with tax) of all credit notes invoices + excess received used by invoice.
getRemainToPay($multicurrency=0)
Return remain amount to pay.
makeStripeSepaRequest($fuser, $did=0, $type='direct-debit', $sourcetype='facture')
Create a withdrawal request for a direct debit order or a credit transfer order.
buildZATCAQRString()
Build string for ZATCA QR Code (Arabi Saudia)
const TYPE_STANDARD
Standard invoice.
demande_prelevement_delete($fuser, $did)
Remove a direct debit request or a credit transfer request.
getVentilExportCompta()
Return if an invoice was dispatched into bookkeeping.
const TYPE_PROFORMA
Proforma invoice.
buildSwitzerlandQRString()
Build string for QR-Bill (Switzerland)
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_SITUATION
Situation invoice.
getSumDepositsUsed($multicurrency=0)
Return amount (with tax) of all deposits invoices used by invoice.
getSommePaiement($multicurrency=0)
Return amount of payments already done.
const TYPE_DEPOSIT
Deposit invoice.
LibStatut($paye, $status, $mode=0, $alreadypaid=-1, $type=-1)
Return label of a status.
const STATUS_ABANDONED
Classified abandoned and no payment done.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date.
const TYPE_REPLACEMENT
Replacement invoice.
getSumFromThisCreditNotesNotUsed($multicurrency=0)
Return amount (with tax) of all converted amount for this credit note.
getListIdAvoirFromInvoice()
Returns array of credit note ids from the invoice.
const STATUS_DRAFT
Draft status.
getIdReplacingInvoice($option='')
Returns the id of the invoice that replaces it.
getLibType($withbadge=0)
Return label of type of invoice.
is_erasable()
Return if an invoice can be deleted Rule is: If invoice is draft and has a temporary ref -> yes (1) I...
getListOfPayments($filtertype='')
Return list of payments.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
Parent class of all other business classes for details of elements (invoices, contracts,...
$label
Custom label of line.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
setPaymentMethods($id)
Change the payments methods.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage bank accounts description of third parties.
Class for CompanyPaymentMode.
Class to manage absolute discounts.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage payments of customer invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
trait CommonIncoterm
Superclass for incoterm classes.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode='')
Return file(s) into a directory (by default most recent)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getUserRemoteIP()
Return the IP of remote user.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db
API class for accounts.