request_method === 'POST') {
ini_set('display_errors', 1);
$API_office_travel_reimburse->checkPermissions('office-travel-reimburse', 'RO');
$API_office_travel_reimburse->return_url = false;
$portal_settings = $GLOBALS['conn']->query("SELECT * FROM system_settings")->fetch_assoc();
$month = $_POST['calender_month'];
$firstDay = $month . '-01';
$lastDay = date('Y-m-t', strtotime($firstDay));
$_GET['builder'] = [
1 => [
'where' => [
0 => 'user_uuid',
1 => $_SESSION['user']['user_uuid']
],
'between' => [
0 => 'travel_date',
1 => $firstDay,
2 => $lastDay
]
]
];
$travel_reimbursements = $API_office_travel_reimburse->getTravelReimburse();
// format is this: 2026-07
$month = $_POST['calender_month'];
$lastDay = date('Y-m-t', strtotime($month . '-01'));
$invoiceNumber = 'D-' . date('nY', strtotime($month . '-01'));
$totalBusinessKm = 0;
$totalHomeworkKm = 0;
foreach ($travel_reimbursements as $trip) {
if ($trip['homework']) {
$totalHomeworkKm += $trip['travel_distance'];
} else {
$totalBusinessKm += $trip['travel_distance'];
}
}
$totalKm = $totalBusinessKm + $totalHomeworkKm;
$amountExcl =
($totalBusinessKm * $portal_settings['office_travelreimburse_cents_business_excl']) +
($totalHomeworkKm * $portal_settings['office_travelreimburse_cents_homework_excl']);
$amountIncl =
($totalBusinessKm * $portal_settings['office_travelreimburse_cents_business_incl']) +
($totalHomeworkKm * $portal_settings['office_travelreimburse_cents_homework_incl']);
// cents -> euros
$amountExcl /= 100;
$amountIncl /= 100;
ob_start();
?>
= __('travelReimburse') ?>
|
= __('date') ?>:
|
= date('d/m/Y', strtotime($lastDay)); ?> |
|
= __('full_name') ?>:
|
= htmlspecialchars($_SESSION['user']['user_full_name']); ?> |
|
= __('invoice_number') ?>:
|
= $invoiceNumber; ?> |
|
= __('total_travel_excl') ?>:
|
€ = number_format($amountExcl, 2, ',', '.'); ?> |
|
= __('total_travel_incl') ?>:
|
€ = number_format($amountIncl, 2, ',', '.'); ?> |
| = __('date') ?> |
= __('from') ?> |
= __('to') ?> |
= __('company') ?> |
KM = __('homework') ?> |
KM = __('business') ?> |
= __('description') ?> |
| = date('d-m-Y', strtotime($trip['travel_date'])); ?> |
= htmlspecialchars($trip['departure_postcode']); ?> |
= htmlspecialchars($trip['destination_postcode']); ?> |
= htmlspecialchars($trip['office_travelreimburse_company_name']); ?> |
= ($trip['homework'] ? $trip['travel_distance'] : '') ?> |
= ($trip['homework'] ? '' : $trip['travel_distance']) ?> |
= $trip['travel_description']; ?> |
|
= __('total') . ' ' . __('business') ?> km
|
= $totalBusinessKm; ?>
|
|
|
= __('total') . ' ' . __('homework') ?> km
|
= $totalHomeworkKm; ?>
|
|
|
= __('total') ?>
|
= $totalKm; ?>
|
|
set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdfFile = sys_get_temp_dir() . '/travel_reimburse.pdf';
file_put_contents(
$pdfFile,
$dompdf->output()
);
$mail = new mailBuilder();
$mail->addAddress($_SESSION['user']['user_email'], $_SESSION['user']['user_full_name']);
$mail->subject = 'Travel reimbursement ' . $_SESSION['user']['user_full_name'] . ' - ' . $invoiceNumber;
$mail->mailText = 'Your travel reimbursement is attached.';
try {
$mail->addAttachment($pdfFile, 'travel_reimbursement.pdf');
} catch (\PHPMailer\PHPMailer\Exception $e) {
}
$mail->sendMail();
unlink($pdfFile);
}