From 902e5dabbb1ab0612764983c094af398e5f636ee Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 26 Jan 2023 17:02:02 +0700 Subject: Invoice and invoice detail --- src/pages/my/invoices.js | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/pages/my/invoices.js (limited to 'src/pages/my/invoices.js') diff --git a/src/pages/my/invoices.js b/src/pages/my/invoices.js new file mode 100644 index 00000000..e136f4fd --- /dev/null +++ b/src/pages/my/invoices.js @@ -0,0 +1,124 @@ +import WithAuth from "@/components/auth/WithAuth"; +import Alert from "@/components/elements/Alert"; +import Link from "@/components/elements/Link"; +import AppBar from "@/components/layouts/AppBar"; +import Layout from "@/components/layouts/Layout"; +import apiOdoo from "@/core/utils/apiOdoo"; +import { useAuth } from "@/core/utils/auth"; +import currencyFormat from "@/core/utils/currencyFormat"; +import { EllipsisVerticalIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; +import { useRouter } from "next/router"; +import { useEffect, useRef, useState } from "react"; + +export default function Invoices() { + const [ auth ] = useAuth(); + const router = useRouter(); + const { + q, + page = 1 + } = router.query; + + const [ invoices, setInvoices ] = useState([]); + const [ activePopupId, setActivePopupId ] = useState(null); + + const [ pageCount, setPageCount ] = useState(0); + const [ isLoading, setIsLoading ] = useState(true); + + const searchQueryRef = useRef(); + + useEffect(() => { + const loadInvoices = async () => { + if (auth) { + const limit = 10; + let offset = (page - 1) * 10; + let queryParams = [`limit=${limit}`, `offset=${offset}`]; + if (q) queryParams.push(`name=${q}`); + queryParams = queryParams.join('&'); + queryParams = queryParams ? '?' + queryParams : ''; + + const dataInvoices = await apiOdoo('GET', `/api/v1/partner/${auth.partner_id}/invoice${queryParams}`); + setInvoices(dataInvoices); + setPageCount(Math.ceil(dataInvoices.sale_order_total / limit)); + setIsLoading(false); + }; + }; + loadInvoices(); + }, [ auth, q, page ]); + + const actionSearch = (e) => { + e.preventDefault(); + let queryParams = []; + if (searchQueryRef.current.value) queryParams.push(`q=${searchQueryRef.current.value}`); + queryParams = queryParams.join('&'); + queryParams = queryParams ? `?${queryParams}` : ''; + router.push(`/my/invoices${queryParams}`); + }; + + return ( + + + + +
+ + +
+ +
+ { invoices?.invoice_total === 0 && !isLoading && ( + + Invoice tidak ditemukan + + ) } + { invoices?.invoices?.map((invoice, index) => ( +
+
+ + No. Transaksi +

{ invoice.name }

+ +
+ { invoice.amount_residual > 0 ? ( +
Belum Lunas
+ ) : ( +
Lunas
+ ) } + {}} /> +
+
+ +
+

+ { invoice.invoice_date } +

+

+ { invoice.payment_term } +

+
+
+
+
+ Nomor PO +

{ invoice.purchase_order_name || '-' }

+
+
+ Total Invoice +

{ currencyFormat(invoice.amount_total) }

+
+
+ +
+ )) } +
+
+
+ ); +} \ No newline at end of file -- cgit v1.2.3