bank.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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('scandir','alpha');
  41. $type = 'bankaccount';
  42. /*
  43. * Actions
  44. */
  45. //Order display of bank account
  46. if ($action == 'setbankorder')
  47. {
  48. if (dolibarr_set_const($db, "BANK_SHOW_ORDER_OPTION",GETPOST('value','alpha'),'chaine',0,'',$conf->entity) > 0)
  49. {
  50. header("Location: ".$_SERVER["PHP_SELF"]);
  51. exit;
  52. }
  53. else
  54. {
  55. dol_print_error($db);
  56. }
  57. }
  58. if ($action == 'specimen')
  59. {
  60. $modele=GETPOST('module','alpha');
  61. if ($modele == 'sepamandate')
  62. {
  63. $object = new CompanyBankAccount($db);
  64. }
  65. else
  66. {
  67. $object = new Account($db);
  68. }
  69. $object->initAsSpecimen();
  70. // Search template files
  71. $file=''; $classname=''; $filefound=0;
  72. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  73. foreach($dirmodels as $reldir)
  74. {
  75. $file=dol_buildpath($reldir."core/modules/bank/doc/pdf_".$modele.".modules.php",0);
  76. if (file_exists($file))
  77. {
  78. $filefound=1;
  79. $classname = "pdf_".$modele;
  80. break;
  81. }
  82. }
  83. if ($filefound)
  84. {
  85. require_once $file;
  86. $module = new $classname($db);
  87. if ($module->write_file($object,$langs) > 0)
  88. {
  89. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bank&file=SPECIMEN.pdf");
  90. return;
  91. }
  92. else
  93. {
  94. setEventMessages($module->error, null, 'errors');
  95. dol_syslog($module->error, LOG_ERR);
  96. }
  97. }
  98. else
  99. {
  100. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  101. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  102. }
  103. }
  104. // Activate a model
  105. if ($action == 'set')
  106. {
  107. $ret = addDocumentModel($value, $type, $label, $scandir);
  108. }
  109. else if ($action == 'del')
  110. {
  111. $ret = delDocumentModel($value, $type);
  112. if ($ret > 0)
  113. {
  114. if ($conf->global->BANKADDON_PDF == "$value") dolibarr_del_const($db, 'BANKADDON_PDF',$conf->entity);
  115. }
  116. }
  117. // Set default model
  118. else if ($action == 'setdoc')
  119. {
  120. if (dolibarr_set_const($db, "BANKADDON_PDF",$value,'chaine',0,'',$conf->entity))
  121. {
  122. // The constant that was read before the new set
  123. // We therefore requires a variable to have a coherent view
  124. $conf->global->BANKADDON_PDF = $value;
  125. }
  126. // On active le modele
  127. $ret = delDocumentModel($value, $type);
  128. if ($ret > 0)
  129. {
  130. $ret = addDocumentModel($value, $type, $label, $scandir);
  131. }
  132. }
  133. /*
  134. * view
  135. */
  136. $form=new Form($db);
  137. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  138. llxHeader("",$langs->trans("BankSetupModule"));
  139. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  140. print load_fiche_titre($langs->trans("BankSetupModule"),$linkback,'title_setup');
  141. $head = bank_admin_prepare_head(null);
  142. dol_fiche_head($head, 'general', $langs->trans("BankSetupModule"), -1, 'account');
  143. $var=true;
  144. $var=! $var;
  145. //Show bank account order
  146. print load_fiche_titre($langs->trans("BankOrderShow"), '', '');
  147. print '<table class="noborder" width="100%">';
  148. print '<tr class="liste_titre">';
  149. print '<td width="140">'.$langs->trans("Name").'</td>';
  150. print '<td>'.$langs->trans("Description").'</td>';
  151. print '<td>'.$langs->trans("Example").'</td>';
  152. print '<td align="center">'.$langs->trans("Status").'</td>';
  153. print '<td align="center" width="60">&nbsp;</td>';
  154. print "</tr>\n";
  155. $bankorder[0][0]=$langs->trans("BankOrderGlobal");
  156. $bankorder[0][1]=$langs->trans("BankOrderGlobalDesc");
  157. $bankorder[0][2]='BankCode DeskCode BankAccountNumber BankAccountNumberKey';
  158. $bankorder[1][0]=$langs->trans("BankOrderES");
  159. $bankorder[1][1]=$langs->trans("BankOrderESDesc");
  160. $bankorder[1][2]='BankCode DeskCode BankAccountNumberKey BankAccountNumber';
  161. $var = true;
  162. $i=0;
  163. $nbofbank=count($bankorder);
  164. while ($i < $nbofbank)
  165. {
  166. $var = !$var;
  167. print '<tr class="oddeven">';
  168. print '<td>'.$bankorder[$i][0]."</td><td>\n";
  169. print $bankorder[$i][1];
  170. print '</td>';
  171. print '<td class="nowrap">';
  172. $tmparray=explode(' ',$bankorder[$i][2]);
  173. foreach($tmparray as $key => $val)
  174. {
  175. if ($key > 0) print ', ';
  176. print $langs->trans($val);
  177. }
  178. print "</td>\n";
  179. if ($conf->global->BANK_SHOW_ORDER_OPTION == $i)
  180. {
  181. print '<td align="center">';
  182. print img_picto($langs->trans("Activated"),'on');
  183. print '</td>';
  184. }
  185. else
  186. {
  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. } else {
  219. dol_print_error($db);
  220. }
  221. print "<table class=\"noborder\" width=\"100%\">\n";
  222. print "<tr class=\"liste_titre\">\n";
  223. print '<td>' . $langs->trans("Name") . '</td>';
  224. print '<td>' . $langs->trans("Description") . '</td>';
  225. print '<td align="center" width="60">' . $langs->trans("Status") . "</td>\n";
  226. print '<td align="center" width="60">' . $langs->trans("Default") . "</td>\n";
  227. print '<td align="center" width="38">' . $langs->trans("ShortInfo") . '</td>';
  228. print '<td align="center" width="38">' . $langs->trans("Preview") . '</td>';
  229. print "</tr>\n";
  230. clearstatcache();
  231. foreach ($dirmodels as $reldir)
  232. {
  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_)/', $file)) {
  245. if (file_exists($dir . '/' . $file)) {
  246. $name = substr($file, 4, dol_strlen($file) - 16);
  247. $classname = substr($file, 0, dol_strlen($file) - 12);
  248. require_once $dir . '/' . $file;
  249. $module = new $classname($db);
  250. $modulequalified = 1;
  251. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2)
  252. $modulequalified = 0;
  253. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1)
  254. $modulequalified = 0;
  255. if ($modulequalified) {
  256. print '<tr class="oddeven"><td width="100">';
  257. print(empty($module->name) ? $name : $module->name);
  258. print "</td><td>\n";
  259. if (method_exists($module, 'info'))
  260. print $module->info($langs);
  261. else
  262. print $module->description;
  263. print '</td>';
  264. // Active
  265. if (in_array($name, $def)) {
  266. print '<td align="center">' . "\n";
  267. print '<a href="' . $_SERVER["PHP_SELF"] . '?action=del&value=' . $name . '">';
  268. print img_picto($langs->trans("Enabled"), 'switch_on');
  269. print '</a>';
  270. print '</td>';
  271. } else {
  272. print '<td align="center">' . "\n";
  273. print '<a href="' . $_SERVER["PHP_SELF"] . '?action=set&value=' . $name . '&amp;scandir=' . $module->scandir . '&amp;label=' . urlencode($module->name) . '">' . img_picto($langs->trans("Disabled"), 'switch_off') . '</a>';
  274. print "</td>";
  275. }
  276. // Default
  277. print '<td align="center">';
  278. if ($conf->global->BANKADDON_PDF == $name) {
  279. print img_picto($langs->trans("Default"), 'on');
  280. } else {
  281. print '<a href="' . $_SERVER["PHP_SELF"] . '?action=setdoc&value=' . $name . '&amp;scandir=' . $module->scandir . '&amp;label=' . urlencode($module->name) . '" alt="' . $langs->trans("Default") . '">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
  282. }
  283. print '</td>';
  284. // Info
  285. $htmltooltip = '' . $langs->trans("Name") . ': ' . $module->name;
  286. $htmltooltip .= '<br>' . $langs->trans("Type") . ': ' . ($module->type ? $module->type : $langs->trans("Unknown"));
  287. if ($module->type == 'pdf') {
  288. $htmltooltip .= '<br>' . $langs->trans("Width") . '/' . $langs->trans("Height") . ': ' . $module->page_largeur . '/' . $module->page_hauteur;
  289. }
  290. $htmltooltip .= '<br><br><u>' . $langs->trans("FeaturesSupported") . ':</u>';
  291. $htmltooltip .= '<br>' . $langs->trans("Logo") . ': ' . yn($module->option_logo, 1, 1);
  292. //$htmltooltip .= '<br>' . $langs->trans("PaymentMode") . ': ' . yn($module->option_modereg, 1, 1);
  293. //$htmltooltip .= '<br>' . $langs->trans("PaymentConditions") . ': ' . yn($module->option_condreg, 1, 1);
  294. $htmltooltip .= '<br>' . $langs->trans("MultiLanguage") . ': ' . yn($module->option_multilang, 1, 1);
  295. // $htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
  296. // $htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  297. //$htmltooltip .= '<br>' . $langs->trans("WatermarkOnDraftOrders") . ': ' . yn($module->option_draft_watermark, 1, 1);
  298. print '<td align="center">';
  299. print $form->textwithpicto('', $htmltooltip, 1, 0);
  300. print '</td>';
  301. // Preview
  302. print '<td align="center">';
  303. if ($module->type == 'pdf') {
  304. print '<a href="' . $_SERVER["PHP_SELF"] . '?action=specimen&module=' . $name . '">' . img_object($langs->trans("Preview"), 'bill') . '</a>';
  305. } else {
  306. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  307. }
  308. print '</td>';
  309. print "</tr>\n";
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. //}
  319. dol_fiche_end();
  320. llxFooter();
  321. $db->close();