From baf32be9cb6e0814d13a5e5804b39f6cb681d2dd Mon Sep 17 00:00:00 2001 From: Aldarien <> Date: Mon, 14 Dec 2020 17:33:53 -0300 Subject: [PATCH] Ceder --- app/Controller/Ventas.php | 51 ++++++--- resources/views/ventas/ceder.blade.php | 143 +++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 resources/views/ventas/ceder.blade.php diff --git a/app/Controller/Ventas.php b/app/Controller/Ventas.php index f204c70..e66faf2 100644 --- a/app/Controller/Ventas.php +++ b/app/Controller/Ventas.php @@ -471,10 +471,45 @@ class Ventas { $id = get('venta'); $venta = model(Venta::class)->findOne($id); + $nueva_venta = model(Venta::class)->create(); $f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone')); - $valor = correctNumber(post('pago')); - $uf = uf($f); + + list($rut, $dv) = explode('-', str_replace('.', '', post('rut'))); + $propietario = model(Propietario::class)->where('rut', $rut)->findOne(); + if (!$propietario) { + $propietario = model(Propietario::class)->create(); + $propietario->rut = $rut; + $propietario->dv = $dv; + $propietario->nombres = trim(post('nombres')); + $propietario->apellido_paterno = trim(post('paterno')); + $propietario->apellido_materno = trim(post('materno')); + $propietario->direccion = $direccion->id; + if (post('otro') != null) { + $propietario->otro = 1; + } + + $propietario->save(); + } + + $nueva_venta->fecha_ingreso = $f->format(); + $nueva_venta->estado = 1; + $cols = [ + 'propiedad', + 'pie', + 'bono_pie', + 'credito', + 'escritura', + 'subsidio', + 'fecha', + 'valor_uf', + 'agente', + 'uf' + ]; + foreach ($cols as $col) { + $nueva_venta->{$col} = $venta->{$col}; + } + $nueva_venta->new(); $venta->estado = -1; $tipo = model(TipoEstadoVenta::class)->where('descripcion', 'cedida')->findOne(); @@ -484,18 +519,8 @@ class Ventas 'fecha' => $f->format('Y-m-d') ]; $estado = model(EstadoVenta::class)->create($data); - $propiedad = $venta->propiedad(); - $propiedad->estado = 0; - $pago = model(Pago::class)->create(); - $pago->fecha = $f->format('Y-m-d'); - $pago->valor = $valor; - $pago->uf = $uf->uf->value; - $pago->tipo = 1; - - $pago->new(); - $propiedad->save(); $estado->save(); - $venta->resciliacion = $pago->id; + $venta->save(); header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id])); } diff --git a/resources/views/ventas/ceder.blade.php b/resources/views/ventas/ceder.blade.php new file mode 100644 index 0000000..82fca7d --- /dev/null +++ b/resources/views/ventas/ceder.blade.php @@ -0,0 +1,143 @@ +@extends('layout.base') + +@section('content') +
+

Ceder - {{$venta->unidad()->descripcion}} - {{$venta->proyecto()->descripcion}}

+
+
+
+
+
Fecha
+ +
+
+
+
+
NUEVO PROPIETARIO
+
+
+
RUT
+
+
+
+
Nombre
+
+
+
+
+
+
+
Dirección
+
+
+
+
+
+
+
+
+
+
+
+
+@endsection + +@push('scripts') + +@endpush