rawbotz 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 402f796c506cac2364cab880d48e8181c69cf8d0
4
- data.tar.gz: c2b42f12e6c8eea8f23e5e7037f53fb15136130c
3
+ metadata.gz: 788bb5000f74251dc1c2aadd371f6260ea4ff84f
4
+ data.tar.gz: bd7d6705020f6fedeccdda86e96d798fb6f7be98
5
5
  SHA512:
6
- metadata.gz: 453857bee3be25903bf77b984cf137b2e28ff59539478b9773ba077bcfaac4b3f08f15d68ae2fa2b5081a3b65cc9b54d3086cf030fe09afc659c76ce1e9d97e5
7
- data.tar.gz: 60662be5fae280a77f09ac2ee953cfb9d3b4a72bfe97864c437024077533d7c2f054d6bc58dc502eebea18a19bd79b3889280ab96ef318ff661774126a003541
6
+ metadata.gz: 35d61d51553864fe25bd25896e04372a9603578e111562e8dcb0447b7f3c10af8818862b970d946bfebf59904b18c1cf145859b062f3e63c5201e77fc2cc40d0
7
+ data.tar.gz: 2f9bebba8f40938e0433c3a94323a001ef2af91467698201f368b934d277ba929b51280734b61cf209a38822eabdee0db1cd89b1af124e5952d2b873a3f0369f
data/lib/rawbotz/app.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'sinatra/base'
2
+ require 'open-uri'
2
3
  require 'action_view' # Workaround https://github.com/haml/haml/issues/695
3
4
  require 'haml'
4
5
  require 'rawbotz/helpers/icon_helper'
@@ -0,0 +1,36 @@
1
+ module Rawbotz
2
+ class ChartMonthDataset
3
+ attr_accessor :date, :value, :length, :darkness
4
+ def initialize date, value, length, darkness
5
+ @date = date
6
+ @value = value
7
+ @length = length
8
+ @darkness = darkness
9
+ end
10
+
11
+ def to_s
12
+ monthname = Date::MONTHNAMES[@date.month]
13
+ <<-eos
14
+ {
15
+ label: "Sales #{monthname[0..2]} #{@date.year}",
16
+ fill: true,
17
+ lineTension: 0.2,
18
+ backgroundColor: "rgba(175,155,155,0)",
19
+ borderColor: "rgba(35,42,102,#{@darkness})",
20
+ borderCapStyle: 'round',
21
+ pointBorderColor: "rgba(0,0,0,#{@darkness})",
22
+ pointBackgroundColor: "#fff",
23
+ pointBorderWidth: 1,
24
+ pointHoverRadius: 8,
25
+ pointHoverBackgroundColor: "rgba(99,102,152,1)",
26
+ pointHoverBorderColor: "rgba(210,210,210,1)",
27
+ pointHoverBorderWidth: 2,
28
+ pointRadius: 2,
29
+ pointHitRadius: 10,
30
+ data : [#{([@value] * @length).join(',')}]
31
+ },
32
+ eos
33
+ #/*data : [#{plot_data.values.map{|v| v[:stock].to_i}.join(',')}]*/
34
+ end
35
+ end
36
+ end
@@ -22,7 +22,7 @@ module Rawbotz
22
22
  order_item_line.gsub!(/PRODUCTNAME/, oi[:local_product][:name].to_s)
23
23
  order_item_line
24
24
  end
25
- lines[lines.find_index(product_line)] = order_lines
25
+ lines[lines.find_index(product_line)] = order_lines if product_line
26
26
  lines.flatten.join("\n")
27
27
  end
28
28
  end
@@ -27,8 +27,13 @@ module Rawbotz::RawbotzApp::Routing::Products
27
27
  Date.today,
28
28
  Date.today - 30,
29
29
  settings)
30
+ @sales_monthly = RawgentoDB::Query.sales_monthly_between(@product.product_id,
31
+ Date.today,
32
+ Date.today - (12 * 30),
33
+ settings).uniq
30
34
  rescue
31
35
  @sales = []
36
+ @sales_monthly = []
32
37
  add_flash :error, 'Cannot connect to MySQL database'
33
38
  end
34
39
  @plot_data = Rawbotz::Datapolate.create_data @sales, @product.stock_items.where(created_at: (Date.today - 30)..Date.today)
