diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index a340fcef94..dd8312549d 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -13,12 +13,16 @@ use App\Models\CheckoutAcceptance; use App\Models\Company; use App\Models\Contracts\Acceptable; use App\Models\User; +use App\Models\AssetModel; +use App\Models\Accessory; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use App\Http\Controllers\SettingsController; use Barryvdh\DomPDF\Facade\Pdf; +use Carbon\Carbon; class AcceptanceController extends Controller { @@ -129,30 +133,60 @@ class AcceptanceController extends Controller } $item = $acceptance->checkoutable_type::find($acceptance->checkoutable_id); - $assigned_to = User::find($item->assigned_to); - $branding_settings= SettingsController::getPDFBranding(); - $data = [ - 'item_tag' => $item->asset_tag, - 'item_model' => $item->model_id, - 'item_serial' => $item->serial, - 'eula' => $item->getEula(), - 'check_out_date' => $acceptance->created_at, - 'accepted_date' => $acceptance->accepted_at, + + if ($acceptance->checkoutable_type== 'App\Models\Asset') { + $assigned_to = User::find($item->assigned_to); + $asset_model = AssetModel::find($item->model_id); + $branding_settings = SettingsController::getPDFBranding(); + $data = [ + 'item_tag' => $item->asset_tag, + 'item_model' => $asset_model->name, + 'item_serial' => $item->serial, + 'eula' => $item->getEula(), + 'check_out_date' => Carbon::parse($acceptance->created_at)->format($branding_settings->date_display_format), + 'accepted_date' => Carbon::parse($acceptance->accepted_at)->format($branding_settings->date_display_format), // 'assigned_by' => self - 'assigned_to' => $assigned_to->first_name.' '.$assigned_to->last_name, - 'company_name' => $branding_settings->site_name, - 'signature' => storage_path().'/private_uploads/signatures/'.$sig_filename, - 'logo' => public_path().'/uploads/'.$branding_settings->logo, - 'date_settings' => $branding_settings->date_display_format, + 'assigned_to' => $assigned_to->first_name . ' ' . $assigned_to->last_name, + 'company_name' => $branding_settings->site_name, + 'signature' => storage_path() . '/private_uploads/signatures/' . $sig_filename, + 'logo' => public_path() . '/uploads/' . $branding_settings->logo, + 'date_settings' => $branding_settings->date_display_format, + ]; + $pdf = Pdf::loadView('account.accept.accept-asset-eula', $data); + Storage::put('private_uploads/eula-pdfs/' . $acceptance->stored_eula_file, $pdf->output()); + + $a = new Actionlog(); + $a->stored_eula = $item->getEula(); + $a->stored_eula_file = $acceptance->stored_eula_file; + $a->save(); + + return redirect()->to('account/accept')->with('success', $return_msg); + } +// TBC: trying to get the user_id here + $accessory_user= DB::table('accessories_users')->find($acceptance->assigned_to_id); + $assigned_to = User::find($accessory_user); + $accessory_model = Accessory::find($item->id); + $branding_settings = SettingsController::getPDFBranding(); + $data = [ + 'item_tag' => $item->model_number, + 'item_model' => $accessory_model->name, + 'eula' => $item->getEula(), + 'check_out_date' => Carbon::parse($acceptance->created_at)->format($branding_settings->date_display_format), + 'accepted_date' => Carbon::parse($acceptance->accepted_at)->format($branding_settings->date_display_format), +// 'assigned_by' => self + 'assigned_to' => $assigned_to->first_name . ' ' . $assigned_to->last_name, + 'company_name' => $branding_settings->site_name, + 'signature' => storage_path() . '/private_uploads/signatures/' . $sig_filename, + 'logo' => public_path() . '/uploads/' . $branding_settings->logo, + 'date_settings' => $branding_settings->date_display_format, ]; + $pdf = Pdf::loadView('account.accept.accept-accessory-eula', $data); + Storage::put('private_uploads/eula-pdfs/' . $acceptance->stored_eula_file, $pdf->output()); - $pdf = Pdf::loadView('account.accept.accept-eula', $data); - Storage::put('private_uploads/eula-pdfs/'.$acceptance->stored_eula_file, $pdf->output()); - - $a=new Actionlog(); - $a->stored_eula = $item->getEula(); - $a->stored_eula_file = $acceptance->stored_eula_file; - $a->save(); + $a = new Actionlog(); + $a->stored_eula = $item->getEula(); + $a->stored_eula_file = $acceptance->stored_eula_file; + $a->save(); return redirect()->to('account/accept')->with('success', $return_msg); } diff --git a/resources/views/account/accept/accept-eula.blade.php b/resources/views/account/accept/accept-accessory-eula.blade.php similarity index 71% rename from resources/views/account/accept/accept-eula.blade.php rename to resources/views/account/accept/accept-accessory-eula.blade.php index 7926117d30..d2eb09017f 100644 --- a/resources/views/account/accept/accept-eula.blade.php +++ b/resources/views/account/accept/accept-accessory-eula.blade.php @@ -10,6 +10,7 @@ @if ($signature)
{{$company_name}}
Date: {{ date($date_settings) }}
Asset Tag: {{ $item_tag }}
Asset Model: {{ $item_model }}
-Asset Tag: {{ $item_serial }}
On {{$check_out_date}} {{$company_name}} is assigning item {{$item_tag}} to {{$assigned_to}}.
- They accept responsibility of said item until it is returned.
Assigned on: {{$check_out_date}}
-Accepted on: {{$accepted_date}}
Accepted on: {{$accepted_date}}
Assigned to: {{$assigned_to}}
@if ($signature){{$company_name}}
+Date: {{ date($date_settings) }}
Asset Tag: {{ $item_tag }}
+Asset Model: {{ $item_model }}
+Asset Serial: {{ $item_serial }}
Assigned on: {{$check_out_date}}
+Accepted on: {{$accepted_date}}
+Assigned to: {{$assigned_to}}
+@if ($signature) +