NEW Can set email of thirdparty as unique and/or mandatory

This commit is contained in:
Laurent Destailleur 2017-09-02 12:36:22 +02:00
parent 015bc51c43
commit a6a5602572
12 changed files with 230 additions and 176 deletions

View File

@ -73,7 +73,7 @@ if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
if (! empty($conf->margin->enabled)) if (! empty($conf->margin->enabled))
$langs->load('margins'); $langs->load('margins');
$projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0); $projectid = (GETPOST('projectid','int') ? GETPOST('projectid', 'int') : 0);
$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
@ -83,7 +83,7 @@ $confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'alpha'); $cancel = GETPOST('cancel', 'alpha');
$lineid = GETPOST('lineid', 'int'); $lineid = GETPOST('lineid', 'int');
$userid = GETPOST('userid', 'int'); $userid = GETPOST('userid', 'int');
$search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha'); $search_ref = GETPOST('sf_ref','alpha') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
$search_societe = GETPOST('search_societe', 'alpha'); $search_societe = GETPOST('search_societe', 'alpha');
$search_montant_ht = GETPOST('search_montant_ht', 'alpha'); $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
$search_montant_ttc = GETPOST('search_montant_ttc', 'alpha'); $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
@ -430,27 +430,52 @@ if (empty($reshook))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate)))
) )
{ {
$idwarehouse = GETPOST('idwarehouse'); $idwarehouse = GETPOST('idwarehouse','int');
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
// Check parameters // Check parameters
// Check for mandatory prof id (but only if country is than than ours) // Check for mandatory fields defined into setup
if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id) $array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
foreach($array_to_check as $key)
{ {
for ($i = 1; $i <= 6; $i++) $keymin=strtolower($key);
{ $i=(int) preg_replace('/[^0-9]/','',$key);
$idprof_mandatory = 'SOCIETE_IDPROF' . ($i) . '_INVOICE_MANDATORY'; $vallabel=$object->thirdparty->$keymin;
$idprof = 'idprof' . $i;
if (! $object->thirdparty->$idprof && ! empty($conf->global->$idprof_mandatory)) if ($i > 0)
{ {
if (! $error) $langs->load("errors"); if ($object->thirdparty->isACompany())
$error++; {
setEventMessages($langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId' . $i, $object->thirdparty->country_code)), null, 'errors'); // Check for mandatory prof id (but only if country is other than ours)
} if ($mysoc->country_id > 0 && $object->thirdparty->country_id == $mysoc->country_id)
} {
$idprof_mandatory ='SOCIETE_'.$key.'_INVOICE_MANDATORY';
if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
{
$langs->load("errors");
$error++;
setEventMessages($langs->trans('ErrorProdIdIsMandatory', $langs->transcountry('ProfId'.$i, $object->thirdparty->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors');
}
}
}
}
else
{
//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
if ($key == 'EMAIL')
{
// Check for mandatory
if (! empty($conf->global->SOCIETE_EMAIL_INVOICE_MANDATORY) && ! isValidEMail($object->thirdparty->email))
{
$langs->load("errors");
$error++;
setEventMessages($langs->trans("ErrorBadEMail", $object->thirdparty->email).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors');
}
}
}
} }
$qualified_for_stock_change = 0; $qualified_for_stock_change = 0;
@ -4260,7 +4285,7 @@ else if ($id > 0 || ! empty($ref))
print '<br>'; print '<br>';
// Select mail models is same action as presend // Select mail models is same action as presend
if (GETPOST('modelselected')) { if (GETPOST('modelselected','alpha')) {
$action = 'presend'; $action = 'presend';
} }
if ($action != 'prerelance' && $action != 'presend') if ($action != 'prerelance' && $action != 'presend')
@ -4347,7 +4372,7 @@ else if ($id > 0 || ! empty($ref))
// Build document if it not exists // Build document if it not exists
if (! $file || ! is_readable($file)) { if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); $result = $object->generateDocument(GETPOST('model','alpha') ? GETPOST('model','alpha') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) { if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors); dol_print_error($db, $object->error, $object->errors);
exit(); exit();
@ -4367,7 +4392,7 @@ else if ($id > 0 || ! empty($ref))
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db); $formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user')); $formmail->fromtype = (GETPOST('fromtype','alpha')?GETPOST('fromtype','alpha'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){ if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id; $formmail->fromid = $user->id;

View File

@ -33,8 +33,8 @@
// Build doc // Build doc
if ($action == 'builddoc' && $permissioncreate) if ($action == 'builddoc' && $permissioncreate)
{ {
if (is_numeric(GETPOST('model'))) if (is_numeric(GETPOST('model','alpha')))
{ {
$error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model")); $error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
} }
@ -48,18 +48,18 @@ if ($action == 'builddoc' && $permissioncreate)
dol_print_error('Object must have been loaded by a fetch'); dol_print_error('Object must have been loaded by a fetch');
exit; exit;
}*/ }*/
// Save last template used to generate document // Save last template used to generate document
if (GETPOST('model')) if (GETPOST('model','alpha'))
{ {
$object->setDocModel($user, GETPOST('model','alpha')); $object->setDocModel($user, GETPOST('model','alpha'));
} }
// Special case to force bank account // Special case to force bank account
//if (property_exists($object, 'fk_bank')) //if (property_exists($object, 'fk_bank'))
//{ //{
if (GETPOST('fk_bank')) { // this field may come from an external module if (GETPOST('fk_bank','int')) { // this field may come from an external module
$object->fk_bank = GETPOST('fk_bank'); $object->fk_bank = GETPOST('fk_bank','int');
} else if (! empty($object->fk_account)) { } else if (! empty($object->fk_account)) {
$object->fk_bank = $object->fk_account; $object->fk_bank = $object->fk_account;
} }
@ -76,13 +76,13 @@ if ($action == 'builddoc' && $permissioncreate)
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
// To be sure vars is defined // To be sure vars is defined
if (empty($hidedetails)) $hidedetails=0; if (empty($hidedetails)) $hidedetails=0;
if (empty($hidedesc)) $hidedesc=0; if (empty($hidedesc)) $hidedesc=0;
if (empty($hideref)) $hideref=0; if (empty($hideref)) $hideref=0;
if (empty($moreparams)) $moreparams=null; if (empty($moreparams)) $moreparams=null;
$result= $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); $result= $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if ($result <= 0) if ($result <= 0)
{ {

View File

@ -5738,8 +5738,8 @@ function dol_osencode($str)
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
* @param string $key Code or Id to get Id or Code * @param string $key Code or Id to get Id or Code
* @param string $tablename Table name without prefix * @param string $tablename Table name without prefix
* @param string $fieldkey Field for code * @param string $fieldkey Field for search ('code' or 'id')
* @param string $fieldid Field for id * @param string $fieldid Field to get ('id' or 'code')
* @return int <0 if KO, Id of code if OK * @return int <0 if KO, Id of code if OK
* @see $langs->getLabelFromKey * @see $langs->getLabelFromKey
*/ */

View File

@ -167,23 +167,6 @@ if ($action == 'setdoc')
} }
} }
//Activate ProfId
if ($action == 'setprofid')
{
$status = GETPOST('status','alpha');
$idprof="SOCIETE_IDPROF".$value."_UNIQUE";
if (dolibarr_set_const($db, $idprof,$status,'chaine',0,'',$conf->entity) > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
dol_print_error($db);
}
}
//Activate Set ref in list //Activate Set ref in list
if ($action=="setaddrefinlist") { if ($action=="setaddrefinlist") {
$setaddrefinlist = GETPOST('value','int'); $setaddrefinlist = GETPOST('value','int');
@ -214,16 +197,33 @@ if ($action=="setaskforshippingmet") {
} }
} }
//Activate ProfId unique
if ($action == 'setprofid')
{
$status = GETPOST('status','alpha');
$idprof="SOCIETE_".$value."_UNIQUE";
if (dolibarr_set_const($db, $idprof, $status, 'chaine', 0, '', $conf->entity) > 0)
{
//header("Location: ".$_SERVER["PHP_SELF"]);
//exit;
}
else
{
dol_print_error($db);
}
}
//Activate ProfId mandatory //Activate ProfId mandatory
if ($action == 'setprofidmandatory') if ($action == 'setprofidmandatory')
{ {
$status = GETPOST('status','alpha'); $status = GETPOST('status','alpha');
$idprof="SOCIETE_IDPROF".$value."_MANDATORY"; $idprof="SOCIETE_".$value."_MANDATORY";
if (dolibarr_set_const($db, $idprof,$status,'chaine',0,'',$conf->entity) > 0) if (dolibarr_set_const($db, $idprof, $status, 'chaine', 0, '', $conf->entity) > 0)
{ {
header("Location: ".$_SERVER["PHP_SELF"]); //header("Location: ".$_SERVER["PHP_SELF"]);
exit; //exit;
} }
else else
{ {
@ -236,11 +236,11 @@ if ($action == 'setprofidinvoicemandatory')
{ {
$status = GETPOST('status','alpha'); $status = GETPOST('status','alpha');
$idprof="SOCIETE_IDPROF".$value."_INVOICE_MANDATORY"; $idprof="SOCIETE_".$value."_INVOICE_MANDATORY";
if (dolibarr_set_const($db, $idprof,$status,'chaine',0,'',$conf->entity) > 0) if (dolibarr_set_const($db, $idprof, $status, 'chaine', 0, '', $conf->entity) > 0)
{ {
header("Location: ".$_SERVER["PHP_SELF"]); //header("Location: ".$_SERVER["PHP_SELF"]);
exit; //exit;
} }
else else
{ {
@ -298,7 +298,6 @@ print ' <td align="center" width="80">'.$langs->trans("Status").'</td>';
print ' <td align="center" width="60">'.$langs->trans("ShortInfo").'</td>'; print ' <td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
print "</tr>\n"; print "</tr>\n";
$var = true;
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$dir = dol_buildpath($dirroot,0); $dir = dol_buildpath($dirroot,0);
@ -327,7 +326,6 @@ foreach ($dirsociete as $dirroot)
if ($modCodeTiers->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($modCodeTiers->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($modCodeTiers->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; if ($modCodeTiers->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
$var = !$var;
print '<tr class="oddeven">'."\n"; print '<tr class="oddeven">'."\n";
print '<td width="140">'.$modCodeTiers->name.'</td>'."\n"; print '<td width="140">'.$modCodeTiers->name.'</td>'."\n";
print '<td>'.$modCodeTiers->info($langs).'</td>'."\n"; print '<td>'.$modCodeTiers->info($langs).'</td>'."\n";
@ -380,7 +378,6 @@ print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>'; print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
print "</tr>\n"; print "</tr>\n";
$var=true;
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$dir = dol_buildpath($dirroot,0); $dir = dol_buildpath($dirroot,0);
@ -403,7 +400,6 @@ foreach ($dirsociete as $dirroot)
} }
$modCodeCompta = new $file; $modCodeCompta = new $file;
$var = !$var;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.$modCodeCompta->name."</td><td>\n"; print '<td>'.$modCodeCompta->name."</td><td>\n";
@ -474,7 +470,6 @@ print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
print '<td align="center" width="60">'.$langs->trans("Preview").'</td>'; print '<td align="center" width="60">'.$langs->trans("Preview").'</td>';
print "</tr>\n"; print "</tr>\n";
$var=true;
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$dir = dol_buildpath($dirroot.'doc/',0); $dir = dol_buildpath($dirroot.'doc/',0);
@ -507,7 +502,6 @@ foreach ($dirsociete as $dirroot)
if ($modulequalified) if ($modulequalified)
{ {
$var = !$var;
print '<tr class="oddeven"><td width="100">'; print '<tr class="oddeven"><td width="100">';
print $module->name; print $module->name;
print "</td><td>\n"; print "</td><td>\n";
@ -597,76 +591,74 @@ print '<td align="center">'.$langs->trans("MustBeMandatory").'</td>';
print '<td align="center">'.$langs->trans("MustBeInvoiceMandatory").'</td>'; print '<td align="center">'.$langs->trans("MustBeInvoiceMandatory").'</td>';
print "</tr>\n"; print "</tr>\n";
$profid[0][0]=$langs->trans("ProfId1"); $profid['IDPROF1'][0]=$langs->trans("ProfId1");
$profid[0][1]=$langs->transcountry('ProfId1', $mysoc->country_code); $profid['IDPROF1'][1]=$langs->transcountry('ProfId1', $mysoc->country_code);
$profid[1][0]=$langs->trans("ProfId2"); $profid['IDPROF2'][0]=$langs->trans("ProfId2");
$profid[1][1]=$langs->transcountry('ProfId2', $mysoc->country_code); $profid['IDPROF2'][1]=$langs->transcountry('ProfId2', $mysoc->country_code);
$profid[2][0]=$langs->trans("ProfId3"); $profid['IDPROF3'][0]=$langs->trans("ProfId3");
$profid[2][1]=$langs->transcountry('ProfId3', $mysoc->country_code); $profid['IDPROF3'][1]=$langs->transcountry('ProfId3', $mysoc->country_code);
$profid[3][0]=$langs->trans("ProfId4"); $profid['IDPROF4'][0]=$langs->trans("ProfId4");
$profid[3][1]=$langs->transcountry('ProfId4', $mysoc->country_code); $profid['IDPROF4'][1]=$langs->transcountry('ProfId4', $mysoc->country_code);
$profid[4][0]=$langs->trans("ProfId5"); $profid['IDPROF5'][0]=$langs->trans("ProfId5");
$profid[4][1]=$langs->transcountry('ProfId5', $mysoc->country_code); $profid['IDPROF5'][1]=$langs->transcountry('ProfId5', $mysoc->country_code);
$profid[5][0]=$langs->trans("ProfId6"); $profid['IDPROF6'][0]=$langs->trans("ProfId6");
$profid[5][1]=$langs->transcountry('ProfId6', $mysoc->country_code); $profid['IDPROF6'][1]=$langs->transcountry('ProfId6', $mysoc->country_code);
$profid['EMAIL'][0]=$langs->trans("EMail");
$var = true; $profid['EMAIL'][1]=$langs->trans('Email');
$i=0;
$nbofloop=count($profid); $nbofloop=count($profid);
while ($i < $nbofloop) foreach($profid as $key => $val)
{ {
if ($profid[$i][1]!='-') if ($profid[$key][1]!='-')
{ {
$var = !$var;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.$profid[$i][0]."</td><td>\n"; print '<td>'.$profid[$key][0]."</td><td>\n";
print $profid[$i][1]; print $profid[$key][1];
print '</td>'; print '</td>';
$idprof_unique ='SOCIETE_IDPROF'.($i+1).'_UNIQUE'; $idprof_unique ='SOCIETE_'.$key.'_UNIQUE';
$idprof_mandatory ='SOCIETE_IDPROF'.($i+1).'_MANDATORY'; $idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
$idprof_invoice_mandatory ='SOCIETE_IDPROF'.($i+1).'_INVOICE_MANDATORY'; $idprof_invoice_mandatory ='SOCIETE_'.$key.'_INVOICE_MANDATORY';
$verif=(empty($conf->global->$idprof_unique)?false:true); $verif=(empty($conf->global->$idprof_unique)?false:true);
$mandatory=(empty($conf->global->$idprof_mandatory)?false:true); $mandatory=(empty($conf->global->$idprof_mandatory)?false:true);
$invoice_mandatory=(empty($conf->global->$idprof_invoice_mandatory)?false:true); $invoice_mandatory=(empty($conf->global->$idprof_invoice_mandatory)?false:true);
if ($verif) if ($verif)
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setprofid&value='.($i+1).'&status=0">'; print '<td align="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setprofid&value='.$key.'&status=0">';
print img_picto($langs->trans("Activated"),'switch_on'); print img_picto($langs->trans("Activated"),'switch_on');
print '</a></td>'; print '</a></td>';
} }
else else
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setprofid&value='.($i+1).'&status=1">'; print '<td align="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setprofid&value='.$key.'&status=1">';
print img_picto($langs->trans("Disabled"),'switch_off'); print img_picto($langs->trans("Disabled"),'switch_off');
print '</a></td>'; print '</a></td>';
} }
if ($mandatory) if ($mandatory)
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setprofidmandatory&value='.($i+1).'&status=0">'; print '<td align="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setprofidmandatory&value='.$key.'&status=0">';
print img_picto($langs->trans("Activated"),'switch_on'); print img_picto($langs->trans("Activated"),'switch_on');
print '</a></td>'; print '</a></td>';
} }
else else
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setprofidmandatory&value='.($i+1).'&status=1">'; print '<td align="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setprofidmandatory&value='.$key.'&status=1">';
print img_picto($langs->trans("Disabled"),'switch_off'); print img_picto($langs->trans("Disabled"),'switch_off');
print '</a></td>'; print '</a></td>';
} }
if ($invoice_mandatory) if ($invoice_mandatory)
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setprofidinvoicemandatory&value='.($i+1).'&status=0">'; print '<td align="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setprofidinvoicemandatory&value='.$key.'&status=0">';
print img_picto($langs->trans("Activated"),'switch_on'); print img_picto($langs->trans("Activated"),'switch_on');
print '</a></td>'; print '</a></td>';
} }
else else
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setprofidinvoicemandatory&value='.($i+1).'&status=1">'; print '<td align="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setprofidinvoicemandatory&value='.$key.'&status=1">';
print img_picto($langs->trans("Disabled"),'switch_off'); print img_picto($langs->trans("Disabled"),'switch_off');
print '</a></td>'; print '</a></td>';
} }
@ -683,7 +675,6 @@ print load_fiche_titre($langs->trans("Other"),'','');
// Autres options // Autres options
$form=new Form($db); $form=new Form($db);
$var=true;
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';

View File

@ -133,7 +133,7 @@
</tr> </tr>
<tr> <tr>
<td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?></td> <td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?></td>
<td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td> <td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td>
<td><?php echo $langs->trans('Web'); ?></td> <td><?php echo $langs->trans('Web'); ?></td>
<td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td> <td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td>

View File

@ -148,7 +148,7 @@ if ($this->control->tpl['fournisseur']) {
</tr> </tr>
<tr> <tr>
<td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?></td> <td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?></td>
<td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td> <td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td>
<td><?php echo $langs->trans('Web'); ?></td> <td><?php echo $langs->trans('Web'); ?></td>
<td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td> <td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td>

View File

@ -143,7 +143,7 @@
</tr> </tr>
<tr> <tr>
<td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?></td> <td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?></td>
<td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td> <td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td>
<td><?php echo $langs->trans('Web'); ?></td> <td><?php echo $langs->trans('Web'); ?></td>
<td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td> <td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td>

View File

@ -145,7 +145,7 @@ if ($this->control->tpl['fournisseur']) {
</tr> </tr>
<tr> <tr>
<td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_MAIL_REQUIRED?'*':''); ?></td> <td><?php echo $langs->trans('EMail').($conf->global->SOCIETE_EMAIL_MANDATORY?'*':''); ?></td>
<td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td> <td><input type="text" name="email" size="32" value="<?php echo $this->control->tpl['email']; ?>"></td>
<td><?php echo $langs->trans('Web'); ?></td> <td><?php echo $langs->trans('Web'); ?></td>
<td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td> <td><input type="text" name="url" size="32" value="<?php echo $this->control->tpl['url']; ?>"></td>

View File

@ -325,7 +325,6 @@ if (empty($reshook))
$action='create'; $action='create';
} }
if ($action == 'update') if ($action == 'update')
{ {
$ret=$object->fetch($socid); $ret=$object->fetch($socid);
@ -333,7 +332,7 @@ if (empty($reshook))
} }
else $object->canvas=$canvas; else $object->canvas=$canvas;
if (GETPOST("private") == 1) if (GETPOST("private") == 1) // Ask to create a contact
{ {
$object->particulier = GETPOST("private"); $object->particulier = GETPOST("private");
@ -356,14 +355,14 @@ if (empty($reshook))
$object->skype = GETPOST('skype', 'alpha'); $object->skype = GETPOST('skype', 'alpha');
$object->phone = GETPOST('phone', 'alpha'); $object->phone = GETPOST('phone', 'alpha');
$object->fax = GETPOST('fax','alpha'); $object->fax = GETPOST('fax','alpha');
$object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL); $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
$object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL); $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
$object->idprof1 = GETPOST('idprof1', 'alpha'); $object->idprof1 = trim(GETPOST('idprof1', 'alpha'));
$object->idprof2 = GETPOST('idprof2', 'alpha'); $object->idprof2 = trim(GETPOST('idprof2', 'alpha'));
$object->idprof3 = GETPOST('idprof3', 'alpha'); $object->idprof3 = trim(GETPOST('idprof3', 'alpha'));
$object->idprof4 = GETPOST('idprof4', 'alpha'); $object->idprof4 = trim(GETPOST('idprof4', 'alpha'));
$object->idprof5 = GETPOST('idprof5', 'alpha'); $object->idprof5 = trim(GETPOST('idprof5', 'alpha'));
$object->idprof6 = GETPOST('idprof6', 'alpha'); $object->idprof6 = trim(GETPOST('idprof6', 'alpha'));
$object->prefix_comm = GETPOST('prefix_comm', 'alpha'); $object->prefix_comm = GETPOST('prefix_comm', 'alpha');
$object->code_client = GETPOST('code_client', 'alpha'); $object->code_client = GETPOST('code_client', 'alpha');
$object->code_fournisseur = GETPOST('code_fournisseur', 'alpha'); $object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
@ -383,7 +382,9 @@ if (empty($reshook))
$object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
$object->effectif_id = GETPOST('effectif_id', 'int'); $object->effectif_id = GETPOST('effectif_id', 'int');
$object->typent_id = GETPOST('typent_id'); $object->typent_id = GETPOST('typent_id','int');
$object->typent_code = dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type
$object->client = GETPOST('client', 'int'); $object->client = GETPOST('client', 'int');
$object->fournisseur = GETPOST('fournisseur', 'int'); $object->fournisseur = GETPOST('fournisseur', 'int');
@ -461,40 +462,6 @@ if (empty($reshook))
$object->country_code=$tmparray['code']; $object->country_code=$tmparray['code'];
$object->country=$tmparray['label']; $object->country=$tmparray['label'];
} }
// Check for duplicate or mandatory prof id
// Only for companies
if (!($object->particulier || $private))
{
for ($i = 1; $i <= 6; $i++)
{
$slabel="idprof".$i;
$_POST[$slabel]=trim($_POST[$slabel]);
$vallabel=$_POST[$slabel];
if ($vallabel && $object->id_prof_verifiable($i))
{
if($object->id_prof_exists($i,$vallabel,$object->id))
{
$langs->load("errors");
$error++; $errors[] = $langs->transcountry('ProfId'.$i, $object->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel);
$action = (($action=='add'||$action=='create')?'create':'edit');
}
}
// Check for mandatory prof id (but only if country is than than ours)
if ($mysoc->country_id > 0 && $object->country_id == $mysoc->country_id)
{
$idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
{
$langs->load("errors");
$error++;
$errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $object->country_code));
$action = (($action=='add'||$action=='create')?'create':'edit');
}
}
}
}
} }
if (! $error) if (! $error)
@ -512,7 +479,7 @@ if (empty($reshook))
{ {
if ($object->particulier) if ($object->particulier)
{ {
dol_syslog("This thirdparty is a personal people",LOG_DEBUG); dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
$result=$object->create_individual($user); $result=$object->create_individual($user);
if (! $result >= 0) if (! $result >= 0)
{ {
@ -1152,7 +1119,7 @@ else
} }
// Email web // Email web
print '<tr><td>'.fieldLabel('EMail','email').(! empty($conf->global->SOCIETE_MAIL_REQUIRED)?'*':'').'</td>'; print '<tr><td>'.fieldLabel('EMail','email',$conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>'; print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
print '<tr><td>'.fieldLabel('Web','url').'</td>'; print '<tr><td>'.fieldLabel('Web','url').'</td>';
print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>'; print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
@ -1710,7 +1677,7 @@ else
} }
// EMail / Web // EMail / Web
print '<tr><td>'.fieldLabel('EMail','email',(! empty($conf->global->SOCIETE_MAIL_REQUIRED))).'</td>'; print '<tr><td>'.fieldLabel('EMail','email',(! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>'; print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
print '<tr><td>'.fieldLabel('Web','url').'</td>'; print '<tr><td>'.fieldLabel('Web','url').'</td>';
print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>'; print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
@ -1740,7 +1707,7 @@ else
if (($j % 2) == 0) print '<tr>'; if (($j % 2) == 0) print '<tr>';
$idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY'; $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
if(empty($conf->global->$idprof_mandatory)) if (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())
print '<td>'.fieldLabel($idprof,$key).'</td><td>'; print '<td>'.fieldLabel($idprof,$key).'</td><td>';
else else
print '<td><span class="fieldrequired">'.fieldLabel($idprof,$key).'</td><td>'; print '<td><span class="fieldrequired">'.fieldLabel($idprof,$key).'</td><td>';

View File

@ -60,7 +60,7 @@ class ThirdpartyApi extends DolibarrApi
$this->company = new Societe($this->db); $this->company = new Societe($this->db);
$this->customer = new Client($this->db); $this->customer = new Client($this->db);
if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) { if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
static::$FIELDS[] = 'email'; static::$FIELDS[] = 'email';
} }
} }

View File

@ -49,7 +49,7 @@ class Thirdparties extends DolibarrApi
$this->db = $db; $this->db = $db;
$this->company = new Societe($this->db); $this->company = new Societe($this->db);
if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) { if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
static::$FIELDS[] = 'email'; static::$FIELDS[] = 'email';
} }
} }

