You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refactor: Store payment types using a foreign key instead of localized strings #4548
Payment types (e.g. Cash, Debit Card, Bank Transfer, Wallet, etc.) are currently stored in the sales table as the string representation of the payment type label in whatever language the logged-in employee was using at the time of sale.
This creates a data integrity problem: a sale recorded by an English-speaking employee is stored as "Cash", while the same payment type recorded by a Spanish-speaking employee is stored as "Efectivo". Querying, filtering, and reporting across these records becomes inconsistent and unreliable.
Proposed Solution
Create a new static payment_types table with at minimum the following columns:
id (primary key, integer)
name (canonical/internal identifier, e.g. cash, debit_card, bank_transfer, wallet)
Update the sales (and receiving) tables to store the payment_type_id (foreign key → payment_types.id) instead of the localized string.
Update all queries, filters, and reports that currently match on the localized string (e.g. LIKE lang('Sales.bank_transfer')) to instead use the numeric foreign key.
Keep the language files for display/UI purposes only — translation happens at the presentation layer, not at the storage layer.
Impact
app/Models/Sale.php — get_payments_summary() and add_filters_to_query() use LIKE lang('Sales.*') conditions that are locale-dependent.
app/Controllers/Reports.php — get_payment_type() returns localized labels used for filtering.
app/Controllers/Sales.php — filter keys map to locale-dependent query conditions.
app/Helpers/locale_helper.php — get_payment_options() builds options from language strings.
app/Models/Receiving.php — get_payment_options() similarly builds options from language strings.
Related PR
This issue was identified during the review of #4547 (Bank Transfer and Wallet payment options), raised by @objecttothis.
The view's check_payment_type() JavaScript function contains hardcoded comparisons against localized payment type strings (PHP-rendered into the JS via <?= lang(...) ?>):
Because the else branch caught all non-cash/non-giftcard types, adding Bank Transfer, Wallet, and UPI payment options (PR #4547) caused the Payment Reference Code field to incorrectly appear for those types.
Interim fix applied: A helper get_reference_code_payment_types(): array was added to locale_helper.php as a single source of truth, used by both the controller validation (postAddPayment()) and the view (JSON-encoded into the JS as referenceCodePaymentTypes). The JS now uses referenceCodePaymentTypes.indexOf(paymentType) !== -1 instead of hardcoded strings.
This is still locale-string-based. The full FK migration proposed here would allow this JS check to use a stable requires_reference_code boolean flag on the payment type record instead of matching against translated strings.
Activity
objecttothis commentedon Jun 30, 2026
Additional impact:
app/Views/sales/register.phpThe view's
check_payment_type()JavaScript function contains hardcoded comparisons against localized payment type strings (PHP-rendered into the JS via<?= lang(...) ?>):Because the
elsebranch caught all non-cash/non-giftcard types, adding Bank Transfer, Wallet, and UPI payment options (PR #4547) caused the Payment Reference Code field to incorrectly appear for those types.Interim fix applied: A helper
get_reference_code_payment_types(): arraywas added tolocale_helper.phpas a single source of truth, used by both the controller validation (postAddPayment()) and the view (JSON-encoded into the JS asreferenceCodePaymentTypes). The JS now usesreferenceCodePaymentTypes.indexOf(paymentType) !== -1instead of hardcoded strings.This is still locale-string-based. The full FK migration proposed here would allow this JS check to use a stable
requires_reference_codeboolean flag on the payment type record instead of matching against translated strings.