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