0 sein');
$allowedMethods = ['cash','bank','paypal','card','other'];
if (!in_array($method, $allowedMethods, true)) $method = 'bank';
if ($id > 0) {
$stmt = $pdo->prepare("
UPDATE finance_expenses
SET date=:date, category=:category, title=:title, amount_eur=:amount, method=:method, notes=:notes
WHERE id=:id
");
$stmt->execute([
':date'=>$date, ':category'=>$category, ':title'=>$title, ':amount'=>$amount, ':method'=>$method, ':notes'=>$notes, ':id'=>$id
]);
} else {
$stmt = $pdo->prepare("
INSERT INTO finance_expenses (date, category, title, amount_eur, method, notes)
VALUES (:date,:category,:title,:amount,:method,:notes)
");
$stmt->execute([
':date'=>$date, ':category'=>$category, ':title'=>$title, ':amount'=>$amount, ':method'=>$method, ':notes'=>$notes
]);
$id = (int)$pdo->lastInsertId();
}
echo json_encode(['ok'=>true,'id'=>$id], JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
http_response_code(400);
echo json_encode(['ok'=>false,'error'=>$e->getMessage()]);
}
d:/anjuma-dashboard/api/finance_expenses_delete.php
prepare("DELETE FROM finance_expenses WHERE id=:id");
$stmt->execute([':id'=>$id]);
echo json_encode(['ok'=>true], JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
http_response_code(400);
echo json_encode(['ok'=>false,'error'=>$e->getMessage()]);
}
d:/anjuma-dashboard/api/invoice_create_from_termin.php
prepare("SELECT * FROM termine WHERE id=:id");
$st->execute([':id' => $terminId]);
$t = $st->fetch(PDO::FETCH_ASSOC);
if (!$t) {
throw new RuntimeException('Termin nicht gefunden');
}
// Prüfen ob Rechnung existiert
$st = $pdo->prepare("SELECT id FROM invoices WHERE termine_id=:tid LIMIT 1");
$st->execute([':tid' => $terminId]);
if ($st->fetch()) {
throw new RuntimeException('Für diesen Termin existiert bereits eine Rechnung.');
}
$serviceDate = date('Y-m-d', (int)$t['startzeit']);
$invoiceDate = date('Y-m-d');
$dueDate = date('Y-m-d', strtotime($invoiceDate . ' +14 days'));
$year = (int)date('Y');
$invoiceNo = nextInvoiceNo($pdo, $year);
$customerName = trim($_POST['customer_name'] ?? 'Kunde (bitte bearbeiten)');
$customerStreet = trim($_POST['customer_street'] ?? '');
$customerZip = trim($_POST['customer_zip'] ?? '');
$customerCity = trim($_POST['customer_city'] ?? '');
$customerCountry = trim($_POST['customer_country'] ?? 'DE');
$gage = (int)($t['gage'] ?? 0);
$desc = "DJ-Leistung am " . date('d.m.Y', (int)$t['startzeit']);
$pdo->beginTransaction();
$pdo->prepare("
INSERT INTO invoices
(invoice_no, invoice_date, service_date, due_date, status,
customer_name, customer_street, customer_zip, customer_city, customer_country,
termine_id, amount_net_eur)
VALUES
(:no, :invdate, :servdate, :duedate, 'draft',
:cname, :cstreet, :czip, :ccity, :ccountry,
:tid, :amount)
")->execute([
':no' => $invoiceNo,
':invdate' => $invoiceDate,
':servdate' => $serviceDate,
':duedate' => $dueDate,
':cname' => $customerName,
':cstreet' => $customerStreet,
':czip' => $customerZip,
':ccity' => $customerCity,
':ccountry' => $customerCountry,
':tid' => $terminId,
':amount' => $gage
]);
$invoiceId = (int)$pdo->lastInsertId();
$pdo->prepare("
INSERT INTO invoice_items
(invoice_id, pos, description, qty, unit_price_eur, line_total_eur)
VALUES
(:iid, 1, :d, 1, :p, :p)
")->execute([
':iid' => $invoiceId,
':d' => $desc,
':p' => $gage
]);
$pdo->commit();
echo json_encode([
'ok' => true,
'invoice_id' => $invoiceId,
'invoice_no' => $invoiceNo
], JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
if ($pdo && $pdo->inTransaction()) $pdo->rollBack();
http_response_code(400);
echo json_encode([
'ok' => false,
'error' => $e->getMessage()
], JSON_UNESCAPED_UNICODE);
}