Promociones para cada subdivicion

This commit is contained in:
Juan Pablo Vial
2025-04-03 16:32:40 -03:00
parent b5d6d0acb9
commit 7b2df74e4d
19 changed files with 495 additions and 247 deletions

View File

@ -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 {}
}

View File

@ -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 {}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreatePromotionUnitTypes extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$this->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();
}
}

View File

@ -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']);

View File

@ -44,7 +44,7 @@
@push('page_scripts')
<script>
class ContractTable {
class ConnectionTable {
table
constructor(tab) {
const parent = document.querySelector(`.ui.tab.segment[data-tab="${tab}"]`)
@ -70,7 +70,7 @@
parent.appendChild(this.table)
}
static fromProjects(data) {
const table = new ContractTable('projects_table')
const table = new ConnectionTable('projects_table')
data.forEach(project => {
const row = document.createElement('tr')
row.innerHTML = [
@ -93,15 +93,15 @@
})
}
static fromBrokers(data) {
const table = new ContractTable('brokers_table')
data.forEach(contract => {
const table = new ConnectionTable('brokers_table')
data.forEach(broker => {
const row = document.createElement('tr')
row.innerHTML = [
`<td>${contract.project.descripcion}</td>`,
`<td>${contract.broker.name}</td>`,
`<td>Todos los Proyectos</td>`,
`<td>${broker.name}</td>`,
'<td colspan="3">Todas las Unidades</td>',
`<td class="right aligned">`,
`<button class="ui red icon button remove_button broker" data-id="${contract.id}">`,
`<button class="ui red icon button remove_button broker" data-id="${broker.rut}">`,
'<i class="plus icon"></i>',
'</button>',
`</td>`
@ -110,13 +110,13 @@
})
document.querySelectorAll('.remove_button.broker').forEach(button => {
button.addEventListener('click', () => {
const contract_id = button.dataset.id
promotion.remove().contract(contract_id)
const broker_rut = button.dataset.id
promotion.remove().broker(broker_rut)
})
})
}
static fromUnitTypes(data) {
const table = new ContractTable('unit-types_table')
const table = new ConnectionTable('unit-types_table')
data.forEach(unitType => {
const row = document.createElement('tr')
const tipo = unitType.unitType.descripcion
@ -141,7 +141,7 @@
})
}
static fromUnitLines(data) {
const table = new ContractTable('unit-lines_table')
const table = new ConnectionTable('unit-lines_table')
data.forEach(unitLine => {
const row = document.createElement('tr')
const tipo = unitLine.tipo_unidad.descripcion
@ -166,7 +166,7 @@
})
}
static fromUnits(data) {
const table = new ContractTable('units_table')
const table = new ConnectionTable('units_table')
data.forEach(unit => {
const row = document.createElement('tr')
const tipo = unit.proyecto_tipo_unidad.tipo_unidad.descripcion
@ -223,8 +223,8 @@
}
})
},
contract: contract_id => {
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/contract/${contract_id}`
broker: broker_rut => {
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/broker/${broker_rut}`
const method = 'delete'
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
if (json.success) {
@ -271,36 +271,36 @@
this.watch().add()
@if (count($promotion->projects()) > 0)
ContractTable.fromProjects({!! json_encode($promotion->projects()) !!})
ConnectionTable.fromProjects({!! json_encode($promotion->projects()) !!})
@else
ContractTable.fromProjects([])
ConnectionTable.fromProjects([])
@endif
@if (count($promotion->contracts()) > 0)
ContractTable.fromBrokers({!! json_encode(array_map(function($contract) {$arr = json_decode(json_encode($contract));$arr['project'] = $contract->project; $arr['broker'] = $contract->broker;},$promotion->contracts())) !!})
@if (count($promotion->brokers()) > 0)
ConnectionTable.fromBrokers({!! json_encode($promotion->brokers()) !!})
@else
ContractTable.fromBrokers([])
ConnectionTable.fromBrokers([])
@endif
@if (count($promotion->unitTypes()) > 0)
ContractTable.fromUnitTypes({!! json_encode($promotion->unitTypes()) !!})
ConnectionTable.fromUnitTypes({!! json_encode($promotion->unitTypes()) !!})
@else
ContractTable.fromUnitTypes([])
ConnectionTable.fromUnitTypes([])
@endif
@if (count($promotion->unitLines()) > 0)
ContractTable.fromUnitLines({!! json_encode($promotion->unitLines()) !!})
ConnectionTable.fromUnitLines({!! json_encode($promotion->unitLines()) !!})
@else
ContractTable.fromUnitLines([])
ConnectionTable.fromUnitLines([])
@endif
@if (count($promotion->units()) > 0)
ContractTable.fromUnits({!! json_encode($promotion->units()) !!})
ConnectionTable.fromUnits({!! json_encode($promotion->units()) !!})
@else
ContractTable.fromUnits([])
ConnectionTable.fromUnits([])
@endif
}
}
$(document).ready(() => {
promotion.setup({
menu: 'tables_tab_menu',
table: 'contracts',
table: 'connections',
button: {
add: 'add_button'
}

View File

@ -7,7 +7,7 @@
<input type="hidden" name="promotion_id" value="{{$promotion->id}}" />
<div class="field" id="type">
<label>Tipo</label>
@foreach (['Proyecto' => 'project', 'Operador' => 'operator', 'Tipo' => 'type', 'Línea' => 'line', 'Unidad' => 'unit'] as $type => $value)
@foreach (['Proyecto' => 'project', 'Operador' => 'broker', 'Tipo' => 'type', 'Línea' => 'line', 'Unidad' => 'unit'] as $type => $value)
<div class="ui radio checkbox type" data-tab="{{ $value }}">
<input type="radio" name="type" value="{{$value}}" @if ($value === 'project') checked="checked"@endif />
<label>{{$type}}</label>
@ -29,16 +29,16 @@
</div>
</div>
</div>
<div class="ui tab segment" data-tab="operator">
<div class="ui tab segment" data-tab="broker">
<div class="field">
<label>Operador</label>
<div class="ui search multiple selection dropdown" id="operator">
<input type="hidden" name="operator[]" />
<div class="ui search multiple selection dropdown" id="broker">
<input type="hidden" name="broker[]" />
<i class="dropdown icon"></i>
<div class="default text">Operador</div>
<div class="menu">
@foreach ($contracts as $contract)
<div class="item" data-value="{{$contract->id}}">{{$contract->broker->name}} - {{$contract->project->descripcion}}</div>
@foreach ($brokers as $broker)
<div class="item" data-value="{{$broker->rut}}">{{$broker->name}}</div>
@endforeach
</div>
</div>
@ -152,7 +152,7 @@
line: 'line',
unit_project: 'unit_project',
unit: 'unit',
operator: 'operator'
broker: 'broker'
}
this.modal = $(`#${this.ids.modal}`).modal({
onApprove: () => {