diff --git a/Gemfile.lock b/Gemfile.lock index b681507..43ce13b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,7 +38,20 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + administrate (0.8.1) + actionpack (>= 4.2, < 5.2) + actionview (>= 4.2, < 5.2) + activerecord (>= 4.2, < 5.2) + autoprefixer-rails (>= 6.0) + datetime_picker_rails (~> 0.0.7) + jquery-rails (>= 4.0) + kaminari (>= 1.0) + momentjs-rails (~> 2.8) + sass-rails (~> 5.0) + selectize-rails (~> 0.6) arel (8.0.0) + autoprefixer-rails (7.1.6) + execjs bcrypt (3.1.11) bindex (0.5.0) builder (3.2.3) @@ -53,6 +66,8 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.0.5) crass (1.0.2) + datetime_picker_rails (0.0.7) + momentjs-rails (>= 2.8.1) devise (4.3.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -70,6 +85,22 @@ GEM jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + kaminari (1.1.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) + actionview + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) + activerecord + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -83,6 +114,17 @@ GEM mini_mime (0.1.4) mini_portile2 (2.3.0) minitest (5.10.3) + momentjs-rails (2.17.1) + railties (>= 3.1) + monetize (1.4.0) + money (~> 6.7) + money (6.10.0) + i18n (>= 0.6.4, < 1.0) + money-rails (1.7.0) + activesupport (>= 3.0) + monetize (~> 1.4.0) + money (~> 6.7) + railties (>= 3.0) multi_json (1.12.2) nio4r (2.1.0) nokogiri (1.8.1) @@ -140,6 +182,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + selectize-rails (0.12.4.1) spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -181,12 +224,14 @@ PLATFORMS ruby DEPENDENCIES + administrate byebug cancan coffee-rails (~> 4.2) devise jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) + money-rails omniauth pg (~> 0.18) puma (~> 3.7) diff --git a/app/models/daily_sale.rb b/app/models/daily_sale.rb new file mode 100644 index 0000000..f9f2e54 --- /dev/null +++ b/app/models/daily_sale.rb @@ -0,0 +1,3 @@ +class DailySale < ApplicationRecord + belongs_to :site +end diff --git a/app/models/role.rb b/app/models/role.rb deleted file mode 100644 index 2224cd0..0000000 --- a/app/models/role.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Role < ApplicationRecord - enum :name [ :global_admin, :site_admin ] - - belongs_to :user - - validates_uniqueness_of :user_role, scope %i[user_id, name] - - -end diff --git a/app/models/site.rb b/app/models/site.rb index f0d3c29..11e3bcd 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,2 +1,4 @@ class Site < ApplicationRecord + has_many :users + has_many :daily_sales end diff --git a/app/models/user.rb b/app/models/user.rb index dd1862f..2a911d6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,6 +5,8 @@ class User < ApplicationRecord :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable + belongs_to :site + ROLES = %i[guest minor dev global_admin] def roles=(roles) diff --git a/config/initializers/money.rb b/config/initializers/money.rb new file mode 100644 index 0000000..4e35a77 --- /dev/null +++ b/config/initializers/money.rb @@ -0,0 +1,92 @@ +# encoding : utf-8 + +MoneyRails.configure do |config| + + # To set the default currency + # + config.default_currency = :nzd + + # Set default bank object + # + # Example: + # config.default_bank = EuCentralBank.new + + # Add exchange rates to current money bank object. + # (The conversion rate refers to one direction only) + # + # Example: + # config.add_rate "USD", "CAD", 1.24515 + # config.add_rate "CAD", "USD", 0.803115 + + # To handle the inclusion of validations for monetized fields + # The default value is true + # + # config.include_validations = true + + # Default ActiveRecord migration configuration values for columns: + # + # config.amount_column = { prefix: '', # column name prefix + # postfix: '_cents', # column name postfix + # column_name: nil, # full column name (overrides prefix, postfix and accessor name) + # type: :integer, # column type + # present: true, # column will be created + # null: false, # other options will be treated as column options + # default: 0 + # } + # + # config.currency_column = { prefix: '', + # postfix: '_currency', + # column_name: nil, + # type: :string, + # present: true, + # null: false, + # default: 'USD' + # } + + # Register a custom currency + # + # Example: + # config.register_currency = { + # :priority => 1, + # :iso_code => "EU4", + # :name => "Euro with subunit of 4 digits", + # :symbol => "€", + # :symbol_first => true, + # :subunit => "Subcent", + # :subunit_to_unit => 10000, + # :thousands_separator => ".", + # :decimal_mark => "," + # } + + # Specify a rounding mode + # Any one of: + # + # BigDecimal::ROUND_UP, + # BigDecimal::ROUND_DOWN, + # BigDecimal::ROUND_HALF_UP, + # BigDecimal::ROUND_HALF_DOWN, + # BigDecimal::ROUND_HALF_EVEN, + # BigDecimal::ROUND_CEILING, + # BigDecimal::ROUND_FLOOR + # + # set to BigDecimal::ROUND_HALF_EVEN by default + # + # config.rounding_mode = BigDecimal::ROUND_HALF_UP + + # Set default money format globally. + # Default value is nil meaning "ignore this option". + # Example: + # + # config.default_format = { + # :no_cents_if_whole => nil, + # :symbol => nil, + # :sign_before_symbol => nil + # } + + # Set default raise_error_on_money_parsing option + # It will be raise error if assigned different currency + # The default value is false + # + # Example: + # config.raise_error_on_money_parsing = false +end diff --git a/config/routes.rb b/config/routes.rb index f786bcd..c8df944 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,5 +2,8 @@ devise_for :users # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - root to: 'index#home' + root to: 'site#index' + + resources :sites, :daily_sales + end diff --git a/db/migrate/20171108040624_create_daily_sales.rb b/db/migrate/20171108040624_create_daily_sales.rb new file mode 100644 index 0000000..8697cf9 --- /dev/null +++ b/db/migrate/20171108040624_create_daily_sales.rb @@ -0,0 +1,16 @@ +class CreateDailySales < ActiveRecord::Migration[5.1] + def change + create_table :daily_sales do |t| + t.references :site, null:false, foreign_key: true + t.date :sale_date, null: false + t.integer :customers, null: false, default: 0 + t.integer :units, null: false, default: 0 + t.monetize :sales_gross, default: 0 + t.text :notes + + t.timestamps + end + + add_index :daily_sales, [:site_id, :sale_date], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 41a8043..6805700 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,25 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171105122258) do +ActiveRecord::Schema.define(version: 20171108040624) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "daily_sales", force: :cascade do |t| + t.bigint "site_id", null: false + t.date "sale_date", null: false + t.integer "customers", default: 0, null: false + t.integer "units", default: 0, null: false + t.integer "sales_gross_cents", default: 0, null: false + t.string "sales_gross_currency", default: "NZD", null: false + t.text "notes" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["site_id", "sale_date"], name: "index_daily_sales_on_site_id_and_sale_date", unique: true + t.index ["site_id"], name: "index_daily_sales_on_site_id" + end + create_table "sites", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false @@ -48,5 +62,6 @@ t.index ["site_id"], name: "index_users_on_site_id" end + add_foreign_key "daily_sales", "sites" add_foreign_key "users", "sites" end diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..272a87c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "nzwinedata", + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "yarn": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/yarn/-/yarn-1.3.2.tgz", + "integrity": "sha1-WTl2JYG1tN3NNBjA9r5C3zruGV8=" + } + } +} diff --git a/package.json b/package.json index d4151af..bd52d9f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "coffeescript": "1.12.7", "prop-types": "^15.6.0", "react": "^16.0.0", - "react-dom": "^16.0.0" + "react-dom": "^16.0.0", + "yarn": "^1.3.2" }, "devDependencies": { "webpack-dev-server": "^2.9.4"