Servicio y vista

This commit is contained in:
Juan Pablo Vial
2024-11-29 17:47:12 -03:00
parent 1f0f25bbde
commit b2c55c08ce
3 changed files with 61 additions and 38 deletions

View File

@ -15,15 +15,15 @@
</tr> </tr>
</thead> </thead>
<tbody id="proveedores"> <tbody id="proveedores">
@foreach ($sociedades as $sociedad) @foreach ($proveedores as $proveedor)
<tr> <tr>
<td>{{$sociedad->nombre}}</td> <td>{{$proveedor->nombre}}</td>
<td>{{$sociedad->contacto->nombreCompleto()}}</td> <td>{{$proveedor->contacto->nombreCompleto()}}</td>
<td class="right aligned"> <td class="right aligned">
<button class="ui icon button" data-sociedad="{{$sociedad->rut}}"> <button class="ui icon button" data-sociedad="{{$proveedor->rut}}">
<i class="edit icon"></i> <i class="edit icon"></i>
</button> </button>
<button class="ui red icon button" data-sociedad="{{$sociedad->rut}}"> <button class="ui red icon button" data-sociedad="{{$proveedor->rut}}">
<i class="remove icon"></i> <i class="remove icon"></i>
</button> </button>
</td> </td>
@ -38,62 +38,53 @@
<div class="three wide field"> <div class="three wide field">
<label for="rut">RUT</label> <label for="rut">RUT</label>
<div class="ui right labeled input"> <div class="ui right labeled input">
<input class="right aligned" type="text" id="rut" name="rut" placeholder="RUT" maxlength="10" required /> <input class="right aligned" type="text" id="rut" name="rut" placeholder="RUT" maxlength="10"
required/>
<div class="ui basic label">-<span id="dv"></span></div> <div class="ui basic label">-<span id="dv"></span></div>
</div> </div>
</div> </div>
<div class="five wide field"> <div class="five wide field">
<label for="nombre">Nombre</label> <label for="nombre">Nombre</label>
<input type="text" id="nombre" name="nombre" placeholder="Nombre" required /> <input type="text" id="nombre" name="nombre" placeholder="Nombre" required/>
</div> </div>
<div class="field"> <div class="field">
<label for="razon">Razón Social</label> <label for="razon">Razón Social</label>
<input type="text" id="razon" name="razon" placeholder="Razón Social" required /> <input type="text" id="razon" name="razon" placeholder="Razón Social" required/>
</div>
<div class="four wide field">
<label for="tipo">Tipo</label>
<div class="ui selection dropdown" id="tipo">
<input type="hidden" name="tipo" required />
<i class="dropdown icon"></i>
<div class="default text">Tipo</div>
<div class="menu">
@foreach ($tiposSociedades as $tipo)
<div class="item" data-value="{{$tipo->id}}">{{$tipo->descripcion}}</div>
@endforeach
</div>
</div>
</div> </div>
<div class="ui divider">Contacto</div> <div class="ui divider">Contacto</div>
<div class="three wide field"> <div class="three wide field">
<label for="rut_contacto">RUT</label> <label for="rut_contacto">RUT</label>
<div class="ui right labeled input"> <div class="ui right labeled input">
<input type="text" id="rut_contacto" name="rut_contacto" placeholder="RUT" maxlength="10" required /> <input type="text" id="rut_contacto" name="rut_contacto" placeholder="RUT" maxlength="10"
required/>
<div class="ui basic label">-<span id="dv_contacto"></span></div> <div class="ui basic label">-<span id="dv_contacto"></span></div>
</div> </div>
</div> </div>
<div class="fields"> <div class="fields">
<div class="five wide field"> <div class="five wide field">
<label for="nombre_contacto">Nombre</label> <label for="nombre_contacto">Nombre</label>
<input type="text" id="nombre_contacto" name="nombre_contacto" placeholder="Nombre" required /> <input type="text" id="nombre_contacto" name="nombre_contacto" placeholder="Nombre" required/>
</div> </div>
<div class="field"> <div class="field">
<label for="apellido_paterno_contacto">Apellido Paterno</label> <label for="apellido_paterno_contacto">Apellido Paterno</label>
<input type="text" id="apellido_paterno_contacto" name="apellido_paterno_contacto" placeholder="Apellido Paterno" required /> <input type="text" id="apellido_paterno_contacto" name="apellido_paterno_contacto"
placeholder="Apellido Paterno" required/>
</div> </div>
<div class="field"> <div class="field">
<label for="apellido_materno_contacto">Apellido Materno</label> <label for="apellido_materno_contacto">Apellido Materno</label>
<input type="text" id="apellido_materno_contacto" name="apellido_materno_contacto" placeholder="Apellido Materno" /> <input type="text" id="apellido_materno_contacto" name="apellido_materno_contacto"
placeholder="Apellido Materno"/>
</div> </div>
</div> </div>
<div class="field"> <div class="field">
<label for="email_contacto">Email</label> <label for="email_contacto">Email</label>
<input type="email" id="email_contacto" name="email_contacto" placeholder="Email" /> <input type="email" id="email_contacto" name="email_contacto" placeholder="Email"/>
</div> </div>
<div class="field"> <div class="field">
<label for="telefono_contacto">Teléfono</label> <label for="telefono_contacto">Teléfono</label>
<div class="ui left labeled input"> <div class="ui left labeled input">
<div class="ui basic label">+56</div> <div class="ui basic label">+56</div>
<input type="text" id="telefono_contacto" name="telefono_contacto" placeholder="Teléfono" /> <input type="text" id="telefono_contacto" name="telefono_contacto" placeholder="Teléfono"/>
</div> </div>
</div> </div>
</form> </form>
@ -133,7 +124,7 @@
}, },
proveedores: '' proveedores: ''
}, },
data: JSON.parse('{!! json_encode($sociedades) !!}'), data: JSON.parse('{!! json_encode($proveedores) !!}'),
add() { add() {
return { return {
sociedad: () => { sociedad: () => {
@ -175,7 +166,8 @@
} }
} }
}, },
edit() {}, edit() {
},
remove() { remove() {
return { return {
sociedad: rut => { sociedad: rut => {
@ -253,7 +245,7 @@
} }
let suma = 0 let suma = 0
let mul = 2 let mul = 2
for (let i = rut.length-1; i >= 0; i--) { for (let i = rut.length - 1; i >= 0; i--) {
suma += parseInt(rut[i]) * mul suma += parseInt(rut[i]) * mul
mul = (mul + 1) % 8 || 2 mul = (mul + 1) % 8 || 2
} }

View File

@ -11,17 +11,13 @@ use Incoviba\Service;
class Proveedores class Proveedores
{ {
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Sociedad $sociedadService, Service\Inmobiliaria\Proveedor $proveedorService,
Repository\Inmobiliaria\TipoSociedad $tipoSociedad): ResponseInterface Repository\Inmobiliaria\TipoSociedad $tipoSociedad): ResponseInterface
{ {
$sociedades = []; $proveedores = [];
try { try {
$sociedades = $sociedadService->getAll('nombre'); $proveedores = $proveedorService->getAll('nombre');
} catch (EmptyResult) {} } catch (EmptyResult) {}
$tiposSociedades = []; return $view->render($response, 'inmobiliarias.proveedores', compact('proveedores'));
try {
$tiposSociedades = $tipoSociedad->fetchAll('descripcion');
} catch (EmptyResult) {}
return $view->render($response, 'inmobiliarias.proveedores', compact('sociedades', 'tiposSociedades'));
} }
} }

View File

@ -0,0 +1,35 @@
<?php
namespace Incoviba\Service\Inmobiliaria;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Common\Define;
use Incoviba\Repository;
use Incoviba\Model;
class Proveedor extends Ideal\Service
{
public function __construct(LoggerInterface $logger, protected Repository\Inmobiliaria\Proveedor $proveedorRepository)
{
parent::__construct($logger);
}
public function getAll(?string $orderBy = null): array
{
try {
return $this->proveedorRepository->fetchAll($orderBy);
} catch (Implement\Exception\EmptyResult) {
return [];
}
}
public function getByRut(int $proveedor_rut): ?Model\Inmobiliaria\Proveedor
{
try {
return $this->proveedorRepository->fetchById($proveedor_rut);
} catch (Implement\Exception\EmptyResult) {
return null;
}
}
}