Conecciones de Promociones

This commit is contained in:
Juan Pablo Vial
2025-04-03 13:15:56 -03:00
parent ced673e452
commit 8a1e6a7761
17 changed files with 1144 additions and 79 deletions

View File

@ -81,6 +81,9 @@ class Insert extends Ideal\Query implements Define\Query\Insert
if ($value === (int) $value) { if ($value === (int) $value) {
return $value; return $value;
} }
if (str_starts_with($value, ':')) {
return $value;
}
return "'{$value}'"; return "'{$value}'";
}, $this->values)) . ')'; }, $this->values)) . ')';
} }

View File

@ -7,4 +7,22 @@ $app->group('/promotions', function($app) {
}); });
$app->group('/promotion/{promotion_id}', function($app) { $app->group('/promotion/{promotion_id}', function($app) {
$app->delete('/remove[/]', [Promotions::class, 'remove']); $app->delete('/remove[/]', [Promotions::class, 'remove']);
$app->group('/connections', function($app) {
$app->post('/add[/]', [Promotions::class, 'addConnections']);
$app->group('/project/{project_id}', function($app) {
$app->delete('[/]', [Promotions::class, 'removeProject']);
});
$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('/unit-line/{unit_line_id}', function($app) {
$app->delete('[/]', [Promotions::class, 'removeUnitLine']);
});
$app->group('/unit/{unit_id}', function($app) {
$app->delete('[/]', [Promotions::class, 'removeUnit']);
});
});
}); });

View File

