Bump and Migrate logic chartjs 2.9.4 to 4.5.0, bump stripe-php from 17.2.1 to 17.6.0, fontawesome-free from 5.15.4 to 7.0.0, fullcalendar from 6.1.17 to 6.1.19, TinyMCE from 7.9.1 to 8.0.2, bootsatrap js bundle from 4.6.1 to 4.6.2, DataTables from 2.3.1 to 2.3.3
This commit is contained in:
@@ -14,8 +14,17 @@ $sql_expense_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(expense_date) A
|
||||
|
||||
$sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Expense' ORDER BY category_name ASC");
|
||||
|
||||
// For chart Y-axis max
|
||||
$largest_expense_month = 0;
|
||||
|
||||
?>
|
||||
|
||||
<!-- Responsive chart helpers -->
|
||||
<style>
|
||||
.chart-h-320 { position: relative; height: 320px; }
|
||||
@media (max-width: 576px) { .chart-h-320 { height: 260px; } }
|
||||
</style>
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header py-2">
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-coins mr-2"></i>Expense Summary</h3>
|
||||
@@ -26,19 +35,16 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category
|
||||
<div class="card-body">
|
||||
<form class="mb-3">
|
||||
<select onchange="this.form.submit()" class="form-control" name="year">
|
||||
<?php
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_expense_years)) {
|
||||
$expense_year = $row['expense_year'];
|
||||
?>
|
||||
<option <?php if ($year == $expense_year) { ?> selected <?php } ?> > <?php echo $expense_year; ?></option>
|
||||
|
||||
<?php while ($row = mysqli_fetch_array($sql_expense_years)) {
|
||||
$expense_year = intval($row['expense_year']); ?>
|
||||
<option <?php if ($year == $expense_year) { ?> selected <?php } ?>><?php echo $expense_year; ?></option>
|
||||
<?php } ?>
|
||||
|
||||
</select>
|
||||
</form>
|
||||
|
||||
<canvas id="cashFlow" width="100%" height="20"></canvas>
|
||||
<div class="chart-h-320 mb-3">
|
||||
<canvas id="cashFlow"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-striped">
|
||||
@@ -61,53 +67,54 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
while ($row = mysqli_fetch_array($sql_categories)) {
|
||||
<?php while ($row = mysqli_fetch_array($sql_categories)) {
|
||||
$category_id = intval($row['category_id']);
|
||||
$category_name = nullable_htmlentities($row['category_name']);
|
||||
?>
|
||||
|
||||
$category_name = nullable_htmlentities($row['category_name']); ?>
|
||||
<tr>
|
||||
<td><?php echo $category_name; ?></td>
|
||||
|
||||
<?php
|
||||
|
||||
$total_expense_for_all_months = 0;
|
||||
for ($month = 1; $month<=12; $month++) {
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
$sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_amount_for_month FROM expenses WHERE expense_category_id = $category_id AND YEAR(expense_date) = $year AND MONTH(expense_date) = $month");
|
||||
$row = mysqli_fetch_array($sql_expenses);
|
||||
$expense_amount_for_month = floatval($row['expense_amount_for_month']);
|
||||
$total_expense_for_all_months = $expense_amount_for_month + $total_expense_for_all_months;
|
||||
|
||||
|
||||
$rowm = mysqli_fetch_array($sql_expenses);
|
||||
$expense_amount_for_month = floatval($rowm['expense_amount_for_month']);
|
||||
$total_expense_for_all_months += $expense_amount_for_month;
|
||||
?>
|
||||
<td class="text-right"><a class="text-dark" href="expenses.php?q=<?php echo $category_name; ?>&dtf=<?php echo "$year-$month"; ?>-01&dtt=<?php echo "$year-$month"; ?>-31"><?php echo numfmt_format_currency($currency_format, $expense_amount_for_month, $session_company_currency); ?></a></td>
|
||||
|
||||
<td class="text-right">
|
||||
<a class="text-dark" href="expenses.php?q=<?php echo $category_name; ?>&dtf=<?php echo "$year-$month"; ?>-01&dtt=<?php echo "$year-$month"; ?>-31">
|
||||
<?php echo numfmt_format_currency($currency_format, $expense_amount_for_month, $session_company_currency); ?>
|
||||
</a>
|
||||
</td>
|
||||
<?php } ?>
|
||||
|
||||
<th class="text-right"><a class="text-dark" href="expenses.php?q=<?php echo $category_name; ?>&dtf=<?php echo $year; ?>-01-01&dtt=<?php echo $year; ?>-12-31"><?php echo numfmt_format_currency($currency_format, $total_expense_for_all_months, $session_company_currency); ?></a></th>
|
||||
<th class="text-right">
|
||||
<a class="text-dark" href="expenses.php?q=<?php echo $category_name; ?>&dtf=<?php echo $year; ?>-01-01&dtt=<?php echo $year; ?>-12-31">
|
||||
<?php echo numfmt_format_currency($currency_format, $total_expense_for_all_months, $session_company_currency); ?>
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<tr>
|
||||
<th>Total</th>
|
||||
<?php
|
||||
|
||||
for ($month = 1; $month<=12; $month++) {
|
||||
$grand_total_all_months = 0;
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
$sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_total_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0");
|
||||
$row = mysqli_fetch_array($sql_expenses);
|
||||
$expense_total_amount_for_month = floatval($row['expense_total_amount_for_month']);
|
||||
$total_expense_for_all_months = $expense_total_amount_for_month + $total_expense_for_all_months;
|
||||
|
||||
|
||||
$rowt = mysqli_fetch_array($sql_expenses);
|
||||
$expense_total_amount_for_month = floatval($rowt['expense_total_amount_for_month']);
|
||||
$grand_total_all_months += $expense_total_amount_for_month;
|
||||
?>
|
||||
|
||||
<th class="text-right"><a class="text-dark" href="expenses.php?dtf=<?php echo "$year-$month"; ?>-01&dtt=<?php echo "$year-$month"; ?>-31"><?php echo numfmt_format_currency($currency_format, $expense_total_amount_for_month, $session_company_currency); ?></a></th>
|
||||
|
||||
<th class="text-right">
|
||||
<a class="text-dark" href="expenses.php?dtf=<?php echo "$year-$month"; ?>-01&dtt=<?php echo "$year-$month"; ?>-31">
|
||||
<?php echo numfmt_format_currency($currency_format, $expense_total_amount_for_month, $session_company_currency); ?>
|
||||
</a>
|
||||
</th>
|
||||
<?php } ?>
|
||||
|
||||
<th class="text-right"><a class="text-dark" href="expenses.php?dtf=<?php echo $year; ?>-01-01&dtt=<?php echo $year; ?>-12-31"><?php echo numfmt_format_currency($currency_format, $total_expense_for_all_months, $session_company_currency); ?></th>
|
||||
<th class="text-right">
|
||||
<a class="text-dark" href="expenses.php?dtf=<?php echo $year; ?>-01-01&dtt=<?php echo $year; ?>-12-31">
|
||||
<?php echo numfmt_format_currency($currency_format, $grand_total_all_months, $session_company_currency); ?>
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -115,79 +122,74 @@ $sql_categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once "../includes/footer.php";
|
||||
?>
|
||||
<?php require_once "../includes/footer.php"; ?>
|
||||
|
||||
<script>
|
||||
// Set new default font family and font color to mimic Bootstrap's default styling
|
||||
Chart.defaults.global.defaultFontFamily = '-apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif';
|
||||
Chart.defaults.global.defaultFontColor = '#292b2c';
|
||||
// Bootstrap-like defaults for Chart.js v4
|
||||
Chart.defaults.font.family = '-apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif';
|
||||
Chart.defaults.color = '#292b2c';
|
||||
|
||||
var ctx = document.getElementById("cashFlow");
|
||||
var myLineChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
||||
datasets: [{
|
||||
label: "Expense",
|
||||
lineTension: 0.3,
|
||||
fill: false,
|
||||
borderColor: "#dc3545",
|
||||
pointBackgroundColor: "#dc3545",
|
||||
pointBorderColor: "#dc3545",
|
||||
pointHoverRadius: 5,
|
||||
pointHoverBackgroundColor: "#dc3545",
|
||||
pointHitRadius: 50,
|
||||
pointBorderWidth: 2,
|
||||
data: [
|
||||
<?php
|
||||
// EXPENSES LINE CHART
|
||||
(function () {
|
||||
var ctx = document.getElementById("cashFlow");
|
||||
if (!ctx) return;
|
||||
|
||||
$largest_expense_month = 0;
|
||||
var dataPoints = [
|
||||
<?php
|
||||
// Build series and track the largest month for axis max
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
$sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0");
|
||||
$rowm = mysqli_fetch_array($sql_expenses);
|
||||
$expenses_for_month = floatval($rowm['expense_amount_for_month']);
|
||||
|
||||
for ($month = 1; $month<=12; $month++) {
|
||||
$sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS expense_amount_for_month FROM expenses WHERE YEAR(expense_date) = $year AND MONTH(expense_date) = $month AND expense_vendor_id > 0");
|
||||
$row = mysqli_fetch_array($sql_expenses);
|
||||
$expenses_for_month = floatval($row['expense_amount_for_month']);
|
||||
|
||||
if ($expenses_for_month > 0 && $expenses_for_month > $largest_expense_month) {
|
||||
$largest_expense_month = $expenses_for_month;
|
||||
}
|
||||
|
||||
echo "$expenses_for_month,";
|
||||
|
||||
} ?>
|
||||
|
||||
],
|
||||
}],
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
time: {
|
||||
unit: 'date'
|
||||
},
|
||||
gridLines: {
|
||||
display: false
|
||||
},
|
||||
ticks: {
|
||||
maxTicksLimit: 12
|
||||
}
|
||||
}],
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
min: 0,
|
||||
max: <?php $max = max(1000, $largest_expense_month, $largest_income_month, $largest_invoice_month); echo roundUpToNearestMultiple($max); ?>,
|
||||
maxTicksLimit: 5
|
||||
},
|
||||
gridLines: {
|
||||
color: "rgba(0, 0, 0, .125)",
|
||||
}
|
||||
}],
|
||||
},
|
||||
legend: {
|
||||
display: false
|
||||
if ($expenses_for_month > 0 && $expenses_for_month > $largest_expense_month) {
|
||||
$largest_expense_month = $expenses_for_month;
|
||||
}
|
||||
echo "$expenses_for_month,";
|
||||
}
|
||||
}
|
||||
});
|
||||
?>
|
||||
];
|
||||
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
|
||||
datasets: [{
|
||||
label: "Expense",
|
||||
tension: 0.3, // v4 name (v2: lineTension)
|
||||
fill: false,
|
||||
borderColor: "#dc3545",
|
||||
pointBackgroundColor: "#dc3545",
|
||||
pointBorderColor: "#dc3545",
|
||||
pointHoverRadius: 5,
|
||||
pointHoverBackgroundColor: "#dc3545",
|
||||
pointBorderWidth: 2,
|
||||
data: dataPoints
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
scales: {
|
||||
x: {
|
||||
grid: { display: false },
|
||||
ticks: { maxTicksLimit: 12 }
|
||||
},
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
min: 0,
|
||||
max: <?php
|
||||
$max = max(1000, $largest_expense_month);
|
||||
echo roundUpToNearestMultiple($max);
|
||||
?>,
|
||||
ticks: { maxTicksLimit: 5 },
|
||||
grid: { color: "rgba(0, 0, 0, .125)" }
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: { display: false }
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user