1<?php 2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com> 5 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es> 6 * Copyright (C) 2019 Markus Welters <markus@welters.de> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22/** 23 * \file htdocs/admin/credtitransfer.php 24 * \ingroup paymentbybanktransfer 25 * \brief Page to setup payments by credit transfer 26 */ 27 28require '../main.inc.php'; 29require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; 32 33// Load translation files required by the page 34$langs->loadLangs(array("admin", "withdrawals")); 35 36// Security check 37if (!$user->admin) accessforbidden(); 38 39$action = GETPOST('action', 'aZ09'); 40$type = 'paymentorder'; 41 42 43/* 44 * Actions 45 */ 46 47if ($action == "set") 48{ 49 $db->begin(); 50 51 $id = GETPOST('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT', 'int'); 52 $account = new Account($db); 53 if ($account->fetch($id) > 0) 54 { 55 $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT", $id, 'chaine', 0, '', $conf->entity); 56 if (!($res > 0)) $error++; 57 /* 58 $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity); 59 if (! $res > 0) $error++; 60 $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity); 61 if (! $res > 0) $error++; 62 $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity); 63 if (! $res > 0) $error++; 64 $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity); 65 if (! $res > 0) $error++; 66 $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity); 67 if (! $res > 0) $error++; 68 $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity); 69 if (! $res > 0) $error++; 70 $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity); 71 if (! $res > 0) $error++; 72 */ 73 } else $error++; 74 75 $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_ICS", GETPOST("PAYMENTBYBANKTRANSFER_ICS"), 'chaine', 0, '', $conf->entity); 76 if (!($res > 0)) $error++; 77 78 if (GETPOST("PAYMENTBYBANKTRANSFER_USER") > 0) 79 { 80 $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_USER", GETPOST("PAYMENTBYBANKTRANSFER_USER"), 'chaine', 0, '', $conf->entity); 81 if (!($res > 0)) $error++; 82 } 83 /* 84 if (GETPOST("PAYMENTBYBANKTRANSFER_END_TO_END") || GETPOST("PAYMENTBYBANKTRANSFER_END_TO_END") == "") 85 { 86 $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_END_TO_END", GETPOST("PAYMENTBYBANKTRANSFER_END_TO_END"), 'chaine', 0, '', $conf->entity); 87 if (!($res > 0)) $error++; 88 } 89 if (GETPOST("PAYMENTBYBANKTRANSFER_USTRD") || GETPOST("PAYMENTBYBANKTRANSFER_USTRD") == "") 90 { 91 $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_USTRD", GETPOST("PAYMENTBYBANKTRANSFER_USTRD"), 'chaine', 0, '', $conf->entity); 92 if (!($res > 0)) $error++; 93 } 94 */ 95 if (GETPOST("PAYMENTBYBANKTRANSFER_ADDDAYS") || GETPOST("PAYMENTBYBANKTRANSFER_ADDDAYS") == "") 96 { 97 $res = dolibarr_set_const($db, "PAYMENTBYBANKTRANSFER_ADDDAYS", GETPOST("PAYMENTBYBANKTRANSFER_ADDDAYS"), 'chaine', 0, '', $conf->entity); 98 if (!($res > 0)) $error++; 99 } elseif (!$error) 100 { 101 $db->commit(); 102 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); 103 } else { 104 $db->rollback(); 105 setEventMessages($langs->trans("Error"), null, 'errors'); 106 } 107} 108 109if ($action == "addnotif") 110{ 111 $bon = new BonPrelevement($db); 112 $bon->AddNotification($db, GETPOST('user', 'int'), $action); 113 114 header("Location: ".$_SERVER["PHP_SELF"]); 115 exit; 116} 117 118if ($action == "deletenotif") 119{ 120 $bon = new BonPrelevement($db); 121 $bon->DeleteNotificationById(GETPOST('notif', 'int')); 122 123 header("Location: ".$_SERVER["PHP_SELF"]); 124 exit; 125} 126 127 128/* 129 * View 130 */ 131 132$form = new Form($db); 133 134$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); 135 136llxHeader('', $langs->trans("CreditTransferSetup")); 137 138$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; 139 140print load_fiche_titre($langs->trans("CreditTransferSetup"), $linkback, 'title_setup'); 141print '<br>'; 142 143print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=set">'; 144print '<input type="hidden" name="token" value="'.newToken().'">'; 145 146print '<table class="noborder centpercent">'; 147 148print '<tr class="liste_titre">'; 149print '<td class="titlefieldcreate">'.$langs->trans("Parameter").'</td>'; 150print '<td>'.$langs->trans("Value").'</td>'; 151print "</tr>"; 152 153// Bank account (from Banks module) 154print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("BankToPayCreditTransfer").'</td>'; 155print '<td class="left">'; 156$form->select_comptes($conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT, 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT', 0, "courant=1", 1); 157print '</td></tr>'; 158 159// ICS 160print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("ICS").'</td>'; 161print '<td class="left">'; 162print '<input type="text" name="PAYMENTBYBANKTRANSFER_ICS" value="'.$conf->global->PAYMENTBYBANKTRANSFER_ICS.'" size="15" ></td>'; 163print '</td></tr>'; 164 165//User 166print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("ResponsibleUser").'</td>'; 167print '<td class="left">'; 168print $form->select_dolusers($conf->global->PAYMENTBYBANKTRANSFER_USER, 'PAYMENTBYBANKTRANSFER_USER', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); 169print '</td>'; 170print '</tr>'; 171 172/* 173//EntToEnd 174print '<tr class="oddeven"><td>'.$langs->trans("END_TO_END").'</td>'; 175print '<td class="left">'; 176print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.$conf->global->PRELEVEMENT_END_TO_END.'" size="15" ></td>'; 177print '</td></tr>'; 178 179//USTRD 180print '<tr class="oddeven"><td>'.$langs->trans("USTRD").'</td>'; 181print '<td class="left">'; 182print '<input type="text" name="PRELEVEMENT_USTRD" value="'.$conf->global->PRELEVEMENT_USTRD.'" size="15" ></td>'; 183print '</td></tr>'; 184*/ 185 186//ADDDAYS 187print '<tr class="oddeven"><td>'.$langs->trans("ADDDAYS").'</td>'; 188print '<td class="left">'; 189if (!$conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS) $conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS = 0; 190print '<input type="text" name="PAYMENTBYBANKTRANSFER_ADDDAYS" value="'.$conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS.'" size="15" ></td>'; 191print '</td></tr>'; 192print '</table>'; 193print '<br>'; 194 195print '<div class="center"><input type="submit" class="button button-save" value="'.$langs->trans("Save").'"></div>'; 196 197print '</form>'; 198 199 200print '<br>'; 201 202 203/* 204 * Document templates generators 205 */ 206/* 207print load_fiche_titre($langs->trans("OrdersModelModule"),'',''); 208 209// Load array def with activated templates 210$def = array(); 211$sql = "SELECT nom"; 212$sql.= " FROM ".MAIN_DB_PREFIX."document_model"; 213$sql.= " WHERE type = '".$db->escape($type)."'"; 214$sql.= " AND entity = ".$conf->entity; 215$resql=$db->query($sql); 216if ($resql) 217{ 218 $i = 0; 219 $num_rows=$db->num_rows($resql); 220 while ($i < $num_rows) 221 { 222 $array = $db->fetch_array($resql); 223 array_push($def, $array[0]); 224 $i++; 225 } 226} 227else 228{ 229 dol_print_error($db); 230} 231 232 233print "<table class=\"noborder\" width=\"100%\">\n"; 234print "<tr class=\"liste_titre\">\n"; 235print '<td>'.$langs->trans("Name").'</td>'; 236print '<td>'.$langs->trans("Description").'</td>'; 237print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n"; 238print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n"; 239print '<td align="center" width="38">'.$langs->trans("ShortInfo").'</td>'; 240print '<td align="center" width="38">'.$langs->trans("Preview").'</td>'; 241print "</tr>\n"; 242 243clearstatcache(); 244 245foreach ($dirmodels as $reldir) 246{ 247 foreach (array('','/doc') as $valdir) 248 { 249 $dir = dol_buildpath($reldir."core/modules/paymentorders".$valdir); 250 251 if (is_dir($dir)) 252 { 253 $handle=opendir($dir); 254 if (is_resource($handle)) 255 { 256 while (($file = readdir($handle))!==false) 257 { 258 $filelist[]=$file; 259 } 260 closedir($handle); 261 arsort($filelist); 262 263 foreach($filelist as $file) 264 { 265 if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) 266 { 267 268 if (file_exists($dir.'/'.$file)) 269 { 270 $name = substr($file, 4, dol_strlen($file) -16); 271 $classname = substr($file, 0, dol_strlen($file) -12); 272 273 require_once $dir.'/'.$file; 274 $module = new $classname($db); 275 276 $modulequalified=1; 277 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; 278 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; 279 280 if ($modulequalified) 281 { 282 $var = !$var; 283 print '<tr class="oddeven"><td width="100">'; 284 print (empty($module->name)?$name:$module->name); 285 print "</td><td>\n"; 286 if (method_exists($module,'info')) print $module->info($langs); 287 else print $module->description; 288 print '</td>'; 289 290 // Active 291 if (in_array($name, $def)) 292 { 293 print '<td class="center">'."\n"; 294 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">'; 295 print img_picto($langs->trans("Enabled"),'switch_on'); 296 print '</a>'; 297 print '</td>'; 298 } 299 else 300 { 301 print '<td class="center">'."\n"; 302 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>'; 303 print "</td>"; 304 } 305 306 // Default 307 print '<td class="center">'; 308 if ($conf->global->PAYMENTORDER_ADDON_PDF == $name) 309 { 310 print img_picto($langs->trans("Default"),'on'); 311 } 312 else 313 { 314 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; 315 } 316 print '</td>'; 317 318 // Info 319 $htmltooltip = ''.$langs->trans("Name").': '.$module->name; 320 $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); 321 if ($module->type == 'pdf') 322 { 323 $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; 324 } 325 $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>'; 326 $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); 327 $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); 328 $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); 329 $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); 330 //$htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1); 331 //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1); 332 $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1); 333 334 335 print '<td class="center">'; 336 print $form->textwithpicto('',$htmltooltip,1,0); 337 print '</td>'; 338 339 // Preview 340 print '<td class="center">'; 341 if ($module->type == 'pdf') 342 { 343 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>'; 344 } 345 else 346 { 347 print img_object($langs->trans("PreviewNotAvailable"),'generic'); 348 } 349 print '</td>'; 350 351 print "</tr>\n"; 352 } 353 } 354 } 355 } 356 } 357 } 358 } 359} 360 361*/ 362 363 364print dol_get_fiche_end(); 365 366print '<br>'; 367 368 369/* 370 * Notifications 371 */ 372 373/* Disable this, there is no trigger with elementtype 'withdraw' 374if (! empty($conf->global->MAIN_MODULE_NOTIFICATION)) 375{ 376 $langs->load("mails"); 377 print load_fiche_titre($langs->trans("Notifications")); 378 379 $sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email"; 380 $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; 381 $sql.= " WHERE entity IN (".getEntity('invoice').")"; 382 383 $resql=$db->query($sql); 384 if ($resql) 385 { 386 $num = $db->num_rows($resql); 387 $i = 0; 388 while ($i < $num) 389 { 390 $obj = $db->fetch_object($resql); 391 392 if (!$obj->fk_soc) 393 { 394 $username=dolGetFirstLastname($obj->firstname,$obj->lastname); 395 $internalusers[$obj->rowid] = $username; 396 } 397 398 $i++; 399 } 400 $db->free($resql); 401 } 402 403 // Get list of triggers for module withdraw 404 $sql = "SELECT rowid, code, label"; 405 $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger"; 406 $sql.= " WHERE elementtype = 'withdraw'"; 407 $sql.= " ORDER BY rang ASC"; 408 409 $resql = $db->query($sql); 410 if ($resql) 411 { 412 $num = $db->num_rows($resql); 413 $i = 0; 414 while ($i < $num) 415 { 416 $obj = $db->fetch_object($resql); 417 $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); 418 $actions[$obj->rowid]=$label; 419 $i++; 420 } 421 $db->free($resql); 422 } 423 424 425 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif">'; 426 print '<input type="hidden" name="token" value="'.newToken().'">'; 427 print '<table class="noborder centpercent">'; 428 print '<tr class="liste_titre">'; 429 print '<td>'.$langs->trans("User").'</td>'; 430 print '<td>'.$langs->trans("Value").'</td>'; 431 print '<td class="right">'.$langs->trans("Action").'</td>'; 432 print "</tr>\n"; 433 434 print '<tr class="impair"><td class="left">'; 435 print $form->selectarray('user',$internalusers);// select_dolusers(0,'user',0); 436 print '</td>'; 437 438 print '<td>'; 439 print $form->selectarray('action',$actions);// select_dolusers(0,'user',0); 440 print '</td>'; 441 442 print '<td class="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>'; 443 444 // List of current notifications for objet_type='withdraw' 445 $sql = "SELECT u.lastname, u.firstname,"; 446 $sql.= " nd.rowid, ad.code, ad.label"; 447 $sql.= " FROM ".MAIN_DB_PREFIX."user as u,"; 448 $sql.= " ".MAIN_DB_PREFIX."notify_def as nd,"; 449 $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as ad"; 450 $sql.= " WHERE u.rowid = nd.fk_user"; 451 $sql.= " AND nd.fk_action = ad.rowid"; 452 $sql.= " AND u.entity IN (0,".$conf->entity.")"; 453 454 $resql = $db->query($sql); 455 if ($resql) 456 { 457 $num = $db->num_rows($resql); 458 $i = 0; 459 while ($i < $num) 460 { 461 $obj = $db->fetch_object($resql); 462 463 464 print '<tr class="oddeven">'; 465 print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>'; 466 $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); 467 print '<td>'.$label.'</td>'; 468 print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&token='.newToken().'¬if='.$obj->rowid.'">'.img_delete().'</a></td>'; 469 print '</tr>'; 470 $i++; 471 } 472 $db->free($resql); 473 } 474 475 print '</table>'; 476 print '</form>'; 477} 478*/ 479 480// End of page 481llxFooter(); 482$db->close(); 483