import React, { useRef, useState, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { useTheme } from '@mui/material/styles';
// import nearleLogo from '../../assets/images/nearleLogo.png';
import logo_nearle1 from '../../../assets/images/logo-nearle1.png';
import axios from 'axios';
import dayjs from 'dayjs';
import Loader from 'components/Loader';
import { enqueueSnackbar } from 'notistack';
import { DownloadOutlined, PrinterFilled } from '@ant-design/icons';
import ReactToPrint, { useReactToPrint } from 'react-to-print';
import { SearchOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
// import jsPDF from 'jspdf';
import { useNavigate } from 'react-router-dom';
import { FaArrowLeft } from 'react-icons/fa6';
import { FaIndianRupeeSign } from 'react-icons/fa6';
// import autoTable from 'jspdf-autotable';
import {
Grid,
Button,
Divider,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TablePagination,
TableRow,
Tabs,
Tab,
Typography,
Box,
OutlinedInput,
InputAdornment,
IconButton,
Tooltip,
Dialog,
DialogTitle,
DialogContent,
Stack,
Chip,
DialogActions,
TextField
} from '@mui/material';
const InvoicePreview = () => {
const [selected, setselected] = useState({});
const location = useLocation();
const navigate = useNavigate();
console.log('previewSelect', location.state);
const componentRef = useRef(null);
const [tabletype, settabletype] = useState(true);
const [paydialog, setpaydialog] = useState(false);
const [refnumber, setRefnumber] = useState('');
const [remarks, setRemarks] = useState('');
const theme = useTheme();
useEffect(() => {
setselected(location.state);
}, []);
// ================================================= || formatNumberToRupees || =================================================
function formatNumberToRupees(value) {
return new Intl.NumberFormat('en-IN', {
style: 'currency',
currency: 'INR',
minimumFractionDigits: 2
}).format(value);
}
useEffect(() => {
console.log('refnumber', refnumber);
console.log('remarks', remarks);
}, [refnumber, remarks]);
// ================================================= || updatePayment || =================================================
const updatePayment = async () => {
try {
const updateResponse = await axios.put(`${process.env.REACT_APP_URL}/invoice/updatestatus`, {
salesid: selected.salesid,
referenceno: refnumber,
referencedate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
billstatus: 2,
paymentremarks: remarks
});
if (updateResponse.status) {
enqueueSnackbar(' Updated Successfully ', {
variant: 'success',
anchorOrigin: { vertical: 'top', horizontal: 'right' },
autoHideDuration: 1000
});
}
console.log('updateResponse', updateResponse);
} catch (error) {
console.log('updateResponse', error);
}
};
return (
<>
{/* // ================================================= || Invoice Details || ================================================= */}
{
navigate('/invoice');
}}
>
Invoice Details
{/* */}
(
}
variant="outlined"
color="primary"
sx={{
'&:hover': {
backgroundColor: 'primary.main',
color: 'primary.contrastText'
}
}}
>
Print
)}
content={() => componentRef.current}
/>
{/* // ================================================= || Date row || ================================================= */}
{' '}
Invoice No :
{`${'\u00a0\u00a0'}${selected.invoiceno}`}
Date :{' '}
{dayjs(selected.transactiondate).format('DD-MM-YYYY')}
Due Date :
{dayjs(selected.dueDate).format('DD-MM-YYYY')}
{/* // ================================================= || from to || ================================================= */}
From:
Nearle Technology Privite Limited.
424, 4thfloor,
Red rose towers,
DB Road, RS Puram,
641002.
care@nearle.in
9047968666
To:
{selected.tenantname}
{selected.address}
{selected.suburb}
{selected.city}
{selected.state}{' '}
{/* // ================================================= || invoice table || ================================================= */}
S.No
Particulars
Unit
Quantity
Rate
{/* {selected && selected.pricingtypeid === 73 && ( */}
Other Charges
{/* )} */}
Amount
{selected.tenantsalesdetails && (
1
{`Invoice from ${dayjs(selected.tenantsalesdetails[0].fromdate).format('DD-MM-YYYY')} to ${dayjs(
selected.tenantsalesdetails[0].todate
).format('DD-MM-YYYY')}`}
{selected.tenantsalesdetails[0].pricingtype}
{`${selected.tenantsalesdetails[0].quantity}km`}
{`₹ ${selected.tenantsalesdetails[0].baserate.toFixed(2)}`}
{/* {selected.tenantsalesdetails[0].pricingtypeid == 73 && ( */}
{`₹ ${selected.tenantsalesdetails[0].othercharges}.00`}
{/* )} */}
{`₹ ${selected.tenantsalesdetails[0].amount}.00`}
)}
Sub Total:
{formatNumberToRupees(selected.salesamount)}
Discount:
- {formatNumberToRupees(selected.discountamt)}
Tax:
+ {formatNumberToRupees(selected.taxamount)}
Grand Total:
{formatNumberToRupees(Math.round(selected.totalamount))}
Notes: {selected.remarks}
{/* ================================================= || updatePayment Dialog || ================================================= */}
>
);
};
export default InvoicePreview;