procedure RaporLoad;
Begin
  SetViewCaption('BASLIK', 'PARADOX KASA HAREKET ANALİZ RAPORU');
  if FFilter <> '' Then
    AddQueryToSQL('KullaniciQ', ' WHERE ' + FFilter);
  AddQueryToSQL('KullaniciQ', 'ORDER BY (DATEPART(month, TARIH)), EVRAKTIPI');
End;

Function RaporFileName: String;
Begin
  Result:= ParsDir + 'Kasa Raporları\Kasa Hareket Analiz.fr3';
End;

Function RaporDefaultSQL: String;
Begin
  Result:= 'Select DATEPART(YEAR, TARIH) AS YIL, ACIKLAMA, ISLEMADI, GIREN, CIKAN, ' + 
      ' dbo.TRMONTHNAME(DATEPART(month, TARIH)) AS AY,  ' +
      ' END AS AY, ' +
      ' CASE COALESCE(EVRAKTIPI, 0) ' +
	  ' WHEN 0 THEN ''NAKİT'' WHEN 1 THEN ''ÇEK'' WHEN 2 THEN ''SENET'' WHEN 3 THEN ''VİSA'' END AS EVRAKTIPI ' +
	  ' from KASAHAREKET ';
End;

procedure Start;
Begin
End;

Procedure Finish;
Begin
End;

Function ReadFilter(Var F: String): Boolean;
Begin
  F:= '';
  Result:= True;
End;

Function ReadSQL(W: String): String;
Begin
  Result:= 'Select DATEPART(YEAR, TARIH) AS YIL, ACIKLAMA, ISLEMADI, GIREN, CIKAN, ' + 
      ' dbo.TRMONTHNAME(DATEPART(month, TARIH)) AS AY, ' +
      ' CASE COALESCE(EVRAKTIPI, 0) ' +
	  ' WHEN 0 THEN ''NAKİT'' WHEN 1 THEN ''ÇEK'' WHEN 2 THEN ''SENET'' WHEN 3 THEN ''VİSA'' END AS EVRAKTIPI ' +
	  ' from KASAHAREKET ';
  if W <> '' Then
    Result:= Result + ' WHERE ' + W;
  Result:= Result + ' ORDER BY (DATEPART(month, TARIH)), EVRAKTIPI';
End;

procedure cxButton1Click(Sender: TObject);
Var
  E: String;
  
  procedure Ekle(S: String);
  Begin
    if E = '' Then
	  E:= S
	else
	  E:= E + ', ' + S;
  End;

Var
  I: Integer;
  F: String;
begin
  I:= Self.evraklar.Checked;
  
  if I > 0 Then
  Begin
    E:= '';

	if I And  2 <>  2 Then 
	Begin
	  if I And  4 =  4 Then Ekle('0');
  	  if I And  8 =  8 Then Ekle('1');
	  if I And 16 = 16 Then Ekle('2');	  
	End;
	
	if E <> '' Then
	  F:= 'COALESCE(EVRAKTIPI, 0) IN(' + E + ') AND';
	F:= F +
        ' CAST(CONVERT(VARCHAR, TARIH, 104) AS DATETIME) >= CAST(' + QuotedStr(FormatDateTime('dd.mm.yyy', Self.IlkTarih.Date)) + ' AS DATETIME) ' + 
        ' AND CAST(CONVERT(VARCHAR, TARIH, 104) AS DATETIME) <= CAST(' + QuotedStr(FormatDateTime('dd.mm.yyy', Self.SonTarih.Date)) + ' AS DATETIME)';	
	
    if not ReadFilterOnly Then
	Begin
      CreateReport(F, ReadSQL(F), 
       'YIL;AY;ACIKLAMA;ISLEM;GIREN;CIKAN;EVRAKTIPI', 
	   'Yıl;Ay;Açıklama;İşlem;Giren;Çıkan;Belge Tipi', 
	   2);  	    
	   
	  AddDataField('GIREN'); 
	  AddDataField('CIKAN'); 
	  AddColumnField('EvrakTipi');
	  AddRowField('AY');  	
	End
	Else
	Begin
	  SetReportData(F, ReadSQL(F));
	End;
  End;
  Self.Close;
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin
    CreateReport(IDS, ReadSQL(IDS), 
     'YIL;AY;ACIKLAMA;ISLEM;GIREN;CIKAN;EVRAKTIPI', 
	 'Yıl;Ay;Açıklama;İşlem;Giren;Çıkan;Belge Tipi', 
	 2);  
  End;
 End;

procedure editFormShow(Sender: TObject);
begin
  AddCheckItems(TComponent(Self.evraklar), 'Tümü;Nakit;Çek;Senet;VİSA');
  Self.IlkTarih.Date:= Date;
  Self.SonTarih.Date:= Date;
end;

// İptal
procedure cxButton2Click(Sender: TObject);
begin
  Self.Close;
end;

Begin
End.