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

Friday mor #21

Merged
merged 95 commits into from
Oct 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
69b09f2
merge the edits
lksnjw Sep 28, 2024
07fa4e0
Merge pull request #1 from lksnjw/SANJEEWA-ADDING
lksnjw Sep 28, 2024
6b00285
Merge pull request #48 from lksnjw/master
lksnjw Sep 28, 2024
aed5ec3
CHANGES MADE PORT NUMBERS
lksnjw Sep 28, 2024
8eb6ae5
done
lksnjw Sep 28, 2024
5eb7bd9
done
lksnjw Sep 28, 2024
af1ac94
fix cloudinary to the register
lksnjw Sep 28, 2024
589096f
Merge pull request #2 from lksnjw/register-change
lksnjw Sep 28, 2024
0d18f30
creating apdf
lksnjw Sep 29, 2024
d9bb721
Merge pull request #3 from lksnjw/creating-a-pdf
lksnjw Sep 29, 2024
1f4c585
fixed driver profile
lksnjw Sep 29, 2024
1eeb6b8
updated
lksnjw Sep 29, 2024
9b976ea
updated the delivery serach
lksnjw Sep 29, 2024
f324699
header
lksnjw Sep 29, 2024
53162ea
done
lksnjw Sep 29, 2024
9952309
Merge pull request #4 from lksnjw/editing-side-bars
lksnjw Sep 29, 2024
15c88d3
count set
lksnjw Sep 29, 2024
ab42f92
Update DLmangeDash.jsx
lksnjw Sep 29, 2024
8e5323f
done
lksnjw Sep 29, 2024
14732e0
updated driver
lksnjw Sep 29, 2024
5f28fc8
Merge pull request #5 from lksnjw/dashboard-update
lksnjw Sep 30, 2024
62f8847
fix errors
lksnjw Sep 30, 2024
71c23e9
Merge pull request #6 from lksnjw/dashboard-update
lksnjw Sep 30, 2024
c181fb9
editing
lksnjw Sep 30, 2024
1103622
done
lksnjw Sep 30, 2024
b3edb8b
Merge pull request #7 from lksnjw/this-is-the-eding-branch
lksnjw Sep 30, 2024
393e363
added pdf download
lksnjw Sep 30, 2024
064fbc2
done
lksnjw Sep 30, 2024
7b42dec
Merge pull request #8 from lksnjw/this-is-the-eding-branch
lksnjw Sep 30, 2024
5042e48
done edit profile pawword verification
lksnjw Sep 30, 2024
f47235f
Merge pull request #9 from lksnjw/this-is-the-eding-branch
lksnjw Sep 30, 2024
0317bc1
done
lksnjw Sep 30, 2024
15c21b1
fixed driver side all deliveriws
lksnjw Sep 30, 2024
2c30771
validation complete for driver registration
lksnjw Sep 30, 2024
24a1504
registation photo validation complete
lksnjw Sep 30, 2024
24219e6
update the sendind email with a button
lksnjw Sep 30, 2024
3650917
DONE linking pages
lksnjw Oct 1, 2024
7ffc3d5
Merge pull request #10 from lksnjw/this-is-the-eding-branch
lksnjw Oct 1, 2024
9ddf5b9
FIX LICENSE REGISTRATION
lksnjw Oct 1, 2024
ba97229
DONE
lksnjw Oct 1, 2024
d2ac115
Update DLDriverRegistrationForm.jsx
lksnjw Oct 1, 2024
823dde3
Merge pull request #11 from lksnjw/this-is-the-eding-branch
lksnjw Oct 1, 2024
dae7947
Merge pull request #12 from lksnjw/SANJEEWA-ADDING
lksnjw Oct 5, 2024
5a1fc7f
🔀 Automated Docker Image Building & Bug fixes (#57)
nmdra Oct 6, 2024
252bd37
Merge pull request #58 from lksnjw/SANJEEWA-ADDING
lksnjw Oct 7, 2024
620d565
format complete
lksnjw Oct 7, 2024
e23b7ae
Merge pull request #61 from lksnjw/SANJEEWA-ADDING
lksnjw Oct 7, 2024
ab18a9c
🚧 Update (WIP)
nmdra Oct 7, 2024
5e4e54b
updated localhost
lksnjw Oct 7, 2024
64bc423
🔀 Update (WIP)
nmdra Oct 7, 2024
ee6521a
Merge pull request #63 from lksnjw/SANJEEWA-ADDING
lksnjw Oct 7, 2024
095fc81
Merge pull request #13 from lksnjw/SANJEEWA-ADDING
lksnjw Oct 7, 2024
3a802c7
Merge branch 'sanjeewa' into sanjeewa_merge
nmdra Oct 7, 2024
43f6853
done
lksnjw Oct 7, 2024
eed00ef
updated auto assigning
lksnjw Oct 7, 2024
f9a7ce6
updated sendin email
lksnjw Oct 7, 2024
335c983
a
lksnjw Oct 8, 2024
a80bf45
Merge remote-tracking branch 'upstream/sanjeewa_merge' into SANJEEWA-…
lksnjw Oct 8, 2024
1766e57
Update DLImageUpload.jsx
lksnjw Oct 8, 2024
55b4cc8
Merge branch 'SANJEEWA-ADDING'
lksnjw Oct 8, 2024
35960d8
Merge branch 'master' of https://github.com/lksnjw/Farm-Cart-
lksnjw Oct 8, 2024
bdff065
update
lksnjw Oct 8, 2024
b1c39bd
fix dl view delivery and make first step to the map
lksnjw Oct 9, 2024
648e8cd
Added income page
lksnjw Oct 10, 2024
e25ce9d
update loadings
lksnjw Oct 10, 2024
7a61744
formated
lksnjw Oct 10, 2024
e719605
Merge branch 'nmdra:master' into master
lksnjw Oct 10, 2024
60f1463
Merge branch 'after-merge' into friday-mor
lksnjw Oct 10, 2024
9e3bd9f
fix preview one
lksnjw Oct 10, 2024
f2d69d1
fixed dash board
lksnjw Oct 10, 2024
e8bb441
formated
lksnjw Oct 10, 2024
20d0941
added admin login
lksnjw Oct 10, 2024
9d52ad1
updated
lksnjw Oct 10, 2024
26917c1
fixed
lksnjw Oct 11, 2024
2203826
Merge branch 'development' into friday-mor
nmdra Oct 11, 2024
e487094
remove folderr
lksnjw Oct 11, 2024
89dd174
Merge branch 'friday-mor' of https://github.com/lksnjw/Farm-Cart- int…
lksnjw Oct 11, 2024
bbcaa23
done
lksnjw Oct 11, 2024
915781f
Merge branch 'master' into friday-mor
nmdra Oct 11, 2024
261fd0d
add changing status
lksnjw Oct 11, 2024
dc92eb9
Merge branch 'friday-mor' of https://github.com/lksnjw/Farm-Cart- int…
lksnjw Oct 11, 2024
c082b4d
fixed
lksnjw Oct 11, 2024
460ec6e
Merge branch 'master' into friday-mor
lksnjw Oct 11, 2024
c835502
Merge pull request #17 from lksnjw/friday-mor
lksnjw Oct 11, 2024
d9e13fe
Done
lksnjw Oct 11, 2024
2c39c39
done
lksnjw Oct 11, 2024
695035f
done all the things
lksnjw Oct 11, 2024
226ca93
Merge branch 'nmdra:master' into master
lksnjw Oct 11, 2024
6b53b72
Merge branch 'master' into friday-mor
lksnjw Oct 11, 2024
2de872b
Update DLDriverRegistrationForm.jsx
lksnjw Oct 12, 2024
c853079
Merge branch 'friday-mor' of https://github.com/lksnjw/Farm-Cart- int…
lksnjw Oct 12, 2024
922a615
done
lksnjw Oct 12, 2024
d3b4a57
Update DLDriverRegistrationForm.jsx
lksnjw Oct 12, 2024
39f062c
Merge branch 'master' into friday-mor
lksnjw Oct 12, 2024
f32c500
Merge branch 'master' into friday-mor
lksnjw Oct 14, 2024
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
Prev Previous commit
Next Next commit
formated
  • Loading branch information
lksnjw committed Oct 10, 2024
commit e8bb4411f2fa5a8883169a3236d7d7b8ffaabc2d
240 changes: 124 additions & 116 deletions frontend/src/Components/Admin/DailyOrdersChart.jsx
Original file line number Diff line number Diff line change
@@ -1,120 +1,128 @@
import React, { useState, useEffect, useRef } from 'react';
import axios from 'axios';
import { Line } from 'react-chartjs-2';
import React, { useState, useEffect, useRef } from 'react'
import axios from 'axios'
import { Line } from 'react-chartjs-2'
import farmcartLogo from '../../assets/logo.png'
import 'chart.js/auto'; // Importing chart.js
import 'chart.js/auto' // Importing chart.js

const DailyOrdersChart = () => {
const [chartData, setChartData] = useState({});
const chartRef = useRef(null); // Reference to capture the chart instance

useEffect(() => {
const fetchDailyOrders = async () => {
try {
const { data } = await axios.get('/api/orders/daily-orders');

const dates = data.map(order => order._id);
const totalOrders = data.map(order => order.totalOrders);
const totalSales = data.map(order => order.totalSales);

setChartData({
labels: dates,
datasets: [
{
label: 'Total Orders',
data: totalOrders,
borderColor: 'rgba(34, 197, 94, 1)', // Tailwind Green (Accent color)
backgroundColor: 'rgba(34, 197, 94, 0.1)',
fill: true,
tension: 0.8,
},
{
label: 'Total Sales ($)',
data: totalSales,
borderColor: 'rgba(16, 185, 129, 1)',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
fill: true,
tension: 0.8,
},
],
});
} catch (error) {
console.error('Error fetching daily orders', error);
}
};

fetchDailyOrders();
}, []);

// Function to download the chart as a PNG image with a white background and a logo
const downloadChart = () => {
const chartInstance = chartRef.current;

if (chartInstance) {
const canvas = chartInstance.canvas; // Get the chart canvas
const imageData = canvas.toDataURL('image/png'); // Get chart image as PNG

// Create a new canvas to add the white background and the logo
const newCanvas = document.createElement('canvas');
newCanvas.width = canvas.width;
newCanvas.height = canvas.height;

const ctx = newCanvas.getContext('2d');

// Fill the new canvas with a white background
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, newCanvas.width, newCanvas.height);

// Draw the original chart on top of the white background
const img = new Image();
img.src = imageData;
img.onload = () => {
ctx.drawImage(img, 0, 0); // Draw the chart image

// Now load the logo and add it to the canvas
const logo = new Image();
logo.src = farmcartLogo; // Replace this with the path or URL of your logo
console.log(logo.src);
logo.onload = () => {
// Draw the logo at the bottom-right corner of the chart
const logoWidth = 150; // Width of the logo
const logoHeight = 50; // Height of the logo
const xPosition = newCanvas.width - logoWidth - 10; // 10px padding from right
const yPosition = 10; // 10px padding from bottom

ctx.drawImage(logo, xPosition, yPosition, logoWidth, logoHeight); // Draw logo

// Convert the new canvas with white background and logo to PNG
const newDataUrl = newCanvas.toDataURL('image/png');

// Trigger download
const link = document.createElement('a');
link.href = newDataUrl;
link.download = 'daily-orders-chart.png'; // Set the filename
link.click(); // Programmatically trigger the download
};
};
const [chartData, setChartData] = useState({})
const chartRef = useRef(null) // Reference to capture the chart instance

useEffect(() => {
const fetchDailyOrders = async () => {
try {
const { data } = await axios.get('/api/orders/daily-orders')

const dates = data.map((order) => order._id)
const totalOrders = data.map((order) => order.totalOrders)
const totalSales = data.map((order) => order.totalSales)

setChartData({
labels: dates,
datasets: [
{
label: 'Total Orders',
data: totalOrders,
borderColor: 'rgba(34, 197, 94, 1)', // Tailwind Green (Accent color)
backgroundColor: 'rgba(34, 197, 94, 0.1)',
fill: true,
tension: 0.8,
},
{
label: 'Total Sales ($)',
data: totalSales,
borderColor: 'rgba(16, 185, 129, 1)',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
fill: true,
tension: 0.8,
},
],
})
} catch (error) {
console.error('Error fetching daily orders', error)
}
}

fetchDailyOrders()
}, [])

// Function to download the chart as a PNG image with a white background and a logo
const downloadChart = () => {
const chartInstance = chartRef.current

if (chartInstance) {
const canvas = chartInstance.canvas // Get the chart canvas
const imageData = canvas.toDataURL('image/png') // Get chart image as PNG

// Create a new canvas to add the white background and the logo
const newCanvas = document.createElement('canvas')
newCanvas.width = canvas.width
newCanvas.height = canvas.height

const ctx = newCanvas.getContext('2d')

// Fill the new canvas with a white background
ctx.fillStyle = 'white'
ctx.fillRect(0, 0, newCanvas.width, newCanvas.height)

// Draw the original chart on top of the white background
const img = new Image()
img.src = imageData
img.onload = () => {
ctx.drawImage(img, 0, 0) // Draw the chart image

// Now load the logo and add it to the canvas
const logo = new Image()
logo.src = farmcartLogo // Replace this with the path or URL of your logo
console.log(logo.src)
logo.onload = () => {
// Draw the logo at the bottom-right corner of the chart
const logoWidth = 150 // Width of the logo
const logoHeight = 50 // Height of the logo
const xPosition = newCanvas.width - logoWidth - 10 // 10px padding from right
const yPosition = 10 // 10px padding from bottom

ctx.drawImage(
logo,
xPosition,
yPosition,
logoWidth,
logoHeight
) // Draw logo

// Convert the new canvas with white background and logo to PNG
const newDataUrl = newCanvas.toDataURL('image/png')

// Trigger download
const link = document.createElement('a')
link.href = newDataUrl
link.download = 'daily-orders-chart.png' // Set the filename
link.click() // Programmatically trigger the download
}
}
}
}
};

return (
<div className="max-w-4xl mx-auto p-6 bg-white shadow-md rounded-lg mt-8">
<h2 className="text-2xl font-bold text-green-600 mb-6">Daily Orders</h2>
{chartData.labels ? (
<>
<Line data={chartData} ref={chartRef} id="bidStatus" />
<button
onClick={downloadChart}
className="mt-6 px-4 py-2 bg-green-500 text-white font-semibold rounded hover:bg-green-600"
>
Download Chart as PNG
</button>
</>
) : (
<p>Loading chart...</p>
)}
</div>
);
};

export default DailyOrdersChart;

return (
<div className="max-w-4xl mx-auto p-6 bg-white shadow-md rounded-lg mt-8">
<h2 className="text-2xl font-bold text-green-600 mb-6">
Daily Orders
</h2>
{chartData.labels ? (
<>
<Line data={chartData} ref={chartRef} id="bidStatus" />
<button
onClick={downloadChart}
className="mt-6 px-4 py-2 bg-green-500 text-white font-semibold rounded hover:bg-green-600"
>
Download Chart as PNG
</button>
</>
) : (
<p>Loading chart...</p>
)}
</div>
)
}

export default DailyOrdersChart
2 changes: 1 addition & 1 deletion frontend/src/Pages/Admin/Adashboard.jsx
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ const Dashboard = () => {
</div>

{/* Additional dashboard content can be added here */}
<DailyOrdersChart/>
<DailyOrdersChart />
</main>
</div>
</div>
Loading