dolibarr 19.0.4
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
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30
31// security check
32if (!$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
46if (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
52if (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
59clearstatcache();
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'=>(getDolGlobalString('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'=>(getDolGlobalString('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 /* Replaced by next option
157 'WORKFLOW_SHIPPING_CLASSIFY_CLOSED_INVOICE' => array(
158 'family' => 'classify_shipping',
159 'position' => 90,
160 'enabled' => isModEnabled("expedition") && isModEnabled("facture"),
161 'picto' => 'shipment',
162 'deprecated' => 1
163 ),
164 */
165
166 'WORKFLOW_SHIPPING_CLASSIFY_BILLED_INVOICE' => array(
167 'family' => 'classify_shipping',
168 'position' => 91,
169 'enabled' => isModEnabled("expedition") && isModEnabled("facture") && getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT') !== '0',
170 'picto' => 'shipment'
171 ),
172
173 // Automatic classification reception
174 /*
175 'WORKFLOW_RECEPTION_CLASSIFY_CLOSED_INVOICE'=>array(
176 'family'=>'classify_reception',
177 'position'=>95,
178 'enabled'=>(isModEnabled("reception") && (isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))),
179 'picto'=>'reception'
180 ),
181 */
182
183 'WORKFLOW_RECEPTION_CLASSIFY_BILLED_INVOICE' => array(
184 'family' => 'classify_reception',
185 'position' => 91,
186 'enabled' => isModEnabled("reception") && isModEnabled("supplier_invoice") && getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0',
187 'picto' => 'shipment'
188 ),
189
190
191 'separator2'=>array('family'=>'separator', 'position'=>400, 'enabled' => (isModEnabled('ticket') && isModEnabled('contract'))),
192
193 // Automatic link ticket -> contract
194 'WORKFLOW_TICKET_LINK_CONTRACT' => array(
195 'family' => 'link_ticket',
196 'position' => 500,
197 'enabled' => (isModEnabled('ticket') && isModEnabled('contract')),
198 'picto' => 'ticket'
199 ),
200 'WORKFLOW_TICKET_USE_PARENT_COMPANY_CONTRACTS' => array(
201 'family' => 'link_ticket',
202 'position' => 501,
203 'enabled' => (isModEnabled('ticket') && isModEnabled('contract')),
204 'picto' => 'ticket'
205 ),
206);
207
208if (!empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow'])) {
209 foreach ($conf->modules_parts['workflow'] as $workflow) {
210 $workflowcodes = array_merge($workflowcodes, $workflow);
211 }
212}
213
214// remove not available workflows (based on activated modules and global defined keys)
215$workflowcodes = array_filter($workflowcodes, function ($var) {
216 return $var['enabled'];
217});
218
219/*
220 * View
221 */
222
223llxHeader('', $langs->trans("WorkflowSetup"), "EN:Module_Workflow_En|FR:Module_Workflow|ES:Módulo_Workflow");
224
225$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
226print load_fiche_titre($langs->trans("WorkflowSetup"), $linkback, 'title_setup');
227
228print '<span class="opacitymedium">'.$langs->trans("WorkflowDesc").'</span>';
229print '<br>';
230print '<br>';
231
232// current module setup don't support any automatic workflow of this module
233if (count($workflowcodes) < 1) {
234 print $langs->trans("ThereIsNoWorkflowToModify");
235
236 llxFooter();
237 $db->close();
238 return;
239}
240
241// Sort on position
242$workflowcodes = dol_sort_array($workflowcodes, 'position');
243
244print '<table class="noborder centpercent">';
245
246$oldfamily = '';
247
248foreach ($workflowcodes as $key => $params) {
249 if ($params['family'] == 'separator') {
250 print '</table>';
251 print '<br>';
252
253 print '<table class="noborder centpercent">';
254
255 continue;
256 }
257
258 $reg = array();
259 if ($oldfamily != $params['family']) {
260 if ($params['family'] == 'create') {
261 $header = $langs->trans("AutomaticCreation");
262 } elseif (preg_match('/classify_(.*)/', $params['family'], $reg)) {
263 $header = $langs->trans("AutomaticClassification");
264 if ($reg[1] == 'proposal') {
265 $header .= ' - '.$langs->trans('Proposal');
266 }
267 if ($reg[1] == 'order') {
268 $header .= ' - '.$langs->trans('Order');
269 }
270 if ($reg[1] == 'supplier_proposal') {
271 $header .= ' - '.$langs->trans('SupplierProposal');
272 }
273 if ($reg[1] == 'supplier_order') {
274 $header .= ' - '.$langs->trans('SupplierOrder');
275 }
276 if ($reg[1] == 'reception') {
277 $header .= ' - '.$langs->trans('Reception');
278 }
279 if ($reg[1] == 'shipping') {
280 $header .= ' - '.$langs->trans('Shipment');
281 }
282 } elseif (preg_match('/link_(.*)/', $params['family'], $reg)) {
283 $header = $langs->trans("AutomaticLinking");
284 if ($reg[1] == 'ticket') {
285 $header .= ' - '.$langs->trans('Ticket');
286 }
287 } else {
288 $header = $langs->trans("Description");
289 }
290
291 print '<tr class="liste_titre">';
292 print '<th>'.$header.'</th>';
293 print '<th class="right">'.$langs->trans("Status").'</th>';
294 print '</tr>';
295
296 $oldfamily = $params['family'];
297 }
298
299 print '<tr class="oddeven">';
300 print '<td>';
301 print img_object('', $params['picto'], 'class="pictofixedwidth"');
302 print ' '.$langs->trans('desc'.$key);
303
304 if (!empty($params['warning'])) {
305 print ' '.img_warning($langs->transnoentitiesnoconv($params['warning']));
306 }
307 if (!empty($params['deprecated'])) {
308 print ' '.img_warning($langs->transnoentitiesnoconv("Deprecated"));
309 }
310
311 print '</td>';
312
313 print '<td class="right">';
314
315 if (!empty($conf->use_javascript_ajax)) {
316 print ajax_constantonoff($key);
317 } else {
318 if (getDolGlobalString($key)) {
319 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'&token='.newToken().'">';
320 print img_picto($langs->trans("Activated"), 'switch_on');
321 print '</a>';
322 } else {
323 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=set'.$key.'&token='.newToken().'">';
324 print img_picto($langs->trans("Disabled"), 'switch_off');
325 print '</a>';
326 }
327 }
328
329 print '</td>';
330 print '</tr>';
331}
332
333print '</table>';
334
335// End of page
336llxFooter();
337$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).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.