*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="clienti3.mnx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*<MenuType>4</MenuType>
*<MenuLocation>REPLACE</MenuLocation>

*<MenuCode>
DEFINE POPUP Clienti SHORTCUT RELATIVE FROM MROW(),MCOL()
DEFINE BAR 1 OF Clienti PROMPT "Regularizare facturi neintocmite" ;
	MESSAGE '4111 :418 ; 4428:4427'
ON SELECTION BAR 1 OF Clienti DO BAR_1_OF_Clienti_FB2P

DEFINE BAR 2 OF Clienti PROMPT "Regularizare clienti creditori"
ON SELECTION BAR 2 OF Clienti DO BAR_2_OF_Clienti_FB2P

DEFINE BAR 3 OF Clienti PROMPT "\<Regularizare clienti externi creditori" ;
	MESSAGE '419:4111'
ON SELECTION BAR 3 OF Clienti DO BAR_3_OF_Clienti_FB2P

DEFINE BAR 4 OF Clienti PROMPT "\-"
ON BAR 4 OF Clienti ACTIVATE POPUP _40i0phplc

	*----------------------------------
	DEFINE POPUP _40i0phplc SHORTCUT RELATIVE
DEFINE BAR 5 OF Clienti PROMPT "Compensare facturi client - lei" ;
	MESSAGE '5121:4111'
ON SELECTION BAR 5 OF Clienti lans(10613)

DEFINE BAR 6 OF Clienti PROMPT "Compensare facturi clienti - valuta" ;
	MESSAGE '5124 : 4111,461'
ON SELECTION BAR 6 OF Clienti DO BAR_6_OF_Clienti_FB2P

DEFINE BAR 7 OF Clienti PROMPT "\-"
ON BAR 7 OF Clienti ACTIVATE POPUP _7ey0nygcs

	*----------------------------------
	DEFINE POPUP _7ey0nygcs SHORTCUT RELATIVE
DEFINE BAR 8 OF Clienti PROMPT "Compensare avansuri client - lei" ;
	MESSAGE '419 : 5121'
ON SELECTION BAR 8 OF Clienti lans(10621)

DEFINE BAR 9 OF Clienti PROMPT "Compensare avansuri clienti - valuta" ;
	MESSAGE '419 : 5124'
ON SELECTION BAR 9 OF Clienti lans_generic(10658,"419")
ACTIVATE POPUP Clienti

*</MenuCode>

*<Procedures>
PROCEDURE BAR_1_OF_Clienti_FB2P
	lans(10325)
	
	IF gnButon = 2
		IF USED('actactan')
			USE IN actactan
		ENDIF 
		RETURN
	ENDIF 
	
	SELECT actactan
	*!*	modificare	v 2.4.25	:	am pus GO TOP deoarece, daca avea si nota cu 4428 - 4427, atunci copia datele de pe aceasta nota
	*!*		si aveam id_fact de la factura, in loc de cel de la nota actuala
	*!*	GO BOTTOM
	Go Top
	*!*	modificare	v 2.4.25	^
	SCATTER FIELDS EXCEPT id_factd, id_factc,pereched,perechec, id_partd, id_partc, partd, partc,id_jtva_coloana,proc_tva,taxcode,taxname NAME otemp
	
	*!*	SELECT DISTINCT proc_tva FROM actactan WHERE !INLIST(proc_tva,1,0) AND scc = '418 ' INTO CURSOR procent
	SELECT distinct a.id_jtva_coloana,(b.cota_tva+100)/100 as proc_tva,b.id_tva, a.taxcode,a.taxname FROM actactan a JOIN jtva_coloane b ;
		ON a.id_jtva_coloana = b.id_jtva_coloana WHERE b.cota_tva <> 0 AND ALLTRIM(a.scc) = '418' INTO CURSOR procent
	
	IF _tally#0
		SELECT procent
		SCAN
			SCATTER NAME oproc
			SELECT actactan
			SUM suma TO lnsuma FOR id_jtva_coloana=oproc.id_jtva_coloana AND ALLTRIM(scc)='418'
			SELECT actactan
			APPEND BLANK 
			GATHER NAME otemp
			replace id_jtva_coloana WITH oproc.id_tva,proc_tva WITH oproc.proc_tva, taxcode WITH oproc.taxcode, taxname WITH oproc.taxname
	*!*			REPLACE scd WITH '4428',scc WITH '4427',
			REPLACE scd WITH '4428',scc WITH iif(inlist(id_jtva_coloana, 22, 24, 26), '4428', '4427')
					
			REPLACE suma WITH ROUND(LnSuma*(oproc.proc_tva-1)/oproc.proc_tva,gnPc) 
	
			SELECT procent
		ENDSCAN 
	ENDIF 
	
	SELECT actactan 
	GO TOP 
	DO FORM verificare
	
	IF gnButon=1
		oscrie_in_fisiere()
	ENDIF 
	
	IF USED('actactan')
		USE IN actactan
	ENDIF 
	IF USED('procent')
		USE IN procent
	ENDIF 
