bank.php 19 KB

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