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 21/** 22 * \file htdocs/admin/workflow.php 23 * \ingroup company 24 * \brief Workflows setup page 25 */ 26 27require '../main.inc.php'; 28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 29 30// security check 31if (!$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 43if (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 49if (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 56clearstatcache(); 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 135if (!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 149llxHeader('', $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>'; 152print load_fiche_titre($langs->trans("WorkflowSetup"), $linkback, 'title_setup'); 153 154print '<span class="opacitymedium">'.$langs->trans("WorkflowDesc").'</span>'; 155print '<br>'; 156print '<br>'; 157 158// current module setup don't support any automatic workflow of this module 159if (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 170print '<table class="noborder centpercent">'; 171 172$oldfamily = ''; 173 174foreach ($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)) { 219 print ajax_constantonoff($key); 220 } else { 221 if (!empty($conf->global->$key)) { 222 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=del'.$key.'&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.'&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 236print '</table>'; 237 238// End of page 239llxFooter(); 240$db->close(); 241