order price update
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { order_api } from "@/features/specification/lib/api";
|
import { order_api } from "@/features/specification/lib/api";
|
||||||
import type { OrderListData } from "@/features/specification/lib/data";
|
import type { OrderListData } from "@/features/specification/lib/data";
|
||||||
import { LanguageRoutes } from "@/shared/config/i18n/types";
|
|
||||||
import { formatPrice } from "@/shared/lib/formatPrice";
|
import { formatPrice } from "@/shared/lib/formatPrice";
|
||||||
import { Alert, AlertDescription } from "@/shared/ui/alert";
|
import { Alert, AlertDescription } from "@/shared/ui/alert";
|
||||||
import { Button } from "@/shared/ui/button";
|
import { Button } from "@/shared/ui/button";
|
||||||
@@ -36,33 +35,18 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
const [tempAmount, setTempAmount] = useState<string>("");
|
const [tempAmount, setTempAmount] = useState<string>("");
|
||||||
const [displayPrice, setDisplayPrice] = useState("");
|
const [displayPrice, setDisplayPrice] = useState("");
|
||||||
|
|
||||||
const formatCurrency = (amount: number): string =>
|
const getMonthName = (pharmacies: OrderListData[]): number => {
|
||||||
new Intl.NumberFormat("uz-UZ").format(amount) + " so'm";
|
return pharmacies.reduce(
|
||||||
|
(total, item) => total + (Number(item.overdue_price) || 0),
|
||||||
const getMonthName = (monthKey: string): string => {
|
0,
|
||||||
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 { mutate, isPending } = useMutation({
|
const { mutate, isPending } = useMutation({
|
||||||
mutationFn: ({ body, id }: { id: number; body: { paid_price: number } }) =>
|
mutationFn: ({ body, id }: { id: number; body: { paid_price: number } }) =>
|
||||||
order_api.update({ body, id }),
|
order_api.update({ body, id }),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success("Lokatsiya jo'natildi");
|
toast.success("To'landi");
|
||||||
queryClient.refetchQueries({ queryKey: ["order_list"] });
|
queryClient.refetchQueries({ queryKey: ["order_list"] });
|
||||||
setEditingId(null);
|
setEditingId(null);
|
||||||
setTempAmount("");
|
setTempAmount("");
|
||||||
@@ -103,8 +87,11 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
setTempAmount(currentAmount.toString());
|
setTempAmount(currentAmount.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = (pharmacyId: number) => {
|
const handleSave = (pharmacyId: number, paid_price: number) => {
|
||||||
const amount = parseInt(tempAmount) || 0;
|
const current = Number(tempAmount) || 0;
|
||||||
|
const old = Number(paid_price) || 0;
|
||||||
|
|
||||||
|
const amount = current + old;
|
||||||
|
|
||||||
mutate({
|
mutate({
|
||||||
body: {
|
body: {
|
||||||
@@ -123,24 +110,15 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
pharmacy.monthlyData[selectedMonth]?.locked === true ||
|
pharmacy.monthlyData[selectedMonth]?.locked === true ||
|
||||||
selectedMonth !== currentMonthKey;
|
selectedMonth !== currentMonthKey;
|
||||||
|
|
||||||
const getTotalForMonth = (): number =>
|
|
||||||
pharmacies.reduce(
|
|
||||||
(total, pharmacy) =>
|
|
||||||
total + (pharmacy.monthlyData[selectedMonth]?.amount || 0),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card className="mb-6 shadow-lg border-0 bg-gradient-to-r from-green-600 to-emerald-600 text-white">
|
<Card className="mb-6 shadow-lg border-0 bg-gradient-to-r from-green-600 to-emerald-600 text-white">
|
||||||
<CardContent className="pt-6">
|
<CardContent className="pt-6">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
<p className="text-green-100 mb-1">
|
<p className="text-green-100 mb-1">Jami qolgan summalar</p>
|
||||||
Jami summa ({getMonthName(selectedMonth)})
|
|
||||||
</p>
|
|
||||||
<p className="text-3xl font-bold">
|
<p className="text-3xl font-bold">
|
||||||
{formatCurrency(getTotalForMonth())}
|
{formatPrice(getMonthName(pharmacies))}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<DollarSign className="h-16 w-16 opacity-20" />
|
<DollarSign className="h-16 w-16 opacity-20" />
|
||||||
@@ -149,8 +127,6 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
</Card>
|
</Card>
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
{pharmacies.map((pharmacy) => {
|
{pharmacies.map((pharmacy) => {
|
||||||
const monthData = pharmacy.monthlyData[selectedMonth];
|
|
||||||
const amount = monthData?.amount || 0;
|
|
||||||
const locked = isLocked(pharmacy);
|
const locked = isLocked(pharmacy);
|
||||||
const isEditing = editingId === pharmacy.id;
|
const isEditing = editingId === pharmacy.id;
|
||||||
|
|
||||||
@@ -173,6 +149,13 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1">
|
||||||
|
<div className="flex items-center text-sm text-gray-600">
|
||||||
|
<Building2 className="h-4 w-4 mr-2 text-blue-600" />
|
||||||
|
Umumiy summa: {formatPrice(pharmacy.total_price)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<div className="flex items-center text-sm text-gray-600">
|
<div className="flex items-center text-sm text-gray-600">
|
||||||
<Banknote className="h-4 w-4 mr-2 text-blue-600" />
|
<Banknote className="h-4 w-4 mr-2 text-blue-600" />
|
||||||
@@ -201,10 +184,16 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
value={displayPrice}
|
value={displayPrice}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const raw = e.target.value.replace(/\D/g, "");
|
const raw = e.target.value.replace(/\D/g, "");
|
||||||
const num = Number(raw);
|
const rawNumber = Number(raw);
|
||||||
if (!isNaN(num)) {
|
|
||||||
setTempAmount(String(num));
|
const limited =
|
||||||
setDisplayPrice(raw ? formatPrice(num) : "");
|
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"
|
className="h-12 text-md"
|
||||||
@@ -212,7 +201,12 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
|
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleSave(pharmacy.id)}
|
onClick={() =>
|
||||||
|
handleSave(
|
||||||
|
pharmacy.id,
|
||||||
|
Number(pharmacy.paid_price),
|
||||||
|
)
|
||||||
|
}
|
||||||
className="flex-1 bg-green-600 hover:bg-green-700"
|
className="flex-1 bg-green-600 hover:bg-green-700"
|
||||||
>
|
>
|
||||||
<Check className="h-4 w-4 mr-2" />
|
<Check className="h-4 w-4 mr-2" />
|
||||||
@@ -236,7 +230,7 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
|||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-4 items-center rounded-lg">
|
<div className="flex flex-col gap-4 items-center rounded-lg">
|
||||||
<span className="text-2xl font-bold text-gray-900">
|
<span className="text-2xl font-bold text-gray-900">
|
||||||
{formatPrice(amount, "uz" as LanguageRoutes, true)}
|
To'langan: {formatPrice(pharmacy.paid_price)}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{!locked && (
|
{!locked && (
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ const PlanTour = () => {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* 🔥 Oylik narxlar */}
|
|
||||||
<PlanPrice selectedMonth={selectedMonth} pharmacies={pharmacies} />
|
<PlanPrice selectedMonth={selectedMonth} pharmacies={pharmacies} />
|
||||||
</div>
|
</div>
|
||||||
</DashboardLayout>
|
</DashboardLayout>
|
||||||
|
|||||||
@@ -135,6 +135,9 @@ export default function TourPlan() {
|
|||||||
});
|
});
|
||||||
}, [data, year, month]);
|
}, [data, year, month]);
|
||||||
|
|
||||||
|
const currentYearSelect = new Date().getFullYear();
|
||||||
|
const years = Array.from({ length: 11 }, (_, i) => currentYearSelect - 5 + i);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardLayout>
|
<DashboardLayout>
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
@@ -147,13 +150,14 @@ export default function TourPlan() {
|
|||||||
<SelectTrigger className="w-fit h-10">
|
<SelectTrigger className="w-fit h-10">
|
||||||
<SelectValue placeholder="Yil" />
|
<SelectValue placeholder="Yil" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectGroup>
|
<SelectGroup>
|
||||||
<SelectItem value="2025">2025</SelectItem>
|
{years.map((y) => (
|
||||||
<SelectItem value="2024">2024</SelectItem>
|
<SelectItem key={y} value={String(y)}>
|
||||||
<SelectItem value="2023">2023</SelectItem>
|
{y}
|
||||||
<SelectItem value="2022">2022</SelectItem>
|
</SelectItem>
|
||||||
<SelectItem value="2021">2021</SelectItem>
|
))}
|
||||||
</SelectGroup>
|
</SelectGroup>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: true, // barcha hostlarga ruxsat
|
host: true, // barcha hostlarga ruxsat
|
||||||
allowedHosts: [
|
allowedHosts: [
|
||||||
"explaining-spoke-component-awareness.trycloudflare.com", // ngrok host qo'shildi
|
"nursing-worked-delays-assist.trycloudflare.com", // ngrok host qo'shildi
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user