first();
if (!$company_pro_document) abort(404);
$company = Company::where('id', $company_pro_document->company_id)->first();
if (!$company) abort(404);
$pro = $company_pro_document->pro;
// {token} replacements
// 1. replace "custom" fields (entered by candidate pro)
$html = $company_pro_document->content_html;
if($company_pro_document->custom_fields_data) {
$customFieldsData = json_decode($company_pro_document->custom_fields_data, true);
foreach ($customFieldsData as $k => $v) {
$html = str_replace('{' . $k . '}', '' . $v . '', $html);
}
}
// replace database driven fields
$html = preg_replace_callback(
'/{([^}]+)}/',
function ($match) use ($company, $company_pro_document, $pro) {
$token = $match[1];
$replacement = '';
if(strpos($token, '.') !== FALSE) {
$token = explode('.', $token);
// if prefixed with * - means pre-send fill
$waitForCountersignToShow = false;
if($token[0][0] === '*') {
$token[0] = substr($token[0], 1);
$waitForCountersignToShow = true;
}
$replacement = @${$token[0]}->{$token[1]};
// special cases
// if the fields are relating to PRO SIGNATURE, then don't display anything until signing
if($token[0] === 'company_pro_document') {
if (!$company_pro_document->has_pro_signed &&
($token[1] === 'pro_signatures' || $token[1] === 'pro_signed_at')) {
$replacement = '';
}
}
// if you want to $waitForCountersignToShow, then do that
if($waitForCountersignToShow && !$company_pro_document->has_hrm_pro_counter_signed){
$replacement = '';
}
if(strpos($token[1], "_at") === strlen($token[1]) - 3) {
if(!!$replacement) {
$replacement = date('m/d/Y', strtotime($replacement));
}
}
}
else {
switch ($token) {
case 'TODAY':
$replacement = date('Y-m-d');
break;
default:
$replacement = '' . $token . '';
break;
}
}
return $replacement;
},
$html
);
$pdf = PDF::loadView('layouts.document-pdf', compact('company_pro_document', 'html'));
return $pdf->stream($uid.'.pdf');
// return view('layouts.document-pdf', compact('company_pro_document', 'html'));
}
}