PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php

https://github.com/asterix14/dolibarr
PHP | 123 lines | 60 code | 17 blank | 46 comment | 4 complexity | 43a68bc6961ec737487e8661634d13ec MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php
  20. * \ingroup facture fourniseur
  21. * \brief File that contain parent class for supplier invoices models
  22. */
  23. require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php");
  24. /**
  25. * \class ModelePDFSuppliersInvoices
  26. * \brief Parent class for supplier invoices models
  27. */
  28. abstract class ModelePDFSuppliersInvoices extends CommonDocGenerator
  29. {
  30. var $error='';
  31. /**
  32. * Return list of active generation modules
  33. *
  34. * @param DoliDB $db Database handler
  35. */
  36. function liste_modeles($db)
  37. {
  38. global $conf;
  39. $type='invoice_supplier';
  40. $liste=array();
  41. include_once(DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php');
  42. $liste=getListOfModels($db,$type,'');
  43. return $liste;
  44. }
  45. }
  46. /**
  47. * Create object on disk.
  48. *
  49. * @param DoliDB $db objet base de donnee
  50. * @param Object $object object supplier invoice
  51. * @param string $model force le modele a utiliser ('' to not force)
  52. * @param Translate $outputlangs objet lang a utiliser pour traduction
  53. * @return int 0 if KO, 1 if OK
  54. */
  55. function supplier_invoice_pdf_create($db, $object, $model, $outputlangs)
  56. {
  57. global $conf, $langs;
  58. $langs->load("suppliers");
  59. $dir = DOL_DOCUMENT_ROOT."/core/modules/supplier_invoice/pdf/";
  60. // Positionne modele sur le nom du modele de invoice fournisseur a utiliser
  61. if (! dol_strlen($model))
  62. {
  63. if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
  64. {
  65. $model = $conf->global->INVOICE_SUPPLIER_ADDON_PDF;
  66. }
  67. else
  68. {
  69. $model = 'canelle';
  70. //print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_PDF_NotDefined");
  71. //return 0;
  72. }
  73. }
  74. // Charge le modele
  75. $file = "pdf_".$model.".modules.php";
  76. if (file_exists($dir.$file))
  77. {
  78. $classname = "pdf_".$model;
  79. require_once($dir.$file);
  80. $obj = new $classname($db,$object);
  81. // We save charset_output to restore it because write_file can change it if needed for
  82. // output format that does not support UTF8.
  83. $sav_charset_output=$outputlangs->charset_output;
  84. if ($obj->write_file($object,$outputlangs) > 0)
  85. {
  86. $outputlangs->charset_output=$sav_charset_output;
  87. // we delete preview files
  88. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  89. dol_delete_preview($object);
  90. return 1;
  91. }
  92. else
  93. {
  94. $outputlangs->charset_output=$sav_charset_output;
  95. dol_syslog("Erreur dans supplier_invoice_pdf_create");
  96. dol_print_error($db,$obj->error);
  97. return 0;
  98. }
  99. }
  100. else
  101. {
  102. print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file);
  103. return 0;
  104. }
  105. }
  106. ?>