From de7361718def0f6bb32294bb074841ba2c0a3ce6 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 21 Feb 2023 16:25:35 +0700 Subject: fix --- src/lib/invoice/api/invoiceApi.js | 10 ++ src/lib/invoice/api/invoicesApi.js | 10 ++ src/lib/invoice/components/Invoice.jsx | 126 +++++++++++++++++++++++++ src/lib/invoice/components/Invoices.jsx | 157 ++++++++++++++++++++++++++++++++ src/lib/invoice/hooks/useInvoice.js | 13 +++ src/lib/invoice/hooks/useInvoices.js | 15 +++ src/lib/invoice/utils/invoices.js | 14 +++ 7 files changed, 345 insertions(+) create mode 100644 src/lib/invoice/api/invoiceApi.js create mode 100644 src/lib/invoice/api/invoicesApi.js create mode 100644 src/lib/invoice/components/Invoice.jsx create mode 100644 src/lib/invoice/components/Invoices.jsx create mode 100644 src/lib/invoice/hooks/useInvoice.js create mode 100644 src/lib/invoice/hooks/useInvoices.js create mode 100644 src/lib/invoice/utils/invoices.js (limited to 'src/lib/invoice') diff --git a/src/lib/invoice/api/invoiceApi.js b/src/lib/invoice/api/invoiceApi.js new file mode 100644 index 00000000..f9bacf8e --- /dev/null +++ b/src/lib/invoice/api/invoiceApi.js @@ -0,0 +1,10 @@ +import odooApi from "@/core/api/odooApi" +import { getAuth } from "@/core/utils/auth" + +const invoiceApi = async ({ id }) => { + const auth = getAuth() + const dataInvoice = await odooApi('GET', `/api/v1/partner/${auth.partnerId}/invoice/${id}`) + return dataInvoice +} + +export default invoiceApi \ No newline at end of file diff --git a/src/lib/invoice/api/invoicesApi.js b/src/lib/invoice/api/invoicesApi.js new file mode 100644 index 00000000..4e842f55 --- /dev/null +++ b/src/lib/invoice/api/invoicesApi.js @@ -0,0 +1,10 @@ +import odooApi from "@/core/api/odooApi" +import { getAuth } from "@/core/utils/auth" + +const invoicesApi = async ({ query }) => { + const auth = getAuth() + const dataInvoices = await odooApi('GET', `/api/v1/partner/${auth.partnerId}/invoice?${query}`) + return dataInvoices +} + +export default invoicesApi \ No newline at end of file diff --git a/src/lib/invoice/components/Invoice.jsx b/src/lib/invoice/components/Invoice.jsx new file mode 100644 index 00000000..de6eacca --- /dev/null +++ b/src/lib/invoice/components/Invoice.jsx @@ -0,0 +1,126 @@ +import Spinner from "@/core/components/elements/Spinner/Spinner" +import useInvoice from "../hooks/useInvoice" +import { downloadInvoice, downloadTaxInvoice } from "../utils/invoices" +import Divider from "@/core/components/elements/Divider/Divider" +import VariantGroupCard from "@/lib/variant/components/VariantGroupCard" +import currencyFormat from "@/core/utils/currencyFormat" + +const Invoice = ({ id }) => { + const { invoice } = useInvoice({ id }) + + if (invoice.isLoading) { + return ( +
+ +
+ ) + } + + const address = invoice.data?.customer + let fullAddress = [] + if (address?.street) fullAddress.push(address.street) + if (address?.subDistrict?.name) fullAddress.push(address.subDistrict.name) + if (address?.district?.name) fullAddress.push(address.district.name) + if (address?.city?.name) fullAddress.push(address.city.name) + fullAddress = fullAddress.join(', ') + + return invoice.data?.name && ( + <> +
+ + { invoice.data?.name } + + + { invoice.data?.amountResidual > 0 ? ( + Belum Lunas + ) : ( + Lunas + ) } + + + { invoice.data?.purchaseOrderName || '-' } + + + { invoice.data?.paymentTerm } + + { invoice.data?.amountResidual > 0 && invoice.invoiceDate != invoice.invoiceDateDue && ( + + { invoice.data?.invoiceDateDue } + + ) } + + { invoice.data?.sales } + + + { invoice.data?.invoiceDate } + +
+

Faktur Pembelian

+ +
+
+

Faktur Pajak

+ +
+
+ + + +
+ Detail Penagihan +
+ +
+ + { address?.name } + + + { address?.email || '-' } + + + { address?.mobile || '-' } + + + { fullAddress } + +
+ + + +
Detail Produk
+ +
+ +
+

Total Belanja

+

{ currencyFormat(invoice.data?.amountTotal) }

+
+
+ + ) +} + +const DescriptionRow = ({ children, label }) => ( +
+ { label } + { children } +
+) + +export default Invoice \ No newline at end of file diff --git a/src/lib/invoice/components/Invoices.jsx b/src/lib/invoice/components/Invoices.jsx new file mode 100644 index 00000000..3b1e71e3 --- /dev/null +++ b/src/lib/invoice/components/Invoices.jsx @@ -0,0 +1,157 @@ +import { CheckIcon, ClockIcon, EllipsisVerticalIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline" +import { toQuery } from "lodash-contrib" +import _ from "lodash" +import { useRouter } from "next/router" +import { useState } from "react" +import useInvoices from "../hooks/useInvoices" +import Spinner from "@/core/components/elements/Spinner/Spinner" +import Alert from "@/core/components/elements/Alert/Alert" +import Pagination from "@/core/components/elements/Pagination/Pagination" +import Link from "@/core/components/elements/Link/Link" +import currencyFormat from "@/core/utils/currencyFormat" +import BottomPopup from "@/core/components/elements/Popup/BottomPopup" +import { downloadInvoice, downloadTaxInvoice } from "../utils/invoices" + +const Invoices = () => { + const router = useRouter() + const { + q = '', + page = 1 + } = router.query + + const limit = 10 + + const query = { + name: q, + offset: (page - 1) * limit, + limit + } + const { invoices } = useInvoices({ query }) + + const [ inputQuery, setInputQuery ] = useState(q) + const [ toOthers, setToOthers ] = useState(null) + + const pageCount = Math.ceil(invoices?.data?.saleOrderTotal / limit) + let pageQuery = _.omit(query, ['limit', 'offset']) + pageQuery = _.pickBy(pageQuery, _.identity) + pageQuery = toQuery(pageQuery) + + const handleSubmit = (e) => { + e.preventDefault() + router.push(`/my/invoices?q=${inputQuery}`) + } + + return ( +
+
+ setInputQuery(e.target.value)} + /> + +
+ + { invoices.isLoading && ( +
+ +
+ ) } + + { !invoices.isLoading && invoices.data?.invoices?.length === 0 && ( + + Tidak ada data transaksi + + ) } + + { invoices.data?.invoices?.map((invoice, index) => ( +
+
+ + No. Invoice +

{ invoice.name }

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

+ { invoice.invoiceDate } +

+

+ { invoice.paymentTerm } +

+
+
+
+
+ No. Purchase Order +

{ invoice.purchaseOrderName || '-' }

+
+
+ Total Invoice +

{ currencyFormat(invoice.amountTotal) }

+
+
+ + { invoice.efaktur ? ( +
+ + Faktur Pajak +
+ ) : ( +
+ + Faktur Pajak +
+ ) } +
+ )) } + + + + setToOthers(null)} + > +
+ + +
+
+
+ ) +} + +export default Invoices \ No newline at end of file diff --git a/src/lib/invoice/hooks/useInvoice.js b/src/lib/invoice/hooks/useInvoice.js new file mode 100644 index 00000000..0e612f2f --- /dev/null +++ b/src/lib/invoice/hooks/useInvoice.js @@ -0,0 +1,13 @@ +import { useQuery } from "react-query" +import invoiceApi from "../api/invoiceApi" + +const useInvoice = ({ id }) => { + const fetchInvoice = async () => await invoiceApi({ id }) + const { data, isLoading, refetch } = useQuery(`invoice-${id}`, fetchInvoice) + + return { + invoice: { data, isLoading, refetch } + } +} + +export default useInvoice \ No newline at end of file diff --git a/src/lib/invoice/hooks/useInvoices.js b/src/lib/invoice/hooks/useInvoices.js new file mode 100644 index 00000000..7bcdc952 --- /dev/null +++ b/src/lib/invoice/hooks/useInvoices.js @@ -0,0 +1,15 @@ +import { useQuery } from "react-query" +import invoicesApi from "../api/invoicesApi" +import _ from "lodash-contrib" + +const useInvoices = ({ query }) => { + const queryString = _.toQuery(query) + const fetchInvoices = async () => await invoicesApi({ query: queryString }) + const { data, isLoading, refetch } = useQuery(`invoices-${queryString}`, fetchInvoices) + + return { + invoices: { data, isLoading, refetch } + } +} + +export default useInvoices \ No newline at end of file diff --git a/src/lib/invoice/utils/invoices.js b/src/lib/invoice/utils/invoices.js new file mode 100644 index 00000000..c152191d --- /dev/null +++ b/src/lib/invoice/utils/invoices.js @@ -0,0 +1,14 @@ +const downloadInvoice = (invoice) => { + const url = `${process.env.ODOO_HOST}/api/v1/download/invoice/${invoice.id}/${invoice.token}` + window.open(url, 'download') +} + +const downloadTaxInvoice = (invoice) => { + const url = `${process.env.ODOO_HOST}/api/v1/download/tax-invoice/${invoice.id}/${invoice.token}` + window.open(url, 'download') +} + +export { + downloadInvoice, + downloadTaxInvoice +} \ No newline at end of file -- cgit v1.2.3 From 04fe185879061b404fe1baa468bf67d32b3fdd5f Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 21 Feb 2023 16:29:04 +0700 Subject: fix --- src/lib/invoice/components/Invoice.jsx | 2 +- src/lib/invoice/components/Invoices.jsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/invoice') diff --git a/src/lib/invoice/components/Invoice.jsx b/src/lib/invoice/components/Invoice.jsx index de6eacca..3e0baaee 100644 --- a/src/lib/invoice/components/Invoice.jsx +++ b/src/lib/invoice/components/Invoice.jsx @@ -55,7 +55,7 @@ const Invoice = ({ id }) => { { invoice.data?.invoiceDate }
-

