vyapari 0.1.5dev10 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/app/models/store.rb
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
class Store < Vyapari::ApplicationRecord
|
|
2
|
-
|
|
3
|
-
# Constants
|
|
4
|
-
ACTIVE = "active"
|
|
5
|
-
INACTIVE = "inactive"
|
|
6
|
-
CLOSED = "closed"
|
|
7
|
-
|
|
8
|
-
STATUS = {"Active" => ACTIVE, "Inactive" => INACTIVE, "Closed" => CLOSED}
|
|
9
|
-
STATUS_REVERSE = {ACTIVE => "Active", INACTIVE => "Inactive", CLOSED => "Closed"}
|
|
10
|
-
|
|
11
|
-
# Constants
|
|
12
|
-
WAREHOUSE = "warehouse"
|
|
13
|
-
POS_STORE = "pos_store"
|
|
14
|
-
|
|
15
|
-
STORE_TYPES = {
|
|
16
|
-
WAREHOUSE => "Warehouse",
|
|
17
|
-
POS_STORE => "POS Store"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
STORE_TYPES_REVERSE = {
|
|
21
|
-
"Warehouse" => WAREHOUSE,
|
|
22
|
-
"POS Store" => POS_STORE
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
# Validations
|
|
26
|
-
validates :name, presence: true, length: {minimum: 2, maximum: 250}, allow_blank: false
|
|
27
|
-
validates :code, presence: true, uniqueness: true, length: {minimum: 2, maximum: 24}, allow_blank: false
|
|
28
|
-
validates :store_type, :presence => true, :inclusion => {:in => STORE_TYPES.keys, :presence_of => :store_type, :message => "%{value} is not a valid store type" }
|
|
29
|
-
validates :status, :presence=> true, :inclusion => {:in => STATUS_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
|
|
30
|
-
|
|
31
|
-
# Associations
|
|
32
|
-
belongs_to :region, optional: true
|
|
33
|
-
belongs_to :country, optional: true
|
|
34
|
-
|
|
35
|
-
has_many :terminals
|
|
36
|
-
has_many :invoices
|
|
37
|
-
has_many :stock_entries
|
|
38
|
-
has_many :stock_bundles
|
|
39
|
-
has_many :products, through: :stock_entries
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# ------------------
|
|
43
|
-
# Class Methods
|
|
44
|
-
# ------------------
|
|
45
|
-
|
|
46
|
-
# return an active record relation object with the search query in its where clause
|
|
47
|
-
# Return the ActiveRecord::Relation object
|
|
48
|
-
# == Examples
|
|
49
|
-
# >>> obj.search(query)
|
|
50
|
-
# => ActiveRecord::Relation object
|
|
51
|
-
scope :search, lambda {|query| joins(:country, :region).where("LOWER(name) LIKE LOWER('%#{query}%') OR
|
|
52
|
-
LOWER(code) LIKE LOWER('%#{query}%') OR
|
|
53
|
-
LOWER(store_type) LIKE LOWER('%#{query}%') OR
|
|
54
|
-
LOWER(regions.name) LIKE LOWER('%#{query}%') OR
|
|
55
|
-
LOWER(countries.name) LIKE LOWER('%#{query}%')")}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
scope :warehouse, -> { where(store_type: WAREHOUSE) }
|
|
59
|
-
scope :pos_store, -> { where(store_type: POS_STORE) }
|
|
60
|
-
|
|
61
|
-
scope :active, -> { where(status: ACTIVE) }
|
|
62
|
-
scope :inactive, -> { where(status: INACTIVE) }
|
|
63
|
-
scope :close, -> { where(status: CLOSED) }
|
|
64
|
-
|
|
65
|
-
scope :active_and_inactive, -> { where(status: [ACTIVE, INACTIVE]) }
|
|
66
|
-
|
|
67
|
-
def self.save_row_data(row)
|
|
68
|
-
|
|
69
|
-
row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
|
|
70
|
-
|
|
71
|
-
return if row[:name].blank?
|
|
72
|
-
|
|
73
|
-
store = Store.find_by_code(row[:code]) || Store.new
|
|
74
|
-
|
|
75
|
-
store.name = row[:name]
|
|
76
|
-
store.code = row[:code]
|
|
77
|
-
|
|
78
|
-
store.set_store_type(row[:store_type])
|
|
79
|
-
|
|
80
|
-
store.region = Region.find_by_code(row[:region]) || Country.find_by_name(row[:country])
|
|
81
|
-
store.country = Country.find_by_code(row[:country]) || Country.find_by_name(row[:country])
|
|
82
|
-
|
|
83
|
-
# Initializing error hash for displaying all errors altogether
|
|
84
|
-
error_object = Kuppayam::Importer::ErrorHash.new
|
|
85
|
-
|
|
86
|
-
if store.valid?
|
|
87
|
-
store.save!
|
|
88
|
-
else
|
|
89
|
-
summary = "Error while saving store: #{store.name}"
|
|
90
|
-
details = "Error! #{store.errors.full_messages.to_sentence}"
|
|
91
|
-
error_object.errors << { summary: summary, details: details }
|
|
92
|
-
end
|
|
93
|
-
return error_object
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# ------------------
|
|
97
|
-
# Instance Methods
|
|
98
|
-
# ------------------
|
|
99
|
-
|
|
100
|
-
def display_name
|
|
101
|
-
#self.country ? "#{self.code_was}-#{self.name_was}, #{self.country.name}" : "#{self.code_was}-#{self.name_was}"
|
|
102
|
-
"#{self.code_was}-#{self.name_was}"
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def display_store_type
|
|
106
|
-
STORE_TYPES[self.store_type]
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def set_store_type(st)
|
|
110
|
-
if STORE_TYPES.keys.include?(st)
|
|
111
|
-
self.store_type = st
|
|
112
|
-
elsif STORE_TYPES_REVERSE.keys.include?(st)
|
|
113
|
-
self.store_type = STORE_TYPES_REVERSE[st]
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def slug
|
|
118
|
-
self.name.parameterize
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def to_param
|
|
122
|
-
"#{id}-#{slug}"
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def warehouse?
|
|
126
|
-
self.store_type == WAREHOUSE
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def pos_store?
|
|
130
|
-
self.store_type == POS_STORE
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def in_stock?(product)
|
|
134
|
-
true
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# Total Counts
|
|
138
|
-
|
|
139
|
-
def total_quantity_of_products_in_stock
|
|
140
|
-
self.stock_entries.active.sum(:quantity) - self.stock_entries.sold.sum(:quantity)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def total_no_of_products_in_stock
|
|
144
|
-
self.stock_entries.active.count
|
|
145
|
-
# - self.stock_entries.sold.count
|
|
146
|
-
# self.stock_entries.active.count - self.stock_entries.sold.count
|
|
147
|
-
#begin
|
|
148
|
-
# result = Product.select("COUNT(products.id) as id, MAX(se.store_id) as store_id").
|
|
149
|
-
# joins("LEFT JOIN stock_entries se ON se.product_id = products.id").
|
|
150
|
-
# where("se.store_id = ?", self.id).
|
|
151
|
-
# group("products.id")
|
|
152
|
-
# return result.size.to_i
|
|
153
|
-
#rescue
|
|
154
|
-
#0
|
|
155
|
-
#end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
# Sold Items Count
|
|
159
|
-
|
|
160
|
-
def sold_items_count(date=Date.today)
|
|
161
|
-
self.stock_entries.dated(date).sold.sum(:quantity)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def sold_items_count_for_today
|
|
165
|
-
self.stock_entries.today.sold.sum(:quantity)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def sold_items_count_for_this_month
|
|
169
|
-
self.stock_entries.this_month.sold.sum(:quantity)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
# Damaged Items Count
|
|
173
|
-
|
|
174
|
-
def damaged_items_count(date=Date.today)
|
|
175
|
-
self.stock_entries.dated(date).damaged.sum(:quantity)
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
def damaged_items_count_for_today
|
|
179
|
-
self.stock_entries.today.damaged.sum(:quantity)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def damaged_items_count_for_this_month
|
|
183
|
-
self.stock_entries.this_month.damaged.sum(:quantity)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
# Returned Items Count
|
|
187
|
-
|
|
188
|
-
def returned_items_count(date=Date.today)
|
|
189
|
-
self.stock_entries.dated(date).returned.sum(:quantity)
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def returned_items_count_for_today
|
|
193
|
-
self.stock_entries.today.returned.sum(:quantity)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def returned_items_count_for_this_month
|
|
197
|
-
self.stock_entries.this_month.returned.sum(:quantity)
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
# Reserved Items Count
|
|
201
|
-
|
|
202
|
-
def reserved_items_count(date=Date.today)
|
|
203
|
-
self.stock_entries.dated(date).reserved.sum(:quantity)
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def reserved_items_count_for_today
|
|
207
|
-
self.stock_entries.today.reserved.sum(:quantity)
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def reserved_items_count_for_this_month
|
|
211
|
-
self.stock_entries.this_month.reserved.sum(:quantity)
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
# * Return true if the brand is active, else false.
|
|
220
|
-
# == Examples
|
|
221
|
-
# >>> brand.active?
|
|
222
|
-
# => true
|
|
223
|
-
def active?
|
|
224
|
-
(status == ACTIVE)
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
# * Return true if the brand is inactive, else false.
|
|
228
|
-
# == Examples
|
|
229
|
-
# >>> brand.inactive?
|
|
230
|
-
# => true
|
|
231
|
-
def inactive?
|
|
232
|
-
(status == INACTIVE)
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
# * Return true if the brand is closed, else false.
|
|
236
|
-
# == Examples
|
|
237
|
-
# >>> brand.closed?
|
|
238
|
-
# => true
|
|
239
|
-
def closed?
|
|
240
|
-
(status == CLOSED)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
# change the status to :active
|
|
244
|
-
# Return the status
|
|
245
|
-
# == Examples
|
|
246
|
-
# >>> brand.publish!
|
|
247
|
-
# => "active"
|
|
248
|
-
def activate!
|
|
249
|
-
self.update_attribute(:status, ACTIVE)
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
# change the status to :inactive
|
|
253
|
-
# Return the status
|
|
254
|
-
# == Examples
|
|
255
|
-
# >>> brand.publish!
|
|
256
|
-
# => "inactive"
|
|
257
|
-
def inactive!
|
|
258
|
-
self.update_attribute(:status, INACTIVE)
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
# change the status to :closed
|
|
262
|
-
# Return the status
|
|
263
|
-
# == Examples
|
|
264
|
-
# >>> brand.publish!
|
|
265
|
-
# => "closed"
|
|
266
|
-
def close!
|
|
267
|
-
self.update_attribute(:status, CLOSED)
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
def can_be_activated?
|
|
271
|
-
inactive? or closed?
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def can_be_inactivated?
|
|
275
|
-
active?
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
def can_be_closed?
|
|
279
|
-
active? or inactive?
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
def can_be_edited?
|
|
283
|
-
!closed?
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
def can_be_deleted?
|
|
287
|
-
if self.terminals.any?
|
|
288
|
-
#self.errors.add(:base, DELETE_MESSAGE)
|
|
289
|
-
return false
|
|
290
|
-
else
|
|
291
|
-
return true
|
|
292
|
-
end
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def report_heading
|
|
296
|
-
rh = []
|
|
297
|
-
rh << self.company.try(:name) if self.company.name
|
|
298
|
-
rh << self.display_name
|
|
299
|
-
rh.join(", ")
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
end
|
data/app/models/supplier.rb
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
class Supplier < Vyapari::ApplicationRecord
|
|
2
|
-
|
|
3
|
-
# Validations
|
|
4
|
-
validates :name, presence: true, length: {minimum: 2, maximum: 250}, allow_blank: false
|
|
5
|
-
validates :code, presence: true, uniqueness: true, length: {minimum: 2, maximum: 24}
|
|
6
|
-
validates :address, length: {minimum: 6, maximum: 1024}
|
|
7
|
-
validates :city, length: {minimum: 2, maximum: 56}
|
|
8
|
-
validates :country, presence: true
|
|
9
|
-
|
|
10
|
-
# Associations
|
|
11
|
-
belongs_to :country
|
|
12
|
-
has_many :stock_entries
|
|
13
|
-
has_many :products, through: :stock_entries
|
|
14
|
-
|
|
15
|
-
# ------------------
|
|
16
|
-
# Class Methods
|
|
17
|
-
# ------------------
|
|
18
|
-
|
|
19
|
-
# return an active record relation object with the search query in its where clause
|
|
20
|
-
# Return the ActiveRecord::Relation object
|
|
21
|
-
# == Examples
|
|
22
|
-
# >>> obj.search(query)
|
|
23
|
-
# => ActiveRecord::Relation object
|
|
24
|
-
scope :search, lambda {|query| joins(:country).where("LOWER(suppliers.name) LIKE LOWER('%#{query}%') OR
|
|
25
|
-
LOWER(suppliers.code) LIKE LOWER('%#{query}%') OR
|
|
26
|
-
LOWER(suppliers.address) LIKE LOWER('%#{query}%') OR
|
|
27
|
-
LOWER(suppliers.city) LIKE LOWER('%#{query}%') OR
|
|
28
|
-
LOWER(countries.name) LIKE LOWER('%#{query}%')")}
|
|
29
|
-
|
|
30
|
-
# Import Methods
|
|
31
|
-
# ---------------
|
|
32
|
-
|
|
33
|
-
def self.save_row_data(row)
|
|
34
|
-
|
|
35
|
-
row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
|
|
36
|
-
|
|
37
|
-
return if row[:name].blank?
|
|
38
|
-
|
|
39
|
-
supplier = Supplier.find_by_code(row[:code]) || Supplier.new
|
|
40
|
-
|
|
41
|
-
supplier.name = row[:name]
|
|
42
|
-
supplier.code = row[:code]
|
|
43
|
-
supplier.address = row[:address]
|
|
44
|
-
supplier.city = row[:city]
|
|
45
|
-
supplier.country = Country.find_by_code(row[:country]) || Country.find_by_name(row[:country])
|
|
46
|
-
|
|
47
|
-
# Initializing error hash for displaying all errors altogether
|
|
48
|
-
error_object = Kuppayam::Importer::ErrorHash.new
|
|
49
|
-
|
|
50
|
-
if supplier.valid?
|
|
51
|
-
supplier.save!
|
|
52
|
-
else
|
|
53
|
-
summary = "Error while saving supplier: #{supplier.name}"
|
|
54
|
-
details = "Error! #{supplier.errors.full_messages.to_sentence}"
|
|
55
|
-
error_object.errors << { summary: summary, details: details }
|
|
56
|
-
end
|
|
57
|
-
return error_object
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# ------------------
|
|
61
|
-
# Instance Methods
|
|
62
|
-
# ------------------
|
|
63
|
-
|
|
64
|
-
def display_name
|
|
65
|
-
"#{self.code_was}-#{self.name_was}"
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def can_be_edited?
|
|
69
|
-
true
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def can_be_deleted?
|
|
73
|
-
if self.stock_entries.any?
|
|
74
|
-
return false
|
|
75
|
-
else
|
|
76
|
-
return true
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
data/app/models/terminal.rb
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
class Terminal < Vyapari::ApplicationRecord
|
|
2
|
-
|
|
3
|
-
# Constants
|
|
4
|
-
ACTIVE = "active"
|
|
5
|
-
INACTIVE = "inactive"
|
|
6
|
-
CLOSED = "closed"
|
|
7
|
-
|
|
8
|
-
STATUS = {"Active" => ACTIVE, "Inactive" => INACTIVE, "Closed" => CLOSED}
|
|
9
|
-
STATUS_REVERSE = {ACTIVE => "Active", INACTIVE => "Inactive", CLOSED => "Closed"}
|
|
10
|
-
|
|
11
|
-
# Validations
|
|
12
|
-
validates :name, presence: true, length: {minimum: 2, maximum: 250}, allow_blank: false
|
|
13
|
-
validates :code, presence: true, uniqueness: true, length: {minimum: 2, maximum: 24}, allow_blank: false
|
|
14
|
-
validates :status, :presence=> true, :inclusion => {:in => STATUS_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
|
|
15
|
-
|
|
16
|
-
# Associations
|
|
17
|
-
belongs_to :store
|
|
18
|
-
has_many :invoices
|
|
19
|
-
|
|
20
|
-
# ------------------
|
|
21
|
-
# Class Methods
|
|
22
|
-
# ------------------
|
|
23
|
-
|
|
24
|
-
# return an active record relation object with the search query in its where clause
|
|
25
|
-
# Return the ActiveRecord::Relation object
|
|
26
|
-
# == Examples
|
|
27
|
-
# >>> obj.search(query)
|
|
28
|
-
# => ActiveRecord::Relation object
|
|
29
|
-
scope :search, lambda {|query| where("LOWER(name) LIKE LOWER('%#{query}%') OR
|
|
30
|
-
LOWER(code) LIKE LOWER('%#{query}%')")}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
scope :active, -> { where(status: ACTIVE) }
|
|
34
|
-
scope :inactive, -> { where(status: INACTIVE) }
|
|
35
|
-
scope :close, -> { where(status: CLOSED) }
|
|
36
|
-
|
|
37
|
-
scope :active_and_inactive, -> { where(status: [ACTIVE, INACTIVE]) }
|
|
38
|
-
|
|
39
|
-
def self.save_row_data(row)
|
|
40
|
-
|
|
41
|
-
row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
|
|
42
|
-
|
|
43
|
-
return if row[:name].blank?
|
|
44
|
-
|
|
45
|
-
terminal = Terminal.find_by_code(row[:code]) || Terminal.new
|
|
46
|
-
|
|
47
|
-
terminal.name = row[:name]
|
|
48
|
-
terminal.code = row[:code]
|
|
49
|
-
|
|
50
|
-
terminal.store = Store.find_by_code(row[:store])
|
|
51
|
-
|
|
52
|
-
# Initializing error hash for displaying all errors altogether
|
|
53
|
-
error_object = Kuppayam::Importer::ErrorHash.new
|
|
54
|
-
|
|
55
|
-
if terminal.valid?
|
|
56
|
-
terminal.save!
|
|
57
|
-
else
|
|
58
|
-
summary = "Error while saving terminal: #{terminal.name}"
|
|
59
|
-
details = "Error! #{terminal.errors.full_messages.to_sentence}"
|
|
60
|
-
error_object.errors << { summary: summary, details: details }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
return error_object
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# ------------------
|
|
67
|
-
# Instance Methods
|
|
68
|
-
# ------------------
|
|
69
|
-
|
|
70
|
-
def display_name
|
|
71
|
-
"#{self.code_was}-#{self.name_was}"
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def slug
|
|
75
|
-
self.name.parameterize
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def to_param
|
|
79
|
-
"#{id}-#{slug}"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# * Return true if the brand is active, else false.
|
|
83
|
-
# == Examples
|
|
84
|
-
# >>> brand.active?
|
|
85
|
-
# => true
|
|
86
|
-
def active?
|
|
87
|
-
(status == ACTIVE)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# * Return true if the brand is inactive, else false.
|
|
91
|
-
# == Examples
|
|
92
|
-
# >>> brand.inactive?
|
|
93
|
-
# => true
|
|
94
|
-
def inactive?
|
|
95
|
-
(status == INACTIVE)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# * Return true if the brand is closed, else false.
|
|
99
|
-
# == Examples
|
|
100
|
-
# >>> brand.closed?
|
|
101
|
-
# => true
|
|
102
|
-
def closed?
|
|
103
|
-
(status == CLOSED)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# change the status to :active
|
|
107
|
-
# Return the status
|
|
108
|
-
# == Examples
|
|
109
|
-
# >>> brand.publish!
|
|
110
|
-
# => "active"
|
|
111
|
-
def activate!
|
|
112
|
-
self.update_attribute(:status, ACTIVE)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# change the status to :inactive
|
|
116
|
-
# Return the status
|
|
117
|
-
# == Examples
|
|
118
|
-
# >>> brand.publish!
|
|
119
|
-
# => "inactive"
|
|
120
|
-
def inactive!
|
|
121
|
-
self.update_attribute(:status, INACTIVE)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# change the status to :closed
|
|
125
|
-
# Return the status
|
|
126
|
-
# == Examples
|
|
127
|
-
# >>> brand.publish!
|
|
128
|
-
# => "closed"
|
|
129
|
-
def close!
|
|
130
|
-
self.update_attribute(:status, CLOSED)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def can_be_activated?
|
|
134
|
-
inactive? or closed?
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def can_be_inactivated?
|
|
138
|
-
active?
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def can_be_closed?
|
|
142
|
-
active? or inactive?
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def can_be_edited?
|
|
146
|
-
!closed?
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def can_be_deleted?
|
|
150
|
-
if self.invoices.any?
|
|
151
|
-
#self.errors.add(:base, DELETE_MESSAGE)
|
|
152
|
-
return false
|
|
153
|
-
else
|
|
154
|
-
return true
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
end
|