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) {
160 $this->sumpayed_multicurrency = $obj->multicurrency_amount;
161 return (
float) $obj->multicurrency_amount;
163 $this->sumpayed = $obj->amount;
164 return (
float) $obj->amount;
170 $this->error = $this->
db->lasterror();
190 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
193 $result = $discountstatic->getSumDepositsUsed($this, $multicurrency);
196 if ($multicurrency) {
197 $this->sumdeposit_multicurrency = $result;
199 $this->sumdeposit = $result;
204 $this->error = $discountstatic->error;
217 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
220 $result = $discountstatic->getSumCreditNotesUsed($this, $multicurrency);
222 if ($multicurrency) {
223 $this->sumcreditnote_multicurrency = $result;
225 $this->sumcreditnote = $result;
230 $this->error = $discountstatic->error;
243 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
246 $result = $discountstatic->getSumFromThisCreditNotesNotUsed($this, $multicurrency);
250 $this->error = $discountstatic->error;
264 $sql =
"SELECT rowid";
265 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
266 $sql .=
" WHERE fk_facture_source = ".((int) $this->
id);
267 $sql .=
" AND type = 2";
273 $row = $this->
db->fetch_row(
$resql);
274 $idarray[] = $row[0];
291 $sql =
"SELECT rowid";
292 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
293 $sql .=
" WHERE fk_facture_source = ".((int) $this->
id);
294 $sql .=
" AND type < 2";
295 if ($option ==
'validated') {
296 $sql .=
' AND fk_statut = 1';
303 $sql .=
" ORDER BY fk_statut DESC";
307 $obj = $this->
db->fetch_object(
$resql);
330 $table =
'paiement_facture';
331 $table2 =
'paiement';
332 $field =
'fk_facture';
333 $field2 =
'fk_paiement';
334 $field3 =
', p.ref_ext';
335 $sharedentity =
'facture';
336 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
337 $table =
'paiementfourn_facturefourn';
338 $table2 =
'paiementfourn';
339 $field =
'fk_facturefourn';
340 $field2 =
'fk_paiementfourn';
342 $sharedentity =
'facture_fourn';
345 $sql =
"SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code".$field3;
346 $sql .=
" FROM ".$this->db->prefix().$table.
" as pf, ".$this->
db->prefix().$table2.
" as p, ".$this->
db->prefix().
"c_paiement as t";
347 $sql .=
" WHERE pf.".$field.
" = ".((int) $this->
id);
348 $sql .=
" AND pf.".$field2.
" = p.rowid";
349 $sql .=
' AND p.fk_paiement = t.id';
350 $sql .=
' AND p.entity IN ('.getEntity($sharedentity).
')';
352 $sql .=
" AND t.code='PRE'";
355 dol_syslog(get_class($this).
"::getListOfPayments", LOG_DEBUG);
361 $obj = $this->
db->fetch_object(
$resql);
362 $tmp = array(
'amount'=>$obj->amount,
'type'=>$obj->code,
'date'=>$obj->datep,
'num'=>$obj->num,
'ref'=>$obj->ref);
363 if (!empty($field3)) {
364 $tmp[
'ref_ext'] = $obj->ref_ext;
373 if ($this->element ==
'facture' || $this->element ==
'invoice') {
374 $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";
375 $sql .=
' FROM '.$this->db->prefix().
'societe_remise_except as rc, '.$this->
db->prefix().
'facture as f';
376 $sql .=
' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $this->
id);
377 $sql .=
' AND (f.type = 2 OR f.type = 0 OR f.type = 3)';
378 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
379 $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";
380 $sql .=
' FROM '.$this->db->prefix().
'societe_remise_except as rc, '.$this->
db->prefix().
'facture_fourn as f';
381 $sql .=
' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $this->
id);
382 $sql .=
' AND (f.type = 2 OR f.type = 0 OR f.type = 3)';
391 $obj = $this->
db->fetch_object(
$resql);
392 if ($multicurrency) {
393 $retarray[] = array(
'amount'=>$obj->multicurrency_amount,
'type'=>$obj->type,
'date'=>$obj->date,
'num'=>
'0',
'ref'=>$obj->ref);
395 $retarray[] = array(
'amount'=>$obj->amount,
'type'=>$obj->type,
'date'=>$obj->date,
'num'=>
'',
'ref'=>$obj->ref);
400 $this->error = $this->
db->lasterror();
409 $this->error = $this->
db->lasterror();
436 $tmppart = substr($this->
ref, 1, 4);
438 if ($this->statut == self::STATUS_DRAFT && $tmppart ===
'PROV') {
442 if (!empty($conf->global->INVOICE_CAN_NEVER_BE_REMOVED)) {
447 if ($tmppart !==
'PROV') {
449 if ($ventilExportCompta != 0) {
454 if ($this->element !=
'invoice_supplier') {
455 if (empty($this->thirdparty)) {
458 $maxref = $this->getNextNumRef($this->thirdparty,
'last');
462 if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $maxref !=
'' && $maxref != $this->ref) {
469 if ($this->situation_cycle_ref && method_exists($this,
'is_last_in_cycle')) {
470 $last = $this->is_last_in_cycle();
479 if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0) {
493 $alreadydispatched = 0;
495 $type =
'customer_invoice';
496 if ($this->element ==
'invoice_supplier') {
497 $type =
'supplier_invoice';
500 $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);
503 $obj = $this->
db->fetch_object(
$resql);
505 $alreadydispatched = $obj->nb;
508 $this->error = $this->
db->lasterror();
512 if ($alreadydispatched) {
529 $labellong =
"Unknown";
531 $labellong =
"InvoiceStandard";
532 $labelshort =
"InvoiceStandardShort";
534 $labellong =
"InvoiceReplacement";
535 $labelshort =
"InvoiceReplacementShort";
537 $labellong =
"InvoiceAvoir";
538 $labelshort =
"CreditNote";
540 $labellong =
"InvoiceDeposit";
541 $labelshort =
"Deposit";
543 $labellong =
"InvoiceProForma";
544 $labelshort =
"ProForma";
546 $labellong =
"InvoiceSituation";
547 $labelshort =
"Situation";
552 $out .=
'<span class="badgeneutral" title="'.dol_escape_htmltag($langs->trans($labellong)).
'">';
554 $out .= $langs->trans($withbadge == 2 ? $labelshort : $labellong);
570 return $this->
LibStatut($this->paye, $this->statut, $mode, $alreadypaid, $this->
type);
584 public function LibStatut($paye, $status, $mode = 0, $alreadypaid = -1, $type = -1)
587 global $langs, $hookmanager;
588 $langs->load(
'bills');
594 $statusType =
'status0';
598 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusDraft');
599 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusDraft');
600 } elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) {
602 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusCanceled');
603 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusCanceled');
605 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedUnpaid');
606 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedUnpaid');
608 $statusType =
'status5';
609 } elseif (($status == 3 || $status == 2) && $alreadypaid > 0) {
610 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedPaidPartially');
611 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedPaidPartially');
612 $statusType =
'status9';
613 } elseif ($alreadypaid == 0) {
614 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
615 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusNotPaid');
616 $statusType =
'status1';
618 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusStarted');
619 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusStarted');
620 $statusType =
'status3';
623 $statusType =
'status6';
625 if ($type == self::TYPE_CREDIT_NOTE) {
626 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaidBackOrConverted');
627 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaidBackOrConverted');
628 } elseif ($type == self::TYPE_DEPOSIT) {
629 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusConverted');
630 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusConverted');
632 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaid');
633 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaid');
641 'alreadypaid' => $alreadypaid,
645 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
648 return $hookmanager->resPrint;
653 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
667 if (!$cond_reglement) {
668 $cond_reglement = $this->cond_reglement_code;
670 if (!$cond_reglement) {
671 $cond_reglement = $this->cond_reglement_id;
678 $sqltemp =
"SELECT c.type_cdr, c.nbjour, c.decalage";
679 $sqltemp .=
" FROM ".$this->db->prefix().
"c_payment_term as c";
680 if (is_numeric($cond_reglement)) {
681 $sqltemp .=
" WHERE c.rowid=".((int) $cond_reglement);
683 $sqltemp .=
" WHERE c.entity IN (".getEntity(
'c_payment_term').
")";
684 $sqltemp .=
" AND c.code = '".$this->db->escape($cond_reglement).
"'";
687 dol_syslog(get_class($this).
'::calculate_date_lim_reglement', LOG_DEBUG);
688 $resqltemp = $this->
db->query($sqltemp);
690 if ($this->
db->num_rows($resqltemp)) {
691 $obj = $this->
db->fetch_object($resqltemp);
692 $cdr_nbjour = $obj->nbjour;
693 $cdr_type = $obj->type_cdr;
694 $cdr_decalage = $obj->decalage;
697 $this->error = $this->
db->error();
700 $this->
db->free($resqltemp);
705 if ($cdr_type == 0) {
706 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
708 $datelim += ($cdr_decalage * 3600 * 24);
709 } elseif ($cdr_type == 1) {
711 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
713 $mois = date(
'm', $datelim);
714 $annee = date(
'Y', $datelim);
722 $datelim =
dol_mktime(12, 0, 0, $mois, 1, $annee);
723 $datelim -= (3600 * 24);
725 $datelim += ($cdr_decalage * 3600 * 24);
726 } elseif ($cdr_type == 2 && !empty($cdr_decalage)) {
728 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
729 $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
731 $date_piece =
dol_mktime(0, 0, 0, date(
'm', $datelim), date(
'd', $datelim), date(
'Y', $datelim));
732 $date_lim_current =
dol_mktime(0, 0, 0, date(
'm', $datelim), $cdr_decalage, date(
'Y', $datelim));
735 $diff = $date_piece - $date_lim_current;
738 $datelim = $date_lim_current;
740 $datelim = $date_lim_next;
743 return 'Bad value for type_cdr in database for record cond_reglement = '.$cond_reglement;
767 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
769 if ($this->statut > self::STATUS_DRAFT && $this->paye == 0) {
770 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
772 $bac->fetch(0, $this->socid);
774 $sql =
"SELECT count(*)";
775 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
776 if ($type ==
'bank-transfer') {
777 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
779 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
781 $sql .=
" AND ext_payment_id IS NULL";
782 $sql .=
" AND traite = 0";
784 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
787 $row = $this->
db->fetch_row(
$resql);
800 if (empty($amount)) {
801 $amount =
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
804 if (is_numeric($amount) && $amount != 0) {
805 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
806 if ($type ==
'bank-transfer') {
807 $sql .=
'fk_facture_fourn, ';
809 $sql .=
'fk_facture, ';
811 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)';
812 $sql .=
" VALUES (".((int) $this->
id);
813 $sql .=
", ".((float)
price2num($amount));
814 $sql .=
", '".$this->db->idate($now).
"'";
815 $sql .=
", ".((int) $fuser->id);
816 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
817 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
818 $sql .=
", '".$this->db->escape($bac->number).
"'";
819 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
820 $sql .=
", '".$this->db->escape($sourcetype).
"'";
821 $sql .=
", ".((int) $conf->entity);
824 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
827 $this->error = $this->
db->lasterror();
828 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
832 $this->error =
'WithdrawRequestErrorNilAmount';
833 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
839 $payment_mode_id =
dol_getIdFromCode($this->
db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
840 if ($payment_mode_id > 0) {
850 $this->error =
"A request already exists";
851 dol_syslog(get_class($this).
'::demandeprelevement Impossible de creer une demande, demande deja en cours');
855 $this->error = $this->
db->error();
856 dol_syslog(get_class($this).
'::demandeprelevement Erreur -2');
860 $this->error =
"Status of invoice does not allow this";
861 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->statut, $this->paye, $this->mode_reglement_id");
879 global $conf, $mysoc, $user, $langs;
881 if (empty($conf->global->STRIPE_SEPA_DIRECT_DEBIT)) {
888 dol_syslog(get_class($this).
"::makeStripeSepaRequest 0", LOG_DEBUG);
890 if ($this->statut > self::STATUS_DRAFT && $this->paye == 0) {
891 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
893 $result = $bac->fetch(0, $this->socid, 1,
'ban');
894 if ($result <= 0 || empty($bac->id)) {
895 $this->error = $langs->trans(
"ThirdpartyHasNoDefaultBanAccount");
896 $this->errors[] = $this->error;
897 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error);
901 $sql =
"SELECT rowid, date_demande, amount, fk_facture, fk_facture_fourn";
902 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
903 $sql .=
" WHERE rowid = ".((int) $did);
905 dol_syslog(get_class($this).
"::makeStripeSepaRequest 1", LOG_DEBUG);
908 $obj = $this->
db->fetch_object(
$resql);
915 $amount = $obj->amount;
928 $amounttocheck =
price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,
'MT');
932 if (is_numeric($amount) && $amount != 0) {
933 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
935 $companypaymentmode->fetch($bac->id);
938 $service =
'StripeTest';
940 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha')) {
941 $service =
'StripeLive';
945 dol_syslog(
"makeStripeSepaRequest amount = ".$amount.
" service=" . $service .
" servicestatus=" . $servicestatus .
" thirdparty_id=" . $this->socid .
" companypaymentmode=" . $companypaymentmode->id);
947 $this->stripechargedone = 0;
948 $this->stripechargeerror = 0;
951 $currency = $conf->currency;
953 global $stripearrayofkeysbyenv;
954 global $savstripearrayofkeysbyenv;
956 $errorforinvoice = 0;
960 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);
964 $amounttopay = $this->total_ttc - $alreadypayed - $amount_credit_notes_included;
968 $arrayzerounitcurrency = [
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF'];
969 $amountstripe = $amounttopay;
970 if (!in_array($currency, $arrayzerounitcurrency)) {
971 $amountstripe = $amountstripe * 100;
974 if ($amountstripe > 0) {
977 dol_syslog(
"We will try to pay with companypaymentmodeid=" . $companypaymentmode->id .
" stripe_card_ref=" . $companypaymentmode->stripe_card_ref .
" mode=" . $companypaymentmode->status, LOG_DEBUG);
980 $resultthirdparty = $thirdparty->fetch($this->socid);
982 include_once DOL_DOCUMENT_ROOT .
'/stripe/class/stripe.class.php';
986 if (empty($savstripearrayofkeysbyenv)) {
987 $savstripearrayofkeysbyenv = $stripearrayofkeysbyenv;
989 dol_syslog(
"makeStripeSepaRequest Current Stripe environment is " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
990 dol_syslog(
"makeStripeSepaRequest Current Saved Stripe environment is " . $savstripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
992 $foundalternativestripeaccount =
'';
995 if (!empty($thirdparty->array_options[
'options_stripeaccount'])) {
996 dol_syslog(
"makeStripeSepaRequest The thirdparty id=" . $thirdparty->id .
" has a dedicated Stripe Account, so we switch to it.");
998 $tmparray = explode(
'@', $thirdparty->array_options[
'options_stripeaccount']);
999 if (!empty($tmparray[1])) {
1000 $tmparray2 = explode(
':', $tmparray[1]);
1001 if (!empty($tmparray2[3])) {
1002 $stripearrayofkeysbyenv = [
1004 "publishable_key" => $tmparray2[0],
1005 "secret_key" => $tmparray2[1]
1008 "publishable_key" => $tmparray2[2],
1009 "secret_key" => $tmparray2[3]
1013 $stripearrayofkeys = $stripearrayofkeysbyenv[$servicestatus];
1014 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1016 $foundalternativestripeaccount = $tmparray[0];
1018 dol_syslog(
"We use now customer=" . $foundalternativestripeaccount .
" publishable_key=" . $stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1022 if (!$foundalternativestripeaccount) {
1023 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1025 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1026 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1027 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);
1030 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1032 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1033 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1034 dol_syslog(
"The thirdparty id=" . $thirdparty->id .
" has no dedicated Stripe Account, so we use global one, so " . json_encode($stripearrayofkeys), LOG_DEBUG);
1038 dol_syslog(
"makeStripeSepaRequest get stripe account", LOG_DEBUG);
1039 $stripeacc = $stripe->getStripeAccount($service, $this->socid);
1040 dol_syslog(
"makeStripeSepaRequest get stripe account return " . json_encode($stripeacc), LOG_DEBUG);
1042 if ($foundalternativestripeaccount) {
1043 if (empty($stripeacc)) {
1044 $customer = \Stripe\Customer::retrieve([
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources']);
1046 $customer = \Stripe\Customer::retrieve([
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'], [
"stripe_account" => $stripeacc]);
1049 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
1050 if (empty($customer) && !empty($stripe->error)) {
1051 $this->errors[] = $stripe->error;
1062 $postactionmessages = [];
1064 if ($resultthirdparty > 0 && !empty($customer)) {
1065 if (!$error && !empty($this->array_options[
'options_delayautopayment']) && $this->array_options[
'options_delayautopayment'] > $now && empty($calledinmyaccountcontext)) {
1066 $errmsg =
'Payment try was canceled (invoice qualified by the automatic payment was delayed after the ' .
dol_print_date($this->array_options[
'options_delayautopayment'],
'day') .
')';
1071 $this->errors[] = $errmsg;
1077 if ($companypaymentmode->type ==
'ban') {
1079 $stripecard = $stripe->sepaStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1081 $stripecard = $stripe->cardStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1085 $FULLTAG =
'INV=' . $this->
id .
'-CUS=' . $thirdparty->id;
1086 $description =
'Stripe payment from doTakePaymentStripeForThirdparty: ' . $FULLTAG .
' ref=' . $this->ref;
1088 $stripefailurecode =
'';
1089 $stripefailuremessage =
'';
1090 $stripefailuredeclinecode =
'';
1092 if (preg_match(
'/^card_/', $stripecard->id)) {
1093 dol_syslog(
"* Create charge on card " . $stripecard->id .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1099 $charge = \Stripe\Charge::create([
1100 'amount' =>
price2num($amountstripe,
'MU'),
1101 'currency' => $currency,
1103 'description' => $description,
1104 'metadata' => [
"FULLTAG" => $FULLTAG,
'Recipient' => $mysoc->name,
'dol_version' => DOL_VERSION,
'dol_entity' => $conf->entity,
'ipaddress' => $ipaddress],
1105 'customer' => $customer->id,
1107 'source' => $stripecard,
1108 'statement_descriptor' =>
dol_trunc(
'INV=' . $this->
id, 10,
'right',
'UTF-8', 1),
1110 }
catch (\
Stripe\Error\Card $e) {
1112 $body = $e->getJsonBody();
1113 $err = $body[
'error'];
1115 $stripefailurecode = $err[
'code'];
1116 $stripefailuremessage = $err[
'message'];
1117 $stripefailuredeclinecode = $err[
'decline_code'];
1119 $stripefailurecode =
'UnknownChargeError';
1120 $stripefailuremessage = $e->getMessage();
1124 dol_syslog(
"* Create payment on SEPA " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1126 dol_syslog(
"* Create payment on card " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1130 $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer->id, $stripeacc, $servicestatus, 0,
'automatic',
true, $stripecard->id, 1);
1132 $charge =
new stdClass();
1134 if ($paymentintent->status ===
'succeeded' || $paymentintent->status ===
'processing') {
1135 $charge->status =
'ok';
1136 $charge->id = $paymentintent->id;
1137 $charge->customer = $customer->id;
1138 } elseif ($paymentintent->status ===
'requires_action') {
1140 dol_syslog(var_export($paymentintent,
true), LOG_DEBUG);
1142 $charge->status =
'failed';
1143 $charge->customer = $customer->id;
1144 $charge->failure_code = $stripe->code;
1145 $charge->failure_message = $stripe->error;
1146 $charge->failure_declinecode = $stripe->declinecode;
1147 $stripefailurecode = $stripe->code;
1148 $stripefailuremessage =
'Action required. Contact the support at ';
1149 $stripefailuredeclinecode = $stripe->declinecode;
1151 dol_syslog(var_export($paymentintent,
true), LOG_DEBUG);
1153 $charge->status =
'failed';
1154 $charge->customer = $customer->id;
1155 $charge->failure_code = $stripe->code;
1156 $charge->failure_message = $stripe->error;
1157 $charge->failure_declinecode = $stripe->declinecode;
1158 $stripefailurecode = $stripe->code;
1159 $stripefailuremessage = $stripe->error;
1160 $stripefailuredeclinecode = $stripe->declinecode;
1168 if (empty($charge) || $charge->status ==
'failed') {
1169 dol_syslog(
'Failed to charge card or payment mode ' . $stripecard->id .
' stripefailurecode=' . $stripefailurecode .
' stripefailuremessage=' . $stripefailuremessage .
' stripefailuredeclinecode=' . $stripefailuredeclinecode, LOG_WARNING);
1172 $this->stripechargeerror++;
1176 $errmsg = $langs->trans(
"FailedToChargeCard");
1177 if (!empty($charge)) {
1178 if ($stripefailuredeclinecode ==
'authentication_required') {
1179 $errauthenticationmessage = $langs->trans(
"ErrSCAAuthentication");
1180 $errmsg = $errauthenticationmessage;
1181 } elseif (in_array($stripefailuredeclinecode, [
'insufficient_funds',
'generic_decline'])) {
1182 $errmsg .=
': ' . $charge->failure_code;
1183 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' ' . $charge->failure_message;
1184 if (empty($stripefailurecode)) {
1185 $stripefailurecode = $charge->failure_code;
1187 if (empty($stripefailuremessage)) {
1188 $stripefailuremessage = $charge->failure_message;
1191 $errmsg .=
': failure_code=' . $charge->failure_code;
1192 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' failure_message=' . $charge->failure_message;
1193 if (empty($stripefailurecode)) {
1194 $stripefailurecode = $charge->failure_code;
1196 if (empty($stripefailuremessage)) {
1197 $stripefailuremessage = $charge->failure_message;
1201 $errmsg .=
': ' . $stripefailurecode .
' - ' . $stripefailuremessage;
1202 $errmsg .= ($stripefailuredeclinecode ?
' - ' . $stripefailuredeclinecode :
'');
1205 $description =
'Stripe payment ERROR from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1206 $postactionmessages[] = $errmsg .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
1207 $this->errors[] = $errmsg;
1209 dol_syslog(
'Successfuly charge card ' . $stripecard->id);
1211 $postactionmessages[] =
'Success to charge card (' . $charge->id .
' with ' . $stripearrayofkeys[
'publishable_key'] .
')';
1215 $this->stripechargedone++;
1218 $description =
'Stripe payment OK (' . $charge->id .
') from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1224 $TRANSACTIONID = $charge->id;
1225 $currency = $conf->currency;
1226 $paymentmethod =
'stripe';
1227 $emetteur_name = $charge->customer;
1232 if ($paymentmethod ==
'paybox') {
1233 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1235 if ($paymentmethod ==
'paypal') {
1236 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1238 if ($paymentmethod ==
'stripe') {
1239 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1241 if (empty($paymentTypeId)) {
1244 $paymentType =
'PRE';
1246 $paymentType = $_SESSION[
"paymentType"];
1247 if (empty($paymentType)) {
1248 $paymentType =
'CB';
1251 $paymentTypeId =
dol_getIdFromCode($this->
db, $paymentType,
'c_paiement',
'code',
'id', 1);
1254 $currencyCodeType = $currency;
1256 $ispostactionok = 1;
1259 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
1261 $paiement->datepaye = $now;
1262 $paiement->date = $now;
1263 if ($currencyCodeType == $conf->currency) {
1264 $paiement->amounts = [$this->
id => $amounttopay];
1266 $paiement->multicurrency_amounts = [$this->
id => $amounttopay];
1268 $postactionmessages[] =
'Payment was done in a different currency than currency expected of company';
1269 $ispostactionok = -1;
1274 $paiement->paiementid = $paymentTypeId;
1275 $paiement->num_paiement =
'';
1276 $paiement->num_payment =
'';
1278 $paiement->note_public =
'StripeSepa payment ' .
dol_print_date($now,
'standard') .
' using ' . $paymentmethod . ($ipaddress ?
' from ip ' . $ipaddress :
'') .
' - Transaction ID = ' . $TRANSACTIONID;
1279 $paiement->note_private =
'StripeSepa payment ' .
dol_print_date($now,
'standard') .
' using ' . $paymentmethod . ($ipaddress ?
' from ip ' . $ipaddress :
'') .
' - Transaction ID = ' . $TRANSACTIONID;
1280 $paiement->ext_payment_id = $charge->id .
':' . $customer->id .
'@' . $stripearrayofkeys[
'publishable_key'];
1281 $paiement->ext_payment_site =
'stripe';
1283 if (!$errorforinvoice) {
1284 dol_syslog(
'* Record payment for invoice id ' . $this->
id .
'. It includes closing of invoice and regenerating document');
1287 $paiement_id = $paiement->create($user, 1);
1288 if ($paiement_id < 0) {
1289 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . join(
"<br>\n", $paiement->errors);
1290 $ispostactionok = -1;
1294 $postactionmessages[] =
'Payment created';
1297 dol_syslog(
"The payment has been created for invoice id " . $this->
id);
1304 if ($paymentmethod ==
'paybox') {
1305 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1307 if ($paymentmethod ==
'paypal') {
1308 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1310 if ($paymentmethod ==
'stripe') {
1311 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1314 if ($bankaccountid > 0) {
1315 $label =
'(CustomerInvoicePayment)';
1317 $label =
'(CustomerInvoicePaymentBack)';
1319 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid, $emetteur_name,
'');
1321 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . join(
"<br>\n", $paiement->errors);
1322 $ispostactionok = -1;
1326 $postactionmessages[] =
'Bank transaction of payment created (by doTakePaymentStripeForThirdparty)';
1329 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
1330 $ispostactionok = -1;
1336 if ($ispostactionok < 1) {
1337 $description =
'Stripe payment OK (' . $charge->id .
' - ' . $amounttopay .
' ' . $conf->currency .
') but post action KO from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1339 $description =
'Stripe payment+post action OK (' . $charge->id .
' - ' . $amounttopay .
' ' . $conf->currency .
') from doTakePaymentStripeForThirdparty: ' . $FULLTAG;
1346 $labeltouse =
'InvoicePaymentSuccess';
1347 $sendemailtocustomer = 1;
1349 if (empty($charge) || $charge->status ==
'failed') {
1350 $labeltouse =
'InvoicePaymentFailure';
1351 if ($noemailtocustomeriferror) {
1352 $sendemailtocustomer = 0;
1357 if (empty($charge) || $charge->status ==
'failed') {
1358 $actioncode =
'PAYMENT_STRIPE_KO';
1359 $extraparams = $stripefailurecode;
1360 $extraparams .= (($extraparams && $stripefailuremessage) ?
' - ' :
'') . $stripefailuremessage;
1361 $extraparams .= (($extraparams && $stripefailuredeclinecode) ?
' - ' :
'') . $stripefailuredeclinecode;
1363 $actioncode =
'PAYMENT_STRIPE_OK';
1369 dol_syslog(
"No card or payment method found for this stripe customer " . $customer->id, LOG_WARNING);
1370 $this->errors[] =
'Failed to get card | payment method for stripe customer = ' . $customer->id;
1372 $labeltouse =
'InvoicePaymentFailure';
1373 $sendemailtocustomer = 1;
1374 if ($noemailtocustomeriferror) {
1375 $sendemailtocustomer = 0;
1378 $description =
'Failed to find or use the payment mode - no credit card defined for the customer account';
1379 $stripefailurecode =
'BADPAYMENTMODE';
1380 $stripefailuremessage =
'Failed to find or use the payment mode - no credit card defined for the customer account';
1381 $postactionmessages[] = $description .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
1385 $actioncode =
'PAYMENT_STRIPE_KO';
1391 $sendemailtocustomer = 0;
1394 $stripefailurecode =
'';
1395 $stripefailuremessage =
'';
1403 if ($resultthirdparty <= 0) {
1404 dol_syslog(
'SellYourSaasUtils Failed to load customer for thirdparty_id = ' . $thirdparty->id, LOG_WARNING);
1405 $this->errors[] =
'Failed to load customer for thirdparty_id = ' . $thirdparty->id;
1407 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);
1408 $this->errors[] =
'Failed to get Stripe customer id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
1413 $labeltouse =
'InvoicePaymentFailure';
1414 $sendemailtocustomer = 1;
1415 if ($noemailtocustomeriferror) {
1416 $sendemailtocustomer = 0;
1419 $description =
'Failed to find or use your payment mode (no payment mode for this customer id)';
1420 $stripefailurecode =
'BADPAYMENTMODE';
1421 $stripefailuremessage =
'Failed to find or use your payment mode (no payment mode for this customer id)';
1422 $postactionmessages = [];
1426 $actioncode =
'PAYMENT_STRIPE_KO';
1431 if ($sendemailtocustomer && $labeltouse) {
1432 dol_syslog(
"* Send email with result of payment - " . $labeltouse);
1435 $outputlangs =
new Translate(
'', $conf);
1436 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1437 $outputlangs->loadLangs([
"main",
"members",
"bills"]);
1440 $arraydefaultmessage =
null;
1442 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
1445 if (!empty($labeltouse)) {
1446 $arraydefaultmessage = $formmail->getEMailTemplate($this->
db,
'facture_send', $user, $outputlangs, 0, 1, $labeltouse);
1449 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1450 $subject = $arraydefaultmessage->topic;
1451 $msg = $arraydefaultmessage->content;
1462 $foundcontract =
null;
1464 if (is_array($this->linkedObjects[
'contrat']) && count($this->linkedObjects[
'contrat']) > 0) {
1466 foreach ($this->linkedObjects[
'contrat'] as $idcontract => $contract) {
1467 $substitutionarray[
'__CONTRACT_REF__'] = $contract->ref_customer;
1468 $substitutionarray[
'__REFCLIENT__'] = $contract->ref_customer;
1469 $substitutionarray[
'__REF_CLIENT__'] = $contract->ref_customer;
1470 $foundcontract = $contract;
1475 dol_syslog(
'__DIRECTDOWNLOAD_URL_INVOICE__=' . $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__']);
1499 if (is_object($invoice)) {
1500 $invoicediroutput = $conf->facture->dir_output;
1502 $fileparams =
dol_most_recent_file($invoicediroutput .
'/' . $this->
ref, preg_quote($this->ref,
'/') .
'[^\-]+*.pdf');
1503 $file = $fileparams[
'fullname'];
1508 $listofpaths = [$file];
1509 $listofnames = [basename($file)];
1515 $trackid =
'inv' . $this->id;
1516 $moreinheader =
'X-Dolibarr-Info: makeStripeSepaRequest' .
"\r\n";
1519 include_once DOL_DOCUMENT_ROOT .
'/core/class/CMailFile.class.php';
1520 $mailfile =
new CMailFile($subjecttosend, $this->thirdparty->email, $from, $texttosend, $listofpaths, $listofmimes, $listofnames,
'',
'', 0, -1,
'',
'', $trackid, $moreinheader);
1521 if ($mailfile->sendfile()) {
1524 $this->error = $langs->trans(
"ErrorFailedToSendMail", $from, $this->thirdparty->email) .
'. ' . $mailfile->error;
1529 $errmsg = $this->error;
1530 $postactionmessages[] = $errmsg;
1531 $ispostactionok = -1;
1534 $postactionmessages[] =
'Email sent to thirdparty (to ' . $this->thirdparty->email .
' with invoice document attached: ' . $file .
', language = ' . $outputlangs->defaultlang .
')';
1536 $postactionmessages[] =
'Email sent to thirdparty (to ' . $this->thirdparty->email .
' without any attached document, language = ' . $outputlangs->defaultlang .
')';
1542 dol_syslog(
"* Record event for payment result - " . $description);
1543 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1548 $actioncomm->type_code =
'AC_OTH_AUTO';
1549 $actioncomm->code =
'AC_' . $actioncode;
1550 $actioncomm->label = $description;
1551 $actioncomm->note_private = join(
",\n", $postactionmessages);
1552 $actioncomm->fk_project = $this->fk_project;
1553 $actioncomm->datep = $now;
1554 $actioncomm->datef = $now;
1555 $actioncomm->percentage = -1;
1556 $actioncomm->socid = $thirdparty->id;
1557 $actioncomm->contactid = 0;
1558 $actioncomm->authorid = $user->id;
1559 $actioncomm->userownerid = $user->id;
1569 $actioncomm->fk_element = $this->id;
1570 $actioncomm->elementtype = $this->element;
1571 $actioncomm->extraparams =
dol_trunc($extraparams, 250);
1573 $actioncomm->create($user);
1577 $this->postactionmessages = $postactionmessages;
1581 dol_syslog(
'Error ' . $e->getMessage(), LOG_ERR);
1582 $this->errors[] =
'Error ' . $e->getMessage();
1587 dol_syslog(
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->
ref .
". Why is the invoice not classified 'Paid' ?", LOG_WARNING);
1588 $this->errors[] =
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->ref .
". Why is the invoice not classified 'Paid' ?";
1591 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_demande(";
1592 $sql .=
"fk_facture, ";
1593 $sql .=
" amount, date_demande, fk_user_demande, ext_payment_id, ext_payment_site, sourcetype, entity)";
1594 $sql .=
" VALUES (".$this->id;
1595 $sql .=
",".((float)
price2num($amount));
1596 $sql .=
",'".$this->db->idate($now).
"'";
1597 $sql .=
",".((int) $fuser->id);
1598 $sql .=
",'".$this->db->escape($stripe_id).
"'";
1599 $sql .=
",'".$this->db->escape($stripe_uri).
"'";
1600 $sql .=
",'".$this->db->escape($sourcetype).
"'";
1601 $sql .=
",".$conf->entity;
1604 dol_syslog(get_class($this).
"::makeStripeSepaRequest", LOG_DEBUG);
1607 $this->error = $this->
db->lasterror();
1608 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur');
1612 $this->error =
'WithdrawRequestErrorNilAmount';
1613 dol_syslog(get_class($this).
'::makeStripeSepaRequest WithdrawRequestErrorNilAmount');
1619 $payment_mode_id =
dol_getIdFromCode($this->
db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
1620 if ($payment_mode_id > 0) {
1630 $this->error = $this->
db->error();
1631 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur -2');
1635 $this->error =
"Status of invoice does not allow this";
1636 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error.
" $this->statut, $this->paye, $this->mode_reglement_id");
1652 $sql =
'DELETE FROM '.$this->db->prefix().
'prelevement_demande';
1653 $sql .=
' WHERE rowid = '.((int) $did);
1654 $sql .=
' AND traite = 0';
1655 if ($this->
db->query($sql)) {
1658 $this->error = $this->
db->lasterror();
1659 dol_syslog(get_class($this).
'::demande_prelevement_delete Error '.$this->error);
1672 global $conf, $mysoc;
1675 $tmplang->setDefaultLang(
'en_US');
1676 $tmplang->load(
"main");
1681 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
1682 $pricetaxstring =
price2num($this->total_tva, 2, 1);
1709 $s = pack(
'C1', 1).pack(
'C1', strlen($mysoc->name)).$mysoc->name;
1710 $s .= pack(
'C1', 2).pack(
'C1', strlen($mysoc->tva_intra)).$mysoc->tva_intra;
1711 $s .= pack(
'C1', 3).pack(
'C1', strlen($datestring)).$datestring;
1712 $s .= pack(
'C1', 4).pack(
'C1', strlen($pricewithtaxstring)).$pricewithtaxstring;
1713 $s .= pack(
'C1', 5).pack(
'C1', strlen($pricetaxstring)).$pricetaxstring;
1719 $s = base64_encode($s);
1732 global $conf, $mysoc;
1735 $tmplang->setDefaultLang(
'en_US');
1736 $tmplang->load(
"main");
1738 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
1739 $pricetaxstring =
price2num($this->total_tva, 2, 1);
1741 $complementaryinfo =
'';
1755 $complementaryinfo =
'//S1/10/'.str_replace(
'/',
'', $this->
ref).
'/11/'.$datestring;
1756 if ($this->ref_client) {
1757 $complementaryinfo .=
'/20/'.$this->ref_client;
1759 if ($this->thirdparty->tva_intra) {
1760 $complementaryinfo .=
'/30/'.$this->thirdparty->tva_intra;
1768 if ($this->fk_account > 0) {
1772 $bankaccount->fetch($this->fk_account);
1773 $s .= $bankaccount->iban.
"\n";
1779 $s .=
dol_trunc($mysoc->name, 70,
'right',
'UTF-8', 1).
"\n";
1780 $addresslinearray = explode(
"\n", $mysoc->address);
1781 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
1782 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
1783 $s .=
dol_trunc($mysoc->zip, 16,
'right',
'UTF-8', 1).
"\n";
1784 $s .=
dol_trunc($mysoc->town, 35,
'right',
'UTF-8', 1).
"\n";
1785 $s .=
dol_trunc($mysoc->country_code, 2,
'right',
'UTF-8', 1).
"\n";
1795 $s .=
price($pricewithtaxstring, 0,
'none', 0, 0, 2).
"\n";
1796 $s .= ($this->multicurrency_code ? $this->multicurrency_code : $conf->currency).
"\n";
1799 $s .=
dol_trunc($this->thirdparty->name, 70,
'right',
'UTF-8', 1).
"\n";
1800 $addresslinearray = explode(
"\n", $this->thirdparty->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($this->thirdparty->zip, 16,
'right',
'UTF-8', 1).
"\n";
1804 $s .=
dol_trunc($this->thirdparty->town, 35,
'right',
'UTF-8', 1).
"\n";
1805 $s .=
dol_trunc($this->thirdparty->country_code, 2,
'right',
'UTF-8', 1).
"\n";
1809 if ($complementaryinfo) {
1810 $s .= $complementaryinfo.
"\n";
1823 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1851 public $product_type = 0;
1857 public $product_ref;
1863 public $product_label;
1869 public $product_desc;
1900 public $vat_src_code;
1912 public $localtax1_tx;
1918 public $localtax2_tx;
1924 public $localtax1_type;
1930 public $localtax2_type;
1936 public $remise_percent;
1961 public $total_localtax1;
1967 public $total_localtax2;
1975 public $date_start_fill;
1976 public $date_end_fill;
1978 public $buy_price_ht;
1991 public $info_bits = 0;
1993 public $special_code = 0;
1995 public $fk_multicurrency;
1996 public $multicurrency_code;
1997 public $multicurrency_subprice;
1998 public $multicurrency_total_ht;
1999 public $multicurrency_total_tva;
2000 public $multicurrency_total_ttc;
2002 public $fk_user_author;
2003 public $fk_user_modif;
2005 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.
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.