diff --git a/cron.php b/cron.php index a156302c..db30d046 100644 --- a/cron.php +++ b/cron.php @@ -53,9 +53,9 @@ while($row = mysqli_fetch_array($sql_companies)){ foreach($domainAlertArray as $day){ //Get Domains Expiring - $sql = mysqli_query($mysqli,"SELECT * FROM domains, clients - WHERE domain_client_id = client_id - AND domain_expire = CURDATE() + INTERVAL $day DAY + $sql = mysqli_query($mysqli,"SELECT * FROM domains + LEFT JOIN clients ON domain_client_id = client_id + WHERE domain_expire = CURDATE() + INTERVAL $day DAY AND domains.company_id = $company_id" ); @@ -66,7 +66,7 @@ while($row = mysqli_fetch_array($sql_companies)){ $client_id = $row['client_id']; $client_name = $row['client_name']; - mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Domain', notification = 'Domain $domain_name for $client_name will expire in $day Days on $domain_expire', notification_timestamp = NOW(), company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Domain', notification = 'Domain $domain_name for $client_name will expire in $day Days on $domain_expire', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id"); } @@ -79,9 +79,9 @@ while($row = mysqli_fetch_array($sql_companies)){ foreach($certificateAlertArray as $day){ //Get Domains Expiring - $sql = mysqli_query($mysqli,"SELECT * FROM certificates, clients - WHERE certificate_client_id = client_id - AND certificate_expire = CURDATE() + INTERVAL $day DAY + $sql = mysqli_query($mysqli,"SELECT * FROM certificates + LEFT JOIN clients ON certificate_client_id = client_id + WHERE certificate_expire = CURDATE() + INTERVAL $day DAY AND certificates.company_id = $company_id" ); @@ -93,7 +93,33 @@ while($row = mysqli_fetch_array($sql_companies)){ $client_id = $row['client_id']; $client_name = $row['client_name']; - mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Certificate', notification = 'Certificate $certificate_name for $client_name will expire in $day Days on $certificate_expire', notification_timestamp = NOW(), company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Certificate', notification = 'Certificate $certificate_name for $client_name will expire in $day Days on $certificate_expire', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id"); + + } + + } + + // CERTIFICATES EXPIRING + + $warranty_alert_array = [1,7,14,30,90,120]; + + foreach($$warranty_alert_array as $day){ + + //Get Asset Warranty Expiring + $sql = mysqli_query($mysqli,"SELECT * FROM assets + LEFT JOIN clients ON asset_client_id = client_id + WHERE asset_warranty_expire = CURDATE() + INTERVAL $day DAY + AND assets.company_id = $company_id" + ); + + while($row = mysqli_fetch_array($sql)){ + $asset_id = $row['asset_id']; + $asset_name = $row['asset_name']; + $asset_warranty_expire = $row['asset_warranty_expire']; + $client_id = $row['client_id']; + $client_name = $row['client_name']; + + mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Asset', notification = 'Asset $asset_name warranty for $client_name will expire in $day Days on $asset_warranty_expire', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id"); } @@ -240,7 +266,7 @@ while($row = mysqli_fetch_array($sql_companies)){ //Send Recurring Invoices that match todays date and are active //Loop through all recurring that match today's date and is active - $sql_recurring = mysqli_query($mysqli,"SELECT * FROM recurring, clients WHERE client_id = recurring_client_id AND recurring_next_date = CURDATE() AND recurring_status = 1 AND recurring.company_id = $company_id"); + $sql_recurring = mysqli_query($mysqli,"SELECT * FROM recurring LEFT JOIN clients ON client_id = recurring_client_id WHERE recurring_next_date = CURDATE() AND recurring_status = 1 AND recurring.company_id = $company_id"); while($row = mysqli_fetch_array($sql_recurring)){ $recurring_id = $row['recurring_id']; @@ -365,4 +391,4 @@ while($row = mysqli_fetch_array($sql_companies)){ } //End Company Loop through -?> +?> \ No newline at end of file diff --git a/db.sql b/db.sql index 7893af17..346100c9 100644 --- a/db.sql +++ b/db.sql @@ -751,6 +751,7 @@ CREATE TABLE `notifications` ( `notification_timestamp` datetime NOT NULL, `notification_dismissed_at` datetime DEFAULT NULL, `notification_dismissed_by` int(11) DEFAULT NULL, + `notification_client_id` int(11) DEFAULT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`notification_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -1448,4 +1449,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-02-21 21:19:40 +-- Dump completed on 2022-02-21 21:41:35 diff --git a/guest_view_invoice.php b/guest_view_invoice.php index 84191986..0507d9af 100644 --- a/guest_view_invoice.php +++ b/guest_view_invoice.php @@ -96,7 +96,7 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){ //Prevent SQL Error if client_name has ' in their name example Bill's Market $client_name_escaped = mysqli_escape_string($mysqli,$client_name); - mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Invoice Viewed', notification = 'Invoice $invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_timestamp = NOW(), company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Invoice Viewed', notification = 'Invoice $invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id"); $sql_payments = mysqli_query($mysqli,"SELECT * FROM payments, accounts WHERE payment_account_id = account_id AND payment_invoice_id = $invoice_id ORDER BY payments.payment_id DESC");