@@ -1,3 +1,3 @@
1
1
  module Rawbotz
2
- VERSION = "0.1.3".freeze
2
+ VERSION = "0.1.4".freeze
3
3
  end
@@ -1,5 +1,9 @@
1
1
  .pure-menu.pure-menu-horizontal#menu
2
2
  %center
3
+ %ul.pure-menu-list
4
+ %li.pure-menu-item
5
+ %a.pure-menu-link(href="/")
6
+ r a w b o t z
3
7
  %ul.pure-menu-list
4
8
  %li.pure-menu-item
5
9
  %a.pure-menu-link(href="/orders")
@@ -2,14 +2,28 @@
2
2
 
3
3
  #main-threes.pure-g
4
4
  .pure-u-1-3.center
5
- %i.fa.fa-shopping-cart.huge-icon
5
+ %a(href="/orders")
6
+ %i.fa.fa-shopping-cart.huge-icon
6
7
  %br
7
- Order
8
+ %h3 Last 3 Orders
9
+ %table.pure-table-horizontal.pure-table
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
+ %tr
12
+ %td
13
+ %a(href="/order/#{order.id}")
14
+ = order.updated_at.strftime("%Y-%m-%d %H:%M")
15
+ %td
16
+ = supplier_link order.supplier
17
+ %td
18
+ = order.state
8
19
  .pure-u-1-3.center
9
- %i.fa.fa-cubes.huge-icon
20
+ %a(href="/products")
21
+ %i.fa.fa-cubes.huge-icon
10
22
  %br
11
- Products
23
+ %h3 Products
24
+ -# latest addition?
12
25
  .pure-u-1-3.center
13
- %i.fa.fa-truck.huge-icon
26
+ %a(href="/suppliers")
27
+ %i.fa.fa-truck.huge-icon
14
28
  %br
15
- Supplier
29
+ %h3 Suppliers
@@ -4,8 +4,13 @@
4
4
 
5
5
  #modal-plot.modal-plot
6
6
 
7
+ - if @mail_preview.to_s != ""
8
+ %h2 Mail preview
9
+ %pre~ @mail_preview
10
+ %a{:href => "mailto:#{@supplier.email}?Subject=Order&body=%s" % URI::escape(@mail_preview).gsub(/&/,'%26')} Open mail
11
+
7
12
  %center
8
- %form.pure-form(action="" method="post")
13
+ %form#non_remote_order.pure-form(action="" method="post")
9
14
  %input(name="supplier_id" type="hidden" value="#{@supplier.id}")
10
15
  %table.pure-table
11
16
  %thead
@@ -36,4 +41,32 @@
36
41
  %center
37
42
  %button.pure-button.pure-button-primary
38
43
  %i.fa.fa-envelope
39
- Send me the mail!
44
+ Send me the mail!
45
+ -#%button#ajax_mailto.pure-button.pure-button-secondary
46
+ -# %i.fa.fa-envelope
47
+ -# Open mail
48
+ -#:javascript
49
+ -# $("#ajax_mailto").click(function(e){
50
+ -# e.preventDefault();
51
+ -# var parameters = $('#non_remote_order').serialize();
52
+ -# //alert(parameters);
53
+ -# $.ajax({
54
+ -# url: "/order/non_remote/#{@supplier.id}/mailto",
55
+ -# data: parameters,
56
+ -# type: 'POST',
57
+ -# success: function(data){
58
+ -# if(data.indexOf('mailto') > -1){
59
+ -# window.location = data;
60
+ -# }
61
+ -# }
62
+ -# });
63
+ -# });
64
+
65
+ -#Edit supplier ...
66
+
67
+ %br
68
+ %h2 Mail template
69
+ %pre~ @supplier.order_template
70
+ %a.pure-button(href="/supplier/#{@supplier.id}")
71
+ Edit template
72
+ %br
@@ -3,6 +3,12 @@
3
3
  %div
4
4
  %canvas(id="canvas" height="450" width="800")
5
5
 
6
+ - month_datasets = []
7
+ - if markers ||= nil
8
+ - markers.sort_by{|m|m[0]}.last(4).each_with_index do |m,i|
9
+ - month_datasets << Rawbotz::ChartMonthDataset.new(m[0],
10
+ m[1], plot_data.length, (i + 1)/(4.0))
11
+
6
12
  - sales_value = ->(h) { h[:sales].to_i }
