automate and view gl entries
This commit is contained in:
@@ -54,6 +54,30 @@
|
||||
(new UsageGuard($pdo1, $company_id, $packages))->increment();
|
||||
require_once '../../../assets/utils/notify_node.php';
|
||||
notify_node('payment_posted', ['id' => $new_id], $company_id);
|
||||
|
||||
// Auto-post GL
|
||||
try {
|
||||
require_once '../../../assets/utils/classes_ac/posting/BasePosting.php';
|
||||
require_once '../../../assets/utils/classes_ac/posting/PaymentPosting.php';
|
||||
$sth = $pdo2->prepare("SELECT formula_id FROM td_payment WHERE company_id = :cid AND id = :id LIMIT 1");
|
||||
$sth->execute([':cid' => $company_id, ':id' => $new_id]);
|
||||
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$posting = new PaymentPosting($pdo2, $company_id);
|
||||
$built = $posting->build($new_id, $row['formula_id'] ?: null);
|
||||
$guard = new PostingWindowGuard($pdo1, $company_id);
|
||||
$gl = new GlManager($pdo2, $company_id, $guard);
|
||||
$pdo2->beginTransaction();
|
||||
$gl->post('payment', $new_id, $built['formula_id'], $built['period'], $built['lines'], ['journal_date' => $built['doc_date']]);
|
||||
$pdo2->commit();
|
||||
notify_node('gl_posted', ['doc_type' => 'payment', 'id' => $new_id, 'action' => 'posted'], $company_id);
|
||||
$answer['gl_posted'] = true;
|
||||
} catch (Exception $e) {
|
||||
if ($pdo2->inTransaction()) $pdo2->rollBack();
|
||||
$answer['gl_posted'] = false;
|
||||
$answer['gl_message'] = $e->getMessage();
|
||||
error_log("auto_gl [payment#{$new_id}]: " . $e->getMessage());
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,30 @@
|
||||
(new UsageGuard($pdo1, $company_id, $packages))->increment();
|
||||
require_once '../../../assets/utils/notify_node.php';
|
||||
notify_node('receipt_posted', ['id' => $new_id], $company_id);
|
||||
|
||||
// Auto-post GL
|
||||
try {
|
||||
require_once '../../../assets/utils/classes_ac/posting/BasePosting.php';
|
||||
require_once '../../../assets/utils/classes_ac/posting/ReceiptPosting.php';
|
||||
$sth = $pdo2->prepare("SELECT formula_id FROM td_receipt WHERE company_id = :cid AND id = :id LIMIT 1");
|
||||
$sth->execute([':cid' => $company_id, ':id' => $new_id]);
|
||||
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$posting = new ReceiptPosting($pdo2, $company_id);
|
||||
$built = $posting->build($new_id, $row['formula_id'] ?: null);
|
||||
$guard = new PostingWindowGuard($pdo1, $company_id);
|
||||
$gl = new GlManager($pdo2, $company_id, $guard);
|
||||
$pdo2->beginTransaction();
|
||||
$gl->post('receipt', $new_id, $built['formula_id'], $built['period'], $built['lines'], ['journal_date' => $built['doc_date']]);
|
||||
$pdo2->commit();
|
||||
notify_node('gl_posted', ['doc_type' => 'receipt', 'id' => $new_id, 'action' => 'posted'], $company_id);
|
||||
$answer['gl_posted'] = true;
|
||||
} catch (Exception $e) {
|
||||
if ($pdo2->inTransaction()) $pdo2->rollBack();
|
||||
$answer['gl_posted'] = false;
|
||||
$answer['gl_message'] = $e->getMessage();
|
||||
error_log("auto_gl [receipt#{$new_id}]: " . $e->getMessage());
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user