Skip to content

Commit dcbb09b

Browse files
committed
added checkoutable class
1 parent 58eac61 commit dcbb09b

File tree

2 files changed

+73
-11
lines changed

2 files changed

+73
-11
lines changed

app/Http/Controllers/ReportsController.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,19 +1133,8 @@ public function getAssetAcceptanceReport($deleted = false) : View
11331133
$query->withTrashed();
11341134
}
11351135

1136-
// $assetsForReport = $query->get()
1137-
// ->map(function ($acceptance) {
1138-
// return [
1139-
// 'assetItem' => $acceptance->checkoutable,
1140-
// 'acceptance' => $acceptance,
1141-
// ];
1142-
// });
1143-
// dd($assetsForReport);
1144-
// $assetsForReport = $query->get()->map(function ($unaccepted) {})
11451136
$itemsForReport = $query->get()->map(fn ($unaccepted) => Checkoutable::fromAcceptance($unaccepted));
11461137

1147-
1148-
11491138
return view('reports/unaccepted_assets', compact('itemsForReport','showDeleted' ));
11501139
}
11511140

app/Models/Checkoutable.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Helpers\Helper;
6+
7+
8+
class Checkoutable
9+
{
10+
public function __construct(
11+
public int $acceptance_id,
12+
public string $created_at,
13+
public string $company,
14+
public string $category,
15+
public string $model,
16+
public string $asset_tag,
17+
public string $name,
18+
public string $type,
19+
public object $acceptance,
20+
){}
21+
22+
// public static function fromCheckoutable(Asset|Accessory|etc..)
23+
// {
24+
//
25+
// }
26+
27+
public static function fromAcceptance(CheckoutAcceptance $unaccepted): self
28+
{
29+
$unaccepted_row = $unaccepted->checkoutable;
30+
$acceptance = $unaccepted;
31+
32+
$company = optional($unaccepted_row->company)->name ?? '';
33+
$category = $model = $name = $tag = '';
34+
$type = $acceptance->checkoutable_item_type ?? '';
35+
36+
if($unaccepted_row instanceof Asset){
37+
$category = optional($unaccepted_row->model?->category?->present())->nameUrl() ?? '';
38+
$model = optional($unaccepted_row->present())->modelUrl() ?? '';
39+
$name = optional($unaccepted_row->present())->nameUrl() ?? '';
40+
$tag = (string) ($unaccepted_row->asset_tag ?? '');
41+
}
42+
elseif($unaccepted_row instanceof Accessory){
43+
$category = optional($unaccepted_row->category?->present())->nameUrl() ?? '';
44+
$model = $unaccepted_row->model_number ?? '';
45+
$name = optional($unaccepted_row->present())->nameUrl() ?? '';
46+
$tag = '';
47+
48+
}
49+
if($unaccepted_row instanceof LicenseSeat){
50+
$category = '';
51+
$model = '';
52+
$name = $unaccepted_row->license->name ?? '';
53+
$tag = '';
54+
}
55+
if($unaccepted_row instanceof Component){
56+
$category = optional($unaccepted_row->category?->present())->nameUrl() ?? '';
57+
$model = $unaccepted_row->model_number ?? '';
58+
$name = $unaccepted_row->present()->nameUrl() ?? '';
59+
$tag = '';
60+
}
61+
return new self(
62+
acceptance_id: $acceptance->id,
63+
created_at: Helper::getFormattedDateObject($acceptance->created_at, 'datetime', false),
64+
company: $company,
65+
category: $category,
66+
model: $model,
67+
asset_tag: $tag,
68+
name: $name,
69+
type: $type,
70+
acceptance: $acceptance,
71+
);
72+
}
73+
}

0 commit comments

Comments
 (0)