bank.php 16 KB

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