getParsedBody(); $output = [ 'input' => $body, 'pago_id' => $pago_id, 'pago' => null ]; try { $pago = $pagoRepository->fetchById($pago_id); if (isset($body['fecha'])) { $fecha = new DateTimeImmutable($body['fecha']); $body['fecha'] = $fecha->format('Y-m-d'); } $output['pago'] = $pagoRepository->edit($pago, $body); } catch (EmptyResult) {} return $this->withJson($response, $output); } // NOT IMPLEMENTED public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); $date = new DateTimeImmutable($json->fecha); $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); return $response->withHeader('Content-Type', 'application/json'); } // NOT IMPLEMENTED public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface { $body = $request->getBody(); $json = json_decode($body->getContents()); $date = new DateTimeImmutable($json->fecha); $response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented'])); return $response->withHeader('Content-Type', 'application/json'); } public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface { $pagos = $pagoService->getPendientes(); $pagos_pendientes = []; foreach ($pagos as $pago) { $pagos_pendientes []= [ 'id' => $pago->id ]; } return $this->withJson($response, ['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)]); } public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface { $pagos = $pagoService->getDepositados(); $pagos_depositados = []; foreach ($pagos as $pago) { $pagos_depositados []= [ 'id' => $pago->id ]; } return $this->withJson($response, ['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)]); } public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface { $pagos = $pagoService->getRebotes(); $rebotes = []; foreach ($pagos as $pago) { $rebotes []= [ 'id' => $pago->id ]; } return $this->withJson($response, ['pagos' => $rebotes, 'total' => count($rebotes)]); } }