src/Globals/ClaimManagementBundle/Controller/ClaimIntakeFragmentsController.php line 586

Open in your IDE?
  1. <?php
  2. namespace Globals\ClaimManagementBundle\Controller;
  3. use Globals\ResourceManagementBundle\Entity\Resource;
  4. use Globals\ResourceManagementBundle\Entity\ResourceDashboard;
  5. use Globals\ResourceManagementBundle\Service\CarrierUtils;
  6. use Globals\ResourceManagementBundle\Service\SLogger;
  7. use Globals\ResourceManagementBundle\Twig\UCFirstAll;
  8. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Globals\ClaimManagementBundle\Entity\Claim;
  14. use Globals\ClaimManagementBundle\Entity\ClaimStatus;
  15. /**
  16.  * @Route("/administration/manage")
  17.  */
  18. class ClaimIntakeFragmentsController extends Controller
  19. {
  20.     private $user null;
  21.     /**
  22.      * @var array
  23.      */
  24.     private $loss_type_map = [
  25.         'AIR CONDITIONING VESSEL' =>    100,
  26.         'AIRCRAFT-DAMAGE BY' =>    123,
  27.         'All Other Physical Damage' =>    100,
  28.         'BI' =>    2,
  29.         'BOP-LOSS OF RENTS' =>    100,
  30.         'BUILDING' =>    95,
  31.         'BUILDING AND CONTENTS' =>    95,
  32.         'Burglary/theft/robbery-money or securities' =>    124,
  33.         'Business Income' =>    100,
  34.         'Business Personal Property' =>    100,
  35.         'Chubb Fire – Lithium Battery' =>    6,
  36.         'COLLAPSE' =>    104,
  37.         'CONSTRUCTION DEFECTS' =>    96,
  38.         'CONTENTS' =>    100,
  39.         'CPL - ANIMAL BITE' =>    96,
  40.         'CPL - BODILY INJURY' =>    96,
  41.         'CPL - PROPERTY DMG' =>    95,
  42.         'CPL-CARE OR CUSTDY OR CTRL' =>    95,
  43.         'CYBER CRIME' =>    100,
  44.         'Cyber Liability' =>    96,
  45.         'DAMAGE UNKNOWN' =>    101,
  46.         'DENIAL' =>    100,
  47.         'Denied/Do No Report' =>    100,
  48.         'Diving Board Liab' =>    96,
  49.         'EARTH MOVEMENT/ SETTLEMENT/ RESULTANT CRACKING' =>    165,
  50.         'EARTHQUAKE' =>    165,
  51.         'ELECTRICAL OR PWR SURGE' =>    100,
  52.         'EMPLOYEE DISHONESTY' =>    100,
  53.         'EQUIPMENT BREAKDOWN' =>    163,
  54.         'EXPLOSION' =>    126,
  55.         'EXTRA CONTRACTUAL' =>    100,
  56.         'FALLING OBJECTS' =>    161,
  57.         'FIRE' =>    6,
  58.         'FIRE LEGAL LIABILITY' =>    96,
  59.         'FLOOD' =>    98,
  60.         'FREEZING - ICE' =>    7,
  61.         'GLASS - HOMEOWNERS' =>    113,
  62.         'GOLF CART LIABILITY' =>    96,
  63.         'HAIL' =>    147,
  64.         'HURRICANE' =>    20,
  65.         'IDENTITY THEFT' =>    100,
  66.         'LEAD LIABILITY    ' =>100,
  67.         'Liability - All Other' =>    96,
  68.         'LIGHTNING' =>    12,
  69.         'LOSS OF WAGES' =>    100,
  70.         'MED-PAY' =>    100,
  71.         'MISC. - ALL RISK' =>    100,
  72.         'MOLD' =>    100,
  73.         'MONEY/CURRENCY/BANK NOTES/CKS' =>    100,
  74.         'MYSTERIOUS DISAPPEAR' =>    15,
  75.         'NO INJURIES' =>    100,
  76.         'NOC' =>    100,
  77.         'OTHER' =>    100,
  78.         'OTHER STRUCTURES' =>    100,
  79.         'PERS INJ PROT OR (PIP)' =>    100,
  80.         'PERSONAL INJURY HO' =>    100,
  81.         'PROPERTY' =>    95,
  82.         'PROPERTY DAMAGE' =>    95,
  83.         'Pypestream Other' =>    100,
  84.         'RIOT OR CIVIL COMMOTION' =>100,
  85.         'Rodent/Vermin' =>    117,
  86.         'Service Line Coverage' =>    100,
  87.         'SEWER  OR  SEWAGE' =>    134,
  88.         'SMOKE' =>    128,
  89.         'STO - Burg, Theft & Rob - Money/Securities' =>    15,
  90.         'STO - Burglary - Outside' =>    15,
  91.         'STO - Burglary/theft/robbery – other' =>    15,
  92.         'STO - Earthquake' =>    165,
  93.         'STO - Fire and Lightning' =>    6,
  94.         'STO - Flood' =>    98,
  95.         'STO - Hurricane' =>    20,
  96.         'STO - Misc - Property Damage' =>    95,
  97.         'STO - Misc animal or insect' =>    100,
  98.         'STO - Mysterious Disappearance' =>    15,
  99.         'STO - Other' =>    100,
  100.         'STO - Property - Mold, Mildew and Dry rot' =>    100,
  101.         'STO - Property - Wind or Hail' =>    53,
  102.         'STO - Property Damage - Outside' =>    95,
  103.         'STO - Severe Storm' =>    23,
  104.         'STO - Sprinkler leakage' =>    102,
  105.         'STO - Vandalism' =>    17,
  106.         'STO - Water Damage' =>    102,
  107.         'STO - Water Damage - Broken Pipe' =>    102,
  108.         'STO - Water from roof' =>    102,
  109.         'STO - Wildfire' =>    157,
  110.         'STO - Winter Storm' =>    23,
  111.         'SUBSIDE OR SOIL MOVMENT' =>    100,
  112.         'Theft - Burglary Or Robbery - From Auto' =>    100,
  113.         'THEFT- OFF PREMISES' =>    15,
  114.         'THEFT ON PREMISES' =>    15,
  115.         'TORNADO' =>    16,
  116.         'TREE ROOTS - DMGD BY' =>    100,
  117.         'TRIP COLLISION' =>    100,
  118.         'TX ONLY - Applicance-Water' =>    102,
  119.         'VANDALISM OR  MAL MISCH' =>    124,
  120.         'VEHICLE - DAMAGED BY' =>    123,
  121.         'Vehicle (Struck By Vehicle & Damaged)' =>    123,
  122.         'VOLCANIC ERUPTION' =>    117,
  123.         'W OR C - MED.EXPENSES' =>    100,
  124.         'W OR C - TTL TEMP DISBL' =>    100,
  125.         'W OR C - VOC. REHAB.' =>    100,
  126.         'W OR C-PERMANENT DSBLTY' =>    100,
  127.         'WATER - BACKUP' =>    153,
  128.         'WATER - OTHER' =>    102,
  129.         'WATER - WEATHER' =>    102,
  130.         'WATERCRAFT LIABILITY' =>    96,
  131.         'WATER-PIPE BREAK' =>    102,
  132.         'WATER-SUMP OVERFLOW' =>    102,
  133.         'WEIGHT ICE OR SNOW' =>    143,
  134.         'WILDFIRE' =>    157,
  135.         'WILDFIRE SMOKE' =>    157,
  136.         'Wind - Catastrophe' =>    138,
  137.         'WINDSTORM' =>    138
  138.     ];
  139.     // Comment here
  140.     /**
  141.      * @Route("/unassigned")
  142.      */
  143.     public function unassignedViewFragment()
  144.     {
  145.         $em $this->get('doctrine')->getManager();
  146.         $CarrierCheck $this->container->get("app.carrier_check");
  147.         $envService $this->get('core.get_environment');
  148.         $claimRepo $em->getRepository("ClaimManagementBundle:Claim");
  149.         $adjusterRepo $em->getRepository("ResourceManagementBundle:Resource");
  150.         $claimTeamRepo $em->getRepository("ClaimManagementBundle:ClaimTeam");
  151.         $claimTeams $claimTeamRepo->findBy(['enabled'=>true], array('name' => 'ASC'));
  152.         $sql "SELECT id, resourceType
  153.               FROM resource_type";
  154.         /**
  155.          * Don't select exception resource types for specific auto assigner instances
  156.          */
  157.         if ($envService->getIsCarrier()) {
  158.             # Hide "None", its a auto assigner feature
  159.             $sql .= " WHERE id != 99";
  160.         } else {
  161.             # ICM doesnt use these resource types
  162.             $sql .= " WHERE id < 90 AND id != 3";
  163.         }
  164.         $stmt $em->getConnection()->prepare($sql);
  165.         $stmt->execute();
  166.         $resourceTypes $stmt->fetchAll(\PDO::FETCH_ASSOC);
  167.         $assignmentParties $em->getRepository("AssignmentBundle:AssignmentParty")->findAll();
  168.         return $this->render('ClaimManagementBundle:ClaimIntakeManagement/Fragments:unassigned.html.twig',[
  169.             'resourceTypes' => $resourceTypes,
  170.             'assignmentParties' => $assignmentParties,
  171.             'teams' => $claimTeams,
  172.             'companyCode' => $envService->getCompanyCode()
  173.         ]);
  174.     }
  175.     // Comment here
  176.     /**
  177.      * @Route("/unassignedmap/{customer_id}/{team_id}", defaults={"customer_id" = null,"team_id" = null})
  178.      */
  179.     public function unassignedViewMap(Request $request$customer_id$team_id)
  180.     {
  181.         $em $this->get('doctrine')->getManager();
  182.         $CarrierCheck $this->container->get("app.carrier_check");
  183.         $envService $this->get('core.get_environment');
  184.         $claimRepo $em->getRepository("ClaimManagementBundle:Claim");
  185.         $adjusterRepo $em->getRepository("ResourceManagementBundle:Resource");
  186.         $claimTeamRepo $em->getRepository("ClaimManagementBundle:ClaimTeam");
  187.         $Customers $em->getRepository("CustomerManagementBundle:Customer")->findBy([], ['companyName' => 'ASC']);
  188.         $resultsetClaimTeam = array();
  189.         $adjusters $adjusterRepo->findBy(['resourceType'=>array(2,3,4)]);
  190.         $claimTeams $claimTeamRepo->findBy(['enabled'=>true], array('name' => 'ASC'));
  191.         $sql "SELECT id, resourceType
  192.               FROM resource_type";
  193.         /**
  194.          * Don't select exception resource types for specific auto assigner instances
  195.          */
  196.         if ($envService->getIsCarrier()) {
  197.             # Hide "None", its a auto assigner feature
  198.             $sql .= " WHERE id != 99";
  199.         } else {
  200.             # ICM doesnt use these resource types
  201.             $sql .= " WHERE id < 90 AND id != 3";
  202.         }
  203.         $stmt $em->getConnection()->prepare($sql);
  204.         $stmt->execute();
  205.         $resourceTypes $stmt->fetchAll(\PDO::FETCH_ASSOC);
  206.         $CarrierCheck $this->container->get("app.carrier_check");
  207.         $isCarrier $CarrierCheck->environmentIsCarrier();
  208.         $tokenStorage $this->container->get("security.token_storage");
  209.         $User $tokenStorage->getToken()->getUser();
  210.         $isTeamLeader false;
  211.         $isAdjuster false;
  212.         $isBranchAdmin false;
  213.         $isBranchUser false;
  214.         if ($this->isGranted("ROLE_ADJUSTER") === true && $this->isGranted("ROLE_TEAM_LEADER") === false) {
  215.             $isAdjuster true;
  216.         } else if ($this->isGranted("ROLE_TEAM_LEADER") === true && ($this->isGranted("ROLE_ADMIN") === false && $this->isGranted("ROLE_EXAMINER") === false)) {
  217.             $isTeamLeader true;
  218.         } else if ($this->isGranted("ROLE_BRANCH_ADMIN") === true && $this->isGranted("ROLE_ADJUSTER") === false) {
  219.             $isBranchAdmin true;
  220.         } else if ($this->isGranted("ROLE_BRANCH_USER") === true && $this->isGranted("ROLE_BRANCH_ADMIN") === false) {
  221.             $isBranchUser true;
  222.         }
  223.         # Build Query and PDO Parameters that will be passed to PaginatorService class
  224.         $dataParams = array();
  225.         $sqlUnassign "SELECT c.id, 
  226.                 c.id as file_number, 
  227.                 c.claim_number as claim_number, 
  228.                 CONCAT(i.first_name, ' ', i.last_name) as insured_member, 
  229.                 CONCAT(ar.first_name,' ',ar.last_name) as assistive_resource,
  230.                 i.address as address, 
  231.                 cust.company_name as company_name,
  232.                 c.date_received as date_received, 
  233.                 c.loss_city as loss_city, 
  234.                 s.stateName as state, 
  235.                 c.loss_zip, DATE_FORMAT(c.loss_date, '%m/%d/%Y') as loss_date, 
  236.                  c.loss_latitude as loss_latitude,
  237.                  c.loss_longitude as loss_longitude, 
  238.                 
  239.                 c.status_id as status_id, 
  240.                 c.date_received, 
  241.                 c.loss_description,
  242.                 p1.description as loss_type
  243.                 FROM claim c "
  244.             . (($isCarrier) ? "LEFT" "INNER") . " JOIN customer cust on c.customer_id = cust.id
  245.                 LEFT JOIN state s
  246.                 on c.loss_state_id = s.id
  247.                 LEFT JOIN perils p1
  248.                   ON c.peril_id = p1.id
  249.                 LEFT JOIN claims_insured ci
  250.                   ON c.id = ci.claim_id AND ci.is_primary = 1
  251.                 LEFT JOIN insured i
  252.                   ON ci.insured_id = i.id " .
  253.             (($isAdjuster) ? "INNER" "LEFT") . " JOIN assignments cr 
  254.                     ON c.id = cr.claim_id AND IFNULL(cr.next_assignment_id,0) = 0 AND cr.is_current_assignment = 1
  255.                 LEFT JOIN resource r 
  256.                     ON cr.resource_id = r.id " .
  257.             (($isBranchAdmin) ? "INNER" "LEFT") . " JOIN customer_resource cust_res 
  258.                     ON c.customer_id = cust_res.customer_id ";
  259.         if ($isTeamLeader) {
  260.             $sqlUnassign .= "INNER JOIN claim_team_resource ctr 
  261.                         ON c.claim_team_id = ctr.claim_team_id ";
  262.         }
  263.         /*
  264.          * 7/26/2019 Added assistive adjuster update
  265.          *
  266.          */
  267.         $sqlUnassign .= "LEFT JOIN resource ar ON ar.id = c.assistive_resource_id ";
  268.         $sqlUnassign .= "WHERE c.loss_longitude<>'0' ";
  269.         // $sql .= "WHERE 1 = 1";
  270.         // if ($resourceId > 0) {
  271.         $sqlUnassign .= " AND c.status_id < 10 ";
  272.         // }
  273.         if($customer_id>0) {
  274.             $sqlUnassign .= "AND c.customer_id = :customer_id ";
  275.             $dataParams['customer_id'] = $customer_id;
  276.         }
  277.         $sqlUnassign .= " GROUP BY c.id ";
  278.         $stmt $em->getConnection()->prepare($sqlUnassign);
  279.         $stmt->execute($dataParams);
  280.         $resultset $stmt->fetchAll(\PDO::FETCH_ASSOC);
  281.  
  282.         $i 0;
  283.         $markerData = array();
  284.        foreach($resultset as $key=>$value){
  285.            $markerData[$i]['longitude'] = $value['loss_longitude'];
  286.            $markerData[$i]['latitude'] =  $value['loss_latitude'];
  287.            $markerData[$i]['claimnumber'] =  $value['file_number'];
  288.            if(!empty($value['loss_type']))
  289.                 $markerData[$i]['loss_type'] = $value['loss_type'];
  290.            else
  291.                $markerData[$i]['loss_type'] = 'NA';
  292.            $date=date_create($value['date_received']);
  293.            $date_received =  date_format($date,"m/d/Y");
  294.            $date1 = new \DateTime("now");
  295.            $date2 = new \DateTime(date_format($date,"m/d/Y H:i:s"));
  296.            $interval $date1->diff($date2);
  297.            $daysDiff $interval->days;
  298.            $hrsDiff $interval->h;
  299.            $totalHrs = ($daysDiff*24 $hrsDiff);
  300.            $markerData[$i]['date_received'] = $date_received;
  301.            $markerData[$i]['interval'] = $totalHrs;
  302.           // $markerData[$i]['days'] = $interval->days;
  303.            //$markerData[$i]['hr'] = $interval->h;
  304.            $markerData[$i]['type'] ='claim';
  305.            $markerData[$i]['id'] = $value['file_number'];
  306.            $markerData[$i]['customerName'] = $value['company_name'];
  307.            if($totalHrs>8)
  308.                 $markerData[$i]['iconUrl'] = '/img/pink-dot.png';
  309.            else
  310.                $markerData[$i]['iconUrl'] = '/img/blue-dot.png';
  311.            $i++;
  312.        }
  313.         if($customer_id>0){
  314.             $dataParamsClaimTeam  = array();
  315.             $dataParamsClaimTeam['customer_id'] = $customer_id;
  316.             $sqlClaimTeam  "SELECT name,id FROM claim_team ct";
  317.             $sqlClaimTeam .= " WHERE  ct.customer_id = :customer_id and enabled=1 ORDER BY name";
  318.             $stmtClaimTeam  $em->getConnection()->prepare($sqlClaimTeam);
  319.             $stmtClaimTeam->execute($dataParamsClaimTeam);
  320.             $resultsetClaimTeam  $stmtClaimTeam->fetchAll(\PDO::FETCH_ASSOC);
  321.             $dataParamsClaimTeamAdj = array();
  322.             if($team_id>0) {
  323.                 $dataParamsClaimTeamAdj['claim_team_id'] = $team_id;
  324.                 $sqlClaimTeamAdj "SELECT r.id, 
  325.                 CONCAT(r.first_name, ' ', r.last_name) as team_member_name,r.latitude,r.longitude,r.email,r.phone FROM resource r  
  326.                 INNER JOIN claim_team_resource ctr on r.id = ctr.resource_id 
  327.                
  328.                 ";
  329.                 $sqlClaimTeamAdj .= "WHERE  r.is_active=1 and ctr.claim_team_id = :claim_team_id ";
  330.                 $stmtClaimTeamAdj $em->getConnection()->prepare($sqlClaimTeamAdj);
  331.                 $stmtClaimTeamAdj->execute($dataParamsClaimTeamAdj);
  332.                 $resultsetClaimTeamAdj $stmtClaimTeamAdj->fetchAll(\PDO::FETCH_ASSOC);
  333.                 
  334.                 if (!empty($resultsetClaimTeamAdj)) {
  335.                     foreach ($resultsetClaimTeamAdj as $key => $value) {
  336.                           $markerData[$i]['longitude'] = $value['longitude'];
  337.                           $markerData[$i]['latitude'] =  $value['latitude'];
  338.                         $markerData[$i]['phone'] = $value['phone'];
  339.                         $sqlClaimCnt "SELECT count(claim_id) as count_of_claims
  340.                             FROM assignments cr 
  341.                             INNER JOIN claim c 
  342.                             ON cr.claim_id = c.id
  343.                             AND IFNULL(next_assignment_id,0) = 0
  344.                             AND is_current_assignment = 1
  345.                             WHERE 1 = 1
  346.                             AND c.status_id < 30
  347.                             AND cr.resource_id = :resource_id";
  348.                         $dataParamsClaimCnt = array();
  349.                         $dataParamsClaimCnt['resource_id'] = $value['id'];
  350.                         $stmtClaimCnt $em->getConnection()->prepare($sqlClaimCnt);
  351.                         $stmtClaimCnt->execute($dataParamsClaimCnt);
  352.                         $numOfClaims $stmtClaimCnt->fetchAll(\PDO::FETCH_ASSOC);
  353.                         foreach ($numOfClaims as $numOfClaim){
  354.                             $markerData[$i]['claim_assigned']= $numOfClaim['count_of_claims'];
  355.                         }
  356.                         $markerData[$i]['email'] = $value['email'];
  357.                         $value['team_member_name'] = str_replace("'","",$value['team_member_name']);
  358.                         $markerData[$i]['customerName'] = str_replace('"',"",$value['team_member_name']);
  359.                         $markerData[$i]['type'] ='adjuster';
  360.                        $markerData[$i]['iconUrl'] = '/img/icon.png';
  361.                          $i++;
  362.                     }
  363.                 }
  364.             }
  365.         }
  366. //dd($markerData);
  367.        // $markerData[0]['longitude'] = '-111.8265049';
  368.        // $markerData[0]['latitude'] = '34.8791806';
  369.       //  $markerData[0]['claimnumber'] = '1111111323-746456-7857657';
  370.        // $markerData[0]['customerName'] = 'USAA CAT1';
  371.        // $markerData[0]['iconUrl'] = 'http://maps.google.com/mapfiles/ms/icons/pink-dot.png';
  372.         //$markerData[1]['longitude'] = '-111.7695277';
  373.        // $markerData[1]['latitude'] = '34.832149';
  374.         //$markerData[1]['claimnumber'] = '22222323-746456-7857657';
  375.        // $markerData[1]['customerName'] = 'USAA CAT2';
  376.        // $markerData[1]['iconUrl'] = 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png';
  377.         return $this->render('ClaimManagementBundle:ClaimIntakeManagement/Fragments:unassigned_map.html.twig',[
  378.             'adjusters' => $adjusters,
  379.             'resourceTypes' => $resourceTypes,
  380.             "Customers" => $Customers,
  381.             'teams' => $claimTeams,'creation'=>true,
  382.             'customer_id'=>$customer_id,
  383.             'companyCode' => $envService->getCompanyCode(),'markerData'=>$markerData,'resultsetClaimTeam'=>$resultsetClaimTeam,'team_id'=>$team_id
  384.         ]);
  385.     }
  386.     // Comment here
  387.     /**
  388.      * @Route("/sendtoxact/{claim_id}/{sendflg}", defaults={"claim_id" = null,"sendflg" = null})
  389.      */
  390.     public function sendclaimxact(Request $request$claim_id,$sendflg)
  391.     {
  392.         $em $this->get('doctrine')->getManager();
  393.         $sentToXact 'N';
  394.         $claimData = array();
  395.         $claimRepo $em->getRepository("ClaimManagementBundle:Claim");
  396.         $claimNotFoundErr '';
  397.         $claimSentXact  '';
  398.         if($claim_id!='') {
  399.             $claimData $claimRepo->findOneBy(['id' => $claim_id]);
  400.             if (empty($claimData)) {
  401.                 $claimData $claimRepo->findOneBy(['claimNumber' => $claim_id]);
  402.             }
  403.             $claimNotFoundErr 'N';
  404.             if (empty($claimData)) {
  405.                 $claimNotFoundErr 'Y';
  406.             }
  407.             if(!empty($claimData) && $claimData->getTransactionId()!=''){
  408.                 $claimSentXact 'Y';
  409.             }else{
  410.                 $claimSentXact 'N';
  411.             }
  412.             if($sendflg=='Y'){
  413.                 $xact_service $this->container->get('integration.xact.outbound');
  414.                 $xact_data = array();
  415.                 
  416.                 if($claimData->getCustomer()->getCarrierId()!='') {
  417.                     $xact_data["carrier_id"] = $claimData->getCustomer()->getCarrierId();
  418.                     $xact_data["customer_name"] = $claimData->getCustomer()->getCompanyName();
  419.                     $xact_data["recipientsXNAddress"] = 'IAS_CLAIMS.HOME.WEB';
  420.                     $sqlInsured "SELECT
  421.                 ci.id, CONCAT(i.first_name, ' ', i.last_name) AS insuredName,i.phone,i.email as insuredEmail, i.address, ci.is_primary, cit.insured_type, i.city, s.stateCode, i.zip_code
  422.                 FROM claims_insured ci
  423.                 INNER JOIN insured i
  424.                   ON ci.insured_id = i.id
  425.                 INNER JOIN claim_insured_types cit
  426.                   ON ci.claim_insured_type_id = cit.id
  427.                 LEFT JOIN state s
  428.                   ON i.state_id = s.id
  429.                 WHERE claim_id = '" $claimData->getId() . "' limit 1";
  430.                     # Search By Claim ID
  431.                     $stmt $em->getConnection()->prepare($sqlInsured);
  432.                     $stmt->execute();
  433.                     $insuredResults $stmt->fetchAll(\PDO::FETCH_ASSOC);
  434.                     //dd($insuredResults);
  435.                     $xact_data["insured_name"] = $insuredResults[0]['insuredName'];
  436.                     $xact_data["InsuredHomeNumber"] = preg_replace('/[^0-9]/''',$insuredResults[0]['phone']);
  437.                     $xact_data["address"] = $insuredResults[0]['address'];
  438.                     $xact_data["prov"] = $insuredResults[0]['stateCode'];
  439.                     $xact_data["postal"] = $insuredResults[0]['zip_code'];
  440.                     $xact_data["city"] = $insuredResults[0]['city'];
  441.                     $xact_data["loss_city"] = $claimData->getLossCity();
  442.                     $xact_data["loss_street"] = $claimData->getLossStreet();
  443.                     $xact_data["loss_state"] = $claimData->getLossState()->getStateCode();
  444.                     $xact_data["loss_zip"] = $claimData->getLossZip();
  445.                     $xact_data["dateOfLoss"] = $claimData->getLossDate()->format('Y-m-d');
  446.                     $xact_data["policyNumber"] = $claimData->getPolicyNumber();
  447.                     $xact_data["claimNumber"] = $claimData->getClaimNumber();
  448.                     $xact_data["notes"] = $claimData->getSpecialNotes();
  449.                     $xact_data["catCode"] = $claimData->getCatastropheCode();
  450.                     $xact_data["ClaimLossDesc"] = substr($claimData->getLossDescription(),0,34);
  451.                     $xact_data["policyStart"] = $claimData->getPolicyStartDate()->format('Y-m-d');
  452.                     $xact_data["policyEnd"] = $claimData->getPolicyEndDate()->format('Y-m-d');
  453.                     $xact_data["dateOfRecieve"] = date('Y-m-d');
  454.                     $xact_data["loss_type"] = strtoupper($claimData->getPeril()->getDescription());
  455.                     $coverageRepo $em->getRepository("ClaimManagementBundle:Coverage");
  456.                     $coverageData $coverageRepo->findBy(['claim' => $claimData]);
  457.                     $coveragesArray = array();
  458.                     if (!empty($coverageData)) {
  459.                         foreach ($coverageData as $coverageData) {
  460.                             if ($coverageData->getName() == 'Dwelling') {
  461.                                 $coveragesArray[0]['name'] = 'Dwelling';
  462.                                 $coveragesArray[0]['id'] = 'COV1';
  463.                                 $coveragesArray[0]['type'] = 0;
  464.                                 $coveragesArray[0]['amt'] = floatval($coverageData->getAmount());
  465.                             }
  466.                             if ($coverageData->getName() == 'APS') {
  467.                                 $coveragesArray[1]['id'] = 'COV3';
  468.                                 $coveragesArray[1]['name'] = 'Aps';
  469.                                 $coveragesArray[1]['type'] = 1;
  470.                                 $coveragesArray[1]['amt'] = floatval($coverageData->getAmount());
  471.                             }
  472.                             if ($coverageData->getName() == 'Contents') {
  473.                                 $coveragesArray[2]['id'] = 'COV2';
  474.                                 $coveragesArray[2]['name'] = 'Contents';
  475.                                 $coveragesArray[2]['type'] = 2;
  476.                                 $coveragesArray[2]['amt'] = floatval($coverageData->getAmount());
  477.                             }
  478.                             if ($coverageData->getName() == 'ALE') {
  479.                                 $coveragesArray[3]['id'] = 'COV4';
  480.                                 $coveragesArray[3]['name'] = 'ALE';
  481.                                 $coveragesArray[3]['type'] = 0;
  482.                                 $coveragesArray[3]['amt'] = floatval($coverageData->getAmount());
  483.                             }
  484.                         }
  485.                     }
  486.                     if (!empty($coveragesArray)) {
  487.                         $xact_data['coverages'] = $coveragesArray;
  488.                     }
  489.                     $resXect $xact_service->exportCreateClaim($xact_data);
  490.                     $claimData->setTransactionId($resXect['transactionId']);
  491.                     if ($resXect['errorDescription'] != '') {
  492.                         $claimData->setXactErrorMessage($resXect['errorDescription']);
  493.                         $claimData->setXactErrorCode($resXect['errorCode']);
  494.                         $sentToXact 'E';
  495.                     } else {
  496.                         $claimData->setXactErrorMessage('Claim sent successfully');
  497.                         $claimData->setXactErrorCode('No Error');
  498.                         $sentToXact 'Y';
  499.                     }
  500.                     $em->persist($claimData);
  501.                     // dump($importable);
  502.                     // actually flush into the db
  503.                     $em->flush();
  504.                 }else{
  505.                     $sentToXact 'C';
  506.                 }
  507.             }
  508.         }
  509.         return $this->render('ClaimManagementBundle:ClaimIntakeManagement/Fragments:send_claim_xact.html.twig',['claim_id'=>$claim_id,'claimNotFoundErr'=>$claimNotFoundErr,'claimSentXact'=>$claimSentXact,'sentToXact'=>$sentToXact
  510.         ]);
  511.     }
  512.     /**
  513.      * @Route("/all")
  514.      */
  515.     public function viewAllClaimsFragment()
  516.     {
  517.         $em $this->getDoctrine()->getManager();
  518.         $CarrierCheck $this->container->get("app.carrier_check");
  519.         $isCarrier $CarrierCheck->environmentIsCarrier();
  520.         $tokenStorage $this->container->get("security.token_storage");
  521.         $User $tokenStorage->getToken()->getUser();
  522.         if($User instanceof Resource) {
  523.             if(in_array(UCFirstAll::ROLE_REGISTERED$User->getRoles())){
  524.                 throw $this->createAccessDeniedException("You don't have access to this page.");
  525.             }
  526.         } else {
  527.             throw $this->createAccessDeniedException("You don't have access to this page.");
  528.         }
  529.         $isTeamLeader false;
  530.         $isAdjuster false;
  531.         $isBranchAdmin false;
  532.         $isBranchUser false;
  533.         if ($this->isGranted("ROLE_ADJUSTER") === true && $this->isGranted("ROLE_TEAM_LEADER") === false) {
  534.             $isAdjuster true;
  535.         } else if ($this->isGranted("ROLE_TEAM_LEADER") === true && ($this->isGranted("ROLE_ADMIN") === false && $this->isGranted("ROLE_EXAMINER") === false)) {
  536.             $isTeamLeader true;
  537.         } else if ($this->isGranted("ROLE_BRANCH_ADMIN") === true && $this->isGranted("ROLE_ADJUSTER") === false) {
  538.             $isBranchAdmin true;
  539.         } else if ($this->isGranted("ROLE_BRANCH_USER") === true && $this->isGranted("ROLE_BRANCH_ADMIN") === false) {
  540.             $isBranchUser true;
  541.         }
  542.         
  543.         $recordsCount 0;
  544.         $dataParams = array();
  545.         $sql "SELECT COUNT(*) as count2
  546.                 FROM claim c 
  547.                 LEFT JOIN customer cust on c.customer_id = cust.id
  548.                 LEFT JOIN state s on c.loss_state_id = s.id
  549.                 LEFT JOIN claims_insured ci
  550.                   ON c.id = ci.claim_id
  551.                 LEFT JOIN insured i
  552.                   ON ci.insured_id = i.id ";
  553.         if ($isAdjuster) {
  554.             $sql .= "INNER JOIN assignments cr 
  555.                         ON c.id = cr.claim_id 
  556.                         AND IFNULL(cr.next_assignment_id,0) = 0
  557.                         AND cr.is_current_assignment = 1 ";
  558.         } else if ($isTeamLeader) {
  559.             $sql .= "INNER JOIN claim_team_resource ctr 
  560.                         ON c.claim_team_id = ctr.claim_team_id ";
  561.         } else if ($isBranchAdmin) {
  562.             $sql .= "INNER JOIN customer_resource cust_res 
  563.                         ON c.customer_id = cust_res.customer_id ";
  564.         }
  565.         $sql .= " WHERE (c.status_id BETWEEN 6 AND 29 OR c.status_id = 98) ";
  566.         if ($isAdjuster) {
  567.             $sql .= "AND cr.resource_id = :adjuster_id ";
  568.             $dataParams['adjuster_id'] = $User->getId();
  569.         } else if ($isTeamLeader) {
  570.             $sql .= "AND ctr.resource_id = :team_leader_id AND ctr.team_lead = 1 ";
  571.             $dataParams['team_leader_id'] = $User->getId();
  572.         } else if ($isBranchAdmin) {
  573.             $sql .= "AND cust_res.resource_id = :branch_admin_id ";
  574.             $dataParams['branch_admin_id'] = $User->getId();
  575.         } else if ($isBranchUser) {
  576.             $sql .= "AND c.claim_rep_id = :branch_user_id ";
  577.             $dataParams['branch_user_id'] = $User->getId();
  578.         }
  579.         $sql .= "GROUP BY c.id ";
  580.         $recordsCount 0;
  581.         $stmt $em->getConnection()->prepare($sql);
  582.         $stmt->execute($dataParams);
  583.         $resultset $stmt->fetchAll(\PDO::FETCH_ASSOC);
  584.         $recordsCount count($resultset);
  585.         $sqlStatus "SELECT id, status_name,hex_color
  586.               FROM claim_status where show_on_report='Y' order by order_by";
  587.         $stmtSql $em->getConnection()->prepare($sqlStatus);
  588.         $stmtSql->execute();
  589.         $statusShow $stmtSql->fetchAll(\PDO::FETCH_ASSOC);
  590.         return $this->render('ClaimManagementBundle:ClaimIntakeManagement/Fragments:all-claims.html.twig', [
  591.             'newClaimCount' => $recordsCount,'statusShow'=>$statusShow
  592.         ]);
  593.     }
  594.     /**
  595.      * @Route("/unassigned_data")
  596.      */
  597.     public function unassignedDatatables(Request $request)
  598.     {
  599.         $em $this->getDoctrine()->getManager();
  600.         //$resourceId = intval($request->query->get("resourceId"));
  601.         $CarrierCheck $this->container->get("app.carrier_check");
  602.         $isCarrier $CarrierCheck->environmentIsCarrier();
  603.         $tokenStorage $this->container->get("security.token_storage");
  604.         $User $tokenStorage->getToken()->getUser();
  605.         # Array of columns that will be sorted
  606.         if($isCarrier) {
  607.             $columnsArr = [
  608.                 "id",
  609.                 "id",
  610.                 "claim_number",
  611.                 "insured_member",
  612.                 "assistive_resource",
  613.                 "loss_city",
  614.                 "state",
  615.                 "loss_zip",
  616.                 "loss_type",
  617.                 "loss_date",
  618.                 "date_received"
  619.             ];
  620.         }else{
  621.             $columnsArr = [
  622.                 "id",
  623.                 "id",
  624.                 "claim_number",
  625.                 "file_number",
  626.                 "company_name",
  627.                 "insured_member",
  628.                 "assistive_resource",
  629.                 "loss_city",
  630.                 "state",
  631.                 "loss_zip",
  632.                 "loss_type",
  633.                 "loss_date",
  634.                 "date_received"
  635.             ];
  636.         }
  637.         $isTeamLeader false;
  638.         $isAdjuster false;
  639.         $isBranchAdmin false;
  640.         $isBranchUser false;
  641.         if ($this->isGranted("ROLE_ADJUSTER") === true && $this->isGranted("ROLE_TEAM_LEADER") === false) {
  642.             $isAdjuster true;
  643.         } else if ($this->isGranted("ROLE_TEAM_LEADER") === true && ($this->isGranted("ROLE_ADMIN") === false && $this->isGranted("ROLE_EXAMINER") === false)) {
  644.             $isTeamLeader true;
  645.         } else if ($this->isGranted("ROLE_BRANCH_ADMIN") === true && $this->isGranted("ROLE_ADJUSTER") === false) {
  646.             $isBranchAdmin true;
  647.         } else if ($this->isGranted("ROLE_BRANCH_USER") === true && $this->isGranted("ROLE_BRANCH_ADMIN") === false) {
  648.             $isBranchUser true;
  649.         }
  650.         # Build Query and PDO Parameters that will be passed to PaginatorService class
  651.         $dataParams = array();
  652.         $sql "SELECT c.id, 
  653.                 c.id as file_number, 
  654.                 c.claim_number as claim_number, 
  655.                 CONCAT(i.first_name, ' ', i.last_name) as insured_member, 
  656.                 CONCAT(ar.first_name,' ',ar.last_name) as assistive_resource,
  657.                 i.address as address, 
  658.                 cust.company_name as company_name,
  659.                 c.date_received as date_received, 
  660.                 c.loss_city as loss_city, 
  661.                 s.stateName as state, 
  662.                 c.loss_zip, DATE_FORMAT(c.loss_date, '%m/%d/%Y') as loss_date, 
  663.                -- c.assignment_notes as notes, 
  664.                 -- c.abridged_aa_notes as notes, 
  665.                 c.status_id as status_id, 
  666.                 c.date_received, 
  667.                 c.loss_description,
  668.                 c.is_claim_category,
  669.                 p1.description as loss_type
  670.                 FROM claim c "
  671.                 . (($isCarrier) ? "LEFT" "INNER") . " JOIN customer cust on c.customer_id = cust.id
  672.                 LEFT JOIN state s
  673.                 on c.loss_state_id = s.id
  674.                 LEFT JOIN perils p1
  675.                   ON c.peril_id = p1.id
  676.                 LEFT JOIN claims_insured ci
  677.                   ON c.id = ci.claim_id AND ci.is_primary = 1
  678.                 LEFT JOIN insured i
  679.                   ON ci.insured_id = i.id " .
  680.             (($isAdjuster) ? "INNER" "LEFT") . " JOIN assignments cr 
  681.                     ON c.id = cr.claim_id AND IFNULL(cr.next_assignment_id,0) = 0 AND cr.is_current_assignment = 1
  682.                 LEFT JOIN resource r 
  683.                     ON cr.resource_id = r.id " .
  684.             (($isBranchAdmin) ? "INNER" "LEFT") . " JOIN customer_resource cust_res 
  685.                     ON c.customer_id = cust_res.customer_id ";
  686.         if ($isTeamLeader) {
  687.             $sql .= "INNER JOIN claim_team_resource ctr 
  688.                         ON c.claim_team_id = ctr.claim_team_id ";
  689.         }
  690.         /*
  691.          * 7/26/2019 Added assistive adjuster update
  692.          *
  693.          */
  694.         $sql .= "LEFT JOIN resource ar ON ar.id = c.assistive_resource_id ";
  695.         $sql .= "WHERE 1 = 1 ";
  696.         // $sql .= "WHERE 1 = 1";
  697.         // if ($resourceId > 0) {
  698.         $sql .= " AND c.status_id < 10 ";
  699.         // }
  700.         if ($isAdjuster) {
  701.             $sql .= "AND cr.resource_id = :adjuster_id ";
  702.             $dataParams['adjuster_id'] = $User->getId();
  703.         } else if ($isTeamLeader) {
  704.             $sql .= "AND ctr.resource_id = :team_leader_id AND ctr.team_lead = 1 ";
  705.             $dataParams['team_leader_id'] = $User->getId();
  706.         } else if ($isBranchAdmin) {
  707.             $sql .= "AND cust_res.resource_id = :branch_admin_id ";
  708.             $dataParams['branch_admin_id'] = $User->getId();
  709.         } else if ($isBranchUser) {
  710.             $sql .= "AND c.claim_rep_id = :branch_user_id ";
  711.             $dataParams['branch_user_id'] = $User->getId();
  712.         }
  713.         # build keyword filter, which is requested by datatables ajax when someone types into keyword field
  714.         $keyword_filter " AND (c.claim_number like :keyword OR c.loss_city like :keyword OR c.loss_zip like :keyword or CONCAT(i.first_name, ' ', i.last_name) LIKE :keyword OR s.stateCode LIKE :keyword OR s.stateName LIKE :keyword OR c.id LIKE :keyword OR cust.company_name LIKE :keyword OR CONCAT(r.first_name, ' ', r.last_name) LIKE :keyword) ";
  715.         # specifiy group by
  716.         // $group_by = " GROUP BY c.id, c.claim_number";
  717.         $group_by "GROUP BY c.id";
  718.         # call PaginatorService
  719.         $paginator $this->container->get("resource.paginator_service");
  720.         /** @var \PDO $pdo */
  721.         $pdo $this->getDoctrine()->getManager()->getConnection();
  722.         $retVal2 $paginator->getPaginationResults($request$sql$dataParams"c.id"$columnsArr"search_keyword"$keyword_filter"keyword"$group_by"GET");
  723.         $retVal $retVal2;
  724.         $retVal['data'] = array();
  725.         $i 0;
  726.         foreach ($retVal2['data'] as $getItem) {
  727.             $status $em->find("ClaimManagementBundle:ClaimStatus"$getItem['status_id']);
  728.             $getItem2 $getItem;
  729.             $claim$em->getRepository("ClaimManagementBundle:Claim")->find($getItem['id']);
  730.             if(!$isCarrier){
  731.                 $claim$em->getRepository("ClaimManagementBundle:Claim")->find($getItem['id']);
  732.                 if(!empty($claim)){
  733.                     $customerId=$claim->getCustomer()->getId();
  734.                     $TpaCustomer $em->getRepository("CompanyManagementBundle:TpaCustomer")->findBy(['customerId' => $customerId]);
  735.                     //dd($customerId);
  736.                     //dd($TpaCustomer);
  737.                     if(!empty($TpaCustomer)){
  738.                         $getItem2['isTpaCustomer'] ='Y';
  739.                     }else{
  740.                         $getItem2['isTpaCustomer'] ='N';
  741.                     }
  742.                 }
  743.                 $Coverages $em->getRepository("ClaimManagementBundle:Coverage")->findBy(['claim' => $claim]);
  744.                 $getItem2['notes'] = "<b>Loss Description: </b> " .$getItem['loss_description'];
  745.                 if(!empty($Coverages)){
  746.                     foreach ($Coverages as $Coverage){
  747.                         if($Coverage){
  748.                             $getItem2['notes'] .= " </br><b>".$Coverage->getName().": </b> $"number_format($Coverage->getAmount(),2);
  749.                         }
  750.                     }
  751.                 }
  752.                 //$getItem2['notes'] = str_replace("\n", "<br>", strip_tags(preg_replace("/<[\/]{0,1}br[ \/]{0,2}>/", "\n", $getItem['notes'])));
  753.             }else{
  754.                 $getItem2['notes'] = str_replace("\n""<br>"strip_tags(preg_replace("/<[\/]{0,1}br[ \/]{0,2}>/""\n"$getItem['notes'])));
  755.             }
  756.             $getItem2['useTbca'] = 0;
  757.             $getItem2['subClaimHtml'] = '';
  758.             $getItem2['color'] = $status->getHexColor();
  759.             $retVal['data'][] = $getItem2;
  760.             $retVal['query'] = $sql;
  761.             
  762.         }
  763.         return new JsonResponse($retVal);
  764.     }
  765.     /**
  766.      * @Route("/all_data")
  767.      */
  768.     public function allDatatables(Request $request)
  769.     {
  770.         # Array of columns that will be sorted
  771.         $columnsArr = [
  772.             "id",
  773.             "claim_number",
  774.             "company_name",
  775.             "insured_member",
  776.             "address",
  777.             "loss_city",
  778.             "state",
  779.             "loss_zip",
  780.             "loss_date",
  781.             "date_received"
  782.         ];
  783.         $resourceId intval($request->query->get("resourceId"));
  784.         $CarrierCheck $this->container->get("app.carrier_check");
  785.         $isCarrier $CarrierCheck->environmentIsCarrier();
  786.         $tokenStorage $this->container->get("security.token_storage");
  787.         $User $tokenStorage->getToken()->getUser();
  788.         $isTeamLeader false;
  789.         $isAdjuster false;
  790.         $isBranchAdmin false;
  791.         $isBranchUser false;
  792.         if ($this->isGranted("ROLE_ADJUSTER") === true && $this->isGranted("ROLE_TEAM_LEADER") === false) {
  793.             $isAdjuster true;
  794.         } else if ($this->isGranted("ROLE_TEAM_LEADER") === true && ($this->isGranted("ROLE_ADMIN") === false && $this->isGranted("ROLE_EXAMINER") === false)) {
  795.             $isTeamLeader true;
  796.         } else if ($this->isGranted("ROLE_BRANCH_ADMIN") === true && $this->isGranted("ROLE_ADJUSTER") === false) {
  797.             $isBranchAdmin true;
  798.         } else if ($this->isGranted("ROLE_BRANCH_USER") === true && $this->isGranted("ROLE_BRANCH_ADMIN") === false) {
  799.             $isBranchUser true;
  800.         }
  801.         # Build Query and PDO Parameters that will be passed to PaginatorService class
  802.         $dataParams = array();
  803.         $sql "SELECT c.status_id as status, c.id, c.claim_number, CONCAT(i.first_name, ' ', i.last_name) as insured_member, i.address as address,
  804.                -- i.phone, i.cell_phone, i.alternate_phone,
  805.                 cust.company_name, c.date_received, c.loss_street, c.loss_city, s.stateName as state, c.loss_zip, c.loss_date, c.special_notes as notes, 
  806.                 p.description as peril, c.special_notes, c.date_received
  807.                 FROM claim c 
  808.                 LEFT JOIN customer cust on c.customer_id = cust.id
  809.                 LEFT JOIN state s on c.loss_state_id = s.id
  810.                 LEFT JOIN perils p on c.peril_id = p.id
  811.                 LEFT JOIN claims_insured ci
  812.                   ON c.id = ci.claim_id
  813.                 LEFT JOIN insured i
  814.                   ON ci.insured_id = i.id "
  815.                 . (($isAdjuster) ? "INNER" "LEFT") . " JOIN assignments cr 
  816.                   ON c.id = cr.claim_id AND IFNULL(cr.next_assignment_id,0) = 0 AND cr.is_current_assignment = 1
  817.                 LEFT JOIN resource r 
  818.                     ON cr.resource_id = r.id ";
  819.         if ($isTeamLeader) {
  820.             $sql .= "INNER JOIN claim_team_resource ctr 
  821.                         ON c.claim_team_id = ctr.claim_team_id ";
  822.         } else if ($isBranchAdmin) {
  823.             $sql .= "INNER JOIN customer_resource cust_res 
  824.                         ON c.customer_id = cust_res.customer_id ";
  825.         }
  826.         $sql .= " WHERE (c.status_id BETWEEN 6 AND 29 OR c.status_id = 98) ";
  827.         if ($isAdjuster) {
  828.             $sql .= "AND cr.resource_id = :adjuster_id ";
  829.             $dataParams['adjuster_id'] = $User->getId();
  830.         } else if ($isTeamLeader) {
  831.             $sql .= "AND ctr.resource_id = :team_leader_id AND ctr.team_lead = 1 ";
  832.             $dataParams['team_leader_id'] = $User->getId();
  833.         } else if ($isBranchAdmin) {
  834.             $sql .= "AND cust_res.resource_id = :branch_admin_id ";
  835.             $dataParams['branch_admin_id'] = $User->getId();
  836.         } else if ($isBranchUser) {
  837.             $sql .= "AND c.claim_rep_id = :branch_user_id ";
  838.             $dataParams['branch_user_id'] = $User->getId();
  839.         }
  840.        $searchedStatusId =  $request->query->get('search_status');
  841.         if(!empty($searchedStatusId)){
  842.             $sql .= " AND   (c.status_id in($searchedStatusId)) ";
  843.         }
  844.         $slog = new SLogger();
  845.         $slog->log("sql at 79: " $sql);
  846.         # build keyword filter, which is requested by datatables ajax when someone types into keyword field
  847.         $keyword_filter " AND (c.claim_number like :keyword OR c.loss_city like :keyword OR c.loss_zip like :keyword or CONCAT(i.first_name, ' ', i.last_name) LIKE :keyword OR s.stateCode LIKE :keyword OR s.stateName LIKE :keyword OR c.id LIKE :keyword OR cust.company_name LIKE :keyword OR CONCAT(r.first_name, ' ', r.last_name) LIKE :keyword) ";
  848.         # specifiy group by
  849.         // $group_by = " GROUP BY c.id, c.claim_number";
  850.         $group_by "GROUP BY c.id";
  851.         # call PaginatorService
  852.         $paginator $this->container->get("resource.paginator_service");
  853.         $retVal $paginator->getPaginationResults($request$sql$dataParams"c.date_received"$columnsArr"search_keyword"$keyword_filter"keyword"$group_by"GET");
  854.         $retVal['data'] = $this->manipulateClaimData($retVal);
  855.         return new JsonResponse($retVal);
  856.     }
  857.     /**
  858.      * @Route("/index")
  859.      */
  860.     public function viewMyClaims()
  861.     {
  862.         # FYI, if they have a role to view all claims, we need to do it here.
  863.         $em $this->get('doctrine')->getManager();
  864.         $authChecker $this->container->get('security.authorization_checker');
  865.         $user  $this->container->get('security.token_storage')->getToken()->getUser();
  866.         $role  $user->getRoles()[0];
  867.       
  868.         /** @var Resource $user */
  869.         $this->user $this->get('security.token_storage')->getToken()->getUser();
  870.         //Getting the settings of the User in an object
  871.         $getDashBoardSettingsOfUser $this->getSettingsUserForDash();
  872.         if($getDashBoardSettingsOfUser) {
  873.             $dbLocalStorageSettings json_decode($getDashBoardSettingsOfUser[0]['dashboard_settings']);
  874.             $dbLocalStoragePosition json_decode($getDashBoardSettingsOfUser[0]['dashboard_position']);
  875.         }
  876.         /*
  877.          * WHEN THERE IS NO SETTINGS FOR THE USER WE PICK THE DEFAULT DASHBOARD SETTINGS
  878.          */
  879.         else{
  880.             $dbLocalStorageSettings "{\"widget\":[]}";
  881.             $dbLocalStoragePosition "{\"grid\":[]}";
  882.         }
  883.         /*
  884.          * Don't show widget for the following
  885.          * Security Roles
  886.          */
  887.         $notShow false;
  888.         if($role == "ROLE_BRANCH_USER" || $role == "ROLE_BRANCH_ADMIN"){
  889.             $notShow true;
  890.         }
  891.         $teamCap 0;
  892.         /*
  893.          *  Check if there are saved settings
  894.          *  If is ICM we load their settings 1 - 20000
  895.          */
  896.         if ($dbLocalStorageSettings == "{\"widget\":[]}") {
  897.             $dbLocalStorageSettings '{"widget":[{"id":"wid-id-sitenotif","title":"Sitewide Notifications","hidden":"'
  898.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? 1) . '","collapsed":0, '
  899.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? "\"menu\": true" "\"menu\": false") . '},                   
  900.                 {"id":"wid-id-all-assigned","title":"All Assigned Claims","hidden":"'
  901.                 . (($authChecker->isGranted("ROLE_BRANCH_USER") === true && $role == "ROLE_ADJUSTER") ? 1) . '","collapsed":0, '
  902.                 . (($authChecker->isGranted("ROLE_BRANCH_USER") === true && ($role != "ROLE_ADJUSTER" && !$notShow)) ? "\"menu\": true" "\"menu\": false") . '},                             
  903.                 {"id":"wid-id-all-claims-widget","title":"All Claims Widget","hidden":"'
  904.                 . (($authChecker->isGranted("ROLE_BRANCH_USER") === true && $role != "ROLE_ADJUSTER") ? 1) . '","collapsed":0, '
  905.                 . (($authChecker->isGranted("ROLE_BRANCH_USER") === true && $role == "ROLE_ADJUSTER") ? "\"menu\": true" "\"menu\": false") . '},
  906.                 {"id":"wid-id-bookmarked-claims-widget","title":"Bookmarked Claims Widget","hidden":"'
  907.                 . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? 1) . '","collapsed":0, '
  908.                 . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? "\"menu\": true" "\"menu\": false") . '},
  909.                 {"id":"wid-id-claims","title":"Claims Diary","hidden":"'
  910.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? 1) . '","collapsed":0, '
  911.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? "\"menu\": true" "\"menu\": false") . '},
  912.                 {"id":"wid-id-status","title":"Status of Claims","hidden":"'
  913.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? 1) . '","collapsed":0, '
  914.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? "\"menu\": true" "\"menu\": false") . '},               
  915.                 {"id":"wid-id-licenses-maintenance","title":"Licenses Maintenance  |  Expiring in less than 60 days  ","hidden":"'
  916.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? 1) . '","collapsed":0, '
  917.                     . (($authChecker->isGranted("ROLE_BRANCH_USER") === true) ? "\"menu\": true" "\"menu\": false") . '},
  918.                 {"id":"wid-id-forecast","title":"Forecast","hidden":1,"collapsed":0,"menu":false},
  919.                 {"id":"wid-id-toploss","title":"Top Perils","hidden":"'
  920.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? 1) . '","collapsed":0,'
  921.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? "\"menu\": true" "\"menu\": false") . '},  
  922.                 {"id":"wid-id-openclaimspie","title":"Open Claims","hidden":1,"collapsed":0,"menu":false},                    
  923.                 {"id":"wid-id-available-resources","title":"Resources","hidden":"'
  924.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true && $teamCap == 0) ? 1) . '","collapsed":0, '
  925.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true && $teamCap == 0) ? "\"menu\": true" "\"menu\": false") . '},                
  926.                 {"id":"wid-id-avg-drive-time","title":"Average Drive Time","hidden":"'
  927.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? 1) . '","collapsed":0, '
  928.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? "\"menu\": true" "\"menu\": false") . '},                    
  929.                 {"id":"wid-id-time-in-progress","title":"Time In Progress","hidden":"'
  930.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? 1) . '","collapsed":0, '
  931.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? "\"menu\": true" "\"menu\": false") . '},  
  932.                 {"id":"wid-id-geomap-us","title":"GeoMap US","hidden":"'
  933.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? 1) . '","collapsed":0, '
  934.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? "\"menu\": true" "\"menu\": false") . '},
  935.                 {"id":"wid-id-mytasks","title":"Task created by me","hidden":"'
  936.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? 1) . '","collapsed":0, '
  937.                     . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? "\"menu\": true" "\"menu\": false") . '},
  938.                 {"id":"wid-id-tasks","title":"Message Forum","hidden":"'
  939.                 . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? 1) . '","collapsed":0, '
  940.                 . (($authChecker->isGranted("ROLE_TEAM_LEADER") === true) ? "\"menu\": true" "\"menu\": false") . '},        
  941.                 {"id":"wid-id-claims-count","title":"Claims Count","hidden":'
  942.                     . (($authChecker->isGranted("ROLE_ADMIN") === true || $authChecker->isGranted("ROLE_EXAMINER") === true) ? 1) .',"collapsed":0,"menu": '
  943.                     . (($authChecker->isGranted("ROLE_ADMIN") === true || $authChecker->isGranted("ROLE_EXAMINER") === true) ? 0) .'},
  944.                 {"id":"wid-id-claims-status-time-spent-avg","title":"Claims Status Time Spent Avg","hidden":'
  945.                     . (($authChecker->isGranted("ROLE_ADMIN") === true || $authChecker->isGranted("ROLE_EXAMINER") === true) ? 1) .',"collapsed":0,"menu": '
  946.                     . (($authChecker->isGranted("ROLE_ADMIN") === true || $authChecker->isGranted("ROLE_EXAMINER") === true) ? 0) .'}]}';
  947.         }
  948.         #Forced password change after 90 Days
  949.         if(!empty($user->getPasswordChangeDate())) {
  950.             $currentDate date('Y-m-d H:i:s');
  951.             $passwordChangeDate $user->getPasswordChangeDate()->format('Y-m-d H:i:s');
  952.             $passwordChangeDay round((strtotime($currentDate) - strtotime($passwordChangeDate)) / (60 60 24));
  953.         }else{
  954.             $passwordChangeDay=0;
  955.         }
  956.         $systemParamService $this->container->get('core.system_parameter_control');
  957.         $systemAdminUsers $systemParamService->getAccessArray('Invoicing_access');
  958.         $bShowInvoiceAccessBox false;
  959.         $user $this->get('security.token_storage')->getToken()->getUser();
  960.         if (!empty($systemAdminUsers) && in_array($user->getId(),$systemAdminUsers)) {
  961.             $bShowInvoiceAccessBox true;
  962.         }
  963.         
  964.         return $this->render('ClaimManagementBundle:ClaimIntakeManagement/Fragments:my-claims.html.twig',[
  965.             'adjuster' => $this->user->getId(),
  966.             'local_storage_settings' => json_encode($dbLocalStorageSettings),
  967.             'local_storage_position' => json_encode($dbLocalStoragePosition),
  968.             'local_storage_sett_obj' => $dbLocalStorageSettings,
  969.             'passwordChangeDay' => $passwordChangeDay,
  970.             'bShowInvoiceAccessBox' => $bShowInvoiceAccessBox
  971.         ]);
  972.     }
  973.     /**
  974.      * @Route("/claims/datatable")
  975.      */
  976.     public function myClaimsDatatable(Request $request)
  977.     {
  978.         # Array of columns that will be sorted
  979.         $columnsArr = [
  980.             "id",
  981.             "claim_number",
  982.             "date_received",
  983.             "insured",
  984.             "adjuster",
  985.             "state",
  986.             "loss_zip",
  987.             "loss_date",
  988.             "customer",
  989.             "status",
  990.             "color",
  991.             "notes"
  992.         ];
  993.         //$resourceId = $this->get('security.token_storage')->getToken()->getUser()->getId();
  994.         $authChecker $this->container->get('security.authorization_checker');
  995.         $user  $this->container->get('security.token_storage')->getToken()->getUser();
  996.         $resourceId $user->getId();
  997.         $status $request->query->get("statusId");
  998.         $dropdownValue intval($request->query->get("dropdownValue"));
  999.         $CarrierCheck $this->container->get("app.carrier_check");
  1000.         $isCarrier $CarrierCheck->environmentIsCarrier();
  1001.         # Build Query and PDO Parameters that will be passed to PaginatorService class
  1002.         $dataParams = array();
  1003.         if ($authChecker->isGranted("ROLE_TEAM_LEADER") === true) {
  1004.             //echo "team Leader";
  1005.             $sql "SELECT c.id, c.status_id as status, c.claim_number, cust.company_name as customer,
  1006.                       c.date_received, c.loss_city, s.stateName as state, c.loss_zip,
  1007.                       c.loss_date, CONCAT(i.first_name, ' ', i.last_name) as insured,
  1008.                       CONCAT(r.first_name, ' ', r.last_name) as adjuster, '' as color, special_notes as notes
  1009.                     FROM claim_team_resource cto
  1010.                       INNER JOIN claim_team_resource cto2 
  1011.                         ON cto.team_lead = 1 AND cto.claim_team_id = cto2.claim_team_id 
  1012.                       INNER JOIN assignments cr 
  1013.                         ON cto2.resource_id = cr.resource_id AND IFNULL(next_assignment_id,0) = 0
  1014.                       AND cr.is_current_assignment = 1
  1015.                       INNER JOIN claim c
  1016.                         ON cr.claim_id = c.id  
  1017.                       INNER JOIN customer cust on c.customer_id = cust.id
  1018.                       INNER JOIN state s on c.loss_state_id = s.id
  1019.                       LEFT JOIN resource r on cto2.resource_id = r.id
  1020.                       LEFT JOIN claims_insured ci on ci.claim_id = c.id
  1021.                       LEFT JOIN insured i ON i.id = ci.insured_id
  1022.                     WHERE c.status_id IN (6,10,12,13,14,15,20,23,25,100,101,103) AND cr.resource_id = :resourceId";
  1023.             $dataParams = array('resourceId' => $resourceId);
  1024.         }else{
  1025.             //echo "rest of them";
  1026.             $sql "SELECT c.id, c.status_id as status, c.claim_number, cust.company_name as customer,
  1027.                     c.date_received, c.loss_city, s.stateName as state, c.loss_zip,
  1028.                     c.loss_date, CONCAT(i.first_name, ' ', i.last_name) as insured,
  1029.                     CONCAT(r.first_name, ' ', r.last_name) as adjuster, '' as color, special_notes as notes
  1030.                     FROM claim c "
  1031.                     . (($isCarrier) ? "LEFT" "INNER") . " JOIN customer cust on c.customer_id = cust.id
  1032.                     INNER JOIN state s on c.loss_state_id = s.id
  1033.                     LEFT JOIN assignments cr on cr.claim_id = c.id
  1034.                     AND IFNULL(next_assignment_id,0) = 0 AND cr.is_current_assignment = 1
  1035.                     LEFT JOIN resource r on cr.resource_id = r.id
  1036.                     LEFT JOIN claims_insured ci on ci.claim_id = c.id 
  1037.                     LEFT JOIN insured i ON i.id = ci.insured_id 
  1038.                     WHERE " . (($isCarrier) ? "1 = 1" "c.status_id IN (6,10,12,13,14,15,20,23,25,100,101,103)") . 
  1039.                     AND cr.resource_id = :resourceId";
  1040.             $dataParams = array('resourceId' => $resourceId);
  1041.             }
  1042.         if ($status) {
  1043.             # Denied claims
  1044.             if ($status == -1) {
  1045.                 $sql .= " AND settlement_id in (4,5,6)";
  1046.             } else {
  1047.                 # all other claims
  1048.                 $sql .= " AND c.status_id != 30";
  1049.                 $sql .= " AND c.status_id = :status";
  1050.                 $dataParams["status"] =  $status;
  1051.             }
  1052.             # if status, add to array
  1053.         } else {
  1054.         }
  1055.         # handle dropdown being passed in from pie dropdown
  1056. //        switch ($dropdownValue) {
  1057. //            default :
  1058. //                $sql .= " AND c.date_received BETWEEN DATE_SUB(curdate(), INTERVAL 7 DAY) AND curdate()";
  1059. //                break;
  1060. //            case 2 :
  1061. //                $sql .= " AND c.date_received BETWEEN DATE_SUB(curdate(), INTERVAL 30 DAY) AND curdate()";
  1062. //                break;
  1063. //        }
  1064.         //echo $sql;
  1065. //                echo "<pre>". $sql . "</pre>";
  1066.         # build keyword filter, which is requested by datatables ajax when someone types into keyword field
  1067.         $keyword_filter "AND (c.claim_number like :keyword) ";
  1068.         # specifiy group by
  1069.         $group_by "GROUP BY c.id, c.claim_number";
  1070.         //return new JsonResponse(["sql" => $sql, "data" => $dataParams]); die;
  1071.         # call PaginatorService
  1072.         $paginator $this->container->get("resource.paginator_service");
  1073.         $data $paginator->getPaginationResults($request$sql$dataParams""$columnsArr""$keyword_filter"keyword"$group_by"GET");
  1074.         # manipulate data before sending to front end
  1075.         $data['data'] = $this->manipulateClaimData($data);
  1076.         return new JsonResponse($data);
  1077.     }
  1078.     public function manipulateClaimData($data)
  1079.     {
  1080.         $em $this->getDoctrine()->getManager();
  1081.         $data $data['data'];
  1082.         $result = [];
  1083.         foreach ($data as $index => $row) {
  1084.             $status $em->find("ClaimManagementBundle:ClaimStatus"$row['status']);
  1085.             $row['color'] =  $status->getHexColor();
  1086.             // $row['color'] = Claim::getStatusColor($row['status']);
  1087.             $row['date_received'] = date("m/d/Y"strtotime($row['date_received']));
  1088.             $row['loss_date'] = date("m/d/Y"strtotime($row['loss_date']));
  1089.             # store into another array
  1090.             $result[$index] = $row;
  1091.         }
  1092.         return $result;
  1093.     }
  1094.     public function getSettingsUserForDash(){
  1095.         //$user = $this->get('security.token_storage')->getToken()->getUsername();
  1096.         $em $this->getDoctrine()->getManager();
  1097.         $user_id $this->user->getId();
  1098.         $sql "SELECT dashboard_settings, dashboard_position FROM resource_dashboard WHERE resource_id = ?";
  1099.         //echo $sql;
  1100.         $stmt $em->getConnection()->prepare($sql);
  1101.         $stmt->execute([$user_id]);
  1102.         $results $stmt->fetchAll();
  1103.         //print_r($results);
  1104.         return $results;
  1105.     }
  1106.     /**
  1107.      * @Route("/claims/save_settings")
  1108.      */
  1109.     public function saveSettingsUserForDash(Request $request){
  1110.         $em $this->getDoctrine()->getManager();
  1111.         $settings_to_save  $request->request->get("currentLocalStorageSettings");
  1112.         $position_to_save  $request->request->get("currentLocalStoragePosition");
  1113.         $user $this->get('security.token_storage')->getToken()->getUser();
  1114.         $resource_dashboard $em->getRepository(ResourceDashboard::class)->findOneBy(array("resource"=>$user));
  1115.         //If there is no existence of the user in the dashboard_settings table it CREATES
  1116.         if(!$resource_dashboard){
  1117.             $resource_dashboard = new ResourceDashboard();
  1118.             $resource_dashboard->setResource($user);
  1119.         }
  1120.         if($settings_to_save && $settings_to_save != "null") {
  1121.             $resource_dashboard->setDashboard($settings_to_save);
  1122.         }
  1123.         if($position_to_save && $position_to_save != "null") {
  1124.             $resource_dashboard->setDashboardPos($position_to_save);
  1125.         }
  1126. //        if (!$username) {
  1127. //            throw $this->createNotFoundException(
  1128. //                'No product found for id '.$username
  1129. //            );
  1130. //        }
  1131.         $em->persist($resource_dashboard);
  1132.         $em->flush();
  1133.         return new JsonResponse(array('success' => true));
  1134.     }
  1135.     /**
  1136.      * @Route("/diary_reporting")
  1137.      */
  1138.     public function getDiaryReportingTool()
  1139.     {
  1140.         # Entity Manager
  1141.         $em $this->getDoctrine()->getManager();
  1142.         $authChecker $this->container->get('security.authorization_checker');
  1143.         $logged_in_user  $this->container->get('security.token_storage')->getToken()->getUser();
  1144.         $logged_in_user_id $logged_in_user->getId();
  1145.         //TEAM LEAD SECTION
  1146.         $resources = array();
  1147.         if ($authChecker->isGranted("ROLE_EXAMINER") || $authChecker->isGranted("ROLE_ADMIN") || $authChecker->isGranted("ROLE_SUPER_ADMIN")){
  1148.             //fetch all the ACTIVE resources
  1149.             $res_sql =    "SELECT DISTINCT r.id, CONCAT(r.first_name,' ',r.last_name) as name
  1150.                            FROM resource r
  1151.                            INNER JOIN diary_entry de 
  1152.                            ON de.resource_id = r.id
  1153.                            WHERE 1 =1 
  1154.                            AND r.is_active = :is_active
  1155.                            UNION ALL 
  1156.                            SELECT DISTINCT r.id , CONCAT(r.first_name,' ',r.last_name) as name 
  1157.                            FROM resource r 
  1158.                            WHERE r.id = :logged_in_user_id
  1159.                            ORDER BY name" ;
  1160.             $res_stmt $em->getConnection()->prepare($res_sql);
  1161.             $res_stmt->execute(["is_active" => 1,"logged_in_user_id" => $logged_in_user_id]);
  1162.             $resources $res_stmt->fetchAll();
  1163.         }else if ($authChecker->isGranted("ROLE_TEAM_LEADER")) {
  1164.             foreach ($logged_in_user->getClaimTeams() as $claimTeamResource){
  1165.                 if($claimTeamResource->getIsTeamLead()){
  1166.                     //fetch all the resources for the team where resource id team lead
  1167.                     $res_sql =    "SELECT DISTINCT r.id, concat(r.first_name,' ',r.last_name) as name 
  1168.                                     FROM resource r 
  1169.                                     INNER JOIN claim_team_resource ctr
  1170.                                     ON r.id = ctr.resource_id
  1171.                                     INNER JOIN diary_entry de 
  1172.                                     ON de.resource_id = r.id
  1173.                                     INNER JOIN claim c 
  1174.                                     ON c.id = de.claim_id
  1175.                                     WHERE 1 = 1 
  1176.                                     AND r.is_active = :is_active
  1177.                                     AND ctr.claim_team_id = :team_id
  1178.                                     AND c.claim_team_id = :team_id
  1179.                                     UNION ALL 
  1180.                                     SELECT DISTINCT r.id , CONCAT(r.first_name,' ',r.last_name) as name 
  1181.                                     FROM resource r
  1182.                                     WHERE r.id = :logged_in_user_id
  1183.                                     ORDER BY name" ;
  1184.                     $res_stmt $em->getConnection()->prepare($res_sql);
  1185.                     $res_stmt->execute(["is_active" => 1,
  1186.                         "team_id" => $claimTeamResource->getClaimTeam()->getId(),
  1187.                         "logged_in_user_id" => $logged_in_user_id]);
  1188.                     $resources $res_stmt->fetchAll();
  1189.                 }
  1190.             }
  1191.         } else if ($authChecker->isGranted("ROLE_ADJUSTER")){
  1192.             //fetch all the ACTIVE resources
  1193.             $res_sql "SELECT DISTINCT r.id , CONCAT(r.first_name,' ',r.last_name) as name 
  1194.                         FROM resource r
  1195.                         -- INNER JOIN diary_entry de 
  1196.                         -- ON de.resource_id = r.id
  1197.                         WHERE r.id = :logged_in_user_id
  1198.                         ORDER BY name" ;
  1199.             $res_stmt $em->getConnection()->prepare($res_sql);
  1200.             $res_stmt->execute(["logged_in_user_id" => $logged_in_user_id]);
  1201.             $resources $res_stmt->fetchAll();
  1202.         }
  1203.         return $this->render('ClaimManagementBundle:ClaimIntakeManagement/Fragments:diary-objects.html.twig',[
  1204.             "resources" => $resources
  1205.         ]);
  1206.     }
  1207.     /**
  1208.      * @Route("/diary_reporting_datatable")
  1209.      */
  1210.     public function getDiaryReportingDatatable(Request $request)
  1211.     {
  1212.         # Entity Manager
  1213.         $em $this->getDoctrine()->getManager();
  1214.         $authChecker $this->container->get('security.authorization_checker');
  1215.         $logged_in_user  $this->container->get('security.token_storage')->getToken()->getUser();
  1216.         $logged_in_user_id $logged_in_user->getId();
  1217.         $dataParams = array();
  1218.         $dataParams["resource_id"] = $request->query->get("resourceId");
  1219.             $sql "SELECT de.*, 
  1220.                 c.claim_team_id AS claim_team_id,
  1221.                 c.id AS claim_id,
  1222.                 c.claim_number AS claim_num,
  1223.                 c.date_received as claim_received_date,
  1224.                 CONCAT(ins.first_name, ' ' , ins.last_name) as claim_insured,
  1225.                 st.stateCode AS claim_state,
  1226.                 c.loss_zip AS claim_zip,
  1227.                 CONCAT(adj.first_name, ' ' , adj.last_name) as adjuster,
  1228.                 cust.company_name AS customer,
  1229.                 p.description AS loss_type,
  1230.                 CONCAT(res.first_name, ' ' , res.last_name) as owner,
  1231.                 CONCAT(author.first_name, ' ' , author.last_name) as author
  1232.                 FROM diary_entry de
  1233.                 INNER JOIN claim c 
  1234.                 ON c.id = de.claim_id
  1235.                 LEFT JOIN claims_insured ci 
  1236.                 ON ci.claim_id = c.id AND ci.is_primary = 1
  1237.                 LEFT JOIN insured ins 
  1238.                 ON ins.id = ci.insured_id    
  1239.                 LEFT JOIN resource res
  1240.                 ON res.id = de.resource_id
  1241.                 LEFT JOIN resource author
  1242.                 ON author.id = de.author_id
  1243.                 LEFT JOIN state st 
  1244.                 ON st.id = c.loss_state_id
  1245.                 LEFT JOIN assignments cr ON cr.claim_id = c.id AND cr.is_primary_adjuster = 1
  1246.                   AND IFNULL(cr.next_assignment_id,0) = 0 AND cr.is_current_assignment = 1
  1247.                 LEFT JOIN resource adj ON adj.id = cr.resource_id
  1248.                 LEFT JOIN customer cust ON c.customer_id = cust.id
  1249.                 LEFT JOIN perils p ON p.id = c.peril_id
  1250.                 WHERE de.resource_id = :resource_id 
  1251.                 AND de.status = 0 ";
  1252.         if($request->query->get("filter") == 1){
  1253.             $sql .= "AND DATE_FORMAT(de.dueDate,'%Y-%m-%d') = :today";
  1254.             $dataParams["today"] = date('Y-m-d');
  1255.             if ($request->query->get("searchFilter")){
  1256.                 $searchFilter $request->query->get("searchFilter");
  1257.                 $sql .= " AND c.claim_number like '"$searchFilter "%'";
  1258.             }
  1259.         }else if($request->query->get("filter") == 2){
  1260.             $sql .= "AND de.dueDate < :today";
  1261.              $dataParams["today"] = date('Y-m-d');
  1262.             if ($request->query->get("searchFilter")){
  1263.                 $searchFilter $request->query->get("searchFilter");
  1264.                 $sql .= " AND c.claim_number like '"$searchFilter "%'";
  1265.             }
  1266.         }else if($request->query->get("filter") == ){
  1267. //            echo "POLLO";
  1268.             if($request->query->get("start_date") && $request->query->get("end_date")) {
  1269.                 $sql .= "AND DATE_FORMAT(de.dueDate,'%Y-%m-%d') BETWEEN :start_date AND :end_date";
  1270.                 $dataParams["start_date"] = date('Y-m-d'strtotime($request->query->get("start_date")));
  1271.                 $dataParams["end_date"] = date('Y-m-d'strtotime($request->query->get("end_date")));
  1272. //                echo $dataParams["start_date"];
  1273.             }
  1274.             if ($request->query->get("searchFilter")){
  1275.                 $searchFilter $request->query->get("searchFilter");
  1276.                 $sql .= " AND c.claim_number like '"$searchFilter "%'";
  1277.             }
  1278.         }else{
  1279.             if ($request->query->get("searchFilter")){
  1280.                 $searchFilter $request->query->get("searchFilter");
  1281.                 $sql .= " AND c.claim_number like '"$searchFilter "%'";
  1282.             }
  1283.         }
  1284.         //echo $sql;
  1285.         $stmt $em->getConnection()->prepare($sql);
  1286.         $stmt->execute($dataParams);
  1287.         $DiaryEntry $stmt->fetchAll();
  1288.         $diary_report = array();
  1289.         foreach ($DiaryEntry as $diaryEntryRow){
  1290.             if ($authChecker->isGranted("ROLE_TEAM_LEADER")
  1291.                 && !$authChecker->isGranted("ROLE_ADMIN")
  1292.                 && !$authChecker->isGranted("ROLE_EXAMINER")
  1293.                 && $logged_in_user_id <> $dataParams["resource_id"] ) {
  1294.                 echo $diaryEntryRow['claim_team_id'] . " ";
  1295.                 $isTeamLead false;
  1296.                 foreach ($logged_in_user->getClaimTeams() as $claimTeamResource) {
  1297.                     if ($claimTeamResource->getIsTeamLead()) {
  1298.                         if($claimTeamResource->getClaimTeam()->getId() == $diaryEntryRow['claim_team_id'])
  1299.                         {
  1300.                             $isTeamLead true;
  1301.                         }
  1302.                     }
  1303.                 }
  1304.                 if(!$isTeamLead){
  1305.                     continue;
  1306.                 }
  1307.             }
  1308.             $diary_report_row['diary_id'] = $diaryEntryRow['id'];
  1309.             $diary_report_row['claim_id'] = $diaryEntryRow['claim_id'];
  1310.             $diary_report_row['claim_num'] = $diaryEntryRow['claim_num'];
  1311.             $diary_report_row['due_date'] = $diaryEntryRow['dueDate'];
  1312.             $diary_report_row['owner'] = $diaryEntryRow['owner'];
  1313.             $diary_report_row['description'] = $diaryEntryRow['description'];
  1314.             $diary_report_row['create_date'] = $diaryEntryRow['dateCreated'];
  1315.             $diary_report_row['author'] = $diaryEntryRow['author'];
  1316.             $diary_report_row['priority'] = $diaryEntryRow['priority'];
  1317.             $diary_report_row['claim_received_date'] = $diaryEntryRow['claim_received_date'];
  1318.             $diary_report_row['claim_insured'] = $diaryEntryRow['claim_insured'];
  1319.             $diary_report_row['claim_state'] = $diaryEntryRow['claim_state'];
  1320.             $diary_report_row['claim_zip'] = $diaryEntryRow['claim_zip'];
  1321.             $diary_report_row['adjuster'] = $diaryEntryRow['adjuster'];
  1322.             $diary_report_row['customer'] = $diaryEntryRow['customer'];
  1323.             $diary_report_row['loss_type'] = $diaryEntryRow['loss_type'];
  1324.             $diary_report[] = $diary_report_row;
  1325.         }
  1326.         return $this->render('ClaimManagementBundle:ClaimIntakeManagement/Fragments/widgets:diary-objects-widget.html.twig',[
  1327.             "diary_report" =>$diary_report
  1328.         ]);
  1329.     }
  1330.     /**
  1331.      * @Route("/searchfileorclaim")
  1332.      */
  1333.     public function searchfileorclaimAction(Request $request)
  1334.     {
  1335.         $em $this->getDoctrine()->getManager();
  1336.         $term $request->request->get("file_claim_id");
  1337.         $response['error'] = false;
  1338.         if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬]/'$term))
  1339.         {
  1340.             // one or more of the 'special characters' found in $string
  1341.             $response['error'] = true;
  1342.             return new JsonResponse($response);
  1343.         }
  1344.         if (preg_match('/^[0-9]+-[0-9]+$/i'$term)) {
  1345.             // contains a dash
  1346.             $claim$em->getRepository("ClaimManagementBundle:Claim")->findOneBy(['claimNumber' => $term]);
  1347.             if(empty($claim)){
  1348.                 $response['error'] = true;
  1349.             }else{
  1350.                 $response['data']['id']= $claim->getId();
  1351.             }
  1352.         } else {
  1353.             // does not contain dash
  1354.             $claim$em->getRepository("ClaimManagementBundle:Claim")->findOneBy(['claimNumber' => $term]);
  1355.             if(empty($claim)){
  1356.                 $claim$em->getRepository("ClaimManagementBundle:Claim")->find($term);
  1357.             }
  1358.         }
  1359.         if(empty($claim)){
  1360.             $response['error'] = true;
  1361.         }else{
  1362.             $response['data']['id']= $claim->getId();
  1363.         }
  1364.         return new JsonResponse($response);
  1365.     }
  1366. }