Function ReadSQL(W: String): String;
Begin
  Result:= 'Set DateFormat DMY '#13#10 + 
     ' Select BELGENO,  CAST(CONVERT(VARCHAR, TARIH, 104) AS DATETIME) AS TARIH, PLAKA, SAHIBI, FIRMAADI, '#13#10 + 
     '   (SELECT SUM(ISNULL(UCRET, 0) * ISNULL(MIKTAR, 0)) FROM TBLOTOISEMRIHAREKET WHERE BASLIKID = I.ID AND SATIRTIPI <> 2) - '#13#10 + 
	 '      (SELECT SUM(ISNULL(UCRET, 0)) FROM TBLOTOISEMRIHAREKET WHERE BASLIKID = I.ID AND SATIRTIPI = 2) AS UCRET '#13#10 + 
	 ' from TBLOTOISEMRI I '#13#10 + 
	 ' LEFT OUTER JOIN TBLARACLAR A ON A.ID = I.ARACID '#13#10 + 
	 ' LEFT OUTER JOIN TBLCARI C WITH(INDEX=TBLCARI_KARTNO) ON C.KARTNO = A.CARIID '#13#10 + 
	 ' WHERE I.DURUM = 1 ';
  if W <> '' Then 
    Result:= Result + ' AND CAST(CONVERT(VARCHAR, TARIH, 104) AS DATETIME) = CAST(' + QuotedStr(W) + ' AS DATETIME)';
End;

procedure RaporLoad;
Begin
  if FFilter <> '' Then
  Begin
	AddQueryToSQL('KullaniciQ', ' AND CAST(CONVERT(VARCHAR, TARIH, 104) AS DATETIME) = CAST(' + QuotedStr(FFilter) + ' AS DATETIME)');
  End;
  AddQueryToSQL('KullaniciQ', 'ORDER BY PLAKA');
End;

Function RaporFileName: String;
Begin
  Result:=  ParsDir + 'Oto Servis\GunSonu.fr3';
End;

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

procedure Start;
Begin
End;

Procedure Finish;
Begin
End;

Function ReadFilter(Var F: String): Boolean;
Var
  t1: TDateTime;
Begin
  F:= '';
  Result:= InputDate('Tarihi Girin', t1);
  if Result Then
   F:= DateToStr(T1);
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin
    CreateReport(IDS, ReadSQL(IDS), 
     'TARIH;BELGENO;PLAKA;SAHIBI;FIRMAADI;UCRET', 
	 'Tarih;Belge No;Plaka;Sahibi;Firma Adı;Servis Ücreti', 
	  0);
	
	CreateSummary('UCRET', skSum);   
  End;
End;

Begin
End.