Module: Crm::Reports::GrossSalesReportHelper
- Defined in:
- app/helpers/crm/reports/gross_sales_report_helper.rb
Instance Method Summary collapse
- #acc_format(value) ⇒ Object
- #acc_ov_customers_link_to(num_customers, program_pricing_id, sales_rep_ids, style) ⇒ Object
- #accounting_record_link(year, month, company_id, account_id) ⇒ Object
- #bo_num_offices_customers_link_to(num_customers, program_pricing_id, number_of_offices, sales_rep_ids, style) ⇒ Object
- #bo_projects_customers_link_to(num_customers, program_pricing_id, projects, sales_rep_ids, style) ⇒ Object
- #business_units_link(year, month, company_id, account_id, bu_id) ⇒ Object
- #closed_activities_link_to(employee_id, ca_count, date, options = {}) ⇒ Object
- #commission_state(status) ⇒ Object
- #comparison_arrow(p1_value, p2_value) ⇒ Object
- #counter_span_current_month(number) ⇒ Object
- #counter_span_sr(number) ⇒ Object
- #counter_span_sr_yearly(number) ⇒ Object
- #customers_link_to(customers_ids, num_customers, style) ⇒ Object
- #growth_indicator(var_value) ⇒ Object
- #hash_to_form_params(hash) ⇒ Object
- #inbound_outbound_blank_boolean_collection_for_select(blank_name = 'All Directions') ⇒ Object
- #inbound_outbound_boolean_collection_for_select(blank: nil) ⇒ Object
- #invoiced_link_to(employee, company_id = [1], amount = nil, start_date = Date.current.beginning_of_month, end_date = Date.current.end_of_month, options = {}) ⇒ Object
- #open_activities_link_to(employee_id, oa_count, date, options = {}) ⇒ Object
- #opposite_growth(prev_value, cur_value) ⇒ Object
- #query_link(search_klass, name_key = nil, options = {}) ⇒ Object
- #reconciliation_link(year, month, company_id, account_id) ⇒ Object
- #sc_state(status) ⇒ Object
- #value_ptg(var_value) ⇒ Object
- #values_format(value, currency = "USD") ⇒ Object
- #values_format_with_not_decimals(value, currency = "USD") ⇒ Object
- #values_format_without_symbol(value) ⇒ Object
- #values_no_symbol(value) ⇒ Object
- #var_percentage(var_value) ⇒ Object
- #var_percentage_opposite(var_value) ⇒ Object
-
#variance_color_class(value) ⇒ Object
Returns a Bootstrap text color class based on the sign of a variance value.
Instance Method Details
#acc_format(value) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 129 def acc_format(value) return unless value if value.positive? value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse elsif value.negative? '(' + (value * -1).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse + ')' end end |
#acc_ov_customers_link_to(num_customers, program_pricing_id, sales_rep_ids, style) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 301 def acc_ov_customers_link_to(num_customers, program_pricing_id, sales_rep_ids, style) pp_ids = [1316, 2422, 2423, 2424, 2425, 582, 583] catalogs = Catalog.where("id in (1,2)").pluck(:id).sort.uniq = {} [:num_records] = num_customers [:style] = style [:query_params] = {} [:query_params][:catalog_id_in] = catalogs if program_pricing_id != 999998 [:query_params][:catalog_id_not_in] = catalogs if program_pricing_id == 999998 [:query_params][:tier2_program_pricing_id_in] = program_pricing_id if program_pricing_id <= 999997 [:query_params][:tier2_program_pricing_id_not_in] = pp_ids if program_pricing_id == 999999 [:query_params][:primary_sales_rep_id_includes] = sales_rep_ids if sales_rep_ids.any? link, counter = query_link(CustomerSearch, nil, ) link.html_safe end |
#accounting_record_link(year, month, company_id, account_id) ⇒ Object
226 227 228 229 230 231 232 233 234 235 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 226 def accounting_record_link(year, month, company_id, account_id) params = {} params[:command] = {} params[:command][:period1_gteq] = Date.new(year, month) params[:command][:period1_lteq] = Date.new(year, month).end_of_month params[:command][:company_ids] = [company_id] params[:command][:ledger_account_ids] = [account_id] params[:command][:from_report] = account_id <= 4999 ? 1 : 2 reports_accounting_records_path(params) end |
#bo_num_offices_customers_link_to(num_customers, program_pricing_id, number_of_offices, sales_rep_ids, style) ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 317 def bo_num_offices_customers_link_to(num_customers, program_pricing_id, number_of_offices, sales_rep_ids, style) pp_ids = [1316, 2422, 2423, 2424, 2425, 582, 583] catalogs = Catalog.where("id in (1,2)").pluck(:id).sort.uniq = {} [:num_records] = num_customers [:style] = style [:query_params] = {} [:query_params][:catalog_id_in] = catalogs if program_pricing_id != 999998 [:query_params][:catalog_id_not_in] = catalogs if program_pricing_id == 999998 [:query_params][:tier2_program_pricing_id_in] = program_pricing_id if program_pricing_id <= 999997 [:query_params][:tier2_program_pricing_id_not_in] = pp_ids if program_pricing_id == 999999 [:query_params][:number_of_offices] = number_of_offices [:query_params][:primary_sales_rep_id_includes] = sales_rep_ids if sales_rep_ids.any? link, counter = query_link(CustomerSearch, nil, ) link.html_safe end |
#bo_projects_customers_link_to(num_customers, program_pricing_id, projects, sales_rep_ids, style) ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 334 def bo_projects_customers_link_to(num_customers, program_pricing_id, projects, sales_rep_ids, style) pp_ids = [1316, 2422, 2423, 2424, 2425, 582, 583] catalogs = Catalog.where("id in (1,2)").pluck(:id).sort.uniq = {} [:num_records] = num_customers [:style] = style [:query_params] = {} [:query_params][:catalog_id_in] = catalogs if program_pricing_id != 999998 [:query_params][:catalog_id_not_in] = catalogs if program_pricing_id == 999998 [:query_params][:tier2_program_pricing_id_in] = program_pricing_id if program_pricing_id <= 999997 [:query_params][:tier2_program_pricing_id_not_in] = pp_ids if program_pricing_id == 999999 [:query_params][:projects_per_year] = projects [:query_params][:primary_sales_rep_id_includes] = sales_rep_ids if sales_rep_ids.any? link, counter = query_link(CustomerSearch, nil, ) link.html_safe end |
#business_units_link(year, month, company_id, account_id, bu_id) ⇒ Object
237 238 239 240 241 242 243 244 245 246 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 237 def business_units_link(year, month, company_id, account_id, bu_id) params = {} params[:command] = {} params[:command][:period1_gteq] = Date.new(year, month) params[:command][:period1_lteq] = Date.new(year, month).end_of_month params[:command][:company_ids] = [company_id] params[:command][:ledger_account_ids] = [account_id] params[:command][:business_units_ids] = [bu_id] reports_accounting_records_path(params) end |
#closed_activities_link_to(employee_id, ca_count, date, options = {}) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 214 def closed_activities_link_to(employee_id, ca_count, date, = {}) [:num_records] = ca_count [:query_params] = {} [:query_params][:completion_datetime_gteq_time] = date.beginning_of_day [:query_params][:completion_datetime_lteq_time] = date.end_of_day [:query_params][:closed_by_id_in] = [employee_id] [:query_params][:activity_type_id] = ['Any'] [:query_params][:activity_result_type_id] = ['AnyCompletion'] link, counter = query_template_link(ActivitySearch, nil, ) link.html_safe end |
#commission_state(status) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 151 def commission_state(status) if status == 'in_progress' content_tag(:span, 'IP', class: 'badge bg-success') elsif status == 'pending_payout' content_tag(:span, 'PP', class: 'badge bg-warning') elsif status == 'paid_out' content_tag(:span, 'PO', class: 'badge bg-danger') end end |
#comparison_arrow(p1_value, p2_value) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 31 def comparison_arrow(p1_value, p2_value) if p1_value > p2_value content_tag(:i, '', class: 'fa-solid fa-arrow-trend-up text-success') elsif p1_value < p2_value content_tag(:i, '', class: 'fa-solid fa-arrow-trend-down text-danger') else content_tag(:span, '-', class: 'text-muted') end end |
#counter_span_current_month(number) ⇒ Object
143 144 145 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 143 def counter_span_current_month(number) content_tag(:span, number, class: 'badge bg-danger') if number.positive? end |
#counter_span_sr(number) ⇒ Object
139 140 141 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 139 def counter_span_sr(number) content_tag(:span, number, class: 'badge bg-secondary') if number.positive? end |
#counter_span_sr_yearly(number) ⇒ Object
147 148 149 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 147 def counter_span_sr_yearly(number) content_tag(:span, number, class: 'badge bg-success') end |
#customers_link_to(customers_ids, num_customers, style) ⇒ Object
291 292 293 294 295 296 297 298 299 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 291 def customers_link_to(customers_ids, num_customers, style) = {} [:num_records] = num_customers [:style] = style [:query_params] = {} [:query_params][:id_in] = customers_ids link, counter = query_link(CustomerSearch, nil, ) link.html_safe end |
#growth_indicator(var_value) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 21 def growth_indicator(var_value) return unless var_value if var_value.positive? content_tag(:i, '', class: 'fa fa-arrow-up text-success') elsif var_value.negative? content_tag(:i, '', class: 'fa fa-arrow-down text-danger') end end |
#hash_to_form_params(hash) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 258 def hash_to_form_params(hash) cleaned_hash = hash.reject { |k, v| v.blank? } pairs = cleaned_hash.to_query.split(Rack::Utils::DEFAULT_SEP) flattened_hash_params = {} # This allows duplicate keys which is what we want for array input tags flattened_hash_params.compare_by_identity = pairs.map do |pair| key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) } next unless value.present? flattened_hash_params[key] = value end flattened_hash_params end |
#inbound_outbound_blank_boolean_collection_for_select(blank_name = 'All Directions') ⇒ Object
175 176 177 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 175 def inbound_outbound_blank_boolean_collection_for_select(blank_name = 'All Directions') inbound_outbound_boolean_collection_for_select(blank: blank_name) end |
#inbound_outbound_boolean_collection_for_select(blank: nil) ⇒ Object
169 170 171 172 173 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 169 def inbound_outbound_boolean_collection_for_select(blank: nil) r = [['Inbound', true], ['Outbound', false]] r.insert(0, [blank, '']) if blank r end |
#invoiced_link_to(employee, company_id = [1], amount = nil, start_date = Date.current.beginning_of_month, end_date = Date.current.end_of_month, options = {}) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 179 def invoiced_link_to(employee, company_id = [1], amount = nil, start_date = Date.current.beginning_of_month, end_date = Date.current.end_of_month, = {}) .reverse_merge!(show_zero: true) if amount.nil? [:aggregate_method] = :sum [:aggregate_column] = :revenue_consolidated else [:num_records] = amount end [:format] = :currency # options[:link_method] = :link [:query_params] = {} [:query_params][:company_id_in] = company_id [:query_params][:gl_date_gteq] = start_date [:query_params][:gl_date_lteq] = end_date [:query_params][:invoice_type_in] = [Invoice::SO] # if employee [:query_params][:report_grouping] = Customer::ReportGrouping.direct_sales_report_grouping [:query_params][:primary_sales_rep_id_includes] = employee if employee query_template_link(InvoiceSearch, nil, )[0] end |
#open_activities_link_to(employee_id, oa_count, date, options = {}) ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 204 def open_activities_link_to(employee_id, oa_count, date, = {}) [:num_records] = oa_count [:query_params] = {} [:query_params][:open_on_date] = date [:query_params][:assigned_resource_id] = [employee_id] [:query_params][:activity_type_id] = ['Any'] link, counter = query_template_link(ActivitySearch, nil, ) link.html_safe end |
#opposite_growth(prev_value, cur_value) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 67 def opposite_growth(prev_value, cur_value) return unless cur_value if cur_value > prev_value content_tag(:i, '', class: 'fa fa-arrow-up', style: 'color:darkred') elsif cur_value < prev_value content_tag(:i, '', class: 'fa fa-arrow-down', style: 'color:darkgreen') else content_tag(:i, '-', class: 'fa', style: 'color:darkyellow') end end |
#query_link(search_klass, name_key = nil, options = {}) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 271 def query_link(search_klass, name_key = nil, = {}) st = 'font-weight: bold; font-size: 12px;' if [:style] == 0 st = 'font-size: 12px;' if [:style] == 1 st = 'font-size: 16px;' if [:style] == 2 qt = search_klass.instantiate_query_template(name_key, ) link_names = [] num_records = [:num_records].to_f.round link_names << content_tag(:span, values_no_symbol(num_records)) [ ( searches_path, method: :post, params: hash_to_form_params(qt.to_params), class: 'btn-link btn p-0 m-0', style: st) { link_names.compact.join.html_safe }, num_records ] end |
#reconciliation_link(year, month, company_id, account_id) ⇒ Object
248 249 250 251 252 253 254 255 256 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 248 def reconciliation_link(year, month, company_id, account_id) params = {} params[:command] = {} params[:command][:years] = year params[:command][:months] = month params[:command][:company_ids] = [company_id] params[:command][:ledger_account_ids] = [account_id] reports_reconciliation_path(params) end |
#sc_state(status) ⇒ Object
161 162 163 164 165 166 167 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 161 def sc_state(status) if status == 'paid_out' content_tag(:span, status.titleize.downcase, class: 'badge bg-danger') else content_tag(:span, status.titleize.downcase, class: 'badge bg-warning') end end |
#value_ptg(var_value) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 79 def value_ptg(var_value) return unless var_value if var_value.positive? || var_value.negative? content_tag(:i, '') + " #{var_value} %" else content_tag(:i, '-') end end |
#values_format(value, currency = "USD") ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 89 def values_format(value, currency = "USD") return unless value if value.present? && (value.positive? || value.negative?) Money.from_amount(value, currency).format else content_tag(:span, '-') end end |
#values_format_with_not_decimals(value, currency = "USD") ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 99 def values_format_with_not_decimals(value, currency = "USD") return unless value if value.present? && (value.positive? || value.negative?) Money.from_amount(value, currency).format.slice(0...-3) else content_tag(:span, '-') end end |
#values_format_without_symbol(value) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 109 def values_format_without_symbol(value) return unless value if value.positive? || value.negative? value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse else content_tag(:span, '-') end end |
#values_no_symbol(value) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 119 def values_no_symbol(value) return unless value if value.positive? || value.negative? value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse else content_tag(:span, '-') end end |
#var_percentage(var_value) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 3 def var_percentage(var_value) return content_tag(:span, '-', class: 'text-muted') unless var_value if var_value.positive? content_tag(:span, class: 'text-success') do content_tag(:i, '', class: 'fa-solid fa-arrow-up me-1') + content_tag(:span, "#{var_value}%") end elsif var_value.negative? content_tag(:span, class: 'text-danger') do content_tag(:i, '', class: 'fa-solid fa-arrow-down me-1') + content_tag(:span, "#{var_value}%") end else content_tag(:span, '-', class: 'text-muted') end end |
#var_percentage_opposite(var_value) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 55 def var_percentage_opposite(var_value) return unless var_value if var_value.positive? content_tag(:i, '', class: 'fa fa-arrow-up', style: 'color:darkred') + " #{var_value} %" elsif var_value.negative? content_tag(:i, '', class: 'fa fa-arrow-down', style: 'color:darkgreen') + " #{var_value} %" else content_tag(:i, '-') end end |
#variance_color_class(value) ⇒ Object
Returns a Bootstrap text color class based on the sign of a variance value.
Positive values get text-success, negative get text-danger, zero gets nothing.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/crm/reports/gross_sales_report_helper.rb', line 43 def variance_color_class(value) return '' unless value if value.positive? 'text-success' elsif value.negative? 'text-danger' else '' end end |