2005-11-11 22:36:56 +00:00
< ? php
2012-07-11 08:14:56 +00:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 - 2006 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 12:43:12 +00:00
* Copyright ( C ) 2012 Regis Houssin < regis . houssin @ inodbox . com >
2012-12-29 00:13:31 +00:00
* Copyright ( C ) 2012 Marcos García < marcosgdf @ gmail . com >
2020-02-17 06:43:24 +00:00
* Copyright ( C ) 2014 - 2020 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2015-11-22 20:31:05 +00:00
* Copyright ( C ) 2015 Benoit Bruchard < benoitb21 @ gmail . com >
2026-02-01 17:05:15 +00:00
* Copyright ( C ) 2024 - 2026 MDW < mdeweerd @ users . noreply . github . com >
2025-11-12 14:32:29 +00:00
* Copyright ( C ) 2025 Frédéric France < frederic . france @ free . fr >
2005-11-11 22:36:56 +00:00
*
* 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
2013-01-16 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2005-11-11 22:36:56 +00:00
* ( 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
2019-09-23 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2005-11-11 22:36:56 +00:00
*/
/**
2015-03-22 14:27:05 +00:00
* \file htdocs / core / modules / dons / html_cerfafr . modules . php
2014-06-15 20:18:19 +00:00
* \ingroup don
* \brief Form of donation
2011-08-27 16:15:06 +00:00
*/
2015-03-22 07:20:19 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php' ;
2015-03-25 21:37:14 +00:00
require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php' ;
2026-08-05 09:09:01 +00:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2012-08-22 21:11:24 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2005-11-11 22:36:56 +00:00
/**
2012-02-16 17:39:22 +00:00
* Class to generate document for subscriptions
*/
2005-11-11 22:36:56 +00:00
class html_cerfafr extends ModeleDon
{
2017-10-07 11:09:31 +00:00
/**
* Constructor
*
2024-01-13 14:50:02 +00:00
* @ param DoliDB $db Database handler
2017-10-07 11:09:31 +00:00
*/
2019-03-01 18:24:06 +00:00
public function __construct ( $db )
2017-10-07 11:09:31 +00:00
{
2026-01-24 15:13:00 +00:00
global $langs ;
2005-11-11 22:36:56 +00:00
2017-10-07 11:09:31 +00:00
$this -> db = $db ;
$this -> name = " cerfafr " ;
2020-02-17 06:43:24 +00:00
$this -> description = $langs -> trans ( 'DonationsReceiptModel' ) . ' - fr_FR - Cerfa 11580*04' ;
2006-08-20 23:04:24 +00:00
2017-10-07 11:09:31 +00:00
// Dimension page for size A4
$this -> type = 'html' ;
}
2005-11-11 22:36:56 +00:00
2012-02-16 17:39:22 +00:00
/**
* Return if a module can be used or not
2012-07-11 08:14:56 +00:00
*
2012-02-16 17:39:22 +00:00
* @ return boolean true if module can be used
*/
2019-03-01 18:24:06 +00:00
public function isEnabled ()
2008-10-29 21:26:59 +00:00
{
return true ;
}
2009-02-10 22:07:31 +00:00
2020-10-31 13:32:18 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 11:09:31 +00:00
/**
* Write the object to document file to disk
*
2024-11-13 22:58:32 +00:00
* @ param Don $don Donation object
* @ param Translate $outputlangs Lang object for output language
2017-03-19 14:37:07 +00:00
* @ param string $currency Currency code
2024-11-13 22:58:32 +00:00
* @ return int <- 1 , 1 > > 0 if OK , < 0 if KO
2017-10-07 11:09:31 +00:00
*/
2019-03-01 18:24:06 +00:00
public function write_file ( $don , $outputlangs , $currency = '' )
2017-10-07 11:09:31 +00:00
{
2020-10-31 13:32:18 +00:00
// phpcs:enable
2020-02-21 16:53:37 +00:00
global $user , $conf , $langs , $mysoc ;
2008-10-29 19:49:10 +00:00
2020-02-21 16:53:37 +00:00
$now = dol_now ();
$id = ( ! is_object ( $don ) ? $don : '' );
2009-02-10 22:07:31 +00:00
2021-02-23 21:03:23 +00:00
if ( ! is_object ( $outputlangs )) {
$outputlangs = $langs ;
}
2009-02-10 22:07:31 +00:00
2019-09-20 05:02:14 +00:00
// Load traductions files required by page
2018-09-18 09:09:56 +00:00
$outputlangs -> loadLangs ( array ( " main " , " dict " , " companies " , " bills " , " products " , " donations " ));
2009-04-29 18:02:50 +00:00
2017-03-19 14:37:07 +00:00
$currency = ! empty ( $currency ) ? $currency : $conf -> currency ;
2018-03-02 11:32:49 +00:00
2021-02-23 21:03:23 +00:00
if ( ! empty ( $conf -> don -> dir_output )) {
2014-06-15 20:18:19 +00:00
// Definition of the object don (for upward compatibility)
2021-02-23 21:03:23 +00:00
if ( ! is_object ( $don )) {
2017-10-07 11:09:31 +00:00
$don = new Don ( $this -> db );
2020-02-21 16:53:37 +00:00
$ret = $don -> fetch ( $id );
$id = $don -> id ;
2006-08-20 23:04:24 +00:00
}
2014-06-15 20:18:19 +00:00
// Definition of $dir and $file
2021-02-23 21:03:23 +00:00
if ( ! empty ( $don -> specimen )) {
2006-08-20 23:04:24 +00:00
$dir = $conf -> don -> dir_output ;
2020-02-21 16:53:37 +00:00
$file = $dir . " /SPECIMEN.html " ;
2020-05-21 13:05:19 +00:00
} else {
2026-01-24 15:13:00 +00:00
$donref = dol_sanitizeFileName (( string ) $don -> ref );
2020-02-21 16:53:37 +00:00
$dir = $conf -> don -> dir_output . " / " . $donref ;
$file = $dir . " / " . $donref . " .html " ;
2006-08-20 23:04:24 +00:00
}
2009-02-10 22:07:31 +00:00
2021-02-23 21:03:23 +00:00
if ( ! file_exists ( $dir )) {
if ( dol_mkdir ( $dir ) < 0 ) {
2020-02-21 16:53:37 +00:00
$this -> error = $langs -> trans ( " ErrorCanNotCreateDir " , $dir );
2017-10-07 11:09:31 +00:00
return - 1 ;
}
}
2009-02-10 22:07:31 +00:00
2021-02-23 21:03:23 +00:00
if ( file_exists ( $dir )) {
2017-10-07 11:09:31 +00:00
$formclass = new Form ( $this -> db );
2012-12-29 00:13:31 +00:00
2017-10-07 11:09:31 +00:00
// This is not the proper way to do it but $formclass->form_modes_reglement
// prints the translation instead of returning it
2022-11-10 11:15:06 +00:00
$formclass -> load_cache_types_paiements ();
2026-08-05 09:09:01 +00:00
// Don::fetch() stores the payment mode into mode_reglement_id. The modepaymentid property is only
// set by the create/update forms, so it is always empty when the document is built from a fetched
// donation and no payment mode checkbox was ever ticked on the receipt.
$modepaymentid = ! empty ( $don -> mode_reglement_id ) ? $don -> mode_reglement_id : $don -> modepaymentid ;
if ( $modepaymentid ) {
2026-08-14 13:35:17 +00:00
$paymentmode = ! empty ( $formclass -> cache_types_paiements [( int ) $modepaymentid ][ 'label' ]) ? $formclass -> cache_types_paiements [ $modepaymentid ][ 'label' ] : '' ;
2021-02-23 21:03:23 +00:00
} else {
$paymentmode = '' ;
}
2026-08-14 13:35:17 +00:00
$modepaymentcode = ! empty ( $formclass -> cache_types_paiements [( int ) $modepaymentid ][ 'code' ]) ? $formclass -> cache_types_paiements [( int ) $modepaymentid ][ 'code' ] : " " ;
2022-11-10 11:15:06 +00:00
if ( $modepaymentcode == 'CHQ' ) {
2017-10-05 23:46:48 +00:00
$ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox" disabled="true" checked="checked"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>' ;
2022-11-10 11:15:06 +00:00
} elseif ( $modepaymentcode == 'LIQ' ) {
2017-10-05 23:46:48 +00:00
$ModePaiement = '<td width="25%"><input type="checkbox" checked="checked"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>' ;
2022-11-10 11:15:06 +00:00
} elseif ( $modepaymentcode == 'VIR' || $modepaymentcode == 'PRE' || $modepaymentcode == 'CB' ) {
2017-10-05 23:46:48 +00:00
$ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox" checked="checked"> Virement, prélèvement, carte bancaire</td>' ;
2020-05-21 13:05:19 +00:00
} else {
2017-10-05 23:46:48 +00:00
$ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>' ;
2015-11-22 20:31:05 +00:00
}
2018-03-02 11:32:49 +00:00
2016-01-10 06:35:00 +00:00
/*
2015-11-22 20:31:05 +00:00
if ( empty ( $don -> societe ))
{
2020-02-17 06:43:24 +00:00
$CodeDon = '<td width="33%"><input type="checkbox" disabled="true" checked="checked" > 200 du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 238 bis du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 978 du CGI</td>' ;
2015-11-22 20:31:05 +00:00
}
else
{
2020-02-17 06:43:24 +00:00
$CodeDon = '<td width="33%"><input type="checkbox" disabled="true" > 200 du CGI</td><td width="33%"><input type="checkbox" disabled="true" checked="checked" > 238 bis du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 978 du CGI</td>' ;
2015-11-22 20:31:05 +00:00
}
2016-01-10 06:35:00 +00:00
*/
2026-08-05 09:09:01 +00:00
// Donator identity.
// When option DONATION_USE_THIRDPARTIES is on, the donation form does not show the name/address
// inputs at all, so llx_don only holds fk_soc and every donator field stays empty. The receipt
// would then be issued without the mandatory identity of the donator, so fall back on the linked
// third party for each field left empty.
$donatorsociete = ( string ) $don -> societe ;
$donatorlastname = ( string ) $don -> lastname ;
$donatorfirstname = ( string ) $don -> firstname ;
$donatoraddress = ( string ) $don -> address ;
$donatorzip = ( string ) $don -> zip ;
$donatortown = ( string ) $don -> town ;
if ( ! empty ( $don -> socid ) && $don -> socid > 0 ) {
$donatorthirdparty = new Societe ( $this -> db );
if ( $donatorthirdparty -> fetch ( $don -> socid ) > 0 ) {
if ( dol_strlen ( trim ( $donatorsociete . $donatorlastname . $donatorfirstname )) == 0 ) {
// A third party holds a single name field, even for a private individual, so it goes
2026-08-13 15:48:25 +00:00
// to the "Name" cell of the form and the "Firstname" cell is left empty.
2026-08-05 09:09:01 +00:00
$donatorsociete = ( string ) $donatorthirdparty -> name ;
}
if ( dol_strlen ( trim ( $donatoraddress )) == 0 ) {
$donatoraddress = ( string ) $donatorthirdparty -> address ;
}
if ( dol_strlen ( trim ( $donatorzip )) == 0 ) {
$donatorzip = ( string ) $donatorthirdparty -> zip ;
}
if ( dol_strlen ( trim ( $donatortown )) == 0 ) {
$donatortown = ( string ) $donatorthirdparty -> town ;
}
} else {
dol_syslog ( " html_cerfafr::write_file Failed to load thirdparty " . $don -> socid . " linked to donation " . $don -> id . " , donator block will remain empty - " . $donatorthirdparty -> error , LOG_ERR );
}
}
if ( dol_strlen ( trim ( $donatorsociete . $donatorlastname . $donatorfirstname )) == 0 ) {
dol_syslog ( " html_cerfafr::write_file No name found for the donator of donation " . $don -> id . " , the receipt will not be compliant " , LOG_WARNING );
}
2018-03-02 11:32:49 +00:00
2017-10-07 11:09:31 +00:00
// Define contents
2020-02-21 16:53:37 +00:00
$donmodel = DOL_DOCUMENT_ROOT . " /core/modules/dons/html_cerfafr.html " ;
2026-01-24 16:40:22 +00:00
$form = file_get_contents ( $donmodel );
2024-03-19 18:14:43 +00:00
$form = str_replace ( '__REF__' , ( string ) $don -> id , $form );
2019-01-27 10:55:16 +00:00
$form = str_replace ( '__DATE__' , dol_print_date ( $don -> date , 'day' , false , $outputlangs ), $form );
2017-10-07 11:09:31 +00:00
//$form = str_replace('__IP__',$user->ip,$form); // TODO $user->ip not exist
2018-03-02 11:32:49 +00:00
$form = str_replace ( '__AMOUNT__' , price ( $don -> amount ), $form );
2019-01-27 10:55:16 +00:00
$form = str_replace ( '__AMOUNTLETTERS__' , $this -> amountToLetters ( $don -> amount ), $form );
$form = str_replace ( '__CURRENCY__' , $outputlangs -> transnoentitiesnoconv ( " Currency " . $currency ), $form );
$form = str_replace ( '__CURRENCYCODE__' , $conf -> currency , $form );
2026-01-29 08:56:10 +00:00
$form = str_replace ( '__MAIN_INFO_SOCIETE_NOM__' , ( string ) $mysoc -> name , $form );
2026-01-24 16:40:22 +00:00
$form = str_replace ( '__MAIN_INFO_SOCIETE_ADDRESS__' , ( string ) $mysoc -> address , $form );
$form = str_replace ( '__MAIN_INFO_SOCIETE_ZIP__' , ( string ) $mysoc -> zip , $form );
$form = str_replace ( '__MAIN_INFO_SOCIETE_TOWN__' , ( string ) $mysoc -> town , $form );
2026-08-13 15:48:25 +00:00
2026-01-29 08:56:10 +00:00
$form = str_replace ( '__MAIN_INFO_SOCIETE_OBJECT__' , ( string ) $mysoc -> socialobject , $form );
2026-08-12 20:43:32 +00:00
2026-08-05 09:09:01 +00:00
$form = str_replace ( '__DONATOR_FIRSTNAME__' , dol_escape_htmltag ( $donatorfirstname ), $form );
// The template concatenates __DONATOR_SOCIETE__ and __DONATOR_LASTNAME__ with no separator,
// so add a line break when both are filled in.
$donatorlastnameprefix = ( dol_strlen ( trim ( $donatorsociete )) > 0 && dol_strlen ( trim ( $donatorlastname )) > 0 ) ? '<br>' : '' ;
$form = str_replace ( '__DONATOR_LASTNAME__' , $donatorlastnameprefix . dol_escape_htmltag ( $donatorlastname ), $form );
$form = str_replace ( '__DONATOR_SOCIETE__' , dol_escape_htmltag ( $donatorsociete ), $form );
2026-08-13 15:48:25 +00:00
2024-03-19 18:14:43 +00:00
$form = str_replace ( '__DONATOR_STATUT__' , ( string ) $don -> statut , $form );
2026-08-05 09:09:01 +00:00
$form = str_replace ( '__DONATOR_ADDRESS__' , dol_nl2br ( dol_escape_htmltag ( $donatoraddress , 0 , 1 )), $form );
$form = str_replace ( '__DONATOR_ZIP__' , dol_escape_htmltag ( $donatorzip ), $form );
$form = str_replace ( '__DONATOR_TOWN__' , dol_escape_htmltag ( $donatortown ), $form );
2026-08-12 20:43:32 +00:00
2025-11-24 14:05:55 +00:00
$form = str_replace ( '__PAYMENTMODE_LIB__ ' , ( string ) $paymentmode , $form );
2019-01-27 10:55:16 +00:00
$form = str_replace ( '__NOW__' , dol_print_date ( $now , 'day' , false , $outputlangs ), $form );
2026-01-24 16:40:22 +00:00
$form = str_replace ( '__DONATION_PAYMENT_MODE__' , $ModePaiement , $form );
$form = str_replace ( '__DONATION_MESSAGE__' , getDolGlobalString ( 'DONATION_MESSAGE' ), $form );
// Replace with a generic replacement feature '__(XXX)__' must become $outputlangs->trans('XXX')
$form = make_substitutions ( $form , array (), $outputlangs );
2018-03-02 11:32:49 +00:00
2020-02-21 16:53:37 +00:00
$frencharticle = '' ;
2021-02-23 21:03:23 +00:00
if ( preg_match ( '/fr/i' , $outputlangs -> defaultlang )) {
$frencharticle = '<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>' ;
}
2019-01-27 10:55:16 +00:00
$form = str_replace ( '__FrenchArticle__' , $frencharticle , $form );
2015-05-18 20:25:51 +00:00
2020-02-21 16:53:37 +00:00
$frencheligibility = '' ;
2021-02-23 21:03:23 +00:00
if ( preg_match ( '/fr/i' , $outputlangs -> defaultlang )) {
$frencheligibility = 'Le bénéficiaire certifie sur l\'honneur que les dons et versements qu\'il reçoit ouvrent droit à la réduction d\'impôt prévue à l\'article :' ;
}
2019-01-27 10:55:16 +00:00
$form = str_replace ( '__FrenchEligibility__' , $frencheligibility , $form );
2015-05-18 20:25:51 +00:00
2020-02-21 16:53:37 +00:00
$art200 = '' ;
2020-10-01 07:34:10 +00:00
if ( $mysoc -> country_code == 'FR' ) {
2023-11-27 11:24:18 +00:00
if ( getDolGlobalInt ( 'DONATION_ART200' ) >= 1 ) {
2020-02-21 16:53:37 +00:00
$art200 = '<input type="checkbox" disabled="true" checked="checked" >200 du CGI' ;
2020-05-21 13:05:19 +00:00
} else {
2020-02-21 16:53:37 +00:00
$art200 = '<input type="checkbox" disabled="true">200 du CGI' ;
2014-06-15 20:18:19 +00:00
}
}
2019-01-27 10:55:16 +00:00
$form = str_replace ( '__ARTICLE200__' , $art200 , $form );
2014-06-15 20:18:19 +00:00
2020-02-21 16:53:37 +00:00
$art238 = '' ;
2020-10-01 07:34:10 +00:00
if ( $mysoc -> country_code == 'FR' ) {
2023-11-27 11:24:18 +00:00
if ( getDolGlobalInt ( 'DONATION_ART238' ) >= 1 ) {
2020-02-21 16:53:37 +00:00
$art238 = '<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI' ;
2020-05-21 13:05:19 +00:00
} else {
2020-02-21 16:53:37 +00:00
$art238 = '<input type="checkbox" disabled="true">238 bis du CGI' ;
2014-06-15 20:18:19 +00:00
}
}
2019-01-27 10:55:16 +00:00
$form = str_replace ( '__ARTICLE238__' , $art238 , $form );
2015-05-18 20:25:51 +00:00
2020-02-21 16:53:37 +00:00
$art978 = '' ;
2020-10-01 07:34:10 +00:00
if ( $mysoc -> country_code == 'FR' ) {
2023-11-27 11:24:18 +00:00
if ( getDolGlobalInt ( 'DONATION_ART978' ) >= 1 ) {
2020-02-21 16:53:37 +00:00
$art978 = '<input type="checkbox" disabled="true" checked="checked" >978 du CGI' ;
2020-05-21 13:05:19 +00:00
} else {
2020-02-21 16:53:37 +00:00
$art978 = '<input type="checkbox" disabled="true">978 du CGI' ;
2014-06-15 20:18:19 +00:00
}
}
2020-02-17 06:43:24 +00:00
$form = str_replace ( '__ARTICLE978__' , $art978 , $form );
2015-05-18 20:25:51 +00:00
2014-06-15 20:18:19 +00:00
// Save file on disk
2017-10-07 11:09:31 +00:00
dol_syslog ( " html_cerfafr::write_file $file " );
2020-02-21 16:53:37 +00:00
$handle = fopen ( $file , " w " );
2019-01-27 10:55:16 +00:00
fwrite ( $handle , $form );
2017-10-07 11:09:31 +00:00
fclose ( $handle );
2023-02-17 18:30:50 +00:00
dolChmod ( $file );
2009-02-10 22:07:31 +00:00
2024-03-09 15:32:02 +00:00
$this -> result = array ( 'fullpath' => $file );
2018-03-02 11:32:49 +00:00
2017-10-07 11:09:31 +00:00
return 1 ;
2020-05-21 13:05:19 +00:00
} else {
2020-02-21 16:53:37 +00:00
$this -> error = $langs -> trans ( " ErrorCanNotCreateDir " , $dir );
2017-10-07 11:09:31 +00:00
return 0 ;
}
2020-05-21 13:05:19 +00:00
} else {
2020-02-21 16:53:37 +00:00
$this -> error = $langs -> trans ( " ErrorConstantNotDefined " , " DON_OUTPUTDIR " );
2017-10-07 11:09:31 +00:00
return 0 ;
2006-08-20 23:04:24 +00:00
}
2017-10-07 11:09:31 +00:00
}
2005-11-11 22:36:56 +00:00
2018-09-02 14:18:08 +00:00
/**
* numbers to letters
*
2026-02-01 17:05:15 +00:00
* @ param mixed $amount amount
2025-11-12 14:32:29 +00:00
* @ param string $devise1 devise 1 ex : euro
* @ param string $devise2 devise 2 ex : centimes
2018-09-02 14:18:08 +00:00
* @ return string amount in letters
*/
2026-02-01 17:05:15 +00:00
private function amountToLetters ( $amount , $devise1 = '' , $devise2 = '' )
2018-09-02 14:18:08 +00:00
{
$unite = array ();
$dix = array ();
$cent = array ();
2021-02-23 21:03:23 +00:00
if ( empty ( $devise1 )) {
$dev1 = 'euros' ;
} else {
$dev1 = $devise1 ;
}
if ( empty ( $devise2 )) {
$dev2 = 'centimes' ;
} else {
$dev2 = $devise2 ;
}
2026-02-01 17:05:15 +00:00
$integerAmount = intval ( $amount );
$fractionalAmount = intval ( round ( $amount - intval ( $amount ), 2 ) * 100 );
$dix_c = intval ( $fractionalAmount % 100 / 10 );
$cent_c = intval ( $fractionalAmount % 1000 / 100 );
$unite [ 1 ] = $integerAmount % 10 ;
$dix [ 1 ] = intval ( $integerAmount % 100 / 10 );
$cent [ 1 ] = intval ( $integerAmount % 1000 / 100 );
$unite [ 2 ] = intval ( $integerAmount % 10000 / 1000 );
$dix [ 2 ] = intval ( $integerAmount % 100000 / 10000 );
$cent [ 2 ] = intval ( $integerAmount % 1000000 / 100000 );
$unite [ 3 ] = intval ( $integerAmount % 10000000 / 1000000 );
$dix [ 3 ] = intval ( $integerAmount % 100000000 / 10000000 );
$cent [ 3 ] = intval ( $integerAmount % 1000000000 / 100000000 );
2020-02-21 16:53:37 +00:00
$chif = array ( '' , 'un' , 'deux' , 'trois' , 'quatre' , 'cinq' , 'six' , 'sept' , 'huit' , 'neuf' , 'dix' , 'onze' , 'douze' , 'treize' , 'quatorze' , 'quinze' , 'seize' , 'dix sept' , 'dix huit' , 'dix neuf' );
$secon_c = '' ;
$trio_c = '' ;
2024-03-09 15:32:02 +00:00
$prim = array ();
$secon = array ();
$trio = array ();
2024-06-08 12:53:46 +00:00
// @phpstan-ignore-next-line
2024-03-11 13:01:28 +00:00
' @ phan - var string [] $prim
@ phan - var string [] $secon
@ phan - var string [] $trio
2024-06-08 12:53:46 +00:00
' ;
2020-02-21 16:53:37 +00:00
for ( $i = 1 ; $i <= 3 ; $i ++ ) {
$prim [ $i ] = '' ;
$secon [ $i ] = '' ;
$trio [ $i ] = '' ;
if ( $dix [ $i ] == 0 ) {
$secon [ $i ] = '' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 1 ) {
2020-02-21 16:53:37 +00:00
$secon [ $i ] = '' ;
$prim [ $i ] = $chif [( $unite [ $i ] + 10 )];
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 2 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'vingt et' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2019-10-27 16:01:23 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'vingt' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2018-09-02 14:18:08 +00:00
}
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 3 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'trente et' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2019-10-27 16:01:23 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'trente' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2018-09-02 14:18:08 +00:00
}
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 4 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'quarante et' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2020-05-21 13:05:19 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'quarante' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2018-09-02 14:18:08 +00:00
}
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 5 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'cinquante et' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2020-05-21 13:05:19 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'cinquante' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2018-09-02 14:18:08 +00:00
}
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 6 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'soixante et' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2020-05-21 13:05:19 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'soixante' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2018-09-02 14:18:08 +00:00
}
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 7 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'soixante et' ;
$prim [ $i ] = $chif [ $unite [ $i ] + 10 ];
2020-05-21 13:05:19 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'soixante' ;
$prim [ $i ] = $chif [ $unite [ $i ] + 10 ];
2018-09-02 14:18:08 +00:00
}
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 8 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'quatre-vingts et' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2020-05-21 13:05:19 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'quatre-vingt' ;
$prim [ $i ] = $chif [ $unite [ $i ]];
2018-09-02 14:18:08 +00:00
}
2020-05-21 13:05:19 +00:00
} elseif ( $dix [ $i ] == 9 ) {
2020-02-21 16:53:37 +00:00
if ( $unite [ $i ] == 1 ) {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'quatre-vingts et' ;
$prim [ $i ] = $chif [ $unite [ $i ] + 10 ];
2020-05-21 13:05:19 +00:00
} else {
2020-10-31 13:32:18 +00:00
$secon [ $i ] = 'quatre-vingts' ;
$prim [ $i ] = $chif [ $unite [ $i ] + 10 ];
2018-09-02 14:18:08 +00:00
}
2017-10-07 11:09:31 +00:00
}
2021-02-23 21:03:23 +00:00
if ( $cent [ $i ] == 1 ) {
$trio [ $i ] = 'cent' ;
} elseif ( $cent [ $i ] != 0 || $cent [ $i ] != '' ) {
$trio [ $i ] = $chif [ $cent [ $i ]] . ' cents' ;
}
2017-10-07 11:09:31 +00:00
}
2018-03-02 11:32:49 +00:00
2020-02-21 16:53:37 +00:00
$chif2 = array ( '' , 'dix' , 'vingt' , 'trente' , 'quarante' , 'cinquante' , 'soixante' , 'soixante-dix' , 'quatre-vingts' , 'quatre-vingts dix' );
$secon_c = $chif2 [ $dix_c ];
2021-02-23 21:03:23 +00:00
if ( $cent_c == 1 ) {
$trio_c = 'cent' ;
} elseif ( $cent_c != 0 || $cent_c != '' ) {
$trio_c = $chif [ $cent_c ] . ' cents' ;
}
2018-03-02 11:32:49 +00:00
2021-02-23 21:03:23 +00:00
if (( $cent [ 3 ] == 0 || $cent [ 3 ] == '' ) && ( $dix [ 3 ] == 0 || $dix [ 3 ] == '' ) && ( $unite [ 3 ] == 1 )) {
2020-02-21 16:53:37 +00:00
$somme = $trio [ 3 ] . ' ' . $secon [ 3 ] . ' ' . $prim [ 3 ] . ' million ' ;
2021-02-23 21:03:23 +00:00
} elseif (( $cent [ 3 ] != 0 && $cent [ 3 ] != '' ) || ( $dix [ 3 ] != 0 && $dix [ 3 ] != '' ) || ( $unite [ 3 ] != 0 && $unite [ 3 ] != '' )) {
2020-02-21 16:53:37 +00:00
$somme = $trio [ 3 ] . ' ' . $secon [ 3 ] . ' ' . $prim [ 3 ] . ' millions ' ;
2021-02-23 21:03:23 +00:00
} else {
$somme = $trio [ 3 ] . ' ' . $secon [ 3 ] . ' ' . $prim [ 3 ];
}
2018-09-02 14:18:08 +00:00
2021-02-23 21:03:23 +00:00
if (( $cent [ 2 ] == 0 || $cent [ 2 ] == '' ) && ( $dix [ 2 ] == 0 || $dix [ 2 ] == '' ) && ( $unite [ 2 ] == 1 )) {
2024-08-07 00:53:45 +00:00
$somme .= ' mille ' ;
2021-02-23 21:03:23 +00:00
} elseif (( $cent [ 2 ] != 0 && $cent [ 2 ] != '' ) || ( $dix [ 2 ] != 0 && $dix [ 2 ] != '' ) || ( $unite [ 2 ] != 0 && $unite [ 2 ] != '' )) {
2024-08-07 00:53:45 +00:00
$somme .= $trio [ 2 ] . ' ' . $secon [ 2 ] . ' ' . $prim [ 2 ] . ' milles ' ;
2021-02-23 21:03:23 +00:00
} else {
2024-08-07 00:53:45 +00:00
$somme .= $trio [ 2 ] . ' ' . $secon [ 2 ] . ' ' . $prim [ 2 ];
2021-02-23 21:03:23 +00:00
}
2018-03-02 11:32:49 +00:00
2024-08-07 00:53:45 +00:00
$somme .= $trio [ 1 ] . ' ' . $secon [ 1 ] . ' ' . $prim [ 1 ];
2018-03-02 11:32:49 +00:00
2024-08-07 00:53:45 +00:00
$somme .= ' ' . $dev1 . ' ' ;
2018-03-02 11:32:49 +00:00
2021-02-23 21:03:23 +00:00
if (( $cent_c == '0' || $cent_c == '' ) && ( $dix_c == '0' || $dix_c == '' )) {
2020-02-21 16:53:37 +00:00
return $somme . ' et zéro ' . $dev2 ;
2021-02-23 21:03:23 +00:00
} else {
return $somme . $trio_c . ' ' . $secon_c . ' ' . $dev2 ;
}
2018-09-02 14:18:08 +00:00
}
2015-11-22 20:31:05 +00:00
}