Hi, I'm new and I've recently started using Grocery CRUD and it's been amazing so far. It has made my life a lot easier, but I am experiencing some issues recently. I've been experiencing some issues with the callback functions where they get completely ignored. I believe I have found the issue, where the functions are not called and the $post_arrays are NULL and not returning any values. Although I have discovered the issues, I do not know how to fix these issues.
Here is my code:
//Creates the Grocery CRUD $crud = new grocery_CRUD(); $crud->set_table('billing'); $crud->set_subject('Billing','Billings'); $crud->fields('Billing_ID','Item_ID','Amount','Status','Due_date','Received_By','Data_Received','Checked_By','Date_Checked','Endorsed_By','Date_Endorsed','Approved_By','Date_Approved','Payment_Prep_By','Date_Payment_Prep','Paid_By','Date_Approved','Date_Paid','Month','Year'); $crud->column(['Billing_ID','Item_ID','Amount','Status','Month','Year']); $crud->field_type('Status', 'invisible'); $crud->field_type('Due_Date', 'datetime'); $crud->field_type('Date_Received', 'datetime'); $crud->field_type('Date_Checked', 'datetime'); $crud->field_type('Date_Endorsed', 'datetime'); $crud->field_type('Date_Approved', 'datetime'); $crud->field_type('Date_Payment_Prep', 'datetime'); $crud->field_type('Date_Paid', 'datetime'); //Configures the Add & Edit Table $crud->add_fields('Billing_ID','Item_ID','Amount','Due_date','Received_By','Data_Received','Checked_By','Date_Checked','Endorsed_By','Date_Endorsed','Approved_By','Date_Approved','Payment_Prep_By','Date_Payment_Prep','Paid_By','Date_Approved','Date_Paid'); $crud->edit_fields('Billing_ID','Item_ID','Amount','Due_date','Received_By','Data_Received','Checked_By','Date_Checked','Endorsed_By','Date_Endorsed','Approved_By','Date_Approved','Payment_Prep_By','Date_Payment_Prep','Paid_By','Date_Approved','Date_Paid'); //Runs a function before the update function is runned $crud->callback_before_update(function ($post_array,$primary_key){ $this->_check_status($post_array); return $post_array; });
function _check_status($post_array){ if (!empty($post_array['Date_Paid'] and $post_array['Paid_By'] and $post_array['Date_Payment_Prep'] and $post_array['Payment_Prep_By'] and $post_array['Date_Approved'] and $post_array['Approved_By'] and $post_array['Date_Endorsed'] and $post_array['Endorsed_By'] and $post_array['Date_Checked'] and $post_array['Checked_By'])) { $post_array['Status'] = 'Paid'; } else if (!empty($post_array['Date_Payment_Prep'] and $post_array['Payment_Prep_By'] and $post_array['Date_Approved'] and $post_array['Approved_By'] and $post_array['Date_Endorsed'] and $post_array['Endorsed_By'] and $post_array['Date_Checked'] and $post_array['Checked_By'])) { $post_array['Status']= 'Preparing Payment'; } else if (!empty($post_array['Date_Approved'] and $post_array['Approved_By'] and $post_array['Date_Endorsed'] and $post_array['Endorsed_By'] and $post_array['Date_Checked'] and $post_array['Checked_By'])) { $post_array['Status'] = 'Approved'; } else if (!empty($post_array['Date_Endorsed'] and $post_array['Endorsed_By'] and $post_array['Date_Checked'] and $post_array['Checked_By'])) { $post_array['Status'] = 'Endorsed'; } else if (!empty($post_array['Date_Checked'] and $post_array['Checked_By'])) { $post_array['Status'] = 'Checked'; } else { $post_array['Status'] = 'Received'; } return $post_array; }
Any help or advice is appreciated. Thank you.