dolibarr 24.0.0-beta
chequereceipts.php
1<?php
2/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
5 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
36
46// Load translation files required by the page
47$langs->loadLangs(array("admin", "companies", "bills", "other", "banks"));
48
49if (!$user->admin) {
51}
52
53$action = GETPOST('action', 'aZ09');
54$value = GETPOST('value', 'alpha');
55
56
57if (!getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
58 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipts_mint.php';
59}
60
61
62
63/*
64 * Actions
65 */
66$error = 0;
67
68if ($action == 'updateMask') {
69 $maskconstchequereceipts = GETPOST('maskconstchequereceipts', 'aZ09');
70 $maskchequereceipts = GETPOST('maskchequereceipts', 'alpha');
71
72 $res = 0;
73
74 if ($maskconstchequereceipts && preg_match('/_MASK$/', $maskconstchequereceipts)) {
75 $res = dolibarr_set_const($db, $maskconstchequereceipts, $maskchequereceipts, 'chaine', 0, '', $conf->entity);
76 }
77
78 if (!($res > 0)) {
79 $error++;
80 }
81
82 if (!$error) {
83 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
84 } else {
85 setEventMessages($langs->trans("Error"), null, 'errors');
86 }
87}
88
89if ($action == 'setmod') {
90 dolibarr_set_const($db, "CHEQUERECEIPTS_ADDON", $value, 'chaine', 0, '', $conf->entity);
91}
92
93if ($action == 'set_BANK_CHEQUERECEIPT_FREE_TEXT') {
94 $freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
95
96 $res = dolibarr_set_const($db, "BANK_CHEQUERECEIPT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
97
98 if (!($res > 0)) {
99 $error++;
100 }
101
102 if (!$error) {
103 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
104 } else {
105 setEventMessages($langs->trans("Error"), null, 'errors');
106 }
107}
108
109/*
110 * View
111 */
112
113$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
114llxHeader("", $langs->trans("BankSetupModule"), '', '', 0, 0, '', '', '', 'mod-admin page-chequereceipts');
115
116$form = new Form($db);
117
118$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
119
120print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup');
121
122$head = bank_admin_prepare_head(null);
123print dol_get_fiche_head($head, 'checkreceipts', $langs->trans("BankSetupModule"), -1, 'account');
124
125/*
126 * Numbering module
127 */
128
129print load_fiche_titre($langs->trans("ChequeReceiptsNumberingModule"), '', '');
130
131print '<div class="div-table-responsive-no-min">';
132print '<table class="noborder centpercent">';
133print '<tr class="liste_titre">';
134print '<td>'.$langs->trans("Name").'</td>';
135print '<td>'.$langs->trans("Description").'</td>';
136print '<td class="nowrap">'.$langs->trans("Example").'</td>';
137print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
138print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
139print '</tr>'."\n";
140
141clearstatcache();
142
143foreach ($dirmodels as $reldir) {
144 $dir = dol_buildpath($reldir."core/modules/cheque/");
145 if (is_dir($dir)) {
146 $handle = opendir($dir);
147 if (is_resource($handle)) {
148 while (($file = readdir($handle)) !== false) {
149 if (!is_dir($dir.$file) || (substr($file, 0, 1) != '.' && substr($file, 0, 3) != 'CVS')) {
150 $filebis = $file;
151 $name = substr($file, 4, dol_strlen($file) - 16);
152 $classname = preg_replace('/\.php$/', '', $file);
153 // For compatibility
154 if (!is_file($dir.$filebis)) {
155 $filebis = $file."/".$file.".modules.php";
156 $classname = "mod_chequereceipt_".$file;
157 }
158 // Check if there is a filter on country
159 preg_match('/\-(.*)_(.*)$/', $classname, $reg);
160 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) {
161 continue;
162 }
163
164 $classname = preg_replace('/\-.*$/', '', $classname);
165 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') {
166 // Charging the numbering class
167 require_once $dir.$filebis;
168
169 $module = new $classname($db);
170 '@phan-var-force ModeleNumRefChequeReceipts $module';
171
172 // Show modules according to features level
173 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
174 continue;
175 }
176 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
177 continue;
178 }
179
180 if ($module->isEnabled()) {
181 print '<tr class="oddeven"><td width="100">';
182 print(empty($module->name) ? $name : $module->name);
183 print "</td><td>\n";
184
185 print $module->info($langs);
186
187 print '</td>';
188
189 // Show example of numbering module
190 print '<td class="nowrap">';
191 $tmp = $module->getExample();
192 if (preg_match('/^Error/', $tmp)) {
193 $langs->load("errors");
194 print '<div class="error">'.$langs->trans($tmp).'</div>';
195 } elseif ($tmp == 'NotConfigured') {
196 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
197 } else {
198 print $tmp;
199 }
200 print '</td>'."\n";
201
202 print '<td class="center">';
203 if (getDolGlobalString('CHEQUERECEIPTS_ADDON') == $file || getDolGlobalString('CHEQUERECEIPTS_ADDON') . '.php' == $file) {
204 print img_picto($langs->trans("Activated"), 'switch_on');
205 } else {
206 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
207 }
208 print '</td>';
209
210 $chequereceipts = new RemiseCheque($db);
211 $chequereceipts->initAsSpecimen();
212
213 // Example
214 $htmltooltip = '';
215 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
216 $nextval = $module->getNextValue($mysoc, $chequereceipts);
217 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
218 $htmltooltip .= $langs->trans("NextValue").': ';
219 if ($nextval) {
220 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
221 $nextval = $langs->trans($nextval);
222 }
223 $htmltooltip .= $nextval.'<br>';
224 } else {
225 $htmltooltip .= $langs->trans($module->error).'<br>';
226 }
227 }
228
229 print '<td class="center">';
230 print $form->textwithpicto('', $htmltooltip, 1, 'info');
231
232 if (getDolGlobalString('CHEQUERECEIPTS_ADDON').'.php' == $file) { // If module is the one used, we show existing errors
233 if (!empty($module->error)) {
234 dol_htmloutput_mesg($module->error, array(), 'error', 1);
235 }
236 }
237
238 print '</td>';
239
240 print "</tr>\n";
241 }
242 }
243 }
244 }
245 closedir($handle);
246 }
247 }
248}
249
250print '</table>';
251print '</div>';
252
253print '<br>';
254
255
256/*
257 * Other options
258 */
259print load_fiche_titre($langs->trans("OtherOptions"), '', '');
260
261print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
262print '<input type="hidden" name="token" value="'.newToken().'">';
263print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">';
264
265print '<table class="noborder centpercent">';
266print '<tr class="liste_titre">';
267print '<td>'.$langs->trans("Parameters").'</td>';
268print '<td class="center" width="60">&nbsp;</td>';
269print '<td width="80">&nbsp;</td>';
270print "</tr>\n";
271
272$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
273$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
274$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
275foreach ($substitutionarray as $key => $val) {
276 $htmltext .= $key.'<br>';
277}
278$htmltext .= '</i>';
279
280print '<tr class="oddeven"><td colspan="2">';
281print $form->textwithpicto($langs->trans("FreeLegalTextOnChequeReceipts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
282$variablename = 'BANK_CHEQUERECEIPT_FREE_TEXT';
283if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
284 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
285} else {
286 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
287 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
288 print $doleditor->Create();
289}
290print '</td><td class="right">';
291print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
292print "</td></tr>\n";
293print '</table>';
294print "<br>";
295
296print '</table>'."\n";
297
298print dol_get_fiche_end();
299
300print '</form>';
301
302// End of page
303llxFooter();
304$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
bank_admin_prepare_head($object)
Prepare array with list of tabs.
Definition bank.lib.php:201
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class to manage cheque delivery receipts.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1135
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.