forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaintenanceReminders.php
84 lines (78 loc) · 3.19 KB
/
MaintenanceReminders.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
//this script can be set to run from cron
$AllowAnyone = true;
include('includes/session.php');
include('includes/htmlMimeMail.php');
$sql="SELECT description,
taskdescription,
ADDDATE(lastcompleted,frequencydays) AS duedate,
userresponsible,
email
FROM fixedassettasks
INNER JOIN fixedassets
ON fixedassettasks.assetid=fixedassets.assetid
INNER JOIN www_users
ON fixedassettasks.userresponsible=www_users.userid
WHERE ADDDATE(lastcompleted,frequencydays-10)> CURDATE()
ORDER BY userresponsible";
$result = DB_query($sql);
$LastUserResponsible = '';
while ($myrow = DB_fetch_array($result)){
if (!isset(${'Mail' . $myrow['userresponsible']}) AND IsEmailAddress($myrow['email'])) {
if ($LastUserResponsible!=''){
${'Mail' . $myrow['userresponsible']}->setText($MailText);
$SendResult = ${'Mail' . $myrow['userresponsible']}->send(array($LastUserEmail));
$MailText = _('You have the following maintenance task(s) falling due or over-due:') . "\n";
}
$LastUserResponsible = $myrow['userresponsible'];
$LastUserEmail = $myrow['email'];
${'Mail' . $myrow['userresponsible']} = new htmlMimeMail();
${'Mail' . $myrow['userresponsible']}->setSubject('Maintenance Tasks Reminder');
${'Mail' . $myrow['userresponsible']}->setFrom('Do_not_reply <>');
}
$MailText .= 'Asset' . ': ' . $myrow['description'] . "\nTask: " . $myrow['taskdescription'] . "\nDue: " . ConvertSQLDate($myrow['duedate']);
if (Date1GreaterThanDate2(ConvertSQLDate($myrow['duedate']),Date($_SESSION['DefaultDateFormat']))) {
$MailText .= _('NB: THIS JOB IS OVERDUE');
}
$MailText . "\n\n";
}
if (DB_num_rows($result)>0){
${'Mail' . $LastUserResponsible}->setText($MailText);
$SendResult = ${'Mail' . $LastUserResponsible}->send(array(${'Mail' . $LastUserResponsible}));
}
/* Now do manager emails for overdue jobs */
$sql="SELECT description,
taskdescription,
ADDDATE(lastcompleted,frequencydays) AS duedate,
realname,
manager
FROM fixedassettasks
INNER JOIN fixedassets
ON fixedassettasks.assetid=fixedassets.assetid
INNER JOIN www_users
ON fixedassettasks.userresponsible=www_users.userid
WHERE ADDDATE(lastcompleted,frequencydays)> CURDATE()
ORDER BY manager";
$result = DB_query($sql);
$LastManager = '';
while ($myrow = DB_fetch_array($result)){
if (!isset(${'Mail' . $myrow['userresponsible']})) {
if ($LastUserResponsible!=''){
${'Mail' . $myrow['userresponsible']}->setText($MailText);
$SendResult = ${'Mail' . $myrow['manager']}->send(array($LastManagerEmail));
$MailText = "Your staff have failed to complete the following tasks by the due date:\n";
}
$LastManager = $myrow['manager'];
$LastManagerEmail = $myrow['email'];
${'Mail' . $myrow['manager']} = new htmlMimeMail();
${'Mail' . $myrow['manager']}->setSubject('Overdue Maintenance Tasks Reminder');
${'Mail' . $myrow['manager']}->setFrom('Do_not_reply <>');
}
$MailText .= _('Asset') . ': ' . $myrow['description'] . "\n" . _('Task:') . ' ' . $myrow['taskdescription'] . "\n" . _('Due:') . ' ' . ConvertSQLDate($myrow['duedate']);
$MailText . "\n\n";
}
if (DB_num_rows($result)>0){
${'Mail' . $LastManager}->setText($MailText);
$SendResult = ${'Mail' . $LastManager}->send(array($LastManagerEmail));
}
?>