-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrial_balance_view.php
More file actions
199 lines (183 loc) · 9.22 KB
/
Copy pathtrial_balance_view.php
File metadata and controls
199 lines (183 loc) · 9.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
require_once 'includes/config.php';
require_once 'includes/functions.php';
require_login();
if ($_SESSION['role'] !== 'admin') {
header('Location: index.php');
exit;
}
$id = (int) ($_GET['id'] ?? 0);
if (!$id) {
header('Location: trial_balance.php');
exit;
}
$stmt = $pdo->prepare("
SELECT tb.*, u.username AS generated_by_name
FROM trial_balances tb
JOIN users u ON tb.generated_by = u.id
WHERE tb.id = ?
");
$stmt->execute([$id]);
$tb = $stmt->fetch();
if (!$tb) {
header('Location: trial_balance.php');
exit;
}
$lines_stmt = $pdo->prepare("
SELECT * FROM trial_balance_lines
WHERE trial_balance_id = ?
ORDER BY coa_code ASC
");
$lines_stmt->execute([$id]);
$lines = $lines_stmt->fetchAll();
// Group by type
$type_order = ['asset', 'liability', 'equity', 'income', 'expense'];
$grouped = [];
foreach ($lines as $line) {
$grouped[$line['coa_type']][] = $line;
}
$balanced = (round($tb['total_debits'], 2) === round($tb['total_credits'], 2));
$page_title = 'View Trial Balance';
require_once 'includes/header.php';
require_once 'includes/topbar.php';
require_once 'includes/sidebar.php';
?>
<div class="page-wrapper">
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box d-md-flex justify-content-md-between align-items-center">
<h4 class="page-title"><?php echo htmlspecialchars($tb['label']); ?></h4>
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
<li class="breadcrumb-item"><a href="trial_balance.php">Trial Balance</a></li>
<li class="breadcrumb-item active">View</li>
</ol>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center no-print">
<div>
<small class="text-muted">
Period: <strong><?php echo date('d M Y', strtotime($tb['date_from'])); ?></strong>
—
<strong><?php echo date('d M Y', strtotime($tb['date_to'])); ?></strong>
|
Generated by <strong><?php echo htmlspecialchars($tb['generated_by_name']); ?></strong>
on <?php echo date('d M Y H:i', strtotime($tb['generated_at'])); ?>
</small>
</div>
<div>
<?php if ($balanced): ?>
<span class="badge bg-success fs-6 me-2">
<i class="fas fa-check-circle me-1"></i> Balanced
</span>
<?php else: ?>
<span class="badge bg-danger fs-6 me-2">
<i class="fas fa-exclamation-triangle me-1"></i> Out of Balance
</span>
<?php endif; ?>
<button onclick="window.print()" class="btn btn-sm btn-outline-secondary me-2">
<i class="fas fa-print me-1"></i> Print
</button>
<a href="trial_balance.php" class="btn btn-sm btn-outline-primary">
<i class="fas fa-arrow-left me-1"></i> Back
</a>
</div>
</div>
<!-- Print header - only shows when printing -->
<div class="card-body print-header" style="display:none;">
<h3 class="text-center"><?php echo htmlspecialchars($tb['label']); ?></h3>
<p class="text-center text-muted">
Period: <?php echo date('d M Y', strtotime($tb['date_from'])); ?>
—
<?php echo date('d M Y', strtotime($tb['date_to'])); ?>
</p>
</div>
<div class="card-body pt-0">
<table class="table table-striped mt-3">
<thead class="table-dark">
<tr>
<th>Code</th>
<th>Account Name</th>
<th>Type</th>
<th class="text-end">Debit (£)</th>
<th class="text-end">Credit (£)</th>
</tr>
</thead>
<tbody>
<?php foreach ($type_order as $type):
if (empty($grouped[$type]))
continue;
?>
<tr class="table-secondary">
<td colspan="5" class="fw-bold text-uppercase small">
<?php echo ucfirst($type); ?>
</td>
</tr>
<?php foreach ($grouped[$type] as $line):
$has_activity = ($line['debit_amount'] > 0 || $line['credit_amount'] > 0);
?>
<tr class="<?php echo !$has_activity ? 'text-muted' : ''; ?>">
<td><?php echo htmlspecialchars($line['coa_code']); ?></td>
<td><?php echo htmlspecialchars($line['coa_name']); ?></td>
<td>
<span class="badge
<?php echo match ($line['coa_type']) {
'asset' => 'bg-primary',
'liability' => 'bg-warning text-dark',
'equity' => 'bg-info text-dark',
'income' => 'bg-success',
'expense' => 'bg-danger',
default => 'bg-secondary'
}; ?>">
<?php echo ucfirst($line['coa_type']); ?>
</span>
</td>
<td class="text-end">
<?php echo $line['debit_amount'] > 0
? number_format($line['debit_amount'], 2)
: '-'; ?>
</td>
<td class="text-end">
<?php echo $line['credit_amount'] > 0
? number_format($line['credit_amount'], 2)
: '-'; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
<tfoot class="table-dark">
<tr>
<td colspan="3" class="fw-bold text-end">TOTALS</td>
<td class="text-end fw-bold">
£<?php echo number_format($tb['total_debits'], 2); ?>
</td>
<td class="text-end fw-bold">
£<?php echo number_format($tb['total_credits'], 2); ?>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
@media print {
.no-print, nav, .sidebar, .topbar, .btn { display: none !important; }
.print-header { display: block !important; }
.page-wrapper { margin: 0 !important; }
.card { box-shadow: none !important; border: none !important; }
table { font-size: 12px; }
}
</style>
<?php require_once 'includes/footer.php'; ?>