src/Controller/BaseController.php line 221

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Idempiere\AdWindowAccess;
  4. use App\Repository\Idempiere\AdRoleRepository;
  5. use App\Repository\Idempiere\AdWindowAccessRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Security\Core\Security;
  13. use Twig\Environment;
  14. use Twig\Extra\Intl\IntlExtension;
  15. use Twig\Loader\FilesystemLoader;
  16. class BaseController extends AbstractController
  17. {
  18. /**
  19. * Accion de Documento
  20. *
  21. * @var array Estatus
  22. */
  23. protected $docaction = [
  24. 'CO' => [
  25. 'code' => 'CO',
  26. 'name' => 'ToComplete',
  27. 'flag' => 'success'
  28. ],
  29. 'VO' => [
  30. 'code' => 'VO',
  31. 'name' => 'Cancel',
  32. 'flag' => 'danger'
  33. ],
  34. 'CL' => [
  35. 'code' => 'CL',
  36. 'name' => 'Close',
  37. 'flag' => 'warning',
  38. ]
  39. ];
  40. /**
  41. * Estatus de Documento
  42. *
  43. * @var array Estatus
  44. */
  45. protected $docstatus = [
  46. 'DR' => [
  47. 'code' => 'DR',
  48. 'name' => 'Draft',
  49. 'flag' => 'info'
  50. ],
  51. 'IP' => [
  52. 'code' => 'IP',
  53. 'name' => 'In Progress',
  54. 'flag' => 'warning'
  55. ],
  56. 'AP' => [
  57. 'code' => 'AP',
  58. 'name' => 'Approved',
  59. 'flag' => 'warning'
  60. ],
  61. 'NA' => [
  62. 'code' => 'NA',
  63. 'name' => 'Not Approved',
  64. 'flag' => 'danger'
  65. ],
  66. 'CO' => [
  67. 'code' => 'CO',
  68. 'name' => 'Complete',
  69. 'flag' => 'success'
  70. ],
  71. 'VO' => [
  72. 'code' => 'VO',
  73. 'name' => 'Voided',
  74. 'flag' => 'danger'
  75. ],
  76. 'RE' => [
  77. 'code' => 'RE',
  78. 'name' => 'Reversed',
  79. 'flag' => 'danger'
  80. ],
  81. 'IN' => [
  82. 'code' => 'IN',
  83. 'name' => 'Invalid',
  84. 'flag' => 'danger'
  85. ],
  86. 'CL' => [
  87. 'code' => 'CL',
  88. 'name' => 'Closed',
  89. 'flag' => 'dark',
  90. ],
  91. 'LS' => [
  92. 'code' => 'LS',
  93. 'name' => 'Loss of Sales',
  94. 'flag' => 'danger',
  95. ],
  96. 'PD' => [
  97. 'code' => 'PD',
  98. 'name' => 'Pendiente por despachar',
  99. 'flag' => 'info',
  100. ],
  101. '??' => [
  102. 'code' => '??',
  103. 'name' => '??',
  104. 'flag' => 'info',
  105. ],
  106. 'PC' => [
  107. 'code' => 'PC',
  108. 'name' => 'Pendiente por cerrar',
  109. 'flag' => 'info',
  110. ]
  111. ];
  112. /**
  113. * Prioridad de Documento
  114. *
  115. * @var array Niveles de Prioridad
  116. */
  117. protected $priorityrule = [
  118. 1 => 'Priority.Urgent',
  119. 3 => 'Priority.High',
  120. 5 => 'Priority.Medium',
  121. 7 => 'Priority.Low',
  122. 9 => 'Priority.Minor'
  123. ];
  124. /**
  125. * Templates Handler
  126. * @var FilesystemLoader
  127. */
  128. protected $loader;
  129. protected $pdf;
  130. /**
  131. * Public Directory
  132. * @var String
  133. */
  134. protected $publicDir;
  135. /**
  136. * Request Stack
  137. * @var RequestStack
  138. */
  139. protected $requestStack;
  140. /**
  141. * Security Manager
  142. * @var Security
  143. */
  144. protected $security;
  145. /**
  146. * Session Interface
  147. * @var SessionInterface
  148. */
  149. protected $session;
  150. protected $status = [
  151. 'VO' => [
  152. 'flag' => 'danger',
  153. 'name' => 'anulado'
  154. ],
  155. 'IN' => [
  156. 'flag' => 'danger',
  157. 'name' => 'invalido'
  158. ],
  159. 'CL' => [
  160. 'flag' => 'dark',
  161. 'name' => 'cerrado'
  162. ],
  163. 'CO' => [
  164. 'flag' => 'success',
  165. 'name' => 'completo'
  166. ],
  167. 'NA' => [
  168. 'flag' => 'danger',
  169. 'name' => 'no aprobado'
  170. ],
  171. 'AP' => [
  172. 'flag' => 'warning',
  173. 'name' => 'aprobado'
  174. ],
  175. 'IP' => [
  176. 'flag' => 'warning',
  177. 'name' => 'en progreso'
  178. ],
  179. 'DR' => [
  180. 'flag' => 'info',
  181. 'name' => 'borrador'
  182. ]
  183. ];
  184. /**
  185. * Twig Engine
  186. * @var Enviroment
  187. */
  188. protected $twig;
  189. public function __construct(RequestStack $requestStack, Security $security)
  190. {
  191. $this->requestStack = $requestStack;
  192. $this->session = $requestStack->getSession();
  193. $this->security = $security;
  194. $this->publicDir = dirname(__FILE__) . '/../../public/';
  195. }
  196. /**
  197. * Ruta raiz - corroborar la sesion del usuario
  198. * @Route("/", name="app_index")
  199. *
  200. * @return RedirectResponse Vista
  201. */
  202. public function index(): RedirectResponse
  203. {
  204. return is_null($this->security->getUser()) ? $this->redirectToRoute('app_login') : $this->redirectToRoute('app_dashboard');
  205. }
  206. /**
  207. * Funcion para enrutar la salida del sistema
  208. * @Route("/salir", name="app_logout")
  209. *
  210. * @return RedirectResponse Vista
  211. */
  212. public function logout(): RedirectResponse { return $this->redirectToRoute('app_login'); }
  213. /**
  214. * Verifica los accesos del rol a la ventana
  215. *
  216. * @param ManagerRegistry $manager Administrador de conexiones a la BD
  217. * @param int $windowID Identificador de la ventana
  218. * @param int $roleID Identificador del rol
  219. *
  220. * @return boolean Permiso de lectura
  221. *
  222. */
  223. public function VerifyWindow(ManagerRegistry $manager, Int $windowID = 0, Int $roleID = 0): bool
  224. {
  225. $window = $this->WindowAccess($manager, $windowID, $roleID);
  226. if ( !is_null($window) )
  227. return $window->isActive();
  228. return false;
  229. }
  230. /**
  231. * Accesos del rol a la ventana
  232. *
  233. * @param ManagerRegistry $manager Administrador de conexiones a la BD
  234. * @param int $windowID Identificador de la ventana
  235. * @param int $roleID Identificador del rol
  236. *
  237. * @return null|AdWindowAccess Permiso
  238. */
  239. public function WindowAccess(ManagerRegistry $manager, Int $windowID = 0, Int $roleID = 0):? AdWindowAccess
  240. {
  241. $RWindowAccess = new AdWindowAccessRepository($manager);
  242. $window = $RWindowAccess->findOneBy(['ad_window_id' => $windowID, 'ad_role_id' => $roleID]);
  243. if ( !is_null($window) )
  244. return $window;
  245. $RRole = new AdRoleRepository($manager);
  246. $role = $RRole->find($roleID);
  247. $roleIncludes = $role->getAdRoleIncludeds();
  248. foreach ($roleIncludes as $role) {
  249. $window = $this->WindowAccess($manager, $windowID, $role->getIncludedRoleId());
  250. if ( !is_null($window) )
  251. return $window;
  252. }
  253. return null;
  254. }
  255. /**
  256. * Create a directory
  257. *
  258. * @param string $targetDir Ruta de la carpeta destino
  259. * @param string $folder Nombre de carpeta a crear
  260. * @return string Nombre de carpeta
  261. */
  262. public function createDir($targetDir, $folder)
  263. {
  264. if (!is_dir($this->publicDir . $targetDir . $folder)) {
  265. mkdir($this->publicDir . $targetDir . $folder);
  266. }
  267. return $targetDir . $folder;
  268. }
  269. public function replaceUrl(String $relativePath): String
  270. {
  271. return str_replace($this->getParameter('app.url'), $this->publicDir, $relativePath);
  272. }
  273. }
  274. ?>