filterByAktiv(true)->find(); foreach ($ma_lst as $ma) { // check, if the mitarbeiter is already present $lhn_abr_lst = LohnabrechnungQuery::create()->filterByMonat($month)->filterByMaId($ma->getId())->find(); if (count($lhn_abr_lst) == 0) { $lhn_abr = null; // check profil $lp = $ma->getLohnprofil(); switch ($lp->getLaTyp()->getValue()) { case LATyp::LAT_GERING: $lhn_abr = new LaGeringfugig(); break; case LATyp::LAT_KURZFR: $lhn_abr = new LaKurzfrist(); break; case LATyp::LAT_NORMAL: $lhn_abr = new LaNormal(); break; case LATyp::LAT_SOZ_BEFR: $lhn_abr = new LaSozialbefreit(); break; default: throw new Exception("Lohnprofil unbekannt: ".$lp->getName()); } $lhn_abr->setMitarbeiter($ma); $lhn_abr->setMonat($month); $lhn_abr->setLohnprofil($lp); $lhn_abr->save(); } } } public static function bruttoBerechnen ($month) { // check parameter if (strlen($month) != 6) throw new Exception ("Invalid month format. yyyymm expected."); // lese Abrechnungsliste $lhn_abr_lst = LohnabrechnungQuery::create()->filterByMonat($month)->find(); foreach ($lhn_abr_lst as $lhn_abr) { if ($lhn_abr->getLohnprofil()->getPeriode()->getValue() == Periode::PE_HOUR) { $lhn_abr->setBrutto( $lhn_abr->getMitarbeiter()->getBasisBetrag() * $lhn_abr->getArbeitsstunden() + $lhn_abr->getZulage() ); } else { $lhn_abr->setBrutto( $lhn_abr->getMitarbeiter()->getBasisBetrag() + $lhn_abr->getZulage() ); } $lhn_abr->save(); } } public static function calculateMonth ($month) { // check parameter if (strlen($month) != 6) throw new Exception ("Invalid month format. yyyymm expected."); // lese Abrechnungsliste $lhn_abr_lst = LohnabrechnungQuery::create()->filterByMonat($month)->find(); foreach ($lhn_abr_lst as $lhn_abr) { // lese Lohnprofil $lhn_prf = $lhn_abr->getLohnProfil(); // setze Brutto für Netto :-)) $lhn_abr->setNetto($lhn_abr->getBrutto()); $class = get_class($lhn_abr); switch ($class) { case "LaNormal": self::berechneSteuern($lhn_abr, $lhn_prf); self::berechneSozial($lhn_abr, $lhn_prf); break; case "LaSozialbefreit": case "LaKurzfrist": self::berechneSteuern($lhn_abr, $lhn_prf); break; case "LaGeringfugig": self::berechneGeringfugig($lhn_abr, $lhn_prf); break; default: throw new Exception("unknown class: $class"); } $lhn_abr->save(); } } public static function abrechnungenErstellen ($month) { // check parameter if (strlen($month) != 6) throw new Exception ("Invalid month format. yyyymm expected."); // Hole Konfigurationsdaten $config = Config::getInstance(); $tmp = $config->getConfig("TmpVerzeichnis", "/tmp"); // lese Abrechnungsliste $lhn_abr_lst = LohnabrechnungQuery::create()->filterByMonat($month)->find(); foreach ($lhn_abr_lst as $lhn_abr) { // lese Motarbeiter und Profil $ma = $lhn_abr->getMitarbeiter(); $lhn_prf = $lhn_abr->getLohnProfil(); // TODO $isLohn berechnen $isLohn = false; $name = $ma->getNachname() . $ma->getVorname(); if ($isLohn) { $txt_path = "$tmp/Lohn_$name.txt"; $pdf_path = "$tmp/Lohn_$name.pdf"; } else { $txt_path = "$tmp/Gehalt_$name.txt"; $pdf_path = "$tmp/Gehalt_$name.pdf"; } Lohnzettel::printLohnzettel($ma, $lhn_abr, $txt_path); // PDF-Konvertierung $path = preg_replace("/mLohn.*/", "mLohn", __FILE__); exec("$path/Lohn/etc/mPrint -pdf $txt_path", $out, $ret); if ($ret > 0) throw new Exception("PDF conversion failed: ".$path. implode("\n", $out)); // PDF-Overlay erzeugen $letter = $config->getConfig("LohnAdministration::Briefpapier"); if ($letter) { // prüfe, ob Briefpapier vorhanden if (!file_exists($letter)) throw new Exception("Letter $letter not existing"); // prüfe, ob pdftk überhaupt installiert exec("which pdftk", $out, $ret); if ($ret > 0) throw new Exception("PDF overlay failed. pdftk not installed."); exec("pdftk $pdf_path background $letter output $tmp/tmp.pdf", $out, $ret); if ($ret > 0) throw new Exception("PDF overlay failed:\n". implode("\n", $out)); exec("mv $tmp/tmp.pdf $pdf_path", $out, $ret); if ($ret > 0) throw new Exception("PDF rename failed: ". implode("\n", $out)); } /* Variante mit pdftkd // PDF-Overlay erzeugen $letter = $config->getConfig("LohnAdministration::Briefpapier"); if ($letter) { // create socket if (! $socket = socket_create(AF_UNIX, SOCK_STREAM, 0)) throw new Exception("Could not create socket\n"); // connect to server $sock_file = "/var/mlohn/pdftkd.sock"; if (! $result = socket_connect($socket, $sock_file)) throw new Exception("Could not connect to server\n"); // send string to server LETTER;PDF_PATH;TMP_DIR $message = "$letter;$pdf_path;$tmp"; if (! socket_write($socket, $message, strlen($message))) throw new Exception("Could not send data to server\n"); // get server response $result = socket_read ($socket, 1024); if ($result != 0) throw new Exception("pdftkd returned $result"); // close socket socket_close($socket); } */ } } public static function verschicken ($month) { // check parameter if (strlen($month) != 6) throw new Exception ("Invalid month format. yyyymm expected."); // Hole Konfigurationsdaten $config = Config::getInstance(); $tmp = $config->getConfig("TmpVerzeichnis", "/tmp"); // get cc address $cc_adress = $config->getConfig("MailCCAddress"); // lese Abrechnungsliste $lhn_abr_lst = LohnabrechnungQuery::create()->filterByMonat($month)->find(); foreach ($lhn_abr_lst as $lhn_abr) { // lese Motarbeiter und Profil $ma = $lhn_abr->getMitarbeiter(); $lhn_prf = $lhn_abr->getLohnProfil(); $isLohn = false; $name = $ma->getName(); if ($isLohn) { $txt_path = "$tmp/Lohn_$name.txt"; $pdf_path = "$tmp/Lohn_$name.pdf"; } else { $txt_path = "$tmp/Gehalt_$name.txt"; $pdf_path = "$tmp/Gehalt_$name.pdf"; } // send mail } } public static function agAnteileBerechnen ($month) { // check parameter if (strlen($month) != 6) throw new Exception ("Invalid month format. yyyymm expected."); // prüfe, ob Datensatz schon existiert $ag_btr = ArbeitgeberbtrQuery::create()->filterByMonat($month)->findOne(); if ($ag_btr !== null) //reset content $ag_btr->reset(); else { // create new $ag_btr = new Arbeitgeberbtr(); $ag_btr->setMonat($month); } // lese Abrechnungsliste $lhn_abr_lst = LohnabrechnungQuery::create()->filterByMonat($month)->find(); foreach ($lhn_abr_lst as $lhn_abr) { // lese Profil $lhn_prf = $lhn_abr->getLohnProfil(); if ($lhn_prf->getRentenversicherungAg() > 0) $ag_btr->setRentenversicherung($ag_btr->getRentenversicherung() + round($lhn_prf->getRentenversicherungAg() * $lhn_abr->getBrutto() / 100, 2)); if ($lhn_prf->getKrankenversicherungAg() > 0) $ag_btr->setKrankenversicherung($ag_btr->getKrankenversicherung() + round($lhn_prf->getKrankenversicherungAg() * $lhn_abr->getBrutto() / 100, 2)); if ($lhn_prf->getU1() > 0) $ag_btr->setU1($ag_btr->getU1() + round($lhn_prf->getU1() * $lhn_abr->getBrutto() / 100, 2)); if ($lhn_prf->getU2() > 0) $ag_btr->setU2($ag_btr->getU2() + round($lhn_prf->getU2() * $lhn_abr->getBrutto() / 100, 2)); if ($lhn_prf->getInso() > 0) $ag_btr->setInso($ag_btr->getInso() + round($lhn_prf->getInso() * $lhn_abr->getBrutto() / 100, 2)); if ($lhn_prf->getPauschalsteuer() > 0) $ag_btr->setPauschalsteuer($ag_btr->getPauschalsteuer() + round($lhn_prf->getPauschalsteuer() * $lhn_abr->getBrutto() / 100, 2)); } $ag_btr->save(); } public static function getMinijobBeitrage ($month, OutputFormatter $outForm) { // check parameter if (strlen($month) != 6) throw new Exception ("Invalid month format. yyyymm expected."); // initialise result $outForm->initResult(); $outForm->formatElement(OutputFormatter::FC_BEG, "MinijobBeitrage"); $outForm->formatElement(OutputFormatter::FC_SGL, "Monat", $month); // suche nach Arbeitgeberbeiträgen $ag_btr = ArbeitgeberbtrQuery::create()->filterByMonat($month)->findOne(); if ($ag_btr == null) throw new Exception("Data for Minijobbeitrage not found."); // suche nach Aufstockungsbeträgen $aufstockung = 0; $lhn_abr_lst = LohnabrechnungQuery::create()->filterByMonat($month)->find(); foreach ($lhn_abr_lst as $lhn_abr) { // lese Profil $lhn_prf = $lhn_abr->getLohnProfil(); if (($lhn_prf->getRentenversicherungAn() > 0) && ($lhn_prf->getLaTyp()->getValue() == LATyp::LAT_GERING)) { $aufstockung += $lhn_abr->getRentenversicherung(); } } $summe = 0; // format output $outForm->formatElement(OutputFormatter::FC_SGL, "Krankenversicherung", $ag_btr->getKrankenversicherung()); $summe += $ag_btr->getKrankenversicherung(); $outForm->formatElement(OutputFormatter::FC_SGL, "Rentenversicherung", $ag_btr->getRentenversicherung()+$aufstockung); $summe += $ag_btr->getRentenversicherung()+$aufstockung; $outForm->formatElement(OutputFormatter::FC_SGL, "U1", $ag_btr->getU1()); $summe += $ag_btr->getU1(); $outForm->formatElement(OutputFormatter::FC_SGL, "U2", $ag_btr->getU2()); $summe += $ag_btr->getU2(); $outForm->formatElement(OutputFormatter::FC_SGL, "Inso", $ag_btr->getInso()); $summe += $ag_btr->getInso(); $outForm->formatElement(OutputFormatter::FC_SGL, "Pauschalsteuer", $ag_btr->getPauschalsteuer()); $summe += $ag_btr->getPauschalsteuer(); $outForm->formatElement(OutputFormatter::FC_SGL, "Summe", $summe); // finish output $outForm->formatElement(OutputFormatter::FC_END); return; } private static function berechneSteuern(Lohnabrechnung $lhn_abr, Lohnprofil $lhn_prf) { if (!$lhn_prf->getKirchensteuerEv()) $lhn_abr->setKirchensteuerEv(0); if (!$lhn_prf->getKirchensteuerRk()) $lhn_abr->setKirchensteuerRk(0); $netto = $lhn_abr->getNetto() - $lhn_abr->getLohnsteuer() - $lhn_abr->getKirchensteuerEv() - $lhn_abr->getKirchensteuerRk() - $lhn_abr->getSoli(); $lhn_abr->setNetto($netto); } private static function berechneSozial(Lohnabrechnung $lhn_abr, Lohnprofil $lhn_prf) { $brutto = $lhn_abr->getBrutto(); $lhn_abr->setRentenversicherung($brutto * $lhn_prf->getRentenversicherungAn()); $lhn_abr->setKrankenversicherung($brutto * $lhn_prf->getKrankenversicherungAn()); $netto = $lhn_abr->getNetto() - $lhn_abr->getRentenversicherung() - $lhn_abr->getKrankenversicherung(); $lhn_abr->setNetto($netto); } private static function berechneGeringfugig(Lohnabrechnung $lhn_abr, Lohnprofil $lhn_prf) { $brutto = $lhn_abr->getBrutto(); $lhn_abr->setRentenversicherung($brutto * ($lhn_prf->getRentenversicherungAn()) / 100); $netto = $lhn_abr->getNetto() - $lhn_abr->getRentenversicherung(); $lhn_abr->setNetto($netto); } }