This commit appears to fix customer deletes and updates.

This commit is contained in:
Steve Ireland
2023-03-24 23:13:14 -04:00
parent a207539f4f
commit 9ee7b8f6d4
7 changed files with 22 additions and 20 deletions

View File

@@ -93,6 +93,10 @@ define('EVENT_PRIORITY_NORMAL', 100);
*/
define('EVENT_PRIORITY_HIGH', 10);
/**
* Global Constants.
*/
const NEW_ENTRY = -1;
/**
* Attribute Related Constants.

View File

@@ -64,7 +64,7 @@ class Customers extends Persons
/**
* Gets one row for a customer manage table. This is called using AJAX to update one row.
*/
public function get_row(int $row_id): void
public function getAjaxRow(int $row_id): void
{
$person = $this->customer->get_info($row_id);
@@ -146,10 +146,10 @@ class Customers extends Persons
/**
* Loads the customer edit form
*/
public function getView(int $customer_id = -1): void //TODO: replace -1 with a constant
public function getView(int $customer_id = NEW_ENTRY): void
{
// Set default values
if($customer_id == null) $customer_id = -1;
if($customer_id == null) $customer_id = NEW_ENTRY;
$info = $this->customer->get_info($customer_id);
foreach(get_object_vars($info) as $property => $value)
@@ -268,7 +268,7 @@ class Customers extends Persons
/**
* Inserts/updates a customer
*/
public function postSave(int $customer_id = -1): void //TODO: Replace -1 with a constant
public function postSave(int $customer_id = NEW_ENTRY): void
{
$first_name = $this->request->getPost('first_name', FILTER_SANITIZE_STRING);
$last_name = $this->request->getPost('last_name', FILTER_SANITIZE_STRING);
@@ -323,7 +323,7 @@ class Customers extends Persons
);
// New customer
if($customer_id == -1)
if($customer_id == NEW_ENTRY)
{
echo json_encode ([
'success' => TRUE,
@@ -345,7 +345,7 @@ class Customers extends Persons
echo json_encode ([
'success' => FALSE,
'message' => lang('Customers.error_adding_updating') . ' ' . $first_name . ' ' . $last_name,
'id' => -1
'id' => NEW_ENTRY
]);
}
}
@@ -373,7 +373,7 @@ class Customers extends Persons
/**
* This deletes customers from the customers table
*/
public function delete(): void
public function postDelete(): void
{
$customers_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING);
$customers_info = $this->customer->get_multiple_info($customers_to_delete);

View File

@@ -85,5 +85,5 @@ class Secure_Controller extends BaseController
public function suggest_search() { return FALSE; }
public function getView(int $data_item_id = -1) { return FALSE; }
public function postSave(int $data_item_id = -1) { return FALSE; }
public function delete() { return FALSE; }
public function postDelete() { return FALSE; }
}

View File

@@ -293,7 +293,7 @@ function get_customer_data_row(object $person, object $stats): array
'messages' => empty($person->phone_number)
? ''
: anchor(
"Messages/view/$person->person_id", //TODO: String interpolation
"Messages/view/$person->person_id",
'<span class="glyphicon glyphicon-phone"></span>',
[
'class' => 'modal-dlg',
@@ -307,7 +307,7 @@ function get_customer_data_row(object $person, object $stats): array
[
'class' => 'modal-dlg',
'data-btn-submit' => lang('Common.submit'),
'title'=>lang($controller . '.update') //TODO: String interpolation
'title'=>lang("$controller.update")
]
)
];

View File

@@ -38,7 +38,6 @@ class Customer extends Person
$builder = $this->db->table('customers');
$builder->join('people', 'people.person_id = customers.person_id');
$builder->where('customers.person_id', $person_id);
return ($builder->get()->getNumRows() == 1);
}
@@ -104,7 +103,7 @@ class Customer extends Person
else
{
//Get empty base parent object, as $customer_id is NOT a customer
$person_obj = parent::get_info(-1); //TODO: NEED TO CREATE A GLOBAL CONSTANT FOR NO_PERSON IN CONFIG/CONSTANTS.PHP AND CALL IT HERE FOR CLARITY.
$person_obj = parent::get_info(NEW_ENTRY);
//Get all the fields from customer table
//append those fields to base parent object, we have a complete empty object
@@ -206,7 +205,7 @@ class Customer extends Person
/**
* Inserts or updates a customer
*/
public function save_customer(array &$person_data, array &$customer_data, bool $customer_id = FALSE): bool
public function save_customer(array &$person_data, array &$customer_data, int $customer_id = NEW_ENTRY): bool
{
$success = FALSE;
@@ -215,7 +214,7 @@ class Customer extends Person
if(parent::save_value($person_data, $customer_id))
{
$builder = $this->db->table('customers');
if(!$customer_id || !$this->exists($customer_id))
if($customer_id == NEW_ENTRY || !$customer_id || !$this->exists($customer_id))
{
$customer_data['person_id'] = $person_data['person_id'];
$success = $builder->insert($customer_data);

View File

@@ -126,11 +126,11 @@ class Person extends Model
* @param bool $person_id identifier of the person to update the information
* @return boolean TRUE if the save was successful, FALSE if not
*/
public function save_value(array &$person_data, bool $person_id = FALSE): bool
public function save_value(array &$person_data, int $person_id = NEW_ENTRY): bool
{
$builder = $this->db->table('people');
if(!$person_id || !$this->exists($person_id))
if($person_id == NEW_ENTRY || !$this->exists($person_id))
{
if($builder->insert($person_data))
{

View File

@@ -284,7 +284,7 @@
var submit_handler = function(url) {
return function (resource, response) {
var id = response.id;
var id = response.id.toString();
if (!response.success) {
$.notify(response.message, { type: 'danger' });
} else {
@@ -292,9 +292,8 @@
var selector = rows_selector(response.id);
var rows = $(selector.join(",")).length;
if (rows > 0 && rows < 15) {
var respond_id = response.id;
var ids = respond_id.split(":");
$.get([url || resource + '/get_row', id].join("/"), {}, function (response) {
var ids = id.split(":");
$.get([url || resource + '/ajaxRow', id].join("/"), {}, function (response) {
$.each(selector, function (index, element) {
var id = $(element).data('uniqueid');
table().updateByUniqueId({id: id, row: response[id] || response});