diff --git a/app/resources/database/migrations/20250317193111_alter_promotions_remove_price.php b/app/resources/database/migrations/20250317193111_alter_promotions_remove_price.php index 9da0da8..9d6b264 100644 --- a/app/resources/database/migrations/20250317193111_alter_promotions_remove_price.php +++ b/app/resources/database/migrations/20250317193111_alter_promotions_remove_price.php @@ -17,11 +17,15 @@ final class AlterPromotionsRemovePrice extends AbstractMigration * Remember to call "create()" or "update()" and NOT "save()" when working * with the Table class. */ - public function change(): void + public function up(): void { - $this->table('promotions') - ->dropForeignKey('price_id') - ->removeColumn('price_id') - ->update(); + if ($this->table('promotions')->hasColumn('price_id')) { + $this->table('promotions') + ->dropForeignKey('price_id') + ->removeColumn('price_id') + ->update(); + } } + + public function down(): void {} } diff --git a/app/resources/database/migrations/20250318204147_alter_promotions_null_dates.php b/app/resources/database/migrations/20250318204147_alter_promotions_null_dates.php index 9540573..83e0990 100644 --- a/app/resources/database/migrations/20250318204147_alter_promotions_null_dates.php +++ b/app/resources/database/migrations/20250318204147_alter_promotions_null_dates.php @@ -17,11 +17,12 @@ final class AlterPromotionsNullDates extends AbstractMigration * Remember to call "create()" or "update()" and NOT "save()" when working * with the Table class. */ - public function change(): void + public function up(): void { $this->table('promotions') ->changeColumn('end_date', 'date', ['null' => true]) ->changeColumn('valid_until', 'date', ['null' => true]) ->update(); } + public function down(): void {} } diff --git a/app/resources/database/migrations/20250317192659_create_promotion_contract.php b/app/resources/database/migrations/20250403175937_create_promotion_brokers.php similarity index 63% rename from app/resources/database/migrations/20250317192659_create_promotion_contract.php rename to app/resources/database/migrations/20250403175937_create_promotion_brokers.php index b427f43..bac0f0a 100644 --- a/app/resources/database/migrations/20250317192659_create_promotion_contract.php +++ b/app/resources/database/migrations/20250403175937_create_promotion_brokers.php @@ -4,7 +4,7 @@ declare(strict_types=1); use Phinx\Migration\AbstractMigration; -final class CreatePromotionContract extends AbstractMigration +final class CreatePromotionBrokers extends AbstractMigration { /** * Change Method. @@ -19,12 +19,11 @@ final class CreatePromotionContract extends AbstractMigration */ public function change(): void { - $this->table('promotion_contracts') + $this->table('promotion_brokers') ->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false]) - ->addColumn('contract_id', 'integer', ['signed' => false, 'null' => false]) - ->addColumn('created_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']) + ->addColumn('broker_rut', 'integer', ['signed' => false, 'null' => false]) ->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) - ->addForeignKey('contract_id', 'broker_contracts', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) + ->addForeignKey('broker_rut', 'brokers', 'rut', ['delete' => 'CASCADE', 'update' => 'CASCADE']) ->create(); } } diff --git a/app/resources/database/migrations/20250318233223_create_promotion_contract_units.php b/app/resources/database/migrations/20250403175950_create_promotion_unit_lines.php similarity index 54% rename from app/resources/database/migrations/20250318233223_create_promotion_contract_units.php rename to app/resources/database/migrations/20250403175950_create_promotion_unit_lines.php index a6c52c0..f653c89 100644 --- a/app/resources/database/migrations/20250318233223_create_promotion_contract_units.php +++ b/app/resources/database/migrations/20250403175950_create_promotion_unit_lines.php @@ -4,7 +4,7 @@ declare(strict_types=1); use Phinx\Migration\AbstractMigration; -final class CreatePromotionContractUnits extends AbstractMigration +final class CreatePromotionUnitLines extends AbstractMigration { /** * Change Method. @@ -19,13 +19,11 @@ final class CreatePromotionContractUnits extends AbstractMigration */ public function change(): void { - $this->table('promotion_contract_units') + $this->table('promotion_unit_lines') ->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false]) - ->addColumn('contract_id', 'integer', ['signed' => false, 'null' => false]) - ->addColumn('unit_id', 'integer', ['signed' => false, 'null' => false]) - ->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'cascade', 'update' => 'cascade']) - ->addForeignKey('contract_id', 'broker_contracts', 'id', ['delete' => 'cascade', 'update' => 'cascade']) - ->addForeignKey('unit_id', 'unidad', 'id', ['delete' => 'cascade', 'update' => 'cascade']) + ->addColumn('unit_line_id', 'integer', ['signed' => false, 'null' => false]) + ->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) + ->addForeignKey('unit_line_id', 'proyecto_tipo_unidad', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) ->create(); } } diff --git a/app/resources/database/migrations/20250403175954_create_promotion_unit_types.php b/app/resources/database/migrations/20250403175954_create_promotion_unit_types.php new file mode 100644 index 0000000..e9f3f4c --- /dev/null +++ b/app/resources/database/migrations/20250403175954_create_promotion_unit_types.php @@ -0,0 +1,31 @@ +table('promotion_unit_types') + ->addColumn('promotion_id', 'integer', ['signed' => false, 'null' => false]) + ->addColumn('project_id', 'integer', ['signed' => false, 'null' => false]) + ->addColumn('unit_type_id', 'integer', ['signed' => false, 'null' => false]) + ->addForeignKey('promotion_id', 'promotions', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) + ->addForeignKey('project_id', 'proyecto', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) + ->addForeignKey('unit_type_id', 'tipo_unidad', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) + ->create(); + } +} diff --git a/app/resources/routes/api/ventas/promotions.php b/app/resources/routes/api/ventas/promotions.php index 14fdb1e..5cb3c8e 100644 --- a/app/resources/routes/api/ventas/promotions.php +++ b/app/resources/routes/api/ventas/promotions.php @@ -11,12 +11,12 @@ $app->group('/promotion/{promotion_id}', function($app) { $app->post('/add[/]', [Promotions::class, 'addConnections']); $app->group('/project/{project_id}', function($app) { $app->delete('[/]', [Promotions::class, 'removeProject']); + $app->group('/unit-type/{unit_type_id}', function($app) { + $app->delete('[/]', [Promotions::class, 'removeUnitType']); + }); }); - $app->group('/contract/{contract_id}', function($app) { - $app->delete('[/]', [Promotions::class, 'removeContract']); - }); - $app->group('/unit-type/{unit_type_id}', function($app) { - $app->delete('[/]', [Promotions::class, 'removeUnitType']); + $app->group('/broker/{broker_rut}', function($app) { + $app->delete('[/]', [Promotions::class, 'removeBroker']); }); $app->group('/unit-line/{unit_line_id}', function($app) { $app->delete('[/]', [Promotions::class, 'removeUnitLine']); diff --git a/app/resources/views/ventas/promotions/show.blade.php b/app/resources/views/ventas/promotions/show.blade.php index a21ef7d..9d4eb4d 100644 --- a/app/resources/views/ventas/promotions/show.blade.php +++ b/app/resources/views/ventas/promotions/show.blade.php @@ -44,7 +44,7 @@ @push('page_scripts')