Module: MailingsHelper

Defined in:
app/helpers/mailings_helper.rb

Overview

== Schema Information

Table name: mailings

id :integer not null, primary key
state :string(255)
description :text
date_completed :datetime
creator_id :integer
updater_id :integer
label_file_name :string(255)
label_content_type :string(255)
label_file_size :integer
cover_letter_file_name :string(255)
cover_letter_type :string(255)
cover_file_size :integer
created_at :datetime
updated_at :datetime
job_id :string(255)
catalog_id :integer

Instance Method Summary collapse

Instance Method Details

#mailing_activities_can_complete?(mailing = @mailing) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/helpers/mailings_helper.rb', line 48

def mailing_activities_can_complete?( mailing = @mailing )
  !mailing.complete? and !mailing.has_active_background_job? and !mailing.ready_to_complete?
end

#mailing_activity_commands(mail_activity = @mail_activity, options = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/helpers/mailings_helper.rb', line 81

def mailing_activity_commands( mail_activity = @mail_activity, options = {} )
  commands = []
  with_options( class: 'btn btn-outline-primary btn-block' ) do |defaults|
    unless options[:hide_show_link]
      show_link_title = fa_icon( 'chevron-right', text: mail_activity.complete? ? "View" : "Process" )
      commands << defaults.link_to( show_link_title,
                    mail_activity_path( mail_activity ),
                    class: 'btn btn-outline-primary btn-block block-ui-on-click' )
    end
    if mail_activity.ready_to_print_postage_label?
      commands << defaults.link_to( fa_icon('print', text: "Print Postage"),
                    upload_path( mail_activity.all_labels_pdf ),
                    target: '_print_postage' )
    end
    if mail_activity.can_complete_mail_activity?
      commands << defaults.link_to( fa_icon('check', text: "Complete", title: "Mark as completed"),
                    complete_mail_activity_path( mail_activity ),
                    data: { turbo_method: :put, turbo_confirm: "Are you sure you want to mark this mail activity as complete? You can't undo this!" } )
    end

    if mail_activity.can_manually_complete_mail_activity?
      commands << defaults.link_to( fa_icon('check', text: "Manually Complete", title: "Mark as manually complete"),
                    manually_complete_mail_activity_path( mail_activity ),
                    data: { turbo_method: :put, turbo_confirm: "Are you sure you want to mark this mail activity as manually complete? You can't undo this!"} )
    end
    if mail_activity.ok_to_delete?
      commands << defaults.link_to( fa_icon('trash', text: "Remove", title: "Remove Activity From Mailing"),
                    mail_activity_path( mail_activity ),
                    data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to remove this mail activity from the mailing?" } )
    end

  end
  commands
end

#mailing_activity_icon_for_state(state) ⇒ Object



52
53
54
# File 'app/helpers/mailings_helper.rb', line 52

def mailing_activity_icon_for_state( state )
  { open: 'circle', packaged: 'dropbox', postage_rated: 'envelope', postage_labeled: 'envelope', complete: 'check'}[state.to_sym]
end

#mailing_activity_postage_commands(mail_activity = @mail_activity) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/mailings_helper.rb', line 66

def mailing_activity_postage_commands( mail_activity = @mail_activity )
  opts = []
  with_options( class: 'btn btn-outline-primary block-ui-on-click' ) do |defaults|
    if mail_activity.ready_to_label?
      opts << blocking_submit_button(label: "Generate Postage Label(s)")
    elsif mail_activity.postage_labeled?
      opts << defaults.link_to( "Void Postage Label(s)", void_postal_labels_mail_activity_path( mail_activity ), data: { turbo_method: :put, turbo_confirm: "Are you sure you want to void the postage label(s)?" } )
    end
    if mail_activity.ready_to_rate?
		opts << defaults.link_to( mail_activity.postage_rated? ? "Refresh Postage Rates" : "Get Postage Rates", find_postal_rates_mail_activity_path(@mail_activity), data: { turbo_method: :put } )
    end
  end
  opts
end

#mailing_activity_postage_rate_for_select(mail_activity = @mail_activity) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'app/helpers/mailings_helper.rb', line 56

def mailing_activity_postage_rate_for_select(mail_activity = @mail_activity)
  mail_activity.postage_rates.map do |pr|
    composite_code = pr['service_code'] # e.g. "UPS::03" or legacy "Priority"
    service_name = pr['service_name'].presence || composite_code
    package_info = pr['hw_package_type'].present? ? " (#{pr['hw_package_type'].underscore.gsub('_', ' ')})" : ''
    label = "#{service_name}#{package_info}: #{number_to_currency(pr['total_charges'].to_f)}"
    [label, composite_code]
  end
end

#mailings_command_options(mailing = nil, link_options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/mailings_helper.rb', line 25

def mailings_command_options(mailing=nil, link_options={})
  mailing ||= @mailing
  opts = []
  with_options **link_options do |lo|
    if mailing.ready_to_complete?
      if mailing.mail_activities.any?(&:ready_to_print_labels?)
        opts << lo.link_to( fa_icon('print', text: 'Print Postage Labels'), print_all_postage_labels_mailing_path(mailing), data: { turbo_method: :put }, target: '_postage_labels' )
      end
    end
    opts << lo.link_to( fa_icon('table', text: "Download Mailing Manifest"), mailing_path(mailing, format: :csv) )
    if mailing_activities_can_complete?( mailing )
       opts << lo.link_to( fa_icon('check', text: "Mark All Mail Activities As Complete"), manually_complete_all_mail_activities_mailing_path( mailing ), data: { turbo_method: :put, turbo_confirm: "This will mark all the open mail activities as complete, you cannot UNDO, continue?"} )
    end
    if mailing.has_active_background_job?
      opts << lo.link_to( "Completion pending", job_path( mailing.job_id ) )
    end
    if mailing.ok_to_delete?
      opts << lo.link_to( fa_icon('trash', text: "Delete Mailing"), mailing_path( mailing ), data: { turbo_method: :delete, turbo_confirm: "Deleting this mailing will not delete the activities, continue?" } )
    end
  end
  opts
end