supplier_payment.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. /* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/supplier_payment.php
  20. * \ingroup supplier
  21. * \brief Page to setup supplier invoices payments
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("admin", "errors", "other", "bills", "orders"));
  29. if (! $user->admin) accessforbidden();
  30. $action = GETPOST('action','alpha');
  31. $value = GETPOST('value','alpha');
  32. $label = GETPOST('label','alpha');
  33. $scandir = GETPOST('scan_dir','alpha');
  34. $type='supplier_payment';
  35. /*
  36. * Actions
  37. */
  38. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  39. if ($action == 'updateMask')
  40. {
  41. $maskconstsupplierpayment=GETPOST('maskconstsupplierpayment','alpha');
  42. $masksupplierpayment=GETPOST('masksupplierpayment','alpha');
  43. if ($maskconstsupplierpayment) $res = dolibarr_set_const($db,$maskconstsupplierpayment,$masksupplierpayment,'chaine',0,'',$conf->entity);
  44. if (! $res > 0) $error++;
  45. if (! $error)
  46. {
  47. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  48. }
  49. else
  50. {
  51. setEventMessages($langs->trans("Error"), null, 'errors');
  52. }
  53. }elseif ($action == 'setmod')
  54. {
  55. dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON", $value, 'chaine', 0, '', $conf->entity);
  56. }
  57. // Activate a model
  58. elseif ($action == 'set')
  59. {
  60. $ret = addDocumentModel($value, $type, $label, $scandir);
  61. }
  62. elseif ($action == 'del')
  63. {
  64. $ret = delDocumentModel($value, $type);
  65. if ($ret > 0)
  66. {
  67. if ($conf->global->FACTURE_ADDON_PDF == "$value") dolibarr_del_const($db, 'SUPPLIER_PAYMENT_ADDON_PDF',$conf->entity);
  68. }
  69. }
  70. // Set default model
  71. elseif ($action == 'setdoc')
  72. {
  73. if (dolibarr_set_const($db, "SUPPLIER_PAYMENT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  74. {
  75. // La constante qui a ete lue en avant du nouveau set
  76. // on passe donc par une variable pour avoir un affichage coherent
  77. $conf->global->FACTURE_ADDON_PDF = $value;
  78. }
  79. // On active le modele
  80. $ret = delDocumentModel($value, $type);
  81. if ($ret > 0)
  82. {
  83. $ret = addDocumentModel($value, $type, $label, $scandir);
  84. }
  85. }
  86. elseif ($action == 'specimen')
  87. {
  88. $modele=GETPOST('module','alpha');
  89. $paiementFourn = new PaiementFourn($db);
  90. $paiementFourn->initAsSpecimen();
  91. // Search template files
  92. $file=''; $classname=''; $filefound=0;
  93. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  94. foreach($dirmodels as $reldir)
  95. {
  96. $file=dol_buildpath($reldir."core/modules/supplier_payment/doc/pdf_".$modele.".modules.php",0);
  97. if (file_exists($file))
  98. {
  99. $filefound=1;
  100. $classname = "pdf_".$modele;
  101. break;
  102. }
  103. }
  104. if ($filefound)
  105. {
  106. require_once $file;
  107. $module = new $classname($db);
  108. if ($module->write_file($paiementFourn,$langs) > 0)
  109. {
  110. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf");
  111. return;
  112. }
  113. else
  114. {
  115. setEventMessages($module->error, $module->errors, 'errors');
  116. dol_syslog($module->error, LOG_ERR);
  117. }
  118. }
  119. else
  120. {
  121. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  122. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  123. }
  124. }
  125. /*
  126. * View
  127. */
  128. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  129. llxHeader("",$langs->trans("SupplierPaymentSetup"),'EN:Supplier_Payment_Configuration|FR:Configuration_module_paiement_fournisseur');
  130. $form=new Form($db);
  131. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  132. print load_fiche_titre($langs->trans("SupplierPaymentSetup"),$linkback,'title_setup');
  133. print "<br>";
  134. $head = supplierorder_admin_prepare_head();
  135. dol_fiche_head($head, 'supplierpayment', $langs->trans("Suppliers"), -1, 'company');
  136. /*
  137. * Numbering module
  138. */
  139. if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
  140. print load_fiche_titre($langs->trans("PaymentsNumberingModule"), '', '');
  141. // Load array def with activated templates
  142. $def = array();
  143. $sql = "SELECT nom";
  144. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  145. $sql.= " WHERE type = '".$type."'";
  146. $sql.= " AND entity = ".$conf->entity;
  147. $resql=$db->query($sql);
  148. if ($resql)
  149. {
  150. $i = 0;
  151. $num_rows=$db->num_rows($resql);
  152. while ($i < $num_rows)
  153. {
  154. $array = $db->fetch_array($resql);
  155. array_push($def, $array[0]);
  156. $i++;
  157. }
  158. }
  159. else
  160. {
  161. dol_print_error($db);
  162. }
  163. print '<table class="noborder" width="100%">';
  164. print '<tr class="liste_titre">';
  165. print '<td>'.$langs->trans("Name").'</td>';
  166. print '<td>'.$langs->trans("Description").'</td>';
  167. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  168. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  169. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  170. print '</tr>'."\n";
  171. clearstatcache();
  172. foreach ($dirmodels as $reldir)
  173. {
  174. $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
  175. if (is_dir($dir))
  176. {
  177. $handle = opendir($dir);
  178. if (is_resource($handle))
  179. {
  180. while (($file = readdir($handle))!==false)
  181. {
  182. if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
  183. {
  184. $filebis = $file;
  185. $classname = preg_replace('/\.php$/','',$file);
  186. // For compatibility
  187. if (! is_file($dir.$filebis))
  188. {
  189. $filebis = $file."/".$file.".modules.php";
  190. $classname = "mod_supplier_payment_".$file;
  191. }
  192. // Check if there is a filter on country
  193. preg_match('/\-(.*)_(.*)$/',$classname,$reg);
  194. if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
  195. $classname = preg_replace('/\-.*$/','',$classname);
  196. if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
  197. {
  198. // Charging the numbering class
  199. require_once $dir.$filebis;
  200. $module = new $classname($db);
  201. // Show modules according to features level
  202. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  203. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  204. if ($module->isEnabled())
  205. {
  206. print '<tr class="oddeven"><td width="100">';
  207. echo preg_replace('/\-.*$/','',preg_replace('/mod_supplier_payment_/','',preg_replace('/\.php$/','',$file)));
  208. print "</td><td>\n";
  209. print $module->info();
  210. print '</td>';
  211. // Show example of numbering module
  212. print '<td class="nowrap">';
  213. $tmp=$module->getExample();
  214. if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  215. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  216. else print $tmp;
  217. print '</td>'."\n";
  218. print '<td align="center">';
  219. //print "> ".$conf->global->SUPPLIER_PAYMENT_ADDON." - ".$file;
  220. if ($conf->global->SUPPLIER_PAYMENT_ADDON == $file || $conf->global->SUPPLIER_PAYMENT_ADDON.'.php' == $file)
  221. {
  222. print img_picto($langs->trans("Activated"),'switch_on');
  223. }
  224. else
  225. {
  226. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&value='.preg_replace('/\.php$/','',$file).'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  227. }
  228. print '</td>';
  229. $payment=new PaiementFourn($db);
  230. $payment->initAsSpecimen();
  231. // Example
  232. $htmltooltip='';
  233. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  234. $nextval=$module->getNextValue($mysoc,$payment);
  235. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  236. $htmltooltip.=$langs->trans("NextValue").': ';
  237. if ($nextval) {
  238. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  239. $nextval = $langs->trans($nextval);
  240. $htmltooltip.=$nextval.'<br>';
  241. } else {
  242. $htmltooltip.=$langs->trans($module->error).'<br>';
  243. }
  244. }
  245. print '<td align="center">';
  246. print $form->textwithpicto('',$htmltooltip,1,0);
  247. if ($conf->global->PAYMENT_ADDON.'.php' == $file) // If module is the one used, we show existing errors
  248. {
  249. if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
  250. }
  251. print '</td>';
  252. print "</tr>\n";
  253. }
  254. }
  255. }
  256. }
  257. closedir($handle);
  258. }
  259. }
  260. }
  261. print '</table>';
  262. /*
  263. * Document templates generators
  264. */
  265. print '<br>';
  266. print load_fiche_titre($langs->trans("PaymentsPDFModules"),'','');
  267. print '<table class="noborder" width="100%">'."\n";
  268. print '<tr class="liste_titre">'."\n";
  269. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  270. print '<td>'.$langs->trans("Description").'</td>'."\n";
  271. print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  272. print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  273. print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  274. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  275. print '</tr>'."\n";
  276. clearstatcache();
  277. foreach ($dirmodels as $reldir)
  278. {
  279. $dir = dol_buildpath($reldir."core/modules/supplier_payment/doc/");
  280. if (is_dir($dir))
  281. {
  282. $handle=opendir($dir);
  283. if (is_resource($handle))
  284. {
  285. while (($file = readdir($handle))!==false)
  286. {
  287. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  288. {
  289. $name = substr($file, 4, dol_strlen($file) -16);
  290. $classname = substr($file, 0, dol_strlen($file) -12);
  291. require_once $dir.'/'.$file;
  292. $module = new $classname($db, new PaiementFourn($db));
  293. print "<tr class=\"oddeven\">\n";
  294. print "<td>";
  295. print (empty($module->name)?$name:$module->name);
  296. print "</td>\n";
  297. print "<td>\n";
  298. require_once $dir.$file;
  299. $module = new $classname($db,$specimenthirdparty);
  300. if (method_exists($module,'info')) print $module->info($langs);
  301. else print $module->description;
  302. print "</td>\n";
  303. // Active
  304. if (in_array($name, $def))
  305. {
  306. print '<td align="center">'."\n";
  307. //if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF != "$name")
  308. //{
  309. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  310. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">';
  311. print img_picto($langs->trans("Enabled"),'switch_on');
  312. print '</a>';
  313. /*}
  314. else
  315. {
  316. print img_picto($langs->trans("Enabled"),'switch_on');
  317. }*/
  318. print "</td>";
  319. }
  320. else
  321. {
  322. print '<td align="center">'."\n";
  323. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  324. print "</td>";
  325. }
  326. // Default
  327. print '<td align="center">';
  328. if ($conf->global->SUPPLIER_PAYMENT_ADDON_PDF == "$name")
  329. {
  330. //print img_picto($langs->trans("Default"),'on');
  331. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  332. print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  333. }
  334. else
  335. {
  336. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=SUPPLIER_PAYMENT"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  337. }
  338. print '</td>';
  339. // Info
  340. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  341. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  342. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  343. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  344. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  345. print '<td align="center">';
  346. print $form->textwithpicto('',$htmltooltip,1,0);
  347. print '</td>';
  348. print '<td align="center">';
  349. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
  350. print '</td>';
  351. print "</tr>\n";
  352. }
  353. }
  354. closedir($handle);
  355. }
  356. }
  357. }
  358. print '</table>';
  359. dol_fiche_end();
  360. // End of page
  361. llxFooter();
  362. $db->close();