ENDPROC && BAR_1_OF_Clienti_FB2P

PROCEDURE BAR_2_OF_Clienti_FB2P
	lans(10421)
	
	
	IF gnButon = 2
		IF USED('actactan')
			USE IN actactan
		ENDIF 
		RETURN
	ENDIF 
	
	SELECT actactan
	*!*	modificare	v 2.4.25	:	am pus GO TOP deoarece, daca avea si nota cu 4428 - 4427, atunci copia datele de pe aceasta nota
	*!*		si aveam id_fact de la factura, in loc de cel de la nota actuala
	*!*	GO BOTTOM
	Go Top
	*!*	modificare	v 2.4.25	^
	SCATTER FIELDS EXCEPT id_factd, id_factc,pereched, perechec, id_partd, id_partc, partd, partc, scd, scc, ascd, ascc, id_jtva_coloana,proc_tva,taxcode,taxname NAME otemp
	
	SELECT DISTINCT a.id_jtva_coloana, (b.cota_tva+100)/100 as proc_tva, a.scc, a.ascc, a.id_partc, a.partc, a.id_factc,;
		a.perechec, b.id_tva, a.taxcode,a.taxname ;
		FROM actactan a join jtva_coloane b on a.id_jtva_coloana = b.id_jtva_coloana WHERE b.cota_tva <> 0 ;
		AND LEFT(a.scd,3) = '419' INTO CURSOR procent
	
	IF _tally#0
		SELECT procent
		SCAN
			SCATTER NAME oproc
			SELECT actactan
			SUM suma TO lnsuma FOR id_jtva_coloana=oproc.id_jtva_coloana AND LEFT(scd,3) = '419' AND id_partc = oproc.id_partc AND scc = oproc.scc AND NVL(ascc,'xxxx') = NVL(oproc.ascc,'xxxx') AND id_factc = oproc.id_factc AND perechec = oproc.perechec
			SELECT actactan
			APPEND BLANK 
			GATHER NAME otemp
			REPLACE scd WITH oproc.scc, ascd WITH oproc.ascc, partd WITH oproc.partc, id_partd WITH oproc.id_partc, id_factd WITH oproc.id_factc, pereched WITH oproc.perechec, scc WITH '4427',id_jtva_coloana with oproc.id_tva,proc_tva with oproc.proc_tva
			REPLACE suma WITH -ROUND(LnSuma*(oproc.proc_tva-1),gnPc)
			REPLACE taxcode WITH oproc.taxcode, taxname WITH oproc.taxname
			SELECT procent
		ENDSCAN 
	ENDIF 
	
	SELECT actactan 
	GO TOP 
	DO FORM verificare
	
	IF gnButon=1
		oscrie_in_fisiere()
	ENDIF 
	
	IF USED('actactan')
		USE IN actactan
	ENDIF 
	IF USED('procent')
		USE IN procent
	ENDIF 
	
	
	
	
ENDPROC && BAR_2_OF_Clienti_FB2P

