Skip to content

Commit

Permalink
Invoices - Send email notif when paid
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongecho committed Oct 6, 2024
1 parent c948ccf commit a9de75a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
10 changes: 10 additions & 0 deletions admin_settings_invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
<small class="text-secondary">We recommend updating the invoice footer to include policies on your late charges. This will be applied every 30 days after the invoice Due Date.</small>
</div>

<div class="form-group">
<label>Email address to notify when invoices are paid online <small class="text-secondary">(Ideally a distribution list/shared mailbox)</small></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-bell"></i></span>
</div>
<input type="email" class="form-control" name="config_invoice_paid_notification_email" placeholder="Address to notify for paid invoices, leave bank for none" value="<?php echo nullable_htmlentities($config_invoice_paid_notification_email); ?>">
</div>
</div>

<hr>

<h4>Recurring Invoice</h4>
Expand Down
12 changes: 9 additions & 3 deletions database_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2231,10 +2231,16 @@
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.5.2'");
}

// if (CURRENT_DATABASE_VERSION == '1.5.2') {
// // Insert queries here required to update to DB version 1.5.3
if (CURRENT_DATABASE_VERSION == '1.5.2') {
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_invoice_paid_notification_email` VARCHAR(200) DEFAULT NULL AFTER `config_invoice_late_fee_percent`");

mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.5.3'");
}

// if (CURRENT_DATABASE_VERSION == '1.5.3') {
// // Insert queries here required to update to DB version 1.5.4
// // Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.5.3'");
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.5.4'");
// }

} else {
Expand Down
2 changes: 1 addition & 1 deletion database_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/

DEFINE("LATEST_DATABASE_VERSION", "1.5.2");
DEFINE("LATEST_DATABASE_VERSION", "1.5.3");
1 change: 1 addition & 0 deletions db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ CREATE TABLE `settings` (
`config_invoice_from_email` varchar(200) DEFAULT NULL,
`config_invoice_late_fee_enable` tinyint(1) NOT NULL DEFAULT 0,
`config_invoice_late_fee_percent` decimal(5,2) NOT NULL DEFAULT 0.00,
`config_invoice_paid_notification_email` varchar(200) DEFAULT NULL,
`config_recurring_prefix` varchar(200) DEFAULT NULL,
`config_recurring_next_number` int(11) NOT NULL,
`config_quote_prefix` varchar(200) DEFAULT NULL,
Expand Down
1 change: 1 addition & 0 deletions get_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
$config_invoice_from_email = $row['config_invoice_from_email'];
$config_invoice_late_fee_enable = intval($row['config_invoice_late_fee_enable']);
$config_invoice_late_fee_percent = floatval($row['config_invoice_late_fee_percent']);
$config_invoice_paid_notification_email = $row['config_invoice_paid_notification_email'];

// Recurring Invoices
$config_recurring_prefix = $row['config_recurring_prefix'];
Expand Down
36 changes: 27 additions & 9 deletions guest_pay_invoice_stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,41 @@
$config_smtp_password = $row['config_smtp_password'];
$config_invoice_from_name = sanitizeInput($row['config_invoice_from_name']);
$config_invoice_from_email = sanitizeInput($row['config_invoice_from_email']);
$config_invoice_paid_notification_email = sanitizeInput($row['config_invoice_paid_notification_email']);

$config_base_url = sanitizeInput($config_base_url);

if (!empty($config_smtp_host)) {
$subject = "Payment Received - Invoice $invoice_prefix$invoice_number";
$body = "Hello $contact_name,<br><br>We have received your payment in the amount of " . $pi_currency . $pi_amount_paid . " for invoice <a href=\'https://$config_base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key\'>$invoice_prefix$invoice_number</a>. Please keep this email as a receipt for your records.<br><br>Amount: " . numfmt_format_currency($currency_format, $pi_amount_paid, $invoice_currency_code) . "<br>Balance: " . numfmt_format_currency($currency_format, '0', $invoice_currency_code) . "<br><br>Thank you for your business!<br><br><br>~<br>$company_name - Billing<br>$config_invoice_from_email<br>$company_phone";

$data = [
[
'from' => $config_invoice_from_email,
'from_name' => $config_invoice_from_name,
'recipient' => $contact_email,
'recipient_name' => $contact_name,
'subject' => $subject,
'body' => $body,
]
$data = [
[
'from' => $config_invoice_from_email,
'from_name' => $config_invoice_from_name,
'recipient' => $contact_email,
'recipient_name' => $contact_name,
'subject' => $subject,
'body' => $body,
]
];


// Email the internal notification address too
if (!empty($config_invoice_paid_notification_email)) {
$subject = "Payment Received - $client_name - Invoice $invoice_prefix$invoice_number";
$body = "Hello, <br><br>This is a notification that an invoice has been paid in ITFlow. Below is a copy of the receipt sent to the client:-<br><br>--------<br><br>Hello $contact_name,<br><br>We have received your payment in the amount of " . $pi_currency . $pi_amount_paid . " for invoice <a href=\'https://$config_base_url/guest_view_invoice.php?invoice_id=$invoice_id&url_key=$invoice_url_key\'>$invoice_prefix$invoice_number</a>. Please keep this email as a receipt for your records.<br><br>Amount: " . numfmt_format_currency($currency_format, $pi_amount_paid, $invoice_currency_code) . "<br>Balance: " . numfmt_format_currency($currency_format, '0', $invoice_currency_code) . "<br><br>Thank you for your business!<br><br><br>~<br>$company_name - Billing<br>$config_invoice_from_email<br>$company_phone";

$data[] = [
'from' => $config_invoice_from_email,
'from_name' => $config_invoice_from_name,
'recipient' => $config_invoice_paid_notification_email,
'recipient_name' => $contact_name,
'subject' => $subject,
'body' => $body,
];
}

$mail = addToMailQueue($mysqli, $data);

// Email logging
Expand Down
6 changes: 5 additions & 1 deletion post/admin/admin_settings_invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
$config_invoice_late_fee_percent = floatval($_POST['config_invoice_late_fee_percent']);
$config_recurring_prefix = sanitizeInput($_POST['config_recurring_prefix']);
$config_recurring_next_number = intval($_POST['config_recurring_next_number']);
$config_invoice_paid_notification_email = '';
if (filter_var($_POST['config_invoice_paid_notification_email'], FILTER_VALIDATE_EMAIL)) {
$config_invoice_paid_notification_email = sanitizeInput($_POST['config_invoice_paid_notification_email']);
}


mysqli_query($mysqli,"UPDATE settings SET config_invoice_prefix = '$config_invoice_prefix', config_invoice_next_number = $config_invoice_next_number, config_invoice_footer = '$config_invoice_footer', config_invoice_late_fee_enable = $config_invoice_late_fee_enable, config_invoice_late_fee_percent = $config_invoice_late_fee_percent, config_recurring_prefix = '$config_recurring_prefix', config_recurring_next_number = $config_recurring_next_number WHERE company_id = 1");
mysqli_query($mysqli,"UPDATE settings SET config_invoice_prefix = '$config_invoice_prefix', config_invoice_next_number = $config_invoice_next_number, config_invoice_footer = '$config_invoice_footer', config_invoice_late_fee_enable = $config_invoice_late_fee_enable, config_invoice_late_fee_percent = $config_invoice_late_fee_percent, config_invoice_paid_notification_email = '$config_invoice_paid_notification_email', config_recurring_prefix = '$config_recurring_prefix', config_recurring_next_number = $config_recurring_next_number WHERE company_id = 1");

//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Edit', log_description = '$session_name edited invoice settings', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
Expand Down
5 changes: 4 additions & 1 deletion post/admin/admin_settings_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
$config_ticket_email_parse_unknown_senders = intval($_POST['config_ticket_email_parse_unknown_senders']);
$config_ticket_default_billable = intval($_POST['config_ticket_default_billable']);
$config_ticket_autoclose_hours = intval($_POST['config_ticket_autoclose_hours']);
$config_ticket_new_ticket_notification_email = sanitizeInput($_POST['config_ticket_new_ticket_notification_email']);
$config_ticket_new_ticket_notification_email = '';
if (filter_var($_POST['config_ticket_new_ticket_notification_email'], FILTER_VALIDATE_EMAIL)) {
$config_ticket_new_ticket_notification_email = sanitizeInput($_POST['config_ticket_new_ticket_notification_email']);
}

mysqli_query($mysqli,"UPDATE settings SET config_ticket_prefix = '$config_ticket_prefix', config_ticket_next_number = $config_ticket_next_number, config_ticket_email_parse = $config_ticket_email_parse, config_ticket_email_parse_unknown_senders = $config_ticket_email_parse_unknown_senders, config_ticket_autoclose_hours = $config_ticket_autoclose_hours, config_ticket_new_ticket_notification_email = '$config_ticket_new_ticket_notification_email', config_ticket_default_billable = $config_ticket_default_billable WHERE company_id = 1");

Expand Down

0 comments on commit a9de75a

Please sign in to comment.