Ventas->Listado->Ventas
This commit is contained in:
@ -4,4 +4,10 @@ $app = require_once implode(DIRECTORY_SEPARATOR, [
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
try {
|
||||
$app->run();
|
||||
} catch (Error $error) {
|
||||
$app->getContainer()->get(Psr\Log\LoggerInterface::class)->error($error);
|
||||
} catch (Exception $exception) {
|
||||
$app->getContainer()->get(Psr\Log\LoggerInterface::class)->notice($exception);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas;
|
||||
|
||||
$app->group('/ventas', function($app) {
|
||||
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']));
|
||||
foreach ($files as $file) {
|
||||
@ -7,4 +9,5 @@ $app->group('/ventas', function($app) {
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
$app->get('[/]', Ventas::class);
|
||||
});
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas;
|
||||
|
||||
$app->group('/ventas', function($app) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']);
|
||||
if (file_exists($folder)) {
|
||||
@ -10,4 +12,5 @@ $app->group('/ventas', function($app) {
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
$app->post('[/]', [Ventas::class, 'proyecto']);
|
||||
});
|
||||
|
@ -4,3 +4,8 @@ use Incoviba\Controller\Ventas\Precios;
|
||||
$app->group('/precios', function($app) {
|
||||
$app->post('[/]', [Precios::class, 'proyecto']);
|
||||
});
|
||||
$app->group('/precio', function($app) {
|
||||
$app->group('/unidad/{unidad_id}', function($app) {
|
||||
$app->get('[/]', [Precios::class, 'unidad']);
|
||||
});
|
||||
});
|
||||
|
@ -4,3 +4,6 @@ use Incoviba\Controller\Ventas\Cierres;
|
||||
$app->group('/cierres', function($app) {
|
||||
$app->get('[/]', Cierres::class);
|
||||
});
|
||||
$app->group('/cierre/{cierre_id}', function($app) {
|
||||
$app->get('[/]', [Cierres::class, 'show']);
|
||||
});
|
||||
|
14
app/resources/views/not_found.blade.php
Normal file
14
app/resources/views/not_found.blade.php
Normal file
@ -0,0 +1,14 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
404 - No Encontrado
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<div class="ui message">
|
||||
<i class="exclamation triangle icon"></i>
|
||||
No se ha encontrado la página solicitada
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -124,7 +124,7 @@
|
||||
).append(
|
||||
$('<div></div>').addClass('content').append(table)
|
||||
)
|
||||
const dt = new DataTable(table, {
|
||||
new DataTable(table, {
|
||||
order: [[1, 'desc'], [0, 'asc']]
|
||||
})
|
||||
}
|
||||
|
141
app/resources/views/ventas/cierres/show.blade.php
Normal file
141
app/resources/views/ventas/cierres/show.blade.php
Normal file
@ -0,0 +1,141 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Cierre - Detalle
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<div class="ui segment">
|
||||
<h2 class="ui blue header">Cierre {{$cierre->principal()->descripcion}} - {{$cierre->proyecto->descripcion}}</h2>
|
||||
<div class="ui basic segments">
|
||||
<div class="ui grid segment">
|
||||
<div class="two wide column">
|
||||
Fecha
|
||||
</div>
|
||||
<div class="two wide column">
|
||||
{{$cierre->dateTime->format('d-m-Y')}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui inverted grey segment">PROPIETARIO</div>
|
||||
<div class="ui grid segment">
|
||||
<div class="row">
|
||||
<div class="two wide column">
|
||||
{{$cierre->propietario->rut()}}
|
||||
</div>
|
||||
<div class="six wide column">
|
||||
{{$cierre->propietario->nombreCompleto()}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="column"></div>
|
||||
<div class="fifteen wide column">
|
||||
{{$cierre->propietario->datos->direccion}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui inverted grey segment">PROPIEDAD</div>
|
||||
<div class="ui segment">
|
||||
<table class="ui very basic table">
|
||||
<tbody>
|
||||
@foreach ($cierre->unidades as $unidad)
|
||||
<tr>
|
||||
<td>{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}</td>
|
||||
<td>{{$unidad->descripcion}}</td>
|
||||
<td>{{$unidad->proyectoTipoUnidad->nombre}}</td>
|
||||
<td>{{$unidad->proyectoTipoUnidad->abreviacion}}</td>
|
||||
<td>{{number_format($unidad->proyectoTipoUnidad->vendible(), 2, ',', '.')}} m²</td>
|
||||
<td>{{number_format($unidad->currentPrecio->valor, 2, ',', '.')}} UF</td>
|
||||
<td>{{number_format($unidad->currentPrecio->valor / $unidad->proyectoTipoUnidad->vendible(), 2, ',', '.')}} UF/m²</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="ui inverted grey segment">OFERTA</div>
|
||||
<div class="ui grid segment">
|
||||
<div class="two wide column">
|
||||
Precio
|
||||
</div>
|
||||
<div class="two wide column">
|
||||
{{number_format($cierre->precio, 2, ',', '.')}} UF
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui grid segment">
|
||||
<strong class="two wide column">
|
||||
Neto
|
||||
</strong>
|
||||
<strong class="two wide column">
|
||||
{{number_format($cierre->neto(), 2, ',', '.')}} UF
|
||||
</strong>
|
||||
<strong class="two wide column">
|
||||
{{number_format($cierre->neto() / $cierre->principal()->vendible, 2, ',', '.')}} UF/m²
|
||||
</strong>
|
||||
<div class="column">
|
||||
@if ($cierre->neto() / $cierre->principal()->vendible > $cierre->principal()->precio / $cierre->principal()->vendible)
|
||||
<i class="green check icon"></i>
|
||||
@else
|
||||
<i class="red remove icon"></i>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@foreach($cierre->valoresCierre as $valorCierre)
|
||||
<div class="ui grid segment">
|
||||
<div class="two wide column">{{ucwords($valorCierre->tipoValorCierre->descripcion)}}</div>
|
||||
<div class="two wide column">{{number_format($valorCierre->valor, 2, ',', '.')}} UF</div>
|
||||
<div class="two wide column">{{number_format($valorCierre->valor / $cierre->precio * 100, 2, ',', '.')}}%</div>
|
||||
</div>
|
||||
@endforeach
|
||||
<div class="ui inverted grey segment">DIFERENCIA</div>
|
||||
<div class="ui grid segment">
|
||||
<div class="two wide column">Neto</div>
|
||||
<div class="two wide column">
|
||||
{{number_format($cierre->neto() - $cierre->principal()->precio, 2, ',', '.')}} UF
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui inverted grey segment">ESTADO</div>
|
||||
<div class="ui segment">
|
||||
<div class="ui grid message {{['aprobado' => 'success', 'abandonado' => 'warning', 'promesado' => 'success'][$cierre->current->tipoEstadoCierre->descripcion]}}">
|
||||
<div class="two wide column">
|
||||
{{ucwords($cierre->current->tipoEstadoCierre->descripcion)}}
|
||||
</div>
|
||||
<div class="four wide column">
|
||||
{{$cierre->current->fecha->format('d-m-Y')}}
|
||||
</div>
|
||||
<div class="right aligned ten wide column">
|
||||
@if ($cierre->current->tipoEstadoCierre->descripcion === 'aprobado')
|
||||
<button class="ui icon basic button" data-content="Promesar" id="promesar" data-id="{{$cierre->id}}">
|
||||
<i class="check icon"></i>
|
||||
</button>
|
||||
<button class="ui icon basic button" data-content="Abandonar" id="abandonar" data-id="{{$cierre->id}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
function action(action, cierre_id) {
|
||||
const url = '{{$urls->base}}/api/cierre/' + cierre_id + '/' + action
|
||||
console.debug(url)
|
||||
}
|
||||
$(document).ready(() => {
|
||||
$('#promesar').popup().click(event => {
|
||||
const button = $(event.currentTarget)
|
||||
const id = button.data('id')
|
||||
action('promesar', id)
|
||||
})
|
||||
$('#abandonar').popup().click(event => {
|
||||
const button = $(event.currentTarget)
|
||||
const id = button.data('id')
|
||||
action('abandonar', id)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
274
app/resources/views/ventas/list.blade.php
Normal file
274
app/resources/views/ventas/list.blade.php
Normal file
@ -0,0 +1,274 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Ventas
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Listado de Ventas</h2>
|
||||
<h4 class="ui dividing header">
|
||||
<div class="ui two column grid">
|
||||
<div id="list_title" class="column">Proyectos</div>
|
||||
<div class="right aligned column">
|
||||
<div class="ui tiny icon buttons">
|
||||
<button class="ui button" id="up_button">
|
||||
<i class="up arrow icon"></i>
|
||||
</button>
|
||||
<button class="ui button" id="refresh_button">
|
||||
<i class="refresh icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</h4>
|
||||
<div class="ui link selection list" id="proyectos"></div>
|
||||
<table class="ui table" id="data"></table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.head.styles.datatables')
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Venta {
|
||||
id
|
||||
propiedad
|
||||
propietario
|
||||
valor
|
||||
fecha
|
||||
estado
|
||||
|
||||
constructor({id, propiedad, propietario, valor, fecha, estado}) {
|
||||
this.id = id
|
||||
this.propiedad = propiedad
|
||||
this.propietario = propietario
|
||||
this.valor = valor
|
||||
this.fecha = fecha
|
||||
this.estado = estado
|
||||
}
|
||||
|
||||
draw(formatter, dateFormatter) {
|
||||
const tipo = this.estado.tipo_estado_venta.descripcion
|
||||
const date = new Date(this.fecha)
|
||||
return $('<tr></tr>').append(
|
||||
$('<td></td>').attr('data-order', this.propiedad.departamentos[0].descripcion).append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/venta/' + this.id).html(this.propiedad.summary)
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/search?tipo=propietario&query=' + encodeURIComponent(this.propietario.nombre_completo)).html(this.propietario.nombre_completo)
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.valor) + ' UF')
|
||||
).append(
|
||||
$('<td></td>').html(this.propiedad.departamentos[0].proyecto_tipo_unidad.abreviacion + ' (' + formatter.format(this.propiedad.departamentos[0].proyecto_tipo_unidad.vendible) + ' m²)')
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.valor / this.propiedad.departamentos[0].proyecto_tipo_unidad.vendible) + ' UF/m²')
|
||||
).append(
|
||||
$('<td></td>').attr('data-order', this.fecha).html(dateFormatter.format(date))
|
||||
).append(
|
||||
$('<td></td>').html(tipo.charAt(0).toUpperCase() + tipo.slice(1))
|
||||
)
|
||||
}
|
||||
}
|
||||
const ventas = {
|
||||
ids: {
|
||||
title: '',
|
||||
proyectos: '',
|
||||
table: '',
|
||||
buttons: {
|
||||
up: '',
|
||||
refresh: ''
|
||||
}
|
||||
},
|
||||
data: {
|
||||
id: 0,
|
||||
proyecto: '',
|
||||
proyectos: JSON.parse('{!! json_encode($proyectos) !!}'),
|
||||
ventas: []
|
||||
},
|
||||
loading: {
|
||||
ventas: false
|
||||
},
|
||||
formatters: {
|
||||
number: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2}),
|
||||
date: new Intl.DateTimeFormat('es-CL')
|
||||
},
|
||||
table: null,
|
||||
get: function() {
|
||||
return {
|
||||
ventas: proyecto_id => {
|
||||
this.data.ventas = []
|
||||
return fetch('{{$urls->api}}/ventas',
|
||||
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}
|
||||
).then(response => {
|
||||
this.loading.precios = false
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.total > 0) {
|
||||
this.data.id = data.ventas[0].propiedad.departamentos[0].proyecto_tipo_unidad.proyecto.id
|
||||
this.data.proyecto = data.ventas[0].propiedad.departamentos[0].proyecto_tipo_unidad.proyecto.descripcion
|
||||
data.ventas.forEach(venta => {
|
||||
this.add().venta(venta)
|
||||
})
|
||||
this.draw().ventas()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
add: function() {
|
||||
return {
|
||||
venta: data => {
|
||||
const venta = new Venta({
|
||||
id: data.id,
|
||||
propiedad: data.propiedad,
|
||||
propietario: data.propietario,
|
||||
valor: data.valor,
|
||||
fecha: data.fecha,
|
||||
estado: data.current_estado
|
||||
})
|
||||
this.data.ventas.push(venta)
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
proyectos: () => {
|
||||
const title = $(this.ids.title)
|
||||
const parent = $(this.ids.proyectos)
|
||||
const table = $(this.ids.table)
|
||||
|
||||
table.hide()
|
||||
parent.html('')
|
||||
this.loading.ventas = false
|
||||
if (this.table !== null) {
|
||||
this.table.destroy()
|
||||
this.table = null
|
||||
}
|
||||
|
||||
title.html('Proyectos')
|
||||
|
||||
this.data.proyectos.forEach(proyecto => {
|
||||
parent.append(
|
||||
$('<div></div>').addClass('item proyecto').attr('data-proyecto', proyecto.id).html(proyecto.descripcion).css('cursor', 'pointer')
|
||||
)
|
||||
})
|
||||
|
||||
parent.show()
|
||||
parent.find('.item.proyecto').click(this.actions().get)
|
||||
},
|
||||
ventas: () => {
|
||||
const title = $(this.ids.title)
|
||||
const parent = $(this.ids.proyectos)
|
||||
const table = $(this.ids.table)
|
||||
|
||||
parent.hide()
|
||||
table.html('')
|
||||
this.loading.ventas = false
|
||||
if (this.table !== null) {
|
||||
this.table.destroy()
|
||||
this.table = null
|
||||
}
|
||||
|
||||
title.html('Ventas de ' + this.data.proyecto + ' [' + this.data.ventas.length + ']')
|
||||
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.data.ventas.forEach(venta => {
|
||||
tbody.append(venta.draw(this.formatters.number, this.formatters.date))
|
||||
})
|
||||
table.append(this.draw().header()).append(tbody)
|
||||
table.show()
|
||||
|
||||
this.table = new DataTable(table, {
|
||||
order: [[0, 'asc']],
|
||||
})
|
||||
},
|
||||
table: () => {
|
||||
const parent = $(this.ids.proyectos)
|
||||
const table = $(this.ids.table)
|
||||
if (table.length > 0) {
|
||||
return
|
||||
}
|
||||
console.debug(parent.parent())
|
||||
},
|
||||
header: () => {
|
||||
return $('<thead></thead>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').html('Departamento')
|
||||
).append(
|
||||
$('<th></th>').html('Propietario')
|
||||
).append(
|
||||
$('<th></th>').html('Valor [UF]')
|
||||
).append(
|
||||
$('<th></th>').html('Tipologia')
|
||||
).append(
|
||||
$('<th></th>').html('UF/m²')
|
||||
).append(
|
||||
$('<th></th>').html('Fecha Venta')
|
||||
).append(
|
||||
$('<th></th>').html('Estado')
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: function() {
|
||||
return {
|
||||
up: event => {
|
||||
this.draw().proyectos()
|
||||
},
|
||||
refresh: event => {
|
||||
const list = $(this.ids.proyectos)
|
||||
if (list.is(':hidden')) {
|
||||
const table = $(this.ids.table)
|
||||
table.hide()
|
||||
if (this.table !== null) {
|
||||
this.table.destroy()
|
||||
this.table = null
|
||||
}
|
||||
this.get().ventas(this.data.id)
|
||||
} else {
|
||||
this.draw().proyectos()
|
||||
}
|
||||
},
|
||||
get: event => {
|
||||
if (this.loading.ventas) {
|
||||
return false
|
||||
}
|
||||
const element = $(event.currentTarget)
|
||||
$(this.ids.proyectos + ' .item.proyecto').css('cursor', 'wait')
|
||||
this.loading.ventas = true
|
||||
const proyecto_id = element.data('proyecto')
|
||||
this.get().ventas(proyecto_id)
|
||||
}
|
||||
}
|
||||
},
|
||||
setup: function({title, proyectos_id, table_id, up_button, refresh_button}) {
|
||||
this.ids.title = title
|
||||
this.ids.proyectos = proyectos_id
|
||||
this.ids.table = table_id
|
||||
this.ids.buttons.up = up_button
|
||||
this.ids.buttons.refresh = refresh_button
|
||||
|
||||
$(this.ids.buttons.up).click(this.actions().up)
|
||||
$(this.ids.buttons.refresh).click(this.actions().refresh)
|
||||
|
||||
this.draw().proyectos()
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
ventas.setup({
|
||||
title: '#list_title',
|
||||
proyectos_id: '#proyectos',
|
||||
table_id: '#data',
|
||||
up_button: '#up_button',
|
||||
refresh_button: '#refresh_button'
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -321,7 +321,7 @@
|
||||
data: {
|
||||
id: 0,
|
||||
proyecto: '',
|
||||
proyectos: [],
|
||||
proyectos: JSON.parse('{!! json_encode($proyectos) !!}'),
|
||||
precios: []
|
||||
},
|
||||
table: null,
|
||||
@ -524,14 +524,14 @@
|
||||
}
|
||||
},
|
||||
up: event => {
|
||||
this.get().proyectos()
|
||||
this.draw().proyectos()
|
||||
},
|
||||
refresh: event => {
|
||||
const list = $(this.ids.proyectos)
|
||||
if (list.is(':hidden')) {
|
||||
this.get().precios(this.data.id)
|
||||
} else {
|
||||
this.get().proyectos()
|
||||
this.draw().proyectos()
|
||||
}
|
||||
},
|
||||
add: () => {
|
||||
@ -581,7 +581,7 @@
|
||||
$(this.ids.buttons.refresh).click(this.actions().refresh)
|
||||
$(this.ids.buttons.add).click(this.actions().add().list)
|
||||
|
||||
this.get().proyectos()
|
||||
this.draw().proyectos()
|
||||
}
|
||||
}
|
||||
|
||||
|
2
app/setup/middlewares/97_not_found.php
Normal file
2
app/setup/middlewares/97_not_found.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\Middleware\NotFound::class));
|
8
app/setup/setups/psr7.php
Normal file
8
app/setup/setups/psr7.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Http\Message\ResponseFactoryInterface::class => function(ContainerInterface $container) {
|
||||
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
|
||||
}
|
||||
];
|
26
app/src/Controller/Ventas.php
Normal file
26
app/src/Controller/Ventas.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
|
||||
{
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$ventas = $service->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['ventas' => $ventas, 'total' => count($ventas)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -12,6 +12,12 @@ class Cierres
|
||||
{
|
||||
return $view->render($response, 'ventas.cierres.list');
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Ventas\Cierre $service, int $cierre_id): ResponseInterface
|
||||
{
|
||||
$cierre = $service->getById($cierre_id);
|
||||
return $view->render($response, 'ventas.cierres.show', compact('cierre'));
|
||||
}
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Cierre $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
|
@ -1,16 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Precios
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'ventas.precios.list');
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.precios.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService): ResponseInterface
|
||||
{
|
||||
@ -21,4 +23,10 @@ class Precios
|
||||
$response->getBody()->write(json_encode(['precios' => $precios, 'total' => count($precios)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$precio = $precioService->getByUnidad($unidad_id);
|
||||
$response->getBody()->write(json_encode(['precio' => $precio]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
25
app/src/Middleware/NotFound.php
Normal file
25
app/src/Middleware/NotFound.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Slim\Exception\HttpNotFoundException;
|
||||
use Incoviba\Common\Alias\View;
|
||||
|
||||
class NotFound
|
||||
{
|
||||
public function __construct(protected LoggerInterface $logger, protected ResponseFactoryInterface $responseFactory, protected View $view) {}
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
try {
|
||||
return $handler->handle($request);
|
||||
} catch (HttpNotFoundException $exception) {
|
||||
$this->logger->warning($exception);
|
||||
$response = $this->responseFactory->createResponse(404);
|
||||
return $this->view->render($response, 'not_found');
|
||||
}
|
||||
}
|
||||
}
|
@ -15,4 +15,8 @@ class Comuna extends Model
|
||||
'provincia' => $this->provincia
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return implode(', ', [$this->descripcion, '' . $this->provincia]);
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,18 @@ class Direccion extends Model
|
||||
'comuna' => $this->comuna
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
$array = [
|
||||
implode(' ', [
|
||||
$this->calle,
|
||||
$this->numero
|
||||
])
|
||||
];
|
||||
if ($this->extra !== '') {
|
||||
$array[]= $this->extra;
|
||||
}
|
||||
$array []= '' . $this->comuna;
|
||||
return implode(', ', $array);
|
||||
}
|
||||
}
|
||||
|
@ -15,4 +15,8 @@ class Provincia extends Model
|
||||
'region' => $this->region
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return implode(', ', [$this->descripcion, '' . $this->region]);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal\Model;
|
||||
use Incoviba\Model\Proyecto\Superficie;
|
||||
use Incoviba\Model\Proyecto\Terreno;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Proyecto extends Model
|
||||
class Proyecto extends Ideal\Model
|
||||
{
|
||||
public Inmobiliaria $inmobiliaria;
|
||||
public string $descripcion;
|
||||
public Direccion $direccion;
|
||||
public Terreno $terreno;
|
||||
public Superficie $superficie;
|
||||
public Proyecto\Terreno $terreno;
|
||||
public Proyecto\Superficie $superficie;
|
||||
public float $corredor;
|
||||
public int $pisos;
|
||||
public int $subterraneos;
|
||||
|
@ -17,4 +17,8 @@ class Region extends Model
|
||||
'numeracion' => $this->numeracion ?? 0
|
||||
]);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->descripcion;
|
||||
}
|
||||
}
|
||||
|
34
app/src/Model/Venta.php
Normal file
34
app/src/Model/Venta.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Venta extends Ideal\Model
|
||||
{
|
||||
public Venta\Propietario $propietario;
|
||||
public Venta\Propiedad $propiedad;
|
||||
public Venta\FormaPago $formaPago;
|
||||
public DateTimeInterface $fecha;
|
||||
public DateTimeInterface $fechaIngreso;
|
||||
public float $valor;
|
||||
public bool $relacionado;
|
||||
|
||||
public array $estados;
|
||||
public Venta\EstadoVenta $currentEstado;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'propietario' => $this->propietario,
|
||||
'propiedad' => $this->propiedad,
|
||||
'forma_pago' => $this->formaPago,
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'fecha_ingreso' => $this->fechaIngreso->format('Y-m-d'),
|
||||
'valor' => $this->valor,
|
||||
'relacionado' => $this->relacionado,
|
||||
'estados' => $this->estados,
|
||||
'current_estado' => $this->currentEstado
|
||||
]);
|
||||
}
|
||||
}
|
8
app/src/Model/Venta/BonoPie.php
Normal file
8
app/src/Model/Venta/BonoPie.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class BonoPie extends Ideal\Model
|
||||
{
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use stdClass;
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
@ -17,6 +18,28 @@ class Cierre extends Ideal\Model
|
||||
public ?EstadoCierre $current = null;
|
||||
|
||||
public array $unidades = [];
|
||||
public array $valoresCierre = [];
|
||||
|
||||
public function neto(): float
|
||||
{
|
||||
$sum = $this->precio;
|
||||
$bonos = array_filter($this->valoresCierre, function(ValorCierre $valorCierre) {return $valorCierre->tipoValorCierre->descripcion === 'bono pie';});
|
||||
$sum -= array_reduce($bonos, function($sum, ValorCierre $bono) {return $sum + $bono->valor;}, 0);
|
||||
$unidades = array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion !== 'departamento';});
|
||||
$sum -= array_reduce($unidades, function($sum, Unidad $unidad) {return $sum + ($unidad->currentPrecio->valor ?? 0);});
|
||||
return $sum;
|
||||
}
|
||||
|
||||
public function principal(): stdClass
|
||||
{
|
||||
$unidades = array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';});
|
||||
$output = [
|
||||
'descripcion' => implode(' - ', array_map(function(Unidad $unidad) {return $unidad->descripcion;}, $unidades)),
|
||||
'vendible' => array_reduce($unidades, function($sum, Unidad $unidad) {return $sum + $unidad->proyectoTipoUnidad->vendible();}, 0),
|
||||
'precio' => array_reduce($unidades, function($sum, Unidad $unidad) {return $sum + $unidad->currentPrecio->valor;}, 0)
|
||||
];
|
||||
return (object) $output;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
@ -28,7 +51,8 @@ class Cierre extends Ideal\Model
|
||||
'propietario' => $this->propietario->rut,
|
||||
'estados' => $this->estados,
|
||||
'estado_cierre' => $this->current,
|
||||
'unidades' => $this->unidades
|
||||
'unidades' => $this->unidades,
|
||||
'valores_cierre' => $this->valoresCierre
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
7
app/src/Model/Venta/Credito.php
Normal file
7
app/src/Model/Venta/Credito.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Credito extends Ideal\Model
|
||||
{}
|
21
app/src/Model/Venta/Entrega.php
Normal file
21
app/src/Model/Venta/Entrega.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Entrega extends Ideal\Model
|
||||
{
|
||||
public DateTimeInterface $fecha;
|
||||
public ?Pago $operacion;
|
||||
public ?Pago $reserva;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'operacion' => $this->operacion,
|
||||
'reserva' => $this->reserva
|
||||
]);
|
||||
}
|
||||
}
|
7
app/src/Model/Venta/Escritura.php
Normal file
7
app/src/Model/Venta/Escritura.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Escritura extends Ideal\Model
|
||||
{}
|
22
app/src/Model/Venta/EstadoVenta.php
Normal file
22
app/src/Model/Venta/EstadoVenta.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class EstadoVenta extends Ideal\Model
|
||||
{
|
||||
public Model\Venta $venta;
|
||||
public TipoEstadoVenta $tipoEstadoVenta;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'venta_id' => $this->venta->id,
|
||||
'tipo_estado_venta' => $this->tipoEstadoVenta,
|
||||
'fecha' => $this->fecha->format('Y-m-d')
|
||||
]);
|
||||
}
|
||||
}
|
24
app/src/Model/Venta/FormaPago.php
Normal file
24
app/src/Model/Venta/FormaPago.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
class FormaPago implements JsonSerializable
|
||||
{
|
||||
public ?Pie $pie;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Credito $credito;
|
||||
public ?Escritura $escritura;
|
||||
public ?Subsidio $subsidio;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'pie' => $this->pie ?? null,
|
||||
'bono_pie' => $this->bonoPie ?? null,
|
||||
'credito' => $this->credito ?? null,
|
||||
'escritura' => $this->escritura ?? null,
|
||||
'subsidio' => $this->subsidio ?? null
|
||||
];
|
||||
}
|
||||
}
|
47
app/src/Model/Venta/Propiedad.php
Normal file
47
app/src/Model/Venta/Propiedad.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Propiedad extends Ideal\Model
|
||||
{
|
||||
public array $unidades;
|
||||
|
||||
public function departamentos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';});
|
||||
}
|
||||
public function estacionamientos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';});
|
||||
}
|
||||
public function bodegas(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';});
|
||||
}
|
||||
|
||||
public function summary(): string
|
||||
{
|
||||
return implode(' - ', array_merge(
|
||||
array_map(function(Unidad $unidad) {
|
||||
return $unidad->descripcion;
|
||||
}, $this->departamentos()),
|
||||
array_map(function(Unidad $unidad) {
|
||||
return "E{$unidad->descripcion}";
|
||||
}, $this->estacionamientos()),
|
||||
array_map(function(Unidad $unidad) {
|
||||
return "B{$unidad->descripcion}";
|
||||
}, $this->bodegas())
|
||||
));
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'departamentos' => $this->departamentos(),
|
||||
'estacionamientos' => $this->estacionamientos(),
|
||||
'bodegas' => $this->bodegas(),
|
||||
'summary' => $this->summary()
|
||||
];
|
||||
}
|
||||
}
|
18
app/src/Model/Venta/Subsidio.php
Normal file
18
app/src/Model/Venta/Subsidio.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Subsidio extends Ideal\Model
|
||||
{
|
||||
public Pago $ahorro;
|
||||
public Pago $subsidio;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'ahorro' => $this->ahorro,
|
||||
'subsidio' => $this->subsidio
|
||||
]);
|
||||
}
|
||||
}
|
16
app/src/Model/Venta/TipoEstadoVenta.php
Normal file
16
app/src/Model/Venta/TipoEstadoVenta.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoEstadoVenta extends Tipo
|
||||
{
|
||||
public bool $activa;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'activa' => $this->activa
|
||||
]);
|
||||
}
|
||||
}
|
7
app/src/Model/Venta/TipoValorCierre.php
Normal file
7
app/src/Model/Venta/TipoValorCierre.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoValorCierre extends Tipo
|
||||
{}
|
@ -12,6 +12,9 @@ class Unidad extends Ideal\Model
|
||||
public ?string $orientacion = '';
|
||||
public Model\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidad;
|
||||
|
||||
public array $precios = [];
|
||||
public ?Precio $currentPrecio = null;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
20
app/src/Model/Venta/ValorCierre.php
Normal file
20
app/src/Model/Venta/ValorCierre.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class ValorCierre extends Ideal\Model
|
||||
{
|
||||
public Cierre $cierre;
|
||||
public TipoValorCierre $tipoValorCierre;
|
||||
public float $valor;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'cierre_id' => $this->cierre->id,
|
||||
'tipo_valor_cierre' => $this->tipoValorCierre,
|
||||
'valor' => $this->valor
|
||||
]);
|
||||
}
|
||||
}
|
155
app/src/Repository/Venta.php
Normal file
155
app/src/Repository/Venta.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Venta extends Ideal\Repository
|
||||
{
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Venta\Propietario $propietarioRepository,
|
||||
protected Venta\Propiedad $propiedadRepository,
|
||||
protected Venta\Pie $pieRepository,
|
||||
protected Venta\BonoPie $bonoPieRepository,
|
||||
protected Venta\Credito $creditoRepository,
|
||||
protected Venta\Escritura $escrituraRepository,
|
||||
protected Venta\Subsidio $subsidioRepository,
|
||||
protected Venta\Entrega $entregaRepository,
|
||||
protected Venta\Pago $pagoRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'propietario' => [
|
||||
'function' => function($data) {
|
||||
return $this->propietarioRepository->fetchById($data['propietario']);
|
||||
}
|
||||
],
|
||||
'propiedad' => [
|
||||
'function' => function($data) {
|
||||
return $this->propiedadRepository->fetchById($data['propiedad']);
|
||||
}
|
||||
],
|
||||
'pie' => [
|
||||
'property' => 'formaPago',
|
||||
'function' => function($data) {
|
||||
$fp = new Model\Venta\FormaPago();
|
||||
$map = [
|
||||
'pie' => [
|
||||
'repository' => $this->pieRepository
|
||||
],
|
||||
'bono_pie' => [
|
||||
'property' => 'bonoPie',
|
||||
'repository' => $this->bonoPieRepository
|
||||
],
|
||||
'credito' => [
|
||||
'repository' => $this->creditoRepository
|
||||
],
|
||||
'escritura' => [
|
||||
'repository' => $this->escrituraRepository
|
||||
],
|
||||
'subsidio' => [
|
||||
'repository' => $this->subsidioRepository
|
||||
]
|
||||
];
|
||||
foreach ($map as $column => $settings) {
|
||||
if ($data[$column] !== null and $data[$column] !== 0) {
|
||||
$fp->{$settings['property'] ?? $column} = $settings['repository']->fetchById($data[$column]);
|
||||
}
|
||||
}
|
||||
return $fp;
|
||||
}
|
||||
],
|
||||
'escriturado' => [
|
||||
'function' => function($data) {
|
||||
return $data['escritura'] !== null;
|
||||
}
|
||||
],
|
||||
'entrega' => [
|
||||
'function' => function($data) {
|
||||
if ($data['entrega'] !== null and $data['entrega'] !== 0) {
|
||||
return $this->entregaRepository->fetchById($data['entrega']);
|
||||
}
|
||||
}
|
||||
],
|
||||
'entregado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['entrega'] !== null and $data['entrega'] !== 0) {
|
||||
return $data['entrega'] !== null;
|
||||
}
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor_uf' => [
|
||||
'property' => 'valor'
|
||||
],
|
||||
//'estado' => [],
|
||||
'fecha_ingreso' => [
|
||||
'property' => 'fechaIngreso',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha_ingreso']);
|
||||
}
|
||||
],
|
||||
/*'avalchile' => [
|
||||
|
||||
],*/
|
||||
//'agente',
|
||||
//'uf',
|
||||
'relacionado' => [
|
||||
'function' => function($data) {
|
||||
return $data['relacionado'] !== 0;
|
||||
}
|
||||
],
|
||||
//'promocion',
|
||||
//'resciliacion',
|
||||
//'devolucion'
|
||||
];
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'],
|
||||
[$model->propietario->rut, $model->propiedad->id, $model->formaPago->Pie?->id, $model->formaPago->bonoPie?->id,
|
||||
$model->formaPago->credito?->id, $model->formaPago->escritura?->id, $model->formaPago->subsidio?->id,
|
||||
$model->formaPago->escritura !== null ? 1 : 0, null, 0, $model->fecha->format('Y-m-d'), $model->valor,
|
||||
$model->currentEstado->vigente ? 1 : 0, $model->fechaIngreso->format('Y-m-d'), '', null, 0,
|
||||
$model->relacionado ? 1 : 0, null, null, null]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/BonoPie.php
Normal file
39
app/src/Repository/Venta/BonoPie.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class BonoPie extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('bono_pie');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\BonoPie(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['valor', 'pago'],
|
||||
[$model->pago->valor, $model->pago->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['valor', 'pago'], $new_data);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/Credito.php
Normal file
39
app/src/Repository/Venta/Credito.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Credito extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('credito');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Credito(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'],
|
||||
[$model->pago->banco->id, $model->pago->valor, $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
}
|
38
app/src/Repository/Venta/Entrega.php
Normal file
38
app/src/Repository/Venta/Entrega.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Entrega extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('entrega');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
|
||||
'pago_operacion', 'pago_reserva'];
|
||||
return $this->parseData(new Model\Venta\Entrega(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
|
||||
'pago_operacion', 'pago_reserva'],
|
||||
[$model->fecha->format('Y-m-d'), $model->operacion->valor, $model->reserva->valor,
|
||||
$model->operacion->fecha('Y-m-d'), $model->reserva->fecha('Y-m-d'), $model->operacion->id,
|
||||
$model->reserva->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion',
|
||||
'fecha_fondo_reserva', 'pago_operacion', 'pago_reserva'], $new_data);
|
||||
}
|
||||
}
|
39
app/src/Repository/Venta/Escritura.php
Normal file
39
app/src/Repository/Venta/Escritura.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Escritura extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('escritura');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Escritura(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'],
|
||||
[$model->pago->valor, $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
}
|
67
app/src/Repository/Venta/EstadoVenta.php
Normal file
67
app/src/Repository/Venta/EstadoVenta.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoVenta extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta $ventaRepository,
|
||||
protected TipoEstadoVenta $tipoEstadoVentaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'venta' => [
|
||||
'function' => function($data) {
|
||||
return $this->ventaRepository->fetchById($data['venta']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoVenta',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoVentaRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['venta', 'estado', 'fecha'],
|
||||
[$model->venta->id, $model->tipoEstadoVenta->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['venta', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ?";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
public function fetchCurrentByVenta(int $venta_id): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `{$this->getTable()}` GROUP BY `venta`) e0 ON e0.`id` = a.`id`
|
||||
WHERE a.`venta` = ?";
|
||||
return $this->fetchOne($query, [$venta_id]);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
@ -52,4 +53,22 @@ WHERE ptu.`proyecto` = ? AND tep.`descripcion` = 'vigente'
|
||||
ORDER BY tu.`orden`, ptu.`nombre`, `unidad`.`subtipo`, LPAD(`unidad`.`descripcion`, 4, '0')";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchByUnidad(int $unidad_id): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.* FROM `estado_precio` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `estado_precio` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`) ep ON ep.`precio` = a.`id`
|
||||
JOIN `tipo_estado_precio` tep ON tep.`id` = ep.`estado`
|
||||
WHERE `unidad` = ? AND tep.`descripcion` = 'vigente'";
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
public function fetchByUnidadAndDate(int $unidad_id, string $date_time): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.* FROM `estado_precio` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `estado_precio` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`) ep ON ep.`precio` = a.`id`
|
||||
JOIN `tipo_estado_precio` tep ON tep.`id` = ep.`estado`
|
||||
WHERE `unidad` = ? AND ep.`fecha` <= ? AND tep.`descripcion` = 'vigente'";
|
||||
return $this->fetchOne($query, [$unidad_id, $date_time]);
|
||||
}
|
||||
}
|
||||
|
45
app/src/Repository/Venta/Propiedad.php
Normal file
45
app/src/Repository/Venta/Propiedad.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Propiedad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Unidad $unidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propiedad');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'unidad_principal' => [
|
||||
'property' => 'unidades',
|
||||
'function' => function($data) {
|
||||
return $this->unidadRepository->fetchByPropiedad($data['id']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'function' => function($data) {
|
||||
return true;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
||||
[$model->departamentos()[0]->id, null, null, 1]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
|
||||
}
|
||||
}
|
33
app/src/Repository/Venta/Subsidio.php
Normal file
33
app/src/Repository/Venta/Subsidio.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Subsidio extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('subsidio');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['pago', 'subsidio'];
|
||||
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pago', 'subsidio'],
|
||||
[$model->ahorro->id, $model->subsidio->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['pago', 'subsidio'], $new_data);
|
||||
}
|
||||
}
|
40
app/src/Repository/Venta/TipoEstadoVenta.php
Normal file
40
app/src/Repository/Venta/TipoEstadoVenta.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoVenta extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_venta');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'activa' => [
|
||||
'function' => function($data) {
|
||||
return $data['activa'] !== 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoEstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'activa'],
|
||||
[$model->descripcion, $model->activa ? 1 : 0]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'activa'], $new_data);
|
||||
}
|
||||
}
|
35
app/src/Repository/Venta/TipoValorCierre.php
Normal file
35
app/src/Repository/Venta/TipoValorCierre.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoValorCierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_valor_cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoValorCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion'],
|
||||
[$model->descripcion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion'], $new_data);
|
||||
}
|
||||
}
|
@ -43,6 +43,15 @@ class Unidad extends Ideal\Repository
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`
|
||||
WHERE pu.`propiedad` = ?
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$propiedad_id]);
|
||||
}
|
||||
public function fetchByCierre(int $cierre_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -51,6 +60,7 @@ FROM `{$this->getTable()}` a
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
WHERE uc.`cierre` = ?
|
||||
GROUP BY a.`id`
|
||||
ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')";
|
||||
return $this->fetchMany($query, [$cierre_id]);
|
||||
}
|
||||
|
55
app/src/Repository/Venta/ValorCierre.php
Normal file
55
app/src/Repository/Venta/ValorCierre.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class ValorCierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection,
|
||||
protected Repository\Venta\Cierre $cierreRepository,
|
||||
protected Repository\Venta\TipoValorCierre $tipoValorCierreRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('valor_cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'cierre' => [
|
||||
'function' => function($data) {
|
||||
return $this->cierreRepository->fetchById($data['cierre']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoValorCierre',
|
||||
'function' => function($data) {
|
||||
return $this->tipoValorCierreRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'valor' => []
|
||||
];
|
||||
return $this->parseData(new Model\Venta\ValorCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['cierre', 'tipo', 'valor'],
|
||||
[$model->cierre->id, $model->tipoValorCierre->id, $model->valor]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['cierre', 'tipo', 'valor'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByCierre(int $cierre_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `cierre` = ?";
|
||||
return $this->fetchMany($query, [$cierre_id]);
|
||||
}
|
||||
}
|
13
app/src/Service/Proyecto.php
Normal file
13
app/src/Service/Proyecto.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyecto
|
||||
{
|
||||
public function __construct(protected Repository\Proyecto $proyectoRepository) {}
|
||||
public function getVendibles(): array
|
||||
{
|
||||
return $this->proyectoRepository->fetchAllActive();
|
||||
}
|
||||
}
|
22
app/src/Service/Venta.php
Normal file
22
app/src/Service/Venta.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Venta
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta $ventaRepository,
|
||||
protected Repository\Venta\EstadoVenta $estadoVentaRepository
|
||||
) {}
|
||||
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($ventas as &$venta) {
|
||||
$venta->estados = $this->estadoVentaRepository->fetchByVenta($venta->id);
|
||||
$venta->currentEstado = $this->estadoVentaRepository->fetchCurrentByVenta($venta->id);
|
||||
}
|
||||
return $ventas;
|
||||
}
|
||||
}
|
@ -2,13 +2,17 @@
|
||||
namespace Incoviba\Service\Ventas;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cierre
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Cierre $cierreRepository,
|
||||
protected Repository\Venta\EstadoCierre $estadoCierreRepository,
|
||||
protected Repository\Venta\Unidad $unidadRepository) {}
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Repository\Venta\ValorCierre $valorCierreRepository,
|
||||
protected Repository\Venta\Precio $precioRepository
|
||||
) {}
|
||||
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
@ -20,4 +24,16 @@ class Cierre
|
||||
}
|
||||
return $cierres;
|
||||
}
|
||||
public function getById(int $cierre_id): Model\Venta\Cierre
|
||||
{
|
||||
$cierre = $this->cierreRepository->fetchById($cierre_id);
|
||||
$cierre->estados = $this->estadoCierreRepository->fetchByCierre($cierre_id);
|
||||
$cierre->current = $this->estadoCierreRepository->fetchCurrentByCierre($cierre_id);
|
||||
$cierre->unidades = $this->unidadRepository->fetchByCierre($cierre_id);
|
||||
foreach ($cierre->unidades as &$unidad) {
|
||||
$unidad->currentPrecio = $this->precioRepository->fetchByUnidadAndDate($unidad->id, $cierre->dateTime->format('Y-m-d'));
|
||||
}
|
||||
$cierre->valoresCierre = $this->valorCierreRepository->fetchByCierre($cierre_id);
|
||||
return $cierre;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Service\Ventas;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Precio
|
||||
{
|
||||
@ -16,4 +17,11 @@ class Precio
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
public function getByUnidad(int $unidad_id): Model\Venta\Precio
|
||||
{
|
||||
$precio = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
return $precio;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user