bank.php 16 KB

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