accounting workflows
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require_role($user_role, ['owner', 'admin', 'staff']);
|
||||
require '../../../assets/utils/classes_ac/AccountFormulaManager.php';
|
||||
|
||||
try {
|
||||
$mgr = new AccountFormulaManager($pdo2, $company_id);
|
||||
$action = $data['action'] ?? ($_POST['action'] ?? 'read');
|
||||
|
||||
if ($action === 'get_by_type') {
|
||||
$doc_type = trim((string)($data['document_type'] ?? ''));
|
||||
if (!$doc_type) throw new Exception('document_type is required.');
|
||||
$answer['output'] = $mgr->getByType($doc_type);
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'retrieve') {
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
$row = $mgr->getById($id);
|
||||
if (!$row) throw new Exception('Formula not found.');
|
||||
$answer['output'] = $row;
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'save') {
|
||||
$new_id = null;
|
||||
dbTransaction($pdo2, function($pdo) use ($data, $company_id, &$new_id) {
|
||||
$mgr = new AccountFormulaManager($pdo, $company_id);
|
||||
$new_id = $mgr->save($data);
|
||||
});
|
||||
$answer['new_id'] = $new_id;
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Formula saved.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($action === 'delete') {
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
if ($id <= 0) throw new Exception('Missing formula id.');
|
||||
$mgr->delete($id);
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Formula disabled.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$answer['output'] = $mgr->getAll();
|
||||
$answer['success'] = 1;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$answer['message'] = 'Database error, please try again.';
|
||||
http_response_code(500);
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/OperationLockManager.php';
|
||||
|
||||
try {
|
||||
$lock_manager = new OperationLockManager($pdo2, $company_id, $user_id);
|
||||
$result = $lock_manager->acquire(
|
||||
trim((string)($data['operation_type'] ?? '')),
|
||||
(int)($data['ttl_minutes'] ?? 120)
|
||||
);
|
||||
$answer = array_merge($answer, $result);
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/FinancialReports.php';
|
||||
|
||||
$as_of_date = trim((string)($data['as_of_date'] ?? ($data['as_of_period'] ?? date('Y-m-d'))));
|
||||
$dept_id = (int)($data['department_id'] ?? 0);
|
||||
|
||||
$reports = new FinancialReports($pdo2, $company_id);
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['output'] = $reports->getBalanceSheet($as_of_date, $dept_id);
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/GlQueryManager.php';
|
||||
|
||||
try {
|
||||
$gl_query = new GlQueryManager($pdo2, $company_id);
|
||||
$answer['output'] = $gl_query->getPostableDocuments(
|
||||
trim((string)($data['doc_type'] ?? '')),
|
||||
trim((string)($data['date_from'] ?? '')),
|
||||
trim((string)($data['date_to'] ?? '')),
|
||||
(int)($data['formula_id'] ?? 0)
|
||||
);
|
||||
$answer['success'] = 1;
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/FinancialReports.php';
|
||||
|
||||
$account_code = trim((string)($data['account_code'] ?? ''));
|
||||
$from_date = trim((string)($data['from_date'] ?? ($data['from_period'] ?? date('Y-m-d'))));
|
||||
$to_date = trim((string)($data['to_date'] ?? ($data['to_period'] ?? $from_date)));
|
||||
$dept_id = (int)($data['department_id'] ?? 0);
|
||||
|
||||
if ($account_code === '') {
|
||||
$answer['message'] = 'account_code is required.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$reports = new FinancialReports($pdo2, $company_id);
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['output'] = $reports->getGLMovement($account_code, $from_date, $to_date, $dept_id);
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/GlQueryManager.php';
|
||||
|
||||
try {
|
||||
$gl_query = new GlQueryManager($pdo2, $company_id);
|
||||
$answer['output'] = $gl_query->getJournalDetail((int)($data['gl_id'] ?? 0));
|
||||
$answer['success'] = 1;
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/GlQueryManager.php';
|
||||
|
||||
try {
|
||||
$gl_query = new GlQueryManager($pdo2, $company_id);
|
||||
$answer['output'] = $gl_query->getJournalListing(
|
||||
trim((string)($data['source_type'] ?? '')),
|
||||
trim((string)($data['date_from'] ?? '')),
|
||||
trim((string)($data['date_to'] ?? ''))
|
||||
);
|
||||
$answer['success'] = 1;
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/FinancialReports.php';
|
||||
|
||||
$from_date = trim((string)($data['from_date'] ?? ($data['from_period'] ?? date('Y-m-d'))));
|
||||
$to_date = trim((string)($data['to_date'] ?? ($data['to_period'] ?? $from_date)));
|
||||
$dept_id = (int)($data['department_id'] ?? 0);
|
||||
|
||||
$reports = new FinancialReports($pdo2, $company_id);
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['output'] = $reports->getProfitAndLoss($from_date, $to_date, $dept_id);
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/FinancialReports.php';
|
||||
|
||||
$from_date = trim((string)($data['from_date'] ?? ($data['from_period'] ?? date('Y-m-d'))));
|
||||
$to_date = trim((string)($data['to_date'] ?? ($data['to_period'] ?? $from_date)));
|
||||
$dept_id = (int)($data['department_id'] ?? 0);
|
||||
|
||||
$reports = new FinancialReports($pdo2, $company_id);
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['output'] = $reports->getTrialBalance($from_date, $to_date, $dept_id);
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/TaxReportManager.php';
|
||||
|
||||
$from_date = trim((string)($data['from_date'] ?? ($data['from_period'] ?? date('Y-m-d'))));
|
||||
$to_date = trim((string)($data['to_date'] ?? ($data['to_period'] ?? $from_date)));
|
||||
$dept_id = (int)($data['department_id'] ?? 0);
|
||||
$categories = $data['categories'] ?? [];
|
||||
if (is_string($categories)) {
|
||||
$decoded = json_decode($categories, true);
|
||||
$categories = is_array($decoded) ? $decoded : [$categories];
|
||||
}
|
||||
if (!is_array($categories)) $categories = [];
|
||||
|
||||
$tax = new TaxReportManager($pdo2, $company_id);
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['output'] = $tax->getVATReport($from_date, $to_date, $categories, $dept_id);
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/BatchActionManager.php';
|
||||
|
||||
try {
|
||||
$batch_action = new BatchActionManager($pdo2, $company_id, $user_id);
|
||||
$batch_action->log($data);
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Batch action logged.';
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/PeriodManager.php';
|
||||
|
||||
$pm = new PeriodManager($pdo2, $company_id);
|
||||
$action = $data['action_type'] ?? '';
|
||||
|
||||
if ($action === 'create_year') {
|
||||
$year = (int)($data['year'] ?? date('Y'));
|
||||
if ($year < 2000 || $year > 2100) exit(json_encode(['message' => 'Invalid year']));
|
||||
$pm->createYear($year);
|
||||
$answer['message'] = "All 12 periods for {$year} created";
|
||||
|
||||
} elseif ($action === 'create_single') {
|
||||
$period = $data['period'] ?? '';
|
||||
if (!preg_match('/^\d{4}-(0[1-9]|1[0-2])$/', $period)) {
|
||||
exit(json_encode(['message' => 'Invalid period format (YYYY-MM)']));
|
||||
}
|
||||
$pm->create($period);
|
||||
$answer['message'] = "Period {$period} created";
|
||||
|
||||
} elseif ($action === 'open') {
|
||||
$pm->open((int)($data['id'] ?? 0));
|
||||
$answer['message'] = 'Period reopened';
|
||||
|
||||
} elseif ($action === 'close') {
|
||||
$pm->close((int)($data['id'] ?? 0));
|
||||
$answer['message'] = 'Period closed';
|
||||
|
||||
} elseif ($action === 'lock') {
|
||||
$pm->lock((int)($data['id'] ?? 0));
|
||||
$answer['message'] = 'Period locked';
|
||||
|
||||
} else {
|
||||
exit(json_encode(['message' => 'Unknown action']));
|
||||
}
|
||||
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/PeriodManager.php';
|
||||
|
||||
$pm = new PeriodManager($pdo2, $company_id);
|
||||
$answer['output'] = $pm->getAll();
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/PeriodManager.php';
|
||||
|
||||
$pm = new PeriodManager($pdo2, $company_id);
|
||||
$stats = $pm->getStats();
|
||||
$answer = array_merge(['success' => 1], $stats);
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/PostingWindowGuard.php';
|
||||
require '../../../assets/utils/classes_ac/GlManager.php';
|
||||
require '../../../assets/utils/classes_ac/posting/BasePosting.php';
|
||||
require '../../../assets/utils/classes_ac/posting/InvoicePosting.php';
|
||||
require '../../../assets/utils/classes_ac/posting/CreditNotePosting.php';
|
||||
require '../../../assets/utils/classes_ac/posting/PurchaseInvoicePosting.php';
|
||||
require '../../../assets/utils/classes_ac/posting/SupplierCreditNotePosting.php';
|
||||
require '../../../assets/utils/classes_ac/posting/ReceiptPosting.php';
|
||||
require '../../../assets/utils/classes_ac/posting/PaymentPosting.php';
|
||||
require '../../../assets/utils/classes_ac/posting/PurchasePosting.php';
|
||||
|
||||
$doc_type = trim((string)($data['doc_type'] ?? ''));
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
$formula_id = (int)($data['formula_id'] ?? 0) ?: null;
|
||||
|
||||
$posting_map = [
|
||||
'invoice' => InvoicePosting::class,
|
||||
'credit_note' => CreditNotePosting::class,
|
||||
'purchase_invoice' => PurchaseInvoicePosting::class,
|
||||
'supplier_credit_note' => SupplierCreditNotePosting::class,
|
||||
'receipt' => ReceiptPosting::class,
|
||||
'payment' => PaymentPosting::class,
|
||||
'purchase_order' => PurchasePosting::class,
|
||||
];
|
||||
|
||||
if (!isset($posting_map[$doc_type]) || $id <= 0) {
|
||||
$answer['message'] = 'Invalid doc_type or id.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
try {
|
||||
$posting_class = $posting_map[$doc_type];
|
||||
$posting = new $posting_class($pdo2, $company_id);
|
||||
$built = $posting->build($id, $formula_id);
|
||||
|
||||
$guard = new PostingWindowGuard($pdo1, $company_id);
|
||||
$gl = new GlManager($pdo2, $company_id, $guard);
|
||||
$meta = ['journal_date' => $built['doc_date'] ?? null];
|
||||
|
||||
$pdo2->beginTransaction();
|
||||
|
||||
$existing = $gl->getBySource($doc_type, $id);
|
||||
if ($existing) {
|
||||
$gl->replace($doc_type, $id, $built['formula_id'], $built['period'], $built['lines'], $meta);
|
||||
} else {
|
||||
$gl->post($doc_type, $id, $built['formula_id'], $built['period'], $built['lines'], $meta);
|
||||
}
|
||||
|
||||
$pdo2->commit();
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = $existing ? 'GL entry replaced.' : 'GL entry posted.';
|
||||
|
||||
} catch (Exception $e) {
|
||||
if ($pdo2->inTransaction()) $pdo2->rollBack();
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/CompanySettingManager.php';
|
||||
require_role($user_role, ['owner', 'admin']);
|
||||
|
||||
$csm = new CompanySettingManager($pdo1, $company_id);
|
||||
|
||||
if ($data['action'] === 'read') {
|
||||
$open_from = $csm->get('posting_open_from');
|
||||
if ($open_from === null || $open_from === '') {
|
||||
$open_from = $csm->get('gl_open_from') ?: '';
|
||||
}
|
||||
|
||||
$open_to = $csm->get('posting_open_to');
|
||||
if ($open_to === null || $open_to === '') {
|
||||
$open_to = $csm->get('gl_open_to') ?: '';
|
||||
}
|
||||
|
||||
$answer['output'] = [
|
||||
'open_from' => $open_from ?: '',
|
||||
'open_to' => $open_to ?: '',
|
||||
];
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($data['action'] === 'save') {
|
||||
$from = trim((string)($data['open_from'] ?? ''));
|
||||
$to = trim((string)($data['open_to'] ?? ''));
|
||||
|
||||
if ($from !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) {
|
||||
$answer['message'] = 'Invalid open_from date. Use YYYY-MM-DD.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
if ($to !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) {
|
||||
$answer['message'] = 'Invalid open_to date. Use YYYY-MM-DD.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
if ($from && $to && $from > $to) {
|
||||
$answer['message'] = 'Open From must be on or before Open To.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$csm->set('posting_open_from', $from);
|
||||
$csm->set('posting_open_to', $to);
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Posting window saved.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$answer['message'] = 'Invalid action.';
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/ProductManager.php';
|
||||
require '../../../assets/utils/classes_ac/ChartOfAccounts.php';
|
||||
|
||||
require_role($user_role, ['owner', 'admin']);
|
||||
|
||||
try {
|
||||
$id = (int)($data['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
throw new Exception('Product is required.');
|
||||
}
|
||||
|
||||
$sales_account_code = trim((string)($data['sales_account_code'] ?? '')) ?: null;
|
||||
$purchase_account_code = trim((string)($data['purchase_account_code'] ?? '')) ?: null;
|
||||
|
||||
$coa = new ChartOfAccounts($pdo2, $company_id);
|
||||
foreach ([
|
||||
'Sales account' => $sales_account_code,
|
||||
'Purchase account' => $purchase_account_code,
|
||||
] as $label => $account_code) {
|
||||
if ($account_code !== null && !$coa->isPostingAccount($account_code)) {
|
||||
throw new Exception($label . ' must be an active posting account.');
|
||||
}
|
||||
}
|
||||
|
||||
dbTransaction($pdo2, function($pdo) use ($company_id, $id, $sales_account_code, $purchase_account_code, $logging) {
|
||||
$product = new ProductManager($pdo, $company_id);
|
||||
$product->updateAccountMapping($id, $sales_account_code, $purchase_account_code, $logging);
|
||||
});
|
||||
|
||||
$answer['success'] = 1;
|
||||
|
||||
} catch (Exception $e) {
|
||||
$answer['success'] = 0;
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/OperationLockManager.php';
|
||||
|
||||
try {
|
||||
$lock_manager = new OperationLockManager($pdo2, $company_id, $user_id);
|
||||
$lock_manager->release(trim((string)($data['operation_type'] ?? '')));
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Lock released.';
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/PostingWindowGuard.php';
|
||||
require '../../../assets/utils/classes_ac/GlManager.php';
|
||||
|
||||
$gl_id = (int)($data['gl_id'] ?? 0);
|
||||
$reference = trim((string)($data['reference'] ?? ''));
|
||||
$description = trim((string)($data['description'] ?? ''));
|
||||
$journal_date = trim((string)($data['journal_date'] ?? ''));
|
||||
$lines_raw = $data['lines'] ?? [];
|
||||
|
||||
if (is_string($lines_raw)) {
|
||||
$lines_raw = json_decode($lines_raw, true) ?: [];
|
||||
}
|
||||
|
||||
// Convert d/m/Y → Y-m-d
|
||||
if (preg_match('#^(\d{2})/(\d{2})/(\d{4})$#', $journal_date, $m)) {
|
||||
$journal_date = "{$m[3]}-{$m[2]}-{$m[1]}";
|
||||
}
|
||||
|
||||
if (!$journal_date || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $journal_date)) {
|
||||
$answer['message'] = 'Valid journal date is required.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$period = substr($journal_date, 0, 7); // YYYY-MM
|
||||
|
||||
// Validate and normalise lines
|
||||
$lines = [];
|
||||
$total_debit = 0;
|
||||
$total_credit = 0;
|
||||
|
||||
foreach ($lines_raw as $l) {
|
||||
$account_code = trim((string)($l['account_code'] ?? ''));
|
||||
$debit = (float)($l['debit'] ?? 0);
|
||||
$credit = (float)($l['credit'] ?? 0);
|
||||
$desc = trim((string)($l['description'] ?? ''));
|
||||
|
||||
if ($account_code === '') continue;
|
||||
if ($debit == 0 && $credit == 0) continue;
|
||||
|
||||
$lines[] = ['account_code' => $account_code, 'department_id' => 0, 'debit' => $debit, 'credit' => $credit, 'description' => $desc];
|
||||
$total_debit += $debit;
|
||||
$total_credit += $credit;
|
||||
}
|
||||
|
||||
if (count($lines) < 2) {
|
||||
$answer['message'] = 'At least two journal lines are required.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if (abs($total_debit - $total_credit) > 0.005) {
|
||||
$answer['message'] = 'Journal is not balanced. Debit ' . number_format($total_debit, 2) . ' ≠ Credit ' . number_format($total_credit, 2) . '.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo2->beginTransaction();
|
||||
$guard = new PostingWindowGuard($pdo1, $company_id);
|
||||
$gl = new GlManager($pdo2, $company_id, $guard);
|
||||
|
||||
if ($gl_id > 0) {
|
||||
$gl->replaceManual($gl_id, $reference, $description, $journal_date, $period, $lines);
|
||||
$answer['message'] = 'Journal entry updated.';
|
||||
} else {
|
||||
$gl_id = $gl->postManual($reference, $description, $journal_date, $period, $lines);
|
||||
$answer['message'] = 'Journal entry saved.';
|
||||
}
|
||||
|
||||
$pdo2->commit();
|
||||
$answer['success'] = 1;
|
||||
$answer['gl_id'] = $gl_id;
|
||||
} catch (Exception $e) {
|
||||
if ($pdo2->inTransaction()) $pdo2->rollBack();
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
Reference in New Issue
Block a user