profit loss pdf
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
import DateRangePicker from '@/components/RangeDatePicker'
|
||||
import { ReportItem, ReportItemFooter, ReportItemHeader, ReportItemSubheader } from '@/components/report/ReportItem'
|
||||
import { ExcelExportProfitLossService } from '@/services/export/excel/ExcelExportProfitLossService'
|
||||
import { PDFExportProfitLossService } from '@/services/export/pdf/PDFExportProfitLossService'
|
||||
import { ProfitLossReport } from '@/types/services/analytic'
|
||||
import { Button, Card, CardContent, Box } from '@mui/material'
|
||||
import { Button, Card, CardContent, Box, Menu, MenuItem, ListItemIcon, ListItemText } from '@mui/material'
|
||||
|
||||
import { useState } from 'react'
|
||||
|
||||
interface ReportProfitLossContentProps {
|
||||
profitData: ProfitLossReport | undefined
|
||||
@@ -31,23 +34,52 @@ const ReportProfitLossContent = ({
|
||||
onStartDateChange,
|
||||
onEndDateChange
|
||||
}: ReportProfitLossContentProps) => {
|
||||
const handleExport = async () => {
|
||||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null)
|
||||
const open = Boolean(anchorEl)
|
||||
|
||||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
setAnchorEl(event.currentTarget)
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null)
|
||||
}
|
||||
const handleExportExcel = async () => {
|
||||
if (!profitData) return
|
||||
handleClose()
|
||||
|
||||
try {
|
||||
const result = await ExcelExportProfitLossService.exportProfitLossToExcel(profitData)
|
||||
|
||||
if (result.success) {
|
||||
// Optional: Show success notification
|
||||
console.log('Export successful:', result.filename)
|
||||
// You can add toast notification here
|
||||
console.log('Excel export successful:', result.filename)
|
||||
} else {
|
||||
console.error('Export failed:', result.error)
|
||||
alert('Export gagal. Silakan coba lagi.')
|
||||
console.error('Excel export failed:', result.error)
|
||||
alert('Export Excel gagal. Silakan coba lagi.')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Export error:', error)
|
||||
alert('Terjadi kesalahan saat export.')
|
||||
console.error('Excel export error:', error)
|
||||
alert('Terjadi kesalahan saat export Excel.')
|
||||
}
|
||||
}
|
||||
|
||||
const handleExportPDF = async () => {
|
||||
if (!profitData) return
|
||||
handleClose()
|
||||
|
||||
try {
|
||||
const result = await PDFExportProfitLossService.exportProfitLossToPDF(profitData)
|
||||
|
||||
if (result.success) {
|
||||
console.log('PDF export successful:', result.filename)
|
||||
// Optional: Show success notification
|
||||
} else {
|
||||
console.error('PDF export failed:', result.error)
|
||||
alert('Export PDF gagal. Silakan coba lagi.')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('PDF export error:', error)
|
||||
alert('Terjadi kesalahan saat export PDF.')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,13 +90,43 @@ const ReportProfitLossContent = ({
|
||||
<Button
|
||||
color='secondary'
|
||||
variant='tonal'
|
||||
startIcon={<i className='tabler-upload' />}
|
||||
startIcon={<i className='tabler-download' />}
|
||||
endIcon={<i className='tabler-chevron-down' />}
|
||||
className='max-sm:is-full'
|
||||
onClick={handleExport}
|
||||
onClick={handleClick}
|
||||
disabled={!profitData}
|
||||
aria-controls={open ? 'export-menu' : undefined}
|
||||
aria-haspopup='true'
|
||||
aria-expanded={open ? 'true' : undefined}
|
||||
>
|
||||
Ekspor
|
||||
Export
|
||||
</Button>
|
||||
|
||||
<Menu
|
||||
id='export-menu'
|
||||
anchorEl={anchorEl}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
MenuListProps={{
|
||||
'aria-labelledby': 'export-button'
|
||||
}}
|
||||
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
|
||||
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
|
||||
>
|
||||
<MenuItem onClick={handleExportExcel}>
|
||||
<ListItemIcon>
|
||||
<i className='tabler-file-type-xls text-green-600' />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Export to Excel</ListItemText>
|
||||
</MenuItem>
|
||||
|
||||
<MenuItem onClick={handleExportPDF}>
|
||||
<ListItemIcon>
|
||||
<i className='tabler-file-type-pdf text-red-600' />
|
||||
</ListItemIcon>
|
||||
<ListItemText>Export to PDF</ListItemText>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<DateRangePicker
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
|
||||
Reference in New Issue
Block a user