supplier_invoice.php 17 KB

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