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