feat(loyalty): implement Phase 2 - company-wide points system
Complete implementation of loyalty module Phase 2 features: Database & Models: - Add company_id to LoyaltyProgram for chain-wide loyalty - Add company_id to LoyaltyCard for multi-location support - Add CompanyLoyaltySettings model for admin-controlled settings - Add points expiration, welcome bonus, and minimum redemption fields - Add POINTS_EXPIRED, WELCOME_BONUS transaction types Services: - Update program_service for company-based queries - Update card_service with enrollment and welcome bonus - Update points_service with void_points for returns - Update stamp_service for company context - Update pin_service for company-wide operations API Endpoints: - Admin: Program listing with stats, company detail views - Vendor: Terminal operations, card management, settings - Storefront: Customer card/transactions, self-enrollment UI Templates: - Admin: Programs dashboard, company detail, settings - Vendor: Terminal, cards list, card detail, settings, stats, enrollment - Storefront: Dashboard, history, enrollment, success pages Background Tasks: - Point expiration task (daily, based on inactivity) - Wallet sync task (hourly) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
115
app/modules/loyalty/static/admin/js/loyalty-analytics.js
Normal file
115
app/modules/loyalty/static/admin/js/loyalty-analytics.js
Normal file
@@ -0,0 +1,115 @@
|
||||
// app/modules/loyalty/static/admin/js/loyalty-analytics.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
// Use centralized logger
|
||||
const loyaltyAnalyticsLog = window.LogConfig.loggers.loyaltyAnalytics || window.LogConfig.createLogger('loyaltyAnalytics');
|
||||
|
||||
// ============================================
|
||||
// LOYALTY ANALYTICS FUNCTION
|
||||
// ============================================
|
||||
function adminLoyaltyAnalytics() {
|
||||
return {
|
||||
// Inherit base layout functionality
|
||||
...data(),
|
||||
|
||||
// Page identifier for sidebar active state
|
||||
currentPage: 'loyalty-analytics',
|
||||
|
||||
// Stats
|
||||
stats: {
|
||||
total_programs: 0,
|
||||
active_programs: 0,
|
||||
total_cards: 0,
|
||||
active_cards: 0,
|
||||
transactions_30d: 0,
|
||||
points_issued_30d: 0,
|
||||
points_redeemed_30d: 0,
|
||||
companies_with_programs: 0
|
||||
},
|
||||
|
||||
// State
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
// Computed: Redemption rate percentage
|
||||
get redemptionRate() {
|
||||
if (this.stats.points_issued_30d === 0) return 0;
|
||||
return Math.round((this.stats.points_redeemed_30d / this.stats.points_issued_30d) * 100);
|
||||
},
|
||||
|
||||
// Computed: Issued percentage for progress bar
|
||||
get issuedPercentage() {
|
||||
const total = this.stats.points_issued_30d + this.stats.points_redeemed_30d;
|
||||
if (total === 0) return 50;
|
||||
return Math.round((this.stats.points_issued_30d / total) * 100);
|
||||
},
|
||||
|
||||
// Computed: Redeemed percentage for progress bar
|
||||
get redeemedPercentage() {
|
||||
return 100 - this.issuedPercentage;
|
||||
},
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
loyaltyAnalyticsLog.info('=== LOYALTY ANALYTICS PAGE INITIALIZING ===');
|
||||
|
||||
// Prevent multiple initializations
|
||||
if (window._loyaltyAnalyticsInitialized) {
|
||||
loyaltyAnalyticsLog.warn('Loyalty analytics page already initialized, skipping...');
|
||||
return;
|
||||
}
|
||||
window._loyaltyAnalyticsInitialized = true;
|
||||
|
||||
loyaltyAnalyticsLog.group('Loading analytics data');
|
||||
await this.loadStats();
|
||||
loyaltyAnalyticsLog.groupEnd();
|
||||
|
||||
loyaltyAnalyticsLog.info('=== LOYALTY ANALYTICS PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
// Load platform stats
|
||||
async loadStats() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
loyaltyAnalyticsLog.info('Fetching loyalty analytics...');
|
||||
|
||||
const response = await apiClient.get('/admin/loyalty/stats');
|
||||
|
||||
if (response) {
|
||||
this.stats = {
|
||||
total_programs: response.total_programs || 0,
|
||||
active_programs: response.active_programs || 0,
|
||||
total_cards: response.total_cards || 0,
|
||||
active_cards: response.active_cards || 0,
|
||||
transactions_30d: response.transactions_30d || 0,
|
||||
points_issued_30d: response.points_issued_30d || 0,
|
||||
points_redeemed_30d: response.points_redeemed_30d || 0,
|
||||
companies_with_programs: response.companies_with_programs || 0
|
||||
};
|
||||
|
||||
loyaltyAnalyticsLog.info('Analytics loaded:', this.stats);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyAnalyticsLog.error('Failed to load analytics:', error);
|
||||
this.error = error.message || 'Failed to load analytics';
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Format number with thousands separator
|
||||
formatNumber(num) {
|
||||
if (num === null || num === undefined) return '0';
|
||||
return new Intl.NumberFormat('en-US').format(num);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Register logger for configuration
|
||||
if (!window.LogConfig.loggers.loyaltyAnalytics) {
|
||||
window.LogConfig.loggers.loyaltyAnalytics = window.LogConfig.createLogger('loyaltyAnalytics');
|
||||
}
|
||||
|
||||
loyaltyAnalyticsLog.info('Loyalty analytics module loaded');
|
||||
208
app/modules/loyalty/static/admin/js/loyalty-company-detail.js
Normal file
208
app/modules/loyalty/static/admin/js/loyalty-company-detail.js
Normal file
@@ -0,0 +1,208 @@
|
||||
// app/modules/loyalty/static/admin/js/loyalty-company-detail.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
// Use centralized logger
|
||||
const loyaltyCompanyDetailLog = window.LogConfig.loggers.loyaltyCompanyDetail || window.LogConfig.createLogger('loyaltyCompanyDetail');
|
||||
|
||||
// ============================================
|
||||
// LOYALTY COMPANY DETAIL FUNCTION
|
||||
// ============================================
|
||||
function adminLoyaltyCompanyDetail() {
|
||||
return {
|
||||
// Inherit base layout functionality
|
||||
...data(),
|
||||
|
||||
// Page identifier for sidebar active state
|
||||
currentPage: 'loyalty-programs',
|
||||
|
||||
// Company ID from URL
|
||||
companyId: null,
|
||||
|
||||
// Company data
|
||||
company: null,
|
||||
program: null,
|
||||
stats: {
|
||||
total_cards: 0,
|
||||
active_cards: 0,
|
||||
total_points_issued: 0,
|
||||
total_points_redeemed: 0,
|
||||
points_issued_30d: 0,
|
||||
points_redeemed_30d: 0,
|
||||
transactions_30d: 0
|
||||
},
|
||||
settings: null,
|
||||
locations: [],
|
||||
|
||||
// State
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
loyaltyCompanyDetailLog.info('=== LOYALTY COMPANY DETAIL PAGE INITIALIZING ===');
|
||||
|
||||
// Prevent multiple initializations
|
||||
if (window._loyaltyCompanyDetailInitialized) {
|
||||
loyaltyCompanyDetailLog.warn('Loyalty company detail page already initialized, skipping...');
|
||||
return;
|
||||
}
|
||||
window._loyaltyCompanyDetailInitialized = true;
|
||||
|
||||
// Extract company ID from URL
|
||||
const pathParts = window.location.pathname.split('/');
|
||||
const companiesIndex = pathParts.indexOf('companies');
|
||||
if (companiesIndex !== -1 && pathParts[companiesIndex + 1]) {
|
||||
this.companyId = parseInt(pathParts[companiesIndex + 1]);
|
||||
}
|
||||
|
||||
if (!this.companyId) {
|
||||
this.error = 'Invalid company ID';
|
||||
loyaltyCompanyDetailLog.error('Could not extract company ID from URL');
|
||||
return;
|
||||
}
|
||||
|
||||
loyaltyCompanyDetailLog.info('Company ID:', this.companyId);
|
||||
|
||||
loyaltyCompanyDetailLog.group('Loading company loyalty data');
|
||||
await this.loadCompanyData();
|
||||
loyaltyCompanyDetailLog.groupEnd();
|
||||
|
||||
loyaltyCompanyDetailLog.info('=== LOYALTY COMPANY DETAIL PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
// Load all company data
|
||||
async loadCompanyData() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
// Load company info
|
||||
await this.loadCompany();
|
||||
|
||||
// Load loyalty-specific data in parallel
|
||||
await Promise.all([
|
||||
this.loadStats(),
|
||||
this.loadSettings(),
|
||||
this.loadLocations()
|
||||
]);
|
||||
} catch (error) {
|
||||
loyaltyCompanyDetailLog.error('Failed to load company data:', error);
|
||||
this.error = error.message || 'Failed to load company loyalty data';
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Load company basic info
|
||||
async loadCompany() {
|
||||
try {
|
||||
loyaltyCompanyDetailLog.info('Fetching company info...');
|
||||
|
||||
// Get company from tenancy API
|
||||
const response = await apiClient.get(`/admin/companies/${this.companyId}`);
|
||||
|
||||
if (response) {
|
||||
this.company = response;
|
||||
loyaltyCompanyDetailLog.info('Company loaded:', this.company.name);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCompanyDetailLog.error('Failed to load company:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Load company loyalty stats
|
||||
async loadStats() {
|
||||
try {
|
||||
loyaltyCompanyDetailLog.info('Fetching company loyalty stats...');
|
||||
|
||||
const response = await apiClient.get(`/admin/loyalty/companies/${this.companyId}/stats`);
|
||||
|
||||
if (response) {
|
||||
this.stats = {
|
||||
total_cards: response.total_cards || 0,
|
||||
active_cards: response.active_cards || 0,
|
||||
total_points_issued: response.total_points_issued || 0,
|
||||
total_points_redeemed: response.total_points_redeemed || 0,
|
||||
points_issued_30d: response.points_issued_30d || 0,
|
||||
points_redeemed_30d: response.points_redeemed_30d || 0,
|
||||
transactions_30d: response.transactions_30d || 0
|
||||
};
|
||||
|
||||
// Also get program info from stats response
|
||||
if (response.program) {
|
||||
this.program = response.program;
|
||||
}
|
||||
|
||||
// Get location breakdown
|
||||
if (response.locations) {
|
||||
this.locations = response.locations;
|
||||
}
|
||||
|
||||
loyaltyCompanyDetailLog.info('Stats loaded:', this.stats);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCompanyDetailLog.warn('Failed to load stats (company may not have loyalty program):', error.message);
|
||||
// Don't throw - stats might fail if no program exists
|
||||
}
|
||||
},
|
||||
|
||||
// Load company loyalty settings
|
||||
async loadSettings() {
|
||||
try {
|
||||
loyaltyCompanyDetailLog.info('Fetching company loyalty settings...');
|
||||
|
||||
const response = await apiClient.get(`/admin/loyalty/companies/${this.companyId}/settings`);
|
||||
|
||||
if (response) {
|
||||
this.settings = response;
|
||||
loyaltyCompanyDetailLog.info('Settings loaded:', this.settings);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCompanyDetailLog.warn('Failed to load settings:', error.message);
|
||||
// Don't throw - settings might not exist yet
|
||||
}
|
||||
},
|
||||
|
||||
// Load location breakdown
|
||||
async loadLocations() {
|
||||
try {
|
||||
loyaltyCompanyDetailLog.info('Fetching location breakdown...');
|
||||
|
||||
// This data comes with stats, but could be a separate endpoint
|
||||
// For now, stats endpoint should return locations array
|
||||
} catch (error) {
|
||||
loyaltyCompanyDetailLog.warn('Failed to load locations:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
// Format date for display
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return 'N/A';
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
});
|
||||
} catch (e) {
|
||||
loyaltyCompanyDetailLog.error('Date parsing error:', e);
|
||||
return dateString;
|
||||
}
|
||||
},
|
||||
|
||||
// Format number with thousands separator
|
||||
formatNumber(num) {
|
||||
if (num === null || num === undefined) return '0';
|
||||
return new Intl.NumberFormat('en-US').format(num);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Register logger for configuration
|
||||
if (!window.LogConfig.loggers.loyaltyCompanyDetail) {
|
||||
window.LogConfig.loggers.loyaltyCompanyDetail = window.LogConfig.createLogger('loyaltyCompanyDetail');
|
||||
}
|
||||
|
||||
loyaltyCompanyDetailLog.info('Loyalty company detail module loaded');
|
||||
173
app/modules/loyalty/static/admin/js/loyalty-company-settings.js
Normal file
173
app/modules/loyalty/static/admin/js/loyalty-company-settings.js
Normal file
@@ -0,0 +1,173 @@
|
||||
// app/modules/loyalty/static/admin/js/loyalty-company-settings.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
// Use centralized logger
|
||||
const loyaltyCompanySettingsLog = window.LogConfig.loggers.loyaltyCompanySettings || window.LogConfig.createLogger('loyaltyCompanySettings');
|
||||
|
||||
// ============================================
|
||||
// LOYALTY COMPANY SETTINGS FUNCTION
|
||||
// ============================================
|
||||
function adminLoyaltyCompanySettings() {
|
||||
return {
|
||||
// Inherit base layout functionality
|
||||
...data(),
|
||||
|
||||
// Page identifier for sidebar active state
|
||||
currentPage: 'loyalty-programs',
|
||||
|
||||
// Company ID from URL
|
||||
companyId: null,
|
||||
|
||||
// Company data
|
||||
company: null,
|
||||
|
||||
// Settings form data
|
||||
settings: {
|
||||
staff_pin_policy: 'optional',
|
||||
staff_pin_lockout_attempts: 5,
|
||||
staff_pin_lockout_minutes: 30,
|
||||
allow_self_enrollment: true,
|
||||
allow_void_transactions: true,
|
||||
allow_cross_location_redemption: true
|
||||
},
|
||||
|
||||
// State
|
||||
loading: false,
|
||||
saving: false,
|
||||
error: null,
|
||||
|
||||
// Back URL
|
||||
get backUrl() {
|
||||
return `/admin/loyalty/companies/${this.companyId}`;
|
||||
},
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
loyaltyCompanySettingsLog.info('=== LOYALTY COMPANY SETTINGS PAGE INITIALIZING ===');
|
||||
|
||||
// Prevent multiple initializations
|
||||
if (window._loyaltyCompanySettingsInitialized) {
|
||||
loyaltyCompanySettingsLog.warn('Loyalty company settings page already initialized, skipping...');
|
||||
return;
|
||||
}
|
||||
window._loyaltyCompanySettingsInitialized = true;
|
||||
|
||||
// Extract company ID from URL
|
||||
const pathParts = window.location.pathname.split('/');
|
||||
const companiesIndex = pathParts.indexOf('companies');
|
||||
if (companiesIndex !== -1 && pathParts[companiesIndex + 1]) {
|
||||
this.companyId = parseInt(pathParts[companiesIndex + 1]);
|
||||
}
|
||||
|
||||
if (!this.companyId) {
|
||||
this.error = 'Invalid company ID';
|
||||
loyaltyCompanySettingsLog.error('Could not extract company ID from URL');
|
||||
return;
|
||||
}
|
||||
|
||||
loyaltyCompanySettingsLog.info('Company ID:', this.companyId);
|
||||
|
||||
loyaltyCompanySettingsLog.group('Loading company settings data');
|
||||
await this.loadData();
|
||||
loyaltyCompanySettingsLog.groupEnd();
|
||||
|
||||
loyaltyCompanySettingsLog.info('=== LOYALTY COMPANY SETTINGS PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
// Load all data
|
||||
async loadData() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
// Load company info and settings in parallel
|
||||
await Promise.all([
|
||||
this.loadCompany(),
|
||||
this.loadSettings()
|
||||
]);
|
||||
} catch (error) {
|
||||
loyaltyCompanySettingsLog.error('Failed to load data:', error);
|
||||
this.error = error.message || 'Failed to load settings';
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Load company basic info
|
||||
async loadCompany() {
|
||||
try {
|
||||
loyaltyCompanySettingsLog.info('Fetching company info...');
|
||||
|
||||
const response = await apiClient.get(`/admin/companies/${this.companyId}`);
|
||||
|
||||
if (response) {
|
||||
this.company = response;
|
||||
loyaltyCompanySettingsLog.info('Company loaded:', this.company.name);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCompanySettingsLog.error('Failed to load company:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Load settings
|
||||
async loadSettings() {
|
||||
try {
|
||||
loyaltyCompanySettingsLog.info('Fetching company loyalty settings...');
|
||||
|
||||
const response = await apiClient.get(`/admin/loyalty/companies/${this.companyId}/settings`);
|
||||
|
||||
if (response) {
|
||||
// Merge with defaults to ensure all fields exist
|
||||
this.settings = {
|
||||
staff_pin_policy: response.staff_pin_policy || 'optional',
|
||||
staff_pin_lockout_attempts: response.staff_pin_lockout_attempts || 5,
|
||||
staff_pin_lockout_minutes: response.staff_pin_lockout_minutes || 30,
|
||||
allow_self_enrollment: response.allow_self_enrollment !== false,
|
||||
allow_void_transactions: response.allow_void_transactions !== false,
|
||||
allow_cross_location_redemption: response.allow_cross_location_redemption !== false
|
||||
};
|
||||
|
||||
loyaltyCompanySettingsLog.info('Settings loaded:', this.settings);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCompanySettingsLog.warn('Failed to load settings, using defaults:', error.message);
|
||||
// Keep default settings
|
||||
}
|
||||
},
|
||||
|
||||
// Save settings
|
||||
async saveSettings() {
|
||||
this.saving = true;
|
||||
|
||||
try {
|
||||
loyaltyCompanySettingsLog.info('Saving company loyalty settings...');
|
||||
|
||||
const response = await apiClient.patch(
|
||||
`/admin/loyalty/companies/${this.companyId}/settings`,
|
||||
this.settings
|
||||
);
|
||||
|
||||
if (response) {
|
||||
loyaltyCompanySettingsLog.info('Settings saved successfully');
|
||||
Utils.showToast('Settings saved successfully', 'success');
|
||||
|
||||
// Navigate back to company detail
|
||||
window.location.href = this.backUrl;
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCompanySettingsLog.error('Failed to save settings:', error);
|
||||
Utils.showToast(`Failed to save settings: ${error.message}`, 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Register logger for configuration
|
||||
if (!window.LogConfig.loggers.loyaltyCompanySettings) {
|
||||
window.LogConfig.loggers.loyaltyCompanySettings = window.LogConfig.createLogger('loyaltyCompanySettings');
|
||||
}
|
||||
|
||||
loyaltyCompanySettingsLog.info('Loyalty company settings module loaded');
|
||||
264
app/modules/loyalty/static/admin/js/loyalty-programs.js
Normal file
264
app/modules/loyalty/static/admin/js/loyalty-programs.js
Normal file
@@ -0,0 +1,264 @@
|
||||
// app/modules/loyalty/static/admin/js/loyalty-programs.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
// Use centralized logger
|
||||
const loyaltyProgramsLog = window.LogConfig.loggers.loyaltyPrograms || window.LogConfig.createLogger('loyaltyPrograms');
|
||||
|
||||
// ============================================
|
||||
// LOYALTY PROGRAMS LIST FUNCTION
|
||||
// ============================================
|
||||
function adminLoyaltyPrograms() {
|
||||
return {
|
||||
// Inherit base layout functionality
|
||||
...data(),
|
||||
|
||||
// Page identifier for sidebar active state
|
||||
currentPage: 'loyalty-programs',
|
||||
|
||||
// Programs page specific state
|
||||
programs: [],
|
||||
stats: {
|
||||
total_programs: 0,
|
||||
active_programs: 0,
|
||||
total_cards: 0,
|
||||
transactions_30d: 0,
|
||||
points_issued_30d: 0,
|
||||
points_redeemed_30d: 0,
|
||||
companies_with_programs: 0
|
||||
},
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
// Search and filters
|
||||
filters: {
|
||||
search: '',
|
||||
is_active: ''
|
||||
},
|
||||
|
||||
// Pagination state
|
||||
pagination: {
|
||||
page: 1,
|
||||
per_page: 20,
|
||||
total: 0,
|
||||
pages: 0
|
||||
},
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
loyaltyProgramsLog.info('=== LOYALTY PROGRAMS PAGE INITIALIZING ===');
|
||||
|
||||
// Prevent multiple initializations
|
||||
if (window._loyaltyProgramsInitialized) {
|
||||
loyaltyProgramsLog.warn('Loyalty programs page already initialized, skipping...');
|
||||
return;
|
||||
}
|
||||
window._loyaltyProgramsInitialized = true;
|
||||
|
||||
// Load platform settings for rows per page
|
||||
if (window.PlatformSettings) {
|
||||
this.pagination.per_page = await window.PlatformSettings.getRowsPerPage();
|
||||
}
|
||||
|
||||
loyaltyProgramsLog.group('Loading loyalty programs data');
|
||||
await Promise.all([
|
||||
this.loadPrograms(),
|
||||
this.loadStats()
|
||||
]);
|
||||
loyaltyProgramsLog.groupEnd();
|
||||
|
||||
loyaltyProgramsLog.info('=== LOYALTY PROGRAMS PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
// Debounced search
|
||||
debouncedSearch() {
|
||||
if (this._searchTimeout) {
|
||||
clearTimeout(this._searchTimeout);
|
||||
}
|
||||
this._searchTimeout = setTimeout(() => {
|
||||
loyaltyProgramsLog.info('Search triggered:', this.filters.search);
|
||||
this.pagination.page = 1;
|
||||
this.loadPrograms();
|
||||
}, 300);
|
||||
},
|
||||
|
||||
// Computed: Get programs for current page (already paginated from server)
|
||||
get paginatedPrograms() {
|
||||
return this.programs;
|
||||
},
|
||||
|
||||
// Computed: Total number of pages
|
||||
get totalPages() {
|
||||
return this.pagination.pages;
|
||||
},
|
||||
|
||||
// Computed: Start index for pagination display
|
||||
get startIndex() {
|
||||
if (this.pagination.total === 0) return 0;
|
||||
return (this.pagination.page - 1) * this.pagination.per_page + 1;
|
||||
},
|
||||
|
||||
// Computed: End index for pagination display
|
||||
get endIndex() {
|
||||
const end = this.pagination.page * this.pagination.per_page;
|
||||
return end > this.pagination.total ? this.pagination.total : end;
|
||||
},
|
||||
|
||||
// Computed: Generate page numbers array with ellipsis
|
||||
get pageNumbers() {
|
||||
const pages = [];
|
||||
const totalPages = this.totalPages;
|
||||
const current = this.pagination.page;
|
||||
|
||||
if (totalPages <= 7) {
|
||||
// Show all pages if 7 or fewer
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
} else {
|
||||
// Always show first page
|
||||
pages.push(1);
|
||||
|
||||
if (current > 3) {
|
||||
pages.push('...');
|
||||
}
|
||||
|
||||
// Show pages around current page
|
||||
const start = Math.max(2, current - 1);
|
||||
const end = Math.min(totalPages - 1, current + 1);
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
pages.push(i);
|
||||
}
|
||||
|
||||
if (current < totalPages - 2) {
|
||||
pages.push('...');
|
||||
}
|
||||
|
||||
// Always show last page
|
||||
pages.push(totalPages);
|
||||
}
|
||||
|
||||
return pages;
|
||||
},
|
||||
|
||||
// Load programs with search and pagination
|
||||
async loadPrograms() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
loyaltyProgramsLog.info('Fetching loyalty programs from API...');
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('skip', (this.pagination.page - 1) * this.pagination.per_page);
|
||||
params.append('limit', this.pagination.per_page);
|
||||
|
||||
if (this.filters.search) {
|
||||
params.append('search', this.filters.search);
|
||||
}
|
||||
if (this.filters.is_active !== '') {
|
||||
params.append('is_active', this.filters.is_active);
|
||||
}
|
||||
|
||||
const response = await apiClient.get(`/admin/loyalty/programs?${params}`);
|
||||
|
||||
if (response.programs) {
|
||||
this.programs = response.programs;
|
||||
this.pagination.total = response.total;
|
||||
this.pagination.pages = Math.ceil(response.total / this.pagination.per_page);
|
||||
|
||||
loyaltyProgramsLog.info(`Loaded ${this.programs.length} programs (total: ${response.total})`);
|
||||
} else {
|
||||
loyaltyProgramsLog.warn('No programs in response');
|
||||
this.programs = [];
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyProgramsLog.error('Failed to load programs:', error);
|
||||
this.error = error.message || 'Failed to load loyalty programs';
|
||||
this.programs = [];
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Load platform stats
|
||||
async loadStats() {
|
||||
try {
|
||||
loyaltyProgramsLog.info('Fetching loyalty stats from API...');
|
||||
|
||||
const response = await apiClient.get('/admin/loyalty/stats');
|
||||
|
||||
if (response) {
|
||||
this.stats = {
|
||||
total_programs: response.total_programs || 0,
|
||||
active_programs: response.active_programs || 0,
|
||||
total_cards: response.total_cards || 0,
|
||||
transactions_30d: response.transactions_30d || 0,
|
||||
points_issued_30d: response.points_issued_30d || 0,
|
||||
points_redeemed_30d: response.points_redeemed_30d || 0,
|
||||
companies_with_programs: response.companies_with_programs || 0
|
||||
};
|
||||
|
||||
loyaltyProgramsLog.info('Stats loaded:', this.stats);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyProgramsLog.error('Failed to load stats:', error);
|
||||
// Don't set error state for stats failure
|
||||
}
|
||||
},
|
||||
|
||||
// Pagination methods
|
||||
previousPage() {
|
||||
if (this.pagination.page > 1) {
|
||||
this.pagination.page--;
|
||||
loyaltyProgramsLog.info('Previous page:', this.pagination.page);
|
||||
this.loadPrograms();
|
||||
}
|
||||
},
|
||||
|
||||
nextPage() {
|
||||
if (this.pagination.page < this.totalPages) {
|
||||
this.pagination.page++;
|
||||
loyaltyProgramsLog.info('Next page:', this.pagination.page);
|
||||
this.loadPrograms();
|
||||
}
|
||||
},
|
||||
|
||||
goToPage(pageNum) {
|
||||
if (pageNum !== '...' && pageNum >= 1 && pageNum <= this.totalPages) {
|
||||
this.pagination.page = pageNum;
|
||||
loyaltyProgramsLog.info('Go to page:', this.pagination.page);
|
||||
this.loadPrograms();
|
||||
}
|
||||
},
|
||||
|
||||
// Format date for display
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return 'N/A';
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
});
|
||||
} catch (e) {
|
||||
loyaltyProgramsLog.error('Date parsing error:', e);
|
||||
return dateString;
|
||||
}
|
||||
},
|
||||
|
||||
// Format number with thousands separator
|
||||
formatNumber(num) {
|
||||
if (num === null || num === undefined) return '0';
|
||||
return new Intl.NumberFormat('en-US').format(num);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Register logger for configuration
|
||||
if (!window.LogConfig.loggers.loyaltyPrograms) {
|
||||
window.LogConfig.loggers.loyaltyPrograms = window.LogConfig.createLogger('loyaltyPrograms');
|
||||
}
|
||||
|
||||
loyaltyProgramsLog.info('Loyalty programs module loaded');
|
||||
@@ -0,0 +1,87 @@
|
||||
// app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
|
||||
// Customer loyalty dashboard
|
||||
|
||||
function customerLoyaltyDashboard() {
|
||||
return {
|
||||
...data(),
|
||||
|
||||
// Data
|
||||
card: null,
|
||||
program: null,
|
||||
rewards: [],
|
||||
transactions: [],
|
||||
locations: [],
|
||||
|
||||
// UI state
|
||||
loading: false,
|
||||
showBarcode: false,
|
||||
|
||||
async init() {
|
||||
console.log('Customer loyalty dashboard initializing...');
|
||||
await this.loadData();
|
||||
},
|
||||
|
||||
async loadData() {
|
||||
this.loading = true;
|
||||
try {
|
||||
await Promise.all([
|
||||
this.loadCard(),
|
||||
this.loadTransactions()
|
||||
]);
|
||||
} catch (error) {
|
||||
console.error('Failed to load loyalty data:', error);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async loadCard() {
|
||||
try {
|
||||
const response = await apiClient.get('/storefront/loyalty/card');
|
||||
if (response) {
|
||||
this.card = response.card;
|
||||
this.program = response.program;
|
||||
this.rewards = response.program?.points_rewards || [];
|
||||
this.locations = response.locations || [];
|
||||
console.log('Loyalty card loaded:', this.card?.card_number);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
console.log('No loyalty card found');
|
||||
this.card = null;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async loadTransactions() {
|
||||
try {
|
||||
const response = await apiClient.get('/storefront/loyalty/transactions?limit=10');
|
||||
if (response && response.transactions) {
|
||||
this.transactions = response.transactions;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to load transactions:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
formatNumber(num) {
|
||||
if (num == null) return '0';
|
||||
return new Intl.NumberFormat('en-US').format(num);
|
||||
},
|
||||
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return '-';
|
||||
try {
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
});
|
||||
} catch (e) {
|
||||
return dateString;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
94
app/modules/loyalty/static/storefront/js/loyalty-enroll.js
Normal file
94
app/modules/loyalty/static/storefront/js/loyalty-enroll.js
Normal file
@@ -0,0 +1,94 @@
|
||||
// app/modules/loyalty/static/storefront/js/loyalty-enroll.js
|
||||
// Self-service loyalty enrollment
|
||||
|
||||
function customerLoyaltyEnroll() {
|
||||
return {
|
||||
...data(),
|
||||
|
||||
// Program info
|
||||
program: null,
|
||||
|
||||
// Form data
|
||||
form: {
|
||||
email: '',
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
phone: '',
|
||||
birthday: '',
|
||||
terms_accepted: false,
|
||||
marketing_consent: false
|
||||
},
|
||||
|
||||
// State
|
||||
loading: false,
|
||||
enrolling: false,
|
||||
enrolled: false,
|
||||
enrolledCard: null,
|
||||
error: null,
|
||||
|
||||
async init() {
|
||||
console.log('Customer loyalty enroll initializing...');
|
||||
await this.loadProgram();
|
||||
},
|
||||
|
||||
async loadProgram() {
|
||||
this.loading = true;
|
||||
try {
|
||||
const response = await apiClient.get('/storefront/loyalty/program');
|
||||
if (response) {
|
||||
this.program = response;
|
||||
console.log('Program loaded:', this.program.display_name);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
console.log('No loyalty program available');
|
||||
this.program = null;
|
||||
} else {
|
||||
console.error('Failed to load program:', error);
|
||||
this.error = 'Failed to load program information';
|
||||
}
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async submitEnrollment() {
|
||||
if (!this.form.email || !this.form.first_name || !this.form.terms_accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.enrolling = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
const response = await apiClient.post('/storefront/loyalty/enroll', {
|
||||
customer_email: this.form.email,
|
||||
customer_name: [this.form.first_name, this.form.last_name].filter(Boolean).join(' '),
|
||||
customer_phone: this.form.phone || null,
|
||||
customer_birthday: this.form.birthday || null,
|
||||
marketing_email_consent: this.form.marketing_consent,
|
||||
marketing_sms_consent: this.form.marketing_consent
|
||||
});
|
||||
|
||||
if (response) {
|
||||
console.log('Enrollment successful:', response.card_number);
|
||||
// Redirect to success page - extract base path from current URL
|
||||
// Current page is at /storefront/loyalty/join, redirect to /storefront/loyalty/join/success
|
||||
const currentPath = window.location.pathname;
|
||||
const successUrl = currentPath.replace(/\/join\/?$/, '/join/success') +
|
||||
'?card=' + encodeURIComponent(response.card_number);
|
||||
window.location.href = successUrl;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Enrollment failed:', error);
|
||||
if (error.message?.includes('already')) {
|
||||
this.error = 'This email is already registered in our loyalty program.';
|
||||
} else {
|
||||
this.error = error.message || 'Enrollment failed. Please try again.';
|
||||
}
|
||||
} finally {
|
||||
this.enrolling = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
119
app/modules/loyalty/static/storefront/js/loyalty-history.js
Normal file
119
app/modules/loyalty/static/storefront/js/loyalty-history.js
Normal file
@@ -0,0 +1,119 @@
|
||||
// app/modules/loyalty/static/storefront/js/loyalty-history.js
|
||||
// Customer loyalty transaction history
|
||||
|
||||
function customerLoyaltyHistory() {
|
||||
return {
|
||||
...data(),
|
||||
|
||||
// Data
|
||||
card: null,
|
||||
transactions: [],
|
||||
|
||||
// Pagination
|
||||
pagination: {
|
||||
page: 1,
|
||||
per_page: 20,
|
||||
total: 0,
|
||||
pages: 0
|
||||
},
|
||||
|
||||
// State
|
||||
loading: false,
|
||||
|
||||
async init() {
|
||||
console.log('Customer loyalty history initializing...');
|
||||
await this.loadData();
|
||||
},
|
||||
|
||||
async loadData() {
|
||||
this.loading = true;
|
||||
try {
|
||||
await Promise.all([
|
||||
this.loadCard(),
|
||||
this.loadTransactions()
|
||||
]);
|
||||
} catch (error) {
|
||||
console.error('Failed to load history:', error);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async loadCard() {
|
||||
try {
|
||||
const response = await apiClient.get('/storefront/loyalty/card');
|
||||
if (response) {
|
||||
this.card = response.card;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to load card:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
async loadTransactions() {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append('skip', (this.pagination.page - 1) * this.pagination.per_page);
|
||||
params.append('limit', this.pagination.per_page);
|
||||
|
||||
const response = await apiClient.get(`/storefront/loyalty/transactions?${params}`);
|
||||
if (response) {
|
||||
this.transactions = response.transactions || [];
|
||||
this.pagination.total = response.total || 0;
|
||||
this.pagination.pages = Math.ceil(this.pagination.total / this.pagination.per_page);
|
||||
console.log(`Loaded ${this.transactions.length} transactions`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load transactions:', error);
|
||||
}
|
||||
},
|
||||
|
||||
previousPage() {
|
||||
if (this.pagination.page > 1) {
|
||||
this.pagination.page--;
|
||||
this.loadTransactions();
|
||||
}
|
||||
},
|
||||
|
||||
nextPage() {
|
||||
if (this.pagination.page < this.pagination.pages) {
|
||||
this.pagination.page++;
|
||||
this.loadTransactions();
|
||||
}
|
||||
},
|
||||
|
||||
getTransactionLabel(tx) {
|
||||
const type = tx.transaction_type || '';
|
||||
const labels = {
|
||||
'points_earned': 'Points Earned',
|
||||
'points_redeemed': 'Reward Redeemed',
|
||||
'points_voided': 'Points Voided',
|
||||
'welcome_bonus': 'Welcome Bonus',
|
||||
'points_expired': 'Points Expired',
|
||||
'stamp_earned': 'Stamp Earned',
|
||||
'stamp_redeemed': 'Stamp Redeemed'
|
||||
};
|
||||
return labels[type] || type.replace(/_/g, ' ');
|
||||
},
|
||||
|
||||
formatNumber(num) {
|
||||
if (num == null) return '0';
|
||||
return new Intl.NumberFormat('en-US').format(num);
|
||||
},
|
||||
|
||||
formatDateTime(dateString) {
|
||||
if (!dateString) return '-';
|
||||
try {
|
||||
return new Date(dateString).toLocaleString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
} catch (e) {
|
||||
return dateString;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
104
app/modules/loyalty/static/vendor/js/loyalty-card-detail.js
vendored
Normal file
104
app/modules/loyalty/static/vendor/js/loyalty-card-detail.js
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
// app/modules/loyalty/static/vendor/js/loyalty-card-detail.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
const loyaltyCardDetailLog = window.LogConfig.loggers.loyaltyCardDetail || window.LogConfig.createLogger('loyaltyCardDetail');
|
||||
|
||||
function vendorLoyaltyCardDetail() {
|
||||
return {
|
||||
...data(),
|
||||
currentPage: 'loyalty-card-detail',
|
||||
|
||||
cardId: null,
|
||||
card: null,
|
||||
transactions: [],
|
||||
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
async init() {
|
||||
loyaltyCardDetailLog.info('=== LOYALTY CARD DETAIL PAGE INITIALIZING ===');
|
||||
if (window._loyaltyCardDetailInitialized) return;
|
||||
window._loyaltyCardDetailInitialized = true;
|
||||
|
||||
// Extract card ID from URL
|
||||
const pathParts = window.location.pathname.split('/');
|
||||
const cardsIndex = pathParts.indexOf('cards');
|
||||
if (cardsIndex !== -1 && pathParts[cardsIndex + 1]) {
|
||||
this.cardId = parseInt(pathParts[cardsIndex + 1]);
|
||||
}
|
||||
|
||||
if (!this.cardId) {
|
||||
this.error = 'Invalid card ID';
|
||||
return;
|
||||
}
|
||||
|
||||
await this.loadData();
|
||||
loyaltyCardDetailLog.info('=== LOYALTY CARD DETAIL PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
async loadData() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
this.loadCard(),
|
||||
this.loadTransactions()
|
||||
]);
|
||||
} catch (error) {
|
||||
loyaltyCardDetailLog.error('Failed to load data:', error);
|
||||
this.error = error.message;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async loadCard() {
|
||||
const response = await apiClient.get(`/vendor/loyalty/cards/${this.cardId}`);
|
||||
if (response) {
|
||||
this.card = response;
|
||||
loyaltyCardDetailLog.info('Card loaded:', this.card.card_number);
|
||||
}
|
||||
},
|
||||
|
||||
async loadTransactions() {
|
||||
try {
|
||||
const response = await apiClient.get(`/vendor/loyalty/cards/${this.cardId}/transactions?limit=50`);
|
||||
if (response && response.transactions) {
|
||||
this.transactions = response.transactions;
|
||||
loyaltyCardDetailLog.info(`Loaded ${this.transactions.length} transactions`);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCardDetailLog.warn('Failed to load transactions:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
formatNumber(num) {
|
||||
return num == null ? '0' : new Intl.NumberFormat('en-US').format(num);
|
||||
},
|
||||
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return '-';
|
||||
try {
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
year: 'numeric', month: 'short', day: 'numeric'
|
||||
});
|
||||
} catch (e) { return dateString; }
|
||||
},
|
||||
|
||||
formatDateTime(dateString) {
|
||||
if (!dateString) return '-';
|
||||
try {
|
||||
return new Date(dateString).toLocaleString('en-US', {
|
||||
year: 'numeric', month: 'short', day: 'numeric',
|
||||
hour: '2-digit', minute: '2-digit'
|
||||
});
|
||||
} catch (e) { return dateString; }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!window.LogConfig.loggers.loyaltyCardDetail) {
|
||||
window.LogConfig.loggers.loyaltyCardDetail = window.LogConfig.createLogger('loyaltyCardDetail');
|
||||
}
|
||||
loyaltyCardDetailLog.info('Loyalty card detail module loaded');
|
||||
160
app/modules/loyalty/static/vendor/js/loyalty-cards.js
vendored
Normal file
160
app/modules/loyalty/static/vendor/js/loyalty-cards.js
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
// app/modules/loyalty/static/vendor/js/loyalty-cards.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
const loyaltyCardsLog = window.LogConfig.loggers.loyaltyCards || window.LogConfig.createLogger('loyaltyCards');
|
||||
|
||||
function vendorLoyaltyCards() {
|
||||
return {
|
||||
...data(),
|
||||
currentPage: 'loyalty-cards',
|
||||
|
||||
// Data
|
||||
cards: [],
|
||||
program: null,
|
||||
stats: {
|
||||
total_cards: 0,
|
||||
active_cards: 0,
|
||||
new_this_month: 0,
|
||||
total_points_balance: 0
|
||||
},
|
||||
|
||||
// Filters
|
||||
filters: {
|
||||
search: '',
|
||||
status: ''
|
||||
},
|
||||
|
||||
// Pagination
|
||||
pagination: {
|
||||
page: 1,
|
||||
per_page: 20,
|
||||
total: 0,
|
||||
pages: 0
|
||||
},
|
||||
|
||||
// State
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
async init() {
|
||||
loyaltyCardsLog.info('=== LOYALTY CARDS PAGE INITIALIZING ===');
|
||||
if (window._loyaltyCardsInitialized) return;
|
||||
window._loyaltyCardsInitialized = true;
|
||||
|
||||
if (window.PlatformSettings) {
|
||||
this.pagination.per_page = await window.PlatformSettings.getRowsPerPage();
|
||||
}
|
||||
|
||||
await this.loadData();
|
||||
loyaltyCardsLog.info('=== LOYALTY CARDS PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
async loadData() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
try {
|
||||
await Promise.all([
|
||||
this.loadProgram(),
|
||||
this.loadCards(),
|
||||
this.loadStats()
|
||||
]);
|
||||
} catch (error) {
|
||||
loyaltyCardsLog.error('Failed to load data:', error);
|
||||
this.error = error.message;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async loadProgram() {
|
||||
try {
|
||||
const response = await apiClient.get('/vendor/loyalty/program');
|
||||
if (response) this.program = response;
|
||||
} catch (error) {
|
||||
if (error.status !== 404) throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async loadCards() {
|
||||
const params = new URLSearchParams();
|
||||
params.append('skip', (this.pagination.page - 1) * this.pagination.per_page);
|
||||
params.append('limit', this.pagination.per_page);
|
||||
if (this.filters.search) params.append('search', this.filters.search);
|
||||
if (this.filters.status) params.append('is_active', this.filters.status === 'active');
|
||||
|
||||
const response = await apiClient.get(`/vendor/loyalty/cards?${params}`);
|
||||
if (response) {
|
||||
this.cards = response.cards || [];
|
||||
this.pagination.total = response.total || 0;
|
||||
this.pagination.pages = Math.ceil(this.pagination.total / this.pagination.per_page);
|
||||
}
|
||||
},
|
||||
|
||||
async loadStats() {
|
||||
try {
|
||||
const response = await apiClient.get('/vendor/loyalty/stats');
|
||||
if (response) {
|
||||
this.stats = {
|
||||
total_cards: response.total_cards || 0,
|
||||
active_cards: response.active_cards || 0,
|
||||
new_this_month: response.new_this_month || 0,
|
||||
total_points_balance: response.total_points_balance || 0
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyCardsLog.warn('Failed to load stats:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
debouncedSearch() {
|
||||
if (this._searchTimeout) clearTimeout(this._searchTimeout);
|
||||
this._searchTimeout = setTimeout(() => {
|
||||
this.pagination.page = 1;
|
||||
this.loadCards();
|
||||
}, 300);
|
||||
},
|
||||
|
||||
applyFilter() {
|
||||
this.pagination.page = 1;
|
||||
this.loadCards();
|
||||
},
|
||||
|
||||
get totalPages() { return this.pagination.pages; },
|
||||
get startIndex() { return this.pagination.total === 0 ? 0 : (this.pagination.page - 1) * this.pagination.per_page + 1; },
|
||||
get endIndex() { const end = this.pagination.page * this.pagination.per_page; return end > this.pagination.total ? this.pagination.total : end; },
|
||||
|
||||
get pageNumbers() {
|
||||
const pages = [];
|
||||
const total = this.totalPages;
|
||||
const current = this.pagination.page;
|
||||
if (total <= 7) { for (let i = 1; i <= total; i++) pages.push(i); }
|
||||
else {
|
||||
pages.push(1);
|
||||
if (current > 3) pages.push('...');
|
||||
const start = Math.max(2, current - 1);
|
||||
const end = Math.min(total - 1, current + 1);
|
||||
for (let i = start; i <= end; i++) pages.push(i);
|
||||
if (current < total - 2) pages.push('...');
|
||||
pages.push(total);
|
||||
}
|
||||
return pages;
|
||||
},
|
||||
|
||||
previousPage() { if (this.pagination.page > 1) { this.pagination.page--; this.loadCards(); } },
|
||||
nextPage() { if (this.pagination.page < this.totalPages) { this.pagination.page++; this.loadCards(); } },
|
||||
goToPage(num) { if (num !== '...' && num >= 1 && num <= this.totalPages) { this.pagination.page = num; this.loadCards(); } },
|
||||
|
||||
formatNumber(num) { return num == null ? '0' : new Intl.NumberFormat('en-US').format(num); },
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return 'Never';
|
||||
try {
|
||||
return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
||||
} catch (e) { return dateString; }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!window.LogConfig.loggers.loyaltyCards) {
|
||||
window.LogConfig.loggers.loyaltyCards = window.LogConfig.createLogger('loyaltyCards');
|
||||
}
|
||||
loyaltyCardsLog.info('Loyalty cards module loaded');
|
||||
101
app/modules/loyalty/static/vendor/js/loyalty-enroll.js
vendored
Normal file
101
app/modules/loyalty/static/vendor/js/loyalty-enroll.js
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
// app/modules/loyalty/static/vendor/js/loyalty-enroll.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
const loyaltyEnrollLog = window.LogConfig.loggers.loyaltyEnroll || window.LogConfig.createLogger('loyaltyEnroll');
|
||||
|
||||
function vendorLoyaltyEnroll() {
|
||||
return {
|
||||
...data(),
|
||||
currentPage: 'loyalty-enroll',
|
||||
|
||||
program: null,
|
||||
form: {
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
birthday: '',
|
||||
marketing_email: false,
|
||||
marketing_sms: false
|
||||
},
|
||||
|
||||
enrolling: false,
|
||||
enrolledCard: null,
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
async init() {
|
||||
loyaltyEnrollLog.info('=== LOYALTY ENROLL PAGE INITIALIZING ===');
|
||||
if (window._loyaltyEnrollInitialized) return;
|
||||
window._loyaltyEnrollInitialized = true;
|
||||
|
||||
await this.loadProgram();
|
||||
loyaltyEnrollLog.info('=== LOYALTY ENROLL PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
async loadProgram() {
|
||||
this.loading = true;
|
||||
try {
|
||||
const response = await apiClient.get('/vendor/loyalty/program');
|
||||
if (response) {
|
||||
this.program = response;
|
||||
loyaltyEnrollLog.info('Program loaded:', this.program.display_name);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
loyaltyEnrollLog.warn('No program configured');
|
||||
} else {
|
||||
this.error = error.message;
|
||||
}
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async enrollCustomer() {
|
||||
if (!this.form.first_name || !this.form.email) return;
|
||||
|
||||
this.enrolling = true;
|
||||
|
||||
try {
|
||||
loyaltyEnrollLog.info('Enrolling customer:', this.form.email);
|
||||
|
||||
const response = await apiClient.post('/vendor/loyalty/cards/enroll', {
|
||||
customer_email: this.form.email,
|
||||
customer_phone: this.form.phone || null,
|
||||
customer_name: [this.form.first_name, this.form.last_name].filter(Boolean).join(' '),
|
||||
customer_birthday: this.form.birthday || null,
|
||||
marketing_email_consent: this.form.marketing_email,
|
||||
marketing_sms_consent: this.form.marketing_sms
|
||||
});
|
||||
|
||||
if (response) {
|
||||
this.enrolledCard = response;
|
||||
loyaltyEnrollLog.info('Customer enrolled successfully:', response.card_number);
|
||||
}
|
||||
} catch (error) {
|
||||
Utils.showToast(`Enrollment failed: ${error.message}`, 'error');
|
||||
loyaltyEnrollLog.error('Enrollment failed:', error);
|
||||
} finally {
|
||||
this.enrolling = false;
|
||||
}
|
||||
},
|
||||
|
||||
resetForm() {
|
||||
this.form = {
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
birthday: '',
|
||||
marketing_email: false,
|
||||
marketing_sms: false
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!window.LogConfig.loggers.loyaltyEnroll) {
|
||||
window.LogConfig.loggers.loyaltyEnroll = window.LogConfig.createLogger('loyaltyEnroll');
|
||||
}
|
||||
loyaltyEnrollLog.info('Loyalty enroll module loaded');
|
||||
118
app/modules/loyalty/static/vendor/js/loyalty-settings.js
vendored
Normal file
118
app/modules/loyalty/static/vendor/js/loyalty-settings.js
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
// app/modules/loyalty/static/vendor/js/loyalty-settings.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
const loyaltySettingsLog = window.LogConfig.loggers.loyaltySettings || window.LogConfig.createLogger('loyaltySettings');
|
||||
|
||||
function vendorLoyaltySettings() {
|
||||
return {
|
||||
...data(),
|
||||
currentPage: 'loyalty-settings',
|
||||
|
||||
settings: {
|
||||
loyalty_type: 'points',
|
||||
points_per_euro: 1,
|
||||
welcome_bonus_points: 0,
|
||||
minimum_redemption_points: 100,
|
||||
points_expiration_days: null,
|
||||
points_rewards: [],
|
||||
card_name: '',
|
||||
card_color: '#4F46E5',
|
||||
is_active: true
|
||||
},
|
||||
|
||||
loading: false,
|
||||
saving: false,
|
||||
error: null,
|
||||
isNewProgram: false,
|
||||
|
||||
async init() {
|
||||
loyaltySettingsLog.info('=== LOYALTY SETTINGS PAGE INITIALIZING ===');
|
||||
if (window._loyaltySettingsInitialized) return;
|
||||
window._loyaltySettingsInitialized = true;
|
||||
|
||||
await this.loadSettings();
|
||||
loyaltySettingsLog.info('=== LOYALTY SETTINGS PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
async loadSettings() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get('/vendor/loyalty/program');
|
||||
if (response) {
|
||||
this.settings = {
|
||||
loyalty_type: response.loyalty_type || 'points',
|
||||
points_per_euro: response.points_per_euro || 1,
|
||||
welcome_bonus_points: response.welcome_bonus_points || 0,
|
||||
minimum_redemption_points: response.minimum_redemption_points || 100,
|
||||
points_expiration_days: response.points_expiration_days || null,
|
||||
points_rewards: response.points_rewards || [],
|
||||
card_name: response.card_name || '',
|
||||
card_color: response.card_color || '#4F46E5',
|
||||
is_active: response.is_active !== false
|
||||
};
|
||||
this.isNewProgram = false;
|
||||
loyaltySettingsLog.info('Settings loaded');
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
loyaltySettingsLog.info('No program found, creating new');
|
||||
this.isNewProgram = true;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async saveSettings() {
|
||||
this.saving = true;
|
||||
|
||||
try {
|
||||
// Ensure rewards have IDs
|
||||
this.settings.points_rewards = this.settings.points_rewards.map((r, i) => ({
|
||||
...r,
|
||||
id: r.id || `reward_${i + 1}`,
|
||||
is_active: r.is_active !== false
|
||||
}));
|
||||
|
||||
let response;
|
||||
if (this.isNewProgram) {
|
||||
response = await apiClient.post('/vendor/loyalty/program', this.settings);
|
||||
this.isNewProgram = false;
|
||||
} else {
|
||||
response = await apiClient.patch('/vendor/loyalty/program', this.settings);
|
||||
}
|
||||
|
||||
Utils.showToast('Settings saved successfully', 'success');
|
||||
loyaltySettingsLog.info('Settings saved');
|
||||
} catch (error) {
|
||||
Utils.showToast(`Failed to save: ${error.message}`, 'error');
|
||||
loyaltySettingsLog.error('Save failed:', error);
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
},
|
||||
|
||||
addReward() {
|
||||
this.settings.points_rewards.push({
|
||||
id: `reward_${Date.now()}`,
|
||||
name: '',
|
||||
points_required: 100,
|
||||
description: '',
|
||||
is_active: true
|
||||
});
|
||||
},
|
||||
|
||||
removeReward(index) {
|
||||
this.settings.points_rewards.splice(index, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!window.LogConfig.loggers.loyaltySettings) {
|
||||
window.LogConfig.loggers.loyaltySettings = window.LogConfig.createLogger('loyaltySettings');
|
||||
}
|
||||
loyaltySettingsLog.info('Loyalty settings module loaded');
|
||||
74
app/modules/loyalty/static/vendor/js/loyalty-stats.js
vendored
Normal file
74
app/modules/loyalty/static/vendor/js/loyalty-stats.js
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
// app/modules/loyalty/static/vendor/js/loyalty-stats.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
const loyaltyStatsLog = window.LogConfig.loggers.loyaltyStats || window.LogConfig.createLogger('loyaltyStats');
|
||||
|
||||
function vendorLoyaltyStats() {
|
||||
return {
|
||||
...data(),
|
||||
currentPage: 'loyalty-stats',
|
||||
|
||||
stats: {
|
||||
total_cards: 0,
|
||||
active_cards: 0,
|
||||
new_this_month: 0,
|
||||
total_points_issued: 0,
|
||||
total_points_redeemed: 0,
|
||||
total_points_balance: 0,
|
||||
points_issued_30d: 0,
|
||||
points_redeemed_30d: 0,
|
||||
transactions_30d: 0,
|
||||
avg_points_per_member: 0
|
||||
},
|
||||
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
async init() {
|
||||
loyaltyStatsLog.info('=== LOYALTY STATS PAGE INITIALIZING ===');
|
||||
if (window._loyaltyStatsInitialized) return;
|
||||
window._loyaltyStatsInitialized = true;
|
||||
|
||||
await this.loadStats();
|
||||
loyaltyStatsLog.info('=== LOYALTY STATS PAGE INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
async loadStats() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get('/vendor/loyalty/stats');
|
||||
if (response) {
|
||||
this.stats = {
|
||||
total_cards: response.total_cards || 0,
|
||||
active_cards: response.active_cards || 0,
|
||||
new_this_month: response.new_this_month || 0,
|
||||
total_points_issued: response.total_points_issued || 0,
|
||||
total_points_redeemed: response.total_points_redeemed || 0,
|
||||
total_points_balance: response.total_points_balance || 0,
|
||||
points_issued_30d: response.points_issued_30d || 0,
|
||||
points_redeemed_30d: response.points_redeemed_30d || 0,
|
||||
transactions_30d: response.transactions_30d || 0,
|
||||
avg_points_per_member: response.avg_points_per_member || 0
|
||||
};
|
||||
loyaltyStatsLog.info('Stats loaded');
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyStatsLog.error('Failed to load stats:', error);
|
||||
this.error = error.message;
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
formatNumber(num) {
|
||||
return num == null ? '0' : new Intl.NumberFormat('en-US').format(num);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!window.LogConfig.loggers.loyaltyStats) {
|
||||
window.LogConfig.loggers.loyaltyStats = window.LogConfig.createLogger('loyaltyStats');
|
||||
}
|
||||
loyaltyStatsLog.info('Loyalty stats module loaded');
|
||||
286
app/modules/loyalty/static/vendor/js/loyalty-terminal.js
vendored
Normal file
286
app/modules/loyalty/static/vendor/js/loyalty-terminal.js
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
// app/modules/loyalty/static/vendor/js/loyalty-terminal.js
|
||||
// noqa: js-006 - async init pattern is safe, loadData has try/catch
|
||||
|
||||
// Use centralized logger
|
||||
const loyaltyTerminalLog = window.LogConfig.loggers.loyaltyTerminal || window.LogConfig.createLogger('loyaltyTerminal');
|
||||
|
||||
// ============================================
|
||||
// VENDOR LOYALTY TERMINAL FUNCTION
|
||||
// ============================================
|
||||
function vendorLoyaltyTerminal() {
|
||||
return {
|
||||
// Inherit base layout functionality
|
||||
...data(),
|
||||
|
||||
// Page identifier
|
||||
currentPage: 'loyalty-terminal',
|
||||
|
||||
// Program state
|
||||
program: null,
|
||||
availableRewards: [],
|
||||
|
||||
// Customer lookup
|
||||
searchQuery: '',
|
||||
lookingUp: false,
|
||||
selectedCard: null,
|
||||
|
||||
// Transaction inputs
|
||||
earnAmount: null,
|
||||
selectedReward: '',
|
||||
|
||||
// PIN entry
|
||||
showPinEntry: false,
|
||||
pinDigits: '',
|
||||
pendingAction: null, // 'earn' or 'redeem'
|
||||
processing: false,
|
||||
|
||||
// Recent transactions
|
||||
recentTransactions: [],
|
||||
|
||||
// State
|
||||
loading: false,
|
||||
error: null,
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
loyaltyTerminalLog.info('=== LOYALTY TERMINAL INITIALIZING ===');
|
||||
|
||||
// Prevent multiple initializations
|
||||
if (window._loyaltyTerminalInitialized) {
|
||||
loyaltyTerminalLog.warn('Loyalty terminal already initialized, skipping...');
|
||||
return;
|
||||
}
|
||||
window._loyaltyTerminalInitialized = true;
|
||||
|
||||
await this.loadData();
|
||||
|
||||
loyaltyTerminalLog.info('=== LOYALTY TERMINAL INITIALIZATION COMPLETE ===');
|
||||
},
|
||||
|
||||
// Load initial data
|
||||
async loadData() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
this.loadProgram(),
|
||||
this.loadRecentTransactions()
|
||||
]);
|
||||
} catch (error) {
|
||||
loyaltyTerminalLog.error('Failed to load data:', error);
|
||||
this.error = error.message || 'Failed to load terminal';
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Load program info
|
||||
async loadProgram() {
|
||||
try {
|
||||
loyaltyTerminalLog.info('Loading program info...');
|
||||
const response = await apiClient.get('/vendor/loyalty/program');
|
||||
|
||||
if (response) {
|
||||
this.program = response;
|
||||
this.availableRewards = response.points_rewards || [];
|
||||
loyaltyTerminalLog.info('Program loaded:', this.program.display_name);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
loyaltyTerminalLog.info('No program configured');
|
||||
this.program = null;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Load recent transactions
|
||||
async loadRecentTransactions() {
|
||||
try {
|
||||
loyaltyTerminalLog.info('Loading recent transactions...');
|
||||
const response = await apiClient.get('/vendor/loyalty/transactions?limit=10');
|
||||
|
||||
if (response && response.transactions) {
|
||||
this.recentTransactions = response.transactions;
|
||||
loyaltyTerminalLog.info(`Loaded ${this.recentTransactions.length} transactions`);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyTerminalLog.warn('Failed to load transactions:', error.message);
|
||||
// Don't throw - transactions are optional
|
||||
}
|
||||
},
|
||||
|
||||
// Look up customer
|
||||
async lookupCustomer() {
|
||||
if (!this.searchQuery) return;
|
||||
|
||||
this.lookingUp = true;
|
||||
this.selectedCard = null;
|
||||
|
||||
try {
|
||||
loyaltyTerminalLog.info('Looking up customer:', this.searchQuery);
|
||||
const response = await apiClient.get(`/vendor/loyalty/cards/lookup?q=${encodeURIComponent(this.searchQuery)}`);
|
||||
|
||||
if (response) {
|
||||
this.selectedCard = response;
|
||||
loyaltyTerminalLog.info('Customer found:', this.selectedCard.customer_name);
|
||||
this.searchQuery = '';
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
Utils.showToast('Customer not found. You can enroll them as a new member.', 'warning');
|
||||
} else {
|
||||
Utils.showToast(`Error looking up customer: ${error.message}`, 'error');
|
||||
}
|
||||
loyaltyTerminalLog.error('Lookup failed:', error);
|
||||
} finally {
|
||||
this.lookingUp = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Clear selected customer
|
||||
clearCustomer() {
|
||||
this.selectedCard = null;
|
||||
this.earnAmount = null;
|
||||
this.selectedReward = '';
|
||||
},
|
||||
|
||||
// Get selected reward points
|
||||
getSelectedRewardPoints() {
|
||||
if (!this.selectedReward) return 0;
|
||||
const reward = this.availableRewards.find(r => r.id === this.selectedReward);
|
||||
return reward ? reward.points_required : 0;
|
||||
},
|
||||
|
||||
// Show PIN modal
|
||||
showPinModal(action) {
|
||||
this.pendingAction = action;
|
||||
this.pinDigits = '';
|
||||
this.showPinEntry = true;
|
||||
},
|
||||
|
||||
// PIN entry methods
|
||||
addPinDigit(digit) {
|
||||
if (this.pinDigits.length < 4) {
|
||||
this.pinDigits += digit.toString();
|
||||
}
|
||||
},
|
||||
|
||||
removePinDigit() {
|
||||
this.pinDigits = this.pinDigits.slice(0, -1);
|
||||
},
|
||||
|
||||
cancelPinEntry() {
|
||||
this.showPinEntry = false;
|
||||
this.pinDigits = '';
|
||||
this.pendingAction = null;
|
||||
},
|
||||
|
||||
// Submit transaction
|
||||
async submitTransaction() {
|
||||
if (this.pinDigits.length !== 4) return;
|
||||
|
||||
this.processing = true;
|
||||
|
||||
try {
|
||||
if (this.pendingAction === 'earn') {
|
||||
await this.earnPoints();
|
||||
} else if (this.pendingAction === 'redeem') {
|
||||
await this.redeemReward();
|
||||
}
|
||||
|
||||
// Close modal and refresh
|
||||
this.showPinEntry = false;
|
||||
this.pinDigits = '';
|
||||
this.pendingAction = null;
|
||||
|
||||
// Refresh customer card and transactions
|
||||
if (this.selectedCard) {
|
||||
await this.refreshCard();
|
||||
}
|
||||
await this.loadRecentTransactions();
|
||||
|
||||
} catch (error) {
|
||||
Utils.showToast(`Transaction failed: ${error.message}`, 'error');
|
||||
loyaltyTerminalLog.error('Transaction failed:', error);
|
||||
} finally {
|
||||
this.processing = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Earn points
|
||||
async earnPoints() {
|
||||
loyaltyTerminalLog.info('Earning points...', { amount: this.earnAmount });
|
||||
|
||||
const response = await apiClient.post('/vendor/loyalty/points/earn', {
|
||||
card_id: this.selectedCard.id,
|
||||
purchase_amount_cents: Math.round(this.earnAmount * 100),
|
||||
staff_pin: this.pinDigits
|
||||
});
|
||||
|
||||
const pointsEarned = response.points_earned || Math.floor(this.earnAmount * (this.program?.points_per_euro || 1));
|
||||
Utils.showToast(`${pointsEarned} points awarded!`, 'success');
|
||||
|
||||
this.earnAmount = null;
|
||||
},
|
||||
|
||||
// Redeem reward
|
||||
async redeemReward() {
|
||||
const reward = this.availableRewards.find(r => r.id === this.selectedReward);
|
||||
if (!reward) return;
|
||||
|
||||
loyaltyTerminalLog.info('Redeeming reward...', { reward: reward.name });
|
||||
|
||||
await apiClient.post('/vendor/loyalty/points/redeem', {
|
||||
card_id: this.selectedCard.id,
|
||||
reward_id: this.selectedReward,
|
||||
staff_pin: this.pinDigits
|
||||
});
|
||||
|
||||
Utils.showToast(`Reward redeemed: ${reward.name}`, 'success');
|
||||
|
||||
this.selectedReward = '';
|
||||
},
|
||||
|
||||
// Refresh card data
|
||||
async refreshCard() {
|
||||
try {
|
||||
const response = await apiClient.get(`/vendor/loyalty/cards/${this.selectedCard.id}`);
|
||||
if (response) {
|
||||
this.selectedCard = response;
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyTerminalLog.warn('Failed to refresh card:', error.message);
|
||||
}
|
||||
},
|
||||
|
||||
// Format number
|
||||
formatNumber(num) {
|
||||
if (num === null || num === undefined) return '0';
|
||||
return new Intl.NumberFormat('en-US').format(num);
|
||||
},
|
||||
|
||||
// Format time
|
||||
formatTime(dateString) {
|
||||
if (!dateString) return '-';
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleTimeString('en-US', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
} catch (e) {
|
||||
return dateString;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Register logger
|
||||
if (!window.LogConfig.loggers.loyaltyTerminal) {
|
||||
window.LogConfig.loggers.loyaltyTerminal = window.LogConfig.createLogger('loyaltyTerminal');
|
||||
}
|
||||
|
||||
loyaltyTerminalLog.info('Loyalty terminal module loaded');
|
||||
Reference in New Issue
Block a user