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 + src/lib/transaction/components/Transaction.jsx | 377 ++++++++++++------------ src/lib/transaction/components/Transactions.jsx | 133 +++++---- 9 files changed, 598 insertions(+), 257 deletions(-) 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') 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 diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx index 143b24bb..e049a9ac 100644 --- a/src/lib/transaction/components/Transaction.jsx +++ b/src/lib/transaction/components/Transaction.jsx @@ -77,216 +77,213 @@ const Transaction = ({ id }) => { transaction.refetch() } - return ( - <> - { transaction.isLoading && ( -
- -
- ) } + if (transaction.isLoading) { + return ( +
+ +
+ ) + } - { transaction.data?.name && ( - <> -
- -
- -
-
- - { transaction.data?.name } - - - { transaction.data?.paymentTerm } - - - { transaction.data?.sales } - - - { transaction.data?.dateOrder } - + return transaction.data?.name && ( + <> +
+ +
+
- - +
+ + { transaction.data?.name } + + + { transaction.data?.paymentTerm } + + + { transaction.data?.sales } + + + { transaction.data?.dateOrder } + +
+ + -
- - { transaction.data?.purchaseOrderName || '-' } - -
-

Dokumen PO

- -
-
+
+ + { transaction.data?.purchaseOrderName || '-' } + +
+

Dokumen PO

+ +
+
- + -
Detail Produk
+
Detail Produk
-
- -
-

Total Belanja

-

{ currencyFormat(transaction.data?.amountTotal) }

-
-
+
+ +
+

Total Belanja

+

{ currencyFormat(transaction.data?.amountTotal) }

+
+
- - - toggleSection('customer')} - /> + + + toggleSection('customer')} + /> - { section.customer && } + { section.customer && } - - - toggleSection('shipping')} - /> + + + toggleSection('shipping')} + /> - { section.shipping && } + { section.shipping && } - - - toggleSection('invoice')} - /> + + + toggleSection('invoice')} + /> - { section.invoice && } + { section.invoice && } - + -
-

Invoice

-
- { transaction.data?.invoices?.map((invoice, index) => ( - -
-
-

{ invoice?.name }

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

- { currencyFormat(invoice.amountTotal) } -

-
-
- +
+

Invoice

+
+ { transaction.data?.invoices?.map((invoice, index) => ( + +
+
+

{ invoice?.name }

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

+ { currencyFormat(invoice.amountTotal) } +

- - )) } - { transaction.data?.invoices?.length === 0 && ( - - Belum ada Invoice - - ) } -
-
- - +
+ +
+ + )) } + { transaction.data?.invoices?.length === 0 && ( + + Belum ada Invoice + + ) } +
+
-
- { transaction.data?.status == 'draft' && ( - - ) } - - { transaction.data?.status != 'draft' && ( - - ) } -
+ - + { transaction.data?.status == 'draft' && ( + + ) } + + { transaction.data?.status != 'draft' && ( + - -
- + Batalkan Transaksi + + ) } +
- +
+ Apakah anda yakin membatalkan transaksi {transaction.data?.name}? +
+
+ - -
-
- - )} + Ya, Batalkan + + + + + +
+ + +
+
+ + +
+
+ + +
+
) } @@ -305,7 +302,7 @@ const SectionButton = ({ label, active, toggle }) => ( const SectionContent = ({ address }) => { let fullAddress = [] if (address?.street) fullAddress.push(address.street) - if (address?.sub_district?.name) fullAddress.push(address.sub_district.name) + if (address?.subDistrict?.name) fullAddress.push(address.sub_district.name) if (address?.district?.name) fullAddress.push(address.district.name) if (address?.city?.name) fullAddress.push(address.city.name) fullAddress = fullAddress.join(', ') diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx index 25a6076a..280e8fc5 100644 --- a/src/lib/transaction/components/Transactions.jsx +++ b/src/lib/transaction/components/Transactions.jsx @@ -58,79 +58,78 @@ const Transactions = () => { } return ( -
-
-
- setInputQuery(e.target.value)} - /> - -
- { transactions.isLoading && ( -
- -
- ) } +
+
+ setInputQuery(e.target.value)} + /> + +
+ + { transactions.isLoading && ( +
+ +
+ ) } - { !transactions.isLoading && transactions.data?.saleOrders?.length === 0 && ( - - Tidak ada data transaksi - - ) } + { !transactions.isLoading && transactions.data?.saleOrders?.length === 0 && ( + + Tidak ada data transaksi + + ) } - { transactions.data?.saleOrders?.map((saleOrder, index) => ( -
-
- - No. Transaksi -

{ saleOrder.name }

- -
- - setToOthers(saleOrder)} /> + { transactions.data?.saleOrders?.map((saleOrder, index) => ( +
+
+ + No. Transaksi +

{ saleOrder.name }

+ +
+ + setToOthers(saleOrder)} /> +
+
+ +
+
+ No. Purchase Order +

{ saleOrder.purchaseOrderName || '-' }

+
+
+ Total Invoice +

{ saleOrder.invoiceCount } Invoice

- -
-
- No. Purchase Order -

{ saleOrder.purchaseOrderName || '-' }

-
-
- Total Invoice -

{ saleOrder.invoiceCount } Invoice

-
+
+
+ Sales +

{ saleOrder.sales }

-
-
- Sales -

{ saleOrder.sales }

-
-
- Total Harga -

{ currencyFormat(saleOrder.amountTotal) }

-
+
+ Total Harga +

{ currencyFormat(saleOrder.amountTotal) }

- -
- )) } - - -
+
+ +
+ )) } + + setToOthers(null)}>
-- cgit v1.2.3