dolibarr  13.0.2
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-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 <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) accessforbidden();
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("admin", "workflow", "propal", "workflow", "orders", "supplier_proposal", "receptions", "errors"));
35 
36 $action = GETPOST('action', 'aZ09');
37 
38 
39 /*
40  * Actions
41  */
42 
43 if (preg_match('/set(.*)/', $action, $reg)) {
44  if (!dolibarr_set_const($db, $reg[1], '1', 'chaine', 0, '', $conf->entity) > 0) {
45  dol_print_error($db);
46  }
47 }
48 
49 if (preg_match('/del(.*)/', $action, $reg)) {
50  if (!dolibarr_set_const($db, $reg[1], '0', 'chaine', 0, '', $conf->entity) > 0) {
51  dol_print_error($db);
52  }
53 }
54 
55 // List of workflow we can enable
56 clearstatcache();
57 
58 $workflowcodes = array(
59  // Automatic creation
60  'WORKFLOW_PROPAL_AUTOCREATE_ORDER'=>array(
61  'family'=>'create',
62  'position'=>10,
63  'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
64  'picto'=>'order'
65  ),
66  'WORKFLOW_ORDER_AUTOCREATE_INVOICE'=>array(
67  'family'=>'create',
68  'position'=>20,
69  'enabled'=>(!empty($conf->commande->enabled) && !empty($conf->facture->enabled)),
70  'picto'=>'bill'
71  ),
72 
73  'separator1'=>array('family'=>'separator', 'position'=>25),
74 
75  // Automatic classification of proposal
76  'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL'=>array(
77  'family'=>'classify_proposal',
78  'position'=>30,
79  'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->commande->enabled)),
80  'picto'=>'propal',
81  'warning'=>''
82  ),
83  'WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL'=>array(
84  'family'=>'classify_proposal',
85  'position'=>31,
86  'enabled'=>(!empty($conf->propal->enabled) && !empty($conf->facture->enabled)),
87  'picto'=>'propal',
88  'warning'=>''
89  ),
90 
91  // Automatic classification of order
92  'WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING'=>array(
93  'family'=>'classify_order',
94  'position'=>40,
95  'enabled'=>(!empty($conf->expedition->enabled) && !empty($conf->commande->enabled)),
96  'picto'=>'order'
97  ),
98  'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array(
99  'family'=>'classify_order',
100  'position'=>41,
101  'enabled'=>(!empty($conf->facture->enabled) && !empty($conf->commande->enabled)),
102  'picto'=>'order',
103  'warning'=>''
104  ), // For this option, if module invoice is disabled, it does not exists, so "Classify billed" for order must be done manually from order card.
105 
106  'separator2'=>array('family'=>'separator', 'position'=>50),
107 
108  // Automatic classification supplier proposal
109  'WORKFLOW_ORDER_CLASSIFY_BILLED_SUPPLIER_PROPOSAL'=>array(
110  'family'=>'classify_supplier_proposal',
111  'position'=>60,
112  '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))),
113  'picto'=>'propal',
114  'warning'=>''
115  ),
116 
117  // Automatic classification supplier order
118  'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER'=>array(
119  'family'=>'classify_supplier_order',
120  'position'=>62,
121  'enabled'=>(!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)),
122  'picto'=>'order',
123  'warning'=>''
124  ),
125 
126  // Automatic classification reception
127  'WORKFLOW_BILL_ON_RECEPTION'=>array(
128  'family'=>'classify_reception',
129  'position'=>64,
130  '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))),
131  'picto'=>'bill'
132  ),
133 );
134 
135 if (!empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow'])) {
136  foreach ($conf->modules_parts['workflow'] as $workflow) {
137  $workflowcodes = array_merge($workflowcodes, $workflow);
138  }
139 }
140 
141 // remove not available workflows (based on activated modules and global defined keys)
142 $workflowcodes = array_filter($workflowcodes, function ($var) {
143  return $var['enabled']; });
144 
145 /*
146  * View
147  */
148 
149 llxHeader('', $langs->trans("WorkflowSetup"), "EN:Module_Workflow_En|FR:Module_Workflow|ES:Módulo_Workflow");
150 
151 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
152 print load_fiche_titre($langs->trans("WorkflowSetup"), $linkback, 'title_setup');
153 
154 print '<span class="opacitymedium">'.$langs->trans("WorkflowDesc").'</span>';
155 print '<br>';
156 print '<br>';
157 
158 // current module setup don't support any automatic workflow of this module
159 if (count($workflowcodes) < 1) {
160  print $langs->trans("ThereIsNoWorkflowToModify");
161 
162  llxFooter();
163  $db->close();
164  return;
165 }
166 
167 // Sort on position
168 $workflowcodes = dol_sort_array($workflowcodes, 'position');
169 
170 print '<table class="noborder centpercent">';
171 
172 $oldfamily = '';
173 
174 foreach ($workflowcodes as $key => $params) {
175  if ($params['family'] == 'separator') {
176  print '</table>';
177  print '<br>';
178  print '<table class="noborder centpercent">';
179 
180  continue;
181  }
182 
183  if ($oldfamily != $params['family']) {
184  if ($params['family'] == 'create') {
185  $header = $langs->trans("AutomaticCreation");
186  } elseif (preg_match('/classify_(.*)/', $params['family'], $reg)) {
187  $header = $langs->trans("AutomaticClassification");
188  if ($reg[1] == 'proposal') $header .= ' - '.$langs->trans('Proposal');
189  if ($reg[1] == 'order') $header .= ' - '.$langs->trans('Order');
190  if ($reg[1] == 'supplier_proposal') $header .= ' - '.$langs->trans('SupplierProposal');
191  if ($reg[1] == 'supplier_order') $header .= ' - '.$langs->trans('SupplierOrder');
192  if ($reg[1] == 'reception') $header .= ' - '.$langs->trans('Reception');
193  } else {
194  $header = $langs->trans("Description");
195  }
196 
197  print '<tr class="liste_titre">';
198  print '<th>'.$header.'</th>';
199  print '<th align="center">'.$langs->trans("Status").'</th>';
200  print '</tr>';
201 
202  $oldfamily = $params['family'];
203  }
204 
205  print '<tr class="oddeven">';
206  print '<td>';
207  print img_object('', $params['picto']);
208  print ' '.$langs->trans('desc'.$key);
209 
210  if (!empty($params['warning'])) {
211  print ' '.img_warning($langs->transnoentitiesnoconv($params['warning']));
212  }
213 
214  print '</td>';
215 
216  print '<td class="center">';
217 
218  if (!empty($conf->use_javascript_ajax)) {
220  } else {
221  if (!empty($conf->global->$key)) {
222  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'&amp;token='.newToken().'">';
223  print img_picto($langs->trans("Activated"), 'switch_on');
224  print '</a>';
225  } else {
226  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=set'.$key.'&amp;token='.newToken().'">';
227  print img_picto($langs->trans("Disabled"), 'switch_off');
228  print '</a>';
229  }
230  }
231 
232  print '</td>';
233  print '</tr>';
234 }
235 
236 print '</table>';
237 
238 // End of page
239 llxFooter();
240 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
llxHeader()
Empty header.
Definition: wrapper.php:45
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0)
On/off button for constant.
Definition: ajax.lib.php:503
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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 ...
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...
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
llxFooter()
Empty footer.
Definition: wrapper.php:59