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