|
| 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