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/components/Invoice.jsx | 126 +++++++++++++++++++++++++ src/lib/invoice/components/Invoices.jsx | 157 ++++++++++++++++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100644 src/lib/invoice/components/Invoice.jsx create mode 100644 src/lib/invoice/components/Invoices.jsx (limited to 'src/lib/invoice/components') 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 -- cgit v1.2.3