import { defineComponent, computed, ref, watch, PropType } from 'vue'; import useApiUtil from '@/composables/api_util'; import { IStockAdjustment, IStockLot, IStockProduct } from '@/models/inventory'; import { GetAllStockLotsDocument, GetAllStockLotsQuery, GetAllStockLotsQueryVariables, GetAllStockAdjustmentsDocument, GetAllStockAdjustmentsQuery, GetAllStockAdjustmentsQueryVariables } from '@/graphql/operations/inventory.queries'; import { parseDate } from '@/utils/helpers'; import { IPagination } from '@/models/pagination'; const ProductDetail = defineComponent({ name: 'product-detail', emits: ["close"], props: { product: { type: Object as PropType, }, }, setup(props, { emit }) { const { withClientQuery } = useApiUtil(); // Prefetch data const stockLots = ref([] as IStockLot[]); const stockAdjustments = ref([] as IStockAdjustment[]); watch(() => props.product?.uid, async (newUid, old) => { if (newUid) { withClientQuery(GetAllStockLotsDocument, { productUid: newUid }, 'stockLots').then(result => { stockLots.value = result; }) withClientQuery(GetAllStockAdjustmentsDocument, { first: 25, after: '', text: '', sortBy: ['-uid'], productUid: newUid }, 'stockAdjustmentAll') .then((paging: IPagination) => { stockAdjustments.value = paging.items ?? []; }) } }); // Tabs const currentTab = ref('stock-lots'); const inventoryTabs = ref(['stock-lots', 'ledger']); const currentTabComponent = computed(() => 'tab-' + currentTab.value); return { currentTab, inventoryTabs, currentTabComponent, props, stockLots, stockAdjustments, emit }; }, render() { return ( <>

Stock Item: {this.props.product?.stockItem?.name}

{this.props.product?.stockItem?.description}


Stock Variant: {this.props.product?.name}

{this.props.product?.description}


{this.currentTab === 'stock-lots' && (<>
{this.stockLots?.map(lot => ( ))}
Lot Number Quantity Expiry Date
{lot.lotNumber} {lot.quantity} {parseDate(lot.expiryDate, false)}
)} {this.currentTab === 'ledger' && (<>
{this.stockAdjustments?.map(adjustment => (<> ))}
Date Lot Transaction Type Quantity By
{parseDate(adjustment?.adjustmentDate)} {adjustment?.lotNumber} {adjustment?.adjustmentType} {adjustment?.adjust} {adjustment?.adjustmentBy?.firstName}
)}
); }, }); export { ProductDetail }; export default ProductDetail