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

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