diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 9706f123cbb..f35f1c5b49a 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -3570,78 +3570,6 @@ parameters: count: 1 path: ../../../htdocs/compta/prelevement/card.php - - - message: '#^Call to function method_exists\(\) with \$this\(BonPrelevement\) and ''LibStatut'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Call to function method_exists\(\) with \$this\(BonPrelevement\) and ''getNomUrl'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(BonPrelevement\) and ''date_echeance'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(BonPrelevement\) and ''total'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^If condition is always true\.$#' - identifier: if.alwaysTrue - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Loose comparison using \=\= between 0 and 1 will always evaluate to false\.$#' - identifier: equal.alwaysFalse - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Property BonPrelevement\:\:\$amount \(float\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Property BonPrelevement\:\:\$date_trans \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Property BonPrelevement\:\:\$factures has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Property BonPrelevement\:\:\$invoice_in_error has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - - - message: '#^Property BonPrelevement\:\:\$thirdparty_in_error has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../../htdocs/compta/prelevement/class/bonprelevement.class.php - - message: '#^Right side of \|\| is always true\.$#' identifier: booleanOr.rightAlwaysTrue diff --git a/htdocs/bookcal/availabilities_contact.php b/htdocs/bookcal/availabilities_contact.php index bcd852ee5e6..e8b7f950112 100644 --- a/htdocs/bookcal/availabilities_contact.php +++ b/htdocs/bookcal/availabilities_contact.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -189,9 +189,12 @@ if ($object->id) { // Contacts lines (modules that overwrite templates must declare this into descriptor) $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); foreach ($dirtpls as $reldir) { - $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); - if ($res) { - break; + $file = dol_buildpath($reldir.'/contacts.tpl.php'); + if (file_exists($file)) { + $res = @include $file; + if ($res) { + break; + } } } } diff --git a/htdocs/bookcal/class/availabilities.class.php b/htdocs/bookcal/class/availabilities.class.php index 0613362a613..5da3e3c04f7 100644 --- a/htdocs/bookcal/class/availabilities.class.php +++ b/htdocs/bookcal/class/availabilities.class.php @@ -212,7 +212,7 @@ class Availabilities extends CommonObject if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) { // @phan-suppress-current-line PhanTypeMismatchProperty $this->fields['rowid']['visible'] = 0; } - if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) { + if (!isModEnabled('multicompany') && isset($this->fields['entity'])) { $this->fields['entity']['enabled'] = 0; } diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php index 0eecf0c4592..a2a4a63ed57 100644 --- a/htdocs/commande/contact.php +++ b/htdocs/commande/contact.php @@ -185,9 +185,12 @@ if ($id > 0 || !empty($ref)) { // Contacts lines (modules that overwrite templates must declare this into descriptor) $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); foreach ($dirtpls as $reldir) { - $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); - if ($res) { - break; + $file = dol_buildpath($reldir.'/contacts.tpl.php'); + if (file_exists($file)) { + $res = @include $file; + if ($res) { + break; + } } } } else { diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php index 02e169952dc..07d518c7f6c 100644 --- a/htdocs/compta/facture/contact.php +++ b/htdocs/compta/facture/contact.php @@ -194,9 +194,12 @@ if ($id > 0 || !empty($ref)) { // Contacts lines (modules that overwrite templates must declare this into descriptor) $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); foreach ($dirtpls as $reldir) { - $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); - if ($res) { - break; + $file = dol_buildpath($reldir.'/contacts.tpl.php'); + if (file_exists($file)) { + $res = @include $file; + if ($res) { + break; + } } } } else { diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 724fc340a47..f904663dc80 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -5,9 +5,9 @@ * Copyright (C) 2010-2014 Laurent Destailleur * Copyright (C) 2014-2016 Ferran Marcet * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2019 JC Prieto + * Copyright (C) 2019 JC Prieto * Copyright (C) 2024-2025 MDW - * Copyright (C) 2024-2025 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -63,7 +63,7 @@ class BonPrelevement extends CommonObject public $picto = 'payment'; /** - * @var int|string + * @var int|''|null */ public $date_echeance; /** @@ -118,15 +118,20 @@ class BonPrelevement extends CommonObject public $user_credit; /** - * @var float|int|string + * @var float|int|string|null */ public $total; + /** * @var int */ public $fetched; + public $labelStatus = array(); + /** + * @var array + */ public $factures = array(); /** @@ -134,7 +139,14 @@ class BonPrelevement extends CommonObject */ public $methodes_trans = array(); + /** + * @var array + */ public $invoice_in_error = array(); + + /** + * @var array + */ public $thirdparty_in_error = array(); /** @@ -224,13 +236,14 @@ class BonPrelevement extends CommonObject * @var int|string */ public $datec; + /** - * @var float + * @var ?float */ public $amount; /** - * @var int Status + * @var int|null Status * @deprecated Use $status */ public $statut; @@ -247,8 +260,9 @@ class BonPrelevement extends CommonObject * @var string */ public $note; + /** - * @var int|string + * @var int|''|null */ public $date_trans; /** @@ -318,7 +332,7 @@ class BonPrelevement extends CommonObject * @param int $invoice_id ID of invoice to add or ID of salary to add * @param int $client_id id invoice customer * @param string $client_nom customer name - * @param int $amount amount of invoice + * @param float $amount amount of invoice * @param string $code_banque code of bank withdrawal * @param string $code_guichet code of bank's office * @param string $number bank account number @@ -384,7 +398,7 @@ class BonPrelevement extends CommonObject * @param int $line_id ID of line added (returned parameter) * @param int $client_id ID of thirdparty for invoices, ID of user for salaries * @param string $client_nom customer name - * @param int $amount amount of invoice + * @param float $amount amount of invoice * @param string $code_banque code of bank withdrawal (Deprecated, not used) * @param string $code_guichet code of bank's office (Deprecated, not used) * @param string $number bank account number (Deprecated, not used) @@ -398,7 +412,7 @@ class BonPrelevement extends CommonObject public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype = '', $bic = '', $iban = '', $rum = '') { $result = -1; - $concat = 0; // ??? what is this for. Seems not used. + $concat = getDolGlobalInt('MAIN_MODULE_PRELEVEMENT_CONCAT'); // ??? what is this for. Seems not used. if ($concat == 1) { /* @@ -517,17 +531,17 @@ class BonPrelevement extends CommonObject $this->method_trans = $obj->method_trans; $this->user_trans = $obj->fk_user_trans; - $this->date_credit = $this->db->jdate($obj->date_credit); - $this->user_credit = $obj->fk_user_credit; + $this->date_credit = $this->db->jdate($obj->date_credit); + $this->user_credit = $obj->fk_user_credit; - $this->type = $obj->type; + $this->type = $obj->type; $this->fk_bank_account = $obj->fk_bank_account; - $this->status = $obj->status; + $this->status = $obj->status; if (empty($this->status)) { // Value is sometimes null in database $this->status = 0; } - $this->statut = $this->status; // For backward compatibility + $this->statut = $this->status; // For backward compatibility $this->fetched = 1; @@ -1147,93 +1161,92 @@ class BonPrelevement extends CommonObject $factures_prev = array(); $factures_prev_id = array(); - if (!$error) { - dol_syslog(__METHOD__ . " Read invoices for did=" . ((int) $did), LOG_DEBUG); + dol_syslog(__METHOD__ . " Read invoices for did=" . ((int) $did), LOG_DEBUG); - $sql = "SELECT f.rowid, pd.rowid as pfdrowid"; - $sql .= ", f.".$this->db->sanitize($socOrUser); // fk_soc or fk_user - $sql .= ", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib"; - $sql .= ", pd.amount"; - if ($sourcetype != 'salary') { - $sql .= ", s.nom as name"; - $sql .= ", f.ref"; - $sql .= ", sr.bic, sr.iban_prefix, sr.frstrecur, sr.default_rib, sr.rum"; + $sql = "SELECT f.rowid, pd.rowid as pfdrowid"; + $sql .= ", f.".$this->db->sanitize($socOrUser); // fk_soc or fk_user + $sql .= ", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib"; + $sql .= ", pd.amount"; + if ($sourcetype != 'salary') { + $sql .= ", s.nom as name"; + $sql .= ", f.ref"; + $sql .= ", sr.bic, sr.iban_prefix, sr.frstrecur, sr.default_rib, sr.rum"; + } else { + $sql .= ", CONCAT(s.firstname, ' ', s.lastname) as name"; + $sql .= ", f.ref"; + $sql .= ", sr.bic, sr.iban_prefix, 'FRST' as frstrecur, sr.default_rib, '' as rum"; + } + $sql .= ", pd.fk_societe_rib as soc_rib_id"; + $sql .= " FROM " . $this->db->prefix() . $sqlTable . " as f"; // f is salary, facture or facture_fourn + $sql .= " LEFT JOIN " . $this->db->prefix() . "prelevement_demande as pd ON f.rowid = pd.fk_".$this->db->sanitize($sqlTable); + $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser)." as s ON s.rowid = f.".$this->db->sanitize($socOrUser); + $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser."_rib")." as sr ON s.rowid = sr.".$this->db->sanitize($socOrUser); + if ($sourcetype != 'salary') { + if (!empty($thirdpartyBANId)) { + $sql .= " AND sr.rowid = " . ((int) $thirdpartyBANId); } else { - $sql .= ", CONCAT(s.firstname, ' ', s.lastname) as name"; - $sql .= ", f.ref"; - $sql .= ", sr.bic, sr.iban_prefix, 'FRST' as frstrecur, sr.default_rib, '' as rum"; + $sql .= " AND sr.default_rib = 1"; } - $sql .= ", pd.fk_societe_rib as soc_rib_id"; - $sql .= " FROM " . $this->db->prefix() . $sqlTable . " as f"; // f is salary, facture or facture_fourn - $sql .= " LEFT JOIN " . $this->db->prefix() . "prelevement_demande as pd ON f.rowid = pd.fk_".$this->db->sanitize($sqlTable); - $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser)." as s ON s.rowid = f.".$this->db->sanitize($socOrUser); - $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser."_rib")." as sr ON s.rowid = sr.".$this->db->sanitize($socOrUser); - if ($sourcetype != 'salary') { - if (!empty($thirdpartyBANId)) { - $sql .= " AND sr.rowid = " . ((int) $thirdpartyBANId); - } else { - $sql .= " AND sr.default_rib = 1"; + $sql .= " AND sr.type = 'ban'"; + } else { + //$sql .= " AND sr.type = 'ban'"; // TODO Add AND sr.type = 'ban' for users too + // TODO Add 'AND sr.default_rib = 1' in sourcetype salary too + // Note: the column has been created in v21 in llx_user_rib and default to 0 + // If we add a test on sr.default_rib = 1, we must also check we have a correct error management to stop if no default BAN is found. + // Also it may be found for on thirdparty and not for the other. + } + $sql .= " WHERE f.entity IN (".$this->db->escape($entities).')'; + if ($sourcetype != 'salary') { + $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; // Invoice validated + $sql .= " AND f.paye = 0"; + $sql .= " AND f.total_ttc > 0"; + /*if ($socid > 0) { + $sql .= " AND f.fk_soc = ".((int) $socid); + }*/ + } else { + //$sql .= " AND f.fk_statut = 1"; // Invoice validated + $sql .= " AND f.paye = 0"; + $sql .= " AND f.amount > 0"; + } + $sql .= " AND pd.traite = 0"; + $sql .= " AND pd.ext_payment_id IS NULL"; + if ($did > 0) { + $sql .= " AND pd.rowid = " . ((int) $did); + } + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + + while ($i < $num) { + $row = $this->db->fetch_row($resql); // TODO Replace with fetch_object() + '@phan-var-force array,string> $row'; + /** @var array{0:int|string,1:int,2:int,3:string,4:string,5:string,6,string,7:float,8:string,9:string,10:string,11:string,12:string,13:string,14:string,15:int} $row */ + + // All fields: + // 0=rowid, 1=pfdrowid, 2=$socOrUser, 3=code_banque, 4=code_guichet, 5=number, 6=key, + // 7=amount, 8=name, 9=ref, 10=bic, 11=iban, 12=frstrecur, 13=default_rib, 14=rum, 15=soc_rib_id + $factures[$i] = $row; + + // Decode BAN + $factures[$i][11] = dolDecrypt($factures[$i][11]); + + if ($row[7] == 0) { + $error++; + dol_syslog(__METHOD__ . " Read invoices/salary error Found a null amount", LOG_ERR); + $this->invoice_in_error[$row[0]] = "Error for invoice or salary id " . $row[0] . ", found a null amount"; + break; } - $sql .= " AND sr.type = 'ban'"; - } else { - //$sql .= " AND sr.type = 'ban'"; // TODO Add AND sr.type = 'ban' for users too - // TODO Add 'AND sr.default_rib = 1' in sourcetype salary too - // Note: the column has been created in v21 in llx_user_rib and default to 0 - // If we add a test on sr.default_rib = 1, we must also check we have a correct error management to stop if no default BAN is found. - // Also it may be found for on thirdparty and not for the other. - } - $sql .= " WHERE f.entity IN (".$this->db->escape($entities).')'; - if ($sourcetype != 'salary') { - $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; // Invoice validated - $sql .= " AND f.paye = 0"; - $sql .= " AND f.total_ttc > 0"; - /*if ($socid > 0) { - $sql .= " AND f.fk_soc = ".((int) $socid); - }*/ - } else { - //$sql .= " AND f.fk_statut = 1"; // Invoice validated - $sql .= " AND f.paye = 0"; - $sql .= " AND f.amount > 0"; - } - $sql .= " AND pd.traite = 0"; - $sql .= " AND pd.ext_payment_id IS NULL"; - if ($did > 0) { - $sql .= " AND pd.rowid = " . ((int) $did); + $i++; } - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - $i = 0; - - while ($i < $num) { - $row = $this->db->fetch_row($resql); // TODO Replace with fetch_object() - '@phan-var-force array,string> $row'; - - // All fields: - // 0=rowid, 1=pfdrowid, 2=$socOrUser, 3=code_banque, 4=code_guichet, 5=number, 6=key, - // 7=amount, 8=name, 9=ref, 10=bic, 11=iban, 12=frstrecur, 13=default_rib, 14=rum, 15=soc_rib_id - $factures[$i] = $row; - - // Decode BAN - $factures[$i][11] = dolDecrypt($factures[$i][11]); - - if ($row[7] == 0) { - $error++; - dol_syslog(__METHOD__ . " Read invoices/salary error Found a null amount", LOG_ERR); - $this->invoice_in_error[$row[0]] = "Error for invoice or salary id " . $row[0] . ", found a null amount"; - break; - } - $i++; - } - - $this->db->free($resql); - dol_syslog(__METHOD__ . " Read invoices/salary, " . $i . " invoices/salary to withdraw", LOG_DEBUG); - } else { - $this->error = $this->db->lasterror(); - dol_syslog(__METHOD__ . " Read invoices/salary error " . $this->db->lasterror(), LOG_ERR); - return -1; - } + $this->db->free($resql); + dol_syslog(__METHOD__ . " Read invoices/salary, " . $i . " invoices/salary to withdraw", LOG_DEBUG); + } else { + $this->error = $this->db->lasterror(); + dol_syslog(__METHOD__ . " Read invoices/salary error " . $this->db->lasterror(), LOG_ERR); + return -1; } if (!$error) { @@ -1465,7 +1478,21 @@ class BonPrelevement extends CommonObject * $fac[14] : rum * $fac[15] : soc_rib_id (id bank account preselected for direct debit or credit transfer) */ - $ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type, $sourcetype, $fac[10], $fac[11], $fac[14]); + $ri = $this->AddFacture( + $fac[0], + $fac[2], + $fac[8], + $fac[7], + $fac[3], + $fac[4], + $fac[5], + $fac[6], + $type, + $sourcetype, + $fac[10], + $fac[11], + $fac[14] + ); if ($ri != 0) { $error++; @@ -2564,7 +2591,7 @@ class BonPrelevement extends CommonObject * Write sender of request (me). * Note: The tag PmtInf is opened here but closed into caller * - * @param Conf $configuration conf + * @param Conf $configuration conf Unused * @param int $ladate Date * @param int $nombre 0 or 1 * @param float $total Total @@ -2613,12 +2640,12 @@ class BonPrelevement extends CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); - $country = explode(':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY); + $country = explode(':', getDolGlobalString('MAIN_INFO_SOCIETE_COUNTRY')); $IdBon = sprintf("%05d", $obj->rowid); $RefBon = $obj->ref; $localInstrument = getDolGlobalString('PAYMENTBYBANKTRANSFER_CUSTOM_LOCAL_INSTRUMENT', 'CORE'); - if (!empty($configuration->global->SEPA_FORCE_TWO_DECIMAL)) { + if (getDolGlobalString('SEPA_FORCE_TWO_DECIMAL')) { $total = number_format((float) price2num($total, 'MT'), 2, ".", ""); } @@ -2644,8 +2671,8 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' ' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))) . '' . $CrLf; $XML_SEPA_INFO .= ' ' . $CrLf; $XML_SEPA_INFO .= ' ' . $country[1] . '' . $CrLf; - $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) => ", ", chr(10) => "")); - $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP . (($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' ' . $configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '') . $configuration->global->MAIN_INFO_SOCIETE_TOWN, array(chr(13) => ", ", chr(10) => "")); + $addressline1 = strtr(getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) => ", ", chr(10) => "")); + $addressline2 = strtr(getDolGlobalString('MAIN_INFO_SOCIETE_ZIP') . ((getDolGlobalString('MAIN_INFO_SOCIETE_ZIP') || ' ' . getDolGlobalString('MAIN_INFO_SOCIETE_TOWN')) ? ' ' : '') . getDolGlobalString('MAIN_INFO_SOCIETE_TOWN'), array(chr(13) => ", ", chr(10) => "")); if ($addressline1) { $XML_SEPA_INFO .= ' ' . dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1), ' '), 70, 'right', 'UTF-8', 1)) . '' . $CrLf; } @@ -2668,8 +2695,8 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS')), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ZIP').' '.getDolGlobalString('MAIN_INFO_SOCIETE_TOWN')), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf;*/ $XML_SEPA_INFO .= ' SLEV' . $CrLf; // Field "Responsible of fees". Must be SLEV @@ -2710,8 +2737,8 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' ' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))) . '' . $CrLf; $XML_SEPA_INFO .= ' ' . $CrLf; $XML_SEPA_INFO .= ' ' . $country[1] . '' . $CrLf; - $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) => ", ", chr(10) => "")); - $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP . (($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' ' . $configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '') . $configuration->global->MAIN_INFO_SOCIETE_TOWN, array(chr(13) => ", ", chr(10) => "")); + $addressline1 = strtr(getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) => ", ", chr(10) => "")); + $addressline2 = strtr(getDolGlobalString('MAIN_INFO_SOCIETE_ZIP') . ((getDolGlobalString('MAIN_INFO_SOCIETE_ZIP') || ' ' . getDolGlobalString('MAIN_INFO_SOCIETE_TOWN')) ? ' ' : '') . getDolGlobalString('MAIN_INFO_SOCIETE_TOWN'), array(chr(13) => ", ", chr(10) => "")); if ($addressline1) { $XML_SEPA_INFO .= ' ' . dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1), ' '), 70, 'right', 'UTF-8', 1)) . '' . $CrLf; } @@ -2734,8 +2761,8 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS')), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ZIP').' '.getDolGlobalString('MAIN_INFO_SOCIETE_TOWN')), ' '), 70, 'right', 'UTF-8', 1)).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf;*/ $XML_SEPA_INFO .= ' SLEV' . $CrLf; // Field "Responsible of fees". Must be SLEV @@ -2962,19 +2989,17 @@ class BonPrelevement extends CommonObject $return .= img_picto('', $this->picto); $return .= ''; $return .= '
'; - $return .= '' . (method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref) . ''; + $return .= '' . $this->getNomUrl(1) . ''; if ($selected >= 0) { $return .= ''; } - if (property_exists($this, 'date_echeance')) { + if (isset($this->date_echeance)) { $return .= '
' . $langs->trans("Date") . ' : ' . dol_print_date($this->db->jdate($this->date_echeance), 'day') . ''; } - if (property_exists($this, 'total')) { + if (isset($this->total)) { $return .= '
' . $langs->trans("Amount") . ' : ' . price($this->total) . ''; } - if (method_exists($this, 'LibStatut')) { - $return .= '
' . $this->getLibStatut(3) . '
'; - } + $return .= '
' . $this->getLibStatut(3) . '
'; $return .= '
'; $return .= ''; $return .= ''; @@ -2993,24 +3018,22 @@ class BonPrelevement extends CommonObject } else { return 0; } - if ($id) { - $sql = "SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX . "prelevement_lignes"; - $sql .= " WHERE fk_prelevement_bons = " . ((int) $id); - $sql .= " AND fk_soc = 0"; // fk_soc can't be NULL - $sql .= " AND fk_user IS NOT NULL"; + $sql = "SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX . "prelevement_lignes"; + $sql .= " WHERE fk_prelevement_bons = " . ((int) $id); + $sql .= " AND fk_soc = 0"; // fk_soc can't be NULL + $sql .= " AND fk_user IS NOT NULL"; - $num = 0; - $resql = $this->db->query($sql); - if ($resql) { - $obj = $this->db->fetch_object($resql); - $num = $obj->nb; - } - if ($num > 0) { - return 1; - } + $num = 0; + $resql = $this->db->query($sql); + if ($resql) { + $obj = $this->db->fetch_object($resql); + $num = $obj->nb; } else { dol_print_error($this->db); } + if ($num > 0) { + return 1; + } return 0; } diff --git a/htdocs/core/modules/modMargin.class.php b/htdocs/core/modules/modMargin.class.php index 274cb6e4550..b222fe038e0 100644 --- a/htdocs/core/modules/modMargin.class.php +++ b/htdocs/core/modules/modMargin.class.php @@ -1,7 +1,8 @@ - * Copyright (C) 2015 Marcos García - * Copyright (C) 2024 MDW +/* Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2015 Marcos García + * Copyright (C) 2024 MDW + * Copyright (C) 2025 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -86,8 +87,8 @@ class modMargin extends DolibarrModules // New pages on tabs $this->tabs = array( - 'product:+margin:Margins:margins:$user->rights->margins->liretous:/margin/tabs/productMargins.php?id=__ID__', - 'thirdparty:+margin:Margins:margins:empty($user->socid) && $user->rights->margins->liretous && ($object->client > 0):/margin/tabs/thirdpartyMargins.php?socid=__ID__' + 'product:+margin:Margins:margins:$user->hasRight("margins","liretous"):/margin/tabs/productMargins.php?id=__ID__', + 'thirdparty:+margin:Margins:margins:empty($user->socid) && $user->hasRight("margins","liretous") && ($object->client > 0):/margin/tabs/thirdpartyMargins.php?socid=__ID__' ); @@ -115,7 +116,7 @@ class modMargin extends DolibarrModules 'langs' => 'margins', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. 'position' => 100, 'enabled' => 'isModEnabled("margin")', // Define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled. - 'perms' => '$user->rights->margins->liretous', // Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules + 'perms' => '$user->hasRight("margins","liretous")', // Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules 'target' => '', 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both ); diff --git a/htdocs/core/modules/modWebsite.class.php b/htdocs/core/modules/modWebsite.class.php index 1680322c42b..6b8b98f9a03 100644 --- a/htdocs/core/modules/modWebsite.class.php +++ b/htdocs/core/modules/modWebsite.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 Frédéric France +/* Copyright (C) 2015 Laurent Destailleur + * Copyright (C) 2024-2025 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -115,18 +115,20 @@ class modWebsite extends DolibarrModules // Main menu entries $r = 0; - $this->menu[$r] = array('fk_menu'=>'0', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode - 'type'=>'top', // This is a Left menu entry - 'titre'=>'WebSites', - 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth em092"'), - 'mainmenu'=>'website', - 'url'=>'/website/index.php', - 'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position'=>100, - 'enabled'=>'$conf->website->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. - 'perms'=>'$user->rights->website->read', // Use 'perms'=>'$user->hasRight("mymodule","level1","level2")' if you want your menu with a permission rules - 'target'=>'', - 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + $this->menu[$r] = [ + 'fk_menu' => '0', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type' => 'top', // This is a Left menu entry + 'titre' => 'WebSites', + 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth em092"'), + 'mainmenu' => 'website', + 'url' => '/website/index.php', + 'langs' => 'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position' => 100, + 'enabled' => 'isModEnabled("website")', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. + 'perms' => '$user->hasRight("website","read")', // Use 'perms'=>'$user->hasRight("mymodule","level1","level2")' if you want your menu with a permission rules + 'target' => '', + 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both + ]; $r++; // Exports diff --git a/htdocs/don/list.php b/htdocs/don/list.php index 5e84c977f28..7b2e0b2688a 100644 --- a/htdocs/don/list.php +++ b/htdocs/don/list.php @@ -67,6 +67,14 @@ $search_company = GETPOST('search_company', 'alpha'); $search_thirdparty = GETPOST('search_thirdparty', 'alpha'); $search_name = GETPOST('search_name', 'alpha'); $search_amount = GETPOST('search_amount', 'alpha'); +$search_date_startday = GETPOSTINT('search_date_startday'); +$search_date_startmonth = GETPOSTINT('search_date_startmonth'); +$search_date_startyear = GETPOSTINT('search_date_startyear'); +$search_date_endday = GETPOSTINT('search_date_endday'); +$search_date_endmonth = GETPOSTINT('search_date_endmonth'); +$search_date_endyear = GETPOSTINT('search_date_endyear'); +$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver +$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); $moreforfilter = GETPOST('moreforfilter', 'alpha'); // Load variable for pagination @@ -177,6 +185,14 @@ if (empty($reshook)) { $search_name = ""; $search_amount = ""; $search_status = ''; + $search_date_startday = ''; + $search_date_startmonth = ''; + $search_date_startyear = ''; + $search_date_endday = ''; + $search_date_endmonth = ''; + $search_date_endyear = ''; + $search_date_start = ''; + $search_date_end = ''; $toselect = array(); $search_array_options = array(); } @@ -257,6 +273,12 @@ if (trim($search_name) != '') { if ($search_amount) { $sql .= natural_search('d.amount', $search_amount, 1); } +if ($search_date_start) { + $sql .= " AND d.datedon >= '".$db->idate($search_date_start)."'"; +} +if ($search_date_end) { + $sql .= " AND d.datedon <= '".$db->idate($search_date_end)."'"; +} // Count total nb of records $nbtotalofrecords = ''; @@ -355,6 +377,25 @@ if ($search_name) { if ($search_amount) { $param .= '&search_amount='.urlencode($search_amount); } +if ($search_date_startday) { + $param .= '&search_date_startday='.urlencode((string) ($search_date_startday)); +} +if ($search_date_startmonth) { + $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth)); +} +if ($search_date_startyear) { + $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear)); +} +if ($search_date_endday) { + $param .= '&search_date_endday='.urlencode((string) ($search_date_endday)); +} +if ($search_date_endmonth) { + $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth)); +} +if ($search_date_endyear) { + $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear)); +} + // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; // Add $param from hooks @@ -362,6 +403,7 @@ $parameters = array('param' => &$param); $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $param .= $hookmanager->resPrint; + // List of mass actions available $arrayofmassactions = array( //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"), @@ -473,8 +515,14 @@ if (getDolGlobalString('DONATION_USE_THIRDPARTIES')) { print ''; print ''; print ''; -print ''; -print ' '; +// Date invoice +print ''; +print '
'; +print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); +print '
'; +print '
'; +print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); +print '
'; print ''; if (isModEnabled('project')) { print ''; diff --git a/htdocs/hrm/compare.php b/htdocs/hrm/compare.php index 0eab2f75ecf..742486553b3 100644 --- a/htdocs/hrm/compare.php +++ b/htdocs/hrm/compare.php @@ -63,7 +63,7 @@ $job = new Job($db); $permissiontoread = $user->hasRight('hrm', 'evaluation', 'read') || $user->hasRight('hrm', 'compare_advance', 'read'); $permissiontoadd = 0; -if (empty($conf->hrm->enabled)) { +if (!isModEnabled('hrm')) { accessforbidden(); } if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) { diff --git a/htdocs/langs/en_US/donations.lang b/htdocs/langs/en_US/donations.lang index 873e7c672e9..cb3323e4c58 100644 --- a/htdocs/langs/en_US/donations.lang +++ b/htdocs/langs/en_US/donations.lang @@ -57,3 +57,7 @@ donAnonymous=Anonymous donation AnonymousDonationTooltip=Check this box if you want your donation to remain anonymous. Your personal information will not be asked. publicDonationFieldHelp=%s can publish my donation in the public register listOfPublicDonations=List of public donations +donationErrorMessageContactEmail=An error has occurred. To complete your donation, please contact us at %s +descDonationLineInInvoice=Donation and contribution +companyBusinessNumber=Business Registration Number +companyTIN=Tax Identification Number \ No newline at end of file diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index a568588aa3f..c9c7241f749 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -179,7 +179,7 @@ class MyObject extends CommonObject public $fk_soc; // both socid and fk_soc are used /** - * @var int Status + * @var ?int Status */ public $status; @@ -843,7 +843,7 @@ class MyObject extends CommonObject if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { $add_save_lastsearch_values = 1; } - if ($url && $add_save_lastsearch_values) { + if ($add_save_lastsearch_values) { $url .= '&save_lastsearch_values=1'; } } diff --git a/htdocs/public/invoice/new.php b/htdocs/public/invoice/new.php new file mode 100644 index 00000000000..d896b0c0859 --- /dev/null +++ b/htdocs/public/invoice/new.php @@ -0,0 +1,594 @@ + + * Copyright (C) 2001-2002 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2012 J. Fernando Lagrange + * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018 Alexandre Spangaro + * Copyright (C) 2021 Waël Almoman + * Copyright (C) 2022 Udo Tamm + * Copyright (C) 2024-2025 MDW + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/public/invoice/new.php + * \ingroup invoice + * \brief Example of form to add a new invoice + * + * Note that you can add following constant to change behaviour of page + * DONATION_INVOICE_MIN_AMOUNT Minimum amount + * PRODUCT_ID_FOR_FREE_AMOUNT_INVOICE Product ID used for free amount invoice line + */ + +if (!defined('NOLOGIN')) { + define("NOLOGIN", 1); // This means this output page does not require to be logged. +} +if (!defined('NOCSRFCHECK')) { + define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. +} +if (!defined('NOBROWSERNOTIF')) { + define('NOBROWSERNOTIF', '1'); +} + + +// For MultiCompany module. +// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php +// Because 2 entities can have the same ref. +$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +// if (is_numeric($entity)) { // $entity is casted to int +define("DOLENTITY", $entity); +// } + + +// Load Dolibarr environment +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +if (isModEnabled('project') || isModEnabled('eventorganization')) { + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +} + +// Init vars +$backtopage = GETPOST('backtopage', 'alpha'); +$action = GETPOST('action', 'aZ09'); +$ws = GETPOST('ws', 'aZ09'); // Website reference where the this public page is embedded or from where is called +$paymentmethod = GETPOST('paymentmethod', 'aZ09'); // Payment method to use + +$errmsg = ''; +$num = 0; +$error = 0; + +/** + * @var Conf $conf + * @var DoliDB $db + * @var HookManager $hookmanager + * @var Societe $mysoc + * @var Translate $langs + * @var User $user + */ + +// Load translation files +$langs->loadLangs(array("main", "donations", "companies", "install", "other", "errors")); + +// Security check +if (!isModEnabled('invoice')) { + httponly_accessforbidden('Module invoice not enabled'); +} + +if (!getDolGlobalString('PRODUCT_ID_FOR_FREE_AMOUNT_INVOICE')) { + httponly_accessforbidden('PRODUCT_ID_FOR_FREE_AMOUNT_INVOICE is not defined'); +} + +if (!getDolGlobalString('DONATION_INVOICE_MIN_AMOUNT')) { + httponly_accessforbidden('DONATION_INVOICE_MIN_AMOUNT is not defined'); +} + +// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context +//$hookmanager->initHooks(array( 'globalcard')); + +$extrafields = new ExtraFields($db); + +$object = new Facture($db); + +$user->loadDefaultValues(); + + +/** + * Show header for new donation + * + * Note: also called by functions.lib:recordNotFound + * + * @param string $title Title + * @param string $head Head array + * @param int $disablejs More content into html header + * @param int $disablehead More content into html header + * @param string[]|string $arrayofjs Array of complementary js files + * @param string[]|string $arrayofcss Array of complementary css files + * @param string $ws Website ref if we are called from a website + * @return void + */ +function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $ws = '') // @phan-suppress-current-line PhanRedefineFunction +{ + global $conf, $langs, $mysoc; + + top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers + + print ''; + + if (!$ws) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + htmlPrintOnlineHeader($mysoc, $langs, 1); + } + + print '
'; +} + +/** + * Show footer for new donation + * + * Note: also called by functions.lib:recordNotFound + * + * @return void + */ +function llxFooterVierge() // @phan-suppress-current-line PhanRedefineFunction +{ + global $conf, $langs; + + print '
'; + + printCommonFooter('public'); + + if (!empty($conf->use_javascript_ajax)) { + print "\n".''."\n"; + print ''."\n"; + } + + print "\n"; + print "\n"; +} + + + +/* + * Actions + */ + +$parameters = array(); +// Note that $action and $object may have been modified by some hooks +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +// Action called when page is submitted +if (empty($reshook) && $action == 'add') { // Test on permission not required here. This is an anonymous form. Check is done on constant to enable and mitigation. + $error = 0; + $urlback = ''; + + $email = GETPOST("email", "aZ09arobase"); + $firstname = GETPOST("firstname", "aZ09"); + $lastname = GETPOST("lastname", "aZ09"); + $societe = GETPOST("societe", "aZ09"); + $idprof2 = GETPOST("idprof2", "aZ09"); + $tva_intra = GETPOST("tva_intra", "aZ09"); + $address = GETPOST("address"); + $zipcode = GETPOST("zipcode", "aZ09"); + $town = GETPOST("town", "aZ09"); + $country_id = GETPOSTINT("country_id"); + $amount = (float) GETPOST("amount", "int"); + $companyId = 0; + $productIdForFreeAmountInvoice = (int) getDolGlobalString('PRODUCT_ID_FOR_FREE_AMOUNT_INVOICE'); + + if (!$email || !isValidEmail($email)) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("ErrorBadEMail", $email)."
\n"; + } + if ($firstname && !preg_match('/^[a-zA-Z0-9À-ÖØ-öø-ÿ \'\-]*$/u', $firstname)) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("firstnameContainsLettersOnly")."
\n"; + } + if ($lastname && !preg_match('/^[a-zA-Z0-9À-ÖØ-öø-ÿ \'\-]*$/u', $lastname)) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("lastnameContainsLettersOnly")."
\n"; + } + if (!$idprof2) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("companyBusinessNumber"))."
\n"; + } + if (!$address) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Address"))."
\n"; + } + if (!$zipcode) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Zip"))."
\n"; + } + if (!$town) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Town"))."
\n"; + } + if (!$country_id) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Country"))."
\n"; + } + if (!$societe) { + $langs->load('errors'); + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Company"))."
\n"; + } else { + // Check if company exists + $company = new Societe($db); + $result = $company->findNearest(0, '', '', '', '', $idprof2, '', '', '', '', $email); + if ($result > 0) { + $companyId = $result; + } elseif ($result < 0) { + $error++; + $errmsg .= $langs->trans("donationErrorMessageContactEmail", $mysoc->email)."
\n"; + } + } + if (!$amount || $amount <= (float) getDolGlobalString("DONATION_INVOICE_MIN_AMOUNT")) { + $error++; + $errmsg .= $langs->trans("ErrorFieldMinimumAmount", (float) getDolGlobalString("DONATION_INVOICE_MIN_AMOUNT"))."
\n"; + } + + // Check Captcha code if is enabled + $sessionkey = 'dol_antispam_value'; + $ok = (array_key_exists($sessionkey, $_SESSION) && (strtolower($_SESSION[$sessionkey]) == strtolower(GETPOST('code')))); + if (!$ok) { + $error++; + $errmsg .= $langs->trans("ErrorBadValueForCode")."
\n"; + $action = ''; + } + + // Start of transaction + $db->begin(); + + // Create invoice for this donation + $invoice = new Facture($db); + + if (!$error && $companyId <= 0) { + // create company + $company = new Societe($db); + + if (!empty($societe)) { + $company->name = $societe; + } else { + $company->name = dolGetFirstLastname($firstname, $lastname); + } + + $company->name_alias = ""; + $company->idprof2 = $idprof2; + $company->address = $address; + $company->zip = $zipcode; + $company->town = $town; + $company->country_id = $country_id; + $company->email = $email; + $company->client = 1; + $company->code_client = 'auto'; + $company->status = 1; // client + $company->tva_intra = $tva_intra; + + $company->ip = getUserRemoteIP(); + + $result = $company->create($user); + if ($result < 0) { + $langs->load('errors'); + $error++; + $errmsg .= implode('
', $company->errors)."
\n"; + } else { + $companyId = $result; + } + } + + if (!$error && $companyId > 0) { + $invoice->socid = $companyId; + $invoice->type = Facture::TYPE_STANDARD; + $invoice->cond_reglement_id = 1; + $invoice->date = dol_now(); + $invoice->module_source = 'donation'; + if (!empty($ws)) { + $invoice->module_source .= '@' . $ws; + } + $invoice->status = Facture::STATUS_DRAFT; + $invoice->ip = getUserRemoteIP(); + + $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 1); + $now = dol_now(); + $minmonthpost = dol_time_plus_duree($now, -1, "m"); + // Calculate nb of post for IP + $nb_post_ip = 0; + if ($nb_post_max > 0) { // Calculate only if there is a limit to check + $sql = "SELECT COUNT(rowid) as nb_invoice"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; + $sql .= " WHERE ip = '".$db->escape($invoice->ip)."'"; + $sql .= " AND datec > '".$db->idate($minmonthpost)."'"; + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) { + $i++; + $obj = $db->fetch_object($resql); + $nb_post_ip = $obj->nb_invoice; + } + } + } + + if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) { + $error++; + $errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress"); + array_push($invoice->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress")); + } + + if (!$error) { + $result = $invoice->create($user); + if ($result <= 0) { + $error++; + $errmsg .= $invoice->error."
\n"; + } + } + + // Issuer Company + $issuerCompany = new Societe($db); + $result = $issuerCompany->fetch($companyId); + if ($result < 0) { + $error++; + $errmsg .= $issuerCompany->error."
\n"; + } + + $tva_tx = get_default_tva($mysoc, $issuerCompany, $productIdForFreeAmountInvoice); + + // Get product for free amount invoice line + $product = new Product($db); + $result = $product->fetch($productIdForFreeAmountInvoice); + if ($result < 0) { + $error++; + $errmsg .= $product->error."
\n"; + } else { + $desc = $product->label; + $productId = $product->id; + // Add line for the invoice + $result = $invoice->addline($desc, $amount, 1, $tva_tx, 0, 0, $productId, 0, "", "", 0, 0, 0, 'TTC', $amount); + if ($result <= 0) { + $error++; + $errmsg .= $invoice->error."
\n"; + } + } + + // Fill array 'array_options' with data from add form + /*$extrafields->fetch_name_optionals_label($donation->table_element); + $ret = $extrafields->setOptionalsFromPost(null, $donation); + if ($ret < 0) { + $error++; + $errmsg .= $donation->error; + }*/ + } + + if (!$error) { + $urlback = getOnlinePaymentUrl(0, 'invoice', (string) $invoice->ref, 0, ''); + if ($ws) { + $urlback .= (strpos($urlback, '?') ? '&' : '?').'ws='.urlencode($ws); + } + if ($paymentmethod) { + $urlback .= (strpos($urlback, '?') ? '&' : '?').'paymentmethod='.urlencode($paymentmethod); + } + $db->commit(); + + header("Location: ".$urlback); + exit; + } else { + $db->rollback(); + $action = "create"; + } +} + +// Action called after a submitted was send and donation created successfully +// If we ask to redirect to the payment page, we never go here because a redirect was done to the payment url. +// backtopage parameter with an url was set on donation submit page, we never go here because a redirect was done to this url. + +if (empty($reshook) && $action == 'added') { // Test on permission not required here + llxHeaderVierge($langs->trans("NewDonationForm")); + + // If we have not been redirected + print '

'; + print '
'; + print $langs->trans("NewDonationbyWeb").'
'; + print '
'; + + llxFooterVierge(); + exit; +} + + +/* + * View + */ + +$form = new Form($db); +$formcompany = new FormCompany($db); +$extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes and labels + + +llxHeaderVierge($langs->trans("NewDonation"), '', 0, 0, array(), array(), $ws); +if (!$ws) { + print '
'; + print load_fiche_titre(img_picto('', '', 'class="pictofixedwidth"').'   '.$langs->trans("NewDonation"), '', '', 0, '', 'center'); + + + print '
'; + print '
'; + + print '
'; + print $langs->trans("NewDonationDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL"))."
\n"; + + print '
'; +} + +dol_htmloutput_errors($errmsg); +dol_htmloutput_events(); + +// Print form +print '
'."\n"; +print ''; +print ''; +print ''; + +if (!$action || $action == 'create') { + print ''; + print ''; + print ''; + print '
'; + + $messagemandatory = ''.$langs->trans("FieldsWithAreMandatory", '*').''; + //print '
'.$langs->trans("FieldsWithAreMandatory", '*').'
'; + //print $langs->trans("FieldsWithIsForPublic",'**').'
'; + + print dol_get_fiche_head(); + + print ''."\n"; + + // Add a specific style or table head for the project row + if ((isModEnabled('project') || isModEnabled('eventorganization')) && !empty($projectTitle)) { + print ''; + print ''; + print ''; + print ''; + } + + // EMail + print ''."\n"; + + // Company + print ''."\n"; + + // Firstname + print ''."\n"; + + // Lastname + print ''."\n"; + + // Address + print ''."\n"; + + // Zip / Town + print ''; + + // Country + print ''; + + //Idprof2 (siret...) + print ''."\n"; + + //Tva_intra + print ''."\n"; + + print ''; + + // Amount + $amount = (float) (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : ''); + + // - If a min is set, we take it into account + $amount = max(0, (float) $amount, (float) getDolGlobalInt("DONATION_INVOICE_MIN_AMOUNT")); + + // Clean the amount + $amount = price2num($amount); + $showedamount = $amount > 0 ? $amount : 5; + print ''; + + // Display Captcha code if is enabled + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; + print ''; + + + + print "
' . $langs->trans("project") . '' . dol_escape_htmltag($projectTitle) . '
'.$langs->trans("Email").''; + print '
'.$langs->trans("Company").''; + print img_picto('', 'company', 'class="pictofixedwidth paddingright"'); + print '
'.$langs->trans("Firstname").'
'.$langs->trans("Lastname").'
'.$langs->trans("Address").''."\n"; + print '
'.$langs->trans('Zip').' / '.$langs->trans('Town').''; + print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 1, '', 'width75'); + print ' / '; + print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1); + print '
'.$langs->trans('Country').''; + print img_picto('', 'country', 'class="pictofixedwidth paddingright"'); + $country_id = GETPOSTINT('country_id'); + if (!$country_id && !empty($conf->geoipmaxmind->enabled)) { + $country_code = dol_user_country(); + //print $country_code; + if ($country_code) { + $new_country_id = getCountry($country_code, '3', $db, $langs); + //print 'xxx'.$country_code.' - '.$new_country_id; + if ($new_country_id) { + $country_id = $new_country_id; + } + } + } + $country_code = getCountry($country_id, '2', $db, $langs); + print $form->select_country($country_id, 'country_id'); + print '
'.$langs->trans("companyBusinessNumber").'
'.$langs->trans("companyTIN").'

'.$langs->trans("donationAmount"); + print ''; + + print ''; + print ' '.$langs->trans("Currency".$conf->currency).' - '; + print $langs->trans("AnyAmountForDonation"); + print ''; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''.img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"').''; + print ''; + print '
\n"; + + print dol_get_fiche_end(); + + // Save / Submit + print '
'; + print ''; + if (!empty($backtopage)) { + print '     '; + } + print '
'; + + + print "
\n"; + print "
"; + print '
'; +} + +//htmlPrintOnlineFooter($mysoc, $langs); +llxFooterVierge(); + +$db->close(); diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 8de68d0ca9e..904a5314b84 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1072,6 +1072,19 @@ if ($ispaymentok) { } $paiement->ext_payment_site = $service; + // Validate invoice if not already validated (this can happen for automatically generated invoices with a free amount) + if (!$error && $object->status == Facture::STATUS_DRAFT) { + $result = $object->validate($user); + if ($result < 0) { + $postactionmessages[] = $object->error; + $ispostactionok = -1; + $error++; + } else { + $postactionmessages[] = 'Invoice validated'; + $ispostactionok = 1; + } + } + if (!$error) { $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents if ($paiement_id < 0) { diff --git a/htdocs/workstation/class/workstation.class.php b/htdocs/workstation/class/workstation.class.php index ebc0355121d..41427e04313 100644 --- a/htdocs/workstation/class/workstation.class.php +++ b/htdocs/workstation/class/workstation.class.php @@ -193,7 +193,7 @@ class Workstation extends CommonObject if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) { $this->fields['rowid']['visible'] = 0; } - if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) { + if (!isModEnabled('multicompany') && isset($this->fields['entity'])) { $this->fields['entity']['enabled'] = 0; }