diff --git a/back-office/Gemfile b/back-office/Gemfile index 6de1ad6..e54f0da 100644 --- a/back-office/Gemfile +++ b/back-office/Gemfile @@ -31,6 +31,8 @@ gem 'puma' # for uploading images gem 'cloudinary' +gem 'tabulous' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/back-office/Gemfile.lock b/back-office/Gemfile.lock index 9906f14..5561909 100644 --- a/back-office/Gemfile.lock +++ b/back-office/Gemfile.lock @@ -63,6 +63,7 @@ GEM coffee-script-source execjs coffee-script-source (1.8.0) + colored (1.2) columnize (0.9.0) debug_inspector (0.0.2) debugger-linecache (1.2.0) @@ -177,6 +178,9 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) + tabulous (2.1.3) + colored (~> 1.2.0) + rails (>= 3.0, < 5.0.0) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) @@ -211,6 +215,7 @@ DEPENDENCIES sass-rails (~> 5.0) sdoc (~> 0.4.0) spring + tabulous turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) diff --git a/back-office/app/controllers/reports_controller.rb b/back-office/app/controllers/reports_controller.rb new file mode 100644 index 0000000..65a845d --- /dev/null +++ b/back-office/app/controllers/reports_controller.rb @@ -0,0 +1,8 @@ +class ReportsController < ApplicationController + + def items_to_order + @items = Item.items_to_order + end + + +end diff --git a/back-office/app/controllers/special_offers_controller.rb b/back-office/app/controllers/special_offers_controller.rb new file mode 100644 index 0000000..1f4d14f --- /dev/null +++ b/back-office/app/controllers/special_offers_controller.rb @@ -0,0 +1,4 @@ +class SpecialOffersController < ApplicationController + active_scaffold :"special_offer" do |conf| + end +end diff --git a/back-office/app/helpers/special_offers_helper.rb b/back-office/app/helpers/special_offers_helper.rb new file mode 100644 index 0000000..03257ac --- /dev/null +++ b/back-office/app/helpers/special_offers_helper.rb @@ -0,0 +1,2 @@ +module SpecialOffersHelper +end \ No newline at end of file diff --git a/back-office/app/models/item.rb b/back-office/app/models/item.rb index 28a4463..004e94a 100644 --- a/back-office/app/models/item.rb +++ b/back-office/app/models/item.rb @@ -3,8 +3,24 @@ class Item < ActiveRecord::Base has_many :multi_media_descriptions belongs_to :sub_category belongs_to :supplier + belongs_to :special_offer validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id, :weight, :supplier_id + # todo build a front end in backoffice (rails) + def self.items_to_order + return Item.find_by_sql(%Q{ + select s.name as supplier, i.name as item, sum(iic.count) amount, i.current_input_price + from carts c + join item_in_carts iic on iic.cart_id = c.id + join items i on i.id = iic.item_id + join suppliers s on i.supplier_id = s.id + where c.confirmed and not (c.packed or c.delivered) + group by s.name, i.name, i.current_input_price + order by s.name, amount desc; + }) + end + + end diff --git a/back-office/app/models/special_offer.rb b/back-office/app/models/special_offer.rb new file mode 100644 index 0000000..5f227a4 --- /dev/null +++ b/back-office/app/models/special_offer.rb @@ -0,0 +1,16 @@ +class SpecialOffer < ActiveRecord::Base + belongs_to :item + belongs_to :category + belongs_to :section + belongs_to :sub_category + has_many :items + + validates_presence_of :beginning, :ending, :image_url + validate :validate_beginning_before_ending + + def validate_beginning_before_ending + if beginning && ending + errors.add(:ending, "End date must come after beginning date") if ending <= beginning + end + end +end diff --git a/back-office/app/tabs/tabulous.rb b/back-office/app/tabs/tabulous.rb new file mode 100644 index 0000000..aef14c3 --- /dev/null +++ b/back-office/app/tabs/tabulous.rb @@ -0,0 +1,13 @@ +Tabulous.setup do + tabs do + + get_from_suppliers_tab do + text { 'From suppliers' } + link_path { '/' } + visible_when { true } + enabled_when { true } + active_when { in_action('any').of_controller('pictures') } + end + + end +end diff --git a/back-office/app/views/reports/items_to_order.html.erb b/back-office/app/views/reports/items_to_order.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/back-office/config/routes.rb b/back-office/config/routes.rb index 3b7fe11..bcef546 100644 --- a/back-office/config/routes.rb +++ b/back-office/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do + resources :special_offers do as_routes end resources :suppliers do as_routes end resources :places do as_routes end resources :delivery_destinations do as_routes end diff --git a/back-office/test/controllers/special_offers_controller_test.rb b/back-office/test/controllers/special_offers_controller_test.rb new file mode 100644 index 0000000..aa94ad2 --- /dev/null +++ b/back-office/test/controllers/special_offers_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class SpecialOffersControllerTest < ActionController::TestCase + setup do + @special_offer = special_offers(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:special_offers) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create special_offer" do + assert_difference('SpecialOffer.count') do + post :create, special_offer: { beginning: @special_offer.beginning, category_id: @special_offer.category_id, checkout_page: @special_offer.checkout_page, ending: @special_offer.ending, image_url: @special_offer.image_url, item_id: @special_offer.item_id, search_result_page: @special_offer.search_result_page, section_id: @special_offer.section_id, start_page: @special_offer.start_page, sub_category_id: @special_offer.sub_category_id, thank_you_page: @special_offer.thank_you_page } + end + + assert_redirected_to special_offer_path(assigns(:special_offer)) + end + + test "should show special_offer" do + get :show, id: @special_offer + assert_response :success + end + + test "should get edit" do + get :edit, id: @special_offer + assert_response :success + end + + test "should update special_offer" do + patch :update, id: @special_offer, special_offer: { beginning: @special_offer.beginning, category_id: @special_offer.category_id, checkout_page: @special_offer.checkout_page, ending: @special_offer.ending, image_url: @special_offer.image_url, item_id: @special_offer.item_id, search_result_page: @special_offer.search_result_page, section_id: @special_offer.section_id, start_page: @special_offer.start_page, sub_category_id: @special_offer.sub_category_id, thank_you_page: @special_offer.thank_you_page } + assert_redirected_to special_offer_path(assigns(:special_offer)) + end + + test "should destroy special_offer" do + assert_difference('SpecialOffer.count', -1) do + delete :destroy, id: @special_offer + end + + assert_redirected_to special_offers_path + end +end diff --git a/back-office/test/fixtures/special_offers.yml b/back-office/test/fixtures/special_offers.yml new file mode 100644 index 0000000..fbdb62a --- /dev/null +++ b/back-office/test/fixtures/special_offers.yml @@ -0,0 +1,27 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + image_url: MyString + start_page: false + section_id: 1 + category_id: 1 + sub_category_id: 1 + item_id: 1 + thank_you_page: false + search_result_page: false + checkout_page: false + beginning: 2015-03-18 + ending: 2015-03-18 + +two: + image_url: MyString + start_page: false + section_id: 1 + category_id: 1 + sub_category_id: 1 + item_id: 1 + thank_you_page: false + search_result_page: false + checkout_page: false + beginning: 2015-03-18 + ending: 2015-03-18 diff --git a/back-office/test/models/special_offer_test.rb b/back-office/test/models/special_offer_test.rb new file mode 100644 index 0000000..d0392e8 --- /dev/null +++ b/back-office/test/models/special_offer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SpecialOfferTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/front-api/db/migrate/20150315074249_add_flags_to_cart.rb b/front-api/db/migrate/20150315074249_add_flags_to_cart.rb new file mode 100644 index 0000000..72eaabe --- /dev/null +++ b/front-api/db/migrate/20150315074249_add_flags_to_cart.rb @@ -0,0 +1,10 @@ +class AddFlagsToCart < ActiveRecord::Migration + def change + add_column :carts, :confirmed, :boolean, default: false + add_column :carts, :packed, :boolean, default: false + add_column :carts, :canceled_on_check, :boolean, default: false + add_column :carts, :canceled_on_delivery, :boolean, default: false + add_column :carts, :delivered, :boolean, default: false + add_column :carts, :internal_note, :text + end +end diff --git a/front-api/db/migrate/20150318044804_create_special_offers.rb b/front-api/db/migrate/20150318044804_create_special_offers.rb new file mode 100644 index 0000000..79ac258 --- /dev/null +++ b/front-api/db/migrate/20150318044804_create_special_offers.rb @@ -0,0 +1,19 @@ +class CreateSpecialOffers < ActiveRecord::Migration + def change + create_table :special_offers do |t| + t.string :image_url + t.boolean :start_page + t.integer :section_id + t.integer :category_id + t.integer :sub_category_id + t.integer :item_id + t.boolean :thank_you_page + t.boolean :search_result_page + t.boolean :checkout_page + t.date :beginning + t.date :ending + + t.timestamps null: false + end + end +end diff --git a/front-api/db/migrate/20150318044933_add_special_offer_to_item.rb b/front-api/db/migrate/20150318044933_add_special_offer_to_item.rb new file mode 100644 index 0000000..dd666b6 --- /dev/null +++ b/front-api/db/migrate/20150318044933_add_special_offer_to_item.rb @@ -0,0 +1,5 @@ +class AddSpecialOfferToItem < ActiveRecord::Migration + def change + add_column :items, :special_offer_id, :integer + end +end diff --git a/front-api/db/schema.rb b/front-api/db/schema.rb index 66c0255..1cf77d0 100644 --- a/front-api/db/schema.rb +++ b/front-api/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150314033743) do +ActiveRecord::Schema.define(version: 20150318044933) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -23,6 +23,12 @@ ActiveRecord::Schema.define(version: 20150314033743) do t.datetime "updated_at", null: false t.string "anonymous_id_string" t.integer "delivery_destination_id" + t.boolean "confirmed" + t.boolean "packed" + t.boolean "canceled_on_check" + t.boolean "canceled_on_delivery" + t.boolean "delivered" + t.text "internal_note" end create_table "categories", force: :cascade do |t| @@ -89,6 +95,7 @@ ActiveRecord::Schema.define(version: 20150314033743) do t.json "traits" t.integer "supplier_id" t.decimal "weight", precision: 5, scale: 3 + t.integer "special_offer_id" end create_table "media_types", force: :cascade do |t| @@ -115,6 +122,22 @@ ActiveRecord::Schema.define(version: 20150314033743) do t.string "name" end + create_table "special_offers", force: :cascade do |t| + t.string "image_url" + t.boolean "start_page" + t.integer "section_id" + t.integer "category_id" + t.integer "sub_category_id" + t.integer "item_id" + t.boolean "thank_you_page" + t.boolean "search_result_page" + t.boolean "checkout_page" + t.date "beginning" + t.date "ending" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "sub_categories", force: :cascade do |t| t.string "name" t.integer "category_id"