workflow.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2005-2021 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/workflow.php
  22. * \ingroup company
  23. * \brief Workflows setup page
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. // security check
  28. if (!$user->admin) {
  29. accessforbidden();
  30. }
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("admin", "workflow", "propal", "workflow", "orders", "supplier_proposal", "receptions", "errors", 'sendings'));
  33. $action = GETPOST('action', 'aZ09');
  34. /*
  35. * Actions
  36. */
  37. if (preg_match('/set(.*)/', $action, $reg)) {
  38. if (!dolibarr_set_const($db, $reg[1], '1', 'chaine', 0, '', $conf->entity) > 0) {
  39. dol_print_error($db);
  40. }
  41. }
  42. if (preg_match('/del(.*)/', $action, $reg)) {
  43. if (!dolibarr_set_const($db, $reg[1], '0', 'chaine', 0, '', $conf->entity) > 0) {
  44. dol_print_error($db);
  45. }
  46. }
  47. // List of workflow we can enable
  48. clearstatcache();
  49. $workflowcodes = array(
  50. // Automatic creation
  51. 'WORKFLOW_PROPAL_AUTOCREATE_ORDER'=>array(
  52. 'family'=>'create',
  53. 'position'=>10,
  54. 'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
  55. 'picto'=>'order'
  56. ),
  57. 'WORKFLOW_PROPAL_AUTOCREATE_ORDER_IFNOTEXISTS'=>array(
  58. 'family'=>'create',
  59. 'position'=>11,
  60. 'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
  61. 'picto'=>'order'
  62. ),
  63. 'WORKFLOW_ORDER_AUTOCREATE_INVOICE'=>array(
  64. 'family'=>'create',
  65. 'position'=>20,
  66. 'enabled'=>(!empty($conf->commande->enabled) && isModEnabled('facture')),
  67. 'picto'=>'bill'
  68. ),
  69. 'WORKFLOW_TICKET_CREATE_INTERVENTION' => array (
  70. 'family'=>'create',
  71. 'position'=>25,
  72. 'enabled'=>(!empty($conf->ticket->enabled) && !empty($conf->ficheinter->enabled)),
  73. 'picto'=>'ticket'
  74. ),
  75. 'separator1'=>array('family'=>'separator', 'position'=>25, 'title'=>''),
  76. // Automatic classification of proposal
  77. 'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL'=>array(
  78. 'family'=>'classify_proposal',
  79. 'position'=>30,
  80. 'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
  81. 'picto'=>'propal',
  82. 'warning'=>''
  83. ),
  84. 'WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL'=>array(
  85. 'family'=>'classify_proposal',
  86. 'position'=>31,
  87. 'enabled'=>(!empty($conf->propal->enabled) && isModEnabled('facture')),
  88. 'picto'=>'propal',
  89. 'warning'=>''
  90. ),
  91. // Automatic classification of order
  92. 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array( // when shipping validated
  93. 'family'=>'classify_order',
  94. 'position'=>40,
  95. 'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)),
  96. 'picto'=>'order'
  97. ),
  98. 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED'=>array( // when shipping closed
  99. 'family'=>'classify_order',
  100. 'position'=>41,
  101. 'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)),
  102. 'picto'=>'order'
  103. ),
  104. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array(
  105. 'family'=>'classify_order',
  106. 'position'=>42,
  107. 'enabled'=>(isModEnabled('facture') && !empty($conf->commande->enabled)),
  108. 'picto'=>'order',
  109. 'warning'=>''
  110. ), // For this option, if module invoice is disabled, it does not exists, so "Classify billed" for order must be done manually from order card.
  111. 'separator2'=>array('family'=>'separator', 'position'=>50),
  112. // Automatic classification supplier proposal
  113. 'WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL'=>array(
  114. 'family'=>'classify_supplier_proposal',
  115. 'position'=>60,
  116. 'enabled'=>(!empty($conf->supplier_proposal->enabled) && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))),
  117. 'picto'=>'supplier_proposal',
  118. 'warning'=>''
  119. ),
  120. // Automatic classification supplier order
  121. 'WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION'=>array(
  122. 'family'=>'classify_supplier_order',
  123. 'position'=>63,
  124. 'enabled'=>(!empty($conf->global->MAIN_FEATURES_LEVEL) && (!empty($conf->reception->enabled)) && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || empty($conf->supplier_order->enabled))),
  125. 'picto'=>'supplier_order',
  126. 'warning'=>''
  127. ),
  128. 'WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION_CLOSED'=>array(
  129. 'family'=>'classify_supplier_order',
  130. 'position'=>64,
  131. 'enabled'=>(!empty($conf->global->MAIN_FEATURES_LEVEL) && (!empty($conf->reception->enabled)) && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || empty($conf->supplier_order->enabled))),
  132. 'picto'=>'supplier_order',
  133. 'warning'=>''
  134. ),
  135. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER'=>array(
  136. 'family'=>'classify_supplier_order',
  137. 'position'=>65,
  138. 'enabled'=>((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)),
  139. 'picto'=>'supplier_order',
  140. 'warning'=>''
  141. ),
  142. // Automatic classification reception
  143. 'WORKFLOW_BILL_ON_RECEPTION'=>array(
  144. 'family'=>'classify_reception',
  145. 'position'=>80,
  146. 'enabled'=>(!empty($conf->reception->enabled) && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))),
  147. 'picto'=>'reception'
  148. ),
  149. // Automatic classification shipping
  150. 'WORKFLOW_SHIPPING_CLASSIFY_CLOSED_INVOICE' => array(
  151. 'family' => 'classify_shipping',
  152. 'position' => 90,
  153. 'enabled' => !empty($conf->expedition->enabled) && !empty($conf->facture->enabled),
  154. 'picto' => 'shipment'
  155. ),
  156. // Automatic link ticket -> contract
  157. 'WORKFLOW_TICKET_LINK_CONTRACT' => array(
  158. 'family' => 'link_ticket',
  159. 'position' => 75,
  160. 'enabled' => !empty($conf->ticket->enabled) && !empty($conf->contract->enabled),
  161. 'picto' => 'ticket'
  162. ),
  163. 'WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS' => array(
  164. 'family' => 'link_ticket',
  165. 'position' => 76,
  166. 'enabled' => !empty($conf->ticket->enabled) && !empty($conf->contract->enabled),
  167. 'picto' => 'ticket'
  168. ),
  169. );
  170. if (!empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow'])) {
  171. foreach ($conf->modules_parts['workflow'] as $workflow) {
  172. $workflowcodes = array_merge($workflowcodes, $workflow);
  173. }
  174. }
  175. // remove not available workflows (based on activated modules and global defined keys)
  176. $workflowcodes = array_filter($workflowcodes, function ($var) {
  177. return $var['enabled'];
  178. });
  179. /*
  180. * View
  181. */
  182. llxHeader('', $langs->trans("WorkflowSetup"), "EN:Module_Workflow_En|FR:Module_Workflow|ES:Módulo_Workflow");
  183. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  184. print load_fiche_titre($langs->trans("WorkflowSetup"), $linkback, 'title_setup');
  185. print '<span class="opacitymedium">'.$langs->trans("WorkflowDesc").'</span>';
  186. print '<br>';
  187. print '<br>';
  188. // current module setup don't support any automatic workflow of this module
  189. if (count($workflowcodes) < 1) {
  190. print $langs->trans("ThereIsNoWorkflowToModify");
  191. llxFooter();
  192. $db->close();
  193. return;
  194. }
  195. // Sort on position
  196. $workflowcodes = dol_sort_array($workflowcodes, 'position');
  197. print '<table class="noborder centpercent">';
  198. $oldfamily = '';
  199. foreach ($workflowcodes as $key => $params) {
  200. if ($params['family'] == 'separator') {
  201. print '</table>';
  202. print '<br>';
  203. print '<table class="noborder centpercent">';
  204. continue;
  205. }
  206. if ($oldfamily != $params['family']) {
  207. if ($params['family'] == 'create') {
  208. $header = $langs->trans("AutomaticCreation");
  209. } elseif (preg_match('/classify_(.*)/', $params['family'], $reg)) {
  210. $header = $langs->trans("AutomaticClassification");
  211. if ($reg[1] == 'proposal') {
  212. $header .= ' - '.$langs->trans('Proposal');
  213. }
  214. if ($reg[1] == 'order') {
  215. $header .= ' - '.$langs->trans('Order');
  216. }
  217. if ($reg[1] == 'supplier_proposal') {
  218. $header .= ' - '.$langs->trans('SupplierProposal');
  219. }
  220. if ($reg[1] == 'supplier_order') {
  221. $header .= ' - '.$langs->trans('SupplierOrder');
  222. }
  223. if ($reg[1] == 'reception') {
  224. $header .= ' - '.$langs->trans('Reception');
  225. }
  226. if ($reg[1] == 'shipping') {
  227. $header .= ' - '.$langs->trans('Shipment');
  228. }
  229. } elseif (preg_match('/link_(.*)/', $params['family'], $reg)) {
  230. $header = $langs->trans("AutomaticLinking");
  231. if ($reg[1] == 'ticket') {
  232. $header .= ' - '.$langs->trans('Ticket');
  233. }
  234. } else {
  235. $header = $langs->trans("Description");
  236. }
  237. print '<tr class="liste_titre">';
  238. print '<th>'.$header.'</th>';
  239. print '<th align="center">'.$langs->trans("Status").'</th>';
  240. print '</tr>';
  241. $oldfamily = $params['family'];
  242. }
  243. print '<tr class="oddeven">';
  244. print '<td>';
  245. print img_object('', $params['picto'], 'class="pictofixedwidth"');
  246. print ' '.$langs->trans('desc'.$key);
  247. if (!empty($params['warning'])) {
  248. print ' '.img_warning($langs->transnoentitiesnoconv($params['warning']));
  249. }
  250. print '</td>';
  251. print '<td class="center">';
  252. if (!empty($conf->use_javascript_ajax)) {
  253. print ajax_constantonoff($key);
  254. } else {
  255. if (!empty($conf->global->$key)) {
  256. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'&token='.newToken().'">';
  257. print img_picto($langs->trans("Activated"), 'switch_on');
  258. print '</a>';
  259. } else {
  260. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=set'.$key.'&token='.newToken().'">';
  261. print img_picto($langs->trans("Disabled"), 'switch_off');
  262. print '</a>';
  263. }
  264. }
  265. print '</td>';
  266. print '</tr>';
  267. }
  268. print '</table>';
  269. // End of page
  270. llxFooter();
  271. $db->close();