Various minor service and service category fixes

This commit is contained in:
Alex Tselegidis 2023-11-03 18:24:49 +01:00
parent 577d161166
commit 38f872d857
4 changed files with 23 additions and 77 deletions

View file

@ -134,39 +134,25 @@ class Service_categories_model extends EA_Model {
* Remove an existing service-category from the database.
*
* @param int $service_category_id Service-Category ID.
* @param bool $force_delete Override soft delete.
*
* @throws RuntimeException
*/
public function delete(int $service_category_id, bool $force_delete = FALSE)
{
if ($force_delete)
public function delete(int $service_category_id): void
{
$this->db->delete('service_categories', ['id' => $service_category_id]);
}
else
{
$this->db->update('service_categories', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $service_category_id]);
}
}
/**
* Get a specific service-category from the database.
*
* @param int $service_category_id The ID of the record to be returned.
* @param bool $with_trashed
*
* @return array Returns an array with the service-category data.
*
* @throws InvalidArgumentException
*/
public function find(int $service_category_id, bool $with_trashed = FALSE): array
public function find(int $service_category_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$service_category = $this->db->get_where('service_categories', ['id' => $service_category_id])->row_array();
if ( ! $service_category)
@ -229,11 +215,10 @@ class Service_categories_model extends EA_Model {
* @param int|null $limit Record limit.
* @param int|null $offset Record offset.
* @param string|null $order_by Order by.
* @param bool $with_trashed
*
* @return array Returns an array of service categories.
*/
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -245,11 +230,6 @@ class Service_categories_model extends EA_Model {
$this->db->order_by($order_by);
}
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$service_categories = $this->db->get('service_categories', $limit, $offset)->result_array();
foreach ($service_categories as &$service_category)
@ -277,17 +257,11 @@ class Service_categories_model extends EA_Model {
* @param int|null $limit Record limit.
* @param int|null $offset Record offset.
* @param string|null $order_by Order by.
* @param bool $with_trashed
*
* @return array Returns an array of service categories.
*/
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$service_categories = $this
->db
->select()

View file

@ -190,39 +190,25 @@ class Services_model extends EA_Model {
* Remove an existing service from the database.
*
* @param int $service_id Service ID.
* @param bool $force_delete Override soft delete.
*
* @throws RuntimeException
*/
public function delete(int $service_id, bool $force_delete = FALSE)
{
if ($force_delete)
public function delete(int $service_id): void
{
$this->db->delete('services', ['id' => $service_id]);
}
else
{
$this->db->update('services', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $service_id]);
}
}
/**
* Get a specific service from the database.
*
* @param int $service_id The ID of the record to be returned.
* @param bool $with_trashed
*
* @return array Returns an array with the service data.
*
* @throws InvalidArgumentException
*/
public function find(int $service_id, bool $with_trashed = FALSE): array
public function find(int $service_id): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$service = $this->db->get_where('services', ['id' => $service_id])->row_array();
if ( ! $service)
@ -285,11 +271,10 @@ class Services_model extends EA_Model {
* @param int|null $limit Record limit.
* @param int|null $offset Record offset.
* @param string|null $order_by Order by.
* @param bool $with_trashed
*
* @return array Returns an array of services.
*/
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
@ -301,11 +286,6 @@ class Services_model extends EA_Model {
$this->db->order_by($order_by);
}
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$services = $this->db->get('services', $limit, $offset)->result_array();
foreach ($services as &$service)
@ -337,7 +317,6 @@ class Services_model extends EA_Model {
->from('services')
->join('services_providers', 'services_providers.id_services = services.id', 'inner')
->join('service_categories', 'service_categories.id = services.id_service_categories', 'left')
->where('services.delete_datetime IS NULL')
->order_by('name ASC')
->get()
->result_array();
@ -367,17 +346,11 @@ class Services_model extends EA_Model {
* @param int|null $limit Record limit.
* @param int|null $offset Record offset.
* @param string|null $order_by Order by.
* @param bool $with_trashed
*
* @return array Returns an array of services.
*/
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ( ! $with_trashed)
{
$this->db->where('delete_datetime IS NULL');
}
$services = $this
->db
->select()

View file

@ -73,7 +73,6 @@
<div class="mb-3">
<label class="form-label" for="description">
<?= lang('description') ?>
</label>
<textarea id="description" rows="4" class="form-control" disabled></textarea>
</div>

View file

@ -14,9 +14,9 @@
*
* This module implements the functionality of the service-categories page.
*/
App.Pages.Categories = (function () {
App.Pages.ServiceCategories = (function () {
const $serviceCategories = $('#service-categories');
const $filterCategories = $('#filter-service-categories');
const $filterServiceCategories = $('#filter-service-categories');
const $id = $('#id');
const $name = $('#name');
const $description = $('#description');
@ -28,7 +28,7 @@ App.Pages.Categories = (function () {
*/
function addEventListeners() {
/**
* Event: Filter Categories Form "Submit"
* Event: Filter Service-Categories Form "Submit"
*
* @param {jQuery.Event} event
*/
@ -72,8 +72,8 @@ App.Pages.Categories = (function () {
$serviceCategories.find('.save-cancel-group').show();
$serviceCategories.find('.record-details').find('input, select, textarea').prop('disabled', false);
$serviceCategories.find('.record-details .form-label span').prop('hidden', false);
$filterCategories.find('button').prop('disabled', true);
$filterCategories.find('.results').css('color', '#AAA');
$filterServiceCategories.find('button').prop('disabled', true);
$filterServiceCategories.find('.results').css('color', '#AAA');
});
/**
@ -84,8 +84,8 @@ App.Pages.Categories = (function () {
$serviceCategories.find('.save-cancel-group').show();
$serviceCategories.find('.record-details').find('input, select, textarea').prop('disabled', false);
$serviceCategories.find('.record-details .form-label span').prop('hidden', false);
$filterCategories.find('button').prop('disabled', true);
$filterCategories.find('.results').css('color', '#AAA');
$filterServiceCategories.find('button').prop('disabled', true);
$filterServiceCategories.find('.results').css('color', '#AAA');
});
/**
@ -196,7 +196,7 @@ App.Pages.Categories = (function () {
App.Http.ServiceCategories.save(serviceCategory).then((response) => {
App.Layouts.Backend.displayNotification(lang('service_category_saved'));
resetForm();
$filterCategories.find('.key').val('');
$filterServiceCategories.find('.key').val('');
filter('', response.id, true);
});
}
@ -259,9 +259,9 @@ App.Pages.Categories = (function () {
* Bring the service-category form back to its initial state.
*/
function resetForm() {
$filterCategories.find('.selected').removeClass('selected');
$filterCategories.find('button').prop('disabled', false);
$filterCategories.find('.results').css('color', '');
$filterServiceCategories.find('.selected').removeClass('selected');
$filterServiceCategories.find('button').prop('disabled', false);
$filterServiceCategories.find('.results').css('color', '');
$serviceCategories.find('.add-edit-delete-group').show();
$serviceCategories.find('.save-cancel-group').hide();
@ -302,9 +302,9 @@ App.Pages.Categories = (function () {
* @param {Boolean} show Optional (false), if true then the method will display the record on the form.
*/
function select(id, show = false) {
$filterCategories.find('.selected').removeClass('selected');
$filterServiceCategories.find('.selected').removeClass('selected');
$filterCategories.find('.service-category-row[data-id="' + id + '"]').addClass('selected');
$filterServiceCategories.find('.service-category-row[data-id="' + id + '"]').addClass('selected');
if (show) {
const serviceCategory = filterResults.find((serviceCategory) => Number(serviceCategory.id) === Number(id));