accounting workflows
This commit is contained in:
@@ -307,6 +307,90 @@ class ReportManager
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function getDashboardStockTotals(): array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT
|
||||
ROUND(COALESCE(SUM(total_in), 0), 2) AS total_in,
|
||||
ROUND(COALESCE(SUM(total_out), 0), 2) AS total_out
|
||||
FROM warehouse_balance
|
||||
WHERE company_id = :company_id"
|
||||
);
|
||||
$sth->execute([':company_id' => $this->companyId]);
|
||||
return $sth->fetch(PDO::FETCH_ASSOC) ?: ['total_in' => 0, 'total_out' => 0];
|
||||
}
|
||||
|
||||
public function getDashboardOrderStats(): array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT COUNT(*), COALESCE(SUM(subtotal), 0)
|
||||
FROM td_order
|
||||
WHERE company_id = :company_id
|
||||
AND status != -1"
|
||||
);
|
||||
$sth->execute([':company_id' => $this->companyId]);
|
||||
[$total_orders, $total_revenue] = $sth->fetch(PDO::FETCH_NUM) ?: [0, 0];
|
||||
|
||||
return [
|
||||
'total_orders' => (int)$total_orders,
|
||||
'total_revenue' => (float)$total_revenue,
|
||||
];
|
||||
}
|
||||
|
||||
public function getDashboardOpenDocumentCounts(): array
|
||||
{
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT COUNT(*) FROM td_invoice
|
||||
WHERE company_id = :company_id
|
||||
AND doc_type = 'invoice'
|
||||
AND status IN (0, 1, 3)"
|
||||
);
|
||||
$sth->execute([':company_id' => $this->companyId]);
|
||||
$unpaid_invoices = (int)$sth->fetchColumn();
|
||||
|
||||
$sth = $this->pdo->prepare(
|
||||
"SELECT COUNT(*) FROM td_return
|
||||
WHERE company_id = :company_id
|
||||
AND status = 0"
|
||||
);
|
||||
$sth->execute([':company_id' => $this->companyId]);
|
||||
$pending_returns = (int)$sth->fetchColumn();
|
||||
|
||||
return [
|
||||
'unpaid_invoices' => $unpaid_invoices,
|
||||
'pending_returns' => $pending_returns,
|
||||
];
|
||||
}
|
||||
|
||||
public function getDashboardStockHealth(): array
|
||||
{
|
||||
$low_stock_items = $this->getLowStockItems();
|
||||
$critical_count = count(array_filter($low_stock_items, fn($i) => $i['status'] === 'critical'));
|
||||
$warning_count = count(array_filter($low_stock_items, fn($i) => $i['status'] === 'warning'));
|
||||
$total_in_stock = (int)$this->getTotalProductInStock();
|
||||
$healthy_count = max(0, $total_in_stock - $critical_count - $warning_count);
|
||||
|
||||
return [
|
||||
'low_stock' => count($low_stock_items),
|
||||
'stock_health' => [
|
||||
'healthy' => $healthy_count,
|
||||
'warning' => $warning_count,
|
||||
'critical' => $critical_count,
|
||||
'total' => $total_in_stock,
|
||||
],
|
||||
'low_stock_items' => $low_stock_items,
|
||||
];
|
||||
}
|
||||
|
||||
public function getDashboardMasterCounts(): array
|
||||
{
|
||||
return [
|
||||
'total_products' => (int)$this->getTotalProduct(),
|
||||
'total_contacts' => (int)$this->getTotalContact(),
|
||||
'total_warehouses' => (int)$this->getTotalWarehouse(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all SKUs at or below their reorder_point with full product and warehouse details.
|
||||
*
|
||||
@@ -1192,7 +1276,7 @@ class ReportManager
|
||||
rl.td_stock_id,
|
||||
rl.login,
|
||||
u.name AS user_name
|
||||
FROM md_rack_log rl
|
||||
FROM td_rack_log rl
|
||||
LEFT JOIN `{$main_db}`.user u
|
||||
ON u.user_id = rl.user_id
|
||||
WHERE rl.company_id = :company_id
|
||||
|
||||
Reference in New Issue
Block a user