Module: EducodeSales::SaleTrendsCountHelper
- Included in:
- SaleTrendsController, SubjectTrendsController
- Defined in:
- app/helpers/educode_sales/sale_trends_count_helper.rb
Constant Summary collapse
- NAMES =
%w[计划投标额 计划投标额累计 实际中标额 实际中标额累计]
Instance Method Summary collapse
- #goal_forecast_month_count(labels, selects, staff_id = nil, property) ⇒ Object
- #goal_forecast_quarter_count(labels, selects, staff_id = nil, property) ⇒ Object
- #goal_forecast_week_count(labels, selects, staff_id = nil, property) ⇒ Object
- #goal_forecast_year_count(labels, selects, staff_id = nil, property) ⇒ Object
Instance Method Details
#goal_forecast_month_count(labels, selects, staff_id = nil, property) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/helpers/educode_sales/sale_trends_count_helper.rb', line 137 def goal_forecast_month_count(labels, selects, staff_id = nil, property) plan_get_count = plan_get_count(staff_id, labels, "month", property) actual_get_count = actual_get_count(staff_id, labels, "month", property) datasets = selects.map.with_index do |select, i| data = if select == NAMES[0] labels.map do |d| month = d.split("-").last.to_i year = d.split("-").first.to_i plan_get_count[[year, month]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end elsif select == NAMES[1] arr = labels.map do |d| month = d.split("-").last.to_i year = d.split("-").first.to_i plan_get_count[[year, month]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } elsif select == NAMES[2] labels.map do |d| month = d.split("-").last.to_i year = d.split("-").first.to_i actual_get_count[[year, month]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end elsif select == NAMES[3] arr = labels.map do |d| month = d.split("-").last.to_i year = d.split("-").first.to_i actual_get_count[[year, month]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } end type = if select == NAMES[3] || select == NAMES[1] 'line' else "bar" end backgroundColor = if select == NAMES[3] || select == NAMES[1] 'rgba(54, 162, 235, 0.2)' else SaleTrend::COLORS[i] end { type: type, label: select, data: data.map { |d| d.round(2) }, backgroundColor: backgroundColor, borderColor: SaleTrend::COLORS[i], borderWidth: 1 } end hash_a = { labels: labels, datasets: [datasets[0], datasets[2]] } hash_b = { labels: labels, datasets: [datasets[1], datasets[3]] } [hash_a, hash_b] end |
#goal_forecast_quarter_count(labels, selects, staff_id = nil, property) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/educode_sales/sale_trends_count_helper.rb', line 5 def goal_forecast_quarter_count(labels, selects, staff_id = nil, property) plan_get_count = plan_get_count(staff_id, labels, "quarter", property) actual_get_count = actual_get_count(staff_id, labels, "quarter", property) datasets = selects.map.with_index do |select, i| data = if select == NAMES[0] labels.map do |d| quarter = d.split("-").last.to_i year = d.split("-").first.to_i plan_get_count[[year, quarter]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end elsif select == NAMES[1] arr = labels.map do |d| quarter = d.split("-").last.to_i year = d.split("-").first.to_i plan_get_count[[year, quarter]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } elsif select == NAMES[2] labels.map do |d| quarter = d.split("-").last.to_i year = d.split("-").first.to_i actual_get_count[[year, quarter]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end elsif select == NAMES[3] arr = labels.map do |d| quarter = d.split("-").last.to_i year = d.split("-").first.to_i actual_get_count[[year, quarter]]&.pluck(:business_id)&.uniq&.reject(&:blank?)&.size.to_f.round(3) end arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } end type = if select == NAMES[3] || select == NAMES[1] 'line' else "bar" end backgroundColor = if select == NAMES[3] || select == NAMES[1] 'rgba(54, 162, 235, 0.2)' else SaleTrend::COLORS[i] end { type: type, label: select, data: data.map { |d| d.round(2) }, backgroundColor: backgroundColor, borderColor: SaleTrend::COLORS[i], borderWidth: 1 } end hash_a = { labels: labels, datasets: [datasets[0], datasets[2]] } hash_b = { labels: labels, datasets: [datasets[1], datasets[3]] } [hash_a, hash_b] end |
#goal_forecast_week_count(labels, selects, staff_id = nil, property) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/helpers/educode_sales/sale_trends_count_helper.rb', line 68 def goal_forecast_week_count(labels, selects, staff_id = nil, property) plan_get_count = plan_get_count(staff_id, labels, "week", property) actual_get_count = actual_get_count(staff_id, labels, "week", property) datasets = selects.map.with_index do |select, i| data = if select == NAMES[0] labels.map do |d| week = d.split("-").last year = d.split("-").first yearweek = "#{year}#{week}".to_i plan_get_count[yearweek].to_f.round(3) end elsif select == NAMES[1] arr = labels.map do |d| week = d.split("-").last year = d.split("-").first yearweek = "#{year}#{week}".to_i plan_get_count[yearweek].to_f.round(3) end arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } elsif select == NAMES[2] labels.map do |d| week = d.split("-").last year = d.split("-").first yearweek = "#{year}#{week}".to_i actual_get_count[yearweek].to_f.round(3) end elsif select == NAMES[3] arr = labels.map do |d| week = d.split("-").last year = d.split("-").first yearweek = "#{year}#{week}".to_i actual_get_count[yearweek].to_f.round(3) end arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } end type = if select == NAMES[0] || select == NAMES[2] 'bar' else "line" end backgroundColor = if select == NAMES[0] || select == NAMES[2] SaleTrend::COLORS[i] else 'rgba(54, 162, 235, 0.2)' end { type: type, label: select, data: data.map { |d| d.round(2) }, backgroundColor: backgroundColor, borderColor: SaleTrend::COLORS[i], borderWidth: 1 } end hash_a = { labels: labels, datasets: [datasets[0], datasets[2]] } hash_b = { labels: labels, datasets: [datasets[1], datasets[3]] } [hash_a, hash_b] end |
#goal_forecast_year_count(labels, selects, staff_id = nil, property) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'app/helpers/educode_sales/sale_trends_count_helper.rb', line 202 def goal_forecast_year_count(labels, selects, staff_id = nil, property) plan_get_count = plan_get_count(staff_id, labels, "year", property) actual_get_count = actual_get_count(staff_id, labels, "year", property) datasets = selects.map.with_index do |select, i| data = if select == NAMES[0] labels.map { |d| plan_get_count[d.to_i] || 0 } elsif select == NAMES[1] arr = labels.map { |d| plan_get_count[d.to_i] || 0 } arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } elsif select == NAMES[2] labels.map { |d| actual_get_count[d.to_i] || 0 } elsif select == NAMES[3] arr = labels.map { |d| actual_get_count[d.to_i] || 0 } arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) } end type = if select == NAMES[3] || select == NAMES[1] 'line' else "bar" end backgroundColor = if select == NAMES[3] || select == NAMES[1] 'rgba(54, 162, 235, 0.2)' else SaleTrend::COLORS[i] end { type: type, label: select, data: data.map { |d| d.round(2) }, backgroundColor: backgroundColor, borderColor: SaleTrend::COLORS[i], borderWidth: 1 } end hash_a = { labels: labels, datasets: [datasets[0], datasets[2]] } hash_b = { labels: labels, datasets: [datasets[1], datasets[3]] } [hash_a, hash_b] end |