Teilnehmerauswertung auf Ledger-Lesemodell umstellen
This commit is contained in:
@@ -265,6 +265,60 @@ function ledger_fetch_participant_summary_by_legacy_id(PDO $pdo, int $tenantId,
|
||||
return $summaries[0] ?? null;
|
||||
}
|
||||
|
||||
function ledger_mirror_legacy_consumption(PDO $pdo, int $tenantId, int $legacyConsumptionId): void
|
||||
{
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO ledger_entries
|
||||
(tenant_id, participant_id, type, amount_cents, marks_count,
|
||||
unit_price_cents, booked_at, source, note, legacy_table, legacy_id)
|
||||
SELECT
|
||||
p.tenant_id,
|
||||
p.id,
|
||||
'consumption',
|
||||
-CAST(ROUND(v.Kosten * 100) AS SIGNED),
|
||||
v.AnzahlStriche,
|
||||
CAST(ROUND(v.KostenproStrich * 100) AS SIGNED),
|
||||
v.Datum,
|
||||
CASE
|
||||
WHEN v.Eintragsart = 2 THEN 'legacy_web'
|
||||
ELSE 'legacy_manual'
|
||||
END,
|
||||
CASE
|
||||
WHEN v.Eintragsart IS NULL THEN NULL
|
||||
ELSE CONCAT('Legacy Eintragsart: ', v.Eintragsart)
|
||||
END,
|
||||
'kl_Kaffeeverbrauch',
|
||||
v.VerbrauchID
|
||||
FROM kl_Kaffeeverbrauch v
|
||||
JOIN participants p
|
||||
ON p.tenant_id = ?
|
||||
AND p.legacy_mitarbeiter_id = v.MitarbeiterID
|
||||
WHERE v.VerbrauchID = ?
|
||||
ON DUPLICATE KEY UPDATE
|
||||
participant_id = VALUES(participant_id),
|
||||
type = VALUES(type),
|
||||
amount_cents = VALUES(amount_cents),
|
||||
marks_count = VALUES(marks_count),
|
||||
unit_price_cents = VALUES(unit_price_cents),
|
||||
booked_at = VALUES(booked_at),
|
||||
source = VALUES(source),
|
||||
note = VALUES(note)"
|
||||
);
|
||||
$stmt->execute([$tenantId, $legacyConsumptionId]);
|
||||
|
||||
$check = $pdo->prepare(
|
||||
"SELECT COUNT(*)
|
||||
FROM ledger_entries
|
||||
WHERE tenant_id = ?
|
||||
AND legacy_table = 'kl_Kaffeeverbrauch'
|
||||
AND legacy_id = ?"
|
||||
);
|
||||
$check->execute([$tenantId, $legacyConsumptionId]);
|
||||
if ((int)$check->fetchColumn() !== 1) {
|
||||
throw new RuntimeException('Der Legacy-Strich konnte nicht ins Ledger gespiegelt werden.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options:
|
||||
* - participant_id: int
|
||||
|
||||
Reference in New Issue
Block a user