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

/htdocs/core/triggers/interface_modWorkflow_WorkflowManager.class.php

https://github.com/asterix14/dolibarr
PHP | 134 lines | 62 code | 18 blank | 54 comment | 18 complexity | 6aca010b22f516b9f771b2661200c0bb MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  3. * Copyright (C) 2011 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 2 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/core/triggers/interface_modWorkflow_WorkflowManager.class.php
  20. * \ingroup core
  21. * \brief Trigger file for workflows
  22. */
  23. /**
  24. * \class InterfaceWorkflowManager
  25. * \brief Class of triggers for workflow module
  26. */
  27. class InterfaceWorkflowManager
  28. {
  29. var $db;
  30. /**
  31. * Constructor.
  32. * @param DB Database handler
  33. */
  34. function InterfaceWorkflowManager($DB)
  35. {
  36. $this->db = $DB ;
  37. $this->name = preg_replace('/^Interface/i','',get_class($this));
  38. $this->family = "core";
  39. $this->description = "Triggers of this module allows to manage workflows";
  40. $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version
  41. $this->picto = 'technic';
  42. }
  43. /**
  44. * Return name of trigger file
  45. * @return string Name of trigger file
  46. */
  47. function getName()
  48. {
  49. return $this->name;
  50. }
  51. /**
  52. * Return description of trigger file
  53. * @return string Description of trigger file
  54. */
  55. function getDesc()
  56. {
  57. return $this->description;
  58. }
  59. /**
  60. * Return version of trigger file
  61. * @return string Version of trigger file
  62. */
  63. function getVersion()
  64. {
  65. global $langs;
  66. $langs->load("admin");
  67. if ($this->version == 'development') return $langs->trans("Development");
  68. elseif ($this->version == 'experimental') return $langs->trans("Experimental");
  69. elseif ($this->version == 'dolibarr') return DOL_VERSION;
  70. elseif ($this->version) return $this->version;
  71. else return $langs->trans("Unknown");
  72. }
  73. /**
  74. * Function called when a Dolibarrr business event is done.
  75. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  76. *
  77. * @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
  78. * @param object Object action is done on
  79. * @param user Object user
  80. * @param langs Object langs
  81. * @param conf Object conf
  82. * @return int <0 if KO, 0 if no action are done, >0 if OK
  83. */
  84. function run_trigger($action,$object,$user,$langs,$conf)
  85. {
  86. if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing
  87. // Proposals to order
  88. if ($action == 'PROPAL_CLOSE_SIGNED')
  89. {
  90. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  91. if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER))
  92. {
  93. include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
  94. $newobject = new Commande($this->db);
  95. $ret=$newobject->createFromProposal($object);
  96. if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
  97. return $ret;
  98. }
  99. }
  100. // Order to invoice
  101. if ($action == 'ORDER_CLOSE')
  102. {
  103. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  104. if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE))
  105. {
  106. include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
  107. $newobject = new Facture($this->db);
  108. $ret=$newobject->createFromOrder($object);
  109. if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
  110. return $ret;
  111. }
  112. }
  113. return 0;
  114. }
  115. }
  116. ?>