rawbotz 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -5
- data/Gemfile +2 -0
- data/README.md +60 -6
- data/Rakefile +3 -2
- data/agpl-3.0.txt +661 -0
- data/exe/bcrypt_pw +10 -0
- data/exe/rawbotz_abort_orders +28 -0
- data/exe/rawbotz_process_order_queue +12 -8
- data/exe/rawbotz_stock_update +10 -1
- data/exe/rawbotz_update_local_products +11 -3
- data/exe/rawbotz_update_remote_products +27 -4
- data/lib/rawbotz.rb +13 -5
- data/lib/rawbotz/app.rb +36 -2
- data/lib/rawbotz/cli/order_result_table.rb +13 -0
- data/lib/rawbotz/helpers/format_helper.rb +14 -0
- data/lib/rawbotz/helpers/icon_helper.rb +108 -22
- data/lib/rawbotz/helpers/order_item_color_helper.rb +17 -0
- data/lib/rawbotz/helpers/resource_link_helper.rb +3 -0
- data/lib/rawbotz/mail_template.rb +42 -7
- data/lib/rawbotz/models/sales.rb +21 -0
- data/lib/rawbotz/models/stock.rb +25 -0
- data/lib/rawbotz/models/stock_product.rb +146 -0
- data/lib/rawbotz/models/stock_product_factory.rb +64 -0
- data/lib/rawbotz/processors/order_linker.rb +50 -0
- data/lib/rawbotz/{order_processor.rb → processors/order_processor.rb} +14 -3
- data/lib/rawbotz/processors/organic_product_deliveries_csv.rb +47 -0
- data/lib/rawbotz/{product_updater.rb → processors/product_updater.rb} +71 -6
- data/lib/rawbotz/processors/stock_processor.rb +67 -0
- data/lib/rawbotz/public/rawbotz.css +35 -1
- data/lib/rawbotz/public/rawbotz.js +0 -1
- data/lib/rawbotz/remote_shop.rb +3 -0
- data/lib/rawbotz/routes.rb +3 -0
- data/lib/rawbotz/routes/non_remote_orders.rb +129 -29
- data/lib/rawbotz/routes/orders.rb +55 -4
- data/lib/rawbotz/routes/orders/stock.rb +75 -0
- data/lib/rawbotz/routes/product_links.rb +1 -1
- data/lib/rawbotz/routes/products.rb +19 -22
- data/lib/rawbotz/routes/remote_shop.rb +1 -1
- data/lib/rawbotz/routes/stock.rb +58 -0
- data/lib/rawbotz/routes/suppliers.rb +9 -4
- data/lib/rawbotz/sales_data.rb +13 -0
- data/lib/rawbotz/version.rb +1 -1
- data/lib/rawbotz/views/_hide_unhide_button.haml +1 -1
- data/lib/rawbotz/views/_menu.haml +9 -0
- data/lib/rawbotz/views/index.haml +1 -1
- data/lib/rawbotz/views/layout.haml +0 -1
- data/lib/rawbotz/views/order/_head.haml +64 -19
- data/lib/rawbotz/views/order/_item_table.haml +19 -3
- data/lib/rawbotz/views/order/_order_actions.haml +26 -0
- data/lib/rawbotz/views/order/link_to_remote.haml +30 -0
- data/lib/rawbotz/views/order/non_remote.haml +120 -26
- data/lib/rawbotz/views/order/packlist.haml +62 -5
- data/lib/rawbotz/views/order/packlist.pdf.haml +35 -0
- data/lib/rawbotz/views/order/stock.haml +116 -0
- data/lib/rawbotz/views/order/view.haml +41 -21
- data/lib/rawbotz/views/orders/_order_table.haml +82 -0
- data/lib/rawbotz/views/orders/index.haml +41 -28
- data/lib/rawbotz/views/orders/menu.haml +2 -2
- data/lib/rawbotz/views/orders/non_remotes.haml +14 -3
- data/lib/rawbotz/views/pdf_layout.haml +44 -0
- data/lib/rawbotz/views/product/view.haml +64 -11
- data/lib/rawbotz/views/products/index.haml +1 -1
- data/lib/rawbotz/views/products/table.haml +5 -1
- data/lib/rawbotz/views/remote_cart/index.haml +10 -0
- data/lib/rawbotz/views/remote_order/view.haml +6 -4
- data/lib/rawbotz/views/remote_orders/index.haml +16 -13
- data/lib/rawbotz/views/stock/index.haml +119 -0
- data/lib/rawbotz/views/stock/menu.haml +20 -0
- data/lib/rawbotz/views/stock_product/_value_table_line.haml +22 -0
- data/lib/rawbotz/views/stock_product/value_table.haml +28 -0
- data/lib/rawbotz/views/stockexplorer/stockexplorer.haml +157 -0
- data/lib/rawbotz/views/supplier/orders/table.haml +26 -0
- data/lib/rawbotz/views/supplier/view.haml +56 -10
- data/rawbotz.gemspec +13 -9
- metadata +86 -17
- data/lib/rawbotz/views/order/new.haml +0 -22
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rawbotz/routes'
|
2
|
+
require 'pdfkit'
|
2
3
|
|
3
4
|
module Rawbotz::RawbotzApp::Routing::Orders
|
4
5
|
include RawgentoModels
|
@@ -6,19 +7,21 @@ module Rawbotz::RawbotzApp::Routing::Orders
|
|
6
7
|
def self.registered(app)
|
7
8
|
# app.get '/orders', &show_orders
|
8
9
|
show_orders = lambda do
|
9
|
-
@orders = Order.
|
10
|
+
@orders = Order.order(created_at: :desc).all
|
10
11
|
haml "orders/index".to_sym
|
11
12
|
end
|
12
13
|
|
13
14
|
# app.get '/order/new', &create_order
|
14
15
|
create_order = lambda do
|
15
|
-
if
|
16
|
+
if settings.supplier.orders.where(state: 'new').present?
|
16
17
|
add_flash :message, "Already one Order in progress"
|
17
|
-
@order =
|
18
|
+
@order = settings.supplier.orders.where(state: 'new').first
|
18
19
|
else
|
19
20
|
@order = Order.create(state: :new)
|
20
|
-
@order.supplier
|
21
|
+
@order.supplier = settings.supplier
|
22
|
+
@order.order_method = :magento
|
21
23
|
|
24
|
+
# There is hell a lot of products missing if with remote order
|
22
25
|
RawgentoDB::Query.understocked.each do |product_id, name, min_qty, stock|
|
23
26
|
local_product = LocalProduct.find_by(product_id: product_id)
|
24
27
|
if local_product.present? && local_product.supplier == settings.supplier
|
@@ -37,6 +40,12 @@ module Rawbotz::RawbotzApp::Routing::Orders
|
|
37
40
|
# app.get '/order/:id', &show_order
|
38
41
|
show_order = lambda do
|
39
42
|
@order = Order.find(params[:id])
|
43
|
+
@stock = {}
|
44
|
+
begin
|
45
|
+
RawgentoDB::Query.stock.each {|s| @stock[s.product_id] = s.qty}
|
46
|
+
rescue Exception => e
|
47
|
+
add_flash :error, "Cannot connect to MySQL database (#{e.message})"
|
48
|
+
end
|
40
49
|
haml 'order/view'.to_sym
|
41
50
|
end
|
42
51
|
|
@@ -48,6 +57,8 @@ module Rawbotz::RawbotzApp::Routing::Orders
|
|
48
57
|
OrderItem.find(k[5..-1]).update(num_wished: v.to_i)
|
49
58
|
end
|
50
59
|
end
|
60
|
+
@order.internal_comment = params[:internal_comment]
|
61
|
+
@order.save
|
51
62
|
if params['action'] == 'order'
|
52
63
|
@order.update(state: :queued)
|
53
64
|
add_flash :success, 'Order queued'
|
@@ -57,6 +68,12 @@ module Rawbotz::RawbotzApp::Routing::Orders
|
|
57
68
|
add_flash :success, 'Order marked deleted'
|
58
69
|
redirect '/orders'
|
59
70
|
else
|
71
|
+
@stock = {}
|
72
|
+
begin
|
73
|
+
RawgentoDB::Query.stock.each {|s| @stock[s.product_id] = s.qty}
|
74
|
+
rescue Exception => e
|
75
|
+
add_flash :error, "Cannot connect to MySQL database (#{e.message})"
|
76
|
+
end
|
60
77
|
haml "order/view".to_sym
|
61
78
|
end
|
62
79
|
end
|
@@ -64,13 +81,47 @@ module Rawbotz::RawbotzApp::Routing::Orders
|
|
64
81
|
# app.get '/order/:id/packlist', &show_order_packlist
|
65
82
|
show_order_packlist = lambda do
|
66
83
|
@order = Order.find(params[:id])
|
84
|
+
@orphans = []
|
85
|
+
@refunds = {}
|
86
|
+
if @order.supplier == settings.supplier && @order.remote_order_link.present?
|
87
|
+
order_linker = Rawbotz::OrderLinker.new @order
|
88
|
+
order_linker.link!
|
89
|
+
@orphans = order_linker.orphans
|
90
|
+
@refunds = order_linker.refunds
|
91
|
+
end
|
67
92
|
haml "order/packlist".to_sym
|
68
93
|
end
|
69
94
|
|
95
|
+
# app.get '/order/:id/packlist/pdf', &show_pdf_packlist
|
96
|
+
show_pdf_packlist = lambda do
|
97
|
+
attachment "packlist_order.pdf"
|
98
|
+
@order = Order.find(params[:id])
|
99
|
+
html = haml "order/packlist.pdf".to_sym, layout: :pdf_layout
|
100
|
+
PDFKit.configure do |config|
|
101
|
+
config.verbose = false
|
102
|
+
config.default_options[:quiet] = true
|
103
|
+
end
|
104
|
+
|
105
|
+
kit = PDFKit.new(html)
|
106
|
+
|
107
|
+
kit.stylesheets << File.join(settings.root, "public",
|
108
|
+
"pure-min.css")
|
109
|
+
kit.stylesheets << File.join(settings.root, "public",
|
110
|
+
"rawbotz.css")
|
111
|
+
# This would need more resources (base64 encoded woff?)
|
112
|
+
#kit.stylesheets << File.join(settings.root, "public",
|
113
|
+
# "font-awesome-4.5.0/css/font-awesome.min.css")
|
114
|
+
kit.stylesheets << File.join(settings.root, "public",
|
115
|
+
"jui/jquery-ui.min.css")
|
116
|
+
kit.to_pdf
|
117
|
+
end
|
118
|
+
|
119
|
+
# routes
|
70
120
|
app.get '/orders', &show_orders
|
71
121
|
app.get '/order/new', &create_order
|
72
122
|
app.get '/order/:id', &show_order
|
73
123
|
app.post '/order/:id', &act_on_order
|
74
124
|
app.get '/order/:id/packlist', &show_order_packlist
|
125
|
+
app.get '/order/:id/packlist/pdf', &show_pdf_packlist
|
75
126
|
end
|
76
127
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rawbotz/routes'
|
2
|
+
|
3
|
+
module Rawbotz::RawbotzApp::Routing::Orders::Stock
|
4
|
+
include RawgentoModels
|
5
|
+
|
6
|
+
def self.registered(app)
|
7
|
+
|
8
|
+
# app.get '/order/:id/stock', &show_stock_order
|
9
|
+
show_stock_order = lambda do
|
10
|
+
@order = Order.find(params[:id])
|
11
|
+
@refunds = {}
|
12
|
+
if @order.supplier == settings.supplier && @order.remote_order_link.blank?
|
13
|
+
add_flash :message, "You need to select a remote order"
|
14
|
+
redirect "/order/#{@order.id}/link_to_remote"
|
15
|
+
else
|
16
|
+
if @order.supplier == settings.supplier
|
17
|
+
order_linker = Rawbotz::OrderLinker.new @order
|
18
|
+
order_linker.link!
|
19
|
+
@orphans = order_linker.orphans
|
20
|
+
@refunds = order_linker.refunds
|
21
|
+
end
|
22
|
+
haml "order/stock".to_sym
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# app.post '/order/:id/stock', &stock_order
|
27
|
+
stock_order = lambda do
|
28
|
+
@order = Order.find(params[:id])
|
29
|
+
|
30
|
+
@order.remote_order_id = params[:remote_order_id]
|
31
|
+
@order.remote_order_link = params[:remote_order_link]
|
32
|
+
|
33
|
+
stock_processor = Rawbotz::StockProcessor.new @order, params
|
34
|
+
errors = stock_processor.process!
|
35
|
+
|
36
|
+
if errors.empty?
|
37
|
+
add_flash :success, "Stocked this order"
|
38
|
+
else
|
39
|
+
errors.each{|e| add_flash :error, e}
|
40
|
+
end
|
41
|
+
|
42
|
+
@refunds = {}
|
43
|
+
if @order.supplier == settings.supplier
|
44
|
+
order_linker = Rawbotz::OrderLinker.new @order
|
45
|
+
order_linker.link!
|
46
|
+
@orphans = order_linker.orphans
|
47
|
+
@refunds = order_linker.refunds
|
48
|
+
end
|
49
|
+
|
50
|
+
haml "order/stock".to_sym
|
51
|
+
end
|
52
|
+
|
53
|
+
# app.get '/order/:id/link_to_remote', &show_link_to_remote_order
|
54
|
+
show_link_to_remote_order = lambda do
|
55
|
+
@order = Order.find(params[:id])
|
56
|
+
@last_orders = Rawbotz.mech.last_orders
|
57
|
+
haml "order/link_to_remote".to_sym
|
58
|
+
end
|
59
|
+
|
60
|
+
# app.post '/order/:id/link_to_remote', &link_to_remote_order
|
61
|
+
link_to_remote_order = lambda do
|
62
|
+
@order = Order.find(params[:id])
|
63
|
+
@order.remote_order_id = params[:remote_order_id]
|
64
|
+
@order.remote_order_link = params[:remote_order_link]
|
65
|
+
@order.save
|
66
|
+
redirect "/order/#{@order.id}/stock"
|
67
|
+
end
|
68
|
+
|
69
|
+
# routes
|
70
|
+
app.get '/order/:id/stock', &show_stock_order
|
71
|
+
app.post '/order/:id/stock', &stock_order
|
72
|
+
app.get '/order/:id/link_to_remote', &show_link_to_remote_order
|
73
|
+
app.post '/order/:id/link_to_remote', &link_to_remote_order
|
74
|
+
end
|
75
|
+
end
|
@@ -22,7 +22,7 @@ module Rawbotz::RawbotzApp::Routing::ProductLinks
|
|
22
22
|
|
23
23
|
# app.get '/products/link_wizard/:idx', &show_link_wizard_id
|
24
24
|
show_link_wizard_id = lambda do
|
25
|
-
@unlinked_count = LocalProduct.unlinked.count
|
25
|
+
@unlinked_count = LocalProduct.supplied_by(settings.supplier).unlinked.count
|
26
26
|
@local_product = LocalProduct.supplied_by(settings.supplier).unlinked.at(params[:idx].to_i || 0)
|
27
27
|
haml "products/link_wizard".to_sym
|
28
28
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'rawbotz/routes'
|
2
2
|
|
3
3
|
module Rawbotz::RawbotzApp::Routing::Products
|
4
|
+
include Rawbotz
|
4
5
|
include RawgentoModels
|
5
6
|
|
6
7
|
def self.registered(app)
|
7
8
|
# app.get '/products', &show_products
|
8
9
|
show_products = lambda do
|
9
|
-
@products = LocalProduct
|
10
|
-
@suppliers = Supplier.all
|
10
|
+
@products = LocalProduct.includes(:supplier, :remote_product)
|
11
|
+
@suppliers = Supplier.includes(:local_products).order(:name).all
|
11
12
|
haml "products/index".to_sym
|
12
13
|
end
|
13
14
|
|
@@ -21,20 +22,17 @@ module Rawbotz::RawbotzApp::Routing::Products
|
|
21
22
|
# app.get '/product/:id', &show_product
|
22
23
|
show_product = lambda do
|
23
24
|
settings = RawgentoDB.settings(Rawbotz.conf_file_path)
|
24
|
-
@product = LocalProduct.unscoped.find(params[:id])
|
25
|
+
@product = LocalProduct.unscoped.includes(:supplier).find(params[:id])
|
25
26
|
begin
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
Date.today - (12 * 30),
|
33
|
-
settings).uniq
|
34
|
-
rescue
|
27
|
+
product_id = @product.product_id
|
28
|
+
@sales = Models::Sales.daily_since product_id
|
29
|
+
@sales_monthly = Models::Sales.monthly_since product_id
|
30
|
+
rescue Exception => e
|
31
|
+
STDERR.puts e.message
|
32
|
+
STDERR.puts e.backtrace
|
35
33
|
@sales = []
|
36
34
|
@sales_monthly = []
|
37
|
-
add_flash :error,
|
35
|
+
add_flash :error, "Cannot connect to MySQL database/ #{e.message}"
|
38
36
|
end
|
39
37
|
@plot_data = Rawbotz::Datapolate.create_data @sales, @product.stock_items.where(created_at: (Date.today - 30)..Date.today)
|
40
38
|
haml "product/view".to_sym
|
@@ -44,10 +42,7 @@ module Rawbotz::RawbotzApp::Routing::Products
|
|
44
42
|
show_product_stock_sales_plot = lambda do
|
45
43
|
@product = LocalProduct.unscoped.find(params[:id])
|
46
44
|
begin
|
47
|
-
@sales =
|
48
|
-
Date.today,
|
49
|
-
Date.today - 30,
|
50
|
-
RawgentoDB.settings(Rawbotz.conf_file_path))
|
45
|
+
@sales = Models::Sales.daily_since(@product.product_id)
|
51
46
|
rescue
|
52
47
|
@sales = []
|
53
48
|
add_flash :error, 'Cannot connect to MySQL database'
|
@@ -59,7 +54,7 @@ module Rawbotz::RawbotzApp::Routing::Products
|
|
59
54
|
# app.post '/product/:id/hide', &hide_product
|
60
55
|
hide_product = lambda do
|
61
56
|
@product = RawgentoModels::LocalProduct.find(params[:id])
|
62
|
-
@product.
|
57
|
+
@product.hidden = true
|
63
58
|
@product.save
|
64
59
|
|
65
60
|
add_flash :success, "Product '#{@product.name}' is now hidden"
|
@@ -69,7 +64,7 @@ module Rawbotz::RawbotzApp::Routing::Products
|
|
69
64
|
# app.post '/product/:id/unhide', &unhide_product
|
70
65
|
unhide_product = lambda do
|
71
66
|
@product = RawgentoModels::LocalProduct.unscoped.find(params[:id])
|
72
|
-
@product.
|
67
|
+
@product.hidden = false
|
73
68
|
@product.save
|
74
69
|
|
75
70
|
add_flash :success, "Product '#{@product.name}' is now not hidden anymore"
|
@@ -85,8 +80,10 @@ module Rawbotz::RawbotzApp::Routing::Products
|
|
85
80
|
# app.post '/remote_products/search', &search_remote_products
|
86
81
|
search_remote_products = lambda do
|
87
82
|
@products = RemoteProduct.supplied_by(settings.supplier)
|
88
|
-
.
|
89
|
-
@products.map
|
83
|
+
.ilike(params[:term]).limit(20).pluck(:name, :id)
|
84
|
+
@products.map do |p|
|
85
|
+
{name: p[0], product_id: p[1]}
|
86
|
+
end.to_json
|
90
87
|
end
|
91
88
|
|
92
89
|
# app.get '/remote_product/:id', &show_remote_product
|
@@ -104,6 +101,6 @@ module Rawbotz::RawbotzApp::Routing::Products
|
|
104
101
|
|
105
102
|
app.get '/remote_products', &show_remote_products
|
106
103
|
app.post '/remote_products/search', &search_remote_products
|
107
|
-
app.get '/remote_product/:id',
|
104
|
+
app.get '/remote_product/:id', &show_remote_product
|
108
105
|
end
|
109
106
|
end
|
@@ -24,7 +24,7 @@ module Rawbotz::RawbotzApp::Routing::RemoteShop
|
|
24
24
|
@remote_order_id = params[:id]
|
25
25
|
@remote_order_items = Rawbotz.mech.products_from_order params[:id]
|
26
26
|
@remote_products_qty = @remote_order_items.map do |remote_product|
|
27
|
-
[RemoteProduct.find_by(name: remote_product[0]) || OpenStruct.new(name: remote_product[0]), remote_product[2]]
|
27
|
+
[RemoteProduct.find_by(name: remote_product[0]) || OpenStruct.new(name: remote_product[0]), remote_product[2], remote_product[3]]
|
28
28
|
end
|
29
29
|
# TODO catch problem if one is missing ...
|
30
30
|
haml "remote_order/view".to_sym
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rawbotz/routes'
|
2
|
+
|
3
|
+
module Rawbotz::RawbotzApp::Routing::Stock
|
4
|
+
include RawgentoModels
|
5
|
+
|
6
|
+
def self.registered(app)
|
7
|
+
|
8
|
+
# app.get '/stock', &show_stock
|
9
|
+
show_stock = lambda do
|
10
|
+
@suppliers = Supplier.where.not(id: settings.supplier.id).order(:name).all
|
11
|
+
begin
|
12
|
+
@stock_products = Rawbotz::Models::StockProductFactory.create @suppliers
|
13
|
+
rescue Exception => e
|
14
|
+
@stock_products = []
|
15
|
+
add_flash :error, "Error: #{e.message}"
|
16
|
+
end
|
17
|
+
|
18
|
+
haml "stock/index".to_sym
|
19
|
+
end
|
20
|
+
|
21
|
+
# app.get '/stock/alerts', &show_stock_alerts
|
22
|
+
show_stock_alerts = lambda do
|
23
|
+
@suppliers = Supplier.where.not(id: settings.supplier.id).order(:name).all
|
24
|
+
begin
|
25
|
+
@stock_products = Rawbotz::Models::StockProductFactory.create @suppliers
|
26
|
+
rescue Exception => e
|
27
|
+
@stock_products = []
|
28
|
+
add_flash :error, "Error: #{e.message}"
|
29
|
+
end
|
30
|
+
|
31
|
+
mis_stocked_product_ids = RawgentoDB::Query.wrongly_not_in_stock
|
32
|
+
@wrongly_out_of_stocks = LocalProduct.where(product_id: mis_stocked_product_ids)
|
33
|
+
|
34
|
+
haml "stock/index".to_sym
|
35
|
+
end
|
36
|
+
|
37
|
+
# app.get '/stock/warnings', &show_stock_warnings
|
38
|
+
show_stock_warnings = lambda do
|
39
|
+
@suppliers = Supplier.where.not(id: settings.supplier.id).order(:name).all
|
40
|
+
begin
|
41
|
+
@stock_products = Rawbotz::Models::StockProductFactory.create @suppliers
|
42
|
+
rescue Exception => e
|
43
|
+
@stock_products = []
|
44
|
+
add_flash :error, "Error: #{e.message}"
|
45
|
+
end
|
46
|
+
|
47
|
+
@stock_products.delete_if {|s| s.expected_stock_lifetime > 10 }
|
48
|
+
|
49
|
+
haml "stock/index".to_sym
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# routes
|
54
|
+
app.get '/stock', &show_stock
|
55
|
+
app.get '/stock/alerts', &show_stock_alerts
|
56
|
+
app.get '/stock/warnings', &show_stock_warnings
|
57
|
+
end
|
58
|
+
end
|
@@ -6,7 +6,7 @@ module Rawbotz::RawbotzApp::Routing::Suppliers
|
|
6
6
|
def self.registered(app)
|
7
7
|
# app.get '/suppliers', &show_suppliers
|
8
8
|
show_suppliers = lambda do
|
9
|
-
@suppliers = Supplier.all
|
9
|
+
@suppliers = Supplier.order(:name).all
|
10
10
|
haml "suppliers/index".to_sym
|
11
11
|
end
|
12
12
|
|
@@ -19,16 +19,21 @@ module Rawbotz::RawbotzApp::Routing::Suppliers
|
|
19
19
|
# app.post '/supplier/:id', &update_supplier
|
20
20
|
update_supplier = lambda do
|
21
21
|
@supplier = Supplier.find(params[:id])
|
22
|
-
@supplier.email
|
23
|
-
@supplier.
|
22
|
+
@supplier.email = params[:email]
|
23
|
+
@supplier.order_info = params[:order_info]
|
24
|
+
@supplier.order_template = params[:order_template]
|
25
|
+
@supplier.delivery_time_days = params[:delivery_time_days]
|
26
|
+
@supplier.minimum_order_value = params[:minimum_order_value]
|
24
27
|
if @supplier.save
|
25
28
|
add_flash :success, "Supplier updated"
|
26
29
|
else
|
27
30
|
add_flash :error, "Supplier could not be saved"
|
28
31
|
end
|
29
|
-
|
32
|
+
# This should redirect to the correct tab!
|
33
|
+
redirect "/supplier/#{@supplier.id}#tab_order_settings".to_sym
|
30
34
|
end
|
31
35
|
|
36
|
+
# routes
|
32
37
|
app.get '/suppliers', &show_suppliers
|
33
38
|
app.get '/supplier/:id', &show_supplier
|
34
39
|
app.post '/supplier/:id', &update_supplier
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Rawbotz
|
2
|
+
module SalesData
|
3
|
+
def self.sales_since day, products
|
4
|
+
db = RawgentoDB::Query
|
5
|
+
monthly_sales = products.map{|p| [p.product_id,
|
6
|
+
db.sales_monthly_between(p.product_id,
|
7
|
+
Date.today,
|
8
|
+
day)]}.to_h
|
9
|
+
# This is NOT the average!
|
10
|
+
monthly_sales.each{|k,v| monthly_sales[k] = v.inject(0){|a,s| a + s[1].to_i}/v.length rescue 0}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/rawbotz/version.rb
CHANGED
@@ -13,6 +13,15 @@
|
|
13
13
|
%a.pure-menu-link(href="/products")
|
14
14
|
= products_icon
|
15
15
|
Products
|
16
|
+
%li.pure-menu-item
|
17
|
+
%a.pure-menu-link(href="/suppliers")
|
18
|
+
= supplier_icon
|
19
|
+
Suppliers
|
20
|
+
%li.pure-menu-item
|
21
|
+
%a.pure-menu-link(href="/stock")
|
22
|
+
= stock_icon
|
23
|
+
= sales_icon
|
24
|
+
Stock/Sales
|
16
25
|
%li.pure-menu-item
|
17
26
|
%a.pure-menu-link(href="/remote_cart")
|
18
27
|
%i(class="fa fa-cart-arrow-down")
|
@@ -8,7 +8,7 @@
|
|
8
8
|
%h3 Last 3 Orders
|
9
9
|
%table.pure-table-horizontal.pure-table
|
10
10
|
-# Order.where(state: [Order::STATES.new, Order::STATES.processing, Order::STATES.queued, Order::STATES.ordered]).order("updated_at DESC").first(3).each do |order|
|
11
|
-
- Order.where(state: ["new", "processing", "ordered"]).order("updated_at DESC").first(3).each do |order|
|
11
|
+
- Order.where(state: ["new", "processing", "ordered", "mailed"]).order("updated_at DESC").first(3).each do |order|
|
12
12
|
%tr
|
13
13
|
%td
|
14
14
|
%a(href="/order/#{order.id}")
|