supplier_invoice.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  7. * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/admin/supplier_invoice.php
  25. * \ingroup fournisseur
  26. * \brief Setup to admin supplier invoices
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("admin", "other", "orders"));
  37. $action = GETPOST('action', 'aZ09');
  38. $type = GETPOST('type', 'alpha');
  39. $value = GETPOST('value', 'alpha');
  40. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  41. $label = GETPOST('label', 'alpha');
  42. $scandir = GETPOST('scan_dir', 'alpha');
  43. $specimenthirdparty = new Societe($db);
  44. $specimenthirdparty->initAsSpecimen();
  45. $error = 0;
  46. if (!$user->admin) {
  47. accessforbidden();
  48. }
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'updateMask') {
  53. $maskconstinvoice = GETPOST('maskconstinvoice', 'aZ09');
  54. $maskconstcredit = GETPOST('maskconstcredit', 'aZ09');
  55. $maskconstdeposit = GETPOST('maskconstdeposit', 'aZ09');
  56. $maskinvoice = GETPOST('maskinvoice', 'alpha');
  57. $maskcredit = GETPOST('maskcredit', 'alpha');
  58. $maskdeposit = GETPOST('maskdeposit', 'alpha');
  59. if ($maskconstinvoice && preg_match('/_MASK$/', $maskconstinvoice)) {
  60. $res = dolibarr_set_const($db, $maskconstinvoice, $maskinvoice, 'chaine', 0, '', $conf->entity);
  61. }
  62. if ($maskconstcredit && preg_match('/_MASK$/', $maskconstcredit)) {
  63. $res = dolibarr_set_const($db, $maskconstcredit, $maskcredit, 'chaine', 0, '', $conf->entity);
  64. }
  65. if ($maskconstdeposit && preg_match('/_MASK$/', $maskconstdeposit)) {
  66. $res = dolibarr_set_const($db, $maskconstdeposit, $maskdeposit, 'chaine', 0, '', $conf->entity);
  67. }
  68. if (!($res > 0)) {
  69. $error++;
  70. }
  71. if (!$error) {
  72. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  73. } else {
  74. setEventMessages($langs->trans("Error"), null, 'errors');
  75. }
  76. }
  77. if ($action == 'specimen') { // For invoices
  78. $modele = GETPOST('module', 'alpha');
  79. $facture = new FactureFournisseur($db);
  80. $facture->initAsSpecimen();
  81. $facture->thirdparty = $specimenthirdparty; // Define who should has build the invoice (so the supplier)
  82. // Search template files
  83. $file = '';
  84. $classname = '';
  85. $filefound = 0;
  86. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  87. foreach ($dirmodels as $reldir) {
  88. $file = dol_buildpath($reldir."core/modules/supplier_invoice/doc/pdf_".$modele.".modules.php", 0);
  89. if (file_exists($file)) {
  90. $filefound = 1;
  91. $classname = "pdf_".$modele;
  92. break;
  93. }
  94. }
  95. if ($filefound) {
  96. require_once $file;
  97. $module = new $classname($db, $facture);
  98. if ($module->write_file($facture, $langs) > 0) {
  99. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture_fournisseur&file=SPECIMEN.pdf");
  100. return;
  101. } else {
  102. setEventMessages($module->error, $module->errors, 'errors');
  103. dol_syslog($module->error, LOG_ERR);
  104. }
  105. } else {
  106. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  107. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  108. }
  109. } elseif ($action == 'set') {
  110. // Activate a model
  111. $ret = addDocumentModel($value, $type, $label, $scandir);
  112. } elseif ($action == 'del') {
  113. $ret = delDocumentModel($value, $type);
  114. if ($ret > 0) {
  115. if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$value") {
  116. dolibarr_del_const($db, 'INVOICE_SUPPLIER_ADDON_PDF', $conf->entity);
  117. }
  118. }
  119. } elseif ($action == 'setdoc') {
  120. // Set default model
  121. if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  122. // La constante qui a ete lue en avant du nouveau set
  123. // on passe donc par une variable pour avoir un affichage coherent
  124. $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value;
  125. }
  126. // On active le modele
  127. $ret = delDocumentModel($value, $type);
  128. if ($ret > 0) {
  129. $ret = addDocumentModel($value, $type, $label, $scandir);
  130. }
  131. } elseif ($action == 'unsetdoc') {
  132. dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity);
  133. }
  134. if ($action == 'setmod') {
  135. // TODO Verifier si module numerotation choisi peut etre active
  136. // par appel methode canBeActivated
  137. dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
  138. }
  139. if ($action == 'addcat') {
  140. $fourn = new Fournisseur($db);
  141. $fourn->CreateCategory($user, GETPOST('cat', 'alphanohtml'));
  142. }
  143. if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT') {
  144. $freetext = GETPOST('SUPPLIER_INVOICE_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
  145. $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
  146. if (!($res > 0)) {
  147. $error++;
  148. }
  149. if (!$error) {
  150. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  151. } else {
  152. setEventMessages($langs->trans("Error"), null, 'errors');
  153. }
  154. }
  155. /*
  156. * View
  157. */
  158. $form = new Form($db);
  159. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  160. llxHeader("", "");
  161. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  162. print load_fiche_titre($langs->trans("SuppliersSetup"), $linkback, 'title_setup');
  163. print "<br>";
  164. $head = supplierorder_admin_prepare_head();
  165. print dol_get_fiche_head($head, 'invoice', $langs->trans("Suppliers"), -1, 'company');
  166. // Supplier invoice numbering module
  167. print load_fiche_titre($langs->trans("SuppliersInvoiceNumberingModel"), '', '');
  168. print '<div class="div-table-responsive-no-min">';
  169. print '<table class="noborder centpercent">';
  170. print '<tr class="liste_titre">';
  171. print '<td width="100">'.$langs->trans("Name").'</td>';
  172. print '<td>'.$langs->trans("Description").'</td>';
  173. print '<td>'.$langs->trans("Example").'</td>';
  174. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  175. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  176. print "</tr>\n";
  177. clearstatcache();
  178. foreach ($dirmodels as $reldir) {
  179. $dir = dol_buildpath($reldir."core/modules/supplier_invoice");
  180. if (is_dir($dir)) {
  181. $handle = opendir($dir);
  182. if (is_resource($handle)) {
  183. while (($file = readdir($handle)) !== false) {
  184. if (substr($file, 0, 24) == 'mod_facture_fournisseur_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  185. $file = substr($file, 0, dol_strlen($file) - 4);
  186. require_once $dir.'/'.$file.'.php';
  187. $module = new $file;
  188. if ($module->isEnabled()) {
  189. // Show modules according to features level
  190. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  191. continue;
  192. }
  193. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  194. continue;
  195. }
  196. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  197. print $module->info();
  198. print '</td>';
  199. // Show example of numbering module
  200. print '<td class="nowrap">';
  201. $tmp = $module->getExample();
  202. if (preg_match('/^Error/', $tmp)) {
  203. $langs->load("errors");
  204. print '<div class="error">'.$langs->trans($tmp).'</div>';
  205. } elseif ($tmp == 'NotConfigured') {
  206. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  207. } else {
  208. print $tmp;
  209. }
  210. print '</td>'."\n";
  211. print '<td class="center">';
  212. if ($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER == "$file") {
  213. print img_picto($langs->trans("Activated"), 'switch_on');
  214. } else {
  215. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  216. }
  217. print '</td>';
  218. $invoice = new FactureFournisseur($db);
  219. $invoice->initAsSpecimen();
  220. // Info
  221. $htmltooltip = '';
  222. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  223. $nextval = $module->getNextValue($mysoc, $invoice);
  224. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  225. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  226. if ($nextval) {
  227. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  228. $nextval = $langs->trans($nextval);
  229. }
  230. $htmltooltip .= $nextval.'<br>';
  231. } else {
  232. $htmltooltip .= $langs->trans($module->error).'<br>';
  233. }
  234. }
  235. print '<td class="center">';
  236. print $form->textwithpicto('', $htmltooltip, 1, 0);
  237. print '</td>';
  238. print '</tr>';
  239. }
  240. }
  241. }
  242. closedir($handle);
  243. }
  244. }
  245. }
  246. print '</table></div><br>';
  247. /*
  248. * Documents models for supplier invoices
  249. */
  250. print load_fiche_titre($langs->trans("BillsPDFModules"), '', '');
  251. // Defini tableau def de modele
  252. $def = array();
  253. $sql = "SELECT nom";
  254. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  255. $sql .= " WHERE type = 'invoice_supplier'";
  256. $sql .= " AND entity = ".$conf->entity;
  257. $resql = $db->query($sql);
  258. if ($resql) {
  259. $i = 0;
  260. $num_rows = $db->num_rows($resql);
  261. while ($i < $num_rows) {
  262. $array = $db->fetch_array($resql);
  263. array_push($def, $array[0]);
  264. $i++;
  265. }
  266. } else {
  267. dol_print_error($db);
  268. }
  269. print '<div class="div-table-responsive-no-min">';
  270. print '<table class="noborder centpercent">'."\n";
  271. print '<tr class="liste_titre">'."\n";
  272. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  273. print '<td>'.$langs->trans("Description").'</td>'."\n";
  274. print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  275. print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  276. print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  277. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  278. print '</tr>'."\n";
  279. clearstatcache();
  280. foreach ($dirmodels as $reldir) {
  281. $realpath = $reldir."core/modules/supplier_invoice/doc";
  282. $dir = dol_buildpath($realpath);
  283. if (is_dir($dir)) {
  284. $handle = opendir($dir);
  285. if (is_resource($handle)) {
  286. while (($file = readdir($handle)) !== false) {
  287. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  288. $name = substr($file, 4, dol_strlen($file) - 16);
  289. $classname = substr($file, 0, dol_strlen($file) - 12);
  290. require_once $dir.'/'.$file;
  291. $module = new $classname($db, new FactureFournisseur($db));
  292. print "<tr class=\"oddeven\">\n";
  293. print "<td>";
  294. print (empty($module->name) ? $name : $module->name);
  295. print "</td>\n";
  296. print "<td>\n";
  297. require_once $dir.'/'.$file;
  298. $module = new $classname($db, $specimenthirdparty);
  299. if (method_exists($module, 'info')) {
  300. print $module->info($langs);
  301. } else {
  302. print $module->description;
  303. }
  304. print "</td>\n";
  305. // Active
  306. if (in_array($name, $def)) {
  307. print '<td class="center">'."\n";
  308. //if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name")
  309. //{
  310. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  311. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&amp;type=invoice_supplier">';
  312. print img_picto($langs->trans("Enabled"), 'switch_on');
  313. print '</a>';
  314. /*}
  315. else
  316. {
  317. print img_picto($langs->trans("Enabled"),'switch_on');
  318. }*/
  319. print "</td>";
  320. } else {
  321. print '<td class="center">'."\n";
  322. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&amp;type=invoice_supplier">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  323. print "</td>";
  324. }
  325. // Default
  326. print '<td class="center">';
  327. if (getDolGlobalString("INVOICE_SUPPLIER_ADDON_PDF") == "$name") {
  328. //print img_picto($langs->trans("Default"),'on');
  329. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  330. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=invoice_supplier"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  331. } else {
  332. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=invoice_supplier"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  333. }
  334. print '</td>';
  335. // Info
  336. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  337. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  338. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  339. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  340. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  341. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  342. $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
  343. $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
  344. print '<td class="center">';
  345. print $form->textwithpicto('', $htmltooltip, 1, 0);
  346. print '</td>';
  347. print '<td class="center">';
  348. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($name).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  349. print '</td>';
  350. print "</tr>\n";
  351. }
  352. }
  353. closedir($handle);
  354. }
  355. }
  356. }
  357. print '</table></div><br>';
  358. /*
  359. * Other options
  360. */
  361. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  362. print '<input type="hidden" name="token" value="'.newToken().'">';
  363. print '<input type="hidden" name="action" value="set_SUPPLIER_INVOICE_FREE_TEXT">';
  364. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  365. print '<div class="div-table-responsive-no-min">';
  366. print '<table class="noborder centpercent">';
  367. print '<tr class="liste_titre">';
  368. print '<td>'.$langs->trans("Parameter").'</td>';
  369. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  370. print '<td width="80">&nbsp;</td>';
  371. print "</tr>\n";
  372. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  373. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  374. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  375. foreach ($substitutionarray as $key => $val) {
  376. $htmltext .= $key.'<br>';
  377. }
  378. $htmltext .= '</i>';
  379. print '<tr class="oddeven"><td colspan="2">';
  380. print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  381. $variablename = 'SUPPLIER_INVOICE_FREE_TEXT';
  382. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
  383. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
  384. } else {
  385. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  386. $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
  387. print $doleditor->Create();
  388. }
  389. print '</td><td class="right">';
  390. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  391. print "</td></tr>\n";
  392. print '</table></div><br>';
  393. print '</form>';
  394. /*
  395. * Notifications
  396. */
  397. print load_fiche_titre($langs->trans("Notifications"), '', '');
  398. print '<div class="div-table-responsive-no-min">';
  399. print '<table class="noborder centpercent">';
  400. print '<tr class="liste_titre">';
  401. print '<td>'.$langs->trans("Parameter").'</td>';
  402. print '<td align="center" width="60"></td>';
  403. print '<td width="80">&nbsp;</td>';
  404. print "</tr>\n";
  405. print '<tr class="oddeven"><td colspan="2">';
  406. print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification").'<br>';
  407. print '</td><td class="right">';
  408. print "</td></tr>\n";
  409. print '</table>';
  410. print '</div>';
  411. // End of page
  412. llxFooter();
  413. $db->close();