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,176 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
class BasketsController < AdminController
|
3
|
+
|
4
|
+
before_filter :load_basket, :only => [:show, :edit, :change , :update, :destroy , :order ,
|
5
|
+
:checkout, :purchase , :discount , :ean]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@q = Basket.search( params[:q] )
|
9
|
+
@basket_scope = @q.result( :distinct => true )
|
10
|
+
@baskets = @basket_scope.includes({:items => :product} , :kori).paginate( :page => params[:page], :per_page => 20 )
|
11
|
+
end
|
12
|
+
|
13
|
+
def checkout
|
14
|
+
if @basket.empty?
|
15
|
+
render :edit , :notice => t(:basket_empty)
|
16
|
+
return
|
17
|
+
end
|
18
|
+
order = @basket.kori || Order.new( :basket => @basket )
|
19
|
+
order.pos_checkout( current_clerk.email )
|
20
|
+
order.save!
|
21
|
+
redirect_to :action => :invoice , :controller => :orders , :id => order.id
|
22
|
+
end
|
23
|
+
|
24
|
+
def show
|
25
|
+
end
|
26
|
+
|
27
|
+
#as an action this order is mean as a verb, ie order this basket
|
28
|
+
def order
|
29
|
+
if @basket.empty?
|
30
|
+
render :edit , :notice => t(:basket_empty)
|
31
|
+
return
|
32
|
+
end
|
33
|
+
order = Order.create! :basket => @basket , :email => current_clerk.email , :orderd_on => Date.today
|
34
|
+
redirect_to :action => :show , :controller => :orders , :id => order.id
|
35
|
+
end
|
36
|
+
|
37
|
+
def purchase
|
38
|
+
if @basket.empty?
|
39
|
+
render :edit , :notice => t(:basket_empty)
|
40
|
+
return
|
41
|
+
end
|
42
|
+
if @basket.locked
|
43
|
+
render :show , :notice => t(:basket_locked)
|
44
|
+
return
|
45
|
+
end
|
46
|
+
purchase = Purchase.create! :basket => @basket
|
47
|
+
redirect_to :action => :show , :controller => :purchases , :id => purchase.id
|
48
|
+
end
|
49
|
+
|
50
|
+
def new
|
51
|
+
@basket = Basket.create!
|
52
|
+
render :edit
|
53
|
+
end
|
54
|
+
|
55
|
+
# refactor discount out of edit
|
56
|
+
def discount
|
57
|
+
if discount = params[:discount]
|
58
|
+
if i_id = params[:item]
|
59
|
+
item = @basket.items.find { |item| item.id.to_s == i_id }
|
60
|
+
item_discount( item , discount )
|
61
|
+
else
|
62
|
+
@basket.items.each do |item|
|
63
|
+
item_discount( item , discount )
|
64
|
+
end
|
65
|
+
end
|
66
|
+
@basket.save!
|
67
|
+
else
|
68
|
+
flash[:error] = "No discount given"
|
69
|
+
end
|
70
|
+
redirect_to :action => :edit
|
71
|
+
end
|
72
|
+
|
73
|
+
# ean search at the top of basket edit
|
74
|
+
def ean
|
75
|
+
return if locked?
|
76
|
+
ean = params[:ean]
|
77
|
+
ean.sub!("P+" , "P-") if ean[0,2] == "P+"
|
78
|
+
prod = Product.find_by_ean ean
|
79
|
+
if(prod)
|
80
|
+
@basket.add_product prod
|
81
|
+
else
|
82
|
+
prod = Product.find_by_scode ean
|
83
|
+
if(prod)
|
84
|
+
@basket.add_product prod
|
85
|
+
else
|
86
|
+
# stor the basket in the session ( or the url ???)
|
87
|
+
redirect_to :action => :index, :controller => :products,
|
88
|
+
:q => {"name_or_product_name_cont"=> ean},:basket => @basket.id
|
89
|
+
return
|
90
|
+
end
|
91
|
+
end
|
92
|
+
redirect_to :action => :edit
|
93
|
+
end
|
94
|
+
|
95
|
+
def edit
|
96
|
+
return if locked?
|
97
|
+
if p_id = (params[:add] || params[:delete])
|
98
|
+
add = params[:add].blank? ? -1 : 1
|
99
|
+
@basket.add_product Product.find(p_id) , add
|
100
|
+
flash.notice = params[:add] ? t('product_added') : t('item_removed')
|
101
|
+
end
|
102
|
+
@basket.save!
|
103
|
+
end
|
104
|
+
|
105
|
+
def create
|
106
|
+
@basket = Basket.create(params_for_basket)
|
107
|
+
if @basket.save
|
108
|
+
redirect_to basket_path(@basket), :notice => t(:create_success, :model => "basket")
|
109
|
+
else
|
110
|
+
render :edit
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def update
|
115
|
+
return if locked?
|
116
|
+
@basket.update_attributes(params_for_basket)
|
117
|
+
flash.notice = t(:update_success, :model => "basket")
|
118
|
+
redirect_to edit_basket_path(@basket)
|
119
|
+
end
|
120
|
+
|
121
|
+
def destroy
|
122
|
+
# the idea is that you can't delete a basket once something has been "done" with it (order..)
|
123
|
+
@basket.destroy unless @basket.kori_type
|
124
|
+
redirect_to baskets_url
|
125
|
+
end
|
126
|
+
|
127
|
+
def inventory
|
128
|
+
if @order.state == "complete"
|
129
|
+
flash[:error] = "Order was already completed (printed), please start with a new customer to add inventory"
|
130
|
+
render :edit
|
131
|
+
return
|
132
|
+
end
|
133
|
+
as = params[:as]
|
134
|
+
num = 0
|
135
|
+
prods = @order.basket.items.length
|
136
|
+
@order.basket.items.each do |item |
|
137
|
+
variant = item.variant
|
138
|
+
num += item.quantity
|
139
|
+
if as
|
140
|
+
variant.on_hand = item.quantity
|
141
|
+
else
|
142
|
+
variant.on_hand += item.quantity
|
143
|
+
end
|
144
|
+
variant.save!
|
145
|
+
end
|
146
|
+
@order.basket.items.clear
|
147
|
+
flash.notice = "Total of #{num} items #{as ? 'inventoried': 'added'} for #{prods} products "
|
148
|
+
render :edit
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
# check if the @basket is locked (no edits allowed)
|
154
|
+
# and if so redirect to show
|
155
|
+
def locked?
|
156
|
+
return false unless @basket.locked
|
157
|
+
redirect_to :action => :show , :notice => t('basket_locked')
|
158
|
+
return true
|
159
|
+
end
|
160
|
+
|
161
|
+
def item_discount item , discount
|
162
|
+
item.price = (item.product.price * ( 1.0 - discount.to_f/100.0 )).round(2)
|
163
|
+
item.save!
|
164
|
+
end
|
165
|
+
|
166
|
+
def load_basket
|
167
|
+
@basket = Basket.find(params[:id])
|
168
|
+
session[:basket] = nil # used to change links on product page, null when we come back
|
169
|
+
end
|
170
|
+
|
171
|
+
def params_for_basket
|
172
|
+
return if params[:basket].blank? or params[:basket].empty?
|
173
|
+
params.require(:basket).permit( :items_attributes => [:quantity , :price , :id] )
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
class CategoriesController < AdminController
|
3
|
+
|
4
|
+
before_filter :load_category, :only => [ :edit, :update, :destroy]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@q = Category.search(params[:q])
|
8
|
+
@category_scope = @q.result(:distinct => true)
|
9
|
+
@categories = @category_scope.includes(:products , :categories ).paginate( :page => params[:page],:per_page => 20).to_a
|
10
|
+
@roots = Category.where(:category_id => nil).includes(:products , :categories ).to_a
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
@category = Category.where(:id => params[:id]).includes(:products).first
|
15
|
+
end
|
16
|
+
|
17
|
+
def new
|
18
|
+
@category = Category.new
|
19
|
+
render :edit
|
20
|
+
end
|
21
|
+
|
22
|
+
def edit
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@category = Category.create(params_for_model)
|
28
|
+
if @category.save
|
29
|
+
redirect_to category_path(@category), :notice => t(:create_success, :model => "category")
|
30
|
+
else
|
31
|
+
render :edit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
online = @category.online
|
37
|
+
if @category.update_attributes(params_for_model)
|
38
|
+
notice = t(:update_success, :model => "category")
|
39
|
+
if @category.online != online
|
40
|
+
count = 0
|
41
|
+
@category.products.each do |prod|
|
42
|
+
prod.online = @category.online
|
43
|
+
prod.save
|
44
|
+
count += 1
|
45
|
+
end
|
46
|
+
notice += "<br> #{count} " + t(:products) + " " + (@category.online ? t(:made_online) : t(:made_offline))
|
47
|
+
end
|
48
|
+
redirect_to category_path(@category), :notice => notice
|
49
|
+
else
|
50
|
+
render :action => :edit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def destroy
|
55
|
+
@category.destroy if @category.categories.empty?
|
56
|
+
redirect_to categories_url
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def load_category
|
62
|
+
@category = Category.find(params[:id])
|
63
|
+
end
|
64
|
+
|
65
|
+
def params_for_model
|
66
|
+
params.require(:category).permit(:category_id,:name,:link,:main_picture,:extra_picture,:position, :online, :description)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
class ClerksController < AdminController
|
3
|
+
|
4
|
+
before_filter :load_clerk, :only => [:show, :edit, :update, :destroy]
|
5
|
+
|
6
|
+
# Uncomment for check abilities with CanCan
|
7
|
+
#authorize_resource
|
8
|
+
|
9
|
+
def index
|
10
|
+
@q = Clerk.search params[:q]
|
11
|
+
@clerk_scope = @q.result(:distinct => true)
|
12
|
+
@clerks = @clerk_scope.paginate( :page => params[:page],:per_page => 20).to_a
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
def new
|
19
|
+
@clerk = Clerk.new
|
20
|
+
render :edit
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@clerk = Clerk.create(params_for_model)
|
28
|
+
if @clerk.save
|
29
|
+
redirect_to clerk_path(@clerk), :notice => t(:create_success, :model => "clerk")
|
30
|
+
else
|
31
|
+
render :edit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
pars = params_for_model
|
37
|
+
if pars["password"].blank? and pars["password_confirmation"].blank?
|
38
|
+
pars.delete("password")
|
39
|
+
pars.delete("password_confirmation")
|
40
|
+
end
|
41
|
+
if @clerk.update_attributes(pars)
|
42
|
+
redirect_to clerk_path(@clerk), :notice => t(:update_success, :model => "clerk")
|
43
|
+
else
|
44
|
+
render :action => :edit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def destroy
|
49
|
+
#should the whole method go ? probably
|
50
|
+
#@clerk.destroy
|
51
|
+
redirect_to clerks_url
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def load_clerk
|
57
|
+
@clerk = Clerk.find(params[:id])
|
58
|
+
end
|
59
|
+
|
60
|
+
def params_for_model
|
61
|
+
params.require(:clerk).permit( :email,:name , :street , :city , :phone ,:password, :password_confirmation , :admin)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
class OrdersController < AdminController
|
3
|
+
|
4
|
+
before_filter :load_order, :only => [:show, :edit, :update ]
|
5
|
+
|
6
|
+
# Uncomment for check abilities with CanCan
|
7
|
+
#authorize_resource
|
8
|
+
|
9
|
+
def index
|
10
|
+
@q = Order.search(params[:q])
|
11
|
+
@order_scope = @q.result( :distinct => true)
|
12
|
+
@orders = @order_scope.includes(:basket => :items ).paginate(:page => params[:page],:per_page => 20)
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
def new
|
19
|
+
@order = Order.new
|
20
|
+
@order.build_basket
|
21
|
+
render :edit
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def create
|
29
|
+
@order = Order.create(params_for_model)
|
30
|
+
@order.build_basket() unless @order.basket
|
31
|
+
if @order.save
|
32
|
+
redirect_to order_path(@order), :notice => t(:create_success, :model => "order")
|
33
|
+
else
|
34
|
+
render :edit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def update
|
39
|
+
@order.build_basket unless @order.basket
|
40
|
+
if @order.update_attributes(params_for_model)
|
41
|
+
redirect_to order_path(@order), :notice => t(:update_success, :model => "order")
|
42
|
+
else
|
43
|
+
render :action => :edit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def load_order
|
50
|
+
@order = Order.find(params[:id])
|
51
|
+
end
|
52
|
+
|
53
|
+
def params_for_model
|
54
|
+
params.require(:order).permit(:ordered_on,:shipment_price,:shipment_tax,:basket_id,:email,:paid_on,:shipped_on,:paid_on,:canceled_on,:shipment_type)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
require 'barby'
|
3
|
+
require 'prawn'
|
4
|
+
require 'prawn/measurement_extensions'
|
5
|
+
require 'barby/barcode/code_128'
|
6
|
+
require 'barby/barcode/ean_13'
|
7
|
+
require 'barby/outputter/png_outputter'
|
8
|
+
|
9
|
+
class ProductsController < AdminController
|
10
|
+
|
11
|
+
before_filter :load_product, :only => [:show, :edit, :update, :delete , :barcode]
|
12
|
+
|
13
|
+
# Uncomment for check abilities with CanCan
|
14
|
+
#authorize_resource
|
15
|
+
|
16
|
+
def index
|
17
|
+
param = params[:q] || {}
|
18
|
+
param.merge!(:product_id_null => 1) unless( params[:basket])
|
19
|
+
@q = Product.search( param )
|
20
|
+
@product_scope = @q.result(:distinct => true)
|
21
|
+
@products = @product_scope.includes(:products , :supplier , :category).paginate( :page => params[:page], :per_page => 20 ).to_a
|
22
|
+
end
|
23
|
+
|
24
|
+
def show
|
25
|
+
end
|
26
|
+
|
27
|
+
def new
|
28
|
+
if params[:parent_id]
|
29
|
+
parent = Product.find params[:parent_id]
|
30
|
+
@product = parent.new_line_item
|
31
|
+
else
|
32
|
+
@product = Product.new :tax => OfficeClerk.config("defaults.tax")
|
33
|
+
end
|
34
|
+
render :edit
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit
|
38
|
+
end
|
39
|
+
|
40
|
+
def create
|
41
|
+
flash.notice = ""
|
42
|
+
@product = Product.create(params_for_model)
|
43
|
+
#TODO maybe there is a better way, but this "validation" happens "after the fact", ie by adding
|
44
|
+
# an item to a parent the parent can become "invalid" even it is not what is being edited. hmmm
|
45
|
+
if @product.line_item? and not @product.product.ean.blank?
|
46
|
+
flash.notice += t(:product_line_has_ean)
|
47
|
+
flash.notice += "<br/>"
|
48
|
+
end
|
49
|
+
if @product.line_item? and not @product.product.scode.blank?
|
50
|
+
flash.notice += t(:product_line_has_scode)
|
51
|
+
flash.notice += "<br/>"
|
52
|
+
end
|
53
|
+
if @product.save
|
54
|
+
flash.notice += t(:create_success, :model => "product")
|
55
|
+
redirect_to product_path(@product)
|
56
|
+
else
|
57
|
+
render :action => :edit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def update
|
62
|
+
flash.notice = ""
|
63
|
+
if ok = @product.update_attributes(params_for_model)
|
64
|
+
flash.notice += t(:update_success, :model => "product")
|
65
|
+
flash.notice += "<br/>"
|
66
|
+
end
|
67
|
+
if (@product.line_item? and not @product.link.blank?)
|
68
|
+
flash.notice += t(:product_item_has_link)
|
69
|
+
flash.notice += "<br/>"
|
70
|
+
ok = false
|
71
|
+
end
|
72
|
+
if (@product.line_item? and @product.product.ean) or (@product.line? and not @product.ean.blank?)
|
73
|
+
flash.notice += t(:product_line_has_ean)
|
74
|
+
flash.notice += "<br/>"
|
75
|
+
ok = false
|
76
|
+
end
|
77
|
+
if (@product.line_item? and @product.product.scode) or (@product.line? and not @product.scode.blank?)
|
78
|
+
flash.notice += t(:product_line_has_scode)
|
79
|
+
ok = false
|
80
|
+
end
|
81
|
+
if ok
|
82
|
+
redirect_to product_path(@product)
|
83
|
+
else
|
84
|
+
render :action => :edit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def delete
|
89
|
+
@product.delete
|
90
|
+
if @product.save
|
91
|
+
redirect_to products_url , :notice => t("deleted")
|
92
|
+
else
|
93
|
+
redirect_to products_url , :notice => t("error")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# loads of ways to create barcodes nowadays, this is a bit older.
|
98
|
+
# Used to be html but moved to pdf for better layout control
|
99
|
+
def barcode
|
100
|
+
pdf = Prawn::Document.new( :page_size => [ 54.mm , 25.mm ] , :margin => 2.mm )
|
101
|
+
pdf.text( @product.full_name , :align => :left )
|
102
|
+
pdf.text( "#{@product.price} € " , :align => :right , :padding => 5.mm)
|
103
|
+
code = @product.ean.blank? || ""
|
104
|
+
if code.length == 12
|
105
|
+
aBarcode = ::Barby::EAN13.new( code )
|
106
|
+
else
|
107
|
+
aBarcode = ::Barby::Code128B.new( code )
|
108
|
+
end
|
109
|
+
pdf.image( StringIO.new( aBarcode.to_png(:xdim => 5)) , :width => 50.mm ,
|
110
|
+
:height => 10.mm , :at => [ 0 , 10.mm])
|
111
|
+
send_data pdf.render , :type => "application/pdf" , :filename => "#{@product.full_name}.pdf"
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def load_product
|
117
|
+
@product = Product.find(params[:id])
|
118
|
+
end
|
119
|
+
|
120
|
+
def params_for_model
|
121
|
+
params.require(:product).permit(:price,:cost,:weight,:name,:description, :online,
|
122
|
+
:link,:ean,:tax,:properties,:scode,:product_id,:category_id,:supplier_id, :main_picture,:extra_picture
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|