18include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
19require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
30 public $name =
'DolibarrContractsLinesExpired';
35 public $desc =
'Third parties with expired contract\'s lines';
40 public $require_admin = 0;
45 public $require_module = array(
'contrat');
50 public $enabled =
'isModEnabled("societe")';
55 public $picto =
'company';
104 global
$conf, $langs;
112 if ($productid <= 0) {
113 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService"));
114 $this->errors[] = $this->error;
121 $sql =
"SELECT s.rowid as id, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture as date_start_real, cd.date_fin_validite as date_end, cd.fk_contrat";
122 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"contrat as c";
123 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"product as p";
124 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
125 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing = ".((int) $mailing_id).
")";
126 $sql .=
" AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
127 $sql .=
" AND cd.statut= 4 AND cd.fk_product = p.rowid AND p.rowid = ".((int) $productid);
128 $sql .=
" AND cd.date_fin_validite < '".$this->db->idate($now).
"'";
129 if (empty($this->evenunsubscribe)) {
130 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int)
$conf->entity).
")";
132 $sql .=
" ORDER BY s.email";
135 $result = $this->db->query($sql);
137 $num = $this->db->num_rows($result);
140 dol_syslog(get_class($this).
"::add_to_target ".$num.
" targets found");
144 $obj = $this->db->fetch_object($result);
145 if ($old != $obj->email) {
147 'email' => $obj->email,
148 'lastname' => $obj->name,
151 (
'DateStart='.dol_print_date($this->db->jdate($obj->date_start_real),
'day')).
';'.
152 (
'DateEnd='.dol_print_date($this->db->jdate($obj->date_end),
'day')).
';'.
153 (
'Contract='.$obj->fk_contrat).
';'.
154 (
'ContactLine='.$obj->cdid),
155 'source_url' => $this->url($obj->id),
156 'source_id' => (
int) $obj->id,
157 'source_type' =>
'thirdparty'
167 $this->error = $this->db->lasterror();
173 return parent::addTargetsToDatabase($mailing_id, $cibles);
211 $sql =
"SELECT count(*) as nb";
212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"contrat as c,";
213 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"product as p";
214 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
215 $sql .=
" AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
216 $sql .=
" AND cd.statut= 4 AND cd.fk_product = p.rowid";
218 $sql .=
" AND p.fk_product_type = 1";
220 $sql .=
" AND cd.date_fin_validite < '".$this->db->idate($now).
"'";
221 if (empty($this->evenunsubscribe)) {
222 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int)
$conf->entity).
")";
225 $a = parent::getNbOfRecipients($sql);
238 global $form, $langs, $user;
241 if (!empty($user->socid)) {
242 $socid = $user->socid;
246 $showempty = $langs->trans(
"ProductOrService");
248 $s =
img_picto(
'',
'product',
'class="pictofixedwidth"');
249 $s .= $form->select_produits(
GETPOSTINT(
'productid'),
'productid', $filtertype, 0, 0, -1, 2,
'', 0, array(), $socid, $showempty, 0,
'', 0,
'',
null, 1);
277 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.
$id.
'">'.
img_object(
'',
"company").
'</a>';
$id
Support class for third parties, contacts, members, users or resources.
Parent class of emailing target selectors modules.
Class to offer a selector of emailing targets with Rule 'services expired'.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
__construct($db)
Constructor.
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
url($id)
Can include an URL link on each record provided by selector shown on target page.
add_to_target($mailing_id)
This is the main function that returns the array of emails.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.