src/ApplicationBundle/Controller/ApprovalController.php line 121

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Controller;
  3. use ApplicationBundle\Constants\GeneralConstant;
  4. use ApplicationBundle\Entity\EncryptedSignature;
  5. use ApplicationBundle\Interfaces\SessionCheckInterface;
  6. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  7. use ApplicationBundle\Modules\System\DocValidation;
  8. use ApplicationBundle\Modules\System\MiscActions;
  9. use ApplicationBundle\Modules\System\System;
  10. use ApplicationBundle\Modules\User\Users;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Routing\Generator\UrlGenerator;
  14. class ApprovalController extends GenericController implements SessionCheckInterface
  15. {
  16.     public function ApproveDocumentAction(Request $request)
  17.     {
  18.         $em $this->getDoctrine()->getManager();
  19.         if ($request->isMethod('POST')) {
  20.             if (isset(GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']))
  21.                 $url $this->generateUrl(
  22.                     GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']
  23.                 );
  24.             else {
  25.                 $url '';
  26.             }
  27.             $options = array(
  28.                 'notification_enabled' => $this->container->getParameter('notification_enabled'),
  29.                 'notification_server' => $this->container->getParameter('notification_server'),
  30. //                'appId'=>$request->getSession()->get(UserConstants::USER_APP_ID),
  31. //                'url'=>$this->generateUrl(
  32. //                    GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']
  33. //                )
  34.             );
  35.             if ($request->request->has('approvalAction')) {
  36.                 $message System::approveDocument(
  37.                     $em,
  38.                     $options,
  39.                     $request->request->get('approvalEntity'),
  40.                     $request->request->get('approvalEntityId'),
  41.                     $request->request->get('approvalId'),
  42.                     $this->getLoggedUserLoginId($request),
  43.                     $request->request->get('approvalAction'),
  44.                     $request->request->get('approvalNote'),
  45.                     $request->request->get('approvalHash'),
  46.                     $url,
  47.                     $request->request->get('forwardTo'),
  48.                     $this->get('mail_module')
  49.                 );
  50. //            $url = $this->generateUrl(
  51. //                GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']
  52. //            );
  53. //            if(!empty($currentApprovalData['UserIdList']))
  54. //            System::AddNewNotification(
  55. //                $this->container->getParameter('notification_enabled'),
  56. //                $this->container->getParameter('notification_server'),$request->getSession()->get(UserConstants::USER_APP_ID),
  57. //                $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  58. //                "Approval: ".GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_alias'].": " . $message['docHash'] . " is pending Your approval",
  59. //                'user',
  60. //                $message['UserIdList'],
  61. //                'information',
  62. ////                GeneralConstant::$Entity_list_details[$entity_id]."/".$projectId,
  63. //                $url . "/" . $request->request->get('approvalEntityId'),
  64. //                "Approval Pending"
  65. //
  66. //            );
  67. //            $this->addFlash(
  68. //                $message[0],
  69. //                $message[1]
  70. //            );
  71.                 if ($message['success'] == true)
  72.                     return new JsonResponse(array("success" => true,
  73.                             'message' => $message,
  74.                             'approvalEntity' => $request->request->get('approvalEntity'),
  75.                             'approvalEntityId' => $request->request->get('approvalEntityId'),
  76.                             'approvalId' => $request->request->get('approvalId'),
  77.                             'approvalAction' => $request->request->get('approvalAction'),
  78.                         )
  79.                     );
  80.                 else
  81.                     return new JsonResponse(array("success" => false'message' => $message,
  82.                             'approvalEntity' => $request->request->get('approvalEntity'),
  83.                             'approvalEntityId' => $request->request->get('approvalEntityId'),
  84.                             'approvalId' => $request->request->get('approvalId'),
  85.                             'approvalAction' => $request->request->get('approvalAction'),
  86.                         )
  87.                     );
  88.             }
  89.             return new JsonResponse(array("success" => false));
  90.         }
  91. //        $userList=$this->get('user_module')->showUserList();
  92.         return new JsonResponse(array("success" => false));
  93.     }
  94.     public function getPendingApprovalListForUserAction(Request $request)
  95.     {
  96.         $em $this->getDoctrine()->getManager();
  97.         $session $request->getSession();
  98.         $currentDateTime = new \DateTime();
  99.         $currTs $currentDateTime->format('U');
  100.         $tvp $this->get('url_encryptor')->encrypt(json_encode(
  101.             array(
  102.                 'timeout' => $currTs 3600,
  103.                 'token' => $session->get('token'0),
  104.             )
  105.         ));
  106.         $absoluteUrlList = [];
  107.         $filterApprovalEntityId=$request->request->get('entity','_all_');
  108.         foreach (GeneralConstant::$Entity_list_details as $e => $d) {
  109.             if (isset($d['entity_view_route_path_name']))
  110.                 $absoluteUrlList[$e] = $this->generateUrl($d['entity_view_route_path_name'], [], UrlGenerator::ABSOLUTE_URL);
  111.         }
  112.         return new JsonResponse(System::getPendingApprovalListByUserLoginId($em$this->getLoggedUserLoginId($request), 1$absoluteUrlList$tvp,$filterApprovalEntityId));
  113.     }
  114.     public function getPendingApprovalListForUserForAppAction(Request $request)
  115.     {
  116.         $em $this->getDoctrine()->getManager();
  117.         $absoluteUrlList = [];
  118.         $session $request->getSession();
  119.         $currentDateTime = new \DateTime();
  120.         $currTs $currentDateTime->format('U');
  121.         $tvp $this->get('url_encryptor')->encrypt(json_encode(
  122.             array(
  123.                 'timeout' => $currTs 3600,
  124.                 'token' => $session->get('token'0),
  125.             )
  126.         ));
  127.         foreach (GeneralConstant::$Entity_list_details as $e => $d) {
  128.             if (isset($d['entity_view_route_path_name']))
  129.                 $absoluteUrlList[$e] = $this->generateUrl(isset($d['entity_print_route_path_name']) ? $d['entity_print_route_path_name'] : $d['entity_view_route_path_name'], [], UrlGenerator::ABSOLUTE_URL);
  130.         }
  131.         return new JsonResponse(System::getPendingApprovalListByUserLoginId($em$this->getLoggedUserLoginId($request), 1$absoluteUrlList$tvp));
  132.     }
  133.     public function getDocumentlListForAppAction(Request $request)
  134.     {
  135.         $em $this->getDoctrine()->getManager();
  136.         $absoluteUrlList = [];
  137.         foreach (GeneralConstant::$Entity_list_details as $e => $d) {
  138.             if (isset($d['entity_view_route_path_name']))
  139.                 $absoluteUrlList[$e] = $this->generateUrl(isset($d['entity_print_route_path_name']) ? $d['entity_print_route_path_name'] : $d['entity_view_route_path_name'], [], UrlGenerator::ABSOLUTE_URL);
  140.         }
  141.         $session $request->getSession();
  142.         $currentDateTime = new \DateTime();
  143.         $currTs $currentDateTime->format('U');
  144.         $tvp $this->get('url_encryptor')->encrypt(json_encode(
  145.             array(
  146.                 'timeout' => $currTs 3600,
  147.                 'token' => $session->get('token'0),
  148.             )
  149.         ));
  150.         return new JsonResponse(System::getPendinDocumentListForAppByUserLoginId($em$this->getLoggedUserLoginId($request), 1$absoluteUrlList,
  151.             $tvp,
  152.             $request->query->get('page''_UNSET_'),
  153.             $request->query->get('offset'0),
  154.             $request->query->get('limit'999999)
  155.         ));
  156.     }
  157.     public function UpdateSignatureAction(Request $request)
  158.     {
  159.         $em $this->getDoctrine()->getManager();
  160.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  161.         $session $request->getSession();
  162.         $userId $session->get('userId');
  163.         $companyId $session->get('userCompanyId');
  164.         $appId $session->get('userAppId');
  165.         $user $em->getRepository('ApplicationBundle:SysUser')->findOneBy(['userId' => $userId]);
  166.         $applicantId $user->getGlobalId();
  167.         $user_data Users::getUserInfoByLoginId($em$this->getLoggedUserLoginId($request));
  168.         $g_path '';
  169.         if ($request->isMethod('POST')) {
  170.             $path "";
  171.             $extension_here '';
  172.             foreach ($request->files as $uploadedFile) {
  173.                 if ($uploadedFile != null) {
  174.                     $extension_here $uploadedFile->guessExtension();
  175.                     $fileName md5(uniqid()) . '.' $extension_here;
  176.                     $path $fileName;
  177.                     $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/FileUploads/';
  178.                     if (!file_exists($upl_dir)) {
  179.                         mkdir($upl_dir0777true);
  180.                     }
  181.                     $file $uploadedFile->move($upl_dir$path);
  182.                 }
  183.             }
  184.             if ($path != "") {
  185.                 $file_path 'uploads/FileUploads/' $path;
  186.                 $g_path $this->container->getParameter('kernel.root_dir') . '/../web/' $file_path;
  187.                 list($width$height) = getimagesize($g_path);
  188.                 $percent = (200 $width);
  189.                 $newwidth $width $percent;
  190.                 $newheight $height $percent;
  191.                 $thumb imagecreatetruecolor($newwidth$newheight);
  192.                 $source = ($extension_here == 'png') ? imagecreatefrompng($g_path) : imagecreatefromjpeg($g_path);
  193.                 imagecopyresampled($thumb$source0000$newwidth$newheight$width$height);
  194.                 $thumbPath $this->container->getParameter('kernel.root_dir') . '/../web/uploads/FileUploads/th.png';
  195.                 imagepng($thumb$thumbPath);
  196.                 $th_file file_get_contents($thumbPath);
  197.                 $image_data base64_encode($th_file);
  198.                 $encoded_data System::encryptSignature($image_data$request->request->get('approvalHash'));
  199.                 if ($encoded_data !== false) {
  200.                     $repo $em->getRepository('ApplicationBundle:EncryptedSignature');
  201.                     $record $repo->findOneBy(['userId' => $userId]);
  202.                     if (!$record) {
  203.                         $record = new \ApplicationBundle\Entity\EncryptedSignature();
  204.                         $record->setUserId($userId);
  205.                         $record->setCreatedAt(new \DateTime());
  206.                     }
  207.                     $record->setCompanyId($companyId);
  208.                     $record->setData($encoded_data);
  209.                     $record->setSigExists(0);
  210.                     $record->setLastDecryptedSigId(0);
  211.                     $record->setUpdatedAt(new \DateTime());
  212.                     $em->persist($record);
  213.                     $em->flush();
  214.                     // Sync to central server
  215.                     if ($systemType !== '_CENTRAL_') {
  216.                         $centralUrl GeneralConstant::HONEYBEE_CENTRAL_SERVER '/SyncSignatureToCentral';
  217.                         $payload = [
  218.                             'userId' => $userId,
  219.                             'approvalHash' => $request->request->get('approvalHash'),
  220.                             'signatureData' => $encoded_data,
  221.                             'companyId' => $companyId,
  222.                             'applicantId' => $applicantId
  223.                         ];
  224.                         $curl curl_init();
  225.                         curl_setopt_array($curl, [
  226.                             CURLOPT_RETURNTRANSFER => true,
  227.                             CURLOPT_POST => true,
  228.                             CURLOPT_URL => $centralUrl,
  229.                             CURLOPT_CONNECTTIMEOUT => 10,
  230.                             CURLOPT_SSL_VERIFYPEER => false,
  231.                             CURLOPT_SSL_VERIFYHOST => false,
  232.                             CURLOPT_HTTPHEADER => [
  233.                                 'Accept: application/json',
  234.                                 'Content-Type: application/json'
  235.                             ],
  236.                             CURLOPT_POSTFIELDS => json_encode($payload)
  237.                         ]);
  238.                         $retData curl_exec($curl);
  239.                         $err curl_error($curl);
  240.                         curl_close($curl);
  241. //                             return new JsonResponse($retData);
  242.                         if ($err) {
  243.                             $this->addFlash('error''Signature sent failed: ' $err);
  244.                         } else {
  245.                             $response json_decode($retDatatrue);
  246.                             if (isset($response['success']) && $response['success'] === true) {
  247.                                 $this->addFlash('success''Signature synced successfully to CENTRAL.');
  248.                             } else {
  249.                                 $this->addFlash('error''CENTRAL server error: ' . ($response['message'] ?? 'Unknown error.'));
  250.                             }
  251.                         }
  252.                     }
  253.                 }
  254.                 // Delete temp files
  255.                 @unlink($g_path);
  256.                 @unlink($thumbPath);
  257.             }
  258.         }
  259.         return $this->render('@System/pages/settings/update_signature.html.twig', [
  260.             'page_title' => 'Update Signature',
  261.             'user_data' => $user_data,
  262.             'path' => $g_path
  263.         ]);
  264.     }
  265.     public function SignatureCheckFromCentralAction(Request $request)
  266.     {
  267.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  268.         if ($systemType !== '_CENTRAL_') {
  269.             return new JsonResponse(['success' => false'message' => 'Only allowed on CENTRAL server.'], 403);
  270.         }
  271.         $em $this->getDoctrine()->getManager('company_group');
  272.         $em->getConnection()->connect();
  273.         $data json_decode($request->getContent(), true);
  274.         if (
  275.             !$data ||
  276.             !isset($data['userId']) ||
  277.             !isset($data['companyId']) ||
  278.             !isset($data['signatureData']) ||
  279.             !isset($data['approvalHash']) ||
  280.             !isset($data['applicantId'])
  281.         ) {
  282.             return new JsonResponse(['success' => false'message' => 'Missing parameters.'], 400);
  283.         }
  284.         $userId $data['userId'];
  285.         $companyId $data['companyId'];
  286.         $signatureData $data['signatureData'];
  287.         $approvalHash $data['approvalHash'];
  288.         $applicantId $data['applicantId'];
  289.         try {
  290.             $centralUser $em
  291.                 ->getRepository("CompanyGroupBundle:EntityApplicantDetails")
  292.                 ->findOneBy(['applicantId' => $applicantId]);
  293.             if (!$centralUser) {
  294.                 return new JsonResponse(['success' => false'message' => 'Central user not found.'], 404);
  295.             }
  296.             $userAppIds json_decode($centralUser->getUserAppIds(), true);
  297.             if (!is_array($userAppIds)) $userAppIds = [];
  298.             $companies $em->getRepository('CompanyGroupBundle:CompanyGroup')->findBy([
  299.                 'appId' => $userAppIds
  300.             ]);
  301.             if (count($companies) < 1) {
  302.                 return new JsonResponse(['success' => false'message' => 'No companies found for userAppIds.'], 404);
  303.             }
  304.             $repo $em->getRepository('CompanyGroupBundle:EntitySignature');
  305.             $record $repo->findOneBy(['userId' => $userId]);
  306.             if (!$record) {
  307.                 $record = new \CompanyGroupBundle\Entity\EntitySignature();
  308.                 $record->setUserId($applicantId);
  309.                 $record->setCreatedAt(new \DateTime());
  310.             }
  311.             $record->setCompanyId($companyId);
  312.             $record->setApplicantId($applicantId);
  313.             $record->setData($signatureData);
  314.             $record->setSigExists(0);
  315.             $record->setLastDecryptedSigId(0);
  316.             $record->setUpdatedAt(new \DateTime());
  317.             $em->persist($record);
  318.             $em->flush();
  319.             $dataByServerId = [];
  320.             $gocDataListByAppId = [];
  321.             foreach ($companies as $entry) {
  322.                 $gocDataListByAppId[$entry->getAppId()] = [
  323.                     'dbName' => $entry->getDbName(),
  324.                     'dbUser' => $entry->getDbUser(),
  325.                     'dbPass' => $entry->getDbPass(),
  326.                     'dbHost' => $entry->getDbHost(),
  327.                     'serverAddress' => $entry->getCompanyGroupServerAddress(),
  328.                     'port' => $entry->getCompanyGroupServerPort() ?: 80,
  329.                     'appId' => $entry->getAppId(),
  330.                     'serverId' => $entry->getCompanyGroupServerId(),
  331.                 ];
  332.                 if (!isset($dataByServerId[$entry->getCompanyGroupServerId()]))
  333.                     $dataByServerId[$entry->getCompanyGroupServerId()] = array(
  334.                         'serverId' => $entry->getCompanyGroupServerId(),
  335.                         'serverAddress' => $entry->getCompanyGroupServerAddress(),
  336.                         'port' => $entry->getCompanyGroupServerPort() ?: 80,
  337.                         'payload' => array(
  338.                             'globalId' => $applicantId,
  339.                             'companyId' => $userAppIds,
  340.                             'signatureData' => $signatureData,
  341. //                                      'approvalHash' => $approvalHash
  342.                         )
  343.                     );
  344.             }
  345.             $urls = [];
  346.             foreach ($dataByServerId as $entry) {
  347.                 $serverAddress $entry['serverAddress'];
  348.                 if (!$serverAddress) continue;
  349. //                     $connector = $this->container->get('application_connector');
  350. //                     $connector->resetConnection(
  351. //                         'default',
  352. //                         $entry['dbName'],
  353. //                         $entry['dbUser'],
  354. //                         $entry['dbPass'],
  355. //                         $entry['dbHost'],
  356. //                         $reset = true
  357. //                     );
  358.                 $syncUrl $serverAddress '/ReceiveSignatureFromCentral';
  359.                 $payload $entry['payload'];
  360.                 $curl curl_init();
  361.                 curl_setopt_array($curl, [
  362.                     CURLOPT_RETURNTRANSFER => true,
  363.                     CURLOPT_POST => true,
  364.                     CURLOPT_URL => $syncUrl,
  365. //                         CURLOPT_PORT => $entry['port'],
  366.                     CURLOPT_CONNECTTIMEOUT => 10,
  367.                     CURLOPT_SSL_VERIFYPEER => false,
  368.                     CURLOPT_SSL_VERIFYHOST => false,
  369.                     CURLOPT_HTTPHEADER => [
  370.                         'Accept: application/json',
  371.                         'Content-Type: application/json'
  372.                     ],
  373.                     CURLOPT_POSTFIELDS => json_encode($payload)
  374.                 ]);
  375.                 $response curl_exec($curl);
  376.                 $err curl_error($curl);
  377.                 $httpCode curl_getinfo($curlCURLINFO_HTTP_CODE);
  378.                 curl_close($curl);
  379. //                     if ($err) {
  380. //                         error_log("ERP Sync Error [AppID $appId]: $err");
  381. //                          $urls[]=$err;
  382. //                     } else {
  383. //                         error_log("ERP Sync Response [AppID $appId] (HTTP $httpCode): $response");
  384. //                         $res = json_decode($response, true);
  385. //                         if (!isset($res['success']) || !$res['success']) {
  386. //                             error_log("❗ ERP Sync error for AppID $appId: " . ($res['message'] ?? 'Unknown'));
  387. //                         }
  388. //
  389. //                      $urls[]=$response;
  390. //                     }
  391.             }
  392.             return new JsonResponse(['success' => true'message' => 'Signature synced successfully.']);
  393.         } catch (\Exception $e) {
  394.             return new JsonResponse(['success' => false'message' => 'DB error: ' $e->getMessage()], 500);
  395.         }
  396.     }
  397.     public function ReceiveSignatureFromCentralAction(Request $request)
  398.     {
  399.         $data json_decode($request->getContent(), true);
  400.         if (
  401.             !$data ||
  402.             !isset($data['globalId']) ||
  403.             !isset($data['companyId']) ||
  404.             !isset($data['signatureData'])
  405.         ) {
  406.             return new JsonResponse(['success' => false'message' => 'Missing required fields'], 400);
  407.         }
  408.         $em_goc $this->getDoctrine()->getManager('company_group');
  409.         $globalId $data['globalId'];
  410.         $signatureData $data['signatureData'];
  411.         $companyId $data['companyId'];
  412.         $companies $em_goc->getRepository('CompanyGroupBundle:CompanyGroup')->findBy([
  413.             'appId' => $companyId
  414.         ]);
  415.         foreach ($companies as $entry) {
  416.             $goc = [
  417.                 'dbName' => $entry->getDbName(),
  418.                 'dbUser' => $entry->getDbUser(),
  419.                 'dbPass' => $entry->getDbPass(),
  420.                 'dbHost' => $entry->getDbHost(),
  421.                 'serverAddress' => $entry->getCompanyGroupServerAddress(),
  422.                 'port' => $entry->getCompanyGroupServerPort() ?: 80,
  423.                 'appId' => $entry->getAppId(),
  424. //                                 'serverId' => $entry->getServerId(),
  425.             ];
  426.             $connector $this->container->get('application_connector');
  427.             $connector->resetConnection(
  428.                 'default',
  429.                 $goc['dbName'],
  430.                 $goc['dbUser'],
  431.                 $goc['dbPass'],
  432.                 $goc['dbHost'],
  433.                 $reset true
  434.             );
  435.             $em $this->getDoctrine()->getManager();
  436.             $user $em->getRepository('ApplicationBundle:SysUser')->findOneBy(['globalId' => $globalId]);
  437.             if (!$user) {
  438.                 return new JsonResponse(['success' => false'message' => 'User not found'], 404);
  439.             }
  440.             $sig $em->getRepository('ApplicationBundle:EncryptedSignature')->findOneBy(['userId' => $user->getUserId()]);
  441.             if (!$sig) {
  442.                 $sig = new \ApplicationBundle\Entity\EncryptedSignature();
  443.                 $sig->setUserId($user->getUserId());
  444.                 $sig->setData($signatureData);
  445.                 $sig->setCreatedAt(new \DateTime());
  446.             }
  447.             $sig->setCompanyId($companyId);
  448.             $sig->setData($signatureData);
  449.             $sig->setSigExists(1);
  450.             $sig->setLastDecryptedSigId(0);
  451.             $sig->setUpdatedAt(new \DateTime());
  452.             $em->persist($sig);
  453.             $em->flush();
  454.         }
  455.         return new JsonResponse(['success' => true'message' => 'Signature updated in ERP']);
  456.     }
  457.     public function CheckSignatureHashAction(Request $request)
  458.     {
  459.         $details_ids = [];
  460.         $em $this->getDoctrine()->getManager();
  461.         if ($request->isMethod('POST')) {
  462.             $em $this->getDoctrine()->getManager();
  463.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  464.             $approveHash $request->request->get('approvalHash');
  465. //
  466.             $retData DocValidation::isSignatureOk($em$loginId$approveHash1);
  467. //            $this->addFlash(
  468. //                'success',
  469. //                'New Transaction Added.'
  470. //            );
  471.             return new JsonResponse(array(
  472.                 "success" => $retData['success'],
  473.                 "data" => $retData['data'],
  474.             ));
  475.         }
  476.         return $this->render('ApplicationBundle:pages/accounts/input_forms:payment_voucher.html.twig',
  477.             array(
  478.                 'test' => $details_ids,
  479.             )
  480.         );
  481.     }
  482.     public function CheckSignatureHashForAppAction(Request $request)
  483.     {
  484.         $details_ids = [];
  485.         $em $this->getDoctrine()->getManager();
  486.         if ($request->isMethod('POST')) {
  487.             $em $this->getDoctrine()->getManager();
  488.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  489.             $approveHash $request->request->get('approvalHash');
  490. //
  491.             $retData DocValidation::isSignatureOk($em$loginId$approveHash1);
  492. //            $this->addFlash(
  493. //                'success',
  494. //                'New Transaction Added.'
  495. //            );
  496.             return new JsonResponse(array(
  497.                 "success" => $retData['success'],
  498. //                "data"=>$retData['data'],
  499.             ));
  500.         }
  501.         return $this->render('ApplicationBundle:pages/accounts/input_forms:payment_voucher.html.twig',
  502.             array(
  503.                 'test' => $details_ids,
  504.             )
  505.         );
  506.     }
  507.     public function approvalRoleAction()
  508.     {
  509.         $approvalRole GeneralConstant::$approvalRoleList;
  510.         return new JsonResponse($approvalRole);
  511.     }
  512.     public function PendingApprovalListAction(Request $request)
  513.     {
  514.         $em $this->getDoctrine()->getManager();
  515.         $login_id $this->getLoggedUserLoginId($request);
  516.         $pending_data System::getPendingApprovalListByUserLoginId($em$login_id);
  517. //        $user_data=Users::getUserInfoByLoginId($em,$login_id);
  518.         //1st get only currently pendings
  519.         if ($request->request->has('getSummaryData'))
  520.             $pending_data MiscActions::getSummaryData($em$pending_data);
  521.         $pending_approval_list $pending_data['pending_approval_list'];
  522.         $override_approval_list $pending_data['override_approval_list'];
  523.         if ($request->request->has('returnJson')) {
  524.             return new JsonResponse(
  525.                 array(
  526.                     'success' => true,
  527.                     'page_title' => 'View',
  528.                     'override_approval_list' => $override_approval_list,
  529.                     'pending_approval_list' => $pending_approval_list
  530. //                'productByCodeData' => $productByCodeData,
  531. //                'productData' => $productData,
  532. //                'currInvList' => $currInvList,
  533. //                'productList' => Inventory::ProductList($em, $companyId),
  534. //                'subCategoryList' => Inventory::ProductSubCategoryList($em, $companyId),
  535. //                'categoryList' => Inventory::ProductCategoryList($em, $companyId),
  536. //                'igList' => Inventory::ItemGroupList($em, $companyId),
  537. //                'unitList' => Inventory::UnitTypeList($em),
  538. //                'brandList' => Inventory::GetBrandList($em, $companyId),
  539. //                'warehouse_action_list' => Inventory::warehouse_action_list($em,$this->getLoggedUserCompanyId($request),'object'),
  540. //                'warehouseList' => Inventory::WarehouseList($em),
  541.                 )
  542.             );
  543.         }
  544.         return $this->render('@System/pages/settings/my_pending_list.html.twig',
  545.             array(
  546.                 'page_title' => 'View',
  547.                 'override_approval_list' => $override_approval_list,
  548.                 'pending_approval_list' => $pending_approval_list
  549.             )
  550.         );
  551.     }
  552.     public function getApprovalLogAction(Request $request)
  553.     {
  554.         $em $this->getDoctrine()->getManager();
  555.         $entityId $request->query->get('entityId');
  556.         $entity $request->query->get('entity');
  557.             $doc $em->getRepository('ApplicationBundle:' GeneralConstant::$Entity_list[$entity])
  558.             ->findOneBy(
  559.                 array(
  560.                     GeneralConstant::$Entity_id_field_list[$entity] => $entityId,
  561.                 )
  562.             );
  563.         $log_data = [];
  564.         $data = [];
  565.         $pending_data = [];
  566.         $remaining_data = [];
  567.         $created_data = [];
  568.         $created_data['dt'] = [];
  569.         $edited_data = [];
  570.         $edited_data['dt'] = [];
  571.         if($doc) {
  572.             $set $em->getRepository('ApplicationBundle:Approval')
  573.                 ->findBy(
  574.                     array(
  575.                         'entity' => $entity,
  576.                         'entityId' => $entityId,
  577.                     )
  578.                 );
  579.             $roleType GeneralConstant::$approvalRole;
  580.             //        $approvalRoles=GeneralConstant::$approvalRoleForPrint;
  581.             //now add additional roles form dbase
  582.             $addRoles $em->getRepository('ApplicationBundle:ApprovalRole')
  583.                 ->findBy(
  584.                     array( //                    'id' => $v->getSigId()
  585.                     )
  586.                 );
  587.             foreach ($addRoles as $addRole) {
  588.                 $roleType[$addRole->getIndexId()] = $addRole->getName();
  589.             }
  590.             if ($doc->getCreatedLoginId() && $doc->getCreatedLoginId() != && $doc->getCreatedLoginId() != null) {
  591.                 $usrDT Users::getUserInfoByLoginId($em$doc->getCreatedLoginId());
  592.                 if (isset($usrDT['id'])) {
  593.                     $gg Users::getUserInfoByUserId($em$usrDT['id']);
  594.                     $gg['action'] = '';
  595.                     $gg['sequence'] = 0;
  596.                     $gg['actionId'] = 0;
  597.                     $gg['role'] = 1;
  598.                     $gg['roleName'] = GeneralConstant::$approvalRole[1];
  599.                     $gg['note'] = '';
  600.                     $gg['current'] = 0;
  601.                     $gg['loginIp'] = $usrDT['loginIp'];
  602.                     $gg['dateTs'] = $doc->getCreatedAt()->format('U');
  603.                     $data[] = $gg;
  604.                 }
  605.             }
  606.             if ($doc->getEditedLoginId() != null && $doc->getEditedLoginId() != 0) {
  607.                 $usrDT Users::getUserInfoByLoginId($em$doc->getEditedLoginId());
  608.                 if (isset($usrDT['id'])) {
  609.                     $gg Users::getUserInfoByUserId($em$usrDT['id']);
  610.                     $gg['action'] = '';
  611.                     $gg['sequence'] = 0;
  612.                     $gg['actionId'] = 0;
  613.                     $gg['role'] = 2;
  614.                     $gg['roleName'] = GeneralConstant::$approvalRole[2];
  615.                     $gg['note'] = '';
  616.                     $gg['current'] = 0;
  617. //                $gg['date'] = $doc->getUpdatedAt();
  618.                     $gg['loginIp'] = $usrDT['loginIp'];
  619.                     $gg['dateTs'] = $doc->getUpdatedAt()->format('U');
  620.                     $data[] = $gg;
  621.                 }
  622.             }
  623.             //        $remaining_data=[];
  624.             foreach ($roleType as $key => $value) {
  625.                 $log_data[$key] = array(
  626.                     'role_name' => $value,
  627.                     'dt' => []
  628.                 );
  629.             }
  630.             foreach ($set as $entry) {
  631.                 if ($entry->getAction() == 3) {
  632.                     foreach (json_decode($entry->getUserIds(), true) as $item)
  633.                         if ($item != null) {
  634.                             $gg Users::getUserInfoByUserId($em$item);
  635.                             $gg['action'] = GeneralConstant::$approvalAction[$entry->getAction()];
  636.                             $gg['sequence'] = $entry->getSequence();
  637.                             $gg['actionId'] = $entry->getAction();
  638.                             $gg['role'] = $entry->getRoleType();
  639.                             $gg['roleName'] = GeneralConstant::$approvalRole[$entry->getRoleType()];
  640.                             $gg['note'] = $entry->getNote();
  641.                             $gg['current'] = $entry->getCurrent() == GeneralConstant::CURRENTLY_PENDING_APPROVAL 0;
  642.                             $gg['dateTs'] = $doc->getUpdatedAt()->format('U');
  643.                             $data[] = $gg;
  644.                         }
  645.                 } else {
  646.                     $usrDT Users::getUserInfoByLoginId($em$doc->getCreatedLoginId());
  647.                     if (isset($usrDT['id'])) {
  648.                         $gg Users::getUserInfoByUserId($em$usrDT['id']);
  649.                         $gg['action'] = GeneralConstant::$approvalAction[$entry->getAction()];
  650.                         $gg['sequence'] = $entry->getSequence();
  651.                         $gg['actionId'] = $entry->getAction();
  652.                         $gg['role'] = $entry->getRoleType();
  653.                         $gg['roleName'] = GeneralConstant::$approvalRole[$entry->getRoleType()];
  654.                         $gg['note'] = $entry->getNote();
  655.                         $gg['current'] = $entry->getCurrent() == GeneralConstant::CURRENTLY_PENDING_APPROVAL 0;
  656.                         $gg['dateTs'] = $usrDT['logTime']->format('U');
  657.                         $gg['loginIp'] = $usrDT['loginIp'];
  658.                         $data[] = $gg;
  659.                     }
  660.                 }
  661.             }
  662.         }
  663.         return new JsonResponse([
  664.             "message" => !empty($data) ? "success" "false",
  665.             "data" => empty($data) ? "No data found using the entity" $data
  666.         ]);
  667.     }
  668.     public function getDocumentDataAction(Request $request)
  669.     {
  670.         $entityListDetails GeneralConstant::$Entity_list_details;
  671.         $entityListForApp = [];
  672.         foreach ($entityListDetails as $id => $entity) {
  673.             $entityListForApp[] = [
  674.                 'id' => $id,
  675.                 'entity_alias' => $entity['entity_alias'],
  676.                 'imageUrl' => 'https://ibb.co.com/4RBXD5pt' // Placeholder URL
  677.             ];
  678.         }
  679.         return new JsonResponse($entityListForApp);
  680.     }
  681.     public function documentSummaryAction(Request $request)
  682.     {
  683.         $documentList GeneralConstant::$documentSummaryList;
  684.         return new JsonResponse($documentList);
  685.     }
  686. }