Reservation Fixes
This commit is contained in:
@ -39,15 +39,15 @@ class Persona extends Ideal\Model
|
|||||||
|
|
||||||
public function __get(string $name): mixed
|
public function __get(string $name): mixed
|
||||||
{
|
{
|
||||||
if (property_exists($this, $name)) {
|
|
||||||
return $this->{$name};
|
|
||||||
}
|
|
||||||
if ($name === 'datos') {
|
if ($name === 'datos') {
|
||||||
return $this->datos();
|
return $this->datos();
|
||||||
}
|
}
|
||||||
if ($name === 'dv') {
|
if ($name === 'dv') {
|
||||||
return $this->digito;
|
return $this->digito;
|
||||||
}
|
}
|
||||||
|
if (property_exists($this, $name)) {
|
||||||
|
return $this->{$name};
|
||||||
|
}
|
||||||
throw new InvalidArgumentException("Property {$name} is not found in " . __CLASS__);
|
throw new InvalidArgumentException("Property {$name} is not found in " . __CLASS__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ class Datos extends Ideal\Model
|
|||||||
public function jsonSerialize(): mixed
|
public function jsonSerialize(): mixed
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'persona_rut' => $this->persona->rut,
|
||||||
'direccion' => $this->direccion ?? null,
|
'direccion' => $this->direccion ?? null,
|
||||||
'telefono' => $this->telefono ?? null,
|
'telefono' => $this->telefono ?? null,
|
||||||
'email' => $this->email ?? null,
|
'email' => $this->email ?? null,
|
||||||
|
@ -40,7 +40,7 @@ class Reservation extends Common\Ideal\Model
|
|||||||
{
|
{
|
||||||
$price = 0;
|
$price = 0;
|
||||||
foreach ($this->units as $unit) {
|
foreach ($this->units as $unit) {
|
||||||
$price += $unit->unit->precio($this->date);
|
$price += $unit->unit->precio($this->date)?->valor ?? 0;
|
||||||
}
|
}
|
||||||
return $price;
|
return $price;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ class Datos extends Ideal\Repository
|
|||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\Persona\Datos
|
public function save(Define\Model $model): Model\Persona\Datos
|
||||||
{
|
{
|
||||||
$this->saveNew([
|
$model->id = $this->saveNew([
|
||||||
'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
|
'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
|
||||||
'nacionalidad', 'ocupacion'
|
'nacionalidad', 'ocupacion'
|
||||||
], [
|
], [
|
||||||
@ -116,4 +116,11 @@ class Datos extends Ideal\Repository
|
|||||||
}
|
}
|
||||||
$this->connection->execute($query, $flattened);
|
$this->connection->execute($query, $flattened);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function filterData(array $data): array
|
||||||
|
{
|
||||||
|
$fields = ['persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
|
||||||
|
'nacionalidad', 'ocupacion'];
|
||||||
|
return array_intersect_key($data, array_flip($fields));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,6 +241,11 @@ class Persona extends Ideal\Service
|
|||||||
}
|
}
|
||||||
if (!empty($addressData)) {
|
if (!empty($addressData)) {
|
||||||
$address = $this->direccionService->add($addressData);
|
$address = $this->direccionService->add($addressData);
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
if (str_starts_with($key, 'address_') or str_starts_with($key, 'direccion_')) {
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
$data['direccion_id'] = $address->id;
|
$data['direccion_id'] = $address->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,29 +267,8 @@ class Persona extends Ideal\Service
|
|||||||
try {
|
try {
|
||||||
$datos = $this->datosPersonaRepository->fetchByPersona($persona->rut);
|
$datos = $this->datosPersonaRepository->fetchByPersona($persona->rut);
|
||||||
$this->datosPersonaRepository->edit($datos, $data);
|
$this->datosPersonaRepository->edit($datos, $data);
|
||||||
} catch (Implement\Exception\EmptyResult) {
|
} catch (Implement\Exception\EmptyResult $exception) {
|
||||||
$datosData = ['persona_rut' => $persona->rut];
|
$datosData = ['persona_rut' => $persona->rut, ...$data];
|
||||||
/*if (isset($data['direccion_id'])) {
|
|
||||||
$datosData['direccion_id'] = $data['direccion_id'];
|
|
||||||
}
|
|
||||||
if (isset($data['email'])) {
|
|
||||||
$datosData['email'] = $data['email'];
|
|
||||||
}
|
|
||||||
if (isset($data['telefono'])) {
|
|
||||||
$datosData['telefono'] = $data['telefono'];
|
|
||||||
}
|
|
||||||
if (isset($data['estado_civil'])) {
|
|
||||||
$datosData['estado_civil'] = $data['estado_civil'];
|
|
||||||
}
|
|
||||||
if (isset($data['fecha_nacimiento'])) {
|
|
||||||
$datosData['fecha_nacimiento'] = $data['fecha_nacimiento'];
|
|
||||||
}
|
|
||||||
if (isset($data['ocupacion'])) {
|
|
||||||
$datosData['ocupacion'] = $data['ocupacion'];
|
|
||||||
}
|
|
||||||
if (isset($data['sexo'])) {
|
|
||||||
$datosData['sexo'] = $data['sexo'];
|
|
||||||
}*/
|
|
||||||
$datosData = $this->datosPersonaRepository->filterData($datosData);
|
$datosData = $this->datosPersonaRepository->filterData($datosData);
|
||||||
$datos = $this->datosPersonaRepository->create($datosData);
|
$datos = $this->datosPersonaRepository->create($datosData);
|
||||||
try {
|
try {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Venta;
|
namespace Incoviba\Service\Venta;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use DateMalformedStringException;
|
use DateMalformedStringException;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
@ -33,6 +35,12 @@ class Reservation extends Ideal\Service\API
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $project_id
|
||||||
|
* @return array
|
||||||
|
* @throws ServiceAction\Read
|
||||||
|
*/
|
||||||
public function getByProject(int $project_id): array
|
public function getByProject(int $project_id): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -51,6 +59,21 @@ class Reservation extends Ideal\Service\API
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $buyer_rut
|
||||||
|
* @param DateTimeInterface $date
|
||||||
|
* @return Model\Venta\Reservation
|
||||||
|
* @throws Read
|
||||||
|
*/
|
||||||
|
public function getByBuyerAndDate(int $buyer_rut, DateTimeInterface $date): Model\Venta\Reservation
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->process($this->reservationRepository->fetchByBuyerAndDate($buyer_rut, $date));
|
||||||
|
} catch (Implement\Exception\EmptyResult $exception) {
|
||||||
|
throw new ServiceAction\Read(__CLASS__, $exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $project_id
|
* @param int $project_id
|
||||||
* @return array
|
* @return array
|
||||||
@ -106,7 +129,7 @@ class Reservation extends Ideal\Service\API
|
|||||||
try {
|
try {
|
||||||
$broker = $this->brokerService->get($data['broker_rut']);
|
$broker = $this->brokerService->get($data['broker_rut']);
|
||||||
$reservation = $this->reservationRepository->edit($reservation, ['broker_rut' => $broker->rut]);
|
$reservation = $this->reservationRepository->edit($reservation, ['broker_rut' => $broker->rut]);
|
||||||
} catch (ServiceAction\Read $exception) {}
|
} catch (ServiceAction\Read) {}
|
||||||
}
|
}
|
||||||
} catch (Implement\Exception\EmptyResult) {
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
$buyerData = [];
|
$buyerData = [];
|
||||||
@ -114,7 +137,7 @@ class Reservation extends Ideal\Service\API
|
|||||||
if (!str_starts_with($key, 'buyer_')) {
|
if (!str_starts_with($key, 'buyer_')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$buyerData[substr($key, 6)] = $value;
|
$buyerData[substr($key, strlen('buyer_'))] = $value;
|
||||||
}
|
}
|
||||||
$this->personaService->add($buyerData);
|
$this->personaService->add($buyerData);
|
||||||
if (array_key_exists('broker_rut', $data)) {
|
if (array_key_exists('broker_rut', $data)) {
|
||||||
@ -186,11 +209,11 @@ class Reservation extends Ideal\Service\API
|
|||||||
return $this->stateRepository->fetchByReservation($reservation_id);
|
return $this->stateRepository->fetchByReservation($reservation_id);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
$model->buyer = $this->personaService->getById($model->buyer->rut);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
protected function addUnits(Model\Venta\Reservation $reservation, array $units): void
|
protected function addUnits(Model\Venta\Reservation $reservation, array $units): void
|
||||||
{
|
{
|
||||||
//var_dump(__LINE__, $units);
|
|
||||||
foreach ($units as $unit_id => $value) {
|
foreach ($units as $unit_id => $value) {
|
||||||
try {
|
try {
|
||||||
$unit = $this->unitService->getById($unit_id);
|
$unit = $this->unitService->getById($unit_id);
|
||||||
@ -203,7 +226,6 @@ class Reservation extends Ideal\Service\API
|
|||||||
}
|
}
|
||||||
protected function addPromotions(Model\Venta\Reservation $reservation, array $promotions): void
|
protected function addPromotions(Model\Venta\Reservation $reservation, array $promotions): void
|
||||||
{
|
{
|
||||||
var_dump(__LINE__, $promotions);
|
|
||||||
foreach ($promotions as $promotion_id) {
|
foreach ($promotions as $promotion_id) {
|
||||||
try {
|
try {
|
||||||
$promotion = $this->promotionService->getById($promotion_id);
|
$promotion = $this->promotionService->getById($promotion_id);
|
||||||
|
Reference in New Issue
Block a user