From 4fa186179d67dac41bc1955bc813681c93de2f6a Mon Sep 17 00:00:00 2001 From: o-psi Date: Mon, 16 Oct 2023 19:30:31 -0500 Subject: [PATCH 01/11] DB Updates to support leads functionality --- database_updates.php | 33 ++++++++++++++++++++------------- database_version.php | 2 +- db.sql | 1 + 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/database_updates.php b/database_updates.php index 0dd7f23f..e8dd31ce 100644 --- a/database_updates.php +++ b/database_updates.php @@ -466,7 +466,6 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.3.1'"); } - if (CURRENT_DATABASE_VERSION == '0.3.1') { // Assets @@ -1104,8 +1103,6 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.5.9'"); } - - if (CURRENT_DATABASE_VERSION == '0.5.9') { // Copy primary_location and primary_contact to their new vars in their own respecting tables @@ -1374,7 +1371,6 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.6'"); } - // Update DB to 0.8.7 if (CURRENT_DATABASE_VERSION == '0.8.6') { // Insert queries here required to update to DB version 0.8.7 mysqli_query($mysqli, "ALTER TABLE `accounts` ADD `account_type` int(6) DEFAULT NULL AFTER `account_notes`"); @@ -1384,7 +1380,6 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.7'"); } - // Update DB to 0.8.8 if (CURRENT_DATABASE_VERSION == '0.8.7') { //Create Main Account Types mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Asset', account_type_id= '10', account_type_description = 'Assets are economic resources which are expected to benefit the business in the future.'"); @@ -1401,10 +1396,7 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.8'"); } - // Be sure to change database_version.php to reflect the version you are updating to here - // Please add this same comment block to the bottom of this file, and update the version number. - // Uncomment Below Lines, to add additional database updates - // + if (CURRENT_DATABASE_VERSION == '0.8.8') { // Insert queries here required to update to DB version 0.8.9 mysqli_query($mysqli, "ALTER TABLE `invoice_items` ADD `item_order` INT(11) NOT NULL DEFAULT 0 AFTER `item_total`"); @@ -1430,10 +1422,7 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { } // - // Be sure to change database_version.php to reflect the version you are updating to here - // Please add this same comment block to the bottom of this file, and update the version number. - // Uncomment Below Lines, to add additional database updates - // + if (CURRENT_DATABASE_VERSION == '0.8.9') { // Insert queries here required to update to DB version 0.9.0 // Update existing quotes and recurrings so that item_order is set to item_id @@ -1473,6 +1462,24 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { } // + // Be sure to change database_version.php to reflect the version you are updating to here + // Please add this same comment block to the bottom of this file, and update the version number. + // Uncomment Below Lines, to add additional database updates + // + if (CURRENT_DATABASE_VERSION == '0.9.0') { + //add leads column to clients table + mysqli_query($mysqli, "ALTER TABLE `clients` ADD `client_lead` TINYINT(1) NOT NULL DEFAULT 0 AFTER `client_id`"); + + // Then, update the database to the next sequential version + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.9.1'"); + } + + //if (CURRENT_DATABASE_VERSION == '0.9.1') { + // Insert queries here required to update to DB version 0.9.0 + + // Then, update the database to the next sequential version + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.9.2'"); + //} } else { // Up-to-date } diff --git a/database_version.php b/database_version.php index 5bea9d6e..6815157f 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.9.0"); +DEFINE("LATEST_DATABASE_VERSION", "0.9.1"); diff --git a/db.sql b/db.sql index b1e9bf6f..dc782fc1 100644 --- a/db.sql +++ b/db.sql @@ -275,6 +275,7 @@ DROP TABLE IF EXISTS `clients`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clients` ( `client_id` int(11) NOT NULL AUTO_INCREMENT, + `client_lead` tinyint(1) NOT NULL DEFAULT 0, `client_name` varchar(200) NOT NULL, `client_type` varchar(200) DEFAULT NULL, `client_website` varchar(200) DEFAULT NULL, From 34db62e8eec7a50ed62a0256edd29e1aa36c8294 Mon Sep 17 00:00:00 2001 From: o-psi Date: Mon, 16 Oct 2023 22:43:48 -0500 Subject: [PATCH 02/11] Update add modal to support leads and clients --- client_add_modal.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client_add_modal.php b/client_add_modal.php index 473949c7..324d8f7a 100644 --- a/client_add_modal.php +++ b/client_add_modal.php @@ -2,12 +2,15 @@ + +
+
@@ -93,7 +128,9 @@
- +
@@ -105,8 +142,12 @@ @@ -120,8 +161,12 @@ @@ -133,12 +178,17 @@
- + - + @@ -147,7 +197,8 @@
- +
@@ -175,10 +226,16 @@ ?>
  • - " name="tags[]" value="" > -
    @@ -188,7 +245,7 @@ - +
    @@ -203,10 +260,12 @@
    - + \ No newline at end of file From efba7ffc8b772b657b9c696d7b0395ded706d683 Mon Sep 17 00:00:00 2001 From: o-psi Date: Mon, 16 Oct 2023 22:49:45 -0500 Subject: [PATCH 04/11] make new leads screen to view leads. --- client_leads.php | 301 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 client_leads.php diff --git a/client_leads.php b/client_leads.php new file mode 100644 index 00000000..4817a7d1 --- /dev/null +++ b/client_leads.php @@ -0,0 +1,301 @@ + + +
    +
    +

    Lead Management

    +
    + + + +
    +
    + +
    +
    +
    +
    +
    + +
    + + +
    +
    +
    +
    +
    + +
    +
    +
    +
    " id="advancedFilter"> +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    + + "> + + + + + + + + + $location_city $location_state $location_zip"; + } + $contact_id = intval($row['contact_id']); + $contact_name = nullable_htmlentities($row['contact_name']); + $contact_title = nullable_htmlentities($row['contact_title']); + $contact_phone = formatPhoneNumber($row['contact_phone']); + $contact_extension = nullable_htmlentities($row['contact_extension']); + $contact_mobile = formatPhoneNumber($row['contact_mobile']); + $contact_email = nullable_htmlentities($row['contact_email']); + $client_website = nullable_htmlentities($row['client_website']); + $client_rate = floatval($row['client_rate']); + $client_currency_code = nullable_htmlentities($row['client_currency_code']); + $client_net_terms = intval($row['client_net_terms']); + $client_tax_id_number = nullable_htmlentities($row['client_tax_id_number']); + $client_referral = nullable_htmlentities($row['client_referral']); + $client_notes = nullable_htmlentities($row['client_notes']); + $client_created_at = date('Y-m-d', strtotime($row['client_created_at'])); + $client_updated_at = nullable_htmlentities($row['client_updated_at']); + $client_archive_at = nullable_htmlentities($row['client_archived_at']); + $client_is_lead = intval($row['client_lead']); + + // Client Tags + + $client_tag_name_display_array = array(); + $client_tag_id_array = array(); + $sql_client_tags = mysqli_query($mysqli, "SELECT * FROM client_tags LEFT JOIN tags ON client_tags.client_tag_tag_id = tags.tag_id WHERE client_tags.client_tag_client_id = $client_id ORDER BY tag_name ASC"); + while ($row = mysqli_fetch_array($sql_client_tags)) { + + $client_tag_id = intval($row['tag_id']); + $client_tag_name = nullable_htmlentities($row['tag_name']); + $client_tag_color = nullable_htmlentities($row['tag_color']); + if (empty($client_tag_color)) { + $client_tag_color = "dark"; + } + $client_tag_icon = nullable_htmlentities($row['tag_icon']); + if (empty($client_tag_icon)) { + $client_tag_icon = "tag"; + } + + $client_tag_id_array[] = $client_tag_id; + $client_tag_name_display_array[] = "$client_tag_name "; + } + $client_tags_display = implode('', $client_tag_name_display_array); + + //Add up all the payments for the invoice and get the total amount paid to the invoice + $sql_invoice_amounts = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE invoice_client_id = $client_id AND invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' "); + $row = mysqli_fetch_array($sql_invoice_amounts); + + $invoice_amounts = floatval($row['invoice_amounts']); + + $sql_amount_paid = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS amount_paid FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_client_id = $client_id"); + $row = mysqli_fetch_array($sql_amount_paid); + + $amount_paid = floatval($row['amount_paid']); + + $balance = $invoice_amounts - $amount_paid; + //set Text color on balance + if ($balance > 0) { + $balance_text_color = "text-danger font-weight-bold"; + } else { + $balance_text_color = ""; + } + + //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"); + $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"); + $row = mysqli_fetch_array($sql_recurring_yearly_total); + + $recurring_yearly_total = floatval($row['recurring_yearly_total']) / 12; + + $recurring_monthly = $recurring_monthly_total + $recurring_yearly_total; + + ?> + + + + + + + + + + + + + + +
    NamePrimary address Primary contact Action
    + + + +
    + +
    + + +
    + +
    + +
    + Created: +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    +
    + +
    +
    + + Date: Mon, 16 Oct 2023 22:49:59 -0500 Subject: [PATCH 05/11] adjust clients to filter out leads --- clients.php | 1 + 1 file changed, 1 insertion(+) diff --git a/clients.php b/clients.php index 9d7546e3..30743879 100644 --- a/clients.php +++ b/clients.php @@ -25,6 +25,7 @@ $sql = mysqli_query( OR tags.tag_name LIKE '%$q%' OR clients.client_tax_id_number LIKE '%$q%') AND clients.client_archived_at IS NULL AND DATE(clients.client_created_at) BETWEEN '$dtf' AND '$dtt' + AND clients.client_lead = 0 GROUP BY clients.client_id ORDER BY $sort $order LIMIT $record_from, $record_to From 44e5b6c2bd9fdfb75ef6cf1923e0f59da9468949 Mon Sep 17 00:00:00 2001 From: o-psi Date: Mon, 16 Oct 2023 22:50:09 -0500 Subject: [PATCH 06/11] add leads to sales --- side_nav.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/side_nav.php b/side_nav.php index 6bf3d75b..37149df7 100644 --- a/side_nav.php +++ b/side_nav.php @@ -68,6 +68,12 @@ if ($config_module_enable_accounting == 1) { ?>
  • +