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