src/ApplicationBundle/Controller/ApprovalController.php line 121

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Controller;
  3. use ApplicationBundle\Constants\AccountsConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\UserConstants;
  6. use ApplicationBundle\Entity\AccCheck;
  7. use ApplicationBundle\Entity\AccCostCentre;
  8. use ApplicationBundle\Entity\AccSettings;
  9. use ApplicationBundle\Entity\CheckFormat;
  10. use ApplicationBundle\Entity\EncryptedSignature;
  11. use ApplicationBundle\Helper\Generic;
  12. use ApplicationBundle\Interfaces\SessionCheckInterface;
  13. use ApplicationBundle\Modules\Accounts\Accounts;
  14. use ApplicationBundle\Modules\Inventory\Inventory;
  15. use ApplicationBundle\Modules\Purchase\Purchase;
  16. use ApplicationBundle\Modules\System\DocValidation;
  17. use ApplicationBundle\Modules\User\Company;
  18. use ApplicationBundle\Modules\System\System;
  19. use ApplicationBundle\Modules\System\MiscActions;
  20. use ApplicationBundle\Modules\User\Users;
  21. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use ApplicationBundle\Entity\AccTransactions;
  25. use Symfony\Component\HttpFoundation\JsonResponse;
  26. use Symfony\Component\Routing\Generator\UrlGenerator;
  27. use Symfony\Component\Validator\Constraints\DateTime;
  28. class ApprovalController extends GenericController implements SessionCheckInterface
  29. {
  30.     public function ApproveDocumentAction(Request $request)
  31.     {
  32.         $em $this->getDoctrine()->getManager();
  33.         if ($request->isMethod('POST')) {
  34.             if(isset(GeneralConstant::$Entity_list_details$request->request->get('approvalEntity')]['entity_view_route_path_name']))
  35.             $url $this->generateUrl(
  36.                 GeneralConstant::$Entity_list_details$request->request->get('approvalEntity')]['entity_view_route_path_name']
  37.             );
  38.             else
  39.             {
  40.                 $url='';
  41.             }
  42.             $options=array(
  43.                 'notification_enabled'=>$this->container->getParameter('notification_enabled'),
  44.                 'notification_server'=>$this->container->getParameter('notification_server'),
  45. //                'appId'=>$request->getSession()->get(UserConstants::USER_APP_ID),
  46. //                'url'=>$this->generateUrl(
  47. //                    GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']
  48. //                )
  49.             );
  50.             if($request->request->has('approvalAction')) {
  51.                 $message System::approveDocument(
  52.                     $em,
  53.                     $options,
  54.                     $request->request->get('approvalEntity'),
  55.                     $request->request->get('approvalEntityId'),
  56.                     $request->request->get('approvalId'),
  57.                     $this->getLoggedUserLoginId($request),
  58.                     $request->request->get('approvalAction'),
  59.                     $request->request->get('approvalNote'),
  60.                     $request->request->get('approvalHash'),
  61.                     $url,
  62.                     $request->request->get('forwardTo'),
  63.                     $this->get('mail_module')
  64.                 );
  65. //            $url = $this->generateUrl(
  66. //                GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']
  67. //            );
  68. //            if(!empty($currentApprovalData['UserIdList']))
  69. //            System::AddNewNotification(
  70. //                $this->container->getParameter('notification_enabled'),
  71. //                $this->container->getParameter('notification_server'),$request->getSession()->get(UserConstants::USER_APP_ID),
  72. //                $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  73. //                "Approval: ".GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_alias'].": " . $message['docHash'] . " is pending Your approval",
  74. //                'user',
  75. //                $message['UserIdList'],
  76. //                'information',
  77. ////                GeneralConstant::$Entity_list_details[$entity_id]."/".$projectId,
  78. //                $url . "/" . $request->request->get('approvalEntityId'),
  79. //                "Approval Pending"
  80. //
  81. //            );
  82. //            $this->addFlash(
  83. //                $message[0],
  84. //                $message[1]
  85. //            );
  86.                 if ($message['success'] == true)
  87.                     return new JsonResponse(array("success" => true,
  88.                             'message' => $message,
  89.                             'approvalEntity' => $request->request->get('approvalEntity'),
  90.                             'approvalEntityId' => $request->request->get('approvalEntityId'),
  91.                             'approvalId' => $request->request->get('approvalId'),
  92.                             'approvalAction' => $request->request->get('approvalAction'),
  93.                         )
  94.                     );
  95.                 else
  96.                     return new JsonResponse(array("success" => false'message' => $message,
  97.                             'approvalEntity' => $request->request->get('approvalEntity'),
  98.                             'approvalEntityId' => $request->request->get('approvalEntityId'),
  99.                             'approvalId' => $request->request->get('approvalId'),
  100.                             'approvalAction' => $request->request->get('approvalAction'),
  101.                         )
  102.                     );
  103.             }
  104.             return new JsonResponse(array("success"=>false));
  105.         }
  106. //        $userList=$this->get('user_module')->showUserList();
  107.         return new JsonResponse(array("success"=>false));
  108.     }
  109.     public function getPendingApprovalListForUserAction(Request $request)
  110.     {
  111.         $em $this->getDoctrine()->getManager();
  112.         $absoluteUrlList=[];
  113.         foreach(GeneralConstant::$Entity_list_details as $e=>$d)
  114.         {
  115.             if(isset($d['entity_view_route_path_name']))
  116.                 $absoluteUrlList[$e]=$this->generateUrl($d['entity_view_route_path_name'], [], UrlGenerator::ABSOLUTE_URL);
  117.         }
  118.         return new JsonResponse(System::getPendingApprovalListByUserLoginId($em$this->getLoggedUserLoginId($request),1,$absoluteUrlList));
  119.     }
  120.     public function UpdateSignatureAction(Request $request
  121.     {
  122.         $em $this->getDoctrine()->getManager();
  123.         $g_path='';
  124.         $user_data=Users::getUserInfoByLoginId($em,$this->getLoggedUserLoginId($request));
  125.         if ($request->isMethod('POST')) {
  126.             $post $request->request;
  127.             $path="";
  128.             $extension_here='';
  129.             foreach($request->files as $uploadedFile) {
  130.                 if($uploadedFile!=null) {
  131.                     $extension_here=$uploadedFile->guessExtension();
  132.                     $fileName md5(uniqid()) . '.' $uploadedFile->guessExtension();
  133.                     $path $fileName;
  134.                     $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/FileUploads/';
  135.                     if (!file_exists($upl_dir)) {
  136.                         mkdir($upl_dir0777true);
  137.                     }
  138.                     $file $uploadedFile->move($upl_dir$path);
  139.                 }
  140.             }
  141.             if($path!="")
  142.                 $file_path='uploads/FileUploads/'.$path;
  143.             $g_path $this->container->getParameter('kernel.root_dir') . '/../web/uploads/FileUploads/'$path;
  144.             $img_file file_get_contents($g_path);
  145.             //new one
  146.             list($width$height) = getimagesize($g_path);
  147.             $percent=(200/$width);
  148.             $newwidth $width $percent;
  149.             $newheight $height $percent;
  150.             $thumb imagecreatetruecolor($newwidth$newheight);
  151.             if($extension_here=='jpg'||$extension_here=='jpeg')
  152.             $source imagecreatefromjpeg($g_path);
  153.             if($extension_here=='png')
  154.                 $source imagecreatefrompng($g_path);
  155. // Resize
  156.             imagecopyresampled($thumb$source0000$newwidth$newheight$width$height);
  157. //            ob_start();
  158.             imagepng($thumb,$this->container->getParameter('kernel.root_dir') . '/../web/uploads/FileUploads/th.png');
  159.             $th_file=file_get_contents($this->container->getParameter('kernel.root_dir') . '/../web/uploads/FileUploads/th.png');
  160.             //new one ends
  161. //            $image_data=base64_encode($img_file);
  162.             $image_data=base64_encode($th_file);
  163.             $encoded_data=System::encryptSignature($image_data,$request->request->get('approvalHash'));
  164.             if($encoded_data!=false)
  165.             {
  166.                 $query_here=$this->getDoctrine()
  167.                     ->getRepository('ApplicationBundle:EncryptedSignature')
  168.                     ->findOneBy(
  169.                         array(
  170.                             'userId'=>$request->request->get('userId')
  171.                         )
  172.                     );
  173.                 if($query_here)
  174.                 {
  175.                     $new=$query_here;
  176. //                    $new->setRefreshFlag(1);
  177.                     $new->setSigExists(0);
  178.                     $new->setLastDecryptedSigId(0);
  179.                     $new->setData($encoded_data);
  180.                 }
  181.                 else
  182.                 {
  183.                     $new=new EncryptedSignature();
  184.                     $new->setData($encoded_data);
  185.                     $new->setUserId($request->request->get('userId'));
  186. //                    $new->setRefreshFlag(1);
  187.                     $new->setSigExists(0);
  188.                     $new->setLastDecryptedSigId(0);
  189.                     $em->persist($new);
  190.                 }
  191.                 $em->flush();
  192.             }
  193. //            now deleting the file
  194.             if (!unlink($g_path))
  195.             {
  196. //                echo ("Error deleting $file");
  197.             }
  198.             else
  199.             {
  200. //                echo ("Deleted $file");
  201.             }
  202.             if (!unlink($this->container->getParameter('kernel.root_dir') . '/../web/uploads/FileUploads/th.png'))
  203.             {
  204. //                echo ("Error deleting $file");
  205.             }
  206.             else
  207.             {
  208. //                echo ("Deleted $file");
  209.             }
  210.         }
  211. //        $userList=$this->get('user_module')->showUserList();
  212.         return $this->render('ApplicationBundle:pages/system/settings:update_signature.html.twig',
  213.             array(
  214.                 'page_title'=>'Update Signature',
  215.                 'user_data'=>$user_data,
  216.                 'path'=>$g_path
  217. //                'incomeLedgerHeads'=>Accounts::getChildLedgerHeads($this->getDoctrine()->getManager(),AccountsConstant::INCOME)
  218.             )
  219.         );
  220.     }
  221.     public function CheckSignatureHashAction(Request $request)
  222.     {
  223.         $details_ids=[];
  224.         $em=$this->getDoctrine()->getManager();
  225.         if($request->isMethod('POST')) {
  226.             $em=$this->getDoctrine()->getManager();
  227.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  228.             $approveHash=$request->request->get('approvalHash');
  229. //
  230.             $retData=DocValidation::isSignatureOk($em,$loginId,$approveHash,1);
  231. //            $this->addFlash(
  232. //                'success',
  233. //                'New Transaction Added.'
  234. //            );
  235.             return new JsonResponse(array(
  236.                 "success"=>$retData['success'],
  237.                 "data"=>$retData['data'],
  238.             ));
  239.         }
  240.         return $this->render('ApplicationBundle:pages/accounts/input_forms:payment_voucher.html.twig',
  241.             array(
  242.                 'test'=>$details_ids,
  243.             )
  244.         );
  245.     }
  246.     public function PendingApprovalListAction(Request $request)
  247.     {
  248.         $em=$this->getDoctrine()->getManager();
  249.         $login_id=$this->getLoggedUserLoginId($request);
  250.         $pending_data=System::getPendingApprovalListByUserLoginId($em,$login_id);
  251. //        $user_data=Users::getUserInfoByLoginId($em,$login_id);
  252.         //1st get only currently pendings
  253.          if($request->request->has('getSummaryData'))
  254.             $pending_data=MiscActions::getSummaryData($em,$pending_data);
  255.         $pending_approval_list=$pending_data['pending_approval_list'];
  256.         $override_approval_list=$pending_data['override_approval_list'];
  257.         if ($request->request->has('returnJson')) {
  258.             return new JsonResponse(
  259.                 array(
  260.                     'success' => true,
  261.                     'page_title'=>'View',
  262.                     'override_approval_list'=>$override_approval_list,
  263.                     'pending_approval_list'=>$pending_approval_list
  264. //                'productByCodeData' => $productByCodeData,
  265. //                'productData' => $productData,
  266. //                'currInvList' => $currInvList,
  267. //                'productList' => Inventory::ProductList($em, $companyId),
  268. //                'subCategoryList' => Inventory::ProductSubCategoryList($em, $companyId),
  269. //                'categoryList' => Inventory::ProductCategoryList($em, $companyId),
  270. //                'igList' => Inventory::ItemGroupList($em, $companyId),
  271. //                'unitList' => Inventory::UnitTypeList($em),
  272. //                'brandList' => Inventory::GetBrandList($em, $companyId),
  273. //                'warehouse_action_list' => Inventory::warehouse_action_list($em,$this->getLoggedUserCompanyId($request),'object'),
  274. //                'warehouseList' => Inventory::WarehouseList($em),
  275.                 )
  276.             );
  277.         }
  278.         return $this->render('ApplicationBundle:pages/system/settings:my_pending_list.html.twig',
  279.             array(
  280.                 'page_title'=>'View',
  281.                 'override_approval_list'=>$override_approval_list,
  282.                 'pending_approval_list'=>$pending_approval_list
  283.             )
  284.         );
  285.     }
  286. }