SET DELETED ON
SET CENTURY ON
SET DATE DMY
SET ANSI ON
SET EXACT ON
SET DATE DMY
SET SAFETY OFF
SET EXCLUSIVE OFF
CLOSE DATABASES

lcDir = [d:\roa_rb\roacont\comun\datemenu\]
lcXsets = lcDir + [xsets.dbf]
lcXnote = lcDir + [xnote.dbf]
USE (lcXsets) IN 0 SHARED
USE (lcXnote) IN 0 SHARED

lnIdSetVzNetax = 8
lnIdSetVzTax19 = 1

lnIdSetCmNetax = 113
lnIdSetCmCapital19 = 101
lnIdSetCmMarfa19 = 103
lnIdSetCmBunuri19 = 105

lnIdSetCmTxInv = 141 && taxare inversa 19% bunuri firma
lnIdSetVzTxInv = 5

SELECT DISTINCT ID_SET ;
	FROM XNOTE ;
	WHERE INLIST(ALLTRIM(XSCD), '4111','461', '418') OR INLIST(ALLTRIM(XSCC), '419') ;
	INTO CURSOR crsIdSetVz



SELECT DISTINCT ID_SET ;
	FROM XNOTE ;
	WHERE INLIST(ALLTRIM(XSCC), '404') ;
	INTO CURSOR crsIdSetCmCapital

SELECT DISTINCT ID_SET ;
	FROM XNOTE;
	WHERE INLIST(ALLTRIM(XSCD), '371') AND INLIST(ALLTRIM(XSCC), '401','462', '408');
	UNION ;
	SELECT DISTINCT S.ID_SET ;
	FROM XSETS S JOIN (SELECT ID_SET FROM XNOTE WHERE INLIST(ALLTRIM(XSCC), '401','462', '408')) N ;
	ON S.ID_SET = N.ID_SET ;
	WHERE 'MARFA'$UPPER(S.NUME_SET);
	INTO CURSOR crsIdSetCmMarfa

SELECT DISTINCT ID_SET ;
	FROM XNOTE ;
	WHERE (INLIST(ALLTRIM(XSCC), '401','462', '408') OR INLIST(ALLTRIM(XSCD), '409')) AND !INLIST(ALLTRIM(XSCD), '371');
	INTO CURSOR crsIdSetCmBunuri

SELECT DISTINCT ID_SET ;
	FROM XSETS ;
	WHERE 'INVERS'$UPPER(NUME_SET) AND '411'$UPPER(LISTA_NOTE) ;
	INTO CURSOR crsIdSetVzTxInv

SELECT DISTINCT ID_SET ;
	FROM XSETS ;
	WHERE 'INVERS'$UPPER(NUME_SET) AND '401'$UPPER(LISTA_NOTE) ;
	INTO CURSOR crsIdSetCmTxInv


DO CLEAN_SETS
DO UPDATE_SETS WITH "crsIdSetVz", lnIdSetVzNetax, lnIdSetVzTax19, "JV"
DO UPDATE_SETS WITH "crsIdSetCmCapital", lnIdSetCmNetax, lnIdSetCmCapital19, "JC"
DO UPDATE_SETS WITH "crsIdSetCmMarfa", lnIdSetCmNetax, lnIdSetCmMarfa19, "JC"
DO UPDATE_SETS WITH "crsIdSetCmBunuri", lnIdSetCmNetax, lnIdSetCmBunuri19, "JC"

DO UPDATE_SETS WITH "crsIdSetVzTxInv", lnIdSetVzNetax, lnIdSetVzTxInv, "JV"
DO UPDATE_SETS WITH "crsIdSetCmTxInv", lnIdSetCmNetax, lnIdSetCmTxInv, "JC"


PROCEDURE CLEAN_SETS
	UPDATE XSETS SET ID_JNETAX = 0, ID_JTAX = 0, TIPJURNAL = ''
ENDPROC

*!*
PROCEDURE UPDATE_SETS
	LPARAMETERS tcCursorIdSet, tnIdSetNetax, tnIdSetTax, tcTipJurnal
	SELECT (tcCursorIdSet)
	SCAN
		IF SEEK(ID_SET,"xsets","id_set")
			IF EMPTY(XSETS.ID_JNETAX) AND EMPTY(XSETS.ID_JTAX) AND EMPTY(XSETS.TIPJURNAL)
				REPLACE ID_JNETAX WITH tnIdSetNetax, ID_JTAX WITH tnIdSetTax, TIPJURNAL WITH tcTipJurnal IN XSETS
			ENDIF
		ENDIF
	ENDSCAN
ENDPROC
