From 48fe49cf778b34e34112bdbdde49a74f88e11322 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 11 Mar 2023 16:16:46 -0500 Subject: [PATCH] BREAKING CHANGES - MAKE FULL BACKUP BEFORE PROCEEDING - Requires Manual Intervention on files see Forum Post Make sure you run the Database update directly after update. This Removes Multi-Company Functionality. Fixes issues with Reponsive tables and bunch of other UI and small Fixes --- accounts.php | 4 +- ajax.php | 26 +- api/v1/assets/create.php | 6 +- api/v1/assets/delete.php | 6 +- api/v1/assets/read.php | 41 - api/v1/assets/update.php | 8 +- api/v1/certificates/read.php | 8 +- api/v1/clients/read.php | 6 +- api/v1/contacts/create.php | 6 +- api/v1/contacts/delete.php | 6 +- api/v1/contacts/read.php | 6 +- api/v1/contacts/update.php | 8 +- api/v1/documents/read.php | 4 +- api/v1/domains/read.php | 8 +- api/v1/expenses/read.php | 4 +- api/v1/invoices/read.php | 4 +- api/v1/networks/read.php | 8 +- api/v1/payments/read.php | 6 +- api/v1/products/read.php | 4 +- api/v1/quotes/read.php | 4 +- api/v1/software/read.php | 12 +- api/v1/tickets/read.php | 4 +- api/v1/validate_api_key.php | 15 +- api_key_add_modal.php | 2 +- calendar_event_add_modal.php | 4 +- calendar_event_edit_modal.php | 4 +- calendar_events.php | 20 +- categories.php | 6 +- check_login.php | 30 +- client_add_modal.php | 4 +- client_assets.php | 2 +- client_certificates.php | 2 +- client_contact_details.php | 20 +- client_contact_edit_modal.php | 2 +- client_contacts.php | 12 +- client_document_add_from_template_modal.php | 2 +- client_document_templates.php | 3 +- client_documents.php | 3 +- client_domains.php | 2 +- client_edit_modal.php | 4 +- client_events.php | 4 +- client_file_view_modal.php | 2 +- client_files.php | 8 +- client_invoices.php | 2 +- client_location_edit_modal.php | 2 +- client_locations.php | 2 +- client_logins.php | 2 +- client_logs.php | 2 +- client_networks.php | 2 +- client_overview.php | 14 +- client_payments.php | 2 +- client_quotes.php | 2 +- client_recurring_invoices.php | 2 +- client_scheduled_tickets.php | 4 +- client_services.php | 2 +- client_shared_items.php | 2 +- client_software.php | 2 +- client_software_add_from_template_modal.php | 2 +- client_tickets.php | 2 +- client_trips.php | 3 +- client_vendors.php | 2 +- clients.php | 7 +- companies.php | 133 -- company_edit_modal.php | 195 --- cron.php | 1358 ++++++++--------- cron_ticket_email_parser.php | 39 +- dashboard_financial.php | 68 +- dashboard_technical.php | 23 +- database_updates.php | 58 +- database_version.php | 2 +- db.sql | 73 +- expense_add_modal.php | 6 +- expense_copy_modal.php | 6 +- expense_edit_modal.php | 11 +- expenses.php | 11 +- functions.php | 3 +- get_credential.php | 19 +- get_settings.php | 2 +- global_search.php | 14 +- guest_download_file.php | 5 +- guest_pay_invoice_stripe.php | 43 +- guest_post.php | 14 +- guest_view_invoice.php | 18 +- guest_view_item.php | 4 +- guest_view_quote.php | 20 +- inc_all_client.php | 21 +- invoice.php | 14 +- invoice_add_modal.php | 4 +- invoice_edit_modal.php | 2 +- invoice_payment_add_modal.php | 4 +- invoices.php | 33 +- item_edit_modal.php | 2 +- login.php | 6 +- logs.php | 2 +- models/user.php | 1 - notifications.php | 4 +- notifications_dismissed.php | 3 +- payments.php | 5 +- portal/check_login.php | 5 +- portal/inc_portal.php | 5 + portal/index.php | 2 +- portal/invoices.php | 2 +- portal/login.php | 2 +- portal/login_microsoft.php | 5 +- portal/login_reset.php | 16 +- portal/portal_footer.php | 2 +- portal/portal_header.php | 4 +- portal/portal_post.php | 22 +- post.php | 1523 ++++++++----------- product_add_modal.php | 4 +- product_edit_modal.php | 4 +- products.php | 5 +- quote.php | 15 +- quote_add_modal.php | 4 +- quote_edit_modal.php | 2 +- quotes.php | 5 +- recurring_invoice.php | 12 +- recurring_invoice_add_modal.php | 4 +- recurring_invoice_edit_modal.php | 2 +- recurring_invoices.php | 5 +- report_expense_by_vendor.php | 9 +- report_expense_summary.php | 10 +- report_income_by_client.php | 8 +- report_income_summary.php | 16 +- report_profit_loss.php | 36 +- report_recurring_by_client.php | 5 +- report_tax_summary.php | 6 +- report_ticket_by_client.php | 6 +- report_ticket_summary.php | 6 +- revenue_add_modal.php | 6 +- revenue_edit_modal.php | 6 +- revenues.php | 7 +- scheduled_ticket_add_modal.php | 2 +- scheduled_tickets.php | 2 +- settings_api.php | 6 +- settings_company.php | 177 +++ settings_side_nav.php | 14 +- settings_software_templates.php | 2 +- settings_tags.php | 6 +- settings_taxes.php | 3 +- setup.php | 61 +- side_nav.php | 43 +- ticket.php | 10 +- ticket_add_modal.php | 8 +- ticket_edit_modal.php | 4 +- ticket_invoice_add_modal.php | 6 +- tickets.php | 13 +- top_nav.php | 5 +- transfer_add_modal.php | 4 +- transfer_edit_modal.php | 4 +- transfers.php | 5 +- trip_add_modal.php | 4 +- trip_copy_modal.php | 2 +- trip_edit_modal.php | 2 +- trips.php | 3 +- uploads/clients/index.php | 1 - user_add_modal.php | 24 - user_companies_modal.php | 64 - user_edit_modal.php | 27 - user_invite_modal.php | 23 - user_profile.php | 8 +- users.php | 15 +- vendor_add_from_template_modal.php | 2 +- vendors.php | 3 +- 164 files changed, 2154 insertions(+), 2794 deletions(-) delete mode 100644 companies.php delete mode 100644 company_edit_modal.php create mode 100644 settings_company.php delete mode 100644 user_companies_modal.php diff --git a/accounts.php b/accounts.php index 8a17f890..0540b9c0 100644 --- a/accounts.php +++ b/accounts.php @@ -12,7 +12,7 @@ $url_query_strings_sb = http_build_query(array_merge($_GET, array('sb' => $sb, ' $sql = mysqli_query( $mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM accounts - WHERE account_name LIKE '%$q%' AND company_id = $session_company_id + WHERE account_name LIKE '%$q%' ORDER BY $sb $o LIMIT $record_from, $record_to" ); @@ -37,7 +37,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/ajax.php b/ajax.php index f743d7f4..b59f7ed6 100644 --- a/ajax.php +++ b/ajax.php @@ -70,7 +70,7 @@ if (isset($_GET['certificate_get_json_details'])) { } // Get all domains for this client that could be linked to this certificate - $domains_sql = mysqli_query($mysqli, "SELECT domain_id, domain_name FROM domains WHERE domain_client_id = '$client_id' AND company_id = '$session_company_id'"); + $domains_sql = mysqli_query($mysqli, "SELECT domain_id, domain_name FROM domains WHERE domain_client_id = $client_id"); while ($row = mysqli_fetch_array($domains_sql)) { $response['domains'][] = $row; } @@ -113,7 +113,7 @@ if (isset($_GET['merge_ticket_get_json_details'])) { $sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_number, ticket_prefix, ticket_subject, ticket_priority, ticket_status, client_name, contact_name FROM tickets LEFT JOIN clients ON ticket_client_id = client_id LEFT JOIN contacts ON ticket_contact_id = contact_id - WHERE ticket_number = '$merge_into_ticket_number' AND tickets.company_id = '$session_company_id'"); + WHERE ticket_number = $merge_into_ticket_number"); if (mysqli_num_rows($sql) == 0) { //Do nothing. @@ -144,7 +144,7 @@ if (isset($_GET['network_get_json_details'])) { $locations_sql = mysqli_query( $mysqli, "SELECT location_id, location_name FROM locations - WHERE location_client_id = '$client_id' AND company_id = '$session_company_id'" + WHERE location_client_id = '$client_id'" ); while ($row = mysqli_fetch_array($locations_sql)) { $response['locations'][] = $row; @@ -158,10 +158,10 @@ if (isset($_POST['client_set_notes'])) { $notes = sanitizeInput($_POST['notes']); // Update notes - mysqli_query($mysqli, "UPDATE clients SET client_notes = '$notes' WHERE client_id = '$client_id'"); + mysqli_query($mysqli, "UPDATE clients SET client_notes = '$notes' WHERE client_id = $client_id"); // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Client', log_action = 'Modify', log_description = '$session_name modified client notes', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_created_at = NOW(), log_client_id = $client_id, log_user_id = $session_user_id, company_id = $session_company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Client', log_action = 'Modify', log_description = '$session_name modified client notes', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id"); } @@ -173,7 +173,7 @@ if (isset($_POST['contact_set_notes'])) { mysqli_query($mysqli, "UPDATE contacts SET contact_notes = '$notes' WHERE contact_id = $contact_id"); // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Modify', log_description = '$session_name modified contact notes', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Modify', log_description = '$session_name modified contact notes', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id"); } @@ -185,7 +185,7 @@ if (isset($_POST['contact_set_notes'])) { if (isset($_GET['ticket_add_view'])) { $ticket_id = intval($_GET['ticket_id']); - mysqli_query($mysqli, "INSERT INTO ticket_views SET view_ticket_id = '$ticket_id', view_user_id = '$session_user_id', view_timestamp = NOW()"); + mysqli_query($mysqli, "INSERT INTO ticket_views SET view_ticket_id = $ticket_id, view_user_id = $session_user_id, view_timestamp = NOW()"); } /* @@ -196,7 +196,7 @@ if (isset($_GET['ticket_add_view'])) { if (isset($_GET['ticket_query_views'])) { $ticket_id = intval($_GET['ticket_id']); - $query = mysqli_query($mysqli, "SELECT user_name FROM ticket_views LEFT JOIN users ON view_user_id = user_id WHERE view_ticket_id = '$ticket_id' AND view_user_id != '$session_user_id' AND view_timestamp > DATE_SUB(NOW(), INTERVAL 2 MINUTE)"); + $query = mysqli_query($mysqli, "SELECT user_name FROM ticket_views LEFT JOIN users ON view_user_id = user_id WHERE view_ticket_id = $ticket_id AND view_user_id != $session_user_id AND view_timestamp > DATE_SUB(NOW(), INTERVAL 2 MINUTE)"); while ($row = mysqli_fetch_array($query)) { $users[] = $row['user_name']; } @@ -236,17 +236,17 @@ if (isset($_GET['share_generate_link'])) { $item_key = randomString(156); if ($item_type == "Document") { - $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT document_name FROM documents WHERE document_id = '$item_id' AND document_client_id = '$client_id' LIMIT 1")); + $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT document_name FROM documents WHERE document_id = $item_id AND document_client_id = $client_id LIMIT 1")); $item_name = sanitizeInput($row['document_name']); } if ($item_type == "File") { - $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT file_name FROM files WHERE file_id = '$item_id' AND file_client_id = '$client_id' LIMIT 1")); + $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT file_name FROM files WHERE file_id = $item_id AND file_client_id = $client_id LIMIT 1")); $item_name = sanitizeInput($row['file_name']); } if ($item_type == "Login") { - $login = mysqli_query($mysqli, "SELECT login_name, login_username, login_password FROM logins WHERE login_id = '$item_id' AND login_client_id = '$client_id' LIMIT 1"); + $login = mysqli_query($mysqli, "SELECT login_name, login_username, login_password FROM logins WHERE login_id = $item_id AND login_client_id = $client_id LIMIT 1"); $row = mysqli_fetch_array($login); $item_name = sanitizeInput($row['login_name']); @@ -266,7 +266,7 @@ if (isset($_GET['share_generate_link'])) { } // Insert entry into DB - $sql = mysqli_query($mysqli, "INSERT INTO shared_items SET item_active = '1', item_key = '$item_key', item_type = '$item_type', item_related_id = '$item_id', item_encrypted_username = '$item_encrypted_username', item_encrypted_credential = '$item_encrypted_credential', item_note = '$item_note', item_views = 0, item_view_limit = '$item_view_limit', item_created_at = NOW(), item_expire_at = '$item_expires', item_client_id = '$client_id'"); + $sql = mysqli_query($mysqli, "INSERT INTO shared_items SET item_active = 1, item_key = '$item_key', item_type = '$item_type', item_related_id = $item_id, item_encrypted_username = '$item_encrypted_username', item_encrypted_credential = '$item_encrypted_credential', item_note = '$item_note', item_views = 0, item_view_limit = $item_view_limit, item_expire_at = '$item_expires', item_client_id = $client_id"); $share_id = $mysqli->insert_id; // Return URL @@ -279,7 +279,7 @@ if (isset($_GET['share_generate_link'])) { echo json_encode($url); // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Sharing', log_action = 'Create', log_description = '$session_name created shared link for $item_type - $item_name', log_client_id = '$client_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Sharing', log_action = 'Create', log_description = '$session_name created shared link for $item_type - $item_name', log_client_id = $client_id, log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id"); } diff --git a/api/v1/assets/create.php b/api/v1/assets/create.php index 3d12db99..3b6b4105 100644 --- a/api/v1/assets/create.php +++ b/api/v1/assets/create.php @@ -11,14 +11,14 @@ $insert_id = false; if (!empty($name) && !empty($client_id)) { // Insert into Database - $insert_sql = mysqli_query($mysqli, "INSERT INTO assets SET asset_name = '$name', asset_type = '$type', asset_make = '$make', asset_model = '$model', asset_serial = '$serial', asset_os = '$os', asset_ip = '$aip', asset_mac = '$mac', asset_status = '$status', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_purchase_date = $purchase_date, asset_warranty_expire = $warranty_expire, asset_install_date = $install_date, asset_notes = '$notes', asset_network_id = $network, asset_client_id = $client_id, company_id = '$company_id'"); + $insert_sql = mysqli_query($mysqli, "INSERT INTO assets SET asset_name = '$name', asset_type = '$type', asset_make = '$make', asset_model = '$model', asset_serial = '$serial', asset_os = '$os', asset_ip = '$aip', asset_mac = '$mac', asset_status = '$status', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_purchase_date = $purchase_date, asset_warranty_expire = $warranty_expire, asset_install_date = $install_date, asset_notes = '$notes', asset_network_id = $network, asset_client_id = $client_id"); if ($insert_sql) { $insert_id = mysqli_insert_id($mysqli); //Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Asset', log_action = 'Created', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = '$client_id', company_id = $company_id"); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Created asset $name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = '$client_id', company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Asset', log_action = 'Created', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = '$client_id'"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Created asset $name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = '$client_id'"); } } diff --git a/api/v1/assets/delete.php b/api/v1/assets/delete.php index 8ce2e912..dfea6676 100644 --- a/api/v1/assets/delete.php +++ b/api/v1/assets/delete.php @@ -10,17 +10,17 @@ $asset_id = intval($_POST['asset_id']); $delete_count = false; if (!empty($asset_id)) { - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM assets WHERE asset_id = $asset_id AND asset_client_id = $client_id AND company_id = '$company_id' LIMIT 1")); + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM assets WHERE asset_id = $asset_id AND asset_client_id = $client_id LIMIT 1")); $asset_name = $row['asset_name']; - $delete_sql = mysqli_query($mysqli, "DELETE FROM assets WHERE asset_id = $asset_id AND asset_client_id = $client_id AND company_id = '$company_id' LIMIT 1"); + $delete_sql = mysqli_query($mysqli, "DELETE FROM assets WHERE asset_id = $asset_id AND asset_client_id = $client_id LIMIT 1"); // Check delete & get affected rows if ($delete_sql && !empty($asset_name)) { $delete_count = mysqli_affected_rows($mysqli); //Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Asset', log_action = 'Deleted', log_description = '$asset_name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Asset', log_action = 'Deleted', log_description = '$asset_name via API ($api_key_name)', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = $client_id"); } } diff --git a/api/v1/assets/read.php b/api/v1/assets/read.php index 33bd5484..e69de29b 100644 --- a/api/v1/assets/read.php +++ b/api/v1/assets/read.php @@ -1,41 +0,0 @@ - NOW() LIMIT 1"); @@ -72,7 +72,7 @@ if (isset($api_key)) { if (mysqli_num_rows($sql) !== 1) { // Invalid Key header(WORDING_UNAUTHORIZED); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Failed', log_description = 'Incorrect or expired key', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW()"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Failed', log_description = 'Incorrect or expired key', log_ip = '$ip', log_user_agent = '$user_agent'"); $return_arr['success'] = "False"; $return_arr['message'] = "Authentication failed. API key is invalid or has expired."; @@ -88,8 +88,7 @@ if (isset($api_key)) { // Set client ID, company ID & key name $row = mysqli_fetch_array($sql); $api_key_name = htmlentities($row['api_key_name']); - $client_id = $row['api_key_client_id']; - $company_id = $row['company_id']; + $client_id = intval($row['api_key_client_id']); // Set limit & offset for queries if (isset($_GET['limit'])) { diff --git a/api_key_add_modal.php b/api_key_add_modal.php index 23cefd42..0887420a 100644 --- a/api_key_add_modal.php +++ b/api_key_add_modal.php @@ -61,7 +61,7 @@ $key = randomString(156); diff --git a/calendar_event_add_modal.php b/calendar_event_add_modal.php index 14bff4af..6d2cb82f 100644 --- a/calendar_event_add_modal.php +++ b/calendar_event_add_modal.php @@ -48,7 +48,7 @@ - Client -- Client -
-
+
"> diff --git a/check_login.php b/check_login.php index cc1f9c65..bc0a98cc 100644 --- a/check_login.php +++ b/check_login.php @@ -26,7 +26,7 @@ if (!isset($_SESSION['logged']) || !$_SESSION['logged']) { $session_ip = sanitizeInput(getIP()); $session_user_agent = sanitizeInput($_SERVER['HTTP_USER_AGENT']); -$session_user_id = $_SESSION['user_id']; +$session_user_id = intval($_SESSION['user_id']); $sql = mysqli_query($mysqli, "SELECT * FROM users, user_settings WHERE users.user_id = user_settings.user_id AND users.user_id = $session_user_id"); $row = mysqli_fetch_array($sql); @@ -34,8 +34,7 @@ $session_name = sanitizeInput($row['user_name']); $session_email = $row['user_email']; $session_avatar = $row['user_avatar']; $session_token = $row['user_token']; -$session_company_id = $row['user_default_company']; -$session_user_role = $row['user_role']; +$session_user_role = intval($row['user_role']); if ($session_user_role == 3) { $session_user_role_display = "Administrator"; } elseif ($session_user_role == 2) { @@ -44,22 +43,7 @@ if ($session_user_role == 3) { $session_user_role_display = "Accountant"; } -//LOAD USER COMPANY ACCESS PERMISSIONS -$session_user_company_access_sql = mysqli_query($mysqli, "SELECT company_id FROM user_companies WHERE user_id = $session_user_id"); -$session_user_company_access_array = array(); -while ($row = mysqli_fetch_array($session_user_company_access_sql)) { - $session_user_company_access_array[] = $row['company_id']; -} -$session_user_company_access = implode(',', $session_user_company_access_array); - -//Check to see if user has rights to company Prevents User from access a company he is not allowed to have access to. -if (!in_array($session_company_id, $session_user_company_access_array)) { - session_start(); - session_destroy(); - header('Location: login.php'); -} - -$sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = $session_company_id"); +$sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = 1"); $row = mysqli_fetch_array($sql); $session_company_name = $row['company_name']; @@ -67,6 +51,9 @@ $session_company_country = $row['company_country']; $session_company_locale = $row['company_locale']; $session_company_currency = $row['company_currency']; +//Set Currency Format +$currency_format = numfmt_create($session_company_locale, NumberFormatter::CURRENCY); + require_once("get_settings.php"); //Detects if using an Apple device and uses Apple Maps instead of google @@ -81,10 +68,7 @@ if ($iPod || $iPhone || $iPad) { } //Get Notification Count for the badge on the top nav -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('notification_id') AS num FROM notifications WHERE (notification_user_id = $session_user_id OR notification_user_id = 0) AND notification_dismissed_at IS NULL AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('notification_id') AS num FROM notifications WHERE (notification_user_id = $session_user_id OR notification_user_id = 0) AND notification_dismissed_at IS NULL")); $num_notifications = $row['num']; -//Set Currency Format -$currency_format = numfmt_create($session_company_locale, NumberFormatter::CURRENCY); - diff --git a/client_add_modal.php b/client_add_modal.php index 602563b8..4409203b 100644 --- a/client_add_modal.php +++ b/client_add_modal.php @@ -64,7 +64,7 @@ @@ -271,7 +271,7 @@

    -
    +
"> diff --git a/client_certificates.php b/client_certificates.php index cb712070..53f39589 100644 --- a/client_certificates.php +++ b/client_certificates.php @@ -61,7 +61,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
diff --git a/client_contact_details.php b/client_contact_details.php index 4eaf91da..a3213bef 100644 --- a/client_contact_details.php +++ b/client_contact_details.php @@ -40,28 +40,28 @@ if (isset($_GET['contact_id'])) { $auth_method = htmlentities($row['contact_auth_method']); // Related Assets Query - $sql_related_assets = mysqli_query($mysqli, "SELECT * FROM assets LEFT JOIN logins ON logins.login_asset_id = assets.asset_id WHERE asset_contact_id = $contact_id AND assets.company_id = $session_company_id ORDER BY asset_name DESC"); + $sql_related_assets = mysqli_query($mysqli, "SELECT * FROM assets LEFT JOIN logins ON logins.login_asset_id = assets.asset_id WHERE asset_contact_id = $contact_id ORDER BY asset_name DESC"); $asset_count = mysqli_num_rows($sql_related_assets); // Related Logins Query - $sql_related_logins = mysqli_query($mysqli, "SELECT * FROM logins WHERE login_contact_id = $contact_id AND company_id = $session_company_id ORDER BY login_name DESC"); + $sql_related_logins = mysqli_query($mysqli, "SELECT * FROM logins WHERE login_contact_id = $contact_id ORDER BY login_name DESC"); $login_count = mysqli_num_rows($sql_related_logins); // Related Software Query - //$sql_related_software = mysqli_query($mysqli, "SELECT * FROM software, software_contacts WHERE software.software_id = software_contacts.software_id AND software_contacts.contact_id = $contact_id AND software.company_id = $session_company_id ORDER BY software.software_id DESC"); + //$sql_related_software = mysqli_query($mysqli, "SELECT * FROM software, software_contacts WHERE software.software_id = software_contacts.software_id AND software_contacts.contact_id = $contact_id ORDER BY software.software_id DESC"); $sql_related_software = mysqli_query( $mysqli, "SELECT * FROM software_contacts LEFT JOIN software ON software_contacts.software_id = software.software_id LEFT JOIN logins on software.software_id = logins.login_software_id - WHERE software_contacts.contact_id = $contact_id AND software.company_id = $session_company_id + WHERE software_contacts.contact_id = $contact_id ORDER BY software.software_id DESC" ); $software_count = mysqli_num_rows($sql_related_software); // Related Tickets Query - $sql_related_tickets = mysqli_query($mysqli, "SELECT * FROM tickets LEFT JOIN users on ticket_assigned_to = user_id WHERE ticket_contact_id = $contact_id AND company_id = $session_company_id ORDER BY ticket_id DESC"); + $sql_related_tickets = mysqli_query($mysqli, "SELECT * FROM tickets LEFT JOIN users on ticket_assigned_to = user_id WHERE ticket_contact_id = $contact_id ORDER BY ticket_id DESC"); $ticket_count = mysqli_num_rows($sql_related_tickets); ?> @@ -79,7 +79,7 @@ if (isset($_GET['contact_id'])) {
- contact_photo"> + contact_photo"> @@ -146,7 +146,7 @@ if (isset($_GET['contact_id'])) {

Assets

-
+
@@ -269,7 +269,7 @@ if (isset($_GET['contact_id'])) {

Passwords

-
+
@@ -370,7 +370,7 @@ if (isset($_GET['contact_id'])) {

Licenses

-
+
@@ -465,7 +465,7 @@ if (isset($_GET['contact_id'])) {

Tickets

-
+
diff --git a/client_contact_edit_modal.php b/client_contact_edit_modal.php index 1d537805..332ba949 100644 --- a/client_contact_edit_modal.php +++ b/client_contact_edit_modal.php @@ -209,7 +209,7 @@
- contact_photo"> + contact_photo"> diff --git a/client_contacts.php b/client_contacts.php index 49a770bc..e3d57f58 100644 --- a/client_contacts.php +++ b/client_contacts.php @@ -60,7 +60,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

-
+
"> @@ -132,19 +132,19 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $auth_method = htmlentities($row['contact_auth_method']); // Related Assets Query - $sql_related_assets = mysqli_query($mysqli, "SELECT * FROM assets WHERE asset_contact_id = $contact_id AND company_id = $session_company_id ORDER BY asset_id DESC"); + $sql_related_assets = mysqli_query($mysqli, "SELECT * FROM assets WHERE asset_contact_id = $contact_id ORDER BY asset_id DESC"); $asset_count = mysqli_num_rows($sql_related_assets); // Related Logins Query - $sql_related_logins = mysqli_query($mysqli, "SELECT * FROM logins WHERE login_contact_id = $contact_id AND company_id = $session_company_id ORDER BY login_id DESC"); + $sql_related_logins = mysqli_query($mysqli, "SELECT * FROM logins WHERE login_contact_id = $contact_id ORDER BY login_id DESC"); $login_count = mysqli_num_rows($sql_related_logins); // Related Software Query - $sql_related_software = mysqli_query($mysqli, "SELECT * FROM software, software_contacts WHERE software.software_id = software_contacts.software_id AND software_contacts.contact_id = $contact_id AND software.company_id = $session_company_id ORDER BY software.software_id DESC"); + $sql_related_software = mysqli_query($mysqli, "SELECT * FROM software, software_contacts WHERE software.software_id = software_contacts.software_id AND software_contacts.contact_id = $contact_id ORDER BY software.software_id DESC"); $software_count = mysqli_num_rows($sql_related_software); // Related Tickets Query - $sql_related_tickets = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_contact_id = $contact_id AND company_id = $session_company_id ORDER BY ticket_id DESC"); + $sql_related_tickets = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_contact_id = $contact_id ORDER BY ticket_id DESC"); $ticket_count = mysqli_num_rows($sql_related_tickets); ?> @@ -153,7 +153,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - "> + "> diff --git a/client_document_add_from_template_modal.php b/client_document_add_from_template_modal.php index 7df8beae..bd07dbf3 100644 --- a/client_document_add_from_template_modal.php +++ b/client_document_add_from_template_modal.php @@ -20,7 +20,7 @@
"> diff --git a/client_documents.php b/client_documents.php index af14d143..9656a0c3 100644 --- a/client_documents.php +++ b/client_documents.php @@ -33,7 +33,6 @@ $sql = mysqli_query( $mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM documents WHERE document_client_id = $client_id - AND documents.company_id = $session_company_id AND document_template = 0 AND document_folder_id = $folder $query_snippet @@ -150,7 +149,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_domains.php b/client_domains.php index 054afd26..125c3538 100644 --- a/client_domains.php +++ b/client_domains.php @@ -48,7 +48,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_edit_modal.php b/client_edit_modal.php index 55d972ee..3073eb1b 100644 --- a/client_edit_modal.php +++ b/client_edit_modal.php @@ -59,7 +59,7 @@ '$client_created_at' OR category_archived_at IS NULL) AND company_id = $session_company_id ORDER BY category_name ASC"); + $referral_sql = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Referral' AND (category_archived_at > '$client_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC"); while ($row = mysqli_fetch_array($referral_sql)) { $referral = htmlentities($row['category_name']); ?> @@ -137,7 +137,7 @@
- "> + ">
diff --git a/client_files.php b/client_files.php index bfa570d2..67566805 100644 --- a/client_files.php +++ b/client_files.php @@ -39,10 +39,10 @@ $num_of_files = mysqli_num_rows($sql_files_images) + mysqli_num_rows($sql_files_
- + diff --git a/client_invoices.php b/client_invoices.php index 3a7164b2..a942d834 100644 --- a/client_invoices.php +++ b/client_invoices.php @@ -52,7 +52,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
" target="_blank" class="text-secondary"> " target="_blank" class="text-secondary"> - " download="" class="text-secondary float-left ml-1"> + " download="" class="text-secondary float-left ml-1"> )" class="text-secondary float-left ml-1">
"> diff --git a/client_location_edit_modal.php b/client_location_edit_modal.php index 1e4e2ded..7462c001 100644 --- a/client_location_edit_modal.php +++ b/client_location_edit_modal.php @@ -158,7 +158,7 @@
- "> + ">
diff --git a/client_locations.php b/client_locations.php index 8b22ee13..7795a270 100644 --- a/client_locations.php +++ b/client_locations.php @@ -53,7 +53,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_logins.php b/client_logins.php index 858a9f61..891dde73 100644 --- a/client_logins.php +++ b/client_logins.php @@ -52,7 +52,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_logs.php b/client_logs.php index 48257bdb..54b944b7 100644 --- a/client_logs.php +++ b/client_logs.php @@ -47,7 +47,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_networks.php b/client_networks.php index b9e11b8c..615b3ef3 100644 --- a/client_networks.php +++ b/client_networks.php @@ -52,7 +52,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_overview.php b/client_overview.php index 66948278..c427bca6 100644 --- a/client_overview.php +++ b/client_overview.php @@ -2,17 +2,17 @@ require_once("inc_all_client.php"); -$sql_contacts = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_client_id = $client_id AND contact_archived_at IS NULL AND contacts.company_id = $session_company_id ORDER BY contact_updated_at, contact_created_at DESC LIMIT 5"); +$sql_contacts = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_client_id = $client_id AND contact_archived_at IS NULL ORDER BY contact_updated_at, contact_created_at DESC LIMIT 5"); -$sql_important_contacts = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_client_id = $client_id AND (contact_important = 1 OR contact_billing = 1 OR contact_technical = 1 OR contact_id = $primary_contact) AND contact_archived_at IS NULL AND contacts.company_id = $session_company_id ORDER BY contact_name DESC"); +$sql_important_contacts = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_client_id = $client_id AND (contact_important = 1 OR contact_billing = 1 OR contact_technical = 1 OR contact_id = $primary_contact) AND contact_archived_at IS NULL ORDER BY contact_name DESC"); -$sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors WHERE vendor_client_id = $client_id AND vendor_template = 0 AND vendor_archived_at IS NULL AND company_id = $session_company_id ORDER BY vendor_updated_at DESC LIMIT 5"); +$sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors WHERE vendor_client_id = $client_id AND vendor_template = 0 AND vendor_archived_at IS NULL ORDER BY vendor_updated_at DESC LIMIT 5"); -$sql_documents = mysqli_query($mysqli, "SELECT * FROM documents WHERE document_client_id = $client_id AND document_archived_at IS NULL AND documents.company_id = $session_company_id ORDER BY document_updated_at DESC LIMIT 5"); +$sql_documents = mysqli_query($mysqli, "SELECT * FROM documents WHERE document_client_id = $client_id AND document_archived_at IS NULL ORDER BY document_updated_at DESC LIMIT 5"); -$sql_tickets = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_client_id = $client_id AND tickets.company_id = $session_company_id ORDER BY ticket_updated_at DESC LIMIT 5"); +$sql_tickets = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_client_id = $client_id ORDER BY ticket_updated_at DESC LIMIT 5"); -$sql_logins = mysqli_query($mysqli, "SELECT * FROM logins WHERE login_client_id = $client_id AND company_id = $session_company_id ORDER BY login_updated_at DESC LIMIT 5"); +$sql_logins = mysqli_query($mysqli, "SELECT * FROM logins WHERE login_client_id = $client_id ORDER BY login_updated_at DESC LIMIT 5"); // Expiring Items @@ -24,7 +24,7 @@ $sql_domains_expiring = mysqli_query( AND domain_expire != '0000-00-00' AND domain_archived_at IS NULL AND domain_expire < CURRENT_DATE + INTERVAL 30 DAY - AND company_id = $session_company_id ORDER BY domain_expire DESC" + ORDER BY domain_expire DESC" ); ?> diff --git a/client_payments.php b/client_payments.php index 037640bd..131ddb7b 100644 --- a/client_payments.php +++ b/client_payments.php @@ -50,7 +50,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_quotes.php b/client_quotes.php index dace3b79..7157c4c5 100644 --- a/client_quotes.php +++ b/client_quotes.php @@ -52,7 +52,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_recurring_invoices.php b/client_recurring_invoices.php index 1a1706ce..fbc46d0e 100644 --- a/client_recurring_invoices.php +++ b/client_recurring_invoices.php @@ -51,7 +51,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_scheduled_tickets.php b/client_scheduled_tickets.php index ef6133b4..1af0b8f1 100644 --- a/client_scheduled_tickets.php +++ b/client_scheduled_tickets.php @@ -1,4 +1,4 @@ -
-
+
diff --git a/client_services.php b/client_services.php index 34d94918..4eaed93e 100644 --- a/client_services.php +++ b/client_services.php @@ -42,7 +42,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_shared_items.php b/client_shared_items.php index 1e1f8660..13fff759 100644 --- a/client_shared_items.php +++ b/client_shared_items.php @@ -44,7 +44,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_software.php b/client_software.php index a34af2d9..76ea74db 100644 --- a/client_software.php +++ b/client_software.php @@ -60,7 +60,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_software_add_from_template_modal.php b/client_software_add_from_template_modal.php index e8fbe085..49d95831 100644 --- a/client_software_add_from_template_modal.php +++ b/client_software_add_from_template_modal.php @@ -20,7 +20,7 @@
"> diff --git a/client_trips.php b/client_trips.php index c17880a8..e0a8c854 100644 --- a/client_trips.php +++ b/client_trips.php @@ -15,7 +15,6 @@ $sql = mysqli_query( LEFT JOIN users ON trip_user_id = user_id WHERE (trip_purpose LIKE '%$q%' OR trip_source LIKE '%$q%' OR trip_destination LIKE '%$q%' OR user_name LIKE '%$q%') AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt' - AND company_id = $session_company_id AND trip_client_id = $client_id ORDER BY $sb $o LIMIT $record_from, $record_to"); @@ -54,7 +53,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/client_vendors.php b/client_vendors.php index 2f38e5ec..c498f48b 100644 --- a/client_vendors.php +++ b/client_vendors.php @@ -61,7 +61,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/clients.php b/clients.php index 4bdfbdbb..cc571285 100644 --- a/clients.php +++ b/clients.php @@ -20,7 +20,6 @@ $sql = mysqli_query( OR contact_mobile LIKE '%$phone_query%' OR location_address LIKE '%$q%' OR location_city LIKE '%$q%' OR location_state LIKE '%$q%' OR location_zip LIKE '%$q%' OR tag_name LIKE '%$q%') AND client_archived_at IS NULL AND DATE(client_created_at) BETWEEN '$dtf' AND '$dtt' - AND clients.company_id = $session_company_id GROUP BY clients.client_id ORDER BY $sb $o LIMIT $record_from, $record_to "); @@ -86,7 +85,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> @@ -175,13 +174,13 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); } //Get Monthly Recurring Total - $sql_recurring_monthly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month' AND recurring_client_id = $client_id AND company_id = $session_company_id"); + $sql_recurring_monthly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month' AND recurring_client_id = $client_id"); $row = mysqli_fetch_array($sql_recurring_monthly_total); $recurring_monthly_total = floatval($row['recurring_monthly_total']); //Get Yearly Recurring Total - $sql_recurring_yearly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year' AND recurring_client_id = $client_id AND company_id = $session_company_id"); + $sql_recurring_yearly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year' AND recurring_client_id = $client_id"); $row = mysqli_fetch_array($sql_recurring_yearly_total); $recurring_yearly_total = floatval($row['recurring_yearly_total']) / 12; diff --git a/companies.php b/companies.php deleted file mode 100644 index 9d8fb354..00000000 --- a/companies.php +++ /dev/null @@ -1,133 +0,0 @@ - $sb, 'o' => $o))); - -$sql = mysqli_query( - $mysqli, - "SELECT SQL_CALC_FOUND_ROWS * FROM companies, settings - WHERE companies.company_id = settings.company_id - AND (company_name LIKE '%$q%') - ORDER BY $sb $o LIMIT $record_from, $record_to"); - -$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - -?> - -
-
-

Companies

