supplier_invoice.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  53. if ($action == 'updateMask') {
  54. $maskconstinvoice = GETPOST('maskconstinvoice', 'aZ09');
  55. $maskconstcredit = GETPOST('maskconstcredit', 'aZ09');
  56. $maskconstdeposit = GETPOST('maskconstdeposit', 'aZ09');
  57. $maskinvoice = GETPOST('maskinvoice', 'alpha');
  58. $maskcredit = GETPOST('maskcredit', 'alpha');
  59. $maskdeposit = GETPOST('maskdeposit', 'alpha');
  60. if ($maskconstinvoice && preg_match('/_MASK$/', $maskconstinvoice)) {
  61. $res = dolibarr_set_const($db, $maskconstinvoice, $maskinvoice, 'chaine', 0, '', $conf->entity);
  62. }
  63. if ($maskconstcredit && preg_match('/_MASK$/', $maskconstcredit)) {
  64. $res = dolibarr_set_const($db, $maskconstcredit, $maskcredit, 'chaine', 0, '', $conf->entity);
  65. }
  66. if ($maskconstdeposit && preg_match('/_MASK$/', $maskconstdeposit)) {
  67. $res = dolibarr_set_const($db, $maskconstdeposit, $maskdeposit, 'chaine', 0, '', $conf->entity);
  68. }
  69. if (!($res > 0)) {
  70. $error++;
  71. }
  72. if (!$error) {
  73. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  74. } else {
  75. setEventMessages($langs->trans("Error"), null, 'errors');
  76. }
  77. }
  78. if ($action == 'specimen') { // For invoices
  79. $modele = GETPOST('module', 'alpha');
  80. $facture = new FactureFournisseur($db);
  81. $facture->initAsSpecimen();
  82. $facture->thirdparty = $specimenthirdparty; // Define who should has build the invoice (so the supplier)
  83. // Search template files
  84. $file = '';
  85. $classname = '';
  86. $filefound = 0;
  87. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  88. foreach ($dirmodels as $reldir) {
  89. $file = dol_buildpath($reldir."core/modules/supplier_invoice/doc/pdf_".$modele.".modules.php", 0);
  90. if (file_exists($file)) {
  91. $filefound = 1;
  92. $classname = "pdf_".$modele;
  93. break;
  94. }
  95. }
  96. if ($filefound) {
  97. require_once $file;
  98. $module = new $classname($db, $facture);
  99. if ($module->write_file($facture, $langs) > 0) {
  100. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture_fournisseur&file=SPECIMEN.pdf");
  101. return;
  102. } else {
  103. setEventMessages($module->error, $module->errors, 'errors');
  104. dol_syslog($module->error, LOG_ERR);
  105. }
  106. } else {
  107. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  108. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  109. }
  110. } elseif ($action == 'set') {
  111. // Activate a model
  112. $ret = addDocumentModel($value, $type, $label, $scandir);
  113. } elseif ($action == 'del') {
  114. $ret = delDocumentModel($value, $type);
  115. if ($ret > 0) {
  116. if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$value") {
  117. dolibarr_del_const($db, 'INVOICE_SUPPLIER_ADDON_PDF', $conf->entity);
  118. }
  119. }
  120. } elseif ($action == 'setdoc') {
  121. // Set default model
  122. if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  123. // La constante qui a ete lue en avant du nouveau set
  124. // on passe donc par une variable pour avoir un affichage coherent
  125. $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value;
  126. }
  127. // On active le modele
  128. $ret = delDocumentModel($value, $type);
  129. if ($ret > 0) {
  130. $ret = addDocumentModel($value, $type, $label, $scandir);
  131. }
  132. } elseif ($action == 'unsetdoc') {
  133. dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity);
  134. }
  135. if ($action == 'setmod') {
  136. // TODO Verifier si module numerotation choisi peut etre active
  137. // par appel methode canBeActivated
  138. dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
  139. }
  140. if ($action == 'addcat') {
  141. $fourn = new Fournisseur($db);
  142. $fourn->CreateCategory($user, GETPOST('cat', 'alphanohtml'));
  143. }
  144. if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT') {
  145. $freetext = GETPOST('SUPPLIER_INVOICE_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
  146. $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
  147. if (!($res > 0)) {
  148. $error++;
  149. }
  150. if (!$error) {
  151. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  152. } else {
  153. setEventMessages($langs->trans("Error"), null, 'errors');
  154. }
  155. }
  156. /*
  157. * View
  158. */
  159. $form = new Form($db);
  160. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  161. llxHeader("", "");
  162. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  163. print load_fiche_titre($langs->trans("SuppliersSetup"), $linkback, 'title_setup');
  164. print "<br>";
  165. $head = supplierorder_admin_prepare_head();
  166. print dol_get_fiche_head($head, 'invoice', $langs->trans("Suppliers"), -1, 'company');
  167. // Supplier invoice numbering module
  168. print load_fiche_titre($langs->trans("SuppliersInvoiceNumberingModel"), '', '');
  169. print '<div class="div-table-responsive-no-min">';
  170. print '<table class="noborder centpercent">';
  171. print '<tr class="liste_titre">';
  172. print '<td width="100">'.$langs->trans("Name").'</td>';
  173. print '<td>'.$langs->trans("Description").'</td>';
  174. print '<td>'.$langs->trans("Example").'</td>';
  175. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  176. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  177. print "</tr>\n";
  178. clearstatcache();
  179. foreach ($dirmodels as $reldir) {
  180. $dir = dol_buildpath($reldir."core/modules/supplier_invoice");
  181. if (is_dir($dir)) {
  182. $handle = opendir($dir);
  183. if (is_resource($handle)) {
  184. while (($file = readdir($handle)) !== false) {
  185. if (substr($file, 0, 24) == 'mod_facture_fournisseur_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  186. $file = substr($file, 0, dol_strlen($file) - 4);
  187. require_once $dir.'/'.$file.'.php';
  188. $module = new $file;
  189. if ($module->isEnabled()) {
  190. // Show modules according to features level
  191. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  192. continue;
  193. }
  194. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  195. continue;
  196. }
  197. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  198. print $module->info($langs);
  199. print '</td>';
  200. // Show example of numbering module
  201. print '<td class="nowrap">';
  202. $tmp = $module->getExample();
  203. if (preg_match('/^Error/', $tmp)) {
  204. $langs->load("errors");
  205. print '<div class="error">'.$langs->trans($tmp).'</div>';
  206. } elseif ($tmp == 'NotConfigured') {
  207. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  208. } else {
  209. print $tmp;
  210. }
  211. print '</td>'."\n";
  212. print '<td class="center">';
  213. if ($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER == "$file") {
  214. print img_picto($langs->trans("Activated"), 'switch_on');
  215. } else {
  216. 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>';
  217. }
  218. print '</td>';
  219. $invoice = new FactureFournisseur($db);
  220. $invoice->initAsSpecimen();
  221. // Info
  222. $htmltooltip = '';
  223. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  224. $nextval = $module->getNextValue($mysoc, $invoice);
  225. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  226. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  227. if ($nextval) {
  228. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  229. $nextval = $langs->trans($nextval);
  230. }
  231. $htmltooltip .= $nextval.'<br>';
  232. } else {
  233. $htmltooltip .= $langs->trans($module->error).'<br>';
  234. }
  235. }
  236. print '<td class="center">';
  237. print $form->textwithpicto('', $htmltooltip, 1, 0);
  238. print '</td>';
  239. print '</tr>';
  240. }
  241. }
  242. }
  243. closedir($handle);
  244. }
  245. }
  246. }
  247. print '</table></div><br>';
  248. /*
  249. * Documents models for supplier invoices
  250. */
  251. print load_fiche_titre($langs->trans("BillsPDFModules"), '', '');
  252. // Defini tableau def de modele
  253. $def = array();
  254. $sql = "SELECT nom";
  255. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  256. $sql .= " WHERE type = 'invoice_supplier'";
  257. $sql .= " AND entity = ".$conf->entity;
  258. $resql = $db->query($sql);
  259. if ($resql) {
  260. $i = 0;
  261. $num_rows = $db->num_rows($resql);
  262. while ($i < $num_rows) {
  263. $array = $db->fetch_array($resql);
  264. array_push($def, $array[0]);
  265. $i++;
  266. }
  267. } else {
  268. dol_print_error($db);
  269. }
  270. print '<div class="div-table-responsive-no-min">';
  271. print '<table class="noborder centpercent">'."\n";
  272. print '<tr class="liste_titre">'."\n";
  273. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  274. print '<td>'.$langs->trans("Description").'</td>'."\n";
  275. print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  276. print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  277. print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  278. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  279. print '</tr>'."\n";
  280. clearstatcache();
  281. foreach ($dirmodels as $reldir) {
  282. $realpath = $reldir."core/modules/supplier_invoice/doc";
  283. $dir = dol_buildpath($realpath);
  284. if (is_dir($dir)) {
  285. $handle = opendir($dir);
  286. if (is_resource($handle)) {
  287. while (($file = readdir($handle)) !== false) {
  288. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  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 FactureFournisseur($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')) {
  301. print $module->info($langs);
  302. } else {
  303. print $module->description;
  304. }
  305. print "</td>\n";
  306. // Active
  307. if (in_array($name, $def)) {
  308. print '<td class="center">'."\n";
  309. //if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name")
  310. //{
  311. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  312. 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">';
  313. print img_picto($langs->trans("Enabled"), 'switch_on');
  314. print '</a>';
  315. /*}
  316. else
  317. {
  318. print img_picto($langs->trans("Enabled"),'switch_on');
  319. }*/
  320. print "</td>";
  321. } else {
  322. print '<td class="center">'."\n";
  323. 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>';
  324. print "</td>";
  325. }
  326. // Default
  327. print '<td class="center">';
  328. if (getDolGlobalString("INVOICE_SUPPLIER_ADDON_PDF") == "$name") {
  329. //print img_picto($langs->trans("Default"),'on');
  330. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  331. 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>';
  332. } else {
  333. 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>';
  334. }
  335. print '</td>';
  336. // Info
  337. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  338. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  339. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  340. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  341. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  342. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  343. $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
  344. $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
  345. print '<td class="center">';
  346. print $form->textwithpicto('', $htmltooltip, 1, 0);
  347. print '</td>';
  348. print '<td class="center">';
  349. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($name).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  350. print '</td>';
  351. print "</tr>\n";
  352. }
  353. }
  354. closedir($handle);
  355. }
  356. }
  357. }
  358. print '</table></div><br>';
  359. /*
  360. * Other options
  361. */
  362. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  363. print '<input type="hidden" name="token" value="'.newToken().'">';
  364. print '<input type="hidden" name="action" value="set_SUPPLIER_INVOICE_FREE_TEXT">';
  365. print load_fiche_titre($langs->trans("OtherOptions"), '', '');
  366. print '<div class="div-table-responsive-no-min">';
  367. print '<table class="noborder centpercent">';
  368. print '<tr class="liste_titre">';
  369. print '<td>'.$langs->trans("Parameter").'</td>';
  370. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  371. print '<td width="80">&nbsp;</td>';
  372. print "</tr>\n";
  373. $substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
  374. $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
  375. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  376. foreach ($substitutionarray as $key => $val) {
  377. $htmltext .= $key.'<br>';
  378. }
  379. $htmltext .= '</i>';
  380. print '<tr class="oddeven"><td colspan="2">';
  381. print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  382. $variablename = 'SUPPLIER_INVOICE_FREE_TEXT';
  383. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
  384. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
  385. } else {
  386. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  387. $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
  388. print $doleditor->Create();
  389. }
  390. print '</td><td class="right">';
  391. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  392. print "</td></tr>\n";
  393. print '</table></div><br>';
  394. print '</form>';
  395. /*
  396. * Notifications
  397. */
  398. print load_fiche_titre($langs->trans("Notifications"), '', '');
  399. print '<div class="div-table-responsive-no-min">';
  400. print '<table class="noborder centpercent">';
  401. print '<tr class="liste_titre">';
  402. print '<td>'.$langs->trans("Parameter").'</td>';
  403. print '<td align="center" width="60"></td>';
  404. print '<td width="80">&nbsp;</td>';
  405. print "</tr>\n";
  406. print '<tr class="oddeven"><td colspan="2">';
  407. print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification").'<br>';
  408. print '</td><td class="right">';
  409. print "</td></tr>\n";
  410. print '</table>';
  411. print '</div>';
  412. // End of page
  413. llxFooter();
  414. $db->close();