16include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
17require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
25 public $name =
'DolibarrContractsLinesExpired';
27 public $desc =
'Third parties with expired contract\'s lines';
28 public $require_admin = 0;
30 public $require_module = array(
'contrat');
32 public $enabled =
'isModEnabled("societe")';
37 public $picto =
'company';
39 public $arrayofproducts = array();
53 $this->arrayofproducts = array();
56 $sql =
"SELECT ref FROM ".MAIN_DB_PREFIX.
"product";
57 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
59 $sql .=
" AND fk_product_type = 1";
61 $sql .=
" ORDER BY ref";
62 $result = $this->db->query($sql);
64 $num = $this->db->num_rows($result);
65 dol_syslog(
"dolibarr_services_expired.modules.php:mailing_dolibarr_services_expired ".$num.
" services found");
69 $obj = $this->db->fetch_object($result);
71 $this->arrayofproducts[$i] = $obj->ref;
91 $key =
GETPOST(
'filter',
'int');
98 $this->error =
"Error: You must choose a filter";
99 $this->errors[] = $this->error;
103 $product = $this->arrayofproducts[$key];
108 $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";
109 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"contrat as c";
110 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"product as p";
111 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
112 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
113 $sql .=
" AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
114 $sql .=
" AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$this->db->escape($product).
"'";
115 $sql .=
" AND cd.date_fin_validite < '".$this->db->idate($now).
"'";
116 if (empty($this->evenunsubscribe)) {
117 $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).
")";
119 $sql .=
" ORDER BY s.email";
122 $result = $this->db->query($sql);
124 $num = $this->db->num_rows($result);
127 dol_syslog(get_class($this).
"::add_to_target ".$num.
" targets found");
131 $obj = $this->db->fetch_object($result);
132 if ($old != $obj->email) {
134 'email' => $obj->email,
135 'lastname' => $obj->name,
138 (
'DateStart='.dol_print_date($this->db->jdate($obj->date_start_real),
'day')).
';'.
139 (
'DateEnd='.dol_print_date($this->db->jdate($obj->date_end),
'day')).
';'.
140 (
'Contract='.$obj->fk_contrat).
';'.
141 (
'ContactLine='.$obj->cdid),
142 'source_url' => $this->url($obj->id),
143 'source_id' => $obj->id,
144 'source_type' =>
'thirdparty'
154 $this->error = $this->db->lasterror();
160 return parent::addTargetsToDatabase($mailing_id, $cibles);
198 $sql =
"SELECT count(*) as nb";
199 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"contrat as c";
200 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"product as p";
201 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
202 $sql .=
" AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''";
203 $sql .=
" AND cd.statut= 4 AND cd.fk_product=p.rowid";
204 $sql .=
" AND p.ref IN (".$this->db->sanitize(
"'".join(
"','", $this->arrayofproducts).
"'", 1).
")";
205 $sql .=
" AND cd.date_fin_validite < '".$this->db->idate($now).
"'";
206 if (empty($this->evenunsubscribe)) {
207 $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).
")";
210 $a = parent::getNbOfRecipients($sql);
225 $s =
img_picto(
'',
'product',
'class="pictofixedwidth"').
'<select id="filter_services_expired" name="filter" class="flat">';
226 if (count($this->arrayofproducts)) {
227 $langs->loadLangs(array(
"products"));
228 $s .=
'<option value="-1">'.$langs->trans(
"ProductOrService").
'</option>';
230 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
232 foreach ($this->arrayofproducts as $key => $val) {
233 $s .=
'<option value="'.$key.
'">'.$val.
'</option>';
250 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$id.
'">'.
img_object(
'',
"company").
'</a>';
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.