1<?php 2/* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es> 3 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * \file htdocs/admin/payment.php 21 * \ingroup facture 22 * \brief Page to setup invoices payments 23 */ 24 25require '../main.inc.php'; 26require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 27require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php'; 28require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; 29 30// Load translation files required by the page 31$langs->loadLangs(array("admin", "other", "errors", "bills")); 32 33if (!$user->admin) accessforbidden(); 34 35$action = GETPOST('action', 'aZ09'); 36$value = GETPOST('value', 'alpha'); 37$label = GETPOST('label', 'alpha'); 38$scandir = GETPOST('scan_dir', 'alpha'); 39$type = 'invoice'; 40 41if (empty($conf->global->PAYMENT_ADDON)) $conf->global->PAYMENT_ADDON = 'mod_payment_cicada.php'; 42 43 44/* 45 * Actions 46 */ 47 48if ($action == 'updateMask') 49{ 50 $maskconstpayment = GETPOST('maskconstpayment', 'alpha'); 51 $maskpayment = GETPOST('maskpayment', 'alpha'); 52 if ($maskconstpayment) $res = dolibarr_set_const($db, $maskconstpayment, $maskpayment, 'chaine', 0, '', $conf->entity); 53 54 if (!($res > 0)) $error++; 55 56 if (!$error) 57 { 58 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); 59 } else { 60 setEventMessages($langs->trans("Error"), null, 'errors'); 61 } 62} 63 64if ($action == 'setmod') 65{ 66 dolibarr_set_const($db, "PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity); 67} 68 69if ($action == 'setparams') 70{ 71 $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS', 'restricthtml'); // No alpha here, we want exact string 72 $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $freetext, 'chaine', 0, '', $conf->entity); 73 if (!($res > 0)) $error++; 74 75 $res = dolibarr_set_const($db, "PAYMENTS_REPORT_GROUP_BY_MOD", GETPOST('PAYMENTS_REPORT_GROUP_BY_MOD', 'int'), 'chaine', 0, '', $conf->entity); 76 if (!($res > 0)) $error++; 77 78 if ($error) 79 { 80 setEventMessages($langs->trans("Error"), null, 'errors'); 81 } 82 if (!$error) 83 { 84 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); 85 } 86} 87 88 89/* 90 * View 91 */ 92 93$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); 94 95llxHeader("", $langs->trans("BillsSetup"), 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura'); 96 97$form = new Form($db); 98 99 100$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; 101print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup'); 102 103$head = invoice_admin_prepare_head(); 104print dol_get_fiche_head($head, 'payment', $langs->trans("Invoices"), -1, 'invoice'); 105 106/* 107 * Numbering module 108 */ 109 110print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', ''); 111 112print '<div class="div-table-responsive-no-min">'; 113print '<table class="noborder centpercent">'; 114print '<tr class="liste_titre">'; 115print '<td>'.$langs->trans("Name").'</td>'; 116print '<td>'.$langs->trans("Description").'</td>'; 117print '<td class="nowrap">'.$langs->trans("Example").'</td>'; 118print '<td align="center" width="60">'.$langs->trans("Status").'</td>'; 119print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>'; 120print '</tr>'."\n"; 121 122clearstatcache(); 123 124foreach ($dirmodels as $reldir) 125{ 126 $dir = dol_buildpath($reldir."core/modules/payment/"); 127 if (is_dir($dir)) 128 { 129 $handle = opendir($dir); 130 if (is_resource($handle)) 131 { 132 while (($file = readdir($handle)) !== false) 133 { 134 if (!is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')) 135 { 136 $filebis = $file; 137 $classname = preg_replace('/\.php$/', '', $file); 138 // For compatibility 139 if (!is_file($dir.$filebis)) 140 { 141 $filebis = $file."/".$file.".modules.php"; 142 $classname = "mod_payment_".$file; 143 } 144 // Check if there is a filter on country 145 preg_match('/\-(.*)_(.*)$/', $classname, $reg); 146 if (!empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue; 147 148 $classname = preg_replace('/\-.*$/', '', $classname); 149 if (!class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/', $filebis) || preg_match('/mod_/', $classname)) && substr($filebis, dol_strlen($filebis) - 3, 3) == 'php') 150 { 151 // Charging the numbering class 152 require_once $dir.$filebis; 153 154 $module = new $classname($db); 155 156 // Show modules according to features level 157 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; 158 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; 159 160 if ($module->isEnabled()) 161 { 162 $var = !$var; 163 print '<tr class="oddeven"><td width="100">'; 164 echo preg_replace('/\-.*$/', '', preg_replace('/mod_payment_/', '', preg_replace('/\.php$/', '', $file))); 165 print "</td><td>\n"; 166 167 print $module->info(); 168 169 print '</td>'; 170 171 // Show example of numbering module 172 print '<td class="nowrap">'; 173 $tmp = $module->getExample(); 174 if (preg_match('/^Error/', $tmp)) { 175 $langs->load("errors"); 176 print '<div class="error">'.$langs->trans($tmp).'</div>'; 177 } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); 178 else print $tmp; 179 print '</td>'."\n"; 180 181 print '<td class="center">'; 182 //print "> ".$conf->global->PAYMENT_ADDON." - ".$file; 183 if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON.'.php' == $file) 184 { 185 print img_picto($langs->trans("Activated"), 'switch_on'); 186 } else { 187 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.preg_replace('/\.php$/', '', $file).'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>'; 188 } 189 print '</td>'; 190 191 $payment = new Paiement($db); 192 $payment->initAsSpecimen(); 193 194 // Example 195 $htmltooltip = ''; 196 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>'; 197 $nextval = $module->getNextValue($mysoc, $payment); 198 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval 199 $htmltooltip .= $langs->trans("NextValue").': '; 200 if ($nextval) { 201 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') 202 $nextval = $langs->trans($nextval); 203 $htmltooltip .= $nextval.'<br>'; 204 } else { 205 $htmltooltip .= $langs->trans($module->error).'<br>'; 206 } 207 } 208 209 print '<td class="center">'; 210 print $form->textwithpicto('', $htmltooltip, 1, 0); 211 212 if ($conf->global->PAYMENT_ADDON.'.php' == $file) // If module is the one used, we show existing errors 213 { 214 if (!empty($module->error)) dol_htmloutput_mesg($module->error, '', 'error', 1); 215 } 216 217 print '</td>'; 218 219 print "</tr>\n"; 220 } 221 } 222 } 223 } 224 closedir($handle); 225 } 226 } 227} 228 229print '</table>'; 230print '</div>'; 231 232print "<br>"; 233 234print load_fiche_titre($langs->trans("OtherOptions"), '', ''); 235 236print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; 237print '<input type="hidden" name="token" value="'.newToken().'" />'; 238print '<input type="hidden" name="action" value="setparams" />'; 239 240print '<div class="div-table-responsive-no-min">'; 241print '<table class="noborder centpercent">'; 242print '<tr class="liste_titre">'; 243print '<td>'.$langs->trans("Parameter").'</td>'; 244print '<td align="center" width="60">'.$langs->trans("Value").'</td>'; 245print '<td width="80"> </td>'; 246print "</tr>\n"; 247 248// Allow payments on different thirdparties bills but same parent company 249print '<tr class="oddeven"><td>'; 250print $langs->trans("PaymentOnDifferentThirdBills"); 251print '</td><td width="60" align="center">'; 252print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS", $conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS, 1); 253print '</td><td class="right">'; 254print "</td></tr>\n"; 255 256// Allow to group payments by mod in rapports 257print '<tr class="oddeven"><td>'; 258print $langs->trans("GroupPaymentsByModOnReports"); 259print '</td><td width="60" align="center">'; 260print $form->selectyesno("PAYMENTS_REPORT_GROUP_BY_MOD", $conf->global->PAYMENTS_REPORT_GROUP_BY_MOD, 1); 261print '</td><td class="right">'; 262print "</td></tr>\n"; 263 264print '</table>'; 265print '</div>'; 266 267print dol_get_fiche_end(); 268 269print '<br>'; 270print '<div class="center">'; 271print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />'; 272print '</div>'; 273print '<br>'; 274 275print '</form>'; 276 277// End of page 278llxFooter(); 279$db->close(); 280