PROCEDURE BAR_3_OF_Clienti_FB2P
	lans(10454)
	
	SELECT actactan
	GO TOP
	
	IF gnButon=1
		DO FORM verificare
	ENDIF
	
	IF gnButon=1
		oscrie_in_fisiere()
	ENDIF
	
	*!*	IF BUTON=2
	*!*		DO STERGE
	*!*		DO inchid_actcv
	*!*		DO deschid_actc
	*!*		RETURN
	*!*	ENDIF
	
	*!*	PRIVATE PnSuma,pnSumaVal
	*!*	pnSuma=m.suma
	*!*	pnSumaVal=m.suma_2
	
	*!*	lcnume=UPPER(ALLTRIM(m.nume))
	*!*	DO imperechere_fact_avans WITH 'avans419',lcnume,m.suma,.t.,'pereche'
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	*!*	m.scd='419 '
	*!*	m.scc='411 '
	*!*	do alfabetaper with;
	*!*	 'CASApermulval',;
	*!*	 "NUMELE CLIENTULUI","CLIENTI","NUME",   ;
	*!*		"","","",  ;
	*!*		'CURSUL VALUTAR','','',  ;
	*!*		'do curs.spr','v'
	*!*	*
	*!*	IF BUTON=2
	*!*	DO STERGE
	*!*	RETURN
	*!*	ENDIF
	
	*!*	local c
	*!*	c=0
	*!*	m.nract=numaract
	*!*	*DO CODARE
	*!*	sele 0
	*!*	use &loc\&nfscurt\tempo\actcv
	*!*	sele actcv
	*!*	scan for ales
	*!*	c=cod
	*!*	M.PERECHE=NRACT
	*!*	m.suma_2=sumaachi
	*!*	m.nrord=''
	*!*	sele actan
	*!*	loca for cod=c
	*!*	if found()
	*!*	m.nrord=nrord
	*!*	cursfact=suma_3
	*!*	endif
	*!*	*!*	sele avans419
	*!*	*!*	loca for cod=c
	*!*	*!*	if found()
	*!*	cursavans=m.cursschimb
	*!*	m.suma=sumaachi*min(cursavans,cursfact)
	*!*	dif=sumaachi*(cursavans-cursfact)
	*!*	DO CODARE
	*!*	DO CONTABILIZEAZA WITH m.scd,m.scc,M.suma,CLASAACT
	*!*	do case
	*!*	case dif<0
	*!*	DO CONTABILIZEAZA WITH '665 ','411 ',-dif,CLASAACT
	*!*	case dif>0
	*!*	DO CONTABILIZEAZA WITH '419 ','765 ',dif,CLASAACT
	*!*	endcase
	*!*	*!*	do inBANCAval
	*!*	*!*	SELE LUCRARI
	*!*	*!*	LOCA FOR NRORD=M.NRORD
	*!*	*!*	if flock()
	*!*	*!*	REPLACE lucrari.incasat WITH lucrari.incasat+m.suma
	*!*	*!*	endif
	*!*	*!*	unlock
	*!*	*!*	SELE CLIENTI
	*!*	*!*	if flock()
	*!*	*!*	REPLACE CLIENTI.incasat WITH CLIENTI.incasat+m.suma
	*!*	*!*	endif
	*!*	*!*	unlock
	
	*!*	SELE CLIENTI
	*!*	if flock()
	*!*	REPLACE CLIENTI.incasat WITH CLIENTI.incasat+m.suma
	*!*	REPLACE CLIENTI.AVANS WITH CLIENTI.AVANS-m.suma
	*!*	endif
	*!*	unlock
	
	*!*	endscan
	*!*	use in actcv
	*!*	do sterge
	*!*	RETURN
ENDPROC && BAR_3_OF_Clienti_FB2P

PROCEDURE BAR_6_OF_Clienti_FB2P
	LOCAL loCont
	loCont = ret_cont("Contul creditor", "4111,461")
	If buton = 2
		Release loCont
		Return
	Endif
	
	
	lans_generic(10657,loCont.Cont, loCont.Acont)
ENDPROC && BAR_6_OF_Clienti_FB2P

*</Procedures>
