diff --git a/resources/js/components/charts/bar-chart.tsx b/resources/js/components/charts/bar-chart.tsx index df42eef..96ed637 100644 --- a/resources/js/components/charts/bar-chart.tsx +++ b/resources/js/components/charts/bar-chart.tsx @@ -2,6 +2,7 @@ import React, { useMemo } from "react" import { Bar, BarChart, CartesianGrid, LabelList, XAxis, YAxis } from "recharts" +import { formatCurrency } from "@/lib/formatters" import { Card, @@ -62,7 +63,7 @@ export const CustomBarChart = React.memo(function CustomBarChart({ return val; } - return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(val); + return formatCurrency(val); }; return ( diff --git a/resources/js/pages/admin/finance/expense/partials/columns.tsx b/resources/js/pages/admin/finance/expense/partials/columns.tsx index 2f74497..514f815 100644 --- a/resources/js/pages/admin/finance/expense/partials/columns.tsx +++ b/resources/js/pages/admin/finance/expense/partials/columns.tsx @@ -3,6 +3,7 @@ import { Pencil, Trash2, ImagePlus } from 'lucide-react'; import { DataTableColumnHeader } from '@/components/data-table-column-header'; import { Button } from '@/components/ui/button'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; +import { formatDate, formatCurrency } from '@/lib/formatters'; import type { Expense } from '@/types'; interface ColumnProps { @@ -11,13 +12,6 @@ interface ColumnProps { onPreviewImage: (url: string) => void; } -const formatCurrency = (amount: number) => { - return new Intl.NumberFormat('id-ID', { - style: 'currency', - currency: 'IDR', - minimumFractionDigits: 0, - }).format(amount); -}; export const getColumns = ({ onEdit, onDelete, onPreviewImage }: ColumnProps): ColumnDef[] => [ { @@ -66,11 +60,7 @@ export const getColumns = ({ onEdit, onDelete, onPreviewImage }: ColumnProps): C header: ({ column }) => ( ), - cell: ({ row }) => new Date(row.original.created_at).toLocaleDateString('id-ID', { - day: '2-digit', - month: 'long', - year: 'numeric' - }), + cell: ({ row }) => formatDate(row.original.created_at), meta: { title: "Tanggal" }, }, { diff --git a/resources/js/pages/admin/manage/order/create.tsx b/resources/js/pages/admin/manage/order/create.tsx index 46e876e..c6da681 100644 --- a/resources/js/pages/admin/manage/order/create.tsx +++ b/resources/js/pages/admin/manage/order/create.tsx @@ -31,6 +31,7 @@ import { SheetTrigger } from "@/components/ui/sheet"; import { cn } from '@/lib/utils'; +import { formatCurrency, formatNumber } from '@/lib/formatters'; import * as orderRoutes from '@/routes/order'; import type { Product } from '@/types'; import type { OrderItem } from '@/types/order'; @@ -238,7 +239,7 @@ return;

- Rp {item.total.toLocaleString('id-ID')} + {formatCurrency(item.total)}

@@ -260,7 +261,7 @@ return; × - Rp {item.price.toLocaleString('id-ID')} + {formatCurrency(item.price)} @@ -327,7 +328,7 @@ return;
Subtotal - Rp {subtotal.toLocaleString('id-ID')} + {formatCurrency(subtotal)}
Potongan / Diskon @@ -351,7 +352,7 @@ return;
Total - Rp {total.toLocaleString('id-ID')} + {formatCurrency(total)}
@@ -375,7 +376,7 @@ return; {change >= 0 && (Number(data.payment) || 0) > 0 && (
Kembalian - Rp {change.toLocaleString('id-ID')} + {formatCurrency(change)}
)}
@@ -509,7 +510,7 @@ return;
Harga - Rp {currentPrice.toLocaleString('id-ID')} + {formatCurrency(currentPrice)}
@@ -597,7 +598,7 @@ return;

Total

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

diff --git a/resources/js/pages/admin/manage/order/edit.tsx b/resources/js/pages/admin/manage/order/edit.tsx index c84f2af..22b8845 100644 --- a/resources/js/pages/admin/manage/order/edit.tsx +++ b/resources/js/pages/admin/manage/order/edit.tsx @@ -30,6 +30,7 @@ import { SheetTrigger } from "@/components/ui/sheet"; import { cn } from '@/lib/utils'; +import { formatCurrency, formatNumber } from '@/lib/formatters'; import * as orderRoutes from '@/routes/order'; import type { Product } from '@/types'; import type { Order } from '@/types/order'; @@ -248,7 +249,7 @@ return;

- Rp {item.total.toLocaleString('id-ID')} + {formatCurrency(item.total)}

@@ -270,7 +271,7 @@ return; × - Rp {item.price.toLocaleString('id-ID')} + {formatCurrency(item.price)} @@ -331,7 +332,7 @@ return;
Subtotal - Rp {subtotal.toLocaleString('id-ID')} + {formatCurrency(subtotal)}
Potongan / Diskon @@ -356,7 +357,7 @@ return;
Total - Rp {total.toLocaleString('id-ID')} + {formatCurrency(total)}
@@ -379,7 +380,7 @@ return; {change >= 0 && data.payment > 0 && (
Kembalian - Rp {change.toLocaleString('id-ID')} + {formatCurrency(change)}
)}
@@ -513,7 +514,7 @@ return;
Harga - Rp {currentPrice.toLocaleString('id-ID')} + {formatCurrency(currentPrice)}
@@ -591,7 +592,7 @@ return;

Total

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

diff --git a/resources/js/pages/admin/manage/order/hooks/use-order-print.ts b/resources/js/pages/admin/manage/order/hooks/use-order-print.ts index dc7c636..3399463 100644 --- a/resources/js/pages/admin/manage/order/hooks/use-order-print.ts +++ b/resources/js/pages/admin/manage/order/hooks/use-order-print.ts @@ -4,6 +4,7 @@ import { useCallback } from 'react'; import { toast } from 'sonner'; import { usePrinter } from '@/hooks/use-printer'; import { EscPosEncoder } from '@/lib/esc-pos-encoder'; +import { formatCurrency } from '@/lib/formatters'; import type { Order } from '@/types/order'; export function useOrderPrint() { @@ -62,7 +63,7 @@ export function useOrderPrint() { if (discountAmount > 0) { const discountLabel = 'Diskon:'; - const discountVal = `- Rp ${discountAmount.toLocaleString('id-ID')}`; + const discountVal = `- ${formatCurrency(discountAmount)}`; const dSpaces = width - discountLabel.length - discountVal.length; result.line(discountLabel + ' '.repeat(Math.max(0, dSpaces)) + discountVal); } diff --git a/resources/js/pages/admin/manage/purchase/create.tsx b/resources/js/pages/admin/manage/purchase/create.tsx index b771714..772d42d 100644 --- a/resources/js/pages/admin/manage/purchase/create.tsx +++ b/resources/js/pages/admin/manage/purchase/create.tsx @@ -34,6 +34,7 @@ import { SheetClose, } from "@/components/ui/sheet"; import { cn } from '@/lib/utils'; +import { formatCurrency, formatNumber } from '@/lib/formatters'; import purchaseRoutes from '@/routes/purchase'; import type { Product, ProductPrice } from '@/types'; @@ -213,7 +214,7 @@ return;

{item.product.name}

- Rp {(item.quantity * item.unit_price).toLocaleString('id-ID')} + {formatCurrency(item.quantity * item.unit_price)}

@@ -297,7 +298,7 @@ return;

Total Belanja

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

{cartItems.length} produk

@@ -521,7 +522,7 @@ return;

{item.product.name}

- Rp {(item.quantity * item.unit_price).toLocaleString('id-ID')} + {formatCurrency(item.quantity * item.unit_price)}

@@ -602,7 +603,7 @@ return;

Total Belanja

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

{cartItems.length} produk

@@ -644,7 +645,7 @@ return;

Total

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

@@ -699,7 +700,7 @@ return;

{item.product.name}

- Rp {(item.quantity * item.unit_price).toLocaleString('id-ID')} + {formatCurrency(item.quantity * item.unit_price)}

@@ -778,7 +779,7 @@ return;

Total Belanja

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

{cartItems.length} produk

diff --git a/resources/js/pages/admin/manage/purchase/edit.tsx b/resources/js/pages/admin/manage/purchase/edit.tsx index 6d80024..4a9a5cd 100644 --- a/resources/js/pages/admin/manage/purchase/edit.tsx +++ b/resources/js/pages/admin/manage/purchase/edit.tsx @@ -34,6 +34,7 @@ import { SheetClose, } from "@/components/ui/sheet"; import { cn } from '@/lib/utils'; +import { formatCurrency, formatNumber } from '@/lib/formatters'; import purchaseRoutes from '@/routes/purchase'; import type { Product, ProductPrice, Purchase } from '@/types'; @@ -218,7 +219,7 @@ return;

{item.product?.name}

- Rp {(item.quantity * item.unit_price).toLocaleString('id-ID')} + {formatCurrency(item.quantity * item.unit_price)}

@@ -302,7 +303,7 @@ return;

Total Belanja

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

{data.items.length} produk

@@ -526,7 +527,7 @@ return;

{item.product?.name}

- Rp {(item.quantity * item.unit_price).toLocaleString('id-ID')} + {formatCurrency(item.quantity * item.unit_price)}

@@ -608,7 +609,7 @@ return;

Total Belanja

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

{data.items.length} produk

@@ -650,7 +651,7 @@ return;

Total

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

@@ -705,7 +706,7 @@ return;

{item.product?.name}

- Rp {(item.quantity * item.unit_price).toLocaleString('id-ID')} + {formatCurrency(item.quantity * item.unit_price)}

@@ -784,7 +785,7 @@ return;

Total Belanja

-

Rp {total.toLocaleString('id-ID')}

+

{formatCurrency(total)}

{data.items.length} produk

diff --git a/resources/js/pages/analysis.tsx b/resources/js/pages/analysis.tsx index fd7fd4c..d30796f 100644 --- a/resources/js/pages/analysis.tsx +++ b/resources/js/pages/analysis.tsx @@ -8,6 +8,7 @@ import type { AnalysisPageProps } from '@/types'; import { Head, router, usePage } from '@inertiajs/react'; import { CalendarIcon, Filter, FilterX } from 'lucide-react'; import { useState } from 'react'; +import { formatDate } from '@/lib/formatters'; import { AovTrendChart } from '../components/charts/aov-trend-chart'; import { CustomBarChart } from '../components/charts/bar-chart'; import { CustomPieChart } from '../components/charts/pie-chart'; @@ -26,14 +27,6 @@ export default function Analisa() { const [isStartOpen, setIsStartOpen] = useState(false); const [isEndOpen, setIsEndOpen] = useState(false); - const formatDate = (dateStr: string) => { - if (!dateStr) return null; - return new Intl.DateTimeFormat("id-ID", { - day: "numeric", - month: "long", - year: "numeric", - }).format(new Date(dateStr)); - }; const formatToYmd = (date: Date) => { return date.getFullYear() + "-" + String(date.getMonth() + 1).padStart(2, '0') + "-" + String(date.getDate()).padStart(2, '0');