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/contact.rb
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
class Contact < Vyapari::ApplicationRecord
|
|
2
|
-
|
|
3
|
-
# Validations
|
|
4
|
-
validates :name, presence: true, length: {minimum: 2, maximum: 250}, allow_blank: false
|
|
5
|
-
validates :email, length: {maximum: 128}, allow_blank: true
|
|
6
|
-
validates :phone, length: {maximum: 128}, allow_blank: true
|
|
7
|
-
|
|
8
|
-
# Associations
|
|
9
|
-
belongs_to :contactable, :polymorphic => true
|
|
10
|
-
|
|
11
|
-
# ------------------
|
|
12
|
-
# Class Methods
|
|
13
|
-
# ------------------
|
|
14
|
-
|
|
15
|
-
# return an active record relation object with the search query in its where clause
|
|
16
|
-
# Return the ActiveRecord::Relation object
|
|
17
|
-
# == Examples
|
|
18
|
-
# >>> obj.search(query)
|
|
19
|
-
# => ActiveRecord::Relation object
|
|
20
|
-
scope :search, lambda {|query| where("LOWER(contacts.name) LIKE LOWER('%#{query}%') OR
|
|
21
|
-
LOWER(contacts.email) LIKE LOWER('%#{query}%') OR
|
|
22
|
-
LOWER(contacts.phone) LIKE LOWER('%#{query}%') OR
|
|
23
|
-
LOWER(contacts.landline) LIKE LOWER('%#{query}%') OR
|
|
24
|
-
LOWER(contacts.fax) LIKE LOWER('%#{query}%') OR
|
|
25
|
-
LOWER(contacts.designation) LIKE LOWER('%#{query}%')
|
|
26
|
-
")}
|
|
27
|
-
|
|
28
|
-
# Import Methods
|
|
29
|
-
# --------------
|
|
30
|
-
|
|
31
|
-
# TODO - this is yet to be done
|
|
32
|
-
def self.save_row_data(row)
|
|
33
|
-
|
|
34
|
-
row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
|
|
35
|
-
|
|
36
|
-
return if row[:name].blank?
|
|
37
|
-
|
|
38
|
-
country = Contact.find_by_code(row[:code]) || Contact.new
|
|
39
|
-
country.name = row[:name]
|
|
40
|
-
country.code = row[:code]
|
|
41
|
-
|
|
42
|
-
# Initializing error hash for displaying all errors altogether
|
|
43
|
-
error_object = Kuppayam::Importer::ErrorHash.new
|
|
44
|
-
|
|
45
|
-
if country.valid?
|
|
46
|
-
country.save!
|
|
47
|
-
else
|
|
48
|
-
summary = "Error while saving country: #{country.name}"
|
|
49
|
-
details = "Error! #{country.errors.full_messages.to_sentence}"
|
|
50
|
-
error_object.errors << { summary: summary, details: details }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
return error_object
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# ------------------
|
|
57
|
-
# Instance Methods
|
|
58
|
-
# ------------------
|
|
59
|
-
|
|
60
|
-
def display_name
|
|
61
|
-
self.name_was
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def can_be_edited?
|
|
65
|
-
true
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def can_be_deleted?
|
|
69
|
-
false
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
end
|
data/app/models/invoice.rb
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
class Invoice < Vyapari::ApplicationRecord
|
|
2
|
-
|
|
3
|
-
# Constants
|
|
4
|
-
DRAFT = "draft"
|
|
5
|
-
ACTIVE = "active"
|
|
6
|
-
CANCELLED = "cancelled"
|
|
7
|
-
|
|
8
|
-
CASH = "cash"
|
|
9
|
-
CREDIT = "credit"
|
|
10
|
-
CREDIT_CARD = "credit_card"
|
|
11
|
-
CHEQUE = "cheque"
|
|
12
|
-
|
|
13
|
-
STATUS = {"Draft" => DRAFT, "Active" => ACTIVE, "Cancelled" => CANCELLED}
|
|
14
|
-
STATUS_REVERSE = {DRAFT => "Draft", ACTIVE => "Active", CANCELLED => "Cancelled"}
|
|
15
|
-
|
|
16
|
-
PAYMENT_METHOD = {"Cash" => CASH, "Credit" => CREDIT, "Credit Card" => CREDIT_CARD, "Cheque" => CHEQUE}
|
|
17
|
-
PAYMENT_METHOD_REVERSE = {CASH => "Cash", CREDIT => "Credid", CREDIT_CARD => "Credit Card", CHEQUE => "Cheque"}
|
|
18
|
-
|
|
19
|
-
# Call backs
|
|
20
|
-
before_save :calculate_gross_total_amount
|
|
21
|
-
|
|
22
|
-
# Validations
|
|
23
|
-
validates :invoice_number, :presence=> true
|
|
24
|
-
validates :invoice_date, :presence=> true
|
|
25
|
-
|
|
26
|
-
validates :status, :presence=> true, :inclusion => {:in => STATUS_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
|
|
27
|
-
|
|
28
|
-
# Associations
|
|
29
|
-
belongs_to :terminal
|
|
30
|
-
belongs_to :store
|
|
31
|
-
belongs_to :user
|
|
32
|
-
has_many :line_items
|
|
33
|
-
has_many :stock_entries
|
|
34
|
-
|
|
35
|
-
# ------------------
|
|
36
|
-
# Class Methods
|
|
37
|
-
# ------------------
|
|
38
|
-
|
|
39
|
-
# Scopes
|
|
40
|
-
|
|
41
|
-
# return an active record relation object with the search query in its where clause
|
|
42
|
-
# Return the ActiveRecord::Relation object
|
|
43
|
-
# == Examples
|
|
44
|
-
# >>> invoice.search(query)
|
|
45
|
-
# => ActiveRecord::Relation object
|
|
46
|
-
scope :search, lambda { |query| where("LOWER(invoice_number) LIKE LOWER('%#{query}%') OR LOWER(notes) LIKE LOWER('%#{query}%') OR LOWER(credit_card_number) LIKE LOWER('%#{query}%') OR LOWER(cheque_number) LIKE LOWER('%#{query}%') OR LOWER(customer_name) LIKE LOWER('%#{query}%') OR LOWER(customer_address) LIKE LOWER('%#{query}%') OR LOWER(net_total_amount) LIKE LOWER('%#{query}%')")
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
|
|
50
|
-
|
|
51
|
-
scope :draft, -> { where(status: DRAFT) }
|
|
52
|
-
scope :active, -> { where(status: ACTIVE) }
|
|
53
|
-
scope :cancelled, -> { where(status: CANCELLED) }
|
|
54
|
-
|
|
55
|
-
scope :cash_invoices, -> { where(payment_method: CASH) }
|
|
56
|
-
scope :credit_invoices, -> { where(payment_method: CREDIT) }
|
|
57
|
-
scope :credit_card_invoices, -> { where(payment_method: CREDIT_CARD) }
|
|
58
|
-
scope :cheque_invoices, -> { where(payment_method: CHEQUE) }
|
|
59
|
-
|
|
60
|
-
scope :payment_method, lambda { |pm| where("LOWER(payment_method)=?", ) }
|
|
61
|
-
|
|
62
|
-
scope :this_month, lambda { where("invoice_date >= ? AND invoice_date <= ?", Time.zone.now.beginning_of_month, Time.zone.now.end_of_month) }
|
|
63
|
-
scope :today, lambda { where('DATE(invoice_date) = ?', Date.current.in_time_zone)}
|
|
64
|
-
scope :dated, lambda { |d| where('DATE(invoice_date) = ?', d)}
|
|
65
|
-
|
|
66
|
-
# ------------------
|
|
67
|
-
# Instance Methods
|
|
68
|
-
# ------------------
|
|
69
|
-
|
|
70
|
-
def initialize
|
|
71
|
-
super
|
|
72
|
-
self.discount = 0.00
|
|
73
|
-
self.tax = 0.00
|
|
74
|
-
self.adjustment = 0.00
|
|
75
|
-
self.money_taken = 0.00
|
|
76
|
-
self.gross_total_amount = 0.00
|
|
77
|
-
self.net_total_amount = 0.00
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def display_name
|
|
81
|
-
self.invoice_number
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def display_status
|
|
85
|
-
STATUS_REVERSE[self.status]
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def display_payment_method
|
|
89
|
-
self.payment_method.titleize
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def slug
|
|
93
|
-
self.invoice_number.parameterize
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def generate_temporary_invoice_number
|
|
97
|
-
self.invoice_number = "#{Time.now.to_i}"
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def reset_invoice_number
|
|
101
|
-
self.update_attribute(:invoice_number, "#{INV}-#{self.terminal.code}-#{self.id}") if self.draft?
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def to_param
|
|
105
|
-
"#{id}-#{slug}"
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# * Return true if the invoice is draft, else false.
|
|
109
|
-
# == Examples
|
|
110
|
-
# >>> invoice.draft?
|
|
111
|
-
# => true
|
|
112
|
-
def draft?
|
|
113
|
-
(status == DRAFT)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# change the status to :draft
|
|
117
|
-
# Return the status
|
|
118
|
-
# == Examples
|
|
119
|
-
# >>> invoice.publish!
|
|
120
|
-
# => "draft"
|
|
121
|
-
def draft!
|
|
122
|
-
self.update_attribute(:status, DRAFT)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# * Return true if the invoice is active, else false.
|
|
126
|
-
# == Examples
|
|
127
|
-
# >>> invoice.active?
|
|
128
|
-
# => true
|
|
129
|
-
def active?
|
|
130
|
-
(status == ACTIVE)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
# change the status to :active
|
|
134
|
-
# Return the status
|
|
135
|
-
# == Examples
|
|
136
|
-
# >>> invoice.unpublish!
|
|
137
|
-
# => "active"
|
|
138
|
-
def activate!
|
|
139
|
-
self.update_attributes(status: ACTIVE)
|
|
140
|
-
#self.line_items.update_attributes(status: LineItem::SOLD)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# * Return true if the invoice is cancelled, else false.
|
|
144
|
-
# == Examples
|
|
145
|
-
# >>> invoice.cancelled?
|
|
146
|
-
# => true
|
|
147
|
-
def cancelled?
|
|
148
|
-
(status == CANCELLED)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# change the status to :cancelled
|
|
152
|
-
# Return the status
|
|
153
|
-
# == Examples
|
|
154
|
-
# >>> invoice.remove!
|
|
155
|
-
# => "cancelled"
|
|
156
|
-
def cancel!
|
|
157
|
-
self.update_attributes(status: CANCELLED)
|
|
158
|
-
#self.line_items.update_attributes(status: LineItem::CANCELLED)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# * Return true if the invoice is cash, else false.
|
|
162
|
-
# == Examples
|
|
163
|
-
# >>> invoice.cash?
|
|
164
|
-
# => true
|
|
165
|
-
def cash?
|
|
166
|
-
(payment_method == CASH)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
# * Return true if the invoice is credit, else false.
|
|
170
|
-
# == Examples
|
|
171
|
-
# >>> invoice.credit?
|
|
172
|
-
# => true
|
|
173
|
-
def credit?
|
|
174
|
-
(payment_method == CREDIT)
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# * Return true if the invoice is credit_card, else false.
|
|
178
|
-
# == Examples
|
|
179
|
-
# >>> invoice.credit_card?
|
|
180
|
-
# => true
|
|
181
|
-
def credit_card?
|
|
182
|
-
(payment_method == CREDIT_CARD)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
# * Return true if the invoice is cheque, else false.
|
|
186
|
-
# == Examples
|
|
187
|
-
# >>> invoice.cheque?
|
|
188
|
-
# => true
|
|
189
|
-
def cheque?
|
|
190
|
-
(payment_method == CHEQUE)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
def can_be_draft?
|
|
194
|
-
active? or cancelled?
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def can_be_active?
|
|
198
|
-
draft? or cancelled?
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def can_be_cancelled?
|
|
202
|
-
draft? or active?
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
# TODO
|
|
206
|
-
|
|
207
|
-
def can_be_edited?
|
|
208
|
-
true
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def can_be_deleted?
|
|
212
|
-
cancelled? && self.line_items.blank?
|
|
213
|
-
#if self.jobs.any?
|
|
214
|
-
# self.errors.add(:base, DELETE_MESSAGE)
|
|
215
|
-
# return false
|
|
216
|
-
#else
|
|
217
|
-
# return true
|
|
218
|
-
#end
|
|
219
|
-
#return true
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def update_stock_register!
|
|
223
|
-
return unless self.active?
|
|
224
|
-
self.stock_entries.destroy_all
|
|
225
|
-
self.line_items.each do |li|
|
|
226
|
-
stock_entry = StockEntry.new
|
|
227
|
-
stock_entry.store = self.store
|
|
228
|
-
stock_entry.product = li.product
|
|
229
|
-
stock_entry.invoice_id = self.id
|
|
230
|
-
stock_entry.quantity = li.quantity
|
|
231
|
-
stock_entry.status = LineItem::SOLD
|
|
232
|
-
stock_entry.save
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
def generate_real_invoice_number!
|
|
237
|
-
self.invoice_number = "INV-#{self.terminal.code}-#{self.id}"
|
|
238
|
-
self.save
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
def discount_amount
|
|
242
|
-
self.gross_total_amount * (self.discount / 100.00)
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
def balance_to_give
|
|
246
|
-
self.money_taken - self.net_total_amount
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
def calculate_gross_total_amount
|
|
250
|
-
self.gross_total_amount = self.line_items.sum("rate * quantity") || 0.0
|
|
251
|
-
total_after_discount_and_tax = self.gross_total_amount - ( self.discount / 100.00 * self.gross_total_amount) + ( self.tax / 100.00 * self.gross_total_amount)
|
|
252
|
-
self.net_total_amount = total_after_discount_and_tax.round(2)
|
|
253
|
-
self.adjustment = self.net_total_amount - total_after_discount_and_tax
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
end
|
data/app/models/line_item.rb
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
class LineItem < Vyapari::ApplicationRecord
|
|
2
|
-
|
|
3
|
-
# Constants
|
|
4
|
-
DRAFT = "draft"
|
|
5
|
-
SOLD = "sold"
|
|
6
|
-
DAMAGED = "damaged"
|
|
7
|
-
RETURNED = "returned"
|
|
8
|
-
CANCELLED = "cancelled"
|
|
9
|
-
|
|
10
|
-
STATUS = {"Draft" => DRAFT, "Sold" => SOLD, "Damaged" => DAMAGED, "Returned" => RETURNED, "Cancelled" => CANCELLED}
|
|
11
|
-
STATUS_REVERSE = {DRAFT => "Draft", SOLD => "Sold", DAMAGED => "Damaged", RETURNED => "Returned", CANCELLED => "Cancelled"}
|
|
12
|
-
|
|
13
|
-
# Call backs
|
|
14
|
-
before_save :calculate_total_amount
|
|
15
|
-
|
|
16
|
-
# Validations
|
|
17
|
-
validates :product, :presence=> true
|
|
18
|
-
validates :quantity, :presence=> true
|
|
19
|
-
validates :rate, :presence=> true
|
|
20
|
-
|
|
21
|
-
validates :status, :presence=> true, :inclusion => {:in => STATUS_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
|
|
22
|
-
|
|
23
|
-
# Associations
|
|
24
|
-
belongs_to :product, optional: true
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# ------------------
|
|
28
|
-
# Class Methods
|
|
29
|
-
# ------------------
|
|
30
|
-
|
|
31
|
-
# Scopes
|
|
32
|
-
|
|
33
|
-
# return an active record relation object with the search query in its where clause
|
|
34
|
-
# Return the ActiveRecord::Relation object
|
|
35
|
-
# == Examples
|
|
36
|
-
# >>> invoice.search(query)
|
|
37
|
-
# => ActiveRecord::Relation object
|
|
38
|
-
scope :search, lambda { |query| joins(:product).where("LOWER(products.name) LIKE LOWER('%#{query}%')")}
|
|
39
|
-
scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
|
|
40
|
-
|
|
41
|
-
scope :draft, -> { where(status: DRAFT) }
|
|
42
|
-
scope :sold, -> { where(status: SOLD) }
|
|
43
|
-
scope :damaged, -> { where(status: DAMAGED) }
|
|
44
|
-
scope :returned, -> { where(status: RETURNED) }
|
|
45
|
-
|
|
46
|
-
scope :this_month, lambda { where("created_at >= ? AND created_at <= ?", Time.zone.now.beginning_of_month, Time.zone.now.end_of_month) }
|
|
47
|
-
|
|
48
|
-
# ------------------
|
|
49
|
-
# Instance Methods
|
|
50
|
-
# ------------------
|
|
51
|
-
|
|
52
|
-
def display_name
|
|
53
|
-
if product
|
|
54
|
-
self.product.display_name
|
|
55
|
-
else
|
|
56
|
-
"#{self.id} - No Product"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# * Return true if the invoice is sold, else false.
|
|
61
|
-
# == Examples
|
|
62
|
-
# >>> invoice.sold?
|
|
63
|
-
# => true
|
|
64
|
-
def sold?
|
|
65
|
-
(status == SOLD)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# change the status to :sold
|
|
69
|
-
# Return the status
|
|
70
|
-
# == Examples
|
|
71
|
-
# >>> invoice.publish!
|
|
72
|
-
# => "sold"
|
|
73
|
-
def sold!
|
|
74
|
-
self.update_attribute(:status, SOLD)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# * Return true if the invoice is active, else false.
|
|
78
|
-
# == Examples
|
|
79
|
-
# >>> invoice.active?
|
|
80
|
-
# => true
|
|
81
|
-
def active?
|
|
82
|
-
(status == ACTIVE)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# change the status to :active
|
|
86
|
-
# Return the status
|
|
87
|
-
# == Examples
|
|
88
|
-
# >>> invoice.unpublish!
|
|
89
|
-
# => "active"
|
|
90
|
-
def activate!
|
|
91
|
-
self.update_attributes(status: ACTIVE, featured: false)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# * Return true if the invoice is cancelled, else false.
|
|
95
|
-
# == Examples
|
|
96
|
-
# >>> invoice.cancelled?
|
|
97
|
-
# => true
|
|
98
|
-
def cancelled?
|
|
99
|
-
(status == CANCELLED)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# change the status to :cancelled
|
|
103
|
-
# Return the status
|
|
104
|
-
# == Examples
|
|
105
|
-
# >>> invoice.remove!
|
|
106
|
-
# => "cancelled"
|
|
107
|
-
def cancel!
|
|
108
|
-
self.update_attributes(status: CANCELLED, featured: false)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def can_be_sold?
|
|
112
|
-
active? or cancelled?
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def can_be_active?
|
|
116
|
-
sold? or cancelled?
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def can_be_cancelled?
|
|
120
|
-
sold? or active?
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# change the status to :sold
|
|
124
|
-
# Return the status
|
|
125
|
-
# == Examples
|
|
126
|
-
# >>> stock_entry.sell!
|
|
127
|
-
# => "sold"
|
|
128
|
-
def sell!
|
|
129
|
-
self.update_attribute(:status, SOLD)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# change the status to :damaged
|
|
133
|
-
# Return the status
|
|
134
|
-
# == Examples
|
|
135
|
-
# >>> stock_entry.mark_as_damaged!
|
|
136
|
-
# => "damaged"
|
|
137
|
-
def mark_as_damaged!
|
|
138
|
-
self.update_attribute(:status, DAMAGED)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# change the status to :returned
|
|
142
|
-
# Return the status
|
|
143
|
-
# == Examples
|
|
144
|
-
# >>> stock_entry.reserve!
|
|
145
|
-
# => "returned"
|
|
146
|
-
def return!
|
|
147
|
-
self.update_attribute(:status, RETURN)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
# change the status to :draft
|
|
151
|
-
# Return the status
|
|
152
|
-
# == Examples
|
|
153
|
-
# >>> stock_entry.draft!
|
|
154
|
-
# => "draft"
|
|
155
|
-
def draft!
|
|
156
|
-
self.update_attribute(:status, DRAFT)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# * Return true if the stock_entry is sold, else false.
|
|
160
|
-
# == Examples
|
|
161
|
-
# >>> stock_entry.sold?
|
|
162
|
-
# => true
|
|
163
|
-
def sold?
|
|
164
|
-
(status == SOLD)
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
# * Return true if the stock_entry is damaged, else false.
|
|
168
|
-
# == Examples
|
|
169
|
-
# >>> stock_entry.damaged?
|
|
170
|
-
# => true
|
|
171
|
-
def damaged?
|
|
172
|
-
(status == DAMAGED)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
# * Return true if the stock_entry is returned, else false.
|
|
176
|
-
# == Examples
|
|
177
|
-
# >>> stock_entry.returned?
|
|
178
|
-
# => true
|
|
179
|
-
def returned?
|
|
180
|
-
(status == RETURNED)
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def calculate_total_amount
|
|
184
|
-
if self.quantity * self.rate
|
|
185
|
-
self.total_amount = self.quantity * self.rate
|
|
186
|
-
else
|
|
187
|
-
self.total_amount = 0.00
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# TODO
|
|
192
|
-
def can_be_edited?
|
|
193
|
-
true
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def can_be_deleted?
|
|
197
|
-
true
|
|
198
|
-
#if self.jobs.any?
|
|
199
|
-
# self.errors.add(:base, DELETE_MESSAGE)
|
|
200
|
-
# return false
|
|
201
|
-
#else
|
|
202
|
-
# return true
|
|
203
|
-
#end
|
|
204
|
-
#return true
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
end
|