bank.php 16 KB

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