order price update
This commit is contained in:
@@ -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<string>("");
|
||||
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 (
|
||||
<>
|
||||
<Card className="mb-6 shadow-lg border-0 bg-gradient-to-r from-green-600 to-emerald-600 text-white">
|
||||
<CardContent className="pt-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-green-100 mb-1">
|
||||
Jami summa ({getMonthName(selectedMonth)})
|
||||
</p>
|
||||
<p className="text-green-100 mb-1">Jami qolgan summalar</p>
|
||||
<p className="text-3xl font-bold">
|
||||
{formatCurrency(getTotalForMonth())}
|
||||
{formatPrice(getMonthName(pharmacies))}
|
||||
</p>
|
||||
</div>
|
||||
<DollarSign className="h-16 w-16 opacity-20" />
|
||||
@@ -149,8 +127,6 @@ const PlanPrice = ({ selectedMonth, pharmacies }: PlanPriceProps) => {
|
||||
</Card>
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{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) => {
|
||||
</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="flex items-center text-sm text-gray-600">
|
||||
<Banknote className="h-4 w-4 mr-2 text-blue-600" />
|
||||
@@ -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) => {
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
onClick={() => handleSave(pharmacy.id)}
|
||||
onClick={() =>
|
||||
handleSave(
|
||||
pharmacy.id,
|
||||
Number(pharmacy.paid_price),
|
||||
)
|
||||
}
|
||||
className="flex-1 bg-green-600 hover:bg-green-700"
|
||||
>
|
||||
<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">
|
||||
<span className="text-2xl font-bold text-gray-900">
|
||||
{formatPrice(amount, "uz" as LanguageRoutes, true)}
|
||||
To'langan: {formatPrice(pharmacy.paid_price)}
|
||||
</span>
|
||||
|
||||
{!locked && (
|
||||
|
||||
@@ -143,7 +143,6 @@ const PlanTour = () => {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 🔥 Oylik narxlar */}
|
||||
<PlanPrice selectedMonth={selectedMonth} pharmacies={pharmacies} />
|
||||
</div>
|
||||
</DashboardLayout>
|
||||
|
||||
@@ -135,6 +135,9 @@ export default function TourPlan() {
|
||||
});
|
||||
}, [data, year, month]);
|
||||
|
||||
const currentYearSelect = new Date().getFullYear();
|
||||
const years = Array.from({ length: 11 }, (_, i) => currentYearSelect - 5 + i);
|
||||
|
||||
return (
|
||||
<DashboardLayout>
|
||||
<div className="space-y-6">
|
||||
@@ -147,13 +150,14 @@ export default function TourPlan() {
|
||||
<SelectTrigger className="w-fit h-10">
|
||||
<SelectValue placeholder="Yil" />
|
||||
</SelectTrigger>
|
||||
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem value="2025">2025</SelectItem>
|
||||
<SelectItem value="2024">2024</SelectItem>
|
||||
<SelectItem value="2023">2023</SelectItem>
|
||||
<SelectItem value="2022">2022</SelectItem>
|
||||
<SelectItem value="2021">2021</SelectItem>
|
||||
{years.map((y) => (
|
||||
<SelectItem key={y} value={String(y)}>
|
||||
{y}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
@@ -16,7 +16,7 @@ export default defineConfig({
|
||||
server: {
|
||||
host: true, // barcha hostlarga ruxsat
|
||||
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