PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 174 lines | 94 code | 21 blank | 59 comment | 30 complexity | 8f7ca453975aa6023cb4a586cfb18187 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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_20_modWorkflow_WorkflowManager.class.php
  20. * \ingroup core
  21. * \brief Trigger file for workflows
  22. */
  23. /**
  24. * Class of triggers for workflow module
  25. */
  26. class InterfaceWorkflowManager
  27. {
  28. var $db;
  29. /**
  30. * Constructor
  31. *
  32. * @param DoliDB $db Database handler
  33. */
  34. function __construct($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. *
  46. * @return string Name of trigger file
  47. */
  48. function getName()
  49. {
  50. return $this->name;
  51. }
  52. /**
  53. * Return description of trigger file
  54. *
  55. * @return string Description of trigger file
  56. */
  57. function getDesc()
  58. {
  59. return $this->description;
  60. }
  61. /**
  62. * Return version of trigger file
  63. *
  64. * @return string Version of trigger file
  65. */
  66. function getVersion()
  67. {
  68. global $langs;
  69. $langs->load("admin");
  70. if ($this->version == 'development') return $langs->trans("Development");
  71. elseif ($this->version == 'experimental') return $langs->trans("Experimental");
  72. elseif ($this->version == 'dolibarr') return DOL_VERSION;
  73. elseif ($this->version) return $this->version;
  74. else return $langs->trans("Unknown");
  75. }
  76. /**
  77. * Function called when a Dolibarrr business event is done.
  78. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  79. *
  80. * @param string $action Event action code
  81. * @param Object $object Object
  82. * @param User $user Object user
  83. * @param Translate $langs Object langs
  84. * @param conf $conf Object conf
  85. * @return int <0 if KO, 0 if no triggered ran, >0 if OK
  86. */
  87. function run_trigger($action,$object,$user,$langs,$conf)
  88. {
  89. if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing
  90. // Proposals to order
  91. if ($action == 'PROPAL_CLOSE_SIGNED')
  92. {
  93. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  94. if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER))
  95. {
  96. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  97. $newobject = new Commande($this->db);
  98. $ret=$newobject->createFromProposal($object);
  99. if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
  100. return $ret;
  101. }
  102. }
  103. // Order to invoice
  104. if ($action == 'ORDER_CLOSE')
  105. {
  106. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  107. if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE))
  108. {
  109. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  110. $newobject = new Facture($this->db);
  111. $ret=$newobject->createFromOrder($object);
  112. if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
  113. return $ret;
  114. }
  115. }
  116. // Order classify billed proposal
  117. if ($action == 'ORDER_CLASSIFY_BILLED')
  118. {
  119. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  120. if (! empty($conf->propal->enabled) && ! empty($conf->global->WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL))
  121. {
  122. $object->fetchObjectLinked('','propal',$object->id,$object->element);
  123. if (! empty($object->linkedObjects))
  124. {
  125. foreach($object->linkedObjects['propal'] as $element)
  126. {
  127. $ret=$element->classifyBilled();
  128. }
  129. }
  130. return $ret;
  131. }
  132. }
  133. // Invoice classify billed order
  134. if ($action == 'BILL_PAYED')
  135. {
  136. dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
  137. if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER))
  138. {
  139. $object->fetchObjectLinked('','commande',$object->id,$object->element);
  140. if (! empty($object->linkedObjects))
  141. {
  142. foreach($object->linkedObjects['commande'] as $element)
  143. {
  144. $ret=$element->classifyBilled();
  145. }
  146. }
  147. return $ret;
  148. }
  149. }
  150. return 0;
  151. }
  152. }
  153. ?>