diff --git a/src/features/plan-tour/ui/PlanPrice.tsx b/src/features/plan-tour/ui/PlanPrice.tsx index 3ab4532..b5f67d4 100644 --- a/src/features/plan-tour/ui/PlanPrice.tsx +++ b/src/features/plan-tour/ui/PlanPrice.tsx @@ -1,6 +1,5 @@ import { order_api } from "@/features/specification/lib/api"; import type { OrderListData } from "@/features/specification/lib/data"; -import { LanguageRoutes } from "@/shared/config/i18n/types"; import { formatPrice } from "@/shared/lib/formatPrice"; import { Alert, AlertDescription } from "@/shared/ui/alert"; import { Button } from "@/shared/ui/button"; @@ -36,33 +35,18 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => { const [tempAmount, setTempAmount] = useState(""); const [displayPrice, setDisplayPrice] = useState(""); - const formatCurrency = (amount: number): string => - new Intl.NumberFormat("uz-UZ").format(amount) + " so'm"; - - const getMonthName = (monthKey: string): string => { - const months = [ - "Yanvar", - "Fevral", - "Mart", - "Aprel", - "May", - "Iyun", - "Iyul", - "Avgust", - "Sentyabr", - "Oktyabr", - "Noyabr", - "Dekabr", - ]; - const [year, month] = monthKey.split("-"); - return `${months[parseInt(month) - 1]} ${year}`; + const getMonthName = (pharmacies: OrderListData[]): number => { + return pharmacies.reduce( + (total, item) => total + (Number(item.overdue_price) || 0), + 0, + ); }; const { mutate, isPending } = useMutation({ mutationFn: ({ body, id }: { id: number; body: { paid_price: number } }) => order_api.update({ body, id }), onSuccess: () => { - toast.success("Lokatsiya jo'natildi"); + toast.success("To'landi"); queryClient.refetchQueries({ queryKey: ["order_list"] }); setEditingId(null); setTempAmount(""); @@ -103,8 +87,11 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => { setTempAmount(currentAmount.toString()); }; - const handleSave = (pharmacyId: number) => { - const amount = parseInt(tempAmount) || 0; + const handleSave = (pharmacyId: number, paid_price: number) => { + const current = Number(tempAmount) || 0; + const old = Number(paid_price) || 0; + + const amount = current + old; mutate({ body: { @@ -123,24 +110,15 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => { pharmacy.monthlyData[selectedMonth]?.locked === true || selectedMonth !== currentMonthKey; - const getTotalForMonth = (): number => - pharmacies.reduce( - (total, pharmacy) => - total + (pharmacy.monthlyData[selectedMonth]?.amount || 0), - 0, - ); - return ( <>
-

- Jami summa ({getMonthName(selectedMonth)}) -

+

Jami qolgan summalar

- {formatCurrency(getTotalForMonth())} + {formatPrice(getMonthName(pharmacies))}

@@ -149,8 +127,6 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
{pharmacies.map((pharmacy) => { - const monthData = pharmacy.monthlyData[selectedMonth]; - const amount = monthData?.amount || 0; const locked = isLocked(pharmacy); const isEditing = editingId === pharmacy.id; @@ -173,6 +149,13 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
+
+
+ + Umumiy summa: {formatPrice(pharmacy.total_price)} +
+
+
@@ -201,10 +184,16 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => { value={displayPrice} onChange={(e) => { const raw = e.target.value.replace(/\D/g, ""); - const num = Number(raw); - if (!isNaN(num)) { - setTempAmount(String(num)); - setDisplayPrice(raw ? formatPrice(num) : ""); + const rawNumber = Number(raw); + + const limited = + rawNumber <= Number(pharmacy.overdue_price) + ? rawNumber + : Number(pharmacy.overdue_price); + + if (!isNaN(limited)) { + setTempAmount(String(limited)); + setDisplayPrice(raw ? formatPrice(limited) : ""); } }} className="h-12 text-md" @@ -212,7 +201,12 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {