Files
thetool/application/TimerecordingBilling/TimerecordingBillingController.php
Spitzer Daniel c3ebfdfd2a Zeiterfassungs Update
* neue Migration für Personaladministration (Aktive Verrechnung)
 * Verrechnung Anpassungen Black P.
 * superexpertEnabled Implementation Verrechnung/Personaladministration
 * Personaladministration (Aktive Verrechnung/Zeiterfassung Enddatum)
2024-04-01 17:35:38 +02:00

187 lines
6.5 KiB
PHP

<?php
class TimerecordingBillingController extends mfBaseController
{
protected function init()
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->can(["Fibu"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$startdate = 1709254800;
$today = time();
$months = [];
$month = $startdate;
while ($month < $today) {
$months[] = date("m.Y", $month);
$month = strtotime("+1 month", $month);
}
$this->layout()->set("months", $months);
$this->layout()->setTemplate("TimerecordingBilling/Index");
}
protected function detailAction()
{
$r = $this->request;
$month = $r->get("month");
if (!$month) {
$this->redirect("TimerecordingBilling");
}
$month = strtotime("01." . $month);
$timerecordingsEmolyees = TimerecordingEmployeeModel::getAll();
foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) {
if ($timerecordingsEmolyee->bmd_active == 0) continue;
$user = new User($timerecordingsEmolyee->user_id);
$employee_number = (string)$user->getFlag('employee_number');
$timerecordingReport = new TimerecordingReportController();
$timerecordings[$timerecordingsEmolyee->user_id]['user_id'] = $timerecordingsEmolyee->user_id;
$timerecordings[$timerecordingsEmolyee->user_id]['user_name'] = $timerecordingsEmolyee->user->name;
$timerecordings[$timerecordingsEmolyee->user_id]['employee_number'] = $employee_number;
$timerecordings[$timerecordingsEmolyee->user_id]['data'] = $timerecordingReport->getTimerecordingsTimes('2', $month, $month, $month, $timerecordingsEmolyee->user_id, 0);
}
$this->layout()->set("timerecordings", $timerecordings);
$this->layout()->setTemplate("TimerecordingBilling/Detail");
$this->layout()->set("month", date("m.Y", $month));
}
protected function apiAction()
{
$do = $this->request->do;
$month = $this->request->month;
$data = [];
switch ($do) {
case "generatebmdexport":
$return = $this->generateBmdExport($month);
break;
case "generatebmdexportnlz":
$return = $this->generateBmdExport($month, 1);
break;
default:
$return = false;
}
if (!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
$data['status'] = "OK";
$data['result'] = $return;
$this->returnJson($data);
}
protected function addAction()
{
}
protected function editAction()
{
}
protected function saveAction()
{
}
protected function deleteAction()
{
}
protected function generateBmdLine()
{
}
protected function generateBmdExport($month, $nlz = 0)
{
//create and download csv file
$filename = "BMDExport_" . $month . ".csv";
$file = fopen("php://output", 'w');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $filename);
if ($nlz == 0) {
$headerarray = ["Monat", "Firma", "Mitarbeiter", "Lohnart", "Menge", "Satz", "Betrag", "Kostenstelle", "NLZ-Kennzeichen", "NLZ Von-Datum", "NLZ Bis-Datum"];
fputcsv($file, $headerarray, ";");
} else {
$headerarray = ["Firma", "Mitarbeiter", "DV-Nr", "Art", "Sonderzeit", "Verarbeitungs-KZ", "Von", "Bis", "Verwaltung", "Bezahlt"];
fputcsv($file, $headerarray, ";");
}
$month = strtotime("01." . $month);
$monthbmd = date("n", $month);
$companybmd = "1";
$timerecordingsEmolyees = TimerecordingEmployeeModel::getAll();
foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) {
if ($timerecordingsEmolyee->bmd_active == 0) continue;
$user = new User($timerecordingsEmolyee->user_id);
$employee_number = (string)$user->getFlag('employee_number');
$employeetypesbmd = TimerecordingEmployeeModel::$employeetypesbmd;
$employee_type = $employeetypesbmd[$timerecordingsEmolyee->type];
$timerecordingReport = new TimerecordingReportController();
$timerecording = $timerecordingReport->getTimerecordingsTimes('2', $month, $month, $month, $timerecordingsEmolyee->user_id, 0);
foreach ($timerecording['time']['isclean'] as $key => $value) {
$hours = $value;
//calc ishours in hours
$hours = $hours / 3600;
$hours = round($hours, 2);
$hours = str_replace(".", ",", $hours);
if (strpos($key, ',') !== false && $nlz == 0) {
$bodyarray = [$monthbmd, $companybmd, $employee_number, $employee_type, $hours, "", "", "", "", "", ""];
fputcsv($file, $bodyarray, ";");
} else if (strpos($key, ',') === false && $nlz == 1) {
}
}
if ($timerecording['time']['diet'] > 0 && $nlz == 0) {
$dietsum = round($timerecording['time']['diet'], 2);
$dietsum = str_replace(".", ",", $dietsum);
$bodyarray = [$monthbmd, $companybmd, $employee_number, "2500", "", "", $dietsum, "", "", "", ""];
fputcsv($file, $bodyarray, ";");
}
if (!empty($timerecording['time']['nlztimes']) && $nlz == 1) {
foreach ($timerecording['time']['nlztimes'] as $nlztime) {
if ($nlztime['minutes']) {
$time = $nlztime['minutes'] / 60;
$time = round($time, 2);
$time = str_replace(".", ",", $time);
if ($nlztime['unpaid'] == "0") {
$pay = $time;
} else {
$pay = 0;
}
} else {
$time = "";
$pay = "";
}
$bodyarray = [$companybmd, $employee_number, 1, $nlztime['categoryshort'], "", "3", $nlztime['start'], $nlztime['end'], $time, $pay];
fputcsv($file, $bodyarray, ";");
}
}
}
die();
}
}