caboose-cms 0.7.55 → 0.7.57

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f95a7d0fdab94f7ee1bb8c66944ea56b473d5507
4
- data.tar.gz: 658a745c061ea7742e6e631ff3f6483ba8ca3808
3
+ metadata.gz: 58a87dfdd169104d0678ba85f750809c5ab12e86
4
+ data.tar.gz: 09d6a88d924f0ee3ce3e953dc3e86187b770f7c1
5
5
  SHA512:
6
- metadata.gz: 3283af7c66a5b2cd687ed64b6d8ea32ecfc718d4ac2c0174b27b533731780fd31e8c74cdecd6c8860513a373139da15750c9575b09c548930289ce97a91c51e9
7
- data.tar.gz: cb3cf3faabf96f629ee86034d7b8d09662d7a310be2fc3c301fcf0685cce208232ad4950bce0049ba5b808e7542af3e12be2a66f74b827062d5e9b7d5f5aac77
6
+ metadata.gz: 245adebb5a83caf5a7671a3a3cae2d7c10b0651447b493679a8459c32568e2fe1e9bca51b6ce01d9ea8bc82a6ae12568e5ebbb5d5d43f783bd8dc02f722e55f3
7
+ data.tar.gz: 50d81237125c19672c000e71850ca3b3f8f725e54722440304c03c9b06e1fbbf720742ca7ce567556d30d93221c12ffad3489408717d16635339b33256b0a30b
@@ -137,6 +137,8 @@ module Caboose
137
137
  self.update_column(:gift_wrap , self.calculate_gift_wrap )
138
138
  self.update_column(:discount , self.calculate_discount )
139
139
  self.update_column(:total , self.calculate_total )
140
+ self.update_column(:cost , self.calculate_cost )
141
+ self.update_column(:profit , self.calculate_profit )
140
142
  end
141
143
 
142
144
  def calculate_subtotal
@@ -186,6 +188,22 @@ module Caboose
186
188
  return (self.subtotal + self.tax + self.shipping + self.handling + self.gift_wrap) - self.discount
187
189
  end
188
190
 
191
+ def calculate_cost
192
+ x = 0.0
193
+ invalid_cost = false
194
+ self.line_items.each do |li|
195
+ invalid_cost = true if li.variant.nil? || li.variant.cost.nil?
196
+ x = x + (li.variant.cost * li.quantity)
197
+ end
198
+ return 0.00 if invalid_cost
199
+ return x
200
+ end
201
+
202
+ def calculate_profit
203
+ return 0.00 if self.cost.nil?
204
+ return (self.total - (self.tax ? self.tax : 0.00) - (self.shipping ? self.shipping : 0.00) - (self.handling ? self.handling : 0.00) - (self.gift_wrap ? self.gift_wrap : 0.00)) - self.cost
205
+ end
206
+
189
207
  def shipping_and_handling
190
208
  (self.shipping ? self.shipping : 0.0) + (self.handling ? self.handling : 0.0)
191
209
  end
@@ -343,7 +361,7 @@ module Caboose
343
361
 
344
362
  end
345
363
  return resp
346
- end
364
+ end
347
365
 
348
366
  #def refund
349
367
  #
@@ -4,13 +4,15 @@ module Caboose
4
4
  def OrderReporter.summary_report(site_id, d1, d2)
5
5
  q = ["select
6
6
  concat(date_part('year', date_authorized), '-', date_part('month', date_authorized), '-', date_part('day', date_authorized)),
7
- count(*),
7
+ count(*),
8
8
  sum(subtotal),
9
9
  sum(tax),
10
10
  sum(shipping),
11
11
  sum(handling),
12
12
  sum(discount),
13
- sum(total)
13
+ sum(total),
14
+ sum(cost),
15
+ sum(profit)
14
16
  from store_orders
15
17
  where site_id = ?
16
18
  and (financial_status = ? or financial_status = ?)
@@ -32,7 +34,9 @@ module Caboose
32
34
  :shipping => row[4].to_f,
33
35
  :handling => row[5].to_f,
34
36
  :discount => row[6].to_f,
35
- :total => row[7].to_f
37
+ :total => row[7].to_f,
38
+ :cost => row[8].to_f,
39
+ :profit => row[9].to_f
36
40
  )
37
41
  end
38
42
  days.sort_by!{ |h| h.date }
@@ -49,7 +53,9 @@ module Caboose
49
53
  :shipping => 0.0,
50
54
  :handling => 0.0,
51
55
  :discount => 0.0,
52
- :total => 0.0
56
+ :total => 0.0,
57
+ :cost => 0.0,
58
+ :profit => 0.0
53
59
  )
54
60
  last_day = last_day + 1.day
55
61
  end
@@ -67,9 +67,9 @@ class Caboose::Schema < Caboose::Utilities::Schema
67
67
  :email ,
68
68
  :payment_id ,
69
69
  :gateway_id ,
70
- :date_authorized ,
71
- :date_captured ,
72
- :date_canceled ,
70
+ #:date_authorized ,
71
+ #:date_captured ,
72
+ #:date_canceled ,
73
73
  :shipping_carrier ,
74
74
  :shipping_service_code ,
75
75
  :shipping_service_name ,
@@ -409,6 +409,8 @@ class Caboose::Schema < Caboose::Utilities::Schema
409
409
  [ :custom_discount , :decimal , { :precision => 8, :scale => 2 }],
410
410
  [ :discount , :decimal , { :precision => 8, :scale => 2 }],
411
411
  [ :total , :decimal , { :precision => 8, :scale => 2 }],
412
+ [ :cost , :decimal , { :precision => 8, :scale => 2, :default => 0.00 }],
413
+ [ :profit , :decimal , { :precision => 8, :scale => 2, :default => 0.00 }],
412
414
  [ :customer_id , :integer ],
