Skip to content

Commit

Permalink
report generation updated
Browse files Browse the repository at this point in the history
  • Loading branch information
NadunSanjeevana committed Sep 12, 2023
1 parent dd8cf90 commit 63a27cd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/layouts/authentication/sign-in/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function Basic() {
login({
name: userData.User_Name,
full_name: userData.Full_Name,
user_ID: userData.UserID,
role: userData.Role,
email: userData.email,
phone_Number: userData.Contact_Number,
Expand Down
3 changes: 1 addition & 2 deletions src/layouts/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from "react";
import Grid from "@mui/material/Grid";
import AnchorLink from "react-anchor-link-smooth-scroll";

Expand All @@ -21,7 +20,7 @@ import ComplexStatisticsCard from "examples/Cards/StatisticsCards/ComplexStatist
import Projects from "layouts/dashboard/components/Projects";
import SearchBar from "./components/SearchBar/searchBar";
import { AdCard } from "./components/adCard";
import { useState } from "react";
import { useState, useEffect } from "react";
import { getCounts } from "api/count/counts";
import { Link } from "react-router-dom";
// import OrdersOverview from "layouts/dashboard/components/OrdersOverview";
Expand Down
12 changes: 8 additions & 4 deletions src/layouts/graph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ import CategoryDistribution from "./components/barCharts/categoryDist";
import MarriageDistribution from "./components/pieCharts/marriageDist";
import HouseSaleDistribution from "./components/pieCharts/houseSaleDDist";

import createPDF from "layouts/reports/reports";
import generatePDF from "layouts/reports/reports";
import PriceFluctuation from "./components/lineCharts/pricefluctuation";
import MDInput from "components/MDInput";
import Demographic from "./components/lineCharts/demographic";
import HousesaleAveragePrice from "./components/barCharts/houseSaleChart";

import { useUser } from "utils/userContext";

function GraphViewer() {
const contentRef = useRef(null);
const { user } = useUser();
console.log(user.user_ID);

const [includeLandSale, setIncludeLandSale] = useState(false);
const [includeCategoryDist, setIncludeCategoryDist] = useState(false);
Expand Down Expand Up @@ -71,7 +75,7 @@ function GraphViewer() {
setIncludeMarriageDist(true);
setIncludePriceFluct(true);
};
const generatePDF = () => {
const createPDF = () => {
const selectedComponents = [];

// Check which components are selected and add them to the selectedComponents array
Expand All @@ -92,7 +96,7 @@ function GraphViewer() {
}

// Pass the selected components to your PDF generator function (ChartToPDF)
createPDF(selectedComponents, contentRef, title);
generatePDF(selectedComponents, contentRef, title, user.user_ID);
};

return (
Expand Down Expand Up @@ -269,7 +273,7 @@ function GraphViewer() {
/>
</MDBox>
</MDBox>
<MDButton color="primary" maxWidth="20px" component="span" onClick={generatePDF}>
<MDButton color="primary" maxWidth="20px" component="span" onClick={createPDF}>
Generate PDF
</MDButton>
</Card>
Expand Down
5 changes: 3 additions & 2 deletions src/layouts/reports/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import jsPDF from "jspdf";
import "jspdf-autotable";
import html2canvas from "html2canvas";
import * as XLSX from "xlsx";

import { savePdf } from "api/report/saveReport";
import { storage } from "../../firebase";
import { ref, uploadBytes, getDownloadURL } from "firebase/storage";
Expand All @@ -24,7 +25,7 @@ export const generateExcel = (data, filename) => {
};

// Function to generate PDF
const generatePDF = async (componentsToPrint, contentRef, title) => {
const generatePDF = async (componentsToPrint, contentRef, title, user_ID) => {
try {
// Create a new jsPDF instance
const doc = new jsPDF();
Expand Down Expand Up @@ -55,7 +56,7 @@ const generatePDF = async (componentsToPrint, contentRef, title) => {

doc.save(`${title}.pdf`);
const pdfBlob = doc.output("blob");
const userID = "pu123";
const userID = user_ID;
const pdfRef = ref(storage, `Reports/${title}`);

// Upload the PDF to Firebase Storage
Expand Down

0 comments on commit 63a27cd

Please sign in to comment.