vyapari 0.1.4 → 0.1.5dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/vyapari/sample_stock_bundle.csv +1 -0
  3. data/app/controllers/vyapari/admin/base_controller.rb +10 -0
  4. data/app/controllers/vyapari/admin/brands_controller.rb +99 -0
  5. data/app/controllers/vyapari/admin/categories_controller.rb +115 -0
  6. data/app/controllers/vyapari/admin/countries_controller.rb +2 -2
  7. data/app/controllers/vyapari/admin/dashboard_controller.rb +3 -1
  8. data/app/controllers/vyapari/admin/exchange_rates_controller.rb +2 -2
  9. data/app/controllers/vyapari/admin/products_controller.rb +79 -0
  10. data/app/controllers/vyapari/admin/regions_controller.rb +1 -1
  11. data/app/controllers/vyapari/admin/resource_controller.rb +1 -0
  12. data/app/controllers/vyapari/admin/stores_controller.rb +67 -0
  13. data/app/controllers/vyapari/admin/suppliers_controller.rb +67 -0
  14. data/app/controllers/vyapari/admin/terminals_controller.rb +150 -0
  15. data/app/controllers/vyapari/application_controller.rb +12 -0
  16. data/app/controllers/vyapari/store_manager/base_controller.rb +28 -0
  17. data/app/controllers/vyapari/store_manager/dashboard_controller.rb +30 -0
  18. data/app/controllers/vyapari/store_manager/resource_controller.rb +17 -0
  19. data/app/controllers/vyapari/store_manager/stock_bundles_controller.rb +206 -0
  20. data/app/controllers/vyapari/store_manager/stock_entries_controller.rb +161 -0
  21. data/app/controllers/vyapari/terminal_staff/base_controller.rb +29 -0
  22. data/app/controllers/vyapari/terminal_staff/dashboard_controller.rb +29 -0
  23. data/app/controllers/vyapari/terminal_staff/invoices_controller.rb +138 -0
  24. data/app/controllers/vyapari/terminal_staff/line_items_controller.rb +123 -0
  25. data/app/controllers/vyapari/terminal_staff/resource_controller.rb +17 -0
  26. data/app/controllers/vyapari/user_dashboard_controller.rb +31 -0
  27. data/app/models/brand.rb +63 -10
  28. data/app/models/category.rb +60 -16
  29. data/app/models/country.rb +27 -5
  30. data/app/models/exchange_rate.rb +31 -6
  31. data/app/models/image/brand_image.rb +3 -0
  32. data/app/models/image/category_image.rb +3 -0
  33. data/app/models/image/product_image.rb +3 -0
  34. data/app/models/invoice.rb +223 -0
  35. data/app/models/line_item.rb +206 -0
  36. data/app/models/product.rb +67 -13
  37. data/app/models/region.rb +26 -3
  38. data/app/models/stock_bundle.rb +249 -0
  39. data/app/models/stock_entry.rb +271 -0
  40. data/app/models/store.rb +216 -0
  41. data/app/models/supplier.rb +85 -0
  42. data/app/models/terminal.rb +158 -0
  43. data/app/models/vyapari/application_record.rb +4 -0
  44. data/app/uploaders/brand_image_uploader.rb +14 -0
  45. data/app/uploaders/category_image_uploader.rb +14 -0
  46. data/app/uploaders/product_image_uploader.rb +14 -0
  47. data/app/uploaders/stock_bundle_uploader.rb +10 -0
  48. data/app/views/layouts/kuppayam/_footer.html.erb +1 -1
  49. data/app/views/layouts/kuppayam/_sidebar.html.erb +45 -44
  50. data/app/views/layouts/vyapari/_store_manager_menu.html.erb +107 -0
  51. data/app/views/layouts/vyapari/_terminal_staff_menu.html.erb +103 -0
  52. data/app/views/layouts/vyapari/store_manager.html.erb +112 -0
  53. data/app/views/layouts/vyapari/terminal_staff.html.erb +116 -0
  54. data/app/views/vyapari/admin/brands/_form.html.erb +23 -0
  55. data/app/views/vyapari/admin/brands/_index.html.erb +89 -0
  56. data/app/views/vyapari/admin/brands/_row.html.erb +63 -0
  57. data/app/views/vyapari/admin/brands/_show.html.erb +104 -0
  58. data/app/views/vyapari/admin/brands/index.html.erb +48 -0
  59. data/app/views/vyapari/admin/categories/_form.html.erb +28 -0
  60. data/app/views/vyapari/admin/categories/_index.html.erb +101 -0
  61. data/app/views/vyapari/admin/categories/_row.html.erb +69 -0
  62. data/app/views/vyapari/admin/categories/_show.html.erb +115 -0
  63. data/app/views/vyapari/admin/{users → categories}/index.html.erb +8 -24
  64. data/app/views/vyapari/admin/countries/_index.html.erb +1 -1
  65. data/app/views/vyapari/admin/countries/index.html.erb +19 -3
  66. data/app/views/vyapari/admin/exchange_rates/_form.html.erb +3 -4
  67. data/app/views/vyapari/admin/exchange_rates/_index.html.erb +7 -7
  68. data/app/views/vyapari/admin/exchange_rates/_row.html.erb +3 -3
  69. data/app/views/vyapari/admin/exchange_rates/_show.html.erb +1 -0
  70. data/app/views/vyapari/admin/exchange_rates/index.html.erb +19 -3
  71. data/app/views/vyapari/admin/products/_form.html.erb +32 -0
  72. data/app/views/vyapari/admin/products/_index.html.erb +58 -0
  73. data/app/views/vyapari/admin/products/_row.html.erb +30 -0
  74. data/app/views/vyapari/admin/products/_show.html.erb +81 -0
  75. data/app/views/vyapari/admin/products/index.html.erb +48 -0
  76. data/app/views/vyapari/admin/regions/_index.html.erb +1 -1
  77. data/app/views/vyapari/admin/regions/index.html.erb +19 -3
  78. data/app/views/vyapari/admin/stores/_form.html.erb +37 -0
  79. data/app/views/vyapari/admin/stores/_index.html.erb +84 -0
  80. data/app/views/vyapari/admin/stores/_row.html.erb +55 -0
  81. data/app/views/vyapari/admin/stores/_show.html.erb +110 -0
  82. data/app/views/vyapari/admin/stores/index.html.erb +48 -0
  83. data/app/views/vyapari/admin/suppliers/_form.html.erb +32 -0
  84. data/app/views/vyapari/admin/suppliers/_index.html.erb +58 -0
  85. data/app/views/vyapari/admin/suppliers/_row.html.erb +30 -0
  86. data/app/views/vyapari/admin/suppliers/_show.html.erb +81 -0
  87. data/app/views/vyapari/admin/suppliers/index.html.erb +48 -0
  88. data/app/views/vyapari/admin/terminals/_form.html.erb +24 -0
  89. data/app/views/vyapari/admin/terminals/_index.html.erb +75 -0
  90. data/app/views/vyapari/admin/terminals/_row.html.erb +49 -0
  91. data/app/views/vyapari/admin/terminals/_show.html.erb +74 -0
  92. data/app/views/vyapari/store_manager/dashboard/index.html.erb +93 -0
  93. data/app/views/vyapari/store_manager/stock_bundles/_form.html.erb +99 -0
  94. data/app/views/vyapari/store_manager/stock_bundles/_index.html.erb +74 -0
  95. data/app/views/vyapari/store_manager/stock_bundles/_row.html.erb +44 -0
  96. data/app/views/vyapari/store_manager/stock_bundles/_show.html.erb +110 -0
  97. data/app/views/vyapari/store_manager/stock_bundles/create.html.erb +57 -0
  98. data/app/views/vyapari/store_manager/stock_bundles/index.html.erb +36 -0
  99. data/app/views/vyapari/store_manager/stock_bundles/update.html.erb +57 -0
  100. data/app/views/vyapari/store_manager/stock_entries/_form.html.erb +50 -0
  101. data/app/views/vyapari/store_manager/stock_entries/_index.html.erb +80 -0
  102. data/app/views/vyapari/store_manager/stock_entries/_row.html.erb +33 -0
  103. data/app/views/vyapari/store_manager/stock_entries/_show.html.erb +110 -0
  104. data/app/views/vyapari/store_manager/stock_entries/_stock_bundle.html.erb +61 -0
  105. data/app/views/vyapari/store_manager/stock_entries/index.html.erb +45 -0
  106. data/app/views/vyapari/terminal_staff/dashboard/_counts.html.erb +88 -0
  107. data/app/views/vyapari/terminal_staff/dashboard/_invoices.html.erb +37 -0
  108. data/app/views/vyapari/terminal_staff/dashboard/index.html.erb +36 -0
  109. data/app/views/vyapari/terminal_staff/invoices/_draft.html.erb +62 -0
  110. data/app/views/vyapari/terminal_staff/invoices/_form.html.erb +120 -0
  111. data/app/views/vyapari/terminal_staff/invoices/_index.html.erb +64 -0
  112. data/app/views/vyapari/terminal_staff/invoices/_row.html.erb +33 -0
  113. data/app/views/vyapari/terminal_staff/invoices/_show.html.erb +171 -0
  114. data/app/views/vyapari/terminal_staff/invoices/index.html.erb +37 -0
  115. data/app/views/vyapari/terminal_staff/invoices/new.js.erb +13 -0
  116. data/app/views/vyapari/terminal_staff/invoices/show.html.erb +1 -0
  117. data/app/views/vyapari/terminal_staff/line_items/_form.html.erb +40 -0
  118. data/app/views/vyapari/terminal_staff/line_items/_index.html.erb +94 -0
  119. data/app/views/vyapari/terminal_staff/line_items/create.js.erb +34 -0
  120. data/app/views/vyapari/terminal_staff/line_items/destroy.js.erb +25 -0
  121. data/app/views/vyapari/terminal_staff/stores/index.html.erb +24 -0
  122. data/app/views/vyapari/user_dashboard/index.html.erb +51 -0
  123. data/config/routes.rb +62 -5
  124. data/db/import_data/brands.csv +7 -0
  125. data/db/import_data/categories.csv +12 -0
  126. data/db/import_data/countries.csv +1 -0
  127. data/db/import_data/dummy/brands.csv +7 -0
  128. data/db/import_data/dummy/categories.csv +12 -0
  129. data/db/import_data/dummy/countries.csv +1 -0
  130. data/db/import_data/dummy/exchange_rates.csv +5 -0
  131. data/db/import_data/dummy/products-copy.csv +1 -0
  132. data/db/import_data/dummy/products.csv +1 -0
  133. data/db/import_data/dummy/products.xlsx +0 -0
  134. data/db/import_data/dummy/regions.csv +13 -0
  135. data/db/import_data/dummy/stores.csv +10 -0
  136. data/db/import_data/dummy/suppliers.csv +14 -0
  137. data/db/import_data/dummy/terminals.csv +11 -0
  138. data/db/import_data/exchange_rates.csv +5 -0
  139. data/db/import_data/regions.csv +13 -0
  140. data/db/import_data/stores.csv +3 -0
  141. data/db/import_data/suppliers.csv +14 -0
  142. data/db/import_data/terminals.csv +3 -0
  143. data/db/migrate/20170000000200_create_exchange_rates.rb +3 -2
  144. data/db/migrate/20170000000203_create_contacts.rb +22 -0
  145. data/db/migrate/20170000000204_create_bank_accounts.rb +21 -0
  146. data/db/migrate/20170000000205_create_suppliers.rb +18 -0
  147. data/db/migrate/20170000000206_create_stores.rb +21 -0
  148. data/db/migrate/20170000000207_create_terminals.rb +18 -0
  149. data/db/migrate/20170000000210_create_brands.rb +14 -0
  150. data/db/migrate/20170000000211_create_categories.rb +22 -0
  151. data/db/migrate/20170000000212_create_products.rb +29 -0
  152. data/db/migrate/20170000000213_create_invoices.rb +58 -0
  153. data/db/migrate/20170000000215_create_stock_bundles.rb +17 -0
  154. data/db/migrate/20170000000216_create_stock_entries.rb +20 -0
  155. data/db/sample_reports/products.xlsx +0 -0
  156. data/lib/tasks/vyapari/all.rake +73 -0
  157. data/lib/vyapari/version.rb +1 -1
  158. metadata +150 -15
  159. data/app/controllers/vyapari/admin/users_controller.rb +0 -130
  160. data/app/views/vyapari/admin/users/_form.html.erb +0 -39
  161. data/app/views/vyapari/admin/users/_index.html.erb +0 -101
  162. data/app/views/vyapari/admin/users/_row.html.erb +0 -72
  163. data/app/views/vyapari/admin/users/_show.html.erb +0 -199
  164. data/lib/tasks/vyapari_tasks.rake +0 -4
