-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicomeStatement.php
189 lines (159 loc) · 6.12 KB
/
icomeStatement.php
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
<?php
session_start();
if(!isset($_SESSION['id']))
{
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Profit & Loss Account</title>
<!-- BOOTSTRAP STYLES-->
<link href="assets/css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="assets/css/font-awesome.css" rel="stylesheet" />
<!-- CUSTOM STYLES-->
<link href="assets/css/custom.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
</head>
<body>
<!-- /. NAV BAR -->
<?php
include 'navheader.php';
?>
<!-- /. NAV TOP -->
<?php
include 'navtop.php';
?>
<!-- /. NAV SIDE -->
<div id="page-wrapper" >
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<h2>Profit & Loss Account </h2>
</div>
</div>
<!-- /. ROW -->
<hr />
<div>
<?php
// Connect to the database
require_once 'connection.php';
// Prepare the SQL statement to fetch income and expense accounts from the Accounts table
$sql = "SELECT account_id, account_name, account_type FROM accounts
WHERE account_type = 'income' OR account_type = 'expense'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Initialize total revenues and total expenses
$total_revenues = 0;
$total_expenses = 0;
// Display the table header
echo '<table class="table table-striped table-bordered table-hover">';
echo '<tr><th>Category</th><th>Amount</th></tr>';
// Loop through the accounts and calculate the total revenues and total expenses
while ($row = $result->fetch_assoc()) {
$account_id = $row['account_id'];
// Calculate the total debit and credit amounts for each account
$sql_amounts = "SELECT SUM(debit_amount) as total_debit, SUM(credit_amount) as total_credit
FROM journalEntries
WHERE account_id = $account_id";
$result_amounts = $conn->query($sql_amounts);
$row_amounts = $result_amounts->fetch_assoc();
$debit_amount = $row_amounts['total_debit'];
$credit_amount = $row_amounts['total_credit'];
// Calculate the account balance
$balance = $debit_amount - $credit_amount;
// Update total revenues or total expenses based on the account type
if ($row['account_type'] == 'income') {
$total_revenues += $balance;
} else {
$total_expenses += $balance;
}
// Display the account name and balance in the table
echo '<tr>';
echo '<td>' . $row['account_name'] . '</td>';
echo '<td>' . number_format($balance, 2) . '</td>';
echo '</tr>';
}
// Calculate net income or loss
$net_income_loss = $total_revenues - $total_expenses;
// Display the total revenues, total expenses, and net income or loss
echo '<tr>';
echo '<td><strong>Revenue:</strong></td>';
echo '<td></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Sales Revenue</td>';
echo '<td>' . number_format($total_revenues, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Other Revenues</td>';
echo '<td></td>';
echo '</tr>';
echo '<tr>';
echo '<td><strong>Total Revenue</strong></td>';
echo '<td>' . number_format($total_revenues, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td><strong>Expenses:</strong></td>';
echo '<td></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Cost of Goods Sold</td>';
echo '<td>' . number_format($total_expenses, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Gross Profit</td>';
echo '<td>' . number_format($total_revenues - $total_expenses, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Operating Expenses:</td>';
echo '<td></td>';
echo '</tr>';
// Additional expense categories can be displayed here if needed
echo '<tr>';
echo '<td><strong>Total Operating Expenses</strong></td>';
echo '<td>' . number_format($total_expenses, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td><strong>Operating Income (or Loss)</strong></td>';
echo '<td>' . number_format($total_revenues - $total_expenses, 2) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td><strong>Other Income</strong></td>';
echo '<td></td>';
echo '</tr>';
echo '<tr>';
echo '<td><strong>Other Expenses</strong></td>';
echo '<td></td>';
echo '</tr>';
echo '<tr>';
echo '<td><strong>Net Income (or Loss)</strong></td>';
echo '<td>' . number_format($net_income_loss, 2) . '</td>';
echo '</tr>';
echo '</table>';
} else {
echo 'No income or expense accounts found.';
}
// Close the database connection
$conn->close();
?>
</div>
<!-- /. ROW -->
</div>
<!-- /. PAGE INNER -->
</div>
<!-- /. PAGE WRAPPER -->
</div>
<!-- /. Footer -->
<?php
include 'footer.php';
?>
<?php
include 'scripts.php';
?>
</html>