0.1.0
This commit is contained in:
@ -6,150 +6,153 @@ use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Incoviba\API\Common\Define\Controller\Json;
|
||||
use Incoviba\API\Common\Factory\Model as Factory;
|
||||
use Incoviba\Venta\Venta;
|
||||
use Incoviba\Mapper\Venta as VentaMapper;
|
||||
|
||||
class Ventas {
|
||||
use Json;
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$ventas = $factory->find(Venta::class)->array();
|
||||
$url = '' . $request->getUri();
|
||||
array_walk($ventas, function (&$item) use ($url) {
|
||||
$item['link'] = [
|
||||
'rel' => 'venta',
|
||||
'title' => 'Venta',
|
||||
'href' => str_replace('/ventas', "/venta/{$item['id']}", $url)
|
||||
];
|
||||
});
|
||||
return $this->withJson($response, compact('ventas'));
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $venta_id): Response {
|
||||
$venta = $factory->find(Venta::class)->one($venta_id);
|
||||
$output = [
|
||||
'input' => $venta_id,
|
||||
'venta' => $venta->toArray(),
|
||||
'link' => [
|
||||
'rel' => 'ventas',
|
||||
'title' => 'Ventas',
|
||||
'href' => str_replace("/venta/{$venta_id}", '/ventas', $request->getUri())
|
||||
]
|
||||
];
|
||||
$output['links'] = [
|
||||
[
|
||||
'rel' => 'propietario',
|
||||
'title' => $venta->propietario()->nombreCompleto(),
|
||||
'href' => str_replace("/venta/{$venta_id}", "/propietario/{$venta->propietario}", $request->getUri())
|
||||
],
|
||||
[
|
||||
'rel' => 'propiedad',
|
||||
'title' => 'Propiedad',
|
||||
'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())
|
||||
];
|
||||
public function __invoke(Request $request, Response $response, Factory $factory, VentaMapper $mapper): Response {
|
||||
$ventas = $mapper->fetchAll();
|
||||
error_log(var_export($ventas, true));
|
||||
$ventas = $factory->find(Venta::class)->array();
|
||||
$url = '' . $request->getUri();
|
||||
array_walk($ventas, function (&$item) use ($url) {
|
||||
$item['link'] = [
|
||||
'rel' => 'venta',
|
||||
'title' => 'Venta',
|
||||
'href' => str_replace('/ventas', "/venta/{$item['id']}", $url)
|
||||
];
|
||||
});
|
||||
return $this->withJson($response, compact('ventas'));
|
||||
}
|
||||
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 {
|
||||
$post = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $post
|
||||
];
|
||||
if (in_array('ventas', $post)) {
|
||||
$output['ventas'] = [];
|
||||
foreach ($post['ventas'] as $input) {
|
||||
$venta = Venta::add($factory, $input);
|
||||
$venta []= [
|
||||
public function show(Request $request, Response $response, Factory $factory, $venta_id): Response {
|
||||
$venta = $factory->find(Venta::class)->one($venta_id);
|
||||
$output = [
|
||||
'input' => $venta_id,
|
||||
'venta' => $venta->toArray(),
|
||||
'created' => $venta->is_new() ? $venta->save() : false
|
||||
'link' => [
|
||||
'rel' => 'ventas',
|
||||
'title' => 'Ventas',
|
||||
'href' => str_replace("/venta/{$venta_id}", '/ventas', $request->getUri())
|
||||
]
|
||||
];
|
||||
}
|
||||
} elseif (in_array('venta', $post)) {
|
||||
$venta = Venta::add($factory, $post);
|
||||
$output['venta'] = $venta;
|
||||
$output['created'] = $venta->is_new() ? $venta->save() : false;
|
||||
$output['links'] = [
|
||||
[
|
||||
'rel' => 'propietario',
|
||||
'title' => $venta->propietario()->nombreCompleto(),
|
||||
'href' => str_replace("/venta/{$venta_id}", "/propietario/{$venta->propietario}", $request->getUri())
|
||||
],
|
||||
[
|
||||
'rel' => 'propiedad',
|
||||
'title' => 'Propiedad',
|
||||
'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 {
|
||||
$post = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $post
|
||||
];
|
||||
if (in_array('ventas', $post)) {
|
||||
$output['ventas'] = [];
|
||||
foreach ($post['ventas'] as $input) {
|
||||
$venta = Venta::add($factory, $input);
|
||||
$venta []= [
|
||||
'venta' => $venta->toArray(),
|
||||
'created' => $venta->is_new() ? $venta->save() : false
|
||||
];
|
||||
}
|
||||
} elseif (in_array('venta', $post)) {
|
||||
$venta = Venta::add($factory, $post);
|
||||
$output['venta'] = $venta;
|
||||
$output['created'] = $venta->is_new() ? $venta->save() : false;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $venta_id): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$input = compact('venta_id', 'post');
|
||||
$venta = $factory->find(Venta::class)->one($venta_id);
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'venta' => $venta->toArray()
|
||||
];
|
||||
$output['edited'] = $venta->edit($post);
|
||||
$output['changes'] = $venta->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $venta_id): Response {
|
||||
$venta = $factory->find(Venta::class)->one($venta_id);
|
||||
$output = [
|
||||
'input' => $venta_id,
|
||||
'venta' => $venta->toArray()
|
||||
];
|
||||
$output['deleted'] = $venta->delete();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $venta_id): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$input = compact('venta_id', 'post');
|
||||
$venta = $factory->find(Venta::class)->one($venta_id);
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'venta' => $venta->toArray()
|
||||
];
|
||||
$output['edited'] = $venta->edit($post);
|
||||
$output['changes'] = $venta->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $venta_id): Response {
|
||||
$venta = $factory->find(Venta::class)->one($venta_id);
|
||||
$output = [
|
||||
'input' => $venta_id,
|
||||
'venta' => $venta->toArray()
|
||||
];
|
||||
$output['deleted'] = $venta->delete();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user