diff --git a/common/Alias/Model.php b/common/Alias/Model.php index 81df5c6..915a095 100644 --- a/common/Alias/Model.php +++ b/common/Alias/Model.php @@ -39,7 +39,7 @@ abstract class Model extends BaseModel implements ModelInterface { } return $definitions; } - public function parentOf(string $child_class, array $definitions): ?array { + public function parentOf(string $child_class, array $definitions): bool|array { $definitions = $this->validateDefinitions( $definitions, [Model::CHILD_KEY, Model::SELF_KEY], @@ -48,7 +48,7 @@ abstract class Model extends BaseModel implements ModelInterface { $where = [[$definitions[Model::CHILD_KEY], $this->{$definitions[Model::SELF_KEY]}]]; return $this->factory->find($child_class)->where($where)->many(); } - public function childOf(string $parent_class, array $definitions): ?ModelInterface { + public function childOf(string $parent_class, array $definitions): bool|ModelInterface { $definitions = $this->validateDefinitions( $definitions, [Model::PARENT_KEY, Model::SELF_KEY], diff --git a/common/Controller/Ventas.php b/common/Controller/Ventas.php index ba3025a..d95ff6b 100644 --- a/common/Controller/Ventas.php +++ b/common/Controller/Ventas.php @@ -45,6 +45,69 @@ class Ventas { 'href' => str_replace("/venta/{$venta_id}", "/propiedad/{$venta->propiedad}", $request->getUri()) ] ]; + if ($venta->pie()) { + $output['links'] []= [ + 'rel' => 'pie', + 'title' => 'Pie', + 'href' => str_replace("/venta/{$venta_id}", "/pie/{$venta->pie}", $request->getUri()) + ]; + } + if ($venta->bono()) { + $output['links'] []= [ + 'rel' => 'bono_pie', + 'title' => 'Bono Pie', + 'href' => str_replace("/venta/{$venta_id}", "/bono/{$venta->bono_pie}", $request->getUri()) + ]; + } + if ($venta->credito()) { + $output['links'] []= [ + 'rel' => 'credito', + 'title' => 'Credito', + 'href' => str_replace("/venta/{$venta_id}", "/credito/{$venta->credito}", $request->getUri()) + ]; + } + if ($venta->escritura()) { + $output['links'] []= [ + 'rel' => 'escritura', + 'title' => 'Escritura', + 'href' => str_replace("/venta/{$venta_id}", "/escritura/{$venta->escritura}", $request->getUri()) + ]; + } + if ($venta->subsidio()) { + $output['links'] []= [ + 'rel' => 'subsidio', + 'title' => 'Subsidio', + 'href' => str_replace("/venta/{$venta_id}", "/subsidio/{$venta->subsidio}", $request->getUri()) + ]; + } + if ($venta->entrega()) { + $output['links'] []= [ + 'rel' => 'entrega', + 'title' => 'Entrega', + 'href' => str_replace("/venta/{$venta_id}", "/entrega/{$venta->entrega}", $request->getUri()) + ]; + } + if ($venta->proyectoAgente()) { + $output['links'] []= [ + 'rel' => 'proyecto_agente', + 'title' => 'Proyecto Agente', + 'href' => str_replace("/venta/{$venta_id}", "/proyecto_agente/{$venta->agente}", $request->getUri()) + ]; + } + if ($venta->promocion()) { + $output['links'] []= [ + 'rel' => 'promocion', + 'title' => 'Promocion', + 'href' => str_replace("/venta/{$venta_id}", "/promocion/{$venta->promocion}", $request->getUri()) + ]; + } + if ($venta->resciliacion()) { + $output['links'] []= [ + 'rel' => 'resciliacion', + 'title' => 'Resciliacion', + 'href' => str_replace("/venta/{$venta_id}", "/resciliacion/{$venta->resciliacion}", $request->getUri()) + ]; + } return $this->withJson($response, $output); } public function add(Request $request, Response $response, Factory $factory): Response { diff --git a/common/Define/Model.php b/common/Define/Model.php index 0356d9e..d01ebfa 100644 --- a/common/Define/Model.php +++ b/common/Define/Model.php @@ -21,7 +21,7 @@ interface Model { * @param array $definitions array of conditions for connecting to the child table * @return array|null */ - public function parentOf(string $child_class, array $definitions): ?array; + public function parentOf(string $child_class, array $definitions): bool|array; /** * Get parent model of class {$parent_class} @@ -29,7 +29,7 @@ interface Model { * @param array $definitions array of conditions for connecting to the parent table * @return Model|null */ - public function childOf(string $parent_class, array $definitions): ?Model; + public function childOf(string $parent_class, array $definitions): bool|Model; /** * Get all siblings of class {$sibling_class} diff --git a/src/Venta/Agente.php b/src/Venta/Agente.php index 7d46f08..bf68982 100644 --- a/src/Venta/Agente.php +++ b/src/Venta/Agente.php @@ -2,5 +2,28 @@ namespace Incoviba\Venta; use Incoviba\API\Common\Alias\Model; +use Incoviba\Common\Direccion; -class Agente extends Model {} +/** + * @property int $id + * @property TipoAgente $tipo + * @property int $rut + * @property string $descripcion + * @property string $representante + * @property int $telefono + * @property string $correo + * @property Direccion $direccion + * @property string $giro + * @property string $abreviacion + */ +class Agente extends Model { + public static $_table = 'agente'; + + protected $ats; + public function agenteTipos() { + if ($this->ats === null) { + $this->ats = $this->parentOf(AgenteTipo::class, [Model::CHILD_KEY => 'agente']); + } + return $this->ats; + } +} diff --git a/src/Venta/AgenteTipo.php b/src/Venta/AgenteTipo.php new file mode 100644 index 0000000..edf8c14 --- /dev/null +++ b/src/Venta/AgenteTipo.php @@ -0,0 +1,31 @@ +agente_o === null) { + $this->agente_o = $this->childOf(Agente::class, [Model::SELF_KEY => 'agente']); + } + return $this->agente_o; + } + protected $tipo_o; + public function tipo() { + if ($this->tipo_o === null) { + $this->tipo_o = $this->childOf(TipoAgente::class, [Model::SELF_KEY => 'tipo']); + } + return $this->tipo_o; + } + + protected $pas; + public function proyectoAgentes() { + if ($this->pas === null) { + $this->pas = $this->parentOf(ProyectoAgente::class, [Model::CHILD_KEY => 'agente']); + } + return $this->pas; + } +} diff --git a/src/Venta/ProyectoAgente.php b/src/Venta/ProyectoAgente.php new file mode 100644 index 0000000..f92ea60 --- /dev/null +++ b/src/Venta/ProyectoAgente.php @@ -0,0 +1,24 @@ +at === null) { + $this->at = $this->childOf(AgenteTipo::class, [Model::SELF_KEY => 'agente']); + } + return $this->at; + } + protected $proyecto_o; + public function proyecto() { + if ($this->proyecto_o === null) { + $this->proyecto_o = $this->childOf(Proyecto::class, [Model::SELF_KEY => 'proyecto']); + } + return $this->proyecto_o; + } +} diff --git a/src/Venta/TipoAgente.php b/src/Venta/TipoAgente.php new file mode 100644 index 0000000..fc88a17 --- /dev/null +++ b/src/Venta/TipoAgente.php @@ -0,0 +1,16 @@ +ats === null) { + $this->ats = $this->parentOf(AgenteTipo::class, [Model::CHILD_KEY => 'tipo']); + } + return $this->ats; + } +} diff --git a/src/Venta/Venta.php b/src/Venta/Venta.php index a38bf60..1179a3d 100644 --- a/src/Venta/Venta.php +++ b/src/Venta/Venta.php @@ -14,7 +14,7 @@ use Incoviba\API\Common\Alias\Model; * @property ?Escritura $escritura * @property ?Subsidio $subsidio * @property ?DateTime $escriturado - * @property ?Entrega $entrga + * @property ?Entrega $entrega * @property ?DateTime $entregado * @property DateTime $fecha * @property double $valor_uf @@ -90,12 +90,12 @@ class Venta extends Model { } return $this->entrega_o; } - protected $agente_o; - public function agente() { - if ($this->agente_o === null) { - $this->agente_o = $this->childOf(Agente::class, [Model::SELF_KEY => 'agente']); + protected $pa; + public function proyectoAgente() { + if ($this->pa === null) { + $this->pa = $this->childOf(ProyectoAgente::class, [Model::SELF_KEY => 'agente']); } - return $this->agente_o; + return $this->pa; } protected $promocion_o; public function promocion() {