@ -18,67 +18,293 @@
<p> <p>
{{ $promotion->startDate->format('d-m-Y') }} -> {!! $promotion->endDate?->format('d-m-Y') ?? '&infin;' !!} {{ $promotion->startDate->format('d-m-Y') }} -> {!! $promotion->endDate?->format('d-m-Y') ?? '&infin;' !!}
</p> </p>
<p>Válido hasta: {!! $promotion->validUntil?->format('d-m-Y') ?? '&infin;' !!}</p> <p>Válido hasta: {!! $promotion->validUntil?->format('d-m-Y') ?? '&empty;' !!}</p>
</div> </div>
</div> </div>
</div> </div>
<table class="ui table" id="contracts"> <div class="ui right aligned basic segment">
<thead> <button class="ui green tertiary icon button" id="add_button">
<tr>
<th>Proyecto</th>
<th>Operador</th>
<th class="center aligned" colspan="2">Unidad</th>
<th class="right aligned">
<button class="ui tertiary green icon button" id="add_button">
<i class="plus icon"></i> <i class="plus icon"></i>
</button> </button>
</th> </div>
</tr> <div class="ui top attached tabular menu" id="tables_tab_menu">
<tr> <div class="active item" data-tab="projects_table">Proyectos</div>
<th colspan="2"></th> <div class="item" data-tab="brokers_table">Operadores</div>
<th>Tipo</th> <div class="item" data-tab="unit-types_table">Tipos</div>
<th></th> <div class="item" data-tab="unit-lines_table">Líneas</div>
</tr> <div class="item" data-tab="units_table">Unidades</div>
</thead> </div>
<tbody> <div class="ui bottom attached tab fitted segment" data-tab="projects_table"></div>
<div class="ui bottom attached tab fitted segment" data-tab="brokers_table"></div>
<div class="ui bottom attached tab fitted segment" data-tab="unit-types_table"></div>
<div class="ui bottom attached tab fitted segment" data-tab="unit-lines_table"></div>
<div class="ui bottom attached tab fitted segment" data-tab="units_table"></div>
@include('ventas.promotions.show.add_modal')
@endsection
@push('page_scripts')
<script>
class ContractTable {
table
constructor(tab) {
const parent = document.querySelector(`.ui.tab.segment[data-tab="${tab}"]`)
this.table = document.createElement('table')
this.table.className = 'ui table'
this.table.innerHTML = [
'<thead>',
'<tr>',
'<th>Proyecto</th>',
'<th>Operador</th>',
'<th class="center aligned" colspan="3">Unidad</th>',
'</tr>',
'<tr>',
'<th colspan="2"></th>',
'<th>Tipo</th>',
'<th>Línea</th>',
'<th>#</th>',
'<th></th>',
'</tr>',
'</thead>',
'<tbody></tbody>'
].join("\n")
parent.appendChild(this.table)
}
static fromProjects(data) {
const table = new ContractTable('projects_table')
data.forEach(project => {
const row = document.createElement('tr')
row.innerHTML = [
`<td>${project.descripcion}</td>`,
'<td>Todos los Operadores</td>',
'<td colspan="3">Todas las Unidades</td>',
`<td class="right aligned">`,
`<button class="ui red icon button remove_button project" data-id="${project.id}">`,
'<i class="plus icon"></i>',
'</button>',
`</td>`
].join("\n")
table.table.querySelector('tbody').appendChild(row)
})
document.querySelectorAll('.remove_button.project').forEach(button => {
button.addEventListener('click', () => {
const project_id = button.dataset.id
promotion.remove().project(project_id)
})
})
}
static fromBrokers(data) {
const table = new ContractTable('brokers_table')
data.forEach(contract => {
const row = document.createElement('tr')
row.innerHTML = [
`<td>${contract.project.descripcion}</td>`,
`<td>${contract.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}">`,
'<i class="plus icon"></i>',
'</button>',
`</td>`
].join("\n")
table.table.querySelector('tbody').appendChild(row)
})
document.querySelectorAll('.remove_button.broker').forEach(button => {
button.addEventListener('click', () => {
const contract_id = button.dataset.id
promotion.remove().contract(contract_id)
})
})
}
static fromUnitTypes(data) {
const table = new ContractTable('unit-types_table')
data.forEach(unitType => {
const row = document.createElement('tr')
const tipo = unitType.unitType.descripcion
row.innerHTML = [
`<td>${unitType.project.descripcion}</td>`,
'<td>Todos los Operadores</td>',
`<td colspan="3">Todos l@s ${tipo.charAt(0).toUpperCase() + tipo.slice(1)}s</td>`,
`<td class="right aligned">`,
`<button class="ui red icon button remove_button unit-type" data-project="${unitType.project.id}" data-id="${unitType.unitType.id}">`,
'<i class="plus icon"></i>',
'</button>',
`</td>`
].join("\n")
table.table.querySelector('tbody').appendChild(row)
})
document.querySelectorAll('.remove_button.unit-type').forEach(button => {
button.addEventListener('click', () => {
const project_id = button.dataset.project
const unit_type_id = button.dataset.id
promotion.remove().unitType(project_id, unit_type_id)
})
})
}
static fromUnitLines(data) {
const table = new ContractTable('unit-lines_table')
data.forEach(unitLine => {
const row = document.createElement('tr')
const tipo = unitLine.tipo_unidad.descripcion
row.innerHTML = [
`<td>${unitLine.proyecto.descripcion}</td>`,
'<td>Todos los Operadores</td>',
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
`<td colspan="2">Todas las unidades de la línea ${unitLine.nombre} - ${unitLine.tipologia}</td>`,
`<td class="right aligned">`,
`<button class="ui red icon button remove_button unit-line" data-id="${unitLine.id}">`,
'<i class="plus icon"></i>',
'</button>',
`</td>`
].join("\n")
table.table.querySelector('tbody').appendChild(row)
})
document.querySelectorAll('.remove_button.unit-line').forEach(button => {
button.addEventListener('click', () => {
const unit_line_id = button.dataset.id
promotion.remove().unitLine(unit_line_id)
})
})
}
static fromUnits(data) {
const table = new ContractTable('units_table')
data.forEach(unit => {
const row = document.createElement('tr')
const tipo = unit.proyecto_tipo_unidad.tipo_unidad.descripcion
row.innerHTML = [
`<td>${unit.proyecto_tipo_unidad.proyecto.descripcion}</td>`,
`<td>Todos los Operadores</td>`,
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
`<td>${unit.proyecto_tipo_unidad.nombre} - ${unit.proyecto_tipo_unidad.tipologia}</td>`,
`<td>${unit.descripcion}</td>`,
`<td class="right aligned">`,
`<button class="ui red icon button remove_button unit" data-id="${unit.id}">`,
'<i class="plus icon"></i>',
'</button>',
`</td>`
].join("\n")
table.table.querySelector('tbody').appendChild(row)
})
document.querySelectorAll('.remove_button.unit').forEach(button => {
button.addEventListener('click', () => {
const unit_id = button.dataset.id
promotion.remove().unit(unit_id)
})
})
}
}
const promotion = {
ids: {
table: '',
button: {
add: ''
}
},
handlers: {
add: null
},
watch() {
return {
add: () => {
document.getElementById(promotion.ids.button.add).addEventListener('click', clickEvent => {
clickEvent.preventDefault()
promotion.handlers.add.show()
})
}
}
},
remove() {
return {
project: project_id => {
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/project/${project_id}`
const method = 'delete'
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
},
contract: contract_id => {
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/contract/${contract_id}`
const method = 'delete'
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
},
unitType: (project_id, unit_type_id) => {
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/unit-type/${project_id}/${unit_type_id}`
const method = 'delete'
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
},
unitLine: unit_line_id => {
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/unit-line/${unit_line_id}`
const method = 'delete'
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
},
unit: unit_id => {
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/unit/${unit_id}`
const method = 'delete'
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
}
}
},
execute() {},
setup(ids) {
this.ids = ids
this.handlers.add = new AddModal()
$(`#${this.ids.menu} .item`).tab()
this.watch().add()
@if (count($promotion->projects()) > 0) @if (count($promotion->projects()) > 0)
@foreach ($promotion->projects() as $project) ContractTable.fromProjects({!! json_encode($promotion->projects()) !!})
<tr> @else
<td>{{ $project->descripcion }}</td> ContractTable.fromProjects([])
<td>Todos los Operadores</td>
<td colspan="2">Todas las Unidades</td>
</tr>
@endforeach
@endif @endif
@if (count($promotion->contracts()) > 0) @if (count($promotion->contracts()) > 0)
@foreach($promotion->contracts() as $contract) ContractTable.fromBrokers({!! json_encode(array_map(function($contract) {$arr = json_decode(json_encode($contract));$arr['project'] = $contract->project; $arr['broker'] = $contract->broker;},$promotion->contracts())) !!})
<tr> @else
<td>{{ $contract->project->descripcion }}</td> ContractTable.fromBrokers([])
<td>{{ $contract->broker->name }}</td> @endif
<td colspan="2">Todas las Unidades</td> @if (count($promotion->unitTypes()) > 0)
</tr> ContractTable.fromUnitTypes({!! json_encode($promotion->unitTypes()) !!})
@endforeach @else
ContractTable.fromUnitTypes([])
@endif
@if (count($promotion->unitLines()) > 0)
ContractTable.fromUnitLines({!! json_encode($promotion->unitLines()) !!})
@else
ContractTable.fromUnitLines([])
@endif @endif
@if (count($promotion->units()) > 0) @if (count($promotion->units()) > 0)
@foreach($promotion->units() as $unit) ContractTable.fromUnits({!! json_encode($promotion->units()) !!})
<tr> @else
<td>{{ $unit->project->descripcion }}</td> ContractTable.fromUnits([])
<td>Todos los Operadores</td>
<td>{{ $unit->proyectoTipoUnidad->tipoUnidad->descripcion }}</td>
<td>{{ $unit->descripcion }}</td>
</tr>
@endforeach
@endif @endif
@if (count($promotion->contractUnits()) > 0) }
@foreach($promotion->contractUnits() as $contractUnit) }
<tr> $(document).ready(() => {
<td>{{ $contractUnit->contract->project->descripcion }}</td> promotion.setup({
<td>{{ $contractUnit->contract->broker->name }}</td> menu: 'tables_tab_menu',
<td>{{ $contractUnit->unidad->proyectoTipoUnidad->tipoUnidad->descripcion }}</td> table: 'contracts',
<td>{{ $contractUnit->unidad->descripcion }}</td> button: {
</tr> add: 'add_button'
@endforeach }
@endif })
</tbody> })
</table> </script>
@endsection @endpush

View File

@ -1,2 +1,288 @@
<div class="ui modal" id="add_connection_modal"> <div class="ui modal" id="add_connection_modal">
<div class="header">
Agregar
</div> </div>
<div class="content">
<form class="ui form" id="add_connection_form">
<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)
<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>
</div>
@endforeach
</div>
<div class="ui active tab segment" data-tab="project">
<div class="field">
<label>Proyecto</label>
<div class="ui search multiple selection dropdown" id="project">
<input type="hidden" name="project[]" />
<i class="dropdown icon"></i>
<div class="default text">Proyecto</div>
<div class="menu">
@foreach ($projects as $project)
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="ui tab segment" data-tab="operator">
<div class="field">
<label>Operador</label>
<div class="ui search multiple selection dropdown" id="operator">
<input type="hidden" name="operator[]" />
<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>
@endforeach
</div>
</div>
</div>
</div>
<div class="ui tab segment" data-tab="type">
<div class="fields">
<div class="six wide field">
<label>Proyecto</label>
<div class="ui search selection dropdown" id="type_project">
<input type="hidden" name="type_project" />
<i class="dropdown icon"></i>
<div class="default text">Proyecto</div>
<div class="menu">
@foreach ($projects as $project)
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="six wide field">
<label>Tipo</label>
<div class="ui search multiple selection dropdown" id="unit_type">
<input type="hidden" name="unit_type[]" />
<i class="dropdown icon"></i>
<div class="default text">Tipo</div>
<div class="menu"></div>
</div>
</div>
</div>
</div>
<div class="ui tab segment" data-tab="line">
<div class="fields">
<div class="six wide field">
<label>Proyecto</label>
<div class="ui search selection dropdown" id="line_project">
<input type="hidden" name="line_project" />
<i class="dropdown icon"></i>
<div class="default text">Proyecto</div>
<div class="menu">
@foreach ($projects as $project)
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="six wide field">
<label>Línea</label>
<div class="ui search multiple selection dropdown" id="line">
<input type="hidden" name="line[]" />
<i class="dropdown icon"></i>
<div class="default text">Línea</div>
<div class="menu"></div>
</div>
</div>
</div>
</div>
<div class="ui tab segment" data-tab="unit">
<div class="fields">
<div class="six wide field">
<label>Proyecto</label>
<div class="ui search selection dropdown" id="unit_project">
<input type="hidden" name="unit_project" />
<i class="dropdown icon"></i>
<div class="default text">Proyecto</div>
<div class="menu">
@foreach ($projects as $project)
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
@endforeach
</div>
</div>
</div>
<div class="six wide field">
<label>Unidad</label>
<div class="ui search multiple selection dropdown" id="unit">
<input type="hidden" name="unit[]" />
<i class="dropdown icon"></i>
<div class="default text">Unidad</div>
<div class="menu"></div>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="actions">
<div class="ui black deny button">
Cancelar
</div>
<div class="ui positive right labeled icon button">
Guardar
<i class="checkmark icon"></i>
</div>
</div>
</div>
@push('page_scripts')
<script>
class AddModal {
ids
modal
units = []
constructor() {
this.ids = {
form: 'add_connection_form',
modal: 'add_connection_modal',
radios: '#type .ui.radio.checkbox.type',
type_project: 'type_project',
unit_type: 'unit_type',
line_project: 'line_project',
line: 'line',
unit_project: 'unit_project',
unit: 'unit',
operator: 'operator'
}
this.modal = $(`#${this.ids.modal}`).modal({
onApprove: () => {
const form = document.getElementById(this.ids.form)
const body = new FormData(form)
const url = `{{$urls->api}}/ventas/promotion/{{$promotion->id}}/connections/add`
const method = 'post'
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
if (json.success) {
window.location.reload()
}
})
}
})
$(`#${this.ids.form} ${this.ids.radios}`).checkbox({
fireOnInit: true,
onChecked: () => {
$(`#${this.ids.form} ${this.ids.radios}`).each((index, radio) => {
if ($(radio).checkbox('is checked')) {
const tab = radio.dataset.tab
$.tab('change tab', tab)
}
})
}
})
$('.ui.dropdown').dropdown()
const typeProject = $(`#${this.ids.type_project}`)
typeProject.dropdown('clear', false)
typeProject.dropdown({
onChange: (value, text, $choice) => {
this.draw().types(value)
}
})
const lineProject = $(`#${this.ids.line_project}`)
lineProject.dropdown('clear', false)
lineProject.dropdown({
onChange: (value, text, $choice) => {
this.draw().lines(value)
}
})
const unitProject = $(`#${this.ids.unit_project}`)
unitProject.dropdown('clear', false)
unitProject.dropdown({
onChange: (value, text, $choice) => {
this.draw().units(value)
}
})
}
show() {
this.modal.modal('show')
}
draw() {
return {
types: project_id => {
this.load().units(project_id).then(() => {
const values = []
this.units[project_id].forEach(unit => {
const tipo = unit.proyecto_tipo_unidad.tipo_unidad
if (values.find(value => value.value === tipo.id)) return
const label = `${tipo.descripcion.charAt(0).toUpperCase() + tipo.descripcion.slice(1)}`
values.push( {
value: tipo.id,
text: label,
name: label
} )
})
$(`#${this.ids.unit_type}`).dropdown('change values', values)
})
},
lines: project_id => {
this.load().units(project_id).then(() => {
const values = []
this.units[project_id].forEach(unit => {
const tipo = unit.proyecto_tipo_unidad.tipo_unidad
const linea = unit.proyecto_tipo_unidad
if (values.find(value => value.value === linea.id)) return
let name = linea.nombre
if (!linea.nombre.includes(tipo.descripcion.charAt(0).toUpperCase() + tipo.descripcion.slice(1))) {
name = `${tipo.descripcion.charAt(0).toUpperCase() + tipo.descripcion.slice(1)} ${name}`
}
const label = `${name} - ${linea.tipologia}`
values.push( {
value: linea.id,
text: label,
name: label
} )
})
$(`#${this.ids.line}`).dropdown('change values', values)
})
},
units: project_id => {
this.load().units(project_id).then(() => {
const values = this.units[project_id].map(unit => {
const tipo = unit.proyecto_tipo_unidad.tipo_unidad.descripcion
const label = `${tipo.charAt(0).toUpperCase() + tipo.slice(1)} - ${unit.descripcion}`
return {
value: unit.id,
text: label,
name: label
}
})
$(`#${this.ids.unit}`).dropdown('change values', values)
})
}
}
}
load() {
return {
units: project_id => {
if (typeof this.units[project_id] !== 'undefined' && this.units[project_id].length > 0) {
return new Promise( resolve => resolve(this.units[project_id]) )
}
const url = `{{ $urls->api }}/proyecto/${project_id}/unidades`
return APIClient.fetch(url).then(response => response.json()).then(json => {
if (json.unidades.length === 0) {
throw new Error('No se encontraron unidades')
}
const units = []
Object.values(json.unidades).forEach(unidades => {
unidades.forEach(unit => {
units.push(unit)
})
})
this.units[project_id] = units
return units
})
}
}
}
}
</script>
@endpush

