caboose-cms 0.7.85 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/caboose/{admin_edit_order.js → admin_edit_invoice.js} +332 -189
- data/app/assets/javascripts/caboose/cart.js +15 -15
- data/app/assets/javascripts/caboose/cart_old.js +2 -2
- data/app/assets/javascripts/caboose/checkout/authnet_payment_method_controller.js +120 -0
- data/app/assets/javascripts/caboose/checkout/billing_address_controller.js +85 -0
- data/app/assets/javascripts/caboose/checkout/cart_controller.js +257 -0
- data/app/assets/javascripts/caboose/checkout/checkout_controller.js +258 -0
- data/app/assets/javascripts/caboose/checkout/gift_cards_controller.js +57 -0
- data/app/assets/javascripts/caboose/checkout/shipping_address_controller.js +86 -0
- data/app/assets/javascripts/caboose/checkout/shipping_method_controller.js +121 -0
- data/app/assets/javascripts/caboose/checkout/stripe_payment_method_controller.js +155 -0
- data/app/assets/javascripts/caboose/checkout_login_register.js +2 -2
- data/app/assets/javascripts/caboose/checkout_module.js +8 -8
- data/app/assets/javascripts/caboose/checkout_old.js +151 -0
- data/app/assets/javascripts/caboose/{checkout_payment.js → checkout_payment_authnet.js} +1 -1
- data/app/assets/javascripts/caboose/checkout_payment_stripe.js +212 -0
- data/app/assets/javascripts/caboose/checkout_shipping.js +1 -1
- data/app/assets/javascripts/caboose/jquery.payment.js +1 -0
- data/app/assets/javascripts/caboose/model/attribute.js +3 -2
- data/app/assets/javascripts/caboose/model/bound_control.js +56 -14
- data/app/assets/javascripts/caboose/model/bound_select.js +9 -11
- data/app/assets/javascripts/caboose/model/bound_select_simple.js +215 -0
- data/app/assets/javascripts/caboose/model/bound_text.js +7 -8
- data/app/assets/javascripts/caboose/{my_account_edit_order.js → my_account_edit_invoice.js} +55 -55
- data/app/assets/javascripts/caboose/united_states.js +65 -0
- data/app/assets/stylesheets/caboose/{my_account_edit_order.css.scss → my_account_edit_invoice.css.scss} +1 -1
- data/app/assets/templates/caboose/cart/line_items.jst.ejs +3 -3
- data/app/assets/templates/caboose/checkout/line_items.jst.ejs +7 -7
- data/app/controllers/caboose/ab_options_controller.rb +4 -4
- data/app/controllers/caboose/ab_variants_controller.rb +5 -5
- data/app/controllers/caboose/admin_controller.rb +0 -6
- data/app/controllers/caboose/application_controller.rb +16 -15
- data/app/controllers/caboose/billing_addresses_controller.rb +22 -22
- data/app/controllers/caboose/block_type_sources_controller.rb +8 -8
- data/app/controllers/caboose/block_types_controller.rb +2 -42
- data/app/controllers/caboose/blocks_controller.rb +26 -26
- data/app/controllers/caboose/calendars_controller.rb +5 -5
- data/app/controllers/caboose/cart_controller.rb +55 -36
- data/app/controllers/caboose/categories_controller.rb +78 -76
- data/app/controllers/caboose/checkout_controller.rb +313 -340
- data/app/controllers/caboose/checkout_controller_bak.rb +620 -0
- data/app/controllers/caboose/domains_controller.rb +5 -5
- data/app/controllers/caboose/event_groups_controller.rb +26 -4
- data/app/controllers/caboose/events_controller.rb +7 -6
- data/app/controllers/caboose/fonts_controller.rb +2 -2
- data/app/controllers/caboose/gift_cards_controller.rb +113 -139
- data/app/controllers/caboose/google_spreadsheets_controller.rb +1 -1
- data/app/controllers/caboose/{order_packages_controller.rb → invoice_packages_controller.rb} +49 -49
- data/app/controllers/caboose/{order_reports_controller.rb → invoice_reports_controller.rb} +11 -13
- data/app/controllers/caboose/invoice_transactions_controller.rb +35 -0
- data/app/controllers/caboose/invoices_controller.rb +328 -0
- data/app/controllers/caboose/line_items_controller.rb +35 -34
- data/app/controllers/caboose/login_controller.rb +7 -7
- data/app/controllers/caboose/login_logs_controller.rb +4 -4
- data/app/controllers/caboose/logout_controller.rb +3 -1
- data/app/controllers/caboose/media_categories_controller.rb +9 -9
- data/app/controllers/caboose/media_controller.rb +21 -46
- data/app/controllers/caboose/modal_controller.rb +4 -3
- data/app/controllers/caboose/modification_values_controller.rb +6 -6
- data/app/controllers/caboose/modifications_controller.rb +7 -6
- data/app/controllers/caboose/my_account_controller.rb +2 -2
- data/app/controllers/caboose/my_account_invoices_controller.rb +166 -0
- data/app/controllers/caboose/my_account_line_items_controller.rb +15 -13
- data/app/controllers/caboose/page_custom_fields_controller.rb +9 -8
- data/app/controllers/caboose/page_permissions_controller.rb +3 -3
- data/app/controllers/caboose/pages_controller.rb +132 -135
- data/app/controllers/caboose/permissions_controller.rb +8 -7
- data/app/controllers/caboose/post_categories_controller.rb +22 -7
- data/app/controllers/caboose/post_custom_fields_controller.rb +9 -8
- data/app/controllers/caboose/posts_controller.rb +35 -43
- data/app/controllers/caboose/product_images_controller.rb +5 -5
- data/app/controllers/caboose/products_controller.rb +53 -47
- data/app/controllers/caboose/redirects_controller.rb +7 -7
- data/app/controllers/caboose/register_controller.rb +2 -2
- data/app/controllers/caboose/retargeting_controller.rb +2 -61
- data/app/controllers/caboose/reviews_controller.rb +1 -0
- data/app/controllers/caboose/roles_controller.rb +10 -9
- data/app/controllers/caboose/settings_controller.rb +9 -7
- data/app/controllers/caboose/shipping_addresses_controller.rb +18 -18
- data/app/controllers/caboose/shipping_packages_controller.rb +24 -21
- data/app/controllers/caboose/sites_controller.rb +35 -25
- data/app/controllers/caboose/smtp_controller.rb +3 -3
- data/app/controllers/caboose/sns_controller.rb +6 -6
- data/app/controllers/caboose/social_controller.rb +5 -6
- data/app/controllers/caboose/stackable_groups_controller.rb +10 -8
- data/app/controllers/caboose/station_controller.rb +3 -3
- data/app/controllers/caboose/store_controller.rb +93 -87
- data/app/controllers/caboose/subscriptions_controller.rb +153 -0
- data/app/controllers/caboose/users_controller.rb +25 -22
- data/app/controllers/caboose/variants_controller.rb +72 -93
- data/app/controllers/caboose/vendors_controller.rb +35 -32
- data/app/mailers/caboose/{orders_mailer.rb → invoices_mailer.rb} +21 -21
- data/app/mailers/caboose/login_mailer.rb +3 -3
- data/app/models/caboose/authnet.rb +295 -195
- data/app/models/caboose/comment_routes.rb +68 -41
- data/app/models/caboose/core_plugin.rb +1 -1
- data/app/models/caboose/discount.rb +14 -3
- data/app/models/caboose/domain_constraint.rb +11 -3
- data/app/models/caboose/gift_card.rb +8 -8
- data/app/models/caboose/invoice.rb +706 -0
- data/app/models/caboose/invoice_discount.rb +10 -0
- data/app/models/caboose/invoice_package.rb +76 -0
- data/app/models/caboose/{order_package_calculator.rb → invoice_package_calculator.rb} +20 -20
- data/app/models/caboose/{order_pdf.rb → invoice_pdf.rb} +30 -30
- data/app/models/caboose/{order_reporter.rb → invoice_reporter.rb} +5 -5
- data/app/models/caboose/invoice_transaction.rb +169 -0
- data/app/models/caboose/line_item.rb +11 -8
- data/app/models/caboose/payment_processors/authorizenet.rb +15 -15
- data/app/models/caboose/payment_processors/base.rb +3 -3
- data/app/models/caboose/{pending_orders_pdf.rb → pending_invoices_pdf.rb} +31 -31
- data/app/models/caboose/product.rb +2 -4
- data/app/models/caboose/schema.rb +159 -111
- data/app/models/caboose/shipping_calculator.rb +41 -139
- data/app/models/caboose/smtp_config.rb +2 -1
- data/app/models/caboose/store_config.rb +7 -7
- data/app/models/caboose/subscription.rb +32 -0
- data/app/models/caboose/tax_calculator.rb +36 -36
- data/app/models/caboose/user.rb +6 -0
- data/app/models/caboose/user_subscription.rb +142 -0
- data/app/models/caboose/wish_list.rb +14 -0
- data/app/models/caboose/wish_list_line_item.rb +13 -0
- data/app/views/caboose/blocks/_products.html.erb +10 -13
- data/app/views/caboose/checkout/_address_form.html.erb +14 -14
- data/app/views/caboose/checkout/_billing_form.html.erb +3 -3
- data/app/views/caboose/checkout/_cart.html.erb +7 -7
- data/app/views/caboose/checkout/_cart_old.html.erb +9 -9
- data/app/views/caboose/checkout/_confirm.html.erb +9 -9
- data/app/views/caboose/checkout/_order_discount.html.erb +3 -3
- data/app/views/caboose/checkout/_shipping_address.html.erb +1 -1
- data/app/views/caboose/checkout/_shipping_method.html.erb +1 -1
- data/app/views/caboose/checkout/addresses.html.erb +10 -10
- data/app/views/caboose/checkout/authnet.html.erb +34 -0
- data/app/views/caboose/checkout/authnet_response_handler.html.erb +3 -0
- data/app/views/caboose/checkout/checkout.html.erb +100 -0
- data/app/views/caboose/checkout/confirm_without_payment.html.erb +6 -6
- data/app/views/caboose/checkout/discount.html.erb +1 -1
- data/app/views/caboose/checkout/index.html.erb +4 -4
- data/app/views/caboose/checkout/payment_authnet.html.erb +140 -0
- data/app/views/caboose/checkout/payment_stripe.html.erb +95 -0
- data/app/views/caboose/checkout/shipping.html.erb +4 -4
- data/app/views/caboose/checkout/thanks.html.erb +3 -3
- data/app/views/caboose/gift_cards/admin_edit.html.erb +19 -19
- data/app/views/caboose/gift_cards/admin_index.html.erb +9 -9
- data/app/views/caboose/{orders → invoices}/_admin_footer.html.erb +0 -0
- data/app/views/caboose/{orders → invoices}/_admin_header.html.erb +0 -0
- data/app/views/caboose/{orders/_quickbooks_order.html.erb → invoices/_quickbooks_invoice.html.erb} +0 -0
- data/app/views/caboose/{orders → invoices}/admin_city_report.html.erb +1 -1
- data/app/views/caboose/invoices/admin_delete_form.html.erb +18 -0
- data/app/views/caboose/{orders → invoices}/admin_edit.html.erb +14 -14
- data/app/views/caboose/{orders → invoices}/admin_index.html.erb +24 -24
- data/app/views/caboose/{orders → invoices}/admin_invalid_order.html.erb +2 -2
- data/app/views/caboose/{orders → invoices}/admin_new.html.erb +7 -7
- data/app/views/caboose/{orders → invoices}/admin_print.html.erb +15 -15
- data/app/views/caboose/{orders → invoices}/admin_summary_report.html.erb +4 -4
- data/app/views/caboose/{orders_mailer/customer_new_order.html.erb → invoices_mailer/customer_new_invoice.html.erb} +21 -21
- data/app/views/caboose/invoices_mailer/customer_payment_authorization.html.erb +5 -0
- data/app/views/caboose/{orders_mailer → invoices_mailer}/customer_status_updated.html.erb +22 -22
- data/app/views/caboose/{orders_mailer/fulfillment_new_order.html.erb → invoices_mailer/fulfillment_new_invoice.html.erb} +23 -23
- data/app/views/caboose/{orders_mailer/shipping_order_ready.html.erb → invoices_mailer/shipping_invoice_ready.html.erb} +0 -0
- data/app/views/caboose/{orders_mailer → invoices_mailer}/test_email.html.erb +0 -0
- data/app/views/caboose/line_items/admin_new.html.erb +1 -1
- data/app/views/caboose/login_mailer/forgot_password_email.html.erb +2 -3
- data/app/views/caboose/my_account/index.html.erb +1 -1
- data/app/views/caboose/{my_account_orders → my_account_invoices}/authnet_relay.html.erb +0 -0
- data/app/views/caboose/{my_account_orders → my_account_invoices}/authnet_response.html.erb +0 -0
- data/app/views/caboose/{my_account_orders → my_account_invoices}/edit.html.erb +9 -9
- data/app/views/caboose/my_account_invoices/index.html.erb +36 -0
- data/app/views/caboose/{my_account_orders → my_account_invoices}/payment_form.html.erb +10 -10
- data/app/views/caboose/post_categories/admin_index.html.erb +1 -1
- data/app/views/caboose/sites/admin_edit.html.erb +1 -1
- data/app/views/caboose/store/admin_edit_general.html.erb +5 -3
- data/app/views/caboose/store/admin_edit_packages.html.erb +6 -6
- data/app/views/caboose/store/admin_edit_shipping.html.erb +3 -3
- data/app/views/caboose/store/admin_edit_tax.html.erb +1 -1
- data/app/views/caboose/subscriptions/admin_edit.html.erb +82 -0
- data/app/views/caboose/subscriptions/admin_index.html.erb +45 -0
- data/config/routes.rb +1 -759
- data/config/routes_old.rb +759 -0
- data/lib/caboose/version.rb +1 -1
- data/lib/tasks/caboose.rake +41 -15
- metadata +101 -61
- data/app/controllers/caboose/my_account_orders_controller.rb +0 -165
- data/app/controllers/caboose/orders_controller.rb +0 -310
- data/app/models/caboose/order.rb +0 -479
- data/app/models/caboose/order_discount.rb +0 -10
- data/app/models/caboose/order_package.rb +0 -133
- data/app/models/caboose/order_transaction.rb +0 -41
- data/app/models/caboose/payment_processors/payscape.rb +0 -94
- data/app/views/caboose/checkout/payment.html.erb +0 -146
- data/app/views/caboose/my_account_orders/index.html.erb +0 -36
- data/app/views/caboose/orders/admin_delete_form.html.erb +0 -21
- data/app/views/caboose/orders_mailer/customer_payment_authorization.html.erb +0 -5
@@ -0,0 +1,76 @@
|
|
1
|
+
module Caboose
|
2
|
+
class InvoicePackage < ActiveRecord::Base
|
3
|
+
self.table_name = 'store_invoice_packages'
|
4
|
+
|
5
|
+
belongs_to :invoice
|
6
|
+
belongs_to :shipping_package
|
7
|
+
belongs_to :shipping_method
|
8
|
+
has_many :line_items
|
9
|
+
attr_accessible :id,
|
10
|
+
:invoice_id,
|
11
|
+
:shipping_method_id,
|
12
|
+
:shipping_package_id,
|
13
|
+
:status,
|
14
|
+
:tracking_number,
|
15
|
+
:total
|
16
|
+
|
17
|
+
STATUS_PENDING = 'Pending'
|
18
|
+
STATUS_SHIPPED = 'Shipped'
|
19
|
+
|
20
|
+
after_initialize :check_nil_fields
|
21
|
+
|
22
|
+
def check_nil_fields
|
23
|
+
self.total = 0.00 if self.total.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.custom_invoice_packages(store_config, invoice)
|
27
|
+
eval(store_config.custom_packages_function)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Calculates the shipping packages required for all the items in the invoice
|
31
|
+
def calculate_shipping_package
|
32
|
+
|
33
|
+
store_config = invoice.site.store_config
|
34
|
+
if !store_config.auto_calculate_packages
|
35
|
+
return self.custom_shipping_package(store_config, self)
|
36
|
+
end
|
37
|
+
|
38
|
+
variants = self.line_items.sort_by{ |li| li.quantity * (li.variant.volume ? li.variant.volume : 0.00) * -1 }.collect{ |li| li.variant.downloadable ? nil : li.variant }.reject{ |v| v.nil? }
|
39
|
+
ShippingPackage.where(:site_id => self.invoice.site_id).reorder(:flat_rate_price).all.each do |sp|
|
40
|
+
if sp.fits(variants)
|
41
|
+
self.shipping_package_id = sp.id
|
42
|
+
self.save
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
Caboose.log("Error: line item #{li.id} (#{li.variant.product.title}) does not fit into any package.")
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
def fits(line_item = nil)
|
51
|
+
variants = self.line_items.collect{ |li| li.variant }
|
52
|
+
variants << line_item.variant if line_item
|
53
|
+
return self.shipping_package.fits(variants)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Gets the activemerchant package based on the shipping package
|
57
|
+
def activemerchant_package
|
58
|
+
sc = self.invoice.site.store_config
|
59
|
+
|
60
|
+
weight = 0.0
|
61
|
+
self.line_items.each{ |li| weight = weight + (li.variant.weight * li.quantity) }
|
62
|
+
weight = weight * 0.035274 if sc.weight_unit == StoreConfig::WEIGHT_UNIT_METRIC # grams to ounces
|
63
|
+
|
64
|
+
sp = self.shipping_package
|
65
|
+
dimensions = [sp.outside_length, sp.outside_width, sp.outside_height]
|
66
|
+
if sc.length_unit == StoreConfig::LENGTH_UNIT_METRIC # cm to inches
|
67
|
+
dimensions[0] = dimensions[0] / 2.54
|
68
|
+
dimensions[1] = dimensions[0] / 2.54
|
69
|
+
dimensions[2] = dimensions[0] / 2.54
|
70
|
+
end
|
71
|
+
|
72
|
+
return ActiveShipping::Package.new(weight, dimensions, :units => :imperial, :container => :variable)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -2,42 +2,42 @@ require 'active_shipping'
|
|
2
2
|
#include ActiveMerchant::Shipping
|
3
3
|
|
4
4
|
module Caboose
|
5
|
-
class
|
5
|
+
class InvoicePackageCalculator
|
6
6
|
|
7
|
-
def self.
|
7
|
+
def self.custom_invoice_packages(store_config, invoice)
|
8
8
|
return eval(store_config.custom_packages_function)
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.invoice_packages(invoice)
|
12
12
|
return [] if Caboose::store_shipping.nil?
|
13
13
|
|
14
|
-
sc =
|
14
|
+
sc = invoice.site.store_config
|
15
15
|
if !sc.auto_calculate_packages
|
16
|
-
|
17
|
-
return
|
16
|
+
invoice_packages = self.custom_invoice_packages(sc, invoice)
|
17
|
+
return invoice_packages
|
18
18
|
end
|
19
19
|
|
20
|
-
# Remove any
|
21
|
-
LineItem.where(:
|
22
|
-
|
20
|
+
# Remove any invoice packages
|
21
|
+
LineItem.where(:invoice_id => invoice.id).update_all(:invoice_package_id => nil)
|
22
|
+
InvoicePackage.where(:invoice_id => invoice.id).destroy_all
|
23
23
|
|
24
24
|
# Calculate what shipping packages we'll need
|
25
|
-
|
25
|
+
InvoicePackage.create_for_invoice(invoice)
|
26
26
|
|
27
27
|
return all_rates
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.rate(
|
31
|
-
return nil if !
|
32
|
-
self.rates(
|
30
|
+
def self.rate(invoice)
|
31
|
+
return nil if !invoice.shipping_service_code
|
32
|
+
self.rates(invoice).each { |rate| return rate if rate[:service_code] == invoice.shipping_service_code }
|
33
33
|
return nil
|
34
34
|
end
|
35
35
|
|
36
|
-
# Calculates the packages required for all the items in the
|
37
|
-
#def self.
|
36
|
+
# Calculates the packages required for all the items in the invoice
|
37
|
+
#def self.packages_for_invoice(invoice)
|
38
38
|
#
|
39
|
-
# # Make sure all the items in the
|
40
|
-
#
|
39
|
+
# # Make sure all the items in the invoice have attributes set
|
40
|
+
# invoice.line_items.each do |li|
|
41
41
|
# v = li.variant
|
42
42
|
# Caboose.log("Error: variant #{v.id} has a zero weight") and return false if v.weight.nil? || v.weight == 0
|
43
43
|
# next if v.volume && v.volume > 0
|
@@ -48,9 +48,9 @@ module Caboose
|
|
48
48
|
# v.save
|
49
49
|
# end
|
50
50
|
#
|
51
|
-
# # Reorder the items in the
|
51
|
+
# # Reorder the items in the invoice by volume
|
52
52
|
# h = {}
|
53
|
-
#
|
53
|
+
# invoice.line_items.each do |li|
|
54
54
|
# (1..li.quantity).each do |i|
|
55
55
|
# v = li.variant
|
56
56
|
# h[v.volume] = v
|
@@ -58,7 +58,7 @@ module Caboose
|
|
58
58
|
# end
|
59
59
|
# variants = h.sort_by{ |k,v| k }.collect{ |x| x[1] }
|
60
60
|
#
|
61
|
-
# all_packages = ShippingPackage.
|
61
|
+
# all_packages = ShippingPackage.reinvoice(:price).all
|
62
62
|
# packages = []
|
63
63
|
#
|
64
64
|
# # Now go through each variant and fit it in a new or existing package
|
@@ -2,9 +2,9 @@ require 'prawn'
|
|
2
2
|
require 'prawn/table'
|
3
3
|
|
4
4
|
module Caboose
|
5
|
-
class
|
5
|
+
class InvoicePdf < Prawn::Document
|
6
6
|
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :invoice, :card_type, :card_number
|
8
8
|
|
9
9
|
def to_pdf
|
10
10
|
|
@@ -18,9 +18,9 @@ module Caboose
|
|
18
18
|
|
19
19
|
#image open("https://dmwwflw4i3miv.cloudfront.net/logo.png"), :position => :center
|
20
20
|
move_down 10
|
21
|
-
|
21
|
+
invoice_info
|
22
22
|
move_down 15
|
23
|
-
|
23
|
+
invoice_table
|
24
24
|
move_down 15
|
25
25
|
customer_info
|
26
26
|
move_down 15
|
@@ -39,8 +39,8 @@ module Caboose
|
|
39
39
|
|
40
40
|
def get_card_details
|
41
41
|
|
42
|
-
sc = self.
|
43
|
-
ot = self.
|
42
|
+
sc = self.invoice.site.store_config
|
43
|
+
ot = self.invoice.invoice_transactions.where(:transaction_type => InvoiceTransaction::TYPE_AUTHORIZE, :success => true).first
|
44
44
|
|
45
45
|
case sc.pp_name
|
46
46
|
when 'authorize.net'
|
@@ -62,14 +62,14 @@ module Caboose
|
|
62
62
|
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
65
|
+
def invoice_info
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
invoice_info = "Invoice Number: #{invoice.invoice_number}\n"
|
68
|
+
invoice_info << "Invoice Date: #{invoice.date_created.strftime('%d %b %Y %H:%M:%S %p')}\n"
|
69
|
+
invoice_info << "Status: #{invoice.status.capitalize}\n"
|
70
70
|
tbl = []
|
71
71
|
tbl << [
|
72
|
-
{ :content =>
|
72
|
+
{ :content => invoice_info }
|
73
73
|
]
|
74
74
|
move_down 4
|
75
75
|
table tbl, :position => 7, :width => 530
|
@@ -78,19 +78,19 @@ module Caboose
|
|
78
78
|
|
79
79
|
def customer_info
|
80
80
|
|
81
|
-
c =
|
81
|
+
c = invoice.customer
|
82
82
|
|
83
83
|
# #{self.card_type} ending in #{self.card_number
|
84
|
-
ba =
|
85
|
-
ba_address = "#{ba.address1}" + (ba.address2.blank? ? '' : "\n#{ba.address2}") + "\n#{ba.city}, #{ba.state} #{ba.zip}"
|
84
|
+
ba = invoice.billing_address
|
85
|
+
ba_address = ba ? "#{ba.address1}" + (ba.address2.blank? ? '' : "\n#{ba.address2}") + "\n#{ba.city}, #{ba.state} #{ba.zip}" : ''
|
86
86
|
billed_to = [
|
87
|
-
[{ :content => "Name" , :border_width => 0, :width => 55 },{ :content => "#{ba.first_name} #{ba.last_name}" , :border_width => 0, :width => 200 }],
|
88
|
-
[{ :content => "Address" , :border_width => 0, :width => 55 },{ :content => ba_address , :border_width => 0, :width => 200 }],
|
89
|
-
[{ :content => "Email" , :border_width => 0, :width => 55 },{ :content => "#{c.email}"
|
90
|
-
[{ :content => "Phone" , :border_width => 0, :width => 55 },{ :content => "#{self.formatted_phone(c.phone)}"
|
87
|
+
[{ :content => "Name" , :border_width => 0, :width => 55 },{ :content => ba ? "#{ba.first_name} #{ba.last_name}" : '' , :border_width => 0, :width => 200 }],
|
88
|
+
[{ :content => "Address" , :border_width => 0, :width => 55 },{ :content => ba ? ba_address : '' , :border_width => 0, :width => 200 }],
|
89
|
+
[{ :content => "Email" , :border_width => 0, :width => 55 },{ :content => "#{c.email}" , :border_width => 0, :width => 200 }],
|
90
|
+
[{ :content => "Phone" , :border_width => 0, :width => 55 },{ :content => "#{self.formatted_phone(c.phone)}" , :border_width => 0, :width => 200 }]
|
91
91
|
]
|
92
92
|
|
93
|
-
sa =
|
93
|
+
sa = invoice.shipping_address
|
94
94
|
sa_address = "#{sa.address1}" + (sa.address2.blank? ? '' : "\n#{sa.address2}") + "\n#{sa.city}, #{sa.state} #{sa.zip}"
|
95
95
|
shipped_to = [
|
96
96
|
[{ :content => "Name" , :border_width => 0, :width => 55 },{ :content => "#{sa.first_name} #{sa.last_name}" , :border_width => 0, :width => 200 }],
|
@@ -113,9 +113,9 @@ module Caboose
|
|
113
113
|
|
114
114
|
end
|
115
115
|
|
116
|
-
def
|
116
|
+
def invoice_table
|
117
117
|
|
118
|
-
hide_prices =
|
118
|
+
hide_prices = invoice.hide_prices_for_any_line_item?
|
119
119
|
|
120
120
|
tbl = []
|
121
121
|
tbl << [
|
@@ -129,9 +129,9 @@ module Caboose
|
|
129
129
|
tbl[0] << { :content => "Amount" , :align => :right , :valign => :bottom }
|
130
130
|
end
|
131
131
|
|
132
|
-
|
132
|
+
invoice.calculate
|
133
133
|
|
134
|
-
|
134
|
+
invoice.invoice_packages.all.each do |pk|
|
135
135
|
|
136
136
|
carrier = pk.shipping_method.carrier
|
137
137
|
service = pk.shipping_method.service_name
|
@@ -172,7 +172,7 @@ module Caboose
|
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
|
-
unassigned =
|
175
|
+
unassigned = invoice.line_items.where("invoice_package_id IS NULL OR invoice_package_id = ?",-1)
|
176
176
|
unassigned.each_with_index do |li, index|
|
177
177
|
options = ''
|
178
178
|
if li.variant.product.option1 && li.variant.option1 then options += li.variant.product.option1 + ": " + li.variant.option1 + "\n" end
|
@@ -208,11 +208,11 @@ module Caboose
|
|
208
208
|
tbl << arr
|
209
209
|
end
|
210
210
|
if !hide_prices
|
211
|
-
tbl << [{ :content => "Subtotal" , :colspan => 6, :align => :right }, { :content => "$" + sprintf("%.2f",
|
212
|
-
tbl << [{ :content => "Discount" , :colspan => 6, :align => :right }, { :content => "(-) $" + sprintf("%.2f",
|
213
|
-
tbl << [{ :content => "Shipping and Handling Charges" , :colspan => 6, :align => :right }, { :content => "(+) $" + sprintf("%.2f",
|
214
|
-
tbl << [{ :content => "Sales Tax" , :colspan => 6, :align => :right }, { :content => "(+) $" + sprintf("%.2f",
|
215
|
-
tbl << [{ :content => "Grand Total" , :colspan => 6, :align => :right, :font_style => :bold }, { :content => "$" + sprintf("%.2f",
|
211
|
+
tbl << [{ :content => "Subtotal" , :colspan => 6, :align => :right }, { :content => "$" + sprintf("%.2f", invoice.subtotal ) , :align => :right }]
|
212
|
+
tbl << [{ :content => "Discount" , :colspan => 6, :align => :right }, { :content => "(-) $" + sprintf("%.2f", invoice.discount ? invoice.discount : 0.0 ) , :align => :right }]
|
213
|
+
tbl << [{ :content => "Shipping and Handling Charges" , :colspan => 6, :align => :right }, { :content => "(+) $" + sprintf("%.2f", invoice.shipping_and_handling ) , :align => :right }]
|
214
|
+
tbl << [{ :content => "Sales Tax" , :colspan => 6, :align => :right }, { :content => "(+) $" + sprintf("%.2f", invoice.tax ? invoice.tax : 0.0 ) , :align => :right }]
|
215
|
+
tbl << [{ :content => "Grand Total" , :colspan => 6, :align => :right, :font_style => :bold }, { :content => "$" + sprintf("%.2f", invoice.total ) , :align => :right, :font_style => :bold }]
|
216
216
|
end
|
217
217
|
|
218
218
|
table tbl , :position => 7, :width => 530
|
@@ -229,7 +229,7 @@ module Caboose
|
|
229
229
|
|
230
230
|
def payment_info
|
231
231
|
|
232
|
-
trans =
|
232
|
+
trans = invoice.invoice_transactions.where(:transaction_type => InvoiceTransaction::TYPE_AUTHORIZE, :success => true).first
|
233
233
|
tbl = []
|
234
234
|
tbl2 = []
|
235
235
|
tbl3 = []
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Caboose
|
2
|
-
class
|
2
|
+
class InvoiceReporter
|
3
3
|
|
4
|
-
def
|
4
|
+
def InvoiceReporter.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
7
|
count(*),
|
@@ -13,7 +13,7 @@ module Caboose
|
|
13
13
|
sum(total),
|
14
14
|
sum(cost),
|
15
15
|
sum(profit)
|
16
|
-
from
|
16
|
+
from store_invoices
|
17
17
|
where site_id = ?
|
18
18
|
and (financial_status = ? or financial_status = ?)
|
19
19
|
and date_authorized >= ?
|
@@ -68,7 +68,7 @@ module Caboose
|
|
68
68
|
return days2
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
71
|
+
def InvoiceReporter.city_report(site_id, d1, d2)
|
72
72
|
q = ["select
|
73
73
|
count(*),
|
74
74
|
sum(O.subtotal),
|
@@ -79,7 +79,7 @@ module Caboose
|
|
79
79
|
sum(O.total),
|
80
80
|
SA.city,
|
81
81
|
SA.state
|
82
|
-
from
|
82
|
+
from store_invoices O
|
83
83
|
left join store_addresses SA on O.shipping_address_id = SA.id
|
84
84
|
where O.site_id = ?
|
85
85
|
and (O.financial_status = ? or O.financial_status = ?)
|
@@ -0,0 +1,169 @@
|
|
1
|
+
module Caboose
|
2
|
+
class InvoiceTransaction < ActiveRecord::Base
|
3
|
+
self.table_name = 'store_invoice_transactions'
|
4
|
+
self.primary_key = 'id'
|
5
|
+
|
6
|
+
belongs_to :invoice
|
7
|
+
belongs_to :parent, :class_name => 'Caboose::InvoiceTransaction', :foreign_key => :parent_id
|
8
|
+
attr_accessible :id,
|
9
|
+
:invoice_id,
|
10
|
+
:parent_id,
|
11
|
+
:transaction_id,
|
12
|
+
:transaction_type,
|
13
|
+
:amount,
|
14
|
+
:amount_refunded,
|
15
|
+
:auth_code,
|
16
|
+
:date_processed,
|
17
|
+
:response_code,
|
18
|
+
:success,
|
19
|
+
:captured,
|
20
|
+
:refunded
|
21
|
+
|
22
|
+
TYPE_AUTHORIZE = 'auth'
|
23
|
+
TYPE_CAPTURE = 'capture'
|
24
|
+
TYPE_AUTHCAP = 'authcap'
|
25
|
+
TYPE_VOID = 'void'
|
26
|
+
TYPE_REFUND = 'refund'
|
27
|
+
|
28
|
+
after_initialize :check_nil_fields
|
29
|
+
|
30
|
+
def children
|
31
|
+
InvoiceTransaction.where(:parent_id => self.id).all
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_nil_fields
|
35
|
+
self.amount = 0.00 if self.amount.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.type_from_authnet_status(status)
|
39
|
+
case status
|
40
|
+
when 'settledSuccessfully' then InvoiceTransaction::TYPE_CAPTURE
|
41
|
+
when 'voided' then InvoiceTransaction::TYPE_VOID
|
42
|
+
when 'declined' then InvoiceTransaction::TYPE_AUTHORIZE
|
43
|
+
when 'authorizedPendingCapture' then InvoiceTransaction::TYPE_AUTHORIZE
|
44
|
+
when 'refundSettledSuccessfully' then InvoiceTransaction::TYPE_REFUND
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Capture funds from a previously authorized transaction
|
49
|
+
def capture
|
50
|
+
|
51
|
+
return { :error => "This invoice doesn't seem to be authorized." } if !self.success
|
52
|
+
|
53
|
+
ct = InvoiceTransaction.where(:parent_id => self.id, :transaction_type => InvoiceTransaction::TYPE_CAPTURE, :success => true).first
|
54
|
+
return { :error => "Funds for this invoice have already been captured." } if ct
|
55
|
+
|
56
|
+
resp = Caboose::StdClass.new
|
57
|
+
sc = self.invoice.site.store_config
|
58
|
+
case sc.pp_name
|
59
|
+
|
60
|
+
when StoreConfig::PAYMENT_PROCESSOR_STRIPE
|
61
|
+
|
62
|
+
Stripe.api_key = sc.stripe_secret_key.strip
|
63
|
+
bt = nil
|
64
|
+
begin
|
65
|
+
c = Stripe::Charge.retrieve(self.transaction_id)
|
66
|
+
c = c.capture
|
67
|
+
bt = Stripe::BalanceTransaction.retrieve(c.balance_transaction)
|
68
|
+
rescue Exception => ex
|
69
|
+
resp.error = "Error during capture process\n#{ex.message}"
|
70
|
+
end
|
71
|
+
|
72
|
+
if resp.error.nil?
|
73
|
+
InvoiceTransaction.create(
|
74
|
+
:invoice_id => self.invoice_id,
|
75
|
+
:parent_id => self.id,
|
76
|
+
:transaction_id => bt.id,
|
77
|
+
:transaction_type => InvoiceTransaction::TYPE_CAPTURE,
|
78
|
+
:amount => bt.amount / 100.0,
|
79
|
+
:date_processed => DateTime.strptime(bt.created.to_s, '%s'),
|
80
|
+
:success => bt.status == 'succeeded' || bt.status == 'pending'
|
81
|
+
)
|
82
|
+
if bt.status == 'succeeded' || bt.status == 'pending'
|
83
|
+
self.captured = true
|
84
|
+
self.save
|
85
|
+
self.invoice.financial_status = Invoice::FINANCIAL_STATUS_CAPTURED
|
86
|
+
self.invoice.save
|
87
|
+
resp.success = true
|
88
|
+
else
|
89
|
+
resp.error = "Error capturing funds."
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
return resp
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
def refund(amount_to_refund = nil)
|
99
|
+
|
100
|
+
resp = StdClass.new
|
101
|
+
|
102
|
+
amount_available_to_refund = self.amount - (self.amount_refunded ? self.amount_refunded : 0.00)
|
103
|
+
amount_to_refund = amount_available_to_refund if amount_to_refund.nil?
|
104
|
+
|
105
|
+
if self.transaction_type != InvoiceTransaction::TYPE_AUTHORIZE && self.transaction_type != InvoiceTransaction::TYPE_AUTHCAP
|
106
|
+
resp.error = "You can only refund authorize transactions."
|
107
|
+
elsif amount_to_refund > amount_available_to_refund
|
108
|
+
resp.error = "The amount to refund exceeds the amount available to refund."
|
109
|
+
else
|
110
|
+
|
111
|
+
sc = self.invoice.site.store_config
|
112
|
+
case sc.pp_name
|
113
|
+
|
114
|
+
when StoreConfig::PAYMENT_PROCESSOR_STRIPE
|
115
|
+
|
116
|
+
Stripe.api_key = sc.stripe_secret_key.strip
|
117
|
+
bt = nil
|
118
|
+
begin
|
119
|
+
r = Stripe::Refund.create(:charge => self.transaction_id, :amount => (amount_to_refund * 100).to_i)
|
120
|
+
rescue Exception => ex
|
121
|
+
resp.error = "Error during refund process\n#{ex.message}"
|
122
|
+
end
|
123
|
+
|
124
|
+
if resp.error.nil?
|
125
|
+
it = InvoiceTransaction.create(
|
126
|
+
:invoice_id => self.invoice_id,
|
127
|
+
:parent_id => self.id,
|
128
|
+
:transaction_id => r.id,
|
129
|
+
:transaction_type => InvoiceTransaction::TYPE_REFUND,
|
130
|
+
:amount => r.amount / 100.0,
|
131
|
+
:date_processed => DateTime.strptime(r.created.to_s, '%s'),
|
132
|
+
:success => r.status == 'succeeded' || r.status == 'pending'
|
133
|
+
)
|
134
|
+
if it.success
|
135
|
+
self.amount_refunded = (self.amount_refunded ? self.amount_refunded : 0.00) + amount_to_refund
|
136
|
+
self.refunded = self.amount_refunded >= self.amount
|
137
|
+
self.save
|
138
|
+
if self.amount_refunded >= self.invoice.total
|
139
|
+
self.invoice.financial_status = Invoice::FINANCIAL_STATUS_REFUNDED
|
140
|
+
self.invoice.save
|
141
|
+
end
|
142
|
+
resp.success = true
|
143
|
+
else
|
144
|
+
resp.error = "Error refunding transaction."
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
return resp
|
151
|
+
end
|
152
|
+
|
153
|
+
def void
|
154
|
+
|
155
|
+
resp = StdClass.new
|
156
|
+
sc = self.invoice.site.store_config
|
157
|
+
case sc.pp_name
|
158
|
+
|
159
|
+
when StoreConfig::PAYMENT_PROCESSOR_STRIPE
|
160
|
+
return self.refund
|
161
|
+
|
162
|
+
end
|
163
|
+
return resp
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
|