diff --git a/htdocs/admin/bom.php b/htdocs/admin/bom.php index 52a468b878d..687ef4ee494 100644 --- a/htdocs/admin/bom.php +++ b/htdocs/admin/bom.php @@ -30,7 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php'; // Load translation files required by the page $langs->loadLangs(array('admin', 'errors', 'mrp', 'other')); -if (! $user->admin) accessforbidden(); +if (!$user->admin) accessforbidden(); $action = GETPOST('action', 'alpha'); $value = GETPOST('value', 'alpha'); @@ -47,14 +47,14 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; if ($action == 'updateMask') { - $maskconstbom=GETPOST('maskconstBom', 'alpha'); - $maskbom=GETPOST('maskBom', 'alpha'); + $maskconstbom = GETPOST('maskconstBom', 'alpha'); + $maskbom = GETPOST('maskBom', 'alpha'); if ($maskconstbom) $res = dolibarr_set_const($db, $maskconstbom, $maskbom, 'chaine', 0, '', $conf->entity); - if (! $res > 0) $error++; + if (!$res > 0) $error++; - if (! $error) + if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } @@ -66,20 +66,20 @@ if ($action == 'updateMask') elseif ($action == 'specimen') { - $modele=GETPOST('module', 'alpha'); + $modele = GETPOST('module', 'alpha'); $bom = new BOM($db); $bom->initAsSpecimen(); // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach($dirmodels as $reldir) + $file = ''; $classname = ''; $filefound = 0; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { - $file=dol_buildpath($reldir."core/modules/bom/doc/pdf_".$modele.".modules.php", 0); + $file = dol_buildpath($reldir."core/modules/bom/doc/pdf_".$modele.".modules.php", 0); if (file_exists($file)) { - $filefound=1; + $filefound = 1; $classname = "pdf_".$modele; break; } @@ -155,9 +155,9 @@ elseif ($action == 'set_BOM_DRAFT_WATERMARK') $draft = GETPOST("BOM_DRAFT_WATERMARK"); $res = dolibarr_set_const($db, "BOM_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity); - if (! $res > 0) $error++; + if (!$res > 0) $error++; - if (! $error) + if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } @@ -169,13 +169,13 @@ elseif ($action == 'set_BOM_DRAFT_WATERMARK') elseif ($action == 'set_BOM_FREE_TEXT') { - $freetext = GETPOST("BOM_FREE_TEXT", 'none'); // No alpha here, we want exact string + $freetext = GETPOST("BOM_FREE_TEXT", 'none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "BOM_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity); - if (! $res > 0) $error++; + if (!$res > 0) $error++; - if (! $error) + if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } @@ -190,13 +190,13 @@ elseif ($action == 'set_BOM_FREE_TEXT') * View */ -$form=new Form($db); +$form = new Form($db); -$dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']); +$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); llxHeader("", $langs->trans("BOMsSetup")); -$linkback=''.$langs->trans("BackToModuleList").''; +$linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("BOMsSetup"), $linkback, 'title_setup'); $head = bomAdminPrepareHead(); @@ -229,18 +229,18 @@ foreach ($dirmodels as $reldir) $handle = opendir($dir); if (is_resource($handle)) { - while (($file = readdir($handle))!==false) + while (($file = readdir($handle)) !== false) { - if (substr($file, 0, 8) == 'mod_bom_' && substr($file, dol_strlen($file)-3, 3) == 'php') + if (substr($file, 0, 8) == 'mod_bom_' && substr($file, dol_strlen($file) - 3, 3) == 'php') { - $file = substr($file, 0, dol_strlen($file)-4); + $file = substr($file, 0, dol_strlen($file) - 4); require_once $dir.$file.'.php'; $module = new $file($db); // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; if ($module->isEnabled()) @@ -251,9 +251,9 @@ foreach ($dirmodels as $reldir) // Show example of numbering model print ''; - $tmp=$module->getExample(); + $tmp = $module->getExample(); if (preg_match('/^Error/', $tmp)) print '
'.$langs->trans($tmp).'
'; - elseif ($tmp=='NotConfigured') print $langs->trans($tmp); + elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); else print $tmp; print ''."\n"; @@ -270,22 +270,22 @@ foreach ($dirmodels as $reldir) } print ''; - $bom=new BOM($db); + $bom = new BOM($db); $bom->initAsSpecimen(); // Info - $htmltooltip=''; - $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; - $bom->type=0; - $nextval=$module->getNextValue($mysoc, $bom); + $htmltooltip = ''; + $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; + $bom->type = 0; + $nextval = $module->getNextValue($mysoc, $bom); if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval - $htmltooltip.=''.$langs->trans("NextValue").': '; + $htmltooltip .= ''.$langs->trans("NextValue").': '; if ($nextval) { - if (preg_match('/^Error/', $nextval) || $nextval=='NotConfigured') + if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') $nextval = $langs->trans($nextval); - $htmltooltip.=$nextval.'
'; + $htmltooltip .= $nextval.'
'; } else { - $htmltooltip.=$langs->trans($module->error).'
'; + $htmltooltip .= $langs->trans($module->error).'
'; } } @@ -313,14 +313,14 @@ print load_fiche_titre($langs->trans("BOMsModelModule"), '', ''); // Load array def with activated templates $def = array(); $sql = "SELECT nom"; -$sql.= " FROM ".MAIN_DB_PREFIX."document_model"; -$sql.= " WHERE type = '".$type."'"; -$sql.= " AND entity = ".$conf->entity; -$resql=$db->query($sql); +$sql .= " FROM ".MAIN_DB_PREFIX."document_model"; +$sql .= " WHERE type = '".$type."'"; +$sql .= " AND entity = ".$conf->entity; +$resql = $db->query($sql); if ($resql) { $i = 0; - $num_rows=$db->num_rows($resql); + $num_rows = $db->num_rows($resql); while ($i < $num_rows) { $array = $db->fetch_array($resql); @@ -348,43 +348,43 @@ clearstatcache(); foreach ($dirmodels as $reldir) { - foreach (array('','/doc') as $valdir) + foreach (array('', '/doc') as $valdir) { $dir = dol_buildpath($reldir."core/modules/bom".$valdir); if (is_dir($dir)) { - $handle=opendir($dir); + $handle = opendir($dir); if (is_resource($handle)) { - while (($file = readdir($handle))!==false) + while (($file = readdir($handle)) !== false) { - $filelist[]=$file; + $filelist[] = $file; } closedir($handle); arsort($filelist); - foreach($filelist as $file) + foreach ($filelist as $file) { if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) { if (file_exists($dir.'/'.$file)) { - $name = substr($file, 4, dol_strlen($file) -16); - $classname = substr($file, 0, dol_strlen($file) -12); + $name = substr($file, 4, dol_strlen($file) - 16); + $classname = substr($file, 0, dol_strlen($file) - 12); require_once $dir.'/'.$file; $module = new $classname($db); - $modulequalified=1; - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; + $modulequalified = 1; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0; if ($modulequalified) { $var = !$var; print ''; - print (empty($module->name)?$name:$module->name); + print (empty($module->name) ? $name : $module->name); print "\n"; if (method_exists($module, 'info')) print $module->info($langs); else print $module->description; @@ -419,15 +419,15 @@ foreach ($dirmodels as $reldir) print ''; // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip .= '
'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); if ($module->type == 'pdf') { - $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip .= '
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; } - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1); - $htmltooltip.='
'.$langs->trans("WatermarkOnDraftBOMs").': '.yn($module->option_draft_watermark, 1, 1); + $htmltooltip .= '

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip .= '
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1); + $htmltooltip .= '
'.$langs->trans("WatermarkOnDraftBOMs").': '.yn($module->option_draft_watermark, 1, 1); print ''; @@ -471,18 +471,18 @@ print ''.$langs->trans("Value").''; print " \n"; print "\n"; -$substitutionarray=pdf_getSubstitutionArray($langs, null, null, 2); -$substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation"); +$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2); +$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation"); $htmltext = ''.$langs->trans("AvailableVariables").':
'; -foreach($substitutionarray as $key => $val) $htmltext.=$key.'
'; -$htmltext.='
'; +foreach ($substitutionarray as $key => $val) $htmltext .= $key.'
'; +$htmltext .= ''; print '
'; print ''; print ''; print ''; print $form->textwithpicto($langs->trans("FreeLegalTextOnBOMs"), $langs->trans("AddCRIfTooLong").'

