1) user invitation 2) app access control 3) txn quota guard
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
* Lifecycle:
|
||||
* post() — first-time GL creation; throws if a record already exists.
|
||||
* replace() — snapshot current lines into td_gl.history, then delete + re-insert.
|
||||
* delete() — hard-delete both td_gl and all its td_gl_item rows (used on void).
|
||||
* delete() — create a reversal journal entry (audit trail), then hard-delete the original.
|
||||
*/
|
||||
class GlManager
|
||||
{
|
||||
@@ -213,7 +213,8 @@ class GlManager
|
||||
public function delete(string $source_type, int $source_id): void
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT id, journal_date, period FROM td_gl
|
||||
"SELECT id, reference, description, journal_date, period, formula_id
|
||||
FROM td_gl
|
||||
WHERE company_id = :cid
|
||||
AND source_type = :source_type
|
||||
AND source_id = :source_id
|
||||
@@ -229,7 +230,40 @@ class GlManager
|
||||
if (!$gl_id) return;
|
||||
|
||||
$journal_date = $this->resolveJournalDate($gl['journal_date'] ?? null, (string)($gl['period'] ?? ''));
|
||||
$this->assertPostingWindow($journal_date, 'GL posting deletion');
|
||||
$this->assertPostingWindow($journal_date, 'GL void');
|
||||
|
||||
$original_lines = $this->getLines($gl_id);
|
||||
|
||||
if (!empty($original_lines)) {
|
||||
$reversal_lines = array_map(fn($line) => [
|
||||
'account_code' => $line['account_code'],
|
||||
'department_id' => (int)$line['department_id'],
|
||||
'debit' => (float)$line['credit'],
|
||||
'credit' => (float)$line['debit'],
|
||||
'description' => 'VOID: ' . $line['description'],
|
||||
], $original_lines);
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$this->pdo->prepare(
|
||||
"INSERT INTO td_gl
|
||||
(company_id, source_type, source_id, reference, description, journal_date,
|
||||
formula_id, period, current_version, history, created_at, updated_at)
|
||||
VALUES
|
||||
(:cid, 'reversal', :source_id, :reference, :description, :journal_date,
|
||||
:formula_id, :period, 1, '[]', :created_at, :updated_at)"
|
||||
)->execute([
|
||||
':cid' => $this->companyId,
|
||||
':source_id' => $gl_id,
|
||||
':reference' => 'VOID/' . ($gl['reference'] ?? ''),
|
||||
':description' => 'Void: ' . ($gl['description'] ?? ''),
|
||||
':journal_date' => $journal_date,
|
||||
':formula_id' => (int)($gl['formula_id'] ?? 0),
|
||||
':period' => $gl['period'] ?? '',
|
||||
':created_at' => $now,
|
||||
':updated_at' => $now,
|
||||
]);
|
||||
$this->insertLines((int)$this->pdo->lastInsertId(), $reversal_lines);
|
||||
}
|
||||
|
||||
$this->pdo->prepare(
|
||||
"DELETE FROM td_gl_item WHERE company_id = :cid AND gl_id = :gl_id"
|
||||
|
||||
Reference in New Issue
Block a user