src/Controller/Api/v3/TimesheetController.php line 102

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\v3;
  3. use App\Controller\Api\Service\EmployeeActivityService;
  4. use App\Controller\Api\Service\HourCapAnalysisService;
  5. use App\Controller\Api\Service\PartnerService;
  6. use App\Controller\Api\Service\ProjectService;
  7. use App\Controller\Api\Service\ReferenceService;
  8. use App\Controller\Api\Service\TimesheetService;
  9. use App\Entity\WorkerTimesheet;
  10. use App\Enum\SeverityInterface;
  11. use App\Service\SerializeService\PartnerSerialize;
  12. use App\Service\SerializeService\ProjectSerialize;
  13. use App\Service\SerializeService\ReferenceSerialize;
  14. use App\Service\SerializeService\TimesheetSerialize;
  15. use App\Service\StreamingService;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\InputBag;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\HttpFoundation\StreamedResponse;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Symfony\Contracts\Translation\TranslatorInterface;
  23. /**
  24.  * @Route("/api/v3/timesheet")
  25.  */
  26. class TimesheetController extends AbstractController
  27. {
  28.     /**
  29.      * ✅
  30.      * @Route("/employees-with-master-data", name="api_v3_timesheet_employees_with_master_data")
  31.      * @param TranslatorInterface $translator
  32.      * @param EmployeeActivityService $employeeActivityService
  33.      * @param PartnerService $partnerService
  34.      * @param PartnerSerialize $partnerSerialize
  35.      * @param ProjectService $projectService
  36.      * @param ProjectSerialize $projectSerialize
  37.      * @param ReferenceSerialize $referenceSerialize
  38.      * @param ReferenceService $referenceService
  39.      * @param TimesheetService $timesheetService
  40.      * @param TimesheetSerialize $timesheetSerialize
  41.      * @return StreamedResponse
  42.      */
  43.     public function employeesWithWithMasterData(TranslatorInterface $translator,
  44.                                                 EmployeeActivityService $employeeActivityService,
  45.                                                 PartnerService $partnerServicePartnerSerialize $partnerSerialize,
  46.                                                 ProjectService $projectServiceProjectSerialize $projectSerialize,
  47.                                                 ReferenceSerialize $referenceSerializeReferenceService $referenceService,
  48.                                                 TimesheetService $timesheetServiceTimesheetSerialize $timesheetSerialize
  49.     ): StreamedResponse
  50.     {
  51.         $streamed = new StreamingService([
  52.             "localText" => ["completed" => $translator->trans('Loaded')]
  53.         ]);
  54.         $streamed->appendStream(
  55.             "employees",
  56.             $translator->trans('Loading employees'),
  57.             function() use ($timesheetService$timesheetSerialize){
  58.                 $data $timesheetService
  59.                     ->setParams(new InputBag([]))
  60.                     ->findByPayload();
  61.                 return $timesheetSerialize->setEntity($data["dataset"])->serializeMonth($data["m"]);
  62.             }
  63.         );
  64.         $streamed->appendStream(
  65.             "partners",
  66.             $translator->trans('Loading partners'),
  67.             fn() => $partnerSerialize->setEntity($partnerService->fetchPartnersForMainList())->serializeFull()
  68.         );
  69.         $streamed->appendStream(
  70.             "projects",
  71.             $translator->trans('Loading projects'),
  72.             fn() => $projectSerialize->setEntity($projectService->fetchAll())->serializeForMainList()
  73.         );
  74.         $streamed->appendStream(
  75.             "timesheet_status",
  76.             $translator->trans('Loading ts statuses'),
  77.             fn() => $referenceSerialize->setEntity($referenceService->timesheetStatuses())->setGroups([
  78.                 "timsheet@base"
  79.             ])->render()
  80.         );
  81.         return $streamed->flush();
  82.     }
  83.     /**
  84.      * ✅
  85.      * @Route("/find-by-payload", name="api_v3_timesheet_find_by_year_and_month", methods={"POST"})
  86.      * @return StreamedResponse
  87.      * @throws \Exception
  88.      */
  89.     public function findByPayload(TimesheetService $timesheetServiceTimesheetSerialize  $timesheetSerializeRequest $request ): Response {
  90.         $data $timesheetService
  91.             ->setParams($request->request)
  92.             ->findByPayload();
  93.         $serialized $timesheetSerialize->setEntity($data["dataset"])->serializeMonth($data['m']);
  94.         return $this->json([
  95.             "message" => "Success",
  96.             "severity" => "success",
  97.             "employees" => $serialized
  98.         ], Response::HTTP_OK );
  99.     }
  100.     /**
  101.      * ✅
  102.      * @Route("/unregistered-employees", name="api_v3_timesheet_unregistered_employees", methods={"POST"})
  103.      * @return StreamedResponse
  104.      * @throws \Exception
  105.      */
  106.     public function unregisteredEmployees(TimesheetService $timesheetServiceTimesheetSerialize  $timesheetSerializeRequest $request ): Response {
  107.         $data $timesheetService
  108.             ->setParams($request->request)
  109.             ->unregisteredEmployees();
  110.         $serialized $timesheetSerialize->setEntity($data["dataset"])->serializeMonth($data["m"]);
  111.         return $this->json([
  112.             "message" => "Success",
  113.             "severity" => "success",
  114.             "freeEmployees" => $serialized
  115.         ], Response::HTTP_OK );
  116.     }
  117.     /**
  118.      * ✅
  119.      * @Route("/sync-register-employees", name="api_v3_timesheet_sync_register_employees", methods={"POST"})
  120.      * @return StreamedResponse
  121.      * @throws \Exception
  122.      */
  123.     public function syncRegisterEmployees(TimesheetService $timesheetServiceTimesheetSerialize  $timesheetSerializeRequest $request ): Response {
  124.         $data $timesheetService
  125.             ->setParams($request->request)
  126.             ->syncRegisterEmployees();
  127.         $ids $data["dataset"]->map(fn($item) => $item->getId() );
  128.         $data $timesheetService
  129.             ->setParams($request->request)
  130.             ->findByPayload($ids->toArray());
  131.         $serialized $timesheetSerialize->setEntity($data["dataset"])->serializeMonth($data['m']);
  132.         #dd($serialized);
  133.         return $this->json([
  134.             "message" => "Success",
  135.             "severity" => "success",
  136.             "hotEmployees" => $serialized
  137.         ], Response::HTTP_OK );
  138.     }
  139.     /**
  140.      * ✅
  141.      * @Route("/upsert", name="api_v3_timesheet_upsert", methods={"POST"})
  142.      * @return StreamedResponse
  143.      * @throws \Exception
  144.      */
  145.     public function upsert(TimesheetService $timesheetServiceTimesheetSerialize  $timesheetSerializeRequest $request ): Response {
  146.         $processed $timesheetService
  147.             ->setParams($request->request)
  148.             ->upsert();
  149.         if(!is_null($timesheetService->getException())){
  150.             return $this->json([
  151.                 "message" => $timesheetService->getException()->getMessage(),
  152.                 "severity" => SeverityInterface::ERROR
  153.             ], Response::HTTP_NOT_ACCEPTABLE );
  154.         }
  155.         // Required WA_Id over Timesheet records
  156.         $ids $processed->map(fn(WorkerTimesheet $item) => $item->getWorkerActivity()->getId() );
  157.         $period json_decode($request->request->get('period'), true);
  158.         $domain json_decode($request->request->get('domain'), true);
  159.         $domain = [
  160.             "project" => !is_null($domain["project"]) ? $domain["project"]["id"] : null,
  161.             "order" => !is_null($domain["order"]) ? $domain["order"]["id"] : null,
  162.             "branch" => !is_null($domain["branch"]) ? $domain["branch"]["id"] : null,
  163.         ];
  164.         $newParams array_merge($period$domain);
  165.         $newParams = new InputBag($newParams);
  166.         $data $timesheetService
  167.             ->setParams($newParams)
  168.             ->findByPayload($ids->toArray());
  169.         $serialized $timesheetSerialize->setEntity($data["dataset"])->serializeMonth($data['m']);
  170.         return $this->json([
  171.             "message" => "Success",
  172.             "severity" => "success",
  173.             "hotEmployees" => $serialized
  174.         ], Response::HTTP_OK );
  175.     }
  176.     /**
  177.      * ✅
  178.      * @Route("/movement", name="api_v3_timesheet_movement", methods={"POST"})
  179.      * @return StreamedResponse
  180.      * @throws \Exception
  181.      */
  182.     public function movement(TimesheetService $timesheetServiceTimesheetSerialize  $timesheetSerializeRequest $request ): Response {
  183.         # $timesheetService->setEntity(new WorkerTimesheet())->setParams($request->request)->movement();
  184.         return $this->json([
  185.             "message" => "Success",
  186.             "severity" => "success",
  187.             "hotEmployees" => []
  188.         ], Response::HTTP_OK );
  189.     }
  190.     /**
  191.      * ⚠️ GEÇİCİ — günlük 10 saat aşımı analizi ve taşıma önerisi (SALT OKUMA).
  192.      * Geçmiş kayıtlardaki aşımları bulur, fazlalığın hangi güne taşınabileceğini önerir.
  193.      * Hiçbir veriyi değiştirmez. Karar verildikten sonra bu route + servis + FE dialog silinir.
  194.      *
  195.      * @Route("/hour-cap-analysis", name="api_v3_timesheet_hour_cap_analysis", methods={"POST"})
  196.      * @param HourCapAnalysisService $hourCapAnalysisService
  197.      * @param Request $request
  198.      * @return Response
  199.      */
  200.     public function hourCapAnalysis(HourCapAnalysisService $hourCapAnalysisServiceRequest $request): Response
  201.     {
  202.         $analysis $hourCapAnalysisService
  203.             ->setParams($request->request)
  204.             ->analyze();
  205.         return $this->json([
  206.             "message" => "Success",
  207.             "severity" => "success",
  208.             "analysis" => $analysis
  209.         ], Response::HTTP_OK );
  210.     }
  211. }