workflow.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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-2016 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 <http://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. // Load translation files required by the page
  28. $langs->loadLangs(array("admin","workflow","propal","workflow","orders","supplier_proposals"));
  29. if (! $user->admin) accessforbidden();
  30. $action = GETPOST('action', 'alpha');
  31. /*
  32. * Actions
  33. */
  34. if (preg_match('/set(.*)/',$action,$reg))
  35. {
  36. if (! dolibarr_set_const($db, $reg[1], '1', 'chaine', 0, '', $conf->entity) > 0)
  37. {
  38. dol_print_error($db);
  39. }
  40. }
  41. if (preg_match('/del(.*)/',$action,$reg))
  42. {
  43. if (! dolibarr_del_const($db, $reg[1], $conf->entity) > 0)
  44. {
  45. dol_print_error($db);
  46. }
  47. }
  48. /*
  49. * View
  50. */
  51. llxHeader('',$langs->trans("WorkflowSetup"),'');
  52. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  53. print load_fiche_titre($langs->trans("WorkflowSetup"),$linkback,'title_setup');
  54. print $langs->trans("WorkflowDesc").'<br>';
  55. print "<br>";
  56. // List of workflow we can enable
  57. clearstatcache();
  58. $workflowcodes=array(
  59. // Automatic creation
  60. 'WORKFLOW_PROPAL_AUTOCREATE_ORDER'=>array('family'=>'create', 'position'=>10, 'enabled'=>'! empty($conf->propal->enabled) && ! empty($conf->commande->enabled)', 'picto'=>'order'),
  61. 'WORKFLOW_ORDER_AUTOCREATE_INVOICE'=>array('family'=>'create', 'position'=>20, 'enabled'=>'! empty($conf->commande->enabled) && ! empty($conf->facture->enabled)', 'picto'=>'bill'),
  62. 'separator1'=>array('family'=>'separator', 'position'=>25),
  63. // Automatic classification of proposal
  64. 'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL'=>array('family'=>'classify_proposal', 'position'=>30, 'enabled'=>'! empty($conf->propal->enabled) && ! empty($conf->commande->enabled)', 'picto'=>'propal','warning'=>''),
  65. 'WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL'=>array('family'=>'classify_proposal', 'position'=>31, 'enabled'=>'! empty($conf->propal->enabled) && ! empty($conf->facture->enabled)', 'picto'=>'propal','warning'=>''),
  66. // Automatic classification of order
  67. 'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array('family'=>'classify_order', 'position'=>40, 'enabled'=>'! empty($conf->expedition->enabled) && ! empty($conf->commande->enabled)', 'picto'=>'order'),
  68. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array('family'=>'classify_order', 'position'=>41, 'enabled'=>'! empty($conf->facture->enabled) && ! empty($conf->commande->enabled)', 'picto'=>'order','warning'=>''), // For this option, if module invoice is disabled, it does not exists, so "Classify billed" for order must be done manually from order card.
  69. 'separator2'=>array('family'=>'separator', 'position'=>50),
  70. // Automatic classification supplier proposal
  71. 'WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL'=>array('family'=>'classify_supplier_proposal', 'position'=>60, 'enabled'=>'! empty($conf->supplier_proposal->enabled) && ! empty($conf->fournisseur->enabled)', 'picto'=>'propal','warning'=>''),
  72. // Automatic classification supplier order
  73. 'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER'=>array('family'=>'classify_supplier_order', 'position'=>62, 'enabled'=>'! empty($conf->fournisseur->enabled)', 'picto'=>'order','warning'=>''),
  74. );
  75. if (! empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow']))
  76. {
  77. foreach($conf->modules_parts['workflow'] as $workflow)
  78. {
  79. $workflowcodes = array_merge($workflowcodes, $workflow);
  80. }
  81. }
  82. // Sort on position
  83. $workflowcodes = dol_sort_array($workflowcodes, 'position');
  84. $nbqualified=0;
  85. $oldfamily='';
  86. print '<table class="noborder" width="100%">'."\n";
  87. foreach($workflowcodes as $key => $params)
  88. {
  89. $picto=$params['picto'];
  90. $enabled=$params['enabled'];
  91. $family=$params['family'];
  92. if ($family == 'separator')
  93. {
  94. print '</table><br>';
  95. print '<table class="noborder" width="100%">'."\n";
  96. continue;
  97. }
  98. if (! verifCond($enabled)) continue;
  99. $nbqualified++;
  100. if ($oldfamily != $family)
  101. {
  102. print '<tr class="liste_titre">'."\n";
  103. print ' <td>';
  104. if ($family == 'create')
  105. {
  106. print $langs->trans("AutomaticCreation");
  107. }
  108. elseif (preg_match('/classify_(.*)/', $family, $reg))
  109. {
  110. print $langs->trans("AutomaticClassification");
  111. if ($reg[1] == 'proposal') print ' - '.$langs->trans('Proposal');
  112. if ($reg[1] == 'order') print ' - '.$langs->trans('Order');
  113. if ($reg[1] == 'supplier_proposal') print ' - '.$langs->trans('SupplierProposal');
  114. if ($reg[1] == 'supplier_order') print ' - '.$langs->trans('SupplierOrder');
  115. }
  116. else
  117. {
  118. print $langs->trans("Description");
  119. }
  120. print '</td>';
  121. print ' <td align="center">'.$langs->trans("Status").'</td>';
  122. print "</tr>\n";
  123. $oldfamily = $family;
  124. }
  125. print "<tr class=\"oddeven\">\n";
  126. print "<td>".img_object('', $picto).$langs->trans('desc'.$key);
  127. if (! empty($params['warning']))
  128. {
  129. $langs->load("errors");
  130. print ' '.img_warning($langs->transnoentitiesnoconv($params['warning']));
  131. }
  132. print "</td>\n";
  133. print '<td align="center">';
  134. if (! empty($conf->use_javascript_ajax))
  135. {
  136. print ajax_constantonoff($key);
  137. }
  138. else
  139. {
  140. if (! empty($conf->global->$key))
  141. {
  142. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'">';
  143. print img_picto($langs->trans("Activated"),'switch_on');
  144. print '</a>';
  145. }
  146. else
  147. {
  148. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set'.$key.'">';
  149. print img_picto($langs->trans("Disabled"),'switch_off');
  150. print '</a>';
  151. }
  152. }
  153. print '</td>';
  154. print '</tr>';
  155. }
  156. if ($nbqualified == 0)
  157. {
  158. print '<tr><td colspan="3">'.$langs->trans("ThereIsNoWorkflowToModify");
  159. }
  160. print '</table>';
  161. // End of page
  162. llxFooter();
  163. $db->close();