dolibarr  16.0.5
workflow.php
Go to the documentation of this file.
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 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 
30 // security check
31 if (!$user->admin) {
33 }
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("admin", "workflow", "propal", "workflow", "orders", "supplier_proposal", "receptions", "errors", 'sendings'));
37 
38 $action = GETPOST('action', 'aZ09');
39 
40 
41 /*
42  * Actions
43  */
44 
45 if (preg_match('/set(.*)/', $action, $reg)) {
46  if (!dolibarr_set_const($db, $reg[1], '1', 'chaine', 0, '', $conf->entity) > 0) {
47  dol_print_error($db);
48  }
49 }
50 
51 if (preg_match('/del(.*)/', $action, $reg)) {
52  if (!dolibarr_set_const($db, $reg[1], '0', 'chaine', 0, '', $conf->entity) > 0) {
53  dol_print_error($db);
54  }
55 }
56 
57 // List of workflow we can enable
58 clearstatcache();
59 
60 $workflowcodes = array(
61  // Automatic creation
62  'WORKFLOW_PROPAL_AUTOCREATE_ORDER'=>array(
63  'family'=>'create',
64  'position'=>10,
65  'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
66  'picto'=>'order'
67  ),
68  'WORKFLOW_ORDER_AUTOCREATE_INVOICE'=>array(
69  'family'=>'create',
70  'position'=>20,
71  'enabled'=>(!empty($conf->commande->enabled) && isModEnabled('facture')),
72  'picto'=>'bill'
73  ),
74  'WORKFLOW_TICKET_CREATE_INTERVENTION' => array (
75  'family'=>'create',
76  'position'=>25,
77  'enabled'=>(!empty($conf->ticket->enabled) && !empty($conf->ficheinter->enabled)),
78  'picto'=>'ticket'
79  ),
80 
81  'separator1'=>array('family'=>'separator', 'position'=>25, 'title'=>''),
82 
83  // Automatic classification of proposal
84  'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL'=>array(
85  'family'=>'classify_proposal',
86  'position'=>30,
87  'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
88  'picto'=>'propal',
89  'warning'=>''
90  ),
91  'WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL'=>array(
92  'family'=>'classify_proposal',
93  'position'=>31,
94  'enabled'=>(!empty($conf->propal->enabled) && isModEnabled('facture')),
95  'picto'=>'propal',
96  'warning'=>''
97  ),
98 
99  // Automatic classification of order
100  'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array( // when shipping validated
101  'family'=>'classify_order',
102  'position'=>40,
103  'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)),
104  'picto'=>'order'
105  ),
106  'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING_CLOSED'=>array( // when shipping closed
107  'family'=>'classify_order',
108  'position'=>41,
109  'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)),
110  'picto'=>'order'
111  ),
112  'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array(
113  'family'=>'classify_order',
114  'position'=>42,
115  'enabled'=>(isModEnabled('facture') && !empty($conf->commande->enabled)),
116  'picto'=>'order',
117  'warning'=>''
118  ), // For this option, if module invoice is disabled, it does not exists, so "Classify billed" for order must be done manually from order card.
119 
120  'separator2'=>array('family'=>'separator', 'position'=>50),
121 
122  // Automatic classification supplier proposal
123  'WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL'=>array(
124  'family'=>'classify_supplier_proposal',
125  'position'=>60,
126  '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))),
127  'picto'=>'supplier_proposal',
128  'warning'=>''
129  ),
130 
131  // Automatic classification supplier order
132  'WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION'=>array(
133  'family'=>'classify_supplier_order',
134  'position'=>63,
135  '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))),
136  'picto'=>'supplier_order',
137  'warning'=>''
138  ),
139 
140  'WORKFLOW_ORDER_CLASSIFY_RECEIVED_RECEPTION_CLOSED'=>array(
141  'family'=>'classify_supplier_order',
142  'position'=>64,
143  '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))),
144  'picto'=>'supplier_order',
145  'warning'=>''
146  ),
147 
148  'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER'=>array(
149  'family'=>'classify_supplier_order',
150  'position'=>65,
151  'enabled'=>((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)),
152  'picto'=>'supplier_order',
153  'warning'=>''
154  ),
155 
156  // Automatic classification reception
157  'WORKFLOW_BILL_ON_RECEPTION'=>array(
158  'family'=>'classify_reception',
159  'position'=>80,
160  '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))),
161  'picto'=>'reception'
162  ),
163 
164  // Automatic classification shipping
165  'WORKFLOW_SHIPPING_CLASSIFY_CLOSED_INVOICE' => array(
166  'family' => 'classify_shipping',
167  'position' => 90,
168  'enabled' => !empty($conf->expedition->enabled) && !empty($conf->facture->enabled),
169  'picto' => 'shipment'
170  ),
171 
172  // Automatic link ticket -> contract
173  'WORKFLOW_TICKET_LINK_CONTRACT' => array(
174  'family' => 'link_ticket',
175  'position' => 75,
176  'enabled' => !empty($conf->ticket->enabled) && !empty($conf->contract->enabled),
177  'picto' => 'ticket'
178  ),
179  'WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS' => array(
180  'family' => 'link_ticket',
181  'position' => 76,
182  'enabled' => !empty($conf->ticket->enabled) && !empty($conf->contract->enabled),
183  'picto' => 'ticket'
184  ),
185 );
186 
187 if (!empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow'])) {
188  foreach ($conf->modules_parts['workflow'] as $workflow) {
189  $workflowcodes = array_merge($workflowcodes, $workflow);
190  }
191 }
192 
193 // remove not available workflows (based on activated modules and global defined keys)
194 $workflowcodes = array_filter($workflowcodes, function ($var) {
195  return $var['enabled'];
196 });
197 
198 /*
199  * View
200  */
201 
202 llxHeader('', $langs->trans("WorkflowSetup"), "EN:Module_Workflow_En|FR:Module_Workflow|ES:Módulo_Workflow");
203 
204 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
205 print load_fiche_titre($langs->trans("WorkflowSetup"), $linkback, 'title_setup');
206 
207 print '<span class="opacitymedium">'.$langs->trans("WorkflowDesc").'</span>';
208 print '<br>';
209 print '<br>';
210 
211 // current module setup don't support any automatic workflow of this module
212 if (count($workflowcodes) < 1) {
213  print $langs->trans("ThereIsNoWorkflowToModify");
214 
215  llxFooter();
216  $db->close();
217  return;
218 }
219 
220 // Sort on position
221 $workflowcodes = dol_sort_array($workflowcodes, 'position');
222 
223 print '<table class="noborder centpercent">';
224 
225 $oldfamily = '';
226 
227 foreach ($workflowcodes as $key => $params) {
228  if ($params['family'] == 'separator') {
229  print '</table>';
230  print '<br>';
231 
232  print '<table class="noborder centpercent">';
233 
234  continue;
235  }
236 
237  if ($oldfamily != $params['family']) {
238  if ($params['family'] == 'create') {
239  $header = $langs->trans("AutomaticCreation");
240  } elseif (preg_match('/classify_(.*)/', $params['family'], $reg)) {
241  $header = $langs->trans("AutomaticClassification");
242  if ($reg[1] == 'proposal') {
243  $header .= ' - '.$langs->trans('Proposal');
244  }
245  if ($reg[1] == 'order') {
246  $header .= ' - '.$langs->trans('Order');
247  }
248  if ($reg[1] == 'supplier_proposal') {
249  $header .= ' - '.$langs->trans('SupplierProposal');
250  }
251  if ($reg[1] == 'supplier_order') {
252  $header .= ' - '.$langs->trans('SupplierOrder');
253  }
254  if ($reg[1] == 'reception') {
255  $header .= ' - '.$langs->trans('Reception');
256  }
257  if ($reg[1] == 'shipping') {
258  $header .= ' - '.$langs->trans('Shipment');
259  }
260  } elseif (preg_match('/link_(.*)/', $params['family'], $reg)) {
261  $header = $langs->trans("AutomaticLinking");
262  if ($reg[1] == 'ticket') {
263  $header .= ' - '.$langs->trans('Ticket');
264  }
265  } else {
266  $header = $langs->trans("Description");
267  }
268 
269  print '<tr class="liste_titre">';
270  print '<th>'.$header.'</th>';
271  print '<th align="center">'.$langs->trans("Status").'</th>';
272  print '</tr>';
273 
274  $oldfamily = $params['family'];
275  }
276 
277  print '<tr class="oddeven">';
278  print '<td>';
279  print img_object('', $params['picto'], 'class="pictofixedwidth"');
280  print ' '.$langs->trans('desc'.$key);
281 
282  if (!empty($params['warning'])) {
283  print ' '.img_warning($langs->transnoentitiesnoconv($params['warning']));
284  }
285 
286  print '</td>';
287 
288  print '<td class="center">';
289 
290  if (!empty($conf->use_javascript_ajax)) {
291  print ajax_constantonoff($key);
292  } else {
293  if (!empty($conf->global->$key)) {
294  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'&token='.newToken().'">';
295  print img_picto($langs->trans("Activated"), 'switch_on');
296  print '</a>';
297  } else {
298  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=set'.$key.'&token='.newToken().'">';
299  print img_picto($langs->trans("Disabled"), 'switch_off');
300  print '</a>';
301  }
302  }
303 
304  print '</td>';
305  print '</tr>';
306 }
307 
308 print '</table>';
309 
310 // End of page
311 llxFooter();
312 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59