import { formatDisplayDate } from '../../core/utils/datetimeUtils'; import { GetHeaderSection, GetPrintTemplate } from '../../core/print/PrintTemplate'; import { CLOSE_PRINT_AFTER_PRINT, STOCK_OPERATION_PRINT_DISABLE_BALANCE_ON_HAND, STOCK_OPERATION_PRINT_DISABLE_COSTS, } from '../../constants'; import { printDocument } from '../../core/print/printUtils'; import { type StockOperationPrintData } from './StockOperationReport'; export const FormatRequisitionDocument = async (data: StockOperationPrintData): Promise => { const emptyRowCount: number = Math.max(0, 28 - (data?.items?.length ?? 0)); const headerSection = await GetHeaderSection(); return `
${headerSection}
HMIS FORM 017: REQUISITION AND ISSUE VOUCHER
Name of Health Unit: ${data?.organizationName ?? ''}
Dept/section/ward/dispensary: ${data?.location ?? ''} Date: ${formatDisplayDate(data?.operationDate)}
${ data?.items ? data?.items .map((p) => { return ` `; }) .join('') : '' } ${ emptyRowCount > 0 ? Array(emptyRowCount) .fill(0) .map( (p) => ` `, ) .join('') : '' }
Ordered by (Name and signature):

${data.orderedBy ?? ' '}

Authorized by (Name and Signature):

${data.authorizedBy ?? ' '}

Item Code No. Item Description (name, formulation, strength) Balance on Hand Quantity Required Quantity Issued Unit Cost Total Cost
${p.itemCode ?? ''} ${p.itemDescription ?? ''} ${ STOCK_OPERATION_PRINT_DISABLE_BALANCE_ON_HAND || !p.balanceOnHand ? '' : `${p.balanceOnHand?.toLocaleString()} ${p.balanceOnHandUoM ?? ''}` } ${p.quantityRequired?.toLocaleString() ?? ''} ${ p.quantityRequiredUoM ?? '' } ${p.quantityIssued?.toLocaleString() ?? ''} ${ p.quantityIssuedUoM ?? '' } ${ STOCK_OPERATION_PRINT_DISABLE_COSTS ? '' : `${p.unitCost?.toLocaleString() ?? ''}${p.unitCostUoM ? `/${p.unitCostUoM}` : ''}` } ${ STOCK_OPERATION_PRINT_DISABLE_COSTS ? '' : `${p.totalCost?.toLocaleString() ?? ''}` }
             
`; }; export const PrintRequisitionStockOperation = async (data: StockOperationPrintData) => { const printData = await FormatRequisitionDocument(data); printDocument(GetPrintTemplate(printData, data?.documentTitle, true, CLOSE_PRINT_AFTER_PRINT)); };