Just check if the field is present in the node: [ ReceiptType ] [ Recipient ], if there is no "Merchant"|"Cardholder" is to see if it appears in "Both".
Code: Select all
Function PrintItemsEFTReceipt ( hPrintItems, oTIMApi )
Local aReceiptHeader := oTIMAPi:hTIM_CFG [ "ReceiptHeader" ]
Local nHeaderLine, nHeaderLines := Len ( aReceiptHeader )
Local nReceipt, nReceipts := Len ( hPrintItems )
Local nItem, nItems, hItems, cItemKey, xItemValue
Local cReceiptType, cRecipient, nRecipient, nRecipients, hRecipients
Local cPrintOut, nPrintWidth , cTranslatedText, cLeft, cRight, n
FOR nReceipt := 1 TO nReceipts
//1st Node - Receipt Type, eg. Purchase, Credit, ...
cReceiptType := hb_HKeyAt( hPrintItems, nReceipt )
hRecipients := hPrintItems [ cReceiptType ]
nRecipients := Len ( hRecipients )
FOR nRecipient := 1 TO 2
//2nd Node - Recipient: Merchant / Cardholder / Both
IF nRecipient = 1
cRecipient := "Merchant"
ELSE
cRecipient := "Cardholder"
ENDIF
IF .Not. hb_HHasKey( hRecipients, cRecipient ) //We check if the recipient is in the hash table
LOOP
ENDIF
IF cRecipient == "Merchant"
nPrintWidth := oTIMApi:hTIM_CFG [ "PrintOptionsMerchant" ] [ "PrintWidth" ]
ELSE
nPrintWidth := oTIMApi:hTIM_CFG [ "PrintOptionsCardholder" ] [ "PrintWidth" ]
ENDIF
cPrintOut := ""
//Let's make a header.
cPrintOut += MakePrintLine ( Replicate ("-=", nPrintWidth / 2 ), , "C", nPrintWidth )
FOR nHeaderLine := 1 TO nHeaderLines
cPrintOut += MakePrintLine ( aReceiptHeader [ nHeaderLine ], , "C", nPrintWidth )
NEXT nHeaderLine
cPrintOut += MakePrintLine ( Replicate ("-=", nPrintWidth / 2 ), , "C", nPrintWidth )
cTranslatedText := oTIMApi:TIM_Translate ( "rec" + cRecipient /* Field names have a "rec" prefix in the translation table. */ )
cPrintOut += MakePrintLine ( ".: " + cTranslatedText + " :.", , "C", nPrintWidth )
cPrintOut += MakePrintLine ( , , , nPrintWidth )
cTranslatedText := oTIMApi:TIM_Translate ( "trxType" + cReceiptType /* Transaction types have a "trxType" prefix in the translation table. */ )
cPrintOut += MakePrintLine ( cTranslatedText, , "L", nPrintWidth )
cPrintOut += MakePrintLine ( , , , nPrintWidth )
IF cReceiptType == "Purchase" .Or. ;
cReceiptType == "PurchaseForcedAcceptance" .Or. ;
cReceiptType == "PurchaseWithCashback" .Or. ;
cReceiptType == "PurchasePhoneAuthorized" .Or. ;
cReceiptType == "PurchasePhoneOrdered" .Or. ;
cReceiptType == "Credit" .Or. ;
cReceiptType == "CashAdvance"
//Printout form for Purchase/Credit/etc transaction
cPrintOut += MakePrintLine ( GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "BrandName" ), , "L", nPrintWidth )
IF cRecipient == "Cardholder"
cPrintOut += MakePrintLine ( GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "CardNumberPrintableCardholder" ), , "L", nPrintWidth )
ELSE
cPrintOut += MakePrintLine ( GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "CardNumberPrintableMerchant" ), , "L", nPrintWidth )
ENDIF
cPrintOut += MakePrintLine ( , , , nPrintWidth )
cLeft := hb_DtoC ( hb_StoD ( GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "TimeStampDate") ), "DD.MM.YYYY" )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "TimeStampTime" )
cRight := Left( cRight, 2 ) + ":" + SubStr( cRight, 3, 2 ) + ":" + Right ( cRight, 2 )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "TrmId" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "TrmId" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "Aid" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "Aid" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "TrxSeqCnt" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "TrxSeqCnt" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "TrxRefNum" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "TrxRefNum" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "AuthCode" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "AuthCode" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "AcqId" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "AcqId" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "CardExpiryDate" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "CardExpiryDate" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cPrintOut += MakePrintLine ( , , , nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "Amount" /* Field names have a "rec" prefix in the translation table. */ )
cRight := AllTrim ( Str ( Val ( GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "Amount" ) ) / ( 10 ^ Val ( GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "Exponent" ) ) ) ) )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cLeft := oTIMApi:TIM_Translate ( "rec" + "Currency" /* Field names have a "rec" prefix in the translation table. */ )
cRight := GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "Currency" )
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
cPrintOut += MakePrintLine ( , , , nPrintWidth )
cPrintOut += MakePrintLine ( GetRecipientField ( hPrintItems [ cReceiptType ], cRecipient, "Disclaimer" ), , "C", nPrintWidth )
ELSE
//Printout form for other transaction ( print all fields )
FOR n := 1 TO 2
IF n = 1
hItems := hPrintItems [ cReceiptType ] [ cRecipient ]
ELSE
hItems := hPrintItems [ cReceiptType ] [ "Both" ]
ENDIF
nItems := Len ( hItems )
FOR nItem := 1 TO nItems
//Items - fileds and values
cItemKey := hb_HKeyAt( hItems, nItem )
xItemValue := hItems [ cItemKey ]
IF cItemKey == "Exponent" //skip print this field
LOOP
ENDIF
cLeft := cItemKey
cTranslatedText := oTIMApi:TIM_Translate ( "rec" + cItemKey /* Field names have a "rec" prefix in the translation table. */ )
IF .Not. Empty ( cTranslatedText )
cLeft := cTranslatedText
ENDIF
IF cItemKey == "Amount"
cRight := AllTrim ( Str ( Val ( xItemValue ) / ( 10 ^ Val ( hPrintItems [ cReceiptType ] [ cRecipient ] [ "Exponent" ] ) ) ) )
ELSE
cRight := xItemValue
ENDIF
cPrintOut += MakePrintLine ( cLeft, cRight, "J", nPrintWidth )
NEXT nItem
NEXT n
cPrintOut += MakePrintLine ( , , , nPrintWidth )
ENDIF
PrintEFTReceipt ( cPrintOut, cRecipient )
NEXT nRecipient
NEXT nReceipt
RETURN
***********************************
Function GetRecipientField ( hReceiptType, cRecipient, cField )
Local cValue := ""
IF hb_HHasKey( hReceiptType [ cRecipient ], cField )
cValue := hReceiptType [ cRecipient ] [ cField ]
ELSEIF hb_HHasKey( hReceiptType [ "Both" ], cField )
cValue := hReceiptType [ "Both" ] [ cField ]
ENDIF
RETURN cValue
*******************************