From 2da97c2bacffdeb4ff652525aafb3154448883be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 23 Feb 2021 21:24:38 +0100 Subject: [PATCH] code syntax contrat directory --- htdocs/contrat/admin/contract_extrafields.php | 17 +- .../contrat/admin/contractdet_extrafields.php | 17 +- htdocs/contrat/agenda.php | 84 +- htdocs/contrat/card.php | 902 +++++++++-------- htdocs/contrat/class/api_contracts.class.php | 61 +- htdocs/contrat/class/contrat.class.php | 914 +++++++++--------- htdocs/contrat/contact.php | 44 +- htdocs/contrat/document.php | 37 +- htdocs/contrat/index.php | 233 +++-- htdocs/contrat/list.php | 478 +++++---- htdocs/contrat/note.php | 36 +- htdocs/contrat/services_list.php | 558 +++++++---- htdocs/contrat/tpl/linkedobjectblock.tpl.php | 21 +- 13 files changed, 1882 insertions(+), 1520 deletions(-) diff --git a/htdocs/contrat/admin/contract_extrafields.php b/htdocs/contrat/admin/contract_extrafields.php index 8571856362a..dc361a1f0b6 100644 --- a/htdocs/contrat/admin/contract_extrafields.php +++ b/htdocs/contrat/admin/contract_extrafields.php @@ -40,13 +40,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'contrat'; //Must be the $element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -78,8 +82,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '
'; print "".$langs->trans("NewAttribute").""; print "
"; @@ -92,8 +95,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print '
'; print load_fiche_titre($langs->trans('NewAttribute')); @@ -105,8 +107,7 @@ if ($action == 'create') /* Edition of an optional field */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print '

'; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/contrat/admin/contractdet_extrafields.php b/htdocs/contrat/admin/contractdet_extrafields.php index 4b3f03ffedf..6e83f0a4c1b 100644 --- a/htdocs/contrat/admin/contractdet_extrafields.php +++ b/htdocs/contrat/admin/contractdet_extrafields.php @@ -40,13 +40,17 @@ $form = new Form($db); // List of supported format $tmptype2label = ExtraFields::$type2label; $type2label = array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} $action = GETPOST('action', 'aZ09'); $attrname = GETPOST('attrname', 'alpha'); $elementtype = 'contratdet'; //Must be the $element of the class that manage extrafield -if (!$user->admin) accessforbidden(); +if (!$user->admin) { + accessforbidden(); +} /* @@ -78,8 +82,7 @@ print dol_get_fiche_end(); // Buttons -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { print '
'; print "".$langs->trans("NewAttribute").""; print "
"; @@ -92,8 +95,7 @@ if ($action != 'create' && $action != 'edit') /* */ /* ************************************************************************** */ -if ($action == 'create') -{ +if ($action == 'create') { print '
'; print load_fiche_titre($langs->trans('NewAttribute')); @@ -105,8 +107,7 @@ if ($action == 'create') /* Edition d'un champ optionnel */ /* */ /* ************************************************************************** */ -if ($action == 'edit' && !empty($attrname)) -{ +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/contrat/agenda.php b/htdocs/contrat/agenda.php index f88b470215c..94232aa6afd 100644 --- a/htdocs/contrat/agenda.php +++ b/htdocs/contrat/agenda.php @@ -35,10 +35,11 @@ if (!empty($conf->projet->enabled)) { // Load translation files required by the page $langs->loadLangs(array("companies", "contracts")); -if (GETPOST('actioncode', 'array')) -{ +if (GETPOST('actioncode', 'array')) { $actioncode = GETPOST('actioncode', 'array', 3); - if (!count($actioncode)) $actioncode = '0'; + if (!count($actioncode)) { + $actioncode = '0'; + } } else { $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); } @@ -50,19 +51,27 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'contrat', $id, ''); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = 'a.datep,a.id'; -if (!$sortorder) $sortorder = 'DESC,DESC'; +if (!$sortfield) { + $sortfield = 'a.datep,a.id'; +} +if (!$sortorder) { + $sortorder = 'DESC,DESC'; +} // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agendacontract', 'globalcard')); @@ -74,20 +83,19 @@ $hookmanager->initHooks(array('agendacontract', 'globalcard')); $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Cancel - if (GETPOST('cancel', 'alpha') && !empty($backtopage)) - { + if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { header("Location: ".$backtopage); exit; } // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $actioncode = ''; $search_agenda_label = ''; } @@ -102,19 +110,18 @@ if (empty($reshook)) $form = new Form($db); $formfile = new FormFile($db); -if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} -if ($id > 0) -{ +if ($id > 0) { // Load object modContract $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis'); - if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') - { + if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') { $module = substr($module, 0, dol_strlen($module) - 4); } $result = dol_include_once('/core/modules/contract/'.$module.'.php'); - if ($result > 0) - { + if ($result > 0) { $modCodeContract = new $module(); } @@ -126,10 +133,14 @@ if ($id > 0) $object->fetch_thirdparty(); $title = $langs->trans("Agenda"); - if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) $title = $object->ref." - ".$title; + if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contractrefonly/', $conf->global->MAIN_HTML_TITLE) && $object->ref) { + $title = $object->ref." - ".$title; + } llxHeader('', $title); - if (!empty($conf->notification->enabled)) $langs->load("mails"); + if (!empty($conf->notification->enabled)) { + $langs->load("mails"); + } $head = contract_prepare_head($object); print dol_get_fiche_head($head, 'agenda', $langs->trans("Contract"), -1, 'contract'); @@ -156,14 +167,14 @@ if ($id > 0) $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $permtoedit, 'string', '', null, null, '', 1, 'getFormatedSupplierRef'); // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); - if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherContracts").')'; + if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) { + $morehtmlref .= ' ('.$langs->trans("OtherContracts").')'; + } // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->contrat->creer) - { + if ($user->rights->contrat->creer) { if ($action != 'classify') { //$morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).''; $morehtmlref .= ' : '; @@ -231,21 +242,22 @@ if ($id > 0) $newcardbutton = ''; - if (!empty($conf->agenda->enabled)) - { - if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) - { + if (!empty($conf->agenda->enabled)) { + if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) { $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out); } } - if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) - { + if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { print '
'; $param = '&id='.$id; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.$contextpage; + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.$limit; + } print load_fiche_titre($langs->trans("ActionsOnContract"), $newcardbutton, ''); //print_barre_liste($langs->trans("ActionsOnCompany"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $newcardbutton, '', 0, 1, 1); diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index d625298b14c..8a8f91f2a93 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -40,7 +40,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +if (!empty($conf->propal->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +} if (!empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; @@ -62,7 +64,9 @@ $datecontrat = ''; $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'contrat', $id); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -74,10 +78,12 @@ $extrafields = new ExtraFields($db); // Load object if ($id > 0 || !empty($ref) && $action != 'add') { $ret = $object->fetch($id, $ref); - if ($ret > 0) + if ($ret > 0) { $ret = $object->fetch_thirdparty(); - if ($ret < 0) + } + if ($ret < 0) { dol_print_error('', $object->error); + } } // fetch optionals attributes and labels @@ -98,36 +104,31 @@ $error = 0; $parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if (empty($reshook)) -{ +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} +if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once - if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) - { + if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) { $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer) - { - if (!GETPOST('dateend')) - { + } elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer) { + if (!GETPOST('dateend')) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors'); } - if (!$error) - { + if (!$error) { $result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment'))); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { @@ -137,16 +138,13 @@ if (empty($reshook)) } // Si ajout champ produit predefini - if (GETPOST('mode') == 'predefined') - { + if (GETPOST('mode') == 'predefined') { $date_start = ''; $date_end = ''; - if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear')) - { + if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear')) { $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); } - if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear')) - { + if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear')) { $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); } } @@ -156,40 +154,32 @@ if (empty($reshook)) $date_end_update = ''; $date_start_real_update = ''; $date_end_real_update = ''; - if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear')) - { + if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear')) { $date_start_update = dol_mktime(GETPOST('date_start_updatehour'), GETPOST('date_start_updatemin'), 0, GETPOST('date_start_updatemonth'), GETPOST('date_start_updateday'), GETPOST('date_start_updateyear')); } - if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear')) - { + if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear')) { $date_end_update = dol_mktime(GETPOST('date_end_updatehour'), GETPOST('date_end_updatemin'), 0, GETPOST('date_end_updatemonth'), GETPOST('date_end_updateday'), GETPOST('date_end_updateyear')); } - if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear')) - { + if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear')) { $date_start_real_update = dol_mktime(GETPOST('date_start_real_updatehour'), GETPOST('date_start_real_updatemin'), 0, GETPOST('date_start_real_updatemonth'), GETPOST('date_start_real_updateday'), GETPOST('date_start_real_updateyear')); } - if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear')) - { + if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear')) { $date_end_real_update = dol_mktime(GETPOST('date_end_real_updatehour'), GETPOST('date_end_real_updatemin'), 0, GETPOST('date_end_real_updatemonth'), GETPOST('date_end_real_updateday'), GETPOST('date_end_real_updateyear')); } - if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear')) - { + if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear')) { $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); } // Add contract - if ($action == 'add' && $user->rights->contrat->creer) - { + if ($action == 'add' && $user->rights->contrat->creer) { // Check - if (empty($datecontrat)) - { + if (empty($datecontrat)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action = 'create'; } - if ($socid < 1) - { + if ($socid < 1) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors'); $action = 'create'; $error++; @@ -202,8 +192,7 @@ if (empty($reshook)) $action = 'create'; } - if (!$error) - { + if (!$error) { $object->socid = $socid; $object->date_contrat = $datecontrat; @@ -219,27 +208,28 @@ if (empty($reshook)) $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); // If creation from another object of another module (Example: origin=propal, originid=1) - if (!empty($origin) && !empty($originid)) - { + if (!empty($origin) && !empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; - if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) - { + if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { $element = $regs[1]; $subelement = $regs[2]; } // For compatibility - if ($element == 'order') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'order') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + $element = 'comm/propal'; $subelement = 'propal'; + } $object->origin = $origin; $object->origin_id = $originid; // Possibility to add external linked objects with hooks $object->linked_objects[$object->origin] = $object->origin_id; - if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) - { + if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) { $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } @@ -248,8 +238,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } - if ($id > 0) - { + if ($id > 0) { dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); $classname = ucfirst($subelement); @@ -257,12 +246,10 @@ if (empty($reshook)) dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); $result = $srcobject->fetch($object->origin_id); - if ($result > 0) - { + if ($result > 0) { $srcobject->fetch_thirdparty(); $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject, 'fetch_lines')) - { + if (empty($lines) && method_exists($srcobject, 'fetch_lines')) { $srcobject->fetch_lines(); $lines = $srcobject->lines; } @@ -270,29 +257,29 @@ if (empty($reshook)) $fk_parent_line = 0; $num = count($lines); - for ($i = 0; $i < $num; $i++) - { + for ($i = 0; $i < $num; $i++) { $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0); if ($product_type == 1 || (!empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0, 1)))) { // TODO Exclude also deee // service prédéfini - if ($lines[$i]->fk_product > 0) - { + if ($lines[$i]->fk_product > 0) { $product_static = new Product($db); // Define output language - if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) - { + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $prod = new Product($db); $prod->id = $lines[$i]->fk_product; $prod->getMultiLangs(); $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if (empty($newlang)) $newlang = $srcobject->thirdparty->default_lang; - if (!empty($newlang)) - { + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (empty($newlang)) { + $newlang = $srcobject->thirdparty->default_lang; + } + if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } @@ -340,8 +327,7 @@ if (empty($reshook)) $lines[$i]->fk_unit ); - if ($result < 0) - { + if ($result < 0) { $error++; break; } @@ -356,16 +342,16 @@ if (empty($reshook)) $parameters = array('objFrom' => $srcobject); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook - if ($reshook < 0) + if ($reshook < 0) { $error++; + } } else { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } else { $result = $object->create($user); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { @@ -376,18 +362,14 @@ if (empty($reshook)) } } elseif ($action == 'classin' && $user->rights->contrat->creer) { $object->setProject(GETPOST('projectid')); - } - - // Add a new line - elseif ($action == 'addline' && $user->rights->contrat->creer) - { + } elseif ($action == 'addline' && $user->rights->contrat->creer) { + // Add a new line // Set if we used free entry or predefined product $predef = ''; $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $price_ht = price2num(GETPOST('price_ht'), 'MU'); $price_ht_devise = price2num(GETPOST('multicurrency_price_ht', 'CU')); - if (GETPOST('prod_entry_mode', 'alpha') == 'free') - { + if (GETPOST('prod_entry_mode', 'alpha') == 'free') { $idprod = 0; $tva_tx = (GETPOST('tva_tx', 'alpha') ? GETPOST('tva_tx', 'alpha') : 0); } else { @@ -398,21 +380,18 @@ if (empty($reshook)) $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS'); $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef), 2) : 0); - if ($qty == '') - { + if ($qty == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); $error++; } - if (GETPOST('prod_entry_mode', 'alpha') == 'free' && empty($idprod) && empty($product_desc)) - { + if (GETPOST('prod_entry_mode', 'alpha') == 'free' && empty($idprod) && empty($product_desc)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors'); $error++; } $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); - if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) - { + if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) { setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors'); $error++; } @@ -428,8 +407,7 @@ if (empty($reshook)) } } - if (!$error) - { + if (!$error) { // Clean parameters $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); @@ -439,15 +417,16 @@ if (empty($reshook)) // Ecrase $desc par celui du produit // Ecrase $tva_tx par celui du produit // Ecrase $base_price_type par celui du produit - if ($idprod > 0) - { + if ($idprod > 0) { $prod = new Product($db); $prod->fetch($idprod); // Update if prices fields are defined $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id); $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id); - if (empty($tva_tx)) $tva_npr = 0; + if (empty($tva_tx)) { + $tva_npr = 0; + } $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; @@ -455,14 +434,12 @@ if (empty($reshook)) $price_base_type = $prod->price_base_type; // On defini prix unitaire - if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) - { + if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) { $pu_ht = $prod->multiprices[$object->thirdparty->price_level]; $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; - } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) - { + } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php'; $prodcustprice = new Productcustomerprice($db); @@ -476,9 +453,13 @@ if (empty($reshook)) $pu_ttc = price($prodcustprice->lines [0]->price_ttc); $price_base_type = $prodcustprice->lines [0]->price_base_type; $tva_tx = $prodcustprice->lines [0]->tva_tx; - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; + if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; + } $tva_npr = $prodcustprice->lines[0]->recuperableonly; - if (empty($tva_tx)) $tva_npr = 0; + if (empty($tva_tx)) { + $tva_npr = 0; + } } } } @@ -488,25 +469,26 @@ if (empty($reshook)) // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tmpvat != $tmpprodvat) - { - if ($price_base_type != 'HT') - { + if ($tmpvat != $tmpprodvat) { + if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU'); } else { $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); } } - $desc = $prod->description; + $desc = $prod->description; //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) { $product_desc=''; } - if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc; - else $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); + if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) { + $desc = $product_desc; + } else { + $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); + } $fk_unit = $prod->fk_unit; } else { @@ -523,16 +505,19 @@ if (empty($reshook)) // ajout prix achat $fk_fournprice = $_POST['fournprice']; - if (!empty($_POST['buying_price'])) - $pa_ht = $_POST['buying_price']; - else $pa_ht = null; + if (!empty($_POST['buying_price'])) { + $pa_ht = $_POST['buying_price']; + } else { + $pa_ht = null; + } $info_bits = 0; - if ($tva_npr) $info_bits |= 0x01; + if ($tva_npr) { + $info_bits |= 0x01; + } if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) - || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) - { + || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { $object->error = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)); $result = -1; } else { @@ -551,22 +536,24 @@ if (empty($reshook)) $price_base_type, $pu_ttc, $info_bits, - $fk_fournprice, - $pa_ht, + $fk_fournprice, + $pa_ht, $array_options, $fk_unit ); } - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) // No generation if default type not defined - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) { // No generation if default type not defined $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -615,19 +602,16 @@ if (empty($reshook)) } elseif ($action == 'updateline' && $user->rights->contrat->creer && !GETPOST('cancel', 'alpha')) { $error = 0; - if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) - { + if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) { setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors'); $action = 'editline'; $_GET['rowid'] = GETPOST('elrowid'); $error++; } - if (!$error) - { + if (!$error) { $objectline = new ContratLigne($db); - if ($objectline->fetch(GETPOST('elrowid', 'int')) < 0) - { + if ($objectline->fetch(GETPOST('elrowid', 'int')) < 0) { setEventMessages($objectline->error, $objectline->errors, 'errors'); $error++; } @@ -636,16 +620,20 @@ if (empty($reshook)) $db->begin(); - if (!$error) - { - if ($date_start_real_update == '') $date_start_real_update = $objectline->date_ouverture; - if ($date_end_real_update == '') $date_end_real_update = $objectline->date_cloture; + if (!$error) { + if ($date_start_real_update == '') { + $date_start_real_update = $objectline->date_ouverture; + } + if ($date_end_real_update == '') { + $date_end_real_update = $objectline->date_cloture; + } $vat_rate = GETPOST('eltva_tx'); // Define info_bits $info_bits = 0; - if (preg_match('/\*/', $vat_rate)) + if (preg_match('/\*/', $vat_rate)) { $info_bits |= 0x01; + } // Define vat_rate $vat_rate = str_replace('*', '', $vat_rate); @@ -657,17 +645,18 @@ if (empty($reshook)) // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $txtva, $reg)) - { + if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } // ajout prix d'achat $fk_fournprice = $_POST['fournprice']; - if (!empty($_POST['buying_price'])) - $pa_ht = $_POST['buying_price']; - else $pa_ht = null; + if (!empty($_POST['buying_price'])) { + $pa_ht = $_POST['buying_price']; + } else { + $pa_ht = null; + } $fk_unit = GETPOST('unit', 'alpha'); @@ -709,43 +698,40 @@ if (empty($reshook)) // TODO verifier price_min si fk_product et multiprix $result = $objectline->update($user); - if ($result < 0) - { + if ($result < 0) { $error++; setEventMessages($objectline->error, $objectline->errors, 'errors'); } } - if (!$error) - { + if (!$error) { $db->commit(); } else { $db->rollback(); } - } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer) - { + } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer) { $result = $object->deleteline(GETPOST('lineid'), $user); - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer) - { + } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer) { $result = $object->validate($user); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -758,49 +744,38 @@ if (empty($reshook)) } else { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'reopen' && $user->rights->contrat->creer) - { + } elseif ($action == 'reopen' && $user->rights->contrat->creer) { $result = $object->reopen($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // Close all lines - elseif ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer) { + } elseif ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer) { + // Close all lines $result = $object->closeAll($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // Close all lines - elseif ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer) { + } elseif ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer) { + // Close all lines $result = $object->activateAll($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer) { $result = $object->delete($user); - if ($result >= 0) - { + if ($result >= 0) { header("Location: list.php?restore_lastsearch_values=1"); return; } else { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contrat->creer) { - if (GETPOST('newcid') > 0) - { + if (GETPOST('newcid') > 0) { $contractline = new ContratLigne($db); $result = $contractline->fetch(GETPOSTINT('lineid')); $contractline->fk_contrat = GETPOSTINT('newcid'); $result = $contractline->update($user, 1); - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); return; } else { @@ -809,18 +784,18 @@ if (empty($reshook)) } else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefNewContract")), null, 'errors'); } - } elseif ($action == 'update_extras') - { + } elseif ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } if (!$error) { $result = $object->insertExtraFields('CONTRACT_MODIFY'); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } @@ -829,8 +804,7 @@ if (empty($reshook)) if ($error) { $action = 'edit_extras'; } - } elseif ($action == 'setref_supplier') - { + } elseif ($action == 'setref_supplier') { $cancelbutton = GETPOST('cancel', 'alpha'); if (!$cancelbutton) { $object->oldcopy = dol_clone($object); @@ -847,12 +821,10 @@ if (empty($reshook)) header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } - } elseif ($action == 'setref_customer') - { + } elseif ($action == 'setref_customer') { $cancelbutton = GETPOST('cancel', 'alpha'); - if (!$cancelbutton) - { + if (!$cancelbutton) { $object->oldcopy = dol_clone($object); $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer', 'alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); @@ -888,11 +860,11 @@ if (empty($reshook)) $new_filedir = $conf->contrat->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); $files = dol_dir_list($old_filedir); - if (!empty($files)) - { - if (!is_dir($new_filedir)) dol_mkdir($new_filedir); - foreach ($files as $file) - { + if (!empty($files)) { + if (!is_dir($new_filedir)) { + dol_mkdir($new_filedir); + } + foreach ($files as $file) { dol_move($file['fullname'], $new_filedir.'/'.$file['name']); } } @@ -941,42 +913,31 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer) - { - if ($action == 'addcontact') - { + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer) { + if ($action == 'addcontact') { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); } else { setEventMessages($object->error, $object->errors, 'errors'); } } - } - - // bascule du statut d'un contact - elseif ($action == 'swapstatut') - { + } elseif ($action == 'swapstatut') { + // bascule du statut d'un contact $result = $object->swapContactStatus(GETPOST('ligne')); - } - - // Efface un contact - elseif ($action == 'deletecontact') - { + } elseif ($action == 'deletecontact') { + // Efface un contact $result = $object->delete_contact(GETPOST('lineid')); - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { @@ -986,10 +947,8 @@ if (empty($reshook)) } // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes') - { - if (!GETPOST('socid', 3)) - { + if ($action == 'confirm_clone' && $confirm == 'yes') { + if (!GETPOST('socid', 3)) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { if ($object->id > 0) { @@ -998,7 +957,9 @@ if (empty($reshook)) header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); exit(); } else { - if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors'); + if (count($object->errors) > 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } $action = ''; } } @@ -1015,53 +976,57 @@ llxHeader('', $langs->trans("Contract"), ""); $form = new Form($db); $formfile = new FormFile($db); -if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} // Load object modContract $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis'); -if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') -{ +if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') { $module = substr($module, 0, dol_strlen($module) - 4); } $result = dol_include_once('/core/modules/contract/'.$module.'.php'); -if ($result > 0) -{ +if ($result > 0) { $modCodeContract = new $module(); } // Create -if ($action == 'create') -{ +if ($action == 'create') { print load_fiche_titre($langs->trans('AddContract'), '', 'contract'); $soc = new Societe($db); - if ($socid > 0) $soc->fetch($socid); + if ($socid > 0) { + $soc->fetch($socid); + } - if (GETPOST('origin') && GETPOST('originid')) - { + if (GETPOST('origin') && GETPOST('originid')) { // Parse element/subelement (ex: project_task) $regs = array(); $element = $subelement = GETPOST('origin'); - if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) - { + if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) { $element = $regs[1]; $subelement = $regs[2]; } - if ($element == 'project') - { + if ($element == 'project') { $projectid = GETPOST('originid'); } else { // For compatibility - if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'order' || $element == 'commande') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + $element = 'comm/propal'; $subelement = 'propal'; + } dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); $classname = ucfirst($subelement); $objectsrc = new $classname($db); $objectsrc->fetch($originid); - if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) $objectsrc->fetch_lines(); + if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) { + $objectsrc->fetch_lines(); + } $objectsrc->fetch_thirdparty(); // Replicate extrafields @@ -1118,8 +1083,7 @@ if ($action == 'create') // Thirdparty print ''; print ''.$langs->trans('ThirdParty').''; - if ($socid > 0) - { + if ($socid > 0) { print ''; print $soc->getNomUrl(1); print ''; @@ -1132,16 +1096,21 @@ if ($action == 'create') } print ''."\n"; - if ($socid > 0) - { + if ($socid > 0) { // Ligne info remises tiers print ''.$langs->trans('Discounts').''; - if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent); - else print $langs->trans("CompanyHasNoRelativeDiscount"); + if ($soc->remise_percent) { + print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent); + } else { + print $langs->trans("CompanyHasNoRelativeDiscount"); + } print '. '; $absolute_discount = $soc->getAvailableDiscounts(); - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + if ($absolute_discount) { + print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); + } else { + print $langs->trans("CompanyHasNoAbsoluteDiscount"); + } print '.'; print ''; } @@ -1161,8 +1130,7 @@ if ($action == 'create') print ""; // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { $langs->load('projects'); $formproject = new FormProjets($db); @@ -1178,8 +1146,7 @@ if ($action == 'create') print $doleditor->Create(1); print ''; - if (empty($user->socid)) - { + if (empty($user->socid)) { print ''.$langs->trans("NotePrivate").''; $doleditor = new DolEditor('note_private', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); print $doleditor->Create(1); @@ -1206,13 +1173,11 @@ if ($action == 'create') print ''; print ''; - if (is_object($objectsrc)) - { + if (is_object($objectsrc)) { print ''; print ''; - if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) - { + if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) { print '
'.$langs->trans("Note").': '.$langs->trans("OnlyLinesWithTypeServiceAreUsed"); } } @@ -1226,8 +1191,7 @@ if ($action == 'create') { $now = dol_now(); - if ($object->id > 0) - { + if ($object->id > 0) { $object->fetch_thirdparty(); $soc = $object->thirdparty; // $soc is used later @@ -1299,10 +1263,9 @@ if ($action == 'create') print $formconfirm; /* - * Contrat - */ - if (!empty($object->brouillon) && $user->rights->contrat->creer) - { + * Contrat + */ + if (!empty($object->brouillon) && $user->rights->contrat->creer) { print '
'; print ''; print ''; @@ -1331,14 +1294,14 @@ if ($action == 'create') $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer, 'string', '', null, null, '', 1, 'getFormatedSupplierRef'); // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); - if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherContracts").')'; + if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) { + $morehtmlref .= ' ('.$langs->trans("OtherContracts").')'; + } // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->contrat->creer) - { + if ($user->rights->contrat->creer) { if ($action != 'classify') { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; } @@ -1379,12 +1342,18 @@ if ($action == 'create') // Line info of thirdparty discounts print ''.$langs->trans('Discount').''; - if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent); - else print $langs->trans("CompanyHasNoRelativeDiscount"); + if ($object->thirdparty->remise_percent) { + print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent); + } else { + print $langs->trans("CompanyHasNoRelativeDiscount"); + } $absolute_discount = $object->thirdparty->getAvailableDiscounts(); print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + if ($absolute_discount) { + print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); + } else { + print $langs->trans("CompanyHasNoAbsoluteDiscount"); + } print '.'; print ''; @@ -1405,22 +1374,19 @@ if ($action == 'create') print ''; - if (!empty($object->brouillon) && $user->rights->contrat->creer) - { + if (!empty($object->brouillon) && $user->rights->contrat->creer) { print '
'; } echo '
'; - if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) - { + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { $blocname = 'contacts'; $title = $langs->trans('ContactsAddresses'); include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; } - if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $blocname = 'notes'; $title = $langs->trans('Notes'); include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; @@ -1430,19 +1396,20 @@ if ($action == 'create') $arrayothercontracts = $object->getListOfContracts('others'); /* - * Lines of contracts - */ + * Lines of contracts + */ $productstatic = new Product($db); $usemargins = 0; - if (!empty($conf->margin->enabled) && !empty($object->element) && in_array($object->element, array('facture', 'propal', 'commande'))) $usemargins = 1; + if (!empty($conf->margin->enabled) && !empty($object->element) && in_array($object->element, array('facture', 'propal', 'commande'))) { + $usemargins = 1; + } // Title line for service $cursorline = 1; print '
'; - while ($cursorline <= $nbofservices) - { + while ($cursorline <= $nbofservices) { print '
'; print '
'; print ''; @@ -1466,8 +1433,7 @@ if ($action == 'create') $sql .= " WHERE cd.rowid = ".$object->lines[$cursorline - 1]->id; $result = $db->query($sql); - if ($result) - { + if ($result) { $total = 0; print ''; @@ -1478,23 +1444,27 @@ if ($action == 'create') // print ''.$langs->trans("PriceUHTCurrency").''; //} print ''.$langs->trans("Qty").''; - if (!empty($conf->global->PRODUCT_USE_UNITS)) print ''.$langs->trans("Unit").''; + if (!empty($conf->global->PRODUCT_USE_UNITS)) { + print ''.$langs->trans("Unit").''; + } print ''.$langs->trans("ReductionShort").''; - if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print ''.$langs->trans("BuyingPrice").''; + if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) { + print ''.$langs->trans("BuyingPrice").''; + } print ' '; print "\n"; $objp = $db->fetch_object($result); // Line in view mode - if ($action != 'editline' || GETPOST('rowid') != $objp->rowid) - { + if ($action != 'editline' || GETPOST('rowid') != $objp->rowid) { $moreparam = ''; - if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') $moreparam = 'style="display: none;"'; + if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') { + $moreparam = 'style="display: none;"'; + } print ''; // Label - if ($objp->fk_product > 0) - { + if ($objp->fk_product > 0) { $productstatic->id = $objp->fk_product; $productstatic->type = $objp->ptype; $productstatic->ref = $objp->pref; @@ -1506,16 +1476,14 @@ if ($action == 'create') print ''; $text = $productstatic->getNomUrl(1, '', 32); - if ($objp->plabel) - { + if ($objp->plabel) { $text .= ' - '; $text .= $objp->plabel; } $description = $objp->description; // Add description in form - if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) - { + if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) { $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ? '
'.dol_htmlentitiesbr($objp->description) : ''; $description = ''; // Already added into main visible desc } @@ -1539,35 +1507,35 @@ if ($action == 'create') // Quantity print ''.$objp->qty.''; // Unit - if (!empty($conf->global->PRODUCT_USE_UNITS)) print ''.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).''; + if (!empty($conf->global->PRODUCT_USE_UNITS)) { + print ''.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).''; + } // Discount - if ($objp->remise_percent > 0) - { + if ($objp->remise_percent > 0) { print ''.$objp->remise_percent."%\n"; } else { print ' '; } // Margin - if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print ''.price($objp->pa_ht).''; + if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) { + print ''.price($objp->pa_ht).''; + } // Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme) print ''; - if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0)) - { + if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0)) { print ''; print ''; print img_picto($langs->trans("MoveToAnotherContract"), 'uparrow'); print ''; } - if ($user->rights->contrat->creer && ($object->statut >= 0)) - { + if ($user->rights->contrat->creer && ($object->statut >= 0)) { print ''; print img_edit(); print ''; } - if ($user->rights->contrat->creer && ($object->statut >= 0)) - { + if ($user->rights->contrat->creer && ($object->statut >= 0)) { print ''; print img_delete(); print ''; @@ -1577,8 +1545,7 @@ if ($action == 'create') print "\n"; // Dates of service planed and real - if ($objp->subprice >= 0) - { + if ($objp->subprice >= 0) { $colspan = 6; if ($conf->margin->enabled && $conf->global->PRODUCT_USE_UNITS) { @@ -1592,8 +1559,7 @@ if ($action == 'create') // Date planned print $langs->trans("DateStartPlanned").': '; - if ($objp->date_debut) - { + if ($objp->date_debut) { print dol_print_date($db->jdate($objp->date_debut), 'day'); // Warning si date prevu passee et pas en service if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { @@ -1601,18 +1567,21 @@ if ($action == 'create') $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); print " ".img_warning($textlate); } - } else print $langs->trans("Unknown"); + } else { + print $langs->trans("Unknown"); + } print '  -  '; print $langs->trans("DateEndPlanned").': '; - if ($objp->date_fin) - { + if ($objp->date_fin) { print dol_print_date($db->jdate($objp->date_fin), 'day'); if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); print " ".img_warning($textlate); } - } else print $langs->trans("Unknown"); + } else { + print $langs->trans("Unknown"); + } print ''; print ''; @@ -1625,14 +1594,12 @@ if ($action == 'create') $line->fetch_optionals(); print $line->showOptionals($extrafields, 'view', array('class'=>'oddeven', 'style'=>$moreparam, 'colspan'=>$colspan), '', '', 1); } - } - // Line in mode update - else { + } else { + // Line in mode update // Ligne carac print ''; print ''; - if ($objp->fk_product > 0) - { + if ($objp->fk_product > 0) { $canchangeproduct = 1; if (empty($canchangeproduct)) { $productstatic->id = $objp->fk_product; @@ -1659,7 +1626,9 @@ if ($action == 'create') // editeur wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $nbrows = ROWS_2; - if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT; + if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) { + $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT; + } $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0); $doleditor = new DolEditor('product_desc', $objp->description, '', 92, 'dolibarr_details', '', false, true, $enable, $nbrows, '90%'); $doleditor->Create(); @@ -1683,8 +1652,7 @@ if ($action == 'create') print ''; // Unit - if (!empty($conf->global->PRODUCT_USE_UNITS)) - { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { print ''; print $form->selectUnits($objp->fk_unit, "unit"); print ''; @@ -1693,10 +1661,11 @@ if ($action == 'create') // Discount print '%'; - if (!empty($usemargins)) - { + if (!empty($usemargins)) { print ''; - if ($objp->fk_product) print ''; + if ($objp->fk_product) { + print ''; + } print ''; } print ''; @@ -1706,8 +1675,12 @@ if ($action == 'create') print ''; $colspan = 6; - if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) $colspan++; - if (!empty($conf->global->PRODUCT_USE_UNITS)) $colspan++; + if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) { + $colspan++; + } + if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $colspan++; + } // Ligne dates prevues print ''; @@ -1732,10 +1705,11 @@ if ($action == 'create') dol_print_error($db); } - if ($object->statut > 0) - { + if ($object->statut > 0) { $moreparam = ''; - if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') $moreparam = 'style="display: none;"'; + if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') { + $moreparam = 'style="display: none;"'; + } print ''; print '
'; print "\n"; @@ -1748,22 +1722,21 @@ if ($action == 'create') /* - * Confirmation to delete service line of contract - */ - if ($action == 'deleteline' && !$_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) - { + * Confirmation to delete service line of contract + */ + if ($action == 'deleteline' && !$_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) { print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'), $langs->trans("DeleteContractLine"), $langs->trans("ConfirmDeleteContractLine"), "confirm_deleteline", '', 0, 1); - if ($ret == 'html') print '
'; + if ($ret == 'html') { + print '
'; + } } /* - * Confirmation to move service toward another contract - */ - if ($action == 'move' && !$_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) - { + * Confirmation to move service toward another contract + */ + if ($action == 'move' && !$_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) { $arraycontractid = array(); - foreach ($arrayothercontracts as $contractcursor) - { + foreach ($arrayothercontracts as $contractcursor) { $arraycontractid[$contractcursor->id] = $contractcursor->ref; } //var_dump($arraycontractid); @@ -1777,10 +1750,9 @@ if ($action == 'create') } /* - * Confirmation de la validation activation - */ - if ($action == 'active' && !$_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) - { + * Confirmation de la validation activation + */ + if ($action == 'active' && !$_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) { $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); $comment = GETPOST('comment', 'alpha'); @@ -1789,16 +1761,14 @@ if ($action == 'create') } /* - * Confirmation de la validation fermeture - */ - if ($action == 'closeline' && !$_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) - { + * Confirmation de la validation fermeture + */ + if ($action == 'closeline' && !$_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) { $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); $comment = GETPOST('comment', 'alpha'); - if (empty($dateactend)) - { + if (empty($dateactend)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEndReal")), null, 'errors'); } else { print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne', 'int')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService", dol_print_date($dateactend, "%A %d %B %Y")), "confirm_closeline", '', 0, 1); @@ -1808,28 +1778,23 @@ if ($action == 'create') // Area with status and activation info of line - if ($object->statut > 0) - { + if ($object->statut > 0) { print ''; print ''; print ''; print ''; print ''; @@ -1871,8 +1841,7 @@ if ($action == 'create') } // Form to activate line - if ($user->rights->contrat->activer && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) - { + if ($user->rights->contrat->activer && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) { print ''; print ''; @@ -1880,15 +1849,17 @@ if ($action == 'create') // Definie date debut et fin par defaut $dateactstart = $objp->date_debut; - if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - elseif (!$dateactstart) $dateactstart = time(); + if (GETPOST('remonth')) { + $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + } elseif (!$dateactstart) { + $dateactstart = time(); + } $dateactend = $objp->date_fin; - if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - elseif (!$dateactend) - { - if ($objp->fk_product > 0) - { + if (GETPOST('endmonth')) { + $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + } elseif (!$dateactend) { + if ($objp->fk_product > 0) { $product = new Product($db); $product->fetch($objp->fk_product); $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit); @@ -1920,8 +1891,7 @@ if ($action == 'create') print ''; } - if ($user->rights->contrat->activer && $action == 'unactivateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) - { + if ($user->rights->contrat->activer && $action == 'unactivateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne')) { /** * Disable a contract line */ @@ -1935,28 +1905,30 @@ if ($action == 'create') // Definie date debut et fin par defaut $dateactstart = $objp->date_debut_reelle; - if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - elseif (!$dateactstart) $dateactstart = time(); + if (GETPOST('remonth')) { + $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + } elseif (!$dateactstart) { + $dateactstart = time(); + } $dateactend = $objp->date_fin_reelle; - if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - elseif (!$dateactend) - { - if ($objp->fk_product > 0) - { + if (GETPOST('endmonth')) { + $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + } elseif (!$dateactend) { + if ($objp->fk_product > 0) { $product = new Product($db); $product->fetch($objp->fk_product); $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit); } } $now = dol_now(); - if ($dateactend > $now) $dateactend = $now; + if ($dateactend > $now) { + $dateactend = $now; + } print '
'.$langs->trans("ServiceStatus").': '.$object->lines[$cursorline - 1]->getLibStatut(4).''; - if ($user->socid == 0) - { - if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline') - { + if ($user->socid == 0) { + if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline') { $tmpaction = 'activateline'; $tmpactionpicto = 'play'; $tmpactiontext = $langs->trans("Activate"); - if ($objp->statut == 4) - { + if ($objp->statut == 4) { $tmpaction = 'unactivateline'; $tmpactionpicto = 'playstop'; $tmpactiontext = $langs->trans("Disable"); } - if (($tmpaction == 'activateline' && $user->rights->contrat->activer) || ($tmpaction == 'unactivateline' && $user->rights->contrat->desactiver)) - { + if (($tmpaction == 'activateline' && $user->rights->contrat->activer) || ($tmpaction == 'unactivateline' && $user->rights->contrat->desactiver)) { print ''; print img_picto($tmpactiontext, $tmpactionpicto); print ''; @@ -1845,8 +1810,11 @@ if ($action == 'create') // Si pas encore active if (!$objp->date_debut_reelle) { print $langs->trans("DateStartReal").': '; - if ($objp->date_debut_reelle) print dol_print_date($db->jdate($objp->date_debut_reelle), 'day'); - else print $langs->trans("ContractStatusNotRunning"); + if ($objp->date_debut_reelle) { + print dol_print_date($db->jdate($objp->date_debut_reelle), 'day'); + } else { + print $langs->trans("ContractStatusNotRunning"); + } } // Si active et en cours if ($objp->date_debut_reelle && !$objp->date_fin_reelle) { @@ -1861,7 +1829,9 @@ if ($action == 'create') print $langs->trans("DateEndReal").': '; print dol_print_date($db->jdate($objp->date_fin_reelle), 'day'); } - if (!empty($objp->comment)) print "  -  ".$objp->comment; + if (!empty($objp->comment)) { + print "  -  ".$objp->comment; + } print ' 
'; - if ($objp->statut >= 4) - { - if ($objp->statut == 4) - { + if ($objp->statut >= 4) { + if ($objp->statut == 4) { print $langs->trans("DateEndReal").' '; print $form->selectDate($dateactend, "end", $usehm, $usehm, ($objp->date_fin_reelle > 0 ? 0 : 1), "closeline", 1, 1); } @@ -1983,8 +1955,7 @@ if ($action == 'create') print ''; // Form to add new line - if ($user->rights->contrat->creer && ($object->statut == 0)) - { + if ($user->rights->contrat->creer && ($object->statut == 0)) { $dateSelector = 1; print "\n"; @@ -1999,10 +1970,11 @@ if ($action == 'create') print ''; // Array with (n*2)+1 lines // Form to add new line - if ($action != 'editline') - { + if ($action != 'editline') { $forcetoshowtitlelines = 1; - if (empty($object->multicurrency_code)) $object->multicurrency_code = $conf->currency; // TODO Remove this when multicurrency supported on contracts + if (empty($object->multicurrency_code)) { + $object->multicurrency_code = $conf->currency; // TODO Remove this when multicurrency supported on contracts + } // Add free products/services $object->formAddObjectLine(1, $mysoc, $soc); @@ -2020,65 +1992,69 @@ if ($action == 'create') /* - * Buttons - */ + * Buttons + */ - if ($user->socid == 0) - { + if ($user->socid == 0) { print '
'; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) - { + if (empty($reshook)) { // Send if (empty($user->socid)) { if ($object->statut == 1) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) { print ''; - } else print ''; + } else { + print ''; + } } } - if ($object->statut == 0 && $nbofservices) - { - if ($user->rights->contrat->creer) print ''; - else print ''; + if ($object->statut == 0 && $nbofservices) { + if ($user->rights->contrat->creer) { + print ''; + } else { + print ''; + } } - if ($object->statut == 1) - { - if ($user->rights->contrat->creer) print ''; - else print ''; + if ($object->statut == 1) { + if ($user->rights->contrat->creer) { + print ''; + } else { + print ''; + } } - if (!empty($conf->commande->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) - { + if (!empty($conf->commande->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) { $langs->load("orders"); - if ($user->rights->commande->creer) print ''; - else print ''; + if ($user->rights->commande->creer) { + print ''; + } else { + print ''; + } } - if (!empty($conf->facture->enabled) && $object->statut > 0) - { + if (!empty($conf->facture->enabled) && $object->statut > 0) { $langs->load("bills"); - if ($user->rights->facture->creer) print ''; - else print ''; + if ($user->rights->facture->creer) { + print ''; + } else { + print ''; + } } - if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) - { - if ($user->rights->contrat->activer) - { + if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) { + if ($user->rights->contrat->activer) { print ''; } else { print ''; } } - if ($object->nbofservicesclosed < $nbofservices) - { - if ($user->rights->contrat->desactiver) - { + if ($object->nbofservicesclosed < $nbofservices) { + if ($user->rights->contrat->desactiver) { print ''; } else { print ''; @@ -2093,10 +2069,12 @@ if ($action == 'create') //} } - if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) - { - if ($action == 'showclosedlines') print ''; - else print ''; + if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) { + if ($action == 'showclosedlines') { + print ''; + } else { + print ''; + } } // Clone @@ -2107,8 +2085,7 @@ if ($action == 'create') // On peut supprimer entite si // - Droit de creer + mode brouillon (erreur creation) // - Droit de supprimer - if (($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer) - { + if (($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer) { print ''; } else { print ''; @@ -2123,13 +2100,12 @@ if ($action == 'create') $action = 'presend'; } - if ($action != 'presend') - { + if ($action != 'presend') { print '
'; /* - * Documents generes - */ + * Documents generes + */ $filename = dol_sanitizeFileName($object->ref); $filedir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref); $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; @@ -2145,8 +2121,7 @@ if ($action == 'create') $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); // Show direct download link - if ($object->statut != Contrat::STATUS_DRAFT && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) - { + if ($object->statut != Contrat::STATUS_DRAFT && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) { print '
'."\n"; print showDirectDownloadLink($object).'
'; } @@ -2182,8 +2157,7 @@ $db->close(); ?> margin->enabled) && $action == 'editline') -{ +if (!empty($conf->margin->enabled) && $action == 'editline') { // TODO Why this ? To manage margin on contracts ? ?> rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; + if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) { + $search_sale = DolibarrApiAccess::$user->id; + } $sql = "SELECT t.rowid"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { + $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + } $sql .= " FROM ".MAIN_DB_PREFIX."contrat as t"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + } $sql .= ' WHERE t.entity IN ('.getEntity('contrat').')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc"; - if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")"; - if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { + $sql .= " AND t.fk_soc = sc.fk_soc"; + } + if ($socids) { + $sql .= " AND t.fk_soc IN (".$socids.")"; + } + if ($search_sale > 0) { + $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + } // Insert sale filter - if ($search_sale > 0) - { + if ($search_sale > 0) { $sql .= " AND sc.fk_user = ".$search_sale; } // Add sql filters - if ($sqlfilters) - { - if (!DolibarrApi::_checkFilters($sqlfilters)) - { + if ($sqlfilters) { + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; @@ -143,8 +152,7 @@ class Contracts extends DolibarrApi $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { - if ($page < 0) - { + if ($page < 0) { $page = 0; } $offset = $limit * $page; @@ -155,13 +163,11 @@ class Contracts extends DolibarrApi dol_syslog("API Rest request"); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); $i = 0; - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $contrat_static = new Contrat($this->db); if ($contrat_static->fetch($obj->rowid)) { @@ -196,12 +202,12 @@ class Contracts extends DolibarrApi $this->contract->$field = $value; } /*if (isset($request_data["lines"])) { - $lines = array(); - foreach ($request_data["lines"] as $line) { - array_push($lines, (object) $line); - } - $this->contract->lines = $lines; - }*/ + $lines = array(); + foreach ($request_data["lines"] as $line) { + array_push($lines, (object) $line); + } + $this->contract->lines = $lines; + }*/ if ($this->contract->create(DolibarrApiAccess::$user) < 0) { throw new RestException(500, "Error creating contract", array_merge(array($this->contract->error), $this->contract->errors)); } @@ -491,7 +497,9 @@ class Contracts extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } foreach ($request_data as $field => $value) { - if ($field == 'id') continue; + if ($field == 'id') { + continue; + } $this->contract->$field = $value; } @@ -667,8 +675,9 @@ class Contracts extends DolibarrApi { $contrat = array(); foreach (Contracts::$FIELDS as $field) { - if (!isset($data[$field])) + if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); + } $contrat[$field] = $data[$field]; } return $contrat; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 7c99a9483b9..94da51cca8a 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -269,8 +269,7 @@ class Contrat extends CommonObject global $db, $langs, $conf; $langs->load("contracts"); - if (!empty($conf->global->CONTRACT_ADDON)) - { + if (!empty($conf->global->CONTRACT_ADDON)) { $mybool = false; $file = $conf->global->CONTRACT_ADDON.".php"; @@ -286,8 +285,7 @@ class Contrat extends CommonObject $mybool |= @include_once $dir.$file; } - if (!$mybool) - { + if (!$mybool) { dol_print_error('', "Failed to include file ".$file); return ''; } @@ -295,8 +293,7 @@ class Contrat extends CommonObject $obj = new $classname(); $numref = $obj->getNextValue($soc, $this); - if ($numref != "") - { + if ($numref != "") { return $numref; } else { $this->error = $obj->error; @@ -325,8 +322,7 @@ class Contrat extends CommonObject { // phpcs:enable $result = $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment); - if ($result < 0) - { + if ($result < 0) { $this->error = $this->lines[$this->lines_id_index_mapper[$line_id]]->error; $this->errors = $this->lines[$this->lines_id_index_mapper[$line_id]]->errors; } @@ -348,8 +344,7 @@ class Contrat extends CommonObject { // phpcs:enable $result = $this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment); - if ($result < 0) - { + if ($result < 0) { $this->error = $this->lines[$this->lines_id_index_mapper[$line_id]]->error; $this->errors = $this->lines[$this->lines_id_index_mapper[$line_id]]->errors; } @@ -369,7 +364,9 @@ class Contrat extends CommonObject */ public function activateAll($user, $date_start = '', $notrigger = 0, $comment = '') { - if (empty($date_start)) $date_start = dol_now(); + if (empty($date_start)) { + $date_start = dol_now(); + } $this->db->begin(); @@ -378,16 +375,13 @@ class Contrat extends CommonObject // Load lines $this->fetch_lines(); - foreach ($this->lines as $contratline) - { + foreach ($this->lines as $contratline) { // Open lines not already open - if ($contratline->statut != ContratLigne::STATUS_OPEN) - { + if ($contratline->statut != ContratLigne::STATUS_OPEN) { $contratline->context = $this->context; $result = $contratline->active_line($user, $date_start, -1, $comment); - if ($result < 0) - { + if ($result < 0) { $error++; $this->error = $contratline->error; $this->errors = $contratline->errors; @@ -396,14 +390,14 @@ class Contrat extends CommonObject } } - if (!$error && $this->statut == 0) - { + if (!$error && $this->statut == 0) { $result = $this->validate($user, '', $notrigger); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -432,17 +426,14 @@ class Contrat extends CommonObject $error = 0; - foreach ($this->lines as $contratline) - { + foreach ($this->lines as $contratline) { // Close lines not already closed - if ($contratline->statut != ContratLigne::STATUS_CLOSED) - { + if ($contratline->statut != ContratLigne::STATUS_CLOSED) { $contratline->date_cloture = $now; $contratline->fk_user_cloture = $user->id; $contratline->statut = ContratLigne::STATUS_CLOSED; $result = $contratline->close_line($user, $now, $comment, $notrigger); - if ($result < 0) - { + if ($result < 0) { $error++; $this->error = $contratline->error; $this->errors = $contratline->errors; @@ -451,14 +442,14 @@ class Contrat extends CommonObject } } - if (!$error && $this->statut == 0) - { + if (!$error && $this->statut == 0) { $result = $this->validate($user, '', $notrigger); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -491,76 +482,69 @@ class Contrat extends CommonObject $this->fetch_thirdparty(); // A contract is validated so we can move thirdparty to status customer - if (empty($conf->global->CONTRACT_DISABLE_AUTOSET_AS_CLIENT_ON_CONTRACT_VALIDATION)) - { + if (empty($conf->global->CONTRACT_DISABLE_AUTOSET_AS_CLIENT_ON_CONTRACT_VALIDATION)) { $result = $this->thirdparty->set_as_client(); } // Define new ref - if ($force_number) - { + if ($force_number) { $num = $force_number; - } elseif (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life - { + } elseif (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($this->thirdparty); } else { $num = $this->ref; } $this->newref = dol_sanitizeFileName($num); - if ($num) - { + if ($num) { $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$this->db->escape($num)."', statut = 1"; //$sql.= ", fk_user_valid = ".$user->id.", date_valid = '".$this->db->idate($now)."'"; $sql .= " WHERE rowid = ".$this->id." AND statut = 0"; dol_syslog(get_class($this)."::validate", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { dol_print_error($this->db); $error++; $this->error = $this->db->lasterror(); } // Trigger calls - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('CONTRACT_VALIDATE', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->oldref = $this->ref; // Rename directory if dir was a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref)) - { + if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'contract/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'contract/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->contract->dir_output.'/'.$oldref; $dirdest = $conf->contract->dir_output.'/'.$newref; - if (!$error && file_exists($dirsource)) - { + if (!$error && file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); - if (@rename($dirsource, $dirdest)) - { + if (@rename($dirsource, $dirdest)) { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref $listoffiles = dol_dir_list($conf->contract->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) - { + foreach ($listoffiles as $fileentry) { $dirsource = $fileentry['name']; $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); $dirsource = $fileentry['path'].'/'.$dirsource; @@ -573,8 +557,7 @@ class Contrat extends CommonObject } // Set new ref and define current statut - if (!$error) - { + if (!$error) { $this->ref = $num; $this->statut = 1; $this->brouillon = 0; @@ -584,8 +567,7 @@ class Contrat extends CommonObject $error++; } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -621,16 +603,14 @@ class Contrat extends CommonObject dol_syslog(get_class($this)."::validate", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { dol_print_error($this->db); $error++; $this->error = $this->db->lasterror(); } // Trigger calls - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('CONTRACT_REOPEN', $user); if ($result < 0) { @@ -640,15 +620,13 @@ class Contrat extends CommonObject } // Set new ref and define current status - if (!$error) - { + if (!$error) { $this->statut = 0; $this->brouillon = 1; $this->date_validation = $now; } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -678,36 +656,32 @@ class Contrat extends CommonObject $sql .= " fk_commercial_signature, fk_commercial_suivi,"; $sql .= " note_private, note_public, model_pdf, extraparams"; $sql .= " FROM ".MAIN_DB_PREFIX."contrat"; - if (!$id) $sql .= " WHERE entity IN (".getEntity('contract').")"; - else $sql .= " WHERE rowid=".(int) $id; - if ($ref_customer) - { + if (!$id) { + $sql .= " WHERE entity IN (".getEntity('contract').")"; + } else { + $sql .= " WHERE rowid=".(int) $id; + } + if ($ref_customer) { $sql .= " AND ref_customer = '".$this->db->escape($ref_customer)."'"; } - if ($ref_supplier) - { + if ($ref_supplier) { $sql .= " AND ref_supplier = '".$this->db->escape($ref_supplier)."'"; } - if ($ref) - { + if ($ref) { $sql .= " AND ref='".$this->db->escape($ref)."'"; } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num > 1) - { + if ($num > 1) { $this->error = 'Fetch found several records.'; dol_syslog($this->error, LOG_ERR); $result = -2; - } elseif ($num) // $num = 1 - { + } elseif ($num) { // $num = 1 $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { $this->id = $obj->rowid; $this->ref = (!isset($obj->ref) || !$obj->ref) ? $obj->rowid : $obj->ref; $this->ref_customer = $obj->ref_customer; @@ -745,8 +719,7 @@ class Contrat extends CommonObject // Lines $result = $this->fetch_lines(); - if ($result < 0) - { + if ($result < 0) { $this->error = $this->db->lasterror(); return -3; } @@ -791,8 +764,7 @@ class Contrat extends CommonObject $now = dol_now(); - if (!is_object($extrafields)) - { + if (!is_object($extrafields)) { require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); } @@ -825,13 +797,11 @@ class Contrat extends CommonObject dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $this->db->fetch_object($result); $line = new ContratLigne($this->db); @@ -908,10 +878,18 @@ class Contrat extends CommonObject //dol_syslog("1 ".$line->desc); //dol_syslog("2 ".$line->product_desc); - if ($line->statut == ContratLigne::STATUS_INITIAL) $this->nbofserviceswait++; - if ($line->statut == ContratLigne::STATUS_OPEN && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) $this->nbofservicesopened++; - if ($line->statut == ContratLigne::STATUS_OPEN && (!empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) $this->nbofservicesexpired++; - if ($line->statut == ContratLigne::STATUS_CLOSED) $this->nbofservicesclosed++; + if ($line->statut == ContratLigne::STATUS_INITIAL) { + $this->nbofserviceswait++; + } + if ($line->statut == ContratLigne::STATUS_OPEN && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) { + $this->nbofservicesopened++; + } + if ($line->statut == ContratLigne::STATUS_OPEN && (!empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) { + $this->nbofservicesexpired++; + } + if ($line->statut == ContratLigne::STATUS_CLOSED) { + $this->nbofservicesclosed++; + } $total_ttc += $objp->total_ttc; // TODO Not saved into database $total_vat += $objp->total_tva; @@ -946,20 +924,20 @@ class Contrat extends CommonObject // Check parameters $paramsok = 1; - if ($this->commercial_signature_id <= 0) - { + if ($this->commercial_signature_id <= 0) { $langs->load("commercial"); $this->error .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SalesRepresentativeSignature")); $paramsok = 0; } - if ($this->commercial_suivi_id <= 0) - { + if ($this->commercial_suivi_id <= 0) { $langs->load("commercial"); $this->error .= ($this->error ? "
" : ''); $this->error .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("SalesRepresentativeFollowUp")); $paramsok = 0; } - if (!$paramsok) return -1; + if (!$paramsok) { + return -1; + } $this->db->begin(); @@ -985,76 +963,66 @@ class Contrat extends CommonObject $sql .= ")"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $error = 0; $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat"); // Load object modContract $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis'); - if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') - { + if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') { $module = substr($module, 0, dol_strlen($module) - 4); } $result = dol_include_once('/core/modules/contract/'.$module.'.php'); - if ($result > 0) - { + if ($result > 0) { $modCodeContract = new $module(); if (!empty($modCodeContract->code_auto)) { // Force the ref to a draft value if numbering module is an automatic numbering $sql = 'UPDATE '.MAIN_DB_PREFIX."contrat SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; - if ($this->db->query($sql)) - { - if ($this->id) - { + if ($this->db->query($sql)) { + if ($this->id) { $this->ref = "(PROV".$this->id.")"; } } } } - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } // Insert business contacts ('SALESREPSIGN','contrat') - if (!$error) - { + if (!$error) { $result = $this->add_contact($this->commercial_signature_id, 'SALESREPSIGN', 'internal'); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } } // Insert business contacts ('SALESREPFOLL','contrat') if (!$error) { $result = $this->add_contact($this->commercial_suivi_id, 'SALESREPFOLL', 'internal'); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } } if (!$error) { - if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects - { + if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds } // Add object linked - if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) - { - foreach ($this->linked_objects as $origin => $tmp_origin_id) - { - if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) - { - foreach ($tmp_origin_id as $origin_id) - { + if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) { + foreach ($this->linked_objects as $origin => $tmp_origin_id) { + if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + foreach ($tmp_origin_id as $origin_id) { $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { + if (!$ret) { $this->error = $this->db->lasterror(); $error++; } @@ -1063,8 +1031,7 @@ class Contrat extends CommonObject { $origin_id = $tmp_origin_id; $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { + if (!$ret) { $this->error = $this->db->lasterror(); $error++; } @@ -1072,20 +1039,16 @@ class Contrat extends CommonObject } } - if (!$error && $this->id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id)) // Get contact from origin object - { + if (!$error && $this->id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id)) { // Get contact from origin object $originforcontact = $this->origin; $originidforcontact = $this->origin_id; - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order - { + if ($originforcontact == 'shipping') { // shipment and order share the same contacts. If creating from shipment we take data of order require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; $exp = new Expedition($this->db); $exp->fetch($this->origin_id); $exp->fetchObjectLinked(); - if (count($exp->linkedObjectsIds['commande']) > 0) - { - foreach ($exp->linkedObjectsIds['commande'] as $key => $value) - { + if (count($exp->linkedObjectsIds['commande']) > 0) { + foreach ($exp->linkedObjectsIds['commande'] as $key => $value) { $originforcontact = 'commande'; $originidforcontact = $value->id; break; // We take first one @@ -1097,28 +1060,30 @@ class Contrat extends CommonObject $sqlcontact .= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$this->db->escape($originforcontact)."'"; $resqlcontact = $this->db->query($sqlcontact); - if ($resqlcontact) - { - while ($objcontact = $this->db->fetch_object($resqlcontact)) - { - if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously + if ($resqlcontact) { + while ($objcontact = $this->db->fetch_object($resqlcontact)) { + if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) { + continue; // ignore this, already forced previously + } //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object } - } else dol_print_error($resqlcontact); + } else { + dol_print_error($resqlcontact); + } } } - if (!$error) - { + if (!$error) { // Call trigger $result = $this->call_trigger('CONTRACT_CREATE', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers - if (!$error) - { + if (!$error) { $this->db->commit(); return $this->id; } else { @@ -1158,29 +1123,29 @@ class Contrat extends CommonObject // Call trigger $result = $this->call_trigger('CONTRACT_DELETE', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers - if (!$error) - { + if (!$error) { // Delete linked contacts $res = $this->delete_linked_contact(); - if ($res < 0) - { + if ($res < 0) { dol_syslog(get_class($this)."::delete error", LOG_ERR); $error++; } } - if (!$error) - { + if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { // Delete contratdet_log /* $sql = "DELETE cdl"; @@ -1193,17 +1158,14 @@ class Contrat extends CommonObject dol_syslog(get_class($this)."::delete contratdet_log", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->error(); $error++; } $numressql = $this->db->num_rows($resql); - if (!$error && $numressql) - { + if (!$error && $numressql) { $tab_resql = array(); - for ($i = 0; $i < $numressql; $i++) - { + for ($i = 0; $i < $numressql; $i++) { $objresql = $this->db->fetch_object($resql); $tab_resql[] = $objresql->cdlrowid; } @@ -1214,8 +1176,7 @@ class Contrat extends CommonObject dol_syslog(get_class($this)."::delete contratdet_log", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->error(); $error++; } @@ -1231,23 +1192,20 @@ class Contrat extends CommonObject dol_syslog(get_class($this)."::delete contratdet_extrafields", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->error(); $error++; } } - if (!$error) - { + if (!$error) { // Delete contratdet $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet"; $sql .= " WHERE fk_contrat=".$this->id; dol_syslog(get_class($this)."::delete contratdet", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->error(); $error++; } @@ -1257,8 +1215,7 @@ class Contrat extends CommonObject if (!$error) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? '' : '@'.$this->module))."' AND src_object_id = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->lasterror(); $this->errors[] = $this->error; $error++; @@ -1266,15 +1223,13 @@ class Contrat extends CommonObject } // Delete contract - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."contrat"; $sql .= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::delete contrat", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->error(); $error++; } @@ -1283,25 +1238,20 @@ class Contrat extends CommonObject // Removed extrafields if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); } } - if (!$error) - { + if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); - if ($conf->contrat->dir_output) - { + if ($conf->contrat->dir_output) { $dir = $conf->contrat->multidir_output[$this->entity]."/".$ref; - if (file_exists($dir)) - { + if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); - if (!$res) - { + if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $error++; } @@ -1309,8 +1259,7 @@ class Contrat extends CommonObject } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -1333,23 +1282,55 @@ class Contrat extends CommonObject $error = 0; // Clean parameters - if (empty($this->fk_commercial_signature) && $this->commercial_signature_id > 0) $this->fk_commercial_signature = $this->commercial_signature_id; - if (empty($this->fk_commercial_suivi) && $this->commercial_suivi_id > 0) $this->fk_commercial_suivi = $this->commercial_suivi_id; - if (empty($this->fk_soc) && $this->socid > 0) $this->fk_soc = (int) $this->socid; - if (empty($this->fk_project) && $this->projet > 0) $this->fk_project = (int) $this->projet; + if (empty($this->fk_commercial_signature) && $this->commercial_signature_id > 0) { + $this->fk_commercial_signature = $this->commercial_signature_id; + } + if (empty($this->fk_commercial_suivi) && $this->commercial_suivi_id > 0) { + $this->fk_commercial_suivi = $this->commercial_suivi_id; + } + if (empty($this->fk_soc) && $this->socid > 0) { + $this->fk_soc = (int) $this->socid; + } + if (empty($this->fk_project) && $this->projet > 0) { + $this->fk_project = (int) $this->projet; + } - if (isset($this->ref)) $this->ref = trim($this->ref); - if (isset($this->ref_customer)) $this->ref_customer = trim($this->ref_customer); - if (isset($this->ref_supplier)) $this->ref_supplier = trim($this->ref_supplier); - if (isset($this->ref_ext)) $this->ref_ext = trim($this->ref_ext); - if (isset($this->entity)) $this->entity = (int) $this->entity; - if (isset($this->statut)) $this->statut = (int) $this->statut; - if (isset($this->fk_soc)) $this->fk_soc = (int) $this->fk_soc; - if (isset($this->fk_commercial_signature)) $this->fk_commercial_signature = trim($this->fk_commercial_signature); - if (isset($this->fk_commercial_suivi)) $this->fk_commercial_suivi = trim($this->fk_commercial_suivi); - if (isset($this->note_private)) $this->note_private = trim($this->note_private); - if (isset($this->note_public)) $this->note_public = trim($this->note_public); - if (isset($this->import_key)) $this->import_key = trim($this->import_key); + if (isset($this->ref)) { + $this->ref = trim($this->ref); + } + if (isset($this->ref_customer)) { + $this->ref_customer = trim($this->ref_customer); + } + if (isset($this->ref_supplier)) { + $this->ref_supplier = trim($this->ref_supplier); + } + if (isset($this->ref_ext)) { + $this->ref_ext = trim($this->ref_ext); + } + if (isset($this->entity)) { + $this->entity = (int) $this->entity; + } + if (isset($this->statut)) { + $this->statut = (int) $this->statut; + } + if (isset($this->fk_soc)) { + $this->fk_soc = (int) $this->fk_soc; + } + if (isset($this->fk_commercial_signature)) { + $this->fk_commercial_signature = trim($this->fk_commercial_signature); + } + if (isset($this->fk_commercial_suivi)) { + $this->fk_commercial_suivi = trim($this->fk_commercial_suivi); + } + if (isset($this->note_private)) { + $this->note_private = trim($this->note_private); + } + if (isset($this->note_public)) { + $this->note_public = trim($this->note_public); + } + if (isset($this->import_key)) { + $this->import_key = trim($this->import_key); + } //if (isset($this->extraparams)) $this->extraparams=trim($this->extraparams); // Check parameters @@ -1377,30 +1358,29 @@ class Contrat extends CommonObject $this->db->begin(); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call triggers $result = $this->call_trigger('CONTRACT_MODIFY', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -1444,14 +1424,12 @@ class Contrat extends CommonObject dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type, $pu_ttc, $info_bits, $rang"); // Check parameters - if ($fk_product <= 0 && empty($desc)) - { + if ($fk_product <= 0 && empty($desc)) { $this->error = "ErrorDescRequiredForFreeProductLines"; return -1; } - if ($this->statut >= 0) - { + if ($this->statut >= 0) { // Clean parameters $pu_ht = price2num($pu_ht); $pu_ttc = price2num($pu_ttc); @@ -1460,8 +1438,7 @@ class Contrat extends CommonObject // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $txtva, $reg)) - { + if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } @@ -1471,23 +1448,38 @@ class Contrat extends CommonObject $remise_percent = price2num($remise_percent); $qty = price2num($qty); - if (empty($qty)) $qty = 1; - if (empty($info_bits)) $info_bits = 0; - if (empty($pu_ht) || !is_numeric($pu_ht)) $pu_ht = 0; - if (empty($pu_ttc)) $pu_ttc = 0; - if (empty($txtva) || !is_numeric($txtva)) $txtva = 0; - if (empty($txlocaltax1) || !is_numeric($txlocaltax1)) $txlocaltax1 = 0; - if (empty($txlocaltax2) || !is_numeric($txlocaltax2)) $txlocaltax2 = 0; + if (empty($qty)) { + $qty = 1; + } + if (empty($info_bits)) { + $info_bits = 0; + } + if (empty($pu_ht) || !is_numeric($pu_ht)) { + $pu_ht = 0; + } + if (empty($pu_ttc)) { + $pu_ttc = 0; + } + if (empty($txtva) || !is_numeric($txtva)) { + $txtva = 0; + } + if (empty($txlocaltax1) || !is_numeric($txlocaltax1)) { + $txlocaltax1 = 0; + } + if (empty($txlocaltax2) || !is_numeric($txlocaltax2)) { + $txlocaltax2 = 0; + } - if ($price_base_type == 'HT') - { + if ($price_base_type == 'HT') { $pu = $pu_ht; } else { $pu = $pu_ttc; } // Check parameters - if (empty($remise_percent)) $remise_percent = 0; + if (empty($remise_percent)) { + $remise_percent = 0; + } if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); @@ -1518,20 +1510,19 @@ class Contrat extends CommonObject // Anciens indicateurs: $price, $remise (a ne plus utiliser) $remise = 0; $price = price2num(round($pu_ht, 2)); - if (dol_strlen($remise_percent) > 0) - { + if (dol_strlen($remise_percent) > 0) { $remise = round(($pu_ht * $remise_percent / 100), 2); $price = $pu_ht - $remise; } - if (empty($pa_ht)) $pa_ht = 0; + if (empty($pa_ht)) { + $pa_ht = 0; + } // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0) - { - if (($result = $this->defineBuyPrice($pu_ht, $remise_percent, $fk_product)) < 0) - { + if ($this->pa_ht == 0) { + if (($result = $this->defineBuyPrice($pu_ht, $remise_percent, $fk_product)) < 0) { return $result; } else { $pa_ht = $result; @@ -1545,8 +1536,12 @@ class Contrat extends CommonObject $sql .= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; $sql .= " info_bits,"; $sql .= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht"; - if ($date_start > 0) { $sql .= ",date_ouverture_prevue"; } - if ($date_end > 0) { $sql .= ",date_fin_validite"; } + if ($date_start > 0) { + $sql .= ",date_ouverture_prevue"; + } + if ($date_end > 0) { + $sql .= ",date_fin_validite"; + } $sql .= ", fk_unit"; $sql .= ") VALUES ("; $sql .= $this->id.", '', '".$this->db->escape($desc)."',"; @@ -1563,28 +1558,35 @@ class Contrat extends CommonObject $sql .= " ".price2num($total_ht).",".price2num($total_tva).",".price2num($total_localtax1).",".price2num($total_localtax2).",".price2num($total_ttc).","; $sql .= " '".$this->db->escape($info_bits)."',"; $sql .= " ".price2num($price).",".price2num($remise).","; - if (isset($fk_fournprice)) $sql .= ' '.$fk_fournprice.','; - else $sql .= ' null,'; - if (isset($pa_ht)) $sql .= ' '.price2num($pa_ht); - else $sql .= ' null'; - if ($date_start > 0) { $sql .= ",'".$this->db->idate($date_start)."'"; } - if ($date_end > 0) { $sql .= ",'".$this->db->idate($date_end)."'"; } + if (isset($fk_fournprice)) { + $sql .= ' '.$fk_fournprice.','; + } else { + $sql .= ' null,'; + } + if (isset($pa_ht)) { + $sql .= ' '.price2num($pa_ht); + } else { + $sql .= ' null'; + } + if ($date_start > 0) { + $sql .= ",'".$this->db->idate($date_start)."'"; + } + if ($date_end > 0) { + $sql .= ",'".$this->db->idate($date_end)."'"; + } $sql .= ", ".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null"); $sql .= ")"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX."contratdet"); - if (!$error) - { + if (!$error) { $contractline = new ContratLigne($this->db); $contractline->array_options = $array_options; $contractline->id = $contractlineid; $result = $contractline->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $this->error[] = $contractline->error; $error++; } @@ -1593,15 +1595,13 @@ class Contrat extends CommonObject if (empty($error)) { // Call trigger $result = $this->call_trigger('LINECONTRACT_INSERT', $user); - if ($result < 0) - { + if ($result < 0) { $error++; } // End call triggers } - if ($error) - { + if ($error) { $this->db->rollback(); return -1; } else { @@ -1657,12 +1657,13 @@ class Contrat extends CommonObject $localtax1tx = price2num($localtax1tx); $localtax2tx = price2num($localtax2tx); $pa_ht = price2num($pa_ht); - if (empty($fk_fournprice)) $fk_fournprice = 0; + if (empty($fk_fournprice)) { + $fk_fournprice = 0; + } $subprice = $price; $remise = 0; - if (dol_strlen($remise_percent) > 0) - { + if (dol_strlen($remise_percent) > 0) { $remise = round(($pu * $remise_percent / 100), 2); $price = $pu - $remise; } else { @@ -1701,19 +1702,18 @@ class Contrat extends CommonObject // Anciens indicateurs: $price, $remise (a ne plus utiliser) $remise = 0; $price = price2num(round($pu, 2)); - if (dol_strlen($remise_percent) > 0) - { + if (dol_strlen($remise_percent) > 0) { $remise = round(($pu * $remise_percent / 100), 2); $price = $pu - $remise; } - if (empty($pa_ht)) $pa_ht = 0; + if (empty($pa_ht)) { + $pa_ht = 0; + } // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0) - { - if (($result = $this->defineBuyPrice($pu, $remise_percent)) < 0) - { + if ($this->pa_ht == 0) { + if (($result = $this->defineBuyPrice($pu, $remise_percent)) < 0) { return $result; } else { $pa_ht = $result; @@ -1738,22 +1738,35 @@ class Contrat extends CommonObject $sql .= ", total_ttc='".price2num($total_ttc)."'"; $sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : "null"); $sql .= ", buy_price_ht='".price2num($pa_ht)."'"; - if ($date_start > 0) { $sql .= ",date_ouverture_prevue='".$this->db->idate($date_start)."'"; } else { $sql .= ",date_ouverture_prevue=null"; } - if ($date_end > 0) { $sql .= ",date_fin_validite='".$this->db->idate($date_end)."'"; } else { $sql .= ",date_fin_validite=null"; } - if ($date_debut_reel > 0) { $sql .= ",date_ouverture='".$this->db->idate($date_debut_reel)."'"; } else { $sql .= ",date_ouverture=null"; } - if ($date_fin_reel > 0) { $sql .= ",date_cloture='".$this->db->idate($date_fin_reel)."'"; } else { $sql .= ",date_cloture=null"; } + if ($date_start > 0) { + $sql .= ",date_ouverture_prevue='".$this->db->idate($date_start)."'"; + } else { + $sql .= ",date_ouverture_prevue=null"; + } + if ($date_end > 0) { + $sql .= ",date_fin_validite='".$this->db->idate($date_end)."'"; + } else { + $sql .= ",date_fin_validite=null"; + } + if ($date_debut_reel > 0) { + $sql .= ",date_ouverture='".$this->db->idate($date_debut_reel)."'"; + } else { + $sql .= ",date_ouverture=null"; + } + if ($date_fin_reel > 0) { + $sql .= ",date_cloture='".$this->db->idate($date_fin_reel)."'"; + } else { + $sql .= ",date_cloture=null"; + } $sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null"); $sql .= " WHERE rowid = ".$rowid; dol_syslog(get_class($this)."::updateline", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $result = $this->update_statut($user); - if ($result >= 0) - { - if (is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used - { + if ($result >= 0) { + if (is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used $contractline = new ContratLigne($this->db); $contractline->fetch($rowid); $contractline->fetch_optionals(); @@ -1764,8 +1777,7 @@ class Contrat extends CommonObject } $result = $contractline->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $this->error[] = $contractline->error; $error++; } @@ -1774,8 +1786,7 @@ class Contrat extends CommonObject if (empty($error)) { // Call trigger $result = $this->call_trigger('LINECONTRACT_UPDATE', $user); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -3; } @@ -1810,11 +1821,12 @@ class Contrat extends CommonObject $error = 0; - if ($this->statut >= 0) - { + if ($this->statut >= 0) { // Call trigger $result = $this->call_trigger('LINECONTRACT_DELETE', $user); - if ($result < 0) return -1; + if ($result < 0) { + return -1; + } // End call triggers $this->db->begin(); @@ -1824,8 +1836,7 @@ class Contrat extends CommonObject dol_syslog(get_class($this)."::deleteline", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = "Error ".$this->db->lasterror(); $error++; } @@ -1835,8 +1846,7 @@ class Contrat extends CommonObject $contractline = new ContratLigne($this->db); $contractline->id = $idline; $result = $contractline->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; $this->error = "Error ".get_class($this)."::deleteline deleteExtraFields error -4 ".$contractline->error; } @@ -1871,7 +1881,9 @@ class Contrat extends CommonObject dol_syslog(__METHOD__." is deprecated", LOG_WARNING); // If draft, we keep it (should not happen) - if ($this->statut == 0) return 1; + if ($this->statut == 0) { + return 1; + } // Load $this->lines array // $this->fetch_lines(); @@ -1910,8 +1922,7 @@ class Contrat extends CommonObject // phpcs:enable global $langs; - if (empty($this->labelStatus) || empty($this->labelStatusShort)) - { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) { global $langs; $langs->load("contracts"); $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ContractStatusDraft'); @@ -1923,10 +1934,11 @@ class Contrat extends CommonObject } $statusType = 'status'.$status; - if ($status == self::STATUS_VALIDATED) $statusType = 'status6'; + if ($status == self::STATUS_VALIDATED) { + $statusType = 'status6'; + } - if ($mode == 4 || $mode == 6 || $mode == 7) - { + if ($mode == 4 || $mode == 6 || $mode == 7) { $text = ''; if ($mode == 4) { $text = ''; @@ -1972,8 +1984,12 @@ class Contrat extends CommonObject //{ // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { + $add_save_lastsearch_values = 1; + } + if ($add_save_lastsearch_values) { + $url .= '&save_lastsearch_values=1'; + } //} $label = ''; @@ -1999,10 +2015,8 @@ class Contrat extends CommonObject } $linkclose = ''; - if (empty($notooltip) && $user->rights->contrat->lire) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip) && $user->rights->contrat->lire) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowOrder"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } @@ -2015,8 +2029,12 @@ class Contrat extends CommonObject $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= ($this->ref ? $this->ref : $this->id); + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= ($this->ref ? $this->ref : $this->id); + } $result .= $linkend; global $action; @@ -2047,10 +2065,8 @@ class Contrat extends CommonObject $sql .= " WHERE c.rowid = ".((int) $id); $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -2087,16 +2103,16 @@ class Contrat extends CommonObject $sql = "SELECT cd.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= " WHERE fk_contrat =".$this->id; - if ($status >= 0) $sql .= " AND statut = ".$status; + if ($status >= 0) { + $sql .= " AND statut = ".$status; + } dol_syslog(get_class($this)."::array_detail()", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); $tab[$i] = $obj->rowid; $i++; @@ -2121,16 +2137,16 @@ class Contrat extends CommonObject $sql = "SELECT c.rowid, c.ref"; $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c"; $sql .= " WHERE fk_soc =".$this->socid; - if ($option == 'others') $sql .= " AND c.rowid != ".$this->id; + if ($option == 'others') { + $sql .= " AND c.rowid != ".$this->id; + } dol_syslog(get_class($this)."::getOtherContracts()", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); $contrat = new Contrat($this->db); $contrat->fetch($obj->rowid); @@ -2161,25 +2177,24 @@ class Contrat extends CommonObject $this->from = " FROM ".MAIN_DB_PREFIX."contrat as c"; $this->from .= ", ".MAIN_DB_PREFIX."contratdet as cd"; $this->from .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$user->socid) $this->from .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$user->socid) { + $this->from .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } - if ($mode == 'inactive') - { + if ($mode == 'inactive') { $sql = "SELECT cd.rowid, cd.date_ouverture_prevue as datefin"; $sql .= $this->from; $sql .= " WHERE c.statut = 1"; $sql .= " AND c.rowid = cd.fk_contrat"; $sql .= " AND cd.statut = 0"; - } elseif ($mode == 'expired') - { + } elseif ($mode == 'expired') { $sql = "SELECT cd.rowid, cd.date_fin_validite as datefin"; $sql .= $this->from; $sql .= " WHERE c.statut = 1"; $sql .= " AND c.rowid = cd.fk_contrat"; $sql .= " AND cd.statut = 4"; $sql .= " AND cd.date_fin_validite < '".$this->db->idate(dol_now())."'"; - } elseif ($mode == 'active') - { + } elseif ($mode == 'active') { $sql = "SELECT cd.rowid, cd.date_fin_validite as datefin"; $sql .= $this->from; $sql .= " WHERE c.statut = 1"; @@ -2190,12 +2205,15 @@ class Contrat extends CommonObject } $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity = ".$conf->entity; - if ($user->socid) $sql .= " AND c.fk_soc = ".$user->socid; - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if ($user->socid) { + $sql .= " AND c.fk_soc = ".$user->socid; + } + if (!$user->rights->societe->client->voir && !$user->socid) { + $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $langs->load("contracts"); $now = dol_now(); @@ -2225,8 +2243,7 @@ class Contrat extends CommonObject $response->url = $url; $response->img = img_object('', "contract"); - while ($obj = $this->db->fetch_object($resql)) - { + while ($obj = $this->db->fetch_object($resql)) { $response->nbtodo++; if ($obj->datefin && $this->db->jdate($obj->datefin) < ($now - $warning_delay)) { @@ -2259,8 +2276,7 @@ class Contrat extends CommonObject $sql = "SELECT count(c.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid"; - if (!$user->rights->societe->client->voir && !$user->socid) - { + if (!$user->rights->societe->client->voir && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; $sql .= " WHERE sc.fk_user = ".$user->id; $clause = "AND"; @@ -2268,10 +2284,8 @@ class Contrat extends CommonObject $sql .= " ".$clause." c.entity = ".$conf->entity; $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->nb["contracts"] = $obj->nb; } $this->db->free($resql); @@ -2328,12 +2342,10 @@ class Contrat extends CommonObject $sql .= $this->db->plimit(100); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num_prods = $this->db->num_rows($resql); $i = 0; - while ($i < $num_prods) - { + while ($i < $num_prods) { $i++; $row = $this->db->fetch_row($resql); $prodids[$i] = $row[0]; @@ -2359,8 +2371,7 @@ class Contrat extends CommonObject // Lines $nbp = 5; $xnbp = 0; - while ($xnbp < $nbp) - { + while ($xnbp < $nbp) { $line = new ContratLigne($this->db); $line->qty = 1; $line->subprice = 100; @@ -2374,8 +2385,7 @@ class Contrat extends CommonObject $line->date_start_real = dol_now() - 200000; $line->date_end = dol_now() + 500000; $line->date_end_real = dol_now() - 100000; - if ($num_prods > 0) - { + if ($num_prods > 0) { $prodid = mt_rand(1, $num_prods); $line->fk_product = $prodids[$prodid]; } @@ -2478,15 +2488,12 @@ class Contrat extends CommonObject // Clean data $clonedObj->statut = 0; // Clean extrafields - if (is_array($clonedObj->array_options) && count($clonedObj->array_options) > 0) - { + if (is_array($clonedObj->array_options) && count($clonedObj->array_options) > 0) { $extrafields->fetch_name_optionals_label($this->table_element); - foreach ($clonedObj->array_options as $key => $option) - { + foreach ($clonedObj->array_options as $key => $option) { $shortkey = preg_replace('/options_/', '', $key); //var_dump($shortkey); var_dump($extrafields->attributes[$this->element]['unique'][$shortkey]); - if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) - { + if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) { //var_dump($key); var_dump($clonedObj->array_options[$key]); exit; unset($clonedObj->array_options[$key]); } @@ -2546,8 +2553,9 @@ class Contrat extends CommonObject ); $action = ''; $reshook = $hookmanager->executeHooks('createFrom', $parameters, $clonedObj, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) + if ($reshook < 0) { $error++; + } } } @@ -2756,12 +2764,15 @@ class ContratLigne extends CommonObjectLine } $statusType = 'status'.$status; - if ($status == self::STATUS_OPEN && $expired == 1) $statusType = 'status1'; - if ($status == self::STATUS_CLOSED) $statusType = 'status6'; + if ($status == self::STATUS_OPEN && $expired == 1) { + $statusType = 'status1'; + } + if ($status == self::STATUS_CLOSED) { + $statusType = 'status6'; + } $params = array(); $reg = array(); - if (preg_match('/class="(.*)"/', $moreatt, $reg)) - { + if (preg_match('/class="(.*)"/', $moreatt, $reg)) { $params = array('badgeParams'=>array('css' => $reg[1])); } return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode, '', $params); @@ -2780,17 +2791,27 @@ class ContratLigne extends CommonObjectLine $result = ''; $label = $langs->trans("ShowContractOfService").': '.$this->label; - if (empty($label)) $label = $this->description; + if (empty($label)) { + $label = $this->description; + } $link = ''; $linkend = ''; $picto = 'service'; - if ($this->type == 0) $picto = 'product'; + if ($this->type == 0) { + $picto = 'product'; + } - if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); - if ($withpicto && $withpicto != 2) $result .= ' '; - if ($withpicto != 2) $result .= $link.($this->product_ref ? $this->product_ref.' ' : '').($this->label ? $this->label : $this->description).$linkend; + if ($withpicto) { + $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); + } + if ($withpicto && $withpicto != 2) { + $result .= ' '; + } + if ($withpicto != 2) { + $result .= $link.($this->product_ref ? $this->product_ref.' ' : '').($this->label ? $this->label : $this->description).$linkend; + } return $result; } @@ -2804,7 +2825,9 @@ class ContratLigne extends CommonObjectLine public function fetch($id, $ref = '') { // Check parameters - if (empty($id) && empty($ref)) return -1; + if (empty($id) && empty($ref)) { + return -1; + } $sql = "SELECT"; $sql .= " t.rowid,"; @@ -2849,15 +2872,17 @@ class ContratLigne extends CommonObjectLine $sql .= " t.commentaire,"; $sql .= " t.fk_unit"; $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as t LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = t.fk_product"; - if ($id) $sql .= " WHERE t.rowid = ".$id; - if ($ref) $sql .= " WHERE t.rowid = '".$this->db->escape($ref)."'"; + if ($id) { + $sql .= " WHERE t.rowid = ".$id; + } + if ($ref) { + $sql .= " WHERE t.rowid = '".$this->db->escape($ref)."'"; + } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { + if ($resql) { + if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -2966,18 +2991,40 @@ class ContratLigne extends CommonObjectLine $this->fk_user_cloture = (int) $this->fk_user_cloture; $this->commentaire = trim($this->commentaire); //if (empty($this->subprice)) $this->subprice = 0; - if (empty($this->price_ht)) $this->price_ht = 0; - if (empty($this->total_ht)) $this->total_ht = 0; - if (empty($this->total_tva)) $this->total_tva = 0; - if (empty($this->total_ttc)) $this->total_ttc = 0; - if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; - if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; - if (empty($this->remise_percent)) $this->remise_percent = 0; + if (empty($this->price_ht)) { + $this->price_ht = 0; + } + if (empty($this->total_ht)) { + $this->total_ht = 0; + } + if (empty($this->total_tva)) { + $this->total_tva = 0; + } + if (empty($this->total_ttc)) { + $this->total_ttc = 0; + } + if (empty($this->localtax1_tx)) { + $this->localtax1_tx = 0; + } + if (empty($this->localtax2_tx)) { + $this->localtax2_tx = 0; + } + if (empty($this->remise_percent)) { + $this->remise_percent = 0; + } // For backward compatibility - if (empty($this->date_start)) $this->date_start = $this->date_ouverture_prevue; - if (empty($this->date_start_real)) $this->date_start = $this->date_ouverture; - if (empty($this->date_end)) $this->date_start = $this->date_fin_validite; - if (empty($this->date_end_real)) $this->date_start = $this->date_cloture; + if (empty($this->date_start)) { + $this->date_start = $this->date_ouverture_prevue; + } + if (empty($this->date_start_real)) { + $this->date_start = $this->date_ouverture; + } + if (empty($this->date_end)) { + $this->date_start = $this->date_fin_validite; + } + if (empty($this->date_end_real)) { + $this->date_start = $this->date_cloture; + } // Check parameters @@ -2996,13 +3043,13 @@ class ContratLigne extends CommonObjectLine $this->total_localtax1 = $tabprice[9]; $this->total_localtax2 = $tabprice[10]; - if (empty($this->pa_ht)) $this->pa_ht = 0; + if (empty($this->pa_ht)) { + $this->pa_ht = 0; + } // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0) - { - if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) - { + if ($this->pa_ht == 0) { + if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { return $result; } else { $this->pa_ht = $result; @@ -3055,46 +3102,38 @@ class ContratLigne extends CommonObjectLine dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = "Error ".$this->db->lasterror(); $error++; } - if (!$error) // For avoid conflicts if trigger used - { + if (!$error) { // For avoid conflicts if trigger used $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } // If we change a planned date (start or end), sync dates for all services - if (!$error && !empty($conf->global->CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES)) - { - if ($this->date_ouverture_prevue != $this->oldcopy->date_ouverture_prevue) - { + if (!$error && !empty($conf->global->CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES)) { + if ($this->date_ouverture_prevue != $this->oldcopy->date_ouverture_prevue) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'contratdet SET'; $sql .= " date_ouverture_prevue = ".($this->date_ouverture_prevue != '' ? "'".$this->db->idate($this->date_ouverture_prevue)."'" : "null"); $sql .= " WHERE fk_contrat = ".$this->fk_contrat; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $error++; $this->error = "Error ".$this->db->lasterror(); } } - if ($this->date_fin_validite != $this->oldcopy->date_fin_validite) - { + if ($this->date_fin_validite != $this->oldcopy->date_fin_validite) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'contratdet SET'; $sql .= " date_fin_validite = ".($this->date_fin_validite != '' ? "'".$this->db->idate($this->date_fin_validite)."'" : "null"); $sql .= " WHERE fk_contrat = ".$this->fk_contrat; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $error++; $this->error = "Error ".$this->db->lasterror(); } @@ -3111,8 +3150,7 @@ class ContratLigne extends CommonObjectLine // End call triggers } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -3147,8 +3185,7 @@ class ContratLigne extends CommonObjectLine dol_syslog(get_class($this)."::update_total", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->db->commit(); return 1; } else { @@ -3178,8 +3215,12 @@ class ContratLigne extends CommonObjectLine $sql .= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; $sql .= " info_bits,"; $sql .= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht"; - if ($this->date_ouverture_prevue > 0) { $sql .= ",date_ouverture_prevue"; } - if ($this->date_fin_validite > 0) { $sql .= ",date_fin_validite"; } + if ($this->date_ouverture_prevue > 0) { + $sql .= ",date_ouverture_prevue"; + } + if ($this->date_fin_validite > 0) { + $sql .= ",date_fin_validite"; + } $sql .= ") VALUES ($this->fk_contrat, '', '".$this->db->escape($this->description)."',"; $sql .= ($this->fk_product > 0 ? $this->fk_product : "null").","; $sql .= " '".$this->db->escape($this->qty)."',"; @@ -3193,34 +3234,40 @@ class ContratLigne extends CommonObjectLine $sql .= " ".price2num($this->total_ht).",".price2num($this->total_tva).",".price2num($this->total_localtax1).",".price2num($this->total_localtax2).",".price2num($this->total_ttc).","; $sql .= " '".$this->db->escape($this->info_bits)."',"; $sql .= " ".price2num($this->price_ht).",".price2num($this->remise).","; - if ($this->fk_fournprice > 0) $sql .= ' '.$this->fk_fournprice.','; - else $sql .= ' null,'; - if ($this->pa_ht > 0) $sql .= ' '.price2num($this->pa_ht); - else $sql .= ' null'; - if ($this->date_ouverture > 0) { $sql .= ",'".$this->db->idate($this->date_ouverture)."'"; } - if ($this->date_cloture > 0) { $sql .= ",'".$this->db->idate($this->date_cloture)."'"; } + if ($this->fk_fournprice > 0) { + $sql .= ' '.$this->fk_fournprice.','; + } else { + $sql .= ' null,'; + } + if ($this->pa_ht > 0) { + $sql .= ' '.price2num($this->pa_ht); + } else { + $sql .= ' null'; + } + if ($this->date_ouverture > 0) { + $sql .= ",'".$this->db->idate($this->date_ouverture)."'"; + } + if ($this->date_cloture > 0) { + $sql .= ",'".$this->db->idate($this->date_cloture)."'"; + } $sql .= ")"; dol_syslog(get_class($this)."::insert", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'contratdet'); // Insert of extrafields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -1; } } - if (!$notrigger) - { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINECONTRACT_INSERT', $user); if ($result < 0) { @@ -3260,7 +3307,9 @@ class ContratLigne extends CommonObjectLine $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = ".ContratLigne::STATUS_OPEN.","; $sql .= " date_ouverture = ".(dol_strlen($date) != 0 ? "'".$this->db->idate($date)."'" : "null").","; - if ($date_end >= 0) $sql .= " date_fin_validite = ".(dol_strlen($date_end) != 0 ? "'".$this->db->idate($date_end)."'" : "null").","; + if ($date_end >= 0) { + $sql .= " date_fin_validite = ".(dol_strlen($date_end) != 0 ? "'".$this->db->idate($date_end)."'" : "null").","; + } $sql .= " fk_user_ouverture = ".$user->id.","; $sql .= " date_cloture = null,"; $sql .= " commentaire = '".$this->db->escape($comment)."'"; @@ -3271,11 +3320,12 @@ class ContratLigne extends CommonObjectLine if ($resql) { // Call trigger $result = $this->call_trigger('LINECONTRACT_ACTIVATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers - if (!$error) - { + if (!$error) { $this->statut = ContratLigne::STATUS_OPEN; $this->date_ouverture = $date; $this->date_fin_validite = $date_end; @@ -3329,10 +3379,8 @@ class ContratLigne extends CommonObjectLine $sql .= " WHERE rowid = ".$this->id." AND statut = ".ContratLigne::STATUS_OPEN; $resql = $this->db->query($sql); - if ($resql) - { - if (!$notrigger) - { + if ($resql) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINECONTRACT_CLOSE', $user); if ($result < 0) { diff --git a/htdocs/contrat/contact.php b/htdocs/contrat/contact.php index c837769819a..35b7268109b 100644 --- a/htdocs/contrat/contact.php +++ b/htdocs/contrat/contact.php @@ -43,7 +43,9 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'contrat', $id); $object = new Contrat($db); @@ -56,19 +58,16 @@ $hookmanager->initHooks(array('contractcard', 'globalcard')); * Actions */ -if ($action == 'addcontact' && $user->rights->contrat->creer) -{ +if ($action == 'addcontact' && $user->rights->contrat->creer) { $result = $object->fetch($id); - if ($result > 0 && $id > 0) - { + if ($result > 0 && $id > 0) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); } - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { @@ -84,10 +83,8 @@ if ($action == 'addcontact' && $user->rights->contrat->creer) } // bascule du statut d'un contact -if ($action == 'swapstatut' && $user->rights->contrat->creer) -{ - if ($object->fetch($id)) - { +if ($action == 'swapstatut' && $user->rights->contrat->creer) { + if ($object->fetch($id)) { $result = $object->swapContactStatus(GETPOST('ligne')); } else { dol_print_error($db, $object->error); @@ -95,13 +92,11 @@ if ($action == 'swapstatut' && $user->rights->contrat->creer) } // Delete contact -if ($action == 'deletecontact' && $user->rights->contrat->creer) -{ +if ($action == 'deletecontact' && $user->rights->contrat->creer) { $object->fetch($id); $result = $object->delete_contact($_GET["lineid"]); - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } @@ -125,10 +120,8 @@ $userstatic = new User($db); /* */ /* *************************************************************************** */ -if ($id > 0 || !empty($ref)) -{ - if ($object->fetch($id, $ref) > 0) - { +if ($id > 0 || !empty($ref)) { + if ($object->fetch($id, $ref) > 0) { $object->fetch_thirdparty(); $head = contract_prepare_head($object); @@ -146,9 +139,9 @@ if ($id > 0 || !empty($ref)) //if (! empty($modCodeContract->code_auto)) { $morehtmlref .= $object->ref; /*} else { - $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3); - $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2); - }*/ + $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3); + $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2); + }*/ $morehtmlref .= '
'; // Ref customer @@ -213,8 +206,11 @@ if ($id > 0 || !empty($ref)) } $absolute_discount = $object->thirdparty->getAvailableDiscounts(); print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + if ($absolute_discount) { + print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); + } else { + print $langs->trans("CompanyHasNoAbsoluteDiscount"); + } print '.'; print ''; diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index dfdb0fe6d31..8e5b1281c47 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -46,8 +46,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); // Security check -if ($user->socid > 0) -{ +if ($user->socid > 0) { unset($_GET["action"]); $action = ''; $socid = $user->socid; @@ -59,18 +58,23 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "ASC"; -if (!$sortfield) $sortfield = "name"; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "name"; +} $object = new Contrat($db); $object->fetch($id, $ref); -if ($object->id > 0) -{ +if ($object->id > 0) { $object->fetch_thirdparty(); } @@ -97,8 +101,7 @@ $form = new Form($db); llxHeader('', $langs->trans("Contract"), ""); -if ($object->id) -{ +if ($object->id) { $head = contract_prepare_head($object); print dol_get_fiche_head($head, 'documents', $langs->trans("Contract"), -1, 'contract'); @@ -107,8 +110,7 @@ if ($object->id) // Build file list $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $totalsize = 0; - foreach ($filearray as $key => $file) - { + foreach ($filearray as $key => $file) { $totalsize += $file['size']; } @@ -136,17 +138,18 @@ if ($object->id) $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef'); // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); - if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherContracts").')'; + if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) { + $morehtmlref .= ' ('.$langs->trans("OtherContracts").')'; + } // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->contrat->creer) - { - if ($action != 'classify') + if ($user->rights->contrat->creer) { + if ($action != 'classify') { //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; $morehtmlref .= ' : '; + } if ($action == 'classify') { //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); $morehtmlref .= '
'; diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index 5ea558c9689..6b1aecf1162 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -46,7 +46,9 @@ $statut = GETPOST('statut') ?GETPOST('statut') : 1; // Security check $socid = 0; $id = GETPOST('id', 'int'); -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'contrat', $id); $staticcompany = new Societe($db); @@ -78,11 +80,9 @@ print load_fiche_titre($langs->trans("ContractsArea"), '', 'contract'); print '
'; -if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo -{ +if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo // Search contract - if (!empty($conf->contrat->enabled)) - { + if (!empty($conf->contrat->enabled)) { print ''; print ''; @@ -112,26 +112,28 @@ $vals = array(); $sql = "SELECT count(cd.rowid) as nb, cd.statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid"; $sql .= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))"; $sql .= " AND c.entity IN (".getEntity('contract', 0).")"; -if ($user->socid) $sql .= ' AND c.fk_soc = '.$user->socid; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +if ($user->socid) { + $sql .= ' AND c.fk_soc = '.$user->socid; +} +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} $sql .= " GROUP BY cd.statut"; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); - if ($obj) - { + if ($obj) { $nb[$obj->status] = $obj->nb; - if ($obj->status != 5) - { + if ($obj->status != 5) { $vals[$obj->status] = $obj->nb; $totalinprocess += $obj->nb; } @@ -147,28 +149,30 @@ if ($resql) $sql = "SELECT count(cd.rowid) as nb, cd.statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid"; $sql .= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')"; $sql .= " AND c.entity IN (".getEntity('contract', 0).")"; -if ($user->socid) $sql .= ' AND c.fk_soc = '.$user->socid; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +if ($user->socid) { + $sql .= ' AND c.fk_soc = '.$user->socid; +} +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} $sql .= " GROUP BY cd.statut"; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); // 0 inactive, 4 active, 5 closed $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); - if ($obj) - { + if ($obj) { $nb[$obj->status.true] = $obj->nb; - if ($obj->status != 5) - { + if ($obj->status != 5) { $vals[$obj->status.true] = $obj->nb; $totalinprocess += $obj->nb; } @@ -189,26 +193,34 @@ print '
'; print '
'; print ''."\n"; $listofstatus = array(0, 4, 4, 5); $bool = false; -foreach ($listofstatus as $status) -{ +foreach ($listofstatus as $status) { $dataseries[] = array($staticcontratligne->LibStatut($status, 1, ($bool ? 1 : 0)), (isset($nb[$status.$bool]) ? (int) $nb[$status.$bool] : 0)); - if ($status == ContratLigne::STATUS_INITIAL) $colorseries[$status.$bool] = '-'.$badgeStatus0; - if ($status == ContratLigne::STATUS_OPEN && !$bool) $colorseries[$status.$bool] = $badgeStatus4; - if ($status == ContratLigne::STATUS_OPEN && $bool) $colorseries[$status.$bool] = $badgeStatus1; - if ($status == ContratLigne::STATUS_CLOSED) $colorseries[$status.$bool] = $badgeStatus6; + if ($status == ContratLigne::STATUS_INITIAL) { + $colorseries[$status.$bool] = '-'.$badgeStatus0; + } + if ($status == ContratLigne::STATUS_OPEN && !$bool) { + $colorseries[$status.$bool] = $badgeStatus4; + } + if ($status == ContratLigne::STATUS_OPEN && $bool) { + $colorseries[$status.$bool] = $badgeStatus1; + } + if ($status == ContratLigne::STATUS_CLOSED) { + $colorseries[$status.$bool] = $badgeStatus6; + } - if (empty($conf->use_javascript_ajax)) - { + if (empty($conf->use_javascript_ajax)) { print ''; print ''; print ''; print "\n"; } - if ($status == 4 && !$bool) $bool = true; - else $bool = false; + if ($status == 4 && !$bool) { + $bool = true; + } else { + $bool = false; + } } -if (!empty($conf->use_javascript_ajax)) -{ +if (!empty($conf->use_javascript_ajax)) { print ''; } $listofstatus = array(0, 4, 4, 5); $bool = false; -foreach ($listofstatus as $status) -{ - if (empty($conf->use_javascript_ajax)) - { +foreach ($listofstatus as $status) { + if (empty($conf->use_javascript_ajax)) { print ''; print ''; print ''; - if ($status == 4 && !$bool) $bool = true; - else $bool = false; + if ($status == 4 && !$bool) { + $bool = true; + } else { + $bool = false; + } print "\n"; } } @@ -245,36 +258,38 @@ print "
'.$langs->trans("Statistics").' - '.$langs->trans("Services").'
'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).''.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'
'; include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; @@ -225,15 +237,16 @@ if (!empty($conf->use_javascript_ajax)) print '
'.$staticcontratligne->LibStatut($status, 0, ($bool ? 1 : 0)).''.($nb[$status.$bool] ? $nb[$status.$bool] : 0).' '.$staticcontratligne->LibStatut($status, 3, ($bool ? 1 : 0)).'