View File

@ -3,6 +3,7 @@ namespace Incoviba\Controller\API\Ventas;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Controller\API\withJson; use Incoviba\Controller\API\withJson;
use Incoviba\Exception\ServiceAction; use Incoviba\Exception\ServiceAction;
use Incoviba\Service; use Incoviba\Service;
@ -11,7 +12,8 @@ class Promotions
{ {
use withJson; use withJson;
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Promotion $promotionService): ResponseInterface public function add(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Promotion $promotionService): ResponseInterface
{ {
$input = $request->getParsedBody(); $input = $request->getParsedBody();
$output = [ $output = [
@ -43,7 +45,8 @@ class Promotions
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Promotion $promotionService): ResponseInterface public function edit(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Promotion $promotionService): ResponseInterface
{ {
$input = $request->getParsedBody(); $input = $request->getParsedBody();
$output = [ $output = [
@ -77,7 +80,8 @@ class Promotions
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function remove(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Promotion $promotionService, int $promotion_id): ResponseInterface public function remove(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Promotion $promotionService, int $promotion_id): ResponseInterface
{ {
$output = [ $output = [
'promotion_id' => $promotion_id, 'promotion_id' => $promotion_id,
@ -94,4 +98,122 @@ class Promotions
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function addConnections(ServerRequestInterface $request, ResponseInterface $response,
LoggerInterface $logger,
Service\Venta\Promotion $promotionService, int $promotion_id): ResponseInterface
{
$input = $request->getParsedBody();
$output = [
'promotion_id' => $promotion_id,
'input' => $input,
'connections' => [],
'success' => false,
'partial' => false
];
$total = 0;
if (count($input['project']) > 0 and $input['project'][0] !== '') {
$project_ids = array_filter($input['project'], function($project_id) { return $project_id !== ''; });
$total += count($project_ids);
foreach ($project_ids as $project_id) {
try {
$promotionService->addProject($promotion_id, $project_id);
$output['connections'] []= [
'project_id' => $project_id,
'success' => true,
];
$output['partial'] = true;
} catch (ServiceAction\Create $exception) {
$logger->error($exception);
}
}
}
if (count($input['operator']) > 0 and $input['operator'][0] !== '') {
$contract_ids = array_filter($input['operator'], function($operator_id) { return $operator_id !== ''; });
$total += count($contract_ids);
foreach ($contract_ids as $contract_id) {
try {
$promotionService->addContract($promotion_id, $contract_id);
$output['connections'] []= [
'operator_id' => $contract_id,
'success' => true,
];
$output['partial'] = true;
} catch (ServiceAction\Create $exception) {
$logger->error($exception);
}
}
}
if (count($input['unit_type']) > 0 and $input['unit_type'][0] !== '') {
$unit_type_ids = array_filter($input['unit_type'], function($unit_type_id) { return $unit_type_id !== ''; });
$total += count($unit_type_ids);
foreach ($unit_type_ids as $unit_type_id) {
try {
$promotionService->addUnitType($promotion_id, $input['type_project'], $unit_type_id);
$output['connections'] []= [
'unit_type_id' => $unit_type_id,
'success' => true,
];
$output['partial'] = true;
} catch (ServiceAction\Create $exception) {
$logger->error($exception);
}
}
}
if (count($input['line']) > 0 and $input['line'][0] !== '') {
$line_ids = array_filter($input['line'], function($line_id) { return $line_id !== ''; });
$total += count($line_ids);
foreach ($line_ids as $line_id) {
try {
$promotionService->addUnitLine($promotion_id, $line_id);
$output['connections'] []= [
'line_id' => $line_id,
'success' => true,
];
$output['partial'] = true;
} catch (ServiceAction\Create $exception) {
$logger->error($exception);
}
}
}
if (count($input['unit']) > 0 and $input['unit'][0] !== '') {
$unit_ids = array_filter($input['unit'], function($unit_id) { return $unit_id !== ''; });
$total += count($unit_ids);
foreach ($unit_ids as $unit_id) {
try {
$promotionService->addUnit($promotion_id, $unit_id);
$output['connections'] []= [
'unit_id' => $unit_id,
'success' => true,
];
$output['partial'] = true;
} catch (ServiceAction\Create $exception) {
$logger->error($exception);
}
}
}
if (count($output['connections']) === $total) {
$output['success'] = true;
}
return $this->withJson($response, $output);
}
public function removeProject(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\Promotion $promotionService,
int $promotion_id, int $project_id): ResponseInterface
{
$output = [
'promotion_id' => $promotion_id,
'project_id' => $project_id,
'connection' => null,
'success' => false,
];
try {
$output['connection'] = $promotionService->removeProject($promotion_id, $project_id);
$output['success'] = true;
} catch (ServiceAction\Delete $exception) {
return $this->withError($response, $exception);
}
return $this->withJson($response, $output);
}
} }

View File

@ -18,12 +18,18 @@ class Promotions extends Ideal\Controller
return $view->render($response, 'ventas.promotions', ['promotions' => $promotions]); return $view->render($response, 'ventas.promotions', ['promotions' => $promotions]);
} }
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta\Promotion $promotionService, int $promotion_id): ResponseInterface Service\Venta\Promotion $promotionService, Service\Proyecto $proyectoService,
Service\Proyecto\Broker $brokerService, Service\Proyecto\Broker\Contract $contractService,
int $promotion_id): ResponseInterface
{ {
$promotion = null; $promotion = null;
try { try {
$promotion = $promotionService->getById($promotion_id); $promotion = $promotionService->getById($promotion_id);
} catch (ServiceAction\Read) {} } catch (ServiceAction\Read) {}
return $view->render($response, 'ventas.promotions.show', ['promotion' => $promotion]); $projects = $proyectoService->getVendibles('descripcion');
$contracts = $contractService->getAll();
$brokers = $brokerService->getAll('name');
return $view->render($response, 'ventas.promotions.show', ['promotion' => $promotion,
'projects' => $projects, 'contracts' => $contracts, 'brokers' => $brokers]);
} }
} }

View File

@ -0,0 +1,22 @@
<?php
namespace Incoviba\Exception;
use Exception;
use Throwable;
class AggregateException extends Exception
{
public function __construct(array $exceptions, ?Throwable $previous = null)
{
$code = count($exceptions);
$temp_arr = array_reverse($exceptions);
$current = array_shift($temp_arr);
$current->previous = $previous;
foreach ($temp_arr as $exception) {
$exception->previous = $current;
$current = $exception;
}
$message = "Aggregate Exception";
parent::__construct($message, $code, $current);
}
}

View File

@ -43,6 +43,15 @@ class ProyectoTipoUnidad extends Ideal\Model
return $this->abreviacion; return $this->abreviacion;
} }
protected array $unidades;
public function unidades(): array
{
if (!isset($this->unidades)) {
$this->unidades = $this->runFactory('unidades');
}
return $this->unidades;
}
public function jsonSerialize(): mixed public function jsonSerialize(): mixed
{ {
return array_merge(parent::jsonSerialize(), [ return array_merge(parent::jsonSerialize(), [

View File

@ -21,7 +21,7 @@ class Promotion extends Common\Ideal\Model
public function projects(): array public function projects(): array
{ {
if (empty($this->projects)) { if (empty($this->projects)) {
$this->projects = $this->runFactory('projects'); $this->projects = $this->runFactory('projects') ?? [];
} }
return $this->projects; return $this->projects;
} }
@ -30,16 +30,33 @@ class Promotion extends Common\Ideal\Model
public function contracts(): array public function contracts(): array
{ {
if (empty($this->contracts)) { if (empty($this->contracts)) {
$this->contracts = $this->runFactory('contracts'); $this->contracts = $this->runFactory('contracts') ?? [];
} }
return $this->contracts; return $this->contracts;
} }
protected array $unitTypes;
public function unitTypes(): array
{
if (empty($this->unitTypes)) {
$this->unitTypes = $this->runFactory('unitTypes') ?? [];
}
return $this->unitTypes;
}
protected array $unitLines;
public function unitLines(): array
{
if (empty($this->unitLines)) {
$this->unitLines = $this->runFactory('unitLines') ?? [];
}
return $this->unitLines;
}
protected array $units; protected array $units;
public function units(): array public function units(): array
{ {
if (empty($this->units)) { if (empty($this->units)) {
$this->units = $this->runFactory('units'); $this->units = $this->runFactory('units') ?? [];
} }
return $this->units; return $this->units;
} }

View File

@ -94,7 +94,7 @@ class Proyecto extends Ideal\Repository
->where("a.descripcion LIKE ?"); ->where("a.descripcion LIKE ?");
return $this->fetchOne($query, ["%{$name}%"]); return $this->fetchOne($query, ["%{$name}%"]);
} }
public function fetchAllActive(): array public function fetchAllActive(null|string|array $orderBy = null): array
{ {
$etapaProyecto = $this->etapaRepository->fetchByDescripcion('Proyecto'); $etapaProyecto = $this->etapaRepository->fetchByDescripcion('Proyecto');
$etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado'); $etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
@ -103,8 +103,12 @@ class Proyecto extends Ideal\Repository
->from("{$this->getTable()} a") ->from("{$this->getTable()} a")
->joined($this->joinTerreno()) ->joined($this->joinTerreno())
->joined($this->joinEstado()) ->joined($this->joinEstado())
->where("et.orden BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)") ->where("et.orden BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)");
->order('a.descripcion'); if ($orderBy === null) {
$query = $query->order('a.descripcion');
} else {
$query = $query->order($orderBy);
}
return $this->fetchMany($query); return $this->fetchMany($query);
} }
public function fetchAllEscriturando(): array public function fetchAllEscriturando(): array
@ -175,8 +179,14 @@ class Proyecto extends Ideal\Repository
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()
->select('a.*') ->select('a.*')
->from("{$this->getTable()} a") ->from("{$this->getTable()} a")
->joined('INNER JOIN promotion_projects pp ON pp.project_id = a.id') ->joined('LEFT OUTER JOIN proyecto_tipo_unidad ptu ON ptu.proyecto = a.id')
->where('pp.promotion_id = :promotion_id'); ->joined('LEFT OUTER JOIN unidad ON unidad.pt = ptu.id')
->joined('LEFT OUTER JOIN promotion_units pu ON pu.unit_id = unidad.id')
->joined('LEFT OUTER JOIN broker_contracts bc ON bc.project_id = a.id')
->joined('LEFT OUTER JOIN promotion_contracts pc ON pc.contract_id = bc.id')
->where('pu.promotion_id = :promotion_id OR pc.promotion_id = :promotion_id')
->group('a.id');
trigger_error($query . ' ' . json_encode(['promotion_id' => $promotion_id]));
return $this->fetchMany($query, ['promotion_id' => $promotion_id]); return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
} }
/*public function fetchSuperficieVendido(int $proyecto_id): float /*public function fetchSuperficieVendido(int $proyecto_id): float

View File

@ -43,4 +43,21 @@ class ProyectoTipoUnidad extends Ideal\Repository
{ {
return $this->update($model, ['proyecto', 'tipo', 'nombre', 'abreviacion', 'util', 'logia', 'terraza', 'descripcion'], $new_data); return $this->update($model, ['proyecto', 'tipo', 'nombre', 'abreviacion', 'util', 'logia', 'terraza', 'descripcion'], $new_data);
} }
/**
* @param int $promotion_id
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchByPromotion(int $promotion_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('INNER JOIN unidad ON unidad.`pt` = a.`id`')
->joined('INNER JOIN `promotion_units` pu ON pu.`unit_id` = unidad.`id`')
->where('pu.`promotion_id` = :promotion_id')
->group('a.id');
return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
}
} }

View File

@ -1,6 +1,8 @@
<?php <?php
namespace Incoviba\Repository\Proyecto; namespace Incoviba\Repository\Proyecto;
use PDO;
use PDOException;
use Incoviba\Common\Define; use Incoviba\Common\Define;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
use Incoviba\Common\Implement; use Incoviba\Common\Implement;
@ -32,6 +34,11 @@ class TipoUnidad extends Ideal\Repository
return $this->update($model, ['descripcion', 'orden'], $new_data); return $this->update($model, ['descripcion', 'orden'], $new_data);
} }
/**
* @param int $proyecto_id
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchByProyecto(int $proyecto_id): array public function fetchByProyecto(int $proyecto_id): array
{ {
$query = $this->connection->getQueryBuilder() $query = $this->connection->getQueryBuilder()
@ -43,6 +50,31 @@ class TipoUnidad extends Ideal\Repository
->order('a.orden'); ->order('a.orden');
return $this->fetchMany($query, [$proyecto_id]); return $this->fetchMany($query, [$proyecto_id]);
} }
/**
* @param int $promotion_id
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchByPromotion(int $promotion_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.id, ptu.proyecto AS project_id')
->from("{$this->getTable()} a")
->joined('INNER JOIN proyecto_tipo_unidad ptu ON ptu.`tipo` = a.`id`')
->joined('INNER JOIN unidad ON unidad.`pt` = ptu.`id`')
->joined('INNER JOIN `promotion_units` pu ON pu.`unit_id` = unidad.`id`')
->where('pu.`promotion_id` = :promotion_id')
->group('a.id');
try {
$result = $this->connection->execute($query, ['promotion_id' => $promotion_id])->fetchAll(PDO::FETCH_ASSOC);
if (empty($result)) {
throw new Implement\Exception\EmptyResult($query);
}
return $result;
} catch (PDOException $exception) {
throw new Implement\Exception\EmptyResult($query, $exception);
}
return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
}
} }

View File

@ -204,4 +204,45 @@ class Promotion extends Common\Ideal\Repository
throw new Common\Implement\Exception\EmptyResult($query, $exception); throw new Common\Implement\Exception\EmptyResult($query, $exception);
} }
} }
/**
* @param Model\Venta\Promotion $promotion
* @param int $project_id
* @return void
* @throws PDOException
*/
public function insertProjectForPromotion(Model\Venta\Promotion $promotion, int $project_id): void
{
$query = $this->connection->getQueryBuilder()
->insert()
->into('promotion_projects')
->columns(['promotion_id', 'project_id'])
->values([':promotion_id', ':project_id']);
$this->connection->execute($query, ['promotion_id' => $promotion->id, 'project_id' => $project_id]);
}
/**
* @param Model\Venta\Promotion $promotion
* @param int $contract_id
* @return void
* @throws PDOException
*/
public function insertContractForPromotion(Model\Venta\Promotion $promotion, int $contract_id): void
{
$query = $this->connection->getQueryBuilder()
->insert()
->into('promotion_contracts')
->columns(['promotion_id', 'contract_id'])
->values([':promotion_id', ':contract_id']);
$this->connection->execute($query, ['promotion_id' => $promotion->id, 'contract_id' => $contract_id]);
}
public function insertUnitForPromotion(Model\Venta\Promotion $promotion, int $unit_id): void
{
$query = $this->connection->getQueryBuilder()
->insert()
->into('promotion_units')
->columns(['promotion_id', 'unit_id'])
->values([':promotion_id', ':unit_id']);
$this->connection->execute($query, ['promotion_id' => $promotion->id, 'unit_id' => $unit_id]);
}
} }

View File

@ -200,6 +200,22 @@ class Unidad extends Ideal\Repository
return $this->fetchMany($query, ['promotion_id' => $promotion_id]); return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
} }
/**
* @param int $proyecto_id
* @param int $tipo_id
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchByProyectoAndTipo(int $proyecto_id, int $tipo_id): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('INNER JOIN proyecto_tipo_unidad ptu ON a.pt = ptu.id')
->where('ptu.`proyecto` = :proyecto_id AND ptu.`tipo` = :tipo_id');
return $this->fetchMany($query, ['proyecto_id' => $proyecto_id, 'tipo_id' => $tipo_id]);
}
protected function joinProrrateo(): string protected function joinProrrateo(): string
{ {
return "LEFT OUTER JOIN unidad_prorrateo up ON up.unidad_id = a.id"; return "LEFT OUTER JOIN unidad_prorrateo up ON up.unidad_id = a.id";

View File

@ -11,9 +11,22 @@ class Proyecto
protected Repository\Proyecto $proyectoRepository, protected Repository\Proyecto $proyectoRepository,
protected Repository\Proyecto\EstadoProyecto $estadoProyecto protected Repository\Proyecto\EstadoProyecto $estadoProyecto
) {} ) {}
public function getVendibles(): array
/**
* @param string|array|null $orderBy
* @return array
*/
public function getAll(null|string|array $orderBy = null): array
{ {
return $this->proyectoRepository->fetchAllActive(); try {
return array_map([$this, 'process'], $this->proyectoRepository->fetchAll($orderBy));
} catch (Implement\Exception\EmptyResult) {
return [];
}
}
public function getVendibles(null|string|array $orderBy = null): array
{
return $this->proyectoRepository->fetchAllActive($orderBy);
} }
public function getEscriturando(): array public function getEscriturando(): array
{ {

View File

@ -58,12 +58,13 @@ class Broker extends Ideal\Service
} }
} }
/** /**
* @param null|string|array $orderBy
* @return array * @return array
*/ */
public function getAll(): array public function getAll(null|string|array $orderBy = null): array
{ {
try { try {
return array_map([$this, 'process'], $this->brokerRepository->fetchAll()); return array_map([$this, 'process'], $this->brokerRepository->fetchAll($orderBy));
} catch (EmptyResult) { } catch (EmptyResult) {
return []; return [];
} }

View File

@ -17,6 +17,8 @@ class Promotion extends Ideal\Service
protected Repository\Venta\Promotion $promotionRepository, protected Repository\Venta\Promotion $promotionRepository,
protected Repository\Proyecto $projectRepository, protected Repository\Proyecto $projectRepository,
protected Repository\Proyecto\Broker\Contract $contractRepository, protected Repository\Proyecto\Broker\Contract $contractRepository,
protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository,
protected Repository\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadRepository,
protected Repository\Venta\Unidad $unidadRepository) protected Repository\Venta\Unidad $unidadRepository)
{ {
parent::__construct($logger); parent::__construct($logger);
@ -133,6 +135,205 @@ class Promotion extends Ideal\Service
} }
} }
/**
* @param int $promotion_id
* @param int $project_id
* @return Model\Venta\Promotion
* @throws Exception\ServiceAction\Create
*/
public function addProject(int $promotion_id, int $project_id): Model\Venta\Promotion
{
try {
$promotion = $this->promotionRepository->fetchById($promotion_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
try {
$project = $this->projectRepository->fetchById($project_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
if (in_array($project, $promotion->projects())) {
return $this->process($promotion);
}
try {
$this->promotionRepository->insertProjectForPromotion($promotion, $project->id);
return $this->process($promotion);
} catch (PDOException $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
}
/**
* @param int $promotion_id
* @param int $contract_id
* @return Model\Venta\Promotion
* @throws Exception\ServiceAction\Create
*/
public function addContract(int $promotion_id, int $contract_id): Model\Venta\Promotion
{
try {
$promotion = $this->promotionRepository->fetchById($promotion_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
try {
$contract = $this->contractRepository->fetchById($contract_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
if (in_array($contract, $promotion->contracts())) {
return $this->process($promotion);
}
try {
$this->promotionRepository->insertContractForPromotion($promotion, $contract->id);
return $this->process($promotion);
} catch (PDOException $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
}
/**
* @param int $promotion_id
* @param int $project_id
* @param int $unitType_id
* @return Model\Venta\Promotion
* @throws Exception\ServiceAction\Create
*/
public function addUnitType(int $promotion_id, int $project_id, int $unitType_id): Model\Venta\Promotion
{
try {
$promotion = $this->promotionRepository->fetchById($promotion_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
try {
$project = $this->projectRepository->fetchById($project_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
try {
$unitType = $this->tipoUnidadRepository->fetchById($unitType_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
if (in_array(['project' => $project, 'unitType' => $unitType], $promotion->unitTypes())) {
return $this->process($promotion);
}
try {
$units = $this->unidadRepository->fetchByProyectoAndTipo($project->id, $unitType->id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
return $this->insertUnits($promotion, $units);
}
/**
* @param int $promotion_id
* @param int $unit_line_id
* @return Model\Venta\Promotion
* @throws Exception\ServiceAction\Create
*/
public function addUnitLine(int $promotion_id, int $unit_line_id): Model\Venta\Promotion
{
try {
$promotion = $this->promotionRepository->fetchById($promotion_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
try {
$unitLine = $this->proyectoTipoUnidadRepository->fetchById($unit_line_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
if (in_array($unitLine, $promotion->unitLines())) {
return $this->process($promotion);
}
try {
$units = $this->unidadRepository->fetchByProyectoTipoUnidad($unitLine->id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
return $this->insertUnits($promotion, $units);
}
/**
* @param int $promotion_id
* @param int $unit_id
* @return Model\Venta\Promotion
* @throws Exception\ServiceAction\Create
*/
public function addUnit(int $promotion_id, int $unit_id): Model\Venta\Promotion
{
try {
$promotion = $this->promotionRepository->fetchById($promotion_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
try {
$unit = $this->unidadRepository->fetchById($unit_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
if (in_array($unit, $promotion->units())) {
return $this->process($promotion);
}
try {
$this->promotionRepository->insertUnitForPromotion($promotion, $unit->id);
return $this->process($promotion);
} catch (PDOException $exception) {
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
}
public function removeProject(int $promotion_id, int $project_id): array
{
try {
$promotion = $this->promotionRepository->fetchById($promotion_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Delete(__CLASS__, $exception);
}
try {
$project = $this->projectRepository->fetchById($project_id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Exception\ServiceAction\Delete(__CLASS__, $exception);
}
try {
$this->promotionRepository->removeProjectForPromotion($promotion, $project->id);
return [
'id' => '',
'promotion_id' => $promotion_id,
'project_id' => $project_id,
];
} catch (PDOException $exception) {
throw new Exception\ServiceAction\Delete(__CLASS__, $exception);
}
}
/**
* @param Model\Venta\Promotion $promotion
* @param array $units
* @return Model\Venta\Promotion
* @throws Exception\ServiceAction\Create
*/
protected function insertUnits(Model\Venta\Promotion $promotion, array $units): Model\Venta\Promotion
{
$errors = [];
foreach ($units as $unit) {
try {
$this->promotionRepository->insertUnitForPromotion($promotion, $unit->id);
} catch (PDOException | \Throwable $exception) {
$this->logger->debug($exception);
$errors []= $exception;
}
}
if (count($errors) > 0) {
$exception = new Exception\AggregateException($errors);
throw new Exception\ServiceAction\Create(__CLASS__, $exception);
}
return $this->process($promotion);
}
protected function process(Model\Venta\Promotion $model): Model\Venta\Promotion protected function process(Model\Venta\Promotion $model): Model\Venta\Promotion
{ {
@ -154,6 +355,31 @@ class Promotion extends Ideal\Service
} }
}) })
->setArgs(['promotion_id' => $model->id])); ->setArgs(['promotion_id' => $model->id]));
$model->addFactory('unitTypes', (new Implement\Repository\Factory())
->setCallable(function($promotion_id) {
try {
return array_map(function(array $ids) {
return [
'project' => $this->projectRepository->fetchById($ids['project_id']),
'unitType' => $this->tipoUnidadRepository->fetchById($ids['id'])
];
}, $this->tipoUnidadRepository->fetchByPromotion($promotion_id));
} catch (Implement\Exception\EmptyResult) {
return [];
}
})
->setArgs(['promotion_id' => $model->id])
);
$model->addFactory('unitLines', (new Implement\Repository\Factory())
->setCallable(function($promotion_id) {
try {
return $this->proyectoTipoUnidadRepository->fetchByPromotion($promotion_id);
} catch (Implement\Exception\EmptyResult) {
return [];
}
})
->setArgs(['promotion_id' => $model->id])
);
$model->addFactory('units', (new Implement\Repository\Factory()) $model->addFactory('units', (new Implement\Repository\Factory())
->setCallable(function($promotion_id) { ->setCallable(function($promotion_id) {
try { try {