close all
deactivate window all
deactivate menu
set exact on
set talk off
set status off
set scoreboard off
set date to british
set clock on
SET DELETE ON
set exclusive off
set century on
SET SAFE OFF

	define window SelCG from 11,16 to 21,79 color gr+/rb,w+/r
    define window listNIR from 3,0 to 22,79 color w+/b,w+/r,r/bg TITLE "  Raport distribuitor " DOUBLE
	
	define window iWAIT from 15,17 to 17,69 color gr+,,n

     define window pprint from 17,17 to 19,69 color gr+,,n
		define popup pprint from 0,30 to 3,45
		define bar 1 of pprint prompt ' Imprimanta '
		define bar 2 of pprint prompt ' Fisier disc '
*		define bar 3 of pprint prompt ' Impr. retea '
       on selection popup pprint do SelDest with cDest,cFile

** START PROGRAM **

cAntet1='INFOWAY Sibiu '
if ISCOLOR()
  set color to g/n,w+/r,gr,r/bg
  set color of box to gr+/n+
  set color of fields to n/bg
 else
  set color to w+/n,n/w+,w,w/n
  set color of box to w/n
  set color of fields to n+/w+
endif

@1,1 say cAntet1 color r/bg
@1,62 say ' Data : '
?? date()
ACTIVATE WINDOW listNIR
sele 1
use produse alias prod
set order to cod_p
sele 2
use facte
set order to data
set relation to codp into prod
sele 3
use chesti1 alias che exclusive
zap



ddata_i=DATE()
@ 5,1 SAY CHR(7)+"Data inceput perioada SITUATIE :" GET ddata_i
READ
if lastkey()=27
  QUIT
endif
ddata_f=ddata_i
@ 6,1 SAY CHR(7)+"Data sfirsit perioada SITUATIE :" GET ddata_f
READ
if lastkey()=27
  QUIT
endif
DO BWAIT
sele facte
go top
scan all for dat>=ddata_i and dat<=ddata_f
IF 'SINTO'$prod.denp
 sele che
 append blank
 replace cod_client with facte.cof
 replace val_cu_tva with facte.total 
 do case
  case  'CHIT'$prod.denp OR 'FINITION'$PROD.DENP
	  replace che.chituri with facte.total  
  case  'ANTIFON'$prod.denp
	  replace che.insonoriza with facte.total 
  case  'SILICON'$prod.denp
  	replace che.silicon with facte.total 
  case  'MASTIC'$prod.denp
  	replace che.mastic with facte.total 
  case  'ROLE'$prod.denp
  	replace che.banda_adez with facte.total 
  case  'SP.'$prod.denp or 'SP '$prod.denp
  	replace che.vopsea with facte.total 
  case  'SMIRDEX'$prod.denp OR 'ABRAZIVA'$PROD.DENP
  	replace che.abrazive with facte.total 
 endcase
ENDIF 
 sele facte
endscan
sele che
copy to chesti11.dbf
index on cod_client to iulia.idx
total to chesti2 on cod_client fields val_cu_tva,chituri,insonoriza,silicon,mastic,banda_adez,vopsea,abrazive
sele 5 
use clienti
set order to codc
sele 4
use chestion alias chet exclusive
zap
append from chesti2.dbf
set relation to str(cod_client,4) into clienti
replace all nume_cli with clienti.denf,localitate with clienti.loca,judet with clienti.jud

 
**** adaugare transferuri
sele che
zap
sele 2 
set relation to 
use tran alias facte
sele facte
go top
scan all for dat>=ddata_i and dat<=ddata_f and 'SINTO'$facte.denp and codg=5 AND !('OUTIL'$FACTE.DENP) && and can>0
 sele che
 append blank
 replace cod_client with facte.codg
 ntotal=facte.can*facte.pl
 replace val_cu_tva with ntotal 
 do case
  case  'CHIT'$facte.denp OR 'FINITION'$FACTE.DENP
	  replace che.chituri with ntotal  
  case  'ANTIFON'$facte.denp
	  replace che.insonoriza with ntotal 
  case  'SILICON'$facte.denp
  	replace che.silicon with ntotal 
  case  'MASTIC'$facte.denp
  	replace che.mastic with ntotal 
  case  'ROLE'$facte.denp
  	replace che.banda_adez with ntotal 
  case  'SP.'$facte.denp or 'SP '$facte.denp
  	replace che.vopsea with ntotal 
  case  'SMIRDEX'$facte.denp OR 'ABRAZIVA'$FACTE.DENP
  	replace che.abrazive with ntotal 
 endcase
 sele facte
endscan
sele che
index on cod_client to iulia.idx
total to chesti3 on cod_client fields val_cu_tva,chituri,insonoriza,silicon,mastic,banda_adez,vopsea,abrazive
****
sele chet
append from chesti3.dbf
go bottom
replace localitate with 'SIBIU',nume_cli with 'CARSYS SRL',JUDET WITH 'SIBIU'
SORT to iulia2.DBF ON judet,LOCALITATE,NUME_CLI 
TOTAL ON NR_CRT FIELDS val_cu_tva,chituri,insonoriza,silicon,mastic,banda_adez,vopsea,abrazive TO IULIA3.DBF
USE IULIA3
REPLACE NUME_CLI WITH 'TOTAL',LOCALITATE WITH ' ',JUDET WITH ''
USE IULIA2.DBF ALIAS CHET
ncrt=0
replace all chet.nr_crt with ncrt()
APPEND FROM IULIA3.DBF
EXPORT TO RAPORT.XLS TYPE XLS
DO fWAIT
DEACTIVATE WIND listnir
QUIT
*RETURN
	   


	procedure Bwait
	  activate window iwait
	  @ 0,2 say 'ROG ASTEPTATI TERMINAREA OPERATIEI DE PRELUCRARE'
	return
	
	procedure Fwait
	  deactivate window iwait
	return


function ncrt
  ncrt=ncrt+1
return ncrt 

