|
|
|
@@ -5,7 +5,7 @@ import SearchBox, { Criterion } from "../SearchBox"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import SearchResults, { Column } from "../SearchResults"; |
|
|
|
import EditNote from "@mui/icons-material/EditNote"; |
|
|
|
import { moneyFormatter } from "@/app/utils/formatUtil" |
|
|
|
import { moneyFormatter, timestampToDateStringV2 } from "@/app/utils/formatUtil" |
|
|
|
import { Button, ButtonGroup, Stack, Tab, Tabs, TabsProps, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, TextField, CardContent, Typography, Divider, Card, ThemeProvider } from "@mui/material"; |
|
|
|
import FileUploadIcon from '@mui/icons-material/FileUpload'; |
|
|
|
import AddIcon from '@mui/icons-material/Add'; |
|
|
|
@@ -62,6 +62,8 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
const { t } = useTranslation("Invoice"); |
|
|
|
|
|
|
|
const [filteredIvoices, setFilterInovices] = useState(invoices); |
|
|
|
const apiRef = useGridApiRef(); |
|
|
|
const [autoRedirectToFirstPage, setAutoRedirectToFirstPage] = useState(true); |
|
|
|
|
|
|
|
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( |
|
|
|
() => [ |
|
|
|
@@ -87,6 +89,7 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
|
|
|
|
const onReset = useCallback(() => { |
|
|
|
// setFilteredIssuedInvoices(issuedInvoice); |
|
|
|
setAutoRedirectToFirstPage(() => true) |
|
|
|
setFilterInovices(invoices) |
|
|
|
}, [invoices]); |
|
|
|
|
|
|
|
@@ -282,12 +285,29 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
|
|
|
|
const handleSaveDialog = async () => { |
|
|
|
// setDialogOpen(false); |
|
|
|
await updateInvoice(selectedRow[0]) |
|
|
|
const response = await updateInvoice(selectedRow[0]) |
|
|
|
setDialogOpen(false); |
|
|
|
|
|
|
|
setAutoRedirectToFirstPage(() => false) |
|
|
|
successDialog(t("Update Success"), t).then(() => { |
|
|
|
window.location.reload() |
|
|
|
// window.location.reload() |
|
|
|
|
|
|
|
setFilterInovices((prev) => { |
|
|
|
const tempInvoices = [...prev] |
|
|
|
const invoiceId = tempInvoices.findIndex((invoice) => invoice.id === response.id) |
|
|
|
if (invoiceId >= 0) { |
|
|
|
const updatedInvoice = tempInvoices[invoiceId] |
|
|
|
updatedInvoice.invoiceNo = response?.invoiceNo |
|
|
|
updatedInvoice.issuedAmount = response?.issuedAmount |
|
|
|
updatedInvoice.issuedDate = timestampToDateStringV2(response.issuedDate)!! |
|
|
|
updatedInvoice.receiptDate = timestampToDateStringV2(response.receiptDate)!! |
|
|
|
updatedInvoice.receivedAmount = response?.receivedAmount |
|
|
|
tempInvoices[invoiceId] = updatedInvoice |
|
|
|
} |
|
|
|
|
|
|
|
return tempInvoices |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
// console.log(selectedRow[0]) |
|
|
|
// setSelectedRow([]); |
|
|
|
}; |
|
|
|
@@ -361,7 +381,7 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
{ field: "invoiceNo", headerName: t("Invoice No"), editable: true, flex: 0.5 }, |
|
|
|
{ field: "projectCode", headerName: t("Project Code"), editable: false, flex: 0.3 }, |
|
|
|
{ field: "projectName", headerName: t("Project Name"), flex: 1 }, |
|
|
|
{ field: "team", headerName: t("Team"), flex: 0.2 }, |
|
|
|
{ field: "team", headerName: t("Team"), flex: 0.4 }, |
|
|
|
{ field: "issuedDate", |
|
|
|
headerName: t("Issue Date"), |
|
|
|
editable: true, |
|
|
|
@@ -450,7 +470,6 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
} |
|
|
|
|
|
|
|
const [rowModesModel, setRowModesModel] = useState<GridRowModesModel>({}); |
|
|
|
const apiRef = useGridApiRef(); |
|
|
|
|
|
|
|
const validateInvoiceEntry = ( |
|
|
|
entry: Partial<invoiceList>, |
|
|
|
@@ -496,18 +515,18 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
(params, event) => { |
|
|
|
// console.log(params.id) |
|
|
|
if (validateRow(params.id) !== undefined || !validateRow(params.id)) { |
|
|
|
|
|
|
|
setRowModesModel((model) => ({ |
|
|
|
...model, |
|
|
|
[params.id]: { mode: GridRowModes.View}, |
|
|
|
})); |
|
|
|
|
|
|
|
const row = apiRef.current.getRowWithUpdatedValues( |
|
|
|
params.id, |
|
|
|
"", |
|
|
|
) |
|
|
|
console.log(row) |
|
|
|
setSelectedRow([{...row}] as invoiceList[]) |
|
|
|
setSelectedRow(() => [{...row}] as invoiceList[]) |
|
|
|
|
|
|
|
setRowModesModel((model) => ({ |
|
|
|
...model, |
|
|
|
[params.id]: { mode: GridRowModes.View}, |
|
|
|
})); |
|
|
|
|
|
|
|
event.defaultMuiPrevented = true; |
|
|
|
} |
|
|
|
// console.log(row) |
|
|
|
@@ -586,6 +605,7 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
&& (query.settled === "All" || (query.settled === t("Settled")) === s.settled) |
|
|
|
), |
|
|
|
); |
|
|
|
setAutoRedirectToFirstPage(() => true) |
|
|
|
}} |
|
|
|
onReset={onReset} |
|
|
|
/> |
|
|
|
@@ -620,7 +640,7 @@ const InvoiceSearch: React.FC<Props> & SubComponents = ({ invoices, projects, ab |
|
|
|
<SearchResults<invoiceList> |
|
|
|
items={filteredIvoices} |
|
|
|
columns={combinedColumns} |
|
|
|
autoRedirectToFirstPage |
|
|
|
autoRedirectToFirstPage={autoRedirectToFirstPage} |
|
|
|
/> |
|
|
|
</ThemeProvider> |
|
|
|
} |
|
|
|
|