fix customer custom field

This commit is contained in:
Ibnu Maksum 2024-02-19 09:29:11 +07:00
parent 2c16bb289e
commit f550af257a
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
8 changed files with 47 additions and 42 deletions

View File

@ -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

View File

@ -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,

View File

@ -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();
}

View File

@ -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"
}

View File

@ -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));"
]
}

View File

@ -62,8 +62,9 @@
<input type="password" class="form-control" id="pppoe_password" name="pppoe_password"
value="{$d['pppoe_password']}" onmouseleave="this.type = 'password'"
onmouseenter="this.type = 'text'">
<span class="help-block">{Lang::T('User Cannot change this, only admin. if it Empty it will
use user password')}</span>
<span class="help-block">
{Lang::T('User Cannot change this, only admin. if it Empty it will use user password')}
</span>
</div>
</div>
<div class="form-group">
@ -83,20 +84,21 @@
</select>
</div>
</div>
<!-- Custom fields add start -->
<!-- Customers Attributes add start -->
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Custom Field')}</label>
<label class="col-md-2 control-label">{Lang::T('Customers Attributes')}</label>
<div id="custom-fields-container" class="col-md-6">
<button class="btn btn-success btn-sm waves-effect waves-light" type="button"
id="add-custom-field">+</button>
</div>
</div>
<!-- Custom fields add end -->
<!-- Customers Attributes add end -->
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-primary waves-effect waves-light" type="submit">{Lang::T('Save
Changes')}</button>
<button class="btn btn-primary waves-effect waves-light" type="submit">
{Lang::T('Save Changes')}
</button>
Or <a href="{$_url}customers/list">{Lang::T('Cancel')}</a>
</div>
</div>

View File

@ -67,8 +67,9 @@
<input type="password" autocomplete="off" class="form-control" id="pppoe_password"
name="pppoe_password" value="{$d['pppoe_password']}"
onmouseleave="this.type = 'password'" onmouseenter="this.type = 'text'">
<span class="help-block">{Lang::T('User Cannot change this, only admin. if it Empty it will
use user password')}</span>
<span class="help-block">
{Lang::T('User Cannot change this, only admin. if it Empty it will use user password')}
</span>
</div>
</div>
<div class="form-group">
@ -88,7 +89,7 @@
</select>
</div>
</div>
<!--custom field edit start -->
<!--Customers Attributes edit start -->
{if $customFields}
{foreach $customFields as $customField}
<div class="form-group">
@ -102,20 +103,21 @@
</div>
{/foreach}
{/if}
<!--custom field edit end -->
<!--custom field add start -->
<!--Customers Attributes edit end -->
<!--Customers Attributes add start -->
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Custom Field')}</label>
<label class="col-md-2 control-label">{Lang::T('Customers Attributes')}</label>
<div id="custom-fields-container" class="col-md-6">
<button class="btn btn-success btn-sm waves-effect waves-light" type="button"
id="add-custom-field">+</button>
</div>
</div>
<!--custom field add end -->
<!--Customers Attributes add end -->
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-primary waves-effect waves-light" type="submit">{Lang::T('Save
Changes')}</button>
<button class="btn btn-primary waves-effect waves-light" type="submit">
{Lang::T('Save Changes')}
</button>
Or <a href="{$_url}customers/list">{Lang::T('Cancel')}</a>
</div>
</div>

View File

@ -37,7 +37,7 @@
onclick="this.select()">
</li>
{/if}
<!--custom field view start -->
<!--Customers Attributes view start -->
{if $customFields}
{foreach $customFields as $customField}
<li class="list-group-item">
@ -45,7 +45,7 @@
</li>
{/foreach}
{/if}
<!--custom field view end -->
<!--Customers Attributes view end -->
<li class="list-group-item">
<b>{Lang::T('Service Type')}</b> <span class="pull-right">{Lang::T($d['service_type'])}</span>
</li>