supplier_payment.php 17 KB

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