'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'
'; -$variablename='BOM_FREE_TEXT'; +$variablename = 'BOM_FREE_TEXT'; if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) { print ''; @@ -490,7 +490,7 @@ if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) else { include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes'); + $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes'); print $doleditor->Create(); } print ''; diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 941eb621e7c..2e44074106b 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -30,44 +30,44 @@ require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php'; // Load translation files required by the page -$langs->loadLangs(array("mrp","other")); +$langs->loadLangs(array("mrp", "other")); // Get parameters -$id = GETPOST('id', 'int'); +$id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); -$contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'bomcard'; // To manage different context of search +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomcard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); $lineid = GETPOST('lineid', 'int'); // PDF -$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); -$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); -$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); +$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); +$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); +$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); // Initialize technical objects -$object=new BOM($db); +$object = new BOM($db); $extrafields = new ExtraFields($db); -$diroutputmassaction=$conf->bom->dir_output . '/temp/massgeneration/'.$user->id; -$hookmanager->initHooks(array('bomcard', 'globalcard')); // Note that conf->hooks_modules contains array +$diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id; +$hookmanager->initHooks(array('bomcard', 'globalcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); -$search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Initialize array of search criterias -$search_all=trim(GETPOST("search_all", 'alpha')); -$search=array(); -foreach($object->fields as $key => $val) +$search_all = trim(GETPOST("search_all", 'alpha')); +$search = array(); +foreach ($object->fields as $key => $val) { - if (GETPOST('search_'.$key, 'alpha')) $search[$key]=GETPOST('search_'.$key, 'alpha'); + if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); } -if (empty($action) && empty($id) && empty($ref)) $action='view'; +if (empty($action) && empty($id) && empty($ref)) $action = 'view'; // Load object -include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. // Security check - Protection if external user //if ($user->socid > 0) access_forbidden(); @@ -85,13 +85,13 @@ $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($ * Actions */ -$parameters=array(); -$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +$parameters = array(); +$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)) { - $error=0; + $error = 0; $backurlforlist = DOL_URL_ROOT.'/bom/bom_list.php'; @@ -100,7 +100,7 @@ if (empty($reshook)) if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist; else $backtopage = DOL_URL_ROOT.'/bom/bom_card.php?id='.($id > 0 ? $id : '__ID__'); } - $triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record + $triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record // Actions cancel, add, update, delete or clone include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; @@ -118,9 +118,9 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; // Actions to send emails - $trigger_name='BOM_SENTBYMAIL'; - $autocopy='MAIN_MAIL_AUTOCOPY_BOM_TO'; - $trackid='bom'.$object->id; + $trigger_name = 'BOM_SENTBYMAIL'; + $autocopy = 'MAIN_MAIL_AUTOCOPY_BOM_TO'; + $trackid = 'bom'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; // Add line @@ -140,12 +140,12 @@ if (empty($reshook)) setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); $error++; } - if (! ($idprod > 0)) { + if (!($idprod > 0)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Product')), null, 'errors'); $error++; } - if (! $error) + if (!$error) { $bomline = new BOMLine($db); $bomline->fk_bom = $id; @@ -176,10 +176,10 @@ if (empty($reshook)) $error = 0; // Set if we used free entry or predefined product - $qty=GETPOST('qty', 'int'); + $qty = GETPOST('qty', 'int'); $qty_frozen = GETPOST('qty_frozen', 'int'); $disable_stock_change = GETPOST('disable_stock_change', 'int'); - $efficiency=GETPOST('efficiency', 'int'); + $efficiency = GETPOST('efficiency', 'int'); if ($qty == '') { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); @@ -212,8 +212,8 @@ if (empty($reshook)) * View */ -$form=new Form($db); -$formfile=new FormFile($db); +$form = new Form($db); +$formfile = new FormFile($db); llxHeader('', $langs->trans("BOM"), ''); @@ -248,10 +248,10 @@ if ($action == 'create') print ''."\n"; // Common attributes - include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php'; + include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; // Other attributes - include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php'; + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; print '
'."\n"; @@ -260,7 +260,7 @@ if ($action == 'create') print '
'; print ''; print '  '; - print ''; // Cancel for create does not post form if we don't know the backtopage + print ''; // Cancel for create does not post form if we don't know the backtopage print '
'; print '
'; @@ -284,10 +284,10 @@ if (($id || $ref) && $action == 'edit') print ''."\n"; // Common attributes - include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php'; + include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php'; // Other attributes - include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php'; + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; print '
'; @@ -313,7 +313,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Confirmation to delete if ($action == 'delete') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteBillOfMaterials'), $langs->trans('ConfirmDeleteBillOfMaterials'), 'confirm_delete', '', 0, 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBillOfMaterials'), $langs->trans('ConfirmDeleteBillOfMaterials'), 'confirm_delete', '', 0, 1); } // Confirmation to delete line if ($action == 'deleteline') @@ -342,14 +342,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object); }*/ - $formquestion=array(); - if (! empty($conf->bom->enabled)) + $formquestion = array(); + if (!empty($conf->bom->enabled)) { $langs->load("mrp"); - require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct = new FormProduct($db); - $forcecombo=0; - if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy + $forcecombo = 0; + if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy $formquestion = array( // 'text' => $langs->trans("ConfirmClone"), // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), @@ -357,7 +357,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea ); } - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220); } // Confirmation of closing @@ -372,14 +372,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object); }*/ - $formquestion=array(); - if (! empty($conf->bom->enabled)) + $formquestion = array(); + if (!empty($conf->bom->enabled)) { $langs->load("mrp"); - require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct = new FormProduct($db); - $forcecombo=0; - if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy + $forcecombo = 0; + if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy $formquestion = array( // 'text' => $langs->trans("ConfirmClone"), // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), @@ -387,7 +387,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea ); } - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Close'), $text, 'confirm_close', $formquestion, 0, 1, 220); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Close'), $text, 'confirm_close', $formquestion, 0, 1, 220); } // Confirmation of reopen @@ -402,14 +402,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object); }*/ - $formquestion=array(); - if (! empty($conf->bom->enabled)) + $formquestion = array(); + if (!empty($conf->bom->enabled)) { $langs->load("mrp"); - require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct = new FormProduct($db); - $forcecombo=0; - if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy + $forcecombo = 0; + if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy $formquestion = array( // 'text' => $langs->trans("ConfirmClone"), // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), @@ -417,14 +417,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea ); } - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ReOpen'), $text, 'confirm_reopen', $formquestion, 0, 1, 220); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $text, 'confirm_reopen', $formquestion, 0, 1, 220); } // Clone confirmation if ($action == 'clone') { // Create an array for form $formquestion = array(); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneBillOfMaterials', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneBillOfMaterials', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } // Confirmation of action xxxx @@ -432,15 +432,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea { $text = $langs->trans('ConfirmSetToDraft', $object->ref); - $formquestion=array(); - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('SetToDraft'), $text, 'confirm_setdraft', $formquestion, 0, 1, 220); + $formquestion = array(); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetToDraft'), $text, 'confirm_setdraft', $formquestion, 0, 1, 220); } // Call Hook formConfirm $parameters = array('lineid' => $lineid); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $formconfirm.=$hookmanager->resPrint; - elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint; + if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; + elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; // Print form confirm print $formconfirm; @@ -448,9 +448,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Object card // ------------------------------------------------------------ - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref='
'; + $morehtmlref = '
'; /* // Ref bis $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->bom->creer, 'string', '', 0, 1); @@ -488,7 +488,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } */ - $morehtmlref.='
'; + $morehtmlref .= '
'; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); @@ -500,11 +500,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''."\n"; // Common attributes - $keyforbreak='description'; - include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php'; + $keyforbreak = 'description'; + include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; // Other attributes - include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; print '
'; print ''; @@ -574,8 +574,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($action != 'presend' && $action != 'editline') { print '
'."\n"; - $parameters=array(); - $reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) @@ -585,7 +585,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($user->rights->bom->write && $object->status == BOM::STATUS_VALIDATED) { - print '' . $langs->trans("SetToDraft") . ''; + print ''.$langs->trans("SetToDraft").''; } // Modify @@ -668,11 +668,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Documents $objref = dol_sanitizeFileName($object->ref); - $relativepath = $objref . '/' . $objref . '.pdf'; - $filedir = $conf->bom->dir_output . '/' . $objref; - $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; - $genallowed = $user->rights->bom->read; // If you can read, you can build the PDF to read content - $delallowed = $user->rights->bom->write; // If you can create/edit, you can remove a file on card + $relativepath = $objref.'/'.$objref.'.pdf'; + $filedir = $conf->bom->dir_output.'/'.$objref; + $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; + $genallowed = $user->rights->bom->read; // If you can read, you can build the PDF to read content + $delallowed = $user->rights->bom->write; // If you can create/edit, you can remove a file on card print $formfile->showdocuments('bom', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang); // Show links to link elements @@ -685,11 +685,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $MAXEVENT = 10; $morehtmlright = ''; - $morehtmlright.= $langs->trans("SeeAll"); - $morehtmlright.= ''; + $morehtmlright .= $langs->trans("SeeAll"); + $morehtmlright .= ''; // List of actions on element - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; $formactions = new FormActions($db); $somethingshown = $formactions->showactions($object, 'bom', $socid, 1, '', $MAXEVENT, '', $morehtmlright); @@ -700,8 +700,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (GETPOST('modelselected')) $action = 'presend'; // Presend form - $modelmail='bom'; - $defaulttopic='InformationMessage'; + $modelmail = 'bom'; + $defaulttopic = 'InformationMessage'; $diroutput = $conf->bom->dir_output; $trackid = 'bom'.$object->id; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 0df1af873a8..48bc48db849 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -35,12 +35,12 @@ * \brief File of class to manage proposals */ -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; -require_once DOL_DOCUMENT_ROOT ."/core/class/commonobjectline.class.php"; -require_once DOL_DOCUMENT_ROOT .'/product/class/product.class.php'; -require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php'; -require_once DOL_DOCUMENT_ROOT .'/margin/lib/margins.lib.php'; -require_once DOL_DOCUMENT_ROOT .'/multicurrency/class/multicurrency.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php"; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; /** * Class to manage proposals @@ -50,27 +50,27 @@ class Propal extends CommonObject /** * @var string ID to identify managed object */ - public $element='propal'; + public $element = 'propal'; /** * @var string Name of table without prefix where object is stored */ - public $table_element='propal'; + public $table_element = 'propal'; /** * @var int Name of subtable line */ - public $table_element_line='propaldet'; + public $table_element_line = 'propaldet'; /** * @var int Field with ID of parent key if this field has a parent */ - public $fk_element ='fk_propal'; + public $fk_element = 'fk_propal'; /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png */ - public $picto='propal'; + public $picto = 'propal'; /** * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe @@ -192,8 +192,8 @@ class Propal extends CommonObject public $demand_reason_id; public $demand_reason_code; - public $products=array(); - public $extraparams=array(); + public $products = array(); + public $extraparams = array(); /** * @var PropaleLigne[] @@ -201,8 +201,8 @@ class Propal extends CommonObject public $lines = array(); public $line; - public $labelStatus=array(); - public $labelStatusShort=array(); + public $labelStatus = array(); + public $labelStatusShort = array(); public $specimen; @@ -239,7 +239,7 @@ class Propal extends CommonObject /** * Billed or processed quote */ - const STATUS_BILLED = 4; // Todo rename into STATUS_CLOSE ? + const STATUS_BILLED = 4; // Todo rename into STATUS_CLOSE ? /** @@ -251,7 +251,7 @@ class Propal extends CommonObject */ public function __construct($db, $socid = 0, $propalid = 0) { - global $conf,$langs; + global $conf, $langs; $this->db = $db; @@ -260,7 +260,7 @@ class Propal extends CommonObject $this->products = array(); - $this->duree_validite=$conf->global->PROPALE_VALIDITY_DURATION; + $this->duree_validite = $conf->global->PROPALE_VALIDITY_DURATION; } @@ -282,26 +282,26 @@ class Propal extends CommonObject // phpcs:enable global $conf, $mysoc; - if (! $qty) $qty = 1; + if (!$qty) $qty = 1; dol_syslog(get_class($this)."::add_product $idproduct, $qty, $remise_percent"); if ($idproduct > 0) { - $prod=new Product($this->db); + $prod = new Product($this->db); $prod->fetch($idproduct); $productdesc = $prod->description; $tva_tx = get_default_tva($mysoc, $this->thirdparty, $prod->id); $tva_npr = get_default_npr($mysoc, $this->thirdparty, $prod->id); - if (empty($tva_tx)) $tva_npr=0; - $vat_src_code = ''; // May be defined into tva_tx + if (empty($tva_tx)) $tva_npr = 0; + $vat_src_code = ''; // May be defined into tva_tx $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr); // multiprices - if($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) + if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) { $price = $prod->multiprices[$this->thirdparty->price_level]; } @@ -312,17 +312,17 @@ class Propal extends CommonObject $line = new PropaleLigne($this->db); - $line->fk_product=$idproduct; - $line->desc=$productdesc; - $line->qty=$qty; - $line->subprice=$price; - $line->remise_percent=$remise_percent; - $line->vat_src_code=$vat_src_code; - $line->tva_tx=$tva_tx; - $line->fk_unit=$prod->fk_unit; + $line->fk_product = $idproduct; + $line->desc = $productdesc; + $line->qty = $qty; + $line->subprice = $price; + $line->remise_percent = $remise_percent; + $line->vat_src_code = $vat_src_code; + $line->tva_tx = $tva_tx; + $line->fk_unit = $prod->fk_unit; if ($tva_npr) $line->info_bits = 1; - $this->lines[]=$line; + $this->lines[] = $line; } } @@ -343,46 +343,46 @@ class Propal extends CommonObject $this->db->begin(); - $remise=new DiscountAbsolute($this->db); - $result=$remise->fetch($idremise); + $remise = new DiscountAbsolute($this->db); + $result = $remise->fetch($idremise); if ($result > 0) { if ($remise->fk_facture) // Protection against multiple submission { - $this->error=$langs->trans("ErrorDiscountAlreadyUsed"); + $this->error = $langs->trans("ErrorDiscountAlreadyUsed"); $this->db->rollback(); return -5; } - $line=new PropaleLigne($this->db); + $line = new PropaleLigne($this->db); $this->line->context = $this->context; - $line->fk_propal=$this->id; - $line->fk_remise_except=$remise->id; - $line->desc=$remise->description; // Description ligne - $line->vat_src_code=$remise->vat_src_code; - $line->tva_tx=$remise->tva_tx; - $line->subprice=-$remise->amount_ht; - $line->fk_product=0; // Id produit predefined - $line->qty=1; - $line->remise=0; - $line->remise_percent=0; - $line->rang=-1; - $line->info_bits=2; + $line->fk_propal = $this->id; + $line->fk_remise_except = $remise->id; + $line->desc = $remise->description; // Description ligne + $line->vat_src_code = $remise->vat_src_code; + $line->tva_tx = $remise->tva_tx; + $line->subprice = -$remise->amount_ht; + $line->fk_product = 0; // Id produit predefined + $line->qty = 1; + $line->remise = 0; + $line->remise_percent = 0; + $line->rang = -1; + $line->info_bits = 2; // TODO deprecated - $line->price=-$remise->amount_ht; + $line->price = -$remise->amount_ht; $line->total_ht = -$remise->amount_ht; $line->total_tva = -$remise->amount_tva; $line->total_ttc = -$remise->amount_ttc; - $result=$line->insert(); + $result = $line->insert(); if ($result > 0) { - $result=$this->update_price(1); + $result = $this->update_price(1); if ($result > 0) { $this->db->commit(); @@ -396,7 +396,7 @@ class Propal extends CommonObject } else { - $this->error=$line->error; + $this->error = $line->error; $this->db->rollback(); return -2; } @@ -455,30 +455,30 @@ class Propal extends CommonObject include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Clean parameters - if (empty($remise_percent)) $remise_percent=0; - if (empty($qty)) $qty=0; - if (empty($info_bits)) $info_bits=0; - if (empty($rang)) $rang=0; - if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0; + if (empty($remise_percent)) $remise_percent = 0; + if (empty($qty)) $qty = 0; + if (empty($info_bits)) $info_bits = 0; + if (empty($rang)) $rang = 0; + if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line = 0; - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); - $pu_ht=price2num($pu_ht); - $pu_ht_devise=price2num($pu_ht_devise); - $pu_ttc=price2num($pu_ttc); + $remise_percent = price2num($remise_percent); + $qty = price2num($qty); + $pu_ht = price2num($pu_ht); + $pu_ht_devise = price2num($pu_ht_devise); + $pu_ttc = price2num($pu_ttc); if (!preg_match('/\((.*)\)/', $txtva)) { - $txtva = price2num($txtva); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1' + $txtva = price2num($txtva); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1' } - $txlocaltax1=price2num($txlocaltax1); - $txlocaltax2=price2num($txlocaltax2); - $pa_ht=price2num($pa_ht); - if ($price_base_type=='HT') + $txlocaltax1 = price2num($txlocaltax1); + $txlocaltax2 = price2num($txlocaltax2); + $pa_ht = price2num($pa_ht); + if ($price_base_type == 'HT') { - $pu=$pu_ht; + $pu = $pu_ht; } else { - $pu=$pu_ttc; + $pu = $pu_ttc; } // Check parameters @@ -486,22 +486,22 @@ class Propal extends CommonObject if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); - $this->error=$langs->trans('ErrorStartDateGreaterEnd'); + $this->error = $langs->trans('ErrorStartDateGreaterEnd'); return -1; } $this->db->begin(); - $product_type=$type; + $product_type = $type; if (!empty($fk_product)) { - $product=new Product($this->db); - $result=$product->fetch($fk_product); - $product_type=$product->type; + $product = new Product($this->db); + $result = $product->fetch($fk_product); + $product_type = $product->type; - if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL) && $product_type == 0 && $product->stock_reel < $qty) { + if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL) && $product_type == 0 && $product->stock_reel < $qty) { $langs->load("errors"); - $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref); + $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref); $this->db->rollback(); return -3; } @@ -512,17 +512,17 @@ class Propal extends CommonObject // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. - $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); + $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); // Clean vat code - $vat_src_code=''; + $vat_src_code = ''; if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; - $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -558,39 +558,39 @@ class Propal extends CommonObject } // Insert line - $this->line=new PropaleLigne($this->db); + $this->line = new PropaleLigne($this->db); $this->line->context = $this->context; - $this->line->fk_propal=$this->id; - $this->line->label=$label; - $this->line->desc=$desc; - $this->line->qty=$qty; + $this->line->fk_propal = $this->id; + $this->line->label = $label; + $this->line->desc = $desc; + $this->line->qty = $qty; - $this->line->vat_src_code=$vat_src_code; - $this->line->tva_tx=$txtva; - $this->line->localtax1_tx=($total_localtax1?$localtaxes_type[1]:0); - $this->line->localtax2_tx=($total_localtax2?$localtaxes_type[3]:0); + $this->line->vat_src_code = $vat_src_code; + $this->line->tva_tx = $txtva; + $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0); + $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0); $this->line->localtax1_type = $localtaxes_type[0]; $this->line->localtax2_type = $localtaxes_type[2]; - $this->line->fk_product=$fk_product; - $this->line->product_type=$type; - $this->line->fk_remise_except=$fk_remise_except; - $this->line->remise_percent=$remise_percent; - $this->line->subprice=$pu_ht; - $this->line->rang=$ranktouse; - $this->line->info_bits=$info_bits; - $this->line->total_ht=$total_ht; - $this->line->total_tva=$total_tva; - $this->line->total_localtax1=$total_localtax1; - $this->line->total_localtax2=$total_localtax2; - $this->line->total_ttc=$total_ttc; - $this->line->special_code=$special_code; - $this->line->fk_parent_line=$fk_parent_line; - $this->line->fk_unit=$fk_unit; + $this->line->fk_product = $fk_product; + $this->line->product_type = $type; + $this->line->fk_remise_except = $fk_remise_except; + $this->line->remise_percent = $remise_percent; + $this->line->subprice = $pu_ht; + $this->line->rang = $ranktouse; + $this->line->info_bits = $info_bits; + $this->line->total_ht = $total_ht; + $this->line->total_tva = $total_tva; + $this->line->total_localtax1 = $total_localtax1; + $this->line->total_localtax2 = $total_localtax2; + $this->line->total_ttc = $total_ttc; + $this->line->special_code = $special_code; + $this->line->fk_parent_line = $fk_parent_line; + $this->line->fk_unit = $fk_unit; - $this->line->date_start=$date_start; - $this->line->date_end=$date_end; + $this->line->date_start = $date_start; + $this->line->date_end = $date_end; $this->line->fk_fournprice = $fk_fournprice; $this->line->pa_ht = $pa_ht; @@ -599,32 +599,32 @@ class Propal extends CommonObject $this->line->origin = $origin; // Multicurrency - $this->line->fk_multicurrency = $this->fk_multicurrency; - $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; $this->line->multicurrency_subprice = $pu_ht_devise; $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; // Mise en option de la ligne - if (empty($qty) && empty($special_code)) $this->line->special_code=3; + if (empty($qty) && empty($special_code)) $this->line->special_code = 3; // TODO deprecated - $this->line->price=$price; - $this->line->remise=$remise; + $this->line->price = $price; + $this->line->remise = $remise; - if (is_array($array_options) && count($array_options)>0) { - $this->line->array_options=$array_options; + if (is_array($array_options) && count($array_options) > 0) { + $this->line->array_options = $array_options; } - $result=$this->line->insert(); + $result = $this->line->insert(); if ($result > 0) { // Reorder if child line - if (! empty($fk_parent_line)) $this->line_order(true, 'DESC'); + if (!empty($fk_parent_line)) $this->line_order(true, 'DESC'); // Mise a jour informations denormalisees au niveau de la propale meme - $result=$this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + $result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. if ($result > 0) { $this->db->commit(); @@ -632,14 +632,14 @@ class Propal extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -1; } } else { - $this->error=$this->line->error; + $this->error = $this->line->error; $this->db->rollback(); return -2; } @@ -689,21 +689,21 @@ class Propal extends CommonObject include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Clean parameters - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); + $remise_percent = price2num($remise_percent); + $qty = price2num($qty); $pu = price2num($pu); - $pu_ht_devise=price2num($pu_ht_devise); + $pu_ht_devise = price2num($pu_ht_devise); $txtva = price2num($txtva); - $txlocaltax1=price2num($txlocaltax1); - $txlocaltax2=price2num($txlocaltax2); - $pa_ht=price2num($pa_ht); - if (empty($qty) && empty($special_code)) $special_code=3; // Set option tag - if (! empty($qty) && $special_code == 3) $special_code=0; // Remove option tag - if (empty($type)) $type=0; + $txlocaltax1 = price2num($txlocaltax1); + $txlocaltax2 = price2num($txlocaltax2); + $pa_ht = price2num($pa_ht); + if (empty($qty) && empty($special_code)) $special_code = 3; // Set option tag + if (!empty($qty) && $special_code == 3) $special_code = 0; // Remove option tag + if (empty($type)) $type = 0; if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); - $this->error=$langs->trans('ErrorStartDateGreaterEnd'); + $this->error = $langs->trans('ErrorStartDateGreaterEnd'); return -1; } @@ -716,17 +716,17 @@ class Propal extends CommonObject // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. - $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); + $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); // Clean vat code - $vat_src_code=''; + $vat_src_code = ''; if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; - $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; $total_ttc = $tabprice[2]; @@ -763,7 +763,7 @@ class Propal extends CommonObject $this->line->context = $this->context; // Reorder if fk_parent_line change - if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) + if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) { $rangmax = $this->line_max($fk_parent_line); $this->line->rang = $rangmax + 1; @@ -771,11 +771,11 @@ class Propal extends CommonObject $this->line->rowid = $rowid; $this->line->label = $label; - $this->line->desc = $desc; - $this->line->qty = $qty; + $this->line->desc = $desc; + $this->line->qty = $qty; $this->line->product_type = $type; $this->line->vat_src_code = $vat_src_code; - $this->line->tva_tx = $txtva; + $this->line->tva_tx = $txtva; $this->line->localtax1_tx = $txlocaltax1; $this->line->localtax2_tx = $txlocaltax2; $this->line->localtax1_type = $localtaxes_type[0]; @@ -789,23 +789,23 @@ class Propal extends CommonObject $this->line->total_localtax1 = $total_localtax1; $this->line->total_localtax2 = $total_localtax2; $this->line->total_ttc = $total_ttc; - $this->line->special_code = $special_code; + $this->line->special_code = $special_code; $this->line->fk_parent_line = $fk_parent_line; - $this->line->skip_update_total = $skip_update_total; - $this->line->fk_unit = $fk_unit; + $this->line->skip_update_total = $skip_update_total; + $this->line->fk_unit = $fk_unit; $this->line->fk_fournprice = $fk_fournprice; $this->line->pa_ht = $pa_ht; - $this->line->date_start=$date_start; - $this->line->date_end=$date_end; + $this->line->date_start = $date_start; + $this->line->date_end = $date_end; // TODO deprecated - $this->line->price=$price; - $this->line->remise=$remise; + $this->line->price = $price; + $this->line->remise = $remise; - if (is_array($array_options) && count($array_options)>0) { - $this->line->array_options=$array_options; + if (is_array($array_options) && count($array_options) > 0) { + $this->line->array_options = $array_options; } // Multicurrency @@ -814,11 +814,11 @@ class Propal extends CommonObject $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - $result=$this->line->update($notrigger); + $result = $this->line->update($notrigger); if ($result > 0) { // Reorder if child line - if (! empty($fk_parent_line)) $this->line_order(true, 'DESC'); + if (!empty($fk_parent_line)) $this->line_order(true, 'DESC'); $this->update_price(1); @@ -830,7 +830,7 @@ class Propal extends CommonObject } else { - $this->error=$this->line->error; + $this->error = $this->line->error; $this->db->rollback(); return -1; @@ -858,7 +858,7 @@ class Propal extends CommonObject { $this->db->begin(); - $line=new PropaleLigne($this->db); + $line = new PropaleLigne($this->db); // For triggers $line->fetch($lineid); @@ -878,7 +878,7 @@ class Propal extends CommonObject } else { - $this->error='ErrorDeleteLineNotAllowedByObjectStatus'; + $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; return -2; } } @@ -894,19 +894,19 @@ class Propal extends CommonObject */ public function create($user, $notrigger = 0) { - global $conf,$hookmanager; - $error=0; + global $conf, $hookmanager; + $error = 0; - $now=dol_now(); + $now = dol_now(); // Clean parameters - if (empty($this->date)) $this->date=$this->datep; + if (empty($this->date)) $this->date = $this->datep; $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600); - if (empty($this->availability_id)) $this->availability_id=0; - if (empty($this->demand_reason_id)) $this->demand_reason_id=0; + if (empty($this->availability_id)) $this->availability_id = 0; + if (empty($this->demand_reason_id)) $this->demand_reason_id = 0; // Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate) - if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); + if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); if (empty($this->fk_multicurrency)) { @@ -918,21 +918,21 @@ class Propal extends CommonObject dol_syslog(get_class($this)."::create"); // Check parameters - $result=$this->fetch_thirdparty(); + $result = $this->fetch_thirdparty(); if ($result < 0) { - $this->error="Failed to fetch company"; + $this->error = "Failed to fetch company"; dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -3; } // Check parameters - if (! empty($this->ref)) // We check that ref is not already used + if (!empty($this->ref)) // We check that ref is not already used { - $result=self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used + $result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used if ($result > 0) { - $this->error='ErrorRefAlreadyExists'; + $this->error = 'ErrorRefAlreadyExists'; dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); $this->db->rollback(); return -1; @@ -941,7 +941,7 @@ class Propal extends CommonObject if (empty($this->date)) { - $this->error="Date of proposal is required"; + $this->error = "Date of proposal is required"; dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -4; } @@ -951,103 +951,103 @@ class Propal extends CommonObject // Insert into database $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal ("; - $sql.= "fk_soc"; - $sql.= ", price"; - $sql.= ", remise"; - $sql.= ", remise_percent"; - $sql.= ", remise_absolue"; - $sql.= ", tva"; - $sql.= ", total"; - $sql.= ", datep"; - $sql.= ", datec"; - $sql.= ", ref"; - $sql.= ", fk_user_author"; - $sql.= ", note_private"; - $sql.= ", note_public"; - $sql.= ", model_pdf"; - $sql.= ", fin_validite"; - $sql.= ", fk_cond_reglement"; - $sql.= ", fk_mode_reglement"; - $sql.= ", fk_account"; - $sql.= ", ref_client"; - $sql.= ", date_livraison"; - $sql.= ", fk_shipping_method"; - $sql.= ", fk_availability"; - $sql.= ", fk_input_reason"; - $sql.= ", fk_projet"; - $sql.= ", fk_incoterms"; - $sql.= ", location_incoterms"; - $sql.= ", entity"; - $sql.= ", fk_multicurrency"; - $sql.= ", multicurrency_code"; - $sql.= ", multicurrency_tx"; - $sql.= ") "; - $sql.= " VALUES ("; - $sql.= $this->socid; - $sql.= ", 0"; - $sql.= ", ".$this->remise; - $sql.= ", ".($this->remise_percent?$this->db->escape($this->remise_percent):'NULL'); - $sql.= ", ".($this->remise_absolue?$this->db->escape($this->remise_absolue):'NULL'); - $sql.= ", 0"; - $sql.= ", 0"; - $sql.= ", '".$this->db->idate($this->date)."'"; - $sql.= ", '".$this->db->idate($now)."'"; - $sql.= ", '(PROV)'"; - $sql.= ", ".($user->id > 0 ? "'".$user->id."'":"NULL"); - $sql.= ", '".$this->db->escape($this->note_private)."'"; - $sql.= ", '".$this->db->escape($this->note_public)."'"; - $sql.= ", '".$this->db->escape($this->modelpdf)."'"; - $sql.= ", ".($this->fin_validite!=''?"'".$this->db->idate($this->fin_validite)."'":"NULL"); - $sql.= ", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id : 'NULL'); - $sql.= ", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id : 'NULL'); - $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL'); - $sql.= ", '".$this->db->escape($this->ref_client)."'"; - $sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":"NULL"); - $sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:'NULL'); - $sql.= ", ".$this->availability_id; - $sql.= ", ".$this->demand_reason_id; - $sql.= ", ".($this->fk_project?$this->fk_project:"null"); - $sql.= ", ".(int) $this->fk_incoterms; - $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; - $sql.= ", ".setEntity($this); - $sql.= ", ".(int) $this->fk_multicurrency; - $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; - $sql.= ", ".(double) $this->multicurrency_tx; - $sql.= ")"; + $sql .= "fk_soc"; + $sql .= ", price"; + $sql .= ", remise"; + $sql .= ", remise_percent"; + $sql .= ", remise_absolue"; + $sql .= ", tva"; + $sql .= ", total"; + $sql .= ", datep"; + $sql .= ", datec"; + $sql .= ", ref"; + $sql .= ", fk_user_author"; + $sql .= ", note_private"; + $sql .= ", note_public"; + $sql .= ", model_pdf"; + $sql .= ", fin_validite"; + $sql .= ", fk_cond_reglement"; + $sql .= ", fk_mode_reglement"; + $sql .= ", fk_account"; + $sql .= ", ref_client"; + $sql .= ", date_livraison"; + $sql .= ", fk_shipping_method"; + $sql .= ", fk_availability"; + $sql .= ", fk_input_reason"; + $sql .= ", fk_projet"; + $sql .= ", fk_incoterms"; + $sql .= ", location_incoterms"; + $sql .= ", entity"; + $sql .= ", fk_multicurrency"; + $sql .= ", multicurrency_code"; + $sql .= ", multicurrency_tx"; + $sql .= ") "; + $sql .= " VALUES ("; + $sql .= $this->socid; + $sql .= ", 0"; + $sql .= ", ".$this->remise; + $sql .= ", ".($this->remise_percent ? $this->db->escape($this->remise_percent) : 'NULL'); + $sql .= ", ".($this->remise_absolue ? $this->db->escape($this->remise_absolue) : 'NULL'); + $sql .= ", 0"; + $sql .= ", 0"; + $sql .= ", '".$this->db->idate($this->date)."'"; + $sql .= ", '".$this->db->idate($now)."'"; + $sql .= ", '(PROV)'"; + $sql .= ", ".($user->id > 0 ? "'".$user->id."'" : "NULL"); + $sql .= ", '".$this->db->escape($this->note_private)."'"; + $sql .= ", '".$this->db->escape($this->note_public)."'"; + $sql .= ", '".$this->db->escape($this->modelpdf)."'"; + $sql .= ", ".($this->fin_validite != '' ? "'".$this->db->idate($this->fin_validite)."'" : "NULL"); + $sql .= ", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id : 'NULL'); + $sql .= ", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id : 'NULL'); + $sql .= ", ".($this->fk_account > 0 ? $this->fk_account : 'NULL'); + $sql .= ", '".$this->db->escape($this->ref_client)."'"; + $sql .= ", ".($this->date_livraison != '' ? "'".$this->db->idate($this->date_livraison)."'" : "NULL"); + $sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : 'NULL'); + $sql .= ", ".$this->availability_id; + $sql .= ", ".$this->demand_reason_id; + $sql .= ", ".($this->fk_project ? $this->fk_project : "null"); + $sql .= ", ".(int) $this->fk_incoterms; + $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; + $sql .= ", ".setEntity($this); + $sql .= ", ".(int) $this->fk_multicurrency; + $sql .= ", '".$this->db->escape($this->multicurrency_code)."'"; + $sql .= ", ".(double) $this->multicurrency_tx; + $sql .= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal"); if ($this->id) { - $this->ref='(PROV'.$this->id.')'; + $this->ref = '(PROV'.$this->id.')'; $sql = 'UPDATE '.MAIN_DB_PREFIX."propal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id; dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) $error++; + $resql = $this->db->query($sql); + if (!$resql) $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 + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds } // Add object linked - if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) + if (!$error && $this->id && is_array($this->linked_objects) && !empty($this->linked_objects)) { - foreach($this->linked_objects as $origin => $tmp_origin_id) + 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) + foreach ($tmp_origin_id as $origin_id) { $ret = $this->add_object_linked($origin, $origin_id); - if (! $ret) + if (!$ret) { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $error++; } } @@ -1056,9 +1056,9 @@ class Propal extends CommonObject { $origin_id = $tmp_origin_id; $ret = $this->add_object_linked($origin, $origin_id); - if (! $ret) + if (!$ret) { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $error++; } } @@ -1069,14 +1069,14 @@ class Propal extends CommonObject * Insertion du detail des produits dans la base * Insert products detail in database */ - if (! $error) + if (!$error) { - $fk_parent_line=0; - $num=count($this->lines); + $fk_parent_line = 0; + $num = count($this->lines); - for ($i=0;$i<$num;$i++) + for ($i = 0; $i < $num; $i++) { - if (! is_object($this->lines[$i])) // If this->lines is not array of objects, coming from REST API + if (!is_object($this->lines[$i])) // If this->lines is not array of objects, coming from REST API { // Convert into object this->lines[$i]. $line = (object) $this->lines[$i]; } @@ -1090,7 +1090,7 @@ class Propal extends CommonObject } // Complete vat rate with code $vatrate = $line->tva_tx; - if ($line->vat_src_code && ! preg_match('/\(.*\)/', $vatrate)) $vatrate.=' ('.$line->vat_src_code.')'; + if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')'; $result = $this->addline( $line->desc, @@ -1122,7 +1122,7 @@ class Propal extends CommonObject if ($result < 0) { $error++; - $this->error=$this->db->error; + $this->error = $this->db->error; dol_print_error($this->db); break; } @@ -1144,20 +1144,20 @@ class Propal extends CommonObject $result=$this->db->query($sql); }*/ - if (! $error) + if (!$error) { // Mise a jour infos denormalisees - $resql=$this->update_price(1); + $resql = $this->update_price(1); if ($resql) { - $action='update'; + $action = 'update'; // Actions on extra fields - if (! $error) + if (!$error) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; @@ -1165,28 +1165,28 @@ class Propal extends CommonObject } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('PROPAL_CREATE', $user); + $result = $this->call_trigger('PROPAL_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $error++; } } } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $error++; } - if (! $error) + if (!$error) { $this->db->commit(); dol_syslog(get_class($this)."::create done id=".$this->id); @@ -1200,7 +1200,7 @@ class Propal extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } @@ -1219,7 +1219,7 @@ class Propal extends CommonObject { // phpcs:enable // i love this function because $this->products is not used in create function... - $this->products=$this->lines; + $this->products = $this->lines; return $this->create($user); } @@ -1233,12 +1233,12 @@ class Propal extends CommonObject */ public function createFromClone(User $user, $socid = 0) { - global $conf,$hookmanager; + global $conf, $hookmanager; dol_include_once('/projet/class/project.class.php'); - $error=0; - $now=dol_now(); + $error = 0; + $now = dol_now(); dol_syslog(__METHOD__, LOG_DEBUG); @@ -1250,17 +1250,17 @@ class Propal extends CommonObject $object->fetch($this->id); $object->fetch_lines(); - $objsoc=new Societe($this->db); + $objsoc = new Societe($this->db); // Change socid if needed - if (! empty($socid) && $socid != $object->socid) + if (!empty($socid) && $socid != $object->socid) { if ($objsoc->fetch($socid) > 0) { - $object->socid = $objsoc->id; - $object->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); - $object->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); - $object->fk_delivery_address = ''; + $object->socid = $objsoc->id; + $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); + $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); + $object->fk_delivery_address = ''; /*if (!empty($conf->projet->enabled)) { @@ -1272,11 +1272,11 @@ class Propal extends CommonObject $clonedObj->fk_project = ''; } }*/ - $object->fk_project = ''; // A cloned proposal is set by default to no project. + $object->fk_project = ''; // A cloned proposal is set by default to no project. } // reset ref_client - $object->ref_client = ''; + $object->ref_client = ''; // TODO Change product price if multi-prices } @@ -1285,25 +1285,25 @@ class Propal extends CommonObject $objsoc->fetch($object->socid); } - $object->id=0; - $object->ref=''; - $object->statut=self::STATUS_DRAFT; + $object->id = 0; + $object->ref = ''; + $object->statut = self::STATUS_DRAFT; // Clear fields - $object->user_author = $user->id; - $object->user_valid = ''; - $object->date = $now; - $object->datep = $now; // deprecated - $object->fin_validite = $object->date + ($object->duree_validite * 24 * 3600); - if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $object->ref_client = ''; - if ($conf->global->MAIN_DONT_KEEP_NOTE_ON_CLONING==1) + $object->user_author = $user->id; + $object->user_valid = ''; + $object->date = $now; + $object->datep = $now; // deprecated + $object->fin_validite = $object->date + ($object->duree_validite * 24 * 3600); + if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $object->ref_client = ''; + if ($conf->global->MAIN_DONT_KEEP_NOTE_ON_CLONING == 1) { $object->note_private = ''; $object->note_public = ''; } // Create clone - $object->context['createfromclone']='createfromclone'; - $result=$object->create($user); + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->create($user); if ($result < 0) { $this->error = $object->error; @@ -1311,7 +1311,7 @@ class Propal extends CommonObject $error++; } - if (! $error) + if (!$error) { // copy internal contacts if ($object->copy_linked_contact($this, 'internal') < 0) @@ -1320,7 +1320,7 @@ class Propal extends CommonObject } } - if (! $error) + if (!$error) { // copy external contacts if same company if ($this->socid == $object->socid) @@ -1330,14 +1330,14 @@ class Propal extends CommonObject } } - if (! $error) + if (!$error) { // Hook of thirdparty module if (is_object($hookmanager)) { - $parameters=array('objFrom'=>$this,'clonedObj'=>$object); - $action=''; - $reshook=$hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + $parameters = array('objFrom'=>$this, 'clonedObj'=>$object); + $action = ''; + $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) $error++; } } @@ -1345,7 +1345,7 @@ class Propal extends CommonObject unset($object->context['createfromclone']); // End - if (! $error) + if (!$error) { $this->db->commit(); return $object->id; @@ -1368,48 +1368,48 @@ class Propal extends CommonObject { $sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc"; - $sql.= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; - $sql.= ", p.datec"; - $sql.= ", p.date_valid as datev"; - $sql.= ", p.datep as dp"; - $sql.= ", p.fin_validite as dfv"; - $sql.= ", p.date_livraison as date_livraison"; - $sql.= ", p.model_pdf, p.last_main_doc, p.ref_client, p.extraparams"; - $sql.= ", p.note_private, p.note_public"; - $sql.= ", p.fk_projet as fk_project, p.fk_statut"; - $sql.= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture"; - $sql.= ", p.fk_delivery_address"; - $sql.= ", p.fk_availability"; - $sql.= ", p.fk_input_reason"; - $sql.= ", p.fk_cond_reglement"; - $sql.= ", p.fk_mode_reglement"; - $sql.= ', p.fk_account'; - $sql.= ", p.fk_shipping_method"; - $sql.= ", p.fk_incoterms, p.location_incoterms"; - $sql.= ", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc"; - $sql.= ", p.tms as date_modification"; - $sql.= ", i.libelle as label_incoterms"; - $sql.= ", c.label as statut_label"; - $sql.= ", ca.code as availability_code, ca.label as availability"; - $sql.= ", dr.code as demand_reason_code, dr.label as demand_reason"; - $sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc"; - $sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement"; - $sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_propalst as c ON p.fk_statut = c.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.getEntity('c_paiement').')'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN ('.getEntity('c_payment_term').')'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON p.fk_availability = ca.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid'; + $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; + $sql .= ", p.datec"; + $sql .= ", p.date_valid as datev"; + $sql .= ", p.datep as dp"; + $sql .= ", p.fin_validite as dfv"; + $sql .= ", p.date_livraison as date_livraison"; + $sql .= ", p.model_pdf, p.last_main_doc, p.ref_client, p.extraparams"; + $sql .= ", p.note_private, p.note_public"; + $sql .= ", p.fk_projet as fk_project, p.fk_statut"; + $sql .= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture"; + $sql .= ", p.fk_delivery_address"; + $sql .= ", p.fk_availability"; + $sql .= ", p.fk_input_reason"; + $sql .= ", p.fk_cond_reglement"; + $sql .= ", p.fk_mode_reglement"; + $sql .= ', p.fk_account'; + $sql .= ", p.fk_shipping_method"; + $sql .= ", p.fk_incoterms, p.location_incoterms"; + $sql .= ", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc"; + $sql .= ", p.tms as date_modification"; + $sql .= ", i.libelle as label_incoterms"; + $sql .= ", c.label as statut_label"; + $sql .= ", ca.code as availability_code, ca.label as availability"; + $sql .= ", dr.code as demand_reason_code, dr.label as demand_reason"; + $sql .= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc"; + $sql .= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_propalst as c ON p.fk_statut = c.id'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.getEntity('c_paiement').')'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN ('.getEntity('c_payment_term').')'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON p.fk_availability = ca.rowid'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid'; if ($ref) { - $sql.= " WHERE p.entity IN (".getEntity('propal').")"; // Dont't use entity if you use rowid - $sql.= " AND p.ref='".$this->db->escape($ref)."'"; + $sql .= " WHERE p.entity IN (".getEntity('propal').")"; // Dont't use entity if you use rowid + $sql .= " AND p.ref='".$this->db->escape($ref)."'"; } - else $sql.= " WHERE p.rowid=".$rowid; + else $sql .= " WHERE p.rowid=".$rowid; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) @@ -1433,7 +1433,7 @@ class Propal extends CommonObject $this->socid = $obj->fk_soc; $this->fk_project = $obj->fk_project; $this->modelpdf = $obj->model_pdf; - $this->last_main_doc = $obj->last_main_doc; + $this->last_main_doc = $obj->last_main_doc; $this->note = $obj->note_private; // TODO deprecated $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; @@ -1442,32 +1442,32 @@ class Propal extends CommonObject $this->datec = $this->db->jdate($obj->datec); // TODO deprecated $this->datev = $this->db->jdate($obj->datev); // TODO deprecated - $this->date_creation = $this->db->jdate($obj->datec); //Creation date - $this->date_validation = $this->db->jdate($obj->datev); //Validation date - $this->date_modification = $this->db->jdate($obj->date_modification); // tms - $this->date = $this->db->jdate($obj->dp); // Proposal date - $this->datep = $this->db->jdate($obj->dp); // deprecated + $this->date_creation = $this->db->jdate($obj->datec); //Creation date + $this->date_validation = $this->db->jdate($obj->datev); //Validation date + $this->date_modification = $this->db->jdate($obj->date_modification); // tms + $this->date = $this->db->jdate($obj->dp); // Proposal date + $this->datep = $this->db->jdate($obj->dp); // deprecated $this->fin_validite = $this->db->jdate($obj->dfv); $this->date_livraison = $this->db->jdate($obj->date_livraison); - $this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; + $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null; $this->availability_id = $obj->fk_availability; $this->availability_code = $obj->availability_code; $this->availability = $obj->availability; $this->demand_reason_id = $obj->fk_input_reason; $this->demand_reason_code = $obj->demand_reason_code; $this->demand_reason = $obj->demand_reason; - $this->fk_address = $obj->fk_delivery_address; + $this->fk_address = $obj->fk_delivery_address; $this->mode_reglement_id = $obj->fk_mode_reglement; $this->mode_reglement_code = $obj->mode_reglement_code; $this->mode_reglement = $obj->mode_reglement; - $this->fk_account = ($obj->fk_account>0)?$obj->fk_account:null; + $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account : null; $this->cond_reglement_id = $obj->fk_cond_reglement; $this->cond_reglement_code = $obj->cond_reglement_code; $this->cond_reglement = $obj->cond_reglement; $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; - $this->extraparams = (array) json_decode($obj->extraparams, true); + $this->extraparams = (array) json_decode($obj->extraparams, true); $this->user_author_id = $obj->fk_user_author; $this->user_valid_id = $obj->fk_user_valid; @@ -1480,9 +1480,9 @@ class Propal extends CommonObject // Multicurrency $this->fk_multicurrency = $obj->fk_multicurrency; - $this->multicurrency_code = $obj->multicurrency_code; + $this->multicurrency_code = $obj->multicurrency_code; $this->multicurrency_tx = $obj->multicurrency_tx; - $this->multicurrency_total_ht = $obj->multicurrency_total_ht; + $this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; @@ -1502,7 +1502,7 @@ class Propal extends CommonObject /* * Lines */ - $result=$this->fetch_lines(); + $result = $this->fetch_lines(); if ($result < 0) { return -3; @@ -1511,12 +1511,12 @@ class Propal extends CommonObject return 1; } - $this->error="Record Not Found"; + $this->error = "Record Not Found"; return 0; } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -1532,15 +1532,15 @@ class Propal extends CommonObject { global $conf; - $error=0; + $error = 0; // Clean parameters - if (isset($this->ref)) $this->ref=trim($this->ref); - if (isset($this->ref_client)) $this->ref_client=trim($this->ref_client); - if (isset($this->note) || isset($this->note_private)) $this->note_private=(isset($this->note_private) ? trim($this->note_private) : trim($this->note)); - if (isset($this->note_public)) $this->note_public=trim($this->note_public); - if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf); - 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_client)) $this->ref_client = trim($this->ref_client); + if (isset($this->note) || isset($this->note_private)) $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note)); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); + if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf); + if (isset($this->import_key)) $this->import_key = trim($this->import_key); // Check parameters // Put here code to add control on parameters values @@ -1548,51 +1548,51 @@ class Propal extends CommonObject // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET"; - $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; - $sql.= " ref_client=".(isset($this->ref_client)?"'".$this->db->escape($this->ref_client)."'":"null").","; - $sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").","; - $sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").","; - $sql.= " datep=".(strval($this->datep)!='' ? "'".$this->db->idate($this->datep)."'" : 'null').","; - $sql.= " date_valid=".(strval($this->date_validation)!='' ? "'".$this->db->idate($this->date_validation)."'" : 'null').","; - $sql.= " tva=".(isset($this->total_tva)?$this->total_tva:"null").","; - $sql.= " localtax1=".(isset($this->total_localtax1)?$this->total_localtax1:"null").","; - $sql.= " localtax2=".(isset($this->total_localtax2)?$this->total_localtax2:"null").","; - $sql.= " total_ht=".(isset($this->total_ht)?$this->total_ht:"null").","; - $sql.= " total=".(isset($this->total_ttc)?$this->total_ttc:"null").","; - $sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").","; - $sql.= " fk_user_author=".(isset($this->user_author_id)?$this->user_author_id:"null").","; - $sql.= " fk_user_valid=".(isset($this->user_valid)?$this->user_valid:"null").","; - $sql.= " fk_projet=".(isset($this->fk_project)?$this->fk_project:"null").","; - $sql.= " fk_cond_reglement=".(isset($this->cond_reglement_id)?$this->cond_reglement_id:"null").","; - $sql.= " fk_mode_reglement=".(isset($this->mode_reglement_id)?$this->mode_reglement_id:"null").","; - $sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").","; - $sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").","; - $sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").","; - $sql.= " import_key=".(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null").""; + $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; + $sql .= " ref_client=".(isset($this->ref_client) ? "'".$this->db->escape($this->ref_client)."'" : "null").","; + $sql .= " ref_ext=".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").","; + $sql .= " fk_soc=".(isset($this->socid) ? $this->socid : "null").","; + $sql .= " datep=".(strval($this->datep) != '' ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql .= " date_valid=".(strval($this->date_validation) != '' ? "'".$this->db->idate($this->date_validation)."'" : 'null').","; + $sql .= " tva=".(isset($this->total_tva) ? $this->total_tva : "null").","; + $sql .= " localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 : "null").","; + $sql .= " localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 : "null").","; + $sql .= " total_ht=".(isset($this->total_ht) ? $this->total_ht : "null").","; + $sql .= " total=".(isset($this->total_ttc) ? $this->total_ttc : "null").","; + $sql .= " fk_statut=".(isset($this->statut) ? $this->statut : "null").","; + $sql .= " fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id : "null").","; + $sql .= " fk_user_valid=".(isset($this->user_valid) ? $this->user_valid : "null").","; + $sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").","; + $sql .= " fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id : "null").","; + $sql .= " fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id : "null").","; + $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; + $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; + $sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").","; + $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null").""; - $sql.= " WHERE rowid=".$this->id; + $sql .= " WHERE rowid=".$this->id; $this->db->begin(); dol_syslog(get_class($this)."::update", LOG_DEBUG); $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 && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } @@ -1600,13 +1600,13 @@ class Propal extends CommonObject // Commit or rollback if ($error) { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } else { @@ -1629,20 +1629,20 @@ class Propal extends CommonObject { global $langs, $conf; // phpcs:enable - $this->lines=array(); + $this->lines = array(); $sql = 'SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,'; - $sql.= ' d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,'; - $sql.= ' d.fk_unit,'; - $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label, p.tobatch as product_batch,'; - $sql.= ' p.weight, p.weight_units, p.volume, p.volume_units,'; - $sql.= ' d.date_start, d.date_end,'; - $sql.= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as d'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (d.fk_product = p.rowid)'; - $sql.= ' WHERE d.fk_propal = '.$this->id; + $sql .= ' d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,'; + $sql .= ' d.fk_unit,'; + $sql .= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label, p.tobatch as product_batch,'; + $sql .= ' p.weight, p.weight_units, p.volume, p.volume_units,'; + $sql .= ' d.date_start, d.date_end,'; + $sql .= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as d'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (d.fk_product = p.rowid)'; + $sql .= ' WHERE d.fk_propal = '.$this->id; if ($only_product) $sql .= ' AND p.fk_product_type = 0'; - $sql.= ' ORDER by d.rang'; + $sql .= ' ORDER by d.rang'; dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); $result = $this->db->query($sql); @@ -1659,14 +1659,14 @@ class Propal extends CommonObject $line = new PropaleLigne($this->db); - $line->rowid = $objp->rowid; //Deprecated - $line->id = $objp->rowid; - $line->fk_propal = $objp->fk_propal; - $line->fk_parent_line = $objp->fk_parent_line; + $line->rowid = $objp->rowid; //Deprecated + $line->id = $objp->rowid; + $line->fk_propal = $objp->fk_propal; + $line->fk_parent_line = $objp->fk_parent_line; $line->product_type = $objp->product_type; $line->label = $objp->custom_label; - $line->desc = $objp->description; // Description ligne - $line->description = $objp->description; // Description ligne + $line->desc = $objp->description; // Description ligne + $line->description = $objp->description; // Description ligne $line->qty = $objp->qty; $line->vat_src_code = $objp->vat_src_code; $line->tva_tx = $objp->tva_tx; @@ -1677,7 +1677,7 @@ class Propal extends CommonObject $line->subprice = $objp->subprice; $line->fk_remise_except = $objp->fk_remise_except; $line->remise_percent = $objp->remise_percent; - $line->price = $objp->price; // TODO deprecated + $line->price = $objp->price; // TODO deprecated $line->info_bits = $objp->info_bits; $line->total_ht = $objp->total_ht; @@ -1685,9 +1685,9 @@ class Propal extends CommonObject $line->total_localtax1 = $objp->total_localtax1; $line->total_localtax2 = $objp->total_localtax2; $line->total_ttc = $objp->total_ttc; - $line->fk_fournprice = $objp->fk_fournprice; - $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht); - $line->pa_ht = $marginInfos[0]; + $line->fk_fournprice = $objp->fk_fournprice; + $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht); + $line->pa_ht = $marginInfos[0]; $line->marge_tx = $marginInfos[1]; $line->marque_tx = $marginInfos[2]; $line->special_code = $objp->special_code; @@ -1722,13 +1722,13 @@ class Propal extends CommonObject $line->fetch_optionals(); // multilangs - if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($objp->fk_product) && ! empty($loadalsotranslation)) { + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) { $line = new Product($this->db); $line->fetch($objp->fk_product); $line->getMultiLangs(); } - $this->lines[$i] = $line; + $this->lines[$i] = $line; //dol_syslog("1 ".$line->fk_product); //print "xx $i ".$this->lines[$i]->fk_product; $i++; @@ -1740,7 +1740,7 @@ class Propal extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -3; } } @@ -1758,7 +1758,7 @@ class Propal extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $error=0; + $error = 0; // Protection if ($this->statut == self::STATUS_VALIDATED) @@ -1767,15 +1767,15 @@ class Propal extends CommonObject return 0; } - if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->propal_advance->validate)))) + if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)))) { - $this->error='ErrorPermissionDenied'; + $this->error = 'ErrorPermissionDenied'; dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); return -1; } - $now=dol_now(); + $now = dol_now(); $this->db->begin(); @@ -1784,7 +1784,7 @@ class Propal extends CommonObject $soc->fetch($this->socid); // Define new ref - if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life + if (!$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($soc); } @@ -1795,28 +1795,28 @@ class Propal extends CommonObject $this->newref = $num; $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql.= " SET ref = '".$num."',"; - $sql.= " fk_statut = ".self::STATUS_VALIDATED.", date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; + $sql .= " SET ref = '".$num."',"; + $sql .= " fk_statut = ".self::STATUS_VALIDATED.", date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; dol_syslog(get_class($this)."::valid", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) + $resql = $this->db->query($sql); + if (!$resql) { dol_print_error($this->db); $error++; } // Trigger calls - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('PROPAL_VALIDATE', $user); + $result = $this->call_trigger('PROPAL_VALIDATE', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->oldref = $this->ref; @@ -1824,41 +1824,41 @@ class Propal extends CommonObject 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 = 'propale/".$this->db->escape($this->newref)."'"; - $sql.= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'propale/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'propale/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'propale/".$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->propal->multidir_output[$this->entity].'/'.$oldref; $dirdest = $conf->propal->multidir_output[$this->entity].'/'.$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)) { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref - $listoffiles=dol_dir_list($dirdest, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach($listoffiles as $fileentry) + $listoffiles = dol_dir_list($dirdest, 'files', 1, '^'.preg_quote($oldref, '/')); + foreach ($listoffiles as $fileentry) { - $dirsource=$fileentry['name']; - $dirdest=preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); - $dirsource=$fileentry['path'].'/'.$dirsource; - $dirdest=$fileentry['path'].'/'.$dirdest; + $dirsource = $fileentry['name']; + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); + $dirsource = $fileentry['path'].'/'.$dirsource; + $dirdest = $fileentry['path'].'/'.$dirdest; @rename($dirsource, $dirdest); } } } } - $this->ref=$num; - $this->brouillon=0; + $this->ref = $num; + $this->brouillon = 0; $this->statut = self::STATUS_VALIDATED; - $this->user_valid_id=$user->id; - $this->datev=$now; + $this->user_valid_id = $user->id; + $this->datev = $now; $this->db->commit(); return 1; @@ -1885,57 +1885,57 @@ class Propal extends CommonObject // phpcs:enable if (empty($date)) { - $this->error='ErrorBadParameter'; + $this->error = 'ErrorBadParameter'; dol_syslog(get_class($this)."::set_date ".$this->error, LOG_ERR); return -1; } - if (! empty($user->rights->propal->creer)) + if (!empty($user->rights->propal->creer)) { - $error=0; + $error = 0; $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = '".$this->db->idate($date)."'"; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; dol_syslog(__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->date = $date; - $this->datep = $date; // deprecated + $this->datep = $date; // deprecated } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } } @@ -1952,52 +1952,52 @@ class Propal extends CommonObject public function set_echeance($user, $date_fin_validite, $notrigger = 0) { // phpcs:enable - if (! empty($user->rights->propal->creer)) + if (!empty($user->rights->propal->creer)) { - $error=0; + $error = 0; $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite!=''?"'".$this->db->idate($date_fin_validite)."'":'null'); - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite != '' ? "'".$this->db->idate($date_fin_validite)."'" : 'null'); + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; dol_syslog(__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->fin_validite = $date_fin_validite; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } } @@ -2014,52 +2014,52 @@ class Propal extends CommonObject public function set_date_livraison($user, $date_livraison, $notrigger = 0) { // phpcs:enable - if (! empty($user->rights->propal->creer)) + if (!empty($user->rights->propal->creer)) { - $error=0; + $error = 0; $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; - $sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null'); - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET date_livraison = ".($date_livraison != '' ? "'".$this->db->idate($date_livraison)."'" : 'null'); + $sql .= " WHERE rowid = ".$this->id; dol_syslog(__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->date_livraison = $date_livraison; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } } @@ -2076,61 +2076,61 @@ class Propal extends CommonObject public function set_availability($user, $id, $notrigger = 0) { // phpcs:enable - if (! empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) + if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) { - $error=0; + $error = 0; $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; - $sql.= " SET fk_availability = '".$id."'"; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET fk_availability = '".$id."'"; + $sql .= " WHERE rowid = ".$this->id; dol_syslog(__METHOD__.' availability('.$id.')', LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->fk_availability = $id; $this->availability_id = $id; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } else { - $error_str='Propal status do not meet requirement '.$this->statut; + $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); - $this->error=$error_str; - $this->errors[]= $this->error; + $this->error = $error_str; + $this->errors[] = $this->error; return -2; } } @@ -2147,63 +2147,63 @@ class Propal extends CommonObject public function set_demand_reason($user, $id, $notrigger = 0) { // phpcs:enable - if (! empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) + if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) { - $error=0; + $error = 0; $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; - $sql.= " SET fk_input_reason = ".$id; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET fk_input_reason = ".$id; + $sql .= " WHERE rowid = ".$this->id; dol_syslog(__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->fk_input_reason = $id; $this->demand_reason_id = $id; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } else { - $error_str='Propal status do not meet requirement '.$this->statut; + $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); - $this->error=$error_str; - $this->errors[]= $this->error; + $this->error = $error_str; + $this->errors[] = $this->error; return -2; } } @@ -2220,51 +2220,51 @@ class Propal extends CommonObject public function set_ref_client($user, $ref_client, $notrigger = 0) { // phpcs:enable - if (! empty($user->rights->propal->creer)) + if (!empty($user->rights->propal->creer)) { - $error=0; + $error = 0; $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); - $sql.= ' WHERE rowid = '.$this->id; + $sql .= ' WHERE rowid = '.$this->id; dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->ref_client = $ref_client; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } else @@ -2285,56 +2285,56 @@ class Propal extends CommonObject public function set_remise_percent($user, $remise, $notrigger = 0) { // phpcs:enable - $remise=trim($remise)?trim($remise):0; + $remise = trim($remise) ?trim($remise) : 0; - if (! empty($user->rights->propal->creer)) + if (!empty($user->rights->propal->creer)) { $remise = price2num($remise); - $error=0; + $error = 0; $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; dol_syslog(__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->remise_percent = $remise; $this->update_price(1); } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } } @@ -2352,57 +2352,57 @@ class Propal extends CommonObject public function set_remise_absolue($user, $remise, $notrigger = 0) { // phpcs:enable - $remise=trim($remise)?trim($remise):0; + $remise = trim($remise) ?trim($remise) : 0; - if (! empty($user->rights->propal->creer)) + if (!empty($user->rights->propal->creer)) { $remise = price2num($remise); - $error=0; + $error = 0; $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; - $sql.= " SET remise_absolue = ".$remise; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; + $sql .= " SET remise_absolue = ".$remise; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; dol_syslog(__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->remise_absolue = $remise; $this->update_price(1); } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } } @@ -2422,27 +2422,27 @@ class Propal extends CommonObject { $this->statut = $statut; - $error=0; + $error = 0; $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql.= " SET fk_statut = ".$this->statut.","; - if (! empty($note)) $sql.= " note_private = '".$this->db->escape($note)."',"; - $sql.= " date_cloture=NULL, fk_user_cloture=NULL"; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET fk_statut = ".$this->statut.","; + if (!empty($note)) $sql .= " note_private = '".$this->db->escape($note)."',"; + $sql .= " date_cloture=NULL, fk_user_cloture=NULL"; + $sql .= " WHERE rowid = ".$this->id; $this->db->begin(); dol_syslog(get_class($this)."::reopen", LOG_DEBUG); $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) { - if (! $notrigger) + if (!$notrigger) { // Call trigger - $result=$this->call_trigger('PROPAL_REOPEN', $user); + $result = $this->call_trigger('PROPAL_REOPEN', $user); if ($result < 0) { $error++; } // End call triggers } @@ -2453,14 +2453,14 @@ class Propal extends CommonObject { if (!empty($this->errors)) { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } } $this->db->rollback(); - return -1*$error; + return -1 * $error; } else { @@ -2481,78 +2481,78 @@ class Propal extends CommonObject */ public function cloture($user, $statut, $note = "", $notrigger = 0) { - global $langs,$conf; + global $langs, $conf; - $error=0; - $now=dol_now(); + $error = 0; + $now = dol_now(); $this->db->begin(); $newprivatenote = dol_concatdesc($this->note_private, $note); $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql.= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($newprivatenote)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($newprivatenote)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id; + $sql .= " WHERE rowid = ".$this->id; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $modelpdf=$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED?$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED:$this->modelpdf; - $trigger_name='PROPAL_CLOSE_REFUSED'; + $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->modelpdf; + $trigger_name = 'PROPAL_CLOSE_REFUSED'; if ($statut == self::STATUS_SIGNED) { - $trigger_name='PROPAL_CLOSE_SIGNED'; - $modelpdf=$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL?$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL:$this->modelpdf; + $trigger_name = 'PROPAL_CLOSE_SIGNED'; + $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->modelpdf; // The connected company is classified as a client - $soc=new Societe($this->db); + $soc = new Societe($this->db); $soc->id = $this->socid; - $result=$soc->set_as_client(); + $result = $soc->set_as_client(); if ($result < 0) { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return -2; } } if ($statut == self::STATUS_BILLED) // Why this ? { - $trigger_name='PROPAL_CLASSIFY_BILLED'; + $trigger_name = 'PROPAL_CLASSIFY_BILLED'; } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) + if (!empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("", $conf); - $newlang=(GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang); + $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } //$ret=$object->fetch($id); // Reload to get new records $this->generateDocument($modelpdf, $outputlangs); } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->statut = $statut; $this->date_cloture = $now; $this->note_private = $newprivatenote; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger($trigger_name, $user); + $result = $this->call_trigger($trigger_name, $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; @@ -2569,7 +2569,7 @@ class Propal extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } @@ -2584,7 +2584,7 @@ class Propal extends CommonObject */ public function classifyBilled(User $user, $notrigger = 0) { - $error=0; + $error = 0; $this->db->begin(); @@ -2592,41 +2592,41 @@ class Propal extends CommonObject $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; dol_syslog(__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; - $this->statut=self::STATUS_BILLED; + $this->oldcopy = clone $this; + $this->statut = self::STATUS_BILLED; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } @@ -2641,7 +2641,7 @@ class Propal extends CommonObject public function setDraft($user, $notrigger = 0) { // phpcs:enable - $error=0; + $error = 0; // Protection if ($this->statut <= self::STATUS_DRAFT) @@ -2654,30 +2654,30 @@ class Propal extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql.= " SET fk_statut = ".self::STATUS_DRAFT; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET fk_statut = ".self::STATUS_DRAFT; + $sql .= " WHERE rowid = ".$this->id; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->statut = self::STATUS_DRAFT; $this->brouillon = 1; @@ -2687,13 +2687,13 @@ class Propal extends CommonObject } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } @@ -2720,25 +2720,25 @@ class Propal extends CommonObject $ga = array(); $sql = "SELECT s.rowid, s.nom as name, s.client,"; - $sql.= " p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, "; - $sql.= " p.datep as dp, p.fin_validite as datelimite"; - if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; - if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE p.entity IN (".getEntity('propal').")"; - $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.fk_statut = c.id"; - if (! $user->rights->societe->client->voir && ! $socid) //restriction + $sql .= " p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, "; + $sql .= " p.datep as dp, p.fin_validite as datelimite"; + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE p.entity IN (".getEntity('propal').")"; + $sql .= " AND p.fk_soc = s.rowid"; + $sql .= " AND p.fk_statut = c.id"; + if (!$user->rights->societe->client->voir && !$socid) //restriction { - $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; } - if ($socid) $sql.= " AND s.rowid = ".$socid; - if ($draft) $sql.= " AND p.fk_statut = ".self::STATUS_DRAFT; - if ($notcurrentuser > 0) $sql.= " AND p.fk_user_author <> ".$user->id; - $sql.= $this->db->order($sortfield, $sortorder); - $sql.= $this->db->plimit($limit, $offset); + if ($socid) $sql .= " AND s.rowid = ".$socid; + if ($draft) $sql .= " AND p.fk_statut = ".self::STATUS_DRAFT; + if ($notcurrentuser > 0) $sql .= " AND p.fk_user_author <> ".$user->id; + $sql .= $this->db->order($sortfield, $sortorder); + $sql .= $this->db->plimit($limit, $offset); - $result=$this->db->query($sql); + $result = $this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); @@ -2759,7 +2759,7 @@ class Propal extends CommonObject } else { - $ga[$i]['id'] = $obj->propalid; + $ga[$i]['id'] = $obj->propalid; $ga[$i]['ref'] = $obj->ref; $ga[$i]['name'] = $obj->name; } @@ -2800,11 +2800,11 @@ class Propal extends CommonObject $linkedInvoices = array(); $this->fetchObjectLinked($id, $this->element); - foreach($this->linkedObjectsIds as $objecttype => $objectid) + foreach ($this->linkedObjectsIds as $objecttype => $objectid) { // Nouveau système du comon object renvoi des rowid et non un id linéaire de 1 à n // On parcourt donc une liste d'objets en tant qu'objet unique - foreach($objectid as $key => $object) + foreach ($objectid as $key => $object) { // Cas des factures liees directement if ($objecttype == 'facture') @@ -2815,9 +2815,9 @@ class Propal extends CommonObject else { $this->fetchObjectLinked($object, $objecttype); - foreach($this->linkedObjectsIds as $subobjecttype => $subobjectid) + foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) { - foreach($subobjectid as $subkey => $subobject) + foreach ($subobjectid as $subkey => $subobject) { if ($subobjecttype == 'facture') { @@ -2831,18 +2831,18 @@ class Propal extends CommonObject if (count($linkedInvoices) > 0) { - $sql= "SELECT rowid as facid, ref, total, datef as df, fk_user_author, fk_statut, paye"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; - $sql.= " WHERE rowid IN (".implode(',', $linkedInvoices).")"; + $sql = "SELECT rowid as facid, ref, total, datef as df, fk_user_author, fk_statut, paye"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; + $sql .= " WHERE rowid IN (".implode(',', $linkedInvoices).")"; dol_syslog(get_class($this)."::InvoiceArrayList", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $tab_sqlobj=array(); + $tab_sqlobj = array(); $nump = $this->db->num_rows($resql); - for ($i = 0;$i < $nump;$i++) + for ($i = 0; $i < $nump; $i++) { $sqlobj = $this->db->fetch_object($resql); $tab_sqlobj[] = $sqlobj; @@ -2885,19 +2885,19 @@ class Propal extends CommonObject global $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $error=0; + $error = 0; $this->db->begin(); - if (! $notrigger) + if (!$notrigger) { // Call trigger - $result=$this->call_trigger('PROPAL_DELETE', $user); + $result = $this->call_trigger('PROPAL_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id; if ($this->db->query($sql)) @@ -2913,33 +2913,33 @@ class Propal extends CommonObject $res = $this->delete_linked_contact(); if ($res < 0) $error++; - if (! $error) + if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->propal->multidir_output[$this->entity] && !empty($this->ref)) { - $dir = $conf->propal->multidir_output[$this->entity] . "/" . $ref ; - $file = $dir . "/" . $ref . ".pdf"; + $dir = $conf->propal->multidir_output[$this->entity]."/".$ref; + $file = $dir."/".$ref.".pdf"; if (file_exists($file)) { dol_delete_preview($this); - if (! dol_delete_file($file, 0, 0, 0, $this)) // For triggers + if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers { - $this->error='ErrorFailToDeleteFile'; - $this->errors=array('ErrorFailToDeleteFile'); + $this->error = 'ErrorFailToDeleteFile'; + $this->errors = array('ErrorFailToDeleteFile'); $this->db->rollback(); return 0; } } if (file_exists($dir)) { - $res=@dol_delete_dir_recursive($dir); - if (! $res) + $res = @dol_delete_dir_recursive($dir); + if (!$res) { - $this->error='ErrorFailToDeleteDir'; - $this->errors=array('ErrorFailToDeleteDir'); + $this->error = 'ErrorFailToDeleteDir'; + $this->errors = array('ErrorFailToDeleteDir'); $this->db->rollback(); return 0; } @@ -2948,21 +2948,21 @@ class Propal extends CommonObject } // Removed extrafields - if (! $error) + if (!$error) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $result=$this->deleteExtraFields(); + $result = $this->deleteExtraFields(); if ($result < 0) { $error++; - $errorflag=-4; + $errorflag = -4; dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); } } } - if (! $error) + if (!$error) { dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG); $this->db->commit(); @@ -2970,21 +2970,21 @@ class Propal extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return 0; } } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return -3; } } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return -2; } @@ -3010,7 +3010,7 @@ class Propal extends CommonObject if ($this->statut >= self::STATUS_DRAFT) { - $error=0; + $error = 0; $this->db->begin(); @@ -3019,49 +3019,49 @@ class Propal extends CommonObject $sql .= ' WHERE rowid='.$this->id; dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->availability_id = $availability_id; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } else { - $error_str='Propal status do not meet requirement '.$this->statut; + $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); - $this->error=$error_str; - $this->errors[]= $this->error; + $this->error = $error_str; + $this->errors[] = $this->error; return -2; } } @@ -3082,7 +3082,7 @@ class Propal extends CommonObject if ($this->statut >= self::STATUS_DRAFT) { - $error=0; + $error = 0; $this->db->begin(); @@ -3091,49 +3091,49 @@ class Propal extends CommonObject $sql .= ' WHERE rowid='.$this->id; dol_syslog(__METHOD__.' demand_reason('.$demand_reason_id.')', LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { - $this->errors[]=$this->db->error(); + $this->errors[] = $this->db->error(); $error++; } - if (! $error) + if (!$error) { - $this->oldcopy= clone $this; + $this->oldcopy = clone $this; $this->demand_reason_id = $demand_reason_id; } - if (! $notrigger && empty($error)) + if (!$notrigger && empty($error)) { // Call trigger - $result=$this->call_trigger('PROPAL_MODIFY', $user); + $result = $this->call_trigger('PROPAL_MODIFY', $user); if ($result < 0) $error++; // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - foreach($this->errors as $errmsg) + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); - return -1*$error; + return -1 * $error; } } else { - $error_str='Propal status do not meet requirement '.$this->statut; + $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); - $this->error=$error_str; - $this->errors[]= $this->error; + $this->error = $error_str; + $this->errors[] = $this->error; return -2; } } @@ -3148,10 +3148,10 @@ class Propal extends CommonObject public function info($id) { $sql = "SELECT c.rowid, "; - $sql.= " c.datec, c.date_valid as datev, c.date_cloture as dateo,"; - $sql.= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture"; - $sql.= " FROM ".MAIN_DB_PREFIX."propal as c"; - $sql.= " WHERE c.rowid = ".$id; + $sql .= " c.datec, c.date_valid as datev, c.date_cloture as dateo,"; + $sql .= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as c"; + $sql .= " WHERE c.rowid = ".$id; $result = $this->db->query($sql); @@ -3169,20 +3169,20 @@ class Propal extends CommonObject $cuser = new User($this->db); $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; + $this->user_creation = $cuser; if ($obj->fk_user_valid) { $vuser = new User($this->db); $vuser->fetch($obj->fk_user_valid); - $this->user_validation = $vuser; + $this->user_validation = $vuser; } if ($obj->fk_user_cloture) { $cluser = new User($this->db); $cluser->fetch($obj->fk_user_cloture); - $this->user_cloture = $cluser; + $this->user_cloture = $cluser; } } $this->db->free($result); @@ -3305,10 +3305,10 @@ class Propal extends CommonObject $response->img = img_object('', "propal"); // This assignment in condition is not a bug. It allows walking the results. - while ($obj=$this->db->fetch_object($resql)) + while ($obj = $this->db->fetch_object($resql)) { $response->nbtodo++; - $response->total+=$obj->total_ht; + $response->total += $obj->total_ht; if ($mode == 'opened') { @@ -3326,7 +3326,7 @@ class Propal extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -3347,8 +3347,8 @@ class Propal extends CommonObject $num_prods = 0; $prodids = array(); $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."product"; - $sql.= " WHERE entity IN (".getEntity('product').")"; + $sql .= " FROM ".MAIN_DB_PREFIX."product"; + $sql .= " WHERE entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); if ($resql) { @@ -3363,13 +3363,13 @@ class Propal extends CommonObject } // Initialise parametres - $this->id=0; + $this->id = 0; $this->ref = 'SPECIMEN'; - $this->ref_client='NEMICEPS'; - $this->specimen=1; + $this->ref_client = 'NEMICEPS'; + $this->specimen = 1; $this->socid = 1; $this->date = time(); - $this->fin_validite = $this->date+3600*24*30; + $this->fin_validite = $this->date + 3600 * 24 * 30; $this->cond_reglement_id = 1; $this->cond_reglement_code = 'RECEP'; $this->mode_reglement_id = 7; @@ -3378,44 +3378,44 @@ class Propal extends CommonObject $this->availability_code = 'AV_NOW'; $this->demand_reason_id = 1; $this->demand_reason_code = 'SRC_00'; - $this->note_public='This is a comment (public)'; - $this->note_private='This is a comment (private)'; + $this->note_public = 'This is a comment (public)'; + $this->note_private = 'This is a comment (private)'; // Lines $nbp = 5; $xnbp = 0; while ($xnbp < $nbp) { - $line=new PropaleLigne($this->db); - $line->desc=$langs->trans("Description")." ".$xnbp; - $line->qty=1; - $line->subprice=100; - $line->price=100; - $line->tva_tx=20; - $line->localtax1_tx=0; - $line->localtax2_tx=0; + $line = new PropaleLigne($this->db); + $line->desc = $langs->trans("Description")." ".$xnbp; + $line->qty = 1; + $line->subprice = 100; + $line->price = 100; + $line->tva_tx = 20; + $line->localtax1_tx = 0; + $line->localtax2_tx = 0; if ($xnbp == 2) { - $line->total_ht=50; - $line->total_ttc=60; - $line->total_tva=10; - $line->remise_percent=50; + $line->total_ht = 50; + $line->total_ttc = 60; + $line->total_tva = 10; + $line->remise_percent = 50; } else { - $line->total_ht=100; - $line->total_ttc=120; - $line->total_tva=20; - $line->remise_percent=00; + $line->total_ht = 100; + $line->total_ttc = 120; + $line->total_tva = 20; + $line->remise_percent = 00; } if ($num_prods > 0) { $prodid = mt_rand(1, $num_prods); - $line->fk_product=$prodids[$prodid]; - $line->product_ref='SPECIMEN'; + $line->fk_product = $prodids[$prodid]; + $line->product_ref = 'SPECIMEN'; } - $this->lines[$xnbp]=$line; + $this->lines[$xnbp] = $line; $this->total_ht += $line->total_ht; $this->total_tva += $line->total_tva; @@ -3464,7 +3464,7 @@ class Propal extends CommonObject else { dol_print_error($this->db); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -3479,14 +3479,14 @@ class Propal extends CommonObject */ public function getNextNumRef($soc) { - global $conf,$langs; + global $conf, $langs; $langs->load("propal"); $classname = $conf->global->PROPALE_ADDON; - if (! empty($classname)) + if (!empty($classname)) { - $mybool=false; + $mybool = false; $file = $classname.".php"; @@ -3496,10 +3496,10 @@ class Propal extends CommonObject $dir = dol_buildpath($reldir."core/modules/propale/"); // Load file with numbering class (if found) - $mybool|=@include_once $dir.$file; + $mybool |= @include_once $dir.$file; } - if (! $mybool) + if (!$mybool) { dol_print_error('', "Failed to include file ".$file); return ''; @@ -3515,7 +3515,7 @@ class Propal extends CommonObject } else { - $this->error=$obj->error; + $this->error = $obj->error; //dol_print_error($db,"Propale::getNextNumRef ".$obj->error); return ""; } @@ -3542,66 +3542,66 @@ class Propal extends CommonObject { global $langs, $conf, $user; - if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips - $result=''; - $label=''; - $url=''; + $result = ''; + $label = ''; + $url = ''; if ($user->rights->propal->lire) { - $label = '' . $langs->trans("ShowPropal") . ''; - if (! empty($this->ref)) - $label.= '
'.$langs->trans('Ref').': '.$this->ref; - if (! empty($this->ref_client)) - $label.= '
'.$langs->trans('RefCustomer').': '.$this->ref_client; - if (! empty($this->total_ht)) - $label.= '
' . $langs->trans('AmountHT') . ': ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); - if (! empty($this->total_tva)) - $label.= '
' . $langs->trans('VAT') . ': ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); - if (! empty($this->total_ttc)) - $label.= '
' . $langs->trans('AmountTTC') . ': ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); + $label = ''.$langs->trans("ShowPropal").''; + if (!empty($this->ref)) + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + if (!empty($this->ref_client)) + $label .= '
'.$langs->trans('RefCustomer').': '.$this->ref_client; + if (!empty($this->total_ht)) + $label .= '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); + if (!empty($this->total_tva)) + $label .= '
'.$langs->trans('VAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); + if (!empty($this->total_ttc)) + $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); if ($option == '') { - $url = DOL_URL_ROOT.'/comm/propal/card.php?id='.$this->id. $get_params; + $url = DOL_URL_ROOT.'/comm/propal/card.php?id='.$this->id.$get_params; } elseif ($option == 'compta') { // deprecated - $url = DOL_URL_ROOT.'/comm/propal/card.php?id='.$this->id. $get_params; + $url = DOL_URL_ROOT.'/comm/propal/card.php?id='.$this->id.$get_params; } elseif ($option == 'expedition') { - $url = DOL_URL_ROOT.'/expedition/propal.php?id='.$this->id. $get_params; + $url = DOL_URL_ROOT.'/expedition/propal.php?id='.$this->id.$get_params; } elseif ($option == 'document') { - $url = DOL_URL_ROOT.'/comm/propal/document.php?id='.$this->id. $get_params; + $url = DOL_URL_ROOT.'/comm/propal/document.php?id='.$this->id.$get_params; } if ($option != 'nolink') { // 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'; + $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'; } } - $linkclose=''; + $linkclose = ''; if (empty($notooltip) && $user->rights->propal->lire) { - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label=$langs->trans("ShowPropal"); - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + $label = $langs->trans("ShowPropal"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose.=' class="classfortooltip"'; + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; } $linkstart = ''; - $linkend=''; + $linkstart .= $linkclose.'>'; + $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; + 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; $result .= $linkend; return $result; @@ -3630,16 +3630,16 @@ class Propal extends CommonObject */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) { - global $conf,$langs; + global $conf, $langs; $langs->load("propale"); - if (! dol_strlen($modele)) { + if (!dol_strlen($modele)) { $modele = 'azur'; if ($this->modelpdf) { $modele = $this->modelpdf; - } elseif (! empty($conf->global->PROPALE_ADDON_PDF)) { + } elseif (!empty($conf->global->PROPALE_ADDON_PDF)) { $modele = $conf->global->PROPALE_ADDON_PDF; } } @@ -3676,20 +3676,20 @@ class PropaleLigne extends CommonObjectLine /** * @var string ID to identify managed object */ - public $element='propaldet'; + public $element = 'propaldet'; /** * @var string Name of table without prefix where object is stored */ - public $table_element='propaldet'; + public $table_element = 'propaldet'; public $oldline; // From llx_propaldet public $fk_propal; public $fk_parent_line; - public $desc; // Description ligne - public $fk_product; // Id produit predefini + public $desc; // Description ligne + public $fk_product; // Id produit predefini /** * @deprecated * @see $product_type @@ -3715,18 +3715,18 @@ class PropaleLigne extends CommonObjectLine public $marge_tx; public $marque_tx; - public $special_code; // Tag for special lines (exlusive tags) + public $special_code; // Tag for special lines (exlusive tags) // 1: frais de port // 2: ecotaxe // 3: option line (when qty = 0) - public $info_bits = 0; // Some other info: + public $info_bits = 0; // Some other info: // Bit 0: 0 si TVA normal - 1 si TVA NPR // Bit 1: 0 ligne normale - 1 si ligne de remise fixe - public $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne - public $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne - public $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne + public $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne + public $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne + public $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne /** * @deprecated @@ -3766,12 +3766,12 @@ class PropaleLigne extends CommonObjectLine */ public $product_desc; - public $localtax1_tx; // Local tax 1 - public $localtax2_tx; // Local tax 2 - public $localtax1_type; // Local tax 1 type - public $localtax2_type; // Local tax 2 type - public $total_localtax1; // Line total local tax 1 - public $total_localtax2; // Line total local tax 2 + public $localtax1_tx; // Local tax 1 + public $localtax2_tx; // Local tax 2 + public $localtax1_type; // Local tax 1 type + public $localtax2_type; // Local tax 2 type + public $total_localtax1; // Line total local tax 1 + public $total_localtax2; // Line total local tax 2 public $date_start; public $date_end; @@ -3793,7 +3793,7 @@ class PropaleLigne extends CommonObjectLine */ public function __construct($db) { - $this->db= $db; + $this->db = $db; } /** @@ -3805,16 +3805,16 @@ class PropaleLigne extends CommonObjectLine public function fetch($rowid) { $sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.vat_src_code, pd.tva_tx,'; - $sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,'; - $sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,'; - $sql.= ' pd.fk_unit,'; - $sql.= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,'; - $sql.= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,'; - $sql.= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,'; - $sql.= ' pd.date_start, pd.date_end, pd.product_type'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid'; - $sql.= ' WHERE pd.rowid = '.$rowid; + $sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,'; + $sql .= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,'; + $sql .= ' pd.fk_unit,'; + $sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,'; + $sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,'; + $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,'; + $sql .= ' pd.date_start, pd.date_end, pd.product_type'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid'; + $sql .= ' WHERE pd.rowid = '.$rowid; $result = $this->db->query($sql); if ($result) @@ -3823,28 +3823,28 @@ class PropaleLigne extends CommonObjectLine if ($objp) { - $this->id = $objp->rowid; - $this->rowid = $objp->rowid; // deprecated - $this->fk_propal = $objp->fk_propal; - $this->fk_parent_line = $objp->fk_parent_line; + $this->id = $objp->rowid; + $this->rowid = $objp->rowid; // deprecated + $this->fk_propal = $objp->fk_propal; + $this->fk_parent_line = $objp->fk_parent_line; $this->label = $objp->custom_label; $this->desc = $objp->description; - $this->qty = $objp->qty; - $this->price = $objp->price; // deprecated - $this->subprice = $objp->subprice; - $this->vat_src_code = $objp->vat_src_code; + $this->qty = $objp->qty; + $this->price = $objp->price; // deprecated + $this->subprice = $objp->subprice; + $this->vat_src_code = $objp->vat_src_code; $this->tva_tx = $objp->tva_tx; - $this->remise = $objp->remise; // deprecated - $this->remise_percent = $objp->remise_percent; + $this->remise = $objp->remise; // deprecated + $this->remise_percent = $objp->remise_percent; $this->fk_remise_except = $objp->fk_remise_except; - $this->fk_product = $objp->fk_product; + $this->fk_product = $objp->fk_product; $this->info_bits = $objp->info_bits; $this->total_ht = $objp->total_ht; $this->total_tva = $objp->total_tva; $this->total_ttc = $objp->total_ttc; - $this->fk_fournprice = $objp->fk_fournprice; + $this->fk_fournprice = $objp->fk_fournprice; $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht); $this->pa_ht = $marginInfos[0]; @@ -3853,11 +3853,11 @@ class PropaleLigne extends CommonObjectLine $this->special_code = $objp->special_code; $this->product_type = $objp->product_type; - $this->rang = $objp->rang; + $this->rang = $objp->rang; - $this->ref = $objp->product_ref; // deprecated - $this->product_ref = $objp->product_ref; - $this->libelle = $objp->product_label; // deprecated + $this->ref = $objp->product_ref; // deprecated + $this->product_ref = $objp->product_ref; + $this->libelle = $objp->product_label; // deprecated $this->product_label = $objp->product_label; $this->product_desc = $objp->product_desc; $this->fk_unit = $objp->fk_unit; @@ -3866,8 +3866,8 @@ class PropaleLigne extends CommonObjectLine $this->date_end = $this->db->jdate($objp->date_end); // Multicurrency - $this->fk_multicurrency = $objp->fk_multicurrency; - $this->multicurrency_code = $objp->multicurrency_code; + $this->fk_multicurrency = $objp->fk_multicurrency; + $this->multicurrency_code = $objp->multicurrency_code; $this->multicurrency_subprice = $objp->multicurrency_subprice; $this->multicurrency_total_ht = $objp->multicurrency_total_ht; $this->multicurrency_total_tva = $objp->multicurrency_total_tva; @@ -3898,35 +3898,35 @@ class PropaleLigne extends CommonObjectLine */ public function insert($notrigger = 0) { - global $conf,$user; + global $conf, $user; - $error=0; + $error = 0; dol_syslog(get_class($this)."::insert rang=".$this->rang); $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. // Clean parameters - if (empty($this->tva_tx)) $this->tva_tx=0; - if (empty($this->localtax1_tx)) $this->localtax1_tx=0; - if (empty($this->localtax2_tx)) $this->localtax2_tx=0; - if (empty($this->localtax1_type)) $this->localtax1_type=0; - if (empty($this->localtax2_type)) $this->localtax2_type=0; - if (empty($this->total_localtax1)) $this->total_localtax1=0; - if (empty($this->total_localtax2)) $this->total_localtax2=0; - if (empty($this->rang)) $this->rang=0; - if (empty($this->remise)) $this->remise=0; - if (empty($this->remise_percent) || ! is_numeric($this->remise_percent)) $this->remise_percent=0; - if (empty($this->info_bits)) $this->info_bits=0; - if (empty($this->special_code)) $this->special_code=0; - if (empty($this->fk_parent_line)) $this->fk_parent_line=0; - if (empty($this->fk_fournprice)) $this->fk_fournprice=0; - if (! is_numeric($this->qty)) $this->qty = 0; - if (empty($this->pa_ht)) $this->pa_ht=0; - if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice=0; - if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0; - if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0; - if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0; + if (empty($this->tva_tx)) $this->tva_tx = 0; + if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; + if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; + if (empty($this->localtax1_type)) $this->localtax1_type = 0; + if (empty($this->localtax2_type)) $this->localtax2_type = 0; + if (empty($this->total_localtax1)) $this->total_localtax1 = 0; + if (empty($this->total_localtax2)) $this->total_localtax2 = 0; + if (empty($this->rang)) $this->rang = 0; + if (empty($this->remise)) $this->remise = 0; + if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) $this->remise_percent = 0; + if (empty($this->info_bits)) $this->info_bits = 0; + if (empty($this->special_code)) $this->special_code = 0; + if (empty($this->fk_parent_line)) $this->fk_parent_line = 0; + if (empty($this->fk_fournprice)) $this->fk_fournprice = 0; + if (!is_numeric($this->qty)) $this->qty = 0; + if (empty($this->pa_ht)) $this->pa_ht = 0; + if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0; + if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0; + if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0; + if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0; // if buy price not defined, define buyprice as configured in margin admin if ($this->pa_ht == 0 && $pa_ht_isemptystring) @@ -3948,71 +3948,71 @@ class PropaleLigne extends CommonObjectLine // Insert line into database $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet'; - $sql.= ' (fk_propal, fk_parent_line, label, description, fk_product, product_type,'; - $sql.= ' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; - $sql.= ' subprice, remise_percent, '; - $sql.= ' info_bits, '; - $sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,'; - $sql.= ' fk_unit,'; - $sql.= ' date_start, date_end'; - $sql.= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)'; - $sql.= " VALUES (".$this->fk_propal.","; - $sql.= " ".($this->fk_parent_line>0?"'".$this->db->escape($this->fk_parent_line)."'":"null").","; - $sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").","; - $sql.= " '".$this->db->escape($this->desc)."',"; - $sql.= " ".($this->fk_product?"'".$this->db->escape($this->fk_product)."'":"null").","; - $sql.= " '".$this->db->escape($this->product_type)."',"; - $sql.= " ".($this->fk_remise_except?"'".$this->db->escape($this->fk_remise_except)."'":"null").","; - $sql.= " ".price2num($this->qty).","; - $sql.= " ".(empty($this->vat_src_code)?"''":"'".$this->db->escape($this->vat_src_code)."'").","; - $sql.= " ".price2num($this->tva_tx).","; - $sql.= " ".price2num($this->localtax1_tx).","; - $sql.= " ".price2num($this->localtax2_tx).","; - $sql.= " '".$this->db->escape($this->localtax1_type)."',"; - $sql.= " '".$this->db->escape($this->localtax2_type)."',"; - $sql.= " ".(price2num($this->subprice)!==''?price2num($this->subprice):"null").","; - $sql.= " ".price2num($this->remise_percent).","; - $sql.= " ".(isset($this->info_bits)?"'".$this->db->escape($this->info_bits)."'":"null").","; - $sql.= " ".price2num($this->total_ht).","; - $sql.= " ".price2num($this->total_tva).","; - $sql.= " ".price2num($this->total_localtax1).","; - $sql.= " ".price2num($this->total_localtax2).","; - $sql.= " ".price2num($this->total_ttc).","; - $sql.= " ".(!empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null").","; - $sql.= " ".(isset($this->pa_ht)?"'".price2num($this->pa_ht)."'":"null").","; - $sql.= ' '.$this->special_code.','; - $sql.= ' '.$this->rang.','; - $sql.= ' '.(!$this->fk_unit ? 'NULL' : $this->fk_unit).','; - $sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").','; - $sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null"); - $sql.= ", ".($this->fk_multicurrency > 0?$this->fk_multicurrency:'null'); - $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; - $sql.= ", ".$this->multicurrency_subprice; - $sql.= ", ".$this->multicurrency_total_ht; - $sql.= ", ".$this->multicurrency_total_tva; - $sql.= ", ".$this->multicurrency_total_ttc; - $sql.= ')'; + $sql .= ' (fk_propal, fk_parent_line, label, description, fk_product, product_type,'; + $sql .= ' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; + $sql .= ' subprice, remise_percent, '; + $sql .= ' info_bits, '; + $sql .= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,'; + $sql .= ' fk_unit,'; + $sql .= ' date_start, date_end'; + $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)'; + $sql .= " VALUES (".$this->fk_propal.","; + $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape($this->fk_parent_line)."'" : "null").","; + $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; + $sql .= " '".$this->db->escape($this->desc)."',"; + $sql .= " ".($this->fk_product ? "'".$this->db->escape($this->fk_product)."'" : "null").","; + $sql .= " '".$this->db->escape($this->product_type)."',"; + $sql .= " ".($this->fk_remise_except ? "'".$this->db->escape($this->fk_remise_except)."'" : "null").","; + $sql .= " ".price2num($this->qty).","; + $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").","; + $sql .= " ".price2num($this->tva_tx).","; + $sql .= " ".price2num($this->localtax1_tx).","; + $sql .= " ".price2num($this->localtax2_tx).","; + $sql .= " '".$this->db->escape($this->localtax1_type)."',"; + $sql .= " '".$this->db->escape($this->localtax2_type)."',"; + $sql .= " ".(price2num($this->subprice) !== '' ?price2num($this->subprice) : "null").","; + $sql .= " ".price2num($this->remise_percent).","; + $sql .= " ".(isset($this->info_bits) ? "'".$this->db->escape($this->info_bits)."'" : "null").","; + $sql .= " ".price2num($this->total_ht).","; + $sql .= " ".price2num($this->total_tva).","; + $sql .= " ".price2num($this->total_localtax1).","; + $sql .= " ".price2num($this->total_localtax2).","; + $sql .= " ".price2num($this->total_ttc).","; + $sql .= " ".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null").","; + $sql .= " ".(isset($this->pa_ht) ? "'".price2num($this->pa_ht)."'" : "null").","; + $sql .= ' '.$this->special_code.','; + $sql .= ' '.$this->rang.','; + $sql .= ' '.(!$this->fk_unit ? 'NULL' : $this->fk_unit).','; + $sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").','; + $sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null"); + $sql .= ", ".($this->fk_multicurrency > 0 ? $this->fk_multicurrency : 'null'); + $sql .= ", '".$this->db->escape($this->multicurrency_code)."'"; + $sql .= ", ".$this->multicurrency_subprice; + $sql .= ", ".$this->multicurrency_total_ht; + $sql .= ", ".$this->multicurrency_total_tva; + $sql .= ", ".$this->multicurrency_total_ttc; + $sql .= ')'; dol_syslog(get_class($this).'::insert', LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'propaldet'); + $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.'propaldet'); if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $this->id=$this->rowid; - $result=$this->insertExtraFields(); + $this->id = $this->rowid; + $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('LINEPROPAL_INSERT', $user); + $result = $this->call_trigger('LINEPROPAL_INSERT', $user); if ($result < 0) { $this->db->rollback(); @@ -4026,7 +4026,7 @@ class PropaleLigne extends CommonObjectLine } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error = $this->db->error()." sql=".$sql; $this->db->rollback(); return -1; } @@ -4043,18 +4043,18 @@ class PropaleLigne extends CommonObjectLine { global $conf; - $error=0; + $error = 0; $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE rowid = ".$this->rowid; dol_syslog("PropaleLigne::delete", LOG_DEBUG); - if ($this->db->query($sql) ) + if ($this->db->query($sql)) { // Remove extrafields - if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used + if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { - $this->id=$this->rowid; - $result=$this->deleteExtraFields(); + $this->id = $this->rowid; + $result = $this->deleteExtraFields(); if ($result < 0) { $error++; @@ -4062,10 +4062,10 @@ class PropaleLigne extends CommonObjectLine } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('LINEPROPAL_DELETE', $user); + $result = $this->call_trigger('LINEPROPAL_DELETE', $user); if ($result < 0) { $this->db->rollback(); @@ -4080,7 +4080,7 @@ class PropaleLigne extends CommonObjectLine } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error = $this->db->error()." sql=".$sql; $this->db->rollback(); return -1; } @@ -4094,31 +4094,31 @@ class PropaleLigne extends CommonObjectLine */ public function update($notrigger = 0) { - global $conf,$user; + global $conf, $user; - $error=0; + $error = 0; $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. // Clean parameters - if (empty($this->tva_tx)) $this->tva_tx=0; - if (empty($this->localtax1_tx)) $this->localtax1_tx=0; - if (empty($this->localtax2_tx)) $this->localtax2_tx=0; - if (empty($this->total_localtax1)) $this->total_localtax1=0; - if (empty($this->total_localtax2)) $this->total_localtax2=0; - if (empty($this->localtax1_type)) $this->localtax1_type=0; - if (empty($this->localtax2_type)) $this->localtax2_type=0; - if (empty($this->marque_tx)) $this->marque_tx=0; - if (empty($this->marge_tx)) $this->marge_tx=0; - if (empty($this->price)) $this->price=0; // TODO A virer - if (empty($this->remise)) $this->remise=0; // TODO A virer - if (empty($this->remise_percent)) $this->remise_percent=0; - if (empty($this->info_bits)) $this->info_bits=0; - if (empty($this->special_code)) $this->special_code=0; - if (empty($this->fk_parent_line)) $this->fk_parent_line=0; - if (empty($this->fk_fournprice)) $this->fk_fournprice=0; - if (empty($this->subprice)) $this->subprice=0; - if (empty($this->pa_ht)) $this->pa_ht=0; + if (empty($this->tva_tx)) $this->tva_tx = 0; + if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; + if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; + if (empty($this->total_localtax1)) $this->total_localtax1 = 0; + if (empty($this->total_localtax2)) $this->total_localtax2 = 0; + if (empty($this->localtax1_type)) $this->localtax1_type = 0; + if (empty($this->localtax2_type)) $this->localtax2_type = 0; + if (empty($this->marque_tx)) $this->marque_tx = 0; + if (empty($this->marge_tx)) $this->marge_tx = 0; + if (empty($this->price)) $this->price = 0; // TODO A virer + if (empty($this->remise)) $this->remise = 0; // TODO A virer + if (empty($this->remise_percent)) $this->remise_percent = 0; + if (empty($this->info_bits)) $this->info_bits = 0; + if (empty($this->special_code)) $this->special_code = 0; + if (empty($this->fk_parent_line)) $this->fk_parent_line = 0; + if (empty($this->fk_fournprice)) $this->fk_fournprice = 0; + if (empty($this->subprice)) $this->subprice = 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 && $pa_ht_isemptystring) @@ -4137,64 +4137,64 @@ class PropaleLigne extends CommonObjectLine // Mise a jour ligne en base $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET"; - $sql.= " description='".$this->db->escape($this->desc)."'"; - $sql.= ", label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null"); - $sql.= ", product_type=".$this->product_type; - $sql.= ", vat_src_code = '".(empty($this->vat_src_code)?'':$this->vat_src_code)."'"; - $sql.= ", tva_tx='".price2num($this->tva_tx)."'"; - $sql.= ", localtax1_tx=".price2num($this->localtax1_tx); - $sql.= ", localtax2_tx=".price2num($this->localtax2_tx); - $sql.= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'"; - $sql.= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'"; - $sql.= ", qty='".price2num($this->qty)."'"; - $sql.= ", subprice=".price2num($this->subprice).""; - $sql.= ", remise_percent=".price2num($this->remise_percent).""; - $sql.= ", price=".price2num($this->price).""; // TODO A virer - $sql.= ", remise=".price2num($this->remise).""; // TODO A virer - $sql.= ", info_bits='".$this->db->escape($this->info_bits)."'"; + $sql .= " description='".$this->db->escape($this->desc)."'"; + $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null"); + $sql .= ", product_type=".$this->product_type; + $sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->vat_src_code)."'"; + $sql .= ", tva_tx='".price2num($this->tva_tx)."'"; + $sql .= ", localtax1_tx=".price2num($this->localtax1_tx); + $sql .= ", localtax2_tx=".price2num($this->localtax2_tx); + $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'"; + $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'"; + $sql .= ", qty='".price2num($this->qty)."'"; + $sql .= ", subprice=".price2num($this->subprice).""; + $sql .= ", remise_percent=".price2num($this->remise_percent).""; + $sql .= ", price=".price2num($this->price).""; // TODO A virer + $sql .= ", remise=".price2num($this->remise).""; // TODO A virer + $sql .= ", info_bits='".$this->db->escape($this->info_bits)."'"; if (empty($this->skip_update_total)) { - $sql.= ", total_ht=".price2num($this->total_ht).""; - $sql.= ", total_tva=".price2num($this->total_tva).""; - $sql.= ", total_ttc=".price2num($this->total_ttc).""; - $sql.= ", total_localtax1=".price2num($this->total_localtax1).""; - $sql.= ", total_localtax2=".price2num($this->total_localtax2).""; + $sql .= ", total_ht=".price2num($this->total_ht).""; + $sql .= ", total_tva=".price2num($this->total_tva).""; + $sql .= ", total_ttc=".price2num($this->total_ttc).""; + $sql .= ", total_localtax1=".price2num($this->total_localtax1).""; + $sql .= ", total_localtax2=".price2num($this->total_localtax2).""; } - $sql.= ", fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null"); - $sql.= ", buy_price_ht=".price2num($this->pa_ht); - if (strlen($this->special_code)) $sql.= ", special_code=".$this->special_code; - $sql.= ", fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null"); - if (! empty($this->rang)) $sql.= ", rang=".$this->rang; - $sql.= ", date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null"); - $sql.= ", date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null"); - $sql.= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); + $sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null"); + $sql .= ", buy_price_ht=".price2num($this->pa_ht); + if (strlen($this->special_code)) $sql .= ", special_code=".$this->special_code; + $sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null"); + if (!empty($this->rang)) $sql .= ", rang=".$this->rang; + $sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null"); + $sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null"); + $sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); // Multicurrency - $sql.= ", multicurrency_subprice=".price2num($this->multicurrency_subprice).""; - $sql.= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; - $sql.= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; - $sql.= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; + $sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice).""; + $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; + $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; + $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - $sql.= " WHERE rowid = ".$this->rowid; + $sql .= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $this->id=$this->rowid; - $result=$this->insertExtraFields(); + $this->id = $this->rowid; + $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('LINEPROPAL_UPDATE', $user); + $result = $this->call_trigger('LINEPROPAL_UPDATE', $user); if ($result < 0) { $this->db->rollback(); @@ -4208,7 +4208,7 @@ class PropaleLigne extends CommonObjectLine } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -2; } @@ -4228,14 +4228,14 @@ class PropaleLigne extends CommonObjectLine // Mise a jour ligne en base $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET"; - $sql.= " total_ht=".price2num($this->total_ht, 'MT').""; - $sql.= ",total_tva=".price2num($this->total_tva, 'MT').""; - $sql.= ",total_ttc=".price2num($this->total_ttc, 'MT').""; - $sql.= " WHERE rowid = ".$this->rowid; + $sql .= " total_ht=".price2num($this->total_ht, 'MT').""; + $sql .= ",total_tva=".price2num($this->total_tva, 'MT').""; + $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT').""; + $sql .= " WHERE rowid = ".$this->rowid; dol_syslog("PropaleLigne::update_total", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $this->db->commit(); @@ -4243,7 +4243,7 @@ class PropaleLigne extends CommonObjectLine } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -2; } diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 9ecc68316c5..83ee0b5f622 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -74,7 +74,7 @@ if ($action == 'reopen' && $user->rights->tax->charges->creer) { $result = $object->set_unpaid($user); if ($result > 0) { - header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); exit(); } else { setEventMessages($object->error, $object->errors, 'errors'); @@ -108,7 +108,7 @@ if ($action == 'setmode' && $user->rights->tax->charges->creer) { // bank account if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { $object->fetch($id); - $result=$object->setBankAccount(GETPOST('fk_account', 'int')); + $result = $object->setBankAccount(GETPOST('fk_account', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } @@ -118,7 +118,7 @@ if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { if ($action == 'confirm_delete' && $confirm == 'yes') { $object->fetch($id); - $result=$object->delete($user); + $result = $object->delete($user); if ($result > 0) { header("Location: list.php"); @@ -134,22 +134,22 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // Add social contribution if ($action == 'add' && $user->rights->tax->charges->creer) { - $dateech=dol_mktime(GETPOST('echhour'), GETPOST('echmin'), GETPOST('echsec'), GETPOST('echmonth'), GETPOST('echday'), GETPOST('echyear')); - $dateperiod=dol_mktime(GETPOST('periodhour'), GETPOST('periodmin'), GETPOST('periodsec'), GETPOST('periodmonth'), GETPOST('periodday'), GETPOST('periodyear')); - $amount=price2num(GETPOST('amount')); - $actioncode=GETPOST('actioncode'); + $dateech = dol_mktime(GETPOST('echhour'), GETPOST('echmin'), GETPOST('echsec'), GETPOST('echmonth'), GETPOST('echday'), GETPOST('echyear')); + $dateperiod = dol_mktime(GETPOST('periodhour'), GETPOST('periodmin'), GETPOST('periodsec'), GETPOST('periodmonth'), GETPOST('periodday'), GETPOST('periodyear')); + $amount = price2num(GETPOST('amount')); + $actioncode = GETPOST('actioncode'); - if (! $dateech) + if (!$dateech) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateDue")), null, 'errors'); $action = 'create'; } - elseif (! $dateperiod) + elseif (!$dateperiod) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors'); $action = 'create'; } - elseif (! $actioncode > 0) + elseif (!$actioncode > 0) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); $action = 'create'; @@ -206,20 +206,20 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); $action = 'edit'; } - elseif (! is_numeric($amount)) + elseif (!is_numeric($amount)) { setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); $action = 'create'; } else { - $result=$object->fetch($id); + $result = $object->fetch($id); - $object->date_ech = $dateech; + $object->date_ech = $dateech; $object->periode = $dateperiod; $object->amount = price2num($amount); - $result=$object->update($user); + $result = $object->update($user); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -228,7 +228,7 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr } // Action clone object -if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; } +if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; } if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) { @@ -274,7 +274,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->char } else { - $id=$originalId; + $id = $originalId; $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); @@ -299,10 +299,10 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->char $form = new Form($db); $formsocialcontrib = new FormSocialContrib($db); $bankaccountstatic = new Account($db); -if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } +if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } -$title = $langs->trans("SocialContribution") . ' - ' . $langs->trans("Card"); -$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; +$title = $langs->trans("SocialContribution").' - '.$langs->trans("Card"); +$help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; llxHeader("", $title, $help_url); @@ -333,7 +333,7 @@ if ($action == 'create') print $langs->trans("Type"); print ''; print ''; - $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode", 'alpha')?GETPOST("actioncode", 'alpha'):'', 'actioncode', 1); + $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode", 'alpha') ?GETPOST("actioncode", 'alpha') : '', 'actioncode', 1); print ''; print ''; @@ -343,7 +343,7 @@ if ($action == 'create') print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")); print ''; print ''; - print $form->selectDate(! empty($dateperiod)?$dateperiod:'-1', 'period', 0, 0, 0, 'charge', 1); + print $form->selectDate(!empty($dateperiod) ? $dateperiod : '-1', 'period', 0, 0, 0, 'charge', 1); print ''; print ''; @@ -353,7 +353,7 @@ if ($action == 'create') print $langs->trans("DateDue"); print ''; print ''; - print $form->selectDate(! empty($dateech)?$dateech:'-1', 'ech', 0, 0, 0, 'charge', 1); + print $form->selectDate(!empty($dateech) ? $dateech : '-1', 'ech', 0, 0, 0, 'charge', 1); print ''; print "\n"; @@ -366,29 +366,29 @@ if ($action == 'create') print ''; // Project - if (! empty($conf->projet->enabled)) + if (!empty($conf->projet->enabled)) { - $formproject=new FormProjets($db); + $formproject = new FormProjets($db); // Associated project $langs->load("projects"); print ''.$langs->trans("Project").''; - $numproject=$formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1); + $numproject = $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1); print ''; } // Payment Mode - print '' . $langs->trans('PaymentMode') . ''; + print ''.$langs->trans('PaymentMode').''; $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id'); print ''; // Bank Account - if (! empty($conf->banque->enabled)) + if (!empty($conf->banque->enabled)) { - print '' . $langs->trans('BankAccount') . ''; + print ''.$langs->trans('BankAccount').''; $form->select_comptes($fk_account, 'fk_account', 0, '', 1); print ''; } @@ -400,7 +400,7 @@ if ($action == 'create') print '
'; print ''; print '     '; - print ''; + print ''; print '
'; print ''; @@ -414,28 +414,28 @@ if ($action == 'create') if ($id > 0) { $object = new ChargeSociales($db); - $result=$object->fetch($id); + $result = $object->fetch($id); if ($result > 0) { - $head=tax_prepare_head($object); + $head = tax_prepare_head($object); $totalpaye = $object->getSommePaiement(); // Clone confirmation if ($action === 'clone') { - $formquestion=array( + $formquestion = array( array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label), ); - if (! empty($conf->global->TAX_ADD_CLON_FOR_NEXT_MONTH_CHECKBOX)) + if (!empty($conf->global->TAX_ADD_CLON_FOR_NEXT_MONTH_CHECKBOX)) { - $formquestion[]=array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1); + $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1); } else { - $formquestion[]=array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1); - $formquestion[]=array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("DateDue"), 'value' => -1); + $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1); + $formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("DateDue"), 'value' => -1); } print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); @@ -558,18 +558,18 @@ if ($id > 0) print $langs->trans('PaymentMode'); print ''; if ($action != 'editmode') - print 'id . '">' . img_edit($langs->trans('SetMode'), 1) . ''; + print 'id.'">'.img_edit($langs->trans('SetMode'), 1).''; print ''; print ''; if ($action == 'editmode') { - $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id'); + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id'); } else { - $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none'); + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); } print ''; // Bank Account - if (! empty($conf->banque->enabled)) + if (!empty($conf->banque->enabled)) { print ''; print '
'; @@ -595,25 +595,25 @@ if ($id > 0) print '
'; $nbcols = 3; - if (! empty($conf->banque->enabled)) { - $nbcols ++; + if (!empty($conf->banque->enabled)) { + $nbcols++; } /* * Payments */ $sql = "SELECT p.rowid, p.num_paiement, datep as dp, p.amount,"; - $sql.= " c.code as type_code,c.libelle as paiement_type,"; - $sql.= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal'; - $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid'; - $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; - $sql.= " WHERE p.fk_charge = ".$id; - $sql.= " AND p.fk_charge = cs.rowid"; - $sql.= " AND cs.entity IN (".getEntity('tax').")"; - $sql.= " ORDER BY dp DESC"; + $sql .= " c.code as type_code,c.libelle as paiement_type,"; + $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal'; + $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id"; + $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql .= " WHERE p.fk_charge = ".$id; + $sql .= " AND p.fk_charge = cs.rowid"; + $sql .= " AND cs.entity IN (".getEntity('tax').")"; + $sql .= " ORDER BY dp DESC"; //print $sql; $resql = $db->query($sql); @@ -624,14 +624,14 @@ if ($id > 0) $num = $db->num_rows($resql); $i = 0; $total = 0; - print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table + print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; print ''; print ''; print ''; - if (! empty($conf->banque->enabled)) { - print ''; + if (!empty($conf->banque->enabled)) { + print ''; } print ''; print ''; @@ -645,16 +645,16 @@ if ($id > 0) print ''; print '\n"; - $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; + $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type; print "\n"; - if (! empty($conf->banque->enabled)) + if (!empty($conf->banque->enabled)) { $bankaccountstatic->id = $objp->baid; $bankaccountstatic->ref = $objp->baref; $bankaccountstatic->label = $objp->baref; $bankaccountstatic->number = $objp->banumber; - if (! empty($conf->accounting->enabled)) { + if (!empty($conf->accounting->enabled)) { $bankaccountstatic->account_number = $objp->account_number; $accountingjournal = new AccountingJournal($db); @@ -687,7 +687,7 @@ if ($id > 0) $cssforamountpaymentcomplete = 'amountpaymentcomplete'; print '"; - print '\n"; + print '\n"; print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").'' . $langs->trans('BankAccount') . ''.$langs->trans('BankAccount').''.$langs->trans("Amount").'
'; print ''.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp), 'day')."".$labeltype.' '.$objp->num_paiement."
'.$langs->trans("RemainderToPay")." :'.price($resteapayer)."
'.price($resteapayer)."
"; print '
'; @@ -730,7 +730,7 @@ if ($id > 0) // Reopen if ($object->paye && $user->rights->tax->charges->creer) { - print ""; + print ""; } // Edit @@ -746,7 +746,7 @@ if ($id > 0) } // Classify 'paid' - if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->tax->charges->creer) + if ($object->paye == 0 && round($resteapayer) <= 0 && $user->rights->tax->charges->creer) { print ""; } @@ -754,7 +754,7 @@ if ($id > 0) // Clone if ($user->rights->tax->charges->creer) { - print ""; + print ""; } // Delete diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index f8a43d70494..88cc24dcb2a 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -30,7 +30,7 @@ * \ingroup societe * \brief File of contacts class */ -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; /** @@ -41,12 +41,12 @@ class Contact extends CommonObject /** * @var string ID to identify managed object */ - public $element='contact'; + public $element = 'contact'; /** * @var string Name of table without prefix where object is stored */ - public $table_element='socpeople'; + public $table_element = 'socpeople'; /** * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe @@ -166,10 +166,10 @@ class Contact extends CommonObject public $birthday; public $default_lang; - public $ref_facturation; // Reference number of invoice for which it is contact - public $ref_contrat; // Nb de reference contrat pour lequel il est contact - public $ref_commande; // Nb de reference commande pour lequel il est contact - public $ref_propal; // Nb de reference propal pour lequel il est contact + public $ref_facturation; // Reference number of invoice for which it is contact + public $ref_contrat; // Nb de reference contrat pour lequel il est contact + public $ref_commande; // Nb de reference commande pour lequel il est contact + public $ref_propal; // Nb de reference propal pour lequel il est contact public $user_id; public $user_login; @@ -194,7 +194,7 @@ class Contact extends CommonObject public function __construct($db) { $this->db = $db; - $this->statut = 1; // By default, status is enabled + $this->statut = 1; // By default, status is enabled } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -237,7 +237,7 @@ class Contact extends CommonObject else { dol_print_error($this->db); - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -252,84 +252,84 @@ class Contact extends CommonObject { global $conf, $langs; - $error=0; - $now=dol_now(); + $error = 0; + $now = dol_now(); $this->db->begin(); // Clean parameters - $this->lastname=$this->lastname?trim($this->lastname):trim($this->name); - $this->firstname=trim($this->firstname); - if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname); - if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname); + $this->lastname = $this->lastname ?trim($this->lastname) : trim($this->name); + $this->firstname = trim($this->firstname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); if (empty($this->socid)) $this->socid = 0; if (empty($this->priv)) $this->priv = 0; if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request - $this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity); + $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople ("; - $sql.= " datec"; - $sql.= ", fk_soc"; - $sql.= ", lastname"; - $sql.= ", firstname"; - $sql.= ", fk_user_creat"; - $sql.= ", priv"; - $sql.= ", statut"; - $sql.= ", canvas"; - $sql.= ", entity"; - $sql.= ", ref_ext"; - $sql.= ", import_key"; - $sql.= ") VALUES ("; - $sql.= "'".$this->db->idate($now)."',"; - if ($this->socid > 0) $sql.= " ".$this->db->escape($this->socid).","; - else $sql.= "null,"; - $sql.= "'".$this->db->escape($this->lastname)."',"; - $sql.= "'".$this->db->escape($this->firstname)."',"; - $sql.= " ".($user->id > 0 ? "'".$this->db->escape($user->id)."'":"null").","; - $sql.= " ".$this->db->escape($this->priv).","; - $sql.= " ".$this->db->escape($this->statut).","; - $sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").","; - $sql.= " ".$this->db->escape($this->entity).","; - $sql.= "'".$this->db->escape($this->ref_ext)."',"; - $sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); - $sql.= ")"; + $sql .= " datec"; + $sql .= ", fk_soc"; + $sql .= ", lastname"; + $sql .= ", firstname"; + $sql .= ", fk_user_creat"; + $sql .= ", priv"; + $sql .= ", statut"; + $sql .= ", canvas"; + $sql .= ", entity"; + $sql .= ", ref_ext"; + $sql .= ", import_key"; + $sql .= ") VALUES ("; + $sql .= "'".$this->db->idate($now)."',"; + if ($this->socid > 0) $sql .= " ".$this->db->escape($this->socid).","; + else $sql .= "null,"; + $sql .= "'".$this->db->escape($this->lastname)."',"; + $sql .= "'".$this->db->escape($this->firstname)."',"; + $sql .= " ".($user->id > 0 ? "'".$this->db->escape($user->id)."'" : "null").","; + $sql .= " ".$this->db->escape($this->priv).","; + $sql .= " ".$this->db->escape($this->statut).","; + $sql .= " ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null").","; + $sql .= " ".$this->db->escape($this->entity).","; + $sql .= "'".$this->db->escape($this->ref_ext)."',"; + $sql .= " ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); + $sql .= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople"); - if (! $error) + if (!$error) { - $result=$this->update($this->id, $user, 1, 'add'); + $result = $this->update($this->id, $user, 1, 'add'); if ($result < 0) { $error++; - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); } } - if (! $error) + if (!$error) { - $result=$this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update + $result = $this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update if ($result < 0) { $error++; - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); } } - if (! $error) + if (!$error) { // Call trigger - $result=$this->call_trigger('CONTACT_CREATE', $user); + $result = $this->call_trigger('CONTACT_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return $this->id; @@ -343,7 +343,7 @@ class Contact extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); @@ -365,26 +365,26 @@ class Contact extends CommonObject { global $conf, $langs, $hookmanager; - $error=0; + $error = 0; $this->id = $id; - $this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity); + $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); // Clean parameters - $this->lastname=trim($this->lastname)?trim($this->lastname):trim($this->lastname); - $this->firstname=trim($this->firstname); - $this->email=trim($this->email); - $this->phone_pro=trim($this->phone_pro); - $this->phone_perso=trim($this->phone_perso); - $this->phone_mobile=trim($this->phone_mobile); - $this->jabberid=trim($this->jabberid); - $this->skype=trim($this->skype); - $this->photo=trim($this->photo); - $this->fax=trim($this->fax); - $this->zip=(empty($this->zip)?'':$this->zip); - $this->town=(empty($this->town)?'':$this->town); - $this->country_id=($this->country_id > 0?$this->country_id:$this->country_id); + $this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname); + $this->firstname = trim($this->firstname); + $this->email = trim($this->email); + $this->phone_pro = trim($this->phone_pro); + $this->phone_perso = trim($this->phone_perso); + $this->phone_mobile = trim($this->phone_mobile); + $this->jabberid = trim($this->jabberid); + $this->skype = trim($this->skype); + $this->photo = trim($this->photo); + $this->fax = trim($this->fax); + $this->zip = (empty($this->zip) ? '' : $this->zip); + $this->town = (empty($this->town) ? '' : $this->town); + $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); if (empty($this->statut)) $this->statut = 0; if (empty($this->civility_code) && ! is_numeric($this->civility_id)) $this->civility_code = $this->civility_id; // For backward compatibility $this->db->begin(); @@ -398,8 +398,8 @@ class Contact extends CommonObject $sql .= ", address='".$this->db->escape($this->address)."'"; $sql .= ", zip='".$this->db->escape($this->zip)."'"; $sql .= ", town='".$this->db->escape($this->town)."'"; - $sql .= ", fk_pays=".($this->country_id>0?$this->country_id:'NULL'); - $sql .= ", fk_departement=".($this->state_id>0?$this->state_id:'NULL'); + $sql .= ", fk_pays=".($this->country_id > 0 ? $this->country_id : 'NULL'); + $sql .= ", fk_departement=".($this->state_id > 0 ? $this->state_id : 'NULL'); $sql .= ", poste='".$this->db->escape($this->poste)."'"; $sql .= ", fax='".$this->db->escape($this->fax)."'"; $sql .= ", email='".$this->db->escape($this->email)."'"; @@ -427,27 +427,27 @@ class Contact extends CommonObject unset($this->state_code); unset($this->state); - $action='update'; + $action = 'update'; // Actions on extra fields - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } - if (! $error) { - $result=$this->updateRoles(); + if (!$error) { + $result = $this->updateRoles(); if ($result < 0) { $error++; } } - if (! $error && $this->user_id > 0) + if (!$error && $this->user_id > 0) { // If contact is linked to a user $tmpobj = new User($this->db); @@ -480,7 +480,7 @@ class Contact extends CommonObject } if ($tmpobj->zip != $this->zip) { - $tmpobj->state_id=$this->state_id; + $tmpobj->state_id = $this->state_id; $usermustbemodified++; } if ($tmpobj->country_id != $this->country_id) @@ -547,7 +547,7 @@ class Contact extends CommonObject } else { - $this->error=$this->db->lasterror().' sql='.$sql; + $this->error = $this->db->lasterror().' sql='.$sql; $this->db->rollback(); return -1; } @@ -569,10 +569,10 @@ class Contact extends CommonObject { // phpcs:enable global $conf; - $dn=''; - if ($mode==0) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN; - elseif ($mode==1) $dn=$conf->global->LDAP_CONTACT_DN; - elseif ($mode==2) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS]; + $dn = ''; + if ($mode == 0) $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN; + elseif ($mode == 1) $dn = $conf->global->LDAP_CONTACT_DN; + elseif ($mode == 2) $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS]; return $dn; } @@ -592,14 +592,14 @@ class Contact extends CommonObject $info = array(); // Object classes - $info["objectclass"]=explode(',', $conf->global->LDAP_CONTACT_OBJECT_CLASS); + $info["objectclass"] = explode(',', $conf->global->LDAP_CONTACT_OBJECT_CLASS); - $this->fullname=$this->getFullName($langs); + $this->fullname = $this->getFullName($langs); // Fields - if ($this->fullname && ! empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname; - if ($this->lastname && ! empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname; - if ($this->firstname && ! empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname; + if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname; + if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname; + if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname; if ($this->poste) $info["title"] = $this->poste; if ($this->socid > 0) @@ -612,17 +612,17 @@ class Contact extends CommonObject if ($soc->client == 2) $info["businessCategory"] = "Prospects"; if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers"; } - if ($this->address && ! empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address; - if ($this->zip && ! empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip; - if ($this->town && ! empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town; - if ($this->country_code && ! empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code; - if ($this->phone_pro && ! empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro; - if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso; - if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile; - if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax; - if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype; - if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2); - if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email; + if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address; + if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip; + if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town; + if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code; + if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro; + if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso; + if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile; + if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax; + if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype; + if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2); + if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email; if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') { @@ -630,7 +630,7 @@ class Contact extends CommonObject $info['uidnumber'] = $this->id; - $info['phpgwTz'] = 0; + $info['phpgwTz'] = 0; $info['phpgwMailType'] = 'INTERNET'; $info['phpgwMailHomeType'] = 'INTERNET'; @@ -665,24 +665,24 @@ class Contact extends CommonObject public function update_perso($id, $user = null, $notrigger = 0) { // phpcs:enable - $error=0; - $result=false; + $error = 0; + $result = false; $this->db->begin(); // Mis a jour contact $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET"; - $sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null"); - $sql.= ", photo = ".($this->photo? "'".$this->db->escape($this->photo)."'" : "null"); + $sql .= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null"); + $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null"); if ($user) $sql .= ", fk_user_modif=".$user->id; - $sql.= " WHERE rowid=".$this->db->escape($id); + $sql .= " WHERE rowid=".$this->db->escape($id); dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG); $resql = $this->db->query($sql); - if (! $resql) + if (!$resql) { $error++; - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); } // Mis a jour alerte birthday @@ -691,16 +691,16 @@ class Contact extends CommonObject //check existing $sql_check = "SELECT rowid FROM ".MAIN_DB_PREFIX."user_alert WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id; $result_check = $this->db->query($sql_check); - if (! $result_check || ($this->db->num_rows($result_check)<1)) + if (!$result_check || ($this->db->num_rows($result_check) < 1)) { //insert $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) "; - $sql.= "VALUES (1,".$this->db->escape($id).",".$user->id.")"; + $sql .= "VALUES (1,".$this->db->escape($id).",".$user->id.")"; $result = $this->db->query($sql); - if (! $result) + if (!$result) { $error++; - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); } } else @@ -711,24 +711,24 @@ class Contact extends CommonObject else { $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_alert "; - $sql.= "WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id; + $sql .= "WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id; $result = $this->db->query($sql); - if (! $result) + if (!$result) { $error++; - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('CONTACT_MODIFY', $user); + $result = $this->call_trigger('CONTACT_MODIFY', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; @@ -864,9 +864,9 @@ class Contact extends CommonObject // Search Dolibarr user linked to this contact $sql = "SELECT u.rowid "; $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE u.fk_socpeople = ". $this->id; + $sql .= " WHERE u.fk_socpeople = ".$this->id; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) @@ -879,7 +879,7 @@ class Contact extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } @@ -890,7 +890,7 @@ class Contact extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."user_alert"; $sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$this->db->escape($id); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) @@ -903,7 +903,7 @@ class Contact extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -912,8 +912,8 @@ class Contact extends CommonObject // fetch optionals attributes and labels $this->fetch_optionals(); - $resultRole=$this->fetchRoles(); - if ($resultRole<0) { + $resultRole = $this->fetchRoles(); + if ($resultRole < 0) { return $resultRole; } @@ -921,13 +921,13 @@ class Contact extends CommonObject } else { - $this->error=$langs->trans("RecordNotFound"); + $this->error = $langs->trans("RecordNotFound"); return 0; } } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -943,7 +943,7 @@ class Contact extends CommonObject unset($this->gender); if (in_array($this->civility_id, array('MR'))) { $this->gender = 'man'; - } elseif(in_array($this->civility_id, array('MME','MLE'))) { + } elseif (in_array($this->civility_id, array('MME', 'MLE'))) { $this->gender = 'woman'; } } @@ -962,26 +962,26 @@ class Contact extends CommonObject { // phpcs:enable // Compte les elements pour lesquels il est contact - $sql ="SELECT tc.element, count(ec.rowid) as nb"; - $sql.=" FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.=" WHERE ec.fk_c_type_contact = tc.rowid"; - $sql.=" AND fk_socpeople = ". $this->id; - $sql.=" AND tc.source = 'external'"; - $sql.=" GROUP BY tc.element"; + $sql = "SELECT tc.element, count(ec.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " WHERE ec.fk_c_type_contact = tc.rowid"; + $sql .= " AND fk_socpeople = ".$this->id; + $sql .= " AND tc.source = 'external'"; + $sql .= " GROUP BY tc.element"; dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - while($obj=$this->db->fetch_object($resql)) + while ($obj = $this->db->fetch_object($resql)) { if ($obj->nb) { - if ($obj->element=='facture') $this->ref_facturation = $obj->nb; - elseif ($obj->element=='contrat') $this->ref_contrat = $obj->nb; - elseif ($obj->element=='commande') $this->ref_commande = $obj->nb; - elseif ($obj->element=='propal') $this->ref_propal = $obj->nb; + if ($obj->element == 'facture') $this->ref_facturation = $obj->nb; + elseif ($obj->element == 'contrat') $this->ref_contrat = $obj->nb; + elseif ($obj->element == 'commande') $this->ref_commande = $obj->nb; + elseif ($obj->element == 'propal') $this->ref_propal = $obj->nb; } } $this->db->free($resql); @@ -989,7 +989,7 @@ class Contact extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -1004,41 +1004,41 @@ class Contact extends CommonObject { global $conf, $langs, $user; - $error=0; + $error = 0; //$this->old_lastname = $obj->lastname; //$this->old_firstname = $obj->firstname; $this->db->begin(); - if (! $error) + if (!$error) { // Get all rowid of element_contact linked to a type that is link to llx_socpeople $sql = "SELECT ec.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,"; - $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql.= " WHERE ec.fk_socpeople=".$this->id; - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.source='external'"; + $sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec,"; + $sql .= " ".MAIN_DB_PREFIX."c_type_contact tc"; + $sql .= " WHERE ec.fk_socpeople=".$this->id; + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; + $sql .= " AND tc.source='external'"; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $num=$this->db->num_rows($resql); + $num = $this->db->num_rows($resql); - $i=0; - while ($i < $num && ! $error) + $i = 0; + while ($i < $num && !$error) { $obj = $this->db->fetch_object($resql); $sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sqldel.=" WHERE rowid = ".$obj->rowid; + $sqldel .= " WHERE rowid = ".$obj->rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $result = $this->db->query($sqldel); - if (! $result) + if (!$result) { $error++; - $this->error=$this->db->error().' sql='.$sqldel; + $this->error = $this->db->error().' sql='.$sqldel; } $i++; @@ -1047,67 +1047,67 @@ class Contact extends CommonObject else { $error++; - $this->error=$this->db->error().' sql='.$sql; + $this->error = $this->db->error().' sql='.$sql; } } - if (! $error) + if (!$error) { // Remove Roles $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->error .= $this->db->lasterror(); - $errorflag=-1; + $errorflag = -1; } } - if (! $error) + if (!$error) { // Remove category $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->error .= $this->db->lasterror(); - $errorflag=-1; + $errorflag = -1; } } - if (! $error) + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople"; $sql .= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $result = $this->db->query($sql); - if (! $result) + if (!$result) { $error++; - $this->error=$this->db->error().' sql='.$sql; + $this->error = $this->db->error().' sql='.$sql; } } // Removed extrafields - if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { + if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { // For avoid conflicts if trigger used - $result=$this->deleteExtraFields(); + $result = $this->deleteExtraFields(); if ($result < 0) $error++; } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('CONTACT_DELETE', $user); + $result = $this->call_trigger('CONTACT_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return 1; @@ -1130,11 +1130,11 @@ class Contact extends CommonObject public function info($id) { $sql = "SELECT c.rowid, c.datec as datec, c.fk_user_creat,"; - $sql.= " c.tms as tms, c.fk_user_modif"; - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c"; - $sql.= " WHERE c.rowid = ".$this->db->escape($id); + $sql .= " c.tms as tms, c.fk_user_modif"; + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; + $sql .= " WHERE c.rowid = ".$this->db->escape($id); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) @@ -1146,7 +1146,7 @@ class Contact extends CommonObject if ($obj->fk_user_creat) { $cuser = new User($this->db); $cuser->fetch($obj->fk_user_creat); - $this->user_creation = $cuser; + $this->user_creation = $cuser; } if ($obj->fk_user_modif) { @@ -1175,22 +1175,22 @@ class Contact extends CommonObject public function getNbOfEMailings() { $sql = "SELECT count(mc.email) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m"; - $sql.= " WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email)."' "; - $sql.= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success + $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m"; + $sql .= " WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email)."' "; + $sql .= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - $nb=$obj->nb; + $nb = $obj->nb; $this->db->free($resql); return $nb; } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -1211,41 +1211,41 @@ class Contact extends CommonObject { global $conf, $langs, $hookmanager; - $result=''; + $result = ''; - $label = '' . $langs->trans("ShowContact") . ''; - $label.= '
' . $langs->trans("Name") . ': '.$this->getFullName($langs); + $label = ''.$langs->trans("ShowContact").''; + $label .= '
'.$langs->trans("Name").': '.$this->getFullName($langs); //if ($this->civility_id) $label.= '
' . $langs->trans("Civility") . ': '.$this->civility_id; // TODO Translate cibilty_id code - if (! empty($this->poste)) $label.= '
' . $langs->trans("Poste") . ': '.$this->poste; - $label.= '
' . $langs->trans("EMail") . ': '.$this->email; + if (!empty($this->poste)) $label .= '
'.$langs->trans("Poste").': '.$this->poste; + $label .= '
'.$langs->trans("EMail").': '.$this->email; $phonelist = array(); if ($this->phone_pro) $phonelist[] = dol_print_phone($this->phone_pro, $this->country_code, $this->id, 0, '', ' ', 'phone'); if ($this->phone_mobile) $phonelist[] = dol_print_phone($this->phone_mobile, $this->country_code, $this->id, 0, '', ' ', 'mobile'); if ($this->phone_perso) $phonelist[] = dol_print_phone($this->phone_perso, $this->country_code, $this->id, 0, '', ' ', 'phone'); - $label.= '
' . $langs->trans("Phone") . ': '.implode(' ', $phonelist); - $label.= '
' . $langs->trans("Address") . ': '.dol_format_address($this, 1, ' ', $langs); + $label .= '
'.$langs->trans("Phone").': '.implode(' ', $phonelist); + $label .= '
'.$langs->trans("Address").': '.dol_format_address($this, 1, ' ', $langs); $url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id; if ($option !== 'nolink') { // 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'; + $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'; } $url .= $moreparam; - $linkclose=""; + $linkclose = ""; if (empty($notooltip)) { - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label=$langs->trans("ShowContact"); - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + $label = $langs->trans("ShowContact"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose.= ' class="classfortooltip"'; + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; /* $hookmanager->initHooks(array('contactdao')); @@ -1256,24 +1256,24 @@ class Contact extends CommonObject } $linkstart = ''; - $linkend=''; + $linkstart .= $linkclose.'>'; + $linkend = ''; if ($option == 'xxx') { $linkstart = ''; - $linkend=''; + $linkend = ''; } - $result.=$linkstart; - if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1); - if ($withpicto != 2) $result.=($maxlen?dol_trunc($this->getFullName($langs), $maxlen):$this->getFullName($langs)); - $result.=$linkend; + $result .= $linkstart; + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)); + $result .= $linkend; global $action; $hookmanager->initHooks(array('contactdao')); - $parameters=array('id'=>$this->id, 'getnomurl'=>$result); - $reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); + $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) $result = $hookmanager->resPrint; else $result .= $hookmanager->resPrint; @@ -1289,7 +1289,7 @@ class Contact extends CommonObject { global $langs; - $code=($this->civility_code ? $this->civility_code : (! empty($this->civility_id)?$this->civility:(! empty($this->civilite)?$this->civilite:''))); + $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : ''))); if (empty($code)) return ''; $langs->load("dict"); @@ -1334,7 +1334,7 @@ class Contact extends CommonObject ); $statusType = 'status4'; - if ($status==0 || $status==5) $statusType = 'status5'; + if ($status == 0 || $status == 5) $statusType = 'status5'; $label = $langs->trans($labelStatus[$status]); $labelshort = $langs->trans($labelStatusShort[$status]); @@ -1354,7 +1354,7 @@ class Contact extends CommonObject { // phpcs:enable global $langs; - if ($status=='1') return $langs->trans('ContactPrivate'); + if ($status == '1') return $langs->trans('ContactPrivate'); else return $langs->trans('ContactPublic'); } @@ -1374,12 +1374,12 @@ class Contact extends CommonObject $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) $socid=$obj->rowid; + if ($obj) $socid = $obj->rowid; } // Initialise parameters - $this->id=0; - $this->specimen=1; + $this->id = 0; + $this->specimen = 1; $this->lastname = 'DOLIBARR'; $this->firstname = 'SPECIMEN'; $this->address = '21 jump street'; @@ -1398,11 +1398,11 @@ class Contact extends CommonObject $this->phone_mobile = '0909090903'; $this->fax = '0909090909'; - $this->note_public='This is a comment (public)'; - $this->note_private='This is a comment (private)'; + $this->note_public = 'This is a comment (public)'; + $this->note_private = 'This is a comment (private)'; $this->socid = $socid; - $this->statut=1; + $this->statut = 1; return 1; } @@ -1414,9 +1414,9 @@ class Contact extends CommonObject */ public function setstatus($status) { - global $conf,$langs,$user; + global $conf, $langs, $user; - $error=0; + $error = 0; // Check parameters if ($this->statut == $status) return 0; @@ -1426,15 +1426,15 @@ class Contact extends CommonObject // Desactive utilisateur $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople"; - $sql.= " SET statut = ".$this->statut; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET statut = ".$this->statut; + $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); dol_syslog(get_class($this)."::setstatus", LOG_DEBUG); if ($result) { // Call trigger - $result=$this->call_trigger('CONTACT_ENABLEDISABLE', $user); + $result = $this->call_trigger('CONTACT_ENABLEDISABLE', $user); if ($result < 0) { $error++; } // End call triggers } @@ -1469,7 +1469,7 @@ class Contact extends CommonObject } // Get current categories - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $c = new Categorie($this->db); $existing = $c->containing($this->id, Categorie::TYPE_CONTACT, 'id'); @@ -1523,34 +1523,34 @@ class Contact extends CommonObject public function fetchRoles() { global $langs; - $error= 0; - $num=0; + $error = 0; + $num = 0; - $sql ="SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle, sc.rowid as contactroleid"; - $sql.=" FROM ".MAIN_DB_PREFIX."societe_contacts as sc "; - $sql.=" INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.=" ON tc.rowid = sc.fk_c_type_contact"; - $sql.=" AND sc.fk_socpeople = ". $this->id; - $sql.=" AND tc.source = 'external' AND tc.active=1"; - $sql.=" AND sc.entity IN (".getEntity('societe').')'; + $sql = "SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle, sc.rowid as contactroleid"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe_contacts as sc "; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " ON tc.rowid = sc.fk_c_type_contact"; + $sql .= " AND sc.fk_socpeople = ".$this->id; + $sql .= " AND tc.source = 'external' AND tc.active=1"; + $sql .= " AND sc.entity IN (".getEntity('societe').')'; dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); - $this->roles=array(); - $resql=$this->db->query($sql); + $this->roles = array(); + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); if ($num > 0) { while ($obj = $this->db->fetch_object($resql)) { - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; + $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; $libelle_element = $langs->trans('ContactDefault_'.$obj->element); - $this->roles[$obj->contactroleid]=array('id'=>$obj->rowid,'element'=>$obj->element,'source'=>$obj->source,'code'=>$obj->code,'label'=>$libelle_element. ' - '.($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle)); + $this->roles[$obj->contactroleid] = array('id'=>$obj->rowid, 'element'=>$obj->element, 'source'=>$obj->source, 'code'=>$obj->code, 'label'=>$libelle_element.' - '.($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle)); } } } else { $error++; - $this->error=$this->db->lasterror(); - $this->errors[]=$this->db->lasterror(); + $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); } if (empty($error)) { @@ -1569,26 +1569,26 @@ class Contact extends CommonObject */ public function getContactRoles($element = '') { - $tab=array(); + $tab = array(); $sql = "SELECT sc.fk_socpeople as id, sc.fk_c_type_contact"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql.= ", ".MAIN_DB_PREFIX."societe_contacts sc"; - $sql.= " WHERE sc.fk_soc =".$this->socid; - $sql.= " AND sc.fk_c_type_contact=tc.rowid"; - $sql.= " AND tc.element='".$element."'"; - $sql.= " AND tc.active=1"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; + $sql .= ", ".MAIN_DB_PREFIX."societe_contacts sc"; + $sql .= " WHERE sc.fk_soc =".$this->socid; + $sql .= " AND sc.fk_c_type_contact=tc.rowid"; + $sql .= " AND tc.element='".$element."'"; + $sql .= " AND tc.active=1"; dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $num=$this->db->num_rows($resql); - $i=0; + $num = $this->db->num_rows($resql); + $i = 0; while ($i < $num) { $obj = $this->db->fetch_object($resql); - $tab[]=array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact); + $tab[] = array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact); $i++; } @@ -1597,7 +1597,7 @@ class Contact extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); dol_print_error($this->db); return -1; } @@ -1613,7 +1613,7 @@ class Contact extends CommonObject { global $conf; - $error=0; + $error = 0; $this->db->begin(); @@ -1622,29 +1622,29 @@ class Contact extends CommonObject dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if (!$result) { - $this->errors[]=$this->db->lasterror().' sql='.$sql; + $this->errors[] = $this->db->lasterror().' sql='.$sql; $error++; } else { - if (count($this->roles)>0) { + if (count($this->roles) > 0) { foreach ($this->roles as $keyRoles => $valRoles) { - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_contacts"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_contacts"; $sql .= " (entity,"; $sql .= "date_creation,"; $sql .= "fk_soc,"; $sql .= "fk_c_type_contact,"; $sql .= "fk_socpeople) "; - $sql .= " VALUES (" . $conf->entity . ","; - $sql .= "'" . $this->db->idate(dol_now()) . "',"; - $sql .= $this->socid . ", "; - $sql .= $valRoles . " , " ; + $sql .= " VALUES (".$conf->entity.","; + $sql .= "'".$this->db->idate(dol_now())."',"; + $sql .= $this->socid.", "; + $sql .= $valRoles." , "; $sql .= $this->id; $sql .= ")"; - dol_syslog(get_class($this) . "::".__METHOD__, LOG_DEBUG); + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if (!$result) { - $this->errors[]=$this->db->lasterror().' sql='.$sql; + $this->errors[] = $this->db->lasterror().' sql='.$sql; $error++; } } @@ -1654,9 +1654,9 @@ class Contact extends CommonObject $this->db->commit(); return 1; } else { - $this->error=implode(' ', $this->errors); + $this->error = implode(' ', $this->errors); $this->db->rollback(); - return $error*-1; + return $error * -1; } } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 48fe598c198..b85ed6c5a3b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -59,7 +59,7 @@ class Form /** * @var string Error code (or message) */ - public $error=''; + public $error = ''; /** * @var string[] Array of error strings @@ -69,12 +69,12 @@ class Form public $num; // Cache arrays - public $cache_types_paiements=array(); - public $cache_conditions_paiements=array(); - public $cache_availability=array(); - public $cache_demand_reason=array(); - public $cache_types_fees=array(); - public $cache_vatrates=array(); + public $cache_types_paiements = array(); + public $cache_conditions_paiements = array(); + public $cache_availability = array(); + public $cache_demand_reason = array(); + public $cache_types_fees = array(); + public $cache_vatrates = array(); /** @@ -104,43 +104,43 @@ class Form */ public function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata = 'string', $moreparam = '', $fieldrequired = 0, $notabletag = 0, $paramid = 'id') { - global $conf,$langs; + global $conf, $langs; - $ret=''; + $ret = ''; // TODO change for compatibility - if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! preg_match('/^select;/', $typeofdata)) + if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;/', $typeofdata)) { - if (! empty($perm)) + if (!empty($perm)) { - $tmp=explode(':', $typeofdata); - $ret.= '
'; - if ($fieldrequired) $ret.=''; - $ret.= $langs->trans($text); - if ($fieldrequired) $ret.=''; - $ret.= '
'."\n"; + $tmp = explode(':', $typeofdata); + $ret .= '
'; + if ($fieldrequired) $ret .= ''; + $ret .= $langs->trans($text); + if ($fieldrequired) $ret .= ''; + $ret .= '
'."\n"; } else { - if ($fieldrequired) $ret.=''; - $ret.= $langs->trans($text); - if ($fieldrequired) $ret.=''; + if ($fieldrequired) $ret .= ''; + $ret .= $langs->trans($text); + if ($fieldrequired) $ret .= ''; } } else { - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret.=''; - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret.=''; - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret.='
'; - if ($fieldrequired) $ret.=''; - $ret.=$langs->trans($text); - if ($fieldrequired) $ret.=''; - if (! empty($notabletag)) $ret.=' '; - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret.=''; - if ($htmlname && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret.='id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).''; - if (! empty($notabletag) && $notabletag == 1) $ret.=' : '; - if (! empty($notabletag) && $notabletag == 3) $ret.=' '; - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret.='
'; + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= ''; + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= ''; + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '
'; + if ($fieldrequired) $ret .= ''; + $ret .= $langs->trans($text); + if ($fieldrequired) $ret .= ''; + if (!empty($notabletag)) $ret .= ' '; + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= ''; + if ($htmlname && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= 'id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).''; + if (!empty($notabletag) && $notabletag == 1) $ret .= ' : '; + if (!empty($notabletag) && $notabletag == 3) $ret .= ' '; + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '
'; } return $ret; @@ -166,128 +166,128 @@ class Form */ public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 'string', $editvalue = '', $extObject = null, $custommsg = null, $moreparam = '', $notabletag = 0, $formatfunc = '', $paramid = 'id') { - global $conf,$langs,$db; + global $conf, $langs, $db; - $ret=''; + $ret = ''; // Check parameters if (empty($typeofdata)) return 'ErrorBadParameter'; // When option to edit inline is activated - if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! preg_match('/^select;|datehourpicker/', $typeofdata)) // TODO add jquery timepicker and support select + if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;|datehourpicker/', $typeofdata)) // TODO add jquery timepicker and support select { - $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg); + $ret .= $this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg); } else { if (GETPOST('action', 'aZ09') == 'edit'.$htmlname) { - $ret.="\n"; - $ret.='
'; - $ret.=''; - $ret.=''; - $ret.=''; - if (empty($notabletag)) $ret.=''; - if (empty($notabletag)) $ret.='
'; + $ret .= "\n"; + $ret .= ''; + $ret .= ''; + $ret .= ''; + $ret .= ''; + if (empty($notabletag)) $ret .= ''; + if (empty($notabletag)) $ret .= ''; + if (empty($notabletag)) $ret .= ''; - if (empty($notabletag)) $ret.=''; + $ret .= ''; + if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag)) $ret .= '
'."\n"; + $ret .= ''; + if (empty($notabletag)) $ret .= ''; - if (empty($notabletag)) $ret.='
'; if (preg_match('/^(string|email)/', $typeofdata)) { - $tmp=explode(':', $typeofdata); - $ret.=''; + $tmp = explode(':', $typeofdata); + $ret .= ''; } elseif (preg_match('/^(numeric|amount)/', $typeofdata)) { - $tmp=explode(':', $typeofdata); - $valuetoshow=price2num($editvalue?$editvalue:$value); - $ret.=''; + $tmp = explode(':', $typeofdata); + $valuetoshow = price2num($editvalue ? $editvalue : $value); + $ret .= ''; } elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) { - $tmp=explode(':', $typeofdata); - $cols=$tmp[2]; - $morealt=''; + $tmp = explode(':', $typeofdata); + $cols = $tmp[2]; + $morealt = ''; if (preg_match('/%/', $cols)) { - $morealt=' style="width: '.$cols.'"'; - $cols=''; + $morealt = ' style="width: '.$cols.'"'; + $cols = ''; } - $valuetoshow = ($editvalue?$editvalue:$value); + $valuetoshow = ($editvalue ? $editvalue : $value); - $ret.=''; + $ret .= ''; } elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') { - $ret.=$this->selectDate($value, $htmlname, 0, 0, 1, 'form'.$htmlname, 1, 0); + $ret .= $this->selectDate($value, $htmlname, 0, 0, 1, 'form'.$htmlname, 1, 0); } elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') { - $ret.=$this->selectDate($value, $htmlname, 1, 1, 1, 'form'.$htmlname, 1, 0); + $ret .= $this->selectDate($value, $htmlname, 1, 1, 1, 'form'.$htmlname, 1, 0); } elseif (preg_match('/^select;/', $typeofdata)) { - $arraydata=explode(',', preg_replace('/^select;/', '', $typeofdata)); - foreach($arraydata as $val) + $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata)); + foreach ($arraydata as $val) { - $tmp=explode(':', $val); - $tmpkey=str_replace('|', ':', $tmp[0]); - $arraylist[$tmpkey]=$tmp[1]; + $tmp = explode(':', $val); + $tmpkey = str_replace('|', ':', $tmp[0]); + $arraylist[$tmpkey] = $tmp[1]; } - $ret.=$this->selectarray($htmlname, $arraylist, $value); + $ret .= $this->selectarray($htmlname, $arraylist, $value); } elseif (preg_match('/^ckeditor/', $typeofdata)) { - $tmp=explode(':', $typeofdata); // Example: ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols:uselocalbrowser + $tmp = explode(':', $typeofdata); // Example: ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols:uselocalbrowser require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor($htmlname, ($editvalue?$editvalue:$value), ($tmp[2]?$tmp[2]:''), ($tmp[3]?$tmp[3]:'100'), ($tmp[1]?$tmp[1]:'dolibarr_notes'), 'In', ($tmp[5]?$tmp[5]:0), (isset($tmp[8])?($tmp[8]?true:false):true), true, ($tmp[6]?$tmp[6]:'20'), ($tmp[7]?$tmp[7]:'100')); - $ret.=$doleditor->Create(1); + $doleditor = new DolEditor($htmlname, ($editvalue ? $editvalue : $value), ($tmp[2] ? $tmp[2] : ''), ($tmp[3] ? $tmp[3] : '100'), ($tmp[1] ? $tmp[1] : 'dolibarr_notes'), 'In', ($tmp[5] ? $tmp[5] : 0), (isset($tmp[8]) ? ($tmp[8] ?true:false) : true), true, ($tmp[6] ? $tmp[6] : '20'), ($tmp[7] ? $tmp[7] : '100')); + $ret .= $doleditor->Create(1); } - if (empty($notabletag)) $ret.=''; + if (empty($notabletag)) $ret .= ''; //else $ret.='
'; - $ret.=''; - if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag)) $ret.='
'."\n"; - $ret.=''; - if (empty($notabletag)) $ret.='
'."\n"; - $ret.=''."\n"; + if (empty($notabletag)) $ret .= '
'."\n"; + $ret .= ''."\n"; } else { - if (preg_match('/^(email)/', $typeofdata)) $ret.=dol_print_email($value, 0, 0, 0, 0, 1); - elseif (preg_match('/^(amount|numeric)/', $typeofdata)) $ret.=($value != '' ? price($value, '', $langs, 0, -1, -1, $conf->currency) : ''); - elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) $ret.=dol_htmlentitiesbr($value); - elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret.=dol_print_date($value, 'day'); - elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') $ret.=dol_print_date($value, 'dayhour'); + if (preg_match('/^(email)/', $typeofdata)) $ret .= dol_print_email($value, 0, 0, 0, 0, 1); + elseif (preg_match('/^(amount|numeric)/', $typeofdata)) $ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, $conf->currency) : ''); + elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) $ret .= dol_htmlentitiesbr($value); + elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret .= dol_print_date($value, 'day'); + elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') $ret .= dol_print_date($value, 'dayhour'); elseif (preg_match('/^select;/', $typeofdata)) { - $arraydata=explode(',', preg_replace('/^select;/', '', $typeofdata)); - foreach($arraydata as $val) + $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata)); + foreach ($arraydata as $val) { - $tmp=explode(':', $val); - $arraylist[$tmp[0]]=$tmp[1]; + $tmp = explode(':', $val); + $arraylist[$tmp[0]] = $tmp[1]; } - $ret.=$arraylist[$value]; + $ret .= $arraylist[$value]; } elseif (preg_match('/^ckeditor/', $typeofdata)) { - $tmpcontent=dol_htmlentitiesbr($value); - if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + $tmpcontent = dol_htmlentitiesbr($value); + if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { - $firstline=preg_replace('/
.*/', '', $tmpcontent); - $firstline=preg_replace('/[\n\r].*/', '', $firstline); - $tmpcontent=$firstline.((strlen($firstline) != strlen($tmpcontent))?'...':''); + $firstline = preg_replace('/
.*/', '', $tmpcontent); + $firstline = preg_replace('/[\n\r].*/', '', $firstline); + $tmpcontent = $firstline.((strlen($firstline) != strlen($tmpcontent)) ? '...' : ''); } - $ret.=$tmpcontent; + $ret .= $tmpcontent; } - else $ret.=$value; + else $ret .= $value; if ($formatfunc && method_exists($object, $formatfunc)) { - $ret=$object->$formatfunc($ret); + $ret = $object->$formatfunc($ret); } } } @@ -311,7 +311,7 @@ class Form { global $conf; - $out=''; + $out = ''; // Check parameters if (preg_match('/^text/', $inputType)) $value = dol_nl2br($value); @@ -320,14 +320,14 @@ class Form if ($condition) { - $element = false; - $table_element = false; + $element = false; + $table_element = false; $fk_element = false; $loadmethod = false; $savemethod = false; $ext_element = false; $button_only = false; - $inputOption = ''; + $inputOption = ''; if (is_object($object)) { @@ -343,46 +343,46 @@ class Form if (preg_match('/^(string|email|numeric)/', $inputType)) { - $tmp=explode(':', $inputType); - $inputType=$tmp[0]; - if (! empty($tmp[1])) $inputOption=$tmp[1]; - if (! empty($tmp[2])) $savemethod=$tmp[2]; - $out.= ''."\n"; + $tmp = explode(':', $inputType); + $inputType = $tmp[0]; + if (!empty($tmp[1])) $inputOption = $tmp[1]; + if (!empty($tmp[2])) $savemethod = $tmp[2]; + $out .= ''."\n"; } elseif ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType))) { - $tmp=explode(':', $inputType); - $inputType=$tmp[0]; - if (! empty($tmp[1])) $inputOption=$tmp[1]; - if (! empty($tmp[2])) $savemethod=$tmp[2]; + $tmp = explode(':', $inputType); + $inputType = $tmp[0]; + if (!empty($tmp[1])) $inputOption = $tmp[1]; + if (!empty($tmp[2])) $savemethod = $tmp[2]; - $out.= ''."\n"; // Use for timestamp format + $out .= ''."\n"; // Use for timestamp format } elseif (preg_match('/^(select|autocomplete)/', $inputType)) { - $tmp=explode(':', $inputType); - $inputType=$tmp[0]; $loadmethod=$tmp[1]; - if (! empty($tmp[2])) $savemethod=$tmp[2]; - if (! empty($tmp[3])) $button_only=true; + $tmp = explode(':', $inputType); + $inputType = $tmp[0]; $loadmethod = $tmp[1]; + if (!empty($tmp[2])) $savemethod = $tmp[2]; + if (!empty($tmp[3])) $button_only = true; } elseif (preg_match('/^textarea/', $inputType)) { - $tmp=explode(':', $inputType); - $inputType=$tmp[0]; - $rows=(empty($tmp[1])?'8':$tmp[1]); - $cols=(empty($tmp[2])?'80':$tmp[2]); + $tmp = explode(':', $inputType); + $inputType = $tmp[0]; + $rows = (empty($tmp[1]) ? '8' : $tmp[1]); + $cols = (empty($tmp[2]) ? '80' : $tmp[2]); } elseif (preg_match('/^ckeditor/', $inputType)) { - $tmp=explode(':', $inputType); - $inputType=$tmp[0]; $toolbar=$tmp[1]; - if (! empty($tmp[2])) $width=$tmp[2]; - if (! empty($tmp[3])) $heigth=$tmp[3]; - if (! empty($tmp[4])) $savemethod=$tmp[4]; + $tmp = explode(':', $inputType); + $inputType = $tmp[0]; $toolbar = $tmp[1]; + if (!empty($tmp[2])) $width = $tmp[2]; + if (!empty($tmp[3])) $heigth = $tmp[3]; + if (!empty($tmp[4])) $savemethod = $tmp[4]; - if (! empty($conf->fckeditor->enabled)) + if (!empty($conf->fckeditor->enabled)) { - $out.= ''."\n"; + $out .= ''."\n"; } else { @@ -390,30 +390,30 @@ class Form } } - $out.= ''."\n"; - $out.= ''."\n"; - $out.= ''."\n"; - $out.= ''."\n"; - if (! empty($savemethod)) $out.= ''."\n"; - if (! empty($ext_element)) $out.= ''."\n"; - if (! empty($custommsg)) + $out .= ''."\n"; + $out .= ''."\n"; + $out .= ''."\n"; + $out .= ''."\n"; + if (!empty($savemethod)) $out .= ''."\n"; + if (!empty($ext_element)) $out .= ''."\n"; + if (!empty($custommsg)) { if (is_array($custommsg)) { if (!empty($custommsg['success'])) - $out.= ''."\n"; + $out .= ''."\n"; if (!empty($custommsg['error'])) - $out.= ''."\n"; + $out .= ''."\n"; } else - $out.= ''."\n"; + $out .= ''."\n"; } if ($inputType == 'textarea') { - $out.= ''."\n"; - $out.= ''."\n"; + $out .= ''."\n"; + $out .= ''."\n"; } - $out.= ''.$value.''."\n"; - $out.= ''.(! empty($editvalue) ? $editvalue : $value).''."\n"; + $out .= ''.$value.''."\n"; + $out .= ''.(!empty($editvalue) ? $editvalue : $value).''."\n"; } else { @@ -447,68 +447,68 @@ class Form global $conf; if ($incbefore) $text = $incbefore.$text; - if (! $htmltext) return $text; + if (!$htmltext) return $text; - $tag='td'; - if ($notabs == 2) $tag='div'; - if ($notabs == 3) $tag='span'; + $tag = 'td'; + if ($notabs == 2) $tag = 'div'; + if ($notabs == 3) $tag = 'span'; // Sanitize tooltip //$htmltext=str_replace("\\","\\\\",$htmltext); - $htmltext=str_replace("\r", "", $htmltext); - $htmltext=str_replace("\n", "", $htmltext); + $htmltext = str_replace("\r", "", $htmltext); + $htmltext = str_replace("\n", "", $htmltext); - $extrastyle=''; - if ($direction < 0) { $extracss=($extracss?$extracss.' ':'').($notabs != 3 ? 'inline-block' : ''); $extrastyle='padding: 0px; padding-left: 3px !important;'; } - if ($direction > 0) { $extracss=($extracss?$extracss.' ':'').($notabs != 3 ? 'inline-block' : ''); $extrastyle='padding: 0px; padding-right: 3px !important;'; } + $extrastyle = ''; + if ($direction < 0) { $extracss = ($extracss ? $extracss.' ' : '').($notabs != 3 ? 'inline-block' : ''); $extrastyle = 'padding: 0px; padding-left: 3px !important;'; } + if ($direction > 0) { $extracss = ($extracss ? $extracss.' ' : '').($notabs != 3 ? 'inline-block' : ''); $extrastyle = 'padding: 0px; padding-right: 3px !important;'; } - $classfortooltip='classfortooltip'; + $classfortooltip = 'classfortooltip'; - $s='';$textfordialog=''; + $s = ''; $textfordialog = ''; if ($tooltiptrigger == '') { - $htmltext=str_replace('"', """, $htmltext); + $htmltext = str_replace('"', """, $htmltext); } else { - $classfortooltip='classfortooltiponclick'; - $textfordialog.=''; + $classfortooltip = 'classfortooltiponclick'; + $textfordialog .= ''; } if ($tooltipon == 2 || $tooltipon == 3) { - $paramfortooltipimg=' class="'.$classfortooltip.($notabs != 3 ? ' inline-block' : '').($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'"'; - if ($tooltiptrigger == '') $paramfortooltipimg.=' title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on img tag to store tooltip - else $paramfortooltipimg.=' dolid="'.$tooltiptrigger.'"'; + $paramfortooltipimg = ' class="'.$classfortooltip.($notabs != 3 ? ' inline-block' : '').($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'"'; + if ($tooltiptrigger == '') $paramfortooltipimg .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on img tag to store tooltip + else $paramfortooltipimg .= ' dolid="'.$tooltiptrigger.'"'; } - else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':'').($extrastyle?' style="'.$extrastyle.'"':''); // Attribut to put on td text tag + else $paramfortooltipimg = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag if ($tooltipon == 1 || $tooltipon == 3) { - $paramfortooltiptd=' class="'.($tooltipon == 3 ? 'cursorpointer ' : '').$classfortooltip.' inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'" '; - if ($tooltiptrigger == '') $paramfortooltiptd.=' title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on td tag to store tooltip - else $paramfortooltiptd.=' dolid="'.$tooltiptrigger.'"'; + $paramfortooltiptd = ' class="'.($tooltipon == 3 ? 'cursorpointer ' : '').$classfortooltip.' inline-block'.($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'" '; + if ($tooltiptrigger == '') $paramfortooltiptd .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on td tag to store tooltip + else $paramfortooltiptd .= ' dolid="'.$tooltiptrigger.'"'; } - else $paramfortooltiptd =($extracss?' class="'.$extracss.'"':'').($extrastyle?' style="'.$extrastyle.'"':''); // Attribut to put on td text tag - if (empty($notabs)) $s.=''; - elseif ($notabs == 2) $s.='
'; + else $paramfortooltiptd = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag + if (empty($notabs)) $s .= '
'; + elseif ($notabs == 2) $s .= '
'; // Define value if value is before if ($direction < 0) { - $s.='<'.$tag.$paramfortooltipimg; + $s .= '<'.$tag.$paramfortooltipimg; if ($tag == 'td') { $s .= ' class=valigntop" width="14"'; } - $s.= '>'.$textfordialog.$img.''; + $s .= '>'.$textfordialog.$img.''; } // Use another method to help avoid having a space in value in order to use this value with jquery // Define label - if ((string) $text != '') $s.='<'.$tag.$paramfortooltiptd.'>'.$text.''; + if ((string) $text != '') $s .= '<'.$tag.$paramfortooltiptd.'>'.$text.''; // Define value if value is after if ($direction > 0) { - $s.='<'.$tag.$paramfortooltipimg; + $s .= '<'.$tag.$paramfortooltipimg; if ($tag == 'td') $s .= ' class="valignmiddle" width="14"'; - $s.= '>'.$textfordialog.$img.''; + $s .= '>'.$textfordialog.$img.''; } - if (empty($notabs)) $s.='
'; - elseif ($notabs == 2) $s.='
'; + if (empty($notabs)) $s .= '
'; + elseif ($notabs == 2) $s .= '
'; return $s; } @@ -532,7 +532,7 @@ class Form global $conf, $langs; $alt = ''; - if ($tooltiptrigger) $alt=$langs->transnoentitiesnoconv("ClickToShowHelp"); + if ($tooltiptrigger) $alt = $langs->transnoentitiesnoconv("ClickToShowHelp"); //For backwards compatibility if ($type == '0') $type = 'info'; @@ -550,7 +550,7 @@ class Form } // If info or help with smartphone, show only text (tooltip hover can't works) - if (! empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) + if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) { if ($type == 'info' || $type == 'infoclickable' || $type == 'help' || $type == 'helpclickable') return $text; } @@ -560,16 +560,16 @@ class Form //if ($type == 'info' || $type == 'help') return ''.$text.'''; //} - $img=''; + $img = ''; if ($type == 'info') $img = img_help(0, $alt); elseif ($type == 'help') $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt); elseif ($type == 'helpclickable') $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt); elseif ($type == 'superadmin') $img = img_picto($alt, 'redstar'); elseif ($type == 'admin') $img = img_picto($alt, 'star'); elseif ($type == 'warning') $img = img_warning($alt); - elseif ($type != 'none') $img = img_picto($alt, $type); // $type can be an image path + elseif ($type != 'none') $img = img_picto($alt, $type); // $type can be an image path - return $this->textwithtooltip($text, $htmltext, ((($tooltiptrigger && ! $img) || strpos($type, 'clickable'))?3:2), $direction, $img, $extracss, $notabs, '', $noencodehtmltext, $tooltiptrigger, $forcenowrap); + return $this->textwithtooltip($text, $htmltext, ((($tooltiptrigger && !$img) || strpos($type, 'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs, '', $noencodehtmltext, $tooltiptrigger, $forcenowrap); } /** @@ -582,39 +582,39 @@ class Form */ public function selectMassAction($selected, $arrayofaction, $alwaysvisible = 0) { - global $conf,$langs,$hookmanager; + global $conf, $langs, $hookmanager; if (count($arrayofaction) == 0) return; - $disabled=0; - $ret='
'; - $ret.=''; // Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks. - $parameters=array(); - $reshook=$hookmanager->executeHooks('addMoreMassActions', $parameters); // Note that $action and $object may have been modified by hook + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreMassActions', $parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) { - $ret.=''; - foreach($arrayofaction as $code => $label) + $ret .= ''; + foreach ($arrayofaction as $code => $label) { - $ret.=''; + $ret .= ''; } } - $ret.=$hookmanager->resPrint; + $ret .= $hookmanager->resPrint; - $ret.=''; + $ret .= ''; - if (empty($conf->dol_optimize_smallscreen)) $ret.=ajax_combobox('.massactionselect'); + if (empty($conf->dol_optimize_smallscreen)) $ret .= ajax_combobox('.massactionselect'); // Warning: if you set submit button to disabled, post using 'Enter' will no more work if there is no another input submit. So we add a hidden button - $ret.=''; // Hidden button BEFORE so it is the one used when we submit with ENTER. - $ret.=''; - $ret.='
'; + $ret .= ''; // Hidden button BEFORE so it is the one used when we submit with ENTER. + $ret .= ''; + $ret .= ''; - if (! empty($conf->use_javascript_ajax)) + if (!empty($conf->use_javascript_ajax)) { - $ret.=' + $ret .= ' '; - $out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); - $out.=' '; - $out.='
'; + $out .= ''; + $out .= ''; + $out .= $this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); + $out .= ' '; + $out .= '
'; } - $assignedtouser=array(); + $assignedtouser = array(); if (!empty($_SESSION['assignedtouser'])) { - $assignedtouser=json_decode($_SESSION['assignedtouser'], true); + $assignedtouser = json_decode($_SESSION['assignedtouser'], true); } - $nbassignetouser=count($assignedtouser); + $nbassignetouser = count($assignedtouser); - if ($nbassignetouser && $action != 'view') $out.='
'; - if ($nbassignetouser) $out.=''; //$out.=''; return $out; @@ -1897,31 +1897,31 @@ class Form public function select_produits($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $status = 1, $finished = 2, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $hidepriceinlabel = 0, $warehouseStatus = '', $selected_combinations = array()) { // phpcs:enable - global $langs,$conf; + global $langs, $conf; // check parameters - $price_level = (! empty($price_level) ? $price_level : 0); - if (is_null($ajaxoptions)) $ajaxoptions=array(); + $price_level = (!empty($price_level) ? $price_level : 0); + if (is_null($ajaxoptions)) $ajaxoptions = array(); - if(strval($filtertype) === '' && (!empty($conf->product->enabled) || !empty($conf->service->enabled))){ - if(!empty($conf->product->enabled) && empty($conf->service->enabled)){ + if (strval($filtertype) === '' && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) { + if (!empty($conf->product->enabled) && empty($conf->service->enabled)) { $filtertype = '0'; } - elseif(empty($conf->product->enabled) && !empty($conf->service->enabled)){ + elseif (empty($conf->product->enabled) && !empty($conf->service->enabled)) { $filtertype = '1'; } } - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { - $placeholder=''; + $placeholder = ''; if ($selected && empty($selected_input_value)) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $producttmpselect = new Product($this->db); $producttmpselect->fetch($selected); - $selected_input_value=$producttmpselect->ref; + $selected_input_value = $producttmpselect->ref; unset($producttmpselect); } // handle case where product or service module is disabled + no filter specified @@ -1935,10 +1935,10 @@ class Form } } // mode=1 means customers products - $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished.'&hidepriceinlabel='.$hidepriceinlabel.'&warehousestatus='.$warehouseStatus; + $urloption = 'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished.'&hidepriceinlabel='.$hidepriceinlabel.'&warehousestatus='.$warehouseStatus; //Price by customer - if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { - $urloption.='&socid='.$socid; + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { + $urloption .= '&socid='.$socid; } print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); @@ -2017,7 +2017,7 @@ class Form } if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : '; elseif ($hidelabel > 1) { - $placeholder=' placeholder="'.$langs->trans("RefOrLabel").'"'; + $placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"'; if ($hidelabel == 2) { print img_picto($langs->trans("Search"), 'search'); } @@ -2060,10 +2060,10 @@ class Form public function select_produits_list($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $filterkey = '', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $hidepriceinlabel = 0, $warehouseStatus = '') { // phpcs:enable - global $langs,$conf,$user,$db; + global $langs, $conf, $user, $db; - $out=''; - $outarray=array(); + $out = ''; + $outarray = array(); // Units if ($conf->global->PRODUCT_USE_UNITS) { @@ -2071,7 +2071,7 @@ class Form } $warehouseStatusArray = array(); - if (! empty($warehouseStatus)) + if (!empty($warehouseStatus)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; if (preg_match('/warehouseclosed/', $warehouseStatus)) @@ -2091,7 +2091,7 @@ class Form $selectFields = " p.rowid, p.label, p.ref, p.description, p.barcode, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.fk_price_expression"; if (count($warehouseStatusArray)) { - $selectFieldsGrouped = ", sum(".$db->ifsql("e.statut IS NULL", "0", "ps.reel").") as stock"; // e.statut is null if there is no record in stock + $selectFieldsGrouped = ", sum(".$db->ifsql("e.statut IS NULL", "0", "ps.reel").") as stock"; // e.statut is null if there is no record in stock } else { @@ -2099,12 +2099,12 @@ class Form } $sql = "SELECT "; - $sql.= $selectFields . $selectFieldsGrouped; + $sql .= $selectFields.$selectFieldsGrouped; - if (! empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) + if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) { //Product category - $sql.= ", (SELECT ".MAIN_DB_PREFIX."categorie_product.fk_categorie + $sql .= ", (SELECT ".MAIN_DB_PREFIX."categorie_product.fk_categorie FROM ".MAIN_DB_PREFIX."categorie_product WHERE ".MAIN_DB_PREFIX."categorie_product.fk_product=p.rowid LIMIT 1 @@ -2112,70 +2112,70 @@ class Form } //Price by customer - if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { - $sql.=', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,'; - $sql.=' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx'; - $selectFields.= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx"; + $sql .= ', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,'; + $sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx'; + $selectFields .= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx"; } // Units - if (! empty($conf->global->PRODUCT_USE_UNITS)) { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { $sql .= ", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units"; $selectFields .= ', unit_long, unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units'; } // Multilang : we add translation - if (! empty($conf->global->MAIN_MULTILANGS)) + if (!empty($conf->global->MAIN_MULTILANGS)) { - $sql.= ", pl.label as label_translated"; - $selectFields.= ", label_translated"; + $sql .= ", pl.label as label_translated"; + $selectFields .= ", label_translated"; } // Price by quantity - if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { - $sql.= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; - if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql.= " AND price_level=".$price_level; - $sql.= " ORDER BY date_price"; - $sql.= " DESC LIMIT 1) as price_rowid"; - $sql.= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable - if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql.= " AND price_level=".$price_level; - $sql.= " ORDER BY date_price"; - $sql.= " DESC LIMIT 1) as price_by_qty"; - $selectFields.= ", price_rowid, price_by_qty"; + $sql .= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; + if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql .= " AND price_level=".$price_level; + $sql .= " ORDER BY date_price"; + $sql .= " DESC LIMIT 1) as price_rowid"; + $sql .= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable + if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql .= " AND price_level=".$price_level; + $sql .= " ORDER BY date_price"; + $sql .= " DESC LIMIT 1) as price_by_qty"; + $selectFields .= ", price_rowid, price_by_qty"; } - $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; if (count($warehouseStatusArray)) { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_product = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (".getEntity('stock').")"; - $sql.= ' AND e.statut IN ('.$this->db->escape(implode(',', $warehouseStatusArray)).')'; // Return line if product is inside the selected stock. If not, an empty line will be returned so we will count 0. + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_product = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (".getEntity('stock').")"; + $sql .= ' AND e.statut IN ('.$this->db->escape(implode(',', $warehouseStatusArray)).')'; // Return line if product is inside the selected stock. If not, an empty line will be returned so we will count 0. } // include search in supplier ref - if(!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) + if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; } //Price by customer - if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { - $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".$socid." AND pcp.fk_product=p.rowid"; + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".$socid." AND pcp.fk_product=p.rowid"; } // Units - if (! empty($conf->global->PRODUCT_USE_UNITS)) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_units u ON u.rowid = p.fk_unit"; + if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units u ON u.rowid = p.fk_unit"; } // Multilang : we add translation - if (! empty($conf->global->MAIN_MULTILANGS)) + if (!empty($conf->global->MAIN_MULTILANGS)) { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='". $langs->getDefaultLang() ."'"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='".$langs->getDefaultLang()."'"; } if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; } - $sql.= ' WHERE p.entity IN ('.getEntity('product').')'; + $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { $sql .= " AND pac.rowid IS NULL"; @@ -2183,103 +2183,103 @@ class Form if ($finished == 0) { - $sql.= " AND p.finished = ".$finished; + $sql .= " AND p.finished = ".$finished; } elseif ($finished == 1) { - $sql.= " AND p.finished = ".$finished; - if ($status >= 0) $sql.= " AND p.tosell = ".$status; + $sql .= " AND p.finished = ".$finished; + if ($status >= 0) $sql .= " AND p.tosell = ".$status; } elseif ($status >= 0) { - $sql.= " AND p.tosell = ".$status; + $sql .= " AND p.tosell = ".$status; } // Filter by product type - if (strval($filtertype) != '') $sql.= " AND p.fk_product_type = ".$filtertype; + if (strval($filtertype) != '') $sql .= " AND p.fk_product_type = ".$filtertype; elseif (empty($conf->product->enabled)) { // when product module is disabled, show services only - $sql.= " AND p.fk_product_type = 1"; + $sql .= " AND p.fk_product_type = 1"; } elseif (empty($conf->service->enabled)) { // when service module is disabled, show products only - $sql.= " AND p.fk_product_type = 0"; + $sql .= " AND p.fk_product_type = 0"; } // Add criteria on ref/label if ($filterkey != '') { - $sql.=' AND ('; - $prefix=empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on + $sql .= ' AND ('; + $prefix = empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on // For natural search $scrit = explode(' ', $filterkey); - $i=0; - if (count($scrit) > 1) $sql.="("; + $i = 0; + if (count($scrit) > 1) $sql .= "("; foreach ($scrit as $crit) { - if ($i > 0) $sql.=" AND "; - $sql.="(p.ref LIKE '".$db->escape($prefix.$crit)."%' OR p.label LIKE '".$db->escape($prefix.$crit)."%'"; - if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '".$db->escape($prefix.$crit)."%'"; + if ($i > 0) $sql .= " AND "; + $sql .= "(p.ref LIKE '".$db->escape($prefix.$crit)."%' OR p.label LIKE '".$db->escape($prefix.$crit)."%'"; + if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= " OR pl.label LIKE '".$db->escape($prefix.$crit)."%'"; if (!empty($conf->global->PRODUCT_AJAX_SEARCH_ON_DESCRIPTION)) { - $sql.=" OR p.description LIKE '".$db->escape($prefix.$crit)."%'"; - if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.description LIKE '".$db->escape($prefix.$crit)."%'"; + $sql .= " OR p.description LIKE '".$db->escape($prefix.$crit)."%'"; + if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= " OR pl.description LIKE '".$db->escape($prefix.$crit)."%'"; } - if (! empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) $sql.=" OR pfp.ref_fourn LIKE '".$db->escape($prefix.$crit)."%'"; - $sql.=")"; + if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) $sql .= " OR pfp.ref_fourn LIKE '".$db->escape($prefix.$crit)."%'"; + $sql .= ")"; $i++; } - if (count($scrit) > 1) $sql.=")"; - if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'"; - $sql.=')'; + if (count($scrit) > 1) $sql .= ")"; + if (!empty($conf->barcode->enabled)) $sql .= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'"; + $sql .= ')'; } if (count($warehouseStatusArray)) { - $sql.= ' GROUP BY'.$selectFields; + $sql .= ' GROUP BY'.$selectFields; } //Sort by category - if(! empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) + if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) { $sql .= " ORDER BY categorie_product_id "; //ASC OR DESC order - ($conf->global->PRODUCT_SORT_BY_CATEGORY == 1) ? $sql .="ASC" : $sql .="DESC"; + ($conf->global->PRODUCT_SORT_BY_CATEGORY == 1) ? $sql .= "ASC" : $sql .= "DESC"; } else { - $sql.= $db->order("p.ref"); + $sql .= $db->order("p.ref"); } - $sql.= $db->plimit($limit, 0); + $sql .= $db->plimit($limit, 0); // Build output string dol_syslog(get_class($this)."::select_produits_list search product", LOG_DEBUG); - $result=$this->db->query($sql); + $result = $this->db->query($sql); if ($result) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; $num = $this->db->num_rows($result); - $events=null; + $events = null; - if (! $forcecombo) + if (!$forcecombo) { - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname, $events, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT); } - $out.=''; - $textifempty=''; + $textifempty = ''; // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. //if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; - if (! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) + if (!empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { - if ($showempty && ! is_numeric($showempty)) $textifempty=$langs->trans($showempty); - else $textifempty.=$langs->trans("All"); + if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty); + else $textifempty .= $langs->trans("All"); } else { - if ($showempty && ! is_numeric($showempty)) $textifempty=$langs->trans($showempty); + if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty); } - if ($showempty) $out.=''; + if ($showempty) $out .= ''; $i = 0; while ($num && $i < $num) @@ -2291,9 +2291,9 @@ class Form if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) { // Price by quantity will return many prices for the same product $sql = "SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; - $sql.= " WHERE fk_product_price=".$objp->price_rowid; - $sql.= " ORDER BY quantity ASC"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql .= " WHERE fk_product_price=".$objp->price_rowid; + $sql .= " ORDER BY quantity ASC"; dol_syslog(get_class($this)."::select_produits_list search price by qty", LOG_DEBUG); $result2 = $this->db->query($sql); @@ -2323,7 +2323,7 @@ class Form // Add new entry // "key" value of json key array is used by jQuery automatically as selected value // "label" value of json key array is used by jQuery automatically as text for combo box - $out.=$opt; + $out .= $opt; array_push($outarray, $optJson); } } @@ -2347,14 +2347,14 @@ class Form // Add new entry // "key" value of json key array is used by jQuery automatically as selected value // "label" value of json key array is used by jQuery automatically as text for combo box - $out.=$opt; + $out .= $opt; array_push($outarray, $optJson); } $i++; } - $out.=''; + $out .= ''; $this->db->free($result); @@ -2384,59 +2384,59 @@ class Form { global $langs, $conf, $user, $db; - $outkey=''; - $outval=''; - $outref=''; - $outlabel=''; - $outdesc=''; - $outbarcode=''; - $outtype=''; - $outprice_ht=''; - $outprice_ttc=''; - $outpricebasetype=''; - $outtva_tx=''; - $outqty=1; - $outdiscount=0; + $outkey = ''; + $outval = ''; + $outref = ''; + $outlabel = ''; + $outdesc = ''; + $outbarcode = ''; + $outtype = ''; + $outprice_ht = ''; + $outprice_ttc = ''; + $outpricebasetype = ''; + $outtva_tx = ''; + $outqty = 1; + $outdiscount = 0; - $maxlengtharticle=(empty($conf->global->PRODUCT_MAX_LENGTH_COMBO)?48:$conf->global->PRODUCT_MAX_LENGTH_COMBO); + $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO); - $label=$objp->label; - if (! empty($objp->label_translated)) $label=$objp->label_translated; - if (! empty($filterkey) && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i', '$1', $label, 1); + $label = $objp->label; + if (!empty($objp->label_translated)) $label = $objp->label_translated; + if (!empty($filterkey) && $filterkey != '') $label = preg_replace('/('.preg_quote($filterkey).')/i', '$1', $label, 1); - $outkey=$objp->rowid; - $outref=$objp->ref; - $outlabel=$objp->label; - $outdesc=$objp->description; - $outbarcode=$objp->barcode; + $outkey = $objp->rowid; + $outref = $objp->ref; + $outlabel = $objp->label; + $outdesc = $objp->description; + $outbarcode = $objp->barcode; - $outtype=$objp->fk_product_type; - $outdurationvalue=$outtype == Product::TYPE_SERVICE?substr($objp->duration, 0, dol_strlen($objp->duration)-1):''; - $outdurationunit=$outtype == Product::TYPE_SERVICE?substr($objp->duration, -1):''; + $outtype = $objp->fk_product_type; + $outdurationvalue = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, 0, dol_strlen($objp->duration) - 1) : ''; + $outdurationunit = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, -1) : ''; // Units $outvalUnits = ''; - if (! empty($conf->global->PRODUCT_USE_UNITS)) { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { if (!empty($objp->unit_short)) { - $outvalUnits .= ' - ' . $objp->unit_short; + $outvalUnits .= ' - '.$objp->unit_short; } } - if (! empty($conf->global->PRODUCT_SHOW_DIMENSIONS_IN_COMBO)) { - if (!empty($objp->weight) && $objp->weight_units!==null) { + if (!empty($conf->global->PRODUCT_SHOW_DIMENSIONS_IN_COMBO)) { + if (!empty($objp->weight) && $objp->weight_units !== null) { $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs); - $outvalUnits .= ' - ' . $unitToShow; + $outvalUnits .= ' - '.$unitToShow; } - if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units!==null) { - $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuringUnitString(0, 'size', $objp->length_units); - $outvalUnits .= ' - ' . $unitToShow; + if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units !== null) { + $unitToShow = $objp->length.' x '.$objp->width.' x '.$objp->height.' '.measuringUnitString(0, 'size', $objp->length_units); + $outvalUnits .= ' - '.$unitToShow; } - if (!empty($objp->surface) && $objp->surface_units!==null) { + if (!empty($objp->surface) && $objp->surface_units !== null) { $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs); - $outvalUnits .= ' - ' . $unitToShow; + $outvalUnits .= ' - '.$unitToShow; } - if (!empty($objp->volume) && $objp->volume_units!==null) { + if (!empty($objp->volume) && $objp->volume_units !== null) { $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs); - $outvalUnits .= ' - ' . $unitToShow; + $outvalUnits .= ' - '.$unitToShow; } } if ($outdurationvalue && $outdurationunit) { @@ -2448,50 +2448,50 @@ class Form 'y' => $langs->trans('Year') ); if (isset($da[$outdurationunit])) { - $outvalUnits .= ' - ' . $outdurationvalue . ' ' . $langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : '')); + $outvalUnits .= ' - '.$outdurationvalue.' '.$langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : '')); } } $opt = '\n"; + $opt .= "\n"; $optJson = array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'label2'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>price2num($outprice_ht), 'price_ttc'=>price2num($outprice_ttc), 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx, 'qty'=>$outqty, 'discount'=>$outdiscount, 'duration_value'=>$outdurationvalue, 'duration_unit'=>$outdurationunit); } @@ -2663,25 +2663,25 @@ class Form public function select_produits_fournisseurs($socid, $selected = '', $htmlname = 'productid', $filtertype = '', $filtre = '', $ajaxoptions = array(), $hidelabel = 0, $alsoproductwithnosupplierprice = 0, $morecss = '') { // phpcs:enable - global $langs,$conf; + global $langs, $conf; global $price_level, $status, $finished; - $selected_input_value=''; - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) + $selected_input_value = ''; + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { if ($selected > 0) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $producttmpselect = new Product($this->db); $producttmpselect->fetch($selected); - $selected_input_value=$producttmpselect->ref; + $selected_input_value = $producttmpselect->ref; unset($producttmpselect); } // mode=2 means suppliers products - $urloption=($socid > 0?'socid='.$socid.'&':'').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished.'&alsoproductwithnosupplierprice='.$alsoproductwithnosupplierprice; + $urloption = ($socid > 0 ? 'socid='.$socid.'&' : '').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished.'&alsoproductwithnosupplierprice='.$alsoproductwithnosupplierprice; print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); - print ($hidelabel?'':$langs->trans("RefOrLabel").' : ').''; + print ($hidelabel ? '' : $langs->trans("RefOrLabel").' : ').''; } else { @@ -2709,10 +2709,10 @@ class Form public function select_produits_fournisseurs_list($socid, $selected = '', $htmlname = 'productid', $filtertype = '', $filtre = '', $filterkey = '', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss = '') { // phpcs:enable - global $langs,$conf,$db; + global $langs, $conf, $db; - $out=''; - $outarray=array(); + $out = ''; + $outarray = array(); $langs->load('stocks'); // Units @@ -2721,55 +2721,55 @@ class Form } $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration, p.fk_product_type,"; - $sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,"; - $sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,"; - $sql.= " pfp.supplier_reputation"; + $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,"; + $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,"; + $sql .= " pfp.supplier_reputation"; // Units if ($conf->global->PRODUCT_USE_UNITS) { $sql .= ", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units"; } - if (! empty($conf->barcode->enabled)) $sql.= " ,pfp.barcode"; - $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; - if ($socid) $sql.= " AND pfp.fk_soc = ".$socid; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; + if (!empty($conf->barcode->enabled)) $sql .= " ,pfp.barcode"; + $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; + if ($socid) $sql .= " AND pfp.fk_soc = ".$socid; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; // Units if ($conf->global->PRODUCT_USE_UNITS) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_units u ON u.rowid = p.fk_unit"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units u ON u.rowid = p.fk_unit"; } - $sql.= " WHERE p.entity IN (".getEntity('product').")"; - $sql.= " AND p.tobuy = 1"; - if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$this->db->escape($filtertype); - if (! empty($filtre)) $sql.=" ".$filtre; + $sql .= " WHERE p.entity IN (".getEntity('product').")"; + $sql .= " AND p.tobuy = 1"; + if (strval($filtertype) != '') $sql .= " AND p.fk_product_type=".$this->db->escape($filtertype); + if (!empty($filtre)) $sql .= " ".$filtre; // Add criteria on ref/label if ($filterkey != '') { - $sql.=' AND ('; - $prefix=empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on + $sql .= ' AND ('; + $prefix = empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on // For natural search $scrit = explode(' ', $filterkey); - $i=0; - if (count($scrit) > 1) $sql.="("; + $i = 0; + if (count($scrit) > 1) $sql .= "("; foreach ($scrit as $crit) { - if ($i > 0) $sql.=" AND "; - $sql.="(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit)."%' OR p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%')"; + if ($i > 0) $sql .= " AND "; + $sql .= "(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit)."%' OR p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%')"; $i++; } - if (count($scrit) > 1) $sql.=")"; - if (! empty($conf->barcode->enabled)){ - $sql.= " OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; - $sql.= " OR pfp.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; + if (count($scrit) > 1) $sql .= ")"; + if (!empty($conf->barcode->enabled)) { + $sql .= " OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; + $sql .= " OR pfp.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; } - $sql.=')'; + $sql .= ')'; } - $sql.= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; - $sql.= $db->plimit($limit, 0); + $sql .= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; + $sql .= $db->plimit($limit, 0); // Build output string dol_syslog(get_class($this)."::select_produits_fournisseurs_list", LOG_DEBUG); - $result=$this->db->query($sql); + $result = $this->db->query($sql); if ($result) { require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; @@ -2777,47 +2777,47 @@ class Form $num = $this->db->num_rows($result); //$out.=''; - if (! $selected) $out.=''; - else $out.=''; + $out .= ''; + $out .= ''; $this->db->free($result); - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.=ajax_combobox($htmlname); + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname); if (empty($outputmode)) return $out; return $outarray; @@ -2997,24 +2997,24 @@ class Form public function select_product_fourn_price($productid, $htmlname = 'productfournpriceid', $selected_supplier = '') { // phpcs:enable - global $langs,$conf; + global $langs, $conf; $langs->load('stocks'); $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration, pfp.fk_soc,"; - $sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,"; - $sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; - $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; - $sql.= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")"; - $sql.= " AND p.tobuy = 1"; - $sql.= " AND s.fournisseur = 1"; - $sql.= " AND p.rowid = ".$productid; - $sql.= " ORDER BY s.nom, pfp.ref_fourn DESC"; + $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,"; + $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; + $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; + $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")"; + $sql .= " AND p.tobuy = 1"; + $sql .= " AND s.fournisseur = 1"; + $sql .= " AND p.rowid = ".$productid; + $sql .= " ORDER BY s.nom, pfp.ref_fourn DESC"; dol_syslog(get_class($this)."::select_product_fourn_price", LOG_DEBUG); - $result=$this->db->query($sql); + $result = $this->db->query($sql); if ($result) { @@ -3022,14 +3022,14 @@ class Form $form = ''; + $form .= ''; $this->db->free($result); return $form; } @@ -3113,12 +3113,12 @@ class Form // phpcs:enable // looking for users $sql = "SELECT a.rowid, a.label"; - $sql .= " FROM ".MAIN_DB_PREFIX ."societe_address as a"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe_address as a"; $sql .= " WHERE a.fk_soc = ".$socid; $sql .= " ORDER BY a.label ASC"; dol_syslog(get_class($this)."::select_address", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { print ''; if ($addempty) print ''; - foreach($this->cache_availability as $id => $arrayavailability) + foreach ($this->cache_availability as $id => $arrayavailability) { if ($selected == $id) { @@ -3296,34 +3296,34 @@ class Form global $langs; $num = count($this->cache_demand_reason); - if ($num > 0) return 0; // Cache already loaded + if ($num > 0) return 0; // Cache already loaded $sql = "SELECT rowid, code, label"; - $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; - $sql.= " WHERE active > 0"; + $sql .= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; + $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - $tmparray=array(); + $tmparray = array(); while ($i < $num) { $obj = $this->db->fetch_object($resql); // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $label=($obj->label!='-'?$obj->label:''); + $label = ($obj->label != '-' ? $obj->label : ''); if ($langs->trans("DemandReasonType".$obj->code) != ("DemandReasonType".$obj->code)) $label = $langs->trans("DemandReasonType".$obj->code); // So translation key DemandReasonTypeSRC_XXX will work - if ($langs->trans($obj->code) != $obj->code) $label=$langs->trans($obj->code); // So translation key SRC_XXX will work + if ($langs->trans($obj->code) != $obj->code) $label = $langs->trans($obj->code); // So translation key SRC_XXX will work - $tmparray[$obj->rowid]['id'] =$obj->rowid; - $tmparray[$obj->rowid]['code'] =$obj->code; - $tmparray[$obj->rowid]['label']=$label; + $tmparray[$obj->rowid]['id'] = $obj->rowid; + $tmparray[$obj->rowid]['code'] = $obj->code; + $tmparray[$obj->rowid]['label'] = $label; $i++; } - $this->cache_demand_reason=dol_sort_array($tmparray, 'label', 'asc', 0, 0, 1); + $this->cache_demand_reason = dol_sort_array($tmparray, 'label', 'asc', 0, 0, 1); unset($tmparray); return $num; @@ -3347,15 +3347,15 @@ class Form */ public function selectInputReason($selected = '', $htmlname = 'demandreasonid', $exclude = '', $addempty = 0) { - global $langs,$user; + global $langs, $user; $this->loadCacheInputReason(); print ''; + print ''; + print ''; - if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + if ($user->admin && !$noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } @@ -3546,26 +3546,26 @@ class Form { global $langs; - $return=''; + $return = ''; - $return.= ''; $options = array( 'HT'=>$langs->trans("HT"), 'TTC'=>$langs->trans("TTC") ); - foreach($options as $id => $value) + foreach ($options as $id => $value) { if ($selected == $id) { - $return.= ''; + $return .= ''; } - $return.= ''; + $return .= ''; return $return; } @@ -3588,10 +3588,10 @@ class Form $langs->load("deliveries"); $sql = "SELECT rowid, code, libelle as label"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; - $sql.= " WHERE active > 0"; - if ($filtre) $sql.=" AND ".$filtre; - $sql.= " ORDER BY libelle ASC"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; + $sql .= " WHERE active > 0"; + if ($filtre) $sql .= " AND ".$filtre; + $sql .= " ORDER BY libelle ASC"; dol_syslog(get_class($this)."::selectShippingMode", LOG_DEBUG); $result = $this->db->query($sql); @@ -3599,7 +3599,7 @@ class Form $num = $this->db->num_rows($result); $i = 0; if ($num) { - print ''; if ($useempty == 1 || ($useempty == 2 && $num > 1)) { print ''; } @@ -3648,7 +3648,7 @@ class Form print ''; } else { if ($selected) { - $code=$langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); + $code = $langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); print $langs->trans("SendingMethod".strtoupper($code)); } else { print " "; @@ -3672,15 +3672,15 @@ class Form $opt = ''; $sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc'; - $sql.= ' FROM ' . MAIN_DB_PREFIX . 'facture'; - $sql.= ' WHERE entity IN ('.getEntity('invoice').')'; - $sql.= ' AND situation_counter>=1'; - $sql.= ' ORDER by situation_cycle_ref, situation_counter desc'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'facture'; + $sql .= ' WHERE entity IN ('.getEntity('invoice').')'; + $sql .= ' AND situation_counter>=1'; + $sql .= ' ORDER by situation_cycle_ref, situation_counter desc'; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { // Last seen cycle $ref = 0; - while ($obj = $this->db->fetch_object($resql)){ + while ($obj = $this->db->fetch_object($resql)) { //Same company ? if ($socid == $obj->fk_soc) { //Same cycle ? @@ -3692,9 +3692,9 @@ class Form //Not prov? if (substr($obj->ref, 1, 4) != 'PROV') { if ($selected == $obj->rowid) { - $opt .= ''; + $opt .= ''; } else { - $opt .= ''; + $opt .= ''; } } } @@ -3704,11 +3704,11 @@ class Form } else { - dol_syslog("Error sql=" . $sql . ", error=" . $this->error, LOG_ERR); + dol_syslog("Error sql=".$sql.", error=".$this->error, LOG_ERR); } if ($opt == '') { - $opt = ''; + $opt = ''; } return $opt; } @@ -3727,34 +3727,34 @@ class Form $langs->load('products'); - $return= ''; $sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units'; - $sql.= ' WHERE active > 0'; + $sql .= ' WHERE active > 0'; $resql = $this->db->query($sql); - if($resql && $this->db->num_rows($resql) > 0) + if ($resql && $this->db->num_rows($resql) > 0) { if ($showempty) $return .= ''; - while($res = $this->db->fetch_object($resql)) + while ($res = $this->db->fetch_object($resql)) { $unitLabel = $res->label; - if (! empty($langs->tab_translate['unit'.$res->code])) // check if Translation is available before + if (!empty($langs->tab_translate['unit'.$res->code])) // check if Translation is available before { - $unitLabel = $langs->trans('unit'.$res->code)!=$res->label?$langs->trans('unit'.$res->code):$res->label; + $unitLabel = $langs->trans('unit'.$res->code) != $res->label ? $langs->trans('unit'.$res->code) : $res->label; } if ($selected == $res->rowid) { - $return.=''; + $return .= ''; } else { - $return.=''; + $return .= ''; } } - $return.=''; + $return .= ''; } return $return; } @@ -3796,7 +3796,7 @@ class Form $i = 0; if ($num) { - print ''; if ($useempty == 1 || ($useempty == 2 && $num > 1)) { print ''; @@ -3868,7 +3868,7 @@ class Form $i = 0; if ($num) { - print ''; if ($useempty == 1 || ($useempty == 2 && $num > 1)) { print ''; @@ -3926,8 +3926,8 @@ class Form $langs->load('banks'); if ($selected) { - require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php'; - $bankstatic=new Account($this->db); + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + $bankstatic = new Account($this->db); $result = $bankstatic->fetch($selected); if ($result) print $bankstatic->getNomUrl(1); } else { @@ -3965,17 +3965,17 @@ class Form // For backward compatibility if (is_numeric($type)) { - dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); + dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); } if ($type === Categorie::TYPE_BANK_LINE) { // TODO Move this into common category feature - $categids=array(); + $categids = array(); $sql = "SELECT c.label, c.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as c"; - $sql.= " WHERE entity = ".$conf->entity; - $sql.= " ORDER BY c.label"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as c"; + $sql .= " WHERE entity = ".$conf->entity; + $sql .= " ORDER BY c.label"; $result = $this->db->query($sql); if ($result) { @@ -3984,7 +3984,7 @@ class Form while ($i < $num) { $objp = $this->db->fetch_object($result); - if ($objp) $cate_arbo[$objp->rowid]=array('id'=>$objp->rowid, 'fulllabel'=>$objp->label); + if ($objp) $cate_arbo[$objp->rowid] = array('id'=>$objp->rowid, 'fulllabel'=>$objp->label); $i++; } $this->db->free($result); @@ -3998,14 +3998,14 @@ class Form } $output = ''; - $output.= "\n"; + $output .= ''; + $output .= "\n"; if ($outputmode) return $outarray; return $output; @@ -4048,7 +4048,7 @@ class Form public function form_confirm($page, $title, $question, $action, $formquestion = '', $selectedchoice = "", $useajax = 0, $height = 170, $width = 500) { // phpcs:enable - dol_syslog(__METHOD__ . ': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING); + dol_syslog(__METHOD__.': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING); print $this->formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width); } @@ -4078,17 +4078,17 @@ class Form */ public function formconfirm($page, $title, $question, $action, $formquestion = '', $selectedchoice = '', $useajax = 0, $height = 0, $width = 500, $disableformtag = 0) { - global $langs,$conf; + global $langs, $conf; global $useglobalvars; - $more=''; - $formconfirm=''; - $inputok=array(); - $inputko=array(); + $more = ''; + $formconfirm = ''; + $inputok = array(); + $inputko = array(); // Clean parameters - $newselectedchoice=empty($selectedchoice)?"no":$selectedchoice; - if ($conf->browser->layout == 'phone') $width='95%'; + $newselectedchoice = empty($selectedchoice) ? "no" : $selectedchoice; + if ($conf->browser->layout == 'phone') $width = '95%'; // Set height automatically if not defined if (empty($height)) { @@ -4098,79 +4098,79 @@ class Form } } - if (is_array($formquestion) && ! empty($formquestion)) + if (is_array($formquestion) && !empty($formquestion)) { // First add hidden fields and value foreach ($formquestion as $key => $input) { - if (is_array($input) && ! empty($input)) + if (is_array($input) && !empty($input)) { if ($input['type'] == 'hidden') { - $more.=''."\n"; + $more .= ''."\n"; } } } // Now add questions - $more.='
'."\n"; - if (! empty($formquestion['text'])) $more.=''.$formquestion['text'].''."\n"; + $more .= '
'."\n"; + if (!empty($formquestion['text'])) $more .= ''.$formquestion['text'].''."\n"; foreach ($formquestion as $key => $input) { - if (is_array($input) && ! empty($input)) + if (is_array($input) && !empty($input)) { - $size=(! empty($input['size'])?' size="'.$input['size'].'"':''); - $moreattr=(! empty($input['moreattr'])?' '.$input['moreattr']:''); - $morecss=(! empty($input['morecss'])?' '.$input['morecss']:''); + $size = (!empty($input['size']) ? ' size="'.$input['size'].'"' : ''); + $moreattr = (!empty($input['moreattr']) ? ' '.$input['moreattr'] : ''); + $morecss = (!empty($input['morecss']) ? ' '.$input['morecss'] : ''); if ($input['type'] == 'text') { - $more.='
'.$input['label'].'
'."\n"; + $more .= '
'.$input['label'].'
'."\n"; } elseif ($input['type'] == 'password') { - $more.='
'.$input['label'].'
'."\n"; + $more .= '
'.$input['label'].'
'."\n"; } elseif ($input['type'] == 'select') { - $more.='
'; - if (! empty($input['label'])) $more.=$input['label'].'
'; - $more.=$this->selectarray($input['name'], $input['values'], $input['default'], 1, 0, 0, $moreattr, 0, 0, 0, '', $morecss); - $more.='
'."\n"; + $more .= '
'; + if (!empty($input['label'])) $more .= $input['label'].'
'; + $more .= $this->selectarray($input['name'], $input['values'], $input['default'], 1, 0, 0, $moreattr, 0, 0, 0, '', $morecss); + $more .= '
'."\n"; } elseif ($input['type'] == 'checkbox') { - $more.='
'; - $more.='
'.$input['label'].'
'; - $more.=''.$input['label'].'
'; + $more .= ' $selval) + $i = 0; + foreach ($input['values'] as $selkey => $selval) { - $more.='
'; - if ($i==0) $more.='
'.$input['label'].'
'; - else $more.='
 
'; - $more.='
'.$input['label'].'
'; + else $more .= '
 
'; + $more .= '
'.$input['label'].'
'; - $more.='
'; - $more.=$this->selectDate($input['value'], $input['name'], 0, 0, 0, '', 1, 0); - $more.='
'."\n"; + $more .= '
'.$input['label'].'
'; + $more .= '
'; + $more .= $this->selectDate($input['value'], $input['name'], 0, 0, 0, '', 1, 0); + $more .= '
'."\n"; $formquestion[] = array('name'=>$input['name'].'day'); $formquestion[] = array('name'=>$input['name'].'month'); $formquestion[] = array('name'=>$input['name'].'year'); @@ -4179,43 +4179,43 @@ class Form } elseif ($input['type'] == 'other') { - $more.='
'; - if (! empty($input['label'])) $more.=$input['label'].'
'; - $more.=$input['value']; - $more.='
'."\n"; + $more .= '
'; + if (!empty($input['label'])) $more .= $input['label'].'
'; + $more .= $input['value']; + $more .= '
'."\n"; } elseif ($input['type'] == 'onecolumn') { - $more.='
'; - $more.=$input['value']; - $more.='
'."\n"; + $more .= '
'; + $more .= $input['value']; + $more .= '
'."\n"; } } } - $more.='
'."\n"; + $more .= '
'."\n"; } // JQUI method dialog is broken with jmobile, we use standard HTML. // Note: When using dol_use_jmobile or no js, you must also check code for button use a GET url with action=xxx and check that you also output the confirm code when action=xxx // See page product/card.php for example - if (! empty($conf->dol_use_jmobile)) $useajax=0; - if (empty($conf->use_javascript_ajax)) $useajax=0; + if (!empty($conf->dol_use_jmobile)) $useajax = 0; + if (empty($conf->use_javascript_ajax)) $useajax = 0; if ($useajax) { - $autoOpen=true; - $dialogconfirm='dialog-confirm'; - $button=''; - if (! is_numeric($useajax)) + $autoOpen = true; + $dialogconfirm = 'dialog-confirm'; + $button = ''; + if (!is_numeric($useajax)) { - $button=$useajax; - $useajax=1; - $autoOpen=false; - $dialogconfirm.='-'.$button; + $button = $useajax; + $useajax = 1; + $autoOpen = false; + $dialogconfirm .= '-'.$button; } - $pageyes=$page.(preg_match('/\?/', $page)?'&':'?').'action='.$action.'&confirm=yes'; - $pageno=($useajax == 2 ? $page.(preg_match('/\?/', $page)?'&':'?').'confirm=no':''); + $pageyes = $page.(preg_match('/\?/', $page) ? '&' : '?').'action='.$action.'&confirm=yes'; + $pageno = ($useajax == 2 ? $page.(preg_match('/\?/', $page) ? '&' : '?').'confirm=no' : ''); // Add input fields into list of fields to read during submit (inputok and inputko) if (is_array($formquestion)) { @@ -4227,28 +4227,28 @@ class Form } } // Show JQuery confirm box. Note that global var $useglobalvars is used inside this template - $formconfirm.= ''."\n"; - $formconfirm.= "\n\n"; - $formconfirm.= ''; - $formconfirm.= "\n"; + $formconfirm .= "\n"; } else { - $formconfirm.= "\n\n"; + $formconfirm .= "\n\n"; - if (empty($disableformtag)) $formconfirm.= '
'."\n"; + if (empty($disableformtag)) $formconfirm .= ''."\n"; - $formconfirm.= ''."\n"; - $formconfirm.= ''."\n"; + $formconfirm .= ''."\n"; + $formconfirm .= ''."\n"; - $formconfirm.= ''."\n"; + $formconfirm .= '
'."\n"; // Line title - $formconfirm.= ''."\n"; + $formconfirm .= ''."\n"; // Line form fields if ($more) { - $formconfirm.=''."\n"; + $formconfirm .= ''."\n"; } // Line with question - $formconfirm.= ''; - $formconfirm.= ''; - $formconfirm.= ''; - $formconfirm.= ''; - $formconfirm.= ''."\n"; + $formconfirm .= ''; + $formconfirm .= ''; + $formconfirm .= ''; + $formconfirm .= ''; + $formconfirm .= ''."\n"; - $formconfirm.= '
'.img_picto('', 'recent').' '.$title.'
'.img_picto('', 'recent').' '.$title.'
'."\n"; - $formconfirm.=$more; - $formconfirm.='
'."\n"; + $formconfirm .= $more; + $formconfirm .= '
'.$question.''; - $formconfirm.= $this->selectyesno("confirm", $newselectedchoice); - $formconfirm.= '
'.$question.''; + $formconfirm .= $this->selectyesno("confirm", $newselectedchoice); + $formconfirm .= '
'."\n"; + $formconfirm .= ''."\n"; - if (empty($disableformtag)) $formconfirm.= "
\n"; - $formconfirm.= '
'; + if (empty($disableformtag)) $formconfirm .= "\n"; + $formconfirm .= '
'; - $formconfirm.= "\n"; + $formconfirm .= "\n"; } return $formconfirm; @@ -4372,20 +4372,20 @@ class Form require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; - $out=''; + $out = ''; - $formproject=new FormProjets($this->db); + $formproject = new FormProjets($this->db); $langs->load("project"); if ($htmlname != "none") { - $out.="\n"; - $out.='
'; - $out.=''; - $out.=''; - $out.=$formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0, '', 1); - $out.=''; - $out.='
'; + $out .= "\n"; + $out .= '
'; + $out .= ''; + $out .= ''; + $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0, '', 1); + $out .= ''; + $out .= '
'; } else { @@ -4394,11 +4394,11 @@ class Form $projet = new Project($this->db); $projet->fetch($selected); //print ''.$projet->title.''; - $out.=$projet->getNomUrl(0, '', 1); + $out .= $projet->getNomUrl(0, '', 1); } else { - $out.=" "; + $out .= " "; } } @@ -4539,24 +4539,24 @@ class Form // phpcs:enable global $langs; - $ret=''; + $ret = ''; if ($htmlname != "none") { - $ret.='
'; - $ret.=''; - $ret.=''; - $ret.=''; - $ret.=''; - $ret.=''; - $ret.='
'; - $ret.=$this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1, 'form'.$htmlname, 1, 0); - $ret.='
'; + $ret .= '
'; + $ret .= ''; + $ret .= ''; + $ret .= ''; + $ret .= ''; + $ret .= ''; + $ret .= '
'; + $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1, 'form'.$htmlname, 1, 0); + $ret .= '
'; } else { - if ($displayhour) $ret.=dol_print_date($selected, 'dayhour'); - else $ret.=dol_print_date($selected, 'day'); + if ($displayhour) $ret .= dol_print_date($selected, 'dayhour'); + else $ret .= dol_print_date($selected, 'day'); } if (empty($nooutput)) print $ret; @@ -4593,8 +4593,8 @@ class Form { if ($selected) { - require_once DOL_DOCUMENT_ROOT .'/user/class/user.class.php'; - $theuser=new User($this->db); + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; + $theuser = new User($this->db); $theuser->fetch($selected); print $theuser->getNomUrl(1); } else { @@ -4700,7 +4700,7 @@ class Form } else { - if (! empty($rate)) + if (!empty($rate)) { print price($rate, 1, $langs, 1, 0); if ($currency && $rate != 1) print '   ('.price($rate, 1, $langs, 1, 0).' '.$currency.' = 1 '.$conf->currency.')'; @@ -4732,33 +4732,33 @@ class Form public function form_remise_dispo($page, $selected, $htmlname, $socid, $amount, $filter = '', $maxvalue = 0, $more = '', $hidelist = 0, $discount_type = 0) { // phpcs:enable - global $conf,$langs; + global $conf, $langs; if ($htmlname != "none") { print '
'; print ''; print ''; print '
'; - if(! empty($discount_type)) { - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) + if (!empty($discount_type)) { + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - if (! $filter || $filter=="fk_invoice_supplier_source IS NULL") $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice + if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice else $translationKey = 'HasCreditNoteFromSupplier'; } else { - if (! $filter || $filter=="fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") $translationKey = 'HasAbsoluteDiscountFromSupplier'; + if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") $translationKey = 'HasAbsoluteDiscountFromSupplier'; else $translationKey = 'HasCreditNoteFromSupplier'; } } else { - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - if (! $filter || $filter=="fk_facture_source IS NULL") $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice + if (!$filter || $filter == "fk_facture_source IS NULL") $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice else $translationKey = 'CompanyHasCreditNote'; } else { - if (! $filter || $filter=="fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") $translationKey = 'CompanyHasAbsoluteDiscount'; + if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") $translationKey = 'CompanyHasAbsoluteDiscount'; else $translationKey = 'CompanyHasCreditNote'; } } @@ -4769,19 +4769,19 @@ class Form { print '
'; $newfilter = 'discount_type='.intval($discount_type); - if(! empty($discount_type)) { - $newfilter.= ' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL'; // Supplier discounts available + if (!empty($discount_type)) { + $newfilter .= ' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL'; // Supplier discounts available } else { - $newfilter.= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available + $newfilter .= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available } - if ($filter) $newfilter.=' AND ('.$filter.')'; - $nbqualifiedlines=$this->select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue); + if ($filter) $newfilter .= ' AND ('.$filter.')'; + $nbqualifiedlines = $this->select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue); if ($nbqualifiedlines > 0) { print '   '; @@ -4832,10 +4832,10 @@ class Form print ''; print ''; print ''; @@ -4846,8 +4846,8 @@ class Form { if ($selected) { - require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php'; - $contact=new Contact($this->db); + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + $contact = new Contact($this->db); $contact->fetch($selected); print $contact->getFullName($langs); } else { @@ -4879,25 +4879,25 @@ class Form $out = ''; if ($htmlname != "none") { - $out.=''; - $out.= ''; - $out.= ''; - $out.= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); - $out.= ''; - $out.= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); + $out .= ''; + $out .= ''; } else { if ($selected) { - require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $soc = new Societe($this->db); $soc->fetch($selected); - $out.= $soc->getNomUrl($langs); + $out .= $soc->getNomUrl($langs); } else { - $out.= " "; + $out .= " "; } } @@ -4930,41 +4930,41 @@ class Form */ public function selectCurrency($selected = '', $htmlname = 'currency_id', $mode = 0) { - global $conf,$langs,$user; + global $conf, $langs, $user; $langs->loadCacheCurrencies(''); - $out=''; + $out = ''; - if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilite + if ($selected == 'euro' || $selected == 'euros') $selected = 'EUR'; // Pour compatibilite - $out.= ''; foreach ($langs->cache_currencies as $code_iso => $currency) { if ($selected && $selected == $code_iso) { - $out.= ''; + $out .= ''; } - $out.= ''; - if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + $out .= ''; + if ($user->admin) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); // Make select dynamic - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname); return $out; @@ -4980,25 +4980,25 @@ class Form */ public function selectMultiCurrency($selected = '', $htmlname = 'multicurrency_code', $useempty = 0) { - global $db,$conf,$langs,$user; + global $db, $conf, $langs, $user; - $langs->loadCacheCurrencies(''); // Load ->cache_currencies + $langs->loadCacheCurrencies(''); // Load ->cache_currencies $TCurrency = array(); $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency'; - $sql.= " WHERE entity IN ('".getEntity('mutlicurrency')."')"; + $sql .= " WHERE entity IN ('".getEntity('mutlicurrency')."')"; $resql = $db->query($sql); if ($resql) { while ($obj = $db->fetch_object($resql)) $TCurrency[$obj->code] = $obj->code; } - $out=''; - $out.= ''; if ($useempty) $out .= ''; // If company current currency not in table, we add it into list. Should always be available. - if (! in_array($conf->currency, $TCurrency)) + if (!in_array($conf->currency, $TCurrency)) { $TCurrency[$conf->currency] = $conf->currency; } @@ -5008,20 +5008,20 @@ class Form { if (isset($TCurrency[$code_iso])) { - if (!empty($selected) && $selected == $code_iso) $out.= ''; + $out .= $currency['label']; + $out .= ' ('.$langs->getCurrencySymbol($code_iso).')'; + $out .= ''; } } } - $out.= ''; + $out .= ''; // Make select dynamic - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.= ajax_combobox($htmlname); + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname); return $out; } @@ -5039,18 +5039,18 @@ class Form global $langs; $num = count($this->cache_vatrates); - if ($num > 0) return $num; // Cache already loaded + if ($num > 0) return $num; // Cache already loaded dol_syslog(__METHOD__, LOG_DEBUG); - $sql = "SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; - $sql.= " WHERE t.fk_pays = c.rowid"; - $sql.= " AND t.active > 0"; - $sql.= " AND c.code IN (".$country_code.")"; - $sql.= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC"; + $sql = "SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; + $sql .= " WHERE t.fk_pays = c.rowid"; + $sql .= " AND t.active > 0"; + $sql .= " AND c.code IN (".$country_code.")"; + $sql .= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC"; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -5060,22 +5060,22 @@ class Form { $obj = $this->db->fetch_object($resql); $this->cache_vatrates[$i]['rowid'] = $obj->rowid; - $this->cache_vatrates[$i]['code'] = $obj->code; + $this->cache_vatrates[$i]['code'] = $obj->code; $this->cache_vatrates[$i]['txtva'] = $obj->taux; - $this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly; + $this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly; $this->cache_vatrates[$i]['localtax1'] = $obj->localtax1; $this->cache_vatrates[$i]['localtax1_type'] = $obj->localtax1_type; $this->cache_vatrates[$i]['localtax2'] = $obj->localtax2; $this->cache_vatrates[$i]['localtax2_type'] = $obj->localtax1_type; - $this->cache_vatrates[$i]['label'] = $obj->taux.'%'.($obj->code?' ('.$obj->code.')':''); // Label must contains only 0-9 , . % or * - $this->cache_vatrates[$i]['labelallrates'] = $obj->taux.'/'.($obj->localtax1?$obj->localtax1:'0').'/'.($obj->localtax2?$obj->localtax2:'0').($obj->code?' ('.$obj->code.')':''); // Must never be used as key, only label - $positiverates=''; - if ($obj->taux) $positiverates.=($positiverates?'/':'').$obj->taux; - if ($obj->localtax1) $positiverates.=($positiverates?'/':'').$obj->localtax1; - if ($obj->localtax2) $positiverates.=($positiverates?'/':'').$obj->localtax2; - if (empty($positiverates)) $positiverates='0'; - $this->cache_vatrates[$i]['labelpositiverates'] = $positiverates.($obj->code?' ('.$obj->code.')':''); // Must never be used as key, only label + $this->cache_vatrates[$i]['label'] = $obj->taux.'%'.($obj->code ? ' ('.$obj->code.')' : ''); // Label must contains only 0-9 , . % or * + $this->cache_vatrates[$i]['labelallrates'] = $obj->taux.'/'.($obj->localtax1 ? $obj->localtax1 : '0').'/'.($obj->localtax2 ? $obj->localtax2 : '0').($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label + $positiverates = ''; + if ($obj->taux) $positiverates .= ($positiverates ? '/' : '').$obj->taux; + if ($obj->localtax1) $positiverates .= ($positiverates ? '/' : '').$obj->localtax1; + if ($obj->localtax2) $positiverates .= ($positiverates ? '/' : '').$obj->localtax2; + if (empty($positiverates)) $positiverates = '0'; + $this->cache_vatrates[$i]['labelpositiverates'] = $positiverates.($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label } return $num; @@ -5118,34 +5118,34 @@ class Form public function load_tva($htmlname = 'tauxtva', $selectedrate = '', $societe_vendeuse = '', $societe_acheteuse = '', $idprod = 0, $info_bits = 0, $type = '', $options_only = false, $mode = 0) { // phpcs:enable - global $langs,$conf,$mysoc; + global $langs, $conf, $mysoc; $langs->load('errors'); - $return=''; + $return = ''; // Define defaultnpr, defaultttx and defaultcode - $defaultnpr=($info_bits & 0x01); - $defaultnpr=(preg_match('/\*/', $selectedrate) ? 1 : $defaultnpr); - $defaulttx=str_replace('*', '', $selectedrate); - $defaultcode=''; + $defaultnpr = ($info_bits & 0x01); + $defaultnpr = (preg_match('/\*/', $selectedrate) ? 1 : $defaultnpr); + $defaulttx = str_replace('*', '', $selectedrate); + $defaultcode = ''; if (preg_match('/\((.*)\)/', $defaulttx, $reg)) { - $defaultcode=$reg[1]; - $defaulttx=preg_replace('/\s*\(.*\)/', '', $defaulttx); + $defaultcode = $reg[1]; + $defaulttx = preg_replace('/\s*\(.*\)/', '', $defaulttx); } //var_dump($selectedrate.'-'.$defaulttx.'-'.$defaultnpr.'-'.$defaultcode); // Check parameters - if (is_object($societe_vendeuse) && ! $societe_vendeuse->country_code) + if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) { if ($societe_vendeuse->id == $mysoc->id) { - $return.= ''.$langs->trans("ErrorYourCountryIsNotDefined").''; + $return .= ''.$langs->trans("ErrorYourCountryIsNotDefined").''; } else { - $return.= ''.$langs->trans("ErrorSupplierCountryIsNotDefined").''; + $return .= ''.$langs->trans("ErrorSupplierCountryIsNotDefined").''; } return $return; } @@ -5158,82 +5158,82 @@ class Form // First we defined code_country to use to find list if (is_object($societe_vendeuse)) { - $code_country="'".$societe_vendeuse->country_code."'"; + $code_country = "'".$societe_vendeuse->country_code."'"; } else { - $code_country="'".$mysoc->country_code."'"; // Pour compatibilite ascendente + $code_country = "'".$mysoc->country_code."'"; // Pour compatibilite ascendente } - if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) // If option to have vat for end customer for services is on + if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) // If option to have vat for end customer for services is on { require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; - if (! isInEEC($societe_vendeuse) && (! is_object($societe_acheteuse) || (isInEEC($societe_acheteuse) && ! $societe_acheteuse->isACompany()))) + if (!isInEEC($societe_vendeuse) && (!is_object($societe_acheteuse) || (isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()))) { // We also add the buyer if (is_numeric($type)) { if ($type == 1) // We know product is a service { - $code_country.=",'".$societe_acheteuse->country_code."'"; + $code_country .= ",'".$societe_acheteuse->country_code."'"; } } - elseif (! $idprod) // We don't know type of product + elseif (!$idprod) // We don't know type of product { - $code_country.=",'".$societe_acheteuse->country_code."'"; + $code_country .= ",'".$societe_acheteuse->country_code."'"; } else { - $prodstatic=new Product($this->db); + $prodstatic = new Product($this->db); $prodstatic->fetch($idprod); if ($prodstatic->type == Product::TYPE_SERVICE) // We know product is a service { - $code_country.=",'".$societe_acheteuse->country_code."'"; + $code_country .= ",'".$societe_acheteuse->country_code."'"; } } } } // Now we get list - $num = $this->load_cache_vatrates($code_country); // If no vat defined, return -1 with message into this->error + $num = $this->load_cache_vatrates($code_country); // If no vat defined, return -1 with message into this->error if ($num > 0) { // Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '') if ($defaulttx < 0 || dol_strlen($defaulttx) == 0) { - $tmpthirdparty=new Societe($this->db); - $defaulttx=get_default_tva($societe_vendeuse, (is_object($societe_acheteuse)?$societe_acheteuse:$tmpthirdparty), $idprod); - $defaultnpr=get_default_npr($societe_vendeuse, (is_object($societe_acheteuse)?$societe_acheteuse:$tmpthirdparty), $idprod); + $tmpthirdparty = new Societe($this->db); + $defaulttx = get_default_tva($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod); + $defaultnpr = get_default_npr($societe_vendeuse, (is_object($societe_acheteuse) ? $societe_acheteuse : $tmpthirdparty), $idprod); if (preg_match('/\((.*)\)/', $defaulttx, $reg)) { - $defaultcode=$reg[1]; - $defaulttx=preg_replace('/\s*\(.*\)/', '', $defaulttx); + $defaultcode = $reg[1]; + $defaulttx = preg_replace('/\s*\(.*\)/', '', $defaulttx); } - if (empty($defaulttx)) $defaultnpr=0; + if (empty($defaulttx)) $defaultnpr = 0; } // Si taux par defaut n'a pu etre determine, on prend dernier de la liste. // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant if ($defaulttx < 0 || dol_strlen($defaulttx) == 0) { - if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) $defaulttx = $this->cache_vatrates[$num-1]['txtva']; - else $defaulttx=($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS == 'none' ? '' : $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS); + if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) $defaulttx = $this->cache_vatrates[$num - 1]['txtva']; + else $defaulttx = ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS == 'none' ? '' : $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS); } // Disabled if seller is not subject to VAT - $disabled=false; $title=''; + $disabled = false; $title = ''; if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj == "0") { // Override/enable VAT for expense report regardless of global setting - needed if expense report used for business expenses if (empty($conf->global->OVERRIDE_VAT_FOR_EXPENSE_REPORT)) { - $title=' title="'.$langs->trans('VATIsNotUsed').'"'; - $disabled=true; + $title = ' title="'.$langs->trans('VATIsNotUsed').'"'; + $disabled = true; } } - if (! $options_only) $return.= ''; - $selectedfound=false; + $selectedfound = false; foreach ($this->cache_vatrates as $rate) { // Keep only 0 if seller is not subject to VAT @@ -5241,48 +5241,48 @@ class Form // Define key to use into select list $key = $rate['txtva']; - $key.= $rate['nprtva'] ? '*': ''; - if ($mode > 0 && $rate['code']) $key.=' ('.$rate['code'].')'; + $key .= $rate['nprtva'] ? '*' : ''; + if ($mode > 0 && $rate['code']) $key .= ' ('.$rate['code'].')'; if ($mode < 0) $key = $rate['rowid']; - $return.= ''; + $return .= ''; } - if (! $options_only) $return.= ''; + if (!$options_only) $return .= ''; } else { - $return.= $this->error; + $return .= $this->error; } $this->num = $num; @@ -5319,7 +5319,7 @@ class Form { // phpcs:enable $retstring = $this->selectDate($set_time, $prefix, $h, $m, $empty, $form_name, $d, $addnowlink, $disabled, $fullday, $addplusone, $adddateof); - if (! empty($nooutput)) { + if (!empty($nooutput)) { return $retstring; } print $retstring; @@ -5353,35 +5353,35 @@ class Form */ public function selectDate($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '', $openinghours = '', $stepminutes = 1, $labeladddateof = '') { - global $conf,$langs; + global $conf, $langs; - $retstring=''; + $retstring = ''; - if ($prefix=='') $prefix='re'; - if ($h == '') $h=0; - if ($m == '') $m=0; - $emptydate=0; - $emptyhours=0; - if ($stepminutes<=0 || $stepminutes>30) $stepminutes = 1; - if ($empty == 1) { $emptydate=1; $emptyhours=1; } - if ($empty == 2) { $emptydate=0; $emptyhours=1; } - $orig_set_time=$set_time; + if ($prefix == '') $prefix = 're'; + if ($h == '') $h = 0; + if ($m == '') $m = 0; + $emptydate = 0; + $emptyhours = 0; + if ($stepminutes <= 0 || $stepminutes > 30) $stepminutes = 1; + if ($empty == 1) { $emptydate = 1; $emptyhours = 1; } + if ($empty == 2) { $emptydate = 0; $emptyhours = 1; } + $orig_set_time = $set_time; if ($set_time === '' && $emptydate == 0) { include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $set_time = dol_now('tzuser')-(getServerTimeZoneInt('now')*3600); // set_time must be relative to PHP server timezone + $set_time = dol_now('tzuser') - (getServerTimeZoneInt('now') * 3600); // set_time must be relative to PHP server timezone } // Analysis of the pre-selection date if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) // deprecated usage { // Date format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' - $syear = (! empty($reg[1])?$reg[1]:''); - $smonth = (! empty($reg[2])?$reg[2]:''); - $sday = (! empty($reg[3])?$reg[3]:''); - $shour = (! empty($reg[4])?$reg[4]:''); - $smin = (! empty($reg[5])?$reg[5]:''); + $syear = (!empty($reg[1]) ? $reg[1] : ''); + $smonth = (!empty($reg[2]) ? $reg[2] : ''); + $sday = (!empty($reg[3]) ? $reg[3] : ''); + $shour = (!empty($reg[4]) ? $reg[4] : ''); + $smin = (!empty($reg[5]) ? $reg[5] : ''); } elseif (strval($set_time) != '' && $set_time != -1) { @@ -5416,9 +5416,9 @@ class Form if ($m == 3) $smin = ''; // You can set MAIN_POPUP_CALENDAR to 'eldy' or 'jquery' - $usecalendar='combo'; - if (! empty($conf->use_javascript_ajax) && (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR != "none")) { - $usecalendar = ((empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR == 'eldy')?'jquery':$conf->global->MAIN_POPUP_CALENDAR); + $usecalendar = 'combo'; + if (!empty($conf->use_javascript_ajax) && (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR != "none")) { + $usecalendar = ((empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR == 'eldy') ? 'jquery' : $conf->global->MAIN_POPUP_CALENDAR); } if ($d) @@ -5426,50 +5426,50 @@ class Form // Show date with popup if ($usecalendar != 'combo') { - $formated_date=''; + $formated_date = ''; //print "e".$set_time." t ".$conf->format_date_short; if (strval($set_time) != '' && $set_time != -1) { //$formated_date=dol_print_date($set_time,$conf->format_date_short); - $formated_date=dol_print_date($set_time, $langs->trans("FormatDateShortInput")); // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript + $formated_date = dol_print_date($set_time, $langs->trans("FormatDateShortInput")); // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript } // Calendrier popup version eldy if ($usecalendar == "eldy") { // Zone de saisie manuelle de la date - $retstring.='trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript - $retstring.='>'; + $retstring .= 'trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript + $retstring .= '>'; // Icone calendrier - if (! $disabled) + if (!$disabled) { - $retstring.=''; + $retstring .= ''; } - else $retstring.=''; + else $retstring .= ''; - $retstring.=''."\n"; - $retstring.=''."\n"; - $retstring.=''."\n"; + $retstring .= ''."\n"; + $retstring .= ''."\n"; + $retstring .= ''."\n"; } elseif ($usecalendar == 'jquery') { - if (! $disabled) + if (!$disabled) { // Output javascript for datepicker - $retstring.=""; + $retstring .= ""; } // Zone de saisie manuelle de la date - $retstring.='
'; - $retstring.='trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript - $retstring.='>'; + $retstring .= '
'; + $retstring .= 'trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript + $retstring .= '>'; // Icone calendrier - if (! $disabled) + if (!$disabled) { /* Not required. Managed by option buttonImage of jquery $retstring.=img_object($langs->trans("SelectDate"),'calendarday','id="'.$prefix.'id" class="datecallink"'); @@ -5513,17 +5513,17 @@ class Form } else { - $retstring.=''; + $retstring .= ''; } - $retstring.='
'; - $retstring.=''."\n"; - $retstring.=''."\n"; - $retstring.=''."\n"; + $retstring .= '
'; + $retstring .= ''."\n"; + $retstring .= ''."\n"; + $retstring .= ''."\n"; } else { - $retstring.="Bad value of MAIN_POPUP_CALENDAR"; + $retstring .= "Bad value of MAIN_POPUP_CALENDAR"; } } // Show date with combo selects @@ -5531,55 +5531,55 @@ class Form { //$retstring.='
'; // Day - $retstring.=''; + $retstring .= ''; if ($emptydate || $set_time == -1) { - $retstring.=''; + $retstring .= ''; } - for ($day = 1 ; $day <= 31; $day++) + for ($day = 1; $day <= 31; $day++) { - $retstring.=''; + $retstring .= ''; } - $retstring.=""; + $retstring .= ""; - $retstring.=''; + $retstring .= ''; if ($emptydate || $set_time == -1) { - $retstring.=''; + $retstring .= ''; } // Month - for ($month = 1 ; $month <= 12 ; $month++) + for ($month = 1; $month <= 12; $month++) { - $retstring.='"; + $retstring .= '"; } - $retstring.=""; + $retstring .= ""; // Year if ($emptydate || $set_time == -1) { - $retstring.=''; + $retstring .= ''; } else { - $retstring.=''; + $retstring .= ''; - for ($year = $syear - 10; $year < $syear + 10 ; $year++) + for ($year = $syear - 10; $year < $syear + 10; $year++) { - $retstring.=''; + $retstring .= ''; } - $retstring.="\n"; + $retstring .= "\n"; } //$retstring.='
'; } } - if ($d && $h) $retstring.=($h==2?'
':' '); + if ($d && $h) $retstring .= ($h == 2 ? '
' : ' '); if ($h) { @@ -5589,33 +5589,33 @@ class Form $openinghours = explode(',', $openinghours); $hourstart = $openinghours[0]; $hourend = $openinghours[1]; - if ($hourend<$hourstart) $hourend = $hourstart; + if ($hourend < $hourstart) $hourend = $hourstart; } // Show hour - $retstring.=''; - if ($emptyhours) $retstring.=''; + $retstring .= ''; + if ($emptyhours) $retstring .= ''; for ($hour = $hourstart; $hour < $hourend; $hour++) { - if (strlen($hour) < 2) $hour = "0" . $hour; - $retstring.=''; + if (strlen($hour) < 2) $hour = "0".$hour; + $retstring .= ''; } - $retstring.=''; - if ($m && empty($conf->dol_optimize_smallscreen)) $retstring.=":"; + $retstring .= ''; + if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":"; } if ($m) { // Show minutes - $retstring.=''; - if ($emptyhours) $retstring.=''; - for ($min = 0; $min < 60 ; $min+=$stepminutes) + $retstring .= ''; + if ($emptyhours) $retstring .= ''; + for ($min = 0; $min < 60; $min += $stepminutes) { - if (strlen($min) < 2) $min = "0" . $min; - $retstring.=''; + if (strlen($min) < 2) $min = "0".$min; + $retstring .= ''; } - $retstring.=''; + $retstring .= ''; - $retstring.=''; + $retstring .= ''; } // Add a "Now" link @@ -5623,10 +5623,10 @@ class Form { // Script which will be inserted in the onClick of the "Now" link $reset_scripts = ""; - if ($addnowlink==2) // local computer time + if ($addnowlink == 2) // local computer time { // pad add leading 0 on numbers - $reset_scripts.="Number.prototype.pad = function(size) { + $reset_scripts .= "Number.prototype.pad = function(size) { var s = String(this); while (s.length < (size || 2)) {s = '0' + s;} return s; @@ -5635,14 +5635,14 @@ class Form } // Generate the date part, depending on the use or not of the javascript calendar - if($addnowlink==1) // server time expressed in user time setup + if ($addnowlink == 1) // server time expressed in user time setup { $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date(dol_now(), 'day', 'tzuser').'\');'; $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.dol_print_date(dol_now(), '%d', 'tzuser').'\');'; $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.dol_print_date(dol_now(), '%m', 'tzuser').'\');'; $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.dol_print_date(dol_now(), '%Y', 'tzuser').'\');'; } - elseif($addnowlink==2) + elseif ($addnowlink == 2) { $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(d.toLocaleDateString(\''.str_replace('_', '-', $langs->defaultlang).'\'));'; $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(d.getDate().pad());'; @@ -5665,11 +5665,11 @@ class Form { if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); '; - if($addnowlink==1) + if ($addnowlink == 1) { $reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(\''.dol_print_date(dol_now(), '%H', 'tzuser').'\');'; } - elseif($addnowlink==2) + elseif ($addnowlink == 2) { $reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(d.getHours().pad());'; } @@ -5681,11 +5681,11 @@ class Form { if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); '; - if($addnowlink==1) + if ($addnowlink == 1) { $reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(\''.dol_print_date(dol_now(), '%M', 'tzuser').'\');'; } - elseif($addnowlink==2) + elseif ($addnowlink == 2) { $reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(d.getMinutes().pad());'; } @@ -5694,9 +5694,9 @@ class Form // If reset_scripts is not empty, print the link with the reset_scripts in the onClick if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) { - $retstring.=' '; + $retstring .= ' '; } } @@ -5764,9 +5764,9 @@ class Form // phpcs:enable global $langs; - $retstring=''; + $retstring = ''; - $hourSelected=0; $minSelected=0; + $hourSelected = 0; $minSelected = 0; // Hours if ($iSecond != '') @@ -5777,54 +5777,54 @@ class Form $minSelected = convertSecondToTime($iSecond, 'min'); } - if ($typehour=='select' ) + if ($typehour == 'select') { - $retstring.=''; for ($hour = 0; $hour < 25; $hour++) // For a duration, we allow 24 hours { - $retstring.='"; } - $retstring.=""; + $retstring .= ""; } - elseif ($typehour=='text' || $typehour=='textselect') + elseif ($typehour == 'text' || $typehour == 'textselect') { - $retstring.=''; + $retstring .= ''; } else return 'BadValueForParameterTypeHour'; - if ($typehour!='text') $retstring.=' '.$langs->trans('HourShort'); - else $retstring.=':'; + if ($typehour != 'text') $retstring .= ' '.$langs->trans('HourShort'); + else $retstring .= ':'; // Minutes - if ($minunderhours) $retstring.='
'; - else $retstring.=' '; + if ($minunderhours) $retstring .= '
'; + else $retstring .= ' '; - if ($typehour=='select' || $typehour=='textselect') + if ($typehour == 'select' || $typehour == 'textselect') { - $retstring.=''; + for ($min = 0; $min <= 55; $min = $min + 5) { - $retstring.=''; + $out .= ''; } else { - $out.= ''; + $out .= ''; } } else @@ -6083,18 +6083,18 @@ class Form } $i++; - if (($i % 10) == 0) $out.="\n"; + if (($i % 10) == 0) $out .= "\n"; } } - $out.= ''."\n"; + $out .= ''."\n"; } else { dol_print_error($this->db); } - $this->result=array('nbofelement'=>$num); + $this->result = array('nbofelement'=>$num); if ($outputmode) return $outarray; return $out; @@ -6133,31 +6133,31 @@ class Form //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1; $jsbeautify = 1; - if ($value_as_key) $array=array_combine($array, $array); + if ($value_as_key) $array = array_combine($array, $array); - $out=''; + $out = ''; // Add code for jquery to use multiselect if ($addjscombo && $jsbeautify) { - $minLengthToAutocomplete=0; - $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?(constant('REQUIRE_JQUERY_MULTISELECT')?constant('REQUIRE_JQUERY_MULTISELECT'):'select2'):$conf->global->MAIN_USE_JQUERY_MULTISELECT; + $minLengthToAutocomplete = 0; + $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ? (constant('REQUIRE_JQUERY_MULTISELECT') ?constant('REQUIRE_JQUERY_MULTISELECT') : 'select2') : $conf->global->MAIN_USE_JQUERY_MULTISELECT; // Enhance with select2 - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname); } - $out.='"; + $out .= ""; return $out; } @@ -6251,16 +6251,16 @@ class Form global $delayedhtmlcontent; // TODO Use an internal dolibarr component instead of select2 - if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return ''; + if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) return ''; - $out=''; + $out = ''; - $tmpplugin='select2'; - $outdelayed="\n".' + $tmpplugin = 'select2'; + $outdelayed = "\n".' '; if ($acceptdelayedhtml) { - $delayedhtmlcontent.=$outdelayed; + $delayedhtmlcontent .= $outdelayed; } else { - $out.=$outdelayed; + $out .= $outdelayed; } return $out; } @@ -6353,13 +6353,13 @@ class Form global $delayedhtmlcontent; // TODO Use an internal dolibarr component instead of select2 - if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return ''; + if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) return ''; - $out=''; + $out = ''; $formattedarrayresult = array(); - foreach($array as $key => $value) { + foreach ($array as $key => $value) { $o = new stdClass(); $o->id = $key; $o->text = $value['text']; @@ -6367,13 +6367,13 @@ class Form $formattedarrayresult[] = $o; } - $tmpplugin='select2'; - $outdelayed="\n".' + $tmpplugin = 'select2'; + $outdelayed = "\n".' '; if ($acceptdelayedhtml) { - $delayedhtmlcontent.=$outdelayed; + $delayedhtmlcontent .= $outdelayed; } else { - $out.=$outdelayed; + $out .= $outdelayed; } return $out; } @@ -6477,36 +6477,36 @@ class Form } // Add code for jquery to use multiselect - if (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) + if (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) { - $out.="\n".' + $out .= "\n".' '; + $out .= ''; } // Try also magic suggest - $out .= ''."\n"; + if (is_array($array) && !empty($array)) { - if ($value_as_key) $array=array_combine($array, $array); + if ($value_as_key) $array = array_combine($array, $array); - if (! empty($array)) + if (!empty($array)) { foreach ($array as $key => $value) { - $out.= ''."\n"; + $out .= dol_htmlentitiesbr($newval); + $out .= ''."\n"; } } } - $out.= ''."\n"; + $out .= ''."\n"; return $out; } @@ -6577,44 +6577,44 @@ class Form */ public static function multiSelectArrayWithCheckbox($htmlname, &$array, $varpage) { - global $conf,$langs,$user; + global $conf, $langs, $user; - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) return ''; + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) return ''; - $tmpvar="MAIN_SELECTEDFIELDS_".$varpage; - if (! empty($user->conf->$tmpvar)) + $tmpvar = "MAIN_SELECTEDFIELDS_".$varpage; + if (!empty($user->conf->$tmpvar)) { - $tmparray=explode(',', $user->conf->$tmpvar); - foreach($array as $key => $val) + $tmparray = explode(',', $user->conf->$tmpvar); + foreach ($array as $key => $val) { //var_dump($key); //var_dump($tmparray); - if (in_array($key, $tmparray)) $array[$key]['checked']=1; - else $array[$key]['checked']=0; + if (in_array($key, $tmparray)) $array[$key]['checked'] = 1; + else $array[$key]['checked'] = 0; } } - $lis=''; - $listcheckedstring=''; + $lis = ''; + $listcheckedstring = ''; - foreach($array as $key => $val) + foreach ($array as $key => $val) { /* var_dump($val); var_dump(array_key_exists('enabled', $val)); var_dump(!$val['enabled']);*/ - if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! $val['enabled']) + if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) { - unset($array[$key]); // We don't want this field + unset($array[$key]); // We don't want this field continue; } if ($val['label']) { - $lis.='
  • '; - $listcheckedstring.=(empty($val['checked'])?'':$key.','); + $lis .= '
  • '; + $listcheckedstring .= (empty($val['checked']) ? '' : $key.','); } } - $out =' + $out = '
    '; print ''; - $nboftypesoutput=0; + $nboftypesoutput = 0; - foreach($object->linkedObjects as $objecttype => $objects) + foreach ($object->linkedObjects as $objecttype => $objects) { $tplpath = $element = $subelement = $objecttype; // to display inport button on tpl - $showImportButton=false; - if(!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)){ - $showImportButton=true; + $showImportButton = false; + if (!empty($compatibleImportElementsList) && in_array($element, $compatibleImportElementsList)) { + $showImportButton = true; } $regs = array(); @@ -6762,47 +6762,47 @@ class Form $subelement = $regs[2]; $tplpath = $element.'/'.$subelement; } - $tplname='linkedobjectblock'; + $tplname = 'linkedobjectblock'; // To work with non standard path - if ($objecttype == 'facture') { + if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; - if (empty($conf->facture->enabled)) continue; // Do not show if module disabled + if (empty($conf->facture->enabled)) continue; // Do not show if module disabled } - elseif ($objecttype == 'facturerec') { + elseif ($objecttype == 'facturerec') { $tplpath = 'compta/facture'; $tplname = 'linkedobjectblockForRec'; - if (empty($conf->facture->enabled)) continue; // Do not show if module disabled + if (empty($conf->facture->enabled)) continue; // Do not show if module disabled } - elseif ($objecttype == 'propal') { + elseif ($objecttype == 'propal') { $tplpath = 'comm/'.$element; - if (empty($conf->propal->enabled)) continue; // Do not show if module disabled + if (empty($conf->propal->enabled)) continue; // Do not show if module disabled } - elseif ($objecttype == 'supplier_proposal') { - if (empty($conf->supplier_proposal->enabled)) continue; // Do not show if module disabled + elseif ($objecttype == 'supplier_proposal') { + if (empty($conf->supplier_proposal->enabled)) continue; // Do not show if module disabled } elseif ($objecttype == 'shipping' || $objecttype == 'shipment') { $tplpath = 'expedition'; - if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled + if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled } elseif ($objecttype == 'reception') { $tplpath = 'reception'; - if (empty($conf->reception->enabled)) continue; // Do not show if module disabled + if (empty($conf->reception->enabled)) continue; // Do not show if module disabled } - elseif ($objecttype == 'delivery') { + elseif ($objecttype == 'delivery') { $tplpath = 'livraison'; - if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled + if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled } elseif ($objecttype == 'invoice_supplier') { $tplpath = 'fourn/facture'; } - elseif ($objecttype == 'order_supplier') { + elseif ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; } - elseif ($objecttype == 'expensereport') { + elseif ($objecttype == 'expensereport') { $tplpath = 'expensereport'; } - elseif ($objecttype == 'subscription') { + elseif ($objecttype == 'subscription') { $tplpath = 'adherents'; } @@ -6811,16 +6811,16 @@ class Form // Output template part (modules that overwrite templates must declare this into descriptor) - $dirtpls=array_merge($conf->modules_parts['tpl'], array('/'.$tplpath.'/tpl')); - foreach($dirtpls as $reldir) + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/'.$tplpath.'/tpl')); + foreach ($dirtpls as $reldir) { if ($nboftypesoutput == ($nbofdifferenttypes - 1)) // No more type to show after { global $noMoreLinkedObjectBlockAfter; - $noMoreLinkedObjectBlockAfter=1; + $noMoreLinkedObjectBlockAfter = 1; } - $res=@include dol_buildpath($reldir.'/'.$tplname.'.tpl.php'); + $res = @include dol_buildpath($reldir.'/'.$tplname.'.tpl.php'); if ($res) { $nboftypesoutput++; @@ -6829,7 +6829,7 @@ class Form } } - if (! $nboftypesoutput) + if (!$nboftypesoutput) { print ''; } @@ -6838,7 +6838,7 @@ class Form if (!empty($compatibleImportElementsList)) { - $res=@include dol_buildpath('core/tpl/ajax/objectlinked_lineimport.tpl.php'); + $res = @include dol_buildpath('core/tpl/ajax/objectlinked_lineimport.tpl.php'); } @@ -6861,73 +6861,73 @@ class Form global $conf, $langs, $hookmanager; global $bc, $action; - $linktoelem=''; - $linktoelemlist=''; - $listofidcompanytoscan=''; + $linktoelem = ''; + $linktoelemlist = ''; + $listofidcompanytoscan = ''; - if (! is_object($object->thirdparty)) $object->fetch_thirdparty(); + if (!is_object($object->thirdparty)) $object->fetch_thirdparty(); - $possiblelinks=array(); - if (is_object($object->thirdparty) && ! empty($object->thirdparty->id) && $object->thirdparty->id > 0) + $possiblelinks = array(); + if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) { - $listofidcompanytoscan=$object->thirdparty->id; - if (($object->thirdparty->parent > 0) && ! empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan.=','.$object->thirdparty->parent; - if (($object->fk_project > 0) && ! empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO)) + $listofidcompanytoscan = $object->thirdparty->id; + if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan .= ','.$object->thirdparty->parent; + if (($object->fk_project > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO)) { include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - $tmpproject=new Project($this->db); + $tmpproject = new Project($this->db); $tmpproject->fetch($object->fk_project); - if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) $listofidcompanytoscan.=','.$tmpproject->socid; + if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) $listofidcompanytoscan .= ','.$tmpproject->socid; unset($tmpproject); } - $possiblelinks=array( + $possiblelinks = array( 'propal'=>array('enabled'=>$conf->propal->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('propal').')'), 'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande').')'), 'invoice'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'), 'invoice_template'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToTemplateInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'), - 'contrat'=>array('enabled'=>$conf->contrat->enabled , 'perms'=>1, 'label'=>'LinkToContract', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('contract').')'), + 'contrat'=>array('enabled'=>$conf->contrat->enabled, 'perms'=>1, 'label'=>'LinkToContract', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('contract').')'), 'fichinter'=>array('enabled'=>$conf->ficheinter->enabled, 'perms'=>1, 'label'=>'LinkToIntervention', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('intervention').')'), - 'supplier_proposal'=>array('enabled'=>$conf->supplier_proposal->enabled , 'perms'=>1, 'label'=>'LinkToSupplierProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('supplier_proposal').')'), - 'order_supplier'=>array('enabled'=>$conf->supplier_order->enabled , 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande_fournisseur').')'), - 'invoice_supplier'=>array('enabled'=>$conf->supplier_invoice->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture_fourn').')'), - 'ticket'=>array('enabled'=>$conf->ticket->enabled , 'perms'=>1, 'label'=>'LinkToTicket', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('ticket').')') + 'supplier_proposal'=>array('enabled'=>$conf->supplier_proposal->enabled, 'perms'=>1, 'label'=>'LinkToSupplierProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('supplier_proposal').')'), + 'order_supplier'=>array('enabled'=>$conf->supplier_order->enabled, 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande_fournisseur').')'), + 'invoice_supplier'=>array('enabled'=>$conf->supplier_invoice->enabled, 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture_fourn').')'), + 'ticket'=>array('enabled'=>$conf->ticket->enabled, 'perms'=>1, 'label'=>'LinkToTicket', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('ticket').')') ); } // Can complete the possiblelink array $hookmanager->initHooks(array('commonobject')); - $parameters=array('listofidcompanytoscan' => $listofidcompanytoscan); + $parameters = array('listofidcompanytoscan' => $listofidcompanytoscan); - if (! empty($listofidcompanytoscan)) // If empty, we don't have criteria to scan the object we can link to + if (!empty($listofidcompanytoscan)) // If empty, we don't have criteria to scan the object we can link to { - $reshook=$hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $reshook = $hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook } if (empty($reshook)) { if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) { - $possiblelinks=array_merge($possiblelinks, $hookmanager->resArray); + $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray); } } elseif ($reshook > 0) { if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) { - $possiblelinks=$hookmanager->resArray; + $possiblelinks = $hookmanager->resArray; } } - foreach($possiblelinks as $key => $possiblelink) + foreach ($possiblelinks as $key => $possiblelink) { $num = 0; if (empty($possiblelink['enabled'])) continue; - if (! empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || ! in_array($key, $excludelinksto))) + if (!empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) { - print '
    use_javascript_ajax)?'':' style="display:none"').'>'; + print '
    use_javascript_ajax) ? '' : ' style="display:none"').'>'; $sql = $possiblelink['sql']; $resqllist = $this->db->query($sql); @@ -6945,10 +6945,10 @@ class Form print '
    '; - $num=$this->select_contacts($societe->id, $selected, $htmlname); - if ($num==0) + $num = $this->select_contacts($societe->id, $selected, $htmlname); + if ($num == 0) { - $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress")); + $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress")); print ''.$addcontact.''; } print '
    '.$langs->trans("None").'
    '; print ''; print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; while ($i < $num) { @@ -6956,17 +6956,17 @@ class Form print ''; print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; $i++; } print '
    ' . $langs->trans("Ref") . '' . $langs->trans("RefCustomer") . '' . $langs->trans("AmountHTShort") . '' . $langs->trans("Company") . ''.$langs->trans("Ref").''.$langs->trans("RefCustomer").''.$langs->trans("AmountHTShort").''.$langs->trans("Company").'
    '; - print ''; + print ''; print '' . $objp->ref . '' . $objp->ref_client . '' . price($objp->total_ht) . '' . $objp->name . ''.$objp->ref.''.$objp->ref_client.''.price($objp->total_ht).''.$objp->name.'
    '; - print '
         
    '; + print '
         
    '; print ''; $this->db->free($resqllist); @@ -6979,19 +6979,19 @@ class Form } //$linktoelem.=($linktoelem?'   ':''); - if ($num > 0) $linktoelemlist.='
  • ' . $langs->trans($possiblelink['label']) .' ('.$num.')
  • '; + if ($num > 0) $linktoelemlist .= '
  • '.$langs->trans($possiblelink['label']).' ('.$num.')
  • '; //else $linktoelem.=$langs->trans($possiblelink['label']); - else $linktoelemlist.='
  • ' . $langs->trans($possiblelink['label']) . ' (0)
  • '; + else $linktoelemlist .= '
  • '.$langs->trans($possiblelink['label']).' (0)
  • '; } } if ($linktoelemlist) { - $linktoelem=' + $linktoelem = '