workflow.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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) && !empty($conf->facture->enabled)),
  67. 'picto'=>'bill'
  68. ),
  69. 'separator1'=>array('family'=>'separator', 'position'=>25, 'title'=>''),
  70. // Automatic classification of proposal
  71. 'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL'=>array(
  72. 'family'=>'classify_proposal',
  73. 'position'=>30,
  74. 'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
  75. 'picto'=>'propal',
  76. 'warning'=>''
  77. ),
  78. 'WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL'=>array(
  79. 'family'=>'classify_proposal',
  80. 'position'=>31,
  81. 'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->facture->enabled)),
  82. 'picto'=>'propal',
  83. 'warning'=>''
  84. ),
  85. // Automatic classification of order
  86. 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array(
  87. 'family'=>'classify_order',
  88. 'position'=>40,
  89. 'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)),
  90. 'picto'=>'order'
  91. ),
  92. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array(
  93. 'family'=>'classify_order',
  94. 'position'=>41,
  95. 'enabled'=>(!empty($conf->facture->enabled) && !empty($conf->commande->enabled)),
  96. 'picto'=>'order',
  97. 'warning'=>''
  98. ), // For this option, if module invoice is disabled, it does not exists, so "Classify billed" for order must be done manually from order card.
  99. 'separator2'=>array('family'=>'separator', 'position'=>50),
  100. // Automatic classification supplier proposal
  101. 'WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL'=>array(
  102. 'family'=>'classify_supplier_proposal',
  103. 'position'=>60,
  104. '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))),
  105. 'picto'=>'supplier_proposal',
  106. 'warning'=>''
  107. ),
  108. // Automatic classification supplier order
  109. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER'=>array(
  110. 'family'=>'classify_supplier_order',
  111. 'position'=>62,
  112. 'enabled'=>((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)),
  113. 'picto'=>'supplier_order',
  114. 'warning'=>''
  115. ),
  116. // Automatic classification reception
  117. 'WORKFLOW_BILL_ON_RECEPTION'=>array(
  118. 'family'=>'classify_reception',
  119. 'position'=>64,
  120. '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))),
  121. 'picto'=>'reception'
  122. ),
  123. // Automatic classification shipping
  124. 'WORKFLOW_SHIPPING_CLASSIFY_CLOSED_INVOICE' => array(
  125. 'family' => 'classify_shipping',
  126. 'position' => 66,
  127. 'enabled' => ! empty($conf->expedition->enabled) && ! empty($conf->facture->enabled),
  128. 'picto' => 'shipment'
  129. )
  130. );
  131. if (!empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow'])) {
  132. foreach ($conf->modules_parts['workflow'] as $workflow) {
  133. $workflowcodes = array_merge($workflowcodes, $workflow);
  134. }
  135. }
  136. // remove not available workflows (based on activated modules and global defined keys)
  137. $workflowcodes = array_filter($workflowcodes, function ($var) {
  138. return $var['enabled'];
  139. });
  140. /*
  141. * View
  142. */
  143. llxHeader('', $langs->trans("WorkflowSetup"), "EN:Module_Workflow_En|FR:Module_Workflow|ES:Módulo_Workflow");
  144. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  145. print load_fiche_titre($langs->trans("WorkflowSetup"), $linkback, 'title_setup');
  146. print '<span class="opacitymedium">'.$langs->trans("WorkflowDesc").'</span>';
  147. print '<br>';
  148. print '<br>';
  149. // current module setup don't support any automatic workflow of this module
  150. if (count($workflowcodes) < 1) {
  151. print $langs->trans("ThereIsNoWorkflowToModify");
  152. llxFooter();
  153. $db->close();
  154. return;
  155. }
  156. // Sort on position
  157. $workflowcodes = dol_sort_array($workflowcodes, 'position');
  158. print '<table class="noborder centpercent">';
  159. $oldfamily = '';
  160. foreach ($workflowcodes as $key => $params) {
  161. if ($params['family'] == 'separator') {
  162. print '</table>';
  163. print '<br>';
  164. print '<table class="noborder centpercent">';
  165. continue;
  166. }
  167. if ($oldfamily != $params['family']) {
  168. if ($params['family'] == 'create') {
  169. $header = $langs->trans("AutomaticCreation");
  170. } elseif (preg_match('/classify_(.*)/', $params['family'], $reg)) {
  171. $header = $langs->trans("AutomaticClassification");
  172. if ($reg[1] == 'proposal') {
  173. $header .= ' - '.$langs->trans('Proposal');
  174. }
  175. if ($reg[1] == 'order') {
  176. $header .= ' - '.$langs->trans('Order');
  177. }
  178. if ($reg[1] == 'supplier_proposal') {
  179. $header .= ' - '.$langs->trans('SupplierProposal');
  180. }
  181. if ($reg[1] == 'supplier_order') {
  182. $header .= ' - '.$langs->trans('SupplierOrder');
  183. }
  184. if ($reg[1] == 'reception') {
  185. $header .= ' - '.$langs->trans('Reception');
  186. }
  187. if ($reg[1] == 'shipping') {
  188. $header .= ' - '.$langs->trans('Shipment');
  189. }
  190. } else {
  191. $header = $langs->trans("Description");
  192. }
  193. print '<tr class="liste_titre">';
  194. print '<th>'.$header.'</th>';
  195. print '<th align="center">'.$langs->trans("Status").'</th>';
  196. print '</tr>';
  197. $oldfamily = $params['family'];
  198. }
  199. print '<tr class="oddeven">';
  200. print '<td>';
  201. print img_object('', $params['picto'], 'class="pictofixedwidth"');
  202. print ' '.$langs->trans('desc'.$key);
  203. if (!empty($params['warning'])) {
  204. print ' '.img_warning($langs->transnoentitiesnoconv($params['warning']));
  205. }
  206. print '</td>';
  207. print '<td class="center">';
  208. if (!empty($conf->use_javascript_ajax)) {
  209. print ajax_constantonoff($key);
  210. } else {
  211. if (!empty($conf->global->$key)) {
  212. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'&amp;token='.newToken().'">';
  213. print img_picto($langs->trans("Activated"), 'switch_on');
  214. print '</a>';
  215. } else {
  216. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=set'.$key.'&amp;token='.newToken().'">';
  217. print img_picto($langs->trans("Disabled"), 'switch_off');
  218. print '</a>';
  219. }
  220. }
  221. print '</td>';
  222. print '</tr>';
  223. }
  224. print '</table>';
  225. // End of page
  226. llxFooter();
  227. $db->close();