forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailSalesReport.php
58 lines (49 loc) · 2.32 KB
/
MailSalesReport.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
<?php
/*Now this is not secure so a malicious user could send multiple emails of the report to the intended receipients
The intention is that this script is called from cron at intervals defined with a command like:
/usr/bin/wget http://localhost/web-erp/MailSalesReport.php
The configuration of this script requires the id of the sales analysis report to send
and an array of the receipients */
/*The following three variables need to be modified for the report - the company database to use and the receipients */
/*The Sales report to send */
$_GET['ReportID'] = 2;
$AllowAnyone = true;
include('includes/session.php');
/*The company database to use */
$DatabaseName = $_SESSION['DatabaseName'];
/*The people to receive the emailed report */
$Recipients = GetMailList('SalesAnalysisReportRecipients');
if (sizeOf($Recipients) == 0) {
$Title = _('Inventory Valuation') . ' - ' . _('Problem Report');
include('includes/header.php');
prnMsg( _('There are no members of the Sales Analysis Report Recipients email group'), 'warn');
include('includes/footer.php');
exit;
}
include ('includes/ConstructSQLForUserDefinedSalesReport.inc');
include ('includes/PDFSalesAnalysis.inc');
include('includes/htmlMimeMail.php');
$mail = new htmlMimeMail();
if ($Counter >0){ /* the number of lines of the sales report is more than 0 ie there is a report to send! */
$pdf->Output($_SESSION['reports_dir'] .'/SalesAnalysis_' . date('Y-m-d') . '.pdf','F'); //save to file
$pdf->__destruct();
$attachment = $mail->getFile($_SESSION['reports_dir'] . '/SalesAnalysis_' . date('Y-m-d') . '.pdf');
$mail->setText(_('Please find herewith sales report'));
$mail->SetSubject(_('Sales Analysis Report'));
$mail->addAttachment($attachment, 'SalesAnalysis_' . date('Y-m-d') . '.pdf', 'application/pdf');
if($_SESSION['SmtpSetting']==0){
$mail->setFrom($_SESSION['CompanyRecord']['coyname'] . '<' . $_SESSION['CompanyRecord']['email'] . '>');
$result = $mail->send($Recipients);
}else{
$result = SendmailBySmtp($mail,$Recipients);
}
} else {
$mail->setText(_('Error running automated sales report number') . ' ' . $ReportID);
if($_SESSION['SmtpSetting']==0){
$mail->setFrom($_SESSION['CompanyRecord']['coyname'] . '<' . $_SESSION['CompanyRecord']['email'] . '>');
$result = $mail->send($Recipients);
}else{
$result = SendmailBySmtp($mail,$Recipients);
}
}
?>