vyapari 0.1.5dev10 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/vyapari/admin/base_controller.rb +0 -9
- data/app/controllers/vyapari/admin/countries_controller.rb +2 -2
- data/app/controllers/vyapari/admin/dashboard_controller.rb +1 -3
- data/app/controllers/vyapari/admin/exchange_rates_controller.rb +2 -2
- data/app/controllers/vyapari/admin/regions_controller.rb +1 -1
- data/app/controllers/vyapari/admin/resource_controller.rb +0 -1
- data/app/controllers/vyapari/admin/users_controller.rb +130 -0
- data/app/controllers/vyapari/application_controller.rb +0 -11
- data/app/models/brand.rb +19 -67
- data/app/models/category.rb +19 -63
- data/app/models/country.rb +7 -31
- data/app/models/exchange_rate.rb +7 -32
- data/app/models/product.rb +20 -75
- data/app/models/region.rb +20 -37
- data/app/models/vyapari/application_record.rb +0 -3
- data/app/views/layouts/kuppayam/_footer.html.erb +1 -1
- data/app/views/layouts/kuppayam/_sidebar.html.erb +44 -45
- data/app/views/vyapari/admin/countries/_index.html.erb +1 -1
- data/app/views/vyapari/admin/countries/index.html.erb +3 -19
- data/app/views/vyapari/admin/exchange_rates/_form.html.erb +4 -3
- data/app/views/vyapari/admin/exchange_rates/_index.html.erb +7 -7
- data/app/views/vyapari/admin/exchange_rates/_row.html.erb +3 -3
- data/app/views/vyapari/admin/exchange_rates/_show.html.erb +0 -1
- data/app/views/vyapari/admin/exchange_rates/index.html.erb +3 -19
- data/app/views/vyapari/admin/regions/_index.html.erb +1 -1
- data/app/views/vyapari/admin/regions/index.html.erb +3 -19
- data/app/views/vyapari/admin/users/_form.html.erb +39 -0
- data/app/views/vyapari/admin/users/_index.html.erb +101 -0
- data/app/views/vyapari/admin/users/_row.html.erb +72 -0
- data/app/views/vyapari/admin/users/_show.html.erb +199 -0
- data/app/views/vyapari/admin/{categories → users}/index.html.erb +24 -8
- data/config/routes.rb +5 -66
- data/db/migrate/20170000000200_create_exchange_rates.rb +2 -3
- data/lib/tasks/vyapari_tasks.rake +4 -0
- data/lib/vyapari/version.rb +1 -1
- metadata +15 -167
- data/app/assets/images/vyapari/sample_stock_bundle.csv +0 -1
- data/app/controllers/vyapari/admin/brands_controller.rb +0 -99
- data/app/controllers/vyapari/admin/categories_controller.rb +0 -115
- data/app/controllers/vyapari/admin/products_controller.rb +0 -79
- data/app/controllers/vyapari/admin/stores_controller.rb +0 -67
- data/app/controllers/vyapari/admin/suppliers_controller.rb +0 -67
- data/app/controllers/vyapari/admin/terminals_controller.rb +0 -150
- data/app/controllers/vyapari/store_manager/base_controller.rb +0 -33
- data/app/controllers/vyapari/store_manager/dashboard_controller.rb +0 -31
- data/app/controllers/vyapari/store_manager/reports/invoices_controller.rb +0 -249
- data/app/controllers/vyapari/store_manager/reports/sales_controller.rb +0 -299
- data/app/controllers/vyapari/store_manager/reports/stock_controller.rb +0 -132
- data/app/controllers/vyapari/store_manager/resource_controller.rb +0 -17
- data/app/controllers/vyapari/store_manager/stock_bundles_controller.rb +0 -206
- data/app/controllers/vyapari/store_manager/stock_entries_controller.rb +0 -161
- data/app/controllers/vyapari/terminal_staff/base_controller.rb +0 -38
- data/app/controllers/vyapari/terminal_staff/dashboard_controller.rb +0 -35
- data/app/controllers/vyapari/terminal_staff/invoices_controller.rb +0 -147
- data/app/controllers/vyapari/terminal_staff/line_items_controller.rb +0 -139
- data/app/controllers/vyapari/terminal_staff/resource_controller.rb +0 -17
- data/app/controllers/vyapari/user_dashboard_controller.rb +0 -31
- data/app/models/bank_account.rb +0 -44
- data/app/models/contact.rb +0 -72
- data/app/models/image/brand_image.rb +0 -3
- data/app/models/image/category_image.rb +0 -3
- data/app/models/image/product_image.rb +0 -3
- data/app/models/invoice.rb +0 -256
- data/app/models/line_item.rb +0 -207
- data/app/models/stock_bundle.rb +0 -249
- data/app/models/stock_entry.rb +0 -275
- data/app/models/store.rb +0 -302
- data/app/models/supplier.rb +0 -79
- data/app/models/terminal.rb +0 -158
- data/app/uploaders/brand_image_uploader.rb +0 -14
- data/app/uploaders/category_image_uploader.rb +0 -14
- data/app/uploaders/product_image_uploader.rb +0 -14
- data/app/uploaders/stock_bundle_uploader.rb +0 -10
- data/app/views/layouts/vyapari/_store_manager_menu.html.erb +0 -126
- data/app/views/layouts/vyapari/_terminal_staff_menu.html.erb +0 -106
- data/app/views/layouts/vyapari/store_manager.html.erb +0 -112
- data/app/views/layouts/vyapari/terminal_staff.html.erb +0 -116
- data/app/views/vyapari/admin/brands/_form.html.erb +0 -23
- data/app/views/vyapari/admin/brands/_index.html.erb +0 -89
- data/app/views/vyapari/admin/brands/_row.html.erb +0 -63
- data/app/views/vyapari/admin/brands/_show.html.erb +0 -104
- data/app/views/vyapari/admin/brands/index.html.erb +0 -48
- data/app/views/vyapari/admin/categories/_form.html.erb +0 -28
- data/app/views/vyapari/admin/categories/_index.html.erb +0 -101
- data/app/views/vyapari/admin/categories/_row.html.erb +0 -69
- data/app/views/vyapari/admin/categories/_show.html.erb +0 -115
- data/app/views/vyapari/admin/products/_form.html.erb +0 -32
- data/app/views/vyapari/admin/products/_index.html.erb +0 -58
- data/app/views/vyapari/admin/products/_row.html.erb +0 -30
- data/app/views/vyapari/admin/products/_show.html.erb +0 -81
- data/app/views/vyapari/admin/products/index.html.erb +0 -48
- data/app/views/vyapari/admin/stores/_form.html.erb +0 -37
- data/app/views/vyapari/admin/stores/_index.html.erb +0 -84
- data/app/views/vyapari/admin/stores/_row.html.erb +0 -55
- data/app/views/vyapari/admin/stores/_show.html.erb +0 -110
- data/app/views/vyapari/admin/stores/index.html.erb +0 -48
- data/app/views/vyapari/admin/suppliers/_form.html.erb +0 -32
- data/app/views/vyapari/admin/suppliers/_index.html.erb +0 -58
- data/app/views/vyapari/admin/suppliers/_row.html.erb +0 -30
- data/app/views/vyapari/admin/suppliers/_show.html.erb +0 -81
- data/app/views/vyapari/admin/suppliers/index.html.erb +0 -48
- data/app/views/vyapari/admin/terminals/_form.html.erb +0 -24
- data/app/views/vyapari/admin/terminals/_index.html.erb +0 -75
- data/app/views/vyapari/admin/terminals/_row.html.erb +0 -49
- data/app/views/vyapari/admin/terminals/_show.html.erb +0 -74
- data/app/views/vyapari/store_manager/dashboard/_sales_counts.html.erb +0 -90
- data/app/views/vyapari/store_manager/dashboard/_stock_counts.html.erb +0 -63
- data/app/views/vyapari/store_manager/dashboard/_terminals.html.erb +0 -23
- data/app/views/vyapari/store_manager/dashboard/index.html.erb +0 -64
- data/app/views/vyapari/store_manager/reports/invoices/_index.html.erb +0 -65
- data/app/views/vyapari/store_manager/reports/invoices/index.html.erb +0 -105
- data/app/views/vyapari/store_manager/reports/sales/_index.html.erb +0 -64
- data/app/views/vyapari/store_manager/reports/sales/index.html.erb +0 -105
- data/app/views/vyapari/store_manager/reports/stock/_index.html.erb +0 -72
- data/app/views/vyapari/store_manager/reports/stock/index.html.erb +0 -32
- data/app/views/vyapari/store_manager/stock_bundles/_form.html.erb +0 -99
- data/app/views/vyapari/store_manager/stock_bundles/_index.html.erb +0 -74
- data/app/views/vyapari/store_manager/stock_bundles/_row.html.erb +0 -44
- data/app/views/vyapari/store_manager/stock_bundles/_show.html.erb +0 -110
- data/app/views/vyapari/store_manager/stock_bundles/create.html.erb +0 -57
- data/app/views/vyapari/store_manager/stock_bundles/index.html.erb +0 -36
- data/app/views/vyapari/store_manager/stock_bundles/update.html.erb +0 -57
- data/app/views/vyapari/store_manager/stock_entries/_form.html.erb +0 -50
- data/app/views/vyapari/store_manager/stock_entries/_index.html.erb +0 -80
- data/app/views/vyapari/store_manager/stock_entries/_row.html.erb +0 -33
- data/app/views/vyapari/store_manager/stock_entries/_show.html.erb +0 -110
- data/app/views/vyapari/store_manager/stock_entries/_stock_bundle.html.erb +0 -61
- data/app/views/vyapari/store_manager/stock_entries/index.html.erb +0 -45
- data/app/views/vyapari/terminal_staff/dashboard/_counts.html.erb +0 -131
- data/app/views/vyapari/terminal_staff/dashboard/_invoices.html.erb +0 -44
- data/app/views/vyapari/terminal_staff/dashboard/_search_form.html.erb +0 -6
- data/app/views/vyapari/terminal_staff/dashboard/_search_results.html.erb +0 -24
- data/app/views/vyapari/terminal_staff/dashboard/index.html.erb +0 -56
- data/app/views/vyapari/terminal_staff/dashboard/search.js.erb +0 -12
- data/app/views/vyapari/terminal_staff/invoices/_draft.html.erb +0 -62
- data/app/views/vyapari/terminal_staff/invoices/_form.html.erb +0 -134
- data/app/views/vyapari/terminal_staff/invoices/_index.html.erb +0 -70
- data/app/views/vyapari/terminal_staff/invoices/_row.html.erb +0 -33
- data/app/views/vyapari/terminal_staff/invoices/_show.html.erb +0 -204
- data/app/views/vyapari/terminal_staff/invoices/index.html.erb +0 -35
- data/app/views/vyapari/terminal_staff/invoices/new.js.erb +0 -18
- data/app/views/vyapari/terminal_staff/invoices/show.html.erb +0 -1
- data/app/views/vyapari/terminal_staff/invoices/show.js.erb +0 -13
- data/app/views/vyapari/terminal_staff/line_items/_form.html.erb +0 -40
- data/app/views/vyapari/terminal_staff/line_items/_index.html.erb +0 -96
- data/app/views/vyapari/terminal_staff/line_items/create.js.erb +0 -34
- data/app/views/vyapari/terminal_staff/line_items/destroy.js.erb +0 -25
- data/app/views/vyapari/user_dashboard/index.html.erb +0 -51
- data/db/import_data/brands.csv +0 -7
- data/db/import_data/categories.csv +0 -12
- data/db/import_data/countries.csv +0 -1
- data/db/import_data/dummy/brands.csv +0 -7
- data/db/import_data/dummy/categories.csv +0 -12
- data/db/import_data/dummy/countries.csv +0 -1
- data/db/import_data/dummy/exchange_rates.csv +0 -5
- data/db/import_data/dummy/products-copy.csv +0 -1
- data/db/import_data/dummy/products.csv +0 -1
- data/db/import_data/dummy/products.xlsx +0 -0
- data/db/import_data/dummy/regions.csv +0 -13
- data/db/import_data/dummy/stores.csv +0 -10
- data/db/import_data/dummy/suppliers.csv +0 -14
- data/db/import_data/dummy/terminals.csv +0 -11
- data/db/import_data/exchange_rates.csv +0 -5
- data/db/import_data/regions.csv +0 -13
- data/db/import_data/stores.csv +0 -3
- data/db/import_data/suppliers.csv +0 -14
- data/db/import_data/terminals.csv +0 -3
- data/db/migrate/20170000000203_create_contacts.rb +0 -22
- data/db/migrate/20170000000204_create_bank_accounts.rb +0 -21
- data/db/migrate/20170000000205_create_suppliers.rb +0 -18
- data/db/migrate/20170000000206_create_stores.rb +0 -21
- data/db/migrate/20170000000207_create_terminals.rb +0 -18
- data/db/migrate/20170000000210_create_brands.rb +0 -14
- data/db/migrate/20170000000211_create_categories.rb +0 -22
- data/db/migrate/20170000000212_create_products.rb +0 -29
- data/db/migrate/20170000000213_create_invoices.rb +0 -61
- data/db/migrate/20170000000215_create_stock_bundles.rb +0 -17
- data/db/migrate/20170000000216_create_stock_entries.rb +0 -20
- data/db/sample_reports/products.xlsx +0 -0
- data/lib/tasks/vyapari/all.rake +0 -73
@@ -1,33 +0,0 @@
|
|
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
|
-
@filter_param_mapping[:brand] = :br
|
25
|
-
@filter_param_mapping[:category] = :ct
|
26
|
-
@filter_param_mapping[:payment_method] = :pym
|
27
|
-
@filter_param_mapping[:terminal] = :trm
|
28
|
-
@filter_param_mapping[:user] = :usr
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Vyapari
|
2
|
-
module StoreManager
|
3
|
-
class DashboardController < Vyapari::StoreManager::BaseController
|
4
|
-
|
5
|
-
# GET /dashboard
|
6
|
-
def index
|
7
|
-
@date = params[:date] ? Date.parse(params[:date]) : Date.today
|
8
|
-
@terminals = @store.terminals
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def breadcrumbs_configuration
|
14
|
-
{
|
15
|
-
heading: "#{@store.name}",
|
16
|
-
description: "A Quick view of stock & sales",
|
17
|
-
links: [
|
18
|
-
{name: "Home", link: user_dashboard_path, icon: 'fa-dashboard'},
|
19
|
-
{name: @store.name, link: store_manager_dashboard_path(@store), icon: 'fa-dashboard'}
|
20
|
-
]
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def set_navs
|
25
|
-
set_nav("store_manager/dashboard")
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
@@ -1,249 +0,0 @@
|
|
1
|
-
module Vyapari
|
2
|
-
module StoreManager
|
3
|
-
module Reports
|
4
|
-
class InvoicesController < Vyapari::StoreManager::BaseController
|
5
|
-
|
6
|
-
def index
|
7
|
-
@relation = Invoice.select("
|
8
|
-
invoices.customer_name as customer_name,
|
9
|
-
invoices.customer_address as customer_address,
|
10
|
-
invoices.customer_phone as customer_phone,
|
11
|
-
invoices.customer_email as customer_email,
|
12
|
-
|
13
|
-
invoices.invoice_number as invoice_number,
|
14
|
-
invoices.invoice_date as invoice_date,
|
15
|
-
|
16
|
-
invoices.discount as discount,
|
17
|
-
TRUNCATE(invoices.net_total_amount, 2) as net_total_amount,
|
18
|
-
|
19
|
-
invoices.payment_method as payment_method,
|
20
|
-
invoices.credit_card_number as credit_card_number,
|
21
|
-
invoices.cheque_number as cheque_number,
|
22
|
-
|
23
|
-
u.name as user_name
|
24
|
-
").
|
25
|
-
joins("LEFT JOIN users u ON invoices.user_id = u.id").
|
26
|
-
where("invoices.status = 'active'").
|
27
|
-
where("invoices.store_id = ?", @store.id)
|
28
|
-
|
29
|
-
parse_filters
|
30
|
-
apply_filters
|
31
|
-
set_columns
|
32
|
-
|
33
|
-
@results = @relation.all
|
34
|
-
|
35
|
-
@total = @relation.except(:select).
|
36
|
-
select("SUM(invoices.id) as id,
|
37
|
-
SUM(invoices.net_total_amount) as net_total_amount")
|
38
|
-
|
39
|
-
render_report
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def apply_filters
|
45
|
-
@relation = @relation.search(@query) if @query
|
46
|
-
|
47
|
-
if @terminal == "null"
|
48
|
-
@relation = @relation.where("invoices.terminal_id IS NULL")
|
49
|
-
elsif @terminal
|
50
|
-
@relation = @relation.where("invoices.terminal_id = ?",@terminal.id)
|
51
|
-
end
|
52
|
-
|
53
|
-
if @user == "null"
|
54
|
-
@relation = @relation.where("invoices.user_id IS NULL")
|
55
|
-
elsif @user
|
56
|
-
@relation = @relation.where("invoices.user_id = ?",@user.id)
|
57
|
-
end
|
58
|
-
|
59
|
-
if @payment_method == "null"
|
60
|
-
@relation = @relation.where("invoices.payment_method IS NULL")
|
61
|
-
elsif @payment_method
|
62
|
-
@relation = @relation.where("invoices.payment_method = ?",@payment_method)
|
63
|
-
end
|
64
|
-
|
65
|
-
@relation = @relation.order(@order_by_options[@order_by.to_sym])
|
66
|
-
end
|
67
|
-
|
68
|
-
def configure_filter_settings
|
69
|
-
|
70
|
-
@order_by_options = {
|
71
|
-
invoice_date_desc: "invoices.invoice_date DESC",
|
72
|
-
invoice_date_asc: "invoices.invoice_date ASC",
|
73
|
-
customer_name_desc: "invoices.customer_name DESC",
|
74
|
-
customer_name_asc: "invoices.customer_name ASC",
|
75
|
-
total_amount_asc: "invoices.net_total_amount DeSC",
|
76
|
-
total_amount_asc: "invoices.net_total_amount ASC"
|
77
|
-
}
|
78
|
-
|
79
|
-
@filter_settings = {
|
80
|
-
string_filters: [
|
81
|
-
{ filter_name: :query },
|
82
|
-
{ filter_name: :order_by, options: {default: :invoice_date_desc} },
|
83
|
-
{ filter_name: :payment_method }
|
84
|
-
],
|
85
|
-
|
86
|
-
reference_filters: [
|
87
|
-
{ filter_name: :user, filter_class: User },
|
88
|
-
{ filter_name: :terminal, filter_class: Terminal },
|
89
|
-
],
|
90
|
-
|
91
|
-
variable_filters: [
|
92
|
-
{ variable_name: :store, filter_name: :store }
|
93
|
-
]
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
def configure_filter_ui_settings
|
98
|
-
@filter_ui_settings = {
|
99
|
-
terminal: {
|
100
|
-
object_filter: true,
|
101
|
-
select_label: 'Filter by Terminal',
|
102
|
-
current_value: @terminal,
|
103
|
-
values: @store.terminals.order(:name).all,
|
104
|
-
current_filters: @filters,
|
105
|
-
url_method_name: 'store_manager_invoices_report_url',
|
106
|
-
filters_to_remove: [:terminal, :store],
|
107
|
-
filters_to_add: {},
|
108
|
-
show_null_filter_on_top: false
|
109
|
-
},
|
110
|
-
user: {
|
111
|
-
object_filter: true,
|
112
|
-
select_label: 'Filter by User',
|
113
|
-
current_value: @user,
|
114
|
-
values: User.order(:name).all,
|
115
|
-
current_filters: @filters,
|
116
|
-
url_method_name: 'store_manager_invoices_report_url',
|
117
|
-
filters_to_remove: [:terminal, :store],
|
118
|
-
filters_to_add: {},
|
119
|
-
show_null_filter_on_top: true
|
120
|
-
},
|
121
|
-
payment_method: {
|
122
|
-
object_filter: false,
|
123
|
-
select_label: "Filter by Payment Method",
|
124
|
-
display_hash: Invoice::PAYMENT_METHOD_REVERSE,
|
125
|
-
current_value: @payment_method,
|
126
|
-
values: Invoice::PAYMENT_METHOD,
|
127
|
-
current_filters: @filters,
|
128
|
-
filters_to_remove: [],
|
129
|
-
filters_to_add: {},
|
130
|
-
url_method_name: 'store_manager_invoices_report_url',
|
131
|
-
show_all_filter_on_top: true
|
132
|
-
},
|
133
|
-
order_by: {
|
134
|
-
object_filter: false,
|
135
|
-
select_label: "Order by",
|
136
|
-
display_hash: Hash[@order_by_options.keys.map {|i| [i, i.to_s.titleize]}],
|
137
|
-
current_value: @order_by,
|
138
|
-
values: Hash[@order_by_options.keys.map {|i| [i.to_s.titleize, i]}],
|
139
|
-
current_filters: @filters,
|
140
|
-
filters_to_remove: [],
|
141
|
-
filters_to_add: {},
|
142
|
-
url_method_name: 'store_manager_invoices_report_url',
|
143
|
-
show_all_filter_on_top: true
|
144
|
-
},
|
145
|
-
}
|
146
|
-
end
|
147
|
-
|
148
|
-
def set_columns
|
149
|
-
@columns = [
|
150
|
-
{ column_name: :id, display_name: "Sl.", align: "center", column_type: :integer },
|
151
|
-
{ column_name: :customer_name, display_name: "Customer Name", align: "center", column_type: :string },
|
152
|
-
{ column_name: :customer_address, display_name: "Customer Address", align: "center", column_type: :string },
|
153
|
-
{ column_name: :customer_phone, display_name: "Customer Phone", align: "center", column_type: :string },
|
154
|
-
{ column_name: :customer_email, display_name: "Customer Email", align: "center", column_type: :string },
|
155
|
-
{ column_name: :invoice_number, display_name: "Invoice Number", align: "center", column_type: :string },
|
156
|
-
{ column_name: :invoice_date, display_name: "Invoice Date", align: "center", column_type: :date },
|
157
|
-
{ column_name: :discount, display_name: "Discount %", align: "center", column_type: :integer },
|
158
|
-
{ column_name: :net_total_amount, display_name: "Total Amount", align: "right", column_type: :currency },
|
159
|
-
{ column_name: :payment_method, display_name: "Payment Method", align: "center", column_type: :status },
|
160
|
-
{ column_name: :credit_card_number, display_name: "Credit Card Number", align: "center", column_type: :string },
|
161
|
-
{ column_name: :cheque_number, display_name: "Cheque Number", align: "center", column_type: :string },
|
162
|
-
{ column_name: :user_name, display_name: "User", align: "center", column_type: :string }
|
163
|
-
]
|
164
|
-
|
165
|
-
if params[:cols]
|
166
|
-
@selected_columns = params[:cols].map{|x| x.to_sym}
|
167
|
-
else
|
168
|
-
@selected_columns = [:id, :invoice_number, :invoice_date, :net_total_amount]
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def breadcrumbs_configuration
|
173
|
-
{
|
174
|
-
heading: "Invoices Report",
|
175
|
-
description: "Invoices Report",
|
176
|
-
links: [{name: "Change Store", link: user_dashboard_path, icon: 'fa-desktop'},
|
177
|
-
{name: @store.name, link: store_manager_dashboard_path(@store), icon: 'fa-dashboard'},
|
178
|
-
{name: "Invoices Reports", link: nil, icon: 'fa-list', active: true}]
|
179
|
-
}
|
180
|
-
end
|
181
|
-
|
182
|
-
def set_navs
|
183
|
-
set_nav("store_manager/reports")
|
184
|
-
end
|
185
|
-
|
186
|
-
def render_report
|
187
|
-
respond_to do |format|
|
188
|
-
format.html {}
|
189
|
-
format.csv do
|
190
|
-
send_data generate_csv(@results),
|
191
|
-
:type => 'text/csv; charset=utf-8; header=present',
|
192
|
-
:disposition => "attachment; filename=invoice-report.csv",
|
193
|
-
:filename => "invoice-report.csv"
|
194
|
-
end
|
195
|
-
format.pdf do
|
196
|
-
render :pdf => "#{@heading} (As on #{Date.today})"
|
197
|
-
#:disposition => 'attachment'
|
198
|
-
#:show_as_html => true
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def generate_csv(results)
|
204
|
-
|
205
|
-
CSV.generate(headers: true) do |csv|
|
206
|
-
# Adding the headings
|
207
|
-
csv << @columns.select{|col_item| @selected_columns.include?(col_item[:column_name])}.collect{|x| x[:display_name]}
|
208
|
-
|
209
|
-
# Adding the results
|
210
|
-
@results.each_with_index do |result, i|
|
211
|
-
|
212
|
-
# Remove Id as we get it with i in each_with_index
|
213
|
-
cols_without_id = @columns.reject{|col_item| col_item[:column_name] == :id}
|
214
|
-
|
215
|
-
# Select columns which are selected by the user / default
|
216
|
-
selected_cols = cols_without_id.select{|col_item| @selected_columns.include?(col_item[:column_name]) }
|
217
|
-
|
218
|
-
# Initialize result row with just serial number
|
219
|
-
result_data = [i+1]
|
220
|
-
|
221
|
-
# Iterate selected columns and populate the result data
|
222
|
-
selected_cols.each do |col_item|
|
223
|
-
|
224
|
-
case col_item[:column_type]
|
225
|
-
when :string, :integer
|
226
|
-
result_data << result.send(col_item[:column_name])
|
227
|
-
when :status
|
228
|
-
result_data << result.send(col_item[:column_name]).titleize
|
229
|
-
when :currency
|
230
|
-
result_data << sprintf("%.2f", result.send(col_item[:column_name]))
|
231
|
-
when :date
|
232
|
-
result_data << result.send(col_item[:column_name]).strftime("%d-%m-%Y")
|
233
|
-
else
|
234
|
-
result_data << result.send(col_item[:column_name])
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
# Append to CSV
|
240
|
-
csv << result_data
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
@@ -1,299 +0,0 @@
|
|
1
|
-
module Vyapari
|
2
|
-
module StoreManager
|
3
|
-
module Reports
|
4
|
-
class SalesController < Vyapari::StoreManager::BaseController
|
5
|
-
|
6
|
-
|
7
|
-
# select p.name, p.ean_sku, p.retail_price,
|
8
|
-
# se.quantity, i.invoice_number, i.invoice_date,
|
9
|
-
# i.payment_method from stock_entries se
|
10
|
-
# left join products p on p.id = se.product_id
|
11
|
-
# left join invoices i on i.id = se.invoice_id
|
12
|
-
# where se.status = 'sold'
|
13
|
-
def index
|
14
|
-
@relation = StockEntry.select("p.name as product_name,
|
15
|
-
p.ean_sku as ean_sku,
|
16
|
-
p.retail_price as retail_price,
|
17
|
-
stock_entries.quantity as quantity,
|
18
|
-
u.name as user_name,
|
19
|
-
i.invoice_number as invoice_number,
|
20
|
-
i.invoice_date as invoice_date,
|
21
|
-
i.payment_method as payment_method").
|
22
|
-
joins("LEFT JOIN products p ON stock_entries.product_id = p.id").
|
23
|
-
joins("LEFT JOIN invoices i ON stock_entries.invoice_id = i.id").
|
24
|
-
joins("LEFT JOIN users u ON i.user_id = u.id").
|
25
|
-
where("stock_entries.status = 'sold'").
|
26
|
-
where("stock_entries.store_id = ?", @store.id)
|
27
|
-
|
28
|
-
parse_filters
|
29
|
-
apply_filters
|
30
|
-
set_columns
|
31
|
-
|
32
|
-
#.page(@current_page).per(@per_page)
|
33
|
-
@results = @relation.all
|
34
|
-
|
35
|
-
@total = @relation.except(:select).
|
36
|
-
select("SUM(stock_entries.id) as id,
|
37
|
-
SUM(p.retail_price) as retail_price")
|
38
|
-
|
39
|
-
render_report
|
40
|
-
end
|
41
|
-
|
42
|
-
# select MAX(p.id) as id, MAX(p.name) as name,
|
43
|
-
# MAX(p.ean_sku) as ean_sku,
|
44
|
-
# MAX(p.purchased_price) as purchased_price,
|
45
|
-
# MAX(p.landed_price) as landed_price,
|
46
|
-
# MAX(p.selling_price) as selling_price,
|
47
|
-
# MAX(p.retail_price) as retail_price,
|
48
|
-
# SUM(se.quantity) as se_quantity,
|
49
|
-
# MAX(se.status) as se_status
|
50
|
-
# from products p left join stock_entries se
|
51
|
-
# on se.product_id = p.id group by p.id;
|
52
|
-
def index_old
|
53
|
-
@relation = Product.select("MAX(products.id) as id,
|
54
|
-
MAX(products.name) as name,
|
55
|
-
MAX(products.ean_sku) as ean_sku,
|
56
|
-
MAX(products.purchased_price) as purchased_price,
|
57
|
-
MAX(products.landed_price) as landed_price,
|
58
|
-
MAX(products.selling_price) as selling_price,
|
59
|
-
MAX(products.retail_price) as retail_price,
|
60
|
-
MAX(se.status) as se_status,
|
61
|
-
SUM(se.quantity) as se_quantity").
|
62
|
-
joins("LEFT JOIN stock_entries se ON se.product_id = products.id")
|
63
|
-
|
64
|
-
parse_filters
|
65
|
-
apply_filters
|
66
|
-
|
67
|
-
@results = @relation.group("products.id").page(@current_page).per(@per_page)
|
68
|
-
@total = @relation.except(:select).
|
69
|
-
select("SUM(products.id) as id,
|
70
|
-
SUM(products.purchased_price) as purchased_price,
|
71
|
-
SUM(products.landed_price) as landed_price,
|
72
|
-
SUM(products.selling_price) as selling_price,
|
73
|
-
SUM(products.retail_price) as retail_price")
|
74
|
-
|
75
|
-
render_report
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def apply_filters
|
81
|
-
@relation = @relation.search(@query) if @query
|
82
|
-
# @relation = @relation.where("se.se_status = ?", @status) if @status
|
83
|
-
|
84
|
-
if @terminal == "null"
|
85
|
-
@relation = @relation.where("i.terminal_id IS NULL")
|
86
|
-
elsif @terminal
|
87
|
-
@relation = @relation.where("i.terminal_id = ?",@terminal.id)
|
88
|
-
end
|
89
|
-
|
90
|
-
if @brand == "null"
|
91
|
-
@relation = @relation.where("p.brand_id IS NULL")
|
92
|
-
elsif @brand
|
93
|
-
@relation = @relation.where("p.brand_id = ?",@brand.id)
|
94
|
-
end
|
95
|
-
|
96
|
-
if @category == "null"
|
97
|
-
@relation = @relation.where("p.category_id IS NULL")
|
98
|
-
elsif @category
|
99
|
-
@relation = @relation.where("p.category_id = ?",@category.id)
|
100
|
-
end
|
101
|
-
|
102
|
-
if @payment_method == "null"
|
103
|
-
@relation = @relation.where("i.payment_method IS NULL")
|
104
|
-
elsif @payment_method
|
105
|
-
@relation = @relation.where("i.payment_method = ?",@payment_method)
|
106
|
-
end
|
107
|
-
|
108
|
-
@relation = @relation.order(@order_by_options[@order_by.to_sym])
|
109
|
-
end
|
110
|
-
|
111
|
-
def set_columns
|
112
|
-
@columns = [
|
113
|
-
{ column_name: :id, display_name: "Sl.", align: "center", column_type: :integer },
|
114
|
-
{ column_name: :product_name, display_name: "Product Name", align: "left", column_type: :string },
|
115
|
-
{ column_name: :ean_sku, display_name: "EAN/SKU", align: "left", column_type: :string },
|
116
|
-
{ column_name: :retail_price, display_name: "Retail Price", align: "right", column_type: :currency },
|
117
|
-
{ column_name: :quantity, display_name: "Quantity", align: "center", column_type: :integer },
|
118
|
-
{ column_name: :invoice_number, display_name: "Invoice Number", align: "center", column_type: :string },
|
119
|
-
{ column_name: :invoice_date, display_name: "Invoice Date", align: "center", column_type: :date },
|
120
|
-
{ column_name: :payment_method, display_name: "Payment Method", align: "center", column_type: :status },
|
121
|
-
{ column_name: :user_name, display_name: "User", align: "center", column_type: :string }
|
122
|
-
]
|
123
|
-
|
124
|
-
if params[:cols]
|
125
|
-
@selected_columns = params[:cols].map{|x| x.to_sym}
|
126
|
-
else
|
127
|
-
@selected_columns = [:id, :product_name, :ean_sku, :retail_price, :quantity, :invoice_number]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def configure_filter_settings
|
132
|
-
|
133
|
-
@order_by_options = {
|
134
|
-
invoice_date_desc: "i.invoice_date DESC",
|
135
|
-
invoice_date_asc: "i.invoice_date ASC",
|
136
|
-
quantity_desc: "stock_entries.quantity DESC",
|
137
|
-
quantity_asc: "stock_entries.quantity ASC",
|
138
|
-
product_name_asc: "p.name ASC, p.ean_sku ASC",
|
139
|
-
product_name_desc: "p.name DESC, p.ean_sku DESc"}
|
140
|
-
|
141
|
-
@filter_settings = {
|
142
|
-
string_filters: [
|
143
|
-
{ filter_name: :query },
|
144
|
-
{ filter_name: :order_by, options: {default: :invoice_date_desc} },
|
145
|
-
{ filter_name: :payment_method }
|
146
|
-
],
|
147
|
-
|
148
|
-
reference_filters: [
|
149
|
-
{ filter_name: :brand, filter_class: Brand },
|
150
|
-
{ filter_name: :category, filter_class: Category },
|
151
|
-
{ filter_name: :terminal, filter_class: Terminal },
|
152
|
-
],
|
153
|
-
|
154
|
-
variable_filters: [
|
155
|
-
{ variable_name: :store, filter_name: :store }
|
156
|
-
]
|
157
|
-
}
|
158
|
-
end
|
159
|
-
|
160
|
-
def configure_filter_ui_settings
|
161
|
-
@filter_ui_settings = {
|
162
|
-
terminal: {
|
163
|
-
object_filter: true,
|
164
|
-
select_label: 'Filter by Terminal',
|
165
|
-
current_value: @terminal,
|
166
|
-
values: @store.terminals.order(:name).all,
|
167
|
-
current_filters: @filters,
|
168
|
-
url_method_name: 'store_manager_sales_report_url',
|
169
|
-
filters_to_remove: [:terminal, :store],
|
170
|
-
filters_to_add: {},
|
171
|
-
show_null_filter_on_top: false
|
172
|
-
},
|
173
|
-
brand: {
|
174
|
-
object_filter: true,
|
175
|
-
select_label: 'Filter by Brand',
|
176
|
-
current_value: @brand,
|
177
|
-
values: Brand.order(:name).all,
|
178
|
-
current_filters: @filters,
|
179
|
-
url_method_name: 'store_manager_sales_report_url',
|
180
|
-
filters_to_remove: [:terminal, :store],
|
181
|
-
filters_to_add: {},
|
182
|
-
show_null_filter_on_top: true
|
183
|
-
},
|
184
|
-
category: {
|
185
|
-
object_filter: true,
|
186
|
-
select_label: 'Filter by Category',
|
187
|
-
current_value: @category,
|
188
|
-
values: Category.order(:name).all,
|
189
|
-
current_filters: @filters,
|
190
|
-
url_method_name: 'store_manager_sales_report_url',
|
191
|
-
filters_to_remove: [:terminal, :store],
|
192
|
-
filters_to_add: {},
|
193
|
-
show_null_filter_on_top: true
|
194
|
-
},
|
195
|
-
payment_method: {
|
196
|
-
object_filter: false,
|
197
|
-
select_label: "Filter by Payment Method",
|
198
|
-
display_hash: Invoice::PAYMENT_METHOD_REVERSE,
|
199
|
-
current_value: @payment_method,
|
200
|
-
values: Invoice::PAYMENT_METHOD,
|
201
|
-
current_filters: @filters,
|
202
|
-
filters_to_remove: [],
|
203
|
-
filters_to_add: {},
|
204
|
-
url_method_name: 'store_manager_sales_report_url',
|
205
|
-
show_all_filter_on_top: true
|
206
|
-
},
|
207
|
-
order_by: {
|
208
|
-
object_filter: false,
|
209
|
-
select_label: "Order by",
|
210
|
-
display_hash: Hash[@order_by_options.keys.map {|i| [i, i.to_s.titleize]}],
|
211
|
-
current_value: @order_by,
|
212
|
-
values: Hash[@order_by_options.keys.map {|i| [i.to_s.titleize, i]}],
|
213
|
-
current_filters: @filters,
|
214
|
-
filters_to_remove: [],
|
215
|
-
filters_to_add: {},
|
216
|
-
url_method_name: 'store_manager_sales_report_url',
|
217
|
-
show_all_filter_on_top: true
|
218
|
-
},
|
219
|
-
}
|
220
|
-
end
|
221
|
-
|
222
|
-
def breadcrumbs_configuration
|
223
|
-
{
|
224
|
-
heading: "Sales Report",
|
225
|
-
description: "Sales Report",
|
226
|
-
links: [{name: "Change Store", link: user_dashboard_path, icon: 'fa-desktop'},
|
227
|
-
{name: @store.name, link: store_manager_dashboard_path(@store), icon: 'fa-dashboard'},
|
228
|
-
{name: "Sales Reports", link: nil, icon: 'fa-list', active: true}]
|
229
|
-
}
|
230
|
-
end
|
231
|
-
|
232
|
-
def set_navs
|
233
|
-
set_nav("store_manager/reports")
|
234
|
-
end
|
235
|
-
|
236
|
-
def render_report
|
237
|
-
respond_to do |format|
|
238
|
-
format.html {}
|
239
|
-
format.csv do
|
240
|
-
send_data generate_csv(@results),
|
241
|
-
:type => 'text/csv; charset=utf-8; header=present',
|
242
|
-
:disposition => "attachment; filename=sales-report.csv",
|
243
|
-
:filename => "sales-report.csv"
|
244
|
-
end
|
245
|
-
format.pdf do
|
246
|
-
render :pdf => "#{@heading} (As on #{Date.today})"
|
247
|
-
#:disposition => 'attachment'
|
248
|
-
#:show_as_html => true
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
def generate_csv(results)
|
254
|
-
|
255
|
-
CSV.generate(headers: true) do |csv|
|
256
|
-
# Adding the headings
|
257
|
-
csv << @columns.select{|col_item| @selected_columns.include?(col_item[:column_name])}.collect{|x| x[:display_name]}
|
258
|
-
|
259
|
-
# Adding the results
|
260
|
-
@results.each_with_index do |result, i|
|
261
|
-
|
262
|
-
# Remove Id as we get it with i in each_with_index
|
263
|
-
cols_without_id = @columns.reject{|col_item| col_item[:column_name] == :id}
|
264
|
-
|
265
|
-
# Select columns which are selected by the user / default
|
266
|
-
selected_cols = cols_without_id.select{|col_item| @selected_columns.include?(col_item[:column_name]) }
|
267
|
-
|
268
|
-
# Initialize result row with just serial number
|
269
|
-
result_data = [i+1]
|
270
|
-
|
271
|
-
# Iterate selected columns and populate the result data
|
272
|
-
selected_cols.each do |col_item|
|
273
|
-
|
274
|
-
case col_item[:column_type]
|
275
|
-
when :string, :integer
|
276
|
-
result_data << result.send(col_item[:column_name])
|
277
|
-
when :status
|
278
|
-
result_data << result.send(col_item[:column_name]).titleize
|
279
|
-
when :currency
|
280
|
-
result_data << sprintf("%.2f", result.send(col_item[:column_name]))
|
281
|
-
when :date
|
282
|
-
result_data << result.send(col_item[:column_name]).strftime("%d-%m-%Y")
|
283
|
-
else
|
284
|
-
result_data << result.send(col_item[:column_name])
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
|
289
|
-
# Append to CSV
|
290
|
-
csv << result_data
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|