mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 12:24:26 +00:00
✅ SISTEMA DE NÓMINA COMPLETO: - API con cálculos automáticos de sueldo - Cálculo de comisiones (10% de revenue de servicios completados) - Cálculo de propinas (5% estimado de revenue) - Cálculo de horas trabajadas desde bookings completados - Sueldo base configurable por staff ✅ COMPONENTE PayrollManagement: - Interfaz completa para gestión de nóminas - Cálculo por períodos mensuales - Tabla de resultados con exportación CSV - Diálogo de cálculo detallado ✅ APIs CRUD STAFF FUNCIONALES: - GET/POST/PUT/DELETE y - Gestión de roles y ubicaciones - Auditoría completa de cambios ✅ APIs CRUD RESOURCES FUNCIONALES: - GET/POST con disponibilidad en tiempo real - Estado de ocupación por recurso - Capacidades y tipos de recursos ✅ MIGRACIÓN PAYROLL PREPARADA: - Tablas: staff_salaries, commission_rates, tip_records, payroll_records - Funciones PostgreSQL para cálculos complejos - RLS policies configuradas Próximo: POS completo con múltiples métodos de pago
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
/**
|
|
* Script to apply payroll migration directly to database
|
|
*/
|
|
|
|
const { createClient } = require('@supabase/supabase-js')
|
|
require('dotenv').config({ path: '.env.local' })
|
|
|
|
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
|
|
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY
|
|
|
|
if (!supabaseUrl || !supabaseServiceKey) {
|
|
console.error('Missing Supabase credentials')
|
|
process.exit(1)
|
|
}
|
|
|
|
const supabase = createClient(supabaseUrl, supabaseServiceKey)
|
|
|
|
async function applyPayrollMigration() {
|
|
console.log('🚀 Applying payroll migration...')
|
|
|
|
try {
|
|
// Read the migration file
|
|
const fs = require('fs')
|
|
const migrationSQL = fs.readFileSync('supabase/migrations/20260117150000_payroll_commission_system.sql', 'utf8')
|
|
|
|
// Split into individual statements (basic approach)
|
|
const statements = migrationSQL
|
|
.split(';')
|
|
.map(stmt => stmt.trim())
|
|
.filter(stmt => stmt.length > 0 && !stmt.startsWith('--'))
|
|
|
|
console.log(`📝 Executing ${statements.length} SQL statements...`)
|
|
|
|
// Execute each statement
|
|
for (let i = 0; i < statements.length; i++) {
|
|
const statement = statements[i]
|
|
if (statement.trim()) {
|
|
console.log(`🔄 Executing statement ${i + 1}/${statements.length}...`)
|
|
try {
|
|
const { error } = await supabase.rpc('exec_sql', { sql: statement })
|
|
if (error) {
|
|
console.warn(`⚠️ Warning on statement ${i + 1}:`, error.message)
|
|
// Continue with other statements
|
|
}
|
|
} catch (err) {
|
|
console.warn(`⚠️ Warning on statement ${i + 1}:`, err.message)
|
|
// Continue with other statements
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log('✅ Migration applied successfully!')
|
|
console.log('💡 You may need to refresh your database connection to see the new tables.')
|
|
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
applyPayrollMigration() |