mirror of
https://github.com/rickbarrette/redmine_qbo_reminders.git
synced 2026-11-17 13:00:36 -05:00
New plugin: email customers appointment reminders
Reminders for redmine_qbo_calendar appointments, to the customer's email in QuickBooks, sent from your own mailbox through Google Workspace's SMTP relay (or Gmail SMTP with an app password, or Redmine's email settings). - Schedule: N days before at a set time, only within sending hours, not within N hours of the appointment; rescheduling sends one for the new time - Plain text + HTML from an editable template with placeholders and sections, calendar (.ics) attachment, Message-ID on the sending domain - Each reminder claimed in the database before sending (no duplicates across processes); failures retried 3 times - Appointment page: status and Send now / Send again; customer page: turn reminders off; settings: test email, recent reminders, send due now - Runs on page loads every 10 minutes, or from cron via rake redmine:appointment_reminders:send - README covers Google Workspace setup and SPF/DKIM/DMARC Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
28 files changed
+1482
No files matched your search
@@ -0,0 +1,5 @@
|
||||
.bundle
|
||||
.config
|
||||
.dockerrc
|
||||
.vscode
|
||||
Gemfile.lock
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2026 Rick Barrette
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,93 @@
|
||||
# Redmine QBO Reminders
|
||||
|
||||
Emails customers a reminder before their appointments in [redmine_qbo_calendar](https://github.com/rickbarrette/redmine_qbo_calendar), at the email address on their QuickBooks Online customer ([redmine_qbo](https://github.com/rickbarrette/redmine_qbo)). The email comes from your own mailbox (for example sales@yourdomain.com through Google Workspace), so there's nothing extra to pay for, and customers can reply to confirm or reschedule.
|
||||
|
||||
* **When**: a set number of days before the appointment at a set time (default: the day before at 4 PM), only between set hours (default 8 AM–8 PM), and not within a set number of hours of the appointment (default 2). An appointment booked after its reminder time gets one right away. Rescheduling an appointment sends a reminder for the new time.
|
||||
* **Which**: appointments with the chosen statuses (default: Scheduled), with a customer who has an email address in QuickBooks and hasn't had reminders turned off.
|
||||
* **What**: a short plain-text and HTML email in your words (placeholders for the customer, vehicle, day, time and shop details), with the appointment attached as a calendar file.
|
||||
* **Appointment page**: whether the reminder was sent (when, to whom), when it will be, or why it won't be, with **Send now** / **Send again**.
|
||||
* **Customer page**: turn reminders off (or back on) for a customer.
|
||||
* **Settings page**: send a test email with the settings as they are on the page, see recent reminders (and why any failed), and send due reminders now.
|
||||
|
||||
Each reminder is recorded before it's sent, so a customer never gets two for the same appointment time, even with several Redmine processes. A failed send is tried again (3 times in all); it can always be sent from the appointment page.
|
||||
|
||||
## Requirements
|
||||
|
||||
* Redmine 7
|
||||
* redmine_qbo and redmine_qbo_calendar 2026.11.0 or later
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
cd /path/to/redmine/plugins
|
||||
git clone https://github.com/rickbarrette/redmine_qbo_reminders.git
|
||||
cd ..
|
||||
bundle exec rake redmine:plugins:migrate
|
||||
```
|
||||
|
||||
Restart Redmine, then set it up under **Administration » Plugins » Redmine QBO Reminders plugin » Configure**, and give the roles that should send reminders or turn them off for customers the **Send appointment reminders** permission.
|
||||
|
||||
## Sending through Google Workspace
|
||||
|
||||
Reminders go out through Google's mail servers as your mailbox, which keeps them out of spam folders far better than mail sent straight from the Redmine server. Two ways, both included with Google Workspace:
|
||||
|
||||
**SMTP relay service (recommended).** In the Google Admin console: Apps » Google Workspace » Gmail » Routing » **SMTP relay service** » Configure:
|
||||
|
||||
* Allowed senders: *Only addresses in my domains*
|
||||
* Authentication: *Require SMTP Authentication* (and/or *Only accept mail from the specified IP addresses* with your server's public IP)
|
||||
* Encryption: *Require TLS encryption*
|
||||
|
||||
Then in the plugin's settings: SMTP server `smtp-relay.gmail.com`, port `587`, domain your domain, and the mailbox's address and an **app password** (or leave both blank when the relay allows your server's IP). The relay allows up to 10,000 messages a day per user.
|
||||
|
||||
**Gmail SMTP.** SMTP server `smtp.gmail.com`, port `587`, with the mailbox's address and an app password. Simpler (no Admin console change), with lower daily limits, and each reminder also lands in the mailbox's Sent folder.
|
||||
|
||||
App passwords: the mailbox needs 2-Step Verification; then Google Account » Security » **App passwords**. Google no longer accepts the account's regular password over SMTP.
|
||||
|
||||
Or choose **Redmine's email settings** to send through whatever `config/configuration.yml` uses.
|
||||
|
||||
The password is kept in Redmine's plugin settings (in the database), like other plugin settings, and is visible to administrators on the settings page.
|
||||
|
||||
## Staying out of spam
|
||||
|
||||
1. **DNS.** Make sure your domain has:
|
||||
* **SPF**: a TXT record including Google, e.g. `v=spf1 include:_spf.google.com ~all` (one SPF record per domain; add the include to the one you have).
|
||||
* **DKIM**: Admin console » Apps » Google Workspace » Gmail » **Authenticate email**: generate a 2048-bit key, publish the TXT record it shows, then click *Start authentication*.
|
||||
* **DMARC**: a TXT record at `_dmarc.yourdomain.com`, e.g. `v=DMARC1; p=none; rua=mailto:you@yourdomain.com`. Move to `p=quarantine` once the reports look clean.
|
||||
|
||||
Check by sending a test (settings page) to a Gmail address and choosing **Show original**: SPF, DKIM and DMARC should all say PASS.
|
||||
2. **From address** on your domain, the same mailbox you send through, with your shop's name as the From name.
|
||||
3. **Keep the message personal and short.** The default asks customers to reply to confirm; replies help your reputation. Avoid link shorteners and image-only mail.
|
||||
4. Reminders are transactional, so they don't need an unsubscribe link; turning reminders off on the customer page covers customers who'd rather not get them.
|
||||
5. Optional: [Google Postmaster Tools](https://postmaster.google.com) shows how Gmail sees your domain once you send more.
|
||||
|
||||
## Running on schedule
|
||||
|
||||
With **Check on page loads** on (the default), Redmine looks for due reminders every 10 minutes while anyone is using it. That's enough when Redmine is open during business hours.
|
||||
|
||||
To send them whether or not anyone is using Redmine, run the rake task every 15 minutes from cron:
|
||||
|
||||
```
|
||||
*/15 * * * * cd /path/to/redmine && bundle exec rake redmine:appointment_reminders:send RAILS_ENV=production
|
||||
```
|
||||
|
||||
In Docker, from the host's crontab:
|
||||
|
||||
```
|
||||
*/15 * * * * docker exec <redmine container> bundle exec rake redmine:appointment_reminders:send RAILS_ENV=production
|
||||
```
|
||||
|
||||
(Use the `RAILS_ENV` your Redmine runs in.) The task is safe to run alongside page-load checks.
|
||||
|
||||
## Message placeholders
|
||||
|
||||
`{{first_name}}` (QuickBooks first name, else the first word of the name), `{{customer}}`, `{{day}}` (Tuesday, November 3), `{{date}}` (11/03/2026), `{{time}}` (9:00 AM), `{{vehicle}}`, `{{subject}}` (the appointment's subject), `{{shop_name}}`, `{{shop_phone}}`, `{{shop_address}}`.
|
||||
|
||||
`{{#vehicle}}…{{/vehicle}}` shows its text only when the appointment has a vehicle, and `{{^vehicle}}…{{/vehicle}}` only when it doesn't (any placeholder works). Lines left empty by missing values are dropped.
|
||||
|
||||
## Time zone
|
||||
|
||||
Appointment times are read as entered, in the **Shop time zone** setting (default Eastern), whatever time zone the server runs in.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
@@ -0,0 +1,75 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# Sending a reminder from an appointment, turning reminders on or off for a customer, and (administrators)
|
||||
# sending a test email or running the reminders from the settings page
|
||||
class AppointmentRemindersController < ApplicationController
|
||||
|
||||
before_action :authorize_global, only: [:send_now, :opt_out, :opt_in]
|
||||
before_action :require_admin, only: [:test, :run]
|
||||
|
||||
def send_now
|
||||
appointment = CustomerAppointment.find(params[:id])
|
||||
reminder = RedmineQboReminders::Sender.new.send_now(appointment, user: User.current)
|
||||
if reminder.nil?
|
||||
flash[:error] = l(:error_reminder_no_email)
|
||||
elsif reminder.sent?
|
||||
flash[:notice] = l(:notice_reminder_sent, email: reminder.email)
|
||||
else
|
||||
flash[:error] = l(:error_reminder_failed, error: reminder.error.to_s)
|
||||
end
|
||||
redirect_to customer_appointment_path(appointment)
|
||||
end
|
||||
|
||||
def opt_out
|
||||
customer = Customer.find(params[:customer_id])
|
||||
ReminderOptOut.find_or_create_by!(customer_id: customer.id) { |o| o.user = User.current }
|
||||
flash[:notice] = l(:notice_reminders_off, customer: customer.name)
|
||||
redirect_back_or_default customer_path(customer)
|
||||
end
|
||||
|
||||
def opt_in
|
||||
customer = Customer.find(params[:customer_id])
|
||||
ReminderOptOut.where(customer_id: customer.id).delete_all
|
||||
flash[:notice] = l(:notice_reminders_on, customer: customer.name)
|
||||
redirect_back_or_default customer_path(customer)
|
||||
end
|
||||
|
||||
# A sample reminder to the address given (or the administrator's own), with the settings as they are on
|
||||
# the settings page, saved or not (its Send test email button submits the form here)
|
||||
def test
|
||||
settings = RedmineQboReminders::Settings.current
|
||||
if params[:settings].respond_to?(:to_unsafe_h)
|
||||
settings = RedmineQboReminders::Settings.new(Setting.plugin_redmine_qbo_reminders.to_h.merge(params[:settings].to_unsafe_h))
|
||||
end
|
||||
email = params[:email].to_s.strip.presence || User.current.mail
|
||||
starts_at = settings.zone.now.beginning_of_day + 1.day + 9.hours
|
||||
message = RedmineQboReminders::Message.new(
|
||||
settings: settings, starts_at: starts_at, uid: "test-#{Time.now.to_i}@#{settings.mail_domain}",
|
||||
values: { 'customer' => 'Jane Doe', 'first_name' => 'Jane', 'vehicle' => '2022 Jeep Gladiator',
|
||||
'subject' => 'Sample appointment' }.merge(RedmineQboReminders::Message.when_values(starts_at))
|
||||
)
|
||||
AppointmentReminderMailer.reminder(message, email).deliver_now
|
||||
flash[:notice] = l(:notice_reminder_test_sent, email: email)
|
||||
rescue StandardError => e
|
||||
flash[:error] = l(:error_reminder_failed, error: "#{e.class}: #{e.message}")
|
||||
ensure
|
||||
redirect_to plugin_settings_path(:redmine_qbo_reminders)
|
||||
end
|
||||
|
||||
def run
|
||||
if RedmineQboReminders::Settings.current.enabled?
|
||||
flash[:notice] = l(:notice_reminders_run, result: RedmineQboReminders::Sender.run.to_s)
|
||||
else
|
||||
flash[:error] = l(:error_reminders_disabled)
|
||||
end
|
||||
redirect_to plugin_settings_path(:redmine_qbo_reminders)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# Sends the reminders that are due (see RedmineQboReminders::Sender)
|
||||
class AppointmentRemindersJob < ActiveJob::Base
|
||||
queue_as :default
|
||||
|
||||
def perform
|
||||
RedmineQboReminders::Sender.run
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,36 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
require 'securerandom'
|
||||
|
||||
# The reminder email: plain text and HTML, with the appointment as a calendar file. Sent through the SMTP
|
||||
# server in the plugin's settings (e.g. Google Workspace's SMTP relay), or through Redmine's own email
|
||||
# settings. Not Redmine's Mailer, which would add Redmine's From address, headers and footer.
|
||||
class AppointmentReminderMailer < ActionMailer::Base
|
||||
layout false
|
||||
# So a refused message is recorded as failed (and retried), not as sent
|
||||
self.raise_delivery_errors = true
|
||||
|
||||
# message: a RedmineQboReminders::Message
|
||||
def reminder(message, email, settings: message.settings)
|
||||
if (ics = message.ics)
|
||||
attachments['appointment.ics'] = { mime_type: 'text/calendar; method=PUBLISH; charset=UTF-8', content: ics }
|
||||
end
|
||||
# A Message-ID on the sending domain, rather than the server's host name
|
||||
headers['Message-ID'] = "<reminder.#{Time.now.to_i}.#{SecureRandom.hex(6)}@#{settings.mail_domain}>"
|
||||
|
||||
options = { to: email, from: settings.from, subject: message.subject }
|
||||
options[:reply_to] = settings.reply_to if settings.reply_to
|
||||
mail(options.merge(settings.delivery_options)) do |format|
|
||||
format.text { render plain: message.text }
|
||||
format.html { render html: message.html.html_safe }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# A reminder emailed (or being emailed, or that failed) for an appointment at a given time
|
||||
class AppointmentReminder < ActiveRecord::Base
|
||||
STATUSES = %w[pending sent failed].freeze
|
||||
# Tries before a failing reminder is given up on (it can still be sent from the appointment page)
|
||||
MAX_ATTEMPTS = 3
|
||||
# A "pending" row older than this was left by a run that died mid-send, and may be tried again
|
||||
STALE_AFTER = 30 * 60
|
||||
|
||||
belongs_to :customer_appointment
|
||||
belongs_to :sent_by, class_name: 'User', optional: true
|
||||
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
|
||||
scope :recent, -> { order(created_at: :desc) }
|
||||
|
||||
def sent?
|
||||
status == 'sent'
|
||||
end
|
||||
|
||||
def failed?
|
||||
status == 'failed'
|
||||
end
|
||||
|
||||
def stale?
|
||||
status == 'pending' && updated_at && updated_at < Time.now - STALE_AFTER
|
||||
end
|
||||
|
||||
# Worth another try on schedule
|
||||
def retry?
|
||||
(failed? || stale?) && attempts < MAX_ATTEMPTS
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# A customer who doesn't get appointment reminders
|
||||
class ReminderOptOut < ActiveRecord::Base
|
||||
belongs_to :customer
|
||||
belongs_to :user, optional: true
|
||||
|
||||
validates :customer_id, presence: true, uniqueness: true
|
||||
|
||||
def self.opted_out?(customer)
|
||||
customer.present? && exists?(customer_id: customer.id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,40 @@
|
||||
<%# The reminder's status on an appointment's page (redmine_qbo_calendar's show_customer_appointment hook) %>
|
||||
<% appointment = local_assigns[:appointment] %>
|
||||
<% if appointment %>
|
||||
<% rs = RedmineQboReminders::ReminderStatus.for(appointment) %>
|
||||
<% can_send = User.current.allowed_to?(:send_appointment_reminders, nil, global: true) %>
|
||||
<div class="box appointment-reminder appointment-reminder-<%= rs.state %>">
|
||||
<i class="fa-regular fa-envelope"></i>
|
||||
<strong><%= l(:label_appointment_reminder) %>:</strong>
|
||||
<% text = case rs.state
|
||||
when :sent then l(:text_reminder_sent, time: format_time(rs.reminder.sent_at), email: rs.email)
|
||||
when :sending then l(:text_reminder_sending, email: rs.email)
|
||||
when :failed then l(:text_reminder_failed_retry, email: rs.email)
|
||||
when :given_up then l(:text_reminder_failed, email: rs.email)
|
||||
when :scheduled then l(:text_reminder_scheduled, time: format_time(rs.at), email: rs.email)
|
||||
when :off then l(:text_reminder_off)
|
||||
when :opted_out then l(:text_reminder_opted_out)
|
||||
when :status then l(:text_reminder_status, status: appointment.status.to_s.humanize)
|
||||
when :no_customer then l(:text_reminder_no_customer)
|
||||
when :no_email then l(:text_reminder_no_email)
|
||||
else l(:text_reminder_too_late)
|
||||
end %>
|
||||
<%= text %>
|
||||
<% if rs.sent? && rs.reminder.sent_by %>(<%= rs.reminder.sent_by %>)<% end %>
|
||||
<% if [:failed, :given_up].include?(rs.state) %><em><%= rs.reminder.error %></em><% end %>
|
||||
|
||||
<% if can_send && appointment.customer && [:sent, :scheduled, :failed, :given_up, :too_late].include?(rs.state) %>
|
||||
<%= button_to (rs.sent? ? l(:button_send_reminder_again) : l(:button_send_reminder_now)),
|
||||
send_appointment_reminder_path(appointment), method: :post, form_class: 'appointment-reminder-send',
|
||||
data: (rs.sent? ? { confirm: l(:text_reminder_send_again_confirm) } : {}) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<style>
|
||||
.appointment-reminder { padding: 8px 12px; }
|
||||
.appointment-reminder em { color: #b71c1c; }
|
||||
.appointment-reminder-sent { border-left: 4px solid #5aa05a; }
|
||||
.appointment-reminder-scheduled { border-left: 4px solid #628db6; }
|
||||
.appointment-reminder-failed, .appointment-reminder-given_up, .appointment-reminder-no_email { border-left: 4px solid #e8a33d; }
|
||||
form.appointment-reminder-send { display: inline; margin-left: 8px; }
|
||||
</style>
|
||||
<% end %>
|
||||
@@ -0,0 +1,19 @@
|
||||
<%# Turning appointment reminders on or off for a customer, on the customer page (redmine_qbo's show_customer_view_right hook) %>
|
||||
<% customer = local_assigns[:customer] %>
|
||||
<% if customer && User.current.allowed_to?(:view_customer_appointments, nil, global: true) %>
|
||||
<% off = ReminderOptOut.opted_out?(customer) %>
|
||||
<div class="customer-reminders">
|
||||
<i class="fa-regular fa-envelope"></i>
|
||||
<strong><%= l(:label_appointment_reminders) %>:</strong>
|
||||
<%= off ? l(:text_customer_reminders_off) : l(:text_customer_reminders_on) %>
|
||||
<% if User.current.allowed_to?(:send_appointment_reminders, nil, global: true) %>
|
||||
<%= button_to (off ? l(:button_reminders_on) : l(:button_reminders_off)),
|
||||
(off ? customer_reminders_on_path(customer) : customer_reminders_off_path(customer)),
|
||||
method: :post, form_class: 'customer-reminders-toggle' %>
|
||||
<% end %>
|
||||
</div>
|
||||
<style>
|
||||
.customer-reminders { margin: 10px 0; }
|
||||
form.customer-reminders-toggle { display: inline; margin-left: 8px; }
|
||||
</style>
|
||||
<% end %>
|
||||
@@ -0,0 +1,200 @@
|
||||
<%# Settings for redmine_qbo_reminders (Administration » Plugins » Configure) %>
|
||||
<% s = RedmineQboReminders::Settings.new(settings) %>
|
||||
<% field = ->(key) { "settings[#{key}]" } %>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_reminders_sending) %></legend>
|
||||
<p>
|
||||
<label><%= l(:label_reminders_enabled) %></label>
|
||||
<%= hidden_field_tag field.call('enabled'), '0', id: nil %>
|
||||
<%= check_box_tag field.call('enabled'), '1', s.enabled?, id: 'reminders_enabled' %>
|
||||
<em class="info"><%= l(:text_reminders_enabled) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_from_name"><%= l(:label_reminders_from_name) %></label>
|
||||
<%= text_field_tag field.call('from_name'), s['from_name'], id: 'reminders_from_name', size: 40, placeholder: s['shop_name'] %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_from_address"><%= l(:label_reminders_from_address) %></label>
|
||||
<%= email_field_tag field.call('from_address'), s['from_address'], id: 'reminders_from_address', size: 40,
|
||||
placeholder: Setting.mail_from %>
|
||||
<em class="info"><%= l(:text_reminders_from_address) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_reply_to"><%= l(:label_reminders_reply_to) %></label>
|
||||
<%= email_field_tag field.call('reply_to'), s['reply_to'], id: 'reminders_reply_to', size: 40 %>
|
||||
<em class="info"><%= l(:text_reminders_reply_to) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= l(:label_reminders_delivery) %></label>
|
||||
<label class="inline"><%= radio_button_tag field.call('delivery'), 'smtp', s['delivery'] == 'smtp', id: 'reminders_delivery_smtp' %> <%= l(:label_reminders_delivery_smtp) %></label><br />
|
||||
<label class="inline"><%= radio_button_tag field.call('delivery'), 'redmine', s['delivery'] == 'redmine', id: 'reminders_delivery_redmine' %> <%= l(:label_reminders_delivery_redmine) %></label>
|
||||
</p>
|
||||
<div id="reminders-smtp">
|
||||
<p>
|
||||
<label for="reminders_smtp_address"><%= l(:label_reminders_smtp_address) %></label>
|
||||
<%= text_field_tag field.call('smtp_address'), s['smtp_address'], id: 'reminders_smtp_address', size: 30 %>
|
||||
<%= l(:label_reminders_smtp_port) %>
|
||||
<%= number_field_tag field.call('smtp_port'), s['smtp_port'], id: 'reminders_smtp_port', min: 1, max: 65535, style: 'width: 6em' %>
|
||||
<em class="info"><%= l(:text_reminders_smtp_address) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_smtp_domain"><%= l(:label_reminders_smtp_domain) %></label>
|
||||
<%= text_field_tag field.call('smtp_domain'), s['smtp_domain'], id: 'reminders_smtp_domain', size: 30, placeholder: s.mail_domain %>
|
||||
<em class="info"><%= l(:text_reminders_smtp_domain) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_smtp_user_name"><%= l(:label_reminders_smtp_user_name) %></label>
|
||||
<%= text_field_tag field.call('smtp_user_name'), s['smtp_user_name'], id: 'reminders_smtp_user_name', size: 30, autocomplete: 'off' %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_smtp_password"><%= l(:label_reminders_smtp_password) %></label>
|
||||
<%= password_field_tag field.call('smtp_password'), s['smtp_password'], id: 'reminders_smtp_password', size: 30, autocomplete: 'new-password' %>
|
||||
<em class="info"><%= l(:text_reminders_smtp_auth) %></em>
|
||||
</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_reminders_schedule) %></legend>
|
||||
<p>
|
||||
<label for="reminders_days_before"><%= l(:label_reminders_send) %></label>
|
||||
<%= number_field_tag field.call('days_before'), s['days_before'], id: 'reminders_days_before', min: 0, max: 14, style: 'width: 4em' %>
|
||||
<%= l(:label_reminders_days_before_at) %>
|
||||
<%= time_field_tag field.call('send_at'), s['send_at'], id: 'reminders_send_at' %>
|
||||
<em class="info"><%= l(:text_reminders_send) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_window_start"><%= l(:label_reminders_window) %></label>
|
||||
<%= time_field_tag field.call('window_start'), s['window_start'], id: 'reminders_window_start' %>
|
||||
–
|
||||
<%= time_field_tag field.call('window_end'), s['window_end'], id: 'reminders_window_end' %>
|
||||
<em class="info"><%= l(:text_reminders_window) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_min_lead_hours"><%= l(:label_reminders_min_lead) %></label>
|
||||
<%= number_field_tag field.call('min_lead_hours'), s['min_lead_hours'], id: 'reminders_min_lead_hours', min: 0, max: 48, step: 0.5, style: 'width: 5em' %>
|
||||
<%= l(:label_reminders_hours) %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_time_zone"><%= l(:label_reminders_time_zone) %></label>
|
||||
<%= select_tag field.call('time_zone'), options_for_select(ActiveSupport::TimeZone.all.map { |z| [z.to_s, z.name] }, s.zone.name),
|
||||
id: 'reminders_time_zone' %>
|
||||
<em class="info"><%= l(:text_reminders_time_zone) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= l(:label_reminders_statuses) %></label>
|
||||
<%= hidden_field_tag "#{field.call('statuses')}[]", '', id: nil %>
|
||||
<% CustomerAppointment::STATUSES.each do |status| %>
|
||||
<label class="inline" style="margin-right: 10px">
|
||||
<%= check_box_tag "#{field.call('statuses')}[]", status, s.statuses.include?(status), id: "reminders_status_#{status.parameterize}" %>
|
||||
<%= status.humanize %>
|
||||
</label>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= l(:label_reminders_check_on_page_loads) %></label>
|
||||
<%= hidden_field_tag field.call('check_on_page_loads'), '0', id: nil %>
|
||||
<%= check_box_tag field.call('check_on_page_loads'), '1', s.check_on_page_loads?, id: 'reminders_check_on_page_loads' %>
|
||||
<em class="info"><%= l(:text_reminders_check_on_page_loads) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_reminders_message) %></legend>
|
||||
<p>
|
||||
<label for="reminders_shop_name"><%= l(:label_reminders_shop_name) %></label>
|
||||
<%= text_field_tag field.call('shop_name'), s['shop_name'], id: 'reminders_shop_name', size: 40 %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_shop_phone"><%= l(:label_reminders_shop_phone) %></label>
|
||||
<%= text_field_tag field.call('shop_phone'), s['shop_phone'], id: 'reminders_shop_phone', size: 20 %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_shop_address"><%= l(:label_reminders_shop_address) %></label>
|
||||
<%= text_field_tag field.call('shop_address'), s['shop_address'], id: 'reminders_shop_address', size: 60 %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_subject"><%= l(:field_subject) %></label>
|
||||
<%= text_field_tag field.call('subject'), s['subject'], id: 'reminders_subject', size: 70 %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_body"><%= l(:label_reminders_body) %></label>
|
||||
<%= text_area_tag field.call('body'), s['body'], id: 'reminders_body', rows: 14, cols: 70, class: 'reminders-body' %>
|
||||
<em class="info">
|
||||
<%= l(:text_reminders_placeholders) %>
|
||||
<% RedmineQboReminders::Template::PLACEHOLDERS.each do |name| %><code>{{<%= name %>}}</code> <% end %><br />
|
||||
<%= l(:text_reminders_sections) %>
|
||||
</em>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= l(:label_reminders_attach_calendar) %></label>
|
||||
<%= hidden_field_tag field.call('attach_calendar'), '0', id: nil %>
|
||||
<%= check_box_tag field.call('attach_calendar'), '1', s.attach_calendar?, id: 'reminders_attach_calendar' %>
|
||||
<em class="info"><%= l(:text_reminders_attach_calendar) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="reminders_test_email"><%= l(:label_reminders_test) %></label>
|
||||
<%= email_field_tag 'email', User.current.mail, id: 'reminders_test_email', size: 30 %>
|
||||
<%= button_tag l(:button_reminders_send_test), type: 'submit', formaction: test_appointment_reminder_path,
|
||||
formmethod: 'post', name: nil, id: 'reminders-send-test' %>
|
||||
<em class="info"><%= l(:text_reminders_test) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="box">
|
||||
<legend><%= l(:label_reminders_recent) %></legend>
|
||||
<% recent = AppointmentReminder.recent.includes(customer_appointment: :customer).limit(15) %>
|
||||
<% if recent.empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<table class="list reminders-recent">
|
||||
<thead><tr>
|
||||
<th><%= l(:label_appointment_reminder_appointment) %></th>
|
||||
<th><%= l(:label_reminders_customer) %></th>
|
||||
<th><%= l(:field_mail) %></th>
|
||||
<th><%= l(:field_status) %></th>
|
||||
<th><%= l(:label_reminders_sent_at) %></th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<% recent.each do |r| %>
|
||||
<% appointment = r.customer_appointment %>
|
||||
<tr>
|
||||
<td class="appointment">
|
||||
<% if appointment %><%= link_to "#{format_time(r.appointment_date)} – #{appointment.subject}", customer_appointment_path(appointment) %><% end %>
|
||||
</td>
|
||||
<td><%= appointment&.customer&.name %></td>
|
||||
<td><%= r.email %></td>
|
||||
<td class="status reminder-<%= r.status %>">
|
||||
<%= l("label_reminder_status_#{r.status}") %>
|
||||
<% if r.error.present? %><br /><em><%= r.error.truncate(140) %></em><% end %>
|
||||
</td>
|
||||
<td><%= format_time(r.sent_at) if r.sent_at %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<p>
|
||||
<%= button_tag l(:button_reminders_run), type: 'submit', formaction: run_appointment_reminders_path, formmethod: 'post',
|
||||
name: nil, id: 'reminders-run' %>
|
||||
<em class="info"><%= l(:text_reminders_run) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<style>
|
||||
textarea.reminders-body { font-family: monospace; width: 95%; }
|
||||
table.reminders-recent td { text-align: left; }
|
||||
table.reminders-recent td.status em { color: #b71c1c; font-size: 0.9em; }
|
||||
table.reminders-recent .reminder-sent { color: #108000; }
|
||||
table.reminders-recent .reminder-failed { color: #b71c1c; }
|
||||
</style>
|
||||
|
||||
<%= javascript_tag do %>
|
||||
$(function() {
|
||||
// The SMTP server settings only matter when sending through it
|
||||
var toggle = function() { $('#reminders-smtp').toggle($('#reminders_delivery_smtp').is(':checked')); };
|
||||
$('input[name="settings[delivery]"]').on('change', toggle);
|
||||
toggle();
|
||||
});
|
||||
<% end %>
|
||||
@@ -0,0 +1,90 @@
|
||||
en:
|
||||
permission_send_appointment_reminders: "Send appointment reminders"
|
||||
|
||||
label_appointment_reminder: "Reminder email"
|
||||
label_appointment_reminders: "Appointment reminders"
|
||||
label_appointment_reminder_appointment: "Appointment"
|
||||
label_reminders_customer: "Customer"
|
||||
label_reminders_sent_at: "Sent"
|
||||
label_reminder_status_pending: "Sending"
|
||||
label_reminder_status_sent: "Sent"
|
||||
label_reminder_status_failed: "Failed"
|
||||
|
||||
text_reminder_sent: "sent %{time} to %{email}"
|
||||
text_reminder_sending: "being sent to %{email}"
|
||||
text_reminder_failed_retry: "couldn't be sent to %{email}; it will be tried again."
|
||||
text_reminder_failed: "couldn't be sent to %{email}, and won't be tried again on its own."
|
||||
text_reminder_scheduled: "will be sent %{time} to %{email}"
|
||||
text_reminder_off: "reminders are turned off in the plugin's settings."
|
||||
text_reminder_opted_out: "turned off for this customer."
|
||||
text_reminder_status: "not sent for %{status} appointments."
|
||||
text_reminder_no_customer: "this appointment has no customer."
|
||||
text_reminder_no_email: "the customer has no email address in QuickBooks."
|
||||
text_reminder_too_late: "not sent: the appointment is too soon (or past)."
|
||||
text_reminder_send_again_confirm: "This customer already has a reminder for this appointment. Send another?"
|
||||
button_send_reminder_now: "Send now"
|
||||
button_send_reminder_again: "Send again"
|
||||
notice_reminder_sent: "Reminder sent to %{email}."
|
||||
error_reminder_no_email: "The customer has no email address in QuickBooks."
|
||||
error_reminder_failed: "The reminder couldn't be sent: %{error}"
|
||||
|
||||
text_customer_reminders_on: "on"
|
||||
text_customer_reminders_off: "off for this customer"
|
||||
button_reminders_off: "Turn off"
|
||||
button_reminders_on: "Turn on"
|
||||
notice_reminders_off: "%{customer} won't get appointment reminders."
|
||||
notice_reminders_on: "%{customer} will get appointment reminders."
|
||||
|
||||
label_reminders_sending: "Sending"
|
||||
label_reminders_enabled: "Send reminders"
|
||||
text_reminders_enabled: "Email customers a reminder before their appointments, at the address on their QuickBooks customer."
|
||||
label_reminders_from_name: "From name"
|
||||
label_reminders_from_address: "From address"
|
||||
text_reminders_from_address: "A mailbox you own on your domain (e.g. sales@…), so replies come back to you and the mail passes SPF, DKIM and DMARC."
|
||||
label_reminders_reply_to: "Reply-to address"
|
||||
text_reminders_reply_to: "Optional: where replies go, when not the From address."
|
||||
label_reminders_delivery: "Send through"
|
||||
label_reminders_delivery_smtp: "This SMTP server (e.g. Google Workspace)"
|
||||
label_reminders_delivery_redmine: "Redmine's email settings (config/configuration.yml)"
|
||||
label_reminders_smtp_address: "SMTP server"
|
||||
label_reminders_smtp_port: "Port"
|
||||
text_reminders_smtp_address: "Google Workspace: smtp-relay.gmail.com (SMTP relay service), or smtp.gmail.com with an app password; port 587. The connection is encrypted (STARTTLS)."
|
||||
label_reminders_smtp_domain: "Domain"
|
||||
text_reminders_smtp_domain: "Your domain, sent when connecting (Google's SMTP relay requires it). Blank: the From address's domain."
|
||||
label_reminders_smtp_user_name: "User name"
|
||||
label_reminders_smtp_password: "Password"
|
||||
text_reminders_smtp_auth: "The mailbox and its app password. Leave both blank when the SMTP relay allows this server by its IP address."
|
||||
|
||||
label_reminders_schedule: "Schedule"
|
||||
label_reminders_send: "Send"
|
||||
label_reminders_days_before_at: "days before the appointment, at"
|
||||
text_reminders_send: "0 sends on the day of the appointment. Appointments booked after that time still get a reminder right away."
|
||||
label_reminders_window: "Only send between"
|
||||
text_reminders_window: "If reminders are late (e.g. Redmine was down), they wait for this window instead of going out at night."
|
||||
label_reminders_min_lead: "Not within"
|
||||
label_reminders_hours: "hours of the appointment"
|
||||
label_reminders_time_zone: "Shop time zone"
|
||||
text_reminders_time_zone: "The time zone appointment times are entered in."
|
||||
label_reminders_statuses: "For appointments that are"
|
||||
label_reminders_check_on_page_loads: "Check on page loads"
|
||||
text_reminders_check_on_page_loads: "Look for due reminders every 10 minutes while Redmine is in use. With the rake task in cron (see the README) this can be off."
|
||||
|
||||
label_reminders_message: "Message"
|
||||
label_reminders_shop_name: "Shop name"
|
||||
label_reminders_shop_phone: "Shop phone"
|
||||
label_reminders_shop_address: "Shop address"
|
||||
label_reminders_body: "Message"
|
||||
text_reminders_placeholders: "Placeholders:"
|
||||
text_reminders_sections: "{{#vehicle}}…{{/vehicle}} shows only when there is a vehicle; {{^vehicle}}…{{/vehicle}} only when there isn't. Sent as plain text and as simple HTML."
|
||||
label_reminders_attach_calendar: "Attach calendar file"
|
||||
text_reminders_attach_calendar: "An .ics file, so the customer can add the appointment to their calendar."
|
||||
label_reminders_test: "Send a test to"
|
||||
button_reminders_send_test: "Send test email"
|
||||
text_reminders_test: "A sample reminder with the settings on this page (saved or not)."
|
||||
notice_reminder_test_sent: "Test reminder sent to %{email}."
|
||||
|
||||
label_reminders_recent: "Recent reminders"
|
||||
button_reminders_run: "Send due reminders now"
|
||||
text_reminders_run: "Uses the saved settings."
|
||||
notice_reminders_run: "Reminders: %{result}."
|
||||
error_reminders_disabled: "Reminders are turned off. Turn on Send reminders and save first."
|
||||
@@ -0,0 +1,18 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
RedmineApp::Application.routes.draw do
|
||||
post 'customer_appointments/:id/reminder', to: 'appointment_reminders#send_now', as: 'send_appointment_reminder'
|
||||
post 'customers/:customer_id/reminders/off', to: 'appointment_reminders#opt_out', as: 'customer_reminders_off'
|
||||
post 'customers/:customer_id/reminders/on', to: 'appointment_reminders#opt_in', as: 'customer_reminders_on'
|
||||
# From the plugin's settings page (administrators)
|
||||
post 'appointment_reminders/test', to: 'appointment_reminders#test', as: 'test_appointment_reminder'
|
||||
post 'appointment_reminders/run', to: 'appointment_reminders#run', as: 'run_appointment_reminders'
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# One row per reminder sent (or tried) for an appointment at a given time; rescheduling the appointment
|
||||
# makes it due again
|
||||
class CreateAppointmentReminders < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :appointment_reminders do |t|
|
||||
t.references :customer_appointment, null: false
|
||||
t.datetime :appointment_date, null: false
|
||||
t.string :email
|
||||
# pending (being sent), sent or failed
|
||||
t.string :status, null: false, default: 'pending'
|
||||
t.text :error
|
||||
t.integer :attempts, null: false, default: 0
|
||||
t.datetime :sent_at
|
||||
# Who sent it from the appointment page; empty when sent on schedule
|
||||
t.references :sent_by
|
||||
t.timestamps
|
||||
end
|
||||
add_index :appointment_reminders, [:customer_appointment_id, :appointment_date], unique: true,
|
||||
name: 'index_appointment_reminders_on_appointment_and_date'
|
||||
add_index :appointment_reminders, :created_at
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# Customers who don't get appointment reminders
|
||||
class CreateReminderOptOuts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :reminder_opt_outs do |t|
|
||||
t.references :customer, null: false, index: { unique: true }
|
||||
t.references :user
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Redmine::Plugin.register :redmine_qbo_reminders do
|
||||
|
||||
# About
|
||||
name 'Redmine QBO Reminders plugin'
|
||||
author 'Rick Barrette'
|
||||
description 'Emails customers reminders of their appointments (redmine_qbo_calendar), using their email address in QuickBooks Online'
|
||||
version '2026.11.0'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo_reminders'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
requires_redmine version_or_higher: '7.0.0'
|
||||
|
||||
# Appointments live in redmine_qbo_calendar; customers and their email addresses in redmine_qbo
|
||||
begin
|
||||
requires_redmine_plugin :redmine_qbo_calendar, version_or_higher: '2026.11.0'
|
||||
rescue Redmine::PluginNotFound
|
||||
raise 'Please install the redmine_qbo_calendar plugin (https://github.com/rickbarrette/redmine_qbo_calendar)'
|
||||
end
|
||||
|
||||
settings default: RedmineQboReminders::Settings::DEFAULTS.dup, partial: 'settings/appointment_reminders'
|
||||
|
||||
# Sending a reminder from the appointment page, and turning reminders on or off for a customer
|
||||
permission :send_appointment_reminders, { appointment_reminders: [:send_now, :opt_out, :opt_in] }, global: true
|
||||
end
|
||||
|
||||
RedmineQboReminders.setup
|
||||
@@ -0,0 +1,35 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
# How often page loads may start a run (when "Check on page loads" is on)
|
||||
CHECK_EVERY = 10 * 60
|
||||
|
||||
def self.setup
|
||||
RedmineQboReminders::Hooks::ViewHookListener
|
||||
RedmineQboReminders::Hooks::AppointmentHookListener
|
||||
RedmineQboReminders::Hooks::CustomerHookListener
|
||||
end
|
||||
|
||||
# Starts a run in the background, at most every CHECK_EVERY seconds (page loads call this). Without cron,
|
||||
# reminders go out while someone is using Redmine.
|
||||
def self.check_soon
|
||||
settings = Settings.current
|
||||
return unless settings.enabled? && settings.check_on_page_loads?
|
||||
return if @last_check && Time.now - @last_check < CHECK_EVERY
|
||||
@last_check = Time.now
|
||||
# Shared between Redmine's processes when its cache is; the claim in Sender stops double sends anyway
|
||||
return unless Rails.cache.write('redmine_qbo_reminders:last_check', Time.now.to_i, unless_exist: true,
|
||||
expires_in: CHECK_EVERY)
|
||||
AppointmentRemindersJob.perform_later
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn "[RedmineQboReminders] Could not start a run: #{e.message}"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
module Hooks
|
||||
# The reminder's status (and a Send button) on redmine_qbo_calendar's appointment page
|
||||
class AppointmentHookListener < Redmine::Hook::ViewListener
|
||||
render_on :show_customer_appointment, partial: 'appointment_reminders/appointment'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
module Hooks
|
||||
# Turning reminders on or off for a customer, on the customer page
|
||||
class CustomerHookListener < Redmine::Hook::ViewListener
|
||||
render_on :show_customer_view_right, partial: 'appointment_reminders/customer'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
module Hooks
|
||||
# Page loads start a reminder run every few minutes (RedmineQboReminders.check_soon); adds nothing to the page
|
||||
class ViewHookListener < Redmine::Hook::ViewListener
|
||||
def view_layouts_base_html_head(context = {})
|
||||
RedmineQboReminders.check_soon if User.current.logged?
|
||||
''
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
# A calendar file (iCalendar) for the appointment, attached to the reminder so the customer can add it
|
||||
# to their calendar with a tap. Published, not an invitation, so mail apps don't ask them to RSVP.
|
||||
module Ics
|
||||
module_function
|
||||
|
||||
# starts_at: a Time; minutes: how long the event is
|
||||
def build(uid:, starts_at:, summary:, minutes: 60, location: nil, description: nil, now: Time.now)
|
||||
fmt = ->(t) { t.utc.strftime('%Y%m%dT%H%M%SZ') }
|
||||
lines = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0',
|
||||
'PRODID:-//redmine_qbo_reminders//EN',
|
||||
'CALSCALE:GREGORIAN',
|
||||
'METHOD:PUBLISH',
|
||||
'BEGIN:VEVENT',
|
||||
"UID:#{uid}",
|
||||
"DTSTAMP:#{fmt.call(now)}",
|
||||
"DTSTART:#{fmt.call(starts_at)}",
|
||||
"DTEND:#{fmt.call(starts_at + minutes * 60)}",
|
||||
"SUMMARY:#{escape(summary)}"
|
||||
]
|
||||
lines << "LOCATION:#{escape(location)}" if location.to_s.strip != ''
|
||||
lines << "DESCRIPTION:#{escape(description)}" if description.to_s.strip != ''
|
||||
lines += ['END:VEVENT', 'END:VCALENDAR']
|
||||
lines.map { |line| fold(line) }.join("\r\n") + "\r\n"
|
||||
end
|
||||
|
||||
def escape(text)
|
||||
text.to_s.strip.gsub('\\', '\\\\\\\\').gsub(/\r?\n/, '\\n').gsub(',', '\\,').gsub(';', '\\;')
|
||||
end
|
||||
|
||||
# Lines longer than 75 bytes continue on the next line, which starts with a space
|
||||
def fold(line)
|
||||
parts = []
|
||||
current = +''
|
||||
line.each_char do |ch|
|
||||
limit = parts.empty? ? 75 : 74
|
||||
if (current + ch).bytesize > limit
|
||||
parts << current
|
||||
current = +''
|
||||
end
|
||||
current << ch
|
||||
end
|
||||
parts << current
|
||||
parts.join("\r\n ")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,70 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
# One reminder: who it's to and what it says, built from an appointment and the settings
|
||||
class Message
|
||||
attr_reader :settings, :values, :starts_at, :uid
|
||||
|
||||
# values: the placeholders' values (see Template); starts_at: the appointment's time in the shop's zone
|
||||
def initialize(settings:, values:, starts_at:, uid:)
|
||||
@settings = settings
|
||||
@values = settings.shop_values.merge(values.transform_keys(&:to_s))
|
||||
@starts_at = starts_at
|
||||
@uid = uid
|
||||
end
|
||||
|
||||
# Built from an appointment (redmine_qbo_calendar's CustomerAppointment)
|
||||
def self.for(appointment, settings, customer_name: nil, first_name: nil)
|
||||
starts_at = settings.schedule.appointment_time(appointment.date)
|
||||
customer = appointment.customer
|
||||
name = customer_name || customer&.name.to_s
|
||||
values = {
|
||||
'customer' => name,
|
||||
'first_name' => first_name.presence || name.split(/\s+/).first.to_s,
|
||||
'vehicle' => appointment.respond_to?(:vehicle) ? appointment.vehicle&.to_s : nil,
|
||||
'subject' => appointment.subject
|
||||
}.merge(when_values(starts_at))
|
||||
new(settings: settings, values: values, starts_at: starts_at,
|
||||
uid: "appointment-#{appointment.id}@#{settings.mail_domain}")
|
||||
end
|
||||
|
||||
# {{day}} "Monday, November 2", {{date}} "11/02/2026", {{time}} "9:00 AM"
|
||||
def self.when_values(starts_at)
|
||||
{
|
||||
'day' => starts_at.strftime('%A, %B %-d'),
|
||||
'date' => starts_at.strftime('%m/%d/%Y'),
|
||||
'time' => starts_at.strftime('%-l:%M %p')
|
||||
}
|
||||
end
|
||||
|
||||
def subject
|
||||
Template.render_line(settings['subject'].presence || Template::DEFAULT_SUBJECT, values)
|
||||
end
|
||||
|
||||
def text
|
||||
Template.render(settings['body'].presence || Template::DEFAULT_BODY, values)
|
||||
end
|
||||
|
||||
def html
|
||||
Template.html(text)
|
||||
end
|
||||
|
||||
# The calendar attachment, or nil when it's turned off
|
||||
def ics
|
||||
return nil unless settings.attach_calendar?
|
||||
shop = values['shop_name'].to_s.strip
|
||||
summary = shop.empty? ? 'Appointment' : "Appointment at #{shop}"
|
||||
summary += " – #{values['vehicle']}" if values['vehicle'].to_s.strip != ''
|
||||
Ics.build(uid: uid, starts_at: starts_at, summary: summary, location: values['shop_address'],
|
||||
description: values['shop_phone'].to_s.strip.empty? ? nil : "Questions or need to reschedule? Call #{values['shop_phone']}")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
# Where an appointment's reminder stands, for the appointment page:
|
||||
# :sent sent (reminder.sent_at, to email)
|
||||
# :failed the last try failed (reminder.error); :given_up when it won't be tried again on schedule
|
||||
# :sending being sent right now
|
||||
# :scheduled will go out at `at` to email
|
||||
# :off reminders are turned off in the plugin's settings
|
||||
# :opted_out turned off for this customer
|
||||
# :status the appointment's status doesn't get reminders (e.g. Cancelled)
|
||||
# :no_customer, :no_email
|
||||
# :too_late too close to (or past) the appointment to send on schedule
|
||||
class ReminderStatus
|
||||
attr_reader :state, :at, :email, :reminder
|
||||
|
||||
def self.for(appointment, settings: Settings.current, now: Time.now)
|
||||
new(appointment, settings, now)
|
||||
end
|
||||
|
||||
def initialize(appointment, settings, now)
|
||||
@reminder = AppointmentReminder.find_by(customer_appointment_id: appointment.id, appointment_date: appointment.date)
|
||||
@state = compute(appointment, settings, now)
|
||||
end
|
||||
|
||||
def sent?
|
||||
state == :sent
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compute(appointment, settings, now)
|
||||
if reminder
|
||||
@email = reminder.email
|
||||
return :sent if reminder.sent?
|
||||
return :sending if reminder.status == 'pending' && !reminder.stale?
|
||||
return(reminder.retry? && settings.enabled? ? :failed : :given_up) if reminder.failed? || reminder.stale?
|
||||
end
|
||||
return :off unless settings.enabled?
|
||||
return :status unless settings.remind_status?(appointment.status)
|
||||
return :no_customer if appointment.customer.nil?
|
||||
return :opted_out if ReminderOptOut.opted_out?(appointment.customer)
|
||||
|
||||
@email = Sender.customer_email(appointment.customer)
|
||||
return :no_email if @email.nil?
|
||||
|
||||
schedule = settings.schedule
|
||||
@at = schedule.next_send(schedule.appointment_time(appointment.date), now)
|
||||
@at ? :scheduled : :too_late
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,85 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
# When an appointment's reminder goes out. Times are the shop's wall-clock time (the time zone set in the
|
||||
# plugin's settings), the way appointments are entered and shown.
|
||||
#
|
||||
# A reminder is due once its send time has passed (days_before days ahead of the appointment, at send_at),
|
||||
# while the appointment is still more than min_lead_hours away, and only between window_start and
|
||||
# window_end, so a late run never emails customers in the middle of the night.
|
||||
class Schedule
|
||||
attr_reader :zone, :days_before, :send_at, :window_start, :window_end, :min_lead_hours
|
||||
|
||||
def initialize(zone:, days_before: 1, send_at: '16:00', window_start: '08:00', window_end: '20:00', min_lead_hours: 2)
|
||||
@zone = zone
|
||||
@days_before = [days_before.to_i, 0].max
|
||||
@send_at = minutes(send_at, 16 * 60)
|
||||
@window_start = minutes(window_start, 8 * 60)
|
||||
@window_end = minutes(window_end, 20 * 60)
|
||||
@min_lead_hours = [min_lead_hours.to_f, 0].max
|
||||
end
|
||||
|
||||
# The appointment's time (stored as the time entered) as a time in the shop's zone
|
||||
def appointment_time(datetime)
|
||||
zone.local(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min)
|
||||
end
|
||||
|
||||
# When the reminder for an appointment at this (shop) time goes out
|
||||
def send_time(appointment_at)
|
||||
day = appointment_at.to_date - days_before
|
||||
zone.local(day.year, day.month, day.day, send_at / 60, send_at % 60)
|
||||
end
|
||||
|
||||
# Too close to the appointment to bother (or already past)
|
||||
def too_late?(appointment_at, now)
|
||||
now >= appointment_at - (min_lead_hours * 3600)
|
||||
end
|
||||
|
||||
def in_window?(now)
|
||||
local = now.in_time_zone(zone)
|
||||
m = local.hour * 60 + local.min
|
||||
m >= window_start && m < window_end
|
||||
end
|
||||
|
||||
def due?(appointment_at, now)
|
||||
now >= send_time(appointment_at) && !too_late?(appointment_at, now) && in_window?(now)
|
||||
end
|
||||
|
||||
# When a not-yet-due reminder will go out: its send time, moved to the next sending window if it falls
|
||||
# outside one. nil when it's too late to send.
|
||||
def next_send(appointment_at, now)
|
||||
at = [send_time(appointment_at), now].max.in_time_zone(zone)
|
||||
unless in_window?(at)
|
||||
m = at.hour * 60 + at.min
|
||||
day = m >= window_end ? at.to_date + 1 : at.to_date
|
||||
at = zone.local(day.year, day.month, day.day, window_start / 60, window_start % 60)
|
||||
end
|
||||
too_late?(appointment_at, at) ? nil : at
|
||||
end
|
||||
|
||||
# Appointments worth looking at now: a little either side of the reminder lead, wide enough to cover
|
||||
# the difference between the server's and the shop's time zone
|
||||
def lookahead(now)
|
||||
[now - 1.day, now + (days_before + 2).days]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# "16:30" -> 990
|
||||
def minutes(value, default)
|
||||
h, m = value.to_s.split(':', 2).map { |v| Integer(v, 10) }
|
||||
return default if h.nil? || h.negative? || h > 23 || m.to_i.negative? || m.to_i > 59
|
||||
h * 60 + m.to_i
|
||||
rescue ArgumentError, TypeError
|
||||
default
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,134 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
# Emails the reminders that are due. Run by the rake task (cron), and on page loads every few minutes when
|
||||
# that's turned on. Safe to run often and from several places at once: each reminder is claimed in the
|
||||
# database before it's sent, so a customer never gets two for the same appointment time.
|
||||
class Sender
|
||||
Result = Struct.new(:sent, :failed, :skipped) do
|
||||
def to_s
|
||||
"#{sent} sent, #{failed} failed, #{skipped} skipped"
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :settings, :now, :result
|
||||
|
||||
def self.run(now: Time.now)
|
||||
new(now: now).run
|
||||
end
|
||||
|
||||
def initialize(settings: Settings.current, now: Time.now)
|
||||
@settings = settings
|
||||
@now = now
|
||||
@result = Result.new(0, 0, 0)
|
||||
end
|
||||
|
||||
def run
|
||||
return result unless settings.enabled?
|
||||
schedule = settings.schedule
|
||||
return result unless schedule.in_window?(now)
|
||||
|
||||
from, to = schedule.lookahead(now)
|
||||
CustomerAppointment.where(date: from..to).includes(:customer).find_each do |appointment|
|
||||
consider(appointment, schedule)
|
||||
end
|
||||
log "Run finished: #{result}" if result.sent + result.failed > 0
|
||||
result
|
||||
end
|
||||
|
||||
# Sends an appointment's reminder now, whatever the schedule says (the appointment page's button).
|
||||
# Returns the AppointmentReminder, or nil when the customer has no email address.
|
||||
def send_now(appointment, user: nil)
|
||||
email = self.class.customer_email(appointment.customer)
|
||||
return nil if email.nil?
|
||||
existing = AppointmentReminder.find_by(customer_appointment_id: appointment.id, appointment_date: appointment.date)
|
||||
deliver(appointment, email, existing, user: user)
|
||||
end
|
||||
|
||||
# The customer's email address in QuickBooks (the first, when there are several), or nil
|
||||
def self.customer_email(customer)
|
||||
return nil if customer.nil?
|
||||
address = customer.email.to_s.split(/[,;]/).map(&:strip).find { |a| a.match?(/\A[^@\s]+@[^@\s]+\.[^@\s]+\z/) }
|
||||
address.presence
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn "[RedmineQboReminders] Could not read the email of customer #{customer&.id}: #{e.message}"
|
||||
nil
|
||||
end
|
||||
|
||||
# The customer's first name in QuickBooks, falling back to the first word of their name
|
||||
def self.first_name(customer)
|
||||
customer.respond_to?(:given_name) ? customer.given_name.to_s.strip.presence : nil
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def consider(appointment, schedule)
|
||||
at = schedule.appointment_time(appointment.date)
|
||||
return unless settings.remind_status?(appointment.status) && schedule.due?(at, now)
|
||||
|
||||
customer = appointment.customer
|
||||
return skip(appointment, 'no customer') if customer.nil?
|
||||
return skip(appointment, 'customer turned reminders off') if ReminderOptOut.opted_out?(customer)
|
||||
|
||||
existing = AppointmentReminder.find_by(customer_appointment_id: appointment.id, appointment_date: appointment.date)
|
||||
return if existing && !existing.retry?
|
||||
|
||||
email = self.class.customer_email(customer)
|
||||
return skip(appointment, 'customer has no email address') if email.nil?
|
||||
|
||||
deliver(appointment, email, existing)
|
||||
end
|
||||
|
||||
def deliver(appointment, email, existing, user: nil)
|
||||
reminder = claim(appointment, email, existing)
|
||||
return nil if reminder.nil?
|
||||
|
||||
message = Message.for(appointment, settings, first_name: self.class.first_name(appointment.customer))
|
||||
AppointmentReminderMailer.reminder(message, email).deliver_now
|
||||
reminder.update!(status: 'sent', sent_at: Time.now, sent_by: user, error: nil)
|
||||
result.sent += 1
|
||||
log "Sent the reminder for appointment ##{appointment.id} to #{email}"
|
||||
reminder
|
||||
rescue StandardError => e
|
||||
result.failed += 1
|
||||
log "Could not send the reminder for appointment ##{appointment.id} to #{email}: #{e.class}: #{e.message}"
|
||||
reminder&.update_columns(status: 'failed', error: "#{e.class}: #{e.message}".truncate(1000), updated_at: Time.now)
|
||||
reminder
|
||||
end
|
||||
|
||||
# Marks the reminder as being sent, or nil when another run got to it first
|
||||
def claim(appointment, email, existing)
|
||||
if existing.nil?
|
||||
AppointmentReminder.create!(customer_appointment: appointment, appointment_date: appointment.date,
|
||||
email: email, status: 'pending', attempts: 1)
|
||||
else
|
||||
claimed = AppointmentReminder.where(id: existing.id, attempts: existing.attempts)
|
||||
.update_all(status: 'pending', attempts: existing.attempts + 1, email: email,
|
||||
error: nil, updated_at: Time.now)
|
||||
claimed.zero? ? nil : existing.reload
|
||||
end
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
nil
|
||||
end
|
||||
|
||||
def skip(appointment, reason)
|
||||
result.skipped += 1
|
||||
log "Skipped appointment ##{appointment.id}: #{reason}"
|
||||
nil
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[RedmineQboReminders] #{msg}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,129 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
module RedmineQboReminders
|
||||
# The plugin's settings (Administration » Plugins » Configure), with defaults
|
||||
class Settings
|
||||
DEFAULTS = {
|
||||
'enabled' => '0',
|
||||
'from_name' => '',
|
||||
'from_address' => '',
|
||||
'reply_to' => '',
|
||||
# 'redmine': Redmine's own email settings (config/configuration.yml); 'smtp': the server below
|
||||
'delivery' => 'smtp',
|
||||
'smtp_address' => 'smtp-relay.gmail.com',
|
||||
'smtp_port' => '587',
|
||||
'smtp_domain' => '',
|
||||
'smtp_user_name' => '',
|
||||
'smtp_password' => '',
|
||||
'time_zone' => 'Eastern Time (US & Canada)',
|
||||
'days_before' => '1',
|
||||
'send_at' => '16:00',
|
||||
'window_start' => '08:00',
|
||||
'window_end' => '20:00',
|
||||
'min_lead_hours' => '2',
|
||||
'statuses' => ['Scheduled'],
|
||||
'check_on_page_loads' => '1',
|
||||
'attach_calendar' => '1',
|
||||
'shop_name' => '',
|
||||
'shop_phone' => '',
|
||||
'shop_address' => '',
|
||||
'subject' => Template::DEFAULT_SUBJECT,
|
||||
'body' => Template::DEFAULT_BODY
|
||||
}.freeze
|
||||
|
||||
def self.current
|
||||
new(Setting.plugin_redmine_qbo_reminders)
|
||||
end
|
||||
|
||||
def initialize(values = {})
|
||||
@values = DEFAULTS.merge((values || {}).to_h.transform_keys(&:to_s).reject { |_, v| v.nil? })
|
||||
end
|
||||
|
||||
def [](key)
|
||||
@values[key.to_s]
|
||||
end
|
||||
|
||||
def enabled?
|
||||
self['enabled'].to_s == '1'
|
||||
end
|
||||
|
||||
def check_on_page_loads?
|
||||
self['check_on_page_loads'].to_s == '1'
|
||||
end
|
||||
|
||||
def attach_calendar?
|
||||
self['attach_calendar'].to_s == '1'
|
||||
end
|
||||
|
||||
# Appointment statuses that get reminders; a blank status counts as Scheduled (the form's first choice)
|
||||
def statuses
|
||||
Array(self['statuses']).map(&:to_s).reject(&:empty?)
|
||||
end
|
||||
|
||||
def remind_status?(status)
|
||||
statuses.include?(status.to_s.presence || 'Scheduled')
|
||||
end
|
||||
|
||||
def zone
|
||||
ActiveSupport::TimeZone[self['time_zone'].to_s] || ActiveSupport::TimeZone['Eastern Time (US & Canada)']
|
||||
end
|
||||
|
||||
def schedule
|
||||
Schedule.new(zone: zone, days_before: self['days_before'], send_at: self['send_at'],
|
||||
window_start: self['window_start'], window_end: self['window_end'],
|
||||
min_lead_hours: self['min_lead_hours'])
|
||||
end
|
||||
|
||||
def from_address
|
||||
self['from_address'].to_s.strip.presence || (defined?(Setting) && Setting.respond_to?(:mail_from) ? Setting.mail_from.to_s : '')
|
||||
end
|
||||
|
||||
# "Ocean State Off Road <sales@example.com>", quoting the name when it needs it
|
||||
def from
|
||||
address = from_address
|
||||
name = self['from_name'].to_s.strip.presence || self['shop_name'].to_s.strip.presence
|
||||
return address if name.nil? || address.include?('<')
|
||||
name = %("#{name.gsub(/(["\\])/, '\\\\\1')}") if name =~ /[()<>\[\]:;@\\,."]/
|
||||
"#{name} <#{address}>"
|
||||
end
|
||||
|
||||
def reply_to
|
||||
self['reply_to'].to_s.strip.presence
|
||||
end
|
||||
|
||||
# The domain mail is sent from (sales@example.com -> example.com): the SMTP greeting and Message-IDs
|
||||
def mail_domain
|
||||
self['smtp_domain'].to_s.strip.presence || from_address[/@([^>\s]+)/, 1] || 'localhost'
|
||||
end
|
||||
|
||||
# Options for ActionMailer's mail(): empty to use Redmine's email settings
|
||||
def delivery_options
|
||||
return {} unless self['delivery'] == 'smtp'
|
||||
smtp = {
|
||||
address: self['smtp_address'].to_s.strip.presence || 'smtp-relay.gmail.com',
|
||||
port: (self['smtp_port'].presence || 587).to_i,
|
||||
domain: mail_domain,
|
||||
enable_starttls_auto: true,
|
||||
open_timeout: 15,
|
||||
read_timeout: 30
|
||||
}
|
||||
if self['smtp_user_name'].to_s.strip != ''
|
||||
smtp.merge!(user_name: self['smtp_user_name'].to_s.strip, password: self['smtp_password'].to_s, authentication: :plain)
|
||||
end
|
||||
{ delivery_method: :smtp, delivery_method_options: smtp }
|
||||
end
|
||||
|
||||
# Shop details for the message
|
||||
def shop_values
|
||||
{ 'shop_name' => self['shop_name'], 'shop_phone' => self['shop_phone'], 'shop_address' => self['shop_address'] }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,69 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
require 'cgi'
|
||||
|
||||
module RedmineQboReminders
|
||||
# The reminder's wording, from the settings. Placeholders:
|
||||
# {{first_name}} {{customer}} {{day}} {{date}} {{time}} {{vehicle}} {{subject}}
|
||||
# {{shop_name}} {{shop_phone}} {{shop_address}}
|
||||
# A section shows only when its placeholder has a value ({{#vehicle}}for your {{vehicle}}{{/vehicle}}), and
|
||||
# an inverted one only when it doesn't ({{^vehicle}}...{{/vehicle}}).
|
||||
module Template
|
||||
PLACEHOLDERS = %w[first_name customer day date time vehicle subject shop_name shop_phone shop_address].freeze
|
||||
|
||||
DEFAULT_SUBJECT = 'Reminder: your appointment {{day}} at {{time}}'
|
||||
DEFAULT_BODY = <<~TEXT.strip
|
||||
Hi {{first_name}},
|
||||
|
||||
This is a reminder of your appointment{{#vehicle}} for your {{vehicle}}{{/vehicle}}{{#shop_name}} at {{shop_name}}{{/shop_name}} on {{day}} at {{time}}.
|
||||
|
||||
Please reply to this email to confirm{{#shop_phone}}, or call us at {{shop_phone}} if you need to reschedule{{/shop_phone}}{{^shop_phone}}, or to let us know if you need to reschedule{{/shop_phone}}.
|
||||
|
||||
Thank you,
|
||||
{{shop_name}}
|
||||
{{shop_address}}
|
||||
{{shop_phone}}
|
||||
TEXT
|
||||
|
||||
module_function
|
||||
|
||||
# The text with placeholders filled in (values: { "vehicle" => "2022 Jeep Gladiator", ... })
|
||||
def render(text, values)
|
||||
values = values.transform_keys(&:to_s).transform_values { |v| v.to_s.strip }
|
||||
out = text.to_s.gsub(/\{\{([#^])(\w+)\}\}(.*?)\{\{\/\2\}\}/m) do
|
||||
present = values[$2].to_s != ''
|
||||
($1 == '#') == present ? $3 : ''
|
||||
end
|
||||
out = out.gsub(/\{\{(\w+)\}\}/) { values[$1].to_s }
|
||||
# Lines left empty by missing values (e.g. no shop phone) collapse, but paragraph breaks stay
|
||||
out.gsub(/[ \t]+$/, '').gsub(/\n{3,}/, "\n\n").strip
|
||||
end
|
||||
|
||||
# A one-line version for the subject
|
||||
def render_line(text, values)
|
||||
render(text, values).gsub(/\s+/, ' ').strip
|
||||
end
|
||||
|
||||
# Plain text as simple HTML: paragraphs at blank lines, line breaks kept
|
||||
def html(text)
|
||||
paragraphs = text.split(/\n{2,}/).map do |para|
|
||||
"<p style=\"margin:0 0 1em\">#{para.split("\n").map { |line| CGI.escapeHTML(line) }.join('<br>')}</p>"
|
||||
end
|
||||
<<~HTML
|
||||
<!DOCTYPE html>
|
||||
<html><head><meta charset="utf-8"></head>
|
||||
<body style="font-family:Arial,Helvetica,sans-serif;font-size:15px;line-height:1.5;color:#222">
|
||||
#{paragraphs.join("\n")}
|
||||
</body></html>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
namespace :redmine do
|
||||
namespace :appointment_reminders do
|
||||
desc 'Email the appointment reminders that are due (run it from cron, e.g. every 15 minutes)'
|
||||
task send: :environment do
|
||||
result = RedmineQboReminders::Sender.run
|
||||
puts "Appointment reminders: #{result}"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user