Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jekkos
Copy link
Member

@jekkos jekkos commented Jul 10, 2025

No description provided.

@jekkos jekkos force-pushed the giftcard-no-person branch from fe0a4ab to 374bd09 Compare July 10, 2025 05:45
@odiea
Copy link
Collaborator

odiea commented Jul 10, 2025

CRITICAL - 2025-07-10 00:58:46 --> [Caused by] mysqli_sql_exception: Cannot add or update a child row: a foreign key constraint fails (ospos115.ospos_giftcards, CONSTRAINT ospos_giftcards_ibfk_1 FOREIGN KEY (person_id) REFERENCES ospos_people (person_id))
in SYSTEMPATH\Database\MySQLi\Connection.php on line 327.
1 SYSTEMPATH\Database\MySQLi\Connection.php(327): mysqli->query('INSERT INTO ospos_giftcards (record_time, giftcard_number, value, person_id) VALUES ('2025-07-10 00:58:45', '23', 45, '0')', 0)
2 SYSTEMPATH\Database\BaseConnection.php(738): CodeIgniter\Database\MySQLi\Connection->execute('INSERT INTO ospos_giftcards (record_time, giftcard_number, value, person_id) VALUES ('2025-07-10 00:58:45', '23', 45, '0')')
3 SYSTEMPATH\Database\BaseConnection.php(652): CodeIgniter\Database\BaseConnection->simpleQuery('INSERT INTO ospos_giftcards (record_time, giftcard_number, value, person_id) VALUES ('2025-07-10 00:58:45', '23', 45, '0')')
4 SYSTEMPATH\Database\BaseBuilder.php(2345): CodeIgniter\Database\BaseConnection->query('INSERT INTO ospos_giftcards (record_time, giftcard_number, value, person_id) VALUES (:record_time:, :giftcard_number:, :value:, :person_id:)', [...], false)
5 APPPATH\Models\Giftcard.php(145): CodeIgniter\Database\BaseBuilder->insert([...])
6 APPPATH\Controllers\Giftcards.php(131): App\Models\Giftcard->save_value([...], -1)
7 SYSTEMPATH\CodeIgniter.php(933): App\Controllers\Giftcards->postSave(-1)
8 SYSTEMPATH\CodeIgniter.php(507): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Giftcards))
9 SYSTEMPATH\CodeIgniter.php(354): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
10 SYSTEMPATH\Boot.php(334): CodeIgniter\CodeIgniter->run()
11 SYSTEMPATH\Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))
12 FCPATH\index.php(56): CodeIgniter\Boot::bootWeb(Object(Config\Paths))

@jekkos
Copy link
Member Author

jekkos commented Jul 10, 2025

I wonder how this would have worked then , I don't see any changes to gitcard table since some time. Did you use mariadb or mysql for the test?

@odiea
Copy link
Collaborator

odiea commented Jul 10, 2025

I use Mysql and to get this option to work I had to drop the constraint. And in Controller /Sales the following needs to be modified if a Customer needs to be added to the Sale with a blank Giftcard name otherwise you get the Incorrect Customer Error.
I did get the following to work as I hoped it would. if (isset($cur_giftcard_customer) && $cur_giftcard_customer != $customer_id && $cur_giftcard_customer != 0)

if (isset($cur_giftcard_customer) && $cur_giftcard_customer != $customer_id) {
                    $data['error'] = lang('Giftcards.cannot_use', [$giftcard_num]);
                } elseif (($cur_giftcard_value - $current_payments_with_giftcard) <= 0 && $this->sale_lib->get_mode() === 'sale') {
                    $data['error'] = lang('Giftcards.remaining_balance', [$giftcard_num, $cur_giftcard_value]);
                } else {
                    $new_giftcard_value = $giftcard->get_giftcard_value($giftcard_num) - $this->sale_lib->get_amount_due();
                    $new_giftcard_value = max($new_giftcard_value, 0);
                    $this->sale_lib->set_giftcard_remainder($new_giftcard_value);
                    $new_giftcard_value = str_replace('$', '\$', to_currency($new_giftcard_value));
                    $data['warning'] = lang('Giftcards.remaining_balance', [$giftcard_num, $new_giftcard_value]);
                    $amount_tendered = min($this->sale_lib->get_amount_due(), $giftcard->get_giftcard_value($giftcard_num));

                    $this->sale_lib->add_payment($payment_type, $amount_tendered);
                }

@jekkos
Copy link
Member Author

jekkos commented Jul 12, 2025

Its weird as the foreign key seems to have been there for some time, so maybe mysql behavior changed and it cannot be null anymore? Thanks for the suggestion I might apply it to the master

@jekkos jekkos added the bug label Jul 16, 2025
@jekkos jekkos added this to the 3.4.2 milestone Jul 16, 2025
@jekkos jekkos self-assigned this Jul 16, 2025
@jekkos
Copy link
Member Author

jekkos commented Aug 29, 2025

Might be related to #4306, giftcards that do not have any customer linked might not work now unless we add this change you suggested @odiea

@objecttothis
Copy link
Member

I haven't looked at the code for this change, but from a use standpoint I think the use of a giftcard should not require the purchasing customer to be entered, but I can see arguments either way for requiring a customer to be entered in the sales register. In terms of fraud prevention, having the purchasing and using customers be stored. We could make a "Require customer to use gift cards" checkbox so that those who want to track gift card use with a specific customer can enforce it.

@objecttothis
Copy link
Member

I think it will be incredibly important to test database schema changes against both MariaDB and MySQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants