From 79691a1ed94bcad877c3d5585e8ae9787bd18de0 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 14 Nov 2024 17:13:32 +0700 Subject: add penghajuan tempo --- src/lib/tempo/components/Tempo.jsx | 268 +++++++++++++++++++++++-------------- 1 file changed, 169 insertions(+), 99 deletions(-) (limited to 'src') diff --git a/src/lib/tempo/components/Tempo.jsx b/src/lib/tempo/components/Tempo.jsx index c3cf621c..3f6e36d1 100644 --- a/src/lib/tempo/components/Tempo.jsx +++ b/src/lib/tempo/components/Tempo.jsx @@ -4,10 +4,10 @@ import { EllipsisVerticalIcon, MagnifyingGlassIcon, } from '@heroicons/react/24/outline'; -import { toQuery } from 'lodash-contrib'; +import { div, toQuery } from 'lodash-contrib'; import _ from 'lodash'; import { useRouter } from 'next/router'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import useInvoices from '../../invoice/hooks/useInvoices'; import Spinner from '@/core/components/elements/Spinner/Spinner'; import Alert from '@/core/components/elements/Alert/Alert'; @@ -22,8 +22,11 @@ import { import MobileView from '@/core/components/views/MobileView'; import DesktopView from '@/core/components/views/DesktopView'; import Menu from '@/lib/auth/components/Menu'; - +import odooApi from '@/core/api/odooApi'; +import { getAuth } from '@/core/utils/auth'; +import ProgressBar from '@ramonak/react-progress-bar'; const Tempo = () => { + const auth = getAuth(); const router = useRouter(); const { q = '', page = 1 } = router.query; @@ -36,6 +39,8 @@ const Tempo = () => { }; const { invoices } = useInvoices({ query }); + const [isLoading, setIsLoading] = useState(true); + const [tempo, setTempo] = useState([]); const [inputQuery, setInputQuery] = useState(q); const [toOthers, setToOthers] = useState(null); @@ -48,9 +53,169 @@ const Tempo = () => { e.preventDefault(); router.push(`/my/invoices?q=${inputQuery}`); }; - + useEffect(() => { + const loadTempo = async () => { + setIsLoading(true); + const dataTempo = await odooApi( + 'GET', + `/api/v1/check/${auth.parentId}/tempo` + ); + setTempo(dataTempo); + setIsLoading(false); + }; + loadTempo(); + }, []); + const limitTempo = Math.round( + parseInt(tempo.amountDue + tempo.remainingLimit) + ); + const amountDue = Math.round(parseInt(tempo.amountDue)); + console.log('tempo', tempo); + const getLabel = () => { + if (Math.round((amountDue / limitTempo) * 100) >= 100) + return 'Limit Tempo mencapai batas'; + if (Math.round((amountDue / limitTempo) * 100) >= 50) return 'Hampir Habis'; + return ''; + }; return ( <> + +
+
+ +
+
+
+

Pembayaran Tempo

+

+ Jenis Tempo Pembayaran Anda adalah :{' '} + {!isLoading && ( + + {tempo.paymentTerm} + + )} +

+
+
+
+

Limit Tempo Terpakai

+

{!isLoading && currencyFormat(amountDue)}

+
+
+

Limit Tempo

+

{!isLoading && currencyFormat(limitTempo)}

+
+
+ +
+ + + {getLabel()} + +
+ +
+
+ + setInputQuery(e.target.value)} + /> +
+
+ + + + + + + + + + + + + + + {invoices.isLoading && ( + + + + )} + {!invoices.isLoading && + (!invoices?.data?.invoices || + invoices?.data?.invoices?.length == 0) && ( + + + + )} + {invoices.data?.invoices?.map((invoice) => ( + + + + + + + + + + ))} + +
No. InvoiceNo. TransaksiSalespersonTanggalJatuh TempoStatusTotal
+
+ +
+
Tidak ada invoice
+ + {invoice.name} + + {invoice.purchaseOrderName || '-'}{invoice.sales}{invoice.invoiceDate} + {invoice.amountResidual > 0 ? ( +
+ Belum Lunas +
+ ) : ( +
+ Lunas +
+ )} +
+ {invoice.amountResidual > 0 ? ( +
+ Belum Lunas +
+ ) : ( +
+ Lunas +
+ )} +
+ {currencyFormat(invoice.amountTotal)} +
+ + +
+
+
@@ -179,101 +344,6 @@ const Tempo = () => {
- - -
-
- -
-
-
-

Pembayaran Tempo

-

- Jenis Tempo Pembayaran Anda adalah :{' '} - 7 Hari -

-
-
- - setInputQuery(e.target.value)} - /> - - -
- - - - - - - - - - - - - - {invoices.isLoading && ( - - - - )} - {!invoices.isLoading && - (!invoices?.data?.invoices || - invoices?.data?.invoices?.length == 0) && ( - - - - )} - {invoices.data?.invoices?.map((invoice) => ( - - - - - - - - - ))} - -
No. InvoiceNo. POTanggalSalespersonStatusTotal
-
- -
-
Tidak ada invoice
- - {invoice.name} - - {invoice.purchaseOrderName || '-'}{invoice.invoiceDate}{invoice.sales} - {invoice.amountResidual > 0 ? ( -
- Belum Lunas -
- ) : ( -
- Lunas -
- )} -
- {currencyFormat(invoice.amountTotal)} -
- - -
-
-
); }; -- cgit v1.2.3