-
-
- -
-
-
- -
- -
-
- -
-
-
- "> - - - - - - - - - - - - - - - - - - - - - - - - -
NameAddressPhoneEmailWebsiteAction
- - - "> - - - - - -
- - -
-
-
- -
-
- -
- - -" tabindex="-1"> - - diff --git a/cron.php b/cron.php index 76e9f38e..7dd30869 100644 --- a/cron.php +++ b/cron.php @@ -3,793 +3,783 @@ require_once("config.php"); require_once("functions.php"); -$sql_companies = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id"); +$sql_companies = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id AND companies.company_id = 1"); -while ($row = mysqli_fetch_array($sql_companies)) { - $company_id = intval($row['company_id']); - $company_name = $row['company_name']; - $company_phone = formatPhoneNumber($row['company_phone']); - $company_email = $row['company_email']; - $company_website = $row['company_website']; - $company_city = $row['company_city']; - $company_state = $row['company_state']; - $company_country = $row['company_country']; - $company_locale = $row['company_locale']; - $company_currency = $row['company_currency']; - $config_enable_cron = intval($row['config_enable_cron']); - $config_invoice_overdue_reminders = $row['config_invoice_overdue_reminders']; - $config_invoice_prefix = $row['config_invoice_prefix']; - $config_invoice_from_email = $row['config_invoice_from_email']; - $config_invoice_from_name = $row['config_invoice_from_name']; - $config_smtp_host = $row['config_smtp_host']; - $config_smtp_username = $row['config_smtp_username']; - $config_smtp_password = $row['config_smtp_password']; - $config_smtp_port = intval($row['config_smtp_port']); - $config_smtp_encryption = $row['config_smtp_encryption']; - $config_mail_from_email = $row['config_mail_from_email']; - $config_mail_from_name = $row['config_mail_from_name']; - $config_recurring_auto_send_invoice = intval($row['config_recurring_auto_send_invoice']); +$row = mysqli_fetch_array($sql_companies); - // Tickets - $config_ticket_prefix = $row['config_ticket_prefix']; - $config_ticket_next_number = intval($row['config_ticket_next_number']); - $config_ticket_from_name = $row['config_ticket_from_name']; - $config_ticket_from_email = $row['config_ticket_from_email']; - $config_ticket_client_general_notifications = intval($row['config_ticket_client_general_notifications']); +// Company Details +$company_name = $row['company_name']; +$company_phone = formatPhoneNumber($row['company_phone']); +$company_email = $row['company_email']; +$company_website = $row['company_website']; +$company_city = $row['company_city']; +$company_state = $row['company_state']; +$company_country = $row['company_country']; +$company_locale = $row['company_locale']; +$company_currency = $row['company_currency']; - //Get Config for Telemetry - $config_theme = $row['config_theme']; - $config_ticket_email_parse = intval($row['config_ticket_email_parse']); - $config_module_enable_itdoc = intval($row['config_module_enable_itdoc']); - $config_module_enable_ticketing = intval($row['config_module_enable_ticketing']); - $config_module_enable_accounting = $row['config_module_enable_accounting']; - $config_telemetry = intval($row['config_telemetry']); +// Company Settings +$config_enable_cron = intval($row['config_enable_cron']); +$config_invoice_overdue_reminders = $row['config_invoice_overdue_reminders']; +$config_invoice_prefix = $row['config_invoice_prefix']; +$config_invoice_from_email = $row['config_invoice_from_email']; +$config_invoice_from_name = $row['config_invoice_from_name']; +$config_smtp_host = $row['config_smtp_host']; +$config_smtp_username = $row['config_smtp_username']; +$config_smtp_password = $row['config_smtp_password']; +$config_smtp_port = intval($row['config_smtp_port']); +$config_smtp_encryption = $row['config_smtp_encryption']; +$config_mail_from_email = $row['config_mail_from_email']; +$config_mail_from_name = $row['config_mail_from_name']; +$config_recurring_auto_send_invoice = intval($row['config_recurring_auto_send_invoice']); - // Set Currency Format - $currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY); +// Tickets +$config_ticket_prefix = $row['config_ticket_prefix']; +$config_ticket_next_number = intval($row['config_ticket_next_number']); +$config_ticket_from_name = $row['config_ticket_from_name']; +$config_ticket_from_email = $row['config_ticket_from_email']; +$config_ticket_client_general_notifications = intval($row['config_ticket_client_general_notifications']); - // Check cron is enabled - if ($config_enable_cron == 1) { +//Get Config for Telemetry +$config_theme = $row['config_theme']; +$config_ticket_email_parse = intval($row['config_ticket_email_parse']); +$config_module_enable_itdoc = intval($row['config_module_enable_itdoc']); +$config_module_enable_ticketing = intval($row['config_module_enable_ticketing']); +$config_module_enable_accounting = $row['config_module_enable_accounting']; +$config_telemetry = intval($row['config_telemetry']); - /* - * ############################################################################################################### - * STARTUP ACTIONS - * ############################################################################################################### - */ +// Set Currency Format +$currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY); - //Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Started', log_description = 'Cron started for $company_name', company_id = $company_id"); +// Check cron is enabled +if ($config_enable_cron == 1) { + + /* + * ############################################################################################################### + * STARTUP ACTIONS + * ############################################################################################################### + */ + + //Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Started', log_description = 'Cron started for $company_name'"); - /* - * ############################################################################################################### - * CLEAN UP (OLD) DATA - * ############################################################################################################### - */ + /* + * ############################################################################################################### + * CLEAN UP (OLD) DATA + * ############################################################################################################### + */ - // Clean-up ticket views table used for collision detection - mysqli_query($mysqli, "TRUNCATE TABLE ticket_views"); + // Clean-up ticket views table used for collision detection + mysqli_query($mysqli, "TRUNCATE TABLE ticket_views"); - // Clean-up shared items that have been used - mysqli_query($mysqli, "DELETE FROM shared_items WHERE item_views = item_view_limit"); + // Clean-up shared items that have been used + mysqli_query($mysqli, "DELETE FROM shared_items WHERE item_views = item_view_limit"); - // Clean-up shared items that have expired - mysqli_query($mysqli, "DELETE FROM shared_items WHERE item_expire_at < NOW()"); + // Clean-up shared items that have expired + mysqli_query($mysqli, "DELETE FROM shared_items WHERE item_expire_at < NOW()"); - // Invalidate any password reset links - mysqli_query($mysqli, "UPDATE contacts SET contact_password_reset_token = NULL WHERE contact_archived_at IS NULL"); + // Invalidate any password reset links + mysqli_query($mysqli, "UPDATE contacts SET contact_password_reset_token = NULL WHERE contact_archived_at IS NULL"); - // Clean-up old dismissed notifications - mysqli_query($mysqli, "DELETE FROM notifications WHERE notification_dismissed_at < CURDATE() - INTERVAL 90 DAY"); + // Clean-up old dismissed notifications + mysqli_query($mysqli, "DELETE FROM notifications WHERE notification_dismissed_at < CURDATE() - INTERVAL 90 DAY"); - //Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron cleaned up old data', company_id = $company_id"); + //Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron cleaned up old data'"); - /* - * ############################################################################################################### - * REFRESH DATA - * ############################################################################################################### - */ - // 2023-02-20 JQ Commenting this code out as its intermitently breaking cron executions, investigating - // ERROR - // php cron.php - // PHP Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in cron.php:141 - // Stack trace: - //#0 cron.php(141): mysqli_fetch_array() - //#1 {main} - // thrown in cron.php on line 141 - // END ERROR - // REFRESH DOMAIN WHOIS DATA (1 a day) - // Get the oldest updated domain (MariaDB shows NULLs first when ordering by default) - //$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT domain_id, domain_name FROM `domains` WHERE company_id = $company_id ORDER BY domain_updated_at LIMIT 1")); + /* + * ############################################################################################################### + * REFRESH DATA + * ############################################################################################################### + */ + // 2023-02-20 JQ Commenting this code out as its intermitently breaking cron executions, investigating + // ERROR + // php cron.php + // PHP Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in cron.php:141 + // Stack trace: + //#0 cron.php(141): mysqli_fetch_array() + //#1 {main} + // thrown in cron.php on line 141 + // END ERROR + // REFRESH DOMAIN WHOIS DATA (1 a day) + // Get the oldest updated domain (MariaDB shows NULLs first when ordering by default) + //$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT domain_id, domain_name FROM `domains` ORDER BY domain_updated_at LIMIT 1")); - //if ($row) { - // $domain_id = intval($row['domain_id']); - // $domain_name = sanitizeInput($row['domain_name']); + //if ($row) { + // $domain_id = intval($row['domain_id']); + // $domain_name = sanitizeInput($row['domain_name']); - // $expire = getDomainExpirationDate($domain_name); - // $records = getDomainRecords($domain_name); - // $a = sanitizeInput($records['a']); - // $ns = sanitizeInput($records['ns']); - // $mx = sanitizeInput($records['mx']); - // $txt = sanitizeInput($records['txt']); - // $whois = sanitizeInput($records['whois']); + // $expire = getDomainExpirationDate($domain_name); + // $records = getDomainRecords($domain_name); + // $a = sanitizeInput($records['a']); + // $ns = sanitizeInput($records['ns']); + // $mx = sanitizeInput($records['mx']); + // $txt = sanitizeInput($records['txt']); + // $whois = sanitizeInput($records['whois']); - // Update the domain - // mysqli_query($mysqli, "UPDATE domains SET domain_name = '$domain_name', domain_expire = '$expire', domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois' WHERE domain_id = $domain_id"); - //} + // Update the domain + // mysqli_query($mysqli, "UPDATE domains SET domain_name = '$domain_name', domain_expire = '$expire', domain_ip = '$a', domain_name_servers = '$ns', domain_mail_servers = '$mx', domain_txt = '$txt', domain_raw_whois = '$whois' WHERE domain_id = $domain_id"); + //} - // TODO: Re-add the cert refresher + // TODO: Re-add the cert refresher - /* - * ############################################################################################################### - * ACTION DATA - * ############################################################################################################### - */ + /* + * ############################################################################################################### + * ACTION DATA + * ############################################################################################################### + */ - // GET NOTIFICATIONS + // GET NOTIFICATIONS - // DOMAINS EXPIRING + // DOMAINS EXPIRING - $domainAlertArray = [1,7,14,30,90,120]; + $domainAlertArray = [1,7,14,30,90,120]; - foreach ($domainAlertArray as $day) { + foreach ($domainAlertArray as $day) { - //Get Domains Expiring - $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" - ); + //Get Domains Expiring + $sql = mysqli_query( + $mysqli, + "SELECT * FROM domains + LEFT JOIN clients ON domain_client_id = client_id + WHERE domain_expire = CURDATE() + INTERVAL $day DAY" + ); - while ($row = mysqli_fetch_array($sql)) { - $domain_id = intval($row['domain_id']); - $domain_name = sanitizeInput($row['domain_name']); - $domain_expire = sanitizeInput($row['domain_expire']); - $client_id = intval($row['client_id']); - $client_name = sanitizeInput($row['client_name']); + while ($row = mysqli_fetch_array($sql)) { + $domain_id = intval($row['domain_id']); + $domain_name = sanitizeInput($row['domain_name']); + $domain_expire = sanitizeInput($row['domain_expire']); + $client_id = intval($row['client_id']); + $client_name = sanitizeInput($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_client_id = $client_id, 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_client_id = $client_id"); } - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for domain expiring', company_id = $company_id"); - // CERTIFICATES EXPIRING + } + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for domain expiring'"); - $certificateAlertArray = [1,7,14,30,90,120]; + // CERTIFICATES EXPIRING - foreach ($certificateAlertArray as $day) { + $certificateAlertArray = [1,7,14,30,90,120]; - //Get Certs Expiring - $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" - ); + foreach ($certificateAlertArray as $day) { - while ($row = mysqli_fetch_array($sql)) { - $certificate_id = intval($row['certificate_id']); - $certificate_name = sanitizeInput($row['certificate_name']); - $certificate_domain = sanitizeInput($row['certificate_domain']); - $certificate_expire = sanitizeInput($row['certificate_expire']); - $client_id = intval($row['client_id']); - $client_name = sanitizeInput($row['client_name']); + //Get Certs Expiring + $sql = mysqli_query( + $mysqli, + "SELECT * FROM certificates + LEFT JOIN clients ON certificate_client_id = client_id + WHERE certificate_expire = CURDATE() + INTERVAL $day DAY" + ); - 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_client_id = $client_id, company_id = $company_id"); + while ($row = mysqli_fetch_array($sql)) { + $certificate_id = intval($row['certificate_id']); + $certificate_name = sanitizeInput($row['certificate_name']); + $certificate_domain = sanitizeInput($row['certificate_domain']); + $certificate_expire = sanitizeInput($row['certificate_expire']); + $client_id = intval($row['client_id']); + $client_name = sanitizeInput($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_client_id = $client_id"); } - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for certificates expiring', company_id = $company_id"); - // Asset Warranties Expiring + } + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for certificates expiring'"); - $warranty_alert_array = [1,7,14,30,90,120]; + // Asset Warranties Expiring - foreach ($warranty_alert_array as $day) { + $warranty_alert_array = [1,7,14,30,90,120]; - //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" - ); + foreach ($warranty_alert_array as $day) { - while ($row = mysqli_fetch_array($sql)) { - $asset_id = intval($row['asset_id']); - $asset_name = sanitizeInput($row['asset_name']); - $asset_warranty_expire = sanitizeInput($row['asset_warranty_expire']); - $client_id = intval($row['client_id']); - $client_name = sanitizeInput($row['client_name']); + //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" + ); - 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_client_id = $client_id, company_id = $company_id"); + while ($row = mysqli_fetch_array($sql)) { + $asset_id = intval($row['asset_id']); + $asset_name = sanitizeInput($row['asset_name']); + $asset_warranty_expire = sanitizeInput($row['asset_warranty_expire']); + $client_id = intval($row['client_id']); + $client_name = sanitizeInput($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_client_id = $client_id"); } - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for asset warranties expiring', company_id = $company_id"); - // Scheduled tickets + } + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for asset warranties expiring'"); - // Get date for search - $today = new DateTime(); - $today_text = $today->format('Y-m-d'); + // Scheduled tickets - // Get scheduled tickets for today - $sql_scheduled_tickets = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets WHERE scheduled_ticket_next_run = '$today_text'"); + // Get date for search + $today = new DateTime(); + $today_text = $today->format('Y-m-d'); - if (mysqli_num_rows($sql_scheduled_tickets) > 0) { - while ($row = mysqli_fetch_array($sql_scheduled_tickets)) { - $schedule_id = intval($row['scheduled_ticket_id']); - $subject = sanitizeInput($row['scheduled_ticket_subject']); - $details = sanitizeInput($row['scheduled_ticket_details']); - $priority = sanitizeInput($row['scheduled_ticket_priority']); - $frequency = sanitizeInput(strtolower($row['scheduled_ticket_frequency'])); - $created_id = intval($row['scheduled_ticket_created_by']); - $client_id = intval($row['scheduled_ticket_client_id']); - $contact_id = intval($row['scheduled_ticket_contact_id']); - $asset_id = intval($row['scheduled_ticket_asset_id']); - $company_id = intval($row['company_id']); + // Get scheduled tickets for today + $sql_scheduled_tickets = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets WHERE scheduled_ticket_next_run = '$today_text'"); - //Get the next Ticket Number and add 1 for the new ticket number - $ticket_number = $config_ticket_next_number; - $new_config_ticket_next_number = $config_ticket_next_number + 1; - mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = $company_id"); + if (mysqli_num_rows($sql_scheduled_tickets) > 0) { + while ($row = mysqli_fetch_array($sql_scheduled_tickets)) { + $schedule_id = intval($row['scheduled_ticket_id']); + $subject = sanitizeInput($row['scheduled_ticket_subject']); + $details = sanitizeInput($row['scheduled_ticket_details']); + $priority = sanitizeInput($row['scheduled_ticket_priority']); + $frequency = sanitizeInput(strtolower($row['scheduled_ticket_frequency'])); + $created_id = intval($row['scheduled_ticket_created_by']); + $client_id = intval($row['scheduled_ticket_client_id']); + $contact_id = intval($row['scheduled_ticket_contact_id']); + $asset_id = intval($row['scheduled_ticket_asset_id']); - // Raise the ticket - mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'Open', ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id, company_id = $company_id"); - $id = mysqli_insert_id($mysqli); + //Get the next Ticket Number and add 1 for the new ticket number + $ticket_number = $config_ticket_next_number; + $new_config_ticket_next_number = $config_ticket_next_number + 1; + mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1"); - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'System created scheduled $frequency ticket - $subject', log_client_id = $client_id, company_id = $company_id, log_user_id = $created_id"); + // Raise the ticket + mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'Open', ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id"); + $id = mysqli_insert_id($mysqli); - // E-mail client - if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1) { + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'System created scheduled $frequency ticket - $subject', log_client_id = $client_id, log_user_id = $created_id"); - // Get contact/ticket/company details - $sql = mysqli_query( - $mysqli, - "SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject, company_phone FROM tickets - LEFT JOIN clients ON ticket_client_id = client_id - LEFT JOIN contacts ON ticket_contact_id = contact_id - LEFT JOIN companies ON tickets.company_id = companies.company_id - WHERE ticket_id = $id AND tickets.company_id = $company_id" + // E-mail client + if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1) { + + // Get contact/ticket/company details + $sql = mysqli_query( + $mysqli, + "SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject, company_phone FROM tickets + LEFT JOIN clients ON ticket_client_id = client_id + LEFT JOIN contacts ON ticket_contact_id = contact_id + WHERE ticket_id = $id" + ); + $row = mysqli_fetch_array($sql); + + $contact_name = $row['contact_name']; + $contact_email = $row['contact_email']; + $ticket_prefix = $row['ticket_prefix']; + $ticket_number = intval($row['ticket_number']); + $ticket_subject = $row['ticket_subject']; + $company_phone = formatPhoneNumber($row['company_phone']); + + // Verify contact email is valid + if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { + + $subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)"; + $body = "#--itflow--#

Hello, $contact_name

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: Open
Portal: https://$config_base_url/portal/ticket.php?id=$id

~
$company_name
Support Department
$config_ticket_from_email
$company_phone"; + + $mail = sendSingleEmail( + $config_smtp_host, + $config_smtp_username, + $config_smtp_password, + $config_smtp_encryption, + $config_smtp_port, + $config_ticket_from_email, + $config_ticket_from_name, + $contact_email, + $contact_name, + $subject, + $body ); - $row = mysqli_fetch_array($sql); - - $contact_name = $row['contact_name']; - $contact_email = $row['contact_email']; - $ticket_prefix = $row['ticket_prefix']; - $ticket_number = intval($row['ticket_number']); - $ticket_subject = $row['ticket_subject']; - $company_phone = formatPhoneNumber($row['company_phone']); - - // Verify contact email is valid - if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { - - $subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)"; - $body = "#--itflow--#

Hello, $contact_name

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: Open
Portal: https://$config_base_url/portal/ticket.php?id=$id

~
$company_name
Support Department
$config_ticket_from_email
$company_phone"; - - $mail = sendSingleEmail( - $config_smtp_host, - $config_smtp_username, - $config_smtp_password, - $config_smtp_encryption, - $config_smtp_port, - $config_ticket_from_email, - $config_ticket_from_name, - $contact_email, - $contact_name, - $subject, - $body - ); - - if ($mail !== true) { - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', company_id = $company_id"); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $company_id"); - } + if ($mail !== true) { + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email'"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail'"); } - } - // Set the next run date - if ($frequency == "weekly") { - // Note: We seemingly have to initialize a new datetime for each loop to avoid stacking the dates - $now = new DateTime(); - $next_run = date_add($now, date_interval_create_from_date_string('1 week')); } - elseif ($frequency == "monthly") { - $now = new DateTime(); - $next_run = date_add($now, date_interval_create_from_date_string('1 month')); - } - elseif ($frequency == "quarterly") { - $now = new DateTime(); - $next_run = date_add($now, date_interval_create_from_date_string('3 months')); - } - elseif ($frequency == "biannually") { - $now = new DateTime(); - $next_run = date_add($now, date_interval_create_from_date_string('6 months')); - } - elseif ($frequency == "annually") { - $now = new DateTime(); - $next_run = date_add($now, date_interval_create_from_date_string('12 months')); - } - - // Update the run date - $next_run = $next_run->format('Y-m-d'); - $a = mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_next_run = '$next_run' WHERE scheduled_ticket_id = $schedule_id"); - } + + // Set the next run date + if ($frequency == "weekly") { + // Note: We seemingly have to initialize a new datetime for each loop to avoid stacking the dates + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('1 week')); + } elseif ($frequency == "monthly") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('1 month')); + } elseif ($frequency == "quarterly") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('3 months')); + } elseif ($frequency == "biannually") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('6 months')); + } elseif ($frequency == "annually") { + $now = new DateTime(); + $next_run = date_add($now, date_interval_create_from_date_string('12 months')); + } + + // Update the run date + $next_run = $next_run->format('Y-m-d'); + $a = mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_next_run = '$next_run' WHERE scheduled_ticket_id = $schedule_id"); + } - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created sent out scheduled tickets', company_id = $company_id"); + } + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created sent out scheduled tickets'"); - // PAST DUE INVOICE Notifications - //$invoiceAlertArray = [$config_invoice_overdue_reminders]; - $invoiceAlertArray = [30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,590,620]; + // PAST DUE INVOICE Notifications + //$invoiceAlertArray = [$config_invoice_overdue_reminders]; + $invoiceAlertArray = [30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,590,620]; - foreach ($invoiceAlertArray as $day) { + foreach ($invoiceAlertArray as $day) { + $sql = mysqli_query( + $mysqli, + "SELECT * FROM invoices + LEFT JOIN clients ON invoice_client_id = client_id + LEFT JOIN contacts ON contact_id = primary_contact + WHERE invoice_status NOT LIKE 'Draft' + AND invoice_status NOT LIKE 'Paid' + AND invoice_status NOT LIKE 'Cancelled' + AND DATE_ADD(invoice_due, INTERVAL $day DAY) = CURDATE() + ORDER BY invoice_number DESC" + ); + + while ($row = mysqli_fetch_array($sql)) { + $invoice_id = intval($row['invoice_id']); + $invoice_prefix = sanitizeInput($row['invoice_prefix']); + $invoice_number = intval($row['invoice_number']); + $invoice_status = $row['invoice_status']; + $invoice_date = $row['invoice_date']; + $invoice_due = $row['invoice_due']; + $invoice_url_key = $row['invoice_url_key']; + $invoice_amount = floatval($row['invoice_amount']); + $invoice_currency_code = $row['invoice_currency_code']; + $client_id = intval($row['client_id']); + $client_name = sanitizeInput($row['client_name']); + $contact_name = $row['contact_name']; + $contact_email = $row['contact_email']; + + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Overdue', notification = 'Invoice $invoice_prefix$invoice_number for $client_name in the amount of $invoice_amount is overdue by $day days', notification_client_id = $client_id"); + + $subject = "Overdue Invoice $invoice_prefix$invoice_number"; + $body = "Hello $contact_name,

According to our records, we have not received payment for invoice $invoice_prefix$invoice_number. Please submit your payment as soon as possible. If you have any questions please contact us at $company_phone. +

+ Please view the details of the invoice below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "
Due Date: $invoice_due


To view your invoice click here


~
$company_name
Billing Department
$config_invoice_from_email
$company_phone"; + + $mail = sendSingleEmail( + $config_smtp_host, + $config_smtp_username, + $config_smtp_password, + $config_smtp_encryption, + $config_smtp_port, + $config_invoice_from_email, + $config_invoice_from_name, + $contact_email, + $contact_name, + $subject, + $body + ); + + if ($mail === true) { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Overdue Invoice', history_invoice_id = $invoice_id"); + } else { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Failed to send Overdue Invoice', history_invoice_id = $invoice_id"); + + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email'"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail'"); + } + + } + + } + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for past due invoices and sent out notifications to the primary contacts email'"); + + //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 LEFT JOIN clients ON client_id = recurring_client_id WHERE recurring_next_date = CURDATE() AND recurring_status = 1"); + + while ($row = mysqli_fetch_array($sql_recurring)) { + $recurring_id = intval($row['recurring_id']); + $recurring_scope = sanitizeInput($row['recurring_scope']); + $recurring_frequency = sanitizeInput($row['recurring_frequency']); + $recurring_status = sanitizeInput($row['recurring_status']); + $recurring_last_sent = sanitizeInput($row['recurring_last_sent']); + $recurring_next_date = sanitizeInput($row['recurring_next_date']); + $recurring_amount = floatval($row['recurring_amount']); + $recurring_currency_code = sanitizeInput($row['recurring_currency_code']); + $recurring_note = sanitizeInput($row['recurring_note']); //Escape SQL + $category_id = intval($row['recurring_category_id']); + $client_id = intval($row['recurring_client_id']); + $client_name = sanitizeInput($row['client_name']); //Escape SQL just in case a name is like Safran's etc + $client_net_terms = intval($row['client_net_terms']); + + + //Get the last Invoice Number and add 1 for the new invoice number + $sql_invoice_number = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = 1"); + $row = mysqli_fetch_array($sql_invoice_number); + $config_invoice_next_number = intval($row['config_invoice_next_number']); + + $new_invoice_number = $config_invoice_next_number; + $new_config_invoice_next_number = $config_invoice_next_number + 1; + mysqli_query($mysqli, "UPDATE settings SET config_invoice_next_number = $new_config_invoice_next_number WHERE company_id = 1"); + + //Generate a unique URL key for clients to access + $url_key = randomString(156); + + mysqli_query($mysqli, "INSERT INTO invoices SET invoice_prefix = '$config_invoice_prefix', invoice_number = $new_invoice_number, invoice_scope = '$recurring_scope', invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), invoice_amount = $recurring_amount, invoice_currency_code = '$recurring_currency_code', invoice_note = '$recurring_note', invoice_category_id = $category_id, invoice_status = 'Sent', invoice_url_key = '$url_key', invoice_client_id = $client_id"); + + $new_invoice_id = mysqli_insert_id($mysqli); + + //Copy Items from original recurring invoice to new invoice + $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_recurring_id = $recurring_id ORDER BY item_id ASC"); + + while ($row = mysqli_fetch_array($sql_invoice_items)) { + $item_id = intval($row['item_id']); + $item_name = sanitizeInput($row['item_name']); //SQL Escape incase of , + $item_description = sanitizeInput($row['item_description']); //SQL Escape incase of , + $item_quantity = floatval($row['item_quantity']); + $item_price = floatval($row['item_price']); + $item_subtotal = floatval($row['item_subtotal']); + $item_tax = floatval($row['item_tax']); + $item_total = floatval($row['item_total']); + $tax_id = intval($row['item_tax_id']); + + //Insert Items into New Invoice + mysqli_query($mysqli, "INSERT INTO invoice_items SET item_name = '$item_name', item_description = '$item_description', item_quantity = $item_quantity, item_price = $item_price, item_subtotal = $item_subtotal, item_tax = $item_tax, item_total = $item_total, item_tax_id = $tax_id, item_invoice_id = $new_invoice_id"); + + } + + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_invoice_id = $new_invoice_id"); + + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Recurring Sent', notification = 'Recurring Invoice $config_invoice_prefix$new_invoice_number for $client_name Sent', notification_client_id = $client_id"); + + //Update recurring dates + + mysqli_query($mysqli, "UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency) WHERE recurring_id = $recurring_id"); + + if ($config_recurring_auto_send_invoice == 1) { $sql = mysqli_query( $mysqli, "SELECT * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN contacts ON contact_id = primary_contact - WHERE invoice_status NOT LIKE 'Draft' - AND invoice_status NOT LIKE 'Paid' - AND invoice_status NOT LIKE 'Cancelled' - AND DATE_ADD(invoice_due, INTERVAL $day DAY) = CURDATE() - AND invoices.company_id = $company_id - ORDER BY invoice_number DESC" + WHERE invoice_id = $new_invoice_id" ); - while ($row = mysqli_fetch_array($sql)) { - $invoice_id = intval($row['invoice_id']); - $invoice_prefix = sanitizeInput($row['invoice_prefix']); - $invoice_number = intval($row['invoice_number']); - $invoice_status = $row['invoice_status']; - $invoice_date = $row['invoice_date']; - $invoice_due = $row['invoice_due']; - $invoice_url_key = $row['invoice_url_key']; - $invoice_amount = floatval($row['invoice_amount']); - $invoice_currency_code = $row['invoice_currency_code']; - $client_id = intval($row['client_id']); - $client_name = sanitizeInput($row['client_name']); - $contact_name = $row['contact_name']; - $contact_email = $row['contact_email']; + $row = mysqli_fetch_array($sql); + $invoice_prefix = $row['invoice_prefix']; + $invoice_number = intval($row['invoice_number']); + $invoice_date = $row['invoice_date']; + $invoice_due = $row['invoice_due']; + $invoice_amount = floatval($row['invoice_amount']); + $invoice_url_key = $row['invoice_url_key']; + $client_id = intval($row['client_id']); + $client_name = $row['client_name']; + $contact_name = $row['contact_name']; + $contact_email = sanitizeInput($row['contact_email']); - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Overdue', notification = 'Invoice $invoice_prefix$invoice_number for $client_name in the amount of $invoice_amount is overdue by $day days', notification_client_id = $client_id, company_id = $company_id"); - $subject = "Overdue Invoice $invoice_prefix$invoice_number"; - $body = "Hello $contact_name,

According to our records, we have not received payment for invoice $invoice_prefix$invoice_number. Please submit your payment as soon as possible. If you have any questions please contact us at $company_phone. -

- Please view the details of the invoice below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . "
Due Date: $invoice_due


To view your invoice click here


~
$company_name
Billing Department
$config_invoice_from_email
$company_phone"; + $subject = "Invoice $invoice_prefix$invoice_number"; + $body = "Hello $contact_name,

Please view the details of the invoice below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $recurring_currency_code) . "
Due Date: $invoice_due


To view your invoice click here


~
$company_name
Billing Department
$config_invoice_from_email
$company_phone"; - $mail = sendSingleEmail( - $config_smtp_host, - $config_smtp_username, - $config_smtp_password, - $config_smtp_encryption, - $config_smtp_port, - $config_invoice_from_email, - $config_invoice_from_name, - $contact_email, - $contact_name, - $subject, - $body - ); + $mail = sendSingleEmail( + $config_smtp_host, + $config_smtp_username, + $config_smtp_password, + $config_smtp_encryption, + $config_smtp_port, + $config_invoice_from_email, + $config_invoice_from_name, + $contact_email, + $contact_name, + $subject, + $body + ); - if ($mail === true) { - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Overdue Invoice', history_invoice_id = $invoice_id, company_id = $company_id"); - } else { - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Failed to send Overdue Invoice', history_invoice_id = $invoice_id, company_id = $company_id"); + if ($mail === true) { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_invoice_id = $new_invoice_id"); + mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Sent', invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id"); - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', company_id = $company_id"); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $company_id"); - } + } else { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_invoice_id = $new_invoice_id"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email'"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail'"); } - } - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for past due invoices and sent out notifications to the primary contacts email', company_id = $company_id"); - - //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 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 = intval($row['recurring_id']); - $recurring_scope = sanitizeInput($row['recurring_scope']); - $recurring_frequency = sanitizeInput($row['recurring_frequency']); - $recurring_status = sanitizeInput($row['recurring_status']); - $recurring_last_sent = sanitizeInput($row['recurring_last_sent']); - $recurring_next_date = sanitizeInput($row['recurring_next_date']); - $recurring_amount = floatval($row['recurring_amount']); - $recurring_currency_code = sanitizeInput($row['recurring_currency_code']); - $recurring_note = sanitizeInput($row['recurring_note']); //Escape SQL - $category_id = intval($row['recurring_category_id']); - $client_id = intval($row['recurring_client_id']); - $client_name = sanitizeInput($row['client_name']); //Escape SQL just in case a name is like Safran's etc - $client_net_terms = intval($row['client_net_terms']); - - - //Get the last Invoice Number and add 1 for the new invoice number - $sql_invoice_number = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = $company_id"); - $row = mysqli_fetch_array($sql_invoice_number); - $config_invoice_next_number = intval($row['config_invoice_next_number']); - - $new_invoice_number = $config_invoice_next_number; - $new_config_invoice_next_number = $config_invoice_next_number + 1; - mysqli_query($mysqli, "UPDATE settings SET config_invoice_next_number = $new_config_invoice_next_number WHERE company_id = $company_id"); - - //Generate a unique URL key for clients to access - $url_key = randomString(156); - - mysqli_query($mysqli, "INSERT INTO invoices SET invoice_prefix = '$config_invoice_prefix', invoice_number = $new_invoice_number, invoice_scope = '$recurring_scope', invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), invoice_amount = $recurring_amount, invoice_currency_code = '$recurring_currency_code', invoice_note = '$recurring_note', invoice_category_id = $category_id, invoice_status = 'Sent', invoice_url_key = '$url_key', invoice_client_id = $client_id, company_id = $company_id"); - - $new_invoice_id = mysqli_insert_id($mysqli); - - //Copy Items from original recurring invoice to new invoice - $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_recurring_id = $recurring_id ORDER BY item_id ASC"); - - while ($row = mysqli_fetch_array($sql_invoice_items)) { - $item_id = intval($row['item_id']); - $item_name = sanitizeInput($row['item_name']); //SQL Escape incase of , - $item_description = sanitizeInput($row['item_description']); //SQL Escape incase of , - $item_quantity = floatval($row['item_quantity']); - $item_price = floatval($row['item_price']); - $item_subtotal = floatval($row['item_subtotal']); - $item_tax = floatval($row['item_tax']); - $item_total = floatval($row['item_total']); - $tax_id = intval($row['item_tax_id']); - - //Insert Items into New Invoice - mysqli_query($mysqli, "INSERT INTO invoice_items SET item_name = '$item_name', item_description = '$item_description', item_quantity = $item_quantity, item_price = $item_price, item_subtotal = $item_subtotal, item_tax = $item_tax, item_total = $item_total, item_tax_id = $tax_id, item_invoice_id = $new_invoice_id, company_id = $company_id"); - - } - - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Invoice Generated from Recurring!', history_invoice_id = $new_invoice_id, company_id = $company_id"); - - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Recurring Sent', notification = 'Recurring Invoice $config_invoice_prefix$new_invoice_number for $client_name Sent', notification_client_id = $client_id, company_id = $company_id"); - - //Update recurring dates - - mysqli_query($mysqli, "UPDATE recurring SET recurring_last_sent = CURDATE(), recurring_next_date = DATE_ADD(CURDATE(), INTERVAL 1 $recurring_frequency) WHERE recurring_id = $recurring_id"); - - if ($config_recurring_auto_send_invoice == 1) { - $sql = mysqli_query( - $mysqli, - "SELECT * FROM invoices - LEFT JOIN clients ON invoice_client_id = client_id - LEFT JOIN contacts ON contact_id = primary_contact - WHERE invoice_id = $new_invoice_id - AND invoices.company_id = $company_id" - ); - - $row = mysqli_fetch_array($sql); - $invoice_prefix = $row['invoice_prefix']; - $invoice_number = intval($row['invoice_number']); - $invoice_date = $row['invoice_date']; - $invoice_due = $row['invoice_due']; - $invoice_amount = floatval($row['invoice_amount']); - $invoice_url_key = $row['invoice_url_key']; - $client_id = intval($row['client_id']); - $client_name = $row['client_name']; - $contact_name = $row['contact_name']; - $contact_email = sanitizeInput($row['contact_email']); - - - $subject = "Invoice $invoice_prefix$invoice_number"; - $body = "Hello $contact_name,

Please view the details of the invoice below.

Invoice: $invoice_prefix$invoice_number
Issue Date: $invoice_date
Total: " . numfmt_format_currency($currency_format, $invoice_amount, $recurring_currency_code) . "
Due Date: $invoice_due


To view your invoice click here


~
$company_name
Billing Department
$config_invoice_from_email
$company_phone"; - - $mail = sendSingleEmail( - $config_smtp_host, - $config_smtp_username, - $config_smtp_password, - $config_smtp_encryption, - $config_smtp_port, - $config_invoice_from_email, - $config_invoice_from_name, - $contact_email, - $contact_name, - $subject, - $body - ); - - if ($mail === true) { - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_invoice_id = $new_invoice_id, company_id = $company_id"); - mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Sent', invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id"); - - } else { - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_invoice_id = $new_invoice_id, company_id = $company_id"); - - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', company_id = $company_id"); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $company_id"); - } + } //End if Autosend is on + } //End Recurring Invoices Loop + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created invoices from recurring invoices and sent emails out'"); - } //End if Autosend is on - } //End Recurring Invoices Loop - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created invoices from recurring invoices and sent emails out', company_id = $company_id"); + // TELEMETRY - // TELEMETRY + if ($config_telemetry == 1) { - if ($config_telemetry == 1) { + $current_version = exec("git rev-parse HEAD"); - $current_version = exec("git rev-parse HEAD"); + // Client Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS num FROM clients")); + $client_count = $row['num']; - // Client Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS num FROM clients")); - $client_count = $row['num']; + // Ticket Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS num FROM tickets")); + $ticket_count = $row['num']; - // Ticket Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS num FROM tickets")); - $ticket_count = $row['num']; + // Calendar Event Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('event_id') AS num FROM events")); + $calendar_event_count = $row['num']; - // Calendar Event Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('event_id') AS num FROM events")); - $calendar_event_count = $row['num']; - - // Quote Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('quote_id') AS num FROM quotes")); - $quote_count = $row['num']; - - // Invoice Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices")); - $invoice_count = $row['num']; + // Quote Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('quote_id') AS num FROM quotes")); + $quote_count = $row['num']; - // Revenue Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('revenue_id') AS num FROM revenues")); - $revenue_count = $row['num']; + // Invoice Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices")); + $invoice_count = $row['num']; - // Recurring Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS num FROM recurring")); - $recurring_count = $row['num']; + // Revenue Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('revenue_id') AS num FROM revenues")); + $revenue_count = $row['num']; - // Account Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('account_id') AS num FROM accounts")); - $account_count = $row['num']; - - // Tax Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('tax_id') AS num FROM taxes")); - $tax_count = $row['num']; - - // Product Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('product_id') AS num FROM products")); - $product_count = $row['num']; - - // Payment Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('payment_id') AS num FROM payments WHERE payment_invoice_id > 0")); - $payment_count = $row['num']; - - // Company Vendor Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 0 AND vendor_client_id = 0")); - $company_vendor_count = $row['num']; - - // Expense Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('expense_id') AS num FROM expenses WHERE expense_vendor_id > 0")); - $expense_count = $row['num']; + // Recurring Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS num FROM recurring")); + $recurring_count = $row['num']; - // Trip Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('trip_id') AS num FROM trips")); - $trip_count = $row['num']; + // Account Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('account_id') AS num FROM accounts")); + $account_count = $row['num']; - // Transfer Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('transfer_id') AS num FROM transfers")); - $transfer_count = $row['num']; + // Tax Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('tax_id') AS num FROM taxes")); + $tax_count = $row['num']; - // Contact Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('contact_id') AS num FROM contacts")); - $contact_count = $row['num']; - - // Location Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('location_id') AS num FROM locations")); - $location_count = $row['num']; - - // Asset Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('asset_id') AS num FROM assets")); - $asset_count = $row['num']; - - // Software Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software WHERE software_template = 0")); - $software_count = $row['num']; - - // Software Template Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software WHERE software_template = 1")); - $software_template_count = $row['num']; - - // Password Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('login_id') AS num FROM logins")); - $password_count = $row['num']; - - // Network Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('network_id') AS num FROM networks")); - $network_count = $row['num']; - - // Certificate Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('certificate_id') AS num FROM certificates")); - $certificate_count = $row['num']; - - // Domain Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('domain_id') AS num FROM domains")); - $domain_count = $row['num']; - - // Service Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('service_id') AS num FROM services")); - $service_count = $row['num']; - - // Client Vendor Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 0 AND vendor_client_id > 0")); - $client_vendor_count = $row['num']; - - // Vendor Template Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 1")); - $vendor_template_count = $row['num']; - - // File Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('file_id') AS num FROM files")); - $file_count = $row['num']; - - // Document Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('document_id') AS num FROM documents WHERE document_template = 0")); - $document_count = $row['num']; - - // Document Template Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('document_id') AS num FROM documents WHERE document_template = 1")); - $document_template_count = $row['num']; - - // Shared Item Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('item_id') AS num FROM shared_items")); - $shared_item_count = $row['num']; - - // Company Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('company_id') AS num FROM companies")); - $company_count = $row['num']; - - // User Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('user_id') AS num FROM users")); - $user_count = $row['num']; - - // Category Expense Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Expense'")); - $category_expense_count = $row['num']; - - // Category Income Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Income'")); - $category_income_count = $row['num']; - - // Category Referral Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Referral'")); - $category_referral_count = $row['num']; - - // Category Payment Method Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Payment Method'")); - $category_payment_method_count = $row['num']; - - // Tag Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('tag_id') AS num FROM tags")); - $tag_count = $row['num']; - - // API Key Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('api_key_id') AS num FROM api_keys")); - $api_key_count = $row['num']; - - // Log Count - $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('log_id') AS num FROM logs")); - $log_count = $row['num']; - - $postdata = http_build_query( - array( - 'installation_id' => "$installation_id", - 'version' => "$current_version", - 'company_name' => "$company_name", - 'city' => "$company_city", - 'state' => "$company_state", - 'country' => "$company_country", - 'currency' => "$company_currency", - 'client_count' => $client_count, - 'ticket_count' => $ticket_count, - 'calendar_event_count' => $calendar_event_count, - 'quote_count' => $quote_count, - 'invoice_count' => $invoice_count, - 'revenue_count' => $revenue_count, - 'recurring_count' => $recurring_count, - 'account_count' => $account_count, - 'tax_count' => $tax_count, - 'product_count' => $product_count, - 'payment_count' => $payment_count, - 'company_vendor_count' => $company_vendor_count, - 'expense_count' => $expense_count, - 'trip_count' => $trip_count, - 'transfer_count' => $transfer_count, - 'contact_count' => $contact_count, - 'location_count' => $location_count, - 'asset_count' => $asset_count, - 'software_count' => $software_count, - 'software_template_count' => $software_template_count, - 'password_count' => $password_count, - 'network_count' => $network_count, - 'certificate_count' => $certificate_count, - 'domain_count' => $domain_count, - 'service_count' => $service_count, - 'client_vendor_count' => $client_vendor_count, - 'vendor_template_count' => $vendor_template_count, - 'file_count' => $file_count, - 'document_count' => $document_count, - 'document_template_count' => $document_template_count, - 'shared_item_count' => $shared_item_count, - 'company_count' => $company_count, - 'user_count' => $user_count, - 'category_expense_count' => $category_expense_count, - 'category_income_count' => $category_income_count, - 'category_referral_count' => $category_referral_count, - 'category_payment_method_count' => $category_payment_method_count, - 'tag_count' => $tag_count, - 'api_key_count' => $api_key_count, - 'log_count' => $log_count, - 'config_theme' => "$config_theme", - 'config_enable_cron' => $config_enable_cron, - 'config_ticket_email_parse' => $config_ticket_email_parse, - 'config_module_enable_itdoc' => $config_module_enable_itdoc, - 'config_module_enable_ticketing' => $config_module_enable_ticketing, - 'config_module_enable_accounting' => $config_module_enable_accounting, - 'config_telemetry' => $config_telemetry, - 'collection_method' => 3 - ) - ); - - $opts = array('http' => - array( - 'method' => 'POST', - 'header' => 'Content-type: application/x-www-form-urlencoded', - 'content' => $postdata - ) - ); - - $context = stream_context_create($opts); - - $result = file_get_contents('https://telemetry.itflow.org', false, $context); - - // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Telemetry', log_description = 'Cron sent telemetry results to ITFlow Developers', company_id = $company_id"); - } - - - - /* - * ############################################################################################################### - * FINISH UP - * ############################################################################################################### - */ - - // Send Alert to inform Cron was run - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Cron', notification = 'Cron.php successfully executed', company_id = $company_id"); + // Product Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('product_id') AS num FROM products")); + $product_count = $row['num']; + + // Payment Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('payment_id') AS num FROM payments WHERE payment_invoice_id > 0")); + $payment_count = $row['num']; + + // Company Vendor Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 0 AND vendor_client_id = 0")); + $company_vendor_count = $row['num']; + + // Expense Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('expense_id') AS num FROM expenses WHERE expense_vendor_id > 0")); + $expense_count = $row['num']; + + // Trip Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('trip_id') AS num FROM trips")); + $trip_count = $row['num']; + + // Transfer Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('transfer_id') AS num FROM transfers")); + $transfer_count = $row['num']; + + // Contact Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('contact_id') AS num FROM contacts")); + $contact_count = $row['num']; + + // Location Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('location_id') AS num FROM locations")); + $location_count = $row['num']; + + // Asset Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('asset_id') AS num FROM assets")); + $asset_count = $row['num']; + + // Software Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software WHERE software_template = 0")); + $software_count = $row['num']; + + // Software Template Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software WHERE software_template = 1")); + $software_template_count = $row['num']; + + // Password Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('login_id') AS num FROM logins")); + $password_count = $row['num']; + + // Network Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('network_id') AS num FROM networks")); + $network_count = $row['num']; + + // Certificate Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('certificate_id') AS num FROM certificates")); + $certificate_count = $row['num']; + + // Domain Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('domain_id') AS num FROM domains")); + $domain_count = $row['num']; + + // Service Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('service_id') AS num FROM services")); + $service_count = $row['num']; + + // Client Vendor Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 0 AND vendor_client_id > 0")); + $client_vendor_count = $row['num']; + + // Vendor Template Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS num FROM vendors WHERE vendor_template = 1")); + $vendor_template_count = $row['num']; + + // File Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('file_id') AS num FROM files")); + $file_count = $row['num']; + + // Document Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('document_id') AS num FROM documents WHERE document_template = 0")); + $document_count = $row['num']; + + // Document Template Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('document_id') AS num FROM documents WHERE document_template = 1")); + $document_template_count = $row['num']; + + // Shared Item Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('item_id') AS num FROM shared_items")); + $shared_item_count = $row['num']; + + // Company Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('company_id') AS num FROM companies")); + $company_count = $row['num']; + + // User Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('user_id') AS num FROM users")); + $user_count = $row['num']; + + // Category Expense Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Expense'")); + $category_expense_count = $row['num']; + + // Category Income Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Income'")); + $category_income_count = $row['num']; + + // Category Referral Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Referral'")); + $category_referral_count = $row['num']; + + // Category Payment Method Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('category_id') AS num FROM categories WHERE category_type = 'Payment Method'")); + $category_payment_method_count = $row['num']; + + // Tag Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('tag_id') AS num FROM tags")); + $tag_count = $row['num']; + + // API Key Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('api_key_id') AS num FROM api_keys")); + $api_key_count = $row['num']; + + // Log Count + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('log_id') AS num FROM logs")); + $log_count = $row['num']; + + $postdata = http_build_query( + array( + 'installation_id' => "$installation_id", + 'version' => "$current_version", + 'company_name' => "$company_name", + 'city' => "$company_city", + 'state' => "$company_state", + 'country' => "$company_country", + 'currency' => "$company_currency", + 'client_count' => $client_count, + 'ticket_count' => $ticket_count, + 'calendar_event_count' => $calendar_event_count, + 'quote_count' => $quote_count, + 'invoice_count' => $invoice_count, + 'revenue_count' => $revenue_count, + 'recurring_count' => $recurring_count, + 'account_count' => $account_count, + 'tax_count' => $tax_count, + 'product_count' => $product_count, + 'payment_count' => $payment_count, + 'company_vendor_count' => $company_vendor_count, + 'expense_count' => $expense_count, + 'trip_count' => $trip_count, + 'transfer_count' => $transfer_count, + 'contact_count' => $contact_count, + 'location_count' => $location_count, + 'asset_count' => $asset_count, + 'software_count' => $software_count, + 'software_template_count' => $software_template_count, + 'password_count' => $password_count, + 'network_count' => $network_count, + 'certificate_count' => $certificate_count, + 'domain_count' => $domain_count, + 'service_count' => $service_count, + 'client_vendor_count' => $client_vendor_count, + 'vendor_template_count' => $vendor_template_count, + 'file_count' => $file_count, + 'document_count' => $document_count, + 'document_template_count' => $document_template_count, + 'shared_item_count' => $shared_item_count, + 'company_count' => $company_count, + 'user_count' => $user_count, + 'category_expense_count' => $category_expense_count, + 'category_income_count' => $category_income_count, + 'category_referral_count' => $category_referral_count, + 'category_payment_method_count' => $category_payment_method_count, + 'tag_count' => $tag_count, + 'api_key_count' => $api_key_count, + 'log_count' => $log_count, + 'config_theme' => "$config_theme", + 'config_enable_cron' => $config_enable_cron, + 'config_ticket_email_parse' => $config_ticket_email_parse, + 'config_module_enable_itdoc' => $config_module_enable_itdoc, + 'config_module_enable_ticketing' => $config_module_enable_ticketing, + 'config_module_enable_accounting' => $config_module_enable_accounting, + 'config_telemetry' => $config_telemetry, + 'collection_method' => 3 + ) + ); + + $opts = array('http' => + array( + 'method' => 'POST', + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $postdata + ) + ); + + $context = stream_context_create($opts); + + $result = file_get_contents('https://telemetry.itflow.org', false, $context); // Logging - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Ended', log_description = 'Cron executed successfully for $company_name', company_id = $company_id"); - - + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Telemetry', log_description = 'Cron sent telemetry results to ITFlow Developers'"); } - // End Cron enabled check -} // End Company Loop through + + + /* + * ############################################################################################################### + * FINISH UP + * ############################################################################################################### + */ + + // Send Alert to inform Cron was run + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Cron', notification = 'Cron.php successfully executed'"); + + // Logging + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Ended', log_description = 'Cron executed successfully for $company_name'"); + + +} +// End Cron enabled check diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php index 162cab3b..eebdcd13 100644 --- a/cron_ticket_email_parser.php +++ b/cron_ticket_email_parser.php @@ -19,8 +19,6 @@ require_once("config.php"); require_once("functions.php"); // Get settings for the "default" company -$company_id = 1; -$session_company_id = 1; require_once("get_settings.php"); // Check setting enabled @@ -51,30 +49,30 @@ require_once("plugins/php-mime-mail-parser/src/Parser.php"); // Function to raise a new ticket for a given contact and email them confirmation (if configured) -function addTicket($contact_id, $contact_name, $contact_email, $client_id, $company_id, $date, $subject, $message) { +function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message) { // Access global variables global $mysqli, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password; // Get the next Ticket Number and add 1 for the new ticket number - $ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = $company_id")); + $ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1")); $ticket_number = intval($ticket_number_sql['config_ticket_next_number']); $new_config_ticket_next_number = $ticket_number + 1; - mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = $company_id"); + mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1"); // Prep ticket details $message = nl2br(htmlentities(strip_tags($message))); $message = trim(mysqli_real_escape_string($mysqli, "Email from: $contact_email at $date:-

$message")); - mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message', ticket_priority = 'Low', ticket_status = 'Open', ticket_created_at = NOW(), ticket_created_by = '0', ticket_contact_id = $contact_id, ticket_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message', ticket_priority = 'Low', ticket_status = 'Open', ticket_created_at = NOW(), ticket_created_by = '0', ticket_contact_id = $contact_id, ticket_client_id = $client_id"); $id = mysqli_insert_id($mysqli); // Logging echo "Created new ticket.
"; - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'Email parser: Client contact $contact_email created ticket $config_ticket_prefix$ticket_number ($subject) ($id)', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'Email parser: Client contact $contact_email created ticket $config_ticket_prefix$ticket_number ($subject) ($id)', log_client_id = $client_id"); // Get company name & phone - $sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = $company_id"); + $sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = 1"); $row = mysqli_fetch_array($sql); $company_phone = formatPhoneNumber($row['company_phone']); $company_name = $row['company_name']; @@ -101,8 +99,8 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $comp ); if ($mail !== true) { - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', company_id = $company_id"); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email'"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail'"); } } @@ -127,7 +125,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message) { $message = "Email from: $from_email at $date:-

$message"; // Lookup the ticket ID - $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT ticket_id, ticket_subject, ticket_status, ticket_contact_id, ticket_client_id, tickets.company_id, contact_email + $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT ticket_id, ticket_subject, ticket_status, ticket_contact_id, ticket_client_id, contact_email FROM tickets LEFT JOIN contacts on tickets.ticket_contact_id = contacts.contact_id WHERE ticket_number = $ticket_number LIMIT 1")); @@ -140,11 +138,10 @@ function addReply($from_email, $date, $subject, $ticket_number, $message) { $ticket_reply_contact = intval($row['ticket_contact_id']); $ticket_contact_email = $row['contact_email']; $client_id = intval($row['ticket_client_id']); - $company_id = intval($row['company_id']); // Check ticket isn't closed if ($ticket_status == "Closed") { - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Ticket', notification = 'Email parser: $from_email attempted to re-open ticket $config_ticket_prefix$ticket_number (ID $ticket_id) - check inbox manually to see email', notification_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Ticket', notification = 'Email parser: $from_email attempted to re-open ticket $config_ticket_prefix$ticket_number (ID $ticket_id) - check inbox manually to see email', notification_client_id = $client_id"); return false; } @@ -171,13 +168,13 @@ function addReply($from_email, $date, $subject, $ticket_number, $message) { $comment = trim(mysqli_real_escape_string($mysqli, $message)); // Add the comment - mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$comment', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '00:00:00', ticket_reply_by = $ticket_reply_contact, ticket_reply_ticket_id = $ticket_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$comment', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '00:00:00', ticket_reply_by = $ticket_reply_contact, ticket_reply_ticket_id = $ticket_id"); // Update Ticket Last Response Field & set ticket to open as client has replied mysqli_query($mysqli, "UPDATE tickets SET ticket_status = 'Open' WHERE ticket_id = $ticket_id AND ticket_client_id = $client_id LIMIT 1"); echo "Updated existing ticket.
"; - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Update', log_description = 'Email parser: Client contact $from_email updated ticket $config_ticket_prefix$ticket_number ($subject)', log_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Update', log_description = 'Email parser: Client contact $from_email updated ticket $config_ticket_prefix$ticket_number ($subject)', log_client_id = $client_id"); return true; @@ -197,7 +194,7 @@ $imap = imap_open("{{$imap_mailbox}}INBOX", $config_smtp_username, $config_smtp_ if (!$imap) { // Logging $extended_log_description = var_export(imap_errors(), true); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Email parser: Failed to connect to IMAP. Details: $extended_log_description', company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Email parser: Failed to connect to IMAP. Details: $extended_log_description'"); exit("Could not connect to IMAP"); } @@ -268,9 +265,8 @@ if ($emails) { $contact_id = intval($row['contact_id']); $contact_email = $row['contact_email']; $client_id = intval($row['contact_client_id']); - $company_id = intval($row['company_id']); - if (addTicket($contact_id, $contact_name, $contact_email, $client_id, $company_id, $date, $subject, $message)) { + if (addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message)) { $email_processed = true; } @@ -287,20 +283,19 @@ if ($emails) { // Client details $client_id = intval($row['client_id']); - $company_id = intval($row['company_id']); // Contact details $password = password_hash(randomString(), PASSWORD_DEFAULT); $contact_name = $from_name; $contact_email = $from_email; - mysqli_query($mysqli, "INSERT INTO contacts SET contact_name = '$contact_name', contact_email = '$contact_email', contact_notes = 'Added automatically via email parsing.', contact_password_hash = '$password', contact_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO contacts SET contact_name = '$contact_name', contact_email = '$contact_email', contact_notes = 'Added automatically via email parsing.', contact_password_hash = '$password', contact_client_id = $client_id"); $contact_id = mysqli_insert_id($mysqli); // Logging for contact creation echo "Created new contact.
"; - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Create', log_description = 'Email parser: created contact $contact_name', log_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Create', log_description = 'Email parser: created contact $contact_name', log_client_id = $client_id"); - if (addTicket($contact_id, $contact_name, $contact_email, $client_id, $company_id, $date, $subject, $message)) { + if (addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message)) { $email_processed = true; } diff --git a/dashboard_financial.php b/dashboard_financial.php index 70eeccc1..f4267b69 100644 --- a/dashboard_financial.php +++ b/dashboard_financial.php @@ -15,10 +15,10 @@ if (isset($_GET['year'])) { //GET unique years from expenses, payments invoices and revenues $sql_years_select = mysqli_query( $mysqli, - "SELECT YEAR(expense_date) AS all_years FROM expenses WHERE company_id = $session_company_id - UNION DISTINCT SELECT YEAR(payment_date) FROM payments WHERE company_id = $session_company_id - UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues WHERE company_id = $session_company_id - UNION DISTINCT SELECT YEAR(invoice_date) FROM invoices WHERE company_id = $session_company_id + "SELECT YEAR(expense_date) AS all_years FROM expenses + UNION DISTINCT SELECT YEAR(payment_date) FROM payments + UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues + UNION DISTINCT SELECT YEAR(invoice_date) FROM invoices ORDER BY all_years DESC "); @@ -26,32 +26,32 @@ $sql_years_select = mysqli_query( $largest_income_month = 0; //Get Total income -$sql_total_payments_to_invoices = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments_to_invoices FROM payments WHERE YEAR(payment_date) = $year AND company_id = $session_company_id"); +$sql_total_payments_to_invoices = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments_to_invoices FROM payments WHERE YEAR(payment_date) = $year"); $row = mysqli_fetch_array($sql_total_payments_to_invoices); $total_payments_to_invoices = floatval($row['total_payments_to_invoices']); //Do not grab transfer payment as these have a category_id of 0 -$sql_total_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE YEAR(revenue_date) = $year AND revenue_category_id > 0 AND company_id = $session_company_id"); +$sql_total_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE YEAR(revenue_date) = $year AND revenue_category_id > 0"); $row = mysqli_fetch_array($sql_total_revenues); $total_revenues = floatval($row['total_revenues']); $total_income = $total_payments_to_invoices + $total_revenues; //Get Total expenses and do not grab transfer expenses as these have a vendor of 0 -$sql_total_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE expense_vendor_id > 0 AND YEAR(expense_date) = $year AND company_id = $session_company_id"); +$sql_total_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE expense_vendor_id > 0 AND YEAR(expense_date) = $year"); $row = mysqli_fetch_array($sql_total_expenses); $total_expenses = floatval($row['total_expenses']); //Total up all the Invoices that are not draft or cancelled -$sql_invoice_totals = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_totals FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' AND YEAR(invoice_date) = $year AND company_id = $session_company_id"); +$sql_invoice_totals = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_totals FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' AND YEAR(invoice_date) = $year"); $row = mysqli_fetch_array($sql_invoice_totals); $invoice_totals = floatval($row['invoice_totals']); //Quaeries from Receivables -$sql_total_payments_to_invoices_all_years = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments_to_invoices_all_years FROM payments WHERE company_id = $session_company_id"); +$sql_total_payments_to_invoices_all_years = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments_to_invoices_all_years FROM payments"); $row = mysqli_fetch_array($sql_total_payments_to_invoices_all_years); $total_payments_to_invoices_all_years = floatval($row['total_payments_to_invoices_all_years']); -$sql_invoice_totals_all_years = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_totals_all_years FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' AND company_id = $session_company_id"); +$sql_invoice_totals_all_years = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_totals_all_years FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled'"); $row = mysqli_fetch_array($sql_invoice_totals_all_years); $invoice_totals_all_years = floatval($row['invoice_totals_all_years']); @@ -59,14 +59,13 @@ $receivables = $invoice_totals_all_years - $total_payments_to_invoices_all_years $profit = $total_income - $total_expenses; -$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE company_id = $session_company_id"); +$sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts"); $sql_latest_invoice_payments = mysqli_query( $mysqli, "SELECT * FROM payments, invoices, clients WHERE payment_invoice_id = invoice_id AND invoice_client_id = client_id - AND clients.company_id = $session_company_id ORDER BY payment_id DESC LIMIT 5" ); @@ -75,31 +74,30 @@ $sql_latest_expenses = mysqli_query( "SELECT * FROM expenses, vendors, categories WHERE expense_vendor_id = vendor_id AND expense_category_id = category_id - AND expenses.company_id = $session_company_id ORDER BY expense_id DESC LIMIT 5" ); //Get Monthly Recurring Total -$sql_recurring_monthly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month' AND company_id = $session_company_id"); +$sql_recurring_monthly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month'"); $row = mysqli_fetch_array($sql_recurring_monthly_total); $recurring_monthly_total = floatval($row['recurring_monthly_total']); //Get Yearly Recurring Total -$sql_recurring_yearly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year' AND company_id = $session_company_id"); +$sql_recurring_yearly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year'"); $row = mysqli_fetch_array($sql_recurring_yearly_total); $recurring_yearly_total = floatval($row['recurring_yearly_total']); //Get Total Miles Driven -$sql_miles_driven = mysqli_query($mysqli, "SELECT SUM(trip_miles) AS total_miles FROM trips WHERE YEAR(trip_date) = $year AND company_id = $session_company_id"); +$sql_miles_driven = mysqli_query($mysqli, "SELECT SUM(trip_miles) AS total_miles FROM trips WHERE YEAR(trip_date) = $year"); $row = mysqli_fetch_array($sql_miles_driven); $total_miles = floatval($row['total_miles']); //Get Total Clients added -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS clients_added FROM clients WHERE YEAR(client_created_at) = $year AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS clients_added FROM clients WHERE YEAR(client_created_at) = $year")); $clients_added = intval($row['clients_added']); //Get Total Vendors added -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS vendors_added FROM vendors WHERE YEAR(vendor_created_at) = $year AND vendor_client_id = 0 AND vendor_template = 0 AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('vendor_id') AS vendors_added FROM vendors WHERE YEAR(vendor_created_at) = $year AND vendor_client_id = 0 AND vendor_template = 0")); $vendors_added = intval($row['vendors_added']); ?> @@ -490,11 +488,11 @@ $vendors_added = intval($row['vendors_added']); data: [ 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month AND company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenues_for_month = floatval($row['revenue_amount_for_month']); @@ -529,11 +527,11 @@ $vendors_added = intval($row['vendors_added']); data: [ 0 AND YEAR(revenue_date) = $year-1 AND MONTH(revenue_date) = $month AND company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year-1 AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenues_for_month = floatval($row['revenue_amount_for_month']); @@ -571,7 +569,7 @@ $vendors_added = intval($row['vendors_added']); $largest_invoice_month = 0; for($month = 1; $month<=12; $month++) { - $sql_projected = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_amount_for_month FROM invoices WHERE YEAR(invoice_due) = $year AND MONTH(invoice_due) = $month AND invoice_status NOT LIKE 'Cancelled' AND invoice_status NOT LIKE 'Draft' AND company_id = $session_company_id"); + $sql_projected = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_amount_for_month FROM invoices WHERE YEAR(invoice_due) = $year AND MONTH(invoice_due) = $month AND invoice_status NOT LIKE 'Cancelled' AND invoice_status NOT LIKE 'Draft'"); $row = mysqli_fetch_array($sql_projected); $invoice_for_month = floatval($row['invoice_amount_for_month']); @@ -607,7 +605,7 @@ $vendors_added = intval($row['vendors_added']); $largest_expense_month = 0; for($month = 1; $month<=12; $month++) { - $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0 AND expenses.company_id = $session_company_id"); + $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0"); $row = mysqli_fetch_array($sql_expenses); $expenses_for_month = floatval($row['expense_amount_for_month']); @@ -683,7 +681,7 @@ $vendors_added = intval($row['vendors_added']); data: [ 0 AND YEAR(expense_date) = $year AND categories.company_id = $session_company_id"); + $sql_categories = mysqli_query($mysqli, "SELECT DISTINCT category_name, categories.category_id FROM categories, expenses WHERE expense_category_id = category_id AND expense_vendor_id > 0 AND YEAR(expense_date) = $year"); while ($row = mysqli_fetch_array($sql_categories)) { $category_name = json_encode($row['category_name']); echo "$category_name,"; @@ -815,7 +813,7 @@ $vendors_added = intval($row['vendors_added']); datasets: [{ data: [ 0 AND YEAR(expense_date) = $year AND categories.company_id = $session_company_id"); + $sql_categories = mysqli_query($mysqli, "SELECT DISTINCT category_name, categories.category_id FROM categories, expenses WHERE expense_category_id = category_id AND expense_vendor_id > 0 AND YEAR(expense_date) = $year"); while ($row = mysqli_fetch_array($sql_categories)) { $category_id = $row['category_id']; @@ -830,7 +828,7 @@ $vendors_added = intval($row['vendors_added']); ], backgroundColor: [ 0 AND YEAR(expense_date) = $year AND categories.company_id = $session_company_id"); + $sql_categories = mysqli_query($mysqli, "SELECT DISTINCT category_name, category_color FROM categories, expenses WHERE expense_category_id = categories.category_id AND expense_vendor_id > 0 AND YEAR(expense_date) = $year"); while ($row = mysqli_fetch_array($sql_categories)) { $category_color = json_encode($row['category_color']); echo "$category_color,"; @@ -856,7 +854,7 @@ $vendors_added = intval($row['vendors_added']); data: { labels: [ CURRENT_DATE AND domain_expire < CURRENT_DATE + INTERVAL 30 DAY - AND domain_archived_at IS NULL - AND company_id = $session_company_id" + AND domain_archived_at IS NULL" )); $expiring_domains = $sql_domains_expiring['expiring_domains']; @@ -76,8 +70,7 @@ $sql_certs_expiring = mysqli_fetch_assoc(mysqli_query( WHERE certificate_expire IS NOT NULL AND certificate_expire > CURRENT_DATE AND certificate_expire < CURRENT_DATE + INTERVAL 30 DAY - AND certificate_archived_at IS NULL - AND company_id = $session_company_id" + AND certificate_archived_at IS NULL" )); $expiring_certificates = $sql_certs_expiring['expiring_certs']; diff --git a/database_updates.php b/database_updates.php index 04b5b8ad..9701fda6 100644 --- a/database_updates.php +++ b/database_updates.php @@ -877,13 +877,65 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.5'"); } - //if (CURRENT_DATABASE_VERSION == '0.4.5') { - // Insert queries here required to update to DB version 0.4.6 + if (CURRENT_DATABASE_VERSION == '0.4.5') { + // Insert queries here required to update to DB version 0.4.6 + mysqli_query($mysqli, "ALTER TABLE `contacts` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `locations` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `assets` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `software` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `logins` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `networks` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `certificates` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `domains` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `tickets` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `ticket_replies` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `scheduled_tickets` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `services` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `vendors` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `calendars` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `events` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `files` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `documents` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `folders` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `invoices` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `recurring` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `quotes` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `history` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `invoice_items` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `payments` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `trips` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `clients` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `expenses` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `transfers` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `revenues` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `api_keys` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `taxes` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `categories` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `tags` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `accounts` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `interfaces` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `records` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `logs` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `notifications` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `products` DROP `company_id`"); + mysqli_query($mysqli, "ALTER TABLE `companies` DROP `company_archived_at`"); + mysqli_query($mysqli, "ALTER TABLE `user_settings` DROP `user_default_company`"); + mysqli_query($mysqli, "DROP TABLE `user_companies`"); + mysqli_query($mysqli, "DROP TABLE `user_keys`"); //Unused Table + + // Then, update the database to the next sequential version + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.6'"); + } + + //if (CURRENT_DATABASE_VERSION == '0.4.6') { + // Insert queries here required to update to DB version 0.4.7 // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.6'"); + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.7'"); //} } else { // Up-to-date } + + diff --git a/database_version.php b/database_version.php index 5bb6c5c4..2f849a21 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.4.5"); +DEFINE("LATEST_DATABASE_VERSION", "0.4.6"); diff --git a/db.sql b/db.sql index e3b3dd42..88e3b429 100644 --- a/db.sql +++ b/db.sql @@ -31,7 +31,6 @@ CREATE TABLE `accounts` ( `account_created_at` datetime NOT NULL DEFAULT current_timestamp(), `account_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `account_archived_at` datetime DEFAULT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`account_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -50,7 +49,6 @@ CREATE TABLE `api_keys` ( `api_key_created_at` datetime NOT NULL DEFAULT current_timestamp(), `api_key_expire` date NOT NULL, `api_key_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`api_key_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -129,7 +127,6 @@ CREATE TABLE `assets` ( `asset_contact_id` int(11) NOT NULL DEFAULT 0, `asset_network_id` int(11) NOT NULL DEFAULT 0, `asset_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -148,7 +145,6 @@ CREATE TABLE `calendars` ( `calendar_created_at` datetime NOT NULL DEFAULT current_timestamp(), `calendar_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `calendar_archived_at` datetime DEFAULT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`calendar_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -168,7 +164,6 @@ CREATE TABLE `categories` ( `category_created_at` datetime NOT NULL DEFAULT current_timestamp(), `category_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `category_archived_at` datetime DEFAULT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -194,7 +189,6 @@ CREATE TABLE `certificates` ( `certificate_accessed_at` datetime DEFAULT NULL, `certificate_domain_id` int(11) NOT NULL DEFAULT 0, `certificate_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`certificate_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -235,7 +229,6 @@ CREATE TABLE `clients` ( `client_accessed_at` datetime DEFAULT NULL, `primary_location` int(11) NOT NULL DEFAULT 0, `primary_contact` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`client_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -263,7 +256,6 @@ CREATE TABLE `companies` ( `company_currency` varchar(200) NOT NULL, `company_created_at` datetime NOT NULL DEFAULT current_timestamp(), `company_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), - `company_archived_at` datetime DEFAULT NULL, PRIMARY KEY (`company_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -355,7 +347,6 @@ CREATE TABLE `contacts` ( `contact_location_id` int(11) NOT NULL DEFAULT 0, `contact_department` varchar(200) DEFAULT NULL, `contact_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -379,7 +370,6 @@ CREATE TABLE `documents` ( `document_template` tinyint(1) NOT NULL DEFAULT 0, `document_folder_id` int(11) NOT NULL DEFAULT 0, `document_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`document_id`), FULLTEXT KEY `document_content_raw` (`document_content_raw`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; @@ -408,7 +398,6 @@ CREATE TABLE `domains` ( `domain_registrar` int(11) NOT NULL DEFAULT 0, `domain_webhost` int(11) NOT NULL DEFAULT 0, `domain_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`domain_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -433,7 +422,6 @@ CREATE TABLE `events` ( `event_client_id` int(11) NOT NULL DEFAULT 0, `event_location_id` int(11) NOT NULL DEFAULT 0, `event_calendar_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`event_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -461,7 +449,6 @@ CREATE TABLE `expenses` ( `expense_client_id` int(11) NOT NULL DEFAULT 0, `expense_category_id` int(11) NOT NULL DEFAULT 0, `expense_account_id` int(11) DEFAULT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`expense_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -483,7 +470,6 @@ CREATE TABLE `files` ( `file_archived_at` datetime DEFAULT NULL, `file_accessed_at` datetime DEFAULT NULL, `file_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`file_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -500,7 +486,6 @@ CREATE TABLE `folders` ( `folder_name` varchar(200) NOT NULL, `parent_folder` int(11) NOT NULL DEFAULT 0, `folder_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`folder_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -520,7 +505,6 @@ CREATE TABLE `history` ( `history_invoice_id` int(11) NOT NULL DEFAULT 0, `history_recurring_id` int(11) NOT NULL DEFAULT 0, `history_quote_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`history_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -544,7 +528,6 @@ CREATE TABLE `interfaces` ( `interface_connected_asset_id` int(11) NOT NULL DEFAULT 0, `interface_network_id` int(11) NOT NULL DEFAULT 0, `interface_asset_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`interface_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -572,7 +555,6 @@ CREATE TABLE `invoice_items` ( `item_quote_id` int(11) NOT NULL DEFAULT 0, `item_recurring_id` int(11) NOT NULL DEFAULT 0, `item_invoice_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`item_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -601,7 +583,6 @@ CREATE TABLE `invoices` ( `invoice_archived_at` datetime DEFAULT NULL, `invoice_category_id` int(11) NOT NULL, `invoice_client_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`invoice_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -631,7 +612,6 @@ CREATE TABLE `locations` ( `location_accessed_at` datetime DEFAULT NULL, `location_contact_id` int(11) NOT NULL DEFAULT 0, `location_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`location_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -662,7 +642,6 @@ CREATE TABLE `logins` ( `login_asset_id` int(11) NOT NULL DEFAULT 0, `login_software_id` int(11) NOT NULL DEFAULT 0, `login_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`login_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -685,7 +664,6 @@ CREATE TABLE `logs` ( `log_client_id` int(11) NOT NULL DEFAULT 0, `log_user_id` int(11) NOT NULL DEFAULT 0, `log_entity_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) DEFAULT NULL, PRIMARY KEY (`log_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -711,7 +689,6 @@ CREATE TABLE `networks` ( `network_accessed_at` datetime DEFAULT NULL, `network_location_id` int(11) NOT NULL DEFAULT 0, `network_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`network_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -732,7 +709,6 @@ CREATE TABLE `notifications` ( `notification_dismissed_by` int(11) DEFAULT NULL, `notification_client_id` int(11) NOT NULL DEFAULT 0, `notification_user_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`notification_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -756,7 +732,6 @@ CREATE TABLE `payments` ( `payment_archived_at` datetime DEFAULT NULL, `payment_account_id` int(11) NOT NULL, `payment_invoice_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`payment_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -779,7 +754,6 @@ CREATE TABLE `products` ( `product_archived_at` datetime DEFAULT NULL, `product_tax_id` int(11) NOT NULL DEFAULT 0, `product_category_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -807,7 +781,6 @@ CREATE TABLE `quotes` ( `quote_archived_at` datetime DEFAULT NULL, `quote_category_id` int(11) NOT NULL, `quote_client_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`quote_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -829,7 +802,6 @@ CREATE TABLE `records` ( `record_updated_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(), `record_archived_at` datetime DEFAULT NULL, `record_domain_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`record_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -858,7 +830,6 @@ CREATE TABLE `recurring` ( `recurring_archived_at` datetime DEFAULT NULL, `recurring_category_id` int(11) NOT NULL, `recurring_client_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`recurring_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -884,7 +855,6 @@ CREATE TABLE `revenues` ( `revenue_category_id` int(11) NOT NULL DEFAULT 0, `revenue_account_id` int(11) NOT NULL, `revenue_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`revenue_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -911,7 +881,6 @@ CREATE TABLE `scheduled_tickets` ( `scheduled_ticket_client_id` int(11) NOT NULL DEFAULT 0, `scheduled_ticket_contact_id` int(11) NOT NULL DEFAULT 0, `scheduled_ticket_asset_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`scheduled_ticket_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1027,7 +996,6 @@ CREATE TABLE `services` ( `service_accessed_at` datetime DEFAULT NULL, `service_review_due` date DEFAULT NULL, `service_client_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`service_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1150,7 +1118,6 @@ CREATE TABLE `software` ( `software_login_id` int(11) NOT NULL DEFAULT 0, `software_client_id` int(11) NOT NULL, `software_template_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`software_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1241,7 +1208,6 @@ CREATE TABLE `tags` ( `tag_created_at` datetime NOT NULL DEFAULT current_timestamp(), `tag_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `tag_archived_at` datetime DEFAULT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`tag_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1260,7 +1226,6 @@ CREATE TABLE `taxes` ( `tax_created_at` datetime NOT NULL DEFAULT current_timestamp(), `tax_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `tax_archived_at` datetime DEFAULT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`tax_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1282,7 +1247,6 @@ CREATE TABLE `ticket_replies` ( `ticket_reply_archived_at` datetime DEFAULT NULL, `ticket_reply_by` int(11) NOT NULL, `ticket_reply_ticket_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`ticket_reply_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1332,7 +1296,6 @@ CREATE TABLE `tickets` ( `ticket_contact_id` int(11) NOT NULL DEFAULT 0, `ticket_location_id` int(11) NOT NULL DEFAULT 0, `ticket_asset_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`ticket_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1352,7 +1315,6 @@ CREATE TABLE `transfers` ( `transfer_archived_at` datetime DEFAULT NULL, `transfer_expense_id` int(11) NOT NULL, `transfer_revenue_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, PRIMARY KEY (`transfer_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1379,41 +1341,10 @@ CREATE TABLE `trips` ( `trip_archived_at` datetime DEFAULT NULL, `trip_user_id` int(11) NOT NULL DEFAULT 0, `trip_client_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`trip_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `user_companies` --- - -DROP TABLE IF EXISTS `user_companies`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `user_companies` ( - `user_id` int(11) NOT NULL, - `company_id` int(11) NOT NULL, - PRIMARY KEY (`user_id`,`company_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `user_keys` --- - -DROP TABLE IF EXISTS `user_keys`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `user_keys` ( - `user_key_id` int(11) NOT NULL AUTO_INCREMENT, - `user_key_name` varchar(200) DEFAULT NULL, - `user_public_key` varchar(250) NOT NULL, - `user_id` int(11) NOT NULL, - PRIMARY KEY (`user_key_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `user_settings` -- @@ -1423,7 +1354,6 @@ DROP TABLE IF EXISTS `user_settings`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `user_settings` ( `user_id` int(11) NOT NULL, - `user_default_company` int(11) NOT NULL, `user_role` int(11) NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; @@ -1524,7 +1454,6 @@ CREATE TABLE `vendors` ( `vendor_accessed_at` datetime DEFAULT NULL, `vendor_client_id` int(11) NOT NULL DEFAULT 0, `vendor_template_id` int(11) NOT NULL DEFAULT 0, - `company_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1538,4 +1467,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-02-25 15:25:59 +-- Dump completed on 2023-03-08 13:31:23 diff --git a/expense_add_modal.php b/expense_add_modal.php index 5ee99a22..9fefa710 100644 --- a/expense_add_modal.php +++ b/expense_add_modal.php @@ -43,7 +43,7 @@ - Vendor - - Category - '$expense_created_at' OR account_archived_at IS NULL) AND company_id = $session_company_id ORDER BY account_name ASC"); + $sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$expense_created_at' OR account_archived_at IS NULL) ORDER BY account_name ASC"); while ($row = mysqli_fetch_array($sql_accounts)) { $account_id_select = intval($row['account_id']); $account_name_select = htmlentities($row['account_name']); @@ -85,7 +85,7 @@ '$expense_created_at' OR category_archived_at IS NULL) AND company_id = $session_company_id ORDER BY category_name ASC"); + $sql_select = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Expense' AND (category_archived_at > '$expense_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC"); while ($row = mysqli_fetch_array($sql_select)) { $category_id_select = intval($row['category_id']); $category_name_select = htmlentities($row['category_name']); @@ -156,7 +156,10 @@
- "> + " + download=""> + + diff --git a/expenses.php b/expenses.php index f62985fd..1ca20bc9 100644 --- a/expenses.php +++ b/expenses.php @@ -15,8 +15,7 @@ $sql = mysqli_query( LEFT JOIN categories ON expense_category_id = category_id LEFT JOIN vendors ON expense_vendor_id = vendor_id LEFT JOIN accounts ON expense_account_id = account_id - WHERE expenses.company_id = $session_company_id - AND expense_vendor_id > 0 + WHERE expense_vendor_id > 0 AND DATE(expense_date) BETWEEN '$dtf' AND '$dtt' AND (vendor_name LIKE '%$q%' OR category_name LIKE '%$q%' OR account_name LIKE '%$q%' OR expense_description LIKE '%$q%' OR expense_amount LIKE '%$q%') ORDER BY $sb $o LIMIT $record_from, $record_to" @@ -39,7 +38,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
- +
@@ -86,7 +85,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

-
+
"> @@ -121,7 +120,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); if (empty($expense_receipt)) { $receipt_attached = ""; } else { - $receipt_attached = ""; + $receipt_attached = ""; } ?> @@ -141,7 +140,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - + @@ -127,7 +126,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent -
+

@@ -141,9 +140,9 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent

- @@ -196,7 +195,6 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent "SELECT * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN contacts ON contact_id = primary_contact - LEFT JOIN companies ON invoices.company_id = companies.company_id WHERE invoice_id = $pi_invoice_id AND invoice_status != 'Draft' AND invoice_status != 'Paid' @@ -215,11 +213,14 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent $invoice_amount = floatval($row['invoice_amount']); $invoice_currency_code = htmlentities($row['invoice_currency_code']); $invoice_url_key = htmlentities($row['invoice_url_key']); - $invoice_company_id = intval($row['company_id']); $client_id = intval($row['client_id']); $client_name = htmlentities($row['client_name']); $contact_name = $row['contact_name']; $contact_email = $row['contact_email']; + + $sql_company = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = 1"); + $row = mysqli_fetch_array($sql_company); + $company_name = mysqli_real_escape_string($mysqli, htmlentities($row['company_name'])); $company_phone = htmlentities($row['company_phone']); $company_locale = htmlentities($row['company_locale']); @@ -241,24 +242,24 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent // Apply payment // Update Invoice Status - mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Paid' WHERE invoice_id = $invoice_id AND company_id = $invoice_company_id"); + mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Paid' WHERE invoice_id = $invoice_id"); // Add Payment to History - mysqli_query($mysqli, "INSERT INTO payments SET payment_date = '$pi_date', payment_amount = $pi_amount_paid, payment_currency_code = '$pi_currency', payment_account_id = $config_stripe_account, payment_method = 'Stripe', payment_reference = 'Stripe - $pi_id', payment_invoice_id = $invoice_id, company_id = $invoice_company_id"); - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Paid', history_description = 'Payment added - $ip - $os - $browser', history_invoice_id = $invoice_id, company_id = $invoice_company_id"); + mysqli_query($mysqli, "INSERT INTO payments SET payment_date = '$pi_date', payment_amount = $pi_amount_paid, payment_currency_code = '$pi_currency', payment_account_id = $config_stripe_account, payment_method = 'Stripe', payment_reference = 'Stripe - $pi_id', payment_invoice_id = $invoice_id"); + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Paid', history_description = 'Payment added - $ip - $os - $browser', history_invoice_id = $invoice_id"); // Notify - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Paid', notification = 'Invoice $invoice_prefix$invoice_number has been paid - $ip - $os - $browser', notification_client_id = $pi_client_id, company_id = $invoice_company_id"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Paid', notification = 'Invoice $invoice_prefix$invoice_number has been paid - $ip - $os - $browser', notification_client_id = $pi_client_id"); // Logging $extended_log_desc = ''; if (!$pi_livemode) { $extended_log_desc = '(DEV MODE)'; } - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Payment', log_action = 'Create', log_description = 'Stripe payment of $pi_currency $pi_amount_paid against invoice $invoice_prefix$invoice_number - $pi_id $extended_log_desc', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = $pi_client_id, company_id = $invoice_company_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Payment', log_action = 'Create', log_description = 'Stripe payment of $pi_currency $pi_amount_paid against invoice $invoice_prefix$invoice_number - $pi_id $extended_log_desc', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = $pi_client_id"); // Send email receipt - $sql_settings = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = $invoice_company_id"); + $sql_settings = mysqli_query($mysqli, "SELECT * FROM settings WHERE company_id = 1"); $row = mysqli_fetch_array($sql_settings); $config_smtp_host = $row['config_smtp_host']; @@ -291,12 +292,12 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent // Email Logging if ($mail === true) { - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Receipt!', history_invoice_id = $invoice_id, company_id = $invoice_company_id"); + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Emailed Receipt!', history_invoice_id = $invoice_id"); } else { - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Email Receipt Failed!', history_invoice_id = $invoice_id, company_id = $invoice_company_id"); + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Sent', history_description = 'Email Receipt Failed!', history_invoice_id = $invoice_id"); - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', company_id = $invoice_company_id"); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $invoice_company_id"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email'"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail'"); } } diff --git a/guest_post.php b/guest_post.php index 46613506..862875ba 100644 --- a/guest_post.php +++ b/guest_post.php @@ -5,19 +5,18 @@ require_once("functions.php"); session_start(); -if (isset($_GET['accept_quote'], $_GET['company_id'], $_GET['url_key'])) { +if (isset($_GET['accept_quote'], $_GET['url_key'])) { $quote_id = intval($_GET['accept_quote']); - $company_id = intval($_GET['company_id']); $url_key = sanitizeInput($_GET['url_key']); - $sql = mysqli_query($mysqli, "SELECT * FROM quotes WHERE quote_id = $quote_id AND quote_url_key = '$url_key' AND company_id = $company_id"); + $sql = mysqli_query($mysqli, "SELECT * FROM quotes WHERE quote_id = $quote_id AND quote_url_key = '$url_key'"); if (mysqli_num_rows($sql) == 1) { mysqli_query($mysqli, "UPDATE quotes SET quote_status = 'Accepted' WHERE quote_id = $quote_id"); - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Accepted', history_description = 'Client accepted Quote!', history_quote_id = $quote_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Accepted', history_description = 'Client accepted Quote!', history_quote_id = $quote_id"); $_SESSION['alert_message'] = "Quote Accepted"; @@ -28,19 +27,18 @@ if (isset($_GET['accept_quote'], $_GET['company_id'], $_GET['url_key'])) { } -if (isset($_GET['decline_quote'], $_GET['company_id'], $_GET['url_key'])) { +if (isset($_GET['decline_quote'], $_GET['url_key'])) { $quote_id = intval($_GET['decline_quote']); - $company_id = intval($_GET['company_id']); $url_key = sanitizeInput($_GET['url_key']); - $sql = mysqli_query($mysqli, "SELECT * FROM quotes WHERE quote_id = $quote_id AND quote_url_key = '$url_key' AND company_id = $company_id"); + $sql = mysqli_query($mysqli, "SELECT * FROM quotes WHERE quote_id = $quote_id AND quote_url_key = '$url_key'"); if (mysqli_num_rows($sql) == 1) { mysqli_query($mysqli, "UPDATE quotes SET quote_status = 'Declined' WHERE quote_id = $quote_id"); - mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Declined', history_description = 'Client declined Quote!', history_quote_id = $quote_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Declined', history_description = 'Client declined Quote!', history_quote_id = $quote_id"); $_SESSION['alert_type'] = "danger"; $_SESSION['alert_message'] = "Quote Declined"; diff --git a/guest_view_invoice.php b/guest_view_invoice.php index 1f521c01..649c668b 100644 --- a/guest_view_invoice.php +++ b/guest_view_invoice.php @@ -17,8 +17,6 @@ $sql = mysqli_query( LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN locations ON primary_location = location_id LEFT JOIN contacts ON primary_contact = contact_id - LEFT JOIN companies ON invoices.company_id = companies.company_id - LEFT JOIN settings ON settings.company_id = companies.company_id WHERE invoice_id = $invoice_id AND invoice_url_key = '$url_key'" ); @@ -31,6 +29,7 @@ if (mysqli_num_rows($sql) !== 1) { } $row = mysqli_fetch_array($sql); + $invoice_id = intval($row['invoice_id']); $invoice_prefix = htmlentities($row['invoice_prefix']); $invoice_number = intval($row['invoice_number']); @@ -57,7 +56,10 @@ $client_net_terms = intval($row['client_net_terms']); if ($client_net_terms == 0) { $client_net_terms = intval($row['config_default_net_terms']); } -$company_id = intval($row['company_id']); + +$sql = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id AND companies.company_id = 1"); +$row = mysqli_fetch_array($sql); + $company_name = htmlentities($row['company_name']); $company_address = htmlentities($row['company_address']); $company_city = htmlentities($row['company_city']); @@ -68,7 +70,7 @@ $company_email = htmlentities($row['company_email']); $company_website = htmlentities($row['company_website']); $company_logo = htmlentities($row['company_logo']); if (!empty($company_logo)) { - $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); + $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_logo")); } $company_locale = htmlentities($row['company_locale']); $config_invoice_footer = htmlentities($row['config_invoice_footer']); @@ -88,11 +90,11 @@ if ($invoice_status == 'Sent') { } //Mark viewed in history -mysqli_query($mysqli, "INSERT INTO history SET history_status = '$invoice_status', history_description = 'Invoice viewed - $ip - $os - $browser', history_invoice_id = $invoice_id, company_id = $company_id"); +mysqli_query($mysqli, "INSERT INTO history SET history_status = '$invoice_status', history_description = 'Invoice viewed - $ip - $os - $browser', history_invoice_id = $invoice_id"); if ($invoice_status !== 'Paid') { $client_name_escaped = sanitizeInput($row['client_name']); - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Viewed', notification = 'Invoice $invoice_prefix$invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Viewed', notification = 'Invoice $invoice_prefix$invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_client_id = $client_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"); @@ -122,7 +124,7 @@ $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE it
Invoice History Print - ');">Download + ');">Download Pay Online @@ -132,7 +134,7 @@ $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE it
- "> + ">
diff --git a/guest_view_item.php b/guest_view_item.php index 4b55c2b0..50380c58 100644 --- a/guest_view_item.php +++ b/guest_view_item.php @@ -77,7 +77,7 @@ if ($item_type == "Document") { // Logging $name = mysqli_real_escape_string($mysqli, $doc_title); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Sharing', log_action = 'View', log_description = 'Viewed shared $item_type $name via link', log_client_id = $client_id, log_ip = '$ip', log_user_agent = '$user_agent', company_id = 1"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Sharing', log_action = 'View', log_description = 'Viewed shared $item_type $name via link', log_client_id = $client_id, log_ip = '$ip', log_user_agent = '$user_agent'"); } elseif ($item_type == "File") { $file_sql = mysqli_query($mysqli, "SELECT * FROM files WHERE file_id = $item_related_id AND file_client_id = $client_id LIMIT 1"); @@ -142,7 +142,7 @@ if ($item_type == "Document") { // Logging $name = sanitizeInput($login_row['login_name']); - mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Sharing', log_action = 'View', log_description = 'Viewed shared $item_type $name via link', log_client_id = $client_id, log_ip = '$ip', log_user_agent = '$ua', company_id = 1"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Sharing', log_action = 'View', log_description = 'Viewed shared $item_type $name via link', log_client_id = $client_id, log_ip = '$ip', log_user_agent = '$ua'"); } diff --git a/guest_view_quote.php b/guest_view_quote.php index 50d2d835..1944509c 100644 --- a/guest_view_quote.php +++ b/guest_view_quote.php @@ -18,8 +18,6 @@ $sql = mysqli_query( LEFT JOIN clients ON quote_client_id = client_id LEFT JOIN locations ON primary_location = location_id LEFT JOIN contacts ON primary_contact = contact_id - LEFT JOIN companies ON quotes.company_id = companies.company_id - LEFT JOIN settings ON settings.company_id = companies.company_id WHERE quote_id = $quote_id AND quote_url_key = '$url_key'" ); @@ -58,7 +56,9 @@ $client_net_terms = intval($row['client_net_terms']); if ($client_net_terms == 0) { $client_net_terms = intval($row['config_default_net_terms']); } -$company_id = intval($row['company_id']); + +$sql = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id AND companies.company_id = 1"); +$row = mysqli_fetch_array($sql); $company_name = htmlentities($row['company_name']); $company_address = htmlentities($row['company_address']); $company_city = htmlentities($row['company_city']); @@ -69,7 +69,7 @@ $company_email = htmlentities($row['company_email']); $company_website = htmlentities($row['company_website']); $company_logo = htmlentities($row['company_logo']); if (!empty($company_logo)) { - $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); + $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_logo")); } $company_locale = htmlentities($row['company_locale']); $config_quote_footer = htmlentities($row['config_quote_footer']); @@ -83,11 +83,11 @@ if ($quote_status == 'Sent') { } //Mark viewed in history -mysqli_query($mysqli, "INSERT INTO history SET history_status = '$quote_status', history_description = 'Quote viewed - $ip - $os - $browser', history_quote_id = $quote_id, company_id = $company_id"); +mysqli_query($mysqli, "INSERT INTO history SET history_status = '$quote_status', history_description = 'Quote viewed - $ip - $os - $browser', history_quote_id = $quote_id"); if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Viewed") { $client_name_escaped = sanitizeInput($row['client_name']); - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Quote Viewed', notification = 'Quote $quote_prefix$quote_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_client_id = $client_id, company_id = $company_id"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Quote Viewed', notification = 'Quote $quote_prefix$quote_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_client_id = $client_id"); } ?> @@ -99,10 +99,10 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie - + Accept - + Decline @@ -110,7 +110,7 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie @@ -119,7 +119,7 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie
- "> + ">

Quote

diff --git a/inc_all_client.php b/inc_all_client.php index 9e9aeda7..08d02675 100644 --- a/inc_all_client.php +++ b/inc_all_client.php @@ -9,15 +9,14 @@ require_once("top_nav.php"); if (isset($_GET['client_id'])) { $client_id = intval($_GET['client_id']); - $sql = mysqli_query($mysqli, "UPDATE clients SET client_accessed_at = NOW() WHERE client_id = $client_id AND company_id = $session_company_id"); + $sql = mysqli_query($mysqli, "UPDATE clients SET client_accessed_at = NOW() WHERE client_id = $client_id"); $sql = mysqli_query( $mysqli, "SELECT * FROM clients LEFT JOIN locations ON primary_location = location_id AND location_archived_at IS NULL LEFT JOIN contacts ON primary_contact = contact_id AND contact_archived_at IS NULL - WHERE client_id = $client_id - AND clients.company_id = $session_company_id" + WHERE client_id = $client_id" ); if (mysqli_num_rows($sql) == 0) { @@ -89,13 +88,13 @@ if (isset($_GET['client_id'])) { $balance = $invoice_amounts - $amount_paid; //Get Monthly Recurring Total - $sql_recurring_monthly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month' AND recurring_client_id = $client_id AND company_id = $session_company_id"); + $sql_recurring_monthly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month' AND recurring_client_id = $client_id"); $row = mysqli_fetch_array($sql_recurring_monthly_total); $recurring_monthly_total = floatval($row['recurring_monthly_total']); //Get Yearly Recurring Total - $sql_recurring_yearly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year' AND recurring_client_id = $client_id AND company_id = $session_company_id"); + $sql_recurring_yearly_total = mysqli_query($mysqli, "SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year' AND recurring_client_id = $client_id"); $row = mysqli_fetch_array($sql_recurring_yearly_total); $recurring_yearly_total = floatval($row['recurring_yearly_total']) / 12; @@ -197,8 +196,7 @@ if (isset($_GET['client_id'])) { WHERE domain_client_id = $client_id AND domain_expire IS NOT NULL AND domain_expire < CURRENT_DATE + INTERVAL 30 DAY - AND domain_archived_at IS NULL - AND company_id = $session_company_id" + AND domain_archived_at IS NULL" )); $num_domains_expiring = intval($row['num']); @@ -209,8 +207,7 @@ if (isset($_GET['client_id'])) { WHERE certificate_client_id = $client_id AND certificate_expire IS NOT NULL AND certificate_expire < CURRENT_DATE + INTERVAL 30 DAY - AND certificate_archived_at IS NULL - AND company_id = $session_company_id" + AND certificate_archived_at IS NULL" )); $num_certs_expiring = intval($row['num']); @@ -222,7 +219,7 @@ if (isset($_GET['client_id'])) { AND asset_warranty_expire IS NOT NULL AND asset_archived_at IS NULL AND asset_warranty_expire < CURRENT_DATE + INTERVAL 90 DAY - AND company_id = $session_company_id ORDER BY asset_warranty_expire DESC" + ORDER BY asset_warranty_expire DESC" ); // Get Assets Retiring @@ -233,7 +230,7 @@ if (isset($_GET['client_id'])) { AND asset_install_date IS NOT NULL AND asset_archived_at IS NULL AND asset_install_date + INTERVAL 7 YEAR < CURRENT_DATE + INTERVAL 90 DAY - AND company_id = $session_company_id ORDER BY asset_install_date DESC" + ORDER BY asset_install_date DESC" ); // Get Stale Tickets @@ -243,7 +240,7 @@ if (isset($_GET['client_id'])) { WHERE ticket_client_id = $client_id AND ticket_created_at < CURRENT_DATE - INTERVAL 14 DAY AND ticket_status != 'Closed' - AND company_id = $session_company_id ORDER BY ticket_created_at DESC" + ORDER BY ticket_created_at DESC" ); } diff --git a/invoice.php b/invoice.php index fe9694e2..66e026a4 100644 --- a/invoice.php +++ b/invoice.php @@ -12,7 +12,6 @@ if (isset($_GET['invoice_id'])) { LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN locations ON primary_location = location_id LEFT JOIN contacts ON primary_contact = contact_id - LEFT JOIN companies ON invoices.company_id = companies.company_id WHERE invoice_id = $invoice_id" ); @@ -52,6 +51,9 @@ if (isset($_GET['invoice_id'])) { if ($client_net_terms == 0) { $client_net_terms = $config_default_net_terms; } + + $sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = 1"); + $row = mysqli_fetch_array($sql); $company_id = intval($row['company_id']); $company_name = htmlentities($row['company_name']); $company_country = htmlentities($row['company_country']); @@ -64,7 +66,7 @@ if (isset($_GET['invoice_id'])) { $company_website = htmlentities($row['company_website']); $company_logo = htmlentities($row['company_logo']); if (!empty($company_logo)) { - $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); + $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_logo")); } $sql_history = mysqli_query($mysqli, "SELECT * FROM history WHERE history_invoice_id = $invoice_id ORDER BY history_id DESC"); @@ -89,7 +91,7 @@ if (isset($_GET['invoice_id'])) { $invoice_badge_color = getInvoiceBadgeColor($invoice_status); //Product autocomplete - $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id"); + $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products"); if (mysqli_num_rows($products_sql) > 0) { while ($row = mysqli_fetch_array($products_sql)) { @@ -164,7 +166,7 @@ if (isset($_GET['invoice_id'])) { Print - ');"> + ');"> Download PDF @@ -194,7 +196,7 @@ if (isset($_GET['invoice_id'])) {
- " alt="Company logo"> + " alt="Company logo">
@@ -331,7 +333,7 @@ if (isset($_GET['invoice_id'])) { - Client - - Category - - Category - '$invoice_created_at' OR category_archived_at IS NULL) AND company_id = $session_company_id ORDER BY category_name ASC"); + $sql_income_category = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND (category_archived_at > '$invoice_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC"); while ($row = mysqli_fetch_array($sql_income_category)) { $category_id_select= intval($row['category_id']); $category_name_select = htmlentities($row['category_name']); diff --git a/invoice_payment_add_modal.php b/invoice_payment_add_modal.php index 6f97603c..0c86ca83 100644 --- a/invoice_payment_add_modal.php +++ b/invoice_payment_add_modal.php @@ -54,7 +54,7 @@ - Method of Payment - diff --git a/invoices.php b/invoices.php index 3b43fc30..78b38c37 100644 --- a/invoices.php +++ b/invoices.php @@ -6,50 +6,50 @@ $o = "DESC"; require_once("inc_all.php"); -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Sent' AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Sent'")); $sent_count = $row['num']; -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Viewed' AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Viewed'")); $viewed_count = $row['num']; -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Partial' AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Partial'")); $partial_count = $row['num']; -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Draft' AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Draft'")); $draft_count = $row['num']; -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Cancelled' AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Cancelled'")); $cancelled_count = $row['num']; -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_due > CURDATE() AND company_id = $session_company_id")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_due > CURDATE()")); $overdue_count = $row['num']; -$sql_total_draft = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_draft FROM invoices WHERE invoice_status = 'Draft' AND company_id = $session_company_id"); +$sql_total_draft = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_draft FROM invoices WHERE invoice_status = 'Draft'"); $row = mysqli_fetch_array($sql_total_draft); $total_draft = floatval($row['total_draft']); -$sql_total_sent = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_sent FROM invoices WHERE invoice_status = 'Sent' AND company_id = $session_company_id"); +$sql_total_sent = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_sent FROM invoices WHERE invoice_status = 'Sent'"); $row = mysqli_fetch_array($sql_total_sent); $total_sent = floatval($row['total_sent']); -$sql_total_viewed = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_viewed FROM invoices WHERE invoice_status = 'Viewed' AND company_id = $session_company_id"); +$sql_total_viewed = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_viewed FROM invoices WHERE invoice_status = 'Viewed'"); $row = mysqli_fetch_array($sql_total_viewed); $total_viewed = floatval($row['total_viewed']); -$sql_total_cancelled = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_cancelled FROM invoices WHERE invoice_status = 'Cancelled' AND company_id = $session_company_id"); +$sql_total_cancelled = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_cancelled FROM invoices WHERE invoice_status = 'Cancelled'"); $row = mysqli_fetch_array($sql_total_cancelled); $total_cancelled = floatval($row['total_cancelled']); -$sql_total_partial = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_partial FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial' AND invoices.company_id = $session_company_id"); +$sql_total_partial = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_partial FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial'"); $row = mysqli_fetch_array($sql_total_partial); $total_partial = floatval($row['total_partial']); $total_partial_count = mysqli_num_rows($sql_total_partial); -$sql_total_overdue_partial = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_overdue_partial FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial' AND invoice_due < CURDATE() AND invoices.company_id = $session_company_id"); +$sql_total_overdue_partial = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_overdue_partial FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial' AND invoice_due < CURDATE()"); $row = mysqli_fetch_array($sql_total_overdue_partial); $total_overdue_partial = floatval($row['total_overdue_partial']); -$sql_total_overdue = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_overdue FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Paid' AND invoice_due < CURDATE() AND invoices.company_id = $session_company_id"); +$sql_total_overdue = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_overdue FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Paid' AND invoice_due < CURDATE()"); $row = mysqli_fetch_array($sql_total_overdue); $total_overdue = floatval($row['total_overdue']); @@ -76,8 +76,7 @@ $sql = mysqli_query( "SELECT SQL_CALC_FOUND_ROWS * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN categories ON invoice_category_id = category_id - WHERE invoices.company_id = $session_company_id - AND (invoice_status LIKE '$status_query') + WHERE (invoice_status LIKE '$status_query') AND DATE(invoice_date) BETWEEN '$dtf' AND '$dtt' AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$q%' OR invoice_scope LIKE '%$q%' OR client_name LIKE '%$q%' OR invoice_status LIKE '%$q%' OR invoice_amount LIKE '%$q%' OR category_name LIKE '%$q%') ORDER BY $sb $o LIMIT $record_from, $record_to" @@ -160,7 +159,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
- +
@@ -202,7 +201,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

-
+
"> diff --git a/item_edit_modal.php b/item_edit_modal.php index 197760cc..8f247fa9 100644 --- a/item_edit_modal.php +++ b/item_edit_modal.php @@ -77,7 +77,7 @@ '$item_created_at' OR tax_archived_at IS NULL) AND company_id = $session_company_id ORDER BY tax_name ASC"); + $taxes_sql = mysqli_query($mysqli, "SELECT * FROM taxes WHERE (tax_archived_at > '$item_created_at' OR tax_archived_at IS NULL) ORDER BY tax_name ASC"); while ($row = mysqli_fetch_array($taxes_sql)) { $tax_id_select = intval($row['tax_id']); $tax_name = htmlentities($row['tax_name']); diff --git a/login.php b/login.php index fb48fda4..d390dbdd 100644 --- a/login.php +++ b/login.php @@ -145,7 +145,7 @@ if (isset($_POST['login'])) { // Set PHP session in DB, so we can access the session encryption data (above) $user_php_session = session_id(); - mysqli_query($mysqli, "UPDATE users SET user_php_session = '$user_php_session' WHERE user_id = '$user_id'"); + mysqli_query($mysqli, "UPDATE users SET user_php_session = '$user_php_session' WHERE user_id = $user_id"); } } @@ -228,7 +228,7 @@ if (isset($_POST['login'])) { - <?php echo $config_app_name; ?> | Login + <?php echo htmlentities($company_name); ?> | Login @@ -244,7 +244,7 @@ if (isset($_POST['login'])) {
"> diff --git a/models/user.php b/models/user.php index 1790a99e..919b662b 100644 --- a/models/user.php +++ b/models/user.php @@ -1,5 +1,4 @@ @@ -18,7 +18,7 @@ $sql = mysqli_query($mysqli, "SELECT * FROM notifications LEFT JOIN clients ON n
0) { ?> -
+
diff --git a/notifications_dismissed.php b/notifications_dismissed.php index 73df5d33..7d5db7ff 100644 --- a/notifications_dismissed.php +++ b/notifications_dismissed.php @@ -18,7 +18,6 @@ $sql = mysqli_query( WHERE (notification_type LIKE '%$q%' OR notification LIKE '%$q%' OR user_name LIKE '%$q%' OR client_name LIKE '%$q%') AND DATE(notification_timestamp) BETWEEN '$dtf' AND '$dtt' AND (notification_user_id = $session_user_id OR notification_user_id = 0) - AND notifications.company_id = $session_company_id AND notification_dismissed_at IS NOT NULL ORDER BY $sb $o LIMIT $record_from, $record_to @@ -64,7 +63,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); -
+
"> diff --git a/payments.php b/payments.php index fbf2a083..f9128f48 100644 --- a/payments.php +++ b/payments.php @@ -15,8 +15,7 @@ $sql = mysqli_query( LEFT JOIN invoices ON payment_invoice_id = invoice_id LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN accounts ON payment_account_id = account_id - WHERE payments.company_id = $session_company_id - AND DATE(payment_date) BETWEEN '$dtf' AND '$dtt' + WHERE DATE(payment_date) BETWEEN '$dtf' AND '$dtt' AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$q%' OR client_name LIKE '%$q%' OR account_name LIKE '%$q%' OR payment_method LIKE '%$q%' OR payment_reference LIKE '%$q%') ORDER BY $sb $o LIMIT $record_from, $record_to" ); @@ -77,7 +76,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> diff --git a/portal/check_login.php b/portal/check_login.php index 0274e9bc..161f907a 100644 --- a/portal/check_login.php +++ b/portal/check_login.php @@ -28,11 +28,10 @@ $session_user_agent = sanitizeInput($_SERVER['HTTP_USER_AGENT']); // Get info from session $session_client_id = intval($_SESSION['client_id']); $session_contact_id = intval($_SESSION['contact_id']); -$session_company_id = intval($_SESSION['company_id']); // Get company info from database -$sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = $session_company_id"); +$sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = 1"); $row = mysqli_fetch_array($sql); $session_company_name = $row['company_name']; @@ -43,7 +42,7 @@ $currency_format = numfmt_create($session_company_locale, NumberFormatter::CURRE // Get contact info -$contact_sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_id = '$session_contact_id' AND contact_client_id = '$session_client_id'"); +$contact_sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_id = $session_contact_id AND contact_client_id = $session_client_id"); $contact = mysqli_fetch_array($contact_sql); $session_contact_name = sanitizeInput($contact['contact_name']); diff --git a/portal/inc_portal.php b/portal/inc_portal.php index 8b77da7e..f3b31d84 100644 --- a/portal/inc_portal.php +++ b/portal/inc_portal.php @@ -19,4 +19,9 @@ if (!isset($_SESSION)) { session_start(); } +// Get Company Information +$sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = 1"); +$row = mysqli_fetch_array($sql); +$company_name = $row['company_name']; + require_once("portal_header.php"); \ No newline at end of file diff --git a/portal/index.php b/portal/index.php index 8e4f4c0b..a267fc60 100644 --- a/portal/index.php +++ b/portal/index.php @@ -11,7 +11,7 @@ require_once("inc_portal.php");
- " alt="..." height="50" width="50" class="img-circle img-responsive"> + " alt="..." height="50" width="50" class="img-circle img-responsive"> diff --git a/portal/invoices.php b/portal/invoices.php index 5b243c99..e33ab9a9 100644 --- a/portal/invoices.php +++ b/portal/invoices.php @@ -17,7 +17,7 @@ $invoices_sql = mysqli_query($mysqli, "SELECT * FROM invoices WHERE invoice_clie
- " alt="..." height="50" width="50" class="img-circle img-responsive"> + " alt="..." height="50" width="50" class="img-circle img-responsive"> diff --git a/portal/login.php b/portal/login.php index bf3a42e9..f4238184 100644 --- a/portal/login.php +++ b/portal/login.php @@ -94,7 +94,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['login'])) {
"> diff --git a/quote.php b/quote.php index 8badc430..2eb5e500 100644 --- a/quote.php +++ b/quote.php @@ -11,7 +11,6 @@ if (isset($_GET['quote_id'])) { LEFT JOIN clients ON quote_client_id = client_id LEFT JOIN locations ON primary_location = location_id LEFT JOIN contacts ON primary_contact = contact_id - LEFT JOIN companies ON quotes.company_id = companies.company_id WHERE quote_id = $quote_id" ); @@ -50,6 +49,10 @@ if (isset($_GET['quote_id'])) { if ($client_net_terms == 0) { $client_net_terms = $config_default_net_terms; } + + $sql = mysqli_query($mysqli, "SELECT * FROM companies, settings WHERE companies.company_id = settings.company_id AND companies.company_id = 1"); + $row = mysqli_fetch_array($sql); + $company_id = intval($row['company_id']); $company_name = htmlentities($row['company_name']); $company_country = htmlentities($row['company_country']); @@ -62,7 +65,7 @@ if (isset($_GET['quote_id'])) { $company_website = htmlentities($row['company_website']); $company_logo = htmlentities($row['company_logo']); if (!empty($company_logo)) { - $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); + $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_logo")); } $sql_history = mysqli_query($mysqli, "SELECT * FROM history WHERE history_quote_id = $quote_id ORDER BY history_id DESC"); @@ -83,7 +86,7 @@ if (isset($_GET['quote_id'])) { } //Product autocomplete - $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id"); + $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products"); if (mysqli_num_rows($products_sql) > 0) { while ($row = mysqli_fetch_array($products_sql)) { @@ -161,7 +164,7 @@ if (isset($_GET['quote_id'])) { Print ');"> + onclick="pdfMake.createPdf(docDefinition).download('');"> Download PDF @@ -186,7 +189,7 @@ if (isset($_GET['quote_id'])) {
- " alt="Company logo"> + " alt="Company logo">
@@ -320,7 +323,7 @@ if (isset($_GET['quote_id'])) { - Client - - Category - - Category - '$quote_created_at' OR category_archived_at IS NULL) AND company_id = $session_company_id ORDER BY category_name ASC"); + $sql_income_category = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND (category_archived_at > '$quote_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC"); while ($row = mysqli_fetch_array($sql_income_category)) { $category_id_select = intval($row['category_id']); $category_name_select = htmlentities($row['category_name']); diff --git a/quotes.php b/quotes.php index 79ac782e..5b3e9d7d 100644 --- a/quotes.php +++ b/quotes.php @@ -14,8 +14,7 @@ $sql = mysqli_query( "SELECT SQL_CALC_FOUND_ROWS * FROM quotes LEFT JOIN clients ON quote_client_id = client_id LEFT JOIN categories ON quote_category_id = category_id - WHERE quotes.company_id = $session_company_id - AND (CONCAT(quote_prefix,quote_number) LIKE '%$q%' OR quote_scope LIKE '%$q%' OR category_name LIKE '%$q%' OR quote_status LIKE '%$q%' OR quote_amount LIKE '%$q%' OR client_name LIKE '%$q%') + WHERE (CONCAT(quote_prefix,quote_number) LIKE '%$q%' OR quote_scope LIKE '%$q%' OR category_name LIKE '%$q%' OR quote_status LIKE '%$q%' OR quote_amount LIKE '%$q%' OR client_name LIKE '%$q%') AND DATE(quote_date) BETWEEN '$dtf' AND '$dtt' ORDER BY $sb $o LIMIT $record_from, $record_to"); @@ -78,7 +77,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

-
+
"> diff --git a/recurring_invoice.php b/recurring_invoice.php index 83c04471..f5dfad66 100644 --- a/recurring_invoice.php +++ b/recurring_invoice.php @@ -11,12 +11,10 @@ if (isset($_GET['recurring_id'])) { LEFT JOIN clients ON recurring_client_id = client_id LEFT JOIN locations ON primary_location = location_id LEFT JOIN contacts ON primary_contact = contact_id - LEFT JOIN companies ON recurring.company_id = companies.company_id WHERE recurring_id = $recurring_id" ); $row = mysqli_fetch_array($sql); - $recurring_id = intval($row['recurring_id']); $recurring_prefix = htmlentities($row['recurring_prefix']); $recurring_number = intval($row['recurring_number']); $recurring_scope = htmlentities($row['recurring_scope']); @@ -53,6 +51,10 @@ if (isset($_GET['recurring_id'])) { $status = "Inactive"; $status_badge_color = "secondary"; } + + $sql = mysqli_query($mysqli, "SELECT * FROM companies WHERE company_id = 1"); + $row = mysqli_fetch_array($sql); + $company_id = intval($row['company_id']); $company_name = htmlentities($row['company_name']); $company_country = htmlentities($row['company_country']); @@ -68,7 +70,7 @@ if (isset($_GET['recurring_id'])) { $sql_history = mysqli_query($mysqli, "SELECT * FROM history WHERE history_recurring_id = $recurring_id ORDER BY history_id DESC"); //Product autocomplete - $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id"); + $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products"); if (mysqli_num_rows($products_sql) > 0) { while ($row = mysqli_fetch_array($products_sql)) { @@ -122,7 +124,7 @@ if (isset($_GET['recurring_id'])) {
- Company logo"> + Company logo">
@@ -258,7 +260,7 @@ if (isset($_GET['recurring_id'])) { - Client - - Category - - Category - '$recurring_created_at' OR category_archived_at IS NULL) AND company_id = $session_company_id ORDER BY category_name ASC"); + $sql_income_category = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND (category_archived_at > '$recurring_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC"); while ($row = mysqli_fetch_array($sql_income_category)) { $category_id_select= intval($row['category_id']); $category_name_select = htmlentities($row['category_name']); diff --git a/recurring_invoices.php b/recurring_invoices.php index 381c678e..66849e45 100644 --- a/recurring_invoices.php +++ b/recurring_invoices.php @@ -14,8 +14,7 @@ $sql = mysqli_query( "SELECT SQL_CALC_FOUND_ROWS * FROM recurring LEFT JOIN clients ON recurring_client_id = client_id LEFT JOIN categories ON recurring_category_id = category_id - WHERE recurring.company_id = $session_company_id - AND (CONCAT(recurring_prefix,recurring_number) LIKE '%$q%' OR recurring_frequency LIKE '%$q%' OR recurring_scope LIKE '%$q%' OR client_name LIKE '%$q%' OR category_name LIKE '%$q%') + WHERE (CONCAT(recurring_prefix,recurring_number) LIKE '%$q%' OR recurring_frequency LIKE '%$q%' OR recurring_scope LIKE '%$q%' OR client_name LIKE '%$q%' OR category_name LIKE '%$q%') AND DATE(recurring_last_sent) BETWEEN '$dtf' AND '$dtt' ORDER BY $sb $o LIMIT $record_from, $record_to"); @@ -78,7 +77,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

-
+
"> diff --git a/report_expense_by_vendor.php b/report_expense_by_vendor.php index 326e53c9..43ca3eb5 100644 --- a/report_expense_by_vendor.php +++ b/report_expense_by_vendor.php @@ -9,9 +9,12 @@ if (isset($_GET['year'])) { $year = date('Y'); } -$sql_payment_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments WHERE company_id = $session_company_id UNION SELECT DISTINCT YEAR(revenue_date) AS payment_year FROM revenues WHERE company_id = $session_company_id ORDER BY payment_year DESC"); +$sql_payment_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments + UNION SELECT DISTINCT YEAR(revenue_date) AS payment_year FROM revenues + ORDER BY payment_year DESC" +); -$sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors WHERE company_id = $session_company_id"); +$sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors WHERE vendor_template = 0"); ?> @@ -39,7 +42,7 @@ $sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors WHERE company_id = $ -
+
diff --git a/report_expense_summary.php b/report_expense_summary.php index 33f05dbc..e9e9aa9d 100644 --- a/report_expense_summary.php +++ b/report_expense_summary.php @@ -9,9 +9,9 @@ if (isset($_GET['year'])) { $year = date('Y'); } -$sql_expense_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(expense_date) AS expense_year FROM expenses WHERE expense_category_id > 0 AND company_id = $session_company_id ORDER BY expense_year DESC"); +$sql_expense_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(expense_date) AS expense_year FROM expenses WHERE expense_category_id > 0 ORDER BY expense_year DESC"); -$sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Expense' AND company_id = $session_company_id ORDER BY category_name ASC"); +$sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Expense' ORDER BY category_name ASC"); ?> @@ -39,7 +39,7 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category -
+
@@ -94,7 +94,7 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category 0 AND company_id = $session_company_id"); + $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0"); $row = mysqli_fetch_array($sql_expenses); $expense_total_amount_for_month = floatval($row['expense_total_amount_for_month']); $total_expense_for_all_months = $expense_total_amount_for_month + $total_expense_for_all_months; @@ -143,7 +143,7 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category $largest_expense_month = 0; for ($month = 1; $month<=12; $month++) { - $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0 AND expenses.company_id = $session_company_id"); + $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0"); $row = mysqli_fetch_array($sql_expenses); $expenses_for_month = floatval($row['expense_amount_for_month']); diff --git a/report_income_by_client.php b/report_income_by_client.php index 74de7436..c98a2496 100644 --- a/report_income_by_client.php +++ b/report_income_by_client.php @@ -9,7 +9,10 @@ if (isset($_GET['year'])) { $year = date('Y'); } -$sql_payment_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments WHERE company_id = $session_company_id UNION SELECT DISTINCT YEAR(revenue_date) AS payment_year FROM revenues WHERE company_id = $session_company_id ORDER BY payment_year DESC"); +$sql_payment_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments + UNION SELECT DISTINCT YEAR(revenue_date) AS payment_year FROM revenues + ORDER BY payment_year DESC" +); ?> @@ -41,14 +44,13 @@ $sql_payment_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(payment_date) A JOIN invoices AS i ON c.client_id = i.invoice_client_id JOIN payments AS p ON i.invoice_id = p.payment_invoice_id WHERE YEAR(p.payment_date) = $year - AND c.company_id = $session_company_id GROUP BY c.client_id HAVING amount_paid > 599 ORDER BY amount_paid DESC" ); ?> -
+
diff --git a/report_income_summary.php b/report_income_summary.php index 60836df3..01006063 100644 --- a/report_income_summary.php +++ b/report_income_summary.php @@ -9,9 +9,11 @@ if (isset($_GET['year'])) { $year = date('Y'); } -$sql_payment_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments WHERE company_id = $session_company_id UNION SELECT DISTINCT YEAR(revenue_date) AS payment_year FROM revenues WHERE company_id = $session_company_id ORDER BY payment_year DESC"); +$sql_payment_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments + UNION SELECT DISTINCT YEAR(revenue_date) AS payment_year FROM revenues + ORDER BY payment_year DESC"); -$sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND company_id = $session_company_id ORDER BY category_name ASC"); +$sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' ORDER BY category_name ASC"); ?> @@ -41,7 +43,7 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category -
+
@@ -114,11 +116,11 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month AND revenues.company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenues_total_amount_for_month = floatval($row['revenue_amount_for_month']); @@ -171,11 +173,11 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month AND company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenues_for_month = floatval($row['revenue_amount_for_month']); diff --git a/report_profit_loss.php b/report_profit_loss.php index 2beebd82..317b59fb 100644 --- a/report_profit_loss.php +++ b/report_profit_loss.php @@ -10,11 +10,15 @@ if (isset($_GET['year'])) { } //GET unique years from expenses, payments and revenues -$sql_all_years = mysqli_query($mysqli, "SELECT YEAR(expense_date) AS all_years FROM expenses WHERE company_id = $session_company_id UNION DISTINCT SELECT YEAR(payment_date) FROM payments WHERE company_id = $session_company_id UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues WHERE company_id = $session_company_id ORDER BY all_years DESC"); +$sql_all_years = mysqli_query($mysqli, "SELECT YEAR(expense_date) AS all_years FROM expenses + UNION DISTINCT SELECT YEAR(payment_date) FROM payments + UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues + ORDER BY all_years DESC" +); -$sql_categories_income = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND company_id = $session_company_id ORDER BY category_name ASC"); +$sql_categories_income = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' ORDER BY category_name ASC"); -$sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Expense' AND company_id = $session_company_id ORDER BY category_name ASC"); +$sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Expense' ORDER BY category_name ASC"); ?> @@ -42,7 +46,7 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE -
+
@@ -174,11 +178,11 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $payment_total_amount_for_quarter_one = 0; for($month = 1; $month<=3; $month++) { - $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month AND payments.company_id = $session_company_id"); + $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month"); $row = mysqli_fetch_array($sql_payments); $payment_total_amount_for_month = floatval($row['payment_total_amount_for_month']); - $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month AND revenues.company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenue_total_amount_for_month = floatval($row['revenue_total_amount_for_month']); @@ -196,11 +200,11 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $payment_total_amount_for_quarter_two = 0; for($month = 4; $month<=6; $month++) { - $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month AND payments.company_id = $session_company_id"); + $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month"); $row = mysqli_fetch_array($sql_payments); $payment_total_amount_for_month = floatval($row['payment_total_amount_for_month']); - $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month AND revenues.company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenue_total_amount_for_month = floatval($row['revenue_total_amount_for_month']); @@ -218,11 +222,11 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $payment_total_amount_for_quarter_three = 0; for($month = 7; $month<=9; $month++) { - $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month AND payments.company_id = $session_company_id"); + $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month"); $row = mysqli_fetch_array($sql_payments); $payment_total_amount_for_month = floatval($row['payment_total_amount_for_month']); - $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month AND revenues.company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenue_total_amount_for_month = floatval($row['revenue_total_amount_for_month']); @@ -240,11 +244,11 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $payment_total_amount_for_quarter_four = 0; for($month = 10; $month<=12; $month++) { - $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month AND payments.company_id = $session_company_id"); + $sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payment_invoice_id = invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month"); $row = mysqli_fetch_array($sql_payments); $payment_total_amount_for_month = floatval($row['payment_total_amount_for_month']); - $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month AND revenues.company_id = $session_company_id"); + $sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE revenue_category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month"); $row = mysqli_fetch_array($sql_revenues); $revenue_total_amount_for_month = floatval($row['revenue_total_amount_for_month']); @@ -351,7 +355,7 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $expense_total_amount_for_quarter_one = 0; for($month = 1; $month<=3; $month++) { - $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0 AND company_id = $session_company_id"); + $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0"); $row = mysqli_fetch_array($sql_expenses); $expense_total_amount_for_quarter_one = $expense_total_amount_for_quarter_one + floatval($row['expense_total_amount_for_month']); } @@ -365,7 +369,7 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $expense_total_amount_for_quarter_two = 0; for($month = 4; $month<=6; $month++) { - $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0 AND company_id = $session_company_id"); + $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0"); $row = mysqli_fetch_array($sql_expenses); $expense_total_amount_for_quarter_two = $expense_total_amount_for_quarter_two + floatval($row['expense_total_amount_for_month']); } @@ -379,7 +383,7 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $expense_total_amount_for_quarter_three = 0; for($month = 7; $month<=9; $month++) { - $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0 AND company_id = $session_company_id"); + $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0"); $row = mysqli_fetch_array($sql_expenses); $expense_total_amount_for_quarter_three = $expense_total_amount_for_quarter_three + floatval($row['expense_total_amount_for_month']); } @@ -393,7 +397,7 @@ $sql_categories_expense = mysqli_query($mysqli, "SELECT * FROM categories WHERE $expense_total_amount_for_quarter_four = 0; for($month = 10; $month<=12; $month++) { - $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0 AND company_id = $session_company_id"); + $sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE expense_category_id > 0 AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0"); $row = mysqli_fetch_array($sql_expenses); $expense_total_amount_for_quarter_four = $expense_total_amount_for_quarter_four + floatval($row['expense_total_amount_for_month']); } diff --git a/report_recurring_by_client.php b/report_recurring_by_client.php index d1a48b09..ebfd23b8 100644 --- a/report_recurring_by_client.php +++ b/report_recurring_by_client.php @@ -9,8 +9,7 @@ $sql = mysqli_query($mysqli, " WHEN recurring.recurring_frequency = 'year' THEN recurring.recurring_amount / 12 END) AS recurring_monthly_total FROM clients LEFT JOIN recurring ON clients.client_id = recurring.recurring_client_id - WHERE clients.company_id = $session_company_id - AND recurring.recurring_status = 1 + WHERE recurring.recurring_status = 1 GROUP BY clients.client_id HAVING recurring_monthly_total > 0 ORDER BY recurring_monthly_total DESC @@ -26,7 +25,7 @@ $sql = mysqli_query($mysqli, "
-
+
diff --git a/report_tax_summary.php b/report_tax_summary.php index c6a664ec..0d48a039 100644 --- a/report_tax_summary.php +++ b/report_tax_summary.php @@ -10,9 +10,9 @@ if (isset($_GET['year'])) { } //GET unique years from expenses, payments and revenues -$sql_all_years = mysqli_query($mysqli, "SELECT DISTINCT(YEAR(item_created_at)) AS all_years FROM invoice_items WHERE company_id = $session_company_id ORDER BY all_years DESC"); +$sql_all_years = mysqli_query($mysqli, "SELECT DISTINCT(YEAR(item_created_at)) AS all_years FROM invoice_items ORDER BY all_years DESC"); -$sql_tax = mysqli_query($mysqli, "SELECT * FROM taxes WHERE company_id = $session_company_id ORDER BY tax_name ASC"); +$sql_tax = mysqli_query($mysqli, "SELECT * FROM taxes ORDER BY tax_name ASC"); ?> @@ -39,7 +39,7 @@ $sql_tax = mysqli_query($mysqli, "SELECT * FROM taxes WHERE company_id = $sessio -
+
diff --git a/report_ticket_by_client.php b/report_ticket_by_client.php index cc40971d..e8104709 100644 --- a/report_ticket_by_client.php +++ b/report_ticket_by_client.php @@ -47,9 +47,9 @@ if (isset($_GET['year'])) { $year = date('Y'); } -$sql_ticket_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(ticket_created_at) AS ticket_year FROM tickets WHERE company_id = $session_company_id ORDER BY ticket_year DESC"); +$sql_ticket_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(ticket_created_at) AS ticket_year FROM tickets ORDER BY ticket_year DESC"); -$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE company_id = $session_company_id ORDER BY client_name ASC"); +$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients ORDER BY client_name ASC"); ?> @@ -71,7 +71,7 @@ $sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients -
+
diff --git a/report_ticket_summary.php b/report_ticket_summary.php index 388d4d58..65ee787e 100644 --- a/report_ticket_summary.php +++ b/report_ticket_summary.php @@ -9,9 +9,9 @@ if (isset($_GET['year'])) { $year = date('Y'); } -$sql_ticket_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(ticket_created_at) AS ticket_year FROM tickets WHERE company_id = $session_company_id ORDER BY ticket_year DESC"); +$sql_ticket_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(ticket_created_at) AS ticket_year FROM tickets ORDER BY ticket_year DESC"); -$sql_tickets = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE company_id = $session_company_id"); +$sql_tickets = mysqli_query($mysqli, "SELECT ticket_id FROM tickets"); ?> @@ -35,7 +35,7 @@ $sql_tickets = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE compan -
+
diff --git a/revenue_add_modal.php b/revenue_add_modal.php index 91ecb3a5..2c1f7689 100644 --- a/revenue_add_modal.php +++ b/revenue_add_modal.php @@ -61,7 +61,7 @@ - Category - - Method of Payment - diff --git a/revenue_edit_modal.php b/revenue_edit_modal.php index 3ef0b92c..1e97d064 100644 --- a/revenue_edit_modal.php +++ b/revenue_edit_modal.php @@ -62,7 +62,7 @@ '$revenue_created_at' OR account_archived_at IS NULL) AND company_id = $session_company_id ORDER BY account_name ASC"); + $sql_accounts = mysqli_query($mysqli, "SELECT * FROM accounts WHERE (account_archived_at > '$revenue_created_at' OR account_archived_at IS NULL) ORDER BY account_name ASC"); while ($row = mysqli_fetch_array($sql_accounts)) { $account_id_select = intval($row['account_id']); $account_name_select = htmlentities($row['account_name']); @@ -103,7 +103,7 @@ '$revenue_created_at' OR category_archived_at IS NULL) AND company_id = $session_company_id ORDER BY category_name ASC"); + $sql_category = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Income' AND (category_archived_at > '$revenue_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC"); while ($row = mysqli_fetch_array($sql_category)) { $category_id_select = intval($row['category_id']); $category_name = htmlentities($row['category_name']); @@ -139,7 +139,7 @@ '$revenue_created_at' OR category_archived_at IS NULL) AND company_id = $session_company_id ORDER BY category_name ASC"); + $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Payment Method' AND (category_archived_at > '$revenue_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC"); while ($row = mysqli_fetch_array($sql_categories)) { $category_name_select = htmlentities($row['category_name']); ?> diff --git a/revenues.php b/revenues.php index cb665ff1..8b33f226 100644 --- a/revenues.php +++ b/revenues.php @@ -14,8 +14,7 @@ $sql = mysqli_query( "SELECT SQL_CALC_FOUND_ROWS * FROM revenues JOIN categories ON revenue_category_id = category_id LEFT JOIN accounts ON revenue_account_id = account_id - WHERE revenues.company_id = $session_company_id - AND (account_name LIKE '%$q%' OR revenue_payment_method LIKE '%$q%' OR category_name LIKE '%$q%' OR revenue_reference LIKE '%$q%' OR revenue_amount LIKE '%$q%') + WHERE (account_name LIKE '%$q%' OR revenue_payment_method LIKE '%$q%' OR category_name LIKE '%$q%' OR revenue_reference LIKE '%$q%' OR revenue_amount LIKE '%$q%') AND DATE(revenue_date) BETWEEN '$dtf' AND '$dtt' ORDER BY $sb $o LIMIT $record_from, $record_to"); @@ -36,7 +35,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
- +
@@ -78,7 +77,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

