#include "hbclass.ch" REQUEST HB_GT_STD_DEFAULT PROCEDURE Main() LOCAL nFailures := TestTicketInvoice() IF nFailures == 0 ? "Ticket continuo Harbour OK" ELSE ? "Ticket continuo Harbour FAIL:", nFailures ENDIF ErrorLevel( nFailures ) RETURN FUNCTION TestTicketInvoice() LOCAL cTemplatePath := "lbl" + hb_ps() + "ticket_1_importado_dominus.lbl" LOCAL cDataPath := "tools" + hb_ps() + "ll12_import" + hb_ps() + "output" + hb_ps() + "ticket_1_sample_data.json" LOCAL hSample := hb_jsonDecode( MemoRead( cDataPath ) ) LOCAL hDataVar := HGet( hSample, "DataVar", { => } ) LOCAL hDetalleVar := HGet( hSample, "DetalleVar", { => } ) LOCAL aSourceRecords := HGet( hDetalleVar, "OMEMQUERY", {} ) LOCAL hFirstRecord := UnwrapRecord( aSourceRecords[ 1 ] ) LOCAL hSecondRecord := hb_HClone( hFirstRecord ) LOCAL oEngine := TLLEngine():New():Create() LOCAL oDocument LOCAL aObjects LOCAL cGroup LOCAL hObject LOCAL oObject LOCAL cId LOCAL nHeader := 0 LOCAL nDetail := 0 LOCAL nFooter := 0 LOCAL nCashTable := 0 LOCAL nInvoiceTable := 0 LOCAL nFailures := 0 hFirstRecord[ "cifc" ] := "B91004515" hFirstRecord[ "concepto" ] := "ARTICULO UNO" hFirstRecord[ "cantidad" ] := 1 hFirstRecord[ "precioii" ] := 10 hFirstRecord[ "tlineaii" ] := 10 hFirstRecord[ "tfaccl" ] := 30 hSecondRecord[ "cifc" ] := "B91004515" hSecondRecord[ "concepto" ] := "ARTICULO DOS" hSecondRecord[ "cantidad" ] := 2 hSecondRecord[ "precioii" ] := 10 hSecondRecord[ "tlineaii" ] := 20 hSecondRecord[ "tfaccl" ] := 30 oEngine:SetEncodingUTF8() oEngine:SetPlantillaContent( MemoRead( cTemplatePath ) ) oEngine:OpenJob() FOR EACH oObject IN oEngine:oPlantillaRuntime:GetObjetos() IF oObject:cId == "ll12_0002" nFailures += AssertTrue( "tabla importada automatica", oObject:cHeightMode == "content" ) nFailures += AssertTrue( "tabla importada conserva cabecera", Len( HGet( HGet( oObject:hSections, "header", { => } ), "aLines", {} ) ) == 1 ) nFailures += AssertTrue( "tabla importada conserva detalle", Len( HGet( HGet( oObject:hSections, "detail", { => } ), "aLines", {} ) ) == 1 ) nFailures += AssertTrue( "tabla importada conserva cuatro pies", Len( HGet( HGet( oObject:hSections, "footer", { => } ), "aLines", {} ) ) == 4 ) ENDIF NEXT FOR EACH cGroup IN hb_HKeys( hDataVar ) oEngine:SendDataVar( cGroup, UnwrapRecord( hDataVar[ cGroup ] ) ) NEXT oEngine:SendDetalleSchema( "OMEMQUERY", hFirstRecord ) oEngine:SendDetalle( "OMEMQUERY", hFirstRecord ) oEngine:SendDetalle( "OMEMQUERY", hSecondRecord ) oDocument := oEngine:RunEngine() nFailures += AssertTrue( "documento generado", HB_ISOBJECT( oDocument ) ) IF HB_ISOBJECT( oDocument ) nFailures += AssertTrue( "una pagina continua", Len( oDocument:GetPaginas() ) == 1 ) nFailures += AssertTrue( "alto incluye tabla y pies", oDocument:nAlto > 145 ) aObjects := oDocument:GetPaginas()[ 1 ][ "objetos" ] FOR EACH hObject IN aObjects cId := HGet( hObject, "id", "" ) IF At( "ll12_0005", cId ) > 0 nCashTable++ ENDIF IF At( "ll12_0002", cId ) > 0 nInvoiceTable++ IF At( "_header_", cId ) > 0 nHeader++ ELSEIF At( "_detail_", cId ) > 0 nDetail++ ELSEIF At( "_footer_", cId ) > 0 nFooter++ ENDIF ENDIF NEXT nFailures += AssertTrue( "capa contado oculta", nCashTable == 0 ) nFailures += AssertTrue( "tabla factura presente", nInvoiceTable > 0 ) nFailures += AssertTrue( "cabecera factura presente", nHeader > 0 ) nFailures += AssertTrue( "dos detalles factura presentes", nDetail >= 2 ) nFailures += AssertTrue( "cuatro pies factura presentes", nFooter >= 4 ) ENDIF ? "alto:", iif( HB_ISOBJECT( oDocument ), oDocument:nAlto, 0 ) ? "tabla factura:", nInvoiceTable, "cabecera:", nHeader, "detalle:", nDetail, "pie:", nFooter oEngine:End() RETURN nFailures FUNCTION UnwrapRecord( hSource ) LOCAL hRecord := { => } LOCAL cKey LOCAL uValue hb_HAutoAdd( hRecord, .T. ) IF ! HB_ISHASH( hSource ) RETURN hRecord ENDIF FOR EACH cKey IN hb_HKeys( hSource ) uValue := hSource[ cKey ] hRecord[ cKey ] := iif( HB_ISHASH( uValue ) .AND. hb_HHasKey( uValue, "valor" ), uValue[ "valor" ], uValue ) NEXT RETURN hRecord FUNCTION HGet( hHash, cKey, uDefault ) IF HB_ISHASH( hHash ) .AND. hb_HHasKey( hHash, cKey ) RETURN hHash[ cKey ] ENDIF RETURN uDefault FUNCTION AssertTrue( cName, lCondition ) IF lCondition RETURN 0 ENDIF ? "FAIL:", cName RETURN 1