This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCadastroFeriadoTipoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cadastro_feriado_tipo', function (Blueprint $table) {
|
||||
|
||||
MigrationUtil::idWithoutIncrements($table);
|
||||
|
||||
$table->string('descricao', 100);
|
||||
|
||||
MigrationUtil::addCommonFields($table, ['staticData' => true]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cadastro_feriado_tipo');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCadastroFeriadoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cadastro_feriado', function (Blueprint $table) {
|
||||
|
||||
$table->id();
|
||||
$table->foreignId('tipo_id')->constrained('cadastro_feriado_tipo');
|
||||
$table->date('inicio')->nullable();
|
||||
$table->text('observacao', 500)->nullable();
|
||||
|
||||
MigrationUtil::addCommonFieldsWithSoftDeletes($table);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cadastro_feriado');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCadastroFeriadoModuloTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cadastro_feriado_modulo', function (Blueprint $table) {
|
||||
|
||||
$table->foreignId('feriado_id')->constrained('cadastro_feriado');
|
||||
$table->foreignId('modulo_id')->constrained('administracao_modulo');
|
||||
|
||||
MigrationUtil::addCommonFieldsWithSoftDeletes($table);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cadastro_feriado_modulo');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AlterDataOnCadastroFeriadoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('cadastro_feriado', function (Blueprint $table) {
|
||||
|
||||
$table->renameColumn('inicio', 'data');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('cadastro_feriado', function (Blueprint $table) {
|
||||
|
||||
$table->renameColumn('data', 'inicio');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddFieldsDiaMesAnoToCadastroFeriadoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('cadastro_feriado', function (Blueprint $table) {
|
||||
|
||||
$table->dropColumn('data');
|
||||
$table->string('ano', 10)->after('tipo_id')->nullable();
|
||||
$table->integer('mes')->after('ano')->nullable();
|
||||
$table->integer('dia')->after('mes')->nullable();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('cadastro_feriado', function (Blueprint $table) {
|
||||
|
||||
$table->date('data')->nullable();
|
||||
$table->dropColumn('ano');
|
||||
$table->dropColumn('mes');
|
||||
$table->dropColumn('dia');
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDataToCadastroFeriadoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('cadastro_feriado', function (Blueprint $table) {
|
||||
$table->date('data')->after('tipo_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('cadastro_feriado', function (Blueprint $table) {
|
||||
$table->dropColumn('data');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateDataToCadastroFeriadoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('cadastro_feriado')
|
||||
->update([
|
||||
'data' => DB::raw('CONCAT(ano, "-", mes, "-", dia)')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::table('cadastro_feriado')
|
||||
->update([
|
||||
'data' => null
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateAnoToCadastroFeriadoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$currentYear = Carbon::now()->year;
|
||||
|
||||
$feriadosSemAno = DB::table('cadastro_feriado')
|
||||
->whereNull('ano')
|
||||
->whereNotNull('mes')
|
||||
->whereNotNull('dia')
|
||||
->get();
|
||||
|
||||
foreach ($feriadosSemAno as $feriado) {
|
||||
|
||||
DB::table('cadastro_feriado')
|
||||
->where('id', $feriado->id)
|
||||
->update([
|
||||
'ano' => $currentYear,
|
||||
'data' => DB::raw('CONCAT(ano, "-", mes, "-", dia)')
|
||||
]);
|
||||
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$nextYear = $currentYear + $i;
|
||||
|
||||
$existingRecord = DB::table('cadastro_feriado')
|
||||
->where('ano', $nextYear)
|
||||
->where('mes', $feriado->mes)
|
||||
->where('dia', $feriado->dia)
|
||||
->exists();
|
||||
|
||||
if (!$existingRecord) {
|
||||
|
||||
$newFeriadoId = DB::table('cadastro_feriado')->insertGetId([
|
||||
'ano' => $nextYear,
|
||||
'mes' => $feriado->mes,
|
||||
'dia' => $feriado->dia,
|
||||
'tipo_id' => $feriado->tipo_id,
|
||||
'observacao' => $feriado->observacao,
|
||||
'data' => DB::raw("CONCAT($nextYear, '-', $feriado->mes, '-', $feriado->dia)")
|
||||
]);
|
||||
|
||||
$modulosAssociados = DB::table('cadastro_feriado_modulo')
|
||||
->where('feriado_id', $feriado->id)
|
||||
->get();
|
||||
|
||||
foreach ($modulosAssociados as $modulo) {
|
||||
DB::table('cadastro_feriado_modulo')->insert([
|
||||
'feriado_id' => $newFeriadoId,
|
||||
'modulo_id' => $modulo->modulo_id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$feriados = DB::table('cadastro_feriado')
|
||||
->whereNull('created_at')
|
||||
->get();
|
||||
|
||||
foreach ($feriados as $feriado) {
|
||||
|
||||
DB::table('cadastro_feriado_modulo')
|
||||
->where('feriado_id', $feriado->id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
DB::table('cadastro_feriado')
|
||||
->whereNull('created_at')
|
||||
->delete();
|
||||
|
||||
DB::table('cadastro_feriado')
|
||||
->update([
|
||||
'data' => null
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user