File: /var/www/api_matriculas/database/seeders/PeriodPricingSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
class PeriodPricingSeeder extends Seeder
{
public function run()
{
$now = Carbon::now();
// Buscar el periodo 2026 (period_year = 2026)
$period = DB::table('periods')->where('period_year', 2026)->first();
if (!$period) {
$this->command->warn('⚠️ No se encontró un período con period_year=2026. Creando período...');
$periodId = DB::table('periods')->insertGetId([
'period' => 'Período 2026',
'period_year' => 2026,
'start_date' => '2026-01-01',
'end_date' => '2026-12-31',
'status' => 1,
'created_at' => $now,
'updated_at' => $now,
]);
} else {
$periodId = $period->id;
}
$configs = [];
// ================================================================
// CUOTA DE INCORPORACIÓN (UF) - por orden de hermano
// concept_code = 'CUOTA_INCORPORACION' (match payment_concept_details)
// ================================================================
$incorporation = [
1 => 93,
2 => 70,
3 => 35,
4 => 18,
5 => 0,
];
foreach ($incorporation as $siblingOrder => $price) {
$configs[] = [
'period_id' => $periodId,
'config_type' => 'incorporation',
'concept_code' => 'CUOTA_INCORPORACION',
'course_id' => null,
'sibling_order' => $siblingOrder,
'currency_type' => 'UF',
'price_regular' => $price,
'price_anticipated' => null,
'price_extended' => null,
'is_family_payment' => false,
'is_optional' => false,
'status' => true,
'created_at' => $now,
'updated_at' => $now,
];
}
// ================================================================
// MATRÍCULA ANUAL - 12.85 UF
// concept_code = 'ENROLLMENT' (match payment_concept_details)
// ================================================================
$configs[] = [
'period_id' => $periodId,
'config_type' => 'enrollment_fee',
'concept_code' => 'ENROLLMENT',
'course_id' => null,
'sibling_order' => null,
'currency_type' => 'UF',
'price_regular' => 12.85,
'price_anticipated' => null,
'price_extended' => null,
'is_family_payment' => false,
'is_optional' => false,
'status' => true,
'created_at' => $now,
'updated_at' => $now,
];
// ================================================================
// COBROS DE TERCEROS (opcionales)
// concept_codes matchean payment_concept_details
// ================================================================
$thirdParty = [
['code' => 'CLINICA_ALEMANA', 'price' => 36000, 'currency' => 'CLP', 'family' => false],
['code' => 'CENTRO_ALUMNOS', 'price' => 1000, 'currency' => 'CLP', 'family' => false],
['code' => 'SEGURO_VIDA_1_APODERADO_CUENTAS', 'price' => 2.5, 'currency' => 'UF', 'family' => false],
['code' => 'SEGURO_VIDA_2_APODERADO', 'price' => 2.5, 'currency' => 'UF', 'family' => false],
['code' => 'CENTRO_PADRES', 'price' => 35000, 'currency' => 'CLP', 'family' => true],
['code' => 'ALL_BRADS', 'price' => 10000, 'currency' => 'CLP', 'family' => true],
];
foreach ($thirdParty as $tp) {
$configs[] = [
'period_id' => $periodId,
'config_type' => 'third_party',
'concept_code' => $tp['code'],
'course_id' => null,
'sibling_order' => null,
'currency_type' => $tp['currency'],
'price_regular' => $tp['price'],
'price_anticipated' => null,
'price_extended' => null,
'is_family_payment' => $tp['family'],
'is_optional' => true,
'status' => true,
'created_at' => $now,
'updated_at' => $now,
];
}
// ================================================================
// COLEGIATURA ANUAL (UF) - por curso y orden de hermano (1-5)
// ================================================================
// Hermanos 1°, 2° y 3° comparten el mismo precio
// Hermano 4° tiene descuento 25%
// Hermano 5° en adelante tiene descuento 75%
//
// concept_code matchea payment_concept_details:
// COLEGIATURA_PG = Play Group
// COLEGIATURA_1 = Pre kínder y Kínder
// COLEGIATURA_2 = 1° a 6° Básico
// COLEGIATURA_3 = 7° Básico a IV Medio
// [concept_code, course_ids, tier_1_3, tier_4, tier_5]
// Cada tier = [regular, anticipado, extendido]
$tuitionGroups = [
// Play Group NO paga colegiatura
// Pre kínder y Kínder
[
'concept_code' => 'COLEGIATURA_1',
'course_ids' => [15, 16],
'tier_1_3' => [154.62, 151.5276, 157.72],
'tier_4' => [115.965, 113.6457, 118.29],
'tier_5' => [38.655, 37.8819, 39.43],
],
// 1° a 6° Básico
[
'concept_code' => 'COLEGIATURA_2',
'course_ids' => [2, 3, 4, 5, 6, 7],
'tier_1_3' => [182.74, 179.0852, 186.39],
'tier_4' => [137.055, 134.3139, 139.7925],
'tier_5' => [45.685, 44.7713, 46.5975],
],
// 7° Básico a IV Medio
[
'concept_code' => 'COLEGIATURA_3',
'course_ids' => [8, 9, 10, 11, 12, 13],
'tier_1_3' => [185.99, 182.2702, 189.71],
'tier_4' => [139.4925, 136.70265, 142.2825],
'tier_5' => [46.4975, 45.56755, 47.4275],
],
];
// Mapeo de sibling_order a tier
$siblingToTier = [
1 => 'tier_1_3',
2 => 'tier_1_3',
3 => 'tier_1_3',
4 => 'tier_4',
5 => 'tier_5',
];
foreach ($tuitionGroups as $group) {
foreach ($group['course_ids'] as $courseId) {
foreach ($siblingToTier as $siblingOrder => $tierKey) {
$prices = $group[$tierKey];
$configs[] = [
'period_id' => $periodId,
'config_type' => 'tuition',
'concept_code' => $group['concept_code'],
'course_id' => $courseId,
'sibling_order' => $siblingOrder,
'currency_type' => 'UF',
'price_regular' => $prices[0],
'price_anticipated' => $prices[1],
'price_extended' => $prices[2],
'is_family_payment' => false,
'is_optional' => false,
'status' => true,
'created_at' => $now,
'updated_at' => $now,
];
}
}
}
// Insertar todo con updateOrInsert para idempotencia
foreach ($configs as $config) {
DB::table('period_pricing_configs')->updateOrInsert(
[
'period_id' => $config['period_id'],
'config_type' => $config['config_type'],
'concept_code' => $config['concept_code'],
'course_id' => $config['course_id'],
'sibling_order' => $config['sibling_order'],
],
$config
);
}
$this->command->info('✅ Se han procesado ' . count($configs) . ' configuraciones de precios para período 2026.');
}
}