bank.php 16 KB

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