diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 668b64c..5afc8fc 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -3,4 +3,30 @@ class ProductsController < ApplicationController def index end + + def new + + end + + def create + + end + + def edit + + end + + def update + + end + + def destroy + + end + + private + def product_params + params.require(:product).permit(:name, :vat_id) + end + end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000..e72d315 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,3 @@ +class Product < ApplicationRecord + belongs_to :vat +end diff --git a/app/models/user_firm.rb b/app/models/user_firm.rb new file mode 100644 index 0000000..44501ae --- /dev/null +++ b/app/models/user_firm.rb @@ -0,0 +1,3 @@ +class UserFirm < ApplicationRecord + belongs_to :user +end diff --git a/app/models/vat.rb b/app/models/vat.rb new file mode 100644 index 0000000..b1aaaa7 --- /dev/null +++ b/app/models/vat.rb @@ -0,0 +1,3 @@ +class Vat < ApplicationRecord + has_many :products +end diff --git a/db/migrate/20161003080546_create_vats.rb b/db/migrate/20161003080546_create_vats.rb new file mode 100644 index 0000000..b2a87c9 --- /dev/null +++ b/db/migrate/20161003080546_create_vats.rb @@ -0,0 +1,11 @@ +class CreateVats < ActiveRecord::Migration[5.0] + def change + create_table :vats do |t| + t.string :name + t.date :start_date + t.decimal :tax_rate, { precision: 6, scale: 2 } + + t.timestamps + end + end +end diff --git a/db/migrate/20161003081113_create_products.rb b/db/migrate/20161003081113_create_products.rb new file mode 100644 index 0000000..9638c9d --- /dev/null +++ b/db/migrate/20161003081113_create_products.rb @@ -0,0 +1,12 @@ +class CreateProducts < ActiveRecord::Migration[5.0] + def change + create_table :products do |t| + t.string :name + t.references :vat, foreign_key: true + t.decimal :netto_price, { precision: 18, scale: 2 } + t.string :qnt_name + + t.timestamps + end + end +end diff --git a/db/migrate/20161003081718_create_user_firms.rb b/db/migrate/20161003081718_create_user_firms.rb new file mode 100644 index 0000000..e313790 --- /dev/null +++ b/db/migrate/20161003081718_create_user_firms.rb @@ -0,0 +1,19 @@ +class CreateUserFirms < ActiveRecord::Migration[5.0] + def change + create_table :user_firms do |t| + t.references :user, foreign_key: true + t.string :name + t.string :street + t.string :postcode + t.string :city + t.string :nip + t.string :regon + t.string :bank_name + t.string :bank_account + t.boolean :main + t.boolean :active + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ae77ac0..52cef7c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160930103815) do +ActiveRecord::Schema.define(version: 20161003081718) do create_table "customers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| t.string "name" @@ -23,6 +23,33 @@ ActiveRecord::Schema.define(version: 20160930103815) do t.datetime "updated_at", null: false end + create_table "products", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| + t.string "name" + t.integer "vat_id" + t.decimal "netto_price", precision: 18, scale: 2 + t.string "qnt_name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["vat_id"], name: "index_products_on_vat_id", using: :btree + end + + create_table "user_firms", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| + t.integer "user_id" + t.string "name" + t.string "street" + t.string "postcode" + t.string "city" + t.string "nip" + t.string "regon" + t.string "bank_name" + t.string "bank_account" + t.boolean "main" + t.boolean "active" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_user_firms_on_user_id", using: :btree + end + create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false @@ -40,4 +67,14 @@ ActiveRecord::Schema.define(version: 20160930103815) do t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree end + create_table "vats", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| + t.string "name" + t.date "start_date" + t.decimal "tax_rate", precision: 6, scale: 2 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_foreign_key "products", "vats" + add_foreign_key "user_firms", "users" end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000..4483efb --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + vat: one + netto_price: + qnt_name: MyString + +two: + name: MyString + vat: two + netto_price: + qnt_name: MyString diff --git a/test/fixtures/user_firms.yml b/test/fixtures/user_firms.yml new file mode 100644 index 0000000..d3fd53f --- /dev/null +++ b/test/fixtures/user_firms.yml @@ -0,0 +1,27 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user: one + name: MyString + street: MyString + postcode: MyString + city: MyString + nip: MyString + regon: MyString + bank_name: MyString + bank_account: MyString + main: false + active: false + +two: + user: two + name: MyString + street: MyString + postcode: MyString + city: MyString + nip: MyString + regon: MyString + bank_name: MyString + bank_account: MyString + main: false + active: false diff --git a/test/fixtures/vats.yml b/test/fixtures/vats.yml new file mode 100644 index 0000000..9764d34 --- /dev/null +++ b/test/fixtures/vats.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + start_date: 2016-10-03 + tax_rate: + +two: + name: MyString + start_date: 2016-10-03 + tax_rate: diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000..211cdd0 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_firm_test.rb b/test/models/user_firm_test.rb new file mode 100644 index 0000000..0addba2 --- /dev/null +++ b/test/models/user_firm_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserFirmTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/vat_test.rb b/test/models/vat_test.rb new file mode 100644 index 0000000..06bf22a --- /dev/null +++ b/test/models/vat_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class VatTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end