Function ReadSQL(W: String): String;
Begin
  Result:=  'Set DateFormat DMY '#13#10 +
			' Select '#13#10 +
			'   SUM(CAST(BRUT - DARA AS REAL)) AS NETKG, CAST(Count(*) AS INT) AS CUVAL, R.KOD AS RENKKODU, R.ACIKLAMA AS RENKADI, S.CINSI, S.STOKKODU '#13#10 +
			' from TBLIPLIKCUVAL C '#13#10 +
			' LEFT OUTER JOIN TBLSTOKLAR S WITH(INDEX=TBLSTOKLAR_KARTNO) ON S.KARTNO = C.STOKID '#13#10 +
			' LEFT OUTER JOIN TBLRENKLER R ON R.ID = C.RENKID '#13#10;
			
  if W <> '' Then
    Result:= Result + ' WHERE ' + W + #13#10;

  Result:= Result + ' GROUP BY R.KOD, R.ACIKLAMA, S.CINSI, S.STOKKODU ';
End;

procedure RaporLoad;
Begin
End;

Function RaporFileName: String;
Begin
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, C.TARIH, 104) AS DATETIME) >= CAST(' + QuotedStr(FormatDateTime('dd.mm.yyy', t1)) + ' AS DATETIME) ' + 
        ' AND CAST(CONVERT(VARCHAR, C.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('', ReadSQL(IDS), 
       'STOKKODU:0;CINSI;RENKKODU;RENKADI:0;CUVAL;NETKG', 
	   'Stok Kodu;Cinsi;Renk Kodu;Renk Adı;Çuval Sayısı;Net KG', 
	    0);
	
	  CreateSummary('NETKG', skSum); 
	  CreateSummary('CUVAL', skSum); 
	  CreateSummary('CINSI', skCount); 
  End;
End;

Begin
End.