bank.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/bank.php
  22. * \ingroup bank
  23. * \brief Page to setup the bank module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("admin", "companies", "bills", "other", "banks"));
  33. if (!$user->admin) {
  34. accessforbidden();
  35. }
  36. $action = GETPOST('action', 'aZ09');
  37. $actionsave = GETPOST('save', 'alpha');
  38. $value = GETPOST('value', 'alpha');
  39. $label = GETPOST('label', 'alpha');
  40. $scandir = GETPOST('scan_dir', 'alpha');
  41. $type = 'bankaccount';
  42. /*
  43. * Actions
  44. */
  45. // Order display of bank account
  46. if ($action == 'setbankorder') {
  47. if (dolibarr_set_const($db, "BANK_SHOW_ORDER_OPTION", GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity) > 0) {
  48. } else {
  49. dol_print_error($db);
  50. }
  51. }
  52. // Auto report last num releve on conciliate
  53. if ($action == 'setreportlastnumreleve') {
  54. if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 1, 'chaine', 0, '', $conf->entity) > 0) {
  55. } else {
  56. dol_print_error($db);
  57. }
  58. } elseif ($action == 'unsetreportlastnumreleve') {
  59. if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 0, 'chaine', 0, '', $conf->entity) > 0) {
  60. } else {
  61. dol_print_error($db);
  62. }
  63. }
  64. // Colorize movements
  65. if ($action == 'setbankcolorizemovement') {
  66. if (dolibarr_set_const($db, "BANK_COLORIZE_MOVEMENT", 1, 'chaine', 0, '', $conf->entity) > 0) {
  67. } else {
  68. dol_print_error($db);
  69. }
  70. } elseif ($action == 'unsetbankcolorizemovement') {
  71. if (dolibarr_set_const($db, "BANK_COLORIZE_MOVEMENT", 0, 'chaine', 0, '', $conf->entity) > 0) {
  72. } else {
  73. dol_print_error($db);
  74. }
  75. }
  76. if ($actionsave) {
  77. $db->begin();
  78. $i = 1;
  79. $errorsaved = 0;
  80. $error = 0;
  81. // Save colors
  82. while ($i <= 2) {
  83. $color = GETPOST('BANK_COLORIZE_MOVEMENT_COLOR'.$i, 'alpha');
  84. if ($color == '-1') {
  85. $color = '';
  86. }
  87. $res = dolibarr_set_const($db, 'BANK_COLORIZE_MOVEMENT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
  88. if (!($res > 0)) {
  89. $error++;
  90. }
  91. $i++;
  92. }
  93. if (!$error) {
  94. $db->commit();
  95. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  96. } else {
  97. $db->rollback();
  98. if (empty($errorsaved)) {
  99. setEventMessages($langs->trans("Error"), null, 'errors');
  100. }
  101. }
  102. }
  103. if ($action == 'specimen') {
  104. $modele = GETPOST('module', 'alpha');
  105. if ($modele == 'sepamandate') {
  106. $object = new CompanyBankAccount($db);
  107. } else {
  108. $object = new Account($db);
  109. }
  110. $object->initAsSpecimen();
  111. // Search template files
  112. $file = '';
  113. $classname = '';
  114. $filefound = 0;
  115. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  116. foreach ($dirmodels as $reldir) {
  117. $file = dol_buildpath($reldir."core/modules/bank/doc/pdf_".$modele.".modules.php", 0);
  118. if (file_exists($file)) {
  119. $filefound = 1;
  120. $classname = "pdf_".$modele;
  121. break;
  122. }
  123. }
  124. if ($filefound) {
  125. require_once $file;
  126. $module = new $classname($db);
  127. if ($module->write_file($object, $langs) > 0) {
  128. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bank&file=SPECIMEN.pdf");
  129. return;
  130. } else {
  131. setEventMessages($module->error, null, 'errors');
  132. dol_syslog($module->error, LOG_ERR);
  133. }
  134. } else {
  135. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  136. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  137. }
  138. }
  139. // Activate a model
  140. if ($action == 'set') {
  141. $ret = addDocumentModel($value, $type, $label, $scandir);
  142. } elseif ($action == 'del') {
  143. $ret = delDocumentModel($value, $type);
  144. if ($ret > 0) {
  145. if ($conf->global->BANKADDON_PDF == "$value") {
  146. dolibarr_del_const($db, 'BANKADDON_PDF', $conf->entity);
  147. }
  148. }
  149. } elseif ($action == 'setdoc') {
  150. // Set default model
  151. if (dolibarr_set_const($db, "BANKADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  152. // The constant that was read before the new set
  153. // We therefore requires a variable to have a coherent view
  154. $conf->global->BANKADDON_PDF = $value;
  155. }
  156. // On active le modele
  157. $ret = delDocumentModel($value, $type);
  158. if ($ret > 0) {
  159. $ret = addDocumentModel($value, $type, $label, $scandir);
  160. }
  161. }
  162. /*
  163. * View
  164. */
  165. $form = new Form($db);
  166. $formother = new FormOther($db);
  167. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  168. llxHeader("", $langs->trans("BankSetupModule"));
  169. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  170. print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup');
  171. print '<form name="bankmovementcolorconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  172. print '<input type="hidden" name="token" value="'.newToken().'">';
  173. print '<input type="hidden" name="action" value="save">';
  174. $head = bank_admin_prepare_head(null);
  175. print dol_get_fiche_head($head, 'general', $langs->trans("BankSetupModule"), -1, 'account');
  176. //Show bank account order
  177. print load_fiche_titre($langs->trans("BankOrderShow"), '', '');
  178. print '<div class="div-table-responsive-no-min">';
  179. print '<table class="noborder centpercent">';
  180. print '<tr class="liste_titre">';
  181. print '<td>'.$langs->trans("Name").'</td>';
  182. print '<td class="minwidth100">'.$langs->trans("Description").'</td>';
  183. print '<td>'.$langs->trans("Example").'</td>';
  184. print '<td class="center">'.$langs->trans("Status").'</td>';
  185. print "</tr>\n";
  186. $bankorder[0][0] = $langs->trans("BankOrderGlobal");
  187. $bankorder[0][1] = $langs->trans("BankOrderGlobalDesc");
  188. $bankorder[0][2] = 'BankCode DeskCode BankAccountNumber BankAccountNumberKey';
  189. $bankorder[1][0] = $langs->trans("BankOrderES");
  190. $bankorder[1][1] = $langs->trans("BankOrderESDesc");
  191. $bankorder[1][2] = 'BankCode DeskCode BankAccountNumberKey BankAccountNumber';
  192. $i = 0;
  193. $nbofbank = count($bankorder);
  194. while ($i < $nbofbank) {
  195. print '<tr class="oddeven">';
  196. print '<td>'.$bankorder[$i][0]."</td><td>\n";
  197. print $bankorder[$i][1];
  198. print '</td>';
  199. print '<td class="nowrap">';
  200. $tmparray = explode(' ', $bankorder[$i][2]);
  201. foreach ($tmparray as $key => $val) {
  202. if ($key > 0) {
  203. print ', ';
  204. }
  205. print $langs->trans($val);
  206. }
  207. print "</td>\n";
  208. if (getDolGlobalInt('BANK_SHOW_ORDER_OPTION') == $i) {
  209. print '<td class="center">';
  210. print img_picto($langs->trans("Activated"), 'on');
  211. print '</td>';
  212. } else {
  213. print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbankorder&token='.newToken().'&value='.((int) $i).'">';
  214. print img_picto($langs->trans("Disabled"), 'off');
  215. print '</a></td>';
  216. }
  217. print '</tr>'."\n";
  218. $i++;
  219. }
  220. print '</table>'."\n";
  221. print "</div>";
  222. print '<br><br>';
  223. /*
  224. * Document templates generators
  225. */
  226. print load_fiche_titre($langs->trans("BankAccountModelModule"), '', '');
  227. // Load array def with activated templates
  228. $def = array();
  229. $sql = "SELECT nom";
  230. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  231. $sql .= " WHERE type = '".$db->escape($type)."'";
  232. $sql .= " AND entity = ".$conf->entity;
  233. $resql = $db->query($sql);
  234. if ($resql) {
  235. $i = 0;
  236. $num_rows = $db->num_rows($resql);
  237. while ($i < $num_rows) {
  238. $array = $db->fetch_array($resql);
  239. array_push($def, $array[0]);
  240. $i++;
  241. }
  242. } else {
  243. dol_print_error($db);
  244. }
  245. print '<div class="div-table-responsive-no-min">';
  246. print '<table class="noborder centpercent">'."\n";
  247. print '<tr class="liste_titre">'."\n";
  248. print '<td>'.$langs->trans("Name").'</td>';
  249. print '<td class="minwidth100">'.$langs->trans("Description").'</td>';
  250. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  251. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  252. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  253. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  254. print '</tr>'."\n";
  255. clearstatcache();
  256. foreach ($dirmodels as $reldir) {
  257. foreach (array('', '/doc') as $valdir) {
  258. $dir = dol_buildpath($reldir."core/modules/bank".$valdir);
  259. if (is_dir($dir)) {
  260. $handle = opendir($dir);
  261. if (is_resource($handle)) {
  262. while (($file = readdir($handle)) !== false) {
  263. $filelist[] = $file;
  264. }
  265. closedir($handle);
  266. arsort($filelist);
  267. foreach ($filelist as $file) {
  268. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  269. if (file_exists($dir.'/'.$file)) {
  270. $name = substr($file, 4, dol_strlen($file) - 16);
  271. $classname = substr($file, 0, dol_strlen($file) - 12);
  272. require_once $dir.'/'.$file;
  273. $module = new $classname($db);
  274. $modulequalified = 1;
  275. if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
  276. $modulequalified = 0;
  277. }
  278. if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
  279. $modulequalified = 0;
  280. }
  281. if ($modulequalified) {
  282. print '<tr class="oddeven"><td width="100">';
  283. print(empty($module->name) ? $name : $module->name);
  284. print "</td><td>\n";
  285. if (method_exists($module, 'info')) {
  286. print $module->info($langs);
  287. } else {
  288. print $module->description;
  289. }
  290. print '</td>';
  291. // Active
  292. if (in_array($name, $def)) {
  293. print '<td class="center">'."\n";
  294. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.$name.'">';
  295. print img_picto($langs->trans("Enabled"), 'switch_on');
  296. print '</a>';
  297. print '</td>';
  298. } else {
  299. print '<td class="center">'."\n";
  300. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&token='.newToken().'&can_dir='.$module->scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  301. print "</td>";
  302. }
  303. // Default
  304. print '<td class="center">';
  305. if ($conf->global->BANKADDON_PDF == $name) {
  306. print img_picto($langs->trans("Default"), 'on');
  307. } else {
  308. 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>';
  309. }
  310. print '</td>';
  311. // Info
  312. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  313. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  314. if ($module->type == 'pdf') {
  315. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  316. }
  317. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  318. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  319. //$htmltooltip .= '<br>' . $langs->trans("PaymentMode") . ': ' . yn($module->option_modereg, 1, 1);
  320. //$htmltooltip .= '<br>' . $langs->trans("PaymentConditions") . ': ' . yn($module->option_condreg, 1, 1);
  321. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  322. // $htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
  323. // $htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  324. //$htmltooltip .= '<br>' . $langs->trans("WatermarkOnDraftOrders") . ': ' . yn($module->option_draft_watermark, 1, 1);
  325. print '<td class="center">';
  326. print $form->textwithpicto('', $htmltooltip, 1, 0);
  327. print '</td>';
  328. // Preview
  329. print '<td class="center">';
  330. if ($module->type == 'pdf') {
  331. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  332. } else {
  333. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  334. }
  335. print '</td>';
  336. print "</tr>\n";
  337. }
  338. }
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. print '</table>';
  346. print '</div>';
  347. print '<br><br>';
  348. print load_fiche_titre($langs->trans("BankColorizeMovement"), '', '');
  349. print '<div class="div-table-responsive-no-min">';
  350. print '<table class="noborder centpercent">'."\n";
  351. print '<tr class="liste_titre">'."\n";
  352. print '<td colspan="4">'.$langs->trans("Name").'</td>';
  353. print '<td align="center" width="75">'.$langs->trans("Value").'</td>'."\n";
  354. print "</tr>\n";
  355. print '<tr class="oddeven"><td colspan="4">';
  356. print $langs->trans('BankColorizeMovementDesc');
  357. print "</td>";
  358. // Active
  359. if (getDolGlobalInt('BANK_COLORIZE_MOVEMENT')) {
  360. print '<td class="center">'."\n";
  361. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetbankcolorizemovement&token='.newToken().'">';
  362. print img_picto($langs->trans("Enabled"), 'switch_on');
  363. print '</a>';
  364. print '</td>';
  365. } else {
  366. print '<td class="center">'."\n";
  367. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setbankcolorizemovement&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  368. print "</td>";
  369. }
  370. print "</tr>\n";
  371. if (getDolGlobalInt('BANK_COLORIZE_MOVEMENT')) {
  372. $i = 1;
  373. while ($i <= 2) {
  374. $key = $i;
  375. $color = 'BANK_COLORIZE_MOVEMENT_COLOR'.$key;
  376. print '<tr class="oddeven">';
  377. // Label
  378. print '<td colspan="4" width="180" class="nowrap">'.$langs->trans("BankColorizeMovementName".$key)."</td>";
  379. // Color
  380. print '<td class="nowrap right">';
  381. print $formother->selectColor((GETPOST("BANK_COLORIZE_MOVEMENT_COLOR".$key) ? GETPOST("BANK_COLORIZE_MOVEMENT_COLOR".$key) : $conf->global->$color), "BANK_COLORIZE_MOVEMENT_COLOR".$key, 'bankmovementcolorconfig', 1, '', 'right hideifnotset');
  382. print '</td>';
  383. print "</tr>";
  384. $i++;
  385. }
  386. }
  387. print '</table>';
  388. print '</div>';
  389. print '<br><br>';
  390. /*
  391. * Document templates generators
  392. */
  393. print load_fiche_titre($langs->trans("Other"), '', '');
  394. print '<div class="div-table-responsive-no-min">';
  395. print '<table class="noborder centpercent">'."\n";
  396. print '<tr class="liste_titre">'."\n";
  397. print '<td>'.$langs->trans("Name").'</td>';
  398. print '<td>'.$langs->trans("Description").'</td>';
  399. print '<td class="center width75">'.$langs->trans("Status")."</td>\n";
  400. print "</tr>\n";
  401. print '<tr class="oddeven"><td>';
  402. print $langs->trans('AccountStatement');
  403. print "</td><td>\n";
  404. print $langs->trans('AutoReportLastAccountStatement');
  405. print '</td>';
  406. // Active
  407. if (getDolGlobalString('BANK_REPORT_LAST_NUM_RELEVE')) {
  408. print '<td class="center">'."\n";
  409. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetreportlastnumreleve&token='.newToken().'">';
  410. print img_picto($langs->trans("Enabled"), 'switch_on');
  411. print '</a>';
  412. print '</td>';
  413. } else {
  414. print '<td class="center">'."\n";
  415. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setreportlastnumreleve&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  416. print "</td>";
  417. }
  418. print "</tr>\n";
  419. // Allow SEPA Mandate OnLine Sign
  420. if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
  421. print '<tr class="oddeven">';
  422. print '<td>'.$langs->trans("AllowOnLineSign").'</td>';
  423. print '<td>'.$langs->trans("BankAccountModelModule").'</td>';
  424. print '<td class="center">';
  425. print ajax_constantonoff('SOCIETE_RIB_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1);
  426. print '</td></tr>';
  427. }
  428. print '</table>';
  429. print '</div>';
  430. print dol_get_fiche_end();
  431. print $form->buttonsSaveCancel("Save", '');
  432. print "</form>\n";
  433. // End of page
  434. llxFooter();
  435. $db->close();