Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 75 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AllUsersReportUsageExport | |
0.00% |
0 / 75 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| array | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
56 | |||
| headings | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Exports; |
| 4 | |
| 5 | use Carbon\CarbonPeriod; |
| 6 | use App\Http\Models\Chart; |
| 7 | use App\Http\Models\Auth\User; |
| 8 | use App\Http\Models\HubspotProperties; |
| 9 | use Vitorccs\LaravelCsv\Concerns\FromArray; |
| 10 | use Vitorccs\LaravelCsv\Concerns\Exportable; |
| 11 | use Vitorccs\LaravelCsv\Concerns\WithHeadings; |
| 12 | |
| 13 | class AllUsersReportUsageExport implements FromArray, WithHeadings |
| 14 | { |
| 15 | use Exportable; |
| 16 | |
| 17 | public $admin; |
| 18 | public $from_date; |
| 19 | public $to_date; |
| 20 | public $user_ids; |
| 21 | public $group_ids; |
| 22 | public $subgroup_ids; |
| 23 | |
| 24 | public function __construct($admin, $from_date, $to_date, $user_ids, $group_ids, $subgroup_ids) |
| 25 | { |
| 26 | $this->admin = $admin; |
| 27 | $this->from_date = $from_date; |
| 28 | $this->to_date = $to_date; |
| 29 | $this->user_ids = $user_ids; |
| 30 | $this->group_ids = $group_ids; |
| 31 | $this->subgroup_ids = $subgroup_ids; |
| 32 | } |
| 33 | |
| 34 | public function array(): array |
| 35 | { |
| 36 | $users = User::select([ |
| 37 | "id", |
| 38 | "first_name", |
| 39 | "last_name", |
| 40 | "company_group_id", |
| 41 | "company_id", |
| 42 | "deleted_at", |
| 43 | "avatar" |
| 44 | ]); |
| 45 | |
| 46 | if (!empty($this->user_ids)) { |
| 47 | $users = $users->whereIn('id', $this->user_ids); |
| 48 | } |
| 49 | |
| 50 | if (!empty($this->group_ids)) { |
| 51 | $users = $users->whereIn('company_group_id', $this->group_ids); |
| 52 | } |
| 53 | |
| 54 | $users = $users->get(); |
| 55 | $ids = $users->pluck("id")->toArray(); |
| 56 | |
| 57 | $properties = HubspotProperties::whereIn("flymsg_id", $ids) |
| 58 | ->get(); |
| 59 | |
| 60 | $period = CarbonPeriod::create($this->from_date, $this->to_date); |
| 61 | $data = []; |
| 62 | |
| 63 | foreach ($properties as $property) { |
| 64 | $row = [ |
| 65 | 'first_name' => $property->firstname ?? '', |
| 66 | 'last_name' => $property->lastname ?? '', |
| 67 | 'email' => $property->email ?? '', |
| 68 | 'license_type' => $property->subscription_type ?? '', |
| 69 | 'flymsg_account_creation_date' => $property->account_creation_date ?? '', |
| 70 | 'extension_installed_on_any_browser' => ($property->flymsg_chrome_extension_installed == "Yes" || $property->flymsg_edge_extension_installed == "Yes") ? "Yes" : "No", |
| 71 | 'last_login_to_flymsg' => $property->last_login ?? '', |
| 72 | 'sentence_rewrite_ai_used' => $property->total___of_times_sentence_rewrite_used__count_ ?? 0, |
| 73 | 'paragraph_rewrite_ai_used' => $property->total___of_times_paragraph_rewrite_used__count_ ?? 0, |
| 74 | 'flyengage_ai_used' => $property->total___of_times_flyengage_used__count_ ?? 0, |
| 75 | 'flyposts_ai_used' => $property->total___of_times_flyposts_used__count_ ?? 0, |
| 76 | 'no_of_flycuts_created' => $property->number_of_flycuts_created_count ?? 0, |
| 77 | 'no_of_flyplates_added_to_flycuts' => $property->number_of_flyplates_in_flycuts_count ?? 0, |
| 78 | 'characters_typed_by_flymsg' => round($property->total___of_characters_typed_by_flymsg_by_user, 0) ?? 0, |
| 79 | 'time_saved_by_flymsg' => round($property->total_time_saved_by_flymsg_by_user, 2) ?? 0, |
| 80 | 'cost_saved_by_flymsg' => round($property->total_cost_savings_by_flymsg_by_user, 2) ?? 0, |
| 81 | ]; |
| 82 | |
| 83 | foreach ($period as $date) { |
| 84 | $month_year = $date->format('M Y'); |
| 85 | $flychart = Chart::where("user_id", $property->flymsg_id)->where("month_year", $month_year)->first(); |
| 86 | $row["characters_typed_by_flymsg___$month_year"] = $flychart->characters_typed ?? 0; |
| 87 | $row["time_saved_by_flymsg___$month_year"] = $flychart->time_saved ?? 0; |
| 88 | $row["cost_saved_by_flymsg___$month_year"] = $flychart->cost_saved ?? 0; |
| 89 | } |
| 90 | |
| 91 | $data[] = $row; |
| 92 | } |
| 93 | |
| 94 | return $data; |
| 95 | } |
| 96 | |
| 97 | public function headings(): array |
| 98 | { |
| 99 | $headers = [ |
| 100 | 'Firstname', |
| 101 | 'Lastname', |
| 102 | 'Email', |
| 103 | 'License Type', |
| 104 | 'FlyMSG Account Creation Date', |
| 105 | 'Extension Installed on Any Browser', |
| 106 | 'Last Login to FlyMSG', |
| 107 | 'Total # of Times FlyEngage AI Used (Count)', |
| 108 | 'Total # of Times FlyPosts AI Used (Count)', |
| 109 | '# of FlyCuts Created (Count)', |
| 110 | '# of FlyPlates Added to FlyCuts (Count)', |
| 111 | 'Total # of Characters Typed by FlyMSG by User', |
| 112 | 'Total Time Saved by FlyMSG by User', |
| 113 | 'Total Cost Savings by FlyMSG by User', |
| 114 | ]; |
| 115 | |
| 116 | $period = CarbonPeriod::create($this->from_date, '1 month', $this->to_date); |
| 117 | |
| 118 | foreach ($period as $date) { |
| 119 | $month_year = $date->format('M Y'); |
| 120 | $headers[] = "Total # of Characters Typed by FlyMSG by User $month_year"; |
| 121 | $headers[] = "Total Time Saved by FlyMSG by User $month_year"; |
| 122 | $headers[] = "Total Cost Savings by FlyMSG by User $month_year"; |
| 123 | } |
| 124 | |
| 125 | return $headers; |
| 126 | } |
| 127 | } |