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 - Fix PDF Export by Period
- Add pppoe_password for Customer, this pppoe_password only admin can change - Add pppoe_password for Customer, this pppoe_password only admin can change
- Country Code Number Settings - Country Code Number Settings
- Customer Meta Table for Custom Fields - Customer Meta Table for Customers Attributess
- Fix Add and Edit Customer Form for admin - Fix Add and Edit Customer Form for admin
- add Notification Message Editor - add Notification Message Editor
- cron reminder - cron reminder

View File

@ -188,8 +188,8 @@ CREATE TABLE `tb_languages` (
`id` int(11) NOT NULL `id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
DROP TABLE IF EXISTS `tbl_customers_custom_fields`; DROP TABLE IF EXISTS `tbl_customers_fields`;
CREATE TABLE tbl_customers_custom_fields ( CREATE TABLE tbl_customers_fields (
id INT PRIMARY KEY AUTO_INCREMENT, id INT PRIMARY KEY AUTO_INCREMENT,
customer_id INT NOT NULL, customer_id INT NOT NULL,
field_name VARCHAR(255) NOT NULL, field_name VARCHAR(255) NOT NULL,

View File

@ -168,8 +168,8 @@ switch ($action) {
if ($customer) { if ($customer) {
// Fetch the custom field values from the tbl_customer_custom_fields table // Fetch the Customers Attributes values from the tbl_customer_custom_fields table
$customFields = ORM::for_table('tbl_customers_custom_fields') $customFields = ORM::for_table('tbl_customers_fields')
->where('customer_id', $customer['id']) ->where('customer_id', $customer['id'])
->find_many(); ->find_many();
@ -210,8 +210,8 @@ switch ($action) {
$id = $routes['2']; $id = $routes['2'];
run_hook('edit_customer'); #HOOK run_hook('edit_customer'); #HOOK
$d = ORM::for_table('tbl_customers')->find_one($id); $d = ORM::for_table('tbl_customers')->find_one($id);
// Fetch the custom field values from the tbl_customers_custom_fields table // Fetch the Customers Attributes values from the tbl_customers_fields table
$customFields = ORM::for_table('tbl_customers_custom_fields') $customFields = ORM::for_table('tbl_customers_fields')
->where('customer_id', $id) ->where('customer_id', $id)
->find_many(); ->find_many();
if ($d) { if ($d) {
@ -231,8 +231,8 @@ switch ($action) {
run_hook('delete_customer'); #HOOK run_hook('delete_customer'); #HOOK
$d = ORM::for_table('tbl_customers')->find_one($id); $d = ORM::for_table('tbl_customers')->find_one($id);
if ($d) { if ($d) {
// Delete the associated custom field records from tbl_customer_custom_fields table // Delete the associated Customers Attributes records from tbl_customer_custom_fields table
ORM::for_table('tbl_customers_custom_fields')->where('customer_id', $id)->delete_many(); 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(); $c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one();
if ($c) { if ($c) {
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']); $p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
@ -285,7 +285,7 @@ switch ($action) {
$address = _post('address'); $address = _post('address');
$phonenumber = _post('phonenumber'); $phonenumber = _post('phonenumber');
$service_type = _post('service_type'); $service_type = _post('service_type');
//post custom field //post Customers Attributes
$custom_field_names = (array) $_POST['custom_field_name']; $custom_field_names = (array) $_POST['custom_field_name'];
$custom_field_values = (array) $_POST['custom_field_value']; $custom_field_values = (array) $_POST['custom_field_value'];
@ -321,7 +321,7 @@ switch ($action) {
// Retrieve the customer ID of the newly created customer // Retrieve the customer ID of the newly created customer
$customerId = $d->id(); $customerId = $d->id();
// Save custom field details // Save Customers Attributes details
if (!empty($custom_field_names) && !empty($custom_field_values)) { if (!empty($custom_field_names) && !empty($custom_field_values)) {
$totalFields = min(count($custom_field_names), count($custom_field_values)); $totalFields = min(count($custom_field_names), count($custom_field_values));
for ($i = 0; $i < $totalFields; $i++) { for ($i = 0; $i < $totalFields; $i++) {
@ -329,7 +329,7 @@ switch ($action) {
$value = $custom_field_values[$i]; $value = $custom_field_values[$i];
if (!empty($name)) { 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->customer_id = $customerId;
$customField->field_name = $name; $customField->field_name = $name;
$customField->field_value = $value; $customField->field_value = $value;
@ -369,8 +369,8 @@ switch ($action) {
$id = _post('id'); $id = _post('id');
$d = ORM::for_table('tbl_customers')->find_one($id); $d = ORM::for_table('tbl_customers')->find_one($id);
//lets find user custom field using id //lets find user Customers Attributes using id
$customFields = ORM::for_table('tbl_customers_custom_fields') $customFields = ORM::for_table('tbl_customers_fields')
->where('customer_id', $id) ->where('customer_id', $id)
->find_many(); ->find_many();
@ -414,7 +414,7 @@ switch ($action) {
$d->save(); $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) { foreach ($customFields as $customField) {
$fieldName = $customField['field_name']; $fieldName = $customField['field_name'];
if (isset($_POST['custom_fields'][$fieldName])) { 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'])) { if (isset($_POST['custom_field_name']) && isset($_POST['custom_field_value'])) {
$newCustomFieldNames = $_POST['custom_field_name']; $newCustomFieldNames = $_POST['custom_field_name'];
$newCustomFieldValues = $_POST['custom_field_value']; $newCustomFieldValues = $_POST['custom_field_value'];
@ -437,8 +437,8 @@ switch ($action) {
$fieldName = $newCustomFieldNames[$i]; $fieldName = $newCustomFieldNames[$i];
$fieldValue = $newCustomFieldValues[$i]; $fieldValue = $newCustomFieldValues[$i];
// Insert the new custom field // Insert the new Customers Attributes
$newCustomField = ORM::for_table('tbl_customers_custom_fields')->create(); $newCustomField = ORM::for_table('tbl_customers_fields')->create();
$newCustomField->set('customer_id', $id); $newCustomField->set('customer_id', $id);
$newCustomField->set('field_name', $fieldName); $newCustomField->set('field_name', $fieldName);
$newCustomField->set('field_value', $fieldValue); $newCustomField->set('field_value', $fieldValue);
@ -447,12 +447,12 @@ switch ($action) {
} }
} }
// Delete custom fields // Delete Customers Attributess
if (isset($_POST['delete_custom_fields'])) { if (isset($_POST['delete_custom_fields'])) {
$fieldsToDelete = $_POST['delete_custom_fields']; $fieldsToDelete = $_POST['delete_custom_fields'];
foreach ($fieldsToDelete as $fieldName) { foreach ($fieldsToDelete as $fieldName) {
// Delete the custom field with the given field name // Delete the Customers Attributes with the given field name
ORM::for_table('tbl_customers_custom_fields') ORM::for_table('tbl_customers_fields')
->where('field_name', $fieldName) ->where('field_name', $fieldName)
->delete_many(); ->delete_many();
} }

View File

@ -413,5 +413,6 @@
"Code": "Code", "Code": "Code",
"Generated By": "Generated By", "Generated By": "Generated By",
"Report Viewer": "Report Viewer", "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": [ "2024.2.16": [
"ALTER TABLE `tbl_customers` ADD `created_by` INT NOT NULL DEFAULT '0' AFTER `auto_renewal`;" "ALTER TABLE `tbl_customers` ADD `created_by` INT NOT NULL DEFAULT '0' AFTER `auto_renewal`;"
], ],
"2024.2.17": [ "2024.2.19": [
"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));" "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" <input type="password" class="form-control" id="pppoe_password" name="pppoe_password"
value="{$d['pppoe_password']}" onmouseleave="this.type = 'password'" value="{$d['pppoe_password']}" onmouseleave="this.type = 'password'"
onmouseenter="this.type = 'text'"> onmouseenter="this.type = 'text'">
<span class="help-block">{Lang::T('User Cannot change this, only admin. if it Empty it will <span class="help-block">
use user password')}</span> {Lang::T('User Cannot change this, only admin. if it Empty it will use user password')}
</span>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -83,20 +84,21 @@
</select> </select>
</div> </div>
</div> </div>
<!-- Custom fields add start --> <!-- Customers Attributes add start -->
<div class="form-group"> <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"> <div id="custom-fields-container" class="col-md-6">
<button class="btn btn-success btn-sm waves-effect waves-light" type="button" <button class="btn btn-success btn-sm waves-effect waves-light" type="button"
id="add-custom-field">+</button> id="add-custom-field">+</button>
</div> </div>
</div> </div>
<!-- Custom fields add end --> <!-- Customers Attributes add end -->
<div class="form-group"> <div class="form-group">
<div class="col-lg-offset-2 col-lg-10"> <div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-primary waves-effect waves-light" type="submit">{Lang::T('Save <button class="btn btn-primary waves-effect waves-light" type="submit">
Changes')}</button> {Lang::T('Save Changes')}
</button>
Or <a href="{$_url}customers/list">{Lang::T('Cancel')}</a> Or <a href="{$_url}customers/list">{Lang::T('Cancel')}</a>
</div> </div>
</div> </div>

View File

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

View File

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