procedure RaporLoad;
Begin
  SetViewCaption('BASLIK', 'PARADOX ' + FFilter + '. AY PERSONEL ÇALIŞMA SAATLERİ');
  SetQueryParam('KullaniciQ', 'AY', FFilter);
End;

Function RaporFileName: String;
Begin
  Result:= ParsDir + 'Pesonel Raporları\Maaş Bordrosu\CalismaSaatleri.fr3';
End;

Function RaporDefaultSQL: String;
Begin
  Result:= 'SELECT '#13 +
       '   AD + '' '' + SOYAD AS PERSONEL, GUN, '#13 +
//       '   CAST(CAST(CAST((TOTDAKIKA / 60) AS INT) AS VARCHAR) + '':'' + CAST(A.TOTDAKIKA - (CAST((TOTDAKIKA / 60) AS INT) * 60) AS VARCHAR) AS TIME) AS SAAT ' +
       '   CAST((TOTDAKIKA / 60) AS INT) AS SAAT '#13 +
       ' FROM( '#13 +
       ' SELECT  '#13 +
       '   PERSONELID, DATEPART(DAY, TARIH) AS GUN, '#13 +
       '   DATEPART(HOUR, SAAT) * 60 + DATEPART(MINUTE, SAAT) AS TOTDAKIKA '#13 +
       ' FROM TBLPERSONELCALISMASAATLERI PCS '#13 +
       ' LEFT OUTER JOIN TBLPERSONEL P1 WITH(INDEX=TBLPERSONEL_KARTNO) ON P1.KARTNO = PCS.PERSONELID  '#13 +
       ' WHERE DATEPART(M, TARIH) = 6 AND DATEPART(YEAR, TARIH) = DATEPART(YEAR, GETDATE()) '#13 +
       ' GROUP BY PERSONELID, TARIH, SAAT '#13 +
       ' ) AS A '#13 +
       ' LEFT OUTER JOIN TBLPERSONEL P WITH(INDEX=TBLPERSONEL_KARTNO) ON P.KARTNO = A.PERSONELID '#13 +
	   ' ORDER BY AD, SOYAD';   
End;

procedure Start;
Begin
End;

Procedure Finish;
Begin
End;

Function ReadFilter(Var F: String): Boolean;
Var 
  I: Integer;
Begin
  F:= '';
  Result:= InputRadio('Ocak;Şubat;Mart;Nisan;Mayıs;Haziran;Temmuz;Ağustos;Eylül;Ekim;Kasım;Aralık', 
     'Personel Maaş Bordrosu',
	 'Maaş Bordrosu Alınacak Ayı Seçin',
	 'Bordro Ayı', I);
  if Result Then
    F:= IntToStr(I + 1);  
End;

Function ReadSQL(W: String): String;
Begin
  Result:= 'SELECT ' +
       '   AD + '' '' + SOYAD AS PERSONEL, GUN, ' +
//       '   CAST(CAST(CAST((TOTDAKIKA / 60) AS INT) AS VARCHAR) + '':'' + CAST(A.TOTDAKIKA - (CAST((TOTDAKIKA / 60) AS INT) * 60) AS VARCHAR) AS TIME) AS SAAT ' +
       '   CAST((TOTDAKIKA / 60) AS INT) AS SAAT ' +
       ' FROM( ' +
       ' SELECT  ' +
       '   PERSONELID, DATEPART(DAY, TARIH) AS GUN, ' +
       '   DATEPART(HOUR, SAAT) * 60 + DATEPART(MINUTE, SAAT) AS TOTDAKIKA ' +
       ' FROM TBLPERSONELCALISMASAATLERI PCS ' +
       ' LEFT OUTER JOIN TBLPERSONEL P1 WITH(INDEX=TBLPERSONEL_KARTNO) ON P1.KARTNO = PCS.PERSONELID  ' +
       ' WHERE DATEPART(M, TARIH) = ' + W + ' AND DATEPART(YEAR, TARIH) = DATEPART(YEAR, GETDATE()) ' +
       ' GROUP BY PERSONELID, TARIH, SAAT ' +
       ' ) AS A ' +
       ' LEFT OUTER JOIN TBLPERSONEL P WITH(INDEX=TBLPERSONEL_KARTNO) ON P.KARTNO = A.PERSONELID ' +
	   ' ORDER BY AD, SOYAD';   
End;

procedure Execute;
Var
  ay: String;
Begin
  if ReadFilter(ay) Then
    CreateReport(ay, readSQL(ay),
     'PERSONEL;GUN;SAAT', 
	 'Personel;Gün;Saat', 
	  2);
  
  AddDataField('SAAT'); 
  AddRowField('PERSONEL');
  AddColumnField('GUN');
  
End;

Begin
End.