Debug v16

This commit is contained in:
Laurent Destailleur 2022-05-16 13:57:11 +02:00
parent c3673bfc3c
commit 84fccb0988
5 changed files with 72 additions and 20 deletions

View File

@ -1953,9 +1953,10 @@ class ExtraFields
* @param string $onlykey Only some keys are filled: * @param string $onlykey Only some keys are filled:
* 'string' => When we make update of only one extrafield ($action = 'update_extras'), calling page can set this to avoid to have other extrafields being reset. * 'string' => When we make update of only one extrafield ($action = 'update_extras'), calling page can set this to avoid to have other extrafields being reset.
* '@GETPOSTISSET' => When we make update of several extrafields ($action = 'update'), calling page can set this to avoid to have fields not into POST being reset. * '@GETPOSTISSET' => When we make update of several extrafields ($action = 'update'), calling page can set this to avoid to have fields not into POST being reset.
* @param int $todefaultifmissing 1=Set value to the default value in database if value is mandatory and missing
* @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example)
*/ */
public function setOptionalsFromPost($extralabels, &$object, $onlykey = '') public function setOptionalsFromPost($extralabels, &$object, $onlykey = '', $todefaultifmissing = 0)
{ {
global $_POST, $langs; global $_POST, $langs;
@ -2015,8 +2016,10 @@ class ExtraFields
|| (!is_array($_POST["options_".$key]) && isset($_POST["options_".$key]) && $this->attributes[$object->table_element]['type'][$key] == 'sellist' && $_POST['options_'.$key] == '0') || (!is_array($_POST["options_".$key]) && isset($_POST["options_".$key]) && $this->attributes[$object->table_element]['type'][$key] == 'sellist' && $_POST['options_'.$key] == '0')
|| (is_array($_POST["options_".$key]) && empty($_POST["options_".$key]))) { || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key]))) {
//print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key];
// Field is not defined. We mark this as a problem. We may fix it later if there is a default value and $todefaultifmissing is set.
$nofillrequired++; $nofillrequired++;
$error_field_required[] = $langs->transnoentitiesnoconv($value); $error_field_required[$key] = $langs->transnoentitiesnoconv($value);
} }
} }
@ -2047,12 +2050,22 @@ class ExtraFields
} }
} }
if (!empty($error_field_required[$key]) && $todefaultifmissing) {
// Value is required but we have a default value and we asked to set empty value to the default value
if (!empty($this->attributes[$object->table_element]['default']) && !is_null($this->attributes[$object->table_element]['default'][$key])) {
$value_key = $this->attributes[$object->table_element]['default'][$key];
unset($error_field_required[$key]);
$nofillrequired--;
}
}
$object->array_options["options_".$key] = $value_key; $object->array_options["options_".$key] = $value_key;
} }
if ($nofillrequired) { if ($nofillrequired) {
$langs->load('errors'); $langs->load('errors');
setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required), null, 'errors'); $this->error = $langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required);
setEventMessages($this->error, null, 'errors');
return -1; return -1;
} else { } else {
return 1; return 1;

View File

@ -509,12 +509,14 @@ function project_admin_prepare_head()
$head[$h][2] = 'attributes_task'; $head[$h][2] = 'attributes_task';
$h++; $h++;
if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
$langs->load("members"); $langs->load("members");
$head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php'; $head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php';
$head[$h][1] = $langs->trans("BlankSubscriptionForm"); $head[$h][1] = $langs->trans("BlankSubscriptionForm");
$head[$h][2] = 'website'; $head[$h][2] = 'website';
$h++; $h++;
}
complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove'); complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove');

View File

@ -265,7 +265,7 @@ print '<td width="80">&nbsp;</td></tr>'."\n";
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td width="80%">'.$langs->trans("ManageOpportunitiesStatus").'</td>'; print '<td width="80%">'.$langs->trans("ManageOpportunitiesStatus").'</td>';
print '<td width="60" class="right">'; print '<td width="60" class="right">';
print ajax_constantonoff("PROJECT_USE_OPPORTUNITIES"); print ajax_constantonoff("PROJECT_USE_OPPORTUNITIES", null, null, 0, 0, 1);
print '</td><td class="right">'; print '</td><td class="right">';
print "</td>"; print "</td>";
print '</tr>'; print '</tr>';

View File

@ -206,16 +206,53 @@ if (empty($reshook) && $action == 'add') {
$errmsg .= $langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Project"))."<br>\n"; $errmsg .= $langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Project"))."<br>\n";
} }
if (!$error) {
$proj = new Project($db); $proj = new Project($db);
$thirdparty = new Societe($db); $thirdparty = new Societe($db);
if (!$error) {
// Search thirdparty and set it if found to the new created project // Search thirdparty and set it if found to the new created project
$result = $thirdparty->fetch(0, '', '', '', '', '', '', '', '', '', $object->email); $result = $thirdparty->fetch(0, '', '', '', '', '', '', '', '', '', $object->email);
if ($result > 0) { if ($result > 0) {
$proj->socid = $thirdparty->id; $proj->socid = $thirdparty->id;
} else {
// Create the prospect
if (GETPOST('societe')) {
$thirdparty->name = GETPOST('societe');
$thirdparty->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname'));
} else {
$thirdparty->name = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname'));
}
$thirdparty->address = GETPOST('address');
$thirdparty->zip = GETPOST('zip');
$thirdparty->town = GETPOST('town');
$thirdparty->country_id = GETPOST('country_id', 'int');
$thirdparty->state_id = GETPOST('state_id');
$thirdparty->client = $thirdparty::PROSPECT;
$thirdparty->code_client = 'auto';
$thirdparty->code_fournisseur = 'auto';
// Fill array 'array_options' with data from the form
$extrafields->fetch_name_optionals_label($thirdparty->table_element);
$ret = $extrafields->setOptionalsFromPost(null, $thirdparty, '', 1);
//var_dump($thirdparty->array_options);exit;
if ($ret < 0) {
$error++;
$errmsg = ($extrafields->error ? $extrafields->error.'<br>' : '').join('<br>', $extrafields->errors);
} }
if (!$error) {
$result = $thirdparty->create($user);
if ($result <= 0) {
$error++;
$errmsg = ($thirdparty->error ? $thirdparty->error.'<br>' : '').join('<br>', $thirdparty->errors);
} else {
$proj->socid = $thirdparty->id;
}
}
}
}
if (!$error) {
// Defined the ref into $defaultref // Defined the ref into $defaultref
$defaultref = ''; $defaultref = '';
$modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON; $modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;

View File

@ -956,7 +956,7 @@ class Societe extends CommonObject
$sql .= ", accountancy_code_sell"; $sql .= ", accountancy_code_sell";
$sql .= ") VALUES ("; $sql .= ") VALUES (";
$sql .= $this->id; $sql .= $this->id;
$sql .= ", ".$conf->entity; $sql .= ", ".((int) $conf->entity);
$sql .= ", '".$this->db->escape($this->accountancy_code_customer)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_customer)."'";
$sql .= ", '".$this->db->escape($this->accountancy_code_supplier)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_supplier)."'";
$sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'";