workflow.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  28. // security check
  29. if (!$user->admin) {
  30. accessforbidden();
  31. }
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("admin", "workflow", "propal", "workflow", "orders", "supplier_proposal", "receptions", "errors", 'sendings'));
  34. $action = GETPOST('action', 'aZ09');
  35. /*
  36. * Actions
  37. */
  38. if (preg_match('/set(.*)/', $action, $reg)) {
  39. if (!dolibarr_set_const($db, $reg[1], '1', 'chaine', 0, '', $conf->entity) > 0) {
  40. dol_print_error($db);
  41. }
  42. }
  43. if (preg_match('/del(.*)/', $action, $reg)) {
  44. if (!dolibarr_set_const($db, $reg[1], '0', 'chaine', 0, '', $conf->entity) > 0) {
  45. dol_print_error($db);
  46. }
  47. }
  48. // List of workflow we can enable
  49. clearstatcache();
  50. $workflowcodes = array(
  51. // Automatic creation
  52. 'WORKFLOW_PROPAL_AUTOCREATE_ORDER'=>array(
  53. 'family'=>'create',
  54. 'position'=>10,
  55. 'enabled'=>(isModEnabled("propal") && isModEnabled('commande')),
  56. 'picto'=>'order'
  57. ),
  58. 'WORKFLOW_ORDER_AUTOCREATE_INVOICE'=>array(
  59. 'family'=>'create',
  60. 'position'=>20,
  61. 'enabled'=>(isModEnabled('commande') && isModEnabled('facture')),
  62. 'picto'=>'bill'
  63. ),
  64. 'WORKFLOW_TICKET_CREATE_INTERVENTION' => array (
  65. 'family'=>'create',
  66. 'position'=>25,
  67. 'enabled'=>(isModEnabled('ticket') && isModEnabled('ficheinter')),
  68. 'picto'=>'ticket'
  69. ),
  70. 'separator1'=>array('family'=>'separator', 'position'=>25, 'title'=>'', 'enabled'=>((isModEnabled("propal") && isModEnabled('commande')) || (isModEnabled('commande') && isModEnabled('facture')) || (isModEnabled('ticket') && isModEnabled('ficheinter')))),
  71. // Automatic classification of proposal
  72. 'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL'=>array(
  73. 'family'=>'classify_proposal',
  74. 'position'=>30,
  75. 'enabled'=>(isModEnabled("propal") && isModEnabled('commande')),
  76. 'picto'=>'propal',
  77. 'warning'=>''
  78. ),
  79. 'WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL'=>array(
  80. 'family'=>'classify_proposal',
  81. 'position'=>31,
  82. 'enabled'=>(isModEnabled("propal") && isModEnabled('facture')),
  83. 'picto'=>'propal',
  84. 'warning'=>''
  85. ),
  86. // Automatic classification of order
  87. 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array( // when shipping validated
  88. 'family'=>'classify_order',
  89. 'position'=>40,
  90. 'enabled'=>(isModEnabled("expedition") && isModEnabled('commande')),
  91. 'picto'=>'order'
  92. ),
  93. 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED'=>array( // when shipping closed
  94. 'family'=>'classify_order',
  95. 'position'=>41,
  96. 'enabled'=>(isModEnabled("expedition") && isModEnabled('commande')),
  97. 'picto'=>'order'
  98. ),
  99. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array(
  100. 'family'=>'classify_order',
  101. 'position'=>42,
  102. 'enabled'=>(isModEnabled('facture') && isModEnabled('commande')),
  103. 'picto'=>'order',
  104. 'warning'=>''
  105. ), // For this option, if module invoice is disabled, it does not exists, so "Classify billed" for order must be done manually from order card.
  106. // Automatic classification supplier proposal
  107. 'WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL'=>array(
  108. 'family'=>'classify_supplier_proposal',
  109. 'position'=>60,
  110. 'enabled'=>(isModEnabled('supplier_proposal') && (isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))),
  111. 'picto'=>'supplier_proposal',
  112. 'warning'=>''
  113. ),
  114. // Automatic classification supplier order
  115. 'WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION'=>array(
  116. 'family'=>'classify_supplier_order',
  117. 'position'=>63,
  118. 'enabled'=>(getDolGlobalString('MAIN_FEATURES_LEVEL') && isModEnabled("reception") && isModEnabled('supplier_order')),
  119. 'picto'=>'supplier_order',
  120. 'warning'=>''
  121. ),
  122. 'WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION_CLOSED'=>array(
  123. 'family'=>'classify_supplier_order',
  124. 'position'=>64,
  125. 'enabled'=>(getDolGlobalString('MAIN_FEATURES_LEVEL') && isModEnabled("reception") && isModEnabled('supplier_order')),
  126. 'picto'=>'supplier_order',
  127. 'warning'=>''
  128. ),
  129. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER'=>array(
  130. 'family'=>'classify_supplier_order',
  131. 'position'=>65,
  132. 'enabled'=>(isModEnabled("supplier_order") || isModEnabled("supplier_invoice")),
  133. 'picto'=>'supplier_order',
  134. 'warning'=>''
  135. ),
  136. // Automatic classification shipping
  137. /* Replaced by next option
  138. 'WORKFLOW_SHIPPING_CLASSIFY_CLOSED_INVOICE' => array(
  139. 'family' => 'classify_shipping',
  140. 'position' => 90,
  141. 'enabled' => isModEnabled("expedition") && isModEnabled("facture"),
  142. 'picto' => 'shipment',
  143. 'deprecated' => 1
  144. ),
  145. */
  146. 'WORKFLOW_SHIPPING_CLASSIFY_BILLED_INVOICE' => array(
  147. 'family' => 'classify_shipping',
  148. 'position' => 91,
  149. 'enabled' => isModEnabled("expedition") && isModEnabled("facture") && getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT') !== '0',
  150. 'picto' => 'shipment'
  151. ),
  152. // Automatic classification reception
  153. /*
  154. 'WORKFLOW_RECEPTION_CLASSIFY_CLOSED_INVOICE'=>array(
  155. 'family'=>'classify_reception',
  156. 'position'=>95,
  157. 'enabled'=>(isModEnabled("reception") && (isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))),
  158. 'picto'=>'reception'
  159. ),
  160. */
  161. 'WORKFLOW_RECEPTION_CLASSIFY_BILLED_INVOICE' => array(
  162. 'family' => 'classify_reception',
  163. 'position' => 91,
  164. 'enabled' => isModEnabled("reception") && isModEnabled("supplier_invoice") && getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0',
  165. 'picto' => 'shipment'
  166. ),
  167. 'separator2'=>array('family'=>'separator', 'position'=>400, 'enabled' => (isModEnabled('ticket') && isModEnabled('contract'))),
  168. // Automatic link ticket -> contract
  169. 'WORKFLOW_TICKET_LINK_CONTRACT' => array(
  170. 'family' => 'link_ticket',
  171. 'position' => 500,
  172. 'enabled' => (isModEnabled('ticket') && isModEnabled('contract')),
  173. 'picto' => 'ticket'
  174. ),
  175. 'WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS' => array(
  176. 'family' => 'link_ticket',
  177. 'position' => 501,
  178. 'enabled' => (isModEnabled('ticket') && isModEnabled('contract')),
  179. 'picto' => 'ticket'
  180. ),
  181. );
  182. if (!empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow'])) {
  183. foreach ($conf->modules_parts['workflow'] as $workflow) {
  184. $workflowcodes = array_merge($workflowcodes, $workflow);
  185. }
  186. }
  187. // remove not available workflows (based on activated modules and global defined keys)
  188. $workflowcodes = array_filter($workflowcodes, function ($var) {
  189. return $var['enabled'];
  190. });
  191. /*
  192. * View
  193. */
  194. llxHeader('', $langs->trans("WorkflowSetup"), "EN:Module_Workflow_En|FR:Module_Workflow|ES:Módulo_Workflow");
  195. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  196. print load_fiche_titre($langs->trans("WorkflowSetup"), $linkback, 'title_setup');
  197. print '<span class="opacitymedium">'.$langs->trans("WorkflowDesc").'</span>';
  198. print '<br>';
  199. print '<br>';
  200. // current module setup don't support any automatic workflow of this module
  201. if (count($workflowcodes) < 1) {
  202. print $langs->trans("ThereIsNoWorkflowToModify");
  203. llxFooter();
  204. $db->close();
  205. return;
  206. }
  207. // Sort on position
  208. $workflowcodes = dol_sort_array($workflowcodes, 'position');
  209. print '<table class="noborder centpercent">';
  210. $oldfamily = '';
  211. foreach ($workflowcodes as $key => $params) {
  212. if ($params['family'] == 'separator') {
  213. print '</table>';
  214. print '<br>';
  215. print '<table class="noborder centpercent">';
  216. continue;
  217. }
  218. $reg = array();
  219. if ($oldfamily != $params['family']) {
  220. if ($params['family'] == 'create') {
  221. $header = $langs->trans("AutomaticCreation");
  222. } elseif (preg_match('/classify_(.*)/', $params['family'], $reg)) {
  223. $header = $langs->trans("AutomaticClassification");
  224. if ($reg[1] == 'proposal') {
  225. $header .= ' - '.$langs->trans('Proposal');
  226. }
  227. if ($reg[1] == 'order') {
  228. $header .= ' - '.$langs->trans('Order');
  229. }
  230. if ($reg[1] == 'supplier_proposal') {
  231. $header .= ' - '.$langs->trans('SupplierProposal');
  232. }
  233. if ($reg[1] == 'supplier_order') {
  234. $header .= ' - '.$langs->trans('SupplierOrder');
  235. }
  236. if ($reg[1] == 'reception') {
  237. $header .= ' - '.$langs->trans('Reception');
  238. }
  239. if ($reg[1] == 'shipping') {
  240. $header .= ' - '.$langs->trans('Shipment');
  241. }
  242. } elseif (preg_match('/link_(.*)/', $params['family'], $reg)) {
  243. $header = $langs->trans("AutomaticLinking");
  244. if ($reg[1] == 'ticket') {
  245. $header .= ' - '.$langs->trans('Ticket');
  246. }
  247. } else {
  248. $header = $langs->trans("Description");
  249. }
  250. print '<tr class="liste_titre">';
  251. print '<th>'.$header.'</th>';
  252. print '<th class="right">'.$langs->trans("Status").'</th>';
  253. print '</tr>';
  254. $oldfamily = $params['family'];
  255. }
  256. print '<tr class="oddeven">';
  257. print '<td>';
  258. print img_object('', $params['picto'], 'class="pictofixedwidth"');
  259. print ' '.$langs->trans('desc'.$key);
  260. if (!empty($params['warning'])) {
  261. print ' '.img_warning($langs->transnoentitiesnoconv($params['warning']));
  262. }
  263. if (!empty($params['deprecated'])) {
  264. print ' '.img_warning($langs->transnoentitiesnoconv("Deprecated"));
  265. }
  266. print '</td>';
  267. print '<td class="right">';
  268. if (!empty($conf->use_javascript_ajax)) {
  269. print ajax_constantonoff($key);
  270. } else {
  271. if (!empty($conf->global->$key)) {
  272. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'&token='.newToken().'">';
  273. print img_picto($langs->trans("Activated"), 'switch_on');
  274. print '</a>';
  275. } else {
  276. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=set'.$key.'&token='.newToken().'">';
  277. print img_picto($langs->trans("Disabled"), 'switch_off');
  278. print '</a>';
  279. }
  280. }
  281. print '</td>';
  282. print '</tr>';
  283. }
  284. print '</table>';
  285. // End of page
  286. llxFooter();
  287. $db->close();