Implemented notification emails when discarding products.
This commit is contained in:
parent
c31c827b36
commit
1f33f73938
@ -6,6 +6,9 @@ $db_user = 'dbname';
|
||||
$db_pass = 'dbpassword';
|
||||
$db_name = 'dbuser';
|
||||
|
||||
# Email subject prefix
|
||||
$email_subject_prefix = "System name: ";
|
||||
|
||||
# Address to use as the sender for reminder emails
|
||||
$sender = 'noreply@example.com';
|
||||
|
||||
@ -15,7 +18,7 @@ $error_address = 'root@example.com';
|
||||
# Discard notifications
|
||||
# If this is set to an email address, the system will send a notification
|
||||
# there each time a product is discarded.
|
||||
#$notify_discard = 'inventory-tracking@example.com';
|
||||
#$discard_notify = 'inventory-tracking@example.com';
|
||||
$discard_notify = false;
|
||||
|
||||
# Directory to save attachments to
|
||||
|
2
cron.php
2
cron.php
@ -7,7 +7,7 @@ require('./include/functions.php');
|
||||
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
$cron = new Cron($sender, $error_address);
|
||||
$cron = new Cron($sender, $error_address, $email_subject_prefix);
|
||||
$cron->run();
|
||||
|
||||
?>
|
||||
|
@ -5,10 +5,11 @@ class Cron {
|
||||
private $error = '';
|
||||
private $kvs;
|
||||
private $ldap;
|
||||
public function __construct($sender, $error) {
|
||||
public function __construct($sender, $error, $prefix) {
|
||||
$this->now = new DateTimeImmutable();
|
||||
$this->sender = $sender;
|
||||
$this->error = $error;
|
||||
$this->subject_prefix = $prefix;
|
||||
$this->warn_time = DateInterval::createFromDateString('3 days');
|
||||
$this->warn_date = $this->now->add($this->warn_time);
|
||||
$this->run_interval = DateInterval::createFromDateString('1 day');
|
||||
@ -108,7 +109,7 @@ class Cron {
|
||||
}
|
||||
|
||||
private function make_receipt_subject($num_new, $num_extended) {
|
||||
$subject = "DSV Helpdesk: ";
|
||||
$subject = $this->subject_prefix;
|
||||
$messages = array();
|
||||
if($num_new > 1) {
|
||||
$messages[] = $num_new." nya";
|
||||
|
@ -68,6 +68,13 @@ class Product extends Entity {
|
||||
$this->update_fields();
|
||||
$this->update_info();
|
||||
$this->update_tags();
|
||||
|
||||
# Global variables are bad, but passing these email properties
|
||||
# around everywhere would be worse
|
||||
global $sender, $notify_discard, $email_subject_prefix;
|
||||
$this->discard_email_address = $notify_discard;
|
||||
$this->email_sender = $sender;
|
||||
$this->email_subject_prefix = $email_subject_prefix;
|
||||
}
|
||||
|
||||
private function update_fields() {
|
||||
@ -272,9 +279,42 @@ class Product extends Entity {
|
||||
bind($update, 'ii', $now, $this->id);
|
||||
execute($update);
|
||||
$this->discardtime = $now;
|
||||
if($this->discard_email_address) {
|
||||
$this->send_discard_email();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function send_discard_email() {
|
||||
$brand = $this->brand;
|
||||
$name = $this->name;
|
||||
$invoice = $this->invoice;
|
||||
$serial = $this->serial;
|
||||
$discardtime = format_date($this->discardtime);
|
||||
|
||||
$subject = $this->email_subject_prefix.$brand.' '.$name.' skrotad';
|
||||
$message = <<<EOF
|
||||
Hej!
|
||||
|
||||
Följande artikel har skrotats i Boka:
|
||||
|
||||
$brand $name, serienummer: $serial, fakturanummer: $invoice
|
||||
|
||||
EOF;
|
||||
try {
|
||||
mb_send_mail($this->discard_email_address,
|
||||
$subject,
|
||||
$message,
|
||||
'From: '.$this->email_sender);
|
||||
} catch(Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
mb_send_mail($this->error,
|
||||
"Kunde inte skicka mail",
|
||||
"Mail kunde inte skickas till "
|
||||
. $this->discard_email_address);
|
||||
}
|
||||
}
|
||||
|
||||
public function toggle_service() {
|
||||
$status = $this->get_status();
|
||||
$now = time();
|
||||
|
Loading…
x
Reference in New Issue
Block a user