procedure RaporLoad;
Begin
// Filtre Kullanılırsa
  if FFilter <> '' Then
    AddQueryToSQL('KullaniciQ', ' AND ' + FFilter);
  AddQueryToSQL('KullaniciQ', 'ORDER BY TARIH');
End;

Function RaporFileName: String;
Begin
  Result:= ParsDir + 'Cari Kart Raporları\Finansal Raporlar\Ödeme Raporları\Odemeler.fr3';
End;

Function RaporDefaultSQL: String;
Begin
  Result:= 'Set DateFormat DMY'#13#10'Select C.FIRMAKODU, C.FIRMAADI, B.TARIH, B.BELGENO, B.ACIKLAMA, B.TUTARI, '#13#10 +
    ' B.OZELKOD1, B.OZELKOD2, B.OZELKOD3, B.OZELKOD4, B.OZELKOD5,   P.AD + '' '' + P.SOYAD AS PERSONEL'#13#10'from TBLCARICIKIS B '#13#10 + 
	' LEFT OUTER JOIN TBLCARI C WITH(INDEX=TBLCARI_KARTNO) ON C.KARTNO = B.CARIID '#13#10 + 
	' LEFT OUTER JOIN TBLPERSONEL P WITH(INDEX=TBLPERSONEL_KARTNO) ON P.KARTNO = B.PERSONELID '#13#10 + 
	' WHERE B.DELETED = 0';
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;

Function ReadSQL(W: String): String;
Begin
  Result:= 'Set DateFormat DMY Select C.FIRMAKODU, C.FIRMAADI, B.TARIH, B.BELGENO, B.ACIKLAMA, B.TUTARI, ' +
    ' B.OZELKOD1, B.OZELKOD2, B.OZELKOD3, B.OZELKOD4, B.OZELKOD5,   P.AD + '' '' + P.SOYAD AS PERSONEL  from TBLCARICIKIS B ' + 
	' LEFT OUTER JOIN TBLCARI C WITH(INDEX=TBLCARI_KARTNO) ON C.KARTNO = B.CARIID ' + 
	' LEFT OUTER JOIN TBLPERSONEL P WITH(INDEX=TBLPERSONEL_KARTNO) ON P.KARTNO = B.PERSONELID ' + 
	' WHERE B.DELETED = 0';

  if W <> '' Then
    Result:= Result + ' AND ' + W;
  Result:= Result + ' ORDER BY TARIH';
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin
    CreateReport(IDS, ReadSQL(IDS), 
     'FIRMAKODU;FIRMAADI;TARIH;BELGENO;ACIKLAMA;TUTARI;PERSONEL;OZELKOD1;OZELKOD2;OZELKOD3:0;OZELKOD4:0;OZELKOD5:0', 
	 'Firma Kodu;Firma Adı;Tarih;Belge No;Açıklama;Tutarı;Personel;Ö.Kod 1;Ö.Kod 2;Ö.Kod 3;Ö.Kod 4;Ö.Kod 5', 
	  0);
	  
	CreateSummary('TUTARI', skSum); 
	CreateSummary('BELGENO', skCount);   
  End;
End;

Begin
End.