src/Service/VehicleRtsActivitiesService.php line 188

  1. <?php
  2. namespace App\Service;
  3. use App\Entity\Activity;
  4. use App\Entity\InventoryParts;
  5. use App\Entity\TransporterDrivers;
  6. use App\Entity\Transporters;
  7. use App\Entity\VatRate;
  8. use App\Entity\VehicleRevokeRequests;
  9. use App\Entity\VehicleRtsActivitiesInventories;
  10. use App\Entity\VehicleRtsActivitiesInventoriesImages;
  11. use App\Entity\VehicleRtsActivitiesInvoices;
  12. use App\Entity\Vehicles;
  13. use App\Entity\VehicleTechnicalSpecs;
  14. use App\Entity\Warehouses;
  15. use App\Form\VehicleRtsActivitiesType;
  16. use Doctrine\ORM\EntityManagerInterface as EntityManager;
  17. use Symfony\Component\{DependencyInjection\ContainerInterface as Container,
  18.     Form\FormFactoryInterface,
  19.     HttpFoundation\File\UploadedFile,
  20.     HttpFoundation\RequestStack,
  21.     Routing\Generator\UrlGeneratorInterface,
  22.     Workflow\Registry};
  23. use Symfony\Bundle\SecurityBundle\Security;
  24. use Symfony\Contracts\Translation\TranslatorInterface;
  25. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  26. /**
  27.  * Class VehicleRtsActivitiesService
  28.  *
  29.  * @Annotation
  30.  * @package App\Service
  31.  */
  32. class VehicleRtsActivitiesService
  33. {
  34.     protected \Symfony\Component\DependencyInjection\ContainerInterface $container;
  35.     protected \Doctrine\ORM\EntityManagerInterface $entityManager;
  36.     protected $entityName;
  37.     protected ?\Symfony\Component\HttpFoundation\Request $request;
  38.     protected \Symfony\Contracts\Translation\TranslatorInterface $translator;
  39.     protected \Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface $params;
  40.     protected \Symfony\Component\Form\FormFactoryInterface $formFactory;
  41.     protected \Symfony\Component\Routing\Generator\UrlGeneratorInterface $router;
  42.     protected \Twig\Environment $templating;
  43.     protected ?\Symfony\Component\Security\Core\User\UserInterface $user;
  44.     protected \Symfony\Component\Workflow\Registry $workflowRegistry;
  45.     /**
  46.      * Vehicles service constructor
  47.      */
  48.     public function __construct(Container $containerEntityManager $EntityManagerTranslatorInterface $translatorParameterBagInterface $params,
  49.                                 FormFactoryInterface $formFactoryUrlGeneratorInterface $router\Twig\Environment $templating,
  50.                                 RequestStack $requestSecurity $securityRegistry $workflowRegistry)
  51.     {
  52.         $this->container $container;
  53.         $this->entityManager $EntityManager;
  54.         $this->translator $translator;
  55.         $this->params $params;
  56.         $this->formFactory $formFactory;
  57.         $this->router $router;
  58.         $this->templating $templating;
  59.         $this->request $request->getCurrentRequest();
  60.         $this->user $security->getUser();
  61.         $this->workflowRegistry $workflowRegistry;
  62.     }
  63.     public function newRtsActivity($requestId=null){
  64.         $request $this->request;
  65.         $locale $request->getLocale();
  66.         $em     $this->entityManager;
  67.         // this will get all url sent data.
  68.         $dataFromURL $request->query->all();
  69.         // get activity type & revokeInventory from url
  70.         $activityType $requestId != null $dataFromURL['form']['revokeActivity'] : $dataFromURL['revokeActivity'];
  71.         $vehicleRtsActivity = new Activity();
  72.         // check if the vehicle will have revokeInventory or not.
  73.         $revokeInventory = isset($dataFromURL['form']['revokeInventory']) ? true null;
  74.         $inventoryParts $em->getRepository(InventoryParts::class)->findAll();
  75.         $vehicleRtsActivity->setActivityInventory(new VehicleRtsActivitiesInventories());
  76.         $vehicleRtsActivity->getActivityInventory()->setParts($inventoryParts);
  77.         //we will use the workflow to check to show returned checkbox or disable it and Repair Checkbox
  78.         $vehicleId =$request->attributes->get('vehicleId');
  79.         $vehicle $em->getRepository(Vehicles::class)->find($vehicleId);
  80.         //we will use the workflow to check
  81.         $workflow $this->workflowRegistry->get($vehicle);
  82.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_RETURN)
  83.             || $workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_UNDER_TRANSPORTATION_AS_READY_FOR_RETURN)) {
  84.             $checkDisable['return'] = [];
  85.         }else{
  86.             $checkDisable['return'] = ['disabled' => 'disabled'];
  87.         }
  88.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_REPAIR)) {
  89.             $checkDisable['repair'] = [];
  90.         }else{
  91.             $checkDisable['repair'] = ['disabled' => 'disabled'];
  92.         }
  93.         $theEffectiveVat$em->getRepository(VatRate::class)->getTheEffectiveVat();
  94.         $form $this->formFactory->create(VehicleRtsActivitiesType::class, $vehicleRtsActivity,
  95.             ['locale' => $locale'activityType' => $activityType'revokeInventory' => $revokeInventory'checkDisable' => $checkDisable'theEffectiveVat' => $theEffectiveVat]);
  96.         $form->handleRequest($request);
  97.         $vehicle->getVehicleTechnicalSpecs();
  98.         $receivingAt $vehicle->getReceivingAt();
  99.         return array(
  100.             'vehicleRtsActivity' => $vehicleRtsActivity,
  101.             'form'               => $form->createView(),
  102.             'locale'             => $locale,
  103.             'receivingAt'  => $receivingAt
  104.         );
  105.     }
  106.     public function addNewRtsActivity($requestId,$vehicleId){
  107.         $request $this->request;
  108.         $vehicleRtsActivity = new Activity();
  109.         $em     $this->entityManager;
  110.         $fileHandler        = new FileHandler();
  111.         $revokeRequest      '' ;
  112.         $locale    $request->getLocale();
  113.         $loginUser $this->user;
  114.         $theEffectiveVat$em->getRepository(VatRate::class)->getTheEffectiveVat();
  115.         // this will get all url sent data.
  116.         $dataFromURL $request->query->all();
  117.         ############################## Note ###############################
  118.         # In vehicle rts activities we save either request id or vehicle id #
  119.         ###################################################################
  120.         // get activity type & revokeInventory from url. if request id exist we'll save it without vehicle_id
  121.         if ($requestId != null) {
  122.             $revokeRequest $em->getRepository(VehicleRevokeRequests::class)->find($requestId); //get revoke request from the id on the url
  123.             $vehicleRtsActivity->setRevokeRequest($revokeRequest);
  124.             $activityType $dataFromURL['form']['revokeActivity']; // get activity type from the url data
  125.         } else {
  126.             $activityType $dataFromURL['revokeActivity'];
  127.         }
  128.         // set activity type equal the type coming from the URL.
  129.         $vehicleRtsActivity->setActivityType($activityType);
  130.         $vehicleRepository $em->getRepository(Vehicles::class);
  131.         $vehicle $vehicleRepository->find($vehicleId);
  132.         if ($requestId == null) { // if request_id not exist we'll save vehicle_id
  133.             $vehicleRtsActivity->setVehicle($vehicle);
  134.         }
  135.         // check if the vehicle will have revokeInventory or not.
  136.         $revokeInventory = isset($dataFromURL['form']['revokeInventory']) ? true null;
  137.         $inventoryParts $em->getRepository(InventoryParts::class)->findAll();
  138.         $vehicleRtsActivity->setActivityInventory(new VehicleRtsActivitiesInventories());
  139.         $vehicleRtsActivity->getActivityInventory()->setParts($inventoryParts);
  140.         //we will use the workflow to check to show returned checkbox or disable it and Repair Checkbox
  141.         $workflow $this->workflowRegistry->get($vehicle);
  142.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_RETURN)
  143.             || $workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_UNDER_TRANSPORTATION_AS_READY_FOR_RETURN)) {
  144.             $checkDisable['return'] = [];
  145.         }else{
  146.             $checkDisable['return'] = ['disabled' => 'disabled'];
  147.         }
  148.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_REPAIR)) {
  149.             $checkDisable['repair'] = [];
  150.         }else{
  151.             $checkDisable['repair'] = ['disabled' => 'disabled'];
  152.         }
  153.         $form $this->formFactory->create(VehicleRtsActivitiesType::class, $vehicleRtsActivity,
  154.             ['locale' => $locale'activityType' => $activityType'revokeInventory' => $revokeInventory'checkDisable' => $checkDisable'theEffectiveVat' => $theEffectiveVat]);
  155.         $form->handleRequest($request);
  156.         if ($form->isValid()) {
  157.             $session $request->getSession();
  158.             // if cancel the RTS before reset the revoke cancellation reason column if RTS
  159.             if ($requestId != null  && $revokeRequest->getRevokeCancellationReason()  ) {
  160.                 $revokeRequest->setRevokeCancellationReason(null);
  161.                 $em->persist($revokeRequest);
  162.                 $em->flush($revokeRequest);
  163.             }
  164.             if ($vehicleRtsActivity->getActivityDestination()) {
  165.                 $inventoryDeliveryPath $vehicleRtsActivity->getActivityDestination()->getInventoryDeliveryPath();
  166.                 if ($inventoryDeliveryPath) {
  167.                     // Generate a unique name for the file before saving it
  168.                     $inventoryDeliveryPathName md5(uniqid()). '.'$inventoryDeliveryPath->guessClientExtension();
  169.                     $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPath($inventoryDeliveryPathName);
  170.                 }
  171.             }
  172.             // put all post data to $formPostData var.
  173.             $formPostData $request->request->all();
  174.             // check if destination posted with the form. then if user make vehicle as returned set vehicle status returned.
  175.             if (isset($formPostData['appbundle_vehiclertsactivities']['activityDestination'])) {
  176.                 $vehicleRtsActivityDestination $formPostData['appbundle_vehiclertsactivities']['activityDestination'];
  177.                 if (isset($vehicleRtsActivityDestination['isReturned']) && $vehicleRtsActivityDestination['isReturned'] == 1) {
  178.                     $oldOfferability $vehicle->getOfferabilityForSale();
  179.                     $vehicleRtsActivity->getActivityDestination()->setIsReturned(1);
  180.                 }elseif (isset($vehicleRtsActivityDestination['isRepair']) && $vehicleRtsActivityDestination['isRepair'] == 1) {
  181.                     $vehicleRtsActivity->getActivityDestination()->setIsRepair(1);
  182.                 }
  183.                 $isRepair = (isset($vehicleRtsActivityDestination['isRepair']))? $vehicleRtsActivityDestination['isRepair'] :null;
  184.                 if (isset($vehicleRtsActivityDestination['exitDate']) && !empty($vehicleRtsActivityDestination['exitDate'])) {
  185.                     $vehicle->setExitDate(new \DateTime($vehicleRtsActivityDestination['exitDate']));
  186.                 }
  187.             }
  188.             $em->flush($vehicle);
  189.             // if activity has transport we should add an invoice.
  190.             if ($vehicleRtsActivity->getActivityTransport() != null && $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()->getSupplierInvoice()->getTotal()) {
  191.                 $activityTransportInvoice $vehicleRtsActivity->getActivityTransport()->getRtsInvoice();
  192.                 $supplierInvoice          $activityTransportInvoice->getSupplierInvoice();
  193.                 $transporterID            = (int)$formPostData['appbundle_vehiclertsactivities']['activityTransport']['transporter'];
  194.                 $transporter              $em->getRepository(Transporters::class)->find($transporterID);
  195.                 $supplierInvoice->setIssuer($transporter->getCompany());
  196.                 $supplierInvoice->setCreatedBy($loginUser);
  197.                 // catch the file that uploaded through the form.
  198.                 $transportFile $supplierInvoice->getImagePath();
  199.                 // if an image is uploaded then generate a name for it.
  200.                 if ($transportFile) {
  201.                     // Generate a unique name for the file before saving it.
  202.                     $fileName md5(uniqid()).'.'$transportFile->guessClientExtension();
  203.                     // Set the 'ImagePath' property to store the image filename instead of the binary file.
  204.                     $supplierInvoice->setImagePath($fileName);
  205.                 }
  206.                 //if 'value is VAT inclusive' checkbox was checked then calculate VAT
  207.                 if (array_key_exists('check_vat_amount',$formPostData['appbundle_vehiclertsactivities']['activityTransport']['rtsInvoice']['supplierInvoice'])
  208.                     && $theEffectiveVat) {
  209.                     $vatAmount VehicleHelper::calcVatFromTotal($supplierInvoice->getTotal(), $theEffectiveVat->getVatRatio());
  210.                     $supplierInvoice->setVatRate($theEffectiveVat);
  211.                 } elseif (! $theEffectiveVat) {
  212.                     //there is no effective VAT rate at all
  213.                     $vatAmountnull;
  214.                 } else{
  215.                     //there is an Effective VAT rate but the user decided that the invoice is VAT ineligible
  216.                     $supplierInvoice->setVatRate($theEffectiveVat);
  217.                     $vatAmount0;
  218.                 }
  219.                 $value =  $supplierInvoice->getTotal() - (float)$vatAmount ;
  220.                 $supplierInvoice->setValue($value);
  221.                 $supplierInvoice->setVatAmount($vatAmount);
  222.                 $em->persist($supplierInvoice);
  223.                 $em->flush($supplierInvoice);
  224.                 $activityTransportInvoice->setRtsInvoiceId($supplierInvoice->getInvoiceId());
  225.                 $activityTransportInvoice->setType(VehicleRtsActivitiesInvoices::INVOICE_TYPES['Transport']);
  226.                 //set the invoice type as Transport
  227.                 $activityTransportInvoice->setActivity($vehicleRtsActivity);
  228.                 // time for saving the uploaded image to disk.
  229.                 if ($transportFile) { // save transport image.
  230.                     $fileHandler  = new FileHandler();
  231.                     $fileRealPath $this->params->get('web_dir_path') . $this->params->get('vehicle_uploaded_files') . '/' $vehicle->getVehicleId(). '/';
  232.                     $fileHandler->save($transportFile$fileRealPath$fileName);
  233.                 }
  234.             } elseif (isset($formPostData['appbundle_vehiclertsactivities']['activityTransport'])) {
  235.                 $vehicleRtsActivity->getActivityTransport()->setRtsInvoice(null);
  236.             }
  237.             if ($revokeInventory) {
  238.                 $activityInventory $vehicleRtsActivity->getActivityInventory();
  239.                 if ($activityInventory) {
  240.                     $activityInventoryImages $activityInventory->getInventoryImage();
  241.                 } else {
  242.                     $activityInventory = new VehicleRtsActivitiesInventories();
  243.                 }
  244.             }
  245.             // broke the relation between activity and inventory.
  246.             $vehicleRtsActivity->setActivityInventory(null);
  247.             $vehicleRtsActivity->setCreatedBy($loginUser);
  248.             $em->persist($vehicleRtsActivity);
  249.             $em->flush($vehicleRtsActivity);
  250.             // time for saving the uploaded image to disk.
  251.             if (isset($inventoryDeliveryPath) && $inventoryDeliveryPath != null) {
  252.                 $inventoryDeliveryPathRealPath $this->params->get('web_dir_path') . $this->params->get('vehicle_uploaded_files') . '/' $vehicleId '/';
  253.                 $fileHandler->save($inventoryDeliveryPath$inventoryDeliveryPathRealPath$inventoryDeliveryPathName );
  254.             }
  255.             if ($revokeInventory) {
  256.                 $activityInventory->setInventoryActivityId($vehicleRtsActivity->getActivityId());
  257.                 $activityInventory->setInventoryActivity($vehicleRtsActivity);
  258.                 /*** Saving inventoryMissingPart if they were unchecked in the form ***/
  259.                 $inventoryPartsSent $activityInventory->getParts();
  260.                 $activityInventory->setParts(null);
  261.                 foreach($inventoryPartsSent as $inventoryPart){
  262.                     if(!$inventoryPart->getIsNotMessing()) {
  263.                         $activityInventory->addPart($inventoryPart);
  264.                     }
  265.                 }
  266.                 $em->persist($activityInventory);
  267.                 $em->flush();
  268.                 $this->addInventoryImages($request$vehicleId$em$vehicleRtsActivity);
  269.             }
  270.             $em->flush();
  271.             $session->getFlashBag()->add('success',
  272.                 $this->translator->trans('RTS activity added successfully', array(), 'vehicles') );
  273.             return array('result'=>'success');
  274.         }else{
  275.             $vehicleTechnicalSpec =$vehicle->getVehicleTechnicalSpecs();
  276.             $receivingAt $vehicle->getReceivingAt();
  277.             return array('result'=>'failed','param'=>array(
  278.                             'vehicleRtsActivity' => $vehicleRtsActivity,
  279.                             'form'               => $form->createView(),
  280.                             'locale'             => $locale,
  281.                             'receivingAt'        => $receivingAt
  282.                         ));
  283.         }
  284.     }
  285.     public function editRtsActivity($vehicleRtsActivity,$vehicleId){
  286.         $request $this->request;
  287.         $em     $this->entityManager;
  288.         $locale      $request->getLocale();
  289.         $fileHandler = new FileHandler();
  290.         $deleteForm $this->createDeleteForm($vehicleRtsActivity);
  291.         $activityType $vehicleRtsActivity->getActivityType();
  292.         $em      $this->entityManager;
  293.         $vehicle $em->getRepository(Vehicles::class)->find($vehicleId);
  294.         $theEffectiveVat$em->getRepository(VatRate::class)->getTheEffectiveVat();
  295.         $imageDirWebPath  $this->params->get('vehicle_uploaded_files') . '/' $vehicleId '/';
  296.         $imageDirRealPath $this->params->get('web_dir_path') . $imageDirWebPath;
  297.         // get the old inventory images to display in page
  298.         $imagesDB =  $em->getRepository(VehicleRtsActivitiesInventoriesImages::class)->findBy(['inventory'=>$vehicleRtsActivity]);
  299.         $vehicleExitDate $vehicle->getExitDate();
  300.         $vehicleExitDate $vehicle->getExitDate();
  301.         if ($vehicleRtsActivity->getActivityDestination()) {
  302.             $isReturnedInActivity          $vehicleRtsActivity->getActivityDestination()->getIsReturned();
  303.             $isRepairInActivity          $vehicleRtsActivity->getActivityDestination()->getIsIsRepair();
  304.             $inventoryDeliveryPathTextName $vehicleRtsActivity->getActivityDestination()->getInventoryDeliveryPath();
  305.             $inventoryDeliveryPathBinaryFile $fileHandler->getBinaryFile($imageDirRealPath$inventoryDeliveryPathTextName);
  306.             if ($inventoryDeliveryPathBinaryFile && $imageDirWebPath) {
  307.                 $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPathWebPath($imageDirWebPath $inventoryDeliveryPathTextName);
  308.                 $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPath($inventoryDeliveryPathBinaryFile);
  309.                 $inventoryDeliveryImage $vehicleRtsActivity->getActivityDestination()->getInventoryDeliveryPathWebPath();
  310.             } else {
  311.                 $inventoryDeliveryImage null;
  312.             }
  313.         } else {
  314.             $isReturnedInActivity   false;
  315.             $isRepairInActivity     false;
  316.             $inventoryDeliveryImage null;
  317.         }
  318.         if ($vehicleRtsActivity->getActivityTransport() && $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()) {
  319.             $transportInvoice $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()->getSupplierInvoice();
  320.         } else {
  321.             $transportInvoice null;
  322.         }
  323.         $revokeInventory $vehicleRtsActivity->getActivityInventory() ? true null;
  324.         //if there is an associated document to the supplier invoice then do some processing to its imagePath property
  325.         if ($transportInvoice) {
  326.             //if the document has a physical valid image to be shown then set its web path
  327.             $imageBinaryFile $fileHandler->getBinaryFile($imageDirRealPath$transportInvoice->getImagePath());
  328.             //if image file physically exists and the web path directory provided then set its web path
  329.             if($imageBinaryFile && $imageDirWebPath){
  330.                 $transportInvoice->setImageWebPath($imageDirWebPath$transportInvoice->getImagePath()); //the form will use this property to show the image
  331.             }
  332.             $transportInvoice->setImagePath($imageBinaryFile);
  333.             $transportInvoiceImage $transportInvoice->getImageWebPath();
  334.         } else {
  335.             $transportInvoiceImage null;
  336.         }
  337.         // get all parts then compare with saved missing parts
  338.         if ($vehicleRtsActivity->getActivityInventory()) {
  339.             $allInventoryParts $em->getRepository(InventoryParts::class)->findAll();
  340.             $inventoryMissingParts $vehicleRtsActivity->getActivityInventory()->getParts();
  341.             $missingParts = [];
  342.             foreach ($inventoryMissingParts as $inventoryMissingPart) {
  343.                 $missingParts[$inventoryMissingPart->getPartId()]= $inventoryMissingPart;
  344.             }
  345.             foreach($allInventoryParts as $inventoryPart) {
  346.                 if (isset($missingParts[$inventoryPart->getPartId()])) {
  347.                     $inventoryMissingPart $missingParts[$inventoryPart->getPartId()];
  348.                     $inventoryPart->setIsNotMessing(false);
  349.                 }else{
  350.                     $inventoryPart->setIsNotMessing(true);
  351.                 }
  352.             }
  353.         $vehicleRtsActivity->getActivityInventory()->setParts($allInventoryParts);
  354.         }
  355.         //if there is a transport invoice and it has a VAT amount then 'value is VAT inclusive' checkbox has to be checked in the form
  356.         $shallVatInclusiveChecked false;
  357.         $activityTransport$vehicleRtsActivity->getActivityTransport();
  358.         if($activityTransport && $activityTransport->getRtsInvoice()
  359.             && $activityTransport->getRtsInvoice()->getSupplierInvoice()->getVatAmount()){
  360.             $shallVatInclusiveChecked =true ;
  361.         }
  362.         $oldWarehouseId null;
  363.         if($vehicleRtsActivity && $vehicleRtsActivity->getActivityStorage() && $vehicleRtsActivity->getActivityStorage()->getWarehouse() ){
  364.             $oldWarehouseId $vehicleRtsActivity->getActivityStorage()->getWarehouse()->getWarehouseId();
  365.         }
  366.         //we will use the workflow to check to show returned checkbox or disable it and Repair Checkbox
  367.         $workflow $this->workflowRegistry->get($vehicle);
  368.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_RETURN)
  369.             || $workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_UNDER_TRANSPORTATION_AS_READY_FOR_RETURN)) {
  370.             $checkDisable['return'] = [];
  371.         }else{
  372.             $checkDisable['return'] = ['disabled' => 'disabled'];
  373.         }
  374.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_REPAIR)) {
  375.             $checkDisable['repair'] = [];
  376.         }else{
  377.             $checkDisable['repair'] = ['disabled' => 'disabled'];
  378.         }
  379.         $editForm $this->formFactory->create(VehicleRtsActivitiesType::class, $vehicleRtsActivity, [
  380.             'locale'               => $locale,
  381.             'activityType'         => $activityType,
  382.             'revokeInventory'      => $revokeInventory,
  383.             'vehicleExitDate'      => $vehicleExitDate,
  384.             'isReturnedInActivity' => $isReturnedInActivity,
  385.             'isRepairInActivity'   => $isRepairInActivity,
  386.             'oldWarehouseId'       => $oldWarehouseId,
  387.             'method'               => 'PATCH',
  388.             'theEffectiveVat' => $theEffectiveVat,
  389.             'checkDisable' => $checkDisable
  390.         ]);
  391.         // get activity invoices that aren't estimation or transport.
  392.         $vehicleRtsActivity->getActivityInvoice()->filter(
  393.             function ($entry) use ($vehicleId$fileHandler$imageDirWebPath$imageDirRealPath) {
  394.                 if ($entry->getType() == 'Estimation' || $entry->getType() == 'Transport') {
  395.                     $entry->getActivity()->removeActivityInvoice($entry);
  396.                 } else {
  397.                     //if the document has a physical valid image to be shown then set its web path
  398.                     $imageBinaryFile $fileHandler->getBinaryFile($imageDirRealPath$entry->getSupplierInvoice()->getImagePath());
  399.                     //if image file physically exists and the web path directory provided then set its web path
  400.                     if ($imageBinaryFile && $imageDirWebPath) {
  401.                         $entry->getSupplierInvoice()->setImageWebPath($imageDirWebPath$entry->getSupplierInvoice()->getImagePath()); //the form will use this property to show the image
  402.                     }
  403.                     $entry->getSupplierInvoice()->setImagePath($imageBinaryFile);
  404.                     $entry->getSupplierInvoice()->setImagePath(null);
  405.                 }
  406.             }
  407.         );
  408.         $activityInvoices $vehicleRtsActivity->getActivityInvoice();
  409.         $vehicle->getVehicleTechnicalSpecs();
  410.         $receivingAt $vehicle->getReceivingAt();
  411.         return array(
  412.             'vehicleRtsActivity'     => $vehicleRtsActivity,
  413.             'edit_form'              => $editForm->createView(),
  414.             'delete_form'            => $deleteForm->createView(),
  415.             'locale'                 => $locale,
  416.             'activityInvoices'       => $activityInvoices,
  417.             'filesRoot'              => $this->params->get('vehicle_uploaded_files') . '/' $vehicleId,
  418.             'inventoryDeliveryImage' => $inventoryDeliveryImage,
  419.             'transportInvoiceImage'  => $transportInvoiceImage,
  420.             'check_vat_amount'       => $shallVatInclusiveChecked,
  421.             'imagesDB'               => $imagesDB,
  422.             'vehicleId'              => $vehicleId,
  423.             'receivingAt'  => $receivingAt
  424.         );
  425.     }
  426.     public function updateRtsActivity($vehicleRtsActivity,$vehicleId){
  427.         $request =$this->request;
  428.         $locale $request->getLocale();
  429.         $em     $this->entityManager;
  430.         $activityType $vehicleRtsActivity->getActivityType();
  431.         $vehicle      $em->getRepository(Vehicles::class)->find($vehicleId);
  432.         $inventoryDeliveryImage null;
  433.         $activityTransport$vehicleRtsActivity->getActivityTransport(); //catch the transport data from Database before form binding for further use
  434.         // get the old inventory images to display in page
  435.         $imagesDB =  $em->getRepository(VehicleRtsActivitiesInventoriesImages::class)->findBy(['inventory'=>$vehicleRtsActivity]);
  436.         $fileHandler      = new FileHandler();
  437.         $imageDirWebPath  $this->params->get('vehicle_uploaded_files') . '/' $vehicle->getVehicleId() . '/';
  438.         $imageDirRealPath $this->params->get('web_dir_path') . $imageDirWebPath;
  439.         // put all post data to $formPostData var.
  440.         $formPostData $request->request->all();
  441.         $clearImageDestination =  null ;
  442.         if (isset($formPostData['appbundle_vehiclertsactivities']['activityDestination'])) {
  443.             $clearImageDestination $formPostData["appbundle_vehiclertsactivities"]['activityDestination']['clearImage'];
  444.         }
  445.         $clearImageSupplier null ;
  446.         if (isset($formPostData["appbundle_vehiclertsactivities"]['activityTransport']) && isset($formPostData["appbundle_vehiclertsactivities"]['activityTransport']['rtsInvoice']) && isset($formPostData["appbundle_vehiclertsactivities"]['activityTransport']['rtsInvoice']['supplierInvoice'])) {
  447.             $clearImageSupplier =  $formPostData["appbundle_vehiclertsactivities"]['activityTransport']['rtsInvoice']['supplierInvoice']['clearImage'];
  448.         }
  449.         // check if destination posted with the form.
  450.         if (isset($formPostData['appbundle_vehiclertsactivities']['activityDestination'])) {
  451.             $inventoryDeliveryPathTextName $vehicleRtsActivity->getActivityDestination()->getInventoryDeliveryPath();
  452.             $inventoryDeliveryPathBinaryFile $fileHandler->getBinaryFile($imageDirRealPath$inventoryDeliveryPathTextName);
  453.             if ($inventoryDeliveryPathBinaryFile && $imageDirWebPath) {
  454.                 $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPathWebPath($imageDirWebPath $inventoryDeliveryPathTextName);
  455.                 $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPath($inventoryDeliveryPathBinaryFile);
  456.                 $inventoryDeliveryImage $vehicleRtsActivity->getActivityDestination()->getInventoryDeliveryPathWebPath();
  457.             }
  458.         }
  459.         // get transport invoice for the activity.
  460.         if ($vehicleRtsActivity->getActivityTransport() && $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()) {
  461.             $transportInvoice $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()->getSupplierInvoice();
  462.         } else {
  463.             $transportInvoice null;
  464.         }
  465.         $revokeInventory $vehicleRtsActivity->getActivityInventory() ? true null;
  466.         //if there is an associated document to the activity transport then do some processing to its imagePath property
  467.         $transportImageWebPath null;
  468.         if ($transportInvoice) {
  469.             //if the document has a phisical valid image to be shown then set its web path
  470.             //keep original image path derived from DB along with docId for forther use
  471.             $transportImageNameText   $transportInvoice->getImagePath();
  472.             $imageBinaryFile          $fileHandler->getBinaryFile($imageDirRealPath$transportInvoice->getImagePath());
  473.             //if image file phisically exists and the web path directory provided then set its web path
  474.             if($imageBinaryFile && $imageDirWebPath){
  475.                 $transportInvoice->setImageWebPath($imageDirWebPath$transportInvoice->getImagePath()); //the form will use this property to show the image
  476.             }
  477.             // reset ImagePath property value to avoid string to File conversion error.
  478.             $transportInvoice->setImagePath(null);
  479.             $transportImageWebPath $transportInvoice->getImageWebPath(); //get the image that will be shown
  480.         }
  481.         // get inventory save images and put it in an array to set image path again if no changes made in the form.
  482.         $inventoryDbImages = array();
  483.         if ($vehicleRtsActivity->getActivityInventory()) {
  484.             foreach ($vehicleRtsActivity->getActivityInventory()->getInventoryImage() as $image) {
  485.                 $inventoryDbImages[] = [
  486.                     'id'   => $image->getImageId(),
  487.                     'path' => $image->getImagePath()
  488.                 ];
  489.             }
  490.         }
  491.         // get all parts then compare with saved missing parts
  492.         if ($vehicleRtsActivity->getActivityInventory()) {
  493.             $allInventoryParts $em->getRepository(InventoryParts::class)->findAll();
  494.             $inventoryMissingParts $vehicleRtsActivity->getActivityInventory()->getParts();
  495.             foreach($allInventoryParts as  $inventoryPart) {
  496.                 if ( !array_key_exists('parts',$formPostData['appbundle_vehiclertsactivities']['activityInventory']) || !array_key_exists($inventoryPart->getPartId() -1  $formPostData['appbundle_vehiclertsactivities']['activityInventory']['parts']) ) {
  497.                     $inventoryPart->setIsNotMessing(false);
  498.                 }
  499.             }
  500.             $vehicleRtsActivity->getActivityInventory()->setParts($allInventoryParts);
  501.         }
  502.         $theEffectiveVat$em->getRepository(VatRate::class)->getTheEffectiveVat();
  503.         //we will use the workflow to check to show returned checkbox or disable it and Repair Checkbox
  504.         $workflow $this->workflowRegistry->get($vehicle);
  505.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_RETURN)
  506.             || $workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_UNDER_TRANSPORTATION_AS_READY_FOR_RETURN)) {
  507.             $checkDisable['return'] = [];
  508.         }else{
  509.             $checkDisable['return'] = ['disabled' => 'disabled'];
  510.         }
  511.         if($workflow->can($vehicle,Vehicles::VEHICLE_TRANSITION_MARK_RECEIVED_AS_READY_FOR_REPAIR)) {
  512.             $checkDisable['repair'] = [];
  513.         }else{
  514.             $checkDisable['repair'] = ['disabled' => 'disabled'];
  515.         }
  516.         $formParams= ['locale' => $locale'activityType' => $activityType'revokeInventory' => $revokeInventory'checkDisable' => $checkDisable'theEffectiveVat' => $theEffectiveVat'method' => 'PATCH'];
  517.         $editForm $this->formFactory->create(VehicleRtsActivitiesType::class, $vehicleRtsActivity$formParams);
  518.         $editForm->handleRequest($request);
  519.         if ($editForm->isValid()) {
  520.             $vehicleRtsActivity $this->entityManager->merge($vehicleRtsActivity);
  521.             if ($vehicleRtsActivity->getActivityDestination()) {
  522.                 $newInventoryDeliveryPath $vehicleRtsActivity->getActivityDestination()->getInventoryDeliveryPath();
  523.                 if ($newInventoryDeliveryPath) {
  524.                     $newInventoryDeliveryPathName md5(uniqid()) . '.' $newInventoryDeliveryPath->guessClientExtension();
  525.                     $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPath($newInventoryDeliveryPathName);
  526.                     $fileHandler->save($newInventoryDeliveryPath$imageDirRealPath$newInventoryDeliveryPathName);
  527.                 } elseif ($clearImageDestination == "1") {
  528.                     $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPath(null);
  529.                 } else{
  530.                     $vehicleRtsActivity->getActivityDestination()->setInventoryDeliveryPath($inventoryDeliveryPathTextName);
  531.                 }
  532.             }
  533.             $supplierInvoicenull;
  534.             // to fix issue TP-107 : In edit RTS activity page, if adding the value of transport fees or editing warehouse then save, the page crashes.
  535.             if ($vehicleRtsActivity->getActivityTransport() && $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()->getSupplierInvoice()->getTotal() != null) {
  536.                 $vehicleRtsActivity->setActivityInvoice(null);
  537.                 $activityTransportInvoice $vehicleRtsActivity->getActivityTransport()->getRtsInvoice();
  538.                 $supplierInvoice          $activityTransportInvoice->getSupplierInvoice();
  539.                 //if the invoice has a VAT rate then we need to recalculate VAT amount without touching its VAT rate
  540.                 if ($supplierInvoice && $supplierInvoice->getVatRate()) {
  541.                     //if 'value is VAT inclusive' checkbox was checked then calculate VAT
  542.                     if (array_key_exists('check_vat_amount'$formPostData['appbundle_vehiclertsactivities']['activityTransport']['rtsInvoice']['supplierInvoice'])) {
  543.                         $vatAmount VehicleHelper::calcVatFromTotal($supplierInvoice->getTotal(), $supplierInvoice->getVatRate()->getVatRatio());
  544.                     } else {
  545.                         //there is an Effective VAT rate but the user decided that the invoice is VAT ineligible
  546.                         $vatAmount 0;
  547.                     }
  548.                     $originalValue $supplierInvoice->getTotal() - (float)$vatAmount;
  549.                     $supplierInvoice->setValue($originalValue);
  550.                     $supplierInvoice->setVatAmount($vatAmount);
  551.                     //if no invoice yet and a value provided
  552.                 } elseif (!$supplierInvoice->getInvoiceId() && $supplierInvoice->getTotal()) {
  553.                     $effectiveVat$em->getRepository(\App\Entity\VatRate::class)->getTheEffectiveVat();
  554.                     if (array_key_exists('check_vat_amount'$formPostData['appbundle_vehiclertsactivities']['activityTransport']['rtsInvoice']['supplierInvoice'])
  555.                         && $effectiveVat) {
  556.                         // calculate VAT according to the rate of the Effective VAT
  557.                         $vatAmountVehicleHelper::calcVatFromTotal($supplierInvoice->getTotal(), $effectiveVat->getVatRatio());
  558.                         $supplierInvoice->setVatRate($effectiveVat);
  559.                     } elseif (! $effectiveVat) {
  560.                         //there is no effective VAT rate at all
  561.                         $vatAmountnull;
  562.                     } else{
  563.                         //there is an Effective VAT rate but the user decided that the invoice is VAT ineligible
  564.                         $supplierInvoice->setVatRate($effectiveVat);
  565.                         $vatAmount0;
  566.                     }
  567.                     $originalValue =  $supplierInvoice->getTotal() - (float)$vatAmount;
  568.                     $supplierInvoice->setValue($originalValue);
  569.                     $supplierInvoice->setVatAmount($vatAmount);
  570.                     //if an already invoice but has no VAT rate then just set value = total
  571.                 } elseif ($supplierInvoice->getInvoiceId() && !$supplierInvoice->getVatRate()) {
  572.                     $supplierInvoice->setValue$supplierInvoice->getTotal() );
  573.                 }
  574.                 if ($activityTransportInvoice->getSupplierInvoice()->getInvoiceId()) {
  575.                     $activityTransportInvoice $this->entityManager->merge($activityTransportInvoice);  //it's important to use result of function, not the same element
  576.                     $activityTransportInvoice->addActivityTransport($vehicleRtsActivity->getActivityTransport());
  577.                 } else {
  578.                     $activityTransportInvoice $vehicleRtsActivity->getActivityTransport()->getRtsInvoice();
  579.                     $transporterID            = (int)$formPostData['appbundle_vehiclertsactivities']['activityTransport']['transporter'];
  580.                     $transporter              $em->getRepository(Transporters::class)->find($transporterID);
  581.                     $supplierInvoice->setIssuer($transporter->getCompany());
  582.                     // catch the file that uploaded through the form.
  583.                     $transportFile $supplierInvoice->getImagePath();
  584.                     // if an image is uploaded then generate a name for it.
  585.                     if ($transportFile) {
  586.                         // Generate a unique name for the file before saving it.
  587.                         $fileName md5(uniqid()).'.'$transportFile->guessClientExtension();
  588.                         // Set the 'ImagePath' property to store the image filename instead of the binary file.
  589.                         $supplierInvoice->setImagePath($fileName);
  590.                     }
  591.                     $em->persist($supplierInvoice);
  592.                     $em->flush($supplierInvoice);
  593.                     $activityTransportInvoice->setRtsInvoiceId($supplierInvoice->getInvoiceId());
  594.                     $activityTransportInvoice->setType(VehicleRtsActivitiesInvoices::INVOICE_TYPES['Transport']); //set the invoice type as Transport
  595.                     $activityTransportInvoice->setActivity($vehicleRtsActivity);
  596.                     // time for saving the uploaded image to disk.
  597.                     if ($transportFile) { // save transport image.
  598.                         $fileHandler  = new FileHandler();
  599.                         $fileRealPath $this->params->get('web_dir_path') . $this->params->get('vehicle_uploaded_files') . '/' $vehicle->getVehicleId(). '/';
  600.                         $fileHandler->save($transportFile$fileRealPath$fileName);
  601.                     }
  602.                 }
  603.                 if ($transportInvoice) {
  604.                     if ($transportInvoice->getImagePath()) {
  605.                         //Upload the image then set the ImagePath property to store the image filename not the binary file
  606.                         $transportInvoice->setImagePath(
  607.                             $fileHandler->save($transportInvoice->getImagePath(), $imageDirRealPath)
  608.                         );
  609.                     } elseif ($clearImageSupplier == "1") {
  610.                         $transportInvoice->setImagePath(null);
  611.                     } else{
  612.                         //No uploaded image, so just put the original image path back in ImagePath property, if there is one there
  613.                         $transportInvoice->setImagePath($transportImageNameText);
  614.                     }
  615.                 }
  616.             } else {
  617.                 if ($vehicleRtsActivity->getActivityTransport()) {
  618.                     $vehicleRtsActivity->getActivityTransport()->setRtsInvoice(null);
  619.                 }
  620.                 $vehicleRtsActivity->setActivityInvoice(null);
  621.             }
  622.             $em->flush($vehicle);
  623.             /*** Upload new added inventoryImages ***/
  624.             if ($vehicleRtsActivity->getActivityInventory()) {
  625.                 $inventoryImages   = array();
  626.                 $activityInventory $vehicleRtsActivity->getActivityInventory();
  627.                 $this->addInventoryImages($request,$vehicleId,$em,$vehicleRtsActivity);
  628.                 /*** Saving inventoryMissingPart if they were unchecked in the form ***/
  629.                 $inventoryPartsSent $activityInventory->getParts();
  630.                 $activityInventory->setParts(null);
  631.                 foreach ($inventoryPartsSent as $inventoryPart) {
  632.                     if (!$inventoryPart->getIsNotMessing()) {
  633.                         $activityInventory->addPart($inventoryPart);
  634.                     }
  635.                 }
  636.             }
  637.             $em->flush();
  638.             $session $request->getSession();
  639.             $session->getFlashBag()->add('success',
  640.                 $this->translator->trans('RTS activity updated successfully', array(), 'vehicles') );
  641.             return array('result'=>'updated','param'=>array('vehicleId' => $vehicleId));
  642.         }else{
  643.             $activityInvoices $vehicleRtsActivity->getActivityInvoice();
  644.             $deleteForm $this->createDeleteForm($vehicleRtsActivity);
  645.             //get $transportInvoiceImage
  646.             $imageDirWebPath  $this->params->get('vehicle_uploaded_files') . '/' $vehicle->getVehicleId() . '/';
  647.             $imageDirRealPath $this->params->get('web_dir_path') . $imageDirWebPath;
  648.             if ($vehicleRtsActivity->getActivityTransport() && $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()) {
  649.                 $transportInvoice $vehicleRtsActivity->getActivityTransport()->getRtsInvoice()->getSupplierInvoice();
  650.             } else {
  651.                 $transportInvoice null;
  652.             }
  653.             $revokeInventory $vehicleRtsActivity->getActivityInventory() ? true null;
  654.             //if there is an associated document to the supplier invoice then do some processing to its imagePath property
  655.             if ($transportInvoice) {
  656.                 //if the document has a physical valid image to be shown then set its web path
  657.                 $imageBinaryFile $fileHandler->getBinaryFile($imageDirRealPath$transportInvoice->getImagePath());
  658.                 //if image file physically exists and the web path directory provided then set its web path
  659.                 if($imageBinaryFile && $imageDirWebPath){
  660.                     $transportInvoice->setImageWebPath($imageDirWebPath$transportInvoice->getImagePath()); //the form will use this property to show the image
  661.                 }
  662.                 $transportInvoice->setImagePath($imageBinaryFile);
  663.                 $transportInvoiceImage $transportInvoice->getImageWebPath();
  664.             } else {
  665.                 $transportInvoiceImage null;
  666.             }
  667.             //if there was a transport invoice and it has a VAT amount then 'value is VAT inclusive' checkbox has to be checked in the form
  668.             $shallVatInclusiveChecked false;
  669.             if($activityTransport && $activityTransport->getRtsInvoice()
  670.                 && $activityTransport->getRtsInvoice()->getSupplierInvoice()->getVatAmount()){
  671.                 $shallVatInclusiveChecked =true;
  672.             }
  673.             $vehicleTechnicalSpec =$vehicle->getVehicleTechnicalSpecs();
  674.             $receivingAt $vehicle->getReceivingAt();
  675.             return array('result'=>'failed','param'=>  array(
  676.                 'vehicleRtsActivity'     => $vehicleRtsActivity,
  677.                 'edit_form'              => $editForm->createView(),
  678.                 'delete_form'            => $deleteForm->createView(),
  679.                 'locale'                 => $locale,
  680.                 'activityInvoices'       => $activityInvoices,
  681.                 'filesRoot'              => $this->params->get('vehicle_uploaded_files') . '/' $vehicleId,
  682.                 'inventoryDeliveryImage' => $inventoryDeliveryImage,
  683.                 'transportInvoiceImage'  => $transportInvoiceImage,
  684.                 'check_vat_amount'       => $shallVatInclusiveChecked,
  685.                 'imagesDB'               => $imagesDB,
  686.                 'vehicleId'              => $vehicleId,
  687.                 'receivingAt'           => $receivingAt
  688.                 ));
  689.         }
  690.     }
  691.     /**
  692.      *  add new or delete rts inventory images
  693.      * @param $request
  694.      * @param $vehicleId
  695.      * @param $em
  696.      * @param $vehicleRtsActivity
  697.      */
  698.     public  function addInventoryImages($request,$vehicleId,$em,$vehicleRtsActivity){
  699.         $activityInventory $em->getRepository(VehicleRtsActivitiesInventories::class)->findBy(['inventoryActivity'=>$vehicleRtsActivity])[0];
  700.         $em->getRepository(Vehicles::class)->find($vehicleId);
  701.         $formPostData            $request->request->all();
  702.         $formPosted $formPostData['appbundle_vehiclertsactivities'];
  703.         $formPostFiles            $request->files->all();
  704.         $images $formPostFiles['appbundle_vehiclertsactivities']['images']; // uploaded images
  705.         $imageRealPath $this->params->get('vehicle_uploaded_files') . '/' $vehicleId '/';
  706.         $fileHandler = new FileHandler();
  707.         // get the deleted images by the user when uploaded them
  708.         $deletedUploadIds explode(',',$formPosted['deletedUploadIds']);
  709.         end($deletedUploadIds);
  710.         unset($deletedUploadIds[key($deletedUploadIds)]); // remove the last item because it's empty because ','
  711.         if($images){
  712.             foreach ($images as $key => $image) {
  713.                 ++$key;
  714.                 if ($image instanceof UploadedFile && !in_array($key,$deletedUploadIds)) {// check is uploaded file and not exists in deletedUploadIds array
  715.                     $imageName md5(uniqid()). '.'$image->guessClientExtension();
  716.                     $rtsInventoryImage = new VehicleRtsActivitiesInventoriesImages();
  717.                     $rtsInventoryImage->setImagePath($imageName);
  718.                     $rtsInventoryImage->setInventory($activityInventory);
  719.                     $em->persist($rtsInventoryImage);
  720.                     $em->flush($rtsInventoryImage);
  721.                     $fileHandler->save($image$imageRealPath$imageName );
  722.                 }
  723.             }
  724.         }
  725.         // get the new images the user chose them from modal
  726.         $newImages explode(',',$formPosted['newImages']);
  727.         end($newImages);
  728.         unset($newImages[key($newImages)]); // remove the last item because it's empty because ','
  729.         foreach ($newImages as $imageName) {
  730.             $rtsInventoryImage = new VehicleRtsActivitiesInventoriesImages();
  731.             $rtsInventoryImage->setImagePath($imageName);
  732.             $rtsInventoryImage->setInventory($activityInventory);
  733.             $em->persist($rtsInventoryImage);
  734.             $em->flush($rtsInventoryImage);
  735.         }
  736.         // get the id images when user deleted them , this image uploaded before and remove them from db
  737.         $deletedImageIds explode(',',$formPosted['deletedImageIds']);
  738.         end($deletedImageIds);
  739.         unset($deletedImageIds[key($deletedImageIds)]); // remove the last item because it's empty because ','
  740.         foreach ($deletedImageIds as $imageId) {
  741.             $image =  $em->getRepository(VehicleRtsActivitiesInventoriesImages::class)->find($imageId);
  742.             $em->remove($image);
  743.             $em->flush();
  744.         }
  745.     }
  746.     /**
  747.      * Creates a form to delete a vehicleRtsActivity entity.
  748.      *
  749.      * @param Activity $vehicleRtsActivity The vehicleRtsActivity entity
  750.      * @return \Symfony\Component\Form\Form|\Symfony\Component\Form\FormInterface
  751.      */
  752.     private function createDeleteForm(Activity $vehicleRtsActivity)
  753.     {
  754.         return $this->formFactory->createBuilder()
  755.             ->setAction($this->router->generate('vehiclertsactivities_delete', array('activityId' => $vehicleRtsActivity->getActivityid())))
  756.             ->setMethod('DELETE')
  757.             ->getForm()
  758.             ;
  759.     }
  760.     public function getCityWarehouses($cityID){
  761.         return $this->entityManager->getRepository(Warehouses::class)->getCityWarehouses($cityID);
  762.     }
  763.     public function getTransporterDrivers($driverName,$transporterID){
  764.         return $this->entityManager->getRepository(TransporterDrivers::class)->getTransporterDrivers($driverName,$transporterID);
  765.     }
  766. }