This commit is contained in:
ptibogxiv 2022-08-29 14:46:26 +02:00
parent 0ee2fce9a2
commit 9d74c5c776
3 changed files with 151 additions and 6 deletions

View File

@ -81,7 +81,7 @@ class mailing_thirdparties extends MailingTargets
$sql .= " AND s.entity IN (".getEntity('societe').")";
$sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
if (GETPOST('default_lang', 'alpha')) {
$sql .= " AND s.default_lang LIKE '".$this->db->escape(GETPOST('default_lang', 'alpha'))."%'";
//$sql .= " AND s.default_lang LIKE '".$this->db->escape(GETPOST('default_lang', 'alpha'))."%'";
}
} else {
$addFilter = "";
@ -226,7 +226,7 @@ class mailing_thirdparties extends MailingTargets
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE s.email <> ''";
$sql .= " AND s.entity IN (".getEntity('societe').")";
$sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = s.email) = 0";
// La requete doit retourner un champ "nb" pour etre comprise par parent::getNbOfRecipients
return parent::getNbOfRecipients($sql);
}
@ -316,11 +316,13 @@ class mailing_thirdparties extends MailingTargets
$s .= '</select>';
$s .= ajax_combobox("filter_status_thirdparties");
if (!empty($conf->global->MAIN_MULTILANGS)) {
// Choose language
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
$formadmin = new FormAdmin($this->db);
$s .= '<span class="opacitymedium">'.$langs->trans("DefaultLang").':</span> ';
$s .= $formadmin->select_language($langs->getDefaultLang(1), 'filter_lang_thirdparties', 0, null, 1, 0, 0, '', 0, 0, 0, null, 1);
}
return $s;
}

View File

