src/Globals/ClaimManagementBundle/Controller/ClaimFlow/ClaimReportController.php line 525

Open in your IDE?
  1. <?php
  2. namespace Globals\ClaimManagementBundle\Controller\ClaimFlow;
  3. use Globals\ClaimManagementBundle\DependencyInjection\ClaimReportFormHelper;
  4. use Globals\ClaimManagementBundle\Entity\Claim;
  5. use Globals\ClaimManagementBundle\Entity\ClaimReport;
  6. use Globals\ClaimManagementBundle\Service\ClaimNotesProviderService;;
  7. use Globals\CoreBundle\Entity\SystemControlMetadata;
  8. use Globals\ResourceManagementBundle\Service\SLogger;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  10. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  12. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpFoundation\Session\Session;
  17. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  18. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  19. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  20. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  21. use Globals\ResourceManagementBundle\DependencyInjection\WasabiUtils;
  22. use Symfony\Component\Serializer\Serializer;
  23. use Globals\ClaimManagementBundle\Entity\DocumentLibrary;
  24. use Knp\Snappy\Pdf;
  25. /**
  26.  * @Route("/claims/fragments")
  27.  */
  28. class ClaimReportController extends Controller
  29. {
  30.     // Reports - Controller Actions
  31.     /*
  32.      *
  33.      */
  34.     /**
  35.      * Method for Reports Tab - show datatable initial html
  36.      *
  37.      * @Route("/reports/{id}")
  38.      */
  39.     public function claimReportsAction(Claim $claim)
  40.     {
  41.         $viewSwbcUpload false;
  42.         $bShowRefUrl false;
  43.         $em $this->getDoctrine()->getManager();
  44.         $companyId 1;
  45.         if ($claim->getCustomer()) {
  46.             $ClaimCustomer $claim->getCustomer();
  47.             if ($ClaimCustomer->getSubCompany()) {
  48.                 $companyId $ClaimCustomer->getSubCompany()->getId();
  49.             }
  50.         }
  51.         $company $em->getRepository("CompanyManagementBundle:Company")->find($companyId);
  52.         if ($claim) {
  53.             $this->denyAccessUnlessGranted("view_attachments_tab"$claim);
  54.             # If customer if SWBC and environment is IAS only
  55.             if($claim->getCustomer()) {
  56.                 if (in_array($claim->getCustomer()->getId(), array(569657135728))) {
  57.                     $viewSwbcUpload true;
  58.                 }
  59.             }
  60.             $file_manager $this->container->get("app.file_manager");
  61.             $em $this->container->get("doctrine.orm.entity_manager");
  62.             $slog = new SLogger();
  63.             $sql "SELECT id
  64.                 FROM claim_report
  65.                 WHERE 1 = 1
  66.                 AND claim_id = :claim_id
  67.                 AND file_title = :file_title
  68.                 AND document_type_id = 15 ";
  69.             $slog->log("1");
  70.             $dataParams = array();
  71.             $dataParams['claim_id'] = $claim->getId();
  72.             $dataParams['file_title'] = 'Review Reports';
  73.             $stmt $em->getConnection()->prepare($sql);
  74.             try{
  75.                 $stmt->execute($dataParams);
  76.             }catch (\PDOException $e){
  77.                 return new Response("Exception occured while trying to fetch reports");
  78.             }
  79.             $reports $stmt->fetchAll(\PDO::FETCH_ASSOC);
  80.             $path '';
  81.             $fileExists false;
  82.             if($reports) {
  83.                 foreach ($reports as $report) {
  84.                     $path $file_manager->retrieveFilePathByEntity($report['id'], "ReviewReports");
  85.                 }
  86.                 if($path[0] != ''){
  87.                     $fileExists true;
  88.                 }
  89.             }
  90.             $dateOpened $claim->getDateReopened() ? $claim->getDateReopened() : ($claim->getDateOpened() ? $claim->getDateOpened() :$claim->getDateCreated());
  91.             $dateClosed $claim->getDateClosed()? $claim->getDateClosed(): new \DateTime('now');
  92.             if($dateClosed $dateOpened){
  93.                 $dateClosed = new \DateTime('now');
  94.             }
  95.             $difference date_diff($dateOpened,$dateClosed);
  96.             $difference = (array)$difference;
  97.             $daysOpen = array();
  98.             $daysOpen['days'] = $difference['days'];
  99.             $daysOpen['h'] = $difference['h'];
  100.             $daysOpen['m'] = $difference['m'];
  101.             $systemParamService $this->container->get('core.system_parameter_control');
  102.             $systemAdminUsers $systemParamService->getAccessArray('Invoicing_access');
  103.             $bShowInvoiceAccessTab false;
  104.             $user $this->get('security.token_storage')->getToken()->getUser();
  105.             if (!empty($systemAdminUsers) && in_array($user->getId(),$systemAdminUsers)) {
  106.                 $bShowInvoiceAccessTab true;
  107.             }
  108.             if ($claim->getStatus()>=10) {
  109.                 $bShowRefUrl true;
  110.             }
  111.             $assignmentService $this->get('claim.assignment');
  112.             $alertMessageDateExpiryArray $assignmentService->validLicense($claim);
  113.             $alertMessageDateExpiry $alertMessageDateExpiryArray['alertMessageDateExpiry'];
  114.             return $this->render('ClaimManagementBundle:ClaimFlowScreen/Fragments:reports-fragment.html.twig', [
  115.                 'active' => 'report',
  116.                 'claim' => $claim,
  117.                 "claimId" => $claim->getId(),
  118.                 "viewSwbcUpload" => $viewSwbcUpload,
  119.                 "fileExists" => $fileExists,
  120.                 "company" => $company,
  121.                 "daysOpen" => $daysOpen,
  122.                 'bShowInvoiceAccessTab' => $bShowInvoiceAccessTab,
  123.                 'alertMessageDateExpiry' =>$alertMessageDateExpiry,
  124.                 "ShowRefUrl" =>$bShowRefUrl
  125.             ]);
  126.         } else {
  127.             throw new NotFoundHttpException('Could not find this claim!');
  128.         }
  129.     }
  130.     /**
  131.      * Method for Reports Database Ajax Data Action
  132.      *
  133.      * @Route("/reports/search/{id}")
  134.      */
  135.     public function claimReportsDataTablesAction(Request $requestClaim $claim)
  136.     {
  137.         $em $this->getDoctrine();
  138.         if ($claim == null) {
  139.             throw $this->createNotFoundException("Claim does not exist");
  140.         }
  141.         ## Use PaginatorService to return paginated results to DataTables Ajax Request
  142.         $User $this->container->get("security.token_storage")->getToken()->getUser();
  143.         # Array of columns that will be sorted
  144.         $columnsArr = array(
  145.             => "file_title",
  146.             => "document_type_id",
  147.             => "adjusterName",
  148.             => "created_on",
  149.             => "invoice_id"
  150.         );
  151.         $claimId $claim->getId();
  152.         $isAdjuster false;
  153.         $isBranchAdmin false;
  154.         $isBranchUser false;
  155.         $isAdmin false;
  156.         if ($this->isGranted("ROLE_ADJUSTER") == true && ($this->isGranted("ROLE_ADMIN") == false && $this->isGranted("ROLE_EXAMINER") == false)) {
  157.             $isAdjuster true;
  158.         } else if ($this->isGranted("ROLE_BRANCH_ADMIN") == true && $this->isGranted("ROLE_ADJUSTER") == false) {
  159.             $isBranchAdmin true;
  160.         } else if ($this->isGranted("ROLE_BRANCH_USER") == true && $this->isGranted("ROLE_BRANCH_ADMIN") == false) {
  161.             $isBranchUser true;
  162.         } else if ($this->isGranted("ROLE_ADMIN") == true || $this->isGranted("ROLE_EXAMINER") == true) {
  163.             $isAdmin true;
  164.         }
  165.         $sql "SELECT dt.doc_type
  166.                 FROM document_type dt
  167.                 WHERE dt.id = :document_type_id
  168.                 LIMIT 1 ";
  169.         $stmt_sel_document_type $em->getConnection()->prepare($sql);
  170.         $sql "SELECT fms.file_id
  171.                 FROM file_manager_service fms
  172.                 WHERE fms.file_id = :file_id
  173.                 AND fms.entity = 'ClaimReport'
  174.                 LIMIT 1 ";
  175.         $stmt_sel_filemanager $em->getConnection()->prepare($sql);
  176.         $sql "SELECT dlt.document_library_id,
  177.                 dlt.id as document_temp_id,
  178.                 dlt.is_final_doc
  179.                 FROM doc_library_temp dlt
  180.                 WHERE dlt.claim_report_id = :claim_report_id
  181.                 LIMIT 1 ";
  182.         $stmt_sel_doc_lib_temp $em->getConnection()->prepare($sql);
  183.         # Build Query and PDO Parameters that will be passed to PaginatorService class
  184.         $dataParams = array();
  185.         $sql "SELECT cr.id, cr.file_title, cr.document_type_id,
  186.                 CONCAT(sr.first_name, ' ', sr.last_name) AS adjusterName,
  187.                 cr.created_on, cr.invoice_id, " .
  188.             (($isAdjuster)  ?  "CASE WHEN cr.adjuster_id = " $User->getId() . " THEN 1 ELSE 0 END" "1" ) . " AS can_delete
  189.                 FROM claim_report cr
  190.                 LEFT JOIN resource sr
  191.                   ON cr.adjuster_id = sr.id
  192.                 WHERE 1 = 1
  193.                 AND cr.document_type_id <> 15 ";
  194.         if(!$isBranchUser && !$isBranchAdmin && !$isAdmin){
  195.             $sql .= "AND cr.document_type_id <> 9 ";
  196.         }
  197.         # Search By Claim ID
  198.         if ($claimId 0) {
  199.             $sql .= "AND cr.claim_id = :claimId ";
  200.             $dataParams['claimId'] = $claimId;
  201.         }
  202.         if ($isBranchUser || $isBranchAdmin) {
  203.             $CustomerResource $em->getRepository("CustomerManagementBundle:CustomerResource")
  204.                 ->findOneBy(["resource" => $User->getId(),"accessLevel" => 2]);
  205.             if(empty($CustomerResource)) {
  206.                 $sql .= "AND ifnull(cr.invoice_id, 0) <> 0 AND ifnull(cr.invoice_id, 0) <> '' ";
  207.             }
  208.         }
  209.         # build keyword filter, which is requested by datatables ajax when someone types into keyword field
  210.         $keyword_filter "AND (cr.file_title like :keyword OR CONCAT(sr.first_name, ' ', sr.last_name) LIKE :keyword) ";
  211.         # call PaginatorService
  212.         $paginator $this->container->get("resource.paginator_service");
  213.         $retVal $paginator->getPaginationResults($request$sql$dataParams"created_on DESC"$columnsArr""$keyword_filter"keyword""");
  214.         # Manipulate the resultset to be recieved by datatable
  215.         $Results2 $retVal['data'];
  216.         $Results = array();
  217.         foreach ($Results2 as $index => $getResult) {
  218.             $getResult2 $getResult;
  219.             $getResult2['created_on'] = date("m/d/Y"strtotime($getResult['created_on']));
  220.             unset($getResult2['entryDate']);
  221.             $getResult2['doc_type'] = "";
  222.             $DocType = array();
  223.             $sql "SELECT dt.doc_type
  224.                 FROM document_type dt
  225.                 WHERE dt.id = :document_type_id
  226.                 LIMIT 1 ";
  227.             $stmt_sel_document_type->execute([
  228.                 'document_type_id' => $getResult2['document_type_id']
  229.             ]);
  230.             $DocTypes $stmt_sel_document_type->fetchAll(\PDO::FETCH_ASSOC);
  231.             if (count($DocTypes) > 0) {
  232.                 $DocType $DocTypes[0];
  233.                 $getResult2['doc_type'] = $DocType['doc_type'];
  234.             }
  235.             /*$getResult2['has_file'] = 0;
  236.             $sql = "SELECT fms.file_id
  237.                 FROM file_manager_service fms
  238.                 WHERE fms.file_id = :file_id
  239.                 AND fms.entity = 'ClaimReport'
  240.                 LIMIT 1 ";
  241.             $stmt_sel_filemanager->execute([
  242.                 "file_id" => $getResult2['id']
  243.             ]);
  244.             $FileManagers = $stmt_sel_filemanager->fetchAll(\PDO::FETCH_ASSOC);
  245.             if (count($FileManagers) > 0) {
  246.                 $getResult2['has_file'] = 1;
  247.             }*/
  248.             $getResult2['document_library_id'] = "";
  249.             $getResult2['document_temp_id'] = "";
  250.             $DocLibTemp = array();
  251.             $sql "SELECT dlt.document_library_id,
  252.                 dlt.id as document_temp_id,
  253.                 dlt.is_final_doc
  254.                 FROM doc_library_temp dlt
  255.                 WHERE dlt.claim_report_id = :claim_report_id
  256.                 LIMIT 1 ";
  257.             $stmt_sel_doc_lib_temp->execute([
  258.                 'claim_report_id' => $getResult2['id']
  259.             ]);
  260.             $DocLibTemps $stmt_sel_doc_lib_temp->fetchAll(\PDO::FETCH_ASSOC);
  261.             $getResult2['can_edit'] = 0;
  262.             if (count($DocLibTemps) > 0) {
  263.                 $getResult2['can_edit'] = 1;
  264.                 $DocLibTemp $DocLibTemps[0];
  265.                 $getResult2['document_library_id'] = $DocLibTemp['document_library_id'];
  266.                 $getResult2['document_temp_id'] = $DocLibTemp['document_temp_id'];
  267. //                if($DocLibTemp['is_final_doc']){
  268. //                    $getResult2['can_edit'] = 0;
  269. //                }
  270.             }
  271.             $getResult2['can_delete'] = 1;
  272.             if($getResult2['doc_type']=='9 - Invoice' || $getResult2['invoice_id'] <> 0){
  273.                 $getResult2['can_delete'] = 0;
  274.             }
  275.             if($getResult2['document_type_id'] == && strpos($getResult2['file_title'], 'CM') !== false){
  276.                 $creditMemoId $getResult2['invoice_id'];
  277.                 $creditMemo $em->getRepository("InvoiceManagementBundle:InvoiceCreditMemo")->find($creditMemoId);
  278.                 $getResult2['invoice_id'] = $creditMemo->getInvoiceId();
  279.             }
  280.             if($getResult2['doc_type']=='9 - Invoice' || $getResult2['invoice_id'] <> 0){
  281.                 if ($isAdjuster) {
  282.                     if($this->get('claim.helper_service')->showInvoice($getResult2['invoice_id'])) {
  283.                         $Results[$index] = $getResult2;
  284.                     }
  285.                 } else {
  286.                     $Results[$index] = $getResult2;
  287.                 }
  288.             } else {
  289.                 $Results[$index] = $getResult2;
  290.             }
  291.         }
  292.         $retVal['data'] = array_values($Results);
  293.         $retVal['recordsTotal'] = count($Results);
  294.         $retVal['recordsFiltered'] = count($Results);
  295.         return new JsonResponse($retVal);
  296.     }
  297.     /**
  298.      * Method to recieve uploaded file from js upload plugin,
  299.      * saves file to /tmp folder, and saves FileObject
  300.      * info to session, for later use
  301.      *
  302.      * @Route("/report/upload_file")
  303.      */
  304.     public function saveUploadClaimReportAjaxAction(Request $request)
  305.     {
  306.         $slog = new SLogger();
  307.         ini_set("max_execution_time"3600);
  308.         ini_set("max_input_time"3600);
  309.         ini_set("post_max_size"'64M');
  310.         ini_set("upload_max_filesize"'64M');
  311.         $documentType $request->request->get('form')['documentType'];
  312. //        $slog->log("Document Type POG: " . $documentType);
  313.         if (isset($_FILES['files']) && count($_FILES['files']['name']) > 0) {
  314.             # Create Array wit same information as $_FILE object
  315.             $session = new Session();
  316.             foreach ($_FILES['files'] as $key => $value) {
  317.                 $useFile[$key] = $value[0];
  318.             }
  319.             $pathArr pathinfo(strtolower($useFile['name']));
  320.             $useFile['file_ext'] = $pathArr['extension'];
  321. //            $slog->log("Document Size POG: " . $useFile['size']);
  322.             if ($useFile['size'] > 67108864) {  // filesize cannot exceed 64 MB
  323.                 $retVal = array(
  324.                     "result" => "fail",
  325.                     "error" => true,
  326.                     "error_msgs" => ["File cannot be larger than 64 MB"],
  327.                     "files" => [
  328.                         [
  329.                             "name" => "File cannot be larger than 64 MB"
  330.                         ]
  331.                     ]
  332.                 );
  333.                 return new JsonResponse($retVal);
  334.             }
  335.             if($documentType) {
  336.                 /*
  337.                  * Categories 1 through 9 only allow .PDF extensions
  338.                  */
  339.                 if ($documentType <= 9) {
  340.                     # Validate file type
  341.                     $categoryPdf = ["pdf"];
  342.                     if (!in_array($useFile['file_ext'], $categoryPdf)) {
  343.                         $retVal = array(
  344.                             "result" => "fail",
  345.                             "error" => true,
  346.                             "error_msgs" => ["Only PDFs"],
  347.                             "files" => [
  348.                                 [
  349.                                     "name" => "Only PDF file extension type allowed"
  350.                                 ]
  351.                             ]
  352.                         );
  353.                         return new JsonResponse($retVal);
  354.                     }
  355.                     /*
  356.                      * Category 10 with id=10 only allow Array of extensions
  357.                      */
  358.                 } elseif ($documentType == 10) {
  359.                     # Validate file type
  360.                     $categoryPdf = ["pdf"];
  361.                     # NO Validate file types
  362.                     $categoryTen = ["action""apk""app""bat""bin""cmd""com""command""cpl""csh""exe""gadget""inf1""ins""inx",
  363.                         "ipa""isu""job""jse""ksh""lnk""msc""msi""msp""mst""osx""out""paf""pif""prg""ps1""reg""rgs",
  364.                         "run""scr""sct""shb""shs""u3p""vb""vbe""vbs""vbscript""workflow""ws""wsf""wsh",
  365.                         "ACTION""APK""APP""BAT""BIN""CMD""COM""COMMAND""CPL""CSH""EXE""GADGET""INF1""INS""INX""IPA",
  366.                         "ISU""JOB""JSE""KSH""LNK""MSC""MSI""MSP""MST""OSX""OUT""PAF""PIF""PRG""PS1""REG""RGS""RUN",
  367.                         "SCR""SCT""SHB""SHS""U3P""VB""VBE""VBS""VBSCRIPT""WORKFLOW""WS""WSF""WSH"];
  368.                     if (in_array($useFile['file_ext'], $categoryTen) && !in_array($useFile['file_ext'], $categoryPdf)) {
  369.                         $retVal = array(
  370.                             "result" => "fail",
  371.                             "error" => true,
  372.                             "error_msgs" => ["Extension file type is NOT allowed"],
  373.                             "files" => [
  374.                                 [
  375.                                     "name" => "This Extension file type is NOT allowed",
  376.                                 ]
  377.                             ]
  378.                         );
  379.                         return new JsonResponse($retVal);
  380.                     }
  381.                     /*
  382.                      * Category 11 with id=11 only allow .ESX extensions
  383.                      */
  384.                 } elseif ($documentType == 11) {
  385.                     # Validate file type
  386.                     $categoryEsx = ["esx"];
  387.                     if (!in_array($useFile['file_ext'], $categoryEsx)) {
  388.                         $retVal = array(
  389.                             "result" => "fail",
  390.                             "error" => true,
  391.                             "error_msgs" => ["Only ESXs"],
  392.                             "files" => [
  393.                                 [
  394.                                     "name" => "Only ESX file extension type allowed"
  395.                                 ]
  396.                             ]
  397.                         );
  398.                         return new JsonResponse($retVal);
  399.                     }
  400.                 }
  401.             }else{
  402.                 $retVal = array(
  403.                     "result" => "fail",
  404.                     "error" => true,
  405.                     "error_msgs" => ["No Document Type"],
  406.                     "files" => [
  407.                         [
  408.                             "name" => "No Document Type selected"
  409.                         ]
  410.                     ]
  411.                 );
  412.                 return new JsonResponse($retVal);
  413.             }
  414.             $path $useFile['tmp_name'];
  415.             # Save path to new file, also in /tmp folder
  416.             $get_num md5(uniqid());
  417.             $new_file_name is_numeric($get_num) ? round($get_num2) : $get_num;
  418.             $new_file_path "/tmp/" $new_file_name;
  419.             $useFile['new_file_name'] = $new_file_name;
  420.             $useFile['used_by_module'] = "UploadClaimReport";
  421.             $orig_file_name $useFile['name'];
  422.             # Save session with $_FILE object array, including path to new /tmp file
  423.             $claimReportUploadFiles = array();
  424.             if ($session->has("claimreport_upload_files")) {
  425.                 $claimReportUploadFiles $session->get("claimreport_upload_files");
  426.             }
  427.             $claimReportUploadFiles[] = $useFile;
  428.             $session->set("claimreport_upload_files"$claimReportUploadFiles);
  429.             $slog = new SLogger();
  430.             $slog->log("claimReportUploadFiles: ");
  431.             $slog->log($claimReportUploadFiles);
  432.             # Move temporary uploaded file to new file
  433.             move_uploaded_file($path$new_file_path);
  434.         }
  435.         $retVal = [
  436.             "files" => [
  437.                 [
  438.                     "name" => $orig_file_name
  439.                 ]
  440.             ]
  441.         ];
  442.         return new JsonResponse($retVal);
  443.     }
  444.     /**
  445.      * Generates view for "Create Report Document" ajax modal,
  446.      * and uses form builder
  447.      *
  448.      * @Route("/report/create/{claimId}")
  449.      */
  450.     public function addClaimReportAjaxAction(Request $request$claimId)
  451.     {
  452.         # Create Form Builder using Form Builder Helper for this Entity
  453.         $onlyServerSideVal false;
  454.         $em $this->container->get("doctrine.orm.entity_manager");
  455.         $formFactory $this->container->get("form.factory");
  456.         $user $this->container->get("security.token_storage")->getToken()->getUser();
  457.         $ReportFormHelper = new ClaimReportFormHelper($em$formFactory$user$onlyServerSideVal);
  458.         $form $ReportFormHelper->getAddForm();
  459.         # Get Logged In User
  460.         $loggedInUser $this->container->get("security.token_storage")->getToken()->getUser();
  461.         # Set the current Logged In User as the value for the Adjuster Field
  462.         $resource $em->getRepository("ResourceManagementBundle:Resource")->find($loggedInUser->getId());
  463.         $form->get('adjuster')->setData($resource);
  464.         # Reset session for claim report file upload
  465.         $session = new Session();
  466.         $session->remove("claimreport_upload_files");
  467.         $Claim $em->getRepository("ClaimManagementBundle:Claim")->findOneBy([
  468.             "id" => $claimId
  469.         ]);
  470.         $isSplCust='0';
  471.         $claimCustomerID=$Claim->getCustomer()->getId();
  472.         $SplCustomerID $em->getRepository('CoreBundle:SystemControlMetadata')->findOneBy(['cmetaKey' => 'spl_cust_report_upload_allowed']);
  473.         $customerIds explode(','$SplCustomerID instanceof SystemControlMetadata $SplCustomerID->getCmetaValue() : "");
  474.         if(in_array($claimCustomerID,$customerIds)){
  475.             $isSplCust='1';
  476.         }
  477.         //dd($isSplCust);
  478.         return $this->render("ClaimManagementBundle:ClaimFlowScreen/Fragments/modals:add-report-modal.html.twig", [
  479.             "reportForm" => $form->createView(),
  480.             "onlyServerSideVal" => $onlyServerSideVal,
  481.             "claimId" => $claimId,
  482.             "isSplCustomer" => $isSplCust
  483.         ]);
  484.     }
  485.     /**
  486.      * Generates view for "Update Report Document" ajax modal,
  487.      * and uses form builder
  488.      *
  489.      * @Route("/report/edit/{id}")
  490.      */
  491.     public function editClaimReportAjaxAction(Request $requestClaimReport $claim_report)
  492.     {
  493.         # Create Form Builder using Form Builder Helper for this Entity
  494.         $onlyServerSideVal false;
  495.         $em $this->container->get("doctrine.orm.entity_manager");
  496.         $formFactory $this->container->get("form.factory");
  497.         $user $this->container->get("security.token_storage")->getToken()->getUser();
  498.         $ReportFormHelper = new ClaimReportFormHelper($em$formFactory$user$onlyServerSideVal);
  499.         $form $ReportFormHelper->getEditForm($claim_report);
  500.         # Reset session for claim report file upload
  501.         $session = new Session();
  502.         $session->remove("claimreport_upload_files");
  503.         $image_id "";
  504.         $claimId $claim_report->getClaim()->getId();
  505.         $FileManager $em->getRepository("ResourceManagementBundle:FileManager")->loadByFileIDEntity($claim_report->getId(), "ClaimReport"false$claimId);
  506.         if ($FileManager) {
  507.             $image_id $FileManager->getId();
  508.         }
  509.         return $this->render("ClaimManagementBundle:ClaimFlowScreen/Fragments/modals:edit-report-modal.html.twig", [
  510.             "reportForm" => $form->createView(),
  511.             "onlyServerSideVal" => $onlyServerSideVal,
  512.             "ClaimReport" => $claim_report,
  513.             "id" => $claim_report->getId(),
  514.             "image_id" => $image_id
  515.         ]);
  516.     }
  517.     /**
  518.      * Update Report Document - ajax action,
  519.      * saves fields, and handles saving of uploaded file
  520.      *
  521.      * @Route("/report/save_edit/{id}")
  522.      */
  523.     public function saveUpdateClaimReportAjaxAction(Request $requestClaimReport $ClaimReport)
  524.     {
  525.         $em $this->container->get("doctrine.orm.entity_manager");
  526.         # Retrieve Form Builder to validate
  527.         $formFactory $this->container->get("form.factory");
  528.         $user $this->container->get("security.token_storage")->getToken()->getUser();
  529.         $ReportFormHelper = new ClaimReportFormHelper($em$formFactory$userfalse);
  530.         $form $ReportFormHelper->getEditForm($ClaimReport);
  531.         # Handle the request from the Form Builder
  532.         $form->handleRequest($request);
  533.         $ClaimReport $form->getData();
  534.         if ($form->isValid()) {
  535.             $session = new Session();
  536.             $claimReportUploadFiles $session->get("claimreport_upload_files");
  537.             foreach ($claimReportUploadFiles as $i => $claimreport_upload_file) {
  538.                 # Update File Upload Fields
  539.                 $ClaimReport->setFileSize($claimreport_upload_file['size']);
  540.                 $ClaimReport->setExt($claimreport_upload_file['file_ext']);
  541.                 $em->persist($ClaimReport);
  542.                 break;
  543.             }
  544.             # Persist Document
  545.             $em->flush();
  546.             # Save Uploaded File using File Manager Service
  547.             if (count($claimReportUploadFiles) > 0) {
  548.                 $claimId $ClaimReport->getClaim()->getId();
  549.                 $file_manager $this->container->get("app.file_manager");
  550.                 $file_manager->saveFile($claimReportUploadFiles[0], $ClaimReport->getId(), "ClaimReport"false$claimId);
  551.             }
  552.             $retVal = array(
  553.                 "status" => "success",
  554.                 "error_msgs" => []
  555.             );
  556.             return new JsonResponse($retVal);
  557.         } else {  // if form not valid
  558.             # Send back errors to client
  559.             $data = array();
  560.             $errors2 = array();
  561.             $errors $this->get("validator")->validate($ClaimReport);
  562.             if (count($errors) > 0) {
  563.                 $data = [
  564.                     "errors" => array()
  565.                 ];
  566.                 foreach ($errors as $error) {
  567.                     $nextError = array();
  568.                     $nextError['id'] = $error->getPropertyPath();
  569.                     $nextError['text'] = $error->getMessage();
  570.                     $data['errors'][] = $nextError;
  571.                 }
  572.             }
  573.             $retVal = array(
  574.                 "result" => "fail",
  575.                 "error_msgs" => $errors2,
  576.                 "error" => true,
  577.                 "data" => $data
  578.             );
  579.             return new JsonResponse($retVal);
  580.         }
  581.     }
  582.     /**
  583.      * Creates Report Document - ajax action,
  584.      * saves fields, and handles saving of uploaded file
  585.      *
  586.      * @Route("/report/save_create/{claimId}")
  587.      */
  588.     public function saveAddClaimReportAjaxAction(Request $request$claimId)
  589.     {
  590.         $em $this->container->get("doctrine.orm.entity_manager");
  591.         ini_set("max_execution_time"3600);
  592.         ini_set("max_input_time"3600);
  593.         ini_set("post_max_size"'64M');
  594.         ini_set("upload_max_filesize"'64M');
  595.         # Retrieve Form Builder to validate
  596.         $formFactory $this->container->get("form.factory");
  597.         $username $this->container->get("security.token_storage")->getToken()->getUsername();
  598.         $Resource $em->getRepository("ResourceManagementBundle:Resource")->findOneBy(['username' => $username]);
  599.         $ReportFormHelper = new ClaimReportFormHelper($em$formFactory$Resourcefalse);
  600.         $form $ReportFormHelper->getAddForm();
  601.         # Handle the request from the Form Builder
  602.         $form->handleRequest($request);
  603.         $ClaimReport $form->getData();
  604.         //$ClaimReport = $em->getRepository("ClaimManagementBundle:ClaimReport")->find($ClaimReport->getId());
  605.         if ($form->isValid()) {
  606.             # Check if session with file exists
  607.             $session = new Session();
  608.             if (!$session->has("claimreport_upload_files")) {
  609.                 $data = array();
  610.                 $errors2 = array();
  611.                 $data = [
  612.                     "errors" => array()
  613.                 ];
  614.                 $nextError = array();
  615.                 $nextError['id2'] = "uploaded_file_reportadd";
  616.                 $nextError['id'] = "documentType";
  617.                 $nextError['text'] = "You did not upload a document.";
  618.                 $data['errors'][] = $nextError;
  619.                 $retVal = array(
  620.                     "result" => "fail",
  621.                     "error_msgs" => $errors2,
  622.                     "error" => true,
  623.                     "data" => $data
  624.                 );
  625.                 return new JsonResponse($retVal);
  626.             }
  627.             $fileTitle2 $ClaimReport->getFileTitle();
  628.             $claimReportUploadFiles $session->get("claimreport_upload_files");
  629.             $claim $em->getRepository("ClaimManagementBundle:Claim")->find($claimId);
  630.             //foreach ($claimReportUploadFiles as $i => $claimreport_upload_file) {
  631.             $i 0;
  632.             $claimreport_upload_file $claimReportUploadFiles[$i];
  633.             if($fileTitle2 == ""){
  634.                 $fileTitle str_replace(".".$claimreport_upload_file['file_ext'],"",$claimreport_upload_file['name']);
  635.             }else {
  636.                 $fileTitle $fileTitle2;
  637.             }
  638.             $ClaimReport2 = new ClaimReport();
  639.             $ClaimReport2->setDocumentType($ClaimReport->getDocumentType());
  640.             $ClaimReport2->setAdjuster($ClaimReport->getAdjuster());
  641.             if ($i 0) {
  642.                 $fileTitle .= " ($i)";
  643.             }
  644.             $ClaimReport2->setFileTitle($fileTitle);
  645.             $ClaimReport2->setFileSize($claimreport_upload_file['size']);
  646.             $ClaimReport2->setExt($claimreport_upload_file['file_ext']);
  647.             # Save Other Claim Report Fields
  648.             $ClaimReport2->setClaim($claim);
  649.             $ClaimReport2->setStatus(0);
  650.             $ClaimReport2->setCreatedOn(new \DateTime());
  651.             $em->persist($ClaimReport2);
  652.             $em->flush();
  653.             # Log File Note that Report was created
  654.             $tokenStorage $this->container->get("security.token_storage");
  655.             $claim_note_service = new ClaimNotesProviderService($em$tokenStorage);
  656.             //$comment = "Claim Report '" .$ClaimReport2->getFileTitle()."' has been created with ID: " . $ClaimReport2->getId();
  657.             $idNote $ClaimReport2->getId();
  658.             $documentType =  $ClaimReport2->getDocumentType();
  659.             $comment $ClaimReport2->getFileTitle()." ".$idNote;
  660.             $claim_note_service->addClaimNoteFromAttach($claim$comment$documentTypefalse,$ClaimReport2);
  661.             # Save Uploaded File using File Manager Service
  662.             $claimId $ClaimReport2->getClaim()->getId();
  663.             $file_manager $this->container->get("app.file_manager");
  664.             $fileSaveError false;
  665.             $validUpload $file_manager->saveFile($claimreport_upload_file$ClaimReport2->getId(), "ClaimReport"false$claimId);
  666.             /*
  667.              * Symbility Upload here
  668.              *
  669.              */
  670.             $symOutbound $this->get('integration.symbility.outbound');
  671.             /** @var Claim $claim */
  672.             if($claim->getAssignmentId()){
  673.                 $symOutbound->pushDocument($claim->getClaimNumber(), [
  674.                     "document_name"     => $ClaimReport2->getFileTitle() . "." $claimreport_upload_file['file_ext'],
  675.                     "document_path"     => "/tmp/".$claimreport_upload_file['new_file_name'],
  676.                     "document_bytes"    => file_get_contents("/tmp/".$claimreport_upload_file['new_file_name']),
  677.                     "document_sender"   => false
  678.                 ],$claim->getAssignmentId());
  679.             }
  680.             if ($validUpload == true) {
  681.                 if ($documentType <> '9 - Policy Information' && $documentType <> '10 - Other (NO MERGE)'
  682.                     && $documentType <> '11 - ESX (NO MERGE)' && $documentType <> '12 - Fast Draft Field Report') {
  683.                     //advance report due date
  684.                     $daysToDiary $claim->getCustomer()->getDaysToDiary();
  685.                     /** @var \DateTime $reportDueDate */
  686.                     $reportDueDate $claim->getReportDueDate();
  687.                     $slog = new SLogger();
  688.                     if ($reportDueDate != '') {
  689.                         $modifiedDate $reportDueDate->modify("+$daysToDiary day");
  690.                         $claim->setReportDueDate(new \DateTime($modifiedDate->format("Y-m-d H:i:s")));
  691.                     }
  692.                     $em->persist($claim);
  693.                     try {
  694.                         $em->flush();
  695.                         $slog->log("IT FLUSHED");
  696.                     } catch (\Exception $e) {
  697.                         $slog->log("DIDN'T FLUSH, WATCH MIRA " $e->getMessage());
  698.                     }
  699.                 }
  700.                 $retVal = array(
  701.                     "status" => "success",
  702.                     "error_msgs" => ""
  703.                 );
  704.             } else {  // error saving file
  705.                 $ClaimReport2 $em->getRepository("ClaimManagementBundle:ClaimReport")->find($ClaimReport2->getId());
  706.                 $em->remove($ClaimReport2);
  707.                 $em->flush();
  708.                 $retVal = array(
  709.                     "status" => "error",
  710.                     "error_msgs" => ["Data connection error. Unable to save file."]
  711.                 );
  712.             }
  713.             return new JsonResponse($retVal);
  714.         } else {  // if form not valid
  715.             # Send back errors to client
  716.             $data = array();
  717.             $errors2 = array();
  718.             $errors $this->get("validator")->validate($ClaimReport);
  719.             if (count($errors) > 0) {
  720.                 $data = [
  721.                     "errors" => array()
  722.                 ];
  723.                 foreach ($errors as $error) {
  724.                     $nextError = array();
  725.                     $nextError['id'] = $error->getPropertyPath();
  726.                     $nextError['text'] = $error->getMessage();
  727.                     $data['errors'][] = $nextError;
  728.                 }
  729.             }
  730.             $retVal = array(
  731.                 "result" => "fail",
  732.                 "error_msgs" => $errors2,
  733.                 "error" => true,
  734.                 "data" => $data
  735.             );
  736.             return new JsonResponse($retVal);
  737.         }
  738.     }
  739.     /**
  740.      * @Route("/report/delete")
  741.      * @Method(methods={"POST"})
  742.      */
  743.     public function deleteClaimReportAction(Request $request)
  744.     {
  745.         $em $this->container->get("doctrine.orm.entity_manager");
  746.         $id intval($request->request->get("id"));
  747.         $ClaimReport $em->getRepository("ClaimManagementBundle:ClaimReport")->find($id);
  748.         $this->denyAccessUnlessGranted("delete_diary"$ClaimReport);
  749.         if ($ClaimReport) {
  750.             # Validate that Claim is not closed
  751.             if ($ClaimReport->getClaim()->getStatus() == 30) {  // if Claim is Closed
  752.                 # return message, can't delete report
  753.                 $retVal = array(
  754.                     "error" => true,
  755.                     "error_msgs" => ["This claim is already closed. You can't delete the Report."]
  756.                 );
  757.                 return new JsonResponse($retVal);
  758.             }
  759.             #### Don't need this validation. We can't delete the reports if they are associated to an invoice. Already taken care through FE validation.
  760.             # Validate claim does not have Invoice
  761.             /*$Invoice = $em->getRepository("InvoiceManagementBundle:Invoice")->findOneBy([
  762.                 "claim" => $ClaimReport->getClaim()
  763.             ]);
  764.             if ($Invoice) {  // if claim already has an Invoice
  765.                 # return message, can't delete report
  766.                 $retVal = array(
  767.                     "error" => true,
  768.                     "error_msgs" => ["This claim has already been invoiced. You can't delete the Report."]
  769.                 );
  770.                 return new JsonResponse($retVal);
  771.             }*/
  772.             # Log Rev Note that Report was deleted
  773.             $tokenStorage $this->container->get("security.token_storage");
  774.             $claim_note_service = new ClaimNotesProviderService($em$tokenStorage);
  775.             $comment "Claim Report '".$ClaimReport->getFileTitle()."' has been deleted, with ID: " $id;
  776.             $claim_note_service->addClaimNote($ClaimReport->getClaim(), $commentfalse62);
  777.             #Delete the corresponding record from document temp if exists
  778.             $sql "DELETE FROM doc_library_temp WHERE claim_report_id = :claim_report_id";
  779.             $dataParams = array();
  780.             $dataParams['claim_report_id'] = $ClaimReport->getId();
  781.             $stmt $em->getConnection()->prepare($sql);
  782.             $stmt->execute($dataParams);
  783.             $claimReportFile $em->getRepository("ResourceManagementBundle:FileManager")->findOneBy([
  784.                 "fileId" => $ClaimReport->getId()
  785.             ]);
  786.             $em->remove($ClaimReport);
  787.             if(!empty($claimReportFile))
  788.                 $em->remove($claimReportFile);
  789.             $em->flush();
  790.             # Delete file with File Manager Service
  791.             $claimId $ClaimReport->getClaim()->getId();
  792.             $this->container->get("app.file_manager")->deleteFileByEntity($id"ClaimReport"false$claimId);
  793.             /*$retVal = array(
  794.                 "status" => "success",
  795.                 "error_msgs" => []
  796.             );*/
  797.             $retVal = array(
  798.                 "error" => false,
  799.                 "error_msgs" => []
  800.             );
  801.             return new JsonResponse($retVal);
  802.         } else {
  803.             $retVal = array(
  804.                 "error" => true,
  805.                 "error_msgs" => ["Claim Report Record does not exist."]
  806.             );
  807.             return new JsonResponse($retVal);
  808.         }
  809.     }
  810.     /**
  811.      * @Route("/report/view/{entity}/{fileId}")
  812.      */
  813.     public function viewDocumentByEntityAndID($entity$fileId)
  814.     {
  815.         $file_manager $this->container->get("app.file_manager");
  816.         $em $this->container->get("doctrine.orm.entity_manager");
  817.         $ClaimReport $em->getRepository("ClaimManagementBundle:ClaimReport")->find($fileId);
  818.         if($ClaimReport->getDocumentType()->getId()==14)
  819.             $entity 'PhotoSheetZip';
  820.         $path $file_manager->retrieveFilePathByEntity($fileId$entity1);
  821.         if($path[0] != '')
  822.             return new Response($path[0], $path[1], $path[2]);
  823.         else
  824.             return new Response("No File Found!");
  825.     }
  826.     /**
  827.      * @Route("/report/createzip/{claim_id}")
  828.      */
  829.     public function createzip(Request $request,$claim_id)
  830.     {
  831.         $file_manager $this->container->get("app.file_manager");
  832.         $em $this->container->get("doctrine.orm.entity_manager");
  833.         $ClaimReport $em->getRepository("ClaimManagementBundle:ClaimReport")->find($claim_id);
  834.         $fileManagerAws $this->container->get("app.wasabi_manager");
  835.         $strphotoidArray explode(",",$request->request->get('strreportid'));
  836.         $env 1000;
  837.         $kernel $this->container->get("kernel");
  838.         $fileNameRand $fileManagerAws->random_strings(10);
  839.         $new_file_path $kernel->getRootDir() . "/../web/" $env "/PhotoSheet/".$fileNameRand.".zip";
  840.         $zipStatus '';
  841.         for($i=0;$i<=count($strphotoidArray);$i++){
  842.             if($strphotoidArray[$i]>0){
  843.                 $fileManagerObj $this->getDoctrine()->getRepository('ResourceManagementBundle:FileManager')->findOneBy(['fileId'=>$strphotoidArray[$i]]);
  844.                 $zipStatus =  $fileManagerAws->createZipFile($new_file_path,$fileManagerObj->getLegacyPath());
  845.             }
  846.         }
  847.         if($zipStatus=='yesZip') {
  848.             $env $kernel->getEnvironment();
  849.             if ($env == 1005)
  850.                 $env 1000;
  851.             $uri $request->getScheme() . '://' $request->getHttpHost() . "/" $env "/PhotoSheet/" $fileNameRand ".zip";
  852.             $retVal = array(
  853.                 "uri" => $uri,
  854.                 "status" => 'yesZip',
  855.                 "file_name" => $fileNameRand
  856.             );
  857.         }else{
  858.             $retVal = array(
  859.                 "status" => 'noZip'
  860.             );
  861.         }
  862.         return new JsonResponse($retVal);
  863.     }
  864.     /**
  865.      * @Route("/report/deletecreatezip")
  866.      */
  867.     public function deletecreatezip(Request $request)
  868.     {
  869.         $file_name $request->request->get('file_name');
  870.         $kernel $this->container->get("kernel");
  871.         $env$kernel->getEnvironment();
  872.         if($env==1005)
  873.             $env 1000;
  874.         $new_file_path $kernel->getRootDir() . "/../web/" $env "/PhotoSheet/".$file_name.".zip";
  875.         unlink($new_file_path);
  876.         $retVal = array(
  877.             "delete" => 'yes'
  878.         );
  879.         return new JsonResponse($retVal);
  880.     }
  881.     /**
  882.      * @Route("/report/view/{claimId}")
  883.      */
  884.     public function viewStackedPDFReport(Request $request$claimId)
  885.     {
  886.         $file_manager $this->container->get("app.file_manager");
  887.         $em $this->container->get("doctrine.orm.entity_manager");
  888.         $slog = new SLogger();
  889.         $sql "SELECT id
  890.                 FROM claim_report
  891.                 WHERE invoice_id = :invoice_id
  892.                 AND claim_id = :claim_id
  893.                 AND file_title = :file_title
  894.                 AND document_type_id = 15 ";
  895.         $slog->log("1");
  896.         $dataParams = array();
  897.         $dataParams['invoice_id'] = 0;
  898.         $dataParams['claim_id'] = $claimId;
  899.         $dataParams['file_title'] = 'Review Reports';
  900.         $stmt $em->getConnection()->prepare($sql);
  901.         try{
  902.             $stmt->execute($dataParams);
  903.         }catch (\PDOException $e){
  904.             return new Response("Exception occured while trying to fetch reports");
  905.         }
  906.         $reports $stmt->fetchAll(\PDO::FETCH_ASSOC);
  907.         $path '';
  908.         if($reports) {
  909.             foreach ($reports as $report) {
  910.                 $path $file_manager->retrieveFilePathByEntity($report['id'], "ReviewReports");
  911.             }
  912.             if($path[0] != '')
  913.                 return new Response($path[0], $path[1], $path[2]);
  914.             else
  915.                 return new Response("No File Found!");
  916.         }else{
  917.             return new Response("No File Found!");
  918.         }
  919.     }
  920.     /**
  921.      * Generates view for "Edit Report title of Document" ajax modal,
  922.      * and uses form builder
  923.      *
  924.      * @Route("/report/edittitle/")
  925.      */
  926.     public function editClaimReportTitleAjaxAction(Request $request)
  927.     {
  928.         $em $this->container->get("doctrine.orm.entity_manager");
  929.         $rowid intval($request->get("rowId"));
  930.         //echo $rowid;
  931.         $onlyServerSideVal true;
  932.         $formFactory $this->container->get("form.factory");
  933.         $user $this->container->get("security.token_storage")->getToken()->getUser();
  934.         $ReportFormHelper = new ClaimReportFormHelper($em$formFactory$user$onlyServerSideVal);
  935.         //$form = $ReportFormHelper->getEditDocTitle($claim_report);
  936.         $ClaimReport $em->getRepository("ClaimManagementBundle:ClaimReport")->find($rowid);
  937.         //dd($ClaimReport);
  938.         if ($ClaimReport) {
  939.             $form $ReportFormHelper->getEditDocTitle($ClaimReport);
  940.             # Validate that Claim is not closed
  941.             if ($ClaimReport->getClaim()->getStatus() == 30) {  // if Claim is Closed
  942.                 # return message, can't Edit report title
  943.                 $retVal = array(
  944.                     "error" => true,
  945.                     "error_msgs" => ["This claim is already closed. You can't edit the Report title."]
  946.                 );
  947.                 return new JsonResponse($retVal);
  948.             }
  949.         }
  950.         return $this->render("ClaimManagementBundle:ClaimFlowScreen/Fragments/modals:edit-report-title-modal.html.twig", [
  951.             "reportForm" => $form->createView(),
  952.             "onlyServerSideVal" => $onlyServerSideVal,
  953.             "rowId" => $rowid
  954.         ]);
  955.     }
  956.     /**
  957.      * Update Report Document Title - ajax action,
  958.      * @Route("/report/saveedittitle/")
  959.      */
  960.     public function saveUpdateClaimReportTitleAjaxAction(Request $request)
  961.     {
  962.         $em $this->container->get("doctrine.orm.entity_manager");
  963.         $rowid intval($request->request->get("rowid"));
  964.         $FrmTitle=$request->request->get('formTitle');
  965.         //dd($rowid);
  966.         $ClaimReport $em->getRepository("ClaimManagementBundle:ClaimReport")->find($rowid);
  967.         $ClaimReport->setFileTitle($FrmTitle);
  968.         $em->persist($ClaimReport);
  969.         $em->flush();
  970.         # Log Rev Note that Report was deleted
  971.         $tokenStorage $this->container->get("security.token_storage");
  972.         $claim_note_service = new ClaimNotesProviderService($em$tokenStorage);
  973.         $comment "Claim Report  attachment Title '".$ClaimReport->getFileTitle()."' has been updated.";
  974.         $claim_note_service->addClaimNote($ClaimReport->getClaim(), $commentfalse52);
  975.         $retVal = array(
  976.             "status" => "success",
  977.             "error_msgs" => []
  978.         );
  979.         return new JsonResponse($retVal);
  980.     }
  981.     /**
  982.      * Generates view for "Edit Report title of Document" ajax modal,
  983.      * and uses form builder
  984.      *
  985.      * @Route("/report/openpdfmodel/{claim_id}")
  986.      */
  987.     public function openPdfModelAjaxAction(Request $request)
  988.     {
  989.         $em $this->container->get("doctrine.orm.entity_manager");
  990.         $claimId $request->get('claim_id');
  991.         $rowId=$request->get("strpdfid") ;
  992.         $rowId=rtrim($rowId,',');
  993.         $onlyServerSideVal true;
  994.         $user $this->container->get("security.token_storage")->getToken()->getUser();
  995.         $sql "SELECT *
  996.                 FROM claim_report
  997.                 WHERE ifnull(invoice_id,0) = 0 ";
  998.         $sql .= "AND id IN (" $rowId ") ";
  999.         $dataParams = array();
  1000.         //$dataParams['invoice_id'] = $invoice['id'];
  1001.         //$dataParams['claim_id'] = $claim_id;
  1002.         $stmt $em->getConnection()->prepare($sql);
  1003.         $stmt->execute($dataParams);
  1004.         $reports $stmt->fetchAll(\PDO::FETCH_ASSOC);
  1005.         //dd($reports);
  1006.         return $this->render("ClaimManagementBundle:ClaimFlowScreen/Fragments/modals:single-pdf-modal.html.twig", [
  1007.             "onlyServerSideVal" => $onlyServerSideVal,
  1008.             "rowId" => $rowId,
  1009.             "reports" => $reports,
  1010.             "claimId" => $claimId
  1011.         ]);
  1012.     }
  1013.     /**
  1014.      * @Route("/report/createsinglepdf/{claim_id}")
  1015.      */
  1016.     public function createsinglepdf(Request $request,$claim_id)
  1017.     {
  1018.         $PdfName=$request->get("strpdfname") ;
  1019.         $rowId=$request->get("strpdfid") ;
  1020.         $rowId=rtrim($rowId,',');
  1021.         $em $this->container->get("doctrine.orm.entity_manager");
  1022.         $file_manager $this->container->get("app.file_manager");
  1023.         $kernel $this->container->get("kernel");
  1024.         $env$kernel->getEnvironment();
  1025.         $env 1000;
  1026.         $sql "SELECT *
  1027.                 FROM claim_report
  1028.                 WHERE ifnull(invoice_id,0) = 0 ";
  1029.         $sql .= "AND id IN (" $rowId ") ";
  1030.         $dataParams = array();
  1031.         //$dataParams['invoice_id'] = $invoice['id'];
  1032.         //$dataParams['claim_id'] = $claim_id;
  1033.         $stmt $em->getConnection()->prepare($sql);
  1034.         $stmt->execute($dataParams);
  1035.         $reports $stmt->fetchAll(\PDO::FETCH_ASSOC);
  1036.         $array explode(','$rowId);
  1037.         $finalReport=[];
  1038.         for($i=0;$i<count($array);$i++){
  1039.             for($j=0$j<count($reports);$j++){
  1040.                 if($array[$i]==$reports[$j]['id']){
  1041.                     $finalReport[$i]= $reports[$j];
  1042.                 }
  1043.             }
  1044.         }
  1045.         $file_str '';
  1046.         # Skip if the invoice if count of attchments is greater than 50
  1047.         if (count($reports) <= 50) {
  1048.             $FilePathArray=[];
  1049.             foreach ($finalReport as $getReport) {
  1050.                 $get_num md5(uniqid());
  1051.                 $filePath $kernel->getRootDir() . "/../web/" $env "/SinglePdf/" $get_num.".pdf";
  1052.                 $FilePathArray[]=$filePath;
  1053.                 $retVal $file_manager->retrieveFilePathByEntity($getReport['id'], "ClaimReport");
  1054.                 $fh fopen($filePath'w');
  1055.                 if ($file_str) {
  1056.                     $file_str .= " " $filePath;
  1057.                 } else {
  1058.                     $file_str $filePath;
  1059.                 }
  1060.                 //print_r($retVal);
  1061.                 fwrite($fh$retVal[0]);
  1062.                 fclose($fh);
  1063.             }
  1064.             //echo "<pre>";
  1065.             //print_r($file_str);
  1066.             //die;
  1067.             /*Build a new PDF for stacking */
  1068.             $get_num_final md5(uniqid());
  1069.             $invfilePath $kernel->getRootDir() . "/../web/" $env "/SinglePdf/" $PdfName.".pdf";
  1070.             //$shell_output = shell_exec("pdftk " . $file_str . " cat output " . $invfilePath . " 2>&1");
  1071.             $shell_output shell_exec("qpdf --empty --pages " $file_str " -- " $invfilePath" 2>&1");
  1072.             $FilePathArray[]=$invfilePath;
  1073.         }
  1074.         if(file_exists($invfilePath) && filesize($invfilePath) > 0)
  1075.         {
  1076.             $content file_get_contents($invfilePath);
  1077.             //$fh = fopen($filePath, 'r');
  1078.             //$content = fread($fh, filesize($filePath));
  1079.             //fclose($fh);
  1080.         }
  1081.         else
  1082.         {
  1083.             $content '';
  1084.         }
  1085.         #Save the file into database
  1086.         $user $this->get('security.token_storage')->getToken()->getUser();
  1087.         $claim $em->getRepository("ClaimManagementBundle:Claim")->find($claim_id);
  1088.         $docType$em->getRepository("ClaimManagementBundle:DocumentType")->find(13);
  1089.         $Resource $em->getRepository("ResourceManagementBundle:Resource")->findOneBy(['id' => $user->getId()]);
  1090.         $ClaimReport = new ClaimReport();
  1091.         $ClaimReport->setDocumentType($docType);
  1092.         $ClaimReport->setAdjuster($Resource);
  1093.         $ClaimReport->setFileTitle($PdfName);
  1094.         $ClaimReport->setFileSize(filesize($invfilePath));
  1095.         $ClaimReport->setExt('pdf');
  1096.         # Save Other Claim Report Fields
  1097.         $ClaimReport->setClaim($claim);
  1098.         $ClaimReport->setStatus(0);
  1099.         $ClaimReport->setCreatedOn(new \DateTime());
  1100.         $em->persist($ClaimReport);
  1101.         $em->flush();
  1102.         # Save Uploaded File using File Manager Service
  1103.         $claimId $ClaimReport->getClaim()->getId();
  1104.         $file_manager $this->container->get("app.file_manager");
  1105.         $claimreport_upload_file=[];
  1106.         $claimreport_upload_file['used_by_module']="UploadClaimReport";
  1107.         $claimreport_upload_file['file_ext']="pdf";
  1108.         $claimreport_upload_file['type']="application/pdf";
  1109.         $claimreport_upload_file['new_file_name']=$PdfName;
  1110.         $claimreport_upload_file['name']=$PdfName;
  1111.         $claimreport_upload_file['new_file_path']=$invfilePath;
  1112.         $validUpload $file_manager->saveFile($claimreport_upload_file$ClaimReport->getId(), "ClaimReport"false$claimId,'','mergepdf');
  1113.         #unlink the files
  1114.         foreach ($FilePathArray as $pathval){
  1115.             unlink($pathval);
  1116.         }
  1117.         return new Response (
  1118.             $content,
  1119.             200,
  1120.             [
  1121.                 'Content-Type' => 'application/pdf',
  1122.                 'Content-Disposition' => 'attachment; filename="' basename($PdfName.'.pdf') . '"',
  1123.                 "Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT",
  1124.                 "Cache-Control: no-store, no-cache, must-revalidate, max-age=0",
  1125.                 "Cache-Control: post-check=0, pre-check=0",
  1126.                 "Pragma: no-cache"
  1127.             ]
  1128.         );
  1129.     }
  1130. }