diff --git a/alerts.php b/alerts.php
new file mode 100644
index 00000000..fbefa724
--- /dev/null
+++ b/alerts.php
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ | Date |
+ Type |
+ Alert |
+ Ack |
+ Actions |
+
+
+
+
+
+ |
+ |
+ |
+ |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ 0 ORDER BY invoice_number DESC");
+
+?>
+
+
+
+
+
+ | Number |
+ Amount |
+ Date |
+ Status |
+ Actions |
+
+
+
+
+
+
+ | QUO- |
+ $ |
+ $ |
+ |
+ |
+
+
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config.php b/config.php
index de1a225e..7bde514a 100644
--- a/config.php
+++ b/config.php
@@ -44,6 +44,8 @@
$_SESSION['alert_message'] = '';
$_SESSION['alert_type'] = "warning";
+ $config_account_balance_threshold = 200;
+
$net_terms_array = array(
diff --git a/create_recurring_invoices.php b/create_recurring_invoices.php
deleted file mode 100644
index 2eb7d6f3..00000000
--- a/create_recurring_invoices.php
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
diff --git a/cron.php b/cron.php
index 2b38e6f7..518ff6f3 100644
--- a/cron.php
+++ b/cron.php
@@ -2,12 +2,15 @@
CURDATE()
+ AND client_domain_expire = CURDATE() + INTERVAL 1 DAY
ORDER BY client_domain_id DESC"
);
@@ -18,11 +21,134 @@ while($row = mysqli_fetch_array($sql)){
$client_id = $row['client_id'];
$client_name = $row['client_name'];
- mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Domain', alert_message = 'Domain $client_domain_name Expiring on $client_domain_expire', alert_date = CURDATE()");
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Domain', alert_message = 'Domain $client_domain_name will expire tomorrow on $client_domain_expire', alert_date = CURDATE()");
}
-//Get Low Account Balances
+//Get Domains Expiring within 14 days
+$sql = mysqli_query($mysqli,"SELECT * FROM client_domains, clients
+ WHERE client_domains.client_id = clients.client_id
+ AND client_domain_expire = CURDATE() + INTERVAL 14 DAY
+ ORDER BY client_domain_id DESC"
+);
+
+while($row = mysqli_fetch_array($sql)){
+ $client_domain_id = $row['client_domain_id'];
+ $client_domain_name = $row['client_domain_name'];
+ $client_domain_expire = $row['client_domain_expire'];
+ $client_id = $row['client_id'];
+ $client_name = $row['client_name'];
+
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Domain', alert_message = 'Domain $client_domain_name will expire in 14 Days on $client_domain_expire', alert_date = CURDATE()");
+
+}
+
+//Get Domains Expiring within 30 days
+$sql = mysqli_query($mysqli,"SELECT * FROM client_domains, clients
+ WHERE client_domains.client_id = clients.client_id
+ AND client_domain_expire = CURDATE() + INTERVAL 30 DAY
+ ORDER BY client_domain_id DESC"
+);
+
+while($row = mysqli_fetch_array($sql)){
+ $client_domain_id = $row['client_domain_id'];
+ $client_domain_name = $row['client_domain_name'];
+ $client_domain_expire = $row['client_domain_expire'];
+ $client_id = $row['client_id'];
+ $client_name = $row['client_name'];
+
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Domain', alert_message = 'Domain $client_domain_name will expire in 30 Days on $client_domain_expire', alert_date = CURDATE()");
+
+}
+
+//Get Domains Expiring within 90 days
+$sql = mysqli_query($mysqli,"SELECT * FROM client_domains, clients
+ WHERE client_domains.client_id = clients.client_id
+ AND client_domain_expire = CURDATE() + INTERVAL 90 DAY
+ ORDER BY client_domain_id DESC"
+);
+
+while($row = mysqli_fetch_array($sql)){
+ $client_domain_id = $row['client_domain_id'];
+ $client_domain_name = $row['client_domain_name'];
+ $client_domain_expire = $row['client_domain_expire'];
+ $client_id = $row['client_id'];
+ $client_name = $row['client_name'];
+
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Domain', alert_message = 'Domain $client_domain_name will expire in 90 Days on $client_domain_expire', alert_date = CURDATE()");
+
+}
+
+//PAST DUE INVOICES
+
+//14 Days
+$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
+ WHERE invoices.client_id = clients.client_id
+ AND invoices.invoice_number > 0
+ AND invoices.invoice_status NOT LIKE 'Draft'
+ AND invoices.invoice_status NOT LIKE 'Paid'
+ AND invoices.invoice_due = CURDATE() + INTERVAL 14 DAY
+ ORDER BY invoices.invoice_number DESC"
+);
+
+while($row = mysqli_fetch_array($sql)){
+ $invoice_id = $row['invoice_id'];
+ $invoice_number = $row['invoice_number'];
+ $invoice_status = $row['invoice_status'];
+ $invoice_date = $row['invoice_date'];
+ $invoice_due = $row['invoice_due'];
+ $invoice_amount = $row['invoice_amount'];
+ $client_id = $row['client_id'];
+ $client_name = $row['client_name'];
+
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Invoice', alert_message = 'Invoice INV-$invoice_number for $client_name in the amount of $invoice_amount is overdue by 14 days', alert_date = CURDATE()");
+}
+
+//30 Days
+$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
+ WHERE invoices.client_id = clients.client_id
+ AND invoices.invoice_number > 0
+ AND invoices.invoice_status NOT LIKE 'Draft'
+ AND invoices.invoice_due = CURDATE() + INTERVAL 30 DAY
+ ORDER BY invoices.invoice_number DESC"
+);
+
+while($row = mysqli_fetch_array($sql)){
+ $invoice_id = $row['invoice_id'];
+ $invoice_number = $row['invoice_number'];
+ $invoice_status = $row['invoice_status'];
+ $invoice_date = $row['invoice_date'];
+ $invoice_due = $row['invoice_due'];
+ $invoice_amount = $row['invoice_amount'];
+ $client_id = $row['client_id'];
+ $client_name = $row['client_name'];
+
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Invoice', alert_message = 'Invoice INV-$invoice_number for $client_name in the amount of $invoice_amount is overdue by 30 days', alert_date = CURDATE()");
+}
+
+//90 Days
+$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
+ WHERE invoices.client_id = clients.client_id
+ AND invoices.invoice_number > 0
+ AND invoices.invoice_status NOT LIKE 'Draft'
+ AND invoices.invoice_due = CURDATE() + INTERVAL 90 DAY
+ ORDER BY invoices.invoice_number DESC"
+);
+
+while($row = mysqli_fetch_array($sql)){
+ $invoice_id = $row['invoice_id'];
+ $invoice_number = $row['invoice_number'];
+ $invoice_status = $row['invoice_status'];
+ $invoice_date = $row['invoice_date'];
+ $invoice_due = $row['invoice_due'];
+ $invoice_amount = $row['invoice_amount'];
+ $client_id = $row['client_id'];
+ $client_name = $row['client_name'];
+
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Invoice', alert_message = 'Invoice INV-$invoice_number for $client_name in the amount of $invoice_amount is overdue by 90 days', alert_date = CURDATE()");
+}
+
+//LOW BALANCE ALERTS
$sql = mysqli_query($mysqli,"SELECT * FROM accounts ORDER BY account_id DESC");
while($row = mysqli_fetch_array($sql)){
@@ -44,24 +170,18 @@ while($row = mysqli_fetch_array($sql)){
$balance = $opening_balance + $total_payments - $total_expenses;
- mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Low Balance', alert_message = 'Low Balance $$balance for $account_name', alert_date = CURDATE()");
+ if($balance < $config_account_balance_threshold){
+
+ mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Account Low Balance', alert_message = 'Threshold of $config_account_balance_threshold triggered low balance of $balance on account $account_name', alert_date = CURDATE()");
+ }
}
-//Get Overdue Invoices
+//Send Recurring Invoices that match todays date and are active
-$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_date_due > CURDATE() AND invoice_status NOT LIKE 'Paid' OR invoice_status NOT LIKE 'Draft' ORDER BY invoice_id DESC");
+$sql_recurring_invoices = mysqli_query($mysqli,"SELECT * FROM recurring_invoices, clients, invoices WHERE clients.client_id = invoices.client_id AND invoices.invoice_id = recurring_invoices.invoice_id AND recurring_invoices.recurring_invoice_next_date = CURDATE() AND recurring_invoices.recurring_invoice_status = 1");
-$invoice_id = $row['invoice_id'];
-$invoice_amount = $row['invoice_amount'];
-$invoice_date = $row['invoice_date'];
-$invoice_date_due = $row['invoice_date_due'];
-
-//Send Recurring Invoices
-
-$sql = mysqli_query($mysqli,"SELECT * FROM recurring_invoices, clients, invoices WHERE clients.client_id = invoices.client_id AND invoices.invoice_id = recurring_invoices.invoice_id AND recurring_invoices.recurring_invoice_next_date = CURDATE()");
-
-while($row = mysqli_fetch_array($sql)){
+while($row = mysqli_fetch_array($sql_recurring_invoices)){
$recurring_invoice_id = $row['recurring_invoice_id'];
$recurring_invoice_frequency = $row['recurring_invoice_frequency'];
$recurring_invoice_status = $row['recurring_invoice_status'];
@@ -75,13 +195,14 @@ while($row = mysqli_fetch_array($sql)){
$invoice_category_id = $row['category_id'];
$client_id = $row['client_id'];
$client_name = $row['client_name'];
+ $client_net_terms = $row['client_net_terms'];
//Get the last Invoice Number and add 1 for the new invoice number
- $sql = mysqli_query($mysqli,"SELECT invoice_number FROM invoices ORDER BY invoice_id DESC LIMIT 1");
- $row = mysqli_fetch_array($sql);
- $invoice_number = $row['invoice_number'] + 1;
+ $sql_invoice_number = mysqli_query($mysqli,"SELECT invoice_number FROM invoices ORDER BY invoice_number DESC LIMIT 1");
+ $row = mysqli_fetch_array($sql_invoice_number);
+ $new_invoice_number = $row['invoice_number'] + 1;
- mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = $invoice_number, invoice_date = CURDATE(), invoice_due = CURDATE(), invoice_amount = '$invoice_amount', invoice_note = '$invoice_note', category_id = $invoice_category_id, invoice_status = 'Sent', client_id = $client_id");
+ mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = $new_invoice_number, invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day) , invoice_amount = '$invoice_amount', invoice_note = '$invoice_note', category_id = $invoice_category_id, invoice_status = 'Sent', client_id = $client_id");
$new_invoice_id = mysqli_insert_id($mysqli);
@@ -104,11 +225,8 @@ while($row = mysqli_fetch_array($sql)){
mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Draft', invoice_history_description = 'INVOICE added!', invoice_id = $new_invoice_id");
- mysqli_query($mysqli,"UPDATE recurring_invoices SET recurring_invoice_last_sent = CURDATE(), recurring_invoice_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_invoice_frequency) , recurring_invoice_id = $recurring_invoice_id");
+ //update the recurring invoice with the new dates
+ mysqli_query($mysqli,"UPDATE recurring_invoices SET recurring_invoice_last_sent = CURDATE(), recurring_invoice_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_invoice_frequency) , invoice_id = $new_invoice_id WHERE recurring_invoice_id = $recurring_invoice_id");
+}
-
-//Send Past Due Invoice Reminders
-
-$sql = mysqli_query($mysqli,"SELECT * FROM accounts ORDER BY account_id DESC");
-
-?>
+?>
\ No newline at end of file
diff --git a/top_nav.php b/top_nav.php
index 62c33827..b0868e84 100644
--- a/top_nav.php
+++ b/top_nav.php
@@ -20,6 +20,18 @@