@ -253,6 +253,7 @@ if (empty($reshook)) {
// Update
$result = $object->update($object->id, $user, 0, 1, 1, 'merge');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
@ -465,6 +466,7 @@ if (empty($reshook)) {
$object->phone = GETPOST('phone', 'alpha');
$object->fax = GETPOST('fax', 'alpha');
$object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
$object->no_email = GETPOST("no_email", "int");
$object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
$object->idprof1 = trim(GETPOST('idprof1', 'alphanohtml'));
$object->idprof2 = trim(GETPOST('idprof2', 'alphanohtml'));
@ -600,6 +602,16 @@ if (empty($reshook)) {
$result = $object->create($user);
if (empty($error) && !empty($conf->mailing->enabled) && !empty($object->email)) {
// Add mass emailing flag into table mailing_unsubscribe
$result = $object->setNoEmail($object->no_email);
if ($result < 0) {
$error++;
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
$action = 'create';
}
}
if ($result >= 0) {
if ($object->particulier) {
dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
@ -757,6 +769,24 @@ if (empty($reshook)) {
$result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
if ($result > 0) {
// Update mass emailing flag into table mailing_unsubscribe
if (GETPOSTISSET('no_email') && $object->email) {
$no_email = GETPOST('no_email', 'int');
$result = $object->setNoEmail($no_email);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit';
}
}
$action = 'view';
} else {
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit';
}
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
@ -1590,6 +1620,35 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'"></td></tr>';
// Unsubscribe
if (!empty($conf->mailing->enabled)) {
if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
print "\n".'<script type="text/javascript">'."\n";
print '$(document).ready(function () {
$("#email").keyup(function() {
if ($(this).val()!="") {
$(".noemail").addClass("fieldrequired");
} else {
$(".noemail").removeClass("fieldrequired");
}
});
})'."\n";
print '</script>'."\n";
}
if (!GETPOSTISSET("no_email") && !empty($object->email)) {
$result = $object->getNoEmail();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
print '<tr>';
print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>';
print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
print '</td>';
print '</tr>';
}
// Social networks
if (!empty($conf->socialnetworks->enabled)) {
foreach ($socialnetworks as $key => $value) {
@ -1931,6 +1990,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
$object->phone = GETPOST('phone', 'alpha');
$object->fax = GETPOST('fax', 'alpha');
$object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
$object->no_email = GETPOST("no_email", "int");
$object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
$object->capital = GETPOST('capital', 'alphanohtml');
$object->idprof1 = GETPOST('idprof1', 'alphanohtml');
@ -2272,10 +2332,58 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '<td>'.img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"').' <input type="text" name="fax" id="fax" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $object->fax).'"></td></tr>';
// EMail / Web
print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL), $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
print '<td colspan="3">'.img_picto('', 'object_email', 'class="pictofixedwidth"').' <input type="text" name="email" id="email" class="maxwidth200onsmartphone maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL) : $object->email).'"></td></tr>';
print '<tr><td>'.$form->editfieldkey('Web', 'url', GETPOST('url', 'alpha'), $object, 0).'</td>';
print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" name="url" id="url" class="maxwidth200onsmartphone maxwidth500 widthcentpercentminusx " value="'.(GETPOSTISSET('url') ?GETPOST('url', 'alpha') : $object->url).'"></td></tr>';
print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" name="url" id="url" class="maxwidth200onsmartphone maxwidth300 widthcentpercentminusx " value="'.(GETPOSTISSET('url') ?GETPOST('url', 'alpha') : $object->url).'"></td>';
// EMail
print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
print '<td>';
print img_picto('', 'object_email');
print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="'.(GETPOSTISSET('email') ?GETPOST('email', 'alpha') : $object->email).'"></td>';
if (!empty($conf->mailing->enabled)) {
$langs->load("mails");
print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
print '<td>'.$object->getNbOfEMailings().'</td>';
} else {
print '<td colspan="2"></td>';
}
print '</tr>';
// Unsubscribe
if (!empty($conf->mailing->enabled)) {
if ($conf->use_javascript_ajax && isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
print "\n".'<script type="text/javascript">'."\n";
print '
jQuery(document).ready(function () {
function init_check_no_email(input) {
if (input.val()!="") {
$(".noemail").addClass("fieldrequired");
} else {
$(".noemail").removeClass("fieldrequired");
}
}
$("#email").keyup(function() {
init_check_no_email($(this));
});
init_check_no_email($("#email"));
})'."\n";
print '</script>'."\n";
}
if (!GETPOSTISSET("no_email") && !empty($object->email)) {
$result = $object->getNoEmail();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
print '<tr>';
print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>';
$useempty = (isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, $useempty);
print '</td>';
print '</tr>';
}
// Social network
if (!empty($conf->socialnetworks->enabled)) {
@ -2931,6 +3039,28 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
}
print '</td></tr>';
// Email
if (!empty($conf->mailing->enabled)) {
$langs->load("mails");
print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
}
// Unsubscribe opt-out
if (!empty($conf->mailing->enabled)) {
$result = $object->getNoEmail();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
if ($object->email) {
print yn($object->no_email);
} else {
print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
}
print '</td></tr>';
}
// Default language
if (!empty($conf->global->MAIN_MULTILANGS)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';

View File

@ -230,6 +230,9 @@ class Thirdparties extends DolibarrApi
$obj = $this->db->fetch_object($result);
$soc_static = new Societe($this->db);
if ($soc_static->fetch($obj->rowid)) {
if (isModEnabled('mailing')) {
$soc_static->getNoEmail();
}
$obj_ret[] = $this->_cleanObjectDatas($soc_static);
}
$i++;
@ -263,6 +266,9 @@ class Thirdparties extends DolibarrApi
if ($this->company->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
}
if (isModEnabled('mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
$this->company->setNoEmail($this->company->no_email);
}
return $this->company->id;
}
@ -296,7 +302,11 @@ class Thirdparties extends DolibarrApi
$this->company->$field = $value;
}
if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) {
if (isModEnabled('mailing') && !empty($this->company->email) && isset($this->company->no_email)) {
$this->company->setNoEmail($this->company->no_email);
}
if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update', 1)) {
return $this->get($id);
}
@ -1876,6 +1886,9 @@ class Thirdparties extends DolibarrApi
if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login.' on this thirdparty');
}
if (isModEnabled('mailing')) {
$this->company->getNoEmail();
}
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice