From f550af257ad0a1078dc8234c3eb0d936b52303e2 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Mon, 19 Feb 2024 09:29:11 +0700 Subject: [PATCH] fix customer custom field --- CHANGELOG.md | 2 +- install/phpnuxbill.sql | 4 ++-- system/controllers/customers.php | 36 ++++++++++++++++---------------- system/lan/english.json | 3 ++- system/updates.json | 4 ++-- ui/ui/customers-add.tpl | 16 +++++++------- ui/ui/customers-edit.tpl | 20 ++++++++++-------- ui/ui/customers-view.tpl | 4 ++-- 8 files changed, 47 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ea3c44..a5460242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -230,7 +230,7 @@ Customer can be move to expired pool after plan expired by cron - Fix PDF Export by Period - Add pppoe_password for Customer, this pppoe_password only admin can change - Country Code Number Settings -- Customer Meta Table for Custom Fields +- Customer Meta Table for Customers Attributess - Fix Add and Edit Customer Form for admin - add Notification Message Editor - cron reminder diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index e31312c6..826d30db 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -188,8 +188,8 @@ CREATE TABLE `tb_languages` ( `id` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -DROP TABLE IF EXISTS `tbl_customers_custom_fields`; -CREATE TABLE tbl_customers_custom_fields ( +DROP TABLE IF EXISTS `tbl_customers_fields`; +CREATE TABLE tbl_customers_fields ( id INT PRIMARY KEY AUTO_INCREMENT, customer_id INT NOT NULL, field_name VARCHAR(255) NOT NULL, diff --git a/system/controllers/customers.php b/system/controllers/customers.php index e6663be7..f33157b0 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -168,8 +168,8 @@ switch ($action) { if ($customer) { - // Fetch the custom field values from the tbl_customer_custom_fields table - $customFields = ORM::for_table('tbl_customers_custom_fields') + // Fetch the Customers Attributes values from the tbl_customer_custom_fields table + $customFields = ORM::for_table('tbl_customers_fields') ->where('customer_id', $customer['id']) ->find_many(); @@ -210,8 +210,8 @@ switch ($action) { $id = $routes['2']; run_hook('edit_customer'); #HOOK $d = ORM::for_table('tbl_customers')->find_one($id); - // Fetch the custom field values from the tbl_customers_custom_fields table - $customFields = ORM::for_table('tbl_customers_custom_fields') + // Fetch the Customers Attributes values from the tbl_customers_fields table + $customFields = ORM::for_table('tbl_customers_fields') ->where('customer_id', $id) ->find_many(); if ($d) { @@ -231,8 +231,8 @@ switch ($action) { run_hook('delete_customer'); #HOOK $d = ORM::for_table('tbl_customers')->find_one($id); if ($d) { - // Delete the associated custom field records from tbl_customer_custom_fields table - ORM::for_table('tbl_customers_custom_fields')->where('customer_id', $id)->delete_many(); + // Delete the associated Customers Attributes records from tbl_customer_custom_fields table + ORM::for_table('tbl_customers_fields')->where('customer_id', $id)->delete_many(); $c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one(); if ($c) { $p = ORM::for_table('tbl_plans')->find_one($c['plan_id']); @@ -285,7 +285,7 @@ switch ($action) { $address = _post('address'); $phonenumber = _post('phonenumber'); $service_type = _post('service_type'); - //post custom field + //post Customers Attributes $custom_field_names = (array) $_POST['custom_field_name']; $custom_field_values = (array) $_POST['custom_field_value']; @@ -321,7 +321,7 @@ switch ($action) { // Retrieve the customer ID of the newly created customer $customerId = $d->id(); - // Save custom field details + // Save Customers Attributes details if (!empty($custom_field_names) && !empty($custom_field_values)) { $totalFields = min(count($custom_field_names), count($custom_field_values)); for ($i = 0; $i < $totalFields; $i++) { @@ -329,7 +329,7 @@ switch ($action) { $value = $custom_field_values[$i]; if (!empty($name)) { - $customField = ORM::for_table('tbl_customers_custom_fields')->create(); + $customField = ORM::for_table('tbl_customers_fields')->create(); $customField->customer_id = $customerId; $customField->field_name = $name; $customField->field_value = $value; @@ -369,8 +369,8 @@ switch ($action) { $id = _post('id'); $d = ORM::for_table('tbl_customers')->find_one($id); - //lets find user custom field using id - $customFields = ORM::for_table('tbl_customers_custom_fields') + //lets find user Customers Attributes using id + $customFields = ORM::for_table('tbl_customers_fields') ->where('customer_id', $id) ->find_many(); @@ -414,7 +414,7 @@ switch ($action) { $d->save(); - // Update custom field values in tbl_customers_custom_fields table + // Update Customers Attributes values in tbl_customers_fields table foreach ($customFields as $customField) { $fieldName = $customField['field_name']; if (isset($_POST['custom_fields'][$fieldName])) { @@ -424,7 +424,7 @@ switch ($action) { } } - // Add new custom fields + // Add new Customers Attributess if (isset($_POST['custom_field_name']) && isset($_POST['custom_field_value'])) { $newCustomFieldNames = $_POST['custom_field_name']; $newCustomFieldValues = $_POST['custom_field_value']; @@ -437,8 +437,8 @@ switch ($action) { $fieldName = $newCustomFieldNames[$i]; $fieldValue = $newCustomFieldValues[$i]; - // Insert the new custom field - $newCustomField = ORM::for_table('tbl_customers_custom_fields')->create(); + // Insert the new Customers Attributes + $newCustomField = ORM::for_table('tbl_customers_fields')->create(); $newCustomField->set('customer_id', $id); $newCustomField->set('field_name', $fieldName); $newCustomField->set('field_value', $fieldValue); @@ -447,12 +447,12 @@ switch ($action) { } } - // Delete custom fields + // Delete Customers Attributess if (isset($_POST['delete_custom_fields'])) { $fieldsToDelete = $_POST['delete_custom_fields']; foreach ($fieldsToDelete as $fieldName) { - // Delete the custom field with the given field name - ORM::for_table('tbl_customers_custom_fields') + // Delete the Customers Attributes with the given field name + ORM::for_table('tbl_customers_fields') ->where('field_name', $fieldName) ->delete_many(); } diff --git a/system/lan/english.json b/system/lan/english.json index 483626f8..d4e9b394 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -413,5 +413,6 @@ "Code": "Code", "Generated By": "Generated By", "Report Viewer": "Report Viewer", - "Super Administrator": "Super Administrator" + "Super Administrator": "Super Administrator", + "Customers Attributes": "Customers Attributes" } \ No newline at end of file diff --git a/system/updates.json b/system/updates.json index 2ae9a9e3..9e3478ce 100644 --- a/system/updates.json +++ b/system/updates.json @@ -56,7 +56,7 @@ "2024.2.16": [ "ALTER TABLE `tbl_customers` ADD `created_by` INT NOT NULL DEFAULT '0' AFTER `auto_renewal`;" ], - "2024.2.17": [ - "CREATE TABLE `tbl_customers_custom_fields` (`id` INT PRIMARY KEY AUTO_INCREMENT, `customer_id` INT NOT NULL, `field_name` VARCHAR(255) NOT NULL, `field_value` VARCHAR(255) NOT NULL, FOREIGN KEY (customer_id) REFERENCES tbl_customers(id));" + "2024.2.19": [ + "CREATE TABLE `tbl_customers_fields` (`id` INT PRIMARY KEY AUTO_INCREMENT, `customer_id` INT NOT NULL, `field_name` VARCHAR(255) NOT NULL, `field_value` VARCHAR(255) NOT NULL, FOREIGN KEY (customer_id) REFERENCES tbl_customers(id));" ] } \ No newline at end of file diff --git a/ui/ui/customers-add.tpl b/ui/ui/customers-add.tpl index 03963c70..26080561 100644 --- a/ui/ui/customers-add.tpl +++ b/ui/ui/customers-add.tpl @@ -62,8 +62,9 @@ - {Lang::T('User Cannot change this, only admin. if it Empty it will - use user password')} + + {Lang::T('User Cannot change this, only admin. if it Empty it will use user password')} +
@@ -83,20 +84,21 @@
- +
- +
- +
- + Or {Lang::T('Cancel')}
diff --git a/ui/ui/customers-edit.tpl b/ui/ui/customers-edit.tpl index 91231e96..3b55a3d8 100644 --- a/ui/ui/customers-edit.tpl +++ b/ui/ui/customers-edit.tpl @@ -67,8 +67,9 @@ - {Lang::T('User Cannot change this, only admin. if it Empty it will - use user password')} + + {Lang::T('User Cannot change this, only admin. if it Empty it will use user password')} +
@@ -88,7 +89,7 @@
- + {if $customFields} {foreach $customFields as $customField}
@@ -102,20 +103,21 @@
{/foreach} {/if} - - + +
- +
- +
- + Or {Lang::T('Cancel')}
diff --git a/ui/ui/customers-view.tpl b/ui/ui/customers-view.tpl index 408ceb33..9dfa75f5 100644 --- a/ui/ui/customers-view.tpl +++ b/ui/ui/customers-view.tpl @@ -37,7 +37,7 @@ onclick="this.select()"> {/if} - + {if $customFields} {foreach $customFields as $customField}
  • @@ -45,7 +45,7 @@
  • {/foreach} {/if} - +
  • {Lang::T('Service Type')} {Lang::T($d['service_type'])}