src/Controller/Admin/FilmProjectCrudController.php line 1419

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\Donation;
  4. use App\Entity\FilmProject;
  5. use App\Entity\FilmProjectProgressReport;
  6. use App\Form\FilmApplicationMemberType;
  7. use App\Repository\ProductRepository;
  8. use App\Repository\FilmProjectProgressReportRepository;
  9. use App\Serializer\FilmProjectObjectConverter;
  10. use App\Service\FilmApplicationService;
  11. use App\Service\UserBillingService;
  12. use App\Service\ProgressReportService;
  13. use App\String\Constant;
  14. use App\String\ProjectString;
  15. use App\Utility\CsvExporter;
  16. use App\Utility\DropdownValues;
  17. use App\Utility\FormGenerator;
  18. use App\Utility\PdfExporter;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Doctrine\ORM\QueryBuilder;
  21. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  22. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  23. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  24. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  25. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  26. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  27. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  28. use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
  29. use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  30. use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
  31. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
  32. use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
  33. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  34. use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
  35. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  36. use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
  37. use EasyCorp\Bundle\EasyAdminBundle\Field\CountryField;
  38. use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
  39. use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
  40. use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
  41. use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField;
  42. use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
  43. use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
  44. use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
  45. use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
  46. use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
  47. use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField;
  48. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  49. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  50. use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;
  51. use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
  52. use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
  53. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  54. use Knp\Snappy\Pdf;
  55. use Symfony\Component\HttpFoundation\RedirectResponse;
  56. use Symfony\Component\HttpFoundation\RequestStack;
  57. use Symfony\Component\HttpFoundation\Response;
  58. use Symfony\Component\HttpFoundation\Session\Session;
  59. use Twig\Environment;
  60. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  61. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  62. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  63. class FilmProjectCrudController extends AbstractCrudController
  64. {
  65.     private EntityManagerInterface $em;
  66.     private AdminUrlGenerator $adminUrlGenerator;
  67.     private FilmApplicationService $filmApplicationService;
  68.     private UserBillingService $userBillingService;
  69.     private $requestStack;
  70.     private ProgressReportService $progressReportService;
  71.     private bool $isProgressReport false;
  72.     public function __construct(EntityManagerInterface $emAdminUrlGenerator $adminUrlGeneratorFilmApplicationService $filmApplicationServiceUserBillingService $userBillingServiceRequestStack $requestStackProgressReportService $progressReportService)
  73.     {
  74.         $this->em $em;
  75.         $this->adminUrlGenerator $adminUrlGenerator;
  76.         $this->filmApplicationService $filmApplicationService;
  77.         $this->userBillingService $userBillingService;
  78.         $this->requestStack $requestStack;
  79.         $this->progressReportService $progressReportService;
  80.     }
  81.     public static function getEntityFqcn(): string
  82.     {
  83.         return FilmProject::class;
  84.     }
  85.     public function configureFields(string $pageName): iterable
  86.     {
  87.         $formGenerator = new FormGenerator();
  88.         $formFields $formGenerator->generateForm(Constant::PROJECT_FORM);
  89.         $formFields array_merge($formFields, [
  90.             // FormField::addTab('Additional Information')->addCssClass('application_payment')->setPermission(Constant::PORTAL_USER_ROLE),
  91.             TextField::new('orderDetails.orderBillingDetails.firstName'ProjectString::PROJECT_PAYMENT_FIRST_NAME)->setColumns(6)->hideOnIndex()->setRequired(true)->addCssClass('firstName'),
  92.             TextField::new('orderDetails.orderBillingDetails.lastName'ProjectString::PROJECT_PAYMENT_LAST_NAME)->setColumns(6)->hideOnIndex()->setRequired(true)->addCssClass('lastName'),
  93.             TextField::new('orderDetails.orderBillingDetails.organisation'ProjectString::PROJECT_PAYMENT_ORGANISATION)->setColumns(12)->hideOnIndex(),
  94.             TextField::new('orderDetails.orderBillingDetails.abn'ProjectString::PROJECT_PAYMENT_ABN)->setColumns(12)->hideOnIndex()->setRequired(true)->addCssClass('abn'),
  95.             TextField::new('orderDetails.orderBillingDetails.street'ProjectString::PROJECT_PAYMENT_STREET)->setColumns(12)->hideOnIndex()->setRequired(true)->addCssClass('streetAddress'),
  96.             TextField::new('orderDetails.orderBillingDetails.suburb'ProjectString::PROJECT_PAYMENT_SUBURB)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('suburb'),
  97.             ChoiceField::new('orderDetails.orderBillingDetails.state'ProjectString::PROJECT_PAYMENT_STATE)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('state')->setChoices(DropdownValues::$states),
  98.             CountryField::new('orderDetails.orderBillingDetails.country'ProjectString::PROJECT_PAYMENT_COUNTRY)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('country'),
  99.             TextField::new('orderDetails.orderBillingDetails.postcode'ProjectString::PROJECT_PAYMENT_POSTCODE)->setColumns(3)->hideOnIndex()->setRequired(true)->setFormTypeOptions([
  100.                 'attr' => [
  101.                     'maxlength' => 4,
  102.                     'minlength' => 4,
  103.                 ]
  104.             ])->addCssClass('postcode'),
  105.             TextField::new('orderDetails.orderBillingDetails.phoneNumber'ProjectString::PROJECT_PAYMENT_PHONE)->setColumns(4)->hideOnIndex()->setRequired(true)->addCssClass('phone'),
  106.             TextField::new('orderDetails.orderBillingDetails.emailAddress'ProjectString::PROJECT_PAYMENT_EMAIL)->setColumns(5)->hideOnIndex()->setRequired(true)->addCssClass('emailAddress'),
  107.             // Hidden fields for Merchant Warrior payment
  108.             HiddenField::new('orderDetails.orderBillingDetails.payframeToken')->hideOnIndex()->hideOnDetail()->setCssClass('mw-token'),
  109.             HiddenField::new('orderDetails.orderBillingDetails.payframeKey')->hideOnIndex()->hideOnDetail()->setCssClass('mw-key'),
  110.             HiddenField::new('orderDetails.orderBillingDetails.cardId')->hideOnIndex()->hideOnDetail()->setCssClass('cardID'),
  111.             BooleanField::new('orderDetails.orderBillingDetails.isSavedCreditCard')->hideOnIndex()->hideOnDetail()->setCssClass('d-none is-saved-credit-card'),
  112.             
  113.             // Index fields
  114.             TextField::new('title''Project Name')->hideOnForm()->setTemplatePath('admin/field/project_title.html.twig'),
  115.             TextField::new('fundingStatus''Funding Status / Goal')->hideOnForm(),
  116.             DateField::new('filmProjectTimeline.fundraisingCampaignEndDate''End Date')->renderAsText()->hideOnForm()->setFormat('d MMM y')->setTemplatePath('admin/field/project_date.html.twig'),
  117.             TextField::new('productionStage''Project Stage')->hideOnForm()->setTemplatePath('admin/field/project_stage.html.twig'),
  118.             TextField::new('status''Status')->hideOnForm()->setTemplatePath('admin/field/project_status.html.twig'),
  119.             TextField::new('wordpressStatus''Wordpress Status')->hideOnForm()->setTemplatePath('admin/field/project_wordpress_status.html.twig'),
  120.             BooleanField::new('isHideDonationBox''Donation Box')->hideOnForm()->setTemplatePath('admin/field/is_display_donation.html.twig'),
  121.             IdField::new('wordpressId''WP ID')->hideOnForm()->setTemplatePath('admin/field/wordpress_id.html.twig')->setPermission(Constant::ADMIN_ROLE),
  122.             IdField::new('oldWordpressId''old WP ID')->hideOnForm()->setTemplatePath('admin/field/wordpress_id.html.twig')->setPermission(Constant::ADMIN_ROLE),
  123.         ]);
  124.         $user $this->getUser();
  125.         $isProgressReport $this->progressReportService->checkIfProgressReportStarts();
  126.         if($isProgressReport) {
  127.             $formFields array_merge($formFields, [
  128.                 // BooleanField::new('progressReportStatus', 'Progress Report Status')->hideOnForm()->setTemplatePath('admin/field/is_progress_report_complete.html.twig'),
  129.                 TextField::new('progressReportStatusUpdate''Progress Report Status')->hideOnForm()->setTemplatePath('admin/field/progress_report_status_update.html.twig'),
  130.             ]);
  131.         }
  132.         // $formFields = array_merge($formFields, [
  133.         //     BooleanField::new('isProgressReportActive', 'Progress Report Status')->hideOnForm()->setTemplatePath('admin/field/is_progress_report_active.html.twig'),
  134.         // ]);
  135.         return $formFields;
  136.     }
  137.     public function createIndexQueryBuilder(SearchDto $searchDtoEntityDto $entityDtoFieldCollection $fieldsFilterCollection $filters): QueryBuilder
  138.     {
  139.         // Get current user profile
  140.         $user $this->getUser();
  141.         
  142.         if ($user->isAdmin()) {
  143.             $response $this->container->get(EntityRepository::class)->createQueryBuilder($searchDto$entityDto$fields$filters);
  144.             $response
  145.                 ->andWhere('entity.status = :declined or entity.status = :approved or entity.status = :resubmit')
  146.                 ->setParameter('declined''declined')
  147.                 ->setParameter('approved''approved')
  148.                 ->setParameter('resubmit''resubmit')
  149.                 // ->addOrderBy('entity.title', 'ASC')
  150.                 ->addOrderBy('entity.id''DESC')
  151.             ;
  152.             return $response;
  153.         }
  154.         $response $this->container->get(EntityRepository::class)->createQueryBuilder($searchDto$entityDto$fields$filters);
  155.         $response
  156.             ->leftJoin('entity.filmProjectMembers','f')
  157.             ->andWhere('entity.owner = :userId or (f.email = :userEmail and f.isActive = true)')
  158.             ->andWhere('entity.status = :approved or entity.status = :declined or entity.status = :resubmit')
  159.             ->setParameter('userId'$user->getId())
  160.             ->setParameter('userEmail'$user->getEmail())
  161.             ->setParameter('approved''approved')
  162.             ->setParameter('declined''declined')
  163.             ->setParameter('resubmit''resubmit')
  164.             ->addOrderBy('entity.id''DESC');
  165.         return $response;
  166.     }
  167.     public function createEntity(string $entityFqcn)
  168.     {
  169.         $user $this->getUser();
  170.         
  171.         return $this->filmApplicationService->createFilmProjectObj($user);
  172.     }
  173.     public function persistEntity(EntityManagerInterface $entityManager$entityInstanceAdminContext $context null): void
  174.     {
  175.         $entityManager->persist($entityInstance);
  176.         $entityManager->flush();
  177.         $this->updateMainMembers($entityManager$entityInstance);
  178.     }
  179.     public function updateEntity(EntityManagerInterface $entityManager$entityInstance): void
  180.     {
  181.         $entityManager->persist($entityInstance);
  182.         $entityManager->flush();
  183.         $this->updateMainMembers($entityManager$entityInstance);
  184.     }
  185.     public function deleteEntity(EntityManagerInterface $entityManager$entityInstance): void
  186.     {
  187.         // $filmProjectAdmin = $entityInstance->getFilmProjectAdmin();
  188.         // $filmProjectProducer = $entityInstance->getFilmProjectProducer();
  189.         // $filmProjectDirector = $entityInstance->getFilmProjectDirector();
  190.         // $filmProjectMembers = $entityInstance->getFilmProjectMembers();
  191.         // $filmProjectAdmin->setAdminFilmProject(null);
  192.         // $filmProjectProducer->setProducerFilmProject(null);
  193.         // $filmProjectDirector->setDirectorFilmProject(null);
  194.         // $entityManager->persist($filmProjectAdmin);
  195.         // $entityManager->persist($filmProjectProducer);
  196.         // $entityManager->persist($filmProjectDirector);
  197.         // $entityManager->flush();
  198.         // $entityInstance
  199.         //     ->setFilmProjectAdmin(null)
  200.         //     ->setFilmProjectProducer(null)
  201.         //     ->setFilmProjectDirector(null)
  202.         // ;        
  203.         // $entityManager->remove($filmProjectAdmin);
  204.         // $entityManager->remove($filmProjectProducer);
  205.         // $entityManager->remove($filmProjectDirector);
  206.         // $entityManager->flush();
  207.         // foreach ($filmProjectMembers as $filmProjectMember) {
  208.         //     $entityManager->remove($filmProjectMember);
  209.         //     $entityInstance->removeFilmProjectMember($filmProjectMember);
  210.         // }
  211.         // $entityManager->persist($entityInstance);
  212.         // $entityManager->flush();
  213.         // $entityManager->remove($entityInstance);
  214.         // $entityManager->flush();
  215.         $entityInstance->setStatus('archived');
  216.         
  217.         $entityManager->persist($entityInstance);
  218.         $entityManager->flush();
  219.         $this->addFlash('Project removed''Project '$entityInstance->getTitle() .' has been removed.');   
  220.     }
  221.     public function configureCrud(Crud $crud): Crud
  222.     {
  223.         // $user = $this->getUser();
  224.         $crud
  225.             ->setPaginatorPageSize(60)
  226.             ->addFormTheme('admin/formTheme/film_application_theme.html.twig')
  227.             ->setPageTitle('index''Manage Projects')
  228.             ->setPageTitle('new''New Project Application')
  229.             ->setPageTitle('edit''Edit Film Project')
  230.             ->overrideTemplate('crud/new''admin/form/new_film_application_form.html.twig')
  231.             ->overrideTemplate('crud/edit''admin/form/film_application_form.html.twig')
  232.             ->overrideTemplate('crud/index''admin/index/film_project_index.html.twig')
  233.             ->overrideTemplate('flash_messages''admin/crud/flash_messages_alt.html.twig')
  234.         ;
  235.         return $crud;
  236.     }
  237.     public function configureActions(Actions $actions): Actions
  238.     {
  239.         $user $this->getUser();
  240.         $roles $user $user->getRoles() : [];
  241.         $isProgressReport $this->progressReportService->checkProgressReportStartsWithUser($user);
  242.         $backAction Action::new('backAction''Save Draft''')
  243.             ->linkToCrudAction('backAction')
  244.         ;
  245.         $saveDraft Action::new('saveDraft''Save Draft''')
  246.             ->linkToCrudAction('saveDraft')
  247.             ->displayIf(static function ($entity) {
  248.                 $status $entity->getStatus();
  249.                 return $status == 'draft' || $status == 'resubmit';
  250.             })
  251.         ;
  252.         $viewWordpressLink Action::new('viewWordpressLink''View Project''')
  253.             ->linkToUrl(function (FilmProject $entity) {
  254.                 return $entity->getWordpressUrl();
  255.             })
  256.             ->displayIf(static function ($entity) {
  257.                 $status $entity->getWordpressStatus();
  258.                 $url $entity->getWordpressUrl();
  259.                 return (( $url != '' ) && ( $status == Constant::WP_STATUS_PUBLISH ));
  260.             })
  261.             ->setHtmlAttributes(['target' => '_blank'])
  262.         ;
  263.         $viewDraftWordpressLink Action::new('viewDraftWordpressLink''View Project''')
  264.             ->linkToUrl(function (FilmProject $entity) {
  265.                 return $entity->getWordpressDraftUrl();
  266.             })
  267.             ->displayIf(static function ($entity) {
  268.                 $status $entity->getWordpressStatus();
  269.                 $url $entity->getWordpressDraftUrl();
  270.                 return (( $url != '' ) && ( $status == Constant::WP_STATUS_DRAFT ));
  271.             })
  272.             ->setHtmlAttributes(['target' => '_blank'])
  273.         ;
  274.         $exportOriginalCopy Action::new('exportOriginalCopy''Export Original Copy''')
  275.             ->linkToCrudAction('exportOriginalCopy')
  276.             ->displayIf(static function ($entity) {
  277.                 $filmProjectOriginalCopy $entity->getFilmProjectOriginal();
  278.                 return !empty($filmProjectOriginalCopy);
  279.             })
  280.         ;
  281.         $exportCurrentVersionCopy Action::new('exportCurrentVersionCopy''Export Current Version''')
  282.             ->linkToCrudAction('exportCurrentVersionCopy')
  283.             ->displayIf(static function ($entity) {
  284.                 $filmProjectOriginalCopy $entity->getFilmProjectOriginal();
  285.                 return !empty($filmProjectOriginalCopy);
  286.             })
  287.         ;
  288.         $exportOriginalCopies Action::new('exportOriginalCopies''Export Original Copy')
  289.             ->linkToCrudAction('exportOriginalCopies')
  290.         ;
  291.         $exportCurrentVersionCopies Action::new('exportCurrentVersionCopies''Export Current Version')
  292.             ->linkToCrudAction('exportCurrentVersionCopies')
  293.         ;
  294.         $publishProjects Action::new('publishProjects''Publish')
  295.             ->linkToCrudAction('publishProjects')
  296.             ->addCssClass('wordpress-action')
  297.         ;
  298.         $unpublishProjects Action::new('unpublishProjects''Unpublish')
  299.             ->linkToCrudAction('unpublishProjects')
  300.             ->addCssClass('wordpress-action')
  301.         ;
  302.         $archiveProjects Action::new('archiveProjects''Archive')
  303.             ->linkToCrudAction('archiveProjects')
  304.             ->addCssClass('wordpress-action')
  305.         ;
  306.         $viewProject Action::new('viewProject''View Project''')
  307.             ->linktoCrudACtion('viewProject')
  308.             ->displayIf(static function ($entity) {
  309.                 $status $entity->getWordpressStatus();
  310.                 $url $entity->getWordpressUrl();
  311.                 return (( $url != '' ) && ( $status == Constant::WP_STATUS_PUBLISH ));
  312.             })
  313.             ->setHtmlAttributes(['target' => '_blank'])
  314.         ;
  315.         $makePrivateProjects Action::new('makePrivateProjects''Make Password Protected')
  316.             ->linkToCrudAction('makePrivateProjects')
  317.         ;
  318.         $makeHiddenProjects Action::new('makeHiddenProjects''Hide project')
  319.             ->linkToCrudAction('makeHiddenProjects')
  320.         ;
  321.         $editProject Action::new('editProject''Edit Project')
  322.             ->linkToCrudAction(Action::EDIT)
  323.             ->displayIf(static function ($entity) {
  324.                 $isDisplay false;
  325.                 $status $entity->getStatus();
  326.                 if ($status != 'approved' && $status != 'declined') {
  327.                     $isDisplay true;
  328.                 }
  329.                 return $isDisplay;
  330.             })
  331.         ;
  332.         $hideDonationBox Action::new('hideDonationBox''Hide Donation Box')
  333.             ->linkToCrudAction('hideDonationBox')
  334.             ->displayIf(static function ($entity) {
  335.                 $wpStatus $entity->getStatus();
  336.                 $status $entity->isIsHideDonationBox();
  337.                 $isProgressReportActive $entity->isIsProgressReportActive();
  338.                 if ($isProgressReportActive) {
  339.                     return (!$status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  340.                 }
  341.                 // return (!$status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  342.                 return (!$status && $wpStatus == 'approved');
  343.             })
  344.         ;
  345.         $showDonationBox Action::new('showDonationBox''Show Donation Box')
  346.             ->linkToCrudAction('showDonationBox')
  347.             ->displayIf(static function ($entity) {
  348.                 $wpStatus $entity->getStatus();
  349.                 $status $entity->isIsHideDonationBox();
  350.                 $isProgressReportActive $entity->isIsProgressReportActive();
  351.                 if ($isProgressReportActive) {
  352.                     return ($status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  353.                 }
  354.                 // return ($status && $wpStatus == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  355.                 return ($status && $wpStatus == 'approved');
  356.             })
  357.         ;
  358.         $updateProjectDetails Action::new('updateProjectDetails''Edit Project')
  359.             ->linkToCrudAction('updateProjectDetails')
  360.             ->displayIf(static function ($entity) {
  361.                 $status $entity->getStatus();
  362.                 return ($status == 'approved');
  363.             })
  364.         ;
  365.         $viewProjectUpdates Action::new('viewProjectUpdates''View Updates')
  366.             ->linkToCrudAction('viewProjectUpdates')
  367.             ->displayIf(static function ($entity) use ($roles) {
  368.                 $status $entity->getStatus();
  369.                 $isProgressReportActive $entity->isIsProgressReportActive();
  370.                 if (!in_array(Constant::ADMIN_ROLE$roles)) {
  371.                     if ($isProgressReportActive) {
  372.                         return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  373.                     }
  374.                 }
  375.                 
  376.                 // return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  377.                 return $status == 'approved';
  378.             })
  379.         ;
  380.         $addProjectUpdates Action::new('addProjectUpdates''Add an update')
  381.             ->linkToCrudAction('addProjectUpdates')
  382.             ->displayIf(static function ($entity) use ($roles) {
  383.                 $status $entity->getStatus();
  384.                 $isProgressReportActive $entity->isIsProgressReportActive();
  385.                 if (!in_array(Constant::ADMIN_ROLE$roles)) {
  386.                     if ($isProgressReportActive) {
  387.                         return ($status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available'));
  388.                     }
  389.                 }
  390.                 return $status == 'approved';
  391.                 // return $status == 'approved';
  392.             })
  393.         ;
  394.         $manageMedia Action::new('manageMedia''Manage Image Gallery')
  395.             ->linkToCrudAction('manageMedia')
  396.             ->displayIf(static function ($entity) use ($roles) {
  397.                 $status $entity->getStatus();
  398.                 $isProgressReportActive $entity->isIsProgressReportActive();
  399.                 if (!in_array(Constant::ADMIN_ROLE$roles)) {
  400.                     if ($isProgressReportActive) {
  401.                         return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  402.                     }
  403.                 }
  404.                 // return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  405.                 return $status == 'approved';
  406.             })
  407.         ;
  408.         $managePartner Action::new('managePartner''Manage Impact Partner')
  409.             ->linkToCrudAction('managePartner')
  410.             ->displayIf(static function ($entity) use ($roles) {
  411.                 $status $entity->getStatus();
  412.                 $isProgressReportActive $entity->isIsProgressReportActive();
  413.                 if (!in_array(Constant::ADMIN_ROLE$roles)) {
  414.                     if ($isProgressReportActive) {
  415.                         return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  416.                     }
  417.                 }
  418.                 
  419.                 // return $status == 'approved' && ($entity->getProgressReportStatusUpdate() == 'complete' || $entity->getProgressReportStatusUpdate() == 'not_available');
  420.                 return $status == 'approved';
  421.             })
  422.         ;
  423.           
  424.         $downloadReport Action::new('downloadReport''Download Application')
  425.             ->linkToCrudAction('downloadReport')
  426.             ->displayIf(static function ($entity) {
  427.                 $status $entity->getStatus();
  428.                 return $status == 'approved';
  429.             })
  430.         ;
  431.         $exportDonorList Action::new('exportDonorList''Export Donor List')
  432.             ->linkToCrudAction('exportDonorList')
  433.             ->displayIf(static function ($entity) {
  434.                 $status $entity->getStatus();
  435.                 $oldWordpressId $entity->getOldWordpressId();
  436.                 return ($status == 'approved' && !$oldWordpressId);
  437.             })
  438.         ;
  439.         $viewProgressReport Action::new('viewProgressReport''View Progress Report')
  440.             ->setHtmlAttributes(['target' => '_blank'])
  441.             ->linkToCrudAction('viewProgressReport')
  442.             ->setCssClass('view-progress-report-action')
  443.             ->displayIf(static function ($entity) {
  444.                 $status $entity->getProgressReportStatusUpdate();
  445.                 $isActive $entity->isIsprogressReportActive();
  446.                 
  447.                 return $isActive && $status != 'complete' && $status != 'not_available';
  448.             })
  449.         ;
  450.         $viewSingleProgressReport Action::new('viewSingleProgressReport''View Progress Report')
  451.             ->setHtmlAttributes(['target' => '_blank'])
  452.             ->linkToCrudAction('viewProgressReport')
  453.             ->setCssClass('view-progress-report-action')
  454.             ->displayIf(static function ($entity) {
  455.                 $status $entity->getProgressReportStatusUpdate();
  456.                 $isActive $entity->isIsprogressReportActive();
  457.                 return $isActive && $status != 'complete' && $status != 'not_available';
  458.             })
  459.         ;
  460.         $viewLastYearProgressReport Action::new('viewLastYearProgressReport''View Last Year Progress Report')
  461.             ->setHtmlAttributes(['target' => '_blank'])
  462.             ->linkToCrudAction('viewLastYearProgressReport')
  463.             ->setCssClass('view-progress-report-action')
  464.             ->displayIf(static function ($entity) use ($isProgressReport) {
  465.                 $status $entity->getLastYearProgressReportStatusUpdate();
  466.                 $isActive $entity->isIsprogressReportActive();
  467.                 return ($isProgressReport || $isActive) && $status != 'complete' && $status != 'not_available';
  468.             })
  469.         ;
  470.         // $submitProjectAsAdmin = Action::new('submitProjectAsAdmin', 'Submit Project', '')
  471.         //     ->linkToCrudAction('submitProjectAsAdmin')
  472.         //     ->displayIf(static function ($entity) {
  473.         //         $status = $entity->getStatus();
  474.         //         return $status == 'draft' || $status == 'resubmit';
  475.         //     })
  476.         // ;
  477.         $exportAllProjects Action::new('exportAllProjects''Export all projects')
  478.             ->linkToUrl('/admin/project/export-all')
  479.             ->createAsGlobalAction()
  480.             ->addCssClass('btn btn-primary me-2 d-block')
  481.         ;
  482.         $exportAllDonations Action::new('exportAllDonations''Export Donations''')
  483.             ->linkToCrudAction('exportAllDonations')
  484.             ->displayIf(static function ($entity) {
  485.                 $filmProjectOriginalCopy $entity->getFilmProjectOriginal();
  486.                 return !empty($filmProjectOriginalCopy);
  487.             })
  488.         ;
  489.         // $exportDonorList->setCssClass('d-none');
  490.         // $exportAllDonations->setCssClass('d-none');
  491.         $toggleOnProgressReportStatus Action::new('toggleOnProgressReportStatus''Turn on Progress Report')
  492.             ->linkToUrl(function(FilmProject $project) {
  493.                 return '/admin/progress-report/workflow/cron/single/'$project->getId();
  494.             })
  495.             ->displayIf(static function ($entity) {
  496.                 return !$entity->isIsProgressReportActive();
  497.             })
  498.         ;
  499.         $toggleOffProgressReportStatus Action::new('toggleOffProgressReportStatus''Turn off Progress Report')
  500.             ->linkToUrl(function(FilmProject $project) {
  501.                 return '/admin/progress-report/workflow/cron/single/'$project->getId();
  502.             })
  503.             ->displayIf(static function ($entity) {
  504.                 return $entity->isIsProgressReportActive();
  505.             })
  506.         ;
  507.         $downloadProgressReport Action::new('downloadProgressReport''Download Progress Report''')
  508.             ->linkToCrudAction('downloadProgressReport')
  509.             // ->displayIf(static function ($entity) {
  510.             //     return $entity->isIsProgressReportActive();
  511.             // })
  512.         ;
  513.         if ($isProgressReport) {
  514.             // $updateProjectDetails->setCssClass('d-none');
  515.             // $hideDonationBox->setCssClass('progress-report-action');
  516.             // $showDonationBox->setCssClass('progress-report-action');
  517.             // $manageMedia->setCssClass('progress-report-action');
  518.             // $managePartner->setCssClass('progress-report-action');
  519.             // $addProjectUpdates->setCssClass('progress-report-action');
  520.             // $viewProjectUpdates->setCssClass('progress-report-action');
  521.             // $downloadProgressReport->setCssClass('progress-report-action');
  522.         }
  523.         $actions
  524.             ->add(Crud::PAGE_INDEX$viewLastYearProgressReport)
  525.             ->add(Crud::PAGE_INDEX$editProject)
  526.             ->add(Crud::PAGE_INDEX$updateProjectDetails)
  527.             ->add(Crud::PAGE_INDEX$viewProjectUpdates)
  528.             ->add(Crud::PAGE_INDEX$addProjectUpdates)
  529.             ->add(Crud::PAGE_INDEX$manageMedia)
  530.             ->add(Crud::PAGE_INDEX$managePartner)
  531.             ->add(Crud::PAGE_INDEX$hideDonationBox)
  532.             ->add(Crud::PAGE_INDEX$showDonationBox)
  533.             ->add(Crud::PAGE_INDEX$downloadReport)
  534.             ->add(Crud::PAGE_INDEX$exportDonorList)
  535.             ->add(Crud::PAGE_INDEX$viewWordpressLink)
  536.             ->add(Crud::PAGE_INDEX$viewDraftWordpressLink)
  537.             ->add(Crud::PAGE_INDEX$exportAllProjects)
  538.             ->add(Crud::PAGE_INDEX$exportAllDonations)
  539.             ->add(Crud::PAGE_INDEX$toggleOnProgressReportStatus)
  540.             ->add(Crud::PAGE_INDEX$toggleOffProgressReportStatus)
  541.             // ->add(Crud::PAGE_INDEX, $viewSingleProgressReport)
  542.             ->add(Crud::PAGE_INDEX$downloadProgressReport)
  543.             ->add(Crud::PAGE_NEW$backAction)
  544.             ->add(Crud::PAGE_NEW$saveDraft)
  545.             // ->add(Crud::PAGE_NEW, Action::INDEX)
  546.             ->add(Crud::PAGE_NEWAction::SAVE_AND_CONTINUE)
  547.             ->add(Crud::PAGE_EDIT$backAction)
  548.             ->add(Crud::PAGE_EDIT$saveDraft)
  549.             ->add(Crud::PAGE_EDIT$exportOriginalCopy)
  550.             ->add(Crud::PAGE_EDIT$exportCurrentVersionCopy)
  551.             // ->add(Crud::PAGE_EDIT, $submitProjectAsAdmin)
  552.             // ->add(Crud::PAGE_EDIT, Action::INDEX)
  553.             ->add(Crud::PAGE_EDIT$viewProject)
  554.             ->add(Crud::PAGE_EDITAction::DELETE)
  555.             ->addBatchAction($exportOriginalCopies)
  556.             ->addBatchAction($exportCurrentVersionCopies)
  557.             ->addBatchAction($publishProjects)
  558.             ->addBatchAction($unpublishProjects)
  559.             ->addBatchAction($archiveProjects)
  560.             ->addBatchAction($makePrivateProjects)
  561.             ->addBatchAction($makeHiddenProjects)
  562.             ->update(Crud::PAGE_INDEXAction::NEW, function (Action $action) {
  563.                 return $action->setLabel('Start an Application');
  564.             })
  565.             // ->update(Crud::PAGE_NEW, Action::INDEX, function (Action $action) {
  566.             //     return $action
  567.             //         ->setLabel('<i class="fa-fw fa fa-list me-1"></i> View Project')
  568.             //         ->setCssClass('me-3 link-primary fw-bold')
  569.             //     ;
  570.             // })
  571.             ->update(Crud::PAGE_NEWAction::SAVE_AND_RETURN, function (Action $action) {
  572.                 return $action->setLabel('Next');
  573.             })
  574.             ->update(Crud::PAGE_NEW$saveDraft, function (Action $action) {
  575.                 return $action->addCssClass('ms-2 px-4 btn btn-secondary action-saveDraft');
  576.             })  
  577.             ->update(Crud::PAGE_NEW$backAction, function (Action $action) {
  578.                 return $action->addCssClass('btn btn-primary d-none action-backAction me-2')->setLabel('Back');
  579.             })
  580.             
  581.             ->update(Crud::PAGE_EDIT$viewProject, function (Action $action) {
  582.                 return $action
  583.                     ->setLabel('<i class="fa-fw fa fa-list me-1"></i> View Project')
  584.                     ->setCssClass('mx-3 link-primary fw-bold')
  585.                 ;
  586.             })
  587.             ->update(Crud::PAGE_EDITAction::SAVE_AND_RETURN, function (Action $action) {
  588.                 return $action->setLabel('Next');
  589.             })     
  590.             ->update(Crud::PAGE_EDIT$saveDraft, function (Action $action) {
  591.                 return $action->addCssClass('ms-2 px-4 btn btn-secondary action-saveDraft');
  592.             })
  593.             ->update(Crud::PAGE_EDIT$backAction, function (Action $action) {
  594.                 return $action->addCssClass('btn btn-primary d-none action-backAction me-2')->setLabel('Back');
  595.             })
  596.             ->update(Crud::PAGE_EDIT$exportOriginalCopy, function (Action $action) {
  597.                 return $action->addCssClass('btn btn-secondary me-2')->setLabel('Export Original Version');
  598.             })
  599.             ->update(Crud::PAGE_EDIT$exportCurrentVersionCopy, function (Action $action) {
  600.                 return $action->addCssClass('btn btn-secondary me-2')->setLabel('Export Current Version');
  601.             })
  602.             // ->update(Crud::PAGE_EDIT, $submitProjectAsAdmin, function (Action $action) {
  603.             //     return $action->addCssClass('btn btn-primary me-2 order-1')->setLabel('Submit Project');
  604.             // })
  605.             ->remove(Crud::PAGE_INDEXAction::EDIT)
  606.             ->setPermission($exportOriginalCopyConstant::ADMIN_ROLE)
  607.             ->setPermission($exportCurrentVersionCopyConstant::ADMIN_ROLE)
  608.             ->setPermission($publishProjectsConstant::ADMIN_ROLE)
  609.             ->setPermission($unpublishProjectsConstant::ADMIN_ROLE)
  610.             ->setPermission($archiveProjectsConstant::ADMIN_ROLE)
  611.             ->setPermission($makePrivateProjectsConstant::ADMIN_ROLE)
  612.             ->setPermission($makeHiddenProjectsConstant::ADMIN_ROLE)
  613.             ->setPermission(Action::DELETEConstant::ADMIN_ROLE)
  614.             ->setPermission(Action::BATCH_DELETEConstant::ADMIN_ROLE)
  615.             ->setPermission($exportAllProjectsConstant::ADMIN_ROLE)
  616.             ->setPermission($viewDraftWordpressLinkConstant::ADMIN_ROLE)
  617.             ->setPermission($exportAllDonationsConstant::ADMIN_ROLE)
  618.             ->setPermission($toggleOnProgressReportStatusConstant::ADMIN_ROLE)
  619.             ->setPermission($toggleOffProgressReportStatusConstant::ADMIN_ROLE)
  620.             // ->setPermission($submitProjectAsAdmin, Constant::ADMIN_ROLE)
  621.             ->reorder(Crud::PAGE_INDEX, ['viewDraftWordpressLink''viewWordpressLink''viewLastYearProgressReport''editProject''updateProjectDetails''showDonationBox''hideDonationBox''manageMedia''managePartner''addProjectUpdates''viewProjectUpdates''exportAllDonations''downloadReport''downloadProgressReport''exportDonorList''toggleOnProgressReportStatus''toggleOffProgressReportStatus'Action::DELETE])
  622.             ->reorder(Crud::PAGE_EDIT, [Action::DELETE'viewProject''backAction''saveDraft''exportOriginalCopy''exportCurrentVersionCopy'Action::SAVE_AND_RETURN])
  623.             ->reorder(Crud::PAGE_NEW, ['backAction''saveDraft'Action::SAVE_AND_RETURN])
  624.         ;
  625.         if ($isProgressReport) {
  626.             $actions
  627.                 ->add(Crud::PAGE_INDEX$viewProgressReport)
  628.                 // ->update(Crud::PAGE_INDEX, $updateProjectDetails, function(Action $action) {
  629.                 //     return $action->setLabel('View Project Details');
  630.                 // })
  631.             ;
  632.             if (!in_array(Constant::ADMIN_ROLE$roles)) {
  633.                 $actions->update(Crud::PAGE_INDEX$updateProjectDetails, function(Action $action) {
  634.                     return $action->setLabel('View Project Details');
  635.                 });
  636.             }
  637.         } else {
  638.             $actions
  639.                 ->add(Crud::PAGE_INDEX$viewSingleProgressReport)
  640.             ;
  641.         }
  642.         return $actions;
  643.     }
  644.     public function configureFilters(Filters $filters): Filters
  645.     {
  646.         // Get current user profile
  647.         $user $this->getUser();
  648.         
  649.         if ($user->isAdmin()) {
  650.             $filters $filters
  651.                 ->add('owner')
  652.                 ->add(EntityFilter::new('filmProjectAdmin''Project Admin'))
  653.             ;
  654.         }
  655.         return $filters;
  656.     }
  657.     protected function getRedirectResponseAfterSave(AdminContext $contextstring $action): RedirectResponse
  658.     {
  659.         $submitButtonName $context->getRequest()->request->all()['ea']['newForm']['btn'];
  660.         $user $this->getUser();
  661.         // if (!$user->isAdmin()) { // IF USER IS NOT ADMIN
  662.         if (Action::SAVE_AND_CONTINUE === $submitButtonName) { // SAVE DRAFT RESPONSE
  663.             $entityInstance $context->getEntity()->getInstance();
  664.             
  665.             $this->filmApplicationService->setFilmProjectToDraft($entityInstance);
  666.             $this->addFlash('success''Your draft has been saved.');
  667.             $url $this->container->get(AdminUrlGenerator::class)
  668.                 ->setAction(Action::EDIT)
  669.                 ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  670.                 ->generateUrl();
  671.             return $this->redirect($url);
  672.         }
  673.         if (Action::SAVE_AND_RETURN === $submitButtonName) { // FINISH APPLICATION RESPONSE
  674.             $entityInstance $context->getEntity()->getInstance();
  675.             $user $this->getUser();
  676.             // Save everything before 
  677.             $this->em->persist($entityInstance);
  678.             $this->em->flush();
  679.             // Check if image exists
  680.             $isImage $this->filmApplicationService->checkIsProjectImage($entityInstance);
  681.             if (!$isImage) {
  682.                 $backUrl $this->container->get(AdminUrlGenerator::class)
  683.                     ->setAction(Action::EDIT)
  684.                     ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  685.                     ->generateUrl();
  686.                 $this->addFlash('notice''Image in Project Details Tab is required.');
  687.                 return $this->redirect($backUrl);
  688.             }
  689.             if (!$entityInstance->getResubmitCount()) {
  690.                 $this->filmApplicationService->proceedPayment($entityInstance);
  691.             }
  692.             $this->filmApplicationService->setFilmProjectToReadyForReview($entityInstance);
  693.             $this->filmApplicationService->setFilmProjectCreatedDateToday($entityInstance); // Set created date for searching purpose
  694.             $this->filmApplicationService->generateSponsorsFromText($entityInstance); 
  695.             
  696.             $this->handleWordpressEndpoint($entityInstance); // handles Wordpress creation and update
  697.             $this->handleSalesforceEndpoint($entityInstance$user); // handles Salesforce creation and update
  698.             
  699.             if (!$entityInstance->getResubmitCount()) { 
  700.                 $this->filmApplicationService->createFilmProjectInvoice($user$entityInstance);
  701.                 $this->filmApplicationService->sendEmail($entityInstance);
  702.             }
  703.             
  704.             $this->addFlash('Application Submitted''Film project '$entityInstance->getTitle() . ' has been submitted.');
  705.             $url $this->container->get(AdminUrlGenerator::class)
  706.                 ->setController(PendingFilmProjectCrudController::class)
  707.                 ->setAction(Action::INDEX)
  708.                 ->generateUrl();
  709.             return $this->redirect($url);
  710.         }
  711.         if (Action::SAVE_AND_ADD_ANOTHER === $submitButtonName) {
  712.             $url $this->container->get(AdminUrlGenerator::class)->setAction(Action::NEW)->generateUrl();
  713.             return $this->redirect($url);
  714.         }
  715.         return $this->redirectToRoute($context->getDashboardRouteName());
  716.     }
  717.     private function handleWordpressEndpoint(FilmProject $entityInstance) {
  718.         $wordpressId $entityInstance->getWordpressId();
  719.         $oldWordpressId $entityInstance->getOldWordpressId();
  720.                
  721.         if ($wordpressId && $wordpressId != $oldWordpressId) {
  722.             $this->filmApplicationService->updateWordpressObject($entityInstance);
  723.         } else {
  724.             $this->filmApplicationService->createWordpressObject($entityInstance);
  725.         }
  726.     }
  727.     private function handleSalesforceEndpoint(FilmProject $entityInstance$user null) {
  728.         $salesforceCampaignId $entityInstance->getSalesforceId();
  729.         if ($salesforceCampaignId) {
  730.             $this->filmApplicationService->updateCampaignSalesforce($entityInstance);
  731.         } else {
  732.             $this->filmApplicationService->createCampaignSalesforce($entityInstance);
  733.         }
  734.         
  735.         if (empty($orderDetailsSalesforceId) && empty($oldWordpressId) && !$user->isAdmin() && !$entityInstance->getResubmitCount()) {
  736.             $this->filmApplicationService->createTransactionSalesforce($entityInstance);
  737.         }
  738.         if ($user->isAdmin()) {
  739.             $this->filmApplicationService->updateCampaignSalesforceAdmin($entityInstance);
  740.         }
  741.     }
  742.     public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  743.     {
  744.         if ( $_GET['crudAction'] === Action::EDIT) {
  745.             $filmProject $this->getFilmProjectFromEntityId();
  746.             if ($filmProject) {
  747.                 $responseParameters
  748.                     ->set('filmProject'$filmProject)
  749.                 ;
  750.             }
  751.         }
  752.         $product $this->filmApplicationService->getDefaultProduct();
  753.         $cards $this->userBillingService->getCurrentSavedCards(); // Get saved cards
  754.         $responseParameters->setAll([
  755.             'product' => $product,
  756.             'cards' => $cards,
  757.         ]);
  758.         return $responseParameters;
  759.     }
  760.     // Custom Actions
  761.     public function saveDraft(AdminContext $context): Response
  762.     {
  763.         $entityInstance $context->getEntity()->getInstance();
  764.         $entityInstance->setStatus('draft');
  765.         if ( $entityInstance->getResubmitCount() ) {
  766.             $entityInstance->setStatus('resubmit');
  767.         }
  768.         
  769.         $this->em->persist($entityInstance);
  770.         $this->em->flush();
  771.         $this->addFlash('success''Your draft has been saved');
  772.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(DraftFilmProjectCrudController::class)
  773.             ->setAction(Action::INDEX)
  774.             ->generateUrl();
  775.         return new RedirectResponse($filmProjectIndexUrl);
  776.     }
  777.     
  778.     public function exportOriginalCopy(AdminContext $context): Response
  779.     {
  780.         $entityInstance $context->getEntity()->getInstance();
  781.         $filmProjectOriginalCopy $entityInstance->getFilmProjectOriginal()->getData();
  782.         $csvExporter = new CsvExporter();
  783.         $csvExporter->exportArrayToCsv($filmProjectOriginalCopy$entityInstance->getTitle() .'-V1.csv');
  784.         $this->addFlash('success''Your original copy has been exported');
  785.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  786.             ->setAction(Action::INDEX)
  787.             ->generateUrl();
  788.         return new RedirectResponse($filmProjectIndexUrl);
  789.     }
  790.     public function exportCurrentVersionCopy(AdminContext $context): Response
  791.     {
  792.         $entityInstance $context->getEntity()->getInstance();
  793.         $filmProjectConverter = new FilmProjectObjectConverter();
  794.         $serializedFilmProject $filmProjectConverter->serializeFilmProjectDocument($entityInstance);
  795.         $csvExporter = new CsvExporter();
  796.         $csvExporter->exportArrayToCsv($serializedFilmProject$entityInstance->getTitle() .'.csv');
  797.         $this->addFlash('success''Your current version project has been exported');
  798.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  799.             ->setAction(Action::INDEX)
  800.             ->generateUrl();
  801.         return new RedirectResponse($filmProjectIndexUrl);
  802.     }
  803.     public function updateProjectDetails(AdminContext $context): Response
  804.     {
  805.         $entityInstance $context->getEntity()->getInstance();
  806.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectEditCrudController::class)
  807.             ->setAction(Action::EDIT)
  808.             ->setEntityId($entityInstance->getId())
  809.             ->generateUrl();
  810.         if ($entityInstance->isIsProgressReportActive() && $entityInstance->getProgressReportStatusUpdate() != 'complete') {
  811.             $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectEditCrudController::class)
  812.                 ->setAction(Action::EDIT)
  813.                 ->setEntityId($entityInstance->getId())
  814.                 ->set('disableFields'"true"
  815.                 ->generateUrl()
  816.             ;
  817.         }
  818.         return new RedirectResponse($projectUpdateUrl);
  819.     }
  820.     public function viewProjectUpdates(AdminContext $context): Response
  821.     {
  822.         $entityInstance $context->getEntity()->getInstance();
  823.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectUpdateCrudController::class)
  824.             ->setAction(Action::INDEX)
  825.             ->unset('entityId')
  826.             ->set('project'$entityInstance->getId())
  827.             ->generateUrl();
  828.         return new RedirectResponse($projectUpdateUrl);
  829.     }
  830.     public function addProjectUpdates(AdminContext $context): Response
  831.     {
  832.         $entityInstance $context->getEntity()->getInstance();
  833.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectUpdateCrudController::class)
  834.             ->setAction(Action::NEW)
  835.             ->unset('entityId')
  836.             ->set('project'$entityInstance->getId())
  837.             ->generateUrl();
  838.         return new RedirectResponse($projectUpdateUrl);
  839.     }
  840.     public function manageMedia(AdminContext $context): Response
  841.     {
  842.         $entityInstance $context->getEntity()->getInstance();
  843.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectMediaCrudController::class)
  844.             ->setAction(Action::EDIT)
  845.             ->setEntityId($entityInstance->getId())
  846.             ->generateUrl();
  847.         return new RedirectResponse($projectUpdateUrl);
  848.     }
  849.     public function managePartner(AdminContext $context): Response
  850.     {
  851.         $entityInstance $context->getEntity()->getInstance();
  852.         $projectUpdateUrl $this->adminUrlGenerator->setController(FilmProjectPartnerCrudController::class)
  853.             ->setAction(Action::EDIT)
  854.             ->setEntityId($entityInstance->getId())
  855.             ->generateUrl();
  856.         return new RedirectResponse($projectUpdateUrl);
  857.     }
  858.     /**
  859.      * BATCH ACTION: export original version
  860.      *
  861.      * @param BatchActionDto $batchActionDto
  862.      * @return void
  863.      */
  864.     public function exportOriginalCopies(BatchActionDto $batchActionDto)
  865.     {
  866.         $className $batchActionDto->getEntityFqcn();
  867.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  868.         
  869.         $filmProjectOriginalCopies = [];
  870.         foreach ($batchActionDto->getEntityIds() as $id) {
  871.             $entityInstance $entityManager->find($className$id);
  872.             $filmProjectOriginalCopy $entityInstance->getFilmProjectOriginal();
  873.             if (empty($filmProjectOriginalCopy)) {
  874.                 $this->addFlash('warning''Only approved projects can be exported into CSV');
  875.                 return $this->redirect($batchActionDto->getReferrerUrl());
  876.             }
  877.             array_push($filmProjectOriginalCopies$filmProjectOriginalCopy->getData());
  878.         }
  879.         
  880.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  881.         $csvExporter = new CsvExporter();
  882.         $csvExporter->exportProjectsToCsv($filmProjectOriginalCopies'projects_V1-'$dateValue .'.xlsx');
  883.    
  884.         // return $this->redirect($batchActionDto->getReferrerUrl());
  885.     }
  886.     /**
  887.      * BATCH: Export current version copy
  888.      *
  889.      * @param BatchActionDto $batchActionDto
  890.      * @return void
  891.      */
  892.     public function exportCurrentVersionCopies(BatchActionDto $batchActionDto)
  893.     {
  894.         $className $batchActionDto->getEntityFqcn();
  895.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  896.         
  897.         $filmProjectConverter = new FilmProjectObjectConverter();
  898.         $filmProjectOriginalCopies = [];
  899.         foreach ($batchActionDto->getEntityIds() as $id) {
  900.             $entityInstance $entityManager->find($className$id);
  901.             $serializedFilmProject $filmProjectConverter->serializeFilmProjectDocument($entityInstance);
  902.             array_push($filmProjectOriginalCopies$serializedFilmProject);
  903.         }
  904.         
  905.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  906.         $csvExporter = new CsvExporter();
  907.         $csvExporter->exportProjectsToCsv($filmProjectOriginalCopies'projects-'$dateValue .'.xlsx');
  908.     
  909.         // return $this->redirect($batchActionDto->getReferrerUrl());
  910.     }
  911.     /**
  912.      * BATCH: Publish projects
  913.      *
  914.      * @param BatchActionDto $batchActionDto
  915.      * @return void
  916.      */
  917.     public function publishProjects(BatchActionDto $batchActionDto)
  918.     {
  919.         $className $batchActionDto->getEntityFqcn();
  920.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  921.         // Check if there is non-approved projects
  922.         foreach ($batchActionDto->getEntityIds() as $id) {
  923.             $entityInstance $entityManager->find($className$id);
  924.             
  925.             if ($entityInstance->getStatus() != 'approved') {
  926.                 $this->addFlash('notice''Project(s) have to be approved before being published.');
  927.                 return $this->redirect($batchActionDto->getReferrerUrl());
  928.             }
  929.         }
  930.         foreach ($batchActionDto->getEntityIds() as $id) {
  931.             $entityInstance $entityManager->find($className$id);
  932.             $this->filmApplicationService->publishProject($entityInstance);
  933.         }
  934.         $this->addFlash('success''Project(s) have been published');
  935.         return $this->redirect($batchActionDto->getReferrerUrl());
  936.     }
  937.     /**
  938.      * BATCH: Unublish projects
  939.      *
  940.      * @param BatchActionDto $batchActionDto
  941.      * @return void
  942.      */
  943.     public function unpublishProjects(BatchActionDto $batchActionDto)
  944.     {
  945.         $className $batchActionDto->getEntityFqcn();
  946.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  947.         // Check if there is non-approved projects
  948.         foreach ($batchActionDto->getEntityIds() as $id) {
  949.             $entityInstance $entityManager->find($className$id);
  950.             
  951.             if ($entityInstance->getStatus() != 'approved') {
  952.                 $this->addFlash('notice''Project(s) have to be approved before being unpublished.');
  953.                 return $this->redirect($batchActionDto->getReferrerUrl());
  954.             }
  955.         }
  956.         foreach ($batchActionDto->getEntityIds() as $id) {
  957.             $entityInstance $entityManager->find($className$id);
  958.             $this->filmApplicationService->unpublishProject($entityInstance);
  959.         }
  960.         $this->addFlash('success''Project(s) have been unpublished');
  961.         return $this->redirect($batchActionDto->getReferrerUrl());
  962.     }
  963.     public function viewProject(AdminContext $adminContext)
  964.     {
  965.         $entityInstance $adminContext->getEntity()->getInstance();
  966.         return $this->redirect($entityInstance->getWordpressUrl());
  967.     }
  968.     /**
  969.      * BATCH: archive projects
  970.      *
  971.      * @param BatchActionDto $batchActionDto
  972.      * @return void
  973.      */
  974.     public function archiveProjects(BatchActionDto $batchActionDto)
  975.     {
  976.         $className $batchActionDto->getEntityFqcn();
  977.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  978.         // Check if there is non-approved projects
  979.         foreach ($batchActionDto->getEntityIds() as $id) {
  980.             $entityInstance $entityManager->find($className$id);
  981.             
  982.             if ($entityInstance->getStatus() != 'approved') {
  983.                 $this->addFlash('notice''Project(s) have to be approved before being archived.');
  984.                 return $this->redirect($batchActionDto->getReferrerUrl());
  985.             }
  986.         }
  987.         foreach ($batchActionDto->getEntityIds() as $id) {
  988.             $entityInstance $entityManager->find($className$id);
  989.             $this->filmApplicationService->archiveProject($entityInstance);
  990.         }
  991.         $this->addFlash('success''Project(s) have been archived');
  992.         return $this->redirect($batchActionDto->getReferrerUrl());
  993.     }
  994.     /**
  995.      * BATCH: Make private projects
  996.      *
  997.      * @param BatchActionDto $batchActionDto
  998.      * @return void
  999.      */
  1000.     public function makePrivateProjects(BatchActionDto $batchActionDto)
  1001.     {
  1002.         $postPassword '';
  1003.         if (isset($_COOKIE['postpassword'])) {
  1004.             $postPassword $_COOKIE['postpassword'];
  1005.         }
  1006.         if ($postPassword) {
  1007.             $className $batchActionDto->getEntityFqcn();
  1008.             $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  1009.             foreach ($batchActionDto->getEntityIds() as $id) {
  1010.                 $entityInstance $entityManager->find($className$id);
  1011.                 $this->filmApplicationService->makePrivateProject($entityInstance$postPassword);
  1012.             }
  1013.         }
  1014.         $this->addFlash('success''Project(s) have been made private');
  1015.         return $this->redirect($batchActionDto->getReferrerUrl());
  1016.     }
  1017.     public function downloadReport(AdminContext $contextEnvironment $twig nullPdf $pdf)
  1018.     {
  1019.         $filmProject $context->getEntity()->getInstance();
  1020.         $pdfExporter = new PdfExporter($twig$pdf);
  1021.         $pdfExporter->convertProjectToPdf($filmProject);
  1022.     }
  1023.     public function hideDonationBox(AdminContext $adminContext)
  1024.     {
  1025.         $entityInstance $adminContext->getEntity()->getInstance();
  1026.         $this->filmApplicationService->hideDonationBox($entityInstance);
  1027.         $this->addFlash('success''The donation box for project '$entityInstance->getTitle() .' has been hidden.');
  1028.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1029.             ->setAction(Action::INDEX)
  1030.             ->generateUrl();
  1031.         return new RedirectResponse($filmProjectIndexUrl);
  1032.     }
  1033.     public function showDonationBox(AdminContext $adminContext)
  1034.     {
  1035.         $entityInstance $adminContext->getEntity()->getInstance();
  1036.         $this->filmApplicationService->showDonationBox($entityInstance);
  1037.         $this->addFlash('success''The donation box for project '$entityInstance->getTitle() .' has been displayed.');
  1038.         $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1039.             ->setAction(Action::INDEX)
  1040.             ->generateUrl();
  1041.         return new RedirectResponse($filmProjectIndexUrl);
  1042.     }
  1043.     public function submitProjectAsAdmin(AdminContext $context
  1044.     {
  1045.         $user $this->getUser();
  1046.         $entityInstance $context->getEntity()->getInstance();
  1047.         // Save everything before 
  1048.         $this->em->persist($entityInstance);
  1049.         $this->em->flush();
  1050.         // Check if image exists
  1051.         $isImage $this->filmApplicationService->checkIsProjectImage($entityInstance);
  1052.         if (!$isImage) {
  1053.             $backUrl $this->container->get(AdminUrlGenerator::class)
  1054.                 ->setAction(Action::EDIT)
  1055.                 ->setEntityId($context->getEntity()->getPrimaryKeyValue())
  1056.                 ->generateUrl();
  1057.             $this->addFlash('notice''Image in Project Details Tab is required.');
  1058.             return $this->redirect($backUrl);
  1059.         }
  1060.         $this->filmApplicationService->setFilmProjectToReadyForReview($entityInstance);
  1061.         $this->filmApplicationService->setFilmProjectCreatedDateToday($entityInstance); // Set created date for searching purpose
  1062.         
  1063.         $this->filmApplicationService->generateSponsorsFromText($entityInstance);
  1064.         $this->filmApplicationService->createWordpressObject($entityInstance);
  1065.         $this->filmApplicationService->createCampaignSalesforce($entityInstance);
  1066.         if (!$entityInstance->getOldWordpressId()) {
  1067.             $this->filmApplicationService->createTransactionSalesforce($entityInstance);
  1068.         }
  1069.         
  1070.         if (!$entityInstance->getResubmitCount()) {
  1071.             $this->filmApplicationService->proceedPayment($entityInstance);
  1072.             $this->filmApplicationService->createFilmProjectInvoice($user$entityInstance);       
  1073.             $this->filmApplicationService->sendEmail($entityInstance);
  1074.         }
  1075.         
  1076.         $this->addFlash('Application Submitted''Film project '$entityInstance->getTitle() . ' has been submitted.');
  1077.         $url $this->container->get(AdminUrlGenerator::class)
  1078.             ->setController(PendingFilmProjectCrudController::class)
  1079.             ->setAction(Action::INDEX)
  1080.             ->generateUrl();
  1081.         return $this->redirect($url);
  1082.     }
  1083.     
  1084.     public function exportAllDonations(AdminContext $adminContext) {
  1085.         $entityInstance $adminContext->getEntity()->getInstance();
  1086.         $donationRepository $this->em->getRepository(Donation::class);
  1087.         $donations $donationRepository->findDonationsByProjectOrderDate($entityInstance->getId());
  1088.         $spreadsheet = new Spreadsheet();
  1089.         $sheet $spreadsheet->getActiveSheet();
  1090.         // Generate columns first
  1091.         $columnTitles = ["Order ID""Receipt ID""First Name""Last Name""Email""Organisation""Donation to""Wordpress ID""Is Anonymous""Total Amount""Pop-up Amount""Fundraising Goal""Date""Status""Salesforce ID""Xero Invoice ID""Xero Contact ID""Merchant Warrior ID"];
  1092.         $excelCol 'A';
  1093.         $excelRow 1;
  1094.         foreach($columnTitles as $columnTitle) {
  1095.             $currentPosition $excelCol .''$excelRow;
  1096.             $sheet->setCellValue($currentPosition$columnTitle)->getColumnDimension($excelCol)->setAutoSize(TRUE);
  1097.             $excelCol++;
  1098.         }
  1099.         $excelRow++;
  1100.         // Universal project field(s)
  1101.         $filmProjectFunding $entityInstance->getFilmProjectFunding();
  1102.         $fundraisingGoal = (number_format((float)$filmProjectFunding->getFundraisingGoal() / 1002));
  1103.         $fundraisingStatus 0;
  1104.         // After that, we generate data respectively
  1105.         $limit 2000;
  1106.         foreach ($donations as $donation) {
  1107.             // Universal project field(s)
  1108.             $project $donation->getFilmProject();
  1109.             $filmProjectFunding $project->getFilmProjectFunding();
  1110.             $fundraisingGoal = (number_format((float)$filmProjectFunding->getFundraisingGoal() / 1002));
  1111.             $orderDetails $donation->getOrderDetails();
  1112.             $orderBillingDetails $orderDetails->getOrderBillingDetails();
  1113.             $paymentDetails $orderDetails->getPaymentDetails();
  1114.             $isAnonymous = (!$donation->isIsContactShared() || !$donation->isIsOrganisationConsent());
  1115.             $isAnon =  (!$donation->isIsContactShared() || !$donation->isIsOrganisationConsent()) ? 'yes' 'no';
  1116.             $totalAmount = (number_format((float)$orderDetails->getTotal() / 1002));
  1117.             if ($donation->getSupportDaf()) {
  1118.                 $totalAmount = (number_format(((float)$orderDetails->getTotal()- $donation->getSupportDaf()) / 1002));
  1119.             }
  1120.             $popupAmount = (number_format((float)$donation->getSupportDaf() / 1002));
  1121.             $isAnonymous = !$this->getUser()->isAdmin();
  1122.             $sheet->setCellValue('A'.$excelRow 'MW'.$orderDetails->getId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Order ID
  1123.             $sheet->setCellValue('B'.$excelRow $orderDetails->getInvoiceNumber())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Receipt ID
  1124.             $sheet->setCellValue('C'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getFirstName())->getColumnDimension($excelCol)->setAutoSize(TRUE); // First Name
  1125.             $sheet->setCellValue('D'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getLastName())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Last Name
  1126.             $sheet->setCellValue('E'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getEmailAddress())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Email
  1127.             $sheet->setCellValue('F'.$excelRow $isAnonymous 'Anonymous' $orderBillingDetails->getOrganisation())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Organisation
  1128.             $sheet->setCellValue('G'.$excelRow $donation->getFilmProject())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Donation to
  1129.             $sheet->setCellValue('H'.$excelRow , (string)$donation->getFilmProject()->getWordpressId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Wordpress ID
  1130.             $sheet->setCellValue('I'.$excelRow $isAnon)->getColumnDimension($excelCol)->setAutoSize(TRUE); // Is Anonymous
  1131.             $sheet->setCellValue('J'.$excelRow str_replace(","""$totalAmount))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Total Amount
  1132.             $sheet->setCellValue('K'.$excelRow str_replace(","""$popupAmount))->getColumnDimension($excelCol)->setAutoSize(TRUE); // pop-up Amount
  1133.             // $sheet->setCellValue('L'.$excelRow , str_replace(",", "", $fundraisingStatus))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Fundraising Status
  1134.             $sheet->setCellValue('L'.$excelRow str_replace(","""$fundraisingGoal))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Fundraising Goal
  1135.             $sheet->setCellValue('M'.$excelRow date_format($donation->getModifiedAt(), 'd/m/Y'))->getColumnDimension($excelCol)->setAutoSize(TRUE); // Date
  1136.             $sheet->setCellValue('N'.$excelRow $paymentDetails->getStatus())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Status
  1137.             $sheet->setCellValue('O'.$excelRow $orderDetails->getSalesforceId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Salesforce ID
  1138.             $sheet->setCellValue('P'.$excelRow $orderDetails->getXeroId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Xero Invoice ID
  1139.             $sheet->setCellValue('Q'.$excelRow $orderDetails->getXeroContactId())->getColumnDimension($excelCol)->setAutoSize(TRUE); // Xero Contact ID
  1140.             $sheet->setCellValue('R'.$excelRow , ($orderDetails->getTransactionId()) ? $orderDetails->getTransactionId() : 'Manual Donation')->getColumnDimension($excelCol)->setAutoSize(TRUE); // Merchant Warrior ID
  1141.             $sheet->getStyle('J'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1142.             $sheet->getStyle('K'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1143.             $sheet->getStyle('L'.$excelRow)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD);
  1144.             if ($excelRow $limit ) {
  1145.                 break;
  1146.             }
  1147.             $excelRow++;
  1148.         }
  1149.         ob_clean();
  1150.         $writer = new Xlsx($spreadsheet);
  1151.         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  1152.         header('Content-Disposition: attachment; filename="'$entityInstance->getTitle() .' donations.xlsx"');
  1153.         $writer->save('php://output');
  1154.         exit();
  1155.     }
  1156.     /**
  1157.      * Get film project from entity ID 
  1158.      *
  1159.      * @return FilmProject|null
  1160.      */
  1161.     protected function getFilmProjectFromEntityId(): ?FilmProject
  1162.     {
  1163.         $entityManager $this->container->get('doctrine')->getManagerForClass(FilmProject::class);
  1164.         $repository =  $entityManager->getRepository(FilmProject::class);
  1165.         $filmProject $repository->findOneBy(['id' => $_GET['entityId']]);
  1166.         return $filmProject;
  1167.     }
  1168.     protected function updateMainMembers(EntityManagerInterface $entityManagerFilmProject $entityInstance)
  1169.     {
  1170.         // Assign main members to project
  1171.         $administrator $entityInstance->getFilmProjectAdmin();
  1172.         $administrator->setAdminFilmProject($entityInstance);
  1173.         $entityManager->persist($administrator);
  1174.         $director $entityInstance->getFilmProjectDirector();
  1175.         $director->setDirectorFilmProject($entityInstance);
  1176.         $entityManager->persist($director);
  1177.         $producer $entityInstance->getFilmProjectProducer();
  1178.         $producer->setProducerFilmProject($entityInstance);
  1179.         $entityManager->persist($producer);
  1180.         $entityManager->flush();
  1181.     }
  1182.     /**
  1183.      * BATCH: Make hidden projects
  1184.      *
  1185.      * @param BatchActionDto $batchActionDto
  1186.      * @return void
  1187.      */
  1188.     public function makeHiddenProjects(BatchActionDto $batchActionDto)
  1189.     {
  1190.         $className $batchActionDto->getEntityFqcn();
  1191.         $entityManager $this->container->get('doctrine')->getManagerForClass($className);
  1192.         foreach ($batchActionDto->getEntityIds() as $id) {
  1193.             $entityInstance $entityManager->find($className$id);
  1194.             $this->filmApplicationService->makeHiddenProject($entityInstance);
  1195.         }
  1196.         $this->addFlash('success''Project(s) have been made private');
  1197.         return $this->redirect($batchActionDto->getReferrerUrl());
  1198.     }
  1199.     public function exportDonorList(AdminContext $contextEntityManagerInterface $em
  1200.     {
  1201.         $entityInstance $context->getEntity()->getInstance(); // get film project
  1202.         $donations $entityInstance->getDonations();
  1203.         
  1204.         $dateValue = (new \DateTime('today'))->format('d-m-y');
  1205.         $csvExporter = new CsvExporter();
  1206.         $csvExporter->exportDonorList($donations$entityInstance->getTitle() .' Donor List -'$dateValue .'.xlsx'$this->getUser());
  1207.     }
  1208.     public function viewProgressReport(AdminContext $contextEntityManagerInterface $em)
  1209.     {
  1210.         $entityInstance $context->getEntity()->getInstance(); // get film project
  1211.         $currentYear = (int) date('Y');
  1212.         if($entityInstance->getCurrentProgressReportYear()) $currentYear = (int)$entityInstance->getCurrentProgressReportYear();
  1213.         $progressReportUrl '/progress-report/'$currentYear .'?projectId=' $entityInstance->getId();
  1214.         return $this->redirect($progressReportUrl);
  1215.     }
  1216.     public function viewLastYearProgressReport(AdminContext $contextEntityManagerInterface $em)
  1217.     {
  1218.         $entityInstance $context->getEntity()->getInstance(); // get film project
  1219.         $lastYear = (int) date('Y') - 1;
  1220.         $progressReportUrl '/progress-report/' $lastYear '?projectId=' $entityInstance->getId();
  1221.         return $this->redirect($progressReportUrl);
  1222.     }
  1223.     public function downloadProgressReport(AdminContext $contextEnvironment $twig nullPdf $pdfEntityManagerInterface $em)
  1224.     {
  1225.         $filmProject $context->getEntity()->getInstance();
  1226.         $progressReportRepo $em->getRepository(FilmProjectProgressReport::class);
  1227.         $progressReport $progressReportRepo->findByYear((int)date("Y"), $filmProject->getId());
  1228.         if (empty($progressReport)) {
  1229.             $this->addFlash('Notice''Progress report is not available.');
  1230.             $filmProjectIndexUrl $this->adminUrlGenerator->setController(FilmProjectCrudController::class)
  1231.                 ->setAction(Action::INDEX)
  1232.                 ->generateUrl();
  1233.             return new RedirectResponse($filmProjectIndexUrl);
  1234.         }
  1235.         $pdfExporter = new PdfExporter($twig$pdf);
  1236.         $pdfExporter->convertProgressReportToPdf($progressReport);
  1237.     }
  1238. }