Var
  Tarih1, Tarih2: TDateTime;

procedure Start;
Begin
End;

Procedure Finish;
Begin
End;
  
procedure FindParam(FF: String);
Var 
  S: TStringList;
  I: Integer;
  C: String;
Begin
  S:= TStringList.Create;
  S.Text:= FF;
  
  For I:= 0 to S.Count - 1 Do
  Begin
    C:= S[I];
	
	if Length(C) > 9 Then
	  Delete(C, 1, 9);
	
    if Pos('TARIH1 = ', S[I]) = 1 Then
	  Tarih1:= StrToDate(C)
    else if Pos('TARIH2 = ', S[I]) = 1 Then
	  Tarih2:= StrToDate(C)
  End;
  S.Free;
End;

Function ReadSQL(W: String): String;
Begin
  FindParam(W);
  
  Result:= 'Set DateFormat DMY '#13 +
    ' Declare @Tarih1 DateTime, @Tarih2 DateTime '#13 +
	' Set @Tarih1 = ' + QuotedStr(FormatDateTime('dd.mm.yyyy', Tarih1)) + #13 +
	' Set @Tarih2 = ' + QuotedStr(FormatDateTime('dd.mm.yyyy', Tarih2)) + #13 +
	' Select  '#13 +
	' 	 S.STOKKODU, S.CINSI, SUM(H.CIKAN) AS SATIS '#13 +
	' from STOKHAREKET H  '#13 +
	' LEFT OUTER JOIN TBLSTOKLAR S WITH(INDEX=TBLSTOKLAR_KARTNO) ON S.KARTNO = H.STOKID  '#13 +
	' WHERE H.ISLEMTIPI = 2 AND TARIH BETWEEN CONVERT(VARCHAR, @Tarih1, 104) AND CONVERT(VARCHAR, @Tarih2, 104) '#13 +
	' GROUP BY S.STOKKODU, S.CINSI '#13 +
	' ORDER BY S.CINSI';
End;

procedure RaporLoad;
Begin
End; 

Function RaporFileName: String;
Begin
End;

Function RaporDefaultSQL: String;
Begin
  Result:= ReadSQL('TARIH1 = ' + FormatDateTime('dd.mm.yyyy', Date) + #13#10 + 'TARIH2 = ' + FormatDateTime('dd.mm.yyyy', Date));
End;

Function ReadFilter(Var F: String): Boolean;
Var
  t1, t2: TDateTime;
Begin
  Result:= Input2Date('Tarihleri Girin', t1, t2);
  if Result Then
  Begin
    F:= 'TARIH1 = ' + DateToStr(t1) + #13#10 + 'TARIH2 = ' + DateToStr(t2);
  End;
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin
	CreateReport(IDS, ReadSQL(IDS), 
     'STOKKODU;CINSI;SATIS', 
	 'Stok Kodu;Cinsi;Satış', 
	  0);
  End;
 End;

Begin
End.