src/ApplicationBundle/Twig/GeneralExtension.php line 27

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Twig;
  3. use ApplicationBundle\Constants\BuddybeeConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\TaskConstant;
  6. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  7. use ApplicationBundle\Modules\Comment\Comment;
  8. use ApplicationBundle\Modules\HumanResource\HumanResource;
  9. use ApplicationBundle\Modules\Inventory\Inventory;
  10. use ApplicationBundle\Modules\Purchase\Purchase;
  11. use ApplicationBundle\Modules\Purchase\Supplier;
  12. use ApplicationBundle\Modules\Sales\Client;
  13. use ApplicationBundle\Modules\Sales\SalesOrderM;
  14. use ApplicationBundle\Modules\System\System;
  15. use ApplicationBundle\Modules\User\Company;
  16. use ApplicationBundle\Modules\User\Department;
  17. use ApplicationBundle\Modules\User\Module;
  18. use ApplicationBundle\Modules\User\Position;
  19. use ApplicationBundle\Modules\User\Users;
  20. use Symfony\Component\HttpFoundation\Session\Session;
  21. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  22. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  23. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  24. use Symfony\Component\Serializer\Serializer;
  25. class GeneralExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
  26. {
  27.     protected $em;
  28.     protected $em_goc;
  29.     protected $dm;
  30.     protected $encryptDecrypt;
  31.     public function __construct(\Doctrine\ORM\EntityManager $em, \Doctrine\ORM\EntityManager $em_goc, \ApplicationBundle\Helper\EncryptDecrypt $encryptDecrypt)
  32.     {
  33.         $this->em $em;
  34.         $this->em_goc $em_goc;
  35.         //        $this->dm = $dm;
  36.         $this->encryptDecrypt $encryptDecrypt;
  37.     }
  38.     public function getFilters()
  39.     {
  40.         return array(
  41.             'functionExists' => new \Twig_SimpleFilter('functionExists', array($this'functionExists')),
  42.             'getMicroTime' => new \Twig_SimpleFilter('getMicroTime', array($this'getMicroTime')),
  43.             'isPhpSeven' => new \Twig_SimpleFilter('isPhpSeven', array($this'isPhpSeven')),
  44.             'getGlobalEncryptedDocInfo' => new \Twig_SimpleFilter('getGlobalEncryptedDocInfo', array($this'getGlobalEncryptedDocInfo')),
  45.             'getConvMultFromToWithdrawable' => new \Twig_SimpleFilter('getConvMultFromToWithdrawable', array($this'getConvMultFromToWithdrawable')),
  46.             'getCurrencyListByMarker' => new \Twig_SimpleFilter('getCurrencyListByMarker', array($this'getCurrencyListByMarker')),
  47.             'getDocumentDataDetails' => new \Twig_SimpleFilter('getDocumentDataDetails', array($this'getDocumentDataDetails')),
  48.             'getDocumentDataDetailsForView' => new \Twig_SimpleFilter('getDocumentDataDetailsForView', array($this'getDocumentDataDetailsForView')),
  49.             'getCurrencyList' => new \Twig_SimpleFilter('getCurrencyList', array($this'getCurrencyList')),
  50.             'imageToBase64Encode' => new \Twig_SimpleFilter('imageToBase64Encode', array($this'imageToBase64Encode')),
  51.             'strToHex' => new \Twig_SimpleFilter('strToHex', array($this'strToHex')),
  52.             'toHex' => new \Twig_SimpleFilter('toHex', array($this'toHex')),
  53. //            'getGlobalVars'   => new \Twig_SimpleFilter('getGlobalVars', array($this, 'getGlobals')),
  54.             'jsonDecode' => new \Twig_SimpleFilter('jsonDecode', array($this'jsonDecode')),
  55.             'strpad' => new \Twig_SimpleFilter('strpad', array($this'strpad')),
  56.             'getRandomColor' => new \Twig_SimpleFilter('getRandomColor', array($this'getRandomColor')),
  57.             'getCommentsForDocument' => new \Twig_SimpleFilter('getCommentsForDocument', array($this'getCommentsForDocument')),
  58.             'doSerialize' => new \Twig_SimpleFilter('doSerialize', array($this'doSerialize')),
  59.             'getUsers' => new \Twig_SimpleFilter('getUsers', array($this'getUsers')),
  60.             'getExpSubTypes' => new \Twig_SimpleFilter('getExpSubTypes', array($this'getExpSubTypes')),
  61.             'getUserRestrictions' => new \Twig_SimpleFilter('getUserRestrictions', array($this'getUserRestrictions')),
  62.             'PendingDocList' => new \Twig_SimpleFilter('PendingDocList', array($this'PendingDocList')),
  63.             'getSystemNotice' => new \Twig_SimpleFilter('getSystemNotice', array($this'getSystemNotice')),
  64.             'getProductDataFromFDM' => new \Twig_SimpleFilter('getProductDataFromFDM', array($this'getProductDataFromFDM')),
  65.             'getPositions' => new \Twig_SimpleFilter('getPositions', array($this'getPositions')),
  66.             'getSegregationSettings' => new \Twig_SimpleFilter('getSegregationSettings', array($this'getSegregationSettings')),
  67.             'getLeaveSettings' => new \Twig_SimpleFilter('getLeaveSettings', array($this'getLeaveSettings')),
  68.             'getDepartments' => new \Twig_SimpleFilter('getDepartments', array($this'getDepartments')),
  69.             'getCompanies' => new \Twig_SimpleFilter('getCompanies', array($this'getCompanies')),
  70.             'getCountries' => new \Twig_SimpleFilter('getCountries', array($this'getCountries')),
  71.             'getCountriesBuddyBee' => new \Twig_SimpleFilter('getCountriesBuddyBee', array($this'getCountriesBuddyBee')),
  72.             'getLanguagesBuddyBee' => new \Twig_SimpleFilter('getLanguagesBuddyBee', array($this'getLanguagesBuddyBee')),
  73.             'getBranchList' => new \Twig_SimpleFilter('getBranchList', array($this'getBranchList')),
  74.             'getDataForAddProductService' => new \Twig_SimpleFilter('getDataForAddProductService', array($this'getDataForAddProductService')),
  75.             'getRegionList' => new \Twig_SimpleFilter('getRegionList', array($this'getRegionList')),
  76.             'getGeographicalRegionList' => new \Twig_SimpleFilter('getGeographicalRegionList', array($this'getGeographicalRegionList')),
  77.             'getClientList' => new \Twig_SimpleFilter('getClientList', array($this'getClientList')),
  78.             'getClientTypeList' => new \Twig_SimpleFilter('getClientTypeList', array($this'getClientTypeList')),
  79.             'getSalesPersonList' => new \Twig_SimpleFilter('getSalesPersonList', array($this'getSalesPersonList')),
  80.             'getColors' => new \Twig_SimpleFilter('getColors', array($this'getColors')),
  81.             'getTaxList' => new \Twig_SimpleFilter('getTaxList', array($this'getTaxList')),
  82.             'getCountriesIndexed' => new \Twig_SimpleFilter('getCountriesIndexed', array($this'getCountriesIndexed')),
  83.             'getUserCompany' => new \Twig_SimpleFilter('getUserCompany', array($this'getUserCompany')),
  84.             'getSupplierDataForSupplierLogin' => new \Twig_SimpleFilter('getSupplierDataForSupplierLogin', array($this'getSupplierDataForSupplierLogin')),
  85.             'getClientDataForClientLogin' => new \Twig_SimpleFilter('getClientDataForClientLogin', array($this'getClientDataForClientLogin')),
  86.             'getMonthlySummary' => new \Twig_SimpleFilter('getMonthlySummary', array($this'getMonthlySummary')),
  87.             'getRecentSales' => new \Twig_SimpleFilter('getRecentSales', array($this'getRecentSales')),
  88.             'getSoCountAndMore' => new \Twig_SimpleFilter('getSoCountAndMore', array($this'getSoCountAndMore')),
  89.             'getRecentPurchase' => new \Twig_SimpleFilter('getRecentPurchase', array($this'getRecentPurchase')),
  90.             'getPositionModuleTree' => new \Twig_SimpleFilter('getPositionModuleTree', array($this'getPositionModuleTree')),
  91.             'showNecessaryMenu' => new \Twig_SimpleFilter('showNecessaryMenu', array($this'showNecessaryMenu')),
  92.             'showMenuIfAdmin' => new \Twig_SimpleFilter('showMenuIfAdmin', array($this'showMenuIfAdmin')),
  93.             'showNecessaryMenuGeneral' => new \Twig_SimpleFilter('showNecessaryMenuGeneral', array($this'showNecessaryMenuGeneral')),
  94.             'showNecessaryCreateBtn' => new \Twig_SimpleFilter('showNecessaryCreateBtn', array($this'showNecessaryCreateBtn')),
  95.             'todoSummaryList' => new \Twig_SimpleFilter('todoSummaryList', array($this'todoSummaryList')),
  96.             'getEntityDetailsByName' => new \Twig_SimpleFilter('getEntityDetailsByName', array($this'getEntityDetailsByName')),
  97.             'inArray' => new \Twig_SimpleFilter('inArray', array($this'inArray')),
  98.             'encryptMe' => new \Twig_SimpleFilter('encryptMe', array($this'encryptMe')),
  99.             'decryptMe' => new \Twig_SimpleFilter('decryptMe', array($this'decryptMe')),
  100.         );
  101.     }
  102.     public function getFunctions(): array
  103.     {
  104.         return [
  105.             new \Twig\TwigFunction('call_method', [$this'callMethod']),
  106.         ];
  107.     }
  108. //    function qr_code_data_uri($qr_data, $options){
  109. //        qr_code_data_uri($qr_data, $options);
  110. //    }
  111.     public function isPhpSeven($gg='')
  112.     {
  113.         if (version_compare(PHP_VERSION'7.3.0''>=')) {
  114.             return true;
  115.         } else {
  116.             return false;
  117.         }
  118.     }
  119.     public function isMethodExist($object$method)
  120.     {
  121.         return method_exists($object$method);
  122.     }
  123.     public function functionExists($method)
  124.     {
  125.         return function_exists($method) ? $method 'pika' $method 'chu';
  126.     }
  127.     public function getGlobals()
  128.     {
  129.         $session = new Session();
  130.         $class = new \ReflectionClass('ApplicationBundle\Modules\Authentication\Constants\UserConstants');
  131.         $UserConstants $class->getConstants();
  132.         $class = new \ReflectionClass('ApplicationBundle\Constants\BuddybeeConstant');
  133.         $BuddybeeConstant $class->getConstants();
  134.         $classToDoConstant = new \ReflectionClass('ApplicationBundle\Constants\TaskConstant');
  135.         $ToDoConstant $classToDoConstant->getConstants();
  136.         $classTicketConstant = new \ReflectionClass('ApplicationBundle\Constants\TicketConstant');
  137.         $TicketConstant $classTicketConstant->getConstants();
  138.         //        $classReportConstant = new \ReflectionClass('ApplicationBundle\Constants\ReportConstant');
  139.         $classReportConstant = new \ReflectionClass('ApplicationBundle\Constants\ReportConstant');
  140.         return array(
  141.             'session' => $session->all(),
  142.             'url_get' => $_GET,
  143.             'UserConstants' => $UserConstants,
  144.             'BuddybeeConstant' => $BuddybeeConstant,
  145.             'TaskConstant' => $ToDoConstant,
  146.             'TicketConstant' => $TicketConstant,
  147.             'globalReportTypeList' => $classReportConstant->getStaticPropertyValue('reportTypeList'),
  148.             'enabled_report_types' => ['pika' => 'chu']
  149.         );
  150.     }
  151.     function imageToBase64Encode($imagePath)
  152.     {
  153.         $img file_get_contents(
  154.             $imagePath
  155.         );
  156.         return base64_encode($img);
  157.     }
  158.     function getConvMultFromToWithdrawable()
  159.     {
  160.         return BuddybeeConstant::$convMultFromToWithdrawable;
  161.     }
  162.     function getEntityDetailsByName($entityName)
  163.     {
  164.        return GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)[$entityName]];
  165.     }
  166.     function getCurrencyListByMarker()
  167.     {
  168.         return BuddybeeConstant::$currency_List_by_marker;
  169.     }
  170.     function strpad($input$padlength$padstring ''$pad_type STR_PAD_LEFT)
  171.     {
  172.         return str_pad($input$padlength$padstring$pad_type);
  173.     }
  174.     function getRandomColor($rmax 200$gmax 200$bmax 200$a 1)
  175.     {
  176.         return '' rand(0$rmax) . ',' rand(0$gmax) . ',' rand(0$bmax);
  177.     }
  178.     public function doSerialize($str)
  179.     {
  180.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  181.         $normalizers = array(new ObjectNormalizer());
  182.         $serializer = new Serializer($normalizers$encoders);
  183.         return $serializer->serialize($str'json');
  184.     }
  185.     public function jsonDecode($str$assoc true$bias JSON_BIGINT_AS_STRING)
  186.     {
  187.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  188.             $obj json_decode($str$assoc512JSON_BIGINT_AS_STRING);
  189.         } else {
  190.             $max_int_length strlen((string)PHP_INT_MAX) - 1;
  191.             $json_without_bigints preg_replace('/:\s*(-?\d{' $max_int_length ',})/'': "$1"'$str);
  192.             $obj json_decode($json_without_bigints$assoc);
  193.         }
  194.         //        return json_decode($str,$assoc,512,$bias);
  195.         if ($obj == null)
  196.             $obj = [];
  197.         return $obj;
  198.     }
  199.     public function getUserRestrictions()
  200.     {
  201.         $session = new Session();
  202.         return Users::getUserApplicationAccessSettings($this->em$session->get(UserConstants::USER_ID))['options'];
  203.     }
  204.     public function getGlobalEncryptedDocInfo($entityName='',$docId=0,$appId='_auto_')
  205.     {
  206.         $session = new Session();
  207.         $golbalId='';
  208.         $companyHash='';
  209.         if($appId=='_auto_')
  210.             $appId$session->get(UserConstants::USER_APP_ID);
  211.        $companyHereCompany::getCurrentCompanyInfo($this->em,$appId);
  212.        $entityIdentifier=0;
  213.        $entityList=GeneralConstant::$Entity_list;
  214.        if($entityName!='')
  215.            $entityIdentifier=array_flip(GeneralConstant::$Entity_list)[$entityName];
  216.        if(isset($companyHere['id']))
  217.        {
  218.            $golbalId'D'.str_pad($appId50STR_PAD_LEFT).str_pad($entityIdentifier20STR_PAD_LEFT).str_pad($docId80STR_PAD_LEFT);
  219.            $companyHash=$companyHere['companyHash'];
  220.        }
  221.         return array(
  222.             'id'=>$golbalId,
  223.             'companyHash'=>$companyHash,
  224.         );
  225.     }
  226.     public function getCurrencyList()
  227.     {
  228.         $session = new Session();
  229.         return Inventory::CurrencyList($this->em);
  230.     }
  231. public function getDocumentDataDetailsForView($documentDataId,$columnsEnabled=[],$viewType='view')
  232.     {
  233.         $session = new Session();
  234.         return SalesOrderM::GetDocumentDataDetailsForView($this->em,$documentDataId,$columnsEnabled,$viewType);
  235.     }
  236.     public function getDocumentDataDetails($documentDataId,$skipRowData=0)
  237.     {
  238.         $session = new Session();
  239.         return SalesOrderM::GetDocumentDataDetails($this->em,$documentDataId,$skipRowData);
  240.     }
  241.     public function getCountries()
  242.     {
  243.         return Company::getCountryList($this->em);
  244.     }
  245.     public function getCountriesBuddyBee($type ""$returnType '')
  246.     {
  247.         if ($type == '_ALL_')
  248.             return Company::getCountryList($this->em_goc'_BUDDYBEE_ALL_'$returnType);
  249.         else if ($type == '_HAS_CONSULTANT_')
  250.             return Company::getCountryList($this->em_goc'_HAS_CONSULTANT_'$returnType);
  251.         else
  252.             return Company::getCountryList($this->em_goc'_BUDDYBEE_'$returnType);
  253. //        return BuddybeeConstant::$buddybee_country_List;
  254.     }
  255.     public function getLanguagesBuddyBee($type ""$returnType '')
  256.     {
  257.         if ($type == '_ALL_')
  258.             return Company::getLanguageList($this->em_goc'_BUDDYBEE_ALL_'$returnType);
  259.         else
  260.             return Company::getLanguageList($this->em_goc'_BUDDYBEE_'$returnType);
  261. //        return BuddybeeConstant::$buddybee_country_List;
  262.     }
  263.     public function getBranchList($types ''$companyId = [])
  264.     {
  265.         if ($types == ''$types = [];
  266.         return Client::BranchList($this->em$companyId$types);
  267.     }
  268.     public function getRegionList($types '')
  269.     {
  270.         if ($types == ''$types = [];
  271.         $session = new Session();
  272.         return Client::RegionList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  273.     }
  274.     public function getGeographicalRegionList($types '')
  275.     {
  276.         if ($types == ''$types = [];
  277.         $session = new Session();
  278.         return Client::GeographicalRegionList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  279.     }
  280.     public function getClientList($types '')
  281.     {
  282.         if ($types == ''$types = [];
  283.         $session = new Session();
  284.         return Client::GetExistingClientList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  285.     }
  286.     public function getClientTypeList($types '')
  287.     {
  288.         if ($types == ''$types = [];
  289.         $session = new Session();
  290.         return Client::ClientTypeList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  291.     }
  292.     public function getSalesPersonList($types '')
  293.     {
  294.         if ($types == ''$types = [];
  295.         $session = new Session();
  296.         return Client::SalesPersonList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  297.     }
  298.     public function getColors()
  299.     {
  300.         return Inventory::GetColorList($this->em);
  301.     }
  302.     public function getTaxList()
  303.     {
  304.         return Inventory::GetTaxList($this->em);
  305.     }
  306.     public function getCommentsForDocument($entity$entityId$appId$isEntityComment 0$conversationHash '')
  307.     {
  308.         if ($isEntityComment == 1)
  309.         {
  310.             if ($conversationHash == '')
  311.                 $conversationHash 'D' . (str_pad($appId5'0'STR_PAD_LEFT)) . (str_pad($entity2'0'STR_PAD_LEFT)) . (str_pad($entityId8'0'STR_PAD_LEFT));
  312.             return array(
  313.                 'commentList' => Comment::getCommentsByConversationHash($this->em_goc$conversationHash$isEntityComment),
  314.                 'hash' => $conversationHash
  315.             );
  316.         }
  317.         else {
  318.             if ($conversationHash == '')
  319.                 $conversationHash 'D' . (str_pad($appId5'0'STR_PAD_LEFT)) . (str_pad($entity2'0'STR_PAD_LEFT)) . (str_pad($entityId8'0'STR_PAD_LEFT));
  320.             return array(
  321.                 'commentList' => Comment::getCommentsByConversationHash($this->em$conversationHash$isEntityComment),
  322.                 'hash' => $conversationHash
  323.             );
  324.         }
  325.     }
  326.     public function getCountriesIndexed()
  327.     {
  328.         return Company::getCountryListIndexed($this->em);
  329.     }
  330.     public function getProductDataFromFDM($FDM)
  331.     {
  332.         $ret_data = array(
  333.             'igId' => 0,
  334.             'categoryId' => 0,
  335.             'subCategoryId' => 0,
  336.             'brandId' => 0,
  337.             'productId' => 0,
  338.             'FDM_MODIFIED' => $FDM
  339.         );
  340.         $session = new Session();
  341.         return Inventory::GetProductDataFromFdm($this->em$FDM$session->get(UserConstants::USER_COMPANY_ID));
  342. //        $FDM_ARRAY = explode('_', $FDM);
  343. //
  344. //        $ret_data['igId'] = isset($FDM_ARRAY[0]) ? (1 * $FDM_ARRAY[0]) : 0;
  345. //        $ret_data['categoryId'] = isset($FDM_ARRAY[1]) ? (1 * $FDM_ARRAY[1]) : 0;
  346. //        $ret_data['subCategoryId'] = isset($FDM_ARRAY[2]) ? (1 * $FDM_ARRAY[2]) : 0;
  347. //        $ret_data['brandId'] = isset($FDM_ARRAY[3]) ? (1 * $FDM_ARRAY[3]) : 0;
  348. //        $ret_data['productId'] = isset($FDM_ARRAY[4]) ? (1 * $FDM_ARRAY[4]) : 0;
  349. //
  350. //
  351. //
  352. //
  353. //        return $ret_data;
  354.     }
  355.     public function callMethod($object$method)
  356.     {
  357.         return call_user_func([$object$method]);
  358.     }
  359.     public function getPositions($department_id)
  360.     {
  361.         return Position::getPositionByDepartment($this->em$department_id);
  362.     }
  363.     public function getSegregationSettings()
  364.     {
  365.         return HumanResource::getSegregationSettings($this->em);
  366.     }
  367.     public function getLeaveSettings()
  368.     {
  369.         return HumanResource::getLeaveSettings($this->em);
  370.     }
  371.     public function getUsers($company_id '')
  372.     {
  373.         return Users::getUserListById($this->em);
  374.     }
  375.     public function getExpSubTypes($company_id '')
  376.     {
  377.         return GeneralConstant::$expenseSubTypes;
  378.     }
  379.     public function PendingDocList()
  380.     {
  381.         $session = new Session();
  382.         //        return $session;
  383.         return System::getPendingApprovalListByUserLoginId($this->em$session->get(UserConstants::USER_LOGIN_ID));
  384.     }
  385.     public function getDepartments($company_id '')
  386.     {
  387.         return Department::getDepartmentList($this->em);
  388.     }
  389.     public function getCompanies()
  390.     {
  391.         return Company::getCompanyList($this->em);
  392.     }
  393.     public function getUserCompany()
  394.     {
  395.         $session = new Session();
  396.         //        return $session;
  397.         return Company::getCompanyData($this->em$session->get(UserConstants::USER_COMPANY_ID1));
  398.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  399.     }
  400.     public function getSupplierDataForSupplierLogin($supplierId 0)
  401.     {
  402.         $session = new Session();
  403.         if ($supplierId == 0)
  404.             $supplierId $session->get('supplierId');
  405.         //        return $session;
  406.         return Supplier::GetSupplierForSupplierLogin($this->em$supplierId);
  407.         //        return Company::getCompanyData($this->em, $session->get(UserConstants::USER_COMPANY_ID, 1));
  408.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  409.     }
  410.     public function getClientDataForClientLogin()
  411.     {
  412.         $session = new Session();
  413.         $clientId $session->get('clientId');
  414.         //        return $session;
  415.         return Client::GetClientForClientLogin($this->em$clientId);
  416.         //        return Company::getCompanyData($this->em, $session->get(UserConstants::USER_COMPANY_ID, 1));
  417.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  418.     }
  419.     public function getMonthlySummary()
  420.     {
  421.         $session = new Session();
  422.         return Company::getMonthlyDataForDashboard($this->em$session->get(UserConstants::USER_COMPANY_ID1));
  423.         //        return $session;
  424.         //        $list_data=
  425.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  426.     }
  427.     public function getRecentSales()
  428.     {
  429.         $session = new Session();
  430.         //        return $session;
  431.         return SalesOrderM::RecentSalesList($this->em$session->get(UserConstants::USER_COMPANY_ID), 5true);
  432.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  433.     }
  434.     public function getSoCountAndMore($limit 5)
  435.     {
  436.         $session = new Session();
  437.         //        return $session;
  438.         return SalesOrderM::getSoCountAndMore($this->em$session->get(UserConstants::USER_COMPANY_ID), $limittrue);
  439.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  440.     }
  441.     public function getRecentPurchase()
  442.     {
  443.         $session = new Session();
  444.         //        return $session;
  445.         return Purchase::RecentPurchaseList($this->em$session->get(UserConstants::USER_COMPANY_ID), 5true);
  446.         //        return $session->get(UserConstants::USER_COMPANY_ID);
  447.     }
  448.     public function getPositionModuleTree($PositionID)
  449.     {
  450.         $list "<ul>";
  451.         $Position $this->em->getRepository('ApplicationBundle:SysDepartmentPosition')->findOneBy(array(
  452.             'status' => GeneralConstant::ACTIVE,
  453.             'positionId' => $PositionID
  454.         ));
  455.         if ($Position) {
  456.             $PositionModules $this->em->getRepository('ApplicationBundle:SysDeptPositionDefaultModule')->findOneBy(array(
  457.                 'status' => GeneralConstant::ACTIVE,
  458.                 'positionId' => $Position->getPositionId()
  459.             ));
  460.             $Modules json_decode($PositionModules->getModuleIds(), true);
  461.             foreach ($Modules as &$ModuleID) {
  462.                 $ModuleInfo Module::getModuleName($this->em$ModuleID);
  463.                 $name $ModuleInfo['name'];
  464.                 self::SeekingLevel($this->em$ModuleInfo['parent_id'], $name);
  465.                 $list .= "<li>" $name "</li>";
  466.             }
  467.         }
  468.         $list .= "</ul>";
  469.         return $list;
  470.     }
  471.     public function getDataForAddProductService()
  472.     {
  473.         $em=$this->em;
  474.         $pl = [];
  475.         $pl_array = [];
  476.         $qry $em->getRepository("ApplicationBundle:InvProducts")->findBy(array(
  477.             "status" => GeneralConstant::ACTIVE,
  478. //            'type' => 1 //trade items
  479.         ));
  480.         foreach ($qry as $product) {
  481.             $pl[$product->getId()] = array(
  482.                 'text' => $product->getName(),
  483.                 'name' => $product->getName(),
  484.                 'id' => $product->getId(),
  485.                 'value' => $product->getId(),
  486.                 'purchase_price' => $product->getPurchasePrice(),
  487.                 'sales_price' => $product->getSalesPrice(),
  488.                 'supplier_id' => $product->getBrandCompany(),
  489.             );
  490.             $pl_array[] = array(
  491.                 'text' => $product->getName(),
  492.                 'value' => $product->getId(),
  493.                 'name' => $product->getName(),
  494.                 'id' => $product->getId(),
  495.                 'purchase_price' => $product->getPurchasePrice(),
  496.                 'sales_price' => $product->getSalesPrice(),
  497.                 'supplier_id' => $product->getBrandCompany(),
  498.             );
  499.         }
  500.         $qry $em->getRepository("ApplicationBundle:AccService")->findBy(array(
  501.             "status" => GeneralConstant::ACTIVE,
  502.             //            'type'=>1//trade items
  503.         ));
  504.         $sl = [];
  505.         $sl_array = [];
  506.         foreach ($qry as $product) {
  507.             $sl[$product->getServiceId()] = array(
  508.                 'text' => $product->getServiceName(),
  509.                 'value' => $product->getServiceId(),
  510.                 'name' => $product->getServiceName(),
  511.                 'id' => $product->getServiceId(),
  512.             );
  513.             $sl_array[] = array(
  514.                 'text' => $product->getServiceName(),
  515.                 'value' => $product->getServiceId(),
  516.                 'name' => $product->getServiceName(),
  517.                 'id' => $product->getServiceId(),
  518.             );
  519.         }
  520.         return array(
  521.             'serviceList' => $sl,
  522.             'serviceListArray' => $sl_array,
  523.             'productList' => $pl,
  524.             'productListArray' => $pl_array,
  525.         );
  526.     }
  527.     public function getSystemNotice()
  528.     {
  529.         $session = new Session();
  530.         if($session->get('userType')!=8)
  531.             $notice $this->em->getRepository('ApplicationBundle:SystemNotice')->findOneBy(array(
  532.                 'enabled' => GeneralConstant::ACTIVE,
  533.                 'showAsNotification' => GeneralConstant::ACTIVE,
  534.                 //            'CompanyId'=>$session->get(UserConstants::USER_COMPANY_ID),
  535.                 //            'appId'=>$session->get(UserConstants::USER_COMPANY_ID),
  536.             ));
  537.         else
  538.             $notice=null;
  539.         $systemMessage = array();
  540.         if ($notice) {
  541.             $systemMessage[] = array(
  542.                 'title' => $notice->getTitle(),
  543.                 'desc' => $notice->getDesc(),
  544.                 'countDownEnds' => $notice->getCountDownEnds(),
  545.             );
  546.         }
  547.         return $systemMessage;
  548.     }
  549.     private function SeekingLevel($em$module_id, &$name)
  550.     {
  551.         $ModuleInfo Module::getModuleName($em$module_id);
  552.         if (!empty($ModuleInfo)) {
  553.             $name .= " < " $ModuleInfo['name'];
  554.             if ($ModuleInfo['level'] > 0) {
  555.                 self::SeekingLevel($em$ModuleInfo['parent_id'], $name);
  556.             }
  557.         }
  558.         return $name;
  559.     }
  560.     /**
  561.      * This function list all the allowed route for current logged user. I have used this function on left_menu.html.twig.
  562.      *
  563.      * @return string
  564.      */
  565.     public function showNecessaryMenu()
  566.     {
  567.         $session = new Session();
  568.         $list json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  569.         //        $list="";
  570.         $r "";
  571.         if ($list) {
  572.             foreach ($list as &$listContent) {
  573.                 $r .= ", .accessible-menu ." $listContent;
  574.             }
  575.         }
  576.         return $r;
  577.     }
  578.     public function strToHex($str)
  579.     {
  580.         return System::strtohex($str);
  581. //        $s = '';
  582. //        foreach (str_split($x) as $c) $s .= sprintf("%02X", ord($c));
  583. //        return ($s);
  584.     }
  585.     public function toHex($number)
  586.     {
  587.         return dechex($number);
  588. //        return $number;
  589. //        $s = '';
  590. //        foreach (str_split($x) as $c) $s .= sprintf("%02X", ord($c));
  591. //        return ($s);
  592.     }
  593.     public function showNecessaryCreateBtn()
  594.     {
  595.         $session = new Session();
  596.         $list json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  597.         //        $list="";
  598.         $r "";
  599.         if ($list) {
  600.             foreach ($list as &$listContent) {
  601.                 $r .= ", .btn." $listContent;
  602.             }
  603.         }
  604.         return $r;
  605.     }
  606.     public function showMenuIfAdmin()
  607.     {
  608.         $session = new Session();
  609.         $list Company::getCompanyRouteList($this->em$session->get(UserConstants::USER_COMPANY_ID));
  610.         //        $list=json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  611.         //        $list="";
  612.         $r "";
  613.         if ($list) {
  614.             foreach ($list as &$listContent) {
  615.                 $r .= ", .accessible-menu ." $listContent;
  616.             }
  617.         }
  618.         return $r;
  619.     }
  620.     public function showNecessaryMenuGeneral()
  621.     {
  622.         $session = new Session();
  623.         $list json_decode($session->get(UserConstants::USER_ROUTE_LIST), true);
  624.         $r "";
  625.         if ($list) {
  626.             foreach ($list as &$listContent) {
  627.                 $r .= ", ." $listContent;
  628.             }
  629.         }
  630.         return $r;
  631.     }
  632.     public function todoSummaryList($assigned_to$types = [])
  633.     {
  634.         $todoList = array();
  635.         $ToDos $this->em->getRepository('ApplicationBundle:Ticket')->findBy(
  636.             array(
  637.                 'status' => TaskConstant::ACTIVE,
  638.                 'type' => $types,
  639.                 'assignedToUserId' => intval($assigned_to)
  640.             )
  641.         );
  642.         if (count($ToDos) > 0) {
  643.             foreach ($ToDos as &$ToDo) {
  644.                 $todoList[] = array(
  645.                     'id' => $ToDo->getId(),
  646.                     'title' => $ToDo->getTitle(),
  647.                     'type' => $ToDo->getType(),
  648.                     'urgency' => $ToDo->getUrgency()
  649.                 );
  650.             }
  651.         }
  652.         return $todoList;
  653.     }
  654.     public function inArray($key$array)
  655.     {
  656.         if($array==null)
  657.             $array=[];
  658.         return in_array($key$array);
  659.     }
  660.     public function encryptMe($str)
  661.     {
  662.         $session = new Session();
  663.         $allSessionsArray $session->all();
  664.         /*return Crypto::Encrypt($str, $allSessionsArray[ACLConstants::SESSION_SALT]);*/
  665.         return $this->encryptDecrypt->encrypt($str$allSessionsArray[GeneralConstant::SESSION_SALT]);
  666.     }
  667.     public function decryptMe($str)
  668.     {
  669.         $session = new Session();
  670.         $allSessionsArray $session->all();
  671.         /*return Crypto::Decrypt($str, $allSessionsArray[ACLConstants::SESSION_SALT]);*/
  672.         return $this->encryptDecrypt->decrypt($str$allSessionsArray[GeneralConstant::SESSION_SALT]);
  673.     }
  674.     public function getMicroTime($str)
  675.     {
  676.         return floor(microtime(true) * 1000);
  677.     }
  678.     public function getName()
  679.     {
  680.         return 'general_extension';
  681.     }
  682. }