procedure RaporLoad;
Var
  K: String;
  P: Integer;
Begin
  SetViewCaption('BASLIK', 'PARADOX TAHSİLAT MAKBUZU');
// Filtre Kullanılırsa
  if FFilter <> '' Then
  Begin
    K:= FFilter;
    P:= POS('=', K);
	if P > 0 Then
	  Delete(K, 1, P + 1);
	  
    AddQueryToSQL('baslikQ', '  AND B.KARTNO = ' + K);
  End;
End;

Function RaporFileName: String;
Begin
  Result:= ParsDir + 'Cari Kart Raporları\Finansal Raporlar\Tahsilat Raporları\Tahsilat Makbuzu.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 TBLCARIGIRIS 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
  IDS: String;
Begin
  IDS:= SelectRecord('Select B.KARTNO, C.FIRMAKODU, C.FIRMAADI, ACIKLAMA, BELGENO, B.TARIH, TUTARI ' + 
     ' from TBLCARIGIRIS B  LEFT OUTER JOIN TBLCARI C WITH(INDEX=TBLCARI_KARTNO) ON C.KARTNO = B.CARIID ' + 
	 ' WHERE B.DELETED = 0',  
	 'FIRMAKODU;FIRMAADI;ACIKLAMA;BELGENO;TARIH;TUTARI', 
     'Firma Kodu;Firma Adı;Açıklama;Belge No;Tarih;Tutarı', 
	 'KARTNO',
	 'Firma Kodu / Adı / Belge No',
	 'FIRMAKODU;FIRMAADI;BELGENO', 
	 False);
  Result:= IDS <> '';
  if Result Then
  Begin
    F:= 'BASLIKID = ' + IDS;
  End;
End;

Function ReadSQL(W: String): String;
Begin
  Result:= 'Set DateFormat DMY ' + 
      ' Select ' + 
      ' CASE ISLEM ' + 
      '   WHEN 0 THEN ''NAKİT'' ' + 
      '   WHEN 1 THEN ''ÇEK'' ' + 
      '   WHEN 2 THEN ''SENET'' ' + 
      '   WHEN 3 THEN ''VİSA'' ' + 
      '   WHEN 4 THEN ''ŞAHSİ ÇEK'' ' + 
      '   WHEN 5 THEN ''ŞAHSİ SENET'' ' + 
      '   WHEN 6 THEN ''ŞAHSİ VİSA'' ' + 
      '   WHEN 7 THEN ''DEKONT'' ' + 
      '   WHEN 8 THEN ''TAKSİT'' ' + 
      '   WHEN 9 THEN ''CİRO ÇEK'' ' + 
      '   WHEN 10 THEN ''CİRO SENET'' ' + 
      ' END AS EVRAK,  ' + 
      ' PORTFOYNO, D.ACIKLAMA, VADE, TUTAR, ISNULL(DV.SEMBOL, ''TL'') AS PARABIRIMI ' + 
      ' from TBLCARIGIRISDETAY D WITH(INDEX=TBLCARIGIRISDETAY_BASLIK) ' + 
      ' LEFT OUTER JOIN TBLDOVIZLER DV ON DV.KARTNO = D.DOVIZID ';

  if W <> '' Then
    Result:= Result + ' WHERE ' + W;
  Result:= Result + ' ORDER BY D.VADE';
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin
    CreateReport(IDS, ReadSQL(IDS), 
     'EVRAK;PORTFOYNO;ACIKLAMA;VADE;TUTAR;PARABIRIMI:0', 
	 'Evrak;Portföy No;Açıklama;Vade;Tutar;Para Birimi', 
	  0);
	  
	CreateSummary('TUTAR', skSum); 
	CreateSummary('PORTFOYNO', skCount);   
  End;
End;

Begin
End.