2025-07-02 08:57:09 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2025-05-17 19:12:01 +00:00
|
|
|
|
2025-07-02 08:57:09 +00:00
|
|
|
import { AG_GRID_LOCALE_ES } from "@ag-grid-community/locale";
|
|
|
|
|
// Grid
|
|
|
|
|
import type { ColDef, GridOptions, ValueFormatterParams } from "ag-grid-community";
|
2025-05-17 19:12:01 +00:00
|
|
|
import { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
|
|
|
|
|
|
|
|
|
|
ModuleRegistry.registerModules([AllCommunityModule]);
|
|
|
|
|
|
2025-07-02 08:57:09 +00:00
|
|
|
import { MoneyDTO } from "@erp/core";
|
|
|
|
|
import { formatDate, formatMoney } from "@erp/core/client";
|
2025-05-17 19:47:08 +00:00
|
|
|
// Core CSS
|
|
|
|
|
import { AgGridReact } from "ag-grid-react";
|
2025-06-24 18:38:57 +00:00
|
|
|
import { useCustomerInvoicesQuery } from "../hooks";
|
2025-05-17 19:47:08 +00:00
|
|
|
|
2025-05-17 19:12:01 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch example Json data
|
|
|
|
|
* Not recommended for production use!
|
|
|
|
|
*/
|
|
|
|
|
export const useFetchJson = <T,>(url: string, limit?: number) => {
|
|
|
|
|
const [data, setData] = useState<T[]>();
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
|
|
|
|
// Note error handling is omitted here for brevity
|
|
|
|
|
const response = await fetch(url);
|
|
|
|
|
const json = await response.json();
|
|
|
|
|
const data = limit ? json.slice(0, limit) : json;
|
|
|
|
|
setData(data);
|
|
|
|
|
setLoading(false);
|
|
|
|
|
};
|
|
|
|
|
fetchData();
|
|
|
|
|
}, [url, limit]);
|
|
|
|
|
return { data, loading };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Row Data Interface
|
|
|
|
|
interface IRow {
|
|
|
|
|
mission: string;
|
|
|
|
|
company: string;
|
|
|
|
|
location: string;
|
|
|
|
|
date: string;
|
|
|
|
|
time: string;
|
|
|
|
|
rocket: string;
|
|
|
|
|
price: number;
|
|
|
|
|
successful: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create new GridExample component
|
2025-06-11 15:13:44 +00:00
|
|
|
export const CustomerInvoicesGrid = () => {
|
|
|
|
|
//const { useList } = useCustomerInvoices();
|
2025-05-20 10:08:24 +00:00
|
|
|
|
2025-06-24 18:38:57 +00:00
|
|
|
const { data, isLoading, isPending, isError, error } = useCustomerInvoicesQuery({});
|
2025-05-17 19:12:01 +00:00
|
|
|
|
|
|
|
|
// Column Definitions: Defines & controls grid columns.
|
|
|
|
|
const [colDefs] = useState<ColDef[]>([
|
2025-07-02 08:57:09 +00:00
|
|
|
{ field: "invoice_number", headerName: "Num. factura" },
|
|
|
|
|
{ field: "invoice_series", headerName: "Serie" },
|
2025-05-17 19:12:01 +00:00
|
|
|
{
|
2025-07-02 08:57:09 +00:00
|
|
|
field: "invoice_status",
|
|
|
|
|
filter: true,
|
|
|
|
|
headerName: "Estado",
|
2025-05-27 17:47:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
2025-07-02 08:57:09 +00:00
|
|
|
field: "issue_date",
|
|
|
|
|
headerName: "Fecha fact.",
|
|
|
|
|
valueFormatter: (params: ValueFormatterParams) => {
|
|
|
|
|
return formatDate(params.value);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: "subtotal_price",
|
2025-05-27 17:47:03 +00:00
|
|
|
valueFormatter: (params: ValueFormatterParams) => {
|
2025-07-02 08:57:09 +00:00
|
|
|
const rawValue: MoneyDTO = params.value;
|
|
|
|
|
return formatMoney(rawValue);
|
2025-05-27 17:47:03 +00:00
|
|
|
},
|
2025-05-17 19:12:01 +00:00
|
|
|
},
|
|
|
|
|
{
|
2025-07-02 08:57:09 +00:00
|
|
|
field: "total_price",
|
2025-05-17 19:12:01 +00:00
|
|
|
valueFormatter: (params: ValueFormatterParams) => {
|
2025-07-02 08:57:09 +00:00
|
|
|
const rawValue: MoneyDTO = params.value;
|
|
|
|
|
return formatMoney(rawValue);
|
2025-05-17 19:12:01 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
2025-07-02 08:57:09 +00:00
|
|
|
const gridOptions: GridOptions = {
|
|
|
|
|
columnDefs: colDefs,
|
|
|
|
|
defaultColDef: {
|
|
|
|
|
editable: true,
|
|
|
|
|
flex: 1,
|
|
|
|
|
minWidth: 100,
|
|
|
|
|
filter: false,
|
2025-05-18 11:53:00 +00:00
|
|
|
sortable: false,
|
2025-07-02 08:57:09 +00:00
|
|
|
resizable: true,
|
|
|
|
|
},
|
|
|
|
|
sideBar: true,
|
|
|
|
|
statusBar: {
|
|
|
|
|
statusPanels: [
|
|
|
|
|
{ statusPanel: "agTotalAndFilteredRowCountComponent", align: "left" },
|
|
|
|
|
{ statusPanel: "agAggregationComponent" },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
rowGroupPanelShow: "always",
|
|
|
|
|
pagination: true,
|
|
|
|
|
paginationPageSize: 10,
|
|
|
|
|
paginationPageSizeSelector: [10, 20, 30, 50],
|
|
|
|
|
enableCharts: true,
|
|
|
|
|
localeText: AG_GRID_LOCALE_ES,
|
|
|
|
|
rowSelection: { mode: "multiRow" },
|
|
|
|
|
};
|
2025-05-17 19:12:01 +00:00
|
|
|
|
|
|
|
|
// Container: Defines the grid's theme & dimensions.
|
|
|
|
|
return (
|
2025-05-18 11:53:00 +00:00
|
|
|
<div
|
2025-05-20 10:08:24 +00:00
|
|
|
className='ag-theme-alpine'
|
|
|
|
|
style={{
|
|
|
|
|
height: "100%",
|
|
|
|
|
width: "100%",
|
|
|
|
|
}}
|
2025-05-18 11:53:00 +00:00
|
|
|
>
|
2025-07-02 08:57:09 +00:00
|
|
|
<AgGridReact rowData={data?.items ?? []} loading={isLoading || isPending} {...gridOptions} />
|
2025-05-17 19:12:01 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|