413
415
  [ :financial_status , :string ],
414
416
  [ :shipping_address_id , :integer ],
@@ -6,6 +6,8 @@ shipping = 0.0
6
6
  handling = 0.0
7
7
  discount = 0.0
8
8
  total = 0.0
9
+ cost = 0.0
10
+ profit = 0.0
9
11
  @rows.each do |row|
10
12
  count = count + row.count
11
13
  subtotal = subtotal + row.subtotal
@@ -14,6 +16,8 @@ total = 0.0
14
16
  handling = handling + row.handling
15
17
  discount = discount + row.discount
16
18
  total = total + row.total
19
+ cost = cost + row.cost
20
+ profit = profit + row.profit
17
21
  end
18
22
  day_count = @rows.count
19
23
  %>
@@ -30,13 +34,15 @@ day_count = @rows.count
30
34
 
31
35
  <table class='data'>
32
36
  <tr><th>&nbsp;</th><th>Total</th><th>Daily Average</th></tr>
33
- <tr><td>Count </td><td align='right'><%= count %></td><td align='right'><%= sprintf('%.1f', count.to_f / day_count) %></td></tr>
34
- <tr><td>Subtotal </td><td align='right'>$<%= sprintf('%.2f', subtotal ) %></td><td align='right'>$<%= sprintf('%.2f', subtotal / day_count) %></td></tr>
35
- <tr><td>Tax </td><td align='right'>$<%= sprintf('%.2f', tax ) %></td><td align='right'>$<%= sprintf('%.2f', tax / day_count) %></td></tr>
36
- <tr><td>Shipping </td><td align='right'>$<%= sprintf('%.2f', shipping ) %></td><td align='right'>$<%= sprintf('%.2f', shipping / day_count) %></td></tr>
37
- <tr><td>Handling </td><td align='right'>$<%= sprintf('%.2f', handling ) %></td><td align='right'>$<%= sprintf('%.2f', handling / day_count) %></td></tr>
38
- <tr><td>Discount </td><td align='right'>$<%= sprintf('%.2f', discount ) %></td><td align='right'>$<%= sprintf('%.2f', discount / day_count) %></td></tr>
39
- <tr><td>Total </td><td align='right'>$<%= sprintf('%.2f', total ) %></td><td align='right'>$<%= sprintf('%.2f', total / day_count) %></td></tr>
37
+ <tr><td>Count </td><td align='right'><%= count %></td><td align='right'><%= sprintf('%.1f', count.to_f / day_count) %></td></tr>
38
+ <tr><td>Subtotal </td><td align='right'>$<%= sprintf('%.2f', subtotal ) %></td><td align='right'>$<%= sprintf('%.2f', (subtotal > 0 && day_count > 0 ? (subtotal / day_count) : 0.00)) %></td></tr>
39
+ <tr><td>Tax </td><td align='right'>$<%= sprintf('%.2f', tax ) %></td><td align='right'>$<%= sprintf('%.2f', (tax > 0 && day_count > 0 ? (tax / day_count) : 0.00)) %></td></tr>
40
+ <tr><td>Shipping </td><td align='right'>$<%= sprintf('%.2f', shipping ) %></td><td align='right'>$<%= sprintf('%.2f', (shipping > 0 && day_count > 0 ? (shipping / day_count) : 0.00)) %></td></tr>
41
+ <tr><td>Handling </td><td align='right'>$<%= sprintf('%.2f', handling ) %></td><td align='right'>$<%= sprintf('%.2f', (handling > 0 && day_count > 0 ? (handling / day_count) : 0.00)) %></td></tr>
42
+ <tr><td>Discount </td><td align='right'>$<%= sprintf('%.2f', discount ) %></td><td align='right'>$<%= sprintf('%.2f', (discount > 0 && day_count > 0 ? (discount / day_count) : 0.00)) %></td></tr>
43
+ <tr><td>Total </td><td align='right'>$<%= sprintf('%.2f', total ) %></td><td align='right'>$<%= sprintf('%.2f', (total > 0 && day_count > 0 ? (total / day_count) : 0.00)) %></td></tr>
44
+ <tr><td>Cost of Goods </td><td align='right'>$<%= sprintf('%.2f', cost ) %></td><td align='right'>$<%= sprintf('%.2f', (cost > 0 && day_count > 0 ? (cost / day_count) : 0.00)) %></td></tr>
45
+ <tr><td>Profit </td><td align='right'>$<%= sprintf('%.2f', profit ) %></td><td align='right'>$<%= sprintf('%.2f', (profit > 0 && day_count > 0 ? (profit / day_count) : 0.00)) %></td></tr>
40
46
  </table><br />
41
47
 
42
48
  <div id='counts_chart'></div>
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.7.55'
2
+ VERSION = '0.7.57'
3
3
  end
@@ -13,6 +13,14 @@ namespace :caboose do
13
13
  puts Caboose::CommentRoutes.compare_routes
14
14
  end
15
15
 
16
+ desc "Calculate order profits"
17
+ task :calculate_order_profits => :environment do
18
+ Caboose::Order.where("status = ? or status = ? or status = ?", Caboose::Order::STATUS_PENDING, Caboose::Order::STATUS_READY_TO_SHIP, Caboose::Order::STATUS_SHIPPED).reorder(:id).all.each do |order|
19
+ order.update_column(:cost , order.calculate_cost )
20
+ order.update_column(:profit , order.calculate_profit )
21
+ end
22
+ end
23
+
16
24
  desc "Verify ELO and ELI roles exist for all sites"
17
25
  task :init_site_users_and_roles => :environment do
18
26
  Caboose::Site.all.each do |site|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.55
4
+ version: 0.7.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry