educode_sales 1.10.37 → 1.10.46
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/educode_sales/application_controller.rb +13 -0
- data/app/controllers/educode_sales/contracts_controller.rb +33 -3
- data/app/controllers/educode_sales/ideas_controller.rb +17 -7
- data/app/controllers/educode_sales/money_plan_records_controller.rb +14 -7
- data/app/controllers/educode_sales/money_plans_controller.rb +5 -1
- data/app/controllers/educode_sales/plans_controller.rb +14 -0
- data/app/controllers/educode_sales/sale_trends_controller.rb +82 -9
- data/app/controllers/educode_sales/teachers_controller.rb +7 -2
- data/app/helpers/educode_sales/sale_trends_helper.rb +410 -0
- data/app/views/educode_sales/businesses/index.html.erb +2 -2
- data/app/views/educode_sales/contracts/_list.html.erb +26 -2
- data/app/views/educode_sales/contracts/index.json.jbuilder +3 -1
- data/app/views/educode_sales/ideas/_index.html.erb +23 -2
- data/app/views/educode_sales/ideas/index.json.jbuilder +1 -1
- data/app/views/educode_sales/ideas/new.html.erb +11 -6
- data/app/views/educode_sales/money_plan_records/_index.html.erb +20 -7
- data/app/views/educode_sales/money_plan_records/index.json.jbuilder +3 -1
- data/app/views/educode_sales/money_plans/_index.html.erb +56 -42
- data/app/views/educode_sales/money_plans/index.json.jbuilder +3 -1
- data/app/views/educode_sales/plans/_target_track.html.erb +178 -0
- data/app/views/educode_sales/plans/index.html.erb +5 -0
- data/app/views/educode_sales/plans/target_track.js.erb +1 -0
- data/app/views/educode_sales/sale_trends/_return_money_forecast.html.erb +176 -0
- data/app/views/educode_sales/sale_trends/return_money_forecast.js.erb +1 -0
- data/app/views/educode_sales/sale_trends/trends.html.erb +6 -0
- data/app/views/educode_sales/teachers/_index.html.erb +21 -9
- data/config/routes.rb +2 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +10 -7
- data/app/assets/images/educode_sales/indexlogo.png +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
module EducodeSales
|
2
2
|
module SaleTrendsHelper
|
3
3
|
NAMES = %w[计划投标额 计划投标额累计 实际中标额 实际中标额累计]
|
4
|
+
RETURN_NAMES = %w[实际回款额 计划回款额 实际回款 计划回款额-全部 计划回款额-o类]
|
4
5
|
|
5
6
|
def goal_forecast_quarter(labels, selects, staff_id = nil, property)
|
6
7
|
plan_get = plan_get(staff_id, labels, "quarter", property)
|
@@ -337,6 +338,274 @@ module EducodeSales
|
|
337
338
|
end
|
338
339
|
end
|
339
340
|
|
341
|
+
|
342
|
+
def return_money_forecast_week(labels, selects, staff_id = nil, property)
|
343
|
+
plan_return = plan_return(staff_id, labels, "week", property)
|
344
|
+
actual_return = actual_return(staff_id, labels, "week", property)
|
345
|
+
plan_return_by_o = plan_return_by_o(staff_id, labels, "week", property)
|
346
|
+
datasets = selects.map.with_index do |select, i|
|
347
|
+
data = if select == RETURN_NAMES[0]
|
348
|
+
labels.map do |d|
|
349
|
+
week = d.split("-").last
|
350
|
+
year = d.split("-").first
|
351
|
+
yearweek = "#{year}#{week}".to_i
|
352
|
+
actual_return[yearweek].to_f.round(3)
|
353
|
+
end
|
354
|
+
elsif select == RETURN_NAMES[1]
|
355
|
+
arr = labels.map do |d|
|
356
|
+
week = d.split("-").last
|
357
|
+
year = d.split("-").first
|
358
|
+
yearweek = "#{year}#{week}".to_i
|
359
|
+
plan_return[yearweek].to_f.round(3)
|
360
|
+
end
|
361
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
362
|
+
elsif select == RETURN_NAMES[2]
|
363
|
+
labels.map do |d|
|
364
|
+
week = d.split("-").last
|
365
|
+
year = d.split("-").first
|
366
|
+
yearweek = "#{year}#{week}".to_i
|
367
|
+
actual_return[yearweek].to_f.round(3)
|
368
|
+
end
|
369
|
+
elsif select == RETURN_NAMES[3]
|
370
|
+
labels.map do |d|
|
371
|
+
week = d.split("-").last
|
372
|
+
year = d.split("-").first
|
373
|
+
yearweek = "#{year}#{week}".to_i
|
374
|
+
plan_return[yearweek].to_f.round(3)
|
375
|
+
end
|
376
|
+
elsif select == RETURN_NAMES[4]
|
377
|
+
arr = labels.map do |d|
|
378
|
+
week = d.split("-").last
|
379
|
+
year = d.split("-").first
|
380
|
+
yearweek = "#{year}#{week}".to_i
|
381
|
+
plan_return_by_o[yearweek].to_f.round(3)
|
382
|
+
end
|
383
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
384
|
+
end
|
385
|
+
type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
386
|
+
'bar'
|
387
|
+
else
|
388
|
+
"line"
|
389
|
+
end
|
390
|
+
backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
391
|
+
'rgba(54, 162, 235, 1)'
|
392
|
+
else
|
393
|
+
SaleTrend::COLORS[i]
|
394
|
+
'rgba(54, 162, 235, 0)'
|
395
|
+
end
|
396
|
+
{
|
397
|
+
type: type,
|
398
|
+
label: select,
|
399
|
+
data: data&.map { |d| d.round(2) },
|
400
|
+
backgroundColor: backgroundColor,
|
401
|
+
borderColor: SaleTrend::COLORS[i],
|
402
|
+
borderWidth: 1
|
403
|
+
}
|
404
|
+
end
|
405
|
+
|
406
|
+
hash_a = {
|
407
|
+
labels: labels,
|
408
|
+
datasets: [datasets[0], datasets[1]]
|
409
|
+
}
|
410
|
+
hash_b = {
|
411
|
+
labels: labels,
|
412
|
+
datasets: [datasets[2], datasets[3], datasets[4]]
|
413
|
+
}
|
414
|
+
[hash_a, hash_b]
|
415
|
+
end
|
416
|
+
|
417
|
+
def return_money_forecast_quarter(labels, selects, staff_id = nil, property)
|
418
|
+
plan_return = plan_return(staff_id, labels, "quarter", property)
|
419
|
+
actual_return = actual_return(staff_id, labels, "quarter", property)
|
420
|
+
plan_return_by_o = plan_return_by_o(staff_id, labels, "quarter", property)
|
421
|
+
datasets = selects.map.with_index do |select, i|
|
422
|
+
data = if select == RETURN_NAMES[0]
|
423
|
+
labels.map do |d|
|
424
|
+
quarter = d.split("-").last.to_i
|
425
|
+
year = d.split("-").first.to_i
|
426
|
+
actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
|
427
|
+
end
|
428
|
+
elsif select == RETURN_NAMES[1]
|
429
|
+
arr = labels.map do |d|
|
430
|
+
quarter = d.split("-").last.to_i
|
431
|
+
year = d.split("-").first.to_i
|
432
|
+
plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
|
433
|
+
end
|
434
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
435
|
+
elsif select == RETURN_NAMES[2]
|
436
|
+
labels.map do |d|
|
437
|
+
quarter = d.split("-").last.to_i
|
438
|
+
year = d.split("-").first.to_i
|
439
|
+
actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
|
440
|
+
end
|
441
|
+
elsif select == RETURN_NAMES[3]
|
442
|
+
labels.map do |d|
|
443
|
+
quarter = d.split("-").last.to_i
|
444
|
+
year = d.split("-").first.to_i
|
445
|
+
plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
|
446
|
+
end
|
447
|
+
elsif select == RETURN_NAMES[4]
|
448
|
+
arr = labels.map do |d|
|
449
|
+
quarter = d.split("-").last.to_i
|
450
|
+
year = d.split("-").first.to_i
|
451
|
+
plan_return_by_o[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
|
452
|
+
end
|
453
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
454
|
+
end
|
455
|
+
type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
456
|
+
'bar'
|
457
|
+
else
|
458
|
+
"line"
|
459
|
+
end
|
460
|
+
backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
461
|
+
'rgba(54, 162, 235, 1)'
|
462
|
+
else
|
463
|
+
SaleTrend::COLORS[i]
|
464
|
+
'rgba(54, 162, 235, 0)'
|
465
|
+
end
|
466
|
+
{
|
467
|
+
type: type,
|
468
|
+
label: select,
|
469
|
+
data: data.map { |d| d.round(2) },
|
470
|
+
backgroundColor: backgroundColor,
|
471
|
+
borderColor: SaleTrend::COLORS[i],
|
472
|
+
borderWidth: 1
|
473
|
+
}
|
474
|
+
end
|
475
|
+
|
476
|
+
hash_a = {
|
477
|
+
labels: labels,
|
478
|
+
datasets: [datasets[0], datasets[1]]
|
479
|
+
}
|
480
|
+
hash_b = {
|
481
|
+
labels: labels,
|
482
|
+
datasets: [datasets[2], datasets[3], datasets[4]]
|
483
|
+
}
|
484
|
+
[hash_a, hash_b]
|
485
|
+
end
|
486
|
+
|
487
|
+
|
488
|
+
def return_money_forecast_month(labels, selects, staff_id = nil, property)
|
489
|
+
plan_return = plan_return(staff_id, labels, "month", property)
|
490
|
+
actual_return = actual_return(staff_id, labels, "month", property)
|
491
|
+
plan_return_by_o = plan_return_by_o(staff_id, labels, "month", property)
|
492
|
+
datasets = selects.map.with_index do |select, i|
|
493
|
+
data = if select == RETURN_NAMES[0]
|
494
|
+
labels.map do |d|
|
495
|
+
quarter = d.split("-").last.to_i
|
496
|
+
year = d.split("-").first.to_i
|
497
|
+
actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
|
498
|
+
end
|
499
|
+
elsif select == RETURN_NAMES[1]
|
500
|
+
arr = labels.map do |d|
|
501
|
+
quarter = d.split("-").last.to_i
|
502
|
+
year = d.split("-").first.to_i
|
503
|
+
plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
|
504
|
+
end
|
505
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
506
|
+
elsif select == RETURN_NAMES[2]
|
507
|
+
labels.map do |d|
|
508
|
+
quarter = d.split("-").last.to_i
|
509
|
+
year = d.split("-").first.to_i
|
510
|
+
actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
|
511
|
+
end
|
512
|
+
elsif select == RETURN_NAMES[3]
|
513
|
+
labels.map do |d|
|
514
|
+
quarter = d.split("-").last.to_i
|
515
|
+
year = d.split("-").first.to_i
|
516
|
+
plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
|
517
|
+
end
|
518
|
+
elsif select == RETURN_NAMES[4]
|
519
|
+
arr = labels.map do |d|
|
520
|
+
quarter = d.split("-").last.to_i
|
521
|
+
year = d.split("-").first.to_i
|
522
|
+
plan_return_by_o[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
|
523
|
+
end
|
524
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
525
|
+
end
|
526
|
+
type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
527
|
+
'bar'
|
528
|
+
else
|
529
|
+
"line"
|
530
|
+
end
|
531
|
+
backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
532
|
+
'rgba(54, 162, 235, 1)'
|
533
|
+
else
|
534
|
+
SaleTrend::COLORS[i]
|
535
|
+
'rgba(54, 162, 235, 0)'
|
536
|
+
end
|
537
|
+
{
|
538
|
+
type: type,
|
539
|
+
label: select,
|
540
|
+
data: data.map { |d| d.round(2) },
|
541
|
+
backgroundColor: backgroundColor,
|
542
|
+
borderColor: SaleTrend::COLORS[i],
|
543
|
+
borderWidth: 1
|
544
|
+
}
|
545
|
+
end
|
546
|
+
|
547
|
+
hash_a = {
|
548
|
+
labels: labels,
|
549
|
+
datasets: [datasets[0], datasets[1]]
|
550
|
+
}
|
551
|
+
hash_b = {
|
552
|
+
labels: labels,
|
553
|
+
datasets: [datasets[2], datasets[3], datasets[4]]
|
554
|
+
}
|
555
|
+
[hash_a, hash_b]
|
556
|
+
end
|
557
|
+
|
558
|
+
def return_money_forecast_year(labels, selects, staff_id = nil, property)
|
559
|
+
plan_return = plan_return(staff_id, labels, "year", property)
|
560
|
+
actual_return = actual_return(staff_id, labels, "year", property)
|
561
|
+
plan_return_by_o = plan_return_by_o(staff_id, labels, "year", property)
|
562
|
+
datasets = selects.map.with_index do |select, i|
|
563
|
+
data = if select == RETURN_NAMES[0]
|
564
|
+
labels.map { |d| actual_return[d.to_i] || 0 }
|
565
|
+
elsif select == RETURN_NAMES[1]
|
566
|
+
arr = labels.map { |d| plan_return[d.to_i] || 0 }
|
567
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
568
|
+
elsif select == RETURN_NAMES[2]
|
569
|
+
labels.map { |d| actual_return[d.to_i] || 0 }
|
570
|
+
elsif select == RETURN_NAMES[3]
|
571
|
+
labels.map { |d| plan_return[d.to_i] || 0 }
|
572
|
+
elsif select == RETURN_NAMES[4]
|
573
|
+
arr = labels.map { |d| plan_return_by_o[d.to_i] || 0 }
|
574
|
+
arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
|
575
|
+
end
|
576
|
+
|
577
|
+
type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
578
|
+
'bar'
|
579
|
+
else
|
580
|
+
"line"
|
581
|
+
end
|
582
|
+
backgroundColor = if RETURN_NAMES[0] || select == RETURN_NAMES[1]
|
583
|
+
'rgba(54, 162, 235, 1)'
|
584
|
+
else
|
585
|
+
SaleTrend::COLORS[i]
|
586
|
+
'rgba(54, 162, 235, 0)'
|
587
|
+
end
|
588
|
+
{
|
589
|
+
type: type,
|
590
|
+
label: select,
|
591
|
+
data: data.map { |d| d.round(2) },
|
592
|
+
backgroundColor: backgroundColor,
|
593
|
+
borderColor: SaleTrend::COLORS[i],
|
594
|
+
borderWidth: 1
|
595
|
+
}
|
596
|
+
end
|
597
|
+
|
598
|
+
hash_a = {
|
599
|
+
labels: labels,
|
600
|
+
datasets: [datasets[0], datasets[1]]
|
601
|
+
}
|
602
|
+
hash_b = {
|
603
|
+
labels: labels,
|
604
|
+
datasets: [datasets[2], datasets[3], datasets[4]]
|
605
|
+
}
|
606
|
+
[hash_a, hash_b]
|
607
|
+
end
|
608
|
+
|
340
609
|
private
|
341
610
|
|
342
611
|
def plan_get(staff_id, time_range, type, property)
|
@@ -433,5 +702,146 @@ module EducodeSales
|
|
433
702
|
end
|
434
703
|
end
|
435
704
|
|
705
|
+
def plan_return(staff_id, time_range, type, property)
|
706
|
+
# plan_return_money 计划回款额
|
707
|
+
start_time = case type
|
708
|
+
when "month"
|
709
|
+
time_range.first + "-01"
|
710
|
+
when "year"
|
711
|
+
time_range.first + "-01-01"
|
712
|
+
when "week"
|
713
|
+
time_range.first.split("-").first + "-01-01"
|
714
|
+
when "quarter"
|
715
|
+
time_range.first.split("-").first + "-01-01"
|
716
|
+
end
|
717
|
+
end_time = case type
|
718
|
+
when "month"
|
719
|
+
time_range.last + "-31"
|
720
|
+
when "year"
|
721
|
+
time_range.last + "-12-31"
|
722
|
+
when "week"
|
723
|
+
time_range.last.split("-").first + "-12-31"
|
724
|
+
when "quarter"
|
725
|
+
time_range.last.split("-").first + "-12-31"
|
726
|
+
end
|
727
|
+
staff_id = staff_id.present? ? Array(staff_id) : nil
|
728
|
+
data = Business.joins(:last_follow_up)
|
729
|
+
.where("educode_sales_follow_ups.plan_return_date >= ? and educode_sales_follow_ups.plan_return_date <= ?", start_time, end_time)
|
730
|
+
if staff_id.present?
|
731
|
+
data = data.joins("LEFT JOIN educode_sales_follow_ups AS last_follow_up ON educode_sales_businesses.last_follow_up_id = last_follow_up.id AND last_follow_up.deleted_at IS NULL
|
732
|
+
LEFT JOIN educode_sales_assign_follow_ups ON educode_sales_assign_follow_ups.follow_up_id = last_follow_up.id").
|
733
|
+
where("(educode_sales_assign_follow_ups.id IS NOT NULL AND educode_sales_assign_follow_ups.staff_id = ?) OR (educode_sales_assign_follow_ups.id IS NULL AND educode_sales_businesses.staff_id = ?)", staff_id, staff_id)
|
734
|
+
end
|
735
|
+
if property.present?
|
736
|
+
data = data.joins(department: [school: :school_tags]).where("school_tags.id = ?", property)
|
737
|
+
end
|
738
|
+
case type
|
739
|
+
when "week"
|
740
|
+
data.select("educode_sales_follow_ups.*, yearweek(educode_sales_follow_ups.plan_return_date) as week").group("yearweek(educode_sales_follow_ups.plan_return_date)").sum("educode_sales_follow_ups.plan_return_money")
|
741
|
+
when "quarter"
|
742
|
+
data = data.select("educode_sales_follow_ups.*, quarter(educode_sales_follow_ups.plan_return_date) as quarter, year(educode_sales_follow_ups.invitation_at) as year")
|
743
|
+
data.group_by { |d| [d.year, d.quarter] }
|
744
|
+
when "month"
|
745
|
+
data = data.select("educode_sales_follow_ups.*, year(educode_sales_follow_ups.plan_return_date) as year, month(educode_sales_follow_ups.plan_return_date) as month")
|
746
|
+
data.group_by { |d| [d.year, d.month] }
|
747
|
+
when "year"
|
748
|
+
data.select("educode_sales_follow_ups.*, year(educode_sales_follow_ups.plan_return_date) as year").group("year(educode_sales_follow_ups.plan_return_date)").sum("educode_sales_follow_ups.plan_return_money")
|
749
|
+
end
|
750
|
+
end
|
751
|
+
|
752
|
+
|
753
|
+
def actual_return(staff_id, time_range, type, property)
|
754
|
+
# money_plan_records表中 amount: 回款金额
|
755
|
+
start_time = case type
|
756
|
+
when "month"
|
757
|
+
time_range.first + "-01"
|
758
|
+
when "year"
|
759
|
+
time_range.first + "-01-01"
|
760
|
+
when "week"
|
761
|
+
time_range.first.split("-").first + "-01-01"
|
762
|
+
when "quarter"
|
763
|
+
time_range.first.split("-").first + "-01-01"
|
764
|
+
end
|
765
|
+
end_time = case type
|
766
|
+
when "month"
|
767
|
+
time_range.last + "-31"
|
768
|
+
when "year"
|
769
|
+
time_range.last + "-12-31"
|
770
|
+
when "week"
|
771
|
+
time_range.last.split("-").first + "-12-31"
|
772
|
+
when "quarter"
|
773
|
+
time_range.last.split("-").first + "-12-31"
|
774
|
+
end
|
775
|
+
staff_id = staff_id.present? ? Array(staff_id) : nil
|
776
|
+
data = MoneyPlanRecord.joins(business: [department: [school: :school_tags]]).where("educode_sales_money_plan_records.date_at >= ? and educode_sales_money_plan_records.date_at <= ?", start_time, end_time)
|
777
|
+
if staff_id.present?
|
778
|
+
data = data.joins("LEFT JOIN educode_sales_follow_ups AS last_follow_up ON educode_sales_businesses.last_follow_up_id = last_follow_up.id AND last_follow_up.deleted_at IS NULL
|
779
|
+
LEFT JOIN educode_sales_assign_follow_ups ON educode_sales_assign_follow_ups.follow_up_id = last_follow_up.id").
|
780
|
+
where("(educode_sales_assign_follow_ups.id IS NOT NULL AND educode_sales_assign_follow_ups.staff_id = ?) OR (educode_sales_assign_follow_ups.id IS NULL AND educode_sales_businesses.staff_id = ?)", staff_id, staff_id)
|
781
|
+
end
|
782
|
+
if property.present?
|
783
|
+
data = data.where("school_tags.id = ?", property)
|
784
|
+
end
|
785
|
+
case type
|
786
|
+
when "week"
|
787
|
+
data.select("educode_sales_money_plan_records.*, yearweek(educode_sales_money_plan_records.date_at) as week").group("yearweek(educode_sales_money_plan_records.date_at)").sum("educode_sales_money_plan_records.amount")
|
788
|
+
when "quarter"
|
789
|
+
data = data.select("educode_sales_money_plan_records.*, quarter(educode_sales_money_plan_records.date_at) as quarter, year(educode_sales_money_plan_records.date_at) as year")
|
790
|
+
data.group_by { |d| [d.year, d.quarter] }
|
791
|
+
when "month"
|
792
|
+
data = data.select("educode_sales_money_plan_records.*, year(educode_sales_money_plan_records.date_at) as year, month(educode_sales_money_plan_records.date_at) as month")
|
793
|
+
data.group_by { |d| [d.year, d.month] }
|
794
|
+
when "year"
|
795
|
+
data.select("educode_sales_money_plan_records.*, year(educode_sales_money_plan_records.date_at) as year").group("year(educode_sales_money_plan_records.date_at)").sum("educode_sales_money_plan_records.amount")
|
796
|
+
end
|
797
|
+
end
|
798
|
+
|
799
|
+
def plan_return_by_o(staff_id, time_range, type, property)
|
800
|
+
# plan_return_money 计划回款额-o类
|
801
|
+
clazz_id = Common.find_by(name: "O类-中标商机", clazz: "business_type", extras: "o_class").id
|
802
|
+
start_time = case type
|
803
|
+
when "month"
|
804
|
+
time_range.first + "-01"
|
805
|
+
when "year"
|
806
|
+
time_range.first + "-01-01"
|
807
|
+
when "week"
|
808
|
+
time_range.first.split("-").first + "-01-01"
|
809
|
+
when "quarter"
|
810
|
+
time_range.first.split("-").first + "-01-01"
|
811
|
+
end
|
812
|
+
end_time = case type
|
813
|
+
when "month"
|
814
|
+
time_range.last + "-31"
|
815
|
+
when "year"
|
816
|
+
time_range.last + "-12-31"
|
817
|
+
when "week"
|
818
|
+
time_range.last.split("-").first + "-12-31"
|
819
|
+
when "quarter"
|
820
|
+
time_range.last.split("-").first + "-12-31"
|
821
|
+
end
|
822
|
+
staff_id = staff_id.present? ? Array(staff_id) : nil
|
823
|
+
data = Business.joins(:last_follow_up).where("educode_sales_businesses.clazz_id = ?", clazz_id)
|
824
|
+
.where("educode_sales_follow_ups.plan_return_date >= ? and educode_sales_follow_ups.plan_return_date <= ?", start_time, end_time)
|
825
|
+
if staff_id.present?
|
826
|
+
data = data.joins("LEFT JOIN educode_sales_follow_ups AS last_follow_up ON educode_sales_businesses.last_follow_up_id = last_follow_up.id AND last_follow_up.deleted_at IS NULL
|
827
|
+
LEFT JOIN educode_sales_assign_follow_ups ON educode_sales_assign_follow_ups.follow_up_id = last_follow_up.id").
|
828
|
+
where("(educode_sales_assign_follow_ups.id IS NOT NULL AND educode_sales_assign_follow_ups.staff_id = ?) OR (educode_sales_assign_follow_ups.id IS NULL AND educode_sales_businesses.staff_id = ?)", staff_id, staff_id)
|
829
|
+
end
|
830
|
+
if property.present?
|
831
|
+
data = data.joins(department: [school: :school_tags]).where("school_tags.id = ?", property)
|
832
|
+
end
|
833
|
+
case type
|
834
|
+
when "week"
|
835
|
+
data.select("educode_sales_follow_ups.*, yearweek(educode_sales_follow_ups.plan_return_date) as week").group("yearweek(educode_sales_follow_ups.plan_return_date)").sum("educode_sales_follow_ups.plan_return_money")
|
836
|
+
when "quarter"
|
837
|
+
data = data.select("educode_sales_follow_ups.*, quarter(educode_sales_follow_ups.plan_return_date) as quarter, year(educode_sales_follow_ups.invitation_at) as year")
|
838
|
+
data.group_by { |d| [d.year, d.quarter] }
|
839
|
+
when "month"
|
840
|
+
data = data.select("educode_sales_follow_ups.*, year(educode_sales_follow_ups.plan_return_date) as year, month(educode_sales_follow_ups.plan_return_date) as month")
|
841
|
+
data.group_by { |d| [d.year, d.month] }
|
842
|
+
when "year"
|
843
|
+
data.select("educode_sales_follow_ups.*, year(educode_sales_follow_ups.plan_return_date) as year").group("year(educode_sales_follow_ups.plan_return_date)").sum("educode_sales_follow_ups.plan_return_money")
|
844
|
+
end
|
845
|
+
end
|
436
846
|
end
|
437
847
|
end
|
@@ -838,7 +838,7 @@
|
|
838
838
|
data.year = "<%= params[:year] %>";
|
839
839
|
<% end %>
|
840
840
|
layer.load(0, {});
|
841
|
-
request.authPost("
|
841
|
+
request.authPost("missions/businesses/get_export_data", {
|
842
842
|
name: data.name,
|
843
843
|
area: data.area,
|
844
844
|
business_step: data.business_step,
|
@@ -859,7 +859,7 @@
|
|
859
859
|
data = res.data
|
860
860
|
table.exportFile(business_table.config.id,data, type);
|
861
861
|
layer.closeAll('loading');
|
862
|
-
request.get('
|
862
|
+
request.get('missions/businesses/add_export_records?type=' + type, {}, function (res) {
|
863
863
|
})
|
864
864
|
})
|
865
865
|
|
@@ -137,6 +137,7 @@
|
|
137
137
|
<script type="text/html" id="toolbar_contract">
|
138
138
|
<div class="layui-btn-container">
|
139
139
|
<span class="table-label">合同列表</span>
|
140
|
+
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" lay-event="export">导出</button>
|
140
141
|
</div>
|
141
142
|
</script>
|
142
143
|
<script>
|
@@ -189,11 +190,13 @@
|
|
189
190
|
|
190
191
|
var business_step_list = xmSelect.render({
|
191
192
|
el: '#contract_business_step',
|
193
|
+
name: 'contract_business_step',
|
192
194
|
data: gon.business_step
|
193
195
|
})
|
194
196
|
|
195
197
|
var index_place_list = xmSelect.render({
|
196
198
|
el: '#contract_index_place',
|
199
|
+
name: 'contract_index_place',
|
197
200
|
model: {
|
198
201
|
icon: 'hidden',
|
199
202
|
label: {
|
@@ -481,7 +484,7 @@
|
|
481
484
|
$(".show_item_contract").toggle()
|
482
485
|
return false;
|
483
486
|
});
|
484
|
-
var
|
487
|
+
var contract_table = table.render({
|
485
488
|
elem: '#contact_table',
|
486
489
|
url: '/missions/contracts',
|
487
490
|
autoSort: false,
|
@@ -519,7 +522,7 @@
|
|
519
522
|
if (search['clazz']) {
|
520
523
|
data.field['clazz'] = search['clazz']
|
521
524
|
}
|
522
|
-
search = data.field
|
525
|
+
search = data.field;
|
523
526
|
table.reload('contact_table', {
|
524
527
|
url: '/missions/contracts',
|
525
528
|
page: {
|
@@ -543,6 +546,27 @@
|
|
543
546
|
return false;
|
544
547
|
});
|
545
548
|
|
549
|
+
/**
|
550
|
+
* toolbar事件监听
|
551
|
+
*/
|
552
|
+
table.on('toolbar(contact_table)', function (obj) {
|
553
|
+
if (obj.event === 'export') { //导出
|
554
|
+
layer.load(0, {});
|
555
|
+
var data = form.val("search_form");
|
556
|
+
var business_step = [];
|
557
|
+
business_step_list.getValue().forEach(function(d) {
|
558
|
+
business_step.push(d.value);
|
559
|
+
});
|
560
|
+
data.business_step = business_step.toString();
|
561
|
+
request.authGet("missions/contracts?" + $.param({q:data}), {
|
562
|
+
}, function (res) {
|
563
|
+
data = res.data;
|
564
|
+
table.exportFile(contract_table.config.id, data, 'xls');
|
565
|
+
layer.closeAll('loading');
|
566
|
+
})
|
567
|
+
}
|
568
|
+
});
|
569
|
+
|
546
570
|
table.on('tool(contact_table)', function (obj) {
|
547
571
|
var data = obj.data;
|
548
572
|
id = data.id
|
@@ -67,6 +67,12 @@
|
|
67
67
|
<input type="text" class="layui-input" id="school" name="school" placeholder=" - " autocomplete="off">
|
68
68
|
</div>
|
69
69
|
</div>
|
70
|
+
<div class="layui-inline">
|
71
|
+
<label class="layui-form-label">协助人</label>
|
72
|
+
<div class="layui-input-inline">
|
73
|
+
<div id="assist_staffs"></div>
|
74
|
+
</div>
|
75
|
+
</div>
|
70
76
|
|
71
77
|
<div class="layui-inline">
|
72
78
|
<button type="reset" class="layui-btn layui-btn-primary" lay-submit lay-filter="reset_business_search">重置
|
@@ -156,6 +162,15 @@
|
|
156
162
|
range: true
|
157
163
|
});
|
158
164
|
|
165
|
+
//协助人选择
|
166
|
+
var assist_staffs_select = xmSelect.render({
|
167
|
+
el: '#assist_staffs',
|
168
|
+
name: 'assist_staffs',
|
169
|
+
data: <%=raw @assist_staffs.to_json %>,
|
170
|
+
filterable: true,
|
171
|
+
radio: true
|
172
|
+
});
|
173
|
+
|
159
174
|
cols_table = [
|
160
175
|
[
|
161
176
|
{
|
@@ -342,7 +357,12 @@
|
|
342
357
|
|
343
358
|
// 监听搜索操作
|
344
359
|
form.on('submit(search_ideas)', function (data) {
|
345
|
-
|
360
|
+
var assist_staffs_value = [];
|
361
|
+
assist_staffs_select.getValue().forEach(function (d) {
|
362
|
+
assist_staffs_value.push(d.value)
|
363
|
+
});
|
364
|
+
data.field.assist_staffs = assist_staffs_value.toString();
|
365
|
+
search = data.field;
|
346
366
|
table.reload('ideas_table', {
|
347
367
|
page: {
|
348
368
|
curr: 1
|
@@ -365,7 +385,8 @@
|
|
365
385
|
types: "",
|
366
386
|
level: "",
|
367
387
|
history_type: ""
|
368
|
-
})
|
388
|
+
});
|
389
|
+
assist_staffs_select.setValue([]);
|
369
390
|
return false;
|
370
391
|
});
|
371
392
|
// form.on('submit(show_hide)', function (data) {
|
@@ -5,6 +5,12 @@
|
|
5
5
|
<div class="layui-row">
|
6
6
|
<h2 style="padding-left: 25px">方案信息</h2>
|
7
7
|
</div>
|
8
|
+
<div class="layui-col-md6" style="display: none">
|
9
|
+
<labeL class="layui-form-label">部门:</labeL>
|
10
|
+
<div class="layui-input-block">
|
11
|
+
<div id="department_id" style="width: 600px;"></div>
|
12
|
+
</div>
|
13
|
+
</div>
|
8
14
|
<div class="layui-row" style="padding-top: 15px">
|
9
15
|
<div class="layui-col-md6">
|
10
16
|
<labeL class="layui-form-label">单位联系人:</labeL>
|
@@ -419,11 +425,11 @@
|
|
419
425
|
})
|
420
426
|
data.field.school_id = schools[0];
|
421
427
|
|
422
|
-
var departments = [];
|
423
|
-
department_list.getValue().forEach(function (d) {
|
424
|
-
|
425
|
-
})
|
426
|
-
data.field.department_id = departments[0];
|
428
|
+
// var departments = [];
|
429
|
+
// department_list.getValue().forEach(function (d) {
|
430
|
+
// departments.push(d.value);
|
431
|
+
// })
|
432
|
+
// data.field.department_id = departments[0];
|
427
433
|
var business = [];
|
428
434
|
business_list.getValue().forEach(function (d) {
|
429
435
|
business.push(d.value);
|
@@ -434,7 +440,6 @@
|
|
434
440
|
data.field.assist_staff_ids = assist_staff_list.getValue('valueStr');
|
435
441
|
data.field.other_staff_ids = other_staff_list.getValue('valueStr');
|
436
442
|
data.field.attachment_ids = attachment_list.getValue('valueStr');
|
437
|
-
data.field.school_id = school_list.getValue('valueStr');
|
438
443
|
request.authPost("missions/ideas/", data.field, function (res) {
|
439
444
|
if (res.success == false) {
|
440
445
|
layer.alert(res.msg)
|
@@ -60,6 +60,7 @@
|
|
60
60
|
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" id="upload_money_plan_btn" style="margin-left: 20px;">批量导入回款计划</button>
|
61
61
|
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" style="margin-left: 20px;"
|
62
62
|
lay-event="add_record">添加回款记录</button>
|
63
|
+
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" lay-event="export">导出</button>
|
63
64
|
<% end %>
|
64
65
|
</script>
|
65
66
|
|
@@ -95,9 +96,10 @@
|
|
95
96
|
range: true
|
96
97
|
});
|
97
98
|
form.render();
|
98
|
-
table.render({
|
99
|
+
var money_plan_record_table = table.render({
|
99
100
|
elem: '#money_plan_record_table',
|
100
101
|
url: '/missions/money_plan_records',
|
102
|
+
title: '回款记录列表',
|
101
103
|
toolbar: '#toolbar_money_plan_record',
|
102
104
|
defaultToolbar: ['filter'],
|
103
105
|
totalRow:true,
|
@@ -174,11 +176,13 @@
|
|
174
176
|
});
|
175
177
|
|
176
178
|
var staff_manages_list = xmSelect.render({
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
179
|
+
el: '#staff_manages',
|
180
|
+
name: 'staff_manages',
|
181
|
+
data: gon.staffs,
|
182
|
+
filterable: true,
|
183
|
+
radio: true,
|
184
|
+
});
|
185
|
+
|
182
186
|
var sort = {},
|
183
187
|
search = {};
|
184
188
|
table.on('sort(money_plan_record_table)', function(obj) {
|
@@ -243,8 +247,17 @@
|
|
243
247
|
$(window).on("resize", function() {
|
244
248
|
layer.full(sindex);
|
245
249
|
});
|
250
|
+
}else if(obj.event === 'export'){
|
251
|
+
layer.load(0, {});
|
252
|
+
var data = form.val("submit_form_record");
|
253
|
+
data.staff_manages = staff_manages_list.getValue('valueStr');
|
254
|
+
request.authGet("missions/money_plan_records?"+ $.param({q: data}), {}, function (res) {
|
255
|
+
data = res.data;
|
256
|
+
table.exportFile(money_plan_record_table.config.id, data, 'xls');
|
257
|
+
layer.closeAll('loading');
|
258
|
+
})
|
246
259
|
}
|
247
|
-
})
|
260
|
+
});
|
248
261
|
table.on('tool(money_plan_record_table)', function(obj) {
|
249
262
|
var data = obj.data;
|
250
263
|
id = data.id;
|