Faktur Pembelian

+

Invoice

-
-
-

Faktur Pajak

- + + {invoice.data?.purchaseOrderName || '-'} + + {invoice.data?.paymentTerm} + {invoice.data?.amountResidual > 0 && invoice.invoiceDate != invoice.invoiceDateDue && ( + + {invoice.data?.invoiceDateDue} + + )} + {invoice.data?.sales} + {invoice.data?.invoiceDate} +
+

Invoice

+ +
+
+

Faktur Pajak

+ +
- - + -
- Detail Penagihan -
- -
- - { address?.name } - - - { address?.email || '-' } - - - { address?.mobile || '-' } - - - { fullAddress } - -
+
Detail Penagihan
- +
+ {address?.name} + {address?.email || '-'} + {address?.mobile || '-'} + {fullAddress} +
+ + -
Detail Produk
+
Detail Produk
-
- -
-

Total Belanja

-

{ currencyFormat(invoice.data?.amountTotal) }

+
+ +
+

Total Belanja

+

{currencyFormat(invoice.data?.amountTotal)}

+
-
- + + ) ) } const DescriptionRow = ({ children, label }) => ( -
- { label } - { children } +
+ {label} + {children}
) -export default Invoice \ No newline at end of file +export default Invoice diff --git a/src/lib/invoice/components/Invoices.jsx b/src/lib/invoice/components/Invoices.jsx index 37944e33..81521785 100644 --- a/src/lib/invoice/components/Invoices.jsx +++ b/src/lib/invoice/components/Invoices.jsx @@ -1,23 +1,25 @@ -import { CheckIcon, ClockIcon, EllipsisVerticalIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline" -import { toQuery } from "lodash-contrib" -import _ from "lodash" -import { useRouter } from "next/router" -import { useState } from "react" -import useInvoices from "../hooks/useInvoices" -import Spinner from "@/core/components/elements/Spinner/Spinner" -import Alert from "@/core/components/elements/Alert/Alert" -import Pagination from "@/core/components/elements/Pagination/Pagination" -import Link from "@/core/components/elements/Link/Link" -import currencyFormat from "@/core/utils/currencyFormat" -import BottomPopup from "@/core/components/elements/Popup/BottomPopup" -import { downloadInvoice, downloadTaxInvoice } from "../utils/invoices" +import { + CheckIcon, + ClockIcon, + EllipsisVerticalIcon, + MagnifyingGlassIcon +} from '@heroicons/react/24/outline' +import { toQuery } from 'lodash-contrib' +import _ from 'lodash' +import { useRouter } from 'next/router' +import { useState } from 'react' +import useInvoices from '../hooks/useInvoices' +import Spinner from '@/core/components/elements/Spinner/Spinner' +import Alert from '@/core/components/elements/Alert/Alert' +import Pagination from '@/core/components/elements/Pagination/Pagination' +import Link from '@/core/components/elements/Link/Link' +import currencyFormat from '@/core/utils/currencyFormat' +import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import { downloadInvoice, downloadTaxInvoice } from '../utils/invoices' const Invoices = () => { const router = useRouter() - const { - q = '', - page = 1 - } = router.query + const { q = '', page = 1 } = router.query const limit = 10 @@ -28,8 +30,8 @@ const Invoices = () => { } const { invoices } = useInvoices({ query }) - const [ inputQuery, setInputQuery ] = useState(q) - const [ toOthers, setToOthers ] = useState(null) + const [inputQuery, setInputQuery] = useState(q) + const [toOthers, setToOthers] = useState(null) const pageCount = Math.ceil(invoices?.data?.saleOrderTotal / limit) let pageQuery = _.omit(query, ['limit', 'offset']) @@ -39,112 +41,111 @@ const Invoices = () => { const handleSubmit = (e) => { e.preventDefault() router.push(`/my/invoices?q=${inputQuery}`) - } + } return ( -
-
- + + setInputQuery(e.target.value)} /> -
- { invoices.isLoading && ( -
- + {invoices.isLoading && ( +
+
- ) } + )} - { !invoices.isLoading && invoices.data?.invoices?.length === 0 && ( - + {!invoices.isLoading && invoices.data?.invoices?.length === 0 && ( + Tidak ada data invoice - ) } + )} - { invoices.data?.invoices?.map((invoice, index) => ( -
-
+ {invoices.data?.invoices?.map((invoice, index) => ( +
+
- No. Invoice -

{ invoice.name }

+ No. Invoice +

{invoice.name}

-
- { invoice.amountResidual > 0 ? ( -
Belum Lunas
- ) : ( -
Lunas
- ) } - setToOthers(invoice)} /> +
+ {invoice.amountResidual > 0 ? ( +
Belum Lunas
+ ) : ( +
Lunas
+ )} + setToOthers(invoice)} />
-
-

- { invoice.invoiceDate } -

-

- { invoice.paymentTerm } -

+
+

{invoice.invoiceDate}

+

{invoice.paymentTerm}

-
-
+
+
- No. Purchase Order -

{ invoice.purchaseOrderName || '-' }

+ No. Purchase Order +

+ {invoice.purchaseOrderName || '-'} +

-
- Total Invoice -

{ currencyFormat(invoice.amountTotal) }

+
+ Total Invoice +

+ {currencyFormat(invoice.amountTotal)} +

- { invoice.efaktur ? ( -
- + {invoice.efaktur ? ( +
+ Faktur Pajak
- ) : ( -
- + ) : ( +
+ Faktur Pajak
- ) } + )}
- )) } + ))} - setToOthers(null)} - > -
- - @@ -154,4 +155,4 @@ const Invoices = () => { ) } -export default Invoices \ No newline at end of file +export default Invoices diff --git a/src/lib/invoice/hooks/useInvoice.js b/src/lib/invoice/hooks/useInvoice.js index 0e612f2f..2de5e91e 100644 --- a/src/lib/invoice/hooks/useInvoice.js +++ b/src/lib/invoice/hooks/useInvoice.js @@ -1,5 +1,5 @@ -import { useQuery } from "react-query" -import invoiceApi from "../api/invoiceApi" +import { useQuery } from 'react-query' +import invoiceApi from '../api/invoiceApi' const useInvoice = ({ id }) => { const fetchInvoice = async () => await invoiceApi({ id }) @@ -10,4 +10,4 @@ const useInvoice = ({ id }) => { } } -export default useInvoice \ No newline at end of file +export default useInvoice diff --git a/src/lib/invoice/hooks/useInvoices.js b/src/lib/invoice/hooks/useInvoices.js index 7bcdc952..061626e4 100644 --- a/src/lib/invoice/hooks/useInvoices.js +++ b/src/lib/invoice/hooks/useInvoices.js @@ -1,6 +1,6 @@ -import { useQuery } from "react-query" -import invoicesApi from "../api/invoicesApi" -import _ from "lodash-contrib" +import { useQuery } from 'react-query' +import invoicesApi from '../api/invoicesApi' +import _ from 'lodash-contrib' const useInvoices = ({ query }) => { const queryString = _.toQuery(query) @@ -12,4 +12,4 @@ const useInvoices = ({ query }) => { } } -export default useInvoices \ No newline at end of file +export default useInvoices diff --git a/src/lib/invoice/utils/invoices.js b/src/lib/invoice/utils/invoices.js index c152191d..221e53cf 100644 --- a/src/lib/invoice/utils/invoices.js +++ b/src/lib/invoice/utils/invoices.js @@ -8,7 +8,4 @@ const downloadTaxInvoice = (invoice) => { window.open(url, 'download') } -export { - downloadInvoice, - downloadTaxInvoice -} \ No newline at end of file +export { downloadInvoice, downloadTaxInvoice } -- cgit v1.2.3 From ac3fdf7be9982e65d8f83a20bc487f8dd62e3bfc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 23:36:47 +0700 Subject: fix --- src/lib/invoice/components/Invoice.jsx | 5 ++++- src/lib/invoice/components/Invoices.jsx | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'src/lib/invoice') diff --git a/src/lib/invoice/components/Invoice.jsx b/src/lib/invoice/components/Invoice.jsx index eaf7b7e0..e34ad8c2 100644 --- a/src/lib/invoice/components/Invoice.jsx +++ b/src/lib/invoice/components/Invoice.jsx @@ -86,7 +86,10 @@ const Invoice = ({ id }) => {
Detail Produk
- +

Total Belanja

{currencyFormat(invoice.data?.amountTotal)}

diff --git a/src/lib/invoice/components/Invoices.jsx b/src/lib/invoice/components/Invoices.jsx index 81521785..ab318a3c 100644 --- a/src/lib/invoice/components/Invoices.jsx +++ b/src/lib/invoice/components/Invoices.jsx @@ -45,7 +45,10 @@ const Invoices = () => { return (
-
+ { value={inputQuery} onChange={(e) => setInputQuery(e.target.value)} /> -
@@ -65,13 +71,19 @@ const Invoices = () => { )} {!invoices.isLoading && invoices.data?.invoices?.length === 0 && ( - + Tidak ada data invoice )} {invoices.data?.invoices?.map((invoice, index) => ( -
+
No. Invoice @@ -83,7 +95,10 @@ const Invoices = () => { ) : (
Lunas
)} - setToOthers(invoice)} /> + setToOthers(invoice)} + />
@@ -128,7 +143,11 @@ const Invoices = () => { className='mt-2 mb-2' /> - setToOthers(null)}> + setToOthers(null)} + >