diff --git a/package-lock.json b/package-lock.json index 79481f9..ae46823 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.4.0", "dependencies": { "@heroicons/react": "^2.2.0", - "@pharmatech/sdk": "^0.4.19", + "@pharmatech/sdk": "^0.4.21", "@react-pdf/renderer": "^4.3.0", "blob-stream": "^0.1.3", "cloudinary": "^2.6.0", @@ -1809,9 +1809,9 @@ } }, "node_modules/@pharmatech/sdk": { - "version": "0.4.19", - "resolved": "https://registry.npmjs.org/@pharmatech/sdk/-/sdk-0.4.19.tgz", - "integrity": "sha512-ZiYsoiVRtDjxs5eDqtUAZrEsUWMEZ9+q5XpSOSHt+gTcZLBzntIOO21ZyAm6ONXyRO6EORsOy2vlnnOv87Cs0g==", + "version": "0.4.21", + "resolved": "https://registry.npmjs.org/@pharmatech/sdk/-/sdk-0.4.21.tgz", + "integrity": "sha512-fxyXlgKN3qLxuGVg6bmRS5DhqfLOLsCYazffax5x0iYFFBIQHQBVRLltm5h84jvOEM0oA7ipD08VVXWMyBj/vQ==", "license": "MIT", "dependencies": { "axios": "^1.8.1" diff --git a/package.json b/package.json index 74c2105..8ef700e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "dependencies": { "@heroicons/react": "^2.2.0", - "@pharmatech/sdk": "^0.4.19", + "@pharmatech/sdk": "^0.4.21", "@react-pdf/renderer": "^4.3.0", "blob-stream": "^0.1.3", "cloudinary": "^2.6.0", diff --git a/src/app/(dashboard)/orders/[id]/edit/page.tsx b/src/app/(dashboard)/orders/[id]/edit/page.tsx index 6b25328..fc3ac87 100644 --- a/src/app/(dashboard)/orders/[id]/edit/page.tsx +++ b/src/app/(dashboard)/orders/[id]/edit/page.tsx @@ -258,7 +258,7 @@ export default function EditOrderStatusPage() { )} - + ); diff --git a/src/app/(dashboard)/orders/[id]/page.tsx b/src/app/(dashboard)/orders/[id]/page.tsx index 274a507..da7bab3 100644 --- a/src/app/(dashboard)/orders/[id]/page.tsx +++ b/src/app/(dashboard)/orders/[id]/page.tsx @@ -171,7 +171,7 @@ export default function ViewOrderStatusPage() { )} - + ); diff --git a/src/app/(dashboard)/reports/inventory/page.tsx b/src/app/(dashboard)/reports/inventory/page.tsx index ed32d16..4e745b9 100644 --- a/src/app/(dashboard)/reports/inventory/page.tsx +++ b/src/app/(dashboard)/reports/inventory/page.tsx @@ -8,10 +8,9 @@ import { api } from '@/lib/sdkConfig'; import PDFReportTemplate from '@/components/FileHelper/PDFReportTemplate'; import { - ProductPresentationResponse, - ProductPresentationDetailResponse, StateResponse, CityResponse, + ProductPresentation, } from '@pharmatech/sdk'; import { formatPrice } from '@/lib/utils/priceFormatter'; import Button from '@/components/Button'; @@ -26,13 +25,7 @@ export default function InventoryReportPreview() { const [cities, setCities] = useState([]); const [selectedState, setSelectedState] = useState(''); const [selectedCity, setSelectedCity] = useState(''); - - const [productData, setProductData] = useState( - [], - ); - const [detailsMap, setDetailsMap] = useState< - Record - >({}); + const [productData, setProductData] = useState([]); useEffect(() => { if (!token || !user?.sub) return; @@ -65,17 +58,6 @@ export default function InventoryReportPreview() { const fetchData = async () => { const res = await api.product.getProducts({ page: 1, limit: 100 }); setProductData(res.results); - - const detailMap: Record = {}; - for (const prod of res.results) { - const detail = await api.productPresentation.getByPresentationId( - prod.product.id, - prod.presentation.id, - ); - detailMap[prod.presentation.id] = detail; - } - - setDetailsMap(detailMap); }; const columns: { @@ -96,9 +78,8 @@ export default function InventoryReportPreview() { const tableData = useMemo(() => { return productData.map((p) => { - const detail = detailsMap[p.presentation.id]; - const genericName = detail?.product?.genericName || '-'; - const presentationName = detail?.presentation?.name || '-'; + const genericName = p.product.genericName; + const presentationName = p.product.name; const stock = p.stock ?? 0; const price = p.price; @@ -110,7 +91,7 @@ export default function InventoryReportPreview() { totalValue: formatPrice(stock * price), }; }); - }, [productData, detailsMap]); + }, [productData]); const handleDownload = async () => { const printDate = new Date().toLocaleDateString('es-VE'); diff --git a/src/components/OrderProductList.tsx b/src/components/OrderProductList.tsx index 9d39e58..0b96b61 100644 --- a/src/components/OrderProductList.tsx +++ b/src/components/OrderProductList.tsx @@ -7,13 +7,15 @@ import { formatPrice } from '@/lib/utils/priceFormatter'; type Props = { details: OrderDetailResponse[]; + total: number; }; -const OrderProductList: FC = ({ details }) => { - const total = details.reduce((acc, detail) => { - const price = detail.productPresentation.price || 0; - return acc + price * detail.quantity; - }, 0); +const OrderProductList: FC = ({ details, total }) => { + const subtotal = details.reduce( + (acc, detail) => acc + detail.quantity * detail.price, + 0, + ); + const discount = subtotal - total; return (
@@ -44,7 +46,13 @@ const OrderProductList: FC = ({ details }) => {
))} -

+

+ Subtotal: ${formatPrice(subtotal)} +

+

+ Descuento: ${formatPrice(discount)} +

+

Total: ${formatPrice(total)}