7
13
  :javascript
8
14
  //Chart.defaults.global.multiTooltipTemplate = "<%= datasetLabel %>: <%= value %>";
@@ -47,7 +53,9 @@
47
53
  pointHitRadius: 10,
48
54
  data : [#{plot_data.values.map{|v| v[:stock].nil? ? 'null' : v[:stock].to_i}.join(',')}]
49
55
  /*data : [#{plot_data.values.map{|v| v[:stock].to_i}.join(',')}]*/
50
- }
56
+ },
57
+ #{month_datasets.join("\n")}
58
+ // month-datasets #{@sales_monthly}, red green blue
51
59
  ]
52
60
  }
53
61
 
@@ -45,20 +45,33 @@
45
45
  .pure-u-1-1
46
46
  %h2 Stock and Sales Values (30 days)
47
47
  .pure-u-2-5
48
- %table.pure-table
48
+ %table.pure-table.pure-table-striped
49
49
  %thead
50
50
  %tr
51
- %th Date
52
- %th Qty in Stock
51
+ %th Month
53
52
  %th Qty Sold
53
+ %th Quarter
54
54
  %tbody
55
- - @plot_data.values.each do |s|
56
- %tr{:class => s[:stock].to_i <= 0 ? "empty-stock" : ""}
57
- %td= s[:label]
58
- %td= s[:stock]
59
- %td= s[:sales]
60
-
55
+ - @sales_monthly.each_slice(3) do |sales|
56
+ - sales.each do |s|
57
+ %tr
58
+ %td
59
+ = Date::MONTHNAMES[s[0].month]
60
+ = s[0].year
61
+ %td=s[1]
62
+ %td
63
+ %tr(style="background-color: rgb(132,122,102);")
64
+ %td(colspan="2")
65
+ = Date::MONTHNAMES[sales[0][0].month]
66
+ = sales[0][0].year
67
+ \-
68
+ = Date::MONTHNAMES[sales[-1][0].month]
69
+ = sales[-1][0].year
70
+ %td
71
+ -#= sales.inspect
72
+ = sales.inject(0) {|acc, s| acc + s[1].to_i }
73
+
61
74
  .pure-u-3-5
62
- = haml :"product/_stock_sales_plot", locals: {plot_data: @plot_data}
75
+ = haml :"product/_stock_sales_plot", locals: {plot_data: @plot_data, markers: @sales_monthly}
63
76
  -#%h2 Orders
64
77
  -#= product.order_items.order ... link
@@ -58,9 +58,9 @@
58
58
  %br
59
59
  %textarea#example_order_template(name="example_order_template" readonly rows="10" cols="80")
60
60
  :preserve
61
- SUBJECT=Order NAME
61
+ SUBJECT=Order SUPPLIERNAME
62
62
 
63
- Dear NAME,
63
+ Dear SUPPLIERNAME,
64
64
 
65
65
  We will order
66
66
 
@@ -75,7 +75,7 @@
75
75
  %dl
76
76
  %dt SUBJECT=
77
77
  %dd will be subject of the mail (and NOT included in mail itself)
78
- %dt NAME
78
+ %dt SUPPLIERNAME
79
79
  %dd will be replaced by this suppliers name
80
80
  %dt *
81
81
  %dd the line starting with a star will be iterated over with every product
data/lib/rawbotz.rb CHANGED
@@ -3,6 +3,7 @@ require "rawbotz/remote_shop"
3
3
  require "rawbotz/local_shop"
4
4
  require "rawbotz/order_processor"
5
5
  require "rawbotz/datapolate"
6
+ require "rawbotz/chart_month_dataset"
6
7
  require "rawbotz/product_updater"
7
8
  require "rawbotz/mail_template"
8
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rawbotz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Wolfsteller
@@ -185,6 +185,7 @@ files:
185
185
  - exe/rawbotz_update_remote_products
186
186
  - lib/rawbotz.rb
187
187
  - lib/rawbotz/app.rb
188
+ - lib/rawbotz/chart_month_dataset.rb
188
189
  - lib/rawbotz/cli/order_result_table.rb
189
190
  - lib/rawbotz/datapolate.rb
190
191
  - lib/rawbotz/helpers/flash_helper.rb