procedure Start;
Begin
End;

Procedure Finish;
Begin
End;

procedure Execute;
Begin
  Form.Caption:= 'Stok Kontrol';
  SetPanelCaption('Stok Kontrol');
  SetPanelRemarks('Depo / Fatura Stok Kontrolu');
  SetIconIndex(28);
  createGrid('', 
      '   Select ' +
      '   CINSI, R.KOD AS RENK, A.STOKID, B.BIRIMADI, BIRIMID, RENKID,  ' +
      '   SUM(GIRENMIKTARI - CIKANMIKTARI) AS MIKTARI, ' +
      '   SUM(GIRENBRUTKG - CIKANBRUTKG) AS BRUTKG, ' +
      '   SUM(GIRENNETKG - CIKANNETKG) AS NETKG, ' +
      '   SUM(GIRENKAPADEDI - CIKANKAPADEDI) AS KAPADEDI ' +
      ' FROM( ' +
      ' Select ' +
      '   H.STOKID, H.BIRIMID, RENKID, SUM(MIKTARI) AS GIRENMIKTARI,  ' +
      '   SUM(BRUTKG) AS GIRENBRUTKG, SUM(NETKG) AS GIRENNETKG, SUM(PALETADET) AS GIRENKAPADEDI, ' +
      '   0.00 AS CIKANMIKTARI, 0.00 AS CIKANBRUTKG, 0.00 AS CIKANNETKG, 0.00 AS CIKANKAPADEDI ' +
      ' from TBLALFATHAREKET H ' +
      ' LEFT OUTER JOIN TBLALFATBASLIK B WITH(INDEX=TBLALFATBASLIK_KARTNO) ON B.KARTNO = H.FATURAID ' +
      ' WHERE ISNULL(B.DELETED, 0) = 0 ' +
      ' GROUP BY H.STOKID, H.BIRIMID, RENKID ' +
      ' UNION ALL ' +
      ' Select ' +
      '   H.STOKID, H.BIRIMID, RENKID, 0.00, 0.00, 0.00, 0.00, SUM(MIKTARI), SUM(BRUTKG), SUM(NETKG), SUM(PALETADET) ' +
      ' from TBLSATFATHAREKET H ' +
      ' LEFT OUTER JOIN TBLSATFATBASLIK B WITH(INDEX=TBLSATFATBASLIK_KARTNO) ON B.KARTNO = H.FATURAID ' +
      ' WHERE ISNULL(B.DELETED, 0) = 0 ' +
      ' GROUP BY H.STOKID, H.BIRIMID, RENKID ' +
      ' ) AS A ' +
      ' LEFT OUTER JOIN TBLSTOKLAR S WITH(INDEX=TBLSTOKLAR_KARTNO) ON S.KARTNO = A.STOKID ' +
	  ' LEFT OUTER JOIN TBLBIRIMLEREX B WITH(INDEX=TBLBIRIMLEREX_KARTNO) ON B.KARTNO = A.BIRIMID ' +
      ' LEFT OUTER JOIN TBLRENKLER R ON R.ID = A.RENKID ' +
      ' GROUP BY CINSI, R.KOD, B.BIRIMADI, A.STOKID, BIRIMID, RENKID ',
	  'CINSI;RENK;MIKTARI;BIRIMADI;BRUTKG;NETKG;KAPADEDI',
	  'Cinsi;Renk;Miktarı;Birimi;Brüt KG;Net KG;Kap Adedi',
	  0);

  CreateSummary('CINSI', skCount);
  CreateSummary('MIKTARI', skSum);
  CreateSummary('BRUTKG', skSum);    
  CreateSummary('NETKG', skSum);    
  CreateSummary('KAPADEDI', skSum);    
End;

Begin
End.
