<?php
namespace App\Controller\Api;
use App\Entity\ClubMonthlyPayments;
use App\Entity\Customer;
use App\Entity\Document;
use App\Services\Api\ClubMonthlyPaymentsManager;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ClubMonthlyPaymentsController extends ApiController
{
/** @var ClubMonthlyPaymentsManager $clubMonthlyPaymentsManager */
protected $clubMonthlyPaymentsManager;
/**
* @param ClubMonthlyPaymentsManager $clubMonthlyPaymentsManager
*/
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, ClubMonthlyPaymentsManager $clubMonthlyPaymentsManager)
{
parent::__construct($em, $parameterBag);
$this->clubMonthlyPaymentsManager = $clubMonthlyPaymentsManager;
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/club_monthly_payments/{clubMonthlyPayment}/update", name="api_club_monthly_payments_add", methods={"POST"})
*/
public function updatePaymentClub(ClubMonthlyPayments $clubMonthlyPayment, Request $request)
{
$request = $this->transformJsonBody($request);
$data = $this->getDataFromRequest($request);
$response = $this->clubMonthlyPaymentsManager->updatePaymentClub($clubMonthlyPayment, $data);
return $this->response($data);
$this->setStatusCode($response["code"]);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/club_monthly_payments/{date}/list", name="api_club_monthly_payments_list", methods={"POST"})
*/
public function listPayments($date, Request $request)
{
$customer = $this->getUser();
$data = $this->clubMonthlyPaymentsManager->listByMonthlyPayment($customer, new DateTime($date));
return $this->response($data);
}
protected function getDataFromRequest(Request $request)
{
return [
'amount'=> $request->get('amount') !== 'null' ? $request->get('amount') : '0.0' ,
'datePaid' => $request->get('datePaid'),
'note' => $request->get('note'),
'paid' => $request->get('paid'),
];
}
}