procedure Start;
Begin
End;

Procedure Finish;
Begin
End;

Function ReadFilter(Var F: String): Boolean;
Var
  IDS: String;
Begin
  F:= '';
  Result:= False;

  IDS:= SelectRecord('Select '#13#10 +
        '   M.BARKOD, M.ID AS KARTNO, R.ID AS RENKID, D.ID AS DESENID, CINSI, BIRIMADI, R.KOD AS RENK, D.KOD AS DESEN '#13#10 +
        ' from TBLBIRIMMUADILKOD M '#13#10 +
        ' LEFT OUTER JOIN TBLBIRIMLEREX B WITH(INDEX=TBLBIRIMLEREX_KARTNO) ON B.KARTNO = M.BIRIMKARTNO '#13#10 +
        ' LEFT OUTER JOIN TBLSTOKLAR S WITH(INDEX=TBLSTOKLAR_KARTNO) ON S.KARTNO = B.STOKID '#13#10 +
        ' LEFT OUTER JOIN TBLRENKLER R ON R.ID = M.RENK '#13#10 +
        ' LEFT OUTER JOIN TBLHALIDESENLER D ON D.ID = M.DESEN '#13#10 +
        ' WHERE ISNULL(B.KARTNO, 0) <> 0 AND ISNULL(S.DELETED, 0) = 0 ORDER BY CINSI',
		'CINSI;BIRIMADI;RENK;DESEN',
		'Cinsi;Birim;Renk;Desen',
		'KARTNO',
		'Cinsi / Renk / Desen',
		'CINSI;RENK;DESEN',
		False);
  if IDS <> '' Then
  Begin
    F:= IDS;
	Result:= True;
  End;  
		
End;

Function ReadSQL(W: String): String;
Begin
  Result:= 'Select '#13#10 +
		'  M.ACIKLAMA, S.KOD1 AS MARKA, ISLEM, BELGENO, TARIH, FIRMAKODU, FIRMAADI, STOKKODU, CINSI, R.KOD AS RENKKOD, D.KOD AS DESENKOD, H.GIREN, H.CIKAN '#13#10 +
		' from TBLBIRIMMUADILKOD M  '#13#10 +
		' LEFT OUTER JOIN TBLBIRIMLEREX B WITH(INDEX=TBLBIRIMLEREX_KARTNO) ON B.KARTNO = M.BIRIMKARTNO '#13#10 +
		' LEFT OUTER JOIN TBLSTOKLAR S WITH(INDEX=TBLSTOKLAR_KARTNO) ON S.KARTNO = B.STOKID '#13#10 +
		' LEFT OUTER JOIN STOKHAREKET H ON H.STOKID = S.KARTNO AND H.RENKID = M.RENK AND H.DESENID = M.DESEN '#13#10 +
		' LEFT OUTER JOIN TBLCARI C WITH(INDEX=TBLCARI_KARTNO) ON C.KARTNO = H.CARIID '#13#10 +
		' LEFT OUTER JOIN TBLRENKLER R ON R.ID = H.RENKID '#13#10 +
		' LEFT OUTER JOIN TBLHALIDESENLER D ON D.ID = H.DESENID '#13#10;
		
  if W <> '' Then		
		Result:= Result + ' WHERE M.ID = ' + W + #13#10;
		
  Result:= Result + ' ORDER BY H.TARIH '#13#10;
End;

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

Function RaporFileName: String;
Begin
  Result:= '';
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin    
    CreateReport(IDS, ReadSQL(IDS), 
     'ACIKLAMA;MARKA;ISLEM;BELGENO;TARIH;FIRMAKODU:0;FIRMAADI;STOKKODU:0;CINSI;RENKKOD;DESENKOD;GIREN;CIKAN', 
	 'Açıklama;MArka;İşlem;BelgeNo;Tarih;Firma Kodu;Firma Adı;Stok Kodu;Cinsi;Renk;DEsen;Giren;Çıkan', 
	  0);
    CreateSummary('ACIKLAMA', skCount);
	CreateSummary('GIREN', skSum);
	CreateSummary('CIKAN', skSum);
  End;
End;

Begin
End.