-
+
"> diff --git a/scheduled_ticket_add_modal.php b/scheduled_ticket_add_modal.php index a9c549b3..e3ed8b68 100644 --- a/scheduled_ticket_add_modal.php +++ b/scheduled_ticket_add_modal.php @@ -43,7 +43,7 @@
-
+
diff --git a/settings_api.php b/settings_api.php index 7e8185c2..e533a34b 100644 --- a/settings_api.php +++ b/settings_api.php @@ -14,8 +14,8 @@ $sql = mysqli_query( "SELECT SQL_CALC_FOUND_ROWS * FROM api_keys LEFT JOIN clients on api_keys.api_key_client_id = clients.client_id WHERE (api_key_name LIKE '%$q%') - AND api_keys.company_id = $session_company_id - ORDER BY $sb $o LIMIT $record_from, $record_to"); + ORDER BY $sb $o LIMIT $record_from, $record_to" +); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); @@ -38,7 +38,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));

-
+
"> diff --git a/settings_company.php b/settings_company.php new file mode 100644 index 00000000..b323be15 --- /dev/null +++ b/settings_company.php @@ -0,0 +1,177 @@ + + +
+
+

Company Details

+
+
+
+ + +
+ +
+
+ +
+ +
+
+ +
+
+ "> +
+
+ +
+ +
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ + + + +
+
+ + - - + +
"> diff --git a/settings_tags.php b/settings_tags.php index 550e4307..9bcc2036 100644 --- a/settings_tags.php +++ b/settings_tags.php @@ -13,7 +13,6 @@ $sql = mysqli_query( $mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM tags WHERE tag_name LIKE '%$q%' - AND company_id = $session_company_id ORDER BY $sb $o LIMIT $record_from, $record_to" ); @@ -26,8 +25,7 @@ if ($num_rows > 0) { $sql_colors_used = mysqli_query( $mysqli, "SELECT tag_color FROM tags - WHERE tag_archived_at IS NULL - AND company_id = $session_company_id" + WHERE tag_archived_at IS NULL" ); while ($color_used_row = mysqli_fetch_array($sql_colors_used)) { @@ -67,7 +65,7 @@ if ($num_rows > 0) {
-
+
"> diff --git a/settings_taxes.php b/settings_taxes.php index 4fa7a0c2..a55d4ba3 100644 --- a/settings_taxes.php +++ b/settings_taxes.php @@ -13,7 +13,6 @@ $sql = mysqli_query( $mysqli, "SELECT * FROM taxes WHERE tax_archived_at IS NULL - AND company_id = $session_company_id ORDER BY $sb $o" ); @@ -29,7 +28,7 @@ $num_rows = mysqli_num_rows($sql);
-
+
"> diff --git a/setup.php b/setup.php index 88ad76bb..ed30518d 100644 --- a/setup.php +++ b/setup.php @@ -908,7 +908,7 @@ if (isset($_POST['add_user'])) { } //Create Settings - mysqli_query($mysqli,"INSERT INTO user_settings SET user_id = $user_id, user_role = 3, user_default_company = 1"); + mysqli_query($mysqli,"INSERT INTO user_settings SET user_id = $user_id, user_role = 3"); $_SESSION['alert_message'] = "User $name created!"; @@ -937,17 +937,6 @@ if (isset($_POST['add_company_settings'])) { mysqli_query($mysqli,"INSERT INTO companies SET company_name = '$name', company_address = '$address', company_city = '$city', company_state = '$state', company_zip = '$zip', company_country = '$country', company_phone = '$phone', company_email = '$email', company_website = '$website', company_locale = '$locale', company_currency = '$currency_code'"); - $company_id = mysqli_insert_id($mysqli); - - mkdirMissing("uploads/clients/$company_id"); - file_put_contents("uploads/clients/$company_id/index.php", ""); - mkdirMissing("uploads/expenses/$company_id"); - file_put_contents("uploads/expenses/$company_id/index.php", ""); - mkdirMissing("uploads/settings/$company_id"); - file_put_contents("uploads/settings/$company_id/index.php", ""); - mkdirMissing("uploads/tmp/$company_id"); - file_put_contents("uploads/tmp/$company_id/index.php", ""); - //Check to see if a file is attached if ($_FILES['file']['tmp_name'] != '') { @@ -976,12 +965,12 @@ if (isset($_POST['add_company_settings'])) { if ($file_error == 0) { // directory in which the uploaded file will be moved - $upload_file_dir = "uploads/settings/$company_id/"; + $upload_file_dir = "uploads/settings/"; $dest_path = $upload_file_dir . $new_file_name; move_uploaded_file($file_tmp_path, $dest_path); - mysqli_query($mysqli,"UPDATE companies SET company_logo = '$new_file_name' WHERE company_id = $company_id"); + mysqli_query($mysqli,"UPDATE companies SET company_logo = '$new_file_name' WHERE company_id = 1"); $_SESSION['alert_message'] = 'File successfully uploaded.'; } else { @@ -991,28 +980,28 @@ if (isset($_POST['add_company_settings'])) { } //Set User Company Permissions - mysqli_query($mysqli,"INSERT INTO user_companies SET user_id = $user_id, company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO user_companies SET user_id = $user_id, company_id = 1"); $latest_database_version = LATEST_DATABASE_VERSION; - mysqli_query($mysqli,"INSERT INTO settings SET company_id = $company_id, config_current_database_version = '$latest_database_version', config_invoice_prefix = 'INV-', config_invoice_next_number = 1, config_recurring_prefix = 'REC-', config_recurring_next_number = 1, config_invoice_overdue_reminders = '1,3,7', config_quote_prefix = 'QUO-', config_quote_next_number = 1, config_default_net_terms = 30, config_ticket_next_number = 1, config_ticket_prefix = 'TCK-'"); + mysqli_query($mysqli,"INSERT INTO settings SET company_id = 1, config_current_database_version = '$latest_database_version', config_invoice_prefix = 'INV-', config_invoice_next_number = 1, config_recurring_prefix = 'REC-', config_recurring_next_number = 1, config_invoice_overdue_reminders = '1,3,7', config_quote_prefix = 'QUO-', config_quote_next_number = 1, config_default_net_terms = 30, config_ticket_next_number = 1, config_ticket_prefix = 'TCK-'"); //Create Some Data - mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_currency_code = '$currency_code', company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_currency_code = '$currency_code', company_id = 1"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue', company_id = $company_id"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Travel', category_type = 'Expense', category_color = 'red', company_id = $company_id"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Advertising', category_type = 'Expense', category_color = 'green', company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue', company_id = 1"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Travel', category_type = 'Expense', category_color = 'red', company_id = 1"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Advertising', category_type = 'Expense', category_color = 'green', company_id = 1"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Service', category_type = 'Income', category_color = 'blue', company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Service', category_type = 'Income', category_color = 'blue', company_id = 1"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Friend', category_type = 'Referral', category_color = 'blue', company_id = $company_id"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Search Engine', category_type = 'Referral', category_color = 'red', company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Friend', category_type = 'Referral', category_color = 'blue', company_id = 1"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Search Engine', category_type = 'Referral', category_color = 'red', company_id = 1"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Cash', category_type = 'Payment Method', category_color = 'blue', company_id = $company_id"); - mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Check', category_type = 'Payment Method', category_color = 'red', company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Cash', category_type = 'Payment Method', category_color = 'blue', company_id = 1"); + mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Check', category_type = 'Payment Method', category_color = 'red', company_id = 1"); - mysqli_query($mysqli,"INSERT INTO calendars SET calendar_name = 'Default', calendar_color = 'blue', company_id = $company_id"); + mysqli_query($mysqli,"INSERT INTO calendars SET calendar_name = 'Default', calendar_color = 'blue', company_id = 1"); $_SESSION['alert_message'] = "Company $name created!"; @@ -1194,7 +1183,7 @@ if (isset($_POST['add_telemetry'])) { @@ -1210,7 +1199,7 @@ if (isset($_POST['add_telemetry'])) {
- Database already configured. Any further changes should be made by editing the config.php file, + Database is already configured. Any further changes should be made by editing the config.php file, or deleting it and refreshing this page.
@@ -1259,7 +1248,9 @@ if (isset($_POST['add_telemetry'])) {

- + @@ -1463,7 +1454,9 @@ if (isset($_POST['add_telemetry'])) {
- + @@ -1501,7 +1494,9 @@ if (isset($_POST['add_telemetry'])) {
- + @@ -1530,7 +1525,9 @@ if (isset($_POST['add_telemetry'])) { ?>
diff --git a/side_nav.php b/side_nav.php index 191c9eb1..0473b8ad 100644 --- a/side_nav.php +++ b/side_nav.php @@ -6,45 +6,12 @@
@@ -101,7 +100,7 @@ " class="user-image img-circle"> - +
"> diff --git a/trip_add_modal.php b/trip_add_modal.php index 732ab2b4..d85c6a4a 100644 --- a/trip_add_modal.php +++ b/trip_add_modal.php @@ -73,7 +73,7 @@ - Client (Optional) - - Client (Optional) - - Client (Optional) -
-
+
"> diff --git a/uploads/clients/index.php b/uploads/clients/index.php index 8b137891..e69de29b 100644 --- a/uploads/clients/index.php +++ b/uploads/clients/index.php @@ -1 +0,0 @@ - diff --git a/user_add_modal.php b/user_add_modal.php index cc892182..6f3e806a 100644 --- a/user_add_modal.php +++ b/user_add_modal.php @@ -47,30 +47,6 @@ -
- -
-
- -
- -
-
-
diff --git a/user_companies_modal.php b/user_companies_modal.php deleted file mode 100644 index f4d34594..00000000 --- a/user_companies_modal.php +++ /dev/null @@ -1,64 +0,0 @@ - diff --git a/user_edit_modal.php b/user_edit_modal.php index 9a81e39c..f715182d 100644 --- a/user_edit_modal.php +++ b/user_edit_modal.php @@ -61,33 +61,6 @@
-
- -
-
- -
- -
-
-
diff --git a/user_invite_modal.php b/user_invite_modal.php index e843d872..4feb00ba 100644 --- a/user_invite_modal.php +++ b/user_invite_modal.php @@ -21,29 +21,6 @@
-
- -
-
- -
- -
-
-
diff --git a/user_profile.php b/user_profile.php index facae218..6271598b 100644 --- a/user_profile.php +++ b/user_profile.php @@ -3,11 +3,13 @@ require_once("inc_all.php"); $sql_recent_logins = mysqli_query($mysqli, "SELECT * FROM logs WHERE log_type = 'Login' OR log_type = 'Login 2FA' AND log_action = 'Success' AND log_user_id = $session_user_id - ORDER BY log_id DESC LIMIT 3"); + ORDER BY log_id DESC LIMIT 3" +); $sql_recent_logs = mysqli_query($mysqli, "SELECT * FROM logs WHERE log_user_id = $session_user_id AND log_type NOT LIKE 'Login' - ORDER BY log_id DESC LIMIT 5"); + ORDER BY log_id DESC LIMIT 5" +); ?> @@ -40,7 +42,7 @@ $sql_recent_logs = mysqli_query($mysqli, "SELECT * FROM logs
- +
diff --git a/users.php b/users.php index 5734b653..246d1187 100644 --- a/users.php +++ b/users.php @@ -47,7 +47,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
"> @@ -76,7 +76,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); } $user_avatar = htmlentities($row['user_avatar']); $user_token = htmlentities($row['user_token']); - $user_default_company = intval($row['user_default_company']); $user_role = $row['user_role']; if ($user_role == 3) { $user_role_display = "Administrator"; @@ -85,13 +84,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); } else { $user_role_display = "Accountant"; } - $user_company_access_sql = mysqli_query($mysqli, "SELECT company_id FROM user_companies WHERE user_id = $user_id"); - $user_company_access_array = array(); - while ($row = mysqli_fetch_array($user_company_access_sql)) { - $user_company_access_array[] = intval($row['company_id']); - } - $user_company_access = implode(',', $user_company_access_array); - $user_initials = htmlentities(initials($user_name)); $sql_last_login = mysqli_query( @@ -155,10 +147,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - - Company Access - - Archive @@ -170,7 +158,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
+
">