Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: real-time update the monthly income of the parking #286

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/ParkingOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function gotoLand($land_ID = null){
'security_count' => $this->securityModel->getSecurityCount($land_ID),
'availability' => $this->landModel->getAvailability($land_ID),
'capacity' => $this->landModel->getCapacity($land_ID),
'today_transactions' => $this->landModel->getTodayTransactions($land_ID)
'today_transactions' => $this->landModel->getTodayTransactions($land_ID),
'total_income' => $this->landModel->getTotalIncome($land_ID)
];

$this->view('parkingOwner/land', $data, $notifications);
Expand Down
12 changes: 6 additions & 6 deletions app/models/LandModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,14 @@ public function getTodayTransactions($landID){
return $row;
}

// Get yesterday transactions
public function getYesterdayTransactions($landID){
$this->db->query('SELECT * FROM driver_land WHERE landID = :landID AND transactionTime = :transactionTime');
// Get total income of the parking for current month
public function getTotalIncome($landID){
$this->db->query('SELECT SUM(cost) AS totalIncome FROM driver_land WHERE landID = :landID AND endTime >= :endTime');
$this->db->bind(':landID', $landID);
$this->db->bind(':transactionTime', date('Y-m-d', strtotime("-1 days")));
$this->db->bind(':endTime', date('Y-m-01'));

$row = $this->db->resultSet();
$row = $this->db->single();

return $row;
return $row->totalIncome;
}
}
3 changes: 3 additions & 0 deletions app/views/inc/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

<!-- Sweet Alert -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<!-- Chart.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
</head>
<body>

Expand Down
34 changes: 27 additions & 7 deletions app/views/parkingOwner/land.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@
<div class="bottom-row"></div>
</div>
</div>
<div style="transform: translateY(-20px)" class="right-col">
<div style="transform: translateY(-20px)" class="right-col" id="monthly-income">
<p style="font-size: 15px">Monthly Income</p>
<h3 style="color: rgba(0,0,0,0.62); font-size: 20px">Rs. 100000</h3>
<h3 style="color: rgba(0,0,0,0.62); font-size: 20px">Rs. <?php echo $data['total_income']?></h3>
</div>
</div>
</div>
Expand Down Expand Up @@ -201,6 +201,7 @@
</main>

<script>
// --------------------------------------- Real time update transaction box ---------------------------------------
function refreshSideCard() {
// Fetch updated content via AJAX
fetch('<?php echo URLROOT?>/ParkingOwner/gotoLand/<?php echo $data["id"]?>')
Expand All @@ -215,12 +216,30 @@ function refreshSideCard() {

// Refresh every 1 second
setInterval(refreshSideCard, 1000);
</script>


function refreshMonthlyIncome() {
// Fetch updated content via AJAX
fetch('<?php echo URLROOT?>/ParkingOwner/gotoLand/<?php echo $data["id"]?>') // Update URL to your controller method
.then(response => response.text())
.then(data => {
// Extract the monthly income value from the returned data
const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
const updatedIncome = doc.getElementById('monthly-income').querySelector('h3').textContent;

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
<script>
// Update the value inside the h3 tag
document.getElementById('monthly-income').querySelector('h3').textContent = updatedIncome;
})
.catch(error => console.error('Error fetching data:', error));
}

// Refresh every 1 second
setInterval(refreshMonthlyIncome, 1000);



// ---------------------------------------------- Chart.js ----------------------------------------------
const xValues = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov', 'dec'];
const yValues = [7,8,8,9,9,9,10,11,14,14,15];

Expand Down Expand Up @@ -248,6 +267,8 @@ function refreshSideCard() {
}
});



// Create a new chart with a different id for the second canvas
new Chart("lineChart2", {
type: "bar",
Expand All @@ -268,6 +289,7 @@ function refreshSideCard() {
});



// ---------------------------------------------- Toggle button ----------------------------------------------
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('toggleButton').addEventListener('change', function () {
Expand All @@ -293,6 +315,4 @@ function refreshSideCard() {
});
</script>



<?php require APPROOT.'/views/inc/footer.php'; ?>
Empty file added public/js/parkingDashboard.js
Empty file.