@@ -9,5 +9,17 @@ module Vyapari
9
9
  set_title("Vyapari - User Management System")
10
10
  end
11
11
 
12
+ def default_redirect_url_after_sign_in
13
+ asd
14
+ vyapari.user_dashboard_url
15
+ # if @current_user.has_role?("Admin")
16
+ # vyapari.admin_dashboard_url
17
+ # elsif @current_user.has_role?("Admin")
18
+ # vyapari.store_dashboard_url
19
+ # else
20
+ # vyapari.admin_dashboard_url
21
+ # end
22
+ end
23
+
12
24
  end
13
25
  end
@@ -0,0 +1,28 @@
1
+ module Vyapari
2
+ module StoreManager
3
+ class BaseController < ApplicationController
4
+
5
+ layout 'vyapari/store_manager'
6
+
7
+ before_action :require_user
8
+
9
+ private
10
+
11
+ def set_default_title
12
+ set_title("Vyapari Store | Vyapari Stock Management Module")
13
+ end
14
+
15
+ def get_nested_resource_objects
16
+ @store = Store.find_by_id(params[:store_id])
17
+ end
18
+
19
+ def configure_filter_param_mapping
20
+ @filter_param_mapping = default_filter_param_mapping
21
+ @filter_param_mapping[:stock_bundle] = :sb
22
+ @filter_param_mapping[:store] = :st
23
+ @filter_param_mapping[:supplier] = :sp
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Vyapari
2
+ module StoreManager
3
+ class DashboardController < Vyapari::StoreManager::BaseController
4
+
5
+ # GET /dashboard
6
+ def index
7
+ @terminals = @store.terminals
8
+ end
9
+
10
+ private
11
+
12
+ def breadcrumbs_configuration
13
+ {
14
+ heading: "#{@store.name}",
15
+ description: "A Quick view of stock & sales",
16
+ links: [
17
+ {name: "Home", link: user_dashboard_path, icon: 'fa-dashboard'},
18
+ {name: @store.name, link: store_manager_dashboard_path(@store), icon: 'fa-dashboard'}
19
+ ]
20
+ }
21
+ end
22
+
23
+ def set_navs
24
+ set_nav("store_manager/dashboard")
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,17 @@
1
+ module Vyapari
2
+ module StoreManager
3
+ class ResourceController < Vyapari::StoreManager::BaseController
4
+
5
+ include ResourceHelper
6
+
7
+ before_action :configure_resource_controller, :set_navs
8
+
9
+ private
10
+
11
+ def resource_url(obj)
12
+ url_for([:store_manager, obj.stock, obj])
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,206 @@
1
+ module Vyapari
2
+ module StoreManager
3
+ class StockBundlesController < ResourceController
4
+
5
+ def index
6
+ get_collections
7
+ respond_to do |format|
8
+ format.html {}
9
+ format.js {
10
+ js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/index" : :index
11
+ render js_view_path
12
+ }
13
+ end
14
+ end
15
+
16
+ def show
17
+ @stock_bundle = @r_object = @resource_options[:class].find_by_id(params[:id])
18
+ set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) unless @r_object
19
+ render_accordingly
20
+ end
21
+
22
+ def download_original_file
23
+ @stock_bundle = @r_object = @resource_options[:class].find_by_id(params[:id])
24
+ send_file @stock_bundle.file.file.path
25
+ end
26
+
27
+ def download_error_file
28
+ @stock_bundle = @r_object = @resource_options[:class].find_by_id(params[:id])
29
+ send_file @stock_bundle.error_file.file.path
30
+ end
31
+
32
+ def new
33
+ @stock_bundle = @r_object = @resource_options[:class].new(store: @store)
34
+ render_accordingly
35
+ end
36
+
37
+ def edit
38
+ @stock_bundle = @r_object = @resource_options[:class].find_by_id(params[:id])
39
+ set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) unless @r_object
40
+ render_accordingly
41
+ end
42
+
43
+ def create
44
+ @stock_bundle = @r_object = @resource_options[:class].new(store: @store)
45
+ @stock_bundle.assign_attributes(permitted_params)
46
+ @stock_bundle.store = @store
47
+ @stock_bundle.status = :pending
48
+
49
+ @stock_bundle.uploader = @current_user
50
+ @stock_bundle.uploaded_date = Time.now
51
+
52
+ if @stock_bundle.valid?
53
+ @stock_bundle.save!
54
+ if @stock_bundle.parse_stocks
55
+ @stock_bundle.approve!
56
+ set_flash_message("#{I18n.t('status.success')} - #{I18n.t('state.changed', item: default_item_name.titleize, new_state: "uploaded")}", :success)
57
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: "uploaded"))
58
+ else
59
+ message = "Stock Bundle #{@stock_bundle.display_name} has been uploaded successfully. However, some of the jobs had some data issues. You need to approve this job bundle manually."
60
+ set_flash_message(message, :warning)
61
+ set_notification(false, I18n.t('status.error'), message)
62
+ end
63
+ else
64
+ message = "Error! Stock Bundle #{@stock_bundle.display_name} was not uploaded. #{@stock_bundle.errors.full_messages.to_sentence}"
65
+ puts "Error! #{message}".red
66
+ set_flash_message(message = message, :danger)
67
+ set_notification(false, I18n.t('status.error'), message)
68
+ end
69
+
70
+ render layout: "kuppayam/document_upload"
71
+
72
+ end
73
+
74
+ def update
75
+ @stock_bundle = @r_object = @resource_options[:class].find_by_id(params[:id])
76
+ @stock_bundle.assign_attributes(permitted_params)
77
+ @stock_bundle.store = @store
78
+ @stock_bundle.status = :pending
79
+
80
+ @stock_bundle.uploader = @current_user
81
+ @stock_bundle.uploaded_date = Time.now
82
+
83
+ if @stock_bundle.valid?
84
+ @stock_bundle.save!
85
+ if @stock_bundle.parse_stocks
86
+ @stock_bundle.approve!
87
+ set_flash_message("#{I18n.t('status.success')} - #{I18n.t('state.changed', item: default_item_name.titleize, new_state: "uploaded")}", :success)
88
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: "uploaded"))
89
+ else
90
+ message = "Stock Bundle #{@stock_bundle.display_name} has been uploaded successfully. However, some of the jobs had some data issues. You need to approve this job bundle manually."
91
+ set_flash_message(message, :warning)
92
+ set_notification(false, I18n.t('status.error'), message)
93
+ end
94
+ else
95
+ message = "Error! Stock Bundle #{@stock_bundle.display_name} was not uploaded. #{@stock_bundle.errors.full_messages.to_sentence}"
96
+ puts "Error! #{message}".red
97
+ set_flash_message(message = message, :danger)
98
+ set_notification(false, I18n.t('status.error'), message)
99
+ end
100
+
101
+ render layout: "kuppayam/document_upload"
102
+
103
+ end
104
+
105
+ def destroy
106
+ @stock_bundle = @r_object = @resource_options[:class].find_by_id(params[:id])
107
+ if @r_object
108
+ if @r_object.can_be_deleted?
109
+ @r_object.destroy
110
+ get_collections
111
+ set_flash_message(I18n.t('success.deleted'), :success)
112
+ set_notification(false, I18n.t('status.success'), I18n.t('success.deleted', item: default_item_name.titleize))
113
+ @destroyed = true
114
+ else
115
+ message = I18n.t('errors.failed_to_delete', item: default_item_name.titleize)
116
+ set_flash_message(message, :failure)
117
+ set_notification(false, I18n.t('status.error'), message)
118
+ @destroyed = false
119
+ end
120
+ else
121
+ set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize))
122
+ end
123
+
124
+ respond_to do |format|
125
+ format.html {}
126
+ format.js {
127
+ js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/destroy" : :destroy
128
+ render js_view_path
129
+ }
130
+ end
131
+
132
+ end
133
+
134
+ private
135
+
136
+ def get_collections
137
+ @relation = @store.stock_bundles.includes(:store, :supplier, :uploader).where("")
138
+
139
+ parse_filters
140
+ apply_filters
141
+
142
+ @stock_bundles = @r_objects = @relation.page(@current_page).per(@per_page)
143
+
144
+ return true
145
+ end
146
+
147
+ def apply_filters
148
+ @relation = @relation.search(@query) if @query
149
+
150
+ @order_by = "created_at desc" unless @order_by
151
+ @relation = @relation.order(@order_by)
152
+ end
153
+
154
+ def configure_filter_settings
155
+ @filter_settings = {
156
+ string_filters: [
157
+ { filter_name: :query }
158
+ ],
159
+ boolean_filters: [],
160
+ reference_filters: [],
161
+ variable_filters: [],
162
+ }
163
+ end
164
+
165
+ def configure_filter_ui_settings
166
+ @filter_ui_settings = {}
167
+ end
168
+
169
+ def resource_url(obj)
170
+ url_for([:admin, obj.store, obj])
171
+ end
172
+
173
+ def resource_controller_configuration
174
+ {
175
+ collection_name: :stock_bundles,
176
+ item_name: :stock_bundle,
177
+ class: StockBundle,
178
+ page_title: "#{@store.name} - Stock Bundle",
179
+ js_view_path: "/kuppayam/workflows/peacock",
180
+ view_path: "/vyapari/store_manager/stock_bundles"
181
+ }
182
+ end
183
+
184
+ def breadcrumbs_configuration
185
+ {
186
+ heading: "#{@store.name} - Stock Bundle",
187
+ description: "Listing all the stock at #{@store.name}",
188
+ links: [
189
+ {name: "Home", link: user_dashboard_path, icon: 'fa-dashboard'},
190
+ {name: @store.name, link: store_manager_dashboard_path(@store), icon: 'fa-dashboard'},
191
+ {name: "Stock Bundle", link: nil, icon: 'fa-truck', active: true}
192
+ ]
193
+ }
194
+ end
195
+
196
+ def permitted_params
197
+ params.require(:stock_bundle).permit(:name, :supplier_id, :file)
198
+ end
199
+
200
+ def set_navs
201
+ set_nav("store_manager/stocks")
202
+ end
203
+
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,161 @@
1
+ module Vyapari
2
+ module StoreManager
3
+ class StockEntriesController < ResourceController
4
+
5
+ def index
6
+ get_collections
7
+ respond_to do |format|
8
+ format.html {}
9
+ format.js {
10
+ js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/index" : :index
11
+ render js_view_path
12
+ }
13
+ end
14
+ end
15
+
16
+ def show
17
+ @stock_entry = @r_object = @resource_options[:class].find_by_id(params[:id])
18
+ set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) unless @r_object
19
+ render_accordingly
20
+ end
21
+
22
+ def new
23
+ @stock_entry = @r_object = @resource_options[:class].new(store: @store)
24
+ render_accordingly
25
+ end
26
+
27
+ def edit
28
+ @stock_entry = @r_object = @resource_options[:class].find_by_id(params[:id])
29
+ set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) unless @r_object
30
+ render_accordingly
31
+ end
32
+
33
+ def create
34
+ @stock_entry = @r_object = @resource_options[:class].new(store: @store)
35
+ @r_object.assign_attributes(permitted_params)
36
+ @r_object.store = @store
37
+ save_resource
38
+ end
39
+
40
+ def update
41
+ @stock_entry = @r_object = @resource_options[:class].find_by_id(params[:id])
42
+ if @r_object
43
+ @r_object.assign_attributes(permitted_params)
44
+ @r_object.store = @store
45
+ save_resource
46
+ else
47
+ set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize))
48
+ end
49
+ end
50
+
51
+ def destroy
52
+ @stock_entry = @r_object = @resource_options[:class].find_by_id(params[:id])
53
+ if @r_object
54
+ if @r_object.can_be_deleted?
55
+ @r_object.destroy
56
+ get_collections
57
+ set_flash_message(I18n.t('success.deleted'), :success)
58
+ set_notification(false, I18n.t('status.success'), I18n.t('success.deleted', item: default_item_name.titleize))
59
+ @destroyed = true
60
+ else
61
+ message = I18n.t('errors.failed_to_delete', item: default_item_name.titleize)
62
+ set_flash_message(message, :failure)
63
+ set_notification(false, I18n.t('status.error'), message)
64
+ @destroyed = false
65
+ end
66
+ else
67
+ set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize))
68
+ end
69
+
70
+ respond_to do |format|
71
+ format.html {}
72
+ format.js {
73
+ js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/destroy" : :destroy
74
+ render js_view_path
75
+ }
76
+ end
77
+
78
+ end
79
+
80
+ private
81
+
82
+ def get_collections
83
+ @relation = @store.stock_entries.where("")
84
+
85
+ parse_filters
86
+ apply_filters
87
+
88
+ @stock_entries = @r_objects = @relation.page(@current_page).per(@per_page)
89
+
90
+ return true
91
+ end
92
+
93
+ def apply_filters
94
+
95
+ @relation = @relation.search(@query) if !@query.blank?
96
+
97
+ if @stock_bundle == "null"
98
+ @relation = @relation.where("stock_entries.stock_bundle_id IS NULL")
99
+ elsif @stock_bundle
100
+ @relation = @relation.where("stock_entries.stock_bundle_id = ?", @stock_bundle.id)
101
+ end
102
+
103
+ @order_by = "created_at desc" unless @order_by
104
+ @relation = @relation.order(@order_by)
105
+ end
106
+
107
+ def configure_filter_settings
108
+ @filter_settings = {
109
+ string_filters: [
110
+ { filter_name: :query }
111
+ ],
112
+ boolean_filters: [],
113
+ reference_filters: [
114
+ { filter_name: :stock_bundle, filter_class: StockBundle },
115
+ ],
116
+ variable_filters: [],
117
+ }
118
+ end
119
+
120
+ def configure_filter_ui_settings
121
+ @filter_ui_settings = {}
122
+ end
123
+
124
+ def resource_url(obj)
125
+ url_for([:admin, obj.store, obj])
126
+ end
127
+
128
+ def resource_controller_configuration
129
+ {
130
+ collection_name: :stock_entries,
131
+ item_name: :stock_entry,
132
+ class: StockEntry,
133
+ page_title: "#{@store.name} - Stock Entries",
134
+ js_view_path: "/kuppayam/workflows/parrot",
135
+ view_path: "/vyapari/store_manager/stock_entries"
136
+ }
137
+ end
138
+
139
+ def breadcrumbs_configuration
140
+ {
141
+ heading: "#{@store.name} - Stock Entries",
142
+ description: "Listing all the stock at #{@store.name}",
143
+ links: [
144
+ {name: "Home", link: user_dashboard_path, icon: 'fa-dashboard'},
145
+ {name: @store.name, link: store_manager_dashboard_path(@store), icon: 'fa-dashboard'},
146
+ {name: "Stock Entries", link: nil, icon: 'fa-truck', active: true}
147
+ ]
148
+ }
149
+ end
150
+
151
+ def permitted_params
152
+ params.require(:stock_entry).permit(:product_id, :quantity, :status)
153
+ end
154
+
155
+ def set_navs
156
+ set_nav("store_manager/stocks")
157
+ end
158
+
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,29 @@
1
+ module Vyapari
2
+ module TerminalStaff
3
+ class BaseController < ApplicationController
4
+
5
+ layout 'vyapari/terminal_staff'
6
+
7
+ before_action :require_user
8
+
9
+ private
10
+
11
+ def set_default_title
12
+ set_title("Vyapari Store | Vyapari Stock Management Module")
13
+ end
14
+
15
+ def get_nested_resource_objects
16
+ @terminal = Terminal.find_by_id(params[:terminal_id])
17
+ @store = @terminal.store if @terminal
18
+ end
19
+
20
+ def configure_filter_param_mapping
21
+ @filter_param_mapping = default_filter_param_mapping
22
+ @filter_param_mapping[:terminal] = :tm
23
+ @filter_param_mapping[:store] = :st
24
+ @filter_param_mapping[:supplier] = :sp
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Vyapari
2
+ module TerminalStaff
3
+ class DashboardController < Vyapari::TerminalStaff::BaseController
4
+
5
+ # GET /dashboard
6
+ def index
7
+ end
8
+
9
+ private
10
+
11
+ def breadcrumbs_configuration
12
+ {
13
+ heading: "#{@terminal.name}",
14
+ description: "#{@store.name}",
15
+ links: [
16
+ {name: "Home", link: user_dashboard_path, icon: 'fa-building-o'},
17
+ {name: @terminal.name, link: terminal_staff_dashboard_path(@store), icon: 'fa-desktop'}
18
+ ]
19
+ }
20
+ end
21
+
22
+ def set_navs
23
+ set_nav("terminal_staff/dashboard")
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,138 @@
1
+ module Vyapari
2
+ module TerminalStaff
3
+ class InvoicesController < Vyapari::TerminalStaff::ResourceController
4
+
5
+ #layout :resolve_layout
6
+
7
+ def new
8
+ @invoice = @r_object = Invoice.new
9
+ @invoice.terminal = @terminal
10
+ @invoice.store = @store
11
+ @invoice.user = @current_user
12
+ @invoice.status = Invoice::DRAFT
13
+ @invoice.generate_temporary_invoice_number
14
+ @invoice.invoice_date = Time.now
15
+ @invoice.save
16
+ #render_show
17
+ end
18
+
19
+ def edit
20
+ @invoice = @r_object = Invoice.find_by_id(params[:id])
21
+ render_show
22
+ end
23
+
24
+ def show
25
+ @invoice = @r_object = Invoice.find_by_id(params[:id])
26
+ end
27
+
28
+ def update
29
+
30
+ @invoice = @r_object = Invoice.find_by_id(params[:id])
31
+ @invoice.invoice_date = Time.now
32
+ @invoice.assign_attributes(permitted_params)
33
+
34
+ if @invoice.valid?
35
+ @invoice.save
36
+ @invoice.generate_real_invoice_number!
37
+ @invoice.activate!
38
+ set_notification(true, @invoice.invoice_number, "Invoice '#{@invoice.invoice_number}' SAVED")
39
+ else
40
+ error_message = @invoice.invoice_number || I18n.t('status.error')
41
+ set_notification(false, error_message, @invoice.errors.full_messages.join(", "))
42
+ end
43
+ render :new
44
+ end
45
+
46
+ private
47
+
48
+ def permitted_params
49
+ params.require(:invoice).permit(:discount, :adjustment, :money_taken, :notes, :payment_method, :customer_name, :customer_address, :credit_card_number)
50
+ end
51
+
52
+ def resolve_layout
53
+ case action_name
54
+ when "show"
55
+ 'kuppayam/print_a4'
56
+ else
57
+ 'vyapari/terminal_staff'
58
+ end
59
+ end
60
+
61
+ def resource_controller_configuration
62
+ {
63
+ collection_name: :invoices,
64
+ item_name: :invoice,
65
+ class: Invoice,
66
+ page_title: "#{@terminal.name} - Invoices",
67
+ js_view_path: "/kuppayam/workflows/peacock",
68
+ view_path: "/vyapari/terminal_staff/invoices"
69
+ }
70
+ end
71
+
72
+ def breadcrumbs_configuration
73
+ {
74
+ heading: "Invoices - #{@terminal.name}",
75
+ description: "Listing the invoices - #{@terminal.name}",
76
+ links: [
77
+ {name: "Home", link: user_dashboard_path, icon: 'fa-dashboard'},
78
+ {name: @store.name, link: store_manager_dashboard_path(@store), icon: 'fa-dashboard'},
79
+ {name: "Stock Entries", link: nil, icon: 'fa-truck', active: true},
80
+ {name: @terminal.name, link: terminal_staff_dashboard_path(@terminal), icon: 'fa-desktop'},
81
+ {name: "Invoices", link: nil, icon: 'fa-file', active: true}
82
+ ]
83
+ }
84
+ end
85
+
86
+ def get_collections
87
+ @relation = @terminal.invoices.where("")
88
+
89
+ parse_filters
90
+ apply_filters
91
+
92
+ @invoices = @r_objects = @relation.page(@current_page).per(@per_page)
93
+
94
+ return true
95
+ end
96
+
97
+ def apply_filters
98
+ @relation = @relation.search(@query) if @query
99
+
100
+ # if @terminal == "null"
101
+ # @relation = @relation.where("invoices.terminal_id IS NULL")
102
+ # elsif @terminal
103
+ # @relation = @relation.where("invoices.terminal_id = ?", @terminal.id)
104
+ # end
105
+
106
+ @order_by = "created_at desc" unless @order_by
107
+ @relation = @relation.order(@order_by)
108
+ end
109
+
110
+ def configure_filter_settings
111
+ @filter_settings = {
112
+ string_filters: [
113
+ { filter_name: :query }
114
+ ],
115
+ boolean_filters: [],
116
+ reference_filters: [
117
+ { filter_name: :terminal, filter_class: Terminal },
118
+ ],
119
+ variable_filters: [],
120
+ }
121
+ end
122
+
123
+ def configure_filter_ui_settings
124
+ @filter_ui_settings = {}
125
+ end
126
+
127
+ def resource_url(obj)
128
+ url_for([:terminal_staff, @terminal, obj])
129
+ end
130
+
131
+ def set_navs
132
+ set_nav("terminal_staff/invoices")
133
+ end
134
+
135
+ end
136
+ end
137
+ end
138
+