src/Controller/Api/ClubMonthlyPaymentsController.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\ClubMonthlyPayments;
  4. use App\Entity\Customer;
  5. use App\Entity\Document;
  6. use App\Services\Api\ClubMonthlyPaymentsManager;
  7. use DateTime;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class ClubMonthlyPaymentsController extends ApiController
  14. {
  15.   /** @var ClubMonthlyPaymentsManager $clubMonthlyPaymentsManager */
  16.   protected $clubMonthlyPaymentsManager;
  17.   /**
  18.    * @param ClubMonthlyPaymentsManager $clubMonthlyPaymentsManager
  19.    */
  20.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagClubMonthlyPaymentsManager $clubMonthlyPaymentsManager)
  21.   {
  22.     parent::__construct($em$parameterBag);
  23.     $this->clubMonthlyPaymentsManager $clubMonthlyPaymentsManager;
  24.   }
  25.   /**
  26.    * @param Request $request
  27.    * @return JsonResponse
  28.    *
  29.    * @Route("/club_monthly_payments/{clubMonthlyPayment}/update", name="api_club_monthly_payments_add", methods={"POST"})
  30.    */
  31.   public function updatePaymentClub(ClubMonthlyPayments $clubMonthlyPaymentRequest $request)
  32.   {
  33.     $request $this->transformJsonBody($request);
  34.     $data $this->getDataFromRequest($request);
  35.     $response $this->clubMonthlyPaymentsManager->updatePaymentClub($clubMonthlyPayment$data);
  36.     return $this->response($data);
  37.     
  38.     $this->setStatusCode($response["code"]);
  39.   }
  40.   /**
  41.    * @param Request $request
  42.    * @return JsonResponse
  43.    *
  44.    * @Route("/club_monthly_payments/{date}/list", name="api_club_monthly_payments_list", methods={"POST"})
  45.    */
  46.   public function listPayments($dateRequest $request)
  47.   {
  48.     $customer $this->getUser();
  49.     $data $this->clubMonthlyPaymentsManager->listByMonthlyPayment($customer, new DateTime($date));
  50.     return $this->response($data);
  51.   }
  52.   protected function getDataFromRequest(Request $request)
  53.   {
  54.     return [
  55.       'amount'=> $request->get('amount') !== 'null' $request->get('amount') : '0.0' ,
  56.       'datePaid' => $request->get('datePaid'),
  57.       'note' => $request->get('note'),
  58.       'paid' => $request->get('paid'),
  59.     ];
  60.   }
  61. }