function defaultSQL(W: String): String;
Begin
  Result:= 'Select A.*, ' + 
      ' (SELECT SUM(MIKTARI) FROM DETAYCARIDOKUM WHERE STOKKODU = A.STOKKODU AND ISLEMTIPI = 2) AS SATIS ' + 
	  ' FROM( ' +
	  ' Select ' + 
	  '   CARIID, STOKKODU, CINSI, SUM(MIKTARI) AS ALIS, BIRIMADI ' +
	  ' from DETAYCARIDOKUM ' +
	  ' WHERE ISLEMTIPI = 3 ' + 
	  ' GROUP BY CARIID, STOKKODU, CINSI, BIRIMADI ' + 
	  ' ) AS A ';
  if W <> '' Then
	Result:= Result + ' WHERE ' + W;
End;

procedure RaporLoad;
Begin
End;

Function RaporFileName: String;
Begin
End;

Function RaporDefaultSQL: String;
Begin
  result:= defaultSQL('');
End;

procedure Start;
Begin
End;

Procedure Finish;
Begin
End;

Function ReadFilter(Var F: String): Boolean;
Var
  IDS: String;
Begin
  IDS:= SelectRecord('Select KARTNO, FIRMAKODU, FIRMAADI FROM TBLCARI WHERE COALESCE(DELETED, 0) = 0 ',  
	 'FIRMAKODU;FIRMAADI', 
     'Firma Kodu;Firma Adı', 
	 'KARTNO',
	 'Firma Kodu / Adı',  
	 'FIRMAKODU;FIRMAADI', 
	 False);
  Result:= IDS <> '';
  if Result Then
  Begin
    F:= 'A.CARIID = ' + IDS;
  End;
End;

Function ReadSQL(W: String): String;
Begin
End;

procedure Execute;
Var
  IDS: String;
Begin
  if ReadFilter(IDS) Then
  Begin
	CreateReport(IDS, defaultSQL(IDS), 
     'STOKKODU:0;CINSI;ALIS;SATIS;BIRIMADI', 
	 'Stok Kodu;Cinsi;Alınan Miktar;Satılan Miktar;Birimi', 
	  0);  
	  
	CreateSummary('ALIS', skSum);
	CreateSummary('SATIS', skSum);
	CreateSummary('CINSI', skCount);
  End;
End;

Begin
End.