"; // Draft contracts -if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) -{ +if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) { $sql = "SELECT c.rowid, c.ref,"; $sql .= " s.nom as name, s.rowid as socid"; $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE s.rowid = c.fk_soc"; $sql .= " AND c.entity IN (".getEntity('contract', 0).")"; $sql .= " AND c.statut = 0"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - if ($socid) $sql .= " AND c.fk_soc = ".$socid; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) { + $sql .= " AND c.fk_soc = ".$socid; + } $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); print '
'; print ''; print ''; print ''; - if ($num) - { + if ($num) { $companystatic = new Societe($db); $i = 0; //$tot_ttc = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); $staticcontrat->ref = $obj->ref; @@ -319,22 +334,27 @@ $sql .= ' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AN $sql .= ' sum('.$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,'; $sql .= " c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom as name, s.rowid as socid"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,"; +} $sql .= " ".MAIN_DB_PREFIX."contrat as c"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('contract', 0).")"; $sql .= " AND c.statut > 0"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; -if ($socid) $sql .= " AND s.rowid = ".$socid; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} +if ($socid) { + $sql .= " AND s.rowid = ".$socid; +} $sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid"; $sql .= " ORDER BY c.tms DESC"; $sql .= " LIMIT ".$max; dol_syslog("contrat/index.php", LOG_DEBUG); $result = $db->query($sql); -if ($result) -{ +if ($result) { $num = $db->num_rows($result); $i = 0; @@ -347,8 +367,7 @@ if ($result) print ''; print "\n"; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($result); print ''; @@ -356,7 +375,9 @@ if ($result) $staticcontrat->ref = ($obj->ref ? $obj->ref : $obj->cid); $staticcontrat->id = $obj->cid; print $staticcontrat->getNomUrl(1, 16); - if ($obj->nb_late) print img_warning($langs->trans("Late")); + if ($obj->nb_late) { + print img_warning($langs->trans("Late")); + } print ''; print ''; print "\n"; - while ($i < min($num, $max)) - { + while ($i < min($num, $max)) { $obj = $db->fetch_object($resql); print ''; @@ -422,8 +447,7 @@ if ($resql) //if (1 == 1) print img_warning($langs->trans("Late")); print ''; print ''; print ''; print "\n"; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); print ''; @@ -498,8 +529,7 @@ if ($resql) print $staticcontrat->getNomUrl(1, 16); print ''; print ''; print ''; print "\n"; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); print ''; @@ -574,8 +611,7 @@ if ($resql) print $staticcontrat->getNomUrl(1, 16); print ''; print ''; print '
'.$langs->trans("DraftContracts").($num ? ''.$num.'' : '').'
'.$langs->trans("Services").'
'; $staticcompany->id = $obj->socid; @@ -388,19 +409,24 @@ $sql .= " s.nom as name,"; $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity"; $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")"; $sql .= " AND cd.fk_contrat = c.rowid"; $sql .= " AND c.fk_soc = s.rowid"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; -if ($socid) $sql .= " AND s.rowid = ".$socid; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} +if ($socid) { + $sql .= " AND s.rowid = ".$socid; +} $sql .= " ORDER BY cd.tms DESC"; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -410,8 +436,7 @@ if ($resql) print '
'.$langs->trans("LastModifiedServices", $max).'
'; - if ($obj->fk_product > 0) - { + if ($obj->fk_product > 0) { $productstatic->id = $obj->fk_product; $productstatic->type = $obj->ptype; $productstatic->ref = $obj->pref; @@ -431,8 +455,11 @@ if ($resql) print $productstatic->getNomUrl(1, '', 20); } else { print ''.img_object($langs->trans("ShowService"), "service"); - if ($obj->label) print ' '.dol_trunc($obj->label, 20).''; - else print ' '.dol_trunc($obj->note, 20); + if ($obj->label) { + print ' '.dol_trunc($obj->label, 20).''; + } else { + print ' '.dol_trunc($obj->note, 20); + } } print ''; @@ -462,7 +489,9 @@ $sql .= " s.nom as name,"; $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity"; $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")"; @@ -470,13 +499,16 @@ $sql .= " AND c.statut = 1"; $sql .= " AND cd.statut = 0"; $sql .= " AND cd.fk_contrat = c.rowid"; $sql .= " AND c.fk_soc = s.rowid"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; -if ($socid) $sql .= " AND s.rowid = ".$socid; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} +if ($socid) { + $sql .= " AND s.rowid = ".$socid; +} $sql .= " ORDER BY cd.tms DESC"; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -486,8 +518,7 @@ if ($resql) print '
'.$langs->trans("NotActivatedServices").' '.$num.'
'; - if ($obj->fk_product > 0) - { + if ($obj->fk_product > 0) { $productstatic->id = $obj->fk_product; $productstatic->type = $obj->ptype; $productstatic->ref = $obj->pref; @@ -507,8 +537,11 @@ if ($resql) print $productstatic->getNomUrl(1, '', 20); } else { print ''.img_object($langs->trans("ShowService"), "service"); - if ($obj->label) print ' '.dol_trunc($obj->label, 20).''; - else print ' '.dol_trunc($obj->note, 20); + if ($obj->label) { + print ' '.dol_trunc($obj->label, 20).''; + } else { + print ' '.dol_trunc($obj->note, 20); + } } print ''; @@ -537,7 +570,9 @@ $sql .= " s.nom as name,"; $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity"; $sql .= " FROM (".MAIN_DB_PREFIX."contrat as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql .= " WHERE c.entity IN (".getEntity('contract', 0).")"; @@ -546,13 +581,16 @@ $sql .= " AND cd.statut = 4"; $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'"; $sql .= " AND cd.fk_contrat = c.rowid"; $sql .= " AND c.fk_soc = s.rowid"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; -if ($socid) $sql .= " AND s.rowid = ".$socid; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} +if ($socid) { + $sql .= " AND s.rowid = ".$socid; +} $sql .= " ORDER BY cd.tms DESC"; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -562,8 +600,7 @@ if ($resql) print '
'.$langs->trans("ListOfExpiredServices").' '.$num.'
'; - if ($obj->fk_product > 0) - { + if ($obj->fk_product > 0) { $productstatic->id = $obj->fk_product; $productstatic->type = $obj->ptype; $productstatic->ref = $obj->pref; @@ -583,8 +619,11 @@ if ($resql) print $productstatic->getNomUrl(1, '', 20); } else { print ''.img_object($langs->trans("ShowService"), "service"); - if ($obj->label) print ' '.dol_trunc($obj->label, 20).''; - else print ' '.dol_trunc($obj->note, 20); + if ($obj->label) { + print ' '.dol_trunc($obj->label, 20).''; + } else { + print ' '.dol_trunc($obj->note, 20); + } } print ''; diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index a890b1f3ce2..27cbf5a3a70 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -76,16 +76,24 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = 'c.ref'; -if (!$sortorder) $sortorder = 'DESC'; +if (!$sortfield) { + $sortfield = 'c.ref'; +} +if (!$sortorder) { + $sortorder = 'DESC'; +} // Security check $id = GETPOST('id', 'int'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'contrat', $id); $diroutputmassaction = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id; @@ -93,7 +101,9 @@ $diroutputmassaction = $conf->contrat->dir_output.'/temp/massgeneration/'.$user- $staticcontrat = new Contrat($db); $staticcontratligne = new ContratLigne($db); -if ($search_status == '') $search_status = 1; +if ($search_status == '') { + $search_status = 1; +} // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $object = new Contrat($db); @@ -112,7 +122,9 @@ $fieldstosearchall = array( 's.nom'=>"ThirdParty", 'c.note_public'=>'NotePublic', ); -if (empty($user->socid)) $fieldstosearchall["c.note_private"] = "NotePrivate"; +if (empty($user->socid)) { + $fieldstosearchall["c.note_private"] = "NotePrivate"; +} $arrayfields = array( 'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>10), @@ -142,18 +154,23 @@ $arrayfields = dol_sort_array($arrayfields, 'position'); * Action */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $parameters = array('socid'=>$socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers $day = ''; $month = ''; $year = ''; @@ -180,8 +197,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_array_options = array(); } -if (empty($reshook)) -{ +if (empty($reshook)) { $objectclass = 'Contrat'; $objectlabel = 'Contracts'; $permissiontoread = $user->rights->contrat->lire; @@ -216,7 +232,9 @@ $sql .= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AN $sql .= ' SUM('.$db->ifsql("cd.statut=5", 1, 0).') as nb_closed'; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + } } // Add fields from hooks $parameters = array(); @@ -226,34 +244,60 @@ $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; -if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= ", ".MAIN_DB_PREFIX."contrat as c"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)"; +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; -if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product'; -if ($search_user > 0) -{ +if ($search_product_category > 0) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product'; +} +if ($search_user > 0) { $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql .= " WHERE c.fk_soc = s.rowid "; $sql .= ' AND c.entity IN ('.getEntity('contract').')'; -if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')'; -if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category; -if ($socid) $sql .= " AND s.rowid = ".$db->escape($socid); -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { + $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')'; +} +if ($search_product_category > 0) { + $sql .= " AND cp.fk_categorie = ".$search_product_category; +} +if ($socid) { + $sql .= " AND s.rowid = ".$db->escape($socid); +} +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} $sql .= dolSqlDateFilter('c.date_contrat', $day, $month, $year); -if ($search_name) $sql .= natural_search('s.nom', $search_name); -if ($search_email) $sql .= natural_search('s.email', $search_email); -if ($search_contract) $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract); -if (!empty($search_ref_customer)) $sql .= natural_search(array('c.ref_customer'), $search_ref_customer); -if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier); -if ($search_sale > 0) -{ +if ($search_name) { + $sql .= natural_search('s.nom', $search_name); +} +if ($search_email) { + $sql .= natural_search('s.email', $search_email); +} +if ($search_contract) { + $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract); +} +if (!empty($search_ref_customer)) { + $sql .= natural_search(array('c.ref_customer'), $search_ref_customer); +} +if (!empty($search_ref_supplier)) { + $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier); +} +if ($search_sale > 0) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale; } -if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall); -if ($search_user > 0) $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user; +if ($sall) { + $sql .= natural_search(array_keys($fieldstosearchall), $sall); +} +if ($search_user > 0) { + $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user; +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -266,34 +310,36 @@ $sql .= " typent.code,"; $sql .= " state.code_departement, state.nom"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : ''); + } } // Add where from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; -if ($search_dfyear > 0 && $search_op2df) -{ - if ($search_op2df == '<=') $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'"; - elseif ($search_op2df == '>=') $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'"; - else $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'"; +if ($search_dfyear > 0 && $search_op2df) { + if ($search_op2df == '<=') { + $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'"; + } elseif ($search_op2df == '>=') { + $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'"; + } else { + $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'"; + } } $sql .= $db->order($sortfield, $sortorder); $totalnboflines = 0; $result = $db->query($sql); -if ($result) -{ +if ($result) { $totalnboflines = $db->num_rows($result); } $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -302,8 +348,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); -if (!$resql) -{ +if (!$resql) { dol_print_error($db); exit; } @@ -311,8 +356,7 @@ if (!$resql) $num = $db->num_rows($resql); // Direct jump if only one record found -if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall && !$page) -{ +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall && !$page) { $obj = $db->fetch_object($resql); $id = $obj->rowid; header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id); @@ -329,31 +373,66 @@ $i = 0; $arrayofselected = is_array($toselect) ? $toselect : array(); -if ($socid > 0) -{ +if ($socid > 0) { $soc = new Societe($db); $soc->fetch($socid); - if (empty($search_name)) $search_name = $soc->name; + if (empty($search_name)) { + $search_name = $soc->name; + } } $param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); -if ($sall != '') $param .= '&sall='.urlencode($sall); -if ($search_contract != '') $param .= '&search_contract='.urlencode($search_contract); -if ($search_name != '') $param .= '&search_name='.urlencode($search_name); -if ($search_email != '') $param .= '&search_email='.urlencode($search_email); -if ($search_ref_customer != '') $param .= '&search_ref_customer='.urlencode($search_ref_customer); -if ($search_ref_supplier != '') $param .= '&search_ref_supplier='.urlencode($search_ref_supplier); -if ($search_op2df != '') $param .= '&search_op2df='.urlencode($search_op2df); -if ($search_dfyear != '') $param .= '&search_dfyear='.urlencode($search_dfyear); -if ($search_dfmonth != '') $param .= '&search_dfmonth='.urlencode($search_dfmonth); -if ($search_sale != '') $param .= '&search_sale='.urlencode($search_sale); -if ($search_user != '') $param .= '&search_user='.urlencode($search_user); -if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); -if ($search_product_category != '') $param .= '&search_product_category='.urlencode($search_product_category); -if ($show_files) $param .= '&show_files='.urlencode($show_files); -if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +if ($sall != '') { + $param .= '&sall='.urlencode($sall); +} +if ($search_contract != '') { + $param .= '&search_contract='.urlencode($search_contract); +} +if ($search_name != '') { + $param .= '&search_name='.urlencode($search_name); +} +if ($search_email != '') { + $param .= '&search_email='.urlencode($search_email); +} +if ($search_ref_customer != '') { + $param .= '&search_ref_customer='.urlencode($search_ref_customer); +} +if ($search_ref_supplier != '') { + $param .= '&search_ref_supplier='.urlencode($search_ref_supplier); +} +if ($search_op2df != '') { + $param .= '&search_op2df='.urlencode($search_op2df); +} +if ($search_dfyear != '') { + $param .= '&search_dfyear='.urlencode($search_dfyear); +} +if ($search_dfmonth != '') { + $param .= '&search_dfmonth='.urlencode($search_dfmonth); +} +if ($search_sale != '') { + $param .= '&search_sale='.urlencode($search_sale); +} +if ($search_user != '') { + $param .= '&search_user='.urlencode($search_user); +} +if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { + $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); +} +if ($search_product_category != '') { + $param .= '&search_product_category='.urlencode($search_product_category); +} +if ($show_files) { + $param .= '&show_files='.urlencode($show_files); +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); +} // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -363,16 +442,24 @@ $arrayofmassactions = array( 'builddoc'=>$langs->trans("PDFMerge"), 'presend'=>$langs->trans("SendByMail"), ); -if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); -if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); +if ($user->rights->contrat->supprimer) { + $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); +} +if (in_array($massaction, array('presend', 'predelete'))) { + $arrayofmassactions = array(); +} $massactionbutton = $form->selectMassAction('', $arrayofmassactions); $url = DOL_URL_ROOT.'/contrat/card.php?action=create'; -if (!empty($socid)) $url .= '&socid='.$socid; +if (!empty($socid)) { + $url .= '&socid='.$socid; +} $newcardbutton = dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->rights->contrat->creer); print ''; -if ($optioncss != '') print ''; +if ($optioncss != '') { + print ''; +} print ''; print ''; print ''; @@ -388,17 +475,17 @@ $objecttmp = new Contrat($db); $trackid = 'con'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; -if ($sall) -{ - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); +if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } $moreforfilter = ''; // If the user can view prospects other than his' -if ($user->rights->societe->client->voir || $socid) -{ +if ($user->rights->societe->client->voir || $socid) { $langs->load("commercial"); $moreforfilter .= '
'; $moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': '; @@ -406,16 +493,14 @@ if ($user->rights->societe->client->voir || $socid) $moreforfilter .= '
'; } // If the user can view other users -if ($user->rights->user->user->lire) -{ +if ($user->rights->user->user->lire) { $moreforfilter .= '
'; $moreforfilter .= $langs->trans('LinkedToSpecificUsers').': '; $moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); - $moreforfilter .= '
'; + $moreforfilter .= ''; } // If the user can view categories of products -if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) -{ +if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) { include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '
'; $moreforfilter .= $langs->trans('IncludingProductWithTag').': '; @@ -426,11 +511,13 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($use $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; -else $moreforfilter = $hookmanager->resPrint; +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} -if (!empty($moreforfilter)) -{ +if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -438,77 +525,75 @@ if (!empty($moreforfilter)) $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields -if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); +if ($massactionbutton) { + $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); +} print '
'; print ''."\n"; print ''; -if (!empty($arrayfields['c.ref']['checked'])) -{ +if (!empty($arrayfields['c.ref']['checked'])) { print ''; } -if (!empty($arrayfields['c.ref_customer']['checked'])) -{ +if (!empty($arrayfields['c.ref_customer']['checked'])) { print ''; } -if (!empty($arrayfields['c.ref_supplier']['checked'])) -{ +if (!empty($arrayfields['c.ref_supplier']['checked'])) { print ''; } -if (!empty($arrayfields['s.nom']['checked'])) -{ +if (!empty($arrayfields['s.nom']['checked'])) { print ''; } -if (!empty($arrayfields['s.email']['checked'])) -{ +if (!empty($arrayfields['s.email']['checked'])) { print ''; } // Town -if (!empty($arrayfields['s.town']['checked'])) print ''; +if (!empty($arrayfields['s.town']['checked'])) { + print ''; +} // Zip -if (!empty($arrayfields['s.zip']['checked'])) print ''; +if (!empty($arrayfields['s.zip']['checked'])) { + print ''; +} // State -if (!empty($arrayfields['state.nom']['checked'])) -{ +if (!empty($arrayfields['state.nom']['checked'])) { print ''; } // Country -if (!empty($arrayfields['country.code_iso']['checked'])) -{ +if (!empty($arrayfields['country.code_iso']['checked'])) { print ''; } // Company type -if (!empty($arrayfields['typent.code']['checked'])) -{ +if (!empty($arrayfields['typent.code']['checked'])) { print ''; } -if (!empty($arrayfields['sale_representative']['checked'])) -{ +if (!empty($arrayfields['sale_representative']['checked'])) { print ''; } -if (!empty($arrayfields['c.date_contrat']['checked'])) -{ +if (!empty($arrayfields['c.date_contrat']['checked'])) { // Date contract print ''; } // Date modification -if (!empty($arrayfields['c.tms']['checked'])) -{ +if (!empty($arrayfields['c.tms']['checked'])) { print ''; } // First end date -if (!empty($arrayfields['lower_planned_end_date']['checked'])) -{ +if (!empty($arrayfields['lower_planned_end_date']['checked'])) { print ''; } // Status -if (!empty($arrayfields['status']['checked'])) -{ +if (!empty($arrayfields['status']['checked'])) { print ''; } print ''; print "\n"; print ''; -if (!empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['c.ref_customer']['checked'])) print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['c.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['s.email']['checked'])) print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); -if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); -if (!empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['c.date_contrat']['checked'])) print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center '); +if (!empty($arrayfields['c.ref']['checked'])) { + print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['c.ref_customer']['checked'])) { + print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['c.ref_supplier']['checked'])) { + print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['s.nom']['checked'])) { + print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['s.email']['checked'])) { + print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['s.town']['checked'])) { + print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['s.zip']['checked'])) { + print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['state.nom']['checked'])) { + print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['country.code_iso']['checked'])) { + print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['typent.code']['checked'])) { + print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['sale_representative']['checked'])) { + print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['c.date_contrat']['checked'])) { + print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center '); +} // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields @@ -598,8 +703,7 @@ $totalarray = array(); $typenArray = array(); $cacheCountryIDCode = array(); -while ($i < min($num, $limit)) -{ +while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); $contracttmp->ref = $obj->ref; @@ -632,11 +736,12 @@ while ($i < min($num, $limit)) print ''; // Ref - if (!empty($arrayfields['c.ref']['checked'])) - { + if (!empty($arrayfields['c.ref']['checked'])) { print ''; } - if (!empty($arrayfields['c.ref_customer']['checked'])) - { + if (!empty($arrayfields['c.ref_customer']['checked'])) { print ''; } - if (!empty($arrayfields['c.ref_supplier']['checked'])) - { + if (!empty($arrayfields['c.ref_supplier']['checked'])) { print ''; } - if (!empty($arrayfields['s.nom']['checked'])) - { + if (!empty($arrayfields['s.nom']['checked'])) { print ''; } - if (!empty($arrayfields['s.email']['checked'])) - { + if (!empty($arrayfields['s.email']['checked'])) { print ''; } // Town - if (!empty($arrayfields['s.town']['checked'])) - { + if (!empty($arrayfields['s.town']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Zip - if (!empty($arrayfields['s.zip']['checked'])) - { + if (!empty($arrayfields['s.zip']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // State - if (!empty($arrayfields['state.nom']['checked'])) - { + if (!empty($arrayfields['state.nom']['checked'])) { print "\n"; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Country - if (!empty($arrayfields['country.code_iso']['checked'])) - { + if (!empty($arrayfields['country.code_iso']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Type ent - if (!empty($arrayfields['typent.code']['checked'])) - { + if (!empty($arrayfields['typent.code']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['sale_representative']['checked'])) - { + if (!empty($arrayfields['sale_representative']['checked'])) { // Sales representatives print ''; } // Date - if (!empty($arrayfields['c.date_contrat']['checked'])) - { + if (!empty($arrayfields['c.date_contrat']['checked'])) { print ''; } // Extra fields @@ -767,32 +874,34 @@ while ($i < min($num, $limit)) $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['c.datec']['checked'])) - { + if (!empty($arrayfields['c.datec']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date modification - if (!empty($arrayfields['c.tms']['checked'])) - { + if (!empty($arrayfields['c.tms']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date lower end date - if (!empty($arrayfields['lower_planned_end_date']['checked'])) - { + if (!empty($arrayfields['lower_planned_end_date']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Status - if (!empty($arrayfields['status']['checked'])) - { + if (!empty($arrayfields['status']['checked'])) { print ''; print ''; print ''; @@ -800,14 +909,17 @@ while ($i < min($num, $limit)) } // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print "\n"; $i++; @@ -824,7 +936,9 @@ print ''; print ''; $hidegeneratedfilelistifempty = 1; -if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; +if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; +} // Show list of available documents $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; diff --git a/htdocs/contrat/note.php b/htdocs/contrat/note.php index c9000c4fb0d..d61ac357a40 100644 --- a/htdocs/contrat/note.php +++ b/htdocs/contrat/note.php @@ -41,7 +41,9 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'contrat', $id); $object = new Contrat($db); @@ -70,8 +72,7 @@ llxHeader('', $langs->trans("Contract"), ""); $form = new Form($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $object->fetch_thirdparty(); $head = contract_prepare_head($object); @@ -89,9 +90,9 @@ if ($id > 0 || !empty($ref)) //if (! empty($modCodeContract->code_auto)) { $morehtmlref .= $object->ref; /*} else { - $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3); - $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2); - }*/ + $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3); + $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2); + }*/ $morehtmlref .= '
'; // Ref customer @@ -104,15 +105,14 @@ if ($id > 0 || !empty($ref)) // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->contrat->creer) - { - if ($action != 'classify') + if ($user->rights->contrat->creer) { + if ($action != 'classify') { //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; $morehtmlref .= ' : '; + } if ($action == 'classify') { //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); $morehtmlref .= '
'; @@ -150,12 +150,18 @@ if ($id > 0 || !empty($ref)) // Ligne info remises tiers print '
'; diff --git a/htdocs/contrat/services_list.php b/htdocs/contrat/services_list.php index 4de651a24f9..072982e56eb 100644 --- a/htdocs/contrat/services_list.php +++ b/htdocs/contrat/services_list.php @@ -39,12 +39,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortfield) $sortfield = "c.rowid"; -if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { + $sortfield = "c.rowid"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} $mode = GETPOST("mode"); $filter = GETPOST("filter"); @@ -90,22 +96,32 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen // Security check $contratid = GETPOST('id', 'int'); -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'contrat', $contratid); -if ($search_status != '') -{ +if ($search_status != '') { $tmp = explode('&', $search_status); $mode = $tmp[0]; - if (empty($tmp[1])) $filter = ''; - else { - if ($tmp[1] == 'filter=notexpired') $filter = 'notexpired'; - if ($tmp[1] == 'filter=expired') $filter = 'expired'; + if (empty($tmp[1])) { + $filter = ''; + } else { + if ($tmp[1] == 'filter=notexpired') { + $filter = 'notexpired'; + } + if ($tmp[1] == 'filter=expired') { + $filter = 'expired'; + } } } else { $search_status = $mode; - if ($filter == 'expired') $search_status .= '&filter=expired'; - if ($filter == 'notexpired') $search_status .= '&filter=notexpired'; + if ($filter == 'expired') { + $search_status .= '&filter=expired'; + } + if ($filter == 'notexpired') { + $search_status .= '&filter=notexpired'; + } } $staticcontrat = new Contrat($db); @@ -142,21 +158,25 @@ $arrayfields = dol_sort_array($arrayfields, 'position'); * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { + $massaction = ''; +} $parameters = array('socid'=>$socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers - { - $search_product_category = 0; + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers + $search_product_category = 0; $search_name = ""; $search_contract = ""; $search_service = ""; @@ -197,7 +217,9 @@ $sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut, c.ref_customer, c.ref $sql .= " s.rowid as socid, s.nom as name, s.email, s.client, s.fournisseur,"; $sql .= " cd.rowid, cd.description, cd.statut,"; $sql .= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype, p.entity as pentity,"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " sc.fk_soc, sc.fk_user,"; +} $sql .= " cd.date_ouverture_prevue,"; $sql .= " cd.date_ouverture,"; $sql .= " cd.date_fin_validite,"; @@ -211,7 +233,9 @@ $sql .= " cd.subprice,"; $sql .= " cd.tms as date_update"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + } } // Add fields from hooks $parameters = array(); @@ -219,50 +243,102 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,"; $sql .= " ".MAIN_DB_PREFIX."societe as s,"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,"; +} $sql .= " ".MAIN_DB_PREFIX."contratdet as cd"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cd.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cd.rowid = ef.fk_object)"; +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; -if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product'; +if ($search_product_category > 0) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product'; +} $sql .= " WHERE c.entity = ".$conf->entity; $sql .= " AND c.rowid = cd.fk_contrat"; -if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category; +if ($search_product_category > 0) { + $sql .= " AND cp.fk_categorie = ".$search_product_category; +} $sql .= " AND c.fk_soc = s.rowid"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; -if ($mode == "0") $sql .= " AND cd.statut = 0"; -if ($mode == "4") $sql .= " AND cd.statut = 4"; -if ($mode == "5") $sql .= " AND cd.statut = 5"; -if ($filter == "expired") $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'"; -if ($filter == "notexpired") $sql .= " AND cd.date_fin_validite >= '".$db->idate($now)."'"; -if ($search_name) $sql .= " AND s.nom LIKE '%".$db->escape($search_name)."%'"; -if ($search_contract) $sql .= " AND c.ref LIKE '%".$db->escape($search_contract)."%' "; -if ($search_service) $sql .= " AND (p.ref LIKE '%".$db->escape($search_service)."%' OR p.description LIKE '%".$db->escape($search_service)."%' OR cd.description LIKE '%".$db->escape($search_service)."%')"; -if ($socid > 0) $sql .= " AND s.rowid = ".$socid; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} +if ($mode == "0") { + $sql .= " AND cd.statut = 0"; +} +if ($mode == "4") { + $sql .= " AND cd.statut = 4"; +} +if ($mode == "5") { + $sql .= " AND cd.statut = 5"; +} +if ($filter == "expired") { + $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'"; +} +if ($filter == "notexpired") { + $sql .= " AND cd.date_fin_validite >= '".$db->idate($now)."'"; +} +if ($search_name) { + $sql .= " AND s.nom LIKE '%".$db->escape($search_name)."%'"; +} +if ($search_contract) { + $sql .= " AND c.ref LIKE '%".$db->escape($search_contract)."%' "; +} +if ($search_service) { + $sql .= " AND (p.ref LIKE '%".$db->escape($search_service)."%' OR p.description LIKE '%".$db->escape($search_service)."%' OR cd.description LIKE '%".$db->escape($search_service)."%')"; +} +if ($socid > 0) { + $sql .= " AND s.rowid = ".$socid; +} $filter_dateouvertureprevue_start = dol_mktime(0, 0, 0, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear); $filter_dateouvertureprevue_end = dol_mktime(23, 59, 59, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear); -if ($filter_dateouvertureprevue_start != '' && $filter_opouvertureprevue == -1) $filter_opouvertureprevue = ' BETWEEN '; +if ($filter_dateouvertureprevue_start != '' && $filter_opouvertureprevue == -1) { + $filter_opouvertureprevue = ' BETWEEN '; +} $filter_date1_start = dol_mktime(0, 0, 0, $op1month, $op1day, $op1year); $filter_date1_end = dol_mktime(23, 59, 59, $op1month, $op1day, $op1year); -if ($filter_date1_start != '' && $filter_op1 == -1) $filter_op1 = ' BETWEEN '; +if ($filter_date1_start != '' && $filter_op1 == -1) { + $filter_op1 = ' BETWEEN '; +} $filter_date2_start = dol_mktime(0, 0, 0, $op2month, $op2day, $op2year); $filter_date2_end = dol_mktime(23, 59, 59, $op2month, $op2day, $op2year); -if ($filter_date2_start != '' && $filter_op2 == -1) $filter_op2 = ' BETWEEN '; +if ($filter_date2_start != '' && $filter_op2 == -1) { + $filter_op2 = ' BETWEEN '; +} $filter_datecloture_start = dol_mktime(0, 0, 0, $opcloturemonth, $opclotureday, $opclotureyear); $filter_datecloture_end = dol_mktime(23, 59, 59, $opcloturemonth, $opclotureday, $opclotureyear); -if ($filter_datecloture_start != '' && $filter_opcloture == -1) $filter_opcloture = ' BETWEEN '; +if ($filter_datecloture_start != '' && $filter_opcloture == -1) { + $filter_opcloture = ' BETWEEN '; +} -if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_opouvertureprevue != ' BETWEEN ' && $filter_dateouvertureprevue_start != '') $sql .= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."'"; -if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_dateouvertureprevue_end)."'"; -if (!empty($filter_op1) && $filter_op1 != -1 && $filter_op1 != ' BETWEEN ' && $filter_date1_start != '') $sql .= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."'"; -if (!empty($filter_op1) && $filter_op1 == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_date1_end)."'"; -if (!empty($filter_op2) && $filter_op2 != -1 && $filter_op2 != ' BETWEEN ' && $filter_date2_start != '') $sql .= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."'"; -if (!empty($filter_op2) && $filter_op2 == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_date2_end)."'"; -if (!empty($filter_opcloture) && $filter_opcloture != ' BETWEEN ' && $filter_opcloture != -1 && $filter_datecloture_start != '') $sql .= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."'"; -if (!empty($filter_opcloture) && $filter_opcloture == ' BETWEEN ') $sql .= " AND '".$db->idate($filter_datecloture_end)."'"; +if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_opouvertureprevue != ' BETWEEN ' && $filter_dateouvertureprevue_start != '') { + $sql .= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."'"; +} +if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue == ' BETWEEN ') { + $sql .= " AND '".$db->idate($filter_dateouvertureprevue_end)."'"; +} +if (!empty($filter_op1) && $filter_op1 != -1 && $filter_op1 != ' BETWEEN ' && $filter_date1_start != '') { + $sql .= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."'"; +} +if (!empty($filter_op1) && $filter_op1 == ' BETWEEN ') { + $sql .= " AND '".$db->idate($filter_date1_end)."'"; +} +if (!empty($filter_op2) && $filter_op2 != -1 && $filter_op2 != ' BETWEEN ' && $filter_date2_start != '') { + $sql .= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."'"; +} +if (!empty($filter_op2) && $filter_op2 == ' BETWEEN ') { + $sql .= " AND '".$db->idate($filter_date2_end)."'"; +} +if (!empty($filter_opcloture) && $filter_opcloture != ' BETWEEN ' && $filter_opcloture != -1 && $filter_datecloture_start != '') { + $sql .= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."'"; +} +if (!empty($filter_opcloture) && $filter_opcloture == ' BETWEEN ') { + $sql .= " AND '".$db->idate($filter_datecloture_end)."'"; +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; $sql .= $db->order($sortfield, $sortorder); @@ -270,12 +346,10 @@ $sql .= $db->order($sortfield, $sortorder); //print $sql; $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -286,8 +360,7 @@ $sql .= $db->plimit($limit + 1, $offset); //print $sql; dol_syslog("contrat/services_list.php", LOG_DEBUG); $resql = $db->query($sql); -if (!$resql) -{ +if (!$resql) { dol_print_error($db); exit; } @@ -297,31 +370,63 @@ $num = $db->num_rows($resql); /* if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) { - $obj = $db->fetch_object($resql); - $id = $obj->id; - header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1'); - exit; + $obj = $db->fetch_object($resql); + $id = $obj->id; + header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1'); + exit; }*/ llxHeader(null, $langs->trans("Services")); $param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; -if ($search_contract) $param .= '&search_contract='.urlencode($search_contract); -if ($search_name) $param .= '&search_name='.urlencode($search_name); -if ($search_service) $param .= '&search_service='.urlencode($search_service); -if ($mode) $param .= '&mode='.urlencode($mode); -if ($filter) $param .= '&filter='.urlencode($filter); -if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) $param .= '&filter_opouvertureprevue='.urlencode($filter_opouvertureprevue); -if (!empty($filter_op1) && $filter_op1 != -1) $param .= '&filter_op1='.urlencode($filter_op1); -if (!empty($filter_op2) && $filter_op2 != -1) $param .= '&filter_op2='.urlencode($filter_op2); -if (!empty($filter_opcloture) && $filter_opcloture != -1) $param .= '&filter_opcloture='.urlencode($filter_opcloture); -if ($filter_dateouvertureprevue != '') $param .= '&opouvertureprevueday='.$opouvertureprevueday.'&opouvertureprevuemonth='.$opouvertureprevuemonth.'&opouvertureprevueyear='.$opouvertureprevueyear; -if ($filter_date1 != '') $param .= '&op1day='.$op1day.'&op1month='.$op1month.'&op1year='.$op1year; -if ($filter_date2 != '') $param .= '&op2day='.$op2day.'&op2month='.$op2month.'&op2year='.$op2year; -if ($filter_datecloture != '') $param .= '&opclotureday='.$op2day.'&opcloturemonth='.$op2month.'&opclotureyear='.$op2year; -if ($optioncss != '') $param .= '&optioncss='.$optioncss; +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.$limit; +} +if ($search_contract) { + $param .= '&search_contract='.urlencode($search_contract); +} +if ($search_name) { + $param .= '&search_name='.urlencode($search_name); +} +if ($search_service) { + $param .= '&search_service='.urlencode($search_service); +} +if ($mode) { + $param .= '&mode='.urlencode($mode); +} +if ($filter) { + $param .= '&filter='.urlencode($filter); +} +if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) { + $param .= '&filter_opouvertureprevue='.urlencode($filter_opouvertureprevue); +} +if (!empty($filter_op1) && $filter_op1 != -1) { + $param .= '&filter_op1='.urlencode($filter_op1); +} +if (!empty($filter_op2) && $filter_op2 != -1) { + $param .= '&filter_op2='.urlencode($filter_op2); +} +if (!empty($filter_opcloture) && $filter_opcloture != -1) { + $param .= '&filter_opcloture='.urlencode($filter_opcloture); +} +if ($filter_dateouvertureprevue != '') { + $param .= '&opouvertureprevueday='.$opouvertureprevueday.'&opouvertureprevuemonth='.$opouvertureprevuemonth.'&opouvertureprevueyear='.$opouvertureprevueyear; +} +if ($filter_date1 != '') { + $param .= '&op1day='.$op1day.'&op1month='.$op1month.'&op1year='.$op1year; +} +if ($filter_date2 != '') { + $param .= '&op2day='.$op2day.'&op2month='.$op2month.'&op2year='.$op2year; +} +if ($filter_datecloture != '') { + $param .= '&opclotureday='.$op2day.'&opcloturemonth='.$op2month.'&opclotureyear='.$op2year; +} +if ($optioncss != '') { + $param .= '&optioncss='.$optioncss; +} // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -335,7 +440,9 @@ $arrayofmassactions = array( $massactionbutton = $form->selectMassAction('', $arrayofmassactions); print ''; -if ($optioncss != '') print ''; +if ($optioncss != '') { + print ''; +} print ''; print ''; print ''; @@ -345,24 +452,32 @@ print ''; print ''; $title = $langs->trans("ListOfServices"); -if ($mode == "0") $title = $langs->trans("ListOfInactiveServices"); // Must use == "0" -if ($mode == "4" && $filter != "expired") $title = $langs->trans("ListOfRunningServices"); -if ($mode == "4" && $filter == "expired") $title = $langs->trans("ListOfExpiredServices"); -if ($mode == "5") $title = $langs->trans("ListOfClosedServices"); +if ($mode == "0") { + $title = $langs->trans("ListOfInactiveServices"); // Must use == "0" +} +if ($mode == "4" && $filter != "expired") { + $title = $langs->trans("ListOfRunningServices"); +} +if ($mode == "4" && $filter == "expired") { + $title = $langs->trans("ListOfExpiredServices"); +} +if ($mode == "5") { + $title = $langs->trans("ListOfClosedServices"); +} print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, '', '', $limit); -if ($sall) -{ - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); +if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } $morefilter = ''; // If the user can view categories of products -if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire)) -{ +if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire)) { include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '
'; $moreforfilter .= $langs->trans('IncludingProductWithTag').': '; @@ -373,12 +488,14 @@ if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights- $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook -if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; -else $moreforfilter = $hookmanager->resPrint; +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} -if (!empty($moreforfilter)) -{ +if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -392,33 +509,62 @@ print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100'); print ''; print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1); print ''; //print $langs->trans('Month').': '; - if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { + print ''; + } print ''; //print ' '.$langs->trans('Year').': '; $syear = $year; @@ -523,20 +608,17 @@ $parameters = array('arrayfields'=>$arrayfields); $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation -if (!empty($arrayfields['c.datec']['checked'])) -{ +if (!empty($arrayfields['c.datec']['checked'])) { print ''; print ''; print ''; $arrayofoperators = array('0'=>'', '='=>'=', '<='=>'<=', '>='=>'>='); print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp'); @@ -547,8 +629,7 @@ if (!empty($arrayfields['lower_planned_end_date']['checked'])) print ''; @@ -558,18 +639,42 @@ print '
'; print $contracttmp->getNomUrl(1); - if ($obj->nb_late) print img_warning($langs->trans("Late")); + if ($obj->nb_late) { + print img_warning($langs->trans("Late")); + } if (!empty($obj->note_private) || !empty($obj->note_public)) { print ' '; print ''.img_picto($langs->trans("ViewPrivateNote"), 'note').''; @@ -652,16 +757,13 @@ while ($i < min($num, $limit)) print ''.$contracttmp->getFormatedCustomerRef($obj->ref_customer).''.$obj->ref_supplier.''; if ($obj->socid > 0) { // TODO Use a cache for this string @@ -669,57 +771,63 @@ while ($i < min($num, $limit)) } print ''.$obj->email.''; print $obj->town; print ''; print $obj->zip; print '".$obj->state_name."'; print $socstatic->country; print ''; - if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1); + if (count($typenArray) == 0) { + $typenArray = $formcompany->typent_array(1); + } print $typenArray[$obj->typent_code]; print ''; - if ($obj->socid > 0) - { + if ($obj->socid > 0) { $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user); - if ($listsalesrepresentatives < 0) dol_print_error($db); + if ($listsalesrepresentatives < 0) { + dol_print_error($db); + } $nbofsalesrepresentative = count($listsalesrepresentatives); if ($nbofsalesrepresentative > 6) { // We print only number @@ -756,8 +864,7 @@ while ($i < min($num, $limit)) print ''.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').''; print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); print ''; print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); print ''; print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser'); print ''.($obj->nb_initial > 0 ? $obj->nb_initial : '').''.($obj->nb_running > 0 ? $obj->nb_running : '').''.($obj->nb_expired > 0 ? $obj->nb_expired : '').''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } print ''; } print '
'.$langs->trans('Discount').''; - if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent); - else print $langs->trans("CompanyHasNoRelativeDiscount"); + if ($object->thirdparty->remise_percent) { + print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent); + } else { + print $langs->trans("CompanyHasNoRelativeDiscount"); + } $absolute_discount = $object->thirdparty->getAvailableDiscounts(); print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + if ($absolute_discount) { + print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)); + } else { + print $langs->trans("CompanyHasNoAbsoluteDiscount"); + } print '.'; print '
'."\n"; print ''; -if (!empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, "", $sortfield, $sortorder); -if (!empty($arrayfields['p.description']['checked'])) print_liste_field_titre($arrayfields['p.description']['label'], $_SERVER["PHP_SELF"], "p.description", "", $param, "", $sortfield, $sortorder); -if (!empty($arrayfields['cd.qty']['checked'])) print_liste_field_titre($arrayfields['cd.qty']['label'], $_SERVER["PHP_SELF"], "cd.qty", "", $param, '', $sortfield, $sortorder, 'center nowrap '); -if (!empty($arrayfields['cd.total_ht']['checked'])) print_liste_field_titre($arrayfields['cd.total_ht']['label'], $_SERVER["PHP_SELF"], "cd.total_ht", "", $param, '', $sortfield, $sortorder, 'center nowrap '); -if (!empty($arrayfields['cd.total_tva']['checked'])) print_liste_field_titre($arrayfields['cd.total_tva']['label'], $_SERVER["PHP_SELF"], "cd.total_tva", "", $param, '', $sortfield, $sortorder, 'center nowrap '); -if (!empty($arrayfields['cd.tva_tx']['checked'])) print_liste_field_titre($arrayfields['cd.tva_tx']['label'], $_SERVER["PHP_SELF"], "cd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center nowrap '); -if (!empty($arrayfields['cd.subprice']['checked'])) print_liste_field_titre($arrayfields['cd.subprice']['label'], $_SERVER["PHP_SELF"], "cd.subprice", "", $param, '', $sortfield, $sortorder, 'center nowrap '); -if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder); -if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture_prevue", "", $param, '', $sortfield, $sortorder, 'center '); -if (!empty($arrayfields['cd.date_ouverture']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture", "", $param, '', $sortfield, $sortorder, 'center '); -if (!empty($arrayfields['cd.date_fin_validite']['checked'])) print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'], $_SERVER["PHP_SELF"], "cd.date_fin_validite", "", $param, '', $sortfield, $sortorder, 'center '); -if (!empty($arrayfields['cd.date_cloture']['checked'])) print_liste_field_titre($arrayfields['cd.date_cloture']['label'], $_SERVER["PHP_SELF"], "cd.date_cloture", "", $param, '', $sortfield, $sortorder, 'center '); +if (!empty($arrayfields['c.ref']['checked'])) { + print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['p.description']['checked'])) { + print_liste_field_titre($arrayfields['p.description']['label'], $_SERVER["PHP_SELF"], "p.description", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['cd.qty']['checked'])) { + print_liste_field_titre($arrayfields['cd.qty']['label'], $_SERVER["PHP_SELF"], "cd.qty", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['cd.total_ht']['checked'])) { + print_liste_field_titre($arrayfields['cd.total_ht']['label'], $_SERVER["PHP_SELF"], "cd.total_ht", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['cd.total_tva']['checked'])) { + print_liste_field_titre($arrayfields['cd.total_tva']['label'], $_SERVER["PHP_SELF"], "cd.total_tva", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['cd.tva_tx']['checked'])) { + print_liste_field_titre($arrayfields['cd.tva_tx']['label'], $_SERVER["PHP_SELF"], "cd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['cd.subprice']['checked'])) { + print_liste_field_titre($arrayfields['cd.subprice']['label'], $_SERVER["PHP_SELF"], "cd.subprice", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['s.nom']['checked'])) { + print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) { + print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture_prevue", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['cd.date_ouverture']['checked'])) { + print_liste_field_titre($arrayfields['cd.date_ouverture']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['cd.date_fin_validite']['checked'])) { + print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'], $_SERVER["PHP_SELF"], "cd.date_fin_validite", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['cd.date_cloture']['checked'])) { + print_liste_field_titre($arrayfields['cd.date_cloture']['label'], $_SERVER["PHP_SELF"], "cd.date_cloture", "", $param, '', $sortfield, $sortorder, 'center '); +} // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (!empty($arrayfields['cd.datec']['checked'])) print_liste_field_titre($arrayfields['cd.datec']['label'], $_SERVER["PHP_SELF"], "cd.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); -if (!empty($arrayfields['cd.tms']['checked'])) print_liste_field_titre($arrayfields['cd.tms']['label'], $_SERVER["PHP_SELF"], "cd.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); -if (!empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "cd.statut,c.statut", "", $param, '', $sortfield, $sortorder, 'right '); +if (!empty($arrayfields['cd.datec']['checked'])) { + print_liste_field_titre($arrayfields['cd.datec']['label'], $_SERVER["PHP_SELF"], "cd.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['cd.tms']['checked'])) { + print_liste_field_titre($arrayfields['cd.tms']['label'], $_SERVER["PHP_SELF"], "cd.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['status']['checked'])) { + print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "cd.statut,c.statut", "", $param, '', $sortfield, $sortorder, 'right '); +} print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print "\n"; print ''; -if (!empty($arrayfields['c.ref']['checked'])) -{ +if (!empty($arrayfields['c.ref']['checked'])) { print ''; } // Service label -if (!empty($arrayfields['p.description']['checked'])) -{ +if (!empty($arrayfields['p.description']['checked'])) { print ''; } // detail lines -if (!empty($arrayfields['cd.qty']['checked'])) -{ +if (!empty($arrayfields['cd.qty']['checked'])) { print ''; } -if (!empty($arrayfields['cd.total_ht']['checked'])) -{ +if (!empty($arrayfields['cd.total_ht']['checked'])) { print ''; } -if (!empty($arrayfields['cd.total_tva']['checked'])) -{ +if (!empty($arrayfields['cd.total_tva']['checked'])) { print ''; } -if (!empty($arrayfields['cd.tva_tx']['checked'])) -{ +if (!empty($arrayfields['cd.tva_tx']['checked'])) { print ''; } -if (!empty($arrayfields['cd.subprice']['checked'])) -{ +if (!empty($arrayfields['cd.subprice']['checked'])) { print ''; } // Third party -if (!empty($arrayfields['s.nom']['checked'])) -{ +if (!empty($arrayfields['s.nom']['checked'])) { print ''; } -if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) -{ +if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) { print ''; } -if (!empty($arrayfields['cd.date_ouverture']['checked'])) -{ +if (!empty($arrayfields['cd.date_ouverture']['checked'])) { print ''; } -if (!empty($arrayfields['cd.date_fin_validite']['checked'])) -{ +if (!empty($arrayfields['cd.date_fin_validite']['checked'])) { print ''; } -if (!empty($arrayfields['cd.date_cloture']['checked'])) -{ +if (!empty($arrayfields['cd.date_cloture']['checked'])) { print ''; } -if (!empty($arrayfields['cd.tms']['checked'])) -{ +if (!empty($arrayfields['cd.tms']['checked'])) { // Date modification print ''; } -if (!empty($arrayfields['status']['checked'])) -{ +if (!empty($arrayfields['status']['checked'])) { // Status print ''; // Ref - if (!empty($arrayfields['c.ref']['checked'])) - { + if (!empty($arrayfields['c.ref']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Service - if (!empty($arrayfields['p.description']['checked'])) - { + if (!empty($arrayfields['p.description']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['cd.qty']['checked'])) - { + if (!empty($arrayfields['cd.qty']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['cd.total_ht']['checked'])) - { + if (!empty($arrayfields['cd.total_ht']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_ht'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_ht'; + } $totalarray['val']['cd.total_ht'] += $obj->total_ht; } - if (!empty($arrayfields['cd.total_tva']['checked'])) - { + if (!empty($arrayfields['cd.total_tva']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_tva'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_tva'; + } $totalarray['val']['cd.total_tva'] += $obj->total_tva; } - if (!empty($arrayfields['cd.tva_tx']['checked'])) - { + if (!empty($arrayfields['cd.tva_tx']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['cd.subprice']['checked'])) - { + if (!empty($arrayfields['cd.subprice']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Third party - if (!empty($arrayfields['s.nom']['checked'])) - { + if (!empty($arrayfields['s.nom']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Start date - if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) - { + if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['cd.date_ouverture']['checked'])) - { + if (!empty($arrayfields['cd.date_ouverture']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // End date - if (!empty($arrayfields['cd.date_fin_validite']['checked'])) - { + if (!empty($arrayfields['cd.date_fin_validite']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Close date (real end date) - if (!empty($arrayfields['cd.date_cloture']['checked'])) - { + if (!empty($arrayfields['cd.date_cloture']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Extra fields @@ -691,45 +846,50 @@ while ($i < min($num, $limit)) $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['cd.datec']['checked'])) - { + if (!empty($arrayfields['cd.datec']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date modification - if (!empty($arrayfields['cd.tms']['checked'])) - { + if (!empty($arrayfields['cd.tms']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Status - if (!empty($arrayfields['status']['checked'])) - { + if (!empty($arrayfields['status']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print "\n"; $i++; diff --git a/htdocs/contrat/tpl/linkedobjectblock.tpl.php b/htdocs/contrat/tpl/linkedobjectblock.tpl.php index 339f51db22c..310e2bd00b9 100644 --- a/htdocs/contrat/tpl/linkedobjectblock.tpl.php +++ b/htdocs/contrat/tpl/linkedobjectblock.tpl.php @@ -17,8 +17,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -37,24 +36,24 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; $langs->load("contracts"); $total = 0; $ilink = 0; -foreach ($linkedObjectBlock as $key => $objectlink) -{ +foreach ($linkedObjectBlock as $key => $objectlink) { $ilink++; $trclass = 'oddeven'; - if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total'; + if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) { + $trclass .= ' liste_sub_total'; + } ?> - - - + + + -
'; print ''; print ''; @@ -426,49 +572,41 @@ if (!empty($arrayfields['c.ref']['checked'])) print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $arrayofoperators = array('<'=>'<', '>'=>'>'); print $form->selectarray('filter_opouvertureprevue', $arrayofoperators, $filter_opouvertureprevue, 1); @@ -477,8 +615,7 @@ if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) print $form->selectDate($filter_dateouvertureprevue, 'opouvertureprevue', 0, 0, 1, '', 1, 0); print ''; $arrayofoperators = array('<'=>'<', '>'=>'>'); print $form->selectarray('filter_op1', $arrayofoperators, $filter_op1, 1); @@ -487,8 +624,7 @@ if (!empty($arrayfields['cd.date_ouverture']['checked'])) print $form->selectDate($filter_date1, 'op1', 0, 0, 1, '', 1, 0); print ''; $arrayofoperators = array('<'=>'<', '>'=>'>'); print $form->selectarray('filter_op2', $arrayofoperators, $filter_op2, 1); @@ -497,8 +633,7 @@ if (!empty($arrayfields['cd.date_fin_validite']['checked'])) print $form->selectDate($filter_date2, 'op2', 0, 0, 1, '', 1, 0); print ''; $arrayofoperators = array('<'=>'<', '>'=>'>'); print $form->selectarray('filter_opcloture', $arrayofoperators, $filter_opcloture, 1); @@ -514,20 +649,17 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; $parameters = array('arrayfields'=>$arrayfields); $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (!empty($arrayfields['cd.datec']['checked'])) -{ +if (!empty($arrayfields['cd.datec']['checked'])) { // Date creation print ''; print ''; print ''; $arrayofstatus = array( @@ -552,8 +684,7 @@ $productstatic = new Product($db); $i = 0; $totalarray = array(); -while ($i < min($num, $limit)) -{ +while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); $contractstatic->id = $obj->cid; @@ -570,118 +701,142 @@ while ($i < min($num, $limit)) print '
'; print $contractstatic->getNomUrl(1, 16); print ''; - if ($obj->pid > 0) - { + if ($obj->pid > 0) { $productstatic->id = $obj->pid; $productstatic->type = $obj->ptype; $productstatic->ref = $obj->pref; $productstatic->entity = $obj->pentity; print $productstatic->getNomUrl(1, '', 24); print $obj->label ? ' - '.dol_trunc($obj->label, 16) : ''; - if (!empty($obj->description) && !empty($conf->global->PRODUCT_DESC_IN_LIST)) print '
'.dol_nl2br($obj->description); + if (!empty($obj->description) && !empty($conf->global->PRODUCT_DESC_IN_LIST)) { + print '
'.dol_nl2br($obj->description); + } } else { - if ($obj->type == 0) print img_object($obj->description, 'product').' '.dol_trunc($obj->description, 24); - if ($obj->type == 1) print img_object($obj->description, 'service').' '.dol_trunc($obj->description, 24); + if ($obj->type == 0) { + print img_object($obj->description, 'product').' '.dol_trunc($obj->description, 24); + } + if ($obj->type == 1) { + print img_object($obj->description, 'service').' '.dol_trunc($obj->description, 24); + } } print '
'; print $obj->qty; print ''; print price($obj->total_ht); print ''; print price($obj->total_tva); print ''; print price2num($obj->tva_tx).'%'; print ''; print price($obj->subprice); print ''; print $companystatic->getNomUrl(1, 'customer', 28); print ''; print ($obj->date_ouverture_prevue ?dol_print_date($db->jdate($obj->date_ouverture_prevue), 'dayhour') : ' '); - if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0) - print ' '.img_picto($langs->trans("Late"), "warning"); - else print '    '; + if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0) { + print ' '.img_picto($langs->trans("Late"), "warning"); + } else { + print '    '; + } print ''.($obj->date_ouverture ?dol_print_date($db->jdate($obj->date_ouverture), 'dayhour') : ' ').''.($obj->date_fin_validite ?dol_print_date($db->jdate($obj->date_fin_validite), 'dayhour') : ' '); - if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) - { + if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) { $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); print img_warning($textlate); - } else print '    '; + } else { + print '    '; + } print ''.dol_print_date($db->jdate($obj->date_cloture), 'dayhour').''; print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); print ''; print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); print ''; - if ($obj->cstatut == 0) - { + if ($obj->cstatut == 0) { // If contract is draft, we say line is also draft print $contractstatic->LibStatut(0, 5); } else { print $staticcontratligne->LibStatut($obj->statut, 5, ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now) ? 1 : 0); } print ''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } print ''; } print '
trans("Contract"); ?>getNomUrl(1); ?>trans("Contract"); ?>getNomUrl(1); ?> date_contrat, 'day'); ?>rights->contrat->lire && empty($conf->global->CONTRACT_SHOW_TOTAL_OF_PRODUCT_AS_PRICE)) - { + if ($user->rights->contrat->lire && empty($conf->global->CONTRACT_SHOW_TOTAL_OF_PRODUCT_AS_PRICE)) { $totalcontrat = 0; foreach ($objectlink->lines as $linecontrat) { $totalcontrat = $totalcontrat + $linecontrat->total_ht;