accounting workflows
This commit is contained in:
@@ -13,7 +13,7 @@ class ChartOfAccounts
|
||||
public function getAll(): array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT * FROM ac_account
|
||||
"SELECT * FROM md_account
|
||||
WHERE company_id = :cid
|
||||
ORDER BY account_code ASC"
|
||||
);
|
||||
@@ -24,7 +24,7 @@ class ChartOfAccounts
|
||||
public function getByCode(string $account_code): ?array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT * FROM ac_account
|
||||
"SELECT * FROM md_account
|
||||
WHERE company_id = :cid AND account_code = :code
|
||||
LIMIT 1"
|
||||
);
|
||||
@@ -36,7 +36,7 @@ class ChartOfAccounts
|
||||
public function getByType(string $account_type): array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT * FROM ac_account
|
||||
"SELECT * FROM md_account
|
||||
WHERE company_id = :cid AND account_type = :type AND status = 1
|
||||
ORDER BY account_code ASC"
|
||||
);
|
||||
@@ -47,7 +47,7 @@ class ChartOfAccounts
|
||||
public function getById(int $id): ?array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT * FROM ac_account
|
||||
"SELECT * FROM md_account
|
||||
WHERE company_id = :cid AND id = :id
|
||||
LIMIT 1"
|
||||
);
|
||||
@@ -59,19 +59,20 @@ class ChartOfAccounts
|
||||
public function create(array $data): int
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"INSERT INTO ac_account
|
||||
(company_id, account_code, account_name, account_type, parent_code, is_posting, status)
|
||||
"INSERT INTO md_account
|
||||
(company_id, account_code, account_name, account_type, account_category, parent_code, is_posting, status)
|
||||
VALUES
|
||||
(:cid, :code, :name, :type, :parent, :posting, :status)"
|
||||
(:cid, :code, :name, :type, :category, :parent, :posting, :status)"
|
||||
);
|
||||
$sth->execute([
|
||||
':cid' => $this->companyId,
|
||||
':code' => trim($data['account_code']),
|
||||
':name' => trim($data['account_name']),
|
||||
':type' => $data['account_type'],
|
||||
':parent' => !empty($data['parent_code']) ? trim($data['parent_code']) : null,
|
||||
':posting' => (int)($data['is_posting'] ?? 1),
|
||||
':status' => (int)($data['status'] ?? 1),
|
||||
':cid' => $this->companyId,
|
||||
':code' => trim($data['account_code']),
|
||||
':name' => trim($data['account_name']),
|
||||
':type' => $data['account_type'],
|
||||
':category' => !empty($data['account_category']) ? trim($data['account_category']) : '',
|
||||
':parent' => !empty($data['parent_code']) ? trim($data['parent_code']) : null,
|
||||
':posting' => (int)($data['is_posting'] ?? 1),
|
||||
':status' => (int)($data['status'] ?? 1),
|
||||
]);
|
||||
return (int)$this->pdo->lastInsertId();
|
||||
}
|
||||
@@ -79,31 +80,33 @@ class ChartOfAccounts
|
||||
public function update(int $id, array $data): void
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"UPDATE ac_account SET
|
||||
account_code = :code,
|
||||
account_name = :name,
|
||||
account_type = :type,
|
||||
parent_code = :parent,
|
||||
is_posting = :posting,
|
||||
status = :status
|
||||
"UPDATE md_account SET
|
||||
account_code = :code,
|
||||
account_name = :name,
|
||||
account_type = :type,
|
||||
account_category = :category,
|
||||
parent_code = :parent,
|
||||
is_posting = :posting,
|
||||
status = :status
|
||||
WHERE company_id = :cid AND id = :id"
|
||||
);
|
||||
$sth->execute([
|
||||
':cid' => $this->companyId,
|
||||
':id' => $id,
|
||||
':code' => trim($data['account_code']),
|
||||
':name' => trim($data['account_name']),
|
||||
':type' => $data['account_type'],
|
||||
':parent' => !empty($data['parent_code']) ? trim($data['parent_code']) : null,
|
||||
':posting' => (int)($data['is_posting'] ?? 1),
|
||||
':status' => (int)($data['status'] ?? 1),
|
||||
':cid' => $this->companyId,
|
||||
':id' => $id,
|
||||
':code' => trim($data['account_code']),
|
||||
':name' => trim($data['account_name']),
|
||||
':type' => $data['account_type'],
|
||||
':category' => !empty($data['account_category']) ? trim($data['account_category']) : '',
|
||||
':parent' => !empty($data['parent_code']) ? trim($data['parent_code']) : null,
|
||||
':posting' => (int)($data['is_posting'] ?? 1),
|
||||
':status' => (int)($data['status'] ?? 1),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"UPDATE ac_account SET status = 0
|
||||
"UPDATE md_account SET status = 0
|
||||
WHERE company_id = :cid AND id = :id"
|
||||
);
|
||||
$sth->execute([':cid' => $this->companyId, ':id' => $id]);
|
||||
@@ -112,7 +115,7 @@ class ChartOfAccounts
|
||||
public function isPostingAccount(string $account_code): bool
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT is_posting FROM ac_account
|
||||
"SELECT is_posting FROM md_account
|
||||
WHERE company_id = :cid AND account_code = :code AND status = 1
|
||||
LIMIT 1"
|
||||
);
|
||||
@@ -124,18 +127,29 @@ class ChartOfAccounts
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT
|
||||
COUNT(*) AS total,
|
||||
SUM(status = 1) AS active,
|
||||
SUM(status = 0) AS inactive,
|
||||
COUNT(*) AS total,
|
||||
SUM(status = 1) AS active,
|
||||
SUM(status = 0) AS inactive,
|
||||
SUM(account_type = 'asset') AS asset,
|
||||
SUM(account_type = 'liability') AS liability,
|
||||
SUM(account_type = 'equity') AS equity,
|
||||
SUM(account_type = 'revenue') AS revenue,
|
||||
SUM(account_type = 'expense') AS expense
|
||||
FROM ac_account
|
||||
FROM md_account
|
||||
WHERE company_id = :cid"
|
||||
);
|
||||
$sth->execute([':cid' => $this->companyId]);
|
||||
return $sth->fetch(PDO::FETCH_ASSOC) ?: [];
|
||||
}
|
||||
|
||||
public function getByCategory(string $category): array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT * FROM md_account
|
||||
WHERE company_id = :cid AND account_category = :cat AND status = 1
|
||||
ORDER BY account_code ASC"
|
||||
);
|
||||
$sth->execute([':cid' => $this->companyId, ':cat' => $category]);
|
||||
return $sth->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user