office_clerk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +73 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +9 -0
- data/Gemfile +63 -0
- data/Gemfile.lock +367 -0
- data/Guardfile +28 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/app/assets/images/admin/baskets-2.jpg +0 -0
- data/app/assets/images/admin/baskets.jpg +0 -0
- data/app/assets/images/admin/categories-2.jpg +0 -0
- data/app/assets/images/admin/categories.jpg +0 -0
- data/app/assets/images/admin/clerks-2.jpg +0 -0
- data/app/assets/images/admin/clerks.jpg +0 -0
- data/app/assets/images/admin/orders-2.jpg +0 -0
- data/app/assets/images/admin/orders.jpg +0 -0
- data/app/assets/images/admin/products-2.jpg +0 -0
- data/app/assets/images/admin/products.jpg +0 -0
- data/app/assets/images/admin/purchases-2.jpg +0 -0
- data/app/assets/images/admin/purchases.jpg +0 -0
- data/app/assets/images/admin/suppliers-2.jpg +0 -0
- data/app/assets/images/admin/suppliers.jpg +0 -0
- data/app/assets/images/alpha.png +0 -0
- data/app/assets/images/down-icon.png +0 -0
- data/app/assets/images/header.gif +0 -0
- data/app/assets/images/hihih.jpg +0 -0
- data/app/assets/images/hue.png +0 -0
- data/app/assets/images/koe.jpg +0 -0
- data/app/assets/images/missing.png +0 -0
- data/app/assets/images/saturation.png +0 -0
- data/app/assets/images/shop/basket.jpg +0 -0
- data/app/assets/images/shop/farfalla-logo.jpg +0 -0
- data/app/assets/images/shop/header.gif +0 -0
- data/app/assets/images/shop/header.jpg +0 -0
- data/app/assets/images/shop/header.png +0 -0
- data/app/assets/images/shop/kansi.jpg +0 -0
- data/app/assets/images/shop/kansi.png +0 -0
- data/app/assets/images/shop/logo.png +0 -0
- data/app/assets/images/shop/menu-gourmet.jpg +0 -0
- data/app/assets/images/shop/menu-hius.jpg +0 -0
- data/app/assets/images/shop/menu-huonetuoksu.jpg +0 -0
- data/app/assets/images/shop/menu-info.jpg +0 -0
- data/app/assets/images/shop/menu-kasvo.jpg +0 -0
- data/app/assets/images/shop/menu-laukut.jpg +0 -0
- data/app/assets/images/shop/menu-luomu.jpg +0 -0
- data/app/assets/images/shop/menu-men.jpg +0 -0
- data/app/assets/images/shop/menu-oljy.jpg +0 -0
- data/app/assets/images/shop/menu-tuoksu1.jpg +0 -0
- data/app/assets/images/shop/menu-vaatteet.jpg +0 -0
- data/app/assets/images/shop/menu-valaisin.jpg +0 -0
- data/app/assets/images/shop/menu-vartalo.jpg +0 -0
- data/app/assets/images/shop/spacer.gif +0 -0
- data/app/assets/images/shop/tausta.jpg +0 -0
- data/app/assets/images/shop/tervetuloa.gif +0 -0
- data/app/assets/images/shop/valk.png +0 -0
- data/app/assets/images/shop/valk3.png +0 -0
- data/app/assets/images/shop/violetti-lev.jpg +0 -0
- data/app/assets/images/shop/violetti.jpg +0 -0
- data/app/assets/images/ui-anim_basic_16x16.gif +0 -0
- data/app/assets/images/up-icon.png +0 -0
- data/app/assets/javascripts/admin.js +29 -0
- data/app/assets/javascripts/shop.js +30 -0
- data/app/assets/stylesheets/admin.css.scss +129 -0
- data/app/assets/stylesheets/shop-receipt.css.scss +80 -0
- data/app/assets/stylesheets/shop.css.scss +403 -0
- data/app/controllers/admin_controller.rb +23 -0
- data/app/controllers/application_controller.rb +41 -0
- data/app/controllers/baskets_controller.rb +176 -0
- data/app/controllers/categories_controller.rb +69 -0
- data/app/controllers/clerks_controller.rb +64 -0
- data/app/controllers/orders_controller.rb +57 -0
- data/app/controllers/products_controller.rb +126 -0
- data/app/controllers/purchases_controller.rb +72 -0
- data/app/controllers/sessions_controller.rb +46 -0
- data/app/controllers/shop_controller.rb +90 -0
- data/app/controllers/suppliers_controller.rb +63 -0
- data/app/helpers/admin_helper.rb +28 -0
- data/app/helpers/application_helper.rb +25 -0
- data/app/helpers/baskets_helper.rb +4 -0
- data/app/helpers/categories_helper.rb +4 -0
- data/app/helpers/orders_helper.rb +4 -0
- data/app/helpers/products_helper.rb +4 -0
- data/app/helpers/purchases_helper.rb +4 -0
- data/app/helpers/shop_helper.rb +17 -0
- data/app/helpers/suppliers_helper.rb +4 -0
- data/app/mailers/.keep +0 -0
- data/app/models/basket.rb +114 -0
- data/app/models/category.rb +27 -0
- data/app/models/clerk.rb +46 -0
- data/app/models/item.rb +26 -0
- data/app/models/order.rb +72 -0
- data/app/models/product.rb +100 -0
- data/app/models/purchase.rb +26 -0
- data/app/models/supplier.rb +15 -0
- data/app/views/addresses/_form_fields.html.haml +4 -0
- data/app/views/addresses/show.html.haml +23 -0
- data/app/views/baskets/_small.html.haml +25 -0
- data/app/views/baskets/edit.html.haml +74 -0
- data/app/views/baskets/index.html.haml +55 -0
- data/app/views/baskets/show.html.haml +18 -0
- data/app/views/categories/_treeview.html.haml +8 -0
- data/app/views/categories/_triple.html.haml +12 -0
- data/app/views/categories/edit.html.haml +36 -0
- data/app/views/categories/index.html.haml +49 -0
- data/app/views/categories/show.html.haml +30 -0
- data/app/views/clerks/edit.html.haml +20 -0
- data/app/views/clerks/index.html.haml +37 -0
- data/app/views/clerks/show.html.haml +19 -0
- data/app/views/layouts/_admin_menu.html.haml +14 -0
- data/app/views/layouts/_google.haml +8 -0
- data/app/views/layouts/_messages.html.haml +5 -0
- data/app/views/layouts/admin.html.haml +42 -0
- data/app/views/layouts/shop.html.haml +96 -0
- data/app/views/orders/edit.html.haml +25 -0
- data/app/views/orders/index.html.haml +93 -0
- data/app/views/orders/show.html.haml +37 -0
- data/app/views/products/_line.html.haml +25 -0
- data/app/views/products/_name.html.haml +4 -0
- data/app/views/products/_online.html.haml +2 -0
- data/app/views/products/_triple.html.haml +12 -0
- data/app/views/products/edit.html.haml +42 -0
- data/app/views/products/index.html.haml +86 -0
- data/app/views/products/show.html.haml +94 -0
- data/app/views/purchases/edit.html.haml +9 -0
- data/app/views/purchases/index.html.haml +52 -0
- data/app/views/purchases/show.html.haml +32 -0
- data/app/views/sessions/new.html.haml +10 -0
- data/app/views/sessions/new_clerk.html.haml +22 -0
- data/app/views/shop/_groups.html.haml +8 -0
- data/app/views/shop/_menu.html.haml +5 -0
- data/app/views/shop/_sub.html.haml +0 -0
- data/app/views/shop/checkout.haml +142 -0
- data/app/views/shop/group.html.haml +9 -0
- data/app/views/shop/main_group.html.haml +9 -0
- data/app/views/shop/order.haml +104 -0
- data/app/views/shop/product.html.haml +67 -0
- data/app/views/shop/product_list.html.haml +50 -0
- data/app/views/shop/saved_search.html +6 -0
- data/app/views/shop/sub_group.html.haml +19 -0
- data/app/views/shop/tuotteista.html.haml +40 -0
- data/app/views/shop/welcome.html.haml +103 -0
- data/app/views/suppliers/edit.html.haml +10 -0
- data/app/views/suppliers/index.html.haml +40 -0
- data/app/views/suppliers/show.html.haml +27 -0
- data/bin/bundle +3 -0
- data/bin/rails +8 -0
- data/bin/rake +8 -0
- data/bin/rspec +7 -0
- data/bin/spring +18 -0
- data/config.ru +7 -0
- data/config/application.example.yml +13 -0
- data/config/application.rb +59 -0
- data/config/application.yml +13 -0
- data/config/boot.rb +7 -0
- data/config/database.yml +25 -0
- data/config/environment.rb +6 -0
- data/config/environments/development.rb +31 -0
- data/config/environments/production.rb +80 -0
- data/config/environments/test.rb +36 -0
- data/config/i18n-tasks.yml +11 -0
- data/config/initializers/attack.rb +32 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/filter_parameter_logging.rb +4 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/migrate.rb +6 -0
- data/config/initializers/mime_types.rb +6 -0
- data/config/initializers/secret_token.rb +12 -0
- data/config/initializers/session_store.rb +3 -0
- data/config/initializers/simple_form.rb +149 -0
- data/config/initializers/simple_form_bootstrap.rb +48 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/config.yml +23 -0
- data/config/locales/en.yml +183 -0
- data/config/locales/fi.yml +211 -0
- data/config/routes.rb +108 -0
- data/db/migrate/20131224171442_clerks.rb +15 -0
- data/db/migrate/20131226110406_suppliers.rb +9 -0
- data/db/migrate/20131226143612_categories.rb +18 -0
- data/db/migrate/20131226143747_items.rb +14 -0
- data/db/migrate/20131226144134_orders.rb +21 -0
- data/db/migrate/20131226144316_baskets.rb +12 -0
- data/db/migrate/20131226151151_purchases.rb +11 -0
- data/db/migrate/20131226151332_products.rb +27 -0
- data/db/schema.rb +138 -0
- data/db/seeds.rb +4 -0
- data/lib/assets/.keep +0 -0
- data/lib/office_clerk.rb +20 -0
- data/lib/office_clerk/shipping_method.rb +35 -0
- data/lib/tasks/.keep +0 -0
- data/lib/tasks/import.rake +33 -0
- data/lib/templates/haml/scaffold/_form.html.haml +8 -0
- data/office_clerk.gemspec +46 -0
- data/public/404.html +58 -0
- data/public/422.html +58 -0
- data/public/500.html +57 -0
- data/public/favicon.ico +0 -0
- data/public/humans.txt +20 -0
- data/public/robots.txt +5 -0
- data/spec/controllers/baskets_controller_spec.rb +112 -0
- data/spec/controllers/categories_controller_spec.rb +133 -0
- data/spec/controllers/clerks_controller_spec.rb +70 -0
- data/spec/controllers/orders_controller_spec.rb +105 -0
- data/spec/controllers/products_controller_spec.rb +138 -0
- data/spec/controllers/purchases_controller_spec.rb +123 -0
- data/spec/controllers/sessions_controller_spec.rb +18 -0
- data/spec/controllers/suppliers_controller_spec.rb +137 -0
- data/spec/factories/addresses.rb +11 -0
- data/spec/factories/baskets.rb +15 -0
- data/spec/factories/categories.rb +8 -0
- data/spec/factories/clerks.rb +15 -0
- data/spec/factories/items.rb +19 -0
- data/spec/factories/orders.rb +9 -0
- data/spec/factories/products.rb +10 -0
- data/spec/factories/purchases.rb +10 -0
- data/spec/factories/suppliers.rb +7 -0
- data/spec/features/baskets/buttons_spec.rb +35 -0
- data/spec/features/baskets/edit_spec.rb +50 -0
- data/spec/features/baskets/index_spec.rb +12 -0
- data/spec/features/baskets/search_spec.rb +33 -0
- data/spec/features/baskets/show_spec.rb +21 -0
- data/spec/features/categories_spec.rb +21 -0
- data/spec/features/clerks_spec.rb +21 -0
- data/spec/features/orders_spec.rb +14 -0
- data/spec/features/products/index_spec.rb +30 -0
- data/spec/features/products/new_spec.rb +20 -0
- data/spec/features/purchases_spec.rb +14 -0
- data/spec/features/shops_spec.rb +18 -0
- data/spec/features/suppliers_spec.rb +18 -0
- data/spec/models/baskets/inventory_spec.rb +34 -0
- data/spec/models/baskets/items_spec.rb +37 -0
- data/spec/models/baskets/products_spec.rb +31 -0
- data/spec/models/category_spec.rb +18 -0
- data/spec/models/clerk/email_spec.rb +69 -0
- data/spec/models/clerk/password_spec.rb +83 -0
- data/spec/models/item_spec.rb +33 -0
- data/spec/models/locale_spec.rb +17 -0
- data/spec/models/order_spec.rb +19 -0
- data/spec/models/product_spec.rb +29 -0
- data/spec/models/purchase_spec.rb +8 -0
- data/spec/models/supplier_spec.rb +8 -0
- data/spec/routing/baskets_routing_spec.rb +35 -0
- data/spec/routing/categories_routing_spec.rb +35 -0
- data/spec/routing/orders_routing_spec.rb +35 -0
- data/spec/routing/products_routing_spec.rb +35 -0
- data/spec/routing/purchases_routing_spec.rb +35 -0
- data/spec/routing/suppliers_routing_spec.rb +35 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/request_helper.rb +31 -0
- data/test/fixtures/baskets.yml +41993 -0
- data/test/fixtures/categories.yml +638 -0
- data/test/fixtures/clerks.yml +694 -0
- data/test/fixtures/items.yml +83651 -0
- data/test/fixtures/orders.yml +58918 -0
- data/test/fixtures/products.yml +110904 -0
- data/test/fixtures/purchases.yml +1755 -0
- data/test/fixtures/suppliers.yml +341 -0
- data/todo +8 -0
- metadata +607 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
class PurchasesController < AdminController
|
3
|
+
|
4
|
+
before_filter :load_purchase, :only => [:show, :edit, :update , :order , :receive , :inventory]
|
5
|
+
|
6
|
+
# Uncomment for check abilities with CanCan
|
7
|
+
#authorize_resource
|
8
|
+
|
9
|
+
def index
|
10
|
+
@q = Purchase.search params[:q]
|
11
|
+
@purchase_scope = @q.result(:distinct => true)
|
12
|
+
@purchases = @purchase_scope.includes(:basket => {:items => :product} ).paginate( :page => params[:page],:per_page => 20 ).to_a
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
# order this from supplier
|
19
|
+
def order
|
20
|
+
@purchase.order!
|
21
|
+
redirect_to purchase_path(@purchase), :notice => t(:ordered)
|
22
|
+
end
|
23
|
+
|
24
|
+
# receive the stuff (ie add to inventory)
|
25
|
+
def receive
|
26
|
+
items = @purchase.receive!
|
27
|
+
redirect_to purchase_path(@purchase), :notice => [t(:received) ,items ,t(:items)].join(" ")
|
28
|
+
end
|
29
|
+
|
30
|
+
# receive the stuff (ie add to inventory)
|
31
|
+
def inventory
|
32
|
+
items = @purchase.inventory!
|
33
|
+
redirect_to purchase_path(@purchase), :notice => [t(:inventorized) ,items ,t(:items)].join(" ")
|
34
|
+
end
|
35
|
+
|
36
|
+
def new
|
37
|
+
@purchase = Purchase.new
|
38
|
+
render :edit
|
39
|
+
end
|
40
|
+
|
41
|
+
def edit
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def create
|
46
|
+
@purchase = Purchase.create(params_for_model)
|
47
|
+
if @purchase.save
|
48
|
+
redirect_to purchase_path(@purchase), :notice => t(:create_success, :model => "purchase")
|
49
|
+
else
|
50
|
+
render :edit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def update
|
55
|
+
if @purchase.update_attributes(params_for_model)
|
56
|
+
redirect_to purchase_path(@purchase), :notice => t(:update_success, :model => "purchase")
|
57
|
+
else
|
58
|
+
render :action => :edit
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def load_purchase
|
65
|
+
@purchase = Purchase.where( :id => params[:id]).includes( :basket => {:items => {:product => :supplier}} ).first
|
66
|
+
end
|
67
|
+
|
68
|
+
def params_for_model
|
69
|
+
params.require(:purchase).permit(:name,:ordered_on,:received_on,:basket_id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
layout "shop"
|
3
|
+
|
4
|
+
def new
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
clerk = Clerk.where(:email => params[:email]).limit(1).first
|
9
|
+
if clerk && clerk.valid_password?(params[:password])
|
10
|
+
session[:clerk_email] = clerk.email
|
11
|
+
url = clerk.admin ? baskets_url : root_url
|
12
|
+
redirect_to url , :notice => I18n.t(:signed_in)
|
13
|
+
else
|
14
|
+
render "new" , :notice => I18n.t(:sign_in_invalid)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy
|
19
|
+
session[:clerk_email] = nil
|
20
|
+
redirect_to root_url, :notice => I18n.t(:signed_out)
|
21
|
+
end
|
22
|
+
|
23
|
+
def new_clerk
|
24
|
+
@clerk = Clerk.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_clerk
|
28
|
+
@clerk = current_clerk
|
29
|
+
if @clerk.update_attributes(params[:clerk])
|
30
|
+
redirect_to root_url, :notice => I18n.t(:updated)
|
31
|
+
else
|
32
|
+
render :action => 'edit'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_clerk
|
37
|
+
@clerk = Clerk.new(params[:clerk])
|
38
|
+
if @clerk.save
|
39
|
+
session[:clerk_email] = @clerk.email
|
40
|
+
redirect_to root_url, :notice => "Signed up!"
|
41
|
+
else
|
42
|
+
render "new"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
class ShopController < ApplicationController
|
2
|
+
before_action :load
|
3
|
+
|
4
|
+
layout "shop"
|
5
|
+
|
6
|
+
def welcome
|
7
|
+
@groups = Category.online.where( :category_id => nil )
|
8
|
+
render :layout => false
|
9
|
+
end
|
10
|
+
|
11
|
+
def product
|
12
|
+
@product = Product.shop_products.where(:link => params[:link]).first
|
13
|
+
unless @product
|
14
|
+
redirect_to :action => :group
|
15
|
+
return
|
16
|
+
end
|
17
|
+
@group = @product.category
|
18
|
+
#error handling
|
19
|
+
# @group = Category.find(@product.category_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
# the checkout page creates an order upon completion. So before a checkout the basket is attached to the session
|
23
|
+
# and by filling out all data an order is created with the basket and the session zeroed
|
24
|
+
def checkout
|
25
|
+
@order = Order.new :ordered_on => Date.today
|
26
|
+
@order.basket = current_basket
|
27
|
+
if(request.get?)
|
28
|
+
@order.email = current_clerk.email if current_clerk
|
29
|
+
@order.shipment_type = "pickup" # price is 0 automatically
|
30
|
+
else
|
31
|
+
order_ps = params.require(:order).permit( :email,:name , :street , :city , :phone , :shipment_type )
|
32
|
+
if @order.update_attributes(order_ps)
|
33
|
+
new_basket
|
34
|
+
redirect_to shop_order_path(@order), :notice => t(:thanks)
|
35
|
+
return
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def order
|
41
|
+
if( params[:id])
|
42
|
+
@order = Order.find( params[:id] )
|
43
|
+
else
|
44
|
+
raise "last order of logged person"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add
|
49
|
+
prod = Product.find( params[:id]) # no id will raise which in turn will show home page
|
50
|
+
current_basket.add_product(prod)
|
51
|
+
if request.get?
|
52
|
+
redirect_to shop_checkout_path
|
53
|
+
else
|
54
|
+
redirect_to shop_group_path(prod.category.link), :notice => "#{t(:product_added)}: #{prod.name}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
def remove
|
58
|
+
prod = Product.find( params[:id]) # no id will raise which in turn will show home page
|
59
|
+
current_basket.add_product(prod , -1)
|
60
|
+
redirect_to shop_checkout_path
|
61
|
+
end
|
62
|
+
|
63
|
+
def group
|
64
|
+
@group = Category.online.where(:link => params[:link]).first
|
65
|
+
if @group
|
66
|
+
@products = @group.shop_products
|
67
|
+
template = "product_list"
|
68
|
+
@groups = @group.categories.online
|
69
|
+
else
|
70
|
+
@groups = Category.online.where( :category_id => nil )
|
71
|
+
template = "main_group"
|
72
|
+
end
|
73
|
+
render template
|
74
|
+
end
|
75
|
+
|
76
|
+
def page
|
77
|
+
@products = Product.shop_products.limit(50)
|
78
|
+
template = params[:id]
|
79
|
+
template = "tuotteista" if template.blank?
|
80
|
+
render template
|
81
|
+
end
|
82
|
+
private
|
83
|
+
def load
|
84
|
+
@menu = {"/page/kotisivu" => "KOTISIVU" ,
|
85
|
+
"/group/start" => "VERKKOKAUPPA" ,
|
86
|
+
"/page/tuotteista" => "TUOTTEISTA",
|
87
|
+
"/page/toimitusehdot" => "TOIMITUSEHDOT" ,
|
88
|
+
"/page/liike" => "LIIKKEEMME" }
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
|
3
|
+
# A Supplier spupplies inventory for products.
|
4
|
+
# The object itself only has an address, it's main function is to be the owner of purchase orders
|
5
|
+
# In other words the supplier is to the Purchase what the User is to an order.
|
6
|
+
#
|
7
|
+
class SuppliersController < AdminController
|
8
|
+
|
9
|
+
before_filter :load_supplier, :only => [:show, :edit, :update, :destroy]
|
10
|
+
|
11
|
+
# Uncomment for check abilities with CanCan
|
12
|
+
# authorize_resource
|
13
|
+
|
14
|
+
def index
|
15
|
+
@q = Supplier.search(params[:q])
|
16
|
+
@supplier_scope = @q.result(:distinct => true)
|
17
|
+
@suppliers = @supplier_scope.paginate(:page => params[:page], :per_page => 20).to_a
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
end
|
22
|
+
|
23
|
+
def new
|
24
|
+
@supplier = Supplier.new
|
25
|
+
render :edit
|
26
|
+
end
|
27
|
+
|
28
|
+
def edit
|
29
|
+
end
|
30
|
+
|
31
|
+
def create
|
32
|
+
@supplier = Supplier.create(params_for_supplier)
|
33
|
+
if @supplier.save
|
34
|
+
redirect_to supplier_path(@supplier), :notice => t(:create_success, :model => :supplier)
|
35
|
+
else
|
36
|
+
render :edit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
@supplier.update_attributes params_for_supplier
|
42
|
+
if @supplier.save
|
43
|
+
redirect_to supplier_path(@supplier), :notice => t(:update_success, :model => :supplier)
|
44
|
+
else
|
45
|
+
render :action => :edit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
# @supplier.deleted_at = Time.now
|
51
|
+
redirect_to suppliers_url
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def load_supplier
|
57
|
+
@supplier = Supplier.find(params[:id])
|
58
|
+
end
|
59
|
+
|
60
|
+
def params_for_supplier
|
61
|
+
params.require(:supplier).permit!
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
module AdminHelper
|
3
|
+
|
4
|
+
def basket_edit_link basket , options = {}
|
5
|
+
return "---" unless basket
|
6
|
+
return "" unless request.url.include?("basket")
|
7
|
+
text = t(:edit) + " "
|
8
|
+
link = edit_basket_path(basket)
|
9
|
+
case basket.kori_type
|
10
|
+
when "Order"
|
11
|
+
text += I18n.t(:order)
|
12
|
+
link = order_path(basket.kori) rescue ""
|
13
|
+
when "Purchase"
|
14
|
+
text += I18n.t(:purchase)
|
15
|
+
link = purchase_path(basket.kori) rescue ""
|
16
|
+
end
|
17
|
+
return link_to text , link , options
|
18
|
+
end
|
19
|
+
|
20
|
+
def sorting_header(model_name, attribute_name, namespace)
|
21
|
+
attribute_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def sort_date key
|
25
|
+
return "" unless params[:q]
|
26
|
+
params[:q][key] || ""
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
def markdown text
|
5
|
+
return "" if text.blank?
|
6
|
+
return sanitize Kramdown::Document.new(text).to_html
|
7
|
+
end
|
8
|
+
|
9
|
+
def euros price
|
10
|
+
price ? number_to_currency(price , :precision => 2 , :unit => "€") : 0.0
|
11
|
+
end
|
12
|
+
|
13
|
+
def date d
|
14
|
+
return "" unless d
|
15
|
+
I18n.l d
|
16
|
+
end
|
17
|
+
|
18
|
+
# change the default link renderer for will_paginate and add global options
|
19
|
+
def paginate(collection , options = {})
|
20
|
+
#options = options.merge defaults
|
21
|
+
options[:renderer] = BootstrapPagination::Rails
|
22
|
+
will_paginate collection, options
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ShopHelper
|
2
|
+
def parents(group)
|
3
|
+
parents = []
|
4
|
+
while group
|
5
|
+
parents << group
|
6
|
+
group = group.category
|
7
|
+
end
|
8
|
+
parents.reverse
|
9
|
+
end
|
10
|
+
def in_group( product , get = 4)
|
11
|
+
group = product.category
|
12
|
+
return [] unless group
|
13
|
+
prods = group.shop_products.to_a
|
14
|
+
prods.delete(product)
|
15
|
+
prods.sample(get)
|
16
|
+
end
|
17
|
+
end
|
data/app/mailers/.keep
ADDED
File without changes
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class Basket < ActiveRecord::Base
|
2
|
+
|
3
|
+
default_scope { order('created_at DESC') }
|
4
|
+
|
5
|
+
belongs_to :kori, polymorphic: true #kori is basket in finnish
|
6
|
+
|
7
|
+
has_many :items, autosave: true
|
8
|
+
before_save :cache_total
|
9
|
+
|
10
|
+
accepts_nested_attributes_for :items
|
11
|
+
|
12
|
+
def quantity
|
13
|
+
items.sum(:quantity)
|
14
|
+
end
|
15
|
+
|
16
|
+
def empty?
|
17
|
+
self.items.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
def cache_total
|
21
|
+
self.total_price = items.to_a.sum{ |i| i.total }
|
22
|
+
self.total_tax = items.to_a.sum{ |i| i.tax_amount}
|
23
|
+
end
|
24
|
+
|
25
|
+
def touch
|
26
|
+
cache_total
|
27
|
+
super
|
28
|
+
save!
|
29
|
+
end
|
30
|
+
|
31
|
+
#return a hash of rate => amount
|
32
|
+
def taxes
|
33
|
+
taxes = Hash.new(0.0)
|
34
|
+
items.each do |item|
|
35
|
+
taxes[item.tax] += item.tax_amount
|
36
|
+
end
|
37
|
+
taxes
|
38
|
+
end
|
39
|
+
|
40
|
+
# receiving the goods means that the item quantity is added to the stock (product.inventory)
|
41
|
+
# also we change the price to the products cost price
|
42
|
+
# locks the basket so receiving or deductiing becomes an error.
|
43
|
+
def receive!
|
44
|
+
raise "Locked since #{self.locked}" if self.locked
|
45
|
+
sum = 0
|
46
|
+
self.items.each do |item|
|
47
|
+
prod = item.product
|
48
|
+
prod.inventory = prod.inventory + item.quantity
|
49
|
+
prod.save!
|
50
|
+
sum += item.quantity
|
51
|
+
item.price = item.product.cost
|
52
|
+
# item.save!
|
53
|
+
end
|
54
|
+
self.locked = Date.today
|
55
|
+
self.save!
|
56
|
+
sum
|
57
|
+
end
|
58
|
+
|
59
|
+
# locks the basket so receiving or deducting becomes an error.
|
60
|
+
# deduct the items from inventory, change affects immediately in the products
|
61
|
+
def deduct!
|
62
|
+
raise "Locked since #{self.locked}" if self.locked
|
63
|
+
sum = 0
|
64
|
+
self.items.each do |item|
|
65
|
+
prod = item.product
|
66
|
+
prod.inventory = prod.inventory - item.quantity
|
67
|
+
sum += item.quantity
|
68
|
+
prod.save!
|
69
|
+
end
|
70
|
+
self.locked = Date.today
|
71
|
+
self.save!
|
72
|
+
sum
|
73
|
+
end
|
74
|
+
|
75
|
+
#inventoying the basket means setting the item quantity as the stock
|
76
|
+
#we actually change the basket for it to be a relative change (so as to look like a receive)
|
77
|
+
def inventory!
|
78
|
+
self.items.each { |item| item.quantity -= item.product.inventory }
|
79
|
+
self.receive!
|
80
|
+
end
|
81
|
+
|
82
|
+
def isa typ
|
83
|
+
return typ == :cart if self.kori_type == nil
|
84
|
+
self.kori_type.downcase == typ.to_s.downcase
|
85
|
+
end
|
86
|
+
|
87
|
+
def suppliers
|
88
|
+
ss = items.collect{|i| i.product.supplier if i.product}
|
89
|
+
ss.uniq!
|
90
|
+
ss.delete(nil)
|
91
|
+
ss
|
92
|
+
end
|
93
|
+
|
94
|
+
#when adding a product (with quantity) we ensure there is only one item for each product
|
95
|
+
def add_product prod , quant = 1
|
96
|
+
return unless prod
|
97
|
+
return unless quant != 0
|
98
|
+
raise "Locked since #{self.locked}" if self.locked
|
99
|
+
exists = items.where(:product_id => prod.id ).limit(1).first
|
100
|
+
if exists
|
101
|
+
exists.quantity += quant
|
102
|
+
else
|
103
|
+
exists = items.new :quantity => quant , :product => prod , :price => prod.price ,
|
104
|
+
:tax => prod.tax , :name => prod.full_name
|
105
|
+
end
|
106
|
+
if( exists.quantity == 0)
|
107
|
+
exists.delete
|
108
|
+
touch
|
109
|
+
else
|
110
|
+
exists.save!
|
111
|
+
end
|
112
|
+
reload
|
113
|
+
end
|
114
|
+
end
|