Implemented repository mapper, and venta show
This commit is contained in:
9
app/common/Define/Repository/Factory.php
Normal file
9
app/common/Define/Repository/Factory.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define\Repository;
|
||||
|
||||
interface Factory
|
||||
{
|
||||
public function setCallable(callable $callable): Factory;
|
||||
public function setArgs(array $args): Factory;
|
||||
public function run(): mixed;
|
||||
}
|
15
app/common/Define/Repository/Mapper.php
Normal file
15
app/common/Define/Repository/Mapper.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define\Repository;
|
||||
|
||||
interface Mapper
|
||||
{
|
||||
public function setProperty(string $property): Mapper;
|
||||
public function setFunction(callable $function): Mapper;
|
||||
public function setFactory(Factory $factory): Mapper;
|
||||
public function setDefault(mixed $value): Mapper;
|
||||
|
||||
public function hasProperty(): bool;
|
||||
public function hasFunction(): bool;
|
||||
public function hasFactory(): bool;
|
||||
public function hasDefault(): bool;
|
||||
}
|
10
app/common/Define/Repository/MapperParser.php
Normal file
10
app/common/Define/Repository/MapperParser.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define\Repository;
|
||||
|
||||
interface MapperParser
|
||||
{
|
||||
public function register(string $column, ?Mapper $mapper = null): MapperParser;
|
||||
public function getColumns(): array;
|
||||
public function hasMapper(string $column): bool;
|
||||
public function getMapper(string $column): Mapper;
|
||||
}
|
@ -7,6 +7,19 @@ abstract class Model implements Define\Model
|
||||
{
|
||||
public int $id;
|
||||
|
||||
protected array $factories;
|
||||
|
||||
public function addFactory(string $property, Define\Repository\Factory $factory): Model
|
||||
{
|
||||
$this->factories[$property] = $factory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function runFactory(string $property): mixed
|
||||
{
|
||||
return $this->factories[$property]->run();
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
|
@ -1,10 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use PDO;
|
||||
use Incoviba\Common\Define\Model;
|
||||
use ReflectionProperty;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
|
||||
abstract class Repository implements Define\Repository
|
||||
{
|
||||
@ -21,14 +22,14 @@ abstract class Repository implements Define\Repository
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function load(array $data_row): Model
|
||||
public function load(array $data_row): Define\Model
|
||||
{
|
||||
$model = $this->create($data_row);
|
||||
$model->{$this->getKey()} = $data_row[$this->getKey()];
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function remove(Model $model): void
|
||||
public function remove(Define\Model $model): void
|
||||
{
|
||||
$query = "DELETE FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?";
|
||||
$this->connection->execute($query, [$model->getId()]);
|
||||
@ -49,26 +50,50 @@ abstract class Repository implements Define\Repository
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
protected function parseData(Define\Model $model, ?array $data, array $data_map): Define\Model
|
||||
protected function parseData(Define\Model $model, ?array $data, Implement\Repository\MapperParser $data_map): Define\Model
|
||||
{
|
||||
if ($data === null) {
|
||||
return $model;
|
||||
}
|
||||
foreach ($data_map as $column => $settings) {
|
||||
if (isset($data[$column])) {
|
||||
$property = $column;
|
||||
if (isset($settings['property'])) {
|
||||
$property = $settings['property'];
|
||||
}
|
||||
$value = $data[$column];
|
||||
if (isset($settings['function'])) {
|
||||
$value = $settings['function']($data);
|
||||
}
|
||||
$model->{$property} = $value;
|
||||
foreach ($data_map->getColumns() as $column) {
|
||||
if (!$data_map->hasMapper($column)) {
|
||||
$this->parsePlainColumn($model, $column, $data);
|
||||
continue;
|
||||
}
|
||||
|
||||
$settings = $data_map->getMapper($column);
|
||||
if ($settings->parse($model, $column, $data)) {
|
||||
continue;
|
||||
}
|
||||
$property = $column;
|
||||
if ($settings->hasProperty()) {
|
||||
$property = $settings->property;
|
||||
}
|
||||
$this->setDefault($model, $property);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
protected function parsePlainColumn(Define\Model &$model, string $column, ?array $data): void
|
||||
{
|
||||
$property = $column;
|
||||
if (isset($data[$column])) {
|
||||
$model->{$property} = $data[$column];
|
||||
return;
|
||||
}
|
||||
$this->setDefault($model, $property);
|
||||
}
|
||||
protected function setDefault(Define\Model &$model, string $property): void
|
||||
{
|
||||
$prop = new ReflectionProperty($model, $property);
|
||||
$type = $prop->getType()->getName();
|
||||
$value = match ($type) {
|
||||
'int' => 0,
|
||||
'float' => 0.0,
|
||||
'string' => '',
|
||||
default => null,
|
||||
};
|
||||
$model->{$property} = $value;
|
||||
}
|
||||
protected function saveNew(array $columns, array $values): int
|
||||
{
|
||||
$columns_string = implode(', ', array_map(function($column) {return "`{$column}`";}, $columns));
|
||||
|
27
app/common/Implement/Repository/Factory.php
Normal file
27
app/common/Implement/Repository/Factory.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Repository;
|
||||
|
||||
use Closure;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class Factory implements Define\Repository\Factory
|
||||
{
|
||||
public Closure $callable;
|
||||
public array $args;
|
||||
|
||||
public function setCallable(callable $callable): Define\Repository\Factory
|
||||
{
|
||||
$this->callable = $callable(...);
|
||||
return $this;
|
||||
}
|
||||
public function setArgs(array $args): Define\Repository\Factory
|
||||
{
|
||||
$this->args = $args;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function run(): mixed
|
||||
{
|
||||
return call_user_func_array($this->callable, $this->args);
|
||||
}
|
||||
}
|
76
app/common/Implement/Repository/Mapper.php
Normal file
76
app/common/Implement/Repository/Mapper.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Repository;
|
||||
|
||||
use Closure;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class Mapper implements Define\Repository\Mapper
|
||||
{
|
||||
public string $property;
|
||||
public Closure $function;
|
||||
public Define\Repository\Factory $factory;
|
||||
public mixed $default;
|
||||
|
||||
public function setProperty(string $property): Define\Repository\Mapper
|
||||
{
|
||||
$this->property = $property;
|
||||
return $this;
|
||||
}
|
||||
public function setFunction(callable $function): Define\Repository\Mapper
|
||||
{
|
||||
$this->function = $function(...);
|
||||
return $this;
|
||||
}
|
||||
public function setFactory(Define\Repository\Factory $factory): Define\Repository\Mapper
|
||||
{
|
||||
$this->factory = $factory;
|
||||
return $this;
|
||||
}
|
||||
public function setDefault(mixed $value): Define\Repository\Mapper
|
||||
{
|
||||
$this->default = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasProperty(): bool
|
||||
{
|
||||
return isset($this->property);
|
||||
}
|
||||
public function hasFunction(): bool
|
||||
{
|
||||
return isset($this->function);
|
||||
}
|
||||
public function hasFactory(): bool
|
||||
{
|
||||
return isset($this->factory);
|
||||
}
|
||||
public function hasDefault(): bool
|
||||
{
|
||||
return isset($this->default);
|
||||
}
|
||||
|
||||
public function parse(Define\Model &$model, string $column, ?array $data): bool
|
||||
{
|
||||
$property = $column;
|
||||
if ($this->hasProperty()) {
|
||||
$property = $this->property;
|
||||
}
|
||||
if (isset($data[$column])) {
|
||||
if ($this->hasFactory()) {
|
||||
$model->addFactory($property, $this->factory);
|
||||
return true;
|
||||
}
|
||||
$value = $data[$column];
|
||||
if ($this->hasFunction()) {
|
||||
$value = ($this->function)($data);
|
||||
}
|
||||
$model->{$property} = $value;
|
||||
return true;
|
||||
}
|
||||
if ($this->hasDefault()) {
|
||||
$model->{$property} = $this->default;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
17
app/common/Implement/Repository/Mapper/Boolean.php
Normal file
17
app/common/Implement/Repository/Mapper/Boolean.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Repository\Mapper;
|
||||
|
||||
use Incoviba\Common\Implement\Repository\Mapper;
|
||||
|
||||
class Boolean extends Mapper
|
||||
{
|
||||
public function __construct(string $column, ?string $property = null)
|
||||
{
|
||||
$this->setFunction(function($data) use ($column) {
|
||||
return $data[$column] !== 0;
|
||||
});
|
||||
if ($property !== null) {
|
||||
$this->setProperty($property);
|
||||
}
|
||||
}
|
||||
}
|
18
app/common/Implement/Repository/Mapper/DateTime.php
Normal file
18
app/common/Implement/Repository/Mapper/DateTime.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Repository\Mapper;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Implement\Repository\Mapper;
|
||||
|
||||
class DateTime extends Mapper
|
||||
{
|
||||
public function __construct(string $column, ?string $property = null)
|
||||
{
|
||||
$this->setFunction(function($data) use ($column) {
|
||||
return new DateTimeImmutable($data[$column]);
|
||||
});
|
||||
if ($property !== null) {
|
||||
$this->setProperty($property);
|
||||
}
|
||||
}
|
||||
}
|
41
app/common/Implement/Repository/MapperParser.php
Normal file
41
app/common/Implement/Repository/MapperParser.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Implement\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Define\Repository\Mapper;
|
||||
|
||||
class MapperParser implements Define\Repository\MapperParser
|
||||
{
|
||||
public function __construct(?array $columns = null)
|
||||
{
|
||||
if ($columns !== null) {
|
||||
foreach ($columns as $column) {
|
||||
$this->register($column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected array $maps;
|
||||
|
||||
public function register(string $column, ?Mapper $mapper = null): Define\Repository\MapperParser
|
||||
{
|
||||
if ($mapper !== null) {
|
||||
$this->maps[$column] = $mapper;
|
||||
return $this;
|
||||
}
|
||||
$this->maps[$column] = [];
|
||||
return $this;
|
||||
}
|
||||
public function getColumns(): array
|
||||
{
|
||||
return array_keys($this->maps);
|
||||
}
|
||||
public function hasMapper(string $column): bool
|
||||
{
|
||||
return is_a($this->maps[$column], Define\Repository\Mapper::class);
|
||||
}
|
||||
public function getMapper(string $column): Mapper
|
||||
{
|
||||
return $this->maps[$column];
|
||||
}
|
||||
}
|
@ -11,3 +11,16 @@ $app->group('/ventas', function($app) {
|
||||
}
|
||||
$app->get('[/]', Ventas::class);
|
||||
});
|
||||
$app->group('/venta/{proyecto_nombre:[A-za-zÑñ\+\ %0-9]+}/{unidad_descripcion:[0-9]+}', function($app) {
|
||||
$app->get('[/]', [Ventas::class, 'showUnidad']);
|
||||
});
|
||||
$app->group('/venta/{venta_id:[0-9]+}', function($app) {
|
||||
$app->group('/propietario', function($app) {
|
||||
$app->get('[/]', [Ventas::class, 'propietario']);
|
||||
});
|
||||
$app->group('/propiedad', function($app) {
|
||||
$app->get('[/]', [Ventas::class, 'propiedad']);
|
||||
});
|
||||
$app->get('/edit[/]', [Ventas::class, 'edit']);
|
||||
$app->get('[/]', [Ventas::class, 'show']);
|
||||
});
|
||||
|
11
app/resources/routes/api/direcciones.php
Normal file
11
app/resources/routes/api/direcciones.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Direcciones;
|
||||
|
||||
$app->group('/direcciones', function($app) {
|
||||
$app->group('/region/{region_id:[0-9]+}', function($app) {
|
||||
$app->get('/comunas[/]', [Direcciones::class, 'comunas']);
|
||||
});
|
||||
$app->group('/comunas', function($app) {
|
||||
$app->post('/find[/]', [Direcciones::class, 'findComunas']);
|
||||
});
|
||||
});
|
@ -14,3 +14,7 @@ $app->group('/ventas', function($app) {
|
||||
}
|
||||
$app->post('[/]', [Ventas::class, 'proyecto']);
|
||||
});
|
||||
$app->group('/venta/{venta_id}', function($app) {
|
||||
$app->get('/comentarios', [Ventas::class, 'comentarios']);
|
||||
$app->get('[/]', [Ventas::class, 'get']);
|
||||
});
|
||||
|
7
app/resources/routes/api/ventas/pagos.php
Normal file
7
app/resources/routes/api/ventas/pagos.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Pagos;
|
||||
|
||||
$app->group('/pago/{pago_id:[0-9]+}', function($app) {
|
||||
$app->put('/depositar[/]', [Pagos::class, 'depositar']);
|
||||
$app->put('/abonar[/]', [Pagos::class, 'abonar']);
|
||||
});
|
6
app/resources/routes/ventas/propietarios.php
Normal file
6
app/resources/routes/ventas/propietarios.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Propietarios;
|
||||
|
||||
$app->group('/propietario/{propietario_rut:[0-9]+}', function($app) {
|
||||
$app->get('[/]', [Propietarios::class, 'show']);
|
||||
});
|
94
app/resources/views/ventas/edit.blade.php
Normal file
94
app/resources/views/ventas/edit.blade.php
Normal file
@ -0,0 +1,94 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Editar Venta</h2>
|
||||
<form class="ui form" id="edit_form">
|
||||
<div class="inline field">
|
||||
<label for="valor">Valor</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" id="valor" name="valor" value="{{$venta->valor}}" />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inline field">
|
||||
<label for="fecha">Fecha Promesa</label>
|
||||
<div class="ui calendar" id="fecha_calendar">
|
||||
<div class="ui icon input">
|
||||
<input type="text" name="fecha" id="fecha" />
|
||||
<i class="calendar icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button">
|
||||
Guardar
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
function getMonthsList() {
|
||||
const formatter = new Intl.DateTimeFormat('es-CL', {month: 'long'})
|
||||
const months = []
|
||||
let m = ''
|
||||
for (let i = 0; i < 12; i ++) {
|
||||
m = formatter.format((new Date()).setMonth(i))
|
||||
months.push(m.charAt(0).toUpperCase() + m.slice(1))
|
||||
}
|
||||
return months
|
||||
}
|
||||
function redirect() {
|
||||
const uri = '{{$urls->base}}/venta/{{$venta->id}}'
|
||||
window.location = uri
|
||||
}
|
||||
function editVenta() {
|
||||
const original = {
|
||||
valor: {{$venta->valor}},
|
||||
fecha: new Date('{{$venta->fecha->format('Y-m-d')}}T00:00:00')
|
||||
}
|
||||
const collator = new Intl.Collator('es-CL')
|
||||
const data = {}
|
||||
Object.keys(original).forEach(name => {
|
||||
let val = $("[name='" + name + "']").val()
|
||||
if (name === 'fecha') {
|
||||
val = $('#fecha_calendar').calendar('get date')
|
||||
if (val.getTime() !== original[name].getTime()) {
|
||||
data[name] = [val.getFullYear(), (''+(val.getMonth()+1)).padStart(2, '0'), (''+val.getDate()).padStart(2, '0')].join('-')
|
||||
}
|
||||
return
|
||||
}
|
||||
if (collator.compare(val, original[name]) !== 0) {
|
||||
data[name] = val
|
||||
}
|
||||
})
|
||||
if (Object.keys(data).length === 0) {
|
||||
redirect()
|
||||
return
|
||||
}
|
||||
const uri = '{{$urls->api}}/venta/{{$venta->id}}'
|
||||
return fetch(uri,
|
||||
{method: 'put', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
|
||||
).then(response => {
|
||||
if (response.ok) {
|
||||
redirect()
|
||||
}
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
$('#fecha_calendar').calendar({
|
||||
type: 'date',
|
||||
initialDate: '{{$venta->fecha->format('Y-m-d')}}',
|
||||
text: {
|
||||
months: getMonthsList()
|
||||
}
|
||||
})
|
||||
$('#edit_form').submit(event => {
|
||||
event.preventDefault()
|
||||
editVenta()
|
||||
return false
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -87,6 +87,7 @@
|
||||
id: 0,
|
||||
proyecto: '',
|
||||
proyectos: JSON.parse('{!! json_encode($proyectos) !!}'),
|
||||
venta_ids: [],
|
||||
ventas: []
|
||||
},
|
||||
loading: {
|
||||
@ -100,6 +101,7 @@
|
||||
get: function() {
|
||||
return {
|
||||
ventas: proyecto_id => {
|
||||
this.data.venta_ids = []
|
||||
this.data.ventas = []
|
||||
return fetch('{{$urls->api}}/ventas',
|
||||
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}
|
||||
@ -110,14 +112,31 @@
|
||||
}
|
||||
}).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.data.id = data.proyecto.id
|
||||
this.data.proyecto = data.proyecto.descripcion
|
||||
this.data.venta_ids = data.ventas
|
||||
const promises = []
|
||||
data.ventas.forEach(venta_id => {
|
||||
promises.push(this.get().venta(venta_id))
|
||||
})
|
||||
Promise.all(promises).then(() => {
|
||||
this.draw().ventas()
|
||||
})
|
||||
this.draw().ventas()
|
||||
}
|
||||
})
|
||||
},
|
||||
venta: venta_id => {
|
||||
return fetch('{{$urls->api}}/venta/' + venta_id).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (typeof data.venta === 'undefined') {
|
||||
console.error(venta_id, data.error)
|
||||
return
|
||||
}
|
||||
this.add().venta(data.venta)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
104
app/resources/views/ventas/propiedades/edit.blade.php
Normal file
104
app/resources/views/ventas/propiedades/edit.blade.php
Normal file
@ -0,0 +1,104 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2>Editar Propiedad - {{$proyecto->descripcion}} {{$propiedad->summary()}}</h2>
|
||||
<table class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo</th>
|
||||
<th>Unidad</th>
|
||||
<th class="right aligned">
|
||||
<button class="ui small green circular icon button" id="add_unidad">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($propiedad->unidades as $unidad)
|
||||
<tr>
|
||||
<td>{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}</td>
|
||||
<td>{{$unidad->descripcion}}</td>
|
||||
<td class="right aligned">
|
||||
<button class="ui small red circular icon button remove_unidad" data-id="{{$unidad->id}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="ui modal" id="add_modal">
|
||||
<div class="content">
|
||||
<h3 class="header">Agregar</h3>
|
||||
<div class="ui form" id="add_form">
|
||||
<div class="field">
|
||||
<label for="tipo">Tipo</label>
|
||||
<select id="tipo" name="tipo" class="ui search selection dropdown">
|
||||
@foreach ($tiposUnidades as $tipoUnidad)
|
||||
<option value="{{$tipoUnidad->id}}">{{ucwords($tipoUnidad->descripcion)}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="unidad">Unidad</label>
|
||||
<select id="unidad" name="unidad" class="ui search selection dropdown" size="4"></select>
|
||||
</div>
|
||||
<button class="ui button">Agregar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const unidades = {
|
||||
@foreach($tiposUnidades as $tipoUnidad)
|
||||
{{$tipoUnidad->id}}: [
|
||||
@foreach($unidades as $unidad)
|
||||
@if ($unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id)
|
||||
{
|
||||
value: {{$unidad->id}},
|
||||
text: '{{$unidad->descripcion}}',
|
||||
name: '{{$unidad->descripcion}}'
|
||||
},
|
||||
@endif
|
||||
@endforeach
|
||||
],
|
||||
@endforeach
|
||||
}
|
||||
function changeTipoUnidad(tipo_unidad_id) {
|
||||
$('#unidad').dropdown('change values', unidades[tipo_unidad_id].sort((a, b) => a.text.padStart(4, '0').localeCompare(b.text.padStart(4, '0'))))
|
||||
}
|
||||
function addUnidad() {
|
||||
$('#add_modal').modal('show')
|
||||
}
|
||||
function removeUnidad(unidad_id) {
|
||||
console.debug(unidad_id)
|
||||
}
|
||||
$(document).ready(() => {
|
||||
$('#add_unidad').click(event => {
|
||||
addUnidad()
|
||||
})
|
||||
$('.remove_unidad').click(event => {
|
||||
const unidad_id = $(event.currentTarget).data('id')
|
||||
removeUnidad(unidad_id)
|
||||
})
|
||||
$('#add_modal').modal()
|
||||
const tipo = $('#tipo')
|
||||
tipo.dropdown()
|
||||
tipo.change(event => {
|
||||
changeTipoUnidad(tipo.val())
|
||||
})
|
||||
$('#unidad').dropdown()
|
||||
changeTipoUnidad(tipo.val())
|
||||
$('#add_form').submit(event => {
|
||||
event.preventDefault()
|
||||
tipo.model('hide')
|
||||
return false
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
226
app/resources/views/ventas/propietarios/edit.blade.php
Normal file
226
app/resources/views/ventas/propietarios/edit.blade.php
Normal file
@ -0,0 +1,226 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Editar Propietario
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Editar Propietario</h2>
|
||||
<form class="ui form" id="edit_form">
|
||||
<input type="hidden" name="venta_id" value="{{$venta_id}}" />
|
||||
<div class="field">
|
||||
<label for="rut">RUT</label>
|
||||
{{$propietario->rut()}}
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="nombres">Nombre</label>
|
||||
<input type="text" name="nombres" id="nombres" value="{{trim($propietario->nombres)}}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="apellido_paterno">Apellido Paterno</label>
|
||||
<input type="text" id="apellido_paterno" name="apellido_paterno" value="{{$propietario->apellidos['paterno']}}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="apellido_materno">Apellido Materno</label>
|
||||
<input type="text" id="apellido_materno" name="apellido_materno" value="{{$propietario->apellidos['materno']}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="calle">Dirección</label>
|
||||
<input type="text" name="calle" id="calle" value="{{$propietario->datos->direccion->calle}}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="numero">Número</label>
|
||||
<input type="number" id="numero" size="6" name="numero" value="{{$propietario->datos->direccion->numero}}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="extra">Información Adicional*</label>
|
||||
<input type="text" id="extra" name="extra" value="{{$propietario->datos->direccion->extra}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="region">Región</label>
|
||||
<select id="region" name="region" class="ui search selection dropdown">
|
||||
@foreach($regiones as $region)
|
||||
<option value="{{$region->id}}"{{($propietario->datos->direccion->comuna->provincia->region->id === $region->id) ? ' selected="selected"' : ''}}>{{$region->numeral}} {{$region->descripcion}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="comunas">Comuna</label>
|
||||
<select class="ui search selection dropdown" name="comuna" id="comunas"></select>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button" id="guardar_button">Guardar</button>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
function drawComunas({parent, comunas}) {
|
||||
parent.html('')
|
||||
comunas.forEach(comuna => {
|
||||
const option = $('<option></option>')
|
||||
option.attr('value', comuna.id).html(comuna.descripcion)
|
||||
if (comuna.id === {{$propietario->datos->direccion->comuna->id}}) {
|
||||
option.prop('selected', true)
|
||||
}
|
||||
parent.append(option)
|
||||
})
|
||||
parent.show()
|
||||
parent.dropdown()
|
||||
}
|
||||
function findComunas(direccion) {
|
||||
const original_id = $("[name='comuna']").val()
|
||||
const uri = '{{$urls->api}}/direcciones/comunas/find'
|
||||
const data = {direccion}
|
||||
return fetch(uri,
|
||||
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
|
||||
).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.total === 0) {
|
||||
return
|
||||
}
|
||||
const comuna_id = data.comunas[0].id
|
||||
if (comuna_id === original_id) {
|
||||
return
|
||||
}
|
||||
const parent = $('#comunas')
|
||||
parent.dropdown('set selected', comuna_id)
|
||||
})
|
||||
}
|
||||
function getComunas(region_id) {
|
||||
const parent = $('#comunas')
|
||||
parent.hide()
|
||||
const uri = '{{$urls->api}}/direcciones/region/' + region_id + '/comunas'
|
||||
return fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.total === 0) {
|
||||
return
|
||||
}
|
||||
drawComunas({parent, comunas: data.comunas})
|
||||
})
|
||||
}
|
||||
function redirect() {
|
||||
window.location = '{{$urls->base}}/venta/{{$venta_id}}'
|
||||
}
|
||||
function changeDireccion() {
|
||||
const names = [
|
||||
'calle',
|
||||
'numero',
|
||||
'extra'
|
||||
]
|
||||
const originals = [
|
||||
'{{trim($propietario->datos->direccion->calle)}}',
|
||||
'{{trim($propietario->datos->direccion->numero)}}',
|
||||
'{{trim($propietario->datos->direccion->extra)}}'
|
||||
]
|
||||
const values = []
|
||||
names.forEach(name => {
|
||||
const val = $("[name='" + name + "']").val()
|
||||
values.push(val)
|
||||
})
|
||||
const collator = new Intl.Collator('es')
|
||||
if (collator.compare(originals.join(' '), values.join(' ')) !== 0) {
|
||||
findComunas(values.join(' ').trim())
|
||||
}
|
||||
}
|
||||
function watchChangeDireccion() {
|
||||
const watched = [
|
||||
'calle',
|
||||
'numero',
|
||||
'extra'
|
||||
]
|
||||
watched.forEach(name => {
|
||||
$("[name='" + name + "']").change(event => {
|
||||
changeDireccion()
|
||||
})
|
||||
})
|
||||
}
|
||||
function editPropietario() {
|
||||
const uri = '{{$urls->api}}/ventas/propietario/{{$propietario->rut}}'
|
||||
const names = [
|
||||
'nombres',
|
||||
'apellido_paterno',
|
||||
'apellido_materno'
|
||||
]
|
||||
const values = [
|
||||
'{{trim($propietario->nombres)}}',
|
||||
'{{trim($propietario->apellidos['paterno'])}}',
|
||||
'{{trim($propietario->apellidos['materno'])}}'
|
||||
]
|
||||
const direccion_names = [
|
||||
'calle',
|
||||
'numero',
|
||||
'extra',
|
||||
'comuna'
|
||||
]
|
||||
const direccion_values = [
|
||||
'{{trim($propietario->datos->direccion->calle)}}',
|
||||
'{{$propietario->datos->direccion->numero}}',
|
||||
'{{trim($propietario->datos->direccion->extra)}}',
|
||||
'{{$propietario->datos->direccion->comuna->id}}'
|
||||
]
|
||||
const data = {}
|
||||
const collator = new Intl.Collator('es')
|
||||
names.forEach((name, index) => {
|
||||
const val = $("[name='" + name + "']").val()
|
||||
if (collator.compare(val, values[index]) !== 0) {
|
||||
console.debug(name, val, values[index], collator.compare(val, values[index]))
|
||||
data[name] = val
|
||||
}
|
||||
})
|
||||
direccion_names.forEach((name, index) => {
|
||||
const val = $("[name='" + name + "']").val()
|
||||
if (collator.compare(val, direccion_values[index]) !== 0) {
|
||||
if (typeof data['direccion'] === 'undefined') {
|
||||
data['direccion'] = {}
|
||||
}
|
||||
console.debug(name, val, direccion_values[index])
|
||||
data['direccion'][name] = val
|
||||
}
|
||||
})
|
||||
if (Object.keys(data).length === 0) {
|
||||
redirect()
|
||||
return
|
||||
}
|
||||
return fetch(uri,
|
||||
{method: 'put', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
|
||||
).then(response => {
|
||||
if (response.ok) {
|
||||
redirect()
|
||||
}
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
const regiones = $("select[name='region']")
|
||||
regiones.dropdown()
|
||||
regiones.change(event => {
|
||||
const region_id = $(event.currentTarget).val()
|
||||
getComunas(region_id)
|
||||
})
|
||||
$('#comunas').hide()
|
||||
getComunas({{$propietario->datos->direccion->comuna->provincia->region->id}})
|
||||
$('#edit_form').submit(event => {
|
||||
event.preventDefault()
|
||||
editPropietario({{$propietario->rut}})
|
||||
return false
|
||||
})
|
||||
$('#guardar_button').click(event => {
|
||||
editPropietario({{$propietario->rut}})
|
||||
})
|
||||
watchChangeDireccion()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
7
app/resources/views/ventas/propietarios/show.blade.php
Normal file
7
app/resources/views/ventas/propietarios/show.blade.php
Normal file
@ -0,0 +1,7 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
{{$propietario->nombreCompleto()}}
|
||||
</div>
|
||||
@endsection
|
40
app/resources/views/ventas/show.blade.php
Normal file
40
app/resources/views/ventas/show.blade.php
Normal file
@ -0,0 +1,40 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Venta {{$venta->proyecto()->descripcion}} {{$venta->propiedad()->summary()}}
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<div class="ui two column grid">
|
||||
<h1 class="four wide column header">
|
||||
<div class="content">
|
||||
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
|
||||
{{$venta->propiedad()->summary()}}
|
||||
</div>
|
||||
</h1>
|
||||
<div class="right floated column">
|
||||
@include('ventas.show.propietario')
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="ui fitted basic mini segment">
|
||||
@if ($venta->currentEstado()->tipoEstadoVenta->activa)
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/desistir">
|
||||
Desistir <i class="minus icon"></i>
|
||||
</a>
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/ceder">
|
||||
Ceder <i clasS="right chevron icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
<div class="ui segments">
|
||||
@include('ventas.show.propiedad')
|
||||
@include('ventas.show.detalle')
|
||||
@include('ventas.show.forma_pago', ['formaPago' => $venta->formaPago()])
|
||||
@include('ventas.show.escritura')
|
||||
@include('ventas.show.entrega')
|
||||
@include('ventas.show.comentarios')
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
88
app/resources/views/ventas/show/comentarios.blade.php
Normal file
88
app/resources/views/ventas/show/comentarios.blade.php
Normal file
@ -0,0 +1,88 @@
|
||||
<div class="ui inverted grey two column grid segment">
|
||||
<div class="column">
|
||||
COMENTARIOS
|
||||
</div>
|
||||
<div class="right aligned column">
|
||||
<a href="javascript: addComment()" style="color: inherit;">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<table class="ui very basic table">
|
||||
<tbody id="comentarios"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Comentario
|
||||
{
|
||||
fecha
|
||||
texto
|
||||
|
||||
constructor({fecha, texto})
|
||||
{
|
||||
this.fecha = new Date(fecha + 'T00:00:00')
|
||||
this.texto = texto
|
||||
}
|
||||
draw(dateFormatter)
|
||||
{
|
||||
return $('<tr></tr>').append(
|
||||
$('<td></td>').html(dateFormatter.format(this.fecha))
|
||||
).append(
|
||||
$('<td></td>').html(this.texto)
|
||||
).append(
|
||||
$('<td></td>').addClass('right aligned').append(
|
||||
$('<a></a>').attr('href', 'javascript: removeComment();').append(
|
||||
$('<i></i>').addClass('minus icon')
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
const comentarios = {
|
||||
comentarios: [],
|
||||
id: '',
|
||||
fetch: function() {
|
||||
return {
|
||||
comentarios: () => {
|
||||
const uri = '{{$urls->api}}/venta/{{$venta->id}}/comentarios'
|
||||
return fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.total === 0) {
|
||||
return
|
||||
}
|
||||
data.comentarios.forEach(settings => {
|
||||
this.comentarios.push(new Comentario(settings))
|
||||
})
|
||||
this.draw().comentarios()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
comentarios: () => {
|
||||
const body = $(this.id)
|
||||
const dateFormatter = new Intl.DateTimeFormat('es-CL', {dateStyle: 'medium'})
|
||||
body.html('')
|
||||
this.comentarios.forEach(comentario => {
|
||||
body.append(comentario.draw(dateFormatter))
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup: function(id) {
|
||||
this.id = id
|
||||
this.fetch().comentarios()
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
comentarios.setup('#comentarios')
|
||||
})
|
||||
</script>
|
||||
@endpush
|
38
app/resources/views/ventas/show/detalle.blade.php
Normal file
38
app/resources/views/ventas/show/detalle.blade.php
Normal file
@ -0,0 +1,38 @@
|
||||
<div class="ui inverted grey two column grid segment">
|
||||
<div class="column">
|
||||
VENTA
|
||||
</div>
|
||||
<div class="right aligned column">
|
||||
<a style="color: inherit;" href="{{$urls->base}}/venta/{{$venta->id}}/edit">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<table class="ui very basic fluid table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Valor Promesa</th>
|
||||
<th>Valor Util</th>
|
||||
<th>UF/m²</th>
|
||||
<th>Comisión</th>
|
||||
<th>
|
||||
Fecha Promesa <br/>
|
||||
Fecha Ingreso
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{$format->ufs($venta->valor)}}</td>
|
||||
<td>{{$format->ufs($venta->util())}}</td>
|
||||
<td>{{$format->number($venta->util() / $venta->propiedad()->vendible(), 2)}} UF/m²</td>
|
||||
<td>0,00 UF (0,00%)</td>
|
||||
<td>
|
||||
{{$venta->fecha->format('d-m-Y')}}<br/>
|
||||
{{$venta->fechaIngreso->format('d-m-Y')}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
11
app/resources/views/ventas/show/entrega.blade.php
Normal file
11
app/resources/views/ventas/show/entrega.blade.php
Normal file
@ -0,0 +1,11 @@
|
||||
<div class="ui inverted grey segment">
|
||||
ENTREGA
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
@if ($venta->entrega() !== null)
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/entregar">
|
||||
No <i class="right chevron icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
22
app/resources/views/ventas/show/escritura.blade.php
Normal file
22
app/resources/views/ventas/show/escritura.blade.php
Normal file
@ -0,0 +1,22 @@
|
||||
<div class="ui inverted grey segment">
|
||||
ESCRITURA
|
||||
</div>
|
||||
@if ($venta->formaPago()->escritura !== null)
|
||||
<div class="ui segment">
|
||||
Escriturado {{$venta->formaPago()->escritura->fecha->format('d-m-Y')}}
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/informe">
|
||||
Informe
|
||||
<i class="right chevron icon"></i>
|
||||
</a>
|
||||
<br />
|
||||
<a href="{{$urls->base}}/venta{{$venta->id}}/escritura/firmar">
|
||||
Firmar
|
||||
</a>
|
||||
</div>
|
||||
@else
|
||||
<div class="ui segment">
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escriturar">
|
||||
Escriturar
|
||||
</a>
|
||||
</div>
|
||||
@endif
|
229
app/resources/views/ventas/show/forma_pago.blade.php
Normal file
229
app/resources/views/ventas/show/forma_pago.blade.php
Normal file
@ -0,0 +1,229 @@
|
||||
<div class="ui inverted grey segment">
|
||||
FORMA DE PAGO
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<table class="ui very basic fluid table">
|
||||
@include('ventas.show.forma_pago.pie', ['pie' => $formaPago->pie])
|
||||
@include('ventas.show.forma_pago.escritura', ['escritura' => $formaPago->escritura])
|
||||
@include('ventas.show.forma_pago.anticipo', ['anticipo' => ['uf' => $formaPago->anticipo(), 'pesos' => $formaPago->anticipo('pesos')]])
|
||||
@include('ventas.show.forma_pago.bono_pie', ['bonoPie' => $formaPago->bonoPie])
|
||||
@include('ventas.show.forma_pago.subsidio', ['subsidio' => $formaPago->subsidio])
|
||||
@include('ventas.show.forma_pago.credito', ['credito' => $formaPago->credito])
|
||||
@include('ventas.show.forma_pago.total')
|
||||
@include('ventas.show.forma_pago.devolucion', ['devolucion' => $formaPago->devolucion])
|
||||
</table>
|
||||
</div>
|
||||
<div id="pago_modal" class="ui modal">
|
||||
<div class="content">
|
||||
<div class="ui form">
|
||||
<div class="inline field">
|
||||
<label for="fecha">Fecha</label>
|
||||
<div class="ui calendar">
|
||||
<div class="ui icon input">
|
||||
<input id="fecha" name="fecha" type="text" />
|
||||
<i class="calendar icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button">
|
||||
Guardar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Anchor
|
||||
{
|
||||
classes
|
||||
title
|
||||
row_id
|
||||
pago_id
|
||||
method
|
||||
icon
|
||||
status
|
||||
|
||||
constructor({classes, title, row_id, pago_id, method, icon})
|
||||
{
|
||||
this.classes = classes
|
||||
this.title = title
|
||||
this.row_id = row_id
|
||||
this.pago_id = pago_id
|
||||
this.method = method
|
||||
this.icon = icon
|
||||
this.status = true
|
||||
}
|
||||
|
||||
draw()
|
||||
{
|
||||
const row = $(this.row_id)
|
||||
const anchor = row.find('a')
|
||||
|
||||
anchor.attr('class', this.classes)
|
||||
anchor.attr('title', this.title)
|
||||
anchor.attr('href', 'javascript: ' + this.method + "({row_id: '" + this.row_id + "', pago_id: " + this.pago_id + '});')
|
||||
|
||||
anchor.html('')
|
||||
anchor.append(
|
||||
$('<i></i>').addClass(this.icon + ' icon')
|
||||
)
|
||||
}
|
||||
toggle()
|
||||
{
|
||||
if (this.status) {
|
||||
$(this.row_id).find('a').css('pointer-events', 'none')
|
||||
this.status = false
|
||||
return
|
||||
}
|
||||
$(this.row_id).find('a').css('pointer-events', '')
|
||||
this.status = true
|
||||
}
|
||||
}
|
||||
class Cell
|
||||
{
|
||||
id
|
||||
classes
|
||||
text
|
||||
anchor
|
||||
status
|
||||
|
||||
constructor({id, classes, text, anchor})
|
||||
{
|
||||
this.id = id
|
||||
this.classes = classes
|
||||
this.text = text
|
||||
this.anchor = anchor
|
||||
this.status = true
|
||||
}
|
||||
|
||||
draw()
|
||||
{
|
||||
const row = $(this.id)
|
||||
row.attr('class', this.classes)
|
||||
row.html('').append(
|
||||
$('<span></span>').html(this.text)
|
||||
).append(this.anchor.draw())
|
||||
}
|
||||
toggle()
|
||||
{
|
||||
if (this.status) {
|
||||
$(this.id).css('cursor', 'wait')
|
||||
this.status = false
|
||||
return
|
||||
}
|
||||
$(this.id).css('cursor', 'default')
|
||||
this.status = true
|
||||
}
|
||||
}
|
||||
class Modal
|
||||
{
|
||||
id
|
||||
date
|
||||
uri
|
||||
|
||||
constructor({id}) {
|
||||
this.id = id
|
||||
}
|
||||
|
||||
show() {
|
||||
$(this.id).find('div.ui.calendar').calendar('reset')
|
||||
$(this.id).find('div.ui.calendar input').val('')
|
||||
$(this.id).modal('show')
|
||||
}
|
||||
setup() {
|
||||
const modal = $(this.id)
|
||||
modal.modal({
|
||||
onHide: function($element) {
|
||||
const pagos = $("[id$='_pago']")
|
||||
pagos.css('cursor', 'default')
|
||||
const anchor = pagos.find("a")
|
||||
anchor.css('pointer-events', '')
|
||||
}
|
||||
})
|
||||
modal.find('div.ui.calendar').calendar({
|
||||
type: 'date'
|
||||
})
|
||||
}
|
||||
}
|
||||
const pagos = {
|
||||
modal: null,
|
||||
cells: [],
|
||||
|
||||
setup: function({modal_id}) {
|
||||
this.modal = new Modal({id: modal_id})
|
||||
this.modal.setup()
|
||||
},
|
||||
add: function() {
|
||||
return {
|
||||
cell: ({cell_id, classes, text, anchor}) => {
|
||||
this.cells.push(new Cell({id: cell_id, classes, text, anchor}))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
function depositar({row_id, pago_id}) {
|
||||
const row = $(row_id)
|
||||
const anchor = row.find("a[title='Depositar']")
|
||||
const uri = '{{$urls->api}}/ventas/pago/' + pago_id + '/depositar'
|
||||
const modal = $('#pago_modal')
|
||||
|
||||
row.css('cursor', 'wait')
|
||||
anchor.css('pointer-events', 'none')
|
||||
modal.find('#fecha').calendar('clear')
|
||||
modal.modal('show')
|
||||
modal.find('.ui.button').click(event => {
|
||||
modal.modal('hide')
|
||||
const date = modal.find('#fecha').val()
|
||||
return fetch(uri,
|
||||
{method: 'put', body: JSON.stringify({fecha: date}), headers: {'Content-Type': 'application/json'}}
|
||||
).then(response => {
|
||||
anchor.css('pointer-events', '')
|
||||
row.css('cursor', 'default')
|
||||
if (response.ok) {
|
||||
anchor.attr('href', "javascript: abonar({row_id: '" + row_id + "', pago_id: " + pago_id + "});")
|
||||
anchor.attr('title', 'Abonar')
|
||||
anchor.html('')
|
||||
anchor.append(
|
||||
$('<i></i>').addClass('piggy bank icon')
|
||||
)
|
||||
row.removeClass('warning').addClass('positive')
|
||||
response.json().then(data => {
|
||||
row.find('.text').html(data.fecha)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
function abonar({row_id, pago_id}) {
|
||||
const row = $(row_id)
|
||||
row.css('cursor', 'wait')
|
||||
const anchor = row.find("a[title='Abonar']")
|
||||
anchor.css('pointer-events', 'none')
|
||||
const uri = '{{$urls->api}}/ventas/pago/' + pago_id + '/abonar'
|
||||
const modal = $('#pago_modal')
|
||||
modal.modal('show')
|
||||
modal.find('.ui.button').click(event => {
|
||||
const date = modal.find('#fecha').val()
|
||||
return fetch(uri,
|
||||
{method: 'put', body: JSON.stringify({fecha: date}), headers: {'Content-Type': 'application/json'}}
|
||||
).then(response => {
|
||||
anchor.css('pointer-events', '')
|
||||
row.css('cursor', 'default')
|
||||
if (response.ok) {
|
||||
anchor.remove()
|
||||
row.removeClass('positive')
|
||||
response.json().then(data => {
|
||||
row.find('.text').html(data.fecha)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
const modal = new Modal({id: '#pago_modal'})
|
||||
modal.setup()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,7 @@
|
||||
<tr>
|
||||
<td><strong>Anticipo</strong></td>
|
||||
<td></td>
|
||||
<td class="right aligned"><strong>{{$format->ufs($anticipo['uf'])}}</strong></td>
|
||||
<td class="right aligned"><strong>{{$format->pesos($anticipo['pesos'])}}</strong></td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
@ -0,0 +1,22 @@
|
||||
<tr>
|
||||
<td>
|
||||
Bono Pie
|
||||
@if ($bonoPie !== null)
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/bono_pie">
|
||||
<i class="edit button"></i>
|
||||
</a>
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/bono_pie/add">
|
||||
<i class="add icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
@if ($bonoPie !== null)
|
||||
<td></td>
|
||||
<td class="right aligned">{{$format->ufs($bonoPie->pago->valor())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($bonoPie->pago->valor)}}</td>
|
||||
<td colspan="2"></td>
|
||||
@else
|
||||
<td colspan="5"></td>
|
||||
@endif
|
||||
</tr>
|
40
app/resources/views/ventas/show/forma_pago/credito.blade.php
Normal file
40
app/resources/views/ventas/show/forma_pago/credito.blade.php
Normal file
@ -0,0 +1,40 @@
|
||||
<tr>
|
||||
<td>
|
||||
Crédito
|
||||
@if ($credito !== null)
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/credito">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/credito/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
@if ($credito !== null)
|
||||
<td></td>
|
||||
<td class="right aligned">
|
||||
{{$format->ufs($credito->pago->valor())}}
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
{{$format->pesos($credito->pago->valor)}}
|
||||
</td>
|
||||
<td id="credito_pago" class="{{$credito->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? 'warning' : ($credito->pago->currentEstado->tipoEstado->descripcion === 'depositado' ? 'positive' : '')}}">
|
||||
<span class="text">{{$credito->pago->currentEstado->fecha->format('d-m-Y')}}</span>
|
||||
@if ($credito->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado')
|
||||
<a href="javascript: depositar({row_id: '#credito_pago', pago_id: {{$credito->pago->id}}});" title="Depositar">
|
||||
<i class="dollar sign icon"></i>
|
||||
</a>
|
||||
@elseif($credito->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
|
||||
<a href="javascript: abonar({row_id: '#credito_pago', pago_id: {{$credito->pago->id}}});" title="Abonar">
|
||||
<i class="piggy bank icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
Banco: {{$credito->pago->banco?->nombre}}
|
||||
</td>
|
||||
@else
|
||||
<td colspan="5"></td>
|
||||
@endif
|
||||
</tr>
|
@ -0,0 +1,34 @@
|
||||
<tr>
|
||||
<td>
|
||||
Escritura
|
||||
@if ($escritura !== null)
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
@if ($escritura !== null)
|
||||
<td></td>
|
||||
<td class="right aligned">{{$format->ufs($escritura->pago->valor())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($escritura->pago->valor)}}</td>
|
||||
<td id="escritura_pago" class="{{$escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? 'warning' : ($escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado' ? 'positive' : '')}}">
|
||||
<span class="text">{{$escritura->pago->currentEstado->fecha->format('d-m-Y')}}</span>
|
||||
@if ($escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado')
|
||||
<a href="javascript: depositar({row_id: '#escritura_pago', pago_id: {{$escritura->pago->id}}});" title="Depositar">
|
||||
<i class="dollar sign icon"></i>
|
||||
</a>
|
||||
@elseif ($escritura->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
|
||||
<a href="javascript: abonar({row_id: '#escritura_pago', pago_id: {{$escritura->pago->id}}});" title="Abonar">
|
||||
<i clasS="piggy bank icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
<td></td>
|
||||
@else
|
||||
<td colspan="5"></td>
|
||||
@endif
|
||||
</tr>
|
31
app/resources/views/ventas/show/forma_pago/pie.blade.php
Normal file
31
app/resources/views/ventas/show/forma_pago/pie.blade.php
Normal file
@ -0,0 +1,31 @@
|
||||
@if ($pie !== null)
|
||||
<tr>
|
||||
<td>
|
||||
Pie
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td></td>
|
||||
<td class="right aligned">{{$format->ufs($pie->valor)}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->valor * $pie->uf)}}</td>
|
||||
<td class="right aligned">Cuotas</td>
|
||||
<td>
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas">
|
||||
{{count($pie->cuotas(true))}}/{{$pie->cuotas}}
|
||||
</a>
|
||||
@if (count($pie->cuotas()) < $pie->cuotas)
|
||||
<a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Pagado</td>
|
||||
<td></td>
|
||||
<td class="right aligned">{{$format->ufs($pie->pagado())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->pagado('pesos'))}}</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
@endif
|
@ -0,0 +1,32 @@
|
||||
<tr>
|
||||
<td
|
||||
@if ($subsidio !== null)
|
||||
rowspan="2"
|
||||
@endif
|
||||
>
|
||||
Subsidio
|
||||
@if ($subsidio !== null)
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/subsidio">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/subsidio/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
@if ($subsidio !== null)
|
||||
<td>Ahorro</td>
|
||||
<td class="right aligned">{{$format->ufs($subsidio->ahorro->valor())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($subsidio->ahorro->valor)}}</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Subsidio</td>
|
||||
<td class="right aligned">{{$format->ufs($subsidio->ahorro->valor())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($subsidio->ahorro->valor)}}</td>
|
||||
<td colspan="2"></td>
|
||||
@else
|
||||
<td colspan="5"></td>
|
||||
@endif
|
||||
</tr>
|
28
app/resources/views/ventas/show/forma_pago/total.blade.php
Normal file
28
app/resources/views/ventas/show/forma_pago/total.blade.php
Normal file
@ -0,0 +1,28 @@
|
||||
<tr class="{{$venta->saldo() < 0 ? 'positive' : ($venta->saldo() > 0 ? 'error' : '')}}">
|
||||
<td>
|
||||
<strong>
|
||||
Total
|
||||
</strong>
|
||||
</td>
|
||||
<td></td>
|
||||
<td class="right aligned">
|
||||
<strong>
|
||||
{{$format->ufs($formaPago->total())}}
|
||||
</strong>
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
<strong>
|
||||
{{$format->pesos($formaPago->total('pesos'))}}
|
||||
</strong>
|
||||
</td>
|
||||
<td class="right aligned" >
|
||||
@if ($venta->saldo() / $venta->valor > 0.01)
|
||||
<strong>
|
||||
Δ
|
||||
{{$format->ufs($venta->saldo())}}
|
||||
({{$format->number($venta->saldo() / $venta->valor * 100, 2)}} %)
|
||||
</strong>
|
||||
@endif
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
56
app/resources/views/ventas/show/propiedad.blade.php
Normal file
56
app/resources/views/ventas/show/propiedad.blade.php
Normal file
@ -0,0 +1,56 @@
|
||||
<div class="ui inverted grey two column grid segment">
|
||||
<div class="column">
|
||||
PROPIEDAD
|
||||
</div>
|
||||
<div class="right aligned column">
|
||||
<a style="color: inherit;" href="{{$urls->base}}/venta/{{$venta->id}}/propiedad">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<table class="ui very basic fluid table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2">Unidad</th>
|
||||
<th class="center aligned">Piso</th>
|
||||
<th class="right aligned">Metros vendibles</th>
|
||||
<th class="right aligned">Precio</th>
|
||||
<th class="right aligned">UF/m²</th>
|
||||
<th class="center aligned">Orientacion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($venta->propiedad()->unidades as $unidad)
|
||||
<tr>
|
||||
<td>
|
||||
{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}
|
||||
@if ($unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento')
|
||||
{{$unidad->proyectoTipoUnidad->abreviacion}}
|
||||
@endif
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
{{$unidad->descripcion}}
|
||||
</td>
|
||||
<td class="center aligned">
|
||||
{{$unidad->piso}}
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
{{$format->number($unidad->proyectoTipoUnidad->vendible(), 2)}} m²
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
{{$format->ufs($unidad->precio($venta->fecha)->valor)}}
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
@if ($unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento')
|
||||
{{$format->number($unidad->precio($venta->fecha)->valor / $unidad->proyectoTipoUnidad->vendible(), 2)}} UF/m²
|
||||
@endif
|
||||
</td>
|
||||
<td class="center aligned">
|
||||
{{$unidad->orientacion}}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
15
app/resources/views/ventas/show/propietario.blade.php
Normal file
15
app/resources/views/ventas/show/propietario.blade.php
Normal file
@ -0,0 +1,15 @@
|
||||
<div class="ui fluid card">
|
||||
<div class="content">
|
||||
<a class="right floated icon link" href="{{$urls->base}}/venta/{{$venta->id}}/propietario">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
<a class="header" href="{{$urls->base}}/search/{{urlencode($venta->propietario()->nombreCompleto())}}">
|
||||
{{$venta->propietario()->nombreCompleto()}}
|
||||
<i class="tiny search icon"></i>
|
||||
</a>
|
||||
{{$venta->propietario()->rut()}}
|
||||
<div class="meta">
|
||||
{{$venta->propietario()->datos->direccion}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
39
app/src/Controller/Direcciones.php
Normal file
39
app/src/Controller/Direcciones.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Direcciones
|
||||
{
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Provincia $provinciaRepository, Repository\Comuna $comunaRepository, int $region_id) : ResponseInterface
|
||||
{
|
||||
$temp_provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
$comunas = [];
|
||||
foreach($temp_provincias as $provincia) {
|
||||
$temp_comunas = $comunaRepository->fetchByProvincia($provincia->id);
|
||||
$comunas = array_merge($comunas, $temp_comunas);
|
||||
}
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcoll($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$response->getBody()->write(json_encode(['comunas' => $comunas, 'total' => count($comunas)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function findComunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByDireccion($json->direccion);
|
||||
$output['comunas'] = $comunas;
|
||||
$output['total'] = count($comunas);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -14,8 +15,13 @@ class Proyectos
|
||||
}
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$response->getBody()->write(json_encode(['proyectos' => $proyectos, 'total' => count($proyectos)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use MongoDB\Driver\Server;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
@ -14,13 +17,89 @@ class Ventas
|
||||
$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
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
return $view->render($response, 'ventas.show', compact('venta'));
|
||||
}
|
||||
public function showUnidad(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, string $proyecto_nombre, int $unidad_descripcion): ResponseInterface
|
||||
{
|
||||
$proyecto_nombre = urldecode($proyecto_nombre);
|
||||
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
||||
return $view->render($response, 'ventas.show', compact('venta'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\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)]));
|
||||
$output = [
|
||||
'proyecto' => [
|
||||
'id' => $proyecto_id
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $service->fetchByProyecto($proyecto_id);
|
||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
||||
$output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
|
||||
$output['total'] = count($ventas);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$response->getBody()->write(json_encode(compact('venta')));
|
||||
} catch (EmptyResult $exception) {
|
||||
$response->getBody()->write(json_encode(['error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]]));
|
||||
}
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
return $view->render($response, 'ventas.edit', compact('venta'));
|
||||
}
|
||||
public function propietario(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, Repository\Region $regionRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$propietario = $venta->propietario();
|
||||
$regiones = $regionRepository->fetchAll();
|
||||
usort($regiones, function(Model\Region $a, Model\Region $b) {
|
||||
return $a->numeracion - $b->numeracion;
|
||||
});
|
||||
return $view->render($response, 'ventas.propietarios.edit', compact('propietario', 'venta_id', 'regiones'));
|
||||
}
|
||||
public function propiedad(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, Service\Venta\Unidad $unidadService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$propiedad = $venta->propiedad();
|
||||
$proyecto = $venta->proyecto();
|
||||
$unidades = $unidadService->getDisponiblesByProyecto($proyecto->id);
|
||||
$tiposUnidades = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!in_array($unidad->proyectoTipoUnidad->tipoUnidad, $tiposUnidades)) {
|
||||
$tiposUnidades []= $unidad->proyectoTipoUnidad->tipoUnidad;
|
||||
}
|
||||
}
|
||||
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id'));
|
||||
}
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -12,19 +13,24 @@ 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
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\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
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['cierres' => $cierres, 'total' => count($cierres)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$cierres = $service->getByProyecto($proyecto_id);
|
||||
$output['cierres'] = $cierres;
|
||||
$output['total'] = count($cierres);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
22
app/src/Controller/Ventas/Comentarios.php
Normal file
22
app/src/Controller/Ventas/Comentarios.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Comentarios
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Comentario $comentarioRepository): ResponseInterface
|
||||
{
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchAll();
|
||||
$output['comentarios'] = $comentarios;
|
||||
$output['total'] = count($comentarios);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@ -44,16 +45,19 @@ class Cuotas
|
||||
}
|
||||
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Ventas\Pago $pagoService): ResponseInterface
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'depositada' => $pagoService->depositar($cuota->pago)
|
||||
'depositada' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['depositada'] = $pagoService->depositar($cuota->pago);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
26
app/src/Controller/Ventas/Pagos.php
Normal file
26
app/src/Controller/Ventas/Pagos.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Pagos
|
||||
{
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$date = new DateTimeImmutable($json->fecha);
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$date = new DateTimeImmutable($json->fecha);
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -14,18 +15,23 @@ class Precios
|
||||
$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
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$response->getBody()->write(json_encode(['precios' => $precios, 'total' => count($precios)]));
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Ventas\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$precio = $precioService->getByUnidad($unidad_id);
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
$response->getBody()->write(json_encode(['precio' => $precio]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
15
app/src/Controller/Ventas/Propietarios.php
Normal file
15
app/src/Controller/Ventas/Propietarios.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Propietarios
|
||||
{
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Venta\Propietario $propietarioRepository, int $propietario_rut): ResponseInterface
|
||||
{
|
||||
$propietario = $propietarioRepository->fetchById($propietario_rut);
|
||||
return $view->render($response, 'ventas.propietarios.show', compact('propietario'));
|
||||
}
|
||||
}
|
@ -17,6 +17,6 @@ class Comuna extends Model
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return implode(', ', [$this->descripcion, '' . $this->provincia]);
|
||||
return $this->descripcion;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,14 @@ class Direccion extends Model
|
||||
public string $extra;
|
||||
public Comuna $comuna;
|
||||
|
||||
public function full(): string
|
||||
{
|
||||
return implode(', ', [
|
||||
"{$this}",
|
||||
$this->comuna->provincia
|
||||
]);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
@ -30,7 +38,7 @@ class Direccion extends Model
|
||||
if ($this->extra !== '') {
|
||||
$array[]= $this->extra;
|
||||
}
|
||||
$array []= '' . $this->comuna;
|
||||
$array []= $this->comuna;
|
||||
return implode(', ', $array);
|
||||
}
|
||||
}
|
||||
|
@ -5,21 +5,36 @@ use Incoviba\Common\Ideal;
|
||||
|
||||
class Proyecto extends Ideal\Model
|
||||
{
|
||||
public Inmobiliaria $inmobiliaria;
|
||||
protected Inmobiliaria $inmobiliaria;
|
||||
public string $descripcion;
|
||||
public Direccion $direccion;
|
||||
protected Direccion $direccion;
|
||||
public Proyecto\Terreno $terreno;
|
||||
public Proyecto\Superficie $superficie;
|
||||
public float $corredor;
|
||||
public int $pisos;
|
||||
public int $subterraneos;
|
||||
|
||||
public function inmobiliaria(): Inmobiliaria
|
||||
{
|
||||
if (!isset($this->inmobiliaria)) {
|
||||
$this->inmobiliaria = $this->runFactory('inmobiliaria');
|
||||
}
|
||||
return $this->inmobiliaria;
|
||||
}
|
||||
public function direccion(): Direccion
|
||||
{
|
||||
if (!isset($this->direccion)) {
|
||||
$this->direccion = $this->runFactory('direccion');
|
||||
}
|
||||
return $this->direccion;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'inmobiliaria' => $this->inmobiliaria,
|
||||
'inmobiliaria' => $this->inmobiliaria(),
|
||||
'descripcion' => $this->descripcion,
|
||||
'direccion' => $this->direccion,
|
||||
'direccion' => $this->direccion(),
|
||||
'terreno' => $this->terreno,
|
||||
'superficie' => $this->superficie,
|
||||
'corredor' => $this->corredor,
|
||||
|
20
app/src/Model/Proyecto/Elemento.php
Normal file
20
app/src/Model/Proyecto/Elemento.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Elemento extends Ideal\Model
|
||||
{
|
||||
public string $descripcion;
|
||||
public string $abreviacion;
|
||||
public int $orden;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'descripcion' => $this->descripcion,
|
||||
'abreviacion' => $this->abreviacion,
|
||||
'orden' => $this->orden
|
||||
]);
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ class ProyectoTipoUnidad extends Ideal\Model
|
||||
public float $terraza;
|
||||
public string $descripcion;
|
||||
|
||||
public array $tipologias;
|
||||
|
||||
public function superficie(): float
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza], function($sum, $item) {return $sum + $item;}, 0);
|
||||
@ -23,6 +25,23 @@ class ProyectoTipoUnidad extends Ideal\Model
|
||||
{
|
||||
return array_reduce([$this->util, $this->logia, $this->terraza / 2], function($sum, $item) {return $sum + $item;}, 0);
|
||||
}
|
||||
public function tipologia(): string
|
||||
{
|
||||
if (isset($this->tipologias) and count($this->tipologias) > 0) {
|
||||
$temp = [...$this->tipologias];
|
||||
usort($temp, function(Tipologia $a, Tipologia $b) {
|
||||
$el = $a->elemento->orden - $b->elemento->orden;
|
||||
if ($el === 0) {
|
||||
return strcmp($a->elemento->abreviacion, $b->elemento->abreviacion);
|
||||
}
|
||||
return $el;
|
||||
});
|
||||
return implode('/', array_map(function(Tipologia $tipologia) {
|
||||
return $tipologia->cantidad . $tipologia->elemento->abreviacion;
|
||||
}, $temp));
|
||||
}
|
||||
return $this->abreviacion;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
@ -36,7 +55,8 @@ class ProyectoTipoUnidad extends Ideal\Model
|
||||
'terraza' => $this->terraza,
|
||||
'superficie' => $this->superficie(),
|
||||
'vendible' => $this->vendible(),
|
||||
'descripcion' => $this->descripcion
|
||||
'descripcion' => $this->descripcion,
|
||||
'tipologia' => $this->tipologia()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
8
app/src/Model/Proyecto/TipoTipologia.php
Normal file
8
app/src/Model/Proyecto/TipoTipologia.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Model\Tipo;
|
||||
|
||||
class TipoTipologia extends Tipo
|
||||
{
|
||||
}
|
20
app/src/Model/Proyecto/Tipologia.php
Normal file
20
app/src/Model/Proyecto/Tipologia.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Tipologia extends Ideal\Model
|
||||
{
|
||||
public ProyectoTipoUnidad $proyectoTipoUnidad;
|
||||
public TipoTipologia $tipoTipologia;
|
||||
public int $cantidad;
|
||||
public Elemento $elemento;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'cantidad' => $this->cantidad,
|
||||
'elemento' => $this->elemento
|
||||
]);
|
||||
}
|
||||
}
|
@ -3,32 +3,103 @@ namespace Incoviba\Model;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Controller\Ventas;
|
||||
|
||||
class Venta extends Ideal\Model
|
||||
{
|
||||
public Venta\Propietario $propietario;
|
||||
public Venta\Propiedad $propiedad;
|
||||
public Venta\FormaPago $formaPago;
|
||||
protected Venta\Propietario $propietario;
|
||||
protected Venta\Propiedad $propiedad;
|
||||
protected Venta\FormaPago $formaPago;
|
||||
public DateTimeInterface $fecha;
|
||||
public DateTimeInterface $fechaIngreso;
|
||||
public float $valor;
|
||||
public bool $relacionado;
|
||||
protected ?Venta\Entrega $entrega;
|
||||
|
||||
public array $estados;
|
||||
public Venta\EstadoVenta $currentEstado;
|
||||
|
||||
public function propietario(): Venta\Propietario
|
||||
{
|
||||
if (!isset($this->propietario)) {
|
||||
$this->propietario = $this->runFactory('propietario');
|
||||
}
|
||||
return $this->propietario;
|
||||
}
|
||||
public function propiedad(): Venta\Propiedad
|
||||
{
|
||||
if (!isset($this->propiedad)) {
|
||||
$this->propiedad = $this->runFactory('propiedad');
|
||||
}
|
||||
return $this->propiedad;
|
||||
}
|
||||
public function formaPago(): Venta\FormaPago
|
||||
{
|
||||
if (!isset($this->formaPago)) {
|
||||
$this->formaPago = $this->runFactory('formaPago');
|
||||
}
|
||||
return $this->formaPago;
|
||||
}
|
||||
public function entrega(): ?Venta\Entrega
|
||||
{
|
||||
if (!isset($this->entrega)) {
|
||||
$this->entrega = $this->runFactory('entrega');
|
||||
}
|
||||
return $this->entrega;
|
||||
}
|
||||
|
||||
public function estados(): array
|
||||
{
|
||||
if (!isset($this->estados)) {
|
||||
$this->estados = $this->runFactory('estados');
|
||||
}
|
||||
return $this->estados;
|
||||
}
|
||||
public function currentEstado(): ?Venta\EstadoVenta
|
||||
{
|
||||
if (!isset($this->currentEstado)) {
|
||||
$this->currentEstado = $this->runFactory('currentEstado');
|
||||
}
|
||||
return $this->currentEstado;
|
||||
}
|
||||
|
||||
public function proyecto(): Proyecto
|
||||
{
|
||||
return $this->propiedad()->departamentos()[0]->proyectoTipoUnidad->proyecto;
|
||||
}
|
||||
|
||||
protected float $valor_util;
|
||||
public function util(): float
|
||||
{
|
||||
if (!isset($this->valor_util)) {
|
||||
$sum = $this->valor;
|
||||
$sum -= array_reduce($this->propiedad()->estacionamientos(), function(float $sum, Venta\Unidad $unidad) {
|
||||
return $unidad->precio($this->fecha)->valor;
|
||||
}, 0);
|
||||
$sum -= array_reduce($this->propiedad()->bodegas(), function(float $sum, Venta\Unidad $unidad) {
|
||||
return $unidad->precio($this->fecha)->valor;
|
||||
}, 0);
|
||||
$this->valor_util = $sum;
|
||||
}
|
||||
return $this->valor_util;
|
||||
}
|
||||
public function saldo(): float
|
||||
{
|
||||
return $this->valor - $this->formaPago->total();
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'propietario' => $this->propietario,
|
||||
'propiedad' => $this->propiedad,
|
||||
'forma_pago' => $this->formaPago,
|
||||
'propietario' => $this->propietario(),
|
||||
'propiedad' => $this->propiedad(),
|
||||
'forma_pago' => $this->formaPago()->ids(),
|
||||
'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
|
||||
'estados' => array_map(function(Venta\EstadoVenta $estado) {return $estado->id;}, $this->estados()),
|
||||
'current_estado' => $this->currentEstado()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,14 @@ use Incoviba\Common\Ideal;
|
||||
|
||||
class BonoPie extends Ideal\Model
|
||||
{
|
||||
public float $valor;
|
||||
public Pago $pago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'valor' => $this->valor,
|
||||
'pago' => $this->pago
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
21
app/src/Model/Venta/Comentario.php
Normal file
21
app/src/Model/Venta/Comentario.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Comentario extends Ideal\Model
|
||||
{
|
||||
public DateTimeInterface $fecha;
|
||||
public string $texto;
|
||||
public bool $activo;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'texto' => $this->texto,
|
||||
'activo' => $this->activo
|
||||
]);
|
||||
}
|
||||
}
|
@ -4,4 +4,13 @@ namespace Incoviba\Model\Venta;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Credito extends Ideal\Model
|
||||
{}
|
||||
{
|
||||
public Pago $pago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago' => $this->pago
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Escritura extends Ideal\Model
|
||||
{}
|
||||
{
|
||||
public Pago $pago;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago' => $this->pago,
|
||||
'fecha' => $this->fecha->format('Y-m-d')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -6,19 +6,62 @@ use JsonSerializable;
|
||||
class FormaPago implements JsonSerializable
|
||||
{
|
||||
public ?Pie $pie;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Credito $credito;
|
||||
public ?Escritura $escritura;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Subsidio $subsidio;
|
||||
public ?Credito $credito;
|
||||
public ?Pago $devolucion;
|
||||
|
||||
public function anticipo(string $moneda = Pago::UF): float
|
||||
{
|
||||
$sum = 0;
|
||||
if ($this->pie !== null) {
|
||||
$sum += $this->pie->pagado($moneda);
|
||||
if (isset($this->pie->reajuste) and $this->pie->reajuste !== null) {
|
||||
$sum += $this->pie->reajuste->valor($moneda);
|
||||
}
|
||||
}
|
||||
if ($this->escritura !== null) {
|
||||
$sum += $this->escritura->pago->valor($moneda);
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
public function total(string $moneda = Pago::UF): float
|
||||
{
|
||||
$sum = $this->anticipo($moneda);
|
||||
if (isset($this->bonoPie)) {
|
||||
$sum += $this->bonoPie->pago->valor($moneda);
|
||||
}
|
||||
if (isset($this->subsidio)) {
|
||||
$sum += $this->subsidio->ahorro->valor($moneda);
|
||||
$sum += $this->subsidio->subsidio->valor($moneda);
|
||||
}
|
||||
if (isset($this->credito)) {
|
||||
$sum += $this->credito->pago->valor($moneda);
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
public function ids(): array
|
||||
{
|
||||
return [
|
||||
'pie_id' => $this->pie?->id,
|
||||
'escritura_id' => $this->escritura?->id,
|
||||
'bono_pie_id' => $this->bonoPie?->id,
|
||||
'credito_id' => $this->credito?->id,
|
||||
'subsidio_id' => $this->subsidio?->id,
|
||||
'devolucion_id' => $this->devolucion?->id
|
||||
];
|
||||
}
|
||||
|
||||
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
|
||||
'bono_pie' => $this->bonoPie ?? null,
|
||||
'subsidio' => $this->subsidio ?? null,
|
||||
'credito' => $this->credito ?? null,
|
||||
'devolucion' => $this->devolucion ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ use Incoviba\Model\Banco;
|
||||
|
||||
class Pago extends Model
|
||||
{
|
||||
const UF = 'uf';
|
||||
const PESOS = 'pesos';
|
||||
|
||||
public float $valor;
|
||||
public ?Banco $banco;
|
||||
public ?TipoPago $tipoPago;
|
||||
@ -16,6 +19,14 @@ class Pago extends Model
|
||||
public ?string $pagador;
|
||||
public ?Pago $asociado;
|
||||
|
||||
public array $estados;
|
||||
public EstadoPago $currentEstado;
|
||||
|
||||
public function valor(string $moneda = Pago::UF): float
|
||||
{
|
||||
return $this->valor / (($moneda === Pago::UF) ? ($this->uf > 0 ? $this->uf : 1) : 1);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -13,6 +13,24 @@ class Pie extends Model
|
||||
public ?Pie $asociado;
|
||||
public ?Pago $reajuste;
|
||||
|
||||
public array $cuotasArray;
|
||||
public function cuotas(bool $pagadas = false): array
|
||||
{
|
||||
if (!$pagadas) {
|
||||
return $this->cuotasArray;
|
||||
}
|
||||
return array_filter($this->cuotasArray, function(Cuota $cuota) {
|
||||
return $cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'no pagado';
|
||||
});
|
||||
}
|
||||
|
||||
public function pagado(string $moneda = Pago::UF): float
|
||||
{
|
||||
return array_reduce($this->cuotas(true), function(float $sum, Cuota $cuota) use ($moneda) {
|
||||
return $sum + $cuota->pago->valor($moneda);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -20,6 +20,14 @@ class Propiedad extends Ideal\Model
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';});
|
||||
}
|
||||
|
||||
protected float $vendible;
|
||||
public function vendible(): float
|
||||
{
|
||||
return array_reduce($this->departamentos(), function(float $sum, Unidad $unidad) {
|
||||
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
public function summary(): string
|
||||
{
|
||||
return implode(' - ', array_merge(
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -15,6 +16,33 @@ class Unidad extends Ideal\Model
|
||||
public array $precios = [];
|
||||
public ?Precio $currentPrecio = null;
|
||||
|
||||
public function precio(DateTimeInterface $dateTime): Precio
|
||||
{
|
||||
if ($dateTime > $this->currentPrecio->current->fecha) {
|
||||
return $this->currentPrecio;
|
||||
}
|
||||
$precio = array_reduce(array_filter($this->precios, function(Precio $precio) use ($dateTime) {
|
||||
return $dateTime > $precio->current->fecha;
|
||||
}), function(?Precio $max, Precio $precio) {
|
||||
if ($max === null) {
|
||||
return $precio;
|
||||
}
|
||||
return $max->current->fecha > $precio->current->fecha ? $max : $precio;
|
||||
});
|
||||
if ($precio === null) {
|
||||
$precio = array_reduce(array_filter($this->precios, function(Precio $precio) use ($dateTime) {
|
||||
return $dateTime < $precio->current->fecha;
|
||||
}), function(?Precio $min, Precio $precio) {
|
||||
if ($min === null) {
|
||||
return $precio;
|
||||
}
|
||||
return $min->current->fecha < $precio->current->fecha ? $min : $precio;
|
||||
});
|
||||
}
|
||||
|
||||
return $precio;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Banco extends Ideal\Repository
|
||||
@ -15,9 +16,7 @@ class Banco extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'nombre' => []
|
||||
];
|
||||
$map = new Implement\Repository\MapperParser(['nombre']);
|
||||
return $this->parseData(new Model\Banco(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Comuna extends Ideal\Repository
|
||||
@ -15,14 +16,10 @@ class Comuna extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'provincia' => [
|
||||
'function' => function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('provincia', (new Implement\Repository\Mapper())->setFunction(function($data) {
|
||||
return $this->provinciaRepository->fetchById($data['provincia']);
|
||||
}));
|
||||
return $this->parseData(new Model\Comuna(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -48,4 +45,12 @@ class Comuna extends Ideal\Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `provincia` = ?";
|
||||
return $this->fetchMany($query, [$provincia_id]);
|
||||
}
|
||||
public function fetchByDireccion(string $direccion): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `direccion` ON `direccion`.`comuna` = a.`id`
|
||||
WHERE TRIM(CONCAT_WS(' ', `direccion`.`calle`, `direccion`.`numero`, `direccion`.`extra`)) LIKE ?";
|
||||
return $this->fetchMany($query, ["%{$direccion}%"]);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,11 @@
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal\Repository;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Direccion extends Repository
|
||||
class Direccion extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Comuna $comunaRepository)
|
||||
{
|
||||
@ -15,16 +16,10 @@ class Direccion extends Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'calle' => [],
|
||||
'numero' => [],
|
||||
'extra' => [],
|
||||
'comuna' => [
|
||||
'function' => function($data) {
|
||||
return $this->comunaRepository->fetchById($data['comuna']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['calle', 'numero', 'extra']))
|
||||
->register('comuna', (new Implement\Repository\Mapper())->setFunction(function($data) {
|
||||
return $this->comunaRepository->fetchById($data['comuna']);
|
||||
}));
|
||||
return $this->parseData(new Model\Direccion(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -21,23 +22,16 @@ class Inmobiliaria extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'dv' => [],
|
||||
'razon' => [],
|
||||
'abreviacion' => [],
|
||||
'cuenta' => [],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['db', 'razon', 'abreviacion', 'cuenta']))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'sociedad' => [
|
||||
'property' => 'tipoSociedad',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('sociedad', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoSociedad')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoSociedadRepository->fetchById($data['sociedad']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Inmobiliaria(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoSociedad extends Ideal\Repository
|
||||
@ -15,10 +16,7 @@ class TipoSociedad extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'abreviacion' => []
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'abreviacion']));
|
||||
return $this->parseData(new Model\Inmobiliaria\TipoSociedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Repository;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Login extends Ideal\Repository
|
||||
@ -17,27 +18,14 @@ class Login extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'user_id' => [
|
||||
'property' => 'user',
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['selector', 'token']))
|
||||
->register('user_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('user')
|
||||
->setFunction(function($data) {
|
||||
return $this->userRepository->fetchById($data['user_id']);
|
||||
}
|
||||
],
|
||||
'selector' => [],
|
||||
'token' => [],
|
||||
'time' => [
|
||||
'property' => 'dateTime',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['time']);
|
||||
}
|
||||
],
|
||||
'status' => [
|
||||
'function' => function($data) {
|
||||
return $data['status'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
}))
|
||||
->register('time', new Implement\Repository\Mapper\DateTime('time', 'dateTime'))
|
||||
->register('status', new Implement\Repository\Mapper\Boolean('status'));
|
||||
return $this->parseData(new Model\Login(), $data, $map);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Provincia extends Ideal\Repository
|
||||
@ -15,14 +16,11 @@ class Provincia extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'region' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('region', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->regionRepository->fetchById($data['region']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Provincia(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,8 +3,8 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Proyecto extends Ideal\Repository
|
||||
{
|
||||
@ -16,40 +16,31 @@ class Proyecto extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'inmobiliaria' => [
|
||||
'function' => function($data) {
|
||||
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria']);
|
||||
}
|
||||
],
|
||||
'descripcion' => [],
|
||||
'direccion' => [
|
||||
'function' => function($data) {
|
||||
return $this->direccionRepository->fetchById($data['direccion']);
|
||||
}
|
||||
],
|
||||
'superficie_terreno' => [
|
||||
'property' => 'terreno',
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'corredor', 'pisos', 'subterraneos']))
|
||||
->register('inmobiliaria', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('direccion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('superficie_terreno', (new Implement\Repository\Mapper())
|
||||
->setProperty('terreno')
|
||||
->setFunction(function($data) {
|
||||
$terreno = new Model\Proyecto\Terreno();
|
||||
$terreno->superficie = $data['superficie_terreno'];
|
||||
$terreno->valor = $data['valor_terreno'];
|
||||
return $terreno;
|
||||
}
|
||||
],
|
||||
'superficie_sobre_nivel' => [
|
||||
'property' => 'superficie',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('superficie_sobre_nivel', (new Implement\Repository\Mapper())
|
||||
->setProperty('superficie')
|
||||
->setFunction(function($data) {
|
||||
$superficie = new Model\Proyecto\Superficie();
|
||||
$superficie->sobre_nivel = $data['superficie_sobre_nivel'];
|
||||
$superficie->bajo_nivel = $data['superficie_bajo_nivel'];
|
||||
return $superficie;
|
||||
}
|
||||
],
|
||||
'corredor' => [],
|
||||
'pisos' => [],
|
||||
'subterraneos' => []
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Proyecto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -57,7 +48,7 @@ class Proyecto extends Ideal\Repository
|
||||
$model->id = $this->saveNew(
|
||||
['inmobiliaria', 'descripcion', 'direccion', 'superficie_terreno', 'valor_terreno', 'corredor',
|
||||
'superficie_sobre_nivel', 'superficie_bajo_nivel', 'pisos', 'subterraneos'],
|
||||
[$model->inmobiliaria->rut, $model->descripcion, $model->direccion->id, $model->terreno->superficie,
|
||||
[$model->inmobiliaria()->rut, $model->descripcion, $model->direccion()->id, $model->terreno->superficie,
|
||||
$model->terreno->valor, $model->corredor, $model->superficie->sobre_nivel,
|
||||
$model->superficie->bajo_nivel, $model->pisos, $model->subterraneos]
|
||||
);
|
||||
|
34
app/src/Repository/Proyecto/Elemento.php
Normal file
34
app/src/Repository/Proyecto/Elemento.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Elemento extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_elemento');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion', 'abreviacion', 'orden']));
|
||||
return $this->parseData(new Model\Proyecto\Elemento(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'abreviacion', 'orden'],
|
||||
[$model->descripcion, $model->abreviacion, $model->orden]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'abreviacion', 'orden'], $new_data);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -16,27 +17,18 @@ class ProyectoTipoUnidad extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'proyecto' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['nombre', 'abreviacion', 'logia', 'terraza', 'descripcion']))
|
||||
->register('proyecto', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoRepository->fetchById($data['proyecto']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoUnidad',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('tipo', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoUnidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoUnidadRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'nombre' => [],
|
||||
'abreviacion' => [],
|
||||
'm2' => [
|
||||
'property' => 'util'
|
||||
],
|
||||
'logia' => [],
|
||||
'terraza' => [],
|
||||
'descripcion' => []
|
||||
];
|
||||
}))
|
||||
->register('m2', (new Implement\Repository\Mapper())
|
||||
->setProperty('util'));
|
||||
return $this->parseData(new Model\Proyecto\ProyectoTipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
34
app/src/Repository/Proyecto/TipoTipologia.php
Normal file
34
app/src/Repository/Proyecto/TipoTipologia.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoTipologia extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipologia');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']));
|
||||
return $this->parseData(new Model\Proyecto\TipoTipologia(), $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);
|
||||
}
|
||||
}
|
58
app/src/Repository/Proyecto/Tipologia.php
Normal file
58
app/src/Repository/Proyecto/Tipologia.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Tipologia extends Ideal\Repository
|
||||
{
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected ProyectoTipoUnidad $proyectoTipoUnidadRepository,
|
||||
protected TipoTipologia $tipoTipologiaRepository,
|
||||
protected Elemento $elementoRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_tipologia');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['cantidad']))
|
||||
->register('tipo', (new Implement\Repository\Mapper())
|
||||
->setProperty('proyectoTipoUnidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoTipoUnidadRepository->fetchById($data['tipo']);
|
||||
}))
|
||||
->register('tipologia', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoTipologiaRepository->fetchById($data['tipologia']);
|
||||
}))
|
||||
->register('elemento', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->elementoRepository->fetchById($data['elemento']);
|
||||
}));
|
||||
return $this->parseData(new Model\Proyecto\Tipologia(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['tipo', 'tipologia', 'cantidad', 'elemento'],
|
||||
[$model->proyectoTipoUnidad->id, $model->tipoTipologia->id, $model->cantidad, $model->elemento->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['tipo', 'tipologia', 'cantidad', 'elemento'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProyectoTipoUnidad(int $proyecto_tipo_unidad_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `tipo` = ?";
|
||||
return $this->fetchMany($query, [$proyecto_tipo_unidad_id]);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Region extends Ideal\Repository
|
||||
@ -15,11 +16,7 @@ class Region extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'numeral' => [],
|
||||
'numeracion' => []
|
||||
];
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'numeral', 'numeracion']);
|
||||
return $this->parseData(new Model\Region(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class User extends Ideal\Repository
|
||||
@ -15,15 +16,8 @@ class User extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'name' => [],
|
||||
'password' => [],
|
||||
'enabled' => [
|
||||
'function' => function($data) {
|
||||
return $data['enabled'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['name', 'password']))
|
||||
->register('enabled', new Implement\Repository\Mapper\Boolean('enabled'));
|
||||
return $this->parseData(new Model\User(), $data, $map);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,9 @@ namespace Incoviba\Repository;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Venta extends Ideal\Repository
|
||||
{
|
||||
@ -12,13 +14,13 @@ class Venta extends Ideal\Repository
|
||||
Define\Connection $connection,
|
||||
protected Venta\Propietario $propietarioRepository,
|
||||
protected Venta\Propiedad $propiedadRepository,
|
||||
protected Venta\Pie $pieRepository,
|
||||
protected Service\Venta\Pie $pieService,
|
||||
protected Venta\BonoPie $bonoPieRepository,
|
||||
protected Venta\Credito $creditoRepository,
|
||||
protected Venta\Escritura $escrituraRepository,
|
||||
protected Venta\Subsidio $subsidioRepository,
|
||||
protected Venta\Entrega $entregaRepository,
|
||||
protected Venta\Pago $pagoRepository
|
||||
protected Service\Venta\Pago $pagoService
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
@ -27,95 +29,96 @@ class Venta extends Ideal\Repository
|
||||
|
||||
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]);
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('propietario', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->propietarioRepository, 'fetchById'])
|
||||
->setArgs([$data['propietario']])))
|
||||
->register('propiedad', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->propiedadRepository, 'fetchById'])
|
||||
->setArgs([$data['propiedad']])))
|
||||
->register('pie', (new Implement\Repository\Mapper())
|
||||
->setProperty('formaPago')
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($repositories, $data) {
|
||||
$fp = new Model\Venta\FormaPago();
|
||||
$map = [
|
||||
'pie' => [
|
||||
'service' => $repositories->pieService
|
||||
],
|
||||
'bono_pie' => [
|
||||
'property' => 'bonoPie',
|
||||
'repository' => $repositories->bonoPieRepository
|
||||
],
|
||||
'credito' => [
|
||||
'repository' => $repositories->creditoRepository
|
||||
],
|
||||
'escritura' => [
|
||||
'repository' => $repositories->escrituraRepository
|
||||
],
|
||||
'subsidio' => [
|
||||
'repository' => $repositories->subsidioRepository
|
||||
],
|
||||
'devolucion' => [
|
||||
'service' => $repositories->pagoService
|
||||
]
|
||||
];
|
||||
foreach ($map as $column => $settings) {
|
||||
if ($data[$column] !== null and $data[$column] !== 0) {
|
||||
if (isset($settings['repository'])) {
|
||||
$fp->{$settings['property'] ?? $column} = $settings['repository']->fetchById($data[$column]);
|
||||
continue;
|
||||
}
|
||||
$fp->{$settings['property'] ?? $column} = $settings['service']->getById($data[$column]);
|
||||
continue;
|
||||
}
|
||||
$fp->{$settings['property'] ?? $column} = null;
|
||||
}
|
||||
}
|
||||
return $fp;
|
||||
}
|
||||
],
|
||||
'escriturado' => [
|
||||
'function' => function($data) {
|
||||
return $fp;
|
||||
})
|
||||
->setArgs([(object) [
|
||||
'pieService' => $this->pieService,
|
||||
'bonoPieRepository' => $this->bonoPieRepository,
|
||||
'creditoRepository' => $this->creditoRepository,
|
||||
'escrituraRepository' => $this->escrituraRepository,
|
||||
'subsidioRepository' => $this->subsidioRepository,
|
||||
'pagoService' => $this->pagoService
|
||||
], $data])))
|
||||
/*->register('escriturado', (new Implement\Repository\Mapper())
|
||||
->setFunction(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'
|
||||
];
|
||||
}))*/
|
||||
->register('entrega', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($entrega_id) {
|
||||
if ($entrega_id !== null and $entrega_id !== 0) {
|
||||
return $this->entregaRepository->fetchById($entrega_id);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
->setArgs([$data['entrega']])))
|
||||
/*->register('entregado', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable(function($entrega_id) {
|
||||
if ($entrega_id !== null and $entrega_id !== 0) {
|
||||
return $entrega_id != null;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
->setArgs([$data['entrega']])))*/
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('valor_uf', (new Implement\Repository\Mapper())
|
||||
->setProperty('valor'))
|
||||
//->register('estado')
|
||||
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
|
||||
//->register('avalchile')
|
||||
//->register('agente')
|
||||
//->register('uf')
|
||||
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
|
||||
//->register('promocion')
|
||||
//->register('resciliacion')
|
||||
//->register('devolucion');
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -124,9 +127,9 @@ class Venta extends Ideal\Repository
|
||||
['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->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]
|
||||
);
|
||||
@ -152,4 +155,17 @@ WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Define\Model
|
||||
{
|
||||
$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 `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
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 `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`";
|
||||
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class BonoPie extends Ideal\Repository
|
||||
@ -15,13 +16,11 @@ class BonoPie extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(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
|
||||
|
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use PDO;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use PDO;
|
||||
|
||||
class Cierre extends Ideal\Repository
|
||||
{
|
||||
@ -21,30 +22,17 @@ class Cierre extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'proyecto' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['precio']))
|
||||
->register('proyecto', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoRepository->fetchById($data['proyecto']);
|
||||
}
|
||||
],
|
||||
'precio' => [],
|
||||
'fecha' => [
|
||||
'property' => 'dateTime',
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'relacionado' => [
|
||||
'function' => function($data) {
|
||||
return $data['relacionado'] !== 0;
|
||||
}
|
||||
],
|
||||
'propietario' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha', 'dateTime'))
|
||||
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'))
|
||||
->register('propietario', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->propietarioRepository->fetchById($data['propietario']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Cierre(), $data, $map);
|
||||
}
|
||||
|
||||
|
43
app/src/Repository/Venta/Comentario.php
Normal file
43
app/src/Repository/Venta/Comentario.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Comentario extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('comentario');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['texto']))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado', 'activo'));
|
||||
return $this->parseData(new Model\Venta\Comentario(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['fecha', 'texto', 'estado'],
|
||||
[$model->fecha->format('Y-m-d'), $model->texto, $model->activo ? 1 : 0]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['fecha', 'texto', 'estado'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `venta` = ? AND `estado` = 1 ORDER BY `fecha` DESC";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
}
|
@ -3,11 +3,13 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Credito extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
public function __construct(Define\Connection $connection, protected Service\Venta\Pago $pagoService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('credito');
|
||||
@ -15,13 +17,11 @@ class Credito extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoService->getById($data['pago']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Credito(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -1,17 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuota extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pie $pieRepository, protected Repository\Banco $bancoRepository, protected Pago $pagoRepository)
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Pie $pieRepository,
|
||||
protected Repository\Banco $bancoRepository,
|
||||
protected Service\Venta\Pago $pagoService
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('cuota');
|
||||
@ -19,68 +25,33 @@ class Cuota extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pie' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'numero']))
|
||||
->register('pie', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pieRepository->fetchById($data['pie']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor' => [],
|
||||
'estado' => [
|
||||
'function' => function($data) {
|
||||
return $data['estado'] !== 0;
|
||||
}
|
||||
],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado'))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['banco'] === null or $data['banco'] === '') {
|
||||
return null;
|
||||
}
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'fecha_pago' => [
|
||||
'property' => 'fechaPago',
|
||||
'function' => function($data) {
|
||||
if ($data['fecha_pago'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha_pago']);
|
||||
}
|
||||
],
|
||||
'abonado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['abonado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $data['abonado'] !== 0;
|
||||
}
|
||||
],
|
||||
'fecha_abonado' => [
|
||||
'property' => 'fechaAbonado',
|
||||
'function' => function($data) {
|
||||
if ($data['fecha_abonado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha_abonado']);
|
||||
}
|
||||
],
|
||||
'uf' => [],
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('fecha_pago', (new Implement\Repository\Mapper\DateTime('fecha_pago', 'fechaPago'))
|
||||
->setDefault(null))
|
||||
->register('abonado', (new Implement\Repository\Mapper\Boolean('abonado'))
|
||||
->setDefault(null))
|
||||
->register('fecha_abonado', (new Implement\Repository\Mapper\DateTime('fecha_abonado', 'fechaAbonado'))
|
||||
->setDefault(null))
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['pago'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'numero' => []
|
||||
];
|
||||
return $this->pagoService->getById($data['pago']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Cuota(), $data, $map);
|
||||
}
|
||||
|
||||
@ -158,4 +129,14 @@ GROUP BY `pago`.`fecha`, `proyecto`.`descripcion`
|
||||
ORDER BY `pago`.`fecha`, `proyecto`.`descripcion`";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
public function fetchVigenteByPie(int $pie_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `pago` ON `pago`.`id` = a.`pago`
|
||||
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
|
||||
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
|
||||
WHERE a.`pie` = ? AND tep.`active` = 1";
|
||||
return $this->fetchMany($query, [$pie_id]);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Entrega extends Ideal\Repository
|
||||
@ -15,8 +16,8 @@ class Entrega extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['fecha', 'fondo_operacion', 'fondo_reserva', 'fecha_fondo_operacion', 'fecha_fondo_reserva',
|
||||
'pago_operacion', 'pago_reserva'];
|
||||
$map = new Implement\Repository\MapperParser(['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
|
||||
|
@ -1,13 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Escritura extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
public function __construct(Define\Connection $connection, protected Service\Venta\Pago $pagoService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('escritura');
|
||||
@ -15,20 +18,19 @@ class Escritura extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoService->getById($data['pago']);
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
|
||||
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]
|
||||
[$model->pago->valor, $model->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -17,24 +18,17 @@ class EstadoCierre extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'cierre' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('cierre', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->cierreRepository->fetchById($data['cierre']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoEstadoCierre',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('tipo', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoEstadoCierre')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoEstadoCierreRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
|
||||
return $this->parseData(new Model\Venta\EstadoCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -19,24 +20,17 @@ class EstadoPago extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoPago',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('estado', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoEstadoPago')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoEstadoPagoRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
|
||||
return $this->parseData(new Model\Venta\EstadoPago(), $data, $map);
|
||||
}
|
||||
|
||||
@ -59,6 +53,14 @@ class EstadoPago extends Ideal\Repository
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ?";
|
||||
return $this->fetchMany($query, [$pago_id]);
|
||||
}
|
||||
public function fetchCurrentByPago(int $pago_id): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `{$this->getTable()}` GROUP BY `pago`) e0 ON e0.`id` = a.`id`
|
||||
WHERE a.`pago` = ?";
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
public function fetchByPagoAndEstado(int $pago_id, int $estado_id): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ? AND `estado` = ?";
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -17,24 +18,17 @@ class EstadoPrecio extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'precio' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('precio', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->precioRepository->fetchById($data['precio']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoPrecio',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('estado', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoEstadoPrecio')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoEstadoPrecioRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
|
||||
return $this->parseData(new Model\Venta\EstadoPrecio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -18,24 +19,17 @@ class EstadoVenta extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'venta' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('venta', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->ventaRepository->fetchById($data['venta']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoVenta',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('estado', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoEstadoVenta')
|
||||
->setFunction(function($data) {
|
||||
return $this->tipoEstadoVentaRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
|
||||
return $this->parseData(new Model\Venta\EstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -17,45 +18,31 @@ class Pago extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'valor' => [],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['valor', 'identificador', 'uf', 'pagador']))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['banco'] === null or $data['banco'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoPago',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('tipo', (new Implement\Repository\Mapper())
|
||||
->setProperty('tipoPago')
|
||||
->setFunction(function($data) {
|
||||
if ($data['tipo'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->tipoPagoRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'identificador' => [],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
if ($data['fecha'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'uf' => [],
|
||||
'pagador' => [],
|
||||
'asociado' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('fecha', (new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->setDefault(null))
|
||||
->register('asociado', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['asociado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['asociado']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Pago(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -4,8 +4,8 @@ namespace Incoviba\Repository\Venta;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Pie extends Ideal\Repository
|
||||
{
|
||||
@ -17,32 +17,22 @@ class Pie extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor' => [],
|
||||
'uf' => [],
|
||||
'cuotas' => [],
|
||||
'asociado' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'cuotas']))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('asociado', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['asociado'] === null or $data['asociado'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['asociado']);
|
||||
}
|
||||
],
|
||||
'reajuste' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('reajuste', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['reajuste'] === null or $data['reajuste'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->pagoRepository->fetchById($data['reajuste']);
|
||||
}
|
||||
]
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Pie(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -17,14 +17,11 @@ class Precio extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'unidad' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['valor']))
|
||||
->register('unidad', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->unidadRepository->fetchById($data['unidad']);
|
||||
}
|
||||
],
|
||||
'valor' => []
|
||||
];
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Precio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -53,7 +50,16 @@ 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
|
||||
public function fetchByUnidad(int $unidad_id): array
|
||||
{
|
||||
$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` = ?";
|
||||
return $this->fetchMany($query, [$unidad_id]);
|
||||
}
|
||||
public function fetchVigenteByUnidad(int $unidad_id): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
|
@ -3,11 +3,13 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Propiedad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Unidad $unidadRepository)
|
||||
public function __construct(Define\Connection $connection, protected Service\Venta\Unidad $unidadService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propiedad');
|
||||
@ -15,19 +17,13 @@ class Propiedad extends Ideal\Repository
|
||||
|
||||
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;
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('unidad_principal', (new Implement\Repository\Mapper())
|
||||
->setProperty('unidades')
|
||||
->setFunction(function($data) {
|
||||
return $this->unidadService->getByPropiedad($data['id']);
|
||||
}))
|
||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
|
||||
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -21,12 +22,10 @@ class Propietario extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'dv' => [],
|
||||
'nombres' => [],
|
||||
'apellido_paterno' => [
|
||||
'property' => 'apellidos',
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['dv', 'nombres']))
|
||||
->register('apellido_paterno', (new Implement\Repository\Mapper())
|
||||
->setProperty('apellidos')
|
||||
->setFunction(function($data) {
|
||||
$arr = [
|
||||
'paterno' => $data['apellido_paterno']
|
||||
];
|
||||
@ -34,35 +33,25 @@ class Propietario extends Ideal\Repository
|
||||
$arr['materno'] = $data['apellido_materno'];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
],
|
||||
'direccion' => [
|
||||
'property' => 'datos',
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('direccion', (new Implement\Repository\Mapper())
|
||||
->setProperty('datos')
|
||||
->setFunction(function($data) {
|
||||
$datos = new Model\Venta\Datos();
|
||||
if ($data['direccion'] !== null and $data['direccion'] !== 0) {
|
||||
$datos->direccion = $this->direccionRepository->fetchById($data['direccion']);
|
||||
}
|
||||
return $datos;
|
||||
}
|
||||
],
|
||||
'representante' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('representante', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['representante'] === null or $data['representante'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['representante']);
|
||||
}
|
||||
],
|
||||
'otro' => [
|
||||
'function' => function($data) {
|
||||
if ($data['otro'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $data['otro'] !== 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
}))
|
||||
->register('otro', (new Implement\Repository\Mapper\Boolean('otro'))
|
||||
->setDefault(null));
|
||||
return $this->parseData(new Model\Venta\Propietario(), $data, $map);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Subsidio extends Ideal\Repository
|
||||
@ -15,7 +16,7 @@ class Subsidio extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['pago', 'subsidio'];
|
||||
$map = new Implement\Repository\MapperParser(['pago', 'subsidio']);
|
||||
return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoCierre extends Ideal\Repository
|
||||
@ -15,14 +16,8 @@ class TipoEstadoCierre extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'vigente' => [
|
||||
'function' => function($data) {
|
||||
return $data['vigente'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('vigente', new Implement\Repository\Mapper\Boolean('vigente'));
|
||||
return $this->parseData(new Model\Venta\TipoEstadoCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,7 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPago extends Ideal\Repository
|
||||
@ -16,7 +16,7 @@ class TipoEstadoPago extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = ['descripcion' => []];
|
||||
$map = new Implement\Repository\MapperParser(['descripcion']);
|
||||
return $this->parseData(new Model\Venta\TipoEstadoPago(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoPrecio extends Ideal\Repository
|
||||
@ -15,9 +16,7 @@ class TipoEstadoPrecio extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
$map = new Implement\Repository\MapperParser(['descripcion']);
|
||||
return $this->parseData(new Model\Venta\TipoEstadoPrecio(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoVenta extends Ideal\Repository
|
||||
@ -15,14 +16,8 @@ class TipoEstadoVenta extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'activa' => [
|
||||
'function' => function($data) {
|
||||
return $data['activa'] !== 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['descripcion']))
|
||||
->register('activa', new Implement\Repository\Mapper\Boolean('activa'));
|
||||
return $this->parseData(new Model\Venta\TipoEstadoVenta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoPago extends Ideal\Repository
|
||||
@ -15,9 +16,7 @@ class TipoPago extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => []
|
||||
];
|
||||
$map = new Implement\Repository\MapperParser(['descripcion']);
|
||||
return $this->parseData(new Model\Venta\TipoPago(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
@ -3,8 +3,8 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class TipoUnidad extends Ideal\Repository
|
||||
{
|
||||
@ -16,10 +16,7 @@ class TipoUnidad extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'orden' => []
|
||||
];
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'orden']);
|
||||
return $this->parseData(new Model\Venta\TipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user