adds the ability to save eula pdfs to storage, still working on storing them in the DB and exposing them in the UI

This commit is contained in:
Godfrey M 2022-03-08 16:42:27 -08:00
parent 533670f3f1
commit 59c583ac74
7 changed files with 72 additions and 18 deletions

View file

@ -10,11 +10,11 @@ use App\Http\Controllers\Controller;
use App\Models\CheckoutAcceptance;
use App\Models\Company;
use App\Models\Contracts\Acceptable;
use Barryvdh\DomPDF\PDF;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Barryvdh\DomPDF\Facade\Pdf;
class AcceptanceController extends Controller
{
@ -40,6 +40,7 @@ class AcceptanceController extends Controller
{
$acceptance = CheckoutAcceptance::find($id);
if (is_null($acceptance)) {
return redirect()->route('account.accept')->with('error', trans('admin/hardware/message.does_not_exist'));
}
@ -96,20 +97,25 @@ class AcceptanceController extends Controller
if (! Storage::exists('private_uploads/signatures')) {
Storage::makeDirectory('private_uploads/signatures', 775);
}
$sig_filename = '';
if ($request->filled('signature_output')) {
$sig_filename = 'siglog-'.Str::uuid().'-'.date('Y-m-d-his').'.png';
$data_uri = e($request->input('signature_output'));
$encoded_image = explode(',', $data_uri);
$decoded_image = base64_decode($encoded_image[1]);
Storage::put('private_uploads/signatures/'.$sig_filename, (string) $decoded_image);
$path = Storage::put('private_uploads/signatures/'.$sig_filename, (string) $decoded_image);
}
if ($request->input('asset_acceptance') == 'accepted') {
$acceptance->accept($sig_filename);
event(new CheckoutAccepted($acceptance));
$return_msg = trans('admin/users/message.accepted');
} else {
$acceptance->decline($sig_filename);
@ -117,21 +123,24 @@ class AcceptanceController extends Controller
$return_msg = trans('admin/users/message.declined');
}
$sig_image=Storage::get('private_uploads/signatures/'.$sig_filename);
$this->SignatureEulaPDF($acceptance, $sig_image );
$item = $acceptance->checkoutable_type::find($acceptance->checkoutable_id);
$data = [
'item' => $item,
'eula' => $item->getEula(),
'signature' => storage_path().'/private_uploads/signatures/'.$sig_filename,
'logo' => public_path().'/uploads/snipe-logo.png',
];
\Log::error(storage_path().'/eula-pdfs/'.$sig_filename);
$pdf = Pdf::loadView('account.accept.accept-eula', $data);
$stored_eula = Storage::put('private_uploads/eula-pdfs/accepted-eula-'.date('Y-m-d-h-i-s').'.pdf', $pdf->output());
//not sure what im doing here,but I think its something of this.
route('log.storedeula.download', $stored_eula);
return redirect()->to('account/accept')->with('success', $return_msg);
}
public function SignatureEulaPDF($acceptance, $sig_image)
{
// When I compact the $data I at least get back an ipsum string in the error message that is recognized as an
// "unknown variable". 2nd param in load view should be the array of things you wanted rendered in the pdf.
$data = [
'eula'=> $acceptance->checkoutable->getEula(),
'signature' => $sig_image,
];
$pdf = PDF::loadView('account.accept.create', compact($data));
return $pdf->download('test.pdf');
}
}
}

View file

@ -16,4 +16,11 @@ class ActionlogController extends Controller
return Response::make($contents)->header('Content-Type', $filetype);
}
public function getStoredEula($filename){
$this->authorize('view', \App\Models\Asset::class);
$file = config('app.private_uploads').'/eula-pdfs/'.$filename;
return Response::download($file);
}
}

View file

@ -52,6 +52,7 @@ class ReportsController extends Controller
'accept_signature',
'action_type',
'note',
'stored_eula_file',
];
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';

View file

@ -112,7 +112,7 @@ class ActionlogsTransformer
'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null,
'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null,
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
'stored_eula_file' => ($actionlog->stored_eula_file) ? route('log.storedeula.download', [ 'filename' => $actionlog->stored_eula_file]) : null,
];
return $array;

View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HTML 5 Boilerplate</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
@if ($signature)
<center>
<img src="{{ $logo }}">
</center>
@endif
<br>
<h2>{{ $item->name }}</h2>
<p>Date: {{ date('Y-m-d h:i') }} </p>
@if ($eula)
{!! $eula !!}
@endif
<br><br>
@if ($signature)
<center>
<img src="{{ $signature }}" style="max-width: 50%">
</center>
@endif
</body>
</html>

View file

@ -53,6 +53,7 @@
<th class="col-sm-2" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.to') }}</th>
<th class="col-sm-1" data-field="note">{{ trans('general.notes') }}</th>
<th class="col-sm-2" data-field="log_meta" data-visible="false" data-formatter="changeLogFormatter">{{ trans('general.changed') }}</th>
<th class="col-sm-1" data-field="stored_eula_file" data-visible="true">{{ trans('general.accept_eula') }}</th>
</tr>
</thead>
</table>

View file

@ -124,6 +124,10 @@ Route::group(['middleware' => 'auth'], function () {
'display-sig/{filename}',
[ActionlogController::class, 'displaySig']
)->name('log.signature.view');
Route::get(
'stored-eula-file/{$filename}/download',
[ActionlogController::class, 'getStoredEula']
)->name('log.storedeula.download');
});
/*