navigation.rb 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # -*- coding: utf-8 -*-
  2. # Configures your navigation
  3. module SimpleNavigationn
  4. module Renderer
  5. class BootstrapBreadcrumbs < SimpleNavigation::Renderer::Base
  6. def render(item_container)
  7. content_tag(:ul, li_tags(item_container).join(join_with), id: item_container.dom_id, class: "page-breadcrumb breadcrumb")
  8. end
  9. protected
  10. def li_tags(item_container)
  11. item_container.items.inject([]) do |list, item|
  12. # rubocop:disable Style/IfInsideElse
  13. if item.selected?
  14. if include_sub_navigation?(item)
  15. list << content_tag(:li, link_to(item.name[:text], item.url, { method: item.method }.merge(item.html_options.except(:class, :id)))) if item.selected?
  16. list.concat li_tags(item.sub_navigation)
  17. elsif item.name.is_a? String
  18. list << content_tag(:li, item.name, class: 'active ') if item.selected?
  19. else
  20. list << content_tag(:li, item.name[:text], class: 'active ') if item.selected?
  21. end
  22. else
  23. next
  24. end
  25. # rubocop:enable Style/IfInsideElse
  26. end
  27. list
  28. end
  29. end
  30. def join_with
  31. @join_with ||= options[:join_with] || ' <i class="fa fa-circle"></i> '
  32. content_tag(:li, content_tag(:span, @join_with, class: 'divider'))
  33. end
  34. end
  35. end
  36. SimpleNavigation.register_renderer bootstrap_breadcrumbs: SimpleNavigationn::Renderer::BootstrapBreadcrumbs
  37. # rubocop:disable Metrics/BlockLength
  38. SimpleNavigation::Configuration.run do |navigation|
  39. navigation.renderer = SimpleNavigationRenderers::Bootstrap3
  40. navigation.items do |primary|
  41. # clientes
  42. if can? :read, Customer
  43. primary.item :customers, { icon: "fa fa-fw fa-smile-o", text: "Clientes" }, customers_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  44. sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
  45. sub_nav.item :list_customers, 'Lista de clientes', customers_path
  46. sub_nav.item :divider_after_list_customers, '#', divider: true
  47. sub_nav.item :debtor_customers, 'Clientes deudores', debtors_path if (can? :debtors, Customer)
  48. sub_nav.item :special_prices, 'Descuentos especiales por cliente', new_special_price_path if (can? :create, SpecialPrice)
  49. end
  50. end
  51. # productos
  52. primary.item :products, { icon: "fa fa-fw fa-cubes", text: "Productos" }, products_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  53. sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
  54. if can? :read, Unit
  55. sub_nav.item :units, 'Unidades de medida', units_path
  56. sub_nav.item :divider_before_categories, '#', divider: true
  57. end
  58. if can? :read, Category
  59. sub_nav.item :list_categories, 'Lista de líneas de producto', categories_path
  60. sub_nav.item :divider_before_products, '#', divider: true
  61. end
  62. sub_nav.item :list_products, 'Lista de productos', products_path if (can? :index, Product)
  63. sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path if (can? :read, AvailableProduct)
  64. sub_nav.item :list_waste_of_products, 'Lista de mermas de productos', product_wastes_path if (can? :read, ProductWaste)
  65. if can? :read, Purchase
  66. sub_nav.item :divider_before_purchases, '#', divider: true
  67. sub_nav.item :list_products, 'Lista de compras', purchases_path
  68. end
  69. if can? :read, Supplier
  70. sub_nav.item :divider_before_purchases, '#', divider: true
  71. sub_nav.item :list_suppliers, 'Lista de proveedores', suppliers_path
  72. end
  73. if (can? :product_track, Product)
  74. sub_nav.item :divider_before_purchases, '#', divider: true
  75. sub_nav.item :product_track, 'Seguimiento de productos', product_track_path
  76. end
  77. end
  78. # puntos de venta y caja registradora
  79. primary.item :pointsales, { icon: "fa fa-fw fa-cart-plus", text: "Puntos de venta" }, pointsales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  80. sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
  81. if can? :read, Pointsale
  82. sub_nav.item :list_pointsales, 'Lista de puntos de venta', pointsales_path
  83. sub_nav.item :divider_before_pointsales, '#', divider: true
  84. end
  85. sub_nav.item :list_cash_registers, 'Lista de cajas', cash_registers_path if (can? :index, CashRegister)
  86. sub_nav.item :list_cash_outs, 'Lista de cortes de caja', cash_outs_path if (can? :read, CashOut)
  87. sub_nav.item :divider_before_pointsales, '#', divider: true
  88. sub_nav.item :list_promotions, 'Promociones', promotions_path if (can? :read, Promotion)
  89. if (can? :read, Seller)
  90. sub_nav.item :divider_before_sellers, '#', divider: true
  91. sub_nav.item :list_sellers, 'Lista de vendedores', sellers_path
  92. end
  93. if can? :read, Transfer
  94. sub_nav.item :divider_after_sellers, '#', divider: true
  95. sub_nav.item :list_transfers, 'Lista de traspasos', transfers_path
  96. end
  97. if can? :read, Warehouse
  98. sub_nav.item :divider_after_list_users, '#', divider: true
  99. sub_nav.item :list_warehouse, 'Almacenes', warehouses_path
  100. end
  101. end
  102. # ventas
  103. if can? :read, Sale
  104. primary.item :sales, { icon: "fa fa-fw fa-money", text: "Ventas" }, sales_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  105. sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
  106. sub_nav.item :list_sales, 'Lista de ventas', sales_path
  107. if can? :sales_reserved, Sale
  108. sub_nav.item :list_sales_reserved, 'Lista de apartados', sales_reserved_path
  109. end
  110. if can? :read, ProductsReturn
  111. sub_nav.item :list_products_return, 'Lista de devoluciones', products_returns_path
  112. end
  113. if can? :manage, Commission
  114. sub_nav.item :divider_after_list_returns, '#', divider: true
  115. sub_nav.item :commission, 'Lista de comisiones', commissions_path
  116. end
  117. end
  118. end
  119. # egresos
  120. if can? :read, Expense
  121. primary.item :expensesconcepts, { icon: "fa fa-fw fa-dollar", text: "Egresos" }, expensesconcepts_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  122. sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
  123. if can? :read, Expensesconcept
  124. sub_nav.item :list_expensesconcepts, 'Lista de conceptos de egreso', expensesconcepts_path
  125. sub_nav.item :divider_after_list_expensesconcepts, '#', divider: true
  126. end
  127. sub_nav.item :list_expenses, 'Lista de egresos', expenses_path
  128. end
  129. end
  130. # reportes
  131. if current_user.usertype == "A" || current_user.usertype == "SS"
  132. primary.item :reports, { icon: "fa fa-bar-chart", text: "Reportes" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  133. sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
  134. sub_nav.item :sales_per_month, 'Ventas por mes', sales_per_month_report_path
  135. sub_nav.item :divider_after_month_sales, '#', divider: true
  136. sub_nav.item :minmax_report, 'Mínimos y Máximos', min_max_path
  137. sub_nav.item :divider_after_minmax_report, '#', divider: true
  138. sub_nav.item :purchases_per_month, 'Compras por mes', purchases_per_month_path
  139. end
  140. end
  141. # soporte
  142. primary.item :support, { icon: "fa fa-fw fa-group", text: "Soporte" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  143. sub_nav.dom_attributes = { class: "dropdown-menu pull-left" }
  144. sub_nav.item :send_info, "Soporte técnico", contact_support_path
  145. sub_nav.item :updates, "Actualizaciones", system_updates_path
  146. end
  147. # configuracion general
  148. if can? :read, PosConfig
  149. primary.item :pos_config, { icon: "fa fa-fw fa-cog", text: "Configuración" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
  150. sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
  151. if can? :manage, PosConfig
  152. sub_nav.item :pos_configs, 'Configurar parámetros generales', pos_configs_path
  153. sub_nav.item :divider_after_pos_config, '#', divider: true
  154. end
  155. sub_nav.item :list_products_initial_stock, 'Stock inicial de productos', products_initial_stock_path
  156. sub_nav.item :list_products_stock, 'Stock mínimo y máximo de productos', products_stock_path
  157. if can? :read, User
  158. sub_nav.item :divider_after_products_stock, '#', divider: true
  159. sub_nav.item :list_users, 'Usuarios del sistema', users_path
  160. end
  161. end
  162. end
  163. class BootstrapBreadcrumbs < SimpleNavigation::Renderer::Base
  164. def render(item_container)
  165. content_tag(:ul, li_tags(item_container).join(join_with), id: item_container.dom_id, class: "#{item_container.dom_class} breadcrumb")
  166. end
  167. protected
  168. def li_tags(item_container)
  169. item_container.items.inject([]) do |list, item|
  170. # rubocop:disable Style/IfInsideElse
  171. if item.selected?
  172. if include_sub_navigation?(item)
  173. list << content_tag(:li, link_to(item.name, item.url, { method: item.method }.merge(item.html_options.except(:class, :id)))) if item.selected?
  174. list.concat li_tags(item.sub_navigation)
  175. else
  176. list << content_tag(:li, item.name, class: 'active') if item.selected?
  177. end
  178. end
  179. # rubocop:enable Style/IfInsideElse
  180. list
  181. end
  182. end
  183. def join_with
  184. @join_with ||= options[:join_with] || '<span class="divider">/</span>'.html_safe
  185. end
  186. end
  187. end
  188. end
  189. # rubocop:enable Metrics/BlockLength