103 lines
3.0 KiB
PHP
103 lines
3.0 KiB
PHP
<?php
|
|
|
|
class VatgroupController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
if(!$me->is(["Admin"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
|
|
protected function indexAction() {
|
|
$vatgroups = VatgroupModel::getAll();
|
|
$this->layout()->set("vatgroups", $vatgroups);
|
|
}
|
|
|
|
protected function addGroupAction() {
|
|
$name = $this->request->group_name;
|
|
if(!$name) {
|
|
$this->layout()->setFlash("Bitte einen Namen angeben!", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
if(VatgroupModel::getFirst(["name" => $name])) {
|
|
$this->layout()->setFlash("Eine Steuersatzgruppe mit diesem Namen ist bereits vorhanden!", "warning");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
$group = VatgroupModel::create([
|
|
"name" => $name
|
|
]);
|
|
|
|
if(!$group->save()) {
|
|
$this->layout()->setFlash("Fehler beim Anlegen der Steuersatzgruppe!", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
$this->layout()->setFlash("Steuersatzgruppe erfolgreic erstellt!", "success");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
protected function saveAction() {
|
|
$id = $this->request->id;
|
|
if(!is_numeric($id) || $id < 1) {
|
|
$this->layout()->setFlash("Ungültige Steuersatzgruppe", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
$group = new Vatgroup($id);
|
|
if(!$group->id) {
|
|
$this->layout()->setFlash("Ungültige Steuersatzgruppe", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
foreach($this->request->rates as $area => $rate) {
|
|
if(!$rate['account'] && !$rate['rate']) continue;
|
|
|
|
if(!$area || !array_key_exists($area, TT_VATRATE_AREAS)) {
|
|
$this->layout()->setFlash("Ungültiges Zielland", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
$data = [];
|
|
$data["vatgroup_id"] = $group->id;
|
|
$data["area"] = $area;
|
|
$data["account"] = trim($rate["account"]);
|
|
$data["rate"] = str_replace(",",".", trim($rate["rate"]));
|
|
$data["invoice_text"] = (trim($rate["invoice_text"])) ? trim($rate["invoice_text"]) : null;
|
|
|
|
if(!$data["account"] || !is_numeric($data["account"])) {
|
|
$this->layout()->setFlash("Ungültige Erlöskontonummer", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
if(!is_numeric($data["rate"])) {
|
|
$this->layout()->setFlash("Ungültiger Steuersatz", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
|
|
$vatrate = VatrateModel::getFirst(["vatgroup_id" => $group->id, "area" => $area]);
|
|
if($vatrate) {
|
|
$vatrate->update($data);
|
|
} else {
|
|
$vatrate = VatrateModel::create($data);
|
|
}
|
|
|
|
if(!$vatrate->save()) {
|
|
$this->layout()->setFlash("Fehler beim Speichern eines Steuersatzes", "error");
|
|
$this->redirect("Vatgroup");
|
|
}
|
|
}
|
|
|
|
$this->layout()->setFlash("Steuersätze erfolgreich gespeichert", "success");
|
|
$this->redirect("Vatgroup");
|
|
|
|
}
|
|
|
|
} |