src/Controller/Api/OtherPaymentsController.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Customer;
  4. use App\Entity\OtherPayments;
  5. use App\Services\Api\OtherPaymentsManager;
  6. use DateTime;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class OtherPaymentsController extends ApiController
  13. {
  14.   /** @var OtherPaymentsManager $otherPaymentsManager */
  15.   protected $otherPaymentsManager;
  16.   /**
  17.    * @param OtherPaymentsManager $otherPaymentsManager
  18.    */
  19.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagOtherPaymentsManager $otherPaymentsManager)
  20.   {
  21.     parent::__construct($em$parameterBag);
  22.     $this->otherPaymentsManager $otherPaymentsManager;
  23.   }
  24.   /**
  25.    * @param Request $request
  26.    * @return JsonResponse
  27.    *
  28.    * @Route("/other_payments/{otherPayment}/update", name="api_other_payments_add", methods={"POST"})
  29.    */
  30.   public function updatePayment(OtherPayments $otherPaymentRequest $request)
  31.   {
  32.     $request $this->transformJsonBody($request);
  33.     $data $this->getDataFromRequest($request);
  34.     $response $this->otherPaymentsManager->updatePayment($otherPayment$data);
  35.     return $this->response($data);
  36.     
  37.     $this->setStatusCode($response["code"]);
  38.   }
  39.   /**
  40.    * @param Request $request
  41.    * @return JsonResponse
  42.    *
  43.    * @Route("/other_payments/{date}/list", name="api_other_payments_list", methods={"POST"})
  44.    */
  45.   public function listPayments($dateRequest $request)
  46.   {
  47.     /** @var Customer $customer */
  48.     $customer $this->getUser();
  49.     $data $this->otherPaymentsManager->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. }