View File

@ -400,7 +400,7 @@ class Societe extends CommonObject
*/ */
function create($user) function create($user)
{ {
global $langs,$conf; global $langs,$conf,$mysoc;
$error=0; $error=0;
@ -422,14 +422,6 @@ class Societe extends CommonObject
dol_syslog(get_class($this)."::create ".$this->name); dol_syslog(get_class($this)."::create ".$this->name);
// Check parameters
if (! empty($conf->global->SOCIETE_MAIL_REQUIRED) && ! isValidEMail($this->email))
{
$langs->load("errors");
$this->error = $langs->trans("ErrorBadEMail",$this->email);
return -1;
}
$now=dol_now(); $now=dol_now();
$this->db->begin(); $this->db->begin();
@ -438,7 +430,7 @@ class Societe extends CommonObject
if ($this->code_client == -1) $this->get_codeclient($this,0); if ($this->code_client == -1) $this->get_codeclient($this,0);
if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1); if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1);
// Check more parameters // Check more parameters (including mandatory setup
// If error, this->errors[] is filled // If error, this->errors[] is filled
$result = $this->verify(); $result = $this->verify();
@ -524,6 +516,7 @@ class Societe extends CommonObject
} }
} }
/** /**
* Create a contact/address from thirdparty * Create a contact/address from thirdparty
* *
@ -568,6 +561,9 @@ class Societe extends CommonObject
*/ */
function verify() function verify()
{ {
global $conf, $langs, $mysoc;
$error = 0;
$this->errors=array(); $this->errors=array();
$result = 0; $result = 0;
@ -630,6 +626,69 @@ class Societe extends CommonObject
} }
} }
// Check for duplicate or mandatory fields defined into setup
$array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
foreach($array_to_check as $key)
{
$keymin=strtolower($key);
$i=(int) preg_replace('/[^0-9]/','',$key);
$vallabel=$this->$keymin;
if ($i > 0)
{
if ($this->isACompany())
{
// Check for unicity
if ($vallabel && $this->id_prof_verifiable($i))
{
if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
{
$langs->load("errors");
$error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
}
// Check for mandatory prof id (but only if country is other than ours)
if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
{
$idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
{
$langs->load("errors");
$error++;
$this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
}
}
}
else
{
//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
if ($key == 'EMAIL')
{
// Check for unicity
if ($vallabel)
{
if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
{
$langs->load("errors");
$error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
}
// Check for mandatory
if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
{
$langs->load("errors");
$error++;
$this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
}
}
}
if ($error) $result = -4;
return $result; return $result;
} }
@ -719,13 +778,7 @@ class Societe extends CommonObject
$this->code_compta=trim($this->code_compta); $this->code_compta=trim($this->code_compta);
$this->code_compta_fournisseur=trim($this->code_compta_fournisseur); $this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
// Check parameters // Check parameters. More tests are done later in the ->verify()
if (! empty($conf->global->SOCIETE_MAIL_REQUIRED) && ! isValidEMail($this->email))
{
$langs->load("errors");
$this->error = $langs->trans("ErrorBadEMail",$this->email);
return -1;
}
if (! is_numeric($this->client) && ! is_numeric($this->fournisseur)) if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
{ {
$langs->load("errors"); $langs->load("errors");
@ -2581,7 +2634,7 @@ class Societe extends CommonObject
/** /**
* Returns if a profid sould be verified * Returns if a profid sould be verified
* *
* @param int $idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) * @param int $idprof 1,2,3,4,5,6 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm,5=idprof5,6=idprof6)
* @return boolean true , false * @return boolean true , false
*/ */
function id_prof_verifiable($idprof) function id_prof_verifiable($idprof)
@ -2602,6 +2655,12 @@ class Societe extends CommonObject
case 4: case 4:
$ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true); $ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
break; break;
case 5:
$ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
break;
case 6:
$ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
break;
default: default:
$ret=false; $ret=false;
} }
@ -2612,28 +2671,40 @@ class Societe extends CommonObject
/** /**
* Verify if a profid exists into database for others thirds * Verify if a profid exists into database for others thirds
* *
* @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm) * @param string $idprof 'idprof1','idprof2','idprof3','idprof4','idprof5','idprof6','email' (Example: idprof1=siren, idprof2=siret, idprof3=naf, idprof4=rcs/rm)
* @param string $value Value of profid * @param string $value Value of profid
* @param int $socid Id of thirdparty if update * @param int $socid Id of thirdparty to exclude (if update)
* @return boolean true if exists, false if not * @return boolean True if exists, False if not
*/ */
function id_prof_exists($idprof,$value,$socid=0) function id_prof_exists($idprof, $value, $socid=0)
{ {
switch($idprof) $field = $idprof;
switch($idprof) // For backward compatibility
{ {
case 1: case '1':
case 'idprof1':
$field="siren"; $field="siren";
break; break;
case 2: case '2':
case 'idprof2':
$field="siret"; $field="siret";
break; break;
case 3: case '3':
case 'idprof3':
$field="ape"; $field="ape";
break; break;
case 4: case '4':
case 'idprof4':
$field="idprof4"; $field="idprof4";
break; break;
} case '5':
$field="idprof5";
break;
case '6':
$field="idprof6";
break;
}
//Verify duplicate entries //Verify duplicate entries
$sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")"; $sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
@ -2895,7 +2966,7 @@ class Societe extends CommonObject
$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default $isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
if (! empty($this->tva_intra)) $isacompany=1; if (! empty($this->tva_intra)) $isacompany=1;
else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_PRIVATE'))) $isacompany=0; else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_PRIVATE'))) $isacompany=0;
else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_SMALL','TE_MEDIUM','TE_LARGE'))) $isacompany=1; else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_SMALL','TE_MEDIUM','TE_LARGE','TE_GROUP'))) $isacompany=1;
return $isacompany; return $isacompany;
} }