Function ReadSQL(W: String): String;
Begin
  Result:= 
       ' SELECT * FROM( ' +
       ' SELECT  ' +
       '   ''GELEN HAVALE'' AS ISLEM, B.TARIH, BN.BANKAKODU, BN.BANKAADI, C.FIRMAKODU, C.FIRMAADI, D.ACIKLAMA, D.TUTAR AS GIREN, 0.000 AS CIKAN,  C.KOD3, C.KOD4 ' +
       ' FROM TBLBANKAGELENHAVALEDETAY D ' +
       ' LEFT OUTER JOIN TBLCARI C ON (D.CARIID = C.KARTNO) ' +
       ' LEFT OUTER JOIN TBLBANKAGELENHAVALE B ON (D.BASLIKID = B.KARTNO) ' +
       ' LEFT OUTER JOIN TBLBANKALAR BN ON BN.KARTNO = B.BANKAID ' +
       ' WHERE ISNULL(B.DELETED, 0) = 0 ' +
       ' UNION ALL ' +
       ' SELECT  ' +
       '   ''GİDEN HAVALE'', B.TARIH, BN.BANKAKODU, BN.BANKAADI, C.FIRMAKODU, C.FIRMAADI, D.ACIKLAMA, 0.000 AS GIREN,D.TUTAR  AS CIKAN,  C.KOD3, C.KOD4 ' +
       ' FROM TBLBANKAGIDENHAVALEDETAY D ' +
       ' LEFT OUTER JOIN TBLCARI C ON (D.CARIID = C.KARTNO) ' +
       ' LEFT OUTER JOIN TBLBANKAGIDENHAVALE B ON (D.BASLIKID = B.KARTNO) ' +
       ' LEFT OUTER JOIN TBLBANKALAR BN ON BN.KARTNO = B.BANKAID ' +
       ' WHERE ISNULL(B.DELETED, 0) = 0 ' +
       ' UNION ALL ' +
       ' SELECT ' +
       '   ''VİRMAN ÇIKIŞI'', TARIH, B.BANKAKODU, BANKAADI, '''', '''', D.ACIKLAMA, 0 AS GIREN, TUTARI AS CIKAN, '''', '''' ' +
       ' FROM TBLBANKAVIRMAN D ' +
       ' LEFT OUTER JOIN TBLBANKALAR B ON B.KARTNO = D.BANKAID ' +
       ' WHERE D.DELETED = 0 ' +
       ' UNION ALL ' +
       ' SELECT ' +
       '   ''VİRMAN GİRİŞİ'', TARIH, B.BANKAKODU, BANKAADI, '''', '''', D.ACIKLAMA, TUTARI AS GIREN, 0 AS CIKAN, '''', '''' ' +
       ' FROM TBLBANKAVIRMAN D ' +
       ' LEFT OUTER JOIN TBLBANKALAR B ON B.KARTNO = D.BANKAID ' +
       ' WHERE D.DELETED = 0 ' +
       ' UNION ALL ' +
       ' SELECT ' +
       '     ''NAKİT GİRİŞİ'', TARIH, B.BANKAKODU, BANKAADI, '''', '''', D.ACIKLAMA, TUTARI AS GIREN, 0 AS CIKAN, '''', '''' ' +
       ' FROM TBLBANKANAKITGIRIS D ' +
       ' LEFT OUTER JOIN TBLBANKALAR B ON B.KARTNO = D.BANKAID ' +
       ' WHERE D.DELETED = 0 ' +
       ' UNION ALL ' +
       ' SELECT ' +
       '     ''NAKİT ÇIKIŞI'', TARIH, B.BANKAKODU, BANKAADI, '''', '''', D.ACIKLAMA, 0 AS GIREN, TUTARI AS CIKAN, '''', '''' ' +
       ' FROM TBLBANKANAKITGIRIS D ' +
       ' LEFT OUTER JOIN TBLBANKALAR B ON B.KARTNO = D.BANKAID ' +
       ' WHERE D.DELETED = 0 ' + 
	   ' ) AS B';
  if W <> '' Then
    Result:= Result + ' WHERE ' + W;
  Result:= Result + ' ORDER BY TARIH';

End;

procedure RaporLoad;
Begin
End;

Function RaporFileName: String;
Begin
  Result:= '';
End;

Function RaporDefaultSQL: String;
Begin
  Result:= ReadSQL('');
End;

procedure Start;
Begin
End;

Procedure Finish;
Begin
End;

Function ReadFilter(Var F: String): Boolean;
Var
  t1, t2: TDateTime;
Begin
  Result:= Input2Date('Tarihleri Girin', t1, t2);
  if Result Then
  Begin
    F:= ' CAST(CONVERT(VARCHAR, B.TARIH, 104) AS DATETIME) >= CAST(' + QuotedStr(FormatDateTime('dd.mm.yyy', t1)) + ' AS DATETIME) ' + 
        ' AND CAST(CONVERT(VARCHAR, B.TARIH, 104) AS DATETIME) <= CAST(' + QuotedStr(FormatDateTime('dd.mm.yyy', t2)) + ' AS DATETIME)';  
  End;
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin
    CreateReport(IDS, ReadSQL(IDS), 
     'ISLEM;TARIH;BANKAKODU:0;BANKAADI;FIRMAKODU:0;FIRMAADI;ACIKLAMA;GIREN;CIKAN;KOD3;KOD4', 
	 'İşlem;Tarih;Banka Kodu;Banka Adı;Firma Kodu;Firma Adı;Açıklama;Giren;Çıkan;Ö.Kod 3;Ö.Kod 4', 
	  0);
	  
	CreateSummary('GIREN', skSum); 
	CreateSummary('CIKAN', skSum); 
	CreateSummary('ISLEM', skCount);   
  End;
End;

Begin
End.