mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
Rough refactor of the acceptance controller
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
afb3843fad
commit
b7eb72fe49
|
@ -106,87 +106,92 @@ class AcceptanceController extends Controller
|
|||
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]);
|
||||
$acceptance->stored_eula_file = 'accepted-eula-'.date('Y-m-d-h-i-s').'.pdf';
|
||||
$path = Storage::put('private_uploads/signatures/'.$sig_filename, (string) $decoded_image);
|
||||
/**
|
||||
* Check for the eula-pdfs directory
|
||||
*/
|
||||
if (! Storage::exists('private_uploads/eula-pdfs')) {
|
||||
Storage::makeDirectory('private_uploads/eula-pdfs', 775);
|
||||
}
|
||||
|
||||
$sig_filename = '';
|
||||
$item = $acceptance->checkoutable_type::find($acceptance->checkoutable_id);
|
||||
$display_model = '';
|
||||
$pdf_view_route = '';
|
||||
$pdf_filename = 'accepted-eula-'.date('Y-m-d-h-i-s').'.pdf';
|
||||
|
||||
if ($request->input('asset_acceptance') == 'accepted') {
|
||||
$acceptance->accept($sig_filename);
|
||||
|
||||
event(new CheckoutAccepted($acceptance));
|
||||
|
||||
$return_msg = trans('admin/users/message.accepted');
|
||||
// The item was accepted, check for a signature
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
$acceptance->decline($sig_filename);
|
||||
// this is horrible
|
||||
if ($acceptance->checkoutable_type== 'App\Models\Asset') {
|
||||
$pdf_view_route ='account.accept.accept-asset-eula';
|
||||
$asset_model = AssetModel::find($item->model_id);
|
||||
$display_model = $asset_model->name;
|
||||
|
||||
event(new CheckoutDeclined($acceptance));
|
||||
|
||||
$return_msg = trans('admin/users/message.declined');
|
||||
}
|
||||
// } elseif ($acceptance->checkoutable_type== 'App\Models\License') {
|
||||
// $pdf_view_route ='account.accept.accept-license-eula';
|
||||
// $license = License::find($item->id);
|
||||
// $display_model = $license->name;
|
||||
|
||||
$item = $acceptance->checkoutable_type::find($acceptance->checkoutable_id);
|
||||
} elseif ($acceptance->checkoutable_type== 'App\Models\Accessory') {
|
||||
$pdf_view_route ='account.accept.accept-accessory-eula';
|
||||
$accessory = Accessory::find($item->id);
|
||||
$display_model = $accessory->name;
|
||||
$assigned_to = User::find($item->assigned_to);
|
||||
|
||||
if ($acceptance->checkoutable_type== 'App\Models\Asset') {
|
||||
$assigned_to = User::find($item->assigned_to);
|
||||
$asset_model = AssetModel::find($item->model_id);
|
||||
// } elseif ($acceptance->checkoutable_type== 'App\Models\Consumable') {
|
||||
// $pdf_view_route ='account.accept.accept-consumable-eula';
|
||||
// $consumable = Consumable::find($item->id);
|
||||
// $display_model = $consumable->name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather the data for the PDF
|
||||
*/
|
||||
$branding_settings = SettingsController::getPDFBranding();
|
||||
$data = [
|
||||
'item_tag' => $item->asset_tag,
|
||||
'item_model' => $asset_model->name,
|
||||
'item_model' => $display_model,
|
||||
'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_to' => $assigned_to->first_name . ' ' . $assigned_to->last_name,
|
||||
'assigned_to' => $assigned_to,
|
||||
'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();
|
||||
if ($pdf_view_route!='') {
|
||||
$pdf = Pdf::loadView($pdf_view_route, $data);
|
||||
Storage::put('private_uploads/eula-pdfs/' .$pdf_filename, $pdf->output());
|
||||
}
|
||||
|
||||
return redirect()->to('account/accept')->with('success', $return_msg);
|
||||
$acceptance->accept($sig_filename, $item->getEula(), $pdf_filename);
|
||||
event(new CheckoutAccepted($acceptance));
|
||||
|
||||
$return_msg = trans('admin/users/message.accepted');
|
||||
|
||||
} else {
|
||||
$acceptance->decline($sig_filename);
|
||||
event(new CheckoutDeclined($acceptance));
|
||||
$return_msg = trans('admin/users/message.declined');
|
||||
}
|
||||
//
|
||||
$accessory_user= DB::table('checkout_acceptances')->find($acceptance->assigned_to_id);
|
||||
$assigned_to = User::find($accessory_user->assigned_to_id);
|
||||
$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());
|
||||
|
||||
$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);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue