Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/app/(dashboard)/orders/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
socket.off('deliveryUpdated', onDeliveryUpdated);
socket.off('disconnect', onDisconnect);
};
}, []);

Check warning on line 87 in src/app/(dashboard)/orders/[id]/edit/page.tsx

View workflow job for this annotation

GitHub Actions / ci

React Hook useEffect has missing dependencies: 'socket' and 'token'. Either include them or remove the dependency array

const fetchOrderData = useCallback(async () => {
if (!token || !id) return;
Expand Down Expand Up @@ -258,7 +258,7 @@
)}
</div>
</div>
<OrderProductList details={order.details} />
<OrderProductList details={order.details} total={order.totalPrice} />
</div>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(dashboard)/orders/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default function ViewOrderStatusPage() {
)}
</div>
</div>
<OrderProductList details={order.details} />
<OrderProductList details={order.details} total={order.totalPrice} />
</div>
</>
);
Expand Down
29 changes: 5 additions & 24 deletions src/app/(dashboard)/reports/inventory/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,13 +25,7 @@ export default function InventoryReportPreview() {
const [cities, setCities] = useState<CityResponse[]>([]);
const [selectedState, setSelectedState] = useState('');
const [selectedCity, setSelectedCity] = useState('');

const [productData, setProductData] = useState<ProductPresentationResponse[]>(
[],
);
const [detailsMap, setDetailsMap] = useState<
Record<string, ProductPresentationDetailResponse>
>({});
const [productData, setProductData] = useState<ProductPresentation[]>([]);

useEffect(() => {
if (!token || !user?.sub) return;
Expand Down Expand Up @@ -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<string, ProductPresentationDetailResponse> = {};
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: {
Expand All @@ -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;

Expand All @@ -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');
Expand Down
20 changes: 14 additions & 6 deletions src/components/OrderProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { formatPrice } from '@/lib/utils/priceFormatter';

type Props = {
details: OrderDetailResponse[];
total: number;
};

const OrderProductList: FC<Props> = ({ details }) => {
const total = details.reduce((acc, detail) => {
const price = detail.productPresentation.price || 0;
return acc + price * detail.quantity;
}, 0);
const OrderProductList: FC<Props> = ({ details, total }) => {
const subtotal = details.reduce(
(acc, detail) => acc + detail.quantity * detail.price,
0,
);
const discount = subtotal - total;

return (
<div className="w-full space-y-4 rounded-xl bg-white p-6 shadow-md lg:w-1/3">
Expand Down Expand Up @@ -44,7 +46,13 @@ const OrderProductList: FC<Props> = ({ details }) => {
</span>
</div>
))}
<p className="text-lg font-semibold text-gray-800">
<p className="text-md text-gray-800">
Subtotal: ${formatPrice(subtotal)}
</p>
<p className="text-md text-[#2ECC71]">
Descuento: ${formatPrice(discount)}
</p>
<p className="text-md font-semibold text-gray-800">
Total: ${formatPrice(total)}
</p>
